1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
6 #include <netinet/in.h>
14 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
16 #pragma GCC diagnostic ignored "-Wpedantic"
18 #include <infiniband/verbs.h>
20 #pragma GCC diagnostic error "-Wpedantic"
23 #include <rte_common.h>
24 #include <rte_ether.h>
25 #include <rte_ethdev_driver.h>
27 #include <rte_flow_driver.h>
28 #include <rte_malloc.h>
31 #include <mlx5_glue.h>
32 #include <mlx5_devx_cmds.h>
35 #include "mlx5_defs.h"
37 #include "mlx5_flow.h"
38 #include "mlx5_rxtx.h"
40 /* Dev ops structure defined in mlx5.c */
41 extern const struct eth_dev_ops mlx5_dev_ops;
42 extern const struct eth_dev_ops mlx5_dev_ops_isolate;
44 /** Device flow drivers. */
45 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
46 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
48 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
50 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
52 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
53 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
54 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
55 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
57 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
58 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
63 MLX5_EXPANSION_ROOT_OUTER,
64 MLX5_EXPANSION_ROOT_ETH_VLAN,
65 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
66 MLX5_EXPANSION_OUTER_ETH,
67 MLX5_EXPANSION_OUTER_ETH_VLAN,
68 MLX5_EXPANSION_OUTER_VLAN,
69 MLX5_EXPANSION_OUTER_IPV4,
70 MLX5_EXPANSION_OUTER_IPV4_UDP,
71 MLX5_EXPANSION_OUTER_IPV4_TCP,
72 MLX5_EXPANSION_OUTER_IPV6,
73 MLX5_EXPANSION_OUTER_IPV6_UDP,
74 MLX5_EXPANSION_OUTER_IPV6_TCP,
76 MLX5_EXPANSION_VXLAN_GPE,
80 MLX5_EXPANSION_ETH_VLAN,
83 MLX5_EXPANSION_IPV4_UDP,
84 MLX5_EXPANSION_IPV4_TCP,
86 MLX5_EXPANSION_IPV6_UDP,
87 MLX5_EXPANSION_IPV6_TCP,
90 /** Supported expansion of items. */
91 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
92 [MLX5_EXPANSION_ROOT] = {
93 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
96 .type = RTE_FLOW_ITEM_TYPE_END,
98 [MLX5_EXPANSION_ROOT_OUTER] = {
99 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
100 MLX5_EXPANSION_OUTER_IPV4,
101 MLX5_EXPANSION_OUTER_IPV6),
102 .type = RTE_FLOW_ITEM_TYPE_END,
104 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
105 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
106 .type = RTE_FLOW_ITEM_TYPE_END,
108 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
109 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
110 .type = RTE_FLOW_ITEM_TYPE_END,
112 [MLX5_EXPANSION_OUTER_ETH] = {
113 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
114 MLX5_EXPANSION_OUTER_IPV6,
115 MLX5_EXPANSION_MPLS),
116 .type = RTE_FLOW_ITEM_TYPE_ETH,
119 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
120 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
121 .type = RTE_FLOW_ITEM_TYPE_ETH,
124 [MLX5_EXPANSION_OUTER_VLAN] = {
125 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
126 MLX5_EXPANSION_OUTER_IPV6),
127 .type = RTE_FLOW_ITEM_TYPE_VLAN,
129 [MLX5_EXPANSION_OUTER_IPV4] = {
130 .next = RTE_FLOW_EXPAND_RSS_NEXT
131 (MLX5_EXPANSION_OUTER_IPV4_UDP,
132 MLX5_EXPANSION_OUTER_IPV4_TCP,
135 MLX5_EXPANSION_IPV6),
136 .type = RTE_FLOW_ITEM_TYPE_IPV4,
137 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
138 ETH_RSS_NONFRAG_IPV4_OTHER,
140 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
141 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
142 MLX5_EXPANSION_VXLAN_GPE),
143 .type = RTE_FLOW_ITEM_TYPE_UDP,
144 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
146 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
147 .type = RTE_FLOW_ITEM_TYPE_TCP,
148 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
150 [MLX5_EXPANSION_OUTER_IPV6] = {
151 .next = RTE_FLOW_EXPAND_RSS_NEXT
152 (MLX5_EXPANSION_OUTER_IPV6_UDP,
153 MLX5_EXPANSION_OUTER_IPV6_TCP,
155 MLX5_EXPANSION_IPV6),
156 .type = RTE_FLOW_ITEM_TYPE_IPV6,
157 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
158 ETH_RSS_NONFRAG_IPV6_OTHER,
160 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
161 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
162 MLX5_EXPANSION_VXLAN_GPE),
163 .type = RTE_FLOW_ITEM_TYPE_UDP,
164 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
166 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
167 .type = RTE_FLOW_ITEM_TYPE_TCP,
168 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
170 [MLX5_EXPANSION_VXLAN] = {
171 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
173 MLX5_EXPANSION_IPV6),
174 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
176 [MLX5_EXPANSION_VXLAN_GPE] = {
177 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
179 MLX5_EXPANSION_IPV6),
180 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
182 [MLX5_EXPANSION_GRE] = {
183 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
184 .type = RTE_FLOW_ITEM_TYPE_GRE,
186 [MLX5_EXPANSION_MPLS] = {
187 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
188 MLX5_EXPANSION_IPV6),
189 .type = RTE_FLOW_ITEM_TYPE_MPLS,
191 [MLX5_EXPANSION_ETH] = {
192 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
193 MLX5_EXPANSION_IPV6),
194 .type = RTE_FLOW_ITEM_TYPE_ETH,
196 [MLX5_EXPANSION_ETH_VLAN] = {
197 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
198 .type = RTE_FLOW_ITEM_TYPE_ETH,
200 [MLX5_EXPANSION_VLAN] = {
201 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
202 MLX5_EXPANSION_IPV6),
203 .type = RTE_FLOW_ITEM_TYPE_VLAN,
205 [MLX5_EXPANSION_IPV4] = {
206 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
207 MLX5_EXPANSION_IPV4_TCP),
208 .type = RTE_FLOW_ITEM_TYPE_IPV4,
209 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
210 ETH_RSS_NONFRAG_IPV4_OTHER,
212 [MLX5_EXPANSION_IPV4_UDP] = {
213 .type = RTE_FLOW_ITEM_TYPE_UDP,
214 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
216 [MLX5_EXPANSION_IPV4_TCP] = {
217 .type = RTE_FLOW_ITEM_TYPE_TCP,
218 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
220 [MLX5_EXPANSION_IPV6] = {
221 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
222 MLX5_EXPANSION_IPV6_TCP),
223 .type = RTE_FLOW_ITEM_TYPE_IPV6,
224 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
225 ETH_RSS_NONFRAG_IPV6_OTHER,
227 [MLX5_EXPANSION_IPV6_UDP] = {
228 .type = RTE_FLOW_ITEM_TYPE_UDP,
229 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
231 [MLX5_EXPANSION_IPV6_TCP] = {
232 .type = RTE_FLOW_ITEM_TYPE_TCP,
233 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
237 static const struct rte_flow_ops mlx5_flow_ops = {
238 .validate = mlx5_flow_validate,
239 .create = mlx5_flow_create,
240 .destroy = mlx5_flow_destroy,
241 .flush = mlx5_flow_flush,
242 .isolate = mlx5_flow_isolate,
243 .query = mlx5_flow_query,
244 .dev_dump = mlx5_flow_dev_dump,
247 /* Convert FDIR request to Generic flow. */
249 struct rte_flow_attr attr;
250 struct rte_flow_item items[4];
251 struct rte_flow_item_eth l2;
252 struct rte_flow_item_eth l2_mask;
254 struct rte_flow_item_ipv4 ipv4;
255 struct rte_flow_item_ipv6 ipv6;
258 struct rte_flow_item_ipv4 ipv4;
259 struct rte_flow_item_ipv6 ipv6;
262 struct rte_flow_item_udp udp;
263 struct rte_flow_item_tcp tcp;
266 struct rte_flow_item_udp udp;
267 struct rte_flow_item_tcp tcp;
269 struct rte_flow_action actions[2];
270 struct rte_flow_action_queue queue;
273 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
274 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
275 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
278 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
279 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
280 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
281 { 9, 10, 11 }, { 12, 13, 14 },
284 /* Tunnel information. */
285 struct mlx5_flow_tunnel_info {
286 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
287 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
290 static struct mlx5_flow_tunnel_info tunnels_info[] = {
292 .tunnel = MLX5_FLOW_LAYER_VXLAN,
293 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
296 .tunnel = MLX5_FLOW_LAYER_GENEVE,
297 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
300 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
301 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
304 .tunnel = MLX5_FLOW_LAYER_GRE,
305 .ptype = RTE_PTYPE_TUNNEL_GRE,
308 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
309 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
312 .tunnel = MLX5_FLOW_LAYER_MPLS,
313 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
316 .tunnel = MLX5_FLOW_LAYER_NVGRE,
317 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
320 .tunnel = MLX5_FLOW_LAYER_IPIP,
321 .ptype = RTE_PTYPE_TUNNEL_IP,
324 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
325 .ptype = RTE_PTYPE_TUNNEL_IP,
328 .tunnel = MLX5_FLOW_LAYER_GTP,
329 .ptype = RTE_PTYPE_TUNNEL_GTPU,
334 * Translate tag ID to register.
337 * Pointer to the Ethernet device structure.
339 * The feature that request the register.
341 * The request register ID.
343 * Error description in case of any.
346 * The request register on success, a negative errno
347 * value otherwise and rte_errno is set.
350 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
351 enum mlx5_feature_name feature,
353 struct rte_flow_error *error)
355 struct mlx5_priv *priv = dev->data->dev_private;
356 struct mlx5_dev_config *config = &priv->config;
357 enum modify_reg start_reg;
358 bool skip_mtr_reg = false;
361 case MLX5_HAIRPIN_RX:
363 case MLX5_HAIRPIN_TX:
365 case MLX5_METADATA_RX:
366 switch (config->dv_xmeta_en) {
367 case MLX5_XMETA_MODE_LEGACY:
369 case MLX5_XMETA_MODE_META16:
371 case MLX5_XMETA_MODE_META32:
375 case MLX5_METADATA_TX:
377 case MLX5_METADATA_FDB:
378 switch (config->dv_xmeta_en) {
379 case MLX5_XMETA_MODE_LEGACY:
381 case MLX5_XMETA_MODE_META16:
383 case MLX5_XMETA_MODE_META32:
388 switch (config->dv_xmeta_en) {
389 case MLX5_XMETA_MODE_LEGACY:
391 case MLX5_XMETA_MODE_META16:
393 case MLX5_XMETA_MODE_META32:
399 * If meter color and flow match share one register, flow match
400 * should use the meter color register for match.
402 if (priv->mtr_reg_share)
403 return priv->mtr_color_reg;
405 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
408 MLX5_ASSERT(priv->mtr_color_reg != REG_NONE);
409 return priv->mtr_color_reg;
412 * Metadata COPY_MARK register using is in meter suffix sub
413 * flow while with meter. It's safe to share the same register.
415 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
418 * If meter is enable, it will engage the register for color
419 * match and flow match. If meter color match is not using the
420 * REG_C_2, need to skip the REG_C_x be used by meter color
422 * If meter is disable, free to use all available registers.
424 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
425 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
426 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
427 if (id > (REG_C_7 - start_reg))
428 return rte_flow_error_set(error, EINVAL,
429 RTE_FLOW_ERROR_TYPE_ITEM,
430 NULL, "invalid tag id");
431 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NONE)
432 return rte_flow_error_set(error, ENOTSUP,
433 RTE_FLOW_ERROR_TYPE_ITEM,
434 NULL, "unsupported tag id");
436 * This case means meter is using the REG_C_x great than 2.
437 * Take care not to conflict with meter color REG_C_x.
438 * If the available index REG_C_y >= REG_C_x, skip the
441 if (skip_mtr_reg && config->flow_mreg_c
442 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
443 if (config->flow_mreg_c
444 [id + 1 + start_reg - REG_C_0] != REG_NONE)
445 return config->flow_mreg_c
446 [id + 1 + start_reg - REG_C_0];
447 return rte_flow_error_set(error, ENOTSUP,
448 RTE_FLOW_ERROR_TYPE_ITEM,
449 NULL, "unsupported tag id");
451 return config->flow_mreg_c[id + start_reg - REG_C_0];
454 return rte_flow_error_set(error, EINVAL,
455 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
456 NULL, "invalid feature name");
460 * Check extensive flow metadata register support.
463 * Pointer to rte_eth_dev structure.
466 * True if device supports extensive flow metadata register, otherwise false.
469 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
471 struct mlx5_priv *priv = dev->data->dev_private;
472 struct mlx5_dev_config *config = &priv->config;
475 * Having available reg_c can be regarded inclusively as supporting
476 * extensive flow metadata register, which could mean,
477 * - metadata register copy action by modify header.
478 * - 16 modify header actions is supported.
479 * - reg_c's are preserved across different domain (FDB and NIC) on
480 * packet loopback by flow lookup miss.
482 return config->flow_mreg_c[2] != REG_NONE;
486 * Discover the maximum number of priority available.
489 * Pointer to the Ethernet device structure.
492 * number of supported flow priority on success, a negative errno
493 * value otherwise and rte_errno is set.
496 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
498 struct mlx5_priv *priv = dev->data->dev_private;
500 struct ibv_flow_attr attr;
501 struct ibv_flow_spec_eth eth;
502 struct ibv_flow_spec_action_drop drop;
506 .port = (uint8_t)priv->ibv_port,
509 .type = IBV_FLOW_SPEC_ETH,
510 .size = sizeof(struct ibv_flow_spec_eth),
513 .size = sizeof(struct ibv_flow_spec_action_drop),
514 .type = IBV_FLOW_SPEC_ACTION_DROP,
517 struct ibv_flow *flow;
518 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
519 uint16_t vprio[] = { 8, 16 };
527 for (i = 0; i != RTE_DIM(vprio); i++) {
528 flow_attr.attr.priority = vprio[i] - 1;
529 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
532 claim_zero(mlx5_glue->destroy_flow(flow));
535 mlx5_hrxq_drop_release(dev);
538 priority = RTE_DIM(priority_map_3);
541 priority = RTE_DIM(priority_map_5);
546 "port %u verbs maximum priority: %d expected 8/16",
547 dev->data->port_id, priority);
550 DRV_LOG(INFO, "port %u flow maximum priority: %d",
551 dev->data->port_id, priority);
556 * Adjust flow priority based on the highest layer and the request priority.
559 * Pointer to the Ethernet device structure.
560 * @param[in] priority
561 * The rule base priority.
562 * @param[in] subpriority
563 * The priority based on the items.
568 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
569 uint32_t subpriority)
572 struct mlx5_priv *priv = dev->data->dev_private;
574 switch (priv->config.flow_prio) {
575 case RTE_DIM(priority_map_3):
576 res = priority_map_3[priority][subpriority];
578 case RTE_DIM(priority_map_5):
579 res = priority_map_5[priority][subpriority];
586 * Verify the @p item specifications (spec, last, mask) are compatible with the
590 * Item specification.
592 * @p item->mask or flow default bit-masks.
593 * @param[in] nic_mask
594 * Bit-masks covering supported fields by the NIC to compare with user mask.
596 * Bit-masks size in bytes.
598 * Pointer to error structure.
601 * 0 on success, a negative errno value otherwise and rte_errno is set.
604 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
606 const uint8_t *nic_mask,
608 struct rte_flow_error *error)
612 MLX5_ASSERT(nic_mask);
613 for (i = 0; i < size; ++i)
614 if ((nic_mask[i] | mask[i]) != nic_mask[i])
615 return rte_flow_error_set(error, ENOTSUP,
616 RTE_FLOW_ERROR_TYPE_ITEM,
618 "mask enables non supported"
620 if (!item->spec && (item->mask || item->last))
621 return rte_flow_error_set(error, EINVAL,
622 RTE_FLOW_ERROR_TYPE_ITEM, item,
623 "mask/last without a spec is not"
625 if (item->spec && item->last) {
631 for (i = 0; i < size; ++i) {
632 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
633 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
635 ret = memcmp(spec, last, size);
637 return rte_flow_error_set(error, EINVAL,
638 RTE_FLOW_ERROR_TYPE_ITEM,
640 "range is not valid");
646 * Adjust the hash fields according to the @p flow information.
648 * @param[in] dev_flow.
649 * Pointer to the mlx5_flow.
651 * 1 when the hash field is for a tunnel item.
652 * @param[in] layer_types
654 * @param[in] hash_fields
658 * The hash fields that should be used.
661 mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow,
662 int tunnel __rte_unused, uint64_t layer_types,
663 uint64_t hash_fields)
665 struct rte_flow *flow = dev_flow->flow;
666 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
667 int rss_request_inner = flow->rss.level >= 2;
669 /* Check RSS hash level for tunnel. */
670 if (tunnel && rss_request_inner)
671 hash_fields |= IBV_RX_HASH_INNER;
672 else if (tunnel || rss_request_inner)
675 /* Check if requested layer matches RSS hash fields. */
676 if (!(flow->rss.types & layer_types))
682 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
683 * if several tunnel rules are used on this queue, the tunnel ptype will be
687 * Rx queue to update.
690 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
693 uint32_t tunnel_ptype = 0;
695 /* Look up for the ptype to use. */
696 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
697 if (!rxq_ctrl->flow_tunnels_n[i])
700 tunnel_ptype = tunnels_info[i].ptype;
706 rxq_ctrl->rxq.tunnel = tunnel_ptype;
710 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
714 * Pointer to the Ethernet device structure.
715 * @param[in] dev_flow
716 * Pointer to device flow structure.
719 flow_drv_rxq_flags_set(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
721 struct mlx5_priv *priv = dev->data->dev_private;
722 struct rte_flow *flow = dev_flow->flow;
723 const int mark = !!(dev_flow->actions &
724 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
725 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
728 for (i = 0; i != flow->rss.queue_num; ++i) {
729 int idx = (*flow->rss.queue)[i];
730 struct mlx5_rxq_ctrl *rxq_ctrl =
731 container_of((*priv->rxqs)[idx],
732 struct mlx5_rxq_ctrl, rxq);
735 * To support metadata register copy on Tx loopback,
736 * this must be always enabled (metadata may arive
737 * from other port - not from local flows only.
739 if (priv->config.dv_flow_en &&
740 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
741 mlx5_flow_ext_mreg_supported(dev)) {
742 rxq_ctrl->rxq.mark = 1;
743 rxq_ctrl->flow_mark_n = 1;
745 rxq_ctrl->rxq.mark = 1;
746 rxq_ctrl->flow_mark_n++;
751 /* Increase the counter matching the flow. */
752 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
753 if ((tunnels_info[j].tunnel &
755 tunnels_info[j].tunnel) {
756 rxq_ctrl->flow_tunnels_n[j]++;
760 flow_rxq_tunnel_ptype_update(rxq_ctrl);
766 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
769 * Pointer to the Ethernet device structure.
771 * Pointer to flow structure.
774 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
776 struct mlx5_flow *dev_flow;
778 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
779 flow_drv_rxq_flags_set(dev, dev_flow);
783 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
784 * device flow if no other flow uses it with the same kind of request.
787 * Pointer to Ethernet device.
788 * @param[in] dev_flow
789 * Pointer to the device flow.
792 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
794 struct mlx5_priv *priv = dev->data->dev_private;
795 struct rte_flow *flow = dev_flow->flow;
796 const int mark = !!(dev_flow->actions &
797 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
798 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
801 MLX5_ASSERT(dev->data->dev_started);
802 for (i = 0; i != flow->rss.queue_num; ++i) {
803 int idx = (*flow->rss.queue)[i];
804 struct mlx5_rxq_ctrl *rxq_ctrl =
805 container_of((*priv->rxqs)[idx],
806 struct mlx5_rxq_ctrl, rxq);
808 if (priv->config.dv_flow_en &&
809 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
810 mlx5_flow_ext_mreg_supported(dev)) {
811 rxq_ctrl->rxq.mark = 1;
812 rxq_ctrl->flow_mark_n = 1;
814 rxq_ctrl->flow_mark_n--;
815 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
820 /* Decrease the counter matching the flow. */
821 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
822 if ((tunnels_info[j].tunnel &
824 tunnels_info[j].tunnel) {
825 rxq_ctrl->flow_tunnels_n[j]--;
829 flow_rxq_tunnel_ptype_update(rxq_ctrl);
835 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
836 * @p flow if no other flow uses it with the same kind of request.
839 * Pointer to Ethernet device.
841 * Pointer to the flow.
844 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
846 struct mlx5_flow *dev_flow;
848 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
849 flow_drv_rxq_flags_trim(dev, dev_flow);
853 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
856 * Pointer to Ethernet device.
859 flow_rxq_flags_clear(struct rte_eth_dev *dev)
861 struct mlx5_priv *priv = dev->data->dev_private;
864 for (i = 0; i != priv->rxqs_n; ++i) {
865 struct mlx5_rxq_ctrl *rxq_ctrl;
868 if (!(*priv->rxqs)[i])
870 rxq_ctrl = container_of((*priv->rxqs)[i],
871 struct mlx5_rxq_ctrl, rxq);
872 rxq_ctrl->flow_mark_n = 0;
873 rxq_ctrl->rxq.mark = 0;
874 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
875 rxq_ctrl->flow_tunnels_n[j] = 0;
876 rxq_ctrl->rxq.tunnel = 0;
881 * return a pointer to the desired action in the list of actions.
884 * The list of actions to search the action in.
886 * The action to find.
889 * Pointer to the action in the list, if found. NULL otherwise.
891 const struct rte_flow_action *
892 mlx5_flow_find_action(const struct rte_flow_action *actions,
893 enum rte_flow_action_type action)
897 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
898 if (actions->type == action)
904 * Validate the flag action.
906 * @param[in] action_flags
907 * Bit-fields that holds the actions detected until now.
909 * Attributes of flow that includes this action.
911 * Pointer to error structure.
914 * 0 on success, a negative errno value otherwise and rte_errno is set.
917 mlx5_flow_validate_action_flag(uint64_t action_flags,
918 const struct rte_flow_attr *attr,
919 struct rte_flow_error *error)
921 if (action_flags & MLX5_FLOW_ACTION_MARK)
922 return rte_flow_error_set(error, EINVAL,
923 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
924 "can't mark and flag in same flow");
925 if (action_flags & MLX5_FLOW_ACTION_FLAG)
926 return rte_flow_error_set(error, EINVAL,
927 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
929 " actions in same flow");
931 return rte_flow_error_set(error, ENOTSUP,
932 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
933 "flag action not supported for "
939 * Validate the mark action.
942 * Pointer to the queue action.
943 * @param[in] action_flags
944 * Bit-fields that holds the actions detected until now.
946 * Attributes of flow that includes this action.
948 * Pointer to error structure.
951 * 0 on success, a negative errno value otherwise and rte_errno is set.
954 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
955 uint64_t action_flags,
956 const struct rte_flow_attr *attr,
957 struct rte_flow_error *error)
959 const struct rte_flow_action_mark *mark = action->conf;
962 return rte_flow_error_set(error, EINVAL,
963 RTE_FLOW_ERROR_TYPE_ACTION,
965 "configuration cannot be null");
966 if (mark->id >= MLX5_FLOW_MARK_MAX)
967 return rte_flow_error_set(error, EINVAL,
968 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
970 "mark id must in 0 <= id < "
971 RTE_STR(MLX5_FLOW_MARK_MAX));
972 if (action_flags & MLX5_FLOW_ACTION_FLAG)
973 return rte_flow_error_set(error, EINVAL,
974 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
975 "can't flag and mark in same flow");
976 if (action_flags & MLX5_FLOW_ACTION_MARK)
977 return rte_flow_error_set(error, EINVAL,
978 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
979 "can't have 2 mark actions in same"
982 return rte_flow_error_set(error, ENOTSUP,
983 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
984 "mark action not supported for "
990 * Validate the drop action.
992 * @param[in] action_flags
993 * Bit-fields that holds the actions detected until now.
995 * Attributes of flow that includes this action.
997 * Pointer to error structure.
1000 * 0 on success, a negative errno value otherwise and rte_errno is set.
1003 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
1004 const struct rte_flow_attr *attr,
1005 struct rte_flow_error *error)
1008 return rte_flow_error_set(error, ENOTSUP,
1009 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1010 "drop action not supported for "
1016 * Validate the queue action.
1019 * Pointer to the queue action.
1020 * @param[in] action_flags
1021 * Bit-fields that holds the actions detected until now.
1023 * Pointer to the Ethernet device structure.
1025 * Attributes of flow that includes this action.
1027 * Pointer to error structure.
1030 * 0 on success, a negative errno value otherwise and rte_errno is set.
1033 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1034 uint64_t action_flags,
1035 struct rte_eth_dev *dev,
1036 const struct rte_flow_attr *attr,
1037 struct rte_flow_error *error)
1039 struct mlx5_priv *priv = dev->data->dev_private;
1040 const struct rte_flow_action_queue *queue = action->conf;
1042 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1043 return rte_flow_error_set(error, EINVAL,
1044 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1045 "can't have 2 fate actions in"
1048 return rte_flow_error_set(error, EINVAL,
1049 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1050 NULL, "No Rx queues configured");
1051 if (queue->index >= priv->rxqs_n)
1052 return rte_flow_error_set(error, EINVAL,
1053 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1055 "queue index out of range");
1056 if (!(*priv->rxqs)[queue->index])
1057 return rte_flow_error_set(error, EINVAL,
1058 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1060 "queue is not configured");
1062 return rte_flow_error_set(error, ENOTSUP,
1063 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1064 "queue action not supported for "
1070 * Validate the rss action.
1073 * Pointer to the queue action.
1074 * @param[in] action_flags
1075 * Bit-fields that holds the actions detected until now.
1077 * Pointer to the Ethernet device structure.
1079 * Attributes of flow that includes this action.
1080 * @param[in] item_flags
1081 * Items that were detected.
1083 * Pointer to error structure.
1086 * 0 on success, a negative errno value otherwise and rte_errno is set.
1089 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1090 uint64_t action_flags,
1091 struct rte_eth_dev *dev,
1092 const struct rte_flow_attr *attr,
1093 uint64_t item_flags,
1094 struct rte_flow_error *error)
1096 struct mlx5_priv *priv = dev->data->dev_private;
1097 const struct rte_flow_action_rss *rss = action->conf;
1098 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1101 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1102 return rte_flow_error_set(error, EINVAL,
1103 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1104 "can't have 2 fate actions"
1106 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1107 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1108 return rte_flow_error_set(error, ENOTSUP,
1109 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1111 "RSS hash function not supported");
1112 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1117 return rte_flow_error_set(error, ENOTSUP,
1118 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1120 "tunnel RSS is not supported");
1121 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1122 if (rss->key_len == 0 && rss->key != NULL)
1123 return rte_flow_error_set(error, ENOTSUP,
1124 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1126 "RSS hash key length 0");
1127 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1128 return rte_flow_error_set(error, ENOTSUP,
1129 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1131 "RSS hash key too small");
1132 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1133 return rte_flow_error_set(error, ENOTSUP,
1134 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1136 "RSS hash key too large");
1137 if (rss->queue_num > priv->config.ind_table_max_size)
1138 return rte_flow_error_set(error, ENOTSUP,
1139 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1141 "number of queues too large");
1142 if (rss->types & MLX5_RSS_HF_MASK)
1143 return rte_flow_error_set(error, ENOTSUP,
1144 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1146 "some RSS protocols are not"
1148 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1149 !(rss->types & ETH_RSS_IP))
1150 return rte_flow_error_set(error, EINVAL,
1151 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1152 "L3 partial RSS requested but L3 RSS"
1153 " type not specified");
1154 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1155 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1156 return rte_flow_error_set(error, EINVAL,
1157 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1158 "L4 partial RSS requested but L4 RSS"
1159 " type not specified");
1161 return rte_flow_error_set(error, EINVAL,
1162 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1163 NULL, "No Rx queues configured");
1164 if (!rss->queue_num)
1165 return rte_flow_error_set(error, EINVAL,
1166 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1167 NULL, "No queues configured");
1168 for (i = 0; i != rss->queue_num; ++i) {
1169 if (rss->queue[i] >= priv->rxqs_n)
1170 return rte_flow_error_set
1172 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1173 &rss->queue[i], "queue index out of range");
1174 if (!(*priv->rxqs)[rss->queue[i]])
1175 return rte_flow_error_set
1176 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1177 &rss->queue[i], "queue is not configured");
1180 return rte_flow_error_set(error, ENOTSUP,
1181 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1182 "rss action not supported for "
1184 if (rss->level > 1 && !tunnel)
1185 return rte_flow_error_set(error, EINVAL,
1186 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1187 "inner RSS is not supported for "
1188 "non-tunnel flows");
1193 * Validate the count action.
1196 * Pointer to the Ethernet device structure.
1198 * Attributes of flow that includes this action.
1200 * Pointer to error structure.
1203 * 0 on success, a negative errno value otherwise and rte_errno is set.
1206 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1207 const struct rte_flow_attr *attr,
1208 struct rte_flow_error *error)
1211 return rte_flow_error_set(error, ENOTSUP,
1212 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1213 "count action not supported for "
1219 * Verify the @p attributes will be correctly understood by the NIC and store
1220 * them in the @p flow if everything is correct.
1223 * Pointer to the Ethernet device structure.
1224 * @param[in] attributes
1225 * Pointer to flow attributes
1227 * Pointer to error structure.
1230 * 0 on success, a negative errno value otherwise and rte_errno is set.
1233 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1234 const struct rte_flow_attr *attributes,
1235 struct rte_flow_error *error)
1237 struct mlx5_priv *priv = dev->data->dev_private;
1238 uint32_t priority_max = priv->config.flow_prio - 1;
1240 if (attributes->group)
1241 return rte_flow_error_set(error, ENOTSUP,
1242 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1243 NULL, "groups is not supported");
1244 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1245 attributes->priority >= priority_max)
1246 return rte_flow_error_set(error, ENOTSUP,
1247 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1248 NULL, "priority out of range");
1249 if (attributes->egress)
1250 return rte_flow_error_set(error, ENOTSUP,
1251 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1252 "egress is not supported");
1253 if (attributes->transfer && !priv->config.dv_esw_en)
1254 return rte_flow_error_set(error, ENOTSUP,
1255 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1256 NULL, "transfer is not supported");
1257 if (!attributes->ingress)
1258 return rte_flow_error_set(error, EINVAL,
1259 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1261 "ingress attribute is mandatory");
1266 * Validate ICMP6 item.
1269 * Item specification.
1270 * @param[in] item_flags
1271 * Bit-fields that holds the items detected until now.
1273 * Pointer to error structure.
1276 * 0 on success, a negative errno value otherwise and rte_errno is set.
1279 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1280 uint64_t item_flags,
1281 uint8_t target_protocol,
1282 struct rte_flow_error *error)
1284 const struct rte_flow_item_icmp6 *mask = item->mask;
1285 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1286 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1287 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1288 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1289 MLX5_FLOW_LAYER_OUTER_L4;
1292 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1293 return rte_flow_error_set(error, EINVAL,
1294 RTE_FLOW_ERROR_TYPE_ITEM, item,
1295 "protocol filtering not compatible"
1296 " with ICMP6 layer");
1297 if (!(item_flags & l3m))
1298 return rte_flow_error_set(error, EINVAL,
1299 RTE_FLOW_ERROR_TYPE_ITEM, item,
1300 "IPv6 is mandatory to filter on"
1302 if (item_flags & l4m)
1303 return rte_flow_error_set(error, EINVAL,
1304 RTE_FLOW_ERROR_TYPE_ITEM, item,
1305 "multiple L4 layers not supported");
1307 mask = &rte_flow_item_icmp6_mask;
1308 ret = mlx5_flow_item_acceptable
1309 (item, (const uint8_t *)mask,
1310 (const uint8_t *)&rte_flow_item_icmp6_mask,
1311 sizeof(struct rte_flow_item_icmp6), error);
1318 * Validate ICMP item.
1321 * Item specification.
1322 * @param[in] item_flags
1323 * Bit-fields that holds the items detected until now.
1325 * Pointer to error structure.
1328 * 0 on success, a negative errno value otherwise and rte_errno is set.
1331 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1332 uint64_t item_flags,
1333 uint8_t target_protocol,
1334 struct rte_flow_error *error)
1336 const struct rte_flow_item_icmp *mask = item->mask;
1337 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1338 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1339 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1340 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1341 MLX5_FLOW_LAYER_OUTER_L4;
1344 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1345 return rte_flow_error_set(error, EINVAL,
1346 RTE_FLOW_ERROR_TYPE_ITEM, item,
1347 "protocol filtering not compatible"
1348 " with ICMP layer");
1349 if (!(item_flags & l3m))
1350 return rte_flow_error_set(error, EINVAL,
1351 RTE_FLOW_ERROR_TYPE_ITEM, item,
1352 "IPv4 is mandatory to filter"
1354 if (item_flags & l4m)
1355 return rte_flow_error_set(error, EINVAL,
1356 RTE_FLOW_ERROR_TYPE_ITEM, item,
1357 "multiple L4 layers not supported");
1359 mask = &rte_flow_item_icmp_mask;
1360 ret = mlx5_flow_item_acceptable
1361 (item, (const uint8_t *)mask,
1362 (const uint8_t *)&rte_flow_item_icmp_mask,
1363 sizeof(struct rte_flow_item_icmp), error);
1370 * Validate Ethernet item.
1373 * Item specification.
1374 * @param[in] item_flags
1375 * Bit-fields that holds the items detected until now.
1377 * Pointer to error structure.
1380 * 0 on success, a negative errno value otherwise and rte_errno is set.
1383 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1384 uint64_t item_flags,
1385 struct rte_flow_error *error)
1387 const struct rte_flow_item_eth *mask = item->mask;
1388 const struct rte_flow_item_eth nic_mask = {
1389 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1390 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1391 .type = RTE_BE16(0xffff),
1394 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1395 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1396 MLX5_FLOW_LAYER_OUTER_L2;
1398 if (item_flags & ethm)
1399 return rte_flow_error_set(error, ENOTSUP,
1400 RTE_FLOW_ERROR_TYPE_ITEM, item,
1401 "multiple L2 layers not supported");
1402 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1403 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1404 return rte_flow_error_set(error, EINVAL,
1405 RTE_FLOW_ERROR_TYPE_ITEM, item,
1406 "L2 layer should not follow "
1408 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1409 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1410 return rte_flow_error_set(error, EINVAL,
1411 RTE_FLOW_ERROR_TYPE_ITEM, item,
1412 "L2 layer should not follow VLAN");
1414 mask = &rte_flow_item_eth_mask;
1415 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1416 (const uint8_t *)&nic_mask,
1417 sizeof(struct rte_flow_item_eth),
1423 * Validate VLAN item.
1426 * Item specification.
1427 * @param[in] item_flags
1428 * Bit-fields that holds the items detected until now.
1430 * Ethernet device flow is being created on.
1432 * Pointer to error structure.
1435 * 0 on success, a negative errno value otherwise and rte_errno is set.
1438 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1439 uint64_t item_flags,
1440 struct rte_eth_dev *dev,
1441 struct rte_flow_error *error)
1443 const struct rte_flow_item_vlan *spec = item->spec;
1444 const struct rte_flow_item_vlan *mask = item->mask;
1445 const struct rte_flow_item_vlan nic_mask = {
1446 .tci = RTE_BE16(UINT16_MAX),
1447 .inner_type = RTE_BE16(UINT16_MAX),
1449 uint16_t vlan_tag = 0;
1450 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1452 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1453 MLX5_FLOW_LAYER_INNER_L4) :
1454 (MLX5_FLOW_LAYER_OUTER_L3 |
1455 MLX5_FLOW_LAYER_OUTER_L4);
1456 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1457 MLX5_FLOW_LAYER_OUTER_VLAN;
1459 if (item_flags & vlanm)
1460 return rte_flow_error_set(error, EINVAL,
1461 RTE_FLOW_ERROR_TYPE_ITEM, item,
1462 "multiple VLAN layers not supported");
1463 else if ((item_flags & l34m) != 0)
1464 return rte_flow_error_set(error, EINVAL,
1465 RTE_FLOW_ERROR_TYPE_ITEM, item,
1466 "VLAN cannot follow L3/L4 layer");
1468 mask = &rte_flow_item_vlan_mask;
1469 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1470 (const uint8_t *)&nic_mask,
1471 sizeof(struct rte_flow_item_vlan),
1475 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1476 struct mlx5_priv *priv = dev->data->dev_private;
1478 if (priv->vmwa_context) {
1480 * Non-NULL context means we have a virtual machine
1481 * and SR-IOV enabled, we have to create VLAN interface
1482 * to make hypervisor to setup E-Switch vport
1483 * context correctly. We avoid creating the multiple
1484 * VLAN interfaces, so we cannot support VLAN tag mask.
1486 return rte_flow_error_set(error, EINVAL,
1487 RTE_FLOW_ERROR_TYPE_ITEM,
1489 "VLAN tag mask is not"
1490 " supported in virtual"
1495 vlan_tag = spec->tci;
1496 vlan_tag &= mask->tci;
1499 * From verbs perspective an empty VLAN is equivalent
1500 * to a packet without VLAN layer.
1503 return rte_flow_error_set(error, EINVAL,
1504 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1506 "VLAN cannot be empty");
1511 * Validate IPV4 item.
1514 * Item specification.
1515 * @param[in] item_flags
1516 * Bit-fields that holds the items detected until now.
1517 * @param[in] acc_mask
1518 * Acceptable mask, if NULL default internal default mask
1519 * will be used to check whether item fields are supported.
1521 * Pointer to error structure.
1524 * 0 on success, a negative errno value otherwise and rte_errno is set.
1527 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1528 uint64_t item_flags,
1530 uint16_t ether_type,
1531 const struct rte_flow_item_ipv4 *acc_mask,
1532 struct rte_flow_error *error)
1534 const struct rte_flow_item_ipv4 *mask = item->mask;
1535 const struct rte_flow_item_ipv4 *spec = item->spec;
1536 const struct rte_flow_item_ipv4 nic_mask = {
1538 .src_addr = RTE_BE32(0xffffffff),
1539 .dst_addr = RTE_BE32(0xffffffff),
1540 .type_of_service = 0xff,
1541 .next_proto_id = 0xff,
1544 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1545 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1546 MLX5_FLOW_LAYER_OUTER_L3;
1547 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1548 MLX5_FLOW_LAYER_OUTER_L4;
1550 uint8_t next_proto = 0xFF;
1551 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1552 MLX5_FLOW_LAYER_OUTER_VLAN |
1553 MLX5_FLOW_LAYER_INNER_VLAN);
1555 if ((last_item & l2_vlan) && ether_type &&
1556 ether_type != RTE_ETHER_TYPE_IPV4)
1557 return rte_flow_error_set(error, EINVAL,
1558 RTE_FLOW_ERROR_TYPE_ITEM, item,
1559 "IPv4 cannot follow L2/VLAN layer "
1560 "which ether type is not IPv4");
1561 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1563 next_proto = mask->hdr.next_proto_id &
1564 spec->hdr.next_proto_id;
1565 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1566 return rte_flow_error_set(error, EINVAL,
1567 RTE_FLOW_ERROR_TYPE_ITEM,
1572 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1573 return rte_flow_error_set(error, EINVAL,
1574 RTE_FLOW_ERROR_TYPE_ITEM, item,
1575 "wrong tunnel type - IPv6 specified "
1576 "but IPv4 item provided");
1577 if (item_flags & l3m)
1578 return rte_flow_error_set(error, ENOTSUP,
1579 RTE_FLOW_ERROR_TYPE_ITEM, item,
1580 "multiple L3 layers not supported");
1581 else if (item_flags & l4m)
1582 return rte_flow_error_set(error, EINVAL,
1583 RTE_FLOW_ERROR_TYPE_ITEM, item,
1584 "L3 cannot follow an L4 layer.");
1585 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1586 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1587 return rte_flow_error_set(error, EINVAL,
1588 RTE_FLOW_ERROR_TYPE_ITEM, item,
1589 "L3 cannot follow an NVGRE layer.");
1591 mask = &rte_flow_item_ipv4_mask;
1592 else if (mask->hdr.next_proto_id != 0 &&
1593 mask->hdr.next_proto_id != 0xff)
1594 return rte_flow_error_set(error, EINVAL,
1595 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1596 "partial mask is not supported"
1598 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1599 acc_mask ? (const uint8_t *)acc_mask
1600 : (const uint8_t *)&nic_mask,
1601 sizeof(struct rte_flow_item_ipv4),
1609 * Validate IPV6 item.
1612 * Item specification.
1613 * @param[in] item_flags
1614 * Bit-fields that holds the items detected until now.
1615 * @param[in] acc_mask
1616 * Acceptable mask, if NULL default internal default mask
1617 * will be used to check whether item fields are supported.
1619 * Pointer to error structure.
1622 * 0 on success, a negative errno value otherwise and rte_errno is set.
1625 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1626 uint64_t item_flags,
1628 uint16_t ether_type,
1629 const struct rte_flow_item_ipv6 *acc_mask,
1630 struct rte_flow_error *error)
1632 const struct rte_flow_item_ipv6 *mask = item->mask;
1633 const struct rte_flow_item_ipv6 *spec = item->spec;
1634 const struct rte_flow_item_ipv6 nic_mask = {
1637 "\xff\xff\xff\xff\xff\xff\xff\xff"
1638 "\xff\xff\xff\xff\xff\xff\xff\xff",
1640 "\xff\xff\xff\xff\xff\xff\xff\xff"
1641 "\xff\xff\xff\xff\xff\xff\xff\xff",
1642 .vtc_flow = RTE_BE32(0xffffffff),
1646 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1647 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1648 MLX5_FLOW_LAYER_OUTER_L3;
1649 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1650 MLX5_FLOW_LAYER_OUTER_L4;
1652 uint8_t next_proto = 0xFF;
1653 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1654 MLX5_FLOW_LAYER_OUTER_VLAN |
1655 MLX5_FLOW_LAYER_INNER_VLAN);
1657 if ((last_item & l2_vlan) && ether_type &&
1658 ether_type != RTE_ETHER_TYPE_IPV6)
1659 return rte_flow_error_set(error, EINVAL,
1660 RTE_FLOW_ERROR_TYPE_ITEM, item,
1661 "IPv6 cannot follow L2/VLAN layer "
1662 "which ether type is not IPv6");
1663 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
1665 next_proto = mask->hdr.proto & spec->hdr.proto;
1666 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1667 return rte_flow_error_set(error, EINVAL,
1668 RTE_FLOW_ERROR_TYPE_ITEM,
1673 if (item_flags & MLX5_FLOW_LAYER_IPIP)
1674 return rte_flow_error_set(error, EINVAL,
1675 RTE_FLOW_ERROR_TYPE_ITEM, item,
1676 "wrong tunnel type - IPv4 specified "
1677 "but IPv6 item provided");
1678 if (item_flags & l3m)
1679 return rte_flow_error_set(error, ENOTSUP,
1680 RTE_FLOW_ERROR_TYPE_ITEM, item,
1681 "multiple L3 layers not supported");
1682 else if (item_flags & l4m)
1683 return rte_flow_error_set(error, EINVAL,
1684 RTE_FLOW_ERROR_TYPE_ITEM, item,
1685 "L3 cannot follow an L4 layer.");
1686 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1687 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1688 return rte_flow_error_set(error, EINVAL,
1689 RTE_FLOW_ERROR_TYPE_ITEM, item,
1690 "L3 cannot follow an NVGRE layer.");
1692 mask = &rte_flow_item_ipv6_mask;
1693 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1694 acc_mask ? (const uint8_t *)acc_mask
1695 : (const uint8_t *)&nic_mask,
1696 sizeof(struct rte_flow_item_ipv6),
1704 * Validate UDP item.
1707 * Item specification.
1708 * @param[in] item_flags
1709 * Bit-fields that holds the items detected until now.
1710 * @param[in] target_protocol
1711 * The next protocol in the previous item.
1712 * @param[in] flow_mask
1713 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
1715 * Pointer to error structure.
1718 * 0 on success, a negative errno value otherwise and rte_errno is set.
1721 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1722 uint64_t item_flags,
1723 uint8_t target_protocol,
1724 struct rte_flow_error *error)
1726 const struct rte_flow_item_udp *mask = item->mask;
1727 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1728 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1729 MLX5_FLOW_LAYER_OUTER_L3;
1730 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1731 MLX5_FLOW_LAYER_OUTER_L4;
1734 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1735 return rte_flow_error_set(error, EINVAL,
1736 RTE_FLOW_ERROR_TYPE_ITEM, item,
1737 "protocol filtering not compatible"
1739 if (!(item_flags & l3m))
1740 return rte_flow_error_set(error, EINVAL,
1741 RTE_FLOW_ERROR_TYPE_ITEM, item,
1742 "L3 is mandatory to filter on L4");
1743 if (item_flags & l4m)
1744 return rte_flow_error_set(error, EINVAL,
1745 RTE_FLOW_ERROR_TYPE_ITEM, item,
1746 "multiple L4 layers not supported");
1748 mask = &rte_flow_item_udp_mask;
1749 ret = mlx5_flow_item_acceptable
1750 (item, (const uint8_t *)mask,
1751 (const uint8_t *)&rte_flow_item_udp_mask,
1752 sizeof(struct rte_flow_item_udp), error);
1759 * Validate TCP item.
1762 * Item specification.
1763 * @param[in] item_flags
1764 * Bit-fields that holds the items detected until now.
1765 * @param[in] target_protocol
1766 * The next protocol in the previous item.
1768 * Pointer to error structure.
1771 * 0 on success, a negative errno value otherwise and rte_errno is set.
1774 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1775 uint64_t item_flags,
1776 uint8_t target_protocol,
1777 const struct rte_flow_item_tcp *flow_mask,
1778 struct rte_flow_error *error)
1780 const struct rte_flow_item_tcp *mask = item->mask;
1781 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1782 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1783 MLX5_FLOW_LAYER_OUTER_L3;
1784 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1785 MLX5_FLOW_LAYER_OUTER_L4;
1788 MLX5_ASSERT(flow_mask);
1789 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1790 return rte_flow_error_set(error, EINVAL,
1791 RTE_FLOW_ERROR_TYPE_ITEM, item,
1792 "protocol filtering not compatible"
1794 if (!(item_flags & l3m))
1795 return rte_flow_error_set(error, EINVAL,
1796 RTE_FLOW_ERROR_TYPE_ITEM, item,
1797 "L3 is mandatory to filter on L4");
1798 if (item_flags & l4m)
1799 return rte_flow_error_set(error, EINVAL,
1800 RTE_FLOW_ERROR_TYPE_ITEM, item,
1801 "multiple L4 layers not supported");
1803 mask = &rte_flow_item_tcp_mask;
1804 ret = mlx5_flow_item_acceptable
1805 (item, (const uint8_t *)mask,
1806 (const uint8_t *)flow_mask,
1807 sizeof(struct rte_flow_item_tcp), error);
1814 * Validate VXLAN item.
1817 * Item specification.
1818 * @param[in] item_flags
1819 * Bit-fields that holds the items detected until now.
1820 * @param[in] target_protocol
1821 * The next protocol in the previous item.
1823 * Pointer to error structure.
1826 * 0 on success, a negative errno value otherwise and rte_errno is set.
1829 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1830 uint64_t item_flags,
1831 struct rte_flow_error *error)
1833 const struct rte_flow_item_vxlan *spec = item->spec;
1834 const struct rte_flow_item_vxlan *mask = item->mask;
1839 } id = { .vlan_id = 0, };
1842 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1843 return rte_flow_error_set(error, ENOTSUP,
1844 RTE_FLOW_ERROR_TYPE_ITEM, item,
1845 "multiple tunnel layers not"
1848 * Verify only UDPv4 is present as defined in
1849 * https://tools.ietf.org/html/rfc7348
1851 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1852 return rte_flow_error_set(error, EINVAL,
1853 RTE_FLOW_ERROR_TYPE_ITEM, item,
1854 "no outer UDP layer found");
1856 mask = &rte_flow_item_vxlan_mask;
1857 ret = mlx5_flow_item_acceptable
1858 (item, (const uint8_t *)mask,
1859 (const uint8_t *)&rte_flow_item_vxlan_mask,
1860 sizeof(struct rte_flow_item_vxlan),
1865 memcpy(&id.vni[1], spec->vni, 3);
1866 memcpy(&id.vni[1], mask->vni, 3);
1868 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1869 return rte_flow_error_set(error, ENOTSUP,
1870 RTE_FLOW_ERROR_TYPE_ITEM, item,
1871 "VXLAN tunnel must be fully defined");
1876 * Validate VXLAN_GPE item.
1879 * Item specification.
1880 * @param[in] item_flags
1881 * Bit-fields that holds the items detected until now.
1883 * Pointer to the private data structure.
1884 * @param[in] target_protocol
1885 * The next protocol in the previous item.
1887 * Pointer to error structure.
1890 * 0 on success, a negative errno value otherwise and rte_errno is set.
1893 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1894 uint64_t item_flags,
1895 struct rte_eth_dev *dev,
1896 struct rte_flow_error *error)
1898 struct mlx5_priv *priv = dev->data->dev_private;
1899 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1900 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1905 } id = { .vlan_id = 0, };
1907 if (!priv->config.l3_vxlan_en)
1908 return rte_flow_error_set(error, ENOTSUP,
1909 RTE_FLOW_ERROR_TYPE_ITEM, item,
1910 "L3 VXLAN is not enabled by device"
1911 " parameter and/or not configured in"
1913 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1914 return rte_flow_error_set(error, ENOTSUP,
1915 RTE_FLOW_ERROR_TYPE_ITEM, item,
1916 "multiple tunnel layers not"
1919 * Verify only UDPv4 is present as defined in
1920 * https://tools.ietf.org/html/rfc7348
1922 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1923 return rte_flow_error_set(error, EINVAL,
1924 RTE_FLOW_ERROR_TYPE_ITEM, item,
1925 "no outer UDP layer found");
1927 mask = &rte_flow_item_vxlan_gpe_mask;
1928 ret = mlx5_flow_item_acceptable
1929 (item, (const uint8_t *)mask,
1930 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1931 sizeof(struct rte_flow_item_vxlan_gpe),
1937 return rte_flow_error_set(error, ENOTSUP,
1938 RTE_FLOW_ERROR_TYPE_ITEM,
1940 "VxLAN-GPE protocol"
1942 memcpy(&id.vni[1], spec->vni, 3);
1943 memcpy(&id.vni[1], mask->vni, 3);
1945 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1946 return rte_flow_error_set(error, ENOTSUP,
1947 RTE_FLOW_ERROR_TYPE_ITEM, item,
1948 "VXLAN-GPE tunnel must be fully"
1953 * Validate GRE Key item.
1956 * Item specification.
1957 * @param[in] item_flags
1958 * Bit flags to mark detected items.
1959 * @param[in] gre_item
1960 * Pointer to gre_item
1962 * Pointer to error structure.
1965 * 0 on success, a negative errno value otherwise and rte_errno is set.
1968 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
1969 uint64_t item_flags,
1970 const struct rte_flow_item *gre_item,
1971 struct rte_flow_error *error)
1973 const rte_be32_t *mask = item->mask;
1975 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
1976 const struct rte_flow_item_gre *gre_spec;
1977 const struct rte_flow_item_gre *gre_mask;
1979 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
1980 return rte_flow_error_set(error, ENOTSUP,
1981 RTE_FLOW_ERROR_TYPE_ITEM, item,
1982 "Multiple GRE key not support");
1983 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
1984 return rte_flow_error_set(error, ENOTSUP,
1985 RTE_FLOW_ERROR_TYPE_ITEM, item,
1986 "No preceding GRE header");
1987 if (item_flags & MLX5_FLOW_LAYER_INNER)
1988 return rte_flow_error_set(error, ENOTSUP,
1989 RTE_FLOW_ERROR_TYPE_ITEM, item,
1990 "GRE key following a wrong item");
1991 gre_mask = gre_item->mask;
1993 gre_mask = &rte_flow_item_gre_mask;
1994 gre_spec = gre_item->spec;
1995 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
1996 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
1997 return rte_flow_error_set(error, EINVAL,
1998 RTE_FLOW_ERROR_TYPE_ITEM, item,
1999 "Key bit must be on");
2002 mask = &gre_key_default_mask;
2003 ret = mlx5_flow_item_acceptable
2004 (item, (const uint8_t *)mask,
2005 (const uint8_t *)&gre_key_default_mask,
2006 sizeof(rte_be32_t), error);
2011 * Validate GRE item.
2014 * Item specification.
2015 * @param[in] item_flags
2016 * Bit flags to mark detected items.
2017 * @param[in] target_protocol
2018 * The next protocol in the previous item.
2020 * Pointer to error structure.
2023 * 0 on success, a negative errno value otherwise and rte_errno is set.
2026 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2027 uint64_t item_flags,
2028 uint8_t target_protocol,
2029 struct rte_flow_error *error)
2031 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2032 const struct rte_flow_item_gre *mask = item->mask;
2034 const struct rte_flow_item_gre nic_mask = {
2035 .c_rsvd0_ver = RTE_BE16(0xB000),
2036 .protocol = RTE_BE16(UINT16_MAX),
2039 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2040 return rte_flow_error_set(error, EINVAL,
2041 RTE_FLOW_ERROR_TYPE_ITEM, item,
2042 "protocol filtering not compatible"
2043 " with this GRE layer");
2044 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2045 return rte_flow_error_set(error, ENOTSUP,
2046 RTE_FLOW_ERROR_TYPE_ITEM, item,
2047 "multiple tunnel layers not"
2049 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2050 return rte_flow_error_set(error, ENOTSUP,
2051 RTE_FLOW_ERROR_TYPE_ITEM, item,
2052 "L3 Layer is missing");
2054 mask = &rte_flow_item_gre_mask;
2055 ret = mlx5_flow_item_acceptable
2056 (item, (const uint8_t *)mask,
2057 (const uint8_t *)&nic_mask,
2058 sizeof(struct rte_flow_item_gre), error);
2061 #ifndef HAVE_MLX5DV_DR
2062 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2063 if (spec && (spec->protocol & mask->protocol))
2064 return rte_flow_error_set(error, ENOTSUP,
2065 RTE_FLOW_ERROR_TYPE_ITEM, item,
2066 "without MPLS support the"
2067 " specification cannot be used for"
2075 * Validate Geneve item.
2078 * Item specification.
2079 * @param[in] itemFlags
2080 * Bit-fields that holds the items detected until now.
2082 * Pointer to the private data structure.
2084 * Pointer to error structure.
2087 * 0 on success, a negative errno value otherwise and rte_errno is set.
2091 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2092 uint64_t item_flags,
2093 struct rte_eth_dev *dev,
2094 struct rte_flow_error *error)
2096 struct mlx5_priv *priv = dev->data->dev_private;
2097 const struct rte_flow_item_geneve *spec = item->spec;
2098 const struct rte_flow_item_geneve *mask = item->mask;
2101 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2102 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2103 const struct rte_flow_item_geneve nic_mask = {
2104 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2105 .vni = "\xff\xff\xff",
2106 .protocol = RTE_BE16(UINT16_MAX),
2109 if (!priv->config.hca_attr.tunnel_stateless_geneve_rx)
2110 return rte_flow_error_set(error, ENOTSUP,
2111 RTE_FLOW_ERROR_TYPE_ITEM, item,
2112 "L3 Geneve is not enabled by device"
2113 " parameter and/or not configured in"
2115 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2116 return rte_flow_error_set(error, ENOTSUP,
2117 RTE_FLOW_ERROR_TYPE_ITEM, item,
2118 "multiple tunnel layers not"
2121 * Verify only UDPv4 is present as defined in
2122 * https://tools.ietf.org/html/rfc7348
2124 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2125 return rte_flow_error_set(error, EINVAL,
2126 RTE_FLOW_ERROR_TYPE_ITEM, item,
2127 "no outer UDP layer found");
2129 mask = &rte_flow_item_geneve_mask;
2130 ret = mlx5_flow_item_acceptable
2131 (item, (const uint8_t *)mask,
2132 (const uint8_t *)&nic_mask,
2133 sizeof(struct rte_flow_item_geneve), error);
2137 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2138 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2139 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2140 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2141 return rte_flow_error_set(error, ENOTSUP,
2142 RTE_FLOW_ERROR_TYPE_ITEM,
2144 "Geneve protocol unsupported"
2145 " fields are being used");
2146 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2147 return rte_flow_error_set
2149 RTE_FLOW_ERROR_TYPE_ITEM,
2151 "Unsupported Geneve options length");
2153 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2154 return rte_flow_error_set
2156 RTE_FLOW_ERROR_TYPE_ITEM, item,
2157 "Geneve tunnel must be fully defined");
2162 * Validate MPLS item.
2165 * Pointer to the rte_eth_dev structure.
2167 * Item specification.
2168 * @param[in] item_flags
2169 * Bit-fields that holds the items detected until now.
2170 * @param[in] prev_layer
2171 * The protocol layer indicated in previous item.
2173 * Pointer to error structure.
2176 * 0 on success, a negative errno value otherwise and rte_errno is set.
2179 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2180 const struct rte_flow_item *item __rte_unused,
2181 uint64_t item_flags __rte_unused,
2182 uint64_t prev_layer __rte_unused,
2183 struct rte_flow_error *error)
2185 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2186 const struct rte_flow_item_mpls *mask = item->mask;
2187 struct mlx5_priv *priv = dev->data->dev_private;
2190 if (!priv->config.mpls_en)
2191 return rte_flow_error_set(error, ENOTSUP,
2192 RTE_FLOW_ERROR_TYPE_ITEM, item,
2193 "MPLS not supported or"
2194 " disabled in firmware"
2196 /* MPLS over IP, UDP, GRE is allowed */
2197 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2198 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2199 MLX5_FLOW_LAYER_GRE)))
2200 return rte_flow_error_set(error, EINVAL,
2201 RTE_FLOW_ERROR_TYPE_ITEM, item,
2202 "protocol filtering not compatible"
2203 " with MPLS layer");
2204 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2205 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2206 !(item_flags & MLX5_FLOW_LAYER_GRE))
2207 return rte_flow_error_set(error, ENOTSUP,
2208 RTE_FLOW_ERROR_TYPE_ITEM, item,
2209 "multiple tunnel layers not"
2212 mask = &rte_flow_item_mpls_mask;
2213 ret = mlx5_flow_item_acceptable
2214 (item, (const uint8_t *)mask,
2215 (const uint8_t *)&rte_flow_item_mpls_mask,
2216 sizeof(struct rte_flow_item_mpls), error);
2221 return rte_flow_error_set(error, ENOTSUP,
2222 RTE_FLOW_ERROR_TYPE_ITEM, item,
2223 "MPLS is not supported by Verbs, please"
2228 * Validate NVGRE item.
2231 * Item specification.
2232 * @param[in] item_flags
2233 * Bit flags to mark detected items.
2234 * @param[in] target_protocol
2235 * The next protocol in the previous item.
2237 * Pointer to error structure.
2240 * 0 on success, a negative errno value otherwise and rte_errno is set.
2243 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2244 uint64_t item_flags,
2245 uint8_t target_protocol,
2246 struct rte_flow_error *error)
2248 const struct rte_flow_item_nvgre *mask = item->mask;
2251 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2252 return rte_flow_error_set(error, EINVAL,
2253 RTE_FLOW_ERROR_TYPE_ITEM, item,
2254 "protocol filtering not compatible"
2255 " with this GRE layer");
2256 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2257 return rte_flow_error_set(error, ENOTSUP,
2258 RTE_FLOW_ERROR_TYPE_ITEM, item,
2259 "multiple tunnel layers not"
2261 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2262 return rte_flow_error_set(error, ENOTSUP,
2263 RTE_FLOW_ERROR_TYPE_ITEM, item,
2264 "L3 Layer is missing");
2266 mask = &rte_flow_item_nvgre_mask;
2267 ret = mlx5_flow_item_acceptable
2268 (item, (const uint8_t *)mask,
2269 (const uint8_t *)&rte_flow_item_nvgre_mask,
2270 sizeof(struct rte_flow_item_nvgre), error);
2276 /* Allocate unique ID for the split Q/RSS subflows. */
2278 flow_qrss_get_id(struct rte_eth_dev *dev)
2280 struct mlx5_priv *priv = dev->data->dev_private;
2281 uint32_t qrss_id, ret;
2283 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2286 MLX5_ASSERT(qrss_id);
2290 /* Free unique ID for the split Q/RSS subflows. */
2292 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2294 struct mlx5_priv *priv = dev->data->dev_private;
2297 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2301 * Release resource related QUEUE/RSS action split.
2304 * Pointer to Ethernet device.
2306 * Flow to release id's from.
2309 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2310 struct rte_flow *flow)
2312 struct mlx5_flow *dev_flow;
2314 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
2315 if (dev_flow->qrss_id)
2316 flow_qrss_free_id(dev, dev_flow->qrss_id);
2320 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2321 const struct rte_flow_attr *attr __rte_unused,
2322 const struct rte_flow_item items[] __rte_unused,
2323 const struct rte_flow_action actions[] __rte_unused,
2324 bool external __rte_unused,
2325 struct rte_flow_error *error)
2327 return rte_flow_error_set(error, ENOTSUP,
2328 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2331 static struct mlx5_flow *
2332 flow_null_prepare(const struct rte_flow_attr *attr __rte_unused,
2333 const struct rte_flow_item items[] __rte_unused,
2334 const struct rte_flow_action actions[] __rte_unused,
2335 struct rte_flow_error *error)
2337 rte_flow_error_set(error, ENOTSUP,
2338 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2343 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2344 struct mlx5_flow *dev_flow __rte_unused,
2345 const struct rte_flow_attr *attr __rte_unused,
2346 const struct rte_flow_item items[] __rte_unused,
2347 const struct rte_flow_action actions[] __rte_unused,
2348 struct rte_flow_error *error)
2350 return rte_flow_error_set(error, ENOTSUP,
2351 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2355 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2356 struct rte_flow *flow __rte_unused,
2357 struct rte_flow_error *error)
2359 return rte_flow_error_set(error, ENOTSUP,
2360 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2364 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2365 struct rte_flow *flow __rte_unused)
2370 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2371 struct rte_flow *flow __rte_unused)
2376 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2377 struct rte_flow *flow __rte_unused,
2378 const struct rte_flow_action *actions __rte_unused,
2379 void *data __rte_unused,
2380 struct rte_flow_error *error)
2382 return rte_flow_error_set(error, ENOTSUP,
2383 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2386 /* Void driver to protect from null pointer reference. */
2387 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2388 .validate = flow_null_validate,
2389 .prepare = flow_null_prepare,
2390 .translate = flow_null_translate,
2391 .apply = flow_null_apply,
2392 .remove = flow_null_remove,
2393 .destroy = flow_null_destroy,
2394 .query = flow_null_query,
2398 * Select flow driver type according to flow attributes and device
2402 * Pointer to the dev structure.
2404 * Pointer to the flow attributes.
2407 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2409 static enum mlx5_flow_drv_type
2410 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2412 struct mlx5_priv *priv = dev->data->dev_private;
2413 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
2415 if (attr->transfer && priv->config.dv_esw_en)
2416 type = MLX5_FLOW_TYPE_DV;
2417 if (!attr->transfer)
2418 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2419 MLX5_FLOW_TYPE_VERBS;
2423 #define flow_get_drv_ops(type) flow_drv_ops[type]
2426 * Flow driver validation API. This abstracts calling driver specific functions.
2427 * The type of flow driver is determined according to flow attributes.
2430 * Pointer to the dev structure.
2432 * Pointer to the flow attributes.
2434 * Pointer to the list of items.
2435 * @param[in] actions
2436 * Pointer to the list of actions.
2437 * @param[in] external
2438 * This flow rule is created by request external to PMD.
2440 * Pointer to the error structure.
2443 * 0 on success, a negative errno value otherwise and rte_errno is set.
2446 flow_drv_validate(struct rte_eth_dev *dev,
2447 const struct rte_flow_attr *attr,
2448 const struct rte_flow_item items[],
2449 const struct rte_flow_action actions[],
2450 bool external, struct rte_flow_error *error)
2452 const struct mlx5_flow_driver_ops *fops;
2453 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2455 fops = flow_get_drv_ops(type);
2456 return fops->validate(dev, attr, items, actions, external, error);
2460 * Flow driver preparation API. This abstracts calling driver specific
2461 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2462 * calculates the size of memory required for device flow, allocates the memory,
2463 * initializes the device flow and returns the pointer.
2466 * This function initializes device flow structure such as dv or verbs in
2467 * struct mlx5_flow. However, it is caller's responsibility to initialize the
2468 * rest. For example, adding returning device flow to flow->dev_flow list and
2469 * setting backward reference to the flow should be done out of this function.
2470 * layers field is not filled either.
2473 * Pointer to the flow attributes.
2475 * Pointer to the list of items.
2476 * @param[in] actions
2477 * Pointer to the list of actions.
2479 * Pointer to the error structure.
2482 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
2484 static inline struct mlx5_flow *
2485 flow_drv_prepare(const struct rte_flow *flow,
2486 const struct rte_flow_attr *attr,
2487 const struct rte_flow_item items[],
2488 const struct rte_flow_action actions[],
2489 struct rte_flow_error *error)
2491 const struct mlx5_flow_driver_ops *fops;
2492 enum mlx5_flow_drv_type type = flow->drv_type;
2494 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2495 fops = flow_get_drv_ops(type);
2496 return fops->prepare(attr, items, actions, error);
2500 * Flow driver translation API. This abstracts calling driver specific
2501 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2502 * translates a generic flow into a driver flow. flow_drv_prepare() must
2506 * dev_flow->layers could be filled as a result of parsing during translation
2507 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
2508 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
2509 * flow->actions could be overwritten even though all the expanded dev_flows
2510 * have the same actions.
2513 * Pointer to the rte dev structure.
2514 * @param[in, out] dev_flow
2515 * Pointer to the mlx5 flow.
2517 * Pointer to the flow attributes.
2519 * Pointer to the list of items.
2520 * @param[in] actions
2521 * Pointer to the list of actions.
2523 * Pointer to the error structure.
2526 * 0 on success, a negative errno value otherwise and rte_errno is set.
2529 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
2530 const struct rte_flow_attr *attr,
2531 const struct rte_flow_item items[],
2532 const struct rte_flow_action actions[],
2533 struct rte_flow_error *error)
2535 const struct mlx5_flow_driver_ops *fops;
2536 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
2538 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2539 fops = flow_get_drv_ops(type);
2540 return fops->translate(dev, dev_flow, attr, items, actions, error);
2544 * Flow driver apply API. This abstracts calling driver specific functions.
2545 * Parent flow (rte_flow) should have driver type (drv_type). It applies
2546 * translated driver flows on to device. flow_drv_translate() must precede.
2549 * Pointer to Ethernet device structure.
2550 * @param[in, out] flow
2551 * Pointer to flow structure.
2553 * Pointer to error structure.
2556 * 0 on success, a negative errno value otherwise and rte_errno is set.
2559 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
2560 struct rte_flow_error *error)
2562 const struct mlx5_flow_driver_ops *fops;
2563 enum mlx5_flow_drv_type type = flow->drv_type;
2565 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2566 fops = flow_get_drv_ops(type);
2567 return fops->apply(dev, flow, error);
2571 * Flow driver remove API. This abstracts calling driver specific functions.
2572 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2573 * on device. All the resources of the flow should be freed by calling
2574 * flow_drv_destroy().
2577 * Pointer to Ethernet device.
2578 * @param[in, out] flow
2579 * Pointer to flow structure.
2582 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
2584 const struct mlx5_flow_driver_ops *fops;
2585 enum mlx5_flow_drv_type type = flow->drv_type;
2587 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2588 fops = flow_get_drv_ops(type);
2589 fops->remove(dev, flow);
2593 * Flow driver destroy API. This abstracts calling driver specific functions.
2594 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2595 * on device and releases resources of the flow.
2598 * Pointer to Ethernet device.
2599 * @param[in, out] flow
2600 * Pointer to flow structure.
2603 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
2605 const struct mlx5_flow_driver_ops *fops;
2606 enum mlx5_flow_drv_type type = flow->drv_type;
2608 flow_mreg_split_qrss_release(dev, flow);
2609 MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2610 fops = flow_get_drv_ops(type);
2611 fops->destroy(dev, flow);
2615 * Validate a flow supported by the NIC.
2617 * @see rte_flow_validate()
2621 mlx5_flow_validate(struct rte_eth_dev *dev,
2622 const struct rte_flow_attr *attr,
2623 const struct rte_flow_item items[],
2624 const struct rte_flow_action actions[],
2625 struct rte_flow_error *error)
2629 ret = flow_drv_validate(dev, attr, items, actions, true, error);
2636 * Get RSS action from the action list.
2638 * @param[in] actions
2639 * Pointer to the list of actions.
2642 * Pointer to the RSS action if exist, else return NULL.
2644 static const struct rte_flow_action_rss*
2645 flow_get_rss_action(const struct rte_flow_action actions[])
2647 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2648 switch (actions->type) {
2649 case RTE_FLOW_ACTION_TYPE_RSS:
2650 return (const struct rte_flow_action_rss *)
2660 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
2662 const struct rte_flow_item *item;
2663 unsigned int has_vlan = 0;
2665 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2666 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2672 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
2673 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
2674 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
2675 MLX5_EXPANSION_ROOT_OUTER;
2679 * Get layer flags from the prefix flow.
2681 * Some flows may be split to several subflows, the prefix subflow gets the
2682 * match items and the suffix sub flow gets the actions.
2683 * Some actions need the user defined match item flags to get the detail for
2685 * This function helps the suffix flow to get the item layer flags from prefix
2688 * @param[in] dev_flow
2689 * Pointer the created preifx subflow.
2692 * The layers get from prefix subflow.
2694 static inline uint64_t
2695 flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
2697 uint64_t layers = 0;
2699 /* If no decap actions, use the layers directly. */
2700 if (!(dev_flow->actions & MLX5_FLOW_ACTION_DECAP))
2701 return dev_flow->layers;
2702 /* Convert L3 layers with decap action. */
2703 if (dev_flow->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
2704 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2705 else if (dev_flow->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
2706 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2707 /* Convert L4 layers with decap action. */
2708 if (dev_flow->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
2709 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
2710 else if (dev_flow->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
2711 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
2716 * Get metadata split action information.
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.
2725 * @param[out] encap_idx
2726 * Pointer to the index of the encap action if exists, otherwise the last
2730 * Total number of actions.
2733 flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
2734 const struct rte_flow_action **qrss,
2737 const struct rte_flow_action_raw_encap *raw_encap;
2739 int raw_decap_idx = -1;
2742 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2743 switch (actions->type) {
2744 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2745 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2746 *encap_idx = actions_n;
2748 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
2749 raw_decap_idx = actions_n;
2751 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2752 raw_encap = actions->conf;
2753 if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
2754 *encap_idx = raw_decap_idx != -1 ?
2755 raw_decap_idx : actions_n;
2757 case RTE_FLOW_ACTION_TYPE_QUEUE:
2758 case RTE_FLOW_ACTION_TYPE_RSS:
2766 if (*encap_idx == -1)
2767 *encap_idx = actions_n;
2768 /* Count RTE_FLOW_ACTION_TYPE_END. */
2769 return actions_n + 1;
2773 * Check meter action from the action list.
2775 * @param[in] actions
2776 * Pointer to the list of actions.
2778 * Pointer to the meter exist flag.
2781 * Total number of actions.
2784 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
2790 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2791 switch (actions->type) {
2792 case RTE_FLOW_ACTION_TYPE_METER:
2800 /* Count RTE_FLOW_ACTION_TYPE_END. */
2801 return actions_n + 1;
2805 * Check if the flow should be splited due to hairpin.
2806 * The reason for the split is that in current HW we can't
2807 * support encap on Rx, so if a flow have encap we move it
2811 * Pointer to Ethernet device.
2813 * Flow rule attributes.
2814 * @param[in] actions
2815 * Associated actions (list terminated by the END action).
2818 * > 0 the number of actions and the flow should be split,
2819 * 0 when no split required.
2822 flow_check_hairpin_split(struct rte_eth_dev *dev,
2823 const struct rte_flow_attr *attr,
2824 const struct rte_flow_action actions[])
2826 int queue_action = 0;
2829 const struct rte_flow_action_queue *queue;
2830 const struct rte_flow_action_rss *rss;
2831 const struct rte_flow_action_raw_encap *raw_encap;
2835 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2836 switch (actions->type) {
2837 case RTE_FLOW_ACTION_TYPE_QUEUE:
2838 queue = actions->conf;
2841 if (mlx5_rxq_get_type(dev, queue->index) !=
2842 MLX5_RXQ_TYPE_HAIRPIN)
2847 case RTE_FLOW_ACTION_TYPE_RSS:
2848 rss = actions->conf;
2849 if (rss == NULL || rss->queue_num == 0)
2851 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
2852 MLX5_RXQ_TYPE_HAIRPIN)
2857 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2858 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2862 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2863 raw_encap = actions->conf;
2864 if (raw_encap->size >
2865 (sizeof(struct rte_flow_item_eth) +
2866 sizeof(struct rte_flow_item_ipv4)))
2875 if (encap == 1 && queue_action)
2880 /* Declare flow create/destroy prototype in advance. */
2881 static struct rte_flow *
2882 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
2883 const struct rte_flow_attr *attr,
2884 const struct rte_flow_item items[],
2885 const struct rte_flow_action actions[],
2886 bool external, struct rte_flow_error *error);
2889 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
2890 struct rte_flow *flow);
2893 * Add a flow of copying flow metadata registers in RX_CP_TBL.
2895 * As mark_id is unique, if there's already a registered flow for the mark_id,
2896 * return by increasing the reference counter of the resource. Otherwise, create
2897 * the resource (mcp_res) and flow.
2900 * - If ingress port is ANY and reg_c[1] is mark_id,
2901 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
2903 * For default flow (zero mark_id), flow is like,
2904 * - If ingress port is ANY,
2905 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
2908 * Pointer to Ethernet device.
2910 * ID of MARK action, zero means default flow for META.
2912 * Perform verbose error reporting if not NULL.
2915 * Associated resource on success, NULL otherwise and rte_errno is set.
2917 static struct mlx5_flow_mreg_copy_resource *
2918 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
2919 struct rte_flow_error *error)
2921 struct mlx5_priv *priv = dev->data->dev_private;
2922 struct rte_flow_attr attr = {
2923 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
2926 struct mlx5_rte_flow_item_tag tag_spec = {
2929 struct rte_flow_item items[] = {
2930 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
2932 struct rte_flow_action_mark ftag = {
2935 struct mlx5_flow_action_copy_mreg cp_mreg = {
2939 struct rte_flow_action_jump jump = {
2940 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
2942 struct rte_flow_action actions[] = {
2943 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
2945 struct mlx5_flow_mreg_copy_resource *mcp_res;
2948 /* Fill the register fileds in the flow. */
2949 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2953 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
2957 /* Check if already registered. */
2958 MLX5_ASSERT(priv->mreg_cp_tbl);
2959 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
2961 /* For non-default rule. */
2962 if (mark_id != MLX5_DEFAULT_COPY_ID)
2964 MLX5_ASSERT(mark_id != MLX5_DEFAULT_COPY_ID ||
2965 mcp_res->refcnt == 1);
2968 /* Provide the full width of FLAG specific value. */
2969 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
2970 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
2971 /* Build a new flow. */
2972 if (mark_id != MLX5_DEFAULT_COPY_ID) {
2973 items[0] = (struct rte_flow_item){
2974 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
2977 items[1] = (struct rte_flow_item){
2978 .type = RTE_FLOW_ITEM_TYPE_END,
2980 actions[0] = (struct rte_flow_action){
2981 .type = MLX5_RTE_FLOW_ACTION_TYPE_MARK,
2984 actions[1] = (struct rte_flow_action){
2985 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
2988 actions[2] = (struct rte_flow_action){
2989 .type = RTE_FLOW_ACTION_TYPE_JUMP,
2992 actions[3] = (struct rte_flow_action){
2993 .type = RTE_FLOW_ACTION_TYPE_END,
2996 /* Default rule, wildcard match. */
2997 attr.priority = MLX5_FLOW_PRIO_RSVD;
2998 items[0] = (struct rte_flow_item){
2999 .type = RTE_FLOW_ITEM_TYPE_END,
3001 actions[0] = (struct rte_flow_action){
3002 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3005 actions[1] = (struct rte_flow_action){
3006 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3009 actions[2] = (struct rte_flow_action){
3010 .type = RTE_FLOW_ACTION_TYPE_END,
3013 /* Build a new entry. */
3014 mcp_res = rte_zmalloc(__func__, sizeof(*mcp_res), 0);
3020 * The copy Flows are not included in any list. There
3021 * ones are referenced from other Flows and can not
3022 * be applied, removed, deleted in ardbitrary order
3023 * by list traversing.
3025 mcp_res->flow = flow_list_create(dev, NULL, &attr, items,
3026 actions, false, error);
3030 mcp_res->hlist_ent.key = mark_id;
3031 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3032 &mcp_res->hlist_ent);
3039 flow_list_destroy(dev, NULL, mcp_res->flow);
3045 * Release flow in RX_CP_TBL.
3048 * Pointer to Ethernet device.
3050 * Parent flow for wich copying is provided.
3053 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3054 struct rte_flow *flow)
3056 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3057 struct mlx5_priv *priv = dev->data->dev_private;
3059 if (!mcp_res || !priv->mreg_cp_tbl)
3061 if (flow->copy_applied) {
3062 MLX5_ASSERT(mcp_res->appcnt);
3063 flow->copy_applied = 0;
3065 if (!mcp_res->appcnt)
3066 flow_drv_remove(dev, mcp_res->flow);
3069 * We do not check availability of metadata registers here,
3070 * because copy resources are not allocated in this case.
3072 if (--mcp_res->refcnt)
3074 MLX5_ASSERT(mcp_res->flow);
3075 flow_list_destroy(dev, NULL, mcp_res->flow);
3076 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3078 flow->mreg_copy = NULL;
3082 * Start flow in RX_CP_TBL.
3085 * Pointer to Ethernet device.
3087 * Parent flow for wich copying is provided.
3090 * 0 on success, a negative errno value otherwise and rte_errno is set.
3093 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3094 struct rte_flow *flow)
3096 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3099 if (!mcp_res || flow->copy_applied)
3101 if (!mcp_res->appcnt) {
3102 ret = flow_drv_apply(dev, mcp_res->flow, NULL);
3107 flow->copy_applied = 1;
3112 * Stop flow in RX_CP_TBL.
3115 * Pointer to Ethernet device.
3117 * Parent flow for wich copying is provided.
3120 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3121 struct rte_flow *flow)
3123 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3125 if (!mcp_res || !flow->copy_applied)
3127 MLX5_ASSERT(mcp_res->appcnt);
3129 flow->copy_applied = 0;
3130 if (!mcp_res->appcnt)
3131 flow_drv_remove(dev, mcp_res->flow);
3135 * Remove the default copy action from RX_CP_TBL.
3138 * Pointer to Ethernet device.
3141 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3143 struct mlx5_flow_mreg_copy_resource *mcp_res;
3144 struct mlx5_priv *priv = dev->data->dev_private;
3146 /* Check if default flow is registered. */
3147 if (!priv->mreg_cp_tbl)
3149 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3150 MLX5_DEFAULT_COPY_ID);
3153 MLX5_ASSERT(mcp_res->flow);
3154 flow_list_destroy(dev, NULL, mcp_res->flow);
3155 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3160 * Add the default copy action in in RX_CP_TBL.
3163 * Pointer to Ethernet device.
3165 * Perform verbose error reporting if not NULL.
3168 * 0 for success, negative value otherwise and rte_errno is set.
3171 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3172 struct rte_flow_error *error)
3174 struct mlx5_priv *priv = dev->data->dev_private;
3175 struct mlx5_flow_mreg_copy_resource *mcp_res;
3177 /* Check whether extensive metadata feature is engaged. */
3178 if (!priv->config.dv_flow_en ||
3179 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3180 !mlx5_flow_ext_mreg_supported(dev) ||
3181 !priv->sh->dv_regc0_mask)
3183 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3190 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3192 * All the flow having Q/RSS action should be split by
3193 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3194 * performs the following,
3195 * - CQE->flow_tag := reg_c[1] (MARK)
3196 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3197 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3198 * but there should be a flow per each MARK ID set by MARK action.
3200 * For the aforementioned reason, if there's a MARK action in flow's action
3201 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3202 * the MARK ID to CQE's flow_tag like,
3203 * - If reg_c[1] is mark_id,
3204 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3206 * For SET_META action which stores value in reg_c[0], as the destination is
3207 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3208 * MARK ID means the default flow. The default flow looks like,
3209 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3212 * Pointer to Ethernet device.
3214 * Pointer to flow structure.
3215 * @param[in] actions
3216 * Pointer to the list of actions.
3218 * Perform verbose error reporting if not NULL.
3221 * 0 on success, negative value otherwise and rte_errno is set.
3224 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3225 struct rte_flow *flow,
3226 const struct rte_flow_action *actions,
3227 struct rte_flow_error *error)
3229 struct mlx5_priv *priv = dev->data->dev_private;
3230 struct mlx5_dev_config *config = &priv->config;
3231 struct mlx5_flow_mreg_copy_resource *mcp_res;
3232 const struct rte_flow_action_mark *mark;
3234 /* Check whether extensive metadata feature is engaged. */
3235 if (!config->dv_flow_en ||
3236 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3237 !mlx5_flow_ext_mreg_supported(dev) ||
3238 !priv->sh->dv_regc0_mask)
3240 /* Find MARK action. */
3241 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3242 switch (actions->type) {
3243 case RTE_FLOW_ACTION_TYPE_FLAG:
3244 mcp_res = flow_mreg_add_copy_action
3245 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3248 flow->mreg_copy = mcp_res;
3249 if (dev->data->dev_started) {
3251 flow->copy_applied = 1;
3254 case RTE_FLOW_ACTION_TYPE_MARK:
3255 mark = (const struct rte_flow_action_mark *)
3258 flow_mreg_add_copy_action(dev, mark->id, error);
3261 flow->mreg_copy = mcp_res;
3262 if (dev->data->dev_started) {
3264 flow->copy_applied = 1;
3274 #define MLX5_MAX_SPLIT_ACTIONS 24
3275 #define MLX5_MAX_SPLIT_ITEMS 24
3278 * Split the hairpin flow.
3279 * Since HW can't support encap on Rx we move the encap to Tx.
3280 * If the count action is after the encap then we also
3281 * move the count action. in this case the count will also measure
3285 * Pointer to Ethernet device.
3286 * @param[in] actions
3287 * Associated actions (list terminated by the END action).
3288 * @param[out] actions_rx
3290 * @param[out] actions_tx
3292 * @param[out] pattern_tx
3293 * The pattern items for the Tx flow.
3294 * @param[out] flow_id
3295 * The flow ID connected to this flow.
3301 flow_hairpin_split(struct rte_eth_dev *dev,
3302 const struct rte_flow_action actions[],
3303 struct rte_flow_action actions_rx[],
3304 struct rte_flow_action actions_tx[],
3305 struct rte_flow_item pattern_tx[],
3308 struct mlx5_priv *priv = dev->data->dev_private;
3309 const struct rte_flow_action_raw_encap *raw_encap;
3310 const struct rte_flow_action_raw_decap *raw_decap;
3311 struct mlx5_rte_flow_action_set_tag *set_tag;
3312 struct rte_flow_action *tag_action;
3313 struct mlx5_rte_flow_item_tag *tag_item;
3314 struct rte_flow_item *item;
3318 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
3319 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3320 switch (actions->type) {
3321 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3322 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3323 rte_memcpy(actions_tx, actions,
3324 sizeof(struct rte_flow_action));
3327 case RTE_FLOW_ACTION_TYPE_COUNT:
3329 rte_memcpy(actions_tx, actions,
3330 sizeof(struct rte_flow_action));
3333 rte_memcpy(actions_rx, actions,
3334 sizeof(struct rte_flow_action));
3338 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3339 raw_encap = actions->conf;
3340 if (raw_encap->size >
3341 (sizeof(struct rte_flow_item_eth) +
3342 sizeof(struct rte_flow_item_ipv4))) {
3343 memcpy(actions_tx, actions,
3344 sizeof(struct rte_flow_action));
3348 rte_memcpy(actions_rx, actions,
3349 sizeof(struct rte_flow_action));
3353 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3354 raw_decap = actions->conf;
3355 if (raw_decap->size <
3356 (sizeof(struct rte_flow_item_eth) +
3357 sizeof(struct rte_flow_item_ipv4))) {
3358 memcpy(actions_tx, actions,
3359 sizeof(struct rte_flow_action));
3362 rte_memcpy(actions_rx, actions,
3363 sizeof(struct rte_flow_action));
3368 rte_memcpy(actions_rx, actions,
3369 sizeof(struct rte_flow_action));
3374 /* Add set meta action and end action for the Rx flow. */
3375 tag_action = actions_rx;
3376 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3378 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
3380 set_tag = (void *)actions_rx;
3381 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
3382 MLX5_ASSERT(set_tag->id > REG_NONE);
3383 set_tag->data = *flow_id;
3384 tag_action->conf = set_tag;
3385 /* Create Tx item list. */
3386 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
3387 addr = (void *)&pattern_tx[2];
3389 item->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3390 tag_item = (void *)addr;
3391 tag_item->data = *flow_id;
3392 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
3393 MLX5_ASSERT(set_tag->id > REG_NONE);
3394 item->spec = tag_item;
3395 addr += sizeof(struct mlx5_rte_flow_item_tag);
3396 tag_item = (void *)addr;
3397 tag_item->data = UINT32_MAX;
3398 tag_item->id = UINT16_MAX;
3399 item->mask = tag_item;
3400 addr += sizeof(struct mlx5_rte_flow_item_tag);
3403 item->type = RTE_FLOW_ITEM_TYPE_END;
3408 * The last stage of splitting chain, just creates the subflow
3409 * without any modification.
3412 * Pointer to Ethernet device.
3414 * Parent flow structure pointer.
3415 * @param[in, out] sub_flow
3416 * Pointer to return the created subflow, may be NULL.
3417 * @param[in] prefix_layers
3418 * Prefix subflow layers, may be 0.
3420 * Flow rule attributes.
3422 * Pattern specification (list terminated by the END pattern item).
3423 * @param[in] actions
3424 * Associated actions (list terminated by the END action).
3425 * @param[in] external
3426 * This flow rule is created by request external to PMD.
3428 * Perform verbose error reporting if not NULL.
3430 * 0 on success, negative value otherwise
3433 flow_create_split_inner(struct rte_eth_dev *dev,
3434 struct rte_flow *flow,
3435 struct mlx5_flow **sub_flow,
3436 uint64_t prefix_layers,
3437 const struct rte_flow_attr *attr,
3438 const struct rte_flow_item items[],
3439 const struct rte_flow_action actions[],
3440 bool external, struct rte_flow_error *error)
3442 struct mlx5_flow *dev_flow;
3444 dev_flow = flow_drv_prepare(flow, attr, items, actions, error);
3447 dev_flow->flow = flow;
3448 dev_flow->external = external;
3449 /* Subflow object was created, we must include one in the list. */
3450 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
3452 * If dev_flow is as one of the suffix flow, some actions in suffix
3453 * flow may need some user defined item layer flags.
3456 dev_flow->layers = prefix_layers;
3458 *sub_flow = dev_flow;
3459 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
3463 * Split the meter flow.
3465 * As meter flow will split to three sub flow, other than meter
3466 * action, the other actions make sense to only meter accepts
3467 * the packet. If it need to be dropped, no other additional
3468 * actions should be take.
3470 * One kind of special action which decapsulates the L3 tunnel
3471 * header will be in the prefix sub flow, as not to take the
3472 * L3 tunnel header into account.
3475 * Pointer to Ethernet device.
3477 * Pattern specification (list terminated by the END pattern item).
3478 * @param[out] sfx_items
3479 * Suffix flow match items (list terminated by the END pattern item).
3480 * @param[in] actions
3481 * Associated actions (list terminated by the END action).
3482 * @param[out] actions_sfx
3483 * Suffix flow actions.
3484 * @param[out] actions_pre
3485 * Prefix flow actions.
3486 * @param[out] pattern_sfx
3487 * The pattern items for the suffix flow.
3488 * @param[out] tag_sfx
3489 * Pointer to suffix flow tag.
3495 flow_meter_split_prep(struct rte_eth_dev *dev,
3496 const struct rte_flow_item items[],
3497 struct rte_flow_item sfx_items[],
3498 const struct rte_flow_action actions[],
3499 struct rte_flow_action actions_sfx[],
3500 struct rte_flow_action actions_pre[])
3502 struct rte_flow_action *tag_action = NULL;
3503 struct rte_flow_item *tag_item;
3504 struct mlx5_rte_flow_action_set_tag *set_tag;
3505 struct rte_flow_error error;
3506 const struct rte_flow_action_raw_encap *raw_encap;
3507 const struct rte_flow_action_raw_decap *raw_decap;
3508 struct mlx5_rte_flow_item_tag *tag_spec;
3509 struct mlx5_rte_flow_item_tag *tag_mask;
3511 bool copy_vlan = false;
3513 /* Prepare the actions for prefix and suffix flow. */
3514 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3515 struct rte_flow_action **action_cur = NULL;
3517 switch (actions->type) {
3518 case RTE_FLOW_ACTION_TYPE_METER:
3519 /* Add the extra tag action first. */
3520 tag_action = actions_pre;
3521 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3523 action_cur = &actions_pre;
3525 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3526 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3527 action_cur = &actions_pre;
3529 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3530 raw_encap = actions->conf;
3531 if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
3532 action_cur = &actions_pre;
3534 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3535 raw_decap = actions->conf;
3536 if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3537 action_cur = &actions_pre;
3539 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3540 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3547 action_cur = &actions_sfx;
3548 memcpy(*action_cur, actions, sizeof(struct rte_flow_action));
3551 /* Add end action to the actions. */
3552 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
3553 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
3556 set_tag = (void *)actions_pre;
3557 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3559 * Get the id from the qrss_pool to make qrss share the id with meter.
3561 tag_id = flow_qrss_get_id(dev);
3562 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
3564 tag_action->conf = set_tag;
3565 /* Prepare the suffix subflow items. */
3566 tag_item = sfx_items++;
3567 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3568 int item_type = items->type;
3570 switch (item_type) {
3571 case RTE_FLOW_ITEM_TYPE_PORT_ID:
3572 memcpy(sfx_items, items, sizeof(*sfx_items));
3575 case RTE_FLOW_ITEM_TYPE_VLAN:
3577 memcpy(sfx_items, items, sizeof(*sfx_items));
3579 * Convert to internal match item, it is used
3580 * for vlan push and set vid.
3582 sfx_items->type = MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
3590 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
3592 tag_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
3593 tag_spec->data = tag_id << MLX5_MTR_COLOR_BITS;
3594 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3595 tag_mask = tag_spec + 1;
3596 tag_mask->data = 0xffffff00;
3597 tag_item->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3598 tag_item->spec = tag_spec;
3599 tag_item->last = NULL;
3600 tag_item->mask = tag_mask;
3605 * Split action list having QUEUE/RSS for metadata register copy.
3607 * Once Q/RSS action is detected in user's action list, the flow action
3608 * should be split in order to copy metadata registers, which will happen in
3610 * - CQE->flow_tag := reg_c[1] (MARK)
3611 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3612 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
3613 * This is because the last action of each flow must be a terminal action
3614 * (QUEUE, RSS or DROP).
3616 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
3617 * stored and kept in the mlx5_flow structure per each sub_flow.
3619 * The Q/RSS action is replaced with,
3620 * - SET_TAG, setting the allocated flow ID to reg_c[2].
3621 * And the following JUMP action is added at the end,
3622 * - JUMP, to RX_CP_TBL.
3624 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
3625 * flow_create_split_metadata() routine. The flow will look like,
3626 * - If flow ID matches (reg_c[2]), perform Q/RSS.
3629 * Pointer to Ethernet device.
3630 * @param[out] split_actions
3631 * Pointer to store split actions to jump to CP_TBL.
3632 * @param[in] actions
3633 * Pointer to the list of original flow actions.
3635 * Pointer to the Q/RSS action.
3636 * @param[in] actions_n
3637 * Number of original actions.
3639 * Perform verbose error reporting if not NULL.
3642 * non-zero unique flow_id on success, otherwise 0 and
3643 * error/rte_error are set.
3646 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
3647 struct rte_flow_action *split_actions,
3648 const struct rte_flow_action *actions,
3649 const struct rte_flow_action *qrss,
3650 int actions_n, struct rte_flow_error *error)
3652 struct mlx5_rte_flow_action_set_tag *set_tag;
3653 struct rte_flow_action_jump *jump;
3654 const int qrss_idx = qrss - actions;
3655 uint32_t flow_id = 0;
3659 * Given actions will be split
3660 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
3661 * - Add jump to mreg CP_TBL.
3662 * As a result, there will be one more action.
3665 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
3666 set_tag = (void *)(split_actions + actions_n);
3668 * If tag action is not set to void(it means we are not the meter
3669 * suffix flow), add the tag action. Since meter suffix flow already
3670 * has the tag added.
3672 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
3674 * Allocate the new subflow ID. This one is unique within
3675 * device and not shared with representors. Otherwise,
3676 * we would have to resolve multi-thread access synch
3677 * issue. Each flow on the shared device is appended
3678 * with source vport identifier, so the resulting
3679 * flows will be unique in the shared (by master and
3680 * representors) domain even if they have coinciding
3683 flow_id = flow_qrss_get_id(dev);
3685 return rte_flow_error_set(error, ENOMEM,
3686 RTE_FLOW_ERROR_TYPE_ACTION,
3687 NULL, "can't allocate id "
3688 "for split Q/RSS subflow");
3689 /* Internal SET_TAG action to set flow ID. */
3690 *set_tag = (struct mlx5_rte_flow_action_set_tag){
3693 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
3697 /* Construct new actions array. */
3698 /* Replace QUEUE/RSS action. */
3699 split_actions[qrss_idx] = (struct rte_flow_action){
3700 .type = MLX5_RTE_FLOW_ACTION_TYPE_TAG,
3704 /* JUMP action to jump to mreg copy table (CP_TBL). */
3705 jump = (void *)(set_tag + 1);
3706 *jump = (struct rte_flow_action_jump){
3707 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3709 split_actions[actions_n - 2] = (struct rte_flow_action){
3710 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3713 split_actions[actions_n - 1] = (struct rte_flow_action){
3714 .type = RTE_FLOW_ACTION_TYPE_END,
3720 * Extend the given action list for Tx metadata copy.
3722 * Copy the given action list to the ext_actions and add flow metadata register
3723 * copy action in order to copy reg_a set by WQE to reg_c[0].
3725 * @param[out] ext_actions
3726 * Pointer to the extended action list.
3727 * @param[in] actions
3728 * Pointer to the list of actions.
3729 * @param[in] actions_n
3730 * Number of actions in the list.
3732 * Perform verbose error reporting if not NULL.
3733 * @param[in] encap_idx
3734 * The encap action inndex.
3737 * 0 on success, negative value otherwise
3740 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
3741 struct rte_flow_action *ext_actions,
3742 const struct rte_flow_action *actions,
3743 int actions_n, struct rte_flow_error *error,
3746 struct mlx5_flow_action_copy_mreg *cp_mreg =
3747 (struct mlx5_flow_action_copy_mreg *)
3748 (ext_actions + actions_n + 1);
3751 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3755 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
3760 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
3761 if (encap_idx == actions_n - 1) {
3762 ext_actions[actions_n - 1] = (struct rte_flow_action){
3763 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3766 ext_actions[actions_n] = (struct rte_flow_action){
3767 .type = RTE_FLOW_ACTION_TYPE_END,
3770 ext_actions[encap_idx] = (struct rte_flow_action){
3771 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3774 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
3775 sizeof(*ext_actions) * (actions_n - encap_idx));
3781 * The splitting for metadata feature.
3783 * - Q/RSS action on NIC Rx should be split in order to pass by
3784 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3785 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3787 * - All the actions on NIC Tx should have a mreg copy action to
3788 * copy reg_a from WQE to reg_c[0].
3791 * Pointer to Ethernet device.
3793 * Parent flow structure pointer.
3794 * @param[in] prefix_layers
3795 * Prefix flow layer flags.
3797 * Flow rule attributes.
3799 * Pattern specification (list terminated by the END pattern item).
3800 * @param[in] actions
3801 * Associated actions (list terminated by the END action).
3802 * @param[in] external
3803 * This flow rule is created by request external to PMD.
3805 * Perform verbose error reporting if not NULL.
3807 * 0 on success, negative value otherwise
3810 flow_create_split_metadata(struct rte_eth_dev *dev,
3811 struct rte_flow *flow,
3812 uint64_t prefix_layers,
3813 const struct rte_flow_attr *attr,
3814 const struct rte_flow_item items[],
3815 const struct rte_flow_action actions[],
3816 bool external, struct rte_flow_error *error)
3818 struct mlx5_priv *priv = dev->data->dev_private;
3819 struct mlx5_dev_config *config = &priv->config;
3820 const struct rte_flow_action *qrss = NULL;
3821 struct rte_flow_action *ext_actions = NULL;
3822 struct mlx5_flow *dev_flow = NULL;
3823 uint32_t qrss_id = 0;
3830 /* Check whether extensive metadata feature is engaged. */
3831 if (!config->dv_flow_en ||
3832 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3833 !mlx5_flow_ext_mreg_supported(dev))
3834 return flow_create_split_inner(dev, flow, NULL, prefix_layers,
3835 attr, items, actions, external,
3837 actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
3840 /* Exclude hairpin flows from splitting. */
3841 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
3842 const struct rte_flow_action_queue *queue;
3845 if (mlx5_rxq_get_type(dev, queue->index) ==
3846 MLX5_RXQ_TYPE_HAIRPIN)
3848 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
3849 const struct rte_flow_action_rss *rss;
3852 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
3853 MLX5_RXQ_TYPE_HAIRPIN)
3858 /* Check if it is in meter suffix table. */
3859 mtr_sfx = attr->group == (attr->transfer ?
3860 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
3861 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
3863 * Q/RSS action on NIC Rx should be split in order to pass by
3864 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3865 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3867 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3868 sizeof(struct rte_flow_action_set_tag) +
3869 sizeof(struct rte_flow_action_jump);
3870 ext_actions = rte_zmalloc(__func__, act_size, 0);
3872 return rte_flow_error_set(error, ENOMEM,
3873 RTE_FLOW_ERROR_TYPE_ACTION,
3874 NULL, "no memory to split "
3877 * If we are the suffix flow of meter, tag already exist.
3878 * Set the tag action to void.
3881 ext_actions[qrss - actions].type =
3882 RTE_FLOW_ACTION_TYPE_VOID;
3884 ext_actions[qrss - actions].type =
3885 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3887 * Create the new actions list with removed Q/RSS action
3888 * and appended set tag and jump to register copy table
3889 * (RX_CP_TBL). We should preallocate unique tag ID here
3890 * in advance, because it is needed for set tag action.
3892 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
3893 qrss, actions_n, error);
3894 if (!mtr_sfx && !qrss_id) {
3898 } else if (attr->egress && !attr->transfer) {
3900 * All the actions on NIC Tx should have a metadata register
3901 * copy action to copy reg_a from WQE to reg_c[meta]
3903 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3904 sizeof(struct mlx5_flow_action_copy_mreg);
3905 ext_actions = rte_zmalloc(__func__, act_size, 0);
3907 return rte_flow_error_set(error, ENOMEM,
3908 RTE_FLOW_ERROR_TYPE_ACTION,
3909 NULL, "no memory to split "
3911 /* Create the action list appended with copy register. */
3912 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
3913 actions_n, error, encap_idx);
3917 /* Add the unmodified original or prefix subflow. */
3918 ret = flow_create_split_inner(dev, flow, &dev_flow, prefix_layers, attr,
3919 items, ext_actions ? ext_actions :
3920 actions, external, error);
3923 MLX5_ASSERT(dev_flow);
3925 const struct rte_flow_attr q_attr = {
3926 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3929 /* Internal PMD action to set register. */
3930 struct mlx5_rte_flow_item_tag q_tag_spec = {
3934 struct rte_flow_item q_items[] = {
3936 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3937 .spec = &q_tag_spec,
3942 .type = RTE_FLOW_ITEM_TYPE_END,
3945 struct rte_flow_action q_actions[] = {
3951 .type = RTE_FLOW_ACTION_TYPE_END,
3954 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
3957 * Configure the tag item only if there is no meter subflow.
3958 * Since tag is already marked in the meter suffix subflow
3959 * we can just use the meter suffix items as is.
3962 /* Not meter subflow. */
3963 MLX5_ASSERT(!mtr_sfx);
3965 * Put unique id in prefix flow due to it is destroyed
3966 * after suffix flow and id will be freed after there
3967 * is no actual flows with this id and identifier
3968 * reallocation becomes possible (for example, for
3969 * other flows in other threads).
3971 dev_flow->qrss_id = qrss_id;
3973 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
3977 q_tag_spec.id = ret;
3980 /* Add suffix subflow to execute Q/RSS. */
3981 ret = flow_create_split_inner(dev, flow, &dev_flow, layers,
3982 &q_attr, mtr_sfx ? items :
3987 MLX5_ASSERT(dev_flow);
3992 * We do not destroy the partially created sub_flows in case of error.
3993 * These ones are included into parent flow list and will be destroyed
3994 * by flow_drv_destroy.
3996 flow_qrss_free_id(dev, qrss_id);
3997 rte_free(ext_actions);
4002 * The splitting for meter feature.
4004 * - The meter flow will be split to two flows as prefix and
4005 * suffix flow. The packets make sense only it pass the prefix
4008 * - Reg_C_5 is used for the packet to match betweend prefix and
4012 * Pointer to Ethernet device.
4014 * Parent flow structure pointer.
4016 * Flow rule attributes.
4018 * Pattern specification (list terminated by the END pattern item).
4019 * @param[in] actions
4020 * Associated actions (list terminated by the END action).
4021 * @param[in] external
4022 * This flow rule is created by request external to PMD.
4024 * Perform verbose error reporting if not NULL.
4026 * 0 on success, negative value otherwise
4029 flow_create_split_meter(struct rte_eth_dev *dev,
4030 struct rte_flow *flow,
4031 const struct rte_flow_attr *attr,
4032 const struct rte_flow_item items[],
4033 const struct rte_flow_action actions[],
4034 bool external, struct rte_flow_error *error)
4036 struct mlx5_priv *priv = dev->data->dev_private;
4037 struct rte_flow_action *sfx_actions = NULL;
4038 struct rte_flow_action *pre_actions = NULL;
4039 struct rte_flow_item *sfx_items = NULL;
4040 struct mlx5_flow *dev_flow = NULL;
4041 struct rte_flow_attr sfx_attr = *attr;
4043 uint32_t mtr_tag_id = 0;
4050 actions_n = flow_check_meter_action(actions, &mtr);
4052 /* The five prefix actions: meter, decap, encap, tag, end. */
4053 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
4054 sizeof(struct mlx5_rte_flow_action_set_tag);
4055 /* tag, vlan, port id, end. */
4056 #define METER_SUFFIX_ITEM 4
4057 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
4058 sizeof(struct mlx5_rte_flow_item_tag) * 2;
4059 sfx_actions = rte_zmalloc(__func__, (act_size + item_size), 0);
4061 return rte_flow_error_set(error, ENOMEM,
4062 RTE_FLOW_ERROR_TYPE_ACTION,
4063 NULL, "no memory to split "
4065 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4067 pre_actions = sfx_actions + actions_n;
4068 mtr_tag_id = flow_meter_split_prep(dev, items, sfx_items,
4069 actions, sfx_actions,
4075 /* Add the prefix subflow. */
4076 ret = flow_create_split_inner(dev, flow, &dev_flow, 0, attr,
4077 items, pre_actions, external,
4083 dev_flow->mtr_flow_id = mtr_tag_id;
4084 /* Setting the sfx group atrr. */
4085 sfx_attr.group = sfx_attr.transfer ?
4086 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4087 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4089 /* Add the prefix subflow. */
4090 ret = flow_create_split_metadata(dev, flow, dev_flow ?
4091 flow_get_prefix_layer_flags(dev_flow) :
4093 sfx_items ? sfx_items : items,
4094 sfx_actions ? sfx_actions : actions,
4098 rte_free(sfx_actions);
4103 * Split the flow to subflow set. The splitters might be linked
4104 * in the chain, like this:
4105 * flow_create_split_outer() calls:
4106 * flow_create_split_meter() calls:
4107 * flow_create_split_metadata(meter_subflow_0) calls:
4108 * flow_create_split_inner(metadata_subflow_0)
4109 * flow_create_split_inner(metadata_subflow_1)
4110 * flow_create_split_inner(metadata_subflow_2)
4111 * flow_create_split_metadata(meter_subflow_1) calls:
4112 * flow_create_split_inner(metadata_subflow_0)
4113 * flow_create_split_inner(metadata_subflow_1)
4114 * flow_create_split_inner(metadata_subflow_2)
4116 * This provide flexible way to add new levels of flow splitting.
4117 * The all of successfully created subflows are included to the
4118 * parent flow dev_flow list.
4121 * Pointer to Ethernet device.
4123 * Parent flow structure pointer.
4125 * Flow rule attributes.
4127 * Pattern specification (list terminated by the END pattern item).
4128 * @param[in] actions
4129 * Associated actions (list terminated by the END action).
4130 * @param[in] external
4131 * This flow rule is created by request external to PMD.
4133 * Perform verbose error reporting if not NULL.
4135 * 0 on success, negative value otherwise
4138 flow_create_split_outer(struct rte_eth_dev *dev,
4139 struct rte_flow *flow,
4140 const struct rte_flow_attr *attr,
4141 const struct rte_flow_item items[],
4142 const struct rte_flow_action actions[],
4143 bool external, struct rte_flow_error *error)
4147 ret = flow_create_split_meter(dev, flow, attr, items,
4148 actions, external, error);
4149 MLX5_ASSERT(ret <= 0);
4154 * Create a flow and add it to @p list.
4157 * Pointer to Ethernet device.
4159 * Pointer to a TAILQ flow list. If this parameter NULL,
4160 * no list insertion occurred, flow is just created,
4161 * this is caller's responsibility to track the
4164 * Flow rule attributes.
4166 * Pattern specification (list terminated by the END pattern item).
4167 * @param[in] actions
4168 * Associated actions (list terminated by the END action).
4169 * @param[in] external
4170 * This flow rule is created by request external to PMD.
4172 * Perform verbose error reporting if not NULL.
4175 * A flow on success, NULL otherwise and rte_errno is set.
4177 static struct rte_flow *
4178 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
4179 const struct rte_flow_attr *attr,
4180 const struct rte_flow_item items[],
4181 const struct rte_flow_action actions[],
4182 bool external, struct rte_flow_error *error)
4184 struct mlx5_priv *priv = dev->data->dev_private;
4185 struct rte_flow *flow = NULL;
4186 struct mlx5_flow *dev_flow;
4187 const struct rte_flow_action_rss *rss;
4189 struct rte_flow_expand_rss buf;
4190 uint8_t buffer[2048];
4193 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4194 uint8_t buffer[2048];
4197 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4198 uint8_t buffer[2048];
4199 } actions_hairpin_tx;
4201 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
4202 uint8_t buffer[2048];
4204 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
4205 const struct rte_flow_action *p_actions_rx = actions;
4208 int hairpin_flow = 0;
4209 uint32_t hairpin_id = 0;
4210 struct rte_flow_attr attr_tx = { .priority = 0 };
4211 int ret = flow_drv_validate(dev, attr, items, p_actions_rx, external,
4216 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4217 if (hairpin_flow > 0) {
4218 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
4222 flow_hairpin_split(dev, actions, actions_rx.actions,
4223 actions_hairpin_tx.actions, items_tx.items,
4225 p_actions_rx = actions_rx.actions;
4227 flow_size = sizeof(struct rte_flow);
4228 rss = flow_get_rss_action(p_actions_rx);
4230 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
4233 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
4234 flow = rte_calloc(__func__, 1, flow_size, 0);
4237 goto error_before_flow;
4239 flow->drv_type = flow_get_drv_type(dev, attr);
4240 if (hairpin_id != 0)
4241 flow->hairpin_flow_id = hairpin_id;
4242 MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
4243 flow->drv_type < MLX5_FLOW_TYPE_MAX);
4244 flow->rss.queue = (void *)(flow + 1);
4247 * The following information is required by
4248 * mlx5_flow_hashfields_adjust() in advance.
4250 flow->rss.level = rss->level;
4251 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
4252 flow->rss.types = !rss->types ? ETH_RSS_IP : rss->types;
4254 LIST_INIT(&flow->dev_flows);
4255 if (rss && rss->types) {
4256 unsigned int graph_root;
4258 graph_root = find_graph_root(items, rss->level);
4259 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
4261 mlx5_support_expansion,
4263 MLX5_ASSERT(ret > 0 &&
4264 (unsigned int)ret < sizeof(expand_buffer.buffer));
4267 buf->entry[0].pattern = (void *)(uintptr_t)items;
4269 for (i = 0; i < buf->entries; ++i) {
4271 * The splitter may create multiple dev_flows,
4272 * depending on configuration. In the simplest
4273 * case it just creates unmodified original flow.
4275 ret = flow_create_split_outer(dev, flow, attr,
4276 buf->entry[i].pattern,
4277 p_actions_rx, external,
4282 /* Create the tx flow. */
4284 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
4285 attr_tx.ingress = 0;
4287 dev_flow = flow_drv_prepare(flow, &attr_tx, items_tx.items,
4288 actions_hairpin_tx.actions, error);
4291 dev_flow->flow = flow;
4292 dev_flow->external = 0;
4293 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
4294 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
4296 actions_hairpin_tx.actions, error);
4301 * Update the metadata register copy table. If extensive
4302 * metadata feature is enabled and registers are supported
4303 * we might create the extra rte_flow for each unique
4304 * MARK/FLAG action ID.
4306 * The table is updated for ingress Flows only, because
4307 * the egress Flows belong to the different device and
4308 * copy table should be updated in peer NIC Rx domain.
4310 if (attr->ingress &&
4311 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
4312 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
4316 if (dev->data->dev_started) {
4317 ret = flow_drv_apply(dev, flow, error);
4322 TAILQ_INSERT_TAIL(list, flow, next);
4323 flow_rxq_flags_set(dev, flow);
4327 mlx5_flow_id_release(priv->sh->flow_id_pool,
4332 flow_mreg_del_copy_action(dev, flow);
4333 ret = rte_errno; /* Save rte_errno before cleanup. */
4334 if (flow->hairpin_flow_id)
4335 mlx5_flow_id_release(priv->sh->flow_id_pool,
4336 flow->hairpin_flow_id);
4338 flow_drv_destroy(dev, flow);
4340 rte_errno = ret; /* Restore rte_errno. */
4345 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
4346 * incoming packets to table 1.
4348 * Other flow rules, requested for group n, will be created in
4349 * e-switch table n+1.
4350 * Jump action to e-switch group n will be created to group n+1.
4352 * Used when working in switchdev mode, to utilise advantages of table 1
4356 * Pointer to Ethernet device.
4359 * Pointer to flow on success, NULL otherwise and rte_errno is set.
4362 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
4364 const struct rte_flow_attr attr = {
4371 const struct rte_flow_item pattern = {
4372 .type = RTE_FLOW_ITEM_TYPE_END,
4374 struct rte_flow_action_jump jump = {
4377 const struct rte_flow_action actions[] = {
4379 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4383 .type = RTE_FLOW_ACTION_TYPE_END,
4386 struct mlx5_priv *priv = dev->data->dev_private;
4387 struct rte_flow_error error;
4389 return flow_list_create(dev, &priv->ctrl_flows, &attr, &pattern,
4390 actions, false, &error);
4396 * @see rte_flow_create()
4400 mlx5_flow_create(struct rte_eth_dev *dev,
4401 const struct rte_flow_attr *attr,
4402 const struct rte_flow_item items[],
4403 const struct rte_flow_action actions[],
4404 struct rte_flow_error *error)
4406 struct mlx5_priv *priv = dev->data->dev_private;
4408 return flow_list_create(dev, &priv->flows,
4409 attr, items, actions, true, error);
4413 * Destroy a flow in a list.
4416 * Pointer to Ethernet device.
4418 * Pointer to a TAILQ flow list. If this parameter NULL,
4419 * there is no flow removal from the list.
4424 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
4425 struct rte_flow *flow)
4427 struct mlx5_priv *priv = dev->data->dev_private;
4430 * Update RX queue flags only if port is started, otherwise it is
4433 if (dev->data->dev_started)
4434 flow_rxq_flags_trim(dev, flow);
4435 if (flow->hairpin_flow_id)
4436 mlx5_flow_id_release(priv->sh->flow_id_pool,
4437 flow->hairpin_flow_id);
4438 flow_drv_destroy(dev, flow);
4440 TAILQ_REMOVE(list, flow, next);
4441 flow_mreg_del_copy_action(dev, flow);
4442 rte_free(flow->fdir);
4447 * Destroy all flows.
4450 * Pointer to Ethernet device.
4452 * Pointer to a TAILQ flow list.
4454 * If flushing is called avtively.
4457 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list,
4460 uint32_t num_flushed = 0;
4462 while (!TAILQ_EMPTY(list)) {
4463 struct rte_flow *flow;
4465 flow = TAILQ_FIRST(list);
4466 flow_list_destroy(dev, list, flow);
4470 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
4471 dev->data->port_id, num_flushed);
4479 * Pointer to Ethernet device.
4481 * Pointer to a TAILQ flow list.
4484 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
4486 struct rte_flow *flow;
4488 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next) {
4489 flow_drv_remove(dev, flow);
4490 flow_mreg_stop_copy_action(dev, flow);
4492 flow_mreg_del_default_copy_action(dev);
4493 flow_rxq_flags_clear(dev);
4500 * Pointer to Ethernet device.
4502 * Pointer to a TAILQ flow list.
4505 * 0 on success, a negative errno value otherwise and rte_errno is set.
4508 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
4510 struct rte_flow *flow;
4511 struct rte_flow_error error;
4514 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4515 ret = flow_mreg_add_default_copy_action(dev, &error);
4518 /* Apply Flows created by application. */
4519 TAILQ_FOREACH(flow, list, next) {
4520 ret = flow_mreg_start_copy_action(dev, flow);
4523 ret = flow_drv_apply(dev, flow, &error);
4526 flow_rxq_flags_set(dev, flow);
4530 ret = rte_errno; /* Save rte_errno before cleanup. */
4531 mlx5_flow_stop(dev, list);
4532 rte_errno = ret; /* Restore rte_errno. */
4537 * Stop all default actions for flows.
4540 * Pointer to Ethernet device.
4542 * Pointer to a TAILQ flow list.
4545 mlx5_flow_stop_default(struct rte_eth_dev *dev)
4547 flow_mreg_del_default_copy_action(dev);
4551 * Start all default actions for flows.
4554 * Pointer to Ethernet device.
4556 * 0 on success, a negative errno value otherwise and rte_errno is set.
4559 mlx5_flow_start_default(struct rte_eth_dev *dev)
4561 struct rte_flow_error error;
4563 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4564 return flow_mreg_add_default_copy_action(dev, &error);
4568 * Verify the flow list is empty
4571 * Pointer to Ethernet device.
4573 * @return the number of flows not released.
4576 mlx5_flow_verify(struct rte_eth_dev *dev)
4578 struct mlx5_priv *priv = dev->data->dev_private;
4579 struct rte_flow *flow;
4582 TAILQ_FOREACH(flow, &priv->flows, next) {
4583 DRV_LOG(DEBUG, "port %u flow %p still referenced",
4584 dev->data->port_id, (void *)flow);
4591 * Enable default hairpin egress flow.
4594 * Pointer to Ethernet device.
4599 * 0 on success, a negative errno value otherwise and rte_errno is set.
4602 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
4605 struct mlx5_priv *priv = dev->data->dev_private;
4606 const struct rte_flow_attr attr = {
4610 struct mlx5_rte_flow_item_tx_queue queue_spec = {
4613 struct mlx5_rte_flow_item_tx_queue queue_mask = {
4614 .queue = UINT32_MAX,
4616 struct rte_flow_item items[] = {
4618 .type = MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
4619 .spec = &queue_spec,
4621 .mask = &queue_mask,
4624 .type = RTE_FLOW_ITEM_TYPE_END,
4627 struct rte_flow_action_jump jump = {
4628 .group = MLX5_HAIRPIN_TX_TABLE,
4630 struct rte_flow_action actions[2];
4631 struct rte_flow *flow;
4632 struct rte_flow_error error;
4634 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
4635 actions[0].conf = &jump;
4636 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
4637 flow = flow_list_create(dev, &priv->ctrl_flows,
4638 &attr, items, actions, false, &error);
4641 "Failed to create ctrl flow: rte_errno(%d),"
4642 " type(%d), message(%s)",
4643 rte_errno, error.type,
4644 error.message ? error.message : " (no stated reason)");
4651 * Enable a control flow configured from the control plane.
4654 * Pointer to Ethernet device.
4656 * An Ethernet flow spec to apply.
4658 * An Ethernet flow mask to apply.
4660 * A VLAN flow spec to apply.
4662 * A VLAN flow mask to apply.
4665 * 0 on success, a negative errno value otherwise and rte_errno is set.
4668 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
4669 struct rte_flow_item_eth *eth_spec,
4670 struct rte_flow_item_eth *eth_mask,
4671 struct rte_flow_item_vlan *vlan_spec,
4672 struct rte_flow_item_vlan *vlan_mask)
4674 struct mlx5_priv *priv = dev->data->dev_private;
4675 const struct rte_flow_attr attr = {
4677 .priority = MLX5_FLOW_PRIO_RSVD,
4679 struct rte_flow_item items[] = {
4681 .type = RTE_FLOW_ITEM_TYPE_ETH,
4687 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
4688 RTE_FLOW_ITEM_TYPE_END,
4694 .type = RTE_FLOW_ITEM_TYPE_END,
4697 uint16_t queue[priv->reta_idx_n];
4698 struct rte_flow_action_rss action_rss = {
4699 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4701 .types = priv->rss_conf.rss_hf,
4702 .key_len = priv->rss_conf.rss_key_len,
4703 .queue_num = priv->reta_idx_n,
4704 .key = priv->rss_conf.rss_key,
4707 struct rte_flow_action actions[] = {
4709 .type = RTE_FLOW_ACTION_TYPE_RSS,
4710 .conf = &action_rss,
4713 .type = RTE_FLOW_ACTION_TYPE_END,
4716 struct rte_flow *flow;
4717 struct rte_flow_error error;
4720 if (!priv->reta_idx_n || !priv->rxqs_n) {
4723 for (i = 0; i != priv->reta_idx_n; ++i)
4724 queue[i] = (*priv->reta_idx)[i];
4725 flow = flow_list_create(dev, &priv->ctrl_flows,
4726 &attr, items, actions, false, &error);
4733 * Enable a flow control configured from the control plane.
4736 * Pointer to Ethernet device.
4738 * An Ethernet flow spec to apply.
4740 * An Ethernet flow mask to apply.
4743 * 0 on success, a negative errno value otherwise and rte_errno is set.
4746 mlx5_ctrl_flow(struct rte_eth_dev *dev,
4747 struct rte_flow_item_eth *eth_spec,
4748 struct rte_flow_item_eth *eth_mask)
4750 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
4756 * @see rte_flow_destroy()
4760 mlx5_flow_destroy(struct rte_eth_dev *dev,
4761 struct rte_flow *flow,
4762 struct rte_flow_error *error __rte_unused)
4764 struct mlx5_priv *priv = dev->data->dev_private;
4766 flow_list_destroy(dev, &priv->flows, flow);
4771 * Destroy all flows.
4773 * @see rte_flow_flush()
4777 mlx5_flow_flush(struct rte_eth_dev *dev,
4778 struct rte_flow_error *error __rte_unused)
4780 struct mlx5_priv *priv = dev->data->dev_private;
4782 mlx5_flow_list_flush(dev, &priv->flows, false);
4789 * @see rte_flow_isolate()
4793 mlx5_flow_isolate(struct rte_eth_dev *dev,
4795 struct rte_flow_error *error)
4797 struct mlx5_priv *priv = dev->data->dev_private;
4799 if (dev->data->dev_started) {
4800 rte_flow_error_set(error, EBUSY,
4801 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4803 "port must be stopped first");
4806 priv->isolated = !!enable;
4808 dev->dev_ops = &mlx5_dev_ops_isolate;
4810 dev->dev_ops = &mlx5_dev_ops;
4817 * @see rte_flow_query()
4821 flow_drv_query(struct rte_eth_dev *dev,
4822 struct rte_flow *flow,
4823 const struct rte_flow_action *actions,
4825 struct rte_flow_error *error)
4827 const struct mlx5_flow_driver_ops *fops;
4828 enum mlx5_flow_drv_type ftype = flow->drv_type;
4830 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
4831 fops = flow_get_drv_ops(ftype);
4833 return fops->query(dev, flow, actions, data, error);
4839 * @see rte_flow_query()
4843 mlx5_flow_query(struct rte_eth_dev *dev,
4844 struct rte_flow *flow,
4845 const struct rte_flow_action *actions,
4847 struct rte_flow_error *error)
4851 ret = flow_drv_query(dev, flow, actions, data, error);
4858 * Convert a flow director filter to a generic flow.
4861 * Pointer to Ethernet device.
4862 * @param fdir_filter
4863 * Flow director filter to add.
4865 * Generic flow parameters structure.
4868 * 0 on success, a negative errno value otherwise and rte_errno is set.
4871 flow_fdir_filter_convert(struct rte_eth_dev *dev,
4872 const struct rte_eth_fdir_filter *fdir_filter,
4873 struct mlx5_fdir *attributes)
4875 struct mlx5_priv *priv = dev->data->dev_private;
4876 const struct rte_eth_fdir_input *input = &fdir_filter->input;
4877 const struct rte_eth_fdir_masks *mask =
4878 &dev->data->dev_conf.fdir_conf.mask;
4880 /* Validate queue number. */
4881 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
4882 DRV_LOG(ERR, "port %u invalid queue number %d",
4883 dev->data->port_id, fdir_filter->action.rx_queue);
4887 attributes->attr.ingress = 1;
4888 attributes->items[0] = (struct rte_flow_item) {
4889 .type = RTE_FLOW_ITEM_TYPE_ETH,
4890 .spec = &attributes->l2,
4891 .mask = &attributes->l2_mask,
4893 switch (fdir_filter->action.behavior) {
4894 case RTE_ETH_FDIR_ACCEPT:
4895 attributes->actions[0] = (struct rte_flow_action){
4896 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
4897 .conf = &attributes->queue,
4900 case RTE_ETH_FDIR_REJECT:
4901 attributes->actions[0] = (struct rte_flow_action){
4902 .type = RTE_FLOW_ACTION_TYPE_DROP,
4906 DRV_LOG(ERR, "port %u invalid behavior %d",
4908 fdir_filter->action.behavior);
4909 rte_errno = ENOTSUP;
4912 attributes->queue.index = fdir_filter->action.rx_queue;
4914 switch (fdir_filter->input.flow_type) {
4915 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4916 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4917 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
4918 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
4919 .src_addr = input->flow.ip4_flow.src_ip,
4920 .dst_addr = input->flow.ip4_flow.dst_ip,
4921 .time_to_live = input->flow.ip4_flow.ttl,
4922 .type_of_service = input->flow.ip4_flow.tos,
4924 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
4925 .src_addr = mask->ipv4_mask.src_ip,
4926 .dst_addr = mask->ipv4_mask.dst_ip,
4927 .time_to_live = mask->ipv4_mask.ttl,
4928 .type_of_service = mask->ipv4_mask.tos,
4929 .next_proto_id = mask->ipv4_mask.proto,
4931 attributes->items[1] = (struct rte_flow_item){
4932 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4933 .spec = &attributes->l3,
4934 .mask = &attributes->l3_mask,
4937 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
4938 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
4939 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
4940 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
4941 .hop_limits = input->flow.ipv6_flow.hop_limits,
4942 .proto = input->flow.ipv6_flow.proto,
4945 memcpy(attributes->l3.ipv6.hdr.src_addr,
4946 input->flow.ipv6_flow.src_ip,
4947 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4948 memcpy(attributes->l3.ipv6.hdr.dst_addr,
4949 input->flow.ipv6_flow.dst_ip,
4950 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4951 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
4952 mask->ipv6_mask.src_ip,
4953 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4954 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
4955 mask->ipv6_mask.dst_ip,
4956 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4957 attributes->items[1] = (struct rte_flow_item){
4958 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4959 .spec = &attributes->l3,
4960 .mask = &attributes->l3_mask,
4964 DRV_LOG(ERR, "port %u invalid flow type%d",
4965 dev->data->port_id, fdir_filter->input.flow_type);
4966 rte_errno = ENOTSUP;
4970 switch (fdir_filter->input.flow_type) {
4971 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4972 attributes->l4.udp.hdr = (struct rte_udp_hdr){
4973 .src_port = input->flow.udp4_flow.src_port,
4974 .dst_port = input->flow.udp4_flow.dst_port,
4976 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
4977 .src_port = mask->src_port_mask,
4978 .dst_port = mask->dst_port_mask,
4980 attributes->items[2] = (struct rte_flow_item){
4981 .type = RTE_FLOW_ITEM_TYPE_UDP,
4982 .spec = &attributes->l4,
4983 .mask = &attributes->l4_mask,
4986 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4987 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
4988 .src_port = input->flow.tcp4_flow.src_port,
4989 .dst_port = input->flow.tcp4_flow.dst_port,
4991 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
4992 .src_port = mask->src_port_mask,
4993 .dst_port = mask->dst_port_mask,
4995 attributes->items[2] = (struct rte_flow_item){
4996 .type = RTE_FLOW_ITEM_TYPE_TCP,
4997 .spec = &attributes->l4,
4998 .mask = &attributes->l4_mask,
5001 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
5002 attributes->l4.udp.hdr = (struct rte_udp_hdr){
5003 .src_port = input->flow.udp6_flow.src_port,
5004 .dst_port = input->flow.udp6_flow.dst_port,
5006 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
5007 .src_port = mask->src_port_mask,
5008 .dst_port = mask->dst_port_mask,
5010 attributes->items[2] = (struct rte_flow_item){
5011 .type = RTE_FLOW_ITEM_TYPE_UDP,
5012 .spec = &attributes->l4,
5013 .mask = &attributes->l4_mask,
5016 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
5017 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
5018 .src_port = input->flow.tcp6_flow.src_port,
5019 .dst_port = input->flow.tcp6_flow.dst_port,
5021 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
5022 .src_port = mask->src_port_mask,
5023 .dst_port = mask->dst_port_mask,
5025 attributes->items[2] = (struct rte_flow_item){
5026 .type = RTE_FLOW_ITEM_TYPE_TCP,
5027 .spec = &attributes->l4,
5028 .mask = &attributes->l4_mask,
5031 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
5032 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
5035 DRV_LOG(ERR, "port %u invalid flow type%d",
5036 dev->data->port_id, fdir_filter->input.flow_type);
5037 rte_errno = ENOTSUP;
5043 #define FLOW_FDIR_CMP(f1, f2, fld) \
5044 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
5047 * Compare two FDIR flows. If items and actions are identical, the two flows are
5051 * Pointer to Ethernet device.
5053 * FDIR flow to compare.
5055 * FDIR flow to compare.
5058 * Zero on match, 1 otherwise.
5061 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
5063 if (FLOW_FDIR_CMP(f1, f2, attr) ||
5064 FLOW_FDIR_CMP(f1, f2, l2) ||
5065 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
5066 FLOW_FDIR_CMP(f1, f2, l3) ||
5067 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
5068 FLOW_FDIR_CMP(f1, f2, l4) ||
5069 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
5070 FLOW_FDIR_CMP(f1, f2, actions[0].type))
5072 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
5073 FLOW_FDIR_CMP(f1, f2, queue))
5079 * Search device flow list to find out a matched FDIR flow.
5082 * Pointer to Ethernet device.
5084 * FDIR flow to lookup.
5087 * Pointer of flow if found, NULL otherwise.
5089 static struct rte_flow *
5090 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
5092 struct mlx5_priv *priv = dev->data->dev_private;
5093 struct rte_flow *flow = NULL;
5095 MLX5_ASSERT(fdir_flow);
5096 TAILQ_FOREACH(flow, &priv->flows, next) {
5097 if (flow->fdir && !flow_fdir_cmp(flow->fdir, fdir_flow)) {
5098 DRV_LOG(DEBUG, "port %u found FDIR flow %p",
5099 dev->data->port_id, (void *)flow);
5107 * Add new flow director filter and store it in list.
5110 * Pointer to Ethernet device.
5111 * @param fdir_filter
5112 * Flow director filter to add.
5115 * 0 on success, a negative errno value otherwise and rte_errno is set.
5118 flow_fdir_filter_add(struct rte_eth_dev *dev,
5119 const struct rte_eth_fdir_filter *fdir_filter)
5121 struct mlx5_priv *priv = dev->data->dev_private;
5122 struct mlx5_fdir *fdir_flow;
5123 struct rte_flow *flow;
5126 fdir_flow = rte_zmalloc(__func__, sizeof(*fdir_flow), 0);
5131 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
5134 flow = flow_fdir_filter_lookup(dev, fdir_flow);
5139 flow = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
5140 fdir_flow->items, fdir_flow->actions, true,
5144 MLX5_ASSERT(!flow->fdir);
5145 flow->fdir = fdir_flow;
5146 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
5147 dev->data->port_id, (void *)flow);
5150 rte_free(fdir_flow);
5155 * Delete specific filter.
5158 * Pointer to Ethernet device.
5159 * @param fdir_filter
5160 * Filter to be deleted.
5163 * 0 on success, a negative errno value otherwise and rte_errno is set.
5166 flow_fdir_filter_delete(struct rte_eth_dev *dev,
5167 const struct rte_eth_fdir_filter *fdir_filter)
5169 struct mlx5_priv *priv = dev->data->dev_private;
5170 struct rte_flow *flow;
5171 struct mlx5_fdir fdir_flow = {
5176 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
5179 flow = flow_fdir_filter_lookup(dev, &fdir_flow);
5184 flow_list_destroy(dev, &priv->flows, flow);
5185 DRV_LOG(DEBUG, "port %u deleted FDIR flow %p",
5186 dev->data->port_id, (void *)flow);
5191 * Update queue for specific filter.
5194 * Pointer to Ethernet device.
5195 * @param fdir_filter
5196 * Filter to be updated.
5199 * 0 on success, a negative errno value otherwise and rte_errno is set.
5202 flow_fdir_filter_update(struct rte_eth_dev *dev,
5203 const struct rte_eth_fdir_filter *fdir_filter)
5207 ret = flow_fdir_filter_delete(dev, fdir_filter);
5210 return flow_fdir_filter_add(dev, fdir_filter);
5214 * Flush all filters.
5217 * Pointer to Ethernet device.
5220 flow_fdir_filter_flush(struct rte_eth_dev *dev)
5222 struct mlx5_priv *priv = dev->data->dev_private;
5224 mlx5_flow_list_flush(dev, &priv->flows, false);
5228 * Get flow director information.
5231 * Pointer to Ethernet device.
5232 * @param[out] fdir_info
5233 * Resulting flow director information.
5236 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
5238 struct rte_eth_fdir_masks *mask =
5239 &dev->data->dev_conf.fdir_conf.mask;
5241 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
5242 fdir_info->guarant_spc = 0;
5243 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
5244 fdir_info->max_flexpayload = 0;
5245 fdir_info->flow_types_mask[0] = 0;
5246 fdir_info->flex_payload_unit = 0;
5247 fdir_info->max_flex_payload_segment_num = 0;
5248 fdir_info->flex_payload_limit = 0;
5249 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
5253 * Deal with flow director operations.
5256 * Pointer to Ethernet device.
5258 * Operation to perform.
5260 * Pointer to operation-specific structure.
5263 * 0 on success, a negative errno value otherwise and rte_errno is set.
5266 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
5269 enum rte_fdir_mode fdir_mode =
5270 dev->data->dev_conf.fdir_conf.mode;
5272 if (filter_op == RTE_ETH_FILTER_NOP)
5274 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
5275 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5276 DRV_LOG(ERR, "port %u flow director mode %d not supported",
5277 dev->data->port_id, fdir_mode);
5281 switch (filter_op) {
5282 case RTE_ETH_FILTER_ADD:
5283 return flow_fdir_filter_add(dev, arg);
5284 case RTE_ETH_FILTER_UPDATE:
5285 return flow_fdir_filter_update(dev, arg);
5286 case RTE_ETH_FILTER_DELETE:
5287 return flow_fdir_filter_delete(dev, arg);
5288 case RTE_ETH_FILTER_FLUSH:
5289 flow_fdir_filter_flush(dev);
5291 case RTE_ETH_FILTER_INFO:
5292 flow_fdir_info_get(dev, arg);
5295 DRV_LOG(DEBUG, "port %u unknown operation %u",
5296 dev->data->port_id, filter_op);
5304 * Manage filter operations.
5307 * Pointer to Ethernet device structure.
5308 * @param filter_type
5311 * Operation to perform.
5313 * Pointer to operation-specific structure.
5316 * 0 on success, a negative errno value otherwise and rte_errno is set.
5319 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
5320 enum rte_filter_type filter_type,
5321 enum rte_filter_op filter_op,
5324 switch (filter_type) {
5325 case RTE_ETH_FILTER_GENERIC:
5326 if (filter_op != RTE_ETH_FILTER_GET) {
5330 *(const void **)arg = &mlx5_flow_ops;
5332 case RTE_ETH_FILTER_FDIR:
5333 return flow_fdir_ctrl_func(dev, filter_op, arg);
5335 DRV_LOG(ERR, "port %u filter type (%d) not supported",
5336 dev->data->port_id, filter_type);
5337 rte_errno = ENOTSUP;
5344 * Create the needed meter and suffix tables.
5347 * Pointer to Ethernet device.
5349 * Pointer to the flow meter.
5352 * Pointer to table set on success, NULL otherwise.
5354 struct mlx5_meter_domains_infos *
5355 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
5356 const struct mlx5_flow_meter *fm)
5358 const struct mlx5_flow_driver_ops *fops;
5360 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5361 return fops->create_mtr_tbls(dev, fm);
5365 * Destroy the meter table set.
5368 * Pointer to Ethernet device.
5370 * Pointer to the meter table set.
5376 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
5377 struct mlx5_meter_domains_infos *tbls)
5379 const struct mlx5_flow_driver_ops *fops;
5381 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5382 return fops->destroy_mtr_tbls(dev, tbls);
5386 * Create policer rules.
5389 * Pointer to Ethernet device.
5391 * Pointer to flow meter structure.
5393 * Pointer to flow attributes.
5396 * 0 on success, -1 otherwise.
5399 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
5400 struct mlx5_flow_meter *fm,
5401 const struct rte_flow_attr *attr)
5403 const struct mlx5_flow_driver_ops *fops;
5405 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5406 return fops->create_policer_rules(dev, fm, attr);
5410 * Destroy policer rules.
5413 * Pointer to flow meter structure.
5415 * Pointer to flow attributes.
5418 * 0 on success, -1 otherwise.
5421 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
5422 struct mlx5_flow_meter *fm,
5423 const struct rte_flow_attr *attr)
5425 const struct mlx5_flow_driver_ops *fops;
5427 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5428 return fops->destroy_policer_rules(dev, fm, attr);
5432 * Allocate a counter.
5435 * Pointer to Ethernet device structure.
5438 * Pointer to allocated counter on success, NULL otherwise.
5440 struct mlx5_flow_counter *
5441 mlx5_counter_alloc(struct rte_eth_dev *dev)
5443 const struct mlx5_flow_driver_ops *fops;
5444 struct rte_flow_attr attr = { .transfer = 0 };
5446 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5447 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5448 return fops->counter_alloc(dev);
5451 "port %u counter allocate is not supported.",
5452 dev->data->port_id);
5460 * Pointer to Ethernet device structure.
5462 * Pointer to counter to be free.
5465 mlx5_counter_free(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt)
5467 const struct mlx5_flow_driver_ops *fops;
5468 struct rte_flow_attr attr = { .transfer = 0 };
5470 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5471 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5472 fops->counter_free(dev, cnt);
5476 "port %u counter free is not supported.",
5477 dev->data->port_id);
5481 * Query counter statistics.
5484 * Pointer to Ethernet device structure.
5486 * Pointer to counter to query.
5488 * Set to clear counter statistics.
5490 * The counter hits packets number to save.
5492 * The counter hits bytes number to save.
5495 * 0 on success, a negative errno value otherwise.
5498 mlx5_counter_query(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt,
5499 bool clear, uint64_t *pkts, uint64_t *bytes)
5501 const struct mlx5_flow_driver_ops *fops;
5502 struct rte_flow_attr attr = { .transfer = 0 };
5504 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5505 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5506 return fops->counter_query(dev, cnt, clear, pkts, bytes);
5509 "port %u counter query is not supported.",
5510 dev->data->port_id);
5514 #define MLX5_POOL_QUERY_FREQ_US 1000000
5517 * Set the periodic procedure for triggering asynchronous batch queries for all
5518 * the counter pools.
5521 * Pointer to mlx5_ibv_shared object.
5524 mlx5_set_query_alarm(struct mlx5_ibv_shared *sh)
5526 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(sh, 0, 0);
5527 uint32_t pools_n = rte_atomic16_read(&cont->n_valid);
5530 cont = MLX5_CNT_CONTAINER(sh, 1, 0);
5531 pools_n += rte_atomic16_read(&cont->n_valid);
5532 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
5533 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
5534 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
5535 sh->cmng.query_thread_on = 0;
5536 DRV_LOG(ERR, "Cannot reinitialize query alarm");
5538 sh->cmng.query_thread_on = 1;
5543 * The periodic procedure for triggering asynchronous batch queries for all the
5544 * counter pools. This function is probably called by the host thread.
5547 * The parameter for the alarm process.
5550 mlx5_flow_query_alarm(void *arg)
5552 struct mlx5_ibv_shared *sh = arg;
5553 struct mlx5_devx_obj *dcs;
5556 uint8_t batch = sh->cmng.batch;
5557 uint16_t pool_index = sh->cmng.pool_index;
5558 struct mlx5_pools_container *cont;
5559 struct mlx5_pools_container *mcont;
5560 struct mlx5_flow_counter_pool *pool;
5562 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
5565 cont = MLX5_CNT_CONTAINER(sh, batch, 1);
5566 mcont = MLX5_CNT_CONTAINER(sh, batch, 0);
5567 /* Check if resize was done and need to flip a container. */
5568 if (cont != mcont) {
5570 /* Clean the old container. */
5571 rte_free(cont->pools);
5572 memset(cont, 0, sizeof(*cont));
5575 /* Flip the host container. */
5576 sh->cmng.mhi[batch] ^= (uint8_t)2;
5580 /* 2 empty containers case is unexpected. */
5581 if (unlikely(batch != sh->cmng.batch))
5585 goto next_container;
5587 pool = cont->pools[pool_index];
5589 /* There is a pool query in progress. */
5592 LIST_FIRST(&sh->cmng.free_stat_raws);
5594 /* No free counter statistics raw memory. */
5596 dcs = (struct mlx5_devx_obj *)(uintptr_t)rte_atomic64_read
5598 offset = batch ? 0 : dcs->id % MLX5_COUNTERS_PER_POOL;
5599 ret = mlx5_devx_cmd_flow_counter_query(dcs, 0, MLX5_COUNTERS_PER_POOL -
5601 pool->raw_hw->mem_mng->dm->id,
5603 (pool->raw_hw->data + offset),
5605 (uint64_t)(uintptr_t)pool);
5607 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
5608 " %d", pool->min_dcs->id);
5609 pool->raw_hw = NULL;
5612 pool->raw_hw->min_dcs_id = dcs->id;
5613 LIST_REMOVE(pool->raw_hw, next);
5614 sh->cmng.pending_queries++;
5616 if (pool_index >= rte_atomic16_read(&cont->n_valid)) {
5621 sh->cmng.batch = batch;
5622 sh->cmng.pool_index = pool_index;
5623 mlx5_set_query_alarm(sh);
5627 * Handler for the HW respond about ready values from an asynchronous batch
5628 * query. This function is probably called by the host thread.
5631 * The pointer to the shared IB device context.
5632 * @param[in] async_id
5633 * The Devx async ID.
5635 * The status of the completion.
5638 mlx5_flow_async_pool_query_handle(struct mlx5_ibv_shared *sh,
5639 uint64_t async_id, int status)
5641 struct mlx5_flow_counter_pool *pool =
5642 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
5643 struct mlx5_counter_stats_raw *raw_to_free;
5645 if (unlikely(status)) {
5646 raw_to_free = pool->raw_hw;
5648 raw_to_free = pool->raw;
5649 rte_spinlock_lock(&pool->sl);
5650 pool->raw = pool->raw_hw;
5651 rte_spinlock_unlock(&pool->sl);
5652 rte_atomic64_add(&pool->query_gen, 1);
5653 /* Be sure the new raw counters data is updated in memory. */
5656 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
5657 pool->raw_hw = NULL;
5658 sh->cmng.pending_queries--;
5662 * Translate the rte_flow group index to HW table value.
5664 * @param[in] attributes
5665 * Pointer to flow attributes
5666 * @param[in] external
5667 * Value is part of flow rule created by request external to PMD.
5669 * rte_flow group index value.
5670 * @param[out] fdb_def_rule
5671 * Whether fdb jump to table 1 is configured.
5675 * Pointer to error structure.
5678 * 0 on success, a negative errno value otherwise and rte_errno is set.
5681 mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, bool external,
5682 uint32_t group, bool fdb_def_rule, uint32_t *table,
5683 struct rte_flow_error *error)
5685 if (attributes->transfer && external && fdb_def_rule) {
5686 if (group == UINT32_MAX)
5687 return rte_flow_error_set
5689 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5691 "group index not supported");
5700 * Discover availability of metadata reg_c's.
5702 * Iteratively use test flows to check availability.
5705 * Pointer to the Ethernet device structure.
5708 * 0 on success, a negative errno value otherwise and rte_errno is set.
5711 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
5713 struct mlx5_priv *priv = dev->data->dev_private;
5714 struct mlx5_dev_config *config = &priv->config;
5715 enum modify_reg idx;
5718 /* reg_c[0] and reg_c[1] are reserved. */
5719 config->flow_mreg_c[n++] = REG_C_0;
5720 config->flow_mreg_c[n++] = REG_C_1;
5721 /* Discover availability of other reg_c's. */
5722 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
5723 struct rte_flow_attr attr = {
5724 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5725 .priority = MLX5_FLOW_PRIO_RSVD,
5728 struct rte_flow_item items[] = {
5730 .type = RTE_FLOW_ITEM_TYPE_END,
5733 struct rte_flow_action actions[] = {
5735 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5736 .conf = &(struct mlx5_flow_action_copy_mreg){
5742 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5743 .conf = &(struct rte_flow_action_jump){
5744 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5748 .type = RTE_FLOW_ACTION_TYPE_END,
5751 struct rte_flow *flow;
5752 struct rte_flow_error error;
5754 if (!config->dv_flow_en)
5756 /* Create internal flow, validation skips copy action. */
5757 flow = flow_list_create(dev, NULL, &attr, items,
5758 actions, false, &error);
5761 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
5762 config->flow_mreg_c[n++] = idx;
5763 flow_list_destroy(dev, NULL, flow);
5765 for (; n < MLX5_MREG_C_NUM; ++n)
5766 config->flow_mreg_c[n] = REG_NONE;
5771 * Dump flow raw hw data to file
5774 * The pointer to Ethernet device.
5776 * A pointer to a file for output.
5778 * Perform verbose error reporting if not NULL. PMDs initialize this
5779 * structure in case of error only.
5781 * 0 on success, a nagative value otherwise.
5784 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
5786 struct rte_flow_error *error __rte_unused)
5788 struct mlx5_priv *priv = dev->data->dev_private;
5789 struct mlx5_ibv_shared *sh = priv->sh;
5791 return mlx5_devx_cmd_flow_dump(sh->fdb_domain, sh->rx_domain,
5792 sh->tx_domain, file);