1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
10 #include <sys/queue.h>
12 #include <rte_common.h>
13 #include <rte_ether.h>
14 #include <ethdev_driver.h>
15 #include <rte_eal_paging.h>
17 #include <rte_cycles.h>
18 #include <rte_flow_driver.h>
19 #include <rte_malloc.h>
22 #include <mlx5_glue.h>
23 #include <mlx5_devx_cmds.h>
25 #include <mlx5_malloc.h>
27 #include "mlx5_defs.h"
29 #include "mlx5_flow.h"
30 #include "mlx5_flow_os.h"
33 #include "mlx5_common_os.h"
34 #include "rte_pmd_mlx5.h"
36 struct tunnel_default_miss_ctx {
40 struct rte_flow_action_rss action_rss;
41 struct rte_flow_action_queue miss_queue;
42 struct rte_flow_action_jump miss_jump;
48 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
49 struct rte_flow *flow,
50 const struct rte_flow_attr *attr,
51 const struct rte_flow_action *app_actions,
53 const struct mlx5_flow_tunnel *tunnel,
54 struct tunnel_default_miss_ctx *ctx,
55 struct rte_flow_error *error);
56 static struct mlx5_flow_tunnel *
57 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
59 mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
61 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
62 const struct mlx5_flow_tunnel *tunnel,
63 uint32_t group, uint32_t *table,
64 struct rte_flow_error *error);
66 static struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);
67 static void mlx5_flow_pop_thread_workspace(void);
70 /** Device flow drivers. */
71 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
73 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
75 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
76 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
77 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
78 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
80 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
81 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
84 /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
85 #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
90 /** Node object of input graph for mlx5_flow_expand_rss(). */
91 struct mlx5_flow_expand_node {
92 const int *const next;
94 * List of next node indexes. Index 0 is interpreted as a terminator.
96 const enum rte_flow_item_type type;
97 /**< Pattern item type of current node. */
100 * RSS types bit-field associated with this node
101 * (see ETH_RSS_* definitions).
104 /**< optional expand field. Default 0 to expand, 1 not go deeper. */
107 /** Object returned by mlx5_flow_expand_rss(). */
108 struct mlx5_flow_expand_rss {
110 /**< Number of entries @p patterns and @p priorities. */
112 struct rte_flow_item *pattern; /**< Expanded pattern array. */
113 uint32_t priority; /**< Priority offset for each expansion. */
117 static enum rte_flow_item_type
118 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
120 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
121 uint16_t ether_type = 0;
122 uint16_t ether_type_m;
123 uint8_t ip_next_proto = 0;
124 uint8_t ip_next_proto_m;
126 if (item == NULL || item->spec == NULL)
128 switch (item->type) {
129 case RTE_FLOW_ITEM_TYPE_ETH:
131 ether_type_m = ((const struct rte_flow_item_eth *)
134 ether_type_m = rte_flow_item_eth_mask.type;
135 if (ether_type_m != RTE_BE16(0xFFFF))
137 ether_type = ((const struct rte_flow_item_eth *)
139 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
140 ret = RTE_FLOW_ITEM_TYPE_IPV4;
141 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
142 ret = RTE_FLOW_ITEM_TYPE_IPV6;
143 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
144 ret = RTE_FLOW_ITEM_TYPE_VLAN;
146 ret = RTE_FLOW_ITEM_TYPE_END;
148 case RTE_FLOW_ITEM_TYPE_VLAN:
150 ether_type_m = ((const struct rte_flow_item_vlan *)
151 (item->mask))->inner_type;
153 ether_type_m = rte_flow_item_vlan_mask.inner_type;
154 if (ether_type_m != RTE_BE16(0xFFFF))
156 ether_type = ((const struct rte_flow_item_vlan *)
157 (item->spec))->inner_type;
158 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
159 ret = RTE_FLOW_ITEM_TYPE_IPV4;
160 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
161 ret = RTE_FLOW_ITEM_TYPE_IPV6;
162 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
163 ret = RTE_FLOW_ITEM_TYPE_VLAN;
165 ret = RTE_FLOW_ITEM_TYPE_END;
167 case RTE_FLOW_ITEM_TYPE_IPV4:
169 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
170 (item->mask))->hdr.next_proto_id;
173 rte_flow_item_ipv4_mask.hdr.next_proto_id;
174 if (ip_next_proto_m != 0xFF)
176 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
177 (item->spec))->hdr.next_proto_id;
178 if (ip_next_proto == IPPROTO_UDP)
179 ret = RTE_FLOW_ITEM_TYPE_UDP;
180 else if (ip_next_proto == IPPROTO_TCP)
181 ret = RTE_FLOW_ITEM_TYPE_TCP;
182 else if (ip_next_proto == IPPROTO_IP)
183 ret = RTE_FLOW_ITEM_TYPE_IPV4;
184 else if (ip_next_proto == IPPROTO_IPV6)
185 ret = RTE_FLOW_ITEM_TYPE_IPV6;
187 ret = RTE_FLOW_ITEM_TYPE_END;
189 case RTE_FLOW_ITEM_TYPE_IPV6:
191 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
192 (item->mask))->hdr.proto;
195 rte_flow_item_ipv6_mask.hdr.proto;
196 if (ip_next_proto_m != 0xFF)
198 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
199 (item->spec))->hdr.proto;
200 if (ip_next_proto == IPPROTO_UDP)
201 ret = RTE_FLOW_ITEM_TYPE_UDP;
202 else if (ip_next_proto == IPPROTO_TCP)
203 ret = RTE_FLOW_ITEM_TYPE_TCP;
204 else if (ip_next_proto == IPPROTO_IP)
205 ret = RTE_FLOW_ITEM_TYPE_IPV4;
206 else if (ip_next_proto == IPPROTO_IPV6)
207 ret = RTE_FLOW_ITEM_TYPE_IPV6;
209 ret = RTE_FLOW_ITEM_TYPE_END;
212 ret = RTE_FLOW_ITEM_TYPE_VOID;
218 #define MLX5_RSS_EXP_ELT_N 16
221 * Expand RSS flows into several possible flows according to the RSS hash
222 * fields requested and the driver capabilities.
225 * Buffer to store the result expansion.
227 * Buffer size in bytes. If 0, @p buf can be NULL.
231 * RSS types to expand (see ETH_RSS_* definitions).
233 * Input graph to expand @p pattern according to @p types.
234 * @param[in] graph_root_index
235 * Index of root node in @p graph, typically 0.
238 * A positive value representing the size of @p buf in bytes regardless of
239 * @p size on success, a negative errno value otherwise and rte_errno is
240 * set, the following errors are defined:
242 * -E2BIG: graph-depth @p graph is too deep.
245 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
246 const struct rte_flow_item *pattern, uint64_t types,
247 const struct mlx5_flow_expand_node graph[],
248 int graph_root_index)
250 const struct rte_flow_item *item;
251 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
252 const int *next_node;
253 const int *stack[MLX5_RSS_EXP_ELT_N];
255 struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
258 size_t user_pattern_size = 0;
260 const struct mlx5_flow_expand_node *next = NULL;
261 struct rte_flow_item missed_item;
264 const struct rte_flow_item *last_item = NULL;
266 memset(&missed_item, 0, sizeof(missed_item));
267 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
268 MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
270 buf->entry[0].priority = 0;
271 buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
273 addr = buf->entry[0].pattern;
275 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
276 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
278 for (i = 0; node->next && node->next[i]; ++i) {
279 next = &graph[node->next[i]];
280 if (next->type == item->type)
285 user_pattern_size += sizeof(*item);
287 user_pattern_size += sizeof(*item); /* Handle END item. */
288 lsize += user_pattern_size;
289 /* Copy the user pattern in the first entry of the buffer. */
291 rte_memcpy(addr, pattern, user_pattern_size);
292 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
295 /* Start expanding. */
296 memset(flow_items, 0, sizeof(flow_items));
297 user_pattern_size -= sizeof(*item);
299 * Check if the last valid item has spec set, need complete pattern,
300 * and the pattern can be used for expansion.
302 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
303 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
304 /* Item type END indicates expansion is not required. */
307 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
310 for (i = 0; node->next && node->next[i]; ++i) {
311 next = &graph[node->next[i]];
312 if (next->type == missed_item.type) {
313 flow_items[0].type = missed_item.type;
314 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
320 if (next && missed) {
321 elt = 2; /* missed item + item end. */
323 lsize += elt * sizeof(*item) + user_pattern_size;
324 if ((node->rss_types & types) && lsize <= size) {
325 buf->entry[buf->entries].priority = 1;
326 buf->entry[buf->entries].pattern = addr;
328 rte_memcpy(addr, buf->entry[0].pattern,
330 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
331 rte_memcpy(addr, flow_items, elt * sizeof(*item));
332 addr = (void *)(((uintptr_t)addr) +
333 elt * sizeof(*item));
336 memset(flow_items, 0, sizeof(flow_items));
337 next_node = node->next;
338 stack[stack_pos] = next_node;
339 node = next_node ? &graph[*next_node] : NULL;
341 flow_items[stack_pos].type = node->type;
342 if (node->rss_types & types) {
344 * compute the number of items to copy from the
345 * expansion and copy it.
346 * When the stack_pos is 0, there are 1 element in it,
347 * plus the addition END item.
350 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
351 lsize += elt * sizeof(*item) + user_pattern_size;
353 size_t n = elt * sizeof(*item);
355 buf->entry[buf->entries].priority =
356 stack_pos + 1 + missed;
357 buf->entry[buf->entries].pattern = addr;
359 rte_memcpy(addr, buf->entry[0].pattern,
361 addr = (void *)(((uintptr_t)addr) +
363 rte_memcpy(addr, &missed_item,
364 missed * sizeof(*item));
365 addr = (void *)(((uintptr_t)addr) +
366 missed * sizeof(*item));
367 rte_memcpy(addr, flow_items, n);
368 addr = (void *)(((uintptr_t)addr) + n);
372 if (!node->optional && node->next) {
373 next_node = node->next;
374 if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
378 stack[stack_pos] = next_node;
379 } else if (*(next_node + 1)) {
380 /* Follow up with the next possibility. */
383 /* Move to the next path. */
385 next_node = stack[--stack_pos];
387 stack[stack_pos] = next_node;
389 node = *next_node ? &graph[*next_node] : NULL;
394 enum mlx5_expansion {
396 MLX5_EXPANSION_ROOT_OUTER,
397 MLX5_EXPANSION_ROOT_ETH_VLAN,
398 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
399 MLX5_EXPANSION_OUTER_ETH,
400 MLX5_EXPANSION_OUTER_ETH_VLAN,
401 MLX5_EXPANSION_OUTER_VLAN,
402 MLX5_EXPANSION_OUTER_IPV4,
403 MLX5_EXPANSION_OUTER_IPV4_UDP,
404 MLX5_EXPANSION_OUTER_IPV4_TCP,
405 MLX5_EXPANSION_OUTER_IPV6,
406 MLX5_EXPANSION_OUTER_IPV6_UDP,
407 MLX5_EXPANSION_OUTER_IPV6_TCP,
408 MLX5_EXPANSION_VXLAN,
409 MLX5_EXPANSION_VXLAN_GPE,
411 MLX5_EXPANSION_GRE_KEY,
414 MLX5_EXPANSION_ETH_VLAN,
417 MLX5_EXPANSION_IPV4_UDP,
418 MLX5_EXPANSION_IPV4_TCP,
420 MLX5_EXPANSION_IPV6_UDP,
421 MLX5_EXPANSION_IPV6_TCP,
424 /** Supported expansion of items. */
425 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
426 [MLX5_EXPANSION_ROOT] = {
427 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
429 MLX5_EXPANSION_IPV6),
430 .type = RTE_FLOW_ITEM_TYPE_END,
432 [MLX5_EXPANSION_ROOT_OUTER] = {
433 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
434 MLX5_EXPANSION_OUTER_IPV4,
435 MLX5_EXPANSION_OUTER_IPV6),
436 .type = RTE_FLOW_ITEM_TYPE_END,
438 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
439 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
440 .type = RTE_FLOW_ITEM_TYPE_END,
442 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
443 .next = MLX5_FLOW_EXPAND_RSS_NEXT
444 (MLX5_EXPANSION_OUTER_ETH_VLAN),
445 .type = RTE_FLOW_ITEM_TYPE_END,
447 [MLX5_EXPANSION_OUTER_ETH] = {
448 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
449 MLX5_EXPANSION_OUTER_IPV6,
450 MLX5_EXPANSION_MPLS),
451 .type = RTE_FLOW_ITEM_TYPE_ETH,
454 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
455 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
456 .type = RTE_FLOW_ITEM_TYPE_ETH,
459 [MLX5_EXPANSION_OUTER_VLAN] = {
460 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
461 MLX5_EXPANSION_OUTER_IPV6),
462 .type = RTE_FLOW_ITEM_TYPE_VLAN,
464 [MLX5_EXPANSION_OUTER_IPV4] = {
465 .next = MLX5_FLOW_EXPAND_RSS_NEXT
466 (MLX5_EXPANSION_OUTER_IPV4_UDP,
467 MLX5_EXPANSION_OUTER_IPV4_TCP,
470 MLX5_EXPANSION_IPV6),
471 .type = RTE_FLOW_ITEM_TYPE_IPV4,
472 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
473 ETH_RSS_NONFRAG_IPV4_OTHER,
475 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
476 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
477 MLX5_EXPANSION_VXLAN_GPE),
478 .type = RTE_FLOW_ITEM_TYPE_UDP,
479 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
481 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
482 .type = RTE_FLOW_ITEM_TYPE_TCP,
483 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
485 [MLX5_EXPANSION_OUTER_IPV6] = {
486 .next = MLX5_FLOW_EXPAND_RSS_NEXT
487 (MLX5_EXPANSION_OUTER_IPV6_UDP,
488 MLX5_EXPANSION_OUTER_IPV6_TCP,
492 .type = RTE_FLOW_ITEM_TYPE_IPV6,
493 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
494 ETH_RSS_NONFRAG_IPV6_OTHER,
496 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
497 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
498 MLX5_EXPANSION_VXLAN_GPE),
499 .type = RTE_FLOW_ITEM_TYPE_UDP,
500 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
502 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
503 .type = RTE_FLOW_ITEM_TYPE_TCP,
504 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
506 [MLX5_EXPANSION_VXLAN] = {
507 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
509 MLX5_EXPANSION_IPV6),
510 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
512 [MLX5_EXPANSION_VXLAN_GPE] = {
513 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
515 MLX5_EXPANSION_IPV6),
516 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
518 [MLX5_EXPANSION_GRE] = {
519 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
521 MLX5_EXPANSION_GRE_KEY),
522 .type = RTE_FLOW_ITEM_TYPE_GRE,
524 [MLX5_EXPANSION_GRE_KEY] = {
525 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
526 MLX5_EXPANSION_IPV6),
527 .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
530 [MLX5_EXPANSION_MPLS] = {
531 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
532 MLX5_EXPANSION_IPV6),
533 .type = RTE_FLOW_ITEM_TYPE_MPLS,
535 [MLX5_EXPANSION_ETH] = {
536 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
537 MLX5_EXPANSION_IPV6),
538 .type = RTE_FLOW_ITEM_TYPE_ETH,
540 [MLX5_EXPANSION_ETH_VLAN] = {
541 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
542 .type = RTE_FLOW_ITEM_TYPE_ETH,
544 [MLX5_EXPANSION_VLAN] = {
545 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
546 MLX5_EXPANSION_IPV6),
547 .type = RTE_FLOW_ITEM_TYPE_VLAN,
549 [MLX5_EXPANSION_IPV4] = {
550 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
551 MLX5_EXPANSION_IPV4_TCP),
552 .type = RTE_FLOW_ITEM_TYPE_IPV4,
553 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
554 ETH_RSS_NONFRAG_IPV4_OTHER,
556 [MLX5_EXPANSION_IPV4_UDP] = {
557 .type = RTE_FLOW_ITEM_TYPE_UDP,
558 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
560 [MLX5_EXPANSION_IPV4_TCP] = {
561 .type = RTE_FLOW_ITEM_TYPE_TCP,
562 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
564 [MLX5_EXPANSION_IPV6] = {
565 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
566 MLX5_EXPANSION_IPV6_TCP),
567 .type = RTE_FLOW_ITEM_TYPE_IPV6,
568 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
569 ETH_RSS_NONFRAG_IPV6_OTHER,
571 [MLX5_EXPANSION_IPV6_UDP] = {
572 .type = RTE_FLOW_ITEM_TYPE_UDP,
573 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
575 [MLX5_EXPANSION_IPV6_TCP] = {
576 .type = RTE_FLOW_ITEM_TYPE_TCP,
577 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
581 static struct rte_flow_action_handle *
582 mlx5_action_handle_create(struct rte_eth_dev *dev,
583 const struct rte_flow_indir_action_conf *conf,
584 const struct rte_flow_action *action,
585 struct rte_flow_error *error);
586 static int mlx5_action_handle_destroy
587 (struct rte_eth_dev *dev,
588 struct rte_flow_action_handle *handle,
589 struct rte_flow_error *error);
590 static int mlx5_action_handle_update
591 (struct rte_eth_dev *dev,
592 struct rte_flow_action_handle *handle,
594 struct rte_flow_error *error);
595 static int mlx5_action_handle_query
596 (struct rte_eth_dev *dev,
597 const struct rte_flow_action_handle *handle,
599 struct rte_flow_error *error);
601 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
602 struct rte_flow_tunnel *app_tunnel,
603 struct rte_flow_action **actions,
604 uint32_t *num_of_actions,
605 struct rte_flow_error *error);
607 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
608 struct rte_flow_tunnel *app_tunnel,
609 struct rte_flow_item **items,
610 uint32_t *num_of_items,
611 struct rte_flow_error *error);
613 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
614 struct rte_flow_item *pmd_items,
615 uint32_t num_items, struct rte_flow_error *err);
617 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
618 struct rte_flow_action *pmd_actions,
619 uint32_t num_actions,
620 struct rte_flow_error *err);
622 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
624 struct rte_flow_restore_info *info,
625 struct rte_flow_error *err);
627 static const struct rte_flow_ops mlx5_flow_ops = {
628 .validate = mlx5_flow_validate,
629 .create = mlx5_flow_create,
630 .destroy = mlx5_flow_destroy,
631 .flush = mlx5_flow_flush,
632 .isolate = mlx5_flow_isolate,
633 .query = mlx5_flow_query,
634 .dev_dump = mlx5_flow_dev_dump,
635 .get_aged_flows = mlx5_flow_get_aged_flows,
636 .action_handle_create = mlx5_action_handle_create,
637 .action_handle_destroy = mlx5_action_handle_destroy,
638 .action_handle_update = mlx5_action_handle_update,
639 .action_handle_query = mlx5_action_handle_query,
640 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
641 .tunnel_match = mlx5_flow_tunnel_match,
642 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
643 .tunnel_item_release = mlx5_flow_tunnel_item_release,
644 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
647 /* Tunnel information. */
648 struct mlx5_flow_tunnel_info {
649 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
650 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
653 static struct mlx5_flow_tunnel_info tunnels_info[] = {
655 .tunnel = MLX5_FLOW_LAYER_VXLAN,
656 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
659 .tunnel = MLX5_FLOW_LAYER_GENEVE,
660 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
663 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
664 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
667 .tunnel = MLX5_FLOW_LAYER_GRE,
668 .ptype = RTE_PTYPE_TUNNEL_GRE,
671 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
672 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
675 .tunnel = MLX5_FLOW_LAYER_MPLS,
676 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
679 .tunnel = MLX5_FLOW_LAYER_NVGRE,
680 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
683 .tunnel = MLX5_FLOW_LAYER_IPIP,
684 .ptype = RTE_PTYPE_TUNNEL_IP,
687 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
688 .ptype = RTE_PTYPE_TUNNEL_IP,
691 .tunnel = MLX5_FLOW_LAYER_GTP,
692 .ptype = RTE_PTYPE_TUNNEL_GTPU,
699 * Translate tag ID to register.
702 * Pointer to the Ethernet device structure.
704 * The feature that request the register.
706 * The request register ID.
708 * Error description in case of any.
711 * The request register on success, a negative errno
712 * value otherwise and rte_errno is set.
715 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
716 enum mlx5_feature_name feature,
718 struct rte_flow_error *error)
720 struct mlx5_priv *priv = dev->data->dev_private;
721 struct mlx5_dev_config *config = &priv->config;
722 enum modify_reg start_reg;
723 bool skip_mtr_reg = false;
726 case MLX5_HAIRPIN_RX:
728 case MLX5_HAIRPIN_TX:
730 case MLX5_METADATA_RX:
731 switch (config->dv_xmeta_en) {
732 case MLX5_XMETA_MODE_LEGACY:
734 case MLX5_XMETA_MODE_META16:
736 case MLX5_XMETA_MODE_META32:
740 case MLX5_METADATA_TX:
742 case MLX5_METADATA_FDB:
743 switch (config->dv_xmeta_en) {
744 case MLX5_XMETA_MODE_LEGACY:
746 case MLX5_XMETA_MODE_META16:
748 case MLX5_XMETA_MODE_META32:
753 switch (config->dv_xmeta_en) {
754 case MLX5_XMETA_MODE_LEGACY:
756 case MLX5_XMETA_MODE_META16:
758 case MLX5_XMETA_MODE_META32:
764 * If meter color and meter id share one register, flow match
765 * should use the meter color register for match.
767 if (priv->mtr_reg_share)
768 return priv->mtr_color_reg;
770 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
773 case MLX5_ASO_FLOW_HIT:
774 case MLX5_ASO_CONNTRACK:
775 /* All features use the same REG_C. */
776 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
777 return priv->mtr_color_reg;
780 * Metadata COPY_MARK register using is in meter suffix sub
781 * flow while with meter. It's safe to share the same register.
783 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
786 * If meter is enable, it will engage the register for color
787 * match and flow match. If meter color match is not using the
788 * REG_C_2, need to skip the REG_C_x be used by meter color
790 * If meter is disable, free to use all available registers.
792 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
793 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
794 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
795 if (id > (uint32_t)(REG_C_7 - start_reg))
796 return rte_flow_error_set(error, EINVAL,
797 RTE_FLOW_ERROR_TYPE_ITEM,
798 NULL, "invalid tag id");
799 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
800 return rte_flow_error_set(error, ENOTSUP,
801 RTE_FLOW_ERROR_TYPE_ITEM,
802 NULL, "unsupported tag id");
804 * This case means meter is using the REG_C_x great than 2.
805 * Take care not to conflict with meter color REG_C_x.
806 * If the available index REG_C_y >= REG_C_x, skip the
809 if (skip_mtr_reg && config->flow_mreg_c
810 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
811 if (id >= (uint32_t)(REG_C_7 - start_reg))
812 return rte_flow_error_set(error, EINVAL,
813 RTE_FLOW_ERROR_TYPE_ITEM,
814 NULL, "invalid tag id");
815 if (config->flow_mreg_c
816 [id + 1 + start_reg - REG_C_0] != REG_NON)
817 return config->flow_mreg_c
818 [id + 1 + start_reg - REG_C_0];
819 return rte_flow_error_set(error, ENOTSUP,
820 RTE_FLOW_ERROR_TYPE_ITEM,
821 NULL, "unsupported tag id");
823 return config->flow_mreg_c[id + start_reg - REG_C_0];
826 return rte_flow_error_set(error, EINVAL,
827 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
828 NULL, "invalid feature name");
832 * Check extensive flow metadata register support.
835 * Pointer to rte_eth_dev structure.
838 * True if device supports extensive flow metadata register, otherwise false.
841 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
843 struct mlx5_priv *priv = dev->data->dev_private;
844 struct mlx5_dev_config *config = &priv->config;
847 * Having available reg_c can be regarded inclusively as supporting
848 * extensive flow metadata register, which could mean,
849 * - metadata register copy action by modify header.
850 * - 16 modify header actions is supported.
851 * - reg_c's are preserved across different domain (FDB and NIC) on
852 * packet loopback by flow lookup miss.
854 return config->flow_mreg_c[2] != REG_NON;
858 * Get the lowest priority.
861 * Pointer to the Ethernet device structure.
862 * @param[in] attributes
863 * Pointer to device flow rule attributes.
866 * The value of lowest priority of flow.
869 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
870 const struct rte_flow_attr *attr)
872 struct mlx5_priv *priv = dev->data->dev_private;
874 if (!attr->group && !attr->transfer)
875 return priv->config.flow_prio - 2;
876 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
880 * Calculate matcher priority of the flow.
883 * Pointer to the Ethernet device structure.
885 * Pointer to device flow rule attributes.
886 * @param[in] subpriority
887 * The priority based on the items.
889 * The matcher priority of the flow.
892 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
893 const struct rte_flow_attr *attr,
894 uint32_t subpriority)
896 uint16_t priority = (uint16_t)attr->priority;
897 struct mlx5_priv *priv = dev->data->dev_private;
899 if (!attr->group && !attr->transfer) {
900 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
901 priority = priv->config.flow_prio - 1;
902 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
904 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
905 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
906 return priority * 3 + subpriority;
910 * Verify the @p item specifications (spec, last, mask) are compatible with the
914 * Item specification.
916 * @p item->mask or flow default bit-masks.
917 * @param[in] nic_mask
918 * Bit-masks covering supported fields by the NIC to compare with user mask.
920 * Bit-masks size in bytes.
921 * @param[in] range_accepted
922 * True if range of values is accepted for specific fields, false otherwise.
924 * Pointer to error structure.
927 * 0 on success, a negative errno value otherwise and rte_errno is set.
930 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
932 const uint8_t *nic_mask,
935 struct rte_flow_error *error)
939 MLX5_ASSERT(nic_mask);
940 for (i = 0; i < size; ++i)
941 if ((nic_mask[i] | mask[i]) != nic_mask[i])
942 return rte_flow_error_set(error, ENOTSUP,
943 RTE_FLOW_ERROR_TYPE_ITEM,
945 "mask enables non supported"
947 if (!item->spec && (item->mask || item->last))
948 return rte_flow_error_set(error, EINVAL,
949 RTE_FLOW_ERROR_TYPE_ITEM, item,
950 "mask/last without a spec is not"
952 if (item->spec && item->last && !range_accepted) {
958 for (i = 0; i < size; ++i) {
959 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
960 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
962 ret = memcmp(spec, last, size);
964 return rte_flow_error_set(error, EINVAL,
965 RTE_FLOW_ERROR_TYPE_ITEM,
967 "range is not valid");
973 * Adjust the hash fields according to the @p flow information.
975 * @param[in] dev_flow.
976 * Pointer to the mlx5_flow.
978 * 1 when the hash field is for a tunnel item.
979 * @param[in] layer_types
981 * @param[in] hash_fields
985 * The hash fields that should be used.
988 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
989 int tunnel __rte_unused, uint64_t layer_types,
990 uint64_t hash_fields)
992 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
993 int rss_request_inner = rss_desc->level >= 2;
995 /* Check RSS hash level for tunnel. */
996 if (tunnel && rss_request_inner)
997 hash_fields |= IBV_RX_HASH_INNER;
998 else if (tunnel || rss_request_inner)
1001 /* Check if requested layer matches RSS hash fields. */
1002 if (!(rss_desc->types & layer_types))
1008 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1009 * if several tunnel rules are used on this queue, the tunnel ptype will be
1013 * Rx queue to update.
1016 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1019 uint32_t tunnel_ptype = 0;
1021 /* Look up for the ptype to use. */
1022 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1023 if (!rxq_ctrl->flow_tunnels_n[i])
1025 if (!tunnel_ptype) {
1026 tunnel_ptype = tunnels_info[i].ptype;
1032 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1036 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
1040 * Pointer to the Ethernet device structure.
1041 * @param[in] dev_handle
1042 * Pointer to device flow handle structure.
1045 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1046 struct mlx5_flow_handle *dev_handle)
1048 struct mlx5_priv *priv = dev->data->dev_private;
1049 const int mark = dev_handle->mark;
1050 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1051 struct mlx5_ind_table_obj *ind_tbl = NULL;
1054 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1055 struct mlx5_hrxq *hrxq;
1057 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1058 dev_handle->rix_hrxq);
1060 ind_tbl = hrxq->ind_table;
1061 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1062 struct mlx5_shared_action_rss *shared_rss;
1064 shared_rss = mlx5_ipool_get
1065 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1066 dev_handle->rix_srss);
1068 ind_tbl = shared_rss->ind_tbl;
1072 for (i = 0; i != ind_tbl->queues_n; ++i) {
1073 int idx = ind_tbl->queues[i];
1074 struct mlx5_rxq_ctrl *rxq_ctrl =
1075 container_of((*priv->rxqs)[idx],
1076 struct mlx5_rxq_ctrl, rxq);
1079 * To support metadata register copy on Tx loopback,
1080 * this must be always enabled (metadata may arive
1081 * from other port - not from local flows only.
1083 if (priv->config.dv_flow_en &&
1084 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1085 mlx5_flow_ext_mreg_supported(dev)) {
1086 rxq_ctrl->rxq.mark = 1;
1087 rxq_ctrl->flow_mark_n = 1;
1089 rxq_ctrl->rxq.mark = 1;
1090 rxq_ctrl->flow_mark_n++;
1095 /* Increase the counter matching the flow. */
1096 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1097 if ((tunnels_info[j].tunnel &
1098 dev_handle->layers) ==
1099 tunnels_info[j].tunnel) {
1100 rxq_ctrl->flow_tunnels_n[j]++;
1104 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1110 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1113 * Pointer to the Ethernet device structure.
1115 * Pointer to flow structure.
1118 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1120 struct mlx5_priv *priv = dev->data->dev_private;
1121 uint32_t handle_idx;
1122 struct mlx5_flow_handle *dev_handle;
1124 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1125 handle_idx, dev_handle, next)
1126 flow_drv_rxq_flags_set(dev, dev_handle);
1130 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1131 * device flow if no other flow uses it with the same kind of request.
1134 * Pointer to Ethernet device.
1135 * @param[in] dev_handle
1136 * Pointer to the device flow handle structure.
1139 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1140 struct mlx5_flow_handle *dev_handle)
1142 struct mlx5_priv *priv = dev->data->dev_private;
1143 const int mark = dev_handle->mark;
1144 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1145 struct mlx5_ind_table_obj *ind_tbl = NULL;
1148 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1149 struct mlx5_hrxq *hrxq;
1151 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1152 dev_handle->rix_hrxq);
1154 ind_tbl = hrxq->ind_table;
1155 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1156 struct mlx5_shared_action_rss *shared_rss;
1158 shared_rss = mlx5_ipool_get
1159 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1160 dev_handle->rix_srss);
1162 ind_tbl = shared_rss->ind_tbl;
1166 MLX5_ASSERT(dev->data->dev_started);
1167 for (i = 0; i != ind_tbl->queues_n; ++i) {
1168 int idx = ind_tbl->queues[i];
1169 struct mlx5_rxq_ctrl *rxq_ctrl =
1170 container_of((*priv->rxqs)[idx],
1171 struct mlx5_rxq_ctrl, rxq);
1173 if (priv->config.dv_flow_en &&
1174 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1175 mlx5_flow_ext_mreg_supported(dev)) {
1176 rxq_ctrl->rxq.mark = 1;
1177 rxq_ctrl->flow_mark_n = 1;
1179 rxq_ctrl->flow_mark_n--;
1180 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1185 /* Decrease the counter matching the flow. */
1186 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1187 if ((tunnels_info[j].tunnel &
1188 dev_handle->layers) ==
1189 tunnels_info[j].tunnel) {
1190 rxq_ctrl->flow_tunnels_n[j]--;
1194 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1200 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1201 * @p flow if no other flow uses it with the same kind of request.
1204 * Pointer to Ethernet device.
1206 * Pointer to the flow.
1209 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1211 struct mlx5_priv *priv = dev->data->dev_private;
1212 uint32_t handle_idx;
1213 struct mlx5_flow_handle *dev_handle;
1215 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1216 handle_idx, dev_handle, next)
1217 flow_drv_rxq_flags_trim(dev, dev_handle);
1221 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1224 * Pointer to Ethernet device.
1227 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1229 struct mlx5_priv *priv = dev->data->dev_private;
1232 for (i = 0; i != priv->rxqs_n; ++i) {
1233 struct mlx5_rxq_ctrl *rxq_ctrl;
1236 if (!(*priv->rxqs)[i])
1238 rxq_ctrl = container_of((*priv->rxqs)[i],
1239 struct mlx5_rxq_ctrl, rxq);
1240 rxq_ctrl->flow_mark_n = 0;
1241 rxq_ctrl->rxq.mark = 0;
1242 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1243 rxq_ctrl->flow_tunnels_n[j] = 0;
1244 rxq_ctrl->rxq.tunnel = 0;
1249 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1252 * Pointer to the Ethernet device structure.
1255 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1257 struct mlx5_priv *priv = dev->data->dev_private;
1258 struct mlx5_rxq_data *data;
1261 for (i = 0; i != priv->rxqs_n; ++i) {
1262 if (!(*priv->rxqs)[i])
1264 data = (*priv->rxqs)[i];
1265 if (!rte_flow_dynf_metadata_avail()) {
1266 data->dynf_meta = 0;
1267 data->flow_meta_mask = 0;
1268 data->flow_meta_offset = -1;
1269 data->flow_meta_port_mask = 0;
1271 data->dynf_meta = 1;
1272 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1273 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1274 data->flow_meta_port_mask = (uint32_t)~0;
1275 if (priv->config.dv_xmeta_en == MLX5_XMETA_MODE_META16)
1276 data->flow_meta_port_mask >>= 16;
1282 * return a pointer to the desired action in the list of actions.
1284 * @param[in] actions
1285 * The list of actions to search the action in.
1287 * The action to find.
1290 * Pointer to the action in the list, if found. NULL otherwise.
1292 const struct rte_flow_action *
1293 mlx5_flow_find_action(const struct rte_flow_action *actions,
1294 enum rte_flow_action_type action)
1296 if (actions == NULL)
1298 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1299 if (actions->type == action)
1305 * Validate the flag action.
1307 * @param[in] action_flags
1308 * Bit-fields that holds the actions detected until now.
1310 * Attributes of flow that includes this action.
1312 * Pointer to error structure.
1315 * 0 on success, a negative errno value otherwise and rte_errno is set.
1318 mlx5_flow_validate_action_flag(uint64_t action_flags,
1319 const struct rte_flow_attr *attr,
1320 struct rte_flow_error *error)
1322 if (action_flags & MLX5_FLOW_ACTION_MARK)
1323 return rte_flow_error_set(error, EINVAL,
1324 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1325 "can't mark and flag in same flow");
1326 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1327 return rte_flow_error_set(error, EINVAL,
1328 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1330 " actions in same flow");
1332 return rte_flow_error_set(error, ENOTSUP,
1333 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1334 "flag action not supported for "
1340 * Validate the mark action.
1343 * Pointer to the queue action.
1344 * @param[in] action_flags
1345 * Bit-fields that holds the actions detected until now.
1347 * Attributes of flow that includes this action.
1349 * Pointer to error structure.
1352 * 0 on success, a negative errno value otherwise and rte_errno is set.
1355 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1356 uint64_t action_flags,
1357 const struct rte_flow_attr *attr,
1358 struct rte_flow_error *error)
1360 const struct rte_flow_action_mark *mark = action->conf;
1363 return rte_flow_error_set(error, EINVAL,
1364 RTE_FLOW_ERROR_TYPE_ACTION,
1366 "configuration cannot be null");
1367 if (mark->id >= MLX5_FLOW_MARK_MAX)
1368 return rte_flow_error_set(error, EINVAL,
1369 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1371 "mark id must in 0 <= id < "
1372 RTE_STR(MLX5_FLOW_MARK_MAX));
1373 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1374 return rte_flow_error_set(error, EINVAL,
1375 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1376 "can't flag and mark in same flow");
1377 if (action_flags & MLX5_FLOW_ACTION_MARK)
1378 return rte_flow_error_set(error, EINVAL,
1379 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1380 "can't have 2 mark actions in same"
1383 return rte_flow_error_set(error, ENOTSUP,
1384 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1385 "mark action not supported for "
1391 * Validate the drop action.
1393 * @param[in] action_flags
1394 * Bit-fields that holds the actions detected until now.
1396 * Attributes of flow that includes this action.
1398 * Pointer to error structure.
1401 * 0 on success, a negative errno value otherwise and rte_errno is set.
1404 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1405 const struct rte_flow_attr *attr,
1406 struct rte_flow_error *error)
1409 return rte_flow_error_set(error, ENOTSUP,
1410 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1411 "drop action not supported for "
1417 * Validate the queue action.
1420 * Pointer to the queue action.
1421 * @param[in] action_flags
1422 * Bit-fields that holds the actions detected until now.
1424 * Pointer to the Ethernet device structure.
1426 * Attributes of flow that includes this action.
1428 * Pointer to error structure.
1431 * 0 on success, a negative errno value otherwise and rte_errno is set.
1434 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1435 uint64_t action_flags,
1436 struct rte_eth_dev *dev,
1437 const struct rte_flow_attr *attr,
1438 struct rte_flow_error *error)
1440 struct mlx5_priv *priv = dev->data->dev_private;
1441 const struct rte_flow_action_queue *queue = action->conf;
1443 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1444 return rte_flow_error_set(error, EINVAL,
1445 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1446 "can't have 2 fate actions in"
1449 return rte_flow_error_set(error, EINVAL,
1450 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1451 NULL, "No Rx queues configured");
1452 if (queue->index >= priv->rxqs_n)
1453 return rte_flow_error_set(error, EINVAL,
1454 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1456 "queue index out of range");
1457 if (!(*priv->rxqs)[queue->index])
1458 return rte_flow_error_set(error, EINVAL,
1459 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1461 "queue is not configured");
1463 return rte_flow_error_set(error, ENOTSUP,
1464 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1465 "queue action not supported for "
1471 * Validate the rss action.
1474 * Pointer to the Ethernet device structure.
1476 * Pointer to the queue action.
1478 * Pointer to error structure.
1481 * 0 on success, a negative errno value otherwise and rte_errno is set.
1484 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1485 const struct rte_flow_action *action,
1486 struct rte_flow_error *error)
1488 struct mlx5_priv *priv = dev->data->dev_private;
1489 const struct rte_flow_action_rss *rss = action->conf;
1490 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1493 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1494 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1495 return rte_flow_error_set(error, ENOTSUP,
1496 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1498 "RSS hash function not supported");
1499 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1504 return rte_flow_error_set(error, ENOTSUP,
1505 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1507 "tunnel RSS is not supported");
1508 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1509 if (rss->key_len == 0 && rss->key != NULL)
1510 return rte_flow_error_set(error, ENOTSUP,
1511 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1513 "RSS hash key length 0");
1514 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1515 return rte_flow_error_set(error, ENOTSUP,
1516 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1518 "RSS hash key too small");
1519 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1520 return rte_flow_error_set(error, ENOTSUP,
1521 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1523 "RSS hash key too large");
1524 if (rss->queue_num > priv->config.ind_table_max_size)
1525 return rte_flow_error_set(error, ENOTSUP,
1526 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1528 "number of queues too large");
1529 if (rss->types & MLX5_RSS_HF_MASK)
1530 return rte_flow_error_set(error, ENOTSUP,
1531 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1533 "some RSS protocols are not"
1535 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1536 !(rss->types & ETH_RSS_IP))
1537 return rte_flow_error_set(error, EINVAL,
1538 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1539 "L3 partial RSS requested but L3 RSS"
1540 " type not specified");
1541 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1542 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1543 return rte_flow_error_set(error, EINVAL,
1544 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1545 "L4 partial RSS requested but L4 RSS"
1546 " type not specified");
1548 return rte_flow_error_set(error, EINVAL,
1549 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1550 NULL, "No Rx queues configured");
1551 if (!rss->queue_num)
1552 return rte_flow_error_set(error, EINVAL,
1553 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1554 NULL, "No queues configured");
1555 for (i = 0; i != rss->queue_num; ++i) {
1556 struct mlx5_rxq_ctrl *rxq_ctrl;
1558 if (rss->queue[i] >= priv->rxqs_n)
1559 return rte_flow_error_set
1561 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1562 &rss->queue[i], "queue index out of range");
1563 if (!(*priv->rxqs)[rss->queue[i]])
1564 return rte_flow_error_set
1565 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1566 &rss->queue[i], "queue is not configured");
1567 rxq_ctrl = container_of((*priv->rxqs)[rss->queue[i]],
1568 struct mlx5_rxq_ctrl, rxq);
1570 rxq_type = rxq_ctrl->type;
1571 if (rxq_type != rxq_ctrl->type)
1572 return rte_flow_error_set
1573 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1575 "combining hairpin and regular RSS queues is not supported");
1581 * Validate the rss action.
1584 * Pointer to the queue action.
1585 * @param[in] action_flags
1586 * Bit-fields that holds the actions detected until now.
1588 * Pointer to the Ethernet device structure.
1590 * Attributes of flow that includes this action.
1591 * @param[in] item_flags
1592 * Items that were detected.
1594 * Pointer to error structure.
1597 * 0 on success, a negative errno value otherwise and rte_errno is set.
1600 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1601 uint64_t action_flags,
1602 struct rte_eth_dev *dev,
1603 const struct rte_flow_attr *attr,
1604 uint64_t item_flags,
1605 struct rte_flow_error *error)
1607 const struct rte_flow_action_rss *rss = action->conf;
1608 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1611 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1612 return rte_flow_error_set(error, EINVAL,
1613 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1614 "can't have 2 fate actions"
1616 ret = mlx5_validate_action_rss(dev, action, error);
1620 return rte_flow_error_set(error, ENOTSUP,
1621 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1622 "rss action not supported for "
1624 if (rss->level > 1 && !tunnel)
1625 return rte_flow_error_set(error, EINVAL,
1626 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1627 "inner RSS is not supported for "
1628 "non-tunnel flows");
1629 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1630 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1631 return rte_flow_error_set(error, EINVAL,
1632 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1633 "RSS on eCPRI is not supported now");
1639 * Validate the default miss action.
1641 * @param[in] action_flags
1642 * Bit-fields that holds the actions detected until now.
1644 * Pointer to error structure.
1647 * 0 on success, a negative errno value otherwise and rte_errno is set.
1650 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1651 const struct rte_flow_attr *attr,
1652 struct rte_flow_error *error)
1654 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1655 return rte_flow_error_set(error, EINVAL,
1656 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1657 "can't have 2 fate actions in"
1660 return rte_flow_error_set(error, ENOTSUP,
1661 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1662 "default miss action not supported "
1665 return rte_flow_error_set(error, ENOTSUP,
1666 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1667 "only group 0 is supported");
1669 return rte_flow_error_set(error, ENOTSUP,
1670 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1671 NULL, "transfer is not supported");
1676 * Validate the count action.
1679 * Pointer to the Ethernet device structure.
1681 * Attributes of flow that includes this action.
1683 * Pointer to error structure.
1686 * 0 on success, a negative errno value otherwise and rte_errno is set.
1689 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1690 const struct rte_flow_attr *attr,
1691 struct rte_flow_error *error)
1694 return rte_flow_error_set(error, ENOTSUP,
1695 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1696 "count action not supported for "
1702 * Validate the ASO CT action.
1705 * Pointer to the Ethernet device structure.
1706 * @param[in] conntrack
1707 * Pointer to the CT action profile.
1709 * Pointer to error structure.
1712 * 0 on success, a negative errno value otherwise and rte_errno is set.
1715 mlx5_validate_action_ct(struct rte_eth_dev *dev,
1716 const struct rte_flow_action_conntrack *conntrack,
1717 struct rte_flow_error *error)
1721 if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
1722 return rte_flow_error_set(error, EINVAL,
1723 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1724 "Invalid CT state");
1725 if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
1726 return rte_flow_error_set(error, EINVAL,
1727 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1728 "Invalid last TCP packet flag");
1733 * Verify the @p attributes will be correctly understood by the NIC and store
1734 * them in the @p flow if everything is correct.
1737 * Pointer to the Ethernet device structure.
1738 * @param[in] attributes
1739 * Pointer to flow attributes
1741 * Pointer to error structure.
1744 * 0 on success, a negative errno value otherwise and rte_errno is set.
1747 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1748 const struct rte_flow_attr *attributes,
1749 struct rte_flow_error *error)
1751 struct mlx5_priv *priv = dev->data->dev_private;
1752 uint32_t priority_max = priv->config.flow_prio - 1;
1754 if (attributes->group)
1755 return rte_flow_error_set(error, ENOTSUP,
1756 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1757 NULL, "groups is not supported");
1758 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
1759 attributes->priority >= priority_max)
1760 return rte_flow_error_set(error, ENOTSUP,
1761 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1762 NULL, "priority out of range");
1763 if (attributes->egress)
1764 return rte_flow_error_set(error, ENOTSUP,
1765 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1766 "egress is not supported");
1767 if (attributes->transfer && !priv->config.dv_esw_en)
1768 return rte_flow_error_set(error, ENOTSUP,
1769 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1770 NULL, "transfer is not supported");
1771 if (!attributes->ingress)
1772 return rte_flow_error_set(error, EINVAL,
1773 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1775 "ingress attribute is mandatory");
1780 * Validate ICMP6 item.
1783 * Item specification.
1784 * @param[in] item_flags
1785 * Bit-fields that holds the items detected until now.
1786 * @param[in] ext_vlan_sup
1787 * Whether extended VLAN features are supported or not.
1789 * Pointer to error structure.
1792 * 0 on success, a negative errno value otherwise and rte_errno is set.
1795 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1796 uint64_t item_flags,
1797 uint8_t target_protocol,
1798 struct rte_flow_error *error)
1800 const struct rte_flow_item_icmp6 *mask = item->mask;
1801 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1802 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1803 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1804 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1805 MLX5_FLOW_LAYER_OUTER_L4;
1808 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1809 return rte_flow_error_set(error, EINVAL,
1810 RTE_FLOW_ERROR_TYPE_ITEM, item,
1811 "protocol filtering not compatible"
1812 " with ICMP6 layer");
1813 if (!(item_flags & l3m))
1814 return rte_flow_error_set(error, EINVAL,
1815 RTE_FLOW_ERROR_TYPE_ITEM, item,
1816 "IPv6 is mandatory to filter on"
1818 if (item_flags & l4m)
1819 return rte_flow_error_set(error, EINVAL,
1820 RTE_FLOW_ERROR_TYPE_ITEM, item,
1821 "multiple L4 layers not supported");
1823 mask = &rte_flow_item_icmp6_mask;
1824 ret = mlx5_flow_item_acceptable
1825 (item, (const uint8_t *)mask,
1826 (const uint8_t *)&rte_flow_item_icmp6_mask,
1827 sizeof(struct rte_flow_item_icmp6),
1828 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1835 * Validate ICMP item.
1838 * Item specification.
1839 * @param[in] item_flags
1840 * Bit-fields that holds the items detected until now.
1842 * Pointer to error structure.
1845 * 0 on success, a negative errno value otherwise and rte_errno is set.
1848 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1849 uint64_t item_flags,
1850 uint8_t target_protocol,
1851 struct rte_flow_error *error)
1853 const struct rte_flow_item_icmp *mask = item->mask;
1854 const struct rte_flow_item_icmp nic_mask = {
1855 .hdr.icmp_type = 0xff,
1856 .hdr.icmp_code = 0xff,
1857 .hdr.icmp_ident = RTE_BE16(0xffff),
1858 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1860 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1861 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1862 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1863 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1864 MLX5_FLOW_LAYER_OUTER_L4;
1867 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1868 return rte_flow_error_set(error, EINVAL,
1869 RTE_FLOW_ERROR_TYPE_ITEM, item,
1870 "protocol filtering not compatible"
1871 " with ICMP layer");
1872 if (!(item_flags & l3m))
1873 return rte_flow_error_set(error, EINVAL,
1874 RTE_FLOW_ERROR_TYPE_ITEM, item,
1875 "IPv4 is mandatory to filter"
1877 if (item_flags & l4m)
1878 return rte_flow_error_set(error, EINVAL,
1879 RTE_FLOW_ERROR_TYPE_ITEM, item,
1880 "multiple L4 layers not supported");
1883 ret = mlx5_flow_item_acceptable
1884 (item, (const uint8_t *)mask,
1885 (const uint8_t *)&nic_mask,
1886 sizeof(struct rte_flow_item_icmp),
1887 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1894 * Validate Ethernet item.
1897 * Item specification.
1898 * @param[in] item_flags
1899 * Bit-fields that holds the items detected until now.
1901 * Pointer to error structure.
1904 * 0 on success, a negative errno value otherwise and rte_errno is set.
1907 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1908 uint64_t item_flags, bool ext_vlan_sup,
1909 struct rte_flow_error *error)
1911 const struct rte_flow_item_eth *mask = item->mask;
1912 const struct rte_flow_item_eth nic_mask = {
1913 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1914 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1915 .type = RTE_BE16(0xffff),
1916 .has_vlan = ext_vlan_sup ? 1 : 0,
1919 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1920 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1921 MLX5_FLOW_LAYER_OUTER_L2;
1923 if (item_flags & ethm)
1924 return rte_flow_error_set(error, ENOTSUP,
1925 RTE_FLOW_ERROR_TYPE_ITEM, item,
1926 "multiple L2 layers not supported");
1927 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1928 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1929 return rte_flow_error_set(error, EINVAL,
1930 RTE_FLOW_ERROR_TYPE_ITEM, item,
1931 "L2 layer should not follow "
1933 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1934 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1935 return rte_flow_error_set(error, EINVAL,
1936 RTE_FLOW_ERROR_TYPE_ITEM, item,
1937 "L2 layer should not follow VLAN");
1939 mask = &rte_flow_item_eth_mask;
1940 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1941 (const uint8_t *)&nic_mask,
1942 sizeof(struct rte_flow_item_eth),
1943 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1948 * Validate VLAN item.
1951 * Item specification.
1952 * @param[in] item_flags
1953 * Bit-fields that holds the items detected until now.
1955 * Ethernet device flow is being created on.
1957 * Pointer to error structure.
1960 * 0 on success, a negative errno value otherwise and rte_errno is set.
1963 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1964 uint64_t item_flags,
1965 struct rte_eth_dev *dev,
1966 struct rte_flow_error *error)
1968 const struct rte_flow_item_vlan *spec = item->spec;
1969 const struct rte_flow_item_vlan *mask = item->mask;
1970 const struct rte_flow_item_vlan nic_mask = {
1971 .tci = RTE_BE16(UINT16_MAX),
1972 .inner_type = RTE_BE16(UINT16_MAX),
1974 uint16_t vlan_tag = 0;
1975 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1977 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1978 MLX5_FLOW_LAYER_INNER_L4) :
1979 (MLX5_FLOW_LAYER_OUTER_L3 |
1980 MLX5_FLOW_LAYER_OUTER_L4);
1981 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1982 MLX5_FLOW_LAYER_OUTER_VLAN;
1984 if (item_flags & vlanm)
1985 return rte_flow_error_set(error, EINVAL,
1986 RTE_FLOW_ERROR_TYPE_ITEM, item,
1987 "multiple VLAN layers not supported");
1988 else if ((item_flags & l34m) != 0)
1989 return rte_flow_error_set(error, EINVAL,
1990 RTE_FLOW_ERROR_TYPE_ITEM, item,
1991 "VLAN cannot follow L3/L4 layer");
1993 mask = &rte_flow_item_vlan_mask;
1994 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1995 (const uint8_t *)&nic_mask,
1996 sizeof(struct rte_flow_item_vlan),
1997 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2000 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2001 struct mlx5_priv *priv = dev->data->dev_private;
2003 if (priv->vmwa_context) {
2005 * Non-NULL context means we have a virtual machine
2006 * and SR-IOV enabled, we have to create VLAN interface
2007 * to make hypervisor to setup E-Switch vport
2008 * context correctly. We avoid creating the multiple
2009 * VLAN interfaces, so we cannot support VLAN tag mask.
2011 return rte_flow_error_set(error, EINVAL,
2012 RTE_FLOW_ERROR_TYPE_ITEM,
2014 "VLAN tag mask is not"
2015 " supported in virtual"
2020 vlan_tag = spec->tci;
2021 vlan_tag &= mask->tci;
2024 * From verbs perspective an empty VLAN is equivalent
2025 * to a packet without VLAN layer.
2028 return rte_flow_error_set(error, EINVAL,
2029 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2031 "VLAN cannot be empty");
2036 * Validate IPV4 item.
2039 * Item specification.
2040 * @param[in] item_flags
2041 * Bit-fields that holds the items detected until now.
2042 * @param[in] last_item
2043 * Previous validated item in the pattern items.
2044 * @param[in] ether_type
2045 * Type in the ethernet layer header (including dot1q).
2046 * @param[in] acc_mask
2047 * Acceptable mask, if NULL default internal default mask
2048 * will be used to check whether item fields are supported.
2049 * @param[in] range_accepted
2050 * True if range of values is accepted for specific fields, false otherwise.
2052 * Pointer to error structure.
2055 * 0 on success, a negative errno value otherwise and rte_errno is set.
2058 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2059 uint64_t item_flags,
2061 uint16_t ether_type,
2062 const struct rte_flow_item_ipv4 *acc_mask,
2063 bool range_accepted,
2064 struct rte_flow_error *error)
2066 const struct rte_flow_item_ipv4 *mask = item->mask;
2067 const struct rte_flow_item_ipv4 *spec = item->spec;
2068 const struct rte_flow_item_ipv4 nic_mask = {
2070 .src_addr = RTE_BE32(0xffffffff),
2071 .dst_addr = RTE_BE32(0xffffffff),
2072 .type_of_service = 0xff,
2073 .next_proto_id = 0xff,
2076 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2077 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2078 MLX5_FLOW_LAYER_OUTER_L3;
2079 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2080 MLX5_FLOW_LAYER_OUTER_L4;
2082 uint8_t next_proto = 0xFF;
2083 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2084 MLX5_FLOW_LAYER_OUTER_VLAN |
2085 MLX5_FLOW_LAYER_INNER_VLAN);
2087 if ((last_item & l2_vlan) && ether_type &&
2088 ether_type != RTE_ETHER_TYPE_IPV4)
2089 return rte_flow_error_set(error, EINVAL,
2090 RTE_FLOW_ERROR_TYPE_ITEM, item,
2091 "IPv4 cannot follow L2/VLAN layer "
2092 "which ether type is not IPv4");
2093 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2095 next_proto = mask->hdr.next_proto_id &
2096 spec->hdr.next_proto_id;
2097 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2098 return rte_flow_error_set(error, EINVAL,
2099 RTE_FLOW_ERROR_TYPE_ITEM,
2104 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2105 return rte_flow_error_set(error, EINVAL,
2106 RTE_FLOW_ERROR_TYPE_ITEM, item,
2107 "wrong tunnel type - IPv6 specified "
2108 "but IPv4 item provided");
2109 if (item_flags & l3m)
2110 return rte_flow_error_set(error, ENOTSUP,
2111 RTE_FLOW_ERROR_TYPE_ITEM, item,
2112 "multiple L3 layers not supported");
2113 else if (item_flags & l4m)
2114 return rte_flow_error_set(error, EINVAL,
2115 RTE_FLOW_ERROR_TYPE_ITEM, item,
2116 "L3 cannot follow an L4 layer.");
2117 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2118 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2119 return rte_flow_error_set(error, EINVAL,
2120 RTE_FLOW_ERROR_TYPE_ITEM, item,
2121 "L3 cannot follow an NVGRE layer.");
2123 mask = &rte_flow_item_ipv4_mask;
2124 else if (mask->hdr.next_proto_id != 0 &&
2125 mask->hdr.next_proto_id != 0xff)
2126 return rte_flow_error_set(error, EINVAL,
2127 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2128 "partial mask is not supported"
2130 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2131 acc_mask ? (const uint8_t *)acc_mask
2132 : (const uint8_t *)&nic_mask,
2133 sizeof(struct rte_flow_item_ipv4),
2134 range_accepted, error);
2141 * Validate IPV6 item.
2144 * Item specification.
2145 * @param[in] item_flags
2146 * Bit-fields that holds the items detected until now.
2147 * @param[in] last_item
2148 * Previous validated item in the pattern items.
2149 * @param[in] ether_type
2150 * Type in the ethernet layer header (including dot1q).
2151 * @param[in] acc_mask
2152 * Acceptable mask, if NULL default internal default mask
2153 * will be used to check whether item fields are supported.
2155 * Pointer to error structure.
2158 * 0 on success, a negative errno value otherwise and rte_errno is set.
2161 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2162 uint64_t item_flags,
2164 uint16_t ether_type,
2165 const struct rte_flow_item_ipv6 *acc_mask,
2166 struct rte_flow_error *error)
2168 const struct rte_flow_item_ipv6 *mask = item->mask;
2169 const struct rte_flow_item_ipv6 *spec = item->spec;
2170 const struct rte_flow_item_ipv6 nic_mask = {
2173 "\xff\xff\xff\xff\xff\xff\xff\xff"
2174 "\xff\xff\xff\xff\xff\xff\xff\xff",
2176 "\xff\xff\xff\xff\xff\xff\xff\xff"
2177 "\xff\xff\xff\xff\xff\xff\xff\xff",
2178 .vtc_flow = RTE_BE32(0xffffffff),
2182 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2183 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2184 MLX5_FLOW_LAYER_OUTER_L3;
2185 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2186 MLX5_FLOW_LAYER_OUTER_L4;
2188 uint8_t next_proto = 0xFF;
2189 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2190 MLX5_FLOW_LAYER_OUTER_VLAN |
2191 MLX5_FLOW_LAYER_INNER_VLAN);
2193 if ((last_item & l2_vlan) && ether_type &&
2194 ether_type != RTE_ETHER_TYPE_IPV6)
2195 return rte_flow_error_set(error, EINVAL,
2196 RTE_FLOW_ERROR_TYPE_ITEM, item,
2197 "IPv6 cannot follow L2/VLAN layer "
2198 "which ether type is not IPv6");
2199 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2200 next_proto = spec->hdr.proto;
2201 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
2202 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2203 return rte_flow_error_set(error, EINVAL,
2204 RTE_FLOW_ERROR_TYPE_ITEM,
2209 if (next_proto == IPPROTO_HOPOPTS ||
2210 next_proto == IPPROTO_ROUTING ||
2211 next_proto == IPPROTO_FRAGMENT ||
2212 next_proto == IPPROTO_ESP ||
2213 next_proto == IPPROTO_AH ||
2214 next_proto == IPPROTO_DSTOPTS)
2215 return rte_flow_error_set(error, EINVAL,
2216 RTE_FLOW_ERROR_TYPE_ITEM, item,
2217 "IPv6 proto (next header) should "
2218 "not be set as extension header");
2219 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2220 return rte_flow_error_set(error, EINVAL,
2221 RTE_FLOW_ERROR_TYPE_ITEM, item,
2222 "wrong tunnel type - IPv4 specified "
2223 "but IPv6 item provided");
2224 if (item_flags & l3m)
2225 return rte_flow_error_set(error, ENOTSUP,
2226 RTE_FLOW_ERROR_TYPE_ITEM, item,
2227 "multiple L3 layers not supported");
2228 else if (item_flags & l4m)
2229 return rte_flow_error_set(error, EINVAL,
2230 RTE_FLOW_ERROR_TYPE_ITEM, item,
2231 "L3 cannot follow an L4 layer.");
2232 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2233 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2234 return rte_flow_error_set(error, EINVAL,
2235 RTE_FLOW_ERROR_TYPE_ITEM, item,
2236 "L3 cannot follow an NVGRE layer.");
2238 mask = &rte_flow_item_ipv6_mask;
2239 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2240 acc_mask ? (const uint8_t *)acc_mask
2241 : (const uint8_t *)&nic_mask,
2242 sizeof(struct rte_flow_item_ipv6),
2243 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2250 * Validate UDP item.
2253 * Item specification.
2254 * @param[in] item_flags
2255 * Bit-fields that holds the items detected until now.
2256 * @param[in] target_protocol
2257 * The next protocol in the previous item.
2258 * @param[in] flow_mask
2259 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2261 * Pointer to error structure.
2264 * 0 on success, a negative errno value otherwise and rte_errno is set.
2267 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2268 uint64_t item_flags,
2269 uint8_t target_protocol,
2270 struct rte_flow_error *error)
2272 const struct rte_flow_item_udp *mask = item->mask;
2273 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2274 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2275 MLX5_FLOW_LAYER_OUTER_L3;
2276 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2277 MLX5_FLOW_LAYER_OUTER_L4;
2280 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2281 return rte_flow_error_set(error, EINVAL,
2282 RTE_FLOW_ERROR_TYPE_ITEM, item,
2283 "protocol filtering not compatible"
2285 if (!(item_flags & l3m))
2286 return rte_flow_error_set(error, EINVAL,
2287 RTE_FLOW_ERROR_TYPE_ITEM, item,
2288 "L3 is mandatory to filter on L4");
2289 if (item_flags & l4m)
2290 return rte_flow_error_set(error, EINVAL,
2291 RTE_FLOW_ERROR_TYPE_ITEM, item,
2292 "multiple L4 layers not supported");
2294 mask = &rte_flow_item_udp_mask;
2295 ret = mlx5_flow_item_acceptable
2296 (item, (const uint8_t *)mask,
2297 (const uint8_t *)&rte_flow_item_udp_mask,
2298 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2306 * Validate TCP item.
2309 * Item specification.
2310 * @param[in] item_flags
2311 * Bit-fields that holds the items detected until now.
2312 * @param[in] target_protocol
2313 * The next protocol in the previous item.
2315 * Pointer to error structure.
2318 * 0 on success, a negative errno value otherwise and rte_errno is set.
2321 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2322 uint64_t item_flags,
2323 uint8_t target_protocol,
2324 const struct rte_flow_item_tcp *flow_mask,
2325 struct rte_flow_error *error)
2327 const struct rte_flow_item_tcp *mask = item->mask;
2328 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2329 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2330 MLX5_FLOW_LAYER_OUTER_L3;
2331 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2332 MLX5_FLOW_LAYER_OUTER_L4;
2335 MLX5_ASSERT(flow_mask);
2336 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2337 return rte_flow_error_set(error, EINVAL,
2338 RTE_FLOW_ERROR_TYPE_ITEM, item,
2339 "protocol filtering not compatible"
2341 if (!(item_flags & l3m))
2342 return rte_flow_error_set(error, EINVAL,
2343 RTE_FLOW_ERROR_TYPE_ITEM, item,
2344 "L3 is mandatory to filter on L4");
2345 if (item_flags & l4m)
2346 return rte_flow_error_set(error, EINVAL,
2347 RTE_FLOW_ERROR_TYPE_ITEM, item,
2348 "multiple L4 layers not supported");
2350 mask = &rte_flow_item_tcp_mask;
2351 ret = mlx5_flow_item_acceptable
2352 (item, (const uint8_t *)mask,
2353 (const uint8_t *)flow_mask,
2354 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2362 * Validate VXLAN item.
2365 * Item specification.
2366 * @param[in] item_flags
2367 * Bit-fields that holds the items detected until now.
2368 * @param[in] target_protocol
2369 * The next protocol in the previous item.
2371 * Pointer to error structure.
2374 * 0 on success, a negative errno value otherwise and rte_errno is set.
2377 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
2378 uint64_t item_flags,
2379 struct rte_flow_error *error)
2381 const struct rte_flow_item_vxlan *spec = item->spec;
2382 const struct rte_flow_item_vxlan *mask = item->mask;
2387 } id = { .vlan_id = 0, };
2390 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2391 return rte_flow_error_set(error, ENOTSUP,
2392 RTE_FLOW_ERROR_TYPE_ITEM, item,
2393 "multiple tunnel layers not"
2396 * Verify only UDPv4 is present as defined in
2397 * https://tools.ietf.org/html/rfc7348
2399 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2400 return rte_flow_error_set(error, EINVAL,
2401 RTE_FLOW_ERROR_TYPE_ITEM, item,
2402 "no outer UDP layer found");
2404 mask = &rte_flow_item_vxlan_mask;
2405 ret = mlx5_flow_item_acceptable
2406 (item, (const uint8_t *)mask,
2407 (const uint8_t *)&rte_flow_item_vxlan_mask,
2408 sizeof(struct rte_flow_item_vxlan),
2409 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2413 memcpy(&id.vni[1], spec->vni, 3);
2414 memcpy(&id.vni[1], mask->vni, 3);
2416 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2417 return rte_flow_error_set(error, ENOTSUP,
2418 RTE_FLOW_ERROR_TYPE_ITEM, item,
2419 "VXLAN tunnel must be fully defined");
2424 * Validate VXLAN_GPE item.
2427 * Item specification.
2428 * @param[in] item_flags
2429 * Bit-fields that holds the items detected until now.
2431 * Pointer to the private data structure.
2432 * @param[in] target_protocol
2433 * The next protocol in the previous item.
2435 * Pointer to error structure.
2438 * 0 on success, a negative errno value otherwise and rte_errno is set.
2441 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2442 uint64_t item_flags,
2443 struct rte_eth_dev *dev,
2444 struct rte_flow_error *error)
2446 struct mlx5_priv *priv = dev->data->dev_private;
2447 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2448 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2453 } id = { .vlan_id = 0, };
2455 if (!priv->config.l3_vxlan_en)
2456 return rte_flow_error_set(error, ENOTSUP,
2457 RTE_FLOW_ERROR_TYPE_ITEM, item,
2458 "L3 VXLAN is not enabled by device"
2459 " parameter and/or not configured in"
2461 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2462 return rte_flow_error_set(error, ENOTSUP,
2463 RTE_FLOW_ERROR_TYPE_ITEM, item,
2464 "multiple tunnel layers not"
2467 * Verify only UDPv4 is present as defined in
2468 * https://tools.ietf.org/html/rfc7348
2470 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2471 return rte_flow_error_set(error, EINVAL,
2472 RTE_FLOW_ERROR_TYPE_ITEM, item,
2473 "no outer UDP layer found");
2475 mask = &rte_flow_item_vxlan_gpe_mask;
2476 ret = mlx5_flow_item_acceptable
2477 (item, (const uint8_t *)mask,
2478 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2479 sizeof(struct rte_flow_item_vxlan_gpe),
2480 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2485 return rte_flow_error_set(error, ENOTSUP,
2486 RTE_FLOW_ERROR_TYPE_ITEM,
2488 "VxLAN-GPE protocol"
2490 memcpy(&id.vni[1], spec->vni, 3);
2491 memcpy(&id.vni[1], mask->vni, 3);
2493 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2494 return rte_flow_error_set(error, ENOTSUP,
2495 RTE_FLOW_ERROR_TYPE_ITEM, item,
2496 "VXLAN-GPE tunnel must be fully"
2501 * Validate GRE Key item.
2504 * Item specification.
2505 * @param[in] item_flags
2506 * Bit flags to mark detected items.
2507 * @param[in] gre_item
2508 * Pointer to gre_item
2510 * Pointer to error structure.
2513 * 0 on success, a negative errno value otherwise and rte_errno is set.
2516 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2517 uint64_t item_flags,
2518 const struct rte_flow_item *gre_item,
2519 struct rte_flow_error *error)
2521 const rte_be32_t *mask = item->mask;
2523 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2524 const struct rte_flow_item_gre *gre_spec;
2525 const struct rte_flow_item_gre *gre_mask;
2527 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2528 return rte_flow_error_set(error, ENOTSUP,
2529 RTE_FLOW_ERROR_TYPE_ITEM, item,
2530 "Multiple GRE key not support");
2531 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2532 return rte_flow_error_set(error, ENOTSUP,
2533 RTE_FLOW_ERROR_TYPE_ITEM, item,
2534 "No preceding GRE header");
2535 if (item_flags & MLX5_FLOW_LAYER_INNER)
2536 return rte_flow_error_set(error, ENOTSUP,
2537 RTE_FLOW_ERROR_TYPE_ITEM, item,
2538 "GRE key following a wrong item");
2539 gre_mask = gre_item->mask;
2541 gre_mask = &rte_flow_item_gre_mask;
2542 gre_spec = gre_item->spec;
2543 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2544 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2545 return rte_flow_error_set(error, EINVAL,
2546 RTE_FLOW_ERROR_TYPE_ITEM, item,
2547 "Key bit must be on");
2550 mask = &gre_key_default_mask;
2551 ret = mlx5_flow_item_acceptable
2552 (item, (const uint8_t *)mask,
2553 (const uint8_t *)&gre_key_default_mask,
2554 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2559 * Validate GRE item.
2562 * Item specification.
2563 * @param[in] item_flags
2564 * Bit flags to mark detected items.
2565 * @param[in] target_protocol
2566 * The next protocol in the previous item.
2568 * Pointer to error structure.
2571 * 0 on success, a negative errno value otherwise and rte_errno is set.
2574 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2575 uint64_t item_flags,
2576 uint8_t target_protocol,
2577 struct rte_flow_error *error)
2579 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2580 const struct rte_flow_item_gre *mask = item->mask;
2582 const struct rte_flow_item_gre nic_mask = {
2583 .c_rsvd0_ver = RTE_BE16(0xB000),
2584 .protocol = RTE_BE16(UINT16_MAX),
2587 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2588 return rte_flow_error_set(error, EINVAL,
2589 RTE_FLOW_ERROR_TYPE_ITEM, item,
2590 "protocol filtering not compatible"
2591 " with this GRE layer");
2592 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2593 return rte_flow_error_set(error, ENOTSUP,
2594 RTE_FLOW_ERROR_TYPE_ITEM, item,
2595 "multiple tunnel layers not"
2597 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2598 return rte_flow_error_set(error, ENOTSUP,
2599 RTE_FLOW_ERROR_TYPE_ITEM, item,
2600 "L3 Layer is missing");
2602 mask = &rte_flow_item_gre_mask;
2603 ret = mlx5_flow_item_acceptable
2604 (item, (const uint8_t *)mask,
2605 (const uint8_t *)&nic_mask,
2606 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2610 #ifndef HAVE_MLX5DV_DR
2611 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2612 if (spec && (spec->protocol & mask->protocol))
2613 return rte_flow_error_set(error, ENOTSUP,
2614 RTE_FLOW_ERROR_TYPE_ITEM, item,
2615 "without MPLS support the"
2616 " specification cannot be used for"
2624 * Validate Geneve item.
2627 * Item specification.
2628 * @param[in] itemFlags
2629 * Bit-fields that holds the items detected until now.
2631 * Pointer to the private data structure.
2633 * Pointer to error structure.
2636 * 0 on success, a negative errno value otherwise and rte_errno is set.
2640 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2641 uint64_t item_flags,
2642 struct rte_eth_dev *dev,
2643 struct rte_flow_error *error)
2645 struct mlx5_priv *priv = dev->data->dev_private;
2646 const struct rte_flow_item_geneve *spec = item->spec;
2647 const struct rte_flow_item_geneve *mask = item->mask;
2650 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2651 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2652 const struct rte_flow_item_geneve nic_mask = {
2653 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2654 .vni = "\xff\xff\xff",
2655 .protocol = RTE_BE16(UINT16_MAX),
2658 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2659 return rte_flow_error_set(error, ENOTSUP,
2660 RTE_FLOW_ERROR_TYPE_ITEM, item,
2661 "L3 Geneve is not enabled by device"
2662 " parameter and/or not configured in"
2664 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2665 return rte_flow_error_set(error, ENOTSUP,
2666 RTE_FLOW_ERROR_TYPE_ITEM, item,
2667 "multiple tunnel layers not"
2670 * Verify only UDPv4 is present as defined in
2671 * https://tools.ietf.org/html/rfc7348
2673 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2674 return rte_flow_error_set(error, EINVAL,
2675 RTE_FLOW_ERROR_TYPE_ITEM, item,
2676 "no outer UDP layer found");
2678 mask = &rte_flow_item_geneve_mask;
2679 ret = mlx5_flow_item_acceptable
2680 (item, (const uint8_t *)mask,
2681 (const uint8_t *)&nic_mask,
2682 sizeof(struct rte_flow_item_geneve),
2683 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2687 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2688 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2689 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2690 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2691 return rte_flow_error_set(error, ENOTSUP,
2692 RTE_FLOW_ERROR_TYPE_ITEM,
2694 "Geneve protocol unsupported"
2695 " fields are being used");
2696 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2697 return rte_flow_error_set
2699 RTE_FLOW_ERROR_TYPE_ITEM,
2701 "Unsupported Geneve options length");
2703 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2704 return rte_flow_error_set
2706 RTE_FLOW_ERROR_TYPE_ITEM, item,
2707 "Geneve tunnel must be fully defined");
2712 * Validate Geneve TLV option item.
2715 * Item specification.
2716 * @param[in] last_item
2717 * Previous validated item in the pattern items.
2718 * @param[in] geneve_item
2719 * Previous GENEVE item specification.
2721 * Pointer to the rte_eth_dev structure.
2723 * Pointer to error structure.
2726 * 0 on success, a negative errno value otherwise and rte_errno is set.
2729 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
2731 const struct rte_flow_item *geneve_item,
2732 struct rte_eth_dev *dev,
2733 struct rte_flow_error *error)
2735 struct mlx5_priv *priv = dev->data->dev_private;
2736 struct mlx5_dev_ctx_shared *sh = priv->sh;
2737 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
2738 struct mlx5_hca_attr *hca_attr = &priv->config.hca_attr;
2739 uint8_t data_max_supported =
2740 hca_attr->max_geneve_tlv_option_data_len * 4;
2741 struct mlx5_dev_config *config = &priv->config;
2742 const struct rte_flow_item_geneve *geneve_spec;
2743 const struct rte_flow_item_geneve *geneve_mask;
2744 const struct rte_flow_item_geneve_opt *spec = item->spec;
2745 const struct rte_flow_item_geneve_opt *mask = item->mask;
2747 unsigned int data_len;
2748 uint8_t tlv_option_len;
2749 uint16_t optlen_m, optlen_v;
2750 const struct rte_flow_item_geneve_opt full_mask = {
2751 .option_class = RTE_BE16(0xffff),
2752 .option_type = 0xff,
2757 mask = &rte_flow_item_geneve_opt_mask;
2759 return rte_flow_error_set
2760 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2761 "Geneve TLV opt class/type/length must be specified");
2762 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
2763 return rte_flow_error_set
2764 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2765 "Geneve TLV opt length exceeeds the limit (31)");
2766 /* Check if class type and length masks are full. */
2767 if (full_mask.option_class != mask->option_class ||
2768 full_mask.option_type != mask->option_type ||
2769 full_mask.option_len != (mask->option_len & full_mask.option_len))
2770 return rte_flow_error_set
2771 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2772 "Geneve TLV opt class/type/length masks must be full");
2773 /* Check if length is supported */
2774 if ((uint32_t)spec->option_len >
2775 config->hca_attr.max_geneve_tlv_option_data_len)
2776 return rte_flow_error_set
2777 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2778 "Geneve TLV opt length not supported");
2779 if (config->hca_attr.max_geneve_tlv_options > 1)
2781 "max_geneve_tlv_options supports more than 1 option");
2782 /* Check GENEVE item preceding. */
2783 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
2784 return rte_flow_error_set
2785 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2786 "Geneve opt item must be preceded with Geneve item");
2787 geneve_spec = geneve_item->spec;
2788 geneve_mask = geneve_item->mask ? geneve_item->mask :
2789 &rte_flow_item_geneve_mask;
2790 /* Check if GENEVE TLV option size doesn't exceed option length */
2791 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
2792 geneve_spec->ver_opt_len_o_c_rsvd0)) {
2793 tlv_option_len = spec->option_len & mask->option_len;
2794 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
2795 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
2796 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
2797 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
2798 if ((optlen_v & optlen_m) <= tlv_option_len)
2799 return rte_flow_error_set
2800 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2801 "GENEVE TLV option length exceeds optlen");
2803 /* Check if length is 0 or data is 0. */
2804 if (spec->data == NULL || spec->option_len == 0)
2805 return rte_flow_error_set
2806 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2807 "Geneve TLV opt with zero data/length not supported");
2808 /* Check not all data & mask are 0. */
2809 data_len = spec->option_len * 4;
2810 if (mask->data == NULL) {
2811 for (i = 0; i < data_len; i++)
2815 return rte_flow_error_set(error, ENOTSUP,
2816 RTE_FLOW_ERROR_TYPE_ITEM, item,
2817 "Can't match on Geneve option data 0");
2819 for (i = 0; i < data_len; i++)
2820 if (spec->data[i] & mask->data[i])
2823 return rte_flow_error_set(error, ENOTSUP,
2824 RTE_FLOW_ERROR_TYPE_ITEM, item,
2825 "Can't match on Geneve option data and mask 0");
2826 /* Check data mask supported. */
2827 for (i = data_max_supported; i < data_len ; i++)
2829 return rte_flow_error_set(error, ENOTSUP,
2830 RTE_FLOW_ERROR_TYPE_ITEM, item,
2831 "Data mask is of unsupported size");
2833 /* Check GENEVE option is supported in NIC. */
2834 if (!config->hca_attr.geneve_tlv_opt)
2835 return rte_flow_error_set
2836 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2837 "Geneve TLV opt not supported");
2838 /* Check if we already have geneve option with different type/class. */
2839 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
2840 geneve_opt_resource = sh->geneve_tlv_option_resource;
2841 if (geneve_opt_resource != NULL)
2842 if (geneve_opt_resource->option_class != spec->option_class ||
2843 geneve_opt_resource->option_type != spec->option_type ||
2844 geneve_opt_resource->length != spec->option_len) {
2845 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2846 return rte_flow_error_set(error, ENOTSUP,
2847 RTE_FLOW_ERROR_TYPE_ITEM, item,
2848 "Only one Geneve TLV option supported");
2850 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2855 * Validate MPLS item.
2858 * Pointer to the rte_eth_dev structure.
2860 * Item specification.
2861 * @param[in] item_flags
2862 * Bit-fields that holds the items detected until now.
2863 * @param[in] prev_layer
2864 * The protocol layer indicated in previous item.
2866 * Pointer to error structure.
2869 * 0 on success, a negative errno value otherwise and rte_errno is set.
2872 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2873 const struct rte_flow_item *item __rte_unused,
2874 uint64_t item_flags __rte_unused,
2875 uint64_t prev_layer __rte_unused,
2876 struct rte_flow_error *error)
2878 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2879 const struct rte_flow_item_mpls *mask = item->mask;
2880 struct mlx5_priv *priv = dev->data->dev_private;
2883 if (!priv->config.mpls_en)
2884 return rte_flow_error_set(error, ENOTSUP,
2885 RTE_FLOW_ERROR_TYPE_ITEM, item,
2886 "MPLS not supported or"
2887 " disabled in firmware"
2889 /* MPLS over IP, UDP, GRE is allowed */
2890 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2891 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2892 MLX5_FLOW_LAYER_GRE |
2893 MLX5_FLOW_LAYER_GRE_KEY)))
2894 return rte_flow_error_set(error, EINVAL,
2895 RTE_FLOW_ERROR_TYPE_ITEM, item,
2896 "protocol filtering not compatible"
2897 " with MPLS layer");
2898 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2899 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2900 !(item_flags & MLX5_FLOW_LAYER_GRE))
2901 return rte_flow_error_set(error, ENOTSUP,
2902 RTE_FLOW_ERROR_TYPE_ITEM, item,
2903 "multiple tunnel layers not"
2906 mask = &rte_flow_item_mpls_mask;
2907 ret = mlx5_flow_item_acceptable
2908 (item, (const uint8_t *)mask,
2909 (const uint8_t *)&rte_flow_item_mpls_mask,
2910 sizeof(struct rte_flow_item_mpls),
2911 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2916 return rte_flow_error_set(error, ENOTSUP,
2917 RTE_FLOW_ERROR_TYPE_ITEM, item,
2918 "MPLS is not supported by Verbs, please"
2924 * Validate NVGRE item.
2927 * Item specification.
2928 * @param[in] item_flags
2929 * Bit flags to mark detected items.
2930 * @param[in] target_protocol
2931 * The next protocol in the previous item.
2933 * Pointer to error structure.
2936 * 0 on success, a negative errno value otherwise and rte_errno is set.
2939 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2940 uint64_t item_flags,
2941 uint8_t target_protocol,
2942 struct rte_flow_error *error)
2944 const struct rte_flow_item_nvgre *mask = item->mask;
2947 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2948 return rte_flow_error_set(error, EINVAL,
2949 RTE_FLOW_ERROR_TYPE_ITEM, item,
2950 "protocol filtering not compatible"
2951 " with this GRE layer");
2952 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2953 return rte_flow_error_set(error, ENOTSUP,
2954 RTE_FLOW_ERROR_TYPE_ITEM, item,
2955 "multiple tunnel layers not"
2957 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2958 return rte_flow_error_set(error, ENOTSUP,
2959 RTE_FLOW_ERROR_TYPE_ITEM, item,
2960 "L3 Layer is missing");
2962 mask = &rte_flow_item_nvgre_mask;
2963 ret = mlx5_flow_item_acceptable
2964 (item, (const uint8_t *)mask,
2965 (const uint8_t *)&rte_flow_item_nvgre_mask,
2966 sizeof(struct rte_flow_item_nvgre),
2967 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2974 * Validate eCPRI item.
2977 * Item specification.
2978 * @param[in] item_flags
2979 * Bit-fields that holds the items detected until now.
2980 * @param[in] last_item
2981 * Previous validated item in the pattern items.
2982 * @param[in] ether_type
2983 * Type in the ethernet layer header (including dot1q).
2984 * @param[in] acc_mask
2985 * Acceptable mask, if NULL default internal default mask
2986 * will be used to check whether item fields are supported.
2988 * Pointer to error structure.
2991 * 0 on success, a negative errno value otherwise and rte_errno is set.
2994 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
2995 uint64_t item_flags,
2997 uint16_t ether_type,
2998 const struct rte_flow_item_ecpri *acc_mask,
2999 struct rte_flow_error *error)
3001 const struct rte_flow_item_ecpri *mask = item->mask;
3002 const struct rte_flow_item_ecpri nic_mask = {
3006 RTE_BE32(((const struct rte_ecpri_common_hdr) {
3010 .dummy[0] = 0xFFFFFFFF,
3013 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3014 MLX5_FLOW_LAYER_OUTER_VLAN);
3015 struct rte_flow_item_ecpri mask_lo;
3017 if (!(last_item & outer_l2_vlan) &&
3018 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3019 return rte_flow_error_set(error, EINVAL,
3020 RTE_FLOW_ERROR_TYPE_ITEM, item,
3021 "eCPRI can only follow L2/VLAN layer or UDP layer");
3022 if ((last_item & outer_l2_vlan) && ether_type &&
3023 ether_type != RTE_ETHER_TYPE_ECPRI)
3024 return rte_flow_error_set(error, EINVAL,
3025 RTE_FLOW_ERROR_TYPE_ITEM, item,
3026 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3027 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3028 return rte_flow_error_set(error, EINVAL,
3029 RTE_FLOW_ERROR_TYPE_ITEM, item,
3030 "eCPRI with tunnel is not supported right now");
3031 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3032 return rte_flow_error_set(error, ENOTSUP,
3033 RTE_FLOW_ERROR_TYPE_ITEM, item,
3034 "multiple L3 layers not supported");
3035 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3036 return rte_flow_error_set(error, EINVAL,
3037 RTE_FLOW_ERROR_TYPE_ITEM, item,
3038 "eCPRI cannot coexist with a TCP layer");
3039 /* In specification, eCPRI could be over UDP layer. */
3040 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3041 return rte_flow_error_set(error, EINVAL,
3042 RTE_FLOW_ERROR_TYPE_ITEM, item,
3043 "eCPRI over UDP layer is not yet supported right now");
3044 /* Mask for type field in common header could be zero. */
3046 mask = &rte_flow_item_ecpri_mask;
3047 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3048 /* Input mask is in big-endian format. */
3049 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3050 return rte_flow_error_set(error, EINVAL,
3051 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3052 "partial mask is not supported for protocol");
3053 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3054 return rte_flow_error_set(error, EINVAL,
3055 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3056 "message header mask must be after a type mask");
3057 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3058 acc_mask ? (const uint8_t *)acc_mask
3059 : (const uint8_t *)&nic_mask,
3060 sizeof(struct rte_flow_item_ecpri),
3061 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3065 * Release resource related QUEUE/RSS action split.
3068 * Pointer to Ethernet device.
3070 * Flow to release id's from.
3073 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
3074 struct rte_flow *flow)
3076 struct mlx5_priv *priv = dev->data->dev_private;
3077 uint32_t handle_idx;
3078 struct mlx5_flow_handle *dev_handle;
3080 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
3081 handle_idx, dev_handle, next)
3082 if (dev_handle->split_flow_id &&
3083 !dev_handle->is_meter_flow_id)
3084 mlx5_ipool_free(priv->sh->ipool
3085 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
3086 dev_handle->split_flow_id);
3090 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3091 const struct rte_flow_attr *attr __rte_unused,
3092 const struct rte_flow_item items[] __rte_unused,
3093 const struct rte_flow_action actions[] __rte_unused,
3094 bool external __rte_unused,
3095 int hairpin __rte_unused,
3096 struct rte_flow_error *error)
3098 return rte_flow_error_set(error, ENOTSUP,
3099 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3102 static struct mlx5_flow *
3103 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3104 const struct rte_flow_attr *attr __rte_unused,
3105 const struct rte_flow_item items[] __rte_unused,
3106 const struct rte_flow_action actions[] __rte_unused,
3107 struct rte_flow_error *error)
3109 rte_flow_error_set(error, ENOTSUP,
3110 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3115 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3116 struct mlx5_flow *dev_flow __rte_unused,
3117 const struct rte_flow_attr *attr __rte_unused,
3118 const struct rte_flow_item items[] __rte_unused,
3119 const struct rte_flow_action actions[] __rte_unused,
3120 struct rte_flow_error *error)
3122 return rte_flow_error_set(error, ENOTSUP,
3123 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3127 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3128 struct rte_flow *flow __rte_unused,
3129 struct rte_flow_error *error)
3131 return rte_flow_error_set(error, ENOTSUP,
3132 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3136 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3137 struct rte_flow *flow __rte_unused)
3142 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3143 struct rte_flow *flow __rte_unused)
3148 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3149 struct rte_flow *flow __rte_unused,
3150 const struct rte_flow_action *actions __rte_unused,
3151 void *data __rte_unused,
3152 struct rte_flow_error *error)
3154 return rte_flow_error_set(error, ENOTSUP,
3155 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3159 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3160 uint32_t domains __rte_unused,
3161 uint32_t flags __rte_unused)
3166 /* Void driver to protect from null pointer reference. */
3167 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3168 .validate = flow_null_validate,
3169 .prepare = flow_null_prepare,
3170 .translate = flow_null_translate,
3171 .apply = flow_null_apply,
3172 .remove = flow_null_remove,
3173 .destroy = flow_null_destroy,
3174 .query = flow_null_query,
3175 .sync_domain = flow_null_sync_domain,
3179 * Select flow driver type according to flow attributes and device
3183 * Pointer to the dev structure.
3185 * Pointer to the flow attributes.
3188 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3190 static enum mlx5_flow_drv_type
3191 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3193 struct mlx5_priv *priv = dev->data->dev_private;
3194 /* The OS can determine first a specific flow type (DV, VERBS) */
3195 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3197 if (type != MLX5_FLOW_TYPE_MAX)
3199 /* If no OS specific type - continue with DV/VERBS selection */
3200 if (attr->transfer && priv->config.dv_esw_en)
3201 type = MLX5_FLOW_TYPE_DV;
3202 if (!attr->transfer)
3203 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3204 MLX5_FLOW_TYPE_VERBS;
3208 #define flow_get_drv_ops(type) flow_drv_ops[type]
3211 * Flow driver validation API. This abstracts calling driver specific functions.
3212 * The type of flow driver is determined according to flow attributes.
3215 * Pointer to the dev structure.
3217 * Pointer to the flow attributes.
3219 * Pointer to the list of items.
3220 * @param[in] actions
3221 * Pointer to the list of actions.
3222 * @param[in] external
3223 * This flow rule is created by request external to PMD.
3224 * @param[in] hairpin
3225 * Number of hairpin TX actions, 0 means classic flow.
3227 * Pointer to the error structure.
3230 * 0 on success, a negative errno value otherwise and rte_errno is set.
3233 flow_drv_validate(struct rte_eth_dev *dev,
3234 const struct rte_flow_attr *attr,
3235 const struct rte_flow_item items[],
3236 const struct rte_flow_action actions[],
3237 bool external, int hairpin, struct rte_flow_error *error)
3239 const struct mlx5_flow_driver_ops *fops;
3240 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3242 fops = flow_get_drv_ops(type);
3243 return fops->validate(dev, attr, items, actions, external,
3248 * Flow driver preparation API. This abstracts calling driver specific
3249 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3250 * calculates the size of memory required for device flow, allocates the memory,
3251 * initializes the device flow and returns the pointer.
3254 * This function initializes device flow structure such as dv or verbs in
3255 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3256 * rest. For example, adding returning device flow to flow->dev_flow list and
3257 * setting backward reference to the flow should be done out of this function.
3258 * layers field is not filled either.
3261 * Pointer to the dev structure.
3263 * Pointer to the flow attributes.
3265 * Pointer to the list of items.
3266 * @param[in] actions
3267 * Pointer to the list of actions.
3268 * @param[in] flow_idx
3269 * This memory pool index to the flow.
3271 * Pointer to the error structure.
3274 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3276 static inline struct mlx5_flow *
3277 flow_drv_prepare(struct rte_eth_dev *dev,
3278 const struct rte_flow *flow,
3279 const struct rte_flow_attr *attr,
3280 const struct rte_flow_item items[],
3281 const struct rte_flow_action actions[],
3283 struct rte_flow_error *error)
3285 const struct mlx5_flow_driver_ops *fops;
3286 enum mlx5_flow_drv_type type = flow->drv_type;
3287 struct mlx5_flow *mlx5_flow = NULL;
3289 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3290 fops = flow_get_drv_ops(type);
3291 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3293 mlx5_flow->flow_idx = flow_idx;
3298 * Flow driver translation API. This abstracts calling driver specific
3299 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3300 * translates a generic flow into a driver flow. flow_drv_prepare() must
3304 * dev_flow->layers could be filled as a result of parsing during translation
3305 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3306 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3307 * flow->actions could be overwritten even though all the expanded dev_flows
3308 * have the same actions.
3311 * Pointer to the rte dev structure.
3312 * @param[in, out] dev_flow
3313 * Pointer to the mlx5 flow.
3315 * Pointer to the flow attributes.
3317 * Pointer to the list of items.
3318 * @param[in] actions
3319 * Pointer to the list of actions.
3321 * Pointer to the error structure.
3324 * 0 on success, a negative errno value otherwise and rte_errno is set.
3327 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3328 const struct rte_flow_attr *attr,
3329 const struct rte_flow_item items[],
3330 const struct rte_flow_action actions[],
3331 struct rte_flow_error *error)
3333 const struct mlx5_flow_driver_ops *fops;
3334 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3336 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3337 fops = flow_get_drv_ops(type);
3338 return fops->translate(dev, dev_flow, attr, items, actions, error);
3342 * Flow driver apply API. This abstracts calling driver specific functions.
3343 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3344 * translated driver flows on to device. flow_drv_translate() must precede.
3347 * Pointer to Ethernet device structure.
3348 * @param[in, out] flow
3349 * Pointer to flow structure.
3351 * Pointer to error structure.
3354 * 0 on success, a negative errno value otherwise and rte_errno is set.
3357 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3358 struct rte_flow_error *error)
3360 const struct mlx5_flow_driver_ops *fops;
3361 enum mlx5_flow_drv_type type = flow->drv_type;
3363 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3364 fops = flow_get_drv_ops(type);
3365 return fops->apply(dev, flow, error);
3369 * Flow driver destroy API. This abstracts calling driver specific functions.
3370 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3371 * on device and releases resources of the flow.
3374 * Pointer to Ethernet device.
3375 * @param[in, out] flow
3376 * Pointer to flow structure.
3379 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3381 const struct mlx5_flow_driver_ops *fops;
3382 enum mlx5_flow_drv_type type = flow->drv_type;
3384 flow_mreg_split_qrss_release(dev, flow);
3385 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3386 fops = flow_get_drv_ops(type);
3387 fops->destroy(dev, flow);
3391 * Flow driver find RSS policy tbl API. This abstracts calling driver
3392 * specific functions. Parent flow (rte_flow) should have driver
3393 * type (drv_type). It will find the RSS policy table that has the rss_desc.
3396 * Pointer to Ethernet device.
3397 * @param[in, out] flow
3398 * Pointer to flow structure.
3400 * Pointer to meter policy table.
3401 * @param[in] rss_desc
3402 * Pointer to rss_desc
3404 static struct mlx5_flow_meter_sub_policy *
3405 flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
3406 struct rte_flow *flow,
3407 struct mlx5_flow_meter_policy *policy,
3408 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
3410 const struct mlx5_flow_driver_ops *fops;
3411 enum mlx5_flow_drv_type type = flow->drv_type;
3413 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3414 fops = flow_get_drv_ops(type);
3415 return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
3419 * Get RSS action from the action list.
3422 * Pointer to Ethernet device.
3423 * @param[in] actions
3424 * Pointer to the list of actions.
3426 * Parent flow structure pointer.
3429 * Pointer to the RSS action if exist, else return NULL.
3431 static const struct rte_flow_action_rss*
3432 flow_get_rss_action(struct rte_eth_dev *dev,
3433 const struct rte_flow_action actions[])
3435 struct mlx5_priv *priv = dev->data->dev_private;
3436 const struct rte_flow_action_rss *rss = NULL;
3438 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3439 switch (actions->type) {
3440 case RTE_FLOW_ACTION_TYPE_RSS:
3441 rss = actions->conf;
3443 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3445 const struct rte_flow_action_sample *sample =
3447 const struct rte_flow_action *act = sample->actions;
3448 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3449 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3453 case RTE_FLOW_ACTION_TYPE_METER:
3456 struct mlx5_flow_meter_info *fm;
3457 struct mlx5_flow_meter_policy *policy;
3458 const struct rte_flow_action_meter *mtr = actions->conf;
3460 fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
3462 policy = mlx5_flow_meter_policy_find(dev,
3463 fm->policy_id, NULL);
3464 if (policy && policy->is_rss)
3466 policy->act_cnt[RTE_COLOR_GREEN].rss->conf;
3478 * Get ASO age action by index.
3481 * Pointer to the Ethernet device structure.
3482 * @param[in] age_idx
3483 * Index to the ASO age action.
3486 * The specified ASO age action.
3488 struct mlx5_aso_age_action*
3489 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3491 uint16_t pool_idx = age_idx & UINT16_MAX;
3492 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3493 struct mlx5_priv *priv = dev->data->dev_private;
3494 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3495 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3497 return &pool->actions[offset - 1];
3500 /* maps indirect action to translated direct in some actions array */
3501 struct mlx5_translated_action_handle {
3502 struct rte_flow_action_handle *action; /**< Indirect action handle. */
3503 int index; /**< Index in related array of rte_flow_action. */
3507 * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
3508 * direct action if translation possible.
3509 * This functionality used to run same execution path for both direct and
3510 * indirect actions on flow create. All necessary preparations for indirect
3511 * action handling should be performed on *handle* actions list returned
3515 * Pointer to Ethernet device.
3516 * @param[in] actions
3517 * List of actions to translate.
3518 * @param[out] handle
3519 * List to store translated indirect action object handles.
3520 * @param[in, out] indir_n
3521 * Size of *handle* array. On return should be updated with number of
3522 * indirect actions retrieved from the *actions* list.
3523 * @param[out] translated_actions
3524 * List of actions where all indirect actions were translated to direct
3525 * if possible. NULL if no translation took place.
3527 * Pointer to the error structure.
3530 * 0 on success, a negative errno value otherwise and rte_errno is set.
3533 flow_action_handles_translate(struct rte_eth_dev *dev,
3534 const struct rte_flow_action actions[],
3535 struct mlx5_translated_action_handle *handle,
3537 struct rte_flow_action **translated_actions,
3538 struct rte_flow_error *error)
3540 struct mlx5_priv *priv = dev->data->dev_private;
3541 struct rte_flow_action *translated = NULL;
3542 size_t actions_size;
3545 struct mlx5_translated_action_handle *handle_end = NULL;
3547 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3548 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
3550 if (copied_n == *indir_n) {
3551 return rte_flow_error_set
3552 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3553 NULL, "too many shared actions");
3555 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
3556 sizeof(actions[n].conf));
3557 handle[copied_n].index = n;
3561 *indir_n = copied_n;
3564 actions_size = sizeof(struct rte_flow_action) * n;
3565 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3570 memcpy(translated, actions, actions_size);
3571 for (handle_end = handle + copied_n; handle < handle_end; handle++) {
3572 struct mlx5_shared_action_rss *shared_rss;
3573 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3574 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3575 uint32_t idx = act_idx &
3576 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3579 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3580 shared_rss = mlx5_ipool_get
3581 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3582 translated[handle->index].type =
3583 RTE_FLOW_ACTION_TYPE_RSS;
3584 translated[handle->index].conf =
3585 &shared_rss->origin;
3587 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
3588 translated[handle->index].type =
3589 (enum rte_flow_action_type)
3590 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
3591 translated[handle->index].conf = (void *)(uintptr_t)idx;
3593 case MLX5_INDIRECT_ACTION_TYPE_AGE:
3594 if (priv->sh->flow_hit_aso_en) {
3595 translated[handle->index].type =
3596 (enum rte_flow_action_type)
3597 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3598 translated[handle->index].conf =
3599 (void *)(uintptr_t)idx;
3603 case MLX5_INDIRECT_ACTION_TYPE_CT:
3604 if (priv->sh->ct_aso_en) {
3605 translated[handle->index].type =
3606 RTE_FLOW_ACTION_TYPE_CONNTRACK;
3607 translated[handle->index].conf =
3608 (void *)(uintptr_t)idx;
3613 mlx5_free(translated);
3614 return rte_flow_error_set
3615 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3616 NULL, "invalid indirect action type");
3619 *translated_actions = translated;
3624 * Get Shared RSS action from the action list.
3627 * Pointer to Ethernet device.
3629 * Pointer to the list of actions.
3630 * @param[in] shared_n
3631 * Actions list length.
3634 * The MLX5 RSS action ID if exists, otherwise return 0.
3637 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3638 struct mlx5_translated_action_handle *handle,
3641 struct mlx5_translated_action_handle *handle_end;
3642 struct mlx5_priv *priv = dev->data->dev_private;
3643 struct mlx5_shared_action_rss *shared_rss;
3646 for (handle_end = handle + shared_n; handle < handle_end; handle++) {
3647 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
3648 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
3649 uint32_t idx = act_idx &
3650 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
3652 case MLX5_INDIRECT_ACTION_TYPE_RSS:
3653 shared_rss = mlx5_ipool_get
3654 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3656 __atomic_add_fetch(&shared_rss->refcnt, 1,
3667 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3669 const struct rte_flow_item *item;
3670 unsigned int has_vlan = 0;
3672 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3673 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3679 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3680 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3681 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3682 MLX5_EXPANSION_ROOT_OUTER;
3686 * Get layer flags from the prefix flow.
3688 * Some flows may be split to several subflows, the prefix subflow gets the
3689 * match items and the suffix sub flow gets the actions.
3690 * Some actions need the user defined match item flags to get the detail for
3692 * This function helps the suffix flow to get the item layer flags from prefix
3695 * @param[in] dev_flow
3696 * Pointer the created preifx subflow.
3699 * The layers get from prefix subflow.
3701 static inline uint64_t
3702 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3704 uint64_t layers = 0;
3707 * Layers bits could be localization, but usually the compiler will
3708 * help to do the optimization work for source code.
3709 * If no decap actions, use the layers directly.
3711 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3712 return dev_flow->handle->layers;
3713 /* Convert L3 layers with decap action. */
3714 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3715 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3716 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3717 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3718 /* Convert L4 layers with decap action. */
3719 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3720 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3721 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3722 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3727 * Get metadata split action information.
3729 * @param[in] actions
3730 * Pointer to the list of actions.
3732 * Pointer to the return pointer.
3733 * @param[out] qrss_type
3734 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3735 * if no QUEUE/RSS is found.
3736 * @param[out] encap_idx
3737 * Pointer to the index of the encap action if exists, otherwise the last
3741 * Total number of actions.
3744 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3745 const struct rte_flow_action **qrss,
3748 const struct rte_flow_action_raw_encap *raw_encap;
3750 int raw_decap_idx = -1;
3753 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3754 switch (actions->type) {
3755 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3756 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3757 *encap_idx = actions_n;
3759 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3760 raw_decap_idx = actions_n;
3762 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3763 raw_encap = actions->conf;
3764 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3765 *encap_idx = raw_decap_idx != -1 ?
3766 raw_decap_idx : actions_n;
3768 case RTE_FLOW_ACTION_TYPE_QUEUE:
3769 case RTE_FLOW_ACTION_TYPE_RSS:
3777 if (*encap_idx == -1)
3778 *encap_idx = actions_n;
3779 /* Count RTE_FLOW_ACTION_TYPE_END. */
3780 return actions_n + 1;
3784 * Check if the action will change packet.
3787 * Pointer to Ethernet device.
3792 * true if action will change packet, false otherwise.
3794 static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
3795 enum rte_flow_action_type type)
3797 struct mlx5_priv *priv = dev->data->dev_private;
3800 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
3801 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
3802 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
3803 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
3804 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
3805 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
3806 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
3807 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
3808 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3809 case RTE_FLOW_ACTION_TYPE_SET_TTL:
3810 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
3811 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
3812 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
3813 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
3814 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
3815 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
3816 case RTE_FLOW_ACTION_TYPE_SET_META:
3817 case RTE_FLOW_ACTION_TYPE_SET_TAG:
3818 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3819 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3820 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3821 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3822 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3823 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3824 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3825 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3826 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3827 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3828 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
3830 case RTE_FLOW_ACTION_TYPE_FLAG:
3831 case RTE_FLOW_ACTION_TYPE_MARK:
3832 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
3842 * Check meter action from the action list.
3845 * Pointer to Ethernet device.
3846 * @param[in] actions
3847 * Pointer to the list of actions.
3848 * @param[out] has_mtr
3849 * Pointer to the meter exist flag.
3850 * @param[out] has_modify
3851 * Pointer to the flag showing there's packet change action.
3852 * @param[out] meter_id
3853 * Pointer to the meter id.
3856 * Total number of actions.
3859 flow_check_meter_action(struct rte_eth_dev *dev,
3860 const struct rte_flow_action actions[],
3861 bool *has_mtr, bool *has_modify, uint32_t *meter_id)
3863 const struct rte_flow_action_meter *mtr = NULL;
3866 MLX5_ASSERT(has_mtr);
3868 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3869 switch (actions->type) {
3870 case RTE_FLOW_ACTION_TYPE_METER:
3871 mtr = actions->conf;
3872 *meter_id = mtr->mtr_id;
3879 *has_modify |= flow_check_modify_action_type(dev,
3883 /* Count RTE_FLOW_ACTION_TYPE_END. */
3884 return actions_n + 1;
3888 * Check if the flow should be split due to hairpin.
3889 * The reason for the split is that in current HW we can't
3890 * support encap and push-vlan on Rx, so if a flow contains
3891 * these actions we move it to Tx.
3894 * Pointer to Ethernet device.
3896 * Flow rule attributes.
3897 * @param[in] actions
3898 * Associated actions (list terminated by the END action).
3901 * > 0 the number of actions and the flow should be split,
3902 * 0 when no split required.
3905 flow_check_hairpin_split(struct rte_eth_dev *dev,
3906 const struct rte_flow_attr *attr,
3907 const struct rte_flow_action actions[])
3909 int queue_action = 0;
3912 const struct rte_flow_action_queue *queue;
3913 const struct rte_flow_action_rss *rss;
3914 const struct rte_flow_action_raw_encap *raw_encap;
3915 const struct rte_eth_hairpin_conf *conf;
3919 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3920 switch (actions->type) {
3921 case RTE_FLOW_ACTION_TYPE_QUEUE:
3922 queue = actions->conf;
3925 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
3926 if (conf == NULL || conf->tx_explicit != 0)
3931 case RTE_FLOW_ACTION_TYPE_RSS:
3932 rss = actions->conf;
3933 if (rss == NULL || rss->queue_num == 0)
3935 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
3936 if (conf == NULL || conf->tx_explicit != 0)
3941 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3942 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3943 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3944 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3945 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3949 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3950 raw_encap = actions->conf;
3951 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3960 if (split && queue_action)
3965 /* Declare flow create/destroy prototype in advance. */
3967 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
3968 const struct rte_flow_attr *attr,
3969 const struct rte_flow_item items[],
3970 const struct rte_flow_action actions[],
3971 bool external, struct rte_flow_error *error);
3974 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
3978 flow_dv_mreg_match_cb(struct mlx5_hlist *list __rte_unused,
3979 struct mlx5_hlist_entry *entry,
3980 uint64_t key, void *cb_ctx __rte_unused)
3982 struct mlx5_flow_mreg_copy_resource *mcp_res =
3983 container_of(entry, typeof(*mcp_res), hlist_ent);
3985 return mcp_res->mark_id != key;
3988 struct mlx5_hlist_entry *
3989 flow_dv_mreg_create_cb(struct mlx5_hlist *list, uint64_t key,
3992 struct rte_eth_dev *dev = list->ctx;
3993 struct mlx5_priv *priv = dev->data->dev_private;
3994 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3995 struct mlx5_flow_mreg_copy_resource *mcp_res;
3996 struct rte_flow_error *error = ctx->error;
3999 uint32_t mark_id = key;
4000 struct rte_flow_attr attr = {
4001 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4004 struct mlx5_rte_flow_item_tag tag_spec = {
4007 struct rte_flow_item items[] = {
4008 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
4010 struct rte_flow_action_mark ftag = {
4013 struct mlx5_flow_action_copy_mreg cp_mreg = {
4017 struct rte_flow_action_jump jump = {
4018 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4020 struct rte_flow_action actions[] = {
4021 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
4024 /* Fill the register fileds in the flow. */
4025 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
4029 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4033 /* Provide the full width of FLAG specific value. */
4034 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
4035 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
4036 /* Build a new flow. */
4037 if (mark_id != MLX5_DEFAULT_COPY_ID) {
4038 items[0] = (struct rte_flow_item){
4039 .type = (enum rte_flow_item_type)
4040 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4043 items[1] = (struct rte_flow_item){
4044 .type = RTE_FLOW_ITEM_TYPE_END,
4046 actions[0] = (struct rte_flow_action){
4047 .type = (enum rte_flow_action_type)
4048 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
4051 actions[1] = (struct rte_flow_action){
4052 .type = (enum rte_flow_action_type)
4053 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4056 actions[2] = (struct rte_flow_action){
4057 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4060 actions[3] = (struct rte_flow_action){
4061 .type = RTE_FLOW_ACTION_TYPE_END,
4064 /* Default rule, wildcard match. */
4065 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
4066 items[0] = (struct rte_flow_item){
4067 .type = RTE_FLOW_ITEM_TYPE_END,
4069 actions[0] = (struct rte_flow_action){
4070 .type = (enum rte_flow_action_type)
4071 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4074 actions[1] = (struct rte_flow_action){
4075 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4078 actions[2] = (struct rte_flow_action){
4079 .type = RTE_FLOW_ACTION_TYPE_END,
4082 /* Build a new entry. */
4083 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
4089 mcp_res->mark_id = mark_id;
4091 * The copy Flows are not included in any list. There
4092 * ones are referenced from other Flows and can not
4093 * be applied, removed, deleted in ardbitrary order
4094 * by list traversing.
4096 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
4097 actions, false, error);
4098 if (!mcp_res->rix_flow) {
4099 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
4102 return &mcp_res->hlist_ent;
4106 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4108 * As mark_id is unique, if there's already a registered flow for the mark_id,
4109 * return by increasing the reference counter of the resource. Otherwise, create
4110 * the resource (mcp_res) and flow.
4113 * - If ingress port is ANY and reg_c[1] is mark_id,
4114 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4116 * For default flow (zero mark_id), flow is like,
4117 * - If ingress port is ANY,
4118 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
4121 * Pointer to Ethernet device.
4123 * ID of MARK action, zero means default flow for META.
4125 * Perform verbose error reporting if not NULL.
4128 * Associated resource on success, NULL otherwise and rte_errno is set.
4130 static struct mlx5_flow_mreg_copy_resource *
4131 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
4132 struct rte_flow_error *error)
4134 struct mlx5_priv *priv = dev->data->dev_private;
4135 struct mlx5_hlist_entry *entry;
4136 struct mlx5_flow_cb_ctx ctx = {
4141 /* Check if already registered. */
4142 MLX5_ASSERT(priv->mreg_cp_tbl);
4143 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
4146 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
4151 flow_dv_mreg_remove_cb(struct mlx5_hlist *list, struct mlx5_hlist_entry *entry)
4153 struct mlx5_flow_mreg_copy_resource *mcp_res =
4154 container_of(entry, typeof(*mcp_res), hlist_ent);
4155 struct rte_eth_dev *dev = list->ctx;
4156 struct mlx5_priv *priv = dev->data->dev_private;
4158 MLX5_ASSERT(mcp_res->rix_flow);
4159 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
4160 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
4164 * Release flow in RX_CP_TBL.
4167 * Pointer to Ethernet device.
4169 * Parent flow for wich copying is provided.
4172 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4173 struct rte_flow *flow)
4175 struct mlx5_flow_mreg_copy_resource *mcp_res;
4176 struct mlx5_priv *priv = dev->data->dev_private;
4178 if (!flow->rix_mreg_copy)
4180 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4181 flow->rix_mreg_copy);
4182 if (!mcp_res || !priv->mreg_cp_tbl)
4184 MLX5_ASSERT(mcp_res->rix_flow);
4185 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4186 flow->rix_mreg_copy = 0;
4190 * Remove the default copy action from RX_CP_TBL.
4192 * This functions is called in the mlx5_dev_start(). No thread safe
4196 * Pointer to Ethernet device.
4199 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4201 struct mlx5_hlist_entry *entry;
4202 struct mlx5_priv *priv = dev->data->dev_private;
4204 /* Check if default flow is registered. */
4205 if (!priv->mreg_cp_tbl)
4207 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl,
4208 MLX5_DEFAULT_COPY_ID, NULL);
4211 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4215 * Add the default copy action in in RX_CP_TBL.
4217 * This functions is called in the mlx5_dev_start(). No thread safe
4221 * Pointer to Ethernet device.
4223 * Perform verbose error reporting if not NULL.
4226 * 0 for success, negative value otherwise and rte_errno is set.
4229 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4230 struct rte_flow_error *error)
4232 struct mlx5_priv *priv = dev->data->dev_private;
4233 struct mlx5_flow_mreg_copy_resource *mcp_res;
4235 /* Check whether extensive metadata feature is engaged. */
4236 if (!priv->config.dv_flow_en ||
4237 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4238 !mlx5_flow_ext_mreg_supported(dev) ||
4239 !priv->sh->dv_regc0_mask)
4242 * Add default mreg copy flow may be called multiple time, but
4243 * only be called once in stop. Avoid register it twice.
4245 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, MLX5_DEFAULT_COPY_ID, NULL))
4247 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
4254 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4256 * All the flow having Q/RSS action should be split by
4257 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4258 * performs the following,
4259 * - CQE->flow_tag := reg_c[1] (MARK)
4260 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4261 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4262 * but there should be a flow per each MARK ID set by MARK action.
4264 * For the aforementioned reason, if there's a MARK action in flow's action
4265 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4266 * the MARK ID to CQE's flow_tag like,
4267 * - If reg_c[1] is mark_id,
4268 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4270 * For SET_META action which stores value in reg_c[0], as the destination is
4271 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4272 * MARK ID means the default flow. The default flow looks like,
4273 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4276 * Pointer to Ethernet device.
4278 * Pointer to flow structure.
4279 * @param[in] actions
4280 * Pointer to the list of actions.
4282 * Perform verbose error reporting if not NULL.
4285 * 0 on success, negative value otherwise and rte_errno is set.
4288 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4289 struct rte_flow *flow,
4290 const struct rte_flow_action *actions,
4291 struct rte_flow_error *error)
4293 struct mlx5_priv *priv = dev->data->dev_private;
4294 struct mlx5_dev_config *config = &priv->config;
4295 struct mlx5_flow_mreg_copy_resource *mcp_res;
4296 const struct rte_flow_action_mark *mark;
4298 /* Check whether extensive metadata feature is engaged. */
4299 if (!config->dv_flow_en ||
4300 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4301 !mlx5_flow_ext_mreg_supported(dev) ||
4302 !priv->sh->dv_regc0_mask)
4304 /* Find MARK action. */
4305 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4306 switch (actions->type) {
4307 case RTE_FLOW_ACTION_TYPE_FLAG:
4308 mcp_res = flow_mreg_add_copy_action
4309 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4312 flow->rix_mreg_copy = mcp_res->idx;
4314 case RTE_FLOW_ACTION_TYPE_MARK:
4315 mark = (const struct rte_flow_action_mark *)
4318 flow_mreg_add_copy_action(dev, mark->id, error);
4321 flow->rix_mreg_copy = mcp_res->idx;
4330 #define MLX5_MAX_SPLIT_ACTIONS 24
4331 #define MLX5_MAX_SPLIT_ITEMS 24
4334 * Split the hairpin flow.
4335 * Since HW can't support encap and push-vlan on Rx, we move these
4337 * If the count action is after the encap then we also
4338 * move the count action. in this case the count will also measure
4342 * Pointer to Ethernet device.
4343 * @param[in] actions
4344 * Associated actions (list terminated by the END action).
4345 * @param[out] actions_rx
4347 * @param[out] actions_tx
4349 * @param[out] pattern_tx
4350 * The pattern items for the Tx flow.
4351 * @param[out] flow_id
4352 * The flow ID connected to this flow.
4358 flow_hairpin_split(struct rte_eth_dev *dev,
4359 const struct rte_flow_action actions[],
4360 struct rte_flow_action actions_rx[],
4361 struct rte_flow_action actions_tx[],
4362 struct rte_flow_item pattern_tx[],
4365 const struct rte_flow_action_raw_encap *raw_encap;
4366 const struct rte_flow_action_raw_decap *raw_decap;
4367 struct mlx5_rte_flow_action_set_tag *set_tag;
4368 struct rte_flow_action *tag_action;
4369 struct mlx5_rte_flow_item_tag *tag_item;
4370 struct rte_flow_item *item;
4374 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4375 switch (actions->type) {
4376 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4377 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4378 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4379 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4380 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4381 rte_memcpy(actions_tx, actions,
4382 sizeof(struct rte_flow_action));
4385 case RTE_FLOW_ACTION_TYPE_COUNT:
4387 rte_memcpy(actions_tx, actions,
4388 sizeof(struct rte_flow_action));
4391 rte_memcpy(actions_rx, actions,
4392 sizeof(struct rte_flow_action));
4396 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4397 raw_encap = actions->conf;
4398 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4399 memcpy(actions_tx, actions,
4400 sizeof(struct rte_flow_action));
4404 rte_memcpy(actions_rx, actions,
4405 sizeof(struct rte_flow_action));
4409 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4410 raw_decap = actions->conf;
4411 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4412 memcpy(actions_tx, actions,
4413 sizeof(struct rte_flow_action));
4416 rte_memcpy(actions_rx, actions,
4417 sizeof(struct rte_flow_action));
4422 rte_memcpy(actions_rx, actions,
4423 sizeof(struct rte_flow_action));
4428 /* Add set meta action and end action for the Rx flow. */
4429 tag_action = actions_rx;
4430 tag_action->type = (enum rte_flow_action_type)
4431 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4433 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4435 set_tag = (void *)actions_rx;
4436 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4437 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
4440 MLX5_ASSERT(set_tag->id > REG_NON);
4441 tag_action->conf = set_tag;
4442 /* Create Tx item list. */
4443 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4444 addr = (void *)&pattern_tx[2];
4446 item->type = (enum rte_flow_item_type)
4447 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4448 tag_item = (void *)addr;
4449 tag_item->data = flow_id;
4450 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4451 MLX5_ASSERT(set_tag->id > REG_NON);
4452 item->spec = tag_item;
4453 addr += sizeof(struct mlx5_rte_flow_item_tag);
4454 tag_item = (void *)addr;
4455 tag_item->data = UINT32_MAX;
4456 tag_item->id = UINT16_MAX;
4457 item->mask = tag_item;
4460 item->type = RTE_FLOW_ITEM_TYPE_END;
4465 * The last stage of splitting chain, just creates the subflow
4466 * without any modification.
4469 * Pointer to Ethernet device.
4471 * Parent flow structure pointer.
4472 * @param[in, out] sub_flow
4473 * Pointer to return the created subflow, may be NULL.
4475 * Flow rule attributes.
4477 * Pattern specification (list terminated by the END pattern item).
4478 * @param[in] actions
4479 * Associated actions (list terminated by the END action).
4480 * @param[in] flow_split_info
4481 * Pointer to flow split info structure.
4483 * Perform verbose error reporting if not NULL.
4485 * 0 on success, negative value otherwise
4488 flow_create_split_inner(struct rte_eth_dev *dev,
4489 struct rte_flow *flow,
4490 struct mlx5_flow **sub_flow,
4491 const struct rte_flow_attr *attr,
4492 const struct rte_flow_item items[],
4493 const struct rte_flow_action actions[],
4494 struct mlx5_flow_split_info *flow_split_info,
4495 struct rte_flow_error *error)
4497 struct mlx5_flow *dev_flow;
4499 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4500 flow_split_info->flow_idx, error);
4503 dev_flow->flow = flow;
4504 dev_flow->external = flow_split_info->external;
4505 dev_flow->skip_scale = flow_split_info->skip_scale;
4506 /* Subflow object was created, we must include one in the list. */
4507 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4508 dev_flow->handle, next);
4510 * If dev_flow is as one of the suffix flow, some actions in suffix
4511 * flow may need some user defined item layer flags, and pass the
4512 * Metadate rxq mark flag to suffix flow as well.
4514 if (flow_split_info->prefix_layers)
4515 dev_flow->handle->layers = flow_split_info->prefix_layers;
4516 if (flow_split_info->prefix_mark)
4517 dev_flow->handle->mark = 1;
4519 *sub_flow = dev_flow;
4520 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4521 dev_flow->dv.table_id = flow_split_info->table_id;
4523 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4527 * Get the sub policy of a meter.
4530 * Pointer to Ethernet device.
4532 * Parent flow structure pointer.
4533 * @param[in] policy_id;
4536 * Flow rule attributes.
4538 * Pattern specification (list terminated by the END pattern item).
4540 * Perform verbose error reporting if not NULL.
4543 * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
4545 static struct mlx5_flow_meter_sub_policy *
4546 get_meter_sub_policy(struct rte_eth_dev *dev,
4547 struct rte_flow *flow,
4549 const struct rte_flow_attr *attr,
4550 const struct rte_flow_item items[],
4551 struct rte_flow_error *error)
4553 struct mlx5_flow_meter_policy *policy;
4554 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
4556 policy = mlx5_flow_meter_policy_find(dev, policy_id, NULL);
4558 rte_flow_error_set(error, EINVAL,
4559 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4560 "Failed to find Meter Policy.");
4563 if (policy->is_rss) {
4564 struct mlx5_flow_workspace *wks =
4565 mlx5_flow_get_thread_workspace();
4566 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
4567 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
4572 * This is a tmp dev_flow,
4573 * no need to register any matcher for it in translate.
4575 wks->skip_matcher_reg = 1;
4576 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
4577 struct mlx5_flow dev_flow = {0};
4578 struct mlx5_flow_handle dev_handle = { {0} };
4579 const void *rss_act = policy->act_cnt[i].rss->conf;
4580 struct rte_flow_action rss_actions[2] = {
4582 .type = RTE_FLOW_ACTION_TYPE_RSS,
4586 .type = RTE_FLOW_ACTION_TYPE_END,
4591 dev_flow.handle = &dev_handle;
4592 dev_flow.ingress = attr->ingress;
4593 dev_flow.flow = flow;
4594 dev_flow.external = 0;
4595 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4596 dev_flow.dv.transfer = attr->transfer;
4598 /* Translate RSS action to get rss hash fields. */
4599 if (flow_drv_translate(dev, &dev_flow, attr,
4600 items, rss_actions, error))
4602 rss_desc_v[i] = wks->rss_desc;
4603 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
4604 rss_desc_v[i].hash_fields = dev_flow.hash_fields;
4605 rss_desc_v[i].queue_num = rss_desc_v[i].hash_fields ?
4606 rss_desc_v[i].queue_num : 1;
4607 rss_desc[i] = &rss_desc_v[i];
4609 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
4610 flow, policy, rss_desc);
4612 enum mlx5_meter_domain mtr_domain =
4613 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4614 attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4615 MLX5_MTR_DOMAIN_INGRESS;
4616 sub_policy = policy->sub_policys[mtr_domain][0];
4619 rte_flow_error_set(error, EINVAL,
4620 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4621 "Failed to get meter sub-policy.");
4629 * Split the meter flow.
4631 * As meter flow will split to three sub flow, other than meter
4632 * action, the other actions make sense to only meter accepts
4633 * the packet. If it need to be dropped, no other additional
4634 * actions should be take.
4636 * One kind of special action which decapsulates the L3 tunnel
4637 * header will be in the prefix sub flow, as not to take the
4638 * L3 tunnel header into account.
4641 * Pointer to Ethernet device.
4643 * Parent flow structure pointer.
4645 * Pointer to flow meter structure.
4647 * Flow rule attributes.
4649 * Pattern specification (list terminated by the END pattern item).
4650 * @param[out] sfx_items
4651 * Suffix flow match items (list terminated by the END pattern item).
4652 * @param[in] actions
4653 * Associated actions (list terminated by the END action).
4654 * @param[out] actions_sfx
4655 * Suffix flow actions.
4656 * @param[out] actions_pre
4657 * Prefix flow actions.
4658 * @param[out] mtr_flow_id
4659 * Pointer to meter flow id.
4661 * Perform verbose error reporting if not NULL.
4664 * 0 on success, a negative errno value otherwise and rte_errno is set.
4667 flow_meter_split_prep(struct rte_eth_dev *dev,
4668 struct rte_flow *flow,
4669 struct mlx5_flow_meter_info *fm,
4670 const struct rte_flow_attr *attr,
4671 const struct rte_flow_item items[],
4672 struct rte_flow_item sfx_items[],
4673 const struct rte_flow_action actions[],
4674 struct rte_flow_action actions_sfx[],
4675 struct rte_flow_action actions_pre[],
4676 uint32_t *mtr_flow_id,
4677 struct rte_flow_error *error)
4679 struct mlx5_priv *priv = dev->data->dev_private;
4680 struct rte_flow_action *tag_action = NULL;
4681 struct rte_flow_item *tag_item;
4682 struct mlx5_rte_flow_action_set_tag *set_tag;
4683 const struct rte_flow_action_raw_encap *raw_encap;
4684 const struct rte_flow_action_raw_decap *raw_decap;
4685 struct mlx5_rte_flow_item_tag *tag_item_spec;
4686 struct mlx5_rte_flow_item_tag *tag_item_mask;
4687 uint32_t tag_id = 0;
4688 bool copy_vlan = false;
4689 struct rte_flow_action *hw_mtr_action;
4690 struct rte_flow_action *action_pre_head = NULL;
4691 bool mtr_first = priv->sh->meter_aso_en &&
4693 (attr->transfer && priv->representor_id != UINT16_MAX));
4694 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
4695 uint8_t mtr_reg_bits = priv->mtr_reg_share ?
4696 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
4697 uint32_t flow_id = 0;
4698 uint32_t flow_id_reversed = 0;
4699 uint8_t flow_id_bits = 0;
4702 /* For ASO meter, meter must be before tag in TX direction. */
4704 action_pre_head = actions_pre++;
4705 /* Leave space for tag action. */
4706 tag_action = actions_pre++;
4708 /* Prepare the actions for prefix and suffix flow. */
4709 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4710 struct rte_flow_action *action_cur = NULL;
4712 switch (actions->type) {
4713 case RTE_FLOW_ACTION_TYPE_METER:
4715 action_cur = action_pre_head;
4717 /* Leave space for tag action. */
4718 tag_action = actions_pre++;
4719 action_cur = actions_pre++;
4722 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4723 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4724 action_cur = actions_pre++;
4726 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4727 raw_encap = actions->conf;
4728 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4729 action_cur = actions_pre++;
4731 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4732 raw_decap = actions->conf;
4733 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4734 action_cur = actions_pre++;
4736 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4737 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4744 action_cur = (fm->def_policy) ?
4745 actions_sfx++ : actions_pre++;
4746 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
4748 /* Add end action to the actions. */
4749 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4750 if (priv->sh->meter_aso_en) {
4752 * For ASO meter, need to add an extra jump action explicitly,
4753 * to jump from meter to policer table.
4755 struct mlx5_flow_meter_sub_policy *sub_policy;
4756 struct mlx5_flow_tbl_data_entry *tbl_data;
4758 if (!fm->def_policy) {
4759 sub_policy = get_meter_sub_policy(dev, flow,
4760 fm->policy_id, attr,
4765 enum mlx5_meter_domain mtr_domain =
4766 attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
4767 attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
4768 MLX5_MTR_DOMAIN_INGRESS;
4771 &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
4773 tbl_data = container_of(sub_policy->tbl_rsc,
4774 struct mlx5_flow_tbl_data_entry, tbl);
4775 hw_mtr_action = actions_pre++;
4776 hw_mtr_action->type = (enum rte_flow_action_type)
4777 MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
4778 hw_mtr_action->conf = tbl_data->jump.action;
4780 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4783 return rte_flow_error_set(error, ENOMEM,
4784 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4785 "No tag action space.");
4787 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
4790 /* Only default-policy Meter creates mtr flow id. */
4791 if (fm->def_policy) {
4792 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
4794 return rte_flow_error_set(error, ENOMEM,
4795 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4796 "Failed to allocate meter flow id.");
4797 flow_id = tag_id - 1;
4798 flow_id_bits = MLX5_REG_BITS - __builtin_clz(flow_id);
4799 flow_id_bits = flow_id_bits ? flow_id_bits : 1;
4800 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
4802 mlx5_ipool_free(fm->flow_ipool, tag_id);
4803 return rte_flow_error_set(error, EINVAL,
4804 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4805 "Meter flow id exceeds max limit.");
4807 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
4808 priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
4810 /* Prepare the suffix subflow items. */
4811 tag_item = sfx_items++;
4812 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4813 int item_type = items->type;
4815 switch (item_type) {
4816 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4817 memcpy(sfx_items, items, sizeof(*sfx_items));
4820 case RTE_FLOW_ITEM_TYPE_VLAN:
4822 memcpy(sfx_items, items, sizeof(*sfx_items));
4824 * Convert to internal match item, it is used
4825 * for vlan push and set vid.
4827 sfx_items->type = (enum rte_flow_item_type)
4828 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4836 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4838 /* Build tag actions and items for meter_id/meter flow_id. */
4839 set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
4840 tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4841 tag_item_mask = tag_item_spec + 1;
4842 /* Both flow_id and meter_id share the same register. */
4843 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
4844 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
4846 .offset = mtr_id_offset,
4847 .length = mtr_reg_bits,
4848 .data = flow->meter,
4851 * The color Reg bits used by flow_id are growing from
4852 * msb to lsb, so must do bit reverse for flow_id val in RegC.
4854 for (shift = 0; shift < flow_id_bits; shift++)
4855 flow_id_reversed = (flow_id_reversed << 1) |
4856 ((flow_id >> shift) & 0x1);
4858 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
4859 tag_item_spec->id = set_tag->id;
4860 tag_item_spec->data = set_tag->data << mtr_id_offset;
4861 tag_item_mask->data = UINT32_MAX << mtr_id_offset;
4862 tag_action->type = (enum rte_flow_action_type)
4863 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4864 tag_action->conf = set_tag;
4865 tag_item->type = (enum rte_flow_item_type)
4866 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4867 tag_item->spec = tag_item_spec;
4868 tag_item->last = NULL;
4869 tag_item->mask = tag_item_mask;
4872 *mtr_flow_id = tag_id;
4877 * Split action list having QUEUE/RSS for metadata register copy.
4879 * Once Q/RSS action is detected in user's action list, the flow action
4880 * should be split in order to copy metadata registers, which will happen in
4882 * - CQE->flow_tag := reg_c[1] (MARK)
4883 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4884 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
4885 * This is because the last action of each flow must be a terminal action
4886 * (QUEUE, RSS or DROP).
4888 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
4889 * stored and kept in the mlx5_flow structure per each sub_flow.
4891 * The Q/RSS action is replaced with,
4892 * - SET_TAG, setting the allocated flow ID to reg_c[2].
4893 * And the following JUMP action is added at the end,
4894 * - JUMP, to RX_CP_TBL.
4896 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
4897 * flow_create_split_metadata() routine. The flow will look like,
4898 * - If flow ID matches (reg_c[2]), perform Q/RSS.
4901 * Pointer to Ethernet device.
4902 * @param[out] split_actions
4903 * Pointer to store split actions to jump to CP_TBL.
4904 * @param[in] actions
4905 * Pointer to the list of original flow actions.
4907 * Pointer to the Q/RSS action.
4908 * @param[in] actions_n
4909 * Number of original actions.
4911 * Perform verbose error reporting if not NULL.
4914 * non-zero unique flow_id on success, otherwise 0 and
4915 * error/rte_error are set.
4918 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
4919 struct rte_flow_action *split_actions,
4920 const struct rte_flow_action *actions,
4921 const struct rte_flow_action *qrss,
4922 int actions_n, struct rte_flow_error *error)
4924 struct mlx5_priv *priv = dev->data->dev_private;
4925 struct mlx5_rte_flow_action_set_tag *set_tag;
4926 struct rte_flow_action_jump *jump;
4927 const int qrss_idx = qrss - actions;
4928 uint32_t flow_id = 0;
4932 * Given actions will be split
4933 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
4934 * - Add jump to mreg CP_TBL.
4935 * As a result, there will be one more action.
4938 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
4939 set_tag = (void *)(split_actions + actions_n);
4941 * If tag action is not set to void(it means we are not the meter
4942 * suffix flow), add the tag action. Since meter suffix flow already
4943 * has the tag added.
4945 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
4947 * Allocate the new subflow ID. This one is unique within
4948 * device and not shared with representors. Otherwise,
4949 * we would have to resolve multi-thread access synch
4950 * issue. Each flow on the shared device is appended
4951 * with source vport identifier, so the resulting
4952 * flows will be unique in the shared (by master and
4953 * representors) domain even if they have coinciding
4956 mlx5_ipool_malloc(priv->sh->ipool
4957 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
4959 return rte_flow_error_set(error, ENOMEM,
4960 RTE_FLOW_ERROR_TYPE_ACTION,
4961 NULL, "can't allocate id "
4962 "for split Q/RSS subflow");
4963 /* Internal SET_TAG action to set flow ID. */
4964 *set_tag = (struct mlx5_rte_flow_action_set_tag){
4967 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
4971 /* Construct new actions array. */
4972 /* Replace QUEUE/RSS action. */
4973 split_actions[qrss_idx] = (struct rte_flow_action){
4974 .type = (enum rte_flow_action_type)
4975 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4979 /* JUMP action to jump to mreg copy table (CP_TBL). */
4980 jump = (void *)(set_tag + 1);
4981 *jump = (struct rte_flow_action_jump){
4982 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4984 split_actions[actions_n - 2] = (struct rte_flow_action){
4985 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4988 split_actions[actions_n - 1] = (struct rte_flow_action){
4989 .type = RTE_FLOW_ACTION_TYPE_END,
4995 * Extend the given action list for Tx metadata copy.
4997 * Copy the given action list to the ext_actions and add flow metadata register
4998 * copy action in order to copy reg_a set by WQE to reg_c[0].
5000 * @param[out] ext_actions
5001 * Pointer to the extended action list.
5002 * @param[in] actions
5003 * Pointer to the list of actions.
5004 * @param[in] actions_n
5005 * Number of actions in the list.
5007 * Perform verbose error reporting if not NULL.
5008 * @param[in] encap_idx
5009 * The encap action inndex.
5012 * 0 on success, negative value otherwise
5015 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
5016 struct rte_flow_action *ext_actions,
5017 const struct rte_flow_action *actions,
5018 int actions_n, struct rte_flow_error *error,
5021 struct mlx5_flow_action_copy_mreg *cp_mreg =
5022 (struct mlx5_flow_action_copy_mreg *)
5023 (ext_actions + actions_n + 1);
5026 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5030 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
5035 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
5036 if (encap_idx == actions_n - 1) {
5037 ext_actions[actions_n - 1] = (struct rte_flow_action){
5038 .type = (enum rte_flow_action_type)
5039 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5042 ext_actions[actions_n] = (struct rte_flow_action){
5043 .type = RTE_FLOW_ACTION_TYPE_END,
5046 ext_actions[encap_idx] = (struct rte_flow_action){
5047 .type = (enum rte_flow_action_type)
5048 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5051 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
5052 sizeof(*ext_actions) * (actions_n - encap_idx));
5058 * Check the match action from the action list.
5060 * @param[in] actions
5061 * Pointer to the list of actions.
5063 * Flow rule attributes.
5065 * The action to be check if exist.
5066 * @param[out] match_action_pos
5067 * Pointer to the position of the matched action if exists, otherwise is -1.
5068 * @param[out] qrss_action_pos
5069 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
5070 * @param[out] modify_after_mirror
5071 * Pointer to the flag of modify action after FDB mirroring.
5074 * > 0 the total number of actions.
5075 * 0 if not found match action in action list.
5078 flow_check_match_action(const struct rte_flow_action actions[],
5079 const struct rte_flow_attr *attr,
5080 enum rte_flow_action_type action,
5081 int *match_action_pos, int *qrss_action_pos,
5082 int *modify_after_mirror)
5084 const struct rte_flow_action_sample *sample;
5091 *match_action_pos = -1;
5092 *qrss_action_pos = -1;
5093 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5094 if (actions->type == action) {
5096 *match_action_pos = actions_n;
5098 switch (actions->type) {
5099 case RTE_FLOW_ACTION_TYPE_QUEUE:
5100 case RTE_FLOW_ACTION_TYPE_RSS:
5101 *qrss_action_pos = actions_n;
5103 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5104 sample = actions->conf;
5105 ratio = sample->ratio;
5106 sub_type = ((const struct rte_flow_action *)
5107 (sample->actions))->type;
5108 if (ratio == 1 && attr->transfer)
5111 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5112 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5113 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5114 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5115 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5116 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5117 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5118 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5119 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5120 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5121 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5122 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5123 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5124 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5125 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5126 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5127 case RTE_FLOW_ACTION_TYPE_FLAG:
5128 case RTE_FLOW_ACTION_TYPE_MARK:
5129 case RTE_FLOW_ACTION_TYPE_SET_META:
5130 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5131 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5132 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5133 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5134 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5135 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5136 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5137 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5138 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
5140 *modify_after_mirror = 1;
5147 if (flag && fdb_mirror && !*modify_after_mirror) {
5148 /* FDB mirroring uses the destination array to implement
5149 * instead of FLOW_SAMPLER object.
5151 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
5154 /* Count RTE_FLOW_ACTION_TYPE_END. */
5155 return flag ? actions_n + 1 : 0;
5158 #define SAMPLE_SUFFIX_ITEM 2
5161 * Split the sample flow.
5163 * As sample flow will split to two sub flow, sample flow with
5164 * sample action, the other actions will move to new suffix flow.
5166 * Also add unique tag id with tag action in the sample flow,
5167 * the same tag id will be as match in the suffix flow.
5170 * Pointer to Ethernet device.
5171 * @param[in] add_tag
5172 * Add extra tag action flag.
5173 * @param[out] sfx_items
5174 * Suffix flow match items (list terminated by the END pattern item).
5175 * @param[in] actions
5176 * Associated actions (list terminated by the END action).
5177 * @param[out] actions_sfx
5178 * Suffix flow actions.
5179 * @param[out] actions_pre
5180 * Prefix flow actions.
5181 * @param[in] actions_n
5182 * The total number of actions.
5183 * @param[in] sample_action_pos
5184 * The sample action position.
5185 * @param[in] qrss_action_pos
5186 * The Queue/RSS action position.
5187 * @param[in] jump_table
5188 * Add extra jump action flag.
5190 * Perform verbose error reporting if not NULL.
5193 * 0 on success, or unique flow_id, a negative errno value
5194 * otherwise and rte_errno is set.
5197 flow_sample_split_prep(struct rte_eth_dev *dev,
5199 struct rte_flow_item sfx_items[],
5200 const struct rte_flow_action actions[],
5201 struct rte_flow_action actions_sfx[],
5202 struct rte_flow_action actions_pre[],
5204 int sample_action_pos,
5205 int qrss_action_pos,
5207 struct rte_flow_error *error)
5209 struct mlx5_priv *priv = dev->data->dev_private;
5210 struct mlx5_rte_flow_action_set_tag *set_tag;
5211 struct mlx5_rte_flow_item_tag *tag_spec;
5212 struct mlx5_rte_flow_item_tag *tag_mask;
5213 struct rte_flow_action_jump *jump_action;
5214 uint32_t tag_id = 0;
5216 int append_index = 0;
5219 if (sample_action_pos < 0)
5220 return rte_flow_error_set(error, EINVAL,
5221 RTE_FLOW_ERROR_TYPE_ACTION,
5222 NULL, "invalid position of sample "
5224 /* Prepare the actions for prefix and suffix flow. */
5225 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
5226 index = qrss_action_pos;
5227 /* Put the preceding the Queue/RSS action into prefix flow. */
5229 memcpy(actions_pre, actions,
5230 sizeof(struct rte_flow_action) * index);
5231 /* Put others preceding the sample action into prefix flow. */
5232 if (sample_action_pos > index + 1)
5233 memcpy(actions_pre + index, actions + index + 1,
5234 sizeof(struct rte_flow_action) *
5235 (sample_action_pos - index - 1));
5236 index = sample_action_pos - 1;
5237 /* Put Queue/RSS action into Suffix flow. */
5238 memcpy(actions_sfx, actions + qrss_action_pos,
5239 sizeof(struct rte_flow_action));
5242 index = sample_action_pos;
5244 memcpy(actions_pre, actions,
5245 sizeof(struct rte_flow_action) * index);
5247 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
5248 * For CX6DX and above, metadata registers Cx preserve their value,
5249 * add an extra tag action for NIC-RX and E-Switch Domain.
5252 /* Prepare the prefix tag action. */
5254 set_tag = (void *)(actions_pre + actions_n + append_index);
5255 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
5258 mlx5_ipool_malloc(priv->sh->ipool
5259 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
5260 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5264 /* Prepare the suffix subflow items. */
5265 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
5266 tag_spec->data = tag_id;
5267 tag_spec->id = set_tag->id;
5268 tag_mask = tag_spec + 1;
5269 tag_mask->data = UINT32_MAX;
5270 sfx_items[0] = (struct rte_flow_item){
5271 .type = (enum rte_flow_item_type)
5272 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5277 sfx_items[1] = (struct rte_flow_item){
5278 .type = (enum rte_flow_item_type)
5279 RTE_FLOW_ITEM_TYPE_END,
5281 /* Prepare the tag action in prefix subflow. */
5282 actions_pre[index++] =
5283 (struct rte_flow_action){
5284 .type = (enum rte_flow_action_type)
5285 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
5289 memcpy(actions_pre + index, actions + sample_action_pos,
5290 sizeof(struct rte_flow_action));
5292 /* For the modify action after the sample action in E-Switch mirroring,
5293 * Add the extra jump action in prefix subflow and jump into the next
5294 * table, then do the modify action in the new table.
5297 /* Prepare the prefix jump action. */
5299 jump_action = (void *)(actions_pre + actions_n + append_index);
5300 jump_action->group = jump_table;
5301 actions_pre[index++] =
5302 (struct rte_flow_action){
5303 .type = (enum rte_flow_action_type)
5304 RTE_FLOW_ACTION_TYPE_JUMP,
5305 .conf = jump_action,
5308 actions_pre[index] = (struct rte_flow_action){
5309 .type = (enum rte_flow_action_type)
5310 RTE_FLOW_ACTION_TYPE_END,
5312 /* Put the actions after sample into Suffix flow. */
5313 memcpy(actions_sfx, actions + sample_action_pos + 1,
5314 sizeof(struct rte_flow_action) *
5315 (actions_n - sample_action_pos - 1));
5320 * The splitting for metadata feature.
5322 * - Q/RSS action on NIC Rx should be split in order to pass by
5323 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5324 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5326 * - All the actions on NIC Tx should have a mreg copy action to
5327 * copy reg_a from WQE to reg_c[0].
5330 * Pointer to Ethernet device.
5332 * Parent flow structure pointer.
5334 * Flow rule attributes.
5336 * Pattern specification (list terminated by the END pattern item).
5337 * @param[in] actions
5338 * Associated actions (list terminated by the END action).
5339 * @param[in] flow_split_info
5340 * Pointer to flow split info structure.
5342 * Perform verbose error reporting if not NULL.
5344 * 0 on success, negative value otherwise
5347 flow_create_split_metadata(struct rte_eth_dev *dev,
5348 struct rte_flow *flow,
5349 const struct rte_flow_attr *attr,
5350 const struct rte_flow_item items[],
5351 const struct rte_flow_action actions[],
5352 struct mlx5_flow_split_info *flow_split_info,
5353 struct rte_flow_error *error)
5355 struct mlx5_priv *priv = dev->data->dev_private;
5356 struct mlx5_dev_config *config = &priv->config;
5357 const struct rte_flow_action *qrss = NULL;
5358 struct rte_flow_action *ext_actions = NULL;
5359 struct mlx5_flow *dev_flow = NULL;
5360 uint32_t qrss_id = 0;
5367 /* Check whether extensive metadata feature is engaged. */
5368 if (!config->dv_flow_en ||
5369 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5370 !mlx5_flow_ext_mreg_supported(dev))
5371 return flow_create_split_inner(dev, flow, NULL, attr, items,
5372 actions, flow_split_info, error);
5373 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
5376 /* Exclude hairpin flows from splitting. */
5377 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
5378 const struct rte_flow_action_queue *queue;
5381 if (mlx5_rxq_get_type(dev, queue->index) ==
5382 MLX5_RXQ_TYPE_HAIRPIN)
5384 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5385 const struct rte_flow_action_rss *rss;
5388 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5389 MLX5_RXQ_TYPE_HAIRPIN)
5394 /* Check if it is in meter suffix table. */
5395 mtr_sfx = attr->group == (attr->transfer ?
5396 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5397 MLX5_FLOW_TABLE_LEVEL_METER);
5399 * Q/RSS action on NIC Rx should be split in order to pass by
5400 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5401 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5403 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5404 sizeof(struct rte_flow_action_set_tag) +
5405 sizeof(struct rte_flow_action_jump);
5406 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5409 return rte_flow_error_set(error, ENOMEM,
5410 RTE_FLOW_ERROR_TYPE_ACTION,
5411 NULL, "no memory to split "
5414 * If we are the suffix flow of meter, tag already exist.
5415 * Set the tag action to void.
5418 ext_actions[qrss - actions].type =
5419 RTE_FLOW_ACTION_TYPE_VOID;
5421 ext_actions[qrss - actions].type =
5422 (enum rte_flow_action_type)
5423 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5425 * Create the new actions list with removed Q/RSS action
5426 * and appended set tag and jump to register copy table
5427 * (RX_CP_TBL). We should preallocate unique tag ID here
5428 * in advance, because it is needed for set tag action.
5430 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5431 qrss, actions_n, error);
5432 if (!mtr_sfx && !qrss_id) {
5436 } else if (attr->egress && !attr->transfer) {
5438 * All the actions on NIC Tx should have a metadata register
5439 * copy action to copy reg_a from WQE to reg_c[meta]
5441 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5442 sizeof(struct mlx5_flow_action_copy_mreg);
5443 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5446 return rte_flow_error_set(error, ENOMEM,
5447 RTE_FLOW_ERROR_TYPE_ACTION,
5448 NULL, "no memory to split "
5450 /* Create the action list appended with copy register. */
5451 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5452 actions_n, error, encap_idx);
5456 /* Add the unmodified original or prefix subflow. */
5457 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5458 items, ext_actions ? ext_actions :
5459 actions, flow_split_info, error);
5462 MLX5_ASSERT(dev_flow);
5464 const struct rte_flow_attr q_attr = {
5465 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5468 /* Internal PMD action to set register. */
5469 struct mlx5_rte_flow_item_tag q_tag_spec = {
5473 struct rte_flow_item q_items[] = {
5475 .type = (enum rte_flow_item_type)
5476 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5477 .spec = &q_tag_spec,
5482 .type = RTE_FLOW_ITEM_TYPE_END,
5485 struct rte_flow_action q_actions[] = {
5491 .type = RTE_FLOW_ACTION_TYPE_END,
5494 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5497 * Configure the tag item only if there is no meter subflow.
5498 * Since tag is already marked in the meter suffix subflow
5499 * we can just use the meter suffix items as is.
5502 /* Not meter subflow. */
5503 MLX5_ASSERT(!mtr_sfx);
5505 * Put unique id in prefix flow due to it is destroyed
5506 * after suffix flow and id will be freed after there
5507 * is no actual flows with this id and identifier
5508 * reallocation becomes possible (for example, for
5509 * other flows in other threads).
5511 dev_flow->handle->split_flow_id = qrss_id;
5512 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5516 q_tag_spec.id = ret;
5519 /* Add suffix subflow to execute Q/RSS. */
5520 flow_split_info->prefix_layers = layers;
5521 flow_split_info->prefix_mark = 0;
5522 ret = flow_create_split_inner(dev, flow, &dev_flow,
5523 &q_attr, mtr_sfx ? items :
5525 flow_split_info, error);
5528 /* qrss ID should be freed if failed. */
5530 MLX5_ASSERT(dev_flow);
5535 * We do not destroy the partially created sub_flows in case of error.
5536 * These ones are included into parent flow list and will be destroyed
5537 * by flow_drv_destroy.
5539 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5541 mlx5_free(ext_actions);
5546 * Create meter internal drop flow with the original pattern.
5549 * Pointer to Ethernet device.
5551 * Parent flow structure pointer.
5553 * Flow rule attributes.
5555 * Pattern specification (list terminated by the END pattern item).
5556 * @param[in] flow_split_info
5557 * Pointer to flow split info structure.
5559 * Pointer to flow meter structure.
5561 * Perform verbose error reporting if not NULL.
5563 * 0 on success, negative value otherwise
5566 flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
5567 struct rte_flow *flow,
5568 const struct rte_flow_attr *attr,
5569 const struct rte_flow_item items[],
5570 struct mlx5_flow_split_info *flow_split_info,
5571 struct mlx5_flow_meter_info *fm,
5572 struct rte_flow_error *error)
5574 struct mlx5_flow *dev_flow = NULL;
5575 struct rte_flow_attr drop_attr = *attr;
5576 struct rte_flow_action drop_actions[3];
5577 struct mlx5_flow_split_info drop_split_info = *flow_split_info;
5579 MLX5_ASSERT(fm->drop_cnt);
5580 drop_actions[0].type =
5581 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
5582 drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
5583 drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
5584 drop_actions[1].conf = NULL;
5585 drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
5586 drop_actions[2].conf = NULL;
5587 drop_split_info.external = false;
5588 drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5589 drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
5590 drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
5591 return flow_create_split_inner(dev, flow, &dev_flow,
5592 &drop_attr, items, drop_actions,
5593 &drop_split_info, error);
5597 * The splitting for meter feature.
5599 * - The meter flow will be split to two flows as prefix and
5600 * suffix flow. The packets make sense only it pass the prefix
5603 * - Reg_C_5 is used for the packet to match betweend prefix and
5607 * Pointer to Ethernet device.
5609 * Parent flow structure pointer.
5611 * Flow rule attributes.
5613 * Pattern specification (list terminated by the END pattern item).
5614 * @param[in] actions
5615 * Associated actions (list terminated by the END action).
5616 * @param[in] flow_split_info
5617 * Pointer to flow split info structure.
5619 * Perform verbose error reporting if not NULL.
5621 * 0 on success, negative value otherwise
5624 flow_create_split_meter(struct rte_eth_dev *dev,
5625 struct rte_flow *flow,
5626 const struct rte_flow_attr *attr,
5627 const struct rte_flow_item items[],
5628 const struct rte_flow_action actions[],
5629 struct mlx5_flow_split_info *flow_split_info,
5630 struct rte_flow_error *error)
5632 struct mlx5_priv *priv = dev->data->dev_private;
5633 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5634 struct rte_flow_action *sfx_actions = NULL;
5635 struct rte_flow_action *pre_actions = NULL;
5636 struct rte_flow_item *sfx_items = NULL;
5637 struct mlx5_flow *dev_flow = NULL;
5638 struct rte_flow_attr sfx_attr = *attr;
5639 struct mlx5_flow_meter_info *fm = NULL;
5640 uint8_t skip_scale_restore;
5641 bool has_mtr = false;
5642 bool has_modify = false;
5643 bool set_mtr_reg = true;
5644 uint32_t meter_id = 0;
5645 uint32_t mtr_idx = 0;
5646 uint32_t mtr_flow_id = 0;
5653 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
5654 &has_modify, &meter_id);
5657 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
5659 return rte_flow_error_set(error, EINVAL,
5660 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5661 NULL, "Meter not found.");
5663 fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
5665 return rte_flow_error_set(error, EINVAL,
5666 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5667 NULL, "Meter not found.");
5668 ret = mlx5_flow_meter_attach(priv, fm,
5672 flow->meter = mtr_idx;
5677 * If it isn't default-policy Meter, and
5678 * 1. There's no action in flow to change
5679 * packet (modify/encap/decap etc.), OR
5680 * 2. No drop count needed for this meter.
5681 * no need to use regC to save meter id anymore.
5683 if (!fm->def_policy && (!has_modify || !fm->drop_cnt))
5684 set_mtr_reg = false;
5685 /* Prefix actions: meter, decap, encap, tag, jump, end. */
5686 act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
5687 sizeof(struct mlx5_rte_flow_action_set_tag);
5688 /* Suffix items: tag, vlan, port id, end. */
5689 #define METER_SUFFIX_ITEM 4
5690 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5691 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5692 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5695 return rte_flow_error_set(error, ENOMEM,
5696 RTE_FLOW_ERROR_TYPE_ACTION,
5697 NULL, "no memory to split "
5699 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5701 /* There's no suffix flow for meter of non-default policy. */
5702 if (!fm->def_policy)
5703 pre_actions = sfx_actions + 1;
5705 pre_actions = sfx_actions + actions_n;
5706 ret = flow_meter_split_prep(dev, flow, fm, &sfx_attr,
5707 items, sfx_items, actions,
5708 sfx_actions, pre_actions,
5709 (set_mtr_reg ? &mtr_flow_id : NULL),
5715 /* Add the prefix subflow. */
5716 flow_split_info->prefix_mark = 0;
5717 skip_scale_restore = flow_split_info->skip_scale;
5718 flow_split_info->skip_scale |=
5719 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5720 ret = flow_create_split_inner(dev, flow, &dev_flow,
5721 attr, items, pre_actions,
5722 flow_split_info, error);
5723 flow_split_info->skip_scale = skip_scale_restore;
5726 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
5731 dev_flow->handle->split_flow_id = mtr_flow_id;
5732 dev_flow->handle->is_meter_flow_id = 1;
5734 if (!fm->def_policy) {
5735 if (!set_mtr_reg && fm->drop_cnt)
5737 flow_meter_create_drop_flow_with_org_pattern(dev, flow,
5743 /* Setting the sfx group atrr. */
5744 sfx_attr.group = sfx_attr.transfer ?
5745 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
5746 MLX5_FLOW_TABLE_LEVEL_METER;
5747 flow_split_info->prefix_layers =
5748 flow_get_prefix_layer_flags(dev_flow);
5749 flow_split_info->prefix_mark = dev_flow->handle->mark;
5750 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
5752 /* Add the prefix subflow. */
5753 ret = flow_create_split_metadata(dev, flow,
5754 &sfx_attr, sfx_items ?
5756 sfx_actions ? sfx_actions : actions,
5757 flow_split_info, error);
5760 mlx5_free(sfx_actions);
5765 * The splitting for sample feature.
5767 * Once Sample action is detected in the action list, the flow actions should
5768 * be split into prefix sub flow and suffix sub flow.
5770 * The original items remain in the prefix sub flow, all actions preceding the
5771 * sample action and the sample action itself will be copied to the prefix
5772 * sub flow, the actions following the sample action will be copied to the
5773 * suffix sub flow, Queue action always be located in the suffix sub flow.
5775 * In order to make the packet from prefix sub flow matches with suffix sub
5776 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5777 * flow uses tag item with the unique flow id.
5780 * Pointer to Ethernet device.
5782 * Parent flow structure pointer.
5784 * Flow rule attributes.
5786 * Pattern specification (list terminated by the END pattern item).
5787 * @param[in] actions
5788 * Associated actions (list terminated by the END action).
5789 * @param[in] flow_split_info
5790 * Pointer to flow split info structure.
5792 * Perform verbose error reporting if not NULL.
5794 * 0 on success, negative value otherwise
5797 flow_create_split_sample(struct rte_eth_dev *dev,
5798 struct rte_flow *flow,
5799 const struct rte_flow_attr *attr,
5800 const struct rte_flow_item items[],
5801 const struct rte_flow_action actions[],
5802 struct mlx5_flow_split_info *flow_split_info,
5803 struct rte_flow_error *error)
5805 struct mlx5_priv *priv = dev->data->dev_private;
5806 struct rte_flow_action *sfx_actions = NULL;
5807 struct rte_flow_action *pre_actions = NULL;
5808 struct rte_flow_item *sfx_items = NULL;
5809 struct mlx5_flow *dev_flow = NULL;
5810 struct rte_flow_attr sfx_attr = *attr;
5811 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5812 struct mlx5_flow_dv_sample_resource *sample_res;
5813 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
5814 struct mlx5_flow_tbl_resource *sfx_tbl;
5818 uint32_t fdb_tx = 0;
5821 int sample_action_pos;
5822 int qrss_action_pos;
5824 int modify_after_mirror = 0;
5825 uint16_t jump_table = 0;
5826 const uint32_t next_ft_step = 1;
5829 if (priv->sampler_en)
5830 actions_n = flow_check_match_action(actions, attr,
5831 RTE_FLOW_ACTION_TYPE_SAMPLE,
5832 &sample_action_pos, &qrss_action_pos,
5833 &modify_after_mirror);
5835 /* The prefix actions must includes sample, tag, end. */
5836 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
5837 + sizeof(struct mlx5_rte_flow_action_set_tag);
5838 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
5839 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5840 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
5841 item_size), 0, SOCKET_ID_ANY);
5843 return rte_flow_error_set(error, ENOMEM,
5844 RTE_FLOW_ERROR_TYPE_ACTION,
5845 NULL, "no memory to split "
5847 /* The representor_id is -1 for uplink. */
5848 fdb_tx = (attr->transfer && priv->representor_id != -1);
5850 * When reg_c_preserve is set, metadata registers Cx preserve
5851 * their value even through packet duplication.
5853 add_tag = (!fdb_tx || priv->config.hca_attr.reg_c_preserve);
5855 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
5857 if (modify_after_mirror)
5858 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
5860 pre_actions = sfx_actions + actions_n;
5861 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
5862 actions, sfx_actions,
5863 pre_actions, actions_n,
5865 qrss_action_pos, jump_table,
5867 if (tag_id < 0 || (add_tag && !tag_id)) {
5871 if (modify_after_mirror)
5872 flow_split_info->skip_scale =
5873 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5874 /* Add the prefix subflow. */
5875 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5877 flow_split_info, error);
5882 dev_flow->handle->split_flow_id = tag_id;
5883 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5884 if (!modify_after_mirror) {
5885 /* Set the sfx group attr. */
5886 sample_res = (struct mlx5_flow_dv_sample_resource *)
5887 dev_flow->dv.sample_res;
5888 sfx_tbl = (struct mlx5_flow_tbl_resource *)
5889 sample_res->normal_path_tbl;
5890 sfx_tbl_data = container_of(sfx_tbl,
5891 struct mlx5_flow_tbl_data_entry,
5893 sfx_attr.group = sfx_attr.transfer ?
5894 (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
5896 MLX5_ASSERT(attr->transfer);
5897 sfx_attr.group = jump_table;
5899 flow_split_info->prefix_layers =
5900 flow_get_prefix_layer_flags(dev_flow);
5901 flow_split_info->prefix_mark = dev_flow->handle->mark;
5902 /* Suffix group level already be scaled with factor, set
5903 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
5904 * again in translation.
5906 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5909 /* Add the suffix subflow. */
5910 ret = flow_create_split_meter(dev, flow, &sfx_attr,
5911 sfx_items ? sfx_items : items,
5912 sfx_actions ? sfx_actions : actions,
5913 flow_split_info, error);
5916 mlx5_free(sfx_actions);
5921 * Split the flow to subflow set. The splitters might be linked
5922 * in the chain, like this:
5923 * flow_create_split_outer() calls:
5924 * flow_create_split_meter() calls:
5925 * flow_create_split_metadata(meter_subflow_0) calls:
5926 * flow_create_split_inner(metadata_subflow_0)
5927 * flow_create_split_inner(metadata_subflow_1)
5928 * flow_create_split_inner(metadata_subflow_2)
5929 * flow_create_split_metadata(meter_subflow_1) calls:
5930 * flow_create_split_inner(metadata_subflow_0)
5931 * flow_create_split_inner(metadata_subflow_1)
5932 * flow_create_split_inner(metadata_subflow_2)
5934 * This provide flexible way to add new levels of flow splitting.
5935 * The all of successfully created subflows are included to the
5936 * parent flow dev_flow list.
5939 * Pointer to Ethernet device.
5941 * Parent flow structure pointer.
5943 * Flow rule attributes.
5945 * Pattern specification (list terminated by the END pattern item).
5946 * @param[in] actions
5947 * Associated actions (list terminated by the END action).
5948 * @param[in] flow_split_info
5949 * Pointer to flow split info structure.
5951 * Perform verbose error reporting if not NULL.
5953 * 0 on success, negative value otherwise
5956 flow_create_split_outer(struct rte_eth_dev *dev,
5957 struct rte_flow *flow,
5958 const struct rte_flow_attr *attr,
5959 const struct rte_flow_item items[],
5960 const struct rte_flow_action actions[],
5961 struct mlx5_flow_split_info *flow_split_info,
5962 struct rte_flow_error *error)
5966 ret = flow_create_split_sample(dev, flow, attr, items,
5967 actions, flow_split_info, error);
5968 MLX5_ASSERT(ret <= 0);
5972 static inline struct mlx5_flow_tunnel *
5973 flow_tunnel_from_rule(const struct mlx5_flow *flow)
5975 struct mlx5_flow_tunnel *tunnel;
5977 #pragma GCC diagnostic push
5978 #pragma GCC diagnostic ignored "-Wcast-qual"
5979 tunnel = (typeof(tunnel))flow->tunnel;
5980 #pragma GCC diagnostic pop
5986 * Adjust flow RSS workspace if needed.
5989 * Pointer to thread flow work space.
5991 * Pointer to RSS descriptor.
5992 * @param[in] nrssq_num
5993 * New RSS queue number.
5996 * 0 on success, -1 otherwise and rte_errno is set.
5999 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
6000 struct mlx5_flow_rss_desc *rss_desc,
6003 if (likely(nrssq_num <= wks->rssq_num))
6005 rss_desc->queue = realloc(rss_desc->queue,
6006 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
6007 if (!rss_desc->queue) {
6011 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
6016 * Create a flow and add it to @p list.
6019 * Pointer to Ethernet device.
6021 * Pointer to a TAILQ flow list. If this parameter NULL,
6022 * no list insertion occurred, flow is just created,
6023 * this is caller's responsibility to track the
6026 * Flow rule attributes.
6028 * Pattern specification (list terminated by the END pattern item).
6029 * @param[in] actions
6030 * Associated actions (list terminated by the END action).
6031 * @param[in] external
6032 * This flow rule is created by request external to PMD.
6034 * Perform verbose error reporting if not NULL.
6037 * A flow index on success, 0 otherwise and rte_errno is set.
6040 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
6041 const struct rte_flow_attr *attr,
6042 const struct rte_flow_item items[],
6043 const struct rte_flow_action original_actions[],
6044 bool external, struct rte_flow_error *error)
6046 struct mlx5_priv *priv = dev->data->dev_private;
6047 struct rte_flow *flow = NULL;
6048 struct mlx5_flow *dev_flow;
6049 const struct rte_flow_action_rss *rss = NULL;
6050 struct mlx5_translated_action_handle
6051 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6052 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6054 struct mlx5_flow_expand_rss buf;
6055 uint8_t buffer[2048];
6058 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6059 uint8_t buffer[2048];
6062 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
6063 uint8_t buffer[2048];
6064 } actions_hairpin_tx;
6066 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
6067 uint8_t buffer[2048];
6069 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
6070 struct mlx5_flow_rss_desc *rss_desc;
6071 const struct rte_flow_action *p_actions_rx;
6075 struct rte_flow_attr attr_tx = { .priority = 0 };
6076 const struct rte_flow_action *actions;
6077 struct rte_flow_action *translated_actions = NULL;
6078 struct mlx5_flow_tunnel *tunnel;
6079 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
6080 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
6081 struct mlx5_flow_split_info flow_split_info = {
6082 .external = !!external,
6092 rss_desc = &wks->rss_desc;
6093 ret = flow_action_handles_translate(dev, original_actions,
6096 &translated_actions, error);
6098 MLX5_ASSERT(translated_actions == NULL);
6101 actions = translated_actions ? translated_actions : original_actions;
6102 p_actions_rx = actions;
6103 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6104 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
6105 external, hairpin_flow, error);
6107 goto error_before_hairpin_split;
6108 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
6111 goto error_before_hairpin_split;
6113 if (hairpin_flow > 0) {
6114 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
6116 goto error_before_hairpin_split;
6118 flow_hairpin_split(dev, actions, actions_rx.actions,
6119 actions_hairpin_tx.actions, items_tx.items,
6121 p_actions_rx = actions_rx.actions;
6123 flow_split_info.flow_idx = idx;
6124 flow->drv_type = flow_get_drv_type(dev, attr);
6125 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
6126 flow->drv_type < MLX5_FLOW_TYPE_MAX);
6127 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
6128 /* RSS Action only works on NIC RX domain */
6129 if (attr->ingress && !attr->transfer)
6130 rss = flow_get_rss_action(dev, p_actions_rx);
6132 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
6135 * The following information is required by
6136 * mlx5_flow_hashfields_adjust() in advance.
6138 rss_desc->level = rss->level;
6139 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
6140 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
6142 flow->dev_handles = 0;
6143 if (rss && rss->types) {
6144 unsigned int graph_root;
6146 graph_root = find_graph_root(items, rss->level);
6147 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
6149 mlx5_support_expansion, graph_root);
6150 MLX5_ASSERT(ret > 0 &&
6151 (unsigned int)ret < sizeof(expand_buffer.buffer));
6154 buf->entry[0].pattern = (void *)(uintptr_t)items;
6156 rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
6158 for (i = 0; i < buf->entries; ++i) {
6159 /* Initialize flow split data. */
6160 flow_split_info.prefix_layers = 0;
6161 flow_split_info.prefix_mark = 0;
6162 flow_split_info.skip_scale = 0;
6164 * The splitter may create multiple dev_flows,
6165 * depending on configuration. In the simplest
6166 * case it just creates unmodified original flow.
6168 ret = flow_create_split_outer(dev, flow, attr,
6169 buf->entry[i].pattern,
6170 p_actions_rx, &flow_split_info,
6174 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
6175 ret = flow_tunnel_add_default_miss(dev, flow, attr,
6178 wks->flows[0].tunnel,
6182 mlx5_free(default_miss_ctx.queue);
6187 /* Create the tx flow. */
6189 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
6190 attr_tx.ingress = 0;
6192 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
6193 actions_hairpin_tx.actions,
6197 dev_flow->flow = flow;
6198 dev_flow->external = 0;
6199 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
6200 dev_flow->handle, next);
6201 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
6203 actions_hairpin_tx.actions, error);
6208 * Update the metadata register copy table. If extensive
6209 * metadata feature is enabled and registers are supported
6210 * we might create the extra rte_flow for each unique
6211 * MARK/FLAG action ID.
6213 * The table is updated for ingress Flows only, because
6214 * the egress Flows belong to the different device and
6215 * copy table should be updated in peer NIC Rx domain.
6217 if (attr->ingress &&
6218 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
6219 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
6224 * If the flow is external (from application) OR device is started,
6225 * OR mreg discover, then apply immediately.
6227 if (external || dev->data->dev_started ||
6228 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
6229 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
6230 ret = flow_drv_apply(dev, flow, error);
6235 rte_spinlock_lock(&priv->flow_list_lock);
6236 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
6238 rte_spinlock_unlock(&priv->flow_list_lock);
6240 flow_rxq_flags_set(dev, flow);
6241 rte_free(translated_actions);
6242 tunnel = flow_tunnel_from_rule(wks->flows);
6245 flow->tunnel_id = tunnel->tunnel_id;
6246 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
6247 mlx5_free(default_miss_ctx.queue);
6249 mlx5_flow_pop_thread_workspace();
6253 ret = rte_errno; /* Save rte_errno before cleanup. */
6254 flow_mreg_del_copy_action(dev, flow);
6255 flow_drv_destroy(dev, flow);
6256 if (rss_desc->shared_rss)
6257 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
6259 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
6260 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
6261 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
6262 rte_errno = ret; /* Restore rte_errno. */
6265 mlx5_flow_pop_thread_workspace();
6266 error_before_hairpin_split:
6267 rte_free(translated_actions);
6272 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
6273 * incoming packets to table 1.
6275 * Other flow rules, requested for group n, will be created in
6276 * e-switch table n+1.
6277 * Jump action to e-switch group n will be created to group n+1.
6279 * Used when working in switchdev mode, to utilise advantages of table 1
6283 * Pointer to Ethernet device.
6286 * Pointer to flow on success, NULL otherwise and rte_errno is set.
6289 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
6291 const struct rte_flow_attr attr = {
6298 const struct rte_flow_item pattern = {
6299 .type = RTE_FLOW_ITEM_TYPE_END,
6301 struct rte_flow_action_jump jump = {
6304 const struct rte_flow_action actions[] = {
6306 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6310 .type = RTE_FLOW_ACTION_TYPE_END,
6313 struct mlx5_priv *priv = dev->data->dev_private;
6314 struct rte_flow_error error;
6316 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
6318 actions, false, &error);
6322 * Validate a flow supported by the NIC.
6324 * @see rte_flow_validate()
6328 mlx5_flow_validate(struct rte_eth_dev *dev,
6329 const struct rte_flow_attr *attr,
6330 const struct rte_flow_item items[],
6331 const struct rte_flow_action original_actions[],
6332 struct rte_flow_error *error)
6335 struct mlx5_translated_action_handle
6336 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
6337 int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
6338 const struct rte_flow_action *actions;
6339 struct rte_flow_action *translated_actions = NULL;
6340 int ret = flow_action_handles_translate(dev, original_actions,
6343 &translated_actions, error);
6347 actions = translated_actions ? translated_actions : original_actions;
6348 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
6349 ret = flow_drv_validate(dev, attr, items, actions,
6350 true, hairpin_flow, error);
6351 rte_free(translated_actions);
6358 * @see rte_flow_create()
6362 mlx5_flow_create(struct rte_eth_dev *dev,
6363 const struct rte_flow_attr *attr,
6364 const struct rte_flow_item items[],
6365 const struct rte_flow_action actions[],
6366 struct rte_flow_error *error)
6368 struct mlx5_priv *priv = dev->data->dev_private;
6371 * If the device is not started yet, it is not allowed to created a
6372 * flow from application. PMD default flows and traffic control flows
6375 if (unlikely(!dev->data->dev_started)) {
6376 DRV_LOG(DEBUG, "port %u is not started when "
6377 "inserting a flow", dev->data->port_id);
6378 rte_flow_error_set(error, ENODEV,
6379 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6381 "port not started");
6385 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
6386 attr, items, actions, true, error);
6390 * Destroy a flow in a list.
6393 * Pointer to Ethernet device.
6395 * Pointer to the Indexed flow list. If this parameter NULL,
6396 * there is no flow removal from the list. Be noted that as
6397 * flow is add to the indexed list, memory of the indexed
6398 * list points to maybe changed as flow destroyed.
6399 * @param[in] flow_idx
6400 * Index of flow to destroy.
6403 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
6406 struct mlx5_priv *priv = dev->data->dev_private;
6407 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
6408 [MLX5_IPOOL_RTE_FLOW], flow_idx);
6413 * Update RX queue flags only if port is started, otherwise it is
6416 if (dev->data->dev_started)
6417 flow_rxq_flags_trim(dev, flow);
6418 flow_drv_destroy(dev, flow);
6420 rte_spinlock_lock(&priv->flow_list_lock);
6421 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
6422 flow_idx, flow, next);
6423 rte_spinlock_unlock(&priv->flow_list_lock);
6426 struct mlx5_flow_tunnel *tunnel;
6428 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
6430 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
6431 mlx5_flow_tunnel_free(dev, tunnel);
6433 flow_mreg_del_copy_action(dev, flow);
6434 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
6438 * Destroy all flows.
6441 * Pointer to Ethernet device.
6443 * Pointer to the Indexed flow list.
6445 * If flushing is called avtively.
6448 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
6450 uint32_t num_flushed = 0;
6453 flow_list_destroy(dev, list, *list);
6457 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
6458 dev->data->port_id, num_flushed);
6463 * Stop all default actions for flows.
6466 * Pointer to Ethernet device.
6469 mlx5_flow_stop_default(struct rte_eth_dev *dev)
6471 flow_mreg_del_default_copy_action(dev);
6472 flow_rxq_flags_clear(dev);
6476 * Start all default actions for flows.
6479 * Pointer to Ethernet device.
6481 * 0 on success, a negative errno value otherwise and rte_errno is set.
6484 mlx5_flow_start_default(struct rte_eth_dev *dev)
6486 struct rte_flow_error error;
6488 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6489 return flow_mreg_add_default_copy_action(dev, &error);
6493 * Release key of thread specific flow workspace data.
6496 flow_release_workspace(void *data)
6498 struct mlx5_flow_workspace *wks = data;
6499 struct mlx5_flow_workspace *next;
6503 free(wks->rss_desc.queue);
6510 * Get thread specific current flow workspace.
6512 * @return pointer to thread specific flow workspace data, NULL on error.
6514 struct mlx5_flow_workspace*
6515 mlx5_flow_get_thread_workspace(void)
6517 struct mlx5_flow_workspace *data;
6519 data = mlx5_flow_os_get_specific_workspace();
6520 MLX5_ASSERT(data && data->inuse);
6521 if (!data || !data->inuse)
6522 DRV_LOG(ERR, "flow workspace not initialized.");
6527 * Allocate and init new flow workspace.
6529 * @return pointer to flow workspace data, NULL on error.
6531 static struct mlx5_flow_workspace*
6532 flow_alloc_thread_workspace(void)
6534 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
6537 DRV_LOG(ERR, "Failed to allocate flow workspace "
6541 data->rss_desc.queue = calloc(1,
6542 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6543 if (!data->rss_desc.queue)
6545 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6548 if (data->rss_desc.queue)
6549 free(data->rss_desc.queue);
6555 * Get new thread specific flow workspace.
6557 * If current workspace inuse, create new one and set as current.
6559 * @return pointer to thread specific flow workspace data, NULL on error.
6561 static struct mlx5_flow_workspace*
6562 mlx5_flow_push_thread_workspace(void)
6564 struct mlx5_flow_workspace *curr;
6565 struct mlx5_flow_workspace *data;
6567 curr = mlx5_flow_os_get_specific_workspace();
6569 data = flow_alloc_thread_workspace();
6572 } else if (!curr->inuse) {
6574 } else if (curr->next) {
6577 data = flow_alloc_thread_workspace();
6585 /* Set as current workspace */
6586 if (mlx5_flow_os_set_specific_workspace(data))
6587 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6592 * Close current thread specific flow workspace.
6594 * If previous workspace available, set it as current.
6596 * @return pointer to thread specific flow workspace data, NULL on error.
6599 mlx5_flow_pop_thread_workspace(void)
6601 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6606 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6612 if (mlx5_flow_os_set_specific_workspace(data->prev))
6613 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6617 * Verify the flow list is empty
6620 * Pointer to Ethernet device.
6622 * @return the number of flows not released.
6625 mlx5_flow_verify(struct rte_eth_dev *dev)
6627 struct mlx5_priv *priv = dev->data->dev_private;
6628 struct rte_flow *flow;
6632 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
6634 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6635 dev->data->port_id, (void *)flow);
6642 * Enable default hairpin egress flow.
6645 * Pointer to Ethernet device.
6650 * 0 on success, a negative errno value otherwise and rte_errno is set.
6653 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6656 struct mlx5_priv *priv = dev->data->dev_private;
6657 const struct rte_flow_attr attr = {
6661 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6664 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6665 .queue = UINT32_MAX,
6667 struct rte_flow_item items[] = {
6669 .type = (enum rte_flow_item_type)
6670 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6671 .spec = &queue_spec,
6673 .mask = &queue_mask,
6676 .type = RTE_FLOW_ITEM_TYPE_END,
6679 struct rte_flow_action_jump jump = {
6680 .group = MLX5_HAIRPIN_TX_TABLE,
6682 struct rte_flow_action actions[2];
6684 struct rte_flow_error error;
6686 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6687 actions[0].conf = &jump;
6688 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6689 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6690 &attr, items, actions, false, &error);
6693 "Failed to create ctrl flow: rte_errno(%d),"
6694 " type(%d), message(%s)",
6695 rte_errno, error.type,
6696 error.message ? error.message : " (no stated reason)");
6703 * Enable a control flow configured from the control plane.
6706 * Pointer to Ethernet device.
6708 * An Ethernet flow spec to apply.
6710 * An Ethernet flow mask to apply.
6712 * A VLAN flow spec to apply.
6714 * A VLAN flow mask to apply.
6717 * 0 on success, a negative errno value otherwise and rte_errno is set.
6720 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6721 struct rte_flow_item_eth *eth_spec,
6722 struct rte_flow_item_eth *eth_mask,
6723 struct rte_flow_item_vlan *vlan_spec,
6724 struct rte_flow_item_vlan *vlan_mask)
6726 struct mlx5_priv *priv = dev->data->dev_private;
6727 const struct rte_flow_attr attr = {
6729 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6731 struct rte_flow_item items[] = {
6733 .type = RTE_FLOW_ITEM_TYPE_ETH,
6739 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6740 RTE_FLOW_ITEM_TYPE_END,
6746 .type = RTE_FLOW_ITEM_TYPE_END,
6749 uint16_t queue[priv->reta_idx_n];
6750 struct rte_flow_action_rss action_rss = {
6751 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6753 .types = priv->rss_conf.rss_hf,
6754 .key_len = priv->rss_conf.rss_key_len,
6755 .queue_num = priv->reta_idx_n,
6756 .key = priv->rss_conf.rss_key,
6759 struct rte_flow_action actions[] = {
6761 .type = RTE_FLOW_ACTION_TYPE_RSS,
6762 .conf = &action_rss,
6765 .type = RTE_FLOW_ACTION_TYPE_END,
6769 struct rte_flow_error error;
6772 if (!priv->reta_idx_n || !priv->rxqs_n) {
6775 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6776 action_rss.types = 0;
6777 for (i = 0; i != priv->reta_idx_n; ++i)
6778 queue[i] = (*priv->reta_idx)[i];
6779 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6780 &attr, items, actions, false, &error);
6787 * Enable a flow control configured from the control plane.
6790 * Pointer to Ethernet device.
6792 * An Ethernet flow spec to apply.
6794 * An Ethernet flow mask to apply.
6797 * 0 on success, a negative errno value otherwise and rte_errno is set.
6800 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6801 struct rte_flow_item_eth *eth_spec,
6802 struct rte_flow_item_eth *eth_mask)
6804 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6808 * Create default miss flow rule matching lacp traffic
6811 * Pointer to Ethernet device.
6813 * An Ethernet flow spec to apply.
6816 * 0 on success, a negative errno value otherwise and rte_errno is set.
6819 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6821 struct mlx5_priv *priv = dev->data->dev_private;
6823 * The LACP matching is done by only using ether type since using
6824 * a multicast dst mac causes kernel to give low priority to this flow.
6826 static const struct rte_flow_item_eth lacp_spec = {
6827 .type = RTE_BE16(0x8809),
6829 static const struct rte_flow_item_eth lacp_mask = {
6832 const struct rte_flow_attr attr = {
6835 struct rte_flow_item items[] = {
6837 .type = RTE_FLOW_ITEM_TYPE_ETH,
6842 .type = RTE_FLOW_ITEM_TYPE_END,
6845 struct rte_flow_action actions[] = {
6847 .type = (enum rte_flow_action_type)
6848 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
6851 .type = RTE_FLOW_ACTION_TYPE_END,
6854 struct rte_flow_error error;
6855 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6856 &attr, items, actions, false, &error);
6866 * @see rte_flow_destroy()
6870 mlx5_flow_destroy(struct rte_eth_dev *dev,
6871 struct rte_flow *flow,
6872 struct rte_flow_error *error __rte_unused)
6874 struct mlx5_priv *priv = dev->data->dev_private;
6876 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
6881 * Destroy all flows.
6883 * @see rte_flow_flush()
6887 mlx5_flow_flush(struct rte_eth_dev *dev,
6888 struct rte_flow_error *error __rte_unused)
6890 struct mlx5_priv *priv = dev->data->dev_private;
6892 mlx5_flow_list_flush(dev, &priv->flows, false);
6899 * @see rte_flow_isolate()
6903 mlx5_flow_isolate(struct rte_eth_dev *dev,
6905 struct rte_flow_error *error)
6907 struct mlx5_priv *priv = dev->data->dev_private;
6909 if (dev->data->dev_started) {
6910 rte_flow_error_set(error, EBUSY,
6911 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6913 "port must be stopped first");
6916 priv->isolated = !!enable;
6918 dev->dev_ops = &mlx5_dev_ops_isolate;
6920 dev->dev_ops = &mlx5_dev_ops;
6922 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
6923 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
6931 * @see rte_flow_query()
6935 flow_drv_query(struct rte_eth_dev *dev,
6937 const struct rte_flow_action *actions,
6939 struct rte_flow_error *error)
6941 struct mlx5_priv *priv = dev->data->dev_private;
6942 const struct mlx5_flow_driver_ops *fops;
6943 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
6944 [MLX5_IPOOL_RTE_FLOW],
6946 enum mlx5_flow_drv_type ftype;
6949 return rte_flow_error_set(error, ENOENT,
6950 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6952 "invalid flow handle");
6954 ftype = flow->drv_type;
6955 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
6956 fops = flow_get_drv_ops(ftype);
6958 return fops->query(dev, flow, actions, data, error);
6964 * @see rte_flow_query()
6968 mlx5_flow_query(struct rte_eth_dev *dev,
6969 struct rte_flow *flow,
6970 const struct rte_flow_action *actions,
6972 struct rte_flow_error *error)
6976 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
6984 * Get rte_flow callbacks.
6987 * Pointer to Ethernet device structure.
6989 * Pointer to operation-specific structure.
6994 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
6995 const struct rte_flow_ops **ops)
6997 *ops = &mlx5_flow_ops;
7002 * Validate meter policy actions.
7003 * Dispatcher for action type specific validation.
7006 * Pointer to the Ethernet device structure.
7008 * The meter policy action object to validate.
7010 * Attributes of flow to determine steering domain.
7011 * @param[out] is_rss
7013 * @param[out] domain_bitmap
7015 * @param[out] is_def_policy
7016 * Is default policy or not.
7018 * Perform verbose error reporting if not NULL. Initialized in case of
7022 * 0 on success, otherwise negative errno value.
7025 mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
7026 const struct rte_flow_action *actions[RTE_COLORS],
7027 struct rte_flow_attr *attr,
7029 uint8_t *domain_bitmap,
7030 bool *is_def_policy,
7031 struct rte_mtr_error *error)
7033 const struct mlx5_flow_driver_ops *fops;
7035 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7036 return fops->validate_mtr_acts(dev, actions, attr,
7037 is_rss, domain_bitmap, is_def_policy, error);
7041 * Destroy the meter table set.
7044 * Pointer to Ethernet device.
7045 * @param[in] mtr_policy
7046 * Meter policy struct.
7049 mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
7050 struct mlx5_flow_meter_policy *mtr_policy)
7052 const struct mlx5_flow_driver_ops *fops;
7054 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7055 fops->destroy_mtr_acts(dev, mtr_policy);
7059 * Create policy action, lock free,
7060 * (mutex should be acquired by caller).
7061 * Dispatcher for action type specific call.
7064 * Pointer to the Ethernet device structure.
7065 * @param[in] mtr_policy
7066 * Meter policy struct.
7068 * Action specification used to create meter actions.
7070 * Perform verbose error reporting if not NULL. Initialized in case of
7074 * 0 on success, otherwise negative errno value.
7077 mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
7078 struct mlx5_flow_meter_policy *mtr_policy,
7079 const struct rte_flow_action *actions[RTE_COLORS],
7080 struct rte_mtr_error *error)
7082 const struct mlx5_flow_driver_ops *fops;
7084 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7085 return fops->create_mtr_acts(dev, mtr_policy, actions, error);
7089 * Create policy rules, lock free,
7090 * (mutex should be acquired by caller).
7091 * Dispatcher for action type specific call.
7094 * Pointer to the Ethernet device structure.
7095 * @param[in] mtr_policy
7096 * Meter policy struct.
7099 * 0 on success, -1 otherwise.
7102 mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
7103 struct mlx5_flow_meter_policy *mtr_policy)
7105 const struct mlx5_flow_driver_ops *fops;
7107 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7108 return fops->create_policy_rules(dev, mtr_policy);
7112 * Destroy policy rules, lock free,
7113 * (mutex should be acquired by caller).
7114 * Dispatcher for action type specific call.
7117 * Pointer to the Ethernet device structure.
7118 * @param[in] mtr_policy
7119 * Meter policy struct.
7122 mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
7123 struct mlx5_flow_meter_policy *mtr_policy)
7125 const struct mlx5_flow_driver_ops *fops;
7127 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7128 fops->destroy_policy_rules(dev, mtr_policy);
7132 * Destroy the default policy table set.
7135 * Pointer to Ethernet device.
7138 mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
7140 const struct mlx5_flow_driver_ops *fops;
7142 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7143 fops->destroy_def_policy(dev);
7147 * Destroy the default policy table set.
7150 * Pointer to Ethernet device.
7153 * 0 on success, -1 otherwise.
7156 mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
7158 const struct mlx5_flow_driver_ops *fops;
7160 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7161 return fops->create_def_policy(dev);
7165 * Create the needed meter and suffix tables.
7168 * Pointer to Ethernet device.
7171 * 0 on success, -1 otherwise.
7174 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
7175 struct mlx5_flow_meter_info *fm,
7177 uint8_t domain_bitmap)
7179 const struct mlx5_flow_driver_ops *fops;
7181 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7182 return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
7186 * Destroy the meter table set.
7189 * Pointer to Ethernet device.
7191 * Pointer to the meter table set.
7194 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
7195 struct mlx5_flow_meter_info *fm)
7197 const struct mlx5_flow_driver_ops *fops;
7199 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7200 fops->destroy_mtr_tbls(dev, fm);
7204 * Destroy the global meter drop table.
7207 * Pointer to Ethernet device.
7210 mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
7212 const struct mlx5_flow_driver_ops *fops;
7214 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7215 fops->destroy_mtr_drop_tbls(dev);
7219 * Allocate the needed aso flow meter id.
7222 * Pointer to Ethernet device.
7225 * Index to aso flow meter on success, NULL otherwise.
7228 mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
7230 const struct mlx5_flow_driver_ops *fops;
7232 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7233 return fops->create_meter(dev);
7237 * Free the aso flow meter id.
7240 * Pointer to Ethernet device.
7241 * @param[in] mtr_idx
7242 * Index to aso flow meter to be free.
7248 mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
7250 const struct mlx5_flow_driver_ops *fops;
7252 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7253 fops->free_meter(dev, mtr_idx);
7257 * Allocate a counter.
7260 * Pointer to Ethernet device structure.
7263 * Index to allocated counter on success, 0 otherwise.
7266 mlx5_counter_alloc(struct rte_eth_dev *dev)
7268 const struct mlx5_flow_driver_ops *fops;
7269 struct rte_flow_attr attr = { .transfer = 0 };
7271 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7272 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7273 return fops->counter_alloc(dev);
7276 "port %u counter allocate is not supported.",
7277 dev->data->port_id);
7285 * Pointer to Ethernet device structure.
7287 * Index to counter to be free.
7290 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
7292 const struct mlx5_flow_driver_ops *fops;
7293 struct rte_flow_attr attr = { .transfer = 0 };
7295 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7296 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7297 fops->counter_free(dev, cnt);
7301 "port %u counter free is not supported.",
7302 dev->data->port_id);
7306 * Query counter statistics.
7309 * Pointer to Ethernet device structure.
7311 * Index to counter to query.
7313 * Set to clear counter statistics.
7315 * The counter hits packets number to save.
7317 * The counter hits bytes number to save.
7320 * 0 on success, a negative errno value otherwise.
7323 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
7324 bool clear, uint64_t *pkts, uint64_t *bytes)
7326 const struct mlx5_flow_driver_ops *fops;
7327 struct rte_flow_attr attr = { .transfer = 0 };
7329 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7330 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7331 return fops->counter_query(dev, cnt, clear, pkts, bytes);
7334 "port %u counter query is not supported.",
7335 dev->data->port_id);
7340 * Allocate a new memory for the counter values wrapped by all the needed
7344 * Pointer to mlx5_dev_ctx_shared object.
7347 * 0 on success, a negative errno value otherwise.
7350 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
7352 struct mlx5_devx_mkey_attr mkey_attr;
7353 struct mlx5_counter_stats_mem_mng *mem_mng;
7354 volatile struct flow_counter_stats *raw_data;
7355 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
7356 int size = (sizeof(struct flow_counter_stats) *
7357 MLX5_COUNTERS_PER_POOL +
7358 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
7359 sizeof(struct mlx5_counter_stats_mem_mng);
7360 size_t pgsize = rte_mem_page_size();
7364 if (pgsize == (size_t)-1) {
7365 DRV_LOG(ERR, "Failed to get mem page size");
7369 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
7374 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
7375 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
7376 mem_mng->umem = mlx5_os_umem_reg(sh->ctx, mem, size,
7377 IBV_ACCESS_LOCAL_WRITE);
7378 if (!mem_mng->umem) {
7383 memset(&mkey_attr, 0, sizeof(mkey_attr));
7384 mkey_attr.addr = (uintptr_t)mem;
7385 mkey_attr.size = size;
7386 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
7387 mkey_attr.pd = sh->pdn;
7388 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
7389 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
7390 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
7392 mlx5_os_umem_dereg(mem_mng->umem);
7397 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
7398 raw_data = (volatile struct flow_counter_stats *)mem;
7399 for (i = 0; i < raws_n; ++i) {
7400 mem_mng->raws[i].mem_mng = mem_mng;
7401 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
7403 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
7404 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
7405 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
7407 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
7408 sh->cmng.mem_mng = mem_mng;
7413 * Set the statistic memory to the new counter pool.
7416 * Pointer to mlx5_dev_ctx_shared object.
7418 * Pointer to the pool to set the statistic memory.
7421 * 0 on success, a negative errno value otherwise.
7424 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
7425 struct mlx5_flow_counter_pool *pool)
7427 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7428 /* Resize statistic memory once used out. */
7429 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
7430 mlx5_flow_create_counter_stat_mem_mng(sh)) {
7431 DRV_LOG(ERR, "Cannot resize counter stat mem.");
7434 rte_spinlock_lock(&pool->sl);
7435 pool->raw = cmng->mem_mng->raws + pool->index %
7436 MLX5_CNT_CONTAINER_RESIZE;
7437 rte_spinlock_unlock(&pool->sl);
7438 pool->raw_hw = NULL;
7442 #define MLX5_POOL_QUERY_FREQ_US 1000000
7445 * Set the periodic procedure for triggering asynchronous batch queries for all
7446 * the counter pools.
7449 * Pointer to mlx5_dev_ctx_shared object.
7452 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
7454 uint32_t pools_n, us;
7456 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
7457 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
7458 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
7459 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
7460 sh->cmng.query_thread_on = 0;
7461 DRV_LOG(ERR, "Cannot reinitialize query alarm");
7463 sh->cmng.query_thread_on = 1;
7468 * The periodic procedure for triggering asynchronous batch queries for all the
7469 * counter pools. This function is probably called by the host thread.
7472 * The parameter for the alarm process.
7475 mlx5_flow_query_alarm(void *arg)
7477 struct mlx5_dev_ctx_shared *sh = arg;
7479 uint16_t pool_index = sh->cmng.pool_index;
7480 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7481 struct mlx5_flow_counter_pool *pool;
7484 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
7486 rte_spinlock_lock(&cmng->pool_update_sl);
7487 pool = cmng->pools[pool_index];
7488 n_valid = cmng->n_valid;
7489 rte_spinlock_unlock(&cmng->pool_update_sl);
7490 /* Set the statistic memory to the new created pool. */
7491 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
7494 /* There is a pool query in progress. */
7497 LIST_FIRST(&sh->cmng.free_stat_raws);
7499 /* No free counter statistics raw memory. */
7502 * Identify the counters released between query trigger and query
7503 * handle more efficiently. The counter released in this gap period
7504 * should wait for a new round of query as the new arrived packets
7505 * will not be taken into account.
7508 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
7509 MLX5_COUNTERS_PER_POOL,
7511 pool->raw_hw->mem_mng->dm->id,
7515 (uint64_t)(uintptr_t)pool);
7517 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
7518 " %d", pool->min_dcs->id);
7519 pool->raw_hw = NULL;
7522 LIST_REMOVE(pool->raw_hw, next);
7523 sh->cmng.pending_queries++;
7525 if (pool_index >= n_valid)
7528 sh->cmng.pool_index = pool_index;
7529 mlx5_set_query_alarm(sh);
7533 * Check and callback event for new aged flow in the counter pool
7536 * Pointer to mlx5_dev_ctx_shared object.
7538 * Pointer to Current counter pool.
7541 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
7542 struct mlx5_flow_counter_pool *pool)
7544 struct mlx5_priv *priv;
7545 struct mlx5_flow_counter *cnt;
7546 struct mlx5_age_info *age_info;
7547 struct mlx5_age_param *age_param;
7548 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
7549 struct mlx5_counter_stats_raw *prev = pool->raw;
7550 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
7551 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
7552 uint16_t expected = AGE_CANDIDATE;
7555 pool->time_of_last_age_check = curr_time;
7556 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
7557 cnt = MLX5_POOL_GET_CNT(pool, i);
7558 age_param = MLX5_CNT_TO_AGE(cnt);
7559 if (__atomic_load_n(&age_param->state,
7560 __ATOMIC_RELAXED) != AGE_CANDIDATE)
7562 if (cur->data[i].hits != prev->data[i].hits) {
7563 __atomic_store_n(&age_param->sec_since_last_hit, 0,
7567 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
7569 __ATOMIC_RELAXED) <= age_param->timeout)
7572 * Hold the lock first, or if between the
7573 * state AGE_TMOUT and tailq operation the
7574 * release happened, the release procedure
7575 * may delete a non-existent tailq node.
7577 priv = rte_eth_devices[age_param->port_id].data->dev_private;
7578 age_info = GET_PORT_AGE_INFO(priv);
7579 rte_spinlock_lock(&age_info->aged_sl);
7580 if (__atomic_compare_exchange_n(&age_param->state, &expected,
7583 __ATOMIC_RELAXED)) {
7584 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
7585 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
7587 rte_spinlock_unlock(&age_info->aged_sl);
7589 mlx5_age_event_prepare(sh);
7593 * Handler for the HW respond about ready values from an asynchronous batch
7594 * query. This function is probably called by the host thread.
7597 * The pointer to the shared device context.
7598 * @param[in] async_id
7599 * The Devx async ID.
7601 * The status of the completion.
7604 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
7605 uint64_t async_id, int status)
7607 struct mlx5_flow_counter_pool *pool =
7608 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
7609 struct mlx5_counter_stats_raw *raw_to_free;
7610 uint8_t query_gen = pool->query_gen ^ 1;
7611 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
7612 enum mlx5_counter_type cnt_type =
7613 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7614 MLX5_COUNTER_TYPE_ORIGIN;
7616 if (unlikely(status)) {
7617 raw_to_free = pool->raw_hw;
7619 raw_to_free = pool->raw;
7621 mlx5_flow_aging_check(sh, pool);
7622 rte_spinlock_lock(&pool->sl);
7623 pool->raw = pool->raw_hw;
7624 rte_spinlock_unlock(&pool->sl);
7625 /* Be sure the new raw counters data is updated in memory. */
7627 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
7628 rte_spinlock_lock(&cmng->csl[cnt_type]);
7629 TAILQ_CONCAT(&cmng->counters[cnt_type],
7630 &pool->counters[query_gen], next);
7631 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7634 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7635 pool->raw_hw = NULL;
7636 sh->cmng.pending_queries--;
7640 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7641 const struct flow_grp_info *grp_info,
7642 struct rte_flow_error *error)
7644 if (grp_info->transfer && grp_info->external &&
7645 grp_info->fdb_def_rule) {
7646 if (group == UINT32_MAX)
7647 return rte_flow_error_set
7649 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7651 "group index not supported");
7656 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7661 * Translate the rte_flow group index to HW table value.
7663 * If tunnel offload is disabled, all group ids converted to flow table
7664 * id using the standard method.
7665 * If tunnel offload is enabled, group id can be converted using the
7666 * standard or tunnel conversion method. Group conversion method
7667 * selection depends on flags in `grp_info` parameter:
7668 * - Internal (grp_info.external == 0) groups conversion uses the
7670 * - Group ids in JUMP action converted with the tunnel conversion.
7671 * - Group id in rule attribute conversion depends on a rule type and
7673 * ** non zero group attributes converted with the tunnel method
7674 * ** zero group attribute in non-tunnel rule is converted using the
7675 * standard method - there's only one root table
7676 * ** zero group attribute in steer tunnel rule is converted with the
7677 * standard method - single root table
7678 * ** zero group attribute in match tunnel rule is a special OvS
7679 * case: that value is used for portability reasons. That group
7680 * id is converted with the tunnel conversion method.
7685 * PMD tunnel offload object
7687 * rte_flow group index value.
7690 * @param[in] grp_info
7691 * flags used for conversion
7693 * Pointer to error structure.
7696 * 0 on success, a negative errno value otherwise and rte_errno is set.
7699 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7700 const struct mlx5_flow_tunnel *tunnel,
7701 uint32_t group, uint32_t *table,
7702 const struct flow_grp_info *grp_info,
7703 struct rte_flow_error *error)
7706 bool standard_translation;
7708 if (!grp_info->skip_scale && grp_info->external &&
7709 group < MLX5_MAX_TABLES_EXTERNAL)
7710 group *= MLX5_FLOW_TABLE_FACTOR;
7711 if (is_tunnel_offload_active(dev)) {
7712 standard_translation = !grp_info->external ||
7713 grp_info->std_tbl_fix;
7715 standard_translation = true;
7718 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
7719 dev->data->port_id, group, grp_info->transfer,
7720 grp_info->external, grp_info->fdb_def_rule,
7721 standard_translation ? "STANDARD" : "TUNNEL");
7722 if (standard_translation)
7723 ret = flow_group_to_table(dev->data->port_id, group, table,
7726 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7733 * Discover availability of metadata reg_c's.
7735 * Iteratively use test flows to check availability.
7738 * Pointer to the Ethernet device structure.
7741 * 0 on success, a negative errno value otherwise and rte_errno is set.
7744 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7746 struct mlx5_priv *priv = dev->data->dev_private;
7747 struct mlx5_dev_config *config = &priv->config;
7748 enum modify_reg idx;
7751 /* reg_c[0] and reg_c[1] are reserved. */
7752 config->flow_mreg_c[n++] = REG_C_0;
7753 config->flow_mreg_c[n++] = REG_C_1;
7754 /* Discover availability of other reg_c's. */
7755 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7756 struct rte_flow_attr attr = {
7757 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7758 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7761 struct rte_flow_item items[] = {
7763 .type = RTE_FLOW_ITEM_TYPE_END,
7766 struct rte_flow_action actions[] = {
7768 .type = (enum rte_flow_action_type)
7769 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7770 .conf = &(struct mlx5_flow_action_copy_mreg){
7776 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7777 .conf = &(struct rte_flow_action_jump){
7778 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7782 .type = RTE_FLOW_ACTION_TYPE_END,
7786 struct rte_flow *flow;
7787 struct rte_flow_error error;
7789 if (!config->dv_flow_en)
7791 /* Create internal flow, validation skips copy action. */
7792 flow_idx = flow_list_create(dev, NULL, &attr, items,
7793 actions, false, &error);
7794 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
7798 config->flow_mreg_c[n++] = idx;
7799 flow_list_destroy(dev, NULL, flow_idx);
7801 for (; n < MLX5_MREG_C_NUM; ++n)
7802 config->flow_mreg_c[n] = REG_NON;
7807 * Dump flow raw hw data to file
7810 * The pointer to Ethernet device.
7812 * A pointer to a file for output.
7814 * Perform verbose error reporting if not NULL. PMDs initialize this
7815 * structure in case of error only.
7817 * 0 on success, a nagative value otherwise.
7820 mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
7822 struct rte_flow_error *error __rte_unused)
7824 struct mlx5_priv *priv = dev->data->dev_private;
7825 struct mlx5_dev_ctx_shared *sh = priv->sh;
7826 uint32_t handle_idx;
7828 struct mlx5_flow_handle *dh;
7829 struct rte_flow *flow;
7831 if (!priv->config.dv_flow_en) {
7832 if (fputs("device dv flow disabled\n", file) <= 0)
7839 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
7841 sh->tx_domain, file);
7843 flow = mlx5_ipool_get(priv->sh->ipool
7844 [MLX5_IPOOL_RTE_FLOW], (uintptr_t)(void *)flow_idx);
7848 handle_idx = flow->dev_handles;
7849 while (handle_idx) {
7850 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
7855 ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
7860 handle_idx = dh->next.next;
7866 * Get aged-out flows.
7869 * Pointer to the Ethernet device structure.
7870 * @param[in] context
7871 * The address of an array of pointers to the aged-out flows contexts.
7872 * @param[in] nb_countexts
7873 * The length of context array pointers.
7875 * Perform verbose error reporting if not NULL. Initialized in case of
7879 * how many contexts get in success, otherwise negative errno value.
7880 * if nb_contexts is 0, return the amount of all aged contexts.
7881 * if nb_contexts is not 0 , return the amount of aged flows reported
7882 * in the context array.
7885 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
7886 uint32_t nb_contexts, struct rte_flow_error *error)
7888 const struct mlx5_flow_driver_ops *fops;
7889 struct rte_flow_attr attr = { .transfer = 0 };
7891 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7892 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7893 return fops->get_aged_flows(dev, contexts, nb_contexts,
7897 "port %u get aged flows is not supported.",
7898 dev->data->port_id);
7902 /* Wrapper for driver action_validate op callback */
7904 flow_drv_action_validate(struct rte_eth_dev *dev,
7905 const struct rte_flow_indir_action_conf *conf,
7906 const struct rte_flow_action *action,
7907 const struct mlx5_flow_driver_ops *fops,
7908 struct rte_flow_error *error)
7910 static const char err_msg[] = "indirect action validation unsupported";
7912 if (!fops->action_validate) {
7913 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7914 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7918 return fops->action_validate(dev, conf, action, error);
7922 * Destroys the shared action by handle.
7925 * Pointer to Ethernet device structure.
7927 * Handle for the indirect action object to be destroyed.
7929 * Perform verbose error reporting if not NULL. PMDs initialize this
7930 * structure in case of error only.
7933 * 0 on success, a negative errno value otherwise and rte_errno is set.
7935 * @note: wrapper for driver action_create op callback.
7938 mlx5_action_handle_destroy(struct rte_eth_dev *dev,
7939 struct rte_flow_action_handle *handle,
7940 struct rte_flow_error *error)
7942 static const char err_msg[] = "indirect action destruction unsupported";
7943 struct rte_flow_attr attr = { .transfer = 0 };
7944 const struct mlx5_flow_driver_ops *fops =
7945 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7947 if (!fops->action_destroy) {
7948 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7949 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7953 return fops->action_destroy(dev, handle, error);
7956 /* Wrapper for driver action_destroy op callback */
7958 flow_drv_action_update(struct rte_eth_dev *dev,
7959 struct rte_flow_action_handle *handle,
7961 const struct mlx5_flow_driver_ops *fops,
7962 struct rte_flow_error *error)
7964 static const char err_msg[] = "indirect action update unsupported";
7966 if (!fops->action_update) {
7967 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7968 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7972 return fops->action_update(dev, handle, update, error);
7975 /* Wrapper for driver action_destroy op callback */
7977 flow_drv_action_query(struct rte_eth_dev *dev,
7978 const struct rte_flow_action_handle *handle,
7980 const struct mlx5_flow_driver_ops *fops,
7981 struct rte_flow_error *error)
7983 static const char err_msg[] = "indirect action query unsupported";
7985 if (!fops->action_query) {
7986 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7987 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7991 return fops->action_query(dev, handle, data, error);
7995 * Create indirect action for reuse in multiple flow rules.
7998 * Pointer to Ethernet device structure.
8000 * Pointer to indirect action object configuration.
8002 * Action configuration for indirect action object creation.
8004 * Perform verbose error reporting if not NULL. PMDs initialize this
8005 * structure in case of error only.
8007 * A valid handle in case of success, NULL otherwise and rte_errno is set.
8009 static struct rte_flow_action_handle *
8010 mlx5_action_handle_create(struct rte_eth_dev *dev,
8011 const struct rte_flow_indir_action_conf *conf,
8012 const struct rte_flow_action *action,
8013 struct rte_flow_error *error)
8015 static const char err_msg[] = "indirect action creation unsupported";
8016 struct rte_flow_attr attr = { .transfer = 0 };
8017 const struct mlx5_flow_driver_ops *fops =
8018 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8020 if (flow_drv_action_validate(dev, conf, action, fops, error))
8022 if (!fops->action_create) {
8023 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
8024 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8028 return fops->action_create(dev, conf, action, error);
8032 * Updates inplace the indirect action configuration pointed by *handle*
8033 * with the configuration provided as *update* argument.
8034 * The update of the indirect action configuration effects all flow rules
8035 * reusing the action via handle.
8038 * Pointer to Ethernet device structure.
8040 * Handle for the indirect action to be updated.
8042 * Action specification used to modify the action pointed by handle.
8043 * *update* could be of same type with the action pointed by the *handle*
8044 * handle argument, or some other structures like a wrapper, depending on
8045 * the indirect action type.
8047 * Perform verbose error reporting if not NULL. PMDs initialize this
8048 * structure in case of error only.
8051 * 0 on success, a negative errno value otherwise and rte_errno is set.
8054 mlx5_action_handle_update(struct rte_eth_dev *dev,
8055 struct rte_flow_action_handle *handle,
8057 struct rte_flow_error *error)
8059 struct rte_flow_attr attr = { .transfer = 0 };
8060 const struct mlx5_flow_driver_ops *fops =
8061 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8064 ret = flow_drv_action_validate(dev, NULL,
8065 (const struct rte_flow_action *)update, fops, error);
8068 return flow_drv_action_update(dev, handle, update, fops,
8073 * Query the indirect action by handle.
8075 * This function allows retrieving action-specific data such as counters.
8076 * Data is gathered by special action which may be present/referenced in
8077 * more than one flow rule definition.
8079 * see @RTE_FLOW_ACTION_TYPE_COUNT
8082 * Pointer to Ethernet device structure.
8084 * Handle for the indirect action to query.
8085 * @param[in, out] data
8086 * Pointer to storage for the associated query data type.
8088 * Perform verbose error reporting if not NULL. PMDs initialize this
8089 * structure in case of error only.
8092 * 0 on success, a negative errno value otherwise and rte_errno is set.
8095 mlx5_action_handle_query(struct rte_eth_dev *dev,
8096 const struct rte_flow_action_handle *handle,
8098 struct rte_flow_error *error)
8100 struct rte_flow_attr attr = { .transfer = 0 };
8101 const struct mlx5_flow_driver_ops *fops =
8102 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8104 return flow_drv_action_query(dev, handle, data, fops, error);
8108 * Destroy all indirect actions (shared RSS).
8111 * Pointer to Ethernet device.
8114 * 0 on success, a negative errno value otherwise and rte_errno is set.
8117 mlx5_action_handle_flush(struct rte_eth_dev *dev)
8119 struct rte_flow_error error;
8120 struct mlx5_priv *priv = dev->data->dev_private;
8121 struct mlx5_shared_action_rss *shared_rss;
8125 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
8126 priv->rss_shared_actions, idx, shared_rss, next) {
8127 ret |= mlx5_action_handle_destroy(dev,
8128 (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
8133 #ifndef HAVE_MLX5DV_DR
8134 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
8136 #define MLX5_DOMAIN_SYNC_FLOW \
8137 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
8140 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
8142 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
8143 const struct mlx5_flow_driver_ops *fops;
8145 struct rte_flow_attr attr = { .transfer = 0 };
8147 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
8148 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
8154 const struct mlx5_flow_tunnel *
8155 mlx5_get_tof(const struct rte_flow_item *item,
8156 const struct rte_flow_action *action,
8157 enum mlx5_tof_rule_type *rule_type)
8159 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
8160 if (item->type == (typeof(item->type))
8161 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
8162 *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
8163 return flow_items_to_tunnel(item);
8166 for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
8167 if (action->type == (typeof(action->type))
8168 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
8169 *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
8170 return flow_actions_to_tunnel(action);
8177 * tunnel offload functionalilty is defined for DV environment only
8179 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8181 union tunnel_offload_mark {
8184 uint32_t app_reserve:8;
8185 uint32_t table_id:15;
8186 uint32_t transfer:1;
8187 uint32_t _unused_:8;
8192 mlx5_access_tunnel_offload_db
8193 (struct rte_eth_dev *dev,
8194 bool (*match)(struct rte_eth_dev *,
8195 struct mlx5_flow_tunnel *, const void *),
8196 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8197 void (*miss)(struct rte_eth_dev *, void *),
8198 void *ctx, bool lock_op);
8201 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
8202 struct rte_flow *flow,
8203 const struct rte_flow_attr *attr,
8204 const struct rte_flow_action *app_actions,
8206 const struct mlx5_flow_tunnel *tunnel,
8207 struct tunnel_default_miss_ctx *ctx,
8208 struct rte_flow_error *error)
8210 struct mlx5_priv *priv = dev->data->dev_private;
8211 struct mlx5_flow *dev_flow;
8212 struct rte_flow_attr miss_attr = *attr;
8213 const struct rte_flow_item miss_items[2] = {
8215 .type = RTE_FLOW_ITEM_TYPE_ETH,
8221 .type = RTE_FLOW_ITEM_TYPE_END,
8227 union tunnel_offload_mark mark_id;
8228 struct rte_flow_action_mark miss_mark;
8229 struct rte_flow_action miss_actions[3] = {
8230 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
8231 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
8233 const struct rte_flow_action_jump *jump_data;
8234 uint32_t i, flow_table = 0; /* prevent compilation warning */
8235 struct flow_grp_info grp_info = {
8237 .transfer = attr->transfer,
8238 .fdb_def_rule = !!priv->fdb_def_rule,
8243 if (!attr->transfer) {
8246 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
8247 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
8248 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
8251 return rte_flow_error_set
8253 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8254 NULL, "invalid default miss RSS");
8255 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8256 ctx->action_rss.level = 0,
8257 ctx->action_rss.types = priv->rss_conf.rss_hf,
8258 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
8259 ctx->action_rss.queue_num = priv->reta_idx_n,
8260 ctx->action_rss.key = priv->rss_conf.rss_key,
8261 ctx->action_rss.queue = ctx->queue;
8262 if (!priv->reta_idx_n || !priv->rxqs_n)
8263 return rte_flow_error_set
8265 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8266 NULL, "invalid port configuration");
8267 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
8268 ctx->action_rss.types = 0;
8269 for (i = 0; i != priv->reta_idx_n; ++i)
8270 ctx->queue[i] = (*priv->reta_idx)[i];
8272 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
8273 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
8275 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
8276 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
8277 jump_data = app_actions->conf;
8278 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
8279 miss_attr.group = jump_data->group;
8280 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
8281 &flow_table, &grp_info, error);
8283 return rte_flow_error_set(error, EINVAL,
8284 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
8285 NULL, "invalid tunnel id");
8286 mark_id.app_reserve = 0;
8287 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
8288 mark_id.transfer = !!attr->transfer;
8289 mark_id._unused_ = 0;
8290 miss_mark.id = mark_id.val;
8291 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
8292 miss_items, miss_actions, flow_idx, error);
8295 dev_flow->flow = flow;
8296 dev_flow->external = true;
8297 dev_flow->tunnel = tunnel;
8298 dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
8299 /* Subflow object was created, we must include one in the list. */
8300 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
8301 dev_flow->handle, next);
8303 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
8304 dev->data->port_id, tunnel->app_tunnel.type,
8305 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
8306 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
8307 miss_actions, error);
8309 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
8315 static const struct mlx5_flow_tbl_data_entry *
8316 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
8318 struct mlx5_priv *priv = dev->data->dev_private;
8319 struct mlx5_dev_ctx_shared *sh = priv->sh;
8320 struct mlx5_hlist_entry *he;
8321 union tunnel_offload_mark mbits = { .val = mark };
8322 union mlx5_flow_tbl_key table_key = {
8324 .level = tunnel_id_to_flow_tbl(mbits.table_id),
8328 .is_fdb = !!mbits.transfer,
8332 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, NULL);
8334 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
8338 mlx5_flow_tunnel_grp2tbl_remove_cb(struct mlx5_hlist *list,
8339 struct mlx5_hlist_entry *entry)
8341 struct mlx5_dev_ctx_shared *sh = list->ctx;
8342 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8344 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8345 tunnel_flow_tbl_to_id(tte->flow_table));
8350 mlx5_flow_tunnel_grp2tbl_match_cb(struct mlx5_hlist *list __rte_unused,
8351 struct mlx5_hlist_entry *entry,
8352 uint64_t key, void *cb_ctx __rte_unused)
8354 union tunnel_tbl_key tbl = {
8357 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
8359 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
8362 static struct mlx5_hlist_entry *
8363 mlx5_flow_tunnel_grp2tbl_create_cb(struct mlx5_hlist *list, uint64_t key,
8364 void *ctx __rte_unused)
8366 struct mlx5_dev_ctx_shared *sh = list->ctx;
8367 struct tunnel_tbl_entry *tte;
8368 union tunnel_tbl_key tbl = {
8372 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
8377 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8379 if (tte->flow_table >= MLX5_MAX_TABLES) {
8380 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
8382 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
8385 } else if (!tte->flow_table) {
8388 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
8389 tte->tunnel_id = tbl.tunnel_id;
8390 tte->group = tbl.group;
8399 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
8400 const struct mlx5_flow_tunnel *tunnel,
8401 uint32_t group, uint32_t *table,
8402 struct rte_flow_error *error)
8404 struct mlx5_hlist_entry *he;
8405 struct tunnel_tbl_entry *tte;
8406 union tunnel_tbl_key key = {
8407 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
8410 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8411 struct mlx5_hlist *group_hash;
8413 group_hash = tunnel ? tunnel->groups : thub->groups;
8414 he = mlx5_hlist_register(group_hash, key.val, NULL);
8416 return rte_flow_error_set(error, EINVAL,
8417 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
8419 "tunnel group index not supported");
8420 tte = container_of(he, typeof(*tte), hash);
8421 *table = tte->flow_table;
8422 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
8423 dev->data->port_id, key.tunnel_id, group, *table);
8428 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
8429 struct mlx5_flow_tunnel *tunnel)
8431 struct mlx5_priv *priv = dev->data->dev_private;
8432 struct mlx5_indexed_pool *ipool;
8434 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
8435 dev->data->port_id, tunnel->tunnel_id);
8436 LIST_REMOVE(tunnel, chain);
8437 mlx5_hlist_destroy(tunnel->groups);
8438 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8439 mlx5_ipool_free(ipool, tunnel->tunnel_id);
8443 mlx5_access_tunnel_offload_db
8444 (struct rte_eth_dev *dev,
8445 bool (*match)(struct rte_eth_dev *,
8446 struct mlx5_flow_tunnel *, const void *),
8447 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
8448 void (*miss)(struct rte_eth_dev *, void *),
8449 void *ctx, bool lock_op)
8451 bool verdict = false;
8452 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8453 struct mlx5_flow_tunnel *tunnel;
8455 rte_spinlock_lock(&thub->sl);
8456 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
8457 verdict = match(dev, tunnel, (const void *)ctx);
8462 rte_spinlock_unlock(&thub->sl);
8464 hit(dev, tunnel, ctx);
8465 if (!verdict && miss)
8468 rte_spinlock_unlock(&thub->sl);
8473 struct tunnel_db_find_tunnel_id_ctx {
8475 struct mlx5_flow_tunnel *tunnel;
8479 find_tunnel_id_match(struct rte_eth_dev *dev,
8480 struct mlx5_flow_tunnel *tunnel, const void *x)
8482 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8485 return tunnel->tunnel_id == ctx->tunnel_id;
8489 find_tunnel_id_hit(struct rte_eth_dev *dev,
8490 struct mlx5_flow_tunnel *tunnel, void *x)
8492 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
8494 ctx->tunnel = tunnel;
8497 static struct mlx5_flow_tunnel *
8498 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
8500 struct tunnel_db_find_tunnel_id_ctx ctx = {
8504 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
8505 find_tunnel_id_hit, NULL, &ctx, true);
8510 static struct mlx5_flow_tunnel *
8511 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
8512 const struct rte_flow_tunnel *app_tunnel)
8514 struct mlx5_priv *priv = dev->data->dev_private;
8515 struct mlx5_indexed_pool *ipool;
8516 struct mlx5_flow_tunnel *tunnel;
8519 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
8520 tunnel = mlx5_ipool_zmalloc(ipool, &id);
8523 if (id >= MLX5_MAX_TUNNELS) {
8524 mlx5_ipool_free(ipool, id);
8525 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
8528 tunnel->groups = mlx5_hlist_create("tunnel groups", 1024, 0, 0,
8529 mlx5_flow_tunnel_grp2tbl_create_cb,
8530 mlx5_flow_tunnel_grp2tbl_match_cb,
8531 mlx5_flow_tunnel_grp2tbl_remove_cb);
8532 if (!tunnel->groups) {
8533 mlx5_ipool_free(ipool, id);
8536 tunnel->groups->ctx = priv->sh;
8537 /* initiate new PMD tunnel */
8538 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
8539 tunnel->tunnel_id = id;
8540 tunnel->action.type = (typeof(tunnel->action.type))
8541 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
8542 tunnel->action.conf = tunnel;
8543 tunnel->item.type = (typeof(tunnel->item.type))
8544 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
8545 tunnel->item.spec = tunnel;
8546 tunnel->item.last = NULL;
8547 tunnel->item.mask = NULL;
8549 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
8550 dev->data->port_id, tunnel->tunnel_id);
8555 struct tunnel_db_get_tunnel_ctx {
8556 const struct rte_flow_tunnel *app_tunnel;
8557 struct mlx5_flow_tunnel *tunnel;
8560 static bool get_tunnel_match(struct rte_eth_dev *dev,
8561 struct mlx5_flow_tunnel *tunnel, const void *x)
8563 const struct tunnel_db_get_tunnel_ctx *ctx = x;
8566 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
8567 sizeof(*ctx->app_tunnel));
8570 static void get_tunnel_hit(struct rte_eth_dev *dev,
8571 struct mlx5_flow_tunnel *tunnel, void *x)
8573 /* called under tunnel spinlock protection */
8574 struct tunnel_db_get_tunnel_ctx *ctx = x;
8578 ctx->tunnel = tunnel;
8581 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
8583 /* called under tunnel spinlock protection */
8584 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
8585 struct tunnel_db_get_tunnel_ctx *ctx = x;
8587 rte_spinlock_unlock(&thub->sl);
8588 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
8589 rte_spinlock_lock(&thub->sl);
8591 ctx->tunnel->refctn = 1;
8592 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
8598 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
8599 const struct rte_flow_tunnel *app_tunnel,
8600 struct mlx5_flow_tunnel **tunnel)
8602 struct tunnel_db_get_tunnel_ctx ctx = {
8603 .app_tunnel = app_tunnel,
8606 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
8607 get_tunnel_miss, &ctx, true);
8608 *tunnel = ctx.tunnel;
8609 return ctx.tunnel ? 0 : -ENOMEM;
8612 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
8614 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
8618 if (!LIST_EMPTY(&thub->tunnels))
8619 DRV_LOG(WARNING, "port %u tunnels present", port_id);
8620 mlx5_hlist_destroy(thub->groups);
8624 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
8627 struct mlx5_flow_tunnel_hub *thub;
8629 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
8633 LIST_INIT(&thub->tunnels);
8634 rte_spinlock_init(&thub->sl);
8635 thub->groups = mlx5_hlist_create("flow groups",
8636 rte_align32pow2(MLX5_MAX_TABLES), 0,
8637 0, mlx5_flow_tunnel_grp2tbl_create_cb,
8638 mlx5_flow_tunnel_grp2tbl_match_cb,
8639 mlx5_flow_tunnel_grp2tbl_remove_cb);
8640 if (!thub->groups) {
8644 thub->groups->ctx = sh;
8645 sh->tunnel_hub = thub;
8651 mlx5_hlist_destroy(thub->groups);
8658 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
8659 struct rte_flow_tunnel *tunnel,
8660 const char *err_msg)
8663 if (!is_tunnel_offload_active(dev)) {
8664 err_msg = "tunnel offload was not activated";
8666 } else if (!tunnel) {
8667 err_msg = "no application tunnel";
8671 switch (tunnel->type) {
8673 err_msg = "unsupported tunnel type";
8675 case RTE_FLOW_ITEM_TYPE_VXLAN:
8684 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
8685 struct rte_flow_tunnel *app_tunnel,
8686 struct rte_flow_action **actions,
8687 uint32_t *num_of_actions,
8688 struct rte_flow_error *error)
8691 struct mlx5_flow_tunnel *tunnel;
8692 const char *err_msg = NULL;
8693 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
8696 return rte_flow_error_set(error, EINVAL,
8697 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
8699 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
8701 return rte_flow_error_set(error, ret,
8702 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
8703 "failed to initialize pmd tunnel");
8705 *actions = &tunnel->action;
8706 *num_of_actions = 1;
8711 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
8712 struct rte_flow_tunnel *app_tunnel,
8713 struct rte_flow_item **items,
8714 uint32_t *num_of_items,
8715 struct rte_flow_error *error)
8718 struct mlx5_flow_tunnel *tunnel;
8719 const char *err_msg = NULL;
8720 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
8723 return rte_flow_error_set(error, EINVAL,
8724 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
8726 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
8728 return rte_flow_error_set(error, ret,
8729 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
8730 "failed to initialize pmd tunnel");
8732 *items = &tunnel->item;
8737 struct tunnel_db_element_release_ctx {
8738 struct rte_flow_item *items;
8739 struct rte_flow_action *actions;
8740 uint32_t num_elements;
8741 struct rte_flow_error *error;
8746 tunnel_element_release_match(struct rte_eth_dev *dev,
8747 struct mlx5_flow_tunnel *tunnel, const void *x)
8749 const struct tunnel_db_element_release_ctx *ctx = x;
8752 if (ctx->num_elements != 1)
8754 else if (ctx->items)
8755 return ctx->items == &tunnel->item;
8756 else if (ctx->actions)
8757 return ctx->actions == &tunnel->action;
8763 tunnel_element_release_hit(struct rte_eth_dev *dev,
8764 struct mlx5_flow_tunnel *tunnel, void *x)
8766 struct tunnel_db_element_release_ctx *ctx = x;
8768 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
8769 mlx5_flow_tunnel_free(dev, tunnel);
8773 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
8775 struct tunnel_db_element_release_ctx *ctx = x;
8777 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
8778 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
8779 "invalid argument");
8783 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
8784 struct rte_flow_item *pmd_items,
8785 uint32_t num_items, struct rte_flow_error *err)
8787 struct tunnel_db_element_release_ctx ctx = {
8790 .num_elements = num_items,
8794 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
8795 tunnel_element_release_hit,
8796 tunnel_element_release_miss, &ctx, false);
8802 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
8803 struct rte_flow_action *pmd_actions,
8804 uint32_t num_actions, struct rte_flow_error *err)
8806 struct tunnel_db_element_release_ctx ctx = {
8808 .actions = pmd_actions,
8809 .num_elements = num_actions,
8813 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
8814 tunnel_element_release_hit,
8815 tunnel_element_release_miss, &ctx, false);
8821 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
8823 struct rte_flow_restore_info *info,
8824 struct rte_flow_error *err)
8826 uint64_t ol_flags = m->ol_flags;
8827 const struct mlx5_flow_tbl_data_entry *tble;
8828 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
8830 if (!is_tunnel_offload_active(dev)) {
8835 if ((ol_flags & mask) != mask)
8837 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
8839 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
8840 dev->data->port_id, m->hash.fdir.hi);
8843 MLX5_ASSERT(tble->tunnel);
8844 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
8845 info->group_id = tble->group_id;
8846 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
8847 RTE_FLOW_RESTORE_INFO_GROUP_ID |
8848 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
8853 return rte_flow_error_set(err, EINVAL,
8854 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8855 "failed to get restore info");
8858 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
8860 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
8861 __rte_unused struct rte_flow_tunnel *app_tunnel,
8862 __rte_unused struct rte_flow_action **actions,
8863 __rte_unused uint32_t *num_of_actions,
8864 __rte_unused struct rte_flow_error *error)
8870 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
8871 __rte_unused struct rte_flow_tunnel *app_tunnel,
8872 __rte_unused struct rte_flow_item **items,
8873 __rte_unused uint32_t *num_of_items,
8874 __rte_unused struct rte_flow_error *error)
8880 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
8881 __rte_unused struct rte_flow_item *pmd_items,
8882 __rte_unused uint32_t num_items,
8883 __rte_unused struct rte_flow_error *err)
8889 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
8890 __rte_unused struct rte_flow_action *pmd_action,
8891 __rte_unused uint32_t num_actions,
8892 __rte_unused struct rte_flow_error *err)
8898 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
8899 __rte_unused struct rte_mbuf *m,
8900 __rte_unused struct rte_flow_restore_info *i,
8901 __rte_unused struct rte_flow_error *err)
8907 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
8908 __rte_unused struct rte_flow *flow,
8909 __rte_unused const struct rte_flow_attr *attr,
8910 __rte_unused const struct rte_flow_action *actions,
8911 __rte_unused uint32_t flow_idx,
8912 __rte_unused const struct mlx5_flow_tunnel *tunnel,
8913 __rte_unused struct tunnel_default_miss_ctx *ctx,
8914 __rte_unused struct rte_flow_error *error)
8919 static struct mlx5_flow_tunnel *
8920 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
8921 __rte_unused uint32_t id)
8927 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
8928 __rte_unused struct mlx5_flow_tunnel *tunnel)
8933 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
8934 __rte_unused const struct mlx5_flow_tunnel *t,
8935 __rte_unused uint32_t group,
8936 __rte_unused uint32_t *table,
8937 struct rte_flow_error *error)
8939 return rte_flow_error_set(error, ENOTSUP,
8940 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8941 "tunnel offload requires DV support");
8945 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
8946 __rte_unused uint16_t port_id)
8949 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */