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>
36 #include "mlx5_defs.h"
38 #include "mlx5_flow.h"
39 #include "mlx5_rxtx.h"
41 /* Dev ops structure defined in mlx5.c */
42 extern const struct eth_dev_ops mlx5_dev_ops;
43 extern const struct eth_dev_ops mlx5_dev_ops_isolate;
45 /** Device flow drivers. */
46 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
47 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
49 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
51 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
53 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
54 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
55 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
56 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
58 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
59 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
64 MLX5_EXPANSION_ROOT_OUTER,
65 MLX5_EXPANSION_ROOT_ETH_VLAN,
66 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
67 MLX5_EXPANSION_OUTER_ETH,
68 MLX5_EXPANSION_OUTER_ETH_VLAN,
69 MLX5_EXPANSION_OUTER_VLAN,
70 MLX5_EXPANSION_OUTER_IPV4,
71 MLX5_EXPANSION_OUTER_IPV4_UDP,
72 MLX5_EXPANSION_OUTER_IPV4_TCP,
73 MLX5_EXPANSION_OUTER_IPV6,
74 MLX5_EXPANSION_OUTER_IPV6_UDP,
75 MLX5_EXPANSION_OUTER_IPV6_TCP,
77 MLX5_EXPANSION_VXLAN_GPE,
81 MLX5_EXPANSION_ETH_VLAN,
84 MLX5_EXPANSION_IPV4_UDP,
85 MLX5_EXPANSION_IPV4_TCP,
87 MLX5_EXPANSION_IPV6_UDP,
88 MLX5_EXPANSION_IPV6_TCP,
91 /** Supported expansion of items. */
92 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
93 [MLX5_EXPANSION_ROOT] = {
94 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
97 .type = RTE_FLOW_ITEM_TYPE_END,
99 [MLX5_EXPANSION_ROOT_OUTER] = {
100 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
101 MLX5_EXPANSION_OUTER_IPV4,
102 MLX5_EXPANSION_OUTER_IPV6),
103 .type = RTE_FLOW_ITEM_TYPE_END,
105 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
106 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
107 .type = RTE_FLOW_ITEM_TYPE_END,
109 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
110 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
111 .type = RTE_FLOW_ITEM_TYPE_END,
113 [MLX5_EXPANSION_OUTER_ETH] = {
114 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
115 MLX5_EXPANSION_OUTER_IPV6,
116 MLX5_EXPANSION_MPLS),
117 .type = RTE_FLOW_ITEM_TYPE_ETH,
120 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
121 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
122 .type = RTE_FLOW_ITEM_TYPE_ETH,
125 [MLX5_EXPANSION_OUTER_VLAN] = {
126 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
127 MLX5_EXPANSION_OUTER_IPV6),
128 .type = RTE_FLOW_ITEM_TYPE_VLAN,
130 [MLX5_EXPANSION_OUTER_IPV4] = {
131 .next = RTE_FLOW_EXPAND_RSS_NEXT
132 (MLX5_EXPANSION_OUTER_IPV4_UDP,
133 MLX5_EXPANSION_OUTER_IPV4_TCP,
136 MLX5_EXPANSION_IPV6),
137 .type = RTE_FLOW_ITEM_TYPE_IPV4,
138 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
139 ETH_RSS_NONFRAG_IPV4_OTHER,
141 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
142 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
143 MLX5_EXPANSION_VXLAN_GPE),
144 .type = RTE_FLOW_ITEM_TYPE_UDP,
145 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
147 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
148 .type = RTE_FLOW_ITEM_TYPE_TCP,
149 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
151 [MLX5_EXPANSION_OUTER_IPV6] = {
152 .next = RTE_FLOW_EXPAND_RSS_NEXT
153 (MLX5_EXPANSION_OUTER_IPV6_UDP,
154 MLX5_EXPANSION_OUTER_IPV6_TCP,
156 MLX5_EXPANSION_IPV6),
157 .type = RTE_FLOW_ITEM_TYPE_IPV6,
158 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
159 ETH_RSS_NONFRAG_IPV6_OTHER,
161 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
162 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
163 MLX5_EXPANSION_VXLAN_GPE),
164 .type = RTE_FLOW_ITEM_TYPE_UDP,
165 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
167 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
168 .type = RTE_FLOW_ITEM_TYPE_TCP,
169 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
171 [MLX5_EXPANSION_VXLAN] = {
172 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
174 MLX5_EXPANSION_IPV6),
175 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
177 [MLX5_EXPANSION_VXLAN_GPE] = {
178 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
180 MLX5_EXPANSION_IPV6),
181 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
183 [MLX5_EXPANSION_GRE] = {
184 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
185 .type = RTE_FLOW_ITEM_TYPE_GRE,
187 [MLX5_EXPANSION_MPLS] = {
188 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
189 MLX5_EXPANSION_IPV6),
190 .type = RTE_FLOW_ITEM_TYPE_MPLS,
192 [MLX5_EXPANSION_ETH] = {
193 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
194 MLX5_EXPANSION_IPV6),
195 .type = RTE_FLOW_ITEM_TYPE_ETH,
197 [MLX5_EXPANSION_ETH_VLAN] = {
198 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
199 .type = RTE_FLOW_ITEM_TYPE_ETH,
201 [MLX5_EXPANSION_VLAN] = {
202 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
203 MLX5_EXPANSION_IPV6),
204 .type = RTE_FLOW_ITEM_TYPE_VLAN,
206 [MLX5_EXPANSION_IPV4] = {
207 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
208 MLX5_EXPANSION_IPV4_TCP),
209 .type = RTE_FLOW_ITEM_TYPE_IPV4,
210 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
211 ETH_RSS_NONFRAG_IPV4_OTHER,
213 [MLX5_EXPANSION_IPV4_UDP] = {
214 .type = RTE_FLOW_ITEM_TYPE_UDP,
215 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
217 [MLX5_EXPANSION_IPV4_TCP] = {
218 .type = RTE_FLOW_ITEM_TYPE_TCP,
219 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
221 [MLX5_EXPANSION_IPV6] = {
222 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
223 MLX5_EXPANSION_IPV6_TCP),
224 .type = RTE_FLOW_ITEM_TYPE_IPV6,
225 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
226 ETH_RSS_NONFRAG_IPV6_OTHER,
228 [MLX5_EXPANSION_IPV6_UDP] = {
229 .type = RTE_FLOW_ITEM_TYPE_UDP,
230 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
232 [MLX5_EXPANSION_IPV6_TCP] = {
233 .type = RTE_FLOW_ITEM_TYPE_TCP,
234 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
238 static const struct rte_flow_ops mlx5_flow_ops = {
239 .validate = mlx5_flow_validate,
240 .create = mlx5_flow_create,
241 .destroy = mlx5_flow_destroy,
242 .flush = mlx5_flow_flush,
243 .isolate = mlx5_flow_isolate,
244 .query = mlx5_flow_query,
245 .dev_dump = mlx5_flow_dev_dump,
246 .get_aged_flows = mlx5_flow_get_aged_flows,
249 /* Convert FDIR request to Generic flow. */
251 struct rte_flow_attr attr;
252 struct rte_flow_item items[4];
253 struct rte_flow_item_eth l2;
254 struct rte_flow_item_eth l2_mask;
256 struct rte_flow_item_ipv4 ipv4;
257 struct rte_flow_item_ipv6 ipv6;
260 struct rte_flow_item_ipv4 ipv4;
261 struct rte_flow_item_ipv6 ipv6;
264 struct rte_flow_item_udp udp;
265 struct rte_flow_item_tcp tcp;
268 struct rte_flow_item_udp udp;
269 struct rte_flow_item_tcp tcp;
271 struct rte_flow_action actions[2];
272 struct rte_flow_action_queue queue;
275 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
276 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
277 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
280 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
281 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
282 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
283 { 9, 10, 11 }, { 12, 13, 14 },
286 /* Tunnel information. */
287 struct mlx5_flow_tunnel_info {
288 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
289 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
292 static struct mlx5_flow_tunnel_info tunnels_info[] = {
294 .tunnel = MLX5_FLOW_LAYER_VXLAN,
295 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
298 .tunnel = MLX5_FLOW_LAYER_GENEVE,
299 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
302 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
303 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
306 .tunnel = MLX5_FLOW_LAYER_GRE,
307 .ptype = RTE_PTYPE_TUNNEL_GRE,
310 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
311 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
314 .tunnel = MLX5_FLOW_LAYER_MPLS,
315 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
318 .tunnel = MLX5_FLOW_LAYER_NVGRE,
319 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
322 .tunnel = MLX5_FLOW_LAYER_IPIP,
323 .ptype = RTE_PTYPE_TUNNEL_IP,
326 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
327 .ptype = RTE_PTYPE_TUNNEL_IP,
330 .tunnel = MLX5_FLOW_LAYER_GTP,
331 .ptype = RTE_PTYPE_TUNNEL_GTPU,
336 * Translate tag ID to register.
339 * Pointer to the Ethernet device structure.
341 * The feature that request the register.
343 * The request register ID.
345 * Error description in case of any.
348 * The request register on success, a negative errno
349 * value otherwise and rte_errno is set.
352 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
353 enum mlx5_feature_name feature,
355 struct rte_flow_error *error)
357 struct mlx5_priv *priv = dev->data->dev_private;
358 struct mlx5_dev_config *config = &priv->config;
359 enum modify_reg start_reg;
360 bool skip_mtr_reg = false;
363 case MLX5_HAIRPIN_RX:
365 case MLX5_HAIRPIN_TX:
367 case MLX5_METADATA_RX:
368 switch (config->dv_xmeta_en) {
369 case MLX5_XMETA_MODE_LEGACY:
371 case MLX5_XMETA_MODE_META16:
373 case MLX5_XMETA_MODE_META32:
377 case MLX5_METADATA_TX:
379 case MLX5_METADATA_FDB:
380 switch (config->dv_xmeta_en) {
381 case MLX5_XMETA_MODE_LEGACY:
383 case MLX5_XMETA_MODE_META16:
385 case MLX5_XMETA_MODE_META32:
390 switch (config->dv_xmeta_en) {
391 case MLX5_XMETA_MODE_LEGACY:
393 case MLX5_XMETA_MODE_META16:
395 case MLX5_XMETA_MODE_META32:
401 * If meter color and flow match share one register, flow match
402 * should use the meter color register for match.
404 if (priv->mtr_reg_share)
405 return priv->mtr_color_reg;
407 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
410 MLX5_ASSERT(priv->mtr_color_reg != REG_NONE);
411 return priv->mtr_color_reg;
414 * Metadata COPY_MARK register using is in meter suffix sub
415 * flow while with meter. It's safe to share the same register.
417 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
420 * If meter is enable, it will engage the register for color
421 * match and flow match. If meter color match is not using the
422 * REG_C_2, need to skip the REG_C_x be used by meter color
424 * If meter is disable, free to use all available registers.
426 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
427 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
428 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
429 if (id > (REG_C_7 - start_reg))
430 return rte_flow_error_set(error, EINVAL,
431 RTE_FLOW_ERROR_TYPE_ITEM,
432 NULL, "invalid tag id");
433 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NONE)
434 return rte_flow_error_set(error, ENOTSUP,
435 RTE_FLOW_ERROR_TYPE_ITEM,
436 NULL, "unsupported tag id");
438 * This case means meter is using the REG_C_x great than 2.
439 * Take care not to conflict with meter color REG_C_x.
440 * If the available index REG_C_y >= REG_C_x, skip the
443 if (skip_mtr_reg && config->flow_mreg_c
444 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
445 if (id >= (REG_C_7 - start_reg))
446 return rte_flow_error_set(error, EINVAL,
447 RTE_FLOW_ERROR_TYPE_ITEM,
448 NULL, "invalid tag id");
449 if (config->flow_mreg_c
450 [id + 1 + start_reg - REG_C_0] != REG_NONE)
451 return config->flow_mreg_c
452 [id + 1 + start_reg - REG_C_0];
453 return rte_flow_error_set(error, ENOTSUP,
454 RTE_FLOW_ERROR_TYPE_ITEM,
455 NULL, "unsupported tag id");
457 return config->flow_mreg_c[id + start_reg - REG_C_0];
460 return rte_flow_error_set(error, EINVAL,
461 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
462 NULL, "invalid feature name");
466 * Check extensive flow metadata register support.
469 * Pointer to rte_eth_dev structure.
472 * True if device supports extensive flow metadata register, otherwise false.
475 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
477 struct mlx5_priv *priv = dev->data->dev_private;
478 struct mlx5_dev_config *config = &priv->config;
481 * Having available reg_c can be regarded inclusively as supporting
482 * extensive flow metadata register, which could mean,
483 * - metadata register copy action by modify header.
484 * - 16 modify header actions is supported.
485 * - reg_c's are preserved across different domain (FDB and NIC) on
486 * packet loopback by flow lookup miss.
488 return config->flow_mreg_c[2] != REG_NONE;
492 * Discover the maximum number of priority available.
495 * Pointer to the Ethernet device structure.
498 * number of supported flow priority on success, a negative errno
499 * value otherwise and rte_errno is set.
502 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
504 struct mlx5_priv *priv = dev->data->dev_private;
506 struct ibv_flow_attr attr;
507 struct ibv_flow_spec_eth eth;
508 struct ibv_flow_spec_action_drop drop;
512 .port = (uint8_t)priv->ibv_port,
515 .type = IBV_FLOW_SPEC_ETH,
516 .size = sizeof(struct ibv_flow_spec_eth),
519 .size = sizeof(struct ibv_flow_spec_action_drop),
520 .type = IBV_FLOW_SPEC_ACTION_DROP,
523 struct ibv_flow *flow;
524 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
525 uint16_t vprio[] = { 8, 16 };
533 for (i = 0; i != RTE_DIM(vprio); i++) {
534 flow_attr.attr.priority = vprio[i] - 1;
535 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
538 claim_zero(mlx5_glue->destroy_flow(flow));
541 mlx5_hrxq_drop_release(dev);
544 priority = RTE_DIM(priority_map_3);
547 priority = RTE_DIM(priority_map_5);
552 "port %u verbs maximum priority: %d expected 8/16",
553 dev->data->port_id, priority);
556 DRV_LOG(INFO, "port %u flow maximum priority: %d",
557 dev->data->port_id, priority);
562 * Adjust flow priority based on the highest layer and the request priority.
565 * Pointer to the Ethernet device structure.
566 * @param[in] priority
567 * The rule base priority.
568 * @param[in] subpriority
569 * The priority based on the items.
574 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
575 uint32_t subpriority)
578 struct mlx5_priv *priv = dev->data->dev_private;
580 switch (priv->config.flow_prio) {
581 case RTE_DIM(priority_map_3):
582 res = priority_map_3[priority][subpriority];
584 case RTE_DIM(priority_map_5):
585 res = priority_map_5[priority][subpriority];
592 * Verify the @p item specifications (spec, last, mask) are compatible with the
596 * Item specification.
598 * @p item->mask or flow default bit-masks.
599 * @param[in] nic_mask
600 * Bit-masks covering supported fields by the NIC to compare with user mask.
602 * Bit-masks size in bytes.
604 * Pointer to error structure.
607 * 0 on success, a negative errno value otherwise and rte_errno is set.
610 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
612 const uint8_t *nic_mask,
614 struct rte_flow_error *error)
618 MLX5_ASSERT(nic_mask);
619 for (i = 0; i < size; ++i)
620 if ((nic_mask[i] | mask[i]) != nic_mask[i])
621 return rte_flow_error_set(error, ENOTSUP,
622 RTE_FLOW_ERROR_TYPE_ITEM,
624 "mask enables non supported"
626 if (!item->spec && (item->mask || item->last))
627 return rte_flow_error_set(error, EINVAL,
628 RTE_FLOW_ERROR_TYPE_ITEM, item,
629 "mask/last without a spec is not"
631 if (item->spec && item->last) {
637 for (i = 0; i < size; ++i) {
638 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
639 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
641 ret = memcmp(spec, last, size);
643 return rte_flow_error_set(error, EINVAL,
644 RTE_FLOW_ERROR_TYPE_ITEM,
646 "range is not valid");
652 * Adjust the hash fields according to the @p flow information.
654 * @param[in] dev_flow.
655 * Pointer to the mlx5_flow.
657 * 1 when the hash field is for a tunnel item.
658 * @param[in] layer_types
660 * @param[in] hash_fields
664 * The hash fields that should be used.
667 mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
668 int tunnel __rte_unused, uint64_t layer_types,
669 uint64_t hash_fields)
671 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
672 int rss_request_inner = rss_desc->level >= 2;
674 /* Check RSS hash level for tunnel. */
675 if (tunnel && rss_request_inner)
676 hash_fields |= IBV_RX_HASH_INNER;
677 else if (tunnel || rss_request_inner)
680 /* Check if requested layer matches RSS hash fields. */
681 if (!(rss_desc->types & layer_types))
687 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
688 * if several tunnel rules are used on this queue, the tunnel ptype will be
692 * Rx queue to update.
695 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
698 uint32_t tunnel_ptype = 0;
700 /* Look up for the ptype to use. */
701 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
702 if (!rxq_ctrl->flow_tunnels_n[i])
705 tunnel_ptype = tunnels_info[i].ptype;
711 rxq_ctrl->rxq.tunnel = tunnel_ptype;
715 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
719 * Pointer to the Ethernet device structure.
720 * @param[in] dev_handle
721 * Pointer to device flow handle structure.
724 flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
725 struct mlx5_flow_handle *dev_handle)
727 struct mlx5_priv *priv = dev->data->dev_private;
728 const int mark = dev_handle->mark;
729 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
730 struct mlx5_hrxq *hrxq;
733 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
735 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
736 dev_handle->rix_hrxq);
739 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
740 int idx = hrxq->ind_table->queues[i];
741 struct mlx5_rxq_ctrl *rxq_ctrl =
742 container_of((*priv->rxqs)[idx],
743 struct mlx5_rxq_ctrl, rxq);
746 * To support metadata register copy on Tx loopback,
747 * this must be always enabled (metadata may arive
748 * from other port - not from local flows only.
750 if (priv->config.dv_flow_en &&
751 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
752 mlx5_flow_ext_mreg_supported(dev)) {
753 rxq_ctrl->rxq.mark = 1;
754 rxq_ctrl->flow_mark_n = 1;
756 rxq_ctrl->rxq.mark = 1;
757 rxq_ctrl->flow_mark_n++;
762 /* Increase the counter matching the flow. */
763 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
764 if ((tunnels_info[j].tunnel &
765 dev_handle->layers) ==
766 tunnels_info[j].tunnel) {
767 rxq_ctrl->flow_tunnels_n[j]++;
771 flow_rxq_tunnel_ptype_update(rxq_ctrl);
777 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
780 * Pointer to the Ethernet device structure.
782 * Pointer to flow structure.
785 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
787 struct mlx5_priv *priv = dev->data->dev_private;
789 struct mlx5_flow_handle *dev_handle;
791 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
792 handle_idx, dev_handle, next)
793 flow_drv_rxq_flags_set(dev, dev_handle);
797 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
798 * device flow if no other flow uses it with the same kind of request.
801 * Pointer to Ethernet device.
802 * @param[in] dev_handle
803 * Pointer to the device flow handle structure.
806 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
807 struct mlx5_flow_handle *dev_handle)
809 struct mlx5_priv *priv = dev->data->dev_private;
810 const int mark = dev_handle->mark;
811 const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
812 struct mlx5_hrxq *hrxq;
815 if (dev_handle->fate_action != MLX5_FLOW_FATE_QUEUE)
817 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
818 dev_handle->rix_hrxq);
821 MLX5_ASSERT(dev->data->dev_started);
822 for (i = 0; i != hrxq->ind_table->queues_n; ++i) {
823 int idx = hrxq->ind_table->queues[i];
824 struct mlx5_rxq_ctrl *rxq_ctrl =
825 container_of((*priv->rxqs)[idx],
826 struct mlx5_rxq_ctrl, rxq);
828 if (priv->config.dv_flow_en &&
829 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
830 mlx5_flow_ext_mreg_supported(dev)) {
831 rxq_ctrl->rxq.mark = 1;
832 rxq_ctrl->flow_mark_n = 1;
834 rxq_ctrl->flow_mark_n--;
835 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
840 /* Decrease the counter matching the flow. */
841 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
842 if ((tunnels_info[j].tunnel &
843 dev_handle->layers) ==
844 tunnels_info[j].tunnel) {
845 rxq_ctrl->flow_tunnels_n[j]--;
849 flow_rxq_tunnel_ptype_update(rxq_ctrl);
855 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
856 * @p flow if no other flow uses it with the same kind of request.
859 * Pointer to Ethernet device.
861 * Pointer to the flow.
864 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
866 struct mlx5_priv *priv = dev->data->dev_private;
868 struct mlx5_flow_handle *dev_handle;
870 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
871 handle_idx, dev_handle, next)
872 flow_drv_rxq_flags_trim(dev, dev_handle);
876 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
879 * Pointer to Ethernet device.
882 flow_rxq_flags_clear(struct rte_eth_dev *dev)
884 struct mlx5_priv *priv = dev->data->dev_private;
887 for (i = 0; i != priv->rxqs_n; ++i) {
888 struct mlx5_rxq_ctrl *rxq_ctrl;
891 if (!(*priv->rxqs)[i])
893 rxq_ctrl = container_of((*priv->rxqs)[i],
894 struct mlx5_rxq_ctrl, rxq);
895 rxq_ctrl->flow_mark_n = 0;
896 rxq_ctrl->rxq.mark = 0;
897 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
898 rxq_ctrl->flow_tunnels_n[j] = 0;
899 rxq_ctrl->rxq.tunnel = 0;
904 * Set the Rx queue dynamic metadata (mask and offset) for a flow
907 * Pointer to the Ethernet device structure.
910 mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev)
912 struct mlx5_priv *priv = dev->data->dev_private;
913 struct mlx5_rxq_data *data;
916 for (i = 0; i != priv->rxqs_n; ++i) {
917 if (!(*priv->rxqs)[i])
919 data = (*priv->rxqs)[i];
920 if (!rte_flow_dynf_metadata_avail()) {
922 data->flow_meta_mask = 0;
923 data->flow_meta_offset = -1;
926 data->flow_meta_mask = rte_flow_dynf_metadata_mask;
927 data->flow_meta_offset = rte_flow_dynf_metadata_offs;
933 * return a pointer to the desired action in the list of actions.
936 * The list of actions to search the action in.
938 * The action to find.
941 * Pointer to the action in the list, if found. NULL otherwise.
943 const struct rte_flow_action *
944 mlx5_flow_find_action(const struct rte_flow_action *actions,
945 enum rte_flow_action_type action)
949 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
950 if (actions->type == action)
956 * Validate the flag action.
958 * @param[in] action_flags
959 * Bit-fields that holds the actions detected until now.
961 * Attributes of flow that includes this action.
963 * Pointer to error structure.
966 * 0 on success, a negative errno value otherwise and rte_errno is set.
969 mlx5_flow_validate_action_flag(uint64_t action_flags,
970 const struct rte_flow_attr *attr,
971 struct rte_flow_error *error)
973 if (action_flags & MLX5_FLOW_ACTION_MARK)
974 return rte_flow_error_set(error, EINVAL,
975 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
976 "can't mark and flag in same flow");
977 if (action_flags & MLX5_FLOW_ACTION_FLAG)
978 return rte_flow_error_set(error, EINVAL,
979 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
981 " actions in same flow");
983 return rte_flow_error_set(error, ENOTSUP,
984 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
985 "flag action not supported for "
991 * Validate the mark action.
994 * Pointer to the queue action.
995 * @param[in] action_flags
996 * Bit-fields that holds the actions detected until now.
998 * Attributes of flow that includes this action.
1000 * Pointer to error structure.
1003 * 0 on success, a negative errno value otherwise and rte_errno is set.
1006 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1007 uint64_t action_flags,
1008 const struct rte_flow_attr *attr,
1009 struct rte_flow_error *error)
1011 const struct rte_flow_action_mark *mark = action->conf;
1014 return rte_flow_error_set(error, EINVAL,
1015 RTE_FLOW_ERROR_TYPE_ACTION,
1017 "configuration cannot be null");
1018 if (mark->id >= MLX5_FLOW_MARK_MAX)
1019 return rte_flow_error_set(error, EINVAL,
1020 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1022 "mark id must in 0 <= id < "
1023 RTE_STR(MLX5_FLOW_MARK_MAX));
1024 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1025 return rte_flow_error_set(error, EINVAL,
1026 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1027 "can't flag and mark in same flow");
1028 if (action_flags & MLX5_FLOW_ACTION_MARK)
1029 return rte_flow_error_set(error, EINVAL,
1030 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1031 "can't have 2 mark actions in same"
1034 return rte_flow_error_set(error, ENOTSUP,
1035 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1036 "mark action not supported for "
1042 * Validate the drop action.
1044 * @param[in] action_flags
1045 * Bit-fields that holds the actions detected until now.
1047 * Attributes of flow that includes this action.
1049 * Pointer to error structure.
1052 * 0 on success, a negative errno value otherwise and rte_errno is set.
1055 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1056 const struct rte_flow_attr *attr,
1057 struct rte_flow_error *error)
1060 return rte_flow_error_set(error, ENOTSUP,
1061 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1062 "drop action not supported for "
1068 * Validate the queue action.
1071 * Pointer to the queue action.
1072 * @param[in] action_flags
1073 * Bit-fields that holds the actions detected until now.
1075 * Pointer to the Ethernet device structure.
1077 * Attributes of flow that includes this action.
1079 * Pointer to error structure.
1082 * 0 on success, a negative errno value otherwise and rte_errno is set.
1085 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1086 uint64_t action_flags,
1087 struct rte_eth_dev *dev,
1088 const struct rte_flow_attr *attr,
1089 struct rte_flow_error *error)
1091 struct mlx5_priv *priv = dev->data->dev_private;
1092 const struct rte_flow_action_queue *queue = action->conf;
1094 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1095 return rte_flow_error_set(error, EINVAL,
1096 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1097 "can't have 2 fate actions in"
1100 return rte_flow_error_set(error, EINVAL,
1101 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1102 NULL, "No Rx queues configured");
1103 if (queue->index >= priv->rxqs_n)
1104 return rte_flow_error_set(error, EINVAL,
1105 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1107 "queue index out of range");
1108 if (!(*priv->rxqs)[queue->index])
1109 return rte_flow_error_set(error, EINVAL,
1110 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1112 "queue is not configured");
1114 return rte_flow_error_set(error, ENOTSUP,
1115 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1116 "queue action not supported for "
1122 * Validate the rss action.
1125 * Pointer to the queue action.
1126 * @param[in] action_flags
1127 * Bit-fields that holds the actions detected until now.
1129 * Pointer to the Ethernet device structure.
1131 * Attributes of flow that includes this action.
1132 * @param[in] item_flags
1133 * Items that were detected.
1135 * Pointer to error structure.
1138 * 0 on success, a negative errno value otherwise and rte_errno is set.
1141 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1142 uint64_t action_flags,
1143 struct rte_eth_dev *dev,
1144 const struct rte_flow_attr *attr,
1145 uint64_t item_flags,
1146 struct rte_flow_error *error)
1148 struct mlx5_priv *priv = dev->data->dev_private;
1149 const struct rte_flow_action_rss *rss = action->conf;
1150 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1153 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1154 return rte_flow_error_set(error, EINVAL,
1155 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1156 "can't have 2 fate actions"
1158 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1159 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1160 return rte_flow_error_set(error, ENOTSUP,
1161 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1163 "RSS hash function not supported");
1164 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1169 return rte_flow_error_set(error, ENOTSUP,
1170 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1172 "tunnel RSS is not supported");
1173 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1174 if (rss->key_len == 0 && rss->key != NULL)
1175 return rte_flow_error_set(error, ENOTSUP,
1176 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1178 "RSS hash key length 0");
1179 if (rss->key_len > 0 && 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 small");
1184 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1185 return rte_flow_error_set(error, ENOTSUP,
1186 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1188 "RSS hash key too large");
1189 if (rss->queue_num > priv->config.ind_table_max_size)
1190 return rte_flow_error_set(error, ENOTSUP,
1191 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1193 "number of queues too large");
1194 if (rss->types & MLX5_RSS_HF_MASK)
1195 return rte_flow_error_set(error, ENOTSUP,
1196 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1198 "some RSS protocols are not"
1200 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1201 !(rss->types & ETH_RSS_IP))
1202 return rte_flow_error_set(error, EINVAL,
1203 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1204 "L3 partial RSS requested but L3 RSS"
1205 " type not specified");
1206 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1207 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1208 return rte_flow_error_set(error, EINVAL,
1209 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1210 "L4 partial RSS requested but L4 RSS"
1211 " type not specified");
1213 return rte_flow_error_set(error, EINVAL,
1214 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1215 NULL, "No Rx queues configured");
1216 if (!rss->queue_num)
1217 return rte_flow_error_set(error, EINVAL,
1218 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1219 NULL, "No queues configured");
1220 for (i = 0; i != rss->queue_num; ++i) {
1221 if (rss->queue[i] >= priv->rxqs_n)
1222 return rte_flow_error_set
1224 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1225 &rss->queue[i], "queue index out of range");
1226 if (!(*priv->rxqs)[rss->queue[i]])
1227 return rte_flow_error_set
1228 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1229 &rss->queue[i], "queue is not configured");
1232 return rte_flow_error_set(error, ENOTSUP,
1233 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1234 "rss action not supported for "
1236 if (rss->level > 1 && !tunnel)
1237 return rte_flow_error_set(error, EINVAL,
1238 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1239 "inner RSS is not supported for "
1240 "non-tunnel flows");
1245 * Validate the count action.
1248 * Pointer to the Ethernet device structure.
1250 * Attributes of flow that includes this action.
1252 * Pointer to error structure.
1255 * 0 on success, a negative errno value otherwise and rte_errno is set.
1258 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1259 const struct rte_flow_attr *attr,
1260 struct rte_flow_error *error)
1263 return rte_flow_error_set(error, ENOTSUP,
1264 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1265 "count action not supported for "
1271 * Verify the @p attributes will be correctly understood by the NIC and store
1272 * them in the @p flow if everything is correct.
1275 * Pointer to the Ethernet device structure.
1276 * @param[in] attributes
1277 * Pointer to flow attributes
1279 * Pointer to error structure.
1282 * 0 on success, a negative errno value otherwise and rte_errno is set.
1285 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1286 const struct rte_flow_attr *attributes,
1287 struct rte_flow_error *error)
1289 struct mlx5_priv *priv = dev->data->dev_private;
1290 uint32_t priority_max = priv->config.flow_prio - 1;
1292 if (attributes->group)
1293 return rte_flow_error_set(error, ENOTSUP,
1294 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1295 NULL, "groups is not supported");
1296 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1297 attributes->priority >= priority_max)
1298 return rte_flow_error_set(error, ENOTSUP,
1299 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1300 NULL, "priority out of range");
1301 if (attributes->egress)
1302 return rte_flow_error_set(error, ENOTSUP,
1303 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1304 "egress is not supported");
1305 if (attributes->transfer && !priv->config.dv_esw_en)
1306 return rte_flow_error_set(error, ENOTSUP,
1307 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1308 NULL, "transfer is not supported");
1309 if (!attributes->ingress)
1310 return rte_flow_error_set(error, EINVAL,
1311 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1313 "ingress attribute is mandatory");
1318 * Validate ICMP6 item.
1321 * Item specification.
1322 * @param[in] item_flags
1323 * Bit-fields that holds the items detected until now.
1325 * Pointer to error structure.
1328 * 0 on success, a negative errno value otherwise and rte_errno is set.
1331 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1332 uint64_t item_flags,
1333 uint8_t target_protocol,
1334 struct rte_flow_error *error)
1336 const struct rte_flow_item_icmp6 *mask = item->mask;
1337 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1338 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1339 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1340 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1341 MLX5_FLOW_LAYER_OUTER_L4;
1344 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1345 return rte_flow_error_set(error, EINVAL,
1346 RTE_FLOW_ERROR_TYPE_ITEM, item,
1347 "protocol filtering not compatible"
1348 " with ICMP6 layer");
1349 if (!(item_flags & l3m))
1350 return rte_flow_error_set(error, EINVAL,
1351 RTE_FLOW_ERROR_TYPE_ITEM, item,
1352 "IPv6 is mandatory to filter on"
1354 if (item_flags & l4m)
1355 return rte_flow_error_set(error, EINVAL,
1356 RTE_FLOW_ERROR_TYPE_ITEM, item,
1357 "multiple L4 layers not supported");
1359 mask = &rte_flow_item_icmp6_mask;
1360 ret = mlx5_flow_item_acceptable
1361 (item, (const uint8_t *)mask,
1362 (const uint8_t *)&rte_flow_item_icmp6_mask,
1363 sizeof(struct rte_flow_item_icmp6), error);
1370 * Validate ICMP item.
1373 * Item specification.
1374 * @param[in] item_flags
1375 * Bit-fields that holds the items detected until now.
1377 * Pointer to error structure.
1380 * 0 on success, a negative errno value otherwise and rte_errno is set.
1383 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1384 uint64_t item_flags,
1385 uint8_t target_protocol,
1386 struct rte_flow_error *error)
1388 const struct rte_flow_item_icmp *mask = item->mask;
1389 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1390 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1391 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1392 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1393 MLX5_FLOW_LAYER_OUTER_L4;
1396 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1397 return rte_flow_error_set(error, EINVAL,
1398 RTE_FLOW_ERROR_TYPE_ITEM, item,
1399 "protocol filtering not compatible"
1400 " with ICMP layer");
1401 if (!(item_flags & l3m))
1402 return rte_flow_error_set(error, EINVAL,
1403 RTE_FLOW_ERROR_TYPE_ITEM, item,
1404 "IPv4 is mandatory to filter"
1406 if (item_flags & l4m)
1407 return rte_flow_error_set(error, EINVAL,
1408 RTE_FLOW_ERROR_TYPE_ITEM, item,
1409 "multiple L4 layers not supported");
1411 mask = &rte_flow_item_icmp_mask;
1412 ret = mlx5_flow_item_acceptable
1413 (item, (const uint8_t *)mask,
1414 (const uint8_t *)&rte_flow_item_icmp_mask,
1415 sizeof(struct rte_flow_item_icmp), error);
1422 * Validate Ethernet item.
1425 * Item specification.
1426 * @param[in] item_flags
1427 * Bit-fields that holds the items detected until now.
1429 * Pointer to error structure.
1432 * 0 on success, a negative errno value otherwise and rte_errno is set.
1435 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1436 uint64_t item_flags,
1437 struct rte_flow_error *error)
1439 const struct rte_flow_item_eth *mask = item->mask;
1440 const struct rte_flow_item_eth nic_mask = {
1441 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1442 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1443 .type = RTE_BE16(0xffff),
1446 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1447 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1448 MLX5_FLOW_LAYER_OUTER_L2;
1450 if (item_flags & ethm)
1451 return rte_flow_error_set(error, ENOTSUP,
1452 RTE_FLOW_ERROR_TYPE_ITEM, item,
1453 "multiple L2 layers not supported");
1454 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1455 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1456 return rte_flow_error_set(error, EINVAL,
1457 RTE_FLOW_ERROR_TYPE_ITEM, item,
1458 "L2 layer should not follow "
1460 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1461 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1462 return rte_flow_error_set(error, EINVAL,
1463 RTE_FLOW_ERROR_TYPE_ITEM, item,
1464 "L2 layer should not follow VLAN");
1466 mask = &rte_flow_item_eth_mask;
1467 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1468 (const uint8_t *)&nic_mask,
1469 sizeof(struct rte_flow_item_eth),
1475 * Validate VLAN item.
1478 * Item specification.
1479 * @param[in] item_flags
1480 * Bit-fields that holds the items detected until now.
1482 * Ethernet device flow is being created on.
1484 * Pointer to error structure.
1487 * 0 on success, a negative errno value otherwise and rte_errno is set.
1490 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1491 uint64_t item_flags,
1492 struct rte_eth_dev *dev,
1493 struct rte_flow_error *error)
1495 const struct rte_flow_item_vlan *spec = item->spec;
1496 const struct rte_flow_item_vlan *mask = item->mask;
1497 const struct rte_flow_item_vlan nic_mask = {
1498 .tci = RTE_BE16(UINT16_MAX),
1499 .inner_type = RTE_BE16(UINT16_MAX),
1501 uint16_t vlan_tag = 0;
1502 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1504 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1505 MLX5_FLOW_LAYER_INNER_L4) :
1506 (MLX5_FLOW_LAYER_OUTER_L3 |
1507 MLX5_FLOW_LAYER_OUTER_L4);
1508 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1509 MLX5_FLOW_LAYER_OUTER_VLAN;
1511 if (item_flags & vlanm)
1512 return rte_flow_error_set(error, EINVAL,
1513 RTE_FLOW_ERROR_TYPE_ITEM, item,
1514 "multiple VLAN layers not supported");
1515 else if ((item_flags & l34m) != 0)
1516 return rte_flow_error_set(error, EINVAL,
1517 RTE_FLOW_ERROR_TYPE_ITEM, item,
1518 "VLAN cannot follow L3/L4 layer");
1520 mask = &rte_flow_item_vlan_mask;
1521 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1522 (const uint8_t *)&nic_mask,
1523 sizeof(struct rte_flow_item_vlan),
1527 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1528 struct mlx5_priv *priv = dev->data->dev_private;
1530 if (priv->vmwa_context) {
1532 * Non-NULL context means we have a virtual machine
1533 * and SR-IOV enabled, we have to create VLAN interface
1534 * to make hypervisor to setup E-Switch vport
1535 * context correctly. We avoid creating the multiple
1536 * VLAN interfaces, so we cannot support VLAN tag mask.
1538 return rte_flow_error_set(error, EINVAL,
1539 RTE_FLOW_ERROR_TYPE_ITEM,
1541 "VLAN tag mask is not"
1542 " supported in virtual"
1547 vlan_tag = spec->tci;
1548 vlan_tag &= mask->tci;
1551 * From verbs perspective an empty VLAN is equivalent
1552 * to a packet without VLAN layer.
1555 return rte_flow_error_set(error, EINVAL,
1556 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1558 "VLAN cannot be empty");
1563 * Validate IPV4 item.
1566 * Item specification.
1567 * @param[in] item_flags
1568 * Bit-fields that holds the items detected until now.
1569 * @param[in] acc_mask
1570 * Acceptable mask, if NULL default internal default mask
1571 * will be used to check whether item fields are supported.
1573 * Pointer to error structure.
1576 * 0 on success, a negative errno value otherwise and rte_errno is set.
1579 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1580 uint64_t item_flags,
1582 uint16_t ether_type,
1583 const struct rte_flow_item_ipv4 *acc_mask,
1584 struct rte_flow_error *error)
1586 const struct rte_flow_item_ipv4 *mask = item->mask;
1587 const struct rte_flow_item_ipv4 *spec = item->spec;
1588 const struct rte_flow_item_ipv4 nic_mask = {
1590 .src_addr = RTE_BE32(0xffffffff),
1591 .dst_addr = RTE_BE32(0xffffffff),
1592 .type_of_service = 0xff,
1593 .next_proto_id = 0xff,
1596 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1597 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1598 MLX5_FLOW_LAYER_OUTER_L3;
1599 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1600 MLX5_FLOW_LAYER_OUTER_L4;
1602 uint8_t next_proto = 0xFF;
1603 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1604 MLX5_FLOW_LAYER_OUTER_VLAN |
1605 MLX5_FLOW_LAYER_INNER_VLAN);
1607 if ((last_item & l2_vlan) && ether_type &&
1608 ether_type != RTE_ETHER_TYPE_IPV4)
1609 return rte_flow_error_set(error, EINVAL,
1610 RTE_FLOW_ERROR_TYPE_ITEM, item,
1611 "IPv4 cannot follow L2/VLAN layer "
1612 "which ether type is not IPv4");
1613 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1615 next_proto = mask->hdr.next_proto_id &
1616 spec->hdr.next_proto_id;
1617 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1618 return rte_flow_error_set(error, EINVAL,
1619 RTE_FLOW_ERROR_TYPE_ITEM,
1624 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1625 return rte_flow_error_set(error, EINVAL,
1626 RTE_FLOW_ERROR_TYPE_ITEM, item,
1627 "wrong tunnel type - IPv6 specified "
1628 "but IPv4 item provided");
1629 if (item_flags & l3m)
1630 return rte_flow_error_set(error, ENOTSUP,
1631 RTE_FLOW_ERROR_TYPE_ITEM, item,
1632 "multiple L3 layers not supported");
1633 else if (item_flags & l4m)
1634 return rte_flow_error_set(error, EINVAL,
1635 RTE_FLOW_ERROR_TYPE_ITEM, item,
1636 "L3 cannot follow an L4 layer.");
1637 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1638 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1639 return rte_flow_error_set(error, EINVAL,
1640 RTE_FLOW_ERROR_TYPE_ITEM, item,
1641 "L3 cannot follow an NVGRE layer.");
1643 mask = &rte_flow_item_ipv4_mask;
1644 else if (mask->hdr.next_proto_id != 0 &&
1645 mask->hdr.next_proto_id != 0xff)
1646 return rte_flow_error_set(error, EINVAL,
1647 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1648 "partial mask is not supported"
1650 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1651 acc_mask ? (const uint8_t *)acc_mask
1652 : (const uint8_t *)&nic_mask,
1653 sizeof(struct rte_flow_item_ipv4),
1661 * Validate IPV6 item.
1664 * Item specification.
1665 * @param[in] item_flags
1666 * Bit-fields that holds the items detected until now.
1667 * @param[in] acc_mask
1668 * Acceptable mask, if NULL default internal default mask
1669 * will be used to check whether item fields are supported.
1671 * Pointer to error structure.
1674 * 0 on success, a negative errno value otherwise and rte_errno is set.
1677 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1678 uint64_t item_flags,
1680 uint16_t ether_type,
1681 const struct rte_flow_item_ipv6 *acc_mask,
1682 struct rte_flow_error *error)
1684 const struct rte_flow_item_ipv6 *mask = item->mask;
1685 const struct rte_flow_item_ipv6 *spec = item->spec;
1686 const struct rte_flow_item_ipv6 nic_mask = {
1689 "\xff\xff\xff\xff\xff\xff\xff\xff"
1690 "\xff\xff\xff\xff\xff\xff\xff\xff",
1692 "\xff\xff\xff\xff\xff\xff\xff\xff"
1693 "\xff\xff\xff\xff\xff\xff\xff\xff",
1694 .vtc_flow = RTE_BE32(0xffffffff),
1698 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1699 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1700 MLX5_FLOW_LAYER_OUTER_L3;
1701 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1702 MLX5_FLOW_LAYER_OUTER_L4;
1704 uint8_t next_proto = 0xFF;
1705 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1706 MLX5_FLOW_LAYER_OUTER_VLAN |
1707 MLX5_FLOW_LAYER_INNER_VLAN);
1709 if ((last_item & l2_vlan) && ether_type &&
1710 ether_type != RTE_ETHER_TYPE_IPV6)
1711 return rte_flow_error_set(error, EINVAL,
1712 RTE_FLOW_ERROR_TYPE_ITEM, item,
1713 "IPv6 cannot follow L2/VLAN layer "
1714 "which ether type is not IPv6");
1715 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
1717 next_proto = mask->hdr.proto & spec->hdr.proto;
1718 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1719 return rte_flow_error_set(error, EINVAL,
1720 RTE_FLOW_ERROR_TYPE_ITEM,
1725 if (item_flags & MLX5_FLOW_LAYER_IPIP)
1726 return rte_flow_error_set(error, EINVAL,
1727 RTE_FLOW_ERROR_TYPE_ITEM, item,
1728 "wrong tunnel type - IPv4 specified "
1729 "but IPv6 item provided");
1730 if (item_flags & l3m)
1731 return rte_flow_error_set(error, ENOTSUP,
1732 RTE_FLOW_ERROR_TYPE_ITEM, item,
1733 "multiple L3 layers not supported");
1734 else if (item_flags & l4m)
1735 return rte_flow_error_set(error, EINVAL,
1736 RTE_FLOW_ERROR_TYPE_ITEM, item,
1737 "L3 cannot follow an L4 layer.");
1738 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1739 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1740 return rte_flow_error_set(error, EINVAL,
1741 RTE_FLOW_ERROR_TYPE_ITEM, item,
1742 "L3 cannot follow an NVGRE layer.");
1744 mask = &rte_flow_item_ipv6_mask;
1745 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1746 acc_mask ? (const uint8_t *)acc_mask
1747 : (const uint8_t *)&nic_mask,
1748 sizeof(struct rte_flow_item_ipv6),
1756 * Validate UDP item.
1759 * Item specification.
1760 * @param[in] item_flags
1761 * Bit-fields that holds the items detected until now.
1762 * @param[in] target_protocol
1763 * The next protocol in the previous item.
1764 * @param[in] flow_mask
1765 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
1767 * Pointer to error structure.
1770 * 0 on success, a negative errno value otherwise and rte_errno is set.
1773 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1774 uint64_t item_flags,
1775 uint8_t target_protocol,
1776 struct rte_flow_error *error)
1778 const struct rte_flow_item_udp *mask = item->mask;
1779 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1780 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1781 MLX5_FLOW_LAYER_OUTER_L3;
1782 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1783 MLX5_FLOW_LAYER_OUTER_L4;
1786 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1787 return rte_flow_error_set(error, EINVAL,
1788 RTE_FLOW_ERROR_TYPE_ITEM, item,
1789 "protocol filtering not compatible"
1791 if (!(item_flags & l3m))
1792 return rte_flow_error_set(error, EINVAL,
1793 RTE_FLOW_ERROR_TYPE_ITEM, item,
1794 "L3 is mandatory to filter on L4");
1795 if (item_flags & l4m)
1796 return rte_flow_error_set(error, EINVAL,
1797 RTE_FLOW_ERROR_TYPE_ITEM, item,
1798 "multiple L4 layers not supported");
1800 mask = &rte_flow_item_udp_mask;
1801 ret = mlx5_flow_item_acceptable
1802 (item, (const uint8_t *)mask,
1803 (const uint8_t *)&rte_flow_item_udp_mask,
1804 sizeof(struct rte_flow_item_udp), error);
1811 * Validate TCP item.
1814 * Item specification.
1815 * @param[in] item_flags
1816 * Bit-fields that holds the items detected until now.
1817 * @param[in] target_protocol
1818 * The next protocol in the previous item.
1820 * Pointer to error structure.
1823 * 0 on success, a negative errno value otherwise and rte_errno is set.
1826 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1827 uint64_t item_flags,
1828 uint8_t target_protocol,
1829 const struct rte_flow_item_tcp *flow_mask,
1830 struct rte_flow_error *error)
1832 const struct rte_flow_item_tcp *mask = item->mask;
1833 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1834 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1835 MLX5_FLOW_LAYER_OUTER_L3;
1836 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1837 MLX5_FLOW_LAYER_OUTER_L4;
1840 MLX5_ASSERT(flow_mask);
1841 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1842 return rte_flow_error_set(error, EINVAL,
1843 RTE_FLOW_ERROR_TYPE_ITEM, item,
1844 "protocol filtering not compatible"
1846 if (!(item_flags & l3m))
1847 return rte_flow_error_set(error, EINVAL,
1848 RTE_FLOW_ERROR_TYPE_ITEM, item,
1849 "L3 is mandatory to filter on L4");
1850 if (item_flags & l4m)
1851 return rte_flow_error_set(error, EINVAL,
1852 RTE_FLOW_ERROR_TYPE_ITEM, item,
1853 "multiple L4 layers not supported");
1855 mask = &rte_flow_item_tcp_mask;
1856 ret = mlx5_flow_item_acceptable
1857 (item, (const uint8_t *)mask,
1858 (const uint8_t *)flow_mask,
1859 sizeof(struct rte_flow_item_tcp), error);
1866 * Validate VXLAN item.
1869 * Item specification.
1870 * @param[in] item_flags
1871 * Bit-fields that holds the items detected until now.
1872 * @param[in] target_protocol
1873 * The next protocol in the previous item.
1875 * Pointer to error structure.
1878 * 0 on success, a negative errno value otherwise and rte_errno is set.
1881 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1882 uint64_t item_flags,
1883 struct rte_flow_error *error)
1885 const struct rte_flow_item_vxlan *spec = item->spec;
1886 const struct rte_flow_item_vxlan *mask = item->mask;
1891 } id = { .vlan_id = 0, };
1894 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1895 return rte_flow_error_set(error, ENOTSUP,
1896 RTE_FLOW_ERROR_TYPE_ITEM, item,
1897 "multiple tunnel layers not"
1900 * Verify only UDPv4 is present as defined in
1901 * https://tools.ietf.org/html/rfc7348
1903 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1904 return rte_flow_error_set(error, EINVAL,
1905 RTE_FLOW_ERROR_TYPE_ITEM, item,
1906 "no outer UDP layer found");
1908 mask = &rte_flow_item_vxlan_mask;
1909 ret = mlx5_flow_item_acceptable
1910 (item, (const uint8_t *)mask,
1911 (const uint8_t *)&rte_flow_item_vxlan_mask,
1912 sizeof(struct rte_flow_item_vxlan),
1917 memcpy(&id.vni[1], spec->vni, 3);
1918 memcpy(&id.vni[1], mask->vni, 3);
1920 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1921 return rte_flow_error_set(error, ENOTSUP,
1922 RTE_FLOW_ERROR_TYPE_ITEM, item,
1923 "VXLAN tunnel must be fully defined");
1928 * Validate VXLAN_GPE item.
1931 * Item specification.
1932 * @param[in] item_flags
1933 * Bit-fields that holds the items detected until now.
1935 * Pointer to the private data structure.
1936 * @param[in] target_protocol
1937 * The next protocol in the previous item.
1939 * Pointer to error structure.
1942 * 0 on success, a negative errno value otherwise and rte_errno is set.
1945 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1946 uint64_t item_flags,
1947 struct rte_eth_dev *dev,
1948 struct rte_flow_error *error)
1950 struct mlx5_priv *priv = dev->data->dev_private;
1951 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1952 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1957 } id = { .vlan_id = 0, };
1959 if (!priv->config.l3_vxlan_en)
1960 return rte_flow_error_set(error, ENOTSUP,
1961 RTE_FLOW_ERROR_TYPE_ITEM, item,
1962 "L3 VXLAN is not enabled by device"
1963 " parameter and/or not configured in"
1965 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1966 return rte_flow_error_set(error, ENOTSUP,
1967 RTE_FLOW_ERROR_TYPE_ITEM, item,
1968 "multiple tunnel layers not"
1971 * Verify only UDPv4 is present as defined in
1972 * https://tools.ietf.org/html/rfc7348
1974 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1975 return rte_flow_error_set(error, EINVAL,
1976 RTE_FLOW_ERROR_TYPE_ITEM, item,
1977 "no outer UDP layer found");
1979 mask = &rte_flow_item_vxlan_gpe_mask;
1980 ret = mlx5_flow_item_acceptable
1981 (item, (const uint8_t *)mask,
1982 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1983 sizeof(struct rte_flow_item_vxlan_gpe),
1989 return rte_flow_error_set(error, ENOTSUP,
1990 RTE_FLOW_ERROR_TYPE_ITEM,
1992 "VxLAN-GPE protocol"
1994 memcpy(&id.vni[1], spec->vni, 3);
1995 memcpy(&id.vni[1], mask->vni, 3);
1997 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1998 return rte_flow_error_set(error, ENOTSUP,
1999 RTE_FLOW_ERROR_TYPE_ITEM, item,
2000 "VXLAN-GPE tunnel must be fully"
2005 * Validate GRE Key item.
2008 * Item specification.
2009 * @param[in] item_flags
2010 * Bit flags to mark detected items.
2011 * @param[in] gre_item
2012 * Pointer to gre_item
2014 * Pointer to error structure.
2017 * 0 on success, a negative errno value otherwise and rte_errno is set.
2020 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2021 uint64_t item_flags,
2022 const struct rte_flow_item *gre_item,
2023 struct rte_flow_error *error)
2025 const rte_be32_t *mask = item->mask;
2027 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2028 const struct rte_flow_item_gre *gre_spec;
2029 const struct rte_flow_item_gre *gre_mask;
2031 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2032 return rte_flow_error_set(error, ENOTSUP,
2033 RTE_FLOW_ERROR_TYPE_ITEM, item,
2034 "Multiple GRE key not support");
2035 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2036 return rte_flow_error_set(error, ENOTSUP,
2037 RTE_FLOW_ERROR_TYPE_ITEM, item,
2038 "No preceding GRE header");
2039 if (item_flags & MLX5_FLOW_LAYER_INNER)
2040 return rte_flow_error_set(error, ENOTSUP,
2041 RTE_FLOW_ERROR_TYPE_ITEM, item,
2042 "GRE key following a wrong item");
2043 gre_mask = gre_item->mask;
2045 gre_mask = &rte_flow_item_gre_mask;
2046 gre_spec = gre_item->spec;
2047 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2048 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2049 return rte_flow_error_set(error, EINVAL,
2050 RTE_FLOW_ERROR_TYPE_ITEM, item,
2051 "Key bit must be on");
2054 mask = &gre_key_default_mask;
2055 ret = mlx5_flow_item_acceptable
2056 (item, (const uint8_t *)mask,
2057 (const uint8_t *)&gre_key_default_mask,
2058 sizeof(rte_be32_t), error);
2063 * Validate GRE item.
2066 * Item specification.
2067 * @param[in] item_flags
2068 * Bit flags to mark detected items.
2069 * @param[in] target_protocol
2070 * The next protocol in the previous item.
2072 * Pointer to error structure.
2075 * 0 on success, a negative errno value otherwise and rte_errno is set.
2078 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2079 uint64_t item_flags,
2080 uint8_t target_protocol,
2081 struct rte_flow_error *error)
2083 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2084 const struct rte_flow_item_gre *mask = item->mask;
2086 const struct rte_flow_item_gre nic_mask = {
2087 .c_rsvd0_ver = RTE_BE16(0xB000),
2088 .protocol = RTE_BE16(UINT16_MAX),
2091 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2092 return rte_flow_error_set(error, EINVAL,
2093 RTE_FLOW_ERROR_TYPE_ITEM, item,
2094 "protocol filtering not compatible"
2095 " with this GRE layer");
2096 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2097 return rte_flow_error_set(error, ENOTSUP,
2098 RTE_FLOW_ERROR_TYPE_ITEM, item,
2099 "multiple tunnel layers not"
2101 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2102 return rte_flow_error_set(error, ENOTSUP,
2103 RTE_FLOW_ERROR_TYPE_ITEM, item,
2104 "L3 Layer is missing");
2106 mask = &rte_flow_item_gre_mask;
2107 ret = mlx5_flow_item_acceptable
2108 (item, (const uint8_t *)mask,
2109 (const uint8_t *)&nic_mask,
2110 sizeof(struct rte_flow_item_gre), error);
2113 #ifndef HAVE_MLX5DV_DR
2114 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2115 if (spec && (spec->protocol & mask->protocol))
2116 return rte_flow_error_set(error, ENOTSUP,
2117 RTE_FLOW_ERROR_TYPE_ITEM, item,
2118 "without MPLS support the"
2119 " specification cannot be used for"
2127 * Validate Geneve item.
2130 * Item specification.
2131 * @param[in] itemFlags
2132 * Bit-fields that holds the items detected until now.
2134 * Pointer to the private data structure.
2136 * Pointer to error structure.
2139 * 0 on success, a negative errno value otherwise and rte_errno is set.
2143 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2144 uint64_t item_flags,
2145 struct rte_eth_dev *dev,
2146 struct rte_flow_error *error)
2148 struct mlx5_priv *priv = dev->data->dev_private;
2149 const struct rte_flow_item_geneve *spec = item->spec;
2150 const struct rte_flow_item_geneve *mask = item->mask;
2153 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2154 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2155 const struct rte_flow_item_geneve nic_mask = {
2156 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2157 .vni = "\xff\xff\xff",
2158 .protocol = RTE_BE16(UINT16_MAX),
2161 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2162 return rte_flow_error_set(error, ENOTSUP,
2163 RTE_FLOW_ERROR_TYPE_ITEM, item,
2164 "L3 Geneve is not enabled by device"
2165 " parameter and/or not configured in"
2167 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2168 return rte_flow_error_set(error, ENOTSUP,
2169 RTE_FLOW_ERROR_TYPE_ITEM, item,
2170 "multiple tunnel layers not"
2173 * Verify only UDPv4 is present as defined in
2174 * https://tools.ietf.org/html/rfc7348
2176 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2177 return rte_flow_error_set(error, EINVAL,
2178 RTE_FLOW_ERROR_TYPE_ITEM, item,
2179 "no outer UDP layer found");
2181 mask = &rte_flow_item_geneve_mask;
2182 ret = mlx5_flow_item_acceptable
2183 (item, (const uint8_t *)mask,
2184 (const uint8_t *)&nic_mask,
2185 sizeof(struct rte_flow_item_geneve), error);
2189 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2190 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2191 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2192 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2193 return rte_flow_error_set(error, ENOTSUP,
2194 RTE_FLOW_ERROR_TYPE_ITEM,
2196 "Geneve protocol unsupported"
2197 " fields are being used");
2198 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2199 return rte_flow_error_set
2201 RTE_FLOW_ERROR_TYPE_ITEM,
2203 "Unsupported Geneve options length");
2205 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2206 return rte_flow_error_set
2208 RTE_FLOW_ERROR_TYPE_ITEM, item,
2209 "Geneve tunnel must be fully defined");
2214 * Validate MPLS item.
2217 * Pointer to the rte_eth_dev structure.
2219 * Item specification.
2220 * @param[in] item_flags
2221 * Bit-fields that holds the items detected until now.
2222 * @param[in] prev_layer
2223 * The protocol layer indicated in previous item.
2225 * Pointer to error structure.
2228 * 0 on success, a negative errno value otherwise and rte_errno is set.
2231 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2232 const struct rte_flow_item *item __rte_unused,
2233 uint64_t item_flags __rte_unused,
2234 uint64_t prev_layer __rte_unused,
2235 struct rte_flow_error *error)
2237 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2238 const struct rte_flow_item_mpls *mask = item->mask;
2239 struct mlx5_priv *priv = dev->data->dev_private;
2242 if (!priv->config.mpls_en)
2243 return rte_flow_error_set(error, ENOTSUP,
2244 RTE_FLOW_ERROR_TYPE_ITEM, item,
2245 "MPLS not supported or"
2246 " disabled in firmware"
2248 /* MPLS over IP, UDP, GRE is allowed */
2249 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2250 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2251 MLX5_FLOW_LAYER_GRE)))
2252 return rte_flow_error_set(error, EINVAL,
2253 RTE_FLOW_ERROR_TYPE_ITEM, item,
2254 "protocol filtering not compatible"
2255 " with MPLS layer");
2256 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2257 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2258 !(item_flags & MLX5_FLOW_LAYER_GRE))
2259 return rte_flow_error_set(error, ENOTSUP,
2260 RTE_FLOW_ERROR_TYPE_ITEM, item,
2261 "multiple tunnel layers not"
2264 mask = &rte_flow_item_mpls_mask;
2265 ret = mlx5_flow_item_acceptable
2266 (item, (const uint8_t *)mask,
2267 (const uint8_t *)&rte_flow_item_mpls_mask,
2268 sizeof(struct rte_flow_item_mpls), error);
2273 return rte_flow_error_set(error, ENOTSUP,
2274 RTE_FLOW_ERROR_TYPE_ITEM, item,
2275 "MPLS is not supported by Verbs, please"
2280 * Validate NVGRE item.
2283 * Item specification.
2284 * @param[in] item_flags
2285 * Bit flags to mark detected items.
2286 * @param[in] target_protocol
2287 * The next protocol in the previous item.
2289 * Pointer to error structure.
2292 * 0 on success, a negative errno value otherwise and rte_errno is set.
2295 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2296 uint64_t item_flags,
2297 uint8_t target_protocol,
2298 struct rte_flow_error *error)
2300 const struct rte_flow_item_nvgre *mask = item->mask;
2303 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2304 return rte_flow_error_set(error, EINVAL,
2305 RTE_FLOW_ERROR_TYPE_ITEM, item,
2306 "protocol filtering not compatible"
2307 " with this GRE layer");
2308 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2309 return rte_flow_error_set(error, ENOTSUP,
2310 RTE_FLOW_ERROR_TYPE_ITEM, item,
2311 "multiple tunnel layers not"
2313 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2314 return rte_flow_error_set(error, ENOTSUP,
2315 RTE_FLOW_ERROR_TYPE_ITEM, item,
2316 "L3 Layer is missing");
2318 mask = &rte_flow_item_nvgre_mask;
2319 ret = mlx5_flow_item_acceptable
2320 (item, (const uint8_t *)mask,
2321 (const uint8_t *)&rte_flow_item_nvgre_mask,
2322 sizeof(struct rte_flow_item_nvgre), error);
2328 /* Allocate unique ID for the split Q/RSS subflows. */
2330 flow_qrss_get_id(struct rte_eth_dev *dev)
2332 struct mlx5_priv *priv = dev->data->dev_private;
2333 uint32_t qrss_id, ret;
2335 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2338 MLX5_ASSERT(qrss_id);
2342 /* Free unique ID for the split Q/RSS subflows. */
2344 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2346 struct mlx5_priv *priv = dev->data->dev_private;
2349 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2353 * Release resource related QUEUE/RSS action split.
2356 * Pointer to Ethernet device.
2358 * Flow to release id's from.
2361 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2362 struct rte_flow *flow)
2364 struct mlx5_priv *priv = dev->data->dev_private;
2365 uint32_t handle_idx;
2366 struct mlx5_flow_handle *dev_handle;
2368 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
2369 handle_idx, dev_handle, next)
2370 if (dev_handle->split_flow_id)
2371 flow_qrss_free_id(dev, dev_handle->split_flow_id);
2375 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2376 const struct rte_flow_attr *attr __rte_unused,
2377 const struct rte_flow_item items[] __rte_unused,
2378 const struct rte_flow_action actions[] __rte_unused,
2379 bool external __rte_unused,
2380 int hairpin __rte_unused,
2381 struct rte_flow_error *error)
2383 return rte_flow_error_set(error, ENOTSUP,
2384 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2387 static struct mlx5_flow *
2388 flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
2389 const struct rte_flow_attr *attr __rte_unused,
2390 const struct rte_flow_item items[] __rte_unused,
2391 const struct rte_flow_action actions[] __rte_unused,
2392 struct rte_flow_error *error)
2394 rte_flow_error_set(error, ENOTSUP,
2395 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2400 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2401 struct mlx5_flow *dev_flow __rte_unused,
2402 const struct rte_flow_attr *attr __rte_unused,
2403 const struct rte_flow_item items[] __rte_unused,
2404 const struct rte_flow_action actions[] __rte_unused,
2405 struct rte_flow_error *error)
2407 return rte_flow_error_set(error, ENOTSUP,
2408 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2412 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2413 struct rte_flow *flow __rte_unused,
2414 struct rte_flow_error *error)
2416 return rte_flow_error_set(error, ENOTSUP,
2417 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2421 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2422 struct rte_flow *flow __rte_unused)
2427 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2428 struct rte_flow *flow __rte_unused)
2433 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2434 struct rte_flow *flow __rte_unused,
2435 const struct rte_flow_action *actions __rte_unused,
2436 void *data __rte_unused,
2437 struct rte_flow_error *error)
2439 return rte_flow_error_set(error, ENOTSUP,
2440 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2443 /* Void driver to protect from null pointer reference. */
2444 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2445 .validate = flow_null_validate,
2446 .prepare = flow_null_prepare,
2447 .translate = flow_null_translate,
2448 .apply = flow_null_apply,
2449 .remove = flow_null_remove,
2450 .destroy = flow_null_destroy,
2451 .query = flow_null_query,
2455 * Select flow driver type according to flow attributes and device
2459 * Pointer to the dev structure.
2461 * Pointer to the flow attributes.
2464 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2466 static enum mlx5_flow_drv_type
2467 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2469 struct mlx5_priv *priv = dev->data->dev_private;
2470 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
2472 if (attr->transfer && priv->config.dv_esw_en)
2473 type = MLX5_FLOW_TYPE_DV;
2474 if (!attr->transfer)
2475 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2476 MLX5_FLOW_TYPE_VERBS;
2480 #define flow_get_drv_ops(type) flow_drv_ops[type]
2483 * Flow driver validation API. This abstracts calling driver specific functions.
2484 * The type of flow driver is determined according to flow attributes.
2487 * Pointer to the dev structure.
2489 * Pointer to the flow attributes.
2491 * Pointer to the list of items.
2492 * @param[in] actions
2493 * Pointer to the list of actions.
2494 * @param[in] external
2495 * This flow rule is created by request external to PMD.
2496 * @param[in] hairpin
2497 * Number of hairpin TX actions, 0 means classic flow.
2499 * Pointer to the error structure.
2502 * 0 on success, a negative errno value otherwise and rte_errno is set.
2505 flow_drv_validate(struct rte_eth_dev *dev,
2506 const struct rte_flow_attr *attr,
2507 const struct rte_flow_item items[],
2508 const struct rte_flow_action actions[],
2509 bool external, int hairpin, struct rte_flow_error *error)
2511 const struct mlx5_flow_driver_ops *fops;
2512 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2514 fops = flow_get_drv_ops(type);
2515 return fops->validate(dev, attr, items, actions, external,
2520 * Flow driver preparation API. This abstracts calling driver specific
2521 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2522 * calculates the size of memory required for device flow, allocates the memory,
2523 * initializes the device flow and returns the pointer.
2526 * This function initializes device flow structure such as dv or verbs in
2527 * struct mlx5_flow. However, it is caller's responsibility to initialize the
2528 * rest. For example, adding returning device flow to flow->dev_flow list and
2529 * setting backward reference to the flow should be done out of this function.
2530 * layers field is not filled either.
2533 * Pointer to the dev structure.
2535 * Pointer to the flow attributes.
2537 * Pointer to the list of items.
2538 * @param[in] actions
2539 * Pointer to the list of actions.
2540 * @param[in] flow_idx
2541 * This memory pool index to the flow.
2543 * Pointer to the error structure.
2546 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
2548 static inline struct mlx5_flow *
2549 flow_drv_prepare(struct rte_eth_dev *dev,
2550 const struct rte_flow *flow,
2551 const struct rte_flow_attr *attr,
2552 const struct rte_flow_item items[],
2553 const struct rte_flow_action actions[],
2555 struct rte_flow_error *error)
2557 const struct mlx5_flow_driver_ops *fops;
2558 enum mlx5_flow_drv_type type = flow->drv_type;
2559 struct mlx5_flow *mlx5_flow = NULL;
2561 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2562 fops = flow_get_drv_ops(type);
2563 mlx5_flow = fops->prepare(dev, attr, items, actions, error);
2565 mlx5_flow->flow_idx = flow_idx;
2570 * Flow driver translation API. This abstracts calling driver specific
2571 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2572 * translates a generic flow into a driver flow. flow_drv_prepare() must
2576 * dev_flow->layers could be filled as a result of parsing during translation
2577 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
2578 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
2579 * flow->actions could be overwritten even though all the expanded dev_flows
2580 * have the same actions.
2583 * Pointer to the rte dev structure.
2584 * @param[in, out] dev_flow
2585 * Pointer to the mlx5 flow.
2587 * Pointer to the flow attributes.
2589 * Pointer to the list of items.
2590 * @param[in] actions
2591 * Pointer to the list of actions.
2593 * Pointer to the error structure.
2596 * 0 on success, a negative errno value otherwise and rte_errno is set.
2599 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
2600 const struct rte_flow_attr *attr,
2601 const struct rte_flow_item items[],
2602 const struct rte_flow_action actions[],
2603 struct rte_flow_error *error)
2605 const struct mlx5_flow_driver_ops *fops;
2606 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
2608 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2609 fops = flow_get_drv_ops(type);
2610 return fops->translate(dev, dev_flow, attr, items, actions, error);
2614 * Flow driver apply API. This abstracts calling driver specific functions.
2615 * Parent flow (rte_flow) should have driver type (drv_type). It applies
2616 * translated driver flows on to device. flow_drv_translate() must precede.
2619 * Pointer to Ethernet device structure.
2620 * @param[in, out] flow
2621 * Pointer to flow structure.
2623 * Pointer to error structure.
2626 * 0 on success, a negative errno value otherwise and rte_errno is set.
2629 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
2630 struct rte_flow_error *error)
2632 const struct mlx5_flow_driver_ops *fops;
2633 enum mlx5_flow_drv_type type = flow->drv_type;
2635 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2636 fops = flow_get_drv_ops(type);
2637 return fops->apply(dev, flow, error);
2641 * Flow driver remove API. This abstracts calling driver specific functions.
2642 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2643 * on device. All the resources of the flow should be freed by calling
2644 * flow_drv_destroy().
2647 * Pointer to Ethernet device.
2648 * @param[in, out] flow
2649 * Pointer to flow structure.
2652 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
2654 const struct mlx5_flow_driver_ops *fops;
2655 enum mlx5_flow_drv_type type = flow->drv_type;
2657 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2658 fops = flow_get_drv_ops(type);
2659 fops->remove(dev, flow);
2663 * Flow driver destroy API. This abstracts calling driver specific functions.
2664 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2665 * on device and releases resources of the flow.
2668 * Pointer to Ethernet device.
2669 * @param[in, out] flow
2670 * Pointer to flow structure.
2673 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
2675 const struct mlx5_flow_driver_ops *fops;
2676 enum mlx5_flow_drv_type type = flow->drv_type;
2678 flow_mreg_split_qrss_release(dev, flow);
2679 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2680 fops = flow_get_drv_ops(type);
2681 fops->destroy(dev, flow);
2685 * Get RSS action from the action list.
2687 * @param[in] actions
2688 * Pointer to the list of actions.
2691 * Pointer to the RSS action if exist, else return NULL.
2693 static const struct rte_flow_action_rss*
2694 flow_get_rss_action(const struct rte_flow_action actions[])
2696 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2697 switch (actions->type) {
2698 case RTE_FLOW_ACTION_TYPE_RSS:
2699 return (const struct rte_flow_action_rss *)
2709 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
2711 const struct rte_flow_item *item;
2712 unsigned int has_vlan = 0;
2714 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2715 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2721 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
2722 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
2723 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
2724 MLX5_EXPANSION_ROOT_OUTER;
2728 * Get layer flags from the prefix flow.
2730 * Some flows may be split to several subflows, the prefix subflow gets the
2731 * match items and the suffix sub flow gets the actions.
2732 * Some actions need the user defined match item flags to get the detail for
2734 * This function helps the suffix flow to get the item layer flags from prefix
2737 * @param[in] dev_flow
2738 * Pointer the created preifx subflow.
2741 * The layers get from prefix subflow.
2743 static inline uint64_t
2744 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
2746 uint64_t layers = 0;
2749 * Layers bits could be localization, but usually the compiler will
2750 * help to do the optimization work for source code.
2751 * If no decap actions, use the layers directly.
2753 if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
2754 return dev_flow->handle->layers;
2755 /* Convert L3 layers with decap action. */
2756 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
2757 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2758 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
2759 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2760 /* Convert L4 layers with decap action. */
2761 if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
2762 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
2763 else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
2764 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
2769 * Get metadata split action information.
2771 * @param[in] actions
2772 * Pointer to the list of actions.
2774 * Pointer to the return pointer.
2775 * @param[out] qrss_type
2776 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
2777 * if no QUEUE/RSS is found.
2778 * @param[out] encap_idx
2779 * Pointer to the index of the encap action if exists, otherwise the last
2783 * Total number of actions.
2786 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
2787 const struct rte_flow_action **qrss,
2790 const struct rte_flow_action_raw_encap *raw_encap;
2792 int raw_decap_idx = -1;
2795 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2796 switch (actions->type) {
2797 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2798 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2799 *encap_idx = actions_n;
2801 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
2802 raw_decap_idx = actions_n;
2804 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2805 raw_encap = actions->conf;
2806 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
2807 *encap_idx = raw_decap_idx != -1 ?
2808 raw_decap_idx : actions_n;
2810 case RTE_FLOW_ACTION_TYPE_QUEUE:
2811 case RTE_FLOW_ACTION_TYPE_RSS:
2819 if (*encap_idx == -1)
2820 *encap_idx = actions_n;
2821 /* Count RTE_FLOW_ACTION_TYPE_END. */
2822 return actions_n + 1;
2826 * Check meter action from the action list.
2828 * @param[in] actions
2829 * Pointer to the list of actions.
2831 * Pointer to the meter exist flag.
2834 * Total number of actions.
2837 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
2843 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2844 switch (actions->type) {
2845 case RTE_FLOW_ACTION_TYPE_METER:
2853 /* Count RTE_FLOW_ACTION_TYPE_END. */
2854 return actions_n + 1;
2858 * Check if the flow should be splited due to hairpin.
2859 * The reason for the split is that in current HW we can't
2860 * support encap on Rx, so if a flow have encap we move it
2864 * Pointer to Ethernet device.
2866 * Flow rule attributes.
2867 * @param[in] actions
2868 * Associated actions (list terminated by the END action).
2871 * > 0 the number of actions and the flow should be split,
2872 * 0 when no split required.
2875 flow_check_hairpin_split(struct rte_eth_dev *dev,
2876 const struct rte_flow_attr *attr,
2877 const struct rte_flow_action actions[])
2879 int queue_action = 0;
2882 const struct rte_flow_action_queue *queue;
2883 const struct rte_flow_action_rss *rss;
2884 const struct rte_flow_action_raw_encap *raw_encap;
2888 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2889 switch (actions->type) {
2890 case RTE_FLOW_ACTION_TYPE_QUEUE:
2891 queue = actions->conf;
2894 if (mlx5_rxq_get_type(dev, queue->index) !=
2895 MLX5_RXQ_TYPE_HAIRPIN)
2900 case RTE_FLOW_ACTION_TYPE_RSS:
2901 rss = actions->conf;
2902 if (rss == NULL || rss->queue_num == 0)
2904 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
2905 MLX5_RXQ_TYPE_HAIRPIN)
2910 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2911 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2915 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2916 raw_encap = actions->conf;
2917 if (raw_encap->size >
2918 (sizeof(struct rte_flow_item_eth) +
2919 sizeof(struct rte_flow_item_ipv4)))
2928 if (encap == 1 && queue_action)
2933 /* Declare flow create/destroy prototype in advance. */
2935 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
2936 const struct rte_flow_attr *attr,
2937 const struct rte_flow_item items[],
2938 const struct rte_flow_action actions[],
2939 bool external, struct rte_flow_error *error);
2942 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
2946 * Add a flow of copying flow metadata registers in RX_CP_TBL.
2948 * As mark_id is unique, if there's already a registered flow for the mark_id,
2949 * return by increasing the reference counter of the resource. Otherwise, create
2950 * the resource (mcp_res) and flow.
2953 * - If ingress port is ANY and reg_c[1] is mark_id,
2954 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
2956 * For default flow (zero mark_id), flow is like,
2957 * - If ingress port is ANY,
2958 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
2961 * Pointer to Ethernet device.
2963 * ID of MARK action, zero means default flow for META.
2965 * Perform verbose error reporting if not NULL.
2968 * Associated resource on success, NULL otherwise and rte_errno is set.
2970 static struct mlx5_flow_mreg_copy_resource *
2971 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
2972 struct rte_flow_error *error)
2974 struct mlx5_priv *priv = dev->data->dev_private;
2975 struct rte_flow_attr attr = {
2976 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
2979 struct mlx5_rte_flow_item_tag tag_spec = {
2982 struct rte_flow_item items[] = {
2983 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
2985 struct rte_flow_action_mark ftag = {
2988 struct mlx5_flow_action_copy_mreg cp_mreg = {
2992 struct rte_flow_action_jump jump = {
2993 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
2995 struct rte_flow_action actions[] = {
2996 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
2998 struct mlx5_flow_mreg_copy_resource *mcp_res;
3002 /* Fill the register fileds in the flow. */
3003 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3007 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3011 /* Check if already registered. */
3012 MLX5_ASSERT(priv->mreg_cp_tbl);
3013 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
3015 /* For non-default rule. */
3016 if (mark_id != MLX5_DEFAULT_COPY_ID)
3018 MLX5_ASSERT(mark_id != MLX5_DEFAULT_COPY_ID ||
3019 mcp_res->refcnt == 1);
3022 /* Provide the full width of FLAG specific value. */
3023 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
3024 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
3025 /* Build a new flow. */
3026 if (mark_id != MLX5_DEFAULT_COPY_ID) {
3027 items[0] = (struct rte_flow_item){
3028 .type = (enum rte_flow_item_type)
3029 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3032 items[1] = (struct rte_flow_item){
3033 .type = RTE_FLOW_ITEM_TYPE_END,
3035 actions[0] = (struct rte_flow_action){
3036 .type = (enum rte_flow_action_type)
3037 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
3040 actions[1] = (struct rte_flow_action){
3041 .type = (enum rte_flow_action_type)
3042 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3045 actions[2] = (struct rte_flow_action){
3046 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3049 actions[3] = (struct rte_flow_action){
3050 .type = RTE_FLOW_ACTION_TYPE_END,
3053 /* Default rule, wildcard match. */
3054 attr.priority = MLX5_FLOW_PRIO_RSVD;
3055 items[0] = (struct rte_flow_item){
3056 .type = RTE_FLOW_ITEM_TYPE_END,
3058 actions[0] = (struct rte_flow_action){
3059 .type = (enum rte_flow_action_type)
3060 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3063 actions[1] = (struct rte_flow_action){
3064 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3067 actions[2] = (struct rte_flow_action){
3068 .type = RTE_FLOW_ACTION_TYPE_END,
3071 /* Build a new entry. */
3072 mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
3079 * The copy Flows are not included in any list. There
3080 * ones are referenced from other Flows and can not
3081 * be applied, removed, deleted in ardbitrary order
3082 * by list traversing.
3084 mcp_res->rix_flow = flow_list_create(dev, NULL, &attr, items,
3085 actions, false, error);
3086 if (!mcp_res->rix_flow)
3089 mcp_res->hlist_ent.key = mark_id;
3090 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3091 &mcp_res->hlist_ent);
3097 if (mcp_res->rix_flow)
3098 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3099 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3104 * Release flow in RX_CP_TBL.
3107 * Pointer to Ethernet device.
3109 * Parent flow for wich copying is provided.
3112 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3113 struct rte_flow *flow)
3115 struct mlx5_flow_mreg_copy_resource *mcp_res;
3116 struct mlx5_priv *priv = dev->data->dev_private;
3118 if (!flow->rix_mreg_copy)
3120 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3121 flow->rix_mreg_copy);
3122 if (!mcp_res || !priv->mreg_cp_tbl)
3124 if (flow->copy_applied) {
3125 MLX5_ASSERT(mcp_res->appcnt);
3126 flow->copy_applied = 0;
3128 if (!mcp_res->appcnt) {
3129 struct rte_flow *mcp_flow = mlx5_ipool_get
3130 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3134 flow_drv_remove(dev, mcp_flow);
3138 * We do not check availability of metadata registers here,
3139 * because copy resources are not allocated in this case.
3141 if (--mcp_res->refcnt)
3143 MLX5_ASSERT(mcp_res->rix_flow);
3144 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3145 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3146 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3147 flow->rix_mreg_copy = 0;
3151 * Start flow in RX_CP_TBL.
3154 * Pointer to Ethernet device.
3156 * Parent flow for wich copying is provided.
3159 * 0 on success, a negative errno value otherwise and rte_errno is set.
3162 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3163 struct rte_flow *flow)
3165 struct mlx5_flow_mreg_copy_resource *mcp_res;
3166 struct mlx5_priv *priv = dev->data->dev_private;
3169 if (!flow->rix_mreg_copy || flow->copy_applied)
3171 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3172 flow->rix_mreg_copy);
3175 if (!mcp_res->appcnt) {
3176 struct rte_flow *mcp_flow = mlx5_ipool_get
3177 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3181 ret = flow_drv_apply(dev, mcp_flow, NULL);
3187 flow->copy_applied = 1;
3192 * Stop flow in RX_CP_TBL.
3195 * Pointer to Ethernet device.
3197 * Parent flow for wich copying is provided.
3200 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3201 struct rte_flow *flow)
3203 struct mlx5_flow_mreg_copy_resource *mcp_res;
3204 struct mlx5_priv *priv = dev->data->dev_private;
3206 if (!flow->rix_mreg_copy || !flow->copy_applied)
3208 mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
3209 flow->rix_mreg_copy);
3212 MLX5_ASSERT(mcp_res->appcnt);
3214 flow->copy_applied = 0;
3215 if (!mcp_res->appcnt) {
3216 struct rte_flow *mcp_flow = mlx5_ipool_get
3217 (priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
3221 flow_drv_remove(dev, mcp_flow);
3226 * Remove the default copy action from RX_CP_TBL.
3229 * Pointer to Ethernet device.
3232 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3234 struct mlx5_flow_mreg_copy_resource *mcp_res;
3235 struct mlx5_priv *priv = dev->data->dev_private;
3237 /* Check if default flow is registered. */
3238 if (!priv->mreg_cp_tbl)
3240 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3241 MLX5_DEFAULT_COPY_ID);
3244 MLX5_ASSERT(mcp_res->rix_flow);
3245 flow_list_destroy(dev, NULL, mcp_res->rix_flow);
3246 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3247 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
3251 * Add the default copy action in in RX_CP_TBL.
3254 * Pointer to Ethernet device.
3256 * Perform verbose error reporting if not NULL.
3259 * 0 for success, negative value otherwise and rte_errno is set.
3262 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3263 struct rte_flow_error *error)
3265 struct mlx5_priv *priv = dev->data->dev_private;
3266 struct mlx5_flow_mreg_copy_resource *mcp_res;
3268 /* Check whether extensive metadata feature is engaged. */
3269 if (!priv->config.dv_flow_en ||
3270 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3271 !mlx5_flow_ext_mreg_supported(dev) ||
3272 !priv->sh->dv_regc0_mask)
3274 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3281 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3283 * All the flow having Q/RSS action should be split by
3284 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3285 * performs the following,
3286 * - CQE->flow_tag := reg_c[1] (MARK)
3287 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3288 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3289 * but there should be a flow per each MARK ID set by MARK action.
3291 * For the aforementioned reason, if there's a MARK action in flow's action
3292 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3293 * the MARK ID to CQE's flow_tag like,
3294 * - If reg_c[1] is mark_id,
3295 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3297 * For SET_META action which stores value in reg_c[0], as the destination is
3298 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3299 * MARK ID means the default flow. The default flow looks like,
3300 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3303 * Pointer to Ethernet device.
3305 * Pointer to flow structure.
3306 * @param[in] actions
3307 * Pointer to the list of actions.
3309 * Perform verbose error reporting if not NULL.
3312 * 0 on success, negative value otherwise and rte_errno is set.
3315 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3316 struct rte_flow *flow,
3317 const struct rte_flow_action *actions,
3318 struct rte_flow_error *error)
3320 struct mlx5_priv *priv = dev->data->dev_private;
3321 struct mlx5_dev_config *config = &priv->config;
3322 struct mlx5_flow_mreg_copy_resource *mcp_res;
3323 const struct rte_flow_action_mark *mark;
3325 /* Check whether extensive metadata feature is engaged. */
3326 if (!config->dv_flow_en ||
3327 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3328 !mlx5_flow_ext_mreg_supported(dev) ||
3329 !priv->sh->dv_regc0_mask)
3331 /* Find MARK action. */
3332 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3333 switch (actions->type) {
3334 case RTE_FLOW_ACTION_TYPE_FLAG:
3335 mcp_res = flow_mreg_add_copy_action
3336 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3339 flow->rix_mreg_copy = mcp_res->idx;
3340 if (dev->data->dev_started) {
3342 flow->copy_applied = 1;
3345 case RTE_FLOW_ACTION_TYPE_MARK:
3346 mark = (const struct rte_flow_action_mark *)
3349 flow_mreg_add_copy_action(dev, mark->id, error);
3352 flow->rix_mreg_copy = mcp_res->idx;
3353 if (dev->data->dev_started) {
3355 flow->copy_applied = 1;
3365 #define MLX5_MAX_SPLIT_ACTIONS 24
3366 #define MLX5_MAX_SPLIT_ITEMS 24
3369 * Split the hairpin flow.
3370 * Since HW can't support encap on Rx we move the encap to Tx.
3371 * If the count action is after the encap then we also
3372 * move the count action. in this case the count will also measure
3376 * Pointer to Ethernet device.
3377 * @param[in] actions
3378 * Associated actions (list terminated by the END action).
3379 * @param[out] actions_rx
3381 * @param[out] actions_tx
3383 * @param[out] pattern_tx
3384 * The pattern items for the Tx flow.
3385 * @param[out] flow_id
3386 * The flow ID connected to this flow.
3392 flow_hairpin_split(struct rte_eth_dev *dev,
3393 const struct rte_flow_action actions[],
3394 struct rte_flow_action actions_rx[],
3395 struct rte_flow_action actions_tx[],
3396 struct rte_flow_item pattern_tx[],
3399 struct mlx5_priv *priv = dev->data->dev_private;
3400 const struct rte_flow_action_raw_encap *raw_encap;
3401 const struct rte_flow_action_raw_decap *raw_decap;
3402 struct mlx5_rte_flow_action_set_tag *set_tag;
3403 struct rte_flow_action *tag_action;
3404 struct mlx5_rte_flow_item_tag *tag_item;
3405 struct rte_flow_item *item;
3409 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
3410 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3411 switch (actions->type) {
3412 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3413 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3414 rte_memcpy(actions_tx, actions,
3415 sizeof(struct rte_flow_action));
3418 case RTE_FLOW_ACTION_TYPE_COUNT:
3420 rte_memcpy(actions_tx, actions,
3421 sizeof(struct rte_flow_action));
3424 rte_memcpy(actions_rx, actions,
3425 sizeof(struct rte_flow_action));
3429 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3430 raw_encap = actions->conf;
3431 if (raw_encap->size >
3432 (sizeof(struct rte_flow_item_eth) +
3433 sizeof(struct rte_flow_item_ipv4))) {
3434 memcpy(actions_tx, actions,
3435 sizeof(struct rte_flow_action));
3439 rte_memcpy(actions_rx, actions,
3440 sizeof(struct rte_flow_action));
3444 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3445 raw_decap = actions->conf;
3446 if (raw_decap->size <
3447 (sizeof(struct rte_flow_item_eth) +
3448 sizeof(struct rte_flow_item_ipv4))) {
3449 memcpy(actions_tx, actions,
3450 sizeof(struct rte_flow_action));
3453 rte_memcpy(actions_rx, actions,
3454 sizeof(struct rte_flow_action));
3459 rte_memcpy(actions_rx, actions,
3460 sizeof(struct rte_flow_action));
3465 /* Add set meta action and end action for the Rx flow. */
3466 tag_action = actions_rx;
3467 tag_action->type = (enum rte_flow_action_type)
3468 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3470 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
3472 set_tag = (void *)actions_rx;
3473 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
3474 MLX5_ASSERT(set_tag->id > REG_NONE);
3475 set_tag->data = *flow_id;
3476 tag_action->conf = set_tag;
3477 /* Create Tx item list. */
3478 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
3479 addr = (void *)&pattern_tx[2];
3481 item->type = (enum rte_flow_item_type)
3482 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3483 tag_item = (void *)addr;
3484 tag_item->data = *flow_id;
3485 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
3486 MLX5_ASSERT(set_tag->id > REG_NONE);
3487 item->spec = tag_item;
3488 addr += sizeof(struct mlx5_rte_flow_item_tag);
3489 tag_item = (void *)addr;
3490 tag_item->data = UINT32_MAX;
3491 tag_item->id = UINT16_MAX;
3492 item->mask = tag_item;
3493 addr += sizeof(struct mlx5_rte_flow_item_tag);
3496 item->type = RTE_FLOW_ITEM_TYPE_END;
3501 * The last stage of splitting chain, just creates the subflow
3502 * without any modification.
3505 * Pointer to Ethernet device.
3507 * Parent flow structure pointer.
3508 * @param[in, out] sub_flow
3509 * Pointer to return the created subflow, may be NULL.
3510 * @param[in] prefix_layers
3511 * Prefix subflow layers, may be 0.
3513 * Flow rule attributes.
3515 * Pattern specification (list terminated by the END pattern item).
3516 * @param[in] actions
3517 * Associated actions (list terminated by the END action).
3518 * @param[in] external
3519 * This flow rule is created by request external to PMD.
3520 * @param[in] flow_idx
3521 * This memory pool index to the flow.
3523 * Perform verbose error reporting if not NULL.
3525 * 0 on success, negative value otherwise
3528 flow_create_split_inner(struct rte_eth_dev *dev,
3529 struct rte_flow *flow,
3530 struct mlx5_flow **sub_flow,
3531 uint64_t prefix_layers,
3532 const struct rte_flow_attr *attr,
3533 const struct rte_flow_item items[],
3534 const struct rte_flow_action actions[],
3535 bool external, uint32_t flow_idx,
3536 struct rte_flow_error *error)
3538 struct mlx5_flow *dev_flow;
3540 dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
3544 dev_flow->flow = flow;
3545 dev_flow->external = external;
3546 /* Subflow object was created, we must include one in the list. */
3547 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
3548 dev_flow->handle, next);
3550 * If dev_flow is as one of the suffix flow, some actions in suffix
3551 * flow may need some user defined item layer flags.
3554 dev_flow->handle->layers = prefix_layers;
3556 *sub_flow = dev_flow;
3557 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
3561 * Split the meter flow.
3563 * As meter flow will split to three sub flow, other than meter
3564 * action, the other actions make sense to only meter accepts
3565 * the packet. If it need to be dropped, no other additional
3566 * actions should be take.
3568 * One kind of special action which decapsulates the L3 tunnel
3569 * header will be in the prefix sub flow, as not to take the
3570 * L3 tunnel header into account.
3573 * Pointer to Ethernet device.
3575 * Pattern specification (list terminated by the END pattern item).
3576 * @param[out] sfx_items
3577 * Suffix flow match items (list terminated by the END pattern item).
3578 * @param[in] actions
3579 * Associated actions (list terminated by the END action).
3580 * @param[out] actions_sfx
3581 * Suffix flow actions.
3582 * @param[out] actions_pre
3583 * Prefix flow actions.
3584 * @param[out] pattern_sfx
3585 * The pattern items for the suffix flow.
3586 * @param[out] tag_sfx
3587 * Pointer to suffix flow tag.
3593 flow_meter_split_prep(struct rte_eth_dev *dev,
3594 const struct rte_flow_item items[],
3595 struct rte_flow_item sfx_items[],
3596 const struct rte_flow_action actions[],
3597 struct rte_flow_action actions_sfx[],
3598 struct rte_flow_action actions_pre[])
3600 struct rte_flow_action *tag_action = NULL;
3601 struct rte_flow_item *tag_item;
3602 struct mlx5_rte_flow_action_set_tag *set_tag;
3603 struct rte_flow_error error;
3604 const struct rte_flow_action_raw_encap *raw_encap;
3605 const struct rte_flow_action_raw_decap *raw_decap;
3606 struct mlx5_rte_flow_item_tag *tag_spec;
3607 struct mlx5_rte_flow_item_tag *tag_mask;
3609 bool copy_vlan = false;
3611 /* Prepare the actions for prefix and suffix flow. */
3612 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3613 struct rte_flow_action **action_cur = NULL;
3615 switch (actions->type) {
3616 case RTE_FLOW_ACTION_TYPE_METER:
3617 /* Add the extra tag action first. */
3618 tag_action = actions_pre;
3619 tag_action->type = (enum rte_flow_action_type)
3620 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3622 action_cur = &actions_pre;
3624 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3625 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3626 action_cur = &actions_pre;
3628 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3629 raw_encap = actions->conf;
3630 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
3631 action_cur = &actions_pre;
3633 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3634 raw_decap = actions->conf;
3635 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3636 action_cur = &actions_pre;
3638 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3639 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3646 action_cur = &actions_sfx;
3647 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
3650 /* Add end action to the actions. */
3651 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
3652 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
3655 set_tag = (void *)actions_pre;
3656 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3658 * Get the id from the qrss_pool to make qrss share the id with meter.
3660 tag_id = flow_qrss_get_id(dev);
3661 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
3663 tag_action->conf = set_tag;
3664 /* Prepare the suffix subflow items. */
3665 tag_item = sfx_items++;
3666 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3667 int item_type = items->type;
3669 switch (item_type) {
3670 case RTE_FLOW_ITEM_TYPE_PORT_ID:
3671 memcpy(sfx_items, items, sizeof(*sfx_items));
3674 case RTE_FLOW_ITEM_TYPE_VLAN:
3676 memcpy(sfx_items, items, sizeof(*sfx_items));
3678 * Convert to internal match item, it is used
3679 * for vlan push and set vid.
3681 sfx_items->type = (enum rte_flow_item_type)
3682 MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
3690 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
3692 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
3693 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
3694 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3695 tag_mask = tag_spec + 1;
3696 tag_mask->data = 0xffffff00;
3697 tag_item->type = (enum rte_flow_item_type)
3698 MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3699 tag_item->spec = tag_spec;
3700 tag_item->last = NULL;
3701 tag_item->mask = tag_mask;
3706 * Split action list having QUEUE/RSS for metadata register copy.
3708 * Once Q/RSS action is detected in user's action list, the flow action
3709 * should be split in order to copy metadata registers, which will happen in
3711 * - CQE->flow_tag := reg_c[1] (MARK)
3712 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3713 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
3714 * This is because the last action of each flow must be a terminal action
3715 * (QUEUE, RSS or DROP).
3717 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
3718 * stored and kept in the mlx5_flow structure per each sub_flow.
3720 * The Q/RSS action is replaced with,
3721 * - SET_TAG, setting the allocated flow ID to reg_c[2].
3722 * And the following JUMP action is added at the end,
3723 * - JUMP, to RX_CP_TBL.
3725 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
3726 * flow_create_split_metadata() routine. The flow will look like,
3727 * - If flow ID matches (reg_c[2]), perform Q/RSS.
3730 * Pointer to Ethernet device.
3731 * @param[out] split_actions
3732 * Pointer to store split actions to jump to CP_TBL.
3733 * @param[in] actions
3734 * Pointer to the list of original flow actions.
3736 * Pointer to the Q/RSS action.
3737 * @param[in] actions_n
3738 * Number of original actions.
3740 * Perform verbose error reporting if not NULL.
3743 * non-zero unique flow_id on success, otherwise 0 and
3744 * error/rte_error are set.
3747 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
3748 struct rte_flow_action *split_actions,
3749 const struct rte_flow_action *actions,
3750 const struct rte_flow_action *qrss,
3751 int actions_n, struct rte_flow_error *error)
3753 struct mlx5_rte_flow_action_set_tag *set_tag;
3754 struct rte_flow_action_jump *jump;
3755 const int qrss_idx = qrss - actions;
3756 uint32_t flow_id = 0;
3760 * Given actions will be split
3761 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
3762 * - Add jump to mreg CP_TBL.
3763 * As a result, there will be one more action.
3766 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
3767 set_tag = (void *)(split_actions + actions_n);
3769 * If tag action is not set to void(it means we are not the meter
3770 * suffix flow), add the tag action. Since meter suffix flow already
3771 * has the tag added.
3773 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
3775 * Allocate the new subflow ID. This one is unique within
3776 * device and not shared with representors. Otherwise,
3777 * we would have to resolve multi-thread access synch
3778 * issue. Each flow on the shared device is appended
3779 * with source vport identifier, so the resulting
3780 * flows will be unique in the shared (by master and
3781 * representors) domain even if they have coinciding
3784 flow_id = flow_qrss_get_id(dev);
3786 return rte_flow_error_set(error, ENOMEM,
3787 RTE_FLOW_ERROR_TYPE_ACTION,
3788 NULL, "can't allocate id "
3789 "for split Q/RSS subflow");
3790 /* Internal SET_TAG action to set flow ID. */
3791 *set_tag = (struct mlx5_rte_flow_action_set_tag){
3794 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
3798 /* Construct new actions array. */
3799 /* Replace QUEUE/RSS action. */
3800 split_actions[qrss_idx] = (struct rte_flow_action){
3801 .type = (enum rte_flow_action_type)
3802 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
3806 /* JUMP action to jump to mreg copy table (CP_TBL). */
3807 jump = (void *)(set_tag + 1);
3808 *jump = (struct rte_flow_action_jump){
3809 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3811 split_actions[actions_n - 2] = (struct rte_flow_action){
3812 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3815 split_actions[actions_n - 1] = (struct rte_flow_action){
3816 .type = RTE_FLOW_ACTION_TYPE_END,
3822 * Extend the given action list for Tx metadata copy.
3824 * Copy the given action list to the ext_actions and add flow metadata register
3825 * copy action in order to copy reg_a set by WQE to reg_c[0].
3827 * @param[out] ext_actions
3828 * Pointer to the extended action list.
3829 * @param[in] actions
3830 * Pointer to the list of actions.
3831 * @param[in] actions_n
3832 * Number of actions in the list.
3834 * Perform verbose error reporting if not NULL.
3835 * @param[in] encap_idx
3836 * The encap action inndex.
3839 * 0 on success, negative value otherwise
3842 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
3843 struct rte_flow_action *ext_actions,
3844 const struct rte_flow_action *actions,
3845 int actions_n, struct rte_flow_error *error,
3848 struct mlx5_flow_action_copy_mreg *cp_mreg =
3849 (struct mlx5_flow_action_copy_mreg *)
3850 (ext_actions + actions_n + 1);
3853 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3857 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
3862 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
3863 if (encap_idx == actions_n - 1) {
3864 ext_actions[actions_n - 1] = (struct rte_flow_action){
3865 .type = (enum rte_flow_action_type)
3866 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3869 ext_actions[actions_n] = (struct rte_flow_action){
3870 .type = RTE_FLOW_ACTION_TYPE_END,
3873 ext_actions[encap_idx] = (struct rte_flow_action){
3874 .type = (enum rte_flow_action_type)
3875 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3878 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
3879 sizeof(*ext_actions) * (actions_n - encap_idx));
3885 * The splitting for metadata feature.
3887 * - Q/RSS action on NIC Rx should be split in order to pass by
3888 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3889 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3891 * - All the actions on NIC Tx should have a mreg copy action to
3892 * copy reg_a from WQE to reg_c[0].
3895 * Pointer to Ethernet device.
3897 * Parent flow structure pointer.
3898 * @param[in] prefix_layers
3899 * Prefix flow layer flags.
3901 * Flow rule attributes.
3903 * Pattern specification (list terminated by the END pattern item).
3904 * @param[in] actions
3905 * Associated actions (list terminated by the END action).
3906 * @param[in] external
3907 * This flow rule is created by request external to PMD.
3908 * @param[in] flow_idx
3909 * This memory pool index to the flow.
3911 * Perform verbose error reporting if not NULL.
3913 * 0 on success, negative value otherwise
3916 flow_create_split_metadata(struct rte_eth_dev *dev,
3917 struct rte_flow *flow,
3918 uint64_t prefix_layers,
3919 const struct rte_flow_attr *attr,
3920 const struct rte_flow_item items[],
3921 const struct rte_flow_action actions[],
3922 bool external, uint32_t flow_idx,
3923 struct rte_flow_error *error)
3925 struct mlx5_priv *priv = dev->data->dev_private;
3926 struct mlx5_dev_config *config = &priv->config;
3927 const struct rte_flow_action *qrss = NULL;
3928 struct rte_flow_action *ext_actions = NULL;
3929 struct mlx5_flow *dev_flow = NULL;
3930 uint32_t qrss_id = 0;
3937 /* Check whether extensive metadata feature is engaged. */
3938 if (!config->dv_flow_en ||
3939 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3940 !mlx5_flow_ext_mreg_supported(dev))
3941 return flow_create_split_inner(dev, flow, NULL, prefix_layers,
3942 attr, items, actions, external,
3944 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
3947 /* Exclude hairpin flows from splitting. */
3948 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
3949 const struct rte_flow_action_queue *queue;
3952 if (mlx5_rxq_get_type(dev, queue->index) ==
3953 MLX5_RXQ_TYPE_HAIRPIN)
3955 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
3956 const struct rte_flow_action_rss *rss;
3959 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
3960 MLX5_RXQ_TYPE_HAIRPIN)
3965 /* Check if it is in meter suffix table. */
3966 mtr_sfx = attr->group == (attr->transfer ?
3967 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
3968 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
3970 * Q/RSS action on NIC Rx should be split in order to pass by
3971 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3972 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3974 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3975 sizeof(struct rte_flow_action_set_tag) +
3976 sizeof(struct rte_flow_action_jump);
3977 ext_actions = rte_zmalloc(__func__, act_size, 0);
3979 return rte_flow_error_set(error, ENOMEM,
3980 RTE_FLOW_ERROR_TYPE_ACTION,
3981 NULL, "no memory to split "
3984 * If we are the suffix flow of meter, tag already exist.
3985 * Set the tag action to void.
3988 ext_actions[qrss - actions].type =
3989 RTE_FLOW_ACTION_TYPE_VOID;
3991 ext_actions[qrss - actions].type =
3992 (enum rte_flow_action_type)
3993 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3995 * Create the new actions list with removed Q/RSS action
3996 * and appended set tag and jump to register copy table
3997 * (RX_CP_TBL). We should preallocate unique tag ID here
3998 * in advance, because it is needed for set tag action.
4000 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
4001 qrss, actions_n, error);
4002 if (!mtr_sfx && !qrss_id) {
4006 } else if (attr->egress && !attr->transfer) {
4008 * All the actions on NIC Tx should have a metadata register
4009 * copy action to copy reg_a from WQE to reg_c[meta]
4011 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
4012 sizeof(struct mlx5_flow_action_copy_mreg);
4013 ext_actions = rte_zmalloc(__func__, act_size, 0);
4015 return rte_flow_error_set(error, ENOMEM,
4016 RTE_FLOW_ERROR_TYPE_ACTION,
4017 NULL, "no memory to split "
4019 /* Create the action list appended with copy register. */
4020 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
4021 actions_n, error, encap_idx);
4025 /* Add the unmodified original or prefix subflow. */
4026 ret = flow_create_split_inner(dev, flow, &dev_flow, prefix_layers, attr,
4027 items, ext_actions ? ext_actions :
4028 actions, external, flow_idx, error);
4031 MLX5_ASSERT(dev_flow);
4033 const struct rte_flow_attr q_attr = {
4034 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
4037 /* Internal PMD action to set register. */
4038 struct mlx5_rte_flow_item_tag q_tag_spec = {
4042 struct rte_flow_item q_items[] = {
4044 .type = (enum rte_flow_item_type)
4045 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
4046 .spec = &q_tag_spec,
4051 .type = RTE_FLOW_ITEM_TYPE_END,
4054 struct rte_flow_action q_actions[] = {
4060 .type = RTE_FLOW_ACTION_TYPE_END,
4063 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
4066 * Configure the tag item only if there is no meter subflow.
4067 * Since tag is already marked in the meter suffix subflow
4068 * we can just use the meter suffix items as is.
4071 /* Not meter subflow. */
4072 MLX5_ASSERT(!mtr_sfx);
4074 * Put unique id in prefix flow due to it is destroyed
4075 * after suffix flow and id will be freed after there
4076 * is no actual flows with this id and identifier
4077 * reallocation becomes possible (for example, for
4078 * other flows in other threads).
4080 dev_flow->handle->split_flow_id = qrss_id;
4081 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
4085 q_tag_spec.id = ret;
4088 /* Add suffix subflow to execute Q/RSS. */
4089 ret = flow_create_split_inner(dev, flow, &dev_flow, layers,
4090 &q_attr, mtr_sfx ? items :
4092 external, flow_idx, error);
4095 /* qrss ID should be freed if failed. */
4097 MLX5_ASSERT(dev_flow);
4102 * We do not destroy the partially created sub_flows in case of error.
4103 * These ones are included into parent flow list and will be destroyed
4104 * by flow_drv_destroy.
4106 flow_qrss_free_id(dev, qrss_id);
4107 rte_free(ext_actions);
4112 * The splitting for meter feature.
4114 * - The meter flow will be split to two flows as prefix and
4115 * suffix flow. The packets make sense only it pass the prefix
4118 * - Reg_C_5 is used for the packet to match betweend prefix and
4122 * Pointer to Ethernet device.
4124 * Parent flow structure pointer.
4126 * Flow rule attributes.
4128 * Pattern specification (list terminated by the END pattern item).
4129 * @param[in] actions
4130 * Associated actions (list terminated by the END action).
4131 * @param[in] external
4132 * This flow rule is created by request external to PMD.
4133 * @param[in] flow_idx
4134 * This memory pool index to the flow.
4136 * Perform verbose error reporting if not NULL.
4138 * 0 on success, negative value otherwise
4141 flow_create_split_meter(struct rte_eth_dev *dev,
4142 struct rte_flow *flow,
4143 const struct rte_flow_attr *attr,
4144 const struct rte_flow_item items[],
4145 const struct rte_flow_action actions[],
4146 bool external, uint32_t flow_idx,
4147 struct rte_flow_error *error)
4149 struct mlx5_priv *priv = dev->data->dev_private;
4150 struct rte_flow_action *sfx_actions = NULL;
4151 struct rte_flow_action *pre_actions = NULL;
4152 struct rte_flow_item *sfx_items = NULL;
4153 struct mlx5_flow *dev_flow = NULL;
4154 struct rte_flow_attr sfx_attr = *attr;
4156 uint32_t mtr_tag_id = 0;
4163 actions_n = flow_check_meter_action(actions, &mtr);
4165 /* The five prefix actions: meter, decap, encap, tag, end. */
4166 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
4167 sizeof(struct mlx5_rte_flow_action_set_tag);
4168 /* tag, vlan, port id, end. */
4169 #define METER_SUFFIX_ITEM 4
4170 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
4171 sizeof(struct mlx5_rte_flow_item_tag) * 2;
4172 sfx_actions = rte_zmalloc(__func__, (act_size + item_size), 0);
4174 return rte_flow_error_set(error, ENOMEM,
4175 RTE_FLOW_ERROR_TYPE_ACTION,
4176 NULL, "no memory to split "
4178 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4180 pre_actions = sfx_actions + actions_n;
4181 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
4182 actions, sfx_actions,
4188 /* Add the prefix subflow. */
4189 ret = flow_create_split_inner(dev, flow, &dev_flow, 0, attr,
4190 items, pre_actions, external,
4196 dev_flow->handle->split_flow_id = mtr_tag_id;
4197 /* Setting the sfx group atrr. */
4198 sfx_attr.group = sfx_attr.transfer ?
4199 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4200 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4202 /* Add the prefix subflow. */
4203 ret = flow_create_split_metadata(dev, flow, dev_flow ?
4204 flow_get_prefix_layer_flags(dev_flow) :
4206 sfx_items ? sfx_items : items,
4207 sfx_actions ? sfx_actions : actions,
4208 external, flow_idx, error);
4211 rte_free(sfx_actions);
4216 * Split the flow to subflow set. The splitters might be linked
4217 * in the chain, like this:
4218 * flow_create_split_outer() calls:
4219 * flow_create_split_meter() calls:
4220 * flow_create_split_metadata(meter_subflow_0) calls:
4221 * flow_create_split_inner(metadata_subflow_0)
4222 * flow_create_split_inner(metadata_subflow_1)
4223 * flow_create_split_inner(metadata_subflow_2)
4224 * flow_create_split_metadata(meter_subflow_1) calls:
4225 * flow_create_split_inner(metadata_subflow_0)
4226 * flow_create_split_inner(metadata_subflow_1)
4227 * flow_create_split_inner(metadata_subflow_2)
4229 * This provide flexible way to add new levels of flow splitting.
4230 * The all of successfully created subflows are included to the
4231 * parent flow dev_flow list.
4234 * Pointer to Ethernet device.
4236 * Parent flow structure pointer.
4238 * Flow rule attributes.
4240 * Pattern specification (list terminated by the END pattern item).
4241 * @param[in] actions
4242 * Associated actions (list terminated by the END action).
4243 * @param[in] external
4244 * This flow rule is created by request external to PMD.
4245 * @param[in] flow_idx
4246 * This memory pool index to the flow.
4248 * Perform verbose error reporting if not NULL.
4250 * 0 on success, negative value otherwise
4253 flow_create_split_outer(struct rte_eth_dev *dev,
4254 struct rte_flow *flow,
4255 const struct rte_flow_attr *attr,
4256 const struct rte_flow_item items[],
4257 const struct rte_flow_action actions[],
4258 bool external, uint32_t flow_idx,
4259 struct rte_flow_error *error)
4263 ret = flow_create_split_meter(dev, flow, attr, items,
4264 actions, external, flow_idx, error);
4265 MLX5_ASSERT(ret <= 0);
4270 * Create a flow and add it to @p list.
4273 * Pointer to Ethernet device.
4275 * Pointer to a TAILQ flow list. If this parameter NULL,
4276 * no list insertion occurred, flow is just created,
4277 * this is caller's responsibility to track the
4280 * Flow rule attributes.
4282 * Pattern specification (list terminated by the END pattern item).
4283 * @param[in] actions
4284 * Associated actions (list terminated by the END action).
4285 * @param[in] external
4286 * This flow rule is created by request external to PMD.
4288 * Perform verbose error reporting if not NULL.
4291 * A flow index on success, 0 otherwise and rte_errno is set.
4294 flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
4295 const struct rte_flow_attr *attr,
4296 const struct rte_flow_item items[],
4297 const struct rte_flow_action actions[],
4298 bool external, struct rte_flow_error *error)
4300 struct mlx5_priv *priv = dev->data->dev_private;
4301 struct rte_flow *flow = NULL;
4302 struct mlx5_flow *dev_flow;
4303 const struct rte_flow_action_rss *rss;
4305 struct rte_flow_expand_rss buf;
4306 uint8_t buffer[2048];
4309 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4310 uint8_t buffer[2048];
4313 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4314 uint8_t buffer[2048];
4315 } actions_hairpin_tx;
4317 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
4318 uint8_t buffer[2048];
4320 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
4321 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
4322 priv->rss_desc)[!!priv->flow_idx];
4323 const struct rte_flow_action *p_actions_rx = actions;
4327 uint32_t hairpin_id = 0;
4328 struct rte_flow_attr attr_tx = { .priority = 0 };
4331 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4332 ret = flow_drv_validate(dev, attr, items, p_actions_rx,
4333 external, hairpin_flow, error);
4336 if (hairpin_flow > 0) {
4337 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
4341 flow_hairpin_split(dev, actions, actions_rx.actions,
4342 actions_hairpin_tx.actions, items_tx.items,
4344 p_actions_rx = actions_rx.actions;
4346 flow = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], &idx);
4349 goto error_before_flow;
4351 flow->drv_type = flow_get_drv_type(dev, attr);
4352 if (hairpin_id != 0)
4353 flow->hairpin_flow_id = hairpin_id;
4354 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
4355 flow->drv_type < MLX5_FLOW_TYPE_MAX);
4356 memset(rss_desc, 0, sizeof(*rss_desc));
4357 rss = flow_get_rss_action(p_actions_rx);
4360 * The following information is required by
4361 * mlx5_flow_hashfields_adjust() in advance.
4363 rss_desc->level = rss->level;
4364 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
4365 rss_desc->types = !rss->types ? ETH_RSS_IP : rss->types;
4367 flow->dev_handles = 0;
4368 if (rss && rss->types) {
4369 unsigned int graph_root;
4371 graph_root = find_graph_root(items, rss->level);
4372 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
4374 mlx5_support_expansion,
4376 MLX5_ASSERT(ret > 0 &&
4377 (unsigned int)ret < sizeof(expand_buffer.buffer));
4380 buf->entry[0].pattern = (void *)(uintptr_t)items;
4383 * Record the start index when there is a nested call. All sub-flows
4384 * need to be translated before another calling.
4385 * No need to use ping-pong buffer to save memory here.
4387 if (priv->flow_idx) {
4388 MLX5_ASSERT(!priv->flow_nested_idx);
4389 priv->flow_nested_idx = priv->flow_idx;
4391 for (i = 0; i < buf->entries; ++i) {
4393 * The splitter may create multiple dev_flows,
4394 * depending on configuration. In the simplest
4395 * case it just creates unmodified original flow.
4397 ret = flow_create_split_outer(dev, flow, attr,
4398 buf->entry[i].pattern,
4399 p_actions_rx, external, idx,
4404 /* Create the tx flow. */
4406 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
4407 attr_tx.ingress = 0;
4409 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
4410 actions_hairpin_tx.actions,
4414 dev_flow->flow = flow;
4415 dev_flow->external = 0;
4416 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
4417 dev_flow->handle, next);
4418 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
4420 actions_hairpin_tx.actions, error);
4425 * Update the metadata register copy table. If extensive
4426 * metadata feature is enabled and registers are supported
4427 * we might create the extra rte_flow for each unique
4428 * MARK/FLAG action ID.
4430 * The table is updated for ingress Flows only, because
4431 * the egress Flows belong to the different device and
4432 * copy table should be updated in peer NIC Rx domain.
4434 if (attr->ingress &&
4435 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
4436 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
4441 * If the flow is external (from application) OR device is started, then
4442 * the flow will be applied immediately.
4444 if (external || dev->data->dev_started) {
4445 ret = flow_drv_apply(dev, flow, error);
4450 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list, idx,
4452 flow_rxq_flags_set(dev, flow);
4453 /* Nested flow creation index recovery. */
4454 priv->flow_idx = priv->flow_nested_idx;
4455 if (priv->flow_nested_idx)
4456 priv->flow_nested_idx = 0;
4460 ret = rte_errno; /* Save rte_errno before cleanup. */
4461 flow_mreg_del_copy_action(dev, flow);
4462 flow_drv_destroy(dev, flow);
4463 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], idx);
4464 rte_errno = ret; /* Restore rte_errno. */
4468 mlx5_flow_id_release(priv->sh->flow_id_pool,
4471 priv->flow_idx = priv->flow_nested_idx;
4472 if (priv->flow_nested_idx)
4473 priv->flow_nested_idx = 0;
4478 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
4479 * incoming packets to table 1.
4481 * Other flow rules, requested for group n, will be created in
4482 * e-switch table n+1.
4483 * Jump action to e-switch group n will be created to group n+1.
4485 * Used when working in switchdev mode, to utilise advantages of table 1
4489 * Pointer to Ethernet device.
4492 * Pointer to flow on success, NULL otherwise and rte_errno is set.
4495 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
4497 const struct rte_flow_attr attr = {
4504 const struct rte_flow_item pattern = {
4505 .type = RTE_FLOW_ITEM_TYPE_END,
4507 struct rte_flow_action_jump jump = {
4510 const struct rte_flow_action actions[] = {
4512 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4516 .type = RTE_FLOW_ACTION_TYPE_END,
4519 struct mlx5_priv *priv = dev->data->dev_private;
4520 struct rte_flow_error error;
4522 return (void *)(uintptr_t)flow_list_create(dev, &priv->ctrl_flows,
4524 actions, false, &error);
4528 * Validate a flow supported by the NIC.
4530 * @see rte_flow_validate()
4534 mlx5_flow_validate(struct rte_eth_dev *dev,
4535 const struct rte_flow_attr *attr,
4536 const struct rte_flow_item items[],
4537 const struct rte_flow_action actions[],
4538 struct rte_flow_error *error)
4542 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4543 return flow_drv_validate(dev, attr, items, actions,
4544 true, hairpin_flow, error);
4550 * @see rte_flow_create()
4554 mlx5_flow_create(struct rte_eth_dev *dev,
4555 const struct rte_flow_attr *attr,
4556 const struct rte_flow_item items[],
4557 const struct rte_flow_action actions[],
4558 struct rte_flow_error *error)
4560 struct mlx5_priv *priv = dev->data->dev_private;
4563 * If the device is not started yet, it is not allowed to created a
4564 * flow from application. PMD default flows and traffic control flows
4567 if (unlikely(!dev->data->dev_started)) {
4568 DRV_LOG(DEBUG, "port %u is not started when "
4569 "inserting a flow", dev->data->port_id);
4570 rte_flow_error_set(error, ENODEV,
4571 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4573 "port not started");
4576 return (void *)(uintptr_t)flow_list_create(dev, &priv->flows,
4577 attr, items, actions, true, error);
4581 * Destroy a flow in a list.
4584 * Pointer to Ethernet device.
4586 * Pointer to the Indexed flow list. If this parameter NULL,
4587 * there is no flow removal from the list. Be noted that as
4588 * flow is add to the indexed list, memory of the indexed
4589 * list points to maybe changed as flow destroyed.
4590 * @param[in] flow_idx
4591 * Index of flow to destroy.
4594 flow_list_destroy(struct rte_eth_dev *dev, uint32_t *list,
4597 struct mlx5_priv *priv = dev->data->dev_private;
4598 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
4599 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
4600 [MLX5_IPOOL_RTE_FLOW], flow_idx);
4605 * Update RX queue flags only if port is started, otherwise it is
4608 if (dev->data->dev_started)
4609 flow_rxq_flags_trim(dev, flow);
4610 if (flow->hairpin_flow_id)
4611 mlx5_flow_id_release(priv->sh->flow_id_pool,
4612 flow->hairpin_flow_id);
4613 flow_drv_destroy(dev, flow);
4615 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], list,
4616 flow_idx, flow, next);
4617 flow_mreg_del_copy_action(dev, flow);
4619 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
4620 if (priv_fdir_flow->rix_flow == flow_idx)
4623 if (priv_fdir_flow) {
4624 LIST_REMOVE(priv_fdir_flow, next);
4625 rte_free(priv_fdir_flow->fdir);
4626 rte_free(priv_fdir_flow);
4629 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
4633 * Destroy all flows.
4636 * Pointer to Ethernet device.
4638 * Pointer to the Indexed flow list.
4640 * If flushing is called avtively.
4643 mlx5_flow_list_flush(struct rte_eth_dev *dev, uint32_t *list, bool active)
4645 uint32_t num_flushed = 0;
4648 flow_list_destroy(dev, list, *list);
4652 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
4653 dev->data->port_id, num_flushed);
4661 * Pointer to Ethernet device.
4663 * Pointer to the Indexed flow list.
4666 mlx5_flow_stop(struct rte_eth_dev *dev, uint32_t *list)
4668 struct mlx5_priv *priv = dev->data->dev_private;
4669 struct rte_flow *flow = NULL;
4672 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
4674 flow_drv_remove(dev, flow);
4675 flow_mreg_stop_copy_action(dev, flow);
4677 flow_mreg_del_default_copy_action(dev);
4678 flow_rxq_flags_clear(dev);
4685 * Pointer to Ethernet device.
4687 * Pointer to the Indexed flow list.
4690 * 0 on success, a negative errno value otherwise and rte_errno is set.
4693 mlx5_flow_start(struct rte_eth_dev *dev, uint32_t *list)
4695 struct mlx5_priv *priv = dev->data->dev_private;
4696 struct rte_flow *flow = NULL;
4697 struct rte_flow_error error;
4701 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4702 ret = flow_mreg_add_default_copy_action(dev, &error);
4705 /* Apply Flows created by application. */
4706 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], *list, idx,
4708 ret = flow_mreg_start_copy_action(dev, flow);
4711 ret = flow_drv_apply(dev, flow, &error);
4714 flow_rxq_flags_set(dev, flow);
4718 ret = rte_errno; /* Save rte_errno before cleanup. */
4719 mlx5_flow_stop(dev, list);
4720 rte_errno = ret; /* Restore rte_errno. */
4725 * Stop all default actions for flows.
4728 * Pointer to Ethernet device.
4731 mlx5_flow_stop_default(struct rte_eth_dev *dev)
4733 flow_mreg_del_default_copy_action(dev);
4734 flow_rxq_flags_clear(dev);
4738 * Start all default actions for flows.
4741 * Pointer to Ethernet device.
4743 * 0 on success, a negative errno value otherwise and rte_errno is set.
4746 mlx5_flow_start_default(struct rte_eth_dev *dev)
4748 struct rte_flow_error error;
4750 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4751 return flow_mreg_add_default_copy_action(dev, &error);
4755 * Allocate intermediate resources for flow creation.
4758 * Pointer to Ethernet device.
4761 mlx5_flow_alloc_intermediate(struct rte_eth_dev *dev)
4763 struct mlx5_priv *priv = dev->data->dev_private;
4765 if (!priv->inter_flows) {
4766 priv->inter_flows = rte_calloc(__func__, 1,
4767 MLX5_NUM_MAX_DEV_FLOWS *
4768 sizeof(struct mlx5_flow) +
4769 (sizeof(struct mlx5_flow_rss_desc) +
4770 sizeof(uint16_t) * UINT16_MAX) * 2, 0);
4771 if (!priv->inter_flows) {
4772 DRV_LOG(ERR, "can't allocate intermediate memory.");
4776 priv->rss_desc = &((struct mlx5_flow *)priv->inter_flows)
4777 [MLX5_NUM_MAX_DEV_FLOWS];
4778 /* Reset the index. */
4780 priv->flow_nested_idx = 0;
4784 * Free intermediate resources for flows.
4787 * Pointer to Ethernet device.
4790 mlx5_flow_free_intermediate(struct rte_eth_dev *dev)
4792 struct mlx5_priv *priv = dev->data->dev_private;
4794 rte_free(priv->inter_flows);
4795 priv->inter_flows = NULL;
4799 * Verify the flow list is empty
4802 * Pointer to Ethernet device.
4804 * @return the number of flows not released.
4807 mlx5_flow_verify(struct rte_eth_dev *dev)
4809 struct mlx5_priv *priv = dev->data->dev_private;
4810 struct rte_flow *flow;
4814 ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], priv->flows, idx,
4816 DRV_LOG(DEBUG, "port %u flow %p still referenced",
4817 dev->data->port_id, (void *)flow);
4824 * Enable default hairpin egress flow.
4827 * Pointer to Ethernet device.
4832 * 0 on success, a negative errno value otherwise and rte_errno is set.
4835 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
4838 struct mlx5_priv *priv = dev->data->dev_private;
4839 const struct rte_flow_attr attr = {
4843 struct mlx5_rte_flow_item_tx_queue queue_spec = {
4846 struct mlx5_rte_flow_item_tx_queue queue_mask = {
4847 .queue = UINT32_MAX,
4849 struct rte_flow_item items[] = {
4851 .type = (enum rte_flow_item_type)
4852 MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
4853 .spec = &queue_spec,
4855 .mask = &queue_mask,
4858 .type = RTE_FLOW_ITEM_TYPE_END,
4861 struct rte_flow_action_jump jump = {
4862 .group = MLX5_HAIRPIN_TX_TABLE,
4864 struct rte_flow_action actions[2];
4866 struct rte_flow_error error;
4868 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
4869 actions[0].conf = &jump;
4870 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
4871 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
4872 &attr, items, actions, false, &error);
4875 "Failed to create ctrl flow: rte_errno(%d),"
4876 " type(%d), message(%s)",
4877 rte_errno, error.type,
4878 error.message ? error.message : " (no stated reason)");
4885 * Enable a control flow configured from the control plane.
4888 * Pointer to Ethernet device.
4890 * An Ethernet flow spec to apply.
4892 * An Ethernet flow mask to apply.
4894 * A VLAN flow spec to apply.
4896 * A VLAN flow mask to apply.
4899 * 0 on success, a negative errno value otherwise and rte_errno is set.
4902 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
4903 struct rte_flow_item_eth *eth_spec,
4904 struct rte_flow_item_eth *eth_mask,
4905 struct rte_flow_item_vlan *vlan_spec,
4906 struct rte_flow_item_vlan *vlan_mask)
4908 struct mlx5_priv *priv = dev->data->dev_private;
4909 const struct rte_flow_attr attr = {
4911 .priority = MLX5_FLOW_PRIO_RSVD,
4913 struct rte_flow_item items[] = {
4915 .type = RTE_FLOW_ITEM_TYPE_ETH,
4921 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
4922 RTE_FLOW_ITEM_TYPE_END,
4928 .type = RTE_FLOW_ITEM_TYPE_END,
4931 uint16_t queue[priv->reta_idx_n];
4932 struct rte_flow_action_rss action_rss = {
4933 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4935 .types = priv->rss_conf.rss_hf,
4936 .key_len = priv->rss_conf.rss_key_len,
4937 .queue_num = priv->reta_idx_n,
4938 .key = priv->rss_conf.rss_key,
4941 struct rte_flow_action actions[] = {
4943 .type = RTE_FLOW_ACTION_TYPE_RSS,
4944 .conf = &action_rss,
4947 .type = RTE_FLOW_ACTION_TYPE_END,
4951 struct rte_flow_error error;
4954 if (!priv->reta_idx_n || !priv->rxqs_n) {
4957 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
4958 action_rss.types = 0;
4959 for (i = 0; i != priv->reta_idx_n; ++i)
4960 queue[i] = (*priv->reta_idx)[i];
4961 flow_idx = flow_list_create(dev, &priv->ctrl_flows,
4962 &attr, items, actions, false, &error);
4969 * Enable a flow control configured from the control plane.
4972 * Pointer to Ethernet device.
4974 * An Ethernet flow spec to apply.
4976 * An Ethernet flow mask to apply.
4979 * 0 on success, a negative errno value otherwise and rte_errno is set.
4982 mlx5_ctrl_flow(struct rte_eth_dev *dev,
4983 struct rte_flow_item_eth *eth_spec,
4984 struct rte_flow_item_eth *eth_mask)
4986 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
4992 * @see rte_flow_destroy()
4996 mlx5_flow_destroy(struct rte_eth_dev *dev,
4997 struct rte_flow *flow,
4998 struct rte_flow_error *error __rte_unused)
5000 struct mlx5_priv *priv = dev->data->dev_private;
5002 flow_list_destroy(dev, &priv->flows, (uintptr_t)(void *)flow);
5007 * Destroy all flows.
5009 * @see rte_flow_flush()
5013 mlx5_flow_flush(struct rte_eth_dev *dev,
5014 struct rte_flow_error *error __rte_unused)
5016 struct mlx5_priv *priv = dev->data->dev_private;
5018 mlx5_flow_list_flush(dev, &priv->flows, false);
5025 * @see rte_flow_isolate()
5029 mlx5_flow_isolate(struct rte_eth_dev *dev,
5031 struct rte_flow_error *error)
5033 struct mlx5_priv *priv = dev->data->dev_private;
5035 if (dev->data->dev_started) {
5036 rte_flow_error_set(error, EBUSY,
5037 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5039 "port must be stopped first");
5042 priv->isolated = !!enable;
5044 dev->dev_ops = &mlx5_dev_ops_isolate;
5046 dev->dev_ops = &mlx5_dev_ops;
5053 * @see rte_flow_query()
5057 flow_drv_query(struct rte_eth_dev *dev,
5059 const struct rte_flow_action *actions,
5061 struct rte_flow_error *error)
5063 struct mlx5_priv *priv = dev->data->dev_private;
5064 const struct mlx5_flow_driver_ops *fops;
5065 struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool
5066 [MLX5_IPOOL_RTE_FLOW],
5068 enum mlx5_flow_drv_type ftype;
5071 return rte_flow_error_set(error, ENOENT,
5072 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5074 "invalid flow handle");
5076 ftype = flow->drv_type;
5077 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
5078 fops = flow_get_drv_ops(ftype);
5080 return fops->query(dev, flow, actions, data, error);
5086 * @see rte_flow_query()
5090 mlx5_flow_query(struct rte_eth_dev *dev,
5091 struct rte_flow *flow,
5092 const struct rte_flow_action *actions,
5094 struct rte_flow_error *error)
5098 ret = flow_drv_query(dev, (uintptr_t)(void *)flow, actions, data,
5106 * Convert a flow director filter to a generic flow.
5109 * Pointer to Ethernet device.
5110 * @param fdir_filter
5111 * Flow director filter to add.
5113 * Generic flow parameters structure.
5116 * 0 on success, a negative errno value otherwise and rte_errno is set.
5119 flow_fdir_filter_convert(struct rte_eth_dev *dev,
5120 const struct rte_eth_fdir_filter *fdir_filter,
5121 struct mlx5_fdir *attributes)
5123 struct mlx5_priv *priv = dev->data->dev_private;
5124 const struct rte_eth_fdir_input *input = &fdir_filter->input;
5125 const struct rte_eth_fdir_masks *mask =
5126 &dev->data->dev_conf.fdir_conf.mask;
5128 /* Validate queue number. */
5129 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
5130 DRV_LOG(ERR, "port %u invalid queue number %d",
5131 dev->data->port_id, fdir_filter->action.rx_queue);
5135 attributes->attr.ingress = 1;
5136 attributes->items[0] = (struct rte_flow_item) {
5137 .type = RTE_FLOW_ITEM_TYPE_ETH,
5138 .spec = &attributes->l2,
5139 .mask = &attributes->l2_mask,
5141 switch (fdir_filter->action.behavior) {
5142 case RTE_ETH_FDIR_ACCEPT:
5143 attributes->actions[0] = (struct rte_flow_action){
5144 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
5145 .conf = &attributes->queue,
5148 case RTE_ETH_FDIR_REJECT:
5149 attributes->actions[0] = (struct rte_flow_action){
5150 .type = RTE_FLOW_ACTION_TYPE_DROP,
5154 DRV_LOG(ERR, "port %u invalid behavior %d",
5156 fdir_filter->action.behavior);
5157 rte_errno = ENOTSUP;
5160 attributes->queue.index = fdir_filter->action.rx_queue;
5162 switch (fdir_filter->input.flow_type) {
5163 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
5164 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
5165 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
5166 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
5167 .src_addr = input->flow.ip4_flow.src_ip,
5168 .dst_addr = input->flow.ip4_flow.dst_ip,
5169 .time_to_live = input->flow.ip4_flow.ttl,
5170 .type_of_service = input->flow.ip4_flow.tos,
5172 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
5173 .src_addr = mask->ipv4_mask.src_ip,
5174 .dst_addr = mask->ipv4_mask.dst_ip,
5175 .time_to_live = mask->ipv4_mask.ttl,
5176 .type_of_service = mask->ipv4_mask.tos,
5177 .next_proto_id = mask->ipv4_mask.proto,
5179 attributes->items[1] = (struct rte_flow_item){
5180 .type = RTE_FLOW_ITEM_TYPE_IPV4,
5181 .spec = &attributes->l3,
5182 .mask = &attributes->l3_mask,
5185 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
5186 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
5187 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
5188 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
5189 .hop_limits = input->flow.ipv6_flow.hop_limits,
5190 .proto = input->flow.ipv6_flow.proto,
5193 memcpy(attributes->l3.ipv6.hdr.src_addr,
5194 input->flow.ipv6_flow.src_ip,
5195 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
5196 memcpy(attributes->l3.ipv6.hdr.dst_addr,
5197 input->flow.ipv6_flow.dst_ip,
5198 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
5199 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
5200 mask->ipv6_mask.src_ip,
5201 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
5202 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
5203 mask->ipv6_mask.dst_ip,
5204 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
5205 attributes->items[1] = (struct rte_flow_item){
5206 .type = RTE_FLOW_ITEM_TYPE_IPV6,
5207 .spec = &attributes->l3,
5208 .mask = &attributes->l3_mask,
5212 DRV_LOG(ERR, "port %u invalid flow type%d",
5213 dev->data->port_id, fdir_filter->input.flow_type);
5214 rte_errno = ENOTSUP;
5218 switch (fdir_filter->input.flow_type) {
5219 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
5220 attributes->l4.udp.hdr = (struct rte_udp_hdr){
5221 .src_port = input->flow.udp4_flow.src_port,
5222 .dst_port = input->flow.udp4_flow.dst_port,
5224 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
5225 .src_port = mask->src_port_mask,
5226 .dst_port = mask->dst_port_mask,
5228 attributes->items[2] = (struct rte_flow_item){
5229 .type = RTE_FLOW_ITEM_TYPE_UDP,
5230 .spec = &attributes->l4,
5231 .mask = &attributes->l4_mask,
5234 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
5235 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
5236 .src_port = input->flow.tcp4_flow.src_port,
5237 .dst_port = input->flow.tcp4_flow.dst_port,
5239 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
5240 .src_port = mask->src_port_mask,
5241 .dst_port = mask->dst_port_mask,
5243 attributes->items[2] = (struct rte_flow_item){
5244 .type = RTE_FLOW_ITEM_TYPE_TCP,
5245 .spec = &attributes->l4,
5246 .mask = &attributes->l4_mask,
5249 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
5250 attributes->l4.udp.hdr = (struct rte_udp_hdr){
5251 .src_port = input->flow.udp6_flow.src_port,
5252 .dst_port = input->flow.udp6_flow.dst_port,
5254 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
5255 .src_port = mask->src_port_mask,
5256 .dst_port = mask->dst_port_mask,
5258 attributes->items[2] = (struct rte_flow_item){
5259 .type = RTE_FLOW_ITEM_TYPE_UDP,
5260 .spec = &attributes->l4,
5261 .mask = &attributes->l4_mask,
5264 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
5265 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
5266 .src_port = input->flow.tcp6_flow.src_port,
5267 .dst_port = input->flow.tcp6_flow.dst_port,
5269 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
5270 .src_port = mask->src_port_mask,
5271 .dst_port = mask->dst_port_mask,
5273 attributes->items[2] = (struct rte_flow_item){
5274 .type = RTE_FLOW_ITEM_TYPE_TCP,
5275 .spec = &attributes->l4,
5276 .mask = &attributes->l4_mask,
5279 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
5280 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
5283 DRV_LOG(ERR, "port %u invalid flow type%d",
5284 dev->data->port_id, fdir_filter->input.flow_type);
5285 rte_errno = ENOTSUP;
5291 #define FLOW_FDIR_CMP(f1, f2, fld) \
5292 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
5295 * Compare two FDIR flows. If items and actions are identical, the two flows are
5299 * Pointer to Ethernet device.
5301 * FDIR flow to compare.
5303 * FDIR flow to compare.
5306 * Zero on match, 1 otherwise.
5309 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
5311 if (FLOW_FDIR_CMP(f1, f2, attr) ||
5312 FLOW_FDIR_CMP(f1, f2, l2) ||
5313 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
5314 FLOW_FDIR_CMP(f1, f2, l3) ||
5315 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
5316 FLOW_FDIR_CMP(f1, f2, l4) ||
5317 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
5318 FLOW_FDIR_CMP(f1, f2, actions[0].type))
5320 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
5321 FLOW_FDIR_CMP(f1, f2, queue))
5327 * Search device flow list to find out a matched FDIR flow.
5330 * Pointer to Ethernet device.
5332 * FDIR flow to lookup.
5335 * Index of flow if found, 0 otherwise.
5338 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
5340 struct mlx5_priv *priv = dev->data->dev_private;
5341 uint32_t flow_idx = 0;
5342 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5344 MLX5_ASSERT(fdir_flow);
5345 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
5346 if (!flow_fdir_cmp(priv_fdir_flow->fdir, fdir_flow)) {
5347 DRV_LOG(DEBUG, "port %u found FDIR flow %u",
5348 dev->data->port_id, flow_idx);
5349 flow_idx = priv_fdir_flow->rix_flow;
5357 * Add new flow director filter and store it in list.
5360 * Pointer to Ethernet device.
5361 * @param fdir_filter
5362 * Flow director filter to add.
5365 * 0 on success, a negative errno value otherwise and rte_errno is set.
5368 flow_fdir_filter_add(struct rte_eth_dev *dev,
5369 const struct rte_eth_fdir_filter *fdir_filter)
5371 struct mlx5_priv *priv = dev->data->dev_private;
5372 struct mlx5_fdir *fdir_flow;
5373 struct rte_flow *flow;
5374 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5378 fdir_flow = rte_zmalloc(__func__, sizeof(*fdir_flow), 0);
5383 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
5386 flow_idx = flow_fdir_filter_lookup(dev, fdir_flow);
5391 priv_fdir_flow = rte_zmalloc(__func__, sizeof(struct mlx5_fdir_flow),
5393 if (!priv_fdir_flow) {
5397 flow_idx = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
5398 fdir_flow->items, fdir_flow->actions, true,
5400 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW], flow_idx);
5404 priv_fdir_flow->fdir = fdir_flow;
5405 priv_fdir_flow->rix_flow = flow_idx;
5406 LIST_INSERT_HEAD(&priv->fdir_flows, priv_fdir_flow, next);
5407 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
5408 dev->data->port_id, (void *)flow);
5411 rte_free(priv_fdir_flow);
5412 rte_free(fdir_flow);
5417 * Delete specific filter.
5420 * Pointer to Ethernet device.
5421 * @param fdir_filter
5422 * Filter to be deleted.
5425 * 0 on success, a negative errno value otherwise and rte_errno is set.
5428 flow_fdir_filter_delete(struct rte_eth_dev *dev,
5429 const struct rte_eth_fdir_filter *fdir_filter)
5431 struct mlx5_priv *priv = dev->data->dev_private;
5433 struct mlx5_fdir fdir_flow = {
5436 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5439 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
5442 LIST_FOREACH(priv_fdir_flow, &priv->fdir_flows, next) {
5443 /* Find the fdir in priv list */
5444 if (!flow_fdir_cmp(priv_fdir_flow->fdir, &fdir_flow))
5447 if (!priv_fdir_flow)
5449 LIST_REMOVE(priv_fdir_flow, next);
5450 flow_idx = priv_fdir_flow->rix_flow;
5451 flow_list_destroy(dev, &priv->flows, flow_idx);
5452 rte_free(priv_fdir_flow->fdir);
5453 rte_free(priv_fdir_flow);
5454 DRV_LOG(DEBUG, "port %u deleted FDIR flow %u",
5455 dev->data->port_id, flow_idx);
5460 * Update queue for specific filter.
5463 * Pointer to Ethernet device.
5464 * @param fdir_filter
5465 * Filter to be updated.
5468 * 0 on success, a negative errno value otherwise and rte_errno is set.
5471 flow_fdir_filter_update(struct rte_eth_dev *dev,
5472 const struct rte_eth_fdir_filter *fdir_filter)
5476 ret = flow_fdir_filter_delete(dev, fdir_filter);
5479 return flow_fdir_filter_add(dev, fdir_filter);
5483 * Flush all filters.
5486 * Pointer to Ethernet device.
5489 flow_fdir_filter_flush(struct rte_eth_dev *dev)
5491 struct mlx5_priv *priv = dev->data->dev_private;
5492 struct mlx5_fdir_flow *priv_fdir_flow = NULL;
5494 while (!LIST_EMPTY(&priv->fdir_flows)) {
5495 priv_fdir_flow = LIST_FIRST(&priv->fdir_flows);
5496 LIST_REMOVE(priv_fdir_flow, next);
5497 flow_list_destroy(dev, &priv->flows, priv_fdir_flow->rix_flow);
5498 rte_free(priv_fdir_flow->fdir);
5499 rte_free(priv_fdir_flow);
5504 * Get flow director information.
5507 * Pointer to Ethernet device.
5508 * @param[out] fdir_info
5509 * Resulting flow director information.
5512 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
5514 struct rte_eth_fdir_masks *mask =
5515 &dev->data->dev_conf.fdir_conf.mask;
5517 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
5518 fdir_info->guarant_spc = 0;
5519 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
5520 fdir_info->max_flexpayload = 0;
5521 fdir_info->flow_types_mask[0] = 0;
5522 fdir_info->flex_payload_unit = 0;
5523 fdir_info->max_flex_payload_segment_num = 0;
5524 fdir_info->flex_payload_limit = 0;
5525 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
5529 * Deal with flow director operations.
5532 * Pointer to Ethernet device.
5534 * Operation to perform.
5536 * Pointer to operation-specific structure.
5539 * 0 on success, a negative errno value otherwise and rte_errno is set.
5542 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
5545 enum rte_fdir_mode fdir_mode =
5546 dev->data->dev_conf.fdir_conf.mode;
5548 if (filter_op == RTE_ETH_FILTER_NOP)
5550 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
5551 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5552 DRV_LOG(ERR, "port %u flow director mode %d not supported",
5553 dev->data->port_id, fdir_mode);
5557 switch (filter_op) {
5558 case RTE_ETH_FILTER_ADD:
5559 return flow_fdir_filter_add(dev, arg);
5560 case RTE_ETH_FILTER_UPDATE:
5561 return flow_fdir_filter_update(dev, arg);
5562 case RTE_ETH_FILTER_DELETE:
5563 return flow_fdir_filter_delete(dev, arg);
5564 case RTE_ETH_FILTER_FLUSH:
5565 flow_fdir_filter_flush(dev);
5567 case RTE_ETH_FILTER_INFO:
5568 flow_fdir_info_get(dev, arg);
5571 DRV_LOG(DEBUG, "port %u unknown operation %u",
5572 dev->data->port_id, filter_op);
5580 * Manage filter operations.
5583 * Pointer to Ethernet device structure.
5584 * @param filter_type
5587 * Operation to perform.
5589 * Pointer to operation-specific structure.
5592 * 0 on success, a negative errno value otherwise and rte_errno is set.
5595 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
5596 enum rte_filter_type filter_type,
5597 enum rte_filter_op filter_op,
5600 switch (filter_type) {
5601 case RTE_ETH_FILTER_GENERIC:
5602 if (filter_op != RTE_ETH_FILTER_GET) {
5606 *(const void **)arg = &mlx5_flow_ops;
5608 case RTE_ETH_FILTER_FDIR:
5609 return flow_fdir_ctrl_func(dev, filter_op, arg);
5611 DRV_LOG(ERR, "port %u filter type (%d) not supported",
5612 dev->data->port_id, filter_type);
5613 rte_errno = ENOTSUP;
5620 * Create the needed meter and suffix tables.
5623 * Pointer to Ethernet device.
5625 * Pointer to the flow meter.
5628 * Pointer to table set on success, NULL otherwise.
5630 struct mlx5_meter_domains_infos *
5631 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
5632 const struct mlx5_flow_meter *fm)
5634 const struct mlx5_flow_driver_ops *fops;
5636 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5637 return fops->create_mtr_tbls(dev, fm);
5641 * Destroy the meter table set.
5644 * Pointer to Ethernet device.
5646 * Pointer to the meter table set.
5652 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
5653 struct mlx5_meter_domains_infos *tbls)
5655 const struct mlx5_flow_driver_ops *fops;
5657 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5658 return fops->destroy_mtr_tbls(dev, tbls);
5662 * Create policer rules.
5665 * Pointer to Ethernet device.
5667 * Pointer to flow meter structure.
5669 * Pointer to flow attributes.
5672 * 0 on success, -1 otherwise.
5675 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
5676 struct mlx5_flow_meter *fm,
5677 const struct rte_flow_attr *attr)
5679 const struct mlx5_flow_driver_ops *fops;
5681 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5682 return fops->create_policer_rules(dev, fm, attr);
5686 * Destroy policer rules.
5689 * Pointer to flow meter structure.
5691 * Pointer to flow attributes.
5694 * 0 on success, -1 otherwise.
5697 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
5698 struct mlx5_flow_meter *fm,
5699 const struct rte_flow_attr *attr)
5701 const struct mlx5_flow_driver_ops *fops;
5703 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5704 return fops->destroy_policer_rules(dev, fm, attr);
5708 * Allocate a counter.
5711 * Pointer to Ethernet device structure.
5714 * Index to allocated counter on success, 0 otherwise.
5717 mlx5_counter_alloc(struct rte_eth_dev *dev)
5719 const struct mlx5_flow_driver_ops *fops;
5720 struct rte_flow_attr attr = { .transfer = 0 };
5722 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5723 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5724 return fops->counter_alloc(dev);
5727 "port %u counter allocate is not supported.",
5728 dev->data->port_id);
5736 * Pointer to Ethernet device structure.
5738 * Index to counter to be free.
5741 mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
5743 const struct mlx5_flow_driver_ops *fops;
5744 struct rte_flow_attr attr = { .transfer = 0 };
5746 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5747 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5748 fops->counter_free(dev, cnt);
5752 "port %u counter free is not supported.",
5753 dev->data->port_id);
5757 * Query counter statistics.
5760 * Pointer to Ethernet device structure.
5762 * Index to counter to query.
5764 * Set to clear counter statistics.
5766 * The counter hits packets number to save.
5768 * The counter hits bytes number to save.
5771 * 0 on success, a negative errno value otherwise.
5774 mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
5775 bool clear, uint64_t *pkts, uint64_t *bytes)
5777 const struct mlx5_flow_driver_ops *fops;
5778 struct rte_flow_attr attr = { .transfer = 0 };
5780 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5781 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5782 return fops->counter_query(dev, cnt, clear, pkts, bytes);
5785 "port %u counter query is not supported.",
5786 dev->data->port_id);
5790 #define MLX5_POOL_QUERY_FREQ_US 1000000
5793 * Get number of all validate pools.
5796 * Pointer to mlx5_ibv_shared object.
5799 * The number of all validate pools.
5802 mlx5_get_all_valid_pool_count(struct mlx5_ibv_shared *sh)
5805 uint32_t pools_n = 0;
5807 for (i = 0; i < MLX5_CCONT_TYPE_MAX; ++i)
5808 pools_n += rte_atomic16_read(&sh->cmng.ccont[i].n_valid);
5813 * Set the periodic procedure for triggering asynchronous batch queries for all
5814 * the counter pools.
5817 * Pointer to mlx5_ibv_shared object.
5820 mlx5_set_query_alarm(struct mlx5_ibv_shared *sh)
5822 uint32_t pools_n, us;
5824 pools_n = mlx5_get_all_valid_pool_count(sh);
5825 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
5826 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
5827 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
5828 sh->cmng.query_thread_on = 0;
5829 DRV_LOG(ERR, "Cannot reinitialize query alarm");
5831 sh->cmng.query_thread_on = 1;
5836 * The periodic procedure for triggering asynchronous batch queries for all the
5837 * counter pools. This function is probably called by the host thread.
5840 * The parameter for the alarm process.
5843 mlx5_flow_query_alarm(void *arg)
5845 struct mlx5_ibv_shared *sh = arg;
5846 struct mlx5_devx_obj *dcs;
5849 uint8_t batch = sh->cmng.batch;
5850 uint8_t age = sh->cmng.age;
5851 uint16_t pool_index = sh->cmng.pool_index;
5852 struct mlx5_pools_container *cont;
5853 struct mlx5_flow_counter_pool *pool;
5854 int cont_loop = MLX5_CCONT_TYPE_MAX;
5856 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
5859 cont = MLX5_CNT_CONTAINER(sh, batch, age);
5860 rte_spinlock_lock(&cont->resize_sl);
5862 rte_spinlock_unlock(&cont->resize_sl);
5863 /* Check if all the containers are empty. */
5864 if (unlikely(--cont_loop == 0))
5868 if (batch == 0 && pool_index == 0) {
5870 sh->cmng.batch = batch;
5873 goto next_container;
5875 pool = cont->pools[pool_index];
5876 rte_spinlock_unlock(&cont->resize_sl);
5878 /* There is a pool query in progress. */
5881 LIST_FIRST(&sh->cmng.free_stat_raws);
5883 /* No free counter statistics raw memory. */
5885 dcs = (struct mlx5_devx_obj *)(uintptr_t)rte_atomic64_read
5887 offset = batch ? 0 : dcs->id % MLX5_COUNTERS_PER_POOL;
5889 * Identify the counters released between query trigger and query
5890 * handle more effiecntly. The counter released in this gap period
5891 * should wait for a new round of query as the new arrived packets
5892 * will not be taken into account.
5894 rte_atomic64_add(&pool->start_query_gen, 1);
5895 ret = mlx5_devx_cmd_flow_counter_query(dcs, 0, MLX5_COUNTERS_PER_POOL -
5897 pool->raw_hw->mem_mng->dm->id,
5899 (pool->raw_hw->data + offset),
5901 (uint64_t)(uintptr_t)pool);
5903 rte_atomic64_sub(&pool->start_query_gen, 1);
5904 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
5905 " %d", pool->min_dcs->id);
5906 pool->raw_hw = NULL;
5909 pool->raw_hw->min_dcs_id = dcs->id;
5910 LIST_REMOVE(pool->raw_hw, next);
5911 sh->cmng.pending_queries++;
5913 if (pool_index >= rte_atomic16_read(&cont->n_valid)) {
5916 if (batch == 0 && pool_index == 0)
5920 sh->cmng.batch = batch;
5921 sh->cmng.pool_index = pool_index;
5923 mlx5_set_query_alarm(sh);
5927 * Check and callback event for new aged flow in the counter pool
5930 * Pointer to mlx5_ibv_shared object.
5932 * Pointer to Current counter pool.
5935 mlx5_flow_aging_check(struct mlx5_ibv_shared *sh,
5936 struct mlx5_flow_counter_pool *pool)
5938 struct mlx5_priv *priv;
5939 struct mlx5_flow_counter *cnt;
5940 struct mlx5_age_info *age_info;
5941 struct mlx5_age_param *age_param;
5942 struct mlx5_counter_stats_raw *cur = pool->raw_hw;
5943 struct mlx5_counter_stats_raw *prev = pool->raw;
5944 uint16_t curr = rte_rdtsc() / (rte_get_tsc_hz() / 10);
5947 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
5948 cnt = MLX5_POOL_GET_CNT(pool, i);
5949 age_param = MLX5_CNT_TO_AGE(cnt);
5950 if (rte_atomic16_read(&age_param->state) != AGE_CANDIDATE)
5952 if (cur->data[i].hits != prev->data[i].hits) {
5953 age_param->expire = curr + age_param->timeout;
5956 if ((uint16_t)(curr - age_param->expire) >= (UINT16_MAX / 2))
5959 * Hold the lock first, or if between the
5960 * state AGE_TMOUT and tailq operation the
5961 * release happened, the release procedure
5962 * may delete a non-existent tailq node.
5964 priv = rte_eth_devices[age_param->port_id].data->dev_private;
5965 age_info = GET_PORT_AGE_INFO(priv);
5966 rte_spinlock_lock(&age_info->aged_sl);
5967 /* If the cpmset fails, release happens. */
5968 if (rte_atomic16_cmpset((volatile uint16_t *)
5973 TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
5974 MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
5976 rte_spinlock_unlock(&age_info->aged_sl);
5978 for (i = 0; i < sh->max_port; i++) {
5979 age_info = &sh->port[i].age_info;
5980 if (!MLX5_AGE_GET(age_info, MLX5_AGE_EVENT_NEW))
5982 if (MLX5_AGE_GET(age_info, MLX5_AGE_TRIGGER))
5983 _rte_eth_dev_callback_process
5984 (&rte_eth_devices[sh->port[i].devx_ih_port_id],
5985 RTE_ETH_EVENT_FLOW_AGED, NULL);
5986 age_info->flags = 0;
5991 * Handler for the HW respond about ready values from an asynchronous batch
5992 * query. This function is probably called by the host thread.
5995 * The pointer to the shared IB device context.
5996 * @param[in] async_id
5997 * The Devx async ID.
5999 * The status of the completion.
6002 mlx5_flow_async_pool_query_handle(struct mlx5_ibv_shared *sh,
6003 uint64_t async_id, int status)
6005 struct mlx5_flow_counter_pool *pool =
6006 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
6007 struct mlx5_counter_stats_raw *raw_to_free;
6009 if (unlikely(status)) {
6010 rte_atomic64_sub(&pool->start_query_gen, 1);
6011 raw_to_free = pool->raw_hw;
6013 raw_to_free = pool->raw;
6014 if (IS_AGE_POOL(pool))
6015 mlx5_flow_aging_check(sh, pool);
6016 rte_spinlock_lock(&pool->sl);
6017 pool->raw = pool->raw_hw;
6018 rte_spinlock_unlock(&pool->sl);
6019 MLX5_ASSERT(rte_atomic64_read(&pool->end_query_gen) + 1 ==
6020 rte_atomic64_read(&pool->start_query_gen));
6021 rte_atomic64_set(&pool->end_query_gen,
6022 rte_atomic64_read(&pool->start_query_gen));
6023 /* Be sure the new raw counters data is updated in memory. */
6026 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
6027 pool->raw_hw = NULL;
6028 sh->cmng.pending_queries--;
6032 * Translate the rte_flow group index to HW table value.
6034 * @param[in] attributes
6035 * Pointer to flow attributes
6036 * @param[in] external
6037 * Value is part of flow rule created by request external to PMD.
6039 * rte_flow group index value.
6040 * @param[out] fdb_def_rule
6041 * Whether fdb jump to table 1 is configured.
6045 * Pointer to error structure.
6048 * 0 on success, a negative errno value otherwise and rte_errno is set.
6051 mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, bool external,
6052 uint32_t group, bool fdb_def_rule, uint32_t *table,
6053 struct rte_flow_error *error)
6055 if (attributes->transfer && external && fdb_def_rule) {
6056 if (group == UINT32_MAX)
6057 return rte_flow_error_set
6059 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6061 "group index not supported");
6070 * Discover availability of metadata reg_c's.
6072 * Iteratively use test flows to check availability.
6075 * Pointer to the Ethernet device structure.
6078 * 0 on success, a negative errno value otherwise and rte_errno is set.
6081 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
6083 struct mlx5_priv *priv = dev->data->dev_private;
6084 struct mlx5_dev_config *config = &priv->config;
6085 enum modify_reg idx;
6088 /* reg_c[0] and reg_c[1] are reserved. */
6089 config->flow_mreg_c[n++] = REG_C_0;
6090 config->flow_mreg_c[n++] = REG_C_1;
6091 /* Discover availability of other reg_c's. */
6092 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
6093 struct rte_flow_attr attr = {
6094 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
6095 .priority = MLX5_FLOW_PRIO_RSVD,
6098 struct rte_flow_item items[] = {
6100 .type = RTE_FLOW_ITEM_TYPE_END,
6103 struct rte_flow_action actions[] = {
6105 .type = (enum rte_flow_action_type)
6106 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6107 .conf = &(struct mlx5_flow_action_copy_mreg){
6113 .type = RTE_FLOW_ACTION_TYPE_JUMP,
6114 .conf = &(struct rte_flow_action_jump){
6115 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
6119 .type = RTE_FLOW_ACTION_TYPE_END,
6123 struct rte_flow *flow;
6124 struct rte_flow_error error;
6126 if (!config->dv_flow_en)
6128 /* Create internal flow, validation skips copy action. */
6129 flow_idx = flow_list_create(dev, NULL, &attr, items,
6130 actions, false, &error);
6131 flow = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RTE_FLOW],
6135 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
6136 config->flow_mreg_c[n++] = idx;
6137 flow_list_destroy(dev, NULL, flow_idx);
6139 for (; n < MLX5_MREG_C_NUM; ++n)
6140 config->flow_mreg_c[n] = REG_NONE;
6145 * Dump flow raw hw data to file
6148 * The pointer to Ethernet device.
6150 * A pointer to a file for output.
6152 * Perform verbose error reporting if not NULL. PMDs initialize this
6153 * structure in case of error only.
6155 * 0 on success, a nagative value otherwise.
6158 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
6160 struct rte_flow_error *error __rte_unused)
6162 struct mlx5_priv *priv = dev->data->dev_private;
6163 struct mlx5_ibv_shared *sh = priv->sh;
6165 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
6166 sh->tx_domain, file);
6170 * Get aged-out flows.
6173 * Pointer to the Ethernet device structure.
6174 * @param[in] context
6175 * The address of an array of pointers to the aged-out flows contexts.
6176 * @param[in] nb_countexts
6177 * The length of context array pointers.
6179 * Perform verbose error reporting if not NULL. Initialized in case of
6183 * how many contexts get in success, otherwise negative errno value.
6184 * if nb_contexts is 0, return the amount of all aged contexts.
6185 * if nb_contexts is not 0 , return the amount of aged flows reported
6186 * in the context array.
6189 mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
6190 uint32_t nb_contexts, struct rte_flow_error *error)
6192 const struct mlx5_flow_driver_ops *fops;
6193 struct rte_flow_attr attr = { .transfer = 0 };
6195 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
6196 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
6197 return fops->get_aged_flows(dev, contexts, nb_contexts,
6201 "port %u get aged flows is not supported.",
6202 dev->data->port_id);