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;
3623 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3624 switch (actions->type) {
3625 case RTE_FLOW_ACTION_TYPE_QUEUE:
3626 queue = actions->conf;
3629 if (mlx5_rxq_get_type(dev, queue->index) !=
3630 MLX5_RXQ_TYPE_HAIRPIN)
3635 case RTE_FLOW_ACTION_TYPE_RSS:
3636 rss = actions->conf;
3637 if (rss == NULL || rss->queue_num == 0)
3639 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
3640 MLX5_RXQ_TYPE_HAIRPIN)
3645 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3646 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3647 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3648 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3649 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3653 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3654 raw_encap = actions->conf;
3655 if (raw_encap->size >
3656 (sizeof(struct rte_flow_item_eth) +
3657 sizeof(struct rte_flow_item_ipv4)))
3666 if (split && queue_action)
3671 /* Declare flow create/destroy prototype in advance. */
3673 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
3674 const struct rte_flow_attr *attr,
3675 const struct rte_flow_item items[],
3676 const struct rte_flow_action actions[],
3677 bool external, struct rte_flow_error *error);
3680 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
3684 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3686 * As mark_id is unique, if there's already a registered flow for the mark_id,
3687 * return by increasing the reference counter of the resource. Otherwise, create
3688 * the resource (mcp_res) and flow.
3691 * - If ingress port is ANY and reg_c[1] is mark_id,
3692 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3694 * For default flow (zero mark_id), flow is like,
3695 * - If ingress port is ANY,
3696 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
3699 * Pointer to Ethernet device.
3701 * ID of MARK action, zero means default flow for META.
3703 * Perform verbose error reporting if not NULL.
3706 * Associated resource on success, NULL otherwise and rte_errno is set.
3708 static struct mlx5_flow_mreg_copy_resource *
3709 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
3710 struct rte_flow_error *error)
3712 struct mlx5_priv *priv = dev->data->dev_private;
3713 struct rte_flow_attr attr = {
3714 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3717 struct mlx5_rte_flow_item_tag tag_spec = {
3720 struct rte_flow_item items[] = {
3721 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
3723 struct rte_flow_action_mark ftag = {
3726 struct mlx5_flow_action_copy_mreg cp_mreg = {
3730 struct rte_flow_action_jump jump = {
3731 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3733 struct rte_flow_action actions[] = {
3734 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
3736 struct mlx5_flow_mreg_copy_resource *mcp_res;
3740 /* Fill the register fileds in the flow. */
3741 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3745 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3749 /* Check if already registered. */
3750 MLX5_ASSERT(priv->mreg_cp_tbl);
3751 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
3753 /* For non-default rule. */
3754 if (mark_id != MLX5_DEFAULT_COPY_ID)
3756 MLX5_ASSERT(mark_id != MLX5_DEFAULT_COPY_ID ||
3757 mcp_res->refcnt == 1);
3760 /* Provide the full width of FLAG specific value. */
3761 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3762 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3763 /* Build a new flow. */
3764 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3765 items[0] = (struct rte_flow_item){
3766 .type = (enum rte_flow_item_type)
3767 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3770 items[1] = (struct rte_flow_item){
3771 .type = RTE_FLOW_ITEM_TYPE_END,
3773 actions[0] = (struct rte_flow_action){
3774 .type = (enum rte_flow_action_type)
3775 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3778 actions[1] = (struct rte_flow_action){
3779 .type = (enum rte_flow_action_type)
3780 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3783 actions[2] = (struct rte_flow_action){
3784 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3787 actions[3] = (struct rte_flow_action){
3788 .type = RTE_FLOW_ACTION_TYPE_END,
3791 /* Default rule, wildcard match. */
3792 attr.priority = MLX5_FLOW_PRIO_RSVD;
3793 items[0] = (struct rte_flow_item){
3794 .type = RTE_FLOW_ITEM_TYPE_END,
3796 actions[0] = (struct rte_flow_action){
3797 .type = (enum rte_flow_action_type)
3798 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3801 actions[1] = (struct rte_flow_action){
3802 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3805 actions[2] = (struct rte_flow_action){
3806 .type = RTE_FLOW_ACTION_TYPE_END,
3809 /* Build a new entry. */
3810 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3817 * The copy Flows are not included in any list. There
3818 * ones are referenced from other Flows and can not
3819 * be applied, removed, deleted in ardbitrary order
3820 * by list traversing.
3822 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3823 actions, false, error);
3824 if (!mcp_res->rix_flow)
3827 mcp_res->hlist_ent.key = mark_id;
3828 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3829 &mcp_res->hlist_ent);
3835 if (mcp_res->rix_flow)
3836 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3837 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3842 * Release flow in RX_CP_TBL.
3845 * Pointer to Ethernet device.
3847 * Parent flow for wich copying is provided.
3850 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3851 struct rte_flow *flow)
3853 struct mlx5_flow_mreg_copy_resource *mcp_res;
3854 struct mlx5_priv *priv = dev->data->dev_private;
3856 if (!flow->rix_mreg_copy)
3858 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3859 flow->rix_mreg_copy);
3860 if (!mcp_res || !priv->mreg_cp_tbl)
3862 if (flow->copy_applied) {
3863 MLX5_ASSERT(mcp_res->appcnt);
3864 flow->copy_applied = 0;
3866 if (!mcp_res->appcnt) {
3867 struct rte_flow *mcp_flow = mlx5_ipool_get
3868 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3872 flow_drv_remove(dev, mcp_flow);
3876 * We do not check availability of metadata registers here,
3877 * because copy resources are not allocated in this case.
3879 if (--mcp_res->refcnt)
3881 MLX5_ASSERT(mcp_res->rix_flow);
3882 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3883 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3884 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3885 flow->rix_mreg_copy = 0;
3889 * Start flow in RX_CP_TBL.
3892 * Pointer to Ethernet device.
3894 * Parent flow for wich copying is provided.
3897 * 0 on success, a negative errno value otherwise and rte_errno is set.
3900 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3901 struct rte_flow *flow)
3903 struct mlx5_flow_mreg_copy_resource *mcp_res;
3904 struct mlx5_priv *priv = dev->data->dev_private;
3907 if (!flow->rix_mreg_copy || flow->copy_applied)
3909 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3910 flow->rix_mreg_copy);
3913 if (!mcp_res->appcnt) {
3914 struct rte_flow *mcp_flow = mlx5_ipool_get
3915 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3919 ret = flow_drv_apply(dev, mcp_flow, NULL);
3925 flow->copy_applied = 1;
3930 * Stop flow in RX_CP_TBL.
3933 * Pointer to Ethernet device.
3935 * Parent flow for wich copying is provided.
3938 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3939 struct rte_flow *flow)
3941 struct mlx5_flow_mreg_copy_resource *mcp_res;
3942 struct mlx5_priv *priv = dev->data->dev_private;
3944 if (!flow->rix_mreg_copy || !flow->copy_applied)
3946 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3947 flow->rix_mreg_copy);
3950 MLX5_ASSERT(mcp_res->appcnt);
3952 flow->copy_applied = 0;
3953 if (!mcp_res->appcnt) {
3954 struct rte_flow *mcp_flow = mlx5_ipool_get
3955 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3959 flow_drv_remove(dev, mcp_flow);
3964 * Remove the default copy action from RX_CP_TBL.
3967 * Pointer to Ethernet device.
3970 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3972 struct mlx5_flow_mreg_copy_resource *mcp_res;
3973 struct mlx5_priv *priv = dev->data->dev_private;
3975 /* Check if default flow is registered. */
3976 if (!priv->mreg_cp_tbl)
3978 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3979 MLX5_DEFAULT_COPY_ID);
3982 MLX5_ASSERT(mcp_res->rix_flow);
3983 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3984 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3985 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3989 * Add the default copy action in in RX_CP_TBL.
3992 * Pointer to Ethernet device.
3994 * Perform verbose error reporting if not NULL.
3997 * 0 for success, negative value otherwise and rte_errno is set.
4000 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4001 struct rte_flow_error *error)
4003 struct mlx5_priv *priv = dev->data->dev_private;
4004 struct mlx5_flow_mreg_copy_resource *mcp_res;
4006 /* Check whether extensive metadata feature is engaged. */
4007 if (!priv->config.dv_flow_en ||
4008 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4009 !mlx5_flow_ext_mreg_supported(dev) ||
4010 !priv->sh->dv_regc0_mask)
4012 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
4019 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4021 * All the flow having Q/RSS action should be split by
4022 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4023 * performs the following,
4024 * - CQE->flow_tag := reg_c[1] (MARK)
4025 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4026 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4027 * but there should be a flow per each MARK ID set by MARK action.
4029 * For the aforementioned reason, if there's a MARK action in flow's action
4030 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4031 * the MARK ID to CQE's flow_tag like,
4032 * - If reg_c[1] is mark_id,
4033 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4035 * For SET_META action which stores value in reg_c[0], as the destination is
4036 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4037 * MARK ID means the default flow. The default flow looks like,
4038 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4041 * Pointer to Ethernet device.
4043 * Pointer to flow structure.
4044 * @param[in] actions
4045 * Pointer to the list of actions.
4047 * Perform verbose error reporting if not NULL.
4050 * 0 on success, negative value otherwise and rte_errno is set.
4053 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4054 struct rte_flow *flow,
4055 const struct rte_flow_action *actions,
4056 struct rte_flow_error *error)
4058 struct mlx5_priv *priv = dev->data->dev_private;
4059 struct mlx5_dev_config *config = &priv->config;
4060 struct mlx5_flow_mreg_copy_resource *mcp_res;
4061 const struct rte_flow_action_mark *mark;
4063 /* Check whether extensive metadata feature is engaged. */
4064 if (!config->dv_flow_en ||
4065 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4066 !mlx5_flow_ext_mreg_supported(dev) ||
4067 !priv->sh->dv_regc0_mask)
4069 /* Find MARK action. */
4070 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4071 switch (actions->type) {
4072 case RTE_FLOW_ACTION_TYPE_FLAG:
4073 mcp_res = flow_mreg_add_copy_action
4074 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4077 flow->rix_mreg_copy = mcp_res->idx;
4078 if (dev->data->dev_started) {
4080 flow->copy_applied = 1;
4083 case RTE_FLOW_ACTION_TYPE_MARK:
4084 mark = (const struct rte_flow_action_mark *)
4087 flow_mreg_add_copy_action(dev, mark->id, error);
4090 flow->rix_mreg_copy = mcp_res->idx;
4091 if (dev->data->dev_started) {
4093 flow->copy_applied = 1;
4103 #define MLX5_MAX_SPLIT_ACTIONS 24
4104 #define MLX5_MAX_SPLIT_ITEMS 24
4107 * Split the hairpin flow.
4108 * Since HW can't support encap and push-vlan on Rx, we move these
4110 * If the count action is after the encap then we also
4111 * move the count action. in this case the count will also measure
4115 * Pointer to Ethernet device.
4116 * @param[in] actions
4117 * Associated actions (list terminated by the END action).
4118 * @param[out] actions_rx
4120 * @param[out] actions_tx
4122 * @param[out] pattern_tx
4123 * The pattern items for the Tx flow.
4124 * @param[out] flow_id
4125 * The flow ID connected to this flow.
4131 flow_hairpin_split(struct rte_eth_dev *dev,
4132 const struct rte_flow_action actions[],
4133 struct rte_flow_action actions_rx[],
4134 struct rte_flow_action actions_tx[],
4135 struct rte_flow_item pattern_tx[],
4138 struct mlx5_priv *priv = dev->data->dev_private;
4139 const struct rte_flow_action_raw_encap *raw_encap;
4140 const struct rte_flow_action_raw_decap *raw_decap;
4141 struct mlx5_rte_flow_action_set_tag *set_tag;
4142 struct rte_flow_action *tag_action;
4143 struct mlx5_rte_flow_item_tag *tag_item;
4144 struct rte_flow_item *item;
4148 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
4149 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4150 switch (actions->type) {
4151 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4152 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4153 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4154 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4155 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4156 rte_memcpy(actions_tx, actions,
4157 sizeof(struct rte_flow_action));
4160 case RTE_FLOW_ACTION_TYPE_COUNT:
4162 rte_memcpy(actions_tx, actions,
4163 sizeof(struct rte_flow_action));
4166 rte_memcpy(actions_rx, actions,
4167 sizeof(struct rte_flow_action));
4171 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4172 raw_encap = actions->conf;
4173 if (raw_encap->size >
4174 (sizeof(struct rte_flow_item_eth) +
4175 sizeof(struct rte_flow_item_ipv4))) {
4176 memcpy(actions_tx, actions,
4177 sizeof(struct rte_flow_action));
4181 rte_memcpy(actions_rx, actions,
4182 sizeof(struct rte_flow_action));
4186 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4187 raw_decap = actions->conf;
4188 if (raw_decap->size <
4189 (sizeof(struct rte_flow_item_eth) +
4190 sizeof(struct rte_flow_item_ipv4))) {
4191 memcpy(actions_tx, actions,
4192 sizeof(struct rte_flow_action));
4195 rte_memcpy(actions_rx, actions,
4196 sizeof(struct rte_flow_action));
4201 rte_memcpy(actions_rx, actions,
4202 sizeof(struct rte_flow_action));
4207 /* Add set meta action and end action for the Rx flow. */
4208 tag_action = actions_rx;
4209 tag_action->type = (enum rte_flow_action_type)
4210 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4212 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4214 set_tag = (void *)actions_rx;
4215 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
4216 MLX5_ASSERT(set_tag->id > REG_NON);
4217 set_tag->data = *flow_id;
4218 tag_action->conf = set_tag;
4219 /* Create Tx item list. */
4220 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4221 addr = (void *)&pattern_tx[2];
4223 item->type = (enum rte_flow_item_type)
4224 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4225 tag_item = (void *)addr;
4226 tag_item->data = *flow_id;
4227 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4228 MLX5_ASSERT(set_tag->id > REG_NON);
4229 item->spec = tag_item;
4230 addr += sizeof(struct mlx5_rte_flow_item_tag);
4231 tag_item = (void *)addr;
4232 tag_item->data = UINT32_MAX;
4233 tag_item->id = UINT16_MAX;
4234 item->mask = tag_item;
4237 item->type = RTE_FLOW_ITEM_TYPE_END;
4242 union tunnel_offload_mark {
4245 uint32_t app_reserve:8;
4246 uint32_t table_id:15;
4247 uint32_t transfer:1;
4248 uint32_t _unused_:8;
4252 struct tunnel_default_miss_ctx {
4256 struct rte_flow_action_rss action_rss;
4257 struct rte_flow_action_queue miss_queue;
4258 struct rte_flow_action_jump miss_jump;
4264 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
4265 struct rte_flow *flow,
4266 const struct rte_flow_attr *attr,
4267 const struct rte_flow_action *app_actions,
4269 struct tunnel_default_miss_ctx *ctx,
4270 struct rte_flow_error *error)
4272 struct mlx5_priv *priv = dev->data->dev_private;
4273 struct mlx5_flow *dev_flow;
4274 struct rte_flow_attr miss_attr = *attr;
4275 const struct mlx5_flow_tunnel *tunnel = app_actions[0].conf;
4276 const struct rte_flow_item miss_items[2] = {
4278 .type = RTE_FLOW_ITEM_TYPE_ETH,
4284 .type = RTE_FLOW_ITEM_TYPE_END,
4290 union tunnel_offload_mark mark_id;
4291 struct rte_flow_action_mark miss_mark;
4292 struct rte_flow_action miss_actions[3] = {
4293 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
4294 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
4296 const struct rte_flow_action_jump *jump_data;
4297 uint32_t i, flow_table = 0; /* prevent compilation warning */
4298 struct flow_grp_info grp_info = {
4300 .transfer = attr->transfer,
4301 .fdb_def_rule = !!priv->fdb_def_rule,
4306 if (!attr->transfer) {
4309 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
4310 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
4311 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
4314 return rte_flow_error_set
4316 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4317 NULL, "invalid default miss RSS");
4318 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4319 ctx->action_rss.level = 0,
4320 ctx->action_rss.types = priv->rss_conf.rss_hf,
4321 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
4322 ctx->action_rss.queue_num = priv->reta_idx_n,
4323 ctx->action_rss.key = priv->rss_conf.rss_key,
4324 ctx->action_rss.queue = ctx->queue;
4325 if (!priv->reta_idx_n || !priv->rxqs_n)
4326 return rte_flow_error_set
4328 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4329 NULL, "invalid port configuration");
4330 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
4331 ctx->action_rss.types = 0;
4332 for (i = 0; i != priv->reta_idx_n; ++i)
4333 ctx->queue[i] = (*priv->reta_idx)[i];
4335 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
4336 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
4338 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
4339 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
4340 jump_data = app_actions->conf;
4341 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
4342 miss_attr.group = jump_data->group;
4343 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
4344 &flow_table, grp_info, error);
4346 return rte_flow_error_set(error, EINVAL,
4347 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4348 NULL, "invalid tunnel id");
4349 mark_id.app_reserve = 0;
4350 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
4351 mark_id.transfer = !!attr->transfer;
4352 mark_id._unused_ = 0;
4353 miss_mark.id = mark_id.val;
4354 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
4355 miss_items, miss_actions, flow_idx, error);
4358 dev_flow->flow = flow;
4359 dev_flow->external = true;
4360 dev_flow->tunnel = tunnel;
4361 /* Subflow object was created, we must include one in the list. */
4362 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4363 dev_flow->handle, next);
4365 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
4366 dev->data->port_id, tunnel->app_tunnel.type,
4367 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
4368 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
4369 miss_actions, error);
4371 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
4378 * The last stage of splitting chain, just creates the subflow
4379 * without any modification.
4382 * Pointer to Ethernet device.
4384 * Parent flow structure pointer.
4385 * @param[in, out] sub_flow
4386 * Pointer to return the created subflow, may be NULL.
4387 * @param[in] prefix_layers
4388 * Prefix subflow layers, may be 0.
4389 * @param[in] prefix_mark
4390 * Prefix subflow mark flag, may be 0.
4392 * Flow rule attributes.
4394 * Pattern specification (list terminated by the END pattern item).
4395 * @param[in] actions
4396 * Associated actions (list terminated by the END action).
4397 * @param[in] external
4398 * This flow rule is created by request external to PMD.
4399 * @param[in] flow_idx
4400 * This memory pool index to the flow.
4402 * Perform verbose error reporting if not NULL.
4404 * 0 on success, negative value otherwise
4407 flow_create_split_inner(struct rte_eth_dev *dev,
4408 struct rte_flow *flow,
4409 struct mlx5_flow **sub_flow,
4410 uint64_t prefix_layers,
4411 uint32_t prefix_mark,
4412 const struct rte_flow_attr *attr,
4413 const struct rte_flow_item items[],
4414 const struct rte_flow_action actions[],
4415 bool external, uint32_t flow_idx,
4416 struct rte_flow_error *error)
4418 struct mlx5_flow *dev_flow;
4420 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4424 dev_flow->flow = flow;
4425 dev_flow->external = external;
4426 /* Subflow object was created, we must include one in the list. */
4427 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4428 dev_flow->handle, next);
4430 * If dev_flow is as one of the suffix flow, some actions in suffix
4431 * flow may need some user defined item layer flags, and pass the
4432 * Metadate rxq mark flag to suffix flow as well.
4435 dev_flow->handle->layers = prefix_layers;
4437 dev_flow->handle->mark = 1;
4439 *sub_flow = dev_flow;
4440 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4444 * Split the meter flow.
4446 * As meter flow will split to three sub flow, other than meter
4447 * action, the other actions make sense to only meter accepts
4448 * the packet. If it need to be dropped, no other additional
4449 * actions should be take.
4451 * One kind of special action which decapsulates the L3 tunnel
4452 * header will be in the prefix sub flow, as not to take the
4453 * L3 tunnel header into account.
4456 * Pointer to Ethernet device.
4458 * Pattern specification (list terminated by the END pattern item).
4459 * @param[out] sfx_items
4460 * Suffix flow match items (list terminated by the END pattern item).
4461 * @param[in] actions
4462 * Associated actions (list terminated by the END action).
4463 * @param[out] actions_sfx
4464 * Suffix flow actions.
4465 * @param[out] actions_pre
4466 * Prefix flow actions.
4467 * @param[out] pattern_sfx
4468 * The pattern items for the suffix flow.
4469 * @param[out] tag_sfx
4470 * Pointer to suffix flow tag.
4476 flow_meter_split_prep(struct rte_eth_dev *dev,
4477 const struct rte_flow_item items[],
4478 struct rte_flow_item sfx_items[],
4479 const struct rte_flow_action actions[],
4480 struct rte_flow_action actions_sfx[],
4481 struct rte_flow_action actions_pre[])
4483 struct rte_flow_action *tag_action = NULL;
4484 struct rte_flow_item *tag_item;
4485 struct mlx5_rte_flow_action_set_tag *set_tag;
4486 struct rte_flow_error error;
4487 const struct rte_flow_action_raw_encap *raw_encap;
4488 const struct rte_flow_action_raw_decap *raw_decap;
4489 struct mlx5_rte_flow_item_tag *tag_spec;
4490 struct mlx5_rte_flow_item_tag *tag_mask;
4492 bool copy_vlan = false;
4494 /* Prepare the actions for prefix and suffix flow. */
4495 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4496 struct rte_flow_action **action_cur = NULL;
4498 switch (actions->type) {
4499 case RTE_FLOW_ACTION_TYPE_METER:
4500 /* Add the extra tag action first. */
4501 tag_action = actions_pre;
4502 tag_action->type = (enum rte_flow_action_type)
4503 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4505 action_cur = &actions_pre;
4507 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4508 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4509 action_cur = &actions_pre;
4511 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4512 raw_encap = actions->conf;
4513 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4514 action_cur = &actions_pre;
4516 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4517 raw_decap = actions->conf;
4518 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4519 action_cur = &actions_pre;
4521 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4522 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4529 action_cur = &actions_sfx;
4530 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
4533 /* Add end action to the actions. */
4534 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4535 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4538 set_tag = (void *)actions_pre;
4539 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4541 * Get the id from the qrss_pool to make qrss share the id with meter.
4543 tag_id = flow_qrss_get_id(dev);
4544 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
4546 tag_action->conf = set_tag;
4547 /* Prepare the suffix subflow items. */
4548 tag_item = sfx_items++;
4549 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4550 int item_type = items->type;
4552 switch (item_type) {
4553 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4554 memcpy(sfx_items, items, sizeof(*sfx_items));
4557 case RTE_FLOW_ITEM_TYPE_VLAN:
4559 memcpy(sfx_items, items, sizeof(*sfx_items));
4561 * Convert to internal match item, it is used
4562 * for vlan push and set vid.
4564 sfx_items->type = (enum rte_flow_item_type)
4565 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4573 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4575 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4576 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
4577 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4578 tag_mask = tag_spec + 1;
4579 tag_mask->data = 0xffffff00;
4580 tag_item->type = (enum rte_flow_item_type)
4581 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4582 tag_item->spec = tag_spec;
4583 tag_item->last = NULL;
4584 tag_item->mask = tag_mask;
4589 * Split action list having QUEUE/RSS for metadata register copy.
4591 * Once Q/RSS action is detected in user's action list, the flow action
4592 * should be split in order to copy metadata registers, which will happen in
4594 * - CQE->flow_tag := reg_c[1] (MARK)
4595 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4596 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
4597 * This is because the last action of each flow must be a terminal action
4598 * (QUEUE, RSS or DROP).
4600 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
4601 * stored and kept in the mlx5_flow structure per each sub_flow.
4603 * The Q/RSS action is replaced with,
4604 * - SET_TAG, setting the allocated flow ID to reg_c[2].
4605 * And the following JUMP action is added at the end,
4606 * - JUMP, to RX_CP_TBL.
4608 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
4609 * flow_create_split_metadata() routine. The flow will look like,
4610 * - If flow ID matches (reg_c[2]), perform Q/RSS.
4613 * Pointer to Ethernet device.
4614 * @param[out] split_actions
4615 * Pointer to store split actions to jump to CP_TBL.
4616 * @param[in] actions
4617 * Pointer to the list of original flow actions.
4619 * Pointer to the Q/RSS action.
4620 * @param[in] actions_n
4621 * Number of original actions.
4623 * Perform verbose error reporting if not NULL.
4626 * non-zero unique flow_id on success, otherwise 0 and
4627 * error/rte_error are set.
4630 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
4631 struct rte_flow_action *split_actions,
4632 const struct rte_flow_action *actions,
4633 const struct rte_flow_action *qrss,
4634 int actions_n, struct rte_flow_error *error)
4636 struct mlx5_rte_flow_action_set_tag *set_tag;
4637 struct rte_flow_action_jump *jump;
4638 const int qrss_idx = qrss - actions;
4639 uint32_t flow_id = 0;
4643 * Given actions will be split
4644 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
4645 * - Add jump to mreg CP_TBL.
4646 * As a result, there will be one more action.
4649 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
4650 set_tag = (void *)(split_actions + actions_n);
4652 * If tag action is not set to void(it means we are not the meter
4653 * suffix flow), add the tag action. Since meter suffix flow already
4654 * has the tag added.
4656 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
4658 * Allocate the new subflow ID. This one is unique within
4659 * device and not shared with representors. Otherwise,
4660 * we would have to resolve multi-thread access synch
4661 * issue. Each flow on the shared device is appended
4662 * with source vport identifier, so the resulting
4663 * flows will be unique in the shared (by master and
4664 * representors) domain even if they have coinciding
4667 flow_id = flow_qrss_get_id(dev);
4669 return rte_flow_error_set(error, ENOMEM,
4670 RTE_FLOW_ERROR_TYPE_ACTION,
4671 NULL, "can't allocate id "
4672 "for split Q/RSS subflow");
4673 /* Internal SET_TAG action to set flow ID. */
4674 *set_tag = (struct mlx5_rte_flow_action_set_tag){
4677 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
4681 /* Construct new actions array. */
4682 /* Replace QUEUE/RSS action. */
4683 split_actions[qrss_idx] = (struct rte_flow_action){
4684 .type = (enum rte_flow_action_type)
4685 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4689 /* JUMP action to jump to mreg copy table (CP_TBL). */
4690 jump = (void *)(set_tag + 1);
4691 *jump = (struct rte_flow_action_jump){
4692 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4694 split_actions[actions_n - 2] = (struct rte_flow_action){
4695 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4698 split_actions[actions_n - 1] = (struct rte_flow_action){
4699 .type = RTE_FLOW_ACTION_TYPE_END,
4705 * Extend the given action list for Tx metadata copy.
4707 * Copy the given action list to the ext_actions and add flow metadata register
4708 * copy action in order to copy reg_a set by WQE to reg_c[0].
4710 * @param[out] ext_actions
4711 * Pointer to the extended action list.
4712 * @param[in] actions
4713 * Pointer to the list of actions.
4714 * @param[in] actions_n
4715 * Number of actions in the list.
4717 * Perform verbose error reporting if not NULL.
4718 * @param[in] encap_idx
4719 * The encap action inndex.
4722 * 0 on success, negative value otherwise
4725 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
4726 struct rte_flow_action *ext_actions,
4727 const struct rte_flow_action *actions,
4728 int actions_n, struct rte_flow_error *error,
4731 struct mlx5_flow_action_copy_mreg *cp_mreg =
4732 (struct mlx5_flow_action_copy_mreg *)
4733 (ext_actions + actions_n + 1);
4736 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4740 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
4745 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
4746 if (encap_idx == actions_n - 1) {
4747 ext_actions[actions_n - 1] = (struct rte_flow_action){
4748 .type = (enum rte_flow_action_type)
4749 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4752 ext_actions[actions_n] = (struct rte_flow_action){
4753 .type = RTE_FLOW_ACTION_TYPE_END,
4756 ext_actions[encap_idx] = (struct rte_flow_action){
4757 .type = (enum rte_flow_action_type)
4758 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4761 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
4762 sizeof(*ext_actions) * (actions_n - encap_idx));
4768 * Check the match action from the action list.
4770 * @param[in] actions
4771 * Pointer to the list of actions.
4773 * Flow rule attributes.
4775 * The action to be check if exist.
4776 * @param[out] match_action_pos
4777 * Pointer to the position of the matched action if exists, otherwise is -1.
4778 * @param[out] qrss_action_pos
4779 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
4782 * > 0 the total number of actions.
4783 * 0 if not found match action in action list.
4786 flow_check_match_action(const struct rte_flow_action actions[],
4787 const struct rte_flow_attr *attr,
4788 enum rte_flow_action_type action,
4789 int *match_action_pos, int *qrss_action_pos)
4791 const struct rte_flow_action_sample *sample;
4798 *match_action_pos = -1;
4799 *qrss_action_pos = -1;
4800 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4801 if (actions->type == action) {
4803 *match_action_pos = actions_n;
4805 if (actions->type == RTE_FLOW_ACTION_TYPE_QUEUE ||
4806 actions->type == RTE_FLOW_ACTION_TYPE_RSS)
4807 *qrss_action_pos = actions_n;
4808 if (actions->type == RTE_FLOW_ACTION_TYPE_JUMP)
4810 if (actions->type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
4811 sample = actions->conf;
4812 ratio = sample->ratio;
4813 sub_type = ((const struct rte_flow_action *)
4814 (sample->actions))->type;
4818 if (flag && action == RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) {
4820 /* JUMP Action not support for Mirroring;
4821 * Mirroring support multi-destination;
4823 if (!jump_flag && sub_type != RTE_FLOW_ACTION_TYPE_END)
4827 /* Count RTE_FLOW_ACTION_TYPE_END. */
4828 return flag ? actions_n + 1 : 0;
4831 #define SAMPLE_SUFFIX_ITEM 2
4834 * Split the sample flow.
4836 * As sample flow will split to two sub flow, sample flow with
4837 * sample action, the other actions will move to new suffix flow.
4839 * Also add unique tag id with tag action in the sample flow,
4840 * the same tag id will be as match in the suffix flow.
4843 * Pointer to Ethernet device.
4845 * FDB egress flow flag.
4846 * @param[out] sfx_items
4847 * Suffix flow match items (list terminated by the END pattern item).
4848 * @param[in] actions
4849 * Associated actions (list terminated by the END action).
4850 * @param[out] actions_sfx
4851 * Suffix flow actions.
4852 * @param[out] actions_pre
4853 * Prefix flow actions.
4854 * @param[in] actions_n
4855 * The total number of actions.
4856 * @param[in] sample_action_pos
4857 * The sample action position.
4858 * @param[in] qrss_action_pos
4859 * The Queue/RSS action position.
4861 * Perform verbose error reporting if not NULL.
4864 * 0 on success, or unique flow_id, a negative errno value
4865 * otherwise and rte_errno is set.
4868 flow_sample_split_prep(struct rte_eth_dev *dev,
4870 struct rte_flow_item sfx_items[],
4871 const struct rte_flow_action actions[],
4872 struct rte_flow_action actions_sfx[],
4873 struct rte_flow_action actions_pre[],
4875 int sample_action_pos,
4876 int qrss_action_pos,
4877 struct rte_flow_error *error)
4879 struct mlx5_rte_flow_action_set_tag *set_tag;
4880 struct mlx5_rte_flow_item_tag *tag_spec;
4881 struct mlx5_rte_flow_item_tag *tag_mask;
4882 uint32_t tag_id = 0;
4886 if (sample_action_pos < 0)
4887 return rte_flow_error_set(error, EINVAL,
4888 RTE_FLOW_ERROR_TYPE_ACTION,
4889 NULL, "invalid position of sample "
4892 /* Prepare the prefix tag action. */
4893 set_tag = (void *)(actions_pre + actions_n + 1);
4894 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
4898 tag_id = flow_qrss_get_id(dev);
4899 set_tag->data = tag_id;
4900 /* Prepare the suffix subflow items. */
4901 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
4902 tag_spec->data = tag_id;
4903 tag_spec->id = set_tag->id;
4904 tag_mask = tag_spec + 1;
4905 tag_mask->data = UINT32_MAX;
4906 sfx_items[0] = (struct rte_flow_item){
4907 .type = (enum rte_flow_item_type)
4908 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4913 sfx_items[1] = (struct rte_flow_item){
4914 .type = (enum rte_flow_item_type)
4915 RTE_FLOW_ITEM_TYPE_END,
4918 /* Prepare the actions for prefix and suffix flow. */
4919 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
4920 index = qrss_action_pos;
4921 /* Put the preceding the Queue/RSS action into prefix flow. */
4923 memcpy(actions_pre, actions,
4924 sizeof(struct rte_flow_action) * index);
4925 /* Put others preceding the sample action into prefix flow. */
4926 if (sample_action_pos > index + 1)
4927 memcpy(actions_pre + index, actions + index + 1,
4928 sizeof(struct rte_flow_action) *
4929 (sample_action_pos - index - 1));
4930 index = sample_action_pos - 1;
4931 /* Put Queue/RSS action into Suffix flow. */
4932 memcpy(actions_sfx, actions + qrss_action_pos,
4933 sizeof(struct rte_flow_action));
4936 index = sample_action_pos;
4938 memcpy(actions_pre, actions,
4939 sizeof(struct rte_flow_action) * index);
4941 /* Add the extra tag action for NIC-RX and E-Switch ingress. */
4943 actions_pre[index++] =
4944 (struct rte_flow_action){
4945 .type = (enum rte_flow_action_type)
4946 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4950 memcpy(actions_pre + index, actions + sample_action_pos,
4951 sizeof(struct rte_flow_action));
4953 actions_pre[index] = (struct rte_flow_action){
4954 .type = (enum rte_flow_action_type)
4955 RTE_FLOW_ACTION_TYPE_END,
4957 /* Put the actions after sample into Suffix flow. */
4958 memcpy(actions_sfx, actions + sample_action_pos + 1,
4959 sizeof(struct rte_flow_action) *
4960 (actions_n - sample_action_pos - 1));
4965 * The splitting for metadata feature.
4967 * - Q/RSS action on NIC Rx should be split in order to pass by
4968 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4969 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4971 * - All the actions on NIC Tx should have a mreg copy action to
4972 * copy reg_a from WQE to reg_c[0].
4975 * Pointer to Ethernet device.
4977 * Parent flow structure pointer.
4978 * @param[in] prefix_layers
4979 * Prefix flow layer flags.
4980 * @param[in] prefix_mark
4981 * Prefix subflow mark flag, may be 0.
4983 * Flow rule attributes.
4985 * Pattern specification (list terminated by the END pattern item).
4986 * @param[in] actions
4987 * Associated actions (list terminated by the END action).
4988 * @param[in] external
4989 * This flow rule is created by request external to PMD.
4990 * @param[in] flow_idx
4991 * This memory pool index to the flow.
4993 * Perform verbose error reporting if not NULL.
4995 * 0 on success, negative value otherwise
4998 flow_create_split_metadata(struct rte_eth_dev *dev,
4999 struct rte_flow *flow,
5000 uint64_t prefix_layers,
5001 uint32_t prefix_mark,
5002 const struct rte_flow_attr *attr,
5003 const struct rte_flow_item items[],
5004 const struct rte_flow_action actions[],
5005 bool external, uint32_t flow_idx,
5006 struct rte_flow_error *error)
5008 struct mlx5_priv *priv = dev->data->dev_private;
5009 struct mlx5_dev_config *config = &priv->config;
5010 const struct rte_flow_action *qrss = NULL;
5011 struct rte_flow_action *ext_actions = NULL;
5012 struct mlx5_flow *dev_flow = NULL;
5013 uint32_t qrss_id = 0;
5020 /* Check whether extensive metadata feature is engaged. */
5021 if (!config->dv_flow_en ||
5022 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5023 !mlx5_flow_ext_mreg_supported(dev))
5024 return flow_create_split_inner(dev, flow, NULL, prefix_layers,
5025 prefix_mark, attr, items,
5026 actions, external, flow_idx,
5028 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5031 /* Exclude hairpin flows from splitting. */
5032 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5033 const struct rte_flow_action_queue *queue;
5036 if (mlx5_rxq_get_type(dev, queue->index) ==
5037 MLX5_RXQ_TYPE_HAIRPIN)
5039 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5040 const struct rte_flow_action_rss *rss;
5043 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5044 MLX5_RXQ_TYPE_HAIRPIN)
5049 /* Check if it is in meter suffix table. */
5050 mtr_sfx = attr->group == (attr->transfer ?
5051 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
5052 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
5054 * Q/RSS action on NIC Rx should be split in order to pass by
5055 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5056 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5058 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5059 sizeof(struct rte_flow_action_set_tag) +
5060 sizeof(struct rte_flow_action_jump);
5061 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5064 return rte_flow_error_set(error, ENOMEM,
5065 RTE_FLOW_ERROR_TYPE_ACTION,
5066 NULL, "no memory to split "
5069 * If we are the suffix flow of meter, tag already exist.
5070 * Set the tag action to void.
5073 ext_actions[qrss - actions].type =
5074 RTE_FLOW_ACTION_TYPE_VOID;
5076 ext_actions[qrss - actions].type =
5077 (enum rte_flow_action_type)
5078 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5080 * Create the new actions list with removed Q/RSS action
5081 * and appended set tag and jump to register copy table
5082 * (RX_CP_TBL). We should preallocate unique tag ID here
5083 * in advance, because it is needed for set tag action.
5085 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5086 qrss, actions_n, error);
5087 if (!mtr_sfx && !qrss_id) {
5091 } else if (attr->egress && !attr->transfer) {
5093 * All the actions on NIC Tx should have a metadata register
5094 * copy action to copy reg_a from WQE to reg_c[meta]
5096 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5097 sizeof(struct mlx5_flow_action_copy_mreg);
5098 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5101 return rte_flow_error_set(error, ENOMEM,
5102 RTE_FLOW_ERROR_TYPE_ACTION,
5103 NULL, "no memory to split "
5105 /* Create the action list appended with copy register. */
5106 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5107 actions_n, error, encap_idx);
5111 /* Add the unmodified original or prefix subflow. */
5112 ret = flow_create_split_inner(dev, flow, &dev_flow, prefix_layers,
5114 items, ext_actions ? ext_actions :
5115 actions, external, flow_idx, error);
5118 MLX5_ASSERT(dev_flow);
5120 const struct rte_flow_attr q_attr = {
5121 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5124 /* Internal PMD action to set register. */
5125 struct mlx5_rte_flow_item_tag q_tag_spec = {
5129 struct rte_flow_item q_items[] = {
5131 .type = (enum rte_flow_item_type)
5132 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5133 .spec = &q_tag_spec,
5138 .type = RTE_FLOW_ITEM_TYPE_END,
5141 struct rte_flow_action q_actions[] = {
5147 .type = RTE_FLOW_ACTION_TYPE_END,
5150 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5153 * Configure the tag item only if there is no meter subflow.
5154 * Since tag is already marked in the meter suffix subflow
5155 * we can just use the meter suffix items as is.
5158 /* Not meter subflow. */
5159 MLX5_ASSERT(!mtr_sfx);
5161 * Put unique id in prefix flow due to it is destroyed
5162 * after suffix flow and id will be freed after there
5163 * is no actual flows with this id and identifier
5164 * reallocation becomes possible (for example, for
5165 * other flows in other threads).
5167 dev_flow->handle->split_flow_id = qrss_id;
5168 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5172 q_tag_spec.id = ret;
5175 /* Add suffix subflow to execute Q/RSS. */
5176 ret = flow_create_split_inner(dev, flow, &dev_flow, layers, 0,
5177 &q_attr, mtr_sfx ? items :
5179 external, flow_idx, error);
5182 /* qrss ID should be freed if failed. */
5184 MLX5_ASSERT(dev_flow);
5189 * We do not destroy the partially created sub_flows in case of error.
5190 * These ones are included into parent flow list and will be destroyed
5191 * by flow_drv_destroy.
5193 flow_qrss_free_id(dev, qrss_id);
5194 mlx5_free(ext_actions);
5199 * The splitting for meter feature.
5201 * - The meter flow will be split to two flows as prefix and
5202 * suffix flow. The packets make sense only it pass the prefix
5205 * - Reg_C_5 is used for the packet to match betweend prefix and
5209 * Pointer to Ethernet device.
5211 * Parent flow structure pointer.
5212 * @param[in] prefix_layers
5213 * Prefix subflow layers, may be 0.
5214 * @param[in] prefix_mark
5215 * Prefix subflow mark flag, may be 0.
5217 * Flow rule attributes.
5219 * Pattern specification (list terminated by the END pattern item).
5220 * @param[in] actions
5221 * Associated actions (list terminated by the END action).
5222 * @param[in] external
5223 * This flow rule is created by request external to PMD.
5224 * @param[in] flow_idx
5225 * This memory pool index to the flow.
5227 * Perform verbose error reporting if not NULL.
5229 * 0 on success, negative value otherwise
5232 flow_create_split_meter(struct rte_eth_dev *dev,
5233 struct rte_flow *flow,
5234 uint64_t prefix_layers,
5235 uint32_t prefix_mark,
5236 const struct rte_flow_attr *attr,
5237 const struct rte_flow_item items[],
5238 const struct rte_flow_action actions[],
5239 bool external, uint32_t flow_idx,
5240 struct rte_flow_error *error)
5242 struct mlx5_priv *priv = dev->data->dev_private;
5243 struct rte_flow_action *sfx_actions = NULL;
5244 struct rte_flow_action *pre_actions = NULL;
5245 struct rte_flow_item *sfx_items = NULL;
5246 struct mlx5_flow *dev_flow = NULL;
5247 struct rte_flow_attr sfx_attr = *attr;
5249 uint32_t mtr_tag_id = 0;
5256 actions_n = flow_check_meter_action(actions, &mtr);
5258 /* The five prefix actions: meter, decap, encap, tag, end. */
5259 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
5260 sizeof(struct mlx5_rte_flow_action_set_tag);
5261 /* tag, vlan, port id, end. */
5262 #define METER_SUFFIX_ITEM 4
5263 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5264 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5265 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5268 return rte_flow_error_set(error, ENOMEM,
5269 RTE_FLOW_ERROR_TYPE_ACTION,
5270 NULL, "no memory to split "
5272 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5274 pre_actions = sfx_actions + actions_n;
5275 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
5276 actions, sfx_actions,
5282 /* Add the prefix subflow. */
5283 ret = flow_create_split_inner(dev, flow, &dev_flow,
5286 pre_actions, external,
5292 dev_flow->handle->split_flow_id = mtr_tag_id;
5293 /* Setting the sfx group atrr. */
5294 sfx_attr.group = sfx_attr.transfer ?
5295 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
5296 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
5298 /* Add the prefix subflow. */
5299 ret = flow_create_split_metadata(dev, flow, dev_flow ?
5300 flow_get_prefix_layer_flags(dev_flow) :
5301 prefix_layers, dev_flow ?
5302 dev_flow->handle->mark : prefix_mark,
5303 &sfx_attr, sfx_items ?
5305 sfx_actions ? sfx_actions : actions,
5306 external, flow_idx, error);
5309 mlx5_free(sfx_actions);
5314 * The splitting for sample feature.
5316 * Once Sample action is detected in the action list, the flow actions should
5317 * be split into prefix sub flow and suffix sub flow.
5319 * The original items remain in the prefix sub flow, all actions preceding the
5320 * sample action and the sample action itself will be copied to the prefix
5321 * sub flow, the actions following the sample action will be copied to the
5322 * suffix sub flow, Queue action always be located in the suffix sub flow.
5324 * In order to make the packet from prefix sub flow matches with suffix sub
5325 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5326 * flow uses tag item with the unique flow id.
5329 * Pointer to Ethernet device.
5331 * Parent flow structure pointer.
5333 * Flow rule attributes.
5335 * Pattern specification (list terminated by the END pattern item).
5336 * @param[in] actions
5337 * Associated actions (list terminated by the END action).
5338 * @param[in] external
5339 * This flow rule is created by request external to PMD.
5340 * @param[in] flow_idx
5341 * This memory pool index to the flow.
5343 * Perform verbose error reporting if not NULL.
5345 * 0 on success, negative value otherwise
5348 flow_create_split_sample(struct rte_eth_dev *dev,
5349 struct rte_flow *flow,
5350 const struct rte_flow_attr *attr,
5351 const struct rte_flow_item items[],
5352 const struct rte_flow_action actions[],
5353 bool external, uint32_t flow_idx,
5354 struct rte_flow_error *error)
5356 struct mlx5_priv *priv = dev->data->dev_private;
5357 struct rte_flow_action *sfx_actions = NULL;
5358 struct rte_flow_action *pre_actions = NULL;
5359 struct rte_flow_item *sfx_items = NULL;
5360 struct mlx5_flow *dev_flow = NULL;
5361 struct rte_flow_attr sfx_attr = *attr;
5362 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5363 struct mlx5_flow_dv_sample_resource *sample_res;
5364 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
5365 struct mlx5_flow_tbl_resource *sfx_tbl;
5366 union mlx5_flow_tbl_key sfx_table_key;
5370 uint32_t fdb_tx = 0;
5373 int sample_action_pos;
5374 int qrss_action_pos;
5377 if (priv->sampler_en)
5378 actions_n = flow_check_match_action(actions, attr,
5379 RTE_FLOW_ACTION_TYPE_SAMPLE,
5380 &sample_action_pos, &qrss_action_pos);
5382 /* The prefix actions must includes sample, tag, end. */
5383 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
5384 + sizeof(struct mlx5_rte_flow_action_set_tag);
5385 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
5386 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5387 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
5388 item_size), 0, SOCKET_ID_ANY);
5390 return rte_flow_error_set(error, ENOMEM,
5391 RTE_FLOW_ERROR_TYPE_ACTION,
5392 NULL, "no memory to split "
5394 /* The representor_id is -1 for uplink. */
5395 fdb_tx = (attr->transfer && priv->representor_id != -1);
5397 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
5399 pre_actions = sfx_actions + actions_n;
5400 tag_id = flow_sample_split_prep(dev, fdb_tx, sfx_items,
5401 actions, sfx_actions,
5402 pre_actions, actions_n,
5404 qrss_action_pos, error);
5405 if (tag_id < 0 || (!fdb_tx && !tag_id)) {
5409 /* Add the prefix subflow. */
5410 ret = flow_create_split_inner(dev, flow, &dev_flow, 0, 0, attr,
5411 items, pre_actions, external,
5417 dev_flow->handle->split_flow_id = tag_id;
5418 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5419 /* Set the sfx group attr. */
5420 sample_res = (struct mlx5_flow_dv_sample_resource *)
5421 dev_flow->dv.sample_res;
5422 sfx_tbl = (struct mlx5_flow_tbl_resource *)
5423 sample_res->normal_path_tbl;
5424 sfx_tbl_data = container_of(sfx_tbl,
5425 struct mlx5_flow_tbl_data_entry, tbl);
5426 sfx_table_key.v64 = sfx_tbl_data->entry.key;
5427 sfx_attr.group = sfx_attr.transfer ?
5428 (sfx_table_key.table_id - 1) :
5429 sfx_table_key.table_id;
5432 /* Add the suffix subflow. */
5433 ret = flow_create_split_meter(dev, flow, dev_flow ?
5434 flow_get_prefix_layer_flags(dev_flow) : 0,
5435 dev_flow ? dev_flow->handle->mark : 0,
5436 &sfx_attr, sfx_items ? sfx_items : items,
5437 sfx_actions ? sfx_actions : actions,
5438 external, flow_idx, error);
5441 mlx5_free(sfx_actions);
5446 * Split the flow to subflow set. The splitters might be linked
5447 * in the chain, like this:
5448 * flow_create_split_outer() calls:
5449 * flow_create_split_meter() calls:
5450 * flow_create_split_metadata(meter_subflow_0) calls:
5451 * flow_create_split_inner(metadata_subflow_0)
5452 * flow_create_split_inner(metadata_subflow_1)
5453 * flow_create_split_inner(metadata_subflow_2)
5454 * flow_create_split_metadata(meter_subflow_1) calls:
5455 * flow_create_split_inner(metadata_subflow_0)
5456 * flow_create_split_inner(metadata_subflow_1)
5457 * flow_create_split_inner(metadata_subflow_2)
5459 * This provide flexible way to add new levels of flow splitting.
5460 * The all of successfully created subflows are included to the
5461 * parent flow dev_flow list.
5464 * Pointer to Ethernet device.
5466 * Parent flow structure pointer.
5468 * Flow rule attributes.
5470 * Pattern specification (list terminated by the END pattern item).
5471 * @param[in] actions
5472 * Associated actions (list terminated by the END action).
5473 * @param[in] external
5474 * This flow rule is created by request external to PMD.
5475 * @param[in] flow_idx
5476 * This memory pool index to the flow.
5478 * Perform verbose error reporting if not NULL.
5480 * 0 on success, negative value otherwise
5483 flow_create_split_outer(struct rte_eth_dev *dev,
5484 struct rte_flow *flow,
5485 const struct rte_flow_attr *attr,
5486 const struct rte_flow_item items[],
5487 const struct rte_flow_action actions[],
5488 bool external, uint32_t flow_idx,
5489 struct rte_flow_error *error)
5493 ret = flow_create_split_sample(dev, flow, attr, items,
5494 actions, external, flow_idx, error);
5495 MLX5_ASSERT(ret <= 0);
5499 static struct mlx5_flow_tunnel *
5500 flow_tunnel_from_rule(struct rte_eth_dev *dev,
5501 const struct rte_flow_attr *attr,
5502 const struct rte_flow_item items[],
5503 const struct rte_flow_action actions[])
5505 struct mlx5_flow_tunnel *tunnel;
5507 #pragma GCC diagnostic push
5508 #pragma GCC diagnostic ignored "-Wcast-qual"
5509 if (is_flow_tunnel_match_rule(dev, attr, items, actions))
5510 tunnel = (struct mlx5_flow_tunnel *)items[0].spec;
5511 else if (is_flow_tunnel_steer_rule(dev, attr, items, actions))
5512 tunnel = (struct mlx5_flow_tunnel *)actions[0].conf;
5515 #pragma GCC diagnostic pop
5521 * Create a flow and add it to @p list.
5524 * Pointer to Ethernet device.
5526 * Pointer to a TAILQ flow list. If this parameter NULL,
5527 * no list insertion occurred, flow is just created,
5528 * this is caller's responsibility to track the
5531 * Flow rule attributes.
5533 * Pattern specification (list terminated by the END pattern item).
5534 * @param[in] actions
5535 * Associated actions (list terminated by the END action).
5536 * @param[in] external
5537 * This flow rule is created by request external to PMD.
5539 * Perform verbose error reporting if not NULL.
5542 * A flow index on success, 0 otherwise and rte_errno is set.
5545 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
5546 const struct rte_flow_attr *attr,
5547 const struct rte_flow_item items[],
5548 const struct rte_flow_action original_actions[],
5549 bool external, struct rte_flow_error *error)
5551 struct mlx5_priv *priv = dev->data->dev_private;
5552 struct rte_flow *flow = NULL;
5553 struct mlx5_flow *dev_flow;
5554 const struct rte_flow_action_rss *rss;
5555 struct mlx5_translated_shared_action
5556 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5557 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5559 struct mlx5_flow_expand_rss buf;
5560 uint8_t buffer[2048];
5563 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5564 uint8_t buffer[2048];
5567 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5568 uint8_t buffer[2048];
5569 } actions_hairpin_tx;
5571 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
5572 uint8_t buffer[2048];
5574 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
5575 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
5576 priv->rss_desc)[!!priv->flow_idx];
5577 const struct rte_flow_action *p_actions_rx;
5581 uint32_t hairpin_id = 0;
5582 struct rte_flow_attr attr_tx = { .priority = 0 };
5583 struct rte_flow_attr attr_factor = {0};
5584 const struct rte_flow_action *actions;
5585 struct rte_flow_action *translated_actions = NULL;
5586 struct mlx5_flow_tunnel *tunnel;
5587 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
5588 int ret = flow_shared_actions_translate(original_actions,
5591 &translated_actions, error);
5594 MLX5_ASSERT(translated_actions == NULL);
5597 actions = translated_actions ? translated_actions : original_actions;
5598 memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
5599 p_actions_rx = actions;
5600 hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
5601 ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
5602 external, hairpin_flow, error);
5604 goto error_before_hairpin_split;
5605 if (hairpin_flow > 0) {
5606 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
5608 goto error_before_hairpin_split;
5610 flow_hairpin_split(dev, actions, actions_rx.actions,
5611 actions_hairpin_tx.actions, items_tx.items,
5613 p_actions_rx = actions_rx.actions;
5615 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
5618 goto error_before_flow;
5620 flow->drv_type = flow_get_drv_type(dev, &attr_factor);
5621 if (hairpin_id != 0)
5622 flow->hairpin_flow_id = hairpin_id;
5623 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
5624 flow->drv_type < MLX5_FLOW_TYPE_MAX);
5625 memset(rss_desc, 0, sizeof(*rss_desc));
5626 rss = flow_get_rss_action(p_actions_rx);
5629 * The following information is required by
5630 * mlx5_flow_hashfields_adjust() in advance.
5632 rss_desc->level = rss->level;
5633 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
5634 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
5636 flow->dev_handles = 0;
5637 if (rss && rss->types) {
5638 unsigned int graph_root;
5640 graph_root = find_graph_root(items, rss->level);
5641 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
5643 mlx5_support_expansion, graph_root);
5644 MLX5_ASSERT(ret > 0 &&
5645 (unsigned int)ret < sizeof(expand_buffer.buffer));
5648 buf->entry[0].pattern = (void *)(uintptr_t)items;
5650 flow->shared_rss = flow_get_shared_rss_action(shared_actions,
5653 * Record the start index when there is a nested call. All sub-flows
5654 * need to be translated before another calling.
5655 * No need to use ping-pong buffer to save memory here.
5657 if (priv->flow_idx) {
5658 MLX5_ASSERT(!priv->flow_nested_idx);
5659 priv->flow_nested_idx = priv->flow_idx;
5661 for (i = 0; i < buf->entries; ++i) {
5663 * The splitter may create multiple dev_flows,
5664 * depending on configuration. In the simplest
5665 * case it just creates unmodified original flow.
5667 ret = flow_create_split_outer(dev, flow, &attr_factor,
5668 buf->entry[i].pattern,
5669 p_actions_rx, external, idx,
5673 if (is_flow_tunnel_steer_rule(dev, attr,
5674 buf->entry[i].pattern,
5676 ret = flow_tunnel_add_default_miss(dev, flow, attr,
5682 mlx5_free(default_miss_ctx.queue);
5687 /* Create the tx flow. */
5689 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
5690 attr_tx.ingress = 0;
5692 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
5693 actions_hairpin_tx.actions,
5697 dev_flow->flow = flow;
5698 dev_flow->external = 0;
5699 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5700 dev_flow->handle, next);
5701 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
5703 actions_hairpin_tx.actions, error);
5708 * Update the metadata register copy table. If extensive
5709 * metadata feature is enabled and registers are supported
5710 * we might create the extra rte_flow for each unique
5711 * MARK/FLAG action ID.
5713 * The table is updated for ingress Flows only, because
5714 * the egress Flows belong to the different device and
5715 * copy table should be updated in peer NIC Rx domain.
5717 if (attr_factor.ingress &&
5718 (external || attr_factor.group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
5719 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
5724 * If the flow is external (from application) OR device is started, then
5725 * the flow will be applied immediately.
5727 if (external || dev->data->dev_started) {
5728 ret = flow_drv_apply(dev, flow, error);
5733 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
5735 flow_rxq_flags_set(dev, flow);
5736 rte_free(translated_actions);
5737 /* Nested flow creation index recovery. */
5738 priv->flow_idx = priv->flow_nested_idx;
5739 if (priv->flow_nested_idx)
5740 priv->flow_nested_idx = 0;
5741 tunnel = flow_tunnel_from_rule(dev, attr, items, actions);
5744 flow->tunnel_id = tunnel->tunnel_id;
5745 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
5746 mlx5_free(default_miss_ctx.queue);
5751 ret = rte_errno; /* Save rte_errno before cleanup. */
5752 flow_mreg_del_copy_action(dev, flow);
5753 flow_drv_destroy(dev, flow);
5754 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
5755 rte_errno = ret; /* Restore rte_errno. */
5759 mlx5_flow_id_release(priv->sh->flow_id_pool,
5762 priv->flow_idx = priv->flow_nested_idx;
5763 if (priv->flow_nested_idx)
5764 priv->flow_nested_idx = 0;
5765 error_before_hairpin_split:
5766 rte_free(translated_actions);
5771 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
5772 * incoming packets to table 1.
5774 * Other flow rules, requested for group n, will be created in
5775 * e-switch table n+1.
5776 * Jump action to e-switch group n will be created to group n+1.
5778 * Used when working in switchdev mode, to utilise advantages of table 1
5782 * Pointer to Ethernet device.
5785 * Pointer to flow on success, NULL otherwise and rte_errno is set.
5788 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
5790 const struct rte_flow_attr attr = {
5797 const struct rte_flow_item pattern = {
5798 .type = RTE_FLOW_ITEM_TYPE_END,
5800 struct rte_flow_action_jump jump = {
5803 const struct rte_flow_action actions[] = {
5805 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5809 .type = RTE_FLOW_ACTION_TYPE_END,
5812 struct mlx5_priv *priv = dev->data->dev_private;
5813 struct rte_flow_error error;
5815 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
5817 actions, false, &error);
5821 * Validate a flow supported by the NIC.
5823 * @see rte_flow_validate()
5827 mlx5_flow_validate(struct rte_eth_dev *dev,
5828 const struct rte_flow_attr *attr,
5829 const struct rte_flow_item items[],
5830 const struct rte_flow_action original_actions[],
5831 struct rte_flow_error *error)
5834 struct mlx5_translated_shared_action
5835 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5836 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5837 const struct rte_flow_action *actions;
5838 struct rte_flow_action *translated_actions = NULL;
5839 int ret = flow_shared_actions_translate(original_actions,
5842 &translated_actions, error);
5846 actions = translated_actions ? translated_actions : original_actions;
5847 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5848 ret = flow_drv_validate(dev, attr, items, actions,
5849 true, hairpin_flow, error);
5850 rte_free(translated_actions);
5857 * @see rte_flow_create()
5861 mlx5_flow_create(struct rte_eth_dev *dev,
5862 const struct rte_flow_attr *attr,
5863 const struct rte_flow_item items[],
5864 const struct rte_flow_action actions[],
5865 struct rte_flow_error *error)
5867 struct mlx5_priv *priv = dev->data->dev_private;
5870 * If the device is not started yet, it is not allowed to created a
5871 * flow from application. PMD default flows and traffic control flows
5874 if (unlikely(!dev->data->dev_started)) {
5875 DRV_LOG(DEBUG, "port %u is not started when "
5876 "inserting a flow", dev->data->port_id);
5877 rte_flow_error_set(error, ENODEV,
5878 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5880 "port not started");
5884 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
5885 attr, items, actions, true, error);
5889 * Destroy a flow in a list.
5892 * Pointer to Ethernet device.
5894 * Pointer to the Indexed flow list. If this parameter NULL,
5895 * there is no flow removal from the list. Be noted that as
5896 * flow is add to the indexed list, memory of the indexed
5897 * list points to maybe changed as flow destroyed.
5898 * @param[in] flow_idx
5899 * Index of flow to destroy.
5902 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
5905 struct mlx5_priv *priv = dev->data->dev_private;
5906 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5907 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5908 [MLX5_IPOOL_RTE_FLOW], flow_idx);
5913 * Update RX queue flags only if port is started, otherwise it is
5916 if (dev->data->dev_started)
5917 flow_rxq_flags_trim(dev, flow);
5918 if (flow->hairpin_flow_id)
5919 mlx5_flow_id_release(priv->sh->flow_id_pool,
5920 flow->hairpin_flow_id);
5921 flow_drv_destroy(dev, flow);
5923 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
5924 flow_idx, flow, next);
5925 flow_mreg_del_copy_action(dev, flow);
5927 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
5928 if (priv_fdir_flow->rix_flow == flow_idx)
5931 if (priv_fdir_flow) {
5932 LIST_REMOVE(priv_fdir_flow, next);
5933 mlx5_free(priv_fdir_flow->fdir);
5934 mlx5_free(priv_fdir_flow);
5937 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5939 struct mlx5_flow_tunnel *tunnel;
5940 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
5942 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
5943 mlx5_flow_tunnel_free(dev, tunnel);
5948 * Destroy all flows.
5951 * Pointer to Ethernet device.
5953 * Pointer to the Indexed flow list.
5955 * If flushing is called avtively.
5958 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
5960 uint32_t num_flushed = 0;
5963 flow_list_destroy(dev, list, *list);
5967 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
5968 dev->data->port_id, num_flushed);
5976 * Pointer to Ethernet device.
5978 * Pointer to the Indexed flow list.
5981 mlx5_flow_stop(struct rte_eth_dev *dev, uint32_t *list)
5983 struct mlx5_priv *priv = dev->data->dev_private;
5984 struct rte_flow *flow = NULL;
5987 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
5989 flow_drv_remove(dev, flow);
5990 flow_mreg_stop_copy_action(dev, flow);
5992 flow_mreg_del_default_copy_action(dev);
5993 flow_rxq_flags_clear(dev);
6000 * Pointer to Ethernet device.
6002 * Pointer to the Indexed flow list.
6005 * 0 on success, a negative errno value otherwise and rte_errno is set.
6008 mlx5_flow_start(struct rte_eth_dev *dev, uint32_t *list)
6010 struct mlx5_priv *priv = dev->data->dev_private;
6011 struct rte_flow *flow = NULL;
6012 struct rte_flow_error error;
6016 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6017 ret = flow_mreg_add_default_copy_action(dev, &error);
6020 /* Apply Flows created by application. */
6021 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
6023 ret = flow_mreg_start_copy_action(dev, flow);
6026 ret = flow_drv_apply(dev, flow, &error);
6029 flow_rxq_flags_set(dev, flow);
6033 ret = rte_errno; /* Save rte_errno before cleanup. */
6034 mlx5_flow_stop(dev, list);
6035 rte_errno = ret; /* Restore rte_errno. */
6040 * Stop all default actions for flows.
6043 * Pointer to Ethernet device.
6046 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6048 flow_mreg_del_default_copy_action(dev);
6049 flow_rxq_flags_clear(dev);
6053 * Start all default actions for flows.
6056 * Pointer to Ethernet device.
6058 * 0 on success, a negative errno value otherwise and rte_errno is set.
6061 mlx5_flow_start_default(struct rte_eth_dev *dev)
6063 struct rte_flow_error error;
6065 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6066 return flow_mreg_add_default_copy_action(dev, &error);
6070 * Allocate intermediate resources for flow creation.
6073 * Pointer to Ethernet device.
6076 mlx5_flow_alloc_intermediate(struct rte_eth_dev *dev)
6078 struct mlx5_priv *priv = dev->data->dev_private;
6080 if (!priv->inter_flows) {
6081 priv->inter_flows = mlx5_malloc(MLX5_MEM_ZERO,
6082 MLX5_NUM_MAX_DEV_FLOWS *
6083 sizeof(struct mlx5_flow) +
6084 (sizeof(struct mlx5_flow_rss_desc) +
6085 sizeof(uint16_t) * UINT16_MAX) * 2, 0,
6087 if (!priv->inter_flows) {
6088 DRV_LOG(ERR, "can't allocate intermediate memory.");
6092 priv->rss_desc = &((struct mlx5_flow *)priv->inter_flows)
6093 [MLX5_NUM_MAX_DEV_FLOWS];
6094 /* Reset the index. */
6096 priv->flow_nested_idx = 0;
6100 * Free intermediate resources for flows.
6103 * Pointer to Ethernet device.
6106 mlx5_flow_free_intermediate(struct rte_eth_dev *dev)
6108 struct mlx5_priv *priv = dev->data->dev_private;
6110 mlx5_free(priv->inter_flows);
6111 priv->inter_flows = NULL;
6115 * Verify the flow list is empty
6118 * Pointer to Ethernet device.
6120 * @return the number of flows not released.
6123 mlx5_flow_verify(struct rte_eth_dev *dev)
6125 struct mlx5_priv *priv = dev->data->dev_private;
6126 struct rte_flow *flow;
6130 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
6132 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6133 dev->data->port_id, (void *)flow);
6140 * Enable default hairpin egress flow.
6143 * Pointer to Ethernet device.
6148 * 0 on success, a negative errno value otherwise and rte_errno is set.
6151 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6154 struct mlx5_priv *priv = dev->data->dev_private;
6155 const struct rte_flow_attr attr = {
6159 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6162 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6163 .queue = UINT32_MAX,
6165 struct rte_flow_item items[] = {
6167 .type = (enum rte_flow_item_type)
6168 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6169 .spec = &queue_spec,
6171 .mask = &queue_mask,
6174 .type = RTE_FLOW_ITEM_TYPE_END,
6177 struct rte_flow_action_jump jump = {
6178 .group = MLX5_HAIRPIN_TX_TABLE,
6180 struct rte_flow_action actions[2];
6182 struct rte_flow_error error;
6184 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6185 actions[0].conf = &jump;
6186 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6187 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6188 &attr, items, actions, false, &error);
6191 "Failed to create ctrl flow: rte_errno(%d),"
6192 " type(%d), message(%s)",
6193 rte_errno, error.type,
6194 error.message ? error.message : " (no stated reason)");
6201 * Enable a control flow configured from the control plane.
6204 * Pointer to Ethernet device.
6206 * An Ethernet flow spec to apply.
6208 * An Ethernet flow mask to apply.
6210 * A VLAN flow spec to apply.
6212 * A VLAN flow mask to apply.
6215 * 0 on success, a negative errno value otherwise and rte_errno is set.
6218 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6219 struct rte_flow_item_eth *eth_spec,
6220 struct rte_flow_item_eth *eth_mask,
6221 struct rte_flow_item_vlan *vlan_spec,
6222 struct rte_flow_item_vlan *vlan_mask)
6224 struct mlx5_priv *priv = dev->data->dev_private;
6225 const struct rte_flow_attr attr = {
6227 .priority = MLX5_FLOW_PRIO_RSVD,
6229 struct rte_flow_item items[] = {
6231 .type = RTE_FLOW_ITEM_TYPE_ETH,
6237 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6238 RTE_FLOW_ITEM_TYPE_END,
6244 .type = RTE_FLOW_ITEM_TYPE_END,
6247 uint16_t queue[priv->reta_idx_n];
6248 struct rte_flow_action_rss action_rss = {
6249 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6251 .types = priv->rss_conf.rss_hf,
6252 .key_len = priv->rss_conf.rss_key_len,
6253 .queue_num = priv->reta_idx_n,
6254 .key = priv->rss_conf.rss_key,
6257 struct rte_flow_action actions[] = {
6259 .type = RTE_FLOW_ACTION_TYPE_RSS,
6260 .conf = &action_rss,
6263 .type = RTE_FLOW_ACTION_TYPE_END,
6267 struct rte_flow_error error;
6270 if (!priv->reta_idx_n || !priv->rxqs_n) {
6273 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6274 action_rss.types = 0;
6275 for (i = 0; i != priv->reta_idx_n; ++i)
6276 queue[i] = (*priv->reta_idx)[i];
6277 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6278 &attr, items, actions, false, &error);
6285 * Enable a flow control configured from the control plane.
6288 * Pointer to Ethernet device.
6290 * An Ethernet flow spec to apply.
6292 * An Ethernet flow mask to apply.
6295 * 0 on success, a negative errno value otherwise and rte_errno is set.
6298 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6299 struct rte_flow_item_eth *eth_spec,
6300 struct rte_flow_item_eth *eth_mask)
6302 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6306 * Create default miss flow rule matching lacp traffic
6309 * Pointer to Ethernet device.
6311 * An Ethernet flow spec to apply.
6314 * 0 on success, a negative errno value otherwise and rte_errno is set.
6317 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6319 struct mlx5_priv *priv = dev->data->dev_private;
6321 * The LACP matching is done by only using ether type since using
6322 * a multicast dst mac causes kernel to give low priority to this flow.
6324 static const struct rte_flow_item_eth lacp_spec = {
6325 .type = RTE_BE16(0x8809),
6327 static const struct rte_flow_item_eth lacp_mask = {
6330 const struct rte_flow_attr attr = {
6333 struct rte_flow_item items[] = {
6335 .type = RTE_FLOW_ITEM_TYPE_ETH,
6340 .type = RTE_FLOW_ITEM_TYPE_END,
6343 struct rte_flow_action actions[] = {
6345 .type = (enum rte_flow_action_type)
6346 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
6349 .type = RTE_FLOW_ACTION_TYPE_END,
6352 struct rte_flow_error error;
6353 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6354 &attr, items, actions, false, &error);
6364 * @see rte_flow_destroy()
6368 mlx5_flow_destroy(struct rte_eth_dev *dev,
6369 struct rte_flow *flow,
6370 struct rte_flow_error *error __rte_unused)
6372 struct mlx5_priv *priv = dev->data->dev_private;
6374 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
6379 * Destroy all flows.
6381 * @see rte_flow_flush()
6385 mlx5_flow_flush(struct rte_eth_dev *dev,
6386 struct rte_flow_error *error __rte_unused)
6388 struct mlx5_priv *priv = dev->data->dev_private;
6390 mlx5_flow_list_flush(dev, &priv->flows, false);
6397 * @see rte_flow_isolate()
6401 mlx5_flow_isolate(struct rte_eth_dev *dev,
6403 struct rte_flow_error *error)
6405 struct mlx5_priv *priv = dev->data->dev_private;
6407 if (dev->data->dev_started) {
6408 rte_flow_error_set(error, EBUSY,
6409 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6411 "port must be stopped first");
6414 priv->isolated = !!enable;
6416 dev->dev_ops = &mlx5_os_dev_ops_isolate;
6418 dev->dev_ops = &mlx5_os_dev_ops;
6420 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
6421 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
6429 * @see rte_flow_query()
6433 flow_drv_query(struct rte_eth_dev *dev,
6435 const struct rte_flow_action *actions,
6437 struct rte_flow_error *error)
6439 struct mlx5_priv *priv = dev->data->dev_private;
6440 const struct mlx5_flow_driver_ops *fops;
6441 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
6442 [MLX5_IPOOL_RTE_FLOW],
6444 enum mlx5_flow_drv_type ftype;
6447 return rte_flow_error_set(error, ENOENT,
6448 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6450 "invalid flow handle");
6452 ftype = flow->drv_type;
6453 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
6454 fops = flow_get_drv_ops(ftype);
6456 return fops->query(dev, flow, actions, data, error);
6462 * @see rte_flow_query()
6466 mlx5_flow_query(struct rte_eth_dev *dev,
6467 struct rte_flow *flow,
6468 const struct rte_flow_action *actions,
6470 struct rte_flow_error *error)
6474 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
6482 * Convert a flow director filter to a generic flow.
6485 * Pointer to Ethernet device.
6486 * @param fdir_filter
6487 * Flow director filter to add.
6489 * Generic flow parameters structure.
6492 * 0 on success, a negative errno value otherwise and rte_errno is set.
6495 flow_fdir_filter_convert(struct rte_eth_dev *dev,
6496 const struct rte_eth_fdir_filter *fdir_filter,
6497 struct mlx5_fdir *attributes)
6499 struct mlx5_priv *priv = dev->data->dev_private;
6500 const struct rte_eth_fdir_input *input = &fdir_filter->input;
6501 const struct rte_eth_fdir_masks *mask =
6502 &dev->data->dev_conf.fdir_conf.mask;
6504 /* Validate queue number. */
6505 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
6506 DRV_LOG(ERR, "port %u invalid queue number %d",
6507 dev->data->port_id, fdir_filter->action.rx_queue);
6511 attributes->attr.ingress = 1;
6512 attributes->items[0] = (struct rte_flow_item) {
6513 .type = RTE_FLOW_ITEM_TYPE_ETH,
6514 .spec = &attributes->l2,
6515 .mask = &attributes->l2_mask,
6517 switch (fdir_filter->action.behavior) {
6518 case RTE_ETH_FDIR_ACCEPT:
6519 attributes->actions[0] = (struct rte_flow_action){
6520 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
6521 .conf = &attributes->queue,
6524 case RTE_ETH_FDIR_REJECT:
6525 attributes->actions[0] = (struct rte_flow_action){
6526 .type = RTE_FLOW_ACTION_TYPE_DROP,
6530 DRV_LOG(ERR, "port %u invalid behavior %d",
6532 fdir_filter->action.behavior);
6533 rte_errno = ENOTSUP;
6536 attributes->queue.index = fdir_filter->action.rx_queue;
6538 switch (fdir_filter->input.flow_type) {
6539 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
6540 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
6541 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
6542 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
6543 .src_addr = input->flow.ip4_flow.src_ip,
6544 .dst_addr = input->flow.ip4_flow.dst_ip,
6545 .time_to_live = input->flow.ip4_flow.ttl,
6546 .type_of_service = input->flow.ip4_flow.tos,
6548 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
6549 .src_addr = mask->ipv4_mask.src_ip,
6550 .dst_addr = mask->ipv4_mask.dst_ip,
6551 .time_to_live = mask->ipv4_mask.ttl,
6552 .type_of_service = mask->ipv4_mask.tos,
6553 .next_proto_id = mask->ipv4_mask.proto,
6555 attributes->items[1] = (struct rte_flow_item){
6556 .type = RTE_FLOW_ITEM_TYPE_IPV4,
6557 .spec = &attributes->l3,
6558 .mask = &attributes->l3_mask,
6561 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
6562 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
6563 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
6564 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
6565 .hop_limits = input->flow.ipv6_flow.hop_limits,
6566 .proto = input->flow.ipv6_flow.proto,
6569 memcpy(attributes->l3.ipv6.hdr.src_addr,
6570 input->flow.ipv6_flow.src_ip,
6571 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
6572 memcpy(attributes->l3.ipv6.hdr.dst_addr,
6573 input->flow.ipv6_flow.dst_ip,
6574 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
6575 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
6576 mask->ipv6_mask.src_ip,
6577 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
6578 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
6579 mask->ipv6_mask.dst_ip,
6580 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
6581 attributes->items[1] = (struct rte_flow_item){
6582 .type = RTE_FLOW_ITEM_TYPE_IPV6,
6583 .spec = &attributes->l3,
6584 .mask = &attributes->l3_mask,
6588 DRV_LOG(ERR, "port %u invalid flow type%d",
6589 dev->data->port_id, fdir_filter->input.flow_type);
6590 rte_errno = ENOTSUP;
6594 switch (fdir_filter->input.flow_type) {
6595 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
6596 attributes->l4.udp.hdr = (struct rte_udp_hdr){
6597 .src_port = input->flow.udp4_flow.src_port,
6598 .dst_port = input->flow.udp4_flow.dst_port,
6600 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
6601 .src_port = mask->src_port_mask,
6602 .dst_port = mask->dst_port_mask,
6604 attributes->items[2] = (struct rte_flow_item){
6605 .type = RTE_FLOW_ITEM_TYPE_UDP,
6606 .spec = &attributes->l4,
6607 .mask = &attributes->l4_mask,
6610 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
6611 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
6612 .src_port = input->flow.tcp4_flow.src_port,
6613 .dst_port = input->flow.tcp4_flow.dst_port,
6615 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
6616 .src_port = mask->src_port_mask,
6617 .dst_port = mask->dst_port_mask,
6619 attributes->items[2] = (struct rte_flow_item){
6620 .type = RTE_FLOW_ITEM_TYPE_TCP,
6621 .spec = &attributes->l4,
6622 .mask = &attributes->l4_mask,
6625 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
6626 attributes->l4.udp.hdr = (struct rte_udp_hdr){
6627 .src_port = input->flow.udp6_flow.src_port,
6628 .dst_port = input->flow.udp6_flow.dst_port,
6630 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
6631 .src_port = mask->src_port_mask,
6632 .dst_port = mask->dst_port_mask,
6634 attributes->items[2] = (struct rte_flow_item){
6635 .type = RTE_FLOW_ITEM_TYPE_UDP,
6636 .spec = &attributes->l4,
6637 .mask = &attributes->l4_mask,
6640 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
6641 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
6642 .src_port = input->flow.tcp6_flow.src_port,
6643 .dst_port = input->flow.tcp6_flow.dst_port,
6645 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
6646 .src_port = mask->src_port_mask,
6647 .dst_port = mask->dst_port_mask,
6649 attributes->items[2] = (struct rte_flow_item){
6650 .type = RTE_FLOW_ITEM_TYPE_TCP,
6651 .spec = &attributes->l4,
6652 .mask = &attributes->l4_mask,
6655 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
6656 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
6659 DRV_LOG(ERR, "port %u invalid flow type%d",
6660 dev->data->port_id, fdir_filter->input.flow_type);
6661 rte_errno = ENOTSUP;
6667 #define FLOW_FDIR_CMP(f1, f2, fld) \
6668 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
6671 * Compare two FDIR flows. If items and actions are identical, the two flows are
6675 * Pointer to Ethernet device.
6677 * FDIR flow to compare.
6679 * FDIR flow to compare.
6682 * Zero on match, 1 otherwise.
6685 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
6687 if (FLOW_FDIR_CMP(f1, f2, attr) ||
6688 FLOW_FDIR_CMP(f1, f2, l2) ||
6689 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
6690 FLOW_FDIR_CMP(f1, f2, l3) ||
6691 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
6692 FLOW_FDIR_CMP(f1, f2, l4) ||
6693 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
6694 FLOW_FDIR_CMP(f1, f2, actions[0].type))
6696 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
6697 FLOW_FDIR_CMP(f1, f2, queue))
6703 * Search device flow list to find out a matched FDIR flow.
6706 * Pointer to Ethernet device.
6708 * FDIR flow to lookup.
6711 * Index of flow if found, 0 otherwise.
6714 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
6716 struct mlx5_priv *priv = dev->data->dev_private;
6717 uint32_t flow_idx = 0;
6718 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6720 MLX5_ASSERT(fdir_flow);
6721 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
6722 if (!flow_fdir_cmp(priv_fdir_flow->fdir, fdir_flow)) {
6723 DRV_LOG(DEBUG, "port %u found FDIR flow %u",
6724 dev->data->port_id, flow_idx);
6725 flow_idx = priv_fdir_flow->rix_flow;
6733 * Add new flow director filter and store it in list.
6736 * Pointer to Ethernet device.
6737 * @param fdir_filter
6738 * Flow director filter to add.
6741 * 0 on success, a negative errno value otherwise and rte_errno is set.
6744 flow_fdir_filter_add(struct rte_eth_dev *dev,
6745 const struct rte_eth_fdir_filter *fdir_filter)
6747 struct mlx5_priv *priv = dev->data->dev_private;
6748 struct mlx5_fdir *fdir_flow;
6749 struct rte_flow *flow;
6750 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6754 fdir_flow = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*fdir_flow), 0,
6760 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
6763 flow_idx = flow_fdir_filter_lookup(dev, fdir_flow);
6768 priv_fdir_flow = mlx5_malloc(MLX5_MEM_ZERO,
6769 sizeof(struct mlx5_fdir_flow),
6771 if (!priv_fdir_flow) {
6775 flow_idx = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
6776 fdir_flow->items, fdir_flow->actions, true,
6778 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
6782 priv_fdir_flow->fdir = fdir_flow;
6783 priv_fdir_flow->rix_flow = flow_idx;
6784 LIST_INSERT_HEAD(&priv->fdir_flows, priv_fdir_flow, next);
6785 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
6786 dev->data->port_id, (void *)flow);
6789 mlx5_free(priv_fdir_flow);
6790 mlx5_free(fdir_flow);
6795 * Delete specific filter.
6798 * Pointer to Ethernet device.
6799 * @param fdir_filter
6800 * Filter to be deleted.
6803 * 0 on success, a negative errno value otherwise and rte_errno is set.
6806 flow_fdir_filter_delete(struct rte_eth_dev *dev,
6807 const struct rte_eth_fdir_filter *fdir_filter)
6809 struct mlx5_priv *priv = dev->data->dev_private;
6811 struct mlx5_fdir fdir_flow = {
6814 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6817 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
6820 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
6821 /* Find the fdir in priv list */
6822 if (!flow_fdir_cmp(priv_fdir_flow->fdir, &fdir_flow))
6825 if (!priv_fdir_flow)
6827 LIST_REMOVE(priv_fdir_flow, next);
6828 flow_idx = priv_fdir_flow->rix_flow;
6829 flow_list_destroy(dev, &priv->flows, flow_idx);
6830 mlx5_free(priv_fdir_flow->fdir);
6831 mlx5_free(priv_fdir_flow);
6832 DRV_LOG(DEBUG, "port %u deleted FDIR flow %u",
6833 dev->data->port_id, flow_idx);
6838 * Update queue for specific filter.
6841 * Pointer to Ethernet device.
6842 * @param fdir_filter
6843 * Filter to be updated.
6846 * 0 on success, a negative errno value otherwise and rte_errno is set.
6849 flow_fdir_filter_update(struct rte_eth_dev *dev,
6850 const struct rte_eth_fdir_filter *fdir_filter)
6854 ret = flow_fdir_filter_delete(dev, fdir_filter);
6857 return flow_fdir_filter_add(dev, fdir_filter);
6861 * Flush all filters.
6864 * Pointer to Ethernet device.
6867 flow_fdir_filter_flush(struct rte_eth_dev *dev)
6869 struct mlx5_priv *priv = dev->data->dev_private;
6870 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6872 while (!LIST_EMPTY(&priv->fdir_flows)) {
6873 priv_fdir_flow = LIST_FIRST(&priv->fdir_flows);
6874 LIST_REMOVE(priv_fdir_flow, next);
6875 flow_list_destroy(dev, &priv->flows, priv_fdir_flow->rix_flow);
6876 mlx5_free(priv_fdir_flow->fdir);
6877 mlx5_free(priv_fdir_flow);
6882 * Get flow director information.
6885 * Pointer to Ethernet device.
6886 * @param[out] fdir_info
6887 * Resulting flow director information.
6890 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
6892 struct rte_eth_fdir_masks *mask =
6893 &dev->data->dev_conf.fdir_conf.mask;
6895 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
6896 fdir_info->guarant_spc = 0;
6897 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
6898 fdir_info->max_flexpayload = 0;
6899 fdir_info->flow_types_mask[0] = 0;
6900 fdir_info->flex_payload_unit = 0;
6901 fdir_info->max_flex_payload_segment_num = 0;
6902 fdir_info->flex_payload_limit = 0;
6903 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
6907 * Deal with flow director operations.
6910 * Pointer to Ethernet device.
6912 * Operation to perform.
6914 * Pointer to operation-specific structure.
6917 * 0 on success, a negative errno value otherwise and rte_errno is set.
6920 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
6923 enum rte_fdir_mode fdir_mode =
6924 dev->data->dev_conf.fdir_conf.mode;
6926 if (filter_op == RTE_ETH_FILTER_NOP)
6928 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
6929 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
6930 DRV_LOG(ERR, "port %u flow director mode %d not supported",
6931 dev->data->port_id, fdir_mode);
6935 switch (filter_op) {
6936 case RTE_ETH_FILTER_ADD:
6937 return flow_fdir_filter_add(dev, arg);
6938 case RTE_ETH_FILTER_UPDATE:
6939 return flow_fdir_filter_update(dev, arg);
6940 case RTE_ETH_FILTER_DELETE:
6941 return flow_fdir_filter_delete(dev, arg);
6942 case RTE_ETH_FILTER_FLUSH:
6943 flow_fdir_filter_flush(dev);
6945 case RTE_ETH_FILTER_INFO:
6946 flow_fdir_info_get(dev, arg);
6949 DRV_LOG(DEBUG, "port %u unknown operation %u",
6950 dev->data->port_id, filter_op);
6958 * Manage filter operations.
6961 * Pointer to Ethernet device structure.
6962 * @param filter_type
6965 * Operation to perform.
6967 * Pointer to operation-specific structure.
6970 * 0 on success, a negative errno value otherwise and rte_errno is set.
6973 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
6974 enum rte_filter_type filter_type,
6975 enum rte_filter_op filter_op,
6978 switch (filter_type) {
6979 case RTE_ETH_FILTER_GENERIC:
6980 if (filter_op != RTE_ETH_FILTER_GET) {
6984 *(const void **)arg = &mlx5_flow_ops;
6986 case RTE_ETH_FILTER_FDIR:
6987 return flow_fdir_ctrl_func(dev, filter_op, arg);
6989 DRV_LOG(ERR, "port %u filter type (%d) not supported",
6990 dev->data->port_id, filter_type);
6991 rte_errno = ENOTSUP;
6998 * Create the needed meter and suffix tables.
7001 * Pointer to Ethernet device.
7003 * Pointer to the flow meter.
7006 * Pointer to table set on success, NULL otherwise.
7008 struct mlx5_meter_domains_infos *
7009 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7010 const struct mlx5_flow_meter *fm)
7012 const struct mlx5_flow_driver_ops *fops;
7014 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7015 return fops->create_mtr_tbls(dev, fm);
7019 * Destroy the meter table set.
7022 * Pointer to Ethernet device.
7024 * Pointer to the meter table set.
7030 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7031 struct mlx5_meter_domains_infos *tbls)
7033 const struct mlx5_flow_driver_ops *fops;
7035 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7036 return fops->destroy_mtr_tbls(dev, tbls);
7040 * Create policer rules.
7043 * Pointer to Ethernet device.
7045 * Pointer to flow meter structure.
7047 * Pointer to flow attributes.
7050 * 0 on success, -1 otherwise.
7053 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
7054 struct mlx5_flow_meter *fm,
7055 const struct rte_flow_attr *attr)
7057 const struct mlx5_flow_driver_ops *fops;
7059 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7060 return fops->create_policer_rules(dev, fm, attr);
7064 * Destroy policer rules.
7067 * Pointer to flow meter structure.
7069 * Pointer to flow attributes.
7072 * 0 on success, -1 otherwise.
7075 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
7076 struct mlx5_flow_meter *fm,
7077 const struct rte_flow_attr *attr)
7079 const struct mlx5_flow_driver_ops *fops;
7081 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7082 return fops->destroy_policer_rules(dev, fm, attr);
7086 * Allocate a counter.
7089 * Pointer to Ethernet device structure.
7092 * Index to allocated counter on success, 0 otherwise.
7095 mlx5_counter_alloc(struct rte_eth_dev *dev)
7097 const struct mlx5_flow_driver_ops *fops;
7098 struct rte_flow_attr attr = { .transfer = 0 };
7100 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7101 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7102 return fops->counter_alloc(dev);
7105 "port %u counter allocate is not supported.",
7106 dev->data->port_id);
7114 * Pointer to Ethernet device structure.
7116 * Index to counter to be free.
7119 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7121 const struct mlx5_flow_driver_ops *fops;
7122 struct rte_flow_attr attr = { .transfer = 0 };
7124 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7125 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7126 fops->counter_free(dev, cnt);
7130 "port %u counter free is not supported.",
7131 dev->data->port_id);
7135 * Query counter statistics.
7138 * Pointer to Ethernet device structure.
7140 * Index to counter to query.
7142 * Set to clear counter statistics.
7144 * The counter hits packets number to save.
7146 * The counter hits bytes number to save.
7149 * 0 on success, a negative errno value otherwise.
7152 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7153 bool clear, uint64_t *pkts, uint64_t *bytes)
7155 const struct mlx5_flow_driver_ops *fops;
7156 struct rte_flow_attr attr = { .transfer = 0 };
7158 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7159 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7160 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7163 "port %u counter query is not supported.",
7164 dev->data->port_id);
7169 * Allocate a new memory for the counter values wrapped by all the needed
7173 * Pointer to mlx5_dev_ctx_shared object.
7176 * 0 on success, a negative errno value otherwise.
7179 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7181 struct mlx5_devx_mkey_attr mkey_attr;
7182 struct mlx5_counter_stats_mem_mng *mem_mng;
7183 volatile struct flow_counter_stats *raw_data;
7184 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7185 int size = (sizeof(struct flow_counter_stats) *
7186 MLX5_COUNTERS_PER_POOL +
7187 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7188 sizeof(struct mlx5_counter_stats_mem_mng);
7189 size_t pgsize = rte_mem_page_size();
7193 if (pgsize == (size_t)-1) {
7194 DRV_LOG(ERR, "Failed to get mem page size");
7198 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7203 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7204 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7205 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
7206 IBV_ACCESS_LOCAL_WRITE);
7207 if (!mem_mng->umem) {
7212 mkey_attr.addr = (uintptr_t)mem;
7213 mkey_attr.size = size;
7214 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7215 mkey_attr.pd = sh->pdn;
7216 mkey_attr.log_entity_size = 0;
7217 mkey_attr.pg_access = 0;
7218 mkey_attr.klm_array = NULL;
7219 mkey_attr.klm_num = 0;
7220 mkey_attr.relaxed_ordering = sh->cmng.relaxed_ordering;
7221 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7223 mlx5_glue->devx_umem_dereg(mem_mng->umem);
7228 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7229 raw_data = (volatile struct flow_counter_stats *)mem;
7230 for (i = 0; i < raws_n; ++i) {
7231 mem_mng->raws[i].mem_mng = mem_mng;
7232 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7234 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7235 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7236 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7238 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7239 sh->cmng.mem_mng = mem_mng;
7244 * Set the statistic memory to the new counter pool.
7247 * Pointer to mlx5_dev_ctx_shared object.
7249 * Pointer to the pool to set the statistic memory.
7252 * 0 on success, a negative errno value otherwise.
7255 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7256 struct mlx5_flow_counter_pool *pool)
7258 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7259 /* Resize statistic memory once used out. */
7260 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7261 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7262 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7265 rte_spinlock_lock(&pool->sl);
7266 pool->raw = cmng->mem_mng->raws + pool->index %
7267 MLX5_CNT_CONTAINER_RESIZE;
7268 rte_spinlock_unlock(&pool->sl);
7269 pool->raw_hw = NULL;
7273 #define MLX5_POOL_QUERY_FREQ_US 1000000
7276 * Set the periodic procedure for triggering asynchronous batch queries for all
7277 * the counter pools.
7280 * Pointer to mlx5_dev_ctx_shared object.
7283 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7285 uint32_t pools_n, us;
7287 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7288 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7289 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7290 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7291 sh->cmng.query_thread_on = 0;
7292 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7294 sh->cmng.query_thread_on = 1;
7299 * The periodic procedure for triggering asynchronous batch queries for all the
7300 * counter pools. This function is probably called by the host thread.
7303 * The parameter for the alarm process.
7306 mlx5_flow_query_alarm(void *arg)
7308 struct mlx5_dev_ctx_shared *sh = arg;
7310 uint16_t pool_index = sh->cmng.pool_index;
7311 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7312 struct mlx5_flow_counter_pool *pool;
7315 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7317 rte_spinlock_lock(&cmng->pool_update_sl);
7318 pool = cmng->pools[pool_index];
7319 n_valid = cmng->n_valid;
7320 rte_spinlock_unlock(&cmng->pool_update_sl);
7321 /* Set the statistic memory to the new created pool. */
7322 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7325 /* There is a pool query in progress. */
7328 LIST_FIRST(&sh->cmng.free_stat_raws);
7330 /* No free counter statistics raw memory. */
7333 * Identify the counters released between query trigger and query
7334 * handle more efficiently. The counter released in this gap period
7335 * should wait for a new round of query as the new arrived packets
7336 * will not be taken into account.
7339 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7340 MLX5_COUNTERS_PER_POOL,
7342 pool->raw_hw->mem_mng->dm->id,
7346 (uint64_t)(uintptr_t)pool);
7348 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7349 " %d", pool->min_dcs->id);
7350 pool->raw_hw = NULL;
7353 LIST_REMOVE(pool->raw_hw, next);
7354 sh->cmng.pending_queries++;
7356 if (pool_index >= n_valid)
7359 sh->cmng.pool_index = pool_index;
7360 mlx5_set_query_alarm(sh);
7364 * Check and callback event for new aged flow in the counter pool
7367 * Pointer to mlx5_dev_ctx_shared object.
7369 * Pointer to Current counter pool.
7372 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7373 struct mlx5_flow_counter_pool *pool)
7375 struct mlx5_priv *priv;
7376 struct mlx5_flow_counter *cnt;
7377 struct mlx5_age_info *age_info;
7378 struct mlx5_age_param *age_param;
7379 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7380 struct mlx5_counter_stats_raw *prev = pool->raw;
7381 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7382 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7383 uint16_t expected = AGE_CANDIDATE;
7386 pool->time_of_last_age_check = curr_time;
7387 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7388 cnt = MLX5_POOL_GET_CNT(pool, i);
7389 age_param = MLX5_CNT_TO_AGE(cnt);
7390 if (__atomic_load_n(&age_param->state,
7391 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7393 if (cur->data[i].hits != prev->data[i].hits) {
7394 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7398 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7400 __ATOMIC_RELAXED) <= age_param->timeout)
7403 * Hold the lock first, or if between the
7404 * state AGE_TMOUT and tailq operation the
7405 * release happened, the release procedure
7406 * may delete a non-existent tailq node.
7408 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7409 age_info = GET_PORT_AGE_INFO(priv);
7410 rte_spinlock_lock(&age_info->aged_sl);
7411 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7414 __ATOMIC_RELAXED)) {
7415 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7416 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7418 rte_spinlock_unlock(&age_info->aged_sl);
7420 for (i = 0; i < sh->max_port; i++) {
7421 age_info = &sh->port[i].age_info;
7422 if (!MLX5_AGE_GET(age_info, MLX5_AGE_EVENT_NEW))
7424 if (MLX5_AGE_GET(age_info, MLX5_AGE_TRIGGER))
7425 rte_eth_dev_callback_process
7426 (&rte_eth_devices[sh->port[i].devx_ih_port_id],
7427 RTE_ETH_EVENT_FLOW_AGED, NULL);
7428 age_info->flags = 0;
7433 * Handler for the HW respond about ready values from an asynchronous batch
7434 * query. This function is probably called by the host thread.
7437 * The pointer to the shared device context.
7438 * @param[in] async_id
7439 * The Devx async ID.
7441 * The status of the completion.
7444 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7445 uint64_t async_id, int status)
7447 struct mlx5_flow_counter_pool *pool =
7448 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7449 struct mlx5_counter_stats_raw *raw_to_free;
7450 uint8_t query_gen = pool->query_gen ^ 1;
7451 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7452 enum mlx5_counter_type cnt_type =
7453 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7454 MLX5_COUNTER_TYPE_ORIGIN;
7456 if (unlikely(status)) {
7457 raw_to_free = pool->raw_hw;
7459 raw_to_free = pool->raw;
7461 mlx5_flow_aging_check(sh, pool);
7462 rte_spinlock_lock(&pool->sl);
7463 pool->raw = pool->raw_hw;
7464 rte_spinlock_unlock(&pool->sl);
7465 /* Be sure the new raw counters data is updated in memory. */
7467 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7468 rte_spinlock_lock(&cmng->csl[cnt_type]);
7469 TAILQ_CONCAT(&cmng->counters[cnt_type],
7470 &pool->counters[query_gen], next);
7471 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7474 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7475 pool->raw_hw = NULL;
7476 sh->cmng.pending_queries--;
7479 static const struct mlx5_flow_tbl_data_entry *
7480 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
7482 struct mlx5_priv *priv = dev->data->dev_private;
7483 struct mlx5_dev_ctx_shared *sh = priv->sh;
7484 struct mlx5_hlist_entry *he;
7485 union tunnel_offload_mark mbits = { .val = mark };
7486 union mlx5_flow_tbl_key table_key = {
7488 .table_id = tunnel_id_to_flow_tbl(mbits.table_id),
7490 .domain = !!mbits.transfer,
7494 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64);
7496 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
7500 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
7501 const struct mlx5_flow_tunnel *tunnel,
7502 uint32_t group, uint32_t *table,
7503 struct rte_flow_error *error)
7505 struct mlx5_hlist_entry *he;
7506 struct tunnel_tbl_entry *tte;
7507 union tunnel_tbl_key key = {
7508 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
7511 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7512 struct mlx5_hlist *group_hash;
7514 group_hash = tunnel ? tunnel->groups : thub->groups;
7515 he = mlx5_hlist_lookup(group_hash, key.val);
7518 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
7523 tte->hash.key = key.val;
7524 ret = mlx5_flow_id_get(thub->table_ids, &tte->flow_table);
7529 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
7530 mlx5_hlist_insert(group_hash, &tte->hash);
7532 tte = container_of(he, typeof(*tte), hash);
7534 *table = tte->flow_table;
7535 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
7536 dev->data->port_id, key.tunnel_id, group, *table);
7540 return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7541 NULL, "tunnel group index not supported");
7545 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7546 struct flow_grp_info grp_info, struct rte_flow_error *error)
7548 if (grp_info.transfer && grp_info.external && grp_info.fdb_def_rule) {
7549 if (group == UINT32_MAX)
7550 return rte_flow_error_set
7552 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7554 "group index not supported");
7559 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7564 * Translate the rte_flow group index to HW table value.
7566 * If tunnel offload is disabled, all group ids converted to flow table
7567 * id using the standard method.
7568 * If tunnel offload is enabled, group id can be converted using the
7569 * standard or tunnel conversion method. Group conversion method
7570 * selection depends on flags in `grp_info` parameter:
7571 * - Internal (grp_info.external == 0) groups conversion uses the
7573 * - Group ids in JUMP action converted with the tunnel conversion.
7574 * - Group id in rule attribute conversion depends on a rule type and
7576 * ** non zero group attributes converted with the tunnel method
7577 * ** zero group attribute in non-tunnel rule is converted using the
7578 * standard method - there's only one root table
7579 * ** zero group attribute in steer tunnel rule is converted with the
7580 * standard method - single root table
7581 * ** zero group attribute in match tunnel rule is a special OvS
7582 * case: that value is used for portability reasons. That group
7583 * id is converted with the tunnel conversion method.
7588 * PMD tunnel offload object
7590 * rte_flow group index value.
7593 * @param[in] grp_info
7594 * flags used for conversion
7596 * Pointer to error structure.
7599 * 0 on success, a negative errno value otherwise and rte_errno is set.
7602 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7603 const struct mlx5_flow_tunnel *tunnel,
7604 uint32_t group, uint32_t *table,
7605 struct flow_grp_info grp_info,
7606 struct rte_flow_error *error)
7609 bool standard_translation;
7611 if (grp_info.external && group < MLX5_MAX_TABLES_EXTERNAL)
7612 group *= MLX5_FLOW_TABLE_FACTOR;
7613 if (is_tunnel_offload_active(dev)) {
7614 standard_translation = !grp_info.external ||
7615 grp_info.std_tbl_fix;
7617 standard_translation = true;
7620 "port %u group=%#x transfer=%d external=%d fdb_def_rule=%d translate=%s",
7621 dev->data->port_id, group, grp_info.transfer,
7622 grp_info.external, grp_info.fdb_def_rule,
7623 standard_translation ? "STANDARD" : "TUNNEL");
7624 if (standard_translation)
7625 ret = flow_group_to_table(dev->data->port_id, group, table,
7628 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7635 * Discover availability of metadata reg_c's.
7637 * Iteratively use test flows to check availability.
7640 * Pointer to the Ethernet device structure.
7643 * 0 on success, a negative errno value otherwise and rte_errno is set.
7646 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7648 struct mlx5_priv *priv = dev->data->dev_private;
7649 struct mlx5_dev_config *config = &priv->config;
7650 enum modify_reg idx;
7653 /* reg_c[0] and reg_c[1] are reserved. */
7654 config->flow_mreg_c[n++] = REG_C_0;
7655 config->flow_mreg_c[n++] = REG_C_1;
7656 /* Discover availability of other reg_c's. */
7657 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7658 struct rte_flow_attr attr = {
7659 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7660 .priority = MLX5_FLOW_PRIO_RSVD,
7663 struct rte_flow_item items[] = {
7665 .type = RTE_FLOW_ITEM_TYPE_END,
7668 struct rte_flow_action actions[] = {
7670 .type = (enum rte_flow_action_type)
7671 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7672 .conf = &(struct mlx5_flow_action_copy_mreg){
7678 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7679 .conf = &(struct rte_flow_action_jump){
7680 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7684 .type = RTE_FLOW_ACTION_TYPE_END,
7688 struct rte_flow *flow;
7689 struct rte_flow_error error;
7691 if (!config->dv_flow_en)
7693 /* Create internal flow, validation skips copy action. */
7694 flow_idx = flow_list_create(dev, NULL, &attr, items,
7695 actions, false, &error);
7696 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
7700 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
7701 config->flow_mreg_c[n++] = idx;
7702 flow_list_destroy(dev, NULL, flow_idx);
7704 for (; n < MLX5_MREG_C_NUM; ++n)
7705 config->flow_mreg_c[n] = REG_NON;
7710 * Dump flow raw hw data to file
7713 * The pointer to Ethernet device.
7715 * A pointer to a file for output.
7717 * Perform verbose error reporting if not NULL. PMDs initialize this
7718 * structure in case of error only.
7720 * 0 on success, a nagative value otherwise.
7723 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
7725 struct rte_flow_error *error __rte_unused)
7727 struct mlx5_priv *priv = dev->data->dev_private;
7728 struct mlx5_dev_ctx_shared *sh = priv->sh;
7730 if (!priv->config.dv_flow_en) {
7731 if (fputs("device dv flow disabled\n", file) <= 0)
7735 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
7736 sh->tx_domain, file);
7740 * Get aged-out flows.
7743 * Pointer to the Ethernet device structure.
7744 * @param[in] context
7745 * The address of an array of pointers to the aged-out flows contexts.
7746 * @param[in] nb_countexts
7747 * The length of context array pointers.
7749 * Perform verbose error reporting if not NULL. Initialized in case of
7753 * how many contexts get in success, otherwise negative errno value.
7754 * if nb_contexts is 0, return the amount of all aged contexts.
7755 * if nb_contexts is not 0 , return the amount of aged flows reported
7756 * in the context array.
7759 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
7760 uint32_t nb_contexts, struct rte_flow_error *error)
7762 const struct mlx5_flow_driver_ops *fops;
7763 struct rte_flow_attr attr = { .transfer = 0 };
7765 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7766 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7767 return fops->get_aged_flows(dev, contexts, nb_contexts,
7771 "port %u get aged flows is not supported.",
7772 dev->data->port_id);
7776 /* Wrapper for driver action_validate op callback */
7778 flow_drv_action_validate(struct rte_eth_dev *dev,
7779 const struct rte_flow_shared_action_conf *conf,
7780 const struct rte_flow_action *action,
7781 const struct mlx5_flow_driver_ops *fops,
7782 struct rte_flow_error *error)
7784 static const char err_msg[] = "shared action validation unsupported";
7786 if (!fops->action_validate) {
7787 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7788 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7792 return fops->action_validate(dev, conf, action, error);
7796 * Destroys the shared action by handle.
7799 * Pointer to Ethernet device structure.
7801 * Handle for the shared action to be destroyed.
7803 * Perform verbose error reporting if not NULL. PMDs initialize this
7804 * structure in case of error only.
7807 * 0 on success, a negative errno value otherwise and rte_errno is set.
7809 * @note: wrapper for driver action_create op callback.
7812 mlx5_shared_action_destroy(struct rte_eth_dev *dev,
7813 struct rte_flow_shared_action *action,
7814 struct rte_flow_error *error)
7816 static const char err_msg[] = "shared action destruction unsupported";
7817 struct rte_flow_attr attr = { .transfer = 0 };
7818 const struct mlx5_flow_driver_ops *fops =
7819 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7821 if (!fops->action_destroy) {
7822 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7823 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7827 return fops->action_destroy(dev, action, error);
7830 /* Wrapper for driver action_destroy op callback */
7832 flow_drv_action_update(struct rte_eth_dev *dev,
7833 struct rte_flow_shared_action *action,
7834 const void *action_conf,
7835 const struct mlx5_flow_driver_ops *fops,
7836 struct rte_flow_error *error)
7838 static const char err_msg[] = "shared action update unsupported";
7840 if (!fops->action_update) {
7841 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7842 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7846 return fops->action_update(dev, action, action_conf, error);
7850 * Create shared action for reuse in multiple flow rules.
7853 * Pointer to Ethernet device structure.
7855 * Action configuration for shared action creation.
7857 * Perform verbose error reporting if not NULL. PMDs initialize this
7858 * structure in case of error only.
7860 * A valid handle in case of success, NULL otherwise and rte_errno is set.
7862 static struct rte_flow_shared_action *
7863 mlx5_shared_action_create(struct rte_eth_dev *dev,
7864 const struct rte_flow_shared_action_conf *conf,
7865 const struct rte_flow_action *action,
7866 struct rte_flow_error *error)
7868 static const char err_msg[] = "shared action creation unsupported";
7869 struct rte_flow_attr attr = { .transfer = 0 };
7870 const struct mlx5_flow_driver_ops *fops =
7871 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7873 if (flow_drv_action_validate(dev, conf, action, fops, error))
7875 if (!fops->action_create) {
7876 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7877 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7881 return fops->action_create(dev, conf, action, error);
7885 * Updates inplace the shared action configuration pointed by *action* handle
7886 * with the configuration provided as *action* argument.
7887 * The update of the shared action configuration effects all flow rules reusing
7888 * the action via handle.
7891 * Pointer to Ethernet device structure.
7892 * @param[in] shared_action
7893 * Handle for the shared action to be updated.
7895 * Action specification used to modify the action pointed by handle.
7896 * *action* should be of same type with the action pointed by the *action*
7897 * handle argument, otherwise considered as invalid.
7899 * Perform verbose error reporting if not NULL. PMDs initialize this
7900 * structure in case of error only.
7903 * 0 on success, a negative errno value otherwise and rte_errno is set.
7906 mlx5_shared_action_update(struct rte_eth_dev *dev,
7907 struct rte_flow_shared_action *shared_action,
7908 const struct rte_flow_action *action,
7909 struct rte_flow_error *error)
7911 struct rte_flow_attr attr = { .transfer = 0 };
7912 const struct mlx5_flow_driver_ops *fops =
7913 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7916 switch (shared_action->type) {
7917 case MLX5_RTE_FLOW_ACTION_TYPE_SHARED_RSS:
7918 if (action->type != RTE_FLOW_ACTION_TYPE_RSS) {
7919 return rte_flow_error_set(error, EINVAL,
7920 RTE_FLOW_ERROR_TYPE_ACTION,
7922 "update action type invalid");
7924 ret = flow_drv_action_validate(dev, NULL, action, fops, error);
7927 return flow_drv_action_update(dev, shared_action, action->conf,
7930 return rte_flow_error_set(error, ENOTSUP,
7931 RTE_FLOW_ERROR_TYPE_ACTION,
7933 "action type not supported");
7938 * Query the shared action by handle.
7940 * This function allows retrieving action-specific data such as counters.
7941 * Data is gathered by special action which may be present/referenced in
7942 * more than one flow rule definition.
7944 * \see RTE_FLOW_ACTION_TYPE_COUNT
7947 * Pointer to Ethernet device structure.
7949 * Handle for the shared action to query.
7950 * @param[in, out] data
7951 * Pointer to storage for the associated query data type.
7953 * Perform verbose error reporting if not NULL. PMDs initialize this
7954 * structure in case of error only.
7957 * 0 on success, a negative errno value otherwise and rte_errno is set.
7960 mlx5_shared_action_query(struct rte_eth_dev *dev,
7961 const struct rte_flow_shared_action *action,
7963 struct rte_flow_error *error)
7966 switch (action->type) {
7967 case MLX5_RTE_FLOW_ACTION_TYPE_SHARED_RSS:
7968 __atomic_load(&action->refcnt, (uint32_t *)data,
7972 return rte_flow_error_set(error, ENOTSUP,
7973 RTE_FLOW_ERROR_TYPE_ACTION,
7975 "action type not supported");
7980 * Destroy all shared actions.
7983 * Pointer to Ethernet device.
7986 * 0 on success, a negative errno value otherwise and rte_errno is set.
7989 mlx5_shared_action_flush(struct rte_eth_dev *dev)
7991 struct rte_flow_error error;
7992 struct mlx5_priv *priv = dev->data->dev_private;
7993 struct rte_flow_shared_action *action;
7996 while (!LIST_EMPTY(&priv->shared_actions)) {
7997 action = LIST_FIRST(&priv->shared_actions);
7998 ret = mlx5_shared_action_destroy(dev, action, &error);
8004 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8005 struct mlx5_flow_tunnel *tunnel)
8007 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8008 struct mlx5_flow_id_pool *id_pool = thub->tunnel_ids;
8010 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8011 dev->data->port_id, tunnel->tunnel_id);
8012 RTE_VERIFY(!__atomic_load_n(&tunnel->refctn, __ATOMIC_RELAXED));
8013 LIST_REMOVE(tunnel, chain);
8014 mlx5_flow_id_release(id_pool, tunnel->tunnel_id);
8015 mlx5_hlist_destroy(tunnel->groups, NULL, NULL);
8019 static struct mlx5_flow_tunnel *
8020 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8022 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8023 struct mlx5_flow_tunnel *tun;
8025 LIST_FOREACH(tun, &thub->tunnels, chain) {
8026 if (tun->tunnel_id == id)
8033 static struct mlx5_flow_tunnel *
8034 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8035 const struct rte_flow_tunnel *app_tunnel)
8038 struct mlx5_flow_tunnel *tunnel;
8039 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8040 struct mlx5_flow_id_pool *id_pool = thub->tunnel_ids;
8043 ret = mlx5_flow_id_get(id_pool, &id);
8047 * mlx5 flow tunnel is an auxlilary data structure
8048 * It's not part of IO. No need to allocate it from
8049 * huge pages pools dedicated for IO
8051 tunnel = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*tunnel),
8054 mlx5_flow_id_pool_release(id_pool);
8057 tunnel->groups = mlx5_hlist_create("tunnel groups", 1024);
8058 if (!tunnel->groups) {
8059 mlx5_flow_id_pool_release(id_pool);
8063 /* initiate new PMD tunnel */
8064 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8065 tunnel->tunnel_id = id;
8066 tunnel->action.type = (typeof(tunnel->action.type))
8067 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8068 tunnel->action.conf = tunnel;
8069 tunnel->item.type = (typeof(tunnel->item.type))
8070 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8071 tunnel->item.spec = tunnel;
8072 tunnel->item.last = NULL;
8073 tunnel->item.mask = NULL;
8075 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8076 dev->data->port_id, tunnel->tunnel_id);
8082 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
8083 const struct rte_flow_tunnel *app_tunnel,
8084 struct mlx5_flow_tunnel **tunnel)
8087 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8088 struct mlx5_flow_tunnel *tun;
8090 LIST_FOREACH(tun, &thub->tunnels, chain) {
8091 if (!memcmp(app_tunnel, &tun->app_tunnel,
8092 sizeof(*app_tunnel))) {
8099 tun = mlx5_flow_tunnel_allocate(dev, app_tunnel);
8101 LIST_INSERT_HEAD(&thub->tunnels, tun, chain);
8108 __atomic_add_fetch(&tun->refctn, 1, __ATOMIC_RELAXED);
8113 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
8115 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
8119 if (!LIST_EMPTY(&thub->tunnels))
8120 DRV_LOG(WARNING, "port %u tunnels present\n", port_id);
8121 mlx5_flow_id_pool_release(thub->tunnel_ids);
8122 mlx5_flow_id_pool_release(thub->table_ids);
8123 mlx5_hlist_destroy(thub->groups, NULL, NULL);
8127 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
8130 struct mlx5_flow_tunnel_hub *thub;
8132 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
8136 LIST_INIT(&thub->tunnels);
8137 thub->tunnel_ids = mlx5_flow_id_pool_alloc(MLX5_MAX_TUNNELS);
8138 if (!thub->tunnel_ids) {
8142 thub->table_ids = mlx5_flow_id_pool_alloc(MLX5_MAX_TABLES);
8143 if (!thub->table_ids) {
8147 thub->groups = mlx5_hlist_create("flow groups", MLX5_MAX_TABLES);
8148 if (!thub->groups) {
8152 sh->tunnel_hub = thub;
8158 mlx5_hlist_destroy(thub->groups, NULL, NULL);
8159 if (thub->table_ids)
8160 mlx5_flow_id_pool_release(thub->table_ids);
8161 if (thub->tunnel_ids)
8162 mlx5_flow_id_pool_release(thub->tunnel_ids);