1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
6 #include <netinet/in.h>
13 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
15 #pragma GCC diagnostic ignored "-Wpedantic"
17 #include <infiniband/verbs.h>
19 #pragma GCC diagnostic error "-Wpedantic"
22 #include <rte_common.h>
23 #include <rte_ether.h>
24 #include <rte_ethdev_driver.h>
26 #include <rte_flow_driver.h>
27 #include <rte_malloc.h>
31 #include "mlx5_defs.h"
32 #include "mlx5_flow.h"
33 #include "mlx5_glue.h"
35 #include "mlx5_rxtx.h"
37 /* Dev ops structure defined in mlx5.c */
38 extern const struct eth_dev_ops mlx5_dev_ops;
39 extern const struct eth_dev_ops mlx5_dev_ops_isolate;
41 /** Device flow drivers. */
42 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
43 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
45 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
47 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
49 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
50 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
51 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
52 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
54 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
55 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
60 MLX5_EXPANSION_ROOT_OUTER,
61 MLX5_EXPANSION_ROOT_ETH_VLAN,
62 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
63 MLX5_EXPANSION_OUTER_ETH,
64 MLX5_EXPANSION_OUTER_ETH_VLAN,
65 MLX5_EXPANSION_OUTER_VLAN,
66 MLX5_EXPANSION_OUTER_IPV4,
67 MLX5_EXPANSION_OUTER_IPV4_UDP,
68 MLX5_EXPANSION_OUTER_IPV4_TCP,
69 MLX5_EXPANSION_OUTER_IPV6,
70 MLX5_EXPANSION_OUTER_IPV6_UDP,
71 MLX5_EXPANSION_OUTER_IPV6_TCP,
73 MLX5_EXPANSION_VXLAN_GPE,
77 MLX5_EXPANSION_ETH_VLAN,
80 MLX5_EXPANSION_IPV4_UDP,
81 MLX5_EXPANSION_IPV4_TCP,
83 MLX5_EXPANSION_IPV6_UDP,
84 MLX5_EXPANSION_IPV6_TCP,
87 /** Supported expansion of items. */
88 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
89 [MLX5_EXPANSION_ROOT] = {
90 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
93 .type = RTE_FLOW_ITEM_TYPE_END,
95 [MLX5_EXPANSION_ROOT_OUTER] = {
96 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
97 MLX5_EXPANSION_OUTER_IPV4,
98 MLX5_EXPANSION_OUTER_IPV6),
99 .type = RTE_FLOW_ITEM_TYPE_END,
101 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
102 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
103 .type = RTE_FLOW_ITEM_TYPE_END,
105 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
106 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
107 .type = RTE_FLOW_ITEM_TYPE_END,
109 [MLX5_EXPANSION_OUTER_ETH] = {
110 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
111 MLX5_EXPANSION_OUTER_IPV6,
112 MLX5_EXPANSION_MPLS),
113 .type = RTE_FLOW_ITEM_TYPE_ETH,
116 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
117 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
118 .type = RTE_FLOW_ITEM_TYPE_ETH,
121 [MLX5_EXPANSION_OUTER_VLAN] = {
122 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
123 MLX5_EXPANSION_OUTER_IPV6),
124 .type = RTE_FLOW_ITEM_TYPE_VLAN,
126 [MLX5_EXPANSION_OUTER_IPV4] = {
127 .next = RTE_FLOW_EXPAND_RSS_NEXT
128 (MLX5_EXPANSION_OUTER_IPV4_UDP,
129 MLX5_EXPANSION_OUTER_IPV4_TCP,
132 MLX5_EXPANSION_IPV6),
133 .type = RTE_FLOW_ITEM_TYPE_IPV4,
134 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
135 ETH_RSS_NONFRAG_IPV4_OTHER,
137 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
138 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
139 MLX5_EXPANSION_VXLAN_GPE),
140 .type = RTE_FLOW_ITEM_TYPE_UDP,
141 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
143 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
144 .type = RTE_FLOW_ITEM_TYPE_TCP,
145 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
147 [MLX5_EXPANSION_OUTER_IPV6] = {
148 .next = RTE_FLOW_EXPAND_RSS_NEXT
149 (MLX5_EXPANSION_OUTER_IPV6_UDP,
150 MLX5_EXPANSION_OUTER_IPV6_TCP,
152 MLX5_EXPANSION_IPV6),
153 .type = RTE_FLOW_ITEM_TYPE_IPV6,
154 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
155 ETH_RSS_NONFRAG_IPV6_OTHER,
157 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
158 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
159 MLX5_EXPANSION_VXLAN_GPE),
160 .type = RTE_FLOW_ITEM_TYPE_UDP,
161 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
163 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
164 .type = RTE_FLOW_ITEM_TYPE_TCP,
165 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
167 [MLX5_EXPANSION_VXLAN] = {
168 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
169 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
171 [MLX5_EXPANSION_VXLAN_GPE] = {
172 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
174 MLX5_EXPANSION_IPV6),
175 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
177 [MLX5_EXPANSION_GRE] = {
178 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
179 .type = RTE_FLOW_ITEM_TYPE_GRE,
181 [MLX5_EXPANSION_MPLS] = {
182 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
183 MLX5_EXPANSION_IPV6),
184 .type = RTE_FLOW_ITEM_TYPE_MPLS,
186 [MLX5_EXPANSION_ETH] = {
187 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
188 MLX5_EXPANSION_IPV6),
189 .type = RTE_FLOW_ITEM_TYPE_ETH,
191 [MLX5_EXPANSION_ETH_VLAN] = {
192 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
193 .type = RTE_FLOW_ITEM_TYPE_ETH,
195 [MLX5_EXPANSION_VLAN] = {
196 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
197 MLX5_EXPANSION_IPV6),
198 .type = RTE_FLOW_ITEM_TYPE_VLAN,
200 [MLX5_EXPANSION_IPV4] = {
201 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
202 MLX5_EXPANSION_IPV4_TCP),
203 .type = RTE_FLOW_ITEM_TYPE_IPV4,
204 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
205 ETH_RSS_NONFRAG_IPV4_OTHER,
207 [MLX5_EXPANSION_IPV4_UDP] = {
208 .type = RTE_FLOW_ITEM_TYPE_UDP,
209 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
211 [MLX5_EXPANSION_IPV4_TCP] = {
212 .type = RTE_FLOW_ITEM_TYPE_TCP,
213 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
215 [MLX5_EXPANSION_IPV6] = {
216 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
217 MLX5_EXPANSION_IPV6_TCP),
218 .type = RTE_FLOW_ITEM_TYPE_IPV6,
219 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
220 ETH_RSS_NONFRAG_IPV6_OTHER,
222 [MLX5_EXPANSION_IPV6_UDP] = {
223 .type = RTE_FLOW_ITEM_TYPE_UDP,
224 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
226 [MLX5_EXPANSION_IPV6_TCP] = {
227 .type = RTE_FLOW_ITEM_TYPE_TCP,
228 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
232 static const struct rte_flow_ops mlx5_flow_ops = {
233 .validate = mlx5_flow_validate,
234 .create = mlx5_flow_create,
235 .destroy = mlx5_flow_destroy,
236 .flush = mlx5_flow_flush,
237 .isolate = mlx5_flow_isolate,
238 .query = mlx5_flow_query,
241 /* Convert FDIR request to Generic flow. */
243 struct rte_flow_attr attr;
244 struct rte_flow_item items[4];
245 struct rte_flow_item_eth l2;
246 struct rte_flow_item_eth l2_mask;
248 struct rte_flow_item_ipv4 ipv4;
249 struct rte_flow_item_ipv6 ipv6;
252 struct rte_flow_item_ipv4 ipv4;
253 struct rte_flow_item_ipv6 ipv6;
256 struct rte_flow_item_udp udp;
257 struct rte_flow_item_tcp tcp;
260 struct rte_flow_item_udp udp;
261 struct rte_flow_item_tcp tcp;
263 struct rte_flow_action actions[2];
264 struct rte_flow_action_queue queue;
267 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
268 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
269 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
272 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
273 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
274 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
275 { 9, 10, 11 }, { 12, 13, 14 },
278 /* Tunnel information. */
279 struct mlx5_flow_tunnel_info {
280 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
281 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
284 static struct mlx5_flow_tunnel_info tunnels_info[] = {
286 .tunnel = MLX5_FLOW_LAYER_VXLAN,
287 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
290 .tunnel = MLX5_FLOW_LAYER_GENEVE,
291 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
294 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
295 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
298 .tunnel = MLX5_FLOW_LAYER_GRE,
299 .ptype = RTE_PTYPE_TUNNEL_GRE,
302 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
303 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
306 .tunnel = MLX5_FLOW_LAYER_MPLS,
307 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
310 .tunnel = MLX5_FLOW_LAYER_NVGRE,
311 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
314 .tunnel = MLX5_FLOW_LAYER_IPIP,
315 .ptype = RTE_PTYPE_TUNNEL_IP,
318 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
319 .ptype = RTE_PTYPE_TUNNEL_IP,
324 * Translate tag ID to register.
327 * Pointer to the Ethernet device structure.
329 * The feature that request the register.
331 * The request register ID.
333 * Error description in case of any.
336 * The request register on success, a negative errno
337 * value otherwise and rte_errno is set.
340 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
341 enum mlx5_feature_name feature,
343 struct rte_flow_error *error)
345 struct mlx5_priv *priv = dev->data->dev_private;
346 struct mlx5_dev_config *config = &priv->config;
347 enum modify_reg start_reg;
350 case MLX5_HAIRPIN_RX:
352 case MLX5_HAIRPIN_TX:
354 case MLX5_METADATA_RX:
355 switch (config->dv_xmeta_en) {
356 case MLX5_XMETA_MODE_LEGACY:
358 case MLX5_XMETA_MODE_META16:
360 case MLX5_XMETA_MODE_META32:
364 case MLX5_METADATA_TX:
366 case MLX5_METADATA_FDB:
369 switch (config->dv_xmeta_en) {
370 case MLX5_XMETA_MODE_LEGACY:
372 case MLX5_XMETA_MODE_META16:
374 case MLX5_XMETA_MODE_META32:
381 * Metadata COPY_MARK register using is in meter suffix sub
382 * flow while with meter. It's safe to share the same register.
384 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
386 RTE_ASSERT(priv->mtr_color_reg != REG_NONE);
387 return priv->mtr_color_reg;
390 * If meter is enable, it will engage two registers for color
391 * match and flow match. If meter color match is not using the
392 * REG_C_2, need to skip the REG_C_x be used by meter color
394 * If meter is disable, free to use all available registers.
396 if (priv->mtr_color_reg != REG_NONE)
397 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_3 :
401 if (id > (REG_C_7 - start_reg))
402 return rte_flow_error_set(error, EINVAL,
403 RTE_FLOW_ERROR_TYPE_ITEM,
404 NULL, "invalid tag id");
405 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NONE)
406 return rte_flow_error_set(error, ENOTSUP,
407 RTE_FLOW_ERROR_TYPE_ITEM,
408 NULL, "unsupported tag id");
410 * This case means meter is using the REG_C_x great than 2.
411 * Take care not to conflict with meter color REG_C_x.
412 * If the available index REG_C_y >= REG_C_x, skip the
415 if (start_reg == REG_C_3 && config->flow_mreg_c
416 [id + REG_C_3 - REG_C_0] >= priv->mtr_color_reg) {
417 if (config->flow_mreg_c[id + 1 + REG_C_3 - REG_C_0] !=
419 return config->flow_mreg_c
420 [id + 1 + REG_C_3 - REG_C_0];
421 return rte_flow_error_set(error, ENOTSUP,
422 RTE_FLOW_ERROR_TYPE_ITEM,
423 NULL, "unsupported tag id");
425 return config->flow_mreg_c[id + start_reg - REG_C_0];
428 return rte_flow_error_set(error, EINVAL,
429 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
430 NULL, "invalid feature name");
434 * Check extensive flow metadata register support.
437 * Pointer to rte_eth_dev structure.
440 * True if device supports extensive flow metadata register, otherwise false.
443 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
445 struct mlx5_priv *priv = dev->data->dev_private;
446 struct mlx5_dev_config *config = &priv->config;
449 * Having available reg_c can be regarded inclusively as supporting
450 * extensive flow metadata register, which could mean,
451 * - metadata register copy action by modify header.
452 * - 16 modify header actions is supported.
453 * - reg_c's are preserved across different domain (FDB and NIC) on
454 * packet loopback by flow lookup miss.
456 return config->flow_mreg_c[2] != REG_NONE;
460 * Discover the maximum number of priority available.
463 * Pointer to the Ethernet device structure.
466 * number of supported flow priority on success, a negative errno
467 * value otherwise and rte_errno is set.
470 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
472 struct mlx5_priv *priv = dev->data->dev_private;
474 struct ibv_flow_attr attr;
475 struct ibv_flow_spec_eth eth;
476 struct ibv_flow_spec_action_drop drop;
480 .port = (uint8_t)priv->ibv_port,
483 .type = IBV_FLOW_SPEC_ETH,
484 .size = sizeof(struct ibv_flow_spec_eth),
487 .size = sizeof(struct ibv_flow_spec_action_drop),
488 .type = IBV_FLOW_SPEC_ACTION_DROP,
491 struct ibv_flow *flow;
492 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
493 uint16_t vprio[] = { 8, 16 };
501 for (i = 0; i != RTE_DIM(vprio); i++) {
502 flow_attr.attr.priority = vprio[i] - 1;
503 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
506 claim_zero(mlx5_glue->destroy_flow(flow));
509 mlx5_hrxq_drop_release(dev);
512 priority = RTE_DIM(priority_map_3);
515 priority = RTE_DIM(priority_map_5);
520 "port %u verbs maximum priority: %d expected 8/16",
521 dev->data->port_id, priority);
524 DRV_LOG(INFO, "port %u flow maximum priority: %d",
525 dev->data->port_id, priority);
530 * Adjust flow priority based on the highest layer and the request priority.
533 * Pointer to the Ethernet device structure.
534 * @param[in] priority
535 * The rule base priority.
536 * @param[in] subpriority
537 * The priority based on the items.
542 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
543 uint32_t subpriority)
546 struct mlx5_priv *priv = dev->data->dev_private;
548 switch (priv->config.flow_prio) {
549 case RTE_DIM(priority_map_3):
550 res = priority_map_3[priority][subpriority];
552 case RTE_DIM(priority_map_5):
553 res = priority_map_5[priority][subpriority];
560 * Verify the @p item specifications (spec, last, mask) are compatible with the
564 * Item specification.
566 * @p item->mask or flow default bit-masks.
567 * @param[in] nic_mask
568 * Bit-masks covering supported fields by the NIC to compare with user mask.
570 * Bit-masks size in bytes.
572 * Pointer to error structure.
575 * 0 on success, a negative errno value otherwise and rte_errno is set.
578 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
580 const uint8_t *nic_mask,
582 struct rte_flow_error *error)
587 for (i = 0; i < size; ++i)
588 if ((nic_mask[i] | mask[i]) != nic_mask[i])
589 return rte_flow_error_set(error, ENOTSUP,
590 RTE_FLOW_ERROR_TYPE_ITEM,
592 "mask enables non supported"
594 if (!item->spec && (item->mask || item->last))
595 return rte_flow_error_set(error, EINVAL,
596 RTE_FLOW_ERROR_TYPE_ITEM, item,
597 "mask/last without a spec is not"
599 if (item->spec && item->last) {
605 for (i = 0; i < size; ++i) {
606 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
607 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
609 ret = memcmp(spec, last, size);
611 return rte_flow_error_set(error, EINVAL,
612 RTE_FLOW_ERROR_TYPE_ITEM,
614 "range is not valid");
620 * Adjust the hash fields according to the @p flow information.
622 * @param[in] dev_flow.
623 * Pointer to the mlx5_flow.
625 * 1 when the hash field is for a tunnel item.
626 * @param[in] layer_types
628 * @param[in] hash_fields
632 * The hash fields that should be used.
635 mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow,
636 int tunnel __rte_unused, uint64_t layer_types,
637 uint64_t hash_fields)
639 struct rte_flow *flow = dev_flow->flow;
640 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
641 int rss_request_inner = flow->rss.level >= 2;
643 /* Check RSS hash level for tunnel. */
644 if (tunnel && rss_request_inner)
645 hash_fields |= IBV_RX_HASH_INNER;
646 else if (tunnel || rss_request_inner)
649 /* Check if requested layer matches RSS hash fields. */
650 if (!(flow->rss.types & layer_types))
656 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
657 * if several tunnel rules are used on this queue, the tunnel ptype will be
661 * Rx queue to update.
664 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
667 uint32_t tunnel_ptype = 0;
669 /* Look up for the ptype to use. */
670 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
671 if (!rxq_ctrl->flow_tunnels_n[i])
674 tunnel_ptype = tunnels_info[i].ptype;
680 rxq_ctrl->rxq.tunnel = tunnel_ptype;
684 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
688 * Pointer to the Ethernet device structure.
689 * @param[in] dev_flow
690 * Pointer to device flow structure.
693 flow_drv_rxq_flags_set(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
695 struct mlx5_priv *priv = dev->data->dev_private;
696 struct rte_flow *flow = dev_flow->flow;
697 const int mark = !!(dev_flow->actions &
698 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
699 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
702 for (i = 0; i != flow->rss.queue_num; ++i) {
703 int idx = (*flow->rss.queue)[i];
704 struct mlx5_rxq_ctrl *rxq_ctrl =
705 container_of((*priv->rxqs)[idx],
706 struct mlx5_rxq_ctrl, rxq);
709 * To support metadata register copy on Tx loopback,
710 * this must be always enabled (metadata may arive
711 * from other port - not from local flows only.
713 if (priv->config.dv_flow_en &&
714 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
715 mlx5_flow_ext_mreg_supported(dev)) {
716 rxq_ctrl->rxq.mark = 1;
717 rxq_ctrl->flow_mark_n = 1;
719 rxq_ctrl->rxq.mark = 1;
720 rxq_ctrl->flow_mark_n++;
725 /* Increase the counter matching the flow. */
726 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
727 if ((tunnels_info[j].tunnel &
729 tunnels_info[j].tunnel) {
730 rxq_ctrl->flow_tunnels_n[j]++;
734 flow_rxq_tunnel_ptype_update(rxq_ctrl);
740 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
743 * Pointer to the Ethernet device structure.
745 * Pointer to flow structure.
748 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
750 struct mlx5_flow *dev_flow;
752 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
753 flow_drv_rxq_flags_set(dev, dev_flow);
757 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
758 * device flow if no other flow uses it with the same kind of request.
761 * Pointer to Ethernet device.
762 * @param[in] dev_flow
763 * Pointer to the device flow.
766 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
768 struct mlx5_priv *priv = dev->data->dev_private;
769 struct rte_flow *flow = dev_flow->flow;
770 const int mark = !!(dev_flow->actions &
771 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
772 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
775 assert(dev->data->dev_started);
776 for (i = 0; i != flow->rss.queue_num; ++i) {
777 int idx = (*flow->rss.queue)[i];
778 struct mlx5_rxq_ctrl *rxq_ctrl =
779 container_of((*priv->rxqs)[idx],
780 struct mlx5_rxq_ctrl, rxq);
782 if (priv->config.dv_flow_en &&
783 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
784 mlx5_flow_ext_mreg_supported(dev)) {
785 rxq_ctrl->rxq.mark = 1;
786 rxq_ctrl->flow_mark_n = 1;
788 rxq_ctrl->flow_mark_n--;
789 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
794 /* Decrease the counter matching the flow. */
795 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
796 if ((tunnels_info[j].tunnel &
798 tunnels_info[j].tunnel) {
799 rxq_ctrl->flow_tunnels_n[j]--;
803 flow_rxq_tunnel_ptype_update(rxq_ctrl);
809 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
810 * @p flow if no other flow uses it with the same kind of request.
813 * Pointer to Ethernet device.
815 * Pointer to the flow.
818 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
820 struct mlx5_flow *dev_flow;
822 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
823 flow_drv_rxq_flags_trim(dev, dev_flow);
827 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
830 * Pointer to Ethernet device.
833 flow_rxq_flags_clear(struct rte_eth_dev *dev)
835 struct mlx5_priv *priv = dev->data->dev_private;
838 for (i = 0; i != priv->rxqs_n; ++i) {
839 struct mlx5_rxq_ctrl *rxq_ctrl;
842 if (!(*priv->rxqs)[i])
844 rxq_ctrl = container_of((*priv->rxqs)[i],
845 struct mlx5_rxq_ctrl, rxq);
846 rxq_ctrl->flow_mark_n = 0;
847 rxq_ctrl->rxq.mark = 0;
848 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
849 rxq_ctrl->flow_tunnels_n[j] = 0;
850 rxq_ctrl->rxq.tunnel = 0;
855 * return a pointer to the desired action in the list of actions.
858 * The list of actions to search the action in.
860 * The action to find.
863 * Pointer to the action in the list, if found. NULL otherwise.
865 const struct rte_flow_action *
866 mlx5_flow_find_action(const struct rte_flow_action *actions,
867 enum rte_flow_action_type action)
871 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
872 if (actions->type == action)
878 * Validate the flag action.
880 * @param[in] action_flags
881 * Bit-fields that holds the actions detected until now.
883 * Attributes of flow that includes this action.
885 * Pointer to error structure.
888 * 0 on success, a negative errno value otherwise and rte_errno is set.
891 mlx5_flow_validate_action_flag(uint64_t action_flags,
892 const struct rte_flow_attr *attr,
893 struct rte_flow_error *error)
896 if (action_flags & MLX5_FLOW_ACTION_DROP)
897 return rte_flow_error_set(error, EINVAL,
898 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
899 "can't drop and flag in same flow");
900 if (action_flags & MLX5_FLOW_ACTION_MARK)
901 return rte_flow_error_set(error, EINVAL,
902 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
903 "can't mark and flag in same flow");
904 if (action_flags & MLX5_FLOW_ACTION_FLAG)
905 return rte_flow_error_set(error, EINVAL,
906 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
908 " actions in same flow");
910 return rte_flow_error_set(error, ENOTSUP,
911 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
912 "flag action not supported for "
918 * Validate the mark action.
921 * Pointer to the queue action.
922 * @param[in] action_flags
923 * Bit-fields that holds the actions detected until now.
925 * Attributes of flow that includes this action.
927 * Pointer to error structure.
930 * 0 on success, a negative errno value otherwise and rte_errno is set.
933 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
934 uint64_t action_flags,
935 const struct rte_flow_attr *attr,
936 struct rte_flow_error *error)
938 const struct rte_flow_action_mark *mark = action->conf;
941 return rte_flow_error_set(error, EINVAL,
942 RTE_FLOW_ERROR_TYPE_ACTION,
944 "configuration cannot be null");
945 if (mark->id >= MLX5_FLOW_MARK_MAX)
946 return rte_flow_error_set(error, EINVAL,
947 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
949 "mark id must in 0 <= id < "
950 RTE_STR(MLX5_FLOW_MARK_MAX));
951 if (action_flags & MLX5_FLOW_ACTION_DROP)
952 return rte_flow_error_set(error, EINVAL,
953 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
954 "can't drop and mark in same flow");
955 if (action_flags & MLX5_FLOW_ACTION_FLAG)
956 return rte_flow_error_set(error, EINVAL,
957 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
958 "can't flag and mark in same flow");
959 if (action_flags & MLX5_FLOW_ACTION_MARK)
960 return rte_flow_error_set(error, EINVAL,
961 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
962 "can't have 2 mark actions in same"
965 return rte_flow_error_set(error, ENOTSUP,
966 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
967 "mark action not supported for "
973 * Validate the drop action.
975 * @param[in] action_flags
976 * Bit-fields that holds the actions detected until now.
978 * Attributes of flow that includes this action.
980 * Pointer to error structure.
983 * 0 on success, a negative errno value otherwise and rte_errno is set.
986 mlx5_flow_validate_action_drop(uint64_t action_flags,
987 const struct rte_flow_attr *attr,
988 struct rte_flow_error *error)
990 if (action_flags & MLX5_FLOW_ACTION_FLAG)
991 return rte_flow_error_set(error, EINVAL,
992 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
993 "can't drop and flag in same flow");
994 if (action_flags & MLX5_FLOW_ACTION_MARK)
995 return rte_flow_error_set(error, EINVAL,
996 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
997 "can't drop and mark in same flow");
998 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
999 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
1000 return rte_flow_error_set(error, EINVAL,
1001 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1002 "can't have 2 fate actions in"
1005 return rte_flow_error_set(error, ENOTSUP,
1006 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1007 "drop action not supported for "
1013 * Validate the queue action.
1016 * Pointer to the queue action.
1017 * @param[in] action_flags
1018 * Bit-fields that holds the actions detected until now.
1020 * Pointer to the Ethernet device structure.
1022 * Attributes of flow that includes this action.
1024 * Pointer to error structure.
1027 * 0 on success, a negative errno value otherwise and rte_errno is set.
1030 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1031 uint64_t action_flags,
1032 struct rte_eth_dev *dev,
1033 const struct rte_flow_attr *attr,
1034 struct rte_flow_error *error)
1036 struct mlx5_priv *priv = dev->data->dev_private;
1037 const struct rte_flow_action_queue *queue = action->conf;
1039 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1040 return rte_flow_error_set(error, EINVAL,
1041 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1042 "can't have 2 fate actions in"
1045 return rte_flow_error_set(error, EINVAL,
1046 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1047 NULL, "No Rx queues configured");
1048 if (queue->index >= priv->rxqs_n)
1049 return rte_flow_error_set(error, EINVAL,
1050 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1052 "queue index out of range");
1053 if (!(*priv->rxqs)[queue->index])
1054 return rte_flow_error_set(error, EINVAL,
1055 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1057 "queue is not configured");
1059 return rte_flow_error_set(error, ENOTSUP,
1060 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1061 "queue action not supported for "
1067 * Validate the rss action.
1070 * Pointer to the queue action.
1071 * @param[in] action_flags
1072 * Bit-fields that holds the actions detected until now.
1074 * Pointer to the Ethernet device structure.
1076 * Attributes of flow that includes this action.
1077 * @param[in] item_flags
1078 * Items that were detected.
1080 * Pointer to error structure.
1083 * 0 on success, a negative errno value otherwise and rte_errno is set.
1086 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1087 uint64_t action_flags,
1088 struct rte_eth_dev *dev,
1089 const struct rte_flow_attr *attr,
1090 uint64_t item_flags,
1091 struct rte_flow_error *error)
1093 struct mlx5_priv *priv = dev->data->dev_private;
1094 const struct rte_flow_action_rss *rss = action->conf;
1095 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1098 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1099 return rte_flow_error_set(error, EINVAL,
1100 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1101 "can't have 2 fate actions"
1103 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1104 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1105 return rte_flow_error_set(error, ENOTSUP,
1106 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1108 "RSS hash function not supported");
1109 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1114 return rte_flow_error_set(error, ENOTSUP,
1115 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1117 "tunnel RSS is not supported");
1118 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1119 if (rss->key_len == 0 && rss->key != NULL)
1120 return rte_flow_error_set(error, ENOTSUP,
1121 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1123 "RSS hash key length 0");
1124 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1125 return rte_flow_error_set(error, ENOTSUP,
1126 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1128 "RSS hash key too small");
1129 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1130 return rte_flow_error_set(error, ENOTSUP,
1131 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1133 "RSS hash key too large");
1134 if (rss->queue_num > priv->config.ind_table_max_size)
1135 return rte_flow_error_set(error, ENOTSUP,
1136 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1138 "number of queues too large");
1139 if (rss->types & MLX5_RSS_HF_MASK)
1140 return rte_flow_error_set(error, ENOTSUP,
1141 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1143 "some RSS protocols are not"
1146 return rte_flow_error_set(error, EINVAL,
1147 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1148 NULL, "No Rx queues configured");
1149 if (!rss->queue_num)
1150 return rte_flow_error_set(error, EINVAL,
1151 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1152 NULL, "No queues configured");
1153 for (i = 0; i != rss->queue_num; ++i) {
1154 if (rss->queue[i] >= priv->rxqs_n)
1155 return rte_flow_error_set
1157 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1158 &rss->queue[i], "queue index out of range");
1159 if (!(*priv->rxqs)[rss->queue[i]])
1160 return rte_flow_error_set
1161 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1162 &rss->queue[i], "queue is not configured");
1165 return rte_flow_error_set(error, ENOTSUP,
1166 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1167 "rss action not supported for "
1169 if (rss->level > 1 && !tunnel)
1170 return rte_flow_error_set(error, EINVAL,
1171 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1172 "inner RSS is not supported for "
1173 "non-tunnel flows");
1178 * Validate the count action.
1181 * Pointer to the Ethernet device structure.
1183 * Attributes of flow that includes this action.
1185 * Pointer to error structure.
1188 * 0 on success, a negative errno value otherwise and rte_errno is set.
1191 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1192 const struct rte_flow_attr *attr,
1193 struct rte_flow_error *error)
1196 return rte_flow_error_set(error, ENOTSUP,
1197 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1198 "count action not supported for "
1204 * Verify the @p attributes will be correctly understood by the NIC and store
1205 * them in the @p flow if everything is correct.
1208 * Pointer to the Ethernet device structure.
1209 * @param[in] attributes
1210 * Pointer to flow attributes
1212 * Pointer to error structure.
1215 * 0 on success, a negative errno value otherwise and rte_errno is set.
1218 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1219 const struct rte_flow_attr *attributes,
1220 struct rte_flow_error *error)
1222 struct mlx5_priv *priv = dev->data->dev_private;
1223 uint32_t priority_max = priv->config.flow_prio - 1;
1225 if (attributes->group)
1226 return rte_flow_error_set(error, ENOTSUP,
1227 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1228 NULL, "groups is not supported");
1229 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1230 attributes->priority >= priority_max)
1231 return rte_flow_error_set(error, ENOTSUP,
1232 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1233 NULL, "priority out of range");
1234 if (attributes->egress)
1235 return rte_flow_error_set(error, ENOTSUP,
1236 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1237 "egress is not supported");
1238 if (attributes->transfer && !priv->config.dv_esw_en)
1239 return rte_flow_error_set(error, ENOTSUP,
1240 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1241 NULL, "transfer is not supported");
1242 if (!attributes->ingress)
1243 return rte_flow_error_set(error, EINVAL,
1244 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1246 "ingress attribute is mandatory");
1251 * Validate ICMP6 item.
1254 * Item specification.
1255 * @param[in] item_flags
1256 * Bit-fields that holds the items detected until now.
1258 * Pointer to error structure.
1261 * 0 on success, a negative errno value otherwise and rte_errno is set.
1264 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1265 uint64_t item_flags,
1266 uint8_t target_protocol,
1267 struct rte_flow_error *error)
1269 const struct rte_flow_item_icmp6 *mask = item->mask;
1270 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1271 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1272 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1273 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1274 MLX5_FLOW_LAYER_OUTER_L4;
1277 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1278 return rte_flow_error_set(error, EINVAL,
1279 RTE_FLOW_ERROR_TYPE_ITEM, item,
1280 "protocol filtering not compatible"
1281 " with ICMP6 layer");
1282 if (!(item_flags & l3m))
1283 return rte_flow_error_set(error, EINVAL,
1284 RTE_FLOW_ERROR_TYPE_ITEM, item,
1285 "IPv6 is mandatory to filter on"
1287 if (item_flags & l4m)
1288 return rte_flow_error_set(error, EINVAL,
1289 RTE_FLOW_ERROR_TYPE_ITEM, item,
1290 "multiple L4 layers not supported");
1292 mask = &rte_flow_item_icmp6_mask;
1293 ret = mlx5_flow_item_acceptable
1294 (item, (const uint8_t *)mask,
1295 (const uint8_t *)&rte_flow_item_icmp6_mask,
1296 sizeof(struct rte_flow_item_icmp6), error);
1303 * Validate ICMP item.
1306 * Item specification.
1307 * @param[in] item_flags
1308 * Bit-fields that holds the items detected until now.
1310 * Pointer to error structure.
1313 * 0 on success, a negative errno value otherwise and rte_errno is set.
1316 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1317 uint64_t item_flags,
1318 uint8_t target_protocol,
1319 struct rte_flow_error *error)
1321 const struct rte_flow_item_icmp *mask = item->mask;
1322 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1323 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1324 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1325 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1326 MLX5_FLOW_LAYER_OUTER_L4;
1329 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1330 return rte_flow_error_set(error, EINVAL,
1331 RTE_FLOW_ERROR_TYPE_ITEM, item,
1332 "protocol filtering not compatible"
1333 " with ICMP layer");
1334 if (!(item_flags & l3m))
1335 return rte_flow_error_set(error, EINVAL,
1336 RTE_FLOW_ERROR_TYPE_ITEM, item,
1337 "IPv4 is mandatory to filter"
1339 if (item_flags & l4m)
1340 return rte_flow_error_set(error, EINVAL,
1341 RTE_FLOW_ERROR_TYPE_ITEM, item,
1342 "multiple L4 layers not supported");
1344 mask = &rte_flow_item_icmp_mask;
1345 ret = mlx5_flow_item_acceptable
1346 (item, (const uint8_t *)mask,
1347 (const uint8_t *)&rte_flow_item_icmp_mask,
1348 sizeof(struct rte_flow_item_icmp), error);
1355 * Validate Ethernet item.
1358 * Item specification.
1359 * @param[in] item_flags
1360 * Bit-fields that holds the items detected until now.
1362 * Pointer to error structure.
1365 * 0 on success, a negative errno value otherwise and rte_errno is set.
1368 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1369 uint64_t item_flags,
1370 struct rte_flow_error *error)
1372 const struct rte_flow_item_eth *mask = item->mask;
1373 const struct rte_flow_item_eth nic_mask = {
1374 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1375 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1376 .type = RTE_BE16(0xffff),
1379 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1380 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1381 MLX5_FLOW_LAYER_OUTER_L2;
1383 if (item_flags & ethm)
1384 return rte_flow_error_set(error, ENOTSUP,
1385 RTE_FLOW_ERROR_TYPE_ITEM, item,
1386 "multiple L2 layers not supported");
1387 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1388 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1389 return rte_flow_error_set(error, EINVAL,
1390 RTE_FLOW_ERROR_TYPE_ITEM, item,
1391 "L2 layer should not follow "
1393 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1394 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1395 return rte_flow_error_set(error, EINVAL,
1396 RTE_FLOW_ERROR_TYPE_ITEM, item,
1397 "L2 layer should not follow VLAN");
1399 mask = &rte_flow_item_eth_mask;
1400 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1401 (const uint8_t *)&nic_mask,
1402 sizeof(struct rte_flow_item_eth),
1408 * Validate VLAN item.
1411 * Item specification.
1412 * @param[in] item_flags
1413 * Bit-fields that holds the items detected until now.
1415 * Ethernet device flow is being created on.
1417 * Pointer to error structure.
1420 * 0 on success, a negative errno value otherwise and rte_errno is set.
1423 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1424 uint64_t item_flags,
1425 struct rte_eth_dev *dev,
1426 struct rte_flow_error *error)
1428 const struct rte_flow_item_vlan *spec = item->spec;
1429 const struct rte_flow_item_vlan *mask = item->mask;
1430 const struct rte_flow_item_vlan nic_mask = {
1431 .tci = RTE_BE16(UINT16_MAX),
1432 .inner_type = RTE_BE16(UINT16_MAX),
1434 uint16_t vlan_tag = 0;
1435 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1437 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1438 MLX5_FLOW_LAYER_INNER_L4) :
1439 (MLX5_FLOW_LAYER_OUTER_L3 |
1440 MLX5_FLOW_LAYER_OUTER_L4);
1441 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1442 MLX5_FLOW_LAYER_OUTER_VLAN;
1444 if (item_flags & vlanm)
1445 return rte_flow_error_set(error, EINVAL,
1446 RTE_FLOW_ERROR_TYPE_ITEM, item,
1447 "multiple VLAN layers not supported");
1448 else if ((item_flags & l34m) != 0)
1449 return rte_flow_error_set(error, EINVAL,
1450 RTE_FLOW_ERROR_TYPE_ITEM, item,
1451 "VLAN cannot follow L3/L4 layer");
1453 mask = &rte_flow_item_vlan_mask;
1454 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1455 (const uint8_t *)&nic_mask,
1456 sizeof(struct rte_flow_item_vlan),
1460 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1461 struct mlx5_priv *priv = dev->data->dev_private;
1463 if (priv->vmwa_context) {
1465 * Non-NULL context means we have a virtual machine
1466 * and SR-IOV enabled, we have to create VLAN interface
1467 * to make hypervisor to setup E-Switch vport
1468 * context correctly. We avoid creating the multiple
1469 * VLAN interfaces, so we cannot support VLAN tag mask.
1471 return rte_flow_error_set(error, EINVAL,
1472 RTE_FLOW_ERROR_TYPE_ITEM,
1474 "VLAN tag mask is not"
1475 " supported in virtual"
1480 vlan_tag = spec->tci;
1481 vlan_tag &= mask->tci;
1484 * From verbs perspective an empty VLAN is equivalent
1485 * to a packet without VLAN layer.
1488 return rte_flow_error_set(error, EINVAL,
1489 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1491 "VLAN cannot be empty");
1496 * Validate IPV4 item.
1499 * Item specification.
1500 * @param[in] item_flags
1501 * Bit-fields that holds the items detected until now.
1502 * @param[in] acc_mask
1503 * Acceptable mask, if NULL default internal default mask
1504 * will be used to check whether item fields are supported.
1506 * Pointer to error structure.
1509 * 0 on success, a negative errno value otherwise and rte_errno is set.
1512 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1513 uint64_t item_flags,
1515 uint16_t ether_type,
1516 const struct rte_flow_item_ipv4 *acc_mask,
1517 struct rte_flow_error *error)
1519 const struct rte_flow_item_ipv4 *mask = item->mask;
1520 const struct rte_flow_item_ipv4 *spec = item->spec;
1521 const struct rte_flow_item_ipv4 nic_mask = {
1523 .src_addr = RTE_BE32(0xffffffff),
1524 .dst_addr = RTE_BE32(0xffffffff),
1525 .type_of_service = 0xff,
1526 .next_proto_id = 0xff,
1529 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1530 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1531 MLX5_FLOW_LAYER_OUTER_L3;
1532 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1533 MLX5_FLOW_LAYER_OUTER_L4;
1535 uint8_t next_proto = 0xFF;
1536 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1537 MLX5_FLOW_LAYER_OUTER_VLAN |
1538 MLX5_FLOW_LAYER_INNER_VLAN);
1540 if ((last_item & l2_vlan) && ether_type &&
1541 ether_type != RTE_ETHER_TYPE_IPV4)
1542 return rte_flow_error_set(error, EINVAL,
1543 RTE_FLOW_ERROR_TYPE_ITEM, item,
1544 "IPv4 cannot follow L2/VLAN layer "
1545 "which ether type is not IPv4");
1546 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1548 next_proto = mask->hdr.next_proto_id &
1549 spec->hdr.next_proto_id;
1550 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1551 return rte_flow_error_set(error, EINVAL,
1552 RTE_FLOW_ERROR_TYPE_ITEM,
1557 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1558 return rte_flow_error_set(error, EINVAL,
1559 RTE_FLOW_ERROR_TYPE_ITEM, item,
1560 "wrong tunnel type - IPv6 specified "
1561 "but IPv4 item provided");
1562 if (item_flags & l3m)
1563 return rte_flow_error_set(error, ENOTSUP,
1564 RTE_FLOW_ERROR_TYPE_ITEM, item,
1565 "multiple L3 layers not supported");
1566 else if (item_flags & l4m)
1567 return rte_flow_error_set(error, EINVAL,
1568 RTE_FLOW_ERROR_TYPE_ITEM, item,
1569 "L3 cannot follow an L4 layer.");
1570 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1571 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1572 return rte_flow_error_set(error, EINVAL,
1573 RTE_FLOW_ERROR_TYPE_ITEM, item,
1574 "L3 cannot follow an NVGRE layer.");
1576 mask = &rte_flow_item_ipv4_mask;
1577 else if (mask->hdr.next_proto_id != 0 &&
1578 mask->hdr.next_proto_id != 0xff)
1579 return rte_flow_error_set(error, EINVAL,
1580 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1581 "partial mask is not supported"
1583 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1584 acc_mask ? (const uint8_t *)acc_mask
1585 : (const uint8_t *)&nic_mask,
1586 sizeof(struct rte_flow_item_ipv4),
1594 * Validate IPV6 item.
1597 * Item specification.
1598 * @param[in] item_flags
1599 * Bit-fields that holds the items detected until now.
1600 * @param[in] acc_mask
1601 * Acceptable mask, if NULL default internal default mask
1602 * will be used to check whether item fields are supported.
1604 * Pointer to error structure.
1607 * 0 on success, a negative errno value otherwise and rte_errno is set.
1610 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1611 uint64_t item_flags,
1613 uint16_t ether_type,
1614 const struct rte_flow_item_ipv6 *acc_mask,
1615 struct rte_flow_error *error)
1617 const struct rte_flow_item_ipv6 *mask = item->mask;
1618 const struct rte_flow_item_ipv6 *spec = item->spec;
1619 const struct rte_flow_item_ipv6 nic_mask = {
1622 "\xff\xff\xff\xff\xff\xff\xff\xff"
1623 "\xff\xff\xff\xff\xff\xff\xff\xff",
1625 "\xff\xff\xff\xff\xff\xff\xff\xff"
1626 "\xff\xff\xff\xff\xff\xff\xff\xff",
1627 .vtc_flow = RTE_BE32(0xffffffff),
1632 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1633 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1634 MLX5_FLOW_LAYER_OUTER_L3;
1635 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1636 MLX5_FLOW_LAYER_OUTER_L4;
1638 uint8_t next_proto = 0xFF;
1639 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1640 MLX5_FLOW_LAYER_OUTER_VLAN |
1641 MLX5_FLOW_LAYER_INNER_VLAN);
1643 if ((last_item & l2_vlan) && ether_type &&
1644 ether_type != RTE_ETHER_TYPE_IPV6)
1645 return rte_flow_error_set(error, EINVAL,
1646 RTE_FLOW_ERROR_TYPE_ITEM, item,
1647 "IPv6 cannot follow L2/VLAN layer "
1648 "which ether type is not IPv6");
1649 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
1651 next_proto = mask->hdr.proto & spec->hdr.proto;
1652 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1653 return rte_flow_error_set(error, EINVAL,
1654 RTE_FLOW_ERROR_TYPE_ITEM,
1659 if (item_flags & MLX5_FLOW_LAYER_IPIP)
1660 return rte_flow_error_set(error, EINVAL,
1661 RTE_FLOW_ERROR_TYPE_ITEM, item,
1662 "wrong tunnel type - IPv4 specified "
1663 "but IPv6 item provided");
1664 if (item_flags & l3m)
1665 return rte_flow_error_set(error, ENOTSUP,
1666 RTE_FLOW_ERROR_TYPE_ITEM, item,
1667 "multiple L3 layers not supported");
1668 else if (item_flags & l4m)
1669 return rte_flow_error_set(error, EINVAL,
1670 RTE_FLOW_ERROR_TYPE_ITEM, item,
1671 "L3 cannot follow an L4 layer.");
1672 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1673 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1674 return rte_flow_error_set(error, EINVAL,
1675 RTE_FLOW_ERROR_TYPE_ITEM, item,
1676 "L3 cannot follow an NVGRE layer.");
1678 mask = &rte_flow_item_ipv6_mask;
1679 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1680 acc_mask ? (const uint8_t *)acc_mask
1681 : (const uint8_t *)&nic_mask,
1682 sizeof(struct rte_flow_item_ipv6),
1690 * Validate UDP item.
1693 * Item specification.
1694 * @param[in] item_flags
1695 * Bit-fields that holds the items detected until now.
1696 * @param[in] target_protocol
1697 * The next protocol in the previous item.
1698 * @param[in] flow_mask
1699 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
1701 * Pointer to error structure.
1704 * 0 on success, a negative errno value otherwise and rte_errno is set.
1707 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1708 uint64_t item_flags,
1709 uint8_t target_protocol,
1710 struct rte_flow_error *error)
1712 const struct rte_flow_item_udp *mask = item->mask;
1713 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1714 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1715 MLX5_FLOW_LAYER_OUTER_L3;
1716 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1717 MLX5_FLOW_LAYER_OUTER_L4;
1720 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1721 return rte_flow_error_set(error, EINVAL,
1722 RTE_FLOW_ERROR_TYPE_ITEM, item,
1723 "protocol filtering not compatible"
1725 if (!(item_flags & l3m))
1726 return rte_flow_error_set(error, EINVAL,
1727 RTE_FLOW_ERROR_TYPE_ITEM, item,
1728 "L3 is mandatory to filter on L4");
1729 if (item_flags & l4m)
1730 return rte_flow_error_set(error, EINVAL,
1731 RTE_FLOW_ERROR_TYPE_ITEM, item,
1732 "multiple L4 layers not supported");
1734 mask = &rte_flow_item_udp_mask;
1735 ret = mlx5_flow_item_acceptable
1736 (item, (const uint8_t *)mask,
1737 (const uint8_t *)&rte_flow_item_udp_mask,
1738 sizeof(struct rte_flow_item_udp), error);
1745 * Validate TCP item.
1748 * Item specification.
1749 * @param[in] item_flags
1750 * Bit-fields that holds the items detected until now.
1751 * @param[in] target_protocol
1752 * The next protocol in the previous item.
1754 * Pointer to error structure.
1757 * 0 on success, a negative errno value otherwise and rte_errno is set.
1760 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1761 uint64_t item_flags,
1762 uint8_t target_protocol,
1763 const struct rte_flow_item_tcp *flow_mask,
1764 struct rte_flow_error *error)
1766 const struct rte_flow_item_tcp *mask = item->mask;
1767 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1768 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1769 MLX5_FLOW_LAYER_OUTER_L3;
1770 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1771 MLX5_FLOW_LAYER_OUTER_L4;
1775 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1776 return rte_flow_error_set(error, EINVAL,
1777 RTE_FLOW_ERROR_TYPE_ITEM, item,
1778 "protocol filtering not compatible"
1780 if (!(item_flags & l3m))
1781 return rte_flow_error_set(error, EINVAL,
1782 RTE_FLOW_ERROR_TYPE_ITEM, item,
1783 "L3 is mandatory to filter on L4");
1784 if (item_flags & l4m)
1785 return rte_flow_error_set(error, EINVAL,
1786 RTE_FLOW_ERROR_TYPE_ITEM, item,
1787 "multiple L4 layers not supported");
1789 mask = &rte_flow_item_tcp_mask;
1790 ret = mlx5_flow_item_acceptable
1791 (item, (const uint8_t *)mask,
1792 (const uint8_t *)flow_mask,
1793 sizeof(struct rte_flow_item_tcp), error);
1800 * Validate VXLAN item.
1803 * Item specification.
1804 * @param[in] item_flags
1805 * Bit-fields that holds the items detected until now.
1806 * @param[in] target_protocol
1807 * The next protocol in the previous item.
1809 * Pointer to error structure.
1812 * 0 on success, a negative errno value otherwise and rte_errno is set.
1815 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1816 uint64_t item_flags,
1817 struct rte_flow_error *error)
1819 const struct rte_flow_item_vxlan *spec = item->spec;
1820 const struct rte_flow_item_vxlan *mask = item->mask;
1825 } id = { .vlan_id = 0, };
1826 uint32_t vlan_id = 0;
1829 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1830 return rte_flow_error_set(error, ENOTSUP,
1831 RTE_FLOW_ERROR_TYPE_ITEM, item,
1832 "multiple tunnel layers not"
1835 * Verify only UDPv4 is present as defined in
1836 * https://tools.ietf.org/html/rfc7348
1838 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1839 return rte_flow_error_set(error, EINVAL,
1840 RTE_FLOW_ERROR_TYPE_ITEM, item,
1841 "no outer UDP layer found");
1843 mask = &rte_flow_item_vxlan_mask;
1844 ret = mlx5_flow_item_acceptable
1845 (item, (const uint8_t *)mask,
1846 (const uint8_t *)&rte_flow_item_vxlan_mask,
1847 sizeof(struct rte_flow_item_vxlan),
1852 memcpy(&id.vni[1], spec->vni, 3);
1853 vlan_id = id.vlan_id;
1854 memcpy(&id.vni[1], mask->vni, 3);
1855 vlan_id &= id.vlan_id;
1858 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1859 * only this layer is defined in the Verbs specification it is
1860 * interpreted as wildcard and all packets will match this
1861 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1862 * udp), all packets matching the layers before will also
1863 * match this rule. To avoid such situation, VNI 0 is
1864 * currently refused.
1867 return rte_flow_error_set(error, ENOTSUP,
1868 RTE_FLOW_ERROR_TYPE_ITEM, item,
1869 "VXLAN vni cannot be 0");
1870 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1871 return rte_flow_error_set(error, ENOTSUP,
1872 RTE_FLOW_ERROR_TYPE_ITEM, item,
1873 "VXLAN tunnel must be fully defined");
1878 * Validate VXLAN_GPE item.
1881 * Item specification.
1882 * @param[in] item_flags
1883 * Bit-fields that holds the items detected until now.
1885 * Pointer to the private data structure.
1886 * @param[in] target_protocol
1887 * The next protocol in the previous item.
1889 * Pointer to error structure.
1892 * 0 on success, a negative errno value otherwise and rte_errno is set.
1895 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1896 uint64_t item_flags,
1897 struct rte_eth_dev *dev,
1898 struct rte_flow_error *error)
1900 struct mlx5_priv *priv = dev->data->dev_private;
1901 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1902 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1907 } id = { .vlan_id = 0, };
1908 uint32_t vlan_id = 0;
1910 if (!priv->config.l3_vxlan_en)
1911 return rte_flow_error_set(error, ENOTSUP,
1912 RTE_FLOW_ERROR_TYPE_ITEM, item,
1913 "L3 VXLAN is not enabled by device"
1914 " parameter and/or not configured in"
1916 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1917 return rte_flow_error_set(error, ENOTSUP,
1918 RTE_FLOW_ERROR_TYPE_ITEM, item,
1919 "multiple tunnel layers not"
1922 * Verify only UDPv4 is present as defined in
1923 * https://tools.ietf.org/html/rfc7348
1925 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1926 return rte_flow_error_set(error, EINVAL,
1927 RTE_FLOW_ERROR_TYPE_ITEM, item,
1928 "no outer UDP layer found");
1930 mask = &rte_flow_item_vxlan_gpe_mask;
1931 ret = mlx5_flow_item_acceptable
1932 (item, (const uint8_t *)mask,
1933 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1934 sizeof(struct rte_flow_item_vxlan_gpe),
1940 return rte_flow_error_set(error, ENOTSUP,
1941 RTE_FLOW_ERROR_TYPE_ITEM,
1943 "VxLAN-GPE protocol"
1945 memcpy(&id.vni[1], spec->vni, 3);
1946 vlan_id = id.vlan_id;
1947 memcpy(&id.vni[1], mask->vni, 3);
1948 vlan_id &= id.vlan_id;
1951 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1952 * layer is defined in the Verbs specification it is interpreted as
1953 * wildcard and all packets will match this rule, if it follows a full
1954 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1955 * before will also match this rule. To avoid such situation, VNI 0
1956 * is currently refused.
1959 return rte_flow_error_set(error, ENOTSUP,
1960 RTE_FLOW_ERROR_TYPE_ITEM, item,
1961 "VXLAN-GPE vni cannot be 0");
1962 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1963 return rte_flow_error_set(error, ENOTSUP,
1964 RTE_FLOW_ERROR_TYPE_ITEM, item,
1965 "VXLAN-GPE tunnel must be fully"
1970 * Validate GRE Key item.
1973 * Item specification.
1974 * @param[in] item_flags
1975 * Bit flags to mark detected items.
1976 * @param[in] gre_item
1977 * Pointer to gre_item
1979 * Pointer to error structure.
1982 * 0 on success, a negative errno value otherwise and rte_errno is set.
1985 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
1986 uint64_t item_flags,
1987 const struct rte_flow_item *gre_item,
1988 struct rte_flow_error *error)
1990 const rte_be32_t *mask = item->mask;
1992 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
1993 const struct rte_flow_item_gre *gre_spec = gre_item->spec;
1994 const struct rte_flow_item_gre *gre_mask = gre_item->mask;
1996 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
1997 return rte_flow_error_set(error, ENOTSUP,
1998 RTE_FLOW_ERROR_TYPE_ITEM, item,
1999 "Multiple GRE key not support");
2000 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2001 return rte_flow_error_set(error, ENOTSUP,
2002 RTE_FLOW_ERROR_TYPE_ITEM, item,
2003 "No preceding GRE header");
2004 if (item_flags & MLX5_FLOW_LAYER_INNER)
2005 return rte_flow_error_set(error, ENOTSUP,
2006 RTE_FLOW_ERROR_TYPE_ITEM, item,
2007 "GRE key following a wrong item");
2009 gre_mask = &rte_flow_item_gre_mask;
2010 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2011 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2012 return rte_flow_error_set(error, EINVAL,
2013 RTE_FLOW_ERROR_TYPE_ITEM, item,
2014 "Key bit must be on");
2017 mask = &gre_key_default_mask;
2018 ret = mlx5_flow_item_acceptable
2019 (item, (const uint8_t *)mask,
2020 (const uint8_t *)&gre_key_default_mask,
2021 sizeof(rte_be32_t), error);
2026 * Validate GRE item.
2029 * Item specification.
2030 * @param[in] item_flags
2031 * Bit flags to mark detected items.
2032 * @param[in] target_protocol
2033 * The next protocol in the previous item.
2035 * Pointer to error structure.
2038 * 0 on success, a negative errno value otherwise and rte_errno is set.
2041 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2042 uint64_t item_flags,
2043 uint8_t target_protocol,
2044 struct rte_flow_error *error)
2046 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2047 const struct rte_flow_item_gre *mask = item->mask;
2049 const struct rte_flow_item_gre nic_mask = {
2050 .c_rsvd0_ver = RTE_BE16(0xB000),
2051 .protocol = RTE_BE16(UINT16_MAX),
2054 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2055 return rte_flow_error_set(error, EINVAL,
2056 RTE_FLOW_ERROR_TYPE_ITEM, item,
2057 "protocol filtering not compatible"
2058 " with this GRE layer");
2059 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2060 return rte_flow_error_set(error, ENOTSUP,
2061 RTE_FLOW_ERROR_TYPE_ITEM, item,
2062 "multiple tunnel layers not"
2064 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2065 return rte_flow_error_set(error, ENOTSUP,
2066 RTE_FLOW_ERROR_TYPE_ITEM, item,
2067 "L3 Layer is missing");
2069 mask = &rte_flow_item_gre_mask;
2070 ret = mlx5_flow_item_acceptable
2071 (item, (const uint8_t *)mask,
2072 (const uint8_t *)&nic_mask,
2073 sizeof(struct rte_flow_item_gre), error);
2076 #ifndef HAVE_MLX5DV_DR
2077 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2078 if (spec && (spec->protocol & mask->protocol))
2079 return rte_flow_error_set(error, ENOTSUP,
2080 RTE_FLOW_ERROR_TYPE_ITEM, item,
2081 "without MPLS support the"
2082 " specification cannot be used for"
2090 * Validate Geneve item.
2093 * Item specification.
2094 * @param[in] itemFlags
2095 * Bit-fields that holds the items detected until now.
2097 * Pointer to the private data structure.
2099 * Pointer to error structure.
2102 * 0 on success, a negative errno value otherwise and rte_errno is set.
2106 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2107 uint64_t item_flags,
2108 struct rte_eth_dev *dev,
2109 struct rte_flow_error *error)
2111 struct mlx5_priv *priv = dev->data->dev_private;
2112 const struct rte_flow_item_geneve *spec = item->spec;
2113 const struct rte_flow_item_geneve *mask = item->mask;
2116 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2117 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2118 const struct rte_flow_item_geneve nic_mask = {
2119 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2120 .vni = "\xff\xff\xff",
2121 .protocol = RTE_BE16(UINT16_MAX),
2124 if (!(priv->config.hca_attr.flex_parser_protocols &
2125 MLX5_HCA_FLEX_GENEVE_ENABLED) ||
2126 !priv->config.hca_attr.tunnel_stateless_geneve_rx)
2127 return rte_flow_error_set(error, ENOTSUP,
2128 RTE_FLOW_ERROR_TYPE_ITEM, item,
2129 "L3 Geneve is not enabled by device"
2130 " parameter and/or not configured in"
2132 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2133 return rte_flow_error_set(error, ENOTSUP,
2134 RTE_FLOW_ERROR_TYPE_ITEM, item,
2135 "multiple tunnel layers not"
2138 * Verify only UDPv4 is present as defined in
2139 * https://tools.ietf.org/html/rfc7348
2141 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2142 return rte_flow_error_set(error, EINVAL,
2143 RTE_FLOW_ERROR_TYPE_ITEM, item,
2144 "no outer UDP layer found");
2146 mask = &rte_flow_item_geneve_mask;
2147 ret = mlx5_flow_item_acceptable
2148 (item, (const uint8_t *)mask,
2149 (const uint8_t *)&nic_mask,
2150 sizeof(struct rte_flow_item_geneve), error);
2154 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2155 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2156 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2157 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2158 return rte_flow_error_set(error, ENOTSUP,
2159 RTE_FLOW_ERROR_TYPE_ITEM,
2161 "Geneve protocol unsupported"
2162 " fields are being used");
2163 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2164 return rte_flow_error_set
2166 RTE_FLOW_ERROR_TYPE_ITEM,
2168 "Unsupported Geneve options length");
2170 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2171 return rte_flow_error_set
2173 RTE_FLOW_ERROR_TYPE_ITEM, item,
2174 "Geneve tunnel must be fully defined");
2179 * Validate MPLS item.
2182 * Pointer to the rte_eth_dev structure.
2184 * Item specification.
2185 * @param[in] item_flags
2186 * Bit-fields that holds the items detected until now.
2187 * @param[in] prev_layer
2188 * The protocol layer indicated in previous item.
2190 * Pointer to error structure.
2193 * 0 on success, a negative errno value otherwise and rte_errno is set.
2196 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2197 const struct rte_flow_item *item __rte_unused,
2198 uint64_t item_flags __rte_unused,
2199 uint64_t prev_layer __rte_unused,
2200 struct rte_flow_error *error)
2202 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2203 const struct rte_flow_item_mpls *mask = item->mask;
2204 struct mlx5_priv *priv = dev->data->dev_private;
2207 if (!priv->config.mpls_en)
2208 return rte_flow_error_set(error, ENOTSUP,
2209 RTE_FLOW_ERROR_TYPE_ITEM, item,
2210 "MPLS not supported or"
2211 " disabled in firmware"
2213 /* MPLS over IP, UDP, GRE is allowed */
2214 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2215 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2216 MLX5_FLOW_LAYER_GRE)))
2217 return rte_flow_error_set(error, EINVAL,
2218 RTE_FLOW_ERROR_TYPE_ITEM, item,
2219 "protocol filtering not compatible"
2220 " with MPLS layer");
2221 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2222 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2223 !(item_flags & MLX5_FLOW_LAYER_GRE))
2224 return rte_flow_error_set(error, ENOTSUP,
2225 RTE_FLOW_ERROR_TYPE_ITEM, item,
2226 "multiple tunnel layers not"
2229 mask = &rte_flow_item_mpls_mask;
2230 ret = mlx5_flow_item_acceptable
2231 (item, (const uint8_t *)mask,
2232 (const uint8_t *)&rte_flow_item_mpls_mask,
2233 sizeof(struct rte_flow_item_mpls), error);
2238 return rte_flow_error_set(error, ENOTSUP,
2239 RTE_FLOW_ERROR_TYPE_ITEM, item,
2240 "MPLS is not supported by Verbs, please"
2245 * Validate NVGRE item.
2248 * Item specification.
2249 * @param[in] item_flags
2250 * Bit flags to mark detected items.
2251 * @param[in] target_protocol
2252 * The next protocol in the previous item.
2254 * Pointer to error structure.
2257 * 0 on success, a negative errno value otherwise and rte_errno is set.
2260 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2261 uint64_t item_flags,
2262 uint8_t target_protocol,
2263 struct rte_flow_error *error)
2265 const struct rte_flow_item_nvgre *mask = item->mask;
2268 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2269 return rte_flow_error_set(error, EINVAL,
2270 RTE_FLOW_ERROR_TYPE_ITEM, item,
2271 "protocol filtering not compatible"
2272 " with this GRE layer");
2273 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2274 return rte_flow_error_set(error, ENOTSUP,
2275 RTE_FLOW_ERROR_TYPE_ITEM, item,
2276 "multiple tunnel layers not"
2278 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2279 return rte_flow_error_set(error, ENOTSUP,
2280 RTE_FLOW_ERROR_TYPE_ITEM, item,
2281 "L3 Layer is missing");
2283 mask = &rte_flow_item_nvgre_mask;
2284 ret = mlx5_flow_item_acceptable
2285 (item, (const uint8_t *)mask,
2286 (const uint8_t *)&rte_flow_item_nvgre_mask,
2287 sizeof(struct rte_flow_item_nvgre), error);
2293 /* Allocate unique ID for the split Q/RSS subflows. */
2295 flow_qrss_get_id(struct rte_eth_dev *dev)
2297 struct mlx5_priv *priv = dev->data->dev_private;
2298 uint32_t qrss_id, ret;
2300 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2307 /* Free unique ID for the split Q/RSS subflows. */
2309 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2311 struct mlx5_priv *priv = dev->data->dev_private;
2314 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2318 * Release resource related QUEUE/RSS action split.
2321 * Pointer to Ethernet device.
2323 * Flow to release id's from.
2326 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2327 struct rte_flow *flow)
2329 struct mlx5_flow *dev_flow;
2331 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
2332 if (dev_flow->qrss_id)
2333 flow_qrss_free_id(dev, dev_flow->qrss_id);
2337 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2338 const struct rte_flow_attr *attr __rte_unused,
2339 const struct rte_flow_item items[] __rte_unused,
2340 const struct rte_flow_action actions[] __rte_unused,
2341 bool external __rte_unused,
2342 struct rte_flow_error *error)
2344 return rte_flow_error_set(error, ENOTSUP,
2345 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2348 static struct mlx5_flow *
2349 flow_null_prepare(const struct rte_flow_attr *attr __rte_unused,
2350 const struct rte_flow_item items[] __rte_unused,
2351 const struct rte_flow_action actions[] __rte_unused,
2352 struct rte_flow_error *error)
2354 rte_flow_error_set(error, ENOTSUP,
2355 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2360 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2361 struct mlx5_flow *dev_flow __rte_unused,
2362 const struct rte_flow_attr *attr __rte_unused,
2363 const struct rte_flow_item items[] __rte_unused,
2364 const struct rte_flow_action actions[] __rte_unused,
2365 struct rte_flow_error *error)
2367 return rte_flow_error_set(error, ENOTSUP,
2368 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2372 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2373 struct rte_flow *flow __rte_unused,
2374 struct rte_flow_error *error)
2376 return rte_flow_error_set(error, ENOTSUP,
2377 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2381 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2382 struct rte_flow *flow __rte_unused)
2387 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2388 struct rte_flow *flow __rte_unused)
2393 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2394 struct rte_flow *flow __rte_unused,
2395 const struct rte_flow_action *actions __rte_unused,
2396 void *data __rte_unused,
2397 struct rte_flow_error *error)
2399 return rte_flow_error_set(error, ENOTSUP,
2400 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2403 /* Void driver to protect from null pointer reference. */
2404 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2405 .validate = flow_null_validate,
2406 .prepare = flow_null_prepare,
2407 .translate = flow_null_translate,
2408 .apply = flow_null_apply,
2409 .remove = flow_null_remove,
2410 .destroy = flow_null_destroy,
2411 .query = flow_null_query,
2415 * Select flow driver type according to flow attributes and device
2419 * Pointer to the dev structure.
2421 * Pointer to the flow attributes.
2424 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2426 static enum mlx5_flow_drv_type
2427 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2429 struct mlx5_priv *priv = dev->data->dev_private;
2430 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
2432 if (attr->transfer && priv->config.dv_esw_en)
2433 type = MLX5_FLOW_TYPE_DV;
2434 if (!attr->transfer)
2435 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2436 MLX5_FLOW_TYPE_VERBS;
2440 #define flow_get_drv_ops(type) flow_drv_ops[type]
2443 * Flow driver validation API. This abstracts calling driver specific functions.
2444 * The type of flow driver is determined according to flow attributes.
2447 * Pointer to the dev structure.
2449 * Pointer to the flow attributes.
2451 * Pointer to the list of items.
2452 * @param[in] actions
2453 * Pointer to the list of actions.
2454 * @param[in] external
2455 * This flow rule is created by request external to PMD.
2457 * Pointer to the error structure.
2460 * 0 on success, a negative errno value otherwise and rte_errno is set.
2463 flow_drv_validate(struct rte_eth_dev *dev,
2464 const struct rte_flow_attr *attr,
2465 const struct rte_flow_item items[],
2466 const struct rte_flow_action actions[],
2467 bool external, struct rte_flow_error *error)
2469 const struct mlx5_flow_driver_ops *fops;
2470 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2472 fops = flow_get_drv_ops(type);
2473 return fops->validate(dev, attr, items, actions, external, error);
2477 * Flow driver preparation API. This abstracts calling driver specific
2478 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2479 * calculates the size of memory required for device flow, allocates the memory,
2480 * initializes the device flow and returns the pointer.
2483 * This function initializes device flow structure such as dv or verbs in
2484 * struct mlx5_flow. However, it is caller's responsibility to initialize the
2485 * rest. For example, adding returning device flow to flow->dev_flow list and
2486 * setting backward reference to the flow should be done out of this function.
2487 * layers field is not filled either.
2490 * Pointer to the flow attributes.
2492 * Pointer to the list of items.
2493 * @param[in] actions
2494 * Pointer to the list of actions.
2496 * Pointer to the error structure.
2499 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
2501 static inline struct mlx5_flow *
2502 flow_drv_prepare(const struct rte_flow *flow,
2503 const struct rte_flow_attr *attr,
2504 const struct rte_flow_item items[],
2505 const struct rte_flow_action actions[],
2506 struct rte_flow_error *error)
2508 const struct mlx5_flow_driver_ops *fops;
2509 enum mlx5_flow_drv_type type = flow->drv_type;
2511 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2512 fops = flow_get_drv_ops(type);
2513 return fops->prepare(attr, items, actions, error);
2517 * Flow driver translation API. This abstracts calling driver specific
2518 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2519 * translates a generic flow into a driver flow. flow_drv_prepare() must
2523 * dev_flow->layers could be filled as a result of parsing during translation
2524 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
2525 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
2526 * flow->actions could be overwritten even though all the expanded dev_flows
2527 * have the same actions.
2530 * Pointer to the rte dev structure.
2531 * @param[in, out] dev_flow
2532 * Pointer to the mlx5 flow.
2534 * Pointer to the flow attributes.
2536 * Pointer to the list of items.
2537 * @param[in] actions
2538 * Pointer to the list of actions.
2540 * Pointer to the error structure.
2543 * 0 on success, a negative errno value otherwise and rte_errno is set.
2546 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
2547 const struct rte_flow_attr *attr,
2548 const struct rte_flow_item items[],
2549 const struct rte_flow_action actions[],
2550 struct rte_flow_error *error)
2552 const struct mlx5_flow_driver_ops *fops;
2553 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
2555 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2556 fops = flow_get_drv_ops(type);
2557 return fops->translate(dev, dev_flow, attr, items, actions, error);
2561 * Flow driver apply API. This abstracts calling driver specific functions.
2562 * Parent flow (rte_flow) should have driver type (drv_type). It applies
2563 * translated driver flows on to device. flow_drv_translate() must precede.
2566 * Pointer to Ethernet device structure.
2567 * @param[in, out] flow
2568 * Pointer to flow structure.
2570 * Pointer to error structure.
2573 * 0 on success, a negative errno value otherwise and rte_errno is set.
2576 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
2577 struct rte_flow_error *error)
2579 const struct mlx5_flow_driver_ops *fops;
2580 enum mlx5_flow_drv_type type = flow->drv_type;
2582 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2583 fops = flow_get_drv_ops(type);
2584 return fops->apply(dev, flow, error);
2588 * Flow driver remove API. This abstracts calling driver specific functions.
2589 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2590 * on device. All the resources of the flow should be freed by calling
2591 * flow_drv_destroy().
2594 * Pointer to Ethernet device.
2595 * @param[in, out] flow
2596 * Pointer to flow structure.
2599 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
2601 const struct mlx5_flow_driver_ops *fops;
2602 enum mlx5_flow_drv_type type = flow->drv_type;
2604 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2605 fops = flow_get_drv_ops(type);
2606 fops->remove(dev, flow);
2610 * Flow driver destroy API. This abstracts calling driver specific functions.
2611 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2612 * on device and releases resources of the flow.
2615 * Pointer to Ethernet device.
2616 * @param[in, out] flow
2617 * Pointer to flow structure.
2620 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
2622 const struct mlx5_flow_driver_ops *fops;
2623 enum mlx5_flow_drv_type type = flow->drv_type;
2625 flow_mreg_split_qrss_release(dev, flow);
2626 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2627 fops = flow_get_drv_ops(type);
2628 fops->destroy(dev, flow);
2632 * Validate a flow supported by the NIC.
2634 * @see rte_flow_validate()
2638 mlx5_flow_validate(struct rte_eth_dev *dev,
2639 const struct rte_flow_attr *attr,
2640 const struct rte_flow_item items[],
2641 const struct rte_flow_action actions[],
2642 struct rte_flow_error *error)
2646 ret = flow_drv_validate(dev, attr, items, actions, true, error);
2653 * Get port id item from the item list.
2656 * Pointer to the list of items.
2659 * Pointer to the port id item if exist, else return NULL.
2661 static const struct rte_flow_item *
2662 find_port_id_item(const struct rte_flow_item *item)
2665 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2666 if (item->type == RTE_FLOW_ITEM_TYPE_PORT_ID)
2673 * Get RSS action from the action list.
2675 * @param[in] actions
2676 * Pointer to the list of actions.
2679 * Pointer to the RSS action if exist, else return NULL.
2681 static const struct rte_flow_action_rss*
2682 flow_get_rss_action(const struct rte_flow_action actions[])
2684 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2685 switch (actions->type) {
2686 case RTE_FLOW_ACTION_TYPE_RSS:
2687 return (const struct rte_flow_action_rss *)
2697 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
2699 const struct rte_flow_item *item;
2700 unsigned int has_vlan = 0;
2702 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2703 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2709 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
2710 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
2711 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
2712 MLX5_EXPANSION_ROOT_OUTER;
2716 * Get QUEUE/RSS action from the action list.
2718 * @param[in] actions
2719 * Pointer to the list of actions.
2721 * Pointer to the return pointer.
2722 * @param[out] qrss_type
2723 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
2724 * if no QUEUE/RSS is found.
2727 * Total number of actions.
2730 flow_parse_qrss_action(const struct rte_flow_action actions[],
2731 const struct rte_flow_action **qrss)
2735 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2736 switch (actions->type) {
2737 case RTE_FLOW_ACTION_TYPE_QUEUE:
2738 case RTE_FLOW_ACTION_TYPE_RSS:
2746 /* Count RTE_FLOW_ACTION_TYPE_END. */
2747 return actions_n + 1;
2751 * Check meter action from the action list.
2753 * @param[in] actions
2754 * Pointer to the list of actions.
2756 * Pointer to the meter exist flag.
2759 * Total number of actions.
2762 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
2768 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2769 switch (actions->type) {
2770 case RTE_FLOW_ACTION_TYPE_METER:
2778 /* Count RTE_FLOW_ACTION_TYPE_END. */
2779 return actions_n + 1;
2783 * Check if the flow should be splited due to hairpin.
2784 * The reason for the split is that in current HW we can't
2785 * support encap on Rx, so if a flow have encap we move it
2789 * Pointer to Ethernet device.
2791 * Flow rule attributes.
2792 * @param[in] actions
2793 * Associated actions (list terminated by the END action).
2796 * > 0 the number of actions and the flow should be split,
2797 * 0 when no split required.
2800 flow_check_hairpin_split(struct rte_eth_dev *dev,
2801 const struct rte_flow_attr *attr,
2802 const struct rte_flow_action actions[])
2804 int queue_action = 0;
2807 const struct rte_flow_action_queue *queue;
2808 const struct rte_flow_action_rss *rss;
2809 const struct rte_flow_action_raw_encap *raw_encap;
2813 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2814 switch (actions->type) {
2815 case RTE_FLOW_ACTION_TYPE_QUEUE:
2816 queue = actions->conf;
2819 if (mlx5_rxq_get_type(dev, queue->index) !=
2820 MLX5_RXQ_TYPE_HAIRPIN)
2825 case RTE_FLOW_ACTION_TYPE_RSS:
2826 rss = actions->conf;
2827 if (rss == NULL || rss->queue_num == 0)
2829 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
2830 MLX5_RXQ_TYPE_HAIRPIN)
2835 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2836 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2840 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2841 raw_encap = actions->conf;
2842 if (raw_encap->size >
2843 (sizeof(struct rte_flow_item_eth) +
2844 sizeof(struct rte_flow_item_ipv4)))
2853 if (encap == 1 && queue_action)
2858 /* Declare flow create/destroy prototype in advance. */
2859 static struct rte_flow *
2860 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
2861 const struct rte_flow_attr *attr,
2862 const struct rte_flow_item items[],
2863 const struct rte_flow_action actions[],
2864 bool external, struct rte_flow_error *error);
2867 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
2868 struct rte_flow *flow);
2871 * Add a flow of copying flow metadata registers in RX_CP_TBL.
2873 * As mark_id is unique, if there's already a registered flow for the mark_id,
2874 * return by increasing the reference counter of the resource. Otherwise, create
2875 * the resource (mcp_res) and flow.
2878 * - If ingress port is ANY and reg_c[1] is mark_id,
2879 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
2881 * For default flow (zero mark_id), flow is like,
2882 * - If ingress port is ANY,
2883 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
2886 * Pointer to Ethernet device.
2888 * ID of MARK action, zero means default flow for META.
2890 * Perform verbose error reporting if not NULL.
2893 * Associated resource on success, NULL otherwise and rte_errno is set.
2895 static struct mlx5_flow_mreg_copy_resource *
2896 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
2897 struct rte_flow_error *error)
2899 struct mlx5_priv *priv = dev->data->dev_private;
2900 struct rte_flow_attr attr = {
2901 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
2904 struct mlx5_rte_flow_item_tag tag_spec = {
2907 struct rte_flow_item items[] = {
2908 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
2910 struct rte_flow_action_mark ftag = {
2913 struct mlx5_flow_action_copy_mreg cp_mreg = {
2917 struct rte_flow_action_jump jump = {
2918 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
2920 struct rte_flow_action actions[] = {
2921 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
2923 struct mlx5_flow_mreg_copy_resource *mcp_res;
2926 /* Fill the register fileds in the flow. */
2927 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2931 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
2935 /* Check if already registered. */
2936 assert(priv->mreg_cp_tbl);
2937 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
2939 /* For non-default rule. */
2942 assert(mark_id || mcp_res->refcnt == 1);
2945 /* Provide the full width of FLAG specific value. */
2946 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
2947 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
2948 /* Build a new flow. */
2950 items[0] = (struct rte_flow_item){
2951 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
2954 items[1] = (struct rte_flow_item){
2955 .type = RTE_FLOW_ITEM_TYPE_END,
2957 actions[0] = (struct rte_flow_action){
2958 .type = MLX5_RTE_FLOW_ACTION_TYPE_MARK,
2961 actions[1] = (struct rte_flow_action){
2962 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
2965 actions[2] = (struct rte_flow_action){
2966 .type = RTE_FLOW_ACTION_TYPE_JUMP,
2969 actions[3] = (struct rte_flow_action){
2970 .type = RTE_FLOW_ACTION_TYPE_END,
2973 /* Default rule, wildcard match. */
2974 attr.priority = MLX5_FLOW_PRIO_RSVD;
2975 items[0] = (struct rte_flow_item){
2976 .type = RTE_FLOW_ITEM_TYPE_END,
2978 actions[0] = (struct rte_flow_action){
2979 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
2982 actions[1] = (struct rte_flow_action){
2983 .type = RTE_FLOW_ACTION_TYPE_JUMP,
2986 actions[2] = (struct rte_flow_action){
2987 .type = RTE_FLOW_ACTION_TYPE_END,
2990 /* Build a new entry. */
2991 mcp_res = rte_zmalloc(__func__, sizeof(*mcp_res), 0);
2997 * The copy Flows are not included in any list. There
2998 * ones are referenced from other Flows and can not
2999 * be applied, removed, deleted in ardbitrary order
3000 * by list traversing.
3002 mcp_res->flow = flow_list_create(dev, NULL, &attr, items,
3003 actions, false, error);
3007 mcp_res->hlist_ent.key = mark_id;
3008 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3009 &mcp_res->hlist_ent);
3016 flow_list_destroy(dev, NULL, mcp_res->flow);
3022 * Release flow in RX_CP_TBL.
3025 * Pointer to Ethernet device.
3027 * Parent flow for wich copying is provided.
3030 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3031 struct rte_flow *flow)
3033 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3034 struct mlx5_priv *priv = dev->data->dev_private;
3036 if (!mcp_res || !priv->mreg_cp_tbl)
3038 if (flow->copy_applied) {
3039 assert(mcp_res->appcnt);
3040 flow->copy_applied = 0;
3042 if (!mcp_res->appcnt)
3043 flow_drv_remove(dev, mcp_res->flow);
3046 * We do not check availability of metadata registers here,
3047 * because copy resources are allocated in this case.
3049 if (--mcp_res->refcnt)
3051 assert(mcp_res->flow);
3052 flow_list_destroy(dev, NULL, mcp_res->flow);
3053 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3055 flow->mreg_copy = NULL;
3059 * Start flow in RX_CP_TBL.
3062 * Pointer to Ethernet device.
3064 * Parent flow for wich copying is provided.
3067 * 0 on success, a negative errno value otherwise and rte_errno is set.
3070 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3071 struct rte_flow *flow)
3073 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3076 if (!mcp_res || flow->copy_applied)
3078 if (!mcp_res->appcnt) {
3079 ret = flow_drv_apply(dev, mcp_res->flow, NULL);
3084 flow->copy_applied = 1;
3089 * Stop flow in RX_CP_TBL.
3092 * Pointer to Ethernet device.
3094 * Parent flow for wich copying is provided.
3097 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3098 struct rte_flow *flow)
3100 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3102 if (!mcp_res || !flow->copy_applied)
3104 assert(mcp_res->appcnt);
3106 flow->copy_applied = 0;
3107 if (!mcp_res->appcnt)
3108 flow_drv_remove(dev, mcp_res->flow);
3112 * Remove the default copy action from RX_CP_TBL.
3115 * Pointer to Ethernet device.
3118 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3120 struct mlx5_flow_mreg_copy_resource *mcp_res;
3121 struct mlx5_priv *priv = dev->data->dev_private;
3123 /* Check if default flow is registered. */
3124 if (!priv->mreg_cp_tbl)
3126 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, 0ULL);
3129 assert(mcp_res->flow);
3130 flow_list_destroy(dev, NULL, mcp_res->flow);
3131 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3136 * Add the default copy action in in RX_CP_TBL.
3139 * Pointer to Ethernet device.
3141 * Perform verbose error reporting if not NULL.
3144 * 0 for success, negative value otherwise and rte_errno is set.
3147 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3148 struct rte_flow_error *error)
3150 struct mlx5_priv *priv = dev->data->dev_private;
3151 struct mlx5_flow_mreg_copy_resource *mcp_res;
3153 /* Check whether extensive metadata feature is engaged. */
3154 if (!priv->config.dv_flow_en ||
3155 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3156 !mlx5_flow_ext_mreg_supported(dev) ||
3157 !priv->sh->dv_regc0_mask)
3159 mcp_res = flow_mreg_add_copy_action(dev, 0, error);
3166 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3168 * All the flow having Q/RSS action should be split by
3169 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3170 * performs the following,
3171 * - CQE->flow_tag := reg_c[1] (MARK)
3172 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3173 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3174 * but there should be a flow per each MARK ID set by MARK action.
3176 * For the aforementioned reason, if there's a MARK action in flow's action
3177 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3178 * the MARK ID to CQE's flow_tag like,
3179 * - If reg_c[1] is mark_id,
3180 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3182 * For SET_META action which stores value in reg_c[0], as the destination is
3183 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3184 * MARK ID means the default flow. The default flow looks like,
3185 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3188 * Pointer to Ethernet device.
3190 * Pointer to flow structure.
3191 * @param[in] actions
3192 * Pointer to the list of actions.
3194 * Perform verbose error reporting if not NULL.
3197 * 0 on success, negative value otherwise and rte_errno is set.
3200 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3201 struct rte_flow *flow,
3202 const struct rte_flow_action *actions,
3203 struct rte_flow_error *error)
3205 struct mlx5_priv *priv = dev->data->dev_private;
3206 struct mlx5_dev_config *config = &priv->config;
3207 struct mlx5_flow_mreg_copy_resource *mcp_res;
3208 const struct rte_flow_action_mark *mark;
3210 /* Check whether extensive metadata feature is engaged. */
3211 if (!config->dv_flow_en ||
3212 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3213 !mlx5_flow_ext_mreg_supported(dev) ||
3214 !priv->sh->dv_regc0_mask)
3216 /* Find MARK action. */
3217 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3218 switch (actions->type) {
3219 case RTE_FLOW_ACTION_TYPE_FLAG:
3220 mcp_res = flow_mreg_add_copy_action
3221 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3224 flow->mreg_copy = mcp_res;
3225 if (dev->data->dev_started) {
3227 flow->copy_applied = 1;
3230 case RTE_FLOW_ACTION_TYPE_MARK:
3231 mark = (const struct rte_flow_action_mark *)
3234 flow_mreg_add_copy_action(dev, mark->id, error);
3237 flow->mreg_copy = mcp_res;
3238 if (dev->data->dev_started) {
3240 flow->copy_applied = 1;
3250 #define MLX5_MAX_SPLIT_ACTIONS 24
3251 #define MLX5_MAX_SPLIT_ITEMS 24
3254 * Split the hairpin flow.
3255 * Since HW can't support encap on Rx we move the encap to Tx.
3256 * If the count action is after the encap then we also
3257 * move the count action. in this case the count will also measure
3261 * Pointer to Ethernet device.
3262 * @param[in] actions
3263 * Associated actions (list terminated by the END action).
3264 * @param[out] actions_rx
3266 * @param[out] actions_tx
3268 * @param[out] pattern_tx
3269 * The pattern items for the Tx flow.
3270 * @param[out] flow_id
3271 * The flow ID connected to this flow.
3277 flow_hairpin_split(struct rte_eth_dev *dev,
3278 const struct rte_flow_action actions[],
3279 struct rte_flow_action actions_rx[],
3280 struct rte_flow_action actions_tx[],
3281 struct rte_flow_item pattern_tx[],
3284 struct mlx5_priv *priv = dev->data->dev_private;
3285 const struct rte_flow_action_raw_encap *raw_encap;
3286 const struct rte_flow_action_raw_decap *raw_decap;
3287 struct mlx5_rte_flow_action_set_tag *set_tag;
3288 struct rte_flow_action *tag_action;
3289 struct mlx5_rte_flow_item_tag *tag_item;
3290 struct rte_flow_item *item;
3294 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
3295 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3296 switch (actions->type) {
3297 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3298 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3299 rte_memcpy(actions_tx, actions,
3300 sizeof(struct rte_flow_action));
3303 case RTE_FLOW_ACTION_TYPE_COUNT:
3305 rte_memcpy(actions_tx, actions,
3306 sizeof(struct rte_flow_action));
3309 rte_memcpy(actions_rx, actions,
3310 sizeof(struct rte_flow_action));
3314 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3315 raw_encap = actions->conf;
3316 if (raw_encap->size >
3317 (sizeof(struct rte_flow_item_eth) +
3318 sizeof(struct rte_flow_item_ipv4))) {
3319 memcpy(actions_tx, actions,
3320 sizeof(struct rte_flow_action));
3324 rte_memcpy(actions_rx, actions,
3325 sizeof(struct rte_flow_action));
3329 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3330 raw_decap = actions->conf;
3331 if (raw_decap->size <
3332 (sizeof(struct rte_flow_item_eth) +
3333 sizeof(struct rte_flow_item_ipv4))) {
3334 memcpy(actions_tx, actions,
3335 sizeof(struct rte_flow_action));
3338 rte_memcpy(actions_rx, actions,
3339 sizeof(struct rte_flow_action));
3344 rte_memcpy(actions_rx, actions,
3345 sizeof(struct rte_flow_action));
3350 /* Add set meta action and end action for the Rx flow. */
3351 tag_action = actions_rx;
3352 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3354 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
3356 set_tag = (void *)actions_rx;
3357 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
3358 assert(set_tag->id > REG_NONE);
3359 set_tag->data = *flow_id;
3360 tag_action->conf = set_tag;
3361 /* Create Tx item list. */
3362 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
3363 addr = (void *)&pattern_tx[2];
3365 item->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3366 tag_item = (void *)addr;
3367 tag_item->data = *flow_id;
3368 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
3369 assert(set_tag->id > REG_NONE);
3370 item->spec = tag_item;
3371 addr += sizeof(struct mlx5_rte_flow_item_tag);
3372 tag_item = (void *)addr;
3373 tag_item->data = UINT32_MAX;
3374 tag_item->id = UINT16_MAX;
3375 item->mask = tag_item;
3376 addr += sizeof(struct mlx5_rte_flow_item_tag);
3379 item->type = RTE_FLOW_ITEM_TYPE_END;
3384 * The last stage of splitting chain, just creates the subflow
3385 * without any modification.
3388 * Pointer to Ethernet device.
3390 * Parent flow structure pointer.
3391 * @param[in, out] sub_flow
3392 * Pointer to return the created subflow, may be NULL.
3394 * Flow rule attributes.
3396 * Pattern specification (list terminated by the END pattern item).
3397 * @param[in] actions
3398 * Associated actions (list terminated by the END action).
3399 * @param[in] external
3400 * This flow rule is created by request external to PMD.
3402 * Perform verbose error reporting if not NULL.
3404 * 0 on success, negative value otherwise
3407 flow_create_split_inner(struct rte_eth_dev *dev,
3408 struct rte_flow *flow,
3409 struct mlx5_flow **sub_flow,
3410 const struct rte_flow_attr *attr,
3411 const struct rte_flow_item items[],
3412 const struct rte_flow_action actions[],
3413 bool external, struct rte_flow_error *error)
3415 struct mlx5_flow *dev_flow;
3417 dev_flow = flow_drv_prepare(flow, attr, items, actions, error);
3420 dev_flow->flow = flow;
3421 dev_flow->external = external;
3422 /* Subflow object was created, we must include one in the list. */
3423 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
3425 *sub_flow = dev_flow;
3426 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
3430 * Split the meter flow.
3432 * As meter flow will split to three sub flow, other than meter
3433 * action, the other actions make sense to only meter accepts
3434 * the packet. If it need to be dropped, no other additional
3435 * actions should be take.
3437 * One kind of special action which decapsulates the L3 tunnel
3438 * header will be in the prefix sub flow, as not to take the
3439 * L3 tunnel header into account.
3442 * Pointer to Ethernet device.
3443 * @param[in] actions
3444 * Associated actions (list terminated by the END action).
3445 * @param[out] actions_sfx
3446 * Suffix flow actions.
3447 * @param[out] actions_pre
3448 * Prefix flow actions.
3449 * @param[out] pattern_sfx
3450 * The pattern items for the suffix flow.
3451 * @param[out] tag_sfx
3452 * Pointer to suffix flow tag.
3458 flow_meter_split_prep(struct rte_eth_dev *dev,
3459 const struct rte_flow_action actions[],
3460 struct rte_flow_action actions_sfx[],
3461 struct rte_flow_action actions_pre[])
3463 struct rte_flow_action *tag_action;
3464 struct mlx5_rte_flow_action_set_tag *set_tag;
3465 struct rte_flow_error error;
3466 const struct rte_flow_action_raw_encap *raw_encap;
3467 const struct rte_flow_action_raw_decap *raw_decap;
3470 /* Add the extra tag action first. */
3471 tag_action = actions_pre;
3472 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3474 /* Prepare the actions for prefix and suffix flow. */
3475 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3476 switch (actions->type) {
3477 case RTE_FLOW_ACTION_TYPE_METER:
3478 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3479 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3480 memcpy(actions_pre, actions,
3481 sizeof(struct rte_flow_action));
3484 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3485 raw_encap = actions->conf;
3486 if (raw_encap->size >
3487 (sizeof(struct rte_flow_item_eth) +
3488 sizeof(struct rte_flow_item_ipv4))) {
3489 memcpy(actions_sfx, actions,
3490 sizeof(struct rte_flow_action));
3493 rte_memcpy(actions_pre, actions,
3494 sizeof(struct rte_flow_action));
3498 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3499 raw_decap = actions->conf;
3500 /* Size 0 decap means 50 bytes as vxlan decap. */
3501 if (raw_decap->size && (raw_decap->size <
3502 (sizeof(struct rte_flow_item_eth) +
3503 sizeof(struct rte_flow_item_ipv4)))) {
3504 memcpy(actions_sfx, actions,
3505 sizeof(struct rte_flow_action));
3508 rte_memcpy(actions_pre, actions,
3509 sizeof(struct rte_flow_action));
3514 memcpy(actions_sfx, actions,
3515 sizeof(struct rte_flow_action));
3520 /* Add end action to the actions. */
3521 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
3522 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
3525 set_tag = (void *)actions_pre;
3526 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3528 * Get the id from the qrss_pool to make qrss share the id with meter.
3530 tag_id = flow_qrss_get_id(dev);
3531 set_tag->data = rte_cpu_to_be_32(tag_id);
3532 tag_action->conf = set_tag;
3537 * Split action list having QUEUE/RSS for metadata register copy.
3539 * Once Q/RSS action is detected in user's action list, the flow action
3540 * should be split in order to copy metadata registers, which will happen in
3542 * - CQE->flow_tag := reg_c[1] (MARK)
3543 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3544 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
3545 * This is because the last action of each flow must be a terminal action
3546 * (QUEUE, RSS or DROP).
3548 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
3549 * stored and kept in the mlx5_flow structure per each sub_flow.
3551 * The Q/RSS action is replaced with,
3552 * - SET_TAG, setting the allocated flow ID to reg_c[2].
3553 * And the following JUMP action is added at the end,
3554 * - JUMP, to RX_CP_TBL.
3556 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
3557 * flow_create_split_metadata() routine. The flow will look like,
3558 * - If flow ID matches (reg_c[2]), perform Q/RSS.
3561 * Pointer to Ethernet device.
3562 * @param[out] split_actions
3563 * Pointer to store split actions to jump to CP_TBL.
3564 * @param[in] actions
3565 * Pointer to the list of original flow actions.
3567 * Pointer to the Q/RSS action.
3568 * @param[in] actions_n
3569 * Number of original actions.
3571 * Perform verbose error reporting if not NULL.
3574 * non-zero unique flow_id on success, otherwise 0 and
3575 * error/rte_error are set.
3578 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
3579 struct rte_flow_action *split_actions,
3580 const struct rte_flow_action *actions,
3581 const struct rte_flow_action *qrss,
3582 int actions_n, struct rte_flow_error *error)
3584 struct mlx5_rte_flow_action_set_tag *set_tag;
3585 struct rte_flow_action_jump *jump;
3586 const int qrss_idx = qrss - actions;
3587 uint32_t flow_id = 0;
3591 * Given actions will be split
3592 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
3593 * - Add jump to mreg CP_TBL.
3594 * As a result, there will be one more action.
3597 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
3598 set_tag = (void *)(split_actions + actions_n);
3600 * If tag action is not set to void(it means we are not the meter
3601 * suffix flow), add the tag action. Since meter suffix flow already
3602 * has the tag added.
3604 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
3606 * Allocate the new subflow ID. This one is unique within
3607 * device and not shared with representors. Otherwise,
3608 * we would have to resolve multi-thread access synch
3609 * issue. Each flow on the shared device is appended
3610 * with source vport identifier, so the resulting
3611 * flows will be unique in the shared (by master and
3612 * representors) domain even if they have coinciding
3615 flow_id = flow_qrss_get_id(dev);
3617 return rte_flow_error_set(error, ENOMEM,
3618 RTE_FLOW_ERROR_TYPE_ACTION,
3619 NULL, "can't allocate id "
3620 "for split Q/RSS subflow");
3621 /* Internal SET_TAG action to set flow ID. */
3622 *set_tag = (struct mlx5_rte_flow_action_set_tag){
3625 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
3629 /* Construct new actions array. */
3630 /* Replace QUEUE/RSS action. */
3631 split_actions[qrss_idx] = (struct rte_flow_action){
3632 .type = MLX5_RTE_FLOW_ACTION_TYPE_TAG,
3636 /* JUMP action to jump to mreg copy table (CP_TBL). */
3637 jump = (void *)(set_tag + 1);
3638 *jump = (struct rte_flow_action_jump){
3639 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3641 split_actions[actions_n - 2] = (struct rte_flow_action){
3642 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3645 split_actions[actions_n - 1] = (struct rte_flow_action){
3646 .type = RTE_FLOW_ACTION_TYPE_END,
3652 * Extend the given action list for Tx metadata copy.
3654 * Copy the given action list to the ext_actions and add flow metadata register
3655 * copy action in order to copy reg_a set by WQE to reg_c[0].
3657 * @param[out] ext_actions
3658 * Pointer to the extended action list.
3659 * @param[in] actions
3660 * Pointer to the list of actions.
3661 * @param[in] actions_n
3662 * Number of actions in the list.
3664 * Perform verbose error reporting if not NULL.
3667 * 0 on success, negative value otherwise
3670 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
3671 struct rte_flow_action *ext_actions,
3672 const struct rte_flow_action *actions,
3673 int actions_n, struct rte_flow_error *error)
3675 struct mlx5_flow_action_copy_mreg *cp_mreg =
3676 (struct mlx5_flow_action_copy_mreg *)
3677 (ext_actions + actions_n + 1);
3680 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3684 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
3688 memcpy(ext_actions, actions,
3689 sizeof(*ext_actions) * actions_n);
3690 ext_actions[actions_n - 1] = (struct rte_flow_action){
3691 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3694 ext_actions[actions_n] = (struct rte_flow_action){
3695 .type = RTE_FLOW_ACTION_TYPE_END,
3701 * The splitting for metadata feature.
3703 * - Q/RSS action on NIC Rx should be split in order to pass by
3704 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3705 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3707 * - All the actions on NIC Tx should have a mreg copy action to
3708 * copy reg_a from WQE to reg_c[0].
3711 * Pointer to Ethernet device.
3713 * Parent flow structure pointer.
3715 * Flow rule attributes.
3717 * Pattern specification (list terminated by the END pattern item).
3718 * @param[in] actions
3719 * Associated actions (list terminated by the END action).
3720 * @param[in] external
3721 * This flow rule is created by request external to PMD.
3723 * Perform verbose error reporting if not NULL.
3725 * 0 on success, negative value otherwise
3728 flow_create_split_metadata(struct rte_eth_dev *dev,
3729 struct rte_flow *flow,
3730 const struct rte_flow_attr *attr,
3731 const struct rte_flow_item items[],
3732 const struct rte_flow_action actions[],
3733 bool external, struct rte_flow_error *error)
3735 struct mlx5_priv *priv = dev->data->dev_private;
3736 struct mlx5_dev_config *config = &priv->config;
3737 const struct rte_flow_action *qrss = NULL;
3738 struct rte_flow_action *ext_actions = NULL;
3739 struct mlx5_flow *dev_flow = NULL;
3740 uint32_t qrss_id = 0;
3746 /* Check whether extensive metadata feature is engaged. */
3747 if (!config->dv_flow_en ||
3748 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3749 !mlx5_flow_ext_mreg_supported(dev))
3750 return flow_create_split_inner(dev, flow, NULL, attr, items,
3751 actions, external, error);
3752 actions_n = flow_parse_qrss_action(actions, &qrss);
3754 /* Exclude hairpin flows from splitting. */
3755 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
3756 const struct rte_flow_action_queue *queue;
3759 if (mlx5_rxq_get_type(dev, queue->index) ==
3760 MLX5_RXQ_TYPE_HAIRPIN)
3762 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
3763 const struct rte_flow_action_rss *rss;
3766 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
3767 MLX5_RXQ_TYPE_HAIRPIN)
3772 /* Check if it is in meter suffix table. */
3773 mtr_sfx = attr->group == (attr->transfer ?
3774 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
3775 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
3777 * Q/RSS action on NIC Rx should be split in order to pass by
3778 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3779 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3781 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3782 sizeof(struct rte_flow_action_set_tag) +
3783 sizeof(struct rte_flow_action_jump);
3784 ext_actions = rte_zmalloc(__func__, act_size, 0);
3786 return rte_flow_error_set(error, ENOMEM,
3787 RTE_FLOW_ERROR_TYPE_ACTION,
3788 NULL, "no memory to split "
3791 * If we are the suffix flow of meter, tag already exist.
3792 * Set the tag action to void.
3795 ext_actions[qrss - actions].type =
3796 RTE_FLOW_ACTION_TYPE_VOID;
3798 ext_actions[qrss - actions].type =
3799 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3801 * Create the new actions list with removed Q/RSS action
3802 * and appended set tag and jump to register copy table
3803 * (RX_CP_TBL). We should preallocate unique tag ID here
3804 * in advance, because it is needed for set tag action.
3806 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
3807 qrss, actions_n, error);
3808 if (!mtr_sfx && !qrss_id) {
3812 } else if (attr->egress && !attr->transfer) {
3814 * All the actions on NIC Tx should have a metadata register
3815 * copy action to copy reg_a from WQE to reg_c[meta]
3817 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3818 sizeof(struct mlx5_flow_action_copy_mreg);
3819 ext_actions = rte_zmalloc(__func__, act_size, 0);
3821 return rte_flow_error_set(error, ENOMEM,
3822 RTE_FLOW_ERROR_TYPE_ACTION,
3823 NULL, "no memory to split "
3825 /* Create the action list appended with copy register. */
3826 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
3831 /* Add the unmodified original or prefix subflow. */
3832 ret = flow_create_split_inner(dev, flow, &dev_flow, attr, items,
3833 ext_actions ? ext_actions : actions,
3839 const struct rte_flow_attr q_attr = {
3840 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3843 /* Internal PMD action to set register. */
3844 struct mlx5_rte_flow_item_tag q_tag_spec = {
3848 struct rte_flow_item q_items[] = {
3850 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3851 .spec = &q_tag_spec,
3856 .type = RTE_FLOW_ITEM_TYPE_END,
3859 struct rte_flow_action q_actions[] = {
3865 .type = RTE_FLOW_ACTION_TYPE_END,
3868 uint64_t hash_fields = dev_flow->hash_fields;
3871 * Configure the tag item only if there is no meter subflow.
3872 * Since tag is already marked in the meter suffix subflow
3873 * we can just use the meter suffix items as is.
3876 /* Not meter subflow. */
3879 * Put unique id in prefix flow due to it is destroyed
3880 * after suffix flow and id will be freed after there
3881 * is no actual flows with this id and identifier
3882 * reallocation becomes possible (for example, for
3883 * other flows in other threads).
3885 dev_flow->qrss_id = qrss_id;
3887 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
3891 q_tag_spec.id = ret;
3894 /* Add suffix subflow to execute Q/RSS. */
3895 ret = flow_create_split_inner(dev, flow, &dev_flow,
3896 &q_attr, mtr_sfx ? items :
3902 dev_flow->hash_fields = hash_fields;
3907 * We do not destroy the partially created sub_flows in case of error.
3908 * These ones are included into parent flow list and will be destroyed
3909 * by flow_drv_destroy.
3911 flow_qrss_free_id(dev, qrss_id);
3912 rte_free(ext_actions);
3917 * The splitting for meter feature.
3919 * - The meter flow will be split to two flows as prefix and
3920 * suffix flow. The packets make sense only it pass the prefix
3923 * - Reg_C_5 is used for the packet to match betweend prefix and
3927 * Pointer to Ethernet device.
3929 * Parent flow structure pointer.
3931 * Flow rule attributes.
3933 * Pattern specification (list terminated by the END pattern item).
3934 * @param[in] actions
3935 * Associated actions (list terminated by the END action).
3936 * @param[in] external
3937 * This flow rule is created by request external to PMD.
3939 * Perform verbose error reporting if not NULL.
3941 * 0 on success, negative value otherwise
3944 flow_create_split_meter(struct rte_eth_dev *dev,
3945 struct rte_flow *flow,
3946 const struct rte_flow_attr *attr,
3947 const struct rte_flow_item items[],
3948 const struct rte_flow_action actions[],
3949 bool external, struct rte_flow_error *error)
3951 struct mlx5_priv *priv = dev->data->dev_private;
3952 struct rte_flow_action *sfx_actions = NULL;
3953 struct rte_flow_action *pre_actions = NULL;
3954 struct rte_flow_item *sfx_items = NULL;
3955 const struct rte_flow_item *sfx_port_id_item;
3956 struct mlx5_flow *dev_flow = NULL;
3957 struct rte_flow_attr sfx_attr = *attr;
3959 uint32_t mtr_tag_id = 0;
3966 actions_n = flow_check_meter_action(actions, &mtr);
3968 struct mlx5_rte_flow_item_tag *tag_spec;
3969 /* The five prefix actions: meter, decap, encap, tag, end. */
3970 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
3971 sizeof(struct rte_flow_action_set_tag);
3973 #define METER_SUFFIX_ITEM 3
3974 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
3975 sizeof(struct mlx5_rte_flow_item_tag);
3976 sfx_actions = rte_zmalloc(__func__, (act_size + item_size), 0);
3978 return rte_flow_error_set(error, ENOMEM,
3979 RTE_FLOW_ERROR_TYPE_ACTION,
3980 NULL, "no memory to split "
3982 pre_actions = sfx_actions + actions_n;
3983 mtr_tag_id = flow_meter_split_prep(dev, actions, sfx_actions,
3989 /* Add the prefix subflow. */
3990 ret = flow_create_split_inner(dev, flow, &dev_flow, attr, items,
3991 pre_actions, external, error);
3996 dev_flow->mtr_flow_id = mtr_tag_id;
3997 /* Prepare the suffix flow match pattern. */
3998 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4000 tag_spec = (struct mlx5_rte_flow_item_tag *)(sfx_items +
4002 tag_spec->data = rte_cpu_to_be_32(dev_flow->mtr_flow_id);
4003 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0,
4005 sfx_items->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4006 sfx_items->spec = tag_spec;
4007 sfx_items->last = NULL;
4008 sfx_items->mask = NULL;
4010 sfx_port_id_item = find_port_id_item(items);
4011 if (sfx_port_id_item) {
4012 memcpy(sfx_items, sfx_port_id_item,
4013 sizeof(*sfx_items));
4016 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4017 sfx_items -= METER_SUFFIX_ITEM;
4018 /* Setting the sfx group atrr. */
4019 sfx_attr.group = sfx_attr.transfer ?
4020 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4021 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4023 /* Add the prefix subflow. */
4024 ret = flow_create_split_metadata(dev, flow, &sfx_attr,
4025 sfx_items ? sfx_items : items,
4026 sfx_actions ? sfx_actions : actions,
4030 rte_free(sfx_actions);
4035 * Split the flow to subflow set. The splitters might be linked
4036 * in the chain, like this:
4037 * flow_create_split_outer() calls:
4038 * flow_create_split_meter() calls:
4039 * flow_create_split_metadata(meter_subflow_0) calls:
4040 * flow_create_split_inner(metadata_subflow_0)
4041 * flow_create_split_inner(metadata_subflow_1)
4042 * flow_create_split_inner(metadata_subflow_2)
4043 * flow_create_split_metadata(meter_subflow_1) calls:
4044 * flow_create_split_inner(metadata_subflow_0)
4045 * flow_create_split_inner(metadata_subflow_1)
4046 * flow_create_split_inner(metadata_subflow_2)
4048 * This provide flexible way to add new levels of flow splitting.
4049 * The all of successfully created subflows are included to the
4050 * parent flow dev_flow list.
4053 * Pointer to Ethernet device.
4055 * Parent flow structure pointer.
4057 * Flow rule attributes.
4059 * Pattern specification (list terminated by the END pattern item).
4060 * @param[in] actions
4061 * Associated actions (list terminated by the END action).
4062 * @param[in] external
4063 * This flow rule is created by request external to PMD.
4065 * Perform verbose error reporting if not NULL.
4067 * 0 on success, negative value otherwise
4070 flow_create_split_outer(struct rte_eth_dev *dev,
4071 struct rte_flow *flow,
4072 const struct rte_flow_attr *attr,
4073 const struct rte_flow_item items[],
4074 const struct rte_flow_action actions[],
4075 bool external, struct rte_flow_error *error)
4079 ret = flow_create_split_meter(dev, flow, attr, items,
4080 actions, external, error);
4086 * Create a flow and add it to @p list.
4089 * Pointer to Ethernet device.
4091 * Pointer to a TAILQ flow list. If this parameter NULL,
4092 * no list insertion occurred, flow is just created,
4093 * this is caller's responsibility to track the
4096 * Flow rule attributes.
4098 * Pattern specification (list terminated by the END pattern item).
4099 * @param[in] actions
4100 * Associated actions (list terminated by the END action).
4101 * @param[in] external
4102 * This flow rule is created by request external to PMD.
4104 * Perform verbose error reporting if not NULL.
4107 * A flow on success, NULL otherwise and rte_errno is set.
4109 static struct rte_flow *
4110 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
4111 const struct rte_flow_attr *attr,
4112 const struct rte_flow_item items[],
4113 const struct rte_flow_action actions[],
4114 bool external, struct rte_flow_error *error)
4116 struct mlx5_priv *priv = dev->data->dev_private;
4117 struct rte_flow *flow = NULL;
4118 struct mlx5_flow *dev_flow;
4119 const struct rte_flow_action_rss *rss;
4121 struct rte_flow_expand_rss buf;
4122 uint8_t buffer[2048];
4125 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4126 uint8_t buffer[2048];
4129 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4130 uint8_t buffer[2048];
4131 } actions_hairpin_tx;
4133 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
4134 uint8_t buffer[2048];
4136 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
4137 const struct rte_flow_action *p_actions_rx = actions;
4141 int hairpin_flow = 0;
4142 uint32_t hairpin_id = 0;
4143 struct rte_flow_attr attr_tx = { .priority = 0 };
4145 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4146 if (hairpin_flow > 0) {
4147 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
4151 flow_hairpin_split(dev, actions, actions_rx.actions,
4152 actions_hairpin_tx.actions, items_tx.items,
4154 p_actions_rx = actions_rx.actions;
4156 ret = flow_drv_validate(dev, attr, items, p_actions_rx, external,
4159 goto error_before_flow;
4160 flow_size = sizeof(struct rte_flow);
4161 rss = flow_get_rss_action(p_actions_rx);
4163 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
4166 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
4167 flow = rte_calloc(__func__, 1, flow_size, 0);
4170 goto error_before_flow;
4172 flow->drv_type = flow_get_drv_type(dev, attr);
4173 if (hairpin_id != 0)
4174 flow->hairpin_flow_id = hairpin_id;
4175 assert(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
4176 flow->drv_type < MLX5_FLOW_TYPE_MAX);
4177 flow->rss.queue = (void *)(flow + 1);
4180 * The following information is required by
4181 * mlx5_flow_hashfields_adjust() in advance.
4183 flow->rss.level = rss->level;
4184 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
4185 flow->rss.types = !rss->types ? ETH_RSS_IP : rss->types;
4187 LIST_INIT(&flow->dev_flows);
4188 if (rss && rss->types) {
4189 unsigned int graph_root;
4191 graph_root = find_graph_root(items, rss->level);
4192 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
4194 mlx5_support_expansion,
4197 (unsigned int)ret < sizeof(expand_buffer.buffer));
4200 buf->entry[0].pattern = (void *)(uintptr_t)items;
4202 for (i = 0; i < buf->entries; ++i) {
4204 * The splitter may create multiple dev_flows,
4205 * depending on configuration. In the simplest
4206 * case it just creates unmodified original flow.
4208 ret = flow_create_split_outer(dev, flow, attr,
4209 buf->entry[i].pattern,
4210 p_actions_rx, external,
4215 /* Create the tx flow. */
4217 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
4218 attr_tx.ingress = 0;
4220 dev_flow = flow_drv_prepare(flow, &attr_tx, items_tx.items,
4221 actions_hairpin_tx.actions, error);
4224 dev_flow->flow = flow;
4225 dev_flow->external = 0;
4226 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
4227 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
4229 actions_hairpin_tx.actions, error);
4234 * Update the metadata register copy table. If extensive
4235 * metadata feature is enabled and registers are supported
4236 * we might create the extra rte_flow for each unique
4237 * MARK/FLAG action ID.
4239 * The table is updated for ingress Flows only, because
4240 * the egress Flows belong to the different device and
4241 * copy table should be updated in peer NIC Rx domain.
4243 if (attr->ingress &&
4244 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
4245 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
4249 if (dev->data->dev_started) {
4250 ret = flow_drv_apply(dev, flow, error);
4255 TAILQ_INSERT_TAIL(list, flow, next);
4256 flow_rxq_flags_set(dev, flow);
4260 mlx5_flow_id_release(priv->sh->flow_id_pool,
4265 flow_mreg_del_copy_action(dev, flow);
4266 ret = rte_errno; /* Save rte_errno before cleanup. */
4267 if (flow->hairpin_flow_id)
4268 mlx5_flow_id_release(priv->sh->flow_id_pool,
4269 flow->hairpin_flow_id);
4271 flow_drv_destroy(dev, flow);
4273 rte_errno = ret; /* Restore rte_errno. */
4278 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
4279 * incoming packets to table 1.
4281 * Other flow rules, requested for group n, will be created in
4282 * e-switch table n+1.
4283 * Jump action to e-switch group n will be created to group n+1.
4285 * Used when working in switchdev mode, to utilise advantages of table 1
4289 * Pointer to Ethernet device.
4292 * Pointer to flow on success, NULL otherwise and rte_errno is set.
4295 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
4297 const struct rte_flow_attr attr = {
4304 const struct rte_flow_item pattern = {
4305 .type = RTE_FLOW_ITEM_TYPE_END,
4307 struct rte_flow_action_jump jump = {
4310 const struct rte_flow_action actions[] = {
4312 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4316 .type = RTE_FLOW_ACTION_TYPE_END,
4319 struct mlx5_priv *priv = dev->data->dev_private;
4320 struct rte_flow_error error;
4322 return flow_list_create(dev, &priv->ctrl_flows, &attr, &pattern,
4323 actions, false, &error);
4329 * @see rte_flow_create()
4333 mlx5_flow_create(struct rte_eth_dev *dev,
4334 const struct rte_flow_attr *attr,
4335 const struct rte_flow_item items[],
4336 const struct rte_flow_action actions[],
4337 struct rte_flow_error *error)
4339 struct mlx5_priv *priv = dev->data->dev_private;
4341 return flow_list_create(dev, &priv->flows,
4342 attr, items, actions, true, error);
4346 * Destroy a flow in a list.
4349 * Pointer to Ethernet device.
4351 * Pointer to a TAILQ flow list. If this parameter NULL,
4352 * there is no flow removal from the list.
4357 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
4358 struct rte_flow *flow)
4360 struct mlx5_priv *priv = dev->data->dev_private;
4363 * Update RX queue flags only if port is started, otherwise it is
4366 if (dev->data->dev_started)
4367 flow_rxq_flags_trim(dev, flow);
4368 if (flow->hairpin_flow_id)
4369 mlx5_flow_id_release(priv->sh->flow_id_pool,
4370 flow->hairpin_flow_id);
4371 flow_drv_destroy(dev, flow);
4373 TAILQ_REMOVE(list, flow, next);
4374 flow_mreg_del_copy_action(dev, flow);
4375 rte_free(flow->fdir);
4380 * Destroy all flows.
4383 * Pointer to Ethernet device.
4385 * Pointer to a TAILQ flow list.
4388 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
4390 while (!TAILQ_EMPTY(list)) {
4391 struct rte_flow *flow;
4393 flow = TAILQ_FIRST(list);
4394 flow_list_destroy(dev, list, flow);
4402 * Pointer to Ethernet device.
4404 * Pointer to a TAILQ flow list.
4407 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
4409 struct rte_flow *flow;
4411 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next) {
4412 flow_drv_remove(dev, flow);
4413 flow_mreg_stop_copy_action(dev, flow);
4415 flow_mreg_del_default_copy_action(dev);
4416 flow_rxq_flags_clear(dev);
4423 * Pointer to Ethernet device.
4425 * Pointer to a TAILQ flow list.
4428 * 0 on success, a negative errno value otherwise and rte_errno is set.
4431 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
4433 struct rte_flow *flow;
4434 struct rte_flow_error error;
4437 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4438 ret = flow_mreg_add_default_copy_action(dev, &error);
4441 /* Apply Flows created by application. */
4442 TAILQ_FOREACH(flow, list, next) {
4443 ret = flow_mreg_start_copy_action(dev, flow);
4446 ret = flow_drv_apply(dev, flow, &error);
4449 flow_rxq_flags_set(dev, flow);
4453 ret = rte_errno; /* Save rte_errno before cleanup. */
4454 mlx5_flow_stop(dev, list);
4455 rte_errno = ret; /* Restore rte_errno. */
4460 * Verify the flow list is empty
4463 * Pointer to Ethernet device.
4465 * @return the number of flows not released.
4468 mlx5_flow_verify(struct rte_eth_dev *dev)
4470 struct mlx5_priv *priv = dev->data->dev_private;
4471 struct rte_flow *flow;
4474 TAILQ_FOREACH(flow, &priv->flows, next) {
4475 DRV_LOG(DEBUG, "port %u flow %p still referenced",
4476 dev->data->port_id, (void *)flow);
4483 * Enable default hairpin egress flow.
4486 * Pointer to Ethernet device.
4491 * 0 on success, a negative errno value otherwise and rte_errno is set.
4494 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
4497 struct mlx5_priv *priv = dev->data->dev_private;
4498 const struct rte_flow_attr attr = {
4502 struct mlx5_rte_flow_item_tx_queue queue_spec = {
4505 struct mlx5_rte_flow_item_tx_queue queue_mask = {
4506 .queue = UINT32_MAX,
4508 struct rte_flow_item items[] = {
4510 .type = MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
4511 .spec = &queue_spec,
4513 .mask = &queue_mask,
4516 .type = RTE_FLOW_ITEM_TYPE_END,
4519 struct rte_flow_action_jump jump = {
4520 .group = MLX5_HAIRPIN_TX_TABLE,
4522 struct rte_flow_action actions[2];
4523 struct rte_flow *flow;
4524 struct rte_flow_error error;
4526 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
4527 actions[0].conf = &jump;
4528 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
4529 flow = flow_list_create(dev, &priv->ctrl_flows,
4530 &attr, items, actions, false, &error);
4533 "Failed to create ctrl flow: rte_errno(%d),"
4534 " type(%d), message(%s)",
4535 rte_errno, error.type,
4536 error.message ? error.message : " (no stated reason)");
4543 * Enable a control flow configured from the control plane.
4546 * Pointer to Ethernet device.
4548 * An Ethernet flow spec to apply.
4550 * An Ethernet flow mask to apply.
4552 * A VLAN flow spec to apply.
4554 * A VLAN flow mask to apply.
4557 * 0 on success, a negative errno value otherwise and rte_errno is set.
4560 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
4561 struct rte_flow_item_eth *eth_spec,
4562 struct rte_flow_item_eth *eth_mask,
4563 struct rte_flow_item_vlan *vlan_spec,
4564 struct rte_flow_item_vlan *vlan_mask)
4566 struct mlx5_priv *priv = dev->data->dev_private;
4567 const struct rte_flow_attr attr = {
4569 .priority = MLX5_FLOW_PRIO_RSVD,
4571 struct rte_flow_item items[] = {
4573 .type = RTE_FLOW_ITEM_TYPE_ETH,
4579 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
4580 RTE_FLOW_ITEM_TYPE_END,
4586 .type = RTE_FLOW_ITEM_TYPE_END,
4589 uint16_t queue[priv->reta_idx_n];
4590 struct rte_flow_action_rss action_rss = {
4591 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4593 .types = priv->rss_conf.rss_hf,
4594 .key_len = priv->rss_conf.rss_key_len,
4595 .queue_num = priv->reta_idx_n,
4596 .key = priv->rss_conf.rss_key,
4599 struct rte_flow_action actions[] = {
4601 .type = RTE_FLOW_ACTION_TYPE_RSS,
4602 .conf = &action_rss,
4605 .type = RTE_FLOW_ACTION_TYPE_END,
4608 struct rte_flow *flow;
4609 struct rte_flow_error error;
4612 if (!priv->reta_idx_n || !priv->rxqs_n) {
4615 for (i = 0; i != priv->reta_idx_n; ++i)
4616 queue[i] = (*priv->reta_idx)[i];
4617 flow = flow_list_create(dev, &priv->ctrl_flows,
4618 &attr, items, actions, false, &error);
4625 * Enable a flow control configured from the control plane.
4628 * Pointer to Ethernet device.
4630 * An Ethernet flow spec to apply.
4632 * An Ethernet flow mask to apply.
4635 * 0 on success, a negative errno value otherwise and rte_errno is set.
4638 mlx5_ctrl_flow(struct rte_eth_dev *dev,
4639 struct rte_flow_item_eth *eth_spec,
4640 struct rte_flow_item_eth *eth_mask)
4642 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
4648 * @see rte_flow_destroy()
4652 mlx5_flow_destroy(struct rte_eth_dev *dev,
4653 struct rte_flow *flow,
4654 struct rte_flow_error *error __rte_unused)
4656 struct mlx5_priv *priv = dev->data->dev_private;
4658 flow_list_destroy(dev, &priv->flows, flow);
4663 * Destroy all flows.
4665 * @see rte_flow_flush()
4669 mlx5_flow_flush(struct rte_eth_dev *dev,
4670 struct rte_flow_error *error __rte_unused)
4672 struct mlx5_priv *priv = dev->data->dev_private;
4674 mlx5_flow_list_flush(dev, &priv->flows);
4681 * @see rte_flow_isolate()
4685 mlx5_flow_isolate(struct rte_eth_dev *dev,
4687 struct rte_flow_error *error)
4689 struct mlx5_priv *priv = dev->data->dev_private;
4691 if (dev->data->dev_started) {
4692 rte_flow_error_set(error, EBUSY,
4693 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4695 "port must be stopped first");
4698 priv->isolated = !!enable;
4700 dev->dev_ops = &mlx5_dev_ops_isolate;
4702 dev->dev_ops = &mlx5_dev_ops;
4709 * @see rte_flow_query()
4713 flow_drv_query(struct rte_eth_dev *dev,
4714 struct rte_flow *flow,
4715 const struct rte_flow_action *actions,
4717 struct rte_flow_error *error)
4719 const struct mlx5_flow_driver_ops *fops;
4720 enum mlx5_flow_drv_type ftype = flow->drv_type;
4722 assert(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
4723 fops = flow_get_drv_ops(ftype);
4725 return fops->query(dev, flow, actions, data, error);
4731 * @see rte_flow_query()
4735 mlx5_flow_query(struct rte_eth_dev *dev,
4736 struct rte_flow *flow,
4737 const struct rte_flow_action *actions,
4739 struct rte_flow_error *error)
4743 ret = flow_drv_query(dev, flow, actions, data, error);
4750 * Convert a flow director filter to a generic flow.
4753 * Pointer to Ethernet device.
4754 * @param fdir_filter
4755 * Flow director filter to add.
4757 * Generic flow parameters structure.
4760 * 0 on success, a negative errno value otherwise and rte_errno is set.
4763 flow_fdir_filter_convert(struct rte_eth_dev *dev,
4764 const struct rte_eth_fdir_filter *fdir_filter,
4765 struct mlx5_fdir *attributes)
4767 struct mlx5_priv *priv = dev->data->dev_private;
4768 const struct rte_eth_fdir_input *input = &fdir_filter->input;
4769 const struct rte_eth_fdir_masks *mask =
4770 &dev->data->dev_conf.fdir_conf.mask;
4772 /* Validate queue number. */
4773 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
4774 DRV_LOG(ERR, "port %u invalid queue number %d",
4775 dev->data->port_id, fdir_filter->action.rx_queue);
4779 attributes->attr.ingress = 1;
4780 attributes->items[0] = (struct rte_flow_item) {
4781 .type = RTE_FLOW_ITEM_TYPE_ETH,
4782 .spec = &attributes->l2,
4783 .mask = &attributes->l2_mask,
4785 switch (fdir_filter->action.behavior) {
4786 case RTE_ETH_FDIR_ACCEPT:
4787 attributes->actions[0] = (struct rte_flow_action){
4788 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
4789 .conf = &attributes->queue,
4792 case RTE_ETH_FDIR_REJECT:
4793 attributes->actions[0] = (struct rte_flow_action){
4794 .type = RTE_FLOW_ACTION_TYPE_DROP,
4798 DRV_LOG(ERR, "port %u invalid behavior %d",
4800 fdir_filter->action.behavior);
4801 rte_errno = ENOTSUP;
4804 attributes->queue.index = fdir_filter->action.rx_queue;
4806 switch (fdir_filter->input.flow_type) {
4807 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4808 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4809 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
4810 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
4811 .src_addr = input->flow.ip4_flow.src_ip,
4812 .dst_addr = input->flow.ip4_flow.dst_ip,
4813 .time_to_live = input->flow.ip4_flow.ttl,
4814 .type_of_service = input->flow.ip4_flow.tos,
4816 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
4817 .src_addr = mask->ipv4_mask.src_ip,
4818 .dst_addr = mask->ipv4_mask.dst_ip,
4819 .time_to_live = mask->ipv4_mask.ttl,
4820 .type_of_service = mask->ipv4_mask.tos,
4821 .next_proto_id = mask->ipv4_mask.proto,
4823 attributes->items[1] = (struct rte_flow_item){
4824 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4825 .spec = &attributes->l3,
4826 .mask = &attributes->l3_mask,
4829 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
4830 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
4831 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
4832 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
4833 .hop_limits = input->flow.ipv6_flow.hop_limits,
4834 .proto = input->flow.ipv6_flow.proto,
4837 memcpy(attributes->l3.ipv6.hdr.src_addr,
4838 input->flow.ipv6_flow.src_ip,
4839 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4840 memcpy(attributes->l3.ipv6.hdr.dst_addr,
4841 input->flow.ipv6_flow.dst_ip,
4842 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4843 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
4844 mask->ipv6_mask.src_ip,
4845 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4846 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
4847 mask->ipv6_mask.dst_ip,
4848 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4849 attributes->items[1] = (struct rte_flow_item){
4850 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4851 .spec = &attributes->l3,
4852 .mask = &attributes->l3_mask,
4856 DRV_LOG(ERR, "port %u invalid flow type%d",
4857 dev->data->port_id, fdir_filter->input.flow_type);
4858 rte_errno = ENOTSUP;
4862 switch (fdir_filter->input.flow_type) {
4863 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4864 attributes->l4.udp.hdr = (struct rte_udp_hdr){
4865 .src_port = input->flow.udp4_flow.src_port,
4866 .dst_port = input->flow.udp4_flow.dst_port,
4868 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
4869 .src_port = mask->src_port_mask,
4870 .dst_port = mask->dst_port_mask,
4872 attributes->items[2] = (struct rte_flow_item){
4873 .type = RTE_FLOW_ITEM_TYPE_UDP,
4874 .spec = &attributes->l4,
4875 .mask = &attributes->l4_mask,
4878 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4879 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
4880 .src_port = input->flow.tcp4_flow.src_port,
4881 .dst_port = input->flow.tcp4_flow.dst_port,
4883 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
4884 .src_port = mask->src_port_mask,
4885 .dst_port = mask->dst_port_mask,
4887 attributes->items[2] = (struct rte_flow_item){
4888 .type = RTE_FLOW_ITEM_TYPE_TCP,
4889 .spec = &attributes->l4,
4890 .mask = &attributes->l4_mask,
4893 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
4894 attributes->l4.udp.hdr = (struct rte_udp_hdr){
4895 .src_port = input->flow.udp6_flow.src_port,
4896 .dst_port = input->flow.udp6_flow.dst_port,
4898 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
4899 .src_port = mask->src_port_mask,
4900 .dst_port = mask->dst_port_mask,
4902 attributes->items[2] = (struct rte_flow_item){
4903 .type = RTE_FLOW_ITEM_TYPE_UDP,
4904 .spec = &attributes->l4,
4905 .mask = &attributes->l4_mask,
4908 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
4909 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
4910 .src_port = input->flow.tcp6_flow.src_port,
4911 .dst_port = input->flow.tcp6_flow.dst_port,
4913 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
4914 .src_port = mask->src_port_mask,
4915 .dst_port = mask->dst_port_mask,
4917 attributes->items[2] = (struct rte_flow_item){
4918 .type = RTE_FLOW_ITEM_TYPE_TCP,
4919 .spec = &attributes->l4,
4920 .mask = &attributes->l4_mask,
4923 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
4924 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
4927 DRV_LOG(ERR, "port %u invalid flow type%d",
4928 dev->data->port_id, fdir_filter->input.flow_type);
4929 rte_errno = ENOTSUP;
4935 #define FLOW_FDIR_CMP(f1, f2, fld) \
4936 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
4939 * Compare two FDIR flows. If items and actions are identical, the two flows are
4943 * Pointer to Ethernet device.
4945 * FDIR flow to compare.
4947 * FDIR flow to compare.
4950 * Zero on match, 1 otherwise.
4953 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
4955 if (FLOW_FDIR_CMP(f1, f2, attr) ||
4956 FLOW_FDIR_CMP(f1, f2, l2) ||
4957 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
4958 FLOW_FDIR_CMP(f1, f2, l3) ||
4959 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
4960 FLOW_FDIR_CMP(f1, f2, l4) ||
4961 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
4962 FLOW_FDIR_CMP(f1, f2, actions[0].type))
4964 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
4965 FLOW_FDIR_CMP(f1, f2, queue))
4971 * Search device flow list to find out a matched FDIR flow.
4974 * Pointer to Ethernet device.
4976 * FDIR flow to lookup.
4979 * Pointer of flow if found, NULL otherwise.
4981 static struct rte_flow *
4982 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
4984 struct mlx5_priv *priv = dev->data->dev_private;
4985 struct rte_flow *flow = NULL;
4988 TAILQ_FOREACH(flow, &priv->flows, next) {
4989 if (flow->fdir && !flow_fdir_cmp(flow->fdir, fdir_flow)) {
4990 DRV_LOG(DEBUG, "port %u found FDIR flow %p",
4991 dev->data->port_id, (void *)flow);
4999 * Add new flow director filter and store it in list.
5002 * Pointer to Ethernet device.
5003 * @param fdir_filter
5004 * Flow director filter to add.
5007 * 0 on success, a negative errno value otherwise and rte_errno is set.
5010 flow_fdir_filter_add(struct rte_eth_dev *dev,
5011 const struct rte_eth_fdir_filter *fdir_filter)
5013 struct mlx5_priv *priv = dev->data->dev_private;
5014 struct mlx5_fdir *fdir_flow;
5015 struct rte_flow *flow;
5018 fdir_flow = rte_zmalloc(__func__, sizeof(*fdir_flow), 0);
5023 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
5026 flow = flow_fdir_filter_lookup(dev, fdir_flow);
5031 flow = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
5032 fdir_flow->items, fdir_flow->actions, true,
5036 assert(!flow->fdir);
5037 flow->fdir = fdir_flow;
5038 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
5039 dev->data->port_id, (void *)flow);
5042 rte_free(fdir_flow);
5047 * Delete specific filter.
5050 * Pointer to Ethernet device.
5051 * @param fdir_filter
5052 * Filter to be deleted.
5055 * 0 on success, a negative errno value otherwise and rte_errno is set.
5058 flow_fdir_filter_delete(struct rte_eth_dev *dev,
5059 const struct rte_eth_fdir_filter *fdir_filter)
5061 struct mlx5_priv *priv = dev->data->dev_private;
5062 struct rte_flow *flow;
5063 struct mlx5_fdir fdir_flow = {
5068 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
5071 flow = flow_fdir_filter_lookup(dev, &fdir_flow);
5076 flow_list_destroy(dev, &priv->flows, flow);
5077 DRV_LOG(DEBUG, "port %u deleted FDIR flow %p",
5078 dev->data->port_id, (void *)flow);
5083 * Update queue for specific filter.
5086 * Pointer to Ethernet device.
5087 * @param fdir_filter
5088 * Filter to be updated.
5091 * 0 on success, a negative errno value otherwise and rte_errno is set.
5094 flow_fdir_filter_update(struct rte_eth_dev *dev,
5095 const struct rte_eth_fdir_filter *fdir_filter)
5099 ret = flow_fdir_filter_delete(dev, fdir_filter);
5102 return flow_fdir_filter_add(dev, fdir_filter);
5106 * Flush all filters.
5109 * Pointer to Ethernet device.
5112 flow_fdir_filter_flush(struct rte_eth_dev *dev)
5114 struct mlx5_priv *priv = dev->data->dev_private;
5116 mlx5_flow_list_flush(dev, &priv->flows);
5120 * Get flow director information.
5123 * Pointer to Ethernet device.
5124 * @param[out] fdir_info
5125 * Resulting flow director information.
5128 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
5130 struct rte_eth_fdir_masks *mask =
5131 &dev->data->dev_conf.fdir_conf.mask;
5133 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
5134 fdir_info->guarant_spc = 0;
5135 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
5136 fdir_info->max_flexpayload = 0;
5137 fdir_info->flow_types_mask[0] = 0;
5138 fdir_info->flex_payload_unit = 0;
5139 fdir_info->max_flex_payload_segment_num = 0;
5140 fdir_info->flex_payload_limit = 0;
5141 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
5145 * Deal with flow director operations.
5148 * Pointer to Ethernet device.
5150 * Operation to perform.
5152 * Pointer to operation-specific structure.
5155 * 0 on success, a negative errno value otherwise and rte_errno is set.
5158 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
5161 enum rte_fdir_mode fdir_mode =
5162 dev->data->dev_conf.fdir_conf.mode;
5164 if (filter_op == RTE_ETH_FILTER_NOP)
5166 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
5167 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5168 DRV_LOG(ERR, "port %u flow director mode %d not supported",
5169 dev->data->port_id, fdir_mode);
5173 switch (filter_op) {
5174 case RTE_ETH_FILTER_ADD:
5175 return flow_fdir_filter_add(dev, arg);
5176 case RTE_ETH_FILTER_UPDATE:
5177 return flow_fdir_filter_update(dev, arg);
5178 case RTE_ETH_FILTER_DELETE:
5179 return flow_fdir_filter_delete(dev, arg);
5180 case RTE_ETH_FILTER_FLUSH:
5181 flow_fdir_filter_flush(dev);
5183 case RTE_ETH_FILTER_INFO:
5184 flow_fdir_info_get(dev, arg);
5187 DRV_LOG(DEBUG, "port %u unknown operation %u",
5188 dev->data->port_id, filter_op);
5196 * Manage filter operations.
5199 * Pointer to Ethernet device structure.
5200 * @param filter_type
5203 * Operation to perform.
5205 * Pointer to operation-specific structure.
5208 * 0 on success, a negative errno value otherwise and rte_errno is set.
5211 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
5212 enum rte_filter_type filter_type,
5213 enum rte_filter_op filter_op,
5216 switch (filter_type) {
5217 case RTE_ETH_FILTER_GENERIC:
5218 if (filter_op != RTE_ETH_FILTER_GET) {
5222 *(const void **)arg = &mlx5_flow_ops;
5224 case RTE_ETH_FILTER_FDIR:
5225 return flow_fdir_ctrl_func(dev, filter_op, arg);
5227 DRV_LOG(ERR, "port %u filter type (%d) not supported",
5228 dev->data->port_id, filter_type);
5229 rte_errno = ENOTSUP;
5236 * Create the needed meter and suffix tables.
5239 * Pointer to Ethernet device.
5241 * Pointer to the flow meter.
5244 * Pointer to table set on success, NULL otherwise.
5246 struct mlx5_meter_domains_infos *
5247 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
5248 const struct mlx5_flow_meter *fm)
5250 const struct mlx5_flow_driver_ops *fops;
5252 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5253 return fops->create_mtr_tbls(dev, fm);
5257 * Destroy the meter table set.
5260 * Pointer to Ethernet device.
5262 * Pointer to the meter table set.
5268 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
5269 struct mlx5_meter_domains_infos *tbls)
5271 const struct mlx5_flow_driver_ops *fops;
5273 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5274 return fops->destroy_mtr_tbls(dev, tbls);
5278 * Create policer rules.
5281 * Pointer to Ethernet device.
5283 * Pointer to flow meter structure.
5285 * Pointer to flow attributes.
5288 * 0 on success, -1 otherwise.
5291 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
5292 struct mlx5_flow_meter *fm,
5293 const struct rte_flow_attr *attr)
5295 const struct mlx5_flow_driver_ops *fops;
5297 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5298 return fops->create_policer_rules(dev, fm, attr);
5302 * Destroy policer rules.
5305 * Pointer to flow meter structure.
5307 * Pointer to flow attributes.
5310 * 0 on success, -1 otherwise.
5313 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
5314 struct mlx5_flow_meter *fm,
5315 const struct rte_flow_attr *attr)
5317 const struct mlx5_flow_driver_ops *fops;
5319 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5320 return fops->destroy_policer_rules(dev, fm, attr);
5324 * Allocate a counter.
5327 * Pointer to Ethernet device structure.
5330 * Pointer to allocated counter on success, NULL otherwise.
5332 struct mlx5_flow_counter *
5333 mlx5_counter_alloc(struct rte_eth_dev *dev)
5335 const struct mlx5_flow_driver_ops *fops;
5336 struct rte_flow_attr attr = { .transfer = 0 };
5338 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5339 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5340 return fops->counter_alloc(dev);
5343 "port %u counter allocate is not supported.",
5344 dev->data->port_id);
5352 * Pointer to Ethernet device structure.
5354 * Pointer to counter to be free.
5357 mlx5_counter_free(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt)
5359 const struct mlx5_flow_driver_ops *fops;
5360 struct rte_flow_attr attr = { .transfer = 0 };
5362 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5363 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5364 fops->counter_free(dev, cnt);
5368 "port %u counter free is not supported.",
5369 dev->data->port_id);
5373 * Query counter statistics.
5376 * Pointer to Ethernet device structure.
5378 * Pointer to counter to query.
5380 * Set to clear counter statistics.
5382 * The counter hits packets number to save.
5384 * The counter hits bytes number to save.
5387 * 0 on success, a negative errno value otherwise.
5390 mlx5_counter_query(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt,
5391 bool clear, uint64_t *pkts, uint64_t *bytes)
5393 const struct mlx5_flow_driver_ops *fops;
5394 struct rte_flow_attr attr = { .transfer = 0 };
5396 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5397 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5398 return fops->counter_query(dev, cnt, clear, pkts, bytes);
5401 "port %u counter query is not supported.",
5402 dev->data->port_id);
5406 #define MLX5_POOL_QUERY_FREQ_US 1000000
5409 * Set the periodic procedure for triggering asynchronous batch queries for all
5410 * the counter pools.
5413 * Pointer to mlx5_ibv_shared object.
5416 mlx5_set_query_alarm(struct mlx5_ibv_shared *sh)
5418 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(sh, 0, 0);
5419 uint32_t pools_n = rte_atomic16_read(&cont->n_valid);
5422 cont = MLX5_CNT_CONTAINER(sh, 1, 0);
5423 pools_n += rte_atomic16_read(&cont->n_valid);
5424 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
5425 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
5426 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
5427 sh->cmng.query_thread_on = 0;
5428 DRV_LOG(ERR, "Cannot reinitialize query alarm");
5430 sh->cmng.query_thread_on = 1;
5435 * The periodic procedure for triggering asynchronous batch queries for all the
5436 * counter pools. This function is probably called by the host thread.
5439 * The parameter for the alarm process.
5442 mlx5_flow_query_alarm(void *arg)
5444 struct mlx5_ibv_shared *sh = arg;
5445 struct mlx5_devx_obj *dcs;
5448 uint8_t batch = sh->cmng.batch;
5449 uint16_t pool_index = sh->cmng.pool_index;
5450 struct mlx5_pools_container *cont;
5451 struct mlx5_pools_container *mcont;
5452 struct mlx5_flow_counter_pool *pool;
5454 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
5457 cont = MLX5_CNT_CONTAINER(sh, batch, 1);
5458 mcont = MLX5_CNT_CONTAINER(sh, batch, 0);
5459 /* Check if resize was done and need to flip a container. */
5460 if (cont != mcont) {
5462 /* Clean the old container. */
5463 rte_free(cont->pools);
5464 memset(cont, 0, sizeof(*cont));
5467 /* Flip the host container. */
5468 sh->cmng.mhi[batch] ^= (uint8_t)2;
5472 /* 2 empty containers case is unexpected. */
5473 if (unlikely(batch != sh->cmng.batch))
5477 goto next_container;
5479 pool = cont->pools[pool_index];
5481 /* There is a pool query in progress. */
5484 LIST_FIRST(&sh->cmng.free_stat_raws);
5486 /* No free counter statistics raw memory. */
5488 dcs = (struct mlx5_devx_obj *)(uintptr_t)rte_atomic64_read
5490 offset = batch ? 0 : dcs->id % MLX5_COUNTERS_PER_POOL;
5491 ret = mlx5_devx_cmd_flow_counter_query(dcs, 0, MLX5_COUNTERS_PER_POOL -
5493 pool->raw_hw->mem_mng->dm->id,
5495 (pool->raw_hw->data + offset),
5497 (uint64_t)(uintptr_t)pool);
5499 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
5500 " %d", pool->min_dcs->id);
5501 pool->raw_hw = NULL;
5504 pool->raw_hw->min_dcs_id = dcs->id;
5505 LIST_REMOVE(pool->raw_hw, next);
5506 sh->cmng.pending_queries++;
5508 if (pool_index >= rte_atomic16_read(&cont->n_valid)) {
5513 sh->cmng.batch = batch;
5514 sh->cmng.pool_index = pool_index;
5515 mlx5_set_query_alarm(sh);
5519 * Handler for the HW respond about ready values from an asynchronous batch
5520 * query. This function is probably called by the host thread.
5523 * The pointer to the shared IB device context.
5524 * @param[in] async_id
5525 * The Devx async ID.
5527 * The status of the completion.
5530 mlx5_flow_async_pool_query_handle(struct mlx5_ibv_shared *sh,
5531 uint64_t async_id, int status)
5533 struct mlx5_flow_counter_pool *pool =
5534 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
5535 struct mlx5_counter_stats_raw *raw_to_free;
5537 if (unlikely(status)) {
5538 raw_to_free = pool->raw_hw;
5540 raw_to_free = pool->raw;
5541 rte_spinlock_lock(&pool->sl);
5542 pool->raw = pool->raw_hw;
5543 rte_spinlock_unlock(&pool->sl);
5544 rte_atomic64_add(&pool->query_gen, 1);
5545 /* Be sure the new raw counters data is updated in memory. */
5548 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
5549 pool->raw_hw = NULL;
5550 sh->cmng.pending_queries--;
5554 * Translate the rte_flow group index to HW table value.
5556 * @param[in] attributes
5557 * Pointer to flow attributes
5558 * @param[in] external
5559 * Value is part of flow rule created by request external to PMD.
5561 * rte_flow group index value.
5565 * Pointer to error structure.
5568 * 0 on success, a negative errno value otherwise and rte_errno is set.
5571 mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, bool external,
5572 uint32_t group, uint32_t *table,
5573 struct rte_flow_error *error)
5575 if (attributes->transfer && external) {
5576 if (group == UINT32_MAX)
5577 return rte_flow_error_set
5579 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5581 "group index not supported");
5590 * Discover availability of metadata reg_c's.
5592 * Iteratively use test flows to check availability.
5595 * Pointer to the Ethernet device structure.
5598 * 0 on success, a negative errno value otherwise and rte_errno is set.
5601 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
5603 struct mlx5_priv *priv = dev->data->dev_private;
5604 struct mlx5_dev_config *config = &priv->config;
5605 enum modify_reg idx;
5608 /* reg_c[0] and reg_c[1] are reserved. */
5609 config->flow_mreg_c[n++] = REG_C_0;
5610 config->flow_mreg_c[n++] = REG_C_1;
5611 /* Discover availability of other reg_c's. */
5612 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
5613 struct rte_flow_attr attr = {
5614 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5615 .priority = MLX5_FLOW_PRIO_RSVD,
5618 struct rte_flow_item items[] = {
5620 .type = RTE_FLOW_ITEM_TYPE_END,
5623 struct rte_flow_action actions[] = {
5625 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5626 .conf = &(struct mlx5_flow_action_copy_mreg){
5632 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5633 .conf = &(struct rte_flow_action_jump){
5634 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5638 .type = RTE_FLOW_ACTION_TYPE_END,
5641 struct rte_flow *flow;
5642 struct rte_flow_error error;
5644 if (!config->dv_flow_en)
5646 /* Create internal flow, validation skips copy action. */
5647 flow = flow_list_create(dev, NULL, &attr, items,
5648 actions, false, &error);
5651 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
5652 config->flow_mreg_c[n++] = idx;
5653 flow_list_destroy(dev, NULL, flow);
5655 for (; n < MLX5_MREG_C_NUM; ++n)
5656 config->flow_mreg_c[n] = REG_NONE;