1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
6 #include <netinet/in.h>
13 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
15 #pragma GCC diagnostic ignored "-Wpedantic"
17 #include <infiniband/verbs.h>
19 #pragma GCC diagnostic error "-Wpedantic"
22 #include <rte_common.h>
23 #include <rte_ether.h>
24 #include <rte_ethdev_driver.h>
26 #include <rte_flow_driver.h>
27 #include <rte_malloc.h>
31 #include "mlx5_defs.h"
32 #include "mlx5_flow.h"
33 #include "mlx5_glue.h"
35 #include "mlx5_rxtx.h"
37 /* Dev ops structure defined in mlx5.c */
38 extern const struct eth_dev_ops mlx5_dev_ops;
39 extern const struct eth_dev_ops mlx5_dev_ops_isolate;
41 /** Device flow drivers. */
42 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
43 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
45 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
47 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
49 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
50 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
51 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
52 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
54 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
55 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
60 MLX5_EXPANSION_ROOT_OUTER,
61 MLX5_EXPANSION_ROOT_ETH_VLAN,
62 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
63 MLX5_EXPANSION_OUTER_ETH,
64 MLX5_EXPANSION_OUTER_ETH_VLAN,
65 MLX5_EXPANSION_OUTER_VLAN,
66 MLX5_EXPANSION_OUTER_IPV4,
67 MLX5_EXPANSION_OUTER_IPV4_UDP,
68 MLX5_EXPANSION_OUTER_IPV4_TCP,
69 MLX5_EXPANSION_OUTER_IPV6,
70 MLX5_EXPANSION_OUTER_IPV6_UDP,
71 MLX5_EXPANSION_OUTER_IPV6_TCP,
73 MLX5_EXPANSION_VXLAN_GPE,
77 MLX5_EXPANSION_ETH_VLAN,
80 MLX5_EXPANSION_IPV4_UDP,
81 MLX5_EXPANSION_IPV4_TCP,
83 MLX5_EXPANSION_IPV6_UDP,
84 MLX5_EXPANSION_IPV6_TCP,
87 /** Supported expansion of items. */
88 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
89 [MLX5_EXPANSION_ROOT] = {
90 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
93 .type = RTE_FLOW_ITEM_TYPE_END,
95 [MLX5_EXPANSION_ROOT_OUTER] = {
96 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
97 MLX5_EXPANSION_OUTER_IPV4,
98 MLX5_EXPANSION_OUTER_IPV6),
99 .type = RTE_FLOW_ITEM_TYPE_END,
101 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
102 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
103 .type = RTE_FLOW_ITEM_TYPE_END,
105 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
106 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
107 .type = RTE_FLOW_ITEM_TYPE_END,
109 [MLX5_EXPANSION_OUTER_ETH] = {
110 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
111 MLX5_EXPANSION_OUTER_IPV6,
112 MLX5_EXPANSION_MPLS),
113 .type = RTE_FLOW_ITEM_TYPE_ETH,
116 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
117 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
118 .type = RTE_FLOW_ITEM_TYPE_ETH,
121 [MLX5_EXPANSION_OUTER_VLAN] = {
122 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
123 MLX5_EXPANSION_OUTER_IPV6),
124 .type = RTE_FLOW_ITEM_TYPE_VLAN,
126 [MLX5_EXPANSION_OUTER_IPV4] = {
127 .next = RTE_FLOW_EXPAND_RSS_NEXT
128 (MLX5_EXPANSION_OUTER_IPV4_UDP,
129 MLX5_EXPANSION_OUTER_IPV4_TCP,
132 MLX5_EXPANSION_IPV6),
133 .type = RTE_FLOW_ITEM_TYPE_IPV4,
134 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
135 ETH_RSS_NONFRAG_IPV4_OTHER,
137 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
138 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
139 MLX5_EXPANSION_VXLAN_GPE),
140 .type = RTE_FLOW_ITEM_TYPE_UDP,
141 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
143 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
144 .type = RTE_FLOW_ITEM_TYPE_TCP,
145 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
147 [MLX5_EXPANSION_OUTER_IPV6] = {
148 .next = RTE_FLOW_EXPAND_RSS_NEXT
149 (MLX5_EXPANSION_OUTER_IPV6_UDP,
150 MLX5_EXPANSION_OUTER_IPV6_TCP,
152 MLX5_EXPANSION_IPV6),
153 .type = RTE_FLOW_ITEM_TYPE_IPV6,
154 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
155 ETH_RSS_NONFRAG_IPV6_OTHER,
157 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
158 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
159 MLX5_EXPANSION_VXLAN_GPE),
160 .type = RTE_FLOW_ITEM_TYPE_UDP,
161 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
163 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
164 .type = RTE_FLOW_ITEM_TYPE_TCP,
165 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
167 [MLX5_EXPANSION_VXLAN] = {
168 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
169 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
171 [MLX5_EXPANSION_VXLAN_GPE] = {
172 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
174 MLX5_EXPANSION_IPV6),
175 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
177 [MLX5_EXPANSION_GRE] = {
178 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
179 .type = RTE_FLOW_ITEM_TYPE_GRE,
181 [MLX5_EXPANSION_MPLS] = {
182 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
183 MLX5_EXPANSION_IPV6),
184 .type = RTE_FLOW_ITEM_TYPE_MPLS,
186 [MLX5_EXPANSION_ETH] = {
187 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
188 MLX5_EXPANSION_IPV6),
189 .type = RTE_FLOW_ITEM_TYPE_ETH,
191 [MLX5_EXPANSION_ETH_VLAN] = {
192 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
193 .type = RTE_FLOW_ITEM_TYPE_ETH,
195 [MLX5_EXPANSION_VLAN] = {
196 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
197 MLX5_EXPANSION_IPV6),
198 .type = RTE_FLOW_ITEM_TYPE_VLAN,
200 [MLX5_EXPANSION_IPV4] = {
201 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
202 MLX5_EXPANSION_IPV4_TCP),
203 .type = RTE_FLOW_ITEM_TYPE_IPV4,
204 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
205 ETH_RSS_NONFRAG_IPV4_OTHER,
207 [MLX5_EXPANSION_IPV4_UDP] = {
208 .type = RTE_FLOW_ITEM_TYPE_UDP,
209 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
211 [MLX5_EXPANSION_IPV4_TCP] = {
212 .type = RTE_FLOW_ITEM_TYPE_TCP,
213 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
215 [MLX5_EXPANSION_IPV6] = {
216 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
217 MLX5_EXPANSION_IPV6_TCP),
218 .type = RTE_FLOW_ITEM_TYPE_IPV6,
219 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
220 ETH_RSS_NONFRAG_IPV6_OTHER,
222 [MLX5_EXPANSION_IPV6_UDP] = {
223 .type = RTE_FLOW_ITEM_TYPE_UDP,
224 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
226 [MLX5_EXPANSION_IPV6_TCP] = {
227 .type = RTE_FLOW_ITEM_TYPE_TCP,
228 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
232 static const struct rte_flow_ops mlx5_flow_ops = {
233 .validate = mlx5_flow_validate,
234 .create = mlx5_flow_create,
235 .destroy = mlx5_flow_destroy,
236 .flush = mlx5_flow_flush,
237 .isolate = mlx5_flow_isolate,
238 .query = mlx5_flow_query,
241 /* Convert FDIR request to Generic flow. */
243 struct rte_flow_attr attr;
244 struct rte_flow_item items[4];
245 struct rte_flow_item_eth l2;
246 struct rte_flow_item_eth l2_mask;
248 struct rte_flow_item_ipv4 ipv4;
249 struct rte_flow_item_ipv6 ipv6;
252 struct rte_flow_item_ipv4 ipv4;
253 struct rte_flow_item_ipv6 ipv6;
256 struct rte_flow_item_udp udp;
257 struct rte_flow_item_tcp tcp;
260 struct rte_flow_item_udp udp;
261 struct rte_flow_item_tcp tcp;
263 struct rte_flow_action actions[2];
264 struct rte_flow_action_queue queue;
267 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
268 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
269 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
272 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
273 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
274 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
275 { 9, 10, 11 }, { 12, 13, 14 },
278 /* Tunnel information. */
279 struct mlx5_flow_tunnel_info {
280 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
281 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
284 static struct mlx5_flow_tunnel_info tunnels_info[] = {
286 .tunnel = MLX5_FLOW_LAYER_VXLAN,
287 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
290 .tunnel = MLX5_FLOW_LAYER_GENEVE,
291 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
294 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
295 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
298 .tunnel = MLX5_FLOW_LAYER_GRE,
299 .ptype = RTE_PTYPE_TUNNEL_GRE,
302 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
303 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
306 .tunnel = MLX5_FLOW_LAYER_MPLS,
307 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
310 .tunnel = MLX5_FLOW_LAYER_NVGRE,
311 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
314 .tunnel = MLX5_FLOW_LAYER_IPIP,
315 .ptype = RTE_PTYPE_TUNNEL_IP,
318 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
319 .ptype = RTE_PTYPE_TUNNEL_IP,
324 * Translate tag ID to register.
327 * Pointer to the Ethernet device structure.
329 * The feature that request the register.
331 * The request register ID.
333 * Error description in case of any.
336 * The request register on success, a negative errno
337 * value otherwise and rte_errno is set.
340 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
341 enum mlx5_feature_name feature,
343 struct rte_flow_error *error)
345 struct mlx5_priv *priv = dev->data->dev_private;
346 struct mlx5_dev_config *config = &priv->config;
347 enum modify_reg start_reg;
350 case MLX5_HAIRPIN_RX:
352 case MLX5_HAIRPIN_TX:
354 case MLX5_METADATA_RX:
355 switch (config->dv_xmeta_en) {
356 case MLX5_XMETA_MODE_LEGACY:
358 case MLX5_XMETA_MODE_META16:
360 case MLX5_XMETA_MODE_META32:
364 case MLX5_METADATA_TX:
366 case MLX5_METADATA_FDB:
367 switch (config->dv_xmeta_en) {
368 case MLX5_XMETA_MODE_LEGACY:
370 case MLX5_XMETA_MODE_META16:
372 case MLX5_XMETA_MODE_META32:
377 switch (config->dv_xmeta_en) {
378 case MLX5_XMETA_MODE_LEGACY:
380 case MLX5_XMETA_MODE_META16:
382 case MLX5_XMETA_MODE_META32:
389 * Metadata COPY_MARK register using is in meter suffix sub
390 * flow while with meter. It's safe to share the same register.
392 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
394 RTE_ASSERT(priv->mtr_color_reg != REG_NONE);
395 return priv->mtr_color_reg;
398 * If meter is enable, it will engage two registers for color
399 * match and flow match. If meter color match is not using the
400 * REG_C_2, need to skip the REG_C_x be used by meter color
402 * If meter is disable, free to use all available registers.
404 if (priv->mtr_color_reg != REG_NONE)
405 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_3 :
409 if (id > (REG_C_7 - start_reg))
410 return rte_flow_error_set(error, EINVAL,
411 RTE_FLOW_ERROR_TYPE_ITEM,
412 NULL, "invalid tag id");
413 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NONE)
414 return rte_flow_error_set(error, ENOTSUP,
415 RTE_FLOW_ERROR_TYPE_ITEM,
416 NULL, "unsupported tag id");
418 * This case means meter is using the REG_C_x great than 2.
419 * Take care not to conflict with meter color REG_C_x.
420 * If the available index REG_C_y >= REG_C_x, skip the
423 if (start_reg == REG_C_3 && config->flow_mreg_c
424 [id + REG_C_3 - REG_C_0] >= priv->mtr_color_reg) {
425 if (config->flow_mreg_c[id + 1 + REG_C_3 - REG_C_0] !=
427 return config->flow_mreg_c
428 [id + 1 + REG_C_3 - REG_C_0];
429 return rte_flow_error_set(error, ENOTSUP,
430 RTE_FLOW_ERROR_TYPE_ITEM,
431 NULL, "unsupported tag id");
433 return config->flow_mreg_c[id + start_reg - REG_C_0];
436 return rte_flow_error_set(error, EINVAL,
437 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
438 NULL, "invalid feature name");
442 * Check extensive flow metadata register support.
445 * Pointer to rte_eth_dev structure.
448 * True if device supports extensive flow metadata register, otherwise false.
451 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
453 struct mlx5_priv *priv = dev->data->dev_private;
454 struct mlx5_dev_config *config = &priv->config;
457 * Having available reg_c can be regarded inclusively as supporting
458 * extensive flow metadata register, which could mean,
459 * - metadata register copy action by modify header.
460 * - 16 modify header actions is supported.
461 * - reg_c's are preserved across different domain (FDB and NIC) on
462 * packet loopback by flow lookup miss.
464 return config->flow_mreg_c[2] != REG_NONE;
468 * Discover the maximum number of priority available.
471 * Pointer to the Ethernet device structure.
474 * number of supported flow priority on success, a negative errno
475 * value otherwise and rte_errno is set.
478 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
480 struct mlx5_priv *priv = dev->data->dev_private;
482 struct ibv_flow_attr attr;
483 struct ibv_flow_spec_eth eth;
484 struct ibv_flow_spec_action_drop drop;
488 .port = (uint8_t)priv->ibv_port,
491 .type = IBV_FLOW_SPEC_ETH,
492 .size = sizeof(struct ibv_flow_spec_eth),
495 .size = sizeof(struct ibv_flow_spec_action_drop),
496 .type = IBV_FLOW_SPEC_ACTION_DROP,
499 struct ibv_flow *flow;
500 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
501 uint16_t vprio[] = { 8, 16 };
509 for (i = 0; i != RTE_DIM(vprio); i++) {
510 flow_attr.attr.priority = vprio[i] - 1;
511 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
514 claim_zero(mlx5_glue->destroy_flow(flow));
517 mlx5_hrxq_drop_release(dev);
520 priority = RTE_DIM(priority_map_3);
523 priority = RTE_DIM(priority_map_5);
528 "port %u verbs maximum priority: %d expected 8/16",
529 dev->data->port_id, priority);
532 DRV_LOG(INFO, "port %u flow maximum priority: %d",
533 dev->data->port_id, priority);
538 * Adjust flow priority based on the highest layer and the request priority.
541 * Pointer to the Ethernet device structure.
542 * @param[in] priority
543 * The rule base priority.
544 * @param[in] subpriority
545 * The priority based on the items.
550 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
551 uint32_t subpriority)
554 struct mlx5_priv *priv = dev->data->dev_private;
556 switch (priv->config.flow_prio) {
557 case RTE_DIM(priority_map_3):
558 res = priority_map_3[priority][subpriority];
560 case RTE_DIM(priority_map_5):
561 res = priority_map_5[priority][subpriority];
568 * Verify the @p item specifications (spec, last, mask) are compatible with the
572 * Item specification.
574 * @p item->mask or flow default bit-masks.
575 * @param[in] nic_mask
576 * Bit-masks covering supported fields by the NIC to compare with user mask.
578 * Bit-masks size in bytes.
580 * Pointer to error structure.
583 * 0 on success, a negative errno value otherwise and rte_errno is set.
586 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
588 const uint8_t *nic_mask,
590 struct rte_flow_error *error)
595 for (i = 0; i < size; ++i)
596 if ((nic_mask[i] | mask[i]) != nic_mask[i])
597 return rte_flow_error_set(error, ENOTSUP,
598 RTE_FLOW_ERROR_TYPE_ITEM,
600 "mask enables non supported"
602 if (!item->spec && (item->mask || item->last))
603 return rte_flow_error_set(error, EINVAL,
604 RTE_FLOW_ERROR_TYPE_ITEM, item,
605 "mask/last without a spec is not"
607 if (item->spec && item->last) {
613 for (i = 0; i < size; ++i) {
614 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
615 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
617 ret = memcmp(spec, last, size);
619 return rte_flow_error_set(error, EINVAL,
620 RTE_FLOW_ERROR_TYPE_ITEM,
622 "range is not valid");
628 * Adjust the hash fields according to the @p flow information.
630 * @param[in] dev_flow.
631 * Pointer to the mlx5_flow.
633 * 1 when the hash field is for a tunnel item.
634 * @param[in] layer_types
636 * @param[in] hash_fields
640 * The hash fields that should be used.
643 mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow,
644 int tunnel __rte_unused, uint64_t layer_types,
645 uint64_t hash_fields)
647 struct rte_flow *flow = dev_flow->flow;
648 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
649 int rss_request_inner = flow->rss.level >= 2;
651 /* Check RSS hash level for tunnel. */
652 if (tunnel && rss_request_inner)
653 hash_fields |= IBV_RX_HASH_INNER;
654 else if (tunnel || rss_request_inner)
657 /* Check if requested layer matches RSS hash fields. */
658 if (!(flow->rss.types & layer_types))
664 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
665 * if several tunnel rules are used on this queue, the tunnel ptype will be
669 * Rx queue to update.
672 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
675 uint32_t tunnel_ptype = 0;
677 /* Look up for the ptype to use. */
678 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
679 if (!rxq_ctrl->flow_tunnels_n[i])
682 tunnel_ptype = tunnels_info[i].ptype;
688 rxq_ctrl->rxq.tunnel = tunnel_ptype;
692 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
696 * Pointer to the Ethernet device structure.
697 * @param[in] dev_flow
698 * Pointer to device flow structure.
701 flow_drv_rxq_flags_set(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
703 struct mlx5_priv *priv = dev->data->dev_private;
704 struct rte_flow *flow = dev_flow->flow;
705 const int mark = !!(dev_flow->actions &
706 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
707 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
710 for (i = 0; i != flow->rss.queue_num; ++i) {
711 int idx = (*flow->rss.queue)[i];
712 struct mlx5_rxq_ctrl *rxq_ctrl =
713 container_of((*priv->rxqs)[idx],
714 struct mlx5_rxq_ctrl, rxq);
717 * To support metadata register copy on Tx loopback,
718 * this must be always enabled (metadata may arive
719 * from other port - not from local flows only.
721 if (priv->config.dv_flow_en &&
722 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
723 mlx5_flow_ext_mreg_supported(dev)) {
724 rxq_ctrl->rxq.mark = 1;
725 rxq_ctrl->flow_mark_n = 1;
727 rxq_ctrl->rxq.mark = 1;
728 rxq_ctrl->flow_mark_n++;
733 /* Increase the counter matching the flow. */
734 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
735 if ((tunnels_info[j].tunnel &
737 tunnels_info[j].tunnel) {
738 rxq_ctrl->flow_tunnels_n[j]++;
742 flow_rxq_tunnel_ptype_update(rxq_ctrl);
748 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
751 * Pointer to the Ethernet device structure.
753 * Pointer to flow structure.
756 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
758 struct mlx5_flow *dev_flow;
760 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
761 flow_drv_rxq_flags_set(dev, dev_flow);
765 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
766 * device flow if no other flow uses it with the same kind of request.
769 * Pointer to Ethernet device.
770 * @param[in] dev_flow
771 * Pointer to the device flow.
774 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
776 struct mlx5_priv *priv = dev->data->dev_private;
777 struct rte_flow *flow = dev_flow->flow;
778 const int mark = !!(dev_flow->actions &
779 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
780 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
783 assert(dev->data->dev_started);
784 for (i = 0; i != flow->rss.queue_num; ++i) {
785 int idx = (*flow->rss.queue)[i];
786 struct mlx5_rxq_ctrl *rxq_ctrl =
787 container_of((*priv->rxqs)[idx],
788 struct mlx5_rxq_ctrl, rxq);
790 if (priv->config.dv_flow_en &&
791 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
792 mlx5_flow_ext_mreg_supported(dev)) {
793 rxq_ctrl->rxq.mark = 1;
794 rxq_ctrl->flow_mark_n = 1;
796 rxq_ctrl->flow_mark_n--;
797 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
802 /* Decrease the counter matching the flow. */
803 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
804 if ((tunnels_info[j].tunnel &
806 tunnels_info[j].tunnel) {
807 rxq_ctrl->flow_tunnels_n[j]--;
811 flow_rxq_tunnel_ptype_update(rxq_ctrl);
817 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
818 * @p flow if no other flow uses it with the same kind of request.
821 * Pointer to Ethernet device.
823 * Pointer to the flow.
826 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
828 struct mlx5_flow *dev_flow;
830 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
831 flow_drv_rxq_flags_trim(dev, dev_flow);
835 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
838 * Pointer to Ethernet device.
841 flow_rxq_flags_clear(struct rte_eth_dev *dev)
843 struct mlx5_priv *priv = dev->data->dev_private;
846 for (i = 0; i != priv->rxqs_n; ++i) {
847 struct mlx5_rxq_ctrl *rxq_ctrl;
850 if (!(*priv->rxqs)[i])
852 rxq_ctrl = container_of((*priv->rxqs)[i],
853 struct mlx5_rxq_ctrl, rxq);
854 rxq_ctrl->flow_mark_n = 0;
855 rxq_ctrl->rxq.mark = 0;
856 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
857 rxq_ctrl->flow_tunnels_n[j] = 0;
858 rxq_ctrl->rxq.tunnel = 0;
863 * return a pointer to the desired action in the list of actions.
866 * The list of actions to search the action in.
868 * The action to find.
871 * Pointer to the action in the list, if found. NULL otherwise.
873 const struct rte_flow_action *
874 mlx5_flow_find_action(const struct rte_flow_action *actions,
875 enum rte_flow_action_type action)
879 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
880 if (actions->type == action)
886 * Validate the flag action.
888 * @param[in] action_flags
889 * Bit-fields that holds the actions detected until now.
891 * Attributes of flow that includes this action.
893 * Pointer to error structure.
896 * 0 on success, a negative errno value otherwise and rte_errno is set.
899 mlx5_flow_validate_action_flag(uint64_t action_flags,
900 const struct rte_flow_attr *attr,
901 struct rte_flow_error *error)
904 if (action_flags & MLX5_FLOW_ACTION_DROP)
905 return rte_flow_error_set(error, EINVAL,
906 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
907 "can't drop and flag in same flow");
908 if (action_flags & MLX5_FLOW_ACTION_MARK)
909 return rte_flow_error_set(error, EINVAL,
910 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
911 "can't mark and flag in same flow");
912 if (action_flags & MLX5_FLOW_ACTION_FLAG)
913 return rte_flow_error_set(error, EINVAL,
914 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
916 " actions in same flow");
918 return rte_flow_error_set(error, ENOTSUP,
919 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
920 "flag action not supported for "
926 * Validate the mark action.
929 * Pointer to the queue action.
930 * @param[in] action_flags
931 * Bit-fields that holds the actions detected until now.
933 * Attributes of flow that includes this action.
935 * Pointer to error structure.
938 * 0 on success, a negative errno value otherwise and rte_errno is set.
941 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
942 uint64_t action_flags,
943 const struct rte_flow_attr *attr,
944 struct rte_flow_error *error)
946 const struct rte_flow_action_mark *mark = action->conf;
949 return rte_flow_error_set(error, EINVAL,
950 RTE_FLOW_ERROR_TYPE_ACTION,
952 "configuration cannot be null");
953 if (mark->id >= MLX5_FLOW_MARK_MAX)
954 return rte_flow_error_set(error, EINVAL,
955 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
957 "mark id must in 0 <= id < "
958 RTE_STR(MLX5_FLOW_MARK_MAX));
959 if (action_flags & MLX5_FLOW_ACTION_DROP)
960 return rte_flow_error_set(error, EINVAL,
961 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
962 "can't drop and mark in same flow");
963 if (action_flags & MLX5_FLOW_ACTION_FLAG)
964 return rte_flow_error_set(error, EINVAL,
965 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
966 "can't flag and mark in same flow");
967 if (action_flags & MLX5_FLOW_ACTION_MARK)
968 return rte_flow_error_set(error, EINVAL,
969 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
970 "can't have 2 mark actions in same"
973 return rte_flow_error_set(error, ENOTSUP,
974 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
975 "mark action not supported for "
981 * Validate the drop action.
983 * @param[in] action_flags
984 * Bit-fields that holds the actions detected until now.
986 * Attributes of flow that includes this action.
988 * Pointer to error structure.
991 * 0 on success, a negative errno value otherwise and rte_errno is set.
994 mlx5_flow_validate_action_drop(uint64_t action_flags,
995 const struct rte_flow_attr *attr,
996 struct rte_flow_error *error)
998 if (action_flags & MLX5_FLOW_ACTION_FLAG)
999 return rte_flow_error_set(error, EINVAL,
1000 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1001 "can't drop and flag in same flow");
1002 if (action_flags & MLX5_FLOW_ACTION_MARK)
1003 return rte_flow_error_set(error, EINVAL,
1004 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1005 "can't drop and mark in same flow");
1006 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
1007 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
1008 return rte_flow_error_set(error, EINVAL,
1009 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1010 "can't have 2 fate actions in"
1013 return rte_flow_error_set(error, ENOTSUP,
1014 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1015 "drop action not supported for "
1021 * Validate the queue action.
1024 * Pointer to the queue action.
1025 * @param[in] action_flags
1026 * Bit-fields that holds the actions detected until now.
1028 * Pointer to the Ethernet device structure.
1030 * Attributes of flow that includes this action.
1032 * Pointer to error structure.
1035 * 0 on success, a negative errno value otherwise and rte_errno is set.
1038 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1039 uint64_t action_flags,
1040 struct rte_eth_dev *dev,
1041 const struct rte_flow_attr *attr,
1042 struct rte_flow_error *error)
1044 struct mlx5_priv *priv = dev->data->dev_private;
1045 const struct rte_flow_action_queue *queue = action->conf;
1047 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1048 return rte_flow_error_set(error, EINVAL,
1049 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1050 "can't have 2 fate actions in"
1053 return rte_flow_error_set(error, EINVAL,
1054 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1055 NULL, "No Rx queues configured");
1056 if (queue->index >= priv->rxqs_n)
1057 return rte_flow_error_set(error, EINVAL,
1058 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1060 "queue index out of range");
1061 if (!(*priv->rxqs)[queue->index])
1062 return rte_flow_error_set(error, EINVAL,
1063 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1065 "queue is not configured");
1067 return rte_flow_error_set(error, ENOTSUP,
1068 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1069 "queue action not supported for "
1075 * Validate the rss action.
1078 * Pointer to the queue action.
1079 * @param[in] action_flags
1080 * Bit-fields that holds the actions detected until now.
1082 * Pointer to the Ethernet device structure.
1084 * Attributes of flow that includes this action.
1085 * @param[in] item_flags
1086 * Items that were detected.
1088 * Pointer to error structure.
1091 * 0 on success, a negative errno value otherwise and rte_errno is set.
1094 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1095 uint64_t action_flags,
1096 struct rte_eth_dev *dev,
1097 const struct rte_flow_attr *attr,
1098 uint64_t item_flags,
1099 struct rte_flow_error *error)
1101 struct mlx5_priv *priv = dev->data->dev_private;
1102 const struct rte_flow_action_rss *rss = action->conf;
1103 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1106 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1107 return rte_flow_error_set(error, EINVAL,
1108 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1109 "can't have 2 fate actions"
1111 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1112 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1113 return rte_flow_error_set(error, ENOTSUP,
1114 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1116 "RSS hash function not supported");
1117 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1122 return rte_flow_error_set(error, ENOTSUP,
1123 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1125 "tunnel RSS is not supported");
1126 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1127 if (rss->key_len == 0 && rss->key != NULL)
1128 return rte_flow_error_set(error, ENOTSUP,
1129 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1131 "RSS hash key length 0");
1132 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1133 return rte_flow_error_set(error, ENOTSUP,
1134 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1136 "RSS hash key too small");
1137 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1138 return rte_flow_error_set(error, ENOTSUP,
1139 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1141 "RSS hash key too large");
1142 if (rss->queue_num > priv->config.ind_table_max_size)
1143 return rte_flow_error_set(error, ENOTSUP,
1144 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1146 "number of queues too large");
1147 if (rss->types & MLX5_RSS_HF_MASK)
1148 return rte_flow_error_set(error, ENOTSUP,
1149 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1151 "some RSS protocols are not"
1154 return rte_flow_error_set(error, EINVAL,
1155 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1156 NULL, "No Rx queues configured");
1157 if (!rss->queue_num)
1158 return rte_flow_error_set(error, EINVAL,
1159 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1160 NULL, "No queues configured");
1161 for (i = 0; i != rss->queue_num; ++i) {
1162 if (rss->queue[i] >= priv->rxqs_n)
1163 return rte_flow_error_set
1165 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1166 &rss->queue[i], "queue index out of range");
1167 if (!(*priv->rxqs)[rss->queue[i]])
1168 return rte_flow_error_set
1169 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1170 &rss->queue[i], "queue is not configured");
1173 return rte_flow_error_set(error, ENOTSUP,
1174 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1175 "rss action not supported for "
1177 if (rss->level > 1 && !tunnel)
1178 return rte_flow_error_set(error, EINVAL,
1179 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1180 "inner RSS is not supported for "
1181 "non-tunnel flows");
1186 * Validate the count action.
1189 * Pointer to the Ethernet device structure.
1191 * Attributes of flow that includes this action.
1193 * Pointer to error structure.
1196 * 0 on success, a negative errno value otherwise and rte_errno is set.
1199 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1200 const struct rte_flow_attr *attr,
1201 struct rte_flow_error *error)
1204 return rte_flow_error_set(error, ENOTSUP,
1205 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1206 "count action not supported for "
1212 * Verify the @p attributes will be correctly understood by the NIC and store
1213 * them in the @p flow if everything is correct.
1216 * Pointer to the Ethernet device structure.
1217 * @param[in] attributes
1218 * Pointer to flow attributes
1220 * Pointer to error structure.
1223 * 0 on success, a negative errno value otherwise and rte_errno is set.
1226 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1227 const struct rte_flow_attr *attributes,
1228 struct rte_flow_error *error)
1230 struct mlx5_priv *priv = dev->data->dev_private;
1231 uint32_t priority_max = priv->config.flow_prio - 1;
1233 if (attributes->group)
1234 return rte_flow_error_set(error, ENOTSUP,
1235 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1236 NULL, "groups is not supported");
1237 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1238 attributes->priority >= priority_max)
1239 return rte_flow_error_set(error, ENOTSUP,
1240 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1241 NULL, "priority out of range");
1242 if (attributes->egress)
1243 return rte_flow_error_set(error, ENOTSUP,
1244 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1245 "egress is not supported");
1246 if (attributes->transfer && !priv->config.dv_esw_en)
1247 return rte_flow_error_set(error, ENOTSUP,
1248 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1249 NULL, "transfer is not supported");
1250 if (!attributes->ingress)
1251 return rte_flow_error_set(error, EINVAL,
1252 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1254 "ingress attribute is mandatory");
1259 * Validate ICMP6 item.
1262 * Item specification.
1263 * @param[in] item_flags
1264 * Bit-fields that holds the items detected until now.
1266 * Pointer to error structure.
1269 * 0 on success, a negative errno value otherwise and rte_errno is set.
1272 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1273 uint64_t item_flags,
1274 uint8_t target_protocol,
1275 struct rte_flow_error *error)
1277 const struct rte_flow_item_icmp6 *mask = item->mask;
1278 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1279 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1280 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1281 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1282 MLX5_FLOW_LAYER_OUTER_L4;
1285 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1286 return rte_flow_error_set(error, EINVAL,
1287 RTE_FLOW_ERROR_TYPE_ITEM, item,
1288 "protocol filtering not compatible"
1289 " with ICMP6 layer");
1290 if (!(item_flags & l3m))
1291 return rte_flow_error_set(error, EINVAL,
1292 RTE_FLOW_ERROR_TYPE_ITEM, item,
1293 "IPv6 is mandatory to filter on"
1295 if (item_flags & l4m)
1296 return rte_flow_error_set(error, EINVAL,
1297 RTE_FLOW_ERROR_TYPE_ITEM, item,
1298 "multiple L4 layers not supported");
1300 mask = &rte_flow_item_icmp6_mask;
1301 ret = mlx5_flow_item_acceptable
1302 (item, (const uint8_t *)mask,
1303 (const uint8_t *)&rte_flow_item_icmp6_mask,
1304 sizeof(struct rte_flow_item_icmp6), error);
1311 * Validate ICMP item.
1314 * Item specification.
1315 * @param[in] item_flags
1316 * Bit-fields that holds the items detected until now.
1318 * Pointer to error structure.
1321 * 0 on success, a negative errno value otherwise and rte_errno is set.
1324 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1325 uint64_t item_flags,
1326 uint8_t target_protocol,
1327 struct rte_flow_error *error)
1329 const struct rte_flow_item_icmp *mask = item->mask;
1330 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1331 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1332 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1333 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1334 MLX5_FLOW_LAYER_OUTER_L4;
1337 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1338 return rte_flow_error_set(error, EINVAL,
1339 RTE_FLOW_ERROR_TYPE_ITEM, item,
1340 "protocol filtering not compatible"
1341 " with ICMP layer");
1342 if (!(item_flags & l3m))
1343 return rte_flow_error_set(error, EINVAL,
1344 RTE_FLOW_ERROR_TYPE_ITEM, item,
1345 "IPv4 is mandatory to filter"
1347 if (item_flags & l4m)
1348 return rte_flow_error_set(error, EINVAL,
1349 RTE_FLOW_ERROR_TYPE_ITEM, item,
1350 "multiple L4 layers not supported");
1352 mask = &rte_flow_item_icmp_mask;
1353 ret = mlx5_flow_item_acceptable
1354 (item, (const uint8_t *)mask,
1355 (const uint8_t *)&rte_flow_item_icmp_mask,
1356 sizeof(struct rte_flow_item_icmp), error);
1363 * Validate Ethernet item.
1366 * Item specification.
1367 * @param[in] item_flags
1368 * Bit-fields that holds the items detected until now.
1370 * Pointer to error structure.
1373 * 0 on success, a negative errno value otherwise and rte_errno is set.
1376 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1377 uint64_t item_flags,
1378 struct rte_flow_error *error)
1380 const struct rte_flow_item_eth *mask = item->mask;
1381 const struct rte_flow_item_eth nic_mask = {
1382 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1383 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1384 .type = RTE_BE16(0xffff),
1387 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1388 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1389 MLX5_FLOW_LAYER_OUTER_L2;
1391 if (item_flags & ethm)
1392 return rte_flow_error_set(error, ENOTSUP,
1393 RTE_FLOW_ERROR_TYPE_ITEM, item,
1394 "multiple L2 layers not supported");
1395 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1396 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1397 return rte_flow_error_set(error, EINVAL,
1398 RTE_FLOW_ERROR_TYPE_ITEM, item,
1399 "L2 layer should not follow "
1401 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1402 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1403 return rte_flow_error_set(error, EINVAL,
1404 RTE_FLOW_ERROR_TYPE_ITEM, item,
1405 "L2 layer should not follow VLAN");
1407 mask = &rte_flow_item_eth_mask;
1408 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1409 (const uint8_t *)&nic_mask,
1410 sizeof(struct rte_flow_item_eth),
1416 * Validate VLAN item.
1419 * Item specification.
1420 * @param[in] item_flags
1421 * Bit-fields that holds the items detected until now.
1423 * Ethernet device flow is being created on.
1425 * Pointer to error structure.
1428 * 0 on success, a negative errno value otherwise and rte_errno is set.
1431 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1432 uint64_t item_flags,
1433 struct rte_eth_dev *dev,
1434 struct rte_flow_error *error)
1436 const struct rte_flow_item_vlan *spec = item->spec;
1437 const struct rte_flow_item_vlan *mask = item->mask;
1438 const struct rte_flow_item_vlan nic_mask = {
1439 .tci = RTE_BE16(UINT16_MAX),
1440 .inner_type = RTE_BE16(UINT16_MAX),
1442 uint16_t vlan_tag = 0;
1443 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1445 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1446 MLX5_FLOW_LAYER_INNER_L4) :
1447 (MLX5_FLOW_LAYER_OUTER_L3 |
1448 MLX5_FLOW_LAYER_OUTER_L4);
1449 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1450 MLX5_FLOW_LAYER_OUTER_VLAN;
1452 if (item_flags & vlanm)
1453 return rte_flow_error_set(error, EINVAL,
1454 RTE_FLOW_ERROR_TYPE_ITEM, item,
1455 "multiple VLAN layers not supported");
1456 else if ((item_flags & l34m) != 0)
1457 return rte_flow_error_set(error, EINVAL,
1458 RTE_FLOW_ERROR_TYPE_ITEM, item,
1459 "VLAN cannot follow L3/L4 layer");
1461 mask = &rte_flow_item_vlan_mask;
1462 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1463 (const uint8_t *)&nic_mask,
1464 sizeof(struct rte_flow_item_vlan),
1468 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1469 struct mlx5_priv *priv = dev->data->dev_private;
1471 if (priv->vmwa_context) {
1473 * Non-NULL context means we have a virtual machine
1474 * and SR-IOV enabled, we have to create VLAN interface
1475 * to make hypervisor to setup E-Switch vport
1476 * context correctly. We avoid creating the multiple
1477 * VLAN interfaces, so we cannot support VLAN tag mask.
1479 return rte_flow_error_set(error, EINVAL,
1480 RTE_FLOW_ERROR_TYPE_ITEM,
1482 "VLAN tag mask is not"
1483 " supported in virtual"
1488 vlan_tag = spec->tci;
1489 vlan_tag &= mask->tci;
1492 * From verbs perspective an empty VLAN is equivalent
1493 * to a packet without VLAN layer.
1496 return rte_flow_error_set(error, EINVAL,
1497 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1499 "VLAN cannot be empty");
1504 * Validate IPV4 item.
1507 * Item specification.
1508 * @param[in] item_flags
1509 * Bit-fields that holds the items detected until now.
1510 * @param[in] acc_mask
1511 * Acceptable mask, if NULL default internal default mask
1512 * will be used to check whether item fields are supported.
1514 * Pointer to error structure.
1517 * 0 on success, a negative errno value otherwise and rte_errno is set.
1520 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1521 uint64_t item_flags,
1523 uint16_t ether_type,
1524 const struct rte_flow_item_ipv4 *acc_mask,
1525 struct rte_flow_error *error)
1527 const struct rte_flow_item_ipv4 *mask = item->mask;
1528 const struct rte_flow_item_ipv4 *spec = item->spec;
1529 const struct rte_flow_item_ipv4 nic_mask = {
1531 .src_addr = RTE_BE32(0xffffffff),
1532 .dst_addr = RTE_BE32(0xffffffff),
1533 .type_of_service = 0xff,
1534 .next_proto_id = 0xff,
1537 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1538 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1539 MLX5_FLOW_LAYER_OUTER_L3;
1540 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1541 MLX5_FLOW_LAYER_OUTER_L4;
1543 uint8_t next_proto = 0xFF;
1544 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1545 MLX5_FLOW_LAYER_OUTER_VLAN |
1546 MLX5_FLOW_LAYER_INNER_VLAN);
1548 if ((last_item & l2_vlan) && ether_type &&
1549 ether_type != RTE_ETHER_TYPE_IPV4)
1550 return rte_flow_error_set(error, EINVAL,
1551 RTE_FLOW_ERROR_TYPE_ITEM, item,
1552 "IPv4 cannot follow L2/VLAN layer "
1553 "which ether type is not IPv4");
1554 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1556 next_proto = mask->hdr.next_proto_id &
1557 spec->hdr.next_proto_id;
1558 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1559 return rte_flow_error_set(error, EINVAL,
1560 RTE_FLOW_ERROR_TYPE_ITEM,
1565 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1566 return rte_flow_error_set(error, EINVAL,
1567 RTE_FLOW_ERROR_TYPE_ITEM, item,
1568 "wrong tunnel type - IPv6 specified "
1569 "but IPv4 item provided");
1570 if (item_flags & l3m)
1571 return rte_flow_error_set(error, ENOTSUP,
1572 RTE_FLOW_ERROR_TYPE_ITEM, item,
1573 "multiple L3 layers not supported");
1574 else if (item_flags & l4m)
1575 return rte_flow_error_set(error, EINVAL,
1576 RTE_FLOW_ERROR_TYPE_ITEM, item,
1577 "L3 cannot follow an L4 layer.");
1578 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1579 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1580 return rte_flow_error_set(error, EINVAL,
1581 RTE_FLOW_ERROR_TYPE_ITEM, item,
1582 "L3 cannot follow an NVGRE layer.");
1584 mask = &rte_flow_item_ipv4_mask;
1585 else if (mask->hdr.next_proto_id != 0 &&
1586 mask->hdr.next_proto_id != 0xff)
1587 return rte_flow_error_set(error, EINVAL,
1588 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1589 "partial mask is not supported"
1591 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1592 acc_mask ? (const uint8_t *)acc_mask
1593 : (const uint8_t *)&nic_mask,
1594 sizeof(struct rte_flow_item_ipv4),
1602 * Validate IPV6 item.
1605 * Item specification.
1606 * @param[in] item_flags
1607 * Bit-fields that holds the items detected until now.
1608 * @param[in] acc_mask
1609 * Acceptable mask, if NULL default internal default mask
1610 * will be used to check whether item fields are supported.
1612 * Pointer to error structure.
1615 * 0 on success, a negative errno value otherwise and rte_errno is set.
1618 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1619 uint64_t item_flags,
1621 uint16_t ether_type,
1622 const struct rte_flow_item_ipv6 *acc_mask,
1623 struct rte_flow_error *error)
1625 const struct rte_flow_item_ipv6 *mask = item->mask;
1626 const struct rte_flow_item_ipv6 *spec = item->spec;
1627 const struct rte_flow_item_ipv6 nic_mask = {
1630 "\xff\xff\xff\xff\xff\xff\xff\xff"
1631 "\xff\xff\xff\xff\xff\xff\xff\xff",
1633 "\xff\xff\xff\xff\xff\xff\xff\xff"
1634 "\xff\xff\xff\xff\xff\xff\xff\xff",
1635 .vtc_flow = RTE_BE32(0xffffffff),
1640 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1641 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1642 MLX5_FLOW_LAYER_OUTER_L3;
1643 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1644 MLX5_FLOW_LAYER_OUTER_L4;
1646 uint8_t next_proto = 0xFF;
1647 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1648 MLX5_FLOW_LAYER_OUTER_VLAN |
1649 MLX5_FLOW_LAYER_INNER_VLAN);
1651 if ((last_item & l2_vlan) && ether_type &&
1652 ether_type != RTE_ETHER_TYPE_IPV6)
1653 return rte_flow_error_set(error, EINVAL,
1654 RTE_FLOW_ERROR_TYPE_ITEM, item,
1655 "IPv6 cannot follow L2/VLAN layer "
1656 "which ether type is not IPv6");
1657 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
1659 next_proto = mask->hdr.proto & spec->hdr.proto;
1660 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1661 return rte_flow_error_set(error, EINVAL,
1662 RTE_FLOW_ERROR_TYPE_ITEM,
1667 if (item_flags & MLX5_FLOW_LAYER_IPIP)
1668 return rte_flow_error_set(error, EINVAL,
1669 RTE_FLOW_ERROR_TYPE_ITEM, item,
1670 "wrong tunnel type - IPv4 specified "
1671 "but IPv6 item provided");
1672 if (item_flags & l3m)
1673 return rte_flow_error_set(error, ENOTSUP,
1674 RTE_FLOW_ERROR_TYPE_ITEM, item,
1675 "multiple L3 layers not supported");
1676 else if (item_flags & l4m)
1677 return rte_flow_error_set(error, EINVAL,
1678 RTE_FLOW_ERROR_TYPE_ITEM, item,
1679 "L3 cannot follow an L4 layer.");
1680 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1681 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1682 return rte_flow_error_set(error, EINVAL,
1683 RTE_FLOW_ERROR_TYPE_ITEM, item,
1684 "L3 cannot follow an NVGRE layer.");
1686 mask = &rte_flow_item_ipv6_mask;
1687 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1688 acc_mask ? (const uint8_t *)acc_mask
1689 : (const uint8_t *)&nic_mask,
1690 sizeof(struct rte_flow_item_ipv6),
1698 * Validate UDP item.
1701 * Item specification.
1702 * @param[in] item_flags
1703 * Bit-fields that holds the items detected until now.
1704 * @param[in] target_protocol
1705 * The next protocol in the previous item.
1706 * @param[in] flow_mask
1707 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
1709 * Pointer to error structure.
1712 * 0 on success, a negative errno value otherwise and rte_errno is set.
1715 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1716 uint64_t item_flags,
1717 uint8_t target_protocol,
1718 struct rte_flow_error *error)
1720 const struct rte_flow_item_udp *mask = item->mask;
1721 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1722 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1723 MLX5_FLOW_LAYER_OUTER_L3;
1724 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1725 MLX5_FLOW_LAYER_OUTER_L4;
1728 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1729 return rte_flow_error_set(error, EINVAL,
1730 RTE_FLOW_ERROR_TYPE_ITEM, item,
1731 "protocol filtering not compatible"
1733 if (!(item_flags & l3m))
1734 return rte_flow_error_set(error, EINVAL,
1735 RTE_FLOW_ERROR_TYPE_ITEM, item,
1736 "L3 is mandatory to filter on L4");
1737 if (item_flags & l4m)
1738 return rte_flow_error_set(error, EINVAL,
1739 RTE_FLOW_ERROR_TYPE_ITEM, item,
1740 "multiple L4 layers not supported");
1742 mask = &rte_flow_item_udp_mask;
1743 ret = mlx5_flow_item_acceptable
1744 (item, (const uint8_t *)mask,
1745 (const uint8_t *)&rte_flow_item_udp_mask,
1746 sizeof(struct rte_flow_item_udp), error);
1753 * Validate TCP item.
1756 * Item specification.
1757 * @param[in] item_flags
1758 * Bit-fields that holds the items detected until now.
1759 * @param[in] target_protocol
1760 * The next protocol in the previous item.
1762 * Pointer to error structure.
1765 * 0 on success, a negative errno value otherwise and rte_errno is set.
1768 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1769 uint64_t item_flags,
1770 uint8_t target_protocol,
1771 const struct rte_flow_item_tcp *flow_mask,
1772 struct rte_flow_error *error)
1774 const struct rte_flow_item_tcp *mask = item->mask;
1775 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1776 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1777 MLX5_FLOW_LAYER_OUTER_L3;
1778 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1779 MLX5_FLOW_LAYER_OUTER_L4;
1783 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1784 return rte_flow_error_set(error, EINVAL,
1785 RTE_FLOW_ERROR_TYPE_ITEM, item,
1786 "protocol filtering not compatible"
1788 if (!(item_flags & l3m))
1789 return rte_flow_error_set(error, EINVAL,
1790 RTE_FLOW_ERROR_TYPE_ITEM, item,
1791 "L3 is mandatory to filter on L4");
1792 if (item_flags & l4m)
1793 return rte_flow_error_set(error, EINVAL,
1794 RTE_FLOW_ERROR_TYPE_ITEM, item,
1795 "multiple L4 layers not supported");
1797 mask = &rte_flow_item_tcp_mask;
1798 ret = mlx5_flow_item_acceptable
1799 (item, (const uint8_t *)mask,
1800 (const uint8_t *)flow_mask,
1801 sizeof(struct rte_flow_item_tcp), error);
1808 * Validate VXLAN item.
1811 * Item specification.
1812 * @param[in] item_flags
1813 * Bit-fields that holds the items detected until now.
1814 * @param[in] target_protocol
1815 * The next protocol in the previous item.
1817 * Pointer to error structure.
1820 * 0 on success, a negative errno value otherwise and rte_errno is set.
1823 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1824 uint64_t item_flags,
1825 struct rte_flow_error *error)
1827 const struct rte_flow_item_vxlan *spec = item->spec;
1828 const struct rte_flow_item_vxlan *mask = item->mask;
1833 } id = { .vlan_id = 0, };
1834 uint32_t vlan_id = 0;
1837 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1838 return rte_flow_error_set(error, ENOTSUP,
1839 RTE_FLOW_ERROR_TYPE_ITEM, item,
1840 "multiple tunnel layers not"
1843 * Verify only UDPv4 is present as defined in
1844 * https://tools.ietf.org/html/rfc7348
1846 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1847 return rte_flow_error_set(error, EINVAL,
1848 RTE_FLOW_ERROR_TYPE_ITEM, item,
1849 "no outer UDP layer found");
1851 mask = &rte_flow_item_vxlan_mask;
1852 ret = mlx5_flow_item_acceptable
1853 (item, (const uint8_t *)mask,
1854 (const uint8_t *)&rte_flow_item_vxlan_mask,
1855 sizeof(struct rte_flow_item_vxlan),
1860 memcpy(&id.vni[1], spec->vni, 3);
1861 vlan_id = id.vlan_id;
1862 memcpy(&id.vni[1], mask->vni, 3);
1863 vlan_id &= id.vlan_id;
1866 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1867 * only this layer is defined in the Verbs specification it is
1868 * interpreted as wildcard and all packets will match this
1869 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1870 * udp), all packets matching the layers before will also
1871 * match this rule. To avoid such situation, VNI 0 is
1872 * currently refused.
1875 return rte_flow_error_set(error, ENOTSUP,
1876 RTE_FLOW_ERROR_TYPE_ITEM, item,
1877 "VXLAN vni cannot be 0");
1878 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1879 return rte_flow_error_set(error, ENOTSUP,
1880 RTE_FLOW_ERROR_TYPE_ITEM, item,
1881 "VXLAN tunnel must be fully defined");
1886 * Validate VXLAN_GPE item.
1889 * Item specification.
1890 * @param[in] item_flags
1891 * Bit-fields that holds the items detected until now.
1893 * Pointer to the private data structure.
1894 * @param[in] target_protocol
1895 * The next protocol in the previous item.
1897 * Pointer to error structure.
1900 * 0 on success, a negative errno value otherwise and rte_errno is set.
1903 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1904 uint64_t item_flags,
1905 struct rte_eth_dev *dev,
1906 struct rte_flow_error *error)
1908 struct mlx5_priv *priv = dev->data->dev_private;
1909 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1910 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1915 } id = { .vlan_id = 0, };
1916 uint32_t vlan_id = 0;
1918 if (!priv->config.l3_vxlan_en)
1919 return rte_flow_error_set(error, ENOTSUP,
1920 RTE_FLOW_ERROR_TYPE_ITEM, item,
1921 "L3 VXLAN is not enabled by device"
1922 " parameter and/or not configured in"
1924 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1925 return rte_flow_error_set(error, ENOTSUP,
1926 RTE_FLOW_ERROR_TYPE_ITEM, item,
1927 "multiple tunnel layers not"
1930 * Verify only UDPv4 is present as defined in
1931 * https://tools.ietf.org/html/rfc7348
1933 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1934 return rte_flow_error_set(error, EINVAL,
1935 RTE_FLOW_ERROR_TYPE_ITEM, item,
1936 "no outer UDP layer found");
1938 mask = &rte_flow_item_vxlan_gpe_mask;
1939 ret = mlx5_flow_item_acceptable
1940 (item, (const uint8_t *)mask,
1941 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1942 sizeof(struct rte_flow_item_vxlan_gpe),
1948 return rte_flow_error_set(error, ENOTSUP,
1949 RTE_FLOW_ERROR_TYPE_ITEM,
1951 "VxLAN-GPE protocol"
1953 memcpy(&id.vni[1], spec->vni, 3);
1954 vlan_id = id.vlan_id;
1955 memcpy(&id.vni[1], mask->vni, 3);
1956 vlan_id &= id.vlan_id;
1959 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1960 * layer is defined in the Verbs specification it is interpreted as
1961 * wildcard and all packets will match this rule, if it follows a full
1962 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1963 * before will also match this rule. To avoid such situation, VNI 0
1964 * is currently refused.
1967 return rte_flow_error_set(error, ENOTSUP,
1968 RTE_FLOW_ERROR_TYPE_ITEM, item,
1969 "VXLAN-GPE vni cannot be 0");
1970 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1971 return rte_flow_error_set(error, ENOTSUP,
1972 RTE_FLOW_ERROR_TYPE_ITEM, item,
1973 "VXLAN-GPE tunnel must be fully"
1978 * Validate GRE Key item.
1981 * Item specification.
1982 * @param[in] item_flags
1983 * Bit flags to mark detected items.
1984 * @param[in] gre_item
1985 * Pointer to gre_item
1987 * Pointer to error structure.
1990 * 0 on success, a negative errno value otherwise and rte_errno is set.
1993 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
1994 uint64_t item_flags,
1995 const struct rte_flow_item *gre_item,
1996 struct rte_flow_error *error)
1998 const rte_be32_t *mask = item->mask;
2000 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2001 const struct rte_flow_item_gre *gre_spec;
2002 const struct rte_flow_item_gre *gre_mask;
2004 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2005 return rte_flow_error_set(error, ENOTSUP,
2006 RTE_FLOW_ERROR_TYPE_ITEM, item,
2007 "Multiple GRE key not support");
2008 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2009 return rte_flow_error_set(error, ENOTSUP,
2010 RTE_FLOW_ERROR_TYPE_ITEM, item,
2011 "No preceding GRE header");
2012 if (item_flags & MLX5_FLOW_LAYER_INNER)
2013 return rte_flow_error_set(error, ENOTSUP,
2014 RTE_FLOW_ERROR_TYPE_ITEM, item,
2015 "GRE key following a wrong item");
2016 gre_mask = gre_item->mask;
2018 gre_mask = &rte_flow_item_gre_mask;
2019 gre_spec = gre_item->spec;
2020 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2021 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2022 return rte_flow_error_set(error, EINVAL,
2023 RTE_FLOW_ERROR_TYPE_ITEM, item,
2024 "Key bit must be on");
2027 mask = &gre_key_default_mask;
2028 ret = mlx5_flow_item_acceptable
2029 (item, (const uint8_t *)mask,
2030 (const uint8_t *)&gre_key_default_mask,
2031 sizeof(rte_be32_t), error);
2036 * Validate GRE item.
2039 * Item specification.
2040 * @param[in] item_flags
2041 * Bit flags to mark detected items.
2042 * @param[in] target_protocol
2043 * The next protocol in the previous item.
2045 * Pointer to error structure.
2048 * 0 on success, a negative errno value otherwise and rte_errno is set.
2051 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2052 uint64_t item_flags,
2053 uint8_t target_protocol,
2054 struct rte_flow_error *error)
2056 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2057 const struct rte_flow_item_gre *mask = item->mask;
2059 const struct rte_flow_item_gre nic_mask = {
2060 .c_rsvd0_ver = RTE_BE16(0xB000),
2061 .protocol = RTE_BE16(UINT16_MAX),
2064 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2065 return rte_flow_error_set(error, EINVAL,
2066 RTE_FLOW_ERROR_TYPE_ITEM, item,
2067 "protocol filtering not compatible"
2068 " with this GRE layer");
2069 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2070 return rte_flow_error_set(error, ENOTSUP,
2071 RTE_FLOW_ERROR_TYPE_ITEM, item,
2072 "multiple tunnel layers not"
2074 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2075 return rte_flow_error_set(error, ENOTSUP,
2076 RTE_FLOW_ERROR_TYPE_ITEM, item,
2077 "L3 Layer is missing");
2079 mask = &rte_flow_item_gre_mask;
2080 ret = mlx5_flow_item_acceptable
2081 (item, (const uint8_t *)mask,
2082 (const uint8_t *)&nic_mask,
2083 sizeof(struct rte_flow_item_gre), error);
2086 #ifndef HAVE_MLX5DV_DR
2087 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2088 if (spec && (spec->protocol & mask->protocol))
2089 return rte_flow_error_set(error, ENOTSUP,
2090 RTE_FLOW_ERROR_TYPE_ITEM, item,
2091 "without MPLS support the"
2092 " specification cannot be used for"
2100 * Validate Geneve item.
2103 * Item specification.
2104 * @param[in] itemFlags
2105 * Bit-fields that holds the items detected until now.
2107 * Pointer to the private data structure.
2109 * Pointer to error structure.
2112 * 0 on success, a negative errno value otherwise and rte_errno is set.
2116 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2117 uint64_t item_flags,
2118 struct rte_eth_dev *dev,
2119 struct rte_flow_error *error)
2121 struct mlx5_priv *priv = dev->data->dev_private;
2122 const struct rte_flow_item_geneve *spec = item->spec;
2123 const struct rte_flow_item_geneve *mask = item->mask;
2126 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2127 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2128 const struct rte_flow_item_geneve nic_mask = {
2129 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2130 .vni = "\xff\xff\xff",
2131 .protocol = RTE_BE16(UINT16_MAX),
2134 if (!(priv->config.hca_attr.flex_parser_protocols &
2135 MLX5_HCA_FLEX_GENEVE_ENABLED) ||
2136 !priv->config.hca_attr.tunnel_stateless_geneve_rx)
2137 return rte_flow_error_set(error, ENOTSUP,
2138 RTE_FLOW_ERROR_TYPE_ITEM, item,
2139 "L3 Geneve is not enabled by device"
2140 " parameter and/or not configured in"
2142 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2143 return rte_flow_error_set(error, ENOTSUP,
2144 RTE_FLOW_ERROR_TYPE_ITEM, item,
2145 "multiple tunnel layers not"
2148 * Verify only UDPv4 is present as defined in
2149 * https://tools.ietf.org/html/rfc7348
2151 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2152 return rte_flow_error_set(error, EINVAL,
2153 RTE_FLOW_ERROR_TYPE_ITEM, item,
2154 "no outer UDP layer found");
2156 mask = &rte_flow_item_geneve_mask;
2157 ret = mlx5_flow_item_acceptable
2158 (item, (const uint8_t *)mask,
2159 (const uint8_t *)&nic_mask,
2160 sizeof(struct rte_flow_item_geneve), error);
2164 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2165 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2166 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2167 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2168 return rte_flow_error_set(error, ENOTSUP,
2169 RTE_FLOW_ERROR_TYPE_ITEM,
2171 "Geneve protocol unsupported"
2172 " fields are being used");
2173 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2174 return rte_flow_error_set
2176 RTE_FLOW_ERROR_TYPE_ITEM,
2178 "Unsupported Geneve options length");
2180 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2181 return rte_flow_error_set
2183 RTE_FLOW_ERROR_TYPE_ITEM, item,
2184 "Geneve tunnel must be fully defined");
2189 * Validate MPLS item.
2192 * Pointer to the rte_eth_dev structure.
2194 * Item specification.
2195 * @param[in] item_flags
2196 * Bit-fields that holds the items detected until now.
2197 * @param[in] prev_layer
2198 * The protocol layer indicated in previous item.
2200 * Pointer to error structure.
2203 * 0 on success, a negative errno value otherwise and rte_errno is set.
2206 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2207 const struct rte_flow_item *item __rte_unused,
2208 uint64_t item_flags __rte_unused,
2209 uint64_t prev_layer __rte_unused,
2210 struct rte_flow_error *error)
2212 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2213 const struct rte_flow_item_mpls *mask = item->mask;
2214 struct mlx5_priv *priv = dev->data->dev_private;
2217 if (!priv->config.mpls_en)
2218 return rte_flow_error_set(error, ENOTSUP,
2219 RTE_FLOW_ERROR_TYPE_ITEM, item,
2220 "MPLS not supported or"
2221 " disabled in firmware"
2223 /* MPLS over IP, UDP, GRE is allowed */
2224 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2225 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2226 MLX5_FLOW_LAYER_GRE)))
2227 return rte_flow_error_set(error, EINVAL,
2228 RTE_FLOW_ERROR_TYPE_ITEM, item,
2229 "protocol filtering not compatible"
2230 " with MPLS layer");
2231 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2232 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2233 !(item_flags & MLX5_FLOW_LAYER_GRE))
2234 return rte_flow_error_set(error, ENOTSUP,
2235 RTE_FLOW_ERROR_TYPE_ITEM, item,
2236 "multiple tunnel layers not"
2239 mask = &rte_flow_item_mpls_mask;
2240 ret = mlx5_flow_item_acceptable
2241 (item, (const uint8_t *)mask,
2242 (const uint8_t *)&rte_flow_item_mpls_mask,
2243 sizeof(struct rte_flow_item_mpls), error);
2248 return rte_flow_error_set(error, ENOTSUP,
2249 RTE_FLOW_ERROR_TYPE_ITEM, item,
2250 "MPLS is not supported by Verbs, please"
2255 * Validate NVGRE item.
2258 * Item specification.
2259 * @param[in] item_flags
2260 * Bit flags to mark detected items.
2261 * @param[in] target_protocol
2262 * The next protocol in the previous item.
2264 * Pointer to error structure.
2267 * 0 on success, a negative errno value otherwise and rte_errno is set.
2270 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2271 uint64_t item_flags,
2272 uint8_t target_protocol,
2273 struct rte_flow_error *error)
2275 const struct rte_flow_item_nvgre *mask = item->mask;
2278 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2279 return rte_flow_error_set(error, EINVAL,
2280 RTE_FLOW_ERROR_TYPE_ITEM, item,
2281 "protocol filtering not compatible"
2282 " with this GRE layer");
2283 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2284 return rte_flow_error_set(error, ENOTSUP,
2285 RTE_FLOW_ERROR_TYPE_ITEM, item,
2286 "multiple tunnel layers not"
2288 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2289 return rte_flow_error_set(error, ENOTSUP,
2290 RTE_FLOW_ERROR_TYPE_ITEM, item,
2291 "L3 Layer is missing");
2293 mask = &rte_flow_item_nvgre_mask;
2294 ret = mlx5_flow_item_acceptable
2295 (item, (const uint8_t *)mask,
2296 (const uint8_t *)&rte_flow_item_nvgre_mask,
2297 sizeof(struct rte_flow_item_nvgre), error);
2303 /* Allocate unique ID for the split Q/RSS subflows. */
2305 flow_qrss_get_id(struct rte_eth_dev *dev)
2307 struct mlx5_priv *priv = dev->data->dev_private;
2308 uint32_t qrss_id, ret;
2310 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2317 /* Free unique ID for the split Q/RSS subflows. */
2319 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2321 struct mlx5_priv *priv = dev->data->dev_private;
2324 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2328 * Release resource related QUEUE/RSS action split.
2331 * Pointer to Ethernet device.
2333 * Flow to release id's from.
2336 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2337 struct rte_flow *flow)
2339 struct mlx5_flow *dev_flow;
2341 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
2342 if (dev_flow->qrss_id)
2343 flow_qrss_free_id(dev, dev_flow->qrss_id);
2347 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2348 const struct rte_flow_attr *attr __rte_unused,
2349 const struct rte_flow_item items[] __rte_unused,
2350 const struct rte_flow_action actions[] __rte_unused,
2351 bool external __rte_unused,
2352 struct rte_flow_error *error)
2354 return rte_flow_error_set(error, ENOTSUP,
2355 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2358 static struct mlx5_flow *
2359 flow_null_prepare(const struct rte_flow_attr *attr __rte_unused,
2360 const struct rte_flow_item items[] __rte_unused,
2361 const struct rte_flow_action actions[] __rte_unused,
2362 struct rte_flow_error *error)
2364 rte_flow_error_set(error, ENOTSUP,
2365 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2370 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2371 struct mlx5_flow *dev_flow __rte_unused,
2372 const struct rte_flow_attr *attr __rte_unused,
2373 const struct rte_flow_item items[] __rte_unused,
2374 const struct rte_flow_action actions[] __rte_unused,
2375 struct rte_flow_error *error)
2377 return rte_flow_error_set(error, ENOTSUP,
2378 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2382 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2383 struct rte_flow *flow __rte_unused,
2384 struct rte_flow_error *error)
2386 return rte_flow_error_set(error, ENOTSUP,
2387 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2391 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2392 struct rte_flow *flow __rte_unused)
2397 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2398 struct rte_flow *flow __rte_unused)
2403 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2404 struct rte_flow *flow __rte_unused,
2405 const struct rte_flow_action *actions __rte_unused,
2406 void *data __rte_unused,
2407 struct rte_flow_error *error)
2409 return rte_flow_error_set(error, ENOTSUP,
2410 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2413 /* Void driver to protect from null pointer reference. */
2414 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2415 .validate = flow_null_validate,
2416 .prepare = flow_null_prepare,
2417 .translate = flow_null_translate,
2418 .apply = flow_null_apply,
2419 .remove = flow_null_remove,
2420 .destroy = flow_null_destroy,
2421 .query = flow_null_query,
2425 * Select flow driver type according to flow attributes and device
2429 * Pointer to the dev structure.
2431 * Pointer to the flow attributes.
2434 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2436 static enum mlx5_flow_drv_type
2437 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2439 struct mlx5_priv *priv = dev->data->dev_private;
2440 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
2442 if (attr->transfer && priv->config.dv_esw_en)
2443 type = MLX5_FLOW_TYPE_DV;
2444 if (!attr->transfer)
2445 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2446 MLX5_FLOW_TYPE_VERBS;
2450 #define flow_get_drv_ops(type) flow_drv_ops[type]
2453 * Flow driver validation API. This abstracts calling driver specific functions.
2454 * The type of flow driver is determined according to flow attributes.
2457 * Pointer to the dev structure.
2459 * Pointer to the flow attributes.
2461 * Pointer to the list of items.
2462 * @param[in] actions
2463 * Pointer to the list of actions.
2464 * @param[in] external
2465 * This flow rule is created by request external to PMD.
2467 * Pointer to the error structure.
2470 * 0 on success, a negative errno value otherwise and rte_errno is set.
2473 flow_drv_validate(struct rte_eth_dev *dev,
2474 const struct rte_flow_attr *attr,
2475 const struct rte_flow_item items[],
2476 const struct rte_flow_action actions[],
2477 bool external, struct rte_flow_error *error)
2479 const struct mlx5_flow_driver_ops *fops;
2480 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2482 fops = flow_get_drv_ops(type);
2483 return fops->validate(dev, attr, items, actions, external, error);
2487 * Flow driver preparation API. This abstracts calling driver specific
2488 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2489 * calculates the size of memory required for device flow, allocates the memory,
2490 * initializes the device flow and returns the pointer.
2493 * This function initializes device flow structure such as dv or verbs in
2494 * struct mlx5_flow. However, it is caller's responsibility to initialize the
2495 * rest. For example, adding returning device flow to flow->dev_flow list and
2496 * setting backward reference to the flow should be done out of this function.
2497 * layers field is not filled either.
2500 * Pointer to the flow attributes.
2502 * Pointer to the list of items.
2503 * @param[in] actions
2504 * Pointer to the list of actions.
2506 * Pointer to the error structure.
2509 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
2511 static inline struct mlx5_flow *
2512 flow_drv_prepare(const struct rte_flow *flow,
2513 const struct rte_flow_attr *attr,
2514 const struct rte_flow_item items[],
2515 const struct rte_flow_action actions[],
2516 struct rte_flow_error *error)
2518 const struct mlx5_flow_driver_ops *fops;
2519 enum mlx5_flow_drv_type type = flow->drv_type;
2521 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2522 fops = flow_get_drv_ops(type);
2523 return fops->prepare(attr, items, actions, error);
2527 * Flow driver translation API. This abstracts calling driver specific
2528 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2529 * translates a generic flow into a driver flow. flow_drv_prepare() must
2533 * dev_flow->layers could be filled as a result of parsing during translation
2534 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
2535 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
2536 * flow->actions could be overwritten even though all the expanded dev_flows
2537 * have the same actions.
2540 * Pointer to the rte dev structure.
2541 * @param[in, out] dev_flow
2542 * Pointer to the mlx5 flow.
2544 * Pointer to the flow attributes.
2546 * Pointer to the list of items.
2547 * @param[in] actions
2548 * Pointer to the list of actions.
2550 * Pointer to the error structure.
2553 * 0 on success, a negative errno value otherwise and rte_errno is set.
2556 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
2557 const struct rte_flow_attr *attr,
2558 const struct rte_flow_item items[],
2559 const struct rte_flow_action actions[],
2560 struct rte_flow_error *error)
2562 const struct mlx5_flow_driver_ops *fops;
2563 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
2565 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2566 fops = flow_get_drv_ops(type);
2567 return fops->translate(dev, dev_flow, attr, items, actions, error);
2571 * Flow driver apply API. This abstracts calling driver specific functions.
2572 * Parent flow (rte_flow) should have driver type (drv_type). It applies
2573 * translated driver flows on to device. flow_drv_translate() must precede.
2576 * Pointer to Ethernet device structure.
2577 * @param[in, out] flow
2578 * Pointer to flow structure.
2580 * Pointer to error structure.
2583 * 0 on success, a negative errno value otherwise and rte_errno is set.
2586 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
2587 struct rte_flow_error *error)
2589 const struct mlx5_flow_driver_ops *fops;
2590 enum mlx5_flow_drv_type type = flow->drv_type;
2592 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2593 fops = flow_get_drv_ops(type);
2594 return fops->apply(dev, flow, error);
2598 * Flow driver remove API. This abstracts calling driver specific functions.
2599 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2600 * on device. All the resources of the flow should be freed by calling
2601 * flow_drv_destroy().
2604 * Pointer to Ethernet device.
2605 * @param[in, out] flow
2606 * Pointer to flow structure.
2609 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
2611 const struct mlx5_flow_driver_ops *fops;
2612 enum mlx5_flow_drv_type type = flow->drv_type;
2614 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2615 fops = flow_get_drv_ops(type);
2616 fops->remove(dev, flow);
2620 * Flow driver destroy API. This abstracts calling driver specific functions.
2621 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2622 * on device and releases resources of the flow.
2625 * Pointer to Ethernet device.
2626 * @param[in, out] flow
2627 * Pointer to flow structure.
2630 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
2632 const struct mlx5_flow_driver_ops *fops;
2633 enum mlx5_flow_drv_type type = flow->drv_type;
2635 flow_mreg_split_qrss_release(dev, flow);
2636 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2637 fops = flow_get_drv_ops(type);
2638 fops->destroy(dev, flow);
2642 * Validate a flow supported by the NIC.
2644 * @see rte_flow_validate()
2648 mlx5_flow_validate(struct rte_eth_dev *dev,
2649 const struct rte_flow_attr *attr,
2650 const struct rte_flow_item items[],
2651 const struct rte_flow_action actions[],
2652 struct rte_flow_error *error)
2656 ret = flow_drv_validate(dev, attr, items, actions, true, error);
2663 * Get port id item from the item list.
2666 * Pointer to the list of items.
2669 * Pointer to the port id item if exist, else return NULL.
2671 static const struct rte_flow_item *
2672 find_port_id_item(const struct rte_flow_item *item)
2675 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2676 if (item->type == RTE_FLOW_ITEM_TYPE_PORT_ID)
2683 * Get RSS action from the action list.
2685 * @param[in] actions
2686 * Pointer to the list of actions.
2689 * Pointer to the RSS action if exist, else return NULL.
2691 static const struct rte_flow_action_rss*
2692 flow_get_rss_action(const struct rte_flow_action actions[])
2694 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2695 switch (actions->type) {
2696 case RTE_FLOW_ACTION_TYPE_RSS:
2697 return (const struct rte_flow_action_rss *)
2707 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
2709 const struct rte_flow_item *item;
2710 unsigned int has_vlan = 0;
2712 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2713 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2719 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
2720 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
2721 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
2722 MLX5_EXPANSION_ROOT_OUTER;
2726 * Get QUEUE/RSS action from the action list.
2728 * @param[in] actions
2729 * Pointer to the list of actions.
2731 * Pointer to the return pointer.
2732 * @param[out] qrss_type
2733 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
2734 * if no QUEUE/RSS is found.
2737 * Total number of actions.
2740 flow_parse_qrss_action(const struct rte_flow_action actions[],
2741 const struct rte_flow_action **qrss)
2745 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2746 switch (actions->type) {
2747 case RTE_FLOW_ACTION_TYPE_QUEUE:
2748 case RTE_FLOW_ACTION_TYPE_RSS:
2756 /* Count RTE_FLOW_ACTION_TYPE_END. */
2757 return actions_n + 1;
2761 * Check meter action from the action list.
2763 * @param[in] actions
2764 * Pointer to the list of actions.
2766 * Pointer to the meter exist flag.
2769 * Total number of actions.
2772 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
2778 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2779 switch (actions->type) {
2780 case RTE_FLOW_ACTION_TYPE_METER:
2788 /* Count RTE_FLOW_ACTION_TYPE_END. */
2789 return actions_n + 1;
2793 * Check if the flow should be splited due to hairpin.
2794 * The reason for the split is that in current HW we can't
2795 * support encap on Rx, so if a flow have encap we move it
2799 * Pointer to Ethernet device.
2801 * Flow rule attributes.
2802 * @param[in] actions
2803 * Associated actions (list terminated by the END action).
2806 * > 0 the number of actions and the flow should be split,
2807 * 0 when no split required.
2810 flow_check_hairpin_split(struct rte_eth_dev *dev,
2811 const struct rte_flow_attr *attr,
2812 const struct rte_flow_action actions[])
2814 int queue_action = 0;
2817 const struct rte_flow_action_queue *queue;
2818 const struct rte_flow_action_rss *rss;
2819 const struct rte_flow_action_raw_encap *raw_encap;
2823 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2824 switch (actions->type) {
2825 case RTE_FLOW_ACTION_TYPE_QUEUE:
2826 queue = actions->conf;
2829 if (mlx5_rxq_get_type(dev, queue->index) !=
2830 MLX5_RXQ_TYPE_HAIRPIN)
2835 case RTE_FLOW_ACTION_TYPE_RSS:
2836 rss = actions->conf;
2837 if (rss == NULL || rss->queue_num == 0)
2839 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
2840 MLX5_RXQ_TYPE_HAIRPIN)
2845 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2846 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2850 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2851 raw_encap = actions->conf;
2852 if (raw_encap->size >
2853 (sizeof(struct rte_flow_item_eth) +
2854 sizeof(struct rte_flow_item_ipv4)))
2863 if (encap == 1 && queue_action)
2868 /* Declare flow create/destroy prototype in advance. */
2869 static struct rte_flow *
2870 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
2871 const struct rte_flow_attr *attr,
2872 const struct rte_flow_item items[],
2873 const struct rte_flow_action actions[],
2874 bool external, struct rte_flow_error *error);
2877 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
2878 struct rte_flow *flow);
2881 * Add a flow of copying flow metadata registers in RX_CP_TBL.
2883 * As mark_id is unique, if there's already a registered flow for the mark_id,
2884 * return by increasing the reference counter of the resource. Otherwise, create
2885 * the resource (mcp_res) and flow.
2888 * - If ingress port is ANY and reg_c[1] is mark_id,
2889 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
2891 * For default flow (zero mark_id), flow is like,
2892 * - If ingress port is ANY,
2893 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
2896 * Pointer to Ethernet device.
2898 * ID of MARK action, zero means default flow for META.
2900 * Perform verbose error reporting if not NULL.
2903 * Associated resource on success, NULL otherwise and rte_errno is set.
2905 static struct mlx5_flow_mreg_copy_resource *
2906 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
2907 struct rte_flow_error *error)
2909 struct mlx5_priv *priv = dev->data->dev_private;
2910 struct rte_flow_attr attr = {
2911 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
2914 struct mlx5_rte_flow_item_tag tag_spec = {
2917 struct rte_flow_item items[] = {
2918 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
2920 struct rte_flow_action_mark ftag = {
2923 struct mlx5_flow_action_copy_mreg cp_mreg = {
2927 struct rte_flow_action_jump jump = {
2928 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
2930 struct rte_flow_action actions[] = {
2931 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
2933 struct mlx5_flow_mreg_copy_resource *mcp_res;
2936 /* Fill the register fileds in the flow. */
2937 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2941 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
2945 /* Check if already registered. */
2946 assert(priv->mreg_cp_tbl);
2947 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
2949 /* For non-default rule. */
2950 if (mark_id != MLX5_DEFAULT_COPY_ID)
2952 assert(mark_id != MLX5_DEFAULT_COPY_ID || mcp_res->refcnt == 1);
2955 /* Provide the full width of FLAG specific value. */
2956 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
2957 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
2958 /* Build a new flow. */
2959 if (mark_id != MLX5_DEFAULT_COPY_ID) {
2960 items[0] = (struct rte_flow_item){
2961 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
2964 items[1] = (struct rte_flow_item){
2965 .type = RTE_FLOW_ITEM_TYPE_END,
2967 actions[0] = (struct rte_flow_action){
2968 .type = MLX5_RTE_FLOW_ACTION_TYPE_MARK,
2971 actions[1] = (struct rte_flow_action){
2972 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
2975 actions[2] = (struct rte_flow_action){
2976 .type = RTE_FLOW_ACTION_TYPE_JUMP,
2979 actions[3] = (struct rte_flow_action){
2980 .type = RTE_FLOW_ACTION_TYPE_END,
2983 /* Default rule, wildcard match. */
2984 attr.priority = MLX5_FLOW_PRIO_RSVD;
2985 items[0] = (struct rte_flow_item){
2986 .type = RTE_FLOW_ITEM_TYPE_END,
2988 actions[0] = (struct rte_flow_action){
2989 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
2992 actions[1] = (struct rte_flow_action){
2993 .type = RTE_FLOW_ACTION_TYPE_JUMP,
2996 actions[2] = (struct rte_flow_action){
2997 .type = RTE_FLOW_ACTION_TYPE_END,
3000 /* Build a new entry. */
3001 mcp_res = rte_zmalloc(__func__, sizeof(*mcp_res), 0);
3007 * The copy Flows are not included in any list. There
3008 * ones are referenced from other Flows and can not
3009 * be applied, removed, deleted in ardbitrary order
3010 * by list traversing.
3012 mcp_res->flow = flow_list_create(dev, NULL, &attr, items,
3013 actions, false, error);
3017 mcp_res->hlist_ent.key = mark_id;
3018 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3019 &mcp_res->hlist_ent);
3026 flow_list_destroy(dev, NULL, mcp_res->flow);
3032 * Release flow in RX_CP_TBL.
3035 * Pointer to Ethernet device.
3037 * Parent flow for wich copying is provided.
3040 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3041 struct rte_flow *flow)
3043 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3044 struct mlx5_priv *priv = dev->data->dev_private;
3046 if (!mcp_res || !priv->mreg_cp_tbl)
3048 if (flow->copy_applied) {
3049 assert(mcp_res->appcnt);
3050 flow->copy_applied = 0;
3052 if (!mcp_res->appcnt)
3053 flow_drv_remove(dev, mcp_res->flow);
3056 * We do not check availability of metadata registers here,
3057 * because copy resources are not allocated in this case.
3059 if (--mcp_res->refcnt)
3061 assert(mcp_res->flow);
3062 flow_list_destroy(dev, NULL, mcp_res->flow);
3063 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3065 flow->mreg_copy = NULL;
3069 * Start flow in RX_CP_TBL.
3072 * Pointer to Ethernet device.
3074 * Parent flow for wich copying is provided.
3077 * 0 on success, a negative errno value otherwise and rte_errno is set.
3080 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3081 struct rte_flow *flow)
3083 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3086 if (!mcp_res || flow->copy_applied)
3088 if (!mcp_res->appcnt) {
3089 ret = flow_drv_apply(dev, mcp_res->flow, NULL);
3094 flow->copy_applied = 1;
3099 * Stop flow in RX_CP_TBL.
3102 * Pointer to Ethernet device.
3104 * Parent flow for wich copying is provided.
3107 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3108 struct rte_flow *flow)
3110 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3112 if (!mcp_res || !flow->copy_applied)
3114 assert(mcp_res->appcnt);
3116 flow->copy_applied = 0;
3117 if (!mcp_res->appcnt)
3118 flow_drv_remove(dev, mcp_res->flow);
3122 * Remove the default copy action from RX_CP_TBL.
3125 * Pointer to Ethernet device.
3128 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3130 struct mlx5_flow_mreg_copy_resource *mcp_res;
3131 struct mlx5_priv *priv = dev->data->dev_private;
3133 /* Check if default flow is registered. */
3134 if (!priv->mreg_cp_tbl)
3136 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3137 MLX5_DEFAULT_COPY_ID);
3140 assert(mcp_res->flow);
3141 flow_list_destroy(dev, NULL, mcp_res->flow);
3142 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3147 * Add the default copy action in in RX_CP_TBL.
3150 * Pointer to Ethernet device.
3152 * Perform verbose error reporting if not NULL.
3155 * 0 for success, negative value otherwise and rte_errno is set.
3158 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3159 struct rte_flow_error *error)
3161 struct mlx5_priv *priv = dev->data->dev_private;
3162 struct mlx5_flow_mreg_copy_resource *mcp_res;
3164 /* Check whether extensive metadata feature is engaged. */
3165 if (!priv->config.dv_flow_en ||
3166 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3167 !mlx5_flow_ext_mreg_supported(dev) ||
3168 !priv->sh->dv_regc0_mask)
3170 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3177 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3179 * All the flow having Q/RSS action should be split by
3180 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3181 * performs the following,
3182 * - CQE->flow_tag := reg_c[1] (MARK)
3183 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3184 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3185 * but there should be a flow per each MARK ID set by MARK action.
3187 * For the aforementioned reason, if there's a MARK action in flow's action
3188 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3189 * the MARK ID to CQE's flow_tag like,
3190 * - If reg_c[1] is mark_id,
3191 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3193 * For SET_META action which stores value in reg_c[0], as the destination is
3194 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3195 * MARK ID means the default flow. The default flow looks like,
3196 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3199 * Pointer to Ethernet device.
3201 * Pointer to flow structure.
3202 * @param[in] actions
3203 * Pointer to the list of actions.
3205 * Perform verbose error reporting if not NULL.
3208 * 0 on success, negative value otherwise and rte_errno is set.
3211 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3212 struct rte_flow *flow,
3213 const struct rte_flow_action *actions,
3214 struct rte_flow_error *error)
3216 struct mlx5_priv *priv = dev->data->dev_private;
3217 struct mlx5_dev_config *config = &priv->config;
3218 struct mlx5_flow_mreg_copy_resource *mcp_res;
3219 const struct rte_flow_action_mark *mark;
3221 /* Check whether extensive metadata feature is engaged. */
3222 if (!config->dv_flow_en ||
3223 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3224 !mlx5_flow_ext_mreg_supported(dev) ||
3225 !priv->sh->dv_regc0_mask)
3227 /* Find MARK action. */
3228 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3229 switch (actions->type) {
3230 case RTE_FLOW_ACTION_TYPE_FLAG:
3231 mcp_res = flow_mreg_add_copy_action
3232 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3235 flow->mreg_copy = mcp_res;
3236 if (dev->data->dev_started) {
3238 flow->copy_applied = 1;
3241 case RTE_FLOW_ACTION_TYPE_MARK:
3242 mark = (const struct rte_flow_action_mark *)
3245 flow_mreg_add_copy_action(dev, mark->id, error);
3248 flow->mreg_copy = mcp_res;
3249 if (dev->data->dev_started) {
3251 flow->copy_applied = 1;
3261 #define MLX5_MAX_SPLIT_ACTIONS 24
3262 #define MLX5_MAX_SPLIT_ITEMS 24
3265 * Split the hairpin flow.
3266 * Since HW can't support encap on Rx we move the encap to Tx.
3267 * If the count action is after the encap then we also
3268 * move the count action. in this case the count will also measure
3272 * Pointer to Ethernet device.
3273 * @param[in] actions
3274 * Associated actions (list terminated by the END action).
3275 * @param[out] actions_rx
3277 * @param[out] actions_tx
3279 * @param[out] pattern_tx
3280 * The pattern items for the Tx flow.
3281 * @param[out] flow_id
3282 * The flow ID connected to this flow.
3288 flow_hairpin_split(struct rte_eth_dev *dev,
3289 const struct rte_flow_action actions[],
3290 struct rte_flow_action actions_rx[],
3291 struct rte_flow_action actions_tx[],
3292 struct rte_flow_item pattern_tx[],
3295 struct mlx5_priv *priv = dev->data->dev_private;
3296 const struct rte_flow_action_raw_encap *raw_encap;
3297 const struct rte_flow_action_raw_decap *raw_decap;
3298 struct mlx5_rte_flow_action_set_tag *set_tag;
3299 struct rte_flow_action *tag_action;
3300 struct mlx5_rte_flow_item_tag *tag_item;
3301 struct rte_flow_item *item;
3305 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
3306 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3307 switch (actions->type) {
3308 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3309 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3310 rte_memcpy(actions_tx, actions,
3311 sizeof(struct rte_flow_action));
3314 case RTE_FLOW_ACTION_TYPE_COUNT:
3316 rte_memcpy(actions_tx, actions,
3317 sizeof(struct rte_flow_action));
3320 rte_memcpy(actions_rx, actions,
3321 sizeof(struct rte_flow_action));
3325 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3326 raw_encap = actions->conf;
3327 if (raw_encap->size >
3328 (sizeof(struct rte_flow_item_eth) +
3329 sizeof(struct rte_flow_item_ipv4))) {
3330 memcpy(actions_tx, actions,
3331 sizeof(struct rte_flow_action));
3335 rte_memcpy(actions_rx, actions,
3336 sizeof(struct rte_flow_action));
3340 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3341 raw_decap = actions->conf;
3342 if (raw_decap->size <
3343 (sizeof(struct rte_flow_item_eth) +
3344 sizeof(struct rte_flow_item_ipv4))) {
3345 memcpy(actions_tx, actions,
3346 sizeof(struct rte_flow_action));
3349 rte_memcpy(actions_rx, actions,
3350 sizeof(struct rte_flow_action));
3355 rte_memcpy(actions_rx, actions,
3356 sizeof(struct rte_flow_action));
3361 /* Add set meta action and end action for the Rx flow. */
3362 tag_action = actions_rx;
3363 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3365 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
3367 set_tag = (void *)actions_rx;
3368 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
3369 assert(set_tag->id > REG_NONE);
3370 set_tag->data = *flow_id;
3371 tag_action->conf = set_tag;
3372 /* Create Tx item list. */
3373 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
3374 addr = (void *)&pattern_tx[2];
3376 item->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3377 tag_item = (void *)addr;
3378 tag_item->data = *flow_id;
3379 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
3380 assert(set_tag->id > REG_NONE);
3381 item->spec = tag_item;
3382 addr += sizeof(struct mlx5_rte_flow_item_tag);
3383 tag_item = (void *)addr;
3384 tag_item->data = UINT32_MAX;
3385 tag_item->id = UINT16_MAX;
3386 item->mask = tag_item;
3387 addr += sizeof(struct mlx5_rte_flow_item_tag);
3390 item->type = RTE_FLOW_ITEM_TYPE_END;
3395 * The last stage of splitting chain, just creates the subflow
3396 * without any modification.
3399 * Pointer to Ethernet device.
3401 * Parent flow structure pointer.
3402 * @param[in, out] sub_flow
3403 * Pointer to return the created subflow, may be NULL.
3405 * Flow rule attributes.
3407 * Pattern specification (list terminated by the END pattern item).
3408 * @param[in] actions
3409 * Associated actions (list terminated by the END action).
3410 * @param[in] external
3411 * This flow rule is created by request external to PMD.
3413 * Perform verbose error reporting if not NULL.
3415 * 0 on success, negative value otherwise
3418 flow_create_split_inner(struct rte_eth_dev *dev,
3419 struct rte_flow *flow,
3420 struct mlx5_flow **sub_flow,
3421 const struct rte_flow_attr *attr,
3422 const struct rte_flow_item items[],
3423 const struct rte_flow_action actions[],
3424 bool external, struct rte_flow_error *error)
3426 struct mlx5_flow *dev_flow;
3428 dev_flow = flow_drv_prepare(flow, attr, items, actions, error);
3431 dev_flow->flow = flow;
3432 dev_flow->external = external;
3433 /* Subflow object was created, we must include one in the list. */
3434 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
3436 *sub_flow = dev_flow;
3437 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
3441 * Split the meter flow.
3443 * As meter flow will split to three sub flow, other than meter
3444 * action, the other actions make sense to only meter accepts
3445 * the packet. If it need to be dropped, no other additional
3446 * actions should be take.
3448 * One kind of special action which decapsulates the L3 tunnel
3449 * header will be in the prefix sub flow, as not to take the
3450 * L3 tunnel header into account.
3453 * Pointer to Ethernet device.
3454 * @param[in] actions
3455 * Associated actions (list terminated by the END action).
3456 * @param[out] actions_sfx
3457 * Suffix flow actions.
3458 * @param[out] actions_pre
3459 * Prefix flow actions.
3460 * @param[out] pattern_sfx
3461 * The pattern items for the suffix flow.
3462 * @param[out] tag_sfx
3463 * Pointer to suffix flow tag.
3469 flow_meter_split_prep(struct rte_eth_dev *dev,
3470 const struct rte_flow_action actions[],
3471 struct rte_flow_action actions_sfx[],
3472 struct rte_flow_action actions_pre[])
3474 struct rte_flow_action *tag_action;
3475 struct mlx5_rte_flow_action_set_tag *set_tag;
3476 struct rte_flow_error error;
3477 const struct rte_flow_action_raw_encap *raw_encap;
3478 const struct rte_flow_action_raw_decap *raw_decap;
3481 /* Add the extra tag action first. */
3482 tag_action = actions_pre;
3483 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3485 /* Prepare the actions for prefix and suffix flow. */
3486 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3487 switch (actions->type) {
3488 case RTE_FLOW_ACTION_TYPE_METER:
3489 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3490 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3491 memcpy(actions_pre, actions,
3492 sizeof(struct rte_flow_action));
3495 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3496 raw_encap = actions->conf;
3497 if (raw_encap->size >
3498 (sizeof(struct rte_flow_item_eth) +
3499 sizeof(struct rte_flow_item_ipv4))) {
3500 memcpy(actions_sfx, actions,
3501 sizeof(struct rte_flow_action));
3504 rte_memcpy(actions_pre, actions,
3505 sizeof(struct rte_flow_action));
3509 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3510 raw_decap = actions->conf;
3511 /* Size 0 decap means 50 bytes as vxlan decap. */
3512 if (raw_decap->size && (raw_decap->size <
3513 (sizeof(struct rte_flow_item_eth) +
3514 sizeof(struct rte_flow_item_ipv4)))) {
3515 memcpy(actions_sfx, actions,
3516 sizeof(struct rte_flow_action));
3519 rte_memcpy(actions_pre, actions,
3520 sizeof(struct rte_flow_action));
3525 memcpy(actions_sfx, actions,
3526 sizeof(struct rte_flow_action));
3531 /* Add end action to the actions. */
3532 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
3533 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
3536 set_tag = (void *)actions_pre;
3537 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3539 * Get the id from the qrss_pool to make qrss share the id with meter.
3541 tag_id = flow_qrss_get_id(dev);
3542 set_tag->data = rte_cpu_to_be_32(tag_id);
3543 tag_action->conf = set_tag;
3548 * Split action list having QUEUE/RSS for metadata register copy.
3550 * Once Q/RSS action is detected in user's action list, the flow action
3551 * should be split in order to copy metadata registers, which will happen in
3553 * - CQE->flow_tag := reg_c[1] (MARK)
3554 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3555 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
3556 * This is because the last action of each flow must be a terminal action
3557 * (QUEUE, RSS or DROP).
3559 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
3560 * stored and kept in the mlx5_flow structure per each sub_flow.
3562 * The Q/RSS action is replaced with,
3563 * - SET_TAG, setting the allocated flow ID to reg_c[2].
3564 * And the following JUMP action is added at the end,
3565 * - JUMP, to RX_CP_TBL.
3567 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
3568 * flow_create_split_metadata() routine. The flow will look like,
3569 * - If flow ID matches (reg_c[2]), perform Q/RSS.
3572 * Pointer to Ethernet device.
3573 * @param[out] split_actions
3574 * Pointer to store split actions to jump to CP_TBL.
3575 * @param[in] actions
3576 * Pointer to the list of original flow actions.
3578 * Pointer to the Q/RSS action.
3579 * @param[in] actions_n
3580 * Number of original actions.
3582 * Perform verbose error reporting if not NULL.
3585 * non-zero unique flow_id on success, otherwise 0 and
3586 * error/rte_error are set.
3589 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
3590 struct rte_flow_action *split_actions,
3591 const struct rte_flow_action *actions,
3592 const struct rte_flow_action *qrss,
3593 int actions_n, struct rte_flow_error *error)
3595 struct mlx5_rte_flow_action_set_tag *set_tag;
3596 struct rte_flow_action_jump *jump;
3597 const int qrss_idx = qrss - actions;
3598 uint32_t flow_id = 0;
3602 * Given actions will be split
3603 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
3604 * - Add jump to mreg CP_TBL.
3605 * As a result, there will be one more action.
3608 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
3609 set_tag = (void *)(split_actions + actions_n);
3611 * If tag action is not set to void(it means we are not the meter
3612 * suffix flow), add the tag action. Since meter suffix flow already
3613 * has the tag added.
3615 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
3617 * Allocate the new subflow ID. This one is unique within
3618 * device and not shared with representors. Otherwise,
3619 * we would have to resolve multi-thread access synch
3620 * issue. Each flow on the shared device is appended
3621 * with source vport identifier, so the resulting
3622 * flows will be unique in the shared (by master and
3623 * representors) domain even if they have coinciding
3626 flow_id = flow_qrss_get_id(dev);
3628 return rte_flow_error_set(error, ENOMEM,
3629 RTE_FLOW_ERROR_TYPE_ACTION,
3630 NULL, "can't allocate id "
3631 "for split Q/RSS subflow");
3632 /* Internal SET_TAG action to set flow ID. */
3633 *set_tag = (struct mlx5_rte_flow_action_set_tag){
3636 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
3640 /* Construct new actions array. */
3641 /* Replace QUEUE/RSS action. */
3642 split_actions[qrss_idx] = (struct rte_flow_action){
3643 .type = MLX5_RTE_FLOW_ACTION_TYPE_TAG,
3647 /* JUMP action to jump to mreg copy table (CP_TBL). */
3648 jump = (void *)(set_tag + 1);
3649 *jump = (struct rte_flow_action_jump){
3650 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3652 split_actions[actions_n - 2] = (struct rte_flow_action){
3653 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3656 split_actions[actions_n - 1] = (struct rte_flow_action){
3657 .type = RTE_FLOW_ACTION_TYPE_END,
3663 * Extend the given action list for Tx metadata copy.
3665 * Copy the given action list to the ext_actions and add flow metadata register
3666 * copy action in order to copy reg_a set by WQE to reg_c[0].
3668 * @param[out] ext_actions
3669 * Pointer to the extended action list.
3670 * @param[in] actions
3671 * Pointer to the list of actions.
3672 * @param[in] actions_n
3673 * Number of actions in the list.
3675 * Perform verbose error reporting if not NULL.
3678 * 0 on success, negative value otherwise
3681 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
3682 struct rte_flow_action *ext_actions,
3683 const struct rte_flow_action *actions,
3684 int actions_n, struct rte_flow_error *error)
3686 struct mlx5_flow_action_copy_mreg *cp_mreg =
3687 (struct mlx5_flow_action_copy_mreg *)
3688 (ext_actions + actions_n + 1);
3691 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3695 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
3699 memcpy(ext_actions, actions,
3700 sizeof(*ext_actions) * actions_n);
3701 ext_actions[actions_n - 1] = (struct rte_flow_action){
3702 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3705 ext_actions[actions_n] = (struct rte_flow_action){
3706 .type = RTE_FLOW_ACTION_TYPE_END,
3712 * The splitting for metadata feature.
3714 * - Q/RSS action on NIC Rx should be split in order to pass by
3715 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3716 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3718 * - All the actions on NIC Tx should have a mreg copy action to
3719 * copy reg_a from WQE to reg_c[0].
3722 * Pointer to Ethernet device.
3724 * Parent flow structure pointer.
3726 * Flow rule attributes.
3728 * Pattern specification (list terminated by the END pattern item).
3729 * @param[in] actions
3730 * Associated actions (list terminated by the END action).
3731 * @param[in] external
3732 * This flow rule is created by request external to PMD.
3734 * Perform verbose error reporting if not NULL.
3736 * 0 on success, negative value otherwise
3739 flow_create_split_metadata(struct rte_eth_dev *dev,
3740 struct rte_flow *flow,
3741 const struct rte_flow_attr *attr,
3742 const struct rte_flow_item items[],
3743 const struct rte_flow_action actions[],
3744 bool external, struct rte_flow_error *error)
3746 struct mlx5_priv *priv = dev->data->dev_private;
3747 struct mlx5_dev_config *config = &priv->config;
3748 const struct rte_flow_action *qrss = NULL;
3749 struct rte_flow_action *ext_actions = NULL;
3750 struct mlx5_flow *dev_flow = NULL;
3751 uint32_t qrss_id = 0;
3757 /* Check whether extensive metadata feature is engaged. */
3758 if (!config->dv_flow_en ||
3759 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3760 !mlx5_flow_ext_mreg_supported(dev))
3761 return flow_create_split_inner(dev, flow, NULL, attr, items,
3762 actions, external, error);
3763 actions_n = flow_parse_qrss_action(actions, &qrss);
3765 /* Exclude hairpin flows from splitting. */
3766 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
3767 const struct rte_flow_action_queue *queue;
3770 if (mlx5_rxq_get_type(dev, queue->index) ==
3771 MLX5_RXQ_TYPE_HAIRPIN)
3773 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
3774 const struct rte_flow_action_rss *rss;
3777 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
3778 MLX5_RXQ_TYPE_HAIRPIN)
3783 /* Check if it is in meter suffix table. */
3784 mtr_sfx = attr->group == (attr->transfer ?
3785 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
3786 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
3788 * Q/RSS action on NIC Rx should be split in order to pass by
3789 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3790 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3792 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3793 sizeof(struct rte_flow_action_set_tag) +
3794 sizeof(struct rte_flow_action_jump);
3795 ext_actions = rte_zmalloc(__func__, act_size, 0);
3797 return rte_flow_error_set(error, ENOMEM,
3798 RTE_FLOW_ERROR_TYPE_ACTION,
3799 NULL, "no memory to split "
3802 * If we are the suffix flow of meter, tag already exist.
3803 * Set the tag action to void.
3806 ext_actions[qrss - actions].type =
3807 RTE_FLOW_ACTION_TYPE_VOID;
3809 ext_actions[qrss - actions].type =
3810 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3812 * Create the new actions list with removed Q/RSS action
3813 * and appended set tag and jump to register copy table
3814 * (RX_CP_TBL). We should preallocate unique tag ID here
3815 * in advance, because it is needed for set tag action.
3817 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
3818 qrss, actions_n, error);
3819 if (!mtr_sfx && !qrss_id) {
3823 } else if (attr->egress && !attr->transfer) {
3825 * All the actions on NIC Tx should have a metadata register
3826 * copy action to copy reg_a from WQE to reg_c[meta]
3828 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3829 sizeof(struct mlx5_flow_action_copy_mreg);
3830 ext_actions = rte_zmalloc(__func__, act_size, 0);
3832 return rte_flow_error_set(error, ENOMEM,
3833 RTE_FLOW_ERROR_TYPE_ACTION,
3834 NULL, "no memory to split "
3836 /* Create the action list appended with copy register. */
3837 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
3842 /* Add the unmodified original or prefix subflow. */
3843 ret = flow_create_split_inner(dev, flow, &dev_flow, attr, items,
3844 ext_actions ? ext_actions : actions,
3850 const struct rte_flow_attr q_attr = {
3851 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3854 /* Internal PMD action to set register. */
3855 struct mlx5_rte_flow_item_tag q_tag_spec = {
3859 struct rte_flow_item q_items[] = {
3861 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3862 .spec = &q_tag_spec,
3867 .type = RTE_FLOW_ITEM_TYPE_END,
3870 struct rte_flow_action q_actions[] = {
3876 .type = RTE_FLOW_ACTION_TYPE_END,
3879 uint64_t hash_fields = dev_flow->hash_fields;
3882 * Configure the tag item only if there is no meter subflow.
3883 * Since tag is already marked in the meter suffix subflow
3884 * we can just use the meter suffix items as is.
3887 /* Not meter subflow. */
3890 * Put unique id in prefix flow due to it is destroyed
3891 * after suffix flow and id will be freed after there
3892 * is no actual flows with this id and identifier
3893 * reallocation becomes possible (for example, for
3894 * other flows in other threads).
3896 dev_flow->qrss_id = qrss_id;
3898 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
3902 q_tag_spec.id = ret;
3905 /* Add suffix subflow to execute Q/RSS. */
3906 ret = flow_create_split_inner(dev, flow, &dev_flow,
3907 &q_attr, mtr_sfx ? items :
3913 dev_flow->hash_fields = hash_fields;
3918 * We do not destroy the partially created sub_flows in case of error.
3919 * These ones are included into parent flow list and will be destroyed
3920 * by flow_drv_destroy.
3922 flow_qrss_free_id(dev, qrss_id);
3923 rte_free(ext_actions);
3928 * The splitting for meter feature.
3930 * - The meter flow will be split to two flows as prefix and
3931 * suffix flow. The packets make sense only it pass the prefix
3934 * - Reg_C_5 is used for the packet to match betweend prefix and
3938 * Pointer to Ethernet device.
3940 * Parent flow structure pointer.
3942 * Flow rule attributes.
3944 * Pattern specification (list terminated by the END pattern item).
3945 * @param[in] actions
3946 * Associated actions (list terminated by the END action).
3947 * @param[in] external
3948 * This flow rule is created by request external to PMD.
3950 * Perform verbose error reporting if not NULL.
3952 * 0 on success, negative value otherwise
3955 flow_create_split_meter(struct rte_eth_dev *dev,
3956 struct rte_flow *flow,
3957 const struct rte_flow_attr *attr,
3958 const struct rte_flow_item items[],
3959 const struct rte_flow_action actions[],
3960 bool external, struct rte_flow_error *error)
3962 struct mlx5_priv *priv = dev->data->dev_private;
3963 struct rte_flow_action *sfx_actions = NULL;
3964 struct rte_flow_action *pre_actions = NULL;
3965 struct rte_flow_item *sfx_items = NULL;
3966 const struct rte_flow_item *sfx_port_id_item;
3967 struct mlx5_flow *dev_flow = NULL;
3968 struct rte_flow_attr sfx_attr = *attr;
3970 uint32_t mtr_tag_id = 0;
3977 actions_n = flow_check_meter_action(actions, &mtr);
3979 struct mlx5_rte_flow_item_tag *tag_spec;
3980 /* The five prefix actions: meter, decap, encap, tag, end. */
3981 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
3982 sizeof(struct rte_flow_action_set_tag);
3984 #define METER_SUFFIX_ITEM 3
3985 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
3986 sizeof(struct mlx5_rte_flow_item_tag);
3987 sfx_actions = rte_zmalloc(__func__, (act_size + item_size), 0);
3989 return rte_flow_error_set(error, ENOMEM,
3990 RTE_FLOW_ERROR_TYPE_ACTION,
3991 NULL, "no memory to split "
3993 pre_actions = sfx_actions + actions_n;
3994 mtr_tag_id = flow_meter_split_prep(dev, actions, sfx_actions,
4000 /* Add the prefix subflow. */
4001 ret = flow_create_split_inner(dev, flow, &dev_flow, attr, items,
4002 pre_actions, external, error);
4007 dev_flow->mtr_flow_id = mtr_tag_id;
4008 /* Prepare the suffix flow match pattern. */
4009 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4011 tag_spec = (struct mlx5_rte_flow_item_tag *)(sfx_items +
4013 tag_spec->data = rte_cpu_to_be_32(dev_flow->mtr_flow_id);
4014 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0,
4016 sfx_items->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4017 sfx_items->spec = tag_spec;
4018 sfx_items->last = NULL;
4019 sfx_items->mask = NULL;
4021 sfx_port_id_item = find_port_id_item(items);
4022 if (sfx_port_id_item) {
4023 memcpy(sfx_items, sfx_port_id_item,
4024 sizeof(*sfx_items));
4027 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4028 sfx_items -= METER_SUFFIX_ITEM;
4029 /* Setting the sfx group atrr. */
4030 sfx_attr.group = sfx_attr.transfer ?
4031 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4032 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4034 /* Add the prefix subflow. */
4035 ret = flow_create_split_metadata(dev, flow, &sfx_attr,
4036 sfx_items ? sfx_items : items,
4037 sfx_actions ? sfx_actions : actions,
4041 rte_free(sfx_actions);
4046 * Split the flow to subflow set. The splitters might be linked
4047 * in the chain, like this:
4048 * flow_create_split_outer() calls:
4049 * flow_create_split_meter() calls:
4050 * flow_create_split_metadata(meter_subflow_0) calls:
4051 * flow_create_split_inner(metadata_subflow_0)
4052 * flow_create_split_inner(metadata_subflow_1)
4053 * flow_create_split_inner(metadata_subflow_2)
4054 * flow_create_split_metadata(meter_subflow_1) calls:
4055 * flow_create_split_inner(metadata_subflow_0)
4056 * flow_create_split_inner(metadata_subflow_1)
4057 * flow_create_split_inner(metadata_subflow_2)
4059 * This provide flexible way to add new levels of flow splitting.
4060 * The all of successfully created subflows are included to the
4061 * parent flow dev_flow list.
4064 * Pointer to Ethernet device.
4066 * Parent flow structure pointer.
4068 * Flow rule attributes.
4070 * Pattern specification (list terminated by the END pattern item).
4071 * @param[in] actions
4072 * Associated actions (list terminated by the END action).
4073 * @param[in] external
4074 * This flow rule is created by request external to PMD.
4076 * Perform verbose error reporting if not NULL.
4078 * 0 on success, negative value otherwise
4081 flow_create_split_outer(struct rte_eth_dev *dev,
4082 struct rte_flow *flow,
4083 const struct rte_flow_attr *attr,
4084 const struct rte_flow_item items[],
4085 const struct rte_flow_action actions[],
4086 bool external, struct rte_flow_error *error)
4090 ret = flow_create_split_meter(dev, flow, attr, items,
4091 actions, external, error);
4097 * Create a flow and add it to @p list.
4100 * Pointer to Ethernet device.
4102 * Pointer to a TAILQ flow list. If this parameter NULL,
4103 * no list insertion occurred, flow is just created,
4104 * this is caller's responsibility to track the
4107 * Flow rule attributes.
4109 * Pattern specification (list terminated by the END pattern item).
4110 * @param[in] actions
4111 * Associated actions (list terminated by the END action).
4112 * @param[in] external
4113 * This flow rule is created by request external to PMD.
4115 * Perform verbose error reporting if not NULL.
4118 * A flow on success, NULL otherwise and rte_errno is set.
4120 static struct rte_flow *
4121 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
4122 const struct rte_flow_attr *attr,
4123 const struct rte_flow_item items[],
4124 const struct rte_flow_action actions[],
4125 bool external, struct rte_flow_error *error)
4127 struct mlx5_priv *priv = dev->data->dev_private;
4128 struct rte_flow *flow = NULL;
4129 struct mlx5_flow *dev_flow;
4130 const struct rte_flow_action_rss *rss;
4132 struct rte_flow_expand_rss buf;
4133 uint8_t buffer[2048];
4136 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4137 uint8_t buffer[2048];
4140 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4141 uint8_t buffer[2048];
4142 } actions_hairpin_tx;
4144 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
4145 uint8_t buffer[2048];
4147 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
4148 const struct rte_flow_action *p_actions_rx = actions;
4152 int hairpin_flow = 0;
4153 uint32_t hairpin_id = 0;
4154 struct rte_flow_attr attr_tx = { .priority = 0 };
4156 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4157 if (hairpin_flow > 0) {
4158 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
4162 flow_hairpin_split(dev, actions, actions_rx.actions,
4163 actions_hairpin_tx.actions, items_tx.items,
4165 p_actions_rx = actions_rx.actions;
4167 ret = flow_drv_validate(dev, attr, items, p_actions_rx, external,
4170 goto error_before_flow;
4171 flow_size = sizeof(struct rte_flow);
4172 rss = flow_get_rss_action(p_actions_rx);
4174 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
4177 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
4178 flow = rte_calloc(__func__, 1, flow_size, 0);
4181 goto error_before_flow;
4183 flow->drv_type = flow_get_drv_type(dev, attr);
4184 if (hairpin_id != 0)
4185 flow->hairpin_flow_id = hairpin_id;
4186 assert(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
4187 flow->drv_type < MLX5_FLOW_TYPE_MAX);
4188 flow->rss.queue = (void *)(flow + 1);
4191 * The following information is required by
4192 * mlx5_flow_hashfields_adjust() in advance.
4194 flow->rss.level = rss->level;
4195 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
4196 flow->rss.types = !rss->types ? ETH_RSS_IP : rss->types;
4198 LIST_INIT(&flow->dev_flows);
4199 if (rss && rss->types) {
4200 unsigned int graph_root;
4202 graph_root = find_graph_root(items, rss->level);
4203 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
4205 mlx5_support_expansion,
4208 (unsigned int)ret < sizeof(expand_buffer.buffer));
4211 buf->entry[0].pattern = (void *)(uintptr_t)items;
4213 for (i = 0; i < buf->entries; ++i) {
4215 * The splitter may create multiple dev_flows,
4216 * depending on configuration. In the simplest
4217 * case it just creates unmodified original flow.
4219 ret = flow_create_split_outer(dev, flow, attr,
4220 buf->entry[i].pattern,
4221 p_actions_rx, external,
4226 /* Create the tx flow. */
4228 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
4229 attr_tx.ingress = 0;
4231 dev_flow = flow_drv_prepare(flow, &attr_tx, items_tx.items,
4232 actions_hairpin_tx.actions, error);
4235 dev_flow->flow = flow;
4236 dev_flow->external = 0;
4237 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
4238 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
4240 actions_hairpin_tx.actions, error);
4245 * Update the metadata register copy table. If extensive
4246 * metadata feature is enabled and registers are supported
4247 * we might create the extra rte_flow for each unique
4248 * MARK/FLAG action ID.
4250 * The table is updated for ingress Flows only, because
4251 * the egress Flows belong to the different device and
4252 * copy table should be updated in peer NIC Rx domain.
4254 if (attr->ingress &&
4255 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
4256 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
4260 if (dev->data->dev_started) {
4261 ret = flow_drv_apply(dev, flow, error);
4266 TAILQ_INSERT_TAIL(list, flow, next);
4267 flow_rxq_flags_set(dev, flow);
4271 mlx5_flow_id_release(priv->sh->flow_id_pool,
4276 flow_mreg_del_copy_action(dev, flow);
4277 ret = rte_errno; /* Save rte_errno before cleanup. */
4278 if (flow->hairpin_flow_id)
4279 mlx5_flow_id_release(priv->sh->flow_id_pool,
4280 flow->hairpin_flow_id);
4282 flow_drv_destroy(dev, flow);
4284 rte_errno = ret; /* Restore rte_errno. */
4289 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
4290 * incoming packets to table 1.
4292 * Other flow rules, requested for group n, will be created in
4293 * e-switch table n+1.
4294 * Jump action to e-switch group n will be created to group n+1.
4296 * Used when working in switchdev mode, to utilise advantages of table 1
4300 * Pointer to Ethernet device.
4303 * Pointer to flow on success, NULL otherwise and rte_errno is set.
4306 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
4308 const struct rte_flow_attr attr = {
4315 const struct rte_flow_item pattern = {
4316 .type = RTE_FLOW_ITEM_TYPE_END,
4318 struct rte_flow_action_jump jump = {
4321 const struct rte_flow_action actions[] = {
4323 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4327 .type = RTE_FLOW_ACTION_TYPE_END,
4330 struct mlx5_priv *priv = dev->data->dev_private;
4331 struct rte_flow_error error;
4333 return flow_list_create(dev, &priv->ctrl_flows, &attr, &pattern,
4334 actions, false, &error);
4340 * @see rte_flow_create()
4344 mlx5_flow_create(struct rte_eth_dev *dev,
4345 const struct rte_flow_attr *attr,
4346 const struct rte_flow_item items[],
4347 const struct rte_flow_action actions[],
4348 struct rte_flow_error *error)
4350 struct mlx5_priv *priv = dev->data->dev_private;
4352 return flow_list_create(dev, &priv->flows,
4353 attr, items, actions, true, error);
4357 * Destroy a flow in a list.
4360 * Pointer to Ethernet device.
4362 * Pointer to a TAILQ flow list. If this parameter NULL,
4363 * there is no flow removal from the list.
4368 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
4369 struct rte_flow *flow)
4371 struct mlx5_priv *priv = dev->data->dev_private;
4374 * Update RX queue flags only if port is started, otherwise it is
4377 if (dev->data->dev_started)
4378 flow_rxq_flags_trim(dev, flow);
4379 if (flow->hairpin_flow_id)
4380 mlx5_flow_id_release(priv->sh->flow_id_pool,
4381 flow->hairpin_flow_id);
4382 flow_drv_destroy(dev, flow);
4384 TAILQ_REMOVE(list, flow, next);
4385 flow_mreg_del_copy_action(dev, flow);
4386 rte_free(flow->fdir);
4391 * Destroy all flows.
4394 * Pointer to Ethernet device.
4396 * Pointer to a TAILQ flow list.
4399 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
4401 while (!TAILQ_EMPTY(list)) {
4402 struct rte_flow *flow;
4404 flow = TAILQ_FIRST(list);
4405 flow_list_destroy(dev, list, flow);
4413 * Pointer to Ethernet device.
4415 * Pointer to a TAILQ flow list.
4418 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
4420 struct rte_flow *flow;
4422 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next) {
4423 flow_drv_remove(dev, flow);
4424 flow_mreg_stop_copy_action(dev, flow);
4426 flow_mreg_del_default_copy_action(dev);
4427 flow_rxq_flags_clear(dev);
4434 * Pointer to Ethernet device.
4436 * Pointer to a TAILQ flow list.
4439 * 0 on success, a negative errno value otherwise and rte_errno is set.
4442 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
4444 struct rte_flow *flow;
4445 struct rte_flow_error error;
4448 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4449 ret = flow_mreg_add_default_copy_action(dev, &error);
4452 /* Apply Flows created by application. */
4453 TAILQ_FOREACH(flow, list, next) {
4454 ret = flow_mreg_start_copy_action(dev, flow);
4457 ret = flow_drv_apply(dev, flow, &error);
4460 flow_rxq_flags_set(dev, flow);
4464 ret = rte_errno; /* Save rte_errno before cleanup. */
4465 mlx5_flow_stop(dev, list);
4466 rte_errno = ret; /* Restore rte_errno. */
4471 * Verify the flow list is empty
4474 * Pointer to Ethernet device.
4476 * @return the number of flows not released.
4479 mlx5_flow_verify(struct rte_eth_dev *dev)
4481 struct mlx5_priv *priv = dev->data->dev_private;
4482 struct rte_flow *flow;
4485 TAILQ_FOREACH(flow, &priv->flows, next) {
4486 DRV_LOG(DEBUG, "port %u flow %p still referenced",
4487 dev->data->port_id, (void *)flow);
4494 * Enable default hairpin egress flow.
4497 * Pointer to Ethernet device.
4502 * 0 on success, a negative errno value otherwise and rte_errno is set.
4505 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
4508 struct mlx5_priv *priv = dev->data->dev_private;
4509 const struct rte_flow_attr attr = {
4513 struct mlx5_rte_flow_item_tx_queue queue_spec = {
4516 struct mlx5_rte_flow_item_tx_queue queue_mask = {
4517 .queue = UINT32_MAX,
4519 struct rte_flow_item items[] = {
4521 .type = MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
4522 .spec = &queue_spec,
4524 .mask = &queue_mask,
4527 .type = RTE_FLOW_ITEM_TYPE_END,
4530 struct rte_flow_action_jump jump = {
4531 .group = MLX5_HAIRPIN_TX_TABLE,
4533 struct rte_flow_action actions[2];
4534 struct rte_flow *flow;
4535 struct rte_flow_error error;
4537 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
4538 actions[0].conf = &jump;
4539 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
4540 flow = flow_list_create(dev, &priv->ctrl_flows,
4541 &attr, items, actions, false, &error);
4544 "Failed to create ctrl flow: rte_errno(%d),"
4545 " type(%d), message(%s)",
4546 rte_errno, error.type,
4547 error.message ? error.message : " (no stated reason)");
4554 * Enable a control flow configured from the control plane.
4557 * Pointer to Ethernet device.
4559 * An Ethernet flow spec to apply.
4561 * An Ethernet flow mask to apply.
4563 * A VLAN flow spec to apply.
4565 * A VLAN flow mask to apply.
4568 * 0 on success, a negative errno value otherwise and rte_errno is set.
4571 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
4572 struct rte_flow_item_eth *eth_spec,
4573 struct rte_flow_item_eth *eth_mask,
4574 struct rte_flow_item_vlan *vlan_spec,
4575 struct rte_flow_item_vlan *vlan_mask)
4577 struct mlx5_priv *priv = dev->data->dev_private;
4578 const struct rte_flow_attr attr = {
4580 .priority = MLX5_FLOW_PRIO_RSVD,
4582 struct rte_flow_item items[] = {
4584 .type = RTE_FLOW_ITEM_TYPE_ETH,
4590 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
4591 RTE_FLOW_ITEM_TYPE_END,
4597 .type = RTE_FLOW_ITEM_TYPE_END,
4600 uint16_t queue[priv->reta_idx_n];
4601 struct rte_flow_action_rss action_rss = {
4602 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4604 .types = priv->rss_conf.rss_hf,
4605 .key_len = priv->rss_conf.rss_key_len,
4606 .queue_num = priv->reta_idx_n,
4607 .key = priv->rss_conf.rss_key,
4610 struct rte_flow_action actions[] = {
4612 .type = RTE_FLOW_ACTION_TYPE_RSS,
4613 .conf = &action_rss,
4616 .type = RTE_FLOW_ACTION_TYPE_END,
4619 struct rte_flow *flow;
4620 struct rte_flow_error error;
4623 if (!priv->reta_idx_n || !priv->rxqs_n) {
4626 for (i = 0; i != priv->reta_idx_n; ++i)
4627 queue[i] = (*priv->reta_idx)[i];
4628 flow = flow_list_create(dev, &priv->ctrl_flows,
4629 &attr, items, actions, false, &error);
4636 * Enable a flow control configured from the control plane.
4639 * Pointer to Ethernet device.
4641 * An Ethernet flow spec to apply.
4643 * An Ethernet flow mask to apply.
4646 * 0 on success, a negative errno value otherwise and rte_errno is set.
4649 mlx5_ctrl_flow(struct rte_eth_dev *dev,
4650 struct rte_flow_item_eth *eth_spec,
4651 struct rte_flow_item_eth *eth_mask)
4653 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
4659 * @see rte_flow_destroy()
4663 mlx5_flow_destroy(struct rte_eth_dev *dev,
4664 struct rte_flow *flow,
4665 struct rte_flow_error *error __rte_unused)
4667 struct mlx5_priv *priv = dev->data->dev_private;
4669 flow_list_destroy(dev, &priv->flows, flow);
4674 * Destroy all flows.
4676 * @see rte_flow_flush()
4680 mlx5_flow_flush(struct rte_eth_dev *dev,
4681 struct rte_flow_error *error __rte_unused)
4683 struct mlx5_priv *priv = dev->data->dev_private;
4685 mlx5_flow_list_flush(dev, &priv->flows);
4692 * @see rte_flow_isolate()
4696 mlx5_flow_isolate(struct rte_eth_dev *dev,
4698 struct rte_flow_error *error)
4700 struct mlx5_priv *priv = dev->data->dev_private;
4702 if (dev->data->dev_started) {
4703 rte_flow_error_set(error, EBUSY,
4704 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4706 "port must be stopped first");
4709 priv->isolated = !!enable;
4711 dev->dev_ops = &mlx5_dev_ops_isolate;
4713 dev->dev_ops = &mlx5_dev_ops;
4720 * @see rte_flow_query()
4724 flow_drv_query(struct rte_eth_dev *dev,
4725 struct rte_flow *flow,
4726 const struct rte_flow_action *actions,
4728 struct rte_flow_error *error)
4730 const struct mlx5_flow_driver_ops *fops;
4731 enum mlx5_flow_drv_type ftype = flow->drv_type;
4733 assert(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
4734 fops = flow_get_drv_ops(ftype);
4736 return fops->query(dev, flow, actions, data, error);
4742 * @see rte_flow_query()
4746 mlx5_flow_query(struct rte_eth_dev *dev,
4747 struct rte_flow *flow,
4748 const struct rte_flow_action *actions,
4750 struct rte_flow_error *error)
4754 ret = flow_drv_query(dev, flow, actions, data, error);
4761 * Convert a flow director filter to a generic flow.
4764 * Pointer to Ethernet device.
4765 * @param fdir_filter
4766 * Flow director filter to add.
4768 * Generic flow parameters structure.
4771 * 0 on success, a negative errno value otherwise and rte_errno is set.
4774 flow_fdir_filter_convert(struct rte_eth_dev *dev,
4775 const struct rte_eth_fdir_filter *fdir_filter,
4776 struct mlx5_fdir *attributes)
4778 struct mlx5_priv *priv = dev->data->dev_private;
4779 const struct rte_eth_fdir_input *input = &fdir_filter->input;
4780 const struct rte_eth_fdir_masks *mask =
4781 &dev->data->dev_conf.fdir_conf.mask;
4783 /* Validate queue number. */
4784 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
4785 DRV_LOG(ERR, "port %u invalid queue number %d",
4786 dev->data->port_id, fdir_filter->action.rx_queue);
4790 attributes->attr.ingress = 1;
4791 attributes->items[0] = (struct rte_flow_item) {
4792 .type = RTE_FLOW_ITEM_TYPE_ETH,
4793 .spec = &attributes->l2,
4794 .mask = &attributes->l2_mask,
4796 switch (fdir_filter->action.behavior) {
4797 case RTE_ETH_FDIR_ACCEPT:
4798 attributes->actions[0] = (struct rte_flow_action){
4799 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
4800 .conf = &attributes->queue,
4803 case RTE_ETH_FDIR_REJECT:
4804 attributes->actions[0] = (struct rte_flow_action){
4805 .type = RTE_FLOW_ACTION_TYPE_DROP,
4809 DRV_LOG(ERR, "port %u invalid behavior %d",
4811 fdir_filter->action.behavior);
4812 rte_errno = ENOTSUP;
4815 attributes->queue.index = fdir_filter->action.rx_queue;
4817 switch (fdir_filter->input.flow_type) {
4818 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4819 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4820 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
4821 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
4822 .src_addr = input->flow.ip4_flow.src_ip,
4823 .dst_addr = input->flow.ip4_flow.dst_ip,
4824 .time_to_live = input->flow.ip4_flow.ttl,
4825 .type_of_service = input->flow.ip4_flow.tos,
4827 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
4828 .src_addr = mask->ipv4_mask.src_ip,
4829 .dst_addr = mask->ipv4_mask.dst_ip,
4830 .time_to_live = mask->ipv4_mask.ttl,
4831 .type_of_service = mask->ipv4_mask.tos,
4832 .next_proto_id = mask->ipv4_mask.proto,
4834 attributes->items[1] = (struct rte_flow_item){
4835 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4836 .spec = &attributes->l3,
4837 .mask = &attributes->l3_mask,
4840 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
4841 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
4842 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
4843 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
4844 .hop_limits = input->flow.ipv6_flow.hop_limits,
4845 .proto = input->flow.ipv6_flow.proto,
4848 memcpy(attributes->l3.ipv6.hdr.src_addr,
4849 input->flow.ipv6_flow.src_ip,
4850 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4851 memcpy(attributes->l3.ipv6.hdr.dst_addr,
4852 input->flow.ipv6_flow.dst_ip,
4853 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4854 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
4855 mask->ipv6_mask.src_ip,
4856 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4857 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
4858 mask->ipv6_mask.dst_ip,
4859 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4860 attributes->items[1] = (struct rte_flow_item){
4861 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4862 .spec = &attributes->l3,
4863 .mask = &attributes->l3_mask,
4867 DRV_LOG(ERR, "port %u invalid flow type%d",
4868 dev->data->port_id, fdir_filter->input.flow_type);
4869 rte_errno = ENOTSUP;
4873 switch (fdir_filter->input.flow_type) {
4874 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4875 attributes->l4.udp.hdr = (struct rte_udp_hdr){
4876 .src_port = input->flow.udp4_flow.src_port,
4877 .dst_port = input->flow.udp4_flow.dst_port,
4879 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
4880 .src_port = mask->src_port_mask,
4881 .dst_port = mask->dst_port_mask,
4883 attributes->items[2] = (struct rte_flow_item){
4884 .type = RTE_FLOW_ITEM_TYPE_UDP,
4885 .spec = &attributes->l4,
4886 .mask = &attributes->l4_mask,
4889 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4890 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
4891 .src_port = input->flow.tcp4_flow.src_port,
4892 .dst_port = input->flow.tcp4_flow.dst_port,
4894 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
4895 .src_port = mask->src_port_mask,
4896 .dst_port = mask->dst_port_mask,
4898 attributes->items[2] = (struct rte_flow_item){
4899 .type = RTE_FLOW_ITEM_TYPE_TCP,
4900 .spec = &attributes->l4,
4901 .mask = &attributes->l4_mask,
4904 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
4905 attributes->l4.udp.hdr = (struct rte_udp_hdr){
4906 .src_port = input->flow.udp6_flow.src_port,
4907 .dst_port = input->flow.udp6_flow.dst_port,
4909 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
4910 .src_port = mask->src_port_mask,
4911 .dst_port = mask->dst_port_mask,
4913 attributes->items[2] = (struct rte_flow_item){
4914 .type = RTE_FLOW_ITEM_TYPE_UDP,
4915 .spec = &attributes->l4,
4916 .mask = &attributes->l4_mask,
4919 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
4920 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
4921 .src_port = input->flow.tcp6_flow.src_port,
4922 .dst_port = input->flow.tcp6_flow.dst_port,
4924 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
4925 .src_port = mask->src_port_mask,
4926 .dst_port = mask->dst_port_mask,
4928 attributes->items[2] = (struct rte_flow_item){
4929 .type = RTE_FLOW_ITEM_TYPE_TCP,
4930 .spec = &attributes->l4,
4931 .mask = &attributes->l4_mask,
4934 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
4935 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
4938 DRV_LOG(ERR, "port %u invalid flow type%d",
4939 dev->data->port_id, fdir_filter->input.flow_type);
4940 rte_errno = ENOTSUP;
4946 #define FLOW_FDIR_CMP(f1, f2, fld) \
4947 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
4950 * Compare two FDIR flows. If items and actions are identical, the two flows are
4954 * Pointer to Ethernet device.
4956 * FDIR flow to compare.
4958 * FDIR flow to compare.
4961 * Zero on match, 1 otherwise.
4964 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
4966 if (FLOW_FDIR_CMP(f1, f2, attr) ||
4967 FLOW_FDIR_CMP(f1, f2, l2) ||
4968 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
4969 FLOW_FDIR_CMP(f1, f2, l3) ||
4970 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
4971 FLOW_FDIR_CMP(f1, f2, l4) ||
4972 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
4973 FLOW_FDIR_CMP(f1, f2, actions[0].type))
4975 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
4976 FLOW_FDIR_CMP(f1, f2, queue))
4982 * Search device flow list to find out a matched FDIR flow.
4985 * Pointer to Ethernet device.
4987 * FDIR flow to lookup.
4990 * Pointer of flow if found, NULL otherwise.
4992 static struct rte_flow *
4993 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
4995 struct mlx5_priv *priv = dev->data->dev_private;
4996 struct rte_flow *flow = NULL;
4999 TAILQ_FOREACH(flow, &priv->flows, next) {
5000 if (flow->fdir && !flow_fdir_cmp(flow->fdir, fdir_flow)) {
5001 DRV_LOG(DEBUG, "port %u found FDIR flow %p",
5002 dev->data->port_id, (void *)flow);
5010 * Add new flow director filter and store it in list.
5013 * Pointer to Ethernet device.
5014 * @param fdir_filter
5015 * Flow director filter to add.
5018 * 0 on success, a negative errno value otherwise and rte_errno is set.
5021 flow_fdir_filter_add(struct rte_eth_dev *dev,
5022 const struct rte_eth_fdir_filter *fdir_filter)
5024 struct mlx5_priv *priv = dev->data->dev_private;
5025 struct mlx5_fdir *fdir_flow;
5026 struct rte_flow *flow;
5029 fdir_flow = rte_zmalloc(__func__, sizeof(*fdir_flow), 0);
5034 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
5037 flow = flow_fdir_filter_lookup(dev, fdir_flow);
5042 flow = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
5043 fdir_flow->items, fdir_flow->actions, true,
5047 assert(!flow->fdir);
5048 flow->fdir = fdir_flow;
5049 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
5050 dev->data->port_id, (void *)flow);
5053 rte_free(fdir_flow);
5058 * Delete specific filter.
5061 * Pointer to Ethernet device.
5062 * @param fdir_filter
5063 * Filter to be deleted.
5066 * 0 on success, a negative errno value otherwise and rte_errno is set.
5069 flow_fdir_filter_delete(struct rte_eth_dev *dev,
5070 const struct rte_eth_fdir_filter *fdir_filter)
5072 struct mlx5_priv *priv = dev->data->dev_private;
5073 struct rte_flow *flow;
5074 struct mlx5_fdir fdir_flow = {
5079 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
5082 flow = flow_fdir_filter_lookup(dev, &fdir_flow);
5087 flow_list_destroy(dev, &priv->flows, flow);
5088 DRV_LOG(DEBUG, "port %u deleted FDIR flow %p",
5089 dev->data->port_id, (void *)flow);
5094 * Update queue for specific filter.
5097 * Pointer to Ethernet device.
5098 * @param fdir_filter
5099 * Filter to be updated.
5102 * 0 on success, a negative errno value otherwise and rte_errno is set.
5105 flow_fdir_filter_update(struct rte_eth_dev *dev,
5106 const struct rte_eth_fdir_filter *fdir_filter)
5110 ret = flow_fdir_filter_delete(dev, fdir_filter);
5113 return flow_fdir_filter_add(dev, fdir_filter);
5117 * Flush all filters.
5120 * Pointer to Ethernet device.
5123 flow_fdir_filter_flush(struct rte_eth_dev *dev)
5125 struct mlx5_priv *priv = dev->data->dev_private;
5127 mlx5_flow_list_flush(dev, &priv->flows);
5131 * Get flow director information.
5134 * Pointer to Ethernet device.
5135 * @param[out] fdir_info
5136 * Resulting flow director information.
5139 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
5141 struct rte_eth_fdir_masks *mask =
5142 &dev->data->dev_conf.fdir_conf.mask;
5144 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
5145 fdir_info->guarant_spc = 0;
5146 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
5147 fdir_info->max_flexpayload = 0;
5148 fdir_info->flow_types_mask[0] = 0;
5149 fdir_info->flex_payload_unit = 0;
5150 fdir_info->max_flex_payload_segment_num = 0;
5151 fdir_info->flex_payload_limit = 0;
5152 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
5156 * Deal with flow director operations.
5159 * Pointer to Ethernet device.
5161 * Operation to perform.
5163 * Pointer to operation-specific structure.
5166 * 0 on success, a negative errno value otherwise and rte_errno is set.
5169 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
5172 enum rte_fdir_mode fdir_mode =
5173 dev->data->dev_conf.fdir_conf.mode;
5175 if (filter_op == RTE_ETH_FILTER_NOP)
5177 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
5178 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5179 DRV_LOG(ERR, "port %u flow director mode %d not supported",
5180 dev->data->port_id, fdir_mode);
5184 switch (filter_op) {
5185 case RTE_ETH_FILTER_ADD:
5186 return flow_fdir_filter_add(dev, arg);
5187 case RTE_ETH_FILTER_UPDATE:
5188 return flow_fdir_filter_update(dev, arg);
5189 case RTE_ETH_FILTER_DELETE:
5190 return flow_fdir_filter_delete(dev, arg);
5191 case RTE_ETH_FILTER_FLUSH:
5192 flow_fdir_filter_flush(dev);
5194 case RTE_ETH_FILTER_INFO:
5195 flow_fdir_info_get(dev, arg);
5198 DRV_LOG(DEBUG, "port %u unknown operation %u",
5199 dev->data->port_id, filter_op);
5207 * Manage filter operations.
5210 * Pointer to Ethernet device structure.
5211 * @param filter_type
5214 * Operation to perform.
5216 * Pointer to operation-specific structure.
5219 * 0 on success, a negative errno value otherwise and rte_errno is set.
5222 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
5223 enum rte_filter_type filter_type,
5224 enum rte_filter_op filter_op,
5227 switch (filter_type) {
5228 case RTE_ETH_FILTER_GENERIC:
5229 if (filter_op != RTE_ETH_FILTER_GET) {
5233 *(const void **)arg = &mlx5_flow_ops;
5235 case RTE_ETH_FILTER_FDIR:
5236 return flow_fdir_ctrl_func(dev, filter_op, arg);
5238 DRV_LOG(ERR, "port %u filter type (%d) not supported",
5239 dev->data->port_id, filter_type);
5240 rte_errno = ENOTSUP;
5247 * Create the needed meter and suffix tables.
5250 * Pointer to Ethernet device.
5252 * Pointer to the flow meter.
5255 * Pointer to table set on success, NULL otherwise.
5257 struct mlx5_meter_domains_infos *
5258 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
5259 const struct mlx5_flow_meter *fm)
5261 const struct mlx5_flow_driver_ops *fops;
5263 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5264 return fops->create_mtr_tbls(dev, fm);
5268 * Destroy the meter table set.
5271 * Pointer to Ethernet device.
5273 * Pointer to the meter table set.
5279 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
5280 struct mlx5_meter_domains_infos *tbls)
5282 const struct mlx5_flow_driver_ops *fops;
5284 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5285 return fops->destroy_mtr_tbls(dev, tbls);
5289 * Create policer rules.
5292 * Pointer to Ethernet device.
5294 * Pointer to flow meter structure.
5296 * Pointer to flow attributes.
5299 * 0 on success, -1 otherwise.
5302 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
5303 struct mlx5_flow_meter *fm,
5304 const struct rte_flow_attr *attr)
5306 const struct mlx5_flow_driver_ops *fops;
5308 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5309 return fops->create_policer_rules(dev, fm, attr);
5313 * Destroy policer rules.
5316 * Pointer to flow meter structure.
5318 * Pointer to flow attributes.
5321 * 0 on success, -1 otherwise.
5324 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
5325 struct mlx5_flow_meter *fm,
5326 const struct rte_flow_attr *attr)
5328 const struct mlx5_flow_driver_ops *fops;
5330 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5331 return fops->destroy_policer_rules(dev, fm, attr);
5335 * Allocate a counter.
5338 * Pointer to Ethernet device structure.
5341 * Pointer to allocated counter on success, NULL otherwise.
5343 struct mlx5_flow_counter *
5344 mlx5_counter_alloc(struct rte_eth_dev *dev)
5346 const struct mlx5_flow_driver_ops *fops;
5347 struct rte_flow_attr attr = { .transfer = 0 };
5349 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5350 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5351 return fops->counter_alloc(dev);
5354 "port %u counter allocate is not supported.",
5355 dev->data->port_id);
5363 * Pointer to Ethernet device structure.
5365 * Pointer to counter to be free.
5368 mlx5_counter_free(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt)
5370 const struct mlx5_flow_driver_ops *fops;
5371 struct rte_flow_attr attr = { .transfer = 0 };
5373 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5374 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5375 fops->counter_free(dev, cnt);
5379 "port %u counter free is not supported.",
5380 dev->data->port_id);
5384 * Query counter statistics.
5387 * Pointer to Ethernet device structure.
5389 * Pointer to counter to query.
5391 * Set to clear counter statistics.
5393 * The counter hits packets number to save.
5395 * The counter hits bytes number to save.
5398 * 0 on success, a negative errno value otherwise.
5401 mlx5_counter_query(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt,
5402 bool clear, uint64_t *pkts, uint64_t *bytes)
5404 const struct mlx5_flow_driver_ops *fops;
5405 struct rte_flow_attr attr = { .transfer = 0 };
5407 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5408 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5409 return fops->counter_query(dev, cnt, clear, pkts, bytes);
5412 "port %u counter query is not supported.",
5413 dev->data->port_id);
5417 #define MLX5_POOL_QUERY_FREQ_US 1000000
5420 * Set the periodic procedure for triggering asynchronous batch queries for all
5421 * the counter pools.
5424 * Pointer to mlx5_ibv_shared object.
5427 mlx5_set_query_alarm(struct mlx5_ibv_shared *sh)
5429 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(sh, 0, 0);
5430 uint32_t pools_n = rte_atomic16_read(&cont->n_valid);
5433 cont = MLX5_CNT_CONTAINER(sh, 1, 0);
5434 pools_n += rte_atomic16_read(&cont->n_valid);
5435 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
5436 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
5437 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
5438 sh->cmng.query_thread_on = 0;
5439 DRV_LOG(ERR, "Cannot reinitialize query alarm");
5441 sh->cmng.query_thread_on = 1;
5446 * The periodic procedure for triggering asynchronous batch queries for all the
5447 * counter pools. This function is probably called by the host thread.
5450 * The parameter for the alarm process.
5453 mlx5_flow_query_alarm(void *arg)
5455 struct mlx5_ibv_shared *sh = arg;
5456 struct mlx5_devx_obj *dcs;
5459 uint8_t batch = sh->cmng.batch;
5460 uint16_t pool_index = sh->cmng.pool_index;
5461 struct mlx5_pools_container *cont;
5462 struct mlx5_pools_container *mcont;
5463 struct mlx5_flow_counter_pool *pool;
5465 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
5468 cont = MLX5_CNT_CONTAINER(sh, batch, 1);
5469 mcont = MLX5_CNT_CONTAINER(sh, batch, 0);
5470 /* Check if resize was done and need to flip a container. */
5471 if (cont != mcont) {
5473 /* Clean the old container. */
5474 rte_free(cont->pools);
5475 memset(cont, 0, sizeof(*cont));
5478 /* Flip the host container. */
5479 sh->cmng.mhi[batch] ^= (uint8_t)2;
5483 /* 2 empty containers case is unexpected. */
5484 if (unlikely(batch != sh->cmng.batch))
5488 goto next_container;
5490 pool = cont->pools[pool_index];
5492 /* There is a pool query in progress. */
5495 LIST_FIRST(&sh->cmng.free_stat_raws);
5497 /* No free counter statistics raw memory. */
5499 dcs = (struct mlx5_devx_obj *)(uintptr_t)rte_atomic64_read
5501 offset = batch ? 0 : dcs->id % MLX5_COUNTERS_PER_POOL;
5502 ret = mlx5_devx_cmd_flow_counter_query(dcs, 0, MLX5_COUNTERS_PER_POOL -
5504 pool->raw_hw->mem_mng->dm->id,
5506 (pool->raw_hw->data + offset),
5508 (uint64_t)(uintptr_t)pool);
5510 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
5511 " %d", pool->min_dcs->id);
5512 pool->raw_hw = NULL;
5515 pool->raw_hw->min_dcs_id = dcs->id;
5516 LIST_REMOVE(pool->raw_hw, next);
5517 sh->cmng.pending_queries++;
5519 if (pool_index >= rte_atomic16_read(&cont->n_valid)) {
5524 sh->cmng.batch = batch;
5525 sh->cmng.pool_index = pool_index;
5526 mlx5_set_query_alarm(sh);
5530 * Handler for the HW respond about ready values from an asynchronous batch
5531 * query. This function is probably called by the host thread.
5534 * The pointer to the shared IB device context.
5535 * @param[in] async_id
5536 * The Devx async ID.
5538 * The status of the completion.
5541 mlx5_flow_async_pool_query_handle(struct mlx5_ibv_shared *sh,
5542 uint64_t async_id, int status)
5544 struct mlx5_flow_counter_pool *pool =
5545 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
5546 struct mlx5_counter_stats_raw *raw_to_free;
5548 if (unlikely(status)) {
5549 raw_to_free = pool->raw_hw;
5551 raw_to_free = pool->raw;
5552 rte_spinlock_lock(&pool->sl);
5553 pool->raw = pool->raw_hw;
5554 rte_spinlock_unlock(&pool->sl);
5555 rte_atomic64_add(&pool->query_gen, 1);
5556 /* Be sure the new raw counters data is updated in memory. */
5559 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
5560 pool->raw_hw = NULL;
5561 sh->cmng.pending_queries--;
5565 * Translate the rte_flow group index to HW table value.
5567 * @param[in] attributes
5568 * Pointer to flow attributes
5569 * @param[in] external
5570 * Value is part of flow rule created by request external to PMD.
5572 * rte_flow group index value.
5576 * Pointer to error structure.
5579 * 0 on success, a negative errno value otherwise and rte_errno is set.
5582 mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, bool external,
5583 uint32_t group, uint32_t *table,
5584 struct rte_flow_error *error)
5586 if (attributes->transfer && external) {
5587 if (group == UINT32_MAX)
5588 return rte_flow_error_set
5590 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5592 "group index not supported");
5601 * Discover availability of metadata reg_c's.
5603 * Iteratively use test flows to check availability.
5606 * Pointer to the Ethernet device structure.
5609 * 0 on success, a negative errno value otherwise and rte_errno is set.
5612 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
5614 struct mlx5_priv *priv = dev->data->dev_private;
5615 struct mlx5_dev_config *config = &priv->config;
5616 enum modify_reg idx;
5619 /* reg_c[0] and reg_c[1] are reserved. */
5620 config->flow_mreg_c[n++] = REG_C_0;
5621 config->flow_mreg_c[n++] = REG_C_1;
5622 /* Discover availability of other reg_c's. */
5623 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
5624 struct rte_flow_attr attr = {
5625 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5626 .priority = MLX5_FLOW_PRIO_RSVD,
5629 struct rte_flow_item items[] = {
5631 .type = RTE_FLOW_ITEM_TYPE_END,
5634 struct rte_flow_action actions[] = {
5636 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5637 .conf = &(struct mlx5_flow_action_copy_mreg){
5643 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5644 .conf = &(struct rte_flow_action_jump){
5645 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5649 .type = RTE_FLOW_ACTION_TYPE_END,
5652 struct rte_flow *flow;
5653 struct rte_flow_error error;
5655 if (!config->dv_flow_en)
5657 /* Create internal flow, validation skips copy action. */
5658 flow = flow_list_create(dev, NULL, &attr, items,
5659 actions, false, &error);
5662 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
5663 config->flow_mreg_c[n++] = idx;
5664 flow_list_destroy(dev, NULL, flow);
5666 for (; n < MLX5_MREG_C_NUM; ++n)
5667 config->flow_mreg_c[n] = REG_NONE;