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>
17 #include <rte_cycles.h>
18 #include <rte_flow_driver.h>
19 #include <rte_malloc.h>
22 #include <mlx5_glue.h>
23 #include <mlx5_devx_cmds.h>
25 #include <mlx5_malloc.h>
27 #include "mlx5_defs.h"
29 #include "mlx5_flow.h"
30 #include "mlx5_flow_os.h"
31 #include "mlx5_rxtx.h"
33 /** Device flow drivers. */
34 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
36 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
38 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
39 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
40 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
41 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
43 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
44 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
47 /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
48 #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
53 /** Node object of input graph for mlx5_flow_expand_rss(). */
54 struct mlx5_flow_expand_node {
55 const int *const next;
57 * List of next node indexes. Index 0 is interpreted as a terminator.
59 const enum rte_flow_item_type type;
60 /**< Pattern item type of current node. */
63 * RSS types bit-field associated with this node
64 * (see ETH_RSS_* definitions).
68 /** Object returned by mlx5_flow_expand_rss(). */
69 struct mlx5_flow_expand_rss {
71 /**< Number of entries @p patterns and @p priorities. */
73 struct rte_flow_item *pattern; /**< Expanded pattern array. */
74 uint32_t priority; /**< Priority offset for each expansion. */
78 static enum rte_flow_item_type
79 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
81 enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
82 uint16_t ether_type = 0;
83 uint16_t ether_type_m;
84 uint8_t ip_next_proto = 0;
85 uint8_t ip_next_proto_m;
87 if (item == NULL || item->spec == NULL)
90 case RTE_FLOW_ITEM_TYPE_ETH:
92 ether_type_m = ((const struct rte_flow_item_eth *)
95 ether_type_m = rte_flow_item_eth_mask.type;
96 if (ether_type_m != RTE_BE16(0xFFFF))
98 ether_type = ((const struct rte_flow_item_eth *)
100 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
101 ret = RTE_FLOW_ITEM_TYPE_IPV4;
102 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
103 ret = RTE_FLOW_ITEM_TYPE_IPV6;
104 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
105 ret = RTE_FLOW_ITEM_TYPE_VLAN;
107 ret = RTE_FLOW_ITEM_TYPE_END;
109 case RTE_FLOW_ITEM_TYPE_VLAN:
111 ether_type_m = ((const struct rte_flow_item_vlan *)
112 (item->mask))->inner_type;
114 ether_type_m = rte_flow_item_vlan_mask.inner_type;
115 if (ether_type_m != RTE_BE16(0xFFFF))
117 ether_type = ((const struct rte_flow_item_vlan *)
118 (item->spec))->inner_type;
119 if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
120 ret = RTE_FLOW_ITEM_TYPE_IPV4;
121 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
122 ret = RTE_FLOW_ITEM_TYPE_IPV6;
123 else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
124 ret = RTE_FLOW_ITEM_TYPE_VLAN;
126 ret = RTE_FLOW_ITEM_TYPE_END;
128 case RTE_FLOW_ITEM_TYPE_IPV4:
130 ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
131 (item->mask))->hdr.next_proto_id;
134 rte_flow_item_ipv4_mask.hdr.next_proto_id;
135 if (ip_next_proto_m != 0xFF)
137 ip_next_proto = ((const struct rte_flow_item_ipv4 *)
138 (item->spec))->hdr.next_proto_id;
139 if (ip_next_proto == IPPROTO_UDP)
140 ret = RTE_FLOW_ITEM_TYPE_UDP;
141 else if (ip_next_proto == IPPROTO_TCP)
142 ret = RTE_FLOW_ITEM_TYPE_TCP;
143 else if (ip_next_proto == IPPROTO_IP)
144 ret = RTE_FLOW_ITEM_TYPE_IPV4;
145 else if (ip_next_proto == IPPROTO_IPV6)
146 ret = RTE_FLOW_ITEM_TYPE_IPV6;
148 ret = RTE_FLOW_ITEM_TYPE_END;
150 case RTE_FLOW_ITEM_TYPE_IPV6:
152 ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
153 (item->mask))->hdr.proto;
156 rte_flow_item_ipv6_mask.hdr.proto;
157 if (ip_next_proto_m != 0xFF)
159 ip_next_proto = ((const struct rte_flow_item_ipv6 *)
160 (item->spec))->hdr.proto;
161 if (ip_next_proto == IPPROTO_UDP)
162 ret = RTE_FLOW_ITEM_TYPE_UDP;
163 else if (ip_next_proto == IPPROTO_TCP)
164 ret = RTE_FLOW_ITEM_TYPE_TCP;
165 else if (ip_next_proto == IPPROTO_IP)
166 ret = RTE_FLOW_ITEM_TYPE_IPV4;
167 else if (ip_next_proto == IPPROTO_IPV6)
168 ret = RTE_FLOW_ITEM_TYPE_IPV6;
170 ret = RTE_FLOW_ITEM_TYPE_END;
173 ret = RTE_FLOW_ITEM_TYPE_VOID;
180 * Expand RSS flows into several possible flows according to the RSS hash
181 * fields requested and the driver capabilities.
184 * Buffer to store the result expansion.
186 * Buffer size in bytes. If 0, @p buf can be NULL.
190 * RSS types to expand (see ETH_RSS_* definitions).
192 * Input graph to expand @p pattern according to @p types.
193 * @param[in] graph_root_index
194 * Index of root node in @p graph, typically 0.
197 * A positive value representing the size of @p buf in bytes regardless of
198 * @p size on success, a negative errno value otherwise and rte_errno is
199 * set, the following errors are defined:
201 * -E2BIG: graph-depth @p graph is too deep.
204 mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
205 const struct rte_flow_item *pattern, uint64_t types,
206 const struct mlx5_flow_expand_node graph[],
207 int graph_root_index)
210 const struct rte_flow_item *item;
211 const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
212 const int *next_node;
213 const int *stack[elt_n];
215 struct rte_flow_item flow_items[elt_n];
218 size_t user_pattern_size = 0;
220 const struct mlx5_flow_expand_node *next = NULL;
221 struct rte_flow_item missed_item;
224 const struct rte_flow_item *last_item = NULL;
226 memset(&missed_item, 0, sizeof(missed_item));
227 lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
228 elt_n * sizeof(buf->entry[0]);
230 buf->entry[0].priority = 0;
231 buf->entry[0].pattern = (void *)&buf->entry[elt_n];
233 addr = buf->entry[0].pattern;
235 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
236 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
238 for (i = 0; node->next && node->next[i]; ++i) {
239 next = &graph[node->next[i]];
240 if (next->type == item->type)
245 user_pattern_size += sizeof(*item);
247 user_pattern_size += sizeof(*item); /* Handle END item. */
248 lsize += user_pattern_size;
249 /* Copy the user pattern in the first entry of the buffer. */
251 rte_memcpy(addr, pattern, user_pattern_size);
252 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
255 /* Start expanding. */
256 memset(flow_items, 0, sizeof(flow_items));
257 user_pattern_size -= sizeof(*item);
259 * Check if the last valid item has spec set, need complete pattern,
260 * and the pattern can be used for expansion.
262 missed_item.type = mlx5_flow_expand_rss_item_complete(last_item);
263 if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
264 /* Item type END indicates expansion is not required. */
267 if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
270 for (i = 0; node->next && node->next[i]; ++i) {
271 next = &graph[node->next[i]];
272 if (next->type == missed_item.type) {
273 flow_items[0].type = missed_item.type;
274 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
280 if (next && missed) {
281 elt = 2; /* missed item + item end. */
283 lsize += elt * sizeof(*item) + user_pattern_size;
284 if ((node->rss_types & types) && lsize <= size) {
285 buf->entry[buf->entries].priority = 1;
286 buf->entry[buf->entries].pattern = addr;
288 rte_memcpy(addr, buf->entry[0].pattern,
290 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
291 rte_memcpy(addr, flow_items, elt * sizeof(*item));
292 addr = (void *)(((uintptr_t)addr) +
293 elt * sizeof(*item));
296 memset(flow_items, 0, sizeof(flow_items));
297 next_node = node->next;
298 stack[stack_pos] = next_node;
299 node = next_node ? &graph[*next_node] : NULL;
301 flow_items[stack_pos].type = node->type;
302 if (node->rss_types & types) {
304 * compute the number of items to copy from the
305 * expansion and copy it.
306 * When the stack_pos is 0, there are 1 element in it,
307 * plus the addition END item.
310 flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
311 lsize += elt * sizeof(*item) + user_pattern_size;
313 size_t n = elt * sizeof(*item);
315 buf->entry[buf->entries].priority =
316 stack_pos + 1 + missed;
317 buf->entry[buf->entries].pattern = addr;
319 rte_memcpy(addr, buf->entry[0].pattern,
321 addr = (void *)(((uintptr_t)addr) +
323 rte_memcpy(addr, &missed_item,
324 missed * sizeof(*item));
325 addr = (void *)(((uintptr_t)addr) +
326 missed * sizeof(*item));
327 rte_memcpy(addr, flow_items, n);
328 addr = (void *)(((uintptr_t)addr) + n);
333 next_node = node->next;
334 if (stack_pos++ == elt_n) {
338 stack[stack_pos] = next_node;
339 } else if (*(next_node + 1)) {
340 /* Follow up with the next possibility. */
343 /* Move to the next path. */
345 next_node = stack[--stack_pos];
347 stack[stack_pos] = next_node;
349 node = *next_node ? &graph[*next_node] : NULL;
351 /* no expanded flows but we have missed item, create one rule for it */
352 if (buf->entries == 1 && missed != 0) {
354 lsize += elt * sizeof(*item) + user_pattern_size;
356 buf->entry[buf->entries].priority = 1;
357 buf->entry[buf->entries].pattern = addr;
359 flow_items[0].type = missed_item.type;
360 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
361 rte_memcpy(addr, buf->entry[0].pattern,
363 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
364 rte_memcpy(addr, flow_items, elt * sizeof(*item));
365 addr = (void *)(((uintptr_t)addr) +
366 elt * sizeof(*item));
372 enum mlx5_expansion {
374 MLX5_EXPANSION_ROOT_OUTER,
375 MLX5_EXPANSION_ROOT_ETH_VLAN,
376 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
377 MLX5_EXPANSION_OUTER_ETH,
378 MLX5_EXPANSION_OUTER_ETH_VLAN,
379 MLX5_EXPANSION_OUTER_VLAN,
380 MLX5_EXPANSION_OUTER_IPV4,
381 MLX5_EXPANSION_OUTER_IPV4_UDP,
382 MLX5_EXPANSION_OUTER_IPV4_TCP,
383 MLX5_EXPANSION_OUTER_IPV6,
384 MLX5_EXPANSION_OUTER_IPV6_UDP,
385 MLX5_EXPANSION_OUTER_IPV6_TCP,
386 MLX5_EXPANSION_VXLAN,
387 MLX5_EXPANSION_VXLAN_GPE,
391 MLX5_EXPANSION_ETH_VLAN,
394 MLX5_EXPANSION_IPV4_UDP,
395 MLX5_EXPANSION_IPV4_TCP,
397 MLX5_EXPANSION_IPV6_UDP,
398 MLX5_EXPANSION_IPV6_TCP,
401 /** Supported expansion of items. */
402 static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
403 [MLX5_EXPANSION_ROOT] = {
404 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
406 MLX5_EXPANSION_IPV6),
407 .type = RTE_FLOW_ITEM_TYPE_END,
409 [MLX5_EXPANSION_ROOT_OUTER] = {
410 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
411 MLX5_EXPANSION_OUTER_IPV4,
412 MLX5_EXPANSION_OUTER_IPV6),
413 .type = RTE_FLOW_ITEM_TYPE_END,
415 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
416 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
417 .type = RTE_FLOW_ITEM_TYPE_END,
419 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
420 .next = MLX5_FLOW_EXPAND_RSS_NEXT
421 (MLX5_EXPANSION_OUTER_ETH_VLAN),
422 .type = RTE_FLOW_ITEM_TYPE_END,
424 [MLX5_EXPANSION_OUTER_ETH] = {
425 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
426 MLX5_EXPANSION_OUTER_IPV6,
427 MLX5_EXPANSION_MPLS),
428 .type = RTE_FLOW_ITEM_TYPE_ETH,
431 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
432 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
433 .type = RTE_FLOW_ITEM_TYPE_ETH,
436 [MLX5_EXPANSION_OUTER_VLAN] = {
437 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
438 MLX5_EXPANSION_OUTER_IPV6),
439 .type = RTE_FLOW_ITEM_TYPE_VLAN,
441 [MLX5_EXPANSION_OUTER_IPV4] = {
442 .next = MLX5_FLOW_EXPAND_RSS_NEXT
443 (MLX5_EXPANSION_OUTER_IPV4_UDP,
444 MLX5_EXPANSION_OUTER_IPV4_TCP,
447 MLX5_EXPANSION_IPV6),
448 .type = RTE_FLOW_ITEM_TYPE_IPV4,
449 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
450 ETH_RSS_NONFRAG_IPV4_OTHER,
452 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
453 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
454 MLX5_EXPANSION_VXLAN_GPE),
455 .type = RTE_FLOW_ITEM_TYPE_UDP,
456 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
458 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
459 .type = RTE_FLOW_ITEM_TYPE_TCP,
460 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
462 [MLX5_EXPANSION_OUTER_IPV6] = {
463 .next = MLX5_FLOW_EXPAND_RSS_NEXT
464 (MLX5_EXPANSION_OUTER_IPV6_UDP,
465 MLX5_EXPANSION_OUTER_IPV6_TCP,
467 MLX5_EXPANSION_IPV6),
468 .type = RTE_FLOW_ITEM_TYPE_IPV6,
469 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
470 ETH_RSS_NONFRAG_IPV6_OTHER,
472 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
473 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
474 MLX5_EXPANSION_VXLAN_GPE),
475 .type = RTE_FLOW_ITEM_TYPE_UDP,
476 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
478 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
479 .type = RTE_FLOW_ITEM_TYPE_TCP,
480 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
482 [MLX5_EXPANSION_VXLAN] = {
483 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
485 MLX5_EXPANSION_IPV6),
486 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
488 [MLX5_EXPANSION_VXLAN_GPE] = {
489 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
491 MLX5_EXPANSION_IPV6),
492 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
494 [MLX5_EXPANSION_GRE] = {
495 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
496 .type = RTE_FLOW_ITEM_TYPE_GRE,
498 [MLX5_EXPANSION_MPLS] = {
499 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
500 MLX5_EXPANSION_IPV6),
501 .type = RTE_FLOW_ITEM_TYPE_MPLS,
503 [MLX5_EXPANSION_ETH] = {
504 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
505 MLX5_EXPANSION_IPV6),
506 .type = RTE_FLOW_ITEM_TYPE_ETH,
508 [MLX5_EXPANSION_ETH_VLAN] = {
509 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
510 .type = RTE_FLOW_ITEM_TYPE_ETH,
512 [MLX5_EXPANSION_VLAN] = {
513 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
514 MLX5_EXPANSION_IPV6),
515 .type = RTE_FLOW_ITEM_TYPE_VLAN,
517 [MLX5_EXPANSION_IPV4] = {
518 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
519 MLX5_EXPANSION_IPV4_TCP),
520 .type = RTE_FLOW_ITEM_TYPE_IPV4,
521 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
522 ETH_RSS_NONFRAG_IPV4_OTHER,
524 [MLX5_EXPANSION_IPV4_UDP] = {
525 .type = RTE_FLOW_ITEM_TYPE_UDP,
526 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
528 [MLX5_EXPANSION_IPV4_TCP] = {
529 .type = RTE_FLOW_ITEM_TYPE_TCP,
530 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
532 [MLX5_EXPANSION_IPV6] = {
533 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
534 MLX5_EXPANSION_IPV6_TCP),
535 .type = RTE_FLOW_ITEM_TYPE_IPV6,
536 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
537 ETH_RSS_NONFRAG_IPV6_OTHER,
539 [MLX5_EXPANSION_IPV6_UDP] = {
540 .type = RTE_FLOW_ITEM_TYPE_UDP,
541 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
543 [MLX5_EXPANSION_IPV6_TCP] = {
544 .type = RTE_FLOW_ITEM_TYPE_TCP,
545 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
549 static const struct rte_flow_ops mlx5_flow_ops = {
550 .validate = mlx5_flow_validate,
551 .create = mlx5_flow_create,
552 .destroy = mlx5_flow_destroy,
553 .flush = mlx5_flow_flush,
554 .isolate = mlx5_flow_isolate,
555 .query = mlx5_flow_query,
556 .dev_dump = mlx5_flow_dev_dump,
557 .get_aged_flows = mlx5_flow_get_aged_flows,
560 /* Convert FDIR request to Generic flow. */
562 struct rte_flow_attr attr;
563 struct rte_flow_item items[4];
564 struct rte_flow_item_eth l2;
565 struct rte_flow_item_eth l2_mask;
567 struct rte_flow_item_ipv4 ipv4;
568 struct rte_flow_item_ipv6 ipv6;
571 struct rte_flow_item_ipv4 ipv4;
572 struct rte_flow_item_ipv6 ipv6;
575 struct rte_flow_item_udp udp;
576 struct rte_flow_item_tcp tcp;
579 struct rte_flow_item_udp udp;
580 struct rte_flow_item_tcp tcp;
582 struct rte_flow_action actions[2];
583 struct rte_flow_action_queue queue;
586 /* Tunnel information. */
587 struct mlx5_flow_tunnel_info {
588 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
589 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
592 static struct mlx5_flow_tunnel_info tunnels_info[] = {
594 .tunnel = MLX5_FLOW_LAYER_VXLAN,
595 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
598 .tunnel = MLX5_FLOW_LAYER_GENEVE,
599 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
602 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
603 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
606 .tunnel = MLX5_FLOW_LAYER_GRE,
607 .ptype = RTE_PTYPE_TUNNEL_GRE,
610 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
611 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
614 .tunnel = MLX5_FLOW_LAYER_MPLS,
615 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
618 .tunnel = MLX5_FLOW_LAYER_NVGRE,
619 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
622 .tunnel = MLX5_FLOW_LAYER_IPIP,
623 .ptype = RTE_PTYPE_TUNNEL_IP,
626 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
627 .ptype = RTE_PTYPE_TUNNEL_IP,
630 .tunnel = MLX5_FLOW_LAYER_GTP,
631 .ptype = RTE_PTYPE_TUNNEL_GTPU,
636 * Translate tag ID to register.
639 * Pointer to the Ethernet device structure.
641 * The feature that request the register.
643 * The request register ID.
645 * Error description in case of any.
648 * The request register on success, a negative errno
649 * value otherwise and rte_errno is set.
652 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
653 enum mlx5_feature_name feature,
655 struct rte_flow_error *error)
657 struct mlx5_priv *priv = dev->data->dev_private;
658 struct mlx5_dev_config *config = &priv->config;
659 enum modify_reg start_reg;
660 bool skip_mtr_reg = false;
663 case MLX5_HAIRPIN_RX:
665 case MLX5_HAIRPIN_TX:
667 case MLX5_METADATA_RX:
668 switch (config->dv_xmeta_en) {
669 case MLX5_XMETA_MODE_LEGACY:
671 case MLX5_XMETA_MODE_META16:
673 case MLX5_XMETA_MODE_META32:
677 case MLX5_METADATA_TX:
679 case MLX5_METADATA_FDB:
680 switch (config->dv_xmeta_en) {
681 case MLX5_XMETA_MODE_LEGACY:
683 case MLX5_XMETA_MODE_META16:
685 case MLX5_XMETA_MODE_META32:
690 switch (config->dv_xmeta_en) {
691 case MLX5_XMETA_MODE_LEGACY:
693 case MLX5_XMETA_MODE_META16:
695 case MLX5_XMETA_MODE_META32:
701 * If meter color and flow match share one register, flow match
702 * should use the meter color register for match.
704 if (priv->mtr_reg_share)
705 return priv->mtr_color_reg;
707 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
710 MLX5_ASSERT(priv->mtr_color_reg != REG_NON);
711 return priv->mtr_color_reg;
714 * Metadata COPY_MARK register using is in meter suffix sub
715 * flow while with meter. It's safe to share the same register.
717 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
720 * If meter is enable, it will engage the register for color
721 * match and flow match. If meter color match is not using the
722 * REG_C_2, need to skip the REG_C_x be used by meter color
724 * If meter is disable, free to use all available registers.
726 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
727 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
728 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
729 if (id > (REG_C_7 - start_reg))
730 return rte_flow_error_set(error, EINVAL,
731 RTE_FLOW_ERROR_TYPE_ITEM,
732 NULL, "invalid tag id");
733 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
734 return rte_flow_error_set(error, ENOTSUP,
735 RTE_FLOW_ERROR_TYPE_ITEM,
736 NULL, "unsupported tag id");
738 * This case means meter is using the REG_C_x great than 2.
739 * Take care not to conflict with meter color REG_C_x.
740 * If the available index REG_C_y >= REG_C_x, skip the
743 if (skip_mtr_reg && config->flow_mreg_c
744 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
745 if (id >= (REG_C_7 - start_reg))
746 return rte_flow_error_set(error, EINVAL,
747 RTE_FLOW_ERROR_TYPE_ITEM,
748 NULL, "invalid tag id");
749 if (config->flow_mreg_c
750 [id + 1 + start_reg - REG_C_0] != REG_NON)
751 return config->flow_mreg_c
752 [id + 1 + start_reg - REG_C_0];
753 return rte_flow_error_set(error, ENOTSUP,
754 RTE_FLOW_ERROR_TYPE_ITEM,
755 NULL, "unsupported tag id");
757 return config->flow_mreg_c[id + start_reg - REG_C_0];
760 return rte_flow_error_set(error, EINVAL,
761 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
762 NULL, "invalid feature name");
766 * Check extensive flow metadata register support.
769 * Pointer to rte_eth_dev structure.
772 * True if device supports extensive flow metadata register, otherwise false.
775 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
777 struct mlx5_priv *priv = dev->data->dev_private;
778 struct mlx5_dev_config *config = &priv->config;
781 * Having available reg_c can be regarded inclusively as supporting
782 * extensive flow metadata register, which could mean,
783 * - metadata register copy action by modify header.
784 * - 16 modify header actions is supported.
785 * - reg_c's are preserved across different domain (FDB and NIC) on
786 * packet loopback by flow lookup miss.
788 return config->flow_mreg_c[2] != REG_NON;
792 * Verify the @p item specifications (spec, last, mask) are compatible with the
796 * Item specification.
798 * @p item->mask or flow default bit-masks.
799 * @param[in] nic_mask
800 * Bit-masks covering supported fields by the NIC to compare with user mask.
802 * Bit-masks size in bytes.
803 * @param[in] range_accepted
804 * True if range of values is accepted for specific fields, false otherwise.
806 * Pointer to error structure.
809 * 0 on success, a negative errno value otherwise and rte_errno is set.
812 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
814 const uint8_t *nic_mask,
817 struct rte_flow_error *error)
821 MLX5_ASSERT(nic_mask);
822 for (i = 0; i < size; ++i)
823 if ((nic_mask[i] | mask[i]) != nic_mask[i])
824 return rte_flow_error_set(error, ENOTSUP,
825 RTE_FLOW_ERROR_TYPE_ITEM,
827 "mask enables non supported"
829 if (!item->spec && (item->mask || item->last))
830 return rte_flow_error_set(error, EINVAL,
831 RTE_FLOW_ERROR_TYPE_ITEM, item,
832 "mask/last without a spec is not"
834 if (item->spec && item->last && !range_accepted) {
840 for (i = 0; i < size; ++i) {
841 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
842 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
844 ret = memcmp(spec, last, size);
846 return rte_flow_error_set(error, EINVAL,
847 RTE_FLOW_ERROR_TYPE_ITEM,
849 "range is not valid");
855 * Adjust the hash fields according to the @p flow information.
857 * @param[in] dev_flow.
858 * Pointer to the mlx5_flow.
860 * 1 when the hash field is for a tunnel item.
861 * @param[in] layer_types
863 * @param[in] hash_fields
867 * The hash fields that should be used.
870 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
871 int tunnel __rte_unused, uint64_t layer_types,
872 uint64_t hash_fields)
874 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
875 int rss_request_inner = rss_desc->level >= 2;
877 /* Check RSS hash level for tunnel. */
878 if (tunnel && rss_request_inner)
879 hash_fields |= IBV_RX_HASH_INNER;
880 else if (tunnel || rss_request_inner)
883 /* Check if requested layer matches RSS hash fields. */
884 if (!(rss_desc->types & layer_types))
890 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
891 * if several tunnel rules are used on this queue, the tunnel ptype will be
895 * Rx queue to update.
898 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
901 uint32_t tunnel_ptype = 0;
903 /* Look up for the ptype to use. */
904 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
905 if (!rxq_ctrl->flow_tunnels_n[i])
908 tunnel_ptype = tunnels_info[i].ptype;
914 rxq_ctrl->rxq.tunnel = tunnel_ptype;
918 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
922 * Pointer to the Ethernet device structure.
923 * @param[in] dev_handle
924 * Pointer to device flow handle structure.
927 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
928 struct mlx5_flow_handle *dev_handle)
930 struct mlx5_priv *priv = dev->data->dev_private;
931 const int mark = dev_handle->mark;
932 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
933 struct mlx5_hrxq *hrxq;
936 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
938 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
939 dev_handle->rix_hrxq);
942 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
943 int idx = hrxq->ind_table->queues[i];
944 struct mlx5_rxq_ctrl *rxq_ctrl =
945 container_of((*priv->rxqs)[idx],
946 struct mlx5_rxq_ctrl, rxq);
949 * To support metadata register copy on Tx loopback,
950 * this must be always enabled (metadata may arive
951 * from other port - not from local flows only.
953 if (priv->config.dv_flow_en &&
954 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
955 mlx5_flow_ext_mreg_supported(dev)) {
956 rxq_ctrl->rxq.mark = 1;
957 rxq_ctrl->flow_mark_n = 1;
959 rxq_ctrl->rxq.mark = 1;
960 rxq_ctrl->flow_mark_n++;
965 /* Increase the counter matching the flow. */
966 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
967 if ((tunnels_info[j].tunnel &
968 dev_handle->layers) ==
969 tunnels_info[j].tunnel) {
970 rxq_ctrl->flow_tunnels_n[j]++;
974 flow_rxq_tunnel_ptype_update(rxq_ctrl);
980 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
983 * Pointer to the Ethernet device structure.
985 * Pointer to flow structure.
988 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
990 struct mlx5_priv *priv = dev->data->dev_private;
992 struct mlx5_flow_handle *dev_handle;
994 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
995 handle_idx, dev_handle, next)
996 flow_drv_rxq_flags_set(dev, dev_handle);
1000 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1001 * device flow if no other flow uses it with the same kind of request.
1004 * Pointer to Ethernet device.
1005 * @param[in] dev_handle
1006 * Pointer to the device flow handle structure.
1009 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1010 struct mlx5_flow_handle *dev_handle)
1012 struct mlx5_priv *priv = dev->data->dev_private;
1013 const int mark = dev_handle->mark;
1014 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1015 struct mlx5_hrxq *hrxq;
1018 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
1020 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1021 dev_handle->rix_hrxq);
1024 MLX5_ASSERT(dev->data->dev_started);
1025 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
1026 int idx = hrxq->ind_table->queues[i];
1027 struct mlx5_rxq_ctrl *rxq_ctrl =
1028 container_of((*priv->rxqs)[idx],
1029 struct mlx5_rxq_ctrl, rxq);
1031 if (priv->config.dv_flow_en &&
1032 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1033 mlx5_flow_ext_mreg_supported(dev)) {
1034 rxq_ctrl->rxq.mark = 1;
1035 rxq_ctrl->flow_mark_n = 1;
1037 rxq_ctrl->flow_mark_n--;
1038 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
1043 /* Decrease the counter matching the flow. */
1044 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1045 if ((tunnels_info[j].tunnel &
1046 dev_handle->layers) ==
1047 tunnels_info[j].tunnel) {
1048 rxq_ctrl->flow_tunnels_n[j]--;
1052 flow_rxq_tunnel_ptype_update(rxq_ctrl);
1058 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1059 * @p flow if no other flow uses it with the same kind of request.
1062 * Pointer to Ethernet device.
1064 * Pointer to the flow.
1067 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1069 struct mlx5_priv *priv = dev->data->dev_private;
1070 uint32_t handle_idx;
1071 struct mlx5_flow_handle *dev_handle;
1073 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1074 handle_idx, dev_handle, next)
1075 flow_drv_rxq_flags_trim(dev, dev_handle);
1079 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1082 * Pointer to Ethernet device.
1085 flow_rxq_flags_clear(struct rte_eth_dev *dev)
1087 struct mlx5_priv *priv = dev->data->dev_private;
1090 for (i = 0; i != priv->rxqs_n; ++i) {
1091 struct mlx5_rxq_ctrl *rxq_ctrl;
1094 if (!(*priv->rxqs)[i])
1096 rxq_ctrl = container_of((*priv->rxqs)[i],
1097 struct mlx5_rxq_ctrl, rxq);
1098 rxq_ctrl->flow_mark_n = 0;
1099 rxq_ctrl->rxq.mark = 0;
1100 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1101 rxq_ctrl->flow_tunnels_n[j] = 0;
1102 rxq_ctrl->rxq.tunnel = 0;
1107 * Set the Rx queue dynamic metadata (mask and offset) for a flow
1110 * Pointer to the Ethernet device structure.
1113 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
1115 struct mlx5_priv *priv = dev->data->dev_private;
1116 struct mlx5_rxq_data *data;
1119 for (i = 0; i != priv->rxqs_n; ++i) {
1120 if (!(*priv->rxqs)[i])
1122 data = (*priv->rxqs)[i];
1123 if (!rte_flow_dynf_metadata_avail()) {
1124 data->dynf_meta = 0;
1125 data->flow_meta_mask = 0;
1126 data->flow_meta_offset = -1;
1128 data->dynf_meta = 1;
1129 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1130 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1136 * return a pointer to the desired action in the list of actions.
1138 * @param[in] actions
1139 * The list of actions to search the action in.
1141 * The action to find.
1144 * Pointer to the action in the list, if found. NULL otherwise.
1146 const struct rte_flow_action *
1147 mlx5_flow_find_action(const struct rte_flow_action *actions,
1148 enum rte_flow_action_type action)
1150 if (actions == NULL)
1152 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1153 if (actions->type == action)
1159 * Validate the flag action.
1161 * @param[in] action_flags
1162 * Bit-fields that holds the actions detected until now.
1164 * Attributes of flow that includes this action.
1166 * Pointer to error structure.
1169 * 0 on success, a negative errno value otherwise and rte_errno is set.
1172 mlx5_flow_validate_action_flag(uint64_t action_flags,
1173 const struct rte_flow_attr *attr,
1174 struct rte_flow_error *error)
1176 if (action_flags & MLX5_FLOW_ACTION_MARK)
1177 return rte_flow_error_set(error, EINVAL,
1178 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1179 "can't mark and flag in same flow");
1180 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1181 return rte_flow_error_set(error, EINVAL,
1182 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1184 " actions in same flow");
1186 return rte_flow_error_set(error, ENOTSUP,
1187 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1188 "flag action not supported for "
1194 * Validate the mark action.
1197 * Pointer to the queue action.
1198 * @param[in] action_flags
1199 * Bit-fields that holds the actions detected until now.
1201 * Attributes of flow that includes this action.
1203 * Pointer to error structure.
1206 * 0 on success, a negative errno value otherwise and rte_errno is set.
1209 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1210 uint64_t action_flags,
1211 const struct rte_flow_attr *attr,
1212 struct rte_flow_error *error)
1214 const struct rte_flow_action_mark *mark = action->conf;
1217 return rte_flow_error_set(error, EINVAL,
1218 RTE_FLOW_ERROR_TYPE_ACTION,
1220 "configuration cannot be null");
1221 if (mark->id >= MLX5_FLOW_MARK_MAX)
1222 return rte_flow_error_set(error, EINVAL,
1223 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1225 "mark id must in 0 <= id < "
1226 RTE_STR(MLX5_FLOW_MARK_MAX));
1227 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1228 return rte_flow_error_set(error, EINVAL,
1229 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1230 "can't flag and mark in same flow");
1231 if (action_flags & MLX5_FLOW_ACTION_MARK)
1232 return rte_flow_error_set(error, EINVAL,
1233 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1234 "can't have 2 mark actions in same"
1237 return rte_flow_error_set(error, ENOTSUP,
1238 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1239 "mark action not supported for "
1245 * Validate the drop action.
1247 * @param[in] action_flags
1248 * Bit-fields that holds the actions detected until now.
1250 * Attributes of flow that includes this action.
1252 * Pointer to error structure.
1255 * 0 on success, a negative errno value otherwise and rte_errno is set.
1258 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1259 const struct rte_flow_attr *attr,
1260 struct rte_flow_error *error)
1263 return rte_flow_error_set(error, ENOTSUP,
1264 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1265 "drop action not supported for "
1271 * Validate the queue action.
1274 * Pointer to the queue action.
1275 * @param[in] action_flags
1276 * Bit-fields that holds the actions detected until now.
1278 * Pointer to the Ethernet device structure.
1280 * Attributes of flow that includes this action.
1282 * Pointer to error structure.
1285 * 0 on success, a negative errno value otherwise and rte_errno is set.
1288 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1289 uint64_t action_flags,
1290 struct rte_eth_dev *dev,
1291 const struct rte_flow_attr *attr,
1292 struct rte_flow_error *error)
1294 struct mlx5_priv *priv = dev->data->dev_private;
1295 const struct rte_flow_action_queue *queue = action->conf;
1297 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1298 return rte_flow_error_set(error, EINVAL,
1299 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1300 "can't have 2 fate actions in"
1303 return rte_flow_error_set(error, EINVAL,
1304 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1305 NULL, "No Rx queues configured");
1306 if (queue->index >= priv->rxqs_n)
1307 return rte_flow_error_set(error, EINVAL,
1308 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1310 "queue index out of range");
1311 if (!(*priv->rxqs)[queue->index])
1312 return rte_flow_error_set(error, EINVAL,
1313 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1315 "queue is not configured");
1317 return rte_flow_error_set(error, ENOTSUP,
1318 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1319 "queue action not supported for "
1325 * Validate the rss action.
1328 * Pointer to the queue action.
1329 * @param[in] action_flags
1330 * Bit-fields that holds the actions detected until now.
1332 * Pointer to the Ethernet device structure.
1334 * Attributes of flow that includes this action.
1335 * @param[in] item_flags
1336 * Items that were detected.
1338 * Pointer to error structure.
1341 * 0 on success, a negative errno value otherwise and rte_errno is set.
1344 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1345 uint64_t action_flags,
1346 struct rte_eth_dev *dev,
1347 const struct rte_flow_attr *attr,
1348 uint64_t item_flags,
1349 struct rte_flow_error *error)
1351 struct mlx5_priv *priv = dev->data->dev_private;
1352 const struct rte_flow_action_rss *rss = action->conf;
1353 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1356 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1357 return rte_flow_error_set(error, EINVAL,
1358 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1359 "can't have 2 fate actions"
1361 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1362 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1363 return rte_flow_error_set(error, ENOTSUP,
1364 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1366 "RSS hash function not supported");
1367 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1372 return rte_flow_error_set(error, ENOTSUP,
1373 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1375 "tunnel RSS is not supported");
1376 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1377 if (rss->key_len == 0 && rss->key != NULL)
1378 return rte_flow_error_set(error, ENOTSUP,
1379 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1381 "RSS hash key length 0");
1382 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1383 return rte_flow_error_set(error, ENOTSUP,
1384 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1386 "RSS hash key too small");
1387 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1388 return rte_flow_error_set(error, ENOTSUP,
1389 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1391 "RSS hash key too large");
1392 if (rss->queue_num > priv->config.ind_table_max_size)
1393 return rte_flow_error_set(error, ENOTSUP,
1394 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1396 "number of queues too large");
1397 if (rss->types & MLX5_RSS_HF_MASK)
1398 return rte_flow_error_set(error, ENOTSUP,
1399 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1401 "some RSS protocols are not"
1403 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1404 !(rss->types & ETH_RSS_IP))
1405 return rte_flow_error_set(error, EINVAL,
1406 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1407 "L3 partial RSS requested but L3 RSS"
1408 " type not specified");
1409 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1410 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1411 return rte_flow_error_set(error, EINVAL,
1412 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1413 "L4 partial RSS requested but L4 RSS"
1414 " type not specified");
1416 return rte_flow_error_set(error, EINVAL,
1417 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1418 NULL, "No Rx queues configured");
1419 if (!rss->queue_num)
1420 return rte_flow_error_set(error, EINVAL,
1421 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1422 NULL, "No queues configured");
1423 for (i = 0; i != rss->queue_num; ++i) {
1424 if (rss->queue[i] >= priv->rxqs_n)
1425 return rte_flow_error_set
1427 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1428 &rss->queue[i], "queue index out of range");
1429 if (!(*priv->rxqs)[rss->queue[i]])
1430 return rte_flow_error_set
1431 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1432 &rss->queue[i], "queue is not configured");
1435 return rte_flow_error_set(error, ENOTSUP,
1436 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1437 "rss action not supported for "
1439 if (rss->level > 1 && !tunnel)
1440 return rte_flow_error_set(error, EINVAL,
1441 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1442 "inner RSS is not supported for "
1443 "non-tunnel flows");
1444 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1445 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1446 return rte_flow_error_set(error, EINVAL,
1447 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1448 "RSS on eCPRI is not supported now");
1454 * Validate the default miss action.
1456 * @param[in] action_flags
1457 * Bit-fields that holds the actions detected until now.
1459 * Pointer to error structure.
1462 * 0 on success, a negative errno value otherwise and rte_errno is set.
1465 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1466 const struct rte_flow_attr *attr,
1467 struct rte_flow_error *error)
1469 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1470 return rte_flow_error_set(error, EINVAL,
1471 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1472 "can't have 2 fate actions in"
1475 return rte_flow_error_set(error, ENOTSUP,
1476 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1477 "default miss action not supported "
1480 return rte_flow_error_set(error, ENOTSUP,
1481 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1482 "only group 0 is supported");
1484 return rte_flow_error_set(error, ENOTSUP,
1485 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1486 NULL, "transfer is not supported");
1491 * Validate the count action.
1494 * Pointer to the Ethernet device structure.
1496 * Attributes of flow that includes this action.
1498 * Pointer to error structure.
1501 * 0 on success, a negative errno value otherwise and rte_errno is set.
1504 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1505 const struct rte_flow_attr *attr,
1506 struct rte_flow_error *error)
1509 return rte_flow_error_set(error, ENOTSUP,
1510 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1511 "count action not supported for "
1517 * Verify the @p attributes will be correctly understood by the NIC and store
1518 * them in the @p flow if everything is correct.
1521 * Pointer to the Ethernet device structure.
1522 * @param[in] attributes
1523 * Pointer to flow attributes
1525 * Pointer to error structure.
1528 * 0 on success, a negative errno value otherwise and rte_errno is set.
1531 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1532 const struct rte_flow_attr *attributes,
1533 struct rte_flow_error *error)
1535 struct mlx5_priv *priv = dev->data->dev_private;
1536 uint32_t priority_max = priv->config.flow_prio - 1;
1538 if (attributes->group)
1539 return rte_flow_error_set(error, ENOTSUP,
1540 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1541 NULL, "groups is not supported");
1542 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1543 attributes->priority >= priority_max)
1544 return rte_flow_error_set(error, ENOTSUP,
1545 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1546 NULL, "priority out of range");
1547 if (attributes->egress)
1548 return rte_flow_error_set(error, ENOTSUP,
1549 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1550 "egress is not supported");
1551 if (attributes->transfer && !priv->config.dv_esw_en)
1552 return rte_flow_error_set(error, ENOTSUP,
1553 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1554 NULL, "transfer is not supported");
1555 if (!attributes->ingress)
1556 return rte_flow_error_set(error, EINVAL,
1557 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1559 "ingress attribute is mandatory");
1564 * Validate ICMP6 item.
1567 * Item specification.
1568 * @param[in] item_flags
1569 * Bit-fields that holds the items detected until now.
1571 * Pointer to error structure.
1574 * 0 on success, a negative errno value otherwise and rte_errno is set.
1577 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1578 uint64_t item_flags,
1579 uint8_t target_protocol,
1580 struct rte_flow_error *error)
1582 const struct rte_flow_item_icmp6 *mask = item->mask;
1583 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1584 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1585 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1586 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1587 MLX5_FLOW_LAYER_OUTER_L4;
1590 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1591 return rte_flow_error_set(error, EINVAL,
1592 RTE_FLOW_ERROR_TYPE_ITEM, item,
1593 "protocol filtering not compatible"
1594 " with ICMP6 layer");
1595 if (!(item_flags & l3m))
1596 return rte_flow_error_set(error, EINVAL,
1597 RTE_FLOW_ERROR_TYPE_ITEM, item,
1598 "IPv6 is mandatory to filter on"
1600 if (item_flags & l4m)
1601 return rte_flow_error_set(error, EINVAL,
1602 RTE_FLOW_ERROR_TYPE_ITEM, item,
1603 "multiple L4 layers not supported");
1605 mask = &rte_flow_item_icmp6_mask;
1606 ret = mlx5_flow_item_acceptable
1607 (item, (const uint8_t *)mask,
1608 (const uint8_t *)&rte_flow_item_icmp6_mask,
1609 sizeof(struct rte_flow_item_icmp6),
1610 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1617 * Validate ICMP item.
1620 * Item specification.
1621 * @param[in] item_flags
1622 * Bit-fields that holds the items detected until now.
1624 * Pointer to error structure.
1627 * 0 on success, a negative errno value otherwise and rte_errno is set.
1630 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1631 uint64_t item_flags,
1632 uint8_t target_protocol,
1633 struct rte_flow_error *error)
1635 const struct rte_flow_item_icmp *mask = item->mask;
1636 const struct rte_flow_item_icmp nic_mask = {
1637 .hdr.icmp_type = 0xff,
1638 .hdr.icmp_code = 0xff,
1639 .hdr.icmp_ident = RTE_BE16(0xffff),
1640 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
1642 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1643 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1644 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1645 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1646 MLX5_FLOW_LAYER_OUTER_L4;
1649 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1650 return rte_flow_error_set(error, EINVAL,
1651 RTE_FLOW_ERROR_TYPE_ITEM, item,
1652 "protocol filtering not compatible"
1653 " with ICMP layer");
1654 if (!(item_flags & l3m))
1655 return rte_flow_error_set(error, EINVAL,
1656 RTE_FLOW_ERROR_TYPE_ITEM, item,
1657 "IPv4 is mandatory to filter"
1659 if (item_flags & l4m)
1660 return rte_flow_error_set(error, EINVAL,
1661 RTE_FLOW_ERROR_TYPE_ITEM, item,
1662 "multiple L4 layers not supported");
1665 ret = mlx5_flow_item_acceptable
1666 (item, (const uint8_t *)mask,
1667 (const uint8_t *)&nic_mask,
1668 sizeof(struct rte_flow_item_icmp),
1669 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1676 * Validate Ethernet item.
1679 * Item specification.
1680 * @param[in] item_flags
1681 * Bit-fields that holds the items detected until now.
1683 * Pointer to error structure.
1686 * 0 on success, a negative errno value otherwise and rte_errno is set.
1689 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1690 uint64_t item_flags,
1691 struct rte_flow_error *error)
1693 const struct rte_flow_item_eth *mask = item->mask;
1694 const struct rte_flow_item_eth nic_mask = {
1695 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1696 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1697 .type = RTE_BE16(0xffff),
1700 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1701 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1702 MLX5_FLOW_LAYER_OUTER_L2;
1704 if (item_flags & ethm)
1705 return rte_flow_error_set(error, ENOTSUP,
1706 RTE_FLOW_ERROR_TYPE_ITEM, item,
1707 "multiple L2 layers not supported");
1708 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1709 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1710 return rte_flow_error_set(error, EINVAL,
1711 RTE_FLOW_ERROR_TYPE_ITEM, item,
1712 "L2 layer should not follow "
1714 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1715 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1716 return rte_flow_error_set(error, EINVAL,
1717 RTE_FLOW_ERROR_TYPE_ITEM, item,
1718 "L2 layer should not follow VLAN");
1720 mask = &rte_flow_item_eth_mask;
1721 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1722 (const uint8_t *)&nic_mask,
1723 sizeof(struct rte_flow_item_eth),
1724 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1729 * Validate VLAN item.
1732 * Item specification.
1733 * @param[in] item_flags
1734 * Bit-fields that holds the items detected until now.
1736 * Ethernet device flow is being created on.
1738 * Pointer to error structure.
1741 * 0 on success, a negative errno value otherwise and rte_errno is set.
1744 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1745 uint64_t item_flags,
1746 struct rte_eth_dev *dev,
1747 struct rte_flow_error *error)
1749 const struct rte_flow_item_vlan *spec = item->spec;
1750 const struct rte_flow_item_vlan *mask = item->mask;
1751 const struct rte_flow_item_vlan nic_mask = {
1752 .tci = RTE_BE16(UINT16_MAX),
1753 .inner_type = RTE_BE16(UINT16_MAX),
1755 uint16_t vlan_tag = 0;
1756 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1758 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1759 MLX5_FLOW_LAYER_INNER_L4) :
1760 (MLX5_FLOW_LAYER_OUTER_L3 |
1761 MLX5_FLOW_LAYER_OUTER_L4);
1762 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1763 MLX5_FLOW_LAYER_OUTER_VLAN;
1765 if (item_flags & vlanm)
1766 return rte_flow_error_set(error, EINVAL,
1767 RTE_FLOW_ERROR_TYPE_ITEM, item,
1768 "multiple VLAN layers not supported");
1769 else if ((item_flags & l34m) != 0)
1770 return rte_flow_error_set(error, EINVAL,
1771 RTE_FLOW_ERROR_TYPE_ITEM, item,
1772 "VLAN cannot follow L3/L4 layer");
1774 mask = &rte_flow_item_vlan_mask;
1775 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1776 (const uint8_t *)&nic_mask,
1777 sizeof(struct rte_flow_item_vlan),
1778 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1781 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1782 struct mlx5_priv *priv = dev->data->dev_private;
1784 if (priv->vmwa_context) {
1786 * Non-NULL context means we have a virtual machine
1787 * and SR-IOV enabled, we have to create VLAN interface
1788 * to make hypervisor to setup E-Switch vport
1789 * context correctly. We avoid creating the multiple
1790 * VLAN interfaces, so we cannot support VLAN tag mask.
1792 return rte_flow_error_set(error, EINVAL,
1793 RTE_FLOW_ERROR_TYPE_ITEM,
1795 "VLAN tag mask is not"
1796 " supported in virtual"
1801 vlan_tag = spec->tci;
1802 vlan_tag &= mask->tci;
1805 * From verbs perspective an empty VLAN is equivalent
1806 * to a packet without VLAN layer.
1809 return rte_flow_error_set(error, EINVAL,
1810 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1812 "VLAN cannot be empty");
1817 * Validate IPV4 item.
1820 * Item specification.
1821 * @param[in] item_flags
1822 * Bit-fields that holds the items detected until now.
1823 * @param[in] last_item
1824 * Previous validated item in the pattern items.
1825 * @param[in] ether_type
1826 * Type in the ethernet layer header (including dot1q).
1827 * @param[in] acc_mask
1828 * Acceptable mask, if NULL default internal default mask
1829 * will be used to check whether item fields are supported.
1830 * @param[in] range_accepted
1831 * True if range of values is accepted for specific fields, false otherwise.
1833 * Pointer to error structure.
1836 * 0 on success, a negative errno value otherwise and rte_errno is set.
1839 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1840 uint64_t item_flags,
1842 uint16_t ether_type,
1843 const struct rte_flow_item_ipv4 *acc_mask,
1844 bool range_accepted,
1845 struct rte_flow_error *error)
1847 const struct rte_flow_item_ipv4 *mask = item->mask;
1848 const struct rte_flow_item_ipv4 *spec = item->spec;
1849 const struct rte_flow_item_ipv4 nic_mask = {
1851 .src_addr = RTE_BE32(0xffffffff),
1852 .dst_addr = RTE_BE32(0xffffffff),
1853 .type_of_service = 0xff,
1854 .next_proto_id = 0xff,
1857 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1858 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1859 MLX5_FLOW_LAYER_OUTER_L3;
1860 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1861 MLX5_FLOW_LAYER_OUTER_L4;
1863 uint8_t next_proto = 0xFF;
1864 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1865 MLX5_FLOW_LAYER_OUTER_VLAN |
1866 MLX5_FLOW_LAYER_INNER_VLAN);
1868 if ((last_item & l2_vlan) && ether_type &&
1869 ether_type != RTE_ETHER_TYPE_IPV4)
1870 return rte_flow_error_set(error, EINVAL,
1871 RTE_FLOW_ERROR_TYPE_ITEM, item,
1872 "IPv4 cannot follow L2/VLAN layer "
1873 "which ether type is not IPv4");
1874 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1876 next_proto = mask->hdr.next_proto_id &
1877 spec->hdr.next_proto_id;
1878 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1879 return rte_flow_error_set(error, EINVAL,
1880 RTE_FLOW_ERROR_TYPE_ITEM,
1885 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1886 return rte_flow_error_set(error, EINVAL,
1887 RTE_FLOW_ERROR_TYPE_ITEM, item,
1888 "wrong tunnel type - IPv6 specified "
1889 "but IPv4 item provided");
1890 if (item_flags & l3m)
1891 return rte_flow_error_set(error, ENOTSUP,
1892 RTE_FLOW_ERROR_TYPE_ITEM, item,
1893 "multiple L3 layers not supported");
1894 else if (item_flags & l4m)
1895 return rte_flow_error_set(error, EINVAL,
1896 RTE_FLOW_ERROR_TYPE_ITEM, item,
1897 "L3 cannot follow an L4 layer.");
1898 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1899 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1900 return rte_flow_error_set(error, EINVAL,
1901 RTE_FLOW_ERROR_TYPE_ITEM, item,
1902 "L3 cannot follow an NVGRE layer.");
1904 mask = &rte_flow_item_ipv4_mask;
1905 else if (mask->hdr.next_proto_id != 0 &&
1906 mask->hdr.next_proto_id != 0xff)
1907 return rte_flow_error_set(error, EINVAL,
1908 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1909 "partial mask is not supported"
1911 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1912 acc_mask ? (const uint8_t *)acc_mask
1913 : (const uint8_t *)&nic_mask,
1914 sizeof(struct rte_flow_item_ipv4),
1915 range_accepted, error);
1922 * Validate IPV6 item.
1925 * Item specification.
1926 * @param[in] item_flags
1927 * Bit-fields that holds the items detected until now.
1928 * @param[in] last_item
1929 * Previous validated item in the pattern items.
1930 * @param[in] ether_type
1931 * Type in the ethernet layer header (including dot1q).
1932 * @param[in] acc_mask
1933 * Acceptable mask, if NULL default internal default mask
1934 * will be used to check whether item fields are supported.
1936 * Pointer to error structure.
1939 * 0 on success, a negative errno value otherwise and rte_errno is set.
1942 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1943 uint64_t item_flags,
1945 uint16_t ether_type,
1946 const struct rte_flow_item_ipv6 *acc_mask,
1947 struct rte_flow_error *error)
1949 const struct rte_flow_item_ipv6 *mask = item->mask;
1950 const struct rte_flow_item_ipv6 *spec = item->spec;
1951 const struct rte_flow_item_ipv6 nic_mask = {
1954 "\xff\xff\xff\xff\xff\xff\xff\xff"
1955 "\xff\xff\xff\xff\xff\xff\xff\xff",
1957 "\xff\xff\xff\xff\xff\xff\xff\xff"
1958 "\xff\xff\xff\xff\xff\xff\xff\xff",
1959 .vtc_flow = RTE_BE32(0xffffffff),
1963 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1964 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1965 MLX5_FLOW_LAYER_OUTER_L3;
1966 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1967 MLX5_FLOW_LAYER_OUTER_L4;
1969 uint8_t next_proto = 0xFF;
1970 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1971 MLX5_FLOW_LAYER_OUTER_VLAN |
1972 MLX5_FLOW_LAYER_INNER_VLAN);
1974 if ((last_item & l2_vlan) && ether_type &&
1975 ether_type != RTE_ETHER_TYPE_IPV6)
1976 return rte_flow_error_set(error, EINVAL,
1977 RTE_FLOW_ERROR_TYPE_ITEM, item,
1978 "IPv6 cannot follow L2/VLAN layer "
1979 "which ether type is not IPv6");
1980 if (mask && mask->hdr.proto == UINT8_MAX && spec)
1981 next_proto = spec->hdr.proto;
1982 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
1983 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1984 return rte_flow_error_set(error, EINVAL,
1985 RTE_FLOW_ERROR_TYPE_ITEM,
1990 if (next_proto == IPPROTO_HOPOPTS ||
1991 next_proto == IPPROTO_ROUTING ||
1992 next_proto == IPPROTO_FRAGMENT ||
1993 next_proto == IPPROTO_ESP ||
1994 next_proto == IPPROTO_AH ||
1995 next_proto == IPPROTO_DSTOPTS)
1996 return rte_flow_error_set(error, EINVAL,
1997 RTE_FLOW_ERROR_TYPE_ITEM, item,
1998 "IPv6 proto (next header) should "
1999 "not be set as extension header");
2000 if (item_flags & MLX5_FLOW_LAYER_IPIP)
2001 return rte_flow_error_set(error, EINVAL,
2002 RTE_FLOW_ERROR_TYPE_ITEM, item,
2003 "wrong tunnel type - IPv4 specified "
2004 "but IPv6 item provided");
2005 if (item_flags & l3m)
2006 return rte_flow_error_set(error, ENOTSUP,
2007 RTE_FLOW_ERROR_TYPE_ITEM, item,
2008 "multiple L3 layers not supported");
2009 else if (item_flags & l4m)
2010 return rte_flow_error_set(error, EINVAL,
2011 RTE_FLOW_ERROR_TYPE_ITEM, item,
2012 "L3 cannot follow an L4 layer.");
2013 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2014 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2015 return rte_flow_error_set(error, EINVAL,
2016 RTE_FLOW_ERROR_TYPE_ITEM, item,
2017 "L3 cannot follow an NVGRE layer.");
2019 mask = &rte_flow_item_ipv6_mask;
2020 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2021 acc_mask ? (const uint8_t *)acc_mask
2022 : (const uint8_t *)&nic_mask,
2023 sizeof(struct rte_flow_item_ipv6),
2024 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2031 * Validate UDP item.
2034 * Item specification.
2035 * @param[in] item_flags
2036 * Bit-fields that holds the items detected until now.
2037 * @param[in] target_protocol
2038 * The next protocol in the previous item.
2039 * @param[in] flow_mask
2040 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
2042 * Pointer to error structure.
2045 * 0 on success, a negative errno value otherwise and rte_errno is set.
2048 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
2049 uint64_t item_flags,
2050 uint8_t target_protocol,
2051 struct rte_flow_error *error)
2053 const struct rte_flow_item_udp *mask = item->mask;
2054 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2055 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2056 MLX5_FLOW_LAYER_OUTER_L3;
2057 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2058 MLX5_FLOW_LAYER_OUTER_L4;
2061 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
2062 return rte_flow_error_set(error, EINVAL,
2063 RTE_FLOW_ERROR_TYPE_ITEM, item,
2064 "protocol filtering not compatible"
2066 if (!(item_flags & l3m))
2067 return rte_flow_error_set(error, EINVAL,
2068 RTE_FLOW_ERROR_TYPE_ITEM, item,
2069 "L3 is mandatory to filter on L4");
2070 if (item_flags & l4m)
2071 return rte_flow_error_set(error, EINVAL,
2072 RTE_FLOW_ERROR_TYPE_ITEM, item,
2073 "multiple L4 layers not supported");
2075 mask = &rte_flow_item_udp_mask;
2076 ret = mlx5_flow_item_acceptable
2077 (item, (const uint8_t *)mask,
2078 (const uint8_t *)&rte_flow_item_udp_mask,
2079 sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2087 * Validate TCP item.
2090 * Item specification.
2091 * @param[in] item_flags
2092 * Bit-fields that holds the items detected until now.
2093 * @param[in] target_protocol
2094 * The next protocol in the previous item.
2096 * Pointer to error structure.
2099 * 0 on success, a negative errno value otherwise and rte_errno is set.
2102 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
2103 uint64_t item_flags,
2104 uint8_t target_protocol,
2105 const struct rte_flow_item_tcp *flow_mask,
2106 struct rte_flow_error *error)
2108 const struct rte_flow_item_tcp *mask = item->mask;
2109 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2110 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2111 MLX5_FLOW_LAYER_OUTER_L3;
2112 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2113 MLX5_FLOW_LAYER_OUTER_L4;
2116 MLX5_ASSERT(flow_mask);
2117 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
2118 return rte_flow_error_set(error, EINVAL,
2119 RTE_FLOW_ERROR_TYPE_ITEM, item,
2120 "protocol filtering not compatible"
2122 if (!(item_flags & l3m))
2123 return rte_flow_error_set(error, EINVAL,
2124 RTE_FLOW_ERROR_TYPE_ITEM, item,
2125 "L3 is mandatory to filter on L4");
2126 if (item_flags & l4m)
2127 return rte_flow_error_set(error, EINVAL,
2128 RTE_FLOW_ERROR_TYPE_ITEM, item,
2129 "multiple L4 layers not supported");
2131 mask = &rte_flow_item_tcp_mask;
2132 ret = mlx5_flow_item_acceptable
2133 (item, (const uint8_t *)mask,
2134 (const uint8_t *)flow_mask,
2135 sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2143 * Validate VXLAN item.
2146 * Item specification.
2147 * @param[in] item_flags
2148 * Bit-fields that holds the items detected until now.
2149 * @param[in] target_protocol
2150 * The next protocol in the previous item.
2152 * Pointer to error structure.
2155 * 0 on success, a negative errno value otherwise and rte_errno is set.
2158 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
2159 uint64_t item_flags,
2160 struct rte_flow_error *error)
2162 const struct rte_flow_item_vxlan *spec = item->spec;
2163 const struct rte_flow_item_vxlan *mask = item->mask;
2168 } id = { .vlan_id = 0, };
2171 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2172 return rte_flow_error_set(error, ENOTSUP,
2173 RTE_FLOW_ERROR_TYPE_ITEM, item,
2174 "multiple tunnel layers not"
2177 * Verify only UDPv4 is present as defined in
2178 * https://tools.ietf.org/html/rfc7348
2180 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2181 return rte_flow_error_set(error, EINVAL,
2182 RTE_FLOW_ERROR_TYPE_ITEM, item,
2183 "no outer UDP layer found");
2185 mask = &rte_flow_item_vxlan_mask;
2186 ret = mlx5_flow_item_acceptable
2187 (item, (const uint8_t *)mask,
2188 (const uint8_t *)&rte_flow_item_vxlan_mask,
2189 sizeof(struct rte_flow_item_vxlan),
2190 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2194 memcpy(&id.vni[1], spec->vni, 3);
2195 memcpy(&id.vni[1], mask->vni, 3);
2197 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2198 return rte_flow_error_set(error, ENOTSUP,
2199 RTE_FLOW_ERROR_TYPE_ITEM, item,
2200 "VXLAN tunnel must be fully defined");
2205 * Validate VXLAN_GPE item.
2208 * Item specification.
2209 * @param[in] item_flags
2210 * Bit-fields that holds the items detected until now.
2212 * Pointer to the private data structure.
2213 * @param[in] target_protocol
2214 * The next protocol in the previous item.
2216 * Pointer to error structure.
2219 * 0 on success, a negative errno value otherwise and rte_errno is set.
2222 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
2223 uint64_t item_flags,
2224 struct rte_eth_dev *dev,
2225 struct rte_flow_error *error)
2227 struct mlx5_priv *priv = dev->data->dev_private;
2228 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
2229 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2234 } id = { .vlan_id = 0, };
2236 if (!priv->config.l3_vxlan_en)
2237 return rte_flow_error_set(error, ENOTSUP,
2238 RTE_FLOW_ERROR_TYPE_ITEM, item,
2239 "L3 VXLAN is not enabled by device"
2240 " parameter and/or not configured in"
2242 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2243 return rte_flow_error_set(error, ENOTSUP,
2244 RTE_FLOW_ERROR_TYPE_ITEM, item,
2245 "multiple tunnel layers not"
2248 * Verify only UDPv4 is present as defined in
2249 * https://tools.ietf.org/html/rfc7348
2251 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2252 return rte_flow_error_set(error, EINVAL,
2253 RTE_FLOW_ERROR_TYPE_ITEM, item,
2254 "no outer UDP layer found");
2256 mask = &rte_flow_item_vxlan_gpe_mask;
2257 ret = mlx5_flow_item_acceptable
2258 (item, (const uint8_t *)mask,
2259 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2260 sizeof(struct rte_flow_item_vxlan_gpe),
2261 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2266 return rte_flow_error_set(error, ENOTSUP,
2267 RTE_FLOW_ERROR_TYPE_ITEM,
2269 "VxLAN-GPE protocol"
2271 memcpy(&id.vni[1], spec->vni, 3);
2272 memcpy(&id.vni[1], mask->vni, 3);
2274 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2275 return rte_flow_error_set(error, ENOTSUP,
2276 RTE_FLOW_ERROR_TYPE_ITEM, item,
2277 "VXLAN-GPE tunnel must be fully"
2282 * Validate GRE Key item.
2285 * Item specification.
2286 * @param[in] item_flags
2287 * Bit flags to mark detected items.
2288 * @param[in] gre_item
2289 * Pointer to gre_item
2291 * Pointer to error structure.
2294 * 0 on success, a negative errno value otherwise and rte_errno is set.
2297 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2298 uint64_t item_flags,
2299 const struct rte_flow_item *gre_item,
2300 struct rte_flow_error *error)
2302 const rte_be32_t *mask = item->mask;
2304 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2305 const struct rte_flow_item_gre *gre_spec;
2306 const struct rte_flow_item_gre *gre_mask;
2308 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2309 return rte_flow_error_set(error, ENOTSUP,
2310 RTE_FLOW_ERROR_TYPE_ITEM, item,
2311 "Multiple GRE key not support");
2312 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2313 return rte_flow_error_set(error, ENOTSUP,
2314 RTE_FLOW_ERROR_TYPE_ITEM, item,
2315 "No preceding GRE header");
2316 if (item_flags & MLX5_FLOW_LAYER_INNER)
2317 return rte_flow_error_set(error, ENOTSUP,
2318 RTE_FLOW_ERROR_TYPE_ITEM, item,
2319 "GRE key following a wrong item");
2320 gre_mask = gre_item->mask;
2322 gre_mask = &rte_flow_item_gre_mask;
2323 gre_spec = gre_item->spec;
2324 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2325 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2326 return rte_flow_error_set(error, EINVAL,
2327 RTE_FLOW_ERROR_TYPE_ITEM, item,
2328 "Key bit must be on");
2331 mask = &gre_key_default_mask;
2332 ret = mlx5_flow_item_acceptable
2333 (item, (const uint8_t *)mask,
2334 (const uint8_t *)&gre_key_default_mask,
2335 sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2340 * Validate GRE item.
2343 * Item specification.
2344 * @param[in] item_flags
2345 * Bit flags to mark detected items.
2346 * @param[in] target_protocol
2347 * The next protocol in the previous item.
2349 * Pointer to error structure.
2352 * 0 on success, a negative errno value otherwise and rte_errno is set.
2355 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2356 uint64_t item_flags,
2357 uint8_t target_protocol,
2358 struct rte_flow_error *error)
2360 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2361 const struct rte_flow_item_gre *mask = item->mask;
2363 const struct rte_flow_item_gre nic_mask = {
2364 .c_rsvd0_ver = RTE_BE16(0xB000),
2365 .protocol = RTE_BE16(UINT16_MAX),
2368 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2369 return rte_flow_error_set(error, EINVAL,
2370 RTE_FLOW_ERROR_TYPE_ITEM, item,
2371 "protocol filtering not compatible"
2372 " with this GRE layer");
2373 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2374 return rte_flow_error_set(error, ENOTSUP,
2375 RTE_FLOW_ERROR_TYPE_ITEM, item,
2376 "multiple tunnel layers not"
2378 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2379 return rte_flow_error_set(error, ENOTSUP,
2380 RTE_FLOW_ERROR_TYPE_ITEM, item,
2381 "L3 Layer is missing");
2383 mask = &rte_flow_item_gre_mask;
2384 ret = mlx5_flow_item_acceptable
2385 (item, (const uint8_t *)mask,
2386 (const uint8_t *)&nic_mask,
2387 sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
2391 #ifndef HAVE_MLX5DV_DR
2392 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2393 if (spec && (spec->protocol & mask->protocol))
2394 return rte_flow_error_set(error, ENOTSUP,
2395 RTE_FLOW_ERROR_TYPE_ITEM, item,
2396 "without MPLS support the"
2397 " specification cannot be used for"
2405 * Validate Geneve item.
2408 * Item specification.
2409 * @param[in] itemFlags
2410 * Bit-fields that holds the items detected until now.
2412 * Pointer to the private data structure.
2414 * Pointer to error structure.
2417 * 0 on success, a negative errno value otherwise and rte_errno is set.
2421 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2422 uint64_t item_flags,
2423 struct rte_eth_dev *dev,
2424 struct rte_flow_error *error)
2426 struct mlx5_priv *priv = dev->data->dev_private;
2427 const struct rte_flow_item_geneve *spec = item->spec;
2428 const struct rte_flow_item_geneve *mask = item->mask;
2431 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2432 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2433 const struct rte_flow_item_geneve nic_mask = {
2434 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2435 .vni = "\xff\xff\xff",
2436 .protocol = RTE_BE16(UINT16_MAX),
2439 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2440 return rte_flow_error_set(error, ENOTSUP,
2441 RTE_FLOW_ERROR_TYPE_ITEM, item,
2442 "L3 Geneve is not enabled by device"
2443 " parameter and/or not configured in"
2445 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2446 return rte_flow_error_set(error, ENOTSUP,
2447 RTE_FLOW_ERROR_TYPE_ITEM, item,
2448 "multiple tunnel layers not"
2451 * Verify only UDPv4 is present as defined in
2452 * https://tools.ietf.org/html/rfc7348
2454 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2455 return rte_flow_error_set(error, EINVAL,
2456 RTE_FLOW_ERROR_TYPE_ITEM, item,
2457 "no outer UDP layer found");
2459 mask = &rte_flow_item_geneve_mask;
2460 ret = mlx5_flow_item_acceptable
2461 (item, (const uint8_t *)mask,
2462 (const uint8_t *)&nic_mask,
2463 sizeof(struct rte_flow_item_geneve),
2464 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2468 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2469 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2470 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2471 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2472 return rte_flow_error_set(error, ENOTSUP,
2473 RTE_FLOW_ERROR_TYPE_ITEM,
2475 "Geneve protocol unsupported"
2476 " fields are being used");
2477 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2478 return rte_flow_error_set
2480 RTE_FLOW_ERROR_TYPE_ITEM,
2482 "Unsupported Geneve options length");
2484 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2485 return rte_flow_error_set
2487 RTE_FLOW_ERROR_TYPE_ITEM, item,
2488 "Geneve tunnel must be fully defined");
2493 * Validate MPLS item.
2496 * Pointer to the rte_eth_dev structure.
2498 * Item specification.
2499 * @param[in] item_flags
2500 * Bit-fields that holds the items detected until now.
2501 * @param[in] prev_layer
2502 * The protocol layer indicated in previous item.
2504 * Pointer to error structure.
2507 * 0 on success, a negative errno value otherwise and rte_errno is set.
2510 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2511 const struct rte_flow_item *item __rte_unused,
2512 uint64_t item_flags __rte_unused,
2513 uint64_t prev_layer __rte_unused,
2514 struct rte_flow_error *error)
2516 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2517 const struct rte_flow_item_mpls *mask = item->mask;
2518 struct mlx5_priv *priv = dev->data->dev_private;
2521 if (!priv->config.mpls_en)
2522 return rte_flow_error_set(error, ENOTSUP,
2523 RTE_FLOW_ERROR_TYPE_ITEM, item,
2524 "MPLS not supported or"
2525 " disabled in firmware"
2527 /* MPLS over IP, UDP, GRE is allowed */
2528 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2529 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2530 MLX5_FLOW_LAYER_GRE)))
2531 return rte_flow_error_set(error, EINVAL,
2532 RTE_FLOW_ERROR_TYPE_ITEM, item,
2533 "protocol filtering not compatible"
2534 " with MPLS layer");
2535 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2536 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2537 !(item_flags & MLX5_FLOW_LAYER_GRE))
2538 return rte_flow_error_set(error, ENOTSUP,
2539 RTE_FLOW_ERROR_TYPE_ITEM, item,
2540 "multiple tunnel layers not"
2543 mask = &rte_flow_item_mpls_mask;
2544 ret = mlx5_flow_item_acceptable
2545 (item, (const uint8_t *)mask,
2546 (const uint8_t *)&rte_flow_item_mpls_mask,
2547 sizeof(struct rte_flow_item_mpls),
2548 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2553 return rte_flow_error_set(error, ENOTSUP,
2554 RTE_FLOW_ERROR_TYPE_ITEM, item,
2555 "MPLS is not supported by Verbs, please"
2561 * Validate NVGRE item.
2564 * Item specification.
2565 * @param[in] item_flags
2566 * Bit flags to mark detected items.
2567 * @param[in] target_protocol
2568 * The next protocol in the previous item.
2570 * Pointer to error structure.
2573 * 0 on success, a negative errno value otherwise and rte_errno is set.
2576 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2577 uint64_t item_flags,
2578 uint8_t target_protocol,
2579 struct rte_flow_error *error)
2581 const struct rte_flow_item_nvgre *mask = item->mask;
2584 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2585 return rte_flow_error_set(error, EINVAL,
2586 RTE_FLOW_ERROR_TYPE_ITEM, item,
2587 "protocol filtering not compatible"
2588 " with this GRE layer");
2589 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2590 return rte_flow_error_set(error, ENOTSUP,
2591 RTE_FLOW_ERROR_TYPE_ITEM, item,
2592 "multiple tunnel layers not"
2594 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2595 return rte_flow_error_set(error, ENOTSUP,
2596 RTE_FLOW_ERROR_TYPE_ITEM, item,
2597 "L3 Layer is missing");
2599 mask = &rte_flow_item_nvgre_mask;
2600 ret = mlx5_flow_item_acceptable
2601 (item, (const uint8_t *)mask,
2602 (const uint8_t *)&rte_flow_item_nvgre_mask,
2603 sizeof(struct rte_flow_item_nvgre),
2604 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2611 * Validate eCPRI item.
2614 * Item specification.
2615 * @param[in] item_flags
2616 * Bit-fields that holds the items detected until now.
2617 * @param[in] last_item
2618 * Previous validated item in the pattern items.
2619 * @param[in] ether_type
2620 * Type in the ethernet layer header (including dot1q).
2621 * @param[in] acc_mask
2622 * Acceptable mask, if NULL default internal default mask
2623 * will be used to check whether item fields are supported.
2625 * Pointer to error structure.
2628 * 0 on success, a negative errno value otherwise and rte_errno is set.
2631 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
2632 uint64_t item_flags,
2634 uint16_t ether_type,
2635 const struct rte_flow_item_ecpri *acc_mask,
2636 struct rte_flow_error *error)
2638 const struct rte_flow_item_ecpri *mask = item->mask;
2639 const struct rte_flow_item_ecpri nic_mask = {
2643 RTE_BE32(((const struct rte_ecpri_common_hdr) {
2647 .dummy[0] = 0xFFFFFFFF,
2650 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
2651 MLX5_FLOW_LAYER_OUTER_VLAN);
2652 struct rte_flow_item_ecpri mask_lo;
2654 if ((last_item & outer_l2_vlan) && ether_type &&
2655 ether_type != RTE_ETHER_TYPE_ECPRI)
2656 return rte_flow_error_set(error, EINVAL,
2657 RTE_FLOW_ERROR_TYPE_ITEM, item,
2658 "eCPRI cannot follow L2/VLAN layer "
2659 "which ether type is not 0xAEFE.");
2660 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2661 return rte_flow_error_set(error, EINVAL,
2662 RTE_FLOW_ERROR_TYPE_ITEM, item,
2663 "eCPRI with tunnel is not supported "
2665 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
2666 return rte_flow_error_set(error, ENOTSUP,
2667 RTE_FLOW_ERROR_TYPE_ITEM, item,
2668 "multiple L3 layers not supported");
2669 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
2670 return rte_flow_error_set(error, EINVAL,
2671 RTE_FLOW_ERROR_TYPE_ITEM, item,
2672 "eCPRI cannot follow a TCP layer.");
2673 /* In specification, eCPRI could be over UDP layer. */
2674 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
2675 return rte_flow_error_set(error, EINVAL,
2676 RTE_FLOW_ERROR_TYPE_ITEM, item,
2677 "eCPRI over UDP layer is not yet "
2678 "supported right now.");
2679 /* Mask for type field in common header could be zero. */
2681 mask = &rte_flow_item_ecpri_mask;
2682 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
2683 /* Input mask is in big-endian format. */
2684 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
2685 return rte_flow_error_set(error, EINVAL,
2686 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2687 "partial mask is not supported "
2689 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
2690 return rte_flow_error_set(error, EINVAL,
2691 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2692 "message header mask must be after "
2694 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2695 acc_mask ? (const uint8_t *)acc_mask
2696 : (const uint8_t *)&nic_mask,
2697 sizeof(struct rte_flow_item_ecpri),
2698 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2701 /* Allocate unique ID for the split Q/RSS subflows. */
2703 flow_qrss_get_id(struct rte_eth_dev *dev)
2705 struct mlx5_priv *priv = dev->data->dev_private;
2706 uint32_t qrss_id, ret;
2708 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2711 MLX5_ASSERT(qrss_id);
2715 /* Free unique ID for the split Q/RSS subflows. */
2717 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2719 struct mlx5_priv *priv = dev->data->dev_private;
2722 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2726 * Release resource related QUEUE/RSS action split.
2729 * Pointer to Ethernet device.
2731 * Flow to release id's from.
2734 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2735 struct rte_flow *flow)
2737 struct mlx5_priv *priv = dev->data->dev_private;
2738 uint32_t handle_idx;
2739 struct mlx5_flow_handle *dev_handle;
2741 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
2742 handle_idx, dev_handle, next)
2743 if (dev_handle->split_flow_id)
2744 flow_qrss_free_id(dev, dev_handle->split_flow_id);
2748 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2749 const struct rte_flow_attr *attr __rte_unused,
2750 const struct rte_flow_item items[] __rte_unused,
2751 const struct rte_flow_action actions[] __rte_unused,
2752 bool external __rte_unused,
2753 int hairpin __rte_unused,
2754 struct rte_flow_error *error)
2756 return rte_flow_error_set(error, ENOTSUP,
2757 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2760 static struct mlx5_flow *
2761 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
2762 const struct rte_flow_attr *attr __rte_unused,
2763 const struct rte_flow_item items[] __rte_unused,
2764 const struct rte_flow_action actions[] __rte_unused,
2765 struct rte_flow_error *error)
2767 rte_flow_error_set(error, ENOTSUP,
2768 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2773 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2774 struct mlx5_flow *dev_flow __rte_unused,
2775 const struct rte_flow_attr *attr __rte_unused,
2776 const struct rte_flow_item items[] __rte_unused,
2777 const struct rte_flow_action actions[] __rte_unused,
2778 struct rte_flow_error *error)
2780 return rte_flow_error_set(error, ENOTSUP,
2781 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2785 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2786 struct rte_flow *flow __rte_unused,
2787 struct rte_flow_error *error)
2789 return rte_flow_error_set(error, ENOTSUP,
2790 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2794 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2795 struct rte_flow *flow __rte_unused)
2800 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2801 struct rte_flow *flow __rte_unused)
2806 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2807 struct rte_flow *flow __rte_unused,
2808 const struct rte_flow_action *actions __rte_unused,
2809 void *data __rte_unused,
2810 struct rte_flow_error *error)
2812 return rte_flow_error_set(error, ENOTSUP,
2813 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2816 /* Void driver to protect from null pointer reference. */
2817 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2818 .validate = flow_null_validate,
2819 .prepare = flow_null_prepare,
2820 .translate = flow_null_translate,
2821 .apply = flow_null_apply,
2822 .remove = flow_null_remove,
2823 .destroy = flow_null_destroy,
2824 .query = flow_null_query,
2828 * Select flow driver type according to flow attributes and device
2832 * Pointer to the dev structure.
2834 * Pointer to the flow attributes.
2837 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2839 static enum mlx5_flow_drv_type
2840 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2842 struct mlx5_priv *priv = dev->data->dev_private;
2843 /* The OS can determine first a specific flow type (DV, VERBS) */
2844 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
2846 if (type != MLX5_FLOW_TYPE_MAX)
2848 /* If no OS specific type - continue with DV/VERBS selection */
2849 if (attr->transfer && priv->config.dv_esw_en)
2850 type = MLX5_FLOW_TYPE_DV;
2851 if (!attr->transfer)
2852 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2853 MLX5_FLOW_TYPE_VERBS;
2857 #define flow_get_drv_ops(type) flow_drv_ops[type]
2860 * Flow driver validation API. This abstracts calling driver specific functions.
2861 * The type of flow driver is determined according to flow attributes.
2864 * Pointer to the dev structure.
2866 * Pointer to the flow attributes.
2868 * Pointer to the list of items.
2869 * @param[in] actions
2870 * Pointer to the list of actions.
2871 * @param[in] external
2872 * This flow rule is created by request external to PMD.
2873 * @param[in] hairpin
2874 * Number of hairpin TX actions, 0 means classic flow.
2876 * Pointer to the error structure.
2879 * 0 on success, a negative errno value otherwise and rte_errno is set.
2882 flow_drv_validate(struct rte_eth_dev *dev,
2883 const struct rte_flow_attr *attr,
2884 const struct rte_flow_item items[],
2885 const struct rte_flow_action actions[],
2886 bool external, int hairpin, struct rte_flow_error *error)
2888 const struct mlx5_flow_driver_ops *fops;
2889 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2891 fops = flow_get_drv_ops(type);
2892 return fops->validate(dev, attr, items, actions, external,
2897 * Flow driver preparation API. This abstracts calling driver specific
2898 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2899 * calculates the size of memory required for device flow, allocates the memory,
2900 * initializes the device flow and returns the pointer.
2903 * This function initializes device flow structure such as dv or verbs in
2904 * struct mlx5_flow. However, it is caller's responsibility to initialize the
2905 * rest. For example, adding returning device flow to flow->dev_flow list and
2906 * setting backward reference to the flow should be done out of this function.
2907 * layers field is not filled either.
2910 * Pointer to the dev structure.
2912 * Pointer to the flow attributes.
2914 * Pointer to the list of items.
2915 * @param[in] actions
2916 * Pointer to the list of actions.
2917 * @param[in] flow_idx
2918 * This memory pool index to the flow.
2920 * Pointer to the error structure.
2923 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
2925 static inline struct mlx5_flow *
2926 flow_drv_prepare(struct rte_eth_dev *dev,
2927 const struct rte_flow *flow,
2928 const struct rte_flow_attr *attr,
2929 const struct rte_flow_item items[],
2930 const struct rte_flow_action actions[],
2932 struct rte_flow_error *error)
2934 const struct mlx5_flow_driver_ops *fops;
2935 enum mlx5_flow_drv_type type = flow->drv_type;
2936 struct mlx5_flow *mlx5_flow = NULL;
2938 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2939 fops = flow_get_drv_ops(type);
2940 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
2942 mlx5_flow->flow_idx = flow_idx;
2947 * Flow driver translation API. This abstracts calling driver specific
2948 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2949 * translates a generic flow into a driver flow. flow_drv_prepare() must
2953 * dev_flow->layers could be filled as a result of parsing during translation
2954 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
2955 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
2956 * flow->actions could be overwritten even though all the expanded dev_flows
2957 * have the same actions.
2960 * Pointer to the rte dev structure.
2961 * @param[in, out] dev_flow
2962 * Pointer to the mlx5 flow.
2964 * Pointer to the flow attributes.
2966 * Pointer to the list of items.
2967 * @param[in] actions
2968 * Pointer to the list of actions.
2970 * Pointer to the error structure.
2973 * 0 on success, a negative errno value otherwise and rte_errno is set.
2976 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
2977 const struct rte_flow_attr *attr,
2978 const struct rte_flow_item items[],
2979 const struct rte_flow_action actions[],
2980 struct rte_flow_error *error)
2982 const struct mlx5_flow_driver_ops *fops;
2983 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
2985 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2986 fops = flow_get_drv_ops(type);
2987 return fops->translate(dev, dev_flow, attr, items, actions, error);
2991 * Flow driver apply API. This abstracts calling driver specific functions.
2992 * Parent flow (rte_flow) should have driver type (drv_type). It applies
2993 * translated driver flows on to device. flow_drv_translate() must precede.
2996 * Pointer to Ethernet device structure.
2997 * @param[in, out] flow
2998 * Pointer to flow structure.
3000 * Pointer to error structure.
3003 * 0 on success, a negative errno value otherwise and rte_errno is set.
3006 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
3007 struct rte_flow_error *error)
3009 const struct mlx5_flow_driver_ops *fops;
3010 enum mlx5_flow_drv_type type = flow->drv_type;
3012 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3013 fops = flow_get_drv_ops(type);
3014 return fops->apply(dev, flow, error);
3018 * Flow driver remove API. This abstracts calling driver specific functions.
3019 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3020 * on device. All the resources of the flow should be freed by calling
3021 * flow_drv_destroy().
3024 * Pointer to Ethernet device.
3025 * @param[in, out] flow
3026 * Pointer to flow structure.
3029 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
3031 const struct mlx5_flow_driver_ops *fops;
3032 enum mlx5_flow_drv_type type = flow->drv_type;
3034 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3035 fops = flow_get_drv_ops(type);
3036 fops->remove(dev, flow);
3040 * Flow driver destroy API. This abstracts calling driver specific functions.
3041 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
3042 * on device and releases resources of the flow.
3045 * Pointer to Ethernet device.
3046 * @param[in, out] flow
3047 * Pointer to flow structure.
3050 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
3052 const struct mlx5_flow_driver_ops *fops;
3053 enum mlx5_flow_drv_type type = flow->drv_type;
3055 flow_mreg_split_qrss_release(dev, flow);
3056 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
3057 fops = flow_get_drv_ops(type);
3058 fops->destroy(dev, flow);
3062 * Get RSS action from the action list.
3064 * @param[in] actions
3065 * Pointer to the list of actions.
3068 * Pointer to the RSS action if exist, else return NULL.
3070 static const struct rte_flow_action_rss*
3071 flow_get_rss_action(const struct rte_flow_action actions[])
3073 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3074 switch (actions->type) {
3075 case RTE_FLOW_ACTION_TYPE_RSS:
3076 return (const struct rte_flow_action_rss *)
3086 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
3088 const struct rte_flow_item *item;
3089 unsigned int has_vlan = 0;
3091 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3092 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
3098 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
3099 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
3100 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
3101 MLX5_EXPANSION_ROOT_OUTER;
3105 * Get layer flags from the prefix flow.
3107 * Some flows may be split to several subflows, the prefix subflow gets the
3108 * match items and the suffix sub flow gets the actions.
3109 * Some actions need the user defined match item flags to get the detail for
3111 * This function helps the suffix flow to get the item layer flags from prefix
3114 * @param[in] dev_flow
3115 * Pointer the created preifx subflow.
3118 * The layers get from prefix subflow.
3120 static inline uint64_t
3121 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
3123 uint64_t layers = 0;
3126 * Layers bits could be localization, but usually the compiler will
3127 * help to do the optimization work for source code.
3128 * If no decap actions, use the layers directly.
3130 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
3131 return dev_flow->handle->layers;
3132 /* Convert L3 layers with decap action. */
3133 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
3134 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3135 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
3136 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3137 /* Convert L4 layers with decap action. */
3138 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
3139 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
3140 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
3141 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
3146 * Get metadata split action information.
3148 * @param[in] actions
3149 * Pointer to the list of actions.
3151 * Pointer to the return pointer.
3152 * @param[out] qrss_type
3153 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
3154 * if no QUEUE/RSS is found.
3155 * @param[out] encap_idx
3156 * Pointer to the index of the encap action if exists, otherwise the last
3160 * Total number of actions.
3163 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
3164 const struct rte_flow_action **qrss,
3167 const struct rte_flow_action_raw_encap *raw_encap;
3169 int raw_decap_idx = -1;
3172 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3173 switch (actions->type) {
3174 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3175 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3176 *encap_idx = actions_n;
3178 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3179 raw_decap_idx = actions_n;
3181 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3182 raw_encap = actions->conf;
3183 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3184 *encap_idx = raw_decap_idx != -1 ?
3185 raw_decap_idx : actions_n;
3187 case RTE_FLOW_ACTION_TYPE_QUEUE:
3188 case RTE_FLOW_ACTION_TYPE_RSS:
3196 if (*encap_idx == -1)
3197 *encap_idx = actions_n;
3198 /* Count RTE_FLOW_ACTION_TYPE_END. */
3199 return actions_n + 1;
3203 * Check meter action from the action list.
3205 * @param[in] actions
3206 * Pointer to the list of actions.
3208 * Pointer to the meter exist flag.
3211 * Total number of actions.
3214 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
3220 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3221 switch (actions->type) {
3222 case RTE_FLOW_ACTION_TYPE_METER:
3230 /* Count RTE_FLOW_ACTION_TYPE_END. */
3231 return actions_n + 1;
3235 * Check if the flow should be split due to hairpin.
3236 * The reason for the split is that in current HW we can't
3237 * support encap and push-vlan on Rx, so if a flow contains
3238 * these actions we move it to Tx.
3241 * Pointer to Ethernet device.
3243 * Flow rule attributes.
3244 * @param[in] actions
3245 * Associated actions (list terminated by the END action).
3248 * > 0 the number of actions and the flow should be split,
3249 * 0 when no split required.
3252 flow_check_hairpin_split(struct rte_eth_dev *dev,
3253 const struct rte_flow_attr *attr,
3254 const struct rte_flow_action actions[])
3256 int queue_action = 0;
3259 const struct rte_flow_action_queue *queue;
3260 const struct rte_flow_action_rss *rss;
3261 const struct rte_flow_action_raw_encap *raw_encap;
3265 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3266 switch (actions->type) {
3267 case RTE_FLOW_ACTION_TYPE_QUEUE:
3268 queue = actions->conf;
3271 if (mlx5_rxq_get_type(dev, queue->index) !=
3272 MLX5_RXQ_TYPE_HAIRPIN)
3277 case RTE_FLOW_ACTION_TYPE_RSS:
3278 rss = actions->conf;
3279 if (rss == NULL || rss->queue_num == 0)
3281 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
3282 MLX5_RXQ_TYPE_HAIRPIN)
3287 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3288 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3289 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3290 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3291 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3295 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3296 raw_encap = actions->conf;
3297 if (raw_encap->size >
3298 (sizeof(struct rte_flow_item_eth) +
3299 sizeof(struct rte_flow_item_ipv4)))
3308 if (split && queue_action)
3313 /* Declare flow create/destroy prototype in advance. */
3315 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
3316 const struct rte_flow_attr *attr,
3317 const struct rte_flow_item items[],
3318 const struct rte_flow_action actions[],
3319 bool external, struct rte_flow_error *error);
3322 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
3326 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3328 * As mark_id is unique, if there's already a registered flow for the mark_id,
3329 * return by increasing the reference counter of the resource. Otherwise, create
3330 * the resource (mcp_res) and flow.
3333 * - If ingress port is ANY and reg_c[1] is mark_id,
3334 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3336 * For default flow (zero mark_id), flow is like,
3337 * - If ingress port is ANY,
3338 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
3341 * Pointer to Ethernet device.
3343 * ID of MARK action, zero means default flow for META.
3345 * Perform verbose error reporting if not NULL.
3348 * Associated resource on success, NULL otherwise and rte_errno is set.
3350 static struct mlx5_flow_mreg_copy_resource *
3351 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
3352 struct rte_flow_error *error)
3354 struct mlx5_priv *priv = dev->data->dev_private;
3355 struct rte_flow_attr attr = {
3356 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3359 struct mlx5_rte_flow_item_tag tag_spec = {
3362 struct rte_flow_item items[] = {
3363 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
3365 struct rte_flow_action_mark ftag = {
3368 struct mlx5_flow_action_copy_mreg cp_mreg = {
3372 struct rte_flow_action_jump jump = {
3373 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3375 struct rte_flow_action actions[] = {
3376 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
3378 struct mlx5_flow_mreg_copy_resource *mcp_res;
3382 /* Fill the register fileds in the flow. */
3383 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3387 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3391 /* Check if already registered. */
3392 MLX5_ASSERT(priv->mreg_cp_tbl);
3393 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
3395 /* For non-default rule. */
3396 if (mark_id != MLX5_DEFAULT_COPY_ID)
3398 MLX5_ASSERT(mark_id != MLX5_DEFAULT_COPY_ID ||
3399 mcp_res->refcnt == 1);
3402 /* Provide the full width of FLAG specific value. */
3403 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3404 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3405 /* Build a new flow. */
3406 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3407 items[0] = (struct rte_flow_item){
3408 .type = (enum rte_flow_item_type)
3409 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3412 items[1] = (struct rte_flow_item){
3413 .type = RTE_FLOW_ITEM_TYPE_END,
3415 actions[0] = (struct rte_flow_action){
3416 .type = (enum rte_flow_action_type)
3417 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3420 actions[1] = (struct rte_flow_action){
3421 .type = (enum rte_flow_action_type)
3422 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3425 actions[2] = (struct rte_flow_action){
3426 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3429 actions[3] = (struct rte_flow_action){
3430 .type = RTE_FLOW_ACTION_TYPE_END,
3433 /* Default rule, wildcard match. */
3434 attr.priority = MLX5_FLOW_PRIO_RSVD;
3435 items[0] = (struct rte_flow_item){
3436 .type = RTE_FLOW_ITEM_TYPE_END,
3438 actions[0] = (struct rte_flow_action){
3439 .type = (enum rte_flow_action_type)
3440 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3443 actions[1] = (struct rte_flow_action){
3444 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3447 actions[2] = (struct rte_flow_action){
3448 .type = RTE_FLOW_ACTION_TYPE_END,
3451 /* Build a new entry. */
3452 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3459 * The copy Flows are not included in any list. There
3460 * ones are referenced from other Flows and can not
3461 * be applied, removed, deleted in ardbitrary order
3462 * by list traversing.
3464 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3465 actions, false, error);
3466 if (!mcp_res->rix_flow)
3469 mcp_res->hlist_ent.key = mark_id;
3470 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3471 &mcp_res->hlist_ent);
3477 if (mcp_res->rix_flow)
3478 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3479 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3484 * Release flow in RX_CP_TBL.
3487 * Pointer to Ethernet device.
3489 * Parent flow for wich copying is provided.
3492 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3493 struct rte_flow *flow)
3495 struct mlx5_flow_mreg_copy_resource *mcp_res;
3496 struct mlx5_priv *priv = dev->data->dev_private;
3498 if (!flow->rix_mreg_copy)
3500 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3501 flow->rix_mreg_copy);
3502 if (!mcp_res || !priv->mreg_cp_tbl)
3504 if (flow->copy_applied) {
3505 MLX5_ASSERT(mcp_res->appcnt);
3506 flow->copy_applied = 0;
3508 if (!mcp_res->appcnt) {
3509 struct rte_flow *mcp_flow = mlx5_ipool_get
3510 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3514 flow_drv_remove(dev, mcp_flow);
3518 * We do not check availability of metadata registers here,
3519 * because copy resources are not allocated in this case.
3521 if (--mcp_res->refcnt)
3523 MLX5_ASSERT(mcp_res->rix_flow);
3524 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3525 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3526 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3527 flow->rix_mreg_copy = 0;
3531 * Start flow in RX_CP_TBL.
3534 * Pointer to Ethernet device.
3536 * Parent flow for wich copying is provided.
3539 * 0 on success, a negative errno value otherwise and rte_errno is set.
3542 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3543 struct rte_flow *flow)
3545 struct mlx5_flow_mreg_copy_resource *mcp_res;
3546 struct mlx5_priv *priv = dev->data->dev_private;
3549 if (!flow->rix_mreg_copy || flow->copy_applied)
3551 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3552 flow->rix_mreg_copy);
3555 if (!mcp_res->appcnt) {
3556 struct rte_flow *mcp_flow = mlx5_ipool_get
3557 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3561 ret = flow_drv_apply(dev, mcp_flow, NULL);
3567 flow->copy_applied = 1;
3572 * Stop flow in RX_CP_TBL.
3575 * Pointer to Ethernet device.
3577 * Parent flow for wich copying is provided.
3580 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3581 struct rte_flow *flow)
3583 struct mlx5_flow_mreg_copy_resource *mcp_res;
3584 struct mlx5_priv *priv = dev->data->dev_private;
3586 if (!flow->rix_mreg_copy || !flow->copy_applied)
3588 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3589 flow->rix_mreg_copy);
3592 MLX5_ASSERT(mcp_res->appcnt);
3594 flow->copy_applied = 0;
3595 if (!mcp_res->appcnt) {
3596 struct rte_flow *mcp_flow = mlx5_ipool_get
3597 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3601 flow_drv_remove(dev, mcp_flow);
3606 * Remove the default copy action from RX_CP_TBL.
3609 * Pointer to Ethernet device.
3612 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3614 struct mlx5_flow_mreg_copy_resource *mcp_res;
3615 struct mlx5_priv *priv = dev->data->dev_private;
3617 /* Check if default flow is registered. */
3618 if (!priv->mreg_cp_tbl)
3620 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3621 MLX5_DEFAULT_COPY_ID);
3624 MLX5_ASSERT(mcp_res->rix_flow);
3625 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3626 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3627 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3631 * Add the default copy action in in RX_CP_TBL.
3634 * Pointer to Ethernet device.
3636 * Perform verbose error reporting if not NULL.
3639 * 0 for success, negative value otherwise and rte_errno is set.
3642 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3643 struct rte_flow_error *error)
3645 struct mlx5_priv *priv = dev->data->dev_private;
3646 struct mlx5_flow_mreg_copy_resource *mcp_res;
3648 /* Check whether extensive metadata feature is engaged. */
3649 if (!priv->config.dv_flow_en ||
3650 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3651 !mlx5_flow_ext_mreg_supported(dev) ||
3652 !priv->sh->dv_regc0_mask)
3654 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3661 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3663 * All the flow having Q/RSS action should be split by
3664 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3665 * performs the following,
3666 * - CQE->flow_tag := reg_c[1] (MARK)
3667 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3668 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3669 * but there should be a flow per each MARK ID set by MARK action.
3671 * For the aforementioned reason, if there's a MARK action in flow's action
3672 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3673 * the MARK ID to CQE's flow_tag like,
3674 * - If reg_c[1] is mark_id,
3675 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3677 * For SET_META action which stores value in reg_c[0], as the destination is
3678 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3679 * MARK ID means the default flow. The default flow looks like,
3680 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3683 * Pointer to Ethernet device.
3685 * Pointer to flow structure.
3686 * @param[in] actions
3687 * Pointer to the list of actions.
3689 * Perform verbose error reporting if not NULL.
3692 * 0 on success, negative value otherwise and rte_errno is set.
3695 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3696 struct rte_flow *flow,
3697 const struct rte_flow_action *actions,
3698 struct rte_flow_error *error)
3700 struct mlx5_priv *priv = dev->data->dev_private;
3701 struct mlx5_dev_config *config = &priv->config;
3702 struct mlx5_flow_mreg_copy_resource *mcp_res;
3703 const struct rte_flow_action_mark *mark;
3705 /* Check whether extensive metadata feature is engaged. */
3706 if (!config->dv_flow_en ||
3707 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3708 !mlx5_flow_ext_mreg_supported(dev) ||
3709 !priv->sh->dv_regc0_mask)
3711 /* Find MARK action. */
3712 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3713 switch (actions->type) {
3714 case RTE_FLOW_ACTION_TYPE_FLAG:
3715 mcp_res = flow_mreg_add_copy_action
3716 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3719 flow->rix_mreg_copy = mcp_res->idx;
3720 if (dev->data->dev_started) {
3722 flow->copy_applied = 1;
3725 case RTE_FLOW_ACTION_TYPE_MARK:
3726 mark = (const struct rte_flow_action_mark *)
3729 flow_mreg_add_copy_action(dev, mark->id, error);
3732 flow->rix_mreg_copy = mcp_res->idx;
3733 if (dev->data->dev_started) {
3735 flow->copy_applied = 1;
3745 #define MLX5_MAX_SPLIT_ACTIONS 24
3746 #define MLX5_MAX_SPLIT_ITEMS 24
3749 * Split the hairpin flow.
3750 * Since HW can't support encap and push-vlan on Rx, we move these
3752 * If the count action is after the encap then we also
3753 * move the count action. in this case the count will also measure
3757 * Pointer to Ethernet device.
3758 * @param[in] actions
3759 * Associated actions (list terminated by the END action).
3760 * @param[out] actions_rx
3762 * @param[out] actions_tx
3764 * @param[out] pattern_tx
3765 * The pattern items for the Tx flow.
3766 * @param[out] flow_id
3767 * The flow ID connected to this flow.
3773 flow_hairpin_split(struct rte_eth_dev *dev,
3774 const struct rte_flow_action actions[],
3775 struct rte_flow_action actions_rx[],
3776 struct rte_flow_action actions_tx[],
3777 struct rte_flow_item pattern_tx[],
3780 struct mlx5_priv *priv = dev->data->dev_private;
3781 const struct rte_flow_action_raw_encap *raw_encap;
3782 const struct rte_flow_action_raw_decap *raw_decap;
3783 struct mlx5_rte_flow_action_set_tag *set_tag;
3784 struct rte_flow_action *tag_action;
3785 struct mlx5_rte_flow_item_tag *tag_item;
3786 struct rte_flow_item *item;
3790 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
3791 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3792 switch (actions->type) {
3793 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3794 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3795 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3796 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3797 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3798 rte_memcpy(actions_tx, actions,
3799 sizeof(struct rte_flow_action));
3802 case RTE_FLOW_ACTION_TYPE_COUNT:
3804 rte_memcpy(actions_tx, actions,
3805 sizeof(struct rte_flow_action));
3808 rte_memcpy(actions_rx, actions,
3809 sizeof(struct rte_flow_action));
3813 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3814 raw_encap = actions->conf;
3815 if (raw_encap->size >
3816 (sizeof(struct rte_flow_item_eth) +
3817 sizeof(struct rte_flow_item_ipv4))) {
3818 memcpy(actions_tx, actions,
3819 sizeof(struct rte_flow_action));
3823 rte_memcpy(actions_rx, actions,
3824 sizeof(struct rte_flow_action));
3828 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3829 raw_decap = actions->conf;
3830 if (raw_decap->size <
3831 (sizeof(struct rte_flow_item_eth) +
3832 sizeof(struct rte_flow_item_ipv4))) {
3833 memcpy(actions_tx, actions,
3834 sizeof(struct rte_flow_action));
3837 rte_memcpy(actions_rx, actions,
3838 sizeof(struct rte_flow_action));
3843 rte_memcpy(actions_rx, actions,
3844 sizeof(struct rte_flow_action));
3849 /* Add set meta action and end action for the Rx flow. */
3850 tag_action = actions_rx;
3851 tag_action->type = (enum rte_flow_action_type)
3852 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3854 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
3856 set_tag = (void *)actions_rx;
3857 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
3858 MLX5_ASSERT(set_tag->id > REG_NON);
3859 set_tag->data = *flow_id;
3860 tag_action->conf = set_tag;
3861 /* Create Tx item list. */
3862 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
3863 addr = (void *)&pattern_tx[2];
3865 item->type = (enum rte_flow_item_type)
3866 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3867 tag_item = (void *)addr;
3868 tag_item->data = *flow_id;
3869 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
3870 MLX5_ASSERT(set_tag->id > REG_NON);
3871 item->spec = tag_item;
3872 addr += sizeof(struct mlx5_rte_flow_item_tag);
3873 tag_item = (void *)addr;
3874 tag_item->data = UINT32_MAX;
3875 tag_item->id = UINT16_MAX;
3876 item->mask = tag_item;
3879 item->type = RTE_FLOW_ITEM_TYPE_END;
3884 * The last stage of splitting chain, just creates the subflow
3885 * without any modification.
3888 * Pointer to Ethernet device.
3890 * Parent flow structure pointer.
3891 * @param[in, out] sub_flow
3892 * Pointer to return the created subflow, may be NULL.
3893 * @param[in] prefix_layers
3894 * Prefix subflow layers, may be 0.
3895 * @param[in] prefix_mark
3896 * Prefix subflow mark flag, may be 0.
3898 * Flow rule attributes.
3900 * Pattern specification (list terminated by the END pattern item).
3901 * @param[in] actions
3902 * Associated actions (list terminated by the END action).
3903 * @param[in] external
3904 * This flow rule is created by request external to PMD.
3905 * @param[in] flow_idx
3906 * This memory pool index to the flow.
3908 * Perform verbose error reporting if not NULL.
3910 * 0 on success, negative value otherwise
3913 flow_create_split_inner(struct rte_eth_dev *dev,
3914 struct rte_flow *flow,
3915 struct mlx5_flow **sub_flow,
3916 uint64_t prefix_layers,
3917 uint32_t prefix_mark,
3918 const struct rte_flow_attr *attr,
3919 const struct rte_flow_item items[],
3920 const struct rte_flow_action actions[],
3921 bool external, uint32_t flow_idx,
3922 struct rte_flow_error *error)
3924 struct mlx5_flow *dev_flow;
3926 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
3930 dev_flow->flow = flow;
3931 dev_flow->external = external;
3932 /* Subflow object was created, we must include one in the list. */
3933 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
3934 dev_flow->handle, next);
3936 * If dev_flow is as one of the suffix flow, some actions in suffix
3937 * flow may need some user defined item layer flags, and pass the
3938 * Metadate rxq mark flag to suffix flow as well.
3941 dev_flow->handle->layers = prefix_layers;
3943 dev_flow->handle->mark = 1;
3945 *sub_flow = dev_flow;
3946 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
3950 * Split the meter flow.
3952 * As meter flow will split to three sub flow, other than meter
3953 * action, the other actions make sense to only meter accepts
3954 * the packet. If it need to be dropped, no other additional
3955 * actions should be take.
3957 * One kind of special action which decapsulates the L3 tunnel
3958 * header will be in the prefix sub flow, as not to take the
3959 * L3 tunnel header into account.
3962 * Pointer to Ethernet device.
3964 * Pattern specification (list terminated by the END pattern item).
3965 * @param[out] sfx_items
3966 * Suffix flow match items (list terminated by the END pattern item).
3967 * @param[in] actions
3968 * Associated actions (list terminated by the END action).
3969 * @param[out] actions_sfx
3970 * Suffix flow actions.
3971 * @param[out] actions_pre
3972 * Prefix flow actions.
3973 * @param[out] pattern_sfx
3974 * The pattern items for the suffix flow.
3975 * @param[out] tag_sfx
3976 * Pointer to suffix flow tag.
3982 flow_meter_split_prep(struct rte_eth_dev *dev,
3983 const struct rte_flow_item items[],
3984 struct rte_flow_item sfx_items[],
3985 const struct rte_flow_action actions[],
3986 struct rte_flow_action actions_sfx[],
3987 struct rte_flow_action actions_pre[])
3989 struct rte_flow_action *tag_action = NULL;
3990 struct rte_flow_item *tag_item;
3991 struct mlx5_rte_flow_action_set_tag *set_tag;
3992 struct rte_flow_error error;
3993 const struct rte_flow_action_raw_encap *raw_encap;
3994 const struct rte_flow_action_raw_decap *raw_decap;
3995 struct mlx5_rte_flow_item_tag *tag_spec;
3996 struct mlx5_rte_flow_item_tag *tag_mask;
3998 bool copy_vlan = false;
4000 /* Prepare the actions for prefix and suffix flow. */
4001 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4002 struct rte_flow_action **action_cur = NULL;
4004 switch (actions->type) {
4005 case RTE_FLOW_ACTION_TYPE_METER:
4006 /* Add the extra tag action first. */
4007 tag_action = actions_pre;
4008 tag_action->type = (enum rte_flow_action_type)
4009 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4011 action_cur = &actions_pre;
4013 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4014 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4015 action_cur = &actions_pre;
4017 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4018 raw_encap = actions->conf;
4019 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
4020 action_cur = &actions_pre;
4022 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4023 raw_decap = actions->conf;
4024 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4025 action_cur = &actions_pre;
4027 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4028 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4035 action_cur = &actions_sfx;
4036 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
4039 /* Add end action to the actions. */
4040 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
4041 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
4044 set_tag = (void *)actions_pre;
4045 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4047 * Get the id from the qrss_pool to make qrss share the id with meter.
4049 tag_id = flow_qrss_get_id(dev);
4050 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
4052 tag_action->conf = set_tag;
4053 /* Prepare the suffix subflow items. */
4054 tag_item = sfx_items++;
4055 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4056 int item_type = items->type;
4058 switch (item_type) {
4059 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4060 memcpy(sfx_items, items, sizeof(*sfx_items));
4063 case RTE_FLOW_ITEM_TYPE_VLAN:
4065 memcpy(sfx_items, items, sizeof(*sfx_items));
4067 * Convert to internal match item, it is used
4068 * for vlan push and set vid.
4070 sfx_items->type = (enum rte_flow_item_type)
4071 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
4079 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4081 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
4082 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
4083 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
4084 tag_mask = tag_spec + 1;
4085 tag_mask->data = 0xffffff00;
4086 tag_item->type = (enum rte_flow_item_type)
4087 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4088 tag_item->spec = tag_spec;
4089 tag_item->last = NULL;
4090 tag_item->mask = tag_mask;
4095 * Split action list having QUEUE/RSS for metadata register copy.
4097 * Once Q/RSS action is detected in user's action list, the flow action
4098 * should be split in order to copy metadata registers, which will happen in
4100 * - CQE->flow_tag := reg_c[1] (MARK)
4101 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
4102 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
4103 * This is because the last action of each flow must be a terminal action
4104 * (QUEUE, RSS or DROP).
4106 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
4107 * stored and kept in the mlx5_flow structure per each sub_flow.
4109 * The Q/RSS action is replaced with,
4110 * - SET_TAG, setting the allocated flow ID to reg_c[2].
4111 * And the following JUMP action is added at the end,
4112 * - JUMP, to RX_CP_TBL.
4114 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
4115 * flow_create_split_metadata() routine. The flow will look like,
4116 * - If flow ID matches (reg_c[2]), perform Q/RSS.
4119 * Pointer to Ethernet device.
4120 * @param[out] split_actions
4121 * Pointer to store split actions to jump to CP_TBL.
4122 * @param[in] actions
4123 * Pointer to the list of original flow actions.
4125 * Pointer to the Q/RSS action.
4126 * @param[in] actions_n
4127 * Number of original actions.
4129 * Perform verbose error reporting if not NULL.
4132 * non-zero unique flow_id on success, otherwise 0 and
4133 * error/rte_error are set.
4136 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
4137 struct rte_flow_action *split_actions,
4138 const struct rte_flow_action *actions,
4139 const struct rte_flow_action *qrss,
4140 int actions_n, struct rte_flow_error *error)
4142 struct mlx5_rte_flow_action_set_tag *set_tag;
4143 struct rte_flow_action_jump *jump;
4144 const int qrss_idx = qrss - actions;
4145 uint32_t flow_id = 0;
4149 * Given actions will be split
4150 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
4151 * - Add jump to mreg CP_TBL.
4152 * As a result, there will be one more action.
4155 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
4156 set_tag = (void *)(split_actions + actions_n);
4158 * If tag action is not set to void(it means we are not the meter
4159 * suffix flow), add the tag action. Since meter suffix flow already
4160 * has the tag added.
4162 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
4164 * Allocate the new subflow ID. This one is unique within
4165 * device and not shared with representors. Otherwise,
4166 * we would have to resolve multi-thread access synch
4167 * issue. Each flow on the shared device is appended
4168 * with source vport identifier, so the resulting
4169 * flows will be unique in the shared (by master and
4170 * representors) domain even if they have coinciding
4173 flow_id = flow_qrss_get_id(dev);
4175 return rte_flow_error_set(error, ENOMEM,
4176 RTE_FLOW_ERROR_TYPE_ACTION,
4177 NULL, "can't allocate id "
4178 "for split Q/RSS subflow");
4179 /* Internal SET_TAG action to set flow ID. */
4180 *set_tag = (struct mlx5_rte_flow_action_set_tag){
4183 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
4187 /* Construct new actions array. */
4188 /* Replace QUEUE/RSS action. */
4189 split_actions[qrss_idx] = (struct rte_flow_action){
4190 .type = (enum rte_flow_action_type)
4191 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4195 /* JUMP action to jump to mreg copy table (CP_TBL). */
4196 jump = (void *)(set_tag + 1);
4197 *jump = (struct rte_flow_action_jump){
4198 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
4200 split_actions[actions_n - 2] = (struct rte_flow_action){
4201 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4204 split_actions[actions_n - 1] = (struct rte_flow_action){
4205 .type = RTE_FLOW_ACTION_TYPE_END,
4211 * Extend the given action list for Tx metadata copy.
4213 * Copy the given action list to the ext_actions and add flow metadata register
4214 * copy action in order to copy reg_a set by WQE to reg_c[0].
4216 * @param[out] ext_actions
4217 * Pointer to the extended action list.
4218 * @param[in] actions
4219 * Pointer to the list of actions.
4220 * @param[in] actions_n
4221 * Number of actions in the list.
4223 * Perform verbose error reporting if not NULL.
4224 * @param[in] encap_idx
4225 * The encap action inndex.
4228 * 0 on success, negative value otherwise
4231 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
4232 struct rte_flow_action *ext_actions,
4233 const struct rte_flow_action *actions,
4234 int actions_n, struct rte_flow_error *error,
4237 struct mlx5_flow_action_copy_mreg *cp_mreg =
4238 (struct mlx5_flow_action_copy_mreg *)
4239 (ext_actions + actions_n + 1);
4242 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
4246 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
4251 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
4252 if (encap_idx == actions_n - 1) {
4253 ext_actions[actions_n - 1] = (struct rte_flow_action){
4254 .type = (enum rte_flow_action_type)
4255 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4258 ext_actions[actions_n] = (struct rte_flow_action){
4259 .type = RTE_FLOW_ACTION_TYPE_END,
4262 ext_actions[encap_idx] = (struct rte_flow_action){
4263 .type = (enum rte_flow_action_type)
4264 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4267 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
4268 sizeof(*ext_actions) * (actions_n - encap_idx));
4274 * Check the match action from the action list.
4276 * @param[in] actions
4277 * Pointer to the list of actions.
4279 * Flow rule attributes.
4281 * The action to be check if exist.
4282 * @param[out] match_action_pos
4283 * Pointer to the position of the matched action if exists, otherwise is -1.
4284 * @param[out] qrss_action_pos
4285 * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
4288 * > 0 the total number of actions.
4289 * 0 if not found match action in action list.
4292 flow_check_match_action(const struct rte_flow_action actions[],
4293 const struct rte_flow_attr *attr,
4294 enum rte_flow_action_type action,
4295 int *match_action_pos, int *qrss_action_pos)
4297 const struct rte_flow_action_sample *sample;
4304 *match_action_pos = -1;
4305 *qrss_action_pos = -1;
4306 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4307 if (actions->type == action) {
4309 *match_action_pos = actions_n;
4311 if (actions->type == RTE_FLOW_ACTION_TYPE_QUEUE ||
4312 actions->type == RTE_FLOW_ACTION_TYPE_RSS)
4313 *qrss_action_pos = actions_n;
4314 if (actions->type == RTE_FLOW_ACTION_TYPE_JUMP)
4316 if (actions->type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
4317 sample = actions->conf;
4318 ratio = sample->ratio;
4319 sub_type = ((const struct rte_flow_action *)
4320 (sample->actions))->type;
4324 if (flag && action == RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) {
4326 /* JUMP Action not support for Mirroring;
4327 * Mirroring support multi-destination;
4329 if (!jump_flag && sub_type != RTE_FLOW_ACTION_TYPE_END)
4333 /* Count RTE_FLOW_ACTION_TYPE_END. */
4334 return flag ? actions_n + 1 : 0;
4337 #define SAMPLE_SUFFIX_ITEM 2
4340 * Split the sample flow.
4342 * As sample flow will split to two sub flow, sample flow with
4343 * sample action, the other actions will move to new suffix flow.
4345 * Also add unique tag id with tag action in the sample flow,
4346 * the same tag id will be as match in the suffix flow.
4349 * Pointer to Ethernet device.
4351 * FDB egress flow flag.
4352 * @param[out] sfx_items
4353 * Suffix flow match items (list terminated by the END pattern item).
4354 * @param[in] actions
4355 * Associated actions (list terminated by the END action).
4356 * @param[out] actions_sfx
4357 * Suffix flow actions.
4358 * @param[out] actions_pre
4359 * Prefix flow actions.
4360 * @param[in] actions_n
4361 * The total number of actions.
4362 * @param[in] sample_action_pos
4363 * The sample action position.
4364 * @param[in] qrss_action_pos
4365 * The Queue/RSS action position.
4367 * Perform verbose error reporting if not NULL.
4370 * 0 on success, or unique flow_id, a negative errno value
4371 * otherwise and rte_errno is set.
4374 flow_sample_split_prep(struct rte_eth_dev *dev,
4376 struct rte_flow_item sfx_items[],
4377 const struct rte_flow_action actions[],
4378 struct rte_flow_action actions_sfx[],
4379 struct rte_flow_action actions_pre[],
4381 int sample_action_pos,
4382 int qrss_action_pos,
4383 struct rte_flow_error *error)
4385 struct mlx5_rte_flow_action_set_tag *set_tag;
4386 struct mlx5_rte_flow_item_tag *tag_spec;
4387 struct mlx5_rte_flow_item_tag *tag_mask;
4388 uint32_t tag_id = 0;
4392 if (sample_action_pos < 0)
4393 return rte_flow_error_set(error, EINVAL,
4394 RTE_FLOW_ERROR_TYPE_ACTION,
4395 NULL, "invalid position of sample "
4398 /* Prepare the prefix tag action. */
4399 set_tag = (void *)(actions_pre + actions_n + 1);
4400 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
4404 tag_id = flow_qrss_get_id(dev);
4405 set_tag->data = tag_id;
4406 /* Prepare the suffix subflow items. */
4407 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
4408 tag_spec->data = tag_id;
4409 tag_spec->id = set_tag->id;
4410 tag_mask = tag_spec + 1;
4411 tag_mask->data = UINT32_MAX;
4412 sfx_items[0] = (struct rte_flow_item){
4413 .type = (enum rte_flow_item_type)
4414 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4419 sfx_items[1] = (struct rte_flow_item){
4420 .type = (enum rte_flow_item_type)
4421 RTE_FLOW_ITEM_TYPE_END,
4424 /* Prepare the actions for prefix and suffix flow. */
4425 if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
4426 index = qrss_action_pos;
4427 /* Put the preceding the Queue/RSS action into prefix flow. */
4429 memcpy(actions_pre, actions,
4430 sizeof(struct rte_flow_action) * index);
4431 /* Put others preceding the sample action into prefix flow. */
4432 if (sample_action_pos > index + 1)
4433 memcpy(actions_pre + index, actions + index + 1,
4434 sizeof(struct rte_flow_action) *
4435 (sample_action_pos - index - 1));
4436 index = sample_action_pos - 1;
4437 /* Put Queue/RSS action into Suffix flow. */
4438 memcpy(actions_sfx, actions + qrss_action_pos,
4439 sizeof(struct rte_flow_action));
4442 index = sample_action_pos;
4444 memcpy(actions_pre, actions,
4445 sizeof(struct rte_flow_action) * index);
4447 /* Add the extra tag action for NIC-RX and E-Switch ingress. */
4449 actions_pre[index++] =
4450 (struct rte_flow_action){
4451 .type = (enum rte_flow_action_type)
4452 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
4456 memcpy(actions_pre + index, actions + sample_action_pos,
4457 sizeof(struct rte_flow_action));
4459 actions_pre[index] = (struct rte_flow_action){
4460 .type = (enum rte_flow_action_type)
4461 RTE_FLOW_ACTION_TYPE_END,
4463 /* Put the actions after sample into Suffix flow. */
4464 memcpy(actions_sfx, actions + sample_action_pos + 1,
4465 sizeof(struct rte_flow_action) *
4466 (actions_n - sample_action_pos - 1));
4471 * The splitting for metadata feature.
4473 * - Q/RSS action on NIC Rx should be split in order to pass by
4474 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4475 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4477 * - All the actions on NIC Tx should have a mreg copy action to
4478 * copy reg_a from WQE to reg_c[0].
4481 * Pointer to Ethernet device.
4483 * Parent flow structure pointer.
4484 * @param[in] prefix_layers
4485 * Prefix flow layer flags.
4486 * @param[in] prefix_mark
4487 * Prefix subflow mark flag, may be 0.
4489 * Flow rule attributes.
4491 * Pattern specification (list terminated by the END pattern item).
4492 * @param[in] actions
4493 * Associated actions (list terminated by the END action).
4494 * @param[in] external
4495 * This flow rule is created by request external to PMD.
4496 * @param[in] flow_idx
4497 * This memory pool index to the flow.
4499 * Perform verbose error reporting if not NULL.
4501 * 0 on success, negative value otherwise
4504 flow_create_split_metadata(struct rte_eth_dev *dev,
4505 struct rte_flow *flow,
4506 uint64_t prefix_layers,
4507 uint32_t prefix_mark,
4508 const struct rte_flow_attr *attr,
4509 const struct rte_flow_item items[],
4510 const struct rte_flow_action actions[],
4511 bool external, uint32_t flow_idx,
4512 struct rte_flow_error *error)
4514 struct mlx5_priv *priv = dev->data->dev_private;
4515 struct mlx5_dev_config *config = &priv->config;
4516 const struct rte_flow_action *qrss = NULL;
4517 struct rte_flow_action *ext_actions = NULL;
4518 struct mlx5_flow *dev_flow = NULL;
4519 uint32_t qrss_id = 0;
4526 /* Check whether extensive metadata feature is engaged. */
4527 if (!config->dv_flow_en ||
4528 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4529 !mlx5_flow_ext_mreg_supported(dev))
4530 return flow_create_split_inner(dev, flow, NULL, prefix_layers,
4531 prefix_mark, attr, items,
4532 actions, external, flow_idx,
4534 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
4537 /* Exclude hairpin flows from splitting. */
4538 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
4539 const struct rte_flow_action_queue *queue;
4542 if (mlx5_rxq_get_type(dev, queue->index) ==
4543 MLX5_RXQ_TYPE_HAIRPIN)
4545 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
4546 const struct rte_flow_action_rss *rss;
4549 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
4550 MLX5_RXQ_TYPE_HAIRPIN)
4555 /* Check if it is in meter suffix table. */
4556 mtr_sfx = attr->group == (attr->transfer ?
4557 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4558 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
4560 * Q/RSS action on NIC Rx should be split in order to pass by
4561 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4562 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4564 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
4565 sizeof(struct rte_flow_action_set_tag) +
4566 sizeof(struct rte_flow_action_jump);
4567 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
4570 return rte_flow_error_set(error, ENOMEM,
4571 RTE_FLOW_ERROR_TYPE_ACTION,
4572 NULL, "no memory to split "
4575 * If we are the suffix flow of meter, tag already exist.
4576 * Set the tag action to void.
4579 ext_actions[qrss - actions].type =
4580 RTE_FLOW_ACTION_TYPE_VOID;
4582 ext_actions[qrss - actions].type =
4583 (enum rte_flow_action_type)
4584 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4586 * Create the new actions list with removed Q/RSS action
4587 * and appended set tag and jump to register copy table
4588 * (RX_CP_TBL). We should preallocate unique tag ID here
4589 * in advance, because it is needed for set tag action.
4591 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
4592 qrss, actions_n, error);
4593 if (!mtr_sfx && !qrss_id) {
4597 } else if (attr->egress && !attr->transfer) {
4599 * All the actions on NIC Tx should have a metadata register
4600 * copy action to copy reg_a from WQE to reg_c[meta]
4602 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
4603 sizeof(struct mlx5_flow_action_copy_mreg);
4604 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
4607 return rte_flow_error_set(error, ENOMEM,
4608 RTE_FLOW_ERROR_TYPE_ACTION,
4609 NULL, "no memory to split "
4611 /* Create the action list appended with copy register. */
4612 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
4613 actions_n, error, encap_idx);
4617 /* Add the unmodified original or prefix subflow. */
4618 ret = flow_create_split_inner(dev, flow, &dev_flow, prefix_layers,
4620 items, ext_actions ? ext_actions :
4621 actions, external, flow_idx, error);
4624 MLX5_ASSERT(dev_flow);
4626 const struct rte_flow_attr q_attr = {
4627 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4630 /* Internal PMD action to set register. */
4631 struct mlx5_rte_flow_item_tag q_tag_spec = {
4635 struct rte_flow_item q_items[] = {
4637 .type = (enum rte_flow_item_type)
4638 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4639 .spec = &q_tag_spec,
4644 .type = RTE_FLOW_ITEM_TYPE_END,
4647 struct rte_flow_action q_actions[] = {
4653 .type = RTE_FLOW_ACTION_TYPE_END,
4656 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
4659 * Configure the tag item only if there is no meter subflow.
4660 * Since tag is already marked in the meter suffix subflow
4661 * we can just use the meter suffix items as is.
4664 /* Not meter subflow. */
4665 MLX5_ASSERT(!mtr_sfx);
4667 * Put unique id in prefix flow due to it is destroyed
4668 * after suffix flow and id will be freed after there
4669 * is no actual flows with this id and identifier
4670 * reallocation becomes possible (for example, for
4671 * other flows in other threads).
4673 dev_flow->handle->split_flow_id = qrss_id;
4674 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
4678 q_tag_spec.id = ret;
4681 /* Add suffix subflow to execute Q/RSS. */
4682 ret = flow_create_split_inner(dev, flow, &dev_flow, layers, 0,
4683 &q_attr, mtr_sfx ? items :
4685 external, flow_idx, error);
4688 /* qrss ID should be freed if failed. */
4690 MLX5_ASSERT(dev_flow);
4695 * We do not destroy the partially created sub_flows in case of error.
4696 * These ones are included into parent flow list and will be destroyed
4697 * by flow_drv_destroy.
4699 flow_qrss_free_id(dev, qrss_id);
4700 mlx5_free(ext_actions);
4705 * The splitting for meter feature.
4707 * - The meter flow will be split to two flows as prefix and
4708 * suffix flow. The packets make sense only it pass the prefix
4711 * - Reg_C_5 is used for the packet to match betweend prefix and
4715 * Pointer to Ethernet device.
4717 * Parent flow structure pointer.
4718 * @param[in] prefix_layers
4719 * Prefix subflow layers, may be 0.
4720 * @param[in] prefix_mark
4721 * Prefix subflow mark flag, may be 0.
4723 * Flow rule attributes.
4725 * Pattern specification (list terminated by the END pattern item).
4726 * @param[in] actions
4727 * Associated actions (list terminated by the END action).
4728 * @param[in] external
4729 * This flow rule is created by request external to PMD.
4730 * @param[in] flow_idx
4731 * This memory pool index to the flow.
4733 * Perform verbose error reporting if not NULL.
4735 * 0 on success, negative value otherwise
4738 flow_create_split_meter(struct rte_eth_dev *dev,
4739 struct rte_flow *flow,
4740 uint64_t prefix_layers,
4741 uint32_t prefix_mark,
4742 const struct rte_flow_attr *attr,
4743 const struct rte_flow_item items[],
4744 const struct rte_flow_action actions[],
4745 bool external, uint32_t flow_idx,
4746 struct rte_flow_error *error)
4748 struct mlx5_priv *priv = dev->data->dev_private;
4749 struct rte_flow_action *sfx_actions = NULL;
4750 struct rte_flow_action *pre_actions = NULL;
4751 struct rte_flow_item *sfx_items = NULL;
4752 struct mlx5_flow *dev_flow = NULL;
4753 struct rte_flow_attr sfx_attr = *attr;
4755 uint32_t mtr_tag_id = 0;
4762 actions_n = flow_check_meter_action(actions, &mtr);
4764 /* The five prefix actions: meter, decap, encap, tag, end. */
4765 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
4766 sizeof(struct mlx5_rte_flow_action_set_tag);
4767 /* tag, vlan, port id, end. */
4768 #define METER_SUFFIX_ITEM 4
4769 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
4770 sizeof(struct mlx5_rte_flow_item_tag) * 2;
4771 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
4774 return rte_flow_error_set(error, ENOMEM,
4775 RTE_FLOW_ERROR_TYPE_ACTION,
4776 NULL, "no memory to split "
4778 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4780 pre_actions = sfx_actions + actions_n;
4781 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
4782 actions, sfx_actions,
4788 /* Add the prefix subflow. */
4789 ret = flow_create_split_inner(dev, flow, &dev_flow,
4792 pre_actions, external,
4798 dev_flow->handle->split_flow_id = mtr_tag_id;
4799 /* Setting the sfx group atrr. */
4800 sfx_attr.group = sfx_attr.transfer ?
4801 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4802 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4804 /* Add the prefix subflow. */
4805 ret = flow_create_split_metadata(dev, flow, dev_flow ?
4806 flow_get_prefix_layer_flags(dev_flow) :
4807 prefix_layers, dev_flow ?
4808 dev_flow->handle->mark : prefix_mark,
4809 &sfx_attr, sfx_items ?
4811 sfx_actions ? sfx_actions : actions,
4812 external, flow_idx, error);
4815 mlx5_free(sfx_actions);
4820 * The splitting for sample feature.
4822 * Once Sample action is detected in the action list, the flow actions should
4823 * be split into prefix sub flow and suffix sub flow.
4825 * The original items remain in the prefix sub flow, all actions preceding the
4826 * sample action and the sample action itself will be copied to the prefix
4827 * sub flow, the actions following the sample action will be copied to the
4828 * suffix sub flow, Queue action always be located in the suffix sub flow.
4830 * In order to make the packet from prefix sub flow matches with suffix sub
4831 * flow, an extra tag action be added into prefix sub flow, and the suffix sub
4832 * flow uses tag item with the unique flow id.
4835 * Pointer to Ethernet device.
4837 * Parent flow structure pointer.
4839 * Flow rule attributes.
4841 * Pattern specification (list terminated by the END pattern item).
4842 * @param[in] actions
4843 * Associated actions (list terminated by the END action).
4844 * @param[in] external
4845 * This flow rule is created by request external to PMD.
4846 * @param[in] flow_idx
4847 * This memory pool index to the flow.
4849 * Perform verbose error reporting if not NULL.
4851 * 0 on success, negative value otherwise
4854 flow_create_split_sample(struct rte_eth_dev *dev,
4855 struct rte_flow *flow,
4856 const struct rte_flow_attr *attr,
4857 const struct rte_flow_item items[],
4858 const struct rte_flow_action actions[],
4859 bool external, uint32_t flow_idx,
4860 struct rte_flow_error *error)
4862 struct mlx5_priv *priv = dev->data->dev_private;
4863 struct rte_flow_action *sfx_actions = NULL;
4864 struct rte_flow_action *pre_actions = NULL;
4865 struct rte_flow_item *sfx_items = NULL;
4866 struct mlx5_flow *dev_flow = NULL;
4867 struct rte_flow_attr sfx_attr = *attr;
4868 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4869 struct mlx5_flow_dv_sample_resource *sample_res;
4870 struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
4871 struct mlx5_flow_tbl_resource *sfx_tbl;
4872 union mlx5_flow_tbl_key sfx_table_key;
4876 uint32_t fdb_tx = 0;
4879 int sample_action_pos;
4880 int qrss_action_pos;
4883 if (priv->sampler_en)
4884 actions_n = flow_check_match_action(actions, attr,
4885 RTE_FLOW_ACTION_TYPE_SAMPLE,
4886 &sample_action_pos, &qrss_action_pos);
4888 /* The prefix actions must includes sample, tag, end. */
4889 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
4890 + sizeof(struct mlx5_rte_flow_action_set_tag);
4891 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
4892 sizeof(struct mlx5_rte_flow_item_tag) * 2;
4893 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
4894 item_size), 0, SOCKET_ID_ANY);
4896 return rte_flow_error_set(error, ENOMEM,
4897 RTE_FLOW_ERROR_TYPE_ACTION,
4898 NULL, "no memory to split "
4900 /* The representor_id is -1 for uplink. */
4901 fdb_tx = (attr->transfer && priv->representor_id != -1);
4903 sfx_items = (struct rte_flow_item *)((char *)sfx_actions
4905 pre_actions = sfx_actions + actions_n;
4906 tag_id = flow_sample_split_prep(dev, fdb_tx, sfx_items,
4907 actions, sfx_actions,
4908 pre_actions, actions_n,
4910 qrss_action_pos, error);
4911 if (tag_id < 0 || (!fdb_tx && !tag_id)) {
4915 /* Add the prefix subflow. */
4916 ret = flow_create_split_inner(dev, flow, &dev_flow, 0, 0, attr,
4917 items, pre_actions, external,
4923 dev_flow->handle->split_flow_id = tag_id;
4924 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
4925 /* Set the sfx group attr. */
4926 sample_res = (struct mlx5_flow_dv_sample_resource *)
4927 dev_flow->dv.sample_res;
4928 sfx_tbl = (struct mlx5_flow_tbl_resource *)
4929 sample_res->normal_path_tbl;
4930 sfx_tbl_data = container_of(sfx_tbl,
4931 struct mlx5_flow_tbl_data_entry, tbl);
4932 sfx_table_key.v64 = sfx_tbl_data->entry.key;
4933 sfx_attr.group = sfx_attr.transfer ?
4934 (sfx_table_key.table_id - 1) :
4935 sfx_table_key.table_id;
4938 /* Add the suffix subflow. */
4939 ret = flow_create_split_meter(dev, flow, dev_flow ?
4940 flow_get_prefix_layer_flags(dev_flow) : 0,
4941 dev_flow ? dev_flow->handle->mark : 0,
4942 &sfx_attr, sfx_items ? sfx_items : items,
4943 sfx_actions ? sfx_actions : actions,
4944 external, flow_idx, error);
4947 mlx5_free(sfx_actions);
4952 * Split the flow to subflow set. The splitters might be linked
4953 * in the chain, like this:
4954 * flow_create_split_outer() calls:
4955 * flow_create_split_meter() calls:
4956 * flow_create_split_metadata(meter_subflow_0) calls:
4957 * flow_create_split_inner(metadata_subflow_0)
4958 * flow_create_split_inner(metadata_subflow_1)
4959 * flow_create_split_inner(metadata_subflow_2)
4960 * flow_create_split_metadata(meter_subflow_1) calls:
4961 * flow_create_split_inner(metadata_subflow_0)
4962 * flow_create_split_inner(metadata_subflow_1)
4963 * flow_create_split_inner(metadata_subflow_2)
4965 * This provide flexible way to add new levels of flow splitting.
4966 * The all of successfully created subflows are included to the
4967 * parent flow dev_flow list.
4970 * Pointer to Ethernet device.
4972 * Parent flow structure pointer.
4974 * Flow rule attributes.
4976 * Pattern specification (list terminated by the END pattern item).
4977 * @param[in] actions
4978 * Associated actions (list terminated by the END action).
4979 * @param[in] external
4980 * This flow rule is created by request external to PMD.
4981 * @param[in] flow_idx
4982 * This memory pool index to the flow.
4984 * Perform verbose error reporting if not NULL.
4986 * 0 on success, negative value otherwise
4989 flow_create_split_outer(struct rte_eth_dev *dev,
4990 struct rte_flow *flow,
4991 const struct rte_flow_attr *attr,
4992 const struct rte_flow_item items[],
4993 const struct rte_flow_action actions[],
4994 bool external, uint32_t flow_idx,
4995 struct rte_flow_error *error)
4999 ret = flow_create_split_sample(dev, flow, attr, items,
5000 actions, external, flow_idx, error);
5001 MLX5_ASSERT(ret <= 0);
5006 * Create a flow and add it to @p list.
5009 * Pointer to Ethernet device.
5011 * Pointer to a TAILQ flow list. If this parameter NULL,
5012 * no list insertion occurred, flow is just created,
5013 * this is caller's responsibility to track the
5016 * Flow rule attributes.
5018 * Pattern specification (list terminated by the END pattern item).
5019 * @param[in] actions
5020 * Associated actions (list terminated by the END action).
5021 * @param[in] external
5022 * This flow rule is created by request external to PMD.
5024 * Perform verbose error reporting if not NULL.
5027 * A flow index on success, 0 otherwise and rte_errno is set.
5030 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
5031 const struct rte_flow_attr *attr,
5032 const struct rte_flow_item items[],
5033 const struct rte_flow_action actions[],
5034 bool external, struct rte_flow_error *error)
5036 struct mlx5_priv *priv = dev->data->dev_private;
5037 struct rte_flow *flow = NULL;
5038 struct mlx5_flow *dev_flow;
5039 const struct rte_flow_action_rss *rss;
5041 struct mlx5_flow_expand_rss buf;
5042 uint8_t buffer[2048];
5045 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5046 uint8_t buffer[2048];
5049 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
5050 uint8_t buffer[2048];
5051 } actions_hairpin_tx;
5053 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
5054 uint8_t buffer[2048];
5056 struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
5057 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
5058 priv->rss_desc)[!!priv->flow_idx];
5059 const struct rte_flow_action *p_actions_rx = actions;
5063 uint32_t hairpin_id = 0;
5064 struct rte_flow_attr attr_tx = { .priority = 0 };
5065 struct rte_flow_attr attr_factor = {0};
5068 memcpy((void *)&attr_factor, (const void *)attr, sizeof(*attr));
5070 attr_factor.group *= MLX5_FLOW_TABLE_FACTOR;
5071 hairpin_flow = flow_check_hairpin_split(dev, &attr_factor, actions);
5072 ret = flow_drv_validate(dev, &attr_factor, items, p_actions_rx,
5073 external, hairpin_flow, error);
5076 if (hairpin_flow > 0) {
5077 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
5081 flow_hairpin_split(dev, actions, actions_rx.actions,
5082 actions_hairpin_tx.actions, items_tx.items,
5084 p_actions_rx = actions_rx.actions;
5086 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
5089 goto error_before_flow;
5091 flow->drv_type = flow_get_drv_type(dev, &attr_factor);
5092 if (hairpin_id != 0)
5093 flow->hairpin_flow_id = hairpin_id;
5094 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
5095 flow->drv_type < MLX5_FLOW_TYPE_MAX);
5096 memset(rss_desc, 0, sizeof(*rss_desc));
5097 rss = flow_get_rss_action(p_actions_rx);
5100 * The following information is required by
5101 * mlx5_flow_hashfields_adjust() in advance.
5103 rss_desc->level = rss->level;
5104 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
5105 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
5107 flow->dev_handles = 0;
5108 if (rss && rss->types) {
5109 unsigned int graph_root;
5111 graph_root = find_graph_root(items, rss->level);
5112 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
5114 mlx5_support_expansion, graph_root);
5115 MLX5_ASSERT(ret > 0 &&
5116 (unsigned int)ret < sizeof(expand_buffer.buffer));
5119 buf->entry[0].pattern = (void *)(uintptr_t)items;
5122 * Record the start index when there is a nested call. All sub-flows
5123 * need to be translated before another calling.
5124 * No need to use ping-pong buffer to save memory here.
5126 if (priv->flow_idx) {
5127 MLX5_ASSERT(!priv->flow_nested_idx);
5128 priv->flow_nested_idx = priv->flow_idx;
5130 for (i = 0; i < buf->entries; ++i) {
5132 * The splitter may create multiple dev_flows,
5133 * depending on configuration. In the simplest
5134 * case it just creates unmodified original flow.
5136 ret = flow_create_split_outer(dev, flow, &attr_factor,
5137 buf->entry[i].pattern,
5138 p_actions_rx, external, idx,
5143 /* Create the tx flow. */
5145 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
5146 attr_tx.ingress = 0;
5148 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
5149 actions_hairpin_tx.actions,
5153 dev_flow->flow = flow;
5154 dev_flow->external = 0;
5155 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5156 dev_flow->handle, next);
5157 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
5159 actions_hairpin_tx.actions, error);
5164 * Update the metadata register copy table. If extensive
5165 * metadata feature is enabled and registers are supported
5166 * we might create the extra rte_flow for each unique
5167 * MARK/FLAG action ID.
5169 * The table is updated for ingress Flows only, because
5170 * the egress Flows belong to the different device and
5171 * copy table should be updated in peer NIC Rx domain.
5173 if (attr_factor.ingress &&
5174 (external || attr_factor.group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
5175 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
5180 * If the flow is external (from application) OR device is started, then
5181 * the flow will be applied immediately.
5183 if (external || dev->data->dev_started) {
5184 ret = flow_drv_apply(dev, flow, error);
5189 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
5191 flow_rxq_flags_set(dev, flow);
5192 /* Nested flow creation index recovery. */
5193 priv->flow_idx = priv->flow_nested_idx;
5194 if (priv->flow_nested_idx)
5195 priv->flow_nested_idx = 0;
5199 ret = rte_errno; /* Save rte_errno before cleanup. */
5200 flow_mreg_del_copy_action(dev, flow);
5201 flow_drv_destroy(dev, flow);
5202 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
5203 rte_errno = ret; /* Restore rte_errno. */
5207 mlx5_flow_id_release(priv->sh->flow_id_pool,
5210 priv->flow_idx = priv->flow_nested_idx;
5211 if (priv->flow_nested_idx)
5212 priv->flow_nested_idx = 0;
5217 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
5218 * incoming packets to table 1.
5220 * Other flow rules, requested for group n, will be created in
5221 * e-switch table n+1.
5222 * Jump action to e-switch group n will be created to group n+1.
5224 * Used when working in switchdev mode, to utilise advantages of table 1
5228 * Pointer to Ethernet device.
5231 * Pointer to flow on success, NULL otherwise and rte_errno is set.
5234 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
5236 const struct rte_flow_attr attr = {
5243 const struct rte_flow_item pattern = {
5244 .type = RTE_FLOW_ITEM_TYPE_END,
5246 struct rte_flow_action_jump jump = {
5249 const struct rte_flow_action actions[] = {
5251 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5255 .type = RTE_FLOW_ACTION_TYPE_END,
5258 struct mlx5_priv *priv = dev->data->dev_private;
5259 struct rte_flow_error error;
5261 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
5263 actions, false, &error);
5267 * Validate a flow supported by the NIC.
5269 * @see rte_flow_validate()
5273 mlx5_flow_validate(struct rte_eth_dev *dev,
5274 const struct rte_flow_attr *attr,
5275 const struct rte_flow_item items[],
5276 const struct rte_flow_action actions[],
5277 struct rte_flow_error *error)
5281 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
5282 return flow_drv_validate(dev, attr, items, actions,
5283 true, hairpin_flow, error);
5289 * @see rte_flow_create()
5293 mlx5_flow_create(struct rte_eth_dev *dev,
5294 const struct rte_flow_attr *attr,
5295 const struct rte_flow_item items[],
5296 const struct rte_flow_action actions[],
5297 struct rte_flow_error *error)
5299 struct mlx5_priv *priv = dev->data->dev_private;
5302 * If the device is not started yet, it is not allowed to created a
5303 * flow from application. PMD default flows and traffic control flows
5306 if (unlikely(!dev->data->dev_started)) {
5307 DRV_LOG(DEBUG, "port %u is not started when "
5308 "inserting a flow", dev->data->port_id);
5309 rte_flow_error_set(error, ENODEV,
5310 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5312 "port not started");
5315 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
5316 attr, items, actions, true, error);
5320 * Destroy a flow in a list.
5323 * Pointer to Ethernet device.
5325 * Pointer to the Indexed flow list. If this parameter NULL,
5326 * there is no flow removal from the list. Be noted that as
5327 * flow is add to the indexed list, memory of the indexed
5328 * list points to maybe changed as flow destroyed.
5329 * @param[in] flow_idx
5330 * Index of flow to destroy.
5333 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
5336 struct mlx5_priv *priv = dev->data->dev_private;
5337 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5338 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5339 [MLX5_IPOOL_RTE_FLOW], flow_idx);
5344 * Update RX queue flags only if port is started, otherwise it is
5347 if (dev->data->dev_started)
5348 flow_rxq_flags_trim(dev, flow);
5349 if (flow->hairpin_flow_id)
5350 mlx5_flow_id_release(priv->sh->flow_id_pool,
5351 flow->hairpin_flow_id);
5352 flow_drv_destroy(dev, flow);
5354 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
5355 flow_idx, flow, next);
5356 flow_mreg_del_copy_action(dev, flow);
5358 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
5359 if (priv_fdir_flow->rix_flow == flow_idx)
5362 if (priv_fdir_flow) {
5363 LIST_REMOVE(priv_fdir_flow, next);
5364 mlx5_free(priv_fdir_flow->fdir);
5365 mlx5_free(priv_fdir_flow);
5368 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5372 * Destroy all flows.
5375 * Pointer to Ethernet device.
5377 * Pointer to the Indexed flow list.
5379 * If flushing is called avtively.
5382 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
5384 uint32_t num_flushed = 0;
5387 flow_list_destroy(dev, list, *list);
5391 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
5392 dev->data->port_id, num_flushed);
5400 * Pointer to Ethernet device.
5402 * Pointer to the Indexed flow list.
5405 mlx5_flow_stop(struct rte_eth_dev *dev, uint32_t *list)
5407 struct mlx5_priv *priv = dev->data->dev_private;
5408 struct rte_flow *flow = NULL;
5411 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
5413 flow_drv_remove(dev, flow);
5414 flow_mreg_stop_copy_action(dev, flow);
5416 flow_mreg_del_default_copy_action(dev);
5417 flow_rxq_flags_clear(dev);
5424 * Pointer to Ethernet device.
5426 * Pointer to the Indexed flow list.
5429 * 0 on success, a negative errno value otherwise and rte_errno is set.
5432 mlx5_flow_start(struct rte_eth_dev *dev, uint32_t *list)
5434 struct mlx5_priv *priv = dev->data->dev_private;
5435 struct rte_flow *flow = NULL;
5436 struct rte_flow_error error;
5440 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
5441 ret = flow_mreg_add_default_copy_action(dev, &error);
5444 /* Apply Flows created by application. */
5445 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
5447 ret = flow_mreg_start_copy_action(dev, flow);
5450 ret = flow_drv_apply(dev, flow, &error);
5453 flow_rxq_flags_set(dev, flow);
5457 ret = rte_errno; /* Save rte_errno before cleanup. */
5458 mlx5_flow_stop(dev, list);
5459 rte_errno = ret; /* Restore rte_errno. */
5464 * Stop all default actions for flows.
5467 * Pointer to Ethernet device.
5470 mlx5_flow_stop_default(struct rte_eth_dev *dev)
5472 flow_mreg_del_default_copy_action(dev);
5473 flow_rxq_flags_clear(dev);
5477 * Start all default actions for flows.
5480 * Pointer to Ethernet device.
5482 * 0 on success, a negative errno value otherwise and rte_errno is set.
5485 mlx5_flow_start_default(struct rte_eth_dev *dev)
5487 struct rte_flow_error error;
5489 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
5490 return flow_mreg_add_default_copy_action(dev, &error);
5494 * Allocate intermediate resources for flow creation.
5497 * Pointer to Ethernet device.
5500 mlx5_flow_alloc_intermediate(struct rte_eth_dev *dev)
5502 struct mlx5_priv *priv = dev->data->dev_private;
5504 if (!priv->inter_flows) {
5505 priv->inter_flows = mlx5_malloc(MLX5_MEM_ZERO,
5506 MLX5_NUM_MAX_DEV_FLOWS *
5507 sizeof(struct mlx5_flow) +
5508 (sizeof(struct mlx5_flow_rss_desc) +
5509 sizeof(uint16_t) * UINT16_MAX) * 2, 0,
5511 if (!priv->inter_flows) {
5512 DRV_LOG(ERR, "can't allocate intermediate memory.");
5516 priv->rss_desc = &((struct mlx5_flow *)priv->inter_flows)
5517 [MLX5_NUM_MAX_DEV_FLOWS];
5518 /* Reset the index. */
5520 priv->flow_nested_idx = 0;
5524 * Free intermediate resources for flows.
5527 * Pointer to Ethernet device.
5530 mlx5_flow_free_intermediate(struct rte_eth_dev *dev)
5532 struct mlx5_priv *priv = dev->data->dev_private;
5534 mlx5_free(priv->inter_flows);
5535 priv->inter_flows = NULL;
5539 * Verify the flow list is empty
5542 * Pointer to Ethernet device.
5544 * @return the number of flows not released.
5547 mlx5_flow_verify(struct rte_eth_dev *dev)
5549 struct mlx5_priv *priv = dev->data->dev_private;
5550 struct rte_flow *flow;
5554 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
5556 DRV_LOG(DEBUG, "port %u flow %p still referenced",
5557 dev->data->port_id, (void *)flow);
5564 * Enable default hairpin egress flow.
5567 * Pointer to Ethernet device.
5572 * 0 on success, a negative errno value otherwise and rte_errno is set.
5575 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
5578 struct mlx5_priv *priv = dev->data->dev_private;
5579 const struct rte_flow_attr attr = {
5583 struct mlx5_rte_flow_item_tx_queue queue_spec = {
5586 struct mlx5_rte_flow_item_tx_queue queue_mask = {
5587 .queue = UINT32_MAX,
5589 struct rte_flow_item items[] = {
5591 .type = (enum rte_flow_item_type)
5592 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
5593 .spec = &queue_spec,
5595 .mask = &queue_mask,
5598 .type = RTE_FLOW_ITEM_TYPE_END,
5601 struct rte_flow_action_jump jump = {
5602 .group = MLX5_HAIRPIN_TX_TABLE,
5604 struct rte_flow_action actions[2];
5606 struct rte_flow_error error;
5608 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
5609 actions[0].conf = &jump;
5610 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
5611 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
5612 &attr, items, actions, false, &error);
5615 "Failed to create ctrl flow: rte_errno(%d),"
5616 " type(%d), message(%s)",
5617 rte_errno, error.type,
5618 error.message ? error.message : " (no stated reason)");
5625 * Enable a control flow configured from the control plane.
5628 * Pointer to Ethernet device.
5630 * An Ethernet flow spec to apply.
5632 * An Ethernet flow mask to apply.
5634 * A VLAN flow spec to apply.
5636 * A VLAN flow mask to apply.
5639 * 0 on success, a negative errno value otherwise and rte_errno is set.
5642 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
5643 struct rte_flow_item_eth *eth_spec,
5644 struct rte_flow_item_eth *eth_mask,
5645 struct rte_flow_item_vlan *vlan_spec,
5646 struct rte_flow_item_vlan *vlan_mask)
5648 struct mlx5_priv *priv = dev->data->dev_private;
5649 const struct rte_flow_attr attr = {
5651 .priority = MLX5_FLOW_PRIO_RSVD,
5653 struct rte_flow_item items[] = {
5655 .type = RTE_FLOW_ITEM_TYPE_ETH,
5661 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
5662 RTE_FLOW_ITEM_TYPE_END,
5668 .type = RTE_FLOW_ITEM_TYPE_END,
5671 uint16_t queue[priv->reta_idx_n];
5672 struct rte_flow_action_rss action_rss = {
5673 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
5675 .types = priv->rss_conf.rss_hf,
5676 .key_len = priv->rss_conf.rss_key_len,
5677 .queue_num = priv->reta_idx_n,
5678 .key = priv->rss_conf.rss_key,
5681 struct rte_flow_action actions[] = {
5683 .type = RTE_FLOW_ACTION_TYPE_RSS,
5684 .conf = &action_rss,
5687 .type = RTE_FLOW_ACTION_TYPE_END,
5691 struct rte_flow_error error;
5694 if (!priv->reta_idx_n || !priv->rxqs_n) {
5697 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
5698 action_rss.types = 0;
5699 for (i = 0; i != priv->reta_idx_n; ++i)
5700 queue[i] = (*priv->reta_idx)[i];
5701 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
5702 &attr, items, actions, false, &error);
5709 * Enable a flow control configured from the control plane.
5712 * Pointer to Ethernet device.
5714 * An Ethernet flow spec to apply.
5716 * An Ethernet flow mask to apply.
5719 * 0 on success, a negative errno value otherwise and rte_errno is set.
5722 mlx5_ctrl_flow(struct rte_eth_dev *dev,
5723 struct rte_flow_item_eth *eth_spec,
5724 struct rte_flow_item_eth *eth_mask)
5726 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
5730 * Create default miss flow rule matching lacp traffic
5733 * Pointer to Ethernet device.
5735 * An Ethernet flow spec to apply.
5738 * 0 on success, a negative errno value otherwise and rte_errno is set.
5741 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
5743 struct mlx5_priv *priv = dev->data->dev_private;
5745 * The LACP matching is done by only using ether type since using
5746 * a multicast dst mac causes kernel to give low priority to this flow.
5748 static const struct rte_flow_item_eth lacp_spec = {
5749 .type = RTE_BE16(0x8809),
5751 static const struct rte_flow_item_eth lacp_mask = {
5754 const struct rte_flow_attr attr = {
5757 struct rte_flow_item items[] = {
5759 .type = RTE_FLOW_ITEM_TYPE_ETH,
5764 .type = RTE_FLOW_ITEM_TYPE_END,
5767 struct rte_flow_action actions[] = {
5769 .type = (enum rte_flow_action_type)
5770 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
5773 .type = RTE_FLOW_ACTION_TYPE_END,
5776 struct rte_flow_error error;
5777 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
5778 &attr, items, actions, false, &error);
5788 * @see rte_flow_destroy()
5792 mlx5_flow_destroy(struct rte_eth_dev *dev,
5793 struct rte_flow *flow,
5794 struct rte_flow_error *error __rte_unused)
5796 struct mlx5_priv *priv = dev->data->dev_private;
5798 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
5803 * Destroy all flows.
5805 * @see rte_flow_flush()
5809 mlx5_flow_flush(struct rte_eth_dev *dev,
5810 struct rte_flow_error *error __rte_unused)
5812 struct mlx5_priv *priv = dev->data->dev_private;
5814 mlx5_flow_list_flush(dev, &priv->flows, false);
5821 * @see rte_flow_isolate()
5825 mlx5_flow_isolate(struct rte_eth_dev *dev,
5827 struct rte_flow_error *error)
5829 struct mlx5_priv *priv = dev->data->dev_private;
5831 if (dev->data->dev_started) {
5832 rte_flow_error_set(error, EBUSY,
5833 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5835 "port must be stopped first");
5838 priv->isolated = !!enable;
5840 dev->dev_ops = &mlx5_os_dev_ops_isolate;
5842 dev->dev_ops = &mlx5_os_dev_ops;
5844 dev->rx_descriptor_status = mlx5_rx_descriptor_status;
5845 dev->tx_descriptor_status = mlx5_tx_descriptor_status;
5853 * @see rte_flow_query()
5857 flow_drv_query(struct rte_eth_dev *dev,
5859 const struct rte_flow_action *actions,
5861 struct rte_flow_error *error)
5863 struct mlx5_priv *priv = dev->data->dev_private;
5864 const struct mlx5_flow_driver_ops *fops;
5865 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5866 [MLX5_IPOOL_RTE_FLOW],
5868 enum mlx5_flow_drv_type ftype;
5871 return rte_flow_error_set(error, ENOENT,
5872 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5874 "invalid flow handle");
5876 ftype = flow->drv_type;
5877 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
5878 fops = flow_get_drv_ops(ftype);
5880 return fops->query(dev, flow, actions, data, error);
5886 * @see rte_flow_query()
5890 mlx5_flow_query(struct rte_eth_dev *dev,
5891 struct rte_flow *flow,
5892 const struct rte_flow_action *actions,
5894 struct rte_flow_error *error)
5898 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
5906 * Convert a flow director filter to a generic flow.
5909 * Pointer to Ethernet device.
5910 * @param fdir_filter
5911 * Flow director filter to add.
5913 * Generic flow parameters structure.
5916 * 0 on success, a negative errno value otherwise and rte_errno is set.
5919 flow_fdir_filter_convert(struct rte_eth_dev *dev,
5920 const struct rte_eth_fdir_filter *fdir_filter,
5921 struct mlx5_fdir *attributes)
5923 struct mlx5_priv *priv = dev->data->dev_private;
5924 const struct rte_eth_fdir_input *input = &fdir_filter->input;
5925 const struct rte_eth_fdir_masks *mask =
5926 &dev->data->dev_conf.fdir_conf.mask;
5928 /* Validate queue number. */
5929 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
5930 DRV_LOG(ERR, "port %u invalid queue number %d",
5931 dev->data->port_id, fdir_filter->action.rx_queue);
5935 attributes->attr.ingress = 1;
5936 attributes->items[0] = (struct rte_flow_item) {
5937 .type = RTE_FLOW_ITEM_TYPE_ETH,
5938 .spec = &attributes->l2,
5939 .mask = &attributes->l2_mask,
5941 switch (fdir_filter->action.behavior) {
5942 case RTE_ETH_FDIR_ACCEPT:
5943 attributes->actions[0] = (struct rte_flow_action){
5944 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
5945 .conf = &attributes->queue,
5948 case RTE_ETH_FDIR_REJECT:
5949 attributes->actions[0] = (struct rte_flow_action){
5950 .type = RTE_FLOW_ACTION_TYPE_DROP,
5954 DRV_LOG(ERR, "port %u invalid behavior %d",
5956 fdir_filter->action.behavior);
5957 rte_errno = ENOTSUP;
5960 attributes->queue.index = fdir_filter->action.rx_queue;
5962 switch (fdir_filter->input.flow_type) {
5963 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
5964 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
5965 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
5966 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
5967 .src_addr = input->flow.ip4_flow.src_ip,
5968 .dst_addr = input->flow.ip4_flow.dst_ip,
5969 .time_to_live = input->flow.ip4_flow.ttl,
5970 .type_of_service = input->flow.ip4_flow.tos,
5972 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
5973 .src_addr = mask->ipv4_mask.src_ip,
5974 .dst_addr = mask->ipv4_mask.dst_ip,
5975 .time_to_live = mask->ipv4_mask.ttl,
5976 .type_of_service = mask->ipv4_mask.tos,
5977 .next_proto_id = mask->ipv4_mask.proto,
5979 attributes->items[1] = (struct rte_flow_item){
5980 .type = RTE_FLOW_ITEM_TYPE_IPV4,
5981 .spec = &attributes->l3,
5982 .mask = &attributes->l3_mask,
5985 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
5986 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
5987 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
5988 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
5989 .hop_limits = input->flow.ipv6_flow.hop_limits,
5990 .proto = input->flow.ipv6_flow.proto,
5993 memcpy(attributes->l3.ipv6.hdr.src_addr,
5994 input->flow.ipv6_flow.src_ip,
5995 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
5996 memcpy(attributes->l3.ipv6.hdr.dst_addr,
5997 input->flow.ipv6_flow.dst_ip,
5998 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
5999 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
6000 mask->ipv6_mask.src_ip,
6001 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
6002 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
6003 mask->ipv6_mask.dst_ip,
6004 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
6005 attributes->items[1] = (struct rte_flow_item){
6006 .type = RTE_FLOW_ITEM_TYPE_IPV6,
6007 .spec = &attributes->l3,
6008 .mask = &attributes->l3_mask,
6012 DRV_LOG(ERR, "port %u invalid flow type%d",
6013 dev->data->port_id, fdir_filter->input.flow_type);
6014 rte_errno = ENOTSUP;
6018 switch (fdir_filter->input.flow_type) {
6019 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
6020 attributes->l4.udp.hdr = (struct rte_udp_hdr){
6021 .src_port = input->flow.udp4_flow.src_port,
6022 .dst_port = input->flow.udp4_flow.dst_port,
6024 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
6025 .src_port = mask->src_port_mask,
6026 .dst_port = mask->dst_port_mask,
6028 attributes->items[2] = (struct rte_flow_item){
6029 .type = RTE_FLOW_ITEM_TYPE_UDP,
6030 .spec = &attributes->l4,
6031 .mask = &attributes->l4_mask,
6034 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
6035 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
6036 .src_port = input->flow.tcp4_flow.src_port,
6037 .dst_port = input->flow.tcp4_flow.dst_port,
6039 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
6040 .src_port = mask->src_port_mask,
6041 .dst_port = mask->dst_port_mask,
6043 attributes->items[2] = (struct rte_flow_item){
6044 .type = RTE_FLOW_ITEM_TYPE_TCP,
6045 .spec = &attributes->l4,
6046 .mask = &attributes->l4_mask,
6049 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
6050 attributes->l4.udp.hdr = (struct rte_udp_hdr){
6051 .src_port = input->flow.udp6_flow.src_port,
6052 .dst_port = input->flow.udp6_flow.dst_port,
6054 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
6055 .src_port = mask->src_port_mask,
6056 .dst_port = mask->dst_port_mask,
6058 attributes->items[2] = (struct rte_flow_item){
6059 .type = RTE_FLOW_ITEM_TYPE_UDP,
6060 .spec = &attributes->l4,
6061 .mask = &attributes->l4_mask,
6064 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
6065 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
6066 .src_port = input->flow.tcp6_flow.src_port,
6067 .dst_port = input->flow.tcp6_flow.dst_port,
6069 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
6070 .src_port = mask->src_port_mask,
6071 .dst_port = mask->dst_port_mask,
6073 attributes->items[2] = (struct rte_flow_item){
6074 .type = RTE_FLOW_ITEM_TYPE_TCP,
6075 .spec = &attributes->l4,
6076 .mask = &attributes->l4_mask,
6079 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
6080 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
6083 DRV_LOG(ERR, "port %u invalid flow type%d",
6084 dev->data->port_id, fdir_filter->input.flow_type);
6085 rte_errno = ENOTSUP;
6091 #define FLOW_FDIR_CMP(f1, f2, fld) \
6092 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
6095 * Compare two FDIR flows. If items and actions are identical, the two flows are
6099 * Pointer to Ethernet device.
6101 * FDIR flow to compare.
6103 * FDIR flow to compare.
6106 * Zero on match, 1 otherwise.
6109 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
6111 if (FLOW_FDIR_CMP(f1, f2, attr) ||
6112 FLOW_FDIR_CMP(f1, f2, l2) ||
6113 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
6114 FLOW_FDIR_CMP(f1, f2, l3) ||
6115 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
6116 FLOW_FDIR_CMP(f1, f2, l4) ||
6117 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
6118 FLOW_FDIR_CMP(f1, f2, actions[0].type))
6120 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
6121 FLOW_FDIR_CMP(f1, f2, queue))
6127 * Search device flow list to find out a matched FDIR flow.
6130 * Pointer to Ethernet device.
6132 * FDIR flow to lookup.
6135 * Index of flow if found, 0 otherwise.
6138 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
6140 struct mlx5_priv *priv = dev->data->dev_private;
6141 uint32_t flow_idx = 0;
6142 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6144 MLX5_ASSERT(fdir_flow);
6145 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
6146 if (!flow_fdir_cmp(priv_fdir_flow->fdir, fdir_flow)) {
6147 DRV_LOG(DEBUG, "port %u found FDIR flow %u",
6148 dev->data->port_id, flow_idx);
6149 flow_idx = priv_fdir_flow->rix_flow;
6157 * Add new flow director filter and store it in list.
6160 * Pointer to Ethernet device.
6161 * @param fdir_filter
6162 * Flow director filter to add.
6165 * 0 on success, a negative errno value otherwise and rte_errno is set.
6168 flow_fdir_filter_add(struct rte_eth_dev *dev,
6169 const struct rte_eth_fdir_filter *fdir_filter)
6171 struct mlx5_priv *priv = dev->data->dev_private;
6172 struct mlx5_fdir *fdir_flow;
6173 struct rte_flow *flow;
6174 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6178 fdir_flow = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*fdir_flow), 0,
6184 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
6187 flow_idx = flow_fdir_filter_lookup(dev, fdir_flow);
6192 priv_fdir_flow = mlx5_malloc(MLX5_MEM_ZERO,
6193 sizeof(struct mlx5_fdir_flow),
6195 if (!priv_fdir_flow) {
6199 flow_idx = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
6200 fdir_flow->items, fdir_flow->actions, true,
6202 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
6206 priv_fdir_flow->fdir = fdir_flow;
6207 priv_fdir_flow->rix_flow = flow_idx;
6208 LIST_INSERT_HEAD(&priv->fdir_flows, priv_fdir_flow, next);
6209 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
6210 dev->data->port_id, (void *)flow);
6213 mlx5_free(priv_fdir_flow);
6214 mlx5_free(fdir_flow);
6219 * Delete specific filter.
6222 * Pointer to Ethernet device.
6223 * @param fdir_filter
6224 * Filter to be deleted.
6227 * 0 on success, a negative errno value otherwise and rte_errno is set.
6230 flow_fdir_filter_delete(struct rte_eth_dev *dev,
6231 const struct rte_eth_fdir_filter *fdir_filter)
6233 struct mlx5_priv *priv = dev->data->dev_private;
6235 struct mlx5_fdir fdir_flow = {
6238 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6241 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
6244 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
6245 /* Find the fdir in priv list */
6246 if (!flow_fdir_cmp(priv_fdir_flow->fdir, &fdir_flow))
6249 if (!priv_fdir_flow)
6251 LIST_REMOVE(priv_fdir_flow, next);
6252 flow_idx = priv_fdir_flow->rix_flow;
6253 flow_list_destroy(dev, &priv->flows, flow_idx);
6254 mlx5_free(priv_fdir_flow->fdir);
6255 mlx5_free(priv_fdir_flow);
6256 DRV_LOG(DEBUG, "port %u deleted FDIR flow %u",
6257 dev->data->port_id, flow_idx);
6262 * Update queue for specific filter.
6265 * Pointer to Ethernet device.
6266 * @param fdir_filter
6267 * Filter to be updated.
6270 * 0 on success, a negative errno value otherwise and rte_errno is set.
6273 flow_fdir_filter_update(struct rte_eth_dev *dev,
6274 const struct rte_eth_fdir_filter *fdir_filter)
6278 ret = flow_fdir_filter_delete(dev, fdir_filter);
6281 return flow_fdir_filter_add(dev, fdir_filter);
6285 * Flush all filters.
6288 * Pointer to Ethernet device.
6291 flow_fdir_filter_flush(struct rte_eth_dev *dev)
6293 struct mlx5_priv *priv = dev->data->dev_private;
6294 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
6296 while (!LIST_EMPTY(&priv->fdir_flows)) {
6297 priv_fdir_flow = LIST_FIRST(&priv->fdir_flows);
6298 LIST_REMOVE(priv_fdir_flow, next);
6299 flow_list_destroy(dev, &priv->flows, priv_fdir_flow->rix_flow);
6300 mlx5_free(priv_fdir_flow->fdir);
6301 mlx5_free(priv_fdir_flow);
6306 * Get flow director information.
6309 * Pointer to Ethernet device.
6310 * @param[out] fdir_info
6311 * Resulting flow director information.
6314 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
6316 struct rte_eth_fdir_masks *mask =
6317 &dev->data->dev_conf.fdir_conf.mask;
6319 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
6320 fdir_info->guarant_spc = 0;
6321 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
6322 fdir_info->max_flexpayload = 0;
6323 fdir_info->flow_types_mask[0] = 0;
6324 fdir_info->flex_payload_unit = 0;
6325 fdir_info->max_flex_payload_segment_num = 0;
6326 fdir_info->flex_payload_limit = 0;
6327 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
6331 * Deal with flow director operations.
6334 * Pointer to Ethernet device.
6336 * Operation to perform.
6338 * Pointer to operation-specific structure.
6341 * 0 on success, a negative errno value otherwise and rte_errno is set.
6344 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
6347 enum rte_fdir_mode fdir_mode =
6348 dev->data->dev_conf.fdir_conf.mode;
6350 if (filter_op == RTE_ETH_FILTER_NOP)
6352 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
6353 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
6354 DRV_LOG(ERR, "port %u flow director mode %d not supported",
6355 dev->data->port_id, fdir_mode);
6359 switch (filter_op) {
6360 case RTE_ETH_FILTER_ADD:
6361 return flow_fdir_filter_add(dev, arg);
6362 case RTE_ETH_FILTER_UPDATE:
6363 return flow_fdir_filter_update(dev, arg);
6364 case RTE_ETH_FILTER_DELETE:
6365 return flow_fdir_filter_delete(dev, arg);
6366 case RTE_ETH_FILTER_FLUSH:
6367 flow_fdir_filter_flush(dev);
6369 case RTE_ETH_FILTER_INFO:
6370 flow_fdir_info_get(dev, arg);
6373 DRV_LOG(DEBUG, "port %u unknown operation %u",
6374 dev->data->port_id, filter_op);
6382 * Manage filter operations.
6385 * Pointer to Ethernet device structure.
6386 * @param filter_type
6389 * Operation to perform.
6391 * Pointer to operation-specific structure.
6394 * 0 on success, a negative errno value otherwise and rte_errno is set.
6397 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
6398 enum rte_filter_type filter_type,
6399 enum rte_filter_op filter_op,
6402 switch (filter_type) {
6403 case RTE_ETH_FILTER_GENERIC:
6404 if (filter_op != RTE_ETH_FILTER_GET) {
6408 *(const void **)arg = &mlx5_flow_ops;
6410 case RTE_ETH_FILTER_FDIR:
6411 return flow_fdir_ctrl_func(dev, filter_op, arg);
6413 DRV_LOG(ERR, "port %u filter type (%d) not supported",
6414 dev->data->port_id, filter_type);
6415 rte_errno = ENOTSUP;
6422 * Create the needed meter and suffix tables.
6425 * Pointer to Ethernet device.
6427 * Pointer to the flow meter.
6430 * Pointer to table set on success, NULL otherwise.
6432 struct mlx5_meter_domains_infos *
6433 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
6434 const struct mlx5_flow_meter *fm)
6436 const struct mlx5_flow_driver_ops *fops;
6438 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6439 return fops->create_mtr_tbls(dev, fm);
6443 * Destroy the meter table set.
6446 * Pointer to Ethernet device.
6448 * Pointer to the meter table set.
6454 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
6455 struct mlx5_meter_domains_infos *tbls)
6457 const struct mlx5_flow_driver_ops *fops;
6459 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6460 return fops->destroy_mtr_tbls(dev, tbls);
6464 * Create policer rules.
6467 * Pointer to Ethernet device.
6469 * Pointer to flow meter structure.
6471 * Pointer to flow attributes.
6474 * 0 on success, -1 otherwise.
6477 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
6478 struct mlx5_flow_meter *fm,
6479 const struct rte_flow_attr *attr)
6481 const struct mlx5_flow_driver_ops *fops;
6483 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6484 return fops->create_policer_rules(dev, fm, attr);
6488 * Destroy policer rules.
6491 * Pointer to flow meter structure.
6493 * Pointer to flow attributes.
6496 * 0 on success, -1 otherwise.
6499 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
6500 struct mlx5_flow_meter *fm,
6501 const struct rte_flow_attr *attr)
6503 const struct mlx5_flow_driver_ops *fops;
6505 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6506 return fops->destroy_policer_rules(dev, fm, attr);
6510 * Allocate a counter.
6513 * Pointer to Ethernet device structure.
6516 * Index to allocated counter on success, 0 otherwise.
6519 mlx5_counter_alloc(struct rte_eth_dev *dev)
6521 const struct mlx5_flow_driver_ops *fops;
6522 struct rte_flow_attr attr = { .transfer = 0 };
6524 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6525 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6526 return fops->counter_alloc(dev);
6529 "port %u counter allocate is not supported.",
6530 dev->data->port_id);
6538 * Pointer to Ethernet device structure.
6540 * Index to counter to be free.
6543 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
6545 const struct mlx5_flow_driver_ops *fops;
6546 struct rte_flow_attr attr = { .transfer = 0 };
6548 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6549 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6550 fops->counter_free(dev, cnt);
6554 "port %u counter free is not supported.",
6555 dev->data->port_id);
6559 * Query counter statistics.
6562 * Pointer to Ethernet device structure.
6564 * Index to counter to query.
6566 * Set to clear counter statistics.
6568 * The counter hits packets number to save.
6570 * The counter hits bytes number to save.
6573 * 0 on success, a negative errno value otherwise.
6576 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
6577 bool clear, uint64_t *pkts, uint64_t *bytes)
6579 const struct mlx5_flow_driver_ops *fops;
6580 struct rte_flow_attr attr = { .transfer = 0 };
6582 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6583 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6584 return fops->counter_query(dev, cnt, clear, pkts, bytes);
6587 "port %u counter query is not supported.",
6588 dev->data->port_id);
6592 #define MLX5_POOL_QUERY_FREQ_US 1000000
6595 * Set the periodic procedure for triggering asynchronous batch queries for all
6596 * the counter pools.
6599 * Pointer to mlx5_dev_ctx_shared object.
6602 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
6604 uint32_t pools_n, us;
6606 pools_n = rte_atomic16_read(&sh->cmng.n_valid);
6607 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
6608 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
6609 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
6610 sh->cmng.query_thread_on = 0;
6611 DRV_LOG(ERR, "Cannot reinitialize query alarm");
6613 sh->cmng.query_thread_on = 1;
6618 * The periodic procedure for triggering asynchronous batch queries for all the
6619 * counter pools. This function is probably called by the host thread.
6622 * The parameter for the alarm process.
6625 mlx5_flow_query_alarm(void *arg)
6627 struct mlx5_dev_ctx_shared *sh = arg;
6629 uint16_t pool_index = sh->cmng.pool_index;
6630 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6631 struct mlx5_flow_counter_pool *pool;
6633 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
6635 rte_spinlock_lock(&cmng->resize_sl);
6636 pool = cmng->pools[pool_index];
6637 rte_spinlock_unlock(&cmng->resize_sl);
6639 /* There is a pool query in progress. */
6642 LIST_FIRST(&sh->cmng.free_stat_raws);
6644 /* No free counter statistics raw memory. */
6647 * Identify the counters released between query trigger and query
6648 * handle more efficiently. The counter released in this gap period
6649 * should wait for a new round of query as the new arrived packets
6650 * will not be taken into account.
6653 ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
6654 MLX5_COUNTERS_PER_POOL,
6656 pool->raw_hw->mem_mng->dm->id,
6660 (uint64_t)(uintptr_t)pool);
6662 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
6663 " %d", pool->min_dcs->id);
6664 pool->raw_hw = NULL;
6667 LIST_REMOVE(pool->raw_hw, next);
6668 sh->cmng.pending_queries++;
6670 if (pool_index >= rte_atomic16_read(&cmng->n_valid))
6673 sh->cmng.pool_index = pool_index;
6674 mlx5_set_query_alarm(sh);
6678 * Check and callback event for new aged flow in the counter pool
6681 * Pointer to mlx5_dev_ctx_shared object.
6683 * Pointer to Current counter pool.
6686 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
6687 struct mlx5_flow_counter_pool *pool)
6689 struct mlx5_priv *priv;
6690 struct mlx5_flow_counter *cnt;
6691 struct mlx5_age_info *age_info;
6692 struct mlx5_age_param *age_param;
6693 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
6694 struct mlx5_counter_stats_raw *prev = pool->raw;
6695 const uint64_t curr_time = MLX5_CURR_TIME_SEC;
6696 const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
6697 uint16_t expected = AGE_CANDIDATE;
6700 pool->time_of_last_age_check = curr_time;
6701 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
6702 cnt = MLX5_POOL_GET_CNT(pool, i);
6703 age_param = MLX5_CNT_TO_AGE(cnt);
6704 if (__atomic_load_n(&age_param->state,
6705 __ATOMIC_RELAXED) != AGE_CANDIDATE)
6707 if (cur->data[i].hits != prev->data[i].hits) {
6708 __atomic_store_n(&age_param->sec_since_last_hit, 0,
6712 if (__atomic_add_fetch(&age_param->sec_since_last_hit,
6714 __ATOMIC_RELAXED) <= age_param->timeout)
6717 * Hold the lock first, or if between the
6718 * state AGE_TMOUT and tailq operation the
6719 * release happened, the release procedure
6720 * may delete a non-existent tailq node.
6722 priv = rte_eth_devices[age_param->port_id].data->dev_private;
6723 age_info = GET_PORT_AGE_INFO(priv);
6724 rte_spinlock_lock(&age_info->aged_sl);
6725 if (__atomic_compare_exchange_n(&age_param->state, &expected,
6728 __ATOMIC_RELAXED)) {
6729 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
6730 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
6732 rte_spinlock_unlock(&age_info->aged_sl);
6734 for (i = 0; i < sh->max_port; i++) {
6735 age_info = &sh->port[i].age_info;
6736 if (!MLX5_AGE_GET(age_info, MLX5_AGE_EVENT_NEW))
6738 if (MLX5_AGE_GET(age_info, MLX5_AGE_TRIGGER))
6739 rte_eth_dev_callback_process
6740 (&rte_eth_devices[sh->port[i].devx_ih_port_id],
6741 RTE_ETH_EVENT_FLOW_AGED, NULL);
6742 age_info->flags = 0;
6747 * Handler for the HW respond about ready values from an asynchronous batch
6748 * query. This function is probably called by the host thread.
6751 * The pointer to the shared device context.
6752 * @param[in] async_id
6753 * The Devx async ID.
6755 * The status of the completion.
6758 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
6759 uint64_t async_id, int status)
6761 struct mlx5_flow_counter_pool *pool =
6762 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
6763 struct mlx5_counter_stats_raw *raw_to_free;
6764 uint8_t query_gen = pool->query_gen ^ 1;
6765 struct mlx5_flow_counter_mng *cmng = &sh->cmng;
6766 enum mlx5_counter_type cnt_type =
6767 IS_AGE_POOL(pool) ? MLX5_COUNTER_TYPE_AGE :
6768 MLX5_COUNTER_TYPE_ORIGIN;
6770 if (unlikely(status)) {
6771 raw_to_free = pool->raw_hw;
6773 raw_to_free = pool->raw;
6774 if (IS_AGE_POOL(pool))
6775 mlx5_flow_aging_check(sh, pool);
6776 rte_spinlock_lock(&pool->sl);
6777 pool->raw = pool->raw_hw;
6778 rte_spinlock_unlock(&pool->sl);
6779 /* Be sure the new raw counters data is updated in memory. */
6781 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
6782 rte_spinlock_lock(&cmng->csl[cnt_type]);
6783 TAILQ_CONCAT(&cmng->counters[cnt_type],
6784 &pool->counters[query_gen], next);
6785 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6788 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
6789 pool->raw_hw = NULL;
6790 sh->cmng.pending_queries--;
6794 * Translate the rte_flow group index to HW table value.
6796 * @param[in] attributes
6797 * Pointer to flow attributes
6798 * @param[in] external
6799 * Value is part of flow rule created by request external to PMD.
6801 * rte_flow group index value.
6802 * @param[out] fdb_def_rule
6803 * Whether fdb jump to table 1 is configured.
6807 * Pointer to error structure.
6810 * 0 on success, a negative errno value otherwise and rte_errno is set.
6813 mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, bool external,
6814 uint32_t group, bool fdb_def_rule, uint32_t *table,
6815 struct rte_flow_error *error)
6817 if (attributes->transfer && external && fdb_def_rule) {
6818 if (group == UINT32_MAX)
6819 return rte_flow_error_set
6821 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6823 "group index not supported");
6832 * Discover availability of metadata reg_c's.
6834 * Iteratively use test flows to check availability.
6837 * Pointer to the Ethernet device structure.
6840 * 0 on success, a negative errno value otherwise and rte_errno is set.
6843 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
6845 struct mlx5_priv *priv = dev->data->dev_private;
6846 struct mlx5_dev_config *config = &priv->config;
6847 enum modify_reg idx;
6850 /* reg_c[0] and reg_c[1] are reserved. */
6851 config->flow_mreg_c[n++] = REG_C_0;
6852 config->flow_mreg_c[n++] = REG_C_1;
6853 /* Discover availability of other reg_c's. */
6854 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
6855 struct rte_flow_attr attr = {
6856 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
6857 .priority = MLX5_FLOW_PRIO_RSVD,
6860 struct rte_flow_item items[] = {
6862 .type = RTE_FLOW_ITEM_TYPE_END,
6865 struct rte_flow_action actions[] = {
6867 .type = (enum rte_flow_action_type)
6868 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6869 .conf = &(struct mlx5_flow_action_copy_mreg){
6875 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6876 .conf = &(struct rte_flow_action_jump){
6877 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
6881 .type = RTE_FLOW_ACTION_TYPE_END,
6885 struct rte_flow *flow;
6886 struct rte_flow_error error;
6888 if (!config->dv_flow_en)
6890 /* Create internal flow, validation skips copy action. */
6891 flow_idx = flow_list_create(dev, NULL, &attr, items,
6892 actions, false, &error);
6893 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
6897 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
6898 config->flow_mreg_c[n++] = idx;
6899 flow_list_destroy(dev, NULL, flow_idx);
6901 for (; n < MLX5_MREG_C_NUM; ++n)
6902 config->flow_mreg_c[n] = REG_NON;
6907 * Dump flow raw hw data to file
6910 * The pointer to Ethernet device.
6912 * A pointer to a file for output.
6914 * Perform verbose error reporting if not NULL. PMDs initialize this
6915 * structure in case of error only.
6917 * 0 on success, a nagative value otherwise.
6920 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
6922 struct rte_flow_error *error __rte_unused)
6924 struct mlx5_priv *priv = dev->data->dev_private;
6925 struct mlx5_dev_ctx_shared *sh = priv->sh;
6927 if (!priv->config.dv_flow_en) {
6928 if (fputs("device dv flow disabled\n", file) <= 0)
6932 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
6933 sh->tx_domain, file);
6937 * Get aged-out flows.
6940 * Pointer to the Ethernet device structure.
6941 * @param[in] context
6942 * The address of an array of pointers to the aged-out flows contexts.
6943 * @param[in] nb_countexts
6944 * The length of context array pointers.
6946 * Perform verbose error reporting if not NULL. Initialized in case of
6950 * how many contexts get in success, otherwise negative errno value.
6951 * if nb_contexts is 0, return the amount of all aged contexts.
6952 * if nb_contexts is not 0 , return the amount of aged flows reported
6953 * in the context array.
6956 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
6957 uint32_t nb_contexts, struct rte_flow_error *error)
6959 const struct mlx5_flow_driver_ops *fops;
6960 struct rte_flow_attr attr = { .transfer = 0 };
6962 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6963 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6964 return fops->get_aged_flows(dev, contexts, nb_contexts,
6968 "port %u get aged flows is not supported.",
6969 dev->data->port_id);