1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
6 #include <netinet/in.h>
13 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
15 #pragma GCC diagnostic ignored "-Wpedantic"
17 #include <infiniband/verbs.h>
19 #pragma GCC diagnostic error "-Wpedantic"
22 #include <rte_common.h>
23 #include <rte_ether.h>
24 #include <rte_ethdev_driver.h>
26 #include <rte_flow_driver.h>
27 #include <rte_malloc.h>
31 #include "mlx5_defs.h"
32 #include "mlx5_flow.h"
33 #include "mlx5_glue.h"
35 #include "mlx5_rxtx.h"
37 /* Dev ops structure defined in mlx5.c */
38 extern const struct eth_dev_ops mlx5_dev_ops;
39 extern const struct eth_dev_ops mlx5_dev_ops_isolate;
41 /** Device flow drivers. */
42 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
43 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
45 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
47 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
49 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
50 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
51 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
52 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
54 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
55 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
60 MLX5_EXPANSION_ROOT_OUTER,
61 MLX5_EXPANSION_ROOT_ETH_VLAN,
62 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
63 MLX5_EXPANSION_OUTER_ETH,
64 MLX5_EXPANSION_OUTER_ETH_VLAN,
65 MLX5_EXPANSION_OUTER_VLAN,
66 MLX5_EXPANSION_OUTER_IPV4,
67 MLX5_EXPANSION_OUTER_IPV4_UDP,
68 MLX5_EXPANSION_OUTER_IPV4_TCP,
69 MLX5_EXPANSION_OUTER_IPV6,
70 MLX5_EXPANSION_OUTER_IPV6_UDP,
71 MLX5_EXPANSION_OUTER_IPV6_TCP,
73 MLX5_EXPANSION_VXLAN_GPE,
77 MLX5_EXPANSION_ETH_VLAN,
80 MLX5_EXPANSION_IPV4_UDP,
81 MLX5_EXPANSION_IPV4_TCP,
83 MLX5_EXPANSION_IPV6_UDP,
84 MLX5_EXPANSION_IPV6_TCP,
87 /** Supported expansion of items. */
88 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
89 [MLX5_EXPANSION_ROOT] = {
90 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
93 .type = RTE_FLOW_ITEM_TYPE_END,
95 [MLX5_EXPANSION_ROOT_OUTER] = {
96 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
97 MLX5_EXPANSION_OUTER_IPV4,
98 MLX5_EXPANSION_OUTER_IPV6),
99 .type = RTE_FLOW_ITEM_TYPE_END,
101 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
102 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
103 .type = RTE_FLOW_ITEM_TYPE_END,
105 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
106 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
107 .type = RTE_FLOW_ITEM_TYPE_END,
109 [MLX5_EXPANSION_OUTER_ETH] = {
110 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
111 MLX5_EXPANSION_OUTER_IPV6,
112 MLX5_EXPANSION_MPLS),
113 .type = RTE_FLOW_ITEM_TYPE_ETH,
116 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
117 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
118 .type = RTE_FLOW_ITEM_TYPE_ETH,
121 [MLX5_EXPANSION_OUTER_VLAN] = {
122 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
123 MLX5_EXPANSION_OUTER_IPV6),
124 .type = RTE_FLOW_ITEM_TYPE_VLAN,
126 [MLX5_EXPANSION_OUTER_IPV4] = {
127 .next = RTE_FLOW_EXPAND_RSS_NEXT
128 (MLX5_EXPANSION_OUTER_IPV4_UDP,
129 MLX5_EXPANSION_OUTER_IPV4_TCP,
132 MLX5_EXPANSION_IPV6),
133 .type = RTE_FLOW_ITEM_TYPE_IPV4,
134 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
135 ETH_RSS_NONFRAG_IPV4_OTHER,
137 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
138 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
139 MLX5_EXPANSION_VXLAN_GPE),
140 .type = RTE_FLOW_ITEM_TYPE_UDP,
141 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
143 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
144 .type = RTE_FLOW_ITEM_TYPE_TCP,
145 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
147 [MLX5_EXPANSION_OUTER_IPV6] = {
148 .next = RTE_FLOW_EXPAND_RSS_NEXT
149 (MLX5_EXPANSION_OUTER_IPV6_UDP,
150 MLX5_EXPANSION_OUTER_IPV6_TCP,
152 MLX5_EXPANSION_IPV6),
153 .type = RTE_FLOW_ITEM_TYPE_IPV6,
154 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
155 ETH_RSS_NONFRAG_IPV6_OTHER,
157 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
158 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
159 MLX5_EXPANSION_VXLAN_GPE),
160 .type = RTE_FLOW_ITEM_TYPE_UDP,
161 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
163 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
164 .type = RTE_FLOW_ITEM_TYPE_TCP,
165 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
167 [MLX5_EXPANSION_VXLAN] = {
168 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
169 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
171 [MLX5_EXPANSION_VXLAN_GPE] = {
172 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
174 MLX5_EXPANSION_IPV6),
175 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
177 [MLX5_EXPANSION_GRE] = {
178 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
179 .type = RTE_FLOW_ITEM_TYPE_GRE,
181 [MLX5_EXPANSION_MPLS] = {
182 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
183 MLX5_EXPANSION_IPV6),
184 .type = RTE_FLOW_ITEM_TYPE_MPLS,
186 [MLX5_EXPANSION_ETH] = {
187 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
188 MLX5_EXPANSION_IPV6),
189 .type = RTE_FLOW_ITEM_TYPE_ETH,
191 [MLX5_EXPANSION_ETH_VLAN] = {
192 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
193 .type = RTE_FLOW_ITEM_TYPE_ETH,
195 [MLX5_EXPANSION_VLAN] = {
196 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
197 MLX5_EXPANSION_IPV6),
198 .type = RTE_FLOW_ITEM_TYPE_VLAN,
200 [MLX5_EXPANSION_IPV4] = {
201 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
202 MLX5_EXPANSION_IPV4_TCP),
203 .type = RTE_FLOW_ITEM_TYPE_IPV4,
204 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
205 ETH_RSS_NONFRAG_IPV4_OTHER,
207 [MLX5_EXPANSION_IPV4_UDP] = {
208 .type = RTE_FLOW_ITEM_TYPE_UDP,
209 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
211 [MLX5_EXPANSION_IPV4_TCP] = {
212 .type = RTE_FLOW_ITEM_TYPE_TCP,
213 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
215 [MLX5_EXPANSION_IPV6] = {
216 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
217 MLX5_EXPANSION_IPV6_TCP),
218 .type = RTE_FLOW_ITEM_TYPE_IPV6,
219 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
220 ETH_RSS_NONFRAG_IPV6_OTHER,
222 [MLX5_EXPANSION_IPV6_UDP] = {
223 .type = RTE_FLOW_ITEM_TYPE_UDP,
224 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
226 [MLX5_EXPANSION_IPV6_TCP] = {
227 .type = RTE_FLOW_ITEM_TYPE_TCP,
228 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
232 static const struct rte_flow_ops mlx5_flow_ops = {
233 .validate = mlx5_flow_validate,
234 .create = mlx5_flow_create,
235 .destroy = mlx5_flow_destroy,
236 .flush = mlx5_flow_flush,
237 .isolate = mlx5_flow_isolate,
238 .query = mlx5_flow_query,
239 .dev_dump = mlx5_flow_dev_dump,
242 /* Convert FDIR request to Generic flow. */
244 struct rte_flow_attr attr;
245 struct rte_flow_item items[4];
246 struct rte_flow_item_eth l2;
247 struct rte_flow_item_eth l2_mask;
249 struct rte_flow_item_ipv4 ipv4;
250 struct rte_flow_item_ipv6 ipv6;
253 struct rte_flow_item_ipv4 ipv4;
254 struct rte_flow_item_ipv6 ipv6;
257 struct rte_flow_item_udp udp;
258 struct rte_flow_item_tcp tcp;
261 struct rte_flow_item_udp udp;
262 struct rte_flow_item_tcp tcp;
264 struct rte_flow_action actions[2];
265 struct rte_flow_action_queue queue;
268 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
269 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
270 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
273 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
274 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
275 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
276 { 9, 10, 11 }, { 12, 13, 14 },
279 /* Tunnel information. */
280 struct mlx5_flow_tunnel_info {
281 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
282 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
285 static struct mlx5_flow_tunnel_info tunnels_info[] = {
287 .tunnel = MLX5_FLOW_LAYER_VXLAN,
288 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
291 .tunnel = MLX5_FLOW_LAYER_GENEVE,
292 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
295 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
296 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
299 .tunnel = MLX5_FLOW_LAYER_GRE,
300 .ptype = RTE_PTYPE_TUNNEL_GRE,
303 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
304 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
307 .tunnel = MLX5_FLOW_LAYER_MPLS,
308 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
311 .tunnel = MLX5_FLOW_LAYER_NVGRE,
312 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
315 .tunnel = MLX5_FLOW_LAYER_IPIP,
316 .ptype = RTE_PTYPE_TUNNEL_IP,
319 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
320 .ptype = RTE_PTYPE_TUNNEL_IP,
323 .tunnel = MLX5_FLOW_LAYER_GTP,
324 .ptype = RTE_PTYPE_TUNNEL_GTPU,
329 * Translate tag ID to register.
332 * Pointer to the Ethernet device structure.
334 * The feature that request the register.
336 * The request register ID.
338 * Error description in case of any.
341 * The request register on success, a negative errno
342 * value otherwise and rte_errno is set.
345 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
346 enum mlx5_feature_name feature,
348 struct rte_flow_error *error)
350 struct mlx5_priv *priv = dev->data->dev_private;
351 struct mlx5_dev_config *config = &priv->config;
352 enum modify_reg start_reg;
355 case MLX5_HAIRPIN_RX:
357 case MLX5_HAIRPIN_TX:
359 case MLX5_METADATA_RX:
360 switch (config->dv_xmeta_en) {
361 case MLX5_XMETA_MODE_LEGACY:
363 case MLX5_XMETA_MODE_META16:
365 case MLX5_XMETA_MODE_META32:
369 case MLX5_METADATA_TX:
371 case MLX5_METADATA_FDB:
372 switch (config->dv_xmeta_en) {
373 case MLX5_XMETA_MODE_LEGACY:
375 case MLX5_XMETA_MODE_META16:
377 case MLX5_XMETA_MODE_META32:
382 switch (config->dv_xmeta_en) {
383 case MLX5_XMETA_MODE_LEGACY:
385 case MLX5_XMETA_MODE_META16:
387 case MLX5_XMETA_MODE_META32:
394 * Metadata COPY_MARK register using is in meter suffix sub
395 * flow while with meter. It's safe to share the same register.
397 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
399 RTE_ASSERT(priv->mtr_color_reg != REG_NONE);
400 return priv->mtr_color_reg;
403 * If meter is enable, it will engage two registers for color
404 * match and flow match. If meter color match is not using the
405 * REG_C_2, need to skip the REG_C_x be used by meter color
407 * If meter is disable, free to use all available registers.
409 if (priv->mtr_color_reg != REG_NONE)
410 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_3 :
414 if (id > (REG_C_7 - start_reg))
415 return rte_flow_error_set(error, EINVAL,
416 RTE_FLOW_ERROR_TYPE_ITEM,
417 NULL, "invalid tag id");
418 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NONE)
419 return rte_flow_error_set(error, ENOTSUP,
420 RTE_FLOW_ERROR_TYPE_ITEM,
421 NULL, "unsupported tag id");
423 * This case means meter is using the REG_C_x great than 2.
424 * Take care not to conflict with meter color REG_C_x.
425 * If the available index REG_C_y >= REG_C_x, skip the
428 if (start_reg == REG_C_3 && config->flow_mreg_c
429 [id + REG_C_3 - REG_C_0] >= priv->mtr_color_reg) {
430 if (config->flow_mreg_c[id + 1 + REG_C_3 - REG_C_0] !=
432 return config->flow_mreg_c
433 [id + 1 + REG_C_3 - REG_C_0];
434 return rte_flow_error_set(error, ENOTSUP,
435 RTE_FLOW_ERROR_TYPE_ITEM,
436 NULL, "unsupported tag id");
438 return config->flow_mreg_c[id + start_reg - REG_C_0];
441 return rte_flow_error_set(error, EINVAL,
442 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
443 NULL, "invalid feature name");
447 * Check extensive flow metadata register support.
450 * Pointer to rte_eth_dev structure.
453 * True if device supports extensive flow metadata register, otherwise false.
456 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
458 struct mlx5_priv *priv = dev->data->dev_private;
459 struct mlx5_dev_config *config = &priv->config;
462 * Having available reg_c can be regarded inclusively as supporting
463 * extensive flow metadata register, which could mean,
464 * - metadata register copy action by modify header.
465 * - 16 modify header actions is supported.
466 * - reg_c's are preserved across different domain (FDB and NIC) on
467 * packet loopback by flow lookup miss.
469 return config->flow_mreg_c[2] != REG_NONE;
473 * Discover the maximum number of priority available.
476 * Pointer to the Ethernet device structure.
479 * number of supported flow priority on success, a negative errno
480 * value otherwise and rte_errno is set.
483 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
485 struct mlx5_priv *priv = dev->data->dev_private;
487 struct ibv_flow_attr attr;
488 struct ibv_flow_spec_eth eth;
489 struct ibv_flow_spec_action_drop drop;
493 .port = (uint8_t)priv->ibv_port,
496 .type = IBV_FLOW_SPEC_ETH,
497 .size = sizeof(struct ibv_flow_spec_eth),
500 .size = sizeof(struct ibv_flow_spec_action_drop),
501 .type = IBV_FLOW_SPEC_ACTION_DROP,
504 struct ibv_flow *flow;
505 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
506 uint16_t vprio[] = { 8, 16 };
514 for (i = 0; i != RTE_DIM(vprio); i++) {
515 flow_attr.attr.priority = vprio[i] - 1;
516 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
519 claim_zero(mlx5_glue->destroy_flow(flow));
522 mlx5_hrxq_drop_release(dev);
525 priority = RTE_DIM(priority_map_3);
528 priority = RTE_DIM(priority_map_5);
533 "port %u verbs maximum priority: %d expected 8/16",
534 dev->data->port_id, priority);
537 DRV_LOG(INFO, "port %u flow maximum priority: %d",
538 dev->data->port_id, priority);
543 * Adjust flow priority based on the highest layer and the request priority.
546 * Pointer to the Ethernet device structure.
547 * @param[in] priority
548 * The rule base priority.
549 * @param[in] subpriority
550 * The priority based on the items.
555 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
556 uint32_t subpriority)
559 struct mlx5_priv *priv = dev->data->dev_private;
561 switch (priv->config.flow_prio) {
562 case RTE_DIM(priority_map_3):
563 res = priority_map_3[priority][subpriority];
565 case RTE_DIM(priority_map_5):
566 res = priority_map_5[priority][subpriority];
573 * Verify the @p item specifications (spec, last, mask) are compatible with the
577 * Item specification.
579 * @p item->mask or flow default bit-masks.
580 * @param[in] nic_mask
581 * Bit-masks covering supported fields by the NIC to compare with user mask.
583 * Bit-masks size in bytes.
585 * Pointer to error structure.
588 * 0 on success, a negative errno value otherwise and rte_errno is set.
591 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
593 const uint8_t *nic_mask,
595 struct rte_flow_error *error)
600 for (i = 0; i < size; ++i)
601 if ((nic_mask[i] | mask[i]) != nic_mask[i])
602 return rte_flow_error_set(error, ENOTSUP,
603 RTE_FLOW_ERROR_TYPE_ITEM,
605 "mask enables non supported"
607 if (!item->spec && (item->mask || item->last))
608 return rte_flow_error_set(error, EINVAL,
609 RTE_FLOW_ERROR_TYPE_ITEM, item,
610 "mask/last without a spec is not"
612 if (item->spec && item->last) {
618 for (i = 0; i < size; ++i) {
619 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
620 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
622 ret = memcmp(spec, last, size);
624 return rte_flow_error_set(error, EINVAL,
625 RTE_FLOW_ERROR_TYPE_ITEM,
627 "range is not valid");
633 * Adjust the hash fields according to the @p flow information.
635 * @param[in] dev_flow.
636 * Pointer to the mlx5_flow.
638 * 1 when the hash field is for a tunnel item.
639 * @param[in] layer_types
641 * @param[in] hash_fields
645 * The hash fields that should be used.
648 mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow,
649 int tunnel __rte_unused, uint64_t layer_types,
650 uint64_t hash_fields)
652 struct rte_flow *flow = dev_flow->flow;
653 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
654 int rss_request_inner = flow->rss.level >= 2;
656 /* Check RSS hash level for tunnel. */
657 if (tunnel && rss_request_inner)
658 hash_fields |= IBV_RX_HASH_INNER;
659 else if (tunnel || rss_request_inner)
662 /* Check if requested layer matches RSS hash fields. */
663 if (!(flow->rss.types & layer_types))
669 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
670 * if several tunnel rules are used on this queue, the tunnel ptype will be
674 * Rx queue to update.
677 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
680 uint32_t tunnel_ptype = 0;
682 /* Look up for the ptype to use. */
683 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
684 if (!rxq_ctrl->flow_tunnels_n[i])
687 tunnel_ptype = tunnels_info[i].ptype;
693 rxq_ctrl->rxq.tunnel = tunnel_ptype;
697 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
701 * Pointer to the Ethernet device structure.
702 * @param[in] dev_flow
703 * Pointer to device flow structure.
706 flow_drv_rxq_flags_set(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
708 struct mlx5_priv *priv = dev->data->dev_private;
709 struct rte_flow *flow = dev_flow->flow;
710 const int mark = !!(dev_flow->actions &
711 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
712 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
715 for (i = 0; i != flow->rss.queue_num; ++i) {
716 int idx = (*flow->rss.queue)[i];
717 struct mlx5_rxq_ctrl *rxq_ctrl =
718 container_of((*priv->rxqs)[idx],
719 struct mlx5_rxq_ctrl, rxq);
722 * To support metadata register copy on Tx loopback,
723 * this must be always enabled (metadata may arive
724 * from other port - not from local flows only.
726 if (priv->config.dv_flow_en &&
727 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
728 mlx5_flow_ext_mreg_supported(dev)) {
729 rxq_ctrl->rxq.mark = 1;
730 rxq_ctrl->flow_mark_n = 1;
732 rxq_ctrl->rxq.mark = 1;
733 rxq_ctrl->flow_mark_n++;
738 /* Increase the counter matching the flow. */
739 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
740 if ((tunnels_info[j].tunnel &
742 tunnels_info[j].tunnel) {
743 rxq_ctrl->flow_tunnels_n[j]++;
747 flow_rxq_tunnel_ptype_update(rxq_ctrl);
753 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
756 * Pointer to the Ethernet device structure.
758 * Pointer to flow structure.
761 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
763 struct mlx5_flow *dev_flow;
765 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
766 flow_drv_rxq_flags_set(dev, dev_flow);
770 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
771 * device flow if no other flow uses it with the same kind of request.
774 * Pointer to Ethernet device.
775 * @param[in] dev_flow
776 * Pointer to the device flow.
779 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
781 struct mlx5_priv *priv = dev->data->dev_private;
782 struct rte_flow *flow = dev_flow->flow;
783 const int mark = !!(dev_flow->actions &
784 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
785 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
788 assert(dev->data->dev_started);
789 for (i = 0; i != flow->rss.queue_num; ++i) {
790 int idx = (*flow->rss.queue)[i];
791 struct mlx5_rxq_ctrl *rxq_ctrl =
792 container_of((*priv->rxqs)[idx],
793 struct mlx5_rxq_ctrl, rxq);
795 if (priv->config.dv_flow_en &&
796 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
797 mlx5_flow_ext_mreg_supported(dev)) {
798 rxq_ctrl->rxq.mark = 1;
799 rxq_ctrl->flow_mark_n = 1;
801 rxq_ctrl->flow_mark_n--;
802 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
807 /* Decrease the counter matching the flow. */
808 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
809 if ((tunnels_info[j].tunnel &
811 tunnels_info[j].tunnel) {
812 rxq_ctrl->flow_tunnels_n[j]--;
816 flow_rxq_tunnel_ptype_update(rxq_ctrl);
822 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
823 * @p flow if no other flow uses it with the same kind of request.
826 * Pointer to Ethernet device.
828 * Pointer to the flow.
831 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
833 struct mlx5_flow *dev_flow;
835 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
836 flow_drv_rxq_flags_trim(dev, dev_flow);
840 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
843 * Pointer to Ethernet device.
846 flow_rxq_flags_clear(struct rte_eth_dev *dev)
848 struct mlx5_priv *priv = dev->data->dev_private;
851 for (i = 0; i != priv->rxqs_n; ++i) {
852 struct mlx5_rxq_ctrl *rxq_ctrl;
855 if (!(*priv->rxqs)[i])
857 rxq_ctrl = container_of((*priv->rxqs)[i],
858 struct mlx5_rxq_ctrl, rxq);
859 rxq_ctrl->flow_mark_n = 0;
860 rxq_ctrl->rxq.mark = 0;
861 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
862 rxq_ctrl->flow_tunnels_n[j] = 0;
863 rxq_ctrl->rxq.tunnel = 0;
868 * return a pointer to the desired action in the list of actions.
871 * The list of actions to search the action in.
873 * The action to find.
876 * Pointer to the action in the list, if found. NULL otherwise.
878 const struct rte_flow_action *
879 mlx5_flow_find_action(const struct rte_flow_action *actions,
880 enum rte_flow_action_type action)
884 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
885 if (actions->type == action)
891 * Validate the flag action.
893 * @param[in] action_flags
894 * Bit-fields that holds the actions detected until now.
896 * Attributes of flow that includes this action.
898 * Pointer to error structure.
901 * 0 on success, a negative errno value otherwise and rte_errno is set.
904 mlx5_flow_validate_action_flag(uint64_t action_flags,
905 const struct rte_flow_attr *attr,
906 struct rte_flow_error *error)
909 if (action_flags & MLX5_FLOW_ACTION_DROP)
910 return rte_flow_error_set(error, EINVAL,
911 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
912 "can't drop and flag in same flow");
913 if (action_flags & MLX5_FLOW_ACTION_MARK)
914 return rte_flow_error_set(error, EINVAL,
915 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
916 "can't mark and flag in same flow");
917 if (action_flags & MLX5_FLOW_ACTION_FLAG)
918 return rte_flow_error_set(error, EINVAL,
919 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
921 " actions in same flow");
923 return rte_flow_error_set(error, ENOTSUP,
924 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
925 "flag action not supported for "
931 * Validate the mark action.
934 * Pointer to the queue action.
935 * @param[in] action_flags
936 * Bit-fields that holds the actions detected until now.
938 * Attributes of flow that includes this action.
940 * Pointer to error structure.
943 * 0 on success, a negative errno value otherwise and rte_errno is set.
946 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
947 uint64_t action_flags,
948 const struct rte_flow_attr *attr,
949 struct rte_flow_error *error)
951 const struct rte_flow_action_mark *mark = action->conf;
954 return rte_flow_error_set(error, EINVAL,
955 RTE_FLOW_ERROR_TYPE_ACTION,
957 "configuration cannot be null");
958 if (mark->id >= MLX5_FLOW_MARK_MAX)
959 return rte_flow_error_set(error, EINVAL,
960 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
962 "mark id must in 0 <= id < "
963 RTE_STR(MLX5_FLOW_MARK_MAX));
964 if (action_flags & MLX5_FLOW_ACTION_DROP)
965 return rte_flow_error_set(error, EINVAL,
966 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
967 "can't drop and mark in same flow");
968 if (action_flags & MLX5_FLOW_ACTION_FLAG)
969 return rte_flow_error_set(error, EINVAL,
970 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
971 "can't flag and mark in same flow");
972 if (action_flags & MLX5_FLOW_ACTION_MARK)
973 return rte_flow_error_set(error, EINVAL,
974 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
975 "can't have 2 mark actions in same"
978 return rte_flow_error_set(error, ENOTSUP,
979 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
980 "mark action not supported for "
986 * Validate the drop action.
988 * @param[in] action_flags
989 * Bit-fields that holds the actions detected until now.
991 * Attributes of flow that includes this action.
993 * Pointer to error structure.
996 * 0 on success, a negative errno value otherwise and rte_errno is set.
999 mlx5_flow_validate_action_drop(uint64_t action_flags,
1000 const struct rte_flow_attr *attr,
1001 struct rte_flow_error *error)
1003 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1004 return rte_flow_error_set(error, EINVAL,
1005 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1006 "can't drop and flag in same flow");
1007 if (action_flags & MLX5_FLOW_ACTION_MARK)
1008 return rte_flow_error_set(error, EINVAL,
1009 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1010 "can't drop and mark in same flow");
1011 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
1012 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
1013 return rte_flow_error_set(error, EINVAL,
1014 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1015 "can't have 2 fate actions in"
1018 return rte_flow_error_set(error, ENOTSUP,
1019 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1020 "drop action not supported for "
1026 * Validate the queue action.
1029 * Pointer to the queue action.
1030 * @param[in] action_flags
1031 * Bit-fields that holds the actions detected until now.
1033 * Pointer to the Ethernet device structure.
1035 * Attributes of flow that includes this action.
1037 * Pointer to error structure.
1040 * 0 on success, a negative errno value otherwise and rte_errno is set.
1043 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1044 uint64_t action_flags,
1045 struct rte_eth_dev *dev,
1046 const struct rte_flow_attr *attr,
1047 struct rte_flow_error *error)
1049 struct mlx5_priv *priv = dev->data->dev_private;
1050 const struct rte_flow_action_queue *queue = action->conf;
1052 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1053 return rte_flow_error_set(error, EINVAL,
1054 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1055 "can't have 2 fate actions in"
1058 return rte_flow_error_set(error, EINVAL,
1059 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1060 NULL, "No Rx queues configured");
1061 if (queue->index >= priv->rxqs_n)
1062 return rte_flow_error_set(error, EINVAL,
1063 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1065 "queue index out of range");
1066 if (!(*priv->rxqs)[queue->index])
1067 return rte_flow_error_set(error, EINVAL,
1068 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1070 "queue is not configured");
1072 return rte_flow_error_set(error, ENOTSUP,
1073 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1074 "queue action not supported for "
1080 * Validate the rss action.
1083 * Pointer to the queue action.
1084 * @param[in] action_flags
1085 * Bit-fields that holds the actions detected until now.
1087 * Pointer to the Ethernet device structure.
1089 * Attributes of flow that includes this action.
1090 * @param[in] item_flags
1091 * Items that were detected.
1093 * Pointer to error structure.
1096 * 0 on success, a negative errno value otherwise and rte_errno is set.
1099 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1100 uint64_t action_flags,
1101 struct rte_eth_dev *dev,
1102 const struct rte_flow_attr *attr,
1103 uint64_t item_flags,
1104 struct rte_flow_error *error)
1106 struct mlx5_priv *priv = dev->data->dev_private;
1107 const struct rte_flow_action_rss *rss = action->conf;
1108 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1111 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1112 return rte_flow_error_set(error, EINVAL,
1113 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1114 "can't have 2 fate actions"
1116 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1117 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1118 return rte_flow_error_set(error, ENOTSUP,
1119 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1121 "RSS hash function not supported");
1122 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1127 return rte_flow_error_set(error, ENOTSUP,
1128 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1130 "tunnel RSS is not supported");
1131 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1132 if (rss->key_len == 0 && rss->key != NULL)
1133 return rte_flow_error_set(error, ENOTSUP,
1134 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1136 "RSS hash key length 0");
1137 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1138 return rte_flow_error_set(error, ENOTSUP,
1139 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1141 "RSS hash key too small");
1142 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1143 return rte_flow_error_set(error, ENOTSUP,
1144 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1146 "RSS hash key too large");
1147 if (rss->queue_num > priv->config.ind_table_max_size)
1148 return rte_flow_error_set(error, ENOTSUP,
1149 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1151 "number of queues too large");
1152 if (rss->types & MLX5_RSS_HF_MASK)
1153 return rte_flow_error_set(error, ENOTSUP,
1154 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1156 "some RSS protocols are not"
1158 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1159 !(rss->types & ETH_RSS_IP))
1160 return rte_flow_error_set(error, EINVAL,
1161 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1162 "L3 partial RSS requested but L3 RSS"
1163 " type not specified");
1164 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1165 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1166 return rte_flow_error_set(error, EINVAL,
1167 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1168 "L4 partial RSS requested but L4 RSS"
1169 " type not specified");
1171 return rte_flow_error_set(error, EINVAL,
1172 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1173 NULL, "No Rx queues configured");
1174 if (!rss->queue_num)
1175 return rte_flow_error_set(error, EINVAL,
1176 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1177 NULL, "No queues configured");
1178 for (i = 0; i != rss->queue_num; ++i) {
1179 if (rss->queue[i] >= priv->rxqs_n)
1180 return rte_flow_error_set
1182 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1183 &rss->queue[i], "queue index out of range");
1184 if (!(*priv->rxqs)[rss->queue[i]])
1185 return rte_flow_error_set
1186 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1187 &rss->queue[i], "queue is not configured");
1190 return rte_flow_error_set(error, ENOTSUP,
1191 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1192 "rss action not supported for "
1194 if (rss->level > 1 && !tunnel)
1195 return rte_flow_error_set(error, EINVAL,
1196 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1197 "inner RSS is not supported for "
1198 "non-tunnel flows");
1203 * Validate the count action.
1206 * Pointer to the Ethernet device structure.
1208 * Attributes of flow that includes this action.
1210 * Pointer to error structure.
1213 * 0 on success, a negative errno value otherwise and rte_errno is set.
1216 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1217 const struct rte_flow_attr *attr,
1218 struct rte_flow_error *error)
1221 return rte_flow_error_set(error, ENOTSUP,
1222 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1223 "count action not supported for "
1229 * Verify the @p attributes will be correctly understood by the NIC and store
1230 * them in the @p flow if everything is correct.
1233 * Pointer to the Ethernet device structure.
1234 * @param[in] attributes
1235 * Pointer to flow attributes
1237 * Pointer to error structure.
1240 * 0 on success, a negative errno value otherwise and rte_errno is set.
1243 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1244 const struct rte_flow_attr *attributes,
1245 struct rte_flow_error *error)
1247 struct mlx5_priv *priv = dev->data->dev_private;
1248 uint32_t priority_max = priv->config.flow_prio - 1;
1250 if (attributes->group)
1251 return rte_flow_error_set(error, ENOTSUP,
1252 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1253 NULL, "groups is not supported");
1254 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1255 attributes->priority >= priority_max)
1256 return rte_flow_error_set(error, ENOTSUP,
1257 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1258 NULL, "priority out of range");
1259 if (attributes->egress)
1260 return rte_flow_error_set(error, ENOTSUP,
1261 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1262 "egress is not supported");
1263 if (attributes->transfer && !priv->config.dv_esw_en)
1264 return rte_flow_error_set(error, ENOTSUP,
1265 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1266 NULL, "transfer is not supported");
1267 if (!attributes->ingress)
1268 return rte_flow_error_set(error, EINVAL,
1269 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1271 "ingress attribute is mandatory");
1276 * Validate ICMP6 item.
1279 * Item specification.
1280 * @param[in] item_flags
1281 * Bit-fields that holds the items detected until now.
1283 * Pointer to error structure.
1286 * 0 on success, a negative errno value otherwise and rte_errno is set.
1289 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1290 uint64_t item_flags,
1291 uint8_t target_protocol,
1292 struct rte_flow_error *error)
1294 const struct rte_flow_item_icmp6 *mask = item->mask;
1295 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1296 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1297 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1298 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1299 MLX5_FLOW_LAYER_OUTER_L4;
1302 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1303 return rte_flow_error_set(error, EINVAL,
1304 RTE_FLOW_ERROR_TYPE_ITEM, item,
1305 "protocol filtering not compatible"
1306 " with ICMP6 layer");
1307 if (!(item_flags & l3m))
1308 return rte_flow_error_set(error, EINVAL,
1309 RTE_FLOW_ERROR_TYPE_ITEM, item,
1310 "IPv6 is mandatory to filter on"
1312 if (item_flags & l4m)
1313 return rte_flow_error_set(error, EINVAL,
1314 RTE_FLOW_ERROR_TYPE_ITEM, item,
1315 "multiple L4 layers not supported");
1317 mask = &rte_flow_item_icmp6_mask;
1318 ret = mlx5_flow_item_acceptable
1319 (item, (const uint8_t *)mask,
1320 (const uint8_t *)&rte_flow_item_icmp6_mask,
1321 sizeof(struct rte_flow_item_icmp6), error);
1328 * Validate ICMP item.
1331 * Item specification.
1332 * @param[in] item_flags
1333 * Bit-fields that holds the items detected until now.
1335 * Pointer to error structure.
1338 * 0 on success, a negative errno value otherwise and rte_errno is set.
1341 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1342 uint64_t item_flags,
1343 uint8_t target_protocol,
1344 struct rte_flow_error *error)
1346 const struct rte_flow_item_icmp *mask = item->mask;
1347 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1348 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1349 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1350 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1351 MLX5_FLOW_LAYER_OUTER_L4;
1354 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1355 return rte_flow_error_set(error, EINVAL,
1356 RTE_FLOW_ERROR_TYPE_ITEM, item,
1357 "protocol filtering not compatible"
1358 " with ICMP layer");
1359 if (!(item_flags & l3m))
1360 return rte_flow_error_set(error, EINVAL,
1361 RTE_FLOW_ERROR_TYPE_ITEM, item,
1362 "IPv4 is mandatory to filter"
1364 if (item_flags & l4m)
1365 return rte_flow_error_set(error, EINVAL,
1366 RTE_FLOW_ERROR_TYPE_ITEM, item,
1367 "multiple L4 layers not supported");
1369 mask = &rte_flow_item_icmp_mask;
1370 ret = mlx5_flow_item_acceptable
1371 (item, (const uint8_t *)mask,
1372 (const uint8_t *)&rte_flow_item_icmp_mask,
1373 sizeof(struct rte_flow_item_icmp), error);
1380 * Validate Ethernet item.
1383 * Item specification.
1384 * @param[in] item_flags
1385 * Bit-fields that holds the items detected until now.
1387 * Pointer to error structure.
1390 * 0 on success, a negative errno value otherwise and rte_errno is set.
1393 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1394 uint64_t item_flags,
1395 struct rte_flow_error *error)
1397 const struct rte_flow_item_eth *mask = item->mask;
1398 const struct rte_flow_item_eth nic_mask = {
1399 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1400 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1401 .type = RTE_BE16(0xffff),
1404 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1405 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1406 MLX5_FLOW_LAYER_OUTER_L2;
1408 if (item_flags & ethm)
1409 return rte_flow_error_set(error, ENOTSUP,
1410 RTE_FLOW_ERROR_TYPE_ITEM, item,
1411 "multiple L2 layers not supported");
1412 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1413 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1414 return rte_flow_error_set(error, EINVAL,
1415 RTE_FLOW_ERROR_TYPE_ITEM, item,
1416 "L2 layer should not follow "
1418 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1419 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1420 return rte_flow_error_set(error, EINVAL,
1421 RTE_FLOW_ERROR_TYPE_ITEM, item,
1422 "L2 layer should not follow VLAN");
1424 mask = &rte_flow_item_eth_mask;
1425 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1426 (const uint8_t *)&nic_mask,
1427 sizeof(struct rte_flow_item_eth),
1433 * Validate VLAN item.
1436 * Item specification.
1437 * @param[in] item_flags
1438 * Bit-fields that holds the items detected until now.
1440 * Ethernet device flow is being created on.
1442 * Pointer to error structure.
1445 * 0 on success, a negative errno value otherwise and rte_errno is set.
1448 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1449 uint64_t item_flags,
1450 struct rte_eth_dev *dev,
1451 struct rte_flow_error *error)
1453 const struct rte_flow_item_vlan *spec = item->spec;
1454 const struct rte_flow_item_vlan *mask = item->mask;
1455 const struct rte_flow_item_vlan nic_mask = {
1456 .tci = RTE_BE16(UINT16_MAX),
1457 .inner_type = RTE_BE16(UINT16_MAX),
1459 uint16_t vlan_tag = 0;
1460 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1462 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1463 MLX5_FLOW_LAYER_INNER_L4) :
1464 (MLX5_FLOW_LAYER_OUTER_L3 |
1465 MLX5_FLOW_LAYER_OUTER_L4);
1466 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1467 MLX5_FLOW_LAYER_OUTER_VLAN;
1469 if (item_flags & vlanm)
1470 return rte_flow_error_set(error, EINVAL,
1471 RTE_FLOW_ERROR_TYPE_ITEM, item,
1472 "multiple VLAN layers not supported");
1473 else if ((item_flags & l34m) != 0)
1474 return rte_flow_error_set(error, EINVAL,
1475 RTE_FLOW_ERROR_TYPE_ITEM, item,
1476 "VLAN cannot follow L3/L4 layer");
1478 mask = &rte_flow_item_vlan_mask;
1479 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1480 (const uint8_t *)&nic_mask,
1481 sizeof(struct rte_flow_item_vlan),
1485 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1486 struct mlx5_priv *priv = dev->data->dev_private;
1488 if (priv->vmwa_context) {
1490 * Non-NULL context means we have a virtual machine
1491 * and SR-IOV enabled, we have to create VLAN interface
1492 * to make hypervisor to setup E-Switch vport
1493 * context correctly. We avoid creating the multiple
1494 * VLAN interfaces, so we cannot support VLAN tag mask.
1496 return rte_flow_error_set(error, EINVAL,
1497 RTE_FLOW_ERROR_TYPE_ITEM,
1499 "VLAN tag mask is not"
1500 " supported in virtual"
1505 vlan_tag = spec->tci;
1506 vlan_tag &= mask->tci;
1509 * From verbs perspective an empty VLAN is equivalent
1510 * to a packet without VLAN layer.
1513 return rte_flow_error_set(error, EINVAL,
1514 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1516 "VLAN cannot be empty");
1521 * Validate IPV4 item.
1524 * Item specification.
1525 * @param[in] item_flags
1526 * Bit-fields that holds the items detected until now.
1527 * @param[in] acc_mask
1528 * Acceptable mask, if NULL default internal default mask
1529 * will be used to check whether item fields are supported.
1531 * Pointer to error structure.
1534 * 0 on success, a negative errno value otherwise and rte_errno is set.
1537 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1538 uint64_t item_flags,
1540 uint16_t ether_type,
1541 const struct rte_flow_item_ipv4 *acc_mask,
1542 struct rte_flow_error *error)
1544 const struct rte_flow_item_ipv4 *mask = item->mask;
1545 const struct rte_flow_item_ipv4 *spec = item->spec;
1546 const struct rte_flow_item_ipv4 nic_mask = {
1548 .src_addr = RTE_BE32(0xffffffff),
1549 .dst_addr = RTE_BE32(0xffffffff),
1550 .type_of_service = 0xff,
1551 .next_proto_id = 0xff,
1554 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1555 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1556 MLX5_FLOW_LAYER_OUTER_L3;
1557 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1558 MLX5_FLOW_LAYER_OUTER_L4;
1560 uint8_t next_proto = 0xFF;
1561 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1562 MLX5_FLOW_LAYER_OUTER_VLAN |
1563 MLX5_FLOW_LAYER_INNER_VLAN);
1565 if ((last_item & l2_vlan) && ether_type &&
1566 ether_type != RTE_ETHER_TYPE_IPV4)
1567 return rte_flow_error_set(error, EINVAL,
1568 RTE_FLOW_ERROR_TYPE_ITEM, item,
1569 "IPv4 cannot follow L2/VLAN layer "
1570 "which ether type is not IPv4");
1571 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1573 next_proto = mask->hdr.next_proto_id &
1574 spec->hdr.next_proto_id;
1575 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1576 return rte_flow_error_set(error, EINVAL,
1577 RTE_FLOW_ERROR_TYPE_ITEM,
1582 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1583 return rte_flow_error_set(error, EINVAL,
1584 RTE_FLOW_ERROR_TYPE_ITEM, item,
1585 "wrong tunnel type - IPv6 specified "
1586 "but IPv4 item provided");
1587 if (item_flags & l3m)
1588 return rte_flow_error_set(error, ENOTSUP,
1589 RTE_FLOW_ERROR_TYPE_ITEM, item,
1590 "multiple L3 layers not supported");
1591 else if (item_flags & l4m)
1592 return rte_flow_error_set(error, EINVAL,
1593 RTE_FLOW_ERROR_TYPE_ITEM, item,
1594 "L3 cannot follow an L4 layer.");
1595 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1596 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1597 return rte_flow_error_set(error, EINVAL,
1598 RTE_FLOW_ERROR_TYPE_ITEM, item,
1599 "L3 cannot follow an NVGRE layer.");
1601 mask = &rte_flow_item_ipv4_mask;
1602 else if (mask->hdr.next_proto_id != 0 &&
1603 mask->hdr.next_proto_id != 0xff)
1604 return rte_flow_error_set(error, EINVAL,
1605 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1606 "partial mask is not supported"
1608 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1609 acc_mask ? (const uint8_t *)acc_mask
1610 : (const uint8_t *)&nic_mask,
1611 sizeof(struct rte_flow_item_ipv4),
1619 * Validate IPV6 item.
1622 * Item specification.
1623 * @param[in] item_flags
1624 * Bit-fields that holds the items detected until now.
1625 * @param[in] acc_mask
1626 * Acceptable mask, if NULL default internal default mask
1627 * will be used to check whether item fields are supported.
1629 * Pointer to error structure.
1632 * 0 on success, a negative errno value otherwise and rte_errno is set.
1635 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1636 uint64_t item_flags,
1638 uint16_t ether_type,
1639 const struct rte_flow_item_ipv6 *acc_mask,
1640 struct rte_flow_error *error)
1642 const struct rte_flow_item_ipv6 *mask = item->mask;
1643 const struct rte_flow_item_ipv6 *spec = item->spec;
1644 const struct rte_flow_item_ipv6 nic_mask = {
1647 "\xff\xff\xff\xff\xff\xff\xff\xff"
1648 "\xff\xff\xff\xff\xff\xff\xff\xff",
1650 "\xff\xff\xff\xff\xff\xff\xff\xff"
1651 "\xff\xff\xff\xff\xff\xff\xff\xff",
1652 .vtc_flow = RTE_BE32(0xffffffff),
1657 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1658 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1659 MLX5_FLOW_LAYER_OUTER_L3;
1660 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1661 MLX5_FLOW_LAYER_OUTER_L4;
1663 uint8_t next_proto = 0xFF;
1664 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1665 MLX5_FLOW_LAYER_OUTER_VLAN |
1666 MLX5_FLOW_LAYER_INNER_VLAN);
1668 if ((last_item & l2_vlan) && ether_type &&
1669 ether_type != RTE_ETHER_TYPE_IPV6)
1670 return rte_flow_error_set(error, EINVAL,
1671 RTE_FLOW_ERROR_TYPE_ITEM, item,
1672 "IPv6 cannot follow L2/VLAN layer "
1673 "which ether type is not IPv6");
1674 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
1676 next_proto = mask->hdr.proto & spec->hdr.proto;
1677 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1678 return rte_flow_error_set(error, EINVAL,
1679 RTE_FLOW_ERROR_TYPE_ITEM,
1684 if (item_flags & MLX5_FLOW_LAYER_IPIP)
1685 return rte_flow_error_set(error, EINVAL,
1686 RTE_FLOW_ERROR_TYPE_ITEM, item,
1687 "wrong tunnel type - IPv4 specified "
1688 "but IPv6 item provided");
1689 if (item_flags & l3m)
1690 return rte_flow_error_set(error, ENOTSUP,
1691 RTE_FLOW_ERROR_TYPE_ITEM, item,
1692 "multiple L3 layers not supported");
1693 else if (item_flags & l4m)
1694 return rte_flow_error_set(error, EINVAL,
1695 RTE_FLOW_ERROR_TYPE_ITEM, item,
1696 "L3 cannot follow an L4 layer.");
1697 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1698 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1699 return rte_flow_error_set(error, EINVAL,
1700 RTE_FLOW_ERROR_TYPE_ITEM, item,
1701 "L3 cannot follow an NVGRE layer.");
1703 mask = &rte_flow_item_ipv6_mask;
1704 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1705 acc_mask ? (const uint8_t *)acc_mask
1706 : (const uint8_t *)&nic_mask,
1707 sizeof(struct rte_flow_item_ipv6),
1715 * Validate UDP item.
1718 * Item specification.
1719 * @param[in] item_flags
1720 * Bit-fields that holds the items detected until now.
1721 * @param[in] target_protocol
1722 * The next protocol in the previous item.
1723 * @param[in] flow_mask
1724 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
1726 * Pointer to error structure.
1729 * 0 on success, a negative errno value otherwise and rte_errno is set.
1732 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1733 uint64_t item_flags,
1734 uint8_t target_protocol,
1735 struct rte_flow_error *error)
1737 const struct rte_flow_item_udp *mask = item->mask;
1738 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1739 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1740 MLX5_FLOW_LAYER_OUTER_L3;
1741 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1742 MLX5_FLOW_LAYER_OUTER_L4;
1745 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1746 return rte_flow_error_set(error, EINVAL,
1747 RTE_FLOW_ERROR_TYPE_ITEM, item,
1748 "protocol filtering not compatible"
1750 if (!(item_flags & l3m))
1751 return rte_flow_error_set(error, EINVAL,
1752 RTE_FLOW_ERROR_TYPE_ITEM, item,
1753 "L3 is mandatory to filter on L4");
1754 if (item_flags & l4m)
1755 return rte_flow_error_set(error, EINVAL,
1756 RTE_FLOW_ERROR_TYPE_ITEM, item,
1757 "multiple L4 layers not supported");
1759 mask = &rte_flow_item_udp_mask;
1760 ret = mlx5_flow_item_acceptable
1761 (item, (const uint8_t *)mask,
1762 (const uint8_t *)&rte_flow_item_udp_mask,
1763 sizeof(struct rte_flow_item_udp), error);
1770 * Validate TCP item.
1773 * Item specification.
1774 * @param[in] item_flags
1775 * Bit-fields that holds the items detected until now.
1776 * @param[in] target_protocol
1777 * The next protocol in the previous item.
1779 * Pointer to error structure.
1782 * 0 on success, a negative errno value otherwise and rte_errno is set.
1785 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1786 uint64_t item_flags,
1787 uint8_t target_protocol,
1788 const struct rte_flow_item_tcp *flow_mask,
1789 struct rte_flow_error *error)
1791 const struct rte_flow_item_tcp *mask = item->mask;
1792 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1793 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1794 MLX5_FLOW_LAYER_OUTER_L3;
1795 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1796 MLX5_FLOW_LAYER_OUTER_L4;
1800 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1801 return rte_flow_error_set(error, EINVAL,
1802 RTE_FLOW_ERROR_TYPE_ITEM, item,
1803 "protocol filtering not compatible"
1805 if (!(item_flags & l3m))
1806 return rte_flow_error_set(error, EINVAL,
1807 RTE_FLOW_ERROR_TYPE_ITEM, item,
1808 "L3 is mandatory to filter on L4");
1809 if (item_flags & l4m)
1810 return rte_flow_error_set(error, EINVAL,
1811 RTE_FLOW_ERROR_TYPE_ITEM, item,
1812 "multiple L4 layers not supported");
1814 mask = &rte_flow_item_tcp_mask;
1815 ret = mlx5_flow_item_acceptable
1816 (item, (const uint8_t *)mask,
1817 (const uint8_t *)flow_mask,
1818 sizeof(struct rte_flow_item_tcp), error);
1825 * Validate VXLAN item.
1828 * Item specification.
1829 * @param[in] item_flags
1830 * Bit-fields that holds the items detected until now.
1831 * @param[in] target_protocol
1832 * The next protocol in the previous item.
1834 * Pointer to error structure.
1837 * 0 on success, a negative errno value otherwise and rte_errno is set.
1840 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1841 uint64_t item_flags,
1842 struct rte_flow_error *error)
1844 const struct rte_flow_item_vxlan *spec = item->spec;
1845 const struct rte_flow_item_vxlan *mask = item->mask;
1850 } id = { .vlan_id = 0, };
1851 uint32_t vlan_id = 0;
1854 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1855 return rte_flow_error_set(error, ENOTSUP,
1856 RTE_FLOW_ERROR_TYPE_ITEM, item,
1857 "multiple tunnel layers not"
1860 * Verify only UDPv4 is present as defined in
1861 * https://tools.ietf.org/html/rfc7348
1863 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1864 return rte_flow_error_set(error, EINVAL,
1865 RTE_FLOW_ERROR_TYPE_ITEM, item,
1866 "no outer UDP layer found");
1868 mask = &rte_flow_item_vxlan_mask;
1869 ret = mlx5_flow_item_acceptable
1870 (item, (const uint8_t *)mask,
1871 (const uint8_t *)&rte_flow_item_vxlan_mask,
1872 sizeof(struct rte_flow_item_vxlan),
1877 memcpy(&id.vni[1], spec->vni, 3);
1878 vlan_id = id.vlan_id;
1879 memcpy(&id.vni[1], mask->vni, 3);
1880 vlan_id &= id.vlan_id;
1883 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1884 * only this layer is defined in the Verbs specification it is
1885 * interpreted as wildcard and all packets will match this
1886 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1887 * udp), all packets matching the layers before will also
1888 * match this rule. To avoid such situation, VNI 0 is
1889 * currently refused.
1892 return rte_flow_error_set(error, ENOTSUP,
1893 RTE_FLOW_ERROR_TYPE_ITEM, item,
1894 "VXLAN vni cannot be 0");
1895 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1896 return rte_flow_error_set(error, ENOTSUP,
1897 RTE_FLOW_ERROR_TYPE_ITEM, item,
1898 "VXLAN tunnel must be fully defined");
1903 * Validate VXLAN_GPE item.
1906 * Item specification.
1907 * @param[in] item_flags
1908 * Bit-fields that holds the items detected until now.
1910 * Pointer to the private data structure.
1911 * @param[in] target_protocol
1912 * The next protocol in the previous item.
1914 * Pointer to error structure.
1917 * 0 on success, a negative errno value otherwise and rte_errno is set.
1920 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1921 uint64_t item_flags,
1922 struct rte_eth_dev *dev,
1923 struct rte_flow_error *error)
1925 struct mlx5_priv *priv = dev->data->dev_private;
1926 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1927 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1932 } id = { .vlan_id = 0, };
1933 uint32_t vlan_id = 0;
1935 if (!priv->config.l3_vxlan_en)
1936 return rte_flow_error_set(error, ENOTSUP,
1937 RTE_FLOW_ERROR_TYPE_ITEM, item,
1938 "L3 VXLAN is not enabled by device"
1939 " parameter and/or not configured in"
1941 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1942 return rte_flow_error_set(error, ENOTSUP,
1943 RTE_FLOW_ERROR_TYPE_ITEM, item,
1944 "multiple tunnel layers not"
1947 * Verify only UDPv4 is present as defined in
1948 * https://tools.ietf.org/html/rfc7348
1950 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1951 return rte_flow_error_set(error, EINVAL,
1952 RTE_FLOW_ERROR_TYPE_ITEM, item,
1953 "no outer UDP layer found");
1955 mask = &rte_flow_item_vxlan_gpe_mask;
1956 ret = mlx5_flow_item_acceptable
1957 (item, (const uint8_t *)mask,
1958 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1959 sizeof(struct rte_flow_item_vxlan_gpe),
1965 return rte_flow_error_set(error, ENOTSUP,
1966 RTE_FLOW_ERROR_TYPE_ITEM,
1968 "VxLAN-GPE protocol"
1970 memcpy(&id.vni[1], spec->vni, 3);
1971 vlan_id = id.vlan_id;
1972 memcpy(&id.vni[1], mask->vni, 3);
1973 vlan_id &= id.vlan_id;
1976 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1977 * layer is defined in the Verbs specification it is interpreted as
1978 * wildcard and all packets will match this rule, if it follows a full
1979 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1980 * before will also match this rule. To avoid such situation, VNI 0
1981 * is currently refused.
1984 return rte_flow_error_set(error, ENOTSUP,
1985 RTE_FLOW_ERROR_TYPE_ITEM, item,
1986 "VXLAN-GPE vni cannot be 0");
1987 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1988 return rte_flow_error_set(error, ENOTSUP,
1989 RTE_FLOW_ERROR_TYPE_ITEM, item,
1990 "VXLAN-GPE tunnel must be fully"
1995 * Validate GRE Key item.
1998 * Item specification.
1999 * @param[in] item_flags
2000 * Bit flags to mark detected items.
2001 * @param[in] gre_item
2002 * Pointer to gre_item
2004 * Pointer to error structure.
2007 * 0 on success, a negative errno value otherwise and rte_errno is set.
2010 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2011 uint64_t item_flags,
2012 const struct rte_flow_item *gre_item,
2013 struct rte_flow_error *error)
2015 const rte_be32_t *mask = item->mask;
2017 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2018 const struct rte_flow_item_gre *gre_spec;
2019 const struct rte_flow_item_gre *gre_mask;
2021 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2022 return rte_flow_error_set(error, ENOTSUP,
2023 RTE_FLOW_ERROR_TYPE_ITEM, item,
2024 "Multiple GRE key not support");
2025 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2026 return rte_flow_error_set(error, ENOTSUP,
2027 RTE_FLOW_ERROR_TYPE_ITEM, item,
2028 "No preceding GRE header");
2029 if (item_flags & MLX5_FLOW_LAYER_INNER)
2030 return rte_flow_error_set(error, ENOTSUP,
2031 RTE_FLOW_ERROR_TYPE_ITEM, item,
2032 "GRE key following a wrong item");
2033 gre_mask = gre_item->mask;
2035 gre_mask = &rte_flow_item_gre_mask;
2036 gre_spec = gre_item->spec;
2037 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2038 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2039 return rte_flow_error_set(error, EINVAL,
2040 RTE_FLOW_ERROR_TYPE_ITEM, item,
2041 "Key bit must be on");
2044 mask = &gre_key_default_mask;
2045 ret = mlx5_flow_item_acceptable
2046 (item, (const uint8_t *)mask,
2047 (const uint8_t *)&gre_key_default_mask,
2048 sizeof(rte_be32_t), error);
2053 * Validate GRE item.
2056 * Item specification.
2057 * @param[in] item_flags
2058 * Bit flags to mark detected items.
2059 * @param[in] target_protocol
2060 * The next protocol in the previous item.
2062 * Pointer to error structure.
2065 * 0 on success, a negative errno value otherwise and rte_errno is set.
2068 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2069 uint64_t item_flags,
2070 uint8_t target_protocol,
2071 struct rte_flow_error *error)
2073 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2074 const struct rte_flow_item_gre *mask = item->mask;
2076 const struct rte_flow_item_gre nic_mask = {
2077 .c_rsvd0_ver = RTE_BE16(0xB000),
2078 .protocol = RTE_BE16(UINT16_MAX),
2081 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2082 return rte_flow_error_set(error, EINVAL,
2083 RTE_FLOW_ERROR_TYPE_ITEM, item,
2084 "protocol filtering not compatible"
2085 " with this GRE layer");
2086 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2087 return rte_flow_error_set(error, ENOTSUP,
2088 RTE_FLOW_ERROR_TYPE_ITEM, item,
2089 "multiple tunnel layers not"
2091 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2092 return rte_flow_error_set(error, ENOTSUP,
2093 RTE_FLOW_ERROR_TYPE_ITEM, item,
2094 "L3 Layer is missing");
2096 mask = &rte_flow_item_gre_mask;
2097 ret = mlx5_flow_item_acceptable
2098 (item, (const uint8_t *)mask,
2099 (const uint8_t *)&nic_mask,
2100 sizeof(struct rte_flow_item_gre), error);
2103 #ifndef HAVE_MLX5DV_DR
2104 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2105 if (spec && (spec->protocol & mask->protocol))
2106 return rte_flow_error_set(error, ENOTSUP,
2107 RTE_FLOW_ERROR_TYPE_ITEM, item,
2108 "without MPLS support the"
2109 " specification cannot be used for"
2117 * Validate Geneve item.
2120 * Item specification.
2121 * @param[in] itemFlags
2122 * Bit-fields that holds the items detected until now.
2124 * Pointer to the private data structure.
2126 * Pointer to error structure.
2129 * 0 on success, a negative errno value otherwise and rte_errno is set.
2133 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2134 uint64_t item_flags,
2135 struct rte_eth_dev *dev,
2136 struct rte_flow_error *error)
2138 struct mlx5_priv *priv = dev->data->dev_private;
2139 const struct rte_flow_item_geneve *spec = item->spec;
2140 const struct rte_flow_item_geneve *mask = item->mask;
2143 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2144 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2145 const struct rte_flow_item_geneve nic_mask = {
2146 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2147 .vni = "\xff\xff\xff",
2148 .protocol = RTE_BE16(UINT16_MAX),
2151 if (!(priv->config.hca_attr.flex_parser_protocols &
2152 MLX5_HCA_FLEX_GENEVE_ENABLED) ||
2153 !priv->config.hca_attr.tunnel_stateless_geneve_rx)
2154 return rte_flow_error_set(error, ENOTSUP,
2155 RTE_FLOW_ERROR_TYPE_ITEM, item,
2156 "L3 Geneve is not enabled by device"
2157 " parameter and/or not configured in"
2159 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2160 return rte_flow_error_set(error, ENOTSUP,
2161 RTE_FLOW_ERROR_TYPE_ITEM, item,
2162 "multiple tunnel layers not"
2165 * Verify only UDPv4 is present as defined in
2166 * https://tools.ietf.org/html/rfc7348
2168 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2169 return rte_flow_error_set(error, EINVAL,
2170 RTE_FLOW_ERROR_TYPE_ITEM, item,
2171 "no outer UDP layer found");
2173 mask = &rte_flow_item_geneve_mask;
2174 ret = mlx5_flow_item_acceptable
2175 (item, (const uint8_t *)mask,
2176 (const uint8_t *)&nic_mask,
2177 sizeof(struct rte_flow_item_geneve), error);
2181 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2182 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2183 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2184 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2185 return rte_flow_error_set(error, ENOTSUP,
2186 RTE_FLOW_ERROR_TYPE_ITEM,
2188 "Geneve protocol unsupported"
2189 " fields are being used");
2190 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2191 return rte_flow_error_set
2193 RTE_FLOW_ERROR_TYPE_ITEM,
2195 "Unsupported Geneve options length");
2197 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2198 return rte_flow_error_set
2200 RTE_FLOW_ERROR_TYPE_ITEM, item,
2201 "Geneve tunnel must be fully defined");
2206 * Validate MPLS item.
2209 * Pointer to the rte_eth_dev structure.
2211 * Item specification.
2212 * @param[in] item_flags
2213 * Bit-fields that holds the items detected until now.
2214 * @param[in] prev_layer
2215 * The protocol layer indicated in previous item.
2217 * Pointer to error structure.
2220 * 0 on success, a negative errno value otherwise and rte_errno is set.
2223 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2224 const struct rte_flow_item *item __rte_unused,
2225 uint64_t item_flags __rte_unused,
2226 uint64_t prev_layer __rte_unused,
2227 struct rte_flow_error *error)
2229 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2230 const struct rte_flow_item_mpls *mask = item->mask;
2231 struct mlx5_priv *priv = dev->data->dev_private;
2234 if (!priv->config.mpls_en)
2235 return rte_flow_error_set(error, ENOTSUP,
2236 RTE_FLOW_ERROR_TYPE_ITEM, item,
2237 "MPLS not supported or"
2238 " disabled in firmware"
2240 /* MPLS over IP, UDP, GRE is allowed */
2241 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2242 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2243 MLX5_FLOW_LAYER_GRE)))
2244 return rte_flow_error_set(error, EINVAL,
2245 RTE_FLOW_ERROR_TYPE_ITEM, item,
2246 "protocol filtering not compatible"
2247 " with MPLS layer");
2248 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2249 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2250 !(item_flags & MLX5_FLOW_LAYER_GRE))
2251 return rte_flow_error_set(error, ENOTSUP,
2252 RTE_FLOW_ERROR_TYPE_ITEM, item,
2253 "multiple tunnel layers not"
2256 mask = &rte_flow_item_mpls_mask;
2257 ret = mlx5_flow_item_acceptable
2258 (item, (const uint8_t *)mask,
2259 (const uint8_t *)&rte_flow_item_mpls_mask,
2260 sizeof(struct rte_flow_item_mpls), error);
2265 return rte_flow_error_set(error, ENOTSUP,
2266 RTE_FLOW_ERROR_TYPE_ITEM, item,
2267 "MPLS is not supported by Verbs, please"
2272 * Validate NVGRE item.
2275 * Item specification.
2276 * @param[in] item_flags
2277 * Bit flags to mark detected items.
2278 * @param[in] target_protocol
2279 * The next protocol in the previous item.
2281 * Pointer to error structure.
2284 * 0 on success, a negative errno value otherwise and rte_errno is set.
2287 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2288 uint64_t item_flags,
2289 uint8_t target_protocol,
2290 struct rte_flow_error *error)
2292 const struct rte_flow_item_nvgre *mask = item->mask;
2295 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2296 return rte_flow_error_set(error, EINVAL,
2297 RTE_FLOW_ERROR_TYPE_ITEM, item,
2298 "protocol filtering not compatible"
2299 " with this GRE layer");
2300 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2301 return rte_flow_error_set(error, ENOTSUP,
2302 RTE_FLOW_ERROR_TYPE_ITEM, item,
2303 "multiple tunnel layers not"
2305 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2306 return rte_flow_error_set(error, ENOTSUP,
2307 RTE_FLOW_ERROR_TYPE_ITEM, item,
2308 "L3 Layer is missing");
2310 mask = &rte_flow_item_nvgre_mask;
2311 ret = mlx5_flow_item_acceptable
2312 (item, (const uint8_t *)mask,
2313 (const uint8_t *)&rte_flow_item_nvgre_mask,
2314 sizeof(struct rte_flow_item_nvgre), error);
2320 /* Allocate unique ID for the split Q/RSS subflows. */
2322 flow_qrss_get_id(struct rte_eth_dev *dev)
2324 struct mlx5_priv *priv = dev->data->dev_private;
2325 uint32_t qrss_id, ret;
2327 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2334 /* Free unique ID for the split Q/RSS subflows. */
2336 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2338 struct mlx5_priv *priv = dev->data->dev_private;
2341 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2345 * Release resource related QUEUE/RSS action split.
2348 * Pointer to Ethernet device.
2350 * Flow to release id's from.
2353 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2354 struct rte_flow *flow)
2356 struct mlx5_flow *dev_flow;
2358 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
2359 if (dev_flow->qrss_id)
2360 flow_qrss_free_id(dev, dev_flow->qrss_id);
2364 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2365 const struct rte_flow_attr *attr __rte_unused,
2366 const struct rte_flow_item items[] __rte_unused,
2367 const struct rte_flow_action actions[] __rte_unused,
2368 bool external __rte_unused,
2369 struct rte_flow_error *error)
2371 return rte_flow_error_set(error, ENOTSUP,
2372 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2375 static struct mlx5_flow *
2376 flow_null_prepare(const struct rte_flow_attr *attr __rte_unused,
2377 const struct rte_flow_item items[] __rte_unused,
2378 const struct rte_flow_action actions[] __rte_unused,
2379 struct rte_flow_error *error)
2381 rte_flow_error_set(error, ENOTSUP,
2382 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2387 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2388 struct mlx5_flow *dev_flow __rte_unused,
2389 const struct rte_flow_attr *attr __rte_unused,
2390 const struct rte_flow_item items[] __rte_unused,
2391 const struct rte_flow_action actions[] __rte_unused,
2392 struct rte_flow_error *error)
2394 return rte_flow_error_set(error, ENOTSUP,
2395 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2399 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2400 struct rte_flow *flow __rte_unused,
2401 struct rte_flow_error *error)
2403 return rte_flow_error_set(error, ENOTSUP,
2404 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2408 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2409 struct rte_flow *flow __rte_unused)
2414 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2415 struct rte_flow *flow __rte_unused)
2420 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2421 struct rte_flow *flow __rte_unused,
2422 const struct rte_flow_action *actions __rte_unused,
2423 void *data __rte_unused,
2424 struct rte_flow_error *error)
2426 return rte_flow_error_set(error, ENOTSUP,
2427 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2430 /* Void driver to protect from null pointer reference. */
2431 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2432 .validate = flow_null_validate,
2433 .prepare = flow_null_prepare,
2434 .translate = flow_null_translate,
2435 .apply = flow_null_apply,
2436 .remove = flow_null_remove,
2437 .destroy = flow_null_destroy,
2438 .query = flow_null_query,
2442 * Select flow driver type according to flow attributes and device
2446 * Pointer to the dev structure.
2448 * Pointer to the flow attributes.
2451 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2453 static enum mlx5_flow_drv_type
2454 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2456 struct mlx5_priv *priv = dev->data->dev_private;
2457 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
2459 if (attr->transfer && priv->config.dv_esw_en)
2460 type = MLX5_FLOW_TYPE_DV;
2461 if (!attr->transfer)
2462 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2463 MLX5_FLOW_TYPE_VERBS;
2467 #define flow_get_drv_ops(type) flow_drv_ops[type]
2470 * Flow driver validation API. This abstracts calling driver specific functions.
2471 * The type of flow driver is determined according to flow attributes.
2474 * Pointer to the dev structure.
2476 * Pointer to the flow attributes.
2478 * Pointer to the list of items.
2479 * @param[in] actions
2480 * Pointer to the list of actions.
2481 * @param[in] external
2482 * This flow rule is created by request external to PMD.
2484 * Pointer to the error structure.
2487 * 0 on success, a negative errno value otherwise and rte_errno is set.
2490 flow_drv_validate(struct rte_eth_dev *dev,
2491 const struct rte_flow_attr *attr,
2492 const struct rte_flow_item items[],
2493 const struct rte_flow_action actions[],
2494 bool external, struct rte_flow_error *error)
2496 const struct mlx5_flow_driver_ops *fops;
2497 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2499 fops = flow_get_drv_ops(type);
2500 return fops->validate(dev, attr, items, actions, external, error);
2504 * Flow driver preparation API. This abstracts calling driver specific
2505 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2506 * calculates the size of memory required for device flow, allocates the memory,
2507 * initializes the device flow and returns the pointer.
2510 * This function initializes device flow structure such as dv or verbs in
2511 * struct mlx5_flow. However, it is caller's responsibility to initialize the
2512 * rest. For example, adding returning device flow to flow->dev_flow list and
2513 * setting backward reference to the flow should be done out of this function.
2514 * layers field is not filled either.
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 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
2528 static inline struct mlx5_flow *
2529 flow_drv_prepare(const struct rte_flow *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 = flow->drv_type;
2538 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2539 fops = flow_get_drv_ops(type);
2540 return fops->prepare(attr, items, actions, error);
2544 * Flow driver translation API. This abstracts calling driver specific
2545 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2546 * translates a generic flow into a driver flow. flow_drv_prepare() must
2550 * dev_flow->layers could be filled as a result of parsing during translation
2551 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
2552 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
2553 * flow->actions could be overwritten even though all the expanded dev_flows
2554 * have the same actions.
2557 * Pointer to the rte dev structure.
2558 * @param[in, out] dev_flow
2559 * Pointer to the mlx5 flow.
2561 * Pointer to the flow attributes.
2563 * Pointer to the list of items.
2564 * @param[in] actions
2565 * Pointer to the list of actions.
2567 * Pointer to the error structure.
2570 * 0 on success, a negative errno value otherwise and rte_errno is set.
2573 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
2574 const struct rte_flow_attr *attr,
2575 const struct rte_flow_item items[],
2576 const struct rte_flow_action actions[],
2577 struct rte_flow_error *error)
2579 const struct mlx5_flow_driver_ops *fops;
2580 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
2582 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2583 fops = flow_get_drv_ops(type);
2584 return fops->translate(dev, dev_flow, attr, items, actions, error);
2588 * Flow driver apply API. This abstracts calling driver specific functions.
2589 * Parent flow (rte_flow) should have driver type (drv_type). It applies
2590 * translated driver flows on to device. flow_drv_translate() must precede.
2593 * Pointer to Ethernet device structure.
2594 * @param[in, out] flow
2595 * Pointer to flow structure.
2597 * Pointer to error structure.
2600 * 0 on success, a negative errno value otherwise and rte_errno is set.
2603 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
2604 struct rte_flow_error *error)
2606 const struct mlx5_flow_driver_ops *fops;
2607 enum mlx5_flow_drv_type type = flow->drv_type;
2609 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2610 fops = flow_get_drv_ops(type);
2611 return fops->apply(dev, flow, error);
2615 * Flow driver remove API. This abstracts calling driver specific functions.
2616 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2617 * on device. All the resources of the flow should be freed by calling
2618 * flow_drv_destroy().
2621 * Pointer to Ethernet device.
2622 * @param[in, out] flow
2623 * Pointer to flow structure.
2626 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
2628 const struct mlx5_flow_driver_ops *fops;
2629 enum mlx5_flow_drv_type type = flow->drv_type;
2631 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2632 fops = flow_get_drv_ops(type);
2633 fops->remove(dev, flow);
2637 * Flow driver destroy API. This abstracts calling driver specific functions.
2638 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2639 * on device and releases resources of the flow.
2642 * Pointer to Ethernet device.
2643 * @param[in, out] flow
2644 * Pointer to flow structure.
2647 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
2649 const struct mlx5_flow_driver_ops *fops;
2650 enum mlx5_flow_drv_type type = flow->drv_type;
2652 flow_mreg_split_qrss_release(dev, flow);
2653 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2654 fops = flow_get_drv_ops(type);
2655 fops->destroy(dev, flow);
2659 * Validate a flow supported by the NIC.
2661 * @see rte_flow_validate()
2665 mlx5_flow_validate(struct rte_eth_dev *dev,
2666 const struct rte_flow_attr *attr,
2667 const struct rte_flow_item items[],
2668 const struct rte_flow_action actions[],
2669 struct rte_flow_error *error)
2673 ret = flow_drv_validate(dev, attr, items, actions, true, error);
2680 * Get port id item from the item list.
2683 * Pointer to the list of items.
2686 * Pointer to the port id item if exist, else return NULL.
2688 static const struct rte_flow_item *
2689 find_port_id_item(const struct rte_flow_item *item)
2692 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2693 if (item->type == RTE_FLOW_ITEM_TYPE_PORT_ID)
2700 * Get RSS action from the action list.
2702 * @param[in] actions
2703 * Pointer to the list of actions.
2706 * Pointer to the RSS action if exist, else return NULL.
2708 static const struct rte_flow_action_rss*
2709 flow_get_rss_action(const struct rte_flow_action actions[])
2711 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2712 switch (actions->type) {
2713 case RTE_FLOW_ACTION_TYPE_RSS:
2714 return (const struct rte_flow_action_rss *)
2724 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
2726 const struct rte_flow_item *item;
2727 unsigned int has_vlan = 0;
2729 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2730 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2736 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
2737 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
2738 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
2739 MLX5_EXPANSION_ROOT_OUTER;
2743 * Get QUEUE/RSS action from the action list.
2745 * @param[in] actions
2746 * Pointer to the list of actions.
2748 * Pointer to the return pointer.
2749 * @param[out] qrss_type
2750 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
2751 * if no QUEUE/RSS is found.
2754 * Total number of actions.
2757 flow_parse_qrss_action(const struct rte_flow_action actions[],
2758 const struct rte_flow_action **qrss)
2762 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2763 switch (actions->type) {
2764 case RTE_FLOW_ACTION_TYPE_QUEUE:
2765 case RTE_FLOW_ACTION_TYPE_RSS:
2773 /* Count RTE_FLOW_ACTION_TYPE_END. */
2774 return actions_n + 1;
2778 * Check meter action from the action list.
2780 * @param[in] actions
2781 * Pointer to the list of actions.
2783 * Pointer to the meter exist flag.
2786 * Total number of actions.
2789 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
2795 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2796 switch (actions->type) {
2797 case RTE_FLOW_ACTION_TYPE_METER:
2805 /* Count RTE_FLOW_ACTION_TYPE_END. */
2806 return actions_n + 1;
2810 * Check if the flow should be splited due to hairpin.
2811 * The reason for the split is that in current HW we can't
2812 * support encap on Rx, so if a flow have encap we move it
2816 * Pointer to Ethernet device.
2818 * Flow rule attributes.
2819 * @param[in] actions
2820 * Associated actions (list terminated by the END action).
2823 * > 0 the number of actions and the flow should be split,
2824 * 0 when no split required.
2827 flow_check_hairpin_split(struct rte_eth_dev *dev,
2828 const struct rte_flow_attr *attr,
2829 const struct rte_flow_action actions[])
2831 int queue_action = 0;
2834 const struct rte_flow_action_queue *queue;
2835 const struct rte_flow_action_rss *rss;
2836 const struct rte_flow_action_raw_encap *raw_encap;
2840 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2841 switch (actions->type) {
2842 case RTE_FLOW_ACTION_TYPE_QUEUE:
2843 queue = actions->conf;
2846 if (mlx5_rxq_get_type(dev, queue->index) !=
2847 MLX5_RXQ_TYPE_HAIRPIN)
2852 case RTE_FLOW_ACTION_TYPE_RSS:
2853 rss = actions->conf;
2854 if (rss == NULL || rss->queue_num == 0)
2856 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
2857 MLX5_RXQ_TYPE_HAIRPIN)
2862 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2863 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2867 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2868 raw_encap = actions->conf;
2869 if (raw_encap->size >
2870 (sizeof(struct rte_flow_item_eth) +
2871 sizeof(struct rte_flow_item_ipv4)))
2880 if (encap == 1 && queue_action)
2885 /* Declare flow create/destroy prototype in advance. */
2886 static struct rte_flow *
2887 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
2888 const struct rte_flow_attr *attr,
2889 const struct rte_flow_item items[],
2890 const struct rte_flow_action actions[],
2891 bool external, struct rte_flow_error *error);
2894 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
2895 struct rte_flow *flow);
2898 * Add a flow of copying flow metadata registers in RX_CP_TBL.
2900 * As mark_id is unique, if there's already a registered flow for the mark_id,
2901 * return by increasing the reference counter of the resource. Otherwise, create
2902 * the resource (mcp_res) and flow.
2905 * - If ingress port is ANY and reg_c[1] is mark_id,
2906 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
2908 * For default flow (zero mark_id), flow is like,
2909 * - If ingress port is ANY,
2910 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
2913 * Pointer to Ethernet device.
2915 * ID of MARK action, zero means default flow for META.
2917 * Perform verbose error reporting if not NULL.
2920 * Associated resource on success, NULL otherwise and rte_errno is set.
2922 static struct mlx5_flow_mreg_copy_resource *
2923 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
2924 struct rte_flow_error *error)
2926 struct mlx5_priv *priv = dev->data->dev_private;
2927 struct rte_flow_attr attr = {
2928 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
2931 struct mlx5_rte_flow_item_tag tag_spec = {
2934 struct rte_flow_item items[] = {
2935 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
2937 struct rte_flow_action_mark ftag = {
2940 struct mlx5_flow_action_copy_mreg cp_mreg = {
2944 struct rte_flow_action_jump jump = {
2945 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
2947 struct rte_flow_action actions[] = {
2948 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
2950 struct mlx5_flow_mreg_copy_resource *mcp_res;
2953 /* Fill the register fileds in the flow. */
2954 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2958 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
2962 /* Check if already registered. */
2963 assert(priv->mreg_cp_tbl);
2964 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
2966 /* For non-default rule. */
2967 if (mark_id != MLX5_DEFAULT_COPY_ID)
2969 assert(mark_id != MLX5_DEFAULT_COPY_ID || mcp_res->refcnt == 1);
2972 /* Provide the full width of FLAG specific value. */
2973 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
2974 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
2975 /* Build a new flow. */
2976 if (mark_id != MLX5_DEFAULT_COPY_ID) {
2977 items[0] = (struct rte_flow_item){
2978 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
2981 items[1] = (struct rte_flow_item){
2982 .type = RTE_FLOW_ITEM_TYPE_END,
2984 actions[0] = (struct rte_flow_action){
2985 .type = MLX5_RTE_FLOW_ACTION_TYPE_MARK,
2988 actions[1] = (struct rte_flow_action){
2989 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
2992 actions[2] = (struct rte_flow_action){
2993 .type = RTE_FLOW_ACTION_TYPE_JUMP,
2996 actions[3] = (struct rte_flow_action){
2997 .type = RTE_FLOW_ACTION_TYPE_END,
3000 /* Default rule, wildcard match. */
3001 attr.priority = MLX5_FLOW_PRIO_RSVD;
3002 items[0] = (struct rte_flow_item){
3003 .type = RTE_FLOW_ITEM_TYPE_END,
3005 actions[0] = (struct rte_flow_action){
3006 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3009 actions[1] = (struct rte_flow_action){
3010 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3013 actions[2] = (struct rte_flow_action){
3014 .type = RTE_FLOW_ACTION_TYPE_END,
3017 /* Build a new entry. */
3018 mcp_res = rte_zmalloc(__func__, sizeof(*mcp_res), 0);
3024 * The copy Flows are not included in any list. There
3025 * ones are referenced from other Flows and can not
3026 * be applied, removed, deleted in ardbitrary order
3027 * by list traversing.
3029 mcp_res->flow = flow_list_create(dev, NULL, &attr, items,
3030 actions, false, error);
3034 mcp_res->hlist_ent.key = mark_id;
3035 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3036 &mcp_res->hlist_ent);
3043 flow_list_destroy(dev, NULL, mcp_res->flow);
3049 * Release flow in RX_CP_TBL.
3052 * Pointer to Ethernet device.
3054 * Parent flow for wich copying is provided.
3057 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3058 struct rte_flow *flow)
3060 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3061 struct mlx5_priv *priv = dev->data->dev_private;
3063 if (!mcp_res || !priv->mreg_cp_tbl)
3065 if (flow->copy_applied) {
3066 assert(mcp_res->appcnt);
3067 flow->copy_applied = 0;
3069 if (!mcp_res->appcnt)
3070 flow_drv_remove(dev, mcp_res->flow);
3073 * We do not check availability of metadata registers here,
3074 * because copy resources are not allocated in this case.
3076 if (--mcp_res->refcnt)
3078 assert(mcp_res->flow);
3079 flow_list_destroy(dev, NULL, mcp_res->flow);
3080 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3082 flow->mreg_copy = NULL;
3086 * Start flow in RX_CP_TBL.
3089 * Pointer to Ethernet device.
3091 * Parent flow for wich copying is provided.
3094 * 0 on success, a negative errno value otherwise and rte_errno is set.
3097 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3098 struct rte_flow *flow)
3100 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3103 if (!mcp_res || flow->copy_applied)
3105 if (!mcp_res->appcnt) {
3106 ret = flow_drv_apply(dev, mcp_res->flow, NULL);
3111 flow->copy_applied = 1;
3116 * Stop flow in RX_CP_TBL.
3119 * Pointer to Ethernet device.
3121 * Parent flow for wich copying is provided.
3124 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3125 struct rte_flow *flow)
3127 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3129 if (!mcp_res || !flow->copy_applied)
3131 assert(mcp_res->appcnt);
3133 flow->copy_applied = 0;
3134 if (!mcp_res->appcnt)
3135 flow_drv_remove(dev, mcp_res->flow);
3139 * Remove the default copy action from RX_CP_TBL.
3142 * Pointer to Ethernet device.
3145 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3147 struct mlx5_flow_mreg_copy_resource *mcp_res;
3148 struct mlx5_priv *priv = dev->data->dev_private;
3150 /* Check if default flow is registered. */
3151 if (!priv->mreg_cp_tbl)
3153 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3154 MLX5_DEFAULT_COPY_ID);
3157 assert(mcp_res->flow);
3158 flow_list_destroy(dev, NULL, mcp_res->flow);
3159 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3164 * Add the default copy action in in RX_CP_TBL.
3167 * Pointer to Ethernet device.
3169 * Perform verbose error reporting if not NULL.
3172 * 0 for success, negative value otherwise and rte_errno is set.
3175 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3176 struct rte_flow_error *error)
3178 struct mlx5_priv *priv = dev->data->dev_private;
3179 struct mlx5_flow_mreg_copy_resource *mcp_res;
3181 /* Check whether extensive metadata feature is engaged. */
3182 if (!priv->config.dv_flow_en ||
3183 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3184 !mlx5_flow_ext_mreg_supported(dev) ||
3185 !priv->sh->dv_regc0_mask)
3187 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3194 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3196 * All the flow having Q/RSS action should be split by
3197 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3198 * performs the following,
3199 * - CQE->flow_tag := reg_c[1] (MARK)
3200 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3201 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3202 * but there should be a flow per each MARK ID set by MARK action.
3204 * For the aforementioned reason, if there's a MARK action in flow's action
3205 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3206 * the MARK ID to CQE's flow_tag like,
3207 * - If reg_c[1] is mark_id,
3208 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3210 * For SET_META action which stores value in reg_c[0], as the destination is
3211 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3212 * MARK ID means the default flow. The default flow looks like,
3213 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3216 * Pointer to Ethernet device.
3218 * Pointer to flow structure.
3219 * @param[in] actions
3220 * Pointer to the list of actions.
3222 * Perform verbose error reporting if not NULL.
3225 * 0 on success, negative value otherwise and rte_errno is set.
3228 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3229 struct rte_flow *flow,
3230 const struct rte_flow_action *actions,
3231 struct rte_flow_error *error)
3233 struct mlx5_priv *priv = dev->data->dev_private;
3234 struct mlx5_dev_config *config = &priv->config;
3235 struct mlx5_flow_mreg_copy_resource *mcp_res;
3236 const struct rte_flow_action_mark *mark;
3238 /* Check whether extensive metadata feature is engaged. */
3239 if (!config->dv_flow_en ||
3240 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3241 !mlx5_flow_ext_mreg_supported(dev) ||
3242 !priv->sh->dv_regc0_mask)
3244 /* Find MARK action. */
3245 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3246 switch (actions->type) {
3247 case RTE_FLOW_ACTION_TYPE_FLAG:
3248 mcp_res = flow_mreg_add_copy_action
3249 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3252 flow->mreg_copy = mcp_res;
3253 if (dev->data->dev_started) {
3255 flow->copy_applied = 1;
3258 case RTE_FLOW_ACTION_TYPE_MARK:
3259 mark = (const struct rte_flow_action_mark *)
3262 flow_mreg_add_copy_action(dev, mark->id, error);
3265 flow->mreg_copy = mcp_res;
3266 if (dev->data->dev_started) {
3268 flow->copy_applied = 1;
3278 #define MLX5_MAX_SPLIT_ACTIONS 24
3279 #define MLX5_MAX_SPLIT_ITEMS 24
3282 * Split the hairpin flow.
3283 * Since HW can't support encap on Rx we move the encap to Tx.
3284 * If the count action is after the encap then we also
3285 * move the count action. in this case the count will also measure
3289 * Pointer to Ethernet device.
3290 * @param[in] actions
3291 * Associated actions (list terminated by the END action).
3292 * @param[out] actions_rx
3294 * @param[out] actions_tx
3296 * @param[out] pattern_tx
3297 * The pattern items for the Tx flow.
3298 * @param[out] flow_id
3299 * The flow ID connected to this flow.
3305 flow_hairpin_split(struct rte_eth_dev *dev,
3306 const struct rte_flow_action actions[],
3307 struct rte_flow_action actions_rx[],
3308 struct rte_flow_action actions_tx[],
3309 struct rte_flow_item pattern_tx[],
3312 struct mlx5_priv *priv = dev->data->dev_private;
3313 const struct rte_flow_action_raw_encap *raw_encap;
3314 const struct rte_flow_action_raw_decap *raw_decap;
3315 struct mlx5_rte_flow_action_set_tag *set_tag;
3316 struct rte_flow_action *tag_action;
3317 struct mlx5_rte_flow_item_tag *tag_item;
3318 struct rte_flow_item *item;
3322 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
3323 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3324 switch (actions->type) {
3325 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3326 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3327 rte_memcpy(actions_tx, actions,
3328 sizeof(struct rte_flow_action));
3331 case RTE_FLOW_ACTION_TYPE_COUNT:
3333 rte_memcpy(actions_tx, actions,
3334 sizeof(struct rte_flow_action));
3337 rte_memcpy(actions_rx, actions,
3338 sizeof(struct rte_flow_action));
3342 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3343 raw_encap = actions->conf;
3344 if (raw_encap->size >
3345 (sizeof(struct rte_flow_item_eth) +
3346 sizeof(struct rte_flow_item_ipv4))) {
3347 memcpy(actions_tx, actions,
3348 sizeof(struct rte_flow_action));
3352 rte_memcpy(actions_rx, actions,
3353 sizeof(struct rte_flow_action));
3357 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3358 raw_decap = actions->conf;
3359 if (raw_decap->size <
3360 (sizeof(struct rte_flow_item_eth) +
3361 sizeof(struct rte_flow_item_ipv4))) {
3362 memcpy(actions_tx, actions,
3363 sizeof(struct rte_flow_action));
3366 rte_memcpy(actions_rx, actions,
3367 sizeof(struct rte_flow_action));
3372 rte_memcpy(actions_rx, actions,
3373 sizeof(struct rte_flow_action));
3378 /* Add set meta action and end action for the Rx flow. */
3379 tag_action = actions_rx;
3380 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3382 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
3384 set_tag = (void *)actions_rx;
3385 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
3386 assert(set_tag->id > REG_NONE);
3387 set_tag->data = *flow_id;
3388 tag_action->conf = set_tag;
3389 /* Create Tx item list. */
3390 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
3391 addr = (void *)&pattern_tx[2];
3393 item->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3394 tag_item = (void *)addr;
3395 tag_item->data = *flow_id;
3396 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
3397 assert(set_tag->id > REG_NONE);
3398 item->spec = tag_item;
3399 addr += sizeof(struct mlx5_rte_flow_item_tag);
3400 tag_item = (void *)addr;
3401 tag_item->data = UINT32_MAX;
3402 tag_item->id = UINT16_MAX;
3403 item->mask = tag_item;
3404 addr += sizeof(struct mlx5_rte_flow_item_tag);
3407 item->type = RTE_FLOW_ITEM_TYPE_END;
3412 * The last stage of splitting chain, just creates the subflow
3413 * without any modification.
3416 * Pointer to Ethernet device.
3418 * Parent flow structure pointer.
3419 * @param[in, out] sub_flow
3420 * Pointer to return the created subflow, may be NULL.
3422 * Flow rule attributes.
3424 * Pattern specification (list terminated by the END pattern item).
3425 * @param[in] actions
3426 * Associated actions (list terminated by the END action).
3427 * @param[in] external
3428 * This flow rule is created by request external to PMD.
3430 * Perform verbose error reporting if not NULL.
3432 * 0 on success, negative value otherwise
3435 flow_create_split_inner(struct rte_eth_dev *dev,
3436 struct rte_flow *flow,
3437 struct mlx5_flow **sub_flow,
3438 const struct rte_flow_attr *attr,
3439 const struct rte_flow_item items[],
3440 const struct rte_flow_action actions[],
3441 bool external, struct rte_flow_error *error)
3443 struct mlx5_flow *dev_flow;
3445 dev_flow = flow_drv_prepare(flow, attr, items, actions, error);
3448 dev_flow->flow = flow;
3449 dev_flow->external = external;
3450 /* Subflow object was created, we must include one in the list. */
3451 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
3453 *sub_flow = dev_flow;
3454 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
3458 * Split the meter flow.
3460 * As meter flow will split to three sub flow, other than meter
3461 * action, the other actions make sense to only meter accepts
3462 * the packet. If it need to be dropped, no other additional
3463 * actions should be take.
3465 * One kind of special action which decapsulates the L3 tunnel
3466 * header will be in the prefix sub flow, as not to take the
3467 * L3 tunnel header into account.
3470 * Pointer to Ethernet device.
3471 * @param[in] actions
3472 * Associated actions (list terminated by the END action).
3473 * @param[out] actions_sfx
3474 * Suffix flow actions.
3475 * @param[out] actions_pre
3476 * Prefix flow actions.
3477 * @param[out] pattern_sfx
3478 * The pattern items for the suffix flow.
3479 * @param[out] tag_sfx
3480 * Pointer to suffix flow tag.
3486 flow_meter_split_prep(struct rte_eth_dev *dev,
3487 const struct rte_flow_action actions[],
3488 struct rte_flow_action actions_sfx[],
3489 struct rte_flow_action actions_pre[])
3491 struct rte_flow_action *tag_action;
3492 struct mlx5_rte_flow_action_set_tag *set_tag;
3493 struct rte_flow_error error;
3494 const struct rte_flow_action_raw_encap *raw_encap;
3495 const struct rte_flow_action_raw_decap *raw_decap;
3498 /* Add the extra tag action first. */
3499 tag_action = actions_pre;
3500 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3502 /* Prepare the actions for prefix and suffix flow. */
3503 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3504 switch (actions->type) {
3505 case RTE_FLOW_ACTION_TYPE_METER:
3506 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3507 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3508 memcpy(actions_pre, actions,
3509 sizeof(struct rte_flow_action));
3512 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3513 raw_encap = actions->conf;
3514 if (raw_encap->size >
3515 (sizeof(struct rte_flow_item_eth) +
3516 sizeof(struct rte_flow_item_ipv4))) {
3517 memcpy(actions_sfx, actions,
3518 sizeof(struct rte_flow_action));
3521 rte_memcpy(actions_pre, actions,
3522 sizeof(struct rte_flow_action));
3526 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3527 raw_decap = actions->conf;
3528 /* Size 0 decap means 50 bytes as vxlan decap. */
3529 if (raw_decap->size && (raw_decap->size <
3530 (sizeof(struct rte_flow_item_eth) +
3531 sizeof(struct rte_flow_item_ipv4)))) {
3532 memcpy(actions_sfx, actions,
3533 sizeof(struct rte_flow_action));
3536 rte_memcpy(actions_pre, actions,
3537 sizeof(struct rte_flow_action));
3542 memcpy(actions_sfx, actions,
3543 sizeof(struct rte_flow_action));
3548 /* Add end action to the actions. */
3549 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
3550 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
3553 set_tag = (void *)actions_pre;
3554 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3556 * Get the id from the qrss_pool to make qrss share the id with meter.
3558 tag_id = flow_qrss_get_id(dev);
3559 set_tag->data = rte_cpu_to_be_32(tag_id);
3560 tag_action->conf = set_tag;
3565 * Split action list having QUEUE/RSS for metadata register copy.
3567 * Once Q/RSS action is detected in user's action list, the flow action
3568 * should be split in order to copy metadata registers, which will happen in
3570 * - CQE->flow_tag := reg_c[1] (MARK)
3571 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3572 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
3573 * This is because the last action of each flow must be a terminal action
3574 * (QUEUE, RSS or DROP).
3576 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
3577 * stored and kept in the mlx5_flow structure per each sub_flow.
3579 * The Q/RSS action is replaced with,
3580 * - SET_TAG, setting the allocated flow ID to reg_c[2].
3581 * And the following JUMP action is added at the end,
3582 * - JUMP, to RX_CP_TBL.
3584 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
3585 * flow_create_split_metadata() routine. The flow will look like,
3586 * - If flow ID matches (reg_c[2]), perform Q/RSS.
3589 * Pointer to Ethernet device.
3590 * @param[out] split_actions
3591 * Pointer to store split actions to jump to CP_TBL.
3592 * @param[in] actions
3593 * Pointer to the list of original flow actions.
3595 * Pointer to the Q/RSS action.
3596 * @param[in] actions_n
3597 * Number of original actions.
3599 * Perform verbose error reporting if not NULL.
3602 * non-zero unique flow_id on success, otherwise 0 and
3603 * error/rte_error are set.
3606 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
3607 struct rte_flow_action *split_actions,
3608 const struct rte_flow_action *actions,
3609 const struct rte_flow_action *qrss,
3610 int actions_n, struct rte_flow_error *error)
3612 struct mlx5_rte_flow_action_set_tag *set_tag;
3613 struct rte_flow_action_jump *jump;
3614 const int qrss_idx = qrss - actions;
3615 uint32_t flow_id = 0;
3619 * Given actions will be split
3620 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
3621 * - Add jump to mreg CP_TBL.
3622 * As a result, there will be one more action.
3625 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
3626 set_tag = (void *)(split_actions + actions_n);
3628 * If tag action is not set to void(it means we are not the meter
3629 * suffix flow), add the tag action. Since meter suffix flow already
3630 * has the tag added.
3632 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
3634 * Allocate the new subflow ID. This one is unique within
3635 * device and not shared with representors. Otherwise,
3636 * we would have to resolve multi-thread access synch
3637 * issue. Each flow on the shared device is appended
3638 * with source vport identifier, so the resulting
3639 * flows will be unique in the shared (by master and
3640 * representors) domain even if they have coinciding
3643 flow_id = flow_qrss_get_id(dev);
3645 return rte_flow_error_set(error, ENOMEM,
3646 RTE_FLOW_ERROR_TYPE_ACTION,
3647 NULL, "can't allocate id "
3648 "for split Q/RSS subflow");
3649 /* Internal SET_TAG action to set flow ID. */
3650 *set_tag = (struct mlx5_rte_flow_action_set_tag){
3653 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
3657 /* Construct new actions array. */
3658 /* Replace QUEUE/RSS action. */
3659 split_actions[qrss_idx] = (struct rte_flow_action){
3660 .type = MLX5_RTE_FLOW_ACTION_TYPE_TAG,
3664 /* JUMP action to jump to mreg copy table (CP_TBL). */
3665 jump = (void *)(set_tag + 1);
3666 *jump = (struct rte_flow_action_jump){
3667 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3669 split_actions[actions_n - 2] = (struct rte_flow_action){
3670 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3673 split_actions[actions_n - 1] = (struct rte_flow_action){
3674 .type = RTE_FLOW_ACTION_TYPE_END,
3680 * Extend the given action list for Tx metadata copy.
3682 * Copy the given action list to the ext_actions and add flow metadata register
3683 * copy action in order to copy reg_a set by WQE to reg_c[0].
3685 * @param[out] ext_actions
3686 * Pointer to the extended action list.
3687 * @param[in] actions
3688 * Pointer to the list of actions.
3689 * @param[in] actions_n
3690 * Number of actions in the list.
3692 * Perform verbose error reporting if not NULL.
3695 * 0 on success, negative value otherwise
3698 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
3699 struct rte_flow_action *ext_actions,
3700 const struct rte_flow_action *actions,
3701 int actions_n, struct rte_flow_error *error)
3703 struct mlx5_flow_action_copy_mreg *cp_mreg =
3704 (struct mlx5_flow_action_copy_mreg *)
3705 (ext_actions + actions_n + 1);
3708 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3712 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
3716 memcpy(ext_actions, actions,
3717 sizeof(*ext_actions) * actions_n);
3718 ext_actions[actions_n - 1] = (struct rte_flow_action){
3719 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3722 ext_actions[actions_n] = (struct rte_flow_action){
3723 .type = RTE_FLOW_ACTION_TYPE_END,
3729 * The splitting for metadata feature.
3731 * - Q/RSS action on NIC Rx should be split in order to pass by
3732 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3733 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3735 * - All the actions on NIC Tx should have a mreg copy action to
3736 * copy reg_a from WQE to reg_c[0].
3739 * Pointer to Ethernet device.
3741 * Parent flow structure pointer.
3743 * Flow rule attributes.
3745 * Pattern specification (list terminated by the END pattern item).
3746 * @param[in] actions
3747 * Associated actions (list terminated by the END action).
3748 * @param[in] external
3749 * This flow rule is created by request external to PMD.
3751 * Perform verbose error reporting if not NULL.
3753 * 0 on success, negative value otherwise
3756 flow_create_split_metadata(struct rte_eth_dev *dev,
3757 struct rte_flow *flow,
3758 const struct rte_flow_attr *attr,
3759 const struct rte_flow_item items[],
3760 const struct rte_flow_action actions[],
3761 bool external, struct rte_flow_error *error)
3763 struct mlx5_priv *priv = dev->data->dev_private;
3764 struct mlx5_dev_config *config = &priv->config;
3765 const struct rte_flow_action *qrss = NULL;
3766 struct rte_flow_action *ext_actions = NULL;
3767 struct mlx5_flow *dev_flow = NULL;
3768 uint32_t qrss_id = 0;
3774 /* Check whether extensive metadata feature is engaged. */
3775 if (!config->dv_flow_en ||
3776 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3777 !mlx5_flow_ext_mreg_supported(dev))
3778 return flow_create_split_inner(dev, flow, NULL, attr, items,
3779 actions, external, error);
3780 actions_n = flow_parse_qrss_action(actions, &qrss);
3782 /* Exclude hairpin flows from splitting. */
3783 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
3784 const struct rte_flow_action_queue *queue;
3787 if (mlx5_rxq_get_type(dev, queue->index) ==
3788 MLX5_RXQ_TYPE_HAIRPIN)
3790 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
3791 const struct rte_flow_action_rss *rss;
3794 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
3795 MLX5_RXQ_TYPE_HAIRPIN)
3800 /* Check if it is in meter suffix table. */
3801 mtr_sfx = attr->group == (attr->transfer ?
3802 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
3803 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
3805 * Q/RSS action on NIC Rx should be split in order to pass by
3806 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3807 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3809 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3810 sizeof(struct rte_flow_action_set_tag) +
3811 sizeof(struct rte_flow_action_jump);
3812 ext_actions = rte_zmalloc(__func__, act_size, 0);
3814 return rte_flow_error_set(error, ENOMEM,
3815 RTE_FLOW_ERROR_TYPE_ACTION,
3816 NULL, "no memory to split "
3819 * If we are the suffix flow of meter, tag already exist.
3820 * Set the tag action to void.
3823 ext_actions[qrss - actions].type =
3824 RTE_FLOW_ACTION_TYPE_VOID;
3826 ext_actions[qrss - actions].type =
3827 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3829 * Create the new actions list with removed Q/RSS action
3830 * and appended set tag and jump to register copy table
3831 * (RX_CP_TBL). We should preallocate unique tag ID here
3832 * in advance, because it is needed for set tag action.
3834 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
3835 qrss, actions_n, error);
3836 if (!mtr_sfx && !qrss_id) {
3840 } else if (attr->egress && !attr->transfer) {
3842 * All the actions on NIC Tx should have a metadata register
3843 * copy action to copy reg_a from WQE to reg_c[meta]
3845 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3846 sizeof(struct mlx5_flow_action_copy_mreg);
3847 ext_actions = rte_zmalloc(__func__, act_size, 0);
3849 return rte_flow_error_set(error, ENOMEM,
3850 RTE_FLOW_ERROR_TYPE_ACTION,
3851 NULL, "no memory to split "
3853 /* Create the action list appended with copy register. */
3854 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
3859 /* Add the unmodified original or prefix subflow. */
3860 ret = flow_create_split_inner(dev, flow, &dev_flow, attr, items,
3861 ext_actions ? ext_actions : actions,
3867 const struct rte_flow_attr q_attr = {
3868 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3871 /* Internal PMD action to set register. */
3872 struct mlx5_rte_flow_item_tag q_tag_spec = {
3876 struct rte_flow_item q_items[] = {
3878 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3879 .spec = &q_tag_spec,
3884 .type = RTE_FLOW_ITEM_TYPE_END,
3887 struct rte_flow_action q_actions[] = {
3893 .type = RTE_FLOW_ACTION_TYPE_END,
3896 uint64_t hash_fields = dev_flow->hash_fields;
3899 * Configure the tag item only if there is no meter subflow.
3900 * Since tag is already marked in the meter suffix subflow
3901 * we can just use the meter suffix items as is.
3904 /* Not meter subflow. */
3907 * Put unique id in prefix flow due to it is destroyed
3908 * after suffix flow and id will be freed after there
3909 * is no actual flows with this id and identifier
3910 * reallocation becomes possible (for example, for
3911 * other flows in other threads).
3913 dev_flow->qrss_id = qrss_id;
3915 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
3919 q_tag_spec.id = ret;
3922 /* Add suffix subflow to execute Q/RSS. */
3923 ret = flow_create_split_inner(dev, flow, &dev_flow,
3924 &q_attr, mtr_sfx ? items :
3930 dev_flow->hash_fields = hash_fields;
3935 * We do not destroy the partially created sub_flows in case of error.
3936 * These ones are included into parent flow list and will be destroyed
3937 * by flow_drv_destroy.
3939 flow_qrss_free_id(dev, qrss_id);
3940 rte_free(ext_actions);
3945 * The splitting for meter feature.
3947 * - The meter flow will be split to two flows as prefix and
3948 * suffix flow. The packets make sense only it pass the prefix
3951 * - Reg_C_5 is used for the packet to match betweend prefix and
3955 * Pointer to Ethernet device.
3957 * Parent flow structure pointer.
3959 * Flow rule attributes.
3961 * Pattern specification (list terminated by the END pattern item).
3962 * @param[in] actions
3963 * Associated actions (list terminated by the END action).
3964 * @param[in] external
3965 * This flow rule is created by request external to PMD.
3967 * Perform verbose error reporting if not NULL.
3969 * 0 on success, negative value otherwise
3972 flow_create_split_meter(struct rte_eth_dev *dev,
3973 struct rte_flow *flow,
3974 const struct rte_flow_attr *attr,
3975 const struct rte_flow_item items[],
3976 const struct rte_flow_action actions[],
3977 bool external, struct rte_flow_error *error)
3979 struct mlx5_priv *priv = dev->data->dev_private;
3980 struct rte_flow_action *sfx_actions = NULL;
3981 struct rte_flow_action *pre_actions = NULL;
3982 struct rte_flow_item *sfx_items = NULL;
3983 const struct rte_flow_item *sfx_port_id_item;
3984 struct mlx5_flow *dev_flow = NULL;
3985 struct rte_flow_attr sfx_attr = *attr;
3987 uint32_t mtr_tag_id = 0;
3994 actions_n = flow_check_meter_action(actions, &mtr);
3996 struct mlx5_rte_flow_item_tag *tag_spec;
3997 /* The five prefix actions: meter, decap, encap, tag, end. */
3998 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
3999 sizeof(struct rte_flow_action_set_tag);
4001 #define METER_SUFFIX_ITEM 3
4002 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
4003 sizeof(struct mlx5_rte_flow_item_tag);
4004 sfx_actions = rte_zmalloc(__func__, (act_size + item_size), 0);
4006 return rte_flow_error_set(error, ENOMEM,
4007 RTE_FLOW_ERROR_TYPE_ACTION,
4008 NULL, "no memory to split "
4010 pre_actions = sfx_actions + actions_n;
4011 mtr_tag_id = flow_meter_split_prep(dev, actions, sfx_actions,
4017 /* Add the prefix subflow. */
4018 ret = flow_create_split_inner(dev, flow, &dev_flow, attr, items,
4019 pre_actions, external, error);
4024 dev_flow->mtr_flow_id = mtr_tag_id;
4025 /* Prepare the suffix flow match pattern. */
4026 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4028 tag_spec = (struct mlx5_rte_flow_item_tag *)(sfx_items +
4030 tag_spec->data = rte_cpu_to_be_32(dev_flow->mtr_flow_id);
4031 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0,
4033 sfx_items->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4034 sfx_items->spec = tag_spec;
4035 sfx_items->last = NULL;
4036 sfx_items->mask = NULL;
4038 sfx_port_id_item = find_port_id_item(items);
4039 if (sfx_port_id_item) {
4040 memcpy(sfx_items, sfx_port_id_item,
4041 sizeof(*sfx_items));
4044 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4045 sfx_items -= sfx_port_id_item ? 2 : 1;
4046 /* Setting the sfx group atrr. */
4047 sfx_attr.group = sfx_attr.transfer ?
4048 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4049 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4051 /* Add the prefix subflow. */
4052 ret = flow_create_split_metadata(dev, flow, &sfx_attr,
4053 sfx_items ? sfx_items : items,
4054 sfx_actions ? sfx_actions : actions,
4058 rte_free(sfx_actions);
4063 * Split the flow to subflow set. The splitters might be linked
4064 * in the chain, like this:
4065 * flow_create_split_outer() calls:
4066 * flow_create_split_meter() calls:
4067 * flow_create_split_metadata(meter_subflow_0) calls:
4068 * flow_create_split_inner(metadata_subflow_0)
4069 * flow_create_split_inner(metadata_subflow_1)
4070 * flow_create_split_inner(metadata_subflow_2)
4071 * flow_create_split_metadata(meter_subflow_1) calls:
4072 * flow_create_split_inner(metadata_subflow_0)
4073 * flow_create_split_inner(metadata_subflow_1)
4074 * flow_create_split_inner(metadata_subflow_2)
4076 * This provide flexible way to add new levels of flow splitting.
4077 * The all of successfully created subflows are included to the
4078 * parent flow dev_flow list.
4081 * Pointer to Ethernet device.
4083 * Parent flow structure pointer.
4085 * Flow rule attributes.
4087 * Pattern specification (list terminated by the END pattern item).
4088 * @param[in] actions
4089 * Associated actions (list terminated by the END action).
4090 * @param[in] external
4091 * This flow rule is created by request external to PMD.
4093 * Perform verbose error reporting if not NULL.
4095 * 0 on success, negative value otherwise
4098 flow_create_split_outer(struct rte_eth_dev *dev,
4099 struct rte_flow *flow,
4100 const struct rte_flow_attr *attr,
4101 const struct rte_flow_item items[],
4102 const struct rte_flow_action actions[],
4103 bool external, struct rte_flow_error *error)
4107 ret = flow_create_split_meter(dev, flow, attr, items,
4108 actions, external, error);
4114 * Create a flow and add it to @p list.
4117 * Pointer to Ethernet device.
4119 * Pointer to a TAILQ flow list. If this parameter NULL,
4120 * no list insertion occurred, flow is just created,
4121 * this is caller's responsibility to track the
4124 * Flow rule attributes.
4126 * Pattern specification (list terminated by the END pattern item).
4127 * @param[in] actions
4128 * Associated actions (list terminated by the END action).
4129 * @param[in] external
4130 * This flow rule is created by request external to PMD.
4132 * Perform verbose error reporting if not NULL.
4135 * A flow on success, NULL otherwise and rte_errno is set.
4137 static struct rte_flow *
4138 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
4139 const struct rte_flow_attr *attr,
4140 const struct rte_flow_item items[],
4141 const struct rte_flow_action actions[],
4142 bool external, struct rte_flow_error *error)
4144 struct mlx5_priv *priv = dev->data->dev_private;
4145 struct rte_flow *flow = NULL;
4146 struct mlx5_flow *dev_flow;
4147 const struct rte_flow_action_rss *rss;
4149 struct rte_flow_expand_rss buf;
4150 uint8_t buffer[2048];
4153 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4154 uint8_t buffer[2048];
4157 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4158 uint8_t buffer[2048];
4159 } actions_hairpin_tx;
4161 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
4162 uint8_t buffer[2048];
4164 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
4165 const struct rte_flow_action *p_actions_rx = actions;
4169 int hairpin_flow = 0;
4170 uint32_t hairpin_id = 0;
4171 struct rte_flow_attr attr_tx = { .priority = 0 };
4173 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4174 if (hairpin_flow > 0) {
4175 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
4179 flow_hairpin_split(dev, actions, actions_rx.actions,
4180 actions_hairpin_tx.actions, items_tx.items,
4182 p_actions_rx = actions_rx.actions;
4184 ret = flow_drv_validate(dev, attr, items, p_actions_rx, external,
4187 goto error_before_flow;
4188 flow_size = sizeof(struct rte_flow);
4189 rss = flow_get_rss_action(p_actions_rx);
4191 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
4194 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
4195 flow = rte_calloc(__func__, 1, flow_size, 0);
4198 goto error_before_flow;
4200 flow->drv_type = flow_get_drv_type(dev, attr);
4201 if (hairpin_id != 0)
4202 flow->hairpin_flow_id = hairpin_id;
4203 assert(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
4204 flow->drv_type < MLX5_FLOW_TYPE_MAX);
4205 flow->rss.queue = (void *)(flow + 1);
4208 * The following information is required by
4209 * mlx5_flow_hashfields_adjust() in advance.
4211 flow->rss.level = rss->level;
4212 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
4213 flow->rss.types = !rss->types ? ETH_RSS_IP : rss->types;
4215 LIST_INIT(&flow->dev_flows);
4216 if (rss && rss->types) {
4217 unsigned int graph_root;
4219 graph_root = find_graph_root(items, rss->level);
4220 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
4222 mlx5_support_expansion,
4225 (unsigned int)ret < sizeof(expand_buffer.buffer));
4228 buf->entry[0].pattern = (void *)(uintptr_t)items;
4230 for (i = 0; i < buf->entries; ++i) {
4232 * The splitter may create multiple dev_flows,
4233 * depending on configuration. In the simplest
4234 * case it just creates unmodified original flow.
4236 ret = flow_create_split_outer(dev, flow, attr,
4237 buf->entry[i].pattern,
4238 p_actions_rx, external,
4243 /* Create the tx flow. */
4245 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
4246 attr_tx.ingress = 0;
4248 dev_flow = flow_drv_prepare(flow, &attr_tx, items_tx.items,
4249 actions_hairpin_tx.actions, error);
4252 dev_flow->flow = flow;
4253 dev_flow->external = 0;
4254 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
4255 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
4257 actions_hairpin_tx.actions, error);
4262 * Update the metadata register copy table. If extensive
4263 * metadata feature is enabled and registers are supported
4264 * we might create the extra rte_flow for each unique
4265 * MARK/FLAG action ID.
4267 * The table is updated for ingress Flows only, because
4268 * the egress Flows belong to the different device and
4269 * copy table should be updated in peer NIC Rx domain.
4271 if (attr->ingress &&
4272 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
4273 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
4277 if (dev->data->dev_started) {
4278 ret = flow_drv_apply(dev, flow, error);
4283 TAILQ_INSERT_TAIL(list, flow, next);
4284 flow_rxq_flags_set(dev, flow);
4288 mlx5_flow_id_release(priv->sh->flow_id_pool,
4293 flow_mreg_del_copy_action(dev, flow);
4294 ret = rte_errno; /* Save rte_errno before cleanup. */
4295 if (flow->hairpin_flow_id)
4296 mlx5_flow_id_release(priv->sh->flow_id_pool,
4297 flow->hairpin_flow_id);
4299 flow_drv_destroy(dev, flow);
4301 rte_errno = ret; /* Restore rte_errno. */
4306 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
4307 * incoming packets to table 1.
4309 * Other flow rules, requested for group n, will be created in
4310 * e-switch table n+1.
4311 * Jump action to e-switch group n will be created to group n+1.
4313 * Used when working in switchdev mode, to utilise advantages of table 1
4317 * Pointer to Ethernet device.
4320 * Pointer to flow on success, NULL otherwise and rte_errno is set.
4323 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
4325 const struct rte_flow_attr attr = {
4332 const struct rte_flow_item pattern = {
4333 .type = RTE_FLOW_ITEM_TYPE_END,
4335 struct rte_flow_action_jump jump = {
4338 const struct rte_flow_action actions[] = {
4340 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4344 .type = RTE_FLOW_ACTION_TYPE_END,
4347 struct mlx5_priv *priv = dev->data->dev_private;
4348 struct rte_flow_error error;
4350 return flow_list_create(dev, &priv->ctrl_flows, &attr, &pattern,
4351 actions, false, &error);
4357 * @see rte_flow_create()
4361 mlx5_flow_create(struct rte_eth_dev *dev,
4362 const struct rte_flow_attr *attr,
4363 const struct rte_flow_item items[],
4364 const struct rte_flow_action actions[],
4365 struct rte_flow_error *error)
4367 struct mlx5_priv *priv = dev->data->dev_private;
4369 return flow_list_create(dev, &priv->flows,
4370 attr, items, actions, true, error);
4374 * Destroy a flow in a list.
4377 * Pointer to Ethernet device.
4379 * Pointer to a TAILQ flow list. If this parameter NULL,
4380 * there is no flow removal from the list.
4385 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
4386 struct rte_flow *flow)
4388 struct mlx5_priv *priv = dev->data->dev_private;
4391 * Update RX queue flags only if port is started, otherwise it is
4394 if (dev->data->dev_started)
4395 flow_rxq_flags_trim(dev, flow);
4396 if (flow->hairpin_flow_id)
4397 mlx5_flow_id_release(priv->sh->flow_id_pool,
4398 flow->hairpin_flow_id);
4399 flow_drv_destroy(dev, flow);
4401 TAILQ_REMOVE(list, flow, next);
4402 flow_mreg_del_copy_action(dev, flow);
4403 rte_free(flow->fdir);
4408 * Destroy all flows.
4411 * Pointer to Ethernet device.
4413 * Pointer to a TAILQ flow list.
4416 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
4418 while (!TAILQ_EMPTY(list)) {
4419 struct rte_flow *flow;
4421 flow = TAILQ_FIRST(list);
4422 flow_list_destroy(dev, list, flow);
4430 * Pointer to Ethernet device.
4432 * Pointer to a TAILQ flow list.
4435 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
4437 struct rte_flow *flow;
4439 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next) {
4440 flow_drv_remove(dev, flow);
4441 flow_mreg_stop_copy_action(dev, flow);
4443 flow_mreg_del_default_copy_action(dev);
4444 flow_rxq_flags_clear(dev);
4451 * Pointer to Ethernet device.
4453 * Pointer to a TAILQ flow list.
4456 * 0 on success, a negative errno value otherwise and rte_errno is set.
4459 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
4461 struct rte_flow *flow;
4462 struct rte_flow_error error;
4465 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4466 ret = flow_mreg_add_default_copy_action(dev, &error);
4469 /* Apply Flows created by application. */
4470 TAILQ_FOREACH(flow, list, next) {
4471 ret = flow_mreg_start_copy_action(dev, flow);
4474 ret = flow_drv_apply(dev, flow, &error);
4477 flow_rxq_flags_set(dev, flow);
4481 ret = rte_errno; /* Save rte_errno before cleanup. */
4482 mlx5_flow_stop(dev, list);
4483 rte_errno = ret; /* Restore rte_errno. */
4488 * Verify the flow list is empty
4491 * Pointer to Ethernet device.
4493 * @return the number of flows not released.
4496 mlx5_flow_verify(struct rte_eth_dev *dev)
4498 struct mlx5_priv *priv = dev->data->dev_private;
4499 struct rte_flow *flow;
4502 TAILQ_FOREACH(flow, &priv->flows, next) {
4503 DRV_LOG(DEBUG, "port %u flow %p still referenced",
4504 dev->data->port_id, (void *)flow);
4511 * Enable default hairpin egress flow.
4514 * Pointer to Ethernet device.
4519 * 0 on success, a negative errno value otherwise and rte_errno is set.
4522 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
4525 struct mlx5_priv *priv = dev->data->dev_private;
4526 const struct rte_flow_attr attr = {
4530 struct mlx5_rte_flow_item_tx_queue queue_spec = {
4533 struct mlx5_rte_flow_item_tx_queue queue_mask = {
4534 .queue = UINT32_MAX,
4536 struct rte_flow_item items[] = {
4538 .type = MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
4539 .spec = &queue_spec,
4541 .mask = &queue_mask,
4544 .type = RTE_FLOW_ITEM_TYPE_END,
4547 struct rte_flow_action_jump jump = {
4548 .group = MLX5_HAIRPIN_TX_TABLE,
4550 struct rte_flow_action actions[2];
4551 struct rte_flow *flow;
4552 struct rte_flow_error error;
4554 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
4555 actions[0].conf = &jump;
4556 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
4557 flow = flow_list_create(dev, &priv->ctrl_flows,
4558 &attr, items, actions, false, &error);
4561 "Failed to create ctrl flow: rte_errno(%d),"
4562 " type(%d), message(%s)",
4563 rte_errno, error.type,
4564 error.message ? error.message : " (no stated reason)");
4571 * Enable a control flow configured from the control plane.
4574 * Pointer to Ethernet device.
4576 * An Ethernet flow spec to apply.
4578 * An Ethernet flow mask to apply.
4580 * A VLAN flow spec to apply.
4582 * A VLAN flow mask to apply.
4585 * 0 on success, a negative errno value otherwise and rte_errno is set.
4588 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
4589 struct rte_flow_item_eth *eth_spec,
4590 struct rte_flow_item_eth *eth_mask,
4591 struct rte_flow_item_vlan *vlan_spec,
4592 struct rte_flow_item_vlan *vlan_mask)
4594 struct mlx5_priv *priv = dev->data->dev_private;
4595 const struct rte_flow_attr attr = {
4597 .priority = MLX5_FLOW_PRIO_RSVD,
4599 struct rte_flow_item items[] = {
4601 .type = RTE_FLOW_ITEM_TYPE_ETH,
4607 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
4608 RTE_FLOW_ITEM_TYPE_END,
4614 .type = RTE_FLOW_ITEM_TYPE_END,
4617 uint16_t queue[priv->reta_idx_n];
4618 struct rte_flow_action_rss action_rss = {
4619 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4621 .types = priv->rss_conf.rss_hf,
4622 .key_len = priv->rss_conf.rss_key_len,
4623 .queue_num = priv->reta_idx_n,
4624 .key = priv->rss_conf.rss_key,
4627 struct rte_flow_action actions[] = {
4629 .type = RTE_FLOW_ACTION_TYPE_RSS,
4630 .conf = &action_rss,
4633 .type = RTE_FLOW_ACTION_TYPE_END,
4636 struct rte_flow *flow;
4637 struct rte_flow_error error;
4640 if (!priv->reta_idx_n || !priv->rxqs_n) {
4643 for (i = 0; i != priv->reta_idx_n; ++i)
4644 queue[i] = (*priv->reta_idx)[i];
4645 flow = flow_list_create(dev, &priv->ctrl_flows,
4646 &attr, items, actions, false, &error);
4653 * Enable a flow control configured from the control plane.
4656 * Pointer to Ethernet device.
4658 * An Ethernet flow spec to apply.
4660 * An Ethernet flow mask to apply.
4663 * 0 on success, a negative errno value otherwise and rte_errno is set.
4666 mlx5_ctrl_flow(struct rte_eth_dev *dev,
4667 struct rte_flow_item_eth *eth_spec,
4668 struct rte_flow_item_eth *eth_mask)
4670 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
4676 * @see rte_flow_destroy()
4680 mlx5_flow_destroy(struct rte_eth_dev *dev,
4681 struct rte_flow *flow,
4682 struct rte_flow_error *error __rte_unused)
4684 struct mlx5_priv *priv = dev->data->dev_private;
4686 flow_list_destroy(dev, &priv->flows, flow);
4691 * Destroy all flows.
4693 * @see rte_flow_flush()
4697 mlx5_flow_flush(struct rte_eth_dev *dev,
4698 struct rte_flow_error *error __rte_unused)
4700 struct mlx5_priv *priv = dev->data->dev_private;
4702 mlx5_flow_list_flush(dev, &priv->flows);
4709 * @see rte_flow_isolate()
4713 mlx5_flow_isolate(struct rte_eth_dev *dev,
4715 struct rte_flow_error *error)
4717 struct mlx5_priv *priv = dev->data->dev_private;
4719 if (dev->data->dev_started) {
4720 rte_flow_error_set(error, EBUSY,
4721 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4723 "port must be stopped first");
4726 priv->isolated = !!enable;
4728 dev->dev_ops = &mlx5_dev_ops_isolate;
4730 dev->dev_ops = &mlx5_dev_ops;
4737 * @see rte_flow_query()
4741 flow_drv_query(struct rte_eth_dev *dev,
4742 struct rte_flow *flow,
4743 const struct rte_flow_action *actions,
4745 struct rte_flow_error *error)
4747 const struct mlx5_flow_driver_ops *fops;
4748 enum mlx5_flow_drv_type ftype = flow->drv_type;
4750 assert(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
4751 fops = flow_get_drv_ops(ftype);
4753 return fops->query(dev, flow, actions, data, error);
4759 * @see rte_flow_query()
4763 mlx5_flow_query(struct rte_eth_dev *dev,
4764 struct rte_flow *flow,
4765 const struct rte_flow_action *actions,
4767 struct rte_flow_error *error)
4771 ret = flow_drv_query(dev, flow, actions, data, error);
4778 * Convert a flow director filter to a generic flow.
4781 * Pointer to Ethernet device.
4782 * @param fdir_filter
4783 * Flow director filter to add.
4785 * Generic flow parameters structure.
4788 * 0 on success, a negative errno value otherwise and rte_errno is set.
4791 flow_fdir_filter_convert(struct rte_eth_dev *dev,
4792 const struct rte_eth_fdir_filter *fdir_filter,
4793 struct mlx5_fdir *attributes)
4795 struct mlx5_priv *priv = dev->data->dev_private;
4796 const struct rte_eth_fdir_input *input = &fdir_filter->input;
4797 const struct rte_eth_fdir_masks *mask =
4798 &dev->data->dev_conf.fdir_conf.mask;
4800 /* Validate queue number. */
4801 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
4802 DRV_LOG(ERR, "port %u invalid queue number %d",
4803 dev->data->port_id, fdir_filter->action.rx_queue);
4807 attributes->attr.ingress = 1;
4808 attributes->items[0] = (struct rte_flow_item) {
4809 .type = RTE_FLOW_ITEM_TYPE_ETH,
4810 .spec = &attributes->l2,
4811 .mask = &attributes->l2_mask,
4813 switch (fdir_filter->action.behavior) {
4814 case RTE_ETH_FDIR_ACCEPT:
4815 attributes->actions[0] = (struct rte_flow_action){
4816 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
4817 .conf = &attributes->queue,
4820 case RTE_ETH_FDIR_REJECT:
4821 attributes->actions[0] = (struct rte_flow_action){
4822 .type = RTE_FLOW_ACTION_TYPE_DROP,
4826 DRV_LOG(ERR, "port %u invalid behavior %d",
4828 fdir_filter->action.behavior);
4829 rte_errno = ENOTSUP;
4832 attributes->queue.index = fdir_filter->action.rx_queue;
4834 switch (fdir_filter->input.flow_type) {
4835 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4836 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4837 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
4838 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
4839 .src_addr = input->flow.ip4_flow.src_ip,
4840 .dst_addr = input->flow.ip4_flow.dst_ip,
4841 .time_to_live = input->flow.ip4_flow.ttl,
4842 .type_of_service = input->flow.ip4_flow.tos,
4844 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
4845 .src_addr = mask->ipv4_mask.src_ip,
4846 .dst_addr = mask->ipv4_mask.dst_ip,
4847 .time_to_live = mask->ipv4_mask.ttl,
4848 .type_of_service = mask->ipv4_mask.tos,
4849 .next_proto_id = mask->ipv4_mask.proto,
4851 attributes->items[1] = (struct rte_flow_item){
4852 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4853 .spec = &attributes->l3,
4854 .mask = &attributes->l3_mask,
4857 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
4858 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
4859 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
4860 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
4861 .hop_limits = input->flow.ipv6_flow.hop_limits,
4862 .proto = input->flow.ipv6_flow.proto,
4865 memcpy(attributes->l3.ipv6.hdr.src_addr,
4866 input->flow.ipv6_flow.src_ip,
4867 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4868 memcpy(attributes->l3.ipv6.hdr.dst_addr,
4869 input->flow.ipv6_flow.dst_ip,
4870 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4871 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
4872 mask->ipv6_mask.src_ip,
4873 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4874 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
4875 mask->ipv6_mask.dst_ip,
4876 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4877 attributes->items[1] = (struct rte_flow_item){
4878 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4879 .spec = &attributes->l3,
4880 .mask = &attributes->l3_mask,
4884 DRV_LOG(ERR, "port %u invalid flow type%d",
4885 dev->data->port_id, fdir_filter->input.flow_type);
4886 rte_errno = ENOTSUP;
4890 switch (fdir_filter->input.flow_type) {
4891 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4892 attributes->l4.udp.hdr = (struct rte_udp_hdr){
4893 .src_port = input->flow.udp4_flow.src_port,
4894 .dst_port = input->flow.udp4_flow.dst_port,
4896 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
4897 .src_port = mask->src_port_mask,
4898 .dst_port = mask->dst_port_mask,
4900 attributes->items[2] = (struct rte_flow_item){
4901 .type = RTE_FLOW_ITEM_TYPE_UDP,
4902 .spec = &attributes->l4,
4903 .mask = &attributes->l4_mask,
4906 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4907 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
4908 .src_port = input->flow.tcp4_flow.src_port,
4909 .dst_port = input->flow.tcp4_flow.dst_port,
4911 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
4912 .src_port = mask->src_port_mask,
4913 .dst_port = mask->dst_port_mask,
4915 attributes->items[2] = (struct rte_flow_item){
4916 .type = RTE_FLOW_ITEM_TYPE_TCP,
4917 .spec = &attributes->l4,
4918 .mask = &attributes->l4_mask,
4921 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
4922 attributes->l4.udp.hdr = (struct rte_udp_hdr){
4923 .src_port = input->flow.udp6_flow.src_port,
4924 .dst_port = input->flow.udp6_flow.dst_port,
4926 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
4927 .src_port = mask->src_port_mask,
4928 .dst_port = mask->dst_port_mask,
4930 attributes->items[2] = (struct rte_flow_item){
4931 .type = RTE_FLOW_ITEM_TYPE_UDP,
4932 .spec = &attributes->l4,
4933 .mask = &attributes->l4_mask,
4936 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
4937 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
4938 .src_port = input->flow.tcp6_flow.src_port,
4939 .dst_port = input->flow.tcp6_flow.dst_port,
4941 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
4942 .src_port = mask->src_port_mask,
4943 .dst_port = mask->dst_port_mask,
4945 attributes->items[2] = (struct rte_flow_item){
4946 .type = RTE_FLOW_ITEM_TYPE_TCP,
4947 .spec = &attributes->l4,
4948 .mask = &attributes->l4_mask,
4951 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
4952 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
4955 DRV_LOG(ERR, "port %u invalid flow type%d",
4956 dev->data->port_id, fdir_filter->input.flow_type);
4957 rte_errno = ENOTSUP;
4963 #define FLOW_FDIR_CMP(f1, f2, fld) \
4964 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
4967 * Compare two FDIR flows. If items and actions are identical, the two flows are
4971 * Pointer to Ethernet device.
4973 * FDIR flow to compare.
4975 * FDIR flow to compare.
4978 * Zero on match, 1 otherwise.
4981 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
4983 if (FLOW_FDIR_CMP(f1, f2, attr) ||
4984 FLOW_FDIR_CMP(f1, f2, l2) ||
4985 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
4986 FLOW_FDIR_CMP(f1, f2, l3) ||
4987 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
4988 FLOW_FDIR_CMP(f1, f2, l4) ||
4989 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
4990 FLOW_FDIR_CMP(f1, f2, actions[0].type))
4992 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
4993 FLOW_FDIR_CMP(f1, f2, queue))
4999 * Search device flow list to find out a matched FDIR flow.
5002 * Pointer to Ethernet device.
5004 * FDIR flow to lookup.
5007 * Pointer of flow if found, NULL otherwise.
5009 static struct rte_flow *
5010 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
5012 struct mlx5_priv *priv = dev->data->dev_private;
5013 struct rte_flow *flow = NULL;
5016 TAILQ_FOREACH(flow, &priv->flows, next) {
5017 if (flow->fdir && !flow_fdir_cmp(flow->fdir, fdir_flow)) {
5018 DRV_LOG(DEBUG, "port %u found FDIR flow %p",
5019 dev->data->port_id, (void *)flow);
5027 * Add new flow director filter and store it in list.
5030 * Pointer to Ethernet device.
5031 * @param fdir_filter
5032 * Flow director filter to add.
5035 * 0 on success, a negative errno value otherwise and rte_errno is set.
5038 flow_fdir_filter_add(struct rte_eth_dev *dev,
5039 const struct rte_eth_fdir_filter *fdir_filter)
5041 struct mlx5_priv *priv = dev->data->dev_private;
5042 struct mlx5_fdir *fdir_flow;
5043 struct rte_flow *flow;
5046 fdir_flow = rte_zmalloc(__func__, sizeof(*fdir_flow), 0);
5051 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
5054 flow = flow_fdir_filter_lookup(dev, fdir_flow);
5059 flow = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
5060 fdir_flow->items, fdir_flow->actions, true,
5064 assert(!flow->fdir);
5065 flow->fdir = fdir_flow;
5066 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
5067 dev->data->port_id, (void *)flow);
5070 rte_free(fdir_flow);
5075 * Delete specific filter.
5078 * Pointer to Ethernet device.
5079 * @param fdir_filter
5080 * Filter to be deleted.
5083 * 0 on success, a negative errno value otherwise and rte_errno is set.
5086 flow_fdir_filter_delete(struct rte_eth_dev *dev,
5087 const struct rte_eth_fdir_filter *fdir_filter)
5089 struct mlx5_priv *priv = dev->data->dev_private;
5090 struct rte_flow *flow;
5091 struct mlx5_fdir fdir_flow = {
5096 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
5099 flow = flow_fdir_filter_lookup(dev, &fdir_flow);
5104 flow_list_destroy(dev, &priv->flows, flow);
5105 DRV_LOG(DEBUG, "port %u deleted FDIR flow %p",
5106 dev->data->port_id, (void *)flow);
5111 * Update queue for specific filter.
5114 * Pointer to Ethernet device.
5115 * @param fdir_filter
5116 * Filter to be updated.
5119 * 0 on success, a negative errno value otherwise and rte_errno is set.
5122 flow_fdir_filter_update(struct rte_eth_dev *dev,
5123 const struct rte_eth_fdir_filter *fdir_filter)
5127 ret = flow_fdir_filter_delete(dev, fdir_filter);
5130 return flow_fdir_filter_add(dev, fdir_filter);
5134 * Flush all filters.
5137 * Pointer to Ethernet device.
5140 flow_fdir_filter_flush(struct rte_eth_dev *dev)
5142 struct mlx5_priv *priv = dev->data->dev_private;
5144 mlx5_flow_list_flush(dev, &priv->flows);
5148 * Get flow director information.
5151 * Pointer to Ethernet device.
5152 * @param[out] fdir_info
5153 * Resulting flow director information.
5156 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
5158 struct rte_eth_fdir_masks *mask =
5159 &dev->data->dev_conf.fdir_conf.mask;
5161 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
5162 fdir_info->guarant_spc = 0;
5163 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
5164 fdir_info->max_flexpayload = 0;
5165 fdir_info->flow_types_mask[0] = 0;
5166 fdir_info->flex_payload_unit = 0;
5167 fdir_info->max_flex_payload_segment_num = 0;
5168 fdir_info->flex_payload_limit = 0;
5169 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
5173 * Deal with flow director operations.
5176 * Pointer to Ethernet device.
5178 * Operation to perform.
5180 * Pointer to operation-specific structure.
5183 * 0 on success, a negative errno value otherwise and rte_errno is set.
5186 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
5189 enum rte_fdir_mode fdir_mode =
5190 dev->data->dev_conf.fdir_conf.mode;
5192 if (filter_op == RTE_ETH_FILTER_NOP)
5194 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
5195 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5196 DRV_LOG(ERR, "port %u flow director mode %d not supported",
5197 dev->data->port_id, fdir_mode);
5201 switch (filter_op) {
5202 case RTE_ETH_FILTER_ADD:
5203 return flow_fdir_filter_add(dev, arg);
5204 case RTE_ETH_FILTER_UPDATE:
5205 return flow_fdir_filter_update(dev, arg);
5206 case RTE_ETH_FILTER_DELETE:
5207 return flow_fdir_filter_delete(dev, arg);
5208 case RTE_ETH_FILTER_FLUSH:
5209 flow_fdir_filter_flush(dev);
5211 case RTE_ETH_FILTER_INFO:
5212 flow_fdir_info_get(dev, arg);
5215 DRV_LOG(DEBUG, "port %u unknown operation %u",
5216 dev->data->port_id, filter_op);
5224 * Manage filter operations.
5227 * Pointer to Ethernet device structure.
5228 * @param filter_type
5231 * Operation to perform.
5233 * Pointer to operation-specific structure.
5236 * 0 on success, a negative errno value otherwise and rte_errno is set.
5239 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
5240 enum rte_filter_type filter_type,
5241 enum rte_filter_op filter_op,
5244 switch (filter_type) {
5245 case RTE_ETH_FILTER_GENERIC:
5246 if (filter_op != RTE_ETH_FILTER_GET) {
5250 *(const void **)arg = &mlx5_flow_ops;
5252 case RTE_ETH_FILTER_FDIR:
5253 return flow_fdir_ctrl_func(dev, filter_op, arg);
5255 DRV_LOG(ERR, "port %u filter type (%d) not supported",
5256 dev->data->port_id, filter_type);
5257 rte_errno = ENOTSUP;
5264 * Create the needed meter and suffix tables.
5267 * Pointer to Ethernet device.
5269 * Pointer to the flow meter.
5272 * Pointer to table set on success, NULL otherwise.
5274 struct mlx5_meter_domains_infos *
5275 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
5276 const struct mlx5_flow_meter *fm)
5278 const struct mlx5_flow_driver_ops *fops;
5280 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5281 return fops->create_mtr_tbls(dev, fm);
5285 * Destroy the meter table set.
5288 * Pointer to Ethernet device.
5290 * Pointer to the meter table set.
5296 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
5297 struct mlx5_meter_domains_infos *tbls)
5299 const struct mlx5_flow_driver_ops *fops;
5301 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5302 return fops->destroy_mtr_tbls(dev, tbls);
5306 * Create policer rules.
5309 * Pointer to Ethernet device.
5311 * Pointer to flow meter structure.
5313 * Pointer to flow attributes.
5316 * 0 on success, -1 otherwise.
5319 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
5320 struct mlx5_flow_meter *fm,
5321 const struct rte_flow_attr *attr)
5323 const struct mlx5_flow_driver_ops *fops;
5325 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5326 return fops->create_policer_rules(dev, fm, attr);
5330 * Destroy policer rules.
5333 * Pointer to flow meter structure.
5335 * Pointer to flow attributes.
5338 * 0 on success, -1 otherwise.
5341 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
5342 struct mlx5_flow_meter *fm,
5343 const struct rte_flow_attr *attr)
5345 const struct mlx5_flow_driver_ops *fops;
5347 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5348 return fops->destroy_policer_rules(dev, fm, attr);
5352 * Allocate a counter.
5355 * Pointer to Ethernet device structure.
5358 * Pointer to allocated counter on success, NULL otherwise.
5360 struct mlx5_flow_counter *
5361 mlx5_counter_alloc(struct rte_eth_dev *dev)
5363 const struct mlx5_flow_driver_ops *fops;
5364 struct rte_flow_attr attr = { .transfer = 0 };
5366 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5367 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5368 return fops->counter_alloc(dev);
5371 "port %u counter allocate is not supported.",
5372 dev->data->port_id);
5380 * Pointer to Ethernet device structure.
5382 * Pointer to counter to be free.
5385 mlx5_counter_free(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt)
5387 const struct mlx5_flow_driver_ops *fops;
5388 struct rte_flow_attr attr = { .transfer = 0 };
5390 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5391 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5392 fops->counter_free(dev, cnt);
5396 "port %u counter free is not supported.",
5397 dev->data->port_id);
5401 * Query counter statistics.
5404 * Pointer to Ethernet device structure.
5406 * Pointer to counter to query.
5408 * Set to clear counter statistics.
5410 * The counter hits packets number to save.
5412 * The counter hits bytes number to save.
5415 * 0 on success, a negative errno value otherwise.
5418 mlx5_counter_query(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt,
5419 bool clear, uint64_t *pkts, uint64_t *bytes)
5421 const struct mlx5_flow_driver_ops *fops;
5422 struct rte_flow_attr attr = { .transfer = 0 };
5424 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5425 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5426 return fops->counter_query(dev, cnt, clear, pkts, bytes);
5429 "port %u counter query is not supported.",
5430 dev->data->port_id);
5434 #define MLX5_POOL_QUERY_FREQ_US 1000000
5437 * Set the periodic procedure for triggering asynchronous batch queries for all
5438 * the counter pools.
5441 * Pointer to mlx5_ibv_shared object.
5444 mlx5_set_query_alarm(struct mlx5_ibv_shared *sh)
5446 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(sh, 0, 0);
5447 uint32_t pools_n = rte_atomic16_read(&cont->n_valid);
5450 cont = MLX5_CNT_CONTAINER(sh, 1, 0);
5451 pools_n += rte_atomic16_read(&cont->n_valid);
5452 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
5453 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
5454 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
5455 sh->cmng.query_thread_on = 0;
5456 DRV_LOG(ERR, "Cannot reinitialize query alarm");
5458 sh->cmng.query_thread_on = 1;
5463 * The periodic procedure for triggering asynchronous batch queries for all the
5464 * counter pools. This function is probably called by the host thread.
5467 * The parameter for the alarm process.
5470 mlx5_flow_query_alarm(void *arg)
5472 struct mlx5_ibv_shared *sh = arg;
5473 struct mlx5_devx_obj *dcs;
5476 uint8_t batch = sh->cmng.batch;
5477 uint16_t pool_index = sh->cmng.pool_index;
5478 struct mlx5_pools_container *cont;
5479 struct mlx5_pools_container *mcont;
5480 struct mlx5_flow_counter_pool *pool;
5482 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
5485 cont = MLX5_CNT_CONTAINER(sh, batch, 1);
5486 mcont = MLX5_CNT_CONTAINER(sh, batch, 0);
5487 /* Check if resize was done and need to flip a container. */
5488 if (cont != mcont) {
5490 /* Clean the old container. */
5491 rte_free(cont->pools);
5492 memset(cont, 0, sizeof(*cont));
5495 /* Flip the host container. */
5496 sh->cmng.mhi[batch] ^= (uint8_t)2;
5500 /* 2 empty containers case is unexpected. */
5501 if (unlikely(batch != sh->cmng.batch))
5505 goto next_container;
5507 pool = cont->pools[pool_index];
5509 /* There is a pool query in progress. */
5512 LIST_FIRST(&sh->cmng.free_stat_raws);
5514 /* No free counter statistics raw memory. */
5516 dcs = (struct mlx5_devx_obj *)(uintptr_t)rte_atomic64_read
5518 offset = batch ? 0 : dcs->id % MLX5_COUNTERS_PER_POOL;
5519 ret = mlx5_devx_cmd_flow_counter_query(dcs, 0, MLX5_COUNTERS_PER_POOL -
5521 pool->raw_hw->mem_mng->dm->id,
5523 (pool->raw_hw->data + offset),
5525 (uint64_t)(uintptr_t)pool);
5527 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
5528 " %d", pool->min_dcs->id);
5529 pool->raw_hw = NULL;
5532 pool->raw_hw->min_dcs_id = dcs->id;
5533 LIST_REMOVE(pool->raw_hw, next);
5534 sh->cmng.pending_queries++;
5536 if (pool_index >= rte_atomic16_read(&cont->n_valid)) {
5541 sh->cmng.batch = batch;
5542 sh->cmng.pool_index = pool_index;
5543 mlx5_set_query_alarm(sh);
5547 * Handler for the HW respond about ready values from an asynchronous batch
5548 * query. This function is probably called by the host thread.
5551 * The pointer to the shared IB device context.
5552 * @param[in] async_id
5553 * The Devx async ID.
5555 * The status of the completion.
5558 mlx5_flow_async_pool_query_handle(struct mlx5_ibv_shared *sh,
5559 uint64_t async_id, int status)
5561 struct mlx5_flow_counter_pool *pool =
5562 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
5563 struct mlx5_counter_stats_raw *raw_to_free;
5565 if (unlikely(status)) {
5566 raw_to_free = pool->raw_hw;
5568 raw_to_free = pool->raw;
5569 rte_spinlock_lock(&pool->sl);
5570 pool->raw = pool->raw_hw;
5571 rte_spinlock_unlock(&pool->sl);
5572 rte_atomic64_add(&pool->query_gen, 1);
5573 /* Be sure the new raw counters data is updated in memory. */
5576 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
5577 pool->raw_hw = NULL;
5578 sh->cmng.pending_queries--;
5582 * Translate the rte_flow group index to HW table value.
5584 * @param[in] attributes
5585 * Pointer to flow attributes
5586 * @param[in] external
5587 * Value is part of flow rule created by request external to PMD.
5589 * rte_flow group index value.
5593 * Pointer to error structure.
5596 * 0 on success, a negative errno value otherwise and rte_errno is set.
5599 mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, bool external,
5600 uint32_t group, uint32_t *table,
5601 struct rte_flow_error *error)
5603 if (attributes->transfer && external) {
5604 if (group == UINT32_MAX)
5605 return rte_flow_error_set
5607 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5609 "group index not supported");
5618 * Discover availability of metadata reg_c's.
5620 * Iteratively use test flows to check availability.
5623 * Pointer to the Ethernet device structure.
5626 * 0 on success, a negative errno value otherwise and rte_errno is set.
5629 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
5631 struct mlx5_priv *priv = dev->data->dev_private;
5632 struct mlx5_dev_config *config = &priv->config;
5633 enum modify_reg idx;
5636 /* reg_c[0] and reg_c[1] are reserved. */
5637 config->flow_mreg_c[n++] = REG_C_0;
5638 config->flow_mreg_c[n++] = REG_C_1;
5639 /* Discover availability of other reg_c's. */
5640 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
5641 struct rte_flow_attr attr = {
5642 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5643 .priority = MLX5_FLOW_PRIO_RSVD,
5646 struct rte_flow_item items[] = {
5648 .type = RTE_FLOW_ITEM_TYPE_END,
5651 struct rte_flow_action actions[] = {
5653 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5654 .conf = &(struct mlx5_flow_action_copy_mreg){
5660 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5661 .conf = &(struct rte_flow_action_jump){
5662 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5666 .type = RTE_FLOW_ACTION_TYPE_END,
5669 struct rte_flow *flow;
5670 struct rte_flow_error error;
5672 if (!config->dv_flow_en)
5674 /* Create internal flow, validation skips copy action. */
5675 flow = flow_list_create(dev, NULL, &attr, items,
5676 actions, false, &error);
5679 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
5680 config->flow_mreg_c[n++] = idx;
5681 flow_list_destroy(dev, NULL, flow);
5683 for (; n < MLX5_MREG_C_NUM; ++n)
5684 config->flow_mreg_c[n] = REG_NONE;
5689 * Dump flow raw hw data to file
5692 * The pointer to Ethernet device.
5694 * A pointer to a file for output.
5696 * Perform verbose error reporting if not NULL. PMDs initialize this
5697 * structure in case of error only.
5699 * 0 on success, a nagative value otherwise.
5702 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
5704 struct rte_flow_error *error __rte_unused)
5706 struct mlx5_priv *priv = dev->data->dev_private;
5708 return mlx5_devx_cmd_flow_dump(priv->sh, file);