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.
1796 * @param[in] ext_vlan_sup
1797 * Whether extended VLAN features are supported or not.
1799 * Pointer to error structure.
1802 * 0 on success, a negative errno value otherwise and rte_errno is set.
1805 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1806 uint64_t item_flags,
1807 uint8_t target_protocol,
1808 struct rte_flow_error *error)
1810 const struct rte_flow_item_icmp6 *mask = item->mask;
1811 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1812 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1813 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1814 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1815 MLX5_FLOW_LAYER_OUTER_L4;
1818 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1819 return rte_flow_error_set(error, EINVAL,
1820 RTE_FLOW_ERROR_TYPE_ITEM, item,
1821 "protocol filtering not compatible"
1822 " with ICMP6 layer");
1823 if (!(item_flags & l3m))
1824 return rte_flow_error_set(error, EINVAL,
1825 RTE_FLOW_ERROR_TYPE_ITEM, item,
1826 "IPv6 is mandatory to filter on"
1828 if (item_flags & l4m)
1829 return rte_flow_error_set(error, EINVAL,
1830 RTE_FLOW_ERROR_TYPE_ITEM, item,
1831 "multiple L4 layers not supported");
1833 mask = &rte_flow_item_icmp6_mask;
1834 ret = mlx5_flow_item_acceptable
1835 (item, (const uint8_t *)mask,
1836 (const uint8_t *)&rte_flow_item_icmp6_mask,
1837 sizeof(struct rte_flow_item_icmp6),
1838 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1845 * Validate ICMP item.
1848 * Item specification.
1849 * @param[in] item_flags
1850 * Bit-fields that holds the items detected until now.
1852 * Pointer to error structure.
1855 * 0 on success, a negative errno value otherwise and rte_errno is set.
1858 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1859 uint64_t item_flags,
1860 uint8_t target_protocol,
1861 struct rte_flow_error *error)
1863 const struct rte_flow_item_icmp *mask = item->mask;
1864 const struct rte_flow_item_icmp nic_mask = {
1865 .hdr.icmp_type = 0xff,
1866 .hdr.icmp_code = 0xff,
1867 .hdr.icmp_ident = RTE_BE16(0xffff),
1868 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1870 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1871 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1872 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1873 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1874 MLX5_FLOW_LAYER_OUTER_L4;
1877 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1878 return rte_flow_error_set(error, EINVAL,
1879 RTE_FLOW_ERROR_TYPE_ITEM, item,
1880 "protocol filtering not compatible"
1881 " with ICMP layer");
1882 if (!(item_flags & l3m))
1883 return rte_flow_error_set(error, EINVAL,
1884 RTE_FLOW_ERROR_TYPE_ITEM, item,
1885 "IPv4 is mandatory to filter"
1887 if (item_flags & l4m)
1888 return rte_flow_error_set(error, EINVAL,
1889 RTE_FLOW_ERROR_TYPE_ITEM, item,
1890 "multiple L4 layers not supported");
1893 ret = mlx5_flow_item_acceptable
1894 (item, (const uint8_t *)mask,
1895 (const uint8_t *)&nic_mask,
1896 sizeof(struct rte_flow_item_icmp),
1897 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1904 * Validate Ethernet item.
1907 * Item specification.
1908 * @param[in] item_flags
1909 * Bit-fields that holds the items detected until now.
1911 * Pointer to error structure.
1914 * 0 on success, a negative errno value otherwise and rte_errno is set.
1917 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1918 uint64_t item_flags, bool ext_vlan_sup,
1919 struct rte_flow_error *error)
1921 const struct rte_flow_item_eth *mask = item->mask;
1922 const struct rte_flow_item_eth nic_mask = {
1923 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1924 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1925 .type = RTE_BE16(0xffff),
1926 .has_vlan = ext_vlan_sup ? 1 : 0,
1929 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1930 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1931 MLX5_FLOW_LAYER_OUTER_L2;
1933 if (item_flags & ethm)
1934 return rte_flow_error_set(error, ENOTSUP,
1935 RTE_FLOW_ERROR_TYPE_ITEM, item,
1936 "multiple L2 layers not supported");
1937 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1938 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1939 return rte_flow_error_set(error, EINVAL,
1940 RTE_FLOW_ERROR_TYPE_ITEM, item,
1941 "L2 layer should not follow "
1943 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1944 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1945 return rte_flow_error_set(error, EINVAL,
1946 RTE_FLOW_ERROR_TYPE_ITEM, item,
1947 "L2 layer should not follow VLAN");
1949 mask = &rte_flow_item_eth_mask;
1950 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1951 (const uint8_t *)&nic_mask,
1952 sizeof(struct rte_flow_item_eth),
1953 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1958 * Validate VLAN item.
1961 * Item specification.
1962 * @param[in] item_flags
1963 * Bit-fields that holds the items detected until now.
1965 * Ethernet device flow is being created on.
1967 * Pointer to error structure.
1970 * 0 on success, a negative errno value otherwise and rte_errno is set.
1973 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1974 uint64_t item_flags,
1975 struct rte_eth_dev *dev,
1976 struct rte_flow_error *error)
1978 const struct rte_flow_item_vlan *spec = item->spec;
1979 const struct rte_flow_item_vlan *mask = item->mask;
1980 const struct rte_flow_item_vlan nic_mask = {
1981 .tci = RTE_BE16(UINT16_MAX),
1982 .inner_type = RTE_BE16(UINT16_MAX),
1984 uint16_t vlan_tag = 0;
1985 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1987 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1988 MLX5_FLOW_LAYER_INNER_L4) :
1989 (MLX5_FLOW_LAYER_OUTER_L3 |
1990 MLX5_FLOW_LAYER_OUTER_L4);
1991 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1992 MLX5_FLOW_LAYER_OUTER_VLAN;
1994 if (item_flags & vlanm)
1995 return rte_flow_error_set(error, EINVAL,
1996 RTE_FLOW_ERROR_TYPE_ITEM, item,
1997 "multiple VLAN layers not supported");
1998 else if ((item_flags & l34m) != 0)
1999 return rte_flow_error_set(error, EINVAL,
2000 RTE_FLOW_ERROR_TYPE_ITEM, item,
2001 "VLAN cannot follow L3/L4 layer");
2003 mask = &rte_flow_item_vlan_mask;
2004 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2005 (const uint8_t *)&nic_mask,
2006 sizeof(struct rte_flow_item_vlan),
2007 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2010 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2011 struct mlx5_priv *priv = dev->data->dev_private;
2013 if (priv->vmwa_context) {
2015 * Non-NULL context means we have a virtual machine
2016 * and SR-IOV enabled, we have to create VLAN interface
2017 * to make hypervisor to setup E-Switch vport
2018 * context correctly. We avoid creating the multiple
2019 * VLAN interfaces, so we cannot support VLAN tag mask.
2021 return rte_flow_error_set(error, EINVAL,
2022 RTE_FLOW_ERROR_TYPE_ITEM,
2024 "VLAN tag mask is not"
2025 " supported in virtual"
2030 vlan_tag = spec->tci;
2031 vlan_tag &= mask->tci;
2034 * From verbs perspective an empty VLAN is equivalent
2035 * to a packet without VLAN layer.
2038 return rte_flow_error_set(error, EINVAL,
2039 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2041 "VLAN cannot be empty");
2046 * Validate IPV4 item.
2049 * Item specification.
2050 * @param[in] item_flags
2051 * Bit-fields that holds the items detected until now.
2052 * @param[in] last_item
2053 * Previous validated item in the pattern items.
2054 * @param[in] ether_type
2055 * Type in the ethernet layer header (including dot1q).
2056 * @param[in] acc_mask
2057 * Acceptable mask, if NULL default internal default mask
2058 * will be used to check whether item fields are supported.
2059 * @param[in] range_accepted
2060 * True if range of values is accepted for specific fields, false otherwise.
2062 * Pointer to error structure.
2065 * 0 on success, a negative errno value otherwise and rte_errno is set.
2068 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2069 uint64_t item_flags,
2071 uint16_t ether_type,
2072 const struct rte_flow_item_ipv4 *acc_mask,
2073 bool range_accepted,
2074 struct rte_flow_error *error)
2076 const struct rte_flow_item_ipv4 *mask = item->mask;
2077 const struct rte_flow_item_ipv4 *spec = item->spec;
2078 const struct rte_flow_item_ipv4 nic_mask = {
2080 .src_addr = RTE_BE32(0xffffffff),
2081 .dst_addr = RTE_BE32(0xffffffff),
2082 .type_of_service = 0xff,
2083 .next_proto_id = 0xff,
2086 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2087 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2088 MLX5_FLOW_LAYER_OUTER_L3;
2089 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2090 MLX5_FLOW_LAYER_OUTER_L4;
2092 uint8_t next_proto = 0xFF;
2093 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2094 MLX5_FLOW_LAYER_OUTER_VLAN |
2095 MLX5_FLOW_LAYER_INNER_VLAN);
2097 if ((last_item & l2_vlan) && ether_type &&
2098 ether_type != RTE_ETHER_TYPE_IPV4)
2099 return rte_flow_error_set(error, EINVAL,
2100 RTE_FLOW_ERROR_TYPE_ITEM, item,
2101 "IPv4 cannot follow L2/VLAN layer "
2102 "which ether type is not IPv4");
2103 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2105 next_proto = mask->hdr.next_proto_id &
2106 spec->hdr.next_proto_id;
2107 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2108 return rte_flow_error_set(error, EINVAL,
2109 RTE_FLOW_ERROR_TYPE_ITEM,
2114 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2115 return rte_flow_error_set(error, EINVAL,
2116 RTE_FLOW_ERROR_TYPE_ITEM, item,
2117 "wrong tunnel type - IPv6 specified "
2118 "but IPv4 item provided");
2119 if (item_flags & l3m)
2120 return rte_flow_error_set(error, ENOTSUP,
2121 RTE_FLOW_ERROR_TYPE_ITEM, item,
2122 "multiple L3 layers not supported");
2123 else if (item_flags & l4m)
2124 return rte_flow_error_set(error, EINVAL,
2125 RTE_FLOW_ERROR_TYPE_ITEM, item,
2126 "L3 cannot follow an L4 layer.");
2127 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2128 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2129 return rte_flow_error_set(error, EINVAL,
2130 RTE_FLOW_ERROR_TYPE_ITEM, item,
2131 "L3 cannot follow an NVGRE layer.");
2133 mask = &rte_flow_item_ipv4_mask;
2134 else if (mask->hdr.next_proto_id != 0 &&
2135 mask->hdr.next_proto_id != 0xff)
2136 return rte_flow_error_set(error, EINVAL,
2137 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2138 "partial mask is not supported"
2140 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2141 acc_mask ? (const uint8_t *)acc_mask
2142 : (const uint8_t *)&nic_mask,
2143 sizeof(struct rte_flow_item_ipv4),
2144 range_accepted, error);
2151 * Validate IPV6 item.
2154 * Item specification.
2155 * @param[in] item_flags
2156 * Bit-fields that holds the items detected until now.
2157 * @param[in] last_item
2158 * Previous validated item in the pattern items.
2159 * @param[in] ether_type
2160 * Type in the ethernet layer header (including dot1q).
2161 * @param[in] acc_mask
2162 * Acceptable mask, if NULL default internal default mask
2163 * will be used to check whether item fields are supported.
2165 * Pointer to error structure.
2168 * 0 on success, a negative errno value otherwise and rte_errno is set.
2171 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2172 uint64_t item_flags,
2174 uint16_t ether_type,
2175 const struct rte_flow_item_ipv6 *acc_mask,
2176 struct rte_flow_error *error)
2178 const struct rte_flow_item_ipv6 *mask = item->mask;
2179 const struct rte_flow_item_ipv6 *spec = item->spec;
2180 const struct rte_flow_item_ipv6 nic_mask = {
2183 "\xff\xff\xff\xff\xff\xff\xff\xff"
2184 "\xff\xff\xff\xff\xff\xff\xff\xff",
2186 "\xff\xff\xff\xff\xff\xff\xff\xff"
2187 "\xff\xff\xff\xff\xff\xff\xff\xff",
2188 .vtc_flow = RTE_BE32(0xffffffff),
2192 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2193 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2194 MLX5_FLOW_LAYER_OUTER_L3;
2195 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2196 MLX5_FLOW_LAYER_OUTER_L4;
2198 uint8_t next_proto = 0xFF;
2199 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2200 MLX5_FLOW_LAYER_OUTER_VLAN |
2201 MLX5_FLOW_LAYER_INNER_VLAN);
2203 if ((last_item & l2_vlan) && ether_type &&
2204 ether_type != RTE_ETHER_TYPE_IPV6)
2205 return rte_flow_error_set(error, EINVAL,
2206 RTE_FLOW_ERROR_TYPE_ITEM, item,
2207 "IPv6 cannot follow L2/VLAN layer "
2208 "which ether type is not IPv6");
2209 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2210 next_proto = spec->hdr.proto;
2211 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
2212 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2213 return rte_flow_error_set(error, EINVAL,
2214 RTE_FLOW_ERROR_TYPE_ITEM,
2219 if (next_proto == IPPROTO_HOPOPTS ||
2220 next_proto == IPPROTO_ROUTING ||
2221 next_proto == IPPROTO_FRAGMENT ||
2222 next_proto == IPPROTO_ESP ||
2223 next_proto == IPPROTO_AH ||
2224 next_proto == IPPROTO_DSTOPTS)
2225 return rte_flow_error_set(error, EINVAL,
2226 RTE_FLOW_ERROR_TYPE_ITEM, item,
2227 "IPv6 proto (next header) should "
2228 "not be set as extension header");
2229 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2230 return rte_flow_error_set(error, EINVAL,
2231 RTE_FLOW_ERROR_TYPE_ITEM, item,
2232 "wrong tunnel type - IPv4 specified "
2233 "but IPv6 item provided");
2234 if (item_flags & l3m)
2235 return rte_flow_error_set(error, ENOTSUP,
2236 RTE_FLOW_ERROR_TYPE_ITEM, item,
2237 "multiple L3 layers not supported");
2238 else if (item_flags & l4m)
2239 return rte_flow_error_set(error, EINVAL,
2240 RTE_FLOW_ERROR_TYPE_ITEM, item,
2241 "L3 cannot follow an L4 layer.");
2242 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2243 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2244 return rte_flow_error_set(error, EINVAL,
2245 RTE_FLOW_ERROR_TYPE_ITEM, item,
2246 "L3 cannot follow an NVGRE layer.");
2248 mask = &rte_flow_item_ipv6_mask;
2249 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2250 acc_mask ? (const uint8_t *)acc_mask
2251 : (const uint8_t *)&nic_mask,
2252 sizeof(struct rte_flow_item_ipv6),
2253 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2260 * Validate UDP item.
2263 * Item specification.
2264 * @param[in] item_flags
2265 * Bit-fields that holds the items detected until now.
2266 * @param[in] target_protocol
2267 * The next protocol in the previous item.
2268 * @param[in] flow_mask
2269 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2271 * Pointer to error structure.
2274 * 0 on success, a negative errno value otherwise and rte_errno is set.
2277 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2278 uint64_t item_flags,
2279 uint8_t target_protocol,
2280 struct rte_flow_error *error)
2282 const struct rte_flow_item_udp *mask = item->mask;
2283 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2284 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2285 MLX5_FLOW_LAYER_OUTER_L3;
2286 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2287 MLX5_FLOW_LAYER_OUTER_L4;
2290 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2291 return rte_flow_error_set(error, EINVAL,
2292 RTE_FLOW_ERROR_TYPE_ITEM, item,
2293 "protocol filtering not compatible"
2295 if (!(item_flags & l3m))
2296 return rte_flow_error_set(error, EINVAL,
2297 RTE_FLOW_ERROR_TYPE_ITEM, item,
2298 "L3 is mandatory to filter on L4");
2299 if (item_flags & l4m)
2300 return rte_flow_error_set(error, EINVAL,
2301 RTE_FLOW_ERROR_TYPE_ITEM, item,
2302 "multiple L4 layers not supported");
2304 mask = &rte_flow_item_udp_mask;
2305 ret = mlx5_flow_item_acceptable
2306 (item, (const uint8_t *)mask,
2307 (const uint8_t *)&rte_flow_item_udp_mask,
2308 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2316 * Validate TCP item.
2319 * Item specification.
2320 * @param[in] item_flags
2321 * Bit-fields that holds the items detected until now.
2322 * @param[in] target_protocol
2323 * The next protocol in the previous item.
2325 * Pointer to error structure.
2328 * 0 on success, a negative errno value otherwise and rte_errno is set.
2331 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2332 uint64_t item_flags,
2333 uint8_t target_protocol,
2334 const struct rte_flow_item_tcp *flow_mask,
2335 struct rte_flow_error *error)
2337 const struct rte_flow_item_tcp *mask = item->mask;
2338 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2339 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2340 MLX5_FLOW_LAYER_OUTER_L3;
2341 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2342 MLX5_FLOW_LAYER_OUTER_L4;
2345 MLX5_ASSERT(flow_mask);
2346 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2347 return rte_flow_error_set(error, EINVAL,
2348 RTE_FLOW_ERROR_TYPE_ITEM, item,
2349 "protocol filtering not compatible"
2351 if (!(item_flags & l3m))
2352 return rte_flow_error_set(error, EINVAL,
2353 RTE_FLOW_ERROR_TYPE_ITEM, item,
2354 "L3 is mandatory to filter on L4");
2355 if (item_flags & l4m)
2356 return rte_flow_error_set(error, EINVAL,
2357 RTE_FLOW_ERROR_TYPE_ITEM, item,
2358 "multiple L4 layers not supported");
2360 mask = &rte_flow_item_tcp_mask;
2361 ret = mlx5_flow_item_acceptable
2362 (item, (const uint8_t *)mask,
2363 (const uint8_t *)flow_mask,
2364 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2372 * Validate VXLAN item.
2375 * Item specification.
2376 * @param[in] item_flags
2377 * Bit-fields that holds the items detected until now.
2378 * @param[in] target_protocol
2379 * The next protocol in the previous item.
2381 * Pointer to error structure.
2384 * 0 on success, a negative errno value otherwise and rte_errno is set.
2387 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
2388 uint64_t item_flags,
2389 struct rte_flow_error *error)
2391 const struct rte_flow_item_vxlan *spec = item->spec;
2392 const struct rte_flow_item_vxlan *mask = item->mask;
2397 } id = { .vlan_id = 0, };
2400 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2401 return rte_flow_error_set(error, ENOTSUP,
2402 RTE_FLOW_ERROR_TYPE_ITEM, item,
2403 "multiple tunnel layers not"
2406 * Verify only UDPv4 is present as defined in
2407 * https://tools.ietf.org/html/rfc7348
2409 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2410 return rte_flow_error_set(error, EINVAL,
2411 RTE_FLOW_ERROR_TYPE_ITEM, item,
2412 "no outer UDP layer found");
2414 mask = &rte_flow_item_vxlan_mask;
2415 ret = mlx5_flow_item_acceptable
2416 (item, (const uint8_t *)mask,
2417 (const uint8_t *)&rte_flow_item_vxlan_mask,
2418 sizeof(struct rte_flow_item_vxlan),
2419 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2423 memcpy(&id.vni[1], spec->vni, 3);
2424 memcpy(&id.vni[1], mask->vni, 3);
2426 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2427 return rte_flow_error_set(error, ENOTSUP,
2428 RTE_FLOW_ERROR_TYPE_ITEM, item,
2429 "VXLAN tunnel must be fully defined");
2434 * Validate VXLAN_GPE item.
2437 * Item specification.
2438 * @param[in] item_flags
2439 * Bit-fields that holds the items detected until now.
2441 * Pointer to the private data structure.
2442 * @param[in] target_protocol
2443 * The next protocol in the previous item.
2445 * Pointer to error structure.
2448 * 0 on success, a negative errno value otherwise and rte_errno is set.
2451 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2452 uint64_t item_flags,
2453 struct rte_eth_dev *dev,
2454 struct rte_flow_error *error)
2456 struct mlx5_priv *priv = dev->data->dev_private;
2457 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2458 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2463 } id = { .vlan_id = 0, };
2465 if (!priv->config.l3_vxlan_en)
2466 return rte_flow_error_set(error, ENOTSUP,
2467 RTE_FLOW_ERROR_TYPE_ITEM, item,
2468 "L3 VXLAN is not enabled by device"
2469 " parameter and/or not configured in"
2471 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2472 return rte_flow_error_set(error, ENOTSUP,
2473 RTE_FLOW_ERROR_TYPE_ITEM, item,
2474 "multiple tunnel layers not"
2477 * Verify only UDPv4 is present as defined in
2478 * https://tools.ietf.org/html/rfc7348
2480 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2481 return rte_flow_error_set(error, EINVAL,
2482 RTE_FLOW_ERROR_TYPE_ITEM, item,
2483 "no outer UDP layer found");
2485 mask = &rte_flow_item_vxlan_gpe_mask;
2486 ret = mlx5_flow_item_acceptable
2487 (item, (const uint8_t *)mask,
2488 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2489 sizeof(struct rte_flow_item_vxlan_gpe),
2490 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2495 return rte_flow_error_set(error, ENOTSUP,
2496 RTE_FLOW_ERROR_TYPE_ITEM,
2498 "VxLAN-GPE protocol"
2500 memcpy(&id.vni[1], spec->vni, 3);
2501 memcpy(&id.vni[1], mask->vni, 3);
2503 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2504 return rte_flow_error_set(error, ENOTSUP,
2505 RTE_FLOW_ERROR_TYPE_ITEM, item,
2506 "VXLAN-GPE tunnel must be fully"
2511 * Validate GRE Key item.
2514 * Item specification.
2515 * @param[in] item_flags
2516 * Bit flags to mark detected items.
2517 * @param[in] gre_item
2518 * Pointer to gre_item
2520 * Pointer to error structure.
2523 * 0 on success, a negative errno value otherwise and rte_errno is set.
2526 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2527 uint64_t item_flags,
2528 const struct rte_flow_item *gre_item,
2529 struct rte_flow_error *error)
2531 const rte_be32_t *mask = item->mask;
2533 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2534 const struct rte_flow_item_gre *gre_spec;
2535 const struct rte_flow_item_gre *gre_mask;
2537 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2538 return rte_flow_error_set(error, ENOTSUP,
2539 RTE_FLOW_ERROR_TYPE_ITEM, item,
2540 "Multiple GRE key not support");
2541 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2542 return rte_flow_error_set(error, ENOTSUP,
2543 RTE_FLOW_ERROR_TYPE_ITEM, item,
2544 "No preceding GRE header");
2545 if (item_flags & MLX5_FLOW_LAYER_INNER)
2546 return rte_flow_error_set(error, ENOTSUP,
2547 RTE_FLOW_ERROR_TYPE_ITEM, item,
2548 "GRE key following a wrong item");
2549 gre_mask = gre_item->mask;
2551 gre_mask = &rte_flow_item_gre_mask;
2552 gre_spec = gre_item->spec;
2553 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2554 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2555 return rte_flow_error_set(error, EINVAL,
2556 RTE_FLOW_ERROR_TYPE_ITEM, item,
2557 "Key bit must be on");
2560 mask = &gre_key_default_mask;
2561 ret = mlx5_flow_item_acceptable
2562 (item, (const uint8_t *)mask,
2563 (const uint8_t *)&gre_key_default_mask,
2564 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2569 * Validate GRE item.
2572 * Item specification.
2573 * @param[in] item_flags
2574 * Bit flags to mark detected items.
2575 * @param[in] target_protocol
2576 * The next protocol in the previous item.
2578 * Pointer to error structure.
2581 * 0 on success, a negative errno value otherwise and rte_errno is set.
2584 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2585 uint64_t item_flags,
2586 uint8_t target_protocol,
2587 struct rte_flow_error *error)
2589 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2590 const struct rte_flow_item_gre *mask = item->mask;
2592 const struct rte_flow_item_gre nic_mask = {
2593 .c_rsvd0_ver = RTE_BE16(0xB000),
2594 .protocol = RTE_BE16(UINT16_MAX),
2597 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2598 return rte_flow_error_set(error, EINVAL,
2599 RTE_FLOW_ERROR_TYPE_ITEM, item,
2600 "protocol filtering not compatible"
2601 " with this GRE layer");
2602 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2603 return rte_flow_error_set(error, ENOTSUP,
2604 RTE_FLOW_ERROR_TYPE_ITEM, item,
2605 "multiple tunnel layers not"
2607 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2608 return rte_flow_error_set(error, ENOTSUP,
2609 RTE_FLOW_ERROR_TYPE_ITEM, item,
2610 "L3 Layer is missing");
2612 mask = &rte_flow_item_gre_mask;
2613 ret = mlx5_flow_item_acceptable
2614 (item, (const uint8_t *)mask,
2615 (const uint8_t *)&nic_mask,
2616 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2620 #ifndef HAVE_MLX5DV_DR
2621 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2622 if (spec && (spec->protocol & mask->protocol))
2623 return rte_flow_error_set(error, ENOTSUP,
2624 RTE_FLOW_ERROR_TYPE_ITEM, item,
2625 "without MPLS support the"
2626 " specification cannot be used for"
2634 * Validate Geneve item.
2637 * Item specification.
2638 * @param[in] itemFlags
2639 * Bit-fields that holds the items detected until now.
2641 * Pointer to the private data structure.
2643 * Pointer to error structure.
2646 * 0 on success, a negative errno value otherwise and rte_errno is set.
2650 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2651 uint64_t item_flags,
2652 struct rte_eth_dev *dev,
2653 struct rte_flow_error *error)
2655 struct mlx5_priv *priv = dev->data->dev_private;
2656 const struct rte_flow_item_geneve *spec = item->spec;
2657 const struct rte_flow_item_geneve *mask = item->mask;
2660 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2661 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2662 const struct rte_flow_item_geneve nic_mask = {
2663 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2664 .vni = "\xff\xff\xff",
2665 .protocol = RTE_BE16(UINT16_MAX),
2668 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2669 return rte_flow_error_set(error, ENOTSUP,
2670 RTE_FLOW_ERROR_TYPE_ITEM, item,
2671 "L3 Geneve is not enabled by device"
2672 " parameter and/or not configured in"
2674 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2675 return rte_flow_error_set(error, ENOTSUP,
2676 RTE_FLOW_ERROR_TYPE_ITEM, item,
2677 "multiple tunnel layers not"
2680 * Verify only UDPv4 is present as defined in
2681 * https://tools.ietf.org/html/rfc7348
2683 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2684 return rte_flow_error_set(error, EINVAL,
2685 RTE_FLOW_ERROR_TYPE_ITEM, item,
2686 "no outer UDP layer found");
2688 mask = &rte_flow_item_geneve_mask;
2689 ret = mlx5_flow_item_acceptable
2690 (item, (const uint8_t *)mask,
2691 (const uint8_t *)&nic_mask,
2692 sizeof(struct rte_flow_item_geneve),
2693 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2697 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2698 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2699 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2700 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2701 return rte_flow_error_set(error, ENOTSUP,
2702 RTE_FLOW_ERROR_TYPE_ITEM,
2704 "Geneve protocol unsupported"
2705 " fields are being used");
2706 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2707 return rte_flow_error_set
2709 RTE_FLOW_ERROR_TYPE_ITEM,
2711 "Unsupported Geneve options length");
2713 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2714 return rte_flow_error_set
2716 RTE_FLOW_ERROR_TYPE_ITEM, item,
2717 "Geneve tunnel must be fully defined");
2722 * Validate MPLS item.
2725 * Pointer to the rte_eth_dev structure.
2727 * Item specification.
2728 * @param[in] item_flags
2729 * Bit-fields that holds the items detected until now.
2730 * @param[in] prev_layer
2731 * The protocol layer indicated in previous item.
2733 * Pointer to error structure.
2736 * 0 on success, a negative errno value otherwise and rte_errno is set.
2739 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2740 const struct rte_flow_item *item __rte_unused,
2741 uint64_t item_flags __rte_unused,
2742 uint64_t prev_layer __rte_unused,
2743 struct rte_flow_error *error)
2745 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2746 const struct rte_flow_item_mpls *mask = item->mask;
2747 struct mlx5_priv *priv = dev->data->dev_private;
2750 if (!priv->config.mpls_en)
2751 return rte_flow_error_set(error, ENOTSUP,
2752 RTE_FLOW_ERROR_TYPE_ITEM, item,
2753 "MPLS not supported or"
2754 " disabled in firmware"
2756 /* MPLS over IP, UDP, GRE is allowed */
2757 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2758 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2759 MLX5_FLOW_LAYER_GRE)))
2760 return rte_flow_error_set(error, EINVAL,
2761 RTE_FLOW_ERROR_TYPE_ITEM, item,
2762 "protocol filtering not compatible"
2763 " with MPLS layer");
2764 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2765 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2766 !(item_flags & MLX5_FLOW_LAYER_GRE))
2767 return rte_flow_error_set(error, ENOTSUP,
2768 RTE_FLOW_ERROR_TYPE_ITEM, item,
2769 "multiple tunnel layers not"
2772 mask = &rte_flow_item_mpls_mask;
2773 ret = mlx5_flow_item_acceptable
2774 (item, (const uint8_t *)mask,
2775 (const uint8_t *)&rte_flow_item_mpls_mask,
2776 sizeof(struct rte_flow_item_mpls),
2777 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2782 return rte_flow_error_set(error, ENOTSUP,
2783 RTE_FLOW_ERROR_TYPE_ITEM, item,
2784 "MPLS is not supported by Verbs, please"
2790 * Validate NVGRE item.
2793 * Item specification.
2794 * @param[in] item_flags
2795 * Bit flags to mark detected items.
2796 * @param[in] target_protocol
2797 * The next protocol in the previous item.
2799 * Pointer to error structure.
2802 * 0 on success, a negative errno value otherwise and rte_errno is set.
2805 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2806 uint64_t item_flags,
2807 uint8_t target_protocol,
2808 struct rte_flow_error *error)
2810 const struct rte_flow_item_nvgre *mask = item->mask;
2813 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2814 return rte_flow_error_set(error, EINVAL,
2815 RTE_FLOW_ERROR_TYPE_ITEM, item,
2816 "protocol filtering not compatible"
2817 " with this GRE layer");
2818 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2819 return rte_flow_error_set(error, ENOTSUP,
2820 RTE_FLOW_ERROR_TYPE_ITEM, item,
2821 "multiple tunnel layers not"
2823 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2824 return rte_flow_error_set(error, ENOTSUP,
2825 RTE_FLOW_ERROR_TYPE_ITEM, item,
2826 "L3 Layer is missing");
2828 mask = &rte_flow_item_nvgre_mask;
2829 ret = mlx5_flow_item_acceptable
2830 (item, (const uint8_t *)mask,
2831 (const uint8_t *)&rte_flow_item_nvgre_mask,
2832 sizeof(struct rte_flow_item_nvgre),
2833 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2840 * Validate eCPRI item.
2843 * Item specification.
2844 * @param[in] item_flags
2845 * Bit-fields that holds the items detected until now.
2846 * @param[in] last_item
2847 * Previous validated item in the pattern items.
2848 * @param[in] ether_type
2849 * Type in the ethernet layer header (including dot1q).
2850 * @param[in] acc_mask
2851 * Acceptable mask, if NULL default internal default mask
2852 * will be used to check whether item fields are supported.
2854 * Pointer to error structure.
2857 * 0 on success, a negative errno value otherwise and rte_errno is set.
2860 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
2861 uint64_t item_flags,
2863 uint16_t ether_type,
2864 const struct rte_flow_item_ecpri *acc_mask,
2865 struct rte_flow_error *error)
2867 const struct rte_flow_item_ecpri *mask = item->mask;
2868 const struct rte_flow_item_ecpri nic_mask = {
2872 RTE_BE32(((const struct rte_ecpri_common_hdr) {
2876 .dummy[0] = 0xFFFFFFFF,
2879 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
2880 MLX5_FLOW_LAYER_OUTER_VLAN);
2881 struct rte_flow_item_ecpri mask_lo;
2883 if ((last_item & outer_l2_vlan) && ether_type &&
2884 ether_type != RTE_ETHER_TYPE_ECPRI)
2885 return rte_flow_error_set(error, EINVAL,
2886 RTE_FLOW_ERROR_TYPE_ITEM, item,
2887 "eCPRI cannot follow L2/VLAN layer "
2888 "which ether type is not 0xAEFE.");
2889 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2890 return rte_flow_error_set(error, EINVAL,
2891 RTE_FLOW_ERROR_TYPE_ITEM, item,
2892 "eCPRI with tunnel is not supported "
2894 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
2895 return rte_flow_error_set(error, ENOTSUP,
2896 RTE_FLOW_ERROR_TYPE_ITEM, item,
2897 "multiple L3 layers not supported");
2898 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
2899 return rte_flow_error_set(error, EINVAL,
2900 RTE_FLOW_ERROR_TYPE_ITEM, item,
2901 "eCPRI cannot follow a TCP layer.");
2902 /* In specification, eCPRI could be over UDP layer. */
2903 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
2904 return rte_flow_error_set(error, EINVAL,
2905 RTE_FLOW_ERROR_TYPE_ITEM, item,
2906 "eCPRI over UDP layer is not yet "
2907 "supported right now.");
2908 /* Mask for type field in common header could be zero. */
2910 mask = &rte_flow_item_ecpri_mask;
2911 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
2912 /* Input mask is in big-endian format. */
2913 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
2914 return rte_flow_error_set(error, EINVAL,
2915 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2916 "partial mask is not supported "
2918 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
2919 return rte_flow_error_set(error, EINVAL,
2920 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2921 "message header mask must be after "
2923 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2924 acc_mask ? (const uint8_t *)acc_mask
2925 : (const uint8_t *)&nic_mask,
2926 sizeof(struct rte_flow_item_ecpri),
2927 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2930 /* Allocate unique ID for the split Q/RSS subflows. */
2932 flow_qrss_get_id(struct rte_eth_dev *dev)
2934 struct mlx5_priv *priv = dev->data->dev_private;
2935 uint32_t qrss_id, ret;
2937 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2940 MLX5_ASSERT(qrss_id);
2944 /* Free unique ID for the split Q/RSS subflows. */
2946 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2948 struct mlx5_priv *priv = dev->data->dev_private;
2951 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2955 * Release resource related QUEUE/RSS action split.
2958 * Pointer to Ethernet device.
2960 * Flow to release id's from.
2963 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2964 struct rte_flow *flow)
2966 struct mlx5_priv *priv = dev->data->dev_private;
2967 uint32_t handle_idx;
2968 struct mlx5_flow_handle *dev_handle;
2970 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
2971 handle_idx, dev_handle, next)
2972 if (dev_handle->split_flow_id)
2973 flow_qrss_free_id(dev, dev_handle->split_flow_id);
2977 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2978 const struct rte_flow_attr *attr __rte_unused,
2979 const struct rte_flow_item items[] __rte_unused,
2980 const struct rte_flow_action actions[] __rte_unused,
2981 bool external __rte_unused,
2982 int hairpin __rte_unused,
2983 struct rte_flow_error *error)
2985 return rte_flow_error_set(error, ENOTSUP,
2986 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2989 static struct mlx5_flow *
2990 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
2991 const struct rte_flow_attr *attr __rte_unused,
2992 const struct rte_flow_item items[] __rte_unused,
2993 const struct rte_flow_action actions[] __rte_unused,
2994 struct rte_flow_error *error)
2996 rte_flow_error_set(error, ENOTSUP,
2997 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3002 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3003 struct mlx5_flow *dev_flow __rte_unused,
3004 const struct rte_flow_attr *attr __rte_unused,
3005 const struct rte_flow_item items[] __rte_unused,
3006 const struct rte_flow_action actions[] __rte_unused,
3007 struct rte_flow_error *error)
3009 return rte_flow_error_set(error, ENOTSUP,
3010 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3014 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3015 struct rte_flow *flow __rte_unused,
3016 struct rte_flow_error *error)
3018 return rte_flow_error_set(error, ENOTSUP,
3019 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3023 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3024 struct rte_flow *flow __rte_unused)
3029 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3030 struct rte_flow *flow __rte_unused)
3035 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3036 struct rte_flow *flow __rte_unused,
3037 const struct rte_flow_action *actions __rte_unused,
3038 void *data __rte_unused,
3039 struct rte_flow_error *error)
3041 return rte_flow_error_set(error, ENOTSUP,
3042 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3045 /* Void driver to protect from null pointer reference. */
3046 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3047 .validate = flow_null_validate,
3048 .prepare = flow_null_prepare,
3049 .translate = flow_null_translate,
3050 .apply = flow_null_apply,
3051 .remove = flow_null_remove,
3052 .destroy = flow_null_destroy,
3053 .query = flow_null_query,
3057 * Select flow driver type according to flow attributes and device
3061 * Pointer to the dev structure.
3063 * Pointer to the flow attributes.
3066 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3068 static enum mlx5_flow_drv_type
3069 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3071 struct mlx5_priv *priv = dev->data->dev_private;
3072 /* The OS can determine first a specific flow type (DV, VERBS) */
3073 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3075 if (type != MLX5_FLOW_TYPE_MAX)
3077 /* If no OS specific type - continue with DV/VERBS selection */
3078 if (attr->transfer && priv->config.dv_esw_en)
3079 type = MLX5_FLOW_TYPE_DV;
3080 if (!attr->transfer)
3081 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3082 MLX5_FLOW_TYPE_VERBS;
3086 #define flow_get_drv_ops(type) flow_drv_ops[type]
3089 * Flow driver validation API. This abstracts calling driver specific functions.
3090 * The type of flow driver is determined according to flow attributes.
3093 * Pointer to the dev structure.
3095 * Pointer to the flow attributes.
3097 * Pointer to the list of items.
3098 * @param[in] actions
3099 * Pointer to the list of actions.
3100 * @param[in] external
3101 * This flow rule is created by request external to PMD.
3102 * @param[in] hairpin
3103 * Number of hairpin TX actions, 0 means classic flow.
3105 * Pointer to the error structure.
3108 * 0 on success, a negative errno value otherwise and rte_errno is set.
3111 flow_drv_validate(struct rte_eth_dev *dev,
3112 const struct rte_flow_attr *attr,
3113 const struct rte_flow_item items[],
3114 const struct rte_flow_action actions[],
3115 bool external, int hairpin, struct rte_flow_error *error)
3117 const struct mlx5_flow_driver_ops *fops;
3118 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3120 fops = flow_get_drv_ops(type);
3121 return fops->validate(dev, attr, items, actions, external,
3126 * Flow driver preparation API. This abstracts calling driver specific
3127 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3128 * calculates the size of memory required for device flow, allocates the memory,
3129 * initializes the device flow and returns the pointer.
3132 * This function initializes device flow structure such as dv or verbs in
3133 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3134 * rest. For example, adding returning device flow to flow->dev_flow list and
3135 * setting backward reference to the flow should be done out of this function.
3136 * layers field is not filled either.
3139 * Pointer to the dev structure.
3141 * Pointer to the flow attributes.
3143 * Pointer to the list of items.
3144 * @param[in] actions
3145 * Pointer to the list of actions.
3146 * @param[in] flow_idx
3147 * This memory pool index to the flow.
3149 * Pointer to the error structure.
3152 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3154 static inline struct mlx5_flow *
3155 flow_drv_prepare(struct rte_eth_dev *dev,
3156 const struct rte_flow *flow,
3157 const struct rte_flow_attr *attr,
3158 const struct rte_flow_item items[],
3159 const struct rte_flow_action actions[],
3161 struct rte_flow_error *error)
3163 const struct mlx5_flow_driver_ops *fops;
3164 enum mlx5_flow_drv_type type = flow->drv_type;
3165 struct mlx5_flow *mlx5_flow = NULL;
3167 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3168 fops = flow_get_drv_ops(type);
3169 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3171 mlx5_flow->flow_idx = flow_idx;
3176 * Flow driver translation API. This abstracts calling driver specific
3177 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3178 * translates a generic flow into a driver flow. flow_drv_prepare() must
3182 * dev_flow->layers could be filled as a result of parsing during translation
3183 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3184 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3185 * flow->actions could be overwritten even though all the expanded dev_flows
3186 * have the same actions.
3189 * Pointer to the rte dev structure.
3190 * @param[in, out] dev_flow
3191 * Pointer to the mlx5 flow.
3193 * Pointer to the flow attributes.
3195 * Pointer to the list of items.
3196 * @param[in] actions
3197 * Pointer to the list of actions.
3199 * Pointer to the error structure.
3202 * 0 on success, a negative errno value otherwise and rte_errno is set.
3205 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3206 const struct rte_flow_attr *attr,
3207 const struct rte_flow_item items[],
3208 const struct rte_flow_action actions[],
3209 struct rte_flow_error *error)
3211 const struct mlx5_flow_driver_ops *fops;
3212 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3214 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3215 fops = flow_get_drv_ops(type);
3216 return fops->translate(dev, dev_flow, attr, items, actions, error);
3220 * Flow driver apply API. This abstracts calling driver specific functions.
3221 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3222 * translated driver flows on to device. flow_drv_translate() must precede.
3225 * Pointer to Ethernet device structure.
3226 * @param[in, out] flow
3227 * Pointer to flow structure.
3229 * Pointer to error structure.
3232 * 0 on success, a negative errno value otherwise and rte_errno is set.
3235 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3236 struct rte_flow_error *error)
3238 const struct mlx5_flow_driver_ops *fops;
3239 enum mlx5_flow_drv_type type = flow->drv_type;
3241 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3242 fops = flow_get_drv_ops(type);
3243 return fops->apply(dev, flow, error);
3247 * Flow driver remove API. This abstracts calling driver specific functions.
3248 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3249 * on device. All the resources of the flow should be freed by calling
3250 * flow_drv_destroy().
3253 * Pointer to Ethernet device.
3254 * @param[in, out] flow
3255 * Pointer to flow structure.
3258 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
3260 const struct mlx5_flow_driver_ops *fops;
3261 enum mlx5_flow_drv_type type = flow->drv_type;
3263 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3264 fops = flow_get_drv_ops(type);
3265 fops->remove(dev, flow);
3269 * Flow driver destroy API. This abstracts calling driver specific functions.
3270 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3271 * on device and releases resources of the flow.
3274 * Pointer to Ethernet device.
3275 * @param[in, out] flow
3276 * Pointer to flow structure.
3279 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3281 const struct mlx5_flow_driver_ops *fops;
3282 enum mlx5_flow_drv_type type = flow->drv_type;
3284 flow_mreg_split_qrss_release(dev, flow);
3285 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3286 fops = flow_get_drv_ops(type);
3287 fops->destroy(dev, flow);
3291 * Get RSS action from the action list.
3293 * @param[in] actions
3294 * Pointer to the list of actions.
3297 * Pointer to the RSS action if exist, else return NULL.
3299 static const struct rte_flow_action_rss*
3300 flow_get_rss_action(const struct rte_flow_action actions[])
3302 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3303 switch (actions->type) {
3304 case RTE_FLOW_ACTION_TYPE_RSS:
3305 return (const struct rte_flow_action_rss *)
3314 /* maps shared action to translated non shared in some actions array */
3315 struct mlx5_translated_shared_action {
3316 struct rte_flow_shared_action *action; /**< Shared action */
3317 int index; /**< Index in related array of rte_flow_action */
3321 * Translates actions of type RTE_FLOW_ACTION_TYPE_SHARED to related
3322 * non shared action if translation possible.
3323 * This functionality used to run same execution path for both shared & non
3324 * shared actions on flow create. All necessary preparations for shared
3325 * action handling should be preformed on *shared* actions list returned
3328 * @param[in] actions
3329 * List of actions to translate.
3330 * @param[out] shared
3331 * List to store translated shared actions.
3332 * @param[in, out] shared_n
3333 * Size of *shared* array. On return should be updated with number of shared
3334 * actions retrieved from the *actions* list.
3335 * @param[out] translated_actions
3336 * List of actions where all shared actions were translated to non shared
3337 * if possible. NULL if no translation took place.
3339 * Pointer to the error structure.
3342 * 0 on success, a negative errno value otherwise and rte_errno is set.
3345 flow_shared_actions_translate(const struct rte_flow_action actions[],
3346 struct mlx5_translated_shared_action *shared,
3348 struct rte_flow_action **translated_actions,
3349 struct rte_flow_error *error)
3351 struct rte_flow_action *translated = NULL;
3352 size_t actions_size;
3355 struct mlx5_translated_shared_action *shared_end = NULL;
3357 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3358 if (actions[n].type != RTE_FLOW_ACTION_TYPE_SHARED)
3360 if (copied_n == *shared_n) {
3361 return rte_flow_error_set
3362 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3363 NULL, "too many shared actions");
3365 rte_memcpy(&shared[copied_n].action, &actions[n].conf,
3366 sizeof(actions[n].conf));
3367 shared[copied_n].index = n;
3371 *shared_n = copied_n;
3374 actions_size = sizeof(struct rte_flow_action) * n;
3375 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3380 memcpy(translated, actions, actions_size);
3381 for (shared_end = shared + copied_n; shared < shared_end; shared++) {
3382 const struct rte_flow_shared_action *shared_action;
3384 shared_action = shared->action;
3385 switch (shared_action->type) {
3386 case MLX5_RTE_FLOW_ACTION_TYPE_SHARED_RSS:
3387 translated[shared->index].type =
3388 RTE_FLOW_ACTION_TYPE_RSS;
3389 translated[shared->index].conf =
3390 &shared_action->rss.origin;
3393 mlx5_free(translated);
3394 return rte_flow_error_set
3395 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3396 NULL, "invalid shared action type");
3399 *translated_actions = translated;
3404 * Get Shared RSS action from the action list.
3407 * Pointer to the list of actions.
3408 * @param[in] shared_n
3409 * Actions list length.
3412 * Pointer to the MLX5 RSS action if exists, otherwise return NULL.
3414 static struct mlx5_shared_action_rss *
3415 flow_get_shared_rss_action(struct mlx5_translated_shared_action *shared,
3418 struct mlx5_translated_shared_action *shared_end;
3420 for (shared_end = shared + shared_n; shared < shared_end; shared++) {
3421 struct rte_flow_shared_action *shared_action;
3423 shared_action = shared->action;
3424 switch (shared_action->type) {
3425 case MLX5_RTE_FLOW_ACTION_TYPE_SHARED_RSS:
3426 __atomic_add_fetch(&shared_action->refcnt, 1,
3428 return &shared_action->rss;
3436 struct rte_flow_shared_action *
3437 mlx5_flow_get_shared_rss(struct rte_flow *flow)
3439 if (flow->shared_rss)
3440 return container_of(flow->shared_rss,
3441 struct rte_flow_shared_action, rss);
3447 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3449 const struct rte_flow_item *item;
3450 unsigned int has_vlan = 0;
3452 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3453 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3459 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3460 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3461 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3462 MLX5_EXPANSION_ROOT_OUTER;
3466 * Get layer flags from the prefix flow.
3468 * Some flows may be split to several subflows, the prefix subflow gets the
3469 * match items and the suffix sub flow gets the actions.
3470 * Some actions need the user defined match item flags to get the detail for
3472 * This function helps the suffix flow to get the item layer flags from prefix
3475 * @param[in] dev_flow
3476 * Pointer the created preifx subflow.
3479 * The layers get from prefix subflow.
3481 static inline uint64_t
3482 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3484 uint64_t layers = 0;
3487 * Layers bits could be localization, but usually the compiler will
3488 * help to do the optimization work for source code.
3489 * If no decap actions, use the layers directly.
3491 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3492 return dev_flow->handle->layers;
3493 /* Convert L3 layers with decap action. */
3494 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3495 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3496 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3497 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3498 /* Convert L4 layers with decap action. */
3499 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3500 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3501 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3502 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3507 * Get metadata split action information.
3509 * @param[in] actions
3510 * Pointer to the list of actions.
3512 * Pointer to the return pointer.
3513 * @param[out] qrss_type
3514 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3515 * if no QUEUE/RSS is found.
3516 * @param[out] encap_idx
3517 * Pointer to the index of the encap action if exists, otherwise the last
3521 * Total number of actions.
3524 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3525 const struct rte_flow_action **qrss,
3528 const struct rte_flow_action_raw_encap *raw_encap;
3530 int raw_decap_idx = -1;
3533 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3534 switch (actions->type) {
3535 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3536 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3537 *encap_idx = actions_n;
3539 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3540 raw_decap_idx = actions_n;
3542 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3543 raw_encap = actions->conf;
3544 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3545 *encap_idx = raw_decap_idx != -1 ?
3546 raw_decap_idx : actions_n;
3548 case RTE_FLOW_ACTION_TYPE_QUEUE:
3549 case RTE_FLOW_ACTION_TYPE_RSS:
3557 if (*encap_idx == -1)
3558 *encap_idx = actions_n;
3559 /* Count RTE_FLOW_ACTION_TYPE_END. */
3560 return actions_n + 1;
3564 * Check meter action from the action list.
3566 * @param[in] actions
3567 * Pointer to the list of actions.
3569 * Pointer to the meter exist flag.
3572 * Total number of actions.
3575 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
3581 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3582 switch (actions->type) {
3583 case RTE_FLOW_ACTION_TYPE_METER:
3591 /* Count RTE_FLOW_ACTION_TYPE_END. */
3592 return actions_n + 1;
3596 * Check if the flow should be split due to hairpin.
3597 * The reason for the split is that in current HW we can't
3598 * support encap and push-vlan on Rx, so if a flow contains
3599 * these actions we move it to Tx.
3602 * Pointer to Ethernet device.
3604 * Flow rule attributes.
3605 * @param[in] actions
3606 * Associated actions (list terminated by the END action).
3609 * > 0 the number of actions and the flow should be split,
3610 * 0 when no split required.
3613 flow_check_hairpin_split(struct rte_eth_dev *dev,
3614 const struct rte_flow_attr *attr,
3615 const struct rte_flow_action actions[])
3617 int queue_action = 0;
3620 const struct rte_flow_action_queue *queue;
3621 const struct rte_flow_action_rss *rss;
3622 const struct rte_flow_action_raw_encap *raw_encap;
3623 const struct rte_eth_hairpin_conf *conf;
3627 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3628 switch (actions->type) {
3629 case RTE_FLOW_ACTION_TYPE_QUEUE:
3630 queue = actions->conf;
3633 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
3634 if (conf != NULL && !!conf->tx_explicit)
3639 case RTE_FLOW_ACTION_TYPE_RSS:
3640 rss = actions->conf;
3641 if (rss == NULL || rss->queue_num == 0)
3643 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
3644 if (conf != NULL && !!conf->tx_explicit)
3649 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3650 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3651 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3652 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3653 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3657 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3658 raw_encap = actions->conf;
3659 if (raw_encap->size >
3660 (sizeof(struct rte_flow_item_eth) +
3661 sizeof(struct rte_flow_item_ipv4)))
3670 if (split && queue_action)
3675 /* Declare flow create/destroy prototype in advance. */
3677 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
3678 const struct rte_flow_attr *attr,
3679 const struct rte_flow_item items[],
3680 const struct rte_flow_action actions[],
3681 bool external, struct rte_flow_error *error);
3684 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
3688 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3690 * As mark_id is unique, if there's already a registered flow for the mark_id,
3691 * return by increasing the reference counter of the resource. Otherwise, create
3692 * the resource (mcp_res) and flow.
3695 * - If ingress port is ANY and reg_c[1] is mark_id,
3696 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3698 * For default flow (zero mark_id), flow is like,
3699 * - If ingress port is ANY,
3700 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
3703 * Pointer to Ethernet device.
3705 * ID of MARK action, zero means default flow for META.
3707 * Perform verbose error reporting if not NULL.
3710 * Associated resource on success, NULL otherwise and rte_errno is set.
3712 static struct mlx5_flow_mreg_copy_resource *
3713 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
3714 struct rte_flow_error *error)
3716 struct mlx5_priv *priv = dev->data->dev_private;
3717 struct rte_flow_attr attr = {
3718 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3721 struct mlx5_rte_flow_item_tag tag_spec = {
3724 struct rte_flow_item items[] = {
3725 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
3727 struct rte_flow_action_mark ftag = {
3730 struct mlx5_flow_action_copy_mreg cp_mreg = {
3734 struct rte_flow_action_jump jump = {
3735 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3737 struct rte_flow_action actions[] = {
3738 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
3740 struct mlx5_flow_mreg_copy_resource *mcp_res;
3744 /* Fill the register fileds in the flow. */
3745 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3749 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3753 /* Check if already registered. */
3754 MLX5_ASSERT(priv->mreg_cp_tbl);
3755 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
3757 /* For non-default rule. */
3758 if (mark_id != MLX5_DEFAULT_COPY_ID)
3760 MLX5_ASSERT(mark_id != MLX5_DEFAULT_COPY_ID ||
3761 mcp_res->refcnt == 1);
3764 /* Provide the full width of FLAG specific value. */
3765 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3766 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3767 /* Build a new flow. */
3768 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3769 items[0] = (struct rte_flow_item){
3770 .type = (enum rte_flow_item_type)
3771 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3774 items[1] = (struct rte_flow_item){
3775 .type = RTE_FLOW_ITEM_TYPE_END,
3777 actions[0] = (struct rte_flow_action){
3778 .type = (enum rte_flow_action_type)
3779 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3782 actions[1] = (struct rte_flow_action){
3783 .type = (enum rte_flow_action_type)
3784 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3787 actions[2] = (struct rte_flow_action){
3788 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3791 actions[3] = (struct rte_flow_action){
3792 .type = RTE_FLOW_ACTION_TYPE_END,
3795 /* Default rule, wildcard match. */
3796 attr.priority = MLX5_FLOW_PRIO_RSVD;
3797 items[0] = (struct rte_flow_item){
3798 .type = RTE_FLOW_ITEM_TYPE_END,
3800 actions[0] = (struct rte_flow_action){
3801 .type = (enum rte_flow_action_type)
3802 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3805 actions[1] = (struct rte_flow_action){
3806 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3809 actions[2] = (struct rte_flow_action){
3810 .type = RTE_FLOW_ACTION_TYPE_END,
3813 /* Build a new entry. */
3814 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3821 * The copy Flows are not included in any list. There
3822 * ones are referenced from other Flows and can not
3823 * be applied, removed, deleted in ardbitrary order
3824 * by list traversing.
3826 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3827 actions, false, error);
3828 if (!mcp_res->rix_flow)
3831 mcp_res->hlist_ent.key = mark_id;
3832 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3833 &mcp_res->hlist_ent);
3839 if (mcp_res->rix_flow)
3840 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3841 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3846 * Release flow in RX_CP_TBL.
3849 * Pointer to Ethernet device.
3851 * Parent flow for wich copying is provided.
3854 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3855 struct rte_flow *flow)
3857 struct mlx5_flow_mreg_copy_resource *mcp_res;
3858 struct mlx5_priv *priv = dev->data->dev_private;
3860 if (!flow->rix_mreg_copy)
3862 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3863 flow->rix_mreg_copy);
3864 if (!mcp_res || !priv->mreg_cp_tbl)
3866 if (flow->copy_applied) {
3867 MLX5_ASSERT(mcp_res->appcnt);
3868 flow->copy_applied = 0;
3870 if (!mcp_res->appcnt) {
3871 struct rte_flow *mcp_flow = mlx5_ipool_get
3872 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3876 flow_drv_remove(dev, mcp_flow);
3880 * We do not check availability of metadata registers here,
3881 * because copy resources are not allocated in this case.
3883 if (--mcp_res->refcnt)
3885 MLX5_ASSERT(mcp_res->rix_flow);
3886 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3887 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3888 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3889 flow->rix_mreg_copy = 0;
3893 * Start flow in RX_CP_TBL.
3896 * Pointer to Ethernet device.
3898 * Parent flow for wich copying is provided.
3901 * 0 on success, a negative errno value otherwise and rte_errno is set.
3904 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3905 struct rte_flow *flow)
3907 struct mlx5_flow_mreg_copy_resource *mcp_res;
3908 struct mlx5_priv *priv = dev->data->dev_private;
3911 if (!flow->rix_mreg_copy || flow->copy_applied)
3913 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3914 flow->rix_mreg_copy);
3917 if (!mcp_res->appcnt) {
3918 struct rte_flow *mcp_flow = mlx5_ipool_get
3919 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3923 ret = flow_drv_apply(dev, mcp_flow, NULL);
3929 flow->copy_applied = 1;
3934 * Stop flow in RX_CP_TBL.
3937 * Pointer to Ethernet device.
3939 * Parent flow for wich copying is provided.
3942 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3943 struct rte_flow *flow)
3945 struct mlx5_flow_mreg_copy_resource *mcp_res;
3946 struct mlx5_priv *priv = dev->data->dev_private;
3948 if (!flow->rix_mreg_copy || !flow->copy_applied)
3950 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3951 flow->rix_mreg_copy);
3954 MLX5_ASSERT(mcp_res->appcnt);
3956 flow->copy_applied = 0;
3957 if (!mcp_res->appcnt) {
3958 struct rte_flow *mcp_flow = mlx5_ipool_get
3959 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3963 flow_drv_remove(dev, mcp_flow);
3968 * Remove the default copy action from RX_CP_TBL.
3971 * Pointer to Ethernet device.
3974 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3976 struct mlx5_flow_mreg_copy_resource *mcp_res;
3977 struct mlx5_priv *priv = dev->data->dev_private;
3979 /* Check if default flow is registered. */
3980 if (!priv->mreg_cp_tbl)
3982 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3983 MLX5_DEFAULT_COPY_ID);
3986 MLX5_ASSERT(mcp_res->rix_flow);
3987 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3988 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3989 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3993 * Add the default copy action in in RX_CP_TBL.
3996 * Pointer to Ethernet device.
3998 * Perform verbose error reporting if not NULL.
4001 * 0 for success, negative value otherwise and rte_errno is set.
4004 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4005 struct rte_flow_error *error)
4007 struct mlx5_priv *priv = dev->data->dev_private;
4008 struct mlx5_flow_mreg_copy_resource *mcp_res;
4010 /* Check whether extensive metadata feature is engaged. */
4011 if (!priv->config.dv_flow_en ||
4012 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4013 !mlx5_flow_ext_mreg_supported(dev) ||
4014 !priv->sh->dv_regc0_mask)
4016 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
4023 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4025 * All the flow having Q/RSS action should be split by
4026 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4027 * performs the following,
4028 * - CQE->flow_tag := reg_c[1] (MARK)
4029 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4030 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4031 * but there should be a flow per each MARK ID set by MARK action.
4033 * For the aforementioned reason, if there's a MARK action in flow's action
4034 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4035 * the MARK ID to CQE's flow_tag like,
4036 * - If reg_c[1] is mark_id,
4037 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4039 * For SET_META action which stores value in reg_c[0], as the destination is
4040 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4041 * MARK ID means the default flow. The default flow looks like,
4042 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4045 * Pointer to Ethernet device.
4047 * Pointer to flow structure.
4048 * @param[in] actions
4049 * Pointer to the list of actions.
4051 * Perform verbose error reporting if not NULL.
4054 * 0 on success, negative value otherwise and rte_errno is set.
4057 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4058 struct rte_flow *flow,
4059 const struct rte_flow_action *actions,
4060 struct rte_flow_error *error)
4062 struct mlx5_priv *priv = dev->data->dev_private;
4063 struct mlx5_dev_config *config = &priv->config;
4064 struct mlx5_flow_mreg_copy_resource *mcp_res;
4065 const struct rte_flow_action_mark *mark;
4067 /* Check whether extensive metadata feature is engaged. */
4068 if (!config->dv_flow_en ||
4069 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4070 !mlx5_flow_ext_mreg_supported(dev) ||
4071 !priv->sh->dv_regc0_mask)
4073 /* Find MARK action. */
4074 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4075 switch (actions->type) {
4076 case RTE_FLOW_ACTION_TYPE_FLAG:
4077 mcp_res = flow_mreg_add_copy_action
4078 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4081 flow->rix_mreg_copy = mcp_res->idx;
4082 if (dev->data->dev_started) {
4084 flow->copy_applied = 1;
4087 case RTE_FLOW_ACTION_TYPE_MARK:
4088 mark = (const struct rte_flow_action_mark *)
4091 flow_mreg_add_copy_action(dev, mark->id, error);
4094 flow->rix_mreg_copy = mcp_res->idx;
4095 if (dev->data->dev_started) {
4097 flow->copy_applied = 1;
4107 #define MLX5_MAX_SPLIT_ACTIONS 24
4108 #define MLX5_MAX_SPLIT_ITEMS 24
4111 * Split the hairpin flow.
4112 * Since HW can't support encap and push-vlan on Rx, we move these
4114 * If the count action is after the encap then we also
4115 * move the count action. in this case the count will also measure
4119 * Pointer to Ethernet device.
4120 * @param[in] actions
4121 * Associated actions (list terminated by the END action).
4122 * @param[out] actions_rx
4124 * @param[out] actions_tx
4126 * @param[out] pattern_tx
4127 * The pattern items for the Tx flow.
4128 * @param[out] flow_id
4129 * The flow ID connected to this flow.
4135 flow_hairpin_split(struct rte_eth_dev *dev,
4136 const struct rte_flow_action actions[],
4137 struct rte_flow_action actions_rx[],
4138 struct rte_flow_action actions_tx[],
4139 struct rte_flow_item pattern_tx[],
4142 struct mlx5_priv *priv = dev->data->dev_private;
4143 const struct rte_flow_action_raw_encap *raw_encap;
4144 const struct rte_flow_action_raw_decap *raw_decap;
4145 struct mlx5_rte_flow_action_set_tag *set_tag;
4146 struct rte_flow_action *tag_action;
4147 struct mlx5_rte_flow_item_tag *tag_item;
4148 struct rte_flow_item *item;
4152 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
4153 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4154 switch (actions->type) {
4155 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4156 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4157 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4158 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4159 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4160 rte_memcpy(actions_tx, actions,
4161 sizeof(struct rte_flow_action));
4164 case RTE_FLOW_ACTION_TYPE_COUNT:
4166 rte_memcpy(actions_tx, actions,
4167 sizeof(struct rte_flow_action));
4170 rte_memcpy(actions_rx, actions,
4171 sizeof(struct rte_flow_action));
4175 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4176 raw_encap = actions->conf;
4177 if (raw_encap->size >
4178 (sizeof(struct rte_flow_item_eth) +
4179 sizeof(struct rte_flow_item_ipv4))) {
4180 memcpy(actions_tx, actions,
4181 sizeof(struct rte_flow_action));
4185 rte_memcpy(actions_rx, actions,
4186 sizeof(struct rte_flow_action));
4190 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4191 raw_decap = actions->conf;
4192 if (raw_decap->size <
4193 (sizeof(struct rte_flow_item_eth) +
4194 sizeof(struct rte_flow_item_ipv4))) {
4195 memcpy(actions_tx, actions,
4196 sizeof(struct rte_flow_action));
4199 rte_memcpy(actions_rx, actions,
4200 sizeof(struct rte_flow_action));
4205 rte_memcpy(actions_rx, actions,
4206 sizeof(struct rte_flow_action));
4211 /* Add set meta action and end action for the Rx flow. */
4212 tag_action = actions_rx;
4213 tag_action->type = (enum rte_flow_action_type)
4214 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4216 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4218 set_tag = (void *)actions_rx;
4219 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
4220 MLX5_ASSERT(set_tag->id > REG_NON);
4221 set_tag->data = *flow_id;
4222 tag_action->conf = set_tag;
4223 /* Create Tx item list. */
4224 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4225 addr = (void *)&pattern_tx[2];
4227 item->type = (enum rte_flow_item_type)
4228 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4229 tag_item = (void *)addr;
4230 tag_item->data = *flow_id;
4231 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4232 MLX5_ASSERT(set_tag->id > REG_NON);
4233 item->spec = tag_item;
4234 addr += sizeof(struct mlx5_rte_flow_item_tag);
4235 tag_item = (void *)addr;
4236 tag_item->data = UINT32_MAX;
4237 tag_item->id = UINT16_MAX;
4238 item->mask = tag_item;
4241 item->type = RTE_FLOW_ITEM_TYPE_END;
4246 union tunnel_offload_mark {
4249 uint32_t app_reserve:8;
4250 uint32_t table_id:15;
4251 uint32_t transfer:1;
4252 uint32_t _unused_:8;
4256 struct tunnel_default_miss_ctx {
4260 struct rte_flow_action_rss action_rss;
4261 struct rte_flow_action_queue miss_queue;
4262 struct rte_flow_action_jump miss_jump;
4268 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
4269 struct rte_flow *flow,
4270 const struct rte_flow_attr *attr,
4271 const struct rte_flow_action *app_actions,
4273 struct tunnel_default_miss_ctx *ctx,
4274 struct rte_flow_error *error)
4276 struct mlx5_priv *priv = dev->data->dev_private;
4277 struct mlx5_flow *dev_flow;
4278 struct rte_flow_attr miss_attr = *attr;
4279 const struct mlx5_flow_tunnel *tunnel = app_actions[0].conf;
4280 const struct rte_flow_item miss_items[2] = {
4282 .type = RTE_FLOW_ITEM_TYPE_ETH,
4288 .type = RTE_FLOW_ITEM_TYPE_END,
4294 union tunnel_offload_mark mark_id;
4295 struct rte_flow_action_mark miss_mark;
4296 struct rte_flow_action miss_actions[3] = {
4297 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
4298 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
4300 const struct rte_flow_action_jump *jump_data;
4301 uint32_t i, flow_table = 0; /* prevent compilation warning */
4302 struct flow_grp_info grp_info = {
4304 .transfer = attr->transfer,
4305 .fdb_def_rule = !!priv->fdb_def_rule,
4310 if (!attr->transfer) {
4313 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
4314 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
4315 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
4318 return rte_flow_error_set
4320 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4321 NULL, "invalid default miss RSS");
4322 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4323 ctx->action_rss.level = 0,
4324 ctx->action_rss.types = priv->rss_conf.rss_hf,
4325 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
4326 ctx->action_rss.queue_num = priv->reta_idx_n,
4327 ctx->action_rss.key = priv->rss_conf.rss_key,
4328 ctx->action_rss.queue = ctx->queue;
4329 if (!priv->reta_idx_n || !priv->rxqs_n)
4330 return rte_flow_error_set
4332 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4333 NULL, "invalid port configuration");
4334 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
4335 ctx->action_rss.types = 0;
4336 for (i = 0; i != priv->reta_idx_n; ++i)
4337 ctx->queue[i] = (*priv->reta_idx)[i];
4339 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
4340 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
4342 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
4343 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
4344 jump_data = app_actions->conf;
4345 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
4346 miss_attr.group = jump_data->group;
4347 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
4348 &flow_table, grp_info, error);
4350 return rte_flow_error_set(error, EINVAL,
4351 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4352 NULL, "invalid tunnel id");
4353 mark_id.app_reserve = 0;
4354 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
4355 mark_id.transfer = !!attr->transfer;
4356 mark_id._unused_ = 0;
4357 miss_mark.id = mark_id.val;
4358 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
4359 miss_items, miss_actions, flow_idx, error);
4362 dev_flow->flow = flow;
4363 dev_flow->external = true;
4364 dev_flow->tunnel = tunnel;
4365 /* Subflow object was created, we must include one in the list. */
4366 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4367 dev_flow->handle, next);
4369 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
4370 dev->data->port_id, tunnel->app_tunnel.type,
4371 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
4372 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
4373 miss_actions, error);
4375 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
4382 * The last stage of splitting chain, just creates the subflow
4383 * without any modification.
4386 * Pointer to Ethernet device.
4388 * Parent flow structure pointer.
4389 * @param[in, out] sub_flow
4390 * Pointer to return the created subflow, may be NULL.
4391 * @param[in] prefix_layers
4392 * Prefix subflow layers, may be 0.
4393 * @param[in] prefix_mark
4394 * Prefix subflow mark flag, may be 0.
4396 * Flow rule attributes.
4398 * Pattern specification (list terminated by the END pattern item).
4399 * @param[in] actions
4400 * Associated actions (list terminated by the END action).
4401 * @param[in] external
4402 * This flow rule is created by request external to PMD.
4403 * @param[in] flow_idx
4404 * This memory pool index to the flow.
4406 * Perform verbose error reporting if not NULL.
4408 * 0 on success, negative value otherwise
4411 flow_create_split_inner(struct rte_eth_dev *dev,
4412 struct rte_flow *flow,
4413 struct mlx5_flow **sub_flow,
4414 uint64_t prefix_layers,
4415 uint32_t prefix_mark,
4416 const struct rte_flow_attr *attr,
4417 const struct rte_flow_item items[],
4418 const struct rte_flow_action actions[],
4419 bool external, uint32_t flow_idx,
4420 struct rte_flow_error *error)
4422 struct mlx5_flow *dev_flow;
4424 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4428 dev_flow->flow = flow;
4429 dev_flow->external = external;
4430 /* Subflow object was created, we must include one in the list. */
4431 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4432 dev_flow->handle, next);
4434 * If dev_flow is as one of the suffix flow, some actions in suffix
4435 * flow may need some user defined item layer flags, and pass the
4436 * Metadate rxq mark flag to suffix flow as well.
4439 dev_flow->handle->layers = prefix_layers;
4441 dev_flow->handle->mark = 1;
4443 *sub_flow = dev_flow;
4444 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4448 * Split the meter flow.
4450 * As meter flow will split to three sub flow, other than meter
4451 * action, the other actions make sense to only meter accepts
4452 * the packet. If it need to be dropped, no other additional
4453 * actions should be take.
4455 * One kind of special action which decapsulates the L3 tunnel
4456 * header will be in the prefix sub flow, as not to take the
4457 * L3 tunnel header into account.
4460 * Pointer to Ethernet device.
4462 * Pattern specification (list terminated by the END pattern item).
4463 * @param[out] sfx_items
4464 * Suffix flow match items (list terminated by the END pattern item).
4465 * @param[in] actions
4466 * Associated actions (list terminated by the END action).
4467 * @param[out] actions_sfx
4468 * Suffix flow actions.
4469 * @param[out] actions_pre
4470 * Prefix flow actions.
4471 * @param[out] pattern_sfx
4472 * The pattern items for the suffix flow.
4473 * @param[out] tag_sfx
4474 * Pointer to suffix flow tag.
4480 flow_meter_split_prep(struct rte_eth_dev *dev,
4481 const struct rte_flow_item items[],
4482 struct rte_flow_item sfx_items[],
4483 const struct rte_flow_action actions[],
4484 struct rte_flow_action actions_sfx[],
4485 struct rte_flow_action actions_pre[])
4487 struct rte_flow_action *tag_action = NULL;
4488 struct rte_flow_item *tag_item;
4489 struct mlx5_rte_flow_action_set_tag *set_tag;
4490 struct rte_flow_error error;
4491 const struct rte_flow_action_raw_encap *raw_encap;
4492 const struct rte_flow_action_raw_decap *raw_decap;
4493 struct mlx5_rte_flow_item_tag *tag_spec;
4494 struct mlx5_rte_flow_item_tag *tag_mask;
4496 bool copy_vlan = false;
4498 /* Prepare the actions for prefix and suffix flow. */
4499 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4500 struct rte_flow_action **action_cur = NULL;
4502 switch (actions->type) {
4503 case RTE_FLOW_ACTION_TYPE_METER:
4504 /* Add the extra tag action first. */
4505 tag_action = actions_pre;
4506 tag_action->type = (enum rte_flow_action_type)
4507 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4509 action_cur = &actions_pre;
4511 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4512 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4513 action_cur = &actions_pre;
4515 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4516 raw_encap = actions->conf;
4517 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4518 action_cur = &actions_pre;
4520 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4521 raw_decap = actions->conf;
4522 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4523 action_cur = &actions_pre;
4525 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4526 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4533 action_cur = &actions_sfx;
4534 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
4537 /* Add end action to the actions. */
4538 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4539 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4542 set_tag = (void *)actions_pre;
4543 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4545 * Get the id from the qrss_pool to make qrss share the id with meter.
4547 tag_id = flow_qrss_get_id(dev);
4548 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
4550 tag_action->conf = set_tag;
4551 /* Prepare the suffix subflow items. */
4552 tag_item = sfx_items++;
4553 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4554 int item_type = items->type;
4556 switch (item_type) {
4557 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4558 memcpy(sfx_items, items, sizeof(*sfx_items));
4561 case RTE_FLOW_ITEM_TYPE_VLAN:
4563 memcpy(sfx_items, items, sizeof(*sfx_items));
4565 * Convert to internal match item, it is used
4566 * for vlan push and set vid.
4568 sfx_items->type = (enum rte_flow_item_type)
4569 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4577 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4579 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4580 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
4581 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4582 tag_mask = tag_spec + 1;
4583 tag_mask->data = 0xffffff00;
4584 tag_item->type = (enum rte_flow_item_type)
4585 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4586 tag_item->spec = tag_spec;
4587 tag_item->last = NULL;
4588 tag_item->mask = tag_mask;
4593 * Split action list having QUEUE/RSS for metadata register copy.
4595 * Once Q/RSS action is detected in user's action list, the flow action
4596 * should be split in order to copy metadata registers, which will happen in
4598 * - CQE->flow_tag := reg_c[1] (MARK)
4599 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4600 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
4601 * This is because the last action of each flow must be a terminal action
4602 * (QUEUE, RSS or DROP).
4604 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
4605 * stored and kept in the mlx5_flow structure per each sub_flow.
4607 * The Q/RSS action is replaced with,
4608 * - SET_TAG, setting the allocated flow ID to reg_c[2].
4609 * And the following JUMP action is added at the end,
4610 * - JUMP, to RX_CP_TBL.
4612 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
4613 * flow_create_split_metadata() routine. The flow will look like,
4614 * - If flow ID matches (reg_c[2]), perform Q/RSS.
4617 * Pointer to Ethernet device.
4618 * @param[out] split_actions
4619 * Pointer to store split actions to jump to CP_TBL.
4620 * @param[in] actions
4621 * Pointer to the list of original flow actions.
4623 * Pointer to the Q/RSS action.
4624 * @param[in] actions_n
4625 * Number of original actions.
4627 * Perform verbose error reporting if not NULL.
4630 * non-zero unique flow_id on success, otherwise 0 and
4631 * error/rte_error are set.
4634 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
4635 struct rte_flow_action *split_actions,
4636 const struct rte_flow_action *actions,
4637 const struct rte_flow_action *qrss,
4638 int actions_n, struct rte_flow_error *error)
4640 struct mlx5_rte_flow_action_set_tag *set_tag;
4641 struct rte_flow_action_jump *jump;
4642 const int qrss_idx = qrss - actions;
4643 uint32_t flow_id = 0;
4647 * Given actions will be split
4648 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
4649 * - Add jump to mreg CP_TBL.
4650 * As a result, there will be one more action.
4653 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
4654 set_tag = (void *)(split_actions + actions_n);
4656 * If tag action is not set to void(it means we are not the meter
4657 * suffix flow), add the tag action. Since meter suffix flow already
4658 * has the tag added.
4660 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
4662 * Allocate the new subflow ID. This one is unique within
4663 * device and not shared with representors. Otherwise,
4664 * we would have to resolve multi-thread access synch
4665 * issue. Each flow on the shared device is appended
4666 * with source vport identifier, so the resulting
4667 * flows will be unique in the shared (by master and
4668 * representors) domain even if they have coinciding
4671 flow_id = flow_qrss_get_id(dev);
4673 return rte_flow_error_set(error, ENOMEM,
4674 RTE_FLOW_ERROR_TYPE_ACTION,
4675 NULL, "can't allocate id "
4676 "for split Q/RSS subflow");
4677 /* Internal SET_TAG action to set flow ID. */
4678 *set_tag = (struct mlx5_rte_flow_action_set_tag){
4681 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
4685 /* Construct new actions array. */
4686 /* Replace QUEUE/RSS action. */
4687 split_actions[qrss_idx] = (struct rte_flow_action){
4688 .type = (enum rte_flow_action_type)
4689 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4693 /* JUMP action to jump to mreg copy table (CP_TBL). */
4694 jump = (void *)(set_tag + 1);
4695 *jump = (struct rte_flow_action_jump){
4696 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4698 split_actions[actions_n - 2] = (struct rte_flow_action){
4699 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4702 split_actions[actions_n - 1] = (struct rte_flow_action){
4703 .type = RTE_FLOW_ACTION_TYPE_END,
4709 * Extend the given action list for Tx metadata copy.
4711 * Copy the given action list to the ext_actions and add flow metadata register
4712 * copy action in order to copy reg_a set by WQE to reg_c[0].
4714 * @param[out] ext_actions
4715 * Pointer to the extended action list.
4716 * @param[in] actions
4717 * Pointer to the list of actions.
4718 * @param[in] actions_n
4719 * Number of actions in the list.
4721 * Perform verbose error reporting if not NULL.
4722 * @param[in] encap_idx
4723 * The encap action inndex.
4726 * 0 on success, negative value otherwise
4729 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
4730 struct rte_flow_action *ext_actions,
4731 const struct rte_flow_action *actions,
4732 int actions_n, struct rte_flow_error *error,
4735 struct mlx5_flow_action_copy_mreg *cp_mreg =
4736 (struct mlx5_flow_action_copy_mreg *)
4737 (ext_actions + actions_n + 1);
4740 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4744 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
4749 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
4750 if (encap_idx == actions_n - 1) {
4751 ext_actions[actions_n - 1] = (struct rte_flow_action){
4752 .type = (enum rte_flow_action_type)
4753 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4756 ext_actions[actions_n] = (struct rte_flow_action){
4757 .type = RTE_FLOW_ACTION_TYPE_END,
4760 ext_actions[encap_idx] = (struct rte_flow_action){
4761 .type = (enum rte_flow_action_type)
4762 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4765 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
4766 sizeof(*ext_actions) * (actions_n - encap_idx));
4772 * Check the match action from the action list.
4774 * @param[in] actions
4775 * Pointer to the list of actions.
4777 * Flow rule attributes.
4779 * The action to be check if exist.
4780 * @param[out] match_action_pos
4781 * Pointer to the position of the matched action if exists, otherwise is -1.
4782 * @param[out] qrss_action_pos
4783 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
4786 * > 0 the total number of actions.
4787 * 0 if not found match action in action list.
4790 flow_check_match_action(const struct rte_flow_action actions[],
4791 const struct rte_flow_attr *attr,
4792 enum rte_flow_action_type action,
4793 int *match_action_pos, int *qrss_action_pos)
4795 const struct rte_flow_action_sample *sample;
4802 *match_action_pos = -1;
4803 *qrss_action_pos = -1;
4804 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4805 if (actions->type == action) {
4807 *match_action_pos = actions_n;
4809 if (actions->type == RTE_FLOW_ACTION_TYPE_QUEUE ||
4810 actions->type == RTE_FLOW_ACTION_TYPE_RSS)
4811 *qrss_action_pos = actions_n;
4812 if (actions->type == RTE_FLOW_ACTION_TYPE_JUMP)
4814 if (actions->type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
4815 sample = actions->conf;
4816 ratio = sample->ratio;
4817 sub_type = ((const struct rte_flow_action *)
4818 (sample->actions))->type;
4822 if (flag && action == RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) {
4824 /* JUMP Action not support for Mirroring;
4825 * Mirroring support multi-destination;
4827 if (!jump_flag && sub_type != RTE_FLOW_ACTION_TYPE_END)
4831 /* Count RTE_FLOW_ACTION_TYPE_END. */
4832 return flag ? actions_n + 1 : 0;
4835 #define SAMPLE_SUFFIX_ITEM 2
4838 * Split the sample flow.
4840 * As sample flow will split to two sub flow, sample flow with
4841 * sample action, the other actions will move to new suffix flow.
4843 * Also add unique tag id with tag action in the sample flow,
4844 * the same tag id will be as match in the suffix flow.
4847 * Pointer to Ethernet device.
4849 * FDB egress flow flag.
4850 * @param[out] sfx_items
4851 * Suffix flow match items (list terminated by the END pattern item).
4852 * @param[in] actions
4853 * Associated actions (list terminated by the END action).
4854 * @param[out] actions_sfx
4855 * Suffix flow actions.
4856 * @param[out] actions_pre
4857 * Prefix flow actions.
4858 * @param[in] actions_n
4859 * The total number of actions.
4860 * @param[in] sample_action_pos
4861 * The sample action position.
4862 * @param[in] qrss_action_pos
4863 * The Queue/RSS action position.
4865 * Perform verbose error reporting if not NULL.
4868 * 0 on success, or unique flow_id, a negative errno value
4869 * otherwise and rte_errno is set.
4872 flow_sample_split_prep(struct rte_eth_dev *dev,
4874 struct rte_flow_item sfx_items[],
4875 const struct rte_flow_action actions[],
4876 struct rte_flow_action actions_sfx[],
4877 struct rte_flow_action actions_pre[],
4879 int sample_action_pos,
4880 int qrss_action_pos,
4881 struct rte_flow_error *error)
4883 struct mlx5_rte_flow_action_set_tag *set_tag;
4884 struct mlx5_rte_flow_item_tag *tag_spec;
4885 struct mlx5_rte_flow_item_tag *tag_mask;
4886 uint32_t tag_id = 0;
4890 if (sample_action_pos < 0)
4891 return rte_flow_error_set(error, EINVAL,
4892 RTE_FLOW_ERROR_TYPE_ACTION,
4893 NULL, "invalid position of sample "
4896 /* Prepare the prefix tag action. */
4897 set_tag = (void *)(actions_pre + actions_n + 1);
4898 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
4902 tag_id = flow_qrss_get_id(dev);
4903 set_tag->data = tag_id;
4904 /* Prepare the suffix subflow items. */
4905 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
4906 tag_spec->data = tag_id;
4907 tag_spec->id = set_tag->id;
4908 tag_mask = tag_spec + 1;
4909 tag_mask->data = UINT32_MAX;
4910 sfx_items[0] = (struct rte_flow_item){
4911 .type = (enum rte_flow_item_type)
4912 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4917 sfx_items[1] = (struct rte_flow_item){
4918 .type = (enum rte_flow_item_type)
4919 RTE_FLOW_ITEM_TYPE_END,
4922 /* Prepare the actions for prefix and suffix flow. */
4923 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
4924 index = qrss_action_pos;
4925 /* Put the preceding the Queue/RSS action into prefix flow. */
4927 memcpy(actions_pre, actions,
4928 sizeof(struct rte_flow_action) * index);
4929 /* Put others preceding the sample action into prefix flow. */
4930 if (sample_action_pos > index + 1)
4931 memcpy(actions_pre + index, actions + index + 1,
4932 sizeof(struct rte_flow_action) *
4933 (sample_action_pos - index - 1));
4934 index = sample_action_pos - 1;
4935 /* Put Queue/RSS action into Suffix flow. */
4936 memcpy(actions_sfx, actions + qrss_action_pos,
4937 sizeof(struct rte_flow_action));
4940 index = sample_action_pos;
4942 memcpy(actions_pre, actions,
4943 sizeof(struct rte_flow_action) * index);
4945 /* Add the extra tag action for NIC-RX and E-Switch ingress. */
4947 actions_pre[index++] =
4948 (struct rte_flow_action){
4949 .type = (enum rte_flow_action_type)
4950 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4954 memcpy(actions_pre + index, actions + sample_action_pos,
4955 sizeof(struct rte_flow_action));
4957 actions_pre[index] = (struct rte_flow_action){
4958 .type = (enum rte_flow_action_type)
4959 RTE_FLOW_ACTION_TYPE_END,
4961 /* Put the actions after sample into Suffix flow. */
4962 memcpy(actions_sfx, actions + sample_action_pos + 1,
4963 sizeof(struct rte_flow_action) *
4964 (actions_n - sample_action_pos - 1));
4969 * The splitting for metadata feature.
4971 * - Q/RSS action on NIC Rx should be split in order to pass by
4972 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4973 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4975 * - All the actions on NIC Tx should have a mreg copy action to
4976 * copy reg_a from WQE to reg_c[0].
4979 * Pointer to Ethernet device.
4981 * Parent flow structure pointer.
4982 * @param[in] prefix_layers
4983 * Prefix flow layer flags.
4984 * @param[in] prefix_mark
4985 * Prefix subflow mark flag, may be 0.
4987 * Flow rule attributes.
4989 * Pattern specification (list terminated by the END pattern item).
4990 * @param[in] actions
4991 * Associated actions (list terminated by the END action).
4992 * @param[in] external
4993 * This flow rule is created by request external to PMD.
4994 * @param[in] flow_idx
4995 * This memory pool index to the flow.
4997 * Perform verbose error reporting if not NULL.
4999 * 0 on success, negative value otherwise
5002 flow_create_split_metadata(struct rte_eth_dev *dev,
5003 struct rte_flow *flow,
5004 uint64_t prefix_layers,
5005 uint32_t prefix_mark,
5006 const struct rte_flow_attr *attr,
5007 const struct rte_flow_item items[],
5008 const struct rte_flow_action actions[],
5009 bool external, uint32_t flow_idx,
5010 struct rte_flow_error *error)
5012 struct mlx5_priv *priv = dev->data->dev_private;
5013 struct mlx5_dev_config *config = &priv->config;
5014 const struct rte_flow_action *qrss = NULL;
5015 struct rte_flow_action *ext_actions = NULL;
5016 struct mlx5_flow *dev_flow = NULL;
5017 uint32_t qrss_id = 0;
5024 /* Check whether extensive metadata feature is engaged. */
5025 if (!config->dv_flow_en ||
5026 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5027 !mlx5_flow_ext_mreg_supported(dev))
5028 return flow_create_split_inner(dev, flow, NULL, prefix_layers,
5029 prefix_mark, attr, items,
5030 actions, external, flow_idx,
5032 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5035 /* Exclude hairpin flows from splitting. */
5036 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5037 const struct rte_flow_action_queue *queue;
5040 if (mlx5_rxq_get_type(dev, queue->index) ==
5041 MLX5_RXQ_TYPE_HAIRPIN)
5043 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5044 const struct rte_flow_action_rss *rss;
5047 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5048 MLX5_RXQ_TYPE_HAIRPIN)
5053 /* Check if it is in meter suffix table. */
5054 mtr_sfx = attr->group == (attr->transfer ?
5055 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
5056 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
5058 * Q/RSS action on NIC Rx should be split in order to pass by
5059 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5060 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5062 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5063 sizeof(struct rte_flow_action_set_tag) +
5064 sizeof(struct rte_flow_action_jump);
5065 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5068 return rte_flow_error_set(error, ENOMEM,
5069 RTE_FLOW_ERROR_TYPE_ACTION,
5070 NULL, "no memory to split "
5073 * If we are the suffix flow of meter, tag already exist.
5074 * Set the tag action to void.
5077 ext_actions[qrss - actions].type =
5078 RTE_FLOW_ACTION_TYPE_VOID;
5080 ext_actions[qrss - actions].type =
5081 (enum rte_flow_action_type)
5082 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5084 * Create the new actions list with removed Q/RSS action
5085 * and appended set tag and jump to register copy table
5086 * (RX_CP_TBL). We should preallocate unique tag ID here
5087 * in advance, because it is needed for set tag action.
5089 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5090 qrss, actions_n, error);
5091 if (!mtr_sfx && !qrss_id) {
5095 } else if (attr->egress && !attr->transfer) {
5097 * All the actions on NIC Tx should have a metadata register
5098 * copy action to copy reg_a from WQE to reg_c[meta]
5100 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5101 sizeof(struct mlx5_flow_action_copy_mreg);
5102 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5105 return rte_flow_error_set(error, ENOMEM,
5106 RTE_FLOW_ERROR_TYPE_ACTION,
5107 NULL, "no memory to split "
5109 /* Create the action list appended with copy register. */
5110 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5111 actions_n, error, encap_idx);
5115 /* Add the unmodified original or prefix subflow. */
5116 ret = flow_create_split_inner(dev, flow, &dev_flow, prefix_layers,
5118 items, ext_actions ? ext_actions :
5119 actions, external, flow_idx, error);
5122 MLX5_ASSERT(dev_flow);
5124 const struct rte_flow_attr q_attr = {
5125 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5128 /* Internal PMD action to set register. */
5129 struct mlx5_rte_flow_item_tag q_tag_spec = {
5133 struct rte_flow_item q_items[] = {
5135 .type = (enum rte_flow_item_type)
5136 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5137 .spec = &q_tag_spec,
5142 .type = RTE_FLOW_ITEM_TYPE_END,
5145 struct rte_flow_action q_actions[] = {
5151 .type = RTE_FLOW_ACTION_TYPE_END,
5154 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5157 * Configure the tag item only if there is no meter subflow.
5158 * Since tag is already marked in the meter suffix subflow
5159 * we can just use the meter suffix items as is.
5162 /* Not meter subflow. */
5163 MLX5_ASSERT(!mtr_sfx);
5165 * Put unique id in prefix flow due to it is destroyed
5166 * after suffix flow and id will be freed after there
5167 * is no actual flows with this id and identifier
5168 * reallocation becomes possible (for example, for
5169 * other flows in other threads).
5171 dev_flow->handle->split_flow_id = qrss_id;
5172 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5176 q_tag_spec.id = ret;
5179 /* Add suffix subflow to execute Q/RSS. */
5180 ret = flow_create_split_inner(dev, flow, &dev_flow, layers, 0,
5181 &q_attr, mtr_sfx ? items :
5183 external, flow_idx, error);
5186 /* qrss ID should be freed if failed. */
5188 MLX5_ASSERT(dev_flow);
5193 * We do not destroy the partially created sub_flows in case of error.
5194 * These ones are included into parent flow list and will be destroyed
5195 * by flow_drv_destroy.
5197 flow_qrss_free_id(dev, qrss_id);
5198 mlx5_free(ext_actions);
5203 * The splitting for meter feature.
5205 * - The meter flow will be split to two flows as prefix and
5206 * suffix flow. The packets make sense only it pass the prefix
5209 * - Reg_C_5 is used for the packet to match betweend prefix and
5213 * Pointer to Ethernet device.
5215 * Parent flow structure pointer.
5216 * @param[in] prefix_layers
5217 * Prefix subflow layers, may be 0.
5218 * @param[in] prefix_mark
5219 * Prefix subflow mark flag, may be 0.
5221 * Flow rule attributes.
5223 * Pattern specification (list terminated by the END pattern item).
5224 * @param[in] actions
5225 * Associated actions (list terminated by the END action).
5226 * @param[in] external
5227 * This flow rule is created by request external to PMD.
5228 * @param[in] flow_idx
5229 * This memory pool index to the flow.
5231 * Perform verbose error reporting if not NULL.
5233 * 0 on success, negative value otherwise
5236 flow_create_split_meter(struct rte_eth_dev *dev,
5237 struct rte_flow *flow,
5238 uint64_t prefix_layers,
5239 uint32_t prefix_mark,
5240 const struct rte_flow_attr *attr,
5241 const struct rte_flow_item items[],
5242 const struct rte_flow_action actions[],
5243 bool external, uint32_t flow_idx,
5244 struct rte_flow_error *error)
5246 struct mlx5_priv *priv = dev->data->dev_private;
5247 struct rte_flow_action *sfx_actions = NULL;
5248 struct rte_flow_action *pre_actions = NULL;
5249 struct rte_flow_item *sfx_items = NULL;
5250 struct mlx5_flow *dev_flow = NULL;
5251 struct rte_flow_attr sfx_attr = *attr;
5253 uint32_t mtr_tag_id = 0;
5260 actions_n = flow_check_meter_action(actions, &mtr);
5262 /* The five prefix actions: meter, decap, encap, tag, end. */
5263 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
5264 sizeof(struct mlx5_rte_flow_action_set_tag);
5265 /* tag, vlan, port id, end. */
5266 #define METER_SUFFIX_ITEM 4
5267 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5268 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5269 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5272 return rte_flow_error_set(error, ENOMEM,
5273 RTE_FLOW_ERROR_TYPE_ACTION,
5274 NULL, "no memory to split "
5276 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5278 pre_actions = sfx_actions + actions_n;
5279 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
5280 actions, sfx_actions,
5286 /* Add the prefix subflow. */
5287 ret = flow_create_split_inner(dev, flow, &dev_flow,
5290 pre_actions, external,
5296 dev_flow->handle->split_flow_id = mtr_tag_id;
5297 /* Setting the sfx group atrr. */
5298 sfx_attr.group = sfx_attr.transfer ?
5299 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
5300 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
5302 /* Add the prefix subflow. */
5303 ret = flow_create_split_metadata(dev, flow, dev_flow ?
5304 flow_get_prefix_layer_flags(dev_flow) :
5305 prefix_layers, dev_flow ?
5306 dev_flow->handle->mark : prefix_mark,
5307 &sfx_attr, sfx_items ?
5309 sfx_actions ? sfx_actions : actions,
5310 external, flow_idx, error);
5313 mlx5_free(sfx_actions);
5318 * The splitting for sample feature.
5320 * Once Sample action is detected in the action list, the flow actions should
5321 * be split into prefix sub flow and suffix sub flow.
5323 * The original items remain in the prefix sub flow, all actions preceding the
5324 * sample action and the sample action itself will be copied to the prefix
5325 * sub flow, the actions following the sample action will be copied to the
5326 * suffix sub flow, Queue action always be located in the suffix sub flow.
5328 * In order to make the packet from prefix sub flow matches with suffix sub
5329 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5330 * flow uses tag item with the unique flow id.
5333 * Pointer to Ethernet device.
5335 * Parent flow structure pointer.
5337 * Flow rule attributes.
5339 * Pattern specification (list terminated by the END pattern item).
5340 * @param[in] actions
5341 * Associated actions (list terminated by the END action).
5342 * @param[in] external
5343 * This flow rule is created by request external to PMD.
5344 * @param[in] flow_idx
5345 * This memory pool index to the flow.
5347 * Perform verbose error reporting if not NULL.
5349 * 0 on success, negative value otherwise
5352 flow_create_split_sample(struct rte_eth_dev *dev,
5353 struct rte_flow *flow,
5354 const struct rte_flow_attr *attr,
5355 const struct rte_flow_item items[],
5356 const struct rte_flow_action actions[],
5357 bool external, uint32_t flow_idx,
5358 struct rte_flow_error *error)
5360 struct mlx5_priv *priv = dev->data->dev_private;
5361 struct rte_flow_action *sfx_actions = NULL;
5362 struct rte_flow_action *pre_actions = NULL;
5363 struct rte_flow_item *sfx_items = NULL;
5364 struct mlx5_flow *dev_flow = NULL;
5365 struct rte_flow_attr sfx_attr = *attr;
5366 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5367 struct mlx5_flow_dv_sample_resource *sample_res;
5368 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
5369 struct mlx5_flow_tbl_resource *sfx_tbl;
5370 union mlx5_flow_tbl_key sfx_table_key;
5374 uint32_t fdb_tx = 0;
5377 int sample_action_pos;
5378 int qrss_action_pos;
5381 if (priv->sampler_en)
5382 actions_n = flow_check_match_action(actions, attr,
5383 RTE_FLOW_ACTION_TYPE_SAMPLE,
5384 &sample_action_pos, &qrss_action_pos);
5386 /* The prefix actions must includes sample, tag, end. */
5387 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
5388 + sizeof(struct mlx5_rte_flow_action_set_tag);
5389 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
5390 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5391 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
5392 item_size), 0, SOCKET_ID_ANY);
5394 return rte_flow_error_set(error, ENOMEM,
5395 RTE_FLOW_ERROR_TYPE_ACTION,
5396 NULL, "no memory to split "
5398 /* The representor_id is -1 for uplink. */
5399 fdb_tx = (attr->transfer && priv->representor_id != -1);
5401 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
5403 pre_actions = sfx_actions + actions_n;
5404 tag_id = flow_sample_split_prep(dev, fdb_tx, sfx_items,
5405 actions, sfx_actions,
5406 pre_actions, actions_n,
5408 qrss_action_pos, error);
5409 if (tag_id < 0 || (!fdb_tx && !tag_id)) {
5413 /* Add the prefix subflow. */
5414 ret = flow_create_split_inner(dev, flow, &dev_flow, 0, 0, attr,
5415 items, pre_actions, external,
5421 dev_flow->handle->split_flow_id = tag_id;
5422 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5423 /* Set the sfx group attr. */
5424 sample_res = (struct mlx5_flow_dv_sample_resource *)
5425 dev_flow->dv.sample_res;
5426 sfx_tbl = (struct mlx5_flow_tbl_resource *)
5427 sample_res->normal_path_tbl;
5428 sfx_tbl_data = container_of(sfx_tbl,
5429 struct mlx5_flow_tbl_data_entry, tbl);
5430 sfx_table_key.v64 = sfx_tbl_data->entry.key;
5431 sfx_attr.group = sfx_attr.transfer ?
5432 (sfx_table_key.table_id - 1) :
5433 sfx_table_key.table_id;
5436 /* Add the suffix subflow. */
5437 ret = flow_create_split_meter(dev, flow, dev_flow ?
5438 flow_get_prefix_layer_flags(dev_flow) : 0,
5439 dev_flow ? dev_flow->handle->mark : 0,
5440 &sfx_attr, sfx_items ? sfx_items : items,
5441 sfx_actions ? sfx_actions : actions,
5442 external, flow_idx, error);
5445 mlx5_free(sfx_actions);
5450 * Split the flow to subflow set. The splitters might be linked
5451 * in the chain, like this:
5452 * flow_create_split_outer() calls:
5453 * flow_create_split_meter() calls:
5454 * flow_create_split_metadata(meter_subflow_0) 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)
5458 * flow_create_split_metadata(meter_subflow_1) calls:
5459 * flow_create_split_inner(metadata_subflow_0)
5460 * flow_create_split_inner(metadata_subflow_1)
5461 * flow_create_split_inner(metadata_subflow_2)
5463 * This provide flexible way to add new levels of flow splitting.
5464 * The all of successfully created subflows are included to the
5465 * parent flow dev_flow list.
5468 * Pointer to Ethernet device.
5470 * Parent flow structure pointer.
5472 * Flow rule attributes.
5474 * Pattern specification (list terminated by the END pattern item).
5475 * @param[in] actions
5476 * Associated actions (list terminated by the END action).
5477 * @param[in] external
5478 * This flow rule is created by request external to PMD.
5479 * @param[in] flow_idx
5480 * This memory pool index to the flow.
5482 * Perform verbose error reporting if not NULL.
5484 * 0 on success, negative value otherwise
5487 flow_create_split_outer(struct rte_eth_dev *dev,
5488 struct rte_flow *flow,
5489 const struct rte_flow_attr *attr,
5490 const struct rte_flow_item items[],
5491 const struct rte_flow_action actions[],
5492 bool external, uint32_t flow_idx,
5493 struct rte_flow_error *error)
5497 ret = flow_create_split_sample(dev, flow, attr, items,
5498 actions, external, flow_idx, error);
5499 MLX5_ASSERT(ret <= 0);
5503 static struct mlx5_flow_tunnel *
5504 flow_tunnel_from_rule(struct rte_eth_dev *dev,
5505 const struct rte_flow_attr *attr,
5506 const struct rte_flow_item items[],
5507 const struct rte_flow_action actions[])
5509 struct mlx5_flow_tunnel *tunnel;
5511 #pragma GCC diagnostic push
5512 #pragma GCC diagnostic ignored "-Wcast-qual"
5513 if (is_flow_tunnel_match_rule(dev, attr, items, actions))
5514 tunnel = (struct mlx5_flow_tunnel *)items[0].spec;
5515 else if (is_flow_tunnel_steer_rule(dev, attr, items, actions))
5516 tunnel = (struct mlx5_flow_tunnel *)actions[0].conf;
5519 #pragma GCC diagnostic pop
5525 * Create a flow and add it to @p list.
5528 * Pointer to Ethernet device.
5530 * Pointer to a TAILQ flow list. If this parameter NULL,
5531 * no list insertion occurred, flow is just created,
5532 * this is caller's responsibility to track the
5535 * Flow rule attributes.
5537 * Pattern specification (list terminated by the END pattern item).
5538 * @param[in] actions
5539 * Associated actions (list terminated by the END action).
5540 * @param[in] external
5541 * This flow rule is created by request external to PMD.
5543 * Perform verbose error reporting if not NULL.
5546 * A flow index on success, 0 otherwise and rte_errno is set.
5549 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
5550 const struct rte_flow_attr *attr,
5551 const struct rte_flow_item items[],
5552 const struct rte_flow_action original_actions[],
5553 bool external, struct rte_flow_error *error)
5555 struct mlx5_priv *priv = dev->data->dev_private;
5556 struct rte_flow *flow = NULL;
5557 struct mlx5_flow *dev_flow;
5558 const struct rte_flow_action_rss *rss;
5559 struct mlx5_translated_shared_action
5560 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5561 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5563 struct mlx5_flow_expand_rss buf;
5564 uint8_t buffer[2048];
5567 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5568 uint8_t buffer[2048];
5571 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5572 uint8_t buffer[2048];
5573 } actions_hairpin_tx;
5575 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
5576 uint8_t buffer[2048];
5578 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
5579 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
5580 priv->rss_desc)[!!priv->flow_idx];
5581 const struct rte_flow_action *p_actions_rx;
5585 uint32_t hairpin_id = 0;
5586 struct rte_flow_attr attr_tx = { .priority = 0 };
5587 struct rte_flow_attr attr_factor = {0};
5588 const struct rte_flow_action *actions;
5589 struct rte_flow_action *translated_actions = NULL;
5590 struct mlx5_flow_tunnel *tunnel;
5591 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
5592 int ret = flow_shared_actions_translate(original_actions,
5595 &translated_actions, error);
5598 MLX5_ASSERT(translated_actions == NULL);
5601 actions = translated_actions ? translated_actions : original_actions;
5602 memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
5603 p_actions_rx = actions;
5604 hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
5605 ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
5606 external, hairpin_flow, error);
5608 goto error_before_hairpin_split;
5609 if (hairpin_flow > 0) {
5610 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
5612 goto error_before_hairpin_split;
5614 flow_hairpin_split(dev, actions, actions_rx.actions,
5615 actions_hairpin_tx.actions, items_tx.items,
5617 p_actions_rx = actions_rx.actions;
5619 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
5622 goto error_before_flow;
5624 flow->drv_type = flow_get_drv_type(dev, &attr_factor);
5625 if (hairpin_id != 0)
5626 flow->hairpin_flow_id = hairpin_id;
5627 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
5628 flow->drv_type < MLX5_FLOW_TYPE_MAX);
5629 memset(rss_desc, 0, sizeof(*rss_desc));
5630 rss = flow_get_rss_action(p_actions_rx);
5633 * The following information is required by
5634 * mlx5_flow_hashfields_adjust() in advance.
5636 rss_desc->level = rss->level;
5637 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
5638 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
5640 flow->dev_handles = 0;
5641 if (rss && rss->types) {
5642 unsigned int graph_root;
5644 graph_root = find_graph_root(items, rss->level);
5645 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
5647 mlx5_support_expansion, graph_root);
5648 MLX5_ASSERT(ret > 0 &&
5649 (unsigned int)ret < sizeof(expand_buffer.buffer));
5652 buf->entry[0].pattern = (void *)(uintptr_t)items;
5654 flow->shared_rss = flow_get_shared_rss_action(shared_actions,
5657 * Record the start index when there is a nested call. All sub-flows
5658 * need to be translated before another calling.
5659 * No need to use ping-pong buffer to save memory here.
5661 if (priv->flow_idx) {
5662 MLX5_ASSERT(!priv->flow_nested_idx);
5663 priv->flow_nested_idx = priv->flow_idx;
5665 for (i = 0; i < buf->entries; ++i) {
5667 * The splitter may create multiple dev_flows,
5668 * depending on configuration. In the simplest
5669 * case it just creates unmodified original flow.
5671 ret = flow_create_split_outer(dev, flow, &attr_factor,
5672 buf->entry[i].pattern,
5673 p_actions_rx, external, idx,
5677 if (is_flow_tunnel_steer_rule(dev, attr,
5678 buf->entry[i].pattern,
5680 ret = flow_tunnel_add_default_miss(dev, flow, attr,
5686 mlx5_free(default_miss_ctx.queue);
5691 /* Create the tx flow. */
5693 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
5694 attr_tx.ingress = 0;
5696 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
5697 actions_hairpin_tx.actions,
5701 dev_flow->flow = flow;
5702 dev_flow->external = 0;
5703 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5704 dev_flow->handle, next);
5705 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
5707 actions_hairpin_tx.actions, error);
5712 * Update the metadata register copy table. If extensive
5713 * metadata feature is enabled and registers are supported
5714 * we might create the extra rte_flow for each unique
5715 * MARK/FLAG action ID.
5717 * The table is updated for ingress Flows only, because
5718 * the egress Flows belong to the different device and
5719 * copy table should be updated in peer NIC Rx domain.
5721 if (attr_factor.ingress &&
5722 (external || attr_factor.group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
5723 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
5728 * If the flow is external (from application) OR device is started, then
5729 * the flow will be applied immediately.
5731 if (external || dev->data->dev_started) {
5732 ret = flow_drv_apply(dev, flow, error);
5737 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
5739 flow_rxq_flags_set(dev, flow);
5740 rte_free(translated_actions);
5741 /* Nested flow creation index recovery. */
5742 priv->flow_idx = priv->flow_nested_idx;
5743 if (priv->flow_nested_idx)
5744 priv->flow_nested_idx = 0;
5745 tunnel = flow_tunnel_from_rule(dev, attr, items, actions);
5748 flow->tunnel_id = tunnel->tunnel_id;
5749 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
5750 mlx5_free(default_miss_ctx.queue);
5755 ret = rte_errno; /* Save rte_errno before cleanup. */
5756 flow_mreg_del_copy_action(dev, flow);
5757 flow_drv_destroy(dev, flow);
5758 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
5759 rte_errno = ret; /* Restore rte_errno. */
5763 mlx5_flow_id_release(priv->sh->flow_id_pool,
5766 priv->flow_idx = priv->flow_nested_idx;
5767 if (priv->flow_nested_idx)
5768 priv->flow_nested_idx = 0;
5769 error_before_hairpin_split:
5770 rte_free(translated_actions);
5775 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
5776 * incoming packets to table 1.
5778 * Other flow rules, requested for group n, will be created in
5779 * e-switch table n+1.
5780 * Jump action to e-switch group n will be created to group n+1.
5782 * Used when working in switchdev mode, to utilise advantages of table 1
5786 * Pointer to Ethernet device.
5789 * Pointer to flow on success, NULL otherwise and rte_errno is set.
5792 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
5794 const struct rte_flow_attr attr = {
5801 const struct rte_flow_item pattern = {
5802 .type = RTE_FLOW_ITEM_TYPE_END,
5804 struct rte_flow_action_jump jump = {
5807 const struct rte_flow_action actions[] = {
5809 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5813 .type = RTE_FLOW_ACTION_TYPE_END,
5816 struct mlx5_priv *priv = dev->data->dev_private;
5817 struct rte_flow_error error;
5819 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
5821 actions, false, &error);
5825 * Validate a flow supported by the NIC.
5827 * @see rte_flow_validate()
5831 mlx5_flow_validate(struct rte_eth_dev *dev,
5832 const struct rte_flow_attr *attr,
5833 const struct rte_flow_item items[],
5834 const struct rte_flow_action original_actions[],
5835 struct rte_flow_error *error)
5838 struct mlx5_translated_shared_action
5839 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5840 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5841 const struct rte_flow_action *actions;
5842 struct rte_flow_action *translated_actions = NULL;
5843 int ret = flow_shared_actions_translate(original_actions,
5846 &translated_actions, error);
5850 actions = translated_actions ? translated_actions : original_actions;
5851 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5852 ret = flow_drv_validate(dev, attr, items, actions,
5853 true, hairpin_flow, error);
5854 rte_free(translated_actions);
5861 * @see rte_flow_create()
5865 mlx5_flow_create(struct rte_eth_dev *dev,
5866 const struct rte_flow_attr *attr,
5867 const struct rte_flow_item items[],
5868 const struct rte_flow_action actions[],
5869 struct rte_flow_error *error)
5871 struct mlx5_priv *priv = dev->data->dev_private;
5874 * If the device is not started yet, it is not allowed to created a
5875 * flow from application. PMD default flows and traffic control flows
5878 if (unlikely(!dev->data->dev_started)) {
5879 DRV_LOG(DEBUG, "port %u is not started when "
5880 "inserting a flow", dev->data->port_id);
5881 rte_flow_error_set(error, ENODEV,
5882 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5884 "port not started");
5888 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
5889 attr, items, actions, true, error);
5893 * Destroy a flow in a list.
5896 * Pointer to Ethernet device.
5898 * Pointer to the Indexed flow list. If this parameter NULL,
5899 * there is no flow removal from the list. Be noted that as
5900 * flow is add to the indexed list, memory of the indexed
5901 * list points to maybe changed as flow destroyed.
5902 * @param[in] flow_idx
5903 * Index of flow to destroy.
5906 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
5909 struct mlx5_priv *priv = dev->data->dev_private;
5910 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5911 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5912 [MLX5_IPOOL_RTE_FLOW], flow_idx);
5917 * Update RX queue flags only if port is started, otherwise it is
5920 if (dev->data->dev_started)
5921 flow_rxq_flags_trim(dev, flow);
5922 if (flow->hairpin_flow_id)
5923 mlx5_flow_id_release(priv->sh->flow_id_pool,
5924 flow->hairpin_flow_id);
5925 flow_drv_destroy(dev, flow);
5927 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
5928 flow_idx, flow, next);
5929 flow_mreg_del_copy_action(dev, flow);
5931 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
5932 if (priv_fdir_flow->rix_flow == flow_idx)
5935 if (priv_fdir_flow) {
5936 LIST_REMOVE(priv_fdir_flow, next);
5937 mlx5_free(priv_fdir_flow->fdir);
5938 mlx5_free(priv_fdir_flow);
5941 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5943 struct mlx5_flow_tunnel *tunnel;
5944 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
5946 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
5947 mlx5_flow_tunnel_free(dev, tunnel);
5952 * Destroy all flows.
5955 * Pointer to Ethernet device.
5957 * Pointer to the Indexed flow list.
5959 * If flushing is called avtively.
5962 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
5964 uint32_t num_flushed = 0;
5967 flow_list_destroy(dev, list, *list);
5971 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
5972 dev->data->port_id, num_flushed);
5980 * Pointer to Ethernet device.
5982 * Pointer to the Indexed flow list.
5985 mlx5_flow_stop(struct rte_eth_dev *dev, uint32_t *list)
5987 struct mlx5_priv *priv = dev->data->dev_private;
5988 struct rte_flow *flow = NULL;
5991 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
5993 flow_drv_remove(dev, flow);
5994 flow_mreg_stop_copy_action(dev, flow);
5996 flow_mreg_del_default_copy_action(dev);
5997 flow_rxq_flags_clear(dev);
6004 * Pointer to Ethernet device.
6006 * Pointer to the Indexed flow list.
6009 * 0 on success, a negative errno value otherwise and rte_errno is set.
6012 mlx5_flow_start(struct rte_eth_dev *dev, uint32_t *list)
6014 struct mlx5_priv *priv = dev->data->dev_private;
6015 struct rte_flow *flow = NULL;
6016 struct rte_flow_error error;
6020 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6021 ret = flow_mreg_add_default_copy_action(dev, &error);
6024 /* Apply Flows created by application. */
6025 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
6027 ret = flow_mreg_start_copy_action(dev, flow);
6030 ret = flow_drv_apply(dev, flow, &error);
6033 flow_rxq_flags_set(dev, flow);
6037 ret = rte_errno; /* Save rte_errno before cleanup. */
6038 mlx5_flow_stop(dev, list);
6039 rte_errno = ret; /* Restore rte_errno. */
6044 * Stop all default actions for flows.
6047 * Pointer to Ethernet device.
6050 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6052 flow_mreg_del_default_copy_action(dev);
6053 flow_rxq_flags_clear(dev);
6057 * Start all default actions for flows.
6060 * Pointer to Ethernet device.
6062 * 0 on success, a negative errno value otherwise and rte_errno is set.
6065 mlx5_flow_start_default(struct rte_eth_dev *dev)
6067 struct rte_flow_error error;
6069 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6070 return flow_mreg_add_default_copy_action(dev, &error);
6074 * Allocate intermediate resources for flow creation.
6077 * Pointer to Ethernet device.
6080 mlx5_flow_alloc_intermediate(struct rte_eth_dev *dev)
6082 struct mlx5_priv *priv = dev->data->dev_private;
6084 if (!priv->inter_flows) {
6085 priv->inter_flows = mlx5_malloc(MLX5_MEM_ZERO,
6086 MLX5_NUM_MAX_DEV_FLOWS *
6087 sizeof(struct mlx5_flow) +
6088 (sizeof(struct mlx5_flow_rss_desc) +
6089 sizeof(uint16_t) * UINT16_MAX) * 2, 0,
6091 if (!priv->inter_flows) {
6092 DRV_LOG(ERR, "can't allocate intermediate memory.");
6096 priv->rss_desc = &((struct mlx5_flow *)priv->inter_flows)
6097 [MLX5_NUM_MAX_DEV_FLOWS];
6098 /* Reset the index. */
6100 priv->flow_nested_idx = 0;
6104 * Free intermediate resources for flows.
6107 * Pointer to Ethernet device.
6110 mlx5_flow_free_intermediate(struct rte_eth_dev *dev)
6112 struct mlx5_priv *priv = dev->data->dev_private;
6114 mlx5_free(priv->inter_flows);
6115 priv->inter_flows = NULL;
6119 * Verify the flow list is empty
6122 * Pointer to Ethernet device.
6124 * @return the number of flows not released.
6127 mlx5_flow_verify(struct rte_eth_dev *dev)
6129 struct mlx5_priv *priv = dev->data->dev_private;
6130 struct rte_flow *flow;
6134 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
6136 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6137 dev->data->port_id, (void *)flow);
6144 * Enable default hairpin egress flow.
6147 * Pointer to Ethernet device.
6152 * 0 on success, a negative errno value otherwise and rte_errno is set.
6155 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6158 struct mlx5_priv *priv = dev->data->dev_private;
6159 const struct rte_flow_attr attr = {
6163 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6166 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6167 .queue = UINT32_MAX,
6169 struct rte_flow_item items[] = {
6171 .type = (enum rte_flow_item_type)
6172 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6173 .spec = &queue_spec,
6175 .mask = &queue_mask,
6178 .type = RTE_FLOW_ITEM_TYPE_END,
6181 struct rte_flow_action_jump jump = {
6182 .group = MLX5_HAIRPIN_TX_TABLE,
6184 struct rte_flow_action actions[2];
6186 struct rte_flow_error error;
6188 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6189 actions[0].conf = &jump;
6190 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6191 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6192 &attr, items, actions, false, &error);
6195 "Failed to create ctrl flow: rte_errno(%d),"
6196 " type(%d), message(%s)",
6197 rte_errno, error.type,
6198 error.message ? error.message : " (no stated reason)");
6205 * Enable a control flow configured from the control plane.
6208 * Pointer to Ethernet device.
6210 * An Ethernet flow spec to apply.
6212 * An Ethernet flow mask to apply.
6214 * A VLAN flow spec to apply.
6216 * A VLAN flow mask to apply.
6219 * 0 on success, a negative errno value otherwise and rte_errno is set.
6222 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6223 struct rte_flow_item_eth *eth_spec,
6224 struct rte_flow_item_eth *eth_mask,
6225 struct rte_flow_item_vlan *vlan_spec,
6226 struct rte_flow_item_vlan *vlan_mask)
6228 struct mlx5_priv *priv = dev->data->dev_private;
6229 const struct rte_flow_attr attr = {
6231 .priority = MLX5_FLOW_PRIO_RSVD,
6233 struct rte_flow_item items[] = {
6235 .type = RTE_FLOW_ITEM_TYPE_ETH,
6241 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6242 RTE_FLOW_ITEM_TYPE_END,
6248 .type = RTE_FLOW_ITEM_TYPE_END,
6251 uint16_t queue[priv->reta_idx_n];
6252 struct rte_flow_action_rss action_rss = {
6253 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6255 .types = priv->rss_conf.rss_hf,
6256 .key_len = priv->rss_conf.rss_key_len,
6257 .queue_num = priv->reta_idx_n,
6258 .key = priv->rss_conf.rss_key,
6261 struct rte_flow_action actions[] = {
6263 .type = RTE_FLOW_ACTION_TYPE_RSS,
6264 .conf = &action_rss,
6267 .type = RTE_FLOW_ACTION_TYPE_END,
6271 struct rte_flow_error error;
6274 if (!priv->reta_idx_n || !priv->rxqs_n) {
6277 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6278 action_rss.types = 0;
6279 for (i = 0; i != priv->reta_idx_n; ++i)
6280 queue[i] = (*priv->reta_idx)[i];
6281 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6282 &attr, items, actions, false, &error);
6289 * Enable a flow control configured from the control plane.
6292 * Pointer to Ethernet device.
6294 * An Ethernet flow spec to apply.
6296 * An Ethernet flow mask to apply.
6299 * 0 on success, a negative errno value otherwise and rte_errno is set.
6302 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6303 struct rte_flow_item_eth *eth_spec,
6304 struct rte_flow_item_eth *eth_mask)
6306 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6310 * Create default miss flow rule matching lacp traffic
6313 * Pointer to Ethernet device.
6315 * An Ethernet flow spec to apply.
6318 * 0 on success, a negative errno value otherwise and rte_errno is set.
6321 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6323 struct mlx5_priv *priv = dev->data->dev_private;
6325 * The LACP matching is done by only using ether type since using
6326 * a multicast dst mac causes kernel to give low priority to this flow.
6328 static const struct rte_flow_item_eth lacp_spec = {
6329 .type = RTE_BE16(0x8809),
6331 static const struct rte_flow_item_eth lacp_mask = {
6334 const struct rte_flow_attr attr = {
6337 struct rte_flow_item items[] = {
6339 .type = RTE_FLOW_ITEM_TYPE_ETH,
6344 .type = RTE_FLOW_ITEM_TYPE_END,
6347 struct rte_flow_action actions[] = {
6349 .type = (enum rte_flow_action_type)
6350 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
6353 .type = RTE_FLOW_ACTION_TYPE_END,
6356 struct rte_flow_error error;
6357 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6358 &attr, items, actions, false, &error);
6368 * @see rte_flow_destroy()
6372 mlx5_flow_destroy(struct rte_eth_dev *dev,
6373 struct rte_flow *flow,
6374 struct rte_flow_error *error __rte_unused)
6376 struct mlx5_priv *priv = dev->data->dev_private;
6378 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
6383 * Destroy all flows.
6385 * @see rte_flow_flush()
6389 mlx5_flow_flush(struct rte_eth_dev *dev,
6390 struct rte_flow_error *error __rte_unused)
6392 struct mlx5_priv *priv = dev->data->dev_private;
6394 mlx5_flow_list_flush(dev, &priv->flows, false);
6401 * @see rte_flow_isolate()
6405 mlx5_flow_isolate(struct rte_eth_dev *dev,
6407 struct rte_flow_error *error)
6409 struct mlx5_priv *priv = dev->data->dev_private;
6411 if (dev->data->dev_started) {
6412 rte_flow_error_set(error, EBUSY,
6413 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6415 "port must be stopped first");
6418 priv->isolated = !!enable;
6420 dev->dev_ops = &mlx5_os_dev_ops_isolate;
6422 dev->dev_ops = &mlx5_os_dev_ops;
6424 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
6425 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
6433 * @see rte_flow_query()
6437 flow_drv_query(struct rte_eth_dev *dev,
6439 const struct rte_flow_action *actions,
6441 struct rte_flow_error *error)
6443 struct mlx5_priv *priv = dev->data->dev_private;
6444 const struct mlx5_flow_driver_ops *fops;
6445 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
6446 [MLX5_IPOOL_RTE_FLOW],
6448 enum mlx5_flow_drv_type ftype;
6451 return rte_flow_error_set(error, ENOENT,
6452 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6454 "invalid flow handle");
6456 ftype = flow->drv_type;
6457 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
6458 fops = flow_get_drv_ops(ftype);
6460 return fops->query(dev, flow, actions, data, error);
6466 * @see rte_flow_query()
6470 mlx5_flow_query(struct rte_eth_dev *dev,
6471 struct rte_flow *flow,
6472 const struct rte_flow_action *actions,
6474 struct rte_flow_error *error)
6478 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
6486 * Convert a flow director filter to a generic flow.
6489 * Pointer to Ethernet device.
6490 * @param fdir_filter
6491 * Flow director filter to add.
6493 * Generic flow parameters structure.
6496 * 0 on success, a negative errno value otherwise and rte_errno is set.
6499 flow_fdir_filter_convert(struct rte_eth_dev *dev,
6500 const struct rte_eth_fdir_filter *fdir_filter,
6501 struct mlx5_fdir *attributes)
6503 struct mlx5_priv *priv = dev->data->dev_private;
6504 const struct rte_eth_fdir_input *input = &fdir_filter->input;
6505 const struct rte_eth_fdir_masks *mask =
6506 &dev->data->dev_conf.fdir_conf.mask;
6508 /* Validate queue number. */
6509 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
6510 DRV_LOG(ERR, "port %u invalid queue number %d",
6511 dev->data->port_id, fdir_filter->action.rx_queue);
6515 attributes->attr.ingress = 1;
6516 attributes->items[0] = (struct rte_flow_item) {
6517 .type = RTE_FLOW_ITEM_TYPE_ETH,
6518 .spec = &attributes->l2,
6519 .mask = &attributes->l2_mask,
6521 switch (fdir_filter->action.behavior) {
6522 case RTE_ETH_FDIR_ACCEPT:
6523 attributes->actions[0] = (struct rte_flow_action){
6524 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
6525 .conf = &attributes->queue,
6528 case RTE_ETH_FDIR_REJECT:
6529 attributes->actions[0] = (struct rte_flow_action){
6530 .type = RTE_FLOW_ACTION_TYPE_DROP,
6534 DRV_LOG(ERR, "port %u invalid behavior %d",
6536 fdir_filter->action.behavior);
6537 rte_errno = ENOTSUP;
6540 attributes->queue.index = fdir_filter->action.rx_queue;
6542 switch (fdir_filter->input.flow_type) {
6543 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
6544 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
6545 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
6546 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
6547 .src_addr = input->flow.ip4_flow.src_ip,
6548 .dst_addr = input->flow.ip4_flow.dst_ip,
6549 .time_to_live = input->flow.ip4_flow.ttl,
6550 .type_of_service = input->flow.ip4_flow.tos,
6552 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
6553 .src_addr = mask->ipv4_mask.src_ip,
6554 .dst_addr = mask->ipv4_mask.dst_ip,
6555 .time_to_live = mask->ipv4_mask.ttl,
6556 .type_of_service = mask->ipv4_mask.tos,
6557 .next_proto_id = mask->ipv4_mask.proto,
6559 attributes->items[1] = (struct rte_flow_item){
6560 .type = RTE_FLOW_ITEM_TYPE_IPV4,
6561 .spec = &attributes->l3,
6562 .mask = &attributes->l3_mask,
6565 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
6566 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
6567 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
6568 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
6569 .hop_limits = input->flow.ipv6_flow.hop_limits,
6570 .proto = input->flow.ipv6_flow.proto,
6573 memcpy(attributes->l3.ipv6.hdr.src_addr,
6574 input->flow.ipv6_flow.src_ip,
6575 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
6576 memcpy(attributes->l3.ipv6.hdr.dst_addr,
6577 input->flow.ipv6_flow.dst_ip,
6578 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
6579 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
6580 mask->ipv6_mask.src_ip,
6581 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
6582 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
6583 mask->ipv6_mask.dst_ip,
6584 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
6585 attributes->items[1] = (struct rte_flow_item){
6586 .type = RTE_FLOW_ITEM_TYPE_IPV6,
6587 .spec = &attributes->l3,
6588 .mask = &attributes->l3_mask,
6592 DRV_LOG(ERR, "port %u invalid flow type%d",
6593 dev->data->port_id, fdir_filter->input.flow_type);
6594 rte_errno = ENOTSUP;
6598 switch (fdir_filter->input.flow_type) {
6599 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
6600 attributes->l4.udp.hdr = (struct rte_udp_hdr){
6601 .src_port = input->flow.udp4_flow.src_port,
6602 .dst_port = input->flow.udp4_flow.dst_port,
6604 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
6605 .src_port = mask->src_port_mask,
6606 .dst_port = mask->dst_port_mask,
6608 attributes->items[2] = (struct rte_flow_item){
6609 .type = RTE_FLOW_ITEM_TYPE_UDP,
6610 .spec = &attributes->l4,
6611 .mask = &attributes->l4_mask,
6614 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
6615 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
6616 .src_port = input->flow.tcp4_flow.src_port,
6617 .dst_port = input->flow.tcp4_flow.dst_port,
6619 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
6620 .src_port = mask->src_port_mask,
6621 .dst_port = mask->dst_port_mask,
6623 attributes->items[2] = (struct rte_flow_item){
6624 .type = RTE_FLOW_ITEM_TYPE_TCP,
6625 .spec = &attributes->l4,
6626 .mask = &attributes->l4_mask,
6629 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
6630 attributes->l4.udp.hdr = (struct rte_udp_hdr){
6631 .src_port = input->flow.udp6_flow.src_port,
6632 .dst_port = input->flow.udp6_flow.dst_port,
6634 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
6635 .src_port = mask->src_port_mask,
6636 .dst_port = mask->dst_port_mask,
6638 attributes->items[2] = (struct rte_flow_item){
6639 .type = RTE_FLOW_ITEM_TYPE_UDP,
6640 .spec = &attributes->l4,
6641 .mask = &attributes->l4_mask,
6644 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
6645 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
6646 .src_port = input->flow.tcp6_flow.src_port,
6647 .dst_port = input->flow.tcp6_flow.dst_port,
6649 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
6650 .src_port = mask->src_port_mask,
6651 .dst_port = mask->dst_port_mask,
6653 attributes->items[2] = (struct rte_flow_item){
6654 .type = RTE_FLOW_ITEM_TYPE_TCP,
6655 .spec = &attributes->l4,
6656 .mask = &attributes->l4_mask,
6659 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
6660 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
6663 DRV_LOG(ERR, "port %u invalid flow type%d",
6664 dev->data->port_id, fdir_filter->input.flow_type);
6665 rte_errno = ENOTSUP;
6671 #define FLOW_FDIR_CMP(f1, f2, fld) \
6672 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
6675 * Compare two FDIR flows. If items and actions are identical, the two flows are
6679 * Pointer to Ethernet device.
6681 * FDIR flow to compare.
6683 * FDIR flow to compare.
6686 * Zero on match, 1 otherwise.
6689 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
6691 if (FLOW_FDIR_CMP(f1, f2, attr) ||
6692 FLOW_FDIR_CMP(f1, f2, l2) ||
6693 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
6694 FLOW_FDIR_CMP(f1, f2, l3) ||
6695 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
6696 FLOW_FDIR_CMP(f1, f2, l4) ||
6697 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
6698 FLOW_FDIR_CMP(f1, f2, actions[0].type))
6700 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
6701 FLOW_FDIR_CMP(f1, f2, queue))
6707 * Search device flow list to find out a matched FDIR flow.
6710 * Pointer to Ethernet device.
6712 * FDIR flow to lookup.
6715 * Index of flow if found, 0 otherwise.
6718 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
6720 struct mlx5_priv *priv = dev->data->dev_private;
6721 uint32_t flow_idx = 0;
6722 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6724 MLX5_ASSERT(fdir_flow);
6725 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
6726 if (!flow_fdir_cmp(priv_fdir_flow->fdir, fdir_flow)) {
6727 DRV_LOG(DEBUG, "port %u found FDIR flow %u",
6728 dev->data->port_id, flow_idx);
6729 flow_idx = priv_fdir_flow->rix_flow;
6737 * Add new flow director filter and store it in list.
6740 * Pointer to Ethernet device.
6741 * @param fdir_filter
6742 * Flow director filter to add.
6745 * 0 on success, a negative errno value otherwise and rte_errno is set.
6748 flow_fdir_filter_add(struct rte_eth_dev *dev,
6749 const struct rte_eth_fdir_filter *fdir_filter)
6751 struct mlx5_priv *priv = dev->data->dev_private;
6752 struct mlx5_fdir *fdir_flow;
6753 struct rte_flow *flow;
6754 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6758 fdir_flow = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*fdir_flow), 0,
6764 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
6767 flow_idx = flow_fdir_filter_lookup(dev, fdir_flow);
6772 priv_fdir_flow = mlx5_malloc(MLX5_MEM_ZERO,
6773 sizeof(struct mlx5_fdir_flow),
6775 if (!priv_fdir_flow) {
6779 flow_idx = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
6780 fdir_flow->items, fdir_flow->actions, true,
6782 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
6786 priv_fdir_flow->fdir = fdir_flow;
6787 priv_fdir_flow->rix_flow = flow_idx;
6788 LIST_INSERT_HEAD(&priv->fdir_flows, priv_fdir_flow, next);
6789 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
6790 dev->data->port_id, (void *)flow);
6793 mlx5_free(priv_fdir_flow);
6794 mlx5_free(fdir_flow);
6799 * Delete specific filter.
6802 * Pointer to Ethernet device.
6803 * @param fdir_filter
6804 * Filter to be deleted.
6807 * 0 on success, a negative errno value otherwise and rte_errno is set.
6810 flow_fdir_filter_delete(struct rte_eth_dev *dev,
6811 const struct rte_eth_fdir_filter *fdir_filter)
6813 struct mlx5_priv *priv = dev->data->dev_private;
6815 struct mlx5_fdir fdir_flow = {
6818 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6821 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
6824 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
6825 /* Find the fdir in priv list */
6826 if (!flow_fdir_cmp(priv_fdir_flow->fdir, &fdir_flow))
6829 if (!priv_fdir_flow)
6831 LIST_REMOVE(priv_fdir_flow, next);
6832 flow_idx = priv_fdir_flow->rix_flow;
6833 flow_list_destroy(dev, &priv->flows, flow_idx);
6834 mlx5_free(priv_fdir_flow->fdir);
6835 mlx5_free(priv_fdir_flow);
6836 DRV_LOG(DEBUG, "port %u deleted FDIR flow %u",
6837 dev->data->port_id, flow_idx);
6842 * Update queue for specific filter.
6845 * Pointer to Ethernet device.
6846 * @param fdir_filter
6847 * Filter to be updated.
6850 * 0 on success, a negative errno value otherwise and rte_errno is set.
6853 flow_fdir_filter_update(struct rte_eth_dev *dev,
6854 const struct rte_eth_fdir_filter *fdir_filter)
6858 ret = flow_fdir_filter_delete(dev, fdir_filter);
6861 return flow_fdir_filter_add(dev, fdir_filter);
6865 * Flush all filters.
6868 * Pointer to Ethernet device.
6871 flow_fdir_filter_flush(struct rte_eth_dev *dev)
6873 struct mlx5_priv *priv = dev->data->dev_private;
6874 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6876 while (!LIST_EMPTY(&priv->fdir_flows)) {
6877 priv_fdir_flow = LIST_FIRST(&priv->fdir_flows);
6878 LIST_REMOVE(priv_fdir_flow, next);
6879 flow_list_destroy(dev, &priv->flows, priv_fdir_flow->rix_flow);
6880 mlx5_free(priv_fdir_flow->fdir);
6881 mlx5_free(priv_fdir_flow);
6886 * Get flow director information.
6889 * Pointer to Ethernet device.
6890 * @param[out] fdir_info
6891 * Resulting flow director information.
6894 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
6896 struct rte_eth_fdir_masks *mask =
6897 &dev->data->dev_conf.fdir_conf.mask;
6899 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
6900 fdir_info->guarant_spc = 0;
6901 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
6902 fdir_info->max_flexpayload = 0;
6903 fdir_info->flow_types_mask[0] = 0;
6904 fdir_info->flex_payload_unit = 0;
6905 fdir_info->max_flex_payload_segment_num = 0;
6906 fdir_info->flex_payload_limit = 0;
6907 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
6911 * Deal with flow director operations.
6914 * Pointer to Ethernet device.
6916 * Operation to perform.
6918 * Pointer to operation-specific structure.
6921 * 0 on success, a negative errno value otherwise and rte_errno is set.
6924 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
6927 enum rte_fdir_mode fdir_mode =
6928 dev->data->dev_conf.fdir_conf.mode;
6930 if (filter_op == RTE_ETH_FILTER_NOP)
6932 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
6933 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
6934 DRV_LOG(ERR, "port %u flow director mode %d not supported",
6935 dev->data->port_id, fdir_mode);
6939 switch (filter_op) {
6940 case RTE_ETH_FILTER_ADD:
6941 return flow_fdir_filter_add(dev, arg);
6942 case RTE_ETH_FILTER_UPDATE:
6943 return flow_fdir_filter_update(dev, arg);
6944 case RTE_ETH_FILTER_DELETE:
6945 return flow_fdir_filter_delete(dev, arg);
6946 case RTE_ETH_FILTER_FLUSH:
6947 flow_fdir_filter_flush(dev);
6949 case RTE_ETH_FILTER_INFO:
6950 flow_fdir_info_get(dev, arg);
6953 DRV_LOG(DEBUG, "port %u unknown operation %u",
6954 dev->data->port_id, filter_op);
6962 * Manage filter operations.
6965 * Pointer to Ethernet device structure.
6966 * @param filter_type
6969 * Operation to perform.
6971 * Pointer to operation-specific structure.
6974 * 0 on success, a negative errno value otherwise and rte_errno is set.
6977 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
6978 enum rte_filter_type filter_type,
6979 enum rte_filter_op filter_op,
6982 switch (filter_type) {
6983 case RTE_ETH_FILTER_GENERIC:
6984 if (filter_op != RTE_ETH_FILTER_GET) {
6988 *(const void **)arg = &mlx5_flow_ops;
6990 case RTE_ETH_FILTER_FDIR:
6991 return flow_fdir_ctrl_func(dev, filter_op, arg);
6993 DRV_LOG(ERR, "port %u filter type (%d) not supported",
6994 dev->data->port_id, filter_type);
6995 rte_errno = ENOTSUP;
7002 * Create the needed meter and suffix tables.
7005 * Pointer to Ethernet device.
7007 * Pointer to the flow meter.
7010 * Pointer to table set on success, NULL otherwise.
7012 struct mlx5_meter_domains_infos *
7013 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7014 const struct mlx5_flow_meter *fm)
7016 const struct mlx5_flow_driver_ops *fops;
7018 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7019 return fops->create_mtr_tbls(dev, fm);
7023 * Destroy the meter table set.
7026 * Pointer to Ethernet device.
7028 * Pointer to the meter table set.
7034 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7035 struct mlx5_meter_domains_infos *tbls)
7037 const struct mlx5_flow_driver_ops *fops;
7039 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7040 return fops->destroy_mtr_tbls(dev, tbls);
7044 * Create policer rules.
7047 * Pointer to Ethernet device.
7049 * Pointer to flow meter structure.
7051 * Pointer to flow attributes.
7054 * 0 on success, -1 otherwise.
7057 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
7058 struct mlx5_flow_meter *fm,
7059 const struct rte_flow_attr *attr)
7061 const struct mlx5_flow_driver_ops *fops;
7063 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7064 return fops->create_policer_rules(dev, fm, attr);
7068 * Destroy policer rules.
7071 * Pointer to flow meter structure.
7073 * Pointer to flow attributes.
7076 * 0 on success, -1 otherwise.
7079 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
7080 struct mlx5_flow_meter *fm,
7081 const struct rte_flow_attr *attr)
7083 const struct mlx5_flow_driver_ops *fops;
7085 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7086 return fops->destroy_policer_rules(dev, fm, attr);
7090 * Allocate a counter.
7093 * Pointer to Ethernet device structure.
7096 * Index to allocated counter on success, 0 otherwise.
7099 mlx5_counter_alloc(struct rte_eth_dev *dev)
7101 const struct mlx5_flow_driver_ops *fops;
7102 struct rte_flow_attr attr = { .transfer = 0 };
7104 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7105 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7106 return fops->counter_alloc(dev);
7109 "port %u counter allocate is not supported.",
7110 dev->data->port_id);
7118 * Pointer to Ethernet device structure.
7120 * Index to counter to be free.
7123 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7125 const struct mlx5_flow_driver_ops *fops;
7126 struct rte_flow_attr attr = { .transfer = 0 };
7128 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7129 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7130 fops->counter_free(dev, cnt);
7134 "port %u counter free is not supported.",
7135 dev->data->port_id);
7139 * Query counter statistics.
7142 * Pointer to Ethernet device structure.
7144 * Index to counter to query.
7146 * Set to clear counter statistics.
7148 * The counter hits packets number to save.
7150 * The counter hits bytes number to save.
7153 * 0 on success, a negative errno value otherwise.
7156 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7157 bool clear, uint64_t *pkts, uint64_t *bytes)
7159 const struct mlx5_flow_driver_ops *fops;
7160 struct rte_flow_attr attr = { .transfer = 0 };
7162 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7163 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7164 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7167 "port %u counter query is not supported.",
7168 dev->data->port_id);
7173 * Allocate a new memory for the counter values wrapped by all the needed
7177 * Pointer to mlx5_dev_ctx_shared object.
7180 * 0 on success, a negative errno value otherwise.
7183 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7185 struct mlx5_devx_mkey_attr mkey_attr;
7186 struct mlx5_counter_stats_mem_mng *mem_mng;
7187 volatile struct flow_counter_stats *raw_data;
7188 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7189 int size = (sizeof(struct flow_counter_stats) *
7190 MLX5_COUNTERS_PER_POOL +
7191 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7192 sizeof(struct mlx5_counter_stats_mem_mng);
7193 size_t pgsize = rte_mem_page_size();
7197 if (pgsize == (size_t)-1) {
7198 DRV_LOG(ERR, "Failed to get mem page size");
7202 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7207 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7208 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7209 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
7210 IBV_ACCESS_LOCAL_WRITE);
7211 if (!mem_mng->umem) {
7216 mkey_attr.addr = (uintptr_t)mem;
7217 mkey_attr.size = size;
7218 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7219 mkey_attr.pd = sh->pdn;
7220 mkey_attr.log_entity_size = 0;
7221 mkey_attr.pg_access = 0;
7222 mkey_attr.klm_array = NULL;
7223 mkey_attr.klm_num = 0;
7224 mkey_attr.relaxed_ordering = sh->cmng.relaxed_ordering;
7225 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7227 mlx5_glue->devx_umem_dereg(mem_mng->umem);
7232 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7233 raw_data = (volatile struct flow_counter_stats *)mem;
7234 for (i = 0; i < raws_n; ++i) {
7235 mem_mng->raws[i].mem_mng = mem_mng;
7236 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7238 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7239 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7240 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7242 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7243 sh->cmng.mem_mng = mem_mng;
7248 * Set the statistic memory to the new counter pool.
7251 * Pointer to mlx5_dev_ctx_shared object.
7253 * Pointer to the pool to set the statistic memory.
7256 * 0 on success, a negative errno value otherwise.
7259 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7260 struct mlx5_flow_counter_pool *pool)
7262 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7263 /* Resize statistic memory once used out. */
7264 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7265 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7266 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7269 rte_spinlock_lock(&pool->sl);
7270 pool->raw = cmng->mem_mng->raws + pool->index %
7271 MLX5_CNT_CONTAINER_RESIZE;
7272 rte_spinlock_unlock(&pool->sl);
7273 pool->raw_hw = NULL;
7277 #define MLX5_POOL_QUERY_FREQ_US 1000000
7280 * Set the periodic procedure for triggering asynchronous batch queries for all
7281 * the counter pools.
7284 * Pointer to mlx5_dev_ctx_shared object.
7287 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7289 uint32_t pools_n, us;
7291 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7292 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7293 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7294 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7295 sh->cmng.query_thread_on = 0;
7296 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7298 sh->cmng.query_thread_on = 1;
7303 * The periodic procedure for triggering asynchronous batch queries for all the
7304 * counter pools. This function is probably called by the host thread.
7307 * The parameter for the alarm process.
7310 mlx5_flow_query_alarm(void *arg)
7312 struct mlx5_dev_ctx_shared *sh = arg;
7314 uint16_t pool_index = sh->cmng.pool_index;
7315 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7316 struct mlx5_flow_counter_pool *pool;
7319 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7321 rte_spinlock_lock(&cmng->pool_update_sl);
7322 pool = cmng->pools[pool_index];
7323 n_valid = cmng->n_valid;
7324 rte_spinlock_unlock(&cmng->pool_update_sl);
7325 /* Set the statistic memory to the new created pool. */
7326 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7329 /* There is a pool query in progress. */
7332 LIST_FIRST(&sh->cmng.free_stat_raws);
7334 /* No free counter statistics raw memory. */
7337 * Identify the counters released between query trigger and query
7338 * handle more efficiently. The counter released in this gap period
7339 * should wait for a new round of query as the new arrived packets
7340 * will not be taken into account.
7343 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7344 MLX5_COUNTERS_PER_POOL,
7346 pool->raw_hw->mem_mng->dm->id,
7350 (uint64_t)(uintptr_t)pool);
7352 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7353 " %d", pool->min_dcs->id);
7354 pool->raw_hw = NULL;
7357 LIST_REMOVE(pool->raw_hw, next);
7358 sh->cmng.pending_queries++;
7360 if (pool_index >= n_valid)
7363 sh->cmng.pool_index = pool_index;
7364 mlx5_set_query_alarm(sh);
7368 * Check and callback event for new aged flow in the counter pool
7371 * Pointer to mlx5_dev_ctx_shared object.
7373 * Pointer to Current counter pool.
7376 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7377 struct mlx5_flow_counter_pool *pool)
7379 struct mlx5_priv *priv;
7380 struct mlx5_flow_counter *cnt;
7381 struct mlx5_age_info *age_info;
7382 struct mlx5_age_param *age_param;
7383 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7384 struct mlx5_counter_stats_raw *prev = pool->raw;
7385 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7386 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7387 uint16_t expected = AGE_CANDIDATE;
7390 pool->time_of_last_age_check = curr_time;
7391 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7392 cnt = MLX5_POOL_GET_CNT(pool, i);
7393 age_param = MLX5_CNT_TO_AGE(cnt);
7394 if (__atomic_load_n(&age_param->state,
7395 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7397 if (cur->data[i].hits != prev->data[i].hits) {
7398 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7402 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7404 __ATOMIC_RELAXED) <= age_param->timeout)
7407 * Hold the lock first, or if between the
7408 * state AGE_TMOUT and tailq operation the
7409 * release happened, the release procedure
7410 * may delete a non-existent tailq node.
7412 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7413 age_info = GET_PORT_AGE_INFO(priv);
7414 rte_spinlock_lock(&age_info->aged_sl);
7415 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7418 __ATOMIC_RELAXED)) {
7419 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7420 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7422 rte_spinlock_unlock(&age_info->aged_sl);
7424 for (i = 0; i < sh->max_port; i++) {
7425 age_info = &sh->port[i].age_info;
7426 if (!MLX5_AGE_GET(age_info, MLX5_AGE_EVENT_NEW))
7428 if (MLX5_AGE_GET(age_info, MLX5_AGE_TRIGGER))
7429 rte_eth_dev_callback_process
7430 (&rte_eth_devices[sh->port[i].devx_ih_port_id],
7431 RTE_ETH_EVENT_FLOW_AGED, NULL);
7432 age_info->flags = 0;
7437 * Handler for the HW respond about ready values from an asynchronous batch
7438 * query. This function is probably called by the host thread.
7441 * The pointer to the shared device context.
7442 * @param[in] async_id
7443 * The Devx async ID.
7445 * The status of the completion.
7448 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7449 uint64_t async_id, int status)
7451 struct mlx5_flow_counter_pool *pool =
7452 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7453 struct mlx5_counter_stats_raw *raw_to_free;
7454 uint8_t query_gen = pool->query_gen ^ 1;
7455 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7456 enum mlx5_counter_type cnt_type =
7457 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7458 MLX5_COUNTER_TYPE_ORIGIN;
7460 if (unlikely(status)) {
7461 raw_to_free = pool->raw_hw;
7463 raw_to_free = pool->raw;
7465 mlx5_flow_aging_check(sh, pool);
7466 rte_spinlock_lock(&pool->sl);
7467 pool->raw = pool->raw_hw;
7468 rte_spinlock_unlock(&pool->sl);
7469 /* Be sure the new raw counters data is updated in memory. */
7471 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7472 rte_spinlock_lock(&cmng->csl[cnt_type]);
7473 TAILQ_CONCAT(&cmng->counters[cnt_type],
7474 &pool->counters[query_gen], next);
7475 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7478 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7479 pool->raw_hw = NULL;
7480 sh->cmng.pending_queries--;
7483 static const struct mlx5_flow_tbl_data_entry *
7484 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
7486 struct mlx5_priv *priv = dev->data->dev_private;
7487 struct mlx5_dev_ctx_shared *sh = priv->sh;
7488 struct mlx5_hlist_entry *he;
7489 union tunnel_offload_mark mbits = { .val = mark };
7490 union mlx5_flow_tbl_key table_key = {
7492 .table_id = tunnel_id_to_flow_tbl(mbits.table_id),
7494 .domain = !!mbits.transfer,
7498 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64);
7500 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
7504 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
7505 const struct mlx5_flow_tunnel *tunnel,
7506 uint32_t group, uint32_t *table,
7507 struct rte_flow_error *error)
7509 struct mlx5_hlist_entry *he;
7510 struct tunnel_tbl_entry *tte;
7511 union tunnel_tbl_key key = {
7512 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
7515 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7516 struct mlx5_hlist *group_hash;
7518 group_hash = tunnel ? tunnel->groups : thub->groups;
7519 he = mlx5_hlist_lookup(group_hash, key.val);
7522 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
7527 tte->hash.key = key.val;
7528 ret = mlx5_flow_id_get(thub->table_ids, &tte->flow_table);
7533 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
7534 mlx5_hlist_insert(group_hash, &tte->hash);
7536 tte = container_of(he, typeof(*tte), hash);
7538 *table = tte->flow_table;
7539 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
7540 dev->data->port_id, key.tunnel_id, group, *table);
7544 return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7545 NULL, "tunnel group index not supported");
7549 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7550 struct flow_grp_info grp_info, struct rte_flow_error *error)
7552 if (grp_info.transfer && grp_info.external && grp_info.fdb_def_rule) {
7553 if (group == UINT32_MAX)
7554 return rte_flow_error_set
7556 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7558 "group index not supported");
7563 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7568 * Translate the rte_flow group index to HW table value.
7570 * If tunnel offload is disabled, all group ids converted to flow table
7571 * id using the standard method.
7572 * If tunnel offload is enabled, group id can be converted using the
7573 * standard or tunnel conversion method. Group conversion method
7574 * selection depends on flags in `grp_info` parameter:
7575 * - Internal (grp_info.external == 0) groups conversion uses the
7577 * - Group ids in JUMP action converted with the tunnel conversion.
7578 * - Group id in rule attribute conversion depends on a rule type and
7580 * ** non zero group attributes converted with the tunnel method
7581 * ** zero group attribute in non-tunnel rule is converted using the
7582 * standard method - there's only one root table
7583 * ** zero group attribute in steer tunnel rule is converted with the
7584 * standard method - single root table
7585 * ** zero group attribute in match tunnel rule is a special OvS
7586 * case: that value is used for portability reasons. That group
7587 * id is converted with the tunnel conversion method.
7592 * PMD tunnel offload object
7594 * rte_flow group index value.
7597 * @param[in] grp_info
7598 * flags used for conversion
7600 * Pointer to error structure.
7603 * 0 on success, a negative errno value otherwise and rte_errno is set.
7606 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7607 const struct mlx5_flow_tunnel *tunnel,
7608 uint32_t group, uint32_t *table,
7609 struct flow_grp_info grp_info,
7610 struct rte_flow_error *error)
7613 bool standard_translation;
7615 if (grp_info.external && group < MLX5_MAX_TABLES_EXTERNAL)
7616 group *= MLX5_FLOW_TABLE_FACTOR;
7617 if (is_tunnel_offload_active(dev)) {
7618 standard_translation = !grp_info.external ||
7619 grp_info.std_tbl_fix;
7621 standard_translation = true;
7624 "port %u group=%#x transfer=%d external=%d fdb_def_rule=%d translate=%s",
7625 dev->data->port_id, group, grp_info.transfer,
7626 grp_info.external, grp_info.fdb_def_rule,
7627 standard_translation ? "STANDARD" : "TUNNEL");
7628 if (standard_translation)
7629 ret = flow_group_to_table(dev->data->port_id, group, table,
7632 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7639 * Discover availability of metadata reg_c's.
7641 * Iteratively use test flows to check availability.
7644 * Pointer to the Ethernet device structure.
7647 * 0 on success, a negative errno value otherwise and rte_errno is set.
7650 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7652 struct mlx5_priv *priv = dev->data->dev_private;
7653 struct mlx5_dev_config *config = &priv->config;
7654 enum modify_reg idx;
7657 /* reg_c[0] and reg_c[1] are reserved. */
7658 config->flow_mreg_c[n++] = REG_C_0;
7659 config->flow_mreg_c[n++] = REG_C_1;
7660 /* Discover availability of other reg_c's. */
7661 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7662 struct rte_flow_attr attr = {
7663 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7664 .priority = MLX5_FLOW_PRIO_RSVD,
7667 struct rte_flow_item items[] = {
7669 .type = RTE_FLOW_ITEM_TYPE_END,
7672 struct rte_flow_action actions[] = {
7674 .type = (enum rte_flow_action_type)
7675 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7676 .conf = &(struct mlx5_flow_action_copy_mreg){
7682 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7683 .conf = &(struct rte_flow_action_jump){
7684 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7688 .type = RTE_FLOW_ACTION_TYPE_END,
7692 struct rte_flow *flow;
7693 struct rte_flow_error error;
7695 if (!config->dv_flow_en)
7697 /* Create internal flow, validation skips copy action. */
7698 flow_idx = flow_list_create(dev, NULL, &attr, items,
7699 actions, false, &error);
7700 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
7704 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
7705 config->flow_mreg_c[n++] = idx;
7706 flow_list_destroy(dev, NULL, flow_idx);
7708 for (; n < MLX5_MREG_C_NUM; ++n)
7709 config->flow_mreg_c[n] = REG_NON;
7714 * Dump flow raw hw data to file
7717 * The pointer to Ethernet device.
7719 * A pointer to a file for output.
7721 * Perform verbose error reporting if not NULL. PMDs initialize this
7722 * structure in case of error only.
7724 * 0 on success, a nagative value otherwise.
7727 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
7729 struct rte_flow_error *error __rte_unused)
7731 struct mlx5_priv *priv = dev->data->dev_private;
7732 struct mlx5_dev_ctx_shared *sh = priv->sh;
7734 if (!priv->config.dv_flow_en) {
7735 if (fputs("device dv flow disabled\n", file) <= 0)
7739 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
7740 sh->tx_domain, file);
7744 * Get aged-out flows.
7747 * Pointer to the Ethernet device structure.
7748 * @param[in] context
7749 * The address of an array of pointers to the aged-out flows contexts.
7750 * @param[in] nb_countexts
7751 * The length of context array pointers.
7753 * Perform verbose error reporting if not NULL. Initialized in case of
7757 * how many contexts get in success, otherwise negative errno value.
7758 * if nb_contexts is 0, return the amount of all aged contexts.
7759 * if nb_contexts is not 0 , return the amount of aged flows reported
7760 * in the context array.
7763 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
7764 uint32_t nb_contexts, struct rte_flow_error *error)
7766 const struct mlx5_flow_driver_ops *fops;
7767 struct rte_flow_attr attr = { .transfer = 0 };
7769 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7770 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7771 return fops->get_aged_flows(dev, contexts, nb_contexts,
7775 "port %u get aged flows is not supported.",
7776 dev->data->port_id);
7780 /* Wrapper for driver action_validate op callback */
7782 flow_drv_action_validate(struct rte_eth_dev *dev,
7783 const struct rte_flow_shared_action_conf *conf,
7784 const struct rte_flow_action *action,
7785 const struct mlx5_flow_driver_ops *fops,
7786 struct rte_flow_error *error)
7788 static const char err_msg[] = "shared action validation unsupported";
7790 if (!fops->action_validate) {
7791 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7792 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7796 return fops->action_validate(dev, conf, action, error);
7800 * Destroys the shared action by handle.
7803 * Pointer to Ethernet device structure.
7805 * Handle for the shared action to be destroyed.
7807 * Perform verbose error reporting if not NULL. PMDs initialize this
7808 * structure in case of error only.
7811 * 0 on success, a negative errno value otherwise and rte_errno is set.
7813 * @note: wrapper for driver action_create op callback.
7816 mlx5_shared_action_destroy(struct rte_eth_dev *dev,
7817 struct rte_flow_shared_action *action,
7818 struct rte_flow_error *error)
7820 static const char err_msg[] = "shared action destruction unsupported";
7821 struct rte_flow_attr attr = { .transfer = 0 };
7822 const struct mlx5_flow_driver_ops *fops =
7823 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7825 if (!fops->action_destroy) {
7826 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7827 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7831 return fops->action_destroy(dev, action, error);
7834 /* Wrapper for driver action_destroy op callback */
7836 flow_drv_action_update(struct rte_eth_dev *dev,
7837 struct rte_flow_shared_action *action,
7838 const void *action_conf,
7839 const struct mlx5_flow_driver_ops *fops,
7840 struct rte_flow_error *error)
7842 static const char err_msg[] = "shared action update unsupported";
7844 if (!fops->action_update) {
7845 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7846 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7850 return fops->action_update(dev, action, action_conf, error);
7854 * Create shared action for reuse in multiple flow rules.
7857 * Pointer to Ethernet device structure.
7859 * Action configuration for shared action creation.
7861 * Perform verbose error reporting if not NULL. PMDs initialize this
7862 * structure in case of error only.
7864 * A valid handle in case of success, NULL otherwise and rte_errno is set.
7866 static struct rte_flow_shared_action *
7867 mlx5_shared_action_create(struct rte_eth_dev *dev,
7868 const struct rte_flow_shared_action_conf *conf,
7869 const struct rte_flow_action *action,
7870 struct rte_flow_error *error)
7872 static const char err_msg[] = "shared action creation unsupported";
7873 struct rte_flow_attr attr = { .transfer = 0 };
7874 const struct mlx5_flow_driver_ops *fops =
7875 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7877 if (flow_drv_action_validate(dev, conf, action, fops, error))
7879 if (!fops->action_create) {
7880 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7881 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7885 return fops->action_create(dev, conf, action, error);
7889 * Updates inplace the shared action configuration pointed by *action* handle
7890 * with the configuration provided as *action* argument.
7891 * The update of the shared action configuration effects all flow rules reusing
7892 * the action via handle.
7895 * Pointer to Ethernet device structure.
7896 * @param[in] shared_action
7897 * Handle for the shared action to be updated.
7899 * Action specification used to modify the action pointed by handle.
7900 * *action* should be of same type with the action pointed by the *action*
7901 * handle argument, otherwise considered as invalid.
7903 * Perform verbose error reporting if not NULL. PMDs initialize this
7904 * structure in case of error only.
7907 * 0 on success, a negative errno value otherwise and rte_errno is set.
7910 mlx5_shared_action_update(struct rte_eth_dev *dev,
7911 struct rte_flow_shared_action *shared_action,
7912 const struct rte_flow_action *action,
7913 struct rte_flow_error *error)
7915 struct rte_flow_attr attr = { .transfer = 0 };
7916 const struct mlx5_flow_driver_ops *fops =
7917 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7920 switch (shared_action->type) {
7921 case MLX5_RTE_FLOW_ACTION_TYPE_SHARED_RSS:
7922 if (action->type != RTE_FLOW_ACTION_TYPE_RSS) {
7923 return rte_flow_error_set(error, EINVAL,
7924 RTE_FLOW_ERROR_TYPE_ACTION,
7926 "update action type invalid");
7928 ret = flow_drv_action_validate(dev, NULL, action, fops, error);
7931 return flow_drv_action_update(dev, shared_action, action->conf,
7934 return rte_flow_error_set(error, ENOTSUP,
7935 RTE_FLOW_ERROR_TYPE_ACTION,
7937 "action type not supported");
7942 * Query the shared action by handle.
7944 * This function allows retrieving action-specific data such as counters.
7945 * Data is gathered by special action which may be present/referenced in
7946 * more than one flow rule definition.
7948 * \see RTE_FLOW_ACTION_TYPE_COUNT
7951 * Pointer to Ethernet device structure.
7953 * Handle for the shared action to query.
7954 * @param[in, out] data
7955 * Pointer to storage for the associated query data type.
7957 * Perform verbose error reporting if not NULL. PMDs initialize this
7958 * structure in case of error only.
7961 * 0 on success, a negative errno value otherwise and rte_errno is set.
7964 mlx5_shared_action_query(struct rte_eth_dev *dev,
7965 const struct rte_flow_shared_action *action,
7967 struct rte_flow_error *error)
7970 switch (action->type) {
7971 case MLX5_RTE_FLOW_ACTION_TYPE_SHARED_RSS:
7972 __atomic_load(&action->refcnt, (uint32_t *)data,
7976 return rte_flow_error_set(error, ENOTSUP,
7977 RTE_FLOW_ERROR_TYPE_ACTION,
7979 "action type not supported");
7984 * Destroy all shared actions.
7987 * Pointer to Ethernet device.
7990 * 0 on success, a negative errno value otherwise and rte_errno is set.
7993 mlx5_shared_action_flush(struct rte_eth_dev *dev)
7995 struct rte_flow_error error;
7996 struct mlx5_priv *priv = dev->data->dev_private;
7997 struct rte_flow_shared_action *action;
8000 while (!LIST_EMPTY(&priv->shared_actions)) {
8001 action = LIST_FIRST(&priv->shared_actions);
8002 ret = mlx5_shared_action_destroy(dev, action, &error);
8008 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8009 struct mlx5_flow_tunnel *tunnel)
8011 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8012 struct mlx5_flow_id_pool *id_pool = thub->tunnel_ids;
8014 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8015 dev->data->port_id, tunnel->tunnel_id);
8016 RTE_VERIFY(!__atomic_load_n(&tunnel->refctn, __ATOMIC_RELAXED));
8017 LIST_REMOVE(tunnel, chain);
8018 mlx5_flow_id_release(id_pool, tunnel->tunnel_id);
8019 mlx5_hlist_destroy(tunnel->groups, NULL, NULL);
8023 static struct mlx5_flow_tunnel *
8024 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8026 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8027 struct mlx5_flow_tunnel *tun;
8029 LIST_FOREACH(tun, &thub->tunnels, chain) {
8030 if (tun->tunnel_id == id)
8037 static struct mlx5_flow_tunnel *
8038 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8039 const struct rte_flow_tunnel *app_tunnel)
8042 struct mlx5_flow_tunnel *tunnel;
8043 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8044 struct mlx5_flow_id_pool *id_pool = thub->tunnel_ids;
8047 ret = mlx5_flow_id_get(id_pool, &id);
8051 * mlx5 flow tunnel is an auxlilary data structure
8052 * It's not part of IO. No need to allocate it from
8053 * huge pages pools dedicated for IO
8055 tunnel = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*tunnel),
8058 mlx5_flow_id_pool_release(id_pool);
8061 tunnel->groups = mlx5_hlist_create("tunnel groups", 1024);
8062 if (!tunnel->groups) {
8063 mlx5_flow_id_pool_release(id_pool);
8067 /* initiate new PMD tunnel */
8068 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8069 tunnel->tunnel_id = id;
8070 tunnel->action.type = (typeof(tunnel->action.type))
8071 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8072 tunnel->action.conf = tunnel;
8073 tunnel->item.type = (typeof(tunnel->item.type))
8074 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8075 tunnel->item.spec = tunnel;
8076 tunnel->item.last = NULL;
8077 tunnel->item.mask = NULL;
8079 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8080 dev->data->port_id, tunnel->tunnel_id);
8086 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
8087 const struct rte_flow_tunnel *app_tunnel,
8088 struct mlx5_flow_tunnel **tunnel)
8091 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8092 struct mlx5_flow_tunnel *tun;
8094 LIST_FOREACH(tun, &thub->tunnels, chain) {
8095 if (!memcmp(app_tunnel, &tun->app_tunnel,
8096 sizeof(*app_tunnel))) {
8103 tun = mlx5_flow_tunnel_allocate(dev, app_tunnel);
8105 LIST_INSERT_HEAD(&thub->tunnels, tun, chain);
8112 __atomic_add_fetch(&tun->refctn, 1, __ATOMIC_RELAXED);
8117 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
8119 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
8123 if (!LIST_EMPTY(&thub->tunnels))
8124 DRV_LOG(WARNING, "port %u tunnels present\n", port_id);
8125 mlx5_flow_id_pool_release(thub->tunnel_ids);
8126 mlx5_flow_id_pool_release(thub->table_ids);
8127 mlx5_hlist_destroy(thub->groups, NULL, NULL);
8131 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
8134 struct mlx5_flow_tunnel_hub *thub;
8136 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
8140 LIST_INIT(&thub->tunnels);
8141 thub->tunnel_ids = mlx5_flow_id_pool_alloc(MLX5_MAX_TUNNELS);
8142 if (!thub->tunnel_ids) {
8146 thub->table_ids = mlx5_flow_id_pool_alloc(MLX5_MAX_TABLES);
8147 if (!thub->table_ids) {
8151 thub->groups = mlx5_hlist_create("flow groups", MLX5_MAX_TABLES);
8152 if (!thub->groups) {
8156 sh->tunnel_hub = thub;
8162 mlx5_hlist_destroy(thub->groups, NULL, NULL);
8163 if (thub->table_ids)
8164 mlx5_flow_id_pool_release(thub->table_ids);
8165 if (thub->tunnel_ids)
8166 mlx5_flow_id_pool_release(thub->tunnel_ids);