1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
6 #include <netinet/in.h>
13 #include <rte_common.h>
14 #include <rte_ether.h>
15 #include <rte_ethdev_driver.h>
16 #include <rte_eal_paging.h>
18 #include <rte_cycles.h>
19 #include <rte_flow_driver.h>
20 #include <rte_malloc.h>
23 #include <mlx5_glue.h>
24 #include <mlx5_devx_cmds.h>
26 #include <mlx5_malloc.h>
28 #include "mlx5_defs.h"
30 #include "mlx5_flow.h"
31 #include "mlx5_flow_os.h"
32 #include "mlx5_rxtx.h"
33 #include "mlx5_common_os.h"
35 /** Device flow drivers. */
36 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
38 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
40 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
41 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
42 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
43 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
45 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
46 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
49 /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
50 #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
55 /** Node object of input graph for mlx5_flow_expand_rss(). */
56 struct mlx5_flow_expand_node {
57 const int *const next;
59 * List of next node indexes. Index 0 is interpreted as a terminator.
61 const enum rte_flow_item_type type;
62 /**< Pattern item type of current node. */
65 * RSS types bit-field associated with this node
66 * (see ETH_RSS_* definitions).
70 /** Object returned by mlx5_flow_expand_rss(). */
71 struct mlx5_flow_expand_rss {
73 /**< Number of entries @p patterns and @p priorities. */
75 struct rte_flow_item *pattern; /**< Expanded pattern array. */
76 uint32_t priority; /**< Priority offset for each expansion. */
80 static enum rte_flow_item_type
81 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
83 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
84 uint16_t ether_type = 0;
85 uint16_t ether_type_m;
86 uint8_t ip_next_proto = 0;
87 uint8_t ip_next_proto_m;
89 if (item == NULL || item->spec == NULL)
92 case RTE_FLOW_ITEM_TYPE_ETH:
94 ether_type_m = ((const struct rte_flow_item_eth *)
97 ether_type_m = rte_flow_item_eth_mask.type;
98 if (ether_type_m != RTE_BE16(0xFFFF))
100 ether_type = ((const struct rte_flow_item_eth *)
102 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
103 ret = RTE_FLOW_ITEM_TYPE_IPV4;
104 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
105 ret = RTE_FLOW_ITEM_TYPE_IPV6;
106 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
107 ret = RTE_FLOW_ITEM_TYPE_VLAN;
109 ret = RTE_FLOW_ITEM_TYPE_END;
111 case RTE_FLOW_ITEM_TYPE_VLAN:
113 ether_type_m = ((const struct rte_flow_item_vlan *)
114 (item->mask))->inner_type;
116 ether_type_m = rte_flow_item_vlan_mask.inner_type;
117 if (ether_type_m != RTE_BE16(0xFFFF))
119 ether_type = ((const struct rte_flow_item_vlan *)
120 (item->spec))->inner_type;
121 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
122 ret = RTE_FLOW_ITEM_TYPE_IPV4;
123 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
124 ret = RTE_FLOW_ITEM_TYPE_IPV6;
125 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
126 ret = RTE_FLOW_ITEM_TYPE_VLAN;
128 ret = RTE_FLOW_ITEM_TYPE_END;
130 case RTE_FLOW_ITEM_TYPE_IPV4:
132 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
133 (item->mask))->hdr.next_proto_id;
136 rte_flow_item_ipv4_mask.hdr.next_proto_id;
137 if (ip_next_proto_m != 0xFF)
139 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
140 (item->spec))->hdr.next_proto_id;
141 if (ip_next_proto == IPPROTO_UDP)
142 ret = RTE_FLOW_ITEM_TYPE_UDP;
143 else if (ip_next_proto == IPPROTO_TCP)
144 ret = RTE_FLOW_ITEM_TYPE_TCP;
145 else if (ip_next_proto == IPPROTO_IP)
146 ret = RTE_FLOW_ITEM_TYPE_IPV4;
147 else if (ip_next_proto == IPPROTO_IPV6)
148 ret = RTE_FLOW_ITEM_TYPE_IPV6;
150 ret = RTE_FLOW_ITEM_TYPE_END;
152 case RTE_FLOW_ITEM_TYPE_IPV6:
154 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
155 (item->mask))->hdr.proto;
158 rte_flow_item_ipv6_mask.hdr.proto;
159 if (ip_next_proto_m != 0xFF)
161 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
162 (item->spec))->hdr.proto;
163 if (ip_next_proto == IPPROTO_UDP)
164 ret = RTE_FLOW_ITEM_TYPE_UDP;
165 else if (ip_next_proto == IPPROTO_TCP)
166 ret = RTE_FLOW_ITEM_TYPE_TCP;
167 else if (ip_next_proto == IPPROTO_IP)
168 ret = RTE_FLOW_ITEM_TYPE_IPV4;
169 else if (ip_next_proto == IPPROTO_IPV6)
170 ret = RTE_FLOW_ITEM_TYPE_IPV6;
172 ret = RTE_FLOW_ITEM_TYPE_END;
175 ret = RTE_FLOW_ITEM_TYPE_VOID;
182 * Expand RSS flows into several possible flows according to the RSS hash
183 * fields requested and the driver capabilities.
186 * Buffer to store the result expansion.
188 * Buffer size in bytes. If 0, @p buf can be NULL.
192 * RSS types to expand (see ETH_RSS_* definitions).
194 * Input graph to expand @p pattern according to @p types.
195 * @param[in] graph_root_index
196 * Index of root node in @p graph, typically 0.
199 * A positive value representing the size of @p buf in bytes regardless of
200 * @p size on success, a negative errno value otherwise and rte_errno is
201 * set, the following errors are defined:
203 * -E2BIG: graph-depth @p graph is too deep.
206 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
207 const struct rte_flow_item *pattern, uint64_t types,
208 const struct mlx5_flow_expand_node graph[],
209 int graph_root_index)
212 const struct rte_flow_item *item;
213 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
214 const int *next_node;
215 const int *stack[elt_n];
217 struct rte_flow_item flow_items[elt_n];
220 size_t user_pattern_size = 0;
222 const struct mlx5_flow_expand_node *next = NULL;
223 struct rte_flow_item missed_item;
226 const struct rte_flow_item *last_item = NULL;
228 memset(&missed_item, 0, sizeof(missed_item));
229 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
230 elt_n * sizeof(buf->entry[0]);
232 buf->entry[0].priority = 0;
233 buf->entry[0].pattern = (void *)&buf->entry[elt_n];
235 addr = buf->entry[0].pattern;
237 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
238 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
240 for (i = 0; node->next && node->next[i]; ++i) {
241 next = &graph[node->next[i]];
242 if (next->type == item->type)
247 user_pattern_size += sizeof(*item);
249 user_pattern_size += sizeof(*item); /* Handle END item. */
250 lsize += user_pattern_size;
251 /* Copy the user pattern in the first entry of the buffer. */
253 rte_memcpy(addr, pattern, user_pattern_size);
254 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
257 /* Start expanding. */
258 memset(flow_items, 0, sizeof(flow_items));
259 user_pattern_size -= sizeof(*item);
261 * Check if the last valid item has spec set, need complete pattern,
262 * and the pattern can be used for expansion.
264 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
265 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
266 /* Item type END indicates expansion is not required. */
269 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
272 for (i = 0; node->next && node->next[i]; ++i) {
273 next = &graph[node->next[i]];
274 if (next->type == missed_item.type) {
275 flow_items[0].type = missed_item.type;
276 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
282 if (next && missed) {
283 elt = 2; /* missed item + item end. */
285 lsize += elt * sizeof(*item) + user_pattern_size;
286 if ((node->rss_types & types) && lsize <= size) {
287 buf->entry[buf->entries].priority = 1;
288 buf->entry[buf->entries].pattern = addr;
290 rte_memcpy(addr, buf->entry[0].pattern,
292 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
293 rte_memcpy(addr, flow_items, elt * sizeof(*item));
294 addr = (void *)(((uintptr_t)addr) +
295 elt * sizeof(*item));
298 memset(flow_items, 0, sizeof(flow_items));
299 next_node = node->next;
300 stack[stack_pos] = next_node;
301 node = next_node ? &graph[*next_node] : NULL;
303 flow_items[stack_pos].type = node->type;
304 if (node->rss_types & types) {
306 * compute the number of items to copy from the
307 * expansion and copy it.
308 * When the stack_pos is 0, there are 1 element in it,
309 * plus the addition END item.
312 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
313 lsize += elt * sizeof(*item) + user_pattern_size;
315 size_t n = elt * sizeof(*item);
317 buf->entry[buf->entries].priority =
318 stack_pos + 1 + missed;
319 buf->entry[buf->entries].pattern = addr;
321 rte_memcpy(addr, buf->entry[0].pattern,
323 addr = (void *)(((uintptr_t)addr) +
325 rte_memcpy(addr, &missed_item,
326 missed * sizeof(*item));
327 addr = (void *)(((uintptr_t)addr) +
328 missed * sizeof(*item));
329 rte_memcpy(addr, flow_items, n);
330 addr = (void *)(((uintptr_t)addr) + n);
335 next_node = node->next;
336 if (stack_pos++ == elt_n) {
340 stack[stack_pos] = next_node;
341 } else if (*(next_node + 1)) {
342 /* Follow up with the next possibility. */
345 /* Move to the next path. */
347 next_node = stack[--stack_pos];
349 stack[stack_pos] = next_node;
351 node = *next_node ? &graph[*next_node] : NULL;
353 /* no expanded flows but we have missed item, create one rule for it */
354 if (buf->entries == 1 && missed != 0) {
356 lsize += elt * sizeof(*item) + user_pattern_size;
358 buf->entry[buf->entries].priority = 1;
359 buf->entry[buf->entries].pattern = addr;
361 flow_items[0].type = missed_item.type;
362 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
363 rte_memcpy(addr, buf->entry[0].pattern,
365 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
366 rte_memcpy(addr, flow_items, elt * sizeof(*item));
367 addr = (void *)(((uintptr_t)addr) +
368 elt * sizeof(*item));
374 enum mlx5_expansion {
376 MLX5_EXPANSION_ROOT_OUTER,
377 MLX5_EXPANSION_ROOT_ETH_VLAN,
378 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
379 MLX5_EXPANSION_OUTER_ETH,
380 MLX5_EXPANSION_OUTER_ETH_VLAN,
381 MLX5_EXPANSION_OUTER_VLAN,
382 MLX5_EXPANSION_OUTER_IPV4,
383 MLX5_EXPANSION_OUTER_IPV4_UDP,
384 MLX5_EXPANSION_OUTER_IPV4_TCP,
385 MLX5_EXPANSION_OUTER_IPV6,
386 MLX5_EXPANSION_OUTER_IPV6_UDP,
387 MLX5_EXPANSION_OUTER_IPV6_TCP,
388 MLX5_EXPANSION_VXLAN,
389 MLX5_EXPANSION_VXLAN_GPE,
393 MLX5_EXPANSION_ETH_VLAN,
396 MLX5_EXPANSION_IPV4_UDP,
397 MLX5_EXPANSION_IPV4_TCP,
399 MLX5_EXPANSION_IPV6_UDP,
400 MLX5_EXPANSION_IPV6_TCP,
403 /** Supported expansion of items. */
404 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
405 [MLX5_EXPANSION_ROOT] = {
406 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
408 MLX5_EXPANSION_IPV6),
409 .type = RTE_FLOW_ITEM_TYPE_END,
411 [MLX5_EXPANSION_ROOT_OUTER] = {
412 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
413 MLX5_EXPANSION_OUTER_IPV4,
414 MLX5_EXPANSION_OUTER_IPV6),
415 .type = RTE_FLOW_ITEM_TYPE_END,
417 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
418 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
419 .type = RTE_FLOW_ITEM_TYPE_END,
421 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
422 .next = MLX5_FLOW_EXPAND_RSS_NEXT
423 (MLX5_EXPANSION_OUTER_ETH_VLAN),
424 .type = RTE_FLOW_ITEM_TYPE_END,
426 [MLX5_EXPANSION_OUTER_ETH] = {
427 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
428 MLX5_EXPANSION_OUTER_IPV6,
429 MLX5_EXPANSION_MPLS),
430 .type = RTE_FLOW_ITEM_TYPE_ETH,
433 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
434 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
435 .type = RTE_FLOW_ITEM_TYPE_ETH,
438 [MLX5_EXPANSION_OUTER_VLAN] = {
439 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
440 MLX5_EXPANSION_OUTER_IPV6),
441 .type = RTE_FLOW_ITEM_TYPE_VLAN,
443 [MLX5_EXPANSION_OUTER_IPV4] = {
444 .next = MLX5_FLOW_EXPAND_RSS_NEXT
445 (MLX5_EXPANSION_OUTER_IPV4_UDP,
446 MLX5_EXPANSION_OUTER_IPV4_TCP,
449 MLX5_EXPANSION_IPV6),
450 .type = RTE_FLOW_ITEM_TYPE_IPV4,
451 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
452 ETH_RSS_NONFRAG_IPV4_OTHER,
454 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
455 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
456 MLX5_EXPANSION_VXLAN_GPE),
457 .type = RTE_FLOW_ITEM_TYPE_UDP,
458 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
460 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
461 .type = RTE_FLOW_ITEM_TYPE_TCP,
462 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
464 [MLX5_EXPANSION_OUTER_IPV6] = {
465 .next = MLX5_FLOW_EXPAND_RSS_NEXT
466 (MLX5_EXPANSION_OUTER_IPV6_UDP,
467 MLX5_EXPANSION_OUTER_IPV6_TCP,
469 MLX5_EXPANSION_IPV6),
470 .type = RTE_FLOW_ITEM_TYPE_IPV6,
471 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
472 ETH_RSS_NONFRAG_IPV6_OTHER,
474 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
475 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
476 MLX5_EXPANSION_VXLAN_GPE),
477 .type = RTE_FLOW_ITEM_TYPE_UDP,
478 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
480 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
481 .type = RTE_FLOW_ITEM_TYPE_TCP,
482 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
484 [MLX5_EXPANSION_VXLAN] = {
485 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
487 MLX5_EXPANSION_IPV6),
488 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
490 [MLX5_EXPANSION_VXLAN_GPE] = {
491 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
493 MLX5_EXPANSION_IPV6),
494 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
496 [MLX5_EXPANSION_GRE] = {
497 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
498 .type = RTE_FLOW_ITEM_TYPE_GRE,
500 [MLX5_EXPANSION_MPLS] = {
501 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
502 MLX5_EXPANSION_IPV6),
503 .type = RTE_FLOW_ITEM_TYPE_MPLS,
505 [MLX5_EXPANSION_ETH] = {
506 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
507 MLX5_EXPANSION_IPV6),
508 .type = RTE_FLOW_ITEM_TYPE_ETH,
510 [MLX5_EXPANSION_ETH_VLAN] = {
511 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
512 .type = RTE_FLOW_ITEM_TYPE_ETH,
514 [MLX5_EXPANSION_VLAN] = {
515 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
516 MLX5_EXPANSION_IPV6),
517 .type = RTE_FLOW_ITEM_TYPE_VLAN,
519 [MLX5_EXPANSION_IPV4] = {
520 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
521 MLX5_EXPANSION_IPV4_TCP),
522 .type = RTE_FLOW_ITEM_TYPE_IPV4,
523 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
524 ETH_RSS_NONFRAG_IPV4_OTHER,
526 [MLX5_EXPANSION_IPV4_UDP] = {
527 .type = RTE_FLOW_ITEM_TYPE_UDP,
528 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
530 [MLX5_EXPANSION_IPV4_TCP] = {
531 .type = RTE_FLOW_ITEM_TYPE_TCP,
532 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
534 [MLX5_EXPANSION_IPV6] = {
535 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
536 MLX5_EXPANSION_IPV6_TCP),
537 .type = RTE_FLOW_ITEM_TYPE_IPV6,
538 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
539 ETH_RSS_NONFRAG_IPV6_OTHER,
541 [MLX5_EXPANSION_IPV6_UDP] = {
542 .type = RTE_FLOW_ITEM_TYPE_UDP,
543 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
545 [MLX5_EXPANSION_IPV6_TCP] = {
546 .type = RTE_FLOW_ITEM_TYPE_TCP,
547 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
551 static const struct rte_flow_ops mlx5_flow_ops = {
552 .validate = mlx5_flow_validate,
553 .create = mlx5_flow_create,
554 .destroy = mlx5_flow_destroy,
555 .flush = mlx5_flow_flush,
556 .isolate = mlx5_flow_isolate,
557 .query = mlx5_flow_query,
558 .dev_dump = mlx5_flow_dev_dump,
559 .get_aged_flows = mlx5_flow_get_aged_flows,
562 /* Convert FDIR request to Generic flow. */
564 struct rte_flow_attr attr;
565 struct rte_flow_item items[4];
566 struct rte_flow_item_eth l2;
567 struct rte_flow_item_eth l2_mask;
569 struct rte_flow_item_ipv4 ipv4;
570 struct rte_flow_item_ipv6 ipv6;
573 struct rte_flow_item_ipv4 ipv4;
574 struct rte_flow_item_ipv6 ipv6;
577 struct rte_flow_item_udp udp;
578 struct rte_flow_item_tcp tcp;
581 struct rte_flow_item_udp udp;
582 struct rte_flow_item_tcp tcp;
584 struct rte_flow_action actions[2];
585 struct rte_flow_action_queue queue;
588 /* Tunnel information. */
589 struct mlx5_flow_tunnel_info {
590 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
591 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
594 static struct mlx5_flow_tunnel_info tunnels_info[] = {
596 .tunnel = MLX5_FLOW_LAYER_VXLAN,
597 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
600 .tunnel = MLX5_FLOW_LAYER_GENEVE,
601 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
604 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
605 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
608 .tunnel = MLX5_FLOW_LAYER_GRE,
609 .ptype = RTE_PTYPE_TUNNEL_GRE,
612 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
613 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
616 .tunnel = MLX5_FLOW_LAYER_MPLS,
617 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
620 .tunnel = MLX5_FLOW_LAYER_NVGRE,
621 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
624 .tunnel = MLX5_FLOW_LAYER_IPIP,
625 .ptype = RTE_PTYPE_TUNNEL_IP,
628 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
629 .ptype = RTE_PTYPE_TUNNEL_IP,
632 .tunnel = MLX5_FLOW_LAYER_GTP,
633 .ptype = RTE_PTYPE_TUNNEL_GTPU,
638 * Translate tag ID to register.
641 * Pointer to the Ethernet device structure.
643 * The feature that request the register.
645 * The request register ID.
647 * Error description in case of any.
650 * The request register on success, a negative errno
651 * value otherwise and rte_errno is set.
654 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
655 enum mlx5_feature_name feature,
657 struct rte_flow_error *error)
659 struct mlx5_priv *priv = dev->data->dev_private;
660 struct mlx5_dev_config *config = &priv->config;
661 enum modify_reg start_reg;
662 bool skip_mtr_reg = false;
665 case MLX5_HAIRPIN_RX:
667 case MLX5_HAIRPIN_TX:
669 case MLX5_METADATA_RX:
670 switch (config->dv_xmeta_en) {
671 case MLX5_XMETA_MODE_LEGACY:
673 case MLX5_XMETA_MODE_META16:
675 case MLX5_XMETA_MODE_META32:
679 case MLX5_METADATA_TX:
681 case MLX5_METADATA_FDB:
682 switch (config->dv_xmeta_en) {
683 case MLX5_XMETA_MODE_LEGACY:
685 case MLX5_XMETA_MODE_META16:
687 case MLX5_XMETA_MODE_META32:
692 switch (config->dv_xmeta_en) {
693 case MLX5_XMETA_MODE_LEGACY:
695 case MLX5_XMETA_MODE_META16:
697 case MLX5_XMETA_MODE_META32:
703 * If meter color and flow match share one register, flow match
704 * should use the meter color register for match.
706 if (priv->mtr_reg_share)
707 return priv->mtr_color_reg;
709 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
712 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
713 return priv->mtr_color_reg;
716 * Metadata COPY_MARK register using is in meter suffix sub
717 * flow while with meter. It's safe to share the same register.
719 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
722 * If meter is enable, it will engage the register for color
723 * match and flow match. If meter color match is not using the
724 * REG_C_2, need to skip the REG_C_x be used by meter color
726 * If meter is disable, free to use all available registers.
728 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
729 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
730 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
731 if (id > (REG_C_7 - start_reg))
732 return rte_flow_error_set(error, EINVAL,
733 RTE_FLOW_ERROR_TYPE_ITEM,
734 NULL, "invalid tag id");
735 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
736 return rte_flow_error_set(error, ENOTSUP,
737 RTE_FLOW_ERROR_TYPE_ITEM,
738 NULL, "unsupported tag id");
740 * This case means meter is using the REG_C_x great than 2.
741 * Take care not to conflict with meter color REG_C_x.
742 * If the available index REG_C_y >= REG_C_x, skip the
745 if (skip_mtr_reg && config->flow_mreg_c
746 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
747 if (id >= (REG_C_7 - start_reg))
748 return rte_flow_error_set(error, EINVAL,
749 RTE_FLOW_ERROR_TYPE_ITEM,
750 NULL, "invalid tag id");
751 if (config->flow_mreg_c
752 [id + 1 + start_reg - REG_C_0] != REG_NON)
753 return config->flow_mreg_c
754 [id + 1 + start_reg - REG_C_0];
755 return rte_flow_error_set(error, ENOTSUP,
756 RTE_FLOW_ERROR_TYPE_ITEM,
757 NULL, "unsupported tag id");
759 return config->flow_mreg_c[id + start_reg - REG_C_0];
762 return rte_flow_error_set(error, EINVAL,
763 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
764 NULL, "invalid feature name");
768 * Check extensive flow metadata register support.
771 * Pointer to rte_eth_dev structure.
774 * True if device supports extensive flow metadata register, otherwise false.
777 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
779 struct mlx5_priv *priv = dev->data->dev_private;
780 struct mlx5_dev_config *config = &priv->config;
783 * Having available reg_c can be regarded inclusively as supporting
784 * extensive flow metadata register, which could mean,
785 * - metadata register copy action by modify header.
786 * - 16 modify header actions is supported.
787 * - reg_c's are preserved across different domain (FDB and NIC) on
788 * packet loopback by flow lookup miss.
790 return config->flow_mreg_c[2] != REG_NON;
794 * Verify the @p item specifications (spec, last, mask) are compatible with the
798 * Item specification.
800 * @p item->mask or flow default bit-masks.
801 * @param[in] nic_mask
802 * Bit-masks covering supported fields by the NIC to compare with user mask.
804 * Bit-masks size in bytes.
805 * @param[in] range_accepted
806 * True if range of values is accepted for specific fields, false otherwise.
808 * Pointer to error structure.
811 * 0 on success, a negative errno value otherwise and rte_errno is set.
814 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
816 const uint8_t *nic_mask,
819 struct rte_flow_error *error)
823 MLX5_ASSERT(nic_mask);
824 for (i = 0; i < size; ++i)
825 if ((nic_mask[i] | mask[i]) != nic_mask[i])
826 return rte_flow_error_set(error, ENOTSUP,
827 RTE_FLOW_ERROR_TYPE_ITEM,
829 "mask enables non supported"
831 if (!item->spec && (item->mask || item->last))
832 return rte_flow_error_set(error, EINVAL,
833 RTE_FLOW_ERROR_TYPE_ITEM, item,
834 "mask/last without a spec is not"
836 if (item->spec && item->last && !range_accepted) {
842 for (i = 0; i < size; ++i) {
843 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
844 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
846 ret = memcmp(spec, last, size);
848 return rte_flow_error_set(error, EINVAL,
849 RTE_FLOW_ERROR_TYPE_ITEM,
851 "range is not valid");
857 * Adjust the hash fields according to the @p flow information.
859 * @param[in] dev_flow.
860 * Pointer to the mlx5_flow.
862 * 1 when the hash field is for a tunnel item.
863 * @param[in] layer_types
865 * @param[in] hash_fields
869 * The hash fields that should be used.
872 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
873 int tunnel __rte_unused, uint64_t layer_types,
874 uint64_t hash_fields)
876 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
877 int rss_request_inner = rss_desc->level >= 2;
879 /* Check RSS hash level for tunnel. */
880 if (tunnel && rss_request_inner)
881 hash_fields |= IBV_RX_HASH_INNER;
882 else if (tunnel || rss_request_inner)
885 /* Check if requested layer matches RSS hash fields. */
886 if (!(rss_desc->types & layer_types))
892 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
893 * if several tunnel rules are used on this queue, the tunnel ptype will be
897 * Rx queue to update.
900 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
903 uint32_t tunnel_ptype = 0;
905 /* Look up for the ptype to use. */
906 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
907 if (!rxq_ctrl->flow_tunnels_n[i])
910 tunnel_ptype = tunnels_info[i].ptype;
916 rxq_ctrl->rxq.tunnel = tunnel_ptype;
920 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
924 * Pointer to the Ethernet device structure.
925 * @param[in] dev_handle
926 * Pointer to device flow handle structure.
929 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
930 struct mlx5_flow_handle *dev_handle)
932 struct mlx5_priv *priv = dev->data->dev_private;
933 const int mark = dev_handle->mark;
934 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
935 struct mlx5_hrxq *hrxq;
938 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
940 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
941 dev_handle->rix_hrxq);
944 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
945 int idx = hrxq->ind_table->queues[i];
946 struct mlx5_rxq_ctrl *rxq_ctrl =
947 container_of((*priv->rxqs)[idx],
948 struct mlx5_rxq_ctrl, rxq);
951 * To support metadata register copy on Tx loopback,
952 * this must be always enabled (metadata may arive
953 * from other port - not from local flows only.
955 if (priv->config.dv_flow_en &&
956 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
957 mlx5_flow_ext_mreg_supported(dev)) {
958 rxq_ctrl->rxq.mark = 1;
959 rxq_ctrl->flow_mark_n = 1;
961 rxq_ctrl->rxq.mark = 1;
962 rxq_ctrl->flow_mark_n++;
967 /* Increase the counter matching the flow. */
968 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
969 if ((tunnels_info[j].tunnel &
970 dev_handle->layers) ==
971 tunnels_info[j].tunnel) {
972 rxq_ctrl->flow_tunnels_n[j]++;
976 flow_rxq_tunnel_ptype_update(rxq_ctrl);
982 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
985 * Pointer to the Ethernet device structure.
987 * Pointer to flow structure.
990 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
992 struct mlx5_priv *priv = dev->data->dev_private;
994 struct mlx5_flow_handle *dev_handle;
996 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
997 handle_idx, dev_handle, next)
998 flow_drv_rxq_flags_set(dev, dev_handle);
1002 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1003 * device flow if no other flow uses it with the same kind of request.
1006 * Pointer to Ethernet device.
1007 * @param[in] dev_handle
1008 * Pointer to the device flow handle structure.
1011 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1012 struct mlx5_flow_handle *dev_handle)
1014 struct mlx5_priv *priv = dev->data->dev_private;
1015 const int mark = dev_handle->mark;
1016 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1017 struct mlx5_hrxq *hrxq;
1020 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
1022 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1023 dev_handle->rix_hrxq);
1026 MLX5_ASSERT(dev->data->dev_started);
1027 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
1028 int idx = hrxq->ind_table->queues[i];
1029 struct mlx5_rxq_ctrl *rxq_ctrl =
1030 container_of((*priv->rxqs)[idx],
1031 struct mlx5_rxq_ctrl, rxq);
1033 if (priv->config.dv_flow_en &&
1034 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1035 mlx5_flow_ext_mreg_supported(dev)) {
1036 rxq_ctrl->rxq.mark = 1;
1037 rxq_ctrl->flow_mark_n = 1;
1039 rxq_ctrl->flow_mark_n--;
1040 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1045 /* Decrease the counter matching the flow. */
1046 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1047 if ((tunnels_info[j].tunnel &
1048 dev_handle->layers) ==
1049 tunnels_info[j].tunnel) {
1050 rxq_ctrl->flow_tunnels_n[j]--;
1054 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1060 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1061 * @p flow if no other flow uses it with the same kind of request.
1064 * Pointer to Ethernet device.
1066 * Pointer to the flow.
1069 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1071 struct mlx5_priv *priv = dev->data->dev_private;
1072 uint32_t handle_idx;
1073 struct mlx5_flow_handle *dev_handle;
1075 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1076 handle_idx, dev_handle, next)
1077 flow_drv_rxq_flags_trim(dev, dev_handle);
1081 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1084 * Pointer to Ethernet device.
1087 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1089 struct mlx5_priv *priv = dev->data->dev_private;
1092 for (i = 0; i != priv->rxqs_n; ++i) {
1093 struct mlx5_rxq_ctrl *rxq_ctrl;
1096 if (!(*priv->rxqs)[i])
1098 rxq_ctrl = container_of((*priv->rxqs)[i],
1099 struct mlx5_rxq_ctrl, rxq);
1100 rxq_ctrl->flow_mark_n = 0;
1101 rxq_ctrl->rxq.mark = 0;
1102 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1103 rxq_ctrl->flow_tunnels_n[j] = 0;
1104 rxq_ctrl->rxq.tunnel = 0;
1109 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1112 * Pointer to the Ethernet device structure.
1115 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1117 struct mlx5_priv *priv = dev->data->dev_private;
1118 struct mlx5_rxq_data *data;
1121 for (i = 0; i != priv->rxqs_n; ++i) {
1122 if (!(*priv->rxqs)[i])
1124 data = (*priv->rxqs)[i];
1125 if (!rte_flow_dynf_metadata_avail()) {
1126 data->dynf_meta = 0;
1127 data->flow_meta_mask = 0;
1128 data->flow_meta_offset = -1;
1130 data->dynf_meta = 1;
1131 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1132 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1138 * return a pointer to the desired action in the list of actions.
1140 * @param[in] actions
1141 * The list of actions to search the action in.
1143 * The action to find.
1146 * Pointer to the action in the list, if found. NULL otherwise.
1148 const struct rte_flow_action *
1149 mlx5_flow_find_action(const struct rte_flow_action *actions,
1150 enum rte_flow_action_type action)
1152 if (actions == NULL)
1154 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1155 if (actions->type == action)
1161 * Validate the flag action.
1163 * @param[in] action_flags
1164 * Bit-fields that holds the actions detected until now.
1166 * Attributes of flow that includes this action.
1168 * Pointer to error structure.
1171 * 0 on success, a negative errno value otherwise and rte_errno is set.
1174 mlx5_flow_validate_action_flag(uint64_t action_flags,
1175 const struct rte_flow_attr *attr,
1176 struct rte_flow_error *error)
1178 if (action_flags & MLX5_FLOW_ACTION_MARK)
1179 return rte_flow_error_set(error, EINVAL,
1180 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1181 "can't mark and flag in same flow");
1182 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1183 return rte_flow_error_set(error, EINVAL,
1184 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1186 " actions in same flow");
1188 return rte_flow_error_set(error, ENOTSUP,
1189 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1190 "flag action not supported for "
1196 * Validate the mark action.
1199 * Pointer to the queue action.
1200 * @param[in] action_flags
1201 * Bit-fields that holds the actions detected until now.
1203 * Attributes of flow that includes this action.
1205 * Pointer to error structure.
1208 * 0 on success, a negative errno value otherwise and rte_errno is set.
1211 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1212 uint64_t action_flags,
1213 const struct rte_flow_attr *attr,
1214 struct rte_flow_error *error)
1216 const struct rte_flow_action_mark *mark = action->conf;
1219 return rte_flow_error_set(error, EINVAL,
1220 RTE_FLOW_ERROR_TYPE_ACTION,
1222 "configuration cannot be null");
1223 if (mark->id >= MLX5_FLOW_MARK_MAX)
1224 return rte_flow_error_set(error, EINVAL,
1225 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1227 "mark id must in 0 <= id < "
1228 RTE_STR(MLX5_FLOW_MARK_MAX));
1229 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1230 return rte_flow_error_set(error, EINVAL,
1231 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1232 "can't flag and mark in same flow");
1233 if (action_flags & MLX5_FLOW_ACTION_MARK)
1234 return rte_flow_error_set(error, EINVAL,
1235 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1236 "can't have 2 mark actions in same"
1239 return rte_flow_error_set(error, ENOTSUP,
1240 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1241 "mark action not supported for "
1247 * Validate the drop action.
1249 * @param[in] action_flags
1250 * Bit-fields that holds the actions detected until now.
1252 * Attributes of flow that includes this action.
1254 * Pointer to error structure.
1257 * 0 on success, a negative errno value otherwise and rte_errno is set.
1260 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1261 const struct rte_flow_attr *attr,
1262 struct rte_flow_error *error)
1265 return rte_flow_error_set(error, ENOTSUP,
1266 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1267 "drop action not supported for "
1273 * Validate the queue action.
1276 * Pointer to the queue action.
1277 * @param[in] action_flags
1278 * Bit-fields that holds the actions detected until now.
1280 * Pointer to the Ethernet device structure.
1282 * Attributes of flow that includes this action.
1284 * Pointer to error structure.
1287 * 0 on success, a negative errno value otherwise and rte_errno is set.
1290 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1291 uint64_t action_flags,
1292 struct rte_eth_dev *dev,
1293 const struct rte_flow_attr *attr,
1294 struct rte_flow_error *error)
1296 struct mlx5_priv *priv = dev->data->dev_private;
1297 const struct rte_flow_action_queue *queue = action->conf;
1299 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1300 return rte_flow_error_set(error, EINVAL,
1301 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1302 "can't have 2 fate actions in"
1305 return rte_flow_error_set(error, EINVAL,
1306 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1307 NULL, "No Rx queues configured");
1308 if (queue->index >= priv->rxqs_n)
1309 return rte_flow_error_set(error, EINVAL,
1310 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1312 "queue index out of range");
1313 if (!(*priv->rxqs)[queue->index])
1314 return rte_flow_error_set(error, EINVAL,
1315 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1317 "queue is not configured");
1319 return rte_flow_error_set(error, ENOTSUP,
1320 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1321 "queue action not supported for "
1327 * Validate the rss action.
1330 * Pointer to the queue action.
1331 * @param[in] action_flags
1332 * Bit-fields that holds the actions detected until now.
1334 * Pointer to the Ethernet device structure.
1336 * Attributes of flow that includes this action.
1337 * @param[in] item_flags
1338 * Items that were detected.
1340 * Pointer to error structure.
1343 * 0 on success, a negative errno value otherwise and rte_errno is set.
1346 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1347 uint64_t action_flags,
1348 struct rte_eth_dev *dev,
1349 const struct rte_flow_attr *attr,
1350 uint64_t item_flags,
1351 struct rte_flow_error *error)
1353 struct mlx5_priv *priv = dev->data->dev_private;
1354 const struct rte_flow_action_rss *rss = action->conf;
1355 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1358 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1359 return rte_flow_error_set(error, EINVAL,
1360 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1361 "can't have 2 fate actions"
1363 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1364 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1365 return rte_flow_error_set(error, ENOTSUP,
1366 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1368 "RSS hash function not supported");
1369 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1374 return rte_flow_error_set(error, ENOTSUP,
1375 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1377 "tunnel RSS is not supported");
1378 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1379 if (rss->key_len == 0 && rss->key != NULL)
1380 return rte_flow_error_set(error, ENOTSUP,
1381 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1383 "RSS hash key length 0");
1384 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1385 return rte_flow_error_set(error, ENOTSUP,
1386 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1388 "RSS hash key too small");
1389 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1390 return rte_flow_error_set(error, ENOTSUP,
1391 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1393 "RSS hash key too large");
1394 if (rss->queue_num > priv->config.ind_table_max_size)
1395 return rte_flow_error_set(error, ENOTSUP,
1396 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1398 "number of queues too large");
1399 if (rss->types & MLX5_RSS_HF_MASK)
1400 return rte_flow_error_set(error, ENOTSUP,
1401 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1403 "some RSS protocols are not"
1405 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1406 !(rss->types & ETH_RSS_IP))
1407 return rte_flow_error_set(error, EINVAL,
1408 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1409 "L3 partial RSS requested but L3 RSS"
1410 " type not specified");
1411 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1412 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1413 return rte_flow_error_set(error, EINVAL,
1414 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1415 "L4 partial RSS requested but L4 RSS"
1416 " type not specified");
1418 return rte_flow_error_set(error, EINVAL,
1419 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1420 NULL, "No Rx queues configured");
1421 if (!rss->queue_num)
1422 return rte_flow_error_set(error, EINVAL,
1423 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1424 NULL, "No queues configured");
1425 for (i = 0; i != rss->queue_num; ++i) {
1426 if (rss->queue[i] >= priv->rxqs_n)
1427 return rte_flow_error_set
1429 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1430 &rss->queue[i], "queue index out of range");
1431 if (!(*priv->rxqs)[rss->queue[i]])
1432 return rte_flow_error_set
1433 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1434 &rss->queue[i], "queue is not configured");
1437 return rte_flow_error_set(error, ENOTSUP,
1438 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1439 "rss action not supported for "
1441 if (rss->level > 1 && !tunnel)
1442 return rte_flow_error_set(error, EINVAL,
1443 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1444 "inner RSS is not supported for "
1445 "non-tunnel flows");
1446 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1447 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1448 return rte_flow_error_set(error, EINVAL,
1449 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1450 "RSS on eCPRI is not supported now");
1456 * Validate the default miss action.
1458 * @param[in] action_flags
1459 * Bit-fields that holds the actions detected until now.
1461 * Pointer to error structure.
1464 * 0 on success, a negative errno value otherwise and rte_errno is set.
1467 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1468 const struct rte_flow_attr *attr,
1469 struct rte_flow_error *error)
1471 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1472 return rte_flow_error_set(error, EINVAL,
1473 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1474 "can't have 2 fate actions in"
1477 return rte_flow_error_set(error, ENOTSUP,
1478 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1479 "default miss action not supported "
1482 return rte_flow_error_set(error, ENOTSUP,
1483 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1484 "only group 0 is supported");
1486 return rte_flow_error_set(error, ENOTSUP,
1487 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1488 NULL, "transfer is not supported");
1493 * Validate the count action.
1496 * Pointer to the Ethernet device structure.
1498 * Attributes of flow that includes this action.
1500 * Pointer to error structure.
1503 * 0 on success, a negative errno value otherwise and rte_errno is set.
1506 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1507 const struct rte_flow_attr *attr,
1508 struct rte_flow_error *error)
1511 return rte_flow_error_set(error, ENOTSUP,
1512 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1513 "count action not supported for "
1519 * Verify the @p attributes will be correctly understood by the NIC and store
1520 * them in the @p flow if everything is correct.
1523 * Pointer to the Ethernet device structure.
1524 * @param[in] attributes
1525 * Pointer to flow attributes
1527 * Pointer to error structure.
1530 * 0 on success, a negative errno value otherwise and rte_errno is set.
1533 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1534 const struct rte_flow_attr *attributes,
1535 struct rte_flow_error *error)
1537 struct mlx5_priv *priv = dev->data->dev_private;
1538 uint32_t priority_max = priv->config.flow_prio - 1;
1540 if (attributes->group)
1541 return rte_flow_error_set(error, ENOTSUP,
1542 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1543 NULL, "groups is not supported");
1544 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1545 attributes->priority >= priority_max)
1546 return rte_flow_error_set(error, ENOTSUP,
1547 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1548 NULL, "priority out of range");
1549 if (attributes->egress)
1550 return rte_flow_error_set(error, ENOTSUP,
1551 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1552 "egress is not supported");
1553 if (attributes->transfer && !priv->config.dv_esw_en)
1554 return rte_flow_error_set(error, ENOTSUP,
1555 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1556 NULL, "transfer is not supported");
1557 if (!attributes->ingress)
1558 return rte_flow_error_set(error, EINVAL,
1559 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1561 "ingress attribute is mandatory");
1566 * Validate ICMP6 item.
1569 * Item specification.
1570 * @param[in] item_flags
1571 * Bit-fields that holds the items detected until now.
1573 * Pointer to error structure.
1576 * 0 on success, a negative errno value otherwise and rte_errno is set.
1579 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1580 uint64_t item_flags,
1581 uint8_t target_protocol,
1582 struct rte_flow_error *error)
1584 const struct rte_flow_item_icmp6 *mask = item->mask;
1585 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1586 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1587 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1588 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1589 MLX5_FLOW_LAYER_OUTER_L4;
1592 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1593 return rte_flow_error_set(error, EINVAL,
1594 RTE_FLOW_ERROR_TYPE_ITEM, item,
1595 "protocol filtering not compatible"
1596 " with ICMP6 layer");
1597 if (!(item_flags & l3m))
1598 return rte_flow_error_set(error, EINVAL,
1599 RTE_FLOW_ERROR_TYPE_ITEM, item,
1600 "IPv6 is mandatory to filter on"
1602 if (item_flags & l4m)
1603 return rte_flow_error_set(error, EINVAL,
1604 RTE_FLOW_ERROR_TYPE_ITEM, item,
1605 "multiple L4 layers not supported");
1607 mask = &rte_flow_item_icmp6_mask;
1608 ret = mlx5_flow_item_acceptable
1609 (item, (const uint8_t *)mask,
1610 (const uint8_t *)&rte_flow_item_icmp6_mask,
1611 sizeof(struct rte_flow_item_icmp6),
1612 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1619 * Validate ICMP item.
1622 * Item specification.
1623 * @param[in] item_flags
1624 * Bit-fields that holds the items detected until now.
1626 * Pointer to error structure.
1629 * 0 on success, a negative errno value otherwise and rte_errno is set.
1632 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1633 uint64_t item_flags,
1634 uint8_t target_protocol,
1635 struct rte_flow_error *error)
1637 const struct rte_flow_item_icmp *mask = item->mask;
1638 const struct rte_flow_item_icmp nic_mask = {
1639 .hdr.icmp_type = 0xff,
1640 .hdr.icmp_code = 0xff,
1641 .hdr.icmp_ident = RTE_BE16(0xffff),
1642 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1644 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1645 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1646 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1647 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1648 MLX5_FLOW_LAYER_OUTER_L4;
1651 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1652 return rte_flow_error_set(error, EINVAL,
1653 RTE_FLOW_ERROR_TYPE_ITEM, item,
1654 "protocol filtering not compatible"
1655 " with ICMP layer");
1656 if (!(item_flags & l3m))
1657 return rte_flow_error_set(error, EINVAL,
1658 RTE_FLOW_ERROR_TYPE_ITEM, item,
1659 "IPv4 is mandatory to filter"
1661 if (item_flags & l4m)
1662 return rte_flow_error_set(error, EINVAL,
1663 RTE_FLOW_ERROR_TYPE_ITEM, item,
1664 "multiple L4 layers not supported");
1667 ret = mlx5_flow_item_acceptable
1668 (item, (const uint8_t *)mask,
1669 (const uint8_t *)&nic_mask,
1670 sizeof(struct rte_flow_item_icmp),
1671 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1678 * Validate Ethernet item.
1681 * Item specification.
1682 * @param[in] item_flags
1683 * Bit-fields that holds the items detected until now.
1685 * Pointer to error structure.
1688 * 0 on success, a negative errno value otherwise and rte_errno is set.
1691 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1692 uint64_t item_flags,
1693 struct rte_flow_error *error)
1695 const struct rte_flow_item_eth *mask = item->mask;
1696 const struct rte_flow_item_eth nic_mask = {
1697 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1698 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1699 .type = RTE_BE16(0xffff),
1702 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1703 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1704 MLX5_FLOW_LAYER_OUTER_L2;
1706 if (item_flags & ethm)
1707 return rte_flow_error_set(error, ENOTSUP,
1708 RTE_FLOW_ERROR_TYPE_ITEM, item,
1709 "multiple L2 layers not supported");
1710 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1711 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1712 return rte_flow_error_set(error, EINVAL,
1713 RTE_FLOW_ERROR_TYPE_ITEM, item,
1714 "L2 layer should not follow "
1716 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1717 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1718 return rte_flow_error_set(error, EINVAL,
1719 RTE_FLOW_ERROR_TYPE_ITEM, item,
1720 "L2 layer should not follow VLAN");
1722 mask = &rte_flow_item_eth_mask;
1723 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1724 (const uint8_t *)&nic_mask,
1725 sizeof(struct rte_flow_item_eth),
1726 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1731 * Validate VLAN item.
1734 * Item specification.
1735 * @param[in] item_flags
1736 * Bit-fields that holds the items detected until now.
1738 * Ethernet device flow is being created on.
1740 * Pointer to error structure.
1743 * 0 on success, a negative errno value otherwise and rte_errno is set.
1746 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1747 uint64_t item_flags,
1748 struct rte_eth_dev *dev,
1749 struct rte_flow_error *error)
1751 const struct rte_flow_item_vlan *spec = item->spec;
1752 const struct rte_flow_item_vlan *mask = item->mask;
1753 const struct rte_flow_item_vlan nic_mask = {
1754 .tci = RTE_BE16(UINT16_MAX),
1755 .inner_type = RTE_BE16(UINT16_MAX),
1757 uint16_t vlan_tag = 0;
1758 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1760 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1761 MLX5_FLOW_LAYER_INNER_L4) :
1762 (MLX5_FLOW_LAYER_OUTER_L3 |
1763 MLX5_FLOW_LAYER_OUTER_L4);
1764 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1765 MLX5_FLOW_LAYER_OUTER_VLAN;
1767 if (item_flags & vlanm)
1768 return rte_flow_error_set(error, EINVAL,
1769 RTE_FLOW_ERROR_TYPE_ITEM, item,
1770 "multiple VLAN layers not supported");
1771 else if ((item_flags & l34m) != 0)
1772 return rte_flow_error_set(error, EINVAL,
1773 RTE_FLOW_ERROR_TYPE_ITEM, item,
1774 "VLAN cannot follow L3/L4 layer");
1776 mask = &rte_flow_item_vlan_mask;
1777 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1778 (const uint8_t *)&nic_mask,
1779 sizeof(struct rte_flow_item_vlan),
1780 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1783 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1784 struct mlx5_priv *priv = dev->data->dev_private;
1786 if (priv->vmwa_context) {
1788 * Non-NULL context means we have a virtual machine
1789 * and SR-IOV enabled, we have to create VLAN interface
1790 * to make hypervisor to setup E-Switch vport
1791 * context correctly. We avoid creating the multiple
1792 * VLAN interfaces, so we cannot support VLAN tag mask.
1794 return rte_flow_error_set(error, EINVAL,
1795 RTE_FLOW_ERROR_TYPE_ITEM,
1797 "VLAN tag mask is not"
1798 " supported in virtual"
1803 vlan_tag = spec->tci;
1804 vlan_tag &= mask->tci;
1807 * From verbs perspective an empty VLAN is equivalent
1808 * to a packet without VLAN layer.
1811 return rte_flow_error_set(error, EINVAL,
1812 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1814 "VLAN cannot be empty");
1819 * Validate IPV4 item.
1822 * Item specification.
1823 * @param[in] item_flags
1824 * Bit-fields that holds the items detected until now.
1825 * @param[in] last_item
1826 * Previous validated item in the pattern items.
1827 * @param[in] ether_type
1828 * Type in the ethernet layer header (including dot1q).
1829 * @param[in] acc_mask
1830 * Acceptable mask, if NULL default internal default mask
1831 * will be used to check whether item fields are supported.
1832 * @param[in] range_accepted
1833 * True if range of values is accepted for specific fields, false otherwise.
1835 * Pointer to error structure.
1838 * 0 on success, a negative errno value otherwise and rte_errno is set.
1841 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1842 uint64_t item_flags,
1844 uint16_t ether_type,
1845 const struct rte_flow_item_ipv4 *acc_mask,
1846 bool range_accepted,
1847 struct rte_flow_error *error)
1849 const struct rte_flow_item_ipv4 *mask = item->mask;
1850 const struct rte_flow_item_ipv4 *spec = item->spec;
1851 const struct rte_flow_item_ipv4 nic_mask = {
1853 .src_addr = RTE_BE32(0xffffffff),
1854 .dst_addr = RTE_BE32(0xffffffff),
1855 .type_of_service = 0xff,
1856 .next_proto_id = 0xff,
1859 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1860 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1861 MLX5_FLOW_LAYER_OUTER_L3;
1862 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1863 MLX5_FLOW_LAYER_OUTER_L4;
1865 uint8_t next_proto = 0xFF;
1866 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1867 MLX5_FLOW_LAYER_OUTER_VLAN |
1868 MLX5_FLOW_LAYER_INNER_VLAN);
1870 if ((last_item & l2_vlan) && ether_type &&
1871 ether_type != RTE_ETHER_TYPE_IPV4)
1872 return rte_flow_error_set(error, EINVAL,
1873 RTE_FLOW_ERROR_TYPE_ITEM, item,
1874 "IPv4 cannot follow L2/VLAN layer "
1875 "which ether type is not IPv4");
1876 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1878 next_proto = mask->hdr.next_proto_id &
1879 spec->hdr.next_proto_id;
1880 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1881 return rte_flow_error_set(error, EINVAL,
1882 RTE_FLOW_ERROR_TYPE_ITEM,
1887 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1888 return rte_flow_error_set(error, EINVAL,
1889 RTE_FLOW_ERROR_TYPE_ITEM, item,
1890 "wrong tunnel type - IPv6 specified "
1891 "but IPv4 item provided");
1892 if (item_flags & l3m)
1893 return rte_flow_error_set(error, ENOTSUP,
1894 RTE_FLOW_ERROR_TYPE_ITEM, item,
1895 "multiple L3 layers not supported");
1896 else if (item_flags & l4m)
1897 return rte_flow_error_set(error, EINVAL,
1898 RTE_FLOW_ERROR_TYPE_ITEM, item,
1899 "L3 cannot follow an L4 layer.");
1900 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1901 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1902 return rte_flow_error_set(error, EINVAL,
1903 RTE_FLOW_ERROR_TYPE_ITEM, item,
1904 "L3 cannot follow an NVGRE layer.");
1906 mask = &rte_flow_item_ipv4_mask;
1907 else if (mask->hdr.next_proto_id != 0 &&
1908 mask->hdr.next_proto_id != 0xff)
1909 return rte_flow_error_set(error, EINVAL,
1910 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1911 "partial mask is not supported"
1913 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1914 acc_mask ? (const uint8_t *)acc_mask
1915 : (const uint8_t *)&nic_mask,
1916 sizeof(struct rte_flow_item_ipv4),
1917 range_accepted, error);
1924 * Validate IPV6 item.
1927 * Item specification.
1928 * @param[in] item_flags
1929 * Bit-fields that holds the items detected until now.
1930 * @param[in] last_item
1931 * Previous validated item in the pattern items.
1932 * @param[in] ether_type
1933 * Type in the ethernet layer header (including dot1q).
1934 * @param[in] acc_mask
1935 * Acceptable mask, if NULL default internal default mask
1936 * will be used to check whether item fields are supported.
1938 * Pointer to error structure.
1941 * 0 on success, a negative errno value otherwise and rte_errno is set.
1944 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1945 uint64_t item_flags,
1947 uint16_t ether_type,
1948 const struct rte_flow_item_ipv6 *acc_mask,
1949 struct rte_flow_error *error)
1951 const struct rte_flow_item_ipv6 *mask = item->mask;
1952 const struct rte_flow_item_ipv6 *spec = item->spec;
1953 const struct rte_flow_item_ipv6 nic_mask = {
1956 "\xff\xff\xff\xff\xff\xff\xff\xff"
1957 "\xff\xff\xff\xff\xff\xff\xff\xff",
1959 "\xff\xff\xff\xff\xff\xff\xff\xff"
1960 "\xff\xff\xff\xff\xff\xff\xff\xff",
1961 .vtc_flow = RTE_BE32(0xffffffff),
1965 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1966 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1967 MLX5_FLOW_LAYER_OUTER_L3;
1968 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1969 MLX5_FLOW_LAYER_OUTER_L4;
1971 uint8_t next_proto = 0xFF;
1972 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1973 MLX5_FLOW_LAYER_OUTER_VLAN |
1974 MLX5_FLOW_LAYER_INNER_VLAN);
1976 if ((last_item & l2_vlan) && ether_type &&
1977 ether_type != RTE_ETHER_TYPE_IPV6)
1978 return rte_flow_error_set(error, EINVAL,
1979 RTE_FLOW_ERROR_TYPE_ITEM, item,
1980 "IPv6 cannot follow L2/VLAN layer "
1981 "which ether type is not IPv6");
1982 if (mask && mask->hdr.proto == UINT8_MAX && spec)
1983 next_proto = spec->hdr.proto;
1984 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
1985 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1986 return rte_flow_error_set(error, EINVAL,
1987 RTE_FLOW_ERROR_TYPE_ITEM,
1992 if (next_proto == IPPROTO_HOPOPTS ||
1993 next_proto == IPPROTO_ROUTING ||
1994 next_proto == IPPROTO_FRAGMENT ||
1995 next_proto == IPPROTO_ESP ||
1996 next_proto == IPPROTO_AH ||
1997 next_proto == IPPROTO_DSTOPTS)
1998 return rte_flow_error_set(error, EINVAL,
1999 RTE_FLOW_ERROR_TYPE_ITEM, item,
2000 "IPv6 proto (next header) should "
2001 "not be set as extension header");
2002 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2003 return rte_flow_error_set(error, EINVAL,
2004 RTE_FLOW_ERROR_TYPE_ITEM, item,
2005 "wrong tunnel type - IPv4 specified "
2006 "but IPv6 item provided");
2007 if (item_flags & l3m)
2008 return rte_flow_error_set(error, ENOTSUP,
2009 RTE_FLOW_ERROR_TYPE_ITEM, item,
2010 "multiple L3 layers not supported");
2011 else if (item_flags & l4m)
2012 return rte_flow_error_set(error, EINVAL,
2013 RTE_FLOW_ERROR_TYPE_ITEM, item,
2014 "L3 cannot follow an L4 layer.");
2015 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2016 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2017 return rte_flow_error_set(error, EINVAL,
2018 RTE_FLOW_ERROR_TYPE_ITEM, item,
2019 "L3 cannot follow an NVGRE layer.");
2021 mask = &rte_flow_item_ipv6_mask;
2022 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2023 acc_mask ? (const uint8_t *)acc_mask
2024 : (const uint8_t *)&nic_mask,
2025 sizeof(struct rte_flow_item_ipv6),
2026 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2033 * Validate UDP item.
2036 * Item specification.
2037 * @param[in] item_flags
2038 * Bit-fields that holds the items detected until now.
2039 * @param[in] target_protocol
2040 * The next protocol in the previous item.
2041 * @param[in] flow_mask
2042 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2044 * Pointer to error structure.
2047 * 0 on success, a negative errno value otherwise and rte_errno is set.
2050 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2051 uint64_t item_flags,
2052 uint8_t target_protocol,
2053 struct rte_flow_error *error)
2055 const struct rte_flow_item_udp *mask = item->mask;
2056 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2057 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2058 MLX5_FLOW_LAYER_OUTER_L3;
2059 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2060 MLX5_FLOW_LAYER_OUTER_L4;
2063 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2064 return rte_flow_error_set(error, EINVAL,
2065 RTE_FLOW_ERROR_TYPE_ITEM, item,
2066 "protocol filtering not compatible"
2068 if (!(item_flags & l3m))
2069 return rte_flow_error_set(error, EINVAL,
2070 RTE_FLOW_ERROR_TYPE_ITEM, item,
2071 "L3 is mandatory to filter on L4");
2072 if (item_flags & l4m)
2073 return rte_flow_error_set(error, EINVAL,
2074 RTE_FLOW_ERROR_TYPE_ITEM, item,
2075 "multiple L4 layers not supported");
2077 mask = &rte_flow_item_udp_mask;
2078 ret = mlx5_flow_item_acceptable
2079 (item, (const uint8_t *)mask,
2080 (const uint8_t *)&rte_flow_item_udp_mask,
2081 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2089 * Validate TCP item.
2092 * Item specification.
2093 * @param[in] item_flags
2094 * Bit-fields that holds the items detected until now.
2095 * @param[in] target_protocol
2096 * The next protocol in the previous item.
2098 * Pointer to error structure.
2101 * 0 on success, a negative errno value otherwise and rte_errno is set.
2104 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2105 uint64_t item_flags,
2106 uint8_t target_protocol,
2107 const struct rte_flow_item_tcp *flow_mask,
2108 struct rte_flow_error *error)
2110 const struct rte_flow_item_tcp *mask = item->mask;
2111 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2112 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2113 MLX5_FLOW_LAYER_OUTER_L3;
2114 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2115 MLX5_FLOW_LAYER_OUTER_L4;
2118 MLX5_ASSERT(flow_mask);
2119 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2120 return rte_flow_error_set(error, EINVAL,
2121 RTE_FLOW_ERROR_TYPE_ITEM, item,
2122 "protocol filtering not compatible"
2124 if (!(item_flags & l3m))
2125 return rte_flow_error_set(error, EINVAL,
2126 RTE_FLOW_ERROR_TYPE_ITEM, item,
2127 "L3 is mandatory to filter on L4");
2128 if (item_flags & l4m)
2129 return rte_flow_error_set(error, EINVAL,
2130 RTE_FLOW_ERROR_TYPE_ITEM, item,
2131 "multiple L4 layers not supported");
2133 mask = &rte_flow_item_tcp_mask;
2134 ret = mlx5_flow_item_acceptable
2135 (item, (const uint8_t *)mask,
2136 (const uint8_t *)flow_mask,
2137 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2145 * Validate VXLAN item.
2148 * Item specification.
2149 * @param[in] item_flags
2150 * Bit-fields that holds the items detected until now.
2151 * @param[in] target_protocol
2152 * The next protocol in the previous item.
2154 * Pointer to error structure.
2157 * 0 on success, a negative errno value otherwise and rte_errno is set.
2160 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
2161 uint64_t item_flags,
2162 struct rte_flow_error *error)
2164 const struct rte_flow_item_vxlan *spec = item->spec;
2165 const struct rte_flow_item_vxlan *mask = item->mask;
2170 } id = { .vlan_id = 0, };
2173 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2174 return rte_flow_error_set(error, ENOTSUP,
2175 RTE_FLOW_ERROR_TYPE_ITEM, item,
2176 "multiple tunnel layers not"
2179 * Verify only UDPv4 is present as defined in
2180 * https://tools.ietf.org/html/rfc7348
2182 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2183 return rte_flow_error_set(error, EINVAL,
2184 RTE_FLOW_ERROR_TYPE_ITEM, item,
2185 "no outer UDP layer found");
2187 mask = &rte_flow_item_vxlan_mask;
2188 ret = mlx5_flow_item_acceptable
2189 (item, (const uint8_t *)mask,
2190 (const uint8_t *)&rte_flow_item_vxlan_mask,
2191 sizeof(struct rte_flow_item_vxlan),
2192 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2196 memcpy(&id.vni[1], spec->vni, 3);
2197 memcpy(&id.vni[1], mask->vni, 3);
2199 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2200 return rte_flow_error_set(error, ENOTSUP,
2201 RTE_FLOW_ERROR_TYPE_ITEM, item,
2202 "VXLAN tunnel must be fully defined");
2207 * Validate VXLAN_GPE item.
2210 * Item specification.
2211 * @param[in] item_flags
2212 * Bit-fields that holds the items detected until now.
2214 * Pointer to the private data structure.
2215 * @param[in] target_protocol
2216 * The next protocol in the previous item.
2218 * Pointer to error structure.
2221 * 0 on success, a negative errno value otherwise and rte_errno is set.
2224 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2225 uint64_t item_flags,
2226 struct rte_eth_dev *dev,
2227 struct rte_flow_error *error)
2229 struct mlx5_priv *priv = dev->data->dev_private;
2230 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2231 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2236 } id = { .vlan_id = 0, };
2238 if (!priv->config.l3_vxlan_en)
2239 return rte_flow_error_set(error, ENOTSUP,
2240 RTE_FLOW_ERROR_TYPE_ITEM, item,
2241 "L3 VXLAN is not enabled by device"
2242 " parameter and/or not configured in"
2244 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2245 return rte_flow_error_set(error, ENOTSUP,
2246 RTE_FLOW_ERROR_TYPE_ITEM, item,
2247 "multiple tunnel layers not"
2250 * Verify only UDPv4 is present as defined in
2251 * https://tools.ietf.org/html/rfc7348
2253 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2254 return rte_flow_error_set(error, EINVAL,
2255 RTE_FLOW_ERROR_TYPE_ITEM, item,
2256 "no outer UDP layer found");
2258 mask = &rte_flow_item_vxlan_gpe_mask;
2259 ret = mlx5_flow_item_acceptable
2260 (item, (const uint8_t *)mask,
2261 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2262 sizeof(struct rte_flow_item_vxlan_gpe),
2263 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2268 return rte_flow_error_set(error, ENOTSUP,
2269 RTE_FLOW_ERROR_TYPE_ITEM,
2271 "VxLAN-GPE protocol"
2273 memcpy(&id.vni[1], spec->vni, 3);
2274 memcpy(&id.vni[1], mask->vni, 3);
2276 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2277 return rte_flow_error_set(error, ENOTSUP,
2278 RTE_FLOW_ERROR_TYPE_ITEM, item,
2279 "VXLAN-GPE tunnel must be fully"
2284 * Validate GRE Key item.
2287 * Item specification.
2288 * @param[in] item_flags
2289 * Bit flags to mark detected items.
2290 * @param[in] gre_item
2291 * Pointer to gre_item
2293 * Pointer to error structure.
2296 * 0 on success, a negative errno value otherwise and rte_errno is set.
2299 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2300 uint64_t item_flags,
2301 const struct rte_flow_item *gre_item,
2302 struct rte_flow_error *error)
2304 const rte_be32_t *mask = item->mask;
2306 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2307 const struct rte_flow_item_gre *gre_spec;
2308 const struct rte_flow_item_gre *gre_mask;
2310 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2311 return rte_flow_error_set(error, ENOTSUP,
2312 RTE_FLOW_ERROR_TYPE_ITEM, item,
2313 "Multiple GRE key not support");
2314 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2315 return rte_flow_error_set(error, ENOTSUP,
2316 RTE_FLOW_ERROR_TYPE_ITEM, item,
2317 "No preceding GRE header");
2318 if (item_flags & MLX5_FLOW_LAYER_INNER)
2319 return rte_flow_error_set(error, ENOTSUP,
2320 RTE_FLOW_ERROR_TYPE_ITEM, item,
2321 "GRE key following a wrong item");
2322 gre_mask = gre_item->mask;
2324 gre_mask = &rte_flow_item_gre_mask;
2325 gre_spec = gre_item->spec;
2326 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2327 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2328 return rte_flow_error_set(error, EINVAL,
2329 RTE_FLOW_ERROR_TYPE_ITEM, item,
2330 "Key bit must be on");
2333 mask = &gre_key_default_mask;
2334 ret = mlx5_flow_item_acceptable
2335 (item, (const uint8_t *)mask,
2336 (const uint8_t *)&gre_key_default_mask,
2337 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2342 * Validate GRE item.
2345 * Item specification.
2346 * @param[in] item_flags
2347 * Bit flags to mark detected items.
2348 * @param[in] target_protocol
2349 * The next protocol in the previous item.
2351 * Pointer to error structure.
2354 * 0 on success, a negative errno value otherwise and rte_errno is set.
2357 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2358 uint64_t item_flags,
2359 uint8_t target_protocol,
2360 struct rte_flow_error *error)
2362 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2363 const struct rte_flow_item_gre *mask = item->mask;
2365 const struct rte_flow_item_gre nic_mask = {
2366 .c_rsvd0_ver = RTE_BE16(0xB000),
2367 .protocol = RTE_BE16(UINT16_MAX),
2370 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2371 return rte_flow_error_set(error, EINVAL,
2372 RTE_FLOW_ERROR_TYPE_ITEM, item,
2373 "protocol filtering not compatible"
2374 " with this GRE layer");
2375 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2376 return rte_flow_error_set(error, ENOTSUP,
2377 RTE_FLOW_ERROR_TYPE_ITEM, item,
2378 "multiple tunnel layers not"
2380 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2381 return rte_flow_error_set(error, ENOTSUP,
2382 RTE_FLOW_ERROR_TYPE_ITEM, item,
2383 "L3 Layer is missing");
2385 mask = &rte_flow_item_gre_mask;
2386 ret = mlx5_flow_item_acceptable
2387 (item, (const uint8_t *)mask,
2388 (const uint8_t *)&nic_mask,
2389 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2393 #ifndef HAVE_MLX5DV_DR
2394 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2395 if (spec && (spec->protocol & mask->protocol))
2396 return rte_flow_error_set(error, ENOTSUP,
2397 RTE_FLOW_ERROR_TYPE_ITEM, item,
2398 "without MPLS support the"
2399 " specification cannot be used for"
2407 * Validate Geneve item.
2410 * Item specification.
2411 * @param[in] itemFlags
2412 * Bit-fields that holds the items detected until now.
2414 * Pointer to the private data structure.
2416 * Pointer to error structure.
2419 * 0 on success, a negative errno value otherwise and rte_errno is set.
2423 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2424 uint64_t item_flags,
2425 struct rte_eth_dev *dev,
2426 struct rte_flow_error *error)
2428 struct mlx5_priv *priv = dev->data->dev_private;
2429 const struct rte_flow_item_geneve *spec = item->spec;
2430 const struct rte_flow_item_geneve *mask = item->mask;
2433 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2434 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2435 const struct rte_flow_item_geneve nic_mask = {
2436 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2437 .vni = "\xff\xff\xff",
2438 .protocol = RTE_BE16(UINT16_MAX),
2441 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2442 return rte_flow_error_set(error, ENOTSUP,
2443 RTE_FLOW_ERROR_TYPE_ITEM, item,
2444 "L3 Geneve is not enabled by device"
2445 " parameter and/or not configured in"
2447 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2448 return rte_flow_error_set(error, ENOTSUP,
2449 RTE_FLOW_ERROR_TYPE_ITEM, item,
2450 "multiple tunnel layers not"
2453 * Verify only UDPv4 is present as defined in
2454 * https://tools.ietf.org/html/rfc7348
2456 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2457 return rte_flow_error_set(error, EINVAL,
2458 RTE_FLOW_ERROR_TYPE_ITEM, item,
2459 "no outer UDP layer found");
2461 mask = &rte_flow_item_geneve_mask;
2462 ret = mlx5_flow_item_acceptable
2463 (item, (const uint8_t *)mask,
2464 (const uint8_t *)&nic_mask,
2465 sizeof(struct rte_flow_item_geneve),
2466 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2470 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2471 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2472 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2473 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2474 return rte_flow_error_set(error, ENOTSUP,
2475 RTE_FLOW_ERROR_TYPE_ITEM,
2477 "Geneve protocol unsupported"
2478 " fields are being used");
2479 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2480 return rte_flow_error_set
2482 RTE_FLOW_ERROR_TYPE_ITEM,
2484 "Unsupported Geneve options length");
2486 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2487 return rte_flow_error_set
2489 RTE_FLOW_ERROR_TYPE_ITEM, item,
2490 "Geneve tunnel must be fully defined");
2495 * Validate MPLS item.
2498 * Pointer to the rte_eth_dev structure.
2500 * Item specification.
2501 * @param[in] item_flags
2502 * Bit-fields that holds the items detected until now.
2503 * @param[in] prev_layer
2504 * The protocol layer indicated in previous item.
2506 * Pointer to error structure.
2509 * 0 on success, a negative errno value otherwise and rte_errno is set.
2512 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2513 const struct rte_flow_item *item __rte_unused,
2514 uint64_t item_flags __rte_unused,
2515 uint64_t prev_layer __rte_unused,
2516 struct rte_flow_error *error)
2518 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2519 const struct rte_flow_item_mpls *mask = item->mask;
2520 struct mlx5_priv *priv = dev->data->dev_private;
2523 if (!priv->config.mpls_en)
2524 return rte_flow_error_set(error, ENOTSUP,
2525 RTE_FLOW_ERROR_TYPE_ITEM, item,
2526 "MPLS not supported or"
2527 " disabled in firmware"
2529 /* MPLS over IP, UDP, GRE is allowed */
2530 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2531 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2532 MLX5_FLOW_LAYER_GRE)))
2533 return rte_flow_error_set(error, EINVAL,
2534 RTE_FLOW_ERROR_TYPE_ITEM, item,
2535 "protocol filtering not compatible"
2536 " with MPLS layer");
2537 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2538 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2539 !(item_flags & MLX5_FLOW_LAYER_GRE))
2540 return rte_flow_error_set(error, ENOTSUP,
2541 RTE_FLOW_ERROR_TYPE_ITEM, item,
2542 "multiple tunnel layers not"
2545 mask = &rte_flow_item_mpls_mask;
2546 ret = mlx5_flow_item_acceptable
2547 (item, (const uint8_t *)mask,
2548 (const uint8_t *)&rte_flow_item_mpls_mask,
2549 sizeof(struct rte_flow_item_mpls),
2550 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2555 return rte_flow_error_set(error, ENOTSUP,
2556 RTE_FLOW_ERROR_TYPE_ITEM, item,
2557 "MPLS is not supported by Verbs, please"
2563 * Validate NVGRE item.
2566 * Item specification.
2567 * @param[in] item_flags
2568 * Bit flags to mark detected items.
2569 * @param[in] target_protocol
2570 * The next protocol in the previous item.
2572 * Pointer to error structure.
2575 * 0 on success, a negative errno value otherwise and rte_errno is set.
2578 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2579 uint64_t item_flags,
2580 uint8_t target_protocol,
2581 struct rte_flow_error *error)
2583 const struct rte_flow_item_nvgre *mask = item->mask;
2586 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2587 return rte_flow_error_set(error, EINVAL,
2588 RTE_FLOW_ERROR_TYPE_ITEM, item,
2589 "protocol filtering not compatible"
2590 " with this GRE layer");
2591 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2592 return rte_flow_error_set(error, ENOTSUP,
2593 RTE_FLOW_ERROR_TYPE_ITEM, item,
2594 "multiple tunnel layers not"
2596 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2597 return rte_flow_error_set(error, ENOTSUP,
2598 RTE_FLOW_ERROR_TYPE_ITEM, item,
2599 "L3 Layer is missing");
2601 mask = &rte_flow_item_nvgre_mask;
2602 ret = mlx5_flow_item_acceptable
2603 (item, (const uint8_t *)mask,
2604 (const uint8_t *)&rte_flow_item_nvgre_mask,
2605 sizeof(struct rte_flow_item_nvgre),
2606 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2613 * Validate eCPRI item.
2616 * Item specification.
2617 * @param[in] item_flags
2618 * Bit-fields that holds the items detected until now.
2619 * @param[in] last_item
2620 * Previous validated item in the pattern items.
2621 * @param[in] ether_type
2622 * Type in the ethernet layer header (including dot1q).
2623 * @param[in] acc_mask
2624 * Acceptable mask, if NULL default internal default mask
2625 * will be used to check whether item fields are supported.
2627 * Pointer to error structure.
2630 * 0 on success, a negative errno value otherwise and rte_errno is set.
2633 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
2634 uint64_t item_flags,
2636 uint16_t ether_type,
2637 const struct rte_flow_item_ecpri *acc_mask,
2638 struct rte_flow_error *error)
2640 const struct rte_flow_item_ecpri *mask = item->mask;
2641 const struct rte_flow_item_ecpri nic_mask = {
2645 RTE_BE32(((const struct rte_ecpri_common_hdr) {
2649 .dummy[0] = 0xFFFFFFFF,
2652 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
2653 MLX5_FLOW_LAYER_OUTER_VLAN);
2654 struct rte_flow_item_ecpri mask_lo;
2656 if ((last_item & outer_l2_vlan) && ether_type &&
2657 ether_type != RTE_ETHER_TYPE_ECPRI)
2658 return rte_flow_error_set(error, EINVAL,
2659 RTE_FLOW_ERROR_TYPE_ITEM, item,
2660 "eCPRI cannot follow L2/VLAN layer "
2661 "which ether type is not 0xAEFE.");
2662 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2663 return rte_flow_error_set(error, EINVAL,
2664 RTE_FLOW_ERROR_TYPE_ITEM, item,
2665 "eCPRI with tunnel is not supported "
2667 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
2668 return rte_flow_error_set(error, ENOTSUP,
2669 RTE_FLOW_ERROR_TYPE_ITEM, item,
2670 "multiple L3 layers not supported");
2671 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
2672 return rte_flow_error_set(error, EINVAL,
2673 RTE_FLOW_ERROR_TYPE_ITEM, item,
2674 "eCPRI cannot follow a TCP layer.");
2675 /* In specification, eCPRI could be over UDP layer. */
2676 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
2677 return rte_flow_error_set(error, EINVAL,
2678 RTE_FLOW_ERROR_TYPE_ITEM, item,
2679 "eCPRI over UDP layer is not yet "
2680 "supported right now.");
2681 /* Mask for type field in common header could be zero. */
2683 mask = &rte_flow_item_ecpri_mask;
2684 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
2685 /* Input mask is in big-endian format. */
2686 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
2687 return rte_flow_error_set(error, EINVAL,
2688 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2689 "partial mask is not supported "
2691 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
2692 return rte_flow_error_set(error, EINVAL,
2693 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2694 "message header mask must be after "
2696 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2697 acc_mask ? (const uint8_t *)acc_mask
2698 : (const uint8_t *)&nic_mask,
2699 sizeof(struct rte_flow_item_ecpri),
2700 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2703 /* Allocate unique ID for the split Q/RSS subflows. */
2705 flow_qrss_get_id(struct rte_eth_dev *dev)
2707 struct mlx5_priv *priv = dev->data->dev_private;
2708 uint32_t qrss_id, ret;
2710 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2713 MLX5_ASSERT(qrss_id);
2717 /* Free unique ID for the split Q/RSS subflows. */
2719 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2721 struct mlx5_priv *priv = dev->data->dev_private;
2724 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2728 * Release resource related QUEUE/RSS action split.
2731 * Pointer to Ethernet device.
2733 * Flow to release id's from.
2736 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2737 struct rte_flow *flow)
2739 struct mlx5_priv *priv = dev->data->dev_private;
2740 uint32_t handle_idx;
2741 struct mlx5_flow_handle *dev_handle;
2743 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
2744 handle_idx, dev_handle, next)
2745 if (dev_handle->split_flow_id)
2746 flow_qrss_free_id(dev, dev_handle->split_flow_id);
2750 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2751 const struct rte_flow_attr *attr __rte_unused,
2752 const struct rte_flow_item items[] __rte_unused,
2753 const struct rte_flow_action actions[] __rte_unused,
2754 bool external __rte_unused,
2755 int hairpin __rte_unused,
2756 struct rte_flow_error *error)
2758 return rte_flow_error_set(error, ENOTSUP,
2759 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2762 static struct mlx5_flow *
2763 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
2764 const struct rte_flow_attr *attr __rte_unused,
2765 const struct rte_flow_item items[] __rte_unused,
2766 const struct rte_flow_action actions[] __rte_unused,
2767 struct rte_flow_error *error)
2769 rte_flow_error_set(error, ENOTSUP,
2770 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2775 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2776 struct mlx5_flow *dev_flow __rte_unused,
2777 const struct rte_flow_attr *attr __rte_unused,
2778 const struct rte_flow_item items[] __rte_unused,
2779 const struct rte_flow_action actions[] __rte_unused,
2780 struct rte_flow_error *error)
2782 return rte_flow_error_set(error, ENOTSUP,
2783 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2787 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2788 struct rte_flow *flow __rte_unused,
2789 struct rte_flow_error *error)
2791 return rte_flow_error_set(error, ENOTSUP,
2792 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2796 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2797 struct rte_flow *flow __rte_unused)
2802 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2803 struct rte_flow *flow __rte_unused)
2808 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2809 struct rte_flow *flow __rte_unused,
2810 const struct rte_flow_action *actions __rte_unused,
2811 void *data __rte_unused,
2812 struct rte_flow_error *error)
2814 return rte_flow_error_set(error, ENOTSUP,
2815 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2818 /* Void driver to protect from null pointer reference. */
2819 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2820 .validate = flow_null_validate,
2821 .prepare = flow_null_prepare,
2822 .translate = flow_null_translate,
2823 .apply = flow_null_apply,
2824 .remove = flow_null_remove,
2825 .destroy = flow_null_destroy,
2826 .query = flow_null_query,
2830 * Select flow driver type according to flow attributes and device
2834 * Pointer to the dev structure.
2836 * Pointer to the flow attributes.
2839 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2841 static enum mlx5_flow_drv_type
2842 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2844 struct mlx5_priv *priv = dev->data->dev_private;
2845 /* The OS can determine first a specific flow type (DV, VERBS) */
2846 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
2848 if (type != MLX5_FLOW_TYPE_MAX)
2850 /* If no OS specific type - continue with DV/VERBS selection */
2851 if (attr->transfer && priv->config.dv_esw_en)
2852 type = MLX5_FLOW_TYPE_DV;
2853 if (!attr->transfer)
2854 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2855 MLX5_FLOW_TYPE_VERBS;
2859 #define flow_get_drv_ops(type) flow_drv_ops[type]
2862 * Flow driver validation API. This abstracts calling driver specific functions.
2863 * The type of flow driver is determined according to flow attributes.
2866 * Pointer to the dev structure.
2868 * Pointer to the flow attributes.
2870 * Pointer to the list of items.
2871 * @param[in] actions
2872 * Pointer to the list of actions.
2873 * @param[in] external
2874 * This flow rule is created by request external to PMD.
2875 * @param[in] hairpin
2876 * Number of hairpin TX actions, 0 means classic flow.
2878 * Pointer to the error structure.
2881 * 0 on success, a negative errno value otherwise and rte_errno is set.
2884 flow_drv_validate(struct rte_eth_dev *dev,
2885 const struct rte_flow_attr *attr,
2886 const struct rte_flow_item items[],
2887 const struct rte_flow_action actions[],
2888 bool external, int hairpin, struct rte_flow_error *error)
2890 const struct mlx5_flow_driver_ops *fops;
2891 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2893 fops = flow_get_drv_ops(type);
2894 return fops->validate(dev, attr, items, actions, external,
2899 * Flow driver preparation API. This abstracts calling driver specific
2900 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2901 * calculates the size of memory required for device flow, allocates the memory,
2902 * initializes the device flow and returns the pointer.
2905 * This function initializes device flow structure such as dv or verbs in
2906 * struct mlx5_flow. However, it is caller's responsibility to initialize the
2907 * rest. For example, adding returning device flow to flow->dev_flow list and
2908 * setting backward reference to the flow should be done out of this function.
2909 * layers field is not filled either.
2912 * Pointer to the dev structure.
2914 * Pointer to the flow attributes.
2916 * Pointer to the list of items.
2917 * @param[in] actions
2918 * Pointer to the list of actions.
2919 * @param[in] flow_idx
2920 * This memory pool index to the flow.
2922 * Pointer to the error structure.
2925 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
2927 static inline struct mlx5_flow *
2928 flow_drv_prepare(struct rte_eth_dev *dev,
2929 const struct rte_flow *flow,
2930 const struct rte_flow_attr *attr,
2931 const struct rte_flow_item items[],
2932 const struct rte_flow_action actions[],
2934 struct rte_flow_error *error)
2936 const struct mlx5_flow_driver_ops *fops;
2937 enum mlx5_flow_drv_type type = flow->drv_type;
2938 struct mlx5_flow *mlx5_flow = NULL;
2940 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2941 fops = flow_get_drv_ops(type);
2942 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
2944 mlx5_flow->flow_idx = flow_idx;
2949 * Flow driver translation API. This abstracts calling driver specific
2950 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2951 * translates a generic flow into a driver flow. flow_drv_prepare() must
2955 * dev_flow->layers could be filled as a result of parsing during translation
2956 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
2957 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
2958 * flow->actions could be overwritten even though all the expanded dev_flows
2959 * have the same actions.
2962 * Pointer to the rte dev structure.
2963 * @param[in, out] dev_flow
2964 * Pointer to the mlx5 flow.
2966 * Pointer to the flow attributes.
2968 * Pointer to the list of items.
2969 * @param[in] actions
2970 * Pointer to the list of actions.
2972 * Pointer to the error structure.
2975 * 0 on success, a negative errno value otherwise and rte_errno is set.
2978 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
2979 const struct rte_flow_attr *attr,
2980 const struct rte_flow_item items[],
2981 const struct rte_flow_action actions[],
2982 struct rte_flow_error *error)
2984 const struct mlx5_flow_driver_ops *fops;
2985 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
2987 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2988 fops = flow_get_drv_ops(type);
2989 return fops->translate(dev, dev_flow, attr, items, actions, error);
2993 * Flow driver apply API. This abstracts calling driver specific functions.
2994 * Parent flow (rte_flow) should have driver type (drv_type). It applies
2995 * translated driver flows on to device. flow_drv_translate() must precede.
2998 * Pointer to Ethernet device structure.
2999 * @param[in, out] flow
3000 * Pointer to flow structure.
3002 * Pointer to error structure.
3005 * 0 on success, a negative errno value otherwise and rte_errno is set.
3008 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3009 struct rte_flow_error *error)
3011 const struct mlx5_flow_driver_ops *fops;
3012 enum mlx5_flow_drv_type type = flow->drv_type;
3014 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3015 fops = flow_get_drv_ops(type);
3016 return fops->apply(dev, flow, error);
3020 * Flow driver remove API. This abstracts calling driver specific functions.
3021 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3022 * on device. All the resources of the flow should be freed by calling
3023 * flow_drv_destroy().
3026 * Pointer to Ethernet device.
3027 * @param[in, out] flow
3028 * Pointer to flow structure.
3031 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
3033 const struct mlx5_flow_driver_ops *fops;
3034 enum mlx5_flow_drv_type type = flow->drv_type;
3036 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3037 fops = flow_get_drv_ops(type);
3038 fops->remove(dev, flow);
3042 * Flow driver destroy API. This abstracts calling driver specific functions.
3043 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3044 * on device and releases resources of the flow.
3047 * Pointer to Ethernet device.
3048 * @param[in, out] flow
3049 * Pointer to flow structure.
3052 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3054 const struct mlx5_flow_driver_ops *fops;
3055 enum mlx5_flow_drv_type type = flow->drv_type;
3057 flow_mreg_split_qrss_release(dev, flow);
3058 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3059 fops = flow_get_drv_ops(type);
3060 fops->destroy(dev, flow);
3064 * Get RSS action from the action list.
3066 * @param[in] actions
3067 * Pointer to the list of actions.
3070 * Pointer to the RSS action if exist, else return NULL.
3072 static const struct rte_flow_action_rss*
3073 flow_get_rss_action(const struct rte_flow_action actions[])
3075 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3076 switch (actions->type) {
3077 case RTE_FLOW_ACTION_TYPE_RSS:
3078 return (const struct rte_flow_action_rss *)
3088 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3090 const struct rte_flow_item *item;
3091 unsigned int has_vlan = 0;
3093 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3094 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3100 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3101 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3102 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3103 MLX5_EXPANSION_ROOT_OUTER;
3107 * Get layer flags from the prefix flow.
3109 * Some flows may be split to several subflows, the prefix subflow gets the
3110 * match items and the suffix sub flow gets the actions.
3111 * Some actions need the user defined match item flags to get the detail for
3113 * This function helps the suffix flow to get the item layer flags from prefix
3116 * @param[in] dev_flow
3117 * Pointer the created preifx subflow.
3120 * The layers get from prefix subflow.
3122 static inline uint64_t
3123 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3125 uint64_t layers = 0;
3128 * Layers bits could be localization, but usually the compiler will
3129 * help to do the optimization work for source code.
3130 * If no decap actions, use the layers directly.
3132 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3133 return dev_flow->handle->layers;
3134 /* Convert L3 layers with decap action. */
3135 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3136 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3137 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3138 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3139 /* Convert L4 layers with decap action. */
3140 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3141 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3142 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3143 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3148 * Get metadata split action information.
3150 * @param[in] actions
3151 * Pointer to the list of actions.
3153 * Pointer to the return pointer.
3154 * @param[out] qrss_type
3155 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3156 * if no QUEUE/RSS is found.
3157 * @param[out] encap_idx
3158 * Pointer to the index of the encap action if exists, otherwise the last
3162 * Total number of actions.
3165 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3166 const struct rte_flow_action **qrss,
3169 const struct rte_flow_action_raw_encap *raw_encap;
3171 int raw_decap_idx = -1;
3174 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3175 switch (actions->type) {
3176 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3177 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3178 *encap_idx = actions_n;
3180 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3181 raw_decap_idx = actions_n;
3183 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3184 raw_encap = actions->conf;
3185 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3186 *encap_idx = raw_decap_idx != -1 ?
3187 raw_decap_idx : actions_n;
3189 case RTE_FLOW_ACTION_TYPE_QUEUE:
3190 case RTE_FLOW_ACTION_TYPE_RSS:
3198 if (*encap_idx == -1)
3199 *encap_idx = actions_n;
3200 /* Count RTE_FLOW_ACTION_TYPE_END. */
3201 return actions_n + 1;
3205 * Check meter action from the action list.
3207 * @param[in] actions
3208 * Pointer to the list of actions.
3210 * Pointer to the meter exist flag.
3213 * Total number of actions.
3216 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
3222 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3223 switch (actions->type) {
3224 case RTE_FLOW_ACTION_TYPE_METER:
3232 /* Count RTE_FLOW_ACTION_TYPE_END. */
3233 return actions_n + 1;
3237 * Check if the flow should be split due to hairpin.
3238 * The reason for the split is that in current HW we can't
3239 * support encap and push-vlan on Rx, so if a flow contains
3240 * these actions we move it to Tx.
3243 * Pointer to Ethernet device.
3245 * Flow rule attributes.
3246 * @param[in] actions
3247 * Associated actions (list terminated by the END action).
3250 * > 0 the number of actions and the flow should be split,
3251 * 0 when no split required.
3254 flow_check_hairpin_split(struct rte_eth_dev *dev,
3255 const struct rte_flow_attr *attr,
3256 const struct rte_flow_action actions[])
3258 int queue_action = 0;
3261 const struct rte_flow_action_queue *queue;
3262 const struct rte_flow_action_rss *rss;
3263 const struct rte_flow_action_raw_encap *raw_encap;
3267 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3268 switch (actions->type) {
3269 case RTE_FLOW_ACTION_TYPE_QUEUE:
3270 queue = actions->conf;
3273 if (mlx5_rxq_get_type(dev, queue->index) !=
3274 MLX5_RXQ_TYPE_HAIRPIN)
3279 case RTE_FLOW_ACTION_TYPE_RSS:
3280 rss = actions->conf;
3281 if (rss == NULL || rss->queue_num == 0)
3283 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
3284 MLX5_RXQ_TYPE_HAIRPIN)
3289 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3290 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3291 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3292 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3293 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3297 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3298 raw_encap = actions->conf;
3299 if (raw_encap->size >
3300 (sizeof(struct rte_flow_item_eth) +
3301 sizeof(struct rte_flow_item_ipv4)))
3310 if (split && queue_action)
3315 /* Declare flow create/destroy prototype in advance. */
3317 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
3318 const struct rte_flow_attr *attr,
3319 const struct rte_flow_item items[],
3320 const struct rte_flow_action actions[],
3321 bool external, struct rte_flow_error *error);
3324 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
3328 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3330 * As mark_id is unique, if there's already a registered flow for the mark_id,
3331 * return by increasing the reference counter of the resource. Otherwise, create
3332 * the resource (mcp_res) and flow.
3335 * - If ingress port is ANY and reg_c[1] is mark_id,
3336 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3338 * For default flow (zero mark_id), flow is like,
3339 * - If ingress port is ANY,
3340 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
3343 * Pointer to Ethernet device.
3345 * ID of MARK action, zero means default flow for META.
3347 * Perform verbose error reporting if not NULL.
3350 * Associated resource on success, NULL otherwise and rte_errno is set.
3352 static struct mlx5_flow_mreg_copy_resource *
3353 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
3354 struct rte_flow_error *error)
3356 struct mlx5_priv *priv = dev->data->dev_private;
3357 struct rte_flow_attr attr = {
3358 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3361 struct mlx5_rte_flow_item_tag tag_spec = {
3364 struct rte_flow_item items[] = {
3365 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
3367 struct rte_flow_action_mark ftag = {
3370 struct mlx5_flow_action_copy_mreg cp_mreg = {
3374 struct rte_flow_action_jump jump = {
3375 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3377 struct rte_flow_action actions[] = {
3378 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
3380 struct mlx5_flow_mreg_copy_resource *mcp_res;
3384 /* Fill the register fileds in the flow. */
3385 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3389 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3393 /* Check if already registered. */
3394 MLX5_ASSERT(priv->mreg_cp_tbl);
3395 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
3397 /* For non-default rule. */
3398 if (mark_id != MLX5_DEFAULT_COPY_ID)
3400 MLX5_ASSERT(mark_id != MLX5_DEFAULT_COPY_ID ||
3401 mcp_res->refcnt == 1);
3404 /* Provide the full width of FLAG specific value. */
3405 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3406 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3407 /* Build a new flow. */
3408 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3409 items[0] = (struct rte_flow_item){
3410 .type = (enum rte_flow_item_type)
3411 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3414 items[1] = (struct rte_flow_item){
3415 .type = RTE_FLOW_ITEM_TYPE_END,
3417 actions[0] = (struct rte_flow_action){
3418 .type = (enum rte_flow_action_type)
3419 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3422 actions[1] = (struct rte_flow_action){
3423 .type = (enum rte_flow_action_type)
3424 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3427 actions[2] = (struct rte_flow_action){
3428 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3431 actions[3] = (struct rte_flow_action){
3432 .type = RTE_FLOW_ACTION_TYPE_END,
3435 /* Default rule, wildcard match. */
3436 attr.priority = MLX5_FLOW_PRIO_RSVD;
3437 items[0] = (struct rte_flow_item){
3438 .type = RTE_FLOW_ITEM_TYPE_END,
3440 actions[0] = (struct rte_flow_action){
3441 .type = (enum rte_flow_action_type)
3442 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3445 actions[1] = (struct rte_flow_action){
3446 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3449 actions[2] = (struct rte_flow_action){
3450 .type = RTE_FLOW_ACTION_TYPE_END,
3453 /* Build a new entry. */
3454 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3461 * The copy Flows are not included in any list. There
3462 * ones are referenced from other Flows and can not
3463 * be applied, removed, deleted in ardbitrary order
3464 * by list traversing.
3466 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3467 actions, false, error);
3468 if (!mcp_res->rix_flow)
3471 mcp_res->hlist_ent.key = mark_id;
3472 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3473 &mcp_res->hlist_ent);
3479 if (mcp_res->rix_flow)
3480 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3481 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3486 * Release flow in RX_CP_TBL.
3489 * Pointer to Ethernet device.
3491 * Parent flow for wich copying is provided.
3494 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3495 struct rte_flow *flow)
3497 struct mlx5_flow_mreg_copy_resource *mcp_res;
3498 struct mlx5_priv *priv = dev->data->dev_private;
3500 if (!flow->rix_mreg_copy)
3502 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3503 flow->rix_mreg_copy);
3504 if (!mcp_res || !priv->mreg_cp_tbl)
3506 if (flow->copy_applied) {
3507 MLX5_ASSERT(mcp_res->appcnt);
3508 flow->copy_applied = 0;
3510 if (!mcp_res->appcnt) {
3511 struct rte_flow *mcp_flow = mlx5_ipool_get
3512 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3516 flow_drv_remove(dev, mcp_flow);
3520 * We do not check availability of metadata registers here,
3521 * because copy resources are not allocated in this case.
3523 if (--mcp_res->refcnt)
3525 MLX5_ASSERT(mcp_res->rix_flow);
3526 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3527 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3528 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3529 flow->rix_mreg_copy = 0;
3533 * Start flow in RX_CP_TBL.
3536 * Pointer to Ethernet device.
3538 * Parent flow for wich copying is provided.
3541 * 0 on success, a negative errno value otherwise and rte_errno is set.
3544 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3545 struct rte_flow *flow)
3547 struct mlx5_flow_mreg_copy_resource *mcp_res;
3548 struct mlx5_priv *priv = dev->data->dev_private;
3551 if (!flow->rix_mreg_copy || flow->copy_applied)
3553 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3554 flow->rix_mreg_copy);
3557 if (!mcp_res->appcnt) {
3558 struct rte_flow *mcp_flow = mlx5_ipool_get
3559 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3563 ret = flow_drv_apply(dev, mcp_flow, NULL);
3569 flow->copy_applied = 1;
3574 * Stop flow in RX_CP_TBL.
3577 * Pointer to Ethernet device.
3579 * Parent flow for wich copying is provided.
3582 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3583 struct rte_flow *flow)
3585 struct mlx5_flow_mreg_copy_resource *mcp_res;
3586 struct mlx5_priv *priv = dev->data->dev_private;
3588 if (!flow->rix_mreg_copy || !flow->copy_applied)
3590 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3591 flow->rix_mreg_copy);
3594 MLX5_ASSERT(mcp_res->appcnt);
3596 flow->copy_applied = 0;
3597 if (!mcp_res->appcnt) {
3598 struct rte_flow *mcp_flow = mlx5_ipool_get
3599 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3603 flow_drv_remove(dev, mcp_flow);
3608 * Remove the default copy action from RX_CP_TBL.
3611 * Pointer to Ethernet device.
3614 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3616 struct mlx5_flow_mreg_copy_resource *mcp_res;
3617 struct mlx5_priv *priv = dev->data->dev_private;
3619 /* Check if default flow is registered. */
3620 if (!priv->mreg_cp_tbl)
3622 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3623 MLX5_DEFAULT_COPY_ID);
3626 MLX5_ASSERT(mcp_res->rix_flow);
3627 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3628 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3629 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3633 * Add the default copy action in in RX_CP_TBL.
3636 * Pointer to Ethernet device.
3638 * Perform verbose error reporting if not NULL.
3641 * 0 for success, negative value otherwise and rte_errno is set.
3644 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3645 struct rte_flow_error *error)
3647 struct mlx5_priv *priv = dev->data->dev_private;
3648 struct mlx5_flow_mreg_copy_resource *mcp_res;
3650 /* Check whether extensive metadata feature is engaged. */
3651 if (!priv->config.dv_flow_en ||
3652 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3653 !mlx5_flow_ext_mreg_supported(dev) ||
3654 !priv->sh->dv_regc0_mask)
3656 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3663 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3665 * All the flow having Q/RSS action should be split by
3666 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3667 * performs the following,
3668 * - CQE->flow_tag := reg_c[1] (MARK)
3669 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3670 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3671 * but there should be a flow per each MARK ID set by MARK action.
3673 * For the aforementioned reason, if there's a MARK action in flow's action
3674 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3675 * the MARK ID to CQE's flow_tag like,
3676 * - If reg_c[1] is mark_id,
3677 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3679 * For SET_META action which stores value in reg_c[0], as the destination is
3680 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3681 * MARK ID means the default flow. The default flow looks like,
3682 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3685 * Pointer to Ethernet device.
3687 * Pointer to flow structure.
3688 * @param[in] actions
3689 * Pointer to the list of actions.
3691 * Perform verbose error reporting if not NULL.
3694 * 0 on success, negative value otherwise and rte_errno is set.
3697 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3698 struct rte_flow *flow,
3699 const struct rte_flow_action *actions,
3700 struct rte_flow_error *error)
3702 struct mlx5_priv *priv = dev->data->dev_private;
3703 struct mlx5_dev_config *config = &priv->config;
3704 struct mlx5_flow_mreg_copy_resource *mcp_res;
3705 const struct rte_flow_action_mark *mark;
3707 /* Check whether extensive metadata feature is engaged. */
3708 if (!config->dv_flow_en ||
3709 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3710 !mlx5_flow_ext_mreg_supported(dev) ||
3711 !priv->sh->dv_regc0_mask)
3713 /* Find MARK action. */
3714 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3715 switch (actions->type) {
3716 case RTE_FLOW_ACTION_TYPE_FLAG:
3717 mcp_res = flow_mreg_add_copy_action
3718 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3721 flow->rix_mreg_copy = mcp_res->idx;
3722 if (dev->data->dev_started) {
3724 flow->copy_applied = 1;
3727 case RTE_FLOW_ACTION_TYPE_MARK:
3728 mark = (const struct rte_flow_action_mark *)
3731 flow_mreg_add_copy_action(dev, mark->id, error);
3734 flow->rix_mreg_copy = mcp_res->idx;
3735 if (dev->data->dev_started) {
3737 flow->copy_applied = 1;
3747 #define MLX5_MAX_SPLIT_ACTIONS 24
3748 #define MLX5_MAX_SPLIT_ITEMS 24
3751 * Split the hairpin flow.
3752 * Since HW can't support encap and push-vlan on Rx, we move these
3754 * If the count action is after the encap then we also
3755 * move the count action. in this case the count will also measure
3759 * Pointer to Ethernet device.
3760 * @param[in] actions
3761 * Associated actions (list terminated by the END action).
3762 * @param[out] actions_rx
3764 * @param[out] actions_tx
3766 * @param[out] pattern_tx
3767 * The pattern items for the Tx flow.
3768 * @param[out] flow_id
3769 * The flow ID connected to this flow.
3775 flow_hairpin_split(struct rte_eth_dev *dev,
3776 const struct rte_flow_action actions[],
3777 struct rte_flow_action actions_rx[],
3778 struct rte_flow_action actions_tx[],
3779 struct rte_flow_item pattern_tx[],
3782 struct mlx5_priv *priv = dev->data->dev_private;
3783 const struct rte_flow_action_raw_encap *raw_encap;
3784 const struct rte_flow_action_raw_decap *raw_decap;
3785 struct mlx5_rte_flow_action_set_tag *set_tag;
3786 struct rte_flow_action *tag_action;
3787 struct mlx5_rte_flow_item_tag *tag_item;
3788 struct rte_flow_item *item;
3792 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
3793 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3794 switch (actions->type) {
3795 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3796 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3797 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3798 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3799 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3800 rte_memcpy(actions_tx, actions,
3801 sizeof(struct rte_flow_action));
3804 case RTE_FLOW_ACTION_TYPE_COUNT:
3806 rte_memcpy(actions_tx, actions,
3807 sizeof(struct rte_flow_action));
3810 rte_memcpy(actions_rx, actions,
3811 sizeof(struct rte_flow_action));
3815 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3816 raw_encap = actions->conf;
3817 if (raw_encap->size >
3818 (sizeof(struct rte_flow_item_eth) +
3819 sizeof(struct rte_flow_item_ipv4))) {
3820 memcpy(actions_tx, actions,
3821 sizeof(struct rte_flow_action));
3825 rte_memcpy(actions_rx, actions,
3826 sizeof(struct rte_flow_action));
3830 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3831 raw_decap = actions->conf;
3832 if (raw_decap->size <
3833 (sizeof(struct rte_flow_item_eth) +
3834 sizeof(struct rte_flow_item_ipv4))) {
3835 memcpy(actions_tx, actions,
3836 sizeof(struct rte_flow_action));
3839 rte_memcpy(actions_rx, actions,
3840 sizeof(struct rte_flow_action));
3845 rte_memcpy(actions_rx, actions,
3846 sizeof(struct rte_flow_action));
3851 /* Add set meta action and end action for the Rx flow. */
3852 tag_action = actions_rx;
3853 tag_action->type = (enum rte_flow_action_type)
3854 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3856 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
3858 set_tag = (void *)actions_rx;
3859 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
3860 MLX5_ASSERT(set_tag->id > REG_NON);
3861 set_tag->data = *flow_id;
3862 tag_action->conf = set_tag;
3863 /* Create Tx item list. */
3864 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
3865 addr = (void *)&pattern_tx[2];
3867 item->type = (enum rte_flow_item_type)
3868 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3869 tag_item = (void *)addr;
3870 tag_item->data = *flow_id;
3871 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
3872 MLX5_ASSERT(set_tag->id > REG_NON);
3873 item->spec = tag_item;
3874 addr += sizeof(struct mlx5_rte_flow_item_tag);
3875 tag_item = (void *)addr;
3876 tag_item->data = UINT32_MAX;
3877 tag_item->id = UINT16_MAX;
3878 item->mask = tag_item;
3881 item->type = RTE_FLOW_ITEM_TYPE_END;
3886 * The last stage of splitting chain, just creates the subflow
3887 * without any modification.
3890 * Pointer to Ethernet device.
3892 * Parent flow structure pointer.
3893 * @param[in, out] sub_flow
3894 * Pointer to return the created subflow, may be NULL.
3895 * @param[in] prefix_layers
3896 * Prefix subflow layers, may be 0.
3897 * @param[in] prefix_mark
3898 * Prefix subflow mark flag, may be 0.
3900 * Flow rule attributes.
3902 * Pattern specification (list terminated by the END pattern item).
3903 * @param[in] actions
3904 * Associated actions (list terminated by the END action).
3905 * @param[in] external
3906 * This flow rule is created by request external to PMD.
3907 * @param[in] flow_idx
3908 * This memory pool index to the flow.
3910 * Perform verbose error reporting if not NULL.
3912 * 0 on success, negative value otherwise
3915 flow_create_split_inner(struct rte_eth_dev *dev,
3916 struct rte_flow *flow,
3917 struct mlx5_flow **sub_flow,
3918 uint64_t prefix_layers,
3919 uint32_t prefix_mark,
3920 const struct rte_flow_attr *attr,
3921 const struct rte_flow_item items[],
3922 const struct rte_flow_action actions[],
3923 bool external, uint32_t flow_idx,
3924 struct rte_flow_error *error)
3926 struct mlx5_flow *dev_flow;
3928 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
3932 dev_flow->flow = flow;
3933 dev_flow->external = external;
3934 /* Subflow object was created, we must include one in the list. */
3935 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
3936 dev_flow->handle, next);
3938 * If dev_flow is as one of the suffix flow, some actions in suffix
3939 * flow may need some user defined item layer flags, and pass the
3940 * Metadate rxq mark flag to suffix flow as well.
3943 dev_flow->handle->layers = prefix_layers;
3945 dev_flow->handle->mark = 1;
3947 *sub_flow = dev_flow;
3948 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
3952 * Split the meter flow.
3954 * As meter flow will split to three sub flow, other than meter
3955 * action, the other actions make sense to only meter accepts
3956 * the packet. If it need to be dropped, no other additional
3957 * actions should be take.
3959 * One kind of special action which decapsulates the L3 tunnel
3960 * header will be in the prefix sub flow, as not to take the
3961 * L3 tunnel header into account.
3964 * Pointer to Ethernet device.
3966 * Pattern specification (list terminated by the END pattern item).
3967 * @param[out] sfx_items
3968 * Suffix flow match items (list terminated by the END pattern item).
3969 * @param[in] actions
3970 * Associated actions (list terminated by the END action).
3971 * @param[out] actions_sfx
3972 * Suffix flow actions.
3973 * @param[out] actions_pre
3974 * Prefix flow actions.
3975 * @param[out] pattern_sfx
3976 * The pattern items for the suffix flow.
3977 * @param[out] tag_sfx
3978 * Pointer to suffix flow tag.
3984 flow_meter_split_prep(struct rte_eth_dev *dev,
3985 const struct rte_flow_item items[],
3986 struct rte_flow_item sfx_items[],
3987 const struct rte_flow_action actions[],
3988 struct rte_flow_action actions_sfx[],
3989 struct rte_flow_action actions_pre[])
3991 struct rte_flow_action *tag_action = NULL;
3992 struct rte_flow_item *tag_item;
3993 struct mlx5_rte_flow_action_set_tag *set_tag;
3994 struct rte_flow_error error;
3995 const struct rte_flow_action_raw_encap *raw_encap;
3996 const struct rte_flow_action_raw_decap *raw_decap;
3997 struct mlx5_rte_flow_item_tag *tag_spec;
3998 struct mlx5_rte_flow_item_tag *tag_mask;
4000 bool copy_vlan = false;
4002 /* Prepare the actions for prefix and suffix flow. */
4003 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4004 struct rte_flow_action **action_cur = NULL;
4006 switch (actions->type) {
4007 case RTE_FLOW_ACTION_TYPE_METER:
4008 /* Add the extra tag action first. */
4009 tag_action = actions_pre;
4010 tag_action->type = (enum rte_flow_action_type)
4011 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4013 action_cur = &actions_pre;
4015 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4016 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4017 action_cur = &actions_pre;
4019 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4020 raw_encap = actions->conf;
4021 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4022 action_cur = &actions_pre;
4024 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4025 raw_decap = actions->conf;
4026 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4027 action_cur = &actions_pre;
4029 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4030 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4037 action_cur = &actions_sfx;
4038 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
4041 /* Add end action to the actions. */
4042 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4043 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4046 set_tag = (void *)actions_pre;
4047 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4049 * Get the id from the qrss_pool to make qrss share the id with meter.
4051 tag_id = flow_qrss_get_id(dev);
4052 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
4054 tag_action->conf = set_tag;
4055 /* Prepare the suffix subflow items. */
4056 tag_item = sfx_items++;
4057 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4058 int item_type = items->type;
4060 switch (item_type) {
4061 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4062 memcpy(sfx_items, items, sizeof(*sfx_items));
4065 case RTE_FLOW_ITEM_TYPE_VLAN:
4067 memcpy(sfx_items, items, sizeof(*sfx_items));
4069 * Convert to internal match item, it is used
4070 * for vlan push and set vid.
4072 sfx_items->type = (enum rte_flow_item_type)
4073 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4081 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4083 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4084 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
4085 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4086 tag_mask = tag_spec + 1;
4087 tag_mask->data = 0xffffff00;
4088 tag_item->type = (enum rte_flow_item_type)
4089 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4090 tag_item->spec = tag_spec;
4091 tag_item->last = NULL;
4092 tag_item->mask = tag_mask;
4097 * Split action list having QUEUE/RSS for metadata register copy.
4099 * Once Q/RSS action is detected in user's action list, the flow action
4100 * should be split in order to copy metadata registers, which will happen in
4102 * - CQE->flow_tag := reg_c[1] (MARK)
4103 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4104 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
4105 * This is because the last action of each flow must be a terminal action
4106 * (QUEUE, RSS or DROP).
4108 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
4109 * stored and kept in the mlx5_flow structure per each sub_flow.
4111 * The Q/RSS action is replaced with,
4112 * - SET_TAG, setting the allocated flow ID to reg_c[2].
4113 * And the following JUMP action is added at the end,
4114 * - JUMP, to RX_CP_TBL.
4116 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
4117 * flow_create_split_metadata() routine. The flow will look like,
4118 * - If flow ID matches (reg_c[2]), perform Q/RSS.
4121 * Pointer to Ethernet device.
4122 * @param[out] split_actions
4123 * Pointer to store split actions to jump to CP_TBL.
4124 * @param[in] actions
4125 * Pointer to the list of original flow actions.
4127 * Pointer to the Q/RSS action.
4128 * @param[in] actions_n
4129 * Number of original actions.
4131 * Perform verbose error reporting if not NULL.
4134 * non-zero unique flow_id on success, otherwise 0 and
4135 * error/rte_error are set.
4138 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
4139 struct rte_flow_action *split_actions,
4140 const struct rte_flow_action *actions,
4141 const struct rte_flow_action *qrss,
4142 int actions_n, struct rte_flow_error *error)
4144 struct mlx5_rte_flow_action_set_tag *set_tag;
4145 struct rte_flow_action_jump *jump;
4146 const int qrss_idx = qrss - actions;
4147 uint32_t flow_id = 0;
4151 * Given actions will be split
4152 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
4153 * - Add jump to mreg CP_TBL.
4154 * As a result, there will be one more action.
4157 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
4158 set_tag = (void *)(split_actions + actions_n);
4160 * If tag action is not set to void(it means we are not the meter
4161 * suffix flow), add the tag action. Since meter suffix flow already
4162 * has the tag added.
4164 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
4166 * Allocate the new subflow ID. This one is unique within
4167 * device and not shared with representors. Otherwise,
4168 * we would have to resolve multi-thread access synch
4169 * issue. Each flow on the shared device is appended
4170 * with source vport identifier, so the resulting
4171 * flows will be unique in the shared (by master and
4172 * representors) domain even if they have coinciding
4175 flow_id = flow_qrss_get_id(dev);
4177 return rte_flow_error_set(error, ENOMEM,
4178 RTE_FLOW_ERROR_TYPE_ACTION,
4179 NULL, "can't allocate id "
4180 "for split Q/RSS subflow");
4181 /* Internal SET_TAG action to set flow ID. */
4182 *set_tag = (struct mlx5_rte_flow_action_set_tag){
4185 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
4189 /* Construct new actions array. */
4190 /* Replace QUEUE/RSS action. */
4191 split_actions[qrss_idx] = (struct rte_flow_action){
4192 .type = (enum rte_flow_action_type)
4193 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4197 /* JUMP action to jump to mreg copy table (CP_TBL). */
4198 jump = (void *)(set_tag + 1);
4199 *jump = (struct rte_flow_action_jump){
4200 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4202 split_actions[actions_n - 2] = (struct rte_flow_action){
4203 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4206 split_actions[actions_n - 1] = (struct rte_flow_action){
4207 .type = RTE_FLOW_ACTION_TYPE_END,
4213 * Extend the given action list for Tx metadata copy.
4215 * Copy the given action list to the ext_actions and add flow metadata register
4216 * copy action in order to copy reg_a set by WQE to reg_c[0].
4218 * @param[out] ext_actions
4219 * Pointer to the extended action list.
4220 * @param[in] actions
4221 * Pointer to the list of actions.
4222 * @param[in] actions_n
4223 * Number of actions in the list.
4225 * Perform verbose error reporting if not NULL.
4226 * @param[in] encap_idx
4227 * The encap action inndex.
4230 * 0 on success, negative value otherwise
4233 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
4234 struct rte_flow_action *ext_actions,
4235 const struct rte_flow_action *actions,
4236 int actions_n, struct rte_flow_error *error,
4239 struct mlx5_flow_action_copy_mreg *cp_mreg =
4240 (struct mlx5_flow_action_copy_mreg *)
4241 (ext_actions + actions_n + 1);
4244 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4248 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
4253 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
4254 if (encap_idx == actions_n - 1) {
4255 ext_actions[actions_n - 1] = (struct rte_flow_action){
4256 .type = (enum rte_flow_action_type)
4257 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4260 ext_actions[actions_n] = (struct rte_flow_action){
4261 .type = RTE_FLOW_ACTION_TYPE_END,
4264 ext_actions[encap_idx] = (struct rte_flow_action){
4265 .type = (enum rte_flow_action_type)
4266 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4269 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
4270 sizeof(*ext_actions) * (actions_n - encap_idx));
4276 * Check the match action from the action list.
4278 * @param[in] actions
4279 * Pointer to the list of actions.
4281 * Flow rule attributes.
4283 * The action to be check if exist.
4284 * @param[out] match_action_pos
4285 * Pointer to the position of the matched action if exists, otherwise is -1.
4286 * @param[out] qrss_action_pos
4287 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
4290 * > 0 the total number of actions.
4291 * 0 if not found match action in action list.
4294 flow_check_match_action(const struct rte_flow_action actions[],
4295 const struct rte_flow_attr *attr,
4296 enum rte_flow_action_type action,
4297 int *match_action_pos, int *qrss_action_pos)
4299 const struct rte_flow_action_sample *sample;
4306 *match_action_pos = -1;
4307 *qrss_action_pos = -1;
4308 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4309 if (actions->type == action) {
4311 *match_action_pos = actions_n;
4313 if (actions->type == RTE_FLOW_ACTION_TYPE_QUEUE ||
4314 actions->type == RTE_FLOW_ACTION_TYPE_RSS)
4315 *qrss_action_pos = actions_n;
4316 if (actions->type == RTE_FLOW_ACTION_TYPE_JUMP)
4318 if (actions->type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
4319 sample = actions->conf;
4320 ratio = sample->ratio;
4321 sub_type = ((const struct rte_flow_action *)
4322 (sample->actions))->type;
4326 if (flag && action == RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) {
4328 /* JUMP Action not support for Mirroring;
4329 * Mirroring support multi-destination;
4331 if (!jump_flag && sub_type != RTE_FLOW_ACTION_TYPE_END)
4335 /* Count RTE_FLOW_ACTION_TYPE_END. */
4336 return flag ? actions_n + 1 : 0;
4339 #define SAMPLE_SUFFIX_ITEM 2
4342 * Split the sample flow.
4344 * As sample flow will split to two sub flow, sample flow with
4345 * sample action, the other actions will move to new suffix flow.
4347 * Also add unique tag id with tag action in the sample flow,
4348 * the same tag id will be as match in the suffix flow.
4351 * Pointer to Ethernet device.
4353 * FDB egress flow flag.
4354 * @param[out] sfx_items
4355 * Suffix flow match items (list terminated by the END pattern item).
4356 * @param[in] actions
4357 * Associated actions (list terminated by the END action).
4358 * @param[out] actions_sfx
4359 * Suffix flow actions.
4360 * @param[out] actions_pre
4361 * Prefix flow actions.
4362 * @param[in] actions_n
4363 * The total number of actions.
4364 * @param[in] sample_action_pos
4365 * The sample action position.
4366 * @param[in] qrss_action_pos
4367 * The Queue/RSS action position.
4369 * Perform verbose error reporting if not NULL.
4372 * 0 on success, or unique flow_id, a negative errno value
4373 * otherwise and rte_errno is set.
4376 flow_sample_split_prep(struct rte_eth_dev *dev,
4378 struct rte_flow_item sfx_items[],
4379 const struct rte_flow_action actions[],
4380 struct rte_flow_action actions_sfx[],
4381 struct rte_flow_action actions_pre[],
4383 int sample_action_pos,
4384 int qrss_action_pos,
4385 struct rte_flow_error *error)
4387 struct mlx5_rte_flow_action_set_tag *set_tag;
4388 struct mlx5_rte_flow_item_tag *tag_spec;
4389 struct mlx5_rte_flow_item_tag *tag_mask;
4390 uint32_t tag_id = 0;
4394 if (sample_action_pos < 0)
4395 return rte_flow_error_set(error, EINVAL,
4396 RTE_FLOW_ERROR_TYPE_ACTION,
4397 NULL, "invalid position of sample "
4400 /* Prepare the prefix tag action. */
4401 set_tag = (void *)(actions_pre + actions_n + 1);
4402 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
4406 tag_id = flow_qrss_get_id(dev);
4407 set_tag->data = tag_id;
4408 /* Prepare the suffix subflow items. */
4409 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
4410 tag_spec->data = tag_id;
4411 tag_spec->id = set_tag->id;
4412 tag_mask = tag_spec + 1;
4413 tag_mask->data = UINT32_MAX;
4414 sfx_items[0] = (struct rte_flow_item){
4415 .type = (enum rte_flow_item_type)
4416 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4421 sfx_items[1] = (struct rte_flow_item){
4422 .type = (enum rte_flow_item_type)
4423 RTE_FLOW_ITEM_TYPE_END,
4426 /* Prepare the actions for prefix and suffix flow. */
4427 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
4428 index = qrss_action_pos;
4429 /* Put the preceding the Queue/RSS action into prefix flow. */
4431 memcpy(actions_pre, actions,
4432 sizeof(struct rte_flow_action) * index);
4433 /* Put others preceding the sample action into prefix flow. */
4434 if (sample_action_pos > index + 1)
4435 memcpy(actions_pre + index, actions + index + 1,
4436 sizeof(struct rte_flow_action) *
4437 (sample_action_pos - index - 1));
4438 index = sample_action_pos - 1;
4439 /* Put Queue/RSS action into Suffix flow. */
4440 memcpy(actions_sfx, actions + qrss_action_pos,
4441 sizeof(struct rte_flow_action));
4444 index = sample_action_pos;
4446 memcpy(actions_pre, actions,
4447 sizeof(struct rte_flow_action) * index);
4449 /* Add the extra tag action for NIC-RX and E-Switch ingress. */
4451 actions_pre[index++] =
4452 (struct rte_flow_action){
4453 .type = (enum rte_flow_action_type)
4454 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4458 memcpy(actions_pre + index, actions + sample_action_pos,
4459 sizeof(struct rte_flow_action));
4461 actions_pre[index] = (struct rte_flow_action){
4462 .type = (enum rte_flow_action_type)
4463 RTE_FLOW_ACTION_TYPE_END,
4465 /* Put the actions after sample into Suffix flow. */
4466 memcpy(actions_sfx, actions + sample_action_pos + 1,
4467 sizeof(struct rte_flow_action) *
4468 (actions_n - sample_action_pos - 1));
4473 * The splitting for metadata feature.
4475 * - Q/RSS action on NIC Rx should be split in order to pass by
4476 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4477 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4479 * - All the actions on NIC Tx should have a mreg copy action to
4480 * copy reg_a from WQE to reg_c[0].
4483 * Pointer to Ethernet device.
4485 * Parent flow structure pointer.
4486 * @param[in] prefix_layers
4487 * Prefix flow layer flags.
4488 * @param[in] prefix_mark
4489 * Prefix subflow mark flag, may be 0.
4491 * Flow rule attributes.
4493 * Pattern specification (list terminated by the END pattern item).
4494 * @param[in] actions
4495 * Associated actions (list terminated by the END action).
4496 * @param[in] external
4497 * This flow rule is created by request external to PMD.
4498 * @param[in] flow_idx
4499 * This memory pool index to the flow.
4501 * Perform verbose error reporting if not NULL.
4503 * 0 on success, negative value otherwise
4506 flow_create_split_metadata(struct rte_eth_dev *dev,
4507 struct rte_flow *flow,
4508 uint64_t prefix_layers,
4509 uint32_t prefix_mark,
4510 const struct rte_flow_attr *attr,
4511 const struct rte_flow_item items[],
4512 const struct rte_flow_action actions[],
4513 bool external, uint32_t flow_idx,
4514 struct rte_flow_error *error)
4516 struct mlx5_priv *priv = dev->data->dev_private;
4517 struct mlx5_dev_config *config = &priv->config;
4518 const struct rte_flow_action *qrss = NULL;
4519 struct rte_flow_action *ext_actions = NULL;
4520 struct mlx5_flow *dev_flow = NULL;
4521 uint32_t qrss_id = 0;
4528 /* Check whether extensive metadata feature is engaged. */
4529 if (!config->dv_flow_en ||
4530 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4531 !mlx5_flow_ext_mreg_supported(dev))
4532 return flow_create_split_inner(dev, flow, NULL, prefix_layers,
4533 prefix_mark, attr, items,
4534 actions, external, flow_idx,
4536 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
4539 /* Exclude hairpin flows from splitting. */
4540 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
4541 const struct rte_flow_action_queue *queue;
4544 if (mlx5_rxq_get_type(dev, queue->index) ==
4545 MLX5_RXQ_TYPE_HAIRPIN)
4547 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
4548 const struct rte_flow_action_rss *rss;
4551 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
4552 MLX5_RXQ_TYPE_HAIRPIN)
4557 /* Check if it is in meter suffix table. */
4558 mtr_sfx = attr->group == (attr->transfer ?
4559 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4560 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
4562 * Q/RSS action on NIC Rx should be split in order to pass by
4563 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4564 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4566 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
4567 sizeof(struct rte_flow_action_set_tag) +
4568 sizeof(struct rte_flow_action_jump);
4569 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
4572 return rte_flow_error_set(error, ENOMEM,
4573 RTE_FLOW_ERROR_TYPE_ACTION,
4574 NULL, "no memory to split "
4577 * If we are the suffix flow of meter, tag already exist.
4578 * Set the tag action to void.
4581 ext_actions[qrss - actions].type =
4582 RTE_FLOW_ACTION_TYPE_VOID;
4584 ext_actions[qrss - actions].type =
4585 (enum rte_flow_action_type)
4586 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4588 * Create the new actions list with removed Q/RSS action
4589 * and appended set tag and jump to register copy table
4590 * (RX_CP_TBL). We should preallocate unique tag ID here
4591 * in advance, because it is needed for set tag action.
4593 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
4594 qrss, actions_n, error);
4595 if (!mtr_sfx && !qrss_id) {
4599 } else if (attr->egress && !attr->transfer) {
4601 * All the actions on NIC Tx should have a metadata register
4602 * copy action to copy reg_a from WQE to reg_c[meta]
4604 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
4605 sizeof(struct mlx5_flow_action_copy_mreg);
4606 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
4609 return rte_flow_error_set(error, ENOMEM,
4610 RTE_FLOW_ERROR_TYPE_ACTION,
4611 NULL, "no memory to split "
4613 /* Create the action list appended with copy register. */
4614 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
4615 actions_n, error, encap_idx);
4619 /* Add the unmodified original or prefix subflow. */
4620 ret = flow_create_split_inner(dev, flow, &dev_flow, prefix_layers,
4622 items, ext_actions ? ext_actions :
4623 actions, external, flow_idx, error);
4626 MLX5_ASSERT(dev_flow);
4628 const struct rte_flow_attr q_attr = {
4629 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4632 /* Internal PMD action to set register. */
4633 struct mlx5_rte_flow_item_tag q_tag_spec = {
4637 struct rte_flow_item q_items[] = {
4639 .type = (enum rte_flow_item_type)
4640 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4641 .spec = &q_tag_spec,
4646 .type = RTE_FLOW_ITEM_TYPE_END,
4649 struct rte_flow_action q_actions[] = {
4655 .type = RTE_FLOW_ACTION_TYPE_END,
4658 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
4661 * Configure the tag item only if there is no meter subflow.
4662 * Since tag is already marked in the meter suffix subflow
4663 * we can just use the meter suffix items as is.
4666 /* Not meter subflow. */
4667 MLX5_ASSERT(!mtr_sfx);
4669 * Put unique id in prefix flow due to it is destroyed
4670 * after suffix flow and id will be freed after there
4671 * is no actual flows with this id and identifier
4672 * reallocation becomes possible (for example, for
4673 * other flows in other threads).
4675 dev_flow->handle->split_flow_id = qrss_id;
4676 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
4680 q_tag_spec.id = ret;
4683 /* Add suffix subflow to execute Q/RSS. */
4684 ret = flow_create_split_inner(dev, flow, &dev_flow, layers, 0,
4685 &q_attr, mtr_sfx ? items :
4687 external, flow_idx, error);
4690 /* qrss ID should be freed if failed. */
4692 MLX5_ASSERT(dev_flow);
4697 * We do not destroy the partially created sub_flows in case of error.
4698 * These ones are included into parent flow list and will be destroyed
4699 * by flow_drv_destroy.
4701 flow_qrss_free_id(dev, qrss_id);
4702 mlx5_free(ext_actions);
4707 * The splitting for meter feature.
4709 * - The meter flow will be split to two flows as prefix and
4710 * suffix flow. The packets make sense only it pass the prefix
4713 * - Reg_C_5 is used for the packet to match betweend prefix and
4717 * Pointer to Ethernet device.
4719 * Parent flow structure pointer.
4720 * @param[in] prefix_layers
4721 * Prefix subflow layers, may be 0.
4722 * @param[in] prefix_mark
4723 * Prefix subflow mark flag, may be 0.
4725 * Flow rule attributes.
4727 * Pattern specification (list terminated by the END pattern item).
4728 * @param[in] actions
4729 * Associated actions (list terminated by the END action).
4730 * @param[in] external
4731 * This flow rule is created by request external to PMD.
4732 * @param[in] flow_idx
4733 * This memory pool index to the flow.
4735 * Perform verbose error reporting if not NULL.
4737 * 0 on success, negative value otherwise
4740 flow_create_split_meter(struct rte_eth_dev *dev,
4741 struct rte_flow *flow,
4742 uint64_t prefix_layers,
4743 uint32_t prefix_mark,
4744 const struct rte_flow_attr *attr,
4745 const struct rte_flow_item items[],
4746 const struct rte_flow_action actions[],
4747 bool external, uint32_t flow_idx,
4748 struct rte_flow_error *error)
4750 struct mlx5_priv *priv = dev->data->dev_private;
4751 struct rte_flow_action *sfx_actions = NULL;
4752 struct rte_flow_action *pre_actions = NULL;
4753 struct rte_flow_item *sfx_items = NULL;
4754 struct mlx5_flow *dev_flow = NULL;
4755 struct rte_flow_attr sfx_attr = *attr;
4757 uint32_t mtr_tag_id = 0;
4764 actions_n = flow_check_meter_action(actions, &mtr);
4766 /* The five prefix actions: meter, decap, encap, tag, end. */
4767 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
4768 sizeof(struct mlx5_rte_flow_action_set_tag);
4769 /* tag, vlan, port id, end. */
4770 #define METER_SUFFIX_ITEM 4
4771 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
4772 sizeof(struct mlx5_rte_flow_item_tag) * 2;
4773 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
4776 return rte_flow_error_set(error, ENOMEM,
4777 RTE_FLOW_ERROR_TYPE_ACTION,
4778 NULL, "no memory to split "
4780 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4782 pre_actions = sfx_actions + actions_n;
4783 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
4784 actions, sfx_actions,
4790 /* Add the prefix subflow. */
4791 ret = flow_create_split_inner(dev, flow, &dev_flow,
4794 pre_actions, external,
4800 dev_flow->handle->split_flow_id = mtr_tag_id;
4801 /* Setting the sfx group atrr. */
4802 sfx_attr.group = sfx_attr.transfer ?
4803 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4804 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4806 /* Add the prefix subflow. */
4807 ret = flow_create_split_metadata(dev, flow, dev_flow ?
4808 flow_get_prefix_layer_flags(dev_flow) :
4809 prefix_layers, dev_flow ?
4810 dev_flow->handle->mark : prefix_mark,
4811 &sfx_attr, sfx_items ?
4813 sfx_actions ? sfx_actions : actions,
4814 external, flow_idx, error);
4817 mlx5_free(sfx_actions);
4822 * The splitting for sample feature.
4824 * Once Sample action is detected in the action list, the flow actions should
4825 * be split into prefix sub flow and suffix sub flow.
4827 * The original items remain in the prefix sub flow, all actions preceding the
4828 * sample action and the sample action itself will be copied to the prefix
4829 * sub flow, the actions following the sample action will be copied to the
4830 * suffix sub flow, Queue action always be located in the suffix sub flow.
4832 * In order to make the packet from prefix sub flow matches with suffix sub
4833 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
4834 * flow uses tag item with the unique flow id.
4837 * Pointer to Ethernet device.
4839 * Parent flow structure pointer.
4841 * Flow rule attributes.
4843 * Pattern specification (list terminated by the END pattern item).
4844 * @param[in] actions
4845 * Associated actions (list terminated by the END action).
4846 * @param[in] external
4847 * This flow rule is created by request external to PMD.
4848 * @param[in] flow_idx
4849 * This memory pool index to the flow.
4851 * Perform verbose error reporting if not NULL.
4853 * 0 on success, negative value otherwise
4856 flow_create_split_sample(struct rte_eth_dev *dev,
4857 struct rte_flow *flow,
4858 const struct rte_flow_attr *attr,
4859 const struct rte_flow_item items[],
4860 const struct rte_flow_action actions[],
4861 bool external, uint32_t flow_idx,
4862 struct rte_flow_error *error)
4864 struct mlx5_priv *priv = dev->data->dev_private;
4865 struct rte_flow_action *sfx_actions = NULL;
4866 struct rte_flow_action *pre_actions = NULL;
4867 struct rte_flow_item *sfx_items = NULL;
4868 struct mlx5_flow *dev_flow = NULL;
4869 struct rte_flow_attr sfx_attr = *attr;
4870 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4871 struct mlx5_flow_dv_sample_resource *sample_res;
4872 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
4873 struct mlx5_flow_tbl_resource *sfx_tbl;
4874 union mlx5_flow_tbl_key sfx_table_key;
4878 uint32_t fdb_tx = 0;
4881 int sample_action_pos;
4882 int qrss_action_pos;
4885 if (priv->sampler_en)
4886 actions_n = flow_check_match_action(actions, attr,
4887 RTE_FLOW_ACTION_TYPE_SAMPLE,
4888 &sample_action_pos, &qrss_action_pos);
4890 /* The prefix actions must includes sample, tag, end. */
4891 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
4892 + sizeof(struct mlx5_rte_flow_action_set_tag);
4893 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
4894 sizeof(struct mlx5_rte_flow_item_tag) * 2;
4895 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
4896 item_size), 0, SOCKET_ID_ANY);
4898 return rte_flow_error_set(error, ENOMEM,
4899 RTE_FLOW_ERROR_TYPE_ACTION,
4900 NULL, "no memory to split "
4902 /* The representor_id is -1 for uplink. */
4903 fdb_tx = (attr->transfer && priv->representor_id != -1);
4905 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
4907 pre_actions = sfx_actions + actions_n;
4908 tag_id = flow_sample_split_prep(dev, fdb_tx, sfx_items,
4909 actions, sfx_actions,
4910 pre_actions, actions_n,
4912 qrss_action_pos, error);
4913 if (tag_id < 0 || (!fdb_tx && !tag_id)) {
4917 /* Add the prefix subflow. */
4918 ret = flow_create_split_inner(dev, flow, &dev_flow, 0, 0, attr,
4919 items, pre_actions, external,
4925 dev_flow->handle->split_flow_id = tag_id;
4926 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4927 /* Set the sfx group attr. */
4928 sample_res = (struct mlx5_flow_dv_sample_resource *)
4929 dev_flow->dv.sample_res;
4930 sfx_tbl = (struct mlx5_flow_tbl_resource *)
4931 sample_res->normal_path_tbl;
4932 sfx_tbl_data = container_of(sfx_tbl,
4933 struct mlx5_flow_tbl_data_entry, tbl);
4934 sfx_table_key.v64 = sfx_tbl_data->entry.key;
4935 sfx_attr.group = sfx_attr.transfer ?
4936 (sfx_table_key.table_id - 1) :
4937 sfx_table_key.table_id;
4940 /* Add the suffix subflow. */
4941 ret = flow_create_split_meter(dev, flow, dev_flow ?
4942 flow_get_prefix_layer_flags(dev_flow) : 0,
4943 dev_flow ? dev_flow->handle->mark : 0,
4944 &sfx_attr, sfx_items ? sfx_items : items,
4945 sfx_actions ? sfx_actions : actions,
4946 external, flow_idx, error);
4949 mlx5_free(sfx_actions);
4954 * Split the flow to subflow set. The splitters might be linked
4955 * in the chain, like this:
4956 * flow_create_split_outer() calls:
4957 * flow_create_split_meter() calls:
4958 * flow_create_split_metadata(meter_subflow_0) calls:
4959 * flow_create_split_inner(metadata_subflow_0)
4960 * flow_create_split_inner(metadata_subflow_1)
4961 * flow_create_split_inner(metadata_subflow_2)
4962 * flow_create_split_metadata(meter_subflow_1) calls:
4963 * flow_create_split_inner(metadata_subflow_0)
4964 * flow_create_split_inner(metadata_subflow_1)
4965 * flow_create_split_inner(metadata_subflow_2)
4967 * This provide flexible way to add new levels of flow splitting.
4968 * The all of successfully created subflows are included to the
4969 * parent flow dev_flow list.
4972 * Pointer to Ethernet device.
4974 * Parent flow structure pointer.
4976 * Flow rule attributes.
4978 * Pattern specification (list terminated by the END pattern item).
4979 * @param[in] actions
4980 * Associated actions (list terminated by the END action).
4981 * @param[in] external
4982 * This flow rule is created by request external to PMD.
4983 * @param[in] flow_idx
4984 * This memory pool index to the flow.
4986 * Perform verbose error reporting if not NULL.
4988 * 0 on success, negative value otherwise
4991 flow_create_split_outer(struct rte_eth_dev *dev,
4992 struct rte_flow *flow,
4993 const struct rte_flow_attr *attr,
4994 const struct rte_flow_item items[],
4995 const struct rte_flow_action actions[],
4996 bool external, uint32_t flow_idx,
4997 struct rte_flow_error *error)
5001 ret = flow_create_split_sample(dev, flow, attr, items,
5002 actions, external, flow_idx, error);
5003 MLX5_ASSERT(ret <= 0);
5008 * Create a flow and add it to @p list.
5011 * Pointer to Ethernet device.
5013 * Pointer to a TAILQ flow list. If this parameter NULL,
5014 * no list insertion occurred, flow is just created,
5015 * this is caller's responsibility to track the
5018 * Flow rule attributes.
5020 * Pattern specification (list terminated by the END pattern item).
5021 * @param[in] actions
5022 * Associated actions (list terminated by the END action).
5023 * @param[in] external
5024 * This flow rule is created by request external to PMD.
5026 * Perform verbose error reporting if not NULL.
5029 * A flow index on success, 0 otherwise and rte_errno is set.
5032 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
5033 const struct rte_flow_attr *attr,
5034 const struct rte_flow_item items[],
5035 const struct rte_flow_action actions[],
5036 bool external, struct rte_flow_error *error)
5038 struct mlx5_priv *priv = dev->data->dev_private;
5039 struct rte_flow *flow = NULL;
5040 struct mlx5_flow *dev_flow;
5041 const struct rte_flow_action_rss *rss;
5043 struct mlx5_flow_expand_rss buf;
5044 uint8_t buffer[2048];
5047 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5048 uint8_t buffer[2048];
5051 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5052 uint8_t buffer[2048];
5053 } actions_hairpin_tx;
5055 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
5056 uint8_t buffer[2048];
5058 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
5059 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
5060 priv->rss_desc)[!!priv->flow_idx];
5061 const struct rte_flow_action *p_actions_rx = actions;
5065 uint32_t hairpin_id = 0;
5066 struct rte_flow_attr attr_tx = { .priority = 0 };
5067 struct rte_flow_attr attr_factor = {0};
5070 memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
5072 attr_factor.group *= MLX5_FLOW_TABLE_FACTOR;
5073 hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
5074 ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
5075 external, hairpin_flow, error);
5078 if (hairpin_flow > 0) {
5079 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
5083 flow_hairpin_split(dev, actions, actions_rx.actions,
5084 actions_hairpin_tx.actions, items_tx.items,
5086 p_actions_rx = actions_rx.actions;
5088 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
5091 goto error_before_flow;
5093 flow->drv_type = flow_get_drv_type(dev, &attr_factor);
5094 if (hairpin_id != 0)
5095 flow->hairpin_flow_id = hairpin_id;
5096 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
5097 flow->drv_type < MLX5_FLOW_TYPE_MAX);
5098 memset(rss_desc, 0, sizeof(*rss_desc));
5099 rss = flow_get_rss_action(p_actions_rx);
5102 * The following information is required by
5103 * mlx5_flow_hashfields_adjust() in advance.
5105 rss_desc->level = rss->level;
5106 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
5107 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
5109 flow->dev_handles = 0;
5110 if (rss && rss->types) {
5111 unsigned int graph_root;
5113 graph_root = find_graph_root(items, rss->level);
5114 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
5116 mlx5_support_expansion, graph_root);
5117 MLX5_ASSERT(ret > 0 &&
5118 (unsigned int)ret < sizeof(expand_buffer.buffer));
5121 buf->entry[0].pattern = (void *)(uintptr_t)items;
5124 * Record the start index when there is a nested call. All sub-flows
5125 * need to be translated before another calling.
5126 * No need to use ping-pong buffer to save memory here.
5128 if (priv->flow_idx) {
5129 MLX5_ASSERT(!priv->flow_nested_idx);
5130 priv->flow_nested_idx = priv->flow_idx;
5132 for (i = 0; i < buf->entries; ++i) {
5134 * The splitter may create multiple dev_flows,
5135 * depending on configuration. In the simplest
5136 * case it just creates unmodified original flow.
5138 ret = flow_create_split_outer(dev, flow, &attr_factor,
5139 buf->entry[i].pattern,
5140 p_actions_rx, external, idx,
5145 /* Create the tx flow. */
5147 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
5148 attr_tx.ingress = 0;
5150 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
5151 actions_hairpin_tx.actions,
5155 dev_flow->flow = flow;
5156 dev_flow->external = 0;
5157 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5158 dev_flow->handle, next);
5159 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
5161 actions_hairpin_tx.actions, error);
5166 * Update the metadata register copy table. If extensive
5167 * metadata feature is enabled and registers are supported
5168 * we might create the extra rte_flow for each unique
5169 * MARK/FLAG action ID.
5171 * The table is updated for ingress Flows only, because
5172 * the egress Flows belong to the different device and
5173 * copy table should be updated in peer NIC Rx domain.
5175 if (attr_factor.ingress &&
5176 (external || attr_factor.group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
5177 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
5182 * If the flow is external (from application) OR device is started, then
5183 * the flow will be applied immediately.
5185 if (external || dev->data->dev_started) {
5186 ret = flow_drv_apply(dev, flow, error);
5191 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
5193 flow_rxq_flags_set(dev, flow);
5194 /* Nested flow creation index recovery. */
5195 priv->flow_idx = priv->flow_nested_idx;
5196 if (priv->flow_nested_idx)
5197 priv->flow_nested_idx = 0;
5201 ret = rte_errno; /* Save rte_errno before cleanup. */
5202 flow_mreg_del_copy_action(dev, flow);
5203 flow_drv_destroy(dev, flow);
5204 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
5205 rte_errno = ret; /* Restore rte_errno. */
5209 mlx5_flow_id_release(priv->sh->flow_id_pool,
5212 priv->flow_idx = priv->flow_nested_idx;
5213 if (priv->flow_nested_idx)
5214 priv->flow_nested_idx = 0;
5219 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
5220 * incoming packets to table 1.
5222 * Other flow rules, requested for group n, will be created in
5223 * e-switch table n+1.
5224 * Jump action to e-switch group n will be created to group n+1.
5226 * Used when working in switchdev mode, to utilise advantages of table 1
5230 * Pointer to Ethernet device.
5233 * Pointer to flow on success, NULL otherwise and rte_errno is set.
5236 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
5238 const struct rte_flow_attr attr = {
5245 const struct rte_flow_item pattern = {
5246 .type = RTE_FLOW_ITEM_TYPE_END,
5248 struct rte_flow_action_jump jump = {
5251 const struct rte_flow_action actions[] = {
5253 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5257 .type = RTE_FLOW_ACTION_TYPE_END,
5260 struct mlx5_priv *priv = dev->data->dev_private;
5261 struct rte_flow_error error;
5263 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
5265 actions, false, &error);
5269 * Validate a flow supported by the NIC.
5271 * @see rte_flow_validate()
5275 mlx5_flow_validate(struct rte_eth_dev *dev,
5276 const struct rte_flow_attr *attr,
5277 const struct rte_flow_item items[],
5278 const struct rte_flow_action actions[],
5279 struct rte_flow_error *error)
5283 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5284 return flow_drv_validate(dev, attr, items, actions,
5285 true, hairpin_flow, error);
5291 * @see rte_flow_create()
5295 mlx5_flow_create(struct rte_eth_dev *dev,
5296 const struct rte_flow_attr *attr,
5297 const struct rte_flow_item items[],
5298 const struct rte_flow_action actions[],
5299 struct rte_flow_error *error)
5301 struct mlx5_priv *priv = dev->data->dev_private;
5304 * If the device is not started yet, it is not allowed to created a
5305 * flow from application. PMD default flows and traffic control flows
5308 if (unlikely(!dev->data->dev_started)) {
5309 DRV_LOG(DEBUG, "port %u is not started when "
5310 "inserting a flow", dev->data->port_id);
5311 rte_flow_error_set(error, ENODEV,
5312 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5314 "port not started");
5317 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
5318 attr, items, actions, true, error);
5322 * Destroy a flow in a list.
5325 * Pointer to Ethernet device.
5327 * Pointer to the Indexed flow list. If this parameter NULL,
5328 * there is no flow removal from the list. Be noted that as
5329 * flow is add to the indexed list, memory of the indexed
5330 * list points to maybe changed as flow destroyed.
5331 * @param[in] flow_idx
5332 * Index of flow to destroy.
5335 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
5338 struct mlx5_priv *priv = dev->data->dev_private;
5339 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5340 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5341 [MLX5_IPOOL_RTE_FLOW], flow_idx);
5346 * Update RX queue flags only if port is started, otherwise it is
5349 if (dev->data->dev_started)
5350 flow_rxq_flags_trim(dev, flow);
5351 if (flow->hairpin_flow_id)
5352 mlx5_flow_id_release(priv->sh->flow_id_pool,
5353 flow->hairpin_flow_id);
5354 flow_drv_destroy(dev, flow);
5356 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
5357 flow_idx, flow, next);
5358 flow_mreg_del_copy_action(dev, flow);
5360 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
5361 if (priv_fdir_flow->rix_flow == flow_idx)
5364 if (priv_fdir_flow) {
5365 LIST_REMOVE(priv_fdir_flow, next);
5366 mlx5_free(priv_fdir_flow->fdir);
5367 mlx5_free(priv_fdir_flow);
5370 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5374 * Destroy all flows.
5377 * Pointer to Ethernet device.
5379 * Pointer to the Indexed flow list.
5381 * If flushing is called avtively.
5384 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
5386 uint32_t num_flushed = 0;
5389 flow_list_destroy(dev, list, *list);
5393 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
5394 dev->data->port_id, num_flushed);
5402 * Pointer to Ethernet device.
5404 * Pointer to the Indexed flow list.
5407 mlx5_flow_stop(struct rte_eth_dev *dev, uint32_t *list)
5409 struct mlx5_priv *priv = dev->data->dev_private;
5410 struct rte_flow *flow = NULL;
5413 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
5415 flow_drv_remove(dev, flow);
5416 flow_mreg_stop_copy_action(dev, flow);
5418 flow_mreg_del_default_copy_action(dev);
5419 flow_rxq_flags_clear(dev);
5426 * Pointer to Ethernet device.
5428 * Pointer to the Indexed flow list.
5431 * 0 on success, a negative errno value otherwise and rte_errno is set.
5434 mlx5_flow_start(struct rte_eth_dev *dev, uint32_t *list)
5436 struct mlx5_priv *priv = dev->data->dev_private;
5437 struct rte_flow *flow = NULL;
5438 struct rte_flow_error error;
5442 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
5443 ret = flow_mreg_add_default_copy_action(dev, &error);
5446 /* Apply Flows created by application. */
5447 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
5449 ret = flow_mreg_start_copy_action(dev, flow);
5452 ret = flow_drv_apply(dev, flow, &error);
5455 flow_rxq_flags_set(dev, flow);
5459 ret = rte_errno; /* Save rte_errno before cleanup. */
5460 mlx5_flow_stop(dev, list);
5461 rte_errno = ret; /* Restore rte_errno. */
5466 * Stop all default actions for flows.
5469 * Pointer to Ethernet device.
5472 mlx5_flow_stop_default(struct rte_eth_dev *dev)
5474 flow_mreg_del_default_copy_action(dev);
5475 flow_rxq_flags_clear(dev);
5479 * Start all default actions for flows.
5482 * Pointer to Ethernet device.
5484 * 0 on success, a negative errno value otherwise and rte_errno is set.
5487 mlx5_flow_start_default(struct rte_eth_dev *dev)
5489 struct rte_flow_error error;
5491 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
5492 return flow_mreg_add_default_copy_action(dev, &error);
5496 * Allocate intermediate resources for flow creation.
5499 * Pointer to Ethernet device.
5502 mlx5_flow_alloc_intermediate(struct rte_eth_dev *dev)
5504 struct mlx5_priv *priv = dev->data->dev_private;
5506 if (!priv->inter_flows) {
5507 priv->inter_flows = mlx5_malloc(MLX5_MEM_ZERO,
5508 MLX5_NUM_MAX_DEV_FLOWS *
5509 sizeof(struct mlx5_flow) +
5510 (sizeof(struct mlx5_flow_rss_desc) +
5511 sizeof(uint16_t) * UINT16_MAX) * 2, 0,
5513 if (!priv->inter_flows) {
5514 DRV_LOG(ERR, "can't allocate intermediate memory.");
5518 priv->rss_desc = &((struct mlx5_flow *)priv->inter_flows)
5519 [MLX5_NUM_MAX_DEV_FLOWS];
5520 /* Reset the index. */
5522 priv->flow_nested_idx = 0;
5526 * Free intermediate resources for flows.
5529 * Pointer to Ethernet device.
5532 mlx5_flow_free_intermediate(struct rte_eth_dev *dev)
5534 struct mlx5_priv *priv = dev->data->dev_private;
5536 mlx5_free(priv->inter_flows);
5537 priv->inter_flows = NULL;
5541 * Verify the flow list is empty
5544 * Pointer to Ethernet device.
5546 * @return the number of flows not released.
5549 mlx5_flow_verify(struct rte_eth_dev *dev)
5551 struct mlx5_priv *priv = dev->data->dev_private;
5552 struct rte_flow *flow;
5556 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
5558 DRV_LOG(DEBUG, "port %u flow %p still referenced",
5559 dev->data->port_id, (void *)flow);
5566 * Enable default hairpin egress flow.
5569 * Pointer to Ethernet device.
5574 * 0 on success, a negative errno value otherwise and rte_errno is set.
5577 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
5580 struct mlx5_priv *priv = dev->data->dev_private;
5581 const struct rte_flow_attr attr = {
5585 struct mlx5_rte_flow_item_tx_queue queue_spec = {
5588 struct mlx5_rte_flow_item_tx_queue queue_mask = {
5589 .queue = UINT32_MAX,
5591 struct rte_flow_item items[] = {
5593 .type = (enum rte_flow_item_type)
5594 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
5595 .spec = &queue_spec,
5597 .mask = &queue_mask,
5600 .type = RTE_FLOW_ITEM_TYPE_END,
5603 struct rte_flow_action_jump jump = {
5604 .group = MLX5_HAIRPIN_TX_TABLE,
5606 struct rte_flow_action actions[2];
5608 struct rte_flow_error error;
5610 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
5611 actions[0].conf = &jump;
5612 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
5613 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
5614 &attr, items, actions, false, &error);
5617 "Failed to create ctrl flow: rte_errno(%d),"
5618 " type(%d), message(%s)",
5619 rte_errno, error.type,
5620 error.message ? error.message : " (no stated reason)");
5627 * Enable a control flow configured from the control plane.
5630 * Pointer to Ethernet device.
5632 * An Ethernet flow spec to apply.
5634 * An Ethernet flow mask to apply.
5636 * A VLAN flow spec to apply.
5638 * A VLAN flow mask to apply.
5641 * 0 on success, a negative errno value otherwise and rte_errno is set.
5644 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
5645 struct rte_flow_item_eth *eth_spec,
5646 struct rte_flow_item_eth *eth_mask,
5647 struct rte_flow_item_vlan *vlan_spec,
5648 struct rte_flow_item_vlan *vlan_mask)
5650 struct mlx5_priv *priv = dev->data->dev_private;
5651 const struct rte_flow_attr attr = {
5653 .priority = MLX5_FLOW_PRIO_RSVD,
5655 struct rte_flow_item items[] = {
5657 .type = RTE_FLOW_ITEM_TYPE_ETH,
5663 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
5664 RTE_FLOW_ITEM_TYPE_END,
5670 .type = RTE_FLOW_ITEM_TYPE_END,
5673 uint16_t queue[priv->reta_idx_n];
5674 struct rte_flow_action_rss action_rss = {
5675 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
5677 .types = priv->rss_conf.rss_hf,
5678 .key_len = priv->rss_conf.rss_key_len,
5679 .queue_num = priv->reta_idx_n,
5680 .key = priv->rss_conf.rss_key,
5683 struct rte_flow_action actions[] = {
5685 .type = RTE_FLOW_ACTION_TYPE_RSS,
5686 .conf = &action_rss,
5689 .type = RTE_FLOW_ACTION_TYPE_END,
5693 struct rte_flow_error error;
5696 if (!priv->reta_idx_n || !priv->rxqs_n) {
5699 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
5700 action_rss.types = 0;
5701 for (i = 0; i != priv->reta_idx_n; ++i)
5702 queue[i] = (*priv->reta_idx)[i];
5703 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
5704 &attr, items, actions, false, &error);
5711 * Enable a flow control configured from the control plane.
5714 * Pointer to Ethernet device.
5716 * An Ethernet flow spec to apply.
5718 * An Ethernet flow mask to apply.
5721 * 0 on success, a negative errno value otherwise and rte_errno is set.
5724 mlx5_ctrl_flow(struct rte_eth_dev *dev,
5725 struct rte_flow_item_eth *eth_spec,
5726 struct rte_flow_item_eth *eth_mask)
5728 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
5732 * Create default miss flow rule matching lacp traffic
5735 * Pointer to Ethernet device.
5737 * An Ethernet flow spec to apply.
5740 * 0 on success, a negative errno value otherwise and rte_errno is set.
5743 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
5745 struct mlx5_priv *priv = dev->data->dev_private;
5747 * The LACP matching is done by only using ether type since using
5748 * a multicast dst mac causes kernel to give low priority to this flow.
5750 static const struct rte_flow_item_eth lacp_spec = {
5751 .type = RTE_BE16(0x8809),
5753 static const struct rte_flow_item_eth lacp_mask = {
5756 const struct rte_flow_attr attr = {
5759 struct rte_flow_item items[] = {
5761 .type = RTE_FLOW_ITEM_TYPE_ETH,
5766 .type = RTE_FLOW_ITEM_TYPE_END,
5769 struct rte_flow_action actions[] = {
5771 .type = (enum rte_flow_action_type)
5772 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
5775 .type = RTE_FLOW_ACTION_TYPE_END,
5778 struct rte_flow_error error;
5779 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
5780 &attr, items, actions, false, &error);
5790 * @see rte_flow_destroy()
5794 mlx5_flow_destroy(struct rte_eth_dev *dev,
5795 struct rte_flow *flow,
5796 struct rte_flow_error *error __rte_unused)
5798 struct mlx5_priv *priv = dev->data->dev_private;
5800 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
5805 * Destroy all flows.
5807 * @see rte_flow_flush()
5811 mlx5_flow_flush(struct rte_eth_dev *dev,
5812 struct rte_flow_error *error __rte_unused)
5814 struct mlx5_priv *priv = dev->data->dev_private;
5816 mlx5_flow_list_flush(dev, &priv->flows, false);
5823 * @see rte_flow_isolate()
5827 mlx5_flow_isolate(struct rte_eth_dev *dev,
5829 struct rte_flow_error *error)
5831 struct mlx5_priv *priv = dev->data->dev_private;
5833 if (dev->data->dev_started) {
5834 rte_flow_error_set(error, EBUSY,
5835 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5837 "port must be stopped first");
5840 priv->isolated = !!enable;
5842 dev->dev_ops = &mlx5_os_dev_ops_isolate;
5844 dev->dev_ops = &mlx5_os_dev_ops;
5846 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
5847 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
5855 * @see rte_flow_query()
5859 flow_drv_query(struct rte_eth_dev *dev,
5861 const struct rte_flow_action *actions,
5863 struct rte_flow_error *error)
5865 struct mlx5_priv *priv = dev->data->dev_private;
5866 const struct mlx5_flow_driver_ops *fops;
5867 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5868 [MLX5_IPOOL_RTE_FLOW],
5870 enum mlx5_flow_drv_type ftype;
5873 return rte_flow_error_set(error, ENOENT,
5874 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5876 "invalid flow handle");
5878 ftype = flow->drv_type;
5879 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
5880 fops = flow_get_drv_ops(ftype);
5882 return fops->query(dev, flow, actions, data, error);
5888 * @see rte_flow_query()
5892 mlx5_flow_query(struct rte_eth_dev *dev,
5893 struct rte_flow *flow,
5894 const struct rte_flow_action *actions,
5896 struct rte_flow_error *error)
5900 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
5908 * Convert a flow director filter to a generic flow.
5911 * Pointer to Ethernet device.
5912 * @param fdir_filter
5913 * Flow director filter to add.
5915 * Generic flow parameters structure.
5918 * 0 on success, a negative errno value otherwise and rte_errno is set.
5921 flow_fdir_filter_convert(struct rte_eth_dev *dev,
5922 const struct rte_eth_fdir_filter *fdir_filter,
5923 struct mlx5_fdir *attributes)
5925 struct mlx5_priv *priv = dev->data->dev_private;
5926 const struct rte_eth_fdir_input *input = &fdir_filter->input;
5927 const struct rte_eth_fdir_masks *mask =
5928 &dev->data->dev_conf.fdir_conf.mask;
5930 /* Validate queue number. */
5931 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
5932 DRV_LOG(ERR, "port %u invalid queue number %d",
5933 dev->data->port_id, fdir_filter->action.rx_queue);
5937 attributes->attr.ingress = 1;
5938 attributes->items[0] = (struct rte_flow_item) {
5939 .type = RTE_FLOW_ITEM_TYPE_ETH,
5940 .spec = &attributes->l2,
5941 .mask = &attributes->l2_mask,
5943 switch (fdir_filter->action.behavior) {
5944 case RTE_ETH_FDIR_ACCEPT:
5945 attributes->actions[0] = (struct rte_flow_action){
5946 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
5947 .conf = &attributes->queue,
5950 case RTE_ETH_FDIR_REJECT:
5951 attributes->actions[0] = (struct rte_flow_action){
5952 .type = RTE_FLOW_ACTION_TYPE_DROP,
5956 DRV_LOG(ERR, "port %u invalid behavior %d",
5958 fdir_filter->action.behavior);
5959 rte_errno = ENOTSUP;
5962 attributes->queue.index = fdir_filter->action.rx_queue;
5964 switch (fdir_filter->input.flow_type) {
5965 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
5966 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
5967 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
5968 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
5969 .src_addr = input->flow.ip4_flow.src_ip,
5970 .dst_addr = input->flow.ip4_flow.dst_ip,
5971 .time_to_live = input->flow.ip4_flow.ttl,
5972 .type_of_service = input->flow.ip4_flow.tos,
5974 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
5975 .src_addr = mask->ipv4_mask.src_ip,
5976 .dst_addr = mask->ipv4_mask.dst_ip,
5977 .time_to_live = mask->ipv4_mask.ttl,
5978 .type_of_service = mask->ipv4_mask.tos,
5979 .next_proto_id = mask->ipv4_mask.proto,
5981 attributes->items[1] = (struct rte_flow_item){
5982 .type = RTE_FLOW_ITEM_TYPE_IPV4,
5983 .spec = &attributes->l3,
5984 .mask = &attributes->l3_mask,
5987 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
5988 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
5989 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
5990 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
5991 .hop_limits = input->flow.ipv6_flow.hop_limits,
5992 .proto = input->flow.ipv6_flow.proto,
5995 memcpy(attributes->l3.ipv6.hdr.src_addr,
5996 input->flow.ipv6_flow.src_ip,
5997 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
5998 memcpy(attributes->l3.ipv6.hdr.dst_addr,
5999 input->flow.ipv6_flow.dst_ip,
6000 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
6001 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
6002 mask->ipv6_mask.src_ip,
6003 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
6004 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
6005 mask->ipv6_mask.dst_ip,
6006 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
6007 attributes->items[1] = (struct rte_flow_item){
6008 .type = RTE_FLOW_ITEM_TYPE_IPV6,
6009 .spec = &attributes->l3,
6010 .mask = &attributes->l3_mask,
6014 DRV_LOG(ERR, "port %u invalid flow type%d",
6015 dev->data->port_id, fdir_filter->input.flow_type);
6016 rte_errno = ENOTSUP;
6020 switch (fdir_filter->input.flow_type) {
6021 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
6022 attributes->l4.udp.hdr = (struct rte_udp_hdr){
6023 .src_port = input->flow.udp4_flow.src_port,
6024 .dst_port = input->flow.udp4_flow.dst_port,
6026 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
6027 .src_port = mask->src_port_mask,
6028 .dst_port = mask->dst_port_mask,
6030 attributes->items[2] = (struct rte_flow_item){
6031 .type = RTE_FLOW_ITEM_TYPE_UDP,
6032 .spec = &attributes->l4,
6033 .mask = &attributes->l4_mask,
6036 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
6037 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
6038 .src_port = input->flow.tcp4_flow.src_port,
6039 .dst_port = input->flow.tcp4_flow.dst_port,
6041 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
6042 .src_port = mask->src_port_mask,
6043 .dst_port = mask->dst_port_mask,
6045 attributes->items[2] = (struct rte_flow_item){
6046 .type = RTE_FLOW_ITEM_TYPE_TCP,
6047 .spec = &attributes->l4,
6048 .mask = &attributes->l4_mask,
6051 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
6052 attributes->l4.udp.hdr = (struct rte_udp_hdr){
6053 .src_port = input->flow.udp6_flow.src_port,
6054 .dst_port = input->flow.udp6_flow.dst_port,
6056 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
6057 .src_port = mask->src_port_mask,
6058 .dst_port = mask->dst_port_mask,
6060 attributes->items[2] = (struct rte_flow_item){
6061 .type = RTE_FLOW_ITEM_TYPE_UDP,
6062 .spec = &attributes->l4,
6063 .mask = &attributes->l4_mask,
6066 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
6067 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
6068 .src_port = input->flow.tcp6_flow.src_port,
6069 .dst_port = input->flow.tcp6_flow.dst_port,
6071 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
6072 .src_port = mask->src_port_mask,
6073 .dst_port = mask->dst_port_mask,
6075 attributes->items[2] = (struct rte_flow_item){
6076 .type = RTE_FLOW_ITEM_TYPE_TCP,
6077 .spec = &attributes->l4,
6078 .mask = &attributes->l4_mask,
6081 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
6082 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
6085 DRV_LOG(ERR, "port %u invalid flow type%d",
6086 dev->data->port_id, fdir_filter->input.flow_type);
6087 rte_errno = ENOTSUP;
6093 #define FLOW_FDIR_CMP(f1, f2, fld) \
6094 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
6097 * Compare two FDIR flows. If items and actions are identical, the two flows are
6101 * Pointer to Ethernet device.
6103 * FDIR flow to compare.
6105 * FDIR flow to compare.
6108 * Zero on match, 1 otherwise.
6111 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
6113 if (FLOW_FDIR_CMP(f1, f2, attr) ||
6114 FLOW_FDIR_CMP(f1, f2, l2) ||
6115 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
6116 FLOW_FDIR_CMP(f1, f2, l3) ||
6117 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
6118 FLOW_FDIR_CMP(f1, f2, l4) ||
6119 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
6120 FLOW_FDIR_CMP(f1, f2, actions[0].type))
6122 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
6123 FLOW_FDIR_CMP(f1, f2, queue))
6129 * Search device flow list to find out a matched FDIR flow.
6132 * Pointer to Ethernet device.
6134 * FDIR flow to lookup.
6137 * Index of flow if found, 0 otherwise.
6140 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
6142 struct mlx5_priv *priv = dev->data->dev_private;
6143 uint32_t flow_idx = 0;
6144 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6146 MLX5_ASSERT(fdir_flow);
6147 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
6148 if (!flow_fdir_cmp(priv_fdir_flow->fdir, fdir_flow)) {
6149 DRV_LOG(DEBUG, "port %u found FDIR flow %u",
6150 dev->data->port_id, flow_idx);
6151 flow_idx = priv_fdir_flow->rix_flow;
6159 * Add new flow director filter and store it in list.
6162 * Pointer to Ethernet device.
6163 * @param fdir_filter
6164 * Flow director filter to add.
6167 * 0 on success, a negative errno value otherwise and rte_errno is set.
6170 flow_fdir_filter_add(struct rte_eth_dev *dev,
6171 const struct rte_eth_fdir_filter *fdir_filter)
6173 struct mlx5_priv *priv = dev->data->dev_private;
6174 struct mlx5_fdir *fdir_flow;
6175 struct rte_flow *flow;
6176 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6180 fdir_flow = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*fdir_flow), 0,
6186 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
6189 flow_idx = flow_fdir_filter_lookup(dev, fdir_flow);
6194 priv_fdir_flow = mlx5_malloc(MLX5_MEM_ZERO,
6195 sizeof(struct mlx5_fdir_flow),
6197 if (!priv_fdir_flow) {
6201 flow_idx = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
6202 fdir_flow->items, fdir_flow->actions, true,
6204 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
6208 priv_fdir_flow->fdir = fdir_flow;
6209 priv_fdir_flow->rix_flow = flow_idx;
6210 LIST_INSERT_HEAD(&priv->fdir_flows, priv_fdir_flow, next);
6211 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
6212 dev->data->port_id, (void *)flow);
6215 mlx5_free(priv_fdir_flow);
6216 mlx5_free(fdir_flow);
6221 * Delete specific filter.
6224 * Pointer to Ethernet device.
6225 * @param fdir_filter
6226 * Filter to be deleted.
6229 * 0 on success, a negative errno value otherwise and rte_errno is set.
6232 flow_fdir_filter_delete(struct rte_eth_dev *dev,
6233 const struct rte_eth_fdir_filter *fdir_filter)
6235 struct mlx5_priv *priv = dev->data->dev_private;
6237 struct mlx5_fdir fdir_flow = {
6240 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6243 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
6246 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
6247 /* Find the fdir in priv list */
6248 if (!flow_fdir_cmp(priv_fdir_flow->fdir, &fdir_flow))
6251 if (!priv_fdir_flow)
6253 LIST_REMOVE(priv_fdir_flow, next);
6254 flow_idx = priv_fdir_flow->rix_flow;
6255 flow_list_destroy(dev, &priv->flows, flow_idx);
6256 mlx5_free(priv_fdir_flow->fdir);
6257 mlx5_free(priv_fdir_flow);
6258 DRV_LOG(DEBUG, "port %u deleted FDIR flow %u",
6259 dev->data->port_id, flow_idx);
6264 * Update queue for specific filter.
6267 * Pointer to Ethernet device.
6268 * @param fdir_filter
6269 * Filter to be updated.
6272 * 0 on success, a negative errno value otherwise and rte_errno is set.
6275 flow_fdir_filter_update(struct rte_eth_dev *dev,
6276 const struct rte_eth_fdir_filter *fdir_filter)
6280 ret = flow_fdir_filter_delete(dev, fdir_filter);
6283 return flow_fdir_filter_add(dev, fdir_filter);
6287 * Flush all filters.
6290 * Pointer to Ethernet device.
6293 flow_fdir_filter_flush(struct rte_eth_dev *dev)
6295 struct mlx5_priv *priv = dev->data->dev_private;
6296 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6298 while (!LIST_EMPTY(&priv->fdir_flows)) {
6299 priv_fdir_flow = LIST_FIRST(&priv->fdir_flows);
6300 LIST_REMOVE(priv_fdir_flow, next);
6301 flow_list_destroy(dev, &priv->flows, priv_fdir_flow->rix_flow);
6302 mlx5_free(priv_fdir_flow->fdir);
6303 mlx5_free(priv_fdir_flow);
6308 * Get flow director information.
6311 * Pointer to Ethernet device.
6312 * @param[out] fdir_info
6313 * Resulting flow director information.
6316 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
6318 struct rte_eth_fdir_masks *mask =
6319 &dev->data->dev_conf.fdir_conf.mask;
6321 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
6322 fdir_info->guarant_spc = 0;
6323 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
6324 fdir_info->max_flexpayload = 0;
6325 fdir_info->flow_types_mask[0] = 0;
6326 fdir_info->flex_payload_unit = 0;
6327 fdir_info->max_flex_payload_segment_num = 0;
6328 fdir_info->flex_payload_limit = 0;
6329 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
6333 * Deal with flow director operations.
6336 * Pointer to Ethernet device.
6338 * Operation to perform.
6340 * Pointer to operation-specific structure.
6343 * 0 on success, a negative errno value otherwise and rte_errno is set.
6346 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
6349 enum rte_fdir_mode fdir_mode =
6350 dev->data->dev_conf.fdir_conf.mode;
6352 if (filter_op == RTE_ETH_FILTER_NOP)
6354 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
6355 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
6356 DRV_LOG(ERR, "port %u flow director mode %d not supported",
6357 dev->data->port_id, fdir_mode);
6361 switch (filter_op) {
6362 case RTE_ETH_FILTER_ADD:
6363 return flow_fdir_filter_add(dev, arg);
6364 case RTE_ETH_FILTER_UPDATE:
6365 return flow_fdir_filter_update(dev, arg);
6366 case RTE_ETH_FILTER_DELETE:
6367 return flow_fdir_filter_delete(dev, arg);
6368 case RTE_ETH_FILTER_FLUSH:
6369 flow_fdir_filter_flush(dev);
6371 case RTE_ETH_FILTER_INFO:
6372 flow_fdir_info_get(dev, arg);
6375 DRV_LOG(DEBUG, "port %u unknown operation %u",
6376 dev->data->port_id, filter_op);
6384 * Manage filter operations.
6387 * Pointer to Ethernet device structure.
6388 * @param filter_type
6391 * Operation to perform.
6393 * Pointer to operation-specific structure.
6396 * 0 on success, a negative errno value otherwise and rte_errno is set.
6399 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
6400 enum rte_filter_type filter_type,
6401 enum rte_filter_op filter_op,
6404 switch (filter_type) {
6405 case RTE_ETH_FILTER_GENERIC:
6406 if (filter_op != RTE_ETH_FILTER_GET) {
6410 *(const void **)arg = &mlx5_flow_ops;
6412 case RTE_ETH_FILTER_FDIR:
6413 return flow_fdir_ctrl_func(dev, filter_op, arg);
6415 DRV_LOG(ERR, "port %u filter type (%d) not supported",
6416 dev->data->port_id, filter_type);
6417 rte_errno = ENOTSUP;
6424 * Create the needed meter and suffix tables.
6427 * Pointer to Ethernet device.
6429 * Pointer to the flow meter.
6432 * Pointer to table set on success, NULL otherwise.
6434 struct mlx5_meter_domains_infos *
6435 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
6436 const struct mlx5_flow_meter *fm)
6438 const struct mlx5_flow_driver_ops *fops;
6440 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6441 return fops->create_mtr_tbls(dev, fm);
6445 * Destroy the meter table set.
6448 * Pointer to Ethernet device.
6450 * Pointer to the meter table set.
6456 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
6457 struct mlx5_meter_domains_infos *tbls)
6459 const struct mlx5_flow_driver_ops *fops;
6461 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6462 return fops->destroy_mtr_tbls(dev, tbls);
6466 * Create policer rules.
6469 * Pointer to Ethernet device.
6471 * Pointer to flow meter structure.
6473 * Pointer to flow attributes.
6476 * 0 on success, -1 otherwise.
6479 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
6480 struct mlx5_flow_meter *fm,
6481 const struct rte_flow_attr *attr)
6483 const struct mlx5_flow_driver_ops *fops;
6485 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6486 return fops->create_policer_rules(dev, fm, attr);
6490 * Destroy policer rules.
6493 * Pointer to flow meter structure.
6495 * Pointer to flow attributes.
6498 * 0 on success, -1 otherwise.
6501 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
6502 struct mlx5_flow_meter *fm,
6503 const struct rte_flow_attr *attr)
6505 const struct mlx5_flow_driver_ops *fops;
6507 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6508 return fops->destroy_policer_rules(dev, fm, attr);
6512 * Allocate a counter.
6515 * Pointer to Ethernet device structure.
6518 * Index to allocated counter on success, 0 otherwise.
6521 mlx5_counter_alloc(struct rte_eth_dev *dev)
6523 const struct mlx5_flow_driver_ops *fops;
6524 struct rte_flow_attr attr = { .transfer = 0 };
6526 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6527 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6528 return fops->counter_alloc(dev);
6531 "port %u counter allocate is not supported.",
6532 dev->data->port_id);
6540 * Pointer to Ethernet device structure.
6542 * Index to counter to be free.
6545 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
6547 const struct mlx5_flow_driver_ops *fops;
6548 struct rte_flow_attr attr = { .transfer = 0 };
6550 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6551 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6552 fops->counter_free(dev, cnt);
6556 "port %u counter free is not supported.",
6557 dev->data->port_id);
6561 * Query counter statistics.
6564 * Pointer to Ethernet device structure.
6566 * Index to counter to query.
6568 * Set to clear counter statistics.
6570 * The counter hits packets number to save.
6572 * The counter hits bytes number to save.
6575 * 0 on success, a negative errno value otherwise.
6578 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
6579 bool clear, uint64_t *pkts, uint64_t *bytes)
6581 const struct mlx5_flow_driver_ops *fops;
6582 struct rte_flow_attr attr = { .transfer = 0 };
6584 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6585 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6586 return fops->counter_query(dev, cnt, clear, pkts, bytes);
6589 "port %u counter query is not supported.",
6590 dev->data->port_id);
6595 * Allocate a new memory for the counter values wrapped by all the needed
6599 * Pointer to mlx5_dev_ctx_shared object.
6602 * 0 on success, a negative errno value otherwise.
6605 mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
6607 struct mlx5_devx_mkey_attr mkey_attr;
6608 struct mlx5_counter_stats_mem_mng *mem_mng;
6609 volatile struct flow_counter_stats *raw_data;
6610 int raws_n = MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES;
6611 int size = (sizeof(struct flow_counter_stats) *
6612 MLX5_COUNTERS_PER_POOL +
6613 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
6614 sizeof(struct mlx5_counter_stats_mem_mng);
6615 size_t pgsize = rte_mem_page_size();
6619 if (pgsize == (size_t)-1) {
6620 DRV_LOG(ERR, "Failed to get mem page size");
6624 mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
6629 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
6630 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
6631 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
6632 IBV_ACCESS_LOCAL_WRITE);
6633 if (!mem_mng->umem) {
6638 mkey_attr.addr = (uintptr_t)mem;
6639 mkey_attr.size = size;
6640 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
6641 mkey_attr.pd = sh->pdn;
6642 mkey_attr.log_entity_size = 0;
6643 mkey_attr.pg_access = 0;
6644 mkey_attr.klm_array = NULL;
6645 mkey_attr.klm_num = 0;
6646 mkey_attr.relaxed_ordering = sh->cmng.relaxed_ordering;
6647 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
6649 mlx5_glue->devx_umem_dereg(mem_mng->umem);
6654 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
6655 raw_data = (volatile struct flow_counter_stats *)mem;
6656 for (i = 0; i < raws_n; ++i) {
6657 mem_mng->raws[i].mem_mng = mem_mng;
6658 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
6660 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
6661 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws,
6662 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE + i,
6664 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
6665 sh->cmng.mem_mng = mem_mng;
6670 * Set the statistic memory to the new counter pool.
6673 * Pointer to mlx5_dev_ctx_shared object.
6675 * Pointer to the pool to set the statistic memory.
6678 * 0 on success, a negative errno value otherwise.
6681 mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
6682 struct mlx5_flow_counter_pool *pool)
6684 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6685 /* Resize statistic memory once used out. */
6686 if (!(pool->index % MLX5_CNT_CONTAINER_RESIZE) &&
6687 mlx5_flow_create_counter_stat_mem_mng(sh)) {
6688 DRV_LOG(ERR, "Cannot resize counter stat mem.");
6691 rte_spinlock_lock(&pool->sl);
6692 pool->raw = cmng->mem_mng->raws + pool->index %
6693 MLX5_CNT_CONTAINER_RESIZE;
6694 rte_spinlock_unlock(&pool->sl);
6695 pool->raw_hw = NULL;
6699 #define MLX5_POOL_QUERY_FREQ_US 1000000
6702 * Set the periodic procedure for triggering asynchronous batch queries for all
6703 * the counter pools.
6706 * Pointer to mlx5_dev_ctx_shared object.
6709 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
6711 uint32_t pools_n, us;
6713 pools_n = __atomic_load_n(&sh->cmng.n_valid, __ATOMIC_RELAXED);
6714 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
6715 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
6716 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
6717 sh->cmng.query_thread_on = 0;
6718 DRV_LOG(ERR, "Cannot reinitialize query alarm");
6720 sh->cmng.query_thread_on = 1;
6725 * The periodic procedure for triggering asynchronous batch queries for all the
6726 * counter pools. This function is probably called by the host thread.
6729 * The parameter for the alarm process.
6732 mlx5_flow_query_alarm(void *arg)
6734 struct mlx5_dev_ctx_shared *sh = arg;
6736 uint16_t pool_index = sh->cmng.pool_index;
6737 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6738 struct mlx5_flow_counter_pool *pool;
6741 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
6743 rte_spinlock_lock(&cmng->pool_update_sl);
6744 pool = cmng->pools[pool_index];
6745 n_valid = cmng->n_valid;
6746 rte_spinlock_unlock(&cmng->pool_update_sl);
6747 /* Set the statistic memory to the new created pool. */
6748 if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
6751 /* There is a pool query in progress. */
6754 LIST_FIRST(&sh->cmng.free_stat_raws);
6756 /* No free counter statistics raw memory. */
6759 * Identify the counters released between query trigger and query
6760 * handle more efficiently. The counter released in this gap period
6761 * should wait for a new round of query as the new arrived packets
6762 * will not be taken into account.
6765 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
6766 MLX5_COUNTERS_PER_POOL,
6768 pool->raw_hw->mem_mng->dm->id,
6772 (uint64_t)(uintptr_t)pool);
6774 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
6775 " %d", pool->min_dcs->id);
6776 pool->raw_hw = NULL;
6779 LIST_REMOVE(pool->raw_hw, next);
6780 sh->cmng.pending_queries++;
6782 if (pool_index >= n_valid)
6785 sh->cmng.pool_index = pool_index;
6786 mlx5_set_query_alarm(sh);
6790 * Check and callback event for new aged flow in the counter pool
6793 * Pointer to mlx5_dev_ctx_shared object.
6795 * Pointer to Current counter pool.
6798 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
6799 struct mlx5_flow_counter_pool *pool)
6801 struct mlx5_priv *priv;
6802 struct mlx5_flow_counter *cnt;
6803 struct mlx5_age_info *age_info;
6804 struct mlx5_age_param *age_param;
6805 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
6806 struct mlx5_counter_stats_raw *prev = pool->raw;
6807 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
6808 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
6809 uint16_t expected = AGE_CANDIDATE;
6812 pool->time_of_last_age_check = curr_time;
6813 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
6814 cnt = MLX5_POOL_GET_CNT(pool, i);
6815 age_param = MLX5_CNT_TO_AGE(cnt);
6816 if (__atomic_load_n(&age_param->state,
6817 __ATOMIC_RELAXED) != AGE_CANDIDATE)
6819 if (cur->data[i].hits != prev->data[i].hits) {
6820 __atomic_store_n(&age_param->sec_since_last_hit, 0,
6824 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
6826 __ATOMIC_RELAXED) <= age_param->timeout)
6829 * Hold the lock first, or if between the
6830 * state AGE_TMOUT and tailq operation the
6831 * release happened, the release procedure
6832 * may delete a non-existent tailq node.
6834 priv = rte_eth_devices[age_param->port_id].data->dev_private;
6835 age_info = GET_PORT_AGE_INFO(priv);
6836 rte_spinlock_lock(&age_info->aged_sl);
6837 if (__atomic_compare_exchange_n(&age_param->state, &expected,
6840 __ATOMIC_RELAXED)) {
6841 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
6842 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
6844 rte_spinlock_unlock(&age_info->aged_sl);
6846 for (i = 0; i < sh->max_port; i++) {
6847 age_info = &sh->port[i].age_info;
6848 if (!MLX5_AGE_GET(age_info, MLX5_AGE_EVENT_NEW))
6850 if (MLX5_AGE_GET(age_info, MLX5_AGE_TRIGGER))
6851 rte_eth_dev_callback_process
6852 (&rte_eth_devices[sh->port[i].devx_ih_port_id],
6853 RTE_ETH_EVENT_FLOW_AGED, NULL);
6854 age_info->flags = 0;
6859 * Handler for the HW respond about ready values from an asynchronous batch
6860 * query. This function is probably called by the host thread.
6863 * The pointer to the shared device context.
6864 * @param[in] async_id
6865 * The Devx async ID.
6867 * The status of the completion.
6870 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
6871 uint64_t async_id, int status)
6873 struct mlx5_flow_counter_pool *pool =
6874 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
6875 struct mlx5_counter_stats_raw *raw_to_free;
6876 uint8_t query_gen = pool->query_gen ^ 1;
6877 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6878 enum mlx5_counter_type cnt_type =
6879 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6880 MLX5_COUNTER_TYPE_ORIGIN;
6882 if (unlikely(status)) {
6883 raw_to_free = pool->raw_hw;
6885 raw_to_free = pool->raw;
6887 mlx5_flow_aging_check(sh, pool);
6888 rte_spinlock_lock(&pool->sl);
6889 pool->raw = pool->raw_hw;
6890 rte_spinlock_unlock(&pool->sl);
6891 /* Be sure the new raw counters data is updated in memory. */
6893 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
6894 rte_spinlock_lock(&cmng->csl[cnt_type]);
6895 TAILQ_CONCAT(&cmng->counters[cnt_type],
6896 &pool->counters[query_gen], next);
6897 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6900 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
6901 pool->raw_hw = NULL;
6902 sh->cmng.pending_queries--;
6906 * Translate the rte_flow group index to HW table value.
6908 * @param[in] attributes
6909 * Pointer to flow attributes
6910 * @param[in] external
6911 * Value is part of flow rule created by request external to PMD.
6913 * rte_flow group index value.
6914 * @param[out] fdb_def_rule
6915 * Whether fdb jump to table 1 is configured.
6919 * Pointer to error structure.
6922 * 0 on success, a negative errno value otherwise and rte_errno is set.
6925 mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, bool external,
6926 uint32_t group, bool fdb_def_rule, uint32_t *table,
6927 struct rte_flow_error *error)
6929 if (attributes->transfer && external && fdb_def_rule) {
6930 if (group == UINT32_MAX)
6931 return rte_flow_error_set
6933 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6935 "group index not supported");
6944 * Discover availability of metadata reg_c's.
6946 * Iteratively use test flows to check availability.
6949 * Pointer to the Ethernet device structure.
6952 * 0 on success, a negative errno value otherwise and rte_errno is set.
6955 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
6957 struct mlx5_priv *priv = dev->data->dev_private;
6958 struct mlx5_dev_config *config = &priv->config;
6959 enum modify_reg idx;
6962 /* reg_c[0] and reg_c[1] are reserved. */
6963 config->flow_mreg_c[n++] = REG_C_0;
6964 config->flow_mreg_c[n++] = REG_C_1;
6965 /* Discover availability of other reg_c's. */
6966 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
6967 struct rte_flow_attr attr = {
6968 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
6969 .priority = MLX5_FLOW_PRIO_RSVD,
6972 struct rte_flow_item items[] = {
6974 .type = RTE_FLOW_ITEM_TYPE_END,
6977 struct rte_flow_action actions[] = {
6979 .type = (enum rte_flow_action_type)
6980 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6981 .conf = &(struct mlx5_flow_action_copy_mreg){
6987 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6988 .conf = &(struct rte_flow_action_jump){
6989 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
6993 .type = RTE_FLOW_ACTION_TYPE_END,
6997 struct rte_flow *flow;
6998 struct rte_flow_error error;
7000 if (!config->dv_flow_en)
7002 /* Create internal flow, validation skips copy action. */
7003 flow_idx = flow_list_create(dev, NULL, &attr, items,
7004 actions, false, &error);
7005 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
7009 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
7010 config->flow_mreg_c[n++] = idx;
7011 flow_list_destroy(dev, NULL, flow_idx);
7013 for (; n < MLX5_MREG_C_NUM; ++n)
7014 config->flow_mreg_c[n] = REG_NON;
7019 * Dump flow raw hw data to file
7022 * The pointer to Ethernet device.
7024 * A pointer to a file for output.
7026 * Perform verbose error reporting if not NULL. PMDs initialize this
7027 * structure in case of error only.
7029 * 0 on success, a nagative value otherwise.
7032 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
7034 struct rte_flow_error *error __rte_unused)
7036 struct mlx5_priv *priv = dev->data->dev_private;
7037 struct mlx5_dev_ctx_shared *sh = priv->sh;
7039 if (!priv->config.dv_flow_en) {
7040 if (fputs("device dv flow disabled\n", file) <= 0)
7044 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
7045 sh->tx_domain, file);
7049 * Get aged-out flows.
7052 * Pointer to the Ethernet device structure.
7053 * @param[in] context
7054 * The address of an array of pointers to the aged-out flows contexts.
7055 * @param[in] nb_countexts
7056 * The length of context array pointers.
7058 * Perform verbose error reporting if not NULL. Initialized in case of
7062 * how many contexts get in success, otherwise negative errno value.
7063 * if nb_contexts is 0, return the amount of all aged contexts.
7064 * if nb_contexts is not 0 , return the amount of aged flows reported
7065 * in the context array.
7068 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
7069 uint32_t nb_contexts, struct rte_flow_error *error)
7071 const struct mlx5_flow_driver_ops *fops;
7072 struct rte_flow_attr attr = { .transfer = 0 };
7074 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
7075 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
7076 return fops->get_aged_flows(dev, contexts, nb_contexts,
7080 "port %u get aged flows is not supported.",
7081 dev->data->port_id);