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_cycles.h>
28 #include <rte_flow_driver.h>
29 #include <rte_malloc.h>
32 #include <mlx5_glue.h>
33 #include <mlx5_devx_cmds.h>
35 #include <mlx5_malloc.h>
37 #include "mlx5_defs.h"
39 #include "mlx5_flow.h"
40 #include "mlx5_flow_os.h"
41 #include "mlx5_rxtx.h"
43 /** Device flow drivers. */
44 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
46 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
48 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
49 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
50 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
51 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
53 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
54 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
59 MLX5_EXPANSION_ROOT_OUTER,
60 MLX5_EXPANSION_ROOT_ETH_VLAN,
61 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
62 MLX5_EXPANSION_OUTER_ETH,
63 MLX5_EXPANSION_OUTER_ETH_VLAN,
64 MLX5_EXPANSION_OUTER_VLAN,
65 MLX5_EXPANSION_OUTER_IPV4,
66 MLX5_EXPANSION_OUTER_IPV4_UDP,
67 MLX5_EXPANSION_OUTER_IPV4_TCP,
68 MLX5_EXPANSION_OUTER_IPV6,
69 MLX5_EXPANSION_OUTER_IPV6_UDP,
70 MLX5_EXPANSION_OUTER_IPV6_TCP,
72 MLX5_EXPANSION_VXLAN_GPE,
76 MLX5_EXPANSION_ETH_VLAN,
79 MLX5_EXPANSION_IPV4_UDP,
80 MLX5_EXPANSION_IPV4_TCP,
82 MLX5_EXPANSION_IPV6_UDP,
83 MLX5_EXPANSION_IPV6_TCP,
86 /** Supported expansion of items. */
87 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
88 [MLX5_EXPANSION_ROOT] = {
89 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
92 .type = RTE_FLOW_ITEM_TYPE_END,
94 [MLX5_EXPANSION_ROOT_OUTER] = {
95 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
96 MLX5_EXPANSION_OUTER_IPV4,
97 MLX5_EXPANSION_OUTER_IPV6),
98 .type = RTE_FLOW_ITEM_TYPE_END,
100 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
101 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
102 .type = RTE_FLOW_ITEM_TYPE_END,
104 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
105 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
106 .type = RTE_FLOW_ITEM_TYPE_END,
108 [MLX5_EXPANSION_OUTER_ETH] = {
109 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
110 MLX5_EXPANSION_OUTER_IPV6,
111 MLX5_EXPANSION_MPLS),
112 .type = RTE_FLOW_ITEM_TYPE_ETH,
115 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
116 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
117 .type = RTE_FLOW_ITEM_TYPE_ETH,
120 [MLX5_EXPANSION_OUTER_VLAN] = {
121 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
122 MLX5_EXPANSION_OUTER_IPV6),
123 .type = RTE_FLOW_ITEM_TYPE_VLAN,
125 [MLX5_EXPANSION_OUTER_IPV4] = {
126 .next = RTE_FLOW_EXPAND_RSS_NEXT
127 (MLX5_EXPANSION_OUTER_IPV4_UDP,
128 MLX5_EXPANSION_OUTER_IPV4_TCP,
131 MLX5_EXPANSION_IPV6),
132 .type = RTE_FLOW_ITEM_TYPE_IPV4,
133 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
134 ETH_RSS_NONFRAG_IPV4_OTHER,
136 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
137 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
138 MLX5_EXPANSION_VXLAN_GPE),
139 .type = RTE_FLOW_ITEM_TYPE_UDP,
140 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
142 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
143 .type = RTE_FLOW_ITEM_TYPE_TCP,
144 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
146 [MLX5_EXPANSION_OUTER_IPV6] = {
147 .next = RTE_FLOW_EXPAND_RSS_NEXT
148 (MLX5_EXPANSION_OUTER_IPV6_UDP,
149 MLX5_EXPANSION_OUTER_IPV6_TCP,
151 MLX5_EXPANSION_IPV6),
152 .type = RTE_FLOW_ITEM_TYPE_IPV6,
153 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
154 ETH_RSS_NONFRAG_IPV6_OTHER,
156 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
157 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
158 MLX5_EXPANSION_VXLAN_GPE),
159 .type = RTE_FLOW_ITEM_TYPE_UDP,
160 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
162 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
163 .type = RTE_FLOW_ITEM_TYPE_TCP,
164 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
166 [MLX5_EXPANSION_VXLAN] = {
167 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
169 MLX5_EXPANSION_IPV6),
170 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
172 [MLX5_EXPANSION_VXLAN_GPE] = {
173 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
175 MLX5_EXPANSION_IPV6),
176 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
178 [MLX5_EXPANSION_GRE] = {
179 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
180 .type = RTE_FLOW_ITEM_TYPE_GRE,
182 [MLX5_EXPANSION_MPLS] = {
183 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
184 MLX5_EXPANSION_IPV6),
185 .type = RTE_FLOW_ITEM_TYPE_MPLS,
187 [MLX5_EXPANSION_ETH] = {
188 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
189 MLX5_EXPANSION_IPV6),
190 .type = RTE_FLOW_ITEM_TYPE_ETH,
192 [MLX5_EXPANSION_ETH_VLAN] = {
193 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
194 .type = RTE_FLOW_ITEM_TYPE_ETH,
196 [MLX5_EXPANSION_VLAN] = {
197 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
198 MLX5_EXPANSION_IPV6),
199 .type = RTE_FLOW_ITEM_TYPE_VLAN,
201 [MLX5_EXPANSION_IPV4] = {
202 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
203 MLX5_EXPANSION_IPV4_TCP),
204 .type = RTE_FLOW_ITEM_TYPE_IPV4,
205 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
206 ETH_RSS_NONFRAG_IPV4_OTHER,
208 [MLX5_EXPANSION_IPV4_UDP] = {
209 .type = RTE_FLOW_ITEM_TYPE_UDP,
210 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
212 [MLX5_EXPANSION_IPV4_TCP] = {
213 .type = RTE_FLOW_ITEM_TYPE_TCP,
214 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
216 [MLX5_EXPANSION_IPV6] = {
217 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
218 MLX5_EXPANSION_IPV6_TCP),
219 .type = RTE_FLOW_ITEM_TYPE_IPV6,
220 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
221 ETH_RSS_NONFRAG_IPV6_OTHER,
223 [MLX5_EXPANSION_IPV6_UDP] = {
224 .type = RTE_FLOW_ITEM_TYPE_UDP,
225 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
227 [MLX5_EXPANSION_IPV6_TCP] = {
228 .type = RTE_FLOW_ITEM_TYPE_TCP,
229 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
233 static const struct rte_flow_ops mlx5_flow_ops = {
234 .validate = mlx5_flow_validate,
235 .create = mlx5_flow_create,
236 .destroy = mlx5_flow_destroy,
237 .flush = mlx5_flow_flush,
238 .isolate = mlx5_flow_isolate,
239 .query = mlx5_flow_query,
240 .dev_dump = mlx5_flow_dev_dump,
241 .get_aged_flows = mlx5_flow_get_aged_flows,
244 /* Convert FDIR request to Generic flow. */
246 struct rte_flow_attr attr;
247 struct rte_flow_item items[4];
248 struct rte_flow_item_eth l2;
249 struct rte_flow_item_eth l2_mask;
251 struct rte_flow_item_ipv4 ipv4;
252 struct rte_flow_item_ipv6 ipv6;
255 struct rte_flow_item_ipv4 ipv4;
256 struct rte_flow_item_ipv6 ipv6;
259 struct rte_flow_item_udp udp;
260 struct rte_flow_item_tcp tcp;
263 struct rte_flow_item_udp udp;
264 struct rte_flow_item_tcp tcp;
266 struct rte_flow_action actions[2];
267 struct rte_flow_action_queue queue;
270 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
271 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
272 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
275 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
276 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
277 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
278 { 9, 10, 11 }, { 12, 13, 14 },
281 /* Tunnel information. */
282 struct mlx5_flow_tunnel_info {
283 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
284 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
287 static struct mlx5_flow_tunnel_info tunnels_info[] = {
289 .tunnel = MLX5_FLOW_LAYER_VXLAN,
290 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
293 .tunnel = MLX5_FLOW_LAYER_GENEVE,
294 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
297 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
298 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
301 .tunnel = MLX5_FLOW_LAYER_GRE,
302 .ptype = RTE_PTYPE_TUNNEL_GRE,
305 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
306 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
309 .tunnel = MLX5_FLOW_LAYER_MPLS,
310 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
313 .tunnel = MLX5_FLOW_LAYER_NVGRE,
314 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
317 .tunnel = MLX5_FLOW_LAYER_IPIP,
318 .ptype = RTE_PTYPE_TUNNEL_IP,
321 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
322 .ptype = RTE_PTYPE_TUNNEL_IP,
325 .tunnel = MLX5_FLOW_LAYER_GTP,
326 .ptype = RTE_PTYPE_TUNNEL_GTPU,
331 * Translate tag ID to register.
334 * Pointer to the Ethernet device structure.
336 * The feature that request the register.
338 * The request register ID.
340 * Error description in case of any.
343 * The request register on success, a negative errno
344 * value otherwise and rte_errno is set.
347 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
348 enum mlx5_feature_name feature,
350 struct rte_flow_error *error)
352 struct mlx5_priv *priv = dev->data->dev_private;
353 struct mlx5_dev_config *config = &priv->config;
354 enum modify_reg start_reg;
355 bool skip_mtr_reg = false;
358 case MLX5_HAIRPIN_RX:
360 case MLX5_HAIRPIN_TX:
362 case MLX5_METADATA_RX:
363 switch (config->dv_xmeta_en) {
364 case MLX5_XMETA_MODE_LEGACY:
366 case MLX5_XMETA_MODE_META16:
368 case MLX5_XMETA_MODE_META32:
372 case MLX5_METADATA_TX:
374 case MLX5_METADATA_FDB:
375 switch (config->dv_xmeta_en) {
376 case MLX5_XMETA_MODE_LEGACY:
378 case MLX5_XMETA_MODE_META16:
380 case MLX5_XMETA_MODE_META32:
385 switch (config->dv_xmeta_en) {
386 case MLX5_XMETA_MODE_LEGACY:
388 case MLX5_XMETA_MODE_META16:
390 case MLX5_XMETA_MODE_META32:
396 * If meter color and flow match share one register, flow match
397 * should use the meter color register for match.
399 if (priv->mtr_reg_share)
400 return priv->mtr_color_reg;
402 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
405 MLX5_ASSERT(priv->mtr_color_reg != REG_NONE);
406 return priv->mtr_color_reg;
409 * Metadata COPY_MARK register using is in meter suffix sub
410 * flow while with meter. It's safe to share the same register.
412 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
415 * If meter is enable, it will engage the register for color
416 * match and flow match. If meter color match is not using the
417 * REG_C_2, need to skip the REG_C_x be used by meter color
419 * If meter is disable, free to use all available registers.
421 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
422 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
423 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
424 if (id > (REG_C_7 - start_reg))
425 return rte_flow_error_set(error, EINVAL,
426 RTE_FLOW_ERROR_TYPE_ITEM,
427 NULL, "invalid tag id");
428 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NONE)
429 return rte_flow_error_set(error, ENOTSUP,
430 RTE_FLOW_ERROR_TYPE_ITEM,
431 NULL, "unsupported tag id");
433 * This case means meter is using the REG_C_x great than 2.
434 * Take care not to conflict with meter color REG_C_x.
435 * If the available index REG_C_y >= REG_C_x, skip the
438 if (skip_mtr_reg && config->flow_mreg_c
439 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
440 if (id >= (REG_C_7 - start_reg))
441 return rte_flow_error_set(error, EINVAL,
442 RTE_FLOW_ERROR_TYPE_ITEM,
443 NULL, "invalid tag id");
444 if (config->flow_mreg_c
445 [id + 1 + start_reg - REG_C_0] != REG_NONE)
446 return config->flow_mreg_c
447 [id + 1 + start_reg - REG_C_0];
448 return rte_flow_error_set(error, ENOTSUP,
449 RTE_FLOW_ERROR_TYPE_ITEM,
450 NULL, "unsupported tag id");
452 return config->flow_mreg_c[id + start_reg - REG_C_0];
455 return rte_flow_error_set(error, EINVAL,
456 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
457 NULL, "invalid feature name");
461 * Check extensive flow metadata register support.
464 * Pointer to rte_eth_dev structure.
467 * True if device supports extensive flow metadata register, otherwise false.
470 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
472 struct mlx5_priv *priv = dev->data->dev_private;
473 struct mlx5_dev_config *config = &priv->config;
476 * Having available reg_c can be regarded inclusively as supporting
477 * extensive flow metadata register, which could mean,
478 * - metadata register copy action by modify header.
479 * - 16 modify header actions is supported.
480 * - reg_c's are preserved across different domain (FDB and NIC) on
481 * packet loopback by flow lookup miss.
483 return config->flow_mreg_c[2] != REG_NONE;
487 * Discover the maximum number of priority available.
490 * Pointer to the Ethernet device structure.
493 * number of supported flow priority on success, a negative errno
494 * value otherwise and rte_errno is set.
497 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
499 struct mlx5_priv *priv = dev->data->dev_private;
501 struct ibv_flow_attr attr;
502 struct ibv_flow_spec_eth eth;
503 struct ibv_flow_spec_action_drop drop;
507 .port = (uint8_t)priv->dev_port,
510 .type = IBV_FLOW_SPEC_ETH,
511 .size = sizeof(struct ibv_flow_spec_eth),
514 .size = sizeof(struct ibv_flow_spec_action_drop),
515 .type = IBV_FLOW_SPEC_ACTION_DROP,
518 struct ibv_flow *flow;
519 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
520 uint16_t vprio[] = { 8, 16 };
528 for (i = 0; i != RTE_DIM(vprio); i++) {
529 flow_attr.attr.priority = vprio[i] - 1;
530 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
533 claim_zero(mlx5_glue->destroy_flow(flow));
536 mlx5_hrxq_drop_release(dev);
539 priority = RTE_DIM(priority_map_3);
542 priority = RTE_DIM(priority_map_5);
547 "port %u verbs maximum priority: %d expected 8/16",
548 dev->data->port_id, priority);
551 DRV_LOG(INFO, "port %u flow maximum priority: %d",
552 dev->data->port_id, priority);
557 * Adjust flow priority based on the highest layer and the request priority.
560 * Pointer to the Ethernet device structure.
561 * @param[in] priority
562 * The rule base priority.
563 * @param[in] subpriority
564 * The priority based on the items.
569 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
570 uint32_t subpriority)
573 struct mlx5_priv *priv = dev->data->dev_private;
575 switch (priv->config.flow_prio) {
576 case RTE_DIM(priority_map_3):
577 res = priority_map_3[priority][subpriority];
579 case RTE_DIM(priority_map_5):
580 res = priority_map_5[priority][subpriority];
587 * Verify the @p item specifications (spec, last, mask) are compatible with the
591 * Item specification.
593 * @p item->mask or flow default bit-masks.
594 * @param[in] nic_mask
595 * Bit-masks covering supported fields by the NIC to compare with user mask.
597 * Bit-masks size in bytes.
599 * Pointer to error structure.
602 * 0 on success, a negative errno value otherwise and rte_errno is set.
605 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
607 const uint8_t *nic_mask,
609 struct rte_flow_error *error)
613 MLX5_ASSERT(nic_mask);
614 for (i = 0; i < size; ++i)
615 if ((nic_mask[i] | mask[i]) != nic_mask[i])
616 return rte_flow_error_set(error, ENOTSUP,
617 RTE_FLOW_ERROR_TYPE_ITEM,
619 "mask enables non supported"
621 if (!item->spec && (item->mask || item->last))
622 return rte_flow_error_set(error, EINVAL,
623 RTE_FLOW_ERROR_TYPE_ITEM, item,
624 "mask/last without a spec is not"
626 if (item->spec && item->last) {
632 for (i = 0; i < size; ++i) {
633 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
634 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
636 ret = memcmp(spec, last, size);
638 return rte_flow_error_set(error, EINVAL,
639 RTE_FLOW_ERROR_TYPE_ITEM,
641 "range is not valid");
647 * Adjust the hash fields according to the @p flow information.
649 * @param[in] dev_flow.
650 * Pointer to the mlx5_flow.
652 * 1 when the hash field is for a tunnel item.
653 * @param[in] layer_types
655 * @param[in] hash_fields
659 * The hash fields that should be used.
662 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
663 int tunnel __rte_unused, uint64_t layer_types,
664 uint64_t hash_fields)
666 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
667 int rss_request_inner = rss_desc->level >= 2;
669 /* Check RSS hash level for tunnel. */
670 if (tunnel && rss_request_inner)
671 hash_fields |= IBV_RX_HASH_INNER;
672 else if (tunnel || rss_request_inner)
675 /* Check if requested layer matches RSS hash fields. */
676 if (!(rss_desc->types & layer_types))
682 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
683 * if several tunnel rules are used on this queue, the tunnel ptype will be
687 * Rx queue to update.
690 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
693 uint32_t tunnel_ptype = 0;
695 /* Look up for the ptype to use. */
696 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
697 if (!rxq_ctrl->flow_tunnels_n[i])
700 tunnel_ptype = tunnels_info[i].ptype;
706 rxq_ctrl->rxq.tunnel = tunnel_ptype;
710 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
714 * Pointer to the Ethernet device structure.
715 * @param[in] dev_handle
716 * Pointer to device flow handle structure.
719 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
720 struct mlx5_flow_handle *dev_handle)
722 struct mlx5_priv *priv = dev->data->dev_private;
723 const int mark = dev_handle->mark;
724 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
725 struct mlx5_hrxq *hrxq;
728 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
730 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
731 dev_handle->rix_hrxq);
734 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
735 int idx = hrxq->ind_table->queues[i];
736 struct mlx5_rxq_ctrl *rxq_ctrl =
737 container_of((*priv->rxqs)[idx],
738 struct mlx5_rxq_ctrl, rxq);
741 * To support metadata register copy on Tx loopback,
742 * this must be always enabled (metadata may arive
743 * from other port - not from local flows only.
745 if (priv->config.dv_flow_en &&
746 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
747 mlx5_flow_ext_mreg_supported(dev)) {
748 rxq_ctrl->rxq.mark = 1;
749 rxq_ctrl->flow_mark_n = 1;
751 rxq_ctrl->rxq.mark = 1;
752 rxq_ctrl->flow_mark_n++;
757 /* Increase the counter matching the flow. */
758 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
759 if ((tunnels_info[j].tunnel &
760 dev_handle->layers) ==
761 tunnels_info[j].tunnel) {
762 rxq_ctrl->flow_tunnels_n[j]++;
766 flow_rxq_tunnel_ptype_update(rxq_ctrl);
772 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
775 * Pointer to the Ethernet device structure.
777 * Pointer to flow structure.
780 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
782 struct mlx5_priv *priv = dev->data->dev_private;
784 struct mlx5_flow_handle *dev_handle;
786 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
787 handle_idx, dev_handle, next)
788 flow_drv_rxq_flags_set(dev, dev_handle);
792 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
793 * device flow if no other flow uses it with the same kind of request.
796 * Pointer to Ethernet device.
797 * @param[in] dev_handle
798 * Pointer to the device flow handle structure.
801 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
802 struct mlx5_flow_handle *dev_handle)
804 struct mlx5_priv *priv = dev->data->dev_private;
805 const int mark = dev_handle->mark;
806 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
807 struct mlx5_hrxq *hrxq;
810 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
812 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
813 dev_handle->rix_hrxq);
816 MLX5_ASSERT(dev->data->dev_started);
817 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
818 int idx = hrxq->ind_table->queues[i];
819 struct mlx5_rxq_ctrl *rxq_ctrl =
820 container_of((*priv->rxqs)[idx],
821 struct mlx5_rxq_ctrl, rxq);
823 if (priv->config.dv_flow_en &&
824 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
825 mlx5_flow_ext_mreg_supported(dev)) {
826 rxq_ctrl->rxq.mark = 1;
827 rxq_ctrl->flow_mark_n = 1;
829 rxq_ctrl->flow_mark_n--;
830 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
835 /* Decrease the counter matching the flow. */
836 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
837 if ((tunnels_info[j].tunnel &
838 dev_handle->layers) ==
839 tunnels_info[j].tunnel) {
840 rxq_ctrl->flow_tunnels_n[j]--;
844 flow_rxq_tunnel_ptype_update(rxq_ctrl);
850 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
851 * @p flow if no other flow uses it with the same kind of request.
854 * Pointer to Ethernet device.
856 * Pointer to the flow.
859 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
861 struct mlx5_priv *priv = dev->data->dev_private;
863 struct mlx5_flow_handle *dev_handle;
865 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
866 handle_idx, dev_handle, next)
867 flow_drv_rxq_flags_trim(dev, dev_handle);
871 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
874 * Pointer to Ethernet device.
877 flow_rxq_flags_clear(struct rte_eth_dev *dev)
879 struct mlx5_priv *priv = dev->data->dev_private;
882 for (i = 0; i != priv->rxqs_n; ++i) {
883 struct mlx5_rxq_ctrl *rxq_ctrl;
886 if (!(*priv->rxqs)[i])
888 rxq_ctrl = container_of((*priv->rxqs)[i],
889 struct mlx5_rxq_ctrl, rxq);
890 rxq_ctrl->flow_mark_n = 0;
891 rxq_ctrl->rxq.mark = 0;
892 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
893 rxq_ctrl->flow_tunnels_n[j] = 0;
894 rxq_ctrl->rxq.tunnel = 0;
899 * Set the Rx queue dynamic metadata (mask and offset) for a flow
902 * Pointer to the Ethernet device structure.
905 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
907 struct mlx5_priv *priv = dev->data->dev_private;
908 struct mlx5_rxq_data *data;
911 for (i = 0; i != priv->rxqs_n; ++i) {
912 if (!(*priv->rxqs)[i])
914 data = (*priv->rxqs)[i];
915 if (!rte_flow_dynf_metadata_avail()) {
917 data->flow_meta_mask = 0;
918 data->flow_meta_offset = -1;
921 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
922 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
928 * return a pointer to the desired action in the list of actions.
931 * The list of actions to search the action in.
933 * The action to find.
936 * Pointer to the action in the list, if found. NULL otherwise.
938 const struct rte_flow_action *
939 mlx5_flow_find_action(const struct rte_flow_action *actions,
940 enum rte_flow_action_type action)
944 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
945 if (actions->type == action)
951 * Validate the flag action.
953 * @param[in] action_flags
954 * Bit-fields that holds the actions detected until now.
956 * Attributes of flow that includes this action.
958 * Pointer to error structure.
961 * 0 on success, a negative errno value otherwise and rte_errno is set.
964 mlx5_flow_validate_action_flag(uint64_t action_flags,
965 const struct rte_flow_attr *attr,
966 struct rte_flow_error *error)
968 if (action_flags & MLX5_FLOW_ACTION_MARK)
969 return rte_flow_error_set(error, EINVAL,
970 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
971 "can't mark and flag in same flow");
972 if (action_flags & MLX5_FLOW_ACTION_FLAG)
973 return rte_flow_error_set(error, EINVAL,
974 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
976 " actions in same flow");
978 return rte_flow_error_set(error, ENOTSUP,
979 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
980 "flag action not supported for "
986 * Validate the mark action.
989 * Pointer to the queue action.
990 * @param[in] action_flags
991 * Bit-fields that holds the actions detected until now.
993 * Attributes of flow that includes this action.
995 * Pointer to error structure.
998 * 0 on success, a negative errno value otherwise and rte_errno is set.
1001 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1002 uint64_t action_flags,
1003 const struct rte_flow_attr *attr,
1004 struct rte_flow_error *error)
1006 const struct rte_flow_action_mark *mark = action->conf;
1009 return rte_flow_error_set(error, EINVAL,
1010 RTE_FLOW_ERROR_TYPE_ACTION,
1012 "configuration cannot be null");
1013 if (mark->id >= MLX5_FLOW_MARK_MAX)
1014 return rte_flow_error_set(error, EINVAL,
1015 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1017 "mark id must in 0 <= id < "
1018 RTE_STR(MLX5_FLOW_MARK_MAX));
1019 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1020 return rte_flow_error_set(error, EINVAL,
1021 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1022 "can't flag and mark in same flow");
1023 if (action_flags & MLX5_FLOW_ACTION_MARK)
1024 return rte_flow_error_set(error, EINVAL,
1025 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1026 "can't have 2 mark actions in same"
1029 return rte_flow_error_set(error, ENOTSUP,
1030 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1031 "mark action not supported for "
1037 * Validate the drop action.
1039 * @param[in] action_flags
1040 * Bit-fields that holds the actions detected until now.
1042 * Attributes of flow that includes this action.
1044 * Pointer to error structure.
1047 * 0 on success, a negative errno value otherwise and rte_errno is set.
1050 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1051 const struct rte_flow_attr *attr,
1052 struct rte_flow_error *error)
1055 return rte_flow_error_set(error, ENOTSUP,
1056 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1057 "drop action not supported for "
1063 * Validate the queue action.
1066 * Pointer to the queue action.
1067 * @param[in] action_flags
1068 * Bit-fields that holds the actions detected until now.
1070 * Pointer to the Ethernet device structure.
1072 * Attributes of flow that includes this action.
1074 * Pointer to error structure.
1077 * 0 on success, a negative errno value otherwise and rte_errno is set.
1080 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1081 uint64_t action_flags,
1082 struct rte_eth_dev *dev,
1083 const struct rte_flow_attr *attr,
1084 struct rte_flow_error *error)
1086 struct mlx5_priv *priv = dev->data->dev_private;
1087 const struct rte_flow_action_queue *queue = action->conf;
1089 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1090 return rte_flow_error_set(error, EINVAL,
1091 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1092 "can't have 2 fate actions in"
1095 return rte_flow_error_set(error, EINVAL,
1096 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1097 NULL, "No Rx queues configured");
1098 if (queue->index >= priv->rxqs_n)
1099 return rte_flow_error_set(error, EINVAL,
1100 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1102 "queue index out of range");
1103 if (!(*priv->rxqs)[queue->index])
1104 return rte_flow_error_set(error, EINVAL,
1105 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1107 "queue is not configured");
1109 return rte_flow_error_set(error, ENOTSUP,
1110 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1111 "queue action not supported for "
1117 * Validate the rss action.
1120 * Pointer to the queue action.
1121 * @param[in] action_flags
1122 * Bit-fields that holds the actions detected until now.
1124 * Pointer to the Ethernet device structure.
1126 * Attributes of flow that includes this action.
1127 * @param[in] item_flags
1128 * Items that were detected.
1130 * Pointer to error structure.
1133 * 0 on success, a negative errno value otherwise and rte_errno is set.
1136 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1137 uint64_t action_flags,
1138 struct rte_eth_dev *dev,
1139 const struct rte_flow_attr *attr,
1140 uint64_t item_flags,
1141 struct rte_flow_error *error)
1143 struct mlx5_priv *priv = dev->data->dev_private;
1144 const struct rte_flow_action_rss *rss = action->conf;
1145 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1148 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1149 return rte_flow_error_set(error, EINVAL,
1150 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1151 "can't have 2 fate actions"
1153 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1154 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1155 return rte_flow_error_set(error, ENOTSUP,
1156 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1158 "RSS hash function not supported");
1159 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1164 return rte_flow_error_set(error, ENOTSUP,
1165 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1167 "tunnel RSS is not supported");
1168 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1169 if (rss->key_len == 0 && rss->key != NULL)
1170 return rte_flow_error_set(error, ENOTSUP,
1171 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1173 "RSS hash key length 0");
1174 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1175 return rte_flow_error_set(error, ENOTSUP,
1176 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1178 "RSS hash key too small");
1179 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1180 return rte_flow_error_set(error, ENOTSUP,
1181 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1183 "RSS hash key too large");
1184 if (rss->queue_num > priv->config.ind_table_max_size)
1185 return rte_flow_error_set(error, ENOTSUP,
1186 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1188 "number of queues too large");
1189 if (rss->types & MLX5_RSS_HF_MASK)
1190 return rte_flow_error_set(error, ENOTSUP,
1191 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1193 "some RSS protocols are not"
1195 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1196 !(rss->types & ETH_RSS_IP))
1197 return rte_flow_error_set(error, EINVAL,
1198 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1199 "L3 partial RSS requested but L3 RSS"
1200 " type not specified");
1201 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1202 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1203 return rte_flow_error_set(error, EINVAL,
1204 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1205 "L4 partial RSS requested but L4 RSS"
1206 " type not specified");
1208 return rte_flow_error_set(error, EINVAL,
1209 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1210 NULL, "No Rx queues configured");
1211 if (!rss->queue_num)
1212 return rte_flow_error_set(error, EINVAL,
1213 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1214 NULL, "No queues configured");
1215 for (i = 0; i != rss->queue_num; ++i) {
1216 if (rss->queue[i] >= priv->rxqs_n)
1217 return rte_flow_error_set
1219 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1220 &rss->queue[i], "queue index out of range");
1221 if (!(*priv->rxqs)[rss->queue[i]])
1222 return rte_flow_error_set
1223 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1224 &rss->queue[i], "queue is not configured");
1227 return rte_flow_error_set(error, ENOTSUP,
1228 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1229 "rss action not supported for "
1231 if (rss->level > 1 && !tunnel)
1232 return rte_flow_error_set(error, EINVAL,
1233 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1234 "inner RSS is not supported for "
1235 "non-tunnel flows");
1236 if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
1237 !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
1238 return rte_flow_error_set(error, EINVAL,
1239 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1240 "RSS on eCPRI is not supported now");
1246 * Validate the default miss action.
1248 * @param[in] action_flags
1249 * Bit-fields that holds the actions detected until now.
1251 * Pointer to error structure.
1254 * 0 on success, a negative errno value otherwise and rte_errno is set.
1257 mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1258 const struct rte_flow_attr *attr,
1259 struct rte_flow_error *error)
1261 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1262 return rte_flow_error_set(error, EINVAL,
1263 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1264 "can't have 2 fate actions in"
1267 return rte_flow_error_set(error, ENOTSUP,
1268 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1269 "default miss action not supported "
1272 return rte_flow_error_set(error, ENOTSUP,
1273 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
1274 "only group 0 is supported");
1276 return rte_flow_error_set(error, ENOTSUP,
1277 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1278 NULL, "transfer is not supported");
1283 * Validate the count action.
1286 * Pointer to the Ethernet device structure.
1288 * Attributes of flow that includes this action.
1290 * Pointer to error structure.
1293 * 0 on success, a negative errno value otherwise and rte_errno is set.
1296 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1297 const struct rte_flow_attr *attr,
1298 struct rte_flow_error *error)
1301 return rte_flow_error_set(error, ENOTSUP,
1302 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1303 "count action not supported for "
1309 * Verify the @p attributes will be correctly understood by the NIC and store
1310 * them in the @p flow if everything is correct.
1313 * Pointer to the Ethernet device structure.
1314 * @param[in] attributes
1315 * Pointer to flow attributes
1317 * Pointer to error structure.
1320 * 0 on success, a negative errno value otherwise and rte_errno is set.
1323 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1324 const struct rte_flow_attr *attributes,
1325 struct rte_flow_error *error)
1327 struct mlx5_priv *priv = dev->data->dev_private;
1328 uint32_t priority_max = priv->config.flow_prio - 1;
1330 if (attributes->group)
1331 return rte_flow_error_set(error, ENOTSUP,
1332 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1333 NULL, "groups is not supported");
1334 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1335 attributes->priority >= priority_max)
1336 return rte_flow_error_set(error, ENOTSUP,
1337 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1338 NULL, "priority out of range");
1339 if (attributes->egress)
1340 return rte_flow_error_set(error, ENOTSUP,
1341 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1342 "egress is not supported");
1343 if (attributes->transfer && !priv->config.dv_esw_en)
1344 return rte_flow_error_set(error, ENOTSUP,
1345 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1346 NULL, "transfer is not supported");
1347 if (!attributes->ingress)
1348 return rte_flow_error_set(error, EINVAL,
1349 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1351 "ingress attribute is mandatory");
1356 * Validate ICMP6 item.
1359 * Item specification.
1360 * @param[in] item_flags
1361 * Bit-fields that holds the items detected until now.
1363 * Pointer to error structure.
1366 * 0 on success, a negative errno value otherwise and rte_errno is set.
1369 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1370 uint64_t item_flags,
1371 uint8_t target_protocol,
1372 struct rte_flow_error *error)
1374 const struct rte_flow_item_icmp6 *mask = item->mask;
1375 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1376 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1377 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1378 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1379 MLX5_FLOW_LAYER_OUTER_L4;
1382 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1383 return rte_flow_error_set(error, EINVAL,
1384 RTE_FLOW_ERROR_TYPE_ITEM, item,
1385 "protocol filtering not compatible"
1386 " with ICMP6 layer");
1387 if (!(item_flags & l3m))
1388 return rte_flow_error_set(error, EINVAL,
1389 RTE_FLOW_ERROR_TYPE_ITEM, item,
1390 "IPv6 is mandatory to filter on"
1392 if (item_flags & l4m)
1393 return rte_flow_error_set(error, EINVAL,
1394 RTE_FLOW_ERROR_TYPE_ITEM, item,
1395 "multiple L4 layers not supported");
1397 mask = &rte_flow_item_icmp6_mask;
1398 ret = mlx5_flow_item_acceptable
1399 (item, (const uint8_t *)mask,
1400 (const uint8_t *)&rte_flow_item_icmp6_mask,
1401 sizeof(struct rte_flow_item_icmp6), error);
1408 * Validate ICMP item.
1411 * Item specification.
1412 * @param[in] item_flags
1413 * Bit-fields that holds the items detected until now.
1415 * Pointer to error structure.
1418 * 0 on success, a negative errno value otherwise and rte_errno is set.
1421 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1422 uint64_t item_flags,
1423 uint8_t target_protocol,
1424 struct rte_flow_error *error)
1426 const struct rte_flow_item_icmp *mask = item->mask;
1427 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1428 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1429 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1430 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1431 MLX5_FLOW_LAYER_OUTER_L4;
1434 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1435 return rte_flow_error_set(error, EINVAL,
1436 RTE_FLOW_ERROR_TYPE_ITEM, item,
1437 "protocol filtering not compatible"
1438 " with ICMP layer");
1439 if (!(item_flags & l3m))
1440 return rte_flow_error_set(error, EINVAL,
1441 RTE_FLOW_ERROR_TYPE_ITEM, item,
1442 "IPv4 is mandatory to filter"
1444 if (item_flags & l4m)
1445 return rte_flow_error_set(error, EINVAL,
1446 RTE_FLOW_ERROR_TYPE_ITEM, item,
1447 "multiple L4 layers not supported");
1449 mask = &rte_flow_item_icmp_mask;
1450 ret = mlx5_flow_item_acceptable
1451 (item, (const uint8_t *)mask,
1452 (const uint8_t *)&rte_flow_item_icmp_mask,
1453 sizeof(struct rte_flow_item_icmp), error);
1460 * Validate Ethernet item.
1463 * Item specification.
1464 * @param[in] item_flags
1465 * Bit-fields that holds the items detected until now.
1467 * Pointer to error structure.
1470 * 0 on success, a negative errno value otherwise and rte_errno is set.
1473 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1474 uint64_t item_flags,
1475 struct rte_flow_error *error)
1477 const struct rte_flow_item_eth *mask = item->mask;
1478 const struct rte_flow_item_eth nic_mask = {
1479 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1480 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1481 .type = RTE_BE16(0xffff),
1484 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1485 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1486 MLX5_FLOW_LAYER_OUTER_L2;
1488 if (item_flags & ethm)
1489 return rte_flow_error_set(error, ENOTSUP,
1490 RTE_FLOW_ERROR_TYPE_ITEM, item,
1491 "multiple L2 layers not supported");
1492 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1493 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1494 return rte_flow_error_set(error, EINVAL,
1495 RTE_FLOW_ERROR_TYPE_ITEM, item,
1496 "L2 layer should not follow "
1498 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1499 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1500 return rte_flow_error_set(error, EINVAL,
1501 RTE_FLOW_ERROR_TYPE_ITEM, item,
1502 "L2 layer should not follow VLAN");
1504 mask = &rte_flow_item_eth_mask;
1505 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1506 (const uint8_t *)&nic_mask,
1507 sizeof(struct rte_flow_item_eth),
1513 * Validate VLAN item.
1516 * Item specification.
1517 * @param[in] item_flags
1518 * Bit-fields that holds the items detected until now.
1520 * Ethernet device flow is being created on.
1522 * Pointer to error structure.
1525 * 0 on success, a negative errno value otherwise and rte_errno is set.
1528 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1529 uint64_t item_flags,
1530 struct rte_eth_dev *dev,
1531 struct rte_flow_error *error)
1533 const struct rte_flow_item_vlan *spec = item->spec;
1534 const struct rte_flow_item_vlan *mask = item->mask;
1535 const struct rte_flow_item_vlan nic_mask = {
1536 .tci = RTE_BE16(UINT16_MAX),
1537 .inner_type = RTE_BE16(UINT16_MAX),
1539 uint16_t vlan_tag = 0;
1540 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1542 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1543 MLX5_FLOW_LAYER_INNER_L4) :
1544 (MLX5_FLOW_LAYER_OUTER_L3 |
1545 MLX5_FLOW_LAYER_OUTER_L4);
1546 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1547 MLX5_FLOW_LAYER_OUTER_VLAN;
1549 if (item_flags & vlanm)
1550 return rte_flow_error_set(error, EINVAL,
1551 RTE_FLOW_ERROR_TYPE_ITEM, item,
1552 "multiple VLAN layers not supported");
1553 else if ((item_flags & l34m) != 0)
1554 return rte_flow_error_set(error, EINVAL,
1555 RTE_FLOW_ERROR_TYPE_ITEM, item,
1556 "VLAN cannot follow L3/L4 layer");
1558 mask = &rte_flow_item_vlan_mask;
1559 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1560 (const uint8_t *)&nic_mask,
1561 sizeof(struct rte_flow_item_vlan),
1565 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1566 struct mlx5_priv *priv = dev->data->dev_private;
1568 if (priv->vmwa_context) {
1570 * Non-NULL context means we have a virtual machine
1571 * and SR-IOV enabled, we have to create VLAN interface
1572 * to make hypervisor to setup E-Switch vport
1573 * context correctly. We avoid creating the multiple
1574 * VLAN interfaces, so we cannot support VLAN tag mask.
1576 return rte_flow_error_set(error, EINVAL,
1577 RTE_FLOW_ERROR_TYPE_ITEM,
1579 "VLAN tag mask is not"
1580 " supported in virtual"
1585 vlan_tag = spec->tci;
1586 vlan_tag &= mask->tci;
1589 * From verbs perspective an empty VLAN is equivalent
1590 * to a packet without VLAN layer.
1593 return rte_flow_error_set(error, EINVAL,
1594 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1596 "VLAN cannot be empty");
1601 * Validate IPV4 item.
1604 * Item specification.
1605 * @param[in] item_flags
1606 * Bit-fields that holds the items detected until now.
1607 * @param[in] last_item
1608 * Previous validated item in the pattern items.
1609 * @param[in] ether_type
1610 * Type in the ethernet layer header (including dot1q).
1611 * @param[in] acc_mask
1612 * Acceptable mask, if NULL default internal default mask
1613 * will be used to check whether item fields are supported.
1615 * Pointer to error structure.
1618 * 0 on success, a negative errno value otherwise and rte_errno is set.
1621 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1622 uint64_t item_flags,
1624 uint16_t ether_type,
1625 const struct rte_flow_item_ipv4 *acc_mask,
1626 struct rte_flow_error *error)
1628 const struct rte_flow_item_ipv4 *mask = item->mask;
1629 const struct rte_flow_item_ipv4 *spec = item->spec;
1630 const struct rte_flow_item_ipv4 nic_mask = {
1632 .src_addr = RTE_BE32(0xffffffff),
1633 .dst_addr = RTE_BE32(0xffffffff),
1634 .type_of_service = 0xff,
1635 .next_proto_id = 0xff,
1638 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1639 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1640 MLX5_FLOW_LAYER_OUTER_L3;
1641 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1642 MLX5_FLOW_LAYER_OUTER_L4;
1644 uint8_t next_proto = 0xFF;
1645 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1646 MLX5_FLOW_LAYER_OUTER_VLAN |
1647 MLX5_FLOW_LAYER_INNER_VLAN);
1649 if ((last_item & l2_vlan) && ether_type &&
1650 ether_type != RTE_ETHER_TYPE_IPV4)
1651 return rte_flow_error_set(error, EINVAL,
1652 RTE_FLOW_ERROR_TYPE_ITEM, item,
1653 "IPv4 cannot follow L2/VLAN layer "
1654 "which ether type is not IPv4");
1655 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1657 next_proto = mask->hdr.next_proto_id &
1658 spec->hdr.next_proto_id;
1659 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1660 return rte_flow_error_set(error, EINVAL,
1661 RTE_FLOW_ERROR_TYPE_ITEM,
1666 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1667 return rte_flow_error_set(error, EINVAL,
1668 RTE_FLOW_ERROR_TYPE_ITEM, item,
1669 "wrong tunnel type - IPv6 specified "
1670 "but IPv4 item provided");
1671 if (item_flags & l3m)
1672 return rte_flow_error_set(error, ENOTSUP,
1673 RTE_FLOW_ERROR_TYPE_ITEM, item,
1674 "multiple L3 layers not supported");
1675 else if (item_flags & l4m)
1676 return rte_flow_error_set(error, EINVAL,
1677 RTE_FLOW_ERROR_TYPE_ITEM, item,
1678 "L3 cannot follow an L4 layer.");
1679 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1680 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1681 return rte_flow_error_set(error, EINVAL,
1682 RTE_FLOW_ERROR_TYPE_ITEM, item,
1683 "L3 cannot follow an NVGRE layer.");
1685 mask = &rte_flow_item_ipv4_mask;
1686 else if (mask->hdr.next_proto_id != 0 &&
1687 mask->hdr.next_proto_id != 0xff)
1688 return rte_flow_error_set(error, EINVAL,
1689 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1690 "partial mask is not supported"
1692 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1693 acc_mask ? (const uint8_t *)acc_mask
1694 : (const uint8_t *)&nic_mask,
1695 sizeof(struct rte_flow_item_ipv4),
1703 * Validate IPV6 item.
1706 * Item specification.
1707 * @param[in] item_flags
1708 * Bit-fields that holds the items detected until now.
1709 * @param[in] last_item
1710 * Previous validated item in the pattern items.
1711 * @param[in] ether_type
1712 * Type in the ethernet layer header (including dot1q).
1713 * @param[in] acc_mask
1714 * Acceptable mask, if NULL default internal default mask
1715 * will be used to check whether item fields are supported.
1717 * Pointer to error structure.
1720 * 0 on success, a negative errno value otherwise and rte_errno is set.
1723 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1724 uint64_t item_flags,
1726 uint16_t ether_type,
1727 const struct rte_flow_item_ipv6 *acc_mask,
1728 struct rte_flow_error *error)
1730 const struct rte_flow_item_ipv6 *mask = item->mask;
1731 const struct rte_flow_item_ipv6 *spec = item->spec;
1732 const struct rte_flow_item_ipv6 nic_mask = {
1735 "\xff\xff\xff\xff\xff\xff\xff\xff"
1736 "\xff\xff\xff\xff\xff\xff\xff\xff",
1738 "\xff\xff\xff\xff\xff\xff\xff\xff"
1739 "\xff\xff\xff\xff\xff\xff\xff\xff",
1740 .vtc_flow = RTE_BE32(0xffffffff),
1744 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1745 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1746 MLX5_FLOW_LAYER_OUTER_L3;
1747 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1748 MLX5_FLOW_LAYER_OUTER_L4;
1750 uint8_t next_proto = 0xFF;
1751 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1752 MLX5_FLOW_LAYER_OUTER_VLAN |
1753 MLX5_FLOW_LAYER_INNER_VLAN);
1755 if ((last_item & l2_vlan) && ether_type &&
1756 ether_type != RTE_ETHER_TYPE_IPV6)
1757 return rte_flow_error_set(error, EINVAL,
1758 RTE_FLOW_ERROR_TYPE_ITEM, item,
1759 "IPv6 cannot follow L2/VLAN layer "
1760 "which ether type is not IPv6");
1761 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
1763 next_proto = mask->hdr.proto & spec->hdr.proto;
1764 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1765 return rte_flow_error_set(error, EINVAL,
1766 RTE_FLOW_ERROR_TYPE_ITEM,
1771 if (item_flags & MLX5_FLOW_LAYER_IPIP)
1772 return rte_flow_error_set(error, EINVAL,
1773 RTE_FLOW_ERROR_TYPE_ITEM, item,
1774 "wrong tunnel type - IPv4 specified "
1775 "but IPv6 item provided");
1776 if (item_flags & l3m)
1777 return rte_flow_error_set(error, ENOTSUP,
1778 RTE_FLOW_ERROR_TYPE_ITEM, item,
1779 "multiple L3 layers not supported");
1780 else if (item_flags & l4m)
1781 return rte_flow_error_set(error, EINVAL,
1782 RTE_FLOW_ERROR_TYPE_ITEM, item,
1783 "L3 cannot follow an L4 layer.");
1784 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1785 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1786 return rte_flow_error_set(error, EINVAL,
1787 RTE_FLOW_ERROR_TYPE_ITEM, item,
1788 "L3 cannot follow an NVGRE layer.");
1790 mask = &rte_flow_item_ipv6_mask;
1791 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1792 acc_mask ? (const uint8_t *)acc_mask
1793 : (const uint8_t *)&nic_mask,
1794 sizeof(struct rte_flow_item_ipv6),
1802 * Validate UDP item.
1805 * Item specification.
1806 * @param[in] item_flags
1807 * Bit-fields that holds the items detected until now.
1808 * @param[in] target_protocol
1809 * The next protocol in the previous item.
1810 * @param[in] flow_mask
1811 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
1813 * Pointer to error structure.
1816 * 0 on success, a negative errno value otherwise and rte_errno is set.
1819 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1820 uint64_t item_flags,
1821 uint8_t target_protocol,
1822 struct rte_flow_error *error)
1824 const struct rte_flow_item_udp *mask = item->mask;
1825 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1826 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1827 MLX5_FLOW_LAYER_OUTER_L3;
1828 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1829 MLX5_FLOW_LAYER_OUTER_L4;
1832 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1833 return rte_flow_error_set(error, EINVAL,
1834 RTE_FLOW_ERROR_TYPE_ITEM, item,
1835 "protocol filtering not compatible"
1837 if (!(item_flags & l3m))
1838 return rte_flow_error_set(error, EINVAL,
1839 RTE_FLOW_ERROR_TYPE_ITEM, item,
1840 "L3 is mandatory to filter on L4");
1841 if (item_flags & l4m)
1842 return rte_flow_error_set(error, EINVAL,
1843 RTE_FLOW_ERROR_TYPE_ITEM, item,
1844 "multiple L4 layers not supported");
1846 mask = &rte_flow_item_udp_mask;
1847 ret = mlx5_flow_item_acceptable
1848 (item, (const uint8_t *)mask,
1849 (const uint8_t *)&rte_flow_item_udp_mask,
1850 sizeof(struct rte_flow_item_udp), error);
1857 * Validate TCP item.
1860 * Item specification.
1861 * @param[in] item_flags
1862 * Bit-fields that holds the items detected until now.
1863 * @param[in] target_protocol
1864 * The next protocol in the previous item.
1866 * Pointer to error structure.
1869 * 0 on success, a negative errno value otherwise and rte_errno is set.
1872 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1873 uint64_t item_flags,
1874 uint8_t target_protocol,
1875 const struct rte_flow_item_tcp *flow_mask,
1876 struct rte_flow_error *error)
1878 const struct rte_flow_item_tcp *mask = item->mask;
1879 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1880 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1881 MLX5_FLOW_LAYER_OUTER_L3;
1882 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1883 MLX5_FLOW_LAYER_OUTER_L4;
1886 MLX5_ASSERT(flow_mask);
1887 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1888 return rte_flow_error_set(error, EINVAL,
1889 RTE_FLOW_ERROR_TYPE_ITEM, item,
1890 "protocol filtering not compatible"
1892 if (!(item_flags & l3m))
1893 return rte_flow_error_set(error, EINVAL,
1894 RTE_FLOW_ERROR_TYPE_ITEM, item,
1895 "L3 is mandatory to filter on L4");
1896 if (item_flags & l4m)
1897 return rte_flow_error_set(error, EINVAL,
1898 RTE_FLOW_ERROR_TYPE_ITEM, item,
1899 "multiple L4 layers not supported");
1901 mask = &rte_flow_item_tcp_mask;
1902 ret = mlx5_flow_item_acceptable
1903 (item, (const uint8_t *)mask,
1904 (const uint8_t *)flow_mask,
1905 sizeof(struct rte_flow_item_tcp), error);
1912 * Validate VXLAN item.
1915 * Item specification.
1916 * @param[in] item_flags
1917 * Bit-fields that holds the items detected until now.
1918 * @param[in] target_protocol
1919 * The next protocol in the previous item.
1921 * Pointer to error structure.
1924 * 0 on success, a negative errno value otherwise and rte_errno is set.
1927 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1928 uint64_t item_flags,
1929 struct rte_flow_error *error)
1931 const struct rte_flow_item_vxlan *spec = item->spec;
1932 const struct rte_flow_item_vxlan *mask = item->mask;
1937 } id = { .vlan_id = 0, };
1940 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1941 return rte_flow_error_set(error, ENOTSUP,
1942 RTE_FLOW_ERROR_TYPE_ITEM, item,
1943 "multiple tunnel layers not"
1946 * Verify only UDPv4 is present as defined in
1947 * https://tools.ietf.org/html/rfc7348
1949 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1950 return rte_flow_error_set(error, EINVAL,
1951 RTE_FLOW_ERROR_TYPE_ITEM, item,
1952 "no outer UDP layer found");
1954 mask = &rte_flow_item_vxlan_mask;
1955 ret = mlx5_flow_item_acceptable
1956 (item, (const uint8_t *)mask,
1957 (const uint8_t *)&rte_flow_item_vxlan_mask,
1958 sizeof(struct rte_flow_item_vxlan),
1963 memcpy(&id.vni[1], spec->vni, 3);
1964 memcpy(&id.vni[1], mask->vni, 3);
1966 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1967 return rte_flow_error_set(error, ENOTSUP,
1968 RTE_FLOW_ERROR_TYPE_ITEM, item,
1969 "VXLAN tunnel must be fully defined");
1974 * Validate VXLAN_GPE item.
1977 * Item specification.
1978 * @param[in] item_flags
1979 * Bit-fields that holds the items detected until now.
1981 * Pointer to the private data structure.
1982 * @param[in] target_protocol
1983 * The next protocol in the previous item.
1985 * Pointer to error structure.
1988 * 0 on success, a negative errno value otherwise and rte_errno is set.
1991 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1992 uint64_t item_flags,
1993 struct rte_eth_dev *dev,
1994 struct rte_flow_error *error)
1996 struct mlx5_priv *priv = dev->data->dev_private;
1997 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1998 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
2003 } id = { .vlan_id = 0, };
2005 if (!priv->config.l3_vxlan_en)
2006 return rte_flow_error_set(error, ENOTSUP,
2007 RTE_FLOW_ERROR_TYPE_ITEM, item,
2008 "L3 VXLAN is not enabled by device"
2009 " parameter and/or not configured in"
2011 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2012 return rte_flow_error_set(error, ENOTSUP,
2013 RTE_FLOW_ERROR_TYPE_ITEM, item,
2014 "multiple tunnel layers not"
2017 * Verify only UDPv4 is present as defined in
2018 * https://tools.ietf.org/html/rfc7348
2020 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2021 return rte_flow_error_set(error, EINVAL,
2022 RTE_FLOW_ERROR_TYPE_ITEM, item,
2023 "no outer UDP layer found");
2025 mask = &rte_flow_item_vxlan_gpe_mask;
2026 ret = mlx5_flow_item_acceptable
2027 (item, (const uint8_t *)mask,
2028 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
2029 sizeof(struct rte_flow_item_vxlan_gpe),
2035 return rte_flow_error_set(error, ENOTSUP,
2036 RTE_FLOW_ERROR_TYPE_ITEM,
2038 "VxLAN-GPE protocol"
2040 memcpy(&id.vni[1], spec->vni, 3);
2041 memcpy(&id.vni[1], mask->vni, 3);
2043 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2044 return rte_flow_error_set(error, ENOTSUP,
2045 RTE_FLOW_ERROR_TYPE_ITEM, item,
2046 "VXLAN-GPE tunnel must be fully"
2051 * Validate GRE Key item.
2054 * Item specification.
2055 * @param[in] item_flags
2056 * Bit flags to mark detected items.
2057 * @param[in] gre_item
2058 * Pointer to gre_item
2060 * Pointer to error structure.
2063 * 0 on success, a negative errno value otherwise and rte_errno is set.
2066 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2067 uint64_t item_flags,
2068 const struct rte_flow_item *gre_item,
2069 struct rte_flow_error *error)
2071 const rte_be32_t *mask = item->mask;
2073 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2074 const struct rte_flow_item_gre *gre_spec;
2075 const struct rte_flow_item_gre *gre_mask;
2077 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2078 return rte_flow_error_set(error, ENOTSUP,
2079 RTE_FLOW_ERROR_TYPE_ITEM, item,
2080 "Multiple GRE key not support");
2081 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2082 return rte_flow_error_set(error, ENOTSUP,
2083 RTE_FLOW_ERROR_TYPE_ITEM, item,
2084 "No preceding GRE header");
2085 if (item_flags & MLX5_FLOW_LAYER_INNER)
2086 return rte_flow_error_set(error, ENOTSUP,
2087 RTE_FLOW_ERROR_TYPE_ITEM, item,
2088 "GRE key following a wrong item");
2089 gre_mask = gre_item->mask;
2091 gre_mask = &rte_flow_item_gre_mask;
2092 gre_spec = gre_item->spec;
2093 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2094 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2095 return rte_flow_error_set(error, EINVAL,
2096 RTE_FLOW_ERROR_TYPE_ITEM, item,
2097 "Key bit must be on");
2100 mask = &gre_key_default_mask;
2101 ret = mlx5_flow_item_acceptable
2102 (item, (const uint8_t *)mask,
2103 (const uint8_t *)&gre_key_default_mask,
2104 sizeof(rte_be32_t), error);
2109 * Validate GRE item.
2112 * Item specification.
2113 * @param[in] item_flags
2114 * Bit flags to mark detected items.
2115 * @param[in] target_protocol
2116 * The next protocol in the previous item.
2118 * Pointer to error structure.
2121 * 0 on success, a negative errno value otherwise and rte_errno is set.
2124 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2125 uint64_t item_flags,
2126 uint8_t target_protocol,
2127 struct rte_flow_error *error)
2129 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2130 const struct rte_flow_item_gre *mask = item->mask;
2132 const struct rte_flow_item_gre nic_mask = {
2133 .c_rsvd0_ver = RTE_BE16(0xB000),
2134 .protocol = RTE_BE16(UINT16_MAX),
2137 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2138 return rte_flow_error_set(error, EINVAL,
2139 RTE_FLOW_ERROR_TYPE_ITEM, item,
2140 "protocol filtering not compatible"
2141 " with this GRE layer");
2142 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2143 return rte_flow_error_set(error, ENOTSUP,
2144 RTE_FLOW_ERROR_TYPE_ITEM, item,
2145 "multiple tunnel layers not"
2147 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2148 return rte_flow_error_set(error, ENOTSUP,
2149 RTE_FLOW_ERROR_TYPE_ITEM, item,
2150 "L3 Layer is missing");
2152 mask = &rte_flow_item_gre_mask;
2153 ret = mlx5_flow_item_acceptable
2154 (item, (const uint8_t *)mask,
2155 (const uint8_t *)&nic_mask,
2156 sizeof(struct rte_flow_item_gre), error);
2159 #ifndef HAVE_MLX5DV_DR
2160 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2161 if (spec && (spec->protocol & mask->protocol))
2162 return rte_flow_error_set(error, ENOTSUP,
2163 RTE_FLOW_ERROR_TYPE_ITEM, item,
2164 "without MPLS support the"
2165 " specification cannot be used for"
2173 * Validate Geneve item.
2176 * Item specification.
2177 * @param[in] itemFlags
2178 * Bit-fields that holds the items detected until now.
2180 * Pointer to the private data structure.
2182 * Pointer to error structure.
2185 * 0 on success, a negative errno value otherwise and rte_errno is set.
2189 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2190 uint64_t item_flags,
2191 struct rte_eth_dev *dev,
2192 struct rte_flow_error *error)
2194 struct mlx5_priv *priv = dev->data->dev_private;
2195 const struct rte_flow_item_geneve *spec = item->spec;
2196 const struct rte_flow_item_geneve *mask = item->mask;
2199 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2200 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2201 const struct rte_flow_item_geneve nic_mask = {
2202 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2203 .vni = "\xff\xff\xff",
2204 .protocol = RTE_BE16(UINT16_MAX),
2207 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2208 return rte_flow_error_set(error, ENOTSUP,
2209 RTE_FLOW_ERROR_TYPE_ITEM, item,
2210 "L3 Geneve is not enabled by device"
2211 " parameter and/or not configured in"
2213 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2214 return rte_flow_error_set(error, ENOTSUP,
2215 RTE_FLOW_ERROR_TYPE_ITEM, item,
2216 "multiple tunnel layers not"
2219 * Verify only UDPv4 is present as defined in
2220 * https://tools.ietf.org/html/rfc7348
2222 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2223 return rte_flow_error_set(error, EINVAL,
2224 RTE_FLOW_ERROR_TYPE_ITEM, item,
2225 "no outer UDP layer found");
2227 mask = &rte_flow_item_geneve_mask;
2228 ret = mlx5_flow_item_acceptable
2229 (item, (const uint8_t *)mask,
2230 (const uint8_t *)&nic_mask,
2231 sizeof(struct rte_flow_item_geneve), error);
2235 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2236 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2237 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2238 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2239 return rte_flow_error_set(error, ENOTSUP,
2240 RTE_FLOW_ERROR_TYPE_ITEM,
2242 "Geneve protocol unsupported"
2243 " fields are being used");
2244 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2245 return rte_flow_error_set
2247 RTE_FLOW_ERROR_TYPE_ITEM,
2249 "Unsupported Geneve options length");
2251 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2252 return rte_flow_error_set
2254 RTE_FLOW_ERROR_TYPE_ITEM, item,
2255 "Geneve tunnel must be fully defined");
2260 * Validate MPLS item.
2263 * Pointer to the rte_eth_dev structure.
2265 * Item specification.
2266 * @param[in] item_flags
2267 * Bit-fields that holds the items detected until now.
2268 * @param[in] prev_layer
2269 * The protocol layer indicated in previous item.
2271 * Pointer to error structure.
2274 * 0 on success, a negative errno value otherwise and rte_errno is set.
2277 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2278 const struct rte_flow_item *item __rte_unused,
2279 uint64_t item_flags __rte_unused,
2280 uint64_t prev_layer __rte_unused,
2281 struct rte_flow_error *error)
2283 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2284 const struct rte_flow_item_mpls *mask = item->mask;
2285 struct mlx5_priv *priv = dev->data->dev_private;
2288 if (!priv->config.mpls_en)
2289 return rte_flow_error_set(error, ENOTSUP,
2290 RTE_FLOW_ERROR_TYPE_ITEM, item,
2291 "MPLS not supported or"
2292 " disabled in firmware"
2294 /* MPLS over IP, UDP, GRE is allowed */
2295 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2296 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2297 MLX5_FLOW_LAYER_GRE)))
2298 return rte_flow_error_set(error, EINVAL,
2299 RTE_FLOW_ERROR_TYPE_ITEM, item,
2300 "protocol filtering not compatible"
2301 " with MPLS layer");
2302 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2303 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2304 !(item_flags & MLX5_FLOW_LAYER_GRE))
2305 return rte_flow_error_set(error, ENOTSUP,
2306 RTE_FLOW_ERROR_TYPE_ITEM, item,
2307 "multiple tunnel layers not"
2310 mask = &rte_flow_item_mpls_mask;
2311 ret = mlx5_flow_item_acceptable
2312 (item, (const uint8_t *)mask,
2313 (const uint8_t *)&rte_flow_item_mpls_mask,
2314 sizeof(struct rte_flow_item_mpls), error);
2319 return rte_flow_error_set(error, ENOTSUP,
2320 RTE_FLOW_ERROR_TYPE_ITEM, item,
2321 "MPLS is not supported by Verbs, please"
2327 * Validate NVGRE item.
2330 * Item specification.
2331 * @param[in] item_flags
2332 * Bit flags to mark detected items.
2333 * @param[in] target_protocol
2334 * The next protocol in the previous item.
2336 * Pointer to error structure.
2339 * 0 on success, a negative errno value otherwise and rte_errno is set.
2342 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2343 uint64_t item_flags,
2344 uint8_t target_protocol,
2345 struct rte_flow_error *error)
2347 const struct rte_flow_item_nvgre *mask = item->mask;
2350 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2351 return rte_flow_error_set(error, EINVAL,
2352 RTE_FLOW_ERROR_TYPE_ITEM, item,
2353 "protocol filtering not compatible"
2354 " with this GRE layer");
2355 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2356 return rte_flow_error_set(error, ENOTSUP,
2357 RTE_FLOW_ERROR_TYPE_ITEM, item,
2358 "multiple tunnel layers not"
2360 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2361 return rte_flow_error_set(error, ENOTSUP,
2362 RTE_FLOW_ERROR_TYPE_ITEM, item,
2363 "L3 Layer is missing");
2365 mask = &rte_flow_item_nvgre_mask;
2366 ret = mlx5_flow_item_acceptable
2367 (item, (const uint8_t *)mask,
2368 (const uint8_t *)&rte_flow_item_nvgre_mask,
2369 sizeof(struct rte_flow_item_nvgre), error);
2376 * Validate eCPRI item.
2379 * Item specification.
2380 * @param[in] item_flags
2381 * Bit-fields that holds the items detected until now.
2382 * @param[in] last_item
2383 * Previous validated item in the pattern items.
2384 * @param[in] ether_type
2385 * Type in the ethernet layer header (including dot1q).
2386 * @param[in] acc_mask
2387 * Acceptable mask, if NULL default internal default mask
2388 * will be used to check whether item fields are supported.
2390 * Pointer to error structure.
2393 * 0 on success, a negative errno value otherwise and rte_errno is set.
2396 mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
2397 uint64_t item_flags,
2399 uint16_t ether_type,
2400 const struct rte_flow_item_ecpri *acc_mask,
2401 struct rte_flow_error *error)
2403 const struct rte_flow_item_ecpri *mask = item->mask;
2404 const struct rte_flow_item_ecpri nic_mask = {
2408 RTE_BE32(((const struct rte_ecpri_common_hdr) {
2412 .dummy[0] = 0xFFFFFFFF,
2415 const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
2416 MLX5_FLOW_LAYER_OUTER_VLAN);
2417 struct rte_flow_item_ecpri mask_lo;
2419 if ((last_item & outer_l2_vlan) && ether_type &&
2420 ether_type != RTE_ETHER_TYPE_ECPRI)
2421 return rte_flow_error_set(error, EINVAL,
2422 RTE_FLOW_ERROR_TYPE_ITEM, item,
2423 "eCPRI cannot follow L2/VLAN layer "
2424 "which ether type is not 0xAEFE.");
2425 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2426 return rte_flow_error_set(error, EINVAL,
2427 RTE_FLOW_ERROR_TYPE_ITEM, item,
2428 "eCPRI with tunnel is not supported "
2430 if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
2431 return rte_flow_error_set(error, ENOTSUP,
2432 RTE_FLOW_ERROR_TYPE_ITEM, item,
2433 "multiple L3 layers not supported");
2434 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
2435 return rte_flow_error_set(error, EINVAL,
2436 RTE_FLOW_ERROR_TYPE_ITEM, item,
2437 "eCPRI cannot follow a TCP layer.");
2438 /* In specification, eCPRI could be over UDP layer. */
2439 else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
2440 return rte_flow_error_set(error, EINVAL,
2441 RTE_FLOW_ERROR_TYPE_ITEM, item,
2442 "eCPRI over UDP layer is not yet "
2443 "supported right now.");
2444 /* Mask for type field in common header could be zero. */
2446 mask = &rte_flow_item_ecpri_mask;
2447 mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
2448 /* Input mask is in big-endian format. */
2449 if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
2450 return rte_flow_error_set(error, EINVAL,
2451 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2452 "partial mask is not supported "
2454 else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
2455 return rte_flow_error_set(error, EINVAL,
2456 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2457 "message header mask must be after "
2459 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2460 acc_mask ? (const uint8_t *)acc_mask
2461 : (const uint8_t *)&nic_mask,
2462 sizeof(struct rte_flow_item_ecpri),
2466 /* Allocate unique ID for the split Q/RSS subflows. */
2468 flow_qrss_get_id(struct rte_eth_dev *dev)
2470 struct mlx5_priv *priv = dev->data->dev_private;
2471 uint32_t qrss_id, ret;
2473 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2476 MLX5_ASSERT(qrss_id);
2480 /* Free unique ID for the split Q/RSS subflows. */
2482 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2484 struct mlx5_priv *priv = dev->data->dev_private;
2487 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2491 * Release resource related QUEUE/RSS action split.
2494 * Pointer to Ethernet device.
2496 * Flow to release id's from.
2499 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2500 struct rte_flow *flow)
2502 struct mlx5_priv *priv = dev->data->dev_private;
2503 uint32_t handle_idx;
2504 struct mlx5_flow_handle *dev_handle;
2506 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
2507 handle_idx, dev_handle, next)
2508 if (dev_handle->split_flow_id)
2509 flow_qrss_free_id(dev, dev_handle->split_flow_id);
2513 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2514 const struct rte_flow_attr *attr __rte_unused,
2515 const struct rte_flow_item items[] __rte_unused,
2516 const struct rte_flow_action actions[] __rte_unused,
2517 bool external __rte_unused,
2518 int hairpin __rte_unused,
2519 struct rte_flow_error *error)
2521 return rte_flow_error_set(error, ENOTSUP,
2522 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2525 static struct mlx5_flow *
2526 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
2527 const struct rte_flow_attr *attr __rte_unused,
2528 const struct rte_flow_item items[] __rte_unused,
2529 const struct rte_flow_action actions[] __rte_unused,
2530 struct rte_flow_error *error)
2532 rte_flow_error_set(error, ENOTSUP,
2533 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2538 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2539 struct mlx5_flow *dev_flow __rte_unused,
2540 const struct rte_flow_attr *attr __rte_unused,
2541 const struct rte_flow_item items[] __rte_unused,
2542 const struct rte_flow_action actions[] __rte_unused,
2543 struct rte_flow_error *error)
2545 return rte_flow_error_set(error, ENOTSUP,
2546 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2550 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2551 struct rte_flow *flow __rte_unused,
2552 struct rte_flow_error *error)
2554 return rte_flow_error_set(error, ENOTSUP,
2555 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2559 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2560 struct rte_flow *flow __rte_unused)
2565 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2566 struct rte_flow *flow __rte_unused)
2571 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2572 struct rte_flow *flow __rte_unused,
2573 const struct rte_flow_action *actions __rte_unused,
2574 void *data __rte_unused,
2575 struct rte_flow_error *error)
2577 return rte_flow_error_set(error, ENOTSUP,
2578 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2581 /* Void driver to protect from null pointer reference. */
2582 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2583 .validate = flow_null_validate,
2584 .prepare = flow_null_prepare,
2585 .translate = flow_null_translate,
2586 .apply = flow_null_apply,
2587 .remove = flow_null_remove,
2588 .destroy = flow_null_destroy,
2589 .query = flow_null_query,
2593 * Select flow driver type according to flow attributes and device
2597 * Pointer to the dev structure.
2599 * Pointer to the flow attributes.
2602 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2604 static enum mlx5_flow_drv_type
2605 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2607 struct mlx5_priv *priv = dev->data->dev_private;
2608 /* The OS can determine first a specific flow type (DV, VERBS) */
2609 enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
2611 if (type != MLX5_FLOW_TYPE_MAX)
2613 /* If no OS specific type - continue with DV/VERBS selection */
2614 if (attr->transfer && priv->config.dv_esw_en)
2615 type = MLX5_FLOW_TYPE_DV;
2616 if (!attr->transfer)
2617 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2618 MLX5_FLOW_TYPE_VERBS;
2622 #define flow_get_drv_ops(type) flow_drv_ops[type]
2625 * Flow driver validation API. This abstracts calling driver specific functions.
2626 * The type of flow driver is determined according to flow attributes.
2629 * Pointer to the dev structure.
2631 * Pointer to the flow attributes.
2633 * Pointer to the list of items.
2634 * @param[in] actions
2635 * Pointer to the list of actions.
2636 * @param[in] external
2637 * This flow rule is created by request external to PMD.
2638 * @param[in] hairpin
2639 * Number of hairpin TX actions, 0 means classic flow.
2641 * Pointer to the error structure.
2644 * 0 on success, a negative errno value otherwise and rte_errno is set.
2647 flow_drv_validate(struct rte_eth_dev *dev,
2648 const struct rte_flow_attr *attr,
2649 const struct rte_flow_item items[],
2650 const struct rte_flow_action actions[],
2651 bool external, int hairpin, struct rte_flow_error *error)
2653 const struct mlx5_flow_driver_ops *fops;
2654 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2656 fops = flow_get_drv_ops(type);
2657 return fops->validate(dev, attr, items, actions, external,
2662 * Flow driver preparation API. This abstracts calling driver specific
2663 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2664 * calculates the size of memory required for device flow, allocates the memory,
2665 * initializes the device flow and returns the pointer.
2668 * This function initializes device flow structure such as dv or verbs in
2669 * struct mlx5_flow. However, it is caller's responsibility to initialize the
2670 * rest. For example, adding returning device flow to flow->dev_flow list and
2671 * setting backward reference to the flow should be done out of this function.
2672 * layers field is not filled either.
2675 * Pointer to the dev structure.
2677 * Pointer to the flow attributes.
2679 * Pointer to the list of items.
2680 * @param[in] actions
2681 * Pointer to the list of actions.
2682 * @param[in] flow_idx
2683 * This memory pool index to the flow.
2685 * Pointer to the error structure.
2688 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
2690 static inline struct mlx5_flow *
2691 flow_drv_prepare(struct rte_eth_dev *dev,
2692 const struct rte_flow *flow,
2693 const struct rte_flow_attr *attr,
2694 const struct rte_flow_item items[],
2695 const struct rte_flow_action actions[],
2697 struct rte_flow_error *error)
2699 const struct mlx5_flow_driver_ops *fops;
2700 enum mlx5_flow_drv_type type = flow->drv_type;
2701 struct mlx5_flow *mlx5_flow = NULL;
2703 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2704 fops = flow_get_drv_ops(type);
2705 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
2707 mlx5_flow->flow_idx = flow_idx;
2712 * Flow driver translation API. This abstracts calling driver specific
2713 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2714 * translates a generic flow into a driver flow. flow_drv_prepare() must
2718 * dev_flow->layers could be filled as a result of parsing during translation
2719 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
2720 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
2721 * flow->actions could be overwritten even though all the expanded dev_flows
2722 * have the same actions.
2725 * Pointer to the rte dev structure.
2726 * @param[in, out] dev_flow
2727 * Pointer to the mlx5 flow.
2729 * Pointer to the flow attributes.
2731 * Pointer to the list of items.
2732 * @param[in] actions
2733 * Pointer to the list of actions.
2735 * Pointer to the error structure.
2738 * 0 on success, a negative errno value otherwise and rte_errno is set.
2741 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
2742 const struct rte_flow_attr *attr,
2743 const struct rte_flow_item items[],
2744 const struct rte_flow_action actions[],
2745 struct rte_flow_error *error)
2747 const struct mlx5_flow_driver_ops *fops;
2748 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
2750 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2751 fops = flow_get_drv_ops(type);
2752 return fops->translate(dev, dev_flow, attr, items, actions, error);
2756 * Flow driver apply API. This abstracts calling driver specific functions.
2757 * Parent flow (rte_flow) should have driver type (drv_type). It applies
2758 * translated driver flows on to device. flow_drv_translate() must precede.
2761 * Pointer to Ethernet device structure.
2762 * @param[in, out] flow
2763 * Pointer to flow structure.
2765 * Pointer to error structure.
2768 * 0 on success, a negative errno value otherwise and rte_errno is set.
2771 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
2772 struct rte_flow_error *error)
2774 const struct mlx5_flow_driver_ops *fops;
2775 enum mlx5_flow_drv_type type = flow->drv_type;
2777 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2778 fops = flow_get_drv_ops(type);
2779 return fops->apply(dev, flow, error);
2783 * Flow driver remove API. This abstracts calling driver specific functions.
2784 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2785 * on device. All the resources of the flow should be freed by calling
2786 * flow_drv_destroy().
2789 * Pointer to Ethernet device.
2790 * @param[in, out] flow
2791 * Pointer to flow structure.
2794 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
2796 const struct mlx5_flow_driver_ops *fops;
2797 enum mlx5_flow_drv_type type = flow->drv_type;
2799 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2800 fops = flow_get_drv_ops(type);
2801 fops->remove(dev, flow);
2805 * Flow driver destroy API. This abstracts calling driver specific functions.
2806 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2807 * on device and releases resources of the flow.
2810 * Pointer to Ethernet device.
2811 * @param[in, out] flow
2812 * Pointer to flow structure.
2815 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
2817 const struct mlx5_flow_driver_ops *fops;
2818 enum mlx5_flow_drv_type type = flow->drv_type;
2820 flow_mreg_split_qrss_release(dev, flow);
2821 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2822 fops = flow_get_drv_ops(type);
2823 fops->destroy(dev, flow);
2827 * Get RSS action from the action list.
2829 * @param[in] actions
2830 * Pointer to the list of actions.
2833 * Pointer to the RSS action if exist, else return NULL.
2835 static const struct rte_flow_action_rss*
2836 flow_get_rss_action(const struct rte_flow_action actions[])
2838 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2839 switch (actions->type) {
2840 case RTE_FLOW_ACTION_TYPE_RSS:
2841 return (const struct rte_flow_action_rss *)
2851 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
2853 const struct rte_flow_item *item;
2854 unsigned int has_vlan = 0;
2856 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2857 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2863 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
2864 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
2865 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
2866 MLX5_EXPANSION_ROOT_OUTER;
2870 * Get layer flags from the prefix flow.
2872 * Some flows may be split to several subflows, the prefix subflow gets the
2873 * match items and the suffix sub flow gets the actions.
2874 * Some actions need the user defined match item flags to get the detail for
2876 * This function helps the suffix flow to get the item layer flags from prefix
2879 * @param[in] dev_flow
2880 * Pointer the created preifx subflow.
2883 * The layers get from prefix subflow.
2885 static inline uint64_t
2886 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
2888 uint64_t layers = 0;
2891 * Layers bits could be localization, but usually the compiler will
2892 * help to do the optimization work for source code.
2893 * If no decap actions, use the layers directly.
2895 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
2896 return dev_flow->handle->layers;
2897 /* Convert L3 layers with decap action. */
2898 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
2899 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2900 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
2901 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2902 /* Convert L4 layers with decap action. */
2903 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
2904 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
2905 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
2906 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
2911 * Get metadata split action information.
2913 * @param[in] actions
2914 * Pointer to the list of actions.
2916 * Pointer to the return pointer.
2917 * @param[out] qrss_type
2918 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
2919 * if no QUEUE/RSS is found.
2920 * @param[out] encap_idx
2921 * Pointer to the index of the encap action if exists, otherwise the last
2925 * Total number of actions.
2928 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
2929 const struct rte_flow_action **qrss,
2932 const struct rte_flow_action_raw_encap *raw_encap;
2934 int raw_decap_idx = -1;
2937 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2938 switch (actions->type) {
2939 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2940 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2941 *encap_idx = actions_n;
2943 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
2944 raw_decap_idx = actions_n;
2946 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2947 raw_encap = actions->conf;
2948 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
2949 *encap_idx = raw_decap_idx != -1 ?
2950 raw_decap_idx : actions_n;
2952 case RTE_FLOW_ACTION_TYPE_QUEUE:
2953 case RTE_FLOW_ACTION_TYPE_RSS:
2961 if (*encap_idx == -1)
2962 *encap_idx = actions_n;
2963 /* Count RTE_FLOW_ACTION_TYPE_END. */
2964 return actions_n + 1;
2968 * Check meter action from the action list.
2970 * @param[in] actions
2971 * Pointer to the list of actions.
2973 * Pointer to the meter exist flag.
2976 * Total number of actions.
2979 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
2985 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2986 switch (actions->type) {
2987 case RTE_FLOW_ACTION_TYPE_METER:
2995 /* Count RTE_FLOW_ACTION_TYPE_END. */
2996 return actions_n + 1;
3000 * Check if the flow should be splited due to hairpin.
3001 * The reason for the split is that in current HW we can't
3002 * support encap on Rx, so if a flow have encap we move it
3006 * Pointer to Ethernet device.
3008 * Flow rule attributes.
3009 * @param[in] actions
3010 * Associated actions (list terminated by the END action).
3013 * > 0 the number of actions and the flow should be split,
3014 * 0 when no split required.
3017 flow_check_hairpin_split(struct rte_eth_dev *dev,
3018 const struct rte_flow_attr *attr,
3019 const struct rte_flow_action actions[])
3021 int queue_action = 0;
3024 const struct rte_flow_action_queue *queue;
3025 const struct rte_flow_action_rss *rss;
3026 const struct rte_flow_action_raw_encap *raw_encap;
3030 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3031 switch (actions->type) {
3032 case RTE_FLOW_ACTION_TYPE_QUEUE:
3033 queue = actions->conf;
3036 if (mlx5_rxq_get_type(dev, queue->index) !=
3037 MLX5_RXQ_TYPE_HAIRPIN)
3042 case RTE_FLOW_ACTION_TYPE_RSS:
3043 rss = actions->conf;
3044 if (rss == NULL || rss->queue_num == 0)
3046 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
3047 MLX5_RXQ_TYPE_HAIRPIN)
3052 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3053 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3057 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3058 raw_encap = actions->conf;
3059 if (raw_encap->size >
3060 (sizeof(struct rte_flow_item_eth) +
3061 sizeof(struct rte_flow_item_ipv4)))
3070 if (encap == 1 && queue_action)
3075 /* Declare flow create/destroy prototype in advance. */
3077 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
3078 const struct rte_flow_attr *attr,
3079 const struct rte_flow_item items[],
3080 const struct rte_flow_action actions[],
3081 bool external, struct rte_flow_error *error);
3084 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
3088 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3090 * As mark_id is unique, if there's already a registered flow for the mark_id,
3091 * return by increasing the reference counter of the resource. Otherwise, create
3092 * the resource (mcp_res) and flow.
3095 * - If ingress port is ANY and reg_c[1] is mark_id,
3096 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3098 * For default flow (zero mark_id), flow is like,
3099 * - If ingress port is ANY,
3100 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
3103 * Pointer to Ethernet device.
3105 * ID of MARK action, zero means default flow for META.
3107 * Perform verbose error reporting if not NULL.
3110 * Associated resource on success, NULL otherwise and rte_errno is set.
3112 static struct mlx5_flow_mreg_copy_resource *
3113 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
3114 struct rte_flow_error *error)
3116 struct mlx5_priv *priv = dev->data->dev_private;
3117 struct rte_flow_attr attr = {
3118 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3121 struct mlx5_rte_flow_item_tag tag_spec = {
3124 struct rte_flow_item items[] = {
3125 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
3127 struct rte_flow_action_mark ftag = {
3130 struct mlx5_flow_action_copy_mreg cp_mreg = {
3134 struct rte_flow_action_jump jump = {
3135 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3137 struct rte_flow_action actions[] = {
3138 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
3140 struct mlx5_flow_mreg_copy_resource *mcp_res;
3144 /* Fill the register fileds in the flow. */
3145 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3149 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3153 /* Check if already registered. */
3154 MLX5_ASSERT(priv->mreg_cp_tbl);
3155 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
3157 /* For non-default rule. */
3158 if (mark_id != MLX5_DEFAULT_COPY_ID)
3160 MLX5_ASSERT(mark_id != MLX5_DEFAULT_COPY_ID ||
3161 mcp_res->refcnt == 1);
3164 /* Provide the full width of FLAG specific value. */
3165 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3166 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3167 /* Build a new flow. */
3168 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3169 items[0] = (struct rte_flow_item){
3170 .type = (enum rte_flow_item_type)
3171 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3174 items[1] = (struct rte_flow_item){
3175 .type = RTE_FLOW_ITEM_TYPE_END,
3177 actions[0] = (struct rte_flow_action){
3178 .type = (enum rte_flow_action_type)
3179 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3182 actions[1] = (struct rte_flow_action){
3183 .type = (enum rte_flow_action_type)
3184 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3187 actions[2] = (struct rte_flow_action){
3188 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3191 actions[3] = (struct rte_flow_action){
3192 .type = RTE_FLOW_ACTION_TYPE_END,
3195 /* Default rule, wildcard match. */
3196 attr.priority = MLX5_FLOW_PRIO_RSVD;
3197 items[0] = (struct rte_flow_item){
3198 .type = RTE_FLOW_ITEM_TYPE_END,
3200 actions[0] = (struct rte_flow_action){
3201 .type = (enum rte_flow_action_type)
3202 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3205 actions[1] = (struct rte_flow_action){
3206 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3209 actions[2] = (struct rte_flow_action){
3210 .type = RTE_FLOW_ACTION_TYPE_END,
3213 /* Build a new entry. */
3214 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3221 * The copy Flows are not included in any list. There
3222 * ones are referenced from other Flows and can not
3223 * be applied, removed, deleted in ardbitrary order
3224 * by list traversing.
3226 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3227 actions, false, error);
3228 if (!mcp_res->rix_flow)
3231 mcp_res->hlist_ent.key = mark_id;
3232 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3233 &mcp_res->hlist_ent);
3239 if (mcp_res->rix_flow)
3240 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3241 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3246 * Release flow in RX_CP_TBL.
3249 * Pointer to Ethernet device.
3251 * Parent flow for wich copying is provided.
3254 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3255 struct rte_flow *flow)
3257 struct mlx5_flow_mreg_copy_resource *mcp_res;
3258 struct mlx5_priv *priv = dev->data->dev_private;
3260 if (!flow->rix_mreg_copy)
3262 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3263 flow->rix_mreg_copy);
3264 if (!mcp_res || !priv->mreg_cp_tbl)
3266 if (flow->copy_applied) {
3267 MLX5_ASSERT(mcp_res->appcnt);
3268 flow->copy_applied = 0;
3270 if (!mcp_res->appcnt) {
3271 struct rte_flow *mcp_flow = mlx5_ipool_get
3272 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3276 flow_drv_remove(dev, mcp_flow);
3280 * We do not check availability of metadata registers here,
3281 * because copy resources are not allocated in this case.
3283 if (--mcp_res->refcnt)
3285 MLX5_ASSERT(mcp_res->rix_flow);
3286 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3287 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3288 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3289 flow->rix_mreg_copy = 0;
3293 * Start flow in RX_CP_TBL.
3296 * Pointer to Ethernet device.
3298 * Parent flow for wich copying is provided.
3301 * 0 on success, a negative errno value otherwise and rte_errno is set.
3304 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3305 struct rte_flow *flow)
3307 struct mlx5_flow_mreg_copy_resource *mcp_res;
3308 struct mlx5_priv *priv = dev->data->dev_private;
3311 if (!flow->rix_mreg_copy || flow->copy_applied)
3313 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3314 flow->rix_mreg_copy);
3317 if (!mcp_res->appcnt) {
3318 struct rte_flow *mcp_flow = mlx5_ipool_get
3319 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3323 ret = flow_drv_apply(dev, mcp_flow, NULL);
3329 flow->copy_applied = 1;
3334 * Stop flow in RX_CP_TBL.
3337 * Pointer to Ethernet device.
3339 * Parent flow for wich copying is provided.
3342 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3343 struct rte_flow *flow)
3345 struct mlx5_flow_mreg_copy_resource *mcp_res;
3346 struct mlx5_priv *priv = dev->data->dev_private;
3348 if (!flow->rix_mreg_copy || !flow->copy_applied)
3350 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3351 flow->rix_mreg_copy);
3354 MLX5_ASSERT(mcp_res->appcnt);
3356 flow->copy_applied = 0;
3357 if (!mcp_res->appcnt) {
3358 struct rte_flow *mcp_flow = mlx5_ipool_get
3359 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3363 flow_drv_remove(dev, mcp_flow);
3368 * Remove the default copy action from RX_CP_TBL.
3371 * Pointer to Ethernet device.
3374 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3376 struct mlx5_flow_mreg_copy_resource *mcp_res;
3377 struct mlx5_priv *priv = dev->data->dev_private;
3379 /* Check if default flow is registered. */
3380 if (!priv->mreg_cp_tbl)
3382 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3383 MLX5_DEFAULT_COPY_ID);
3386 MLX5_ASSERT(mcp_res->rix_flow);
3387 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3388 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3389 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3393 * Add the default copy action in in RX_CP_TBL.
3396 * Pointer to Ethernet device.
3398 * Perform verbose error reporting if not NULL.
3401 * 0 for success, negative value otherwise and rte_errno is set.
3404 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3405 struct rte_flow_error *error)
3407 struct mlx5_priv *priv = dev->data->dev_private;
3408 struct mlx5_flow_mreg_copy_resource *mcp_res;
3410 /* Check whether extensive metadata feature is engaged. */
3411 if (!priv->config.dv_flow_en ||
3412 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3413 !mlx5_flow_ext_mreg_supported(dev) ||
3414 !priv->sh->dv_regc0_mask)
3416 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3423 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3425 * All the flow having Q/RSS action should be split by
3426 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3427 * performs the following,
3428 * - CQE->flow_tag := reg_c[1] (MARK)
3429 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3430 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3431 * but there should be a flow per each MARK ID set by MARK action.
3433 * For the aforementioned reason, if there's a MARK action in flow's action
3434 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3435 * the MARK ID to CQE's flow_tag like,
3436 * - If reg_c[1] is mark_id,
3437 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3439 * For SET_META action which stores value in reg_c[0], as the destination is
3440 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3441 * MARK ID means the default flow. The default flow looks like,
3442 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3445 * Pointer to Ethernet device.
3447 * Pointer to flow structure.
3448 * @param[in] actions
3449 * Pointer to the list of actions.
3451 * Perform verbose error reporting if not NULL.
3454 * 0 on success, negative value otherwise and rte_errno is set.
3457 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3458 struct rte_flow *flow,
3459 const struct rte_flow_action *actions,
3460 struct rte_flow_error *error)
3462 struct mlx5_priv *priv = dev->data->dev_private;
3463 struct mlx5_dev_config *config = &priv->config;
3464 struct mlx5_flow_mreg_copy_resource *mcp_res;
3465 const struct rte_flow_action_mark *mark;
3467 /* Check whether extensive metadata feature is engaged. */
3468 if (!config->dv_flow_en ||
3469 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3470 !mlx5_flow_ext_mreg_supported(dev) ||
3471 !priv->sh->dv_regc0_mask)
3473 /* Find MARK action. */
3474 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3475 switch (actions->type) {
3476 case RTE_FLOW_ACTION_TYPE_FLAG:
3477 mcp_res = flow_mreg_add_copy_action
3478 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3481 flow->rix_mreg_copy = mcp_res->idx;
3482 if (dev->data->dev_started) {
3484 flow->copy_applied = 1;
3487 case RTE_FLOW_ACTION_TYPE_MARK:
3488 mark = (const struct rte_flow_action_mark *)
3491 flow_mreg_add_copy_action(dev, mark->id, error);
3494 flow->rix_mreg_copy = mcp_res->idx;
3495 if (dev->data->dev_started) {
3497 flow->copy_applied = 1;
3507 #define MLX5_MAX_SPLIT_ACTIONS 24
3508 #define MLX5_MAX_SPLIT_ITEMS 24
3511 * Split the hairpin flow.
3512 * Since HW can't support encap on Rx we move the encap to Tx.
3513 * If the count action is after the encap then we also
3514 * move the count action. in this case the count will also measure
3518 * Pointer to Ethernet device.
3519 * @param[in] actions
3520 * Associated actions (list terminated by the END action).
3521 * @param[out] actions_rx
3523 * @param[out] actions_tx
3525 * @param[out] pattern_tx
3526 * The pattern items for the Tx flow.
3527 * @param[out] flow_id
3528 * The flow ID connected to this flow.
3534 flow_hairpin_split(struct rte_eth_dev *dev,
3535 const struct rte_flow_action actions[],
3536 struct rte_flow_action actions_rx[],
3537 struct rte_flow_action actions_tx[],
3538 struct rte_flow_item pattern_tx[],
3541 struct mlx5_priv *priv = dev->data->dev_private;
3542 const struct rte_flow_action_raw_encap *raw_encap;
3543 const struct rte_flow_action_raw_decap *raw_decap;
3544 struct mlx5_rte_flow_action_set_tag *set_tag;
3545 struct rte_flow_action *tag_action;
3546 struct mlx5_rte_flow_item_tag *tag_item;
3547 struct rte_flow_item *item;
3551 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
3552 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3553 switch (actions->type) {
3554 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3555 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3556 rte_memcpy(actions_tx, actions,
3557 sizeof(struct rte_flow_action));
3560 case RTE_FLOW_ACTION_TYPE_COUNT:
3562 rte_memcpy(actions_tx, actions,
3563 sizeof(struct rte_flow_action));
3566 rte_memcpy(actions_rx, actions,
3567 sizeof(struct rte_flow_action));
3571 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3572 raw_encap = actions->conf;
3573 if (raw_encap->size >
3574 (sizeof(struct rte_flow_item_eth) +
3575 sizeof(struct rte_flow_item_ipv4))) {
3576 memcpy(actions_tx, actions,
3577 sizeof(struct rte_flow_action));
3581 rte_memcpy(actions_rx, actions,
3582 sizeof(struct rte_flow_action));
3586 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3587 raw_decap = actions->conf;
3588 if (raw_decap->size <
3589 (sizeof(struct rte_flow_item_eth) +
3590 sizeof(struct rte_flow_item_ipv4))) {
3591 memcpy(actions_tx, actions,
3592 sizeof(struct rte_flow_action));
3595 rte_memcpy(actions_rx, actions,
3596 sizeof(struct rte_flow_action));
3601 rte_memcpy(actions_rx, actions,
3602 sizeof(struct rte_flow_action));
3607 /* Add set meta action and end action for the Rx flow. */
3608 tag_action = actions_rx;
3609 tag_action->type = (enum rte_flow_action_type)
3610 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3612 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
3614 set_tag = (void *)actions_rx;
3615 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
3616 MLX5_ASSERT(set_tag->id > REG_NONE);
3617 set_tag->data = *flow_id;
3618 tag_action->conf = set_tag;
3619 /* Create Tx item list. */
3620 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
3621 addr = (void *)&pattern_tx[2];
3623 item->type = (enum rte_flow_item_type)
3624 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3625 tag_item = (void *)addr;
3626 tag_item->data = *flow_id;
3627 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
3628 MLX5_ASSERT(set_tag->id > REG_NONE);
3629 item->spec = tag_item;
3630 addr += sizeof(struct mlx5_rte_flow_item_tag);
3631 tag_item = (void *)addr;
3632 tag_item->data = UINT32_MAX;
3633 tag_item->id = UINT16_MAX;
3634 item->mask = tag_item;
3635 addr += sizeof(struct mlx5_rte_flow_item_tag);
3638 item->type = RTE_FLOW_ITEM_TYPE_END;
3643 * The last stage of splitting chain, just creates the subflow
3644 * without any modification.
3647 * Pointer to Ethernet device.
3649 * Parent flow structure pointer.
3650 * @param[in, out] sub_flow
3651 * Pointer to return the created subflow, may be NULL.
3652 * @param[in] prefix_layers
3653 * Prefix subflow layers, may be 0.
3655 * Flow rule attributes.
3657 * Pattern specification (list terminated by the END pattern item).
3658 * @param[in] actions
3659 * Associated actions (list terminated by the END action).
3660 * @param[in] external
3661 * This flow rule is created by request external to PMD.
3662 * @param[in] flow_idx
3663 * This memory pool index to the flow.
3665 * Perform verbose error reporting if not NULL.
3667 * 0 on success, negative value otherwise
3670 flow_create_split_inner(struct rte_eth_dev *dev,
3671 struct rte_flow *flow,
3672 struct mlx5_flow **sub_flow,
3673 uint64_t prefix_layers,
3674 const struct rte_flow_attr *attr,
3675 const struct rte_flow_item items[],
3676 const struct rte_flow_action actions[],
3677 bool external, uint32_t flow_idx,
3678 struct rte_flow_error *error)
3680 struct mlx5_flow *dev_flow;
3682 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
3686 dev_flow->flow = flow;
3687 dev_flow->external = external;
3688 /* Subflow object was created, we must include one in the list. */
3689 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
3690 dev_flow->handle, next);
3692 * If dev_flow is as one of the suffix flow, some actions in suffix
3693 * flow may need some user defined item layer flags.
3696 dev_flow->handle->layers = prefix_layers;
3698 *sub_flow = dev_flow;
3699 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
3703 * Split the meter flow.
3705 * As meter flow will split to three sub flow, other than meter
3706 * action, the other actions make sense to only meter accepts
3707 * the packet. If it need to be dropped, no other additional
3708 * actions should be take.
3710 * One kind of special action which decapsulates the L3 tunnel
3711 * header will be in the prefix sub flow, as not to take the
3712 * L3 tunnel header into account.
3715 * Pointer to Ethernet device.
3717 * Pattern specification (list terminated by the END pattern item).
3718 * @param[out] sfx_items
3719 * Suffix flow match items (list terminated by the END pattern item).
3720 * @param[in] actions
3721 * Associated actions (list terminated by the END action).
3722 * @param[out] actions_sfx
3723 * Suffix flow actions.
3724 * @param[out] actions_pre
3725 * Prefix flow actions.
3726 * @param[out] pattern_sfx
3727 * The pattern items for the suffix flow.
3728 * @param[out] tag_sfx
3729 * Pointer to suffix flow tag.
3735 flow_meter_split_prep(struct rte_eth_dev *dev,
3736 const struct rte_flow_item items[],
3737 struct rte_flow_item sfx_items[],
3738 const struct rte_flow_action actions[],
3739 struct rte_flow_action actions_sfx[],
3740 struct rte_flow_action actions_pre[])
3742 struct rte_flow_action *tag_action = NULL;
3743 struct rte_flow_item *tag_item;
3744 struct mlx5_rte_flow_action_set_tag *set_tag;
3745 struct rte_flow_error error;
3746 const struct rte_flow_action_raw_encap *raw_encap;
3747 const struct rte_flow_action_raw_decap *raw_decap;
3748 struct mlx5_rte_flow_item_tag *tag_spec;
3749 struct mlx5_rte_flow_item_tag *tag_mask;
3751 bool copy_vlan = false;
3753 /* Prepare the actions for prefix and suffix flow. */
3754 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3755 struct rte_flow_action **action_cur = NULL;
3757 switch (actions->type) {
3758 case RTE_FLOW_ACTION_TYPE_METER:
3759 /* Add the extra tag action first. */
3760 tag_action = actions_pre;
3761 tag_action->type = (enum rte_flow_action_type)
3762 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3764 action_cur = &actions_pre;
3766 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3767 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3768 action_cur = &actions_pre;
3770 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3771 raw_encap = actions->conf;
3772 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
3773 action_cur = &actions_pre;
3775 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3776 raw_decap = actions->conf;
3777 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3778 action_cur = &actions_pre;
3780 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3781 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3788 action_cur = &actions_sfx;
3789 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
3792 /* Add end action to the actions. */
3793 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
3794 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
3797 set_tag = (void *)actions_pre;
3798 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3800 * Get the id from the qrss_pool to make qrss share the id with meter.
3802 tag_id = flow_qrss_get_id(dev);
3803 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
3805 tag_action->conf = set_tag;
3806 /* Prepare the suffix subflow items. */
3807 tag_item = sfx_items++;
3808 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3809 int item_type = items->type;
3811 switch (item_type) {
3812 case RTE_FLOW_ITEM_TYPE_PORT_ID:
3813 memcpy(sfx_items, items, sizeof(*sfx_items));
3816 case RTE_FLOW_ITEM_TYPE_VLAN:
3818 memcpy(sfx_items, items, sizeof(*sfx_items));
3820 * Convert to internal match item, it is used
3821 * for vlan push and set vid.
3823 sfx_items->type = (enum rte_flow_item_type)
3824 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
3832 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
3834 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
3835 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
3836 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3837 tag_mask = tag_spec + 1;
3838 tag_mask->data = 0xffffff00;
3839 tag_item->type = (enum rte_flow_item_type)
3840 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3841 tag_item->spec = tag_spec;
3842 tag_item->last = NULL;
3843 tag_item->mask = tag_mask;
3848 * Split action list having QUEUE/RSS for metadata register copy.
3850 * Once Q/RSS action is detected in user's action list, the flow action
3851 * should be split in order to copy metadata registers, which will happen in
3853 * - CQE->flow_tag := reg_c[1] (MARK)
3854 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3855 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
3856 * This is because the last action of each flow must be a terminal action
3857 * (QUEUE, RSS or DROP).
3859 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
3860 * stored and kept in the mlx5_flow structure per each sub_flow.
3862 * The Q/RSS action is replaced with,
3863 * - SET_TAG, setting the allocated flow ID to reg_c[2].
3864 * And the following JUMP action is added at the end,
3865 * - JUMP, to RX_CP_TBL.
3867 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
3868 * flow_create_split_metadata() routine. The flow will look like,
3869 * - If flow ID matches (reg_c[2]), perform Q/RSS.
3872 * Pointer to Ethernet device.
3873 * @param[out] split_actions
3874 * Pointer to store split actions to jump to CP_TBL.
3875 * @param[in] actions
3876 * Pointer to the list of original flow actions.
3878 * Pointer to the Q/RSS action.
3879 * @param[in] actions_n
3880 * Number of original actions.
3882 * Perform verbose error reporting if not NULL.
3885 * non-zero unique flow_id on success, otherwise 0 and
3886 * error/rte_error are set.
3889 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
3890 struct rte_flow_action *split_actions,
3891 const struct rte_flow_action *actions,
3892 const struct rte_flow_action *qrss,
3893 int actions_n, struct rte_flow_error *error)
3895 struct mlx5_rte_flow_action_set_tag *set_tag;
3896 struct rte_flow_action_jump *jump;
3897 const int qrss_idx = qrss - actions;
3898 uint32_t flow_id = 0;
3902 * Given actions will be split
3903 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
3904 * - Add jump to mreg CP_TBL.
3905 * As a result, there will be one more action.
3908 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
3909 set_tag = (void *)(split_actions + actions_n);
3911 * If tag action is not set to void(it means we are not the meter
3912 * suffix flow), add the tag action. Since meter suffix flow already
3913 * has the tag added.
3915 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
3917 * Allocate the new subflow ID. This one is unique within
3918 * device and not shared with representors. Otherwise,
3919 * we would have to resolve multi-thread access synch
3920 * issue. Each flow on the shared device is appended
3921 * with source vport identifier, so the resulting
3922 * flows will be unique in the shared (by master and
3923 * representors) domain even if they have coinciding
3926 flow_id = flow_qrss_get_id(dev);
3928 return rte_flow_error_set(error, ENOMEM,
3929 RTE_FLOW_ERROR_TYPE_ACTION,
3930 NULL, "can't allocate id "
3931 "for split Q/RSS subflow");
3932 /* Internal SET_TAG action to set flow ID. */
3933 *set_tag = (struct mlx5_rte_flow_action_set_tag){
3936 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
3940 /* Construct new actions array. */
3941 /* Replace QUEUE/RSS action. */
3942 split_actions[qrss_idx] = (struct rte_flow_action){
3943 .type = (enum rte_flow_action_type)
3944 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
3948 /* JUMP action to jump to mreg copy table (CP_TBL). */
3949 jump = (void *)(set_tag + 1);
3950 *jump = (struct rte_flow_action_jump){
3951 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3953 split_actions[actions_n - 2] = (struct rte_flow_action){
3954 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3957 split_actions[actions_n - 1] = (struct rte_flow_action){
3958 .type = RTE_FLOW_ACTION_TYPE_END,
3964 * Extend the given action list for Tx metadata copy.
3966 * Copy the given action list to the ext_actions and add flow metadata register
3967 * copy action in order to copy reg_a set by WQE to reg_c[0].
3969 * @param[out] ext_actions
3970 * Pointer to the extended action list.
3971 * @param[in] actions
3972 * Pointer to the list of actions.
3973 * @param[in] actions_n
3974 * Number of actions in the list.
3976 * Perform verbose error reporting if not NULL.
3977 * @param[in] encap_idx
3978 * The encap action inndex.
3981 * 0 on success, negative value otherwise
3984 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
3985 struct rte_flow_action *ext_actions,
3986 const struct rte_flow_action *actions,
3987 int actions_n, struct rte_flow_error *error,
3990 struct mlx5_flow_action_copy_mreg *cp_mreg =
3991 (struct mlx5_flow_action_copy_mreg *)
3992 (ext_actions + actions_n + 1);
3995 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3999 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
4004 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
4005 if (encap_idx == actions_n - 1) {
4006 ext_actions[actions_n - 1] = (struct rte_flow_action){
4007 .type = (enum rte_flow_action_type)
4008 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4011 ext_actions[actions_n] = (struct rte_flow_action){
4012 .type = RTE_FLOW_ACTION_TYPE_END,
4015 ext_actions[encap_idx] = (struct rte_flow_action){
4016 .type = (enum rte_flow_action_type)
4017 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
4020 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
4021 sizeof(*ext_actions) * (actions_n - encap_idx));
4027 * The splitting for metadata feature.
4029 * - Q/RSS action on NIC Rx should be split in order to pass by
4030 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4031 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4033 * - All the actions on NIC Tx should have a mreg copy action to
4034 * copy reg_a from WQE to reg_c[0].
4037 * Pointer to Ethernet device.
4039 * Parent flow structure pointer.
4040 * @param[in] prefix_layers
4041 * Prefix flow layer flags.
4043 * Flow rule attributes.
4045 * Pattern specification (list terminated by the END pattern item).
4046 * @param[in] actions
4047 * Associated actions (list terminated by the END action).
4048 * @param[in] external
4049 * This flow rule is created by request external to PMD.
4050 * @param[in] flow_idx
4051 * This memory pool index to the flow.
4053 * Perform verbose error reporting if not NULL.
4055 * 0 on success, negative value otherwise
4058 flow_create_split_metadata(struct rte_eth_dev *dev,
4059 struct rte_flow *flow,
4060 uint64_t prefix_layers,
4061 const struct rte_flow_attr *attr,
4062 const struct rte_flow_item items[],
4063 const struct rte_flow_action actions[],
4064 bool external, uint32_t flow_idx,
4065 struct rte_flow_error *error)
4067 struct mlx5_priv *priv = dev->data->dev_private;
4068 struct mlx5_dev_config *config = &priv->config;
4069 const struct rte_flow_action *qrss = NULL;
4070 struct rte_flow_action *ext_actions = NULL;
4071 struct mlx5_flow *dev_flow = NULL;
4072 uint32_t qrss_id = 0;
4079 /* Check whether extensive metadata feature is engaged. */
4080 if (!config->dv_flow_en ||
4081 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4082 !mlx5_flow_ext_mreg_supported(dev))
4083 return flow_create_split_inner(dev, flow, NULL, prefix_layers,
4084 attr, items, actions, external,
4086 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
4089 /* Exclude hairpin flows from splitting. */
4090 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
4091 const struct rte_flow_action_queue *queue;
4094 if (mlx5_rxq_get_type(dev, queue->index) ==
4095 MLX5_RXQ_TYPE_HAIRPIN)
4097 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
4098 const struct rte_flow_action_rss *rss;
4101 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
4102 MLX5_RXQ_TYPE_HAIRPIN)
4107 /* Check if it is in meter suffix table. */
4108 mtr_sfx = attr->group == (attr->transfer ?
4109 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4110 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
4112 * Q/RSS action on NIC Rx should be split in order to pass by
4113 * the mreg copy table (RX_CP_TBL) and then it jumps to the
4114 * action table (RX_ACT_TBL) which has the split Q/RSS action.
4116 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
4117 sizeof(struct rte_flow_action_set_tag) +
4118 sizeof(struct rte_flow_action_jump);
4119 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
4122 return rte_flow_error_set(error, ENOMEM,
4123 RTE_FLOW_ERROR_TYPE_ACTION,
4124 NULL, "no memory to split "
4127 * If we are the suffix flow of meter, tag already exist.
4128 * Set the tag action to void.
4131 ext_actions[qrss - actions].type =
4132 RTE_FLOW_ACTION_TYPE_VOID;
4134 ext_actions[qrss - actions].type =
4135 (enum rte_flow_action_type)
4136 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
4138 * Create the new actions list with removed Q/RSS action
4139 * and appended set tag and jump to register copy table
4140 * (RX_CP_TBL). We should preallocate unique tag ID here
4141 * in advance, because it is needed for set tag action.
4143 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
4144 qrss, actions_n, error);
4145 if (!mtr_sfx && !qrss_id) {
4149 } else if (attr->egress && !attr->transfer) {
4151 * All the actions on NIC Tx should have a metadata register
4152 * copy action to copy reg_a from WQE to reg_c[meta]
4154 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
4155 sizeof(struct mlx5_flow_action_copy_mreg);
4156 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
4159 return rte_flow_error_set(error, ENOMEM,
4160 RTE_FLOW_ERROR_TYPE_ACTION,
4161 NULL, "no memory to split "
4163 /* Create the action list appended with copy register. */
4164 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
4165 actions_n, error, encap_idx);
4169 /* Add the unmodified original or prefix subflow. */
4170 ret = flow_create_split_inner(dev, flow, &dev_flow, prefix_layers, attr,
4171 items, ext_actions ? ext_actions :
4172 actions, external, flow_idx, error);
4175 MLX5_ASSERT(dev_flow);
4177 const struct rte_flow_attr q_attr = {
4178 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4181 /* Internal PMD action to set register. */
4182 struct mlx5_rte_flow_item_tag q_tag_spec = {
4186 struct rte_flow_item q_items[] = {
4188 .type = (enum rte_flow_item_type)
4189 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4190 .spec = &q_tag_spec,
4195 .type = RTE_FLOW_ITEM_TYPE_END,
4198 struct rte_flow_action q_actions[] = {
4204 .type = RTE_FLOW_ACTION_TYPE_END,
4207 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
4210 * Configure the tag item only if there is no meter subflow.
4211 * Since tag is already marked in the meter suffix subflow
4212 * we can just use the meter suffix items as is.
4215 /* Not meter subflow. */
4216 MLX5_ASSERT(!mtr_sfx);
4218 * Put unique id in prefix flow due to it is destroyed
4219 * after suffix flow and id will be freed after there
4220 * is no actual flows with this id and identifier
4221 * reallocation becomes possible (for example, for
4222 * other flows in other threads).
4224 dev_flow->handle->split_flow_id = qrss_id;
4225 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
4229 q_tag_spec.id = ret;
4232 /* Add suffix subflow to execute Q/RSS. */
4233 ret = flow_create_split_inner(dev, flow, &dev_flow, layers,
4234 &q_attr, mtr_sfx ? items :
4236 external, flow_idx, error);
4239 /* qrss ID should be freed if failed. */
4241 MLX5_ASSERT(dev_flow);
4246 * We do not destroy the partially created sub_flows in case of error.
4247 * These ones are included into parent flow list and will be destroyed
4248 * by flow_drv_destroy.
4250 flow_qrss_free_id(dev, qrss_id);
4251 mlx5_free(ext_actions);
4256 * The splitting for meter feature.
4258 * - The meter flow will be split to two flows as prefix and
4259 * suffix flow. The packets make sense only it pass the prefix
4262 * - Reg_C_5 is used for the packet to match betweend prefix and
4266 * Pointer to Ethernet device.
4268 * Parent flow structure pointer.
4270 * Flow rule attributes.
4272 * Pattern specification (list terminated by the END pattern item).
4273 * @param[in] actions
4274 * Associated actions (list terminated by the END action).
4275 * @param[in] external
4276 * This flow rule is created by request external to PMD.
4277 * @param[in] flow_idx
4278 * This memory pool index to the flow.
4280 * Perform verbose error reporting if not NULL.
4282 * 0 on success, negative value otherwise
4285 flow_create_split_meter(struct rte_eth_dev *dev,
4286 struct rte_flow *flow,
4287 const struct rte_flow_attr *attr,
4288 const struct rte_flow_item items[],
4289 const struct rte_flow_action actions[],
4290 bool external, uint32_t flow_idx,
4291 struct rte_flow_error *error)
4293 struct mlx5_priv *priv = dev->data->dev_private;
4294 struct rte_flow_action *sfx_actions = NULL;
4295 struct rte_flow_action *pre_actions = NULL;
4296 struct rte_flow_item *sfx_items = NULL;
4297 struct mlx5_flow *dev_flow = NULL;
4298 struct rte_flow_attr sfx_attr = *attr;
4300 uint32_t mtr_tag_id = 0;
4307 actions_n = flow_check_meter_action(actions, &mtr);
4309 /* The five prefix actions: meter, decap, encap, tag, end. */
4310 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
4311 sizeof(struct mlx5_rte_flow_action_set_tag);
4312 /* tag, vlan, port id, end. */
4313 #define METER_SUFFIX_ITEM 4
4314 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
4315 sizeof(struct mlx5_rte_flow_item_tag) * 2;
4316 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
4319 return rte_flow_error_set(error, ENOMEM,
4320 RTE_FLOW_ERROR_TYPE_ACTION,
4321 NULL, "no memory to split "
4323 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4325 pre_actions = sfx_actions + actions_n;
4326 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
4327 actions, sfx_actions,
4333 /* Add the prefix subflow. */
4334 ret = flow_create_split_inner(dev, flow, &dev_flow, 0, attr,
4335 items, pre_actions, external,
4341 dev_flow->handle->split_flow_id = mtr_tag_id;
4342 /* Setting the sfx group atrr. */
4343 sfx_attr.group = sfx_attr.transfer ?
4344 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4345 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4347 /* Add the prefix subflow. */
4348 ret = flow_create_split_metadata(dev, flow, dev_flow ?
4349 flow_get_prefix_layer_flags(dev_flow) :
4351 sfx_items ? sfx_items : items,
4352 sfx_actions ? sfx_actions : actions,
4353 external, flow_idx, error);
4356 mlx5_free(sfx_actions);
4361 * Split the flow to subflow set. The splitters might be linked
4362 * in the chain, like this:
4363 * flow_create_split_outer() calls:
4364 * flow_create_split_meter() calls:
4365 * flow_create_split_metadata(meter_subflow_0) calls:
4366 * flow_create_split_inner(metadata_subflow_0)
4367 * flow_create_split_inner(metadata_subflow_1)
4368 * flow_create_split_inner(metadata_subflow_2)
4369 * flow_create_split_metadata(meter_subflow_1) calls:
4370 * flow_create_split_inner(metadata_subflow_0)
4371 * flow_create_split_inner(metadata_subflow_1)
4372 * flow_create_split_inner(metadata_subflow_2)
4374 * This provide flexible way to add new levels of flow splitting.
4375 * The all of successfully created subflows are included to the
4376 * parent flow dev_flow list.
4379 * Pointer to Ethernet device.
4381 * Parent flow structure pointer.
4383 * Flow rule attributes.
4385 * Pattern specification (list terminated by the END pattern item).
4386 * @param[in] actions
4387 * Associated actions (list terminated by the END action).
4388 * @param[in] external
4389 * This flow rule is created by request external to PMD.
4390 * @param[in] flow_idx
4391 * This memory pool index to the flow.
4393 * Perform verbose error reporting if not NULL.
4395 * 0 on success, negative value otherwise
4398 flow_create_split_outer(struct rte_eth_dev *dev,
4399 struct rte_flow *flow,
4400 const struct rte_flow_attr *attr,
4401 const struct rte_flow_item items[],
4402 const struct rte_flow_action actions[],
4403 bool external, uint32_t flow_idx,
4404 struct rte_flow_error *error)
4408 ret = flow_create_split_meter(dev, flow, attr, items,
4409 actions, external, flow_idx, error);
4410 MLX5_ASSERT(ret <= 0);
4415 * Create a flow and add it to @p list.
4418 * Pointer to Ethernet device.
4420 * Pointer to a TAILQ flow list. If this parameter NULL,
4421 * no list insertion occurred, flow is just created,
4422 * this is caller's responsibility to track the
4425 * Flow rule attributes.
4427 * Pattern specification (list terminated by the END pattern item).
4428 * @param[in] actions
4429 * Associated actions (list terminated by the END action).
4430 * @param[in] external
4431 * This flow rule is created by request external to PMD.
4433 * Perform verbose error reporting if not NULL.
4436 * A flow index on success, 0 otherwise and rte_errno is set.
4439 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
4440 const struct rte_flow_attr *attr,
4441 const struct rte_flow_item items[],
4442 const struct rte_flow_action actions[],
4443 bool external, struct rte_flow_error *error)
4445 struct mlx5_priv *priv = dev->data->dev_private;
4446 struct rte_flow *flow = NULL;
4447 struct mlx5_flow *dev_flow;
4448 const struct rte_flow_action_rss *rss;
4450 struct rte_flow_expand_rss buf;
4451 uint8_t buffer[2048];
4454 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4455 uint8_t buffer[2048];
4458 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4459 uint8_t buffer[2048];
4460 } actions_hairpin_tx;
4462 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
4463 uint8_t buffer[2048];
4465 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
4466 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
4467 priv->rss_desc)[!!priv->flow_idx];
4468 const struct rte_flow_action *p_actions_rx = actions;
4472 uint32_t hairpin_id = 0;
4473 struct rte_flow_attr attr_tx = { .priority = 0 };
4476 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4477 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
4478 external, hairpin_flow, error);
4481 if (hairpin_flow > 0) {
4482 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
4486 flow_hairpin_split(dev, actions, actions_rx.actions,
4487 actions_hairpin_tx.actions, items_tx.items,
4489 p_actions_rx = actions_rx.actions;
4491 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
4494 goto error_before_flow;
4496 flow->drv_type = flow_get_drv_type(dev, attr);
4497 if (hairpin_id != 0)
4498 flow->hairpin_flow_id = hairpin_id;
4499 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
4500 flow->drv_type < MLX5_FLOW_TYPE_MAX);
4501 memset(rss_desc, 0, sizeof(*rss_desc));
4502 rss = flow_get_rss_action(p_actions_rx);
4505 * The following information is required by
4506 * mlx5_flow_hashfields_adjust() in advance.
4508 rss_desc->level = rss->level;
4509 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
4510 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
4512 flow->dev_handles = 0;
4513 if (rss && rss->types) {
4514 unsigned int graph_root;
4516 graph_root = find_graph_root(items, rss->level);
4517 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
4519 mlx5_support_expansion,
4521 MLX5_ASSERT(ret > 0 &&
4522 (unsigned int)ret < sizeof(expand_buffer.buffer));
4525 buf->entry[0].pattern = (void *)(uintptr_t)items;
4528 * Record the start index when there is a nested call. All sub-flows
4529 * need to be translated before another calling.
4530 * No need to use ping-pong buffer to save memory here.
4532 if (priv->flow_idx) {
4533 MLX5_ASSERT(!priv->flow_nested_idx);
4534 priv->flow_nested_idx = priv->flow_idx;
4536 for (i = 0; i < buf->entries; ++i) {
4538 * The splitter may create multiple dev_flows,
4539 * depending on configuration. In the simplest
4540 * case it just creates unmodified original flow.
4542 ret = flow_create_split_outer(dev, flow, attr,
4543 buf->entry[i].pattern,
4544 p_actions_rx, external, idx,
4549 /* Create the tx flow. */
4551 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
4552 attr_tx.ingress = 0;
4554 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
4555 actions_hairpin_tx.actions,
4559 dev_flow->flow = flow;
4560 dev_flow->external = 0;
4561 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4562 dev_flow->handle, next);
4563 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
4565 actions_hairpin_tx.actions, error);
4570 * Update the metadata register copy table. If extensive
4571 * metadata feature is enabled and registers are supported
4572 * we might create the extra rte_flow for each unique
4573 * MARK/FLAG action ID.
4575 * The table is updated for ingress Flows only, because
4576 * the egress Flows belong to the different device and
4577 * copy table should be updated in peer NIC Rx domain.
4579 if (attr->ingress &&
4580 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
4581 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
4586 * If the flow is external (from application) OR device is started, then
4587 * the flow will be applied immediately.
4589 if (external || dev->data->dev_started) {
4590 ret = flow_drv_apply(dev, flow, error);
4595 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
4597 flow_rxq_flags_set(dev, flow);
4598 /* Nested flow creation index recovery. */
4599 priv->flow_idx = priv->flow_nested_idx;
4600 if (priv->flow_nested_idx)
4601 priv->flow_nested_idx = 0;
4605 ret = rte_errno; /* Save rte_errno before cleanup. */
4606 flow_mreg_del_copy_action(dev, flow);
4607 flow_drv_destroy(dev, flow);
4608 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
4609 rte_errno = ret; /* Restore rte_errno. */
4613 mlx5_flow_id_release(priv->sh->flow_id_pool,
4616 priv->flow_idx = priv->flow_nested_idx;
4617 if (priv->flow_nested_idx)
4618 priv->flow_nested_idx = 0;
4623 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
4624 * incoming packets to table 1.
4626 * Other flow rules, requested for group n, will be created in
4627 * e-switch table n+1.
4628 * Jump action to e-switch group n will be created to group n+1.
4630 * Used when working in switchdev mode, to utilise advantages of table 1
4634 * Pointer to Ethernet device.
4637 * Pointer to flow on success, NULL otherwise and rte_errno is set.
4640 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
4642 const struct rte_flow_attr attr = {
4649 const struct rte_flow_item pattern = {
4650 .type = RTE_FLOW_ITEM_TYPE_END,
4652 struct rte_flow_action_jump jump = {
4655 const struct rte_flow_action actions[] = {
4657 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4661 .type = RTE_FLOW_ACTION_TYPE_END,
4664 struct mlx5_priv *priv = dev->data->dev_private;
4665 struct rte_flow_error error;
4667 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
4669 actions, false, &error);
4673 * Validate a flow supported by the NIC.
4675 * @see rte_flow_validate()
4679 mlx5_flow_validate(struct rte_eth_dev *dev,
4680 const struct rte_flow_attr *attr,
4681 const struct rte_flow_item items[],
4682 const struct rte_flow_action actions[],
4683 struct rte_flow_error *error)
4687 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4688 return flow_drv_validate(dev, attr, items, actions,
4689 true, hairpin_flow, error);
4695 * @see rte_flow_create()
4699 mlx5_flow_create(struct rte_eth_dev *dev,
4700 const struct rte_flow_attr *attr,
4701 const struct rte_flow_item items[],
4702 const struct rte_flow_action actions[],
4703 struct rte_flow_error *error)
4705 struct mlx5_priv *priv = dev->data->dev_private;
4708 * If the device is not started yet, it is not allowed to created a
4709 * flow from application. PMD default flows and traffic control flows
4712 if (unlikely(!dev->data->dev_started)) {
4713 DRV_LOG(DEBUG, "port %u is not started when "
4714 "inserting a flow", dev->data->port_id);
4715 rte_flow_error_set(error, ENODEV,
4716 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4718 "port not started");
4721 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
4722 attr, items, actions, true, error);
4726 * Destroy a flow in a list.
4729 * Pointer to Ethernet device.
4731 * Pointer to the Indexed flow list. If this parameter NULL,
4732 * there is no flow removal from the list. Be noted that as
4733 * flow is add to the indexed list, memory of the indexed
4734 * list points to maybe changed as flow destroyed.
4735 * @param[in] flow_idx
4736 * Index of flow to destroy.
4739 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
4742 struct mlx5_priv *priv = dev->data->dev_private;
4743 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
4744 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
4745 [MLX5_IPOOL_RTE_FLOW], flow_idx);
4750 * Update RX queue flags only if port is started, otherwise it is
4753 if (dev->data->dev_started)
4754 flow_rxq_flags_trim(dev, flow);
4755 if (flow->hairpin_flow_id)
4756 mlx5_flow_id_release(priv->sh->flow_id_pool,
4757 flow->hairpin_flow_id);
4758 flow_drv_destroy(dev, flow);
4760 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
4761 flow_idx, flow, next);
4762 flow_mreg_del_copy_action(dev, flow);
4764 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
4765 if (priv_fdir_flow->rix_flow == flow_idx)
4768 if (priv_fdir_flow) {
4769 LIST_REMOVE(priv_fdir_flow, next);
4770 mlx5_free(priv_fdir_flow->fdir);
4771 mlx5_free(priv_fdir_flow);
4774 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
4778 * Destroy all flows.
4781 * Pointer to Ethernet device.
4783 * Pointer to the Indexed flow list.
4785 * If flushing is called avtively.
4788 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
4790 uint32_t num_flushed = 0;
4793 flow_list_destroy(dev, list, *list);
4797 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
4798 dev->data->port_id, num_flushed);
4806 * Pointer to Ethernet device.
4808 * Pointer to the Indexed flow list.
4811 mlx5_flow_stop(struct rte_eth_dev *dev, uint32_t *list)
4813 struct mlx5_priv *priv = dev->data->dev_private;
4814 struct rte_flow *flow = NULL;
4817 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
4819 flow_drv_remove(dev, flow);
4820 flow_mreg_stop_copy_action(dev, flow);
4822 flow_mreg_del_default_copy_action(dev);
4823 flow_rxq_flags_clear(dev);
4830 * Pointer to Ethernet device.
4832 * Pointer to the Indexed flow list.
4835 * 0 on success, a negative errno value otherwise and rte_errno is set.
4838 mlx5_flow_start(struct rte_eth_dev *dev, uint32_t *list)
4840 struct mlx5_priv *priv = dev->data->dev_private;
4841 struct rte_flow *flow = NULL;
4842 struct rte_flow_error error;
4846 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4847 ret = flow_mreg_add_default_copy_action(dev, &error);
4850 /* Apply Flows created by application. */
4851 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
4853 ret = flow_mreg_start_copy_action(dev, flow);
4856 ret = flow_drv_apply(dev, flow, &error);
4859 flow_rxq_flags_set(dev, flow);
4863 ret = rte_errno; /* Save rte_errno before cleanup. */
4864 mlx5_flow_stop(dev, list);
4865 rte_errno = ret; /* Restore rte_errno. */
4870 * Stop all default actions for flows.
4873 * Pointer to Ethernet device.
4876 mlx5_flow_stop_default(struct rte_eth_dev *dev)
4878 flow_mreg_del_default_copy_action(dev);
4879 flow_rxq_flags_clear(dev);
4883 * Start all default actions for flows.
4886 * Pointer to Ethernet device.
4888 * 0 on success, a negative errno value otherwise and rte_errno is set.
4891 mlx5_flow_start_default(struct rte_eth_dev *dev)
4893 struct rte_flow_error error;
4895 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4896 return flow_mreg_add_default_copy_action(dev, &error);
4900 * Allocate intermediate resources for flow creation.
4903 * Pointer to Ethernet device.
4906 mlx5_flow_alloc_intermediate(struct rte_eth_dev *dev)
4908 struct mlx5_priv *priv = dev->data->dev_private;
4910 if (!priv->inter_flows) {
4911 priv->inter_flows = mlx5_malloc(MLX5_MEM_ZERO,
4912 MLX5_NUM_MAX_DEV_FLOWS *
4913 sizeof(struct mlx5_flow) +
4914 (sizeof(struct mlx5_flow_rss_desc) +
4915 sizeof(uint16_t) * UINT16_MAX) * 2, 0,
4917 if (!priv->inter_flows) {
4918 DRV_LOG(ERR, "can't allocate intermediate memory.");
4922 priv->rss_desc = &((struct mlx5_flow *)priv->inter_flows)
4923 [MLX5_NUM_MAX_DEV_FLOWS];
4924 /* Reset the index. */
4926 priv->flow_nested_idx = 0;
4930 * Free intermediate resources for flows.
4933 * Pointer to Ethernet device.
4936 mlx5_flow_free_intermediate(struct rte_eth_dev *dev)
4938 struct mlx5_priv *priv = dev->data->dev_private;
4940 mlx5_free(priv->inter_flows);
4941 priv->inter_flows = NULL;
4945 * Verify the flow list is empty
4948 * Pointer to Ethernet device.
4950 * @return the number of flows not released.
4953 mlx5_flow_verify(struct rte_eth_dev *dev)
4955 struct mlx5_priv *priv = dev->data->dev_private;
4956 struct rte_flow *flow;
4960 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
4962 DRV_LOG(DEBUG, "port %u flow %p still referenced",
4963 dev->data->port_id, (void *)flow);
4970 * Enable default hairpin egress flow.
4973 * Pointer to Ethernet device.
4978 * 0 on success, a negative errno value otherwise and rte_errno is set.
4981 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
4984 struct mlx5_priv *priv = dev->data->dev_private;
4985 const struct rte_flow_attr attr = {
4989 struct mlx5_rte_flow_item_tx_queue queue_spec = {
4992 struct mlx5_rte_flow_item_tx_queue queue_mask = {
4993 .queue = UINT32_MAX,
4995 struct rte_flow_item items[] = {
4997 .type = (enum rte_flow_item_type)
4998 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
4999 .spec = &queue_spec,
5001 .mask = &queue_mask,
5004 .type = RTE_FLOW_ITEM_TYPE_END,
5007 struct rte_flow_action_jump jump = {
5008 .group = MLX5_HAIRPIN_TX_TABLE,
5010 struct rte_flow_action actions[2];
5012 struct rte_flow_error error;
5014 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
5015 actions[0].conf = &jump;
5016 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
5017 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
5018 &attr, items, actions, false, &error);
5021 "Failed to create ctrl flow: rte_errno(%d),"
5022 " type(%d), message(%s)",
5023 rte_errno, error.type,
5024 error.message ? error.message : " (no stated reason)");
5031 * Enable a control flow configured from the control plane.
5034 * Pointer to Ethernet device.
5036 * An Ethernet flow spec to apply.
5038 * An Ethernet flow mask to apply.
5040 * A VLAN flow spec to apply.
5042 * A VLAN flow mask to apply.
5045 * 0 on success, a negative errno value otherwise and rte_errno is set.
5048 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
5049 struct rte_flow_item_eth *eth_spec,
5050 struct rte_flow_item_eth *eth_mask,
5051 struct rte_flow_item_vlan *vlan_spec,
5052 struct rte_flow_item_vlan *vlan_mask)
5054 struct mlx5_priv *priv = dev->data->dev_private;
5055 const struct rte_flow_attr attr = {
5057 .priority = MLX5_FLOW_PRIO_RSVD,
5059 struct rte_flow_item items[] = {
5061 .type = RTE_FLOW_ITEM_TYPE_ETH,
5067 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
5068 RTE_FLOW_ITEM_TYPE_END,
5074 .type = RTE_FLOW_ITEM_TYPE_END,
5077 uint16_t queue[priv->reta_idx_n];
5078 struct rte_flow_action_rss action_rss = {
5079 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
5081 .types = priv->rss_conf.rss_hf,
5082 .key_len = priv->rss_conf.rss_key_len,
5083 .queue_num = priv->reta_idx_n,
5084 .key = priv->rss_conf.rss_key,
5087 struct rte_flow_action actions[] = {
5089 .type = RTE_FLOW_ACTION_TYPE_RSS,
5090 .conf = &action_rss,
5093 .type = RTE_FLOW_ACTION_TYPE_END,
5097 struct rte_flow_error error;
5100 if (!priv->reta_idx_n || !priv->rxqs_n) {
5103 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
5104 action_rss.types = 0;
5105 for (i = 0; i != priv->reta_idx_n; ++i)
5106 queue[i] = (*priv->reta_idx)[i];
5107 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
5108 &attr, items, actions, false, &error);
5115 * Enable a flow control configured from the control plane.
5118 * Pointer to Ethernet device.
5120 * An Ethernet flow spec to apply.
5122 * An Ethernet flow mask to apply.
5125 * 0 on success, a negative errno value otherwise and rte_errno is set.
5128 mlx5_ctrl_flow(struct rte_eth_dev *dev,
5129 struct rte_flow_item_eth *eth_spec,
5130 struct rte_flow_item_eth *eth_mask)
5132 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
5136 * Create default miss flow rule matching lacp traffic
5139 * Pointer to Ethernet device.
5141 * An Ethernet flow spec to apply.
5144 * 0 on success, a negative errno value otherwise and rte_errno is set.
5147 mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
5149 struct mlx5_priv *priv = dev->data->dev_private;
5151 * The LACP matching is done by only using ether type since using
5152 * a multicast dst mac causes kernel to give low priority to this flow.
5154 static const struct rte_flow_item_eth lacp_spec = {
5155 .type = RTE_BE16(0x8809),
5157 static const struct rte_flow_item_eth lacp_mask = {
5160 const struct rte_flow_attr attr = {
5163 struct rte_flow_item items[] = {
5165 .type = RTE_FLOW_ITEM_TYPE_ETH,
5170 .type = RTE_FLOW_ITEM_TYPE_END,
5173 struct rte_flow_action actions[] = {
5175 .type = (enum rte_flow_action_type)
5176 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
5179 .type = RTE_FLOW_ACTION_TYPE_END,
5182 struct rte_flow_error error;
5183 uint32_t flow_idx = flow_list_create(dev, &priv->ctrl_flows,
5184 &attr, items, actions, false, &error);
5194 * @see rte_flow_destroy()
5198 mlx5_flow_destroy(struct rte_eth_dev *dev,
5199 struct rte_flow *flow,
5200 struct rte_flow_error *error __rte_unused)
5202 struct mlx5_priv *priv = dev->data->dev_private;
5204 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
5209 * Destroy all flows.
5211 * @see rte_flow_flush()
5215 mlx5_flow_flush(struct rte_eth_dev *dev,
5216 struct rte_flow_error *error __rte_unused)
5218 struct mlx5_priv *priv = dev->data->dev_private;
5220 mlx5_flow_list_flush(dev, &priv->flows, false);
5227 * @see rte_flow_isolate()
5231 mlx5_flow_isolate(struct rte_eth_dev *dev,
5233 struct rte_flow_error *error)
5235 struct mlx5_priv *priv = dev->data->dev_private;
5237 if (dev->data->dev_started) {
5238 rte_flow_error_set(error, EBUSY,
5239 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5241 "port must be stopped first");
5244 priv->isolated = !!enable;
5246 dev->dev_ops = &mlx5_os_dev_ops_isolate;
5248 dev->dev_ops = &mlx5_os_dev_ops;
5255 * @see rte_flow_query()
5259 flow_drv_query(struct rte_eth_dev *dev,
5261 const struct rte_flow_action *actions,
5263 struct rte_flow_error *error)
5265 struct mlx5_priv *priv = dev->data->dev_private;
5266 const struct mlx5_flow_driver_ops *fops;
5267 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5268 [MLX5_IPOOL_RTE_FLOW],
5270 enum mlx5_flow_drv_type ftype;
5273 return rte_flow_error_set(error, ENOENT,
5274 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5276 "invalid flow handle");
5278 ftype = flow->drv_type;
5279 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
5280 fops = flow_get_drv_ops(ftype);
5282 return fops->query(dev, flow, actions, data, error);
5288 * @see rte_flow_query()
5292 mlx5_flow_query(struct rte_eth_dev *dev,
5293 struct rte_flow *flow,
5294 const struct rte_flow_action *actions,
5296 struct rte_flow_error *error)
5300 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
5308 * Convert a flow director filter to a generic flow.
5311 * Pointer to Ethernet device.
5312 * @param fdir_filter
5313 * Flow director filter to add.
5315 * Generic flow parameters structure.
5318 * 0 on success, a negative errno value otherwise and rte_errno is set.
5321 flow_fdir_filter_convert(struct rte_eth_dev *dev,
5322 const struct rte_eth_fdir_filter *fdir_filter,
5323 struct mlx5_fdir *attributes)
5325 struct mlx5_priv *priv = dev->data->dev_private;
5326 const struct rte_eth_fdir_input *input = &fdir_filter->input;
5327 const struct rte_eth_fdir_masks *mask =
5328 &dev->data->dev_conf.fdir_conf.mask;
5330 /* Validate queue number. */
5331 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
5332 DRV_LOG(ERR, "port %u invalid queue number %d",
5333 dev->data->port_id, fdir_filter->action.rx_queue);
5337 attributes->attr.ingress = 1;
5338 attributes->items[0] = (struct rte_flow_item) {
5339 .type = RTE_FLOW_ITEM_TYPE_ETH,
5340 .spec = &attributes->l2,
5341 .mask = &attributes->l2_mask,
5343 switch (fdir_filter->action.behavior) {
5344 case RTE_ETH_FDIR_ACCEPT:
5345 attributes->actions[0] = (struct rte_flow_action){
5346 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
5347 .conf = &attributes->queue,
5350 case RTE_ETH_FDIR_REJECT:
5351 attributes->actions[0] = (struct rte_flow_action){
5352 .type = RTE_FLOW_ACTION_TYPE_DROP,
5356 DRV_LOG(ERR, "port %u invalid behavior %d",
5358 fdir_filter->action.behavior);
5359 rte_errno = ENOTSUP;
5362 attributes->queue.index = fdir_filter->action.rx_queue;
5364 switch (fdir_filter->input.flow_type) {
5365 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
5366 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
5367 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
5368 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
5369 .src_addr = input->flow.ip4_flow.src_ip,
5370 .dst_addr = input->flow.ip4_flow.dst_ip,
5371 .time_to_live = input->flow.ip4_flow.ttl,
5372 .type_of_service = input->flow.ip4_flow.tos,
5374 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
5375 .src_addr = mask->ipv4_mask.src_ip,
5376 .dst_addr = mask->ipv4_mask.dst_ip,
5377 .time_to_live = mask->ipv4_mask.ttl,
5378 .type_of_service = mask->ipv4_mask.tos,
5379 .next_proto_id = mask->ipv4_mask.proto,
5381 attributes->items[1] = (struct rte_flow_item){
5382 .type = RTE_FLOW_ITEM_TYPE_IPV4,
5383 .spec = &attributes->l3,
5384 .mask = &attributes->l3_mask,
5387 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
5388 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
5389 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
5390 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
5391 .hop_limits = input->flow.ipv6_flow.hop_limits,
5392 .proto = input->flow.ipv6_flow.proto,
5395 memcpy(attributes->l3.ipv6.hdr.src_addr,
5396 input->flow.ipv6_flow.src_ip,
5397 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
5398 memcpy(attributes->l3.ipv6.hdr.dst_addr,
5399 input->flow.ipv6_flow.dst_ip,
5400 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
5401 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
5402 mask->ipv6_mask.src_ip,
5403 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
5404 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
5405 mask->ipv6_mask.dst_ip,
5406 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
5407 attributes->items[1] = (struct rte_flow_item){
5408 .type = RTE_FLOW_ITEM_TYPE_IPV6,
5409 .spec = &attributes->l3,
5410 .mask = &attributes->l3_mask,
5414 DRV_LOG(ERR, "port %u invalid flow type%d",
5415 dev->data->port_id, fdir_filter->input.flow_type);
5416 rte_errno = ENOTSUP;
5420 switch (fdir_filter->input.flow_type) {
5421 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
5422 attributes->l4.udp.hdr = (struct rte_udp_hdr){
5423 .src_port = input->flow.udp4_flow.src_port,
5424 .dst_port = input->flow.udp4_flow.dst_port,
5426 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
5427 .src_port = mask->src_port_mask,
5428 .dst_port = mask->dst_port_mask,
5430 attributes->items[2] = (struct rte_flow_item){
5431 .type = RTE_FLOW_ITEM_TYPE_UDP,
5432 .spec = &attributes->l4,
5433 .mask = &attributes->l4_mask,
5436 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
5437 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
5438 .src_port = input->flow.tcp4_flow.src_port,
5439 .dst_port = input->flow.tcp4_flow.dst_port,
5441 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
5442 .src_port = mask->src_port_mask,
5443 .dst_port = mask->dst_port_mask,
5445 attributes->items[2] = (struct rte_flow_item){
5446 .type = RTE_FLOW_ITEM_TYPE_TCP,
5447 .spec = &attributes->l4,
5448 .mask = &attributes->l4_mask,
5451 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
5452 attributes->l4.udp.hdr = (struct rte_udp_hdr){
5453 .src_port = input->flow.udp6_flow.src_port,
5454 .dst_port = input->flow.udp6_flow.dst_port,
5456 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
5457 .src_port = mask->src_port_mask,
5458 .dst_port = mask->dst_port_mask,
5460 attributes->items[2] = (struct rte_flow_item){
5461 .type = RTE_FLOW_ITEM_TYPE_UDP,
5462 .spec = &attributes->l4,
5463 .mask = &attributes->l4_mask,
5466 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
5467 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
5468 .src_port = input->flow.tcp6_flow.src_port,
5469 .dst_port = input->flow.tcp6_flow.dst_port,
5471 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
5472 .src_port = mask->src_port_mask,
5473 .dst_port = mask->dst_port_mask,
5475 attributes->items[2] = (struct rte_flow_item){
5476 .type = RTE_FLOW_ITEM_TYPE_TCP,
5477 .spec = &attributes->l4,
5478 .mask = &attributes->l4_mask,
5481 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
5482 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
5485 DRV_LOG(ERR, "port %u invalid flow type%d",
5486 dev->data->port_id, fdir_filter->input.flow_type);
5487 rte_errno = ENOTSUP;
5493 #define FLOW_FDIR_CMP(f1, f2, fld) \
5494 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
5497 * Compare two FDIR flows. If items and actions are identical, the two flows are
5501 * Pointer to Ethernet device.
5503 * FDIR flow to compare.
5505 * FDIR flow to compare.
5508 * Zero on match, 1 otherwise.
5511 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
5513 if (FLOW_FDIR_CMP(f1, f2, attr) ||
5514 FLOW_FDIR_CMP(f1, f2, l2) ||
5515 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
5516 FLOW_FDIR_CMP(f1, f2, l3) ||
5517 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
5518 FLOW_FDIR_CMP(f1, f2, l4) ||
5519 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
5520 FLOW_FDIR_CMP(f1, f2, actions[0].type))
5522 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
5523 FLOW_FDIR_CMP(f1, f2, queue))
5529 * Search device flow list to find out a matched FDIR flow.
5532 * Pointer to Ethernet device.
5534 * FDIR flow to lookup.
5537 * Index of flow if found, 0 otherwise.
5540 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
5542 struct mlx5_priv *priv = dev->data->dev_private;
5543 uint32_t flow_idx = 0;
5544 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5546 MLX5_ASSERT(fdir_flow);
5547 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
5548 if (!flow_fdir_cmp(priv_fdir_flow->fdir, fdir_flow)) {
5549 DRV_LOG(DEBUG, "port %u found FDIR flow %u",
5550 dev->data->port_id, flow_idx);
5551 flow_idx = priv_fdir_flow->rix_flow;
5559 * Add new flow director filter and store it in list.
5562 * Pointer to Ethernet device.
5563 * @param fdir_filter
5564 * Flow director filter to add.
5567 * 0 on success, a negative errno value otherwise and rte_errno is set.
5570 flow_fdir_filter_add(struct rte_eth_dev *dev,
5571 const struct rte_eth_fdir_filter *fdir_filter)
5573 struct mlx5_priv *priv = dev->data->dev_private;
5574 struct mlx5_fdir *fdir_flow;
5575 struct rte_flow *flow;
5576 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5580 fdir_flow = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*fdir_flow), 0,
5586 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
5589 flow_idx = flow_fdir_filter_lookup(dev, fdir_flow);
5594 priv_fdir_flow = mlx5_malloc(MLX5_MEM_ZERO,
5595 sizeof(struct mlx5_fdir_flow),
5597 if (!priv_fdir_flow) {
5601 flow_idx = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
5602 fdir_flow->items, fdir_flow->actions, true,
5604 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5608 priv_fdir_flow->fdir = fdir_flow;
5609 priv_fdir_flow->rix_flow = flow_idx;
5610 LIST_INSERT_HEAD(&priv->fdir_flows, priv_fdir_flow, next);
5611 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
5612 dev->data->port_id, (void *)flow);
5615 mlx5_free(priv_fdir_flow);
5616 mlx5_free(fdir_flow);
5621 * Delete specific filter.
5624 * Pointer to Ethernet device.
5625 * @param fdir_filter
5626 * Filter to be deleted.
5629 * 0 on success, a negative errno value otherwise and rte_errno is set.
5632 flow_fdir_filter_delete(struct rte_eth_dev *dev,
5633 const struct rte_eth_fdir_filter *fdir_filter)
5635 struct mlx5_priv *priv = dev->data->dev_private;
5637 struct mlx5_fdir fdir_flow = {
5640 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5643 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
5646 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
5647 /* Find the fdir in priv list */
5648 if (!flow_fdir_cmp(priv_fdir_flow->fdir, &fdir_flow))
5651 if (!priv_fdir_flow)
5653 LIST_REMOVE(priv_fdir_flow, next);
5654 flow_idx = priv_fdir_flow->rix_flow;
5655 flow_list_destroy(dev, &priv->flows, flow_idx);
5656 mlx5_free(priv_fdir_flow->fdir);
5657 mlx5_free(priv_fdir_flow);
5658 DRV_LOG(DEBUG, "port %u deleted FDIR flow %u",
5659 dev->data->port_id, flow_idx);
5664 * Update queue for specific filter.
5667 * Pointer to Ethernet device.
5668 * @param fdir_filter
5669 * Filter to be updated.
5672 * 0 on success, a negative errno value otherwise and rte_errno is set.
5675 flow_fdir_filter_update(struct rte_eth_dev *dev,
5676 const struct rte_eth_fdir_filter *fdir_filter)
5680 ret = flow_fdir_filter_delete(dev, fdir_filter);
5683 return flow_fdir_filter_add(dev, fdir_filter);
5687 * Flush all filters.
5690 * Pointer to Ethernet device.
5693 flow_fdir_filter_flush(struct rte_eth_dev *dev)
5695 struct mlx5_priv *priv = dev->data->dev_private;
5696 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5698 while (!LIST_EMPTY(&priv->fdir_flows)) {
5699 priv_fdir_flow = LIST_FIRST(&priv->fdir_flows);
5700 LIST_REMOVE(priv_fdir_flow, next);
5701 flow_list_destroy(dev, &priv->flows, priv_fdir_flow->rix_flow);
5702 mlx5_free(priv_fdir_flow->fdir);
5703 mlx5_free(priv_fdir_flow);
5708 * Get flow director information.
5711 * Pointer to Ethernet device.
5712 * @param[out] fdir_info
5713 * Resulting flow director information.
5716 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
5718 struct rte_eth_fdir_masks *mask =
5719 &dev->data->dev_conf.fdir_conf.mask;
5721 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
5722 fdir_info->guarant_spc = 0;
5723 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
5724 fdir_info->max_flexpayload = 0;
5725 fdir_info->flow_types_mask[0] = 0;
5726 fdir_info->flex_payload_unit = 0;
5727 fdir_info->max_flex_payload_segment_num = 0;
5728 fdir_info->flex_payload_limit = 0;
5729 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
5733 * Deal with flow director operations.
5736 * Pointer to Ethernet device.
5738 * Operation to perform.
5740 * Pointer to operation-specific structure.
5743 * 0 on success, a negative errno value otherwise and rte_errno is set.
5746 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
5749 enum rte_fdir_mode fdir_mode =
5750 dev->data->dev_conf.fdir_conf.mode;
5752 if (filter_op == RTE_ETH_FILTER_NOP)
5754 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
5755 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5756 DRV_LOG(ERR, "port %u flow director mode %d not supported",
5757 dev->data->port_id, fdir_mode);
5761 switch (filter_op) {
5762 case RTE_ETH_FILTER_ADD:
5763 return flow_fdir_filter_add(dev, arg);
5764 case RTE_ETH_FILTER_UPDATE:
5765 return flow_fdir_filter_update(dev, arg);
5766 case RTE_ETH_FILTER_DELETE:
5767 return flow_fdir_filter_delete(dev, arg);
5768 case RTE_ETH_FILTER_FLUSH:
5769 flow_fdir_filter_flush(dev);
5771 case RTE_ETH_FILTER_INFO:
5772 flow_fdir_info_get(dev, arg);
5775 DRV_LOG(DEBUG, "port %u unknown operation %u",
5776 dev->data->port_id, filter_op);
5784 * Manage filter operations.
5787 * Pointer to Ethernet device structure.
5788 * @param filter_type
5791 * Operation to perform.
5793 * Pointer to operation-specific structure.
5796 * 0 on success, a negative errno value otherwise and rte_errno is set.
5799 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
5800 enum rte_filter_type filter_type,
5801 enum rte_filter_op filter_op,
5804 switch (filter_type) {
5805 case RTE_ETH_FILTER_GENERIC:
5806 if (filter_op != RTE_ETH_FILTER_GET) {
5810 *(const void **)arg = &mlx5_flow_ops;
5812 case RTE_ETH_FILTER_FDIR:
5813 return flow_fdir_ctrl_func(dev, filter_op, arg);
5815 DRV_LOG(ERR, "port %u filter type (%d) not supported",
5816 dev->data->port_id, filter_type);
5817 rte_errno = ENOTSUP;
5824 * Create the needed meter and suffix tables.
5827 * Pointer to Ethernet device.
5829 * Pointer to the flow meter.
5832 * Pointer to table set on success, NULL otherwise.
5834 struct mlx5_meter_domains_infos *
5835 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
5836 const struct mlx5_flow_meter *fm)
5838 const struct mlx5_flow_driver_ops *fops;
5840 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5841 return fops->create_mtr_tbls(dev, fm);
5845 * Destroy the meter table set.
5848 * Pointer to Ethernet device.
5850 * Pointer to the meter table set.
5856 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
5857 struct mlx5_meter_domains_infos *tbls)
5859 const struct mlx5_flow_driver_ops *fops;
5861 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5862 return fops->destroy_mtr_tbls(dev, tbls);
5866 * Create policer rules.
5869 * Pointer to Ethernet device.
5871 * Pointer to flow meter structure.
5873 * Pointer to flow attributes.
5876 * 0 on success, -1 otherwise.
5879 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
5880 struct mlx5_flow_meter *fm,
5881 const struct rte_flow_attr *attr)
5883 const struct mlx5_flow_driver_ops *fops;
5885 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5886 return fops->create_policer_rules(dev, fm, attr);
5890 * Destroy policer rules.
5893 * Pointer to flow meter structure.
5895 * Pointer to flow attributes.
5898 * 0 on success, -1 otherwise.
5901 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
5902 struct mlx5_flow_meter *fm,
5903 const struct rte_flow_attr *attr)
5905 const struct mlx5_flow_driver_ops *fops;
5907 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5908 return fops->destroy_policer_rules(dev, fm, attr);
5912 * Allocate a counter.
5915 * Pointer to Ethernet device structure.
5918 * Index to allocated counter on success, 0 otherwise.
5921 mlx5_counter_alloc(struct rte_eth_dev *dev)
5923 const struct mlx5_flow_driver_ops *fops;
5924 struct rte_flow_attr attr = { .transfer = 0 };
5926 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5927 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5928 return fops->counter_alloc(dev);
5931 "port %u counter allocate is not supported.",
5932 dev->data->port_id);
5940 * Pointer to Ethernet device structure.
5942 * Index to counter to be free.
5945 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
5947 const struct mlx5_flow_driver_ops *fops;
5948 struct rte_flow_attr attr = { .transfer = 0 };
5950 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5951 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5952 fops->counter_free(dev, cnt);
5956 "port %u counter free is not supported.",
5957 dev->data->port_id);
5961 * Query counter statistics.
5964 * Pointer to Ethernet device structure.
5966 * Index to counter to query.
5968 * Set to clear counter statistics.
5970 * The counter hits packets number to save.
5972 * The counter hits bytes number to save.
5975 * 0 on success, a negative errno value otherwise.
5978 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
5979 bool clear, uint64_t *pkts, uint64_t *bytes)
5981 const struct mlx5_flow_driver_ops *fops;
5982 struct rte_flow_attr attr = { .transfer = 0 };
5984 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5985 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5986 return fops->counter_query(dev, cnt, clear, pkts, bytes);
5989 "port %u counter query is not supported.",
5990 dev->data->port_id);
5994 #define MLX5_POOL_QUERY_FREQ_US 1000000
5997 * Get number of all validate pools.
6000 * Pointer to mlx5_dev_ctx_shared object.
6003 * The number of all validate pools.
6006 mlx5_get_all_valid_pool_count(struct mlx5_dev_ctx_shared *sh)
6009 uint32_t pools_n = 0;
6011 for (i = 0; i < MLX5_CCONT_TYPE_MAX; ++i)
6012 pools_n += rte_atomic16_read(&sh->cmng.ccont[i].n_valid);
6017 * Set the periodic procedure for triggering asynchronous batch queries for all
6018 * the counter pools.
6021 * Pointer to mlx5_dev_ctx_shared object.
6024 mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
6026 uint32_t pools_n, us;
6028 pools_n = mlx5_get_all_valid_pool_count(sh);
6029 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
6030 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
6031 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
6032 sh->cmng.query_thread_on = 0;
6033 DRV_LOG(ERR, "Cannot reinitialize query alarm");
6035 sh->cmng.query_thread_on = 1;
6040 * The periodic procedure for triggering asynchronous batch queries for all the
6041 * counter pools. This function is probably called by the host thread.
6044 * The parameter for the alarm process.
6047 mlx5_flow_query_alarm(void *arg)
6049 struct mlx5_dev_ctx_shared *sh = arg;
6050 struct mlx5_devx_obj *dcs;
6053 uint8_t batch = sh->cmng.batch;
6054 uint8_t age = sh->cmng.age;
6055 uint16_t pool_index = sh->cmng.pool_index;
6056 struct mlx5_pools_container *cont;
6057 struct mlx5_flow_counter_pool *pool;
6058 int cont_loop = MLX5_CCONT_TYPE_MAX;
6060 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
6063 cont = MLX5_CNT_CONTAINER(sh, batch, age);
6064 rte_spinlock_lock(&cont->resize_sl);
6066 rte_spinlock_unlock(&cont->resize_sl);
6067 /* Check if all the containers are empty. */
6068 if (unlikely(--cont_loop == 0))
6072 if (batch == 0 && pool_index == 0) {
6074 sh->cmng.batch = batch;
6077 goto next_container;
6079 pool = cont->pools[pool_index];
6080 rte_spinlock_unlock(&cont->resize_sl);
6082 /* There is a pool query in progress. */
6085 LIST_FIRST(&sh->cmng.free_stat_raws);
6087 /* No free counter statistics raw memory. */
6089 dcs = (struct mlx5_devx_obj *)(uintptr_t)rte_atomic64_read
6091 offset = batch ? 0 : dcs->id % MLX5_COUNTERS_PER_POOL;
6093 * Identify the counters released between query trigger and query
6094 * handle more effiecntly. The counter released in this gap period
6095 * should wait for a new round of query as the new arrived packets
6096 * will not be taken into account.
6099 ret = mlx5_devx_cmd_flow_counter_query(dcs, 0, MLX5_COUNTERS_PER_POOL -
6101 pool->raw_hw->mem_mng->dm->id,
6103 (pool->raw_hw->data + offset),
6105 (uint64_t)(uintptr_t)pool);
6107 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
6108 " %d", pool->min_dcs->id);
6109 pool->raw_hw = NULL;
6112 pool->raw_hw->min_dcs_id = dcs->id;
6113 LIST_REMOVE(pool->raw_hw, next);
6114 sh->cmng.pending_queries++;
6116 if (pool_index >= rte_atomic16_read(&cont->n_valid)) {
6119 if (batch == 0 && pool_index == 0)
6123 sh->cmng.batch = batch;
6124 sh->cmng.pool_index = pool_index;
6126 mlx5_set_query_alarm(sh);
6130 * Check and callback event for new aged flow in the counter pool
6133 * Pointer to mlx5_dev_ctx_shared object.
6135 * Pointer to Current counter pool.
6138 mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
6139 struct mlx5_flow_counter_pool *pool)
6141 struct mlx5_priv *priv;
6142 struct mlx5_flow_counter *cnt;
6143 struct mlx5_age_info *age_info;
6144 struct mlx5_age_param *age_param;
6145 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
6146 struct mlx5_counter_stats_raw *prev = pool->raw;
6147 uint16_t curr = rte_rdtsc() / (rte_get_tsc_hz() / 10);
6150 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
6151 cnt = MLX5_POOL_GET_CNT(pool, i);
6152 age_param = MLX5_CNT_TO_AGE(cnt);
6153 if (rte_atomic16_read(&age_param->state) != AGE_CANDIDATE)
6155 if (cur->data[i].hits != prev->data[i].hits) {
6156 age_param->expire = curr + age_param->timeout;
6159 if ((uint16_t)(curr - age_param->expire) >= (UINT16_MAX / 2))
6162 * Hold the lock first, or if between the
6163 * state AGE_TMOUT and tailq operation the
6164 * release happened, the release procedure
6165 * may delete a non-existent tailq node.
6167 priv = rte_eth_devices[age_param->port_id].data->dev_private;
6168 age_info = GET_PORT_AGE_INFO(priv);
6169 rte_spinlock_lock(&age_info->aged_sl);
6170 /* If the cpmset fails, release happens. */
6171 if (rte_atomic16_cmpset((volatile uint16_t *)
6176 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
6177 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
6179 rte_spinlock_unlock(&age_info->aged_sl);
6181 for (i = 0; i < sh->max_port; i++) {
6182 age_info = &sh->port[i].age_info;
6183 if (!MLX5_AGE_GET(age_info, MLX5_AGE_EVENT_NEW))
6185 if (MLX5_AGE_GET(age_info, MLX5_AGE_TRIGGER))
6186 _rte_eth_dev_callback_process
6187 (&rte_eth_devices[sh->port[i].devx_ih_port_id],
6188 RTE_ETH_EVENT_FLOW_AGED, NULL);
6189 age_info->flags = 0;
6194 * Handler for the HW respond about ready values from an asynchronous batch
6195 * query. This function is probably called by the host thread.
6198 * The pointer to the shared device context.
6199 * @param[in] async_id
6200 * The Devx async ID.
6202 * The status of the completion.
6205 mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
6206 uint64_t async_id, int status)
6208 struct mlx5_flow_counter_pool *pool =
6209 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
6210 struct mlx5_counter_stats_raw *raw_to_free;
6211 uint8_t age = !!IS_AGE_POOL(pool);
6212 uint8_t query_gen = pool->query_gen ^ 1;
6213 struct mlx5_pools_container *cont =
6214 MLX5_CNT_CONTAINER(sh, !IS_EXT_POOL(pool), age);
6216 if (unlikely(status)) {
6217 raw_to_free = pool->raw_hw;
6219 raw_to_free = pool->raw;
6220 if (IS_AGE_POOL(pool))
6221 mlx5_flow_aging_check(sh, pool);
6222 rte_spinlock_lock(&pool->sl);
6223 pool->raw = pool->raw_hw;
6224 rte_spinlock_unlock(&pool->sl);
6225 /* Be sure the new raw counters data is updated in memory. */
6227 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
6228 rte_spinlock_lock(&cont->csl);
6229 TAILQ_CONCAT(&cont->counters,
6230 &pool->counters[query_gen], next);
6231 rte_spinlock_unlock(&cont->csl);
6234 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
6235 pool->raw_hw = NULL;
6236 sh->cmng.pending_queries--;
6240 * Translate the rte_flow group index to HW table value.
6242 * @param[in] attributes
6243 * Pointer to flow attributes
6244 * @param[in] external
6245 * Value is part of flow rule created by request external to PMD.
6247 * rte_flow group index value.
6248 * @param[out] fdb_def_rule
6249 * Whether fdb jump to table 1 is configured.
6253 * Pointer to error structure.
6256 * 0 on success, a negative errno value otherwise and rte_errno is set.
6259 mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, bool external,
6260 uint32_t group, bool fdb_def_rule, uint32_t *table,
6261 struct rte_flow_error *error)
6263 if (attributes->transfer && external && fdb_def_rule) {
6264 if (group == UINT32_MAX)
6265 return rte_flow_error_set
6267 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6269 "group index not supported");
6278 * Discover availability of metadata reg_c's.
6280 * Iteratively use test flows to check availability.
6283 * Pointer to the Ethernet device structure.
6286 * 0 on success, a negative errno value otherwise and rte_errno is set.
6289 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
6291 struct mlx5_priv *priv = dev->data->dev_private;
6292 struct mlx5_dev_config *config = &priv->config;
6293 enum modify_reg idx;
6296 /* reg_c[0] and reg_c[1] are reserved. */
6297 config->flow_mreg_c[n++] = REG_C_0;
6298 config->flow_mreg_c[n++] = REG_C_1;
6299 /* Discover availability of other reg_c's. */
6300 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
6301 struct rte_flow_attr attr = {
6302 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
6303 .priority = MLX5_FLOW_PRIO_RSVD,
6306 struct rte_flow_item items[] = {
6308 .type = RTE_FLOW_ITEM_TYPE_END,
6311 struct rte_flow_action actions[] = {
6313 .type = (enum rte_flow_action_type)
6314 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6315 .conf = &(struct mlx5_flow_action_copy_mreg){
6321 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6322 .conf = &(struct rte_flow_action_jump){
6323 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
6327 .type = RTE_FLOW_ACTION_TYPE_END,
6331 struct rte_flow *flow;
6332 struct rte_flow_error error;
6334 if (!config->dv_flow_en)
6336 /* Create internal flow, validation skips copy action. */
6337 flow_idx = flow_list_create(dev, NULL, &attr, items,
6338 actions, false, &error);
6339 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
6343 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
6344 config->flow_mreg_c[n++] = idx;
6345 flow_list_destroy(dev, NULL, flow_idx);
6347 for (; n < MLX5_MREG_C_NUM; ++n)
6348 config->flow_mreg_c[n] = REG_NONE;
6353 * Dump flow raw hw data to file
6356 * The pointer to Ethernet device.
6358 * A pointer to a file for output.
6360 * Perform verbose error reporting if not NULL. PMDs initialize this
6361 * structure in case of error only.
6363 * 0 on success, a nagative value otherwise.
6366 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
6368 struct rte_flow_error *error __rte_unused)
6370 struct mlx5_priv *priv = dev->data->dev_private;
6371 struct mlx5_dev_ctx_shared *sh = priv->sh;
6373 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
6374 sh->tx_domain, file);
6378 * Get aged-out flows.
6381 * Pointer to the Ethernet device structure.
6382 * @param[in] context
6383 * The address of an array of pointers to the aged-out flows contexts.
6384 * @param[in] nb_countexts
6385 * The length of context array pointers.
6387 * Perform verbose error reporting if not NULL. Initialized in case of
6391 * how many contexts get in success, otherwise negative errno value.
6392 * if nb_contexts is 0, return the amount of all aged contexts.
6393 * if nb_contexts is not 0 , return the amount of aged flows reported
6394 * in the context array.
6397 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
6398 uint32_t nb_contexts, struct rte_flow_error *error)
6400 const struct mlx5_flow_driver_ops *fops;
6401 struct rte_flow_attr attr = { .transfer = 0 };
6403 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6404 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6405 return fops->get_aged_flows(dev, contexts, nb_contexts,
6409 "port %u get aged flows is not supported.",
6410 dev->data->port_id);