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;
353 bool skip_mtr_reg = false;
356 case MLX5_HAIRPIN_RX:
358 case MLX5_HAIRPIN_TX:
360 case MLX5_METADATA_RX:
361 switch (config->dv_xmeta_en) {
362 case MLX5_XMETA_MODE_LEGACY:
364 case MLX5_XMETA_MODE_META16:
366 case MLX5_XMETA_MODE_META32:
370 case MLX5_METADATA_TX:
372 case MLX5_METADATA_FDB:
373 switch (config->dv_xmeta_en) {
374 case MLX5_XMETA_MODE_LEGACY:
376 case MLX5_XMETA_MODE_META16:
378 case MLX5_XMETA_MODE_META32:
383 switch (config->dv_xmeta_en) {
384 case MLX5_XMETA_MODE_LEGACY:
386 case MLX5_XMETA_MODE_META16:
388 case MLX5_XMETA_MODE_META32:
394 * If meter color and flow match share one register, flow match
395 * should use the meter color register for match.
397 if (priv->mtr_reg_share)
398 return priv->mtr_color_reg;
400 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
403 RTE_ASSERT(priv->mtr_color_reg != REG_NONE);
404 return priv->mtr_color_reg;
407 * Metadata COPY_MARK register using is in meter suffix sub
408 * flow while with meter. It's safe to share the same register.
410 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
413 * If meter is enable, it will engage the register for color
414 * match and flow match. If meter color match is not using the
415 * REG_C_2, need to skip the REG_C_x be used by meter color
417 * If meter is disable, free to use all available registers.
419 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_2 :
420 (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
421 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
422 if (id > (REG_C_7 - start_reg))
423 return rte_flow_error_set(error, EINVAL,
424 RTE_FLOW_ERROR_TYPE_ITEM,
425 NULL, "invalid tag id");
426 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NONE)
427 return rte_flow_error_set(error, ENOTSUP,
428 RTE_FLOW_ERROR_TYPE_ITEM,
429 NULL, "unsupported tag id");
431 * This case means meter is using the REG_C_x great than 2.
432 * Take care not to conflict with meter color REG_C_x.
433 * If the available index REG_C_y >= REG_C_x, skip the
436 if (skip_mtr_reg && config->flow_mreg_c
437 [id + start_reg - REG_C_0] >= priv->mtr_color_reg) {
438 if (config->flow_mreg_c
439 [id + 1 + start_reg - REG_C_0] != REG_NONE)
440 return config->flow_mreg_c
441 [id + 1 + start_reg - REG_C_0];
442 return rte_flow_error_set(error, ENOTSUP,
443 RTE_FLOW_ERROR_TYPE_ITEM,
444 NULL, "unsupported tag id");
446 return config->flow_mreg_c[id + start_reg - REG_C_0];
449 return rte_flow_error_set(error, EINVAL,
450 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
451 NULL, "invalid feature name");
455 * Check extensive flow metadata register support.
458 * Pointer to rte_eth_dev structure.
461 * True if device supports extensive flow metadata register, otherwise false.
464 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
466 struct mlx5_priv *priv = dev->data->dev_private;
467 struct mlx5_dev_config *config = &priv->config;
470 * Having available reg_c can be regarded inclusively as supporting
471 * extensive flow metadata register, which could mean,
472 * - metadata register copy action by modify header.
473 * - 16 modify header actions is supported.
474 * - reg_c's are preserved across different domain (FDB and NIC) on
475 * packet loopback by flow lookup miss.
477 return config->flow_mreg_c[2] != REG_NONE;
481 * Discover the maximum number of priority available.
484 * Pointer to the Ethernet device structure.
487 * number of supported flow priority on success, a negative errno
488 * value otherwise and rte_errno is set.
491 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
493 struct mlx5_priv *priv = dev->data->dev_private;
495 struct ibv_flow_attr attr;
496 struct ibv_flow_spec_eth eth;
497 struct ibv_flow_spec_action_drop drop;
501 .port = (uint8_t)priv->ibv_port,
504 .type = IBV_FLOW_SPEC_ETH,
505 .size = sizeof(struct ibv_flow_spec_eth),
508 .size = sizeof(struct ibv_flow_spec_action_drop),
509 .type = IBV_FLOW_SPEC_ACTION_DROP,
512 struct ibv_flow *flow;
513 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
514 uint16_t vprio[] = { 8, 16 };
522 for (i = 0; i != RTE_DIM(vprio); i++) {
523 flow_attr.attr.priority = vprio[i] - 1;
524 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
527 claim_zero(mlx5_glue->destroy_flow(flow));
530 mlx5_hrxq_drop_release(dev);
533 priority = RTE_DIM(priority_map_3);
536 priority = RTE_DIM(priority_map_5);
541 "port %u verbs maximum priority: %d expected 8/16",
542 dev->data->port_id, priority);
545 DRV_LOG(INFO, "port %u flow maximum priority: %d",
546 dev->data->port_id, priority);
551 * Adjust flow priority based on the highest layer and the request priority.
554 * Pointer to the Ethernet device structure.
555 * @param[in] priority
556 * The rule base priority.
557 * @param[in] subpriority
558 * The priority based on the items.
563 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
564 uint32_t subpriority)
567 struct mlx5_priv *priv = dev->data->dev_private;
569 switch (priv->config.flow_prio) {
570 case RTE_DIM(priority_map_3):
571 res = priority_map_3[priority][subpriority];
573 case RTE_DIM(priority_map_5):
574 res = priority_map_5[priority][subpriority];
581 * Verify the @p item specifications (spec, last, mask) are compatible with the
585 * Item specification.
587 * @p item->mask or flow default bit-masks.
588 * @param[in] nic_mask
589 * Bit-masks covering supported fields by the NIC to compare with user mask.
591 * Bit-masks size in bytes.
593 * Pointer to error structure.
596 * 0 on success, a negative errno value otherwise and rte_errno is set.
599 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
601 const uint8_t *nic_mask,
603 struct rte_flow_error *error)
608 for (i = 0; i < size; ++i)
609 if ((nic_mask[i] | mask[i]) != nic_mask[i])
610 return rte_flow_error_set(error, ENOTSUP,
611 RTE_FLOW_ERROR_TYPE_ITEM,
613 "mask enables non supported"
615 if (!item->spec && (item->mask || item->last))
616 return rte_flow_error_set(error, EINVAL,
617 RTE_FLOW_ERROR_TYPE_ITEM, item,
618 "mask/last without a spec is not"
620 if (item->spec && item->last) {
626 for (i = 0; i < size; ++i) {
627 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
628 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
630 ret = memcmp(spec, last, size);
632 return rte_flow_error_set(error, EINVAL,
633 RTE_FLOW_ERROR_TYPE_ITEM,
635 "range is not valid");
641 * Adjust the hash fields according to the @p flow information.
643 * @param[in] dev_flow.
644 * Pointer to the mlx5_flow.
646 * 1 when the hash field is for a tunnel item.
647 * @param[in] layer_types
649 * @param[in] hash_fields
653 * The hash fields that should be used.
656 mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow,
657 int tunnel __rte_unused, uint64_t layer_types,
658 uint64_t hash_fields)
660 struct rte_flow *flow = dev_flow->flow;
661 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
662 int rss_request_inner = flow->rss.level >= 2;
664 /* Check RSS hash level for tunnel. */
665 if (tunnel && rss_request_inner)
666 hash_fields |= IBV_RX_HASH_INNER;
667 else if (tunnel || rss_request_inner)
670 /* Check if requested layer matches RSS hash fields. */
671 if (!(flow->rss.types & layer_types))
677 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
678 * if several tunnel rules are used on this queue, the tunnel ptype will be
682 * Rx queue to update.
685 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
688 uint32_t tunnel_ptype = 0;
690 /* Look up for the ptype to use. */
691 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
692 if (!rxq_ctrl->flow_tunnels_n[i])
695 tunnel_ptype = tunnels_info[i].ptype;
701 rxq_ctrl->rxq.tunnel = tunnel_ptype;
705 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
709 * Pointer to the Ethernet device structure.
710 * @param[in] dev_flow
711 * Pointer to device flow structure.
714 flow_drv_rxq_flags_set(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
716 struct mlx5_priv *priv = dev->data->dev_private;
717 struct rte_flow *flow = dev_flow->flow;
718 const int mark = !!(dev_flow->actions &
719 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
720 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
723 for (i = 0; i != flow->rss.queue_num; ++i) {
724 int idx = (*flow->rss.queue)[i];
725 struct mlx5_rxq_ctrl *rxq_ctrl =
726 container_of((*priv->rxqs)[idx],
727 struct mlx5_rxq_ctrl, rxq);
730 * To support metadata register copy on Tx loopback,
731 * this must be always enabled (metadata may arive
732 * from other port - not from local flows only.
734 if (priv->config.dv_flow_en &&
735 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
736 mlx5_flow_ext_mreg_supported(dev)) {
737 rxq_ctrl->rxq.mark = 1;
738 rxq_ctrl->flow_mark_n = 1;
740 rxq_ctrl->rxq.mark = 1;
741 rxq_ctrl->flow_mark_n++;
746 /* Increase the counter matching the flow. */
747 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
748 if ((tunnels_info[j].tunnel &
750 tunnels_info[j].tunnel) {
751 rxq_ctrl->flow_tunnels_n[j]++;
755 flow_rxq_tunnel_ptype_update(rxq_ctrl);
761 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
764 * Pointer to the Ethernet device structure.
766 * Pointer to flow structure.
769 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
771 struct mlx5_flow *dev_flow;
773 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
774 flow_drv_rxq_flags_set(dev, dev_flow);
778 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
779 * device flow if no other flow uses it with the same kind of request.
782 * Pointer to Ethernet device.
783 * @param[in] dev_flow
784 * Pointer to the device flow.
787 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
789 struct mlx5_priv *priv = dev->data->dev_private;
790 struct rte_flow *flow = dev_flow->flow;
791 const int mark = !!(dev_flow->actions &
792 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
793 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
796 assert(dev->data->dev_started);
797 for (i = 0; i != flow->rss.queue_num; ++i) {
798 int idx = (*flow->rss.queue)[i];
799 struct mlx5_rxq_ctrl *rxq_ctrl =
800 container_of((*priv->rxqs)[idx],
801 struct mlx5_rxq_ctrl, rxq);
803 if (priv->config.dv_flow_en &&
804 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
805 mlx5_flow_ext_mreg_supported(dev)) {
806 rxq_ctrl->rxq.mark = 1;
807 rxq_ctrl->flow_mark_n = 1;
809 rxq_ctrl->flow_mark_n--;
810 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
815 /* Decrease the counter matching the flow. */
816 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
817 if ((tunnels_info[j].tunnel &
819 tunnels_info[j].tunnel) {
820 rxq_ctrl->flow_tunnels_n[j]--;
824 flow_rxq_tunnel_ptype_update(rxq_ctrl);
830 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
831 * @p flow if no other flow uses it with the same kind of request.
834 * Pointer to Ethernet device.
836 * Pointer to the flow.
839 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
841 struct mlx5_flow *dev_flow;
843 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
844 flow_drv_rxq_flags_trim(dev, dev_flow);
848 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
851 * Pointer to Ethernet device.
854 flow_rxq_flags_clear(struct rte_eth_dev *dev)
856 struct mlx5_priv *priv = dev->data->dev_private;
859 for (i = 0; i != priv->rxqs_n; ++i) {
860 struct mlx5_rxq_ctrl *rxq_ctrl;
863 if (!(*priv->rxqs)[i])
865 rxq_ctrl = container_of((*priv->rxqs)[i],
866 struct mlx5_rxq_ctrl, rxq);
867 rxq_ctrl->flow_mark_n = 0;
868 rxq_ctrl->rxq.mark = 0;
869 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
870 rxq_ctrl->flow_tunnels_n[j] = 0;
871 rxq_ctrl->rxq.tunnel = 0;
876 * return a pointer to the desired action in the list of actions.
879 * The list of actions to search the action in.
881 * The action to find.
884 * Pointer to the action in the list, if found. NULL otherwise.
886 const struct rte_flow_action *
887 mlx5_flow_find_action(const struct rte_flow_action *actions,
888 enum rte_flow_action_type action)
892 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
893 if (actions->type == action)
899 * Validate the flag action.
901 * @param[in] action_flags
902 * Bit-fields that holds the actions detected until now.
904 * Attributes of flow that includes this action.
906 * Pointer to error structure.
909 * 0 on success, a negative errno value otherwise and rte_errno is set.
912 mlx5_flow_validate_action_flag(uint64_t action_flags,
913 const struct rte_flow_attr *attr,
914 struct rte_flow_error *error)
916 if (action_flags & MLX5_FLOW_ACTION_MARK)
917 return rte_flow_error_set(error, EINVAL,
918 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
919 "can't mark and flag in same flow");
920 if (action_flags & MLX5_FLOW_ACTION_FLAG)
921 return rte_flow_error_set(error, EINVAL,
922 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
924 " actions in same flow");
926 return rte_flow_error_set(error, ENOTSUP,
927 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
928 "flag action not supported for "
934 * Validate the mark action.
937 * Pointer to the queue action.
938 * @param[in] action_flags
939 * Bit-fields that holds the actions detected until now.
941 * Attributes of flow that includes this action.
943 * Pointer to error structure.
946 * 0 on success, a negative errno value otherwise and rte_errno is set.
949 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
950 uint64_t action_flags,
951 const struct rte_flow_attr *attr,
952 struct rte_flow_error *error)
954 const struct rte_flow_action_mark *mark = action->conf;
957 return rte_flow_error_set(error, EINVAL,
958 RTE_FLOW_ERROR_TYPE_ACTION,
960 "configuration cannot be null");
961 if (mark->id >= MLX5_FLOW_MARK_MAX)
962 return rte_flow_error_set(error, EINVAL,
963 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
965 "mark id must in 0 <= id < "
966 RTE_STR(MLX5_FLOW_MARK_MAX));
967 if (action_flags & MLX5_FLOW_ACTION_FLAG)
968 return rte_flow_error_set(error, EINVAL,
969 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
970 "can't flag and mark in same flow");
971 if (action_flags & MLX5_FLOW_ACTION_MARK)
972 return rte_flow_error_set(error, EINVAL,
973 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
974 "can't have 2 mark actions in same"
977 return rte_flow_error_set(error, ENOTSUP,
978 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
979 "mark action not supported for "
985 * Validate the drop action.
987 * @param[in] action_flags
988 * Bit-fields that holds the actions detected until now.
990 * Attributes of flow that includes this action.
992 * Pointer to error structure.
995 * 0 on success, a negative errno value otherwise and rte_errno is set.
998 mlx5_flow_validate_action_drop(uint64_t action_flags __rte_unused,
999 const struct rte_flow_attr *attr,
1000 struct rte_flow_error *error)
1003 return rte_flow_error_set(error, ENOTSUP,
1004 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1005 "drop action not supported for "
1011 * Validate the queue action.
1014 * Pointer to the queue action.
1015 * @param[in] action_flags
1016 * Bit-fields that holds the actions detected until now.
1018 * Pointer to the Ethernet device structure.
1020 * Attributes of flow that includes this action.
1022 * Pointer to error structure.
1025 * 0 on success, a negative errno value otherwise and rte_errno is set.
1028 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1029 uint64_t action_flags,
1030 struct rte_eth_dev *dev,
1031 const struct rte_flow_attr *attr,
1032 struct rte_flow_error *error)
1034 struct mlx5_priv *priv = dev->data->dev_private;
1035 const struct rte_flow_action_queue *queue = action->conf;
1037 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1038 return rte_flow_error_set(error, EINVAL,
1039 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1040 "can't have 2 fate actions in"
1043 return rte_flow_error_set(error, EINVAL,
1044 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1045 NULL, "No Rx queues configured");
1046 if (queue->index >= priv->rxqs_n)
1047 return rte_flow_error_set(error, EINVAL,
1048 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1050 "queue index out of range");
1051 if (!(*priv->rxqs)[queue->index])
1052 return rte_flow_error_set(error, EINVAL,
1053 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1055 "queue is not configured");
1057 return rte_flow_error_set(error, ENOTSUP,
1058 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1059 "queue action not supported for "
1065 * Validate the rss action.
1068 * Pointer to the queue action.
1069 * @param[in] action_flags
1070 * Bit-fields that holds the actions detected until now.
1072 * Pointer to the Ethernet device structure.
1074 * Attributes of flow that includes this action.
1075 * @param[in] item_flags
1076 * Items that were detected.
1078 * Pointer to error structure.
1081 * 0 on success, a negative errno value otherwise and rte_errno is set.
1084 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1085 uint64_t action_flags,
1086 struct rte_eth_dev *dev,
1087 const struct rte_flow_attr *attr,
1088 uint64_t item_flags,
1089 struct rte_flow_error *error)
1091 struct mlx5_priv *priv = dev->data->dev_private;
1092 const struct rte_flow_action_rss *rss = action->conf;
1093 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1096 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1097 return rte_flow_error_set(error, EINVAL,
1098 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1099 "can't have 2 fate actions"
1101 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1102 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1103 return rte_flow_error_set(error, ENOTSUP,
1104 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1106 "RSS hash function not supported");
1107 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1112 return rte_flow_error_set(error, ENOTSUP,
1113 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1115 "tunnel RSS is not supported");
1116 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1117 if (rss->key_len == 0 && rss->key != NULL)
1118 return rte_flow_error_set(error, ENOTSUP,
1119 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1121 "RSS hash key length 0");
1122 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1123 return rte_flow_error_set(error, ENOTSUP,
1124 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1126 "RSS hash key too small");
1127 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1128 return rte_flow_error_set(error, ENOTSUP,
1129 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1131 "RSS hash key too large");
1132 if (rss->queue_num > priv->config.ind_table_max_size)
1133 return rte_flow_error_set(error, ENOTSUP,
1134 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1136 "number of queues too large");
1137 if (rss->types & MLX5_RSS_HF_MASK)
1138 return rte_flow_error_set(error, ENOTSUP,
1139 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1141 "some RSS protocols are not"
1143 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1144 !(rss->types & ETH_RSS_IP))
1145 return rte_flow_error_set(error, EINVAL,
1146 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1147 "L3 partial RSS requested but L3 RSS"
1148 " type not specified");
1149 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1150 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1151 return rte_flow_error_set(error, EINVAL,
1152 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1153 "L4 partial RSS requested but L4 RSS"
1154 " type not specified");
1156 return rte_flow_error_set(error, EINVAL,
1157 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1158 NULL, "No Rx queues configured");
1159 if (!rss->queue_num)
1160 return rte_flow_error_set(error, EINVAL,
1161 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1162 NULL, "No queues configured");
1163 for (i = 0; i != rss->queue_num; ++i) {
1164 if (rss->queue[i] >= priv->rxqs_n)
1165 return rte_flow_error_set
1167 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1168 &rss->queue[i], "queue index out of range");
1169 if (!(*priv->rxqs)[rss->queue[i]])
1170 return rte_flow_error_set
1171 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1172 &rss->queue[i], "queue is not configured");
1175 return rte_flow_error_set(error, ENOTSUP,
1176 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1177 "rss action not supported for "
1179 if (rss->level > 1 && !tunnel)
1180 return rte_flow_error_set(error, EINVAL,
1181 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1182 "inner RSS is not supported for "
1183 "non-tunnel flows");
1188 * Validate the count action.
1191 * Pointer to the Ethernet device structure.
1193 * Attributes of flow that includes this action.
1195 * Pointer to error structure.
1198 * 0 on success, a negative errno value otherwise and rte_errno is set.
1201 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1202 const struct rte_flow_attr *attr,
1203 struct rte_flow_error *error)
1206 return rte_flow_error_set(error, ENOTSUP,
1207 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1208 "count action not supported for "
1214 * Verify the @p attributes will be correctly understood by the NIC and store
1215 * them in the @p flow if everything is correct.
1218 * Pointer to the Ethernet device structure.
1219 * @param[in] attributes
1220 * Pointer to flow attributes
1222 * Pointer to error structure.
1225 * 0 on success, a negative errno value otherwise and rte_errno is set.
1228 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1229 const struct rte_flow_attr *attributes,
1230 struct rte_flow_error *error)
1232 struct mlx5_priv *priv = dev->data->dev_private;
1233 uint32_t priority_max = priv->config.flow_prio - 1;
1235 if (attributes->group)
1236 return rte_flow_error_set(error, ENOTSUP,
1237 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1238 NULL, "groups is not supported");
1239 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1240 attributes->priority >= priority_max)
1241 return rte_flow_error_set(error, ENOTSUP,
1242 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1243 NULL, "priority out of range");
1244 if (attributes->egress)
1245 return rte_flow_error_set(error, ENOTSUP,
1246 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1247 "egress is not supported");
1248 if (attributes->transfer && !priv->config.dv_esw_en)
1249 return rte_flow_error_set(error, ENOTSUP,
1250 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1251 NULL, "transfer is not supported");
1252 if (!attributes->ingress)
1253 return rte_flow_error_set(error, EINVAL,
1254 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1256 "ingress attribute is mandatory");
1261 * Validate ICMP6 item.
1264 * Item specification.
1265 * @param[in] item_flags
1266 * Bit-fields that holds the items detected until now.
1268 * Pointer to error structure.
1271 * 0 on success, a negative errno value otherwise and rte_errno is set.
1274 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1275 uint64_t item_flags,
1276 uint8_t target_protocol,
1277 struct rte_flow_error *error)
1279 const struct rte_flow_item_icmp6 *mask = item->mask;
1280 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1281 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1282 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1283 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1284 MLX5_FLOW_LAYER_OUTER_L4;
1287 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1288 return rte_flow_error_set(error, EINVAL,
1289 RTE_FLOW_ERROR_TYPE_ITEM, item,
1290 "protocol filtering not compatible"
1291 " with ICMP6 layer");
1292 if (!(item_flags & l3m))
1293 return rte_flow_error_set(error, EINVAL,
1294 RTE_FLOW_ERROR_TYPE_ITEM, item,
1295 "IPv6 is mandatory to filter on"
1297 if (item_flags & l4m)
1298 return rte_flow_error_set(error, EINVAL,
1299 RTE_FLOW_ERROR_TYPE_ITEM, item,
1300 "multiple L4 layers not supported");
1302 mask = &rte_flow_item_icmp6_mask;
1303 ret = mlx5_flow_item_acceptable
1304 (item, (const uint8_t *)mask,
1305 (const uint8_t *)&rte_flow_item_icmp6_mask,
1306 sizeof(struct rte_flow_item_icmp6), error);
1313 * Validate ICMP item.
1316 * Item specification.
1317 * @param[in] item_flags
1318 * Bit-fields that holds the items detected until now.
1320 * Pointer to error structure.
1323 * 0 on success, a negative errno value otherwise and rte_errno is set.
1326 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1327 uint64_t item_flags,
1328 uint8_t target_protocol,
1329 struct rte_flow_error *error)
1331 const struct rte_flow_item_icmp *mask = item->mask;
1332 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1333 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1334 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1335 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1336 MLX5_FLOW_LAYER_OUTER_L4;
1339 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1340 return rte_flow_error_set(error, EINVAL,
1341 RTE_FLOW_ERROR_TYPE_ITEM, item,
1342 "protocol filtering not compatible"
1343 " with ICMP layer");
1344 if (!(item_flags & l3m))
1345 return rte_flow_error_set(error, EINVAL,
1346 RTE_FLOW_ERROR_TYPE_ITEM, item,
1347 "IPv4 is mandatory to filter"
1349 if (item_flags & l4m)
1350 return rte_flow_error_set(error, EINVAL,
1351 RTE_FLOW_ERROR_TYPE_ITEM, item,
1352 "multiple L4 layers not supported");
1354 mask = &rte_flow_item_icmp_mask;
1355 ret = mlx5_flow_item_acceptable
1356 (item, (const uint8_t *)mask,
1357 (const uint8_t *)&rte_flow_item_icmp_mask,
1358 sizeof(struct rte_flow_item_icmp), error);
1365 * Validate Ethernet item.
1368 * Item specification.
1369 * @param[in] item_flags
1370 * Bit-fields that holds the items detected until now.
1372 * Pointer to error structure.
1375 * 0 on success, a negative errno value otherwise and rte_errno is set.
1378 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1379 uint64_t item_flags,
1380 struct rte_flow_error *error)
1382 const struct rte_flow_item_eth *mask = item->mask;
1383 const struct rte_flow_item_eth nic_mask = {
1384 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1385 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1386 .type = RTE_BE16(0xffff),
1389 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1390 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1391 MLX5_FLOW_LAYER_OUTER_L2;
1393 if (item_flags & ethm)
1394 return rte_flow_error_set(error, ENOTSUP,
1395 RTE_FLOW_ERROR_TYPE_ITEM, item,
1396 "multiple L2 layers not supported");
1397 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1398 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1399 return rte_flow_error_set(error, EINVAL,
1400 RTE_FLOW_ERROR_TYPE_ITEM, item,
1401 "L2 layer should not follow "
1403 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1404 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1405 return rte_flow_error_set(error, EINVAL,
1406 RTE_FLOW_ERROR_TYPE_ITEM, item,
1407 "L2 layer should not follow VLAN");
1409 mask = &rte_flow_item_eth_mask;
1410 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1411 (const uint8_t *)&nic_mask,
1412 sizeof(struct rte_flow_item_eth),
1418 * Validate VLAN item.
1421 * Item specification.
1422 * @param[in] item_flags
1423 * Bit-fields that holds the items detected until now.
1425 * Ethernet device flow is being created on.
1427 * Pointer to error structure.
1430 * 0 on success, a negative errno value otherwise and rte_errno is set.
1433 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1434 uint64_t item_flags,
1435 struct rte_eth_dev *dev,
1436 struct rte_flow_error *error)
1438 const struct rte_flow_item_vlan *spec = item->spec;
1439 const struct rte_flow_item_vlan *mask = item->mask;
1440 const struct rte_flow_item_vlan nic_mask = {
1441 .tci = RTE_BE16(UINT16_MAX),
1442 .inner_type = RTE_BE16(UINT16_MAX),
1444 uint16_t vlan_tag = 0;
1445 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1447 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1448 MLX5_FLOW_LAYER_INNER_L4) :
1449 (MLX5_FLOW_LAYER_OUTER_L3 |
1450 MLX5_FLOW_LAYER_OUTER_L4);
1451 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1452 MLX5_FLOW_LAYER_OUTER_VLAN;
1454 if (item_flags & vlanm)
1455 return rte_flow_error_set(error, EINVAL,
1456 RTE_FLOW_ERROR_TYPE_ITEM, item,
1457 "multiple VLAN layers not supported");
1458 else if ((item_flags & l34m) != 0)
1459 return rte_flow_error_set(error, EINVAL,
1460 RTE_FLOW_ERROR_TYPE_ITEM, item,
1461 "VLAN cannot follow L3/L4 layer");
1463 mask = &rte_flow_item_vlan_mask;
1464 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1465 (const uint8_t *)&nic_mask,
1466 sizeof(struct rte_flow_item_vlan),
1470 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1471 struct mlx5_priv *priv = dev->data->dev_private;
1473 if (priv->vmwa_context) {
1475 * Non-NULL context means we have a virtual machine
1476 * and SR-IOV enabled, we have to create VLAN interface
1477 * to make hypervisor to setup E-Switch vport
1478 * context correctly. We avoid creating the multiple
1479 * VLAN interfaces, so we cannot support VLAN tag mask.
1481 return rte_flow_error_set(error, EINVAL,
1482 RTE_FLOW_ERROR_TYPE_ITEM,
1484 "VLAN tag mask is not"
1485 " supported in virtual"
1490 vlan_tag = spec->tci;
1491 vlan_tag &= mask->tci;
1494 * From verbs perspective an empty VLAN is equivalent
1495 * to a packet without VLAN layer.
1498 return rte_flow_error_set(error, EINVAL,
1499 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1501 "VLAN cannot be empty");
1506 * Validate IPV4 item.
1509 * Item specification.
1510 * @param[in] item_flags
1511 * Bit-fields that holds the items detected until now.
1512 * @param[in] acc_mask
1513 * Acceptable mask, if NULL default internal default mask
1514 * will be used to check whether item fields are supported.
1516 * Pointer to error structure.
1519 * 0 on success, a negative errno value otherwise and rte_errno is set.
1522 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1523 uint64_t item_flags,
1525 uint16_t ether_type,
1526 const struct rte_flow_item_ipv4 *acc_mask,
1527 struct rte_flow_error *error)
1529 const struct rte_flow_item_ipv4 *mask = item->mask;
1530 const struct rte_flow_item_ipv4 *spec = item->spec;
1531 const struct rte_flow_item_ipv4 nic_mask = {
1533 .src_addr = RTE_BE32(0xffffffff),
1534 .dst_addr = RTE_BE32(0xffffffff),
1535 .type_of_service = 0xff,
1536 .next_proto_id = 0xff,
1539 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1540 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1541 MLX5_FLOW_LAYER_OUTER_L3;
1542 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1543 MLX5_FLOW_LAYER_OUTER_L4;
1545 uint8_t next_proto = 0xFF;
1546 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1547 MLX5_FLOW_LAYER_OUTER_VLAN |
1548 MLX5_FLOW_LAYER_INNER_VLAN);
1550 if ((last_item & l2_vlan) && ether_type &&
1551 ether_type != RTE_ETHER_TYPE_IPV4)
1552 return rte_flow_error_set(error, EINVAL,
1553 RTE_FLOW_ERROR_TYPE_ITEM, item,
1554 "IPv4 cannot follow L2/VLAN layer "
1555 "which ether type is not IPv4");
1556 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1558 next_proto = mask->hdr.next_proto_id &
1559 spec->hdr.next_proto_id;
1560 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1561 return rte_flow_error_set(error, EINVAL,
1562 RTE_FLOW_ERROR_TYPE_ITEM,
1567 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1568 return rte_flow_error_set(error, EINVAL,
1569 RTE_FLOW_ERROR_TYPE_ITEM, item,
1570 "wrong tunnel type - IPv6 specified "
1571 "but IPv4 item provided");
1572 if (item_flags & l3m)
1573 return rte_flow_error_set(error, ENOTSUP,
1574 RTE_FLOW_ERROR_TYPE_ITEM, item,
1575 "multiple L3 layers not supported");
1576 else if (item_flags & l4m)
1577 return rte_flow_error_set(error, EINVAL,
1578 RTE_FLOW_ERROR_TYPE_ITEM, item,
1579 "L3 cannot follow an L4 layer.");
1580 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1581 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1582 return rte_flow_error_set(error, EINVAL,
1583 RTE_FLOW_ERROR_TYPE_ITEM, item,
1584 "L3 cannot follow an NVGRE layer.");
1586 mask = &rte_flow_item_ipv4_mask;
1587 else if (mask->hdr.next_proto_id != 0 &&
1588 mask->hdr.next_proto_id != 0xff)
1589 return rte_flow_error_set(error, EINVAL,
1590 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1591 "partial mask is not supported"
1593 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1594 acc_mask ? (const uint8_t *)acc_mask
1595 : (const uint8_t *)&nic_mask,
1596 sizeof(struct rte_flow_item_ipv4),
1604 * Validate IPV6 item.
1607 * Item specification.
1608 * @param[in] item_flags
1609 * Bit-fields that holds the items detected until now.
1610 * @param[in] acc_mask
1611 * Acceptable mask, if NULL default internal default mask
1612 * will be used to check whether item fields are supported.
1614 * Pointer to error structure.
1617 * 0 on success, a negative errno value otherwise and rte_errno is set.
1620 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1621 uint64_t item_flags,
1623 uint16_t ether_type,
1624 const struct rte_flow_item_ipv6 *acc_mask,
1625 struct rte_flow_error *error)
1627 const struct rte_flow_item_ipv6 *mask = item->mask;
1628 const struct rte_flow_item_ipv6 *spec = item->spec;
1629 const struct rte_flow_item_ipv6 nic_mask = {
1632 "\xff\xff\xff\xff\xff\xff\xff\xff"
1633 "\xff\xff\xff\xff\xff\xff\xff\xff",
1635 "\xff\xff\xff\xff\xff\xff\xff\xff"
1636 "\xff\xff\xff\xff\xff\xff\xff\xff",
1637 .vtc_flow = RTE_BE32(0xffffffff),
1642 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1643 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1644 MLX5_FLOW_LAYER_OUTER_L3;
1645 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1646 MLX5_FLOW_LAYER_OUTER_L4;
1648 uint8_t next_proto = 0xFF;
1649 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1650 MLX5_FLOW_LAYER_OUTER_VLAN |
1651 MLX5_FLOW_LAYER_INNER_VLAN);
1653 if ((last_item & l2_vlan) && ether_type &&
1654 ether_type != RTE_ETHER_TYPE_IPV6)
1655 return rte_flow_error_set(error, EINVAL,
1656 RTE_FLOW_ERROR_TYPE_ITEM, item,
1657 "IPv6 cannot follow L2/VLAN layer "
1658 "which ether type is not IPv6");
1659 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
1661 next_proto = mask->hdr.proto & spec->hdr.proto;
1662 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1663 return rte_flow_error_set(error, EINVAL,
1664 RTE_FLOW_ERROR_TYPE_ITEM,
1669 if (item_flags & MLX5_FLOW_LAYER_IPIP)
1670 return rte_flow_error_set(error, EINVAL,
1671 RTE_FLOW_ERROR_TYPE_ITEM, item,
1672 "wrong tunnel type - IPv4 specified "
1673 "but IPv6 item provided");
1674 if (item_flags & l3m)
1675 return rte_flow_error_set(error, ENOTSUP,
1676 RTE_FLOW_ERROR_TYPE_ITEM, item,
1677 "multiple L3 layers not supported");
1678 else if (item_flags & l4m)
1679 return rte_flow_error_set(error, EINVAL,
1680 RTE_FLOW_ERROR_TYPE_ITEM, item,
1681 "L3 cannot follow an L4 layer.");
1682 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1683 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1684 return rte_flow_error_set(error, EINVAL,
1685 RTE_FLOW_ERROR_TYPE_ITEM, item,
1686 "L3 cannot follow an NVGRE layer.");
1688 mask = &rte_flow_item_ipv6_mask;
1689 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1690 acc_mask ? (const uint8_t *)acc_mask
1691 : (const uint8_t *)&nic_mask,
1692 sizeof(struct rte_flow_item_ipv6),
1700 * Validate UDP item.
1703 * Item specification.
1704 * @param[in] item_flags
1705 * Bit-fields that holds the items detected until now.
1706 * @param[in] target_protocol
1707 * The next protocol in the previous item.
1708 * @param[in] flow_mask
1709 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
1711 * Pointer to error structure.
1714 * 0 on success, a negative errno value otherwise and rte_errno is set.
1717 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1718 uint64_t item_flags,
1719 uint8_t target_protocol,
1720 struct rte_flow_error *error)
1722 const struct rte_flow_item_udp *mask = item->mask;
1723 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1724 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1725 MLX5_FLOW_LAYER_OUTER_L3;
1726 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1727 MLX5_FLOW_LAYER_OUTER_L4;
1730 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1731 return rte_flow_error_set(error, EINVAL,
1732 RTE_FLOW_ERROR_TYPE_ITEM, item,
1733 "protocol filtering not compatible"
1735 if (!(item_flags & l3m))
1736 return rte_flow_error_set(error, EINVAL,
1737 RTE_FLOW_ERROR_TYPE_ITEM, item,
1738 "L3 is mandatory to filter on L4");
1739 if (item_flags & l4m)
1740 return rte_flow_error_set(error, EINVAL,
1741 RTE_FLOW_ERROR_TYPE_ITEM, item,
1742 "multiple L4 layers not supported");
1744 mask = &rte_flow_item_udp_mask;
1745 ret = mlx5_flow_item_acceptable
1746 (item, (const uint8_t *)mask,
1747 (const uint8_t *)&rte_flow_item_udp_mask,
1748 sizeof(struct rte_flow_item_udp), error);
1755 * Validate TCP item.
1758 * Item specification.
1759 * @param[in] item_flags
1760 * Bit-fields that holds the items detected until now.
1761 * @param[in] target_protocol
1762 * The next protocol in the previous item.
1764 * Pointer to error structure.
1767 * 0 on success, a negative errno value otherwise and rte_errno is set.
1770 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1771 uint64_t item_flags,
1772 uint8_t target_protocol,
1773 const struct rte_flow_item_tcp *flow_mask,
1774 struct rte_flow_error *error)
1776 const struct rte_flow_item_tcp *mask = item->mask;
1777 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1778 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1779 MLX5_FLOW_LAYER_OUTER_L3;
1780 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1781 MLX5_FLOW_LAYER_OUTER_L4;
1785 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1786 return rte_flow_error_set(error, EINVAL,
1787 RTE_FLOW_ERROR_TYPE_ITEM, item,
1788 "protocol filtering not compatible"
1790 if (!(item_flags & l3m))
1791 return rte_flow_error_set(error, EINVAL,
1792 RTE_FLOW_ERROR_TYPE_ITEM, item,
1793 "L3 is mandatory to filter on L4");
1794 if (item_flags & l4m)
1795 return rte_flow_error_set(error, EINVAL,
1796 RTE_FLOW_ERROR_TYPE_ITEM, item,
1797 "multiple L4 layers not supported");
1799 mask = &rte_flow_item_tcp_mask;
1800 ret = mlx5_flow_item_acceptable
1801 (item, (const uint8_t *)mask,
1802 (const uint8_t *)flow_mask,
1803 sizeof(struct rte_flow_item_tcp), error);
1810 * Validate VXLAN item.
1813 * Item specification.
1814 * @param[in] item_flags
1815 * Bit-fields that holds the items detected until now.
1816 * @param[in] target_protocol
1817 * The next protocol in the previous item.
1819 * Pointer to error structure.
1822 * 0 on success, a negative errno value otherwise and rte_errno is set.
1825 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1826 uint64_t item_flags,
1827 struct rte_flow_error *error)
1829 const struct rte_flow_item_vxlan *spec = item->spec;
1830 const struct rte_flow_item_vxlan *mask = item->mask;
1835 } id = { .vlan_id = 0, };
1836 uint32_t vlan_id = 0;
1839 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1840 return rte_flow_error_set(error, ENOTSUP,
1841 RTE_FLOW_ERROR_TYPE_ITEM, item,
1842 "multiple tunnel layers not"
1845 * Verify only UDPv4 is present as defined in
1846 * https://tools.ietf.org/html/rfc7348
1848 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1849 return rte_flow_error_set(error, EINVAL,
1850 RTE_FLOW_ERROR_TYPE_ITEM, item,
1851 "no outer UDP layer found");
1853 mask = &rte_flow_item_vxlan_mask;
1854 ret = mlx5_flow_item_acceptable
1855 (item, (const uint8_t *)mask,
1856 (const uint8_t *)&rte_flow_item_vxlan_mask,
1857 sizeof(struct rte_flow_item_vxlan),
1862 memcpy(&id.vni[1], spec->vni, 3);
1863 vlan_id = id.vlan_id;
1864 memcpy(&id.vni[1], mask->vni, 3);
1865 vlan_id &= id.vlan_id;
1868 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1869 * only this layer is defined in the Verbs specification it is
1870 * interpreted as wildcard and all packets will match this
1871 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1872 * udp), all packets matching the layers before will also
1873 * match this rule. To avoid such situation, VNI 0 is
1874 * currently refused.
1877 return rte_flow_error_set(error, ENOTSUP,
1878 RTE_FLOW_ERROR_TYPE_ITEM, item,
1879 "VXLAN vni cannot be 0");
1880 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1881 return rte_flow_error_set(error, ENOTSUP,
1882 RTE_FLOW_ERROR_TYPE_ITEM, item,
1883 "VXLAN tunnel must be fully defined");
1888 * Validate VXLAN_GPE item.
1891 * Item specification.
1892 * @param[in] item_flags
1893 * Bit-fields that holds the items detected until now.
1895 * Pointer to the private data structure.
1896 * @param[in] target_protocol
1897 * The next protocol in the previous item.
1899 * Pointer to error structure.
1902 * 0 on success, a negative errno value otherwise and rte_errno is set.
1905 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1906 uint64_t item_flags,
1907 struct rte_eth_dev *dev,
1908 struct rte_flow_error *error)
1910 struct mlx5_priv *priv = dev->data->dev_private;
1911 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1912 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1917 } id = { .vlan_id = 0, };
1918 uint32_t vlan_id = 0;
1920 if (!priv->config.l3_vxlan_en)
1921 return rte_flow_error_set(error, ENOTSUP,
1922 RTE_FLOW_ERROR_TYPE_ITEM, item,
1923 "L3 VXLAN is not enabled by device"
1924 " parameter and/or not configured in"
1926 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1927 return rte_flow_error_set(error, ENOTSUP,
1928 RTE_FLOW_ERROR_TYPE_ITEM, item,
1929 "multiple tunnel layers not"
1932 * Verify only UDPv4 is present as defined in
1933 * https://tools.ietf.org/html/rfc7348
1935 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1936 return rte_flow_error_set(error, EINVAL,
1937 RTE_FLOW_ERROR_TYPE_ITEM, item,
1938 "no outer UDP layer found");
1940 mask = &rte_flow_item_vxlan_gpe_mask;
1941 ret = mlx5_flow_item_acceptable
1942 (item, (const uint8_t *)mask,
1943 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1944 sizeof(struct rte_flow_item_vxlan_gpe),
1950 return rte_flow_error_set(error, ENOTSUP,
1951 RTE_FLOW_ERROR_TYPE_ITEM,
1953 "VxLAN-GPE protocol"
1955 memcpy(&id.vni[1], spec->vni, 3);
1956 vlan_id = id.vlan_id;
1957 memcpy(&id.vni[1], mask->vni, 3);
1958 vlan_id &= id.vlan_id;
1961 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1962 * layer is defined in the Verbs specification it is interpreted as
1963 * wildcard and all packets will match this rule, if it follows a full
1964 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1965 * before will also match this rule. To avoid such situation, VNI 0
1966 * is currently refused.
1969 return rte_flow_error_set(error, ENOTSUP,
1970 RTE_FLOW_ERROR_TYPE_ITEM, item,
1971 "VXLAN-GPE vni cannot be 0");
1972 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1973 return rte_flow_error_set(error, ENOTSUP,
1974 RTE_FLOW_ERROR_TYPE_ITEM, item,
1975 "VXLAN-GPE tunnel must be fully"
1980 * Validate GRE Key item.
1983 * Item specification.
1984 * @param[in] item_flags
1985 * Bit flags to mark detected items.
1986 * @param[in] gre_item
1987 * Pointer to gre_item
1989 * Pointer to error structure.
1992 * 0 on success, a negative errno value otherwise and rte_errno is set.
1995 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
1996 uint64_t item_flags,
1997 const struct rte_flow_item *gre_item,
1998 struct rte_flow_error *error)
2000 const rte_be32_t *mask = item->mask;
2002 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2003 const struct rte_flow_item_gre *gre_spec;
2004 const struct rte_flow_item_gre *gre_mask;
2006 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2007 return rte_flow_error_set(error, ENOTSUP,
2008 RTE_FLOW_ERROR_TYPE_ITEM, item,
2009 "Multiple GRE key not support");
2010 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2011 return rte_flow_error_set(error, ENOTSUP,
2012 RTE_FLOW_ERROR_TYPE_ITEM, item,
2013 "No preceding GRE header");
2014 if (item_flags & MLX5_FLOW_LAYER_INNER)
2015 return rte_flow_error_set(error, ENOTSUP,
2016 RTE_FLOW_ERROR_TYPE_ITEM, item,
2017 "GRE key following a wrong item");
2018 gre_mask = gre_item->mask;
2020 gre_mask = &rte_flow_item_gre_mask;
2021 gre_spec = gre_item->spec;
2022 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2023 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2024 return rte_flow_error_set(error, EINVAL,
2025 RTE_FLOW_ERROR_TYPE_ITEM, item,
2026 "Key bit must be on");
2029 mask = &gre_key_default_mask;
2030 ret = mlx5_flow_item_acceptable
2031 (item, (const uint8_t *)mask,
2032 (const uint8_t *)&gre_key_default_mask,
2033 sizeof(rte_be32_t), error);
2038 * Validate GRE item.
2041 * Item specification.
2042 * @param[in] item_flags
2043 * Bit flags to mark detected items.
2044 * @param[in] target_protocol
2045 * The next protocol in the previous item.
2047 * Pointer to error structure.
2050 * 0 on success, a negative errno value otherwise and rte_errno is set.
2053 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2054 uint64_t item_flags,
2055 uint8_t target_protocol,
2056 struct rte_flow_error *error)
2058 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2059 const struct rte_flow_item_gre *mask = item->mask;
2061 const struct rte_flow_item_gre nic_mask = {
2062 .c_rsvd0_ver = RTE_BE16(0xB000),
2063 .protocol = RTE_BE16(UINT16_MAX),
2066 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2067 return rte_flow_error_set(error, EINVAL,
2068 RTE_FLOW_ERROR_TYPE_ITEM, item,
2069 "protocol filtering not compatible"
2070 " with this GRE layer");
2071 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2072 return rte_flow_error_set(error, ENOTSUP,
2073 RTE_FLOW_ERROR_TYPE_ITEM, item,
2074 "multiple tunnel layers not"
2076 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2077 return rte_flow_error_set(error, ENOTSUP,
2078 RTE_FLOW_ERROR_TYPE_ITEM, item,
2079 "L3 Layer is missing");
2081 mask = &rte_flow_item_gre_mask;
2082 ret = mlx5_flow_item_acceptable
2083 (item, (const uint8_t *)mask,
2084 (const uint8_t *)&nic_mask,
2085 sizeof(struct rte_flow_item_gre), error);
2088 #ifndef HAVE_MLX5DV_DR
2089 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2090 if (spec && (spec->protocol & mask->protocol))
2091 return rte_flow_error_set(error, ENOTSUP,
2092 RTE_FLOW_ERROR_TYPE_ITEM, item,
2093 "without MPLS support the"
2094 " specification cannot be used for"
2102 * Validate Geneve item.
2105 * Item specification.
2106 * @param[in] itemFlags
2107 * Bit-fields that holds the items detected until now.
2109 * Pointer to the private data structure.
2111 * Pointer to error structure.
2114 * 0 on success, a negative errno value otherwise and rte_errno is set.
2118 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2119 uint64_t item_flags,
2120 struct rte_eth_dev *dev,
2121 struct rte_flow_error *error)
2123 struct mlx5_priv *priv = dev->data->dev_private;
2124 const struct rte_flow_item_geneve *spec = item->spec;
2125 const struct rte_flow_item_geneve *mask = item->mask;
2128 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2129 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2130 const struct rte_flow_item_geneve nic_mask = {
2131 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2132 .vni = "\xff\xff\xff",
2133 .protocol = RTE_BE16(UINT16_MAX),
2136 if (!(priv->config.hca_attr.flex_parser_protocols &
2137 MLX5_HCA_FLEX_GENEVE_ENABLED) ||
2138 !priv->config.hca_attr.tunnel_stateless_geneve_rx)
2139 return rte_flow_error_set(error, ENOTSUP,
2140 RTE_FLOW_ERROR_TYPE_ITEM, item,
2141 "L3 Geneve is not enabled by device"
2142 " parameter and/or not configured in"
2144 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2145 return rte_flow_error_set(error, ENOTSUP,
2146 RTE_FLOW_ERROR_TYPE_ITEM, item,
2147 "multiple tunnel layers not"
2150 * Verify only UDPv4 is present as defined in
2151 * https://tools.ietf.org/html/rfc7348
2153 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2154 return rte_flow_error_set(error, EINVAL,
2155 RTE_FLOW_ERROR_TYPE_ITEM, item,
2156 "no outer UDP layer found");
2158 mask = &rte_flow_item_geneve_mask;
2159 ret = mlx5_flow_item_acceptable
2160 (item, (const uint8_t *)mask,
2161 (const uint8_t *)&nic_mask,
2162 sizeof(struct rte_flow_item_geneve), error);
2166 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2167 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2168 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2169 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2170 return rte_flow_error_set(error, ENOTSUP,
2171 RTE_FLOW_ERROR_TYPE_ITEM,
2173 "Geneve protocol unsupported"
2174 " fields are being used");
2175 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2176 return rte_flow_error_set
2178 RTE_FLOW_ERROR_TYPE_ITEM,
2180 "Unsupported Geneve options length");
2182 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2183 return rte_flow_error_set
2185 RTE_FLOW_ERROR_TYPE_ITEM, item,
2186 "Geneve tunnel must be fully defined");
2191 * Validate MPLS item.
2194 * Pointer to the rte_eth_dev structure.
2196 * Item specification.
2197 * @param[in] item_flags
2198 * Bit-fields that holds the items detected until now.
2199 * @param[in] prev_layer
2200 * The protocol layer indicated in previous item.
2202 * Pointer to error structure.
2205 * 0 on success, a negative errno value otherwise and rte_errno is set.
2208 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2209 const struct rte_flow_item *item __rte_unused,
2210 uint64_t item_flags __rte_unused,
2211 uint64_t prev_layer __rte_unused,
2212 struct rte_flow_error *error)
2214 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2215 const struct rte_flow_item_mpls *mask = item->mask;
2216 struct mlx5_priv *priv = dev->data->dev_private;
2219 if (!priv->config.mpls_en)
2220 return rte_flow_error_set(error, ENOTSUP,
2221 RTE_FLOW_ERROR_TYPE_ITEM, item,
2222 "MPLS not supported or"
2223 " disabled in firmware"
2225 /* MPLS over IP, UDP, GRE is allowed */
2226 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2227 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2228 MLX5_FLOW_LAYER_GRE)))
2229 return rte_flow_error_set(error, EINVAL,
2230 RTE_FLOW_ERROR_TYPE_ITEM, item,
2231 "protocol filtering not compatible"
2232 " with MPLS layer");
2233 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2234 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2235 !(item_flags & MLX5_FLOW_LAYER_GRE))
2236 return rte_flow_error_set(error, ENOTSUP,
2237 RTE_FLOW_ERROR_TYPE_ITEM, item,
2238 "multiple tunnel layers not"
2241 mask = &rte_flow_item_mpls_mask;
2242 ret = mlx5_flow_item_acceptable
2243 (item, (const uint8_t *)mask,
2244 (const uint8_t *)&rte_flow_item_mpls_mask,
2245 sizeof(struct rte_flow_item_mpls), error);
2250 return rte_flow_error_set(error, ENOTSUP,
2251 RTE_FLOW_ERROR_TYPE_ITEM, item,
2252 "MPLS is not supported by Verbs, please"
2257 * Validate NVGRE item.
2260 * Item specification.
2261 * @param[in] item_flags
2262 * Bit flags to mark detected items.
2263 * @param[in] target_protocol
2264 * The next protocol in the previous item.
2266 * Pointer to error structure.
2269 * 0 on success, a negative errno value otherwise and rte_errno is set.
2272 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2273 uint64_t item_flags,
2274 uint8_t target_protocol,
2275 struct rte_flow_error *error)
2277 const struct rte_flow_item_nvgre *mask = item->mask;
2280 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2281 return rte_flow_error_set(error, EINVAL,
2282 RTE_FLOW_ERROR_TYPE_ITEM, item,
2283 "protocol filtering not compatible"
2284 " with this GRE layer");
2285 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2286 return rte_flow_error_set(error, ENOTSUP,
2287 RTE_FLOW_ERROR_TYPE_ITEM, item,
2288 "multiple tunnel layers not"
2290 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2291 return rte_flow_error_set(error, ENOTSUP,
2292 RTE_FLOW_ERROR_TYPE_ITEM, item,
2293 "L3 Layer is missing");
2295 mask = &rte_flow_item_nvgre_mask;
2296 ret = mlx5_flow_item_acceptable
2297 (item, (const uint8_t *)mask,
2298 (const uint8_t *)&rte_flow_item_nvgre_mask,
2299 sizeof(struct rte_flow_item_nvgre), error);
2305 /* Allocate unique ID for the split Q/RSS subflows. */
2307 flow_qrss_get_id(struct rte_eth_dev *dev)
2309 struct mlx5_priv *priv = dev->data->dev_private;
2310 uint32_t qrss_id, ret;
2312 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2319 /* Free unique ID for the split Q/RSS subflows. */
2321 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2323 struct mlx5_priv *priv = dev->data->dev_private;
2326 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2330 * Release resource related QUEUE/RSS action split.
2333 * Pointer to Ethernet device.
2335 * Flow to release id's from.
2338 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2339 struct rte_flow *flow)
2341 struct mlx5_flow *dev_flow;
2343 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
2344 if (dev_flow->qrss_id)
2345 flow_qrss_free_id(dev, dev_flow->qrss_id);
2349 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2350 const struct rte_flow_attr *attr __rte_unused,
2351 const struct rte_flow_item items[] __rte_unused,
2352 const struct rte_flow_action actions[] __rte_unused,
2353 bool external __rte_unused,
2354 struct rte_flow_error *error)
2356 return rte_flow_error_set(error, ENOTSUP,
2357 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2360 static struct mlx5_flow *
2361 flow_null_prepare(const struct rte_flow_attr *attr __rte_unused,
2362 const struct rte_flow_item items[] __rte_unused,
2363 const struct rte_flow_action actions[] __rte_unused,
2364 struct rte_flow_error *error)
2366 rte_flow_error_set(error, ENOTSUP,
2367 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2372 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2373 struct mlx5_flow *dev_flow __rte_unused,
2374 const struct rte_flow_attr *attr __rte_unused,
2375 const struct rte_flow_item items[] __rte_unused,
2376 const struct rte_flow_action actions[] __rte_unused,
2377 struct rte_flow_error *error)
2379 return rte_flow_error_set(error, ENOTSUP,
2380 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2384 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2385 struct rte_flow *flow __rte_unused,
2386 struct rte_flow_error *error)
2388 return rte_flow_error_set(error, ENOTSUP,
2389 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2393 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2394 struct rte_flow *flow __rte_unused)
2399 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2400 struct rte_flow *flow __rte_unused)
2405 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2406 struct rte_flow *flow __rte_unused,
2407 const struct rte_flow_action *actions __rte_unused,
2408 void *data __rte_unused,
2409 struct rte_flow_error *error)
2411 return rte_flow_error_set(error, ENOTSUP,
2412 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2415 /* Void driver to protect from null pointer reference. */
2416 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2417 .validate = flow_null_validate,
2418 .prepare = flow_null_prepare,
2419 .translate = flow_null_translate,
2420 .apply = flow_null_apply,
2421 .remove = flow_null_remove,
2422 .destroy = flow_null_destroy,
2423 .query = flow_null_query,
2427 * Select flow driver type according to flow attributes and device
2431 * Pointer to the dev structure.
2433 * Pointer to the flow attributes.
2436 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2438 static enum mlx5_flow_drv_type
2439 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2441 struct mlx5_priv *priv = dev->data->dev_private;
2442 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
2444 if (attr->transfer && priv->config.dv_esw_en)
2445 type = MLX5_FLOW_TYPE_DV;
2446 if (!attr->transfer)
2447 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2448 MLX5_FLOW_TYPE_VERBS;
2452 #define flow_get_drv_ops(type) flow_drv_ops[type]
2455 * Flow driver validation API. This abstracts calling driver specific functions.
2456 * The type of flow driver is determined according to flow attributes.
2459 * Pointer to the dev structure.
2461 * Pointer to the flow attributes.
2463 * Pointer to the list of items.
2464 * @param[in] actions
2465 * Pointer to the list of actions.
2466 * @param[in] external
2467 * This flow rule is created by request external to PMD.
2469 * Pointer to the error structure.
2472 * 0 on success, a negative errno value otherwise and rte_errno is set.
2475 flow_drv_validate(struct rte_eth_dev *dev,
2476 const struct rte_flow_attr *attr,
2477 const struct rte_flow_item items[],
2478 const struct rte_flow_action actions[],
2479 bool external, struct rte_flow_error *error)
2481 const struct mlx5_flow_driver_ops *fops;
2482 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2484 fops = flow_get_drv_ops(type);
2485 return fops->validate(dev, attr, items, actions, external, error);
2489 * Flow driver preparation API. This abstracts calling driver specific
2490 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2491 * calculates the size of memory required for device flow, allocates the memory,
2492 * initializes the device flow and returns the pointer.
2495 * This function initializes device flow structure such as dv or verbs in
2496 * struct mlx5_flow. However, it is caller's responsibility to initialize the
2497 * rest. For example, adding returning device flow to flow->dev_flow list and
2498 * setting backward reference to the flow should be done out of this function.
2499 * layers field is not filled either.
2502 * Pointer to the flow attributes.
2504 * Pointer to the list of items.
2505 * @param[in] actions
2506 * Pointer to the list of actions.
2508 * Pointer to the error structure.
2511 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
2513 static inline struct mlx5_flow *
2514 flow_drv_prepare(const struct rte_flow *flow,
2515 const struct rte_flow_attr *attr,
2516 const struct rte_flow_item items[],
2517 const struct rte_flow_action actions[],
2518 struct rte_flow_error *error)
2520 const struct mlx5_flow_driver_ops *fops;
2521 enum mlx5_flow_drv_type type = flow->drv_type;
2523 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2524 fops = flow_get_drv_ops(type);
2525 return fops->prepare(attr, items, actions, error);
2529 * Flow driver translation API. This abstracts calling driver specific
2530 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2531 * translates a generic flow into a driver flow. flow_drv_prepare() must
2535 * dev_flow->layers could be filled as a result of parsing during translation
2536 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
2537 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
2538 * flow->actions could be overwritten even though all the expanded dev_flows
2539 * have the same actions.
2542 * Pointer to the rte dev structure.
2543 * @param[in, out] dev_flow
2544 * Pointer to the mlx5 flow.
2546 * Pointer to the flow attributes.
2548 * Pointer to the list of items.
2549 * @param[in] actions
2550 * Pointer to the list of actions.
2552 * Pointer to the error structure.
2555 * 0 on success, a negative errno value otherwise and rte_errno is set.
2558 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
2559 const struct rte_flow_attr *attr,
2560 const struct rte_flow_item items[],
2561 const struct rte_flow_action actions[],
2562 struct rte_flow_error *error)
2564 const struct mlx5_flow_driver_ops *fops;
2565 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
2567 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2568 fops = flow_get_drv_ops(type);
2569 return fops->translate(dev, dev_flow, attr, items, actions, error);
2573 * Flow driver apply API. This abstracts calling driver specific functions.
2574 * Parent flow (rte_flow) should have driver type (drv_type). It applies
2575 * translated driver flows on to device. flow_drv_translate() must precede.
2578 * Pointer to Ethernet device structure.
2579 * @param[in, out] flow
2580 * Pointer to flow structure.
2582 * Pointer to error structure.
2585 * 0 on success, a negative errno value otherwise and rte_errno is set.
2588 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
2589 struct rte_flow_error *error)
2591 const struct mlx5_flow_driver_ops *fops;
2592 enum mlx5_flow_drv_type type = flow->drv_type;
2594 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2595 fops = flow_get_drv_ops(type);
2596 return fops->apply(dev, flow, error);
2600 * Flow driver remove API. This abstracts calling driver specific functions.
2601 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2602 * on device. All the resources of the flow should be freed by calling
2603 * flow_drv_destroy().
2606 * Pointer to Ethernet device.
2607 * @param[in, out] flow
2608 * Pointer to flow structure.
2611 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
2613 const struct mlx5_flow_driver_ops *fops;
2614 enum mlx5_flow_drv_type type = flow->drv_type;
2616 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2617 fops = flow_get_drv_ops(type);
2618 fops->remove(dev, flow);
2622 * Flow driver destroy API. This abstracts calling driver specific functions.
2623 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2624 * on device and releases resources of the flow.
2627 * Pointer to Ethernet device.
2628 * @param[in, out] flow
2629 * Pointer to flow structure.
2632 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
2634 const struct mlx5_flow_driver_ops *fops;
2635 enum mlx5_flow_drv_type type = flow->drv_type;
2637 flow_mreg_split_qrss_release(dev, flow);
2638 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2639 fops = flow_get_drv_ops(type);
2640 fops->destroy(dev, flow);
2644 * Validate a flow supported by the NIC.
2646 * @see rte_flow_validate()
2650 mlx5_flow_validate(struct rte_eth_dev *dev,
2651 const struct rte_flow_attr *attr,
2652 const struct rte_flow_item items[],
2653 const struct rte_flow_action actions[],
2654 struct rte_flow_error *error)
2658 ret = flow_drv_validate(dev, attr, items, actions, true, error);
2665 * Get port id item from the item list.
2668 * Pointer to the list of items.
2671 * Pointer to the port id item if exist, else return NULL.
2673 static const struct rte_flow_item *
2674 find_port_id_item(const struct rte_flow_item *item)
2677 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2678 if (item->type == RTE_FLOW_ITEM_TYPE_PORT_ID)
2685 * Get RSS action from the action list.
2687 * @param[in] actions
2688 * Pointer to the list of actions.
2691 * Pointer to the RSS action if exist, else return NULL.
2693 static const struct rte_flow_action_rss*
2694 flow_get_rss_action(const struct rte_flow_action actions[])
2696 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2697 switch (actions->type) {
2698 case RTE_FLOW_ACTION_TYPE_RSS:
2699 return (const struct rte_flow_action_rss *)
2709 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
2711 const struct rte_flow_item *item;
2712 unsigned int has_vlan = 0;
2714 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2715 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2721 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
2722 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
2723 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
2724 MLX5_EXPANSION_ROOT_OUTER;
2728 * Get QUEUE/RSS action from the action list.
2730 * @param[in] actions
2731 * Pointer to the list of actions.
2733 * Pointer to the return pointer.
2734 * @param[out] qrss_type
2735 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
2736 * if no QUEUE/RSS is found.
2739 * Total number of actions.
2742 flow_parse_qrss_action(const struct rte_flow_action actions[],
2743 const struct rte_flow_action **qrss)
2747 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2748 switch (actions->type) {
2749 case RTE_FLOW_ACTION_TYPE_QUEUE:
2750 case RTE_FLOW_ACTION_TYPE_RSS:
2758 /* Count RTE_FLOW_ACTION_TYPE_END. */
2759 return actions_n + 1;
2763 * Check meter action from the action list.
2765 * @param[in] actions
2766 * Pointer to the list of actions.
2768 * Pointer to the meter exist flag.
2771 * Total number of actions.
2774 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
2780 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2781 switch (actions->type) {
2782 case RTE_FLOW_ACTION_TYPE_METER:
2790 /* Count RTE_FLOW_ACTION_TYPE_END. */
2791 return actions_n + 1;
2795 * Check if the flow should be splited due to hairpin.
2796 * The reason for the split is that in current HW we can't
2797 * support encap on Rx, so if a flow have encap we move it
2801 * Pointer to Ethernet device.
2803 * Flow rule attributes.
2804 * @param[in] actions
2805 * Associated actions (list terminated by the END action).
2808 * > 0 the number of actions and the flow should be split,
2809 * 0 when no split required.
2812 flow_check_hairpin_split(struct rte_eth_dev *dev,
2813 const struct rte_flow_attr *attr,
2814 const struct rte_flow_action actions[])
2816 int queue_action = 0;
2819 const struct rte_flow_action_queue *queue;
2820 const struct rte_flow_action_rss *rss;
2821 const struct rte_flow_action_raw_encap *raw_encap;
2825 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2826 switch (actions->type) {
2827 case RTE_FLOW_ACTION_TYPE_QUEUE:
2828 queue = actions->conf;
2831 if (mlx5_rxq_get_type(dev, queue->index) !=
2832 MLX5_RXQ_TYPE_HAIRPIN)
2837 case RTE_FLOW_ACTION_TYPE_RSS:
2838 rss = actions->conf;
2839 if (rss == NULL || rss->queue_num == 0)
2841 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
2842 MLX5_RXQ_TYPE_HAIRPIN)
2847 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2848 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2852 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2853 raw_encap = actions->conf;
2854 if (raw_encap->size >
2855 (sizeof(struct rte_flow_item_eth) +
2856 sizeof(struct rte_flow_item_ipv4)))
2865 if (encap == 1 && queue_action)
2870 /* Declare flow create/destroy prototype in advance. */
2871 static struct rte_flow *
2872 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
2873 const struct rte_flow_attr *attr,
2874 const struct rte_flow_item items[],
2875 const struct rte_flow_action actions[],
2876 bool external, struct rte_flow_error *error);
2879 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
2880 struct rte_flow *flow);
2883 * Add a flow of copying flow metadata registers in RX_CP_TBL.
2885 * As mark_id is unique, if there's already a registered flow for the mark_id,
2886 * return by increasing the reference counter of the resource. Otherwise, create
2887 * the resource (mcp_res) and flow.
2890 * - If ingress port is ANY and reg_c[1] is mark_id,
2891 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
2893 * For default flow (zero mark_id), flow is like,
2894 * - If ingress port is ANY,
2895 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
2898 * Pointer to Ethernet device.
2900 * ID of MARK action, zero means default flow for META.
2902 * Perform verbose error reporting if not NULL.
2905 * Associated resource on success, NULL otherwise and rte_errno is set.
2907 static struct mlx5_flow_mreg_copy_resource *
2908 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
2909 struct rte_flow_error *error)
2911 struct mlx5_priv *priv = dev->data->dev_private;
2912 struct rte_flow_attr attr = {
2913 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
2916 struct mlx5_rte_flow_item_tag tag_spec = {
2919 struct rte_flow_item items[] = {
2920 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
2922 struct rte_flow_action_mark ftag = {
2925 struct mlx5_flow_action_copy_mreg cp_mreg = {
2929 struct rte_flow_action_jump jump = {
2930 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
2932 struct rte_flow_action actions[] = {
2933 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
2935 struct mlx5_flow_mreg_copy_resource *mcp_res;
2938 /* Fill the register fileds in the flow. */
2939 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2943 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
2947 /* Check if already registered. */
2948 assert(priv->mreg_cp_tbl);
2949 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
2951 /* For non-default rule. */
2952 if (mark_id != MLX5_DEFAULT_COPY_ID)
2954 assert(mark_id != MLX5_DEFAULT_COPY_ID || mcp_res->refcnt == 1);
2957 /* Provide the full width of FLAG specific value. */
2958 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
2959 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
2960 /* Build a new flow. */
2961 if (mark_id != MLX5_DEFAULT_COPY_ID) {
2962 items[0] = (struct rte_flow_item){
2963 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
2966 items[1] = (struct rte_flow_item){
2967 .type = RTE_FLOW_ITEM_TYPE_END,
2969 actions[0] = (struct rte_flow_action){
2970 .type = MLX5_RTE_FLOW_ACTION_TYPE_MARK,
2973 actions[1] = (struct rte_flow_action){
2974 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
2977 actions[2] = (struct rte_flow_action){
2978 .type = RTE_FLOW_ACTION_TYPE_JUMP,
2981 actions[3] = (struct rte_flow_action){
2982 .type = RTE_FLOW_ACTION_TYPE_END,
2985 /* Default rule, wildcard match. */
2986 attr.priority = MLX5_FLOW_PRIO_RSVD;
2987 items[0] = (struct rte_flow_item){
2988 .type = RTE_FLOW_ITEM_TYPE_END,
2990 actions[0] = (struct rte_flow_action){
2991 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
2994 actions[1] = (struct rte_flow_action){
2995 .type = RTE_FLOW_ACTION_TYPE_JUMP,
2998 actions[2] = (struct rte_flow_action){
2999 .type = RTE_FLOW_ACTION_TYPE_END,
3002 /* Build a new entry. */
3003 mcp_res = rte_zmalloc(__func__, sizeof(*mcp_res), 0);
3009 * The copy Flows are not included in any list. There
3010 * ones are referenced from other Flows and can not
3011 * be applied, removed, deleted in ardbitrary order
3012 * by list traversing.
3014 mcp_res->flow = flow_list_create(dev, NULL, &attr, items,
3015 actions, false, error);
3019 mcp_res->hlist_ent.key = mark_id;
3020 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3021 &mcp_res->hlist_ent);
3028 flow_list_destroy(dev, NULL, mcp_res->flow);
3034 * Release flow in RX_CP_TBL.
3037 * Pointer to Ethernet device.
3039 * Parent flow for wich copying is provided.
3042 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3043 struct rte_flow *flow)
3045 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3046 struct mlx5_priv *priv = dev->data->dev_private;
3048 if (!mcp_res || !priv->mreg_cp_tbl)
3050 if (flow->copy_applied) {
3051 assert(mcp_res->appcnt);
3052 flow->copy_applied = 0;
3054 if (!mcp_res->appcnt)
3055 flow_drv_remove(dev, mcp_res->flow);
3058 * We do not check availability of metadata registers here,
3059 * because copy resources are not allocated in this case.
3061 if (--mcp_res->refcnt)
3063 assert(mcp_res->flow);
3064 flow_list_destroy(dev, NULL, mcp_res->flow);
3065 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3067 flow->mreg_copy = NULL;
3071 * Start flow in RX_CP_TBL.
3074 * Pointer to Ethernet device.
3076 * Parent flow for wich copying is provided.
3079 * 0 on success, a negative errno value otherwise and rte_errno is set.
3082 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3083 struct rte_flow *flow)
3085 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3088 if (!mcp_res || flow->copy_applied)
3090 if (!mcp_res->appcnt) {
3091 ret = flow_drv_apply(dev, mcp_res->flow, NULL);
3096 flow->copy_applied = 1;
3101 * Stop flow in RX_CP_TBL.
3104 * Pointer to Ethernet device.
3106 * Parent flow for wich copying is provided.
3109 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3110 struct rte_flow *flow)
3112 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3114 if (!mcp_res || !flow->copy_applied)
3116 assert(mcp_res->appcnt);
3118 flow->copy_applied = 0;
3119 if (!mcp_res->appcnt)
3120 flow_drv_remove(dev, mcp_res->flow);
3124 * Remove the default copy action from RX_CP_TBL.
3127 * Pointer to Ethernet device.
3130 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3132 struct mlx5_flow_mreg_copy_resource *mcp_res;
3133 struct mlx5_priv *priv = dev->data->dev_private;
3135 /* Check if default flow is registered. */
3136 if (!priv->mreg_cp_tbl)
3138 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3139 MLX5_DEFAULT_COPY_ID);
3142 assert(mcp_res->flow);
3143 flow_list_destroy(dev, NULL, mcp_res->flow);
3144 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3149 * Add the default copy action in in RX_CP_TBL.
3152 * Pointer to Ethernet device.
3154 * Perform verbose error reporting if not NULL.
3157 * 0 for success, negative value otherwise and rte_errno is set.
3160 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3161 struct rte_flow_error *error)
3163 struct mlx5_priv *priv = dev->data->dev_private;
3164 struct mlx5_flow_mreg_copy_resource *mcp_res;
3166 /* Check whether extensive metadata feature is engaged. */
3167 if (!priv->config.dv_flow_en ||
3168 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3169 !mlx5_flow_ext_mreg_supported(dev) ||
3170 !priv->sh->dv_regc0_mask)
3172 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3179 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3181 * All the flow having Q/RSS action should be split by
3182 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3183 * performs the following,
3184 * - CQE->flow_tag := reg_c[1] (MARK)
3185 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3186 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3187 * but there should be a flow per each MARK ID set by MARK action.
3189 * For the aforementioned reason, if there's a MARK action in flow's action
3190 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3191 * the MARK ID to CQE's flow_tag like,
3192 * - If reg_c[1] is mark_id,
3193 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3195 * For SET_META action which stores value in reg_c[0], as the destination is
3196 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3197 * MARK ID means the default flow. The default flow looks like,
3198 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3201 * Pointer to Ethernet device.
3203 * Pointer to flow structure.
3204 * @param[in] actions
3205 * Pointer to the list of actions.
3207 * Perform verbose error reporting if not NULL.
3210 * 0 on success, negative value otherwise and rte_errno is set.
3213 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3214 struct rte_flow *flow,
3215 const struct rte_flow_action *actions,
3216 struct rte_flow_error *error)
3218 struct mlx5_priv *priv = dev->data->dev_private;
3219 struct mlx5_dev_config *config = &priv->config;
3220 struct mlx5_flow_mreg_copy_resource *mcp_res;
3221 const struct rte_flow_action_mark *mark;
3223 /* Check whether extensive metadata feature is engaged. */
3224 if (!config->dv_flow_en ||
3225 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3226 !mlx5_flow_ext_mreg_supported(dev) ||
3227 !priv->sh->dv_regc0_mask)
3229 /* Find MARK action. */
3230 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3231 switch (actions->type) {
3232 case RTE_FLOW_ACTION_TYPE_FLAG:
3233 mcp_res = flow_mreg_add_copy_action
3234 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3237 flow->mreg_copy = mcp_res;
3238 if (dev->data->dev_started) {
3240 flow->copy_applied = 1;
3243 case RTE_FLOW_ACTION_TYPE_MARK:
3244 mark = (const struct rte_flow_action_mark *)
3247 flow_mreg_add_copy_action(dev, mark->id, error);
3250 flow->mreg_copy = mcp_res;
3251 if (dev->data->dev_started) {
3253 flow->copy_applied = 1;
3263 #define MLX5_MAX_SPLIT_ACTIONS 24
3264 #define MLX5_MAX_SPLIT_ITEMS 24
3267 * Split the hairpin flow.
3268 * Since HW can't support encap on Rx we move the encap to Tx.
3269 * If the count action is after the encap then we also
3270 * move the count action. in this case the count will also measure
3274 * Pointer to Ethernet device.
3275 * @param[in] actions
3276 * Associated actions (list terminated by the END action).
3277 * @param[out] actions_rx
3279 * @param[out] actions_tx
3281 * @param[out] pattern_tx
3282 * The pattern items for the Tx flow.
3283 * @param[out] flow_id
3284 * The flow ID connected to this flow.
3290 flow_hairpin_split(struct rte_eth_dev *dev,
3291 const struct rte_flow_action actions[],
3292 struct rte_flow_action actions_rx[],
3293 struct rte_flow_action actions_tx[],
3294 struct rte_flow_item pattern_tx[],
3297 struct mlx5_priv *priv = dev->data->dev_private;
3298 const struct rte_flow_action_raw_encap *raw_encap;
3299 const struct rte_flow_action_raw_decap *raw_decap;
3300 struct mlx5_rte_flow_action_set_tag *set_tag;
3301 struct rte_flow_action *tag_action;
3302 struct mlx5_rte_flow_item_tag *tag_item;
3303 struct rte_flow_item *item;
3307 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
3308 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3309 switch (actions->type) {
3310 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3311 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3312 rte_memcpy(actions_tx, actions,
3313 sizeof(struct rte_flow_action));
3316 case RTE_FLOW_ACTION_TYPE_COUNT:
3318 rte_memcpy(actions_tx, actions,
3319 sizeof(struct rte_flow_action));
3322 rte_memcpy(actions_rx, actions,
3323 sizeof(struct rte_flow_action));
3327 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3328 raw_encap = actions->conf;
3329 if (raw_encap->size >
3330 (sizeof(struct rte_flow_item_eth) +
3331 sizeof(struct rte_flow_item_ipv4))) {
3332 memcpy(actions_tx, actions,
3333 sizeof(struct rte_flow_action));
3337 rte_memcpy(actions_rx, actions,
3338 sizeof(struct rte_flow_action));
3342 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3343 raw_decap = actions->conf;
3344 if (raw_decap->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));
3351 rte_memcpy(actions_rx, actions,
3352 sizeof(struct rte_flow_action));
3357 rte_memcpy(actions_rx, actions,
3358 sizeof(struct rte_flow_action));
3363 /* Add set meta action and end action for the Rx flow. */
3364 tag_action = actions_rx;
3365 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3367 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
3369 set_tag = (void *)actions_rx;
3370 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
3371 assert(set_tag->id > REG_NONE);
3372 set_tag->data = *flow_id;
3373 tag_action->conf = set_tag;
3374 /* Create Tx item list. */
3375 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
3376 addr = (void *)&pattern_tx[2];
3378 item->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3379 tag_item = (void *)addr;
3380 tag_item->data = *flow_id;
3381 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
3382 assert(set_tag->id > REG_NONE);
3383 item->spec = tag_item;
3384 addr += sizeof(struct mlx5_rte_flow_item_tag);
3385 tag_item = (void *)addr;
3386 tag_item->data = UINT32_MAX;
3387 tag_item->id = UINT16_MAX;
3388 item->mask = tag_item;
3389 addr += sizeof(struct mlx5_rte_flow_item_tag);
3392 item->type = RTE_FLOW_ITEM_TYPE_END;
3397 * The last stage of splitting chain, just creates the subflow
3398 * without any modification.
3401 * Pointer to Ethernet device.
3403 * Parent flow structure pointer.
3404 * @param[in, out] sub_flow
3405 * Pointer to return the created subflow, may be NULL.
3407 * Flow rule attributes.
3409 * Pattern specification (list terminated by the END pattern item).
3410 * @param[in] actions
3411 * Associated actions (list terminated by the END action).
3412 * @param[in] external
3413 * This flow rule is created by request external to PMD.
3415 * Perform verbose error reporting if not NULL.
3417 * 0 on success, negative value otherwise
3420 flow_create_split_inner(struct rte_eth_dev *dev,
3421 struct rte_flow *flow,
3422 struct mlx5_flow **sub_flow,
3423 const struct rte_flow_attr *attr,
3424 const struct rte_flow_item items[],
3425 const struct rte_flow_action actions[],
3426 bool external, struct rte_flow_error *error)
3428 struct mlx5_flow *dev_flow;
3430 dev_flow = flow_drv_prepare(flow, attr, items, actions, error);
3433 dev_flow->flow = flow;
3434 dev_flow->external = external;
3435 /* Subflow object was created, we must include one in the list. */
3436 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
3438 *sub_flow = dev_flow;
3439 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
3443 * Split the meter flow.
3445 * As meter flow will split to three sub flow, other than meter
3446 * action, the other actions make sense to only meter accepts
3447 * the packet. If it need to be dropped, no other additional
3448 * actions should be take.
3450 * One kind of special action which decapsulates the L3 tunnel
3451 * header will be in the prefix sub flow, as not to take the
3452 * L3 tunnel header into account.
3455 * Pointer to Ethernet device.
3456 * @param[in] actions
3457 * Associated actions (list terminated by the END action).
3458 * @param[out] actions_sfx
3459 * Suffix flow actions.
3460 * @param[out] actions_pre
3461 * Prefix flow actions.
3462 * @param[out] pattern_sfx
3463 * The pattern items for the suffix flow.
3464 * @param[out] tag_sfx
3465 * Pointer to suffix flow tag.
3471 flow_meter_split_prep(struct rte_eth_dev *dev,
3472 const struct rte_flow_action actions[],
3473 struct rte_flow_action actions_sfx[],
3474 struct rte_flow_action actions_pre[])
3476 struct rte_flow_action *tag_action;
3477 struct mlx5_rte_flow_action_set_tag *set_tag;
3478 struct rte_flow_error error;
3479 const struct rte_flow_action_raw_encap *raw_encap;
3480 const struct rte_flow_action_raw_decap *raw_decap;
3483 /* Add the extra tag action first. */
3484 tag_action = actions_pre;
3485 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3487 /* Prepare the actions for prefix and suffix flow. */
3488 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3489 switch (actions->type) {
3490 case RTE_FLOW_ACTION_TYPE_METER:
3491 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3492 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3493 memcpy(actions_pre, actions,
3494 sizeof(struct rte_flow_action));
3497 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3498 raw_encap = actions->conf;
3499 if (raw_encap->size >
3500 (sizeof(struct rte_flow_item_eth) +
3501 sizeof(struct rte_flow_item_ipv4))) {
3502 memcpy(actions_sfx, actions,
3503 sizeof(struct rte_flow_action));
3506 rte_memcpy(actions_pre, actions,
3507 sizeof(struct rte_flow_action));
3511 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3512 raw_decap = actions->conf;
3513 /* Size 0 decap means 50 bytes as vxlan decap. */
3514 if (raw_decap->size && (raw_decap->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));
3527 memcpy(actions_sfx, actions,
3528 sizeof(struct rte_flow_action));
3533 /* Add end action to the actions. */
3534 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
3535 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
3538 set_tag = (void *)actions_pre;
3539 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3541 * Get the id from the qrss_pool to make qrss share the id with meter.
3543 tag_id = flow_qrss_get_id(dev);
3544 set_tag->data = tag_id << MLX5_MTR_COLOR_BITS;
3545 tag_action->conf = set_tag;
3550 * Split action list having QUEUE/RSS for metadata register copy.
3552 * Once Q/RSS action is detected in user's action list, the flow action
3553 * should be split in order to copy metadata registers, which will happen in
3555 * - CQE->flow_tag := reg_c[1] (MARK)
3556 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3557 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
3558 * This is because the last action of each flow must be a terminal action
3559 * (QUEUE, RSS or DROP).
3561 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
3562 * stored and kept in the mlx5_flow structure per each sub_flow.
3564 * The Q/RSS action is replaced with,
3565 * - SET_TAG, setting the allocated flow ID to reg_c[2].
3566 * And the following JUMP action is added at the end,
3567 * - JUMP, to RX_CP_TBL.
3569 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
3570 * flow_create_split_metadata() routine. The flow will look like,
3571 * - If flow ID matches (reg_c[2]), perform Q/RSS.
3574 * Pointer to Ethernet device.
3575 * @param[out] split_actions
3576 * Pointer to store split actions to jump to CP_TBL.
3577 * @param[in] actions
3578 * Pointer to the list of original flow actions.
3580 * Pointer to the Q/RSS action.
3581 * @param[in] actions_n
3582 * Number of original actions.
3584 * Perform verbose error reporting if not NULL.
3587 * non-zero unique flow_id on success, otherwise 0 and
3588 * error/rte_error are set.
3591 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
3592 struct rte_flow_action *split_actions,
3593 const struct rte_flow_action *actions,
3594 const struct rte_flow_action *qrss,
3595 int actions_n, struct rte_flow_error *error)
3597 struct mlx5_rte_flow_action_set_tag *set_tag;
3598 struct rte_flow_action_jump *jump;
3599 const int qrss_idx = qrss - actions;
3600 uint32_t flow_id = 0;
3604 * Given actions will be split
3605 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
3606 * - Add jump to mreg CP_TBL.
3607 * As a result, there will be one more action.
3610 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
3611 set_tag = (void *)(split_actions + actions_n);
3613 * If tag action is not set to void(it means we are not the meter
3614 * suffix flow), add the tag action. Since meter suffix flow already
3615 * has the tag added.
3617 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
3619 * Allocate the new subflow ID. This one is unique within
3620 * device and not shared with representors. Otherwise,
3621 * we would have to resolve multi-thread access synch
3622 * issue. Each flow on the shared device is appended
3623 * with source vport identifier, so the resulting
3624 * flows will be unique in the shared (by master and
3625 * representors) domain even if they have coinciding
3628 flow_id = flow_qrss_get_id(dev);
3630 return rte_flow_error_set(error, ENOMEM,
3631 RTE_FLOW_ERROR_TYPE_ACTION,
3632 NULL, "can't allocate id "
3633 "for split Q/RSS subflow");
3634 /* Internal SET_TAG action to set flow ID. */
3635 *set_tag = (struct mlx5_rte_flow_action_set_tag){
3638 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
3642 /* Construct new actions array. */
3643 /* Replace QUEUE/RSS action. */
3644 split_actions[qrss_idx] = (struct rte_flow_action){
3645 .type = MLX5_RTE_FLOW_ACTION_TYPE_TAG,
3649 /* JUMP action to jump to mreg copy table (CP_TBL). */
3650 jump = (void *)(set_tag + 1);
3651 *jump = (struct rte_flow_action_jump){
3652 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3654 split_actions[actions_n - 2] = (struct rte_flow_action){
3655 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3658 split_actions[actions_n - 1] = (struct rte_flow_action){
3659 .type = RTE_FLOW_ACTION_TYPE_END,
3665 * Extend the given action list for Tx metadata copy.
3667 * Copy the given action list to the ext_actions and add flow metadata register
3668 * copy action in order to copy reg_a set by WQE to reg_c[0].
3670 * @param[out] ext_actions
3671 * Pointer to the extended action list.
3672 * @param[in] actions
3673 * Pointer to the list of actions.
3674 * @param[in] actions_n
3675 * Number of actions in the list.
3677 * Perform verbose error reporting if not NULL.
3680 * 0 on success, negative value otherwise
3683 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
3684 struct rte_flow_action *ext_actions,
3685 const struct rte_flow_action *actions,
3686 int actions_n, struct rte_flow_error *error)
3688 struct mlx5_flow_action_copy_mreg *cp_mreg =
3689 (struct mlx5_flow_action_copy_mreg *)
3690 (ext_actions + actions_n + 1);
3693 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3697 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
3701 memcpy(ext_actions, actions,
3702 sizeof(*ext_actions) * actions_n);
3703 ext_actions[actions_n - 1] = (struct rte_flow_action){
3704 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3707 ext_actions[actions_n] = (struct rte_flow_action){
3708 .type = RTE_FLOW_ACTION_TYPE_END,
3714 * The splitting for metadata feature.
3716 * - Q/RSS action on NIC Rx should be split in order to pass by
3717 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3718 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3720 * - All the actions on NIC Tx should have a mreg copy action to
3721 * copy reg_a from WQE to reg_c[0].
3724 * Pointer to Ethernet device.
3726 * Parent flow structure pointer.
3728 * Flow rule attributes.
3730 * Pattern specification (list terminated by the END pattern item).
3731 * @param[in] actions
3732 * Associated actions (list terminated by the END action).
3733 * @param[in] external
3734 * This flow rule is created by request external to PMD.
3736 * Perform verbose error reporting if not NULL.
3738 * 0 on success, negative value otherwise
3741 flow_create_split_metadata(struct rte_eth_dev *dev,
3742 struct rte_flow *flow,
3743 const struct rte_flow_attr *attr,
3744 const struct rte_flow_item items[],
3745 const struct rte_flow_action actions[],
3746 bool external, struct rte_flow_error *error)
3748 struct mlx5_priv *priv = dev->data->dev_private;
3749 struct mlx5_dev_config *config = &priv->config;
3750 const struct rte_flow_action *qrss = NULL;
3751 struct rte_flow_action *ext_actions = NULL;
3752 struct mlx5_flow *dev_flow = NULL;
3753 uint32_t qrss_id = 0;
3759 /* Check whether extensive metadata feature is engaged. */
3760 if (!config->dv_flow_en ||
3761 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3762 !mlx5_flow_ext_mreg_supported(dev))
3763 return flow_create_split_inner(dev, flow, NULL, attr, items,
3764 actions, external, error);
3765 actions_n = flow_parse_qrss_action(actions, &qrss);
3767 /* Exclude hairpin flows from splitting. */
3768 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
3769 const struct rte_flow_action_queue *queue;
3772 if (mlx5_rxq_get_type(dev, queue->index) ==
3773 MLX5_RXQ_TYPE_HAIRPIN)
3775 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
3776 const struct rte_flow_action_rss *rss;
3779 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
3780 MLX5_RXQ_TYPE_HAIRPIN)
3785 /* Check if it is in meter suffix table. */
3786 mtr_sfx = attr->group == (attr->transfer ?
3787 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
3788 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
3790 * Q/RSS action on NIC Rx should be split in order to pass by
3791 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3792 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3794 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3795 sizeof(struct rte_flow_action_set_tag) +
3796 sizeof(struct rte_flow_action_jump);
3797 ext_actions = rte_zmalloc(__func__, act_size, 0);
3799 return rte_flow_error_set(error, ENOMEM,
3800 RTE_FLOW_ERROR_TYPE_ACTION,
3801 NULL, "no memory to split "
3804 * If we are the suffix flow of meter, tag already exist.
3805 * Set the tag action to void.
3808 ext_actions[qrss - actions].type =
3809 RTE_FLOW_ACTION_TYPE_VOID;
3811 ext_actions[qrss - actions].type =
3812 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3814 * Create the new actions list with removed Q/RSS action
3815 * and appended set tag and jump to register copy table
3816 * (RX_CP_TBL). We should preallocate unique tag ID here
3817 * in advance, because it is needed for set tag action.
3819 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
3820 qrss, actions_n, error);
3821 if (!mtr_sfx && !qrss_id) {
3825 } else if (attr->egress && !attr->transfer) {
3827 * All the actions on NIC Tx should have a metadata register
3828 * copy action to copy reg_a from WQE to reg_c[meta]
3830 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3831 sizeof(struct mlx5_flow_action_copy_mreg);
3832 ext_actions = rte_zmalloc(__func__, act_size, 0);
3834 return rte_flow_error_set(error, ENOMEM,
3835 RTE_FLOW_ERROR_TYPE_ACTION,
3836 NULL, "no memory to split "
3838 /* Create the action list appended with copy register. */
3839 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
3844 /* Add the unmodified original or prefix subflow. */
3845 ret = flow_create_split_inner(dev, flow, &dev_flow, attr, items,
3846 ext_actions ? ext_actions : actions,
3852 const struct rte_flow_attr q_attr = {
3853 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3856 /* Internal PMD action to set register. */
3857 struct mlx5_rte_flow_item_tag q_tag_spec = {
3861 struct rte_flow_item q_items[] = {
3863 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3864 .spec = &q_tag_spec,
3869 .type = RTE_FLOW_ITEM_TYPE_END,
3872 struct rte_flow_action q_actions[] = {
3878 .type = RTE_FLOW_ACTION_TYPE_END,
3881 uint64_t hash_fields = dev_flow->hash_fields;
3884 * Configure the tag item only if there is no meter subflow.
3885 * Since tag is already marked in the meter suffix subflow
3886 * we can just use the meter suffix items as is.
3889 /* Not meter subflow. */
3892 * Put unique id in prefix flow due to it is destroyed
3893 * after suffix flow and id will be freed after there
3894 * is no actual flows with this id and identifier
3895 * reallocation becomes possible (for example, for
3896 * other flows in other threads).
3898 dev_flow->qrss_id = qrss_id;
3900 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
3904 q_tag_spec.id = ret;
3907 /* Add suffix subflow to execute Q/RSS. */
3908 ret = flow_create_split_inner(dev, flow, &dev_flow,
3909 &q_attr, mtr_sfx ? items :
3915 dev_flow->hash_fields = hash_fields;
3920 * We do not destroy the partially created sub_flows in case of error.
3921 * These ones are included into parent flow list and will be destroyed
3922 * by flow_drv_destroy.
3924 flow_qrss_free_id(dev, qrss_id);
3925 rte_free(ext_actions);
3930 * The splitting for meter feature.
3932 * - The meter flow will be split to two flows as prefix and
3933 * suffix flow. The packets make sense only it pass the prefix
3936 * - Reg_C_5 is used for the packet to match betweend prefix and
3940 * Pointer to Ethernet device.
3942 * Parent flow structure pointer.
3944 * Flow rule attributes.
3946 * Pattern specification (list terminated by the END pattern item).
3947 * @param[in] actions
3948 * Associated actions (list terminated by the END action).
3949 * @param[in] external
3950 * This flow rule is created by request external to PMD.
3952 * Perform verbose error reporting if not NULL.
3954 * 0 on success, negative value otherwise
3957 flow_create_split_meter(struct rte_eth_dev *dev,
3958 struct rte_flow *flow,
3959 const struct rte_flow_attr *attr,
3960 const struct rte_flow_item items[],
3961 const struct rte_flow_action actions[],
3962 bool external, struct rte_flow_error *error)
3964 struct mlx5_priv *priv = dev->data->dev_private;
3965 struct rte_flow_action *sfx_actions = NULL;
3966 struct rte_flow_action *pre_actions = NULL;
3967 struct rte_flow_item *sfx_items = NULL;
3968 const struct rte_flow_item *sfx_port_id_item;
3969 struct mlx5_flow *dev_flow = NULL;
3970 struct rte_flow_attr sfx_attr = *attr;
3972 uint32_t mtr_tag_id = 0;
3979 actions_n = flow_check_meter_action(actions, &mtr);
3981 struct mlx5_rte_flow_item_tag *tag_spec;
3982 struct mlx5_rte_flow_item_tag *tag_mask;
3983 /* The five prefix actions: meter, decap, encap, tag, end. */
3984 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
3985 sizeof(struct rte_flow_action_set_tag);
3987 #define METER_SUFFIX_ITEM 3
3988 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
3989 sizeof(struct mlx5_rte_flow_item_tag) * 2;
3990 sfx_actions = rte_zmalloc(__func__, (act_size + item_size), 0);
3992 return rte_flow_error_set(error, ENOMEM,
3993 RTE_FLOW_ERROR_TYPE_ACTION,
3994 NULL, "no memory to split "
3996 pre_actions = sfx_actions + actions_n;
3997 mtr_tag_id = flow_meter_split_prep(dev, actions, sfx_actions,
4003 /* Add the prefix subflow. */
4004 ret = flow_create_split_inner(dev, flow, &dev_flow, attr, items,
4005 pre_actions, external, error);
4010 dev_flow->mtr_flow_id = mtr_tag_id;
4011 /* Prepare the suffix flow match pattern. */
4012 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4014 tag_spec = (struct mlx5_rte_flow_item_tag *)(sfx_items +
4016 tag_spec->data = dev_flow->mtr_flow_id << MLX5_MTR_COLOR_BITS;
4017 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0,
4019 tag_mask = tag_spec + 1;
4020 tag_mask->data = 0xffffff00;
4021 sfx_items->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4022 sfx_items->spec = tag_spec;
4023 sfx_items->last = NULL;
4024 sfx_items->mask = tag_mask;
4026 sfx_port_id_item = find_port_id_item(items);
4027 if (sfx_port_id_item) {
4028 memcpy(sfx_items, sfx_port_id_item,
4029 sizeof(*sfx_items));
4032 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4033 sfx_items -= sfx_port_id_item ? 2 : 1;
4034 /* Setting the sfx group atrr. */
4035 sfx_attr.group = sfx_attr.transfer ?
4036 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4037 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4039 /* Add the prefix subflow. */
4040 ret = flow_create_split_metadata(dev, flow, &sfx_attr,
4041 sfx_items ? sfx_items : items,
4042 sfx_actions ? sfx_actions : actions,
4046 rte_free(sfx_actions);
4051 * Split the flow to subflow set. The splitters might be linked
4052 * in the chain, like this:
4053 * flow_create_split_outer() calls:
4054 * flow_create_split_meter() calls:
4055 * flow_create_split_metadata(meter_subflow_0) calls:
4056 * flow_create_split_inner(metadata_subflow_0)
4057 * flow_create_split_inner(metadata_subflow_1)
4058 * flow_create_split_inner(metadata_subflow_2)
4059 * flow_create_split_metadata(meter_subflow_1) calls:
4060 * flow_create_split_inner(metadata_subflow_0)
4061 * flow_create_split_inner(metadata_subflow_1)
4062 * flow_create_split_inner(metadata_subflow_2)
4064 * This provide flexible way to add new levels of flow splitting.
4065 * The all of successfully created subflows are included to the
4066 * parent flow dev_flow list.
4069 * Pointer to Ethernet device.
4071 * Parent flow structure pointer.
4073 * Flow rule attributes.
4075 * Pattern specification (list terminated by the END pattern item).
4076 * @param[in] actions
4077 * Associated actions (list terminated by the END action).
4078 * @param[in] external
4079 * This flow rule is created by request external to PMD.
4081 * Perform verbose error reporting if not NULL.
4083 * 0 on success, negative value otherwise
4086 flow_create_split_outer(struct rte_eth_dev *dev,
4087 struct rte_flow *flow,
4088 const struct rte_flow_attr *attr,
4089 const struct rte_flow_item items[],
4090 const struct rte_flow_action actions[],
4091 bool external, struct rte_flow_error *error)
4095 ret = flow_create_split_meter(dev, flow, attr, items,
4096 actions, external, error);
4102 * Create a flow and add it to @p list.
4105 * Pointer to Ethernet device.
4107 * Pointer to a TAILQ flow list. If this parameter NULL,
4108 * no list insertion occurred, flow is just created,
4109 * this is caller's responsibility to track the
4112 * Flow rule attributes.
4114 * Pattern specification (list terminated by the END pattern item).
4115 * @param[in] actions
4116 * Associated actions (list terminated by the END action).
4117 * @param[in] external
4118 * This flow rule is created by request external to PMD.
4120 * Perform verbose error reporting if not NULL.
4123 * A flow on success, NULL otherwise and rte_errno is set.
4125 static struct rte_flow *
4126 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
4127 const struct rte_flow_attr *attr,
4128 const struct rte_flow_item items[],
4129 const struct rte_flow_action actions[],
4130 bool external, struct rte_flow_error *error)
4132 struct mlx5_priv *priv = dev->data->dev_private;
4133 struct rte_flow *flow = NULL;
4134 struct mlx5_flow *dev_flow;
4135 const struct rte_flow_action_rss *rss;
4137 struct rte_flow_expand_rss buf;
4138 uint8_t buffer[2048];
4141 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4142 uint8_t buffer[2048];
4145 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4146 uint8_t buffer[2048];
4147 } actions_hairpin_tx;
4149 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
4150 uint8_t buffer[2048];
4152 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
4153 const struct rte_flow_action *p_actions_rx = actions;
4157 int hairpin_flow = 0;
4158 uint32_t hairpin_id = 0;
4159 struct rte_flow_attr attr_tx = { .priority = 0 };
4161 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4162 if (hairpin_flow > 0) {
4163 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
4167 flow_hairpin_split(dev, actions, actions_rx.actions,
4168 actions_hairpin_tx.actions, items_tx.items,
4170 p_actions_rx = actions_rx.actions;
4172 ret = flow_drv_validate(dev, attr, items, p_actions_rx, external,
4175 goto error_before_flow;
4176 flow_size = sizeof(struct rte_flow);
4177 rss = flow_get_rss_action(p_actions_rx);
4179 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
4182 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
4183 flow = rte_calloc(__func__, 1, flow_size, 0);
4186 goto error_before_flow;
4188 flow->drv_type = flow_get_drv_type(dev, attr);
4189 if (hairpin_id != 0)
4190 flow->hairpin_flow_id = hairpin_id;
4191 assert(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
4192 flow->drv_type < MLX5_FLOW_TYPE_MAX);
4193 flow->rss.queue = (void *)(flow + 1);
4196 * The following information is required by
4197 * mlx5_flow_hashfields_adjust() in advance.
4199 flow->rss.level = rss->level;
4200 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
4201 flow->rss.types = !rss->types ? ETH_RSS_IP : rss->types;
4203 LIST_INIT(&flow->dev_flows);
4204 if (rss && rss->types) {
4205 unsigned int graph_root;
4207 graph_root = find_graph_root(items, rss->level);
4208 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
4210 mlx5_support_expansion,
4213 (unsigned int)ret < sizeof(expand_buffer.buffer));
4216 buf->entry[0].pattern = (void *)(uintptr_t)items;
4218 for (i = 0; i < buf->entries; ++i) {
4220 * The splitter may create multiple dev_flows,
4221 * depending on configuration. In the simplest
4222 * case it just creates unmodified original flow.
4224 ret = flow_create_split_outer(dev, flow, attr,
4225 buf->entry[i].pattern,
4226 p_actions_rx, external,
4231 /* Create the tx flow. */
4233 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
4234 attr_tx.ingress = 0;
4236 dev_flow = flow_drv_prepare(flow, &attr_tx, items_tx.items,
4237 actions_hairpin_tx.actions, error);
4240 dev_flow->flow = flow;
4241 dev_flow->external = 0;
4242 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
4243 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
4245 actions_hairpin_tx.actions, error);
4250 * Update the metadata register copy table. If extensive
4251 * metadata feature is enabled and registers are supported
4252 * we might create the extra rte_flow for each unique
4253 * MARK/FLAG action ID.
4255 * The table is updated for ingress Flows only, because
4256 * the egress Flows belong to the different device and
4257 * copy table should be updated in peer NIC Rx domain.
4259 if (attr->ingress &&
4260 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
4261 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
4265 if (dev->data->dev_started) {
4266 ret = flow_drv_apply(dev, flow, error);
4271 TAILQ_INSERT_TAIL(list, flow, next);
4272 flow_rxq_flags_set(dev, flow);
4276 mlx5_flow_id_release(priv->sh->flow_id_pool,
4281 flow_mreg_del_copy_action(dev, flow);
4282 ret = rte_errno; /* Save rte_errno before cleanup. */
4283 if (flow->hairpin_flow_id)
4284 mlx5_flow_id_release(priv->sh->flow_id_pool,
4285 flow->hairpin_flow_id);
4287 flow_drv_destroy(dev, flow);
4289 rte_errno = ret; /* Restore rte_errno. */
4294 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
4295 * incoming packets to table 1.
4297 * Other flow rules, requested for group n, will be created in
4298 * e-switch table n+1.
4299 * Jump action to e-switch group n will be created to group n+1.
4301 * Used when working in switchdev mode, to utilise advantages of table 1
4305 * Pointer to Ethernet device.
4308 * Pointer to flow on success, NULL otherwise and rte_errno is set.
4311 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
4313 const struct rte_flow_attr attr = {
4320 const struct rte_flow_item pattern = {
4321 .type = RTE_FLOW_ITEM_TYPE_END,
4323 struct rte_flow_action_jump jump = {
4326 const struct rte_flow_action actions[] = {
4328 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4332 .type = RTE_FLOW_ACTION_TYPE_END,
4335 struct mlx5_priv *priv = dev->data->dev_private;
4336 struct rte_flow_error error;
4338 return flow_list_create(dev, &priv->ctrl_flows, &attr, &pattern,
4339 actions, false, &error);
4345 * @see rte_flow_create()
4349 mlx5_flow_create(struct rte_eth_dev *dev,
4350 const struct rte_flow_attr *attr,
4351 const struct rte_flow_item items[],
4352 const struct rte_flow_action actions[],
4353 struct rte_flow_error *error)
4355 struct mlx5_priv *priv = dev->data->dev_private;
4357 return flow_list_create(dev, &priv->flows,
4358 attr, items, actions, true, error);
4362 * Destroy a flow in a list.
4365 * Pointer to Ethernet device.
4367 * Pointer to a TAILQ flow list. If this parameter NULL,
4368 * there is no flow removal from the list.
4373 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
4374 struct rte_flow *flow)
4376 struct mlx5_priv *priv = dev->data->dev_private;
4379 * Update RX queue flags only if port is started, otherwise it is
4382 if (dev->data->dev_started)
4383 flow_rxq_flags_trim(dev, flow);
4384 if (flow->hairpin_flow_id)
4385 mlx5_flow_id_release(priv->sh->flow_id_pool,
4386 flow->hairpin_flow_id);
4387 flow_drv_destroy(dev, flow);
4389 TAILQ_REMOVE(list, flow, next);
4390 flow_mreg_del_copy_action(dev, flow);
4391 rte_free(flow->fdir);
4396 * Destroy all flows.
4399 * Pointer to Ethernet device.
4401 * Pointer to a TAILQ flow list.
4404 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
4406 while (!TAILQ_EMPTY(list)) {
4407 struct rte_flow *flow;
4409 flow = TAILQ_FIRST(list);
4410 flow_list_destroy(dev, list, flow);
4418 * Pointer to Ethernet device.
4420 * Pointer to a TAILQ flow list.
4423 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
4425 struct rte_flow *flow;
4427 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next) {
4428 flow_drv_remove(dev, flow);
4429 flow_mreg_stop_copy_action(dev, flow);
4431 flow_mreg_del_default_copy_action(dev);
4432 flow_rxq_flags_clear(dev);
4439 * Pointer to Ethernet device.
4441 * Pointer to a TAILQ flow list.
4444 * 0 on success, a negative errno value otherwise and rte_errno is set.
4447 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
4449 struct rte_flow *flow;
4450 struct rte_flow_error error;
4453 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4454 ret = flow_mreg_add_default_copy_action(dev, &error);
4457 /* Apply Flows created by application. */
4458 TAILQ_FOREACH(flow, list, next) {
4459 ret = flow_mreg_start_copy_action(dev, flow);
4462 ret = flow_drv_apply(dev, flow, &error);
4465 flow_rxq_flags_set(dev, flow);
4469 ret = rte_errno; /* Save rte_errno before cleanup. */
4470 mlx5_flow_stop(dev, list);
4471 rte_errno = ret; /* Restore rte_errno. */
4476 * Verify the flow list is empty
4479 * Pointer to Ethernet device.
4481 * @return the number of flows not released.
4484 mlx5_flow_verify(struct rte_eth_dev *dev)
4486 struct mlx5_priv *priv = dev->data->dev_private;
4487 struct rte_flow *flow;
4490 TAILQ_FOREACH(flow, &priv->flows, next) {
4491 DRV_LOG(DEBUG, "port %u flow %p still referenced",
4492 dev->data->port_id, (void *)flow);
4499 * Enable default hairpin egress flow.
4502 * Pointer to Ethernet device.
4507 * 0 on success, a negative errno value otherwise and rte_errno is set.
4510 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
4513 struct mlx5_priv *priv = dev->data->dev_private;
4514 const struct rte_flow_attr attr = {
4518 struct mlx5_rte_flow_item_tx_queue queue_spec = {
4521 struct mlx5_rte_flow_item_tx_queue queue_mask = {
4522 .queue = UINT32_MAX,
4524 struct rte_flow_item items[] = {
4526 .type = MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
4527 .spec = &queue_spec,
4529 .mask = &queue_mask,
4532 .type = RTE_FLOW_ITEM_TYPE_END,
4535 struct rte_flow_action_jump jump = {
4536 .group = MLX5_HAIRPIN_TX_TABLE,
4538 struct rte_flow_action actions[2];
4539 struct rte_flow *flow;
4540 struct rte_flow_error error;
4542 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
4543 actions[0].conf = &jump;
4544 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
4545 flow = flow_list_create(dev, &priv->ctrl_flows,
4546 &attr, items, actions, false, &error);
4549 "Failed to create ctrl flow: rte_errno(%d),"
4550 " type(%d), message(%s)",
4551 rte_errno, error.type,
4552 error.message ? error.message : " (no stated reason)");
4559 * Enable a control flow configured from the control plane.
4562 * Pointer to Ethernet device.
4564 * An Ethernet flow spec to apply.
4566 * An Ethernet flow mask to apply.
4568 * A VLAN flow spec to apply.
4570 * A VLAN flow mask to apply.
4573 * 0 on success, a negative errno value otherwise and rte_errno is set.
4576 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
4577 struct rte_flow_item_eth *eth_spec,
4578 struct rte_flow_item_eth *eth_mask,
4579 struct rte_flow_item_vlan *vlan_spec,
4580 struct rte_flow_item_vlan *vlan_mask)
4582 struct mlx5_priv *priv = dev->data->dev_private;
4583 const struct rte_flow_attr attr = {
4585 .priority = MLX5_FLOW_PRIO_RSVD,
4587 struct rte_flow_item items[] = {
4589 .type = RTE_FLOW_ITEM_TYPE_ETH,
4595 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
4596 RTE_FLOW_ITEM_TYPE_END,
4602 .type = RTE_FLOW_ITEM_TYPE_END,
4605 uint16_t queue[priv->reta_idx_n];
4606 struct rte_flow_action_rss action_rss = {
4607 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4609 .types = priv->rss_conf.rss_hf,
4610 .key_len = priv->rss_conf.rss_key_len,
4611 .queue_num = priv->reta_idx_n,
4612 .key = priv->rss_conf.rss_key,
4615 struct rte_flow_action actions[] = {
4617 .type = RTE_FLOW_ACTION_TYPE_RSS,
4618 .conf = &action_rss,
4621 .type = RTE_FLOW_ACTION_TYPE_END,
4624 struct rte_flow *flow;
4625 struct rte_flow_error error;
4628 if (!priv->reta_idx_n || !priv->rxqs_n) {
4631 for (i = 0; i != priv->reta_idx_n; ++i)
4632 queue[i] = (*priv->reta_idx)[i];
4633 flow = flow_list_create(dev, &priv->ctrl_flows,
4634 &attr, items, actions, false, &error);
4641 * Enable a flow control configured from the control plane.
4644 * Pointer to Ethernet device.
4646 * An Ethernet flow spec to apply.
4648 * An Ethernet flow mask to apply.
4651 * 0 on success, a negative errno value otherwise and rte_errno is set.
4654 mlx5_ctrl_flow(struct rte_eth_dev *dev,
4655 struct rte_flow_item_eth *eth_spec,
4656 struct rte_flow_item_eth *eth_mask)
4658 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
4664 * @see rte_flow_destroy()
4668 mlx5_flow_destroy(struct rte_eth_dev *dev,
4669 struct rte_flow *flow,
4670 struct rte_flow_error *error __rte_unused)
4672 struct mlx5_priv *priv = dev->data->dev_private;
4674 flow_list_destroy(dev, &priv->flows, flow);
4679 * Destroy all flows.
4681 * @see rte_flow_flush()
4685 mlx5_flow_flush(struct rte_eth_dev *dev,
4686 struct rte_flow_error *error __rte_unused)
4688 struct mlx5_priv *priv = dev->data->dev_private;
4690 mlx5_flow_list_flush(dev, &priv->flows);
4697 * @see rte_flow_isolate()
4701 mlx5_flow_isolate(struct rte_eth_dev *dev,
4703 struct rte_flow_error *error)
4705 struct mlx5_priv *priv = dev->data->dev_private;
4707 if (dev->data->dev_started) {
4708 rte_flow_error_set(error, EBUSY,
4709 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4711 "port must be stopped first");
4714 priv->isolated = !!enable;
4716 dev->dev_ops = &mlx5_dev_ops_isolate;
4718 dev->dev_ops = &mlx5_dev_ops;
4725 * @see rte_flow_query()
4729 flow_drv_query(struct rte_eth_dev *dev,
4730 struct rte_flow *flow,
4731 const struct rte_flow_action *actions,
4733 struct rte_flow_error *error)
4735 const struct mlx5_flow_driver_ops *fops;
4736 enum mlx5_flow_drv_type ftype = flow->drv_type;
4738 assert(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
4739 fops = flow_get_drv_ops(ftype);
4741 return fops->query(dev, flow, actions, data, error);
4747 * @see rte_flow_query()
4751 mlx5_flow_query(struct rte_eth_dev *dev,
4752 struct rte_flow *flow,
4753 const struct rte_flow_action *actions,
4755 struct rte_flow_error *error)
4759 ret = flow_drv_query(dev, flow, actions, data, error);
4766 * Convert a flow director filter to a generic flow.
4769 * Pointer to Ethernet device.
4770 * @param fdir_filter
4771 * Flow director filter to add.
4773 * Generic flow parameters structure.
4776 * 0 on success, a negative errno value otherwise and rte_errno is set.
4779 flow_fdir_filter_convert(struct rte_eth_dev *dev,
4780 const struct rte_eth_fdir_filter *fdir_filter,
4781 struct mlx5_fdir *attributes)
4783 struct mlx5_priv *priv = dev->data->dev_private;
4784 const struct rte_eth_fdir_input *input = &fdir_filter->input;
4785 const struct rte_eth_fdir_masks *mask =
4786 &dev->data->dev_conf.fdir_conf.mask;
4788 /* Validate queue number. */
4789 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
4790 DRV_LOG(ERR, "port %u invalid queue number %d",
4791 dev->data->port_id, fdir_filter->action.rx_queue);
4795 attributes->attr.ingress = 1;
4796 attributes->items[0] = (struct rte_flow_item) {
4797 .type = RTE_FLOW_ITEM_TYPE_ETH,
4798 .spec = &attributes->l2,
4799 .mask = &attributes->l2_mask,
4801 switch (fdir_filter->action.behavior) {
4802 case RTE_ETH_FDIR_ACCEPT:
4803 attributes->actions[0] = (struct rte_flow_action){
4804 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
4805 .conf = &attributes->queue,
4808 case RTE_ETH_FDIR_REJECT:
4809 attributes->actions[0] = (struct rte_flow_action){
4810 .type = RTE_FLOW_ACTION_TYPE_DROP,
4814 DRV_LOG(ERR, "port %u invalid behavior %d",
4816 fdir_filter->action.behavior);
4817 rte_errno = ENOTSUP;
4820 attributes->queue.index = fdir_filter->action.rx_queue;
4822 switch (fdir_filter->input.flow_type) {
4823 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4824 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4825 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
4826 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
4827 .src_addr = input->flow.ip4_flow.src_ip,
4828 .dst_addr = input->flow.ip4_flow.dst_ip,
4829 .time_to_live = input->flow.ip4_flow.ttl,
4830 .type_of_service = input->flow.ip4_flow.tos,
4832 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
4833 .src_addr = mask->ipv4_mask.src_ip,
4834 .dst_addr = mask->ipv4_mask.dst_ip,
4835 .time_to_live = mask->ipv4_mask.ttl,
4836 .type_of_service = mask->ipv4_mask.tos,
4837 .next_proto_id = mask->ipv4_mask.proto,
4839 attributes->items[1] = (struct rte_flow_item){
4840 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4841 .spec = &attributes->l3,
4842 .mask = &attributes->l3_mask,
4845 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
4846 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
4847 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
4848 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
4849 .hop_limits = input->flow.ipv6_flow.hop_limits,
4850 .proto = input->flow.ipv6_flow.proto,
4853 memcpy(attributes->l3.ipv6.hdr.src_addr,
4854 input->flow.ipv6_flow.src_ip,
4855 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4856 memcpy(attributes->l3.ipv6.hdr.dst_addr,
4857 input->flow.ipv6_flow.dst_ip,
4858 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4859 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
4860 mask->ipv6_mask.src_ip,
4861 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4862 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
4863 mask->ipv6_mask.dst_ip,
4864 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4865 attributes->items[1] = (struct rte_flow_item){
4866 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4867 .spec = &attributes->l3,
4868 .mask = &attributes->l3_mask,
4872 DRV_LOG(ERR, "port %u invalid flow type%d",
4873 dev->data->port_id, fdir_filter->input.flow_type);
4874 rte_errno = ENOTSUP;
4878 switch (fdir_filter->input.flow_type) {
4879 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4880 attributes->l4.udp.hdr = (struct rte_udp_hdr){
4881 .src_port = input->flow.udp4_flow.src_port,
4882 .dst_port = input->flow.udp4_flow.dst_port,
4884 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
4885 .src_port = mask->src_port_mask,
4886 .dst_port = mask->dst_port_mask,
4888 attributes->items[2] = (struct rte_flow_item){
4889 .type = RTE_FLOW_ITEM_TYPE_UDP,
4890 .spec = &attributes->l4,
4891 .mask = &attributes->l4_mask,
4894 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4895 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
4896 .src_port = input->flow.tcp4_flow.src_port,
4897 .dst_port = input->flow.tcp4_flow.dst_port,
4899 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
4900 .src_port = mask->src_port_mask,
4901 .dst_port = mask->dst_port_mask,
4903 attributes->items[2] = (struct rte_flow_item){
4904 .type = RTE_FLOW_ITEM_TYPE_TCP,
4905 .spec = &attributes->l4,
4906 .mask = &attributes->l4_mask,
4909 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
4910 attributes->l4.udp.hdr = (struct rte_udp_hdr){
4911 .src_port = input->flow.udp6_flow.src_port,
4912 .dst_port = input->flow.udp6_flow.dst_port,
4914 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
4915 .src_port = mask->src_port_mask,
4916 .dst_port = mask->dst_port_mask,
4918 attributes->items[2] = (struct rte_flow_item){
4919 .type = RTE_FLOW_ITEM_TYPE_UDP,
4920 .spec = &attributes->l4,
4921 .mask = &attributes->l4_mask,
4924 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
4925 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
4926 .src_port = input->flow.tcp6_flow.src_port,
4927 .dst_port = input->flow.tcp6_flow.dst_port,
4929 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
4930 .src_port = mask->src_port_mask,
4931 .dst_port = mask->dst_port_mask,
4933 attributes->items[2] = (struct rte_flow_item){
4934 .type = RTE_FLOW_ITEM_TYPE_TCP,
4935 .spec = &attributes->l4,
4936 .mask = &attributes->l4_mask,
4939 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
4940 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
4943 DRV_LOG(ERR, "port %u invalid flow type%d",
4944 dev->data->port_id, fdir_filter->input.flow_type);
4945 rte_errno = ENOTSUP;
4951 #define FLOW_FDIR_CMP(f1, f2, fld) \
4952 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
4955 * Compare two FDIR flows. If items and actions are identical, the two flows are
4959 * Pointer to Ethernet device.
4961 * FDIR flow to compare.
4963 * FDIR flow to compare.
4966 * Zero on match, 1 otherwise.
4969 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
4971 if (FLOW_FDIR_CMP(f1, f2, attr) ||
4972 FLOW_FDIR_CMP(f1, f2, l2) ||
4973 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
4974 FLOW_FDIR_CMP(f1, f2, l3) ||
4975 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
4976 FLOW_FDIR_CMP(f1, f2, l4) ||
4977 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
4978 FLOW_FDIR_CMP(f1, f2, actions[0].type))
4980 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
4981 FLOW_FDIR_CMP(f1, f2, queue))
4987 * Search device flow list to find out a matched FDIR flow.
4990 * Pointer to Ethernet device.
4992 * FDIR flow to lookup.
4995 * Pointer of flow if found, NULL otherwise.
4997 static struct rte_flow *
4998 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
5000 struct mlx5_priv *priv = dev->data->dev_private;
5001 struct rte_flow *flow = NULL;
5004 TAILQ_FOREACH(flow, &priv->flows, next) {
5005 if (flow->fdir && !flow_fdir_cmp(flow->fdir, fdir_flow)) {
5006 DRV_LOG(DEBUG, "port %u found FDIR flow %p",
5007 dev->data->port_id, (void *)flow);
5015 * Add new flow director filter and store it in list.
5018 * Pointer to Ethernet device.
5019 * @param fdir_filter
5020 * Flow director filter to add.
5023 * 0 on success, a negative errno value otherwise and rte_errno is set.
5026 flow_fdir_filter_add(struct rte_eth_dev *dev,
5027 const struct rte_eth_fdir_filter *fdir_filter)
5029 struct mlx5_priv *priv = dev->data->dev_private;
5030 struct mlx5_fdir *fdir_flow;
5031 struct rte_flow *flow;
5034 fdir_flow = rte_zmalloc(__func__, sizeof(*fdir_flow), 0);
5039 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
5042 flow = flow_fdir_filter_lookup(dev, fdir_flow);
5047 flow = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
5048 fdir_flow->items, fdir_flow->actions, true,
5052 assert(!flow->fdir);
5053 flow->fdir = fdir_flow;
5054 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
5055 dev->data->port_id, (void *)flow);
5058 rte_free(fdir_flow);
5063 * Delete specific filter.
5066 * Pointer to Ethernet device.
5067 * @param fdir_filter
5068 * Filter to be deleted.
5071 * 0 on success, a negative errno value otherwise and rte_errno is set.
5074 flow_fdir_filter_delete(struct rte_eth_dev *dev,
5075 const struct rte_eth_fdir_filter *fdir_filter)
5077 struct mlx5_priv *priv = dev->data->dev_private;
5078 struct rte_flow *flow;
5079 struct mlx5_fdir fdir_flow = {
5084 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
5087 flow = flow_fdir_filter_lookup(dev, &fdir_flow);
5092 flow_list_destroy(dev, &priv->flows, flow);
5093 DRV_LOG(DEBUG, "port %u deleted FDIR flow %p",
5094 dev->data->port_id, (void *)flow);
5099 * Update queue for specific filter.
5102 * Pointer to Ethernet device.
5103 * @param fdir_filter
5104 * Filter to be updated.
5107 * 0 on success, a negative errno value otherwise and rte_errno is set.
5110 flow_fdir_filter_update(struct rte_eth_dev *dev,
5111 const struct rte_eth_fdir_filter *fdir_filter)
5115 ret = flow_fdir_filter_delete(dev, fdir_filter);
5118 return flow_fdir_filter_add(dev, fdir_filter);
5122 * Flush all filters.
5125 * Pointer to Ethernet device.
5128 flow_fdir_filter_flush(struct rte_eth_dev *dev)
5130 struct mlx5_priv *priv = dev->data->dev_private;
5132 mlx5_flow_list_flush(dev, &priv->flows);
5136 * Get flow director information.
5139 * Pointer to Ethernet device.
5140 * @param[out] fdir_info
5141 * Resulting flow director information.
5144 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
5146 struct rte_eth_fdir_masks *mask =
5147 &dev->data->dev_conf.fdir_conf.mask;
5149 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
5150 fdir_info->guarant_spc = 0;
5151 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
5152 fdir_info->max_flexpayload = 0;
5153 fdir_info->flow_types_mask[0] = 0;
5154 fdir_info->flex_payload_unit = 0;
5155 fdir_info->max_flex_payload_segment_num = 0;
5156 fdir_info->flex_payload_limit = 0;
5157 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
5161 * Deal with flow director operations.
5164 * Pointer to Ethernet device.
5166 * Operation to perform.
5168 * Pointer to operation-specific structure.
5171 * 0 on success, a negative errno value otherwise and rte_errno is set.
5174 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
5177 enum rte_fdir_mode fdir_mode =
5178 dev->data->dev_conf.fdir_conf.mode;
5180 if (filter_op == RTE_ETH_FILTER_NOP)
5182 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
5183 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5184 DRV_LOG(ERR, "port %u flow director mode %d not supported",
5185 dev->data->port_id, fdir_mode);
5189 switch (filter_op) {
5190 case RTE_ETH_FILTER_ADD:
5191 return flow_fdir_filter_add(dev, arg);
5192 case RTE_ETH_FILTER_UPDATE:
5193 return flow_fdir_filter_update(dev, arg);
5194 case RTE_ETH_FILTER_DELETE:
5195 return flow_fdir_filter_delete(dev, arg);
5196 case RTE_ETH_FILTER_FLUSH:
5197 flow_fdir_filter_flush(dev);
5199 case RTE_ETH_FILTER_INFO:
5200 flow_fdir_info_get(dev, arg);
5203 DRV_LOG(DEBUG, "port %u unknown operation %u",
5204 dev->data->port_id, filter_op);
5212 * Manage filter operations.
5215 * Pointer to Ethernet device structure.
5216 * @param filter_type
5219 * Operation to perform.
5221 * Pointer to operation-specific structure.
5224 * 0 on success, a negative errno value otherwise and rte_errno is set.
5227 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
5228 enum rte_filter_type filter_type,
5229 enum rte_filter_op filter_op,
5232 switch (filter_type) {
5233 case RTE_ETH_FILTER_GENERIC:
5234 if (filter_op != RTE_ETH_FILTER_GET) {
5238 *(const void **)arg = &mlx5_flow_ops;
5240 case RTE_ETH_FILTER_FDIR:
5241 return flow_fdir_ctrl_func(dev, filter_op, arg);
5243 DRV_LOG(ERR, "port %u filter type (%d) not supported",
5244 dev->data->port_id, filter_type);
5245 rte_errno = ENOTSUP;
5252 * Create the needed meter and suffix tables.
5255 * Pointer to Ethernet device.
5257 * Pointer to the flow meter.
5260 * Pointer to table set on success, NULL otherwise.
5262 struct mlx5_meter_domains_infos *
5263 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
5264 const struct mlx5_flow_meter *fm)
5266 const struct mlx5_flow_driver_ops *fops;
5268 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5269 return fops->create_mtr_tbls(dev, fm);
5273 * Destroy the meter table set.
5276 * Pointer to Ethernet device.
5278 * Pointer to the meter table set.
5284 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
5285 struct mlx5_meter_domains_infos *tbls)
5287 const struct mlx5_flow_driver_ops *fops;
5289 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5290 return fops->destroy_mtr_tbls(dev, tbls);
5294 * Create policer rules.
5297 * Pointer to Ethernet device.
5299 * Pointer to flow meter structure.
5301 * Pointer to flow attributes.
5304 * 0 on success, -1 otherwise.
5307 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
5308 struct mlx5_flow_meter *fm,
5309 const struct rte_flow_attr *attr)
5311 const struct mlx5_flow_driver_ops *fops;
5313 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5314 return fops->create_policer_rules(dev, fm, attr);
5318 * Destroy policer rules.
5321 * Pointer to flow meter structure.
5323 * Pointer to flow attributes.
5326 * 0 on success, -1 otherwise.
5329 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
5330 struct mlx5_flow_meter *fm,
5331 const struct rte_flow_attr *attr)
5333 const struct mlx5_flow_driver_ops *fops;
5335 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5336 return fops->destroy_policer_rules(dev, fm, attr);
5340 * Allocate a counter.
5343 * Pointer to Ethernet device structure.
5346 * Pointer to allocated counter on success, NULL otherwise.
5348 struct mlx5_flow_counter *
5349 mlx5_counter_alloc(struct rte_eth_dev *dev)
5351 const struct mlx5_flow_driver_ops *fops;
5352 struct rte_flow_attr attr = { .transfer = 0 };
5354 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5355 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5356 return fops->counter_alloc(dev);
5359 "port %u counter allocate is not supported.",
5360 dev->data->port_id);
5368 * Pointer to Ethernet device structure.
5370 * Pointer to counter to be free.
5373 mlx5_counter_free(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt)
5375 const struct mlx5_flow_driver_ops *fops;
5376 struct rte_flow_attr attr = { .transfer = 0 };
5378 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5379 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5380 fops->counter_free(dev, cnt);
5384 "port %u counter free is not supported.",
5385 dev->data->port_id);
5389 * Query counter statistics.
5392 * Pointer to Ethernet device structure.
5394 * Pointer to counter to query.
5396 * Set to clear counter statistics.
5398 * The counter hits packets number to save.
5400 * The counter hits bytes number to save.
5403 * 0 on success, a negative errno value otherwise.
5406 mlx5_counter_query(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt,
5407 bool clear, uint64_t *pkts, uint64_t *bytes)
5409 const struct mlx5_flow_driver_ops *fops;
5410 struct rte_flow_attr attr = { .transfer = 0 };
5412 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5413 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5414 return fops->counter_query(dev, cnt, clear, pkts, bytes);
5417 "port %u counter query is not supported.",
5418 dev->data->port_id);
5422 #define MLX5_POOL_QUERY_FREQ_US 1000000
5425 * Set the periodic procedure for triggering asynchronous batch queries for all
5426 * the counter pools.
5429 * Pointer to mlx5_ibv_shared object.
5432 mlx5_set_query_alarm(struct mlx5_ibv_shared *sh)
5434 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(sh, 0, 0);
5435 uint32_t pools_n = rte_atomic16_read(&cont->n_valid);
5438 cont = MLX5_CNT_CONTAINER(sh, 1, 0);
5439 pools_n += rte_atomic16_read(&cont->n_valid);
5440 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
5441 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
5442 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
5443 sh->cmng.query_thread_on = 0;
5444 DRV_LOG(ERR, "Cannot reinitialize query alarm");
5446 sh->cmng.query_thread_on = 1;
5451 * The periodic procedure for triggering asynchronous batch queries for all the
5452 * counter pools. This function is probably called by the host thread.
5455 * The parameter for the alarm process.
5458 mlx5_flow_query_alarm(void *arg)
5460 struct mlx5_ibv_shared *sh = arg;
5461 struct mlx5_devx_obj *dcs;
5464 uint8_t batch = sh->cmng.batch;
5465 uint16_t pool_index = sh->cmng.pool_index;
5466 struct mlx5_pools_container *cont;
5467 struct mlx5_pools_container *mcont;
5468 struct mlx5_flow_counter_pool *pool;
5470 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
5473 cont = MLX5_CNT_CONTAINER(sh, batch, 1);
5474 mcont = MLX5_CNT_CONTAINER(sh, batch, 0);
5475 /* Check if resize was done and need to flip a container. */
5476 if (cont != mcont) {
5478 /* Clean the old container. */
5479 rte_free(cont->pools);
5480 memset(cont, 0, sizeof(*cont));
5483 /* Flip the host container. */
5484 sh->cmng.mhi[batch] ^= (uint8_t)2;
5488 /* 2 empty containers case is unexpected. */
5489 if (unlikely(batch != sh->cmng.batch))
5493 goto next_container;
5495 pool = cont->pools[pool_index];
5497 /* There is a pool query in progress. */
5500 LIST_FIRST(&sh->cmng.free_stat_raws);
5502 /* No free counter statistics raw memory. */
5504 dcs = (struct mlx5_devx_obj *)(uintptr_t)rte_atomic64_read
5506 offset = batch ? 0 : dcs->id % MLX5_COUNTERS_PER_POOL;
5507 ret = mlx5_devx_cmd_flow_counter_query(dcs, 0, MLX5_COUNTERS_PER_POOL -
5509 pool->raw_hw->mem_mng->dm->id,
5511 (pool->raw_hw->data + offset),
5513 (uint64_t)(uintptr_t)pool);
5515 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
5516 " %d", pool->min_dcs->id);
5517 pool->raw_hw = NULL;
5520 pool->raw_hw->min_dcs_id = dcs->id;
5521 LIST_REMOVE(pool->raw_hw, next);
5522 sh->cmng.pending_queries++;
5524 if (pool_index >= rte_atomic16_read(&cont->n_valid)) {
5529 sh->cmng.batch = batch;
5530 sh->cmng.pool_index = pool_index;
5531 mlx5_set_query_alarm(sh);
5535 * Handler for the HW respond about ready values from an asynchronous batch
5536 * query. This function is probably called by the host thread.
5539 * The pointer to the shared IB device context.
5540 * @param[in] async_id
5541 * The Devx async ID.
5543 * The status of the completion.
5546 mlx5_flow_async_pool_query_handle(struct mlx5_ibv_shared *sh,
5547 uint64_t async_id, int status)
5549 struct mlx5_flow_counter_pool *pool =
5550 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
5551 struct mlx5_counter_stats_raw *raw_to_free;
5553 if (unlikely(status)) {
5554 raw_to_free = pool->raw_hw;
5556 raw_to_free = pool->raw;
5557 rte_spinlock_lock(&pool->sl);
5558 pool->raw = pool->raw_hw;
5559 rte_spinlock_unlock(&pool->sl);
5560 rte_atomic64_add(&pool->query_gen, 1);
5561 /* Be sure the new raw counters data is updated in memory. */
5564 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
5565 pool->raw_hw = NULL;
5566 sh->cmng.pending_queries--;
5570 * Translate the rte_flow group index to HW table value.
5572 * @param[in] attributes
5573 * Pointer to flow attributes
5574 * @param[in] external
5575 * Value is part of flow rule created by request external to PMD.
5577 * rte_flow group index value.
5581 * Pointer to error structure.
5584 * 0 on success, a negative errno value otherwise and rte_errno is set.
5587 mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, bool external,
5588 uint32_t group, uint32_t *table,
5589 struct rte_flow_error *error)
5591 if (attributes->transfer && external) {
5592 if (group == UINT32_MAX)
5593 return rte_flow_error_set
5595 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5597 "group index not supported");
5606 * Discover availability of metadata reg_c's.
5608 * Iteratively use test flows to check availability.
5611 * Pointer to the Ethernet device structure.
5614 * 0 on success, a negative errno value otherwise and rte_errno is set.
5617 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
5619 struct mlx5_priv *priv = dev->data->dev_private;
5620 struct mlx5_dev_config *config = &priv->config;
5621 enum modify_reg idx;
5624 /* reg_c[0] and reg_c[1] are reserved. */
5625 config->flow_mreg_c[n++] = REG_C_0;
5626 config->flow_mreg_c[n++] = REG_C_1;
5627 /* Discover availability of other reg_c's. */
5628 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
5629 struct rte_flow_attr attr = {
5630 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5631 .priority = MLX5_FLOW_PRIO_RSVD,
5634 struct rte_flow_item items[] = {
5636 .type = RTE_FLOW_ITEM_TYPE_END,
5639 struct rte_flow_action actions[] = {
5641 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5642 .conf = &(struct mlx5_flow_action_copy_mreg){
5648 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5649 .conf = &(struct rte_flow_action_jump){
5650 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5654 .type = RTE_FLOW_ACTION_TYPE_END,
5657 struct rte_flow *flow;
5658 struct rte_flow_error error;
5660 if (!config->dv_flow_en)
5662 /* Create internal flow, validation skips copy action. */
5663 flow = flow_list_create(dev, NULL, &attr, items,
5664 actions, false, &error);
5667 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
5668 config->flow_mreg_c[n++] = idx;
5669 flow_list_destroy(dev, NULL, flow);
5671 for (; n < MLX5_MREG_C_NUM; ++n)
5672 config->flow_mreg_c[n] = REG_NONE;
5677 * Dump flow raw hw data to file
5680 * The pointer to Ethernet device.
5682 * A pointer to a file for output.
5684 * Perform verbose error reporting if not NULL. PMDs initialize this
5685 * structure in case of error only.
5687 * 0 on success, a nagative value otherwise.
5690 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
5692 struct rte_flow_error *error __rte_unused)
5694 struct mlx5_priv *priv = dev->data->dev_private;
5696 return mlx5_devx_cmd_flow_dump(priv->sh, file);