1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
6 #include <netinet/in.h>
13 #include <rte_common.h>
14 #include <rte_ether.h>
15 #include <ethdev_driver.h>
16 #include <rte_eal_paging.h>
18 #include <rte_cycles.h>
19 #include <rte_flow_driver.h>
20 #include <rte_malloc.h>
23 #include <mlx5_glue.h>
24 #include <mlx5_devx_cmds.h>
26 #include <mlx5_malloc.h>
28 #include "mlx5_defs.h"
30 #include "mlx5_flow.h"
31 #include "mlx5_flow_os.h"
32 #include "mlx5_rxtx.h"
33 #include "mlx5_common_os.h"
34 #include "rte_pmd_mlx5.h"
36 struct tunnel_default_miss_ctx {
40 struct rte_flow_action_rss action_rss;
41 struct rte_flow_action_queue miss_queue;
42 struct rte_flow_action_jump miss_jump;
48 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
49 struct rte_flow *flow,
50 const struct rte_flow_attr *attr,
51 const struct rte_flow_action *app_actions,
53 struct tunnel_default_miss_ctx *ctx,
54 struct rte_flow_error *error);
55 static struct mlx5_flow_tunnel *
56 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
58 mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
60 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
61 const struct mlx5_flow_tunnel *tunnel,
62 uint32_t group, uint32_t *table,
63 struct rte_flow_error *error);
65 static struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);
66 static void mlx5_flow_pop_thread_workspace(void);
69 /** Device flow drivers. */
70 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
72 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
74 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
75 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
76 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
77 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
79 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
80 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
83 /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
84 #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
89 /** Node object of input graph for mlx5_flow_expand_rss(). */
90 struct mlx5_flow_expand_node {
91 const int *const next;
93 * List of next node indexes. Index 0 is interpreted as a terminator.
95 const enum rte_flow_item_type type;
96 /**< Pattern item type of current node. */
99 * RSS types bit-field associated with this node
100 * (see ETH_RSS_* definitions).
104 /** Object returned by mlx5_flow_expand_rss(). */
105 struct mlx5_flow_expand_rss {
107 /**< Number of entries @p patterns and @p priorities. */
109 struct rte_flow_item *pattern; /**< Expanded pattern array. */
110 uint32_t priority; /**< Priority offset for each expansion. */
114 static enum rte_flow_item_type
115 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
117 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
118 uint16_t ether_type = 0;
119 uint16_t ether_type_m;
120 uint8_t ip_next_proto = 0;
121 uint8_t ip_next_proto_m;
123 if (item == NULL || item->spec == NULL)
125 switch (item->type) {
126 case RTE_FLOW_ITEM_TYPE_ETH:
128 ether_type_m = ((const struct rte_flow_item_eth *)
131 ether_type_m = rte_flow_item_eth_mask.type;
132 if (ether_type_m != RTE_BE16(0xFFFF))
134 ether_type = ((const struct rte_flow_item_eth *)
136 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
137 ret = RTE_FLOW_ITEM_TYPE_IPV4;
138 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
139 ret = RTE_FLOW_ITEM_TYPE_IPV6;
140 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
141 ret = RTE_FLOW_ITEM_TYPE_VLAN;
143 ret = RTE_FLOW_ITEM_TYPE_END;
145 case RTE_FLOW_ITEM_TYPE_VLAN:
147 ether_type_m = ((const struct rte_flow_item_vlan *)
148 (item->mask))->inner_type;
150 ether_type_m = rte_flow_item_vlan_mask.inner_type;
151 if (ether_type_m != RTE_BE16(0xFFFF))
153 ether_type = ((const struct rte_flow_item_vlan *)
154 (item->spec))->inner_type;
155 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
156 ret = RTE_FLOW_ITEM_TYPE_IPV4;
157 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
158 ret = RTE_FLOW_ITEM_TYPE_IPV6;
159 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
160 ret = RTE_FLOW_ITEM_TYPE_VLAN;
162 ret = RTE_FLOW_ITEM_TYPE_END;
164 case RTE_FLOW_ITEM_TYPE_IPV4:
166 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
167 (item->mask))->hdr.next_proto_id;
170 rte_flow_item_ipv4_mask.hdr.next_proto_id;
171 if (ip_next_proto_m != 0xFF)
173 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
174 (item->spec))->hdr.next_proto_id;
175 if (ip_next_proto == IPPROTO_UDP)
176 ret = RTE_FLOW_ITEM_TYPE_UDP;
177 else if (ip_next_proto == IPPROTO_TCP)
178 ret = RTE_FLOW_ITEM_TYPE_TCP;
179 else if (ip_next_proto == IPPROTO_IP)
180 ret = RTE_FLOW_ITEM_TYPE_IPV4;
181 else if (ip_next_proto == IPPROTO_IPV6)
182 ret = RTE_FLOW_ITEM_TYPE_IPV6;
184 ret = RTE_FLOW_ITEM_TYPE_END;
186 case RTE_FLOW_ITEM_TYPE_IPV6:
188 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
189 (item->mask))->hdr.proto;
192 rte_flow_item_ipv6_mask.hdr.proto;
193 if (ip_next_proto_m != 0xFF)
195 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
196 (item->spec))->hdr.proto;
197 if (ip_next_proto == IPPROTO_UDP)
198 ret = RTE_FLOW_ITEM_TYPE_UDP;
199 else if (ip_next_proto == IPPROTO_TCP)
200 ret = RTE_FLOW_ITEM_TYPE_TCP;
201 else if (ip_next_proto == IPPROTO_IP)
202 ret = RTE_FLOW_ITEM_TYPE_IPV4;
203 else if (ip_next_proto == IPPROTO_IPV6)
204 ret = RTE_FLOW_ITEM_TYPE_IPV6;
206 ret = RTE_FLOW_ITEM_TYPE_END;
209 ret = RTE_FLOW_ITEM_TYPE_VOID;
215 #define MLX5_RSS_EXP_ELT_N 8
218 * Expand RSS flows into several possible flows according to the RSS hash
219 * fields requested and the driver capabilities.
222 * Buffer to store the result expansion.
224 * Buffer size in bytes. If 0, @p buf can be NULL.
228 * RSS types to expand (see ETH_RSS_* definitions).
230 * Input graph to expand @p pattern according to @p types.
231 * @param[in] graph_root_index
232 * Index of root node in @p graph, typically 0.
235 * A positive value representing the size of @p buf in bytes regardless of
236 * @p size on success, a negative errno value otherwise and rte_errno is
237 * set, the following errors are defined:
239 * -E2BIG: graph-depth @p graph is too deep.
242 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
243 const struct rte_flow_item *pattern, uint64_t types,
244 const struct mlx5_flow_expand_node graph[],
245 int graph_root_index)
247 const struct rte_flow_item *item;
248 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
249 const int *next_node;
250 const int *stack[MLX5_RSS_EXP_ELT_N];
252 struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
255 size_t user_pattern_size = 0;
257 const struct mlx5_flow_expand_node *next = NULL;
258 struct rte_flow_item missed_item;
261 const struct rte_flow_item *last_item = NULL;
263 memset(&missed_item, 0, sizeof(missed_item));
264 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
265 MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
267 buf->entry[0].priority = 0;
268 buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
270 addr = buf->entry[0].pattern;
272 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
273 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
275 for (i = 0; node->next && node->next[i]; ++i) {
276 next = &graph[node->next[i]];
277 if (next->type == item->type)
282 user_pattern_size += sizeof(*item);
284 user_pattern_size += sizeof(*item); /* Handle END item. */
285 lsize += user_pattern_size;
286 /* Copy the user pattern in the first entry of the buffer. */
288 rte_memcpy(addr, pattern, user_pattern_size);
289 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
292 /* Start expanding. */
293 memset(flow_items, 0, sizeof(flow_items));
294 user_pattern_size -= sizeof(*item);
296 * Check if the last valid item has spec set, need complete pattern,
297 * and the pattern can be used for expansion.
299 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
300 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
301 /* Item type END indicates expansion is not required. */
304 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
307 for (i = 0; node->next && node->next[i]; ++i) {
308 next = &graph[node->next[i]];
309 if (next->type == missed_item.type) {
310 flow_items[0].type = missed_item.type;
311 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
317 if (next && missed) {
318 elt = 2; /* missed item + item end. */
320 lsize += elt * sizeof(*item) + user_pattern_size;
321 if ((node->rss_types & types) && lsize <= size) {
322 buf->entry[buf->entries].priority = 1;
323 buf->entry[buf->entries].pattern = addr;
325 rte_memcpy(addr, buf->entry[0].pattern,
327 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
328 rte_memcpy(addr, flow_items, elt * sizeof(*item));
329 addr = (void *)(((uintptr_t)addr) +
330 elt * sizeof(*item));
333 memset(flow_items, 0, sizeof(flow_items));
334 next_node = node->next;
335 stack[stack_pos] = next_node;
336 node = next_node ? &graph[*next_node] : NULL;
338 flow_items[stack_pos].type = node->type;
339 if (node->rss_types & types) {
341 * compute the number of items to copy from the
342 * expansion and copy it.
343 * When the stack_pos is 0, there are 1 element in it,
344 * plus the addition END item.
347 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
348 lsize += elt * sizeof(*item) + user_pattern_size;
350 size_t n = elt * sizeof(*item);
352 buf->entry[buf->entries].priority =
353 stack_pos + 1 + missed;
354 buf->entry[buf->entries].pattern = addr;
356 rte_memcpy(addr, buf->entry[0].pattern,
358 addr = (void *)(((uintptr_t)addr) +
360 rte_memcpy(addr, &missed_item,
361 missed * sizeof(*item));
362 addr = (void *)(((uintptr_t)addr) +
363 missed * sizeof(*item));
364 rte_memcpy(addr, flow_items, n);
365 addr = (void *)(((uintptr_t)addr) + n);
370 next_node = node->next;
371 if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
375 stack[stack_pos] = next_node;
376 } else if (*(next_node + 1)) {
377 /* Follow up with the next possibility. */
380 /* Move to the next path. */
382 next_node = stack[--stack_pos];
384 stack[stack_pos] = next_node;
386 node = *next_node ? &graph[*next_node] : NULL;
388 /* no expanded flows but we have missed item, create one rule for it */
389 if (buf->entries == 1 && missed != 0) {
391 lsize += elt * sizeof(*item) + user_pattern_size;
393 buf->entry[buf->entries].priority = 1;
394 buf->entry[buf->entries].pattern = addr;
396 flow_items[0].type = missed_item.type;
397 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
398 rte_memcpy(addr, buf->entry[0].pattern,
400 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
401 rte_memcpy(addr, flow_items, elt * sizeof(*item));
407 enum mlx5_expansion {
409 MLX5_EXPANSION_ROOT_OUTER,
410 MLX5_EXPANSION_ROOT_ETH_VLAN,
411 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
412 MLX5_EXPANSION_OUTER_ETH,
413 MLX5_EXPANSION_OUTER_ETH_VLAN,
414 MLX5_EXPANSION_OUTER_VLAN,
415 MLX5_EXPANSION_OUTER_IPV4,
416 MLX5_EXPANSION_OUTER_IPV4_UDP,
417 MLX5_EXPANSION_OUTER_IPV4_TCP,
418 MLX5_EXPANSION_OUTER_IPV6,
419 MLX5_EXPANSION_OUTER_IPV6_UDP,
420 MLX5_EXPANSION_OUTER_IPV6_TCP,
421 MLX5_EXPANSION_VXLAN,
422 MLX5_EXPANSION_VXLAN_GPE,
426 MLX5_EXPANSION_ETH_VLAN,
429 MLX5_EXPANSION_IPV4_UDP,
430 MLX5_EXPANSION_IPV4_TCP,
432 MLX5_EXPANSION_IPV6_UDP,
433 MLX5_EXPANSION_IPV6_TCP,
436 /** Supported expansion of items. */
437 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
438 [MLX5_EXPANSION_ROOT] = {
439 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
441 MLX5_EXPANSION_IPV6),
442 .type = RTE_FLOW_ITEM_TYPE_END,
444 [MLX5_EXPANSION_ROOT_OUTER] = {
445 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
446 MLX5_EXPANSION_OUTER_IPV4,
447 MLX5_EXPANSION_OUTER_IPV6),
448 .type = RTE_FLOW_ITEM_TYPE_END,
450 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
451 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
452 .type = RTE_FLOW_ITEM_TYPE_END,
454 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
455 .next = MLX5_FLOW_EXPAND_RSS_NEXT
456 (MLX5_EXPANSION_OUTER_ETH_VLAN),
457 .type = RTE_FLOW_ITEM_TYPE_END,
459 [MLX5_EXPANSION_OUTER_ETH] = {
460 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
461 MLX5_EXPANSION_OUTER_IPV6,
462 MLX5_EXPANSION_MPLS),
463 .type = RTE_FLOW_ITEM_TYPE_ETH,
466 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
467 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
468 .type = RTE_FLOW_ITEM_TYPE_ETH,
471 [MLX5_EXPANSION_OUTER_VLAN] = {
472 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
473 MLX5_EXPANSION_OUTER_IPV6),
474 .type = RTE_FLOW_ITEM_TYPE_VLAN,
476 [MLX5_EXPANSION_OUTER_IPV4] = {
477 .next = MLX5_FLOW_EXPAND_RSS_NEXT
478 (MLX5_EXPANSION_OUTER_IPV4_UDP,
479 MLX5_EXPANSION_OUTER_IPV4_TCP,
482 MLX5_EXPANSION_IPV6),
483 .type = RTE_FLOW_ITEM_TYPE_IPV4,
484 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
485 ETH_RSS_NONFRAG_IPV4_OTHER,
487 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
488 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
489 MLX5_EXPANSION_VXLAN_GPE),
490 .type = RTE_FLOW_ITEM_TYPE_UDP,
491 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
493 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
494 .type = RTE_FLOW_ITEM_TYPE_TCP,
495 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
497 [MLX5_EXPANSION_OUTER_IPV6] = {
498 .next = MLX5_FLOW_EXPAND_RSS_NEXT
499 (MLX5_EXPANSION_OUTER_IPV6_UDP,
500 MLX5_EXPANSION_OUTER_IPV6_TCP,
502 MLX5_EXPANSION_IPV6),
503 .type = RTE_FLOW_ITEM_TYPE_IPV6,
504 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
505 ETH_RSS_NONFRAG_IPV6_OTHER,
507 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
508 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
509 MLX5_EXPANSION_VXLAN_GPE),
510 .type = RTE_FLOW_ITEM_TYPE_UDP,
511 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
513 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
514 .type = RTE_FLOW_ITEM_TYPE_TCP,
515 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
517 [MLX5_EXPANSION_VXLAN] = {
518 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
520 MLX5_EXPANSION_IPV6),
521 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
523 [MLX5_EXPANSION_VXLAN_GPE] = {
524 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
526 MLX5_EXPANSION_IPV6),
527 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
529 [MLX5_EXPANSION_GRE] = {
530 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
531 .type = RTE_FLOW_ITEM_TYPE_GRE,
533 [MLX5_EXPANSION_MPLS] = {
534 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
535 MLX5_EXPANSION_IPV6),
536 .type = RTE_FLOW_ITEM_TYPE_MPLS,
538 [MLX5_EXPANSION_ETH] = {
539 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
540 MLX5_EXPANSION_IPV6),
541 .type = RTE_FLOW_ITEM_TYPE_ETH,
543 [MLX5_EXPANSION_ETH_VLAN] = {
544 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
545 .type = RTE_FLOW_ITEM_TYPE_ETH,
547 [MLX5_EXPANSION_VLAN] = {
548 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
549 MLX5_EXPANSION_IPV6),
550 .type = RTE_FLOW_ITEM_TYPE_VLAN,
552 [MLX5_EXPANSION_IPV4] = {
553 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
554 MLX5_EXPANSION_IPV4_TCP),
555 .type = RTE_FLOW_ITEM_TYPE_IPV4,
556 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
557 ETH_RSS_NONFRAG_IPV4_OTHER,
559 [MLX5_EXPANSION_IPV4_UDP] = {
560 .type = RTE_FLOW_ITEM_TYPE_UDP,
561 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
563 [MLX5_EXPANSION_IPV4_TCP] = {
564 .type = RTE_FLOW_ITEM_TYPE_TCP,
565 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
567 [MLX5_EXPANSION_IPV6] = {
568 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
569 MLX5_EXPANSION_IPV6_TCP),
570 .type = RTE_FLOW_ITEM_TYPE_IPV6,
571 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
572 ETH_RSS_NONFRAG_IPV6_OTHER,
574 [MLX5_EXPANSION_IPV6_UDP] = {
575 .type = RTE_FLOW_ITEM_TYPE_UDP,
576 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
578 [MLX5_EXPANSION_IPV6_TCP] = {
579 .type = RTE_FLOW_ITEM_TYPE_TCP,
580 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
584 static struct rte_flow_shared_action *
585 mlx5_shared_action_create(struct rte_eth_dev *dev,
586 const struct rte_flow_shared_action_conf *conf,
587 const struct rte_flow_action *action,
588 struct rte_flow_error *error);
589 static int mlx5_shared_action_destroy
590 (struct rte_eth_dev *dev,
591 struct rte_flow_shared_action *shared_action,
592 struct rte_flow_error *error);
593 static int mlx5_shared_action_update
594 (struct rte_eth_dev *dev,
595 struct rte_flow_shared_action *shared_action,
596 const struct rte_flow_action *action,
597 struct rte_flow_error *error);
598 static int mlx5_shared_action_query
599 (struct rte_eth_dev *dev,
600 const struct rte_flow_shared_action *action,
602 struct rte_flow_error *error);
604 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
605 struct rte_flow_tunnel *app_tunnel,
606 struct rte_flow_action **actions,
607 uint32_t *num_of_actions,
608 struct rte_flow_error *error);
610 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
611 struct rte_flow_tunnel *app_tunnel,
612 struct rte_flow_item **items,
613 uint32_t *num_of_items,
614 struct rte_flow_error *error);
616 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
617 struct rte_flow_item *pmd_items,
618 uint32_t num_items, struct rte_flow_error *err);
620 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
621 struct rte_flow_action *pmd_actions,
622 uint32_t num_actions,
623 struct rte_flow_error *err);
625 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
627 struct rte_flow_restore_info *info,
628 struct rte_flow_error *err);
630 static const struct rte_flow_ops mlx5_flow_ops = {
631 .validate = mlx5_flow_validate,
632 .create = mlx5_flow_create,
633 .destroy = mlx5_flow_destroy,
634 .flush = mlx5_flow_flush,
635 .isolate = mlx5_flow_isolate,
636 .query = mlx5_flow_query,
637 .dev_dump = mlx5_flow_dev_dump,
638 .get_aged_flows = mlx5_flow_get_aged_flows,
639 .shared_action_create = mlx5_shared_action_create,
640 .shared_action_destroy = mlx5_shared_action_destroy,
641 .shared_action_update = mlx5_shared_action_update,
642 .shared_action_query = mlx5_shared_action_query,
643 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
644 .tunnel_match = mlx5_flow_tunnel_match,
645 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
646 .tunnel_item_release = mlx5_flow_tunnel_item_release,
647 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
650 /* Tunnel information. */
651 struct mlx5_flow_tunnel_info {
652 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
653 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
656 static struct mlx5_flow_tunnel_info tunnels_info[] = {
658 .tunnel = MLX5_FLOW_LAYER_VXLAN,
659 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
662 .tunnel = MLX5_FLOW_LAYER_GENEVE,
663 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
666 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
667 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
670 .tunnel = MLX5_FLOW_LAYER_GRE,
671 .ptype = RTE_PTYPE_TUNNEL_GRE,
674 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
675 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
678 .tunnel = MLX5_FLOW_LAYER_MPLS,
679 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
682 .tunnel = MLX5_FLOW_LAYER_NVGRE,
683 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
686 .tunnel = MLX5_FLOW_LAYER_IPIP,
687 .ptype = RTE_PTYPE_TUNNEL_IP,
690 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
691 .ptype = RTE_PTYPE_TUNNEL_IP,
694 .tunnel = MLX5_FLOW_LAYER_GTP,
695 .ptype = RTE_PTYPE_TUNNEL_GTPU,
702 * Translate tag ID to register.
705 * Pointer to the Ethernet device structure.
707 * The feature that request the register.
709 * The request register ID.
711 * Error description in case of any.
714 * The request register on success, a negative errno
715 * value otherwise and rte_errno is set.
718 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
719 enum mlx5_feature_name feature,
721 struct rte_flow_error *error)
723 struct mlx5_priv *priv = dev->data->dev_private;
724 struct mlx5_dev_config *config = &priv->config;
725 enum modify_reg start_reg;
726 bool skip_mtr_reg = false;
729 case MLX5_HAIRPIN_RX:
731 case MLX5_HAIRPIN_TX:
733 case MLX5_METADATA_RX:
734 switch (config->dv_xmeta_en) {
735 case MLX5_XMETA_MODE_LEGACY:
737 case MLX5_XMETA_MODE_META16:
739 case MLX5_XMETA_MODE_META32:
743 case MLX5_METADATA_TX:
745 case MLX5_METADATA_FDB:
746 switch (config->dv_xmeta_en) {
747 case MLX5_XMETA_MODE_LEGACY:
749 case MLX5_XMETA_MODE_META16:
751 case MLX5_XMETA_MODE_META32:
756 switch (config->dv_xmeta_en) {
757 case MLX5_XMETA_MODE_LEGACY:
759 case MLX5_XMETA_MODE_META16:
761 case MLX5_XMETA_MODE_META32:
767 * If meter color and flow match share one register, flow match
768 * should use the meter color register for match.
770 if (priv->mtr_reg_share)
771 return priv->mtr_color_reg;
773 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
776 case MLX5_ASO_FLOW_HIT: /* Both features use the same REG_C. */
777 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
778 return priv->mtr_color_reg;
781 * Metadata COPY_MARK register using is in meter suffix sub
782 * flow while with meter. It's safe to share the same register.
784 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
787 * If meter is enable, it will engage the register for color
788 * match and flow match. If meter color match is not using the
789 * REG_C_2, need to skip the REG_C_x be used by meter color
791 * If meter is disable, free to use all available registers.
793 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
794 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
795 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
796 if (id > (uint32_t)(REG_C_7 - start_reg))
797 return rte_flow_error_set(error, EINVAL,
798 RTE_FLOW_ERROR_TYPE_ITEM,
799 NULL, "invalid tag id");
800 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
801 return rte_flow_error_set(error, ENOTSUP,
802 RTE_FLOW_ERROR_TYPE_ITEM,
803 NULL, "unsupported tag id");
805 * This case means meter is using the REG_C_x great than 2.
806 * Take care not to conflict with meter color REG_C_x.
807 * If the available index REG_C_y >= REG_C_x, skip the
810 if (skip_mtr_reg && config->flow_mreg_c
811 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
812 if (id >= (uint32_t)(REG_C_7 - start_reg))
813 return rte_flow_error_set(error, EINVAL,
814 RTE_FLOW_ERROR_TYPE_ITEM,
815 NULL, "invalid tag id");
816 if (config->flow_mreg_c
817 [id + 1 + start_reg - REG_C_0] != REG_NON)
818 return config->flow_mreg_c
819 [id + 1 + start_reg - REG_C_0];
820 return rte_flow_error_set(error, ENOTSUP,
821 RTE_FLOW_ERROR_TYPE_ITEM,
822 NULL, "unsupported tag id");
824 return config->flow_mreg_c[id + start_reg - REG_C_0];
827 return rte_flow_error_set(error, EINVAL,
828 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
829 NULL, "invalid feature name");
833 * Check extensive flow metadata register support.
836 * Pointer to rte_eth_dev structure.
839 * True if device supports extensive flow metadata register, otherwise false.
842 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
844 struct mlx5_priv *priv = dev->data->dev_private;
845 struct mlx5_dev_config *config = &priv->config;
848 * Having available reg_c can be regarded inclusively as supporting
849 * extensive flow metadata register, which could mean,
850 * - metadata register copy action by modify header.
851 * - 16 modify header actions is supported.
852 * - reg_c's are preserved across different domain (FDB and NIC) on
853 * packet loopback by flow lookup miss.
855 return config->flow_mreg_c[2] != REG_NON;
859 * Get the lowest priority.
862 * Pointer to the Ethernet device structure.
863 * @param[in] attributes
864 * Pointer to device flow rule attributes.
867 * The value of lowest priority of flow.
870 mlx5_get_lowest_priority(struct rte_eth_dev *dev,
871 const struct rte_flow_attr *attr)
873 struct mlx5_priv *priv = dev->data->dev_private;
875 if (!attr->group && !attr->transfer)
876 return priv->config.flow_prio - 2;
877 return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
881 * Calculate matcher priority of the flow.
884 * Pointer to the Ethernet device structure.
886 * Pointer to device flow rule attributes.
887 * @param[in] subpriority
888 * The priority based on the items.
890 * The matcher priority of the flow.
893 mlx5_get_matcher_priority(struct rte_eth_dev *dev,
894 const struct rte_flow_attr *attr,
895 uint32_t subpriority)
897 uint16_t priority = (uint16_t)attr->priority;
898 struct mlx5_priv *priv = dev->data->dev_private;
900 if (!attr->group && !attr->transfer) {
901 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
902 priority = priv->config.flow_prio - 1;
903 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
905 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
906 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
907 return priority * 3 + subpriority;
911 * Verify the @p item specifications (spec, last, mask) are compatible with the
915 * Item specification.
917 * @p item->mask or flow default bit-masks.
918 * @param[in] nic_mask
919 * Bit-masks covering supported fields by the NIC to compare with user mask.
921 * Bit-masks size in bytes.
922 * @param[in] range_accepted
923 * True if range of values is accepted for specific fields, false otherwise.
925 * Pointer to error structure.
928 * 0 on success, a negative errno value otherwise and rte_errno is set.
931 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
933 const uint8_t *nic_mask,
936 struct rte_flow_error *error)
940 MLX5_ASSERT(nic_mask);
941 for (i = 0; i < size; ++i)
942 if ((nic_mask[i] | mask[i]) != nic_mask[i])
943 return rte_flow_error_set(error, ENOTSUP,
944 RTE_FLOW_ERROR_TYPE_ITEM,
946 "mask enables non supported"
948 if (!item->spec && (item->mask || item->last))
949 return rte_flow_error_set(error, EINVAL,
950 RTE_FLOW_ERROR_TYPE_ITEM, item,
951 "mask/last without a spec is not"
953 if (item->spec && item->last && !range_accepted) {
959 for (i = 0; i < size; ++i) {
960 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
961 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
963 ret = memcmp(spec, last, size);
965 return rte_flow_error_set(error, EINVAL,
966 RTE_FLOW_ERROR_TYPE_ITEM,
968 "range is not valid");
974 * Adjust the hash fields according to the @p flow information.
976 * @param[in] dev_flow.
977 * Pointer to the mlx5_flow.
979 * 1 when the hash field is for a tunnel item.
980 * @param[in] layer_types
982 * @param[in] hash_fields
986 * The hash fields that should be used.
989 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
990 int tunnel __rte_unused, uint64_t layer_types,
991 uint64_t hash_fields)
993 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
994 int rss_request_inner = rss_desc->level >= 2;
996 /* Check RSS hash level for tunnel. */
997 if (tunnel && rss_request_inner)
998 hash_fields |= IBV_RX_HASH_INNER;
999 else if (tunnel || rss_request_inner)
1002 /* Check if requested layer matches RSS hash fields. */
1003 if (!(rss_desc->types & layer_types))
1009 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1010 * if several tunnel rules are used on this queue, the tunnel ptype will be
1014 * Rx queue to update.
1017 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1020 uint32_t tunnel_ptype = 0;
1022 /* Look up for the ptype to use. */
1023 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1024 if (!rxq_ctrl->flow_tunnels_n[i])
1026 if (!tunnel_ptype) {
1027 tunnel_ptype = tunnels_info[i].ptype;
1033 rxq_ctrl->rxq.tunnel = tunnel_ptype;
1037 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
1041 * Pointer to the Ethernet device structure.
1042 * @param[in] dev_handle
1043 * Pointer to device flow handle structure.
1046 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1047 struct mlx5_flow_handle *dev_handle)
1049 struct mlx5_priv *priv = dev->data->dev_private;
1050 const int mark = dev_handle->mark;
1051 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1052 struct mlx5_ind_table_obj *ind_tbl = NULL;
1055 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1056 struct mlx5_hrxq *hrxq;
1058 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1059 dev_handle->rix_hrxq);
1061 ind_tbl = hrxq->ind_table;
1062 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1063 struct mlx5_shared_action_rss *shared_rss;
1065 shared_rss = mlx5_ipool_get
1066 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1067 dev_handle->rix_srss);
1069 ind_tbl = shared_rss->ind_tbl;
1073 for (i = 0; i != ind_tbl->queues_n; ++i) {
1074 int idx = ind_tbl->queues[i];
1075 struct mlx5_rxq_ctrl *rxq_ctrl =
1076 container_of((*priv->rxqs)[idx],
1077 struct mlx5_rxq_ctrl, rxq);
1080 * To support metadata register copy on Tx loopback,
1081 * this must be always enabled (metadata may arive
1082 * from other port - not from local flows only.
1084 if (priv->config.dv_flow_en &&
1085 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1086 mlx5_flow_ext_mreg_supported(dev)) {
1087 rxq_ctrl->rxq.mark = 1;
1088 rxq_ctrl->flow_mark_n = 1;
1090 rxq_ctrl->rxq.mark = 1;
1091 rxq_ctrl->flow_mark_n++;
1096 /* Increase the counter matching the flow. */
1097 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1098 if ((tunnels_info[j].tunnel &
1099 dev_handle->layers) ==
1100 tunnels_info[j].tunnel) {
1101 rxq_ctrl->flow_tunnels_n[j]++;
1105 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1111 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1114 * Pointer to the Ethernet device structure.
1116 * Pointer to flow structure.
1119 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1121 struct mlx5_priv *priv = dev->data->dev_private;
1122 uint32_t handle_idx;
1123 struct mlx5_flow_handle *dev_handle;
1125 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1126 handle_idx, dev_handle, next)
1127 flow_drv_rxq_flags_set(dev, dev_handle);
1131 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1132 * device flow if no other flow uses it with the same kind of request.
1135 * Pointer to Ethernet device.
1136 * @param[in] dev_handle
1137 * Pointer to the device flow handle structure.
1140 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1141 struct mlx5_flow_handle *dev_handle)
1143 struct mlx5_priv *priv = dev->data->dev_private;
1144 const int mark = dev_handle->mark;
1145 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1146 struct mlx5_ind_table_obj *ind_tbl = NULL;
1149 if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1150 struct mlx5_hrxq *hrxq;
1152 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1153 dev_handle->rix_hrxq);
1155 ind_tbl = hrxq->ind_table;
1156 } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1157 struct mlx5_shared_action_rss *shared_rss;
1159 shared_rss = mlx5_ipool_get
1160 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1161 dev_handle->rix_srss);
1163 ind_tbl = shared_rss->ind_tbl;
1167 MLX5_ASSERT(dev->data->dev_started);
1168 for (i = 0; i != ind_tbl->queues_n; ++i) {
1169 int idx = ind_tbl->queues[i];
1170 struct mlx5_rxq_ctrl *rxq_ctrl =
1171 container_of((*priv->rxqs)[idx],
1172 struct mlx5_rxq_ctrl, rxq);
1174 if (priv->config.dv_flow_en &&
1175 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1176 mlx5_flow_ext_mreg_supported(dev)) {
1177 rxq_ctrl->rxq.mark = 1;
1178 rxq_ctrl->flow_mark_n = 1;
1180 rxq_ctrl->flow_mark_n--;
1181 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1186 /* Decrease the counter matching the flow. */
1187 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1188 if ((tunnels_info[j].tunnel &
1189 dev_handle->layers) ==
1190 tunnels_info[j].tunnel) {
1191 rxq_ctrl->flow_tunnels_n[j]--;
1195 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1201 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1202 * @p flow if no other flow uses it with the same kind of request.
1205 * Pointer to Ethernet device.
1207 * Pointer to the flow.
1210 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1212 struct mlx5_priv *priv = dev->data->dev_private;
1213 uint32_t handle_idx;
1214 struct mlx5_flow_handle *dev_handle;
1216 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1217 handle_idx, dev_handle, next)
1218 flow_drv_rxq_flags_trim(dev, dev_handle);
1222 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1225 * Pointer to Ethernet device.
1228 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1230 struct mlx5_priv *priv = dev->data->dev_private;
1233 for (i = 0; i != priv->rxqs_n; ++i) {
1234 struct mlx5_rxq_ctrl *rxq_ctrl;
1237 if (!(*priv->rxqs)[i])
1239 rxq_ctrl = container_of((*priv->rxqs)[i],
1240 struct mlx5_rxq_ctrl, rxq);
1241 rxq_ctrl->flow_mark_n = 0;
1242 rxq_ctrl->rxq.mark = 0;
1243 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1244 rxq_ctrl->flow_tunnels_n[j] = 0;
1245 rxq_ctrl->rxq.tunnel = 0;
1250 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1253 * Pointer to the Ethernet device structure.
1256 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1258 struct mlx5_priv *priv = dev->data->dev_private;
1259 struct mlx5_rxq_data *data;
1262 for (i = 0; i != priv->rxqs_n; ++i) {
1263 if (!(*priv->rxqs)[i])
1265 data = (*priv->rxqs)[i];
1266 if (!rte_flow_dynf_metadata_avail()) {
1267 data->dynf_meta = 0;
1268 data->flow_meta_mask = 0;
1269 data->flow_meta_offset = -1;
1270 data->flow_meta_port_mask = 0;
1272 data->dynf_meta = 1;
1273 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1274 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1275 data->flow_meta_port_mask = (uint32_t)~0;
1276 if (priv->config.dv_xmeta_en == MLX5_XMETA_MODE_META16)
1277 data->flow_meta_port_mask >>= 16;
1283 * return a pointer to the desired action in the list of actions.
1285 * @param[in] actions
1286 * The list of actions to search the action in.
1288 * The action to find.
1291 * Pointer to the action in the list, if found. NULL otherwise.
1293 const struct rte_flow_action *
1294 mlx5_flow_find_action(const struct rte_flow_action *actions,
1295 enum rte_flow_action_type action)
1297 if (actions == NULL)
1299 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1300 if (actions->type == action)
1306 * Validate the flag action.
1308 * @param[in] action_flags
1309 * Bit-fields that holds the actions detected until now.
1311 * Attributes of flow that includes this action.
1313 * Pointer to error structure.
1316 * 0 on success, a negative errno value otherwise and rte_errno is set.
1319 mlx5_flow_validate_action_flag(uint64_t action_flags,
1320 const struct rte_flow_attr *attr,
1321 struct rte_flow_error *error)
1323 if (action_flags & MLX5_FLOW_ACTION_MARK)
1324 return rte_flow_error_set(error, EINVAL,
1325 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1326 "can't mark and flag in same flow");
1327 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1328 return rte_flow_error_set(error, EINVAL,
1329 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1331 " actions in same flow");
1333 return rte_flow_error_set(error, ENOTSUP,
1334 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1335 "flag action not supported for "
1341 * Validate the mark action.
1344 * Pointer to the queue action.
1345 * @param[in] action_flags
1346 * Bit-fields that holds the actions detected until now.
1348 * Attributes of flow that includes this action.
1350 * Pointer to error structure.
1353 * 0 on success, a negative errno value otherwise and rte_errno is set.
1356 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1357 uint64_t action_flags,
1358 const struct rte_flow_attr *attr,
1359 struct rte_flow_error *error)
1361 const struct rte_flow_action_mark *mark = action->conf;
1364 return rte_flow_error_set(error, EINVAL,
1365 RTE_FLOW_ERROR_TYPE_ACTION,
1367 "configuration cannot be null");
1368 if (mark->id >= MLX5_FLOW_MARK_MAX)
1369 return rte_flow_error_set(error, EINVAL,
1370 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1372 "mark id must in 0 <= id < "
1373 RTE_STR(MLX5_FLOW_MARK_MAX));
1374 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1375 return rte_flow_error_set(error, EINVAL,
1376 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1377 "can't flag and mark in same flow");
1378 if (action_flags & MLX5_FLOW_ACTION_MARK)
1379 return rte_flow_error_set(error, EINVAL,
1380 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1381 "can't have 2 mark actions in same"
1384 return rte_flow_error_set(error, ENOTSUP,
1385 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1386 "mark action not supported for "
1392 * Validate the drop action.
1394 * @param[in] action_flags
1395 * Bit-fields that holds the actions detected until now.
1397 * Attributes of flow that includes this action.
1399 * Pointer to error structure.
1402 * 0 on success, a negative errno value otherwise and rte_errno is set.
1405 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1406 const struct rte_flow_attr *attr,
1407 struct rte_flow_error *error)
1410 return rte_flow_error_set(error, ENOTSUP,
1411 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1412 "drop action not supported for "
1418 * Validate the queue action.
1421 * Pointer to the queue action.
1422 * @param[in] action_flags
1423 * Bit-fields that holds the actions detected until now.
1425 * Pointer to the Ethernet device structure.
1427 * Attributes of flow that includes this action.
1429 * Pointer to error structure.
1432 * 0 on success, a negative errno value otherwise and rte_errno is set.
1435 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1436 uint64_t action_flags,
1437 struct rte_eth_dev *dev,
1438 const struct rte_flow_attr *attr,
1439 struct rte_flow_error *error)
1441 struct mlx5_priv *priv = dev->data->dev_private;
1442 const struct rte_flow_action_queue *queue = action->conf;
1444 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1445 return rte_flow_error_set(error, EINVAL,
1446 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1447 "can't have 2 fate actions in"
1450 return rte_flow_error_set(error, EINVAL,
1451 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1452 NULL, "No Rx queues configured");
1453 if (queue->index >= priv->rxqs_n)
1454 return rte_flow_error_set(error, EINVAL,
1455 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1457 "queue index out of range");
1458 if (!(*priv->rxqs)[queue->index])
1459 return rte_flow_error_set(error, EINVAL,
1460 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1462 "queue is not configured");
1464 return rte_flow_error_set(error, ENOTSUP,
1465 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1466 "queue action not supported for "
1472 * Validate the rss action.
1475 * Pointer to the Ethernet device structure.
1477 * Pointer to the queue action.
1479 * Pointer to error structure.
1482 * 0 on success, a negative errno value otherwise and rte_errno is set.
1485 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1486 const struct rte_flow_action *action,
1487 struct rte_flow_error *error)
1489 struct mlx5_priv *priv = dev->data->dev_private;
1490 const struct rte_flow_action_rss *rss = action->conf;
1491 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1494 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1495 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1496 return rte_flow_error_set(error, ENOTSUP,
1497 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1499 "RSS hash function not supported");
1500 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1505 return rte_flow_error_set(error, ENOTSUP,
1506 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1508 "tunnel RSS is not supported");
1509 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1510 if (rss->key_len == 0 && rss->key != NULL)
1511 return rte_flow_error_set(error, ENOTSUP,
1512 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1514 "RSS hash key length 0");
1515 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1516 return rte_flow_error_set(error, ENOTSUP,
1517 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1519 "RSS hash key too small");
1520 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1521 return rte_flow_error_set(error, ENOTSUP,
1522 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1524 "RSS hash key too large");
1525 if (rss->queue_num > priv->config.ind_table_max_size)
1526 return rte_flow_error_set(error, ENOTSUP,
1527 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1529 "number of queues too large");
1530 if (rss->types & MLX5_RSS_HF_MASK)
1531 return rte_flow_error_set(error, ENOTSUP,
1532 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1534 "some RSS protocols are not"
1536 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1537 !(rss->types & ETH_RSS_IP))
1538 return rte_flow_error_set(error, EINVAL,
1539 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1540 "L3 partial RSS requested but L3 RSS"
1541 " type not specified");
1542 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1543 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1544 return rte_flow_error_set(error, EINVAL,
1545 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1546 "L4 partial RSS requested but L4 RSS"
1547 " type not specified");
1549 return rte_flow_error_set(error, EINVAL,
1550 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1551 NULL, "No Rx queues configured");
1552 if (!rss->queue_num)
1553 return rte_flow_error_set(error, EINVAL,
1554 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1555 NULL, "No queues configured");
1556 for (i = 0; i != rss->queue_num; ++i) {
1557 struct mlx5_rxq_ctrl *rxq_ctrl;
1559 if (rss->queue[i] >= priv->rxqs_n)
1560 return rte_flow_error_set
1562 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1563 &rss->queue[i], "queue index out of range");
1564 if (!(*priv->rxqs)[rss->queue[i]])
1565 return rte_flow_error_set
1566 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1567 &rss->queue[i], "queue is not configured");
1568 rxq_ctrl = container_of((*priv->rxqs)[rss->queue[i]],
1569 struct mlx5_rxq_ctrl, rxq);
1571 rxq_type = rxq_ctrl->type;
1572 if (rxq_type != rxq_ctrl->type)
1573 return rte_flow_error_set
1574 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1576 "combining hairpin and regular RSS queues is not supported");
1582 * Validate the rss action.
1585 * Pointer to the queue action.
1586 * @param[in] action_flags
1587 * Bit-fields that holds the actions detected until now.
1589 * Pointer to the Ethernet device structure.
1591 * Attributes of flow that includes this action.
1592 * @param[in] item_flags
1593 * Items that were detected.
1595 * Pointer to error structure.
1598 * 0 on success, a negative errno value otherwise and rte_errno is set.
1601 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1602 uint64_t action_flags,
1603 struct rte_eth_dev *dev,
1604 const struct rte_flow_attr *attr,
1605 uint64_t item_flags,
1606 struct rte_flow_error *error)
1608 const struct rte_flow_action_rss *rss = action->conf;
1609 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1612 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1613 return rte_flow_error_set(error, EINVAL,
1614 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1615 "can't have 2 fate actions"
1617 ret = mlx5_validate_action_rss(dev, action, error);
1621 return rte_flow_error_set(error, ENOTSUP,
1622 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1623 "rss action not supported for "
1625 if (rss->level > 1 && !tunnel)
1626 return rte_flow_error_set(error, EINVAL,
1627 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1628 "inner RSS is not supported for "
1629 "non-tunnel flows");
1630 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1631 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1632 return rte_flow_error_set(error, EINVAL,
1633 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1634 "RSS on eCPRI is not supported now");
1640 * Validate the default miss action.
1642 * @param[in] action_flags
1643 * Bit-fields that holds the actions detected until now.
1645 * Pointer to error structure.
1648 * 0 on success, a negative errno value otherwise and rte_errno is set.
1651 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1652 const struct rte_flow_attr *attr,
1653 struct rte_flow_error *error)
1655 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1656 return rte_flow_error_set(error, EINVAL,
1657 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1658 "can't have 2 fate actions in"
1661 return rte_flow_error_set(error, ENOTSUP,
1662 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1663 "default miss action not supported "
1666 return rte_flow_error_set(error, ENOTSUP,
1667 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1668 "only group 0 is supported");
1670 return rte_flow_error_set(error, ENOTSUP,
1671 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1672 NULL, "transfer is not supported");
1677 * Validate the count action.
1680 * Pointer to the Ethernet device structure.
1682 * Attributes of flow that includes this action.
1684 * Pointer to error structure.
1687 * 0 on success, a negative errno value otherwise and rte_errno is set.
1690 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1691 const struct rte_flow_attr *attr,
1692 struct rte_flow_error *error)
1695 return rte_flow_error_set(error, ENOTSUP,
1696 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1697 "count action not supported for "
1703 * Verify the @p attributes will be correctly understood by the NIC and store
1704 * them in the @p flow if everything is correct.
1707 * Pointer to the Ethernet device structure.
1708 * @param[in] attributes
1709 * Pointer to flow attributes
1711 * Pointer to error structure.
1714 * 0 on success, a negative errno value otherwise and rte_errno is set.
1717 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1718 const struct rte_flow_attr *attributes,
1719 struct rte_flow_error *error)
1721 struct mlx5_priv *priv = dev->data->dev_private;
1722 uint32_t priority_max = priv->config.flow_prio - 1;
1724 if (attributes->group)
1725 return rte_flow_error_set(error, ENOTSUP,
1726 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1727 NULL, "groups is not supported");
1728 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
1729 attributes->priority >= priority_max)
1730 return rte_flow_error_set(error, ENOTSUP,
1731 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1732 NULL, "priority out of range");
1733 if (attributes->egress)
1734 return rte_flow_error_set(error, ENOTSUP,
1735 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1736 "egress is not supported");
1737 if (attributes->transfer && !priv->config.dv_esw_en)
1738 return rte_flow_error_set(error, ENOTSUP,
1739 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1740 NULL, "transfer is not supported");
1741 if (!attributes->ingress)
1742 return rte_flow_error_set(error, EINVAL,
1743 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1745 "ingress attribute is mandatory");
1750 * Validate ICMP6 item.
1753 * Item specification.
1754 * @param[in] item_flags
1755 * Bit-fields that holds the items detected until now.
1756 * @param[in] ext_vlan_sup
1757 * Whether extended VLAN features are supported or not.
1759 * Pointer to error structure.
1762 * 0 on success, a negative errno value otherwise and rte_errno is set.
1765 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1766 uint64_t item_flags,
1767 uint8_t target_protocol,
1768 struct rte_flow_error *error)
1770 const struct rte_flow_item_icmp6 *mask = item->mask;
1771 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1772 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1773 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1774 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1775 MLX5_FLOW_LAYER_OUTER_L4;
1778 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1779 return rte_flow_error_set(error, EINVAL,
1780 RTE_FLOW_ERROR_TYPE_ITEM, item,
1781 "protocol filtering not compatible"
1782 " with ICMP6 layer");
1783 if (!(item_flags & l3m))
1784 return rte_flow_error_set(error, EINVAL,
1785 RTE_FLOW_ERROR_TYPE_ITEM, item,
1786 "IPv6 is mandatory to filter on"
1788 if (item_flags & l4m)
1789 return rte_flow_error_set(error, EINVAL,
1790 RTE_FLOW_ERROR_TYPE_ITEM, item,
1791 "multiple L4 layers not supported");
1793 mask = &rte_flow_item_icmp6_mask;
1794 ret = mlx5_flow_item_acceptable
1795 (item, (const uint8_t *)mask,
1796 (const uint8_t *)&rte_flow_item_icmp6_mask,
1797 sizeof(struct rte_flow_item_icmp6),
1798 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1805 * Validate ICMP item.
1808 * Item specification.
1809 * @param[in] item_flags
1810 * Bit-fields that holds the items detected until now.
1812 * Pointer to error structure.
1815 * 0 on success, a negative errno value otherwise and rte_errno is set.
1818 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1819 uint64_t item_flags,
1820 uint8_t target_protocol,
1821 struct rte_flow_error *error)
1823 const struct rte_flow_item_icmp *mask = item->mask;
1824 const struct rte_flow_item_icmp nic_mask = {
1825 .hdr.icmp_type = 0xff,
1826 .hdr.icmp_code = 0xff,
1827 .hdr.icmp_ident = RTE_BE16(0xffff),
1828 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1830 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1831 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1832 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1833 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1834 MLX5_FLOW_LAYER_OUTER_L4;
1837 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1838 return rte_flow_error_set(error, EINVAL,
1839 RTE_FLOW_ERROR_TYPE_ITEM, item,
1840 "protocol filtering not compatible"
1841 " with ICMP layer");
1842 if (!(item_flags & l3m))
1843 return rte_flow_error_set(error, EINVAL,
1844 RTE_FLOW_ERROR_TYPE_ITEM, item,
1845 "IPv4 is mandatory to filter"
1847 if (item_flags & l4m)
1848 return rte_flow_error_set(error, EINVAL,
1849 RTE_FLOW_ERROR_TYPE_ITEM, item,
1850 "multiple L4 layers not supported");
1853 ret = mlx5_flow_item_acceptable
1854 (item, (const uint8_t *)mask,
1855 (const uint8_t *)&nic_mask,
1856 sizeof(struct rte_flow_item_icmp),
1857 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1864 * Validate Ethernet item.
1867 * Item specification.
1868 * @param[in] item_flags
1869 * Bit-fields that holds the items detected until now.
1871 * Pointer to error structure.
1874 * 0 on success, a negative errno value otherwise and rte_errno is set.
1877 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1878 uint64_t item_flags, bool ext_vlan_sup,
1879 struct rte_flow_error *error)
1881 const struct rte_flow_item_eth *mask = item->mask;
1882 const struct rte_flow_item_eth nic_mask = {
1883 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1884 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1885 .type = RTE_BE16(0xffff),
1886 .has_vlan = ext_vlan_sup ? 1 : 0,
1889 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1890 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1891 MLX5_FLOW_LAYER_OUTER_L2;
1893 if (item_flags & ethm)
1894 return rte_flow_error_set(error, ENOTSUP,
1895 RTE_FLOW_ERROR_TYPE_ITEM, item,
1896 "multiple L2 layers not supported");
1897 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1898 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1899 return rte_flow_error_set(error, EINVAL,
1900 RTE_FLOW_ERROR_TYPE_ITEM, item,
1901 "L2 layer should not follow "
1903 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1904 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1905 return rte_flow_error_set(error, EINVAL,
1906 RTE_FLOW_ERROR_TYPE_ITEM, item,
1907 "L2 layer should not follow VLAN");
1909 mask = &rte_flow_item_eth_mask;
1910 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1911 (const uint8_t *)&nic_mask,
1912 sizeof(struct rte_flow_item_eth),
1913 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1918 * Validate VLAN item.
1921 * Item specification.
1922 * @param[in] item_flags
1923 * Bit-fields that holds the items detected until now.
1925 * Ethernet device flow is being created on.
1927 * Pointer to error structure.
1930 * 0 on success, a negative errno value otherwise and rte_errno is set.
1933 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1934 uint64_t item_flags,
1935 struct rte_eth_dev *dev,
1936 struct rte_flow_error *error)
1938 const struct rte_flow_item_vlan *spec = item->spec;
1939 const struct rte_flow_item_vlan *mask = item->mask;
1940 const struct rte_flow_item_vlan nic_mask = {
1941 .tci = RTE_BE16(UINT16_MAX),
1942 .inner_type = RTE_BE16(UINT16_MAX),
1944 uint16_t vlan_tag = 0;
1945 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1947 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1948 MLX5_FLOW_LAYER_INNER_L4) :
1949 (MLX5_FLOW_LAYER_OUTER_L3 |
1950 MLX5_FLOW_LAYER_OUTER_L4);
1951 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1952 MLX5_FLOW_LAYER_OUTER_VLAN;
1954 if (item_flags & vlanm)
1955 return rte_flow_error_set(error, EINVAL,
1956 RTE_FLOW_ERROR_TYPE_ITEM, item,
1957 "multiple VLAN layers not supported");
1958 else if ((item_flags & l34m) != 0)
1959 return rte_flow_error_set(error, EINVAL,
1960 RTE_FLOW_ERROR_TYPE_ITEM, item,
1961 "VLAN cannot follow L3/L4 layer");
1963 mask = &rte_flow_item_vlan_mask;
1964 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1965 (const uint8_t *)&nic_mask,
1966 sizeof(struct rte_flow_item_vlan),
1967 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1970 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1971 struct mlx5_priv *priv = dev->data->dev_private;
1973 if (priv->vmwa_context) {
1975 * Non-NULL context means we have a virtual machine
1976 * and SR-IOV enabled, we have to create VLAN interface
1977 * to make hypervisor to setup E-Switch vport
1978 * context correctly. We avoid creating the multiple
1979 * VLAN interfaces, so we cannot support VLAN tag mask.
1981 return rte_flow_error_set(error, EINVAL,
1982 RTE_FLOW_ERROR_TYPE_ITEM,
1984 "VLAN tag mask is not"
1985 " supported in virtual"
1990 vlan_tag = spec->tci;
1991 vlan_tag &= mask->tci;
1994 * From verbs perspective an empty VLAN is equivalent
1995 * to a packet without VLAN layer.
1998 return rte_flow_error_set(error, EINVAL,
1999 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2001 "VLAN cannot be empty");
2006 * Validate IPV4 item.
2009 * Item specification.
2010 * @param[in] item_flags
2011 * Bit-fields that holds the items detected until now.
2012 * @param[in] last_item
2013 * Previous validated item in the pattern items.
2014 * @param[in] ether_type
2015 * Type in the ethernet layer header (including dot1q).
2016 * @param[in] acc_mask
2017 * Acceptable mask, if NULL default internal default mask
2018 * will be used to check whether item fields are supported.
2019 * @param[in] range_accepted
2020 * True if range of values is accepted for specific fields, false otherwise.
2022 * Pointer to error structure.
2025 * 0 on success, a negative errno value otherwise and rte_errno is set.
2028 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
2029 uint64_t item_flags,
2031 uint16_t ether_type,
2032 const struct rte_flow_item_ipv4 *acc_mask,
2033 bool range_accepted,
2034 struct rte_flow_error *error)
2036 const struct rte_flow_item_ipv4 *mask = item->mask;
2037 const struct rte_flow_item_ipv4 *spec = item->spec;
2038 const struct rte_flow_item_ipv4 nic_mask = {
2040 .src_addr = RTE_BE32(0xffffffff),
2041 .dst_addr = RTE_BE32(0xffffffff),
2042 .type_of_service = 0xff,
2043 .next_proto_id = 0xff,
2046 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2047 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2048 MLX5_FLOW_LAYER_OUTER_L3;
2049 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2050 MLX5_FLOW_LAYER_OUTER_L4;
2052 uint8_t next_proto = 0xFF;
2053 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2054 MLX5_FLOW_LAYER_OUTER_VLAN |
2055 MLX5_FLOW_LAYER_INNER_VLAN);
2057 if ((last_item & l2_vlan) && ether_type &&
2058 ether_type != RTE_ETHER_TYPE_IPV4)
2059 return rte_flow_error_set(error, EINVAL,
2060 RTE_FLOW_ERROR_TYPE_ITEM, item,
2061 "IPv4 cannot follow L2/VLAN layer "
2062 "which ether type is not IPv4");
2063 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2065 next_proto = mask->hdr.next_proto_id &
2066 spec->hdr.next_proto_id;
2067 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2068 return rte_flow_error_set(error, EINVAL,
2069 RTE_FLOW_ERROR_TYPE_ITEM,
2074 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2075 return rte_flow_error_set(error, EINVAL,
2076 RTE_FLOW_ERROR_TYPE_ITEM, item,
2077 "wrong tunnel type - IPv6 specified "
2078 "but IPv4 item provided");
2079 if (item_flags & l3m)
2080 return rte_flow_error_set(error, ENOTSUP,
2081 RTE_FLOW_ERROR_TYPE_ITEM, item,
2082 "multiple L3 layers not supported");
2083 else if (item_flags & l4m)
2084 return rte_flow_error_set(error, EINVAL,
2085 RTE_FLOW_ERROR_TYPE_ITEM, item,
2086 "L3 cannot follow an L4 layer.");
2087 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2088 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2089 return rte_flow_error_set(error, EINVAL,
2090 RTE_FLOW_ERROR_TYPE_ITEM, item,
2091 "L3 cannot follow an NVGRE layer.");
2093 mask = &rte_flow_item_ipv4_mask;
2094 else if (mask->hdr.next_proto_id != 0 &&
2095 mask->hdr.next_proto_id != 0xff)
2096 return rte_flow_error_set(error, EINVAL,
2097 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2098 "partial mask is not supported"
2100 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2101 acc_mask ? (const uint8_t *)acc_mask
2102 : (const uint8_t *)&nic_mask,
2103 sizeof(struct rte_flow_item_ipv4),
2104 range_accepted, error);
2111 * Validate IPV6 item.
2114 * Item specification.
2115 * @param[in] item_flags
2116 * Bit-fields that holds the items detected until now.
2117 * @param[in] last_item
2118 * Previous validated item in the pattern items.
2119 * @param[in] ether_type
2120 * Type in the ethernet layer header (including dot1q).
2121 * @param[in] acc_mask
2122 * Acceptable mask, if NULL default internal default mask
2123 * will be used to check whether item fields are supported.
2125 * Pointer to error structure.
2128 * 0 on success, a negative errno value otherwise and rte_errno is set.
2131 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2132 uint64_t item_flags,
2134 uint16_t ether_type,
2135 const struct rte_flow_item_ipv6 *acc_mask,
2136 struct rte_flow_error *error)
2138 const struct rte_flow_item_ipv6 *mask = item->mask;
2139 const struct rte_flow_item_ipv6 *spec = item->spec;
2140 const struct rte_flow_item_ipv6 nic_mask = {
2143 "\xff\xff\xff\xff\xff\xff\xff\xff"
2144 "\xff\xff\xff\xff\xff\xff\xff\xff",
2146 "\xff\xff\xff\xff\xff\xff\xff\xff"
2147 "\xff\xff\xff\xff\xff\xff\xff\xff",
2148 .vtc_flow = RTE_BE32(0xffffffff),
2152 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2153 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2154 MLX5_FLOW_LAYER_OUTER_L3;
2155 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2156 MLX5_FLOW_LAYER_OUTER_L4;
2158 uint8_t next_proto = 0xFF;
2159 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2160 MLX5_FLOW_LAYER_OUTER_VLAN |
2161 MLX5_FLOW_LAYER_INNER_VLAN);
2163 if ((last_item & l2_vlan) && ether_type &&
2164 ether_type != RTE_ETHER_TYPE_IPV6)
2165 return rte_flow_error_set(error, EINVAL,
2166 RTE_FLOW_ERROR_TYPE_ITEM, item,
2167 "IPv6 cannot follow L2/VLAN layer "
2168 "which ether type is not IPv6");
2169 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2170 next_proto = spec->hdr.proto;
2171 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
2172 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2173 return rte_flow_error_set(error, EINVAL,
2174 RTE_FLOW_ERROR_TYPE_ITEM,
2179 if (next_proto == IPPROTO_HOPOPTS ||
2180 next_proto == IPPROTO_ROUTING ||
2181 next_proto == IPPROTO_FRAGMENT ||
2182 next_proto == IPPROTO_ESP ||
2183 next_proto == IPPROTO_AH ||
2184 next_proto == IPPROTO_DSTOPTS)
2185 return rte_flow_error_set(error, EINVAL,
2186 RTE_FLOW_ERROR_TYPE_ITEM, item,
2187 "IPv6 proto (next header) should "
2188 "not be set as extension header");
2189 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2190 return rte_flow_error_set(error, EINVAL,
2191 RTE_FLOW_ERROR_TYPE_ITEM, item,
2192 "wrong tunnel type - IPv4 specified "
2193 "but IPv6 item provided");
2194 if (item_flags & l3m)
2195 return rte_flow_error_set(error, ENOTSUP,
2196 RTE_FLOW_ERROR_TYPE_ITEM, item,
2197 "multiple L3 layers not supported");
2198 else if (item_flags & l4m)
2199 return rte_flow_error_set(error, EINVAL,
2200 RTE_FLOW_ERROR_TYPE_ITEM, item,
2201 "L3 cannot follow an L4 layer.");
2202 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2203 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2204 return rte_flow_error_set(error, EINVAL,
2205 RTE_FLOW_ERROR_TYPE_ITEM, item,
2206 "L3 cannot follow an NVGRE layer.");
2208 mask = &rte_flow_item_ipv6_mask;
2209 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2210 acc_mask ? (const uint8_t *)acc_mask
2211 : (const uint8_t *)&nic_mask,
2212 sizeof(struct rte_flow_item_ipv6),
2213 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2220 * Validate UDP item.
2223 * Item specification.
2224 * @param[in] item_flags
2225 * Bit-fields that holds the items detected until now.
2226 * @param[in] target_protocol
2227 * The next protocol in the previous item.
2228 * @param[in] flow_mask
2229 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2231 * Pointer to error structure.
2234 * 0 on success, a negative errno value otherwise and rte_errno is set.
2237 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2238 uint64_t item_flags,
2239 uint8_t target_protocol,
2240 struct rte_flow_error *error)
2242 const struct rte_flow_item_udp *mask = item->mask;
2243 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2244 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2245 MLX5_FLOW_LAYER_OUTER_L3;
2246 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2247 MLX5_FLOW_LAYER_OUTER_L4;
2250 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2251 return rte_flow_error_set(error, EINVAL,
2252 RTE_FLOW_ERROR_TYPE_ITEM, item,
2253 "protocol filtering not compatible"
2255 if (!(item_flags & l3m))
2256 return rte_flow_error_set(error, EINVAL,
2257 RTE_FLOW_ERROR_TYPE_ITEM, item,
2258 "L3 is mandatory to filter on L4");
2259 if (item_flags & l4m)
2260 return rte_flow_error_set(error, EINVAL,
2261 RTE_FLOW_ERROR_TYPE_ITEM, item,
2262 "multiple L4 layers not supported");
2264 mask = &rte_flow_item_udp_mask;
2265 ret = mlx5_flow_item_acceptable
2266 (item, (const uint8_t *)mask,
2267 (const uint8_t *)&rte_flow_item_udp_mask,
2268 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2276 * Validate TCP item.
2279 * Item specification.
2280 * @param[in] item_flags
2281 * Bit-fields that holds the items detected until now.
2282 * @param[in] target_protocol
2283 * The next protocol in the previous item.
2285 * Pointer to error structure.
2288 * 0 on success, a negative errno value otherwise and rte_errno is set.
2291 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2292 uint64_t item_flags,
2293 uint8_t target_protocol,
2294 const struct rte_flow_item_tcp *flow_mask,
2295 struct rte_flow_error *error)
2297 const struct rte_flow_item_tcp *mask = item->mask;
2298 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2299 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2300 MLX5_FLOW_LAYER_OUTER_L3;
2301 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2302 MLX5_FLOW_LAYER_OUTER_L4;
2305 MLX5_ASSERT(flow_mask);
2306 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2307 return rte_flow_error_set(error, EINVAL,
2308 RTE_FLOW_ERROR_TYPE_ITEM, item,
2309 "protocol filtering not compatible"
2311 if (!(item_flags & l3m))
2312 return rte_flow_error_set(error, EINVAL,
2313 RTE_FLOW_ERROR_TYPE_ITEM, item,
2314 "L3 is mandatory to filter on L4");
2315 if (item_flags & l4m)
2316 return rte_flow_error_set(error, EINVAL,
2317 RTE_FLOW_ERROR_TYPE_ITEM, item,
2318 "multiple L4 layers not supported");
2320 mask = &rte_flow_item_tcp_mask;
2321 ret = mlx5_flow_item_acceptable
2322 (item, (const uint8_t *)mask,
2323 (const uint8_t *)flow_mask,
2324 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2332 * Validate VXLAN item.
2335 * Item specification.
2336 * @param[in] item_flags
2337 * Bit-fields that holds the items detected until now.
2338 * @param[in] target_protocol
2339 * The next protocol in the previous item.
2341 * Pointer to error structure.
2344 * 0 on success, a negative errno value otherwise and rte_errno is set.
2347 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
2348 uint64_t item_flags,
2349 struct rte_flow_error *error)
2351 const struct rte_flow_item_vxlan *spec = item->spec;
2352 const struct rte_flow_item_vxlan *mask = item->mask;
2357 } id = { .vlan_id = 0, };
2360 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2361 return rte_flow_error_set(error, ENOTSUP,
2362 RTE_FLOW_ERROR_TYPE_ITEM, item,
2363 "multiple tunnel layers not"
2366 * Verify only UDPv4 is present as defined in
2367 * https://tools.ietf.org/html/rfc7348
2369 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2370 return rte_flow_error_set(error, EINVAL,
2371 RTE_FLOW_ERROR_TYPE_ITEM, item,
2372 "no outer UDP layer found");
2374 mask = &rte_flow_item_vxlan_mask;
2375 ret = mlx5_flow_item_acceptable
2376 (item, (const uint8_t *)mask,
2377 (const uint8_t *)&rte_flow_item_vxlan_mask,
2378 sizeof(struct rte_flow_item_vxlan),
2379 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2383 memcpy(&id.vni[1], spec->vni, 3);
2384 memcpy(&id.vni[1], mask->vni, 3);
2386 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2387 return rte_flow_error_set(error, ENOTSUP,
2388 RTE_FLOW_ERROR_TYPE_ITEM, item,
2389 "VXLAN tunnel must be fully defined");
2394 * Validate VXLAN_GPE item.
2397 * Item specification.
2398 * @param[in] item_flags
2399 * Bit-fields that holds the items detected until now.
2401 * Pointer to the private data structure.
2402 * @param[in] target_protocol
2403 * The next protocol in the previous item.
2405 * Pointer to error structure.
2408 * 0 on success, a negative errno value otherwise and rte_errno is set.
2411 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2412 uint64_t item_flags,
2413 struct rte_eth_dev *dev,
2414 struct rte_flow_error *error)
2416 struct mlx5_priv *priv = dev->data->dev_private;
2417 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2418 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2423 } id = { .vlan_id = 0, };
2425 if (!priv->config.l3_vxlan_en)
2426 return rte_flow_error_set(error, ENOTSUP,
2427 RTE_FLOW_ERROR_TYPE_ITEM, item,
2428 "L3 VXLAN is not enabled by device"
2429 " parameter and/or not configured in"
2431 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2432 return rte_flow_error_set(error, ENOTSUP,
2433 RTE_FLOW_ERROR_TYPE_ITEM, item,
2434 "multiple tunnel layers not"
2437 * Verify only UDPv4 is present as defined in
2438 * https://tools.ietf.org/html/rfc7348
2440 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2441 return rte_flow_error_set(error, EINVAL,
2442 RTE_FLOW_ERROR_TYPE_ITEM, item,
2443 "no outer UDP layer found");
2445 mask = &rte_flow_item_vxlan_gpe_mask;
2446 ret = mlx5_flow_item_acceptable
2447 (item, (const uint8_t *)mask,
2448 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2449 sizeof(struct rte_flow_item_vxlan_gpe),
2450 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2455 return rte_flow_error_set(error, ENOTSUP,
2456 RTE_FLOW_ERROR_TYPE_ITEM,
2458 "VxLAN-GPE protocol"
2460 memcpy(&id.vni[1], spec->vni, 3);
2461 memcpy(&id.vni[1], mask->vni, 3);
2463 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2464 return rte_flow_error_set(error, ENOTSUP,
2465 RTE_FLOW_ERROR_TYPE_ITEM, item,
2466 "VXLAN-GPE tunnel must be fully"
2471 * Validate GRE Key item.
2474 * Item specification.
2475 * @param[in] item_flags
2476 * Bit flags to mark detected items.
2477 * @param[in] gre_item
2478 * Pointer to gre_item
2480 * Pointer to error structure.
2483 * 0 on success, a negative errno value otherwise and rte_errno is set.
2486 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2487 uint64_t item_flags,
2488 const struct rte_flow_item *gre_item,
2489 struct rte_flow_error *error)
2491 const rte_be32_t *mask = item->mask;
2493 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2494 const struct rte_flow_item_gre *gre_spec;
2495 const struct rte_flow_item_gre *gre_mask;
2497 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2498 return rte_flow_error_set(error, ENOTSUP,
2499 RTE_FLOW_ERROR_TYPE_ITEM, item,
2500 "Multiple GRE key not support");
2501 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2502 return rte_flow_error_set(error, ENOTSUP,
2503 RTE_FLOW_ERROR_TYPE_ITEM, item,
2504 "No preceding GRE header");
2505 if (item_flags & MLX5_FLOW_LAYER_INNER)
2506 return rte_flow_error_set(error, ENOTSUP,
2507 RTE_FLOW_ERROR_TYPE_ITEM, item,
2508 "GRE key following a wrong item");
2509 gre_mask = gre_item->mask;
2511 gre_mask = &rte_flow_item_gre_mask;
2512 gre_spec = gre_item->spec;
2513 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2514 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2515 return rte_flow_error_set(error, EINVAL,
2516 RTE_FLOW_ERROR_TYPE_ITEM, item,
2517 "Key bit must be on");
2520 mask = &gre_key_default_mask;
2521 ret = mlx5_flow_item_acceptable
2522 (item, (const uint8_t *)mask,
2523 (const uint8_t *)&gre_key_default_mask,
2524 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2529 * Validate GRE item.
2532 * Item specification.
2533 * @param[in] item_flags
2534 * Bit flags to mark detected items.
2535 * @param[in] target_protocol
2536 * The next protocol in the previous item.
2538 * Pointer to error structure.
2541 * 0 on success, a negative errno value otherwise and rte_errno is set.
2544 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2545 uint64_t item_flags,
2546 uint8_t target_protocol,
2547 struct rte_flow_error *error)
2549 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2550 const struct rte_flow_item_gre *mask = item->mask;
2552 const struct rte_flow_item_gre nic_mask = {
2553 .c_rsvd0_ver = RTE_BE16(0xB000),
2554 .protocol = RTE_BE16(UINT16_MAX),
2557 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2558 return rte_flow_error_set(error, EINVAL,
2559 RTE_FLOW_ERROR_TYPE_ITEM, item,
2560 "protocol filtering not compatible"
2561 " with this GRE layer");
2562 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2563 return rte_flow_error_set(error, ENOTSUP,
2564 RTE_FLOW_ERROR_TYPE_ITEM, item,
2565 "multiple tunnel layers not"
2567 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2568 return rte_flow_error_set(error, ENOTSUP,
2569 RTE_FLOW_ERROR_TYPE_ITEM, item,
2570 "L3 Layer is missing");
2572 mask = &rte_flow_item_gre_mask;
2573 ret = mlx5_flow_item_acceptable
2574 (item, (const uint8_t *)mask,
2575 (const uint8_t *)&nic_mask,
2576 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2580 #ifndef HAVE_MLX5DV_DR
2581 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2582 if (spec && (spec->protocol & mask->protocol))
2583 return rte_flow_error_set(error, ENOTSUP,
2584 RTE_FLOW_ERROR_TYPE_ITEM, item,
2585 "without MPLS support the"
2586 " specification cannot be used for"
2594 * Validate Geneve item.
2597 * Item specification.
2598 * @param[in] itemFlags
2599 * Bit-fields that holds the items detected until now.
2601 * Pointer to the private data structure.
2603 * Pointer to error structure.
2606 * 0 on success, a negative errno value otherwise and rte_errno is set.
2610 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2611 uint64_t item_flags,
2612 struct rte_eth_dev *dev,
2613 struct rte_flow_error *error)
2615 struct mlx5_priv *priv = dev->data->dev_private;
2616 const struct rte_flow_item_geneve *spec = item->spec;
2617 const struct rte_flow_item_geneve *mask = item->mask;
2620 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2621 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2622 const struct rte_flow_item_geneve nic_mask = {
2623 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2624 .vni = "\xff\xff\xff",
2625 .protocol = RTE_BE16(UINT16_MAX),
2628 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2629 return rte_flow_error_set(error, ENOTSUP,
2630 RTE_FLOW_ERROR_TYPE_ITEM, item,
2631 "L3 Geneve is not enabled by device"
2632 " parameter and/or not configured in"
2634 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2635 return rte_flow_error_set(error, ENOTSUP,
2636 RTE_FLOW_ERROR_TYPE_ITEM, item,
2637 "multiple tunnel layers not"
2640 * Verify only UDPv4 is present as defined in
2641 * https://tools.ietf.org/html/rfc7348
2643 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2644 return rte_flow_error_set(error, EINVAL,
2645 RTE_FLOW_ERROR_TYPE_ITEM, item,
2646 "no outer UDP layer found");
2648 mask = &rte_flow_item_geneve_mask;
2649 ret = mlx5_flow_item_acceptable
2650 (item, (const uint8_t *)mask,
2651 (const uint8_t *)&nic_mask,
2652 sizeof(struct rte_flow_item_geneve),
2653 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2657 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2658 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2659 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2660 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2661 return rte_flow_error_set(error, ENOTSUP,
2662 RTE_FLOW_ERROR_TYPE_ITEM,
2664 "Geneve protocol unsupported"
2665 " fields are being used");
2666 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2667 return rte_flow_error_set
2669 RTE_FLOW_ERROR_TYPE_ITEM,
2671 "Unsupported Geneve options length");
2673 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2674 return rte_flow_error_set
2676 RTE_FLOW_ERROR_TYPE_ITEM, item,
2677 "Geneve tunnel must be fully defined");
2682 * Validate Geneve TLV option item.
2685 * Item specification.
2686 * @param[in] last_item
2687 * Previous validated item in the pattern items.
2688 * @param[in] geneve_item
2689 * Previous GENEVE item specification.
2691 * Pointer to the rte_eth_dev structure.
2693 * Pointer to error structure.
2696 * 0 on success, a negative errno value otherwise and rte_errno is set.
2699 mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
2701 const struct rte_flow_item *geneve_item,
2702 struct rte_eth_dev *dev,
2703 struct rte_flow_error *error)
2705 struct mlx5_priv *priv = dev->data->dev_private;
2706 struct mlx5_dev_ctx_shared *sh = priv->sh;
2707 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
2708 struct mlx5_hca_attr *hca_attr = &priv->config.hca_attr;
2709 uint8_t data_max_supported =
2710 hca_attr->max_geneve_tlv_option_data_len * 4;
2711 struct mlx5_dev_config *config = &priv->config;
2712 const struct rte_flow_item_geneve *geneve_spec;
2713 const struct rte_flow_item_geneve *geneve_mask;
2714 const struct rte_flow_item_geneve_opt *spec = item->spec;
2715 const struct rte_flow_item_geneve_opt *mask = item->mask;
2717 unsigned int data_len;
2718 uint8_t tlv_option_len;
2719 uint16_t optlen_m, optlen_v;
2720 const struct rte_flow_item_geneve_opt full_mask = {
2721 .option_class = RTE_BE16(0xffff),
2722 .option_type = 0xff,
2727 mask = &rte_flow_item_geneve_opt_mask;
2729 return rte_flow_error_set
2730 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2731 "Geneve TLV opt class/type/length must be specified");
2732 if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
2733 return rte_flow_error_set
2734 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2735 "Geneve TLV opt length exceeeds the limit (31)");
2736 /* Check if class type and length masks are full. */
2737 if (full_mask.option_class != mask->option_class ||
2738 full_mask.option_type != mask->option_type ||
2739 full_mask.option_len != (mask->option_len & full_mask.option_len))
2740 return rte_flow_error_set
2741 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2742 "Geneve TLV opt class/type/length masks must be full");
2743 /* Check if length is supported */
2744 if ((uint32_t)spec->option_len >
2745 config->hca_attr.max_geneve_tlv_option_data_len)
2746 return rte_flow_error_set
2747 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2748 "Geneve TLV opt length not supported");
2749 if (config->hca_attr.max_geneve_tlv_options > 1)
2751 "max_geneve_tlv_options supports more than 1 option");
2752 /* Check GENEVE item preceding. */
2753 if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
2754 return rte_flow_error_set
2755 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2756 "Geneve opt item must be preceded with Geneve item");
2757 geneve_spec = geneve_item->spec;
2758 geneve_mask = geneve_item->mask ? geneve_item->mask :
2759 &rte_flow_item_geneve_mask;
2760 /* Check if GENEVE TLV option size doesn't exceed option length */
2761 if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
2762 geneve_spec->ver_opt_len_o_c_rsvd0)) {
2763 tlv_option_len = spec->option_len & mask->option_len;
2764 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
2765 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
2766 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
2767 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
2768 if ((optlen_v & optlen_m) <= tlv_option_len)
2769 return rte_flow_error_set
2770 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2771 "GENEVE TLV option length exceeds optlen");
2773 /* Check if length is 0 or data is 0. */
2774 if (spec->data == NULL || spec->option_len == 0)
2775 return rte_flow_error_set
2776 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2777 "Geneve TLV opt with zero data/length not supported");
2778 /* Check not all data & mask are 0. */
2779 data_len = spec->option_len * 4;
2780 if (mask->data == NULL) {
2781 for (i = 0; i < data_len; i++)
2785 return rte_flow_error_set(error, ENOTSUP,
2786 RTE_FLOW_ERROR_TYPE_ITEM, item,
2787 "Can't match on Geneve option data 0");
2789 for (i = 0; i < data_len; i++)
2790 if (spec->data[i] & mask->data[i])
2793 return rte_flow_error_set(error, ENOTSUP,
2794 RTE_FLOW_ERROR_TYPE_ITEM, item,
2795 "Can't match on Geneve option data and mask 0");
2796 /* Check data mask supported. */
2797 for (i = data_max_supported; i < data_len ; i++)
2799 return rte_flow_error_set(error, ENOTSUP,
2800 RTE_FLOW_ERROR_TYPE_ITEM, item,
2801 "Data mask is of unsupported size");
2803 /* Check GENEVE option is supported in NIC. */
2804 if (!config->hca_attr.geneve_tlv_opt)
2805 return rte_flow_error_set
2806 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2807 "Geneve TLV opt not supported");
2808 /* Check if we already have geneve option with different type/class. */
2809 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
2810 geneve_opt_resource = sh->geneve_tlv_option_resource;
2811 if (geneve_opt_resource != NULL)
2812 if (geneve_opt_resource->option_class != spec->option_class ||
2813 geneve_opt_resource->option_type != spec->option_type ||
2814 geneve_opt_resource->length != spec->option_len) {
2815 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2816 return rte_flow_error_set(error, ENOTSUP,
2817 RTE_FLOW_ERROR_TYPE_ITEM, item,
2818 "Only one Geneve TLV option supported");
2820 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
2825 * Validate MPLS item.
2828 * Pointer to the rte_eth_dev structure.
2830 * Item specification.
2831 * @param[in] item_flags
2832 * Bit-fields that holds the items detected until now.
2833 * @param[in] prev_layer
2834 * The protocol layer indicated in previous item.
2836 * Pointer to error structure.
2839 * 0 on success, a negative errno value otherwise and rte_errno is set.
2842 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2843 const struct rte_flow_item *item __rte_unused,
2844 uint64_t item_flags __rte_unused,
2845 uint64_t prev_layer __rte_unused,
2846 struct rte_flow_error *error)
2848 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2849 const struct rte_flow_item_mpls *mask = item->mask;
2850 struct mlx5_priv *priv = dev->data->dev_private;
2853 if (!priv->config.mpls_en)
2854 return rte_flow_error_set(error, ENOTSUP,
2855 RTE_FLOW_ERROR_TYPE_ITEM, item,
2856 "MPLS not supported or"
2857 " disabled in firmware"
2859 /* MPLS over IP, UDP, GRE is allowed */
2860 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2861 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2862 MLX5_FLOW_LAYER_GRE |
2863 MLX5_FLOW_LAYER_GRE_KEY)))
2864 return rte_flow_error_set(error, EINVAL,
2865 RTE_FLOW_ERROR_TYPE_ITEM, item,
2866 "protocol filtering not compatible"
2867 " with MPLS layer");
2868 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2869 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2870 !(item_flags & MLX5_FLOW_LAYER_GRE))
2871 return rte_flow_error_set(error, ENOTSUP,
2872 RTE_FLOW_ERROR_TYPE_ITEM, item,
2873 "multiple tunnel layers not"
2876 mask = &rte_flow_item_mpls_mask;
2877 ret = mlx5_flow_item_acceptable
2878 (item, (const uint8_t *)mask,
2879 (const uint8_t *)&rte_flow_item_mpls_mask,
2880 sizeof(struct rte_flow_item_mpls),
2881 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2886 return rte_flow_error_set(error, ENOTSUP,
2887 RTE_FLOW_ERROR_TYPE_ITEM, item,
2888 "MPLS is not supported by Verbs, please"
2894 * Validate NVGRE item.
2897 * Item specification.
2898 * @param[in] item_flags
2899 * Bit flags to mark detected items.
2900 * @param[in] target_protocol
2901 * The next protocol in the previous item.
2903 * Pointer to error structure.
2906 * 0 on success, a negative errno value otherwise and rte_errno is set.
2909 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2910 uint64_t item_flags,
2911 uint8_t target_protocol,
2912 struct rte_flow_error *error)
2914 const struct rte_flow_item_nvgre *mask = item->mask;
2917 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2918 return rte_flow_error_set(error, EINVAL,
2919 RTE_FLOW_ERROR_TYPE_ITEM, item,
2920 "protocol filtering not compatible"
2921 " with this GRE layer");
2922 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2923 return rte_flow_error_set(error, ENOTSUP,
2924 RTE_FLOW_ERROR_TYPE_ITEM, item,
2925 "multiple tunnel layers not"
2927 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2928 return rte_flow_error_set(error, ENOTSUP,
2929 RTE_FLOW_ERROR_TYPE_ITEM, item,
2930 "L3 Layer is missing");
2932 mask = &rte_flow_item_nvgre_mask;
2933 ret = mlx5_flow_item_acceptable
2934 (item, (const uint8_t *)mask,
2935 (const uint8_t *)&rte_flow_item_nvgre_mask,
2936 sizeof(struct rte_flow_item_nvgre),
2937 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2944 * Validate eCPRI item.
2947 * Item specification.
2948 * @param[in] item_flags
2949 * Bit-fields that holds the items detected until now.
2950 * @param[in] last_item
2951 * Previous validated item in the pattern items.
2952 * @param[in] ether_type
2953 * Type in the ethernet layer header (including dot1q).
2954 * @param[in] acc_mask
2955 * Acceptable mask, if NULL default internal default mask
2956 * will be used to check whether item fields are supported.
2958 * Pointer to error structure.
2961 * 0 on success, a negative errno value otherwise and rte_errno is set.
2964 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
2965 uint64_t item_flags,
2967 uint16_t ether_type,
2968 const struct rte_flow_item_ecpri *acc_mask,
2969 struct rte_flow_error *error)
2971 const struct rte_flow_item_ecpri *mask = item->mask;
2972 const struct rte_flow_item_ecpri nic_mask = {
2976 RTE_BE32(((const struct rte_ecpri_common_hdr) {
2980 .dummy[0] = 0xFFFFFFFF,
2983 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
2984 MLX5_FLOW_LAYER_OUTER_VLAN);
2985 struct rte_flow_item_ecpri mask_lo;
2987 if (!(last_item & outer_l2_vlan) &&
2988 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
2989 return rte_flow_error_set(error, EINVAL,
2990 RTE_FLOW_ERROR_TYPE_ITEM, item,
2991 "eCPRI can only follow L2/VLAN layer or UDP layer");
2992 if ((last_item & outer_l2_vlan) && ether_type &&
2993 ether_type != RTE_ETHER_TYPE_ECPRI)
2994 return rte_flow_error_set(error, EINVAL,
2995 RTE_FLOW_ERROR_TYPE_ITEM, item,
2996 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
2997 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2998 return rte_flow_error_set(error, EINVAL,
2999 RTE_FLOW_ERROR_TYPE_ITEM, item,
3000 "eCPRI with tunnel is not supported right now");
3001 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3002 return rte_flow_error_set(error, ENOTSUP,
3003 RTE_FLOW_ERROR_TYPE_ITEM, item,
3004 "multiple L3 layers not supported");
3005 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3006 return rte_flow_error_set(error, EINVAL,
3007 RTE_FLOW_ERROR_TYPE_ITEM, item,
3008 "eCPRI cannot coexist with a TCP layer");
3009 /* In specification, eCPRI could be over UDP layer. */
3010 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3011 return rte_flow_error_set(error, EINVAL,
3012 RTE_FLOW_ERROR_TYPE_ITEM, item,
3013 "eCPRI over UDP layer is not yet supported right now");
3014 /* Mask for type field in common header could be zero. */
3016 mask = &rte_flow_item_ecpri_mask;
3017 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3018 /* Input mask is in big-endian format. */
3019 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3020 return rte_flow_error_set(error, EINVAL,
3021 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3022 "partial mask is not supported for protocol");
3023 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3024 return rte_flow_error_set(error, EINVAL,
3025 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3026 "message header mask must be after a type mask");
3027 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
3028 acc_mask ? (const uint8_t *)acc_mask
3029 : (const uint8_t *)&nic_mask,
3030 sizeof(struct rte_flow_item_ecpri),
3031 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3035 * Release resource related QUEUE/RSS action split.
3038 * Pointer to Ethernet device.
3040 * Flow to release id's from.
3043 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
3044 struct rte_flow *flow)
3046 struct mlx5_priv *priv = dev->data->dev_private;
3047 uint32_t handle_idx;
3048 struct mlx5_flow_handle *dev_handle;
3050 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
3051 handle_idx, dev_handle, next)
3052 if (dev_handle->split_flow_id)
3053 mlx5_ipool_free(priv->sh->ipool
3054 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
3055 dev_handle->split_flow_id);
3059 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
3060 const struct rte_flow_attr *attr __rte_unused,
3061 const struct rte_flow_item items[] __rte_unused,
3062 const struct rte_flow_action actions[] __rte_unused,
3063 bool external __rte_unused,
3064 int hairpin __rte_unused,
3065 struct rte_flow_error *error)
3067 return rte_flow_error_set(error, ENOTSUP,
3068 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3071 static struct mlx5_flow *
3072 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
3073 const struct rte_flow_attr *attr __rte_unused,
3074 const struct rte_flow_item items[] __rte_unused,
3075 const struct rte_flow_action actions[] __rte_unused,
3076 struct rte_flow_error *error)
3078 rte_flow_error_set(error, ENOTSUP,
3079 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3084 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
3085 struct mlx5_flow *dev_flow __rte_unused,
3086 const struct rte_flow_attr *attr __rte_unused,
3087 const struct rte_flow_item items[] __rte_unused,
3088 const struct rte_flow_action actions[] __rte_unused,
3089 struct rte_flow_error *error)
3091 return rte_flow_error_set(error, ENOTSUP,
3092 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3096 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
3097 struct rte_flow *flow __rte_unused,
3098 struct rte_flow_error *error)
3100 return rte_flow_error_set(error, ENOTSUP,
3101 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3105 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
3106 struct rte_flow *flow __rte_unused)
3111 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
3112 struct rte_flow *flow __rte_unused)
3117 flow_null_query(struct rte_eth_dev *dev __rte_unused,
3118 struct rte_flow *flow __rte_unused,
3119 const struct rte_flow_action *actions __rte_unused,
3120 void *data __rte_unused,
3121 struct rte_flow_error *error)
3123 return rte_flow_error_set(error, ENOTSUP,
3124 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
3128 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
3129 uint32_t domains __rte_unused,
3130 uint32_t flags __rte_unused)
3135 /* Void driver to protect from null pointer reference. */
3136 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
3137 .validate = flow_null_validate,
3138 .prepare = flow_null_prepare,
3139 .translate = flow_null_translate,
3140 .apply = flow_null_apply,
3141 .remove = flow_null_remove,
3142 .destroy = flow_null_destroy,
3143 .query = flow_null_query,
3144 .sync_domain = flow_null_sync_domain,
3148 * Select flow driver type according to flow attributes and device
3152 * Pointer to the dev structure.
3154 * Pointer to the flow attributes.
3157 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
3159 static enum mlx5_flow_drv_type
3160 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
3162 struct mlx5_priv *priv = dev->data->dev_private;
3163 /* The OS can determine first a specific flow type (DV, VERBS) */
3164 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
3166 if (type != MLX5_FLOW_TYPE_MAX)
3168 /* If no OS specific type - continue with DV/VERBS selection */
3169 if (attr->transfer && priv->config.dv_esw_en)
3170 type = MLX5_FLOW_TYPE_DV;
3171 if (!attr->transfer)
3172 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
3173 MLX5_FLOW_TYPE_VERBS;
3177 #define flow_get_drv_ops(type) flow_drv_ops[type]
3180 * Flow driver validation API. This abstracts calling driver specific functions.
3181 * The type of flow driver is determined according to flow attributes.
3184 * Pointer to the dev structure.
3186 * Pointer to the flow attributes.
3188 * Pointer to the list of items.
3189 * @param[in] actions
3190 * Pointer to the list of actions.
3191 * @param[in] external
3192 * This flow rule is created by request external to PMD.
3193 * @param[in] hairpin
3194 * Number of hairpin TX actions, 0 means classic flow.
3196 * Pointer to the error structure.
3199 * 0 on success, a negative errno value otherwise and rte_errno is set.
3202 flow_drv_validate(struct rte_eth_dev *dev,
3203 const struct rte_flow_attr *attr,
3204 const struct rte_flow_item items[],
3205 const struct rte_flow_action actions[],
3206 bool external, int hairpin, struct rte_flow_error *error)
3208 const struct mlx5_flow_driver_ops *fops;
3209 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
3211 fops = flow_get_drv_ops(type);
3212 return fops->validate(dev, attr, items, actions, external,
3217 * Flow driver preparation API. This abstracts calling driver specific
3218 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3219 * calculates the size of memory required for device flow, allocates the memory,
3220 * initializes the device flow and returns the pointer.
3223 * This function initializes device flow structure such as dv or verbs in
3224 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3225 * rest. For example, adding returning device flow to flow->dev_flow list and
3226 * setting backward reference to the flow should be done out of this function.
3227 * layers field is not filled either.
3230 * Pointer to the dev structure.
3232 * Pointer to the flow attributes.
3234 * Pointer to the list of items.
3235 * @param[in] actions
3236 * Pointer to the list of actions.
3237 * @param[in] flow_idx
3238 * This memory pool index to the flow.
3240 * Pointer to the error structure.
3243 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3245 static inline struct mlx5_flow *
3246 flow_drv_prepare(struct rte_eth_dev *dev,
3247 const struct rte_flow *flow,
3248 const struct rte_flow_attr *attr,
3249 const struct rte_flow_item items[],
3250 const struct rte_flow_action actions[],
3252 struct rte_flow_error *error)
3254 const struct mlx5_flow_driver_ops *fops;
3255 enum mlx5_flow_drv_type type = flow->drv_type;
3256 struct mlx5_flow *mlx5_flow = NULL;
3258 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3259 fops = flow_get_drv_ops(type);
3260 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3262 mlx5_flow->flow_idx = flow_idx;
3267 * Flow driver translation API. This abstracts calling driver specific
3268 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3269 * translates a generic flow into a driver flow. flow_drv_prepare() must
3273 * dev_flow->layers could be filled as a result of parsing during translation
3274 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3275 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3276 * flow->actions could be overwritten even though all the expanded dev_flows
3277 * have the same actions.
3280 * Pointer to the rte dev structure.
3281 * @param[in, out] dev_flow
3282 * Pointer to the mlx5 flow.
3284 * Pointer to the flow attributes.
3286 * Pointer to the list of items.
3287 * @param[in] actions
3288 * Pointer to the list of actions.
3290 * Pointer to the error structure.
3293 * 0 on success, a negative errno value otherwise and rte_errno is set.
3296 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3297 const struct rte_flow_attr *attr,
3298 const struct rte_flow_item items[],
3299 const struct rte_flow_action actions[],
3300 struct rte_flow_error *error)
3302 const struct mlx5_flow_driver_ops *fops;
3303 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3305 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3306 fops = flow_get_drv_ops(type);
3307 return fops->translate(dev, dev_flow, attr, items, actions, error);
3311 * Flow driver apply API. This abstracts calling driver specific functions.
3312 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3313 * translated driver flows on to device. flow_drv_translate() must precede.
3316 * Pointer to Ethernet device structure.
3317 * @param[in, out] flow
3318 * Pointer to flow structure.
3320 * Pointer to error structure.
3323 * 0 on success, a negative errno value otherwise and rte_errno is set.
3326 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3327 struct rte_flow_error *error)
3329 const struct mlx5_flow_driver_ops *fops;
3330 enum mlx5_flow_drv_type type = flow->drv_type;
3332 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3333 fops = flow_get_drv_ops(type);
3334 return fops->apply(dev, flow, error);
3338 * Flow driver destroy API. This abstracts calling driver specific functions.
3339 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3340 * on device and releases resources of the flow.
3343 * Pointer to Ethernet device.
3344 * @param[in, out] flow
3345 * Pointer to flow structure.
3348 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3350 const struct mlx5_flow_driver_ops *fops;
3351 enum mlx5_flow_drv_type type = flow->drv_type;
3353 flow_mreg_split_qrss_release(dev, flow);
3354 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3355 fops = flow_get_drv_ops(type);
3356 fops->destroy(dev, flow);
3360 * Get RSS action from the action list.
3362 * @param[in] actions
3363 * Pointer to the list of actions.
3366 * Pointer to the RSS action if exist, else return NULL.
3368 static const struct rte_flow_action_rss*
3369 flow_get_rss_action(const struct rte_flow_action actions[])
3371 const struct rte_flow_action_rss *rss = NULL;
3373 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3374 switch (actions->type) {
3375 case RTE_FLOW_ACTION_TYPE_RSS:
3376 rss = actions->conf;
3378 case RTE_FLOW_ACTION_TYPE_SAMPLE:
3380 const struct rte_flow_action_sample *sample =
3382 const struct rte_flow_action *act = sample->actions;
3383 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
3384 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
3396 * Get ASO age action by index.
3399 * Pointer to the Ethernet device structure.
3400 * @param[in] age_idx
3401 * Index to the ASO age action.
3404 * The specified ASO age action.
3406 struct mlx5_aso_age_action*
3407 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3409 uint16_t pool_idx = age_idx & UINT16_MAX;
3410 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3411 struct mlx5_priv *priv = dev->data->dev_private;
3412 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3413 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3415 return &pool->actions[offset - 1];
3418 /* maps shared action to translated non shared in some actions array */
3419 struct mlx5_translated_shared_action {
3420 struct rte_flow_shared_action *action; /**< Shared action */
3421 int index; /**< Index in related array of rte_flow_action */
3425 * Translates actions of type RTE_FLOW_ACTION_TYPE_SHARED to related
3426 * non shared action if translation possible.
3427 * This functionality used to run same execution path for both shared & non
3428 * shared actions on flow create. All necessary preparations for shared
3429 * action handling should be preformed on *shared* actions list returned
3433 * Pointer to Ethernet device.
3434 * @param[in] actions
3435 * List of actions to translate.
3436 * @param[out] shared
3437 * List to store translated shared actions.
3438 * @param[in, out] shared_n
3439 * Size of *shared* array. On return should be updated with number of shared
3440 * actions retrieved from the *actions* list.
3441 * @param[out] translated_actions
3442 * List of actions where all shared actions were translated to non shared
3443 * if possible. NULL if no translation took place.
3445 * Pointer to the error structure.
3448 * 0 on success, a negative errno value otherwise and rte_errno is set.
3451 flow_shared_actions_translate(struct rte_eth_dev *dev,
3452 const struct rte_flow_action actions[],
3453 struct mlx5_translated_shared_action *shared,
3455 struct rte_flow_action **translated_actions,
3456 struct rte_flow_error *error)
3458 struct mlx5_priv *priv = dev->data->dev_private;
3459 struct rte_flow_action *translated = NULL;
3460 size_t actions_size;
3463 struct mlx5_translated_shared_action *shared_end = NULL;
3465 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3466 if (actions[n].type != RTE_FLOW_ACTION_TYPE_SHARED)
3468 if (copied_n == *shared_n) {
3469 return rte_flow_error_set
3470 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3471 NULL, "too many shared actions");
3473 rte_memcpy(&shared[copied_n].action, &actions[n].conf,
3474 sizeof(actions[n].conf));
3475 shared[copied_n].index = n;
3479 *shared_n = copied_n;
3482 actions_size = sizeof(struct rte_flow_action) * n;
3483 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3488 memcpy(translated, actions, actions_size);
3489 for (shared_end = shared + copied_n; shared < shared_end; shared++) {
3490 struct mlx5_shared_action_rss *shared_rss;
3491 uint32_t act_idx = (uint32_t)(uintptr_t)shared->action;
3492 uint32_t type = act_idx >> MLX5_SHARED_ACTION_TYPE_OFFSET;
3493 uint32_t idx = act_idx & ((1u << MLX5_SHARED_ACTION_TYPE_OFFSET)
3497 case MLX5_SHARED_ACTION_TYPE_RSS:
3498 shared_rss = mlx5_ipool_get
3499 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3500 translated[shared->index].type =
3501 RTE_FLOW_ACTION_TYPE_RSS;
3502 translated[shared->index].conf =
3503 &shared_rss->origin;
3505 case MLX5_SHARED_ACTION_TYPE_AGE:
3506 if (priv->sh->flow_hit_aso_en) {
3507 translated[shared->index].type =
3508 (enum rte_flow_action_type)
3509 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3510 translated[shared->index].conf =
3511 (void *)(uintptr_t)idx;
3516 mlx5_free(translated);
3517 return rte_flow_error_set
3518 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3519 NULL, "invalid shared action type");
3522 *translated_actions = translated;
3527 * Get Shared RSS action from the action list.
3530 * Pointer to Ethernet device.
3532 * Pointer to the list of actions.
3533 * @param[in] shared_n
3534 * Actions list length.
3537 * The MLX5 RSS action ID if exists, otherwise return 0.
3540 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3541 struct mlx5_translated_shared_action *shared,
3544 struct mlx5_translated_shared_action *shared_end;
3545 struct mlx5_priv *priv = dev->data->dev_private;
3546 struct mlx5_shared_action_rss *shared_rss;
3549 for (shared_end = shared + shared_n; shared < shared_end; shared++) {
3550 uint32_t act_idx = (uint32_t)(uintptr_t)shared->action;
3551 uint32_t type = act_idx >> MLX5_SHARED_ACTION_TYPE_OFFSET;
3552 uint32_t idx = act_idx &
3553 ((1u << MLX5_SHARED_ACTION_TYPE_OFFSET) - 1);
3555 case MLX5_SHARED_ACTION_TYPE_RSS:
3556 shared_rss = mlx5_ipool_get
3557 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3559 __atomic_add_fetch(&shared_rss->refcnt, 1,
3570 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3572 const struct rte_flow_item *item;
3573 unsigned int has_vlan = 0;
3575 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3576 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3582 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3583 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3584 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3585 MLX5_EXPANSION_ROOT_OUTER;
3589 * Get layer flags from the prefix flow.
3591 * Some flows may be split to several subflows, the prefix subflow gets the
3592 * match items and the suffix sub flow gets the actions.
3593 * Some actions need the user defined match item flags to get the detail for
3595 * This function helps the suffix flow to get the item layer flags from prefix
3598 * @param[in] dev_flow
3599 * Pointer the created preifx subflow.
3602 * The layers get from prefix subflow.
3604 static inline uint64_t
3605 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3607 uint64_t layers = 0;
3610 * Layers bits could be localization, but usually the compiler will
3611 * help to do the optimization work for source code.
3612 * If no decap actions, use the layers directly.
3614 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3615 return dev_flow->handle->layers;
3616 /* Convert L3 layers with decap action. */
3617 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3618 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3619 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3620 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3621 /* Convert L4 layers with decap action. */
3622 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3623 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3624 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3625 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3630 * Get metadata split action information.
3632 * @param[in] actions
3633 * Pointer to the list of actions.
3635 * Pointer to the return pointer.
3636 * @param[out] qrss_type
3637 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3638 * if no QUEUE/RSS is found.
3639 * @param[out] encap_idx
3640 * Pointer to the index of the encap action if exists, otherwise the last
3644 * Total number of actions.
3647 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3648 const struct rte_flow_action **qrss,
3651 const struct rte_flow_action_raw_encap *raw_encap;
3653 int raw_decap_idx = -1;
3656 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3657 switch (actions->type) {
3658 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3659 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3660 *encap_idx = actions_n;
3662 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3663 raw_decap_idx = actions_n;
3665 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3666 raw_encap = actions->conf;
3667 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3668 *encap_idx = raw_decap_idx != -1 ?
3669 raw_decap_idx : actions_n;
3671 case RTE_FLOW_ACTION_TYPE_QUEUE:
3672 case RTE_FLOW_ACTION_TYPE_RSS:
3680 if (*encap_idx == -1)
3681 *encap_idx = actions_n;
3682 /* Count RTE_FLOW_ACTION_TYPE_END. */
3683 return actions_n + 1;
3687 * Check meter action from the action list.
3689 * @param[in] actions
3690 * Pointer to the list of actions.
3692 * Pointer to the meter exist flag.
3695 * Total number of actions.
3698 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
3704 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3705 switch (actions->type) {
3706 case RTE_FLOW_ACTION_TYPE_METER:
3714 /* Count RTE_FLOW_ACTION_TYPE_END. */
3715 return actions_n + 1;
3719 * Check if the flow should be split due to hairpin.
3720 * The reason for the split is that in current HW we can't
3721 * support encap and push-vlan on Rx, so if a flow contains
3722 * these actions we move it to Tx.
3725 * Pointer to Ethernet device.
3727 * Flow rule attributes.
3728 * @param[in] actions
3729 * Associated actions (list terminated by the END action).
3732 * > 0 the number of actions and the flow should be split,
3733 * 0 when no split required.
3736 flow_check_hairpin_split(struct rte_eth_dev *dev,
3737 const struct rte_flow_attr *attr,
3738 const struct rte_flow_action actions[])
3740 int queue_action = 0;
3743 const struct rte_flow_action_queue *queue;
3744 const struct rte_flow_action_rss *rss;
3745 const struct rte_flow_action_raw_encap *raw_encap;
3746 const struct rte_eth_hairpin_conf *conf;
3750 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3751 switch (actions->type) {
3752 case RTE_FLOW_ACTION_TYPE_QUEUE:
3753 queue = actions->conf;
3756 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
3757 if (conf == NULL || conf->tx_explicit != 0)
3762 case RTE_FLOW_ACTION_TYPE_RSS:
3763 rss = actions->conf;
3764 if (rss == NULL || rss->queue_num == 0)
3766 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
3767 if (conf == NULL || conf->tx_explicit != 0)
3772 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3773 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3774 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3775 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3776 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3780 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3781 raw_encap = actions->conf;
3782 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3791 if (split && queue_action)
3796 /* Declare flow create/destroy prototype in advance. */
3798 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
3799 const struct rte_flow_attr *attr,
3800 const struct rte_flow_item items[],
3801 const struct rte_flow_action actions[],
3802 bool external, struct rte_flow_error *error);
3805 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
3809 flow_dv_mreg_match_cb(struct mlx5_hlist *list __rte_unused,
3810 struct mlx5_hlist_entry *entry,
3811 uint64_t key, void *cb_ctx __rte_unused)
3813 struct mlx5_flow_mreg_copy_resource *mcp_res =
3814 container_of(entry, typeof(*mcp_res), hlist_ent);
3816 return mcp_res->mark_id != key;
3819 struct mlx5_hlist_entry *
3820 flow_dv_mreg_create_cb(struct mlx5_hlist *list, uint64_t key,
3823 struct rte_eth_dev *dev = list->ctx;
3824 struct mlx5_priv *priv = dev->data->dev_private;
3825 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3826 struct mlx5_flow_mreg_copy_resource *mcp_res;
3827 struct rte_flow_error *error = ctx->error;
3830 uint32_t mark_id = key;
3831 struct rte_flow_attr attr = {
3832 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3835 struct mlx5_rte_flow_item_tag tag_spec = {
3838 struct rte_flow_item items[] = {
3839 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
3841 struct rte_flow_action_mark ftag = {
3844 struct mlx5_flow_action_copy_mreg cp_mreg = {
3848 struct rte_flow_action_jump jump = {
3849 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3851 struct rte_flow_action actions[] = {
3852 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
3855 /* Fill the register fileds in the flow. */
3856 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3860 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3864 /* Provide the full width of FLAG specific value. */
3865 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3866 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3867 /* Build a new flow. */
3868 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3869 items[0] = (struct rte_flow_item){
3870 .type = (enum rte_flow_item_type)
3871 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3874 items[1] = (struct rte_flow_item){
3875 .type = RTE_FLOW_ITEM_TYPE_END,
3877 actions[0] = (struct rte_flow_action){
3878 .type = (enum rte_flow_action_type)
3879 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3882 actions[1] = (struct rte_flow_action){
3883 .type = (enum rte_flow_action_type)
3884 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3887 actions[2] = (struct rte_flow_action){
3888 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3891 actions[3] = (struct rte_flow_action){
3892 .type = RTE_FLOW_ACTION_TYPE_END,
3895 /* Default rule, wildcard match. */
3896 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
3897 items[0] = (struct rte_flow_item){
3898 .type = RTE_FLOW_ITEM_TYPE_END,
3900 actions[0] = (struct rte_flow_action){
3901 .type = (enum rte_flow_action_type)
3902 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3905 actions[1] = (struct rte_flow_action){
3906 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3909 actions[2] = (struct rte_flow_action){
3910 .type = RTE_FLOW_ACTION_TYPE_END,
3913 /* Build a new entry. */
3914 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3920 mcp_res->mark_id = mark_id;
3922 * The copy Flows are not included in any list. There
3923 * ones are referenced from other Flows and can not
3924 * be applied, removed, deleted in ardbitrary order
3925 * by list traversing.
3927 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3928 actions, false, error);
3929 if (!mcp_res->rix_flow) {
3930 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
3933 return &mcp_res->hlist_ent;
3937 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3939 * As mark_id is unique, if there's already a registered flow for the mark_id,
3940 * return by increasing the reference counter of the resource. Otherwise, create
3941 * the resource (mcp_res) and flow.
3944 * - If ingress port is ANY and reg_c[1] is mark_id,
3945 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3947 * For default flow (zero mark_id), flow is like,
3948 * - If ingress port is ANY,
3949 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
3952 * Pointer to Ethernet device.
3954 * ID of MARK action, zero means default flow for META.
3956 * Perform verbose error reporting if not NULL.
3959 * Associated resource on success, NULL otherwise and rte_errno is set.
3961 static struct mlx5_flow_mreg_copy_resource *
3962 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
3963 struct rte_flow_error *error)
3965 struct mlx5_priv *priv = dev->data->dev_private;
3966 struct mlx5_hlist_entry *entry;
3967 struct mlx5_flow_cb_ctx ctx = {
3972 /* Check if already registered. */
3973 MLX5_ASSERT(priv->mreg_cp_tbl);
3974 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
3977 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
3982 flow_dv_mreg_remove_cb(struct mlx5_hlist *list, struct mlx5_hlist_entry *entry)
3984 struct mlx5_flow_mreg_copy_resource *mcp_res =
3985 container_of(entry, typeof(*mcp_res), hlist_ent);
3986 struct rte_eth_dev *dev = list->ctx;
3987 struct mlx5_priv *priv = dev->data->dev_private;
3989 MLX5_ASSERT(mcp_res->rix_flow);
3990 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3991 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3995 * Release flow in RX_CP_TBL.
3998 * Pointer to Ethernet device.
4000 * Parent flow for wich copying is provided.
4003 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
4004 struct rte_flow *flow)
4006 struct mlx5_flow_mreg_copy_resource *mcp_res;
4007 struct mlx5_priv *priv = dev->data->dev_private;
4009 if (!flow->rix_mreg_copy)
4011 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
4012 flow->rix_mreg_copy);
4013 if (!mcp_res || !priv->mreg_cp_tbl)
4015 MLX5_ASSERT(mcp_res->rix_flow);
4016 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
4017 flow->rix_mreg_copy = 0;
4021 * Remove the default copy action from RX_CP_TBL.
4023 * This functions is called in the mlx5_dev_start(). No thread safe
4027 * Pointer to Ethernet device.
4030 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
4032 struct mlx5_hlist_entry *entry;
4033 struct mlx5_priv *priv = dev->data->dev_private;
4035 /* Check if default flow is registered. */
4036 if (!priv->mreg_cp_tbl)
4038 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl,
4039 MLX5_DEFAULT_COPY_ID, NULL);
4042 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
4046 * Add the default copy action in in RX_CP_TBL.
4048 * This functions is called in the mlx5_dev_start(). No thread safe
4052 * Pointer to Ethernet device.
4054 * Perform verbose error reporting if not NULL.
4057 * 0 for success, negative value otherwise and rte_errno is set.
4060 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
4061 struct rte_flow_error *error)
4063 struct mlx5_priv *priv = dev->data->dev_private;
4064 struct mlx5_flow_mreg_copy_resource *mcp_res;
4066 /* Check whether extensive metadata feature is engaged. */
4067 if (!priv->config.dv_flow_en ||
4068 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4069 !mlx5_flow_ext_mreg_supported(dev) ||
4070 !priv->sh->dv_regc0_mask)
4073 * Add default mreg copy flow may be called multiple time, but
4074 * only be called once in stop. Avoid register it twice.
4076 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, MLX5_DEFAULT_COPY_ID, NULL))
4078 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
4085 * Add a flow of copying flow metadata registers in RX_CP_TBL.
4087 * All the flow having Q/RSS action should be split by
4088 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
4089 * performs the following,
4090 * - CQE->flow_tag := reg_c[1] (MARK)
4091 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4092 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
4093 * but there should be a flow per each MARK ID set by MARK action.
4095 * For the aforementioned reason, if there's a MARK action in flow's action
4096 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
4097 * the MARK ID to CQE's flow_tag like,
4098 * - If reg_c[1] is mark_id,
4099 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4101 * For SET_META action which stores value in reg_c[0], as the destination is
4102 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
4103 * MARK ID means the default flow. The default flow looks like,
4104 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
4107 * Pointer to Ethernet device.
4109 * Pointer to flow structure.
4110 * @param[in] actions
4111 * Pointer to the list of actions.
4113 * Perform verbose error reporting if not NULL.
4116 * 0 on success, negative value otherwise and rte_errno is set.
4119 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
4120 struct rte_flow *flow,
4121 const struct rte_flow_action *actions,
4122 struct rte_flow_error *error)
4124 struct mlx5_priv *priv = dev->data->dev_private;
4125 struct mlx5_dev_config *config = &priv->config;
4126 struct mlx5_flow_mreg_copy_resource *mcp_res;
4127 const struct rte_flow_action_mark *mark;
4129 /* Check whether extensive metadata feature is engaged. */
4130 if (!config->dv_flow_en ||
4131 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4132 !mlx5_flow_ext_mreg_supported(dev) ||
4133 !priv->sh->dv_regc0_mask)
4135 /* Find MARK action. */
4136 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4137 switch (actions->type) {
4138 case RTE_FLOW_ACTION_TYPE_FLAG:
4139 mcp_res = flow_mreg_add_copy_action
4140 (dev, MLX5_FLOW_MARK_DEFAULT, error);
4143 flow->rix_mreg_copy = mcp_res->idx;
4145 case RTE_FLOW_ACTION_TYPE_MARK:
4146 mark = (const struct rte_flow_action_mark *)
4149 flow_mreg_add_copy_action(dev, mark->id, error);
4152 flow->rix_mreg_copy = mcp_res->idx;
4161 #define MLX5_MAX_SPLIT_ACTIONS 24
4162 #define MLX5_MAX_SPLIT_ITEMS 24
4165 * Split the hairpin flow.
4166 * Since HW can't support encap and push-vlan on Rx, we move these
4168 * If the count action is after the encap then we also
4169 * move the count action. in this case the count will also measure
4173 * Pointer to Ethernet device.
4174 * @param[in] actions
4175 * Associated actions (list terminated by the END action).
4176 * @param[out] actions_rx
4178 * @param[out] actions_tx
4180 * @param[out] pattern_tx
4181 * The pattern items for the Tx flow.
4182 * @param[out] flow_id
4183 * The flow ID connected to this flow.
4189 flow_hairpin_split(struct rte_eth_dev *dev,
4190 const struct rte_flow_action actions[],
4191 struct rte_flow_action actions_rx[],
4192 struct rte_flow_action actions_tx[],
4193 struct rte_flow_item pattern_tx[],
4196 const struct rte_flow_action_raw_encap *raw_encap;
4197 const struct rte_flow_action_raw_decap *raw_decap;
4198 struct mlx5_rte_flow_action_set_tag *set_tag;
4199 struct rte_flow_action *tag_action;
4200 struct mlx5_rte_flow_item_tag *tag_item;
4201 struct rte_flow_item *item;
4205 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4206 switch (actions->type) {
4207 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4208 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4209 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4210 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4211 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4212 rte_memcpy(actions_tx, actions,
4213 sizeof(struct rte_flow_action));
4216 case RTE_FLOW_ACTION_TYPE_COUNT:
4218 rte_memcpy(actions_tx, actions,
4219 sizeof(struct rte_flow_action));
4222 rte_memcpy(actions_rx, actions,
4223 sizeof(struct rte_flow_action));
4227 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4228 raw_encap = actions->conf;
4229 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
4230 memcpy(actions_tx, actions,
4231 sizeof(struct rte_flow_action));
4235 rte_memcpy(actions_rx, actions,
4236 sizeof(struct rte_flow_action));
4240 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4241 raw_decap = actions->conf;
4242 if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
4243 memcpy(actions_tx, actions,
4244 sizeof(struct rte_flow_action));
4247 rte_memcpy(actions_rx, actions,
4248 sizeof(struct rte_flow_action));
4253 rte_memcpy(actions_rx, actions,
4254 sizeof(struct rte_flow_action));
4259 /* Add set meta action and end action for the Rx flow. */
4260 tag_action = actions_rx;
4261 tag_action->type = (enum rte_flow_action_type)
4262 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4264 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4266 set_tag = (void *)actions_rx;
4267 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
4268 MLX5_ASSERT(set_tag->id > REG_NON);
4269 set_tag->data = flow_id;
4270 tag_action->conf = set_tag;
4271 /* Create Tx item list. */
4272 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4273 addr = (void *)&pattern_tx[2];
4275 item->type = (enum rte_flow_item_type)
4276 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4277 tag_item = (void *)addr;
4278 tag_item->data = flow_id;
4279 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4280 MLX5_ASSERT(set_tag->id > REG_NON);
4281 item->spec = tag_item;
4282 addr += sizeof(struct mlx5_rte_flow_item_tag);
4283 tag_item = (void *)addr;
4284 tag_item->data = UINT32_MAX;
4285 tag_item->id = UINT16_MAX;
4286 item->mask = tag_item;
4289 item->type = RTE_FLOW_ITEM_TYPE_END;
4294 * The last stage of splitting chain, just creates the subflow
4295 * without any modification.
4298 * Pointer to Ethernet device.
4300 * Parent flow structure pointer.
4301 * @param[in, out] sub_flow
4302 * Pointer to return the created subflow, may be NULL.
4304 * Flow rule attributes.
4306 * Pattern specification (list terminated by the END pattern item).
4307 * @param[in] actions
4308 * Associated actions (list terminated by the END action).
4309 * @param[in] flow_split_info
4310 * Pointer to flow split info structure.
4312 * Perform verbose error reporting if not NULL.
4314 * 0 on success, negative value otherwise
4317 flow_create_split_inner(struct rte_eth_dev *dev,
4318 struct rte_flow *flow,
4319 struct mlx5_flow **sub_flow,
4320 const struct rte_flow_attr *attr,
4321 const struct rte_flow_item items[],
4322 const struct rte_flow_action actions[],
4323 struct mlx5_flow_split_info *flow_split_info,
4324 struct rte_flow_error *error)
4326 struct mlx5_flow *dev_flow;
4328 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4329 flow_split_info->flow_idx, error);
4332 dev_flow->flow = flow;
4333 dev_flow->external = flow_split_info->external;
4334 dev_flow->skip_scale = flow_split_info->skip_scale;
4335 /* Subflow object was created, we must include one in the list. */
4336 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4337 dev_flow->handle, next);
4339 * If dev_flow is as one of the suffix flow, some actions in suffix
4340 * flow may need some user defined item layer flags, and pass the
4341 * Metadate rxq mark flag to suffix flow as well.
4343 if (flow_split_info->prefix_layers)
4344 dev_flow->handle->layers = flow_split_info->prefix_layers;
4345 if (flow_split_info->prefix_mark)
4346 dev_flow->handle->mark = 1;
4348 *sub_flow = dev_flow;
4349 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4353 * Split the meter flow.
4355 * As meter flow will split to three sub flow, other than meter
4356 * action, the other actions make sense to only meter accepts
4357 * the packet. If it need to be dropped, no other additional
4358 * actions should be take.
4360 * One kind of special action which decapsulates the L3 tunnel
4361 * header will be in the prefix sub flow, as not to take the
4362 * L3 tunnel header into account.
4365 * Pointer to Ethernet device.
4367 * Pattern specification (list terminated by the END pattern item).
4368 * @param[out] sfx_items
4369 * Suffix flow match items (list terminated by the END pattern item).
4370 * @param[in] actions
4371 * Associated actions (list terminated by the END action).
4372 * @param[out] actions_sfx
4373 * Suffix flow actions.
4374 * @param[out] actions_pre
4375 * Prefix flow actions.
4376 * @param[out] pattern_sfx
4377 * The pattern items for the suffix flow.
4378 * @param[out] tag_sfx
4379 * Pointer to suffix flow tag.
4385 flow_meter_split_prep(struct rte_eth_dev *dev,
4386 const struct rte_flow_item items[],
4387 struct rte_flow_item sfx_items[],
4388 const struct rte_flow_action actions[],
4389 struct rte_flow_action actions_sfx[],
4390 struct rte_flow_action actions_pre[])
4392 struct mlx5_priv *priv = dev->data->dev_private;
4393 struct rte_flow_action *tag_action = NULL;
4394 struct rte_flow_item *tag_item;
4395 struct mlx5_rte_flow_action_set_tag *set_tag;
4396 struct rte_flow_error error;
4397 const struct rte_flow_action_raw_encap *raw_encap;
4398 const struct rte_flow_action_raw_decap *raw_decap;
4399 struct mlx5_rte_flow_item_tag *tag_spec;
4400 struct mlx5_rte_flow_item_tag *tag_mask;
4401 uint32_t tag_id = 0;
4402 bool copy_vlan = false;
4404 /* Prepare the actions for prefix and suffix flow. */
4405 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4406 struct rte_flow_action **action_cur = NULL;
4408 switch (actions->type) {
4409 case RTE_FLOW_ACTION_TYPE_METER:
4410 /* Add the extra tag action first. */
4411 tag_action = actions_pre;
4412 tag_action->type = (enum rte_flow_action_type)
4413 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4415 action_cur = &actions_pre;
4417 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4418 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4419 action_cur = &actions_pre;
4421 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4422 raw_encap = actions->conf;
4423 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4424 action_cur = &actions_pre;
4426 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4427 raw_decap = actions->conf;
4428 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4429 action_cur = &actions_pre;
4431 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4432 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4439 action_cur = &actions_sfx;
4440 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
4443 /* Add end action to the actions. */
4444 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4445 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4448 set_tag = (void *)actions_pre;
4449 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4450 mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
4452 if (tag_id >= (1 << (sizeof(tag_id) * 8 - MLX5_MTR_COLOR_BITS))) {
4453 DRV_LOG(ERR, "Port %u meter flow id exceed max limit.",
4454 dev->data->port_id);
4455 mlx5_ipool_free(priv->sh->ipool
4456 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], tag_id);
4458 } else if (!tag_id) {
4461 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
4463 tag_action->conf = set_tag;
4464 /* Prepare the suffix subflow items. */
4465 tag_item = sfx_items++;
4466 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4467 int item_type = items->type;
4469 switch (item_type) {
4470 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4471 memcpy(sfx_items, items, sizeof(*sfx_items));
4474 case RTE_FLOW_ITEM_TYPE_VLAN:
4476 memcpy(sfx_items, items, sizeof(*sfx_items));
4478 * Convert to internal match item, it is used
4479 * for vlan push and set vid.
4481 sfx_items->type = (enum rte_flow_item_type)
4482 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4490 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4492 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4493 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
4494 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4495 tag_mask = tag_spec + 1;
4496 tag_mask->data = 0xffffff00;
4497 tag_item->type = (enum rte_flow_item_type)
4498 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4499 tag_item->spec = tag_spec;
4500 tag_item->last = NULL;
4501 tag_item->mask = tag_mask;
4506 * Split action list having QUEUE/RSS for metadata register copy.
4508 * Once Q/RSS action is detected in user's action list, the flow action
4509 * should be split in order to copy metadata registers, which will happen in
4511 * - CQE->flow_tag := reg_c[1] (MARK)
4512 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4513 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
4514 * This is because the last action of each flow must be a terminal action
4515 * (QUEUE, RSS or DROP).
4517 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
4518 * stored and kept in the mlx5_flow structure per each sub_flow.
4520 * The Q/RSS action is replaced with,
4521 * - SET_TAG, setting the allocated flow ID to reg_c[2].
4522 * And the following JUMP action is added at the end,
4523 * - JUMP, to RX_CP_TBL.
4525 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
4526 * flow_create_split_metadata() routine. The flow will look like,
4527 * - If flow ID matches (reg_c[2]), perform Q/RSS.
4530 * Pointer to Ethernet device.
4531 * @param[out] split_actions
4532 * Pointer to store split actions to jump to CP_TBL.
4533 * @param[in] actions
4534 * Pointer to the list of original flow actions.
4536 * Pointer to the Q/RSS action.
4537 * @param[in] actions_n
4538 * Number of original actions.
4540 * Perform verbose error reporting if not NULL.
4543 * non-zero unique flow_id on success, otherwise 0 and
4544 * error/rte_error are set.
4547 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
4548 struct rte_flow_action *split_actions,
4549 const struct rte_flow_action *actions,
4550 const struct rte_flow_action *qrss,
4551 int actions_n, struct rte_flow_error *error)
4553 struct mlx5_priv *priv = dev->data->dev_private;
4554 struct mlx5_rte_flow_action_set_tag *set_tag;
4555 struct rte_flow_action_jump *jump;
4556 const int qrss_idx = qrss - actions;
4557 uint32_t flow_id = 0;
4561 * Given actions will be split
4562 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
4563 * - Add jump to mreg CP_TBL.
4564 * As a result, there will be one more action.
4567 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
4568 set_tag = (void *)(split_actions + actions_n);
4570 * If tag action is not set to void(it means we are not the meter
4571 * suffix flow), add the tag action. Since meter suffix flow already
4572 * has the tag added.
4574 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
4576 * Allocate the new subflow ID. This one is unique within
4577 * device and not shared with representors. Otherwise,
4578 * we would have to resolve multi-thread access synch
4579 * issue. Each flow on the shared device is appended
4580 * with source vport identifier, so the resulting
4581 * flows will be unique in the shared (by master and
4582 * representors) domain even if they have coinciding
4585 mlx5_ipool_malloc(priv->sh->ipool
4586 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
4588 return rte_flow_error_set(error, ENOMEM,
4589 RTE_FLOW_ERROR_TYPE_ACTION,
4590 NULL, "can't allocate id "
4591 "for split Q/RSS subflow");
4592 /* Internal SET_TAG action to set flow ID. */
4593 *set_tag = (struct mlx5_rte_flow_action_set_tag){
4596 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
4600 /* Construct new actions array. */
4601 /* Replace QUEUE/RSS action. */
4602 split_actions[qrss_idx] = (struct rte_flow_action){
4603 .type = (enum rte_flow_action_type)
4604 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4608 /* JUMP action to jump to mreg copy table (CP_TBL). */
4609 jump = (void *)(set_tag + 1);
4610 *jump = (struct rte_flow_action_jump){
4611 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4613 split_actions[actions_n - 2] = (struct rte_flow_action){
4614 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4617 split_actions[actions_n - 1] = (struct rte_flow_action){
4618 .type = RTE_FLOW_ACTION_TYPE_END,
4624 * Extend the given action list for Tx metadata copy.
4626 * Copy the given action list to the ext_actions and add flow metadata register
4627 * copy action in order to copy reg_a set by WQE to reg_c[0].
4629 * @param[out] ext_actions
4630 * Pointer to the extended action list.
4631 * @param[in] actions
4632 * Pointer to the list of actions.
4633 * @param[in] actions_n
4634 * Number of actions in the list.
4636 * Perform verbose error reporting if not NULL.
4637 * @param[in] encap_idx
4638 * The encap action inndex.
4641 * 0 on success, negative value otherwise
4644 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
4645 struct rte_flow_action *ext_actions,
4646 const struct rte_flow_action *actions,
4647 int actions_n, struct rte_flow_error *error,
4650 struct mlx5_flow_action_copy_mreg *cp_mreg =
4651 (struct mlx5_flow_action_copy_mreg *)
4652 (ext_actions + actions_n + 1);
4655 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4659 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
4664 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
4665 if (encap_idx == actions_n - 1) {
4666 ext_actions[actions_n - 1] = (struct rte_flow_action){
4667 .type = (enum rte_flow_action_type)
4668 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4671 ext_actions[actions_n] = (struct rte_flow_action){
4672 .type = RTE_FLOW_ACTION_TYPE_END,
4675 ext_actions[encap_idx] = (struct rte_flow_action){
4676 .type = (enum rte_flow_action_type)
4677 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4680 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
4681 sizeof(*ext_actions) * (actions_n - encap_idx));
4687 * Check the match action from the action list.
4689 * @param[in] actions
4690 * Pointer to the list of actions.
4692 * Flow rule attributes.
4694 * The action to be check if exist.
4695 * @param[out] match_action_pos
4696 * Pointer to the position of the matched action if exists, otherwise is -1.
4697 * @param[out] qrss_action_pos
4698 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
4699 * @param[out] modify_after_mirror
4700 * Pointer to the flag of modify action after FDB mirroring.
4703 * > 0 the total number of actions.
4704 * 0 if not found match action in action list.
4707 flow_check_match_action(const struct rte_flow_action actions[],
4708 const struct rte_flow_attr *attr,
4709 enum rte_flow_action_type action,
4710 int *match_action_pos, int *qrss_action_pos,
4711 int *modify_after_mirror)
4713 const struct rte_flow_action_sample *sample;
4720 *match_action_pos = -1;
4721 *qrss_action_pos = -1;
4722 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4723 if (actions->type == action) {
4725 *match_action_pos = actions_n;
4727 switch (actions->type) {
4728 case RTE_FLOW_ACTION_TYPE_QUEUE:
4729 case RTE_FLOW_ACTION_TYPE_RSS:
4730 *qrss_action_pos = actions_n;
4732 case RTE_FLOW_ACTION_TYPE_SAMPLE:
4733 sample = actions->conf;
4734 ratio = sample->ratio;
4735 sub_type = ((const struct rte_flow_action *)
4736 (sample->actions))->type;
4737 if (ratio == 1 && attr->transfer)
4740 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4741 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4742 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4743 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4744 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4745 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4746 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4747 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4748 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4749 case RTE_FLOW_ACTION_TYPE_SET_TTL:
4750 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4751 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4752 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4753 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4754 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4755 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
4756 case RTE_FLOW_ACTION_TYPE_FLAG:
4757 case RTE_FLOW_ACTION_TYPE_MARK:
4758 case RTE_FLOW_ACTION_TYPE_SET_META:
4759 case RTE_FLOW_ACTION_TYPE_SET_TAG:
4761 *modify_after_mirror = 1;
4768 if (flag && fdb_mirror && !*modify_after_mirror) {
4769 /* FDB mirroring uses the destination array to implement
4770 * instead of FLOW_SAMPLER object.
4772 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
4775 /* Count RTE_FLOW_ACTION_TYPE_END. */
4776 return flag ? actions_n + 1 : 0;
4779 #define SAMPLE_SUFFIX_ITEM 2
4782 * Split the sample flow.
4784 * As sample flow will split to two sub flow, sample flow with
4785 * sample action, the other actions will move to new suffix flow.
4787 * Also add unique tag id with tag action in the sample flow,
4788 * the same tag id will be as match in the suffix flow.
4791 * Pointer to Ethernet device.
4792 * @param[in] add_tag
4793 * Add extra tag action flag.
4794 * @param[out] sfx_items
4795 * Suffix flow match items (list terminated by the END pattern item).
4796 * @param[in] actions
4797 * Associated actions (list terminated by the END action).
4798 * @param[out] actions_sfx
4799 * Suffix flow actions.
4800 * @param[out] actions_pre
4801 * Prefix flow actions.
4802 * @param[in] actions_n
4803 * The total number of actions.
4804 * @param[in] sample_action_pos
4805 * The sample action position.
4806 * @param[in] qrss_action_pos
4807 * The Queue/RSS action position.
4808 * @param[in] jump_table
4809 * Add extra jump action flag.
4811 * Perform verbose error reporting if not NULL.
4814 * 0 on success, or unique flow_id, a negative errno value
4815 * otherwise and rte_errno is set.
4818 flow_sample_split_prep(struct rte_eth_dev *dev,
4820 struct rte_flow_item sfx_items[],
4821 const struct rte_flow_action actions[],
4822 struct rte_flow_action actions_sfx[],
4823 struct rte_flow_action actions_pre[],
4825 int sample_action_pos,
4826 int qrss_action_pos,
4828 struct rte_flow_error *error)
4830 struct mlx5_priv *priv = dev->data->dev_private;
4831 struct mlx5_rte_flow_action_set_tag *set_tag;
4832 struct mlx5_rte_flow_item_tag *tag_spec;
4833 struct mlx5_rte_flow_item_tag *tag_mask;
4834 struct rte_flow_action_jump *jump_action;
4835 uint32_t tag_id = 0;
4837 int append_index = 0;
4840 if (sample_action_pos < 0)
4841 return rte_flow_error_set(error, EINVAL,
4842 RTE_FLOW_ERROR_TYPE_ACTION,
4843 NULL, "invalid position of sample "
4845 /* Prepare the actions for prefix and suffix flow. */
4846 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
4847 index = qrss_action_pos;
4848 /* Put the preceding the Queue/RSS action into prefix flow. */
4850 memcpy(actions_pre, actions,
4851 sizeof(struct rte_flow_action) * index);
4852 /* Put others preceding the sample action into prefix flow. */
4853 if (sample_action_pos > index + 1)
4854 memcpy(actions_pre + index, actions + index + 1,
4855 sizeof(struct rte_flow_action) *
4856 (sample_action_pos - index - 1));
4857 index = sample_action_pos - 1;
4858 /* Put Queue/RSS action into Suffix flow. */
4859 memcpy(actions_sfx, actions + qrss_action_pos,
4860 sizeof(struct rte_flow_action));
4863 index = sample_action_pos;
4865 memcpy(actions_pre, actions,
4866 sizeof(struct rte_flow_action) * index);
4868 /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
4869 * For CX6DX and above, metadata registers Cx preserve their value,
4870 * add an extra tag action for NIC-RX and E-Switch Domain.
4873 /* Prepare the prefix tag action. */
4875 set_tag = (void *)(actions_pre + actions_n + append_index);
4876 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
4880 mlx5_ipool_malloc(priv->sh->ipool
4881 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
4882 set_tag->data = tag_id;
4883 /* Prepare the suffix subflow items. */
4884 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
4885 tag_spec->data = tag_id;
4886 tag_spec->id = set_tag->id;
4887 tag_mask = tag_spec + 1;
4888 tag_mask->data = UINT32_MAX;
4889 sfx_items[0] = (struct rte_flow_item){
4890 .type = (enum rte_flow_item_type)
4891 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4896 sfx_items[1] = (struct rte_flow_item){
4897 .type = (enum rte_flow_item_type)
4898 RTE_FLOW_ITEM_TYPE_END,
4900 /* Prepare the tag action in prefix subflow. */
4901 actions_pre[index++] =
4902 (struct rte_flow_action){
4903 .type = (enum rte_flow_action_type)
4904 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4908 memcpy(actions_pre + index, actions + sample_action_pos,
4909 sizeof(struct rte_flow_action));
4911 /* For the modify action after the sample action in E-Switch mirroring,
4912 * Add the extra jump action in prefix subflow and jump into the next
4913 * table, then do the modify action in the new table.
4916 /* Prepare the prefix jump action. */
4918 jump_action = (void *)(actions_pre + actions_n + append_index);
4919 jump_action->group = jump_table;
4920 actions_pre[index++] =
4921 (struct rte_flow_action){
4922 .type = (enum rte_flow_action_type)
4923 RTE_FLOW_ACTION_TYPE_JUMP,
4924 .conf = jump_action,
4927 actions_pre[index] = (struct rte_flow_action){
4928 .type = (enum rte_flow_action_type)
4929 RTE_FLOW_ACTION_TYPE_END,
4931 /* Put the actions after sample into Suffix flow. */
4932 memcpy(actions_sfx, actions + sample_action_pos + 1,
4933 sizeof(struct rte_flow_action) *
4934 (actions_n - sample_action_pos - 1));
4939 * The splitting for metadata feature.
4941 * - Q/RSS action on NIC Rx should be split in order to pass by
4942 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4943 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4945 * - All the actions on NIC Tx should have a mreg copy action to
4946 * copy reg_a from WQE to reg_c[0].
4949 * Pointer to Ethernet device.
4951 * Parent flow structure pointer.
4953 * Flow rule attributes.
4955 * Pattern specification (list terminated by the END pattern item).
4956 * @param[in] actions
4957 * Associated actions (list terminated by the END action).
4958 * @param[in] flow_split_info
4959 * Pointer to flow split info structure.
4961 * Perform verbose error reporting if not NULL.
4963 * 0 on success, negative value otherwise
4966 flow_create_split_metadata(struct rte_eth_dev *dev,
4967 struct rte_flow *flow,
4968 const struct rte_flow_attr *attr,
4969 const struct rte_flow_item items[],
4970 const struct rte_flow_action actions[],
4971 struct mlx5_flow_split_info *flow_split_info,
4972 struct rte_flow_error *error)
4974 struct mlx5_priv *priv = dev->data->dev_private;
4975 struct mlx5_dev_config *config = &priv->config;
4976 const struct rte_flow_action *qrss = NULL;
4977 struct rte_flow_action *ext_actions = NULL;
4978 struct mlx5_flow *dev_flow = NULL;
4979 uint32_t qrss_id = 0;
4986 /* Check whether extensive metadata feature is engaged. */
4987 if (!config->dv_flow_en ||
4988 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4989 !mlx5_flow_ext_mreg_supported(dev))
4990 return flow_create_split_inner(dev, flow, NULL, attr, items,
4991 actions, flow_split_info, error);
4992 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
4995 /* Exclude hairpin flows from splitting. */
4996 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
4997 const struct rte_flow_action_queue *queue;
5000 if (mlx5_rxq_get_type(dev, queue->index) ==
5001 MLX5_RXQ_TYPE_HAIRPIN)
5003 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
5004 const struct rte_flow_action_rss *rss;
5007 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
5008 MLX5_RXQ_TYPE_HAIRPIN)
5013 /* Check if it is in meter suffix table. */
5014 mtr_sfx = attr->group == (attr->transfer ?
5015 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
5016 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
5018 * Q/RSS action on NIC Rx should be split in order to pass by
5019 * the mreg copy table (RX_CP_TBL) and then it jumps to the
5020 * action table (RX_ACT_TBL) which has the split Q/RSS action.
5022 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5023 sizeof(struct rte_flow_action_set_tag) +
5024 sizeof(struct rte_flow_action_jump);
5025 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5028 return rte_flow_error_set(error, ENOMEM,
5029 RTE_FLOW_ERROR_TYPE_ACTION,
5030 NULL, "no memory to split "
5033 * If we are the suffix flow of meter, tag already exist.
5034 * Set the tag action to void.
5037 ext_actions[qrss - actions].type =
5038 RTE_FLOW_ACTION_TYPE_VOID;
5040 ext_actions[qrss - actions].type =
5041 (enum rte_flow_action_type)
5042 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5044 * Create the new actions list with removed Q/RSS action
5045 * and appended set tag and jump to register copy table
5046 * (RX_CP_TBL). We should preallocate unique tag ID here
5047 * in advance, because it is needed for set tag action.
5049 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
5050 qrss, actions_n, error);
5051 if (!mtr_sfx && !qrss_id) {
5055 } else if (attr->egress && !attr->transfer) {
5057 * All the actions on NIC Tx should have a metadata register
5058 * copy action to copy reg_a from WQE to reg_c[meta]
5060 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
5061 sizeof(struct mlx5_flow_action_copy_mreg);
5062 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
5065 return rte_flow_error_set(error, ENOMEM,
5066 RTE_FLOW_ERROR_TYPE_ACTION,
5067 NULL, "no memory to split "
5069 /* Create the action list appended with copy register. */
5070 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
5071 actions_n, error, encap_idx);
5075 /* Add the unmodified original or prefix subflow. */
5076 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5077 items, ext_actions ? ext_actions :
5078 actions, flow_split_info, error);
5081 MLX5_ASSERT(dev_flow);
5083 const struct rte_flow_attr q_attr = {
5084 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5087 /* Internal PMD action to set register. */
5088 struct mlx5_rte_flow_item_tag q_tag_spec = {
5092 struct rte_flow_item q_items[] = {
5094 .type = (enum rte_flow_item_type)
5095 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5096 .spec = &q_tag_spec,
5101 .type = RTE_FLOW_ITEM_TYPE_END,
5104 struct rte_flow_action q_actions[] = {
5110 .type = RTE_FLOW_ACTION_TYPE_END,
5113 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
5116 * Configure the tag item only if there is no meter subflow.
5117 * Since tag is already marked in the meter suffix subflow
5118 * we can just use the meter suffix items as is.
5121 /* Not meter subflow. */
5122 MLX5_ASSERT(!mtr_sfx);
5124 * Put unique id in prefix flow due to it is destroyed
5125 * after suffix flow and id will be freed after there
5126 * is no actual flows with this id and identifier
5127 * reallocation becomes possible (for example, for
5128 * other flows in other threads).
5130 dev_flow->handle->split_flow_id = qrss_id;
5131 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
5135 q_tag_spec.id = ret;
5138 /* Add suffix subflow to execute Q/RSS. */
5139 flow_split_info->prefix_layers = layers;
5140 flow_split_info->prefix_mark = 0;
5141 ret = flow_create_split_inner(dev, flow, &dev_flow,
5142 &q_attr, mtr_sfx ? items :
5144 flow_split_info, error);
5147 /* qrss ID should be freed if failed. */
5149 MLX5_ASSERT(dev_flow);
5154 * We do not destroy the partially created sub_flows in case of error.
5155 * These ones are included into parent flow list and will be destroyed
5156 * by flow_drv_destroy.
5158 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
5160 mlx5_free(ext_actions);
5165 * The splitting for meter feature.
5167 * - The meter flow will be split to two flows as prefix and
5168 * suffix flow. The packets make sense only it pass the prefix
5171 * - Reg_C_5 is used for the packet to match betweend prefix and
5175 * Pointer to Ethernet device.
5177 * Parent flow structure pointer.
5179 * Flow rule attributes.
5181 * Pattern specification (list terminated by the END pattern item).
5182 * @param[in] actions
5183 * Associated actions (list terminated by the END action).
5184 * @param[in] flow_split_info
5185 * Pointer to flow split info structure.
5187 * Perform verbose error reporting if not NULL.
5189 * 0 on success, negative value otherwise
5192 flow_create_split_meter(struct rte_eth_dev *dev,
5193 struct rte_flow *flow,
5194 const struct rte_flow_attr *attr,
5195 const struct rte_flow_item items[],
5196 const struct rte_flow_action actions[],
5197 struct mlx5_flow_split_info *flow_split_info,
5198 struct rte_flow_error *error)
5200 struct mlx5_priv *priv = dev->data->dev_private;
5201 struct rte_flow_action *sfx_actions = NULL;
5202 struct rte_flow_action *pre_actions = NULL;
5203 struct rte_flow_item *sfx_items = NULL;
5204 struct mlx5_flow *dev_flow = NULL;
5205 struct rte_flow_attr sfx_attr = *attr;
5207 uint32_t mtr_tag_id = 0;
5214 actions_n = flow_check_meter_action(actions, &mtr);
5216 /* The five prefix actions: meter, decap, encap, tag, end. */
5217 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
5218 sizeof(struct mlx5_rte_flow_action_set_tag);
5219 /* tag, vlan, port id, end. */
5220 #define METER_SUFFIX_ITEM 4
5221 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
5222 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5223 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
5226 return rte_flow_error_set(error, ENOMEM,
5227 RTE_FLOW_ERROR_TYPE_ACTION,
5228 NULL, "no memory to split "
5230 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
5232 pre_actions = sfx_actions + actions_n;
5233 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
5234 actions, sfx_actions,
5240 /* Add the prefix subflow. */
5241 flow_split_info->prefix_mark = 0;
5242 ret = flow_create_split_inner(dev, flow, &dev_flow,
5243 attr, items, pre_actions,
5244 flow_split_info, error);
5249 dev_flow->handle->split_flow_id = mtr_tag_id;
5250 /* Setting the sfx group atrr. */
5251 sfx_attr.group = sfx_attr.transfer ?
5252 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
5253 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
5254 flow_split_info->prefix_layers =
5255 flow_get_prefix_layer_flags(dev_flow);
5256 flow_split_info->prefix_mark = dev_flow->handle->mark;
5258 /* Add the prefix subflow. */
5259 ret = flow_create_split_metadata(dev, flow,
5260 &sfx_attr, sfx_items ?
5262 sfx_actions ? sfx_actions : actions,
5263 flow_split_info, error);
5266 mlx5_free(sfx_actions);
5271 * The splitting for sample feature.
5273 * Once Sample action is detected in the action list, the flow actions should
5274 * be split into prefix sub flow and suffix sub flow.
5276 * The original items remain in the prefix sub flow, all actions preceding the
5277 * sample action and the sample action itself will be copied to the prefix
5278 * sub flow, the actions following the sample action will be copied to the
5279 * suffix sub flow, Queue action always be located in the suffix sub flow.
5281 * In order to make the packet from prefix sub flow matches with suffix sub
5282 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
5283 * flow uses tag item with the unique flow id.
5286 * Pointer to Ethernet device.
5288 * Parent flow structure pointer.
5290 * Flow rule attributes.
5292 * Pattern specification (list terminated by the END pattern item).
5293 * @param[in] actions
5294 * Associated actions (list terminated by the END action).
5295 * @param[in] flow_split_info
5296 * Pointer to flow split info structure.
5298 * Perform verbose error reporting if not NULL.
5300 * 0 on success, negative value otherwise
5303 flow_create_split_sample(struct rte_eth_dev *dev,
5304 struct rte_flow *flow,
5305 const struct rte_flow_attr *attr,
5306 const struct rte_flow_item items[],
5307 const struct rte_flow_action actions[],
5308 struct mlx5_flow_split_info *flow_split_info,
5309 struct rte_flow_error *error)
5311 struct mlx5_priv *priv = dev->data->dev_private;
5312 struct rte_flow_action *sfx_actions = NULL;
5313 struct rte_flow_action *pre_actions = NULL;
5314 struct rte_flow_item *sfx_items = NULL;
5315 struct mlx5_flow *dev_flow = NULL;
5316 struct rte_flow_attr sfx_attr = *attr;
5317 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5318 struct mlx5_flow_dv_sample_resource *sample_res;
5319 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
5320 struct mlx5_flow_tbl_resource *sfx_tbl;
5324 uint32_t fdb_tx = 0;
5327 int sample_action_pos;
5328 int qrss_action_pos;
5330 int modify_after_mirror = 0;
5331 uint16_t jump_table = 0;
5332 const uint32_t next_ft_step = 1;
5335 if (priv->sampler_en)
5336 actions_n = flow_check_match_action(actions, attr,
5337 RTE_FLOW_ACTION_TYPE_SAMPLE,
5338 &sample_action_pos, &qrss_action_pos,
5339 &modify_after_mirror);
5341 /* The prefix actions must includes sample, tag, end. */
5342 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
5343 + sizeof(struct mlx5_rte_flow_action_set_tag);
5344 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
5345 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5346 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
5347 item_size), 0, SOCKET_ID_ANY);
5349 return rte_flow_error_set(error, ENOMEM,
5350 RTE_FLOW_ERROR_TYPE_ACTION,
5351 NULL, "no memory to split "
5353 /* The representor_id is -1 for uplink. */
5354 fdb_tx = (attr->transfer && priv->representor_id != -1);
5356 * When reg_c_preserve is set, metadata registers Cx preserve
5357 * their value even through packet duplication.
5359 add_tag = (!fdb_tx || priv->config.hca_attr.reg_c_preserve);
5361 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
5363 if (modify_after_mirror)
5364 jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
5366 pre_actions = sfx_actions + actions_n;
5367 tag_id = flow_sample_split_prep(dev, add_tag, sfx_items,
5368 actions, sfx_actions,
5369 pre_actions, actions_n,
5371 qrss_action_pos, jump_table,
5373 if (tag_id < 0 || (add_tag && !tag_id)) {
5377 if (modify_after_mirror)
5378 flow_split_info->skip_scale =
5379 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
5380 /* Add the prefix subflow. */
5381 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5383 flow_split_info, error);
5388 dev_flow->handle->split_flow_id = tag_id;
5389 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5390 if (!modify_after_mirror) {
5391 /* Set the sfx group attr. */
5392 sample_res = (struct mlx5_flow_dv_sample_resource *)
5393 dev_flow->dv.sample_res;
5394 sfx_tbl = (struct mlx5_flow_tbl_resource *)
5395 sample_res->normal_path_tbl;
5396 sfx_tbl_data = container_of(sfx_tbl,
5397 struct mlx5_flow_tbl_data_entry,
5399 sfx_attr.group = sfx_attr.transfer ?
5400 (sfx_tbl_data->table_id - 1) :
5401 sfx_tbl_data->table_id;
5403 MLX5_ASSERT(attr->transfer);
5404 sfx_attr.group = jump_table;
5406 flow_split_info->prefix_layers =
5407 flow_get_prefix_layer_flags(dev_flow);
5408 flow_split_info->prefix_mark = dev_flow->handle->mark;
5409 /* Suffix group level already be scaled with factor, set
5410 * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
5411 * again in translation.
5413 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
5416 /* Add the suffix subflow. */
5417 ret = flow_create_split_meter(dev, flow, &sfx_attr,
5418 sfx_items ? sfx_items : items,
5419 sfx_actions ? sfx_actions : actions,
5420 flow_split_info, error);
5423 mlx5_free(sfx_actions);
5428 * Split the flow to subflow set. The splitters might be linked
5429 * in the chain, like this:
5430 * flow_create_split_outer() calls:
5431 * flow_create_split_meter() calls:
5432 * flow_create_split_metadata(meter_subflow_0) calls:
5433 * flow_create_split_inner(metadata_subflow_0)
5434 * flow_create_split_inner(metadata_subflow_1)
5435 * flow_create_split_inner(metadata_subflow_2)
5436 * flow_create_split_metadata(meter_subflow_1) calls:
5437 * flow_create_split_inner(metadata_subflow_0)
5438 * flow_create_split_inner(metadata_subflow_1)
5439 * flow_create_split_inner(metadata_subflow_2)
5441 * This provide flexible way to add new levels of flow splitting.
5442 * The all of successfully created subflows are included to the
5443 * parent flow dev_flow list.
5446 * Pointer to Ethernet device.
5448 * Parent flow structure pointer.
5450 * Flow rule attributes.
5452 * Pattern specification (list terminated by the END pattern item).
5453 * @param[in] actions
5454 * Associated actions (list terminated by the END action).
5455 * @param[in] flow_split_info
5456 * Pointer to flow split info structure.
5458 * Perform verbose error reporting if not NULL.
5460 * 0 on success, negative value otherwise
5463 flow_create_split_outer(struct rte_eth_dev *dev,
5464 struct rte_flow *flow,
5465 const struct rte_flow_attr *attr,
5466 const struct rte_flow_item items[],
5467 const struct rte_flow_action actions[],
5468 struct mlx5_flow_split_info *flow_split_info,
5469 struct rte_flow_error *error)
5473 ret = flow_create_split_sample(dev, flow, attr, items,
5474 actions, flow_split_info, error);
5475 MLX5_ASSERT(ret <= 0);
5479 static struct mlx5_flow_tunnel *
5480 flow_tunnel_from_rule(struct rte_eth_dev *dev,
5481 const struct rte_flow_attr *attr,
5482 const struct rte_flow_item items[],
5483 const struct rte_flow_action actions[])
5485 struct mlx5_flow_tunnel *tunnel;
5487 #pragma GCC diagnostic push
5488 #pragma GCC diagnostic ignored "-Wcast-qual"
5489 if (is_flow_tunnel_match_rule(dev, attr, items, actions))
5490 tunnel = (struct mlx5_flow_tunnel *)items[0].spec;
5491 else if (is_flow_tunnel_steer_rule(dev, attr, items, actions))
5492 tunnel = (struct mlx5_flow_tunnel *)actions[0].conf;
5495 #pragma GCC diagnostic pop
5501 * Adjust flow RSS workspace if needed.
5504 * Pointer to thread flow work space.
5506 * Pointer to RSS descriptor.
5507 * @param[in] nrssq_num
5508 * New RSS queue number.
5511 * 0 on success, -1 otherwise and rte_errno is set.
5514 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
5515 struct mlx5_flow_rss_desc *rss_desc,
5518 if (likely(nrssq_num <= wks->rssq_num))
5520 rss_desc->queue = realloc(rss_desc->queue,
5521 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
5522 if (!rss_desc->queue) {
5526 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
5531 * Create a flow and add it to @p list.
5534 * Pointer to Ethernet device.
5536 * Pointer to a TAILQ flow list. If this parameter NULL,
5537 * no list insertion occurred, flow is just created,
5538 * this is caller's responsibility to track the
5541 * Flow rule attributes.
5543 * Pattern specification (list terminated by the END pattern item).
5544 * @param[in] actions
5545 * Associated actions (list terminated by the END action).
5546 * @param[in] external
5547 * This flow rule is created by request external to PMD.
5549 * Perform verbose error reporting if not NULL.
5552 * A flow index on success, 0 otherwise and rte_errno is set.
5555 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
5556 const struct rte_flow_attr *attr,
5557 const struct rte_flow_item items[],
5558 const struct rte_flow_action original_actions[],
5559 bool external, struct rte_flow_error *error)
5561 struct mlx5_priv *priv = dev->data->dev_private;
5562 struct rte_flow *flow = NULL;
5563 struct mlx5_flow *dev_flow;
5564 const struct rte_flow_action_rss *rss = NULL;
5565 struct mlx5_translated_shared_action
5566 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5567 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5569 struct mlx5_flow_expand_rss buf;
5570 uint8_t buffer[2048];
5573 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5574 uint8_t buffer[2048];
5577 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5578 uint8_t buffer[2048];
5579 } actions_hairpin_tx;
5581 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
5582 uint8_t buffer[2048];
5584 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
5585 struct mlx5_flow_rss_desc *rss_desc;
5586 const struct rte_flow_action *p_actions_rx;
5590 struct rte_flow_attr attr_tx = { .priority = 0 };
5591 const struct rte_flow_action *actions;
5592 struct rte_flow_action *translated_actions = NULL;
5593 struct mlx5_flow_tunnel *tunnel;
5594 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
5595 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
5596 struct mlx5_flow_split_info flow_split_info = {
5597 .external = !!external,
5606 rss_desc = &wks->rss_desc;
5607 ret = flow_shared_actions_translate(dev, original_actions,
5610 &translated_actions, error);
5612 MLX5_ASSERT(translated_actions == NULL);
5615 actions = translated_actions ? translated_actions : original_actions;
5616 p_actions_rx = actions;
5617 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5618 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
5619 external, hairpin_flow, error);
5621 goto error_before_hairpin_split;
5622 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
5625 goto error_before_hairpin_split;
5627 if (hairpin_flow > 0) {
5628 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
5630 goto error_before_hairpin_split;
5632 flow_hairpin_split(dev, actions, actions_rx.actions,
5633 actions_hairpin_tx.actions, items_tx.items,
5635 p_actions_rx = actions_rx.actions;
5637 flow_split_info.flow_idx = idx;
5638 flow->drv_type = flow_get_drv_type(dev, attr);
5639 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
5640 flow->drv_type < MLX5_FLOW_TYPE_MAX);
5641 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
5642 /* RSS Action only works on NIC RX domain */
5643 if (attr->ingress && !attr->transfer)
5644 rss = flow_get_rss_action(p_actions_rx);
5646 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
5649 * The following information is required by
5650 * mlx5_flow_hashfields_adjust() in advance.
5652 rss_desc->level = rss->level;
5653 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
5654 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
5656 flow->dev_handles = 0;
5657 if (rss && rss->types) {
5658 unsigned int graph_root;
5660 graph_root = find_graph_root(items, rss->level);
5661 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
5663 mlx5_support_expansion, graph_root);
5664 MLX5_ASSERT(ret > 0 &&
5665 (unsigned int)ret < sizeof(expand_buffer.buffer));
5668 buf->entry[0].pattern = (void *)(uintptr_t)items;
5670 rss_desc->shared_rss = flow_get_shared_rss_action(dev, shared_actions,
5672 for (i = 0; i < buf->entries; ++i) {
5673 /* Initialize flow split data. */
5674 flow_split_info.prefix_layers = 0;
5675 flow_split_info.prefix_mark = 0;
5676 flow_split_info.skip_scale = 0;
5678 * The splitter may create multiple dev_flows,
5679 * depending on configuration. In the simplest
5680 * case it just creates unmodified original flow.
5682 ret = flow_create_split_outer(dev, flow, attr,
5683 buf->entry[i].pattern,
5684 p_actions_rx, &flow_split_info,
5688 if (is_flow_tunnel_steer_rule(dev, attr,
5689 buf->entry[i].pattern,
5691 ret = flow_tunnel_add_default_miss(dev, flow, attr,
5697 mlx5_free(default_miss_ctx.queue);
5702 /* Create the tx flow. */
5704 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
5705 attr_tx.ingress = 0;
5707 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
5708 actions_hairpin_tx.actions,
5712 dev_flow->flow = flow;
5713 dev_flow->external = 0;
5714 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5715 dev_flow->handle, next);
5716 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
5718 actions_hairpin_tx.actions, error);
5723 * Update the metadata register copy table. If extensive
5724 * metadata feature is enabled and registers are supported
5725 * we might create the extra rte_flow for each unique
5726 * MARK/FLAG action ID.
5728 * The table is updated for ingress Flows only, because
5729 * the egress Flows belong to the different device and
5730 * copy table should be updated in peer NIC Rx domain.
5732 if (attr->ingress &&
5733 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
5734 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
5739 * If the flow is external (from application) OR device is started,
5740 * OR mreg discover, then apply immediately.
5742 if (external || dev->data->dev_started ||
5743 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
5744 attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
5745 ret = flow_drv_apply(dev, flow, error);
5750 rte_spinlock_lock(&priv->flow_list_lock);
5751 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
5753 rte_spinlock_unlock(&priv->flow_list_lock);
5755 flow_rxq_flags_set(dev, flow);
5756 rte_free(translated_actions);
5757 tunnel = flow_tunnel_from_rule(dev, attr, items, actions);
5760 flow->tunnel_id = tunnel->tunnel_id;
5761 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
5762 mlx5_free(default_miss_ctx.queue);
5764 mlx5_flow_pop_thread_workspace();
5768 ret = rte_errno; /* Save rte_errno before cleanup. */
5769 flow_mreg_del_copy_action(dev, flow);
5770 flow_drv_destroy(dev, flow);
5771 if (rss_desc->shared_rss)
5772 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
5774 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
5775 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
5776 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
5777 rte_errno = ret; /* Restore rte_errno. */
5780 mlx5_flow_pop_thread_workspace();
5781 error_before_hairpin_split:
5782 rte_free(translated_actions);
5787 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
5788 * incoming packets to table 1.
5790 * Other flow rules, requested for group n, will be created in
5791 * e-switch table n+1.
5792 * Jump action to e-switch group n will be created to group n+1.
5794 * Used when working in switchdev mode, to utilise advantages of table 1
5798 * Pointer to Ethernet device.
5801 * Pointer to flow on success, NULL otherwise and rte_errno is set.
5804 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
5806 const struct rte_flow_attr attr = {
5813 const struct rte_flow_item pattern = {
5814 .type = RTE_FLOW_ITEM_TYPE_END,
5816 struct rte_flow_action_jump jump = {
5819 const struct rte_flow_action actions[] = {
5821 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5825 .type = RTE_FLOW_ACTION_TYPE_END,
5828 struct mlx5_priv *priv = dev->data->dev_private;
5829 struct rte_flow_error error;
5831 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
5833 actions, false, &error);
5837 * Validate a flow supported by the NIC.
5839 * @see rte_flow_validate()
5843 mlx5_flow_validate(struct rte_eth_dev *dev,
5844 const struct rte_flow_attr *attr,
5845 const struct rte_flow_item items[],
5846 const struct rte_flow_action original_actions[],
5847 struct rte_flow_error *error)
5850 struct mlx5_translated_shared_action
5851 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5852 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5853 const struct rte_flow_action *actions;
5854 struct rte_flow_action *translated_actions = NULL;
5855 int ret = flow_shared_actions_translate(dev, original_actions,
5858 &translated_actions, error);
5862 actions = translated_actions ? translated_actions : original_actions;
5863 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5864 ret = flow_drv_validate(dev, attr, items, actions,
5865 true, hairpin_flow, error);
5866 rte_free(translated_actions);
5873 * @see rte_flow_create()
5877 mlx5_flow_create(struct rte_eth_dev *dev,
5878 const struct rte_flow_attr *attr,
5879 const struct rte_flow_item items[],
5880 const struct rte_flow_action actions[],
5881 struct rte_flow_error *error)
5883 struct mlx5_priv *priv = dev->data->dev_private;
5886 * If the device is not started yet, it is not allowed to created a
5887 * flow from application. PMD default flows and traffic control flows
5890 if (unlikely(!dev->data->dev_started)) {
5891 DRV_LOG(DEBUG, "port %u is not started when "
5892 "inserting a flow", dev->data->port_id);
5893 rte_flow_error_set(error, ENODEV,
5894 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5896 "port not started");
5900 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
5901 attr, items, actions, true, error);
5905 * Destroy a flow in a list.
5908 * Pointer to Ethernet device.
5910 * Pointer to the Indexed flow list. If this parameter NULL,
5911 * there is no flow removal from the list. Be noted that as
5912 * flow is add to the indexed list, memory of the indexed
5913 * list points to maybe changed as flow destroyed.
5914 * @param[in] flow_idx
5915 * Index of flow to destroy.
5918 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
5921 struct mlx5_priv *priv = dev->data->dev_private;
5922 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5923 [MLX5_IPOOL_RTE_FLOW], flow_idx);
5928 * Update RX queue flags only if port is started, otherwise it is
5931 if (dev->data->dev_started)
5932 flow_rxq_flags_trim(dev, flow);
5933 flow_drv_destroy(dev, flow);
5935 rte_spinlock_lock(&priv->flow_list_lock);
5936 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
5937 flow_idx, flow, next);
5938 rte_spinlock_unlock(&priv->flow_list_lock);
5941 struct mlx5_flow_tunnel *tunnel;
5943 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
5945 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
5946 mlx5_flow_tunnel_free(dev, tunnel);
5948 flow_mreg_del_copy_action(dev, flow);
5949 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5953 * Destroy all flows.
5956 * Pointer to Ethernet device.
5958 * Pointer to the Indexed flow list.
5960 * If flushing is called avtively.
5963 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
5965 uint32_t num_flushed = 0;
5968 flow_list_destroy(dev, list, *list);
5972 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
5973 dev->data->port_id, num_flushed);
5978 * Stop all default actions for flows.
5981 * Pointer to Ethernet device.
5984 mlx5_flow_stop_default(struct rte_eth_dev *dev)
5986 flow_mreg_del_default_copy_action(dev);
5987 flow_rxq_flags_clear(dev);
5991 * Start all default actions for flows.
5994 * Pointer to Ethernet device.
5996 * 0 on success, a negative errno value otherwise and rte_errno is set.
5999 mlx5_flow_start_default(struct rte_eth_dev *dev)
6001 struct rte_flow_error error;
6003 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
6004 return flow_mreg_add_default_copy_action(dev, &error);
6008 * Release key of thread specific flow workspace data.
6011 flow_release_workspace(void *data)
6013 struct mlx5_flow_workspace *wks = data;
6014 struct mlx5_flow_workspace *next;
6018 free(wks->rss_desc.queue);
6025 * Get thread specific current flow workspace.
6027 * @return pointer to thread specific flow workspace data, NULL on error.
6029 struct mlx5_flow_workspace*
6030 mlx5_flow_get_thread_workspace(void)
6032 struct mlx5_flow_workspace *data;
6034 data = mlx5_flow_os_get_specific_workspace();
6035 MLX5_ASSERT(data && data->inuse);
6036 if (!data || !data->inuse)
6037 DRV_LOG(ERR, "flow workspace not initialized.");
6042 * Allocate and init new flow workspace.
6044 * @return pointer to flow workspace data, NULL on error.
6046 static struct mlx5_flow_workspace*
6047 flow_alloc_thread_workspace(void)
6049 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
6052 DRV_LOG(ERR, "Failed to allocate flow workspace "
6056 data->rss_desc.queue = calloc(1,
6057 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
6058 if (!data->rss_desc.queue)
6060 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
6063 if (data->rss_desc.queue)
6064 free(data->rss_desc.queue);
6070 * Get new thread specific flow workspace.
6072 * If current workspace inuse, create new one and set as current.
6074 * @return pointer to thread specific flow workspace data, NULL on error.
6076 static struct mlx5_flow_workspace*
6077 mlx5_flow_push_thread_workspace(void)
6079 struct mlx5_flow_workspace *curr;
6080 struct mlx5_flow_workspace *data;
6082 curr = mlx5_flow_os_get_specific_workspace();
6084 data = flow_alloc_thread_workspace();
6087 } else if (!curr->inuse) {
6089 } else if (curr->next) {
6092 data = flow_alloc_thread_workspace();
6100 /* Set as current workspace */
6101 if (mlx5_flow_os_set_specific_workspace(data))
6102 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6107 * Close current thread specific flow workspace.
6109 * If previous workspace available, set it as current.
6111 * @return pointer to thread specific flow workspace data, NULL on error.
6114 mlx5_flow_pop_thread_workspace(void)
6116 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
6121 DRV_LOG(ERR, "Failed to close unused flow workspace.");
6127 if (mlx5_flow_os_set_specific_workspace(data->prev))
6128 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
6132 * Verify the flow list is empty
6135 * Pointer to Ethernet device.
6137 * @return the number of flows not released.
6140 mlx5_flow_verify(struct rte_eth_dev *dev)
6142 struct mlx5_priv *priv = dev->data->dev_private;
6143 struct rte_flow *flow;
6147 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
6149 DRV_LOG(DEBUG, "port %u flow %p still referenced",
6150 dev->data->port_id, (void *)flow);
6157 * Enable default hairpin egress flow.
6160 * Pointer to Ethernet device.
6165 * 0 on success, a negative errno value otherwise and rte_errno is set.
6168 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
6171 struct mlx5_priv *priv = dev->data->dev_private;
6172 const struct rte_flow_attr attr = {
6176 struct mlx5_rte_flow_item_tx_queue queue_spec = {
6179 struct mlx5_rte_flow_item_tx_queue queue_mask = {
6180 .queue = UINT32_MAX,
6182 struct rte_flow_item items[] = {
6184 .type = (enum rte_flow_item_type)
6185 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
6186 .spec = &queue_spec,
6188 .mask = &queue_mask,
6191 .type = RTE_FLOW_ITEM_TYPE_END,
6194 struct rte_flow_action_jump jump = {
6195 .group = MLX5_HAIRPIN_TX_TABLE,
6197 struct rte_flow_action actions[2];
6199 struct rte_flow_error error;
6201 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
6202 actions[0].conf = &jump;
6203 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
6204 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6205 &attr, items, actions, false, &error);
6208 "Failed to create ctrl flow: rte_errno(%d),"
6209 " type(%d), message(%s)",
6210 rte_errno, error.type,
6211 error.message ? error.message : " (no stated reason)");
6218 * Enable a control flow configured from the control plane.
6221 * Pointer to Ethernet device.
6223 * An Ethernet flow spec to apply.
6225 * An Ethernet flow mask to apply.
6227 * A VLAN flow spec to apply.
6229 * A VLAN flow mask to apply.
6232 * 0 on success, a negative errno value otherwise and rte_errno is set.
6235 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
6236 struct rte_flow_item_eth *eth_spec,
6237 struct rte_flow_item_eth *eth_mask,
6238 struct rte_flow_item_vlan *vlan_spec,
6239 struct rte_flow_item_vlan *vlan_mask)
6241 struct mlx5_priv *priv = dev->data->dev_private;
6242 const struct rte_flow_attr attr = {
6244 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
6246 struct rte_flow_item items[] = {
6248 .type = RTE_FLOW_ITEM_TYPE_ETH,
6254 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
6255 RTE_FLOW_ITEM_TYPE_END,
6261 .type = RTE_FLOW_ITEM_TYPE_END,
6264 uint16_t queue[priv->reta_idx_n];
6265 struct rte_flow_action_rss action_rss = {
6266 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6268 .types = priv->rss_conf.rss_hf,
6269 .key_len = priv->rss_conf.rss_key_len,
6270 .queue_num = priv->reta_idx_n,
6271 .key = priv->rss_conf.rss_key,
6274 struct rte_flow_action actions[] = {
6276 .type = RTE_FLOW_ACTION_TYPE_RSS,
6277 .conf = &action_rss,
6280 .type = RTE_FLOW_ACTION_TYPE_END,
6284 struct rte_flow_error error;
6287 if (!priv->reta_idx_n || !priv->rxqs_n) {
6290 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
6291 action_rss.types = 0;
6292 for (i = 0; i != priv->reta_idx_n; ++i)
6293 queue[i] = (*priv->reta_idx)[i];
6294 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6295 &attr, items, actions, false, &error);
6302 * Enable a flow control configured from the control plane.
6305 * Pointer to Ethernet device.
6307 * An Ethernet flow spec to apply.
6309 * An Ethernet flow mask to apply.
6312 * 0 on success, a negative errno value otherwise and rte_errno is set.
6315 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6316 struct rte_flow_item_eth *eth_spec,
6317 struct rte_flow_item_eth *eth_mask)
6319 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6323 * Create default miss flow rule matching lacp traffic
6326 * Pointer to Ethernet device.
6328 * An Ethernet flow spec to apply.
6331 * 0 on success, a negative errno value otherwise and rte_errno is set.
6334 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6336 struct mlx5_priv *priv = dev->data->dev_private;
6338 * The LACP matching is done by only using ether type since using
6339 * a multicast dst mac causes kernel to give low priority to this flow.
6341 static const struct rte_flow_item_eth lacp_spec = {
6342 .type = RTE_BE16(0x8809),
6344 static const struct rte_flow_item_eth lacp_mask = {
6347 const struct rte_flow_attr attr = {
6350 struct rte_flow_item items[] = {
6352 .type = RTE_FLOW_ITEM_TYPE_ETH,
6357 .type = RTE_FLOW_ITEM_TYPE_END,
6360 struct rte_flow_action actions[] = {
6362 .type = (enum rte_flow_action_type)
6363 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
6366 .type = RTE_FLOW_ACTION_TYPE_END,
6369 struct rte_flow_error error;
6370 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6371 &attr, items, actions, false, &error);
6381 * @see rte_flow_destroy()
6385 mlx5_flow_destroy(struct rte_eth_dev *dev,
6386 struct rte_flow *flow,
6387 struct rte_flow_error *error __rte_unused)
6389 struct mlx5_priv *priv = dev->data->dev_private;
6391 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
6396 * Destroy all flows.
6398 * @see rte_flow_flush()
6402 mlx5_flow_flush(struct rte_eth_dev *dev,
6403 struct rte_flow_error *error __rte_unused)
6405 struct mlx5_priv *priv = dev->data->dev_private;
6407 mlx5_flow_list_flush(dev, &priv->flows, false);
6414 * @see rte_flow_isolate()
6418 mlx5_flow_isolate(struct rte_eth_dev *dev,
6420 struct rte_flow_error *error)
6422 struct mlx5_priv *priv = dev->data->dev_private;
6424 if (dev->data->dev_started) {
6425 rte_flow_error_set(error, EBUSY,
6426 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6428 "port must be stopped first");
6431 priv->isolated = !!enable;
6433 dev->dev_ops = &mlx5_dev_ops_isolate;
6435 dev->dev_ops = &mlx5_dev_ops;
6437 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
6438 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
6446 * @see rte_flow_query()
6450 flow_drv_query(struct rte_eth_dev *dev,
6452 const struct rte_flow_action *actions,
6454 struct rte_flow_error *error)
6456 struct mlx5_priv *priv = dev->data->dev_private;
6457 const struct mlx5_flow_driver_ops *fops;
6458 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
6459 [MLX5_IPOOL_RTE_FLOW],
6461 enum mlx5_flow_drv_type ftype;
6464 return rte_flow_error_set(error, ENOENT,
6465 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6467 "invalid flow handle");
6469 ftype = flow->drv_type;
6470 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
6471 fops = flow_get_drv_ops(ftype);
6473 return fops->query(dev, flow, actions, data, error);
6479 * @see rte_flow_query()
6483 mlx5_flow_query(struct rte_eth_dev *dev,
6484 struct rte_flow *flow,
6485 const struct rte_flow_action *actions,
6487 struct rte_flow_error *error)
6491 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
6499 * Manage filter operations.
6502 * Pointer to Ethernet device structure.
6503 * @param filter_type
6506 * Operation to perform.
6508 * Pointer to operation-specific structure.
6511 * 0 on success, a negative errno value otherwise and rte_errno is set.
6514 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
6515 enum rte_filter_type filter_type,
6516 enum rte_filter_op filter_op,
6519 switch (filter_type) {
6520 case RTE_ETH_FILTER_GENERIC:
6521 if (filter_op != RTE_ETH_FILTER_GET) {
6525 *(const void **)arg = &mlx5_flow_ops;
6528 DRV_LOG(ERR, "port %u filter type (%d) not supported",
6529 dev->data->port_id, filter_type);
6530 rte_errno = ENOTSUP;
6537 * Create the needed meter and suffix tables.
6540 * Pointer to Ethernet device.
6542 * Pointer to the flow meter.
6545 * Pointer to table set on success, NULL otherwise.
6547 struct mlx5_meter_domains_infos *
6548 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
6549 const struct mlx5_flow_meter *fm)
6551 const struct mlx5_flow_driver_ops *fops;
6553 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6554 return fops->create_mtr_tbls(dev, fm);
6558 * Destroy the meter table set.
6561 * Pointer to Ethernet device.
6563 * Pointer to the meter table set.
6569 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
6570 struct mlx5_meter_domains_infos *tbls)
6572 const struct mlx5_flow_driver_ops *fops;
6574 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6575 return fops->destroy_mtr_tbls(dev, tbls);
6579 * Create policer rules.
6582 * Pointer to Ethernet device.
6584 * Pointer to flow meter structure.
6586 * Pointer to flow attributes.
6589 * 0 on success, -1 otherwise.
6592 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
6593 struct mlx5_flow_meter *fm,
6594 const struct rte_flow_attr *attr)
6596 const struct mlx5_flow_driver_ops *fops;
6598 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6599 return fops->create_policer_rules(dev, fm, attr);
6603 * Destroy policer rules.
6606 * Pointer to flow meter structure.
6608 * Pointer to flow attributes.
6611 * 0 on success, -1 otherwise.
6614 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
6615 struct mlx5_flow_meter *fm,
6616 const struct rte_flow_attr *attr)
6618 const struct mlx5_flow_driver_ops *fops;
6620 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6621 return fops->destroy_policer_rules(dev, fm, attr);
6625 * Allocate a counter.
6628 * Pointer to Ethernet device structure.
6631 * Index to allocated counter on success, 0 otherwise.
6634 mlx5_counter_alloc(struct rte_eth_dev *dev)
6636 const struct mlx5_flow_driver_ops *fops;
6637 struct rte_flow_attr attr = { .transfer = 0 };
6639 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6640 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6641 return fops->counter_alloc(dev);
6644 "port %u counter allocate is not supported.",
6645 dev->data->port_id);
6653 * Pointer to Ethernet device structure.
6655 * Index to counter to be free.
6658 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
6660 const struct mlx5_flow_driver_ops *fops;
6661 struct rte_flow_attr attr = { .transfer = 0 };
6663 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6664 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6665 fops->counter_free(dev, cnt);
6669 "port %u counter free is not supported.",
6670 dev->data->port_id);
6674 * Query counter statistics.
6677 * Pointer to Ethernet device structure.
6679 * Index to counter to query.
6681 * Set to clear counter statistics.
6683 * The counter hits packets number to save.
6685 * The counter hits bytes number to save.
6688 * 0 on success, a negative errno value otherwise.
6691 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
6692 bool clear, uint64_t *pkts, uint64_t *bytes)
6694 const struct mlx5_flow_driver_ops *fops;
6695 struct rte_flow_attr attr = { .transfer = 0 };
6697 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6698 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6699 return fops->counter_query(dev, cnt, clear, pkts, bytes);
6702 "port %u counter query is not supported.",
6703 dev->data->port_id);
6708 * Allocate a new memory for the counter values wrapped by all the needed
6712 * Pointer to mlx5_dev_ctx_shared object.
6715 * 0 on success, a negative errno value otherwise.
6718 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
6720 struct mlx5_devx_mkey_attr mkey_attr;
6721 struct mlx5_counter_stats_mem_mng *mem_mng;
6722 volatile struct flow_counter_stats *raw_data;
6723 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
6724 int size = (sizeof(struct flow_counter_stats) *
6725 MLX5_COUNTERS_PER_POOL +
6726 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
6727 sizeof(struct mlx5_counter_stats_mem_mng);
6728 size_t pgsize = rte_mem_page_size();
6732 if (pgsize == (size_t)-1) {
6733 DRV_LOG(ERR, "Failed to get mem page size");
6737 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
6742 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
6743 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
6744 mem_mng->umem = mlx5_os_umem_reg(sh->ctx, mem, size,
6745 IBV_ACCESS_LOCAL_WRITE);
6746 if (!mem_mng->umem) {
6751 mkey_attr.addr = (uintptr_t)mem;
6752 mkey_attr.size = size;
6753 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
6754 mkey_attr.pd = sh->pdn;
6755 mkey_attr.log_entity_size = 0;
6756 mkey_attr.pg_access = 0;
6757 mkey_attr.klm_array = NULL;
6758 mkey_attr.klm_num = 0;
6759 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
6760 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
6761 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
6763 mlx5_os_umem_dereg(mem_mng->umem);
6768 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
6769 raw_data = (volatile struct flow_counter_stats *)mem;
6770 for (i = 0; i < raws_n; ++i) {
6771 mem_mng->raws[i].mem_mng = mem_mng;
6772 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
6774 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
6775 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
6776 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
6778 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
6779 sh->cmng.mem_mng = mem_mng;
6784 * Set the statistic memory to the new counter pool.
6787 * Pointer to mlx5_dev_ctx_shared object.
6789 * Pointer to the pool to set the statistic memory.
6792 * 0 on success, a negative errno value otherwise.
6795 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
6796 struct mlx5_flow_counter_pool *pool)
6798 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6799 /* Resize statistic memory once used out. */
6800 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
6801 mlx5_flow_create_counter_stat_mem_mng(sh)) {
6802 DRV_LOG(ERR, "Cannot resize counter stat mem.");
6805 rte_spinlock_lock(&pool->sl);
6806 pool->raw = cmng->mem_mng->raws + pool->index %
6807 MLX5_CNT_CONTAINER_RESIZE;
6808 rte_spinlock_unlock(&pool->sl);
6809 pool->raw_hw = NULL;
6813 #define MLX5_POOL_QUERY_FREQ_US 1000000
6816 * Set the periodic procedure for triggering asynchronous batch queries for all
6817 * the counter pools.
6820 * Pointer to mlx5_dev_ctx_shared object.
6823 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
6825 uint32_t pools_n, us;
6827 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
6828 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
6829 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
6830 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
6831 sh->cmng.query_thread_on = 0;
6832 DRV_LOG(ERR, "Cannot reinitialize query alarm");
6834 sh->cmng.query_thread_on = 1;
6839 * The periodic procedure for triggering asynchronous batch queries for all the
6840 * counter pools. This function is probably called by the host thread.
6843 * The parameter for the alarm process.
6846 mlx5_flow_query_alarm(void *arg)
6848 struct mlx5_dev_ctx_shared *sh = arg;
6850 uint16_t pool_index = sh->cmng.pool_index;
6851 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6852 struct mlx5_flow_counter_pool *pool;
6855 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
6857 rte_spinlock_lock(&cmng->pool_update_sl);
6858 pool = cmng->pools[pool_index];
6859 n_valid = cmng->n_valid;
6860 rte_spinlock_unlock(&cmng->pool_update_sl);
6861 /* Set the statistic memory to the new created pool. */
6862 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
6865 /* There is a pool query in progress. */
6868 LIST_FIRST(&sh->cmng.free_stat_raws);
6870 /* No free counter statistics raw memory. */
6873 * Identify the counters released between query trigger and query
6874 * handle more efficiently. The counter released in this gap period
6875 * should wait for a new round of query as the new arrived packets
6876 * will not be taken into account.
6879 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
6880 MLX5_COUNTERS_PER_POOL,
6882 pool->raw_hw->mem_mng->dm->id,
6886 (uint64_t)(uintptr_t)pool);
6888 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
6889 " %d", pool->min_dcs->id);
6890 pool->raw_hw = NULL;
6893 LIST_REMOVE(pool->raw_hw, next);
6894 sh->cmng.pending_queries++;
6896 if (pool_index >= n_valid)
6899 sh->cmng.pool_index = pool_index;
6900 mlx5_set_query_alarm(sh);
6904 * Check and callback event for new aged flow in the counter pool
6907 * Pointer to mlx5_dev_ctx_shared object.
6909 * Pointer to Current counter pool.
6912 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
6913 struct mlx5_flow_counter_pool *pool)
6915 struct mlx5_priv *priv;
6916 struct mlx5_flow_counter *cnt;
6917 struct mlx5_age_info *age_info;
6918 struct mlx5_age_param *age_param;
6919 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
6920 struct mlx5_counter_stats_raw *prev = pool->raw;
6921 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
6922 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
6923 uint16_t expected = AGE_CANDIDATE;
6926 pool->time_of_last_age_check = curr_time;
6927 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
6928 cnt = MLX5_POOL_GET_CNT(pool, i);
6929 age_param = MLX5_CNT_TO_AGE(cnt);
6930 if (__atomic_load_n(&age_param->state,
6931 __ATOMIC_RELAXED) != AGE_CANDIDATE)
6933 if (cur->data[i].hits != prev->data[i].hits) {
6934 __atomic_store_n(&age_param->sec_since_last_hit, 0,
6938 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
6940 __ATOMIC_RELAXED) <= age_param->timeout)
6943 * Hold the lock first, or if between the
6944 * state AGE_TMOUT and tailq operation the
6945 * release happened, the release procedure
6946 * may delete a non-existent tailq node.
6948 priv = rte_eth_devices[age_param->port_id].data->dev_private;
6949 age_info = GET_PORT_AGE_INFO(priv);
6950 rte_spinlock_lock(&age_info->aged_sl);
6951 if (__atomic_compare_exchange_n(&age_param->state, &expected,
6954 __ATOMIC_RELAXED)) {
6955 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
6956 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
6958 rte_spinlock_unlock(&age_info->aged_sl);
6960 mlx5_age_event_prepare(sh);
6964 * Handler for the HW respond about ready values from an asynchronous batch
6965 * query. This function is probably called by the host thread.
6968 * The pointer to the shared device context.
6969 * @param[in] async_id
6970 * The Devx async ID.
6972 * The status of the completion.
6975 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
6976 uint64_t async_id, int status)
6978 struct mlx5_flow_counter_pool *pool =
6979 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
6980 struct mlx5_counter_stats_raw *raw_to_free;
6981 uint8_t query_gen = pool->query_gen ^ 1;
6982 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6983 enum mlx5_counter_type cnt_type =
6984 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6985 MLX5_COUNTER_TYPE_ORIGIN;
6987 if (unlikely(status)) {
6988 raw_to_free = pool->raw_hw;
6990 raw_to_free = pool->raw;
6992 mlx5_flow_aging_check(sh, pool);
6993 rte_spinlock_lock(&pool->sl);
6994 pool->raw = pool->raw_hw;
6995 rte_spinlock_unlock(&pool->sl);
6996 /* Be sure the new raw counters data is updated in memory. */
6998 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
6999 rte_spinlock_lock(&cmng->csl[cnt_type]);
7000 TAILQ_CONCAT(&cmng->counters[cnt_type],
7001 &pool->counters[query_gen], next);
7002 rte_spinlock_unlock(&cmng->csl[cnt_type]);
7005 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
7006 pool->raw_hw = NULL;
7007 sh->cmng.pending_queries--;
7011 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
7012 const struct flow_grp_info *grp_info,
7013 struct rte_flow_error *error)
7015 if (grp_info->transfer && grp_info->external &&
7016 grp_info->fdb_def_rule) {
7017 if (group == UINT32_MAX)
7018 return rte_flow_error_set
7020 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7022 "group index not supported");
7027 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
7032 * Translate the rte_flow group index to HW table value.
7034 * If tunnel offload is disabled, all group ids converted to flow table
7035 * id using the standard method.
7036 * If tunnel offload is enabled, group id can be converted using the
7037 * standard or tunnel conversion method. Group conversion method
7038 * selection depends on flags in `grp_info` parameter:
7039 * - Internal (grp_info.external == 0) groups conversion uses the
7041 * - Group ids in JUMP action converted with the tunnel conversion.
7042 * - Group id in rule attribute conversion depends on a rule type and
7044 * ** non zero group attributes converted with the tunnel method
7045 * ** zero group attribute in non-tunnel rule is converted using the
7046 * standard method - there's only one root table
7047 * ** zero group attribute in steer tunnel rule is converted with the
7048 * standard method - single root table
7049 * ** zero group attribute in match tunnel rule is a special OvS
7050 * case: that value is used for portability reasons. That group
7051 * id is converted with the tunnel conversion method.
7056 * PMD tunnel offload object
7058 * rte_flow group index value.
7061 * @param[in] grp_info
7062 * flags used for conversion
7064 * Pointer to error structure.
7067 * 0 on success, a negative errno value otherwise and rte_errno is set.
7070 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
7071 const struct mlx5_flow_tunnel *tunnel,
7072 uint32_t group, uint32_t *table,
7073 const struct flow_grp_info *grp_info,
7074 struct rte_flow_error *error)
7077 bool standard_translation;
7079 if (!grp_info->skip_scale && grp_info->external &&
7080 group < MLX5_MAX_TABLES_EXTERNAL)
7081 group *= MLX5_FLOW_TABLE_FACTOR;
7082 if (is_tunnel_offload_active(dev)) {
7083 standard_translation = !grp_info->external ||
7084 grp_info->std_tbl_fix;
7086 standard_translation = true;
7089 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
7090 dev->data->port_id, group, grp_info->transfer,
7091 grp_info->external, grp_info->fdb_def_rule,
7092 standard_translation ? "STANDARD" : "TUNNEL");
7093 if (standard_translation)
7094 ret = flow_group_to_table(dev->data->port_id, group, table,
7097 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
7104 * Discover availability of metadata reg_c's.
7106 * Iteratively use test flows to check availability.
7109 * Pointer to the Ethernet device structure.
7112 * 0 on success, a negative errno value otherwise and rte_errno is set.
7115 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
7117 struct mlx5_priv *priv = dev->data->dev_private;
7118 struct mlx5_dev_config *config = &priv->config;
7119 enum modify_reg idx;
7122 /* reg_c[0] and reg_c[1] are reserved. */
7123 config->flow_mreg_c[n++] = REG_C_0;
7124 config->flow_mreg_c[n++] = REG_C_1;
7125 /* Discover availability of other reg_c's. */
7126 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
7127 struct rte_flow_attr attr = {
7128 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
7129 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7132 struct rte_flow_item items[] = {
7134 .type = RTE_FLOW_ITEM_TYPE_END,
7137 struct rte_flow_action actions[] = {
7139 .type = (enum rte_flow_action_type)
7140 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
7141 .conf = &(struct mlx5_flow_action_copy_mreg){
7147 .type = RTE_FLOW_ACTION_TYPE_JUMP,
7148 .conf = &(struct rte_flow_action_jump){
7149 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
7153 .type = RTE_FLOW_ACTION_TYPE_END,
7157 struct rte_flow *flow;
7158 struct rte_flow_error error;
7160 if (!config->dv_flow_en)
7162 /* Create internal flow, validation skips copy action. */
7163 flow_idx = flow_list_create(dev, NULL, &attr, items,
7164 actions, false, &error);
7165 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
7169 config->flow_mreg_c[n++] = idx;
7170 flow_list_destroy(dev, NULL, flow_idx);
7172 for (; n < MLX5_MREG_C_NUM; ++n)
7173 config->flow_mreg_c[n] = REG_NON;
7178 * Dump flow raw hw data to file
7181 * The pointer to Ethernet device.
7183 * A pointer to a file for output.
7185 * Perform verbose error reporting if not NULL. PMDs initialize this
7186 * structure in case of error only.
7188 * 0 on success, a nagative value otherwise.
7191 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
7193 struct rte_flow_error *error __rte_unused)
7195 struct mlx5_priv *priv = dev->data->dev_private;
7196 struct mlx5_dev_ctx_shared *sh = priv->sh;
7198 if (!priv->config.dv_flow_en) {
7199 if (fputs("device dv flow disabled\n", file) <= 0)
7203 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
7204 sh->tx_domain, file);
7208 * Get aged-out flows.
7211 * Pointer to the Ethernet device structure.
7212 * @param[in] context
7213 * The address of an array of pointers to the aged-out flows contexts.
7214 * @param[in] nb_countexts
7215 * The length of context array pointers.
7217 * Perform verbose error reporting if not NULL. Initialized in case of
7221 * how many contexts get in success, otherwise negative errno value.
7222 * if nb_contexts is 0, return the amount of all aged contexts.
7223 * if nb_contexts is not 0 , return the amount of aged flows reported
7224 * in the context array.
7227 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
7228 uint32_t nb_contexts, struct rte_flow_error *error)
7230 const struct mlx5_flow_driver_ops *fops;
7231 struct rte_flow_attr attr = { .transfer = 0 };
7233 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7234 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7235 return fops->get_aged_flows(dev, contexts, nb_contexts,
7239 "port %u get aged flows is not supported.",
7240 dev->data->port_id);
7244 /* Wrapper for driver action_validate op callback */
7246 flow_drv_action_validate(struct rte_eth_dev *dev,
7247 const struct rte_flow_shared_action_conf *conf,
7248 const struct rte_flow_action *action,
7249 const struct mlx5_flow_driver_ops *fops,
7250 struct rte_flow_error *error)
7252 static const char err_msg[] = "shared action validation unsupported";
7254 if (!fops->action_validate) {
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_validate(dev, conf, action, error);
7264 * Destroys the shared action by handle.
7267 * Pointer to Ethernet device structure.
7269 * Handle for the shared action to be destroyed.
7271 * Perform verbose error reporting if not NULL. PMDs initialize this
7272 * structure in case of error only.
7275 * 0 on success, a negative errno value otherwise and rte_errno is set.
7277 * @note: wrapper for driver action_create op callback.
7280 mlx5_shared_action_destroy(struct rte_eth_dev *dev,
7281 struct rte_flow_shared_action *action,
7282 struct rte_flow_error *error)
7284 static const char err_msg[] = "shared action destruction unsupported";
7285 struct rte_flow_attr attr = { .transfer = 0 };
7286 const struct mlx5_flow_driver_ops *fops =
7287 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7289 if (!fops->action_destroy) {
7290 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7291 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7295 return fops->action_destroy(dev, action, error);
7298 /* Wrapper for driver action_destroy op callback */
7300 flow_drv_action_update(struct rte_eth_dev *dev,
7301 struct rte_flow_shared_action *action,
7302 const void *action_conf,
7303 const struct mlx5_flow_driver_ops *fops,
7304 struct rte_flow_error *error)
7306 static const char err_msg[] = "shared action update unsupported";
7308 if (!fops->action_update) {
7309 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7310 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7314 return fops->action_update(dev, action, action_conf, error);
7317 /* Wrapper for driver action_destroy op callback */
7319 flow_drv_action_query(struct rte_eth_dev *dev,
7320 const struct rte_flow_shared_action *action,
7322 const struct mlx5_flow_driver_ops *fops,
7323 struct rte_flow_error *error)
7325 static const char err_msg[] = "shared action query unsupported";
7327 if (!fops->action_query) {
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_query(dev, action, data, error);
7337 * Create shared action for reuse in multiple flow rules.
7340 * Pointer to Ethernet device structure.
7342 * Action configuration for shared action creation.
7344 * Perform verbose error reporting if not NULL. PMDs initialize this
7345 * structure in case of error only.
7347 * A valid handle in case of success, NULL otherwise and rte_errno is set.
7349 static struct rte_flow_shared_action *
7350 mlx5_shared_action_create(struct rte_eth_dev *dev,
7351 const struct rte_flow_shared_action_conf *conf,
7352 const struct rte_flow_action *action,
7353 struct rte_flow_error *error)
7355 static const char err_msg[] = "shared action creation unsupported";
7356 struct rte_flow_attr attr = { .transfer = 0 };
7357 const struct mlx5_flow_driver_ops *fops =
7358 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7360 if (flow_drv_action_validate(dev, conf, action, fops, error))
7362 if (!fops->action_create) {
7363 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7364 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7368 return fops->action_create(dev, conf, action, error);
7372 * Updates inplace the shared action configuration pointed by *action* handle
7373 * with the configuration provided as *action* argument.
7374 * The update of the shared action configuration effects all flow rules reusing
7375 * the action via handle.
7378 * Pointer to Ethernet device structure.
7379 * @param[in] shared_action
7380 * Handle for the shared action to be updated.
7382 * Action specification used to modify the action pointed by handle.
7383 * *action* should be of same type with the action pointed by the *action*
7384 * handle argument, otherwise considered as invalid.
7386 * Perform verbose error reporting if not NULL. PMDs initialize this
7387 * structure in case of error only.
7390 * 0 on success, a negative errno value otherwise and rte_errno is set.
7393 mlx5_shared_action_update(struct rte_eth_dev *dev,
7394 struct rte_flow_shared_action *shared_action,
7395 const struct rte_flow_action *action,
7396 struct rte_flow_error *error)
7398 struct rte_flow_attr attr = { .transfer = 0 };
7399 const struct mlx5_flow_driver_ops *fops =
7400 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7403 ret = flow_drv_action_validate(dev, NULL, action, fops, error);
7406 return flow_drv_action_update(dev, shared_action, action->conf, fops,
7411 * Query the shared action by handle.
7413 * This function allows retrieving action-specific data such as counters.
7414 * Data is gathered by special action which may be present/referenced in
7415 * more than one flow rule definition.
7417 * \see RTE_FLOW_ACTION_TYPE_COUNT
7420 * Pointer to Ethernet device structure.
7422 * Handle for the shared action to query.
7423 * @param[in, out] data
7424 * Pointer to storage for the associated query data type.
7426 * Perform verbose error reporting if not NULL. PMDs initialize this
7427 * structure in case of error only.
7430 * 0 on success, a negative errno value otherwise and rte_errno is set.
7433 mlx5_shared_action_query(struct rte_eth_dev *dev,
7434 const struct rte_flow_shared_action *action,
7436 struct rte_flow_error *error)
7438 struct rte_flow_attr attr = { .transfer = 0 };
7439 const struct mlx5_flow_driver_ops *fops =
7440 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7442 return flow_drv_action_query(dev, action, data, fops, error);
7446 * Destroy all shared actions.
7449 * Pointer to Ethernet device.
7452 * 0 on success, a negative errno value otherwise and rte_errno is set.
7455 mlx5_shared_action_flush(struct rte_eth_dev *dev)
7457 struct rte_flow_error error;
7458 struct mlx5_priv *priv = dev->data->dev_private;
7459 struct mlx5_shared_action_rss *shared_rss;
7463 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
7464 priv->rss_shared_actions, idx, shared_rss, next) {
7465 ret |= mlx5_shared_action_destroy(dev,
7466 (struct rte_flow_shared_action *)(uintptr_t)idx, &error);
7471 #ifndef HAVE_MLX5DV_DR
7472 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
7474 #define MLX5_DOMAIN_SYNC_FLOW \
7475 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
7478 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
7480 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
7481 const struct mlx5_flow_driver_ops *fops;
7483 struct rte_flow_attr attr = { .transfer = 0 };
7485 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7486 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
7493 * tunnel offload functionalilty is defined for DV environment only
7495 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7497 union tunnel_offload_mark {
7500 uint32_t app_reserve:8;
7501 uint32_t table_id:15;
7502 uint32_t transfer:1;
7503 uint32_t _unused_:8;
7508 mlx5_access_tunnel_offload_db
7509 (struct rte_eth_dev *dev,
7510 bool (*match)(struct rte_eth_dev *,
7511 struct mlx5_flow_tunnel *, const void *),
7512 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
7513 void (*miss)(struct rte_eth_dev *, void *),
7514 void *ctx, bool lock_op);
7517 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
7518 struct rte_flow *flow,
7519 const struct rte_flow_attr *attr,
7520 const struct rte_flow_action *app_actions,
7522 struct tunnel_default_miss_ctx *ctx,
7523 struct rte_flow_error *error)
7525 struct mlx5_priv *priv = dev->data->dev_private;
7526 struct mlx5_flow *dev_flow;
7527 struct rte_flow_attr miss_attr = *attr;
7528 const struct mlx5_flow_tunnel *tunnel = app_actions[0].conf;
7529 const struct rte_flow_item miss_items[2] = {
7531 .type = RTE_FLOW_ITEM_TYPE_ETH,
7537 .type = RTE_FLOW_ITEM_TYPE_END,
7543 union tunnel_offload_mark mark_id;
7544 struct rte_flow_action_mark miss_mark;
7545 struct rte_flow_action miss_actions[3] = {
7546 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
7547 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
7549 const struct rte_flow_action_jump *jump_data;
7550 uint32_t i, flow_table = 0; /* prevent compilation warning */
7551 struct flow_grp_info grp_info = {
7553 .transfer = attr->transfer,
7554 .fdb_def_rule = !!priv->fdb_def_rule,
7559 if (!attr->transfer) {
7562 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
7563 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
7564 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
7567 return rte_flow_error_set
7569 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
7570 NULL, "invalid default miss RSS");
7571 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
7572 ctx->action_rss.level = 0,
7573 ctx->action_rss.types = priv->rss_conf.rss_hf,
7574 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
7575 ctx->action_rss.queue_num = priv->reta_idx_n,
7576 ctx->action_rss.key = priv->rss_conf.rss_key,
7577 ctx->action_rss.queue = ctx->queue;
7578 if (!priv->reta_idx_n || !priv->rxqs_n)
7579 return rte_flow_error_set
7581 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
7582 NULL, "invalid port configuration");
7583 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
7584 ctx->action_rss.types = 0;
7585 for (i = 0; i != priv->reta_idx_n; ++i)
7586 ctx->queue[i] = (*priv->reta_idx)[i];
7588 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
7589 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
7591 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
7592 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
7593 jump_data = app_actions->conf;
7594 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
7595 miss_attr.group = jump_data->group;
7596 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
7597 &flow_table, &grp_info, error);
7599 return rte_flow_error_set(error, EINVAL,
7600 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
7601 NULL, "invalid tunnel id");
7602 mark_id.app_reserve = 0;
7603 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
7604 mark_id.transfer = !!attr->transfer;
7605 mark_id._unused_ = 0;
7606 miss_mark.id = mark_id.val;
7607 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
7608 miss_items, miss_actions, flow_idx, error);
7611 dev_flow->flow = flow;
7612 dev_flow->external = true;
7613 dev_flow->tunnel = tunnel;
7614 /* Subflow object was created, we must include one in the list. */
7615 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
7616 dev_flow->handle, next);
7618 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
7619 dev->data->port_id, tunnel->app_tunnel.type,
7620 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
7621 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
7622 miss_actions, error);
7624 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
7630 static const struct mlx5_flow_tbl_data_entry *
7631 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
7633 struct mlx5_priv *priv = dev->data->dev_private;
7634 struct mlx5_dev_ctx_shared *sh = priv->sh;
7635 struct mlx5_hlist_entry *he;
7636 union tunnel_offload_mark mbits = { .val = mark };
7637 union mlx5_flow_tbl_key table_key = {
7639 .table_id = tunnel_id_to_flow_tbl(mbits.table_id),
7641 .domain = !!mbits.transfer,
7645 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, NULL);
7647 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
7651 mlx5_flow_tunnel_grp2tbl_remove_cb(struct mlx5_hlist *list,
7652 struct mlx5_hlist_entry *entry)
7654 struct mlx5_dev_ctx_shared *sh = list->ctx;
7655 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
7657 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
7658 tunnel_flow_tbl_to_id(tte->flow_table));
7663 mlx5_flow_tunnel_grp2tbl_match_cb(struct mlx5_hlist *list __rte_unused,
7664 struct mlx5_hlist_entry *entry,
7665 uint64_t key, void *cb_ctx __rte_unused)
7667 union tunnel_tbl_key tbl = {
7670 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
7672 return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
7675 static struct mlx5_hlist_entry *
7676 mlx5_flow_tunnel_grp2tbl_create_cb(struct mlx5_hlist *list, uint64_t key,
7677 void *ctx __rte_unused)
7679 struct mlx5_dev_ctx_shared *sh = list->ctx;
7680 struct tunnel_tbl_entry *tte;
7681 union tunnel_tbl_key tbl = {
7685 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
7690 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
7692 if (tte->flow_table >= MLX5_MAX_TABLES) {
7693 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
7695 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
7698 } else if (!tte->flow_table) {
7701 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
7702 tte->tunnel_id = tbl.tunnel_id;
7703 tte->group = tbl.group;
7712 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
7713 const struct mlx5_flow_tunnel *tunnel,
7714 uint32_t group, uint32_t *table,
7715 struct rte_flow_error *error)
7717 struct mlx5_hlist_entry *he;
7718 struct tunnel_tbl_entry *tte;
7719 union tunnel_tbl_key key = {
7720 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
7723 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7724 struct mlx5_hlist *group_hash;
7726 group_hash = tunnel ? tunnel->groups : thub->groups;
7727 he = mlx5_hlist_register(group_hash, key.val, NULL);
7729 return rte_flow_error_set(error, EINVAL,
7730 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7732 "tunnel group index not supported");
7733 tte = container_of(he, typeof(*tte), hash);
7734 *table = tte->flow_table;
7735 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
7736 dev->data->port_id, key.tunnel_id, group, *table);
7741 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
7742 struct mlx5_flow_tunnel *tunnel)
7744 struct mlx5_priv *priv = dev->data->dev_private;
7745 struct mlx5_indexed_pool *ipool;
7747 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
7748 dev->data->port_id, tunnel->tunnel_id);
7749 LIST_REMOVE(tunnel, chain);
7750 mlx5_hlist_destroy(tunnel->groups);
7751 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
7752 mlx5_ipool_free(ipool, tunnel->tunnel_id);
7756 mlx5_access_tunnel_offload_db
7757 (struct rte_eth_dev *dev,
7758 bool (*match)(struct rte_eth_dev *,
7759 struct mlx5_flow_tunnel *, const void *),
7760 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
7761 void (*miss)(struct rte_eth_dev *, void *),
7762 void *ctx, bool lock_op)
7764 bool verdict = false;
7765 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7766 struct mlx5_flow_tunnel *tunnel;
7768 rte_spinlock_lock(&thub->sl);
7769 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
7770 verdict = match(dev, tunnel, (const void *)ctx);
7775 rte_spinlock_unlock(&thub->sl);
7777 hit(dev, tunnel, ctx);
7778 if (!verdict && miss)
7781 rte_spinlock_unlock(&thub->sl);
7786 struct tunnel_db_find_tunnel_id_ctx {
7788 struct mlx5_flow_tunnel *tunnel;
7792 find_tunnel_id_match(struct rte_eth_dev *dev,
7793 struct mlx5_flow_tunnel *tunnel, const void *x)
7795 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
7798 return tunnel->tunnel_id == ctx->tunnel_id;
7802 find_tunnel_id_hit(struct rte_eth_dev *dev,
7803 struct mlx5_flow_tunnel *tunnel, void *x)
7805 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
7807 ctx->tunnel = tunnel;
7810 static struct mlx5_flow_tunnel *
7811 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
7813 struct tunnel_db_find_tunnel_id_ctx ctx = {
7817 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
7818 find_tunnel_id_hit, NULL, &ctx, true);
7823 static struct mlx5_flow_tunnel *
7824 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
7825 const struct rte_flow_tunnel *app_tunnel)
7827 struct mlx5_priv *priv = dev->data->dev_private;
7828 struct mlx5_indexed_pool *ipool;
7829 struct mlx5_flow_tunnel *tunnel;
7832 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
7833 tunnel = mlx5_ipool_zmalloc(ipool, &id);
7836 if (id >= MLX5_MAX_TUNNELS) {
7837 mlx5_ipool_free(ipool, id);
7838 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
7841 tunnel->groups = mlx5_hlist_create("tunnel groups", 1024, 0, 0,
7842 mlx5_flow_tunnel_grp2tbl_create_cb,
7843 mlx5_flow_tunnel_grp2tbl_match_cb,
7844 mlx5_flow_tunnel_grp2tbl_remove_cb);
7845 if (!tunnel->groups) {
7846 mlx5_ipool_free(ipool, id);
7849 tunnel->groups->ctx = priv->sh;
7850 /* initiate new PMD tunnel */
7851 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
7852 tunnel->tunnel_id = id;
7853 tunnel->action.type = (typeof(tunnel->action.type))
7854 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
7855 tunnel->action.conf = tunnel;
7856 tunnel->item.type = (typeof(tunnel->item.type))
7857 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
7858 tunnel->item.spec = tunnel;
7859 tunnel->item.last = NULL;
7860 tunnel->item.mask = NULL;
7862 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
7863 dev->data->port_id, tunnel->tunnel_id);
7868 struct tunnel_db_get_tunnel_ctx {
7869 const struct rte_flow_tunnel *app_tunnel;
7870 struct mlx5_flow_tunnel *tunnel;
7873 static bool get_tunnel_match(struct rte_eth_dev *dev,
7874 struct mlx5_flow_tunnel *tunnel, const void *x)
7876 const struct tunnel_db_get_tunnel_ctx *ctx = x;
7879 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
7880 sizeof(*ctx->app_tunnel));
7883 static void get_tunnel_hit(struct rte_eth_dev *dev,
7884 struct mlx5_flow_tunnel *tunnel, void *x)
7886 /* called under tunnel spinlock protection */
7887 struct tunnel_db_get_tunnel_ctx *ctx = x;
7891 ctx->tunnel = tunnel;
7894 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
7896 /* called under tunnel spinlock protection */
7897 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7898 struct tunnel_db_get_tunnel_ctx *ctx = x;
7900 rte_spinlock_unlock(&thub->sl);
7901 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
7902 ctx->tunnel->refctn = 1;
7903 rte_spinlock_lock(&thub->sl);
7905 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
7910 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
7911 const struct rte_flow_tunnel *app_tunnel,
7912 struct mlx5_flow_tunnel **tunnel)
7914 struct tunnel_db_get_tunnel_ctx ctx = {
7915 .app_tunnel = app_tunnel,
7918 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
7919 get_tunnel_miss, &ctx, true);
7920 *tunnel = ctx.tunnel;
7921 return ctx.tunnel ? 0 : -ENOMEM;
7924 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
7926 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
7930 if (!LIST_EMPTY(&thub->tunnels))
7931 DRV_LOG(WARNING, "port %u tunnels present", port_id);
7932 mlx5_hlist_destroy(thub->groups);
7936 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
7939 struct mlx5_flow_tunnel_hub *thub;
7941 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
7945 LIST_INIT(&thub->tunnels);
7946 rte_spinlock_init(&thub->sl);
7947 thub->groups = mlx5_hlist_create("flow groups",
7948 rte_align32pow2(MLX5_MAX_TABLES), 0,
7949 0, mlx5_flow_tunnel_grp2tbl_create_cb,
7950 mlx5_flow_tunnel_grp2tbl_match_cb,
7951 mlx5_flow_tunnel_grp2tbl_remove_cb);
7952 if (!thub->groups) {
7956 thub->groups->ctx = sh;
7957 sh->tunnel_hub = thub;
7963 mlx5_hlist_destroy(thub->groups);
7970 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
7971 struct rte_flow_tunnel *tunnel,
7972 const char *err_msg)
7975 if (!is_tunnel_offload_active(dev)) {
7976 err_msg = "tunnel offload was not activated";
7978 } else if (!tunnel) {
7979 err_msg = "no application tunnel";
7983 switch (tunnel->type) {
7985 err_msg = "unsupported tunnel type";
7987 case RTE_FLOW_ITEM_TYPE_VXLAN:
7996 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
7997 struct rte_flow_tunnel *app_tunnel,
7998 struct rte_flow_action **actions,
7999 uint32_t *num_of_actions,
8000 struct rte_flow_error *error)
8003 struct mlx5_flow_tunnel *tunnel;
8004 const char *err_msg = NULL;
8005 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
8008 return rte_flow_error_set(error, EINVAL,
8009 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
8011 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
8013 return rte_flow_error_set(error, ret,
8014 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
8015 "failed to initialize pmd tunnel");
8017 *actions = &tunnel->action;
8018 *num_of_actions = 1;
8023 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
8024 struct rte_flow_tunnel *app_tunnel,
8025 struct rte_flow_item **items,
8026 uint32_t *num_of_items,
8027 struct rte_flow_error *error)
8030 struct mlx5_flow_tunnel *tunnel;
8031 const char *err_msg = NULL;
8032 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
8035 return rte_flow_error_set(error, EINVAL,
8036 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
8038 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
8040 return rte_flow_error_set(error, ret,
8041 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
8042 "failed to initialize pmd tunnel");
8044 *items = &tunnel->item;
8049 struct tunnel_db_element_release_ctx {
8050 struct rte_flow_item *items;
8051 struct rte_flow_action *actions;
8052 uint32_t num_elements;
8053 struct rte_flow_error *error;
8058 tunnel_element_release_match(struct rte_eth_dev *dev,
8059 struct mlx5_flow_tunnel *tunnel, const void *x)
8061 const struct tunnel_db_element_release_ctx *ctx = x;
8064 if (ctx->num_elements != 1)
8066 else if (ctx->items)
8067 return ctx->items == &tunnel->item;
8068 else if (ctx->actions)
8069 return ctx->actions == &tunnel->action;
8075 tunnel_element_release_hit(struct rte_eth_dev *dev,
8076 struct mlx5_flow_tunnel *tunnel, void *x)
8078 struct tunnel_db_element_release_ctx *ctx = x;
8080 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
8081 mlx5_flow_tunnel_free(dev, tunnel);
8085 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
8087 struct tunnel_db_element_release_ctx *ctx = x;
8089 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
8090 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
8091 "invalid argument");
8095 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
8096 struct rte_flow_item *pmd_items,
8097 uint32_t num_items, struct rte_flow_error *err)
8099 struct tunnel_db_element_release_ctx ctx = {
8102 .num_elements = num_items,
8106 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
8107 tunnel_element_release_hit,
8108 tunnel_element_release_miss, &ctx, false);
8114 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
8115 struct rte_flow_action *pmd_actions,
8116 uint32_t num_actions, struct rte_flow_error *err)
8118 struct tunnel_db_element_release_ctx ctx = {
8120 .actions = pmd_actions,
8121 .num_elements = num_actions,
8125 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
8126 tunnel_element_release_hit,
8127 tunnel_element_release_miss, &ctx, false);
8133 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
8135 struct rte_flow_restore_info *info,
8136 struct rte_flow_error *err)
8138 uint64_t ol_flags = m->ol_flags;
8139 const struct mlx5_flow_tbl_data_entry *tble;
8140 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
8142 if (!is_tunnel_offload_active(dev)) {
8147 if ((ol_flags & mask) != mask)
8149 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
8151 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
8152 dev->data->port_id, m->hash.fdir.hi);
8155 MLX5_ASSERT(tble->tunnel);
8156 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
8157 info->group_id = tble->group_id;
8158 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
8159 RTE_FLOW_RESTORE_INFO_GROUP_ID |
8160 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
8165 return rte_flow_error_set(err, EINVAL,
8166 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8167 "failed to get restore info");
8170 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
8172 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
8173 __rte_unused struct rte_flow_tunnel *app_tunnel,
8174 __rte_unused struct rte_flow_action **actions,
8175 __rte_unused uint32_t *num_of_actions,
8176 __rte_unused struct rte_flow_error *error)
8182 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
8183 __rte_unused struct rte_flow_tunnel *app_tunnel,
8184 __rte_unused struct rte_flow_item **items,
8185 __rte_unused uint32_t *num_of_items,
8186 __rte_unused struct rte_flow_error *error)
8192 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
8193 __rte_unused struct rte_flow_item *pmd_items,
8194 __rte_unused uint32_t num_items,
8195 __rte_unused struct rte_flow_error *err)
8201 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
8202 __rte_unused struct rte_flow_action *pmd_action,
8203 __rte_unused uint32_t num_actions,
8204 __rte_unused struct rte_flow_error *err)
8210 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
8211 __rte_unused struct rte_mbuf *m,
8212 __rte_unused struct rte_flow_restore_info *i,
8213 __rte_unused struct rte_flow_error *err)
8219 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
8220 __rte_unused struct rte_flow *flow,
8221 __rte_unused const struct rte_flow_attr *attr,
8222 __rte_unused const struct rte_flow_action *actions,
8223 __rte_unused uint32_t flow_idx,
8224 __rte_unused struct tunnel_default_miss_ctx *ctx,
8225 __rte_unused struct rte_flow_error *error)
8230 static struct mlx5_flow_tunnel *
8231 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
8232 __rte_unused uint32_t id)
8238 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
8239 __rte_unused struct mlx5_flow_tunnel *tunnel)
8244 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
8245 __rte_unused const struct mlx5_flow_tunnel *t,
8246 __rte_unused uint32_t group,
8247 __rte_unused uint32_t *table,
8248 struct rte_flow_error *error)
8250 return rte_flow_error_set(error, ENOTSUP,
8251 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8252 "tunnel offload requires DV support");
8256 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
8257 __rte_unused uint16_t port_id)
8260 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */