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"
31 #include "mlx5_rxtx.h"
32 #include "mlx5_common_os.h"
33 #include "rte_pmd_mlx5.h"
35 struct tunnel_default_miss_ctx {
39 struct rte_flow_action_rss action_rss;
40 struct rte_flow_action_queue miss_queue;
41 struct rte_flow_action_jump miss_jump;
47 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
48 struct rte_flow *flow,
49 const struct rte_flow_attr *attr,
50 const struct rte_flow_action *app_actions,
52 struct tunnel_default_miss_ctx *ctx,
53 struct rte_flow_error *error);
54 static struct mlx5_flow_tunnel *
55 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
57 mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
59 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
60 const struct mlx5_flow_tunnel *tunnel,
61 uint32_t group, uint32_t *table,
62 struct rte_flow_error *error);
64 static struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);
65 static void mlx5_flow_pop_thread_workspace(void);
68 /** Device flow drivers. */
69 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
71 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
73 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
74 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
75 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
76 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
78 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
79 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
82 /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
83 #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
88 /** Node object of input graph for mlx5_flow_expand_rss(). */
89 struct mlx5_flow_expand_node {
90 const int *const next;
92 * List of next node indexes. Index 0 is interpreted as a terminator.
94 const enum rte_flow_item_type type;
95 /**< Pattern item type of current node. */
98 * RSS types bit-field associated with this node
99 * (see ETH_RSS_* definitions).
103 /** Object returned by mlx5_flow_expand_rss(). */
104 struct mlx5_flow_expand_rss {
106 /**< Number of entries @p patterns and @p priorities. */
108 struct rte_flow_item *pattern; /**< Expanded pattern array. */
109 uint32_t priority; /**< Priority offset for each expansion. */
113 static enum rte_flow_item_type
114 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
116 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
117 uint16_t ether_type = 0;
118 uint16_t ether_type_m;
119 uint8_t ip_next_proto = 0;
120 uint8_t ip_next_proto_m;
122 if (item == NULL || item->spec == NULL)
124 switch (item->type) {
125 case RTE_FLOW_ITEM_TYPE_ETH:
127 ether_type_m = ((const struct rte_flow_item_eth *)
130 ether_type_m = rte_flow_item_eth_mask.type;
131 if (ether_type_m != RTE_BE16(0xFFFF))
133 ether_type = ((const struct rte_flow_item_eth *)
135 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
136 ret = RTE_FLOW_ITEM_TYPE_IPV4;
137 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
138 ret = RTE_FLOW_ITEM_TYPE_IPV6;
139 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
140 ret = RTE_FLOW_ITEM_TYPE_VLAN;
142 ret = RTE_FLOW_ITEM_TYPE_END;
144 case RTE_FLOW_ITEM_TYPE_VLAN:
146 ether_type_m = ((const struct rte_flow_item_vlan *)
147 (item->mask))->inner_type;
149 ether_type_m = rte_flow_item_vlan_mask.inner_type;
150 if (ether_type_m != RTE_BE16(0xFFFF))
152 ether_type = ((const struct rte_flow_item_vlan *)
153 (item->spec))->inner_type;
154 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
155 ret = RTE_FLOW_ITEM_TYPE_IPV4;
156 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
157 ret = RTE_FLOW_ITEM_TYPE_IPV6;
158 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
159 ret = RTE_FLOW_ITEM_TYPE_VLAN;
161 ret = RTE_FLOW_ITEM_TYPE_END;
163 case RTE_FLOW_ITEM_TYPE_IPV4:
165 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
166 (item->mask))->hdr.next_proto_id;
169 rte_flow_item_ipv4_mask.hdr.next_proto_id;
170 if (ip_next_proto_m != 0xFF)
172 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
173 (item->spec))->hdr.next_proto_id;
174 if (ip_next_proto == IPPROTO_UDP)
175 ret = RTE_FLOW_ITEM_TYPE_UDP;
176 else if (ip_next_proto == IPPROTO_TCP)
177 ret = RTE_FLOW_ITEM_TYPE_TCP;
178 else if (ip_next_proto == IPPROTO_IP)
179 ret = RTE_FLOW_ITEM_TYPE_IPV4;
180 else if (ip_next_proto == IPPROTO_IPV6)
181 ret = RTE_FLOW_ITEM_TYPE_IPV6;
183 ret = RTE_FLOW_ITEM_TYPE_END;
185 case RTE_FLOW_ITEM_TYPE_IPV6:
187 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
188 (item->mask))->hdr.proto;
191 rte_flow_item_ipv6_mask.hdr.proto;
192 if (ip_next_proto_m != 0xFF)
194 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
195 (item->spec))->hdr.proto;
196 if (ip_next_proto == IPPROTO_UDP)
197 ret = RTE_FLOW_ITEM_TYPE_UDP;
198 else if (ip_next_proto == IPPROTO_TCP)
199 ret = RTE_FLOW_ITEM_TYPE_TCP;
200 else if (ip_next_proto == IPPROTO_IP)
201 ret = RTE_FLOW_ITEM_TYPE_IPV4;
202 else if (ip_next_proto == IPPROTO_IPV6)
203 ret = RTE_FLOW_ITEM_TYPE_IPV6;
205 ret = RTE_FLOW_ITEM_TYPE_END;
208 ret = RTE_FLOW_ITEM_TYPE_VOID;
214 #define MLX5_RSS_EXP_ELT_N 8
217 * Expand RSS flows into several possible flows according to the RSS hash
218 * fields requested and the driver capabilities.
221 * Buffer to store the result expansion.
223 * Buffer size in bytes. If 0, @p buf can be NULL.
227 * RSS types to expand (see ETH_RSS_* definitions).
229 * Input graph to expand @p pattern according to @p types.
230 * @param[in] graph_root_index
231 * Index of root node in @p graph, typically 0.
234 * A positive value representing the size of @p buf in bytes regardless of
235 * @p size on success, a negative errno value otherwise and rte_errno is
236 * set, the following errors are defined:
238 * -E2BIG: graph-depth @p graph is too deep.
241 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
242 const struct rte_flow_item *pattern, uint64_t types,
243 const struct mlx5_flow_expand_node graph[],
244 int graph_root_index)
246 const struct rte_flow_item *item;
247 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
248 const int *next_node;
249 const int *stack[MLX5_RSS_EXP_ELT_N];
251 struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
254 size_t user_pattern_size = 0;
256 const struct mlx5_flow_expand_node *next = NULL;
257 struct rte_flow_item missed_item;
260 const struct rte_flow_item *last_item = NULL;
262 memset(&missed_item, 0, sizeof(missed_item));
263 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
264 MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
266 buf->entry[0].priority = 0;
267 buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
269 addr = buf->entry[0].pattern;
271 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
272 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
274 for (i = 0; node->next && node->next[i]; ++i) {
275 next = &graph[node->next[i]];
276 if (next->type == item->type)
281 user_pattern_size += sizeof(*item);
283 user_pattern_size += sizeof(*item); /* Handle END item. */
284 lsize += user_pattern_size;
285 /* Copy the user pattern in the first entry of the buffer. */
287 rte_memcpy(addr, pattern, user_pattern_size);
288 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
291 /* Start expanding. */
292 memset(flow_items, 0, sizeof(flow_items));
293 user_pattern_size -= sizeof(*item);
295 * Check if the last valid item has spec set, need complete pattern,
296 * and the pattern can be used for expansion.
298 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
299 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
300 /* Item type END indicates expansion is not required. */
303 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
306 for (i = 0; node->next && node->next[i]; ++i) {
307 next = &graph[node->next[i]];
308 if (next->type == missed_item.type) {
309 flow_items[0].type = missed_item.type;
310 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
316 if (next && missed) {
317 elt = 2; /* missed item + item end. */
319 lsize += elt * sizeof(*item) + user_pattern_size;
320 if ((node->rss_types & types) && lsize <= size) {
321 buf->entry[buf->entries].priority = 1;
322 buf->entry[buf->entries].pattern = addr;
324 rte_memcpy(addr, buf->entry[0].pattern,
326 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
327 rte_memcpy(addr, flow_items, elt * sizeof(*item));
328 addr = (void *)(((uintptr_t)addr) +
329 elt * sizeof(*item));
332 memset(flow_items, 0, sizeof(flow_items));
333 next_node = node->next;
334 stack[stack_pos] = next_node;
335 node = next_node ? &graph[*next_node] : NULL;
337 flow_items[stack_pos].type = node->type;
338 if (node->rss_types & types) {
340 * compute the number of items to copy from the
341 * expansion and copy it.
342 * When the stack_pos is 0, there are 1 element in it,
343 * plus the addition END item.
346 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
347 lsize += elt * sizeof(*item) + user_pattern_size;
349 size_t n = elt * sizeof(*item);
351 buf->entry[buf->entries].priority =
352 stack_pos + 1 + missed;
353 buf->entry[buf->entries].pattern = addr;
355 rte_memcpy(addr, buf->entry[0].pattern,
357 addr = (void *)(((uintptr_t)addr) +
359 rte_memcpy(addr, &missed_item,
360 missed * sizeof(*item));
361 addr = (void *)(((uintptr_t)addr) +
362 missed * sizeof(*item));
363 rte_memcpy(addr, flow_items, n);
364 addr = (void *)(((uintptr_t)addr) + n);
369 next_node = node->next;
370 if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
374 stack[stack_pos] = next_node;
375 } else if (*(next_node + 1)) {
376 /* Follow up with the next possibility. */
379 /* Move to the next path. */
381 next_node = stack[--stack_pos];
383 stack[stack_pos] = next_node;
385 node = *next_node ? &graph[*next_node] : NULL;
390 enum mlx5_expansion {
392 MLX5_EXPANSION_ROOT_OUTER,
393 MLX5_EXPANSION_ROOT_ETH_VLAN,
394 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
395 MLX5_EXPANSION_OUTER_ETH,
396 MLX5_EXPANSION_OUTER_ETH_VLAN,
397 MLX5_EXPANSION_OUTER_VLAN,
398 MLX5_EXPANSION_OUTER_IPV4,
399 MLX5_EXPANSION_OUTER_IPV4_UDP,
400 MLX5_EXPANSION_OUTER_IPV4_TCP,
401 MLX5_EXPANSION_OUTER_IPV6,
402 MLX5_EXPANSION_OUTER_IPV6_UDP,
403 MLX5_EXPANSION_OUTER_IPV6_TCP,
404 MLX5_EXPANSION_VXLAN,
405 MLX5_EXPANSION_VXLAN_GPE,
409 MLX5_EXPANSION_ETH_VLAN,
412 MLX5_EXPANSION_IPV4_UDP,
413 MLX5_EXPANSION_IPV4_TCP,
415 MLX5_EXPANSION_IPV6_UDP,
416 MLX5_EXPANSION_IPV6_TCP,
419 /** Supported expansion of items. */
420 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
421 [MLX5_EXPANSION_ROOT] = {
422 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
424 MLX5_EXPANSION_IPV6),
425 .type = RTE_FLOW_ITEM_TYPE_END,
427 [MLX5_EXPANSION_ROOT_OUTER] = {
428 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
429 MLX5_EXPANSION_OUTER_IPV4,
430 MLX5_EXPANSION_OUTER_IPV6),
431 .type = RTE_FLOW_ITEM_TYPE_END,
433 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
434 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
435 .type = RTE_FLOW_ITEM_TYPE_END,
437 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
438 .next = MLX5_FLOW_EXPAND_RSS_NEXT
439 (MLX5_EXPANSION_OUTER_ETH_VLAN),
440 .type = RTE_FLOW_ITEM_TYPE_END,
442 [MLX5_EXPANSION_OUTER_ETH] = {
443 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
444 MLX5_EXPANSION_OUTER_IPV6,
445 MLX5_EXPANSION_MPLS),
446 .type = RTE_FLOW_ITEM_TYPE_ETH,
449 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
450 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
451 .type = RTE_FLOW_ITEM_TYPE_ETH,
454 [MLX5_EXPANSION_OUTER_VLAN] = {
455 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
456 MLX5_EXPANSION_OUTER_IPV6),
457 .type = RTE_FLOW_ITEM_TYPE_VLAN,
459 [MLX5_EXPANSION_OUTER_IPV4] = {
460 .next = MLX5_FLOW_EXPAND_RSS_NEXT
461 (MLX5_EXPANSION_OUTER_IPV4_UDP,
462 MLX5_EXPANSION_OUTER_IPV4_TCP,
465 MLX5_EXPANSION_IPV6),
466 .type = RTE_FLOW_ITEM_TYPE_IPV4,
467 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
468 ETH_RSS_NONFRAG_IPV4_OTHER,
470 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
471 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
472 MLX5_EXPANSION_VXLAN_GPE),
473 .type = RTE_FLOW_ITEM_TYPE_UDP,
474 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
476 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
477 .type = RTE_FLOW_ITEM_TYPE_TCP,
478 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
480 [MLX5_EXPANSION_OUTER_IPV6] = {
481 .next = MLX5_FLOW_EXPAND_RSS_NEXT
482 (MLX5_EXPANSION_OUTER_IPV6_UDP,
483 MLX5_EXPANSION_OUTER_IPV6_TCP,
487 .type = RTE_FLOW_ITEM_TYPE_IPV6,
488 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
489 ETH_RSS_NONFRAG_IPV6_OTHER,
491 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
492 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
493 MLX5_EXPANSION_VXLAN_GPE),
494 .type = RTE_FLOW_ITEM_TYPE_UDP,
495 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
497 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
498 .type = RTE_FLOW_ITEM_TYPE_TCP,
499 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
501 [MLX5_EXPANSION_VXLAN] = {
502 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
504 MLX5_EXPANSION_IPV6),
505 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
507 [MLX5_EXPANSION_VXLAN_GPE] = {
508 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
510 MLX5_EXPANSION_IPV6),
511 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
513 [MLX5_EXPANSION_GRE] = {
514 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
515 MLX5_EXPANSION_IPV6),
516 .type = RTE_FLOW_ITEM_TYPE_GRE,
518 [MLX5_EXPANSION_MPLS] = {
519 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
520 MLX5_EXPANSION_IPV6),
521 .type = RTE_FLOW_ITEM_TYPE_MPLS,
523 [MLX5_EXPANSION_ETH] = {
524 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
525 MLX5_EXPANSION_IPV6),
526 .type = RTE_FLOW_ITEM_TYPE_ETH,
528 [MLX5_EXPANSION_ETH_VLAN] = {
529 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
530 .type = RTE_FLOW_ITEM_TYPE_ETH,
532 [MLX5_EXPANSION_VLAN] = {
533 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
534 MLX5_EXPANSION_IPV6),
535 .type = RTE_FLOW_ITEM_TYPE_VLAN,
537 [MLX5_EXPANSION_IPV4] = {
538 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
539 MLX5_EXPANSION_IPV4_TCP),
540 .type = RTE_FLOW_ITEM_TYPE_IPV4,
541 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
542 ETH_RSS_NONFRAG_IPV4_OTHER,
544 [MLX5_EXPANSION_IPV4_UDP] = {
545 .type = RTE_FLOW_ITEM_TYPE_UDP,
546 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
548 [MLX5_EXPANSION_IPV4_TCP] = {
549 .type = RTE_FLOW_ITEM_TYPE_TCP,
550 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
552 [MLX5_EXPANSION_IPV6] = {
553 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
554 MLX5_EXPANSION_IPV6_TCP),
555 .type = RTE_FLOW_ITEM_TYPE_IPV6,
556 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
557 ETH_RSS_NONFRAG_IPV6_OTHER,
559 [MLX5_EXPANSION_IPV6_UDP] = {
560 .type = RTE_FLOW_ITEM_TYPE_UDP,
561 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
563 [MLX5_EXPANSION_IPV6_TCP] = {
564 .type = RTE_FLOW_ITEM_TYPE_TCP,
565 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
569 static struct rte_flow_shared_action *
570 mlx5_shared_action_create(struct rte_eth_dev *dev,
571 const struct rte_flow_shared_action_conf *conf,
572 const struct rte_flow_action *action,
573 struct rte_flow_error *error);
574 static int mlx5_shared_action_destroy
575 (struct rte_eth_dev *dev,
576 struct rte_flow_shared_action *shared_action,
577 struct rte_flow_error *error);
578 static int mlx5_shared_action_update
579 (struct rte_eth_dev *dev,
580 struct rte_flow_shared_action *shared_action,
581 const struct rte_flow_action *action,
582 struct rte_flow_error *error);
583 static int mlx5_shared_action_query
584 (struct rte_eth_dev *dev,
585 const struct rte_flow_shared_action *action,
587 struct rte_flow_error *error);
589 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
590 struct rte_flow_tunnel *app_tunnel,
591 struct rte_flow_action **actions,
592 uint32_t *num_of_actions,
593 struct rte_flow_error *error);
595 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
596 struct rte_flow_tunnel *app_tunnel,
597 struct rte_flow_item **items,
598 uint32_t *num_of_items,
599 struct rte_flow_error *error);
601 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
602 struct rte_flow_item *pmd_items,
603 uint32_t num_items, struct rte_flow_error *err);
605 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
606 struct rte_flow_action *pmd_actions,
607 uint32_t num_actions,
608 struct rte_flow_error *err);
610 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
612 struct rte_flow_restore_info *info,
613 struct rte_flow_error *err);
615 static const struct rte_flow_ops mlx5_flow_ops = {
616 .validate = mlx5_flow_validate,
617 .create = mlx5_flow_create,
618 .destroy = mlx5_flow_destroy,
619 .flush = mlx5_flow_flush,
620 .isolate = mlx5_flow_isolate,
621 .query = mlx5_flow_query,
622 .dev_dump = mlx5_flow_dev_dump,
623 .get_aged_flows = mlx5_flow_get_aged_flows,
624 .shared_action_create = mlx5_shared_action_create,
625 .shared_action_destroy = mlx5_shared_action_destroy,
626 .shared_action_update = mlx5_shared_action_update,
627 .shared_action_query = mlx5_shared_action_query,
628 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
629 .tunnel_match = mlx5_flow_tunnel_match,
630 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
631 .tunnel_item_release = mlx5_flow_tunnel_item_release,
632 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
635 /* Tunnel information. */
636 struct mlx5_flow_tunnel_info {
637 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
638 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
641 static struct mlx5_flow_tunnel_info tunnels_info[] = {
643 .tunnel = MLX5_FLOW_LAYER_VXLAN,
644 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
647 .tunnel = MLX5_FLOW_LAYER_GENEVE,
648 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
651 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
652 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
655 .tunnel = MLX5_FLOW_LAYER_GRE,
656 .ptype = RTE_PTYPE_TUNNEL_GRE,
659 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
660 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
663 .tunnel = MLX5_FLOW_LAYER_MPLS,
664 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
667 .tunnel = MLX5_FLOW_LAYER_NVGRE,
668 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
671 .tunnel = MLX5_FLOW_LAYER_IPIP,
672 .ptype = RTE_PTYPE_TUNNEL_IP,
675 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
676 .ptype = RTE_PTYPE_TUNNEL_IP,
679 .tunnel = MLX5_FLOW_LAYER_GTP,
680 .ptype = RTE_PTYPE_TUNNEL_GTPU,
687 * Translate tag ID to register.
690 * Pointer to the Ethernet device structure.
692 * The feature that request the register.
694 * The request register ID.
696 * Error description in case of any.
699 * The request register on success, a negative errno
700 * value otherwise and rte_errno is set.
703 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
704 enum mlx5_feature_name feature,
706 struct rte_flow_error *error)
708 struct mlx5_priv *priv = dev->data->dev_private;
709 struct mlx5_dev_config *config = &priv->config;
710 enum modify_reg start_reg;
711 bool skip_mtr_reg = false;
714 case MLX5_HAIRPIN_RX:
716 case MLX5_HAIRPIN_TX:
718 case MLX5_METADATA_RX:
719 switch (config->dv_xmeta_en) {
720 case MLX5_XMETA_MODE_LEGACY:
722 case MLX5_XMETA_MODE_META16:
724 case MLX5_XMETA_MODE_META32:
728 case MLX5_METADATA_TX:
730 case MLX5_METADATA_FDB:
731 switch (config->dv_xmeta_en) {
732 case MLX5_XMETA_MODE_LEGACY:
734 case MLX5_XMETA_MODE_META16:
736 case MLX5_XMETA_MODE_META32:
741 switch (config->dv_xmeta_en) {
742 case MLX5_XMETA_MODE_LEGACY:
744 case MLX5_XMETA_MODE_META16:
746 case MLX5_XMETA_MODE_META32:
752 * If meter color and flow match share one register, flow match
753 * should use the meter color register for match.
755 if (priv->mtr_reg_share)
756 return priv->mtr_color_reg;
758 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
761 case MLX5_ASO_FLOW_HIT: /* Both features use the same REG_C. */
762 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
763 return priv->mtr_color_reg;
766 * Metadata COPY_MARK register using is in meter suffix sub
767 * flow while with meter. It's safe to share the same register.
769 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
772 * If meter is enable, it will engage the register for color
773 * match and flow match. If meter color match is not using the
774 * REG_C_2, need to skip the REG_C_x be used by meter color
776 * If meter is disable, free to use all available registers.
778 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
779 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
780 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
781 if (id > (uint32_t)(REG_C_7 - start_reg))
782 return rte_flow_error_set(error, EINVAL,
783 RTE_FLOW_ERROR_TYPE_ITEM,
784 NULL, "invalid tag id");
785 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
786 return rte_flow_error_set(error, ENOTSUP,
787 RTE_FLOW_ERROR_TYPE_ITEM,
788 NULL, "unsupported tag id");
790 * This case means meter is using the REG_C_x great than 2.
791 * Take care not to conflict with meter color REG_C_x.
792 * If the available index REG_C_y >= REG_C_x, skip the
795 if (skip_mtr_reg && config->flow_mreg_c
796 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
797 if (id >= (uint32_t)(REG_C_7 - start_reg))
798 return rte_flow_error_set(error, EINVAL,
799 RTE_FLOW_ERROR_TYPE_ITEM,
800 NULL, "invalid tag id");
801 if (config->flow_mreg_c
802 [id + 1 + start_reg - REG_C_0] != REG_NON)
803 return config->flow_mreg_c
804 [id + 1 + start_reg - REG_C_0];
805 return rte_flow_error_set(error, ENOTSUP,
806 RTE_FLOW_ERROR_TYPE_ITEM,
807 NULL, "unsupported tag id");
809 return config->flow_mreg_c[id + start_reg - REG_C_0];
812 return rte_flow_error_set(error, EINVAL,
813 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
814 NULL, "invalid feature name");
818 * Check extensive flow metadata register support.
821 * Pointer to rte_eth_dev structure.
824 * True if device supports extensive flow metadata register, otherwise false.
827 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
829 struct mlx5_priv *priv = dev->data->dev_private;
830 struct mlx5_dev_config *config = &priv->config;
833 * Having available reg_c can be regarded inclusively as supporting
834 * extensive flow metadata register, which could mean,
835 * - metadata register copy action by modify header.
836 * - 16 modify header actions is supported.
837 * - reg_c's are preserved across different domain (FDB and NIC) on
838 * packet loopback by flow lookup miss.
840 return config->flow_mreg_c[2] != REG_NON;
844 * Get the lowest priority.
847 * Pointer to the Ethernet device structure.
848 * @param[in] attributes
849 * Pointer to device flow rule attributes.
852 * The value of lowest priority of flow.
855 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
856 const struct rte_flow_attr *attr)
858 struct mlx5_priv *priv = dev->data->dev_private;
860 if (!attr->group && !attr->transfer)
861 return priv->config.flow_prio - 2;
862 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
866 * Calculate matcher priority of the flow.
869 * Pointer to the Ethernet device structure.
871 * Pointer to device flow rule attributes.
872 * @param[in] subpriority
873 * The priority based on the items.
875 * The matcher priority of the flow.
878 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
879 const struct rte_flow_attr *attr,
880 uint32_t subpriority)
882 uint16_t priority = (uint16_t)attr->priority;
883 struct mlx5_priv *priv = dev->data->dev_private;
885 if (!attr->group && !attr->transfer) {
886 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
887 priority = priv->config.flow_prio - 1;
888 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
890 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
891 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
892 return priority * 3 + subpriority;
896 * Verify the @p item specifications (spec, last, mask) are compatible with the
900 * Item specification.
902 * @p item->mask or flow default bit-masks.
903 * @param[in] nic_mask
904 * Bit-masks covering supported fields by the NIC to compare with user mask.
906 * Bit-masks size in bytes.
907 * @param[in] range_accepted
908 * True if range of values is accepted for specific fields, false otherwise.
910 * Pointer to error structure.
913 * 0 on success, a negative errno value otherwise and rte_errno is set.
916 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
918 const uint8_t *nic_mask,
921 struct rte_flow_error *error)
925 MLX5_ASSERT(nic_mask);
926 for (i = 0; i < size; ++i)
927 if ((nic_mask[i] | mask[i]) != nic_mask[i])
928 return rte_flow_error_set(error, ENOTSUP,
929 RTE_FLOW_ERROR_TYPE_ITEM,
931 "mask enables non supported"
933 if (!item->spec && (item->mask || item->last))
934 return rte_flow_error_set(error, EINVAL,
935 RTE_FLOW_ERROR_TYPE_ITEM, item,
936 "mask/last without a spec is not"
938 if (item->spec && item->last && !range_accepted) {
944 for (i = 0; i < size; ++i) {
945 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
946 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
948 ret = memcmp(spec, last, size);
950 return rte_flow_error_set(error, EINVAL,
951 RTE_FLOW_ERROR_TYPE_ITEM,
953 "range is not valid");
959 * Adjust the hash fields according to the @p flow information.
961 * @param[in] dev_flow.
962 * Pointer to the mlx5_flow.
964 * 1 when the hash field is for a tunnel item.
965 * @param[in] layer_types
967 * @param[in] hash_fields
971 * The hash fields that should be used.
974 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
975 int tunnel __rte_unused, uint64_t layer_types,
976 uint64_t hash_fields)
978 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
979 int rss_request_inner = rss_desc->level >= 2;
981 /* Check RSS hash level for tunnel. */
982 if (tunnel && rss_request_inner)
983 hash_fields |= IBV_RX_HASH_INNER;
984 else if (tunnel || rss_request_inner)
987 /* Check if requested layer matches RSS hash fields. */
988 if (!(rss_desc->types & layer_types))
994 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
995 * if several tunnel rules are used on this queue, the tunnel ptype will be
999 * Rx queue to update.
1002 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1005 uint32_t tunnel_ptype = 0;
1007 /* Look up for the ptype to use. */
1008 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1009 if (!rxq_ctrl->flow_tunnels_n[i])
1011 if (!tunnel_ptype) {
1012 tunnel_ptype = tunnels_info[i].ptype;
1018 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1022 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
1026 * Pointer to the Ethernet device structure.
1027 * @param[in] dev_handle
1028 * Pointer to device flow handle structure.
1031 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1032 struct mlx5_flow_handle *dev_handle)
1034 struct mlx5_priv *priv = dev->data->dev_private;
1035 const int mark = dev_handle->mark;
1036 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1037 struct mlx5_ind_table_obj *ind_tbl = NULL;
1040 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1041 struct mlx5_hrxq *hrxq;
1043 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1044 dev_handle->rix_hrxq);
1046 ind_tbl = hrxq->ind_table;
1047 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1048 struct mlx5_shared_action_rss *shared_rss;
1050 shared_rss = mlx5_ipool_get
1051 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1052 dev_handle->rix_srss);
1054 ind_tbl = shared_rss->ind_tbl;
1058 for (i = 0; i != ind_tbl->queues_n; ++i) {
1059 int idx = ind_tbl->queues[i];
1060 struct mlx5_rxq_ctrl *rxq_ctrl =
1061 container_of((*priv->rxqs)[idx],
1062 struct mlx5_rxq_ctrl, rxq);
1065 * To support metadata register copy on Tx loopback,
1066 * this must be always enabled (metadata may arive
1067 * from other port - not from local flows only.
1069 if (priv->config.dv_flow_en &&
1070 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1071 mlx5_flow_ext_mreg_supported(dev)) {
1072 rxq_ctrl->rxq.mark = 1;
1073 rxq_ctrl->flow_mark_n = 1;
1075 rxq_ctrl->rxq.mark = 1;
1076 rxq_ctrl->flow_mark_n++;
1081 /* Increase the counter matching the flow. */
1082 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1083 if ((tunnels_info[j].tunnel &
1084 dev_handle->layers) ==
1085 tunnels_info[j].tunnel) {
1086 rxq_ctrl->flow_tunnels_n[j]++;
1090 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1096 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1099 * Pointer to the Ethernet device structure.
1101 * Pointer to flow structure.
1104 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1106 struct mlx5_priv *priv = dev->data->dev_private;
1107 uint32_t handle_idx;
1108 struct mlx5_flow_handle *dev_handle;
1110 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1111 handle_idx, dev_handle, next)
1112 flow_drv_rxq_flags_set(dev, dev_handle);
1116 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1117 * device flow if no other flow uses it with the same kind of request.
1120 * Pointer to Ethernet device.
1121 * @param[in] dev_handle
1122 * Pointer to the device flow handle structure.
1125 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1126 struct mlx5_flow_handle *dev_handle)
1128 struct mlx5_priv *priv = dev->data->dev_private;
1129 const int mark = dev_handle->mark;
1130 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1131 struct mlx5_ind_table_obj *ind_tbl = NULL;
1134 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1135 struct mlx5_hrxq *hrxq;
1137 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1138 dev_handle->rix_hrxq);
1140 ind_tbl = hrxq->ind_table;
1141 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1142 struct mlx5_shared_action_rss *shared_rss;
1144 shared_rss = mlx5_ipool_get
1145 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1146 dev_handle->rix_srss);
1148 ind_tbl = shared_rss->ind_tbl;
1152 MLX5_ASSERT(dev->data->dev_started);
1153 for (i = 0; i != ind_tbl->queues_n; ++i) {
1154 int idx = ind_tbl->queues[i];
1155 struct mlx5_rxq_ctrl *rxq_ctrl =
1156 container_of((*priv->rxqs)[idx],
1157 struct mlx5_rxq_ctrl, rxq);
1159 if (priv->config.dv_flow_en &&
1160 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1161 mlx5_flow_ext_mreg_supported(dev)) {
1162 rxq_ctrl->rxq.mark = 1;
1163 rxq_ctrl->flow_mark_n = 1;
1165 rxq_ctrl->flow_mark_n--;
1166 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1171 /* Decrease the counter matching the flow. */
1172 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1173 if ((tunnels_info[j].tunnel &
1174 dev_handle->layers) ==
1175 tunnels_info[j].tunnel) {
1176 rxq_ctrl->flow_tunnels_n[j]--;
1180 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1186 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1187 * @p flow if no other flow uses it with the same kind of request.
1190 * Pointer to Ethernet device.
1192 * Pointer to the flow.
1195 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1197 struct mlx5_priv *priv = dev->data->dev_private;
1198 uint32_t handle_idx;
1199 struct mlx5_flow_handle *dev_handle;
1201 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1202 handle_idx, dev_handle, next)
1203 flow_drv_rxq_flags_trim(dev, dev_handle);
1207 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1210 * Pointer to Ethernet device.
1213 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1215 struct mlx5_priv *priv = dev->data->dev_private;
1218 for (i = 0; i != priv->rxqs_n; ++i) {
1219 struct mlx5_rxq_ctrl *rxq_ctrl;
1222 if (!(*priv->rxqs)[i])
1224 rxq_ctrl = container_of((*priv->rxqs)[i],
1225 struct mlx5_rxq_ctrl, rxq);
1226 rxq_ctrl->flow_mark_n = 0;
1227 rxq_ctrl->rxq.mark = 0;
1228 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1229 rxq_ctrl->flow_tunnels_n[j] = 0;
1230 rxq_ctrl->rxq.tunnel = 0;
1235 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1238 * Pointer to the Ethernet device structure.
1241 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1243 struct mlx5_priv *priv = dev->data->dev_private;
1244 struct mlx5_rxq_data *data;
1247 for (i = 0; i != priv->rxqs_n; ++i) {
1248 if (!(*priv->rxqs)[i])
1250 data = (*priv->rxqs)[i];
1251 if (!rte_flow_dynf_metadata_avail()) {
1252 data->dynf_meta = 0;
1253 data->flow_meta_mask = 0;
1254 data->flow_meta_offset = -1;
1255 data->flow_meta_port_mask = 0;
1257 data->dynf_meta = 1;
1258 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1259 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1260 data->flow_meta_port_mask = (uint32_t)~0;
1261 if (priv->config.dv_xmeta_en == MLX5_XMETA_MODE_META16)
1262 data->flow_meta_port_mask >>= 16;
1268 * return a pointer to the desired action in the list of actions.
1270 * @param[in] actions
1271 * The list of actions to search the action in.
1273 * The action to find.
1276 * Pointer to the action in the list, if found. NULL otherwise.
1278 const struct rte_flow_action *
1279 mlx5_flow_find_action(const struct rte_flow_action *actions,
1280 enum rte_flow_action_type action)
1282 if (actions == NULL)
1284 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1285 if (actions->type == action)
1291 * Validate the flag action.
1293 * @param[in] action_flags
1294 * Bit-fields that holds the actions detected until now.
1296 * Attributes of flow that includes this action.
1298 * Pointer to error structure.
1301 * 0 on success, a negative errno value otherwise and rte_errno is set.
1304 mlx5_flow_validate_action_flag(uint64_t action_flags,
1305 const struct rte_flow_attr *attr,
1306 struct rte_flow_error *error)
1308 if (action_flags & MLX5_FLOW_ACTION_MARK)
1309 return rte_flow_error_set(error, EINVAL,
1310 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1311 "can't mark and flag in same flow");
1312 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1313 return rte_flow_error_set(error, EINVAL,
1314 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1316 " actions in same flow");
1318 return rte_flow_error_set(error, ENOTSUP,
1319 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1320 "flag action not supported for "
1326 * Validate the mark action.
1329 * Pointer to the queue action.
1330 * @param[in] action_flags
1331 * Bit-fields that holds the actions detected until now.
1333 * Attributes of flow that includes this action.
1335 * Pointer to error structure.
1338 * 0 on success, a negative errno value otherwise and rte_errno is set.
1341 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1342 uint64_t action_flags,
1343 const struct rte_flow_attr *attr,
1344 struct rte_flow_error *error)
1346 const struct rte_flow_action_mark *mark = action->conf;
1349 return rte_flow_error_set(error, EINVAL,
1350 RTE_FLOW_ERROR_TYPE_ACTION,
1352 "configuration cannot be null");
1353 if (mark->id >= MLX5_FLOW_MARK_MAX)
1354 return rte_flow_error_set(error, EINVAL,
1355 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1357 "mark id must in 0 <= id < "
1358 RTE_STR(MLX5_FLOW_MARK_MAX));
1359 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1360 return rte_flow_error_set(error, EINVAL,
1361 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1362 "can't flag and mark in same flow");
1363 if (action_flags & MLX5_FLOW_ACTION_MARK)
1364 return rte_flow_error_set(error, EINVAL,
1365 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1366 "can't have 2 mark actions in same"
1369 return rte_flow_error_set(error, ENOTSUP,
1370 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1371 "mark action not supported for "
1377 * Validate the drop action.
1379 * @param[in] action_flags
1380 * Bit-fields that holds the actions detected until now.
1382 * Attributes of flow that includes this action.
1384 * Pointer to error structure.
1387 * 0 on success, a negative errno value otherwise and rte_errno is set.
1390 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1391 const struct rte_flow_attr *attr,
1392 struct rte_flow_error *error)
1395 return rte_flow_error_set(error, ENOTSUP,
1396 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1397 "drop action not supported for "
1403 * Validate the queue action.
1406 * Pointer to the queue action.
1407 * @param[in] action_flags
1408 * Bit-fields that holds the actions detected until now.
1410 * Pointer to the Ethernet device structure.
1412 * Attributes of flow that includes this action.
1414 * Pointer to error structure.
1417 * 0 on success, a negative errno value otherwise and rte_errno is set.
1420 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1421 uint64_t action_flags,
1422 struct rte_eth_dev *dev,
1423 const struct rte_flow_attr *attr,
1424 struct rte_flow_error *error)
1426 struct mlx5_priv *priv = dev->data->dev_private;
1427 const struct rte_flow_action_queue *queue = action->conf;
1429 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1430 return rte_flow_error_set(error, EINVAL,
1431 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1432 "can't have 2 fate actions in"
1435 return rte_flow_error_set(error, EINVAL,
1436 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1437 NULL, "No Rx queues configured");
1438 if (queue->index >= priv->rxqs_n)
1439 return rte_flow_error_set(error, EINVAL,
1440 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1442 "queue index out of range");
1443 if (!(*priv->rxqs)[queue->index])
1444 return rte_flow_error_set(error, EINVAL,
1445 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1447 "queue is not configured");
1449 return rte_flow_error_set(error, ENOTSUP,
1450 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1451 "queue action not supported for "
1457 * Validate the rss action.
1460 * Pointer to the Ethernet device structure.
1462 * Pointer to the queue action.
1464 * Pointer to error structure.
1467 * 0 on success, a negative errno value otherwise and rte_errno is set.
1470 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1471 const struct rte_flow_action *action,
1472 struct rte_flow_error *error)
1474 struct mlx5_priv *priv = dev->data->dev_private;
1475 const struct rte_flow_action_rss *rss = action->conf;
1476 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1479 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1480 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1481 return rte_flow_error_set(error, ENOTSUP,
1482 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1484 "RSS hash function not supported");
1485 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1490 return rte_flow_error_set(error, ENOTSUP,
1491 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1493 "tunnel RSS is not supported");
1494 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1495 if (rss->key_len == 0 && rss->key != NULL)
1496 return rte_flow_error_set(error, ENOTSUP,
1497 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1499 "RSS hash key length 0");
1500 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1501 return rte_flow_error_set(error, ENOTSUP,
1502 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1504 "RSS hash key too small");
1505 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1506 return rte_flow_error_set(error, ENOTSUP,
1507 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1509 "RSS hash key too large");
1510 if (rss->queue_num > priv->config.ind_table_max_size)
1511 return rte_flow_error_set(error, ENOTSUP,
1512 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1514 "number of queues too large");
1515 if (rss->types & MLX5_RSS_HF_MASK)
1516 return rte_flow_error_set(error, ENOTSUP,
1517 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1519 "some RSS protocols are not"
1521 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1522 !(rss->types & ETH_RSS_IP))
1523 return rte_flow_error_set(error, EINVAL,
1524 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1525 "L3 partial RSS requested but L3 RSS"
1526 " type not specified");
1527 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1528 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1529 return rte_flow_error_set(error, EINVAL,
1530 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1531 "L4 partial RSS requested but L4 RSS"
1532 " type not specified");
1534 return rte_flow_error_set(error, EINVAL,
1535 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1536 NULL, "No Rx queues configured");
1537 if (!rss->queue_num)
1538 return rte_flow_error_set(error, EINVAL,
1539 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1540 NULL, "No queues configured");
1541 for (i = 0; i != rss->queue_num; ++i) {
1542 struct mlx5_rxq_ctrl *rxq_ctrl;
1544 if (rss->queue[i] >= priv->rxqs_n)
1545 return rte_flow_error_set
1547 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1548 &rss->queue[i], "queue index out of range");
1549 if (!(*priv->rxqs)[rss->queue[i]])
1550 return rte_flow_error_set
1551 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1552 &rss->queue[i], "queue is not configured");
1553 rxq_ctrl = container_of((*priv->rxqs)[rss->queue[i]],
1554 struct mlx5_rxq_ctrl, rxq);
1556 rxq_type = rxq_ctrl->type;
1557 if (rxq_type != rxq_ctrl->type)
1558 return rte_flow_error_set
1559 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1561 "combining hairpin and regular RSS queues is not supported");
1567 * Validate the rss action.
1570 * Pointer to the queue action.
1571 * @param[in] action_flags
1572 * Bit-fields that holds the actions detected until now.
1574 * Pointer to the Ethernet device structure.
1576 * Attributes of flow that includes this action.
1577 * @param[in] item_flags
1578 * Items that were detected.
1580 * Pointer to error structure.
1583 * 0 on success, a negative errno value otherwise and rte_errno is set.
1586 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1587 uint64_t action_flags,
1588 struct rte_eth_dev *dev,
1589 const struct rte_flow_attr *attr,
1590 uint64_t item_flags,
1591 struct rte_flow_error *error)
1593 const struct rte_flow_action_rss *rss = action->conf;
1594 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1597 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1598 return rte_flow_error_set(error, EINVAL,
1599 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1600 "can't have 2 fate actions"
1602 ret = mlx5_validate_action_rss(dev, action, error);
1606 return rte_flow_error_set(error, ENOTSUP,
1607 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1608 "rss action not supported for "
1610 if (rss->level > 1 && !tunnel)
1611 return rte_flow_error_set(error, EINVAL,
1612 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1613 "inner RSS is not supported for "
1614 "non-tunnel flows");
1615 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1616 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1617 return rte_flow_error_set(error, EINVAL,
1618 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1619 "RSS on eCPRI is not supported now");
1625 * Validate the default miss action.
1627 * @param[in] action_flags
1628 * Bit-fields that holds the actions detected until now.
1630 * Pointer to error structure.
1633 * 0 on success, a negative errno value otherwise and rte_errno is set.
1636 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1637 const struct rte_flow_attr *attr,
1638 struct rte_flow_error *error)
1640 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1641 return rte_flow_error_set(error, EINVAL,
1642 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1643 "can't have 2 fate actions in"
1646 return rte_flow_error_set(error, ENOTSUP,
1647 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1648 "default miss action not supported "
1651 return rte_flow_error_set(error, ENOTSUP,
1652 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1653 "only group 0 is supported");
1655 return rte_flow_error_set(error, ENOTSUP,
1656 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1657 NULL, "transfer is not supported");
1662 * Validate the count action.
1665 * Pointer to the Ethernet device structure.
1667 * Attributes of flow that includes this action.
1669 * Pointer to error structure.
1672 * 0 on success, a negative errno value otherwise and rte_errno is set.
1675 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1676 const struct rte_flow_attr *attr,
1677 struct rte_flow_error *error)
1680 return rte_flow_error_set(error, ENOTSUP,
1681 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1682 "count action not supported for "
1688 * Verify the @p attributes will be correctly understood by the NIC and store
1689 * them in the @p flow if everything is correct.
1692 * Pointer to the Ethernet device structure.
1693 * @param[in] attributes
1694 * Pointer to flow attributes
1696 * Pointer to error structure.
1699 * 0 on success, a negative errno value otherwise and rte_errno is set.
1702 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1703 const struct rte_flow_attr *attributes,
1704 struct rte_flow_error *error)
1706 struct mlx5_priv *priv = dev->data->dev_private;
1707 uint32_t priority_max = priv->config.flow_prio - 1;
1709 if (attributes->group)
1710 return rte_flow_error_set(error, ENOTSUP,
1711 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1712 NULL, "groups is not supported");
1713 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
1714 attributes->priority >= priority_max)
1715 return rte_flow_error_set(error, ENOTSUP,
1716 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1717 NULL, "priority out of range");
1718 if (attributes->egress)
1719 return rte_flow_error_set(error, ENOTSUP,
1720 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1721 "egress is not supported");
1722 if (attributes->transfer && !priv->config.dv_esw_en)
1723 return rte_flow_error_set(error, ENOTSUP,
1724 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1725 NULL, "transfer is not supported");
1726 if (!attributes->ingress)
1727 return rte_flow_error_set(error, EINVAL,
1728 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1730 "ingress attribute is mandatory");
1735 * Validate ICMP6 item.
1738 * Item specification.
1739 * @param[in] item_flags
1740 * Bit-fields that holds the items detected until now.
1741 * @param[in] ext_vlan_sup
1742 * Whether extended VLAN features are supported or not.
1744 * Pointer to error structure.
1747 * 0 on success, a negative errno value otherwise and rte_errno is set.
1750 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1751 uint64_t item_flags,
1752 uint8_t target_protocol,
1753 struct rte_flow_error *error)
1755 const struct rte_flow_item_icmp6 *mask = item->mask;
1756 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1757 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1758 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1759 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1760 MLX5_FLOW_LAYER_OUTER_L4;
1763 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1764 return rte_flow_error_set(error, EINVAL,
1765 RTE_FLOW_ERROR_TYPE_ITEM, item,
1766 "protocol filtering not compatible"
1767 " with ICMP6 layer");
1768 if (!(item_flags & l3m))
1769 return rte_flow_error_set(error, EINVAL,
1770 RTE_FLOW_ERROR_TYPE_ITEM, item,
1771 "IPv6 is mandatory to filter on"
1773 if (item_flags & l4m)
1774 return rte_flow_error_set(error, EINVAL,
1775 RTE_FLOW_ERROR_TYPE_ITEM, item,
1776 "multiple L4 layers not supported");
1778 mask = &rte_flow_item_icmp6_mask;
1779 ret = mlx5_flow_item_acceptable
1780 (item, (const uint8_t *)mask,
1781 (const uint8_t *)&rte_flow_item_icmp6_mask,
1782 sizeof(struct rte_flow_item_icmp6),
1783 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1790 * Validate ICMP item.
1793 * Item specification.
1794 * @param[in] item_flags
1795 * Bit-fields that holds the items detected until now.
1797 * Pointer to error structure.
1800 * 0 on success, a negative errno value otherwise and rte_errno is set.
1803 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1804 uint64_t item_flags,
1805 uint8_t target_protocol,
1806 struct rte_flow_error *error)
1808 const struct rte_flow_item_icmp *mask = item->mask;
1809 const struct rte_flow_item_icmp nic_mask = {
1810 .hdr.icmp_type = 0xff,
1811 .hdr.icmp_code = 0xff,
1812 .hdr.icmp_ident = RTE_BE16(0xffff),
1813 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1815 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1816 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1817 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1818 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1819 MLX5_FLOW_LAYER_OUTER_L4;
1822 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1823 return rte_flow_error_set(error, EINVAL,
1824 RTE_FLOW_ERROR_TYPE_ITEM, item,
1825 "protocol filtering not compatible"
1826 " with ICMP layer");
1827 if (!(item_flags & l3m))
1828 return rte_flow_error_set(error, EINVAL,
1829 RTE_FLOW_ERROR_TYPE_ITEM, item,
1830 "IPv4 is mandatory to filter"
1832 if (item_flags & l4m)
1833 return rte_flow_error_set(error, EINVAL,
1834 RTE_FLOW_ERROR_TYPE_ITEM, item,
1835 "multiple L4 layers not supported");
1838 ret = mlx5_flow_item_acceptable
1839 (item, (const uint8_t *)mask,
1840 (const uint8_t *)&nic_mask,
1841 sizeof(struct rte_flow_item_icmp),
1842 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1849 * Validate Ethernet item.
1852 * Item specification.
1853 * @param[in] item_flags
1854 * Bit-fields that holds the items detected until now.
1856 * Pointer to error structure.
1859 * 0 on success, a negative errno value otherwise and rte_errno is set.
1862 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1863 uint64_t item_flags, bool ext_vlan_sup,
1864 struct rte_flow_error *error)
1866 const struct rte_flow_item_eth *mask = item->mask;
1867 const struct rte_flow_item_eth nic_mask = {
1868 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1869 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1870 .type = RTE_BE16(0xffff),
1871 .has_vlan = ext_vlan_sup ? 1 : 0,
1874 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1875 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1876 MLX5_FLOW_LAYER_OUTER_L2;
1878 if (item_flags & ethm)
1879 return rte_flow_error_set(error, ENOTSUP,
1880 RTE_FLOW_ERROR_TYPE_ITEM, item,
1881 "multiple L2 layers not supported");
1882 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1883 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1884 return rte_flow_error_set(error, EINVAL,
1885 RTE_FLOW_ERROR_TYPE_ITEM, item,
1886 "L2 layer should not follow "
1888 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1889 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1890 return rte_flow_error_set(error, EINVAL,
1891 RTE_FLOW_ERROR_TYPE_ITEM, item,
1892 "L2 layer should not follow VLAN");
1894 mask = &rte_flow_item_eth_mask;
1895 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1896 (const uint8_t *)&nic_mask,
1897 sizeof(struct rte_flow_item_eth),
1898 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1903 * Validate VLAN item.
1906 * Item specification.
1907 * @param[in] item_flags
1908 * Bit-fields that holds the items detected until now.
1910 * Ethernet device flow is being created on.
1912 * Pointer to error structure.
1915 * 0 on success, a negative errno value otherwise and rte_errno is set.
1918 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1919 uint64_t item_flags,
1920 struct rte_eth_dev *dev,
1921 struct rte_flow_error *error)
1923 const struct rte_flow_item_vlan *spec = item->spec;
1924 const struct rte_flow_item_vlan *mask = item->mask;
1925 const struct rte_flow_item_vlan nic_mask = {
1926 .tci = RTE_BE16(UINT16_MAX),
1927 .inner_type = RTE_BE16(UINT16_MAX),
1929 uint16_t vlan_tag = 0;
1930 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1932 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1933 MLX5_FLOW_LAYER_INNER_L4) :
1934 (MLX5_FLOW_LAYER_OUTER_L3 |
1935 MLX5_FLOW_LAYER_OUTER_L4);
1936 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1937 MLX5_FLOW_LAYER_OUTER_VLAN;
1939 if (item_flags & vlanm)
1940 return rte_flow_error_set(error, EINVAL,
1941 RTE_FLOW_ERROR_TYPE_ITEM, item,
1942 "multiple VLAN layers not supported");
1943 else if ((item_flags & l34m) != 0)
1944 return rte_flow_error_set(error, EINVAL,
1945 RTE_FLOW_ERROR_TYPE_ITEM, item,
1946 "VLAN cannot follow L3/L4 layer");
1948 mask = &rte_flow_item_vlan_mask;
1949 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1950 (const uint8_t *)&nic_mask,
1951 sizeof(struct rte_flow_item_vlan),
1952 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1955 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1956 struct mlx5_priv *priv = dev->data->dev_private;
1958 if (priv->vmwa_context) {
1960 * Non-NULL context means we have a virtual machine
1961 * and SR-IOV enabled, we have to create VLAN interface
1962 * to make hypervisor to setup E-Switch vport
1963 * context correctly. We avoid creating the multiple
1964 * VLAN interfaces, so we cannot support VLAN tag mask.
1966 return rte_flow_error_set(error, EINVAL,
1967 RTE_FLOW_ERROR_TYPE_ITEM,
1969 "VLAN tag mask is not"
1970 " supported in virtual"
1975 vlan_tag = spec->tci;
1976 vlan_tag &= mask->tci;
1979 * From verbs perspective an empty VLAN is equivalent
1980 * to a packet without VLAN layer.
1983 return rte_flow_error_set(error, EINVAL,
1984 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1986 "VLAN cannot be empty");
1991 * Validate IPV4 item.
1994 * Item specification.
1995 * @param[in] item_flags
1996 * Bit-fields that holds the items detected until now.
1997 * @param[in] last_item
1998 * Previous validated item in the pattern items.
1999 * @param[in] ether_type
2000 * Type in the ethernet layer header (including dot1q).
2001 * @param[in] acc_mask
2002 * Acceptable mask, if NULL default internal default mask
2003 * will be used to check whether item fields are supported.
2004 * @param[in] range_accepted
2005 * True if range of values is accepted for specific fields, false otherwise.
2007 * Pointer to error structure.
2010 * 0 on success, a negative errno value otherwise and rte_errno is set.
2013 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2014 uint64_t item_flags,
2016 uint16_t ether_type,
2017 const struct rte_flow_item_ipv4 *acc_mask,
2018 bool range_accepted,
2019 struct rte_flow_error *error)
2021 const struct rte_flow_item_ipv4 *mask = item->mask;
2022 const struct rte_flow_item_ipv4 *spec = item->spec;
2023 const struct rte_flow_item_ipv4 nic_mask = {
2025 .src_addr = RTE_BE32(0xffffffff),
2026 .dst_addr = RTE_BE32(0xffffffff),
2027 .type_of_service = 0xff,
2028 .next_proto_id = 0xff,
2031 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2032 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2033 MLX5_FLOW_LAYER_OUTER_L3;
2034 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2035 MLX5_FLOW_LAYER_OUTER_L4;
2037 uint8_t next_proto = 0xFF;
2038 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2039 MLX5_FLOW_LAYER_OUTER_VLAN |
2040 MLX5_FLOW_LAYER_INNER_VLAN);
2042 if ((last_item & l2_vlan) && ether_type &&
2043 ether_type != RTE_ETHER_TYPE_IPV4)
2044 return rte_flow_error_set(error, EINVAL,
2045 RTE_FLOW_ERROR_TYPE_ITEM, item,
2046 "IPv4 cannot follow L2/VLAN layer "
2047 "which ether type is not IPv4");
2048 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2050 next_proto = mask->hdr.next_proto_id &
2051 spec->hdr.next_proto_id;
2052 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2053 return rte_flow_error_set(error, EINVAL,
2054 RTE_FLOW_ERROR_TYPE_ITEM,
2059 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2060 return rte_flow_error_set(error, EINVAL,
2061 RTE_FLOW_ERROR_TYPE_ITEM, item,
2062 "wrong tunnel type - IPv6 specified "
2063 "but IPv4 item provided");
2064 if (item_flags & l3m)
2065 return rte_flow_error_set(error, ENOTSUP,
2066 RTE_FLOW_ERROR_TYPE_ITEM, item,
2067 "multiple L3 layers not supported");
2068 else if (item_flags & l4m)
2069 return rte_flow_error_set(error, EINVAL,
2070 RTE_FLOW_ERROR_TYPE_ITEM, item,
2071 "L3 cannot follow an L4 layer.");
2072 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2073 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2074 return rte_flow_error_set(error, EINVAL,
2075 RTE_FLOW_ERROR_TYPE_ITEM, item,
2076 "L3 cannot follow an NVGRE layer.");
2078 mask = &rte_flow_item_ipv4_mask;
2079 else if (mask->hdr.next_proto_id != 0 &&
2080 mask->hdr.next_proto_id != 0xff)
2081 return rte_flow_error_set(error, EINVAL,
2082 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2083 "partial mask is not supported"
2085 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2086 acc_mask ? (const uint8_t *)acc_mask
2087 : (const uint8_t *)&nic_mask,
2088 sizeof(struct rte_flow_item_ipv4),
2089 range_accepted, error);
2096 * Validate IPV6 item.
2099 * Item specification.
2100 * @param[in] item_flags
2101 * Bit-fields that holds the items detected until now.
2102 * @param[in] last_item
2103 * Previous validated item in the pattern items.
2104 * @param[in] ether_type
2105 * Type in the ethernet layer header (including dot1q).
2106 * @param[in] acc_mask
2107 * Acceptable mask, if NULL default internal default mask
2108 * will be used to check whether item fields are supported.
2110 * Pointer to error structure.
2113 * 0 on success, a negative errno value otherwise and rte_errno is set.
2116 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2117 uint64_t item_flags,
2119 uint16_t ether_type,
2120 const struct rte_flow_item_ipv6 *acc_mask,
2121 struct rte_flow_error *error)
2123 const struct rte_flow_item_ipv6 *mask = item->mask;
2124 const struct rte_flow_item_ipv6 *spec = item->spec;
2125 const struct rte_flow_item_ipv6 nic_mask = {
2128 "\xff\xff\xff\xff\xff\xff\xff\xff"
2129 "\xff\xff\xff\xff\xff\xff\xff\xff",
2131 "\xff\xff\xff\xff\xff\xff\xff\xff"
2132 "\xff\xff\xff\xff\xff\xff\xff\xff",
2133 .vtc_flow = RTE_BE32(0xffffffff),
2137 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2138 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2139 MLX5_FLOW_LAYER_OUTER_L3;
2140 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2141 MLX5_FLOW_LAYER_OUTER_L4;
2143 uint8_t next_proto = 0xFF;
2144 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2145 MLX5_FLOW_LAYER_OUTER_VLAN |
2146 MLX5_FLOW_LAYER_INNER_VLAN);
2148 if ((last_item & l2_vlan) && ether_type &&
2149 ether_type != RTE_ETHER_TYPE_IPV6)
2150 return rte_flow_error_set(error, EINVAL,
2151 RTE_FLOW_ERROR_TYPE_ITEM, item,
2152 "IPv6 cannot follow L2/VLAN layer "
2153 "which ether type is not IPv6");
2154 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2155 next_proto = spec->hdr.proto;
2156 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
2157 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2158 return rte_flow_error_set(error, EINVAL,
2159 RTE_FLOW_ERROR_TYPE_ITEM,
2164 if (next_proto == IPPROTO_HOPOPTS ||
2165 next_proto == IPPROTO_ROUTING ||
2166 next_proto == IPPROTO_FRAGMENT ||
2167 next_proto == IPPROTO_ESP ||
2168 next_proto == IPPROTO_AH ||
2169 next_proto == IPPROTO_DSTOPTS)
2170 return rte_flow_error_set(error, EINVAL,
2171 RTE_FLOW_ERROR_TYPE_ITEM, item,
2172 "IPv6 proto (next header) should "
2173 "not be set as extension header");
2174 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2175 return rte_flow_error_set(error, EINVAL,
2176 RTE_FLOW_ERROR_TYPE_ITEM, item,
2177 "wrong tunnel type - IPv4 specified "
2178 "but IPv6 item provided");
2179 if (item_flags & l3m)
2180 return rte_flow_error_set(error, ENOTSUP,
2181 RTE_FLOW_ERROR_TYPE_ITEM, item,
2182 "multiple L3 layers not supported");
2183 else if (item_flags & l4m)
2184 return rte_flow_error_set(error, EINVAL,
2185 RTE_FLOW_ERROR_TYPE_ITEM, item,
2186 "L3 cannot follow an L4 layer.");
2187 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2188 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2189 return rte_flow_error_set(error, EINVAL,
2190 RTE_FLOW_ERROR_TYPE_ITEM, item,
2191 "L3 cannot follow an NVGRE layer.");
2193 mask = &rte_flow_item_ipv6_mask;
2194 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2195 acc_mask ? (const uint8_t *)acc_mask
2196 : (const uint8_t *)&nic_mask,
2197 sizeof(struct rte_flow_item_ipv6),
2198 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2205 * Validate UDP item.
2208 * Item specification.
2209 * @param[in] item_flags
2210 * Bit-fields that holds the items detected until now.
2211 * @param[in] target_protocol
2212 * The next protocol in the previous item.
2213 * @param[in] flow_mask
2214 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2216 * Pointer to error structure.
2219 * 0 on success, a negative errno value otherwise and rte_errno is set.
2222 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2223 uint64_t item_flags,
2224 uint8_t target_protocol,
2225 struct rte_flow_error *error)
2227 const struct rte_flow_item_udp *mask = item->mask;
2228 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2229 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2230 MLX5_FLOW_LAYER_OUTER_L3;
2231 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2232 MLX5_FLOW_LAYER_OUTER_L4;
2235 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2236 return rte_flow_error_set(error, EINVAL,
2237 RTE_FLOW_ERROR_TYPE_ITEM, item,
2238 "protocol filtering not compatible"
2240 if (!(item_flags & l3m))
2241 return rte_flow_error_set(error, EINVAL,
2242 RTE_FLOW_ERROR_TYPE_ITEM, item,
2243 "L3 is mandatory to filter on L4");
2244 if (item_flags & l4m)
2245 return rte_flow_error_set(error, EINVAL,
2246 RTE_FLOW_ERROR_TYPE_ITEM, item,
2247 "multiple L4 layers not supported");
2249 mask = &rte_flow_item_udp_mask;
2250 ret = mlx5_flow_item_acceptable
2251 (item, (const uint8_t *)mask,
2252 (const uint8_t *)&rte_flow_item_udp_mask,
2253 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2261 * Validate TCP item.
2264 * Item specification.
2265 * @param[in] item_flags
2266 * Bit-fields that holds the items detected until now.
2267 * @param[in] target_protocol
2268 * The next protocol in the previous item.
2270 * Pointer to error structure.
2273 * 0 on success, a negative errno value otherwise and rte_errno is set.
2276 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2277 uint64_t item_flags,
2278 uint8_t target_protocol,
2279 const struct rte_flow_item_tcp *flow_mask,
2280 struct rte_flow_error *error)
2282 const struct rte_flow_item_tcp *mask = item->mask;
2283 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2284 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2285 MLX5_FLOW_LAYER_OUTER_L3;
2286 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2287 MLX5_FLOW_LAYER_OUTER_L4;
2290 MLX5_ASSERT(flow_mask);
2291 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2292 return rte_flow_error_set(error, EINVAL,
2293 RTE_FLOW_ERROR_TYPE_ITEM, item,
2294 "protocol filtering not compatible"
2296 if (!(item_flags & l3m))
2297 return rte_flow_error_set(error, EINVAL,
2298 RTE_FLOW_ERROR_TYPE_ITEM, item,
2299 "L3 is mandatory to filter on L4");
2300 if (item_flags & l4m)
2301 return rte_flow_error_set(error, EINVAL,
2302 RTE_FLOW_ERROR_TYPE_ITEM, item,
2303 "multiple L4 layers not supported");
2305 mask = &rte_flow_item_tcp_mask;
2306 ret = mlx5_flow_item_acceptable
2307 (item, (const uint8_t *)mask,
2308 (const uint8_t *)flow_mask,
2309 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2317 * Validate VXLAN item.
2320 * Item specification.
2321 * @param[in] item_flags
2322 * Bit-fields that holds the items detected until now.
2323 * @param[in] target_protocol
2324 * The next protocol in the previous item.
2326 * Pointer to error structure.
2329 * 0 on success, a negative errno value otherwise and rte_errno is set.
2332 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
2333 uint64_t item_flags,
2334 struct rte_flow_error *error)
2336 const struct rte_flow_item_vxlan *spec = item->spec;
2337 const struct rte_flow_item_vxlan *mask = item->mask;
2342 } id = { .vlan_id = 0, };
2345 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2346 return rte_flow_error_set(error, ENOTSUP,
2347 RTE_FLOW_ERROR_TYPE_ITEM, item,
2348 "multiple tunnel layers not"
2351 * Verify only UDPv4 is present as defined in
2352 * https://tools.ietf.org/html/rfc7348
2354 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2355 return rte_flow_error_set(error, EINVAL,
2356 RTE_FLOW_ERROR_TYPE_ITEM, item,
2357 "no outer UDP layer found");
2359 mask = &rte_flow_item_vxlan_mask;
2360 ret = mlx5_flow_item_acceptable
2361 (item, (const uint8_t *)mask,
2362 (const uint8_t *)&rte_flow_item_vxlan_mask,
2363 sizeof(struct rte_flow_item_vxlan),
2364 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2368 memcpy(&id.vni[1], spec->vni, 3);
2369 memcpy(&id.vni[1], mask->vni, 3);
2371 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2372 return rte_flow_error_set(error, ENOTSUP,
2373 RTE_FLOW_ERROR_TYPE_ITEM, item,
2374 "VXLAN tunnel must be fully defined");
2379 * Validate VXLAN_GPE item.
2382 * Item specification.
2383 * @param[in] item_flags
2384 * Bit-fields that holds the items detected until now.
2386 * Pointer to the private data structure.
2387 * @param[in] target_protocol
2388 * The next protocol in the previous item.
2390 * Pointer to error structure.
2393 * 0 on success, a negative errno value otherwise and rte_errno is set.
2396 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2397 uint64_t item_flags,
2398 struct rte_eth_dev *dev,
2399 struct rte_flow_error *error)
2401 struct mlx5_priv *priv = dev->data->dev_private;
2402 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2403 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2408 } id = { .vlan_id = 0, };
2410 if (!priv->config.l3_vxlan_en)
2411 return rte_flow_error_set(error, ENOTSUP,
2412 RTE_FLOW_ERROR_TYPE_ITEM, item,
2413 "L3 VXLAN is not enabled by device"
2414 " parameter and/or not configured in"
2416 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2417 return rte_flow_error_set(error, ENOTSUP,
2418 RTE_FLOW_ERROR_TYPE_ITEM, item,
2419 "multiple tunnel layers not"
2422 * Verify only UDPv4 is present as defined in
2423 * https://tools.ietf.org/html/rfc7348
2425 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2426 return rte_flow_error_set(error, EINVAL,
2427 RTE_FLOW_ERROR_TYPE_ITEM, item,
2428 "no outer UDP layer found");
2430 mask = &rte_flow_item_vxlan_gpe_mask;
2431 ret = mlx5_flow_item_acceptable
2432 (item, (const uint8_t *)mask,
2433 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2434 sizeof(struct rte_flow_item_vxlan_gpe),
2435 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2440 return rte_flow_error_set(error, ENOTSUP,
2441 RTE_FLOW_ERROR_TYPE_ITEM,
2443 "VxLAN-GPE protocol"
2445 memcpy(&id.vni[1], spec->vni, 3);
2446 memcpy(&id.vni[1], mask->vni, 3);
2448 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2449 return rte_flow_error_set(error, ENOTSUP,
2450 RTE_FLOW_ERROR_TYPE_ITEM, item,
2451 "VXLAN-GPE tunnel must be fully"
2456 * Validate GRE Key item.
2459 * Item specification.
2460 * @param[in] item_flags
2461 * Bit flags to mark detected items.
2462 * @param[in] gre_item
2463 * Pointer to gre_item
2465 * Pointer to error structure.
2468 * 0 on success, a negative errno value otherwise and rte_errno is set.
2471 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2472 uint64_t item_flags,
2473 const struct rte_flow_item *gre_item,
2474 struct rte_flow_error *error)
2476 const rte_be32_t *mask = item->mask;
2478 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2479 const struct rte_flow_item_gre *gre_spec;
2480 const struct rte_flow_item_gre *gre_mask;
2482 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2483 return rte_flow_error_set(error, ENOTSUP,
2484 RTE_FLOW_ERROR_TYPE_ITEM, item,
2485 "Multiple GRE key not support");
2486 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2487 return rte_flow_error_set(error, ENOTSUP,
2488 RTE_FLOW_ERROR_TYPE_ITEM, item,
2489 "No preceding GRE header");
2490 if (item_flags & MLX5_FLOW_LAYER_INNER)
2491 return rte_flow_error_set(error, ENOTSUP,
2492 RTE_FLOW_ERROR_TYPE_ITEM, item,
2493 "GRE key following a wrong item");
2494 gre_mask = gre_item->mask;
2496 gre_mask = &rte_flow_item_gre_mask;
2497 gre_spec = gre_item->spec;
2498 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2499 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2500 return rte_flow_error_set(error, EINVAL,
2501 RTE_FLOW_ERROR_TYPE_ITEM, item,
2502 "Key bit must be on");
2505 mask = &gre_key_default_mask;
2506 ret = mlx5_flow_item_acceptable
2507 (item, (const uint8_t *)mask,
2508 (const uint8_t *)&gre_key_default_mask,
2509 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2514 * Validate GRE item.
2517 * Item specification.
2518 * @param[in] item_flags
2519 * Bit flags to mark detected items.
2520 * @param[in] target_protocol
2521 * The next protocol in the previous item.
2523 * Pointer to error structure.
2526 * 0 on success, a negative errno value otherwise and rte_errno is set.
2529 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2530 uint64_t item_flags,
2531 uint8_t target_protocol,
2532 struct rte_flow_error *error)
2534 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2535 const struct rte_flow_item_gre *mask = item->mask;
2537 const struct rte_flow_item_gre nic_mask = {
2538 .c_rsvd0_ver = RTE_BE16(0xB000),
2539 .protocol = RTE_BE16(UINT16_MAX),
2542 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2543 return rte_flow_error_set(error, EINVAL,
2544 RTE_FLOW_ERROR_TYPE_ITEM, item,
2545 "protocol filtering not compatible"
2546 " with this GRE layer");
2547 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2548 return rte_flow_error_set(error, ENOTSUP,
2549 RTE_FLOW_ERROR_TYPE_ITEM, item,
2550 "multiple tunnel layers not"
2552 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2553 return rte_flow_error_set(error, ENOTSUP,
2554 RTE_FLOW_ERROR_TYPE_ITEM, item,
2555 "L3 Layer is missing");
2557 mask = &rte_flow_item_gre_mask;
2558 ret = mlx5_flow_item_acceptable
2559 (item, (const uint8_t *)mask,
2560 (const uint8_t *)&nic_mask,
2561 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2565 #ifndef HAVE_MLX5DV_DR
2566 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2567 if (spec && (spec->protocol & mask->protocol))
2568 return rte_flow_error_set(error, ENOTSUP,
2569 RTE_FLOW_ERROR_TYPE_ITEM, item,
2570 "without MPLS support the"
2571 " specification cannot be used for"
2579 * Validate Geneve item.
2582 * Item specification.
2583 * @param[in] itemFlags
2584 * Bit-fields that holds the items detected until now.
2586 * Pointer to the private data structure.
2588 * Pointer to error structure.
2591 * 0 on success, a negative errno value otherwise and rte_errno is set.
2595 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2596 uint64_t item_flags,
2597 struct rte_eth_dev *dev,
2598 struct rte_flow_error *error)
2600 struct mlx5_priv *priv = dev->data->dev_private;
2601 const struct rte_flow_item_geneve *spec = item->spec;
2602 const struct rte_flow_item_geneve *mask = item->mask;
2605 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2606 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2607 const struct rte_flow_item_geneve nic_mask = {
2608 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2609 .vni = "\xff\xff\xff",
2610 .protocol = RTE_BE16(UINT16_MAX),
2613 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2614 return rte_flow_error_set(error, ENOTSUP,
2615 RTE_FLOW_ERROR_TYPE_ITEM, item,
2616 "L3 Geneve is not enabled by device"
2617 " parameter and/or not configured in"
2619 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2620 return rte_flow_error_set(error, ENOTSUP,
2621 RTE_FLOW_ERROR_TYPE_ITEM, item,
2622 "multiple tunnel layers not"
2625 * Verify only UDPv4 is present as defined in
2626 * https://tools.ietf.org/html/rfc7348
2628 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2629 return rte_flow_error_set(error, EINVAL,
2630 RTE_FLOW_ERROR_TYPE_ITEM, item,
2631 "no outer UDP layer found");
2633 mask = &rte_flow_item_geneve_mask;
2634 ret = mlx5_flow_item_acceptable
2635 (item, (const uint8_t *)mask,
2636 (const uint8_t *)&nic_mask,
2637 sizeof(struct rte_flow_item_geneve),
2638 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2642 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2643 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2644 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2645 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2646 return rte_flow_error_set(error, ENOTSUP,
2647 RTE_FLOW_ERROR_TYPE_ITEM,
2649 "Geneve protocol unsupported"
2650 " fields are being used");
2651 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2652 return rte_flow_error_set
2654 RTE_FLOW_ERROR_TYPE_ITEM,
2656 "Unsupported Geneve options length");
2658 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2659 return rte_flow_error_set
2661 RTE_FLOW_ERROR_TYPE_ITEM, item,
2662 "Geneve tunnel must be fully defined");
2667 * Validate Geneve TLV option item.
2670 * Item specification.
2671 * @param[in] last_item
2672 * Previous validated item in the pattern items.
2673 * @param[in] geneve_item
2674 * Previous GENEVE item specification.
2676 * Pointer to the rte_eth_dev structure.
2678 * Pointer to error structure.
2681 * 0 on success, a negative errno value otherwise and rte_errno is set.
2684 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
2686 const struct rte_flow_item *geneve_item,
2687 struct rte_eth_dev *dev,
2688 struct rte_flow_error *error)
2690 struct mlx5_priv *priv = dev->data->dev_private;
2691 struct mlx5_dev_ctx_shared *sh = priv->sh;
2692 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
2693 struct mlx5_hca_attr *hca_attr = &priv->config.hca_attr;
2694 uint8_t data_max_supported =
2695 hca_attr->max_geneve_tlv_option_data_len * 4;
2696 struct mlx5_dev_config *config = &priv->config;
2697 const struct rte_flow_item_geneve *geneve_spec;
2698 const struct rte_flow_item_geneve *geneve_mask;
2699 const struct rte_flow_item_geneve_opt *spec = item->spec;
2700 const struct rte_flow_item_geneve_opt *mask = item->mask;
2702 unsigned int data_len;
2703 uint8_t tlv_option_len;
2704 uint16_t optlen_m, optlen_v;
2705 const struct rte_flow_item_geneve_opt full_mask = {
2706 .option_class = RTE_BE16(0xffff),
2707 .option_type = 0xff,
2712 mask = &rte_flow_item_geneve_opt_mask;
2714 return rte_flow_error_set
2715 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2716 "Geneve TLV opt class/type/length must be specified");
2717 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
2718 return rte_flow_error_set
2719 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2720 "Geneve TLV opt length exceeeds the limit (31)");
2721 /* Check if class type and length masks are full. */
2722 if (full_mask.option_class != mask->option_class ||
2723 full_mask.option_type != mask->option_type ||
2724 full_mask.option_len != (mask->option_len & full_mask.option_len))
2725 return rte_flow_error_set
2726 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2727 "Geneve TLV opt class/type/length masks must be full");
2728 /* Check if length is supported */
2729 if ((uint32_t)spec->option_len >
2730 config->hca_attr.max_geneve_tlv_option_data_len)
2731 return rte_flow_error_set
2732 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2733 "Geneve TLV opt length not supported");
2734 if (config->hca_attr.max_geneve_tlv_options > 1)
2736 "max_geneve_tlv_options supports more than 1 option");
2737 /* Check GENEVE item preceding. */
2738 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
2739 return rte_flow_error_set
2740 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2741 "Geneve opt item must be preceded with Geneve item");
2742 geneve_spec = geneve_item->spec;
2743 geneve_mask = geneve_item->mask ? geneve_item->mask :
2744 &rte_flow_item_geneve_mask;
2745 /* Check if GENEVE TLV option size doesn't exceed option length */
2746 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
2747 geneve_spec->ver_opt_len_o_c_rsvd0)) {
2748 tlv_option_len = spec->option_len & mask->option_len;
2749 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
2750 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
2751 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
2752 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
2753 if ((optlen_v & optlen_m) <= tlv_option_len)
2754 return rte_flow_error_set
2755 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2756 "GENEVE TLV option length exceeds optlen");
2758 /* Check if length is 0 or data is 0. */
2759 if (spec->data == NULL || spec->option_len == 0)
2760 return rte_flow_error_set
2761 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2762 "Geneve TLV opt with zero data/length not supported");
2763 /* Check not all data & mask are 0. */
2764 data_len = spec->option_len * 4;
2765 if (mask->data == NULL) {
2766 for (i = 0; i < data_len; i++)
2770 return rte_flow_error_set(error, ENOTSUP,
2771 RTE_FLOW_ERROR_TYPE_ITEM, item,
2772 "Can't match on Geneve option data 0");
2774 for (i = 0; i < data_len; i++)
2775 if (spec->data[i] & mask->data[i])
2778 return rte_flow_error_set(error, ENOTSUP,
2779 RTE_FLOW_ERROR_TYPE_ITEM, item,
2780 "Can't match on Geneve option data and mask 0");
2781 /* Check data mask supported. */
2782 for (i = data_max_supported; i < data_len ; i++)
2784 return rte_flow_error_set(error, ENOTSUP,
2785 RTE_FLOW_ERROR_TYPE_ITEM, item,
2786 "Data mask is of unsupported size");
2788 /* Check GENEVE option is supported in NIC. */
2789 if (!config->hca_attr.geneve_tlv_opt)
2790 return rte_flow_error_set
2791 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2792 "Geneve TLV opt not supported");
2793 /* Check if we already have geneve option with different type/class. */
2794 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
2795 geneve_opt_resource = sh->geneve_tlv_option_resource;
2796 if (geneve_opt_resource != NULL)
2797 if (geneve_opt_resource->option_class != spec->option_class ||
2798 geneve_opt_resource->option_type != spec->option_type ||
2799 geneve_opt_resource->length != spec->option_len) {
2800 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2801 return rte_flow_error_set(error, ENOTSUP,
2802 RTE_FLOW_ERROR_TYPE_ITEM, item,
2803 "Only one Geneve TLV option supported");
2805 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2810 * Validate MPLS item.
2813 * Pointer to the rte_eth_dev structure.
2815 * Item specification.
2816 * @param[in] item_flags
2817 * Bit-fields that holds the items detected until now.
2818 * @param[in] prev_layer
2819 * The protocol layer indicated in previous item.
2821 * Pointer to error structure.
2824 * 0 on success, a negative errno value otherwise and rte_errno is set.
2827 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2828 const struct rte_flow_item *item __rte_unused,
2829 uint64_t item_flags __rte_unused,
2830 uint64_t prev_layer __rte_unused,
2831 struct rte_flow_error *error)
2833 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2834 const struct rte_flow_item_mpls *mask = item->mask;
2835 struct mlx5_priv *priv = dev->data->dev_private;
2838 if (!priv->config.mpls_en)
2839 return rte_flow_error_set(error, ENOTSUP,
2840 RTE_FLOW_ERROR_TYPE_ITEM, item,
2841 "MPLS not supported or"
2842 " disabled in firmware"
2844 /* MPLS over IP, UDP, GRE is allowed */
2845 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2846 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2847 MLX5_FLOW_LAYER_GRE |
2848 MLX5_FLOW_LAYER_GRE_KEY)))
2849 return rte_flow_error_set(error, EINVAL,
2850 RTE_FLOW_ERROR_TYPE_ITEM, item,
2851 "protocol filtering not compatible"
2852 " with MPLS layer");
2853 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2854 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2855 !(item_flags & MLX5_FLOW_LAYER_GRE))
2856 return rte_flow_error_set(error, ENOTSUP,
2857 RTE_FLOW_ERROR_TYPE_ITEM, item,
2858 "multiple tunnel layers not"
2861 mask = &rte_flow_item_mpls_mask;
2862 ret = mlx5_flow_item_acceptable
2863 (item, (const uint8_t *)mask,
2864 (const uint8_t *)&rte_flow_item_mpls_mask,
2865 sizeof(struct rte_flow_item_mpls),
2866 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2871 return rte_flow_error_set(error, ENOTSUP,
2872 RTE_FLOW_ERROR_TYPE_ITEM, item,
2873 "MPLS is not supported by Verbs, please"
2879 * Validate NVGRE item.
2882 * Item specification.
2883 * @param[in] item_flags
2884 * Bit flags to mark detected items.
2885 * @param[in] target_protocol
2886 * The next protocol in the previous item.
2888 * Pointer to error structure.
2891 * 0 on success, a negative errno value otherwise and rte_errno is set.
2894 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2895 uint64_t item_flags,
2896 uint8_t target_protocol,
2897 struct rte_flow_error *error)
2899 const struct rte_flow_item_nvgre *mask = item->mask;
2902 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2903 return rte_flow_error_set(error, EINVAL,
2904 RTE_FLOW_ERROR_TYPE_ITEM, item,
2905 "protocol filtering not compatible"
2906 " with this GRE layer");
2907 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2908 return rte_flow_error_set(error, ENOTSUP,
2909 RTE_FLOW_ERROR_TYPE_ITEM, item,
2910 "multiple tunnel layers not"
2912 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2913 return rte_flow_error_set(error, ENOTSUP,
2914 RTE_FLOW_ERROR_TYPE_ITEM, item,
2915 "L3 Layer is missing");
2917 mask = &rte_flow_item_nvgre_mask;
2918 ret = mlx5_flow_item_acceptable
2919 (item, (const uint8_t *)mask,
2920 (const uint8_t *)&rte_flow_item_nvgre_mask,
2921 sizeof(struct rte_flow_item_nvgre),
2922 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2929 * Validate eCPRI item.
2932 * Item specification.
2933 * @param[in] item_flags
2934 * Bit-fields that holds the items detected until now.
2935 * @param[in] last_item
2936 * Previous validated item in the pattern items.
2937 * @param[in] ether_type
2938 * Type in the ethernet layer header (including dot1q).
2939 * @param[in] acc_mask
2940 * Acceptable mask, if NULL default internal default mask
2941 * will be used to check whether item fields are supported.
2943 * Pointer to error structure.
2946 * 0 on success, a negative errno value otherwise and rte_errno is set.
2949 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
2950 uint64_t item_flags,
2952 uint16_t ether_type,
2953 const struct rte_flow_item_ecpri *acc_mask,
2954 struct rte_flow_error *error)
2956 const struct rte_flow_item_ecpri *mask = item->mask;
2957 const struct rte_flow_item_ecpri nic_mask = {
2961 RTE_BE32(((const struct rte_ecpri_common_hdr) {
2965 .dummy[0] = 0xFFFFFFFF,
2968 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
2969 MLX5_FLOW_LAYER_OUTER_VLAN);
2970 struct rte_flow_item_ecpri mask_lo;
2972 if (!(last_item & outer_l2_vlan) &&
2973 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
2974 return rte_flow_error_set(error, EINVAL,
2975 RTE_FLOW_ERROR_TYPE_ITEM, item,
2976 "eCPRI can only follow L2/VLAN layer or UDP layer");
2977 if ((last_item & outer_l2_vlan) && ether_type &&
2978 ether_type != RTE_ETHER_TYPE_ECPRI)
2979 return rte_flow_error_set(error, EINVAL,
2980 RTE_FLOW_ERROR_TYPE_ITEM, item,
2981 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
2982 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2983 return rte_flow_error_set(error, EINVAL,
2984 RTE_FLOW_ERROR_TYPE_ITEM, item,
2985 "eCPRI with tunnel is not supported right now");
2986 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
2987 return rte_flow_error_set(error, ENOTSUP,
2988 RTE_FLOW_ERROR_TYPE_ITEM, item,
2989 "multiple L3 layers not supported");
2990 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
2991 return rte_flow_error_set(error, EINVAL,
2992 RTE_FLOW_ERROR_TYPE_ITEM, item,
2993 "eCPRI cannot coexist with a TCP layer");
2994 /* In specification, eCPRI could be over UDP layer. */
2995 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
2996 return rte_flow_error_set(error, EINVAL,
2997 RTE_FLOW_ERROR_TYPE_ITEM, item,
2998 "eCPRI over UDP layer is not yet supported right now");
2999 /* Mask for type field in common header could be zero. */
3001 mask = &rte_flow_item_ecpri_mask;
3002 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3003 /* Input mask is in big-endian format. */
3004 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3005 return rte_flow_error_set(error, EINVAL,
3006 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3007 "partial mask is not supported for protocol");
3008 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3009 return rte_flow_error_set(error, EINVAL,
3010 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3011 "message header mask must be after a type mask");
3012 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3013 acc_mask ? (const uint8_t *)acc_mask
3014 : (const uint8_t *)&nic_mask,
3015 sizeof(struct rte_flow_item_ecpri),
3016 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3020 * Release resource related QUEUE/RSS action split.
3023 * Pointer to Ethernet device.
3025 * Flow to release id's from.
3028 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
3029 struct rte_flow *flow)
3031 struct mlx5_priv *priv = dev->data->dev_private;
3032 uint32_t handle_idx;
3033 struct mlx5_flow_handle *dev_handle;
3035 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
3036 handle_idx, dev_handle, next)
3037 if (dev_handle->split_flow_id)
3038 mlx5_ipool_free(priv->sh->ipool
3039 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
3040 dev_handle->split_flow_id);
3044 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3045 const struct rte_flow_attr *attr __rte_unused,
3046 const struct rte_flow_item items[] __rte_unused,
3047 const struct rte_flow_action actions[] __rte_unused,
3048 bool external __rte_unused,
3049 int hairpin __rte_unused,
3050 struct rte_flow_error *error)
3052 return rte_flow_error_set(error, ENOTSUP,
3053 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3056 static struct mlx5_flow *
3057 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3058 const struct rte_flow_attr *attr __rte_unused,
3059 const struct rte_flow_item items[] __rte_unused,
3060 const struct rte_flow_action actions[] __rte_unused,
3061 struct rte_flow_error *error)
3063 rte_flow_error_set(error, ENOTSUP,
3064 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3069 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3070 struct mlx5_flow *dev_flow __rte_unused,
3071 const struct rte_flow_attr *attr __rte_unused,
3072 const struct rte_flow_item items[] __rte_unused,
3073 const struct rte_flow_action actions[] __rte_unused,
3074 struct rte_flow_error *error)
3076 return rte_flow_error_set(error, ENOTSUP,
3077 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3081 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3082 struct rte_flow *flow __rte_unused,
3083 struct rte_flow_error *error)
3085 return rte_flow_error_set(error, ENOTSUP,
3086 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3090 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3091 struct rte_flow *flow __rte_unused)
3096 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3097 struct rte_flow *flow __rte_unused)
3102 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3103 struct rte_flow *flow __rte_unused,
3104 const struct rte_flow_action *actions __rte_unused,
3105 void *data __rte_unused,
3106 struct rte_flow_error *error)
3108 return rte_flow_error_set(error, ENOTSUP,
3109 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3113 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3114 uint32_t domains __rte_unused,
3115 uint32_t flags __rte_unused)
3120 /* Void driver to protect from null pointer reference. */
3121 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3122 .validate = flow_null_validate,
3123 .prepare = flow_null_prepare,
3124 .translate = flow_null_translate,
3125 .apply = flow_null_apply,
3126 .remove = flow_null_remove,
3127 .destroy = flow_null_destroy,
3128 .query = flow_null_query,
3129 .sync_domain = flow_null_sync_domain,
3133 * Select flow driver type according to flow attributes and device
3137 * Pointer to the dev structure.
3139 * Pointer to the flow attributes.
3142 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3144 static enum mlx5_flow_drv_type
3145 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3147 struct mlx5_priv *priv = dev->data->dev_private;
3148 /* The OS can determine first a specific flow type (DV, VERBS) */
3149 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3151 if (type != MLX5_FLOW_TYPE_MAX)
3153 /* If no OS specific type - continue with DV/VERBS selection */
3154 if (attr->transfer && priv->config.dv_esw_en)
3155 type = MLX5_FLOW_TYPE_DV;
3156 if (!attr->transfer)
3157 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3158 MLX5_FLOW_TYPE_VERBS;
3162 #define flow_get_drv_ops(type) flow_drv_ops[type]
3165 * Flow driver validation API. This abstracts calling driver specific functions.
3166 * The type of flow driver is determined according to flow attributes.
3169 * Pointer to the dev structure.
3171 * Pointer to the flow attributes.
3173 * Pointer to the list of items.
3174 * @param[in] actions
3175 * Pointer to the list of actions.
3176 * @param[in] external
3177 * This flow rule is created by request external to PMD.
3178 * @param[in] hairpin
3179 * Number of hairpin TX actions, 0 means classic flow.
3181 * Pointer to the error structure.
3184 * 0 on success, a negative errno value otherwise and rte_errno is set.
3187 flow_drv_validate(struct rte_eth_dev *dev,
3188 const struct rte_flow_attr *attr,
3189 const struct rte_flow_item items[],
3190 const struct rte_flow_action actions[],
3191 bool external, int hairpin, struct rte_flow_error *error)
3193 const struct mlx5_flow_driver_ops *fops;
3194 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3196 fops = flow_get_drv_ops(type);
3197 return fops->validate(dev, attr, items, actions, external,
3202 * Flow driver preparation API. This abstracts calling driver specific
3203 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3204 * calculates the size of memory required for device flow, allocates the memory,
3205 * initializes the device flow and returns the pointer.
3208 * This function initializes device flow structure such as dv or verbs in
3209 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3210 * rest. For example, adding returning device flow to flow->dev_flow list and
3211 * setting backward reference to the flow should be done out of this function.
3212 * layers field is not filled either.
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] flow_idx
3223 * This memory pool index to the flow.
3225 * Pointer to the error structure.
3228 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3230 static inline struct mlx5_flow *
3231 flow_drv_prepare(struct rte_eth_dev *dev,
3232 const struct rte_flow *flow,
3233 const struct rte_flow_attr *attr,
3234 const struct rte_flow_item items[],
3235 const struct rte_flow_action actions[],
3237 struct rte_flow_error *error)
3239 const struct mlx5_flow_driver_ops *fops;
3240 enum mlx5_flow_drv_type type = flow->drv_type;
3241 struct mlx5_flow *mlx5_flow = NULL;
3243 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3244 fops = flow_get_drv_ops(type);
3245 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3247 mlx5_flow->flow_idx = flow_idx;
3252 * Flow driver translation API. This abstracts calling driver specific
3253 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3254 * translates a generic flow into a driver flow. flow_drv_prepare() must
3258 * dev_flow->layers could be filled as a result of parsing during translation
3259 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3260 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3261 * flow->actions could be overwritten even though all the expanded dev_flows
3262 * have the same actions.
3265 * Pointer to the rte dev structure.
3266 * @param[in, out] dev_flow
3267 * Pointer to the mlx5 flow.
3269 * Pointer to the flow attributes.
3271 * Pointer to the list of items.
3272 * @param[in] actions
3273 * Pointer to the list of actions.
3275 * Pointer to the error structure.
3278 * 0 on success, a negative errno value otherwise and rte_errno is set.
3281 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3282 const struct rte_flow_attr *attr,
3283 const struct rte_flow_item items[],
3284 const struct rte_flow_action actions[],
3285 struct rte_flow_error *error)
3287 const struct mlx5_flow_driver_ops *fops;
3288 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3290 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3291 fops = flow_get_drv_ops(type);
3292 return fops->translate(dev, dev_flow, attr, items, actions, error);
3296 * Flow driver apply API. This abstracts calling driver specific functions.
3297 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3298 * translated driver flows on to device. flow_drv_translate() must precede.
3301 * Pointer to Ethernet device structure.
3302 * @param[in, out] flow
3303 * Pointer to flow structure.
3305 * Pointer to error structure.
3308 * 0 on success, a negative errno value otherwise and rte_errno is set.
3311 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3312 struct rte_flow_error *error)
3314 const struct mlx5_flow_driver_ops *fops;
3315 enum mlx5_flow_drv_type type = flow->drv_type;
3317 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3318 fops = flow_get_drv_ops(type);
3319 return fops->apply(dev, flow, error);
3323 * Flow driver destroy API. This abstracts calling driver specific functions.
3324 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3325 * on device and releases resources of the flow.
3328 * Pointer to Ethernet device.
3329 * @param[in, out] flow
3330 * Pointer to flow structure.
3333 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3335 const struct mlx5_flow_driver_ops *fops;
3336 enum mlx5_flow_drv_type type = flow->drv_type;
3338 flow_mreg_split_qrss_release(dev, flow);
3339 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3340 fops = flow_get_drv_ops(type);
3341 fops->destroy(dev, flow);
3345 * Get RSS action from the action list.
3347 * @param[in] actions
3348 * Pointer to the list of actions.
3351 * Pointer to the RSS action if exist, else return NULL.
3353 static const struct rte_flow_action_rss*
3354 flow_get_rss_action(const struct rte_flow_action actions[])
3356 const struct rte_flow_action_rss *rss = NULL;
3358 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3359 switch (actions->type) {
3360 case RTE_FLOW_ACTION_TYPE_RSS:
3361 rss = actions->conf;
3363 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3365 const struct rte_flow_action_sample *sample =
3367 const struct rte_flow_action *act = sample->actions;
3368 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3369 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3381 * Get ASO age action by index.
3384 * Pointer to the Ethernet device structure.
3385 * @param[in] age_idx
3386 * Index to the ASO age action.
3389 * The specified ASO age action.
3391 struct mlx5_aso_age_action*
3392 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3394 uint16_t pool_idx = age_idx & UINT16_MAX;
3395 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3396 struct mlx5_priv *priv = dev->data->dev_private;
3397 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3398 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3400 return &pool->actions[offset - 1];
3403 /* maps shared action to translated non shared in some actions array */
3404 struct mlx5_translated_shared_action {
3405 struct rte_flow_shared_action *action; /**< Shared action */
3406 int index; /**< Index in related array of rte_flow_action */
3410 * Translates actions of type RTE_FLOW_ACTION_TYPE_SHARED to related
3411 * non shared action if translation possible.
3412 * This functionality used to run same execution path for both shared & non
3413 * shared actions on flow create. All necessary preparations for shared
3414 * action handling should be preformed on *shared* actions list returned
3418 * Pointer to Ethernet device.
3419 * @param[in] actions
3420 * List of actions to translate.
3421 * @param[out] shared
3422 * List to store translated shared actions.
3423 * @param[in, out] shared_n
3424 * Size of *shared* array. On return should be updated with number of shared
3425 * actions retrieved from the *actions* list.
3426 * @param[out] translated_actions
3427 * List of actions where all shared actions were translated to non shared
3428 * if possible. NULL if no translation took place.
3430 * Pointer to the error structure.
3433 * 0 on success, a negative errno value otherwise and rte_errno is set.
3436 flow_shared_actions_translate(struct rte_eth_dev *dev,
3437 const struct rte_flow_action actions[],
3438 struct mlx5_translated_shared_action *shared,
3440 struct rte_flow_action **translated_actions,
3441 struct rte_flow_error *error)
3443 struct mlx5_priv *priv = dev->data->dev_private;
3444 struct rte_flow_action *translated = NULL;
3445 size_t actions_size;
3448 struct mlx5_translated_shared_action *shared_end = NULL;
3450 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3451 if (actions[n].type != RTE_FLOW_ACTION_TYPE_SHARED)
3453 if (copied_n == *shared_n) {
3454 return rte_flow_error_set
3455 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3456 NULL, "too many shared actions");
3458 rte_memcpy(&shared[copied_n].action, &actions[n].conf,
3459 sizeof(actions[n].conf));
3460 shared[copied_n].index = n;
3464 *shared_n = copied_n;
3467 actions_size = sizeof(struct rte_flow_action) * n;
3468 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3473 memcpy(translated, actions, actions_size);
3474 for (shared_end = shared + copied_n; shared < shared_end; shared++) {
3475 struct mlx5_shared_action_rss *shared_rss;
3476 uint32_t act_idx = (uint32_t)(uintptr_t)shared->action;
3477 uint32_t type = act_idx >> MLX5_SHARED_ACTION_TYPE_OFFSET;
3478 uint32_t idx = act_idx & ((1u << MLX5_SHARED_ACTION_TYPE_OFFSET)
3482 case MLX5_SHARED_ACTION_TYPE_RSS:
3483 shared_rss = mlx5_ipool_get
3484 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3485 translated[shared->index].type =
3486 RTE_FLOW_ACTION_TYPE_RSS;
3487 translated[shared->index].conf =
3488 &shared_rss->origin;
3490 case MLX5_SHARED_ACTION_TYPE_AGE:
3491 if (priv->sh->flow_hit_aso_en) {
3492 translated[shared->index].type =
3493 (enum rte_flow_action_type)
3494 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3495 translated[shared->index].conf =
3496 (void *)(uintptr_t)idx;
3501 mlx5_free(translated);
3502 return rte_flow_error_set
3503 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3504 NULL, "invalid shared action type");
3507 *translated_actions = translated;
3512 * Get Shared RSS action from the action list.
3515 * Pointer to Ethernet device.
3517 * Pointer to the list of actions.
3518 * @param[in] shared_n
3519 * Actions list length.
3522 * The MLX5 RSS action ID if exists, otherwise return 0.
3525 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3526 struct mlx5_translated_shared_action *shared,
3529 struct mlx5_translated_shared_action *shared_end;
3530 struct mlx5_priv *priv = dev->data->dev_private;
3531 struct mlx5_shared_action_rss *shared_rss;
3534 for (shared_end = shared + shared_n; shared < shared_end; shared++) {
3535 uint32_t act_idx = (uint32_t)(uintptr_t)shared->action;
3536 uint32_t type = act_idx >> MLX5_SHARED_ACTION_TYPE_OFFSET;
3537 uint32_t idx = act_idx &
3538 ((1u << MLX5_SHARED_ACTION_TYPE_OFFSET) - 1);
3540 case MLX5_SHARED_ACTION_TYPE_RSS:
3541 shared_rss = mlx5_ipool_get
3542 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3544 __atomic_add_fetch(&shared_rss->refcnt, 1,
3555 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3557 const struct rte_flow_item *item;
3558 unsigned int has_vlan = 0;
3560 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3561 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3567 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3568 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3569 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3570 MLX5_EXPANSION_ROOT_OUTER;
3574 * Get layer flags from the prefix flow.
3576 * Some flows may be split to several subflows, the prefix subflow gets the
3577 * match items and the suffix sub flow gets the actions.
3578 * Some actions need the user defined match item flags to get the detail for
3580 * This function helps the suffix flow to get the item layer flags from prefix
3583 * @param[in] dev_flow
3584 * Pointer the created preifx subflow.
3587 * The layers get from prefix subflow.
3589 static inline uint64_t
3590 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3592 uint64_t layers = 0;
3595 * Layers bits could be localization, but usually the compiler will
3596 * help to do the optimization work for source code.
3597 * If no decap actions, use the layers directly.
3599 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3600 return dev_flow->handle->layers;
3601 /* Convert L3 layers with decap action. */
3602 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3603 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3604 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3605 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3606 /* Convert L4 layers with decap action. */
3607 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3608 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3609 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3610 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3615 * Get metadata split action information.
3617 * @param[in] actions
3618 * Pointer to the list of actions.
3620 * Pointer to the return pointer.
3621 * @param[out] qrss_type
3622 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3623 * if no QUEUE/RSS is found.
3624 * @param[out] encap_idx
3625 * Pointer to the index of the encap action if exists, otherwise the last
3629 * Total number of actions.
3632 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3633 const struct rte_flow_action **qrss,
3636 const struct rte_flow_action_raw_encap *raw_encap;
3638 int raw_decap_idx = -1;
3641 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3642 switch (actions->type) {
3643 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3644 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3645 *encap_idx = actions_n;
3647 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3648 raw_decap_idx = actions_n;
3650 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3651 raw_encap = actions->conf;
3652 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3653 *encap_idx = raw_decap_idx != -1 ?
3654 raw_decap_idx : actions_n;
3656 case RTE_FLOW_ACTION_TYPE_QUEUE:
3657 case RTE_FLOW_ACTION_TYPE_RSS:
3665 if (*encap_idx == -1)
3666 *encap_idx = actions_n;
3667 /* Count RTE_FLOW_ACTION_TYPE_END. */
3668 return actions_n + 1;
3672 * Check meter action from the action list.
3674 * @param[in] actions
3675 * Pointer to the list of actions.
3677 * Pointer to the meter exist flag.
3680 * Total number of actions.
3683 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
3689 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3690 switch (actions->type) {
3691 case RTE_FLOW_ACTION_TYPE_METER:
3699 /* Count RTE_FLOW_ACTION_TYPE_END. */
3700 return actions_n + 1;
3704 * Check if the flow should be split due to hairpin.
3705 * The reason for the split is that in current HW we can't
3706 * support encap and push-vlan on Rx, so if a flow contains
3707 * these actions we move it to Tx.
3710 * Pointer to Ethernet device.
3712 * Flow rule attributes.
3713 * @param[in] actions
3714 * Associated actions (list terminated by the END action).
3717 * > 0 the number of actions and the flow should be split,
3718 * 0 when no split required.
3721 flow_check_hairpin_split(struct rte_eth_dev *dev,
3722 const struct rte_flow_attr *attr,
3723 const struct rte_flow_action actions[])
3725 int queue_action = 0;
3728 const struct rte_flow_action_queue *queue;
3729 const struct rte_flow_action_rss *rss;
3730 const struct rte_flow_action_raw_encap *raw_encap;
3731 const struct rte_eth_hairpin_conf *conf;
3735 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3736 switch (actions->type) {
3737 case RTE_FLOW_ACTION_TYPE_QUEUE:
3738 queue = actions->conf;
3741 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
3742 if (conf == NULL || conf->tx_explicit != 0)
3747 case RTE_FLOW_ACTION_TYPE_RSS:
3748 rss = actions->conf;
3749 if (rss == NULL || rss->queue_num == 0)
3751 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
3752 if (conf == NULL || conf->tx_explicit != 0)
3757 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3758 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3759 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3760 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3761 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3765 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3766 raw_encap = actions->conf;
3767 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3776 if (split && queue_action)
3781 /* Declare flow create/destroy prototype in advance. */
3783 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
3784 const struct rte_flow_attr *attr,
3785 const struct rte_flow_item items[],
3786 const struct rte_flow_action actions[],
3787 bool external, struct rte_flow_error *error);
3790 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
3794 flow_dv_mreg_match_cb(struct mlx5_hlist *list __rte_unused,
3795 struct mlx5_hlist_entry *entry,
3796 uint64_t key, void *cb_ctx __rte_unused)
3798 struct mlx5_flow_mreg_copy_resource *mcp_res =
3799 container_of(entry, typeof(*mcp_res), hlist_ent);
3801 return mcp_res->mark_id != key;
3804 struct mlx5_hlist_entry *
3805 flow_dv_mreg_create_cb(struct mlx5_hlist *list, uint64_t key,
3808 struct rte_eth_dev *dev = list->ctx;
3809 struct mlx5_priv *priv = dev->data->dev_private;
3810 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3811 struct mlx5_flow_mreg_copy_resource *mcp_res;
3812 struct rte_flow_error *error = ctx->error;
3815 uint32_t mark_id = key;
3816 struct rte_flow_attr attr = {
3817 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3820 struct mlx5_rte_flow_item_tag tag_spec = {
3823 struct rte_flow_item items[] = {
3824 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
3826 struct rte_flow_action_mark ftag = {
3829 struct mlx5_flow_action_copy_mreg cp_mreg = {
3833 struct rte_flow_action_jump jump = {
3834 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3836 struct rte_flow_action actions[] = {
3837 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
3840 /* Fill the register fileds in the flow. */
3841 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3845 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3849 /* Provide the full width of FLAG specific value. */
3850 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3851 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3852 /* Build a new flow. */
3853 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3854 items[0] = (struct rte_flow_item){
3855 .type = (enum rte_flow_item_type)
3856 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3859 items[1] = (struct rte_flow_item){
3860 .type = RTE_FLOW_ITEM_TYPE_END,
3862 actions[0] = (struct rte_flow_action){
3863 .type = (enum rte_flow_action_type)
3864 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3867 actions[1] = (struct rte_flow_action){
3868 .type = (enum rte_flow_action_type)
3869 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3872 actions[2] = (struct rte_flow_action){
3873 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3876 actions[3] = (struct rte_flow_action){
3877 .type = RTE_FLOW_ACTION_TYPE_END,
3880 /* Default rule, wildcard match. */
3881 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
3882 items[0] = (struct rte_flow_item){
3883 .type = RTE_FLOW_ITEM_TYPE_END,
3885 actions[0] = (struct rte_flow_action){
3886 .type = (enum rte_flow_action_type)
3887 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3890 actions[1] = (struct rte_flow_action){
3891 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3894 actions[2] = (struct rte_flow_action){
3895 .type = RTE_FLOW_ACTION_TYPE_END,
3898 /* Build a new entry. */
3899 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3905 mcp_res->mark_id = mark_id;
3907 * The copy Flows are not included in any list. There
3908 * ones are referenced from other Flows and can not
3909 * be applied, removed, deleted in ardbitrary order
3910 * by list traversing.
3912 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3913 actions, false, error);
3914 if (!mcp_res->rix_flow) {
3915 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
3918 return &mcp_res->hlist_ent;
3922 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3924 * As mark_id is unique, if there's already a registered flow for the mark_id,
3925 * return by increasing the reference counter of the resource. Otherwise, create
3926 * the resource (mcp_res) and flow.
3929 * - If ingress port is ANY and reg_c[1] is mark_id,
3930 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3932 * For default flow (zero mark_id), flow is like,
3933 * - If ingress port is ANY,
3934 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
3937 * Pointer to Ethernet device.
3939 * ID of MARK action, zero means default flow for META.
3941 * Perform verbose error reporting if not NULL.
3944 * Associated resource on success, NULL otherwise and rte_errno is set.
3946 static struct mlx5_flow_mreg_copy_resource *
3947 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
3948 struct rte_flow_error *error)
3950 struct mlx5_priv *priv = dev->data->dev_private;
3951 struct mlx5_hlist_entry *entry;
3952 struct mlx5_flow_cb_ctx ctx = {
3957 /* Check if already registered. */
3958 MLX5_ASSERT(priv->mreg_cp_tbl);
3959 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
3962 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
3967 flow_dv_mreg_remove_cb(struct mlx5_hlist *list, struct mlx5_hlist_entry *entry)
3969 struct mlx5_flow_mreg_copy_resource *mcp_res =
3970 container_of(entry, typeof(*mcp_res), hlist_ent);
3971 struct rte_eth_dev *dev = list->ctx;
3972 struct mlx5_priv *priv = dev->data->dev_private;
3974 MLX5_ASSERT(mcp_res->rix_flow);
3975 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3976 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3980 * Release flow in RX_CP_TBL.
3983 * Pointer to Ethernet device.
3985 * Parent flow for wich copying is provided.
3988 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3989 struct rte_flow *flow)
3991 struct mlx5_flow_mreg_copy_resource *mcp_res;
3992 struct mlx5_priv *priv = dev->data->dev_private;
3994 if (!flow->rix_mreg_copy)
3996 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3997 flow->rix_mreg_copy);
3998 if (!mcp_res || !priv->mreg_cp_tbl)
4000 MLX5_ASSERT(mcp_res->rix_flow);
4001 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4002 flow->rix_mreg_copy = 0;
4006 * Remove the default copy action from RX_CP_TBL.
4008 * This functions is called in the mlx5_dev_start(). No thread safe
4012 * Pointer to Ethernet device.
4015 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4017 struct mlx5_hlist_entry *entry;
4018 struct mlx5_priv *priv = dev->data->dev_private;
4020 /* Check if default flow is registered. */
4021 if (!priv->mreg_cp_tbl)
4023 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl,
4024 MLX5_DEFAULT_COPY_ID, NULL);
4027 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4031 * Add the default copy action in in RX_CP_TBL.
4033 * This functions is called in the mlx5_dev_start(). No thread safe
4037 * Pointer to Ethernet device.
4039 * Perform verbose error reporting if not NULL.
4042 * 0 for success, negative value otherwise and rte_errno is set.
4045 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4046 struct rte_flow_error *error)
4048 struct mlx5_priv *priv = dev->data->dev_private;
4049 struct mlx5_flow_mreg_copy_resource *mcp_res;
4051 /* Check whether extensive metadata feature is engaged. */
4052 if (!priv->config.dv_flow_en ||
4053 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4054 !mlx5_flow_ext_mreg_supported(dev) ||
4055 !priv->sh->dv_regc0_mask)
4058 * Add default mreg copy flow may be called multiple time, but
4059 * only be called once in stop. Avoid register it twice.
4061 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, MLX5_DEFAULT_COPY_ID, NULL))
4063 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
4070 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4072 * All the flow having Q/RSS action should be split by
4073 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4074 * performs the following,
4075 * - CQE->flow_tag := reg_c[1] (MARK)
4076 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4077 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4078 * but there should be a flow per each MARK ID set by MARK action.
4080 * For the aforementioned reason, if there's a MARK action in flow's action
4081 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4082 * the MARK ID to CQE's flow_tag like,
4083 * - If reg_c[1] is mark_id,
4084 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4086 * For SET_META action which stores value in reg_c[0], as the destination is
4087 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4088 * MARK ID means the default flow. The default flow looks like,
4089 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4092 * Pointer to Ethernet device.
4094 * Pointer to flow structure.
4095 * @param[in] actions
4096 * Pointer to the list of actions.
4098 * Perform verbose error reporting if not NULL.
4101 * 0 on success, negative value otherwise and rte_errno is set.
4104 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4105 struct rte_flow *flow,
4106 const struct rte_flow_action *actions,
4107 struct rte_flow_error *error)
4109 struct mlx5_priv *priv = dev->data->dev_private;
4110 struct mlx5_dev_config *config = &priv->config;
4111 struct mlx5_flow_mreg_copy_resource *mcp_res;
4112 const struct rte_flow_action_mark *mark;
4114 /* Check whether extensive metadata feature is engaged. */
4115 if (!config->dv_flow_en ||
4116 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4117 !mlx5_flow_ext_mreg_supported(dev) ||
4118 !priv->sh->dv_regc0_mask)
4120 /* Find MARK action. */
4121 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4122 switch (actions->type) {
4123 case RTE_FLOW_ACTION_TYPE_FLAG:
4124 mcp_res = flow_mreg_add_copy_action
4125 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4128 flow->rix_mreg_copy = mcp_res->idx;
4130 case RTE_FLOW_ACTION_TYPE_MARK:
4131 mark = (const struct rte_flow_action_mark *)
4134 flow_mreg_add_copy_action(dev, mark->id, error);
4137 flow->rix_mreg_copy = mcp_res->idx;
4146 #define MLX5_MAX_SPLIT_ACTIONS 24
4147 #define MLX5_MAX_SPLIT_ITEMS 24
4150 * Split the hairpin flow.
4151 * Since HW can't support encap and push-vlan on Rx, we move these
4153 * If the count action is after the encap then we also
4154 * move the count action. in this case the count will also measure
4158 * Pointer to Ethernet device.
4159 * @param[in] actions
4160 * Associated actions (list terminated by the END action).
4161 * @param[out] actions_rx
4163 * @param[out] actions_tx
4165 * @param[out] pattern_tx
4166 * The pattern items for the Tx flow.
4167 * @param[out] flow_id
4168 * The flow ID connected to this flow.
4174 flow_hairpin_split(struct rte_eth_dev *dev,
4175 const struct rte_flow_action actions[],
4176 struct rte_flow_action actions_rx[],
4177 struct rte_flow_action actions_tx[],
4178 struct rte_flow_item pattern_tx[],
4181 const struct rte_flow_action_raw_encap *raw_encap;
4182 const struct rte_flow_action_raw_decap *raw_decap;
4183 struct mlx5_rte_flow_action_set_tag *set_tag;
4184 struct rte_flow_action *tag_action;
4185 struct mlx5_rte_flow_item_tag *tag_item;
4186 struct rte_flow_item *item;
4190 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4191 switch (actions->type) {
4192 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4193 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4194 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4195 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4196 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4197 rte_memcpy(actions_tx, actions,
4198 sizeof(struct rte_flow_action));
4201 case RTE_FLOW_ACTION_TYPE_COUNT:
4203 rte_memcpy(actions_tx, actions,
4204 sizeof(struct rte_flow_action));
4207 rte_memcpy(actions_rx, actions,
4208 sizeof(struct rte_flow_action));
4212 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4213 raw_encap = actions->conf;
4214 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4215 memcpy(actions_tx, actions,
4216 sizeof(struct rte_flow_action));
4220 rte_memcpy(actions_rx, actions,
4221 sizeof(struct rte_flow_action));
4225 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4226 raw_decap = actions->conf;
4227 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4228 memcpy(actions_tx, actions,
4229 sizeof(struct rte_flow_action));
4232 rte_memcpy(actions_rx, actions,
4233 sizeof(struct rte_flow_action));
4238 rte_memcpy(actions_rx, actions,
4239 sizeof(struct rte_flow_action));
4244 /* Add set meta action and end action for the Rx flow. */
4245 tag_action = actions_rx;
4246 tag_action->type = (enum rte_flow_action_type)
4247 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4249 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4251 set_tag = (void *)actions_rx;
4252 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
4253 MLX5_ASSERT(set_tag->id > REG_NON);
4254 set_tag->data = flow_id;
4255 tag_action->conf = set_tag;
4256 /* Create Tx item list. */
4257 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4258 addr = (void *)&pattern_tx[2];
4260 item->type = (enum rte_flow_item_type)
4261 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4262 tag_item = (void *)addr;
4263 tag_item->data = flow_id;
4264 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4265 MLX5_ASSERT(set_tag->id > REG_NON);
4266 item->spec = tag_item;
4267 addr += sizeof(struct mlx5_rte_flow_item_tag);
4268 tag_item = (void *)addr;
4269 tag_item->data = UINT32_MAX;
4270 tag_item->id = UINT16_MAX;
4271 item->mask = tag_item;
4274 item->type = RTE_FLOW_ITEM_TYPE_END;
4279 * The last stage of splitting chain, just creates the subflow
4280 * without any modification.
4283 * Pointer to Ethernet device.
4285 * Parent flow structure pointer.
4286 * @param[in, out] sub_flow
4287 * Pointer to return the created subflow, may be NULL.
4289 * Flow rule attributes.
4291 * Pattern specification (list terminated by the END pattern item).
4292 * @param[in] actions
4293 * Associated actions (list terminated by the END action).
4294 * @param[in] flow_split_info
4295 * Pointer to flow split info structure.
4297 * Perform verbose error reporting if not NULL.
4299 * 0 on success, negative value otherwise
4302 flow_create_split_inner(struct rte_eth_dev *dev,
4303 struct rte_flow *flow,
4304 struct mlx5_flow **sub_flow,
4305 const struct rte_flow_attr *attr,
4306 const struct rte_flow_item items[],
4307 const struct rte_flow_action actions[],
4308 struct mlx5_flow_split_info *flow_split_info,
4309 struct rte_flow_error *error)
4311 struct mlx5_flow *dev_flow;
4313 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4314 flow_split_info->flow_idx, error);
4317 dev_flow->flow = flow;
4318 dev_flow->external = flow_split_info->external;
4319 dev_flow->skip_scale = flow_split_info->skip_scale;
4320 /* Subflow object was created, we must include one in the list. */
4321 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4322 dev_flow->handle, next);
4324 * If dev_flow is as one of the suffix flow, some actions in suffix
4325 * flow may need some user defined item layer flags, and pass the
4326 * Metadate rxq mark flag to suffix flow as well.
4328 if (flow_split_info->prefix_layers)
4329 dev_flow->handle->layers = flow_split_info->prefix_layers;
4330 if (flow_split_info->prefix_mark)
4331 dev_flow->handle->mark = 1;
4333 *sub_flow = dev_flow;
4334 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4338 * Split the meter flow.
4340 * As meter flow will split to three sub flow, other than meter
4341 * action, the other actions make sense to only meter accepts
4342 * the packet. If it need to be dropped, no other additional
4343 * actions should be take.
4345 * One kind of special action which decapsulates the L3 tunnel
4346 * header will be in the prefix sub flow, as not to take the
4347 * L3 tunnel header into account.
4350 * Pointer to Ethernet device.
4352 * Pattern specification (list terminated by the END pattern item).
4353 * @param[out] sfx_items
4354 * Suffix flow match items (list terminated by the END pattern item).
4355 * @param[in] actions
4356 * Associated actions (list terminated by the END action).
4357 * @param[out] actions_sfx
4358 * Suffix flow actions.
4359 * @param[out] actions_pre
4360 * Prefix flow actions.
4361 * @param[out] pattern_sfx
4362 * The pattern items for the suffix flow.
4363 * @param[out] tag_sfx
4364 * Pointer to suffix flow tag.
4370 flow_meter_split_prep(struct rte_eth_dev *dev,
4371 const struct rte_flow_item items[],
4372 struct rte_flow_item sfx_items[],
4373 const struct rte_flow_action actions[],
4374 struct rte_flow_action actions_sfx[],
4375 struct rte_flow_action actions_pre[])
4377 struct mlx5_priv *priv = dev->data->dev_private;
4378 struct rte_flow_action *tag_action = NULL;
4379 struct rte_flow_item *tag_item;
4380 struct mlx5_rte_flow_action_set_tag *set_tag;
4381 struct rte_flow_error error;
4382 const struct rte_flow_action_raw_encap *raw_encap;
4383 const struct rte_flow_action_raw_decap *raw_decap;
4384 struct mlx5_rte_flow_item_tag *tag_spec;
4385 struct mlx5_rte_flow_item_tag *tag_mask;
4386 uint32_t tag_id = 0;
4387 bool copy_vlan = false;
4389 /* Prepare the actions for prefix and suffix flow. */
4390 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4391 struct rte_flow_action **action_cur = NULL;
4393 switch (actions->type) {
4394 case RTE_FLOW_ACTION_TYPE_METER:
4395 /* Add the extra tag action first. */
4396 tag_action = actions_pre;
4397 tag_action->type = (enum rte_flow_action_type)
4398 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4400 action_cur = &actions_pre;
4402 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4403 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4404 action_cur = &actions_pre;
4406 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4407 raw_encap = actions->conf;
4408 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4409 action_cur = &actions_pre;
4411 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4412 raw_decap = actions->conf;
4413 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4414 action_cur = &actions_pre;
4416 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4417 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4424 action_cur = &actions_sfx;
4425 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
4428 /* Add end action to the actions. */
4429 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4430 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4433 set_tag = (void *)actions_pre;
4434 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4435 mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
4437 if (tag_id >= (1 << (sizeof(tag_id) * 8 - MLX5_MTR_COLOR_BITS))) {
4438 DRV_LOG(ERR, "Port %u meter flow id exceed max limit.",
4439 dev->data->port_id);
4440 mlx5_ipool_free(priv->sh->ipool
4441 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], tag_id);
4443 } else if (!tag_id) {
4446 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
4448 tag_action->conf = set_tag;
4449 /* Prepare the suffix subflow items. */
4450 tag_item = sfx_items++;
4451 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4452 int item_type = items->type;
4454 switch (item_type) {
4455 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4456 memcpy(sfx_items, items, sizeof(*sfx_items));
4459 case RTE_FLOW_ITEM_TYPE_VLAN:
4461 memcpy(sfx_items, items, sizeof(*sfx_items));
4463 * Convert to internal match item, it is used
4464 * for vlan push and set vid.
4466 sfx_items->type = (enum rte_flow_item_type)
4467 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4475 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4477 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4478 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
4479 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4480 tag_mask = tag_spec + 1;
4481 tag_mask->data = 0xffffff00;
4482 tag_item->type = (enum rte_flow_item_type)
4483 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4484 tag_item->spec = tag_spec;
4485 tag_item->last = NULL;
4486 tag_item->mask = tag_mask;
4491 * Split action list having QUEUE/RSS for metadata register copy.
4493 * Once Q/RSS action is detected in user's action list, the flow action
4494 * should be split in order to copy metadata registers, which will happen in
4496 * - CQE->flow_tag := reg_c[1] (MARK)
4497 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4498 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
4499 * This is because the last action of each flow must be a terminal action
4500 * (QUEUE, RSS or DROP).
4502 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
4503 * stored and kept in the mlx5_flow structure per each sub_flow.
4505 * The Q/RSS action is replaced with,
4506 * - SET_TAG, setting the allocated flow ID to reg_c[2].
4507 * And the following JUMP action is added at the end,
4508 * - JUMP, to RX_CP_TBL.
4510 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
4511 * flow_create_split_metadata() routine. The flow will look like,
4512 * - If flow ID matches (reg_c[2]), perform Q/RSS.
4515 * Pointer to Ethernet device.
4516 * @param[out] split_actions
4517 * Pointer to store split actions to jump to CP_TBL.
4518 * @param[in] actions
4519 * Pointer to the list of original flow actions.
4521 * Pointer to the Q/RSS action.
4522 * @param[in] actions_n
4523 * Number of original actions.
4525 * Perform verbose error reporting if not NULL.
4528 * non-zero unique flow_id on success, otherwise 0 and
4529 * error/rte_error are set.
4532 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
4533 struct rte_flow_action *split_actions,
4534 const struct rte_flow_action *actions,
4535 const struct rte_flow_action *qrss,
4536 int actions_n, struct rte_flow_error *error)
4538 struct mlx5_priv *priv = dev->data->dev_private;
4539 struct mlx5_rte_flow_action_set_tag *set_tag;
4540 struct rte_flow_action_jump *jump;
4541 const int qrss_idx = qrss - actions;
4542 uint32_t flow_id = 0;
4546 * Given actions will be split
4547 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
4548 * - Add jump to mreg CP_TBL.
4549 * As a result, there will be one more action.
4552 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
4553 set_tag = (void *)(split_actions + actions_n);
4555 * If tag action is not set to void(it means we are not the meter
4556 * suffix flow), add the tag action. Since meter suffix flow already
4557 * has the tag added.
4559 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
4561 * Allocate the new subflow ID. This one is unique within
4562 * device and not shared with representors. Otherwise,
4563 * we would have to resolve multi-thread access synch
4564 * issue. Each flow on the shared device is appended
4565 * with source vport identifier, so the resulting
4566 * flows will be unique in the shared (by master and
4567 * representors) domain even if they have coinciding
4570 mlx5_ipool_malloc(priv->sh->ipool
4571 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
4573 return rte_flow_error_set(error, ENOMEM,
4574 RTE_FLOW_ERROR_TYPE_ACTION,
4575 NULL, "can't allocate id "
4576 "for split Q/RSS subflow");
4577 /* Internal SET_TAG action to set flow ID. */
4578 *set_tag = (struct mlx5_rte_flow_action_set_tag){
4581 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
4585 /* Construct new actions array. */
4586 /* Replace QUEUE/RSS action. */
4587 split_actions[qrss_idx] = (struct rte_flow_action){
4588 .type = (enum rte_flow_action_type)
4589 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4593 /* JUMP action to jump to mreg copy table (CP_TBL). */
4594 jump = (void *)(set_tag + 1);
4595 *jump = (struct rte_flow_action_jump){
4596 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4598 split_actions[actions_n - 2] = (struct rte_flow_action){
4599 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4602 split_actions[actions_n - 1] = (struct rte_flow_action){
4603 .type = RTE_FLOW_ACTION_TYPE_END,
4609 * Extend the given action list for Tx metadata copy.
4611 * Copy the given action list to the ext_actions and add flow metadata register
4612 * copy action in order to copy reg_a set by WQE to reg_c[0].
4614 * @param[out] ext_actions
4615 * Pointer to the extended action list.
4616 * @param[in] actions
4617 * Pointer to the list of actions.
4618 * @param[in] actions_n
4619 * Number of actions in the list.
4621 * Perform verbose error reporting if not NULL.
4622 * @param[in] encap_idx
4623 * The encap action inndex.
4626 * 0 on success, negative value otherwise
4629 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
4630 struct rte_flow_action *ext_actions,
4631 const struct rte_flow_action *actions,
4632 int actions_n, struct rte_flow_error *error,
4635 struct mlx5_flow_action_copy_mreg *cp_mreg =
4636 (struct mlx5_flow_action_copy_mreg *)
4637 (ext_actions + actions_n + 1);
4640 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4644 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
4649 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
4650 if (encap_idx == actions_n - 1) {
4651 ext_actions[actions_n - 1] = (struct rte_flow_action){
4652 .type = (enum rte_flow_action_type)
4653 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4656 ext_actions[actions_n] = (struct rte_flow_action){
4657 .type = RTE_FLOW_ACTION_TYPE_END,
4660 ext_actions[encap_idx] = (struct rte_flow_action){
4661 .type = (enum rte_flow_action_type)
4662 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4665 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
4666 sizeof(*ext_actions) * (actions_n - encap_idx));
4672 * Check the match action from the action list.
4674 * @param[in] actions
4675 * Pointer to the list of actions.
4677 * Flow rule attributes.
4679 * The action to be check if exist.
4680 * @param[out] match_action_pos
4681 * Pointer to the position of the matched action if exists, otherwise is -1.
4682 * @param[out] qrss_action_pos
4683 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
4684 * @param[out] modify_after_mirror
4685 * Pointer to the flag of modify action after FDB mirroring.
4688 * > 0 the total number of actions.
4689 * 0 if not found match action in action list.
4692 flow_check_match_action(const struct rte_flow_action actions[],
4693 const struct rte_flow_attr *attr,
4694 enum rte_flow_action_type action,
4695 int *match_action_pos, int *qrss_action_pos,
4696 int *modify_after_mirror)
4698 const struct rte_flow_action_sample *sample;
4705 *match_action_pos = -1;
4706 *qrss_action_pos = -1;
4707 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4708 if (actions->type == action) {
4710 *match_action_pos = actions_n;
4712 switch (actions->type) {
4713 case RTE_FLOW_ACTION_TYPE_QUEUE:
4714 case RTE_FLOW_ACTION_TYPE_RSS:
4715 *qrss_action_pos = actions_n;
4717 case RTE_FLOW_ACTION_TYPE_SAMPLE:
4718 sample = actions->conf;
4719 ratio = sample->ratio;
4720 sub_type = ((const struct rte_flow_action *)
4721 (sample->actions))->type;
4722 if (ratio == 1 && attr->transfer)
4725 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4726 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4727 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4728 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4729 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4730 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4731 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4732 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4733 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4734 case RTE_FLOW_ACTION_TYPE_SET_TTL:
4735 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4736 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4737 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4738 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4739 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4740 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
4741 case RTE_FLOW_ACTION_TYPE_FLAG:
4742 case RTE_FLOW_ACTION_TYPE_MARK:
4743 case RTE_FLOW_ACTION_TYPE_SET_META:
4744 case RTE_FLOW_ACTION_TYPE_SET_TAG:
4746 *modify_after_mirror = 1;
4753 if (flag && fdb_mirror && !*modify_after_mirror) {
4754 /* FDB mirroring uses the destination array to implement
4755 * instead of FLOW_SAMPLER object.
4757 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
4760 /* Count RTE_FLOW_ACTION_TYPE_END. */
4761 return flag ? actions_n + 1 : 0;
4764 #define SAMPLE_SUFFIX_ITEM 2
4767 * Split the sample flow.
4769 * As sample flow will split to two sub flow, sample flow with
4770 * sample action, the other actions will move to new suffix flow.
4772 * Also add unique tag id with tag action in the sample flow,
4773 * the same tag id will be as match in the suffix flow.
4776 * Pointer to Ethernet device.
4777 * @param[in] add_tag
4778 * Add extra tag action flag.
4779 * @param[out] sfx_items
4780 * Suffix flow match items (list terminated by the END pattern item).
4781 * @param[in] actions
4782 * Associated actions (list terminated by the END action).
4783 * @param[out] actions_sfx
4784 * Suffix flow actions.
4785 * @param[out] actions_pre
4786 * Prefix flow actions.
4787 * @param[in] actions_n
4788 * The total number of actions.
4789 * @param[in] sample_action_pos
4790 * The sample action position.
4791 * @param[in] qrss_action_pos
4792 * The Queue/RSS action position.
4793 * @param[in] jump_table
4794 * Add extra jump action flag.
4796 * Perform verbose error reporting if not NULL.
4799 * 0 on success, or unique flow_id, a negative errno value
4800 * otherwise and rte_errno is set.
4803 flow_sample_split_prep(struct rte_eth_dev *dev,
4805 struct rte_flow_item sfx_items[],
4806 const struct rte_flow_action actions[],
4807 struct rte_flow_action actions_sfx[],
4808 struct rte_flow_action actions_pre[],
4810 int sample_action_pos,
4811 int qrss_action_pos,
4813 struct rte_flow_error *error)
4815 struct mlx5_priv *priv = dev->data->dev_private;
4816 struct mlx5_rte_flow_action_set_tag *set_tag;
4817 struct mlx5_rte_flow_item_tag *tag_spec;
4818 struct mlx5_rte_flow_item_tag *tag_mask;
4819 struct rte_flow_action_jump *jump_action;
4820 uint32_t tag_id = 0;
4822 int append_index = 0;
4825 if (sample_action_pos < 0)
4826 return rte_flow_error_set(error, EINVAL,
4827 RTE_FLOW_ERROR_TYPE_ACTION,
4828 NULL, "invalid position of sample "
4830 /* Prepare the actions for prefix and suffix flow. */
4831 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
4832 index = qrss_action_pos;
4833 /* Put the preceding the Queue/RSS action into prefix flow. */
4835 memcpy(actions_pre, actions,
4836 sizeof(struct rte_flow_action) * index);
4837 /* Put others preceding the sample action into prefix flow. */
4838 if (sample_action_pos > index + 1)
4839 memcpy(actions_pre + index, actions + index + 1,
4840 sizeof(struct rte_flow_action) *
4841 (sample_action_pos - index - 1));
4842 index = sample_action_pos - 1;
4843 /* Put Queue/RSS action into Suffix flow. */
4844 memcpy(actions_sfx, actions + qrss_action_pos,
4845 sizeof(struct rte_flow_action));
4848 index = sample_action_pos;
4850 memcpy(actions_pre, actions,
4851 sizeof(struct rte_flow_action) * index);
4853 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
4854 * For CX6DX and above, metadata registers Cx preserve their value,
4855 * add an extra tag action for NIC-RX and E-Switch Domain.
4858 /* Prepare the prefix tag action. */
4860 set_tag = (void *)(actions_pre + actions_n + append_index);
4861 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
4865 mlx5_ipool_malloc(priv->sh->ipool
4866 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
4867 set_tag->data = tag_id;
4868 /* Prepare the suffix subflow items. */
4869 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
4870 tag_spec->data = tag_id;
4871 tag_spec->id = set_tag->id;
4872 tag_mask = tag_spec + 1;
4873 tag_mask->data = UINT32_MAX;
4874 sfx_items[0] = (struct rte_flow_item){
4875 .type = (enum rte_flow_item_type)
4876 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4881 sfx_items[1] = (struct rte_flow_item){
4882 .type = (enum rte_flow_item_type)
4883 RTE_FLOW_ITEM_TYPE_END,
4885 /* Prepare the tag action in prefix subflow. */
4886 actions_pre[index++] =
4887 (struct rte_flow_action){
4888 .type = (enum rte_flow_action_type)
4889 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4893 memcpy(actions_pre + index, actions + sample_action_pos,
4894 sizeof(struct rte_flow_action));
4896 /* For the modify action after the sample action in E-Switch mirroring,
4897 * Add the extra jump action in prefix subflow and jump into the next
4898 * table, then do the modify action in the new table.
4901 /* Prepare the prefix jump action. */
4903 jump_action = (void *)(actions_pre + actions_n + append_index);
4904 jump_action->group = jump_table;
4905 actions_pre[index++] =
4906 (struct rte_flow_action){
4907 .type = (enum rte_flow_action_type)
4908 RTE_FLOW_ACTION_TYPE_JUMP,
4909 .conf = jump_action,
4912 actions_pre[index] = (struct rte_flow_action){
4913 .type = (enum rte_flow_action_type)
4914 RTE_FLOW_ACTION_TYPE_END,
4916 /* Put the actions after sample into Suffix flow. */
4917 memcpy(actions_sfx, actions + sample_action_pos + 1,
4918 sizeof(struct rte_flow_action) *
4919 (actions_n - sample_action_pos - 1));
4924 * The splitting for metadata feature.
4926 * - Q/RSS action on NIC Rx should be split in order to pass by
4927 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4928 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4930 * - All the actions on NIC Tx should have a mreg copy action to
4931 * copy reg_a from WQE to reg_c[0].
4934 * Pointer to Ethernet device.
4936 * Parent flow structure pointer.
4938 * Flow rule attributes.
4940 * Pattern specification (list terminated by the END pattern item).
4941 * @param[in] actions
4942 * Associated actions (list terminated by the END action).
4943 * @param[in] flow_split_info
4944 * Pointer to flow split info structure.
4946 * Perform verbose error reporting if not NULL.
4948 * 0 on success, negative value otherwise
4951 flow_create_split_metadata(struct rte_eth_dev *dev,
4952 struct rte_flow *flow,
4953 const struct rte_flow_attr *attr,
4954 const struct rte_flow_item items[],
4955 const struct rte_flow_action actions[],
4956 struct mlx5_flow_split_info *flow_split_info,
4957 struct rte_flow_error *error)
4959 struct mlx5_priv *priv = dev->data->dev_private;
4960 struct mlx5_dev_config *config = &priv->config;
4961 const struct rte_flow_action *qrss = NULL;
4962 struct rte_flow_action *ext_actions = NULL;
4963 struct mlx5_flow *dev_flow = NULL;
4964 uint32_t qrss_id = 0;
4971 /* Check whether extensive metadata feature is engaged. */
4972 if (!config->dv_flow_en ||
4973 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4974 !mlx5_flow_ext_mreg_supported(dev))
4975 return flow_create_split_inner(dev, flow, NULL, attr, items,
4976 actions, flow_split_info, error);
4977 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
4980 /* Exclude hairpin flows from splitting. */
4981 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
4982 const struct rte_flow_action_queue *queue;
4985 if (mlx5_rxq_get_type(dev, queue->index) ==
4986 MLX5_RXQ_TYPE_HAIRPIN)
4988 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
4989 const struct rte_flow_action_rss *rss;
4992 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
4993 MLX5_RXQ_TYPE_HAIRPIN)
4998 /* Check if it is in meter suffix table. */
4999 mtr_sfx = attr->group == (attr->transfer ?
5000 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
5001 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
5003 * Q/RSS action on NIC Rx should be split in order to pass by
5004 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5005 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5007 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5008 sizeof(struct rte_flow_action_set_tag) +
5009 sizeof(struct rte_flow_action_jump);
5010 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5013 return rte_flow_error_set(error, ENOMEM,
5014 RTE_FLOW_ERROR_TYPE_ACTION,
5015 NULL, "no memory to split "
5018 * If we are the suffix flow of meter, tag already exist.
5019 * Set the tag action to void.
5022 ext_actions[qrss - actions].type =
5023 RTE_FLOW_ACTION_TYPE_VOID;
5025 ext_actions[qrss - actions].type =
5026 (enum rte_flow_action_type)
5027 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5029 * Create the new actions list with removed Q/RSS action
5030 * and appended set tag and jump to register copy table
5031 * (RX_CP_TBL). We should preallocate unique tag ID here
5032 * in advance, because it is needed for set tag action.
5034 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5035 qrss, actions_n, error);
5036 if (!mtr_sfx && !qrss_id) {
5040 } else if (attr->egress && !attr->transfer) {
5042 * All the actions on NIC Tx should have a metadata register
5043 * copy action to copy reg_a from WQE to reg_c[meta]
5045 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5046 sizeof(struct mlx5_flow_action_copy_mreg);
5047 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5050 return rte_flow_error_set(error, ENOMEM,
5051 RTE_FLOW_ERROR_TYPE_ACTION,
5052 NULL, "no memory to split "
5054 /* Create the action list appended with copy register. */
5055 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5056 actions_n, error, encap_idx);
5060 /* Add the unmodified original or prefix subflow. */
5061 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5062 items, ext_actions ? ext_actions :
5063 actions, flow_split_info, error);
5066 MLX5_ASSERT(dev_flow);
5068 const struct rte_flow_attr q_attr = {
5069 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5072 /* Internal PMD action to set register. */
5073 struct mlx5_rte_flow_item_tag q_tag_spec = {
5077 struct rte_flow_item q_items[] = {
5079 .type = (enum rte_flow_item_type)
5080 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5081 .spec = &q_tag_spec,
5086 .type = RTE_FLOW_ITEM_TYPE_END,
5089 struct rte_flow_action q_actions[] = {
5095 .type = RTE_FLOW_ACTION_TYPE_END,
5098 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5101 * Configure the tag item only if there is no meter subflow.
5102 * Since tag is already marked in the meter suffix subflow
5103 * we can just use the meter suffix items as is.
5106 /* Not meter subflow. */
5107 MLX5_ASSERT(!mtr_sfx);
5109 * Put unique id in prefix flow due to it is destroyed
5110 * after suffix flow and id will be freed after there
5111 * is no actual flows with this id and identifier
5112 * reallocation becomes possible (for example, for
5113 * other flows in other threads).
5115 dev_flow->handle->split_flow_id = qrss_id;
5116 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5120 q_tag_spec.id = ret;
5123 /* Add suffix subflow to execute Q/RSS. */
5124 flow_split_info->prefix_layers = layers;
5125 flow_split_info->prefix_mark = 0;
5126 ret = flow_create_split_inner(dev, flow, &dev_flow,
5127 &q_attr, mtr_sfx ? items :
5129 flow_split_info, error);
5132 /* qrss ID should be freed if failed. */
5134 MLX5_ASSERT(dev_flow);
5139 * We do not destroy the partially created sub_flows in case of error.
5140 * These ones are included into parent flow list and will be destroyed
5141 * by flow_drv_destroy.
5143 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5145 mlx5_free(ext_actions);
5150 * The splitting for meter feature.
5152 * - The meter flow will be split to two flows as prefix and
5153 * suffix flow. The packets make sense only it pass the prefix
5156 * - Reg_C_5 is used for the packet to match betweend prefix and
5160 * Pointer to Ethernet device.
5162 * Parent flow structure pointer.
5164 * Flow rule attributes.
5166 * Pattern specification (list terminated by the END pattern item).
5167 * @param[in] actions
5168 * Associated actions (list terminated by the END action).
5169 * @param[in] flow_split_info
5170 * Pointer to flow split info structure.
5172 * Perform verbose error reporting if not NULL.
5174 * 0 on success, negative value otherwise
5177 flow_create_split_meter(struct rte_eth_dev *dev,
5178 struct rte_flow *flow,
5179 const struct rte_flow_attr *attr,
5180 const struct rte_flow_item items[],
5181 const struct rte_flow_action actions[],
5182 struct mlx5_flow_split_info *flow_split_info,
5183 struct rte_flow_error *error)
5185 struct mlx5_priv *priv = dev->data->dev_private;
5186 struct rte_flow_action *sfx_actions = NULL;
5187 struct rte_flow_action *pre_actions = NULL;
5188 struct rte_flow_item *sfx_items = NULL;
5189 struct mlx5_flow *dev_flow = NULL;
5190 struct rte_flow_attr sfx_attr = *attr;
5192 uint32_t mtr_tag_id = 0;
5199 actions_n = flow_check_meter_action(actions, &mtr);
5201 /* The five prefix actions: meter, decap, encap, tag, end. */
5202 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
5203 sizeof(struct mlx5_rte_flow_action_set_tag);
5204 /* tag, vlan, port id, end. */
5205 #define METER_SUFFIX_ITEM 4
5206 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5207 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5208 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5211 return rte_flow_error_set(error, ENOMEM,
5212 RTE_FLOW_ERROR_TYPE_ACTION,
5213 NULL, "no memory to split "
5215 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5217 pre_actions = sfx_actions + actions_n;
5218 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
5219 actions, sfx_actions,
5225 /* Add the prefix subflow. */
5226 flow_split_info->prefix_mark = 0;
5227 ret = flow_create_split_inner(dev, flow, &dev_flow,
5228 attr, items, pre_actions,
5229 flow_split_info, error);
5234 dev_flow->handle->split_flow_id = mtr_tag_id;
5235 /* Setting the sfx group atrr. */
5236 sfx_attr.group = sfx_attr.transfer ?
5237 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
5238 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
5239 flow_split_info->prefix_layers =
5240 flow_get_prefix_layer_flags(dev_flow);
5241 flow_split_info->prefix_mark = dev_flow->handle->mark;
5243 /* Add the prefix subflow. */
5244 ret = flow_create_split_metadata(dev, flow,
5245 &sfx_attr, sfx_items ?
5247 sfx_actions ? sfx_actions : actions,
5248 flow_split_info, error);
5251 mlx5_free(sfx_actions);
5256 * The splitting for sample feature.
5258 * Once Sample action is detected in the action list, the flow actions should
5259 * be split into prefix sub flow and suffix sub flow.
5261 * The original items remain in the prefix sub flow, all actions preceding the
5262 * sample action and the sample action itself will be copied to the prefix
5263 * sub flow, the actions following the sample action will be copied to the
5264 * suffix sub flow, Queue action always be located in the suffix sub flow.
5266 * In order to make the packet from prefix sub flow matches with suffix sub
5267 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5268 * flow uses tag item with the unique flow id.
5271 * Pointer to Ethernet device.
5273 * Parent flow structure pointer.
5275 * Flow rule attributes.
5277 * Pattern specification (list terminated by the END pattern item).
5278 * @param[in] actions
5279 * Associated actions (list terminated by the END action).
5280 * @param[in] flow_split_info
5281 * Pointer to flow split info structure.
5283 * Perform verbose error reporting if not NULL.
5285 * 0 on success, negative value otherwise
5288 flow_create_split_sample(struct rte_eth_dev *dev,
5289 struct rte_flow *flow,
5290 const struct rte_flow_attr *attr,
5291 const struct rte_flow_item items[],
5292 const struct rte_flow_action actions[],
5293 struct mlx5_flow_split_info *flow_split_info,
5294 struct rte_flow_error *error)
5296 struct mlx5_priv *priv = dev->data->dev_private;
5297 struct rte_flow_action *sfx_actions = NULL;
5298 struct rte_flow_action *pre_actions = NULL;
5299 struct rte_flow_item *sfx_items = NULL;
5300 struct mlx5_flow *dev_flow = NULL;
5301 struct rte_flow_attr sfx_attr = *attr;
5302 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5303 struct mlx5_flow_dv_sample_resource *sample_res;
5304 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
5305 struct mlx5_flow_tbl_resource *sfx_tbl;
5309 uint32_t fdb_tx = 0;
5312 int sample_action_pos;
5313 int qrss_action_pos;
5315 int modify_after_mirror = 0;
5316 uint16_t jump_table = 0;
5317 const uint32_t next_ft_step = 1;
5320 if (priv->sampler_en)
5321 actions_n = flow_check_match_action(actions, attr,
5322 RTE_FLOW_ACTION_TYPE_SAMPLE,
5323 &sample_action_pos, &qrss_action_pos,
5324 &modify_after_mirror);
5326 /* The prefix actions must includes sample, tag, end. */
5327 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
5328 + sizeof(struct mlx5_rte_flow_action_set_tag);
5329 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
5330 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5331 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
5332 item_size), 0, SOCKET_ID_ANY);
5334 return rte_flow_error_set(error, ENOMEM,
5335 RTE_FLOW_ERROR_TYPE_ACTION,
5336 NULL, "no memory to split "
5338 /* The representor_id is -1 for uplink. */
5339 fdb_tx = (attr->transfer && priv->representor_id != -1);
5341 * When reg_c_preserve is set, metadata registers Cx preserve
5342 * their value even through packet duplication.
5344 add_tag = (!fdb_tx || priv->config.hca_attr.reg_c_preserve);
5346 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
5348 if (modify_after_mirror)
5349 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
5351 pre_actions = sfx_actions + actions_n;
5352 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
5353 actions, sfx_actions,
5354 pre_actions, actions_n,
5356 qrss_action_pos, jump_table,
5358 if (tag_id < 0 || (add_tag && !tag_id)) {
5362 if (modify_after_mirror)
5363 flow_split_info->skip_scale =
5364 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5365 /* Add the prefix subflow. */
5366 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5368 flow_split_info, error);
5373 dev_flow->handle->split_flow_id = tag_id;
5374 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5375 if (!modify_after_mirror) {
5376 /* Set the sfx group attr. */
5377 sample_res = (struct mlx5_flow_dv_sample_resource *)
5378 dev_flow->dv.sample_res;
5379 sfx_tbl = (struct mlx5_flow_tbl_resource *)
5380 sample_res->normal_path_tbl;
5381 sfx_tbl_data = container_of(sfx_tbl,
5382 struct mlx5_flow_tbl_data_entry,
5384 sfx_attr.group = sfx_attr.transfer ?
5385 (sfx_tbl_data->table_id - 1) :
5386 sfx_tbl_data->table_id;
5388 MLX5_ASSERT(attr->transfer);
5389 sfx_attr.group = jump_table;
5391 flow_split_info->prefix_layers =
5392 flow_get_prefix_layer_flags(dev_flow);
5393 flow_split_info->prefix_mark = dev_flow->handle->mark;
5394 /* Suffix group level already be scaled with factor, set
5395 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
5396 * again in translation.
5398 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5401 /* Add the suffix subflow. */
5402 ret = flow_create_split_meter(dev, flow, &sfx_attr,
5403 sfx_items ? sfx_items : items,
5404 sfx_actions ? sfx_actions : actions,
5405 flow_split_info, error);
5408 mlx5_free(sfx_actions);
5413 * Split the flow to subflow set. The splitters might be linked
5414 * in the chain, like this:
5415 * flow_create_split_outer() calls:
5416 * flow_create_split_meter() calls:
5417 * flow_create_split_metadata(meter_subflow_0) calls:
5418 * flow_create_split_inner(metadata_subflow_0)
5419 * flow_create_split_inner(metadata_subflow_1)
5420 * flow_create_split_inner(metadata_subflow_2)
5421 * flow_create_split_metadata(meter_subflow_1) calls:
5422 * flow_create_split_inner(metadata_subflow_0)
5423 * flow_create_split_inner(metadata_subflow_1)
5424 * flow_create_split_inner(metadata_subflow_2)
5426 * This provide flexible way to add new levels of flow splitting.
5427 * The all of successfully created subflows are included to the
5428 * parent flow dev_flow list.
5431 * Pointer to Ethernet device.
5433 * Parent flow structure pointer.
5435 * Flow rule attributes.
5437 * Pattern specification (list terminated by the END pattern item).
5438 * @param[in] actions
5439 * Associated actions (list terminated by the END action).
5440 * @param[in] flow_split_info
5441 * Pointer to flow split info structure.
5443 * Perform verbose error reporting if not NULL.
5445 * 0 on success, negative value otherwise
5448 flow_create_split_outer(struct rte_eth_dev *dev,
5449 struct rte_flow *flow,
5450 const struct rte_flow_attr *attr,
5451 const struct rte_flow_item items[],
5452 const struct rte_flow_action actions[],
5453 struct mlx5_flow_split_info *flow_split_info,
5454 struct rte_flow_error *error)
5458 ret = flow_create_split_sample(dev, flow, attr, items,
5459 actions, flow_split_info, error);
5460 MLX5_ASSERT(ret <= 0);
5464 static struct mlx5_flow_tunnel *
5465 flow_tunnel_from_rule(struct rte_eth_dev *dev,
5466 const struct rte_flow_attr *attr,
5467 const struct rte_flow_item items[],
5468 const struct rte_flow_action actions[])
5470 struct mlx5_flow_tunnel *tunnel;
5472 #pragma GCC diagnostic push
5473 #pragma GCC diagnostic ignored "-Wcast-qual"
5474 if (is_flow_tunnel_match_rule(dev, attr, items, actions))
5475 tunnel = (struct mlx5_flow_tunnel *)items[0].spec;
5476 else if (is_flow_tunnel_steer_rule(dev, attr, items, actions))
5477 tunnel = (struct mlx5_flow_tunnel *)actions[0].conf;
5480 #pragma GCC diagnostic pop
5486 * Adjust flow RSS workspace if needed.
5489 * Pointer to thread flow work space.
5491 * Pointer to RSS descriptor.
5492 * @param[in] nrssq_num
5493 * New RSS queue number.
5496 * 0 on success, -1 otherwise and rte_errno is set.
5499 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
5500 struct mlx5_flow_rss_desc *rss_desc,
5503 if (likely(nrssq_num <= wks->rssq_num))
5505 rss_desc->queue = realloc(rss_desc->queue,
5506 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
5507 if (!rss_desc->queue) {
5511 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
5516 * Create a flow and add it to @p list.
5519 * Pointer to Ethernet device.
5521 * Pointer to a TAILQ flow list. If this parameter NULL,
5522 * no list insertion occurred, flow is just created,
5523 * this is caller's responsibility to track the
5526 * Flow rule attributes.
5528 * Pattern specification (list terminated by the END pattern item).
5529 * @param[in] actions
5530 * Associated actions (list terminated by the END action).
5531 * @param[in] external
5532 * This flow rule is created by request external to PMD.
5534 * Perform verbose error reporting if not NULL.
5537 * A flow index on success, 0 otherwise and rte_errno is set.
5540 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
5541 const struct rte_flow_attr *attr,
5542 const struct rte_flow_item items[],
5543 const struct rte_flow_action original_actions[],
5544 bool external, struct rte_flow_error *error)
5546 struct mlx5_priv *priv = dev->data->dev_private;
5547 struct rte_flow *flow = NULL;
5548 struct mlx5_flow *dev_flow;
5549 const struct rte_flow_action_rss *rss = NULL;
5550 struct mlx5_translated_shared_action
5551 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5552 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5554 struct mlx5_flow_expand_rss buf;
5555 uint8_t buffer[2048];
5558 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5559 uint8_t buffer[2048];
5562 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5563 uint8_t buffer[2048];
5564 } actions_hairpin_tx;
5566 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
5567 uint8_t buffer[2048];
5569 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
5570 struct mlx5_flow_rss_desc *rss_desc;
5571 const struct rte_flow_action *p_actions_rx;
5575 struct rte_flow_attr attr_tx = { .priority = 0 };
5576 const struct rte_flow_action *actions;
5577 struct rte_flow_action *translated_actions = NULL;
5578 struct mlx5_flow_tunnel *tunnel;
5579 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
5580 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
5581 struct mlx5_flow_split_info flow_split_info = {
5582 .external = !!external,
5591 rss_desc = &wks->rss_desc;
5592 ret = flow_shared_actions_translate(dev, original_actions,
5595 &translated_actions, error);
5597 MLX5_ASSERT(translated_actions == NULL);
5600 actions = translated_actions ? translated_actions : original_actions;
5601 p_actions_rx = actions;
5602 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5603 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
5604 external, hairpin_flow, error);
5606 goto error_before_hairpin_split;
5607 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
5610 goto error_before_hairpin_split;
5612 if (hairpin_flow > 0) {
5613 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
5615 goto error_before_hairpin_split;
5617 flow_hairpin_split(dev, actions, actions_rx.actions,
5618 actions_hairpin_tx.actions, items_tx.items,
5620 p_actions_rx = actions_rx.actions;
5622 flow_split_info.flow_idx = idx;
5623 flow->drv_type = flow_get_drv_type(dev, attr);
5624 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
5625 flow->drv_type < MLX5_FLOW_TYPE_MAX);
5626 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
5627 /* RSS Action only works on NIC RX domain */
5628 if (attr->ingress && !attr->transfer)
5629 rss = flow_get_rss_action(p_actions_rx);
5631 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
5634 * The following information is required by
5635 * mlx5_flow_hashfields_adjust() in advance.
5637 rss_desc->level = rss->level;
5638 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
5639 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
5641 flow->dev_handles = 0;
5642 if (rss && rss->types) {
5643 unsigned int graph_root;
5645 graph_root = find_graph_root(items, rss->level);
5646 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
5648 mlx5_support_expansion, graph_root);
5649 MLX5_ASSERT(ret > 0 &&
5650 (unsigned int)ret < sizeof(expand_buffer.buffer));
5653 buf->entry[0].pattern = (void *)(uintptr_t)items;
5655 rss_desc->shared_rss = flow_get_shared_rss_action(dev, shared_actions,
5657 for (i = 0; i < buf->entries; ++i) {
5658 /* Initialize flow split data. */
5659 flow_split_info.prefix_layers = 0;
5660 flow_split_info.prefix_mark = 0;
5661 flow_split_info.skip_scale = 0;
5663 * The splitter may create multiple dev_flows,
5664 * depending on configuration. In the simplest
5665 * case it just creates unmodified original flow.
5667 ret = flow_create_split_outer(dev, flow, attr,
5668 buf->entry[i].pattern,
5669 p_actions_rx, &flow_split_info,
5673 if (is_flow_tunnel_steer_rule(dev, attr,
5674 buf->entry[i].pattern,
5676 ret = flow_tunnel_add_default_miss(dev, flow, attr,
5682 mlx5_free(default_miss_ctx.queue);
5687 /* Create the tx flow. */
5689 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
5690 attr_tx.ingress = 0;
5692 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
5693 actions_hairpin_tx.actions,
5697 dev_flow->flow = flow;
5698 dev_flow->external = 0;
5699 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5700 dev_flow->handle, next);
5701 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
5703 actions_hairpin_tx.actions, error);
5708 * Update the metadata register copy table. If extensive
5709 * metadata feature is enabled and registers are supported
5710 * we might create the extra rte_flow for each unique
5711 * MARK/FLAG action ID.
5713 * The table is updated for ingress Flows only, because
5714 * the egress Flows belong to the different device and
5715 * copy table should be updated in peer NIC Rx domain.
5717 if (attr->ingress &&
5718 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
5719 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
5724 * If the flow is external (from application) OR device is started,
5725 * OR mreg discover, then apply immediately.
5727 if (external || dev->data->dev_started ||
5728 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
5729 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
5730 ret = flow_drv_apply(dev, flow, error);
5735 rte_spinlock_lock(&priv->flow_list_lock);
5736 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
5738 rte_spinlock_unlock(&priv->flow_list_lock);
5740 flow_rxq_flags_set(dev, flow);
5741 rte_free(translated_actions);
5742 tunnel = flow_tunnel_from_rule(dev, attr, items, actions);
5745 flow->tunnel_id = tunnel->tunnel_id;
5746 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
5747 mlx5_free(default_miss_ctx.queue);
5749 mlx5_flow_pop_thread_workspace();
5753 ret = rte_errno; /* Save rte_errno before cleanup. */
5754 flow_mreg_del_copy_action(dev, flow);
5755 flow_drv_destroy(dev, flow);
5756 if (rss_desc->shared_rss)
5757 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
5759 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
5760 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
5761 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
5762 rte_errno = ret; /* Restore rte_errno. */
5765 mlx5_flow_pop_thread_workspace();
5766 error_before_hairpin_split:
5767 rte_free(translated_actions);
5772 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
5773 * incoming packets to table 1.
5775 * Other flow rules, requested for group n, will be created in
5776 * e-switch table n+1.
5777 * Jump action to e-switch group n will be created to group n+1.
5779 * Used when working in switchdev mode, to utilise advantages of table 1
5783 * Pointer to Ethernet device.
5786 * Pointer to flow on success, NULL otherwise and rte_errno is set.
5789 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
5791 const struct rte_flow_attr attr = {
5798 const struct rte_flow_item pattern = {
5799 .type = RTE_FLOW_ITEM_TYPE_END,
5801 struct rte_flow_action_jump jump = {
5804 const struct rte_flow_action actions[] = {
5806 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5810 .type = RTE_FLOW_ACTION_TYPE_END,
5813 struct mlx5_priv *priv = dev->data->dev_private;
5814 struct rte_flow_error error;
5816 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
5818 actions, false, &error);
5822 * Validate a flow supported by the NIC.
5824 * @see rte_flow_validate()
5828 mlx5_flow_validate(struct rte_eth_dev *dev,
5829 const struct rte_flow_attr *attr,
5830 const struct rte_flow_item items[],
5831 const struct rte_flow_action original_actions[],
5832 struct rte_flow_error *error)
5835 struct mlx5_translated_shared_action
5836 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5837 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5838 const struct rte_flow_action *actions;
5839 struct rte_flow_action *translated_actions = NULL;
5840 int ret = flow_shared_actions_translate(dev, original_actions,
5843 &translated_actions, error);
5847 actions = translated_actions ? translated_actions : original_actions;
5848 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5849 ret = flow_drv_validate(dev, attr, items, actions,
5850 true, hairpin_flow, error);
5851 rte_free(translated_actions);
5858 * @see rte_flow_create()
5862 mlx5_flow_create(struct rte_eth_dev *dev,
5863 const struct rte_flow_attr *attr,
5864 const struct rte_flow_item items[],
5865 const struct rte_flow_action actions[],
5866 struct rte_flow_error *error)
5868 struct mlx5_priv *priv = dev->data->dev_private;
5871 * If the device is not started yet, it is not allowed to created a
5872 * flow from application. PMD default flows and traffic control flows
5875 if (unlikely(!dev->data->dev_started)) {
5876 DRV_LOG(DEBUG, "port %u is not started when "
5877 "inserting a flow", dev->data->port_id);
5878 rte_flow_error_set(error, ENODEV,
5879 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5881 "port not started");
5885 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
5886 attr, items, actions, true, error);
5890 * Destroy a flow in a list.
5893 * Pointer to Ethernet device.
5895 * Pointer to the Indexed flow list. If this parameter NULL,
5896 * there is no flow removal from the list. Be noted that as
5897 * flow is add to the indexed list, memory of the indexed
5898 * list points to maybe changed as flow destroyed.
5899 * @param[in] flow_idx
5900 * Index of flow to destroy.
5903 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
5906 struct mlx5_priv *priv = dev->data->dev_private;
5907 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5908 [MLX5_IPOOL_RTE_FLOW], flow_idx);
5913 * Update RX queue flags only if port is started, otherwise it is
5916 if (dev->data->dev_started)
5917 flow_rxq_flags_trim(dev, flow);
5918 flow_drv_destroy(dev, flow);
5920 rte_spinlock_lock(&priv->flow_list_lock);
5921 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
5922 flow_idx, flow, next);
5923 rte_spinlock_unlock(&priv->flow_list_lock);
5926 struct mlx5_flow_tunnel *tunnel;
5928 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
5930 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
5931 mlx5_flow_tunnel_free(dev, tunnel);
5933 flow_mreg_del_copy_action(dev, flow);
5934 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5938 * Destroy all flows.
5941 * Pointer to Ethernet device.
5943 * Pointer to the Indexed flow list.
5945 * If flushing is called avtively.
5948 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
5950 uint32_t num_flushed = 0;
5953 flow_list_destroy(dev, list, *list);
5957 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
5958 dev->data->port_id, num_flushed);
5963 * Stop all default actions for flows.
5966 * Pointer to Ethernet device.
5969 mlx5_flow_stop_default(struct rte_eth_dev *dev)
5971 flow_mreg_del_default_copy_action(dev);
5972 flow_rxq_flags_clear(dev);
5976 * Start all default actions for flows.
5979 * Pointer to Ethernet device.
5981 * 0 on success, a negative errno value otherwise and rte_errno is set.
5984 mlx5_flow_start_default(struct rte_eth_dev *dev)
5986 struct rte_flow_error error;
5988 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
5989 return flow_mreg_add_default_copy_action(dev, &error);
5993 * Release key of thread specific flow workspace data.
5996 flow_release_workspace(void *data)
5998 struct mlx5_flow_workspace *wks = data;
5999 struct mlx5_flow_workspace *next;
6003 free(wks->rss_desc.queue);
6010 * Get thread specific current flow workspace.
6012 * @return pointer to thread specific flow workspace data, NULL on error.
6014 struct mlx5_flow_workspace*
6015 mlx5_flow_get_thread_workspace(void)
6017 struct mlx5_flow_workspace *data;
6019 data = mlx5_flow_os_get_specific_workspace();
6020 MLX5_ASSERT(data && data->inuse);
6021 if (!data || !data->inuse)
6022 DRV_LOG(ERR, "flow workspace not initialized.");
6027 * Allocate and init new flow workspace.
6029 * @return pointer to flow workspace data, NULL on error.
6031 static struct mlx5_flow_workspace*
6032 flow_alloc_thread_workspace(void)
6034 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
6037 DRV_LOG(ERR, "Failed to allocate flow workspace "
6041 data->rss_desc.queue = calloc(1,
6042 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6043 if (!data->rss_desc.queue)
6045 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6048 if (data->rss_desc.queue)
6049 free(data->rss_desc.queue);
6055 * Get new thread specific flow workspace.
6057 * If current workspace inuse, create new one and set as current.
6059 * @return pointer to thread specific flow workspace data, NULL on error.
6061 static struct mlx5_flow_workspace*
6062 mlx5_flow_push_thread_workspace(void)
6064 struct mlx5_flow_workspace *curr;
6065 struct mlx5_flow_workspace *data;
6067 curr = mlx5_flow_os_get_specific_workspace();
6069 data = flow_alloc_thread_workspace();
6072 } else if (!curr->inuse) {
6074 } else if (curr->next) {
6077 data = flow_alloc_thread_workspace();
6085 /* Set as current workspace */
6086 if (mlx5_flow_os_set_specific_workspace(data))
6087 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6092 * Close current thread specific flow workspace.
6094 * If previous workspace available, set it as current.
6096 * @return pointer to thread specific flow workspace data, NULL on error.
6099 mlx5_flow_pop_thread_workspace(void)
6101 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6106 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6112 if (mlx5_flow_os_set_specific_workspace(data->prev))
6113 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6117 * Verify the flow list is empty
6120 * Pointer to Ethernet device.
6122 * @return the number of flows not released.
6125 mlx5_flow_verify(struct rte_eth_dev *dev)
6127 struct mlx5_priv *priv = dev->data->dev_private;
6128 struct rte_flow *flow;
6132 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
6134 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6135 dev->data->port_id, (void *)flow);
6142 * Enable default hairpin egress flow.
6145 * Pointer to Ethernet device.
6150 * 0 on success, a negative errno value otherwise and rte_errno is set.
6153 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6156 struct mlx5_priv *priv = dev->data->dev_private;
6157 const struct rte_flow_attr attr = {
6161 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6164 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6165 .queue = UINT32_MAX,
6167 struct rte_flow_item items[] = {
6169 .type = (enum rte_flow_item_type)
6170 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6171 .spec = &queue_spec,
6173 .mask = &queue_mask,
6176 .type = RTE_FLOW_ITEM_TYPE_END,
6179 struct rte_flow_action_jump jump = {
6180 .group = MLX5_HAIRPIN_TX_TABLE,
6182 struct rte_flow_action actions[2];
6184 struct rte_flow_error error;
6186 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6187 actions[0].conf = &jump;
6188 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6189 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6190 &attr, items, actions, false, &error);
6193 "Failed to create ctrl flow: rte_errno(%d),"
6194 " type(%d), message(%s)",
6195 rte_errno, error.type,
6196 error.message ? error.message : " (no stated reason)");
6203 * Enable a control flow configured from the control plane.
6206 * Pointer to Ethernet device.
6208 * An Ethernet flow spec to apply.
6210 * An Ethernet flow mask to apply.
6212 * A VLAN flow spec to apply.
6214 * A VLAN flow mask to apply.
6217 * 0 on success, a negative errno value otherwise and rte_errno is set.
6220 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6221 struct rte_flow_item_eth *eth_spec,
6222 struct rte_flow_item_eth *eth_mask,
6223 struct rte_flow_item_vlan *vlan_spec,
6224 struct rte_flow_item_vlan *vlan_mask)
6226 struct mlx5_priv *priv = dev->data->dev_private;
6227 const struct rte_flow_attr attr = {
6229 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6231 struct rte_flow_item items[] = {
6233 .type = RTE_FLOW_ITEM_TYPE_ETH,
6239 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6240 RTE_FLOW_ITEM_TYPE_END,
6246 .type = RTE_FLOW_ITEM_TYPE_END,
6249 uint16_t queue[priv->reta_idx_n];
6250 struct rte_flow_action_rss action_rss = {
6251 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6253 .types = priv->rss_conf.rss_hf,
6254 .key_len = priv->rss_conf.rss_key_len,
6255 .queue_num = priv->reta_idx_n,
6256 .key = priv->rss_conf.rss_key,
6259 struct rte_flow_action actions[] = {
6261 .type = RTE_FLOW_ACTION_TYPE_RSS,
6262 .conf = &action_rss,
6265 .type = RTE_FLOW_ACTION_TYPE_END,
6269 struct rte_flow_error error;
6272 if (!priv->reta_idx_n || !priv->rxqs_n) {
6275 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6276 action_rss.types = 0;
6277 for (i = 0; i != priv->reta_idx_n; ++i)
6278 queue[i] = (*priv->reta_idx)[i];
6279 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6280 &attr, items, actions, false, &error);
6287 * Enable a flow control configured from the control plane.
6290 * Pointer to Ethernet device.
6292 * An Ethernet flow spec to apply.
6294 * An Ethernet flow mask to apply.
6297 * 0 on success, a negative errno value otherwise and rte_errno is set.
6300 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6301 struct rte_flow_item_eth *eth_spec,
6302 struct rte_flow_item_eth *eth_mask)
6304 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6308 * Create default miss flow rule matching lacp traffic
6311 * Pointer to Ethernet device.
6313 * An Ethernet flow spec to apply.
6316 * 0 on success, a negative errno value otherwise and rte_errno is set.
6319 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6321 struct mlx5_priv *priv = dev->data->dev_private;
6323 * The LACP matching is done by only using ether type since using
6324 * a multicast dst mac causes kernel to give low priority to this flow.
6326 static const struct rte_flow_item_eth lacp_spec = {
6327 .type = RTE_BE16(0x8809),
6329 static const struct rte_flow_item_eth lacp_mask = {
6332 const struct rte_flow_attr attr = {
6335 struct rte_flow_item items[] = {
6337 .type = RTE_FLOW_ITEM_TYPE_ETH,
6342 .type = RTE_FLOW_ITEM_TYPE_END,
6345 struct rte_flow_action actions[] = {
6347 .type = (enum rte_flow_action_type)
6348 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
6351 .type = RTE_FLOW_ACTION_TYPE_END,
6354 struct rte_flow_error error;
6355 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6356 &attr, items, actions, false, &error);
6366 * @see rte_flow_destroy()
6370 mlx5_flow_destroy(struct rte_eth_dev *dev,
6371 struct rte_flow *flow,
6372 struct rte_flow_error *error __rte_unused)
6374 struct mlx5_priv *priv = dev->data->dev_private;
6376 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
6381 * Destroy all flows.
6383 * @see rte_flow_flush()
6387 mlx5_flow_flush(struct rte_eth_dev *dev,
6388 struct rte_flow_error *error __rte_unused)
6390 struct mlx5_priv *priv = dev->data->dev_private;
6392 mlx5_flow_list_flush(dev, &priv->flows, false);
6399 * @see rte_flow_isolate()
6403 mlx5_flow_isolate(struct rte_eth_dev *dev,
6405 struct rte_flow_error *error)
6407 struct mlx5_priv *priv = dev->data->dev_private;
6409 if (dev->data->dev_started) {
6410 rte_flow_error_set(error, EBUSY,
6411 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6413 "port must be stopped first");
6416 priv->isolated = !!enable;
6418 dev->dev_ops = &mlx5_dev_ops_isolate;
6420 dev->dev_ops = &mlx5_dev_ops;
6422 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
6423 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
6431 * @see rte_flow_query()
6435 flow_drv_query(struct rte_eth_dev *dev,
6437 const struct rte_flow_action *actions,
6439 struct rte_flow_error *error)
6441 struct mlx5_priv *priv = dev->data->dev_private;
6442 const struct mlx5_flow_driver_ops *fops;
6443 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
6444 [MLX5_IPOOL_RTE_FLOW],
6446 enum mlx5_flow_drv_type ftype;
6449 return rte_flow_error_set(error, ENOENT,
6450 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6452 "invalid flow handle");
6454 ftype = flow->drv_type;
6455 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
6456 fops = flow_get_drv_ops(ftype);
6458 return fops->query(dev, flow, actions, data, error);
6464 * @see rte_flow_query()
6468 mlx5_flow_query(struct rte_eth_dev *dev,
6469 struct rte_flow *flow,
6470 const struct rte_flow_action *actions,
6472 struct rte_flow_error *error)
6476 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
6484 * Get rte_flow callbacks.
6487 * Pointer to Ethernet device structure.
6489 * Pointer to operation-specific structure.
6494 mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
6495 const struct rte_flow_ops **ops)
6497 *ops = &mlx5_flow_ops;
6502 * Create the needed meter and suffix tables.
6505 * Pointer to Ethernet device.
6507 * Pointer to the flow meter.
6510 * Pointer to table set on success, NULL otherwise.
6512 struct mlx5_meter_domains_infos *
6513 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
6514 const struct mlx5_flow_meter *fm)
6516 const struct mlx5_flow_driver_ops *fops;
6518 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6519 return fops->create_mtr_tbls(dev, fm);
6523 * Destroy the meter table set.
6526 * Pointer to Ethernet device.
6528 * Pointer to the meter table set.
6534 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
6535 struct mlx5_meter_domains_infos *tbls)
6537 const struct mlx5_flow_driver_ops *fops;
6539 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6540 return fops->destroy_mtr_tbls(dev, tbls);
6544 * Create policer rules.
6547 * Pointer to Ethernet device.
6549 * Pointer to flow meter structure.
6551 * Pointer to flow attributes.
6554 * 0 on success, -1 otherwise.
6557 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
6558 struct mlx5_flow_meter *fm,
6559 const struct rte_flow_attr *attr)
6561 const struct mlx5_flow_driver_ops *fops;
6563 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6564 return fops->create_policer_rules(dev, fm, attr);
6568 * Destroy policer rules.
6571 * Pointer to flow meter structure.
6573 * Pointer to flow attributes.
6576 * 0 on success, -1 otherwise.
6579 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
6580 struct mlx5_flow_meter *fm,
6581 const struct rte_flow_attr *attr)
6583 const struct mlx5_flow_driver_ops *fops;
6585 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6586 return fops->destroy_policer_rules(dev, fm, attr);
6590 * Allocate a counter.
6593 * Pointer to Ethernet device structure.
6596 * Index to allocated counter on success, 0 otherwise.
6599 mlx5_counter_alloc(struct rte_eth_dev *dev)
6601 const struct mlx5_flow_driver_ops *fops;
6602 struct rte_flow_attr attr = { .transfer = 0 };
6604 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6605 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6606 return fops->counter_alloc(dev);
6609 "port %u counter allocate is not supported.",
6610 dev->data->port_id);
6618 * Pointer to Ethernet device structure.
6620 * Index to counter to be free.
6623 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
6625 const struct mlx5_flow_driver_ops *fops;
6626 struct rte_flow_attr attr = { .transfer = 0 };
6628 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6629 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6630 fops->counter_free(dev, cnt);
6634 "port %u counter free is not supported.",
6635 dev->data->port_id);
6639 * Query counter statistics.
6642 * Pointer to Ethernet device structure.
6644 * Index to counter to query.
6646 * Set to clear counter statistics.
6648 * The counter hits packets number to save.
6650 * The counter hits bytes number to save.
6653 * 0 on success, a negative errno value otherwise.
6656 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
6657 bool clear, uint64_t *pkts, uint64_t *bytes)
6659 const struct mlx5_flow_driver_ops *fops;
6660 struct rte_flow_attr attr = { .transfer = 0 };
6662 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6663 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6664 return fops->counter_query(dev, cnt, clear, pkts, bytes);
6667 "port %u counter query is not supported.",
6668 dev->data->port_id);
6673 * Allocate a new memory for the counter values wrapped by all the needed
6677 * Pointer to mlx5_dev_ctx_shared object.
6680 * 0 on success, a negative errno value otherwise.
6683 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
6685 struct mlx5_devx_mkey_attr mkey_attr;
6686 struct mlx5_counter_stats_mem_mng *mem_mng;
6687 volatile struct flow_counter_stats *raw_data;
6688 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
6689 int size = (sizeof(struct flow_counter_stats) *
6690 MLX5_COUNTERS_PER_POOL +
6691 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
6692 sizeof(struct mlx5_counter_stats_mem_mng);
6693 size_t pgsize = rte_mem_page_size();
6697 if (pgsize == (size_t)-1) {
6698 DRV_LOG(ERR, "Failed to get mem page size");
6702 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
6707 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
6708 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
6709 mem_mng->umem = mlx5_os_umem_reg(sh->ctx, mem, size,
6710 IBV_ACCESS_LOCAL_WRITE);
6711 if (!mem_mng->umem) {
6716 mkey_attr.addr = (uintptr_t)mem;
6717 mkey_attr.size = size;
6718 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
6719 mkey_attr.pd = sh->pdn;
6720 mkey_attr.log_entity_size = 0;
6721 mkey_attr.pg_access = 0;
6722 mkey_attr.klm_array = NULL;
6723 mkey_attr.klm_num = 0;
6724 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
6725 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
6726 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
6728 mlx5_os_umem_dereg(mem_mng->umem);
6733 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
6734 raw_data = (volatile struct flow_counter_stats *)mem;
6735 for (i = 0; i < raws_n; ++i) {
6736 mem_mng->raws[i].mem_mng = mem_mng;
6737 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
6739 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
6740 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
6741 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
6743 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
6744 sh->cmng.mem_mng = mem_mng;
6749 * Set the statistic memory to the new counter pool.
6752 * Pointer to mlx5_dev_ctx_shared object.
6754 * Pointer to the pool to set the statistic memory.
6757 * 0 on success, a negative errno value otherwise.
6760 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
6761 struct mlx5_flow_counter_pool *pool)
6763 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6764 /* Resize statistic memory once used out. */
6765 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
6766 mlx5_flow_create_counter_stat_mem_mng(sh)) {
6767 DRV_LOG(ERR, "Cannot resize counter stat mem.");
6770 rte_spinlock_lock(&pool->sl);
6771 pool->raw = cmng->mem_mng->raws + pool->index %
6772 MLX5_CNT_CONTAINER_RESIZE;
6773 rte_spinlock_unlock(&pool->sl);
6774 pool->raw_hw = NULL;
6778 #define MLX5_POOL_QUERY_FREQ_US 1000000
6781 * Set the periodic procedure for triggering asynchronous batch queries for all
6782 * the counter pools.
6785 * Pointer to mlx5_dev_ctx_shared object.
6788 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
6790 uint32_t pools_n, us;
6792 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
6793 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
6794 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
6795 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
6796 sh->cmng.query_thread_on = 0;
6797 DRV_LOG(ERR, "Cannot reinitialize query alarm");
6799 sh->cmng.query_thread_on = 1;
6804 * The periodic procedure for triggering asynchronous batch queries for all the
6805 * counter pools. This function is probably called by the host thread.
6808 * The parameter for the alarm process.
6811 mlx5_flow_query_alarm(void *arg)
6813 struct mlx5_dev_ctx_shared *sh = arg;
6815 uint16_t pool_index = sh->cmng.pool_index;
6816 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6817 struct mlx5_flow_counter_pool *pool;
6820 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
6822 rte_spinlock_lock(&cmng->pool_update_sl);
6823 pool = cmng->pools[pool_index];
6824 n_valid = cmng->n_valid;
6825 rte_spinlock_unlock(&cmng->pool_update_sl);
6826 /* Set the statistic memory to the new created pool. */
6827 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
6830 /* There is a pool query in progress. */
6833 LIST_FIRST(&sh->cmng.free_stat_raws);
6835 /* No free counter statistics raw memory. */
6838 * Identify the counters released between query trigger and query
6839 * handle more efficiently. The counter released in this gap period
6840 * should wait for a new round of query as the new arrived packets
6841 * will not be taken into account.
6844 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
6845 MLX5_COUNTERS_PER_POOL,
6847 pool->raw_hw->mem_mng->dm->id,
6851 (uint64_t)(uintptr_t)pool);
6853 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
6854 " %d", pool->min_dcs->id);
6855 pool->raw_hw = NULL;
6858 LIST_REMOVE(pool->raw_hw, next);
6859 sh->cmng.pending_queries++;
6861 if (pool_index >= n_valid)
6864 sh->cmng.pool_index = pool_index;
6865 mlx5_set_query_alarm(sh);
6869 * Check and callback event for new aged flow in the counter pool
6872 * Pointer to mlx5_dev_ctx_shared object.
6874 * Pointer to Current counter pool.
6877 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
6878 struct mlx5_flow_counter_pool *pool)
6880 struct mlx5_priv *priv;
6881 struct mlx5_flow_counter *cnt;
6882 struct mlx5_age_info *age_info;
6883 struct mlx5_age_param *age_param;
6884 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
6885 struct mlx5_counter_stats_raw *prev = pool->raw;
6886 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
6887 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
6888 uint16_t expected = AGE_CANDIDATE;
6891 pool->time_of_last_age_check = curr_time;
6892 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
6893 cnt = MLX5_POOL_GET_CNT(pool, i);
6894 age_param = MLX5_CNT_TO_AGE(cnt);
6895 if (__atomic_load_n(&age_param->state,
6896 __ATOMIC_RELAXED) != AGE_CANDIDATE)
6898 if (cur->data[i].hits != prev->data[i].hits) {
6899 __atomic_store_n(&age_param->sec_since_last_hit, 0,
6903 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
6905 __ATOMIC_RELAXED) <= age_param->timeout)
6908 * Hold the lock first, or if between the
6909 * state AGE_TMOUT and tailq operation the
6910 * release happened, the release procedure
6911 * may delete a non-existent tailq node.
6913 priv = rte_eth_devices[age_param->port_id].data->dev_private;
6914 age_info = GET_PORT_AGE_INFO(priv);
6915 rte_spinlock_lock(&age_info->aged_sl);
6916 if (__atomic_compare_exchange_n(&age_param->state, &expected,
6919 __ATOMIC_RELAXED)) {
6920 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
6921 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
6923 rte_spinlock_unlock(&age_info->aged_sl);
6925 mlx5_age_event_prepare(sh);
6929 * Handler for the HW respond about ready values from an asynchronous batch
6930 * query. This function is probably called by the host thread.
6933 * The pointer to the shared device context.
6934 * @param[in] async_id
6935 * The Devx async ID.
6937 * The status of the completion.
6940 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
6941 uint64_t async_id, int status)
6943 struct mlx5_flow_counter_pool *pool =
6944 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
6945 struct mlx5_counter_stats_raw *raw_to_free;
6946 uint8_t query_gen = pool->query_gen ^ 1;
6947 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6948 enum mlx5_counter_type cnt_type =
6949 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6950 MLX5_COUNTER_TYPE_ORIGIN;
6952 if (unlikely(status)) {
6953 raw_to_free = pool->raw_hw;
6955 raw_to_free = pool->raw;
6957 mlx5_flow_aging_check(sh, pool);
6958 rte_spinlock_lock(&pool->sl);
6959 pool->raw = pool->raw_hw;
6960 rte_spinlock_unlock(&pool->sl);
6961 /* Be sure the new raw counters data is updated in memory. */
6963 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
6964 rte_spinlock_lock(&cmng->csl[cnt_type]);
6965 TAILQ_CONCAT(&cmng->counters[cnt_type],
6966 &pool->counters[query_gen], next);
6967 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6970 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
6971 pool->raw_hw = NULL;
6972 sh->cmng.pending_queries--;
6976 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
6977 const struct flow_grp_info *grp_info,
6978 struct rte_flow_error *error)
6980 if (grp_info->transfer && grp_info->external &&
6981 grp_info->fdb_def_rule) {
6982 if (group == UINT32_MAX)
6983 return rte_flow_error_set
6985 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6987 "group index not supported");
6992 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
6997 * Translate the rte_flow group index to HW table value.
6999 * If tunnel offload is disabled, all group ids converted to flow table
7000 * id using the standard method.
7001 * If tunnel offload is enabled, group id can be converted using the
7002 * standard or tunnel conversion method. Group conversion method
7003 * selection depends on flags in `grp_info` parameter:
7004 * - Internal (grp_info.external == 0) groups conversion uses the
7006 * - Group ids in JUMP action converted with the tunnel conversion.
7007 * - Group id in rule attribute conversion depends on a rule type and
7009 * ** non zero group attributes converted with the tunnel method
7010 * ** zero group attribute in non-tunnel rule is converted using the
7011 * standard method - there's only one root table
7012 * ** zero group attribute in steer tunnel rule is converted with the
7013 * standard method - single root table
7014 * ** zero group attribute in match tunnel rule is a special OvS
7015 * case: that value is used for portability reasons. That group
7016 * id is converted with the tunnel conversion method.
7021 * PMD tunnel offload object
7023 * rte_flow group index value.
7026 * @param[in] grp_info
7027 * flags used for conversion
7029 * Pointer to error structure.
7032 * 0 on success, a negative errno value otherwise and rte_errno is set.
7035 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7036 const struct mlx5_flow_tunnel *tunnel,
7037 uint32_t group, uint32_t *table,
7038 const struct flow_grp_info *grp_info,
7039 struct rte_flow_error *error)
7042 bool standard_translation;
7044 if (!grp_info->skip_scale && grp_info->external &&
7045 group < MLX5_MAX_TABLES_EXTERNAL)
7046 group *= MLX5_FLOW_TABLE_FACTOR;
7047 if (is_tunnel_offload_active(dev)) {
7048 standard_translation = !grp_info->external ||
7049 grp_info->std_tbl_fix;
7051 standard_translation = true;
7054 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
7055 dev->data->port_id, group, grp_info->transfer,
7056 grp_info->external, grp_info->fdb_def_rule,
7057 standard_translation ? "STANDARD" : "TUNNEL");
7058 if (standard_translation)
7059 ret = flow_group_to_table(dev->data->port_id, group, table,
7062 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7069 * Discover availability of metadata reg_c's.
7071 * Iteratively use test flows to check availability.
7074 * Pointer to the Ethernet device structure.
7077 * 0 on success, a negative errno value otherwise and rte_errno is set.
7080 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7082 struct mlx5_priv *priv = dev->data->dev_private;
7083 struct mlx5_dev_config *config = &priv->config;
7084 enum modify_reg idx;
7087 /* reg_c[0] and reg_c[1] are reserved. */
7088 config->flow_mreg_c[n++] = REG_C_0;
7089 config->flow_mreg_c[n++] = REG_C_1;
7090 /* Discover availability of other reg_c's. */
7091 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7092 struct rte_flow_attr attr = {
7093 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7094 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7097 struct rte_flow_item items[] = {
7099 .type = RTE_FLOW_ITEM_TYPE_END,
7102 struct rte_flow_action actions[] = {
7104 .type = (enum rte_flow_action_type)
7105 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7106 .conf = &(struct mlx5_flow_action_copy_mreg){
7112 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7113 .conf = &(struct rte_flow_action_jump){
7114 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7118 .type = RTE_FLOW_ACTION_TYPE_END,
7122 struct rte_flow *flow;
7123 struct rte_flow_error error;
7125 if (!config->dv_flow_en)
7127 /* Create internal flow, validation skips copy action. */
7128 flow_idx = flow_list_create(dev, NULL, &attr, items,
7129 actions, false, &error);
7130 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
7134 config->flow_mreg_c[n++] = idx;
7135 flow_list_destroy(dev, NULL, flow_idx);
7137 for (; n < MLX5_MREG_C_NUM; ++n)
7138 config->flow_mreg_c[n] = REG_NON;
7143 * Dump flow raw hw data to file
7146 * The pointer to Ethernet device.
7148 * A pointer to a file for output.
7150 * Perform verbose error reporting if not NULL. PMDs initialize this
7151 * structure in case of error only.
7153 * 0 on success, a nagative value otherwise.
7156 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
7158 struct rte_flow_error *error __rte_unused)
7160 struct mlx5_priv *priv = dev->data->dev_private;
7161 struct mlx5_dev_ctx_shared *sh = priv->sh;
7163 if (!priv->config.dv_flow_en) {
7164 if (fputs("device dv flow disabled\n", file) <= 0)
7168 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
7169 sh->tx_domain, file);
7173 * Get aged-out flows.
7176 * Pointer to the Ethernet device structure.
7177 * @param[in] context
7178 * The address of an array of pointers to the aged-out flows contexts.
7179 * @param[in] nb_countexts
7180 * The length of context array pointers.
7182 * Perform verbose error reporting if not NULL. Initialized in case of
7186 * how many contexts get in success, otherwise negative errno value.
7187 * if nb_contexts is 0, return the amount of all aged contexts.
7188 * if nb_contexts is not 0 , return the amount of aged flows reported
7189 * in the context array.
7192 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
7193 uint32_t nb_contexts, struct rte_flow_error *error)
7195 const struct mlx5_flow_driver_ops *fops;
7196 struct rte_flow_attr attr = { .transfer = 0 };
7198 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7199 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7200 return fops->get_aged_flows(dev, contexts, nb_contexts,
7204 "port %u get aged flows is not supported.",
7205 dev->data->port_id);
7209 /* Wrapper for driver action_validate op callback */
7211 flow_drv_action_validate(struct rte_eth_dev *dev,
7212 const struct rte_flow_shared_action_conf *conf,
7213 const struct rte_flow_action *action,
7214 const struct mlx5_flow_driver_ops *fops,
7215 struct rte_flow_error *error)
7217 static const char err_msg[] = "shared action validation unsupported";
7219 if (!fops->action_validate) {
7220 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7221 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7225 return fops->action_validate(dev, conf, action, error);
7229 * Destroys the shared action by handle.
7232 * Pointer to Ethernet device structure.
7234 * Handle for the shared action to be destroyed.
7236 * Perform verbose error reporting if not NULL. PMDs initialize this
7237 * structure in case of error only.
7240 * 0 on success, a negative errno value otherwise and rte_errno is set.
7242 * @note: wrapper for driver action_create op callback.
7245 mlx5_shared_action_destroy(struct rte_eth_dev *dev,
7246 struct rte_flow_shared_action *action,
7247 struct rte_flow_error *error)
7249 static const char err_msg[] = "shared action destruction unsupported";
7250 struct rte_flow_attr attr = { .transfer = 0 };
7251 const struct mlx5_flow_driver_ops *fops =
7252 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7254 if (!fops->action_destroy) {
7255 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7256 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7260 return fops->action_destroy(dev, action, error);
7263 /* Wrapper for driver action_destroy op callback */
7265 flow_drv_action_update(struct rte_eth_dev *dev,
7266 struct rte_flow_shared_action *action,
7267 const void *action_conf,
7268 const struct mlx5_flow_driver_ops *fops,
7269 struct rte_flow_error *error)
7271 static const char err_msg[] = "shared action update unsupported";
7273 if (!fops->action_update) {
7274 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7275 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7279 return fops->action_update(dev, action, action_conf, error);
7282 /* Wrapper for driver action_destroy op callback */
7284 flow_drv_action_query(struct rte_eth_dev *dev,
7285 const struct rte_flow_shared_action *action,
7287 const struct mlx5_flow_driver_ops *fops,
7288 struct rte_flow_error *error)
7290 static const char err_msg[] = "shared action query unsupported";
7292 if (!fops->action_query) {
7293 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7294 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7298 return fops->action_query(dev, action, data, error);
7302 * Create shared action for reuse in multiple flow rules.
7305 * Pointer to Ethernet device structure.
7307 * Action configuration for shared action creation.
7309 * Perform verbose error reporting if not NULL. PMDs initialize this
7310 * structure in case of error only.
7312 * A valid handle in case of success, NULL otherwise and rte_errno is set.
7314 static struct rte_flow_shared_action *
7315 mlx5_shared_action_create(struct rte_eth_dev *dev,
7316 const struct rte_flow_shared_action_conf *conf,
7317 const struct rte_flow_action *action,
7318 struct rte_flow_error *error)
7320 static const char err_msg[] = "shared action creation unsupported";
7321 struct rte_flow_attr attr = { .transfer = 0 };
7322 const struct mlx5_flow_driver_ops *fops =
7323 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7325 if (flow_drv_action_validate(dev, conf, action, fops, error))
7327 if (!fops->action_create) {
7328 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7329 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7333 return fops->action_create(dev, conf, action, error);
7337 * Updates inplace the shared action configuration pointed by *action* handle
7338 * with the configuration provided as *action* argument.
7339 * The update of the shared action configuration effects all flow rules reusing
7340 * the action via handle.
7343 * Pointer to Ethernet device structure.
7344 * @param[in] shared_action
7345 * Handle for the shared action to be updated.
7347 * Action specification used to modify the action pointed by handle.
7348 * *action* should be of same type with the action pointed by the *action*
7349 * handle argument, otherwise considered as invalid.
7351 * Perform verbose error reporting if not NULL. PMDs initialize this
7352 * structure in case of error only.
7355 * 0 on success, a negative errno value otherwise and rte_errno is set.
7358 mlx5_shared_action_update(struct rte_eth_dev *dev,
7359 struct rte_flow_shared_action *shared_action,
7360 const struct rte_flow_action *action,
7361 struct rte_flow_error *error)
7363 struct rte_flow_attr attr = { .transfer = 0 };
7364 const struct mlx5_flow_driver_ops *fops =
7365 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7368 ret = flow_drv_action_validate(dev, NULL, action, fops, error);
7371 return flow_drv_action_update(dev, shared_action, action->conf, fops,
7376 * Query the shared action by handle.
7378 * This function allows retrieving action-specific data such as counters.
7379 * Data is gathered by special action which may be present/referenced in
7380 * more than one flow rule definition.
7382 * \see RTE_FLOW_ACTION_TYPE_COUNT
7385 * Pointer to Ethernet device structure.
7387 * Handle for the shared action to query.
7388 * @param[in, out] data
7389 * Pointer to storage for the associated query data type.
7391 * Perform verbose error reporting if not NULL. PMDs initialize this
7392 * structure in case of error only.
7395 * 0 on success, a negative errno value otherwise and rte_errno is set.
7398 mlx5_shared_action_query(struct rte_eth_dev *dev,
7399 const struct rte_flow_shared_action *action,
7401 struct rte_flow_error *error)
7403 struct rte_flow_attr attr = { .transfer = 0 };
7404 const struct mlx5_flow_driver_ops *fops =
7405 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7407 return flow_drv_action_query(dev, action, data, fops, error);
7411 * Destroy all shared actions.
7414 * Pointer to Ethernet device.
7417 * 0 on success, a negative errno value otherwise and rte_errno is set.
7420 mlx5_shared_action_flush(struct rte_eth_dev *dev)
7422 struct rte_flow_error error;
7423 struct mlx5_priv *priv = dev->data->dev_private;
7424 struct mlx5_shared_action_rss *shared_rss;
7428 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
7429 priv->rss_shared_actions, idx, shared_rss, next) {
7430 ret |= mlx5_shared_action_destroy(dev,
7431 (struct rte_flow_shared_action *)(uintptr_t)idx, &error);
7436 #ifndef HAVE_MLX5DV_DR
7437 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
7439 #define MLX5_DOMAIN_SYNC_FLOW \
7440 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
7443 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
7445 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
7446 const struct mlx5_flow_driver_ops *fops;
7448 struct rte_flow_attr attr = { .transfer = 0 };
7450 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7451 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
7458 * tunnel offload functionalilty is defined for DV environment only
7460 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7462 union tunnel_offload_mark {
7465 uint32_t app_reserve:8;
7466 uint32_t table_id:15;
7467 uint32_t transfer:1;
7468 uint32_t _unused_:8;
7473 mlx5_access_tunnel_offload_db
7474 (struct rte_eth_dev *dev,
7475 bool (*match)(struct rte_eth_dev *,
7476 struct mlx5_flow_tunnel *, const void *),
7477 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
7478 void (*miss)(struct rte_eth_dev *, void *),
7479 void *ctx, bool lock_op);
7482 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
7483 struct rte_flow *flow,
7484 const struct rte_flow_attr *attr,
7485 const struct rte_flow_action *app_actions,
7487 struct tunnel_default_miss_ctx *ctx,
7488 struct rte_flow_error *error)
7490 struct mlx5_priv *priv = dev->data->dev_private;
7491 struct mlx5_flow *dev_flow;
7492 struct rte_flow_attr miss_attr = *attr;
7493 const struct mlx5_flow_tunnel *tunnel = app_actions[0].conf;
7494 const struct rte_flow_item miss_items[2] = {
7496 .type = RTE_FLOW_ITEM_TYPE_ETH,
7502 .type = RTE_FLOW_ITEM_TYPE_END,
7508 union tunnel_offload_mark mark_id;
7509 struct rte_flow_action_mark miss_mark;
7510 struct rte_flow_action miss_actions[3] = {
7511 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
7512 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
7514 const struct rte_flow_action_jump *jump_data;
7515 uint32_t i, flow_table = 0; /* prevent compilation warning */
7516 struct flow_grp_info grp_info = {
7518 .transfer = attr->transfer,
7519 .fdb_def_rule = !!priv->fdb_def_rule,
7524 if (!attr->transfer) {
7527 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
7528 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
7529 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
7532 return rte_flow_error_set
7534 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
7535 NULL, "invalid default miss RSS");
7536 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
7537 ctx->action_rss.level = 0,
7538 ctx->action_rss.types = priv->rss_conf.rss_hf,
7539 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
7540 ctx->action_rss.queue_num = priv->reta_idx_n,
7541 ctx->action_rss.key = priv->rss_conf.rss_key,
7542 ctx->action_rss.queue = ctx->queue;
7543 if (!priv->reta_idx_n || !priv->rxqs_n)
7544 return rte_flow_error_set
7546 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
7547 NULL, "invalid port configuration");
7548 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
7549 ctx->action_rss.types = 0;
7550 for (i = 0; i != priv->reta_idx_n; ++i)
7551 ctx->queue[i] = (*priv->reta_idx)[i];
7553 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
7554 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
7556 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
7557 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
7558 jump_data = app_actions->conf;
7559 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
7560 miss_attr.group = jump_data->group;
7561 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
7562 &flow_table, &grp_info, error);
7564 return rte_flow_error_set(error, EINVAL,
7565 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
7566 NULL, "invalid tunnel id");
7567 mark_id.app_reserve = 0;
7568 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
7569 mark_id.transfer = !!attr->transfer;
7570 mark_id._unused_ = 0;
7571 miss_mark.id = mark_id.val;
7572 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
7573 miss_items, miss_actions, flow_idx, error);
7576 dev_flow->flow = flow;
7577 dev_flow->external = true;
7578 dev_flow->tunnel = tunnel;
7579 /* Subflow object was created, we must include one in the list. */
7580 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
7581 dev_flow->handle, next);
7583 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
7584 dev->data->port_id, tunnel->app_tunnel.type,
7585 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
7586 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
7587 miss_actions, error);
7589 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
7595 static const struct mlx5_flow_tbl_data_entry *
7596 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
7598 struct mlx5_priv *priv = dev->data->dev_private;
7599 struct mlx5_dev_ctx_shared *sh = priv->sh;
7600 struct mlx5_hlist_entry *he;
7601 union tunnel_offload_mark mbits = { .val = mark };
7602 union mlx5_flow_tbl_key table_key = {
7604 .table_id = tunnel_id_to_flow_tbl(mbits.table_id),
7606 .domain = !!mbits.transfer,
7610 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, NULL);
7612 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
7616 mlx5_flow_tunnel_grp2tbl_remove_cb(struct mlx5_hlist *list,
7617 struct mlx5_hlist_entry *entry)
7619 struct mlx5_dev_ctx_shared *sh = list->ctx;
7620 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
7622 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
7623 tunnel_flow_tbl_to_id(tte->flow_table));
7628 mlx5_flow_tunnel_grp2tbl_match_cb(struct mlx5_hlist *list __rte_unused,
7629 struct mlx5_hlist_entry *entry,
7630 uint64_t key, void *cb_ctx __rte_unused)
7632 union tunnel_tbl_key tbl = {
7635 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
7637 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
7640 static struct mlx5_hlist_entry *
7641 mlx5_flow_tunnel_grp2tbl_create_cb(struct mlx5_hlist *list, uint64_t key,
7642 void *ctx __rte_unused)
7644 struct mlx5_dev_ctx_shared *sh = list->ctx;
7645 struct tunnel_tbl_entry *tte;
7646 union tunnel_tbl_key tbl = {
7650 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
7655 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
7657 if (tte->flow_table >= MLX5_MAX_TABLES) {
7658 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
7660 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
7663 } else if (!tte->flow_table) {
7666 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
7667 tte->tunnel_id = tbl.tunnel_id;
7668 tte->group = tbl.group;
7677 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
7678 const struct mlx5_flow_tunnel *tunnel,
7679 uint32_t group, uint32_t *table,
7680 struct rte_flow_error *error)
7682 struct mlx5_hlist_entry *he;
7683 struct tunnel_tbl_entry *tte;
7684 union tunnel_tbl_key key = {
7685 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
7688 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7689 struct mlx5_hlist *group_hash;
7691 group_hash = tunnel ? tunnel->groups : thub->groups;
7692 he = mlx5_hlist_register(group_hash, key.val, NULL);
7694 return rte_flow_error_set(error, EINVAL,
7695 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7697 "tunnel group index not supported");
7698 tte = container_of(he, typeof(*tte), hash);
7699 *table = tte->flow_table;
7700 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
7701 dev->data->port_id, key.tunnel_id, group, *table);
7706 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
7707 struct mlx5_flow_tunnel *tunnel)
7709 struct mlx5_priv *priv = dev->data->dev_private;
7710 struct mlx5_indexed_pool *ipool;
7712 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
7713 dev->data->port_id, tunnel->tunnel_id);
7714 LIST_REMOVE(tunnel, chain);
7715 mlx5_hlist_destroy(tunnel->groups);
7716 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
7717 mlx5_ipool_free(ipool, tunnel->tunnel_id);
7721 mlx5_access_tunnel_offload_db
7722 (struct rte_eth_dev *dev,
7723 bool (*match)(struct rte_eth_dev *,
7724 struct mlx5_flow_tunnel *, const void *),
7725 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
7726 void (*miss)(struct rte_eth_dev *, void *),
7727 void *ctx, bool lock_op)
7729 bool verdict = false;
7730 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7731 struct mlx5_flow_tunnel *tunnel;
7733 rte_spinlock_lock(&thub->sl);
7734 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
7735 verdict = match(dev, tunnel, (const void *)ctx);
7740 rte_spinlock_unlock(&thub->sl);
7742 hit(dev, tunnel, ctx);
7743 if (!verdict && miss)
7746 rte_spinlock_unlock(&thub->sl);
7751 struct tunnel_db_find_tunnel_id_ctx {
7753 struct mlx5_flow_tunnel *tunnel;
7757 find_tunnel_id_match(struct rte_eth_dev *dev,
7758 struct mlx5_flow_tunnel *tunnel, const void *x)
7760 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
7763 return tunnel->tunnel_id == ctx->tunnel_id;
7767 find_tunnel_id_hit(struct rte_eth_dev *dev,
7768 struct mlx5_flow_tunnel *tunnel, void *x)
7770 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
7772 ctx->tunnel = tunnel;
7775 static struct mlx5_flow_tunnel *
7776 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
7778 struct tunnel_db_find_tunnel_id_ctx ctx = {
7782 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
7783 find_tunnel_id_hit, NULL, &ctx, true);
7788 static struct mlx5_flow_tunnel *
7789 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
7790 const struct rte_flow_tunnel *app_tunnel)
7792 struct mlx5_priv *priv = dev->data->dev_private;
7793 struct mlx5_indexed_pool *ipool;
7794 struct mlx5_flow_tunnel *tunnel;
7797 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
7798 tunnel = mlx5_ipool_zmalloc(ipool, &id);
7801 if (id >= MLX5_MAX_TUNNELS) {
7802 mlx5_ipool_free(ipool, id);
7803 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
7806 tunnel->groups = mlx5_hlist_create("tunnel groups", 1024, 0, 0,
7807 mlx5_flow_tunnel_grp2tbl_create_cb,
7808 mlx5_flow_tunnel_grp2tbl_match_cb,
7809 mlx5_flow_tunnel_grp2tbl_remove_cb);
7810 if (!tunnel->groups) {
7811 mlx5_ipool_free(ipool, id);
7814 tunnel->groups->ctx = priv->sh;
7815 /* initiate new PMD tunnel */
7816 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
7817 tunnel->tunnel_id = id;
7818 tunnel->action.type = (typeof(tunnel->action.type))
7819 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
7820 tunnel->action.conf = tunnel;
7821 tunnel->item.type = (typeof(tunnel->item.type))
7822 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
7823 tunnel->item.spec = tunnel;
7824 tunnel->item.last = NULL;
7825 tunnel->item.mask = NULL;
7827 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
7828 dev->data->port_id, tunnel->tunnel_id);
7833 struct tunnel_db_get_tunnel_ctx {
7834 const struct rte_flow_tunnel *app_tunnel;
7835 struct mlx5_flow_tunnel *tunnel;
7838 static bool get_tunnel_match(struct rte_eth_dev *dev,
7839 struct mlx5_flow_tunnel *tunnel, const void *x)
7841 const struct tunnel_db_get_tunnel_ctx *ctx = x;
7844 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
7845 sizeof(*ctx->app_tunnel));
7848 static void get_tunnel_hit(struct rte_eth_dev *dev,
7849 struct mlx5_flow_tunnel *tunnel, void *x)
7851 /* called under tunnel spinlock protection */
7852 struct tunnel_db_get_tunnel_ctx *ctx = x;
7856 ctx->tunnel = tunnel;
7859 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
7861 /* called under tunnel spinlock protection */
7862 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7863 struct tunnel_db_get_tunnel_ctx *ctx = x;
7865 rte_spinlock_unlock(&thub->sl);
7866 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
7867 rte_spinlock_lock(&thub->sl);
7869 ctx->tunnel->refctn = 1;
7870 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
7876 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
7877 const struct rte_flow_tunnel *app_tunnel,
7878 struct mlx5_flow_tunnel **tunnel)
7880 struct tunnel_db_get_tunnel_ctx ctx = {
7881 .app_tunnel = app_tunnel,
7884 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
7885 get_tunnel_miss, &ctx, true);
7886 *tunnel = ctx.tunnel;
7887 return ctx.tunnel ? 0 : -ENOMEM;
7890 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
7892 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
7896 if (!LIST_EMPTY(&thub->tunnels))
7897 DRV_LOG(WARNING, "port %u tunnels present", port_id);
7898 mlx5_hlist_destroy(thub->groups);
7902 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
7905 struct mlx5_flow_tunnel_hub *thub;
7907 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
7911 LIST_INIT(&thub->tunnels);
7912 rte_spinlock_init(&thub->sl);
7913 thub->groups = mlx5_hlist_create("flow groups",
7914 rte_align32pow2(MLX5_MAX_TABLES), 0,
7915 0, mlx5_flow_tunnel_grp2tbl_create_cb,
7916 mlx5_flow_tunnel_grp2tbl_match_cb,
7917 mlx5_flow_tunnel_grp2tbl_remove_cb);
7918 if (!thub->groups) {
7922 thub->groups->ctx = sh;
7923 sh->tunnel_hub = thub;
7929 mlx5_hlist_destroy(thub->groups);
7936 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
7937 struct rte_flow_tunnel *tunnel,
7938 const char *err_msg)
7941 if (!is_tunnel_offload_active(dev)) {
7942 err_msg = "tunnel offload was not activated";
7944 } else if (!tunnel) {
7945 err_msg = "no application tunnel";
7949 switch (tunnel->type) {
7951 err_msg = "unsupported tunnel type";
7953 case RTE_FLOW_ITEM_TYPE_VXLAN:
7962 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
7963 struct rte_flow_tunnel *app_tunnel,
7964 struct rte_flow_action **actions,
7965 uint32_t *num_of_actions,
7966 struct rte_flow_error *error)
7969 struct mlx5_flow_tunnel *tunnel;
7970 const char *err_msg = NULL;
7971 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
7974 return rte_flow_error_set(error, EINVAL,
7975 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
7977 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
7979 return rte_flow_error_set(error, ret,
7980 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
7981 "failed to initialize pmd tunnel");
7983 *actions = &tunnel->action;
7984 *num_of_actions = 1;
7989 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
7990 struct rte_flow_tunnel *app_tunnel,
7991 struct rte_flow_item **items,
7992 uint32_t *num_of_items,
7993 struct rte_flow_error *error)
7996 struct mlx5_flow_tunnel *tunnel;
7997 const char *err_msg = NULL;
7998 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
8001 return rte_flow_error_set(error, EINVAL,
8002 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
8004 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
8006 return rte_flow_error_set(error, ret,
8007 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
8008 "failed to initialize pmd tunnel");
8010 *items = &tunnel->item;
8015 struct tunnel_db_element_release_ctx {
8016 struct rte_flow_item *items;
8017 struct rte_flow_action *actions;
8018 uint32_t num_elements;
8019 struct rte_flow_error *error;
8024 tunnel_element_release_match(struct rte_eth_dev *dev,
8025 struct mlx5_flow_tunnel *tunnel, const void *x)
8027 const struct tunnel_db_element_release_ctx *ctx = x;
8030 if (ctx->num_elements != 1)
8032 else if (ctx->items)
8033 return ctx->items == &tunnel->item;
8034 else if (ctx->actions)
8035 return ctx->actions == &tunnel->action;
8041 tunnel_element_release_hit(struct rte_eth_dev *dev,
8042 struct mlx5_flow_tunnel *tunnel, void *x)
8044 struct tunnel_db_element_release_ctx *ctx = x;
8046 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
8047 mlx5_flow_tunnel_free(dev, tunnel);
8051 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
8053 struct tunnel_db_element_release_ctx *ctx = x;
8055 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
8056 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
8057 "invalid argument");
8061 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
8062 struct rte_flow_item *pmd_items,
8063 uint32_t num_items, struct rte_flow_error *err)
8065 struct tunnel_db_element_release_ctx ctx = {
8068 .num_elements = num_items,
8072 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
8073 tunnel_element_release_hit,
8074 tunnel_element_release_miss, &ctx, false);
8080 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
8081 struct rte_flow_action *pmd_actions,
8082 uint32_t num_actions, struct rte_flow_error *err)
8084 struct tunnel_db_element_release_ctx ctx = {
8086 .actions = pmd_actions,
8087 .num_elements = num_actions,
8091 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
8092 tunnel_element_release_hit,
8093 tunnel_element_release_miss, &ctx, false);
8099 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
8101 struct rte_flow_restore_info *info,
8102 struct rte_flow_error *err)
8104 uint64_t ol_flags = m->ol_flags;
8105 const struct mlx5_flow_tbl_data_entry *tble;
8106 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
8108 if (!is_tunnel_offload_active(dev)) {
8113 if ((ol_flags & mask) != mask)
8115 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
8117 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
8118 dev->data->port_id, m->hash.fdir.hi);
8121 MLX5_ASSERT(tble->tunnel);
8122 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
8123 info->group_id = tble->group_id;
8124 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
8125 RTE_FLOW_RESTORE_INFO_GROUP_ID |
8126 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
8131 return rte_flow_error_set(err, EINVAL,
8132 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8133 "failed to get restore info");
8136 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
8138 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
8139 __rte_unused struct rte_flow_tunnel *app_tunnel,
8140 __rte_unused struct rte_flow_action **actions,
8141 __rte_unused uint32_t *num_of_actions,
8142 __rte_unused struct rte_flow_error *error)
8148 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
8149 __rte_unused struct rte_flow_tunnel *app_tunnel,
8150 __rte_unused struct rte_flow_item **items,
8151 __rte_unused uint32_t *num_of_items,
8152 __rte_unused struct rte_flow_error *error)
8158 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
8159 __rte_unused struct rte_flow_item *pmd_items,
8160 __rte_unused uint32_t num_items,
8161 __rte_unused struct rte_flow_error *err)
8167 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
8168 __rte_unused struct rte_flow_action *pmd_action,
8169 __rte_unused uint32_t num_actions,
8170 __rte_unused struct rte_flow_error *err)
8176 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
8177 __rte_unused struct rte_mbuf *m,
8178 __rte_unused struct rte_flow_restore_info *i,
8179 __rte_unused struct rte_flow_error *err)
8185 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
8186 __rte_unused struct rte_flow *flow,
8187 __rte_unused const struct rte_flow_attr *attr,
8188 __rte_unused const struct rte_flow_action *actions,
8189 __rte_unused uint32_t flow_idx,
8190 __rte_unused struct tunnel_default_miss_ctx *ctx,
8191 __rte_unused struct rte_flow_error *error)
8196 static struct mlx5_flow_tunnel *
8197 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
8198 __rte_unused uint32_t id)
8204 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
8205 __rte_unused struct mlx5_flow_tunnel *tunnel)
8210 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
8211 __rte_unused const struct mlx5_flow_tunnel *t,
8212 __rte_unused uint32_t group,
8213 __rte_unused uint32_t *table,
8214 struct rte_flow_error *error)
8216 return rte_flow_error_set(error, ENOTSUP,
8217 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8218 "tunnel offload requires DV support");
8222 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
8223 __rte_unused uint16_t port_id)
8226 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */