1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
6 #include <netinet/in.h>
14 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
16 #pragma GCC diagnostic ignored "-Wpedantic"
18 #include <infiniband/verbs.h>
20 #pragma GCC diagnostic error "-Wpedantic"
23 #include <rte_common.h>
24 #include <rte_ether.h>
25 #include <rte_ethdev_driver.h>
27 #include <rte_flow_driver.h>
28 #include <rte_malloc.h>
31 #include <mlx5_glue.h>
32 #include <mlx5_devx_cmds.h>
35 #include "mlx5_defs.h"
37 #include "mlx5_flow.h"
38 #include "mlx5_rxtx.h"
40 /* Dev ops structure defined in mlx5.c */
41 extern const struct eth_dev_ops mlx5_dev_ops;
42 extern const struct eth_dev_ops mlx5_dev_ops_isolate;
44 /** Device flow drivers. */
45 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
46 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
48 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
50 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
52 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
53 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
54 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
55 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
57 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
58 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
63 MLX5_EXPANSION_ROOT_OUTER,
64 MLX5_EXPANSION_ROOT_ETH_VLAN,
65 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
66 MLX5_EXPANSION_OUTER_ETH,
67 MLX5_EXPANSION_OUTER_ETH_VLAN,
68 MLX5_EXPANSION_OUTER_VLAN,
69 MLX5_EXPANSION_OUTER_IPV4,
70 MLX5_EXPANSION_OUTER_IPV4_UDP,
71 MLX5_EXPANSION_OUTER_IPV4_TCP,
72 MLX5_EXPANSION_OUTER_IPV6,
73 MLX5_EXPANSION_OUTER_IPV6_UDP,
74 MLX5_EXPANSION_OUTER_IPV6_TCP,
76 MLX5_EXPANSION_VXLAN_GPE,
80 MLX5_EXPANSION_ETH_VLAN,
83 MLX5_EXPANSION_IPV4_UDP,
84 MLX5_EXPANSION_IPV4_TCP,
86 MLX5_EXPANSION_IPV6_UDP,
87 MLX5_EXPANSION_IPV6_TCP,
90 /** Supported expansion of items. */
91 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
92 [MLX5_EXPANSION_ROOT] = {
93 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
96 .type = RTE_FLOW_ITEM_TYPE_END,
98 [MLX5_EXPANSION_ROOT_OUTER] = {
99 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
100 MLX5_EXPANSION_OUTER_IPV4,
101 MLX5_EXPANSION_OUTER_IPV6),
102 .type = RTE_FLOW_ITEM_TYPE_END,
104 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
105 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
106 .type = RTE_FLOW_ITEM_TYPE_END,
108 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
109 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
110 .type = RTE_FLOW_ITEM_TYPE_END,
112 [MLX5_EXPANSION_OUTER_ETH] = {
113 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
114 MLX5_EXPANSION_OUTER_IPV6,
115 MLX5_EXPANSION_MPLS),
116 .type = RTE_FLOW_ITEM_TYPE_ETH,
119 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
120 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
121 .type = RTE_FLOW_ITEM_TYPE_ETH,
124 [MLX5_EXPANSION_OUTER_VLAN] = {
125 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
126 MLX5_EXPANSION_OUTER_IPV6),
127 .type = RTE_FLOW_ITEM_TYPE_VLAN,
129 [MLX5_EXPANSION_OUTER_IPV4] = {
130 .next = RTE_FLOW_EXPAND_RSS_NEXT
131 (MLX5_EXPANSION_OUTER_IPV4_UDP,
132 MLX5_EXPANSION_OUTER_IPV4_TCP,
135 MLX5_EXPANSION_IPV6),
136 .type = RTE_FLOW_ITEM_TYPE_IPV4,
137 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
138 ETH_RSS_NONFRAG_IPV4_OTHER,
140 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
141 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
142 MLX5_EXPANSION_VXLAN_GPE),
143 .type = RTE_FLOW_ITEM_TYPE_UDP,
144 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
146 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
147 .type = RTE_FLOW_ITEM_TYPE_TCP,
148 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
150 [MLX5_EXPANSION_OUTER_IPV6] = {
151 .next = RTE_FLOW_EXPAND_RSS_NEXT
152 (MLX5_EXPANSION_OUTER_IPV6_UDP,
153 MLX5_EXPANSION_OUTER_IPV6_TCP,
155 MLX5_EXPANSION_IPV6),
156 .type = RTE_FLOW_ITEM_TYPE_IPV6,
157 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
158 ETH_RSS_NONFRAG_IPV6_OTHER,
160 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
161 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
162 MLX5_EXPANSION_VXLAN_GPE),
163 .type = RTE_FLOW_ITEM_TYPE_UDP,
164 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
166 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
167 .type = RTE_FLOW_ITEM_TYPE_TCP,
168 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
170 [MLX5_EXPANSION_VXLAN] = {
171 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
173 MLX5_EXPANSION_IPV6),
174 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
176 [MLX5_EXPANSION_VXLAN_GPE] = {
177 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
179 MLX5_EXPANSION_IPV6),
180 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
182 [MLX5_EXPANSION_GRE] = {
183 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
184 .type = RTE_FLOW_ITEM_TYPE_GRE,
186 [MLX5_EXPANSION_MPLS] = {
187 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
188 MLX5_EXPANSION_IPV6),
189 .type = RTE_FLOW_ITEM_TYPE_MPLS,
191 [MLX5_EXPANSION_ETH] = {
192 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
193 MLX5_EXPANSION_IPV6),
194 .type = RTE_FLOW_ITEM_TYPE_ETH,
196 [MLX5_EXPANSION_ETH_VLAN] = {
197 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
198 .type = RTE_FLOW_ITEM_TYPE_ETH,
200 [MLX5_EXPANSION_VLAN] = {
201 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
202 MLX5_EXPANSION_IPV6),
203 .type = RTE_FLOW_ITEM_TYPE_VLAN,
205 [MLX5_EXPANSION_IPV4] = {
206 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
207 MLX5_EXPANSION_IPV4_TCP),
208 .type = RTE_FLOW_ITEM_TYPE_IPV4,
209 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
210 ETH_RSS_NONFRAG_IPV4_OTHER,
212 [MLX5_EXPANSION_IPV4_UDP] = {
213 .type = RTE_FLOW_ITEM_TYPE_UDP,
214 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
216 [MLX5_EXPANSION_IPV4_TCP] = {
217 .type = RTE_FLOW_ITEM_TYPE_TCP,
218 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
220 [MLX5_EXPANSION_IPV6] = {
221 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
222 MLX5_EXPANSION_IPV6_TCP),
223 .type = RTE_FLOW_ITEM_TYPE_IPV6,
224 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
225 ETH_RSS_NONFRAG_IPV6_OTHER,
227 [MLX5_EXPANSION_IPV6_UDP] = {
228 .type = RTE_FLOW_ITEM_TYPE_UDP,
229 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
231 [MLX5_EXPANSION_IPV6_TCP] = {
232 .type = RTE_FLOW_ITEM_TYPE_TCP,
233 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
237 static const struct rte_flow_ops mlx5_flow_ops = {
238 .validate = mlx5_flow_validate,
239 .create = mlx5_flow_create,
240 .destroy = mlx5_flow_destroy,
241 .flush = mlx5_flow_flush,
242 .isolate = mlx5_flow_isolate,
243 .query = mlx5_flow_query,
244 .dev_dump = mlx5_flow_dev_dump,
247 /* Convert FDIR request to Generic flow. */
249 struct rte_flow_attr attr;
250 struct rte_flow_item items[4];
251 struct rte_flow_item_eth l2;
252 struct rte_flow_item_eth l2_mask;
254 struct rte_flow_item_ipv4 ipv4;
255 struct rte_flow_item_ipv6 ipv6;
258 struct rte_flow_item_ipv4 ipv4;
259 struct rte_flow_item_ipv6 ipv6;
262 struct rte_flow_item_udp udp;
263 struct rte_flow_item_tcp tcp;
266 struct rte_flow_item_udp udp;
267 struct rte_flow_item_tcp tcp;
269 struct rte_flow_action actions[2];
270 struct rte_flow_action_queue queue;
273 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
274 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
275 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
278 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
279 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
280 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
281 { 9, 10, 11 }, { 12, 13, 14 },
284 /* Tunnel information. */
285 struct mlx5_flow_tunnel_info {
286 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
287 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
290 static struct mlx5_flow_tunnel_info tunnels_info[] = {
292 .tunnel = MLX5_FLOW_LAYER_VXLAN,
293 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
296 .tunnel = MLX5_FLOW_LAYER_GENEVE,
297 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
300 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
301 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
304 .tunnel = MLX5_FLOW_LAYER_GRE,
305 .ptype = RTE_PTYPE_TUNNEL_GRE,
308 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
309 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
312 .tunnel = MLX5_FLOW_LAYER_MPLS,
313 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
316 .tunnel = MLX5_FLOW_LAYER_NVGRE,
317 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
320 .tunnel = MLX5_FLOW_LAYER_IPIP,
321 .ptype = RTE_PTYPE_TUNNEL_IP,
324 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
325 .ptype = RTE_PTYPE_TUNNEL_IP,
328 .tunnel = MLX5_FLOW_LAYER_GTP,
329 .ptype = RTE_PTYPE_TUNNEL_GTPU,
334 * Translate tag ID to register.
337 * Pointer to the Ethernet device structure.
339 * The feature that request the register.
341 * The request register ID.
343 * Error description in case of any.
346 * The request register on success, a negative errno
347 * value otherwise and rte_errno is set.
350 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
351 enum mlx5_feature_name feature,
353 struct rte_flow_error *error)
355 struct mlx5_priv *priv = dev->data->dev_private;
356 struct mlx5_dev_config *config = &priv->config;
357 enum modify_reg start_reg;
358 bool skip_mtr_reg = false;
361 case MLX5_HAIRPIN_RX:
363 case MLX5_HAIRPIN_TX:
365 case MLX5_METADATA_RX:
366 switch (config->dv_xmeta_en) {
367 case MLX5_XMETA_MODE_LEGACY:
369 case MLX5_XMETA_MODE_META16:
371 case MLX5_XMETA_MODE_META32:
375 case MLX5_METADATA_TX:
377 case MLX5_METADATA_FDB:
378 switch (config->dv_xmeta_en) {
379 case MLX5_XMETA_MODE_LEGACY:
381 case MLX5_XMETA_MODE_META16:
383 case MLX5_XMETA_MODE_META32:
388 switch (config->dv_xmeta_en) {
389 case MLX5_XMETA_MODE_LEGACY:
391 case MLX5_XMETA_MODE_META16:
393 case MLX5_XMETA_MODE_META32:
399 * If meter color and flow match share one register, flow match
400 * should use the meter color register for match.
402 if (priv->mtr_reg_share)
403 return priv->mtr_color_reg;
405 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
408 MLX5_ASSERT(priv->mtr_color_reg != REG_NONE);
409 return priv->mtr_color_reg;
412 * Metadata COPY_MARK register using is in meter suffix sub
413 * flow while with meter. It's safe to share the same register.
415 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
418 * If meter is enable, it will engage the register for color
419 * match and flow match. If meter color match is not using the
420 * REG_C_2, need to skip the REG_C_x be used by meter color
422 * If meter is disable, free to use all available registers.
424 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
425 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
426 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
427 if (id > (REG_C_7 - start_reg))
428 return rte_flow_error_set(error, EINVAL,
429 RTE_FLOW_ERROR_TYPE_ITEM,
430 NULL, "invalid tag id");
431 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NONE)
432 return rte_flow_error_set(error, ENOTSUP,
433 RTE_FLOW_ERROR_TYPE_ITEM,
434 NULL, "unsupported tag id");
436 * This case means meter is using the REG_C_x great than 2.
437 * Take care not to conflict with meter color REG_C_x.
438 * If the available index REG_C_y >= REG_C_x, skip the
441 if (skip_mtr_reg && config->flow_mreg_c
442 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
443 if (config->flow_mreg_c
444 [id + 1 + start_reg - REG_C_0] != REG_NONE)
445 return config->flow_mreg_c
446 [id + 1 + start_reg - REG_C_0];
447 return rte_flow_error_set(error, ENOTSUP,
448 RTE_FLOW_ERROR_TYPE_ITEM,
449 NULL, "unsupported tag id");
451 return config->flow_mreg_c[id + start_reg - REG_C_0];
454 return rte_flow_error_set(error, EINVAL,
455 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
456 NULL, "invalid feature name");
460 * Check extensive flow metadata register support.
463 * Pointer to rte_eth_dev structure.
466 * True if device supports extensive flow metadata register, otherwise false.
469 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
471 struct mlx5_priv *priv = dev->data->dev_private;
472 struct mlx5_dev_config *config = &priv->config;
475 * Having available reg_c can be regarded inclusively as supporting
476 * extensive flow metadata register, which could mean,
477 * - metadata register copy action by modify header.
478 * - 16 modify header actions is supported.
479 * - reg_c's are preserved across different domain (FDB and NIC) on
480 * packet loopback by flow lookup miss.
482 return config->flow_mreg_c[2] != REG_NONE;
486 * Discover the maximum number of priority available.
489 * Pointer to the Ethernet device structure.
492 * number of supported flow priority on success, a negative errno
493 * value otherwise and rte_errno is set.
496 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
498 struct mlx5_priv *priv = dev->data->dev_private;
500 struct ibv_flow_attr attr;
501 struct ibv_flow_spec_eth eth;
502 struct ibv_flow_spec_action_drop drop;
506 .port = (uint8_t)priv->ibv_port,
509 .type = IBV_FLOW_SPEC_ETH,
510 .size = sizeof(struct ibv_flow_spec_eth),
513 .size = sizeof(struct ibv_flow_spec_action_drop),
514 .type = IBV_FLOW_SPEC_ACTION_DROP,
517 struct ibv_flow *flow;
518 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
519 uint16_t vprio[] = { 8, 16 };
527 for (i = 0; i != RTE_DIM(vprio); i++) {
528 flow_attr.attr.priority = vprio[i] - 1;
529 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
532 claim_zero(mlx5_glue->destroy_flow(flow));
535 mlx5_hrxq_drop_release(dev);
538 priority = RTE_DIM(priority_map_3);
541 priority = RTE_DIM(priority_map_5);
546 "port %u verbs maximum priority: %d expected 8/16",
547 dev->data->port_id, priority);
550 DRV_LOG(INFO, "port %u flow maximum priority: %d",
551 dev->data->port_id, priority);
556 * Adjust flow priority based on the highest layer and the request priority.
559 * Pointer to the Ethernet device structure.
560 * @param[in] priority
561 * The rule base priority.
562 * @param[in] subpriority
563 * The priority based on the items.
568 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
569 uint32_t subpriority)
572 struct mlx5_priv *priv = dev->data->dev_private;
574 switch (priv->config.flow_prio) {
575 case RTE_DIM(priority_map_3):
576 res = priority_map_3[priority][subpriority];
578 case RTE_DIM(priority_map_5):
579 res = priority_map_5[priority][subpriority];
586 * Verify the @p item specifications (spec, last, mask) are compatible with the
590 * Item specification.
592 * @p item->mask or flow default bit-masks.
593 * @param[in] nic_mask
594 * Bit-masks covering supported fields by the NIC to compare with user mask.
596 * Bit-masks size in bytes.
598 * Pointer to error structure.
601 * 0 on success, a negative errno value otherwise and rte_errno is set.
604 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
606 const uint8_t *nic_mask,
608 struct rte_flow_error *error)
612 MLX5_ASSERT(nic_mask);
613 for (i = 0; i < size; ++i)
614 if ((nic_mask[i] | mask[i]) != nic_mask[i])
615 return rte_flow_error_set(error, ENOTSUP,
616 RTE_FLOW_ERROR_TYPE_ITEM,
618 "mask enables non supported"
620 if (!item->spec && (item->mask || item->last))
621 return rte_flow_error_set(error, EINVAL,
622 RTE_FLOW_ERROR_TYPE_ITEM, item,
623 "mask/last without a spec is not"
625 if (item->spec && item->last) {
631 for (i = 0; i < size; ++i) {
632 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
633 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
635 ret = memcmp(spec, last, size);
637 return rte_flow_error_set(error, EINVAL,
638 RTE_FLOW_ERROR_TYPE_ITEM,
640 "range is not valid");
646 * Adjust the hash fields according to the @p flow information.
648 * @param[in] dev_flow.
649 * Pointer to the mlx5_flow.
651 * 1 when the hash field is for a tunnel item.
652 * @param[in] layer_types
654 * @param[in] hash_fields
658 * The hash fields that should be used.
661 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
662 int tunnel __rte_unused, uint64_t layer_types,
663 uint64_t hash_fields)
665 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
666 int rss_request_inner = rss_desc->level >= 2;
668 /* Check RSS hash level for tunnel. */
669 if (tunnel && rss_request_inner)
670 hash_fields |= IBV_RX_HASH_INNER;
671 else if (tunnel || rss_request_inner)
674 /* Check if requested layer matches RSS hash fields. */
675 if (!(rss_desc->types & layer_types))
681 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
682 * if several tunnel rules are used on this queue, the tunnel ptype will be
686 * Rx queue to update.
689 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
692 uint32_t tunnel_ptype = 0;
694 /* Look up for the ptype to use. */
695 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
696 if (!rxq_ctrl->flow_tunnels_n[i])
699 tunnel_ptype = tunnels_info[i].ptype;
705 rxq_ctrl->rxq.tunnel = tunnel_ptype;
709 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
713 * Pointer to the Ethernet device structure.
714 * @param[in] dev_handle
715 * Pointer to device flow handle structure.
718 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
719 struct mlx5_flow_handle *dev_handle)
721 struct mlx5_priv *priv = dev->data->dev_private;
722 const int mark = dev_handle->mark;
723 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
724 struct mlx5_hrxq *hrxq;
727 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
729 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
730 dev_handle->rix_hrxq);
733 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
734 int idx = hrxq->ind_table->queues[i];
735 struct mlx5_rxq_ctrl *rxq_ctrl =
736 container_of((*priv->rxqs)[idx],
737 struct mlx5_rxq_ctrl, rxq);
740 * To support metadata register copy on Tx loopback,
741 * this must be always enabled (metadata may arive
742 * from other port - not from local flows only.
744 if (priv->config.dv_flow_en &&
745 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
746 mlx5_flow_ext_mreg_supported(dev)) {
747 rxq_ctrl->rxq.mark = 1;
748 rxq_ctrl->flow_mark_n = 1;
750 rxq_ctrl->rxq.mark = 1;
751 rxq_ctrl->flow_mark_n++;
756 /* Increase the counter matching the flow. */
757 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
758 if ((tunnels_info[j].tunnel &
759 dev_handle->layers) ==
760 tunnels_info[j].tunnel) {
761 rxq_ctrl->flow_tunnels_n[j]++;
765 flow_rxq_tunnel_ptype_update(rxq_ctrl);
771 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
774 * Pointer to the Ethernet device structure.
776 * Pointer to flow structure.
779 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
781 struct mlx5_priv *priv = dev->data->dev_private;
783 struct mlx5_flow_handle *dev_handle;
785 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
786 handle_idx, dev_handle, next)
787 flow_drv_rxq_flags_set(dev, dev_handle);
791 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
792 * device flow if no other flow uses it with the same kind of request.
795 * Pointer to Ethernet device.
796 * @param[in] dev_handle
797 * Pointer to the device flow handle structure.
800 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
801 struct mlx5_flow_handle *dev_handle)
803 struct mlx5_priv *priv = dev->data->dev_private;
804 const int mark = dev_handle->mark;
805 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
806 struct mlx5_hrxq *hrxq;
809 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
811 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
812 dev_handle->rix_hrxq);
815 MLX5_ASSERT(dev->data->dev_started);
816 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
817 int idx = hrxq->ind_table->queues[i];
818 struct mlx5_rxq_ctrl *rxq_ctrl =
819 container_of((*priv->rxqs)[idx],
820 struct mlx5_rxq_ctrl, rxq);
822 if (priv->config.dv_flow_en &&
823 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
824 mlx5_flow_ext_mreg_supported(dev)) {
825 rxq_ctrl->rxq.mark = 1;
826 rxq_ctrl->flow_mark_n = 1;
828 rxq_ctrl->flow_mark_n--;
829 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
834 /* Decrease the counter matching the flow. */
835 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
836 if ((tunnels_info[j].tunnel &
837 dev_handle->layers) ==
838 tunnels_info[j].tunnel) {
839 rxq_ctrl->flow_tunnels_n[j]--;
843 flow_rxq_tunnel_ptype_update(rxq_ctrl);
849 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
850 * @p flow if no other flow uses it with the same kind of request.
853 * Pointer to Ethernet device.
855 * Pointer to the flow.
858 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
860 struct mlx5_priv *priv = dev->data->dev_private;
862 struct mlx5_flow_handle *dev_handle;
864 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
865 handle_idx, dev_handle, next)
866 flow_drv_rxq_flags_trim(dev, dev_handle);
870 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
873 * Pointer to Ethernet device.
876 flow_rxq_flags_clear(struct rte_eth_dev *dev)
878 struct mlx5_priv *priv = dev->data->dev_private;
881 for (i = 0; i != priv->rxqs_n; ++i) {
882 struct mlx5_rxq_ctrl *rxq_ctrl;
885 if (!(*priv->rxqs)[i])
887 rxq_ctrl = container_of((*priv->rxqs)[i],
888 struct mlx5_rxq_ctrl, rxq);
889 rxq_ctrl->flow_mark_n = 0;
890 rxq_ctrl->rxq.mark = 0;
891 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
892 rxq_ctrl->flow_tunnels_n[j] = 0;
893 rxq_ctrl->rxq.tunnel = 0;
898 * Set the Rx queue dynamic metadata (mask and offset) for a flow
901 * Pointer to the Ethernet device structure.
904 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
906 struct mlx5_priv *priv = dev->data->dev_private;
907 struct mlx5_rxq_data *data;
910 for (i = 0; i != priv->rxqs_n; ++i) {
911 if (!(*priv->rxqs)[i])
913 data = (*priv->rxqs)[i];
914 if (!rte_flow_dynf_metadata_avail()) {
916 data->flow_meta_mask = 0;
917 data->flow_meta_offset = -1;
920 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
921 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
927 * return a pointer to the desired action in the list of actions.
930 * The list of actions to search the action in.
932 * The action to find.
935 * Pointer to the action in the list, if found. NULL otherwise.
937 const struct rte_flow_action *
938 mlx5_flow_find_action(const struct rte_flow_action *actions,
939 enum rte_flow_action_type action)
943 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
944 if (actions->type == action)
950 * Validate the flag action.
952 * @param[in] action_flags
953 * Bit-fields that holds the actions detected until now.
955 * Attributes of flow that includes this action.
957 * Pointer to error structure.
960 * 0 on success, a negative errno value otherwise and rte_errno is set.
963 mlx5_flow_validate_action_flag(uint64_t action_flags,
964 const struct rte_flow_attr *attr,
965 struct rte_flow_error *error)
967 if (action_flags & MLX5_FLOW_ACTION_MARK)
968 return rte_flow_error_set(error, EINVAL,
969 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
970 "can't mark and flag in same flow");
971 if (action_flags & MLX5_FLOW_ACTION_FLAG)
972 return rte_flow_error_set(error, EINVAL,
973 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
975 " actions in same flow");
977 return rte_flow_error_set(error, ENOTSUP,
978 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
979 "flag action not supported for "
985 * Validate the mark action.
988 * Pointer to the queue action.
989 * @param[in] action_flags
990 * Bit-fields that holds the actions detected until now.
992 * Attributes of flow that includes this action.
994 * Pointer to error structure.
997 * 0 on success, a negative errno value otherwise and rte_errno is set.
1000 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1001 uint64_t action_flags,
1002 const struct rte_flow_attr *attr,
1003 struct rte_flow_error *error)
1005 const struct rte_flow_action_mark *mark = action->conf;
1008 return rte_flow_error_set(error, EINVAL,
1009 RTE_FLOW_ERROR_TYPE_ACTION,
1011 "configuration cannot be null");
1012 if (mark->id >= MLX5_FLOW_MARK_MAX)
1013 return rte_flow_error_set(error, EINVAL,
1014 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1016 "mark id must in 0 <= id < "
1017 RTE_STR(MLX5_FLOW_MARK_MAX));
1018 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1019 return rte_flow_error_set(error, EINVAL,
1020 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1021 "can't flag and mark in same flow");
1022 if (action_flags & MLX5_FLOW_ACTION_MARK)
1023 return rte_flow_error_set(error, EINVAL,
1024 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1025 "can't have 2 mark actions in same"
1028 return rte_flow_error_set(error, ENOTSUP,
1029 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1030 "mark action not supported for "
1036 * Validate the drop action.
1038 * @param[in] action_flags
1039 * Bit-fields that holds the actions detected until now.
1041 * Attributes of flow that includes this action.
1043 * Pointer to error structure.
1046 * 0 on success, a negative errno value otherwise and rte_errno is set.
1049 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1050 const struct rte_flow_attr *attr,
1051 struct rte_flow_error *error)
1054 return rte_flow_error_set(error, ENOTSUP,
1055 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1056 "drop action not supported for "
1062 * Validate the queue action.
1065 * Pointer to the queue action.
1066 * @param[in] action_flags
1067 * Bit-fields that holds the actions detected until now.
1069 * Pointer to the Ethernet device structure.
1071 * Attributes of flow that includes this action.
1073 * Pointer to error structure.
1076 * 0 on success, a negative errno value otherwise and rte_errno is set.
1079 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1080 uint64_t action_flags,
1081 struct rte_eth_dev *dev,
1082 const struct rte_flow_attr *attr,
1083 struct rte_flow_error *error)
1085 struct mlx5_priv *priv = dev->data->dev_private;
1086 const struct rte_flow_action_queue *queue = action->conf;
1088 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1089 return rte_flow_error_set(error, EINVAL,
1090 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1091 "can't have 2 fate actions in"
1094 return rte_flow_error_set(error, EINVAL,
1095 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1096 NULL, "No Rx queues configured");
1097 if (queue->index >= priv->rxqs_n)
1098 return rte_flow_error_set(error, EINVAL,
1099 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1101 "queue index out of range");
1102 if (!(*priv->rxqs)[queue->index])
1103 return rte_flow_error_set(error, EINVAL,
1104 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1106 "queue is not configured");
1108 return rte_flow_error_set(error, ENOTSUP,
1109 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1110 "queue action not supported for "
1116 * Validate the rss action.
1119 * Pointer to the queue action.
1120 * @param[in] action_flags
1121 * Bit-fields that holds the actions detected until now.
1123 * Pointer to the Ethernet device structure.
1125 * Attributes of flow that includes this action.
1126 * @param[in] item_flags
1127 * Items that were detected.
1129 * Pointer to error structure.
1132 * 0 on success, a negative errno value otherwise and rte_errno is set.
1135 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1136 uint64_t action_flags,
1137 struct rte_eth_dev *dev,
1138 const struct rte_flow_attr *attr,
1139 uint64_t item_flags,
1140 struct rte_flow_error *error)
1142 struct mlx5_priv *priv = dev->data->dev_private;
1143 const struct rte_flow_action_rss *rss = action->conf;
1144 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1147 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1148 return rte_flow_error_set(error, EINVAL,
1149 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1150 "can't have 2 fate actions"
1152 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1153 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1154 return rte_flow_error_set(error, ENOTSUP,
1155 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1157 "RSS hash function not supported");
1158 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1163 return rte_flow_error_set(error, ENOTSUP,
1164 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1166 "tunnel RSS is not supported");
1167 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1168 if (rss->key_len == 0 && rss->key != NULL)
1169 return rte_flow_error_set(error, ENOTSUP,
1170 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1172 "RSS hash key length 0");
1173 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1174 return rte_flow_error_set(error, ENOTSUP,
1175 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1177 "RSS hash key too small");
1178 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1179 return rte_flow_error_set(error, ENOTSUP,
1180 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1182 "RSS hash key too large");
1183 if (rss->queue_num > priv->config.ind_table_max_size)
1184 return rte_flow_error_set(error, ENOTSUP,
1185 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1187 "number of queues too large");
1188 if (rss->types & MLX5_RSS_HF_MASK)
1189 return rte_flow_error_set(error, ENOTSUP,
1190 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1192 "some RSS protocols are not"
1194 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1195 !(rss->types & ETH_RSS_IP))
1196 return rte_flow_error_set(error, EINVAL,
1197 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1198 "L3 partial RSS requested but L3 RSS"
1199 " type not specified");
1200 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1201 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1202 return rte_flow_error_set(error, EINVAL,
1203 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1204 "L4 partial RSS requested but L4 RSS"
1205 " type not specified");
1207 return rte_flow_error_set(error, EINVAL,
1208 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1209 NULL, "No Rx queues configured");
1210 if (!rss->queue_num)
1211 return rte_flow_error_set(error, EINVAL,
1212 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1213 NULL, "No queues configured");
1214 for (i = 0; i != rss->queue_num; ++i) {
1215 if (rss->queue[i] >= priv->rxqs_n)
1216 return rte_flow_error_set
1218 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1219 &rss->queue[i], "queue index out of range");
1220 if (!(*priv->rxqs)[rss->queue[i]])
1221 return rte_flow_error_set
1222 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1223 &rss->queue[i], "queue is not configured");
1226 return rte_flow_error_set(error, ENOTSUP,
1227 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1228 "rss action not supported for "
1230 if (rss->level > 1 && !tunnel)
1231 return rte_flow_error_set(error, EINVAL,
1232 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1233 "inner RSS is not supported for "
1234 "non-tunnel flows");
1239 * Validate the count action.
1242 * Pointer to the Ethernet device structure.
1244 * Attributes of flow that includes this action.
1246 * Pointer to error structure.
1249 * 0 on success, a negative errno value otherwise and rte_errno is set.
1252 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1253 const struct rte_flow_attr *attr,
1254 struct rte_flow_error *error)
1257 return rte_flow_error_set(error, ENOTSUP,
1258 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1259 "count action not supported for "
1265 * Verify the @p attributes will be correctly understood by the NIC and store
1266 * them in the @p flow if everything is correct.
1269 * Pointer to the Ethernet device structure.
1270 * @param[in] attributes
1271 * Pointer to flow attributes
1273 * Pointer to error structure.
1276 * 0 on success, a negative errno value otherwise and rte_errno is set.
1279 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1280 const struct rte_flow_attr *attributes,
1281 struct rte_flow_error *error)
1283 struct mlx5_priv *priv = dev->data->dev_private;
1284 uint32_t priority_max = priv->config.flow_prio - 1;
1286 if (attributes->group)
1287 return rte_flow_error_set(error, ENOTSUP,
1288 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1289 NULL, "groups is not supported");
1290 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1291 attributes->priority >= priority_max)
1292 return rte_flow_error_set(error, ENOTSUP,
1293 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1294 NULL, "priority out of range");
1295 if (attributes->egress)
1296 return rte_flow_error_set(error, ENOTSUP,
1297 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1298 "egress is not supported");
1299 if (attributes->transfer && !priv->config.dv_esw_en)
1300 return rte_flow_error_set(error, ENOTSUP,
1301 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1302 NULL, "transfer is not supported");
1303 if (!attributes->ingress)
1304 return rte_flow_error_set(error, EINVAL,
1305 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1307 "ingress attribute is mandatory");
1312 * Validate ICMP6 item.
1315 * Item specification.
1316 * @param[in] item_flags
1317 * Bit-fields that holds the items detected until now.
1319 * Pointer to error structure.
1322 * 0 on success, a negative errno value otherwise and rte_errno is set.
1325 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1326 uint64_t item_flags,
1327 uint8_t target_protocol,
1328 struct rte_flow_error *error)
1330 const struct rte_flow_item_icmp6 *mask = item->mask;
1331 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1332 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1333 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1334 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1335 MLX5_FLOW_LAYER_OUTER_L4;
1338 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1339 return rte_flow_error_set(error, EINVAL,
1340 RTE_FLOW_ERROR_TYPE_ITEM, item,
1341 "protocol filtering not compatible"
1342 " with ICMP6 layer");
1343 if (!(item_flags & l3m))
1344 return rte_flow_error_set(error, EINVAL,
1345 RTE_FLOW_ERROR_TYPE_ITEM, item,
1346 "IPv6 is mandatory to filter on"
1348 if (item_flags & l4m)
1349 return rte_flow_error_set(error, EINVAL,
1350 RTE_FLOW_ERROR_TYPE_ITEM, item,
1351 "multiple L4 layers not supported");
1353 mask = &rte_flow_item_icmp6_mask;
1354 ret = mlx5_flow_item_acceptable
1355 (item, (const uint8_t *)mask,
1356 (const uint8_t *)&rte_flow_item_icmp6_mask,
1357 sizeof(struct rte_flow_item_icmp6), error);
1364 * Validate ICMP item.
1367 * Item specification.
1368 * @param[in] item_flags
1369 * Bit-fields that holds the items detected until now.
1371 * Pointer to error structure.
1374 * 0 on success, a negative errno value otherwise and rte_errno is set.
1377 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1378 uint64_t item_flags,
1379 uint8_t target_protocol,
1380 struct rte_flow_error *error)
1382 const struct rte_flow_item_icmp *mask = item->mask;
1383 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1384 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1385 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1386 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1387 MLX5_FLOW_LAYER_OUTER_L4;
1390 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1391 return rte_flow_error_set(error, EINVAL,
1392 RTE_FLOW_ERROR_TYPE_ITEM, item,
1393 "protocol filtering not compatible"
1394 " with ICMP layer");
1395 if (!(item_flags & l3m))
1396 return rte_flow_error_set(error, EINVAL,
1397 RTE_FLOW_ERROR_TYPE_ITEM, item,
1398 "IPv4 is mandatory to filter"
1400 if (item_flags & l4m)
1401 return rte_flow_error_set(error, EINVAL,
1402 RTE_FLOW_ERROR_TYPE_ITEM, item,
1403 "multiple L4 layers not supported");
1405 mask = &rte_flow_item_icmp_mask;
1406 ret = mlx5_flow_item_acceptable
1407 (item, (const uint8_t *)mask,
1408 (const uint8_t *)&rte_flow_item_icmp_mask,
1409 sizeof(struct rte_flow_item_icmp), error);
1416 * Validate Ethernet item.
1419 * Item specification.
1420 * @param[in] item_flags
1421 * Bit-fields that holds the items detected until now.
1423 * Pointer to error structure.
1426 * 0 on success, a negative errno value otherwise and rte_errno is set.
1429 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1430 uint64_t item_flags,
1431 struct rte_flow_error *error)
1433 const struct rte_flow_item_eth *mask = item->mask;
1434 const struct rte_flow_item_eth nic_mask = {
1435 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1436 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1437 .type = RTE_BE16(0xffff),
1440 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1441 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1442 MLX5_FLOW_LAYER_OUTER_L2;
1444 if (item_flags & ethm)
1445 return rte_flow_error_set(error, ENOTSUP,
1446 RTE_FLOW_ERROR_TYPE_ITEM, item,
1447 "multiple L2 layers not supported");
1448 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1449 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1450 return rte_flow_error_set(error, EINVAL,
1451 RTE_FLOW_ERROR_TYPE_ITEM, item,
1452 "L2 layer should not follow "
1454 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1455 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1456 return rte_flow_error_set(error, EINVAL,
1457 RTE_FLOW_ERROR_TYPE_ITEM, item,
1458 "L2 layer should not follow VLAN");
1460 mask = &rte_flow_item_eth_mask;
1461 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1462 (const uint8_t *)&nic_mask,
1463 sizeof(struct rte_flow_item_eth),
1469 * Validate VLAN item.
1472 * Item specification.
1473 * @param[in] item_flags
1474 * Bit-fields that holds the items detected until now.
1476 * Ethernet device flow is being created on.
1478 * Pointer to error structure.
1481 * 0 on success, a negative errno value otherwise and rte_errno is set.
1484 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1485 uint64_t item_flags,
1486 struct rte_eth_dev *dev,
1487 struct rte_flow_error *error)
1489 const struct rte_flow_item_vlan *spec = item->spec;
1490 const struct rte_flow_item_vlan *mask = item->mask;
1491 const struct rte_flow_item_vlan nic_mask = {
1492 .tci = RTE_BE16(UINT16_MAX),
1493 .inner_type = RTE_BE16(UINT16_MAX),
1495 uint16_t vlan_tag = 0;
1496 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1498 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1499 MLX5_FLOW_LAYER_INNER_L4) :
1500 (MLX5_FLOW_LAYER_OUTER_L3 |
1501 MLX5_FLOW_LAYER_OUTER_L4);
1502 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1503 MLX5_FLOW_LAYER_OUTER_VLAN;
1505 if (item_flags & vlanm)
1506 return rte_flow_error_set(error, EINVAL,
1507 RTE_FLOW_ERROR_TYPE_ITEM, item,
1508 "multiple VLAN layers not supported");
1509 else if ((item_flags & l34m) != 0)
1510 return rte_flow_error_set(error, EINVAL,
1511 RTE_FLOW_ERROR_TYPE_ITEM, item,
1512 "VLAN cannot follow L3/L4 layer");
1514 mask = &rte_flow_item_vlan_mask;
1515 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1516 (const uint8_t *)&nic_mask,
1517 sizeof(struct rte_flow_item_vlan),
1521 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1522 struct mlx5_priv *priv = dev->data->dev_private;
1524 if (priv->vmwa_context) {
1526 * Non-NULL context means we have a virtual machine
1527 * and SR-IOV enabled, we have to create VLAN interface
1528 * to make hypervisor to setup E-Switch vport
1529 * context correctly. We avoid creating the multiple
1530 * VLAN interfaces, so we cannot support VLAN tag mask.
1532 return rte_flow_error_set(error, EINVAL,
1533 RTE_FLOW_ERROR_TYPE_ITEM,
1535 "VLAN tag mask is not"
1536 " supported in virtual"
1541 vlan_tag = spec->tci;
1542 vlan_tag &= mask->tci;
1545 * From verbs perspective an empty VLAN is equivalent
1546 * to a packet without VLAN layer.
1549 return rte_flow_error_set(error, EINVAL,
1550 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1552 "VLAN cannot be empty");
1557 * Validate IPV4 item.
1560 * Item specification.
1561 * @param[in] item_flags
1562 * Bit-fields that holds the items detected until now.
1563 * @param[in] acc_mask
1564 * Acceptable mask, if NULL default internal default mask
1565 * will be used to check whether item fields are supported.
1567 * Pointer to error structure.
1570 * 0 on success, a negative errno value otherwise and rte_errno is set.
1573 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1574 uint64_t item_flags,
1576 uint16_t ether_type,
1577 const struct rte_flow_item_ipv4 *acc_mask,
1578 struct rte_flow_error *error)
1580 const struct rte_flow_item_ipv4 *mask = item->mask;
1581 const struct rte_flow_item_ipv4 *spec = item->spec;
1582 const struct rte_flow_item_ipv4 nic_mask = {
1584 .src_addr = RTE_BE32(0xffffffff),
1585 .dst_addr = RTE_BE32(0xffffffff),
1586 .type_of_service = 0xff,
1587 .next_proto_id = 0xff,
1590 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1591 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1592 MLX5_FLOW_LAYER_OUTER_L3;
1593 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1594 MLX5_FLOW_LAYER_OUTER_L4;
1596 uint8_t next_proto = 0xFF;
1597 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1598 MLX5_FLOW_LAYER_OUTER_VLAN |
1599 MLX5_FLOW_LAYER_INNER_VLAN);
1601 if ((last_item & l2_vlan) && ether_type &&
1602 ether_type != RTE_ETHER_TYPE_IPV4)
1603 return rte_flow_error_set(error, EINVAL,
1604 RTE_FLOW_ERROR_TYPE_ITEM, item,
1605 "IPv4 cannot follow L2/VLAN layer "
1606 "which ether type is not IPv4");
1607 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1609 next_proto = mask->hdr.next_proto_id &
1610 spec->hdr.next_proto_id;
1611 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1612 return rte_flow_error_set(error, EINVAL,
1613 RTE_FLOW_ERROR_TYPE_ITEM,
1618 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1619 return rte_flow_error_set(error, EINVAL,
1620 RTE_FLOW_ERROR_TYPE_ITEM, item,
1621 "wrong tunnel type - IPv6 specified "
1622 "but IPv4 item provided");
1623 if (item_flags & l3m)
1624 return rte_flow_error_set(error, ENOTSUP,
1625 RTE_FLOW_ERROR_TYPE_ITEM, item,
1626 "multiple L3 layers not supported");
1627 else if (item_flags & l4m)
1628 return rte_flow_error_set(error, EINVAL,
1629 RTE_FLOW_ERROR_TYPE_ITEM, item,
1630 "L3 cannot follow an L4 layer.");
1631 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1632 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1633 return rte_flow_error_set(error, EINVAL,
1634 RTE_FLOW_ERROR_TYPE_ITEM, item,
1635 "L3 cannot follow an NVGRE layer.");
1637 mask = &rte_flow_item_ipv4_mask;
1638 else if (mask->hdr.next_proto_id != 0 &&
1639 mask->hdr.next_proto_id != 0xff)
1640 return rte_flow_error_set(error, EINVAL,
1641 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1642 "partial mask is not supported"
1644 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1645 acc_mask ? (const uint8_t *)acc_mask
1646 : (const uint8_t *)&nic_mask,
1647 sizeof(struct rte_flow_item_ipv4),
1655 * Validate IPV6 item.
1658 * Item specification.
1659 * @param[in] item_flags
1660 * Bit-fields that holds the items detected until now.
1661 * @param[in] acc_mask
1662 * Acceptable mask, if NULL default internal default mask
1663 * will be used to check whether item fields are supported.
1665 * Pointer to error structure.
1668 * 0 on success, a negative errno value otherwise and rte_errno is set.
1671 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1672 uint64_t item_flags,
1674 uint16_t ether_type,
1675 const struct rte_flow_item_ipv6 *acc_mask,
1676 struct rte_flow_error *error)
1678 const struct rte_flow_item_ipv6 *mask = item->mask;
1679 const struct rte_flow_item_ipv6 *spec = item->spec;
1680 const struct rte_flow_item_ipv6 nic_mask = {
1683 "\xff\xff\xff\xff\xff\xff\xff\xff"
1684 "\xff\xff\xff\xff\xff\xff\xff\xff",
1686 "\xff\xff\xff\xff\xff\xff\xff\xff"
1687 "\xff\xff\xff\xff\xff\xff\xff\xff",
1688 .vtc_flow = RTE_BE32(0xffffffff),
1692 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1693 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1694 MLX5_FLOW_LAYER_OUTER_L3;
1695 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1696 MLX5_FLOW_LAYER_OUTER_L4;
1698 uint8_t next_proto = 0xFF;
1699 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1700 MLX5_FLOW_LAYER_OUTER_VLAN |
1701 MLX5_FLOW_LAYER_INNER_VLAN);
1703 if ((last_item & l2_vlan) && ether_type &&
1704 ether_type != RTE_ETHER_TYPE_IPV6)
1705 return rte_flow_error_set(error, EINVAL,
1706 RTE_FLOW_ERROR_TYPE_ITEM, item,
1707 "IPv6 cannot follow L2/VLAN layer "
1708 "which ether type is not IPv6");
1709 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
1711 next_proto = mask->hdr.proto & spec->hdr.proto;
1712 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1713 return rte_flow_error_set(error, EINVAL,
1714 RTE_FLOW_ERROR_TYPE_ITEM,
1719 if (item_flags & MLX5_FLOW_LAYER_IPIP)
1720 return rte_flow_error_set(error, EINVAL,
1721 RTE_FLOW_ERROR_TYPE_ITEM, item,
1722 "wrong tunnel type - IPv4 specified "
1723 "but IPv6 item provided");
1724 if (item_flags & l3m)
1725 return rte_flow_error_set(error, ENOTSUP,
1726 RTE_FLOW_ERROR_TYPE_ITEM, item,
1727 "multiple L3 layers not supported");
1728 else if (item_flags & l4m)
1729 return rte_flow_error_set(error, EINVAL,
1730 RTE_FLOW_ERROR_TYPE_ITEM, item,
1731 "L3 cannot follow an L4 layer.");
1732 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1733 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1734 return rte_flow_error_set(error, EINVAL,
1735 RTE_FLOW_ERROR_TYPE_ITEM, item,
1736 "L3 cannot follow an NVGRE layer.");
1738 mask = &rte_flow_item_ipv6_mask;
1739 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1740 acc_mask ? (const uint8_t *)acc_mask
1741 : (const uint8_t *)&nic_mask,
1742 sizeof(struct rte_flow_item_ipv6),
1750 * Validate UDP item.
1753 * Item specification.
1754 * @param[in] item_flags
1755 * Bit-fields that holds the items detected until now.
1756 * @param[in] target_protocol
1757 * The next protocol in the previous item.
1758 * @param[in] flow_mask
1759 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
1761 * Pointer to error structure.
1764 * 0 on success, a negative errno value otherwise and rte_errno is set.
1767 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1768 uint64_t item_flags,
1769 uint8_t target_protocol,
1770 struct rte_flow_error *error)
1772 const struct rte_flow_item_udp *mask = item->mask;
1773 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1774 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1775 MLX5_FLOW_LAYER_OUTER_L3;
1776 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1777 MLX5_FLOW_LAYER_OUTER_L4;
1780 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1781 return rte_flow_error_set(error, EINVAL,
1782 RTE_FLOW_ERROR_TYPE_ITEM, item,
1783 "protocol filtering not compatible"
1785 if (!(item_flags & l3m))
1786 return rte_flow_error_set(error, EINVAL,
1787 RTE_FLOW_ERROR_TYPE_ITEM, item,
1788 "L3 is mandatory to filter on L4");
1789 if (item_flags & l4m)
1790 return rte_flow_error_set(error, EINVAL,
1791 RTE_FLOW_ERROR_TYPE_ITEM, item,
1792 "multiple L4 layers not supported");
1794 mask = &rte_flow_item_udp_mask;
1795 ret = mlx5_flow_item_acceptable
1796 (item, (const uint8_t *)mask,
1797 (const uint8_t *)&rte_flow_item_udp_mask,
1798 sizeof(struct rte_flow_item_udp), error);
1805 * Validate TCP item.
1808 * Item specification.
1809 * @param[in] item_flags
1810 * Bit-fields that holds the items detected until now.
1811 * @param[in] target_protocol
1812 * The next protocol in the previous item.
1814 * Pointer to error structure.
1817 * 0 on success, a negative errno value otherwise and rte_errno is set.
1820 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1821 uint64_t item_flags,
1822 uint8_t target_protocol,
1823 const struct rte_flow_item_tcp *flow_mask,
1824 struct rte_flow_error *error)
1826 const struct rte_flow_item_tcp *mask = item->mask;
1827 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1828 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1829 MLX5_FLOW_LAYER_OUTER_L3;
1830 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1831 MLX5_FLOW_LAYER_OUTER_L4;
1834 MLX5_ASSERT(flow_mask);
1835 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1836 return rte_flow_error_set(error, EINVAL,
1837 RTE_FLOW_ERROR_TYPE_ITEM, item,
1838 "protocol filtering not compatible"
1840 if (!(item_flags & l3m))
1841 return rte_flow_error_set(error, EINVAL,
1842 RTE_FLOW_ERROR_TYPE_ITEM, item,
1843 "L3 is mandatory to filter on L4");
1844 if (item_flags & l4m)
1845 return rte_flow_error_set(error, EINVAL,
1846 RTE_FLOW_ERROR_TYPE_ITEM, item,
1847 "multiple L4 layers not supported");
1849 mask = &rte_flow_item_tcp_mask;
1850 ret = mlx5_flow_item_acceptable
1851 (item, (const uint8_t *)mask,
1852 (const uint8_t *)flow_mask,
1853 sizeof(struct rte_flow_item_tcp), error);
1860 * Validate VXLAN item.
1863 * Item specification.
1864 * @param[in] item_flags
1865 * Bit-fields that holds the items detected until now.
1866 * @param[in] target_protocol
1867 * The next protocol in the previous item.
1869 * Pointer to error structure.
1872 * 0 on success, a negative errno value otherwise and rte_errno is set.
1875 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1876 uint64_t item_flags,
1877 struct rte_flow_error *error)
1879 const struct rte_flow_item_vxlan *spec = item->spec;
1880 const struct rte_flow_item_vxlan *mask = item->mask;
1885 } id = { .vlan_id = 0, };
1888 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1889 return rte_flow_error_set(error, ENOTSUP,
1890 RTE_FLOW_ERROR_TYPE_ITEM, item,
1891 "multiple tunnel layers not"
1894 * Verify only UDPv4 is present as defined in
1895 * https://tools.ietf.org/html/rfc7348
1897 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1898 return rte_flow_error_set(error, EINVAL,
1899 RTE_FLOW_ERROR_TYPE_ITEM, item,
1900 "no outer UDP layer found");
1902 mask = &rte_flow_item_vxlan_mask;
1903 ret = mlx5_flow_item_acceptable
1904 (item, (const uint8_t *)mask,
1905 (const uint8_t *)&rte_flow_item_vxlan_mask,
1906 sizeof(struct rte_flow_item_vxlan),
1911 memcpy(&id.vni[1], spec->vni, 3);
1912 memcpy(&id.vni[1], mask->vni, 3);
1914 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1915 return rte_flow_error_set(error, ENOTSUP,
1916 RTE_FLOW_ERROR_TYPE_ITEM, item,
1917 "VXLAN tunnel must be fully defined");
1922 * Validate VXLAN_GPE item.
1925 * Item specification.
1926 * @param[in] item_flags
1927 * Bit-fields that holds the items detected until now.
1929 * Pointer to the private data structure.
1930 * @param[in] target_protocol
1931 * The next protocol in the previous item.
1933 * Pointer to error structure.
1936 * 0 on success, a negative errno value otherwise and rte_errno is set.
1939 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1940 uint64_t item_flags,
1941 struct rte_eth_dev *dev,
1942 struct rte_flow_error *error)
1944 struct mlx5_priv *priv = dev->data->dev_private;
1945 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1946 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1951 } id = { .vlan_id = 0, };
1953 if (!priv->config.l3_vxlan_en)
1954 return rte_flow_error_set(error, ENOTSUP,
1955 RTE_FLOW_ERROR_TYPE_ITEM, item,
1956 "L3 VXLAN is not enabled by device"
1957 " parameter and/or not configured in"
1959 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1960 return rte_flow_error_set(error, ENOTSUP,
1961 RTE_FLOW_ERROR_TYPE_ITEM, item,
1962 "multiple tunnel layers not"
1965 * Verify only UDPv4 is present as defined in
1966 * https://tools.ietf.org/html/rfc7348
1968 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1969 return rte_flow_error_set(error, EINVAL,
1970 RTE_FLOW_ERROR_TYPE_ITEM, item,
1971 "no outer UDP layer found");
1973 mask = &rte_flow_item_vxlan_gpe_mask;
1974 ret = mlx5_flow_item_acceptable
1975 (item, (const uint8_t *)mask,
1976 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1977 sizeof(struct rte_flow_item_vxlan_gpe),
1983 return rte_flow_error_set(error, ENOTSUP,
1984 RTE_FLOW_ERROR_TYPE_ITEM,
1986 "VxLAN-GPE protocol"
1988 memcpy(&id.vni[1], spec->vni, 3);
1989 memcpy(&id.vni[1], mask->vni, 3);
1991 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1992 return rte_flow_error_set(error, ENOTSUP,
1993 RTE_FLOW_ERROR_TYPE_ITEM, item,
1994 "VXLAN-GPE tunnel must be fully"
1999 * Validate GRE Key item.
2002 * Item specification.
2003 * @param[in] item_flags
2004 * Bit flags to mark detected items.
2005 * @param[in] gre_item
2006 * Pointer to gre_item
2008 * Pointer to error structure.
2011 * 0 on success, a negative errno value otherwise and rte_errno is set.
2014 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2015 uint64_t item_flags,
2016 const struct rte_flow_item *gre_item,
2017 struct rte_flow_error *error)
2019 const rte_be32_t *mask = item->mask;
2021 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2022 const struct rte_flow_item_gre *gre_spec;
2023 const struct rte_flow_item_gre *gre_mask;
2025 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2026 return rte_flow_error_set(error, ENOTSUP,
2027 RTE_FLOW_ERROR_TYPE_ITEM, item,
2028 "Multiple GRE key not support");
2029 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2030 return rte_flow_error_set(error, ENOTSUP,
2031 RTE_FLOW_ERROR_TYPE_ITEM, item,
2032 "No preceding GRE header");
2033 if (item_flags & MLX5_FLOW_LAYER_INNER)
2034 return rte_flow_error_set(error, ENOTSUP,
2035 RTE_FLOW_ERROR_TYPE_ITEM, item,
2036 "GRE key following a wrong item");
2037 gre_mask = gre_item->mask;
2039 gre_mask = &rte_flow_item_gre_mask;
2040 gre_spec = gre_item->spec;
2041 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2042 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2043 return rte_flow_error_set(error, EINVAL,
2044 RTE_FLOW_ERROR_TYPE_ITEM, item,
2045 "Key bit must be on");
2048 mask = &gre_key_default_mask;
2049 ret = mlx5_flow_item_acceptable
2050 (item, (const uint8_t *)mask,
2051 (const uint8_t *)&gre_key_default_mask,
2052 sizeof(rte_be32_t), error);
2057 * Validate GRE item.
2060 * Item specification.
2061 * @param[in] item_flags
2062 * Bit flags to mark detected items.
2063 * @param[in] target_protocol
2064 * The next protocol in the previous item.
2066 * Pointer to error structure.
2069 * 0 on success, a negative errno value otherwise and rte_errno is set.
2072 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2073 uint64_t item_flags,
2074 uint8_t target_protocol,
2075 struct rte_flow_error *error)
2077 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2078 const struct rte_flow_item_gre *mask = item->mask;
2080 const struct rte_flow_item_gre nic_mask = {
2081 .c_rsvd0_ver = RTE_BE16(0xB000),
2082 .protocol = RTE_BE16(UINT16_MAX),
2085 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2086 return rte_flow_error_set(error, EINVAL,
2087 RTE_FLOW_ERROR_TYPE_ITEM, item,
2088 "protocol filtering not compatible"
2089 " with this GRE layer");
2090 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2091 return rte_flow_error_set(error, ENOTSUP,
2092 RTE_FLOW_ERROR_TYPE_ITEM, item,
2093 "multiple tunnel layers not"
2095 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2096 return rte_flow_error_set(error, ENOTSUP,
2097 RTE_FLOW_ERROR_TYPE_ITEM, item,
2098 "L3 Layer is missing");
2100 mask = &rte_flow_item_gre_mask;
2101 ret = mlx5_flow_item_acceptable
2102 (item, (const uint8_t *)mask,
2103 (const uint8_t *)&nic_mask,
2104 sizeof(struct rte_flow_item_gre), error);
2107 #ifndef HAVE_MLX5DV_DR
2108 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2109 if (spec && (spec->protocol & mask->protocol))
2110 return rte_flow_error_set(error, ENOTSUP,
2111 RTE_FLOW_ERROR_TYPE_ITEM, item,
2112 "without MPLS support the"
2113 " specification cannot be used for"
2121 * Validate Geneve item.
2124 * Item specification.
2125 * @param[in] itemFlags
2126 * Bit-fields that holds the items detected until now.
2128 * Pointer to the private data structure.
2130 * Pointer to error structure.
2133 * 0 on success, a negative errno value otherwise and rte_errno is set.
2137 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2138 uint64_t item_flags,
2139 struct rte_eth_dev *dev,
2140 struct rte_flow_error *error)
2142 struct mlx5_priv *priv = dev->data->dev_private;
2143 const struct rte_flow_item_geneve *spec = item->spec;
2144 const struct rte_flow_item_geneve *mask = item->mask;
2147 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2148 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2149 const struct rte_flow_item_geneve nic_mask = {
2150 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2151 .vni = "\xff\xff\xff",
2152 .protocol = RTE_BE16(UINT16_MAX),
2155 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2156 return rte_flow_error_set(error, ENOTSUP,
2157 RTE_FLOW_ERROR_TYPE_ITEM, item,
2158 "L3 Geneve is not enabled by device"
2159 " parameter and/or not configured in"
2161 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2162 return rte_flow_error_set(error, ENOTSUP,
2163 RTE_FLOW_ERROR_TYPE_ITEM, item,
2164 "multiple tunnel layers not"
2167 * Verify only UDPv4 is present as defined in
2168 * https://tools.ietf.org/html/rfc7348
2170 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2171 return rte_flow_error_set(error, EINVAL,
2172 RTE_FLOW_ERROR_TYPE_ITEM, item,
2173 "no outer UDP layer found");
2175 mask = &rte_flow_item_geneve_mask;
2176 ret = mlx5_flow_item_acceptable
2177 (item, (const uint8_t *)mask,
2178 (const uint8_t *)&nic_mask,
2179 sizeof(struct rte_flow_item_geneve), error);
2183 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2184 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2185 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2186 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2187 return rte_flow_error_set(error, ENOTSUP,
2188 RTE_FLOW_ERROR_TYPE_ITEM,
2190 "Geneve protocol unsupported"
2191 " fields are being used");
2192 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2193 return rte_flow_error_set
2195 RTE_FLOW_ERROR_TYPE_ITEM,
2197 "Unsupported Geneve options length");
2199 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2200 return rte_flow_error_set
2202 RTE_FLOW_ERROR_TYPE_ITEM, item,
2203 "Geneve tunnel must be fully defined");
2208 * Validate MPLS item.
2211 * Pointer to the rte_eth_dev structure.
2213 * Item specification.
2214 * @param[in] item_flags
2215 * Bit-fields that holds the items detected until now.
2216 * @param[in] prev_layer
2217 * The protocol layer indicated in previous item.
2219 * Pointer to error structure.
2222 * 0 on success, a negative errno value otherwise and rte_errno is set.
2225 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2226 const struct rte_flow_item *item __rte_unused,
2227 uint64_t item_flags __rte_unused,
2228 uint64_t prev_layer __rte_unused,
2229 struct rte_flow_error *error)
2231 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2232 const struct rte_flow_item_mpls *mask = item->mask;
2233 struct mlx5_priv *priv = dev->data->dev_private;
2236 if (!priv->config.mpls_en)
2237 return rte_flow_error_set(error, ENOTSUP,
2238 RTE_FLOW_ERROR_TYPE_ITEM, item,
2239 "MPLS not supported or"
2240 " disabled in firmware"
2242 /* MPLS over IP, UDP, GRE is allowed */
2243 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2244 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2245 MLX5_FLOW_LAYER_GRE)))
2246 return rte_flow_error_set(error, EINVAL,
2247 RTE_FLOW_ERROR_TYPE_ITEM, item,
2248 "protocol filtering not compatible"
2249 " with MPLS layer");
2250 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2251 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2252 !(item_flags & MLX5_FLOW_LAYER_GRE))
2253 return rte_flow_error_set(error, ENOTSUP,
2254 RTE_FLOW_ERROR_TYPE_ITEM, item,
2255 "multiple tunnel layers not"
2258 mask = &rte_flow_item_mpls_mask;
2259 ret = mlx5_flow_item_acceptable
2260 (item, (const uint8_t *)mask,
2261 (const uint8_t *)&rte_flow_item_mpls_mask,
2262 sizeof(struct rte_flow_item_mpls), error);
2267 return rte_flow_error_set(error, ENOTSUP,
2268 RTE_FLOW_ERROR_TYPE_ITEM, item,
2269 "MPLS is not supported by Verbs, please"
2274 * Validate NVGRE item.
2277 * Item specification.
2278 * @param[in] item_flags
2279 * Bit flags to mark detected items.
2280 * @param[in] target_protocol
2281 * The next protocol in the previous item.
2283 * Pointer to error structure.
2286 * 0 on success, a negative errno value otherwise and rte_errno is set.
2289 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2290 uint64_t item_flags,
2291 uint8_t target_protocol,
2292 struct rte_flow_error *error)
2294 const struct rte_flow_item_nvgre *mask = item->mask;
2297 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2298 return rte_flow_error_set(error, EINVAL,
2299 RTE_FLOW_ERROR_TYPE_ITEM, item,
2300 "protocol filtering not compatible"
2301 " with this GRE layer");
2302 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2303 return rte_flow_error_set(error, ENOTSUP,
2304 RTE_FLOW_ERROR_TYPE_ITEM, item,
2305 "multiple tunnel layers not"
2307 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2308 return rte_flow_error_set(error, ENOTSUP,
2309 RTE_FLOW_ERROR_TYPE_ITEM, item,
2310 "L3 Layer is missing");
2312 mask = &rte_flow_item_nvgre_mask;
2313 ret = mlx5_flow_item_acceptable
2314 (item, (const uint8_t *)mask,
2315 (const uint8_t *)&rte_flow_item_nvgre_mask,
2316 sizeof(struct rte_flow_item_nvgre), error);
2322 /* Allocate unique ID for the split Q/RSS subflows. */
2324 flow_qrss_get_id(struct rte_eth_dev *dev)
2326 struct mlx5_priv *priv = dev->data->dev_private;
2327 uint32_t qrss_id, ret;
2329 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2332 MLX5_ASSERT(qrss_id);
2336 /* Free unique ID for the split Q/RSS subflows. */
2338 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2340 struct mlx5_priv *priv = dev->data->dev_private;
2343 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2347 * Release resource related QUEUE/RSS action split.
2350 * Pointer to Ethernet device.
2352 * Flow to release id's from.
2355 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2356 struct rte_flow *flow)
2358 struct mlx5_priv *priv = dev->data->dev_private;
2359 uint32_t handle_idx;
2360 struct mlx5_flow_handle *dev_handle;
2362 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
2363 handle_idx, dev_handle, next)
2364 if (dev_handle->split_flow_id)
2365 flow_qrss_free_id(dev, dev_handle->split_flow_id);
2369 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2370 const struct rte_flow_attr *attr __rte_unused,
2371 const struct rte_flow_item items[] __rte_unused,
2372 const struct rte_flow_action actions[] __rte_unused,
2373 bool external __rte_unused,
2374 int hairpin __rte_unused,
2375 struct rte_flow_error *error)
2377 return rte_flow_error_set(error, ENOTSUP,
2378 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2381 static struct mlx5_flow *
2382 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
2383 const struct rte_flow_attr *attr __rte_unused,
2384 const struct rte_flow_item items[] __rte_unused,
2385 const struct rte_flow_action actions[] __rte_unused,
2386 struct rte_flow_error *error)
2388 rte_flow_error_set(error, ENOTSUP,
2389 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2394 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2395 struct mlx5_flow *dev_flow __rte_unused,
2396 const struct rte_flow_attr *attr __rte_unused,
2397 const struct rte_flow_item items[] __rte_unused,
2398 const struct rte_flow_action actions[] __rte_unused,
2399 struct rte_flow_error *error)
2401 return rte_flow_error_set(error, ENOTSUP,
2402 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2406 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2407 struct rte_flow *flow __rte_unused,
2408 struct rte_flow_error *error)
2410 return rte_flow_error_set(error, ENOTSUP,
2411 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2415 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2416 struct rte_flow *flow __rte_unused)
2421 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2422 struct rte_flow *flow __rte_unused)
2427 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2428 struct rte_flow *flow __rte_unused,
2429 const struct rte_flow_action *actions __rte_unused,
2430 void *data __rte_unused,
2431 struct rte_flow_error *error)
2433 return rte_flow_error_set(error, ENOTSUP,
2434 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2437 /* Void driver to protect from null pointer reference. */
2438 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2439 .validate = flow_null_validate,
2440 .prepare = flow_null_prepare,
2441 .translate = flow_null_translate,
2442 .apply = flow_null_apply,
2443 .remove = flow_null_remove,
2444 .destroy = flow_null_destroy,
2445 .query = flow_null_query,
2449 * Select flow driver type according to flow attributes and device
2453 * Pointer to the dev structure.
2455 * Pointer to the flow attributes.
2458 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2460 static enum mlx5_flow_drv_type
2461 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2463 struct mlx5_priv *priv = dev->data->dev_private;
2464 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
2466 if (attr->transfer && priv->config.dv_esw_en)
2467 type = MLX5_FLOW_TYPE_DV;
2468 if (!attr->transfer)
2469 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2470 MLX5_FLOW_TYPE_VERBS;
2474 #define flow_get_drv_ops(type) flow_drv_ops[type]
2477 * Flow driver validation API. This abstracts calling driver specific functions.
2478 * The type of flow driver is determined according to flow attributes.
2481 * Pointer to the dev structure.
2483 * Pointer to the flow attributes.
2485 * Pointer to the list of items.
2486 * @param[in] actions
2487 * Pointer to the list of actions.
2488 * @param[in] external
2489 * This flow rule is created by request external to PMD.
2490 * @param[in] hairpin
2491 * Number of hairpin TX actions, 0 means classic flow.
2493 * Pointer to the error structure.
2496 * 0 on success, a negative errno value otherwise and rte_errno is set.
2499 flow_drv_validate(struct rte_eth_dev *dev,
2500 const struct rte_flow_attr *attr,
2501 const struct rte_flow_item items[],
2502 const struct rte_flow_action actions[],
2503 bool external, int hairpin, struct rte_flow_error *error)
2505 const struct mlx5_flow_driver_ops *fops;
2506 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2508 fops = flow_get_drv_ops(type);
2509 return fops->validate(dev, attr, items, actions, external,
2514 * Flow driver preparation API. This abstracts calling driver specific
2515 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2516 * calculates the size of memory required for device flow, allocates the memory,
2517 * initializes the device flow and returns the pointer.
2520 * This function initializes device flow structure such as dv or verbs in
2521 * struct mlx5_flow. However, it is caller's responsibility to initialize the
2522 * rest. For example, adding returning device flow to flow->dev_flow list and
2523 * setting backward reference to the flow should be done out of this function.
2524 * layers field is not filled either.
2527 * Pointer to the dev structure.
2529 * Pointer to the flow attributes.
2531 * Pointer to the list of items.
2532 * @param[in] actions
2533 * Pointer to the list of actions.
2535 * Pointer to the error structure.
2538 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
2540 static inline struct mlx5_flow *
2541 flow_drv_prepare(struct rte_eth_dev *dev,
2542 const struct rte_flow *flow,
2543 const struct rte_flow_attr *attr,
2544 const struct rte_flow_item items[],
2545 const struct rte_flow_action actions[],
2546 struct rte_flow_error *error)
2548 const struct mlx5_flow_driver_ops *fops;
2549 enum mlx5_flow_drv_type type = flow->drv_type;
2551 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2552 fops = flow_get_drv_ops(type);
2553 return fops->prepare(dev, attr, items, actions, error);
2557 * Flow driver translation API. This abstracts calling driver specific
2558 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2559 * translates a generic flow into a driver flow. flow_drv_prepare() must
2563 * dev_flow->layers could be filled as a result of parsing during translation
2564 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
2565 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
2566 * flow->actions could be overwritten even though all the expanded dev_flows
2567 * have the same actions.
2570 * Pointer to the rte dev structure.
2571 * @param[in, out] dev_flow
2572 * Pointer to the mlx5 flow.
2574 * Pointer to the flow attributes.
2576 * Pointer to the list of items.
2577 * @param[in] actions
2578 * Pointer to the list of actions.
2580 * Pointer to the error structure.
2583 * 0 on success, a negative errno value otherwise and rte_errno is set.
2586 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
2587 const struct rte_flow_attr *attr,
2588 const struct rte_flow_item items[],
2589 const struct rte_flow_action actions[],
2590 struct rte_flow_error *error)
2592 const struct mlx5_flow_driver_ops *fops;
2593 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
2595 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2596 fops = flow_get_drv_ops(type);
2597 return fops->translate(dev, dev_flow, attr, items, actions, error);
2601 * Flow driver apply API. This abstracts calling driver specific functions.
2602 * Parent flow (rte_flow) should have driver type (drv_type). It applies
2603 * translated driver flows on to device. flow_drv_translate() must precede.
2606 * Pointer to Ethernet device structure.
2607 * @param[in, out] flow
2608 * Pointer to flow structure.
2610 * Pointer to error structure.
2613 * 0 on success, a negative errno value otherwise and rte_errno is set.
2616 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
2617 struct rte_flow_error *error)
2619 const struct mlx5_flow_driver_ops *fops;
2620 enum mlx5_flow_drv_type type = flow->drv_type;
2622 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2623 fops = flow_get_drv_ops(type);
2624 return fops->apply(dev, flow, error);
2628 * Flow driver remove API. This abstracts calling driver specific functions.
2629 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2630 * on device. All the resources of the flow should be freed by calling
2631 * flow_drv_destroy().
2634 * Pointer to Ethernet device.
2635 * @param[in, out] flow
2636 * Pointer to flow structure.
2639 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
2641 const struct mlx5_flow_driver_ops *fops;
2642 enum mlx5_flow_drv_type type = flow->drv_type;
2644 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2645 fops = flow_get_drv_ops(type);
2646 fops->remove(dev, flow);
2650 * Flow driver destroy API. This abstracts calling driver specific functions.
2651 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2652 * on device and releases resources of the flow.
2655 * Pointer to Ethernet device.
2656 * @param[in, out] flow
2657 * Pointer to flow structure.
2660 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
2662 const struct mlx5_flow_driver_ops *fops;
2663 enum mlx5_flow_drv_type type = flow->drv_type;
2665 flow_mreg_split_qrss_release(dev, flow);
2666 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2667 fops = flow_get_drv_ops(type);
2668 fops->destroy(dev, flow);
2672 * Get RSS action from the action list.
2674 * @param[in] actions
2675 * Pointer to the list of actions.
2678 * Pointer to the RSS action if exist, else return NULL.
2680 static const struct rte_flow_action_rss*
2681 flow_get_rss_action(const struct rte_flow_action actions[])
2683 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2684 switch (actions->type) {
2685 case RTE_FLOW_ACTION_TYPE_RSS:
2686 return (const struct rte_flow_action_rss *)
2696 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
2698 const struct rte_flow_item *item;
2699 unsigned int has_vlan = 0;
2701 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2702 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2708 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
2709 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
2710 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
2711 MLX5_EXPANSION_ROOT_OUTER;
2715 * Get layer flags from the prefix flow.
2717 * Some flows may be split to several subflows, the prefix subflow gets the
2718 * match items and the suffix sub flow gets the actions.
2719 * Some actions need the user defined match item flags to get the detail for
2721 * This function helps the suffix flow to get the item layer flags from prefix
2724 * @param[in] dev_flow
2725 * Pointer the created preifx subflow.
2728 * The layers get from prefix subflow.
2730 static inline uint64_t
2731 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
2733 uint64_t layers = 0;
2736 * Layers bits could be localization, but usually the compiler will
2737 * help to do the optimization work for source code.
2738 * If no decap actions, use the layers directly.
2740 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
2741 return dev_flow->handle->layers;
2742 /* Convert L3 layers with decap action. */
2743 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
2744 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2745 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
2746 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2747 /* Convert L4 layers with decap action. */
2748 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
2749 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
2750 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
2751 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
2756 * Get metadata split action information.
2758 * @param[in] actions
2759 * Pointer to the list of actions.
2761 * Pointer to the return pointer.
2762 * @param[out] qrss_type
2763 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
2764 * if no QUEUE/RSS is found.
2765 * @param[out] encap_idx
2766 * Pointer to the index of the encap action if exists, otherwise the last
2770 * Total number of actions.
2773 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
2774 const struct rte_flow_action **qrss,
2777 const struct rte_flow_action_raw_encap *raw_encap;
2779 int raw_decap_idx = -1;
2782 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2783 switch (actions->type) {
2784 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2785 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2786 *encap_idx = actions_n;
2788 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
2789 raw_decap_idx = actions_n;
2791 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2792 raw_encap = actions->conf;
2793 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
2794 *encap_idx = raw_decap_idx != -1 ?
2795 raw_decap_idx : actions_n;
2797 case RTE_FLOW_ACTION_TYPE_QUEUE:
2798 case RTE_FLOW_ACTION_TYPE_RSS:
2806 if (*encap_idx == -1)
2807 *encap_idx = actions_n;
2808 /* Count RTE_FLOW_ACTION_TYPE_END. */
2809 return actions_n + 1;
2813 * Check meter action from the action list.
2815 * @param[in] actions
2816 * Pointer to the list of actions.
2818 * Pointer to the meter exist flag.
2821 * Total number of actions.
2824 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
2830 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2831 switch (actions->type) {
2832 case RTE_FLOW_ACTION_TYPE_METER:
2840 /* Count RTE_FLOW_ACTION_TYPE_END. */
2841 return actions_n + 1;
2845 * Check if the flow should be splited due to hairpin.
2846 * The reason for the split is that in current HW we can't
2847 * support encap on Rx, so if a flow have encap we move it
2851 * Pointer to Ethernet device.
2853 * Flow rule attributes.
2854 * @param[in] actions
2855 * Associated actions (list terminated by the END action).
2858 * > 0 the number of actions and the flow should be split,
2859 * 0 when no split required.
2862 flow_check_hairpin_split(struct rte_eth_dev *dev,
2863 const struct rte_flow_attr *attr,
2864 const struct rte_flow_action actions[])
2866 int queue_action = 0;
2869 const struct rte_flow_action_queue *queue;
2870 const struct rte_flow_action_rss *rss;
2871 const struct rte_flow_action_raw_encap *raw_encap;
2875 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2876 switch (actions->type) {
2877 case RTE_FLOW_ACTION_TYPE_QUEUE:
2878 queue = actions->conf;
2881 if (mlx5_rxq_get_type(dev, queue->index) !=
2882 MLX5_RXQ_TYPE_HAIRPIN)
2887 case RTE_FLOW_ACTION_TYPE_RSS:
2888 rss = actions->conf;
2889 if (rss == NULL || rss->queue_num == 0)
2891 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
2892 MLX5_RXQ_TYPE_HAIRPIN)
2897 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2898 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2902 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2903 raw_encap = actions->conf;
2904 if (raw_encap->size >
2905 (sizeof(struct rte_flow_item_eth) +
2906 sizeof(struct rte_flow_item_ipv4)))
2915 if (encap == 1 && queue_action)
2920 /* Declare flow create/destroy prototype in advance. */
2922 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
2923 const struct rte_flow_attr *attr,
2924 const struct rte_flow_item items[],
2925 const struct rte_flow_action actions[],
2926 bool external, struct rte_flow_error *error);
2929 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
2933 * Add a flow of copying flow metadata registers in RX_CP_TBL.
2935 * As mark_id is unique, if there's already a registered flow for the mark_id,
2936 * return by increasing the reference counter of the resource. Otherwise, create
2937 * the resource (mcp_res) and flow.
2940 * - If ingress port is ANY and reg_c[1] is mark_id,
2941 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
2943 * For default flow (zero mark_id), flow is like,
2944 * - If ingress port is ANY,
2945 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
2948 * Pointer to Ethernet device.
2950 * ID of MARK action, zero means default flow for META.
2952 * Perform verbose error reporting if not NULL.
2955 * Associated resource on success, NULL otherwise and rte_errno is set.
2957 static struct mlx5_flow_mreg_copy_resource *
2958 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
2959 struct rte_flow_error *error)
2961 struct mlx5_priv *priv = dev->data->dev_private;
2962 struct rte_flow_attr attr = {
2963 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
2966 struct mlx5_rte_flow_item_tag tag_spec = {
2969 struct rte_flow_item items[] = {
2970 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
2972 struct rte_flow_action_mark ftag = {
2975 struct mlx5_flow_action_copy_mreg cp_mreg = {
2979 struct rte_flow_action_jump jump = {
2980 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
2982 struct rte_flow_action actions[] = {
2983 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
2985 struct mlx5_flow_mreg_copy_resource *mcp_res;
2989 /* Fill the register fileds in the flow. */
2990 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2994 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
2998 /* Check if already registered. */
2999 MLX5_ASSERT(priv->mreg_cp_tbl);
3000 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
3002 /* For non-default rule. */
3003 if (mark_id != MLX5_DEFAULT_COPY_ID)
3005 MLX5_ASSERT(mark_id != MLX5_DEFAULT_COPY_ID ||
3006 mcp_res->refcnt == 1);
3009 /* Provide the full width of FLAG specific value. */
3010 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3011 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3012 /* Build a new flow. */
3013 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3014 items[0] = (struct rte_flow_item){
3015 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3018 items[1] = (struct rte_flow_item){
3019 .type = RTE_FLOW_ITEM_TYPE_END,
3021 actions[0] = (struct rte_flow_action){
3022 .type = MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3025 actions[1] = (struct rte_flow_action){
3026 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3029 actions[2] = (struct rte_flow_action){
3030 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3033 actions[3] = (struct rte_flow_action){
3034 .type = RTE_FLOW_ACTION_TYPE_END,
3037 /* Default rule, wildcard match. */
3038 attr.priority = MLX5_FLOW_PRIO_RSVD;
3039 items[0] = (struct rte_flow_item){
3040 .type = RTE_FLOW_ITEM_TYPE_END,
3042 actions[0] = (struct rte_flow_action){
3043 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3046 actions[1] = (struct rte_flow_action){
3047 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3050 actions[2] = (struct rte_flow_action){
3051 .type = RTE_FLOW_ACTION_TYPE_END,
3054 /* Build a new entry. */
3055 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3062 * The copy Flows are not included in any list. There
3063 * ones are referenced from other Flows and can not
3064 * be applied, removed, deleted in ardbitrary order
3065 * by list traversing.
3067 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3068 actions, false, error);
3069 if (!mcp_res->rix_flow)
3072 mcp_res->hlist_ent.key = mark_id;
3073 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3074 &mcp_res->hlist_ent);
3080 if (mcp_res->rix_flow)
3081 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3082 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3087 * Release flow in RX_CP_TBL.
3090 * Pointer to Ethernet device.
3092 * Parent flow for wich copying is provided.
3095 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3096 struct rte_flow *flow)
3098 struct mlx5_flow_mreg_copy_resource *mcp_res;
3099 struct mlx5_priv *priv = dev->data->dev_private;
3101 if (!flow->rix_mreg_copy)
3103 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3104 flow->rix_mreg_copy);
3105 if (!mcp_res || !priv->mreg_cp_tbl)
3107 if (flow->copy_applied) {
3108 MLX5_ASSERT(mcp_res->appcnt);
3109 flow->copy_applied = 0;
3111 if (!mcp_res->appcnt) {
3112 struct rte_flow *mcp_flow = mlx5_ipool_get
3113 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3117 flow_drv_remove(dev, mcp_flow);
3121 * We do not check availability of metadata registers here,
3122 * because copy resources are not allocated in this case.
3124 if (--mcp_res->refcnt)
3126 MLX5_ASSERT(mcp_res->rix_flow);
3127 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3128 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3129 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3130 flow->rix_mreg_copy = 0;
3134 * Start flow in RX_CP_TBL.
3137 * Pointer to Ethernet device.
3139 * Parent flow for wich copying is provided.
3142 * 0 on success, a negative errno value otherwise and rte_errno is set.
3145 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3146 struct rte_flow *flow)
3148 struct mlx5_flow_mreg_copy_resource *mcp_res;
3149 struct mlx5_priv *priv = dev->data->dev_private;
3152 if (!flow->rix_mreg_copy || flow->copy_applied)
3154 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3155 flow->rix_mreg_copy);
3158 if (!mcp_res->appcnt) {
3159 struct rte_flow *mcp_flow = mlx5_ipool_get
3160 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3164 ret = flow_drv_apply(dev, mcp_flow, NULL);
3170 flow->copy_applied = 1;
3175 * Stop flow in RX_CP_TBL.
3178 * Pointer to Ethernet device.
3180 * Parent flow for wich copying is provided.
3183 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3184 struct rte_flow *flow)
3186 struct mlx5_flow_mreg_copy_resource *mcp_res;
3187 struct mlx5_priv *priv = dev->data->dev_private;
3189 if (!flow->rix_mreg_copy || !flow->copy_applied)
3191 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3192 flow->rix_mreg_copy);
3195 MLX5_ASSERT(mcp_res->appcnt);
3197 flow->copy_applied = 0;
3198 if (!mcp_res->appcnt) {
3199 struct rte_flow *mcp_flow = mlx5_ipool_get
3200 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3204 flow_drv_remove(dev, mcp_flow);
3209 * Remove the default copy action from RX_CP_TBL.
3212 * Pointer to Ethernet device.
3215 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3217 struct mlx5_flow_mreg_copy_resource *mcp_res;
3218 struct mlx5_priv *priv = dev->data->dev_private;
3220 /* Check if default flow is registered. */
3221 if (!priv->mreg_cp_tbl)
3223 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3224 MLX5_DEFAULT_COPY_ID);
3227 MLX5_ASSERT(mcp_res->rix_flow);
3228 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3229 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3230 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3234 * Add the default copy action in in RX_CP_TBL.
3237 * Pointer to Ethernet device.
3239 * Perform verbose error reporting if not NULL.
3242 * 0 for success, negative value otherwise and rte_errno is set.
3245 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3246 struct rte_flow_error *error)
3248 struct mlx5_priv *priv = dev->data->dev_private;
3249 struct mlx5_flow_mreg_copy_resource *mcp_res;
3251 /* Check whether extensive metadata feature is engaged. */
3252 if (!priv->config.dv_flow_en ||
3253 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3254 !mlx5_flow_ext_mreg_supported(dev) ||
3255 !priv->sh->dv_regc0_mask)
3257 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3264 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3266 * All the flow having Q/RSS action should be split by
3267 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3268 * performs the following,
3269 * - CQE->flow_tag := reg_c[1] (MARK)
3270 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3271 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3272 * but there should be a flow per each MARK ID set by MARK action.
3274 * For the aforementioned reason, if there's a MARK action in flow's action
3275 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3276 * the MARK ID to CQE's flow_tag like,
3277 * - If reg_c[1] is mark_id,
3278 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3280 * For SET_META action which stores value in reg_c[0], as the destination is
3281 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3282 * MARK ID means the default flow. The default flow looks like,
3283 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3286 * Pointer to Ethernet device.
3288 * Pointer to flow structure.
3289 * @param[in] actions
3290 * Pointer to the list of actions.
3292 * Perform verbose error reporting if not NULL.
3295 * 0 on success, negative value otherwise and rte_errno is set.
3298 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3299 struct rte_flow *flow,
3300 const struct rte_flow_action *actions,
3301 struct rte_flow_error *error)
3303 struct mlx5_priv *priv = dev->data->dev_private;
3304 struct mlx5_dev_config *config = &priv->config;
3305 struct mlx5_flow_mreg_copy_resource *mcp_res;
3306 const struct rte_flow_action_mark *mark;
3308 /* Check whether extensive metadata feature is engaged. */
3309 if (!config->dv_flow_en ||
3310 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3311 !mlx5_flow_ext_mreg_supported(dev) ||
3312 !priv->sh->dv_regc0_mask)
3314 /* Find MARK action. */
3315 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3316 switch (actions->type) {
3317 case RTE_FLOW_ACTION_TYPE_FLAG:
3318 mcp_res = flow_mreg_add_copy_action
3319 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3322 flow->rix_mreg_copy = mcp_res->idx;
3323 if (dev->data->dev_started) {
3325 flow->copy_applied = 1;
3328 case RTE_FLOW_ACTION_TYPE_MARK:
3329 mark = (const struct rte_flow_action_mark *)
3332 flow_mreg_add_copy_action(dev, mark->id, error);
3335 flow->rix_mreg_copy = mcp_res->idx;
3336 if (dev->data->dev_started) {
3338 flow->copy_applied = 1;
3348 #define MLX5_MAX_SPLIT_ACTIONS 24
3349 #define MLX5_MAX_SPLIT_ITEMS 24
3352 * Split the hairpin flow.
3353 * Since HW can't support encap on Rx we move the encap to Tx.
3354 * If the count action is after the encap then we also
3355 * move the count action. in this case the count will also measure
3359 * Pointer to Ethernet device.
3360 * @param[in] actions
3361 * Associated actions (list terminated by the END action).
3362 * @param[out] actions_rx
3364 * @param[out] actions_tx
3366 * @param[out] pattern_tx
3367 * The pattern items for the Tx flow.
3368 * @param[out] flow_id
3369 * The flow ID connected to this flow.
3375 flow_hairpin_split(struct rte_eth_dev *dev,
3376 const struct rte_flow_action actions[],
3377 struct rte_flow_action actions_rx[],
3378 struct rte_flow_action actions_tx[],
3379 struct rte_flow_item pattern_tx[],
3382 struct mlx5_priv *priv = dev->data->dev_private;
3383 const struct rte_flow_action_raw_encap *raw_encap;
3384 const struct rte_flow_action_raw_decap *raw_decap;
3385 struct mlx5_rte_flow_action_set_tag *set_tag;
3386 struct rte_flow_action *tag_action;
3387 struct mlx5_rte_flow_item_tag *tag_item;
3388 struct rte_flow_item *item;
3392 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
3393 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3394 switch (actions->type) {
3395 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3396 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3397 rte_memcpy(actions_tx, actions,
3398 sizeof(struct rte_flow_action));
3401 case RTE_FLOW_ACTION_TYPE_COUNT:
3403 rte_memcpy(actions_tx, actions,
3404 sizeof(struct rte_flow_action));
3407 rte_memcpy(actions_rx, actions,
3408 sizeof(struct rte_flow_action));
3412 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3413 raw_encap = actions->conf;
3414 if (raw_encap->size >
3415 (sizeof(struct rte_flow_item_eth) +
3416 sizeof(struct rte_flow_item_ipv4))) {
3417 memcpy(actions_tx, actions,
3418 sizeof(struct rte_flow_action));
3422 rte_memcpy(actions_rx, actions,
3423 sizeof(struct rte_flow_action));
3427 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3428 raw_decap = actions->conf;
3429 if (raw_decap->size <
3430 (sizeof(struct rte_flow_item_eth) +
3431 sizeof(struct rte_flow_item_ipv4))) {
3432 memcpy(actions_tx, actions,
3433 sizeof(struct rte_flow_action));
3436 rte_memcpy(actions_rx, actions,
3437 sizeof(struct rte_flow_action));
3442 rte_memcpy(actions_rx, actions,
3443 sizeof(struct rte_flow_action));
3448 /* Add set meta action and end action for the Rx flow. */
3449 tag_action = actions_rx;
3450 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3452 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
3454 set_tag = (void *)actions_rx;
3455 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
3456 MLX5_ASSERT(set_tag->id > REG_NONE);
3457 set_tag->data = *flow_id;
3458 tag_action->conf = set_tag;
3459 /* Create Tx item list. */
3460 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
3461 addr = (void *)&pattern_tx[2];
3463 item->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3464 tag_item = (void *)addr;
3465 tag_item->data = *flow_id;
3466 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
3467 MLX5_ASSERT(set_tag->id > REG_NONE);
3468 item->spec = tag_item;
3469 addr += sizeof(struct mlx5_rte_flow_item_tag);
3470 tag_item = (void *)addr;
3471 tag_item->data = UINT32_MAX;
3472 tag_item->id = UINT16_MAX;
3473 item->mask = tag_item;
3474 addr += sizeof(struct mlx5_rte_flow_item_tag);
3477 item->type = RTE_FLOW_ITEM_TYPE_END;
3482 * The last stage of splitting chain, just creates the subflow
3483 * without any modification.
3486 * Pointer to Ethernet device.
3488 * Parent flow structure pointer.
3489 * @param[in, out] sub_flow
3490 * Pointer to return the created subflow, may be NULL.
3491 * @param[in] prefix_layers
3492 * Prefix subflow layers, may be 0.
3494 * Flow rule attributes.
3496 * Pattern specification (list terminated by the END pattern item).
3497 * @param[in] actions
3498 * Associated actions (list terminated by the END action).
3499 * @param[in] external
3500 * This flow rule is created by request external to PMD.
3502 * Perform verbose error reporting if not NULL.
3504 * 0 on success, negative value otherwise
3507 flow_create_split_inner(struct rte_eth_dev *dev,
3508 struct rte_flow *flow,
3509 struct mlx5_flow **sub_flow,
3510 uint64_t prefix_layers,
3511 const struct rte_flow_attr *attr,
3512 const struct rte_flow_item items[],
3513 const struct rte_flow_action actions[],
3514 bool external, struct rte_flow_error *error)
3516 struct mlx5_flow *dev_flow;
3518 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions, error);
3521 dev_flow->flow = flow;
3522 dev_flow->external = external;
3523 /* Subflow object was created, we must include one in the list. */
3524 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
3525 dev_flow->handle, next);
3527 * If dev_flow is as one of the suffix flow, some actions in suffix
3528 * flow may need some user defined item layer flags.
3531 dev_flow->handle->layers = prefix_layers;
3533 *sub_flow = dev_flow;
3534 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
3538 * Split the meter flow.
3540 * As meter flow will split to three sub flow, other than meter
3541 * action, the other actions make sense to only meter accepts
3542 * the packet. If it need to be dropped, no other additional
3543 * actions should be take.
3545 * One kind of special action which decapsulates the L3 tunnel
3546 * header will be in the prefix sub flow, as not to take the
3547 * L3 tunnel header into account.
3550 * Pointer to Ethernet device.
3552 * Pattern specification (list terminated by the END pattern item).
3553 * @param[out] sfx_items
3554 * Suffix flow match items (list terminated by the END pattern item).
3555 * @param[in] actions
3556 * Associated actions (list terminated by the END action).
3557 * @param[out] actions_sfx
3558 * Suffix flow actions.
3559 * @param[out] actions_pre
3560 * Prefix flow actions.
3561 * @param[out] pattern_sfx
3562 * The pattern items for the suffix flow.
3563 * @param[out] tag_sfx
3564 * Pointer to suffix flow tag.
3570 flow_meter_split_prep(struct rte_eth_dev *dev,
3571 const struct rte_flow_item items[],
3572 struct rte_flow_item sfx_items[],
3573 const struct rte_flow_action actions[],
3574 struct rte_flow_action actions_sfx[],
3575 struct rte_flow_action actions_pre[])
3577 struct rte_flow_action *tag_action = NULL;
3578 struct rte_flow_item *tag_item;
3579 struct mlx5_rte_flow_action_set_tag *set_tag;
3580 struct rte_flow_error error;
3581 const struct rte_flow_action_raw_encap *raw_encap;
3582 const struct rte_flow_action_raw_decap *raw_decap;
3583 struct mlx5_rte_flow_item_tag *tag_spec;
3584 struct mlx5_rte_flow_item_tag *tag_mask;
3586 bool copy_vlan = false;
3588 /* Prepare the actions for prefix and suffix flow. */
3589 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3590 struct rte_flow_action **action_cur = NULL;
3592 switch (actions->type) {
3593 case RTE_FLOW_ACTION_TYPE_METER:
3594 /* Add the extra tag action first. */
3595 tag_action = actions_pre;
3596 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3598 action_cur = &actions_pre;
3600 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3601 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3602 action_cur = &actions_pre;
3604 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3605 raw_encap = actions->conf;
3606 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
3607 action_cur = &actions_pre;
3609 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3610 raw_decap = actions->conf;
3611 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3612 action_cur = &actions_pre;
3614 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3615 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3622 action_cur = &actions_sfx;
3623 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
3626 /* Add end action to the actions. */
3627 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
3628 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
3631 set_tag = (void *)actions_pre;
3632 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3634 * Get the id from the qrss_pool to make qrss share the id with meter.
3636 tag_id = flow_qrss_get_id(dev);
3637 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
3639 tag_action->conf = set_tag;
3640 /* Prepare the suffix subflow items. */
3641 tag_item = sfx_items++;
3642 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3643 int item_type = items->type;
3645 switch (item_type) {
3646 case RTE_FLOW_ITEM_TYPE_PORT_ID:
3647 memcpy(sfx_items, items, sizeof(*sfx_items));
3650 case RTE_FLOW_ITEM_TYPE_VLAN:
3652 memcpy(sfx_items, items, sizeof(*sfx_items));
3654 * Convert to internal match item, it is used
3655 * for vlan push and set vid.
3657 sfx_items->type = MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
3665 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
3667 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
3668 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
3669 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3670 tag_mask = tag_spec + 1;
3671 tag_mask->data = 0xffffff00;
3672 tag_item->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3673 tag_item->spec = tag_spec;
3674 tag_item->last = NULL;
3675 tag_item->mask = tag_mask;
3680 * Split action list having QUEUE/RSS for metadata register copy.
3682 * Once Q/RSS action is detected in user's action list, the flow action
3683 * should be split in order to copy metadata registers, which will happen in
3685 * - CQE->flow_tag := reg_c[1] (MARK)
3686 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3687 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
3688 * This is because the last action of each flow must be a terminal action
3689 * (QUEUE, RSS or DROP).
3691 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
3692 * stored and kept in the mlx5_flow structure per each sub_flow.
3694 * The Q/RSS action is replaced with,
3695 * - SET_TAG, setting the allocated flow ID to reg_c[2].
3696 * And the following JUMP action is added at the end,
3697 * - JUMP, to RX_CP_TBL.
3699 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
3700 * flow_create_split_metadata() routine. The flow will look like,
3701 * - If flow ID matches (reg_c[2]), perform Q/RSS.
3704 * Pointer to Ethernet device.
3705 * @param[out] split_actions
3706 * Pointer to store split actions to jump to CP_TBL.
3707 * @param[in] actions
3708 * Pointer to the list of original flow actions.
3710 * Pointer to the Q/RSS action.
3711 * @param[in] actions_n
3712 * Number of original actions.
3714 * Perform verbose error reporting if not NULL.
3717 * non-zero unique flow_id on success, otherwise 0 and
3718 * error/rte_error are set.
3721 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
3722 struct rte_flow_action *split_actions,
3723 const struct rte_flow_action *actions,
3724 const struct rte_flow_action *qrss,
3725 int actions_n, struct rte_flow_error *error)
3727 struct mlx5_rte_flow_action_set_tag *set_tag;
3728 struct rte_flow_action_jump *jump;
3729 const int qrss_idx = qrss - actions;
3730 uint32_t flow_id = 0;
3734 * Given actions will be split
3735 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
3736 * - Add jump to mreg CP_TBL.
3737 * As a result, there will be one more action.
3740 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
3741 set_tag = (void *)(split_actions + actions_n);
3743 * If tag action is not set to void(it means we are not the meter
3744 * suffix flow), add the tag action. Since meter suffix flow already
3745 * has the tag added.
3747 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
3749 * Allocate the new subflow ID. This one is unique within
3750 * device and not shared with representors. Otherwise,
3751 * we would have to resolve multi-thread access synch
3752 * issue. Each flow on the shared device is appended
3753 * with source vport identifier, so the resulting
3754 * flows will be unique in the shared (by master and
3755 * representors) domain even if they have coinciding
3758 flow_id = flow_qrss_get_id(dev);
3760 return rte_flow_error_set(error, ENOMEM,
3761 RTE_FLOW_ERROR_TYPE_ACTION,
3762 NULL, "can't allocate id "
3763 "for split Q/RSS subflow");
3764 /* Internal SET_TAG action to set flow ID. */
3765 *set_tag = (struct mlx5_rte_flow_action_set_tag){
3768 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
3772 /* Construct new actions array. */
3773 /* Replace QUEUE/RSS action. */
3774 split_actions[qrss_idx] = (struct rte_flow_action){
3775 .type = MLX5_RTE_FLOW_ACTION_TYPE_TAG,
3779 /* JUMP action to jump to mreg copy table (CP_TBL). */
3780 jump = (void *)(set_tag + 1);
3781 *jump = (struct rte_flow_action_jump){
3782 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3784 split_actions[actions_n - 2] = (struct rte_flow_action){
3785 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3788 split_actions[actions_n - 1] = (struct rte_flow_action){
3789 .type = RTE_FLOW_ACTION_TYPE_END,
3795 * Extend the given action list for Tx metadata copy.
3797 * Copy the given action list to the ext_actions and add flow metadata register
3798 * copy action in order to copy reg_a set by WQE to reg_c[0].
3800 * @param[out] ext_actions
3801 * Pointer to the extended action list.
3802 * @param[in] actions
3803 * Pointer to the list of actions.
3804 * @param[in] actions_n
3805 * Number of actions in the list.
3807 * Perform verbose error reporting if not NULL.
3808 * @param[in] encap_idx
3809 * The encap action inndex.
3812 * 0 on success, negative value otherwise
3815 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
3816 struct rte_flow_action *ext_actions,
3817 const struct rte_flow_action *actions,
3818 int actions_n, struct rte_flow_error *error,
3821 struct mlx5_flow_action_copy_mreg *cp_mreg =
3822 (struct mlx5_flow_action_copy_mreg *)
3823 (ext_actions + actions_n + 1);
3826 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3830 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
3835 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
3836 if (encap_idx == actions_n - 1) {
3837 ext_actions[actions_n - 1] = (struct rte_flow_action){
3838 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3841 ext_actions[actions_n] = (struct rte_flow_action){
3842 .type = RTE_FLOW_ACTION_TYPE_END,
3845 ext_actions[encap_idx] = (struct rte_flow_action){
3846 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3849 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
3850 sizeof(*ext_actions) * (actions_n - encap_idx));
3856 * The splitting for metadata feature.
3858 * - Q/RSS action on NIC Rx should be split in order to pass by
3859 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3860 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3862 * - All the actions on NIC Tx should have a mreg copy action to
3863 * copy reg_a from WQE to reg_c[0].
3866 * Pointer to Ethernet device.
3868 * Parent flow structure pointer.
3869 * @param[in] prefix_layers
3870 * Prefix flow layer flags.
3872 * Flow rule attributes.
3874 * Pattern specification (list terminated by the END pattern item).
3875 * @param[in] actions
3876 * Associated actions (list terminated by the END action).
3877 * @param[in] external
3878 * This flow rule is created by request external to PMD.
3880 * Perform verbose error reporting if not NULL.
3882 * 0 on success, negative value otherwise
3885 flow_create_split_metadata(struct rte_eth_dev *dev,
3886 struct rte_flow *flow,
3887 uint64_t prefix_layers,
3888 const struct rte_flow_attr *attr,
3889 const struct rte_flow_item items[],
3890 const struct rte_flow_action actions[],
3891 bool external, struct rte_flow_error *error)
3893 struct mlx5_priv *priv = dev->data->dev_private;
3894 struct mlx5_dev_config *config = &priv->config;
3895 const struct rte_flow_action *qrss = NULL;
3896 struct rte_flow_action *ext_actions = NULL;
3897 struct mlx5_flow *dev_flow = NULL;
3898 uint32_t qrss_id = 0;
3905 /* Check whether extensive metadata feature is engaged. */
3906 if (!config->dv_flow_en ||
3907 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3908 !mlx5_flow_ext_mreg_supported(dev))
3909 return flow_create_split_inner(dev, flow, NULL, prefix_layers,
3910 attr, items, actions, external,
3912 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
3915 /* Exclude hairpin flows from splitting. */
3916 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
3917 const struct rte_flow_action_queue *queue;
3920 if (mlx5_rxq_get_type(dev, queue->index) ==
3921 MLX5_RXQ_TYPE_HAIRPIN)
3923 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
3924 const struct rte_flow_action_rss *rss;
3927 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
3928 MLX5_RXQ_TYPE_HAIRPIN)
3933 /* Check if it is in meter suffix table. */
3934 mtr_sfx = attr->group == (attr->transfer ?
3935 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
3936 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
3938 * Q/RSS action on NIC Rx should be split in order to pass by
3939 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3940 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3942 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3943 sizeof(struct rte_flow_action_set_tag) +
3944 sizeof(struct rte_flow_action_jump);
3945 ext_actions = rte_zmalloc(__func__, act_size, 0);
3947 return rte_flow_error_set(error, ENOMEM,
3948 RTE_FLOW_ERROR_TYPE_ACTION,
3949 NULL, "no memory to split "
3952 * If we are the suffix flow of meter, tag already exist.
3953 * Set the tag action to void.
3956 ext_actions[qrss - actions].type =
3957 RTE_FLOW_ACTION_TYPE_VOID;
3959 ext_actions[qrss - actions].type =
3960 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3962 * Create the new actions list with removed Q/RSS action
3963 * and appended set tag and jump to register copy table
3964 * (RX_CP_TBL). We should preallocate unique tag ID here
3965 * in advance, because it is needed for set tag action.
3967 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
3968 qrss, actions_n, error);
3969 if (!mtr_sfx && !qrss_id) {
3973 } else if (attr->egress && !attr->transfer) {
3975 * All the actions on NIC Tx should have a metadata register
3976 * copy action to copy reg_a from WQE to reg_c[meta]
3978 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3979 sizeof(struct mlx5_flow_action_copy_mreg);
3980 ext_actions = rte_zmalloc(__func__, act_size, 0);
3982 return rte_flow_error_set(error, ENOMEM,
3983 RTE_FLOW_ERROR_TYPE_ACTION,
3984 NULL, "no memory to split "
3986 /* Create the action list appended with copy register. */
3987 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
3988 actions_n, error, encap_idx);
3992 /* Add the unmodified original or prefix subflow. */
3993 ret = flow_create_split_inner(dev, flow, &dev_flow, prefix_layers, attr,
3994 items, ext_actions ? ext_actions :
3995 actions, external, error);
3998 MLX5_ASSERT(dev_flow);
4000 const struct rte_flow_attr q_attr = {
4001 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4004 /* Internal PMD action to set register. */
4005 struct mlx5_rte_flow_item_tag q_tag_spec = {
4009 struct rte_flow_item q_items[] = {
4011 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4012 .spec = &q_tag_spec,
4017 .type = RTE_FLOW_ITEM_TYPE_END,
4020 struct rte_flow_action q_actions[] = {
4026 .type = RTE_FLOW_ACTION_TYPE_END,
4029 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
4032 * Configure the tag item only if there is no meter subflow.
4033 * Since tag is already marked in the meter suffix subflow
4034 * we can just use the meter suffix items as is.
4037 /* Not meter subflow. */
4038 MLX5_ASSERT(!mtr_sfx);
4040 * Put unique id in prefix flow due to it is destroyed
4041 * after suffix flow and id will be freed after there
4042 * is no actual flows with this id and identifier
4043 * reallocation becomes possible (for example, for
4044 * other flows in other threads).
4046 dev_flow->handle->split_flow_id = qrss_id;
4047 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
4051 q_tag_spec.id = ret;
4054 /* Add suffix subflow to execute Q/RSS. */
4055 ret = flow_create_split_inner(dev, flow, &dev_flow, layers,
4056 &q_attr, mtr_sfx ? items :
4061 /* qrss ID should be freed if failed. */
4063 MLX5_ASSERT(dev_flow);
4068 * We do not destroy the partially created sub_flows in case of error.
4069 * These ones are included into parent flow list and will be destroyed
4070 * by flow_drv_destroy.
4072 flow_qrss_free_id(dev, qrss_id);
4073 rte_free(ext_actions);
4078 * The splitting for meter feature.
4080 * - The meter flow will be split to two flows as prefix and
4081 * suffix flow. The packets make sense only it pass the prefix
4084 * - Reg_C_5 is used for the packet to match betweend prefix and
4088 * Pointer to Ethernet device.
4090 * Parent flow structure pointer.
4092 * Flow rule attributes.
4094 * Pattern specification (list terminated by the END pattern item).
4095 * @param[in] actions
4096 * Associated actions (list terminated by the END action).
4097 * @param[in] external
4098 * This flow rule is created by request external to PMD.
4100 * Perform verbose error reporting if not NULL.
4102 * 0 on success, negative value otherwise
4105 flow_create_split_meter(struct rte_eth_dev *dev,
4106 struct rte_flow *flow,
4107 const struct rte_flow_attr *attr,
4108 const struct rte_flow_item items[],
4109 const struct rte_flow_action actions[],
4110 bool external, struct rte_flow_error *error)
4112 struct mlx5_priv *priv = dev->data->dev_private;
4113 struct rte_flow_action *sfx_actions = NULL;
4114 struct rte_flow_action *pre_actions = NULL;
4115 struct rte_flow_item *sfx_items = NULL;
4116 struct mlx5_flow *dev_flow = NULL;
4117 struct rte_flow_attr sfx_attr = *attr;
4119 uint32_t mtr_tag_id = 0;
4126 actions_n = flow_check_meter_action(actions, &mtr);
4128 /* The five prefix actions: meter, decap, encap, tag, end. */
4129 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
4130 sizeof(struct mlx5_rte_flow_action_set_tag);
4131 /* tag, vlan, port id, end. */
4132 #define METER_SUFFIX_ITEM 4
4133 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
4134 sizeof(struct mlx5_rte_flow_item_tag) * 2;
4135 sfx_actions = rte_zmalloc(__func__, (act_size + item_size), 0);
4137 return rte_flow_error_set(error, ENOMEM,
4138 RTE_FLOW_ERROR_TYPE_ACTION,
4139 NULL, "no memory to split "
4141 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4143 pre_actions = sfx_actions + actions_n;
4144 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
4145 actions, sfx_actions,
4151 /* Add the prefix subflow. */
4152 ret = flow_create_split_inner(dev, flow, &dev_flow, 0, attr,
4153 items, pre_actions, external,
4159 dev_flow->handle->split_flow_id = mtr_tag_id;
4160 /* Setting the sfx group atrr. */
4161 sfx_attr.group = sfx_attr.transfer ?
4162 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4163 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4165 /* Add the prefix subflow. */
4166 ret = flow_create_split_metadata(dev, flow, dev_flow ?
4167 flow_get_prefix_layer_flags(dev_flow) :
4169 sfx_items ? sfx_items : items,
4170 sfx_actions ? sfx_actions : actions,
4174 rte_free(sfx_actions);
4179 * Split the flow to subflow set. The splitters might be linked
4180 * in the chain, like this:
4181 * flow_create_split_outer() calls:
4182 * flow_create_split_meter() calls:
4183 * flow_create_split_metadata(meter_subflow_0) calls:
4184 * flow_create_split_inner(metadata_subflow_0)
4185 * flow_create_split_inner(metadata_subflow_1)
4186 * flow_create_split_inner(metadata_subflow_2)
4187 * flow_create_split_metadata(meter_subflow_1) calls:
4188 * flow_create_split_inner(metadata_subflow_0)
4189 * flow_create_split_inner(metadata_subflow_1)
4190 * flow_create_split_inner(metadata_subflow_2)
4192 * This provide flexible way to add new levels of flow splitting.
4193 * The all of successfully created subflows are included to the
4194 * parent flow dev_flow list.
4197 * Pointer to Ethernet device.
4199 * Parent flow structure pointer.
4201 * Flow rule attributes.
4203 * Pattern specification (list terminated by the END pattern item).
4204 * @param[in] actions
4205 * Associated actions (list terminated by the END action).
4206 * @param[in] external
4207 * This flow rule is created by request external to PMD.
4209 * Perform verbose error reporting if not NULL.
4211 * 0 on success, negative value otherwise
4214 flow_create_split_outer(struct rte_eth_dev *dev,
4215 struct rte_flow *flow,
4216 const struct rte_flow_attr *attr,
4217 const struct rte_flow_item items[],
4218 const struct rte_flow_action actions[],
4219 bool external, struct rte_flow_error *error)
4223 ret = flow_create_split_meter(dev, flow, attr, items,
4224 actions, external, error);
4225 MLX5_ASSERT(ret <= 0);
4230 * Create a flow and add it to @p list.
4233 * Pointer to Ethernet device.
4235 * Pointer to a TAILQ flow list. If this parameter NULL,
4236 * no list insertion occurred, flow is just created,
4237 * this is caller's responsibility to track the
4240 * Flow rule attributes.
4242 * Pattern specification (list terminated by the END pattern item).
4243 * @param[in] actions
4244 * Associated actions (list terminated by the END action).
4245 * @param[in] external
4246 * This flow rule is created by request external to PMD.
4248 * Perform verbose error reporting if not NULL.
4251 * A flow index on success, 0 otherwise and rte_errno is set.
4254 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
4255 const struct rte_flow_attr *attr,
4256 const struct rte_flow_item items[],
4257 const struct rte_flow_action actions[],
4258 bool external, struct rte_flow_error *error)
4260 struct mlx5_priv *priv = dev->data->dev_private;
4261 struct rte_flow *flow = NULL;
4262 struct mlx5_flow *dev_flow;
4263 const struct rte_flow_action_rss *rss;
4265 struct rte_flow_expand_rss buf;
4266 uint8_t buffer[2048];
4269 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4270 uint8_t buffer[2048];
4273 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4274 uint8_t buffer[2048];
4275 } actions_hairpin_tx;
4277 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
4278 uint8_t buffer[2048];
4280 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
4281 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
4282 priv->rss_desc)[!!priv->flow_idx];
4283 const struct rte_flow_action *p_actions_rx = actions;
4287 uint32_t hairpin_id = 0;
4288 struct rte_flow_attr attr_tx = { .priority = 0 };
4291 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4292 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
4293 external, hairpin_flow, error);
4296 if (hairpin_flow > 0) {
4297 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
4301 flow_hairpin_split(dev, actions, actions_rx.actions,
4302 actions_hairpin_tx.actions, items_tx.items,
4304 p_actions_rx = actions_rx.actions;
4306 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
4309 goto error_before_flow;
4311 flow->drv_type = flow_get_drv_type(dev, attr);
4312 if (hairpin_id != 0)
4313 flow->hairpin_flow_id = hairpin_id;
4314 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
4315 flow->drv_type < MLX5_FLOW_TYPE_MAX);
4316 memset(rss_desc, 0, sizeof(*rss_desc));
4317 rss = flow_get_rss_action(p_actions_rx);
4320 * The following information is required by
4321 * mlx5_flow_hashfields_adjust() in advance.
4323 rss_desc->level = rss->level;
4324 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
4325 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
4327 flow->dev_handles = 0;
4328 if (rss && rss->types) {
4329 unsigned int graph_root;
4331 graph_root = find_graph_root(items, rss->level);
4332 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
4334 mlx5_support_expansion,
4336 MLX5_ASSERT(ret > 0 &&
4337 (unsigned int)ret < sizeof(expand_buffer.buffer));
4340 buf->entry[0].pattern = (void *)(uintptr_t)items;
4343 * Record the start index when there is a nested call. All sub-flows
4344 * need to be translated before another calling.
4345 * No need to use ping-pong buffer to save memory here.
4347 if (priv->flow_idx) {
4348 MLX5_ASSERT(!priv->flow_nested_idx);
4349 priv->flow_nested_idx = priv->flow_idx;
4351 for (i = 0; i < buf->entries; ++i) {
4353 * The splitter may create multiple dev_flows,
4354 * depending on configuration. In the simplest
4355 * case it just creates unmodified original flow.
4357 ret = flow_create_split_outer(dev, flow, attr,
4358 buf->entry[i].pattern,
4359 p_actions_rx, external,
4364 /* Create the tx flow. */
4366 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
4367 attr_tx.ingress = 0;
4369 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
4370 actions_hairpin_tx.actions, error);
4373 dev_flow->flow = flow;
4374 dev_flow->external = 0;
4375 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4376 dev_flow->handle, next);
4377 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
4379 actions_hairpin_tx.actions, error);
4384 * Update the metadata register copy table. If extensive
4385 * metadata feature is enabled and registers are supported
4386 * we might create the extra rte_flow for each unique
4387 * MARK/FLAG action ID.
4389 * The table is updated for ingress Flows only, because
4390 * the egress Flows belong to the different device and
4391 * copy table should be updated in peer NIC Rx domain.
4393 if (attr->ingress &&
4394 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
4395 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
4400 * If the flow is external (from application) OR device is started, then
4401 * the flow will be applied immediately.
4403 if (external || dev->data->dev_started) {
4404 ret = flow_drv_apply(dev, flow, error);
4409 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
4411 flow_rxq_flags_set(dev, flow);
4412 /* Nested flow creation index recovery. */
4413 priv->flow_idx = priv->flow_nested_idx;
4414 if (priv->flow_nested_idx)
4415 priv->flow_nested_idx = 0;
4419 ret = rte_errno; /* Save rte_errno before cleanup. */
4420 flow_mreg_del_copy_action(dev, flow);
4421 flow_drv_destroy(dev, flow);
4422 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
4423 rte_errno = ret; /* Restore rte_errno. */
4427 mlx5_flow_id_release(priv->sh->flow_id_pool,
4430 priv->flow_idx = priv->flow_nested_idx;
4431 if (priv->flow_nested_idx)
4432 priv->flow_nested_idx = 0;
4437 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
4438 * incoming packets to table 1.
4440 * Other flow rules, requested for group n, will be created in
4441 * e-switch table n+1.
4442 * Jump action to e-switch group n will be created to group n+1.
4444 * Used when working in switchdev mode, to utilise advantages of table 1
4448 * Pointer to Ethernet device.
4451 * Pointer to flow on success, NULL otherwise and rte_errno is set.
4454 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
4456 const struct rte_flow_attr attr = {
4463 const struct rte_flow_item pattern = {
4464 .type = RTE_FLOW_ITEM_TYPE_END,
4466 struct rte_flow_action_jump jump = {
4469 const struct rte_flow_action actions[] = {
4471 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4475 .type = RTE_FLOW_ACTION_TYPE_END,
4478 struct mlx5_priv *priv = dev->data->dev_private;
4479 struct rte_flow_error error;
4481 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
4483 actions, false, &error);
4487 * Validate a flow supported by the NIC.
4489 * @see rte_flow_validate()
4493 mlx5_flow_validate(struct rte_eth_dev *dev,
4494 const struct rte_flow_attr *attr,
4495 const struct rte_flow_item items[],
4496 const struct rte_flow_action actions[],
4497 struct rte_flow_error *error)
4501 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4502 return flow_drv_validate(dev, attr, items, actions,
4503 true, hairpin_flow, error);
4509 * @see rte_flow_create()
4513 mlx5_flow_create(struct rte_eth_dev *dev,
4514 const struct rte_flow_attr *attr,
4515 const struct rte_flow_item items[],
4516 const struct rte_flow_action actions[],
4517 struct rte_flow_error *error)
4519 struct mlx5_priv *priv = dev->data->dev_private;
4522 * If the device is not started yet, it is not allowed to created a
4523 * flow from application. PMD default flows and traffic control flows
4526 if (unlikely(!dev->data->dev_started)) {
4527 DRV_LOG(DEBUG, "port %u is not started when "
4528 "inserting a flow", dev->data->port_id);
4529 rte_flow_error_set(error, ENODEV,
4530 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4532 "port not started");
4535 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
4536 attr, items, actions, true, error);
4540 * Destroy a flow in a list.
4543 * Pointer to Ethernet device.
4545 * Pointer to the Indexed flow list. If this parameter NULL,
4546 * there is no flow removal from the list. Be noted that as
4547 * flow is add to the indexed list, memory of the indexed
4548 * list points to maybe changed as flow destroyed.
4549 * @param[in] flow_idx
4550 * Index of flow to destroy.
4553 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
4556 struct mlx5_priv *priv = dev->data->dev_private;
4557 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
4558 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
4559 [MLX5_IPOOL_RTE_FLOW], flow_idx);
4564 * Update RX queue flags only if port is started, otherwise it is
4567 if (dev->data->dev_started)
4568 flow_rxq_flags_trim(dev, flow);
4569 if (flow->hairpin_flow_id)
4570 mlx5_flow_id_release(priv->sh->flow_id_pool,
4571 flow->hairpin_flow_id);
4572 flow_drv_destroy(dev, flow);
4574 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
4575 flow_idx, flow, next);
4576 flow_mreg_del_copy_action(dev, flow);
4578 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
4579 if (priv_fdir_flow->rix_flow == flow_idx)
4582 if (priv_fdir_flow) {
4583 LIST_REMOVE(priv_fdir_flow, next);
4584 rte_free(priv_fdir_flow->fdir);
4585 rte_free(priv_fdir_flow);
4588 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
4592 * Destroy all flows.
4595 * Pointer to Ethernet device.
4597 * Pointer to the Indexed flow list.
4599 * If flushing is called avtively.
4602 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
4604 uint32_t num_flushed = 0;
4607 flow_list_destroy(dev, list, *list);
4611 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
4612 dev->data->port_id, num_flushed);
4620 * Pointer to Ethernet device.
4622 * Pointer to the Indexed flow list.
4625 mlx5_flow_stop(struct rte_eth_dev *dev, uint32_t *list)
4627 struct mlx5_priv *priv = dev->data->dev_private;
4628 struct rte_flow *flow = NULL;
4631 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
4633 flow_drv_remove(dev, flow);
4634 flow_mreg_stop_copy_action(dev, flow);
4636 flow_mreg_del_default_copy_action(dev);
4637 flow_rxq_flags_clear(dev);
4644 * Pointer to Ethernet device.
4646 * Pointer to the Indexed flow list.
4649 * 0 on success, a negative errno value otherwise and rte_errno is set.
4652 mlx5_flow_start(struct rte_eth_dev *dev, uint32_t *list)
4654 struct mlx5_priv *priv = dev->data->dev_private;
4655 struct rte_flow *flow = NULL;
4656 struct rte_flow_error error;
4660 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4661 ret = flow_mreg_add_default_copy_action(dev, &error);
4664 /* Apply Flows created by application. */
4665 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
4667 ret = flow_mreg_start_copy_action(dev, flow);
4670 ret = flow_drv_apply(dev, flow, &error);
4673 flow_rxq_flags_set(dev, flow);
4677 ret = rte_errno; /* Save rte_errno before cleanup. */
4678 mlx5_flow_stop(dev, list);
4679 rte_errno = ret; /* Restore rte_errno. */
4684 * Stop all default actions for flows.
4687 * Pointer to Ethernet device.
4690 mlx5_flow_stop_default(struct rte_eth_dev *dev)
4692 flow_mreg_del_default_copy_action(dev);
4693 flow_rxq_flags_clear(dev);
4697 * Start all default actions for flows.
4700 * Pointer to Ethernet device.
4702 * 0 on success, a negative errno value otherwise and rte_errno is set.
4705 mlx5_flow_start_default(struct rte_eth_dev *dev)
4707 struct rte_flow_error error;
4709 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4710 return flow_mreg_add_default_copy_action(dev, &error);
4714 * Allocate intermediate resources for flow creation.
4717 * Pointer to Ethernet device.
4720 mlx5_flow_alloc_intermediate(struct rte_eth_dev *dev)
4722 struct mlx5_priv *priv = dev->data->dev_private;
4724 if (!priv->inter_flows) {
4725 priv->inter_flows = rte_calloc(__func__, 1,
4726 MLX5_NUM_MAX_DEV_FLOWS *
4727 sizeof(struct mlx5_flow) +
4728 (sizeof(struct mlx5_flow_rss_desc) +
4729 sizeof(uint16_t) * UINT16_MAX) * 2, 0);
4730 if (!priv->inter_flows) {
4731 DRV_LOG(ERR, "can't allocate intermediate memory.");
4735 priv->rss_desc = &((struct mlx5_flow *)priv->inter_flows)
4736 [MLX5_NUM_MAX_DEV_FLOWS];
4737 /* Reset the index. */
4739 priv->flow_nested_idx = 0;
4743 * Free intermediate resources for flows.
4746 * Pointer to Ethernet device.
4749 mlx5_flow_free_intermediate(struct rte_eth_dev *dev)
4751 struct mlx5_priv *priv = dev->data->dev_private;
4753 rte_free(priv->inter_flows);
4754 priv->inter_flows = NULL;
4758 * Verify the flow list is empty
4761 * Pointer to Ethernet device.
4763 * @return the number of flows not released.
4766 mlx5_flow_verify(struct rte_eth_dev *dev)
4768 struct mlx5_priv *priv = dev->data->dev_private;
4769 struct rte_flow *flow;
4773 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
4775 DRV_LOG(DEBUG, "port %u flow %p still referenced",
4776 dev->data->port_id, (void *)flow);
4783 * Enable default hairpin egress flow.
4786 * Pointer to Ethernet device.
4791 * 0 on success, a negative errno value otherwise and rte_errno is set.
4794 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
4797 struct mlx5_priv *priv = dev->data->dev_private;
4798 const struct rte_flow_attr attr = {
4802 struct mlx5_rte_flow_item_tx_queue queue_spec = {
4805 struct mlx5_rte_flow_item_tx_queue queue_mask = {
4806 .queue = UINT32_MAX,
4808 struct rte_flow_item items[] = {
4810 .type = MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
4811 .spec = &queue_spec,
4813 .mask = &queue_mask,
4816 .type = RTE_FLOW_ITEM_TYPE_END,
4819 struct rte_flow_action_jump jump = {
4820 .group = MLX5_HAIRPIN_TX_TABLE,
4822 struct rte_flow_action actions[2];
4824 struct rte_flow_error error;
4826 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
4827 actions[0].conf = &jump;
4828 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
4829 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
4830 &attr, items, actions, false, &error);
4833 "Failed to create ctrl flow: rte_errno(%d),"
4834 " type(%d), message(%s)",
4835 rte_errno, error.type,
4836 error.message ? error.message : " (no stated reason)");
4843 * Enable a control flow configured from the control plane.
4846 * Pointer to Ethernet device.
4848 * An Ethernet flow spec to apply.
4850 * An Ethernet flow mask to apply.
4852 * A VLAN flow spec to apply.
4854 * A VLAN flow mask to apply.
4857 * 0 on success, a negative errno value otherwise and rte_errno is set.
4860 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
4861 struct rte_flow_item_eth *eth_spec,
4862 struct rte_flow_item_eth *eth_mask,
4863 struct rte_flow_item_vlan *vlan_spec,
4864 struct rte_flow_item_vlan *vlan_mask)
4866 struct mlx5_priv *priv = dev->data->dev_private;
4867 const struct rte_flow_attr attr = {
4869 .priority = MLX5_FLOW_PRIO_RSVD,
4871 struct rte_flow_item items[] = {
4873 .type = RTE_FLOW_ITEM_TYPE_ETH,
4879 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
4880 RTE_FLOW_ITEM_TYPE_END,
4886 .type = RTE_FLOW_ITEM_TYPE_END,
4889 uint16_t queue[priv->reta_idx_n];
4890 struct rte_flow_action_rss action_rss = {
4891 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4893 .types = priv->rss_conf.rss_hf,
4894 .key_len = priv->rss_conf.rss_key_len,
4895 .queue_num = priv->reta_idx_n,
4896 .key = priv->rss_conf.rss_key,
4899 struct rte_flow_action actions[] = {
4901 .type = RTE_FLOW_ACTION_TYPE_RSS,
4902 .conf = &action_rss,
4905 .type = RTE_FLOW_ACTION_TYPE_END,
4909 struct rte_flow_error error;
4912 if (!priv->reta_idx_n || !priv->rxqs_n) {
4915 for (i = 0; i != priv->reta_idx_n; ++i)
4916 queue[i] = (*priv->reta_idx)[i];
4917 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
4918 &attr, items, actions, false, &error);
4925 * Enable a flow control configured from the control plane.
4928 * Pointer to Ethernet device.
4930 * An Ethernet flow spec to apply.
4932 * An Ethernet flow mask to apply.
4935 * 0 on success, a negative errno value otherwise and rte_errno is set.
4938 mlx5_ctrl_flow(struct rte_eth_dev *dev,
4939 struct rte_flow_item_eth *eth_spec,
4940 struct rte_flow_item_eth *eth_mask)
4942 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
4948 * @see rte_flow_destroy()
4952 mlx5_flow_destroy(struct rte_eth_dev *dev,
4953 struct rte_flow *flow,
4954 struct rte_flow_error *error __rte_unused)
4956 struct mlx5_priv *priv = dev->data->dev_private;
4958 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
4963 * Destroy all flows.
4965 * @see rte_flow_flush()
4969 mlx5_flow_flush(struct rte_eth_dev *dev,
4970 struct rte_flow_error *error __rte_unused)
4972 struct mlx5_priv *priv = dev->data->dev_private;
4974 mlx5_flow_list_flush(dev, &priv->flows, false);
4981 * @see rte_flow_isolate()
4985 mlx5_flow_isolate(struct rte_eth_dev *dev,
4987 struct rte_flow_error *error)
4989 struct mlx5_priv *priv = dev->data->dev_private;
4991 if (dev->data->dev_started) {
4992 rte_flow_error_set(error, EBUSY,
4993 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4995 "port must be stopped first");
4998 priv->isolated = !!enable;
5000 dev->dev_ops = &mlx5_dev_ops_isolate;
5002 dev->dev_ops = &mlx5_dev_ops;
5009 * @see rte_flow_query()
5013 flow_drv_query(struct rte_eth_dev *dev,
5015 const struct rte_flow_action *actions,
5017 struct rte_flow_error *error)
5019 struct mlx5_priv *priv = dev->data->dev_private;
5020 const struct mlx5_flow_driver_ops *fops;
5021 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5022 [MLX5_IPOOL_RTE_FLOW],
5024 enum mlx5_flow_drv_type ftype;
5027 return rte_flow_error_set(error, ENOENT,
5028 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5030 "invalid flow handle");
5032 ftype = flow->drv_type;
5033 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
5034 fops = flow_get_drv_ops(ftype);
5036 return fops->query(dev, flow, actions, data, error);
5042 * @see rte_flow_query()
5046 mlx5_flow_query(struct rte_eth_dev *dev,
5047 struct rte_flow *flow,
5048 const struct rte_flow_action *actions,
5050 struct rte_flow_error *error)
5054 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
5062 * Convert a flow director filter to a generic flow.
5065 * Pointer to Ethernet device.
5066 * @param fdir_filter
5067 * Flow director filter to add.
5069 * Generic flow parameters structure.
5072 * 0 on success, a negative errno value otherwise and rte_errno is set.
5075 flow_fdir_filter_convert(struct rte_eth_dev *dev,
5076 const struct rte_eth_fdir_filter *fdir_filter,
5077 struct mlx5_fdir *attributes)
5079 struct mlx5_priv *priv = dev->data->dev_private;
5080 const struct rte_eth_fdir_input *input = &fdir_filter->input;
5081 const struct rte_eth_fdir_masks *mask =
5082 &dev->data->dev_conf.fdir_conf.mask;
5084 /* Validate queue number. */
5085 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
5086 DRV_LOG(ERR, "port %u invalid queue number %d",
5087 dev->data->port_id, fdir_filter->action.rx_queue);
5091 attributes->attr.ingress = 1;
5092 attributes->items[0] = (struct rte_flow_item) {
5093 .type = RTE_FLOW_ITEM_TYPE_ETH,
5094 .spec = &attributes->l2,
5095 .mask = &attributes->l2_mask,
5097 switch (fdir_filter->action.behavior) {
5098 case RTE_ETH_FDIR_ACCEPT:
5099 attributes->actions[0] = (struct rte_flow_action){
5100 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
5101 .conf = &attributes->queue,
5104 case RTE_ETH_FDIR_REJECT:
5105 attributes->actions[0] = (struct rte_flow_action){
5106 .type = RTE_FLOW_ACTION_TYPE_DROP,
5110 DRV_LOG(ERR, "port %u invalid behavior %d",
5112 fdir_filter->action.behavior);
5113 rte_errno = ENOTSUP;
5116 attributes->queue.index = fdir_filter->action.rx_queue;
5118 switch (fdir_filter->input.flow_type) {
5119 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
5120 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
5121 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
5122 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
5123 .src_addr = input->flow.ip4_flow.src_ip,
5124 .dst_addr = input->flow.ip4_flow.dst_ip,
5125 .time_to_live = input->flow.ip4_flow.ttl,
5126 .type_of_service = input->flow.ip4_flow.tos,
5128 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
5129 .src_addr = mask->ipv4_mask.src_ip,
5130 .dst_addr = mask->ipv4_mask.dst_ip,
5131 .time_to_live = mask->ipv4_mask.ttl,
5132 .type_of_service = mask->ipv4_mask.tos,
5133 .next_proto_id = mask->ipv4_mask.proto,
5135 attributes->items[1] = (struct rte_flow_item){
5136 .type = RTE_FLOW_ITEM_TYPE_IPV4,
5137 .spec = &attributes->l3,
5138 .mask = &attributes->l3_mask,
5141 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
5142 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
5143 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
5144 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
5145 .hop_limits = input->flow.ipv6_flow.hop_limits,
5146 .proto = input->flow.ipv6_flow.proto,
5149 memcpy(attributes->l3.ipv6.hdr.src_addr,
5150 input->flow.ipv6_flow.src_ip,
5151 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
5152 memcpy(attributes->l3.ipv6.hdr.dst_addr,
5153 input->flow.ipv6_flow.dst_ip,
5154 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
5155 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
5156 mask->ipv6_mask.src_ip,
5157 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
5158 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
5159 mask->ipv6_mask.dst_ip,
5160 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
5161 attributes->items[1] = (struct rte_flow_item){
5162 .type = RTE_FLOW_ITEM_TYPE_IPV6,
5163 .spec = &attributes->l3,
5164 .mask = &attributes->l3_mask,
5168 DRV_LOG(ERR, "port %u invalid flow type%d",
5169 dev->data->port_id, fdir_filter->input.flow_type);
5170 rte_errno = ENOTSUP;
5174 switch (fdir_filter->input.flow_type) {
5175 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
5176 attributes->l4.udp.hdr = (struct rte_udp_hdr){
5177 .src_port = input->flow.udp4_flow.src_port,
5178 .dst_port = input->flow.udp4_flow.dst_port,
5180 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
5181 .src_port = mask->src_port_mask,
5182 .dst_port = mask->dst_port_mask,
5184 attributes->items[2] = (struct rte_flow_item){
5185 .type = RTE_FLOW_ITEM_TYPE_UDP,
5186 .spec = &attributes->l4,
5187 .mask = &attributes->l4_mask,
5190 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
5191 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
5192 .src_port = input->flow.tcp4_flow.src_port,
5193 .dst_port = input->flow.tcp4_flow.dst_port,
5195 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
5196 .src_port = mask->src_port_mask,
5197 .dst_port = mask->dst_port_mask,
5199 attributes->items[2] = (struct rte_flow_item){
5200 .type = RTE_FLOW_ITEM_TYPE_TCP,
5201 .spec = &attributes->l4,
5202 .mask = &attributes->l4_mask,
5205 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
5206 attributes->l4.udp.hdr = (struct rte_udp_hdr){
5207 .src_port = input->flow.udp6_flow.src_port,
5208 .dst_port = input->flow.udp6_flow.dst_port,
5210 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
5211 .src_port = mask->src_port_mask,
5212 .dst_port = mask->dst_port_mask,
5214 attributes->items[2] = (struct rte_flow_item){
5215 .type = RTE_FLOW_ITEM_TYPE_UDP,
5216 .spec = &attributes->l4,
5217 .mask = &attributes->l4_mask,
5220 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
5221 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
5222 .src_port = input->flow.tcp6_flow.src_port,
5223 .dst_port = input->flow.tcp6_flow.dst_port,
5225 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
5226 .src_port = mask->src_port_mask,
5227 .dst_port = mask->dst_port_mask,
5229 attributes->items[2] = (struct rte_flow_item){
5230 .type = RTE_FLOW_ITEM_TYPE_TCP,
5231 .spec = &attributes->l4,
5232 .mask = &attributes->l4_mask,
5235 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
5236 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
5239 DRV_LOG(ERR, "port %u invalid flow type%d",
5240 dev->data->port_id, fdir_filter->input.flow_type);
5241 rte_errno = ENOTSUP;
5247 #define FLOW_FDIR_CMP(f1, f2, fld) \
5248 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
5251 * Compare two FDIR flows. If items and actions are identical, the two flows are
5255 * Pointer to Ethernet device.
5257 * FDIR flow to compare.
5259 * FDIR flow to compare.
5262 * Zero on match, 1 otherwise.
5265 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
5267 if (FLOW_FDIR_CMP(f1, f2, attr) ||
5268 FLOW_FDIR_CMP(f1, f2, l2) ||
5269 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
5270 FLOW_FDIR_CMP(f1, f2, l3) ||
5271 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
5272 FLOW_FDIR_CMP(f1, f2, l4) ||
5273 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
5274 FLOW_FDIR_CMP(f1, f2, actions[0].type))
5276 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
5277 FLOW_FDIR_CMP(f1, f2, queue))
5283 * Search device flow list to find out a matched FDIR flow.
5286 * Pointer to Ethernet device.
5288 * FDIR flow to lookup.
5291 * Index of flow if found, 0 otherwise.
5294 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
5296 struct mlx5_priv *priv = dev->data->dev_private;
5297 uint32_t flow_idx = 0;
5298 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5300 MLX5_ASSERT(fdir_flow);
5301 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
5302 if (!flow_fdir_cmp(priv_fdir_flow->fdir, fdir_flow)) {
5303 DRV_LOG(DEBUG, "port %u found FDIR flow %u",
5304 dev->data->port_id, flow_idx);
5305 flow_idx = priv_fdir_flow->rix_flow;
5313 * Add new flow director filter and store it in list.
5316 * Pointer to Ethernet device.
5317 * @param fdir_filter
5318 * Flow director filter to add.
5321 * 0 on success, a negative errno value otherwise and rte_errno is set.
5324 flow_fdir_filter_add(struct rte_eth_dev *dev,
5325 const struct rte_eth_fdir_filter *fdir_filter)
5327 struct mlx5_priv *priv = dev->data->dev_private;
5328 struct mlx5_fdir *fdir_flow;
5329 struct rte_flow *flow;
5330 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5334 fdir_flow = rte_zmalloc(__func__, sizeof(*fdir_flow), 0);
5339 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
5342 flow_idx = flow_fdir_filter_lookup(dev, fdir_flow);
5347 priv_fdir_flow = rte_zmalloc(__func__, sizeof(struct mlx5_fdir_flow),
5349 if (!priv_fdir_flow) {
5353 flow_idx = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
5354 fdir_flow->items, fdir_flow->actions, true,
5356 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5360 priv_fdir_flow->fdir = fdir_flow;
5361 priv_fdir_flow->rix_flow = flow_idx;
5362 LIST_INSERT_HEAD(&priv->fdir_flows, priv_fdir_flow, next);
5363 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
5364 dev->data->port_id, (void *)flow);
5367 rte_free(priv_fdir_flow);
5368 rte_free(fdir_flow);
5373 * Delete specific filter.
5376 * Pointer to Ethernet device.
5377 * @param fdir_filter
5378 * Filter to be deleted.
5381 * 0 on success, a negative errno value otherwise and rte_errno is set.
5384 flow_fdir_filter_delete(struct rte_eth_dev *dev,
5385 const struct rte_eth_fdir_filter *fdir_filter)
5387 struct mlx5_priv *priv = dev->data->dev_private;
5389 struct mlx5_fdir fdir_flow = {
5392 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5395 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
5398 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
5399 /* Find the fdir in priv list */
5400 if (!flow_fdir_cmp(priv_fdir_flow->fdir, &fdir_flow))
5403 if (!priv_fdir_flow)
5405 LIST_REMOVE(priv_fdir_flow, next);
5406 flow_idx = priv_fdir_flow->rix_flow;
5407 flow_list_destroy(dev, &priv->flows, flow_idx);
5408 rte_free(priv_fdir_flow->fdir);
5409 rte_free(priv_fdir_flow);
5410 DRV_LOG(DEBUG, "port %u deleted FDIR flow %u",
5411 dev->data->port_id, flow_idx);
5416 * Update queue for specific filter.
5419 * Pointer to Ethernet device.
5420 * @param fdir_filter
5421 * Filter to be updated.
5424 * 0 on success, a negative errno value otherwise and rte_errno is set.
5427 flow_fdir_filter_update(struct rte_eth_dev *dev,
5428 const struct rte_eth_fdir_filter *fdir_filter)
5432 ret = flow_fdir_filter_delete(dev, fdir_filter);
5435 return flow_fdir_filter_add(dev, fdir_filter);
5439 * Flush all filters.
5442 * Pointer to Ethernet device.
5445 flow_fdir_filter_flush(struct rte_eth_dev *dev)
5447 struct mlx5_priv *priv = dev->data->dev_private;
5448 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5450 while (!LIST_EMPTY(&priv->fdir_flows)) {
5451 priv_fdir_flow = LIST_FIRST(&priv->fdir_flows);
5452 LIST_REMOVE(priv_fdir_flow, next);
5453 flow_list_destroy(dev, &priv->flows, priv_fdir_flow->rix_flow);
5454 rte_free(priv_fdir_flow->fdir);
5455 rte_free(priv_fdir_flow);
5460 * Get flow director information.
5463 * Pointer to Ethernet device.
5464 * @param[out] fdir_info
5465 * Resulting flow director information.
5468 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
5470 struct rte_eth_fdir_masks *mask =
5471 &dev->data->dev_conf.fdir_conf.mask;
5473 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
5474 fdir_info->guarant_spc = 0;
5475 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
5476 fdir_info->max_flexpayload = 0;
5477 fdir_info->flow_types_mask[0] = 0;
5478 fdir_info->flex_payload_unit = 0;
5479 fdir_info->max_flex_payload_segment_num = 0;
5480 fdir_info->flex_payload_limit = 0;
5481 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
5485 * Deal with flow director operations.
5488 * Pointer to Ethernet device.
5490 * Operation to perform.
5492 * Pointer to operation-specific structure.
5495 * 0 on success, a negative errno value otherwise and rte_errno is set.
5498 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
5501 enum rte_fdir_mode fdir_mode =
5502 dev->data->dev_conf.fdir_conf.mode;
5504 if (filter_op == RTE_ETH_FILTER_NOP)
5506 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
5507 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5508 DRV_LOG(ERR, "port %u flow director mode %d not supported",
5509 dev->data->port_id, fdir_mode);
5513 switch (filter_op) {
5514 case RTE_ETH_FILTER_ADD:
5515 return flow_fdir_filter_add(dev, arg);
5516 case RTE_ETH_FILTER_UPDATE:
5517 return flow_fdir_filter_update(dev, arg);
5518 case RTE_ETH_FILTER_DELETE:
5519 return flow_fdir_filter_delete(dev, arg);
5520 case RTE_ETH_FILTER_FLUSH:
5521 flow_fdir_filter_flush(dev);
5523 case RTE_ETH_FILTER_INFO:
5524 flow_fdir_info_get(dev, arg);
5527 DRV_LOG(DEBUG, "port %u unknown operation %u",
5528 dev->data->port_id, filter_op);
5536 * Manage filter operations.
5539 * Pointer to Ethernet device structure.
5540 * @param filter_type
5543 * Operation to perform.
5545 * Pointer to operation-specific structure.
5548 * 0 on success, a negative errno value otherwise and rte_errno is set.
5551 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
5552 enum rte_filter_type filter_type,
5553 enum rte_filter_op filter_op,
5556 switch (filter_type) {
5557 case RTE_ETH_FILTER_GENERIC:
5558 if (filter_op != RTE_ETH_FILTER_GET) {
5562 *(const void **)arg = &mlx5_flow_ops;
5564 case RTE_ETH_FILTER_FDIR:
5565 return flow_fdir_ctrl_func(dev, filter_op, arg);
5567 DRV_LOG(ERR, "port %u filter type (%d) not supported",
5568 dev->data->port_id, filter_type);
5569 rte_errno = ENOTSUP;
5576 * Create the needed meter and suffix tables.
5579 * Pointer to Ethernet device.
5581 * Pointer to the flow meter.
5584 * Pointer to table set on success, NULL otherwise.
5586 struct mlx5_meter_domains_infos *
5587 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
5588 const struct mlx5_flow_meter *fm)
5590 const struct mlx5_flow_driver_ops *fops;
5592 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5593 return fops->create_mtr_tbls(dev, fm);
5597 * Destroy the meter table set.
5600 * Pointer to Ethernet device.
5602 * Pointer to the meter table set.
5608 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
5609 struct mlx5_meter_domains_infos *tbls)
5611 const struct mlx5_flow_driver_ops *fops;
5613 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5614 return fops->destroy_mtr_tbls(dev, tbls);
5618 * Create policer rules.
5621 * Pointer to Ethernet device.
5623 * Pointer to flow meter structure.
5625 * Pointer to flow attributes.
5628 * 0 on success, -1 otherwise.
5631 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
5632 struct mlx5_flow_meter *fm,
5633 const struct rte_flow_attr *attr)
5635 const struct mlx5_flow_driver_ops *fops;
5637 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5638 return fops->create_policer_rules(dev, fm, attr);
5642 * Destroy policer rules.
5645 * Pointer to flow meter structure.
5647 * Pointer to flow attributes.
5650 * 0 on success, -1 otherwise.
5653 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
5654 struct mlx5_flow_meter *fm,
5655 const struct rte_flow_attr *attr)
5657 const struct mlx5_flow_driver_ops *fops;
5659 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5660 return fops->destroy_policer_rules(dev, fm, attr);
5664 * Allocate a counter.
5667 * Pointer to Ethernet device structure.
5670 * Index to allocated counter on success, 0 otherwise.
5673 mlx5_counter_alloc(struct rte_eth_dev *dev)
5675 const struct mlx5_flow_driver_ops *fops;
5676 struct rte_flow_attr attr = { .transfer = 0 };
5678 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5679 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5680 return fops->counter_alloc(dev);
5683 "port %u counter allocate is not supported.",
5684 dev->data->port_id);
5692 * Pointer to Ethernet device structure.
5694 * Index to counter to be free.
5697 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
5699 const struct mlx5_flow_driver_ops *fops;
5700 struct rte_flow_attr attr = { .transfer = 0 };
5702 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5703 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5704 fops->counter_free(dev, cnt);
5708 "port %u counter free is not supported.",
5709 dev->data->port_id);
5713 * Query counter statistics.
5716 * Pointer to Ethernet device structure.
5718 * Index to counter to query.
5720 * Set to clear counter statistics.
5722 * The counter hits packets number to save.
5724 * The counter hits bytes number to save.
5727 * 0 on success, a negative errno value otherwise.
5730 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
5731 bool clear, uint64_t *pkts, uint64_t *bytes)
5733 const struct mlx5_flow_driver_ops *fops;
5734 struct rte_flow_attr attr = { .transfer = 0 };
5736 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5737 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5738 return fops->counter_query(dev, cnt, clear, pkts, bytes);
5741 "port %u counter query is not supported.",
5742 dev->data->port_id);
5746 #define MLX5_POOL_QUERY_FREQ_US 1000000
5749 * Set the periodic procedure for triggering asynchronous batch queries for all
5750 * the counter pools.
5753 * Pointer to mlx5_ibv_shared object.
5756 mlx5_set_query_alarm(struct mlx5_ibv_shared *sh)
5758 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(sh, 0, 0);
5759 uint32_t pools_n = rte_atomic16_read(&cont->n_valid);
5762 cont = MLX5_CNT_CONTAINER(sh, 1, 0);
5763 pools_n += rte_atomic16_read(&cont->n_valid);
5764 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
5765 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
5766 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
5767 sh->cmng.query_thread_on = 0;
5768 DRV_LOG(ERR, "Cannot reinitialize query alarm");
5770 sh->cmng.query_thread_on = 1;
5775 * The periodic procedure for triggering asynchronous batch queries for all the
5776 * counter pools. This function is probably called by the host thread.
5779 * The parameter for the alarm process.
5782 mlx5_flow_query_alarm(void *arg)
5784 struct mlx5_ibv_shared *sh = arg;
5785 struct mlx5_devx_obj *dcs;
5788 uint8_t batch = sh->cmng.batch;
5789 uint16_t pool_index = sh->cmng.pool_index;
5790 struct mlx5_pools_container *cont;
5791 struct mlx5_pools_container *mcont;
5792 struct mlx5_flow_counter_pool *pool;
5794 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
5797 cont = MLX5_CNT_CONTAINER(sh, batch, 1);
5798 mcont = MLX5_CNT_CONTAINER(sh, batch, 0);
5799 /* Check if resize was done and need to flip a container. */
5800 if (cont != mcont) {
5802 /* Clean the old container. */
5803 rte_free(cont->pools);
5804 memset(cont, 0, sizeof(*cont));
5807 /* Flip the host container. */
5808 sh->cmng.mhi[batch] ^= (uint8_t)2;
5812 /* 2 empty containers case is unexpected. */
5813 if (unlikely(batch != sh->cmng.batch))
5817 goto next_container;
5819 pool = cont->pools[pool_index];
5821 /* There is a pool query in progress. */
5824 LIST_FIRST(&sh->cmng.free_stat_raws);
5826 /* No free counter statistics raw memory. */
5828 dcs = (struct mlx5_devx_obj *)(uintptr_t)rte_atomic64_read
5830 offset = batch ? 0 : dcs->id % MLX5_COUNTERS_PER_POOL;
5832 * Identify the counters released between query trigger and query
5833 * handle more effiecntly. The counter released in this gap period
5834 * should wait for a new round of query as the new arrived packets
5835 * will not be taken into account.
5837 rte_atomic64_add(&pool->start_query_gen, 1);
5838 ret = mlx5_devx_cmd_flow_counter_query(dcs, 0, MLX5_COUNTERS_PER_POOL -
5840 pool->raw_hw->mem_mng->dm->id,
5842 (pool->raw_hw->data + offset),
5844 (uint64_t)(uintptr_t)pool);
5846 rte_atomic64_sub(&pool->start_query_gen, 1);
5847 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
5848 " %d", pool->min_dcs->id);
5849 pool->raw_hw = NULL;
5852 pool->raw_hw->min_dcs_id = dcs->id;
5853 LIST_REMOVE(pool->raw_hw, next);
5854 sh->cmng.pending_queries++;
5856 if (pool_index >= rte_atomic16_read(&cont->n_valid)) {
5861 sh->cmng.batch = batch;
5862 sh->cmng.pool_index = pool_index;
5863 mlx5_set_query_alarm(sh);
5867 * Handler for the HW respond about ready values from an asynchronous batch
5868 * query. This function is probably called by the host thread.
5871 * The pointer to the shared IB device context.
5872 * @param[in] async_id
5873 * The Devx async ID.
5875 * The status of the completion.
5878 mlx5_flow_async_pool_query_handle(struct mlx5_ibv_shared *sh,
5879 uint64_t async_id, int status)
5881 struct mlx5_flow_counter_pool *pool =
5882 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
5883 struct mlx5_counter_stats_raw *raw_to_free;
5885 if (unlikely(status)) {
5886 rte_atomic64_sub(&pool->start_query_gen, 1);
5887 raw_to_free = pool->raw_hw;
5889 raw_to_free = pool->raw;
5890 rte_spinlock_lock(&pool->sl);
5891 pool->raw = pool->raw_hw;
5892 rte_spinlock_unlock(&pool->sl);
5893 MLX5_ASSERT(rte_atomic64_read(&pool->end_query_gen) + 1 ==
5894 rte_atomic64_read(&pool->start_query_gen));
5895 rte_atomic64_set(&pool->end_query_gen,
5896 rte_atomic64_read(&pool->start_query_gen));
5897 /* Be sure the new raw counters data is updated in memory. */
5900 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
5901 pool->raw_hw = NULL;
5902 sh->cmng.pending_queries--;
5906 * Translate the rte_flow group index to HW table value.
5908 * @param[in] attributes
5909 * Pointer to flow attributes
5910 * @param[in] external
5911 * Value is part of flow rule created by request external to PMD.
5913 * rte_flow group index value.
5914 * @param[out] fdb_def_rule
5915 * Whether fdb jump to table 1 is configured.
5919 * Pointer to error structure.
5922 * 0 on success, a negative errno value otherwise and rte_errno is set.
5925 mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, bool external,
5926 uint32_t group, bool fdb_def_rule, uint32_t *table,
5927 struct rte_flow_error *error)
5929 if (attributes->transfer && external && fdb_def_rule) {
5930 if (group == UINT32_MAX)
5931 return rte_flow_error_set
5933 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5935 "group index not supported");
5944 * Discover availability of metadata reg_c's.
5946 * Iteratively use test flows to check availability.
5949 * Pointer to the Ethernet device structure.
5952 * 0 on success, a negative errno value otherwise and rte_errno is set.
5955 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
5957 struct mlx5_priv *priv = dev->data->dev_private;
5958 struct mlx5_dev_config *config = &priv->config;
5959 enum modify_reg idx;
5962 /* reg_c[0] and reg_c[1] are reserved. */
5963 config->flow_mreg_c[n++] = REG_C_0;
5964 config->flow_mreg_c[n++] = REG_C_1;
5965 /* Discover availability of other reg_c's. */
5966 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
5967 struct rte_flow_attr attr = {
5968 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5969 .priority = MLX5_FLOW_PRIO_RSVD,
5972 struct rte_flow_item items[] = {
5974 .type = RTE_FLOW_ITEM_TYPE_END,
5977 struct rte_flow_action actions[] = {
5979 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5980 .conf = &(struct mlx5_flow_action_copy_mreg){
5986 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5987 .conf = &(struct rte_flow_action_jump){
5988 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5992 .type = RTE_FLOW_ACTION_TYPE_END,
5996 struct rte_flow *flow;
5997 struct rte_flow_error error;
5999 if (!config->dv_flow_en)
6001 /* Create internal flow, validation skips copy action. */
6002 flow_idx = flow_list_create(dev, NULL, &attr, items,
6003 actions, false, &error);
6004 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
6008 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
6009 config->flow_mreg_c[n++] = idx;
6010 flow_list_destroy(dev, NULL, flow_idx);
6012 for (; n < MLX5_MREG_C_NUM; ++n)
6013 config->flow_mreg_c[n] = REG_NONE;
6018 * Dump flow raw hw data to file
6021 * The pointer to Ethernet device.
6023 * A pointer to a file for output.
6025 * Perform verbose error reporting if not NULL. PMDs initialize this
6026 * structure in case of error only.
6028 * 0 on success, a nagative value otherwise.
6031 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
6033 struct rte_flow_error *error __rte_unused)
6035 struct mlx5_priv *priv = dev->data->dev_private;
6036 struct mlx5_ibv_shared *sh = priv->sh;
6038 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
6039 sh->tx_domain, file);