1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
6 #include <netinet/in.h>
13 #include <rte_common.h>
14 #include <rte_ether.h>
15 #include <rte_ethdev_driver.h>
16 #include <rte_eal_paging.h>
18 #include <rte_cycles.h>
19 #include <rte_flow_driver.h>
20 #include <rte_malloc.h>
23 #include <mlx5_glue.h>
24 #include <mlx5_devx_cmds.h>
26 #include <mlx5_malloc.h>
28 #include "mlx5_defs.h"
30 #include "mlx5_flow.h"
31 #include "mlx5_flow_os.h"
32 #include "mlx5_rxtx.h"
33 #include "mlx5_common_os.h"
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 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
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;
216 * Expand RSS flows into several possible flows according to the RSS hash
217 * fields requested and the driver capabilities.
220 * Buffer to store the result expansion.
222 * Buffer size in bytes. If 0, @p buf can be NULL.
226 * RSS types to expand (see ETH_RSS_* definitions).
228 * Input graph to expand @p pattern according to @p types.
229 * @param[in] graph_root_index
230 * Index of root node in @p graph, typically 0.
233 * A positive value representing the size of @p buf in bytes regardless of
234 * @p size on success, a negative errno value otherwise and rte_errno is
235 * set, the following errors are defined:
237 * -E2BIG: graph-depth @p graph is too deep.
240 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
241 const struct rte_flow_item *pattern, uint64_t types,
242 const struct mlx5_flow_expand_node graph[],
243 int graph_root_index)
246 const struct rte_flow_item *item;
247 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
248 const int *next_node;
249 const int *stack[elt_n];
251 struct rte_flow_item flow_items[elt_n];
254 size_t user_pattern_size = 0;
256 const struct mlx5_flow_expand_node *next = NULL;
257 struct rte_flow_item missed_item;
260 const struct rte_flow_item *last_item = NULL;
262 memset(&missed_item, 0, sizeof(missed_item));
263 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
264 elt_n * sizeof(buf->entry[0]);
266 buf->entry[0].priority = 0;
267 buf->entry[0].pattern = (void *)&buf->entry[elt_n];
269 addr = buf->entry[0].pattern;
271 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
272 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
274 for (i = 0; node->next && node->next[i]; ++i) {
275 next = &graph[node->next[i]];
276 if (next->type == item->type)
281 user_pattern_size += sizeof(*item);
283 user_pattern_size += sizeof(*item); /* Handle END item. */
284 lsize += user_pattern_size;
285 /* Copy the user pattern in the first entry of the buffer. */
287 rte_memcpy(addr, pattern, user_pattern_size);
288 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
291 /* Start expanding. */
292 memset(flow_items, 0, sizeof(flow_items));
293 user_pattern_size -= sizeof(*item);
295 * Check if the last valid item has spec set, need complete pattern,
296 * and the pattern can be used for expansion.
298 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
299 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
300 /* Item type END indicates expansion is not required. */
303 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
306 for (i = 0; node->next && node->next[i]; ++i) {
307 next = &graph[node->next[i]];
308 if (next->type == missed_item.type) {
309 flow_items[0].type = missed_item.type;
310 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
316 if (next && missed) {
317 elt = 2; /* missed item + item end. */
319 lsize += elt * sizeof(*item) + user_pattern_size;
320 if ((node->rss_types & types) && lsize <= size) {
321 buf->entry[buf->entries].priority = 1;
322 buf->entry[buf->entries].pattern = addr;
324 rte_memcpy(addr, buf->entry[0].pattern,
326 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
327 rte_memcpy(addr, flow_items, elt * sizeof(*item));
328 addr = (void *)(((uintptr_t)addr) +
329 elt * sizeof(*item));
332 memset(flow_items, 0, sizeof(flow_items));
333 next_node = node->next;
334 stack[stack_pos] = next_node;
335 node = next_node ? &graph[*next_node] : NULL;
337 flow_items[stack_pos].type = node->type;
338 if (node->rss_types & types) {
340 * compute the number of items to copy from the
341 * expansion and copy it.
342 * When the stack_pos is 0, there are 1 element in it,
343 * plus the addition END item.
346 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
347 lsize += elt * sizeof(*item) + user_pattern_size;
349 size_t n = elt * sizeof(*item);
351 buf->entry[buf->entries].priority =
352 stack_pos + 1 + missed;
353 buf->entry[buf->entries].pattern = addr;
355 rte_memcpy(addr, buf->entry[0].pattern,
357 addr = (void *)(((uintptr_t)addr) +
359 rte_memcpy(addr, &missed_item,
360 missed * sizeof(*item));
361 addr = (void *)(((uintptr_t)addr) +
362 missed * sizeof(*item));
363 rte_memcpy(addr, flow_items, n);
364 addr = (void *)(((uintptr_t)addr) + n);
369 next_node = node->next;
370 if (stack_pos++ == elt_n) {
374 stack[stack_pos] = next_node;
375 } else if (*(next_node + 1)) {
376 /* Follow up with the next possibility. */
379 /* Move to the next path. */
381 next_node = stack[--stack_pos];
383 stack[stack_pos] = next_node;
385 node = *next_node ? &graph[*next_node] : NULL;
387 /* no expanded flows but we have missed item, create one rule for it */
388 if (buf->entries == 1 && missed != 0) {
390 lsize += elt * sizeof(*item) + user_pattern_size;
392 buf->entry[buf->entries].priority = 1;
393 buf->entry[buf->entries].pattern = addr;
395 flow_items[0].type = missed_item.type;
396 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
397 rte_memcpy(addr, buf->entry[0].pattern,
399 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
400 rte_memcpy(addr, flow_items, elt * sizeof(*item));
406 enum mlx5_expansion {
408 MLX5_EXPANSION_ROOT_OUTER,
409 MLX5_EXPANSION_ROOT_ETH_VLAN,
410 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
411 MLX5_EXPANSION_OUTER_ETH,
412 MLX5_EXPANSION_OUTER_ETH_VLAN,
413 MLX5_EXPANSION_OUTER_VLAN,
414 MLX5_EXPANSION_OUTER_IPV4,
415 MLX5_EXPANSION_OUTER_IPV4_UDP,
416 MLX5_EXPANSION_OUTER_IPV4_TCP,
417 MLX5_EXPANSION_OUTER_IPV6,
418 MLX5_EXPANSION_OUTER_IPV6_UDP,
419 MLX5_EXPANSION_OUTER_IPV6_TCP,
420 MLX5_EXPANSION_VXLAN,
421 MLX5_EXPANSION_VXLAN_GPE,
425 MLX5_EXPANSION_ETH_VLAN,
428 MLX5_EXPANSION_IPV4_UDP,
429 MLX5_EXPANSION_IPV4_TCP,
431 MLX5_EXPANSION_IPV6_UDP,
432 MLX5_EXPANSION_IPV6_TCP,
435 /** Supported expansion of items. */
436 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
437 [MLX5_EXPANSION_ROOT] = {
438 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
440 MLX5_EXPANSION_IPV6),
441 .type = RTE_FLOW_ITEM_TYPE_END,
443 [MLX5_EXPANSION_ROOT_OUTER] = {
444 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
445 MLX5_EXPANSION_OUTER_IPV4,
446 MLX5_EXPANSION_OUTER_IPV6),
447 .type = RTE_FLOW_ITEM_TYPE_END,
449 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
450 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
451 .type = RTE_FLOW_ITEM_TYPE_END,
453 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
454 .next = MLX5_FLOW_EXPAND_RSS_NEXT
455 (MLX5_EXPANSION_OUTER_ETH_VLAN),
456 .type = RTE_FLOW_ITEM_TYPE_END,
458 [MLX5_EXPANSION_OUTER_ETH] = {
459 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
460 MLX5_EXPANSION_OUTER_IPV6,
461 MLX5_EXPANSION_MPLS),
462 .type = RTE_FLOW_ITEM_TYPE_ETH,
465 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
466 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
467 .type = RTE_FLOW_ITEM_TYPE_ETH,
470 [MLX5_EXPANSION_OUTER_VLAN] = {
471 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
472 MLX5_EXPANSION_OUTER_IPV6),
473 .type = RTE_FLOW_ITEM_TYPE_VLAN,
475 [MLX5_EXPANSION_OUTER_IPV4] = {
476 .next = MLX5_FLOW_EXPAND_RSS_NEXT
477 (MLX5_EXPANSION_OUTER_IPV4_UDP,
478 MLX5_EXPANSION_OUTER_IPV4_TCP,
481 MLX5_EXPANSION_IPV6),
482 .type = RTE_FLOW_ITEM_TYPE_IPV4,
483 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
484 ETH_RSS_NONFRAG_IPV4_OTHER,
486 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
487 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
488 MLX5_EXPANSION_VXLAN_GPE),
489 .type = RTE_FLOW_ITEM_TYPE_UDP,
490 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
492 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
493 .type = RTE_FLOW_ITEM_TYPE_TCP,
494 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
496 [MLX5_EXPANSION_OUTER_IPV6] = {
497 .next = MLX5_FLOW_EXPAND_RSS_NEXT
498 (MLX5_EXPANSION_OUTER_IPV6_UDP,
499 MLX5_EXPANSION_OUTER_IPV6_TCP,
501 MLX5_EXPANSION_IPV6),
502 .type = RTE_FLOW_ITEM_TYPE_IPV6,
503 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
504 ETH_RSS_NONFRAG_IPV6_OTHER,
506 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
507 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
508 MLX5_EXPANSION_VXLAN_GPE),
509 .type = RTE_FLOW_ITEM_TYPE_UDP,
510 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
512 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
513 .type = RTE_FLOW_ITEM_TYPE_TCP,
514 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
516 [MLX5_EXPANSION_VXLAN] = {
517 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
519 MLX5_EXPANSION_IPV6),
520 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
522 [MLX5_EXPANSION_VXLAN_GPE] = {
523 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
525 MLX5_EXPANSION_IPV6),
526 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
528 [MLX5_EXPANSION_GRE] = {
529 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
530 .type = RTE_FLOW_ITEM_TYPE_GRE,
532 [MLX5_EXPANSION_MPLS] = {
533 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
534 MLX5_EXPANSION_IPV6),
535 .type = RTE_FLOW_ITEM_TYPE_MPLS,
537 [MLX5_EXPANSION_ETH] = {
538 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
539 MLX5_EXPANSION_IPV6),
540 .type = RTE_FLOW_ITEM_TYPE_ETH,
542 [MLX5_EXPANSION_ETH_VLAN] = {
543 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
544 .type = RTE_FLOW_ITEM_TYPE_ETH,
546 [MLX5_EXPANSION_VLAN] = {
547 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
548 MLX5_EXPANSION_IPV6),
549 .type = RTE_FLOW_ITEM_TYPE_VLAN,
551 [MLX5_EXPANSION_IPV4] = {
552 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
553 MLX5_EXPANSION_IPV4_TCP),
554 .type = RTE_FLOW_ITEM_TYPE_IPV4,
555 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
556 ETH_RSS_NONFRAG_IPV4_OTHER,
558 [MLX5_EXPANSION_IPV4_UDP] = {
559 .type = RTE_FLOW_ITEM_TYPE_UDP,
560 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
562 [MLX5_EXPANSION_IPV4_TCP] = {
563 .type = RTE_FLOW_ITEM_TYPE_TCP,
564 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
566 [MLX5_EXPANSION_IPV6] = {
567 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
568 MLX5_EXPANSION_IPV6_TCP),
569 .type = RTE_FLOW_ITEM_TYPE_IPV6,
570 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
571 ETH_RSS_NONFRAG_IPV6_OTHER,
573 [MLX5_EXPANSION_IPV6_UDP] = {
574 .type = RTE_FLOW_ITEM_TYPE_UDP,
575 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
577 [MLX5_EXPANSION_IPV6_TCP] = {
578 .type = RTE_FLOW_ITEM_TYPE_TCP,
579 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
583 static struct rte_flow_shared_action *
584 mlx5_shared_action_create(struct rte_eth_dev *dev,
585 const struct rte_flow_shared_action_conf *conf,
586 const struct rte_flow_action *action,
587 struct rte_flow_error *error);
588 static int mlx5_shared_action_destroy
589 (struct rte_eth_dev *dev,
590 struct rte_flow_shared_action *shared_action,
591 struct rte_flow_error *error);
592 static int mlx5_shared_action_update
593 (struct rte_eth_dev *dev,
594 struct rte_flow_shared_action *shared_action,
595 const struct rte_flow_action *action,
596 struct rte_flow_error *error);
597 static int mlx5_shared_action_query
598 (struct rte_eth_dev *dev,
599 const struct rte_flow_shared_action *action,
601 struct rte_flow_error *error);
603 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
604 struct rte_flow_tunnel *app_tunnel,
605 struct rte_flow_action **actions,
606 uint32_t *num_of_actions,
607 struct rte_flow_error *error);
609 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
610 struct rte_flow_tunnel *app_tunnel,
611 struct rte_flow_item **items,
612 uint32_t *num_of_items,
613 struct rte_flow_error *error);
615 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
616 struct rte_flow_item *pmd_items,
617 uint32_t num_items, struct rte_flow_error *err);
619 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
620 struct rte_flow_action *pmd_actions,
621 uint32_t num_actions,
622 struct rte_flow_error *err);
624 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
626 struct rte_flow_restore_info *info,
627 struct rte_flow_error *err);
629 static const struct rte_flow_ops mlx5_flow_ops = {
630 .validate = mlx5_flow_validate,
631 .create = mlx5_flow_create,
632 .destroy = mlx5_flow_destroy,
633 .flush = mlx5_flow_flush,
634 .isolate = mlx5_flow_isolate,
635 .query = mlx5_flow_query,
636 .dev_dump = mlx5_flow_dev_dump,
637 .get_aged_flows = mlx5_flow_get_aged_flows,
638 .shared_action_create = mlx5_shared_action_create,
639 .shared_action_destroy = mlx5_shared_action_destroy,
640 .shared_action_update = mlx5_shared_action_update,
641 .shared_action_query = mlx5_shared_action_query,
642 .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
643 .tunnel_match = mlx5_flow_tunnel_match,
644 .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
645 .tunnel_item_release = mlx5_flow_tunnel_item_release,
646 .get_restore_info = mlx5_flow_tunnel_get_restore_info,
649 /* Tunnel information. */
650 struct mlx5_flow_tunnel_info {
651 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
652 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
655 static struct mlx5_flow_tunnel_info tunnels_info[] = {
657 .tunnel = MLX5_FLOW_LAYER_VXLAN,
658 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
661 .tunnel = MLX5_FLOW_LAYER_GENEVE,
662 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
665 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
666 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
669 .tunnel = MLX5_FLOW_LAYER_GRE,
670 .ptype = RTE_PTYPE_TUNNEL_GRE,
673 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
674 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
677 .tunnel = MLX5_FLOW_LAYER_MPLS,
678 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
681 .tunnel = MLX5_FLOW_LAYER_NVGRE,
682 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
685 .tunnel = MLX5_FLOW_LAYER_IPIP,
686 .ptype = RTE_PTYPE_TUNNEL_IP,
689 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
690 .ptype = RTE_PTYPE_TUNNEL_IP,
693 .tunnel = MLX5_FLOW_LAYER_GTP,
694 .ptype = RTE_PTYPE_TUNNEL_GTPU,
698 /* Key of thread specific flow workspace data. */
699 static pthread_key_t key_workspace;
701 /* Thread specific flow workspace data once initialization data. */
702 static pthread_once_t key_workspace_init;
706 * Translate tag ID to register.
709 * Pointer to the Ethernet device structure.
711 * The feature that request the register.
713 * The request register ID.
715 * Error description in case of any.
718 * The request register on success, a negative errno
719 * value otherwise and rte_errno is set.
722 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
723 enum mlx5_feature_name feature,
725 struct rte_flow_error *error)
727 struct mlx5_priv *priv = dev->data->dev_private;
728 struct mlx5_dev_config *config = &priv->config;
729 enum modify_reg start_reg;
730 bool skip_mtr_reg = false;
733 case MLX5_HAIRPIN_RX:
735 case MLX5_HAIRPIN_TX:
737 case MLX5_METADATA_RX:
738 switch (config->dv_xmeta_en) {
739 case MLX5_XMETA_MODE_LEGACY:
741 case MLX5_XMETA_MODE_META16:
743 case MLX5_XMETA_MODE_META32:
747 case MLX5_METADATA_TX:
749 case MLX5_METADATA_FDB:
750 switch (config->dv_xmeta_en) {
751 case MLX5_XMETA_MODE_LEGACY:
753 case MLX5_XMETA_MODE_META16:
755 case MLX5_XMETA_MODE_META32:
760 switch (config->dv_xmeta_en) {
761 case MLX5_XMETA_MODE_LEGACY:
763 case MLX5_XMETA_MODE_META16:
765 case MLX5_XMETA_MODE_META32:
771 * If meter color and flow match share one register, flow match
772 * should use the meter color register for match.
774 if (priv->mtr_reg_share)
775 return priv->mtr_color_reg;
777 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
780 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
781 return priv->mtr_color_reg;
784 * Metadata COPY_MARK register using is in meter suffix sub
785 * flow while with meter. It's safe to share the same register.
787 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
790 * If meter is enable, it will engage the register for color
791 * match and flow match. If meter color match is not using the
792 * REG_C_2, need to skip the REG_C_x be used by meter color
794 * If meter is disable, free to use all available registers.
796 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
797 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
798 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
799 if (id > (REG_C_7 - start_reg))
800 return rte_flow_error_set(error, EINVAL,
801 RTE_FLOW_ERROR_TYPE_ITEM,
802 NULL, "invalid tag id");
803 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
804 return rte_flow_error_set(error, ENOTSUP,
805 RTE_FLOW_ERROR_TYPE_ITEM,
806 NULL, "unsupported tag id");
808 * This case means meter is using the REG_C_x great than 2.
809 * Take care not to conflict with meter color REG_C_x.
810 * If the available index REG_C_y >= REG_C_x, skip the
813 if (skip_mtr_reg && config->flow_mreg_c
814 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
815 if (id >= (REG_C_7 - start_reg))
816 return rte_flow_error_set(error, EINVAL,
817 RTE_FLOW_ERROR_TYPE_ITEM,
818 NULL, "invalid tag id");
819 if (config->flow_mreg_c
820 [id + 1 + start_reg - REG_C_0] != REG_NON)
821 return config->flow_mreg_c
822 [id + 1 + start_reg - REG_C_0];
823 return rte_flow_error_set(error, ENOTSUP,
824 RTE_FLOW_ERROR_TYPE_ITEM,
825 NULL, "unsupported tag id");
827 return config->flow_mreg_c[id + start_reg - REG_C_0];
830 return rte_flow_error_set(error, EINVAL,
831 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
832 NULL, "invalid feature name");
836 * Check extensive flow metadata register support.
839 * Pointer to rte_eth_dev structure.
842 * True if device supports extensive flow metadata register, otherwise false.
845 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
847 struct mlx5_priv *priv = dev->data->dev_private;
848 struct mlx5_dev_config *config = &priv->config;
851 * Having available reg_c can be regarded inclusively as supporting
852 * extensive flow metadata register, which could mean,
853 * - metadata register copy action by modify header.
854 * - 16 modify header actions is supported.
855 * - reg_c's are preserved across different domain (FDB and NIC) on
856 * packet loopback by flow lookup miss.
858 return config->flow_mreg_c[2] != REG_NON;
862 * Verify the @p item specifications (spec, last, mask) are compatible with the
866 * Item specification.
868 * @p item->mask or flow default bit-masks.
869 * @param[in] nic_mask
870 * Bit-masks covering supported fields by the NIC to compare with user mask.
872 * Bit-masks size in bytes.
873 * @param[in] range_accepted
874 * True if range of values is accepted for specific fields, false otherwise.
876 * Pointer to error structure.
879 * 0 on success, a negative errno value otherwise and rte_errno is set.
882 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
884 const uint8_t *nic_mask,
887 struct rte_flow_error *error)
891 MLX5_ASSERT(nic_mask);
892 for (i = 0; i < size; ++i)
893 if ((nic_mask[i] | mask[i]) != nic_mask[i])
894 return rte_flow_error_set(error, ENOTSUP,
895 RTE_FLOW_ERROR_TYPE_ITEM,
897 "mask enables non supported"
899 if (!item->spec && (item->mask || item->last))
900 return rte_flow_error_set(error, EINVAL,
901 RTE_FLOW_ERROR_TYPE_ITEM, item,
902 "mask/last without a spec is not"
904 if (item->spec && item->last && !range_accepted) {
910 for (i = 0; i < size; ++i) {
911 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
912 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
914 ret = memcmp(spec, last, size);
916 return rte_flow_error_set(error, EINVAL,
917 RTE_FLOW_ERROR_TYPE_ITEM,
919 "range is not valid");
925 * Adjust the hash fields according to the @p flow information.
927 * @param[in] dev_flow.
928 * Pointer to the mlx5_flow.
930 * 1 when the hash field is for a tunnel item.
931 * @param[in] layer_types
933 * @param[in] hash_fields
937 * The hash fields that should be used.
940 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
941 int tunnel __rte_unused, uint64_t layer_types,
942 uint64_t hash_fields)
944 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
945 int rss_request_inner = rss_desc->level >= 2;
947 /* Check RSS hash level for tunnel. */
948 if (tunnel && rss_request_inner)
949 hash_fields |= IBV_RX_HASH_INNER;
950 else if (tunnel || rss_request_inner)
953 /* Check if requested layer matches RSS hash fields. */
954 if (!(rss_desc->types & layer_types))
960 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
961 * if several tunnel rules are used on this queue, the tunnel ptype will be
965 * Rx queue to update.
968 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
971 uint32_t tunnel_ptype = 0;
973 /* Look up for the ptype to use. */
974 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
975 if (!rxq_ctrl->flow_tunnels_n[i])
978 tunnel_ptype = tunnels_info[i].ptype;
984 rxq_ctrl->rxq.tunnel = tunnel_ptype;
988 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
992 * Pointer to the Ethernet device structure.
993 * @param[in] dev_handle
994 * Pointer to device flow handle structure.
997 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
998 struct mlx5_flow_handle *dev_handle)
1000 struct mlx5_priv *priv = dev->data->dev_private;
1001 const int mark = dev_handle->mark;
1002 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1003 struct mlx5_hrxq *hrxq;
1006 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
1008 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1009 dev_handle->rix_hrxq);
1012 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
1013 int idx = hrxq->ind_table->queues[i];
1014 struct mlx5_rxq_ctrl *rxq_ctrl =
1015 container_of((*priv->rxqs)[idx],
1016 struct mlx5_rxq_ctrl, rxq);
1019 * To support metadata register copy on Tx loopback,
1020 * this must be always enabled (metadata may arive
1021 * from other port - not from local flows only.
1023 if (priv->config.dv_flow_en &&
1024 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1025 mlx5_flow_ext_mreg_supported(dev)) {
1026 rxq_ctrl->rxq.mark = 1;
1027 rxq_ctrl->flow_mark_n = 1;
1029 rxq_ctrl->rxq.mark = 1;
1030 rxq_ctrl->flow_mark_n++;
1035 /* Increase the counter matching the flow. */
1036 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1037 if ((tunnels_info[j].tunnel &
1038 dev_handle->layers) ==
1039 tunnels_info[j].tunnel) {
1040 rxq_ctrl->flow_tunnels_n[j]++;
1044 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1050 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1053 * Pointer to the Ethernet device structure.
1055 * Pointer to flow structure.
1058 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1060 struct mlx5_priv *priv = dev->data->dev_private;
1061 uint32_t handle_idx;
1062 struct mlx5_flow_handle *dev_handle;
1064 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1065 handle_idx, dev_handle, next)
1066 flow_drv_rxq_flags_set(dev, dev_handle);
1070 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1071 * device flow if no other flow uses it with the same kind of request.
1074 * Pointer to Ethernet device.
1075 * @param[in] dev_handle
1076 * Pointer to the device flow handle structure.
1079 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1080 struct mlx5_flow_handle *dev_handle)
1082 struct mlx5_priv *priv = dev->data->dev_private;
1083 const int mark = dev_handle->mark;
1084 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1085 struct mlx5_hrxq *hrxq;
1088 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
1090 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1091 dev_handle->rix_hrxq);
1094 MLX5_ASSERT(dev->data->dev_started);
1095 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
1096 int idx = hrxq->ind_table->queues[i];
1097 struct mlx5_rxq_ctrl *rxq_ctrl =
1098 container_of((*priv->rxqs)[idx],
1099 struct mlx5_rxq_ctrl, rxq);
1101 if (priv->config.dv_flow_en &&
1102 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1103 mlx5_flow_ext_mreg_supported(dev)) {
1104 rxq_ctrl->rxq.mark = 1;
1105 rxq_ctrl->flow_mark_n = 1;
1107 rxq_ctrl->flow_mark_n--;
1108 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1113 /* Decrease the counter matching the flow. */
1114 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1115 if ((tunnels_info[j].tunnel &
1116 dev_handle->layers) ==
1117 tunnels_info[j].tunnel) {
1118 rxq_ctrl->flow_tunnels_n[j]--;
1122 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1128 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1129 * @p flow if no other flow uses it with the same kind of request.
1132 * Pointer to Ethernet device.
1134 * Pointer to the flow.
1137 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1139 struct mlx5_priv *priv = dev->data->dev_private;
1140 uint32_t handle_idx;
1141 struct mlx5_flow_handle *dev_handle;
1143 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1144 handle_idx, dev_handle, next)
1145 flow_drv_rxq_flags_trim(dev, dev_handle);
1149 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1152 * Pointer to Ethernet device.
1155 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1157 struct mlx5_priv *priv = dev->data->dev_private;
1160 for (i = 0; i != priv->rxqs_n; ++i) {
1161 struct mlx5_rxq_ctrl *rxq_ctrl;
1164 if (!(*priv->rxqs)[i])
1166 rxq_ctrl = container_of((*priv->rxqs)[i],
1167 struct mlx5_rxq_ctrl, rxq);
1168 rxq_ctrl->flow_mark_n = 0;
1169 rxq_ctrl->rxq.mark = 0;
1170 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1171 rxq_ctrl->flow_tunnels_n[j] = 0;
1172 rxq_ctrl->rxq.tunnel = 0;
1177 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1180 * Pointer to the Ethernet device structure.
1183 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1185 struct mlx5_priv *priv = dev->data->dev_private;
1186 struct mlx5_rxq_data *data;
1189 for (i = 0; i != priv->rxqs_n; ++i) {
1190 if (!(*priv->rxqs)[i])
1192 data = (*priv->rxqs)[i];
1193 if (!rte_flow_dynf_metadata_avail()) {
1194 data->dynf_meta = 0;
1195 data->flow_meta_mask = 0;
1196 data->flow_meta_offset = -1;
1198 data->dynf_meta = 1;
1199 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1200 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1206 * return a pointer to the desired action in the list of actions.
1208 * @param[in] actions
1209 * The list of actions to search the action in.
1211 * The action to find.
1214 * Pointer to the action in the list, if found. NULL otherwise.
1216 const struct rte_flow_action *
1217 mlx5_flow_find_action(const struct rte_flow_action *actions,
1218 enum rte_flow_action_type action)
1220 if (actions == NULL)
1222 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1223 if (actions->type == action)
1229 * Validate the flag action.
1231 * @param[in] action_flags
1232 * Bit-fields that holds the actions detected until now.
1234 * Attributes of flow that includes this action.
1236 * Pointer to error structure.
1239 * 0 on success, a negative errno value otherwise and rte_errno is set.
1242 mlx5_flow_validate_action_flag(uint64_t action_flags,
1243 const struct rte_flow_attr *attr,
1244 struct rte_flow_error *error)
1246 if (action_flags & MLX5_FLOW_ACTION_MARK)
1247 return rte_flow_error_set(error, EINVAL,
1248 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1249 "can't mark and flag in same flow");
1250 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1251 return rte_flow_error_set(error, EINVAL,
1252 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1254 " actions in same flow");
1256 return rte_flow_error_set(error, ENOTSUP,
1257 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1258 "flag action not supported for "
1264 * Validate the mark action.
1267 * Pointer to the queue action.
1268 * @param[in] action_flags
1269 * Bit-fields that holds the actions detected until now.
1271 * Attributes of flow that includes this action.
1273 * Pointer to error structure.
1276 * 0 on success, a negative errno value otherwise and rte_errno is set.
1279 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1280 uint64_t action_flags,
1281 const struct rte_flow_attr *attr,
1282 struct rte_flow_error *error)
1284 const struct rte_flow_action_mark *mark = action->conf;
1287 return rte_flow_error_set(error, EINVAL,
1288 RTE_FLOW_ERROR_TYPE_ACTION,
1290 "configuration cannot be null");
1291 if (mark->id >= MLX5_FLOW_MARK_MAX)
1292 return rte_flow_error_set(error, EINVAL,
1293 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1295 "mark id must in 0 <= id < "
1296 RTE_STR(MLX5_FLOW_MARK_MAX));
1297 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1298 return rte_flow_error_set(error, EINVAL,
1299 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1300 "can't flag and mark in same flow");
1301 if (action_flags & MLX5_FLOW_ACTION_MARK)
1302 return rte_flow_error_set(error, EINVAL,
1303 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1304 "can't have 2 mark actions in same"
1307 return rte_flow_error_set(error, ENOTSUP,
1308 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1309 "mark action not supported for "
1315 * Validate the drop action.
1317 * @param[in] action_flags
1318 * Bit-fields that holds the actions detected until now.
1320 * Attributes of flow that includes this action.
1322 * Pointer to error structure.
1325 * 0 on success, a negative errno value otherwise and rte_errno is set.
1328 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1329 const struct rte_flow_attr *attr,
1330 struct rte_flow_error *error)
1333 return rte_flow_error_set(error, ENOTSUP,
1334 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1335 "drop action not supported for "
1341 * Validate the queue action.
1344 * Pointer to the queue action.
1345 * @param[in] action_flags
1346 * Bit-fields that holds the actions detected until now.
1348 * Pointer to the Ethernet device structure.
1350 * Attributes of flow that includes this action.
1352 * Pointer to error structure.
1355 * 0 on success, a negative errno value otherwise and rte_errno is set.
1358 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1359 uint64_t action_flags,
1360 struct rte_eth_dev *dev,
1361 const struct rte_flow_attr *attr,
1362 struct rte_flow_error *error)
1364 struct mlx5_priv *priv = dev->data->dev_private;
1365 const struct rte_flow_action_queue *queue = action->conf;
1367 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1368 return rte_flow_error_set(error, EINVAL,
1369 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1370 "can't have 2 fate actions in"
1373 return rte_flow_error_set(error, EINVAL,
1374 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1375 NULL, "No Rx queues configured");
1376 if (queue->index >= priv->rxqs_n)
1377 return rte_flow_error_set(error, EINVAL,
1378 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1380 "queue index out of range");
1381 if (!(*priv->rxqs)[queue->index])
1382 return rte_flow_error_set(error, EINVAL,
1383 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1385 "queue is not configured");
1387 return rte_flow_error_set(error, ENOTSUP,
1388 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1389 "queue action not supported for "
1395 * Validate the rss action.
1398 * Pointer to the Ethernet device structure.
1400 * Pointer to the queue action.
1402 * Pointer to error structure.
1405 * 0 on success, a negative errno value otherwise and rte_errno is set.
1408 mlx5_validate_action_rss(struct rte_eth_dev *dev,
1409 const struct rte_flow_action *action,
1410 struct rte_flow_error *error)
1412 struct mlx5_priv *priv = dev->data->dev_private;
1413 const struct rte_flow_action_rss *rss = action->conf;
1414 enum mlx5_rxq_type rxq_type = MLX5_RXQ_TYPE_UNDEFINED;
1417 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1418 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1419 return rte_flow_error_set(error, ENOTSUP,
1420 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1422 "RSS hash function not supported");
1423 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1428 return rte_flow_error_set(error, ENOTSUP,
1429 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1431 "tunnel RSS is not supported");
1432 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1433 if (rss->key_len == 0 && rss->key != NULL)
1434 return rte_flow_error_set(error, ENOTSUP,
1435 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1437 "RSS hash key length 0");
1438 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1439 return rte_flow_error_set(error, ENOTSUP,
1440 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1442 "RSS hash key too small");
1443 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1444 return rte_flow_error_set(error, ENOTSUP,
1445 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1447 "RSS hash key too large");
1448 if (rss->queue_num > priv->config.ind_table_max_size)
1449 return rte_flow_error_set(error, ENOTSUP,
1450 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1452 "number of queues too large");
1453 if (rss->types & MLX5_RSS_HF_MASK)
1454 return rte_flow_error_set(error, ENOTSUP,
1455 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1457 "some RSS protocols are not"
1459 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1460 !(rss->types & ETH_RSS_IP))
1461 return rte_flow_error_set(error, EINVAL,
1462 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1463 "L3 partial RSS requested but L3 RSS"
1464 " type not specified");
1465 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1466 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1467 return rte_flow_error_set(error, EINVAL,
1468 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1469 "L4 partial RSS requested but L4 RSS"
1470 " type not specified");
1472 return rte_flow_error_set(error, EINVAL,
1473 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1474 NULL, "No Rx queues configured");
1475 if (!rss->queue_num)
1476 return rte_flow_error_set(error, EINVAL,
1477 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1478 NULL, "No queues configured");
1479 for (i = 0; i != rss->queue_num; ++i) {
1480 struct mlx5_rxq_ctrl *rxq_ctrl;
1482 if (rss->queue[i] >= priv->rxqs_n)
1483 return rte_flow_error_set
1485 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1486 &rss->queue[i], "queue index out of range");
1487 if (!(*priv->rxqs)[rss->queue[i]])
1488 return rte_flow_error_set
1489 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1490 &rss->queue[i], "queue is not configured");
1491 rxq_ctrl = container_of((*priv->rxqs)[rss->queue[i]],
1492 struct mlx5_rxq_ctrl, rxq);
1494 rxq_type = rxq_ctrl->type;
1495 if (rxq_type != rxq_ctrl->type)
1496 return rte_flow_error_set
1497 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1499 "combining hairpin and regular RSS queues is not supported");
1505 * Validate the rss action.
1508 * Pointer to the queue action.
1509 * @param[in] action_flags
1510 * Bit-fields that holds the actions detected until now.
1512 * Pointer to the Ethernet device structure.
1514 * Attributes of flow that includes this action.
1515 * @param[in] item_flags
1516 * Items that were detected.
1518 * Pointer to error structure.
1521 * 0 on success, a negative errno value otherwise and rte_errno is set.
1524 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1525 uint64_t action_flags,
1526 struct rte_eth_dev *dev,
1527 const struct rte_flow_attr *attr,
1528 uint64_t item_flags,
1529 struct rte_flow_error *error)
1531 const struct rte_flow_action_rss *rss = action->conf;
1532 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1535 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1536 return rte_flow_error_set(error, EINVAL,
1537 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1538 "can't have 2 fate actions"
1540 ret = mlx5_validate_action_rss(dev, action, error);
1544 return rte_flow_error_set(error, ENOTSUP,
1545 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1546 "rss action not supported for "
1548 if (rss->level > 1 && !tunnel)
1549 return rte_flow_error_set(error, EINVAL,
1550 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1551 "inner RSS is not supported for "
1552 "non-tunnel flows");
1553 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1554 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1555 return rte_flow_error_set(error, EINVAL,
1556 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1557 "RSS on eCPRI is not supported now");
1563 * Validate the default miss action.
1565 * @param[in] action_flags
1566 * Bit-fields that holds the actions detected until now.
1568 * Pointer to error structure.
1571 * 0 on success, a negative errno value otherwise and rte_errno is set.
1574 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1575 const struct rte_flow_attr *attr,
1576 struct rte_flow_error *error)
1578 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1579 return rte_flow_error_set(error, EINVAL,
1580 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1581 "can't have 2 fate actions in"
1584 return rte_flow_error_set(error, ENOTSUP,
1585 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1586 "default miss action not supported "
1589 return rte_flow_error_set(error, ENOTSUP,
1590 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1591 "only group 0 is supported");
1593 return rte_flow_error_set(error, ENOTSUP,
1594 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1595 NULL, "transfer is not supported");
1600 * Validate the count action.
1603 * Pointer to the Ethernet device structure.
1605 * Attributes of flow that includes this action.
1607 * Pointer to error structure.
1610 * 0 on success, a negative errno value otherwise and rte_errno is set.
1613 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1614 const struct rte_flow_attr *attr,
1615 struct rte_flow_error *error)
1618 return rte_flow_error_set(error, ENOTSUP,
1619 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1620 "count action not supported for "
1626 * Verify the @p attributes will be correctly understood by the NIC and store
1627 * them in the @p flow if everything is correct.
1630 * Pointer to the Ethernet device structure.
1631 * @param[in] attributes
1632 * Pointer to flow attributes
1634 * Pointer to error structure.
1637 * 0 on success, a negative errno value otherwise and rte_errno is set.
1640 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1641 const struct rte_flow_attr *attributes,
1642 struct rte_flow_error *error)
1644 struct mlx5_priv *priv = dev->data->dev_private;
1645 uint32_t priority_max = priv->config.flow_prio - 1;
1647 if (attributes->group)
1648 return rte_flow_error_set(error, ENOTSUP,
1649 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1650 NULL, "groups is not supported");
1651 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1652 attributes->priority >= priority_max)
1653 return rte_flow_error_set(error, ENOTSUP,
1654 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1655 NULL, "priority out of range");
1656 if (attributes->egress)
1657 return rte_flow_error_set(error, ENOTSUP,
1658 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1659 "egress is not supported");
1660 if (attributes->transfer && !priv->config.dv_esw_en)
1661 return rte_flow_error_set(error, ENOTSUP,
1662 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1663 NULL, "transfer is not supported");
1664 if (!attributes->ingress)
1665 return rte_flow_error_set(error, EINVAL,
1666 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1668 "ingress attribute is mandatory");
1673 * Validate ICMP6 item.
1676 * Item specification.
1677 * @param[in] item_flags
1678 * Bit-fields that holds the items detected until now.
1679 * @param[in] ext_vlan_sup
1680 * Whether extended VLAN features are supported or not.
1682 * Pointer to error structure.
1685 * 0 on success, a negative errno value otherwise and rte_errno is set.
1688 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1689 uint64_t item_flags,
1690 uint8_t target_protocol,
1691 struct rte_flow_error *error)
1693 const struct rte_flow_item_icmp6 *mask = item->mask;
1694 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1695 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1696 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1697 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1698 MLX5_FLOW_LAYER_OUTER_L4;
1701 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1702 return rte_flow_error_set(error, EINVAL,
1703 RTE_FLOW_ERROR_TYPE_ITEM, item,
1704 "protocol filtering not compatible"
1705 " with ICMP6 layer");
1706 if (!(item_flags & l3m))
1707 return rte_flow_error_set(error, EINVAL,
1708 RTE_FLOW_ERROR_TYPE_ITEM, item,
1709 "IPv6 is mandatory to filter on"
1711 if (item_flags & l4m)
1712 return rte_flow_error_set(error, EINVAL,
1713 RTE_FLOW_ERROR_TYPE_ITEM, item,
1714 "multiple L4 layers not supported");
1716 mask = &rte_flow_item_icmp6_mask;
1717 ret = mlx5_flow_item_acceptable
1718 (item, (const uint8_t *)mask,
1719 (const uint8_t *)&rte_flow_item_icmp6_mask,
1720 sizeof(struct rte_flow_item_icmp6),
1721 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1728 * Validate ICMP item.
1731 * Item specification.
1732 * @param[in] item_flags
1733 * Bit-fields that holds the items detected until now.
1735 * Pointer to error structure.
1738 * 0 on success, a negative errno value otherwise and rte_errno is set.
1741 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1742 uint64_t item_flags,
1743 uint8_t target_protocol,
1744 struct rte_flow_error *error)
1746 const struct rte_flow_item_icmp *mask = item->mask;
1747 const struct rte_flow_item_icmp nic_mask = {
1748 .hdr.icmp_type = 0xff,
1749 .hdr.icmp_code = 0xff,
1750 .hdr.icmp_ident = RTE_BE16(0xffff),
1751 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1753 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1754 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1755 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1756 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1757 MLX5_FLOW_LAYER_OUTER_L4;
1760 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1761 return rte_flow_error_set(error, EINVAL,
1762 RTE_FLOW_ERROR_TYPE_ITEM, item,
1763 "protocol filtering not compatible"
1764 " with ICMP layer");
1765 if (!(item_flags & l3m))
1766 return rte_flow_error_set(error, EINVAL,
1767 RTE_FLOW_ERROR_TYPE_ITEM, item,
1768 "IPv4 is mandatory to filter"
1770 if (item_flags & l4m)
1771 return rte_flow_error_set(error, EINVAL,
1772 RTE_FLOW_ERROR_TYPE_ITEM, item,
1773 "multiple L4 layers not supported");
1776 ret = mlx5_flow_item_acceptable
1777 (item, (const uint8_t *)mask,
1778 (const uint8_t *)&nic_mask,
1779 sizeof(struct rte_flow_item_icmp),
1780 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1787 * Validate Ethernet item.
1790 * Item specification.
1791 * @param[in] item_flags
1792 * Bit-fields that holds the items detected until now.
1794 * Pointer to error structure.
1797 * 0 on success, a negative errno value otherwise and rte_errno is set.
1800 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1801 uint64_t item_flags, bool ext_vlan_sup,
1802 struct rte_flow_error *error)
1804 const struct rte_flow_item_eth *mask = item->mask;
1805 const struct rte_flow_item_eth nic_mask = {
1806 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1807 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1808 .type = RTE_BE16(0xffff),
1809 .has_vlan = ext_vlan_sup ? 1 : 0,
1812 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1813 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1814 MLX5_FLOW_LAYER_OUTER_L2;
1816 if (item_flags & ethm)
1817 return rte_flow_error_set(error, ENOTSUP,
1818 RTE_FLOW_ERROR_TYPE_ITEM, item,
1819 "multiple L2 layers not supported");
1820 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1821 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1822 return rte_flow_error_set(error, EINVAL,
1823 RTE_FLOW_ERROR_TYPE_ITEM, item,
1824 "L2 layer should not follow "
1826 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1827 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1828 return rte_flow_error_set(error, EINVAL,
1829 RTE_FLOW_ERROR_TYPE_ITEM, item,
1830 "L2 layer should not follow VLAN");
1832 mask = &rte_flow_item_eth_mask;
1833 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1834 (const uint8_t *)&nic_mask,
1835 sizeof(struct rte_flow_item_eth),
1836 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1841 * Validate VLAN item.
1844 * Item specification.
1845 * @param[in] item_flags
1846 * Bit-fields that holds the items detected until now.
1848 * Ethernet device flow is being created on.
1850 * Pointer to error structure.
1853 * 0 on success, a negative errno value otherwise and rte_errno is set.
1856 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1857 uint64_t item_flags,
1858 struct rte_eth_dev *dev,
1859 struct rte_flow_error *error)
1861 const struct rte_flow_item_vlan *spec = item->spec;
1862 const struct rte_flow_item_vlan *mask = item->mask;
1863 const struct rte_flow_item_vlan nic_mask = {
1864 .tci = RTE_BE16(UINT16_MAX),
1865 .inner_type = RTE_BE16(UINT16_MAX),
1867 uint16_t vlan_tag = 0;
1868 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1870 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1871 MLX5_FLOW_LAYER_INNER_L4) :
1872 (MLX5_FLOW_LAYER_OUTER_L3 |
1873 MLX5_FLOW_LAYER_OUTER_L4);
1874 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1875 MLX5_FLOW_LAYER_OUTER_VLAN;
1877 if (item_flags & vlanm)
1878 return rte_flow_error_set(error, EINVAL,
1879 RTE_FLOW_ERROR_TYPE_ITEM, item,
1880 "multiple VLAN layers not supported");
1881 else if ((item_flags & l34m) != 0)
1882 return rte_flow_error_set(error, EINVAL,
1883 RTE_FLOW_ERROR_TYPE_ITEM, item,
1884 "VLAN cannot follow L3/L4 layer");
1886 mask = &rte_flow_item_vlan_mask;
1887 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1888 (const uint8_t *)&nic_mask,
1889 sizeof(struct rte_flow_item_vlan),
1890 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1893 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1894 struct mlx5_priv *priv = dev->data->dev_private;
1896 if (priv->vmwa_context) {
1898 * Non-NULL context means we have a virtual machine
1899 * and SR-IOV enabled, we have to create VLAN interface
1900 * to make hypervisor to setup E-Switch vport
1901 * context correctly. We avoid creating the multiple
1902 * VLAN interfaces, so we cannot support VLAN tag mask.
1904 return rte_flow_error_set(error, EINVAL,
1905 RTE_FLOW_ERROR_TYPE_ITEM,
1907 "VLAN tag mask is not"
1908 " supported in virtual"
1913 vlan_tag = spec->tci;
1914 vlan_tag &= mask->tci;
1917 * From verbs perspective an empty VLAN is equivalent
1918 * to a packet without VLAN layer.
1921 return rte_flow_error_set(error, EINVAL,
1922 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1924 "VLAN cannot be empty");
1929 * Validate IPV4 item.
1932 * Item specification.
1933 * @param[in] item_flags
1934 * Bit-fields that holds the items detected until now.
1935 * @param[in] last_item
1936 * Previous validated item in the pattern items.
1937 * @param[in] ether_type
1938 * Type in the ethernet layer header (including dot1q).
1939 * @param[in] acc_mask
1940 * Acceptable mask, if NULL default internal default mask
1941 * will be used to check whether item fields are supported.
1942 * @param[in] range_accepted
1943 * True if range of values is accepted for specific fields, false otherwise.
1945 * Pointer to error structure.
1948 * 0 on success, a negative errno value otherwise and rte_errno is set.
1951 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1952 uint64_t item_flags,
1954 uint16_t ether_type,
1955 const struct rte_flow_item_ipv4 *acc_mask,
1956 bool range_accepted,
1957 struct rte_flow_error *error)
1959 const struct rte_flow_item_ipv4 *mask = item->mask;
1960 const struct rte_flow_item_ipv4 *spec = item->spec;
1961 const struct rte_flow_item_ipv4 nic_mask = {
1963 .src_addr = RTE_BE32(0xffffffff),
1964 .dst_addr = RTE_BE32(0xffffffff),
1965 .type_of_service = 0xff,
1966 .next_proto_id = 0xff,
1969 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1970 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1971 MLX5_FLOW_LAYER_OUTER_L3;
1972 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1973 MLX5_FLOW_LAYER_OUTER_L4;
1975 uint8_t next_proto = 0xFF;
1976 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1977 MLX5_FLOW_LAYER_OUTER_VLAN |
1978 MLX5_FLOW_LAYER_INNER_VLAN);
1980 if ((last_item & l2_vlan) && ether_type &&
1981 ether_type != RTE_ETHER_TYPE_IPV4)
1982 return rte_flow_error_set(error, EINVAL,
1983 RTE_FLOW_ERROR_TYPE_ITEM, item,
1984 "IPv4 cannot follow L2/VLAN layer "
1985 "which ether type is not IPv4");
1986 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1988 next_proto = mask->hdr.next_proto_id &
1989 spec->hdr.next_proto_id;
1990 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1991 return rte_flow_error_set(error, EINVAL,
1992 RTE_FLOW_ERROR_TYPE_ITEM,
1997 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1998 return rte_flow_error_set(error, EINVAL,
1999 RTE_FLOW_ERROR_TYPE_ITEM, item,
2000 "wrong tunnel type - IPv6 specified "
2001 "but IPv4 item provided");
2002 if (item_flags & l3m)
2003 return rte_flow_error_set(error, ENOTSUP,
2004 RTE_FLOW_ERROR_TYPE_ITEM, item,
2005 "multiple L3 layers not supported");
2006 else if (item_flags & l4m)
2007 return rte_flow_error_set(error, EINVAL,
2008 RTE_FLOW_ERROR_TYPE_ITEM, item,
2009 "L3 cannot follow an L4 layer.");
2010 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2011 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2012 return rte_flow_error_set(error, EINVAL,
2013 RTE_FLOW_ERROR_TYPE_ITEM, item,
2014 "L3 cannot follow an NVGRE layer.");
2016 mask = &rte_flow_item_ipv4_mask;
2017 else if (mask->hdr.next_proto_id != 0 &&
2018 mask->hdr.next_proto_id != 0xff)
2019 return rte_flow_error_set(error, EINVAL,
2020 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2021 "partial mask is not supported"
2023 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2024 acc_mask ? (const uint8_t *)acc_mask
2025 : (const uint8_t *)&nic_mask,
2026 sizeof(struct rte_flow_item_ipv4),
2027 range_accepted, error);
2034 * Validate IPV6 item.
2037 * Item specification.
2038 * @param[in] item_flags
2039 * Bit-fields that holds the items detected until now.
2040 * @param[in] last_item
2041 * Previous validated item in the pattern items.
2042 * @param[in] ether_type
2043 * Type in the ethernet layer header (including dot1q).
2044 * @param[in] acc_mask
2045 * Acceptable mask, if NULL default internal default mask
2046 * will be used to check whether item fields are supported.
2048 * Pointer to error structure.
2051 * 0 on success, a negative errno value otherwise and rte_errno is set.
2054 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
2055 uint64_t item_flags,
2057 uint16_t ether_type,
2058 const struct rte_flow_item_ipv6 *acc_mask,
2059 struct rte_flow_error *error)
2061 const struct rte_flow_item_ipv6 *mask = item->mask;
2062 const struct rte_flow_item_ipv6 *spec = item->spec;
2063 const struct rte_flow_item_ipv6 nic_mask = {
2066 "\xff\xff\xff\xff\xff\xff\xff\xff"
2067 "\xff\xff\xff\xff\xff\xff\xff\xff",
2069 "\xff\xff\xff\xff\xff\xff\xff\xff"
2070 "\xff\xff\xff\xff\xff\xff\xff\xff",
2071 .vtc_flow = RTE_BE32(0xffffffff),
2075 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2076 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2077 MLX5_FLOW_LAYER_OUTER_L3;
2078 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2079 MLX5_FLOW_LAYER_OUTER_L4;
2081 uint8_t next_proto = 0xFF;
2082 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2083 MLX5_FLOW_LAYER_OUTER_VLAN |
2084 MLX5_FLOW_LAYER_INNER_VLAN);
2086 if ((last_item & l2_vlan) && ether_type &&
2087 ether_type != RTE_ETHER_TYPE_IPV6)
2088 return rte_flow_error_set(error, EINVAL,
2089 RTE_FLOW_ERROR_TYPE_ITEM, item,
2090 "IPv6 cannot follow L2/VLAN layer "
2091 "which ether type is not IPv6");
2092 if (mask && mask->hdr.proto == UINT8_MAX && spec)
2093 next_proto = spec->hdr.proto;
2094 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
2095 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2096 return rte_flow_error_set(error, EINVAL,
2097 RTE_FLOW_ERROR_TYPE_ITEM,
2102 if (next_proto == IPPROTO_HOPOPTS ||
2103 next_proto == IPPROTO_ROUTING ||
2104 next_proto == IPPROTO_FRAGMENT ||
2105 next_proto == IPPROTO_ESP ||
2106 next_proto == IPPROTO_AH ||
2107 next_proto == IPPROTO_DSTOPTS)
2108 return rte_flow_error_set(error, EINVAL,
2109 RTE_FLOW_ERROR_TYPE_ITEM, item,
2110 "IPv6 proto (next header) should "
2111 "not be set as extension header");
2112 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2113 return rte_flow_error_set(error, EINVAL,
2114 RTE_FLOW_ERROR_TYPE_ITEM, item,
2115 "wrong tunnel type - IPv4 specified "
2116 "but IPv6 item provided");
2117 if (item_flags & l3m)
2118 return rte_flow_error_set(error, ENOTSUP,
2119 RTE_FLOW_ERROR_TYPE_ITEM, item,
2120 "multiple L3 layers not supported");
2121 else if (item_flags & l4m)
2122 return rte_flow_error_set(error, EINVAL,
2123 RTE_FLOW_ERROR_TYPE_ITEM, item,
2124 "L3 cannot follow an L4 layer.");
2125 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2126 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2127 return rte_flow_error_set(error, EINVAL,
2128 RTE_FLOW_ERROR_TYPE_ITEM, item,
2129 "L3 cannot follow an NVGRE layer.");
2131 mask = &rte_flow_item_ipv6_mask;
2132 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2133 acc_mask ? (const uint8_t *)acc_mask
2134 : (const uint8_t *)&nic_mask,
2135 sizeof(struct rte_flow_item_ipv6),
2136 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2143 * Validate UDP item.
2146 * Item specification.
2147 * @param[in] item_flags
2148 * Bit-fields that holds the items detected until now.
2149 * @param[in] target_protocol
2150 * The next protocol in the previous item.
2151 * @param[in] flow_mask
2152 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2154 * Pointer to error structure.
2157 * 0 on success, a negative errno value otherwise and rte_errno is set.
2160 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2161 uint64_t item_flags,
2162 uint8_t target_protocol,
2163 struct rte_flow_error *error)
2165 const struct rte_flow_item_udp *mask = item->mask;
2166 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2167 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2168 MLX5_FLOW_LAYER_OUTER_L3;
2169 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2170 MLX5_FLOW_LAYER_OUTER_L4;
2173 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2174 return rte_flow_error_set(error, EINVAL,
2175 RTE_FLOW_ERROR_TYPE_ITEM, item,
2176 "protocol filtering not compatible"
2178 if (!(item_flags & l3m))
2179 return rte_flow_error_set(error, EINVAL,
2180 RTE_FLOW_ERROR_TYPE_ITEM, item,
2181 "L3 is mandatory to filter on L4");
2182 if (item_flags & l4m)
2183 return rte_flow_error_set(error, EINVAL,
2184 RTE_FLOW_ERROR_TYPE_ITEM, item,
2185 "multiple L4 layers not supported");
2187 mask = &rte_flow_item_udp_mask;
2188 ret = mlx5_flow_item_acceptable
2189 (item, (const uint8_t *)mask,
2190 (const uint8_t *)&rte_flow_item_udp_mask,
2191 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2199 * Validate TCP item.
2202 * Item specification.
2203 * @param[in] item_flags
2204 * Bit-fields that holds the items detected until now.
2205 * @param[in] target_protocol
2206 * The next protocol in the previous item.
2208 * Pointer to error structure.
2211 * 0 on success, a negative errno value otherwise and rte_errno is set.
2214 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2215 uint64_t item_flags,
2216 uint8_t target_protocol,
2217 const struct rte_flow_item_tcp *flow_mask,
2218 struct rte_flow_error *error)
2220 const struct rte_flow_item_tcp *mask = item->mask;
2221 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2222 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2223 MLX5_FLOW_LAYER_OUTER_L3;
2224 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2225 MLX5_FLOW_LAYER_OUTER_L4;
2228 MLX5_ASSERT(flow_mask);
2229 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2230 return rte_flow_error_set(error, EINVAL,
2231 RTE_FLOW_ERROR_TYPE_ITEM, item,
2232 "protocol filtering not compatible"
2234 if (!(item_flags & l3m))
2235 return rte_flow_error_set(error, EINVAL,
2236 RTE_FLOW_ERROR_TYPE_ITEM, item,
2237 "L3 is mandatory to filter on L4");
2238 if (item_flags & l4m)
2239 return rte_flow_error_set(error, EINVAL,
2240 RTE_FLOW_ERROR_TYPE_ITEM, item,
2241 "multiple L4 layers not supported");
2243 mask = &rte_flow_item_tcp_mask;
2244 ret = mlx5_flow_item_acceptable
2245 (item, (const uint8_t *)mask,
2246 (const uint8_t *)flow_mask,
2247 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2255 * Validate VXLAN item.
2258 * Item specification.
2259 * @param[in] item_flags
2260 * Bit-fields that holds the items detected until now.
2261 * @param[in] target_protocol
2262 * The next protocol in the previous item.
2264 * Pointer to error structure.
2267 * 0 on success, a negative errno value otherwise and rte_errno is set.
2270 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
2271 uint64_t item_flags,
2272 struct rte_flow_error *error)
2274 const struct rte_flow_item_vxlan *spec = item->spec;
2275 const struct rte_flow_item_vxlan *mask = item->mask;
2280 } id = { .vlan_id = 0, };
2283 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2284 return rte_flow_error_set(error, ENOTSUP,
2285 RTE_FLOW_ERROR_TYPE_ITEM, item,
2286 "multiple tunnel layers not"
2289 * Verify only UDPv4 is present as defined in
2290 * https://tools.ietf.org/html/rfc7348
2292 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2293 return rte_flow_error_set(error, EINVAL,
2294 RTE_FLOW_ERROR_TYPE_ITEM, item,
2295 "no outer UDP layer found");
2297 mask = &rte_flow_item_vxlan_mask;
2298 ret = mlx5_flow_item_acceptable
2299 (item, (const uint8_t *)mask,
2300 (const uint8_t *)&rte_flow_item_vxlan_mask,
2301 sizeof(struct rte_flow_item_vxlan),
2302 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2306 memcpy(&id.vni[1], spec->vni, 3);
2307 memcpy(&id.vni[1], mask->vni, 3);
2309 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2310 return rte_flow_error_set(error, ENOTSUP,
2311 RTE_FLOW_ERROR_TYPE_ITEM, item,
2312 "VXLAN tunnel must be fully defined");
2317 * Validate VXLAN_GPE item.
2320 * Item specification.
2321 * @param[in] item_flags
2322 * Bit-fields that holds the items detected until now.
2324 * Pointer to the private data structure.
2325 * @param[in] target_protocol
2326 * The next protocol in the previous item.
2328 * Pointer to error structure.
2331 * 0 on success, a negative errno value otherwise and rte_errno is set.
2334 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2335 uint64_t item_flags,
2336 struct rte_eth_dev *dev,
2337 struct rte_flow_error *error)
2339 struct mlx5_priv *priv = dev->data->dev_private;
2340 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2341 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2346 } id = { .vlan_id = 0, };
2348 if (!priv->config.l3_vxlan_en)
2349 return rte_flow_error_set(error, ENOTSUP,
2350 RTE_FLOW_ERROR_TYPE_ITEM, item,
2351 "L3 VXLAN is not enabled by device"
2352 " parameter and/or not configured in"
2354 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2355 return rte_flow_error_set(error, ENOTSUP,
2356 RTE_FLOW_ERROR_TYPE_ITEM, item,
2357 "multiple tunnel layers not"
2360 * Verify only UDPv4 is present as defined in
2361 * https://tools.ietf.org/html/rfc7348
2363 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2364 return rte_flow_error_set(error, EINVAL,
2365 RTE_FLOW_ERROR_TYPE_ITEM, item,
2366 "no outer UDP layer found");
2368 mask = &rte_flow_item_vxlan_gpe_mask;
2369 ret = mlx5_flow_item_acceptable
2370 (item, (const uint8_t *)mask,
2371 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2372 sizeof(struct rte_flow_item_vxlan_gpe),
2373 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2378 return rte_flow_error_set(error, ENOTSUP,
2379 RTE_FLOW_ERROR_TYPE_ITEM,
2381 "VxLAN-GPE protocol"
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-GPE tunnel must be fully"
2394 * Validate GRE Key item.
2397 * Item specification.
2398 * @param[in] item_flags
2399 * Bit flags to mark detected items.
2400 * @param[in] gre_item
2401 * Pointer to gre_item
2403 * Pointer to error structure.
2406 * 0 on success, a negative errno value otherwise and rte_errno is set.
2409 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2410 uint64_t item_flags,
2411 const struct rte_flow_item *gre_item,
2412 struct rte_flow_error *error)
2414 const rte_be32_t *mask = item->mask;
2416 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2417 const struct rte_flow_item_gre *gre_spec;
2418 const struct rte_flow_item_gre *gre_mask;
2420 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2421 return rte_flow_error_set(error, ENOTSUP,
2422 RTE_FLOW_ERROR_TYPE_ITEM, item,
2423 "Multiple GRE key not support");
2424 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2425 return rte_flow_error_set(error, ENOTSUP,
2426 RTE_FLOW_ERROR_TYPE_ITEM, item,
2427 "No preceding GRE header");
2428 if (item_flags & MLX5_FLOW_LAYER_INNER)
2429 return rte_flow_error_set(error, ENOTSUP,
2430 RTE_FLOW_ERROR_TYPE_ITEM, item,
2431 "GRE key following a wrong item");
2432 gre_mask = gre_item->mask;
2434 gre_mask = &rte_flow_item_gre_mask;
2435 gre_spec = gre_item->spec;
2436 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2437 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2438 return rte_flow_error_set(error, EINVAL,
2439 RTE_FLOW_ERROR_TYPE_ITEM, item,
2440 "Key bit must be on");
2443 mask = &gre_key_default_mask;
2444 ret = mlx5_flow_item_acceptable
2445 (item, (const uint8_t *)mask,
2446 (const uint8_t *)&gre_key_default_mask,
2447 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2452 * Validate GRE item.
2455 * Item specification.
2456 * @param[in] item_flags
2457 * Bit flags to mark detected items.
2458 * @param[in] target_protocol
2459 * The next protocol in the previous item.
2461 * Pointer to error structure.
2464 * 0 on success, a negative errno value otherwise and rte_errno is set.
2467 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2468 uint64_t item_flags,
2469 uint8_t target_protocol,
2470 struct rte_flow_error *error)
2472 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2473 const struct rte_flow_item_gre *mask = item->mask;
2475 const struct rte_flow_item_gre nic_mask = {
2476 .c_rsvd0_ver = RTE_BE16(0xB000),
2477 .protocol = RTE_BE16(UINT16_MAX),
2480 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2481 return rte_flow_error_set(error, EINVAL,
2482 RTE_FLOW_ERROR_TYPE_ITEM, item,
2483 "protocol filtering not compatible"
2484 " with this GRE layer");
2485 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2486 return rte_flow_error_set(error, ENOTSUP,
2487 RTE_FLOW_ERROR_TYPE_ITEM, item,
2488 "multiple tunnel layers not"
2490 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2491 return rte_flow_error_set(error, ENOTSUP,
2492 RTE_FLOW_ERROR_TYPE_ITEM, item,
2493 "L3 Layer is missing");
2495 mask = &rte_flow_item_gre_mask;
2496 ret = mlx5_flow_item_acceptable
2497 (item, (const uint8_t *)mask,
2498 (const uint8_t *)&nic_mask,
2499 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2503 #ifndef HAVE_MLX5DV_DR
2504 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2505 if (spec && (spec->protocol & mask->protocol))
2506 return rte_flow_error_set(error, ENOTSUP,
2507 RTE_FLOW_ERROR_TYPE_ITEM, item,
2508 "without MPLS support the"
2509 " specification cannot be used for"
2517 * Validate Geneve item.
2520 * Item specification.
2521 * @param[in] itemFlags
2522 * Bit-fields that holds the items detected until now.
2524 * Pointer to the private data structure.
2526 * Pointer to error structure.
2529 * 0 on success, a negative errno value otherwise and rte_errno is set.
2533 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2534 uint64_t item_flags,
2535 struct rte_eth_dev *dev,
2536 struct rte_flow_error *error)
2538 struct mlx5_priv *priv = dev->data->dev_private;
2539 const struct rte_flow_item_geneve *spec = item->spec;
2540 const struct rte_flow_item_geneve *mask = item->mask;
2543 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2544 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2545 const struct rte_flow_item_geneve nic_mask = {
2546 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2547 .vni = "\xff\xff\xff",
2548 .protocol = RTE_BE16(UINT16_MAX),
2551 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2552 return rte_flow_error_set(error, ENOTSUP,
2553 RTE_FLOW_ERROR_TYPE_ITEM, item,
2554 "L3 Geneve is not enabled by device"
2555 " parameter and/or not configured in"
2557 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2558 return rte_flow_error_set(error, ENOTSUP,
2559 RTE_FLOW_ERROR_TYPE_ITEM, item,
2560 "multiple tunnel layers not"
2563 * Verify only UDPv4 is present as defined in
2564 * https://tools.ietf.org/html/rfc7348
2566 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2567 return rte_flow_error_set(error, EINVAL,
2568 RTE_FLOW_ERROR_TYPE_ITEM, item,
2569 "no outer UDP layer found");
2571 mask = &rte_flow_item_geneve_mask;
2572 ret = mlx5_flow_item_acceptable
2573 (item, (const uint8_t *)mask,
2574 (const uint8_t *)&nic_mask,
2575 sizeof(struct rte_flow_item_geneve),
2576 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2580 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2581 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2582 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2583 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2584 return rte_flow_error_set(error, ENOTSUP,
2585 RTE_FLOW_ERROR_TYPE_ITEM,
2587 "Geneve protocol unsupported"
2588 " fields are being used");
2589 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2590 return rte_flow_error_set
2592 RTE_FLOW_ERROR_TYPE_ITEM,
2594 "Unsupported Geneve options length");
2596 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2597 return rte_flow_error_set
2599 RTE_FLOW_ERROR_TYPE_ITEM, item,
2600 "Geneve tunnel must be fully defined");
2605 * Validate MPLS item.
2608 * Pointer to the rte_eth_dev structure.
2610 * Item specification.
2611 * @param[in] item_flags
2612 * Bit-fields that holds the items detected until now.
2613 * @param[in] prev_layer
2614 * The protocol layer indicated in previous item.
2616 * Pointer to error structure.
2619 * 0 on success, a negative errno value otherwise and rte_errno is set.
2622 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2623 const struct rte_flow_item *item __rte_unused,
2624 uint64_t item_flags __rte_unused,
2625 uint64_t prev_layer __rte_unused,
2626 struct rte_flow_error *error)
2628 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2629 const struct rte_flow_item_mpls *mask = item->mask;
2630 struct mlx5_priv *priv = dev->data->dev_private;
2633 if (!priv->config.mpls_en)
2634 return rte_flow_error_set(error, ENOTSUP,
2635 RTE_FLOW_ERROR_TYPE_ITEM, item,
2636 "MPLS not supported or"
2637 " disabled in firmware"
2639 /* MPLS over IP, UDP, GRE is allowed */
2640 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2641 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2642 MLX5_FLOW_LAYER_GRE |
2643 MLX5_FLOW_LAYER_GRE_KEY)))
2644 return rte_flow_error_set(error, EINVAL,
2645 RTE_FLOW_ERROR_TYPE_ITEM, item,
2646 "protocol filtering not compatible"
2647 " with MPLS layer");
2648 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2649 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2650 !(item_flags & MLX5_FLOW_LAYER_GRE))
2651 return rte_flow_error_set(error, ENOTSUP,
2652 RTE_FLOW_ERROR_TYPE_ITEM, item,
2653 "multiple tunnel layers not"
2656 mask = &rte_flow_item_mpls_mask;
2657 ret = mlx5_flow_item_acceptable
2658 (item, (const uint8_t *)mask,
2659 (const uint8_t *)&rte_flow_item_mpls_mask,
2660 sizeof(struct rte_flow_item_mpls),
2661 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2666 return rte_flow_error_set(error, ENOTSUP,
2667 RTE_FLOW_ERROR_TYPE_ITEM, item,
2668 "MPLS is not supported by Verbs, please"
2674 * Validate NVGRE item.
2677 * Item specification.
2678 * @param[in] item_flags
2679 * Bit flags to mark detected items.
2680 * @param[in] target_protocol
2681 * The next protocol in the previous item.
2683 * Pointer to error structure.
2686 * 0 on success, a negative errno value otherwise and rte_errno is set.
2689 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2690 uint64_t item_flags,
2691 uint8_t target_protocol,
2692 struct rte_flow_error *error)
2694 const struct rte_flow_item_nvgre *mask = item->mask;
2697 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2698 return rte_flow_error_set(error, EINVAL,
2699 RTE_FLOW_ERROR_TYPE_ITEM, item,
2700 "protocol filtering not compatible"
2701 " with this GRE layer");
2702 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2703 return rte_flow_error_set(error, ENOTSUP,
2704 RTE_FLOW_ERROR_TYPE_ITEM, item,
2705 "multiple tunnel layers not"
2707 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2708 return rte_flow_error_set(error, ENOTSUP,
2709 RTE_FLOW_ERROR_TYPE_ITEM, item,
2710 "L3 Layer is missing");
2712 mask = &rte_flow_item_nvgre_mask;
2713 ret = mlx5_flow_item_acceptable
2714 (item, (const uint8_t *)mask,
2715 (const uint8_t *)&rte_flow_item_nvgre_mask,
2716 sizeof(struct rte_flow_item_nvgre),
2717 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2724 * Validate eCPRI item.
2727 * Item specification.
2728 * @param[in] item_flags
2729 * Bit-fields that holds the items detected until now.
2730 * @param[in] last_item
2731 * Previous validated item in the pattern items.
2732 * @param[in] ether_type
2733 * Type in the ethernet layer header (including dot1q).
2734 * @param[in] acc_mask
2735 * Acceptable mask, if NULL default internal default mask
2736 * will be used to check whether item fields are supported.
2738 * Pointer to error structure.
2741 * 0 on success, a negative errno value otherwise and rte_errno is set.
2744 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
2745 uint64_t item_flags,
2747 uint16_t ether_type,
2748 const struct rte_flow_item_ecpri *acc_mask,
2749 struct rte_flow_error *error)
2751 const struct rte_flow_item_ecpri *mask = item->mask;
2752 const struct rte_flow_item_ecpri nic_mask = {
2756 RTE_BE32(((const struct rte_ecpri_common_hdr) {
2760 .dummy[0] = 0xFFFFFFFF,
2763 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
2764 MLX5_FLOW_LAYER_OUTER_VLAN);
2765 struct rte_flow_item_ecpri mask_lo;
2767 if (!(last_item & outer_l2_vlan) &&
2768 last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
2769 return rte_flow_error_set(error, EINVAL,
2770 RTE_FLOW_ERROR_TYPE_ITEM, item,
2771 "eCPRI can only follow L2/VLAN layer or UDP layer");
2772 if ((last_item & outer_l2_vlan) && ether_type &&
2773 ether_type != RTE_ETHER_TYPE_ECPRI)
2774 return rte_flow_error_set(error, EINVAL,
2775 RTE_FLOW_ERROR_TYPE_ITEM, item,
2776 "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
2777 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2778 return rte_flow_error_set(error, EINVAL,
2779 RTE_FLOW_ERROR_TYPE_ITEM, item,
2780 "eCPRI with tunnel is not supported right now");
2781 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
2782 return rte_flow_error_set(error, ENOTSUP,
2783 RTE_FLOW_ERROR_TYPE_ITEM, item,
2784 "multiple L3 layers not supported");
2785 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
2786 return rte_flow_error_set(error, EINVAL,
2787 RTE_FLOW_ERROR_TYPE_ITEM, item,
2788 "eCPRI cannot coexist with a TCP layer");
2789 /* In specification, eCPRI could be over UDP layer. */
2790 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
2791 return rte_flow_error_set(error, EINVAL,
2792 RTE_FLOW_ERROR_TYPE_ITEM, item,
2793 "eCPRI over UDP layer is not yet supported right now");
2794 /* Mask for type field in common header could be zero. */
2796 mask = &rte_flow_item_ecpri_mask;
2797 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
2798 /* Input mask is in big-endian format. */
2799 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
2800 return rte_flow_error_set(error, EINVAL,
2801 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2802 "partial mask is not supported for protocol");
2803 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
2804 return rte_flow_error_set(error, EINVAL,
2805 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2806 "message header mask must be after a type mask");
2807 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2808 acc_mask ? (const uint8_t *)acc_mask
2809 : (const uint8_t *)&nic_mask,
2810 sizeof(struct rte_flow_item_ecpri),
2811 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2815 * Release resource related QUEUE/RSS action split.
2818 * Pointer to Ethernet device.
2820 * Flow to release id's from.
2823 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2824 struct rte_flow *flow)
2826 struct mlx5_priv *priv = dev->data->dev_private;
2827 uint32_t handle_idx;
2828 struct mlx5_flow_handle *dev_handle;
2830 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
2831 handle_idx, dev_handle, next)
2832 if (dev_handle->split_flow_id)
2833 mlx5_ipool_free(priv->sh->ipool
2834 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
2835 dev_handle->split_flow_id);
2839 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2840 const struct rte_flow_attr *attr __rte_unused,
2841 const struct rte_flow_item items[] __rte_unused,
2842 const struct rte_flow_action actions[] __rte_unused,
2843 bool external __rte_unused,
2844 int hairpin __rte_unused,
2845 struct rte_flow_error *error)
2847 return rte_flow_error_set(error, ENOTSUP,
2848 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2851 static struct mlx5_flow *
2852 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
2853 const struct rte_flow_attr *attr __rte_unused,
2854 const struct rte_flow_item items[] __rte_unused,
2855 const struct rte_flow_action actions[] __rte_unused,
2856 struct rte_flow_error *error)
2858 rte_flow_error_set(error, ENOTSUP,
2859 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2864 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2865 struct mlx5_flow *dev_flow __rte_unused,
2866 const struct rte_flow_attr *attr __rte_unused,
2867 const struct rte_flow_item items[] __rte_unused,
2868 const struct rte_flow_action actions[] __rte_unused,
2869 struct rte_flow_error *error)
2871 return rte_flow_error_set(error, ENOTSUP,
2872 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2876 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2877 struct rte_flow *flow __rte_unused,
2878 struct rte_flow_error *error)
2880 return rte_flow_error_set(error, ENOTSUP,
2881 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2885 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2886 struct rte_flow *flow __rte_unused)
2891 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2892 struct rte_flow *flow __rte_unused)
2897 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2898 struct rte_flow *flow __rte_unused,
2899 const struct rte_flow_action *actions __rte_unused,
2900 void *data __rte_unused,
2901 struct rte_flow_error *error)
2903 return rte_flow_error_set(error, ENOTSUP,
2904 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2908 flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
2909 uint32_t domains __rte_unused,
2910 uint32_t flags __rte_unused)
2915 /* Void driver to protect from null pointer reference. */
2916 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2917 .validate = flow_null_validate,
2918 .prepare = flow_null_prepare,
2919 .translate = flow_null_translate,
2920 .apply = flow_null_apply,
2921 .remove = flow_null_remove,
2922 .destroy = flow_null_destroy,
2923 .query = flow_null_query,
2924 .sync_domain = flow_null_sync_domain,
2928 * Select flow driver type according to flow attributes and device
2932 * Pointer to the dev structure.
2934 * Pointer to the flow attributes.
2937 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2939 static enum mlx5_flow_drv_type
2940 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2942 struct mlx5_priv *priv = dev->data->dev_private;
2943 /* The OS can determine first a specific flow type (DV, VERBS) */
2944 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
2946 if (type != MLX5_FLOW_TYPE_MAX)
2948 /* If no OS specific type - continue with DV/VERBS selection */
2949 if (attr->transfer && priv->config.dv_esw_en)
2950 type = MLX5_FLOW_TYPE_DV;
2951 if (!attr->transfer)
2952 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2953 MLX5_FLOW_TYPE_VERBS;
2957 #define flow_get_drv_ops(type) flow_drv_ops[type]
2960 * Flow driver validation API. This abstracts calling driver specific functions.
2961 * The type of flow driver is determined according to flow attributes.
2964 * Pointer to the dev structure.
2966 * Pointer to the flow attributes.
2968 * Pointer to the list of items.
2969 * @param[in] actions
2970 * Pointer to the list of actions.
2971 * @param[in] external
2972 * This flow rule is created by request external to PMD.
2973 * @param[in] hairpin
2974 * Number of hairpin TX actions, 0 means classic flow.
2976 * Pointer to the error structure.
2979 * 0 on success, a negative errno value otherwise and rte_errno is set.
2982 flow_drv_validate(struct rte_eth_dev *dev,
2983 const struct rte_flow_attr *attr,
2984 const struct rte_flow_item items[],
2985 const struct rte_flow_action actions[],
2986 bool external, int hairpin, struct rte_flow_error *error)
2988 const struct mlx5_flow_driver_ops *fops;
2989 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2991 fops = flow_get_drv_ops(type);
2992 return fops->validate(dev, attr, items, actions, external,
2997 * Flow driver preparation API. This abstracts calling driver specific
2998 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2999 * calculates the size of memory required for device flow, allocates the memory,
3000 * initializes the device flow and returns the pointer.
3003 * This function initializes device flow structure such as dv or verbs in
3004 * struct mlx5_flow. However, it is caller's responsibility to initialize the
3005 * rest. For example, adding returning device flow to flow->dev_flow list and
3006 * setting backward reference to the flow should be done out of this function.
3007 * layers field is not filled either.
3010 * Pointer to the dev structure.
3012 * Pointer to the flow attributes.
3014 * Pointer to the list of items.
3015 * @param[in] actions
3016 * Pointer to the list of actions.
3017 * @param[in] flow_idx
3018 * This memory pool index to the flow.
3020 * Pointer to the error structure.
3023 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
3025 static inline struct mlx5_flow *
3026 flow_drv_prepare(struct rte_eth_dev *dev,
3027 const struct rte_flow *flow,
3028 const struct rte_flow_attr *attr,
3029 const struct rte_flow_item items[],
3030 const struct rte_flow_action actions[],
3032 struct rte_flow_error *error)
3034 const struct mlx5_flow_driver_ops *fops;
3035 enum mlx5_flow_drv_type type = flow->drv_type;
3036 struct mlx5_flow *mlx5_flow = NULL;
3038 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3039 fops = flow_get_drv_ops(type);
3040 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
3042 mlx5_flow->flow_idx = flow_idx;
3047 * Flow driver translation API. This abstracts calling driver specific
3048 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
3049 * translates a generic flow into a driver flow. flow_drv_prepare() must
3053 * dev_flow->layers could be filled as a result of parsing during translation
3054 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
3055 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
3056 * flow->actions could be overwritten even though all the expanded dev_flows
3057 * have the same actions.
3060 * Pointer to the rte dev structure.
3061 * @param[in, out] dev_flow
3062 * Pointer to the mlx5 flow.
3064 * Pointer to the flow attributes.
3066 * Pointer to the list of items.
3067 * @param[in] actions
3068 * Pointer to the list of actions.
3070 * Pointer to the error structure.
3073 * 0 on success, a negative errno value otherwise and rte_errno is set.
3076 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
3077 const struct rte_flow_attr *attr,
3078 const struct rte_flow_item items[],
3079 const struct rte_flow_action actions[],
3080 struct rte_flow_error *error)
3082 const struct mlx5_flow_driver_ops *fops;
3083 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
3085 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3086 fops = flow_get_drv_ops(type);
3087 return fops->translate(dev, dev_flow, attr, items, actions, error);
3091 * Flow driver apply API. This abstracts calling driver specific functions.
3092 * Parent flow (rte_flow) should have driver type (drv_type). It applies
3093 * translated driver flows on to device. flow_drv_translate() must precede.
3096 * Pointer to Ethernet device structure.
3097 * @param[in, out] flow
3098 * Pointer to flow structure.
3100 * Pointer to error structure.
3103 * 0 on success, a negative errno value otherwise and rte_errno is set.
3106 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3107 struct rte_flow_error *error)
3109 const struct mlx5_flow_driver_ops *fops;
3110 enum mlx5_flow_drv_type type = flow->drv_type;
3112 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3113 fops = flow_get_drv_ops(type);
3114 return fops->apply(dev, flow, error);
3118 * Flow driver destroy API. This abstracts calling driver specific functions.
3119 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3120 * on device and releases resources of the flow.
3123 * Pointer to Ethernet device.
3124 * @param[in, out] flow
3125 * Pointer to flow structure.
3128 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3130 const struct mlx5_flow_driver_ops *fops;
3131 enum mlx5_flow_drv_type type = flow->drv_type;
3133 flow_mreg_split_qrss_release(dev, flow);
3134 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3135 fops = flow_get_drv_ops(type);
3136 fops->destroy(dev, flow);
3140 * Get RSS action from the action list.
3142 * @param[in] actions
3143 * Pointer to the list of actions.
3146 * Pointer to the RSS action if exist, else return NULL.
3148 static const struct rte_flow_action_rss*
3149 flow_get_rss_action(const struct rte_flow_action actions[])
3151 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3152 switch (actions->type) {
3153 case RTE_FLOW_ACTION_TYPE_RSS:
3154 return (const struct rte_flow_action_rss *)
3164 * Get ASO age action by index.
3167 * Pointer to the Ethernet device structure.
3168 * @param[in] age_idx
3169 * Index to the ASO age action.
3172 * The specified ASO age action.
3174 struct mlx5_aso_age_action*
3175 flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
3177 uint16_t pool_idx = age_idx & UINT16_MAX;
3178 uint16_t offset = (age_idx >> 16) & UINT16_MAX;
3179 struct mlx5_priv *priv = dev->data->dev_private;
3180 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
3181 struct mlx5_aso_age_pool *pool = mng->pools[pool_idx];
3183 return &pool->actions[offset - 1];
3186 /* maps shared action to translated non shared in some actions array */
3187 struct mlx5_translated_shared_action {
3188 struct rte_flow_shared_action *action; /**< Shared action */
3189 int index; /**< Index in related array of rte_flow_action */
3193 * Translates actions of type RTE_FLOW_ACTION_TYPE_SHARED to related
3194 * non shared action if translation possible.
3195 * This functionality used to run same execution path for both shared & non
3196 * shared actions on flow create. All necessary preparations for shared
3197 * action handling should be preformed on *shared* actions list returned
3201 * Pointer to Ethernet device.
3202 * @param[in] actions
3203 * List of actions to translate.
3204 * @param[out] shared
3205 * List to store translated shared actions.
3206 * @param[in, out] shared_n
3207 * Size of *shared* array. On return should be updated with number of shared
3208 * actions retrieved from the *actions* list.
3209 * @param[out] translated_actions
3210 * List of actions where all shared actions were translated to non shared
3211 * if possible. NULL if no translation took place.
3213 * Pointer to the error structure.
3216 * 0 on success, a negative errno value otherwise and rte_errno is set.
3219 flow_shared_actions_translate(struct rte_eth_dev *dev,
3220 const struct rte_flow_action actions[],
3221 struct mlx5_translated_shared_action *shared,
3223 struct rte_flow_action **translated_actions,
3224 struct rte_flow_error *error)
3226 struct mlx5_priv *priv = dev->data->dev_private;
3227 struct rte_flow_action *translated = NULL;
3228 size_t actions_size;
3231 struct mlx5_translated_shared_action *shared_end = NULL;
3233 for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
3234 if (actions[n].type != RTE_FLOW_ACTION_TYPE_SHARED)
3236 if (copied_n == *shared_n) {
3237 return rte_flow_error_set
3238 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
3239 NULL, "too many shared actions");
3241 rte_memcpy(&shared[copied_n].action, &actions[n].conf,
3242 sizeof(actions[n].conf));
3243 shared[copied_n].index = n;
3247 *shared_n = copied_n;
3250 actions_size = sizeof(struct rte_flow_action) * n;
3251 translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
3256 memcpy(translated, actions, actions_size);
3257 for (shared_end = shared + copied_n; shared < shared_end; shared++) {
3258 struct mlx5_shared_action_rss *shared_rss;
3259 uint32_t act_idx = (uint32_t)(uintptr_t)shared->action;
3260 uint32_t type = act_idx >> MLX5_SHARED_ACTION_TYPE_OFFSET;
3261 uint32_t idx = act_idx & ((1u << MLX5_SHARED_ACTION_TYPE_OFFSET)
3265 case MLX5_SHARED_ACTION_TYPE_RSS:
3266 shared_rss = mlx5_ipool_get
3267 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
3268 translated[shared->index].type =
3269 RTE_FLOW_ACTION_TYPE_RSS;
3270 translated[shared->index].conf =
3271 &shared_rss->origin;
3273 case MLX5_SHARED_ACTION_TYPE_AGE:
3274 if (priv->sh->flow_hit_aso_en) {
3275 translated[shared->index].type =
3276 (enum rte_flow_action_type)
3277 MLX5_RTE_FLOW_ACTION_TYPE_AGE;
3278 translated[shared->index].conf =
3279 (void *)(uintptr_t)idx;
3284 mlx5_free(translated);
3285 return rte_flow_error_set
3286 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3287 NULL, "invalid shared action type");
3290 *translated_actions = translated;
3295 * Get Shared RSS action from the action list.
3298 * Pointer to Ethernet device.
3300 * Pointer to the list of actions.
3301 * @param[in] shared_n
3302 * Actions list length.
3305 * The MLX5 RSS action ID if exists, otherwise return 0.
3308 flow_get_shared_rss_action(struct rte_eth_dev *dev,
3309 struct mlx5_translated_shared_action *shared,
3312 struct mlx5_translated_shared_action *shared_end;
3313 struct mlx5_priv *priv = dev->data->dev_private;
3314 struct mlx5_shared_action_rss *shared_rss;
3317 for (shared_end = shared + shared_n; shared < shared_end; shared++) {
3318 uint32_t act_idx = (uint32_t)(uintptr_t)shared->action;
3319 uint32_t type = act_idx >> MLX5_SHARED_ACTION_TYPE_OFFSET;
3320 uint32_t idx = act_idx &
3321 ((1u << MLX5_SHARED_ACTION_TYPE_OFFSET) - 1);
3323 case MLX5_SHARED_ACTION_TYPE_RSS:
3324 shared_rss = mlx5_ipool_get
3325 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
3327 __atomic_add_fetch(&shared_rss->refcnt, 1,
3338 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3340 const struct rte_flow_item *item;
3341 unsigned int has_vlan = 0;
3343 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3344 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3350 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3351 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3352 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3353 MLX5_EXPANSION_ROOT_OUTER;
3357 * Get layer flags from the prefix flow.
3359 * Some flows may be split to several subflows, the prefix subflow gets the
3360 * match items and the suffix sub flow gets the actions.
3361 * Some actions need the user defined match item flags to get the detail for
3363 * This function helps the suffix flow to get the item layer flags from prefix
3366 * @param[in] dev_flow
3367 * Pointer the created preifx subflow.
3370 * The layers get from prefix subflow.
3372 static inline uint64_t
3373 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3375 uint64_t layers = 0;
3378 * Layers bits could be localization, but usually the compiler will
3379 * help to do the optimization work for source code.
3380 * If no decap actions, use the layers directly.
3382 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3383 return dev_flow->handle->layers;
3384 /* Convert L3 layers with decap action. */
3385 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3386 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3387 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3388 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3389 /* Convert L4 layers with decap action. */
3390 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3391 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3392 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3393 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3398 * Get metadata split action information.
3400 * @param[in] actions
3401 * Pointer to the list of actions.
3403 * Pointer to the return pointer.
3404 * @param[out] qrss_type
3405 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3406 * if no QUEUE/RSS is found.
3407 * @param[out] encap_idx
3408 * Pointer to the index of the encap action if exists, otherwise the last
3412 * Total number of actions.
3415 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3416 const struct rte_flow_action **qrss,
3419 const struct rte_flow_action_raw_encap *raw_encap;
3421 int raw_decap_idx = -1;
3424 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3425 switch (actions->type) {
3426 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3427 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3428 *encap_idx = actions_n;
3430 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3431 raw_decap_idx = actions_n;
3433 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3434 raw_encap = actions->conf;
3435 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3436 *encap_idx = raw_decap_idx != -1 ?
3437 raw_decap_idx : actions_n;
3439 case RTE_FLOW_ACTION_TYPE_QUEUE:
3440 case RTE_FLOW_ACTION_TYPE_RSS:
3448 if (*encap_idx == -1)
3449 *encap_idx = actions_n;
3450 /* Count RTE_FLOW_ACTION_TYPE_END. */
3451 return actions_n + 1;
3455 * Check meter action from the action list.
3457 * @param[in] actions
3458 * Pointer to the list of actions.
3460 * Pointer to the meter exist flag.
3463 * Total number of actions.
3466 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
3472 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3473 switch (actions->type) {
3474 case RTE_FLOW_ACTION_TYPE_METER:
3482 /* Count RTE_FLOW_ACTION_TYPE_END. */
3483 return actions_n + 1;
3487 * Check if the flow should be split due to hairpin.
3488 * The reason for the split is that in current HW we can't
3489 * support encap and push-vlan on Rx, so if a flow contains
3490 * these actions we move it to Tx.
3493 * Pointer to Ethernet device.
3495 * Flow rule attributes.
3496 * @param[in] actions
3497 * Associated actions (list terminated by the END action).
3500 * > 0 the number of actions and the flow should be split,
3501 * 0 when no split required.
3504 flow_check_hairpin_split(struct rte_eth_dev *dev,
3505 const struct rte_flow_attr *attr,
3506 const struct rte_flow_action actions[])
3508 int queue_action = 0;
3511 const struct rte_flow_action_queue *queue;
3512 const struct rte_flow_action_rss *rss;
3513 const struct rte_flow_action_raw_encap *raw_encap;
3514 const struct rte_eth_hairpin_conf *conf;
3518 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3519 switch (actions->type) {
3520 case RTE_FLOW_ACTION_TYPE_QUEUE:
3521 queue = actions->conf;
3524 conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
3525 if (conf != NULL && !!conf->tx_explicit)
3530 case RTE_FLOW_ACTION_TYPE_RSS:
3531 rss = actions->conf;
3532 if (rss == NULL || rss->queue_num == 0)
3534 conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
3535 if (conf != NULL && !!conf->tx_explicit)
3540 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3541 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3542 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3543 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3544 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3548 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3549 raw_encap = actions->conf;
3550 if (raw_encap->size >
3551 (sizeof(struct rte_flow_item_eth) +
3552 sizeof(struct rte_flow_item_ipv4)))
3561 if (split && queue_action)
3566 /* Declare flow create/destroy prototype in advance. */
3568 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
3569 const struct rte_flow_attr *attr,
3570 const struct rte_flow_item items[],
3571 const struct rte_flow_action actions[],
3572 bool external, struct rte_flow_error *error);
3575 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
3578 struct mlx5_hlist_entry *
3579 flow_dv_mreg_create_cb(struct mlx5_hlist *list, uint64_t key,
3582 struct rte_eth_dev *dev = list->ctx;
3583 struct mlx5_priv *priv = dev->data->dev_private;
3584 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3585 struct mlx5_flow_mreg_copy_resource *mcp_res;
3586 struct rte_flow_error *error = ctx->error;
3589 uint32_t mark_id = key;
3590 struct rte_flow_attr attr = {
3591 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3594 struct mlx5_rte_flow_item_tag tag_spec = {
3597 struct rte_flow_item items[] = {
3598 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
3600 struct rte_flow_action_mark ftag = {
3603 struct mlx5_flow_action_copy_mreg cp_mreg = {
3607 struct rte_flow_action_jump jump = {
3608 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3610 struct rte_flow_action actions[] = {
3611 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
3614 /* Fill the register fileds in the flow. */
3615 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3619 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3623 /* Provide the full width of FLAG specific value. */
3624 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3625 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3626 /* Build a new flow. */
3627 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3628 items[0] = (struct rte_flow_item){
3629 .type = (enum rte_flow_item_type)
3630 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3633 items[1] = (struct rte_flow_item){
3634 .type = RTE_FLOW_ITEM_TYPE_END,
3636 actions[0] = (struct rte_flow_action){
3637 .type = (enum rte_flow_action_type)
3638 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3641 actions[1] = (struct rte_flow_action){
3642 .type = (enum rte_flow_action_type)
3643 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3646 actions[2] = (struct rte_flow_action){
3647 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3650 actions[3] = (struct rte_flow_action){
3651 .type = RTE_FLOW_ACTION_TYPE_END,
3654 /* Default rule, wildcard match. */
3655 attr.priority = MLX5_FLOW_PRIO_RSVD;
3656 items[0] = (struct rte_flow_item){
3657 .type = RTE_FLOW_ITEM_TYPE_END,
3659 actions[0] = (struct rte_flow_action){
3660 .type = (enum rte_flow_action_type)
3661 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3664 actions[1] = (struct rte_flow_action){
3665 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3668 actions[2] = (struct rte_flow_action){
3669 .type = RTE_FLOW_ACTION_TYPE_END,
3672 /* Build a new entry. */
3673 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3680 * The copy Flows are not included in any list. There
3681 * ones are referenced from other Flows and can not
3682 * be applied, removed, deleted in ardbitrary order
3683 * by list traversing.
3685 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3686 actions, false, error);
3687 if (!mcp_res->rix_flow) {
3688 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
3691 return &mcp_res->hlist_ent;
3695 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3697 * As mark_id is unique, if there's already a registered flow for the mark_id,
3698 * return by increasing the reference counter of the resource. Otherwise, create
3699 * the resource (mcp_res) and flow.
3702 * - If ingress port is ANY and reg_c[1] is mark_id,
3703 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3705 * For default flow (zero mark_id), flow is like,
3706 * - If ingress port is ANY,
3707 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
3710 * Pointer to Ethernet device.
3712 * ID of MARK action, zero means default flow for META.
3714 * Perform verbose error reporting if not NULL.
3717 * Associated resource on success, NULL otherwise and rte_errno is set.
3719 static struct mlx5_flow_mreg_copy_resource *
3720 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
3721 struct rte_flow_error *error)
3723 struct mlx5_priv *priv = dev->data->dev_private;
3724 struct mlx5_hlist_entry *entry;
3725 struct mlx5_flow_cb_ctx ctx = {
3730 /* Check if already registered. */
3731 MLX5_ASSERT(priv->mreg_cp_tbl);
3732 entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
3735 return container_of(entry, struct mlx5_flow_mreg_copy_resource,
3740 flow_dv_mreg_remove_cb(struct mlx5_hlist *list, struct mlx5_hlist_entry *entry)
3742 struct mlx5_flow_mreg_copy_resource *mcp_res =
3743 container_of(entry, typeof(*mcp_res), hlist_ent);
3744 struct rte_eth_dev *dev = list->ctx;
3745 struct mlx5_priv *priv = dev->data->dev_private;
3747 MLX5_ASSERT(mcp_res->rix_flow);
3748 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3749 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3753 * Release flow in RX_CP_TBL.
3756 * Pointer to Ethernet device.
3758 * Parent flow for wich copying is provided.
3761 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3762 struct rte_flow *flow)
3764 struct mlx5_flow_mreg_copy_resource *mcp_res;
3765 struct mlx5_priv *priv = dev->data->dev_private;
3767 if (!flow->rix_mreg_copy)
3769 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3770 flow->rix_mreg_copy);
3771 if (!mcp_res || !priv->mreg_cp_tbl)
3773 MLX5_ASSERT(mcp_res->rix_flow);
3774 mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3775 flow->rix_mreg_copy = 0;
3779 * Remove the default copy action from RX_CP_TBL.
3781 * This functions is called in the mlx5_dev_start(). No thread safe
3785 * Pointer to Ethernet device.
3788 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3790 struct mlx5_hlist_entry *entry;
3791 struct mlx5_priv *priv = dev->data->dev_private;
3793 /* Check if default flow is registered. */
3794 if (!priv->mreg_cp_tbl)
3796 entry = mlx5_hlist_lookup(priv->mreg_cp_tbl,
3797 MLX5_DEFAULT_COPY_ID, NULL);
3800 mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
3804 * Add the default copy action in in RX_CP_TBL.
3806 * This functions is called in the mlx5_dev_start(). No thread safe
3810 * Pointer to Ethernet device.
3812 * Perform verbose error reporting if not NULL.
3815 * 0 for success, negative value otherwise and rte_errno is set.
3818 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3819 struct rte_flow_error *error)
3821 struct mlx5_priv *priv = dev->data->dev_private;
3822 struct mlx5_flow_mreg_copy_resource *mcp_res;
3824 /* Check whether extensive metadata feature is engaged. */
3825 if (!priv->config.dv_flow_en ||
3826 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3827 !mlx5_flow_ext_mreg_supported(dev) ||
3828 !priv->sh->dv_regc0_mask)
3831 * Add default mreg copy flow may be called multiple time, but
3832 * only be called once in stop. Avoid register it twice.
3834 if (mlx5_hlist_lookup(priv->mreg_cp_tbl, MLX5_DEFAULT_COPY_ID, NULL))
3836 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3843 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3845 * All the flow having Q/RSS action should be split by
3846 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3847 * performs the following,
3848 * - CQE->flow_tag := reg_c[1] (MARK)
3849 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3850 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3851 * but there should be a flow per each MARK ID set by MARK action.
3853 * For the aforementioned reason, if there's a MARK action in flow's action
3854 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3855 * the MARK ID to CQE's flow_tag like,
3856 * - If reg_c[1] is mark_id,
3857 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3859 * For SET_META action which stores value in reg_c[0], as the destination is
3860 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3861 * MARK ID means the default flow. The default flow looks like,
3862 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3865 * Pointer to Ethernet device.
3867 * Pointer to flow structure.
3868 * @param[in] actions
3869 * Pointer to the list of actions.
3871 * Perform verbose error reporting if not NULL.
3874 * 0 on success, negative value otherwise and rte_errno is set.
3877 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3878 struct rte_flow *flow,
3879 const struct rte_flow_action *actions,
3880 struct rte_flow_error *error)
3882 struct mlx5_priv *priv = dev->data->dev_private;
3883 struct mlx5_dev_config *config = &priv->config;
3884 struct mlx5_flow_mreg_copy_resource *mcp_res;
3885 const struct rte_flow_action_mark *mark;
3887 /* Check whether extensive metadata feature is engaged. */
3888 if (!config->dv_flow_en ||
3889 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3890 !mlx5_flow_ext_mreg_supported(dev) ||
3891 !priv->sh->dv_regc0_mask)
3893 /* Find MARK action. */
3894 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3895 switch (actions->type) {
3896 case RTE_FLOW_ACTION_TYPE_FLAG:
3897 mcp_res = flow_mreg_add_copy_action
3898 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3901 flow->rix_mreg_copy = mcp_res->idx;
3903 case RTE_FLOW_ACTION_TYPE_MARK:
3904 mark = (const struct rte_flow_action_mark *)
3907 flow_mreg_add_copy_action(dev, mark->id, error);
3910 flow->rix_mreg_copy = mcp_res->idx;
3919 #define MLX5_MAX_SPLIT_ACTIONS 24
3920 #define MLX5_MAX_SPLIT_ITEMS 24
3923 * Split the hairpin flow.
3924 * Since HW can't support encap and push-vlan on Rx, we move these
3926 * If the count action is after the encap then we also
3927 * move the count action. in this case the count will also measure
3931 * Pointer to Ethernet device.
3932 * @param[in] actions
3933 * Associated actions (list terminated by the END action).
3934 * @param[out] actions_rx
3936 * @param[out] actions_tx
3938 * @param[out] pattern_tx
3939 * The pattern items for the Tx flow.
3940 * @param[out] flow_id
3941 * The flow ID connected to this flow.
3947 flow_hairpin_split(struct rte_eth_dev *dev,
3948 const struct rte_flow_action actions[],
3949 struct rte_flow_action actions_rx[],
3950 struct rte_flow_action actions_tx[],
3951 struct rte_flow_item pattern_tx[],
3954 const struct rte_flow_action_raw_encap *raw_encap;
3955 const struct rte_flow_action_raw_decap *raw_decap;
3956 struct mlx5_rte_flow_action_set_tag *set_tag;
3957 struct rte_flow_action *tag_action;
3958 struct mlx5_rte_flow_item_tag *tag_item;
3959 struct rte_flow_item *item;
3963 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3964 switch (actions->type) {
3965 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3966 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3967 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3968 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3969 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3970 rte_memcpy(actions_tx, actions,
3971 sizeof(struct rte_flow_action));
3974 case RTE_FLOW_ACTION_TYPE_COUNT:
3976 rte_memcpy(actions_tx, actions,
3977 sizeof(struct rte_flow_action));
3980 rte_memcpy(actions_rx, actions,
3981 sizeof(struct rte_flow_action));
3985 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3986 raw_encap = actions->conf;
3987 if (raw_encap->size >
3988 (sizeof(struct rte_flow_item_eth) +
3989 sizeof(struct rte_flow_item_ipv4))) {
3990 memcpy(actions_tx, actions,
3991 sizeof(struct rte_flow_action));
3995 rte_memcpy(actions_rx, actions,
3996 sizeof(struct rte_flow_action));
4000 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4001 raw_decap = actions->conf;
4002 if (raw_decap->size <
4003 (sizeof(struct rte_flow_item_eth) +
4004 sizeof(struct rte_flow_item_ipv4))) {
4005 memcpy(actions_tx, actions,
4006 sizeof(struct rte_flow_action));
4009 rte_memcpy(actions_rx, actions,
4010 sizeof(struct rte_flow_action));
4015 rte_memcpy(actions_rx, actions,
4016 sizeof(struct rte_flow_action));
4021 /* Add set meta action and end action for the Rx flow. */
4022 tag_action = actions_rx;
4023 tag_action->type = (enum rte_flow_action_type)
4024 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4026 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
4028 set_tag = (void *)actions_rx;
4029 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
4030 MLX5_ASSERT(set_tag->id > REG_NON);
4031 set_tag->data = flow_id;
4032 tag_action->conf = set_tag;
4033 /* Create Tx item list. */
4034 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
4035 addr = (void *)&pattern_tx[2];
4037 item->type = (enum rte_flow_item_type)
4038 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4039 tag_item = (void *)addr;
4040 tag_item->data = flow_id;
4041 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
4042 MLX5_ASSERT(set_tag->id > REG_NON);
4043 item->spec = tag_item;
4044 addr += sizeof(struct mlx5_rte_flow_item_tag);
4045 tag_item = (void *)addr;
4046 tag_item->data = UINT32_MAX;
4047 tag_item->id = UINT16_MAX;
4048 item->mask = tag_item;
4051 item->type = RTE_FLOW_ITEM_TYPE_END;
4056 * The last stage of splitting chain, just creates the subflow
4057 * without any modification.
4060 * Pointer to Ethernet device.
4062 * Parent flow structure pointer.
4063 * @param[in, out] sub_flow
4064 * Pointer to return the created subflow, may be NULL.
4066 * Flow rule attributes.
4068 * Pattern specification (list terminated by the END pattern item).
4069 * @param[in] actions
4070 * Associated actions (list terminated by the END action).
4071 * @param[in] flow_split_info
4072 * Pointer to flow split info structure.
4074 * Perform verbose error reporting if not NULL.
4076 * 0 on success, negative value otherwise
4079 flow_create_split_inner(struct rte_eth_dev *dev,
4080 struct rte_flow *flow,
4081 struct mlx5_flow **sub_flow,
4082 const struct rte_flow_attr *attr,
4083 const struct rte_flow_item items[],
4084 const struct rte_flow_action actions[],
4085 struct mlx5_flow_split_info *flow_split_info,
4086 struct rte_flow_error *error)
4088 struct mlx5_flow *dev_flow;
4090 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
4091 flow_split_info->flow_idx, error);
4094 dev_flow->flow = flow;
4095 dev_flow->external = flow_split_info->external;
4096 dev_flow->skip_scale = flow_split_info->skip_scale;
4097 /* Subflow object was created, we must include one in the list. */
4098 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4099 dev_flow->handle, next);
4101 * If dev_flow is as one of the suffix flow, some actions in suffix
4102 * flow may need some user defined item layer flags, and pass the
4103 * Metadate rxq mark flag to suffix flow as well.
4105 if (flow_split_info->prefix_layers)
4106 dev_flow->handle->layers = flow_split_info->prefix_layers;
4107 if (flow_split_info->prefix_mark)
4108 dev_flow->handle->mark = 1;
4110 *sub_flow = dev_flow;
4111 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
4115 * Split the meter flow.
4117 * As meter flow will split to three sub flow, other than meter
4118 * action, the other actions make sense to only meter accepts
4119 * the packet. If it need to be dropped, no other additional
4120 * actions should be take.
4122 * One kind of special action which decapsulates the L3 tunnel
4123 * header will be in the prefix sub flow, as not to take the
4124 * L3 tunnel header into account.
4127 * Pointer to Ethernet device.
4129 * Pattern specification (list terminated by the END pattern item).
4130 * @param[out] sfx_items
4131 * Suffix flow match items (list terminated by the END pattern item).
4132 * @param[in] actions
4133 * Associated actions (list terminated by the END action).
4134 * @param[out] actions_sfx
4135 * Suffix flow actions.
4136 * @param[out] actions_pre
4137 * Prefix flow actions.
4138 * @param[out] pattern_sfx
4139 * The pattern items for the suffix flow.
4140 * @param[out] tag_sfx
4141 * Pointer to suffix flow tag.
4147 flow_meter_split_prep(struct rte_eth_dev *dev,
4148 const struct rte_flow_item items[],
4149 struct rte_flow_item sfx_items[],
4150 const struct rte_flow_action actions[],
4151 struct rte_flow_action actions_sfx[],
4152 struct rte_flow_action actions_pre[])
4154 struct mlx5_priv *priv = dev->data->dev_private;
4155 struct rte_flow_action *tag_action = NULL;
4156 struct rte_flow_item *tag_item;
4157 struct mlx5_rte_flow_action_set_tag *set_tag;
4158 struct rte_flow_error error;
4159 const struct rte_flow_action_raw_encap *raw_encap;
4160 const struct rte_flow_action_raw_decap *raw_decap;
4161 struct mlx5_rte_flow_item_tag *tag_spec;
4162 struct mlx5_rte_flow_item_tag *tag_mask;
4163 uint32_t tag_id = 0;
4164 bool copy_vlan = false;
4166 /* Prepare the actions for prefix and suffix flow. */
4167 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4168 struct rte_flow_action **action_cur = NULL;
4170 switch (actions->type) {
4171 case RTE_FLOW_ACTION_TYPE_METER:
4172 /* Add the extra tag action first. */
4173 tag_action = actions_pre;
4174 tag_action->type = (enum rte_flow_action_type)
4175 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4177 action_cur = &actions_pre;
4179 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4180 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4181 action_cur = &actions_pre;
4183 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4184 raw_encap = actions->conf;
4185 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4186 action_cur = &actions_pre;
4188 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4189 raw_decap = actions->conf;
4190 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4191 action_cur = &actions_pre;
4193 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4194 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4201 action_cur = &actions_sfx;
4202 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
4205 /* Add end action to the actions. */
4206 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4207 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4210 set_tag = (void *)actions_pre;
4211 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4212 mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
4214 if (tag_id >= (1 << (sizeof(tag_id) * 8 - MLX5_MTR_COLOR_BITS))) {
4215 DRV_LOG(ERR, "Port %u meter flow id exceed max limit.",
4216 dev->data->port_id);
4217 mlx5_ipool_free(priv->sh->ipool
4218 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], tag_id);
4220 } else if (!tag_id) {
4223 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
4225 tag_action->conf = set_tag;
4226 /* Prepare the suffix subflow items. */
4227 tag_item = sfx_items++;
4228 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4229 int item_type = items->type;
4231 switch (item_type) {
4232 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4233 memcpy(sfx_items, items, sizeof(*sfx_items));
4236 case RTE_FLOW_ITEM_TYPE_VLAN:
4238 memcpy(sfx_items, items, sizeof(*sfx_items));
4240 * Convert to internal match item, it is used
4241 * for vlan push and set vid.
4243 sfx_items->type = (enum rte_flow_item_type)
4244 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4252 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4254 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4255 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
4256 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4257 tag_mask = tag_spec + 1;
4258 tag_mask->data = 0xffffff00;
4259 tag_item->type = (enum rte_flow_item_type)
4260 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4261 tag_item->spec = tag_spec;
4262 tag_item->last = NULL;
4263 tag_item->mask = tag_mask;
4268 * Split action list having QUEUE/RSS for metadata register copy.
4270 * Once Q/RSS action is detected in user's action list, the flow action
4271 * should be split in order to copy metadata registers, which will happen in
4273 * - CQE->flow_tag := reg_c[1] (MARK)
4274 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4275 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
4276 * This is because the last action of each flow must be a terminal action
4277 * (QUEUE, RSS or DROP).
4279 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
4280 * stored and kept in the mlx5_flow structure per each sub_flow.
4282 * The Q/RSS action is replaced with,
4283 * - SET_TAG, setting the allocated flow ID to reg_c[2].
4284 * And the following JUMP action is added at the end,
4285 * - JUMP, to RX_CP_TBL.
4287 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
4288 * flow_create_split_metadata() routine. The flow will look like,
4289 * - If flow ID matches (reg_c[2]), perform Q/RSS.
4292 * Pointer to Ethernet device.
4293 * @param[out] split_actions
4294 * Pointer to store split actions to jump to CP_TBL.
4295 * @param[in] actions
4296 * Pointer to the list of original flow actions.
4298 * Pointer to the Q/RSS action.
4299 * @param[in] actions_n
4300 * Number of original actions.
4302 * Perform verbose error reporting if not NULL.
4305 * non-zero unique flow_id on success, otherwise 0 and
4306 * error/rte_error are set.
4309 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
4310 struct rte_flow_action *split_actions,
4311 const struct rte_flow_action *actions,
4312 const struct rte_flow_action *qrss,
4313 int actions_n, struct rte_flow_error *error)
4315 struct mlx5_priv *priv = dev->data->dev_private;
4316 struct mlx5_rte_flow_action_set_tag *set_tag;
4317 struct rte_flow_action_jump *jump;
4318 const int qrss_idx = qrss - actions;
4319 uint32_t flow_id = 0;
4323 * Given actions will be split
4324 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
4325 * - Add jump to mreg CP_TBL.
4326 * As a result, there will be one more action.
4329 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
4330 set_tag = (void *)(split_actions + actions_n);
4332 * If tag action is not set to void(it means we are not the meter
4333 * suffix flow), add the tag action. Since meter suffix flow already
4334 * has the tag added.
4336 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
4338 * Allocate the new subflow ID. This one is unique within
4339 * device and not shared with representors. Otherwise,
4340 * we would have to resolve multi-thread access synch
4341 * issue. Each flow on the shared device is appended
4342 * with source vport identifier, so the resulting
4343 * flows will be unique in the shared (by master and
4344 * representors) domain even if they have coinciding
4347 mlx5_ipool_malloc(priv->sh->ipool
4348 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
4350 return rte_flow_error_set(error, ENOMEM,
4351 RTE_FLOW_ERROR_TYPE_ACTION,
4352 NULL, "can't allocate id "
4353 "for split Q/RSS subflow");
4354 /* Internal SET_TAG action to set flow ID. */
4355 *set_tag = (struct mlx5_rte_flow_action_set_tag){
4358 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
4362 /* Construct new actions array. */
4363 /* Replace QUEUE/RSS action. */
4364 split_actions[qrss_idx] = (struct rte_flow_action){
4365 .type = (enum rte_flow_action_type)
4366 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4370 /* JUMP action to jump to mreg copy table (CP_TBL). */
4371 jump = (void *)(set_tag + 1);
4372 *jump = (struct rte_flow_action_jump){
4373 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4375 split_actions[actions_n - 2] = (struct rte_flow_action){
4376 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4379 split_actions[actions_n - 1] = (struct rte_flow_action){
4380 .type = RTE_FLOW_ACTION_TYPE_END,
4386 * Extend the given action list for Tx metadata copy.
4388 * Copy the given action list to the ext_actions and add flow metadata register
4389 * copy action in order to copy reg_a set by WQE to reg_c[0].
4391 * @param[out] ext_actions
4392 * Pointer to the extended action list.
4393 * @param[in] actions
4394 * Pointer to the list of actions.
4395 * @param[in] actions_n
4396 * Number of actions in the list.
4398 * Perform verbose error reporting if not NULL.
4399 * @param[in] encap_idx
4400 * The encap action inndex.
4403 * 0 on success, negative value otherwise
4406 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
4407 struct rte_flow_action *ext_actions,
4408 const struct rte_flow_action *actions,
4409 int actions_n, struct rte_flow_error *error,
4412 struct mlx5_flow_action_copy_mreg *cp_mreg =
4413 (struct mlx5_flow_action_copy_mreg *)
4414 (ext_actions + actions_n + 1);
4417 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4421 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
4426 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
4427 if (encap_idx == actions_n - 1) {
4428 ext_actions[actions_n - 1] = (struct rte_flow_action){
4429 .type = (enum rte_flow_action_type)
4430 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4433 ext_actions[actions_n] = (struct rte_flow_action){
4434 .type = RTE_FLOW_ACTION_TYPE_END,
4437 ext_actions[encap_idx] = (struct rte_flow_action){
4438 .type = (enum rte_flow_action_type)
4439 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4442 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
4443 sizeof(*ext_actions) * (actions_n - encap_idx));
4449 * Check the match action from the action list.
4451 * @param[in] actions
4452 * Pointer to the list of actions.
4454 * Flow rule attributes.
4456 * The action to be check if exist.
4457 * @param[out] match_action_pos
4458 * Pointer to the position of the matched action if exists, otherwise is -1.
4459 * @param[out] qrss_action_pos
4460 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
4463 * > 0 the total number of actions.
4464 * 0 if not found match action in action list.
4467 flow_check_match_action(const struct rte_flow_action actions[],
4468 const struct rte_flow_attr *attr,
4469 enum rte_flow_action_type action,
4470 int *match_action_pos, int *qrss_action_pos)
4472 const struct rte_flow_action_sample *sample;
4479 *match_action_pos = -1;
4480 *qrss_action_pos = -1;
4481 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4482 if (actions->type == action) {
4484 *match_action_pos = actions_n;
4486 if (actions->type == RTE_FLOW_ACTION_TYPE_QUEUE ||
4487 actions->type == RTE_FLOW_ACTION_TYPE_RSS)
4488 *qrss_action_pos = actions_n;
4489 if (actions->type == RTE_FLOW_ACTION_TYPE_JUMP)
4491 if (actions->type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
4492 sample = actions->conf;
4493 ratio = sample->ratio;
4494 sub_type = ((const struct rte_flow_action *)
4495 (sample->actions))->type;
4499 if (flag && action == RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) {
4501 /* JUMP Action not support for Mirroring;
4502 * Mirroring support multi-destination;
4504 if (!jump_flag && sub_type != RTE_FLOW_ACTION_TYPE_END)
4508 /* Count RTE_FLOW_ACTION_TYPE_END. */
4509 return flag ? actions_n + 1 : 0;
4512 #define SAMPLE_SUFFIX_ITEM 2
4515 * Split the sample flow.
4517 * As sample flow will split to two sub flow, sample flow with
4518 * sample action, the other actions will move to new suffix flow.
4520 * Also add unique tag id with tag action in the sample flow,
4521 * the same tag id will be as match in the suffix flow.
4524 * Pointer to Ethernet device.
4526 * FDB egress flow flag.
4527 * @param[out] sfx_items
4528 * Suffix flow match items (list terminated by the END pattern item).
4529 * @param[in] actions
4530 * Associated actions (list terminated by the END action).
4531 * @param[out] actions_sfx
4532 * Suffix flow actions.
4533 * @param[out] actions_pre
4534 * Prefix flow actions.
4535 * @param[in] actions_n
4536 * The total number of actions.
4537 * @param[in] sample_action_pos
4538 * The sample action position.
4539 * @param[in] qrss_action_pos
4540 * The Queue/RSS action position.
4542 * Perform verbose error reporting if not NULL.
4545 * 0 on success, or unique flow_id, a negative errno value
4546 * otherwise and rte_errno is set.
4549 flow_sample_split_prep(struct rte_eth_dev *dev,
4551 struct rte_flow_item sfx_items[],
4552 const struct rte_flow_action actions[],
4553 struct rte_flow_action actions_sfx[],
4554 struct rte_flow_action actions_pre[],
4556 int sample_action_pos,
4557 int qrss_action_pos,
4558 struct rte_flow_error *error)
4560 struct mlx5_priv *priv = dev->data->dev_private;
4561 struct mlx5_rte_flow_action_set_tag *set_tag;
4562 struct mlx5_rte_flow_item_tag *tag_spec;
4563 struct mlx5_rte_flow_item_tag *tag_mask;
4564 uint32_t tag_id = 0;
4568 if (sample_action_pos < 0)
4569 return rte_flow_error_set(error, EINVAL,
4570 RTE_FLOW_ERROR_TYPE_ACTION,
4571 NULL, "invalid position of sample "
4574 /* Prepare the prefix tag action. */
4575 set_tag = (void *)(actions_pre + actions_n + 1);
4576 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
4580 mlx5_ipool_malloc(priv->sh->ipool
4581 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
4582 set_tag->data = tag_id;
4583 /* Prepare the suffix subflow items. */
4584 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
4585 tag_spec->data = tag_id;
4586 tag_spec->id = set_tag->id;
4587 tag_mask = tag_spec + 1;
4588 tag_mask->data = UINT32_MAX;
4589 sfx_items[0] = (struct rte_flow_item){
4590 .type = (enum rte_flow_item_type)
4591 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4596 sfx_items[1] = (struct rte_flow_item){
4597 .type = (enum rte_flow_item_type)
4598 RTE_FLOW_ITEM_TYPE_END,
4601 /* Prepare the actions for prefix and suffix flow. */
4602 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
4603 index = qrss_action_pos;
4604 /* Put the preceding the Queue/RSS action into prefix flow. */
4606 memcpy(actions_pre, actions,
4607 sizeof(struct rte_flow_action) * index);
4608 /* Put others preceding the sample action into prefix flow. */
4609 if (sample_action_pos > index + 1)
4610 memcpy(actions_pre + index, actions + index + 1,
4611 sizeof(struct rte_flow_action) *
4612 (sample_action_pos - index - 1));
4613 index = sample_action_pos - 1;
4614 /* Put Queue/RSS action into Suffix flow. */
4615 memcpy(actions_sfx, actions + qrss_action_pos,
4616 sizeof(struct rte_flow_action));
4619 index = sample_action_pos;
4621 memcpy(actions_pre, actions,
4622 sizeof(struct rte_flow_action) * index);
4624 /* Add the extra tag action for NIC-RX and E-Switch ingress. */
4626 actions_pre[index++] =
4627 (struct rte_flow_action){
4628 .type = (enum rte_flow_action_type)
4629 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4633 memcpy(actions_pre + index, actions + sample_action_pos,
4634 sizeof(struct rte_flow_action));
4636 actions_pre[index] = (struct rte_flow_action){
4637 .type = (enum rte_flow_action_type)
4638 RTE_FLOW_ACTION_TYPE_END,
4640 /* Put the actions after sample into Suffix flow. */
4641 memcpy(actions_sfx, actions + sample_action_pos + 1,
4642 sizeof(struct rte_flow_action) *
4643 (actions_n - sample_action_pos - 1));
4648 * The splitting for metadata feature.
4650 * - Q/RSS action on NIC Rx should be split in order to pass by
4651 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4652 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4654 * - All the actions on NIC Tx should have a mreg copy action to
4655 * copy reg_a from WQE to reg_c[0].
4658 * Pointer to Ethernet device.
4660 * Parent flow structure pointer.
4662 * Flow rule attributes.
4664 * Pattern specification (list terminated by the END pattern item).
4665 * @param[in] actions
4666 * Associated actions (list terminated by the END action).
4667 * @param[in] flow_split_info
4668 * Pointer to flow split info structure.
4670 * Perform verbose error reporting if not NULL.
4672 * 0 on success, negative value otherwise
4675 flow_create_split_metadata(struct rte_eth_dev *dev,
4676 struct rte_flow *flow,
4677 const struct rte_flow_attr *attr,
4678 const struct rte_flow_item items[],
4679 const struct rte_flow_action actions[],
4680 struct mlx5_flow_split_info *flow_split_info,
4681 struct rte_flow_error *error)
4683 struct mlx5_priv *priv = dev->data->dev_private;
4684 struct mlx5_dev_config *config = &priv->config;
4685 const struct rte_flow_action *qrss = NULL;
4686 struct rte_flow_action *ext_actions = NULL;
4687 struct mlx5_flow *dev_flow = NULL;
4688 uint32_t qrss_id = 0;
4695 /* Check whether extensive metadata feature is engaged. */
4696 if (!config->dv_flow_en ||
4697 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4698 !mlx5_flow_ext_mreg_supported(dev))
4699 return flow_create_split_inner(dev, flow, NULL, attr, items,
4700 actions, flow_split_info, error);
4701 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
4704 /* Exclude hairpin flows from splitting. */
4705 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
4706 const struct rte_flow_action_queue *queue;
4709 if (mlx5_rxq_get_type(dev, queue->index) ==
4710 MLX5_RXQ_TYPE_HAIRPIN)
4712 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
4713 const struct rte_flow_action_rss *rss;
4716 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
4717 MLX5_RXQ_TYPE_HAIRPIN)
4722 /* Check if it is in meter suffix table. */
4723 mtr_sfx = attr->group == (attr->transfer ?
4724 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4725 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
4727 * Q/RSS action on NIC Rx should be split in order to pass by
4728 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4729 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4731 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
4732 sizeof(struct rte_flow_action_set_tag) +
4733 sizeof(struct rte_flow_action_jump);
4734 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
4737 return rte_flow_error_set(error, ENOMEM,
4738 RTE_FLOW_ERROR_TYPE_ACTION,
4739 NULL, "no memory to split "
4742 * If we are the suffix flow of meter, tag already exist.
4743 * Set the tag action to void.
4746 ext_actions[qrss - actions].type =
4747 RTE_FLOW_ACTION_TYPE_VOID;
4749 ext_actions[qrss - actions].type =
4750 (enum rte_flow_action_type)
4751 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4753 * Create the new actions list with removed Q/RSS action
4754 * and appended set tag and jump to register copy table
4755 * (RX_CP_TBL). We should preallocate unique tag ID here
4756 * in advance, because it is needed for set tag action.
4758 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
4759 qrss, actions_n, error);
4760 if (!mtr_sfx && !qrss_id) {
4764 } else if (attr->egress && !attr->transfer) {
4766 * All the actions on NIC Tx should have a metadata register
4767 * copy action to copy reg_a from WQE to reg_c[meta]
4769 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
4770 sizeof(struct mlx5_flow_action_copy_mreg);
4771 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
4774 return rte_flow_error_set(error, ENOMEM,
4775 RTE_FLOW_ERROR_TYPE_ACTION,
4776 NULL, "no memory to split "
4778 /* Create the action list appended with copy register. */
4779 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
4780 actions_n, error, encap_idx);
4784 /* Add the unmodified original or prefix subflow. */
4785 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
4786 items, ext_actions ? ext_actions :
4787 actions, flow_split_info, error);
4790 MLX5_ASSERT(dev_flow);
4792 const struct rte_flow_attr q_attr = {
4793 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4796 /* Internal PMD action to set register. */
4797 struct mlx5_rte_flow_item_tag q_tag_spec = {
4801 struct rte_flow_item q_items[] = {
4803 .type = (enum rte_flow_item_type)
4804 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4805 .spec = &q_tag_spec,
4810 .type = RTE_FLOW_ITEM_TYPE_END,
4813 struct rte_flow_action q_actions[] = {
4819 .type = RTE_FLOW_ACTION_TYPE_END,
4822 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
4825 * Configure the tag item only if there is no meter subflow.
4826 * Since tag is already marked in the meter suffix subflow
4827 * we can just use the meter suffix items as is.
4830 /* Not meter subflow. */
4831 MLX5_ASSERT(!mtr_sfx);
4833 * Put unique id in prefix flow due to it is destroyed
4834 * after suffix flow and id will be freed after there
4835 * is no actual flows with this id and identifier
4836 * reallocation becomes possible (for example, for
4837 * other flows in other threads).
4839 dev_flow->handle->split_flow_id = qrss_id;
4840 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
4844 q_tag_spec.id = ret;
4847 /* Add suffix subflow to execute Q/RSS. */
4848 flow_split_info->prefix_layers = layers;
4849 flow_split_info->prefix_mark = 0;
4850 ret = flow_create_split_inner(dev, flow, &dev_flow,
4851 &q_attr, mtr_sfx ? items :
4853 flow_split_info, error);
4856 /* qrss ID should be freed if failed. */
4858 MLX5_ASSERT(dev_flow);
4863 * We do not destroy the partially created sub_flows in case of error.
4864 * These ones are included into parent flow list and will be destroyed
4865 * by flow_drv_destroy.
4867 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
4869 mlx5_free(ext_actions);
4874 * The splitting for meter feature.
4876 * - The meter flow will be split to two flows as prefix and
4877 * suffix flow. The packets make sense only it pass the prefix
4880 * - Reg_C_5 is used for the packet to match betweend prefix and
4884 * Pointer to Ethernet device.
4886 * Parent flow structure pointer.
4888 * Flow rule attributes.
4890 * Pattern specification (list terminated by the END pattern item).
4891 * @param[in] actions
4892 * Associated actions (list terminated by the END action).
4893 * @param[in] flow_split_info
4894 * Pointer to flow split info structure.
4896 * Perform verbose error reporting if not NULL.
4898 * 0 on success, negative value otherwise
4901 flow_create_split_meter(struct rte_eth_dev *dev,
4902 struct rte_flow *flow,
4903 const struct rte_flow_attr *attr,
4904 const struct rte_flow_item items[],
4905 const struct rte_flow_action actions[],
4906 struct mlx5_flow_split_info *flow_split_info,
4907 struct rte_flow_error *error)
4909 struct mlx5_priv *priv = dev->data->dev_private;
4910 struct rte_flow_action *sfx_actions = NULL;
4911 struct rte_flow_action *pre_actions = NULL;
4912 struct rte_flow_item *sfx_items = NULL;
4913 struct mlx5_flow *dev_flow = NULL;
4914 struct rte_flow_attr sfx_attr = *attr;
4916 uint32_t mtr_tag_id = 0;
4923 actions_n = flow_check_meter_action(actions, &mtr);
4925 /* The five prefix actions: meter, decap, encap, tag, end. */
4926 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
4927 sizeof(struct mlx5_rte_flow_action_set_tag);
4928 /* tag, vlan, port id, end. */
4929 #define METER_SUFFIX_ITEM 4
4930 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
4931 sizeof(struct mlx5_rte_flow_item_tag) * 2;
4932 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
4935 return rte_flow_error_set(error, ENOMEM,
4936 RTE_FLOW_ERROR_TYPE_ACTION,
4937 NULL, "no memory to split "
4939 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4941 pre_actions = sfx_actions + actions_n;
4942 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
4943 actions, sfx_actions,
4949 /* Add the prefix subflow. */
4950 flow_split_info->prefix_mark = 0;
4951 ret = flow_create_split_inner(dev, flow, &dev_flow,
4952 attr, items, pre_actions,
4953 flow_split_info, error);
4958 dev_flow->handle->split_flow_id = mtr_tag_id;
4959 /* Setting the sfx group atrr. */
4960 sfx_attr.group = sfx_attr.transfer ?
4961 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4962 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4963 flow_split_info->prefix_layers =
4964 flow_get_prefix_layer_flags(dev_flow);
4965 flow_split_info->prefix_mark = dev_flow->handle->mark;
4967 /* Add the prefix subflow. */
4968 ret = flow_create_split_metadata(dev, flow,
4969 &sfx_attr, sfx_items ?
4971 sfx_actions ? sfx_actions : actions,
4972 flow_split_info, error);
4975 mlx5_free(sfx_actions);
4980 * The splitting for sample feature.
4982 * Once Sample action is detected in the action list, the flow actions should
4983 * be split into prefix sub flow and suffix sub flow.
4985 * The original items remain in the prefix sub flow, all actions preceding the
4986 * sample action and the sample action itself will be copied to the prefix
4987 * sub flow, the actions following the sample action will be copied to the
4988 * suffix sub flow, Queue action always be located in the suffix sub flow.
4990 * In order to make the packet from prefix sub flow matches with suffix sub
4991 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
4992 * flow uses tag item with the unique flow id.
4995 * Pointer to Ethernet device.
4997 * Parent flow structure pointer.
4999 * Flow rule attributes.
5001 * Pattern specification (list terminated by the END pattern item).
5002 * @param[in] actions
5003 * Associated actions (list terminated by the END action).
5004 * @param[in] flow_split_info
5005 * Pointer to flow split info structure.
5007 * Perform verbose error reporting if not NULL.
5009 * 0 on success, negative value otherwise
5012 flow_create_split_sample(struct rte_eth_dev *dev,
5013 struct rte_flow *flow,
5014 const struct rte_flow_attr *attr,
5015 const struct rte_flow_item items[],
5016 const struct rte_flow_action actions[],
5017 struct mlx5_flow_split_info *flow_split_info,
5018 struct rte_flow_error *error)
5020 struct mlx5_priv *priv = dev->data->dev_private;
5021 struct rte_flow_action *sfx_actions = NULL;
5022 struct rte_flow_action *pre_actions = NULL;
5023 struct rte_flow_item *sfx_items = NULL;
5024 struct mlx5_flow *dev_flow = NULL;
5025 struct rte_flow_attr sfx_attr = *attr;
5026 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5027 struct mlx5_flow_dv_sample_resource *sample_res;
5028 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
5029 struct mlx5_flow_tbl_resource *sfx_tbl;
5030 union mlx5_flow_tbl_key sfx_table_key;
5034 uint32_t fdb_tx = 0;
5037 int sample_action_pos;
5038 int qrss_action_pos;
5041 if (priv->sampler_en)
5042 actions_n = flow_check_match_action(actions, attr,
5043 RTE_FLOW_ACTION_TYPE_SAMPLE,
5044 &sample_action_pos, &qrss_action_pos);
5046 /* The prefix actions must includes sample, tag, end. */
5047 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
5048 + sizeof(struct mlx5_rte_flow_action_set_tag);
5049 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
5050 sizeof(struct mlx5_rte_flow_item_tag) * 2;
5051 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
5052 item_size), 0, SOCKET_ID_ANY);
5054 return rte_flow_error_set(error, ENOMEM,
5055 RTE_FLOW_ERROR_TYPE_ACTION,
5056 NULL, "no memory to split "
5058 /* The representor_id is -1 for uplink. */
5059 fdb_tx = (attr->transfer && priv->representor_id != -1);
5061 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
5063 pre_actions = sfx_actions + actions_n;
5064 tag_id = flow_sample_split_prep(dev, fdb_tx, sfx_items,
5065 actions, sfx_actions,
5066 pre_actions, actions_n,
5068 qrss_action_pos, error);
5069 if (tag_id < 0 || (!fdb_tx && !tag_id)) {
5073 /* Add the prefix subflow. */
5074 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
5076 flow_split_info, error);
5081 dev_flow->handle->split_flow_id = tag_id;
5082 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5083 /* Set the sfx group attr. */
5084 sample_res = (struct mlx5_flow_dv_sample_resource *)
5085 dev_flow->dv.sample_res;
5086 sfx_tbl = (struct mlx5_flow_tbl_resource *)
5087 sample_res->normal_path_tbl;
5088 sfx_tbl_data = container_of(sfx_tbl,
5089 struct mlx5_flow_tbl_data_entry, tbl);
5090 sfx_table_key.v64 = sfx_tbl_data->entry.key;
5091 sfx_attr.group = sfx_attr.transfer ?
5092 (sfx_table_key.table_id - 1) :
5093 sfx_table_key.table_id;
5094 flow_split_info->prefix_layers =
5095 flow_get_prefix_layer_flags(dev_flow);
5096 flow_split_info->prefix_mark = dev_flow->handle->mark;
5097 /* Suffix group level already be scaled with factor, set
5098 * skip_scale to 1 to avoid scale again in translation.
5100 flow_split_info->skip_scale = 1;
5103 /* Add the suffix subflow. */
5104 ret = flow_create_split_meter(dev, flow, &sfx_attr,
5105 sfx_items ? sfx_items : items,
5106 sfx_actions ? sfx_actions : actions,
5107 flow_split_info, error);
5110 mlx5_free(sfx_actions);
5115 * Split the flow to subflow set. The splitters might be linked
5116 * in the chain, like this:
5117 * flow_create_split_outer() calls:
5118 * flow_create_split_meter() calls:
5119 * flow_create_split_metadata(meter_subflow_0) calls:
5120 * flow_create_split_inner(metadata_subflow_0)
5121 * flow_create_split_inner(metadata_subflow_1)
5122 * flow_create_split_inner(metadata_subflow_2)
5123 * flow_create_split_metadata(meter_subflow_1) calls:
5124 * flow_create_split_inner(metadata_subflow_0)
5125 * flow_create_split_inner(metadata_subflow_1)
5126 * flow_create_split_inner(metadata_subflow_2)
5128 * This provide flexible way to add new levels of flow splitting.
5129 * The all of successfully created subflows are included to the
5130 * parent flow dev_flow list.
5133 * Pointer to Ethernet device.
5135 * Parent flow structure pointer.
5137 * Flow rule attributes.
5139 * Pattern specification (list terminated by the END pattern item).
5140 * @param[in] actions
5141 * Associated actions (list terminated by the END action).
5142 * @param[in] flow_split_info
5143 * Pointer to flow split info structure.
5145 * Perform verbose error reporting if not NULL.
5147 * 0 on success, negative value otherwise
5150 flow_create_split_outer(struct rte_eth_dev *dev,
5151 struct rte_flow *flow,
5152 const struct rte_flow_attr *attr,
5153 const struct rte_flow_item items[],
5154 const struct rte_flow_action actions[],
5155 struct mlx5_flow_split_info *flow_split_info,
5156 struct rte_flow_error *error)
5160 ret = flow_create_split_sample(dev, flow, attr, items,
5161 actions, flow_split_info, error);
5162 MLX5_ASSERT(ret <= 0);
5166 static struct mlx5_flow_tunnel *
5167 flow_tunnel_from_rule(struct rte_eth_dev *dev,
5168 const struct rte_flow_attr *attr,
5169 const struct rte_flow_item items[],
5170 const struct rte_flow_action actions[])
5172 struct mlx5_flow_tunnel *tunnel;
5174 #pragma GCC diagnostic push
5175 #pragma GCC diagnostic ignored "-Wcast-qual"
5176 if (is_flow_tunnel_match_rule(dev, attr, items, actions))
5177 tunnel = (struct mlx5_flow_tunnel *)items[0].spec;
5178 else if (is_flow_tunnel_steer_rule(dev, attr, items, actions))
5179 tunnel = (struct mlx5_flow_tunnel *)actions[0].conf;
5182 #pragma GCC diagnostic pop
5188 * Adjust flow RSS workspace if needed.
5191 * Pointer to thread flow work space.
5193 * Pointer to RSS descriptor.
5194 * @param[in] nrssq_num
5195 * New RSS queue number.
5198 * 0 on success, -1 otherwise and rte_errno is set.
5201 flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
5202 struct mlx5_flow_rss_desc *rss_desc,
5205 if (likely(nrssq_num <= wks->rssq_num))
5207 rss_desc->queue = realloc(rss_desc->queue,
5208 sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
5209 if (!rss_desc->queue) {
5213 wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
5218 * Create a flow and add it to @p list.
5221 * Pointer to Ethernet device.
5223 * Pointer to a TAILQ flow list. If this parameter NULL,
5224 * no list insertion occurred, flow is just created,
5225 * this is caller's responsibility to track the
5228 * Flow rule attributes.
5230 * Pattern specification (list terminated by the END pattern item).
5231 * @param[in] actions
5232 * Associated actions (list terminated by the END action).
5233 * @param[in] external
5234 * This flow rule is created by request external to PMD.
5236 * Perform verbose error reporting if not NULL.
5239 * A flow index on success, 0 otherwise and rte_errno is set.
5242 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
5243 const struct rte_flow_attr *attr,
5244 const struct rte_flow_item items[],
5245 const struct rte_flow_action original_actions[],
5246 bool external, struct rte_flow_error *error)
5248 struct mlx5_priv *priv = dev->data->dev_private;
5249 struct rte_flow *flow = NULL;
5250 struct mlx5_flow *dev_flow;
5251 const struct rte_flow_action_rss *rss;
5252 struct mlx5_translated_shared_action
5253 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5254 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5256 struct mlx5_flow_expand_rss buf;
5257 uint8_t buffer[2048];
5260 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5261 uint8_t buffer[2048];
5264 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5265 uint8_t buffer[2048];
5266 } actions_hairpin_tx;
5268 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
5269 uint8_t buffer[2048];
5271 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
5272 struct mlx5_flow_rss_desc *rss_desc;
5273 const struct rte_flow_action *p_actions_rx;
5277 struct rte_flow_attr attr_tx = { .priority = 0 };
5278 const struct rte_flow_action *actions;
5279 struct rte_flow_action *translated_actions = NULL;
5280 struct mlx5_flow_tunnel *tunnel;
5281 struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
5282 struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
5283 struct mlx5_flow_split_info flow_split_info = {
5284 .external = !!external,
5293 rss_desc = &wks->rss_desc;
5294 ret = flow_shared_actions_translate(dev, original_actions,
5297 &translated_actions, error);
5299 MLX5_ASSERT(translated_actions == NULL);
5302 actions = translated_actions ? translated_actions : original_actions;
5303 p_actions_rx = actions;
5304 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5305 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
5306 external, hairpin_flow, error);
5308 goto error_before_hairpin_split;
5309 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
5312 goto error_before_hairpin_split;
5314 if (hairpin_flow > 0) {
5315 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
5317 goto error_before_hairpin_split;
5319 flow_hairpin_split(dev, actions, actions_rx.actions,
5320 actions_hairpin_tx.actions, items_tx.items,
5322 p_actions_rx = actions_rx.actions;
5324 flow_split_info.flow_idx = idx;
5325 flow->drv_type = flow_get_drv_type(dev, attr);
5326 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
5327 flow->drv_type < MLX5_FLOW_TYPE_MAX);
5328 memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
5329 rss = flow_get_rss_action(p_actions_rx);
5331 if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
5334 * The following information is required by
5335 * mlx5_flow_hashfields_adjust() in advance.
5337 rss_desc->level = rss->level;
5338 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
5339 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
5341 flow->dev_handles = 0;
5342 if (rss && rss->types) {
5343 unsigned int graph_root;
5345 graph_root = find_graph_root(items, rss->level);
5346 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
5348 mlx5_support_expansion, graph_root);
5349 MLX5_ASSERT(ret > 0 &&
5350 (unsigned int)ret < sizeof(expand_buffer.buffer));
5353 buf->entry[0].pattern = (void *)(uintptr_t)items;
5355 rss_desc->shared_rss = flow_get_shared_rss_action(dev, shared_actions,
5357 for (i = 0; i < buf->entries; ++i) {
5358 /* Initialize flow split data. */
5359 flow_split_info.prefix_layers = 0;
5360 flow_split_info.prefix_mark = 0;
5361 flow_split_info.skip_scale = 0;
5363 * The splitter may create multiple dev_flows,
5364 * depending on configuration. In the simplest
5365 * case it just creates unmodified original flow.
5367 ret = flow_create_split_outer(dev, flow, attr,
5368 buf->entry[i].pattern,
5369 p_actions_rx, &flow_split_info,
5373 if (is_flow_tunnel_steer_rule(dev, attr,
5374 buf->entry[i].pattern,
5376 ret = flow_tunnel_add_default_miss(dev, flow, attr,
5382 mlx5_free(default_miss_ctx.queue);
5387 /* Create the tx flow. */
5389 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
5390 attr_tx.ingress = 0;
5392 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
5393 actions_hairpin_tx.actions,
5397 dev_flow->flow = flow;
5398 dev_flow->external = 0;
5399 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5400 dev_flow->handle, next);
5401 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
5403 actions_hairpin_tx.actions, error);
5408 * Update the metadata register copy table. If extensive
5409 * metadata feature is enabled and registers are supported
5410 * we might create the extra rte_flow for each unique
5411 * MARK/FLAG action ID.
5413 * The table is updated for ingress Flows only, because
5414 * the egress Flows belong to the different device and
5415 * copy table should be updated in peer NIC Rx domain.
5417 if (attr->ingress &&
5418 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
5419 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
5424 * If the flow is external (from application) OR device is started,
5425 * OR mreg discover, then apply immediately.
5427 if (external || dev->data->dev_started ||
5428 (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
5429 attr->priority == MLX5_FLOW_PRIO_RSVD)) {
5430 ret = flow_drv_apply(dev, flow, error);
5435 rte_spinlock_lock(&priv->flow_list_lock);
5436 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
5438 rte_spinlock_unlock(&priv->flow_list_lock);
5440 flow_rxq_flags_set(dev, flow);
5441 rte_free(translated_actions);
5442 tunnel = flow_tunnel_from_rule(dev, attr, items, actions);
5445 flow->tunnel_id = tunnel->tunnel_id;
5446 __atomic_add_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED);
5447 mlx5_free(default_miss_ctx.queue);
5449 mlx5_flow_pop_thread_workspace();
5453 ret = rte_errno; /* Save rte_errno before cleanup. */
5454 flow_mreg_del_copy_action(dev, flow);
5455 flow_drv_destroy(dev, flow);
5456 if (rss_desc->shared_rss)
5457 __atomic_sub_fetch(&((struct mlx5_shared_action_rss *)
5459 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
5460 rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
5461 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
5462 rte_errno = ret; /* Restore rte_errno. */
5465 mlx5_flow_pop_thread_workspace();
5466 error_before_hairpin_split:
5467 rte_free(translated_actions);
5472 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
5473 * incoming packets to table 1.
5475 * Other flow rules, requested for group n, will be created in
5476 * e-switch table n+1.
5477 * Jump action to e-switch group n will be created to group n+1.
5479 * Used when working in switchdev mode, to utilise advantages of table 1
5483 * Pointer to Ethernet device.
5486 * Pointer to flow on success, NULL otherwise and rte_errno is set.
5489 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
5491 const struct rte_flow_attr attr = {
5498 const struct rte_flow_item pattern = {
5499 .type = RTE_FLOW_ITEM_TYPE_END,
5501 struct rte_flow_action_jump jump = {
5504 const struct rte_flow_action actions[] = {
5506 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5510 .type = RTE_FLOW_ACTION_TYPE_END,
5513 struct mlx5_priv *priv = dev->data->dev_private;
5514 struct rte_flow_error error;
5516 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
5518 actions, false, &error);
5522 * Validate a flow supported by the NIC.
5524 * @see rte_flow_validate()
5528 mlx5_flow_validate(struct rte_eth_dev *dev,
5529 const struct rte_flow_attr *attr,
5530 const struct rte_flow_item items[],
5531 const struct rte_flow_action original_actions[],
5532 struct rte_flow_error *error)
5535 struct mlx5_translated_shared_action
5536 shared_actions[MLX5_MAX_SHARED_ACTIONS];
5537 int shared_actions_n = MLX5_MAX_SHARED_ACTIONS;
5538 const struct rte_flow_action *actions;
5539 struct rte_flow_action *translated_actions = NULL;
5540 int ret = flow_shared_actions_translate(dev, original_actions,
5543 &translated_actions, error);
5547 actions = translated_actions ? translated_actions : original_actions;
5548 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5549 ret = flow_drv_validate(dev, attr, items, actions,
5550 true, hairpin_flow, error);
5551 rte_free(translated_actions);
5558 * @see rte_flow_create()
5562 mlx5_flow_create(struct rte_eth_dev *dev,
5563 const struct rte_flow_attr *attr,
5564 const struct rte_flow_item items[],
5565 const struct rte_flow_action actions[],
5566 struct rte_flow_error *error)
5568 struct mlx5_priv *priv = dev->data->dev_private;
5571 * If the device is not started yet, it is not allowed to created a
5572 * flow from application. PMD default flows and traffic control flows
5575 if (unlikely(!dev->data->dev_started)) {
5576 DRV_LOG(DEBUG, "port %u is not started when "
5577 "inserting a flow", dev->data->port_id);
5578 rte_flow_error_set(error, ENODEV,
5579 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5581 "port not started");
5585 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
5586 attr, items, actions, true, error);
5590 * Destroy a flow in a list.
5593 * Pointer to Ethernet device.
5595 * Pointer to the Indexed flow list. If this parameter NULL,
5596 * there is no flow removal from the list. Be noted that as
5597 * flow is add to the indexed list, memory of the indexed
5598 * list points to maybe changed as flow destroyed.
5599 * @param[in] flow_idx
5600 * Index of flow to destroy.
5603 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
5606 struct mlx5_priv *priv = dev->data->dev_private;
5607 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5608 [MLX5_IPOOL_RTE_FLOW], flow_idx);
5613 * Update RX queue flags only if port is started, otherwise it is
5616 if (dev->data->dev_started)
5617 flow_rxq_flags_trim(dev, flow);
5618 flow_drv_destroy(dev, flow);
5620 rte_spinlock_lock(&priv->flow_list_lock);
5621 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
5622 flow_idx, flow, next);
5623 rte_spinlock_unlock(&priv->flow_list_lock);
5626 struct mlx5_flow_tunnel *tunnel;
5628 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
5630 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
5631 mlx5_flow_tunnel_free(dev, tunnel);
5633 flow_mreg_del_copy_action(dev, flow);
5634 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5638 * Destroy all flows.
5641 * Pointer to Ethernet device.
5643 * Pointer to the Indexed flow list.
5645 * If flushing is called avtively.
5648 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
5650 uint32_t num_flushed = 0;
5653 flow_list_destroy(dev, list, *list);
5657 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
5658 dev->data->port_id, num_flushed);
5663 * Stop all default actions for flows.
5666 * Pointer to Ethernet device.
5669 mlx5_flow_stop_default(struct rte_eth_dev *dev)
5671 flow_mreg_del_default_copy_action(dev);
5672 flow_rxq_flags_clear(dev);
5676 * Start all default actions for flows.
5679 * Pointer to Ethernet device.
5681 * 0 on success, a negative errno value otherwise and rte_errno is set.
5684 mlx5_flow_start_default(struct rte_eth_dev *dev)
5686 struct rte_flow_error error;
5688 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
5689 return flow_mreg_add_default_copy_action(dev, &error);
5693 * Release key of thread specific flow workspace data.
5696 flow_release_workspace(void *data)
5698 struct mlx5_flow_workspace *wks = data;
5699 struct mlx5_flow_workspace *next;
5703 free(wks->rss_desc.queue);
5710 * Initialize key of thread specific flow workspace data.
5713 flow_alloc_workspace(void)
5715 if (pthread_key_create(&key_workspace, flow_release_workspace))
5716 DRV_LOG(ERR, "Can't create flow workspace data thread key.");
5720 * Get thread specific current flow workspace.
5722 * @return pointer to thread specific flow workspace data, NULL on error.
5724 struct mlx5_flow_workspace*
5725 mlx5_flow_get_thread_workspace(void)
5727 struct mlx5_flow_workspace *data;
5729 data = pthread_getspecific(key_workspace);
5730 MLX5_ASSERT(data && data->inuse);
5731 if (!data || !data->inuse)
5732 DRV_LOG(ERR, "flow workspace not initialized.");
5737 * Allocate and init new flow workspace.
5739 * @return pointer to flow workspace data, NULL on error.
5741 static struct mlx5_flow_workspace*
5742 flow_alloc_thread_workspace(void)
5744 struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
5747 DRV_LOG(ERR, "Failed to allocate flow workspace "
5751 data->rss_desc.queue = calloc(1,
5752 sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
5753 if (!data->rss_desc.queue)
5755 data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
5758 if (data->rss_desc.queue)
5759 free(data->rss_desc.queue);
5765 * Get new thread specific flow workspace.
5767 * If current workspace inuse, create new one and set as current.
5769 * @return pointer to thread specific flow workspace data, NULL on error.
5771 static struct mlx5_flow_workspace*
5772 mlx5_flow_push_thread_workspace(void)
5774 struct mlx5_flow_workspace *curr;
5775 struct mlx5_flow_workspace *data;
5777 if (pthread_once(&key_workspace_init, flow_alloc_workspace)) {
5778 DRV_LOG(ERR, "Failed to init flow workspace data thread key.");
5781 curr = pthread_getspecific(key_workspace);
5783 data = flow_alloc_thread_workspace();
5786 } else if (!curr->inuse) {
5788 } else if (curr->next) {
5791 data = flow_alloc_thread_workspace();
5799 /* Set as current workspace */
5800 if (pthread_setspecific(key_workspace, data))
5801 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
5806 * Close current thread specific flow workspace.
5808 * If previous workspace available, set it as current.
5810 * @return pointer to thread specific flow workspace data, NULL on error.
5813 mlx5_flow_pop_thread_workspace(void)
5815 struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
5820 DRV_LOG(ERR, "Failed to close unused flow workspace.");
5826 if (pthread_setspecific(key_workspace, data->prev))
5827 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
5831 * Verify the flow list is empty
5834 * Pointer to Ethernet device.
5836 * @return the number of flows not released.
5839 mlx5_flow_verify(struct rte_eth_dev *dev)
5841 struct mlx5_priv *priv = dev->data->dev_private;
5842 struct rte_flow *flow;
5846 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
5848 DRV_LOG(DEBUG, "port %u flow %p still referenced",
5849 dev->data->port_id, (void *)flow);
5856 * Enable default hairpin egress flow.
5859 * Pointer to Ethernet device.
5864 * 0 on success, a negative errno value otherwise and rte_errno is set.
5867 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
5870 struct mlx5_priv *priv = dev->data->dev_private;
5871 const struct rte_flow_attr attr = {
5875 struct mlx5_rte_flow_item_tx_queue queue_spec = {
5878 struct mlx5_rte_flow_item_tx_queue queue_mask = {
5879 .queue = UINT32_MAX,
5881 struct rte_flow_item items[] = {
5883 .type = (enum rte_flow_item_type)
5884 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
5885 .spec = &queue_spec,
5887 .mask = &queue_mask,
5890 .type = RTE_FLOW_ITEM_TYPE_END,
5893 struct rte_flow_action_jump jump = {
5894 .group = MLX5_HAIRPIN_TX_TABLE,
5896 struct rte_flow_action actions[2];
5898 struct rte_flow_error error;
5900 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
5901 actions[0].conf = &jump;
5902 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
5903 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
5904 &attr, items, actions, false, &error);
5907 "Failed to create ctrl flow: rte_errno(%d),"
5908 " type(%d), message(%s)",
5909 rte_errno, error.type,
5910 error.message ? error.message : " (no stated reason)");
5917 * Enable a control flow configured from the control plane.
5920 * Pointer to Ethernet device.
5922 * An Ethernet flow spec to apply.
5924 * An Ethernet flow mask to apply.
5926 * A VLAN flow spec to apply.
5928 * A VLAN flow mask to apply.
5931 * 0 on success, a negative errno value otherwise and rte_errno is set.
5934 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
5935 struct rte_flow_item_eth *eth_spec,
5936 struct rte_flow_item_eth *eth_mask,
5937 struct rte_flow_item_vlan *vlan_spec,
5938 struct rte_flow_item_vlan *vlan_mask)
5940 struct mlx5_priv *priv = dev->data->dev_private;
5941 const struct rte_flow_attr attr = {
5943 .priority = MLX5_FLOW_PRIO_RSVD,
5945 struct rte_flow_item items[] = {
5947 .type = RTE_FLOW_ITEM_TYPE_ETH,
5953 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
5954 RTE_FLOW_ITEM_TYPE_END,
5960 .type = RTE_FLOW_ITEM_TYPE_END,
5963 uint16_t queue[priv->reta_idx_n];
5964 struct rte_flow_action_rss action_rss = {
5965 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
5967 .types = priv->rss_conf.rss_hf,
5968 .key_len = priv->rss_conf.rss_key_len,
5969 .queue_num = priv->reta_idx_n,
5970 .key = priv->rss_conf.rss_key,
5973 struct rte_flow_action actions[] = {
5975 .type = RTE_FLOW_ACTION_TYPE_RSS,
5976 .conf = &action_rss,
5979 .type = RTE_FLOW_ACTION_TYPE_END,
5983 struct rte_flow_error error;
5986 if (!priv->reta_idx_n || !priv->rxqs_n) {
5989 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
5990 action_rss.types = 0;
5991 for (i = 0; i != priv->reta_idx_n; ++i)
5992 queue[i] = (*priv->reta_idx)[i];
5993 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
5994 &attr, items, actions, false, &error);
6001 * Enable a flow control configured from the control plane.
6004 * Pointer to Ethernet device.
6006 * An Ethernet flow spec to apply.
6008 * An Ethernet flow mask to apply.
6011 * 0 on success, a negative errno value otherwise and rte_errno is set.
6014 mlx5_ctrl_flow(struct rte_eth_dev *dev,
6015 struct rte_flow_item_eth *eth_spec,
6016 struct rte_flow_item_eth *eth_mask)
6018 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
6022 * Create default miss flow rule matching lacp traffic
6025 * Pointer to Ethernet device.
6027 * An Ethernet flow spec to apply.
6030 * 0 on success, a negative errno value otherwise and rte_errno is set.
6033 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
6035 struct mlx5_priv *priv = dev->data->dev_private;
6037 * The LACP matching is done by only using ether type since using
6038 * a multicast dst mac causes kernel to give low priority to this flow.
6040 static const struct rte_flow_item_eth lacp_spec = {
6041 .type = RTE_BE16(0x8809),
6043 static const struct rte_flow_item_eth lacp_mask = {
6046 const struct rte_flow_attr attr = {
6049 struct rte_flow_item items[] = {
6051 .type = RTE_FLOW_ITEM_TYPE_ETH,
6056 .type = RTE_FLOW_ITEM_TYPE_END,
6059 struct rte_flow_action actions[] = {
6061 .type = (enum rte_flow_action_type)
6062 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
6065 .type = RTE_FLOW_ACTION_TYPE_END,
6068 struct rte_flow_error error;
6069 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
6070 &attr, items, actions, false, &error);
6080 * @see rte_flow_destroy()
6084 mlx5_flow_destroy(struct rte_eth_dev *dev,
6085 struct rte_flow *flow,
6086 struct rte_flow_error *error __rte_unused)
6088 struct mlx5_priv *priv = dev->data->dev_private;
6090 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
6095 * Destroy all flows.
6097 * @see rte_flow_flush()
6101 mlx5_flow_flush(struct rte_eth_dev *dev,
6102 struct rte_flow_error *error __rte_unused)
6104 struct mlx5_priv *priv = dev->data->dev_private;
6106 mlx5_flow_list_flush(dev, &priv->flows, false);
6113 * @see rte_flow_isolate()
6117 mlx5_flow_isolate(struct rte_eth_dev *dev,
6119 struct rte_flow_error *error)
6121 struct mlx5_priv *priv = dev->data->dev_private;
6123 if (dev->data->dev_started) {
6124 rte_flow_error_set(error, EBUSY,
6125 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6127 "port must be stopped first");
6130 priv->isolated = !!enable;
6132 dev->dev_ops = &mlx5_os_dev_ops_isolate;
6134 dev->dev_ops = &mlx5_os_dev_ops;
6136 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
6137 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
6145 * @see rte_flow_query()
6149 flow_drv_query(struct rte_eth_dev *dev,
6151 const struct rte_flow_action *actions,
6153 struct rte_flow_error *error)
6155 struct mlx5_priv *priv = dev->data->dev_private;
6156 const struct mlx5_flow_driver_ops *fops;
6157 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
6158 [MLX5_IPOOL_RTE_FLOW],
6160 enum mlx5_flow_drv_type ftype;
6163 return rte_flow_error_set(error, ENOENT,
6164 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6166 "invalid flow handle");
6168 ftype = flow->drv_type;
6169 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
6170 fops = flow_get_drv_ops(ftype);
6172 return fops->query(dev, flow, actions, data, error);
6178 * @see rte_flow_query()
6182 mlx5_flow_query(struct rte_eth_dev *dev,
6183 struct rte_flow *flow,
6184 const struct rte_flow_action *actions,
6186 struct rte_flow_error *error)
6190 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
6198 * Manage filter operations.
6201 * Pointer to Ethernet device structure.
6202 * @param filter_type
6205 * Operation to perform.
6207 * Pointer to operation-specific structure.
6210 * 0 on success, a negative errno value otherwise and rte_errno is set.
6213 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
6214 enum rte_filter_type filter_type,
6215 enum rte_filter_op filter_op,
6218 switch (filter_type) {
6219 case RTE_ETH_FILTER_GENERIC:
6220 if (filter_op != RTE_ETH_FILTER_GET) {
6224 *(const void **)arg = &mlx5_flow_ops;
6227 DRV_LOG(ERR, "port %u filter type (%d) not supported",
6228 dev->data->port_id, filter_type);
6229 rte_errno = ENOTSUP;
6236 * Create the needed meter and suffix tables.
6239 * Pointer to Ethernet device.
6241 * Pointer to the flow meter.
6244 * Pointer to table set on success, NULL otherwise.
6246 struct mlx5_meter_domains_infos *
6247 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
6248 const struct mlx5_flow_meter *fm)
6250 const struct mlx5_flow_driver_ops *fops;
6252 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6253 return fops->create_mtr_tbls(dev, fm);
6257 * Destroy the meter table set.
6260 * Pointer to Ethernet device.
6262 * Pointer to the meter table set.
6268 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
6269 struct mlx5_meter_domains_infos *tbls)
6271 const struct mlx5_flow_driver_ops *fops;
6273 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6274 return fops->destroy_mtr_tbls(dev, tbls);
6278 * Create policer rules.
6281 * Pointer to Ethernet device.
6283 * Pointer to flow meter structure.
6285 * Pointer to flow attributes.
6288 * 0 on success, -1 otherwise.
6291 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
6292 struct mlx5_flow_meter *fm,
6293 const struct rte_flow_attr *attr)
6295 const struct mlx5_flow_driver_ops *fops;
6297 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6298 return fops->create_policer_rules(dev, fm, attr);
6302 * Destroy policer rules.
6305 * Pointer to flow meter structure.
6307 * Pointer to flow attributes.
6310 * 0 on success, -1 otherwise.
6313 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
6314 struct mlx5_flow_meter *fm,
6315 const struct rte_flow_attr *attr)
6317 const struct mlx5_flow_driver_ops *fops;
6319 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6320 return fops->destroy_policer_rules(dev, fm, attr);
6324 * Allocate a counter.
6327 * Pointer to Ethernet device structure.
6330 * Index to allocated counter on success, 0 otherwise.
6333 mlx5_counter_alloc(struct rte_eth_dev *dev)
6335 const struct mlx5_flow_driver_ops *fops;
6336 struct rte_flow_attr attr = { .transfer = 0 };
6338 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6339 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6340 return fops->counter_alloc(dev);
6343 "port %u counter allocate is not supported.",
6344 dev->data->port_id);
6352 * Pointer to Ethernet device structure.
6354 * Index to counter to be free.
6357 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
6359 const struct mlx5_flow_driver_ops *fops;
6360 struct rte_flow_attr attr = { .transfer = 0 };
6362 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6363 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6364 fops->counter_free(dev, cnt);
6368 "port %u counter free is not supported.",
6369 dev->data->port_id);
6373 * Query counter statistics.
6376 * Pointer to Ethernet device structure.
6378 * Index to counter to query.
6380 * Set to clear counter statistics.
6382 * The counter hits packets number to save.
6384 * The counter hits bytes number to save.
6387 * 0 on success, a negative errno value otherwise.
6390 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
6391 bool clear, uint64_t *pkts, uint64_t *bytes)
6393 const struct mlx5_flow_driver_ops *fops;
6394 struct rte_flow_attr attr = { .transfer = 0 };
6396 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6397 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6398 return fops->counter_query(dev, cnt, clear, pkts, bytes);
6401 "port %u counter query is not supported.",
6402 dev->data->port_id);
6407 * Allocate a new memory for the counter values wrapped by all the needed
6411 * Pointer to mlx5_dev_ctx_shared object.
6414 * 0 on success, a negative errno value otherwise.
6417 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
6419 struct mlx5_devx_mkey_attr mkey_attr;
6420 struct mlx5_counter_stats_mem_mng *mem_mng;
6421 volatile struct flow_counter_stats *raw_data;
6422 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
6423 int size = (sizeof(struct flow_counter_stats) *
6424 MLX5_COUNTERS_PER_POOL +
6425 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
6426 sizeof(struct mlx5_counter_stats_mem_mng);
6427 size_t pgsize = rte_mem_page_size();
6431 if (pgsize == (size_t)-1) {
6432 DRV_LOG(ERR, "Failed to get mem page size");
6436 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
6441 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
6442 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
6443 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
6444 IBV_ACCESS_LOCAL_WRITE);
6445 if (!mem_mng->umem) {
6450 mkey_attr.addr = (uintptr_t)mem;
6451 mkey_attr.size = size;
6452 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
6453 mkey_attr.pd = sh->pdn;
6454 mkey_attr.log_entity_size = 0;
6455 mkey_attr.pg_access = 0;
6456 mkey_attr.klm_array = NULL;
6457 mkey_attr.klm_num = 0;
6458 mkey_attr.relaxed_ordering_write = sh->cmng.relaxed_ordering_write;
6459 mkey_attr.relaxed_ordering_read = sh->cmng.relaxed_ordering_read;
6460 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
6462 mlx5_glue->devx_umem_dereg(mem_mng->umem);
6467 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
6468 raw_data = (volatile struct flow_counter_stats *)mem;
6469 for (i = 0; i < raws_n; ++i) {
6470 mem_mng->raws[i].mem_mng = mem_mng;
6471 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
6473 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
6474 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
6475 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
6477 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
6478 sh->cmng.mem_mng = mem_mng;
6483 * Set the statistic memory to the new counter pool.
6486 * Pointer to mlx5_dev_ctx_shared object.
6488 * Pointer to the pool to set the statistic memory.
6491 * 0 on success, a negative errno value otherwise.
6494 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
6495 struct mlx5_flow_counter_pool *pool)
6497 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6498 /* Resize statistic memory once used out. */
6499 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
6500 mlx5_flow_create_counter_stat_mem_mng(sh)) {
6501 DRV_LOG(ERR, "Cannot resize counter stat mem.");
6504 rte_spinlock_lock(&pool->sl);
6505 pool->raw = cmng->mem_mng->raws + pool->index %
6506 MLX5_CNT_CONTAINER_RESIZE;
6507 rte_spinlock_unlock(&pool->sl);
6508 pool->raw_hw = NULL;
6512 #define MLX5_POOL_QUERY_FREQ_US 1000000
6515 * Set the periodic procedure for triggering asynchronous batch queries for all
6516 * the counter pools.
6519 * Pointer to mlx5_dev_ctx_shared object.
6522 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
6524 uint32_t pools_n, us;
6526 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
6527 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
6528 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
6529 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
6530 sh->cmng.query_thread_on = 0;
6531 DRV_LOG(ERR, "Cannot reinitialize query alarm");
6533 sh->cmng.query_thread_on = 1;
6538 * The periodic procedure for triggering asynchronous batch queries for all the
6539 * counter pools. This function is probably called by the host thread.
6542 * The parameter for the alarm process.
6545 mlx5_flow_query_alarm(void *arg)
6547 struct mlx5_dev_ctx_shared *sh = arg;
6549 uint16_t pool_index = sh->cmng.pool_index;
6550 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6551 struct mlx5_flow_counter_pool *pool;
6554 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
6556 rte_spinlock_lock(&cmng->pool_update_sl);
6557 pool = cmng->pools[pool_index];
6558 n_valid = cmng->n_valid;
6559 rte_spinlock_unlock(&cmng->pool_update_sl);
6560 /* Set the statistic memory to the new created pool. */
6561 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
6564 /* There is a pool query in progress. */
6567 LIST_FIRST(&sh->cmng.free_stat_raws);
6569 /* No free counter statistics raw memory. */
6572 * Identify the counters released between query trigger and query
6573 * handle more efficiently. The counter released in this gap period
6574 * should wait for a new round of query as the new arrived packets
6575 * will not be taken into account.
6578 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
6579 MLX5_COUNTERS_PER_POOL,
6581 pool->raw_hw->mem_mng->dm->id,
6585 (uint64_t)(uintptr_t)pool);
6587 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
6588 " %d", pool->min_dcs->id);
6589 pool->raw_hw = NULL;
6592 LIST_REMOVE(pool->raw_hw, next);
6593 sh->cmng.pending_queries++;
6595 if (pool_index >= n_valid)
6598 sh->cmng.pool_index = pool_index;
6599 mlx5_set_query_alarm(sh);
6603 * Check and callback event for new aged flow in the counter pool
6606 * Pointer to mlx5_dev_ctx_shared object.
6608 * Pointer to Current counter pool.
6611 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
6612 struct mlx5_flow_counter_pool *pool)
6614 struct mlx5_priv *priv;
6615 struct mlx5_flow_counter *cnt;
6616 struct mlx5_age_info *age_info;
6617 struct mlx5_age_param *age_param;
6618 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
6619 struct mlx5_counter_stats_raw *prev = pool->raw;
6620 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
6621 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
6622 uint16_t expected = AGE_CANDIDATE;
6625 pool->time_of_last_age_check = curr_time;
6626 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
6627 cnt = MLX5_POOL_GET_CNT(pool, i);
6628 age_param = MLX5_CNT_TO_AGE(cnt);
6629 if (__atomic_load_n(&age_param->state,
6630 __ATOMIC_RELAXED) != AGE_CANDIDATE)
6632 if (cur->data[i].hits != prev->data[i].hits) {
6633 __atomic_store_n(&age_param->sec_since_last_hit, 0,
6637 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
6639 __ATOMIC_RELAXED) <= age_param->timeout)
6642 * Hold the lock first, or if between the
6643 * state AGE_TMOUT and tailq operation the
6644 * release happened, the release procedure
6645 * may delete a non-existent tailq node.
6647 priv = rte_eth_devices[age_param->port_id].data->dev_private;
6648 age_info = GET_PORT_AGE_INFO(priv);
6649 rte_spinlock_lock(&age_info->aged_sl);
6650 if (__atomic_compare_exchange_n(&age_param->state, &expected,
6653 __ATOMIC_RELAXED)) {
6654 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
6655 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
6657 rte_spinlock_unlock(&age_info->aged_sl);
6659 mlx5_age_event_prepare(sh);
6663 * Handler for the HW respond about ready values from an asynchronous batch
6664 * query. This function is probably called by the host thread.
6667 * The pointer to the shared device context.
6668 * @param[in] async_id
6669 * The Devx async ID.
6671 * The status of the completion.
6674 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
6675 uint64_t async_id, int status)
6677 struct mlx5_flow_counter_pool *pool =
6678 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
6679 struct mlx5_counter_stats_raw *raw_to_free;
6680 uint8_t query_gen = pool->query_gen ^ 1;
6681 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6682 enum mlx5_counter_type cnt_type =
6683 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6684 MLX5_COUNTER_TYPE_ORIGIN;
6686 if (unlikely(status)) {
6687 raw_to_free = pool->raw_hw;
6689 raw_to_free = pool->raw;
6691 mlx5_flow_aging_check(sh, pool);
6692 rte_spinlock_lock(&pool->sl);
6693 pool->raw = pool->raw_hw;
6694 rte_spinlock_unlock(&pool->sl);
6695 /* Be sure the new raw counters data is updated in memory. */
6697 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
6698 rte_spinlock_lock(&cmng->csl[cnt_type]);
6699 TAILQ_CONCAT(&cmng->counters[cnt_type],
6700 &pool->counters[query_gen], next);
6701 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6704 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
6705 pool->raw_hw = NULL;
6706 sh->cmng.pending_queries--;
6710 flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
6711 const struct flow_grp_info *grp_info,
6712 struct rte_flow_error *error)
6714 if (grp_info->transfer && grp_info->external &&
6715 grp_info->fdb_def_rule) {
6716 if (group == UINT32_MAX)
6717 return rte_flow_error_set
6719 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6721 "group index not supported");
6726 DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
6731 * Translate the rte_flow group index to HW table value.
6733 * If tunnel offload is disabled, all group ids converted to flow table
6734 * id using the standard method.
6735 * If tunnel offload is enabled, group id can be converted using the
6736 * standard or tunnel conversion method. Group conversion method
6737 * selection depends on flags in `grp_info` parameter:
6738 * - Internal (grp_info.external == 0) groups conversion uses the
6740 * - Group ids in JUMP action converted with the tunnel conversion.
6741 * - Group id in rule attribute conversion depends on a rule type and
6743 * ** non zero group attributes converted with the tunnel method
6744 * ** zero group attribute in non-tunnel rule is converted using the
6745 * standard method - there's only one root table
6746 * ** zero group attribute in steer tunnel rule is converted with the
6747 * standard method - single root table
6748 * ** zero group attribute in match tunnel rule is a special OvS
6749 * case: that value is used for portability reasons. That group
6750 * id is converted with the tunnel conversion method.
6755 * PMD tunnel offload object
6757 * rte_flow group index value.
6760 * @param[in] grp_info
6761 * flags used for conversion
6763 * Pointer to error structure.
6766 * 0 on success, a negative errno value otherwise and rte_errno is set.
6769 mlx5_flow_group_to_table(struct rte_eth_dev *dev,
6770 const struct mlx5_flow_tunnel *tunnel,
6771 uint32_t group, uint32_t *table,
6772 const struct flow_grp_info *grp_info,
6773 struct rte_flow_error *error)
6776 bool standard_translation;
6778 if (!grp_info->skip_scale && grp_info->external &&
6779 group < MLX5_MAX_TABLES_EXTERNAL)
6780 group *= MLX5_FLOW_TABLE_FACTOR;
6781 if (is_tunnel_offload_active(dev)) {
6782 standard_translation = !grp_info->external ||
6783 grp_info->std_tbl_fix;
6785 standard_translation = true;
6788 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
6789 dev->data->port_id, group, grp_info->transfer,
6790 grp_info->external, grp_info->fdb_def_rule,
6791 standard_translation ? "STANDARD" : "TUNNEL");
6792 if (standard_translation)
6793 ret = flow_group_to_table(dev->data->port_id, group, table,
6796 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
6803 * Discover availability of metadata reg_c's.
6805 * Iteratively use test flows to check availability.
6808 * Pointer to the Ethernet device structure.
6811 * 0 on success, a negative errno value otherwise and rte_errno is set.
6814 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
6816 struct mlx5_priv *priv = dev->data->dev_private;
6817 struct mlx5_dev_config *config = &priv->config;
6818 enum modify_reg idx;
6821 /* reg_c[0] and reg_c[1] are reserved. */
6822 config->flow_mreg_c[n++] = REG_C_0;
6823 config->flow_mreg_c[n++] = REG_C_1;
6824 /* Discover availability of other reg_c's. */
6825 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
6826 struct rte_flow_attr attr = {
6827 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
6828 .priority = MLX5_FLOW_PRIO_RSVD,
6831 struct rte_flow_item items[] = {
6833 .type = RTE_FLOW_ITEM_TYPE_END,
6836 struct rte_flow_action actions[] = {
6838 .type = (enum rte_flow_action_type)
6839 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6840 .conf = &(struct mlx5_flow_action_copy_mreg){
6846 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6847 .conf = &(struct rte_flow_action_jump){
6848 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
6852 .type = RTE_FLOW_ACTION_TYPE_END,
6856 struct rte_flow *flow;
6857 struct rte_flow_error error;
6859 if (!config->dv_flow_en)
6861 /* Create internal flow, validation skips copy action. */
6862 flow_idx = flow_list_create(dev, NULL, &attr, items,
6863 actions, false, &error);
6864 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
6868 config->flow_mreg_c[n++] = idx;
6869 flow_list_destroy(dev, NULL, flow_idx);
6871 for (; n < MLX5_MREG_C_NUM; ++n)
6872 config->flow_mreg_c[n] = REG_NON;
6877 * Dump flow raw hw data to file
6880 * The pointer to Ethernet device.
6882 * A pointer to a file for output.
6884 * Perform verbose error reporting if not NULL. PMDs initialize this
6885 * structure in case of error only.
6887 * 0 on success, a nagative value otherwise.
6890 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
6892 struct rte_flow_error *error __rte_unused)
6894 struct mlx5_priv *priv = dev->data->dev_private;
6895 struct mlx5_dev_ctx_shared *sh = priv->sh;
6897 if (!priv->config.dv_flow_en) {
6898 if (fputs("device dv flow disabled\n", file) <= 0)
6902 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
6903 sh->tx_domain, file);
6907 * Get aged-out flows.
6910 * Pointer to the Ethernet device structure.
6911 * @param[in] context
6912 * The address of an array of pointers to the aged-out flows contexts.
6913 * @param[in] nb_countexts
6914 * The length of context array pointers.
6916 * Perform verbose error reporting if not NULL. Initialized in case of
6920 * how many contexts get in success, otherwise negative errno value.
6921 * if nb_contexts is 0, return the amount of all aged contexts.
6922 * if nb_contexts is not 0 , return the amount of aged flows reported
6923 * in the context array.
6926 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
6927 uint32_t nb_contexts, struct rte_flow_error *error)
6929 const struct mlx5_flow_driver_ops *fops;
6930 struct rte_flow_attr attr = { .transfer = 0 };
6932 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6933 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6934 return fops->get_aged_flows(dev, contexts, nb_contexts,
6938 "port %u get aged flows is not supported.",
6939 dev->data->port_id);
6943 /* Wrapper for driver action_validate op callback */
6945 flow_drv_action_validate(struct rte_eth_dev *dev,
6946 const struct rte_flow_shared_action_conf *conf,
6947 const struct rte_flow_action *action,
6948 const struct mlx5_flow_driver_ops *fops,
6949 struct rte_flow_error *error)
6951 static const char err_msg[] = "shared action validation unsupported";
6953 if (!fops->action_validate) {
6954 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
6955 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
6959 return fops->action_validate(dev, conf, action, error);
6963 * Destroys the shared action by handle.
6966 * Pointer to Ethernet device structure.
6968 * Handle for the shared action to be destroyed.
6970 * Perform verbose error reporting if not NULL. PMDs initialize this
6971 * structure in case of error only.
6974 * 0 on success, a negative errno value otherwise and rte_errno is set.
6976 * @note: wrapper for driver action_create op callback.
6979 mlx5_shared_action_destroy(struct rte_eth_dev *dev,
6980 struct rte_flow_shared_action *action,
6981 struct rte_flow_error *error)
6983 static const char err_msg[] = "shared action destruction unsupported";
6984 struct rte_flow_attr attr = { .transfer = 0 };
6985 const struct mlx5_flow_driver_ops *fops =
6986 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
6988 if (!fops->action_destroy) {
6989 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
6990 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
6994 return fops->action_destroy(dev, action, error);
6997 /* Wrapper for driver action_destroy op callback */
6999 flow_drv_action_update(struct rte_eth_dev *dev,
7000 struct rte_flow_shared_action *action,
7001 const void *action_conf,
7002 const struct mlx5_flow_driver_ops *fops,
7003 struct rte_flow_error *error)
7005 static const char err_msg[] = "shared action update unsupported";
7007 if (!fops->action_update) {
7008 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7009 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7013 return fops->action_update(dev, action, action_conf, error);
7016 /* Wrapper for driver action_destroy op callback */
7018 flow_drv_action_query(struct rte_eth_dev *dev,
7019 const struct rte_flow_shared_action *action,
7021 const struct mlx5_flow_driver_ops *fops,
7022 struct rte_flow_error *error)
7024 static const char err_msg[] = "shared action query unsupported";
7026 if (!fops->action_query) {
7027 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7028 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7032 return fops->action_query(dev, action, data, error);
7036 * Create shared action for reuse in multiple flow rules.
7039 * Pointer to Ethernet device structure.
7041 * Action configuration for shared action creation.
7043 * Perform verbose error reporting if not NULL. PMDs initialize this
7044 * structure in case of error only.
7046 * A valid handle in case of success, NULL otherwise and rte_errno is set.
7048 static struct rte_flow_shared_action *
7049 mlx5_shared_action_create(struct rte_eth_dev *dev,
7050 const struct rte_flow_shared_action_conf *conf,
7051 const struct rte_flow_action *action,
7052 struct rte_flow_error *error)
7054 static const char err_msg[] = "shared action creation unsupported";
7055 struct rte_flow_attr attr = { .transfer = 0 };
7056 const struct mlx5_flow_driver_ops *fops =
7057 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7059 if (flow_drv_action_validate(dev, conf, action, fops, error))
7061 if (!fops->action_create) {
7062 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
7063 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
7067 return fops->action_create(dev, conf, action, error);
7071 * Updates inplace the shared action configuration pointed by *action* handle
7072 * with the configuration provided as *action* argument.
7073 * The update of the shared action configuration effects all flow rules reusing
7074 * the action via handle.
7077 * Pointer to Ethernet device structure.
7078 * @param[in] shared_action
7079 * Handle for the shared action to be updated.
7081 * Action specification used to modify the action pointed by handle.
7082 * *action* should be of same type with the action pointed by the *action*
7083 * handle argument, otherwise considered as invalid.
7085 * Perform verbose error reporting if not NULL. PMDs initialize this
7086 * structure in case of error only.
7089 * 0 on success, a negative errno value otherwise and rte_errno is set.
7092 mlx5_shared_action_update(struct rte_eth_dev *dev,
7093 struct rte_flow_shared_action *shared_action,
7094 const struct rte_flow_action *action,
7095 struct rte_flow_error *error)
7097 struct rte_flow_attr attr = { .transfer = 0 };
7098 const struct mlx5_flow_driver_ops *fops =
7099 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7102 ret = flow_drv_action_validate(dev, NULL, action, fops, error);
7105 return flow_drv_action_update(dev, shared_action, action->conf, fops,
7110 * Query the shared action by handle.
7112 * This function allows retrieving action-specific data such as counters.
7113 * Data is gathered by special action which may be present/referenced in
7114 * more than one flow rule definition.
7116 * \see RTE_FLOW_ACTION_TYPE_COUNT
7119 * Pointer to Ethernet device structure.
7121 * Handle for the shared action to query.
7122 * @param[in, out] data
7123 * Pointer to storage for the associated query data type.
7125 * Perform verbose error reporting if not NULL. PMDs initialize this
7126 * structure in case of error only.
7129 * 0 on success, a negative errno value otherwise and rte_errno is set.
7132 mlx5_shared_action_query(struct rte_eth_dev *dev,
7133 const struct rte_flow_shared_action *action,
7135 struct rte_flow_error *error)
7137 struct rte_flow_attr attr = { .transfer = 0 };
7138 const struct mlx5_flow_driver_ops *fops =
7139 flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7141 return flow_drv_action_query(dev, action, data, fops, error);
7145 * Destroy all shared actions.
7148 * Pointer to Ethernet device.
7151 * 0 on success, a negative errno value otherwise and rte_errno is set.
7154 mlx5_shared_action_flush(struct rte_eth_dev *dev)
7156 struct rte_flow_error error;
7157 struct mlx5_priv *priv = dev->data->dev_private;
7158 struct mlx5_shared_action_rss *action;
7162 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
7163 priv->rss_shared_actions, idx, action, next) {
7164 ret |= mlx5_shared_action_destroy(dev,
7165 (struct rte_flow_shared_action *)(uintptr_t)idx, &error);
7170 #ifndef HAVE_MLX5DV_DR
7171 #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
7173 #define MLX5_DOMAIN_SYNC_FLOW \
7174 (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
7177 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
7179 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
7180 const struct mlx5_flow_driver_ops *fops;
7182 struct rte_flow_attr attr = { .transfer = 0 };
7184 fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
7185 ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
7192 * tunnel offload functionalilty is defined for DV environment only
7194 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7196 union tunnel_offload_mark {
7199 uint32_t app_reserve:8;
7200 uint32_t table_id:15;
7201 uint32_t transfer:1;
7202 uint32_t _unused_:8;
7207 mlx5_access_tunnel_offload_db
7208 (struct rte_eth_dev *dev,
7209 bool (*match)(struct rte_eth_dev *,
7210 struct mlx5_flow_tunnel *, const void *),
7211 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
7212 void (*miss)(struct rte_eth_dev *, void *),
7213 void *ctx, bool lock_op);
7216 flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
7217 struct rte_flow *flow,
7218 const struct rte_flow_attr *attr,
7219 const struct rte_flow_action *app_actions,
7221 struct tunnel_default_miss_ctx *ctx,
7222 struct rte_flow_error *error)
7224 struct mlx5_priv *priv = dev->data->dev_private;
7225 struct mlx5_flow *dev_flow;
7226 struct rte_flow_attr miss_attr = *attr;
7227 const struct mlx5_flow_tunnel *tunnel = app_actions[0].conf;
7228 const struct rte_flow_item miss_items[2] = {
7230 .type = RTE_FLOW_ITEM_TYPE_ETH,
7236 .type = RTE_FLOW_ITEM_TYPE_END,
7242 union tunnel_offload_mark mark_id;
7243 struct rte_flow_action_mark miss_mark;
7244 struct rte_flow_action miss_actions[3] = {
7245 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
7246 [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
7248 const struct rte_flow_action_jump *jump_data;
7249 uint32_t i, flow_table = 0; /* prevent compilation warning */
7250 struct flow_grp_info grp_info = {
7252 .transfer = attr->transfer,
7253 .fdb_def_rule = !!priv->fdb_def_rule,
7258 if (!attr->transfer) {
7261 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
7262 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
7263 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
7266 return rte_flow_error_set
7268 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
7269 NULL, "invalid default miss RSS");
7270 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
7271 ctx->action_rss.level = 0,
7272 ctx->action_rss.types = priv->rss_conf.rss_hf,
7273 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
7274 ctx->action_rss.queue_num = priv->reta_idx_n,
7275 ctx->action_rss.key = priv->rss_conf.rss_key,
7276 ctx->action_rss.queue = ctx->queue;
7277 if (!priv->reta_idx_n || !priv->rxqs_n)
7278 return rte_flow_error_set
7280 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
7281 NULL, "invalid port configuration");
7282 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
7283 ctx->action_rss.types = 0;
7284 for (i = 0; i != priv->reta_idx_n; ++i)
7285 ctx->queue[i] = (*priv->reta_idx)[i];
7287 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
7288 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
7290 miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
7291 for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
7292 jump_data = app_actions->conf;
7293 miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
7294 miss_attr.group = jump_data->group;
7295 ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
7296 &flow_table, &grp_info, error);
7298 return rte_flow_error_set(error, EINVAL,
7299 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
7300 NULL, "invalid tunnel id");
7301 mark_id.app_reserve = 0;
7302 mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
7303 mark_id.transfer = !!attr->transfer;
7304 mark_id._unused_ = 0;
7305 miss_mark.id = mark_id.val;
7306 dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
7307 miss_items, miss_actions, flow_idx, error);
7310 dev_flow->flow = flow;
7311 dev_flow->external = true;
7312 dev_flow->tunnel = tunnel;
7313 /* Subflow object was created, we must include one in the list. */
7314 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
7315 dev_flow->handle, next);
7317 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
7318 dev->data->port_id, tunnel->app_tunnel.type,
7319 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
7320 ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
7321 miss_actions, error);
7323 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
7329 static const struct mlx5_flow_tbl_data_entry *
7330 tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
7332 struct mlx5_priv *priv = dev->data->dev_private;
7333 struct mlx5_dev_ctx_shared *sh = priv->sh;
7334 struct mlx5_hlist_entry *he;
7335 union tunnel_offload_mark mbits = { .val = mark };
7336 union mlx5_flow_tbl_key table_key = {
7338 .table_id = tunnel_id_to_flow_tbl(mbits.table_id),
7340 .domain = !!mbits.transfer,
7344 he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, NULL);
7346 container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
7350 mlx5_flow_tunnel_grp2tbl_remove_cb(struct mlx5_hlist *list,
7351 struct mlx5_hlist_entry *entry)
7353 struct mlx5_dev_ctx_shared *sh = list->ctx;
7354 struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
7356 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
7357 tunnel_flow_tbl_to_id(tte->flow_table));
7361 static struct mlx5_hlist_entry *
7362 mlx5_flow_tunnel_grp2tbl_create_cb(struct mlx5_hlist *list,
7363 uint64_t key __rte_unused,
7364 void *ctx __rte_unused)
7366 struct mlx5_dev_ctx_shared *sh = list->ctx;
7367 struct tunnel_tbl_entry *tte;
7369 tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
7374 mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
7376 if (tte->flow_table >= MLX5_MAX_TABLES) {
7377 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
7379 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
7382 } else if (!tte->flow_table) {
7385 tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
7394 tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
7395 const struct mlx5_flow_tunnel *tunnel,
7396 uint32_t group, uint32_t *table,
7397 struct rte_flow_error *error)
7399 struct mlx5_hlist_entry *he;
7400 struct tunnel_tbl_entry *tte;
7401 union tunnel_tbl_key key = {
7402 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
7405 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7406 struct mlx5_hlist *group_hash;
7408 group_hash = tunnel ? tunnel->groups : thub->groups;
7409 he = mlx5_hlist_register(group_hash, key.val, NULL);
7411 return rte_flow_error_set(error, EINVAL,
7412 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7414 "tunnel group index not supported");
7415 tte = container_of(he, typeof(*tte), hash);
7416 *table = tte->flow_table;
7417 DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
7418 dev->data->port_id, key.tunnel_id, group, *table);
7423 mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
7424 struct mlx5_flow_tunnel *tunnel)
7426 struct mlx5_priv *priv = dev->data->dev_private;
7427 struct mlx5_indexed_pool *ipool;
7429 DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
7430 dev->data->port_id, tunnel->tunnel_id);
7431 mlx5_hlist_destroy(tunnel->groups);
7432 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
7433 mlx5_ipool_free(ipool, tunnel->tunnel_id);
7437 mlx5_access_tunnel_offload_db
7438 (struct rte_eth_dev *dev,
7439 bool (*match)(struct rte_eth_dev *,
7440 struct mlx5_flow_tunnel *, const void *),
7441 void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
7442 void (*miss)(struct rte_eth_dev *, void *),
7443 void *ctx, bool lock_op)
7445 bool verdict = false;
7446 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7447 struct mlx5_flow_tunnel *tunnel;
7449 rte_spinlock_lock(&thub->sl);
7450 LIST_FOREACH(tunnel, &thub->tunnels, chain) {
7451 verdict = match(dev, tunnel, (const void *)ctx);
7456 rte_spinlock_unlock(&thub->sl);
7458 hit(dev, tunnel, ctx);
7459 if (!verdict && miss)
7462 rte_spinlock_unlock(&thub->sl);
7467 struct tunnel_db_find_tunnel_id_ctx {
7469 struct mlx5_flow_tunnel *tunnel;
7473 find_tunnel_id_match(struct rte_eth_dev *dev,
7474 struct mlx5_flow_tunnel *tunnel, const void *x)
7476 const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
7479 return tunnel->tunnel_id == ctx->tunnel_id;
7483 find_tunnel_id_hit(struct rte_eth_dev *dev,
7484 struct mlx5_flow_tunnel *tunnel, void *x)
7486 struct tunnel_db_find_tunnel_id_ctx *ctx = x;
7488 ctx->tunnel = tunnel;
7491 static struct mlx5_flow_tunnel *
7492 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
7494 struct tunnel_db_find_tunnel_id_ctx ctx = {
7498 mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
7499 find_tunnel_id_hit, NULL, &ctx, true);
7504 static struct mlx5_flow_tunnel *
7505 mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
7506 const struct rte_flow_tunnel *app_tunnel)
7508 struct mlx5_priv *priv = dev->data->dev_private;
7509 struct mlx5_indexed_pool *ipool;
7510 struct mlx5_flow_tunnel *tunnel;
7513 ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
7514 tunnel = mlx5_ipool_zmalloc(ipool, &id);
7517 if (id >= MLX5_MAX_TUNNELS) {
7518 mlx5_ipool_free(ipool, id);
7519 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
7522 tunnel->groups = mlx5_hlist_create("tunnel groups", 1024, 0, 0,
7523 mlx5_flow_tunnel_grp2tbl_create_cb,
7525 mlx5_flow_tunnel_grp2tbl_remove_cb);
7526 if (!tunnel->groups) {
7527 mlx5_ipool_free(ipool, id);
7530 tunnel->groups->ctx = priv->sh;
7531 /* initiate new PMD tunnel */
7532 memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
7533 tunnel->tunnel_id = id;
7534 tunnel->action.type = (typeof(tunnel->action.type))
7535 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
7536 tunnel->action.conf = tunnel;
7537 tunnel->item.type = (typeof(tunnel->item.type))
7538 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
7539 tunnel->item.spec = tunnel;
7540 tunnel->item.last = NULL;
7541 tunnel->item.mask = NULL;
7543 DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
7544 dev->data->port_id, tunnel->tunnel_id);
7549 struct tunnel_db_get_tunnel_ctx {
7550 const struct rte_flow_tunnel *app_tunnel;
7551 struct mlx5_flow_tunnel *tunnel;
7554 static bool get_tunnel_match(struct rte_eth_dev *dev,
7555 struct mlx5_flow_tunnel *tunnel, const void *x)
7557 const struct tunnel_db_get_tunnel_ctx *ctx = x;
7560 return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
7561 sizeof(*ctx->app_tunnel));
7564 static void get_tunnel_hit(struct rte_eth_dev *dev,
7565 struct mlx5_flow_tunnel *tunnel, void *x)
7567 /* called under tunnel spinlock protection */
7568 struct tunnel_db_get_tunnel_ctx *ctx = x;
7572 ctx->tunnel = tunnel;
7575 static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
7577 /* called under tunnel spinlock protection */
7578 struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
7579 struct tunnel_db_get_tunnel_ctx *ctx = x;
7581 rte_spinlock_unlock(&thub->sl);
7582 ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
7583 ctx->tunnel->refctn = 1;
7584 rte_spinlock_lock(&thub->sl);
7586 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
7591 mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
7592 const struct rte_flow_tunnel *app_tunnel,
7593 struct mlx5_flow_tunnel **tunnel)
7595 struct tunnel_db_get_tunnel_ctx ctx = {
7596 .app_tunnel = app_tunnel,
7599 mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
7600 get_tunnel_miss, &ctx, true);
7601 *tunnel = ctx.tunnel;
7602 return ctx.tunnel ? 0 : -ENOMEM;
7605 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
7607 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
7611 if (!LIST_EMPTY(&thub->tunnels))
7612 DRV_LOG(WARNING, "port %u tunnels present\n", port_id);
7613 mlx5_hlist_destroy(thub->groups);
7617 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
7620 struct mlx5_flow_tunnel_hub *thub;
7622 thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
7626 LIST_INIT(&thub->tunnels);
7627 rte_spinlock_init(&thub->sl);
7628 thub->groups = mlx5_hlist_create("flow groups", MLX5_MAX_TABLES, 0,
7629 0, mlx5_flow_tunnel_grp2tbl_create_cb,
7631 mlx5_flow_tunnel_grp2tbl_remove_cb);
7632 if (!thub->groups) {
7636 thub->groups->ctx = sh;
7637 sh->tunnel_hub = thub;
7643 mlx5_hlist_destroy(thub->groups);
7650 mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
7651 struct rte_flow_tunnel *tunnel,
7652 const char *err_msg)
7655 if (!is_tunnel_offload_active(dev)) {
7656 err_msg = "tunnel offload was not activated";
7658 } else if (!tunnel) {
7659 err_msg = "no application tunnel";
7663 switch (tunnel->type) {
7665 err_msg = "unsupported tunnel type";
7667 case RTE_FLOW_ITEM_TYPE_VXLAN:
7676 mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
7677 struct rte_flow_tunnel *app_tunnel,
7678 struct rte_flow_action **actions,
7679 uint32_t *num_of_actions,
7680 struct rte_flow_error *error)
7683 struct mlx5_flow_tunnel *tunnel;
7684 const char *err_msg = NULL;
7685 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
7688 return rte_flow_error_set(error, EINVAL,
7689 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
7691 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
7693 return rte_flow_error_set(error, ret,
7694 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
7695 "failed to initialize pmd tunnel");
7697 *actions = &tunnel->action;
7698 *num_of_actions = 1;
7703 mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
7704 struct rte_flow_tunnel *app_tunnel,
7705 struct rte_flow_item **items,
7706 uint32_t *num_of_items,
7707 struct rte_flow_error *error)
7710 struct mlx5_flow_tunnel *tunnel;
7711 const char *err_msg = NULL;
7712 bool verdict = mlx5_flow_tunnel_validate(dev, app_tunnel, err_msg);
7715 return rte_flow_error_set(error, EINVAL,
7716 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
7718 ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
7720 return rte_flow_error_set(error, ret,
7721 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
7722 "failed to initialize pmd tunnel");
7724 *items = &tunnel->item;
7729 struct tunnel_db_element_release_ctx {
7730 struct rte_flow_item *items;
7731 struct rte_flow_action *actions;
7732 uint32_t num_elements;
7733 struct rte_flow_error *error;
7738 tunnel_element_release_match(struct rte_eth_dev *dev,
7739 struct mlx5_flow_tunnel *tunnel, const void *x)
7741 const struct tunnel_db_element_release_ctx *ctx = x;
7744 if (ctx->num_elements != 1)
7746 else if (ctx->items)
7747 return ctx->items == &tunnel->item;
7748 else if (ctx->actions)
7749 return ctx->actions == &tunnel->action;
7755 tunnel_element_release_hit(struct rte_eth_dev *dev,
7756 struct mlx5_flow_tunnel *tunnel, void *x)
7758 struct tunnel_db_element_release_ctx *ctx = x;
7760 if (!__atomic_sub_fetch(&tunnel->refctn, 1, __ATOMIC_RELAXED))
7761 mlx5_flow_tunnel_free(dev, tunnel);
7765 tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
7767 struct tunnel_db_element_release_ctx *ctx = x;
7769 ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
7770 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
7771 "invalid argument");
7775 mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
7776 struct rte_flow_item *pmd_items,
7777 uint32_t num_items, struct rte_flow_error *err)
7779 struct tunnel_db_element_release_ctx ctx = {
7782 .num_elements = num_items,
7786 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
7787 tunnel_element_release_hit,
7788 tunnel_element_release_miss, &ctx, false);
7794 mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
7795 struct rte_flow_action *pmd_actions,
7796 uint32_t num_actions, struct rte_flow_error *err)
7798 struct tunnel_db_element_release_ctx ctx = {
7800 .actions = pmd_actions,
7801 .num_elements = num_actions,
7805 mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
7806 tunnel_element_release_hit,
7807 tunnel_element_release_miss, &ctx, false);
7813 mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
7815 struct rte_flow_restore_info *info,
7816 struct rte_flow_error *err)
7818 uint64_t ol_flags = m->ol_flags;
7819 const struct mlx5_flow_tbl_data_entry *tble;
7820 const uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
7822 if (!is_tunnel_offload_active(dev)) {
7827 if ((ol_flags & mask) != mask)
7829 tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
7831 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
7832 dev->data->port_id, m->hash.fdir.hi);
7835 MLX5_ASSERT(tble->tunnel);
7836 memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
7837 info->group_id = tble->group_id;
7838 info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
7839 RTE_FLOW_RESTORE_INFO_GROUP_ID |
7840 RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
7845 return rte_flow_error_set(err, EINVAL,
7846 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7847 "failed to get restore info");
7850 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
7852 mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
7853 __rte_unused struct rte_flow_tunnel *app_tunnel,
7854 __rte_unused struct rte_flow_action **actions,
7855 __rte_unused uint32_t *num_of_actions,
7856 __rte_unused struct rte_flow_error *error)
7862 mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
7863 __rte_unused struct rte_flow_tunnel *app_tunnel,
7864 __rte_unused struct rte_flow_item **items,
7865 __rte_unused uint32_t *num_of_items,
7866 __rte_unused struct rte_flow_error *error)
7872 mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
7873 __rte_unused struct rte_flow_item *pmd_items,
7874 __rte_unused uint32_t num_items,
7875 __rte_unused struct rte_flow_error *err)
7881 mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
7882 __rte_unused struct rte_flow_action *pmd_action,
7883 __rte_unused uint32_t num_actions,
7884 __rte_unused struct rte_flow_error *err)
7890 mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
7891 __rte_unused struct rte_mbuf *m,
7892 __rte_unused struct rte_flow_restore_info *i,
7893 __rte_unused struct rte_flow_error *err)
7899 flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
7900 __rte_unused struct rte_flow *flow,
7901 __rte_unused const struct rte_flow_attr *attr,
7902 __rte_unused const struct rte_flow_action *actions,
7903 __rte_unused uint32_t flow_idx,
7904 __rte_unused struct tunnel_default_miss_ctx *ctx,
7905 __rte_unused struct rte_flow_error *error)
7910 static struct mlx5_flow_tunnel *
7911 mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
7912 __rte_unused uint32_t id)
7918 mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
7919 __rte_unused struct mlx5_flow_tunnel *tunnel)
7924 tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
7925 __rte_unused const struct mlx5_flow_tunnel *t,
7926 __rte_unused uint32_t group,
7927 __rte_unused uint32_t *table,
7928 struct rte_flow_error *error)
7930 return rte_flow_error_set(error, ENOTSUP,
7931 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7932 "tunnel offload requires DV support");
7936 mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
7937 __rte_unused uint16_t port_id)
7940 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */