1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
6 #include <netinet/in.h>
13 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
15 #pragma GCC diagnostic ignored "-Wpedantic"
17 #include <infiniband/verbs.h>
19 #pragma GCC diagnostic error "-Wpedantic"
22 #include <rte_common.h>
23 #include <rte_ether.h>
24 #include <rte_ethdev_driver.h>
26 #include <rte_flow_driver.h>
27 #include <rte_malloc.h>
31 #include "mlx5_defs.h"
32 #include "mlx5_flow.h"
33 #include "mlx5_glue.h"
35 #include "mlx5_rxtx.h"
37 /* Dev ops structure defined in mlx5.c */
38 extern const struct eth_dev_ops mlx5_dev_ops;
39 extern const struct eth_dev_ops mlx5_dev_ops_isolate;
41 /** Device flow drivers. */
42 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
43 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
45 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
47 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
49 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
50 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
51 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
52 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
54 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
55 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
60 MLX5_EXPANSION_ROOT_OUTER,
61 MLX5_EXPANSION_ROOT_ETH_VLAN,
62 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
63 MLX5_EXPANSION_OUTER_ETH,
64 MLX5_EXPANSION_OUTER_ETH_VLAN,
65 MLX5_EXPANSION_OUTER_VLAN,
66 MLX5_EXPANSION_OUTER_IPV4,
67 MLX5_EXPANSION_OUTER_IPV4_UDP,
68 MLX5_EXPANSION_OUTER_IPV4_TCP,
69 MLX5_EXPANSION_OUTER_IPV6,
70 MLX5_EXPANSION_OUTER_IPV6_UDP,
71 MLX5_EXPANSION_OUTER_IPV6_TCP,
73 MLX5_EXPANSION_VXLAN_GPE,
77 MLX5_EXPANSION_ETH_VLAN,
80 MLX5_EXPANSION_IPV4_UDP,
81 MLX5_EXPANSION_IPV4_TCP,
83 MLX5_EXPANSION_IPV6_UDP,
84 MLX5_EXPANSION_IPV6_TCP,
87 /** Supported expansion of items. */
88 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
89 [MLX5_EXPANSION_ROOT] = {
90 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
93 .type = RTE_FLOW_ITEM_TYPE_END,
95 [MLX5_EXPANSION_ROOT_OUTER] = {
96 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
97 MLX5_EXPANSION_OUTER_IPV4,
98 MLX5_EXPANSION_OUTER_IPV6),
99 .type = RTE_FLOW_ITEM_TYPE_END,
101 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
102 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
103 .type = RTE_FLOW_ITEM_TYPE_END,
105 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
106 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
107 .type = RTE_FLOW_ITEM_TYPE_END,
109 [MLX5_EXPANSION_OUTER_ETH] = {
110 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
111 MLX5_EXPANSION_OUTER_IPV6,
112 MLX5_EXPANSION_MPLS),
113 .type = RTE_FLOW_ITEM_TYPE_ETH,
116 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
117 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
118 .type = RTE_FLOW_ITEM_TYPE_ETH,
121 [MLX5_EXPANSION_OUTER_VLAN] = {
122 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
123 MLX5_EXPANSION_OUTER_IPV6),
124 .type = RTE_FLOW_ITEM_TYPE_VLAN,
126 [MLX5_EXPANSION_OUTER_IPV4] = {
127 .next = RTE_FLOW_EXPAND_RSS_NEXT
128 (MLX5_EXPANSION_OUTER_IPV4_UDP,
129 MLX5_EXPANSION_OUTER_IPV4_TCP,
132 MLX5_EXPANSION_IPV6),
133 .type = RTE_FLOW_ITEM_TYPE_IPV4,
134 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
135 ETH_RSS_NONFRAG_IPV4_OTHER,
137 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
138 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
139 MLX5_EXPANSION_VXLAN_GPE),
140 .type = RTE_FLOW_ITEM_TYPE_UDP,
141 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
143 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
144 .type = RTE_FLOW_ITEM_TYPE_TCP,
145 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
147 [MLX5_EXPANSION_OUTER_IPV6] = {
148 .next = RTE_FLOW_EXPAND_RSS_NEXT
149 (MLX5_EXPANSION_OUTER_IPV6_UDP,
150 MLX5_EXPANSION_OUTER_IPV6_TCP,
152 MLX5_EXPANSION_IPV6),
153 .type = RTE_FLOW_ITEM_TYPE_IPV6,
154 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
155 ETH_RSS_NONFRAG_IPV6_OTHER,
157 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
158 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
159 MLX5_EXPANSION_VXLAN_GPE),
160 .type = RTE_FLOW_ITEM_TYPE_UDP,
161 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
163 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
164 .type = RTE_FLOW_ITEM_TYPE_TCP,
165 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
167 [MLX5_EXPANSION_VXLAN] = {
168 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
169 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
171 [MLX5_EXPANSION_VXLAN_GPE] = {
172 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
174 MLX5_EXPANSION_IPV6),
175 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
177 [MLX5_EXPANSION_GRE] = {
178 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
179 .type = RTE_FLOW_ITEM_TYPE_GRE,
181 [MLX5_EXPANSION_MPLS] = {
182 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
183 MLX5_EXPANSION_IPV6),
184 .type = RTE_FLOW_ITEM_TYPE_MPLS,
186 [MLX5_EXPANSION_ETH] = {
187 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
188 MLX5_EXPANSION_IPV6),
189 .type = RTE_FLOW_ITEM_TYPE_ETH,
191 [MLX5_EXPANSION_ETH_VLAN] = {
192 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
193 .type = RTE_FLOW_ITEM_TYPE_ETH,
195 [MLX5_EXPANSION_VLAN] = {
196 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
197 MLX5_EXPANSION_IPV6),
198 .type = RTE_FLOW_ITEM_TYPE_VLAN,
200 [MLX5_EXPANSION_IPV4] = {
201 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
202 MLX5_EXPANSION_IPV4_TCP),
203 .type = RTE_FLOW_ITEM_TYPE_IPV4,
204 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
205 ETH_RSS_NONFRAG_IPV4_OTHER,
207 [MLX5_EXPANSION_IPV4_UDP] = {
208 .type = RTE_FLOW_ITEM_TYPE_UDP,
209 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
211 [MLX5_EXPANSION_IPV4_TCP] = {
212 .type = RTE_FLOW_ITEM_TYPE_TCP,
213 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
215 [MLX5_EXPANSION_IPV6] = {
216 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
217 MLX5_EXPANSION_IPV6_TCP),
218 .type = RTE_FLOW_ITEM_TYPE_IPV6,
219 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
220 ETH_RSS_NONFRAG_IPV6_OTHER,
222 [MLX5_EXPANSION_IPV6_UDP] = {
223 .type = RTE_FLOW_ITEM_TYPE_UDP,
224 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
226 [MLX5_EXPANSION_IPV6_TCP] = {
227 .type = RTE_FLOW_ITEM_TYPE_TCP,
228 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
232 static const struct rte_flow_ops mlx5_flow_ops = {
233 .validate = mlx5_flow_validate,
234 .create = mlx5_flow_create,
235 .destroy = mlx5_flow_destroy,
236 .flush = mlx5_flow_flush,
237 .isolate = mlx5_flow_isolate,
238 .query = mlx5_flow_query,
239 .dev_dump = mlx5_flow_dev_dump,
242 /* Convert FDIR request to Generic flow. */
244 struct rte_flow_attr attr;
245 struct rte_flow_item items[4];
246 struct rte_flow_item_eth l2;
247 struct rte_flow_item_eth l2_mask;
249 struct rte_flow_item_ipv4 ipv4;
250 struct rte_flow_item_ipv6 ipv6;
253 struct rte_flow_item_ipv4 ipv4;
254 struct rte_flow_item_ipv6 ipv6;
257 struct rte_flow_item_udp udp;
258 struct rte_flow_item_tcp tcp;
261 struct rte_flow_item_udp udp;
262 struct rte_flow_item_tcp tcp;
264 struct rte_flow_action actions[2];
265 struct rte_flow_action_queue queue;
268 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
269 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
270 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
273 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
274 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
275 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
276 { 9, 10, 11 }, { 12, 13, 14 },
279 /* Tunnel information. */
280 struct mlx5_flow_tunnel_info {
281 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
282 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
285 static struct mlx5_flow_tunnel_info tunnels_info[] = {
287 .tunnel = MLX5_FLOW_LAYER_VXLAN,
288 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
291 .tunnel = MLX5_FLOW_LAYER_GENEVE,
292 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
295 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
296 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
299 .tunnel = MLX5_FLOW_LAYER_GRE,
300 .ptype = RTE_PTYPE_TUNNEL_GRE,
303 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
304 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
307 .tunnel = MLX5_FLOW_LAYER_MPLS,
308 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
311 .tunnel = MLX5_FLOW_LAYER_NVGRE,
312 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
315 .tunnel = MLX5_FLOW_LAYER_IPIP,
316 .ptype = RTE_PTYPE_TUNNEL_IP,
319 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
320 .ptype = RTE_PTYPE_TUNNEL_IP,
325 * Translate tag ID to register.
328 * Pointer to the Ethernet device structure.
330 * The feature that request the register.
332 * The request register ID.
334 * Error description in case of any.
337 * The request register on success, a negative errno
338 * value otherwise and rte_errno is set.
341 mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
342 enum mlx5_feature_name feature,
344 struct rte_flow_error *error)
346 struct mlx5_priv *priv = dev->data->dev_private;
347 struct mlx5_dev_config *config = &priv->config;
348 enum modify_reg start_reg;
351 case MLX5_HAIRPIN_RX:
353 case MLX5_HAIRPIN_TX:
355 case MLX5_METADATA_RX:
356 switch (config->dv_xmeta_en) {
357 case MLX5_XMETA_MODE_LEGACY:
359 case MLX5_XMETA_MODE_META16:
361 case MLX5_XMETA_MODE_META32:
365 case MLX5_METADATA_TX:
367 case MLX5_METADATA_FDB:
368 switch (config->dv_xmeta_en) {
369 case MLX5_XMETA_MODE_LEGACY:
371 case MLX5_XMETA_MODE_META16:
373 case MLX5_XMETA_MODE_META32:
378 switch (config->dv_xmeta_en) {
379 case MLX5_XMETA_MODE_LEGACY:
381 case MLX5_XMETA_MODE_META16:
383 case MLX5_XMETA_MODE_META32:
390 * Metadata COPY_MARK register using is in meter suffix sub
391 * flow while with meter. It's safe to share the same register.
393 return priv->mtr_color_reg != REG_C_2 ? REG_C_2 : REG_C_3;
395 RTE_ASSERT(priv->mtr_color_reg != REG_NONE);
396 return priv->mtr_color_reg;
399 * If meter is enable, it will engage two registers for color
400 * match and flow match. If meter color match is not using the
401 * REG_C_2, need to skip the REG_C_x be used by meter color
403 * If meter is disable, free to use all available registers.
405 if (priv->mtr_color_reg != REG_NONE)
406 start_reg = priv->mtr_color_reg != REG_C_2 ? REG_C_3 :
410 if (id > (REG_C_7 - start_reg))
411 return rte_flow_error_set(error, EINVAL,
412 RTE_FLOW_ERROR_TYPE_ITEM,
413 NULL, "invalid tag id");
414 if (config->flow_mreg_c[id + start_reg - REG_C_0] == REG_NONE)
415 return rte_flow_error_set(error, ENOTSUP,
416 RTE_FLOW_ERROR_TYPE_ITEM,
417 NULL, "unsupported tag id");
419 * This case means meter is using the REG_C_x great than 2.
420 * Take care not to conflict with meter color REG_C_x.
421 * If the available index REG_C_y >= REG_C_x, skip the
424 if (start_reg == REG_C_3 && config->flow_mreg_c
425 [id + REG_C_3 - REG_C_0] >= priv->mtr_color_reg) {
426 if (config->flow_mreg_c[id + 1 + REG_C_3 - REG_C_0] !=
428 return config->flow_mreg_c
429 [id + 1 + REG_C_3 - REG_C_0];
430 return rte_flow_error_set(error, ENOTSUP,
431 RTE_FLOW_ERROR_TYPE_ITEM,
432 NULL, "unsupported tag id");
434 return config->flow_mreg_c[id + start_reg - REG_C_0];
437 return rte_flow_error_set(error, EINVAL,
438 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
439 NULL, "invalid feature name");
443 * Check extensive flow metadata register support.
446 * Pointer to rte_eth_dev structure.
449 * True if device supports extensive flow metadata register, otherwise false.
452 mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
454 struct mlx5_priv *priv = dev->data->dev_private;
455 struct mlx5_dev_config *config = &priv->config;
458 * Having available reg_c can be regarded inclusively as supporting
459 * extensive flow metadata register, which could mean,
460 * - metadata register copy action by modify header.
461 * - 16 modify header actions is supported.
462 * - reg_c's are preserved across different domain (FDB and NIC) on
463 * packet loopback by flow lookup miss.
465 return config->flow_mreg_c[2] != REG_NONE;
469 * Discover the maximum number of priority available.
472 * Pointer to the Ethernet device structure.
475 * number of supported flow priority on success, a negative errno
476 * value otherwise and rte_errno is set.
479 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
481 struct mlx5_priv *priv = dev->data->dev_private;
483 struct ibv_flow_attr attr;
484 struct ibv_flow_spec_eth eth;
485 struct ibv_flow_spec_action_drop drop;
489 .port = (uint8_t)priv->ibv_port,
492 .type = IBV_FLOW_SPEC_ETH,
493 .size = sizeof(struct ibv_flow_spec_eth),
496 .size = sizeof(struct ibv_flow_spec_action_drop),
497 .type = IBV_FLOW_SPEC_ACTION_DROP,
500 struct ibv_flow *flow;
501 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
502 uint16_t vprio[] = { 8, 16 };
510 for (i = 0; i != RTE_DIM(vprio); i++) {
511 flow_attr.attr.priority = vprio[i] - 1;
512 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
515 claim_zero(mlx5_glue->destroy_flow(flow));
518 mlx5_hrxq_drop_release(dev);
521 priority = RTE_DIM(priority_map_3);
524 priority = RTE_DIM(priority_map_5);
529 "port %u verbs maximum priority: %d expected 8/16",
530 dev->data->port_id, priority);
533 DRV_LOG(INFO, "port %u flow maximum priority: %d",
534 dev->data->port_id, priority);
539 * Adjust flow priority based on the highest layer and the request priority.
542 * Pointer to the Ethernet device structure.
543 * @param[in] priority
544 * The rule base priority.
545 * @param[in] subpriority
546 * The priority based on the items.
551 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
552 uint32_t subpriority)
555 struct mlx5_priv *priv = dev->data->dev_private;
557 switch (priv->config.flow_prio) {
558 case RTE_DIM(priority_map_3):
559 res = priority_map_3[priority][subpriority];
561 case RTE_DIM(priority_map_5):
562 res = priority_map_5[priority][subpriority];
569 * Verify the @p item specifications (spec, last, mask) are compatible with the
573 * Item specification.
575 * @p item->mask or flow default bit-masks.
576 * @param[in] nic_mask
577 * Bit-masks covering supported fields by the NIC to compare with user mask.
579 * Bit-masks size in bytes.
581 * Pointer to error structure.
584 * 0 on success, a negative errno value otherwise and rte_errno is set.
587 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
589 const uint8_t *nic_mask,
591 struct rte_flow_error *error)
596 for (i = 0; i < size; ++i)
597 if ((nic_mask[i] | mask[i]) != nic_mask[i])
598 return rte_flow_error_set(error, ENOTSUP,
599 RTE_FLOW_ERROR_TYPE_ITEM,
601 "mask enables non supported"
603 if (!item->spec && (item->mask || item->last))
604 return rte_flow_error_set(error, EINVAL,
605 RTE_FLOW_ERROR_TYPE_ITEM, item,
606 "mask/last without a spec is not"
608 if (item->spec && item->last) {
614 for (i = 0; i < size; ++i) {
615 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
616 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
618 ret = memcmp(spec, last, size);
620 return rte_flow_error_set(error, EINVAL,
621 RTE_FLOW_ERROR_TYPE_ITEM,
623 "range is not valid");
629 * Adjust the hash fields according to the @p flow information.
631 * @param[in] dev_flow.
632 * Pointer to the mlx5_flow.
634 * 1 when the hash field is for a tunnel item.
635 * @param[in] layer_types
637 * @param[in] hash_fields
641 * The hash fields that should be used.
644 mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow,
645 int tunnel __rte_unused, uint64_t layer_types,
646 uint64_t hash_fields)
648 struct rte_flow *flow = dev_flow->flow;
649 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
650 int rss_request_inner = flow->rss.level >= 2;
652 /* Check RSS hash level for tunnel. */
653 if (tunnel && rss_request_inner)
654 hash_fields |= IBV_RX_HASH_INNER;
655 else if (tunnel || rss_request_inner)
658 /* Check if requested layer matches RSS hash fields. */
659 if (!(flow->rss.types & layer_types))
665 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
666 * if several tunnel rules are used on this queue, the tunnel ptype will be
670 * Rx queue to update.
673 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
676 uint32_t tunnel_ptype = 0;
678 /* Look up for the ptype to use. */
679 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
680 if (!rxq_ctrl->flow_tunnels_n[i])
683 tunnel_ptype = tunnels_info[i].ptype;
689 rxq_ctrl->rxq.tunnel = tunnel_ptype;
693 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
697 * Pointer to the Ethernet device structure.
698 * @param[in] dev_flow
699 * Pointer to device flow structure.
702 flow_drv_rxq_flags_set(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
704 struct mlx5_priv *priv = dev->data->dev_private;
705 struct rte_flow *flow = dev_flow->flow;
706 const int mark = !!(dev_flow->actions &
707 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
708 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
711 for (i = 0; i != flow->rss.queue_num; ++i) {
712 int idx = (*flow->rss.queue)[i];
713 struct mlx5_rxq_ctrl *rxq_ctrl =
714 container_of((*priv->rxqs)[idx],
715 struct mlx5_rxq_ctrl, rxq);
718 * To support metadata register copy on Tx loopback,
719 * this must be always enabled (metadata may arive
720 * from other port - not from local flows only.
722 if (priv->config.dv_flow_en &&
723 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
724 mlx5_flow_ext_mreg_supported(dev)) {
725 rxq_ctrl->rxq.mark = 1;
726 rxq_ctrl->flow_mark_n = 1;
728 rxq_ctrl->rxq.mark = 1;
729 rxq_ctrl->flow_mark_n++;
734 /* Increase the counter matching the flow. */
735 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
736 if ((tunnels_info[j].tunnel &
738 tunnels_info[j].tunnel) {
739 rxq_ctrl->flow_tunnels_n[j]++;
743 flow_rxq_tunnel_ptype_update(rxq_ctrl);
749 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
752 * Pointer to the Ethernet device structure.
754 * Pointer to flow structure.
757 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
759 struct mlx5_flow *dev_flow;
761 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
762 flow_drv_rxq_flags_set(dev, dev_flow);
766 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
767 * device flow if no other flow uses it with the same kind of request.
770 * Pointer to Ethernet device.
771 * @param[in] dev_flow
772 * Pointer to the device flow.
775 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
777 struct mlx5_priv *priv = dev->data->dev_private;
778 struct rte_flow *flow = dev_flow->flow;
779 const int mark = !!(dev_flow->actions &
780 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
781 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
784 assert(dev->data->dev_started);
785 for (i = 0; i != flow->rss.queue_num; ++i) {
786 int idx = (*flow->rss.queue)[i];
787 struct mlx5_rxq_ctrl *rxq_ctrl =
788 container_of((*priv->rxqs)[idx],
789 struct mlx5_rxq_ctrl, rxq);
791 if (priv->config.dv_flow_en &&
792 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
793 mlx5_flow_ext_mreg_supported(dev)) {
794 rxq_ctrl->rxq.mark = 1;
795 rxq_ctrl->flow_mark_n = 1;
797 rxq_ctrl->flow_mark_n--;
798 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
803 /* Decrease the counter matching the flow. */
804 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
805 if ((tunnels_info[j].tunnel &
807 tunnels_info[j].tunnel) {
808 rxq_ctrl->flow_tunnels_n[j]--;
812 flow_rxq_tunnel_ptype_update(rxq_ctrl);
818 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
819 * @p flow if no other flow uses it with the same kind of request.
822 * Pointer to Ethernet device.
824 * Pointer to the flow.
827 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
829 struct mlx5_flow *dev_flow;
831 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
832 flow_drv_rxq_flags_trim(dev, dev_flow);
836 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
839 * Pointer to Ethernet device.
842 flow_rxq_flags_clear(struct rte_eth_dev *dev)
844 struct mlx5_priv *priv = dev->data->dev_private;
847 for (i = 0; i != priv->rxqs_n; ++i) {
848 struct mlx5_rxq_ctrl *rxq_ctrl;
851 if (!(*priv->rxqs)[i])
853 rxq_ctrl = container_of((*priv->rxqs)[i],
854 struct mlx5_rxq_ctrl, rxq);
855 rxq_ctrl->flow_mark_n = 0;
856 rxq_ctrl->rxq.mark = 0;
857 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
858 rxq_ctrl->flow_tunnels_n[j] = 0;
859 rxq_ctrl->rxq.tunnel = 0;
864 * return a pointer to the desired action in the list of actions.
867 * The list of actions to search the action in.
869 * The action to find.
872 * Pointer to the action in the list, if found. NULL otherwise.
874 const struct rte_flow_action *
875 mlx5_flow_find_action(const struct rte_flow_action *actions,
876 enum rte_flow_action_type action)
880 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
881 if (actions->type == action)
887 * Validate the flag action.
889 * @param[in] action_flags
890 * Bit-fields that holds the actions detected until now.
892 * Attributes of flow that includes this action.
894 * Pointer to error structure.
897 * 0 on success, a negative errno value otherwise and rte_errno is set.
900 mlx5_flow_validate_action_flag(uint64_t action_flags,
901 const struct rte_flow_attr *attr,
902 struct rte_flow_error *error)
905 if (action_flags & MLX5_FLOW_ACTION_DROP)
906 return rte_flow_error_set(error, EINVAL,
907 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
908 "can't drop and flag in same flow");
909 if (action_flags & MLX5_FLOW_ACTION_MARK)
910 return rte_flow_error_set(error, EINVAL,
911 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
912 "can't mark and flag in same flow");
913 if (action_flags & MLX5_FLOW_ACTION_FLAG)
914 return rte_flow_error_set(error, EINVAL,
915 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
917 " actions in same flow");
919 return rte_flow_error_set(error, ENOTSUP,
920 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
921 "flag action not supported for "
927 * Validate the mark action.
930 * Pointer to the queue action.
931 * @param[in] action_flags
932 * Bit-fields that holds the actions detected until now.
934 * Attributes of flow that includes this action.
936 * Pointer to error structure.
939 * 0 on success, a negative errno value otherwise and rte_errno is set.
942 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
943 uint64_t action_flags,
944 const struct rte_flow_attr *attr,
945 struct rte_flow_error *error)
947 const struct rte_flow_action_mark *mark = action->conf;
950 return rte_flow_error_set(error, EINVAL,
951 RTE_FLOW_ERROR_TYPE_ACTION,
953 "configuration cannot be null");
954 if (mark->id >= MLX5_FLOW_MARK_MAX)
955 return rte_flow_error_set(error, EINVAL,
956 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
958 "mark id must in 0 <= id < "
959 RTE_STR(MLX5_FLOW_MARK_MAX));
960 if (action_flags & MLX5_FLOW_ACTION_DROP)
961 return rte_flow_error_set(error, EINVAL,
962 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
963 "can't drop and mark in same flow");
964 if (action_flags & MLX5_FLOW_ACTION_FLAG)
965 return rte_flow_error_set(error, EINVAL,
966 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
967 "can't flag and mark in same flow");
968 if (action_flags & MLX5_FLOW_ACTION_MARK)
969 return rte_flow_error_set(error, EINVAL,
970 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
971 "can't have 2 mark actions in same"
974 return rte_flow_error_set(error, ENOTSUP,
975 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
976 "mark action not supported for "
982 * Validate the drop action.
984 * @param[in] action_flags
985 * Bit-fields that holds the actions detected until now.
987 * Attributes of flow that includes this action.
989 * Pointer to error structure.
992 * 0 on success, a negative errno value otherwise and rte_errno is set.
995 mlx5_flow_validate_action_drop(uint64_t action_flags,
996 const struct rte_flow_attr *attr,
997 struct rte_flow_error *error)
999 if (action_flags & MLX5_FLOW_ACTION_FLAG)
1000 return rte_flow_error_set(error, EINVAL,
1001 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1002 "can't drop and flag in same flow");
1003 if (action_flags & MLX5_FLOW_ACTION_MARK)
1004 return rte_flow_error_set(error, EINVAL,
1005 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1006 "can't drop and mark in same flow");
1007 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
1008 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
1009 return rte_flow_error_set(error, EINVAL,
1010 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1011 "can't have 2 fate actions in"
1014 return rte_flow_error_set(error, ENOTSUP,
1015 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1016 "drop action not supported for "
1022 * Validate the queue action.
1025 * Pointer to the queue action.
1026 * @param[in] action_flags
1027 * Bit-fields that holds the actions detected until now.
1029 * Pointer to the Ethernet device structure.
1031 * Attributes of flow that includes this action.
1033 * Pointer to error structure.
1036 * 0 on success, a negative errno value otherwise and rte_errno is set.
1039 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1040 uint64_t action_flags,
1041 struct rte_eth_dev *dev,
1042 const struct rte_flow_attr *attr,
1043 struct rte_flow_error *error)
1045 struct mlx5_priv *priv = dev->data->dev_private;
1046 const struct rte_flow_action_queue *queue = action->conf;
1048 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1049 return rte_flow_error_set(error, EINVAL,
1050 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1051 "can't have 2 fate actions in"
1054 return rte_flow_error_set(error, EINVAL,
1055 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1056 NULL, "No Rx queues configured");
1057 if (queue->index >= priv->rxqs_n)
1058 return rte_flow_error_set(error, EINVAL,
1059 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1061 "queue index out of range");
1062 if (!(*priv->rxqs)[queue->index])
1063 return rte_flow_error_set(error, EINVAL,
1064 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1066 "queue is not configured");
1068 return rte_flow_error_set(error, ENOTSUP,
1069 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1070 "queue action not supported for "
1076 * Validate the rss action.
1079 * Pointer to the queue action.
1080 * @param[in] action_flags
1081 * Bit-fields that holds the actions detected until now.
1083 * Pointer to the Ethernet device structure.
1085 * Attributes of flow that includes this action.
1086 * @param[in] item_flags
1087 * Items that were detected.
1089 * Pointer to error structure.
1092 * 0 on success, a negative errno value otherwise and rte_errno is set.
1095 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1096 uint64_t action_flags,
1097 struct rte_eth_dev *dev,
1098 const struct rte_flow_attr *attr,
1099 uint64_t item_flags,
1100 struct rte_flow_error *error)
1102 struct mlx5_priv *priv = dev->data->dev_private;
1103 const struct rte_flow_action_rss *rss = action->conf;
1104 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1107 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
1108 return rte_flow_error_set(error, EINVAL,
1109 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1110 "can't have 2 fate actions"
1112 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
1113 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
1114 return rte_flow_error_set(error, ENOTSUP,
1115 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1117 "RSS hash function not supported");
1118 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1123 return rte_flow_error_set(error, ENOTSUP,
1124 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1126 "tunnel RSS is not supported");
1127 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
1128 if (rss->key_len == 0 && rss->key != NULL)
1129 return rte_flow_error_set(error, ENOTSUP,
1130 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1132 "RSS hash key length 0");
1133 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
1134 return rte_flow_error_set(error, ENOTSUP,
1135 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1137 "RSS hash key too small");
1138 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
1139 return rte_flow_error_set(error, ENOTSUP,
1140 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1142 "RSS hash key too large");
1143 if (rss->queue_num > priv->config.ind_table_max_size)
1144 return rte_flow_error_set(error, ENOTSUP,
1145 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1147 "number of queues too large");
1148 if (rss->types & MLX5_RSS_HF_MASK)
1149 return rte_flow_error_set(error, ENOTSUP,
1150 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1152 "some RSS protocols are not"
1154 if ((rss->types & (ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY)) &&
1155 !(rss->types & ETH_RSS_IP))
1156 return rte_flow_error_set(error, EINVAL,
1157 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1158 "L3 partial RSS requested but L3 RSS"
1159 " type not specified");
1160 if ((rss->types & (ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY)) &&
1161 !(rss->types & (ETH_RSS_UDP | ETH_RSS_TCP)))
1162 return rte_flow_error_set(error, EINVAL,
1163 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1164 "L4 partial RSS requested but L4 RSS"
1165 " type not specified");
1167 return rte_flow_error_set(error, EINVAL,
1168 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1169 NULL, "No Rx queues configured");
1170 if (!rss->queue_num)
1171 return rte_flow_error_set(error, EINVAL,
1172 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1173 NULL, "No queues configured");
1174 for (i = 0; i != rss->queue_num; ++i) {
1175 if (rss->queue[i] >= priv->rxqs_n)
1176 return rte_flow_error_set
1178 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1179 &rss->queue[i], "queue index out of range");
1180 if (!(*priv->rxqs)[rss->queue[i]])
1181 return rte_flow_error_set
1182 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1183 &rss->queue[i], "queue is not configured");
1186 return rte_flow_error_set(error, ENOTSUP,
1187 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1188 "rss action not supported for "
1190 if (rss->level > 1 && !tunnel)
1191 return rte_flow_error_set(error, EINVAL,
1192 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
1193 "inner RSS is not supported for "
1194 "non-tunnel flows");
1199 * Validate the count action.
1202 * Pointer to the Ethernet device structure.
1204 * Attributes of flow that includes this action.
1206 * Pointer to error structure.
1209 * 0 on success, a negative errno value otherwise and rte_errno is set.
1212 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
1213 const struct rte_flow_attr *attr,
1214 struct rte_flow_error *error)
1217 return rte_flow_error_set(error, ENOTSUP,
1218 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1219 "count action not supported for "
1225 * Verify the @p attributes will be correctly understood by the NIC and store
1226 * them in the @p flow if everything is correct.
1229 * Pointer to the Ethernet device structure.
1230 * @param[in] attributes
1231 * Pointer to flow attributes
1233 * Pointer to error structure.
1236 * 0 on success, a negative errno value otherwise and rte_errno is set.
1239 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1240 const struct rte_flow_attr *attributes,
1241 struct rte_flow_error *error)
1243 struct mlx5_priv *priv = dev->data->dev_private;
1244 uint32_t priority_max = priv->config.flow_prio - 1;
1246 if (attributes->group)
1247 return rte_flow_error_set(error, ENOTSUP,
1248 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1249 NULL, "groups is not supported");
1250 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1251 attributes->priority >= priority_max)
1252 return rte_flow_error_set(error, ENOTSUP,
1253 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1254 NULL, "priority out of range");
1255 if (attributes->egress)
1256 return rte_flow_error_set(error, ENOTSUP,
1257 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1258 "egress is not supported");
1259 if (attributes->transfer && !priv->config.dv_esw_en)
1260 return rte_flow_error_set(error, ENOTSUP,
1261 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1262 NULL, "transfer is not supported");
1263 if (!attributes->ingress)
1264 return rte_flow_error_set(error, EINVAL,
1265 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1267 "ingress attribute is mandatory");
1272 * Validate ICMP6 item.
1275 * Item specification.
1276 * @param[in] item_flags
1277 * Bit-fields that holds the items detected until now.
1279 * Pointer to error structure.
1282 * 0 on success, a negative errno value otherwise and rte_errno is set.
1285 mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1286 uint64_t item_flags,
1287 uint8_t target_protocol,
1288 struct rte_flow_error *error)
1290 const struct rte_flow_item_icmp6 *mask = item->mask;
1291 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1292 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1293 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1294 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1295 MLX5_FLOW_LAYER_OUTER_L4;
1298 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
1299 return rte_flow_error_set(error, EINVAL,
1300 RTE_FLOW_ERROR_TYPE_ITEM, item,
1301 "protocol filtering not compatible"
1302 " with ICMP6 layer");
1303 if (!(item_flags & l3m))
1304 return rte_flow_error_set(error, EINVAL,
1305 RTE_FLOW_ERROR_TYPE_ITEM, item,
1306 "IPv6 is mandatory to filter on"
1308 if (item_flags & l4m)
1309 return rte_flow_error_set(error, EINVAL,
1310 RTE_FLOW_ERROR_TYPE_ITEM, item,
1311 "multiple L4 layers not supported");
1313 mask = &rte_flow_item_icmp6_mask;
1314 ret = mlx5_flow_item_acceptable
1315 (item, (const uint8_t *)mask,
1316 (const uint8_t *)&rte_flow_item_icmp6_mask,
1317 sizeof(struct rte_flow_item_icmp6), error);
1324 * Validate ICMP item.
1327 * Item specification.
1328 * @param[in] item_flags
1329 * Bit-fields that holds the items detected until now.
1331 * Pointer to error structure.
1334 * 0 on success, a negative errno value otherwise and rte_errno is set.
1337 mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1338 uint64_t item_flags,
1339 uint8_t target_protocol,
1340 struct rte_flow_error *error)
1342 const struct rte_flow_item_icmp *mask = item->mask;
1343 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1344 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1345 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1346 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1347 MLX5_FLOW_LAYER_OUTER_L4;
1350 if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
1351 return rte_flow_error_set(error, EINVAL,
1352 RTE_FLOW_ERROR_TYPE_ITEM, item,
1353 "protocol filtering not compatible"
1354 " with ICMP layer");
1355 if (!(item_flags & l3m))
1356 return rte_flow_error_set(error, EINVAL,
1357 RTE_FLOW_ERROR_TYPE_ITEM, item,
1358 "IPv4 is mandatory to filter"
1360 if (item_flags & l4m)
1361 return rte_flow_error_set(error, EINVAL,
1362 RTE_FLOW_ERROR_TYPE_ITEM, item,
1363 "multiple L4 layers not supported");
1365 mask = &rte_flow_item_icmp_mask;
1366 ret = mlx5_flow_item_acceptable
1367 (item, (const uint8_t *)mask,
1368 (const uint8_t *)&rte_flow_item_icmp_mask,
1369 sizeof(struct rte_flow_item_icmp), error);
1376 * Validate Ethernet item.
1379 * Item specification.
1380 * @param[in] item_flags
1381 * Bit-fields that holds the items detected until now.
1383 * Pointer to error structure.
1386 * 0 on success, a negative errno value otherwise and rte_errno is set.
1389 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1390 uint64_t item_flags,
1391 struct rte_flow_error *error)
1393 const struct rte_flow_item_eth *mask = item->mask;
1394 const struct rte_flow_item_eth nic_mask = {
1395 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1396 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1397 .type = RTE_BE16(0xffff),
1400 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1401 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1402 MLX5_FLOW_LAYER_OUTER_L2;
1404 if (item_flags & ethm)
1405 return rte_flow_error_set(error, ENOTSUP,
1406 RTE_FLOW_ERROR_TYPE_ITEM, item,
1407 "multiple L2 layers not supported");
1408 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
1409 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
1410 return rte_flow_error_set(error, EINVAL,
1411 RTE_FLOW_ERROR_TYPE_ITEM, item,
1412 "L2 layer should not follow "
1414 if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
1415 (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
1416 return rte_flow_error_set(error, EINVAL,
1417 RTE_FLOW_ERROR_TYPE_ITEM, item,
1418 "L2 layer should not follow VLAN");
1420 mask = &rte_flow_item_eth_mask;
1421 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1422 (const uint8_t *)&nic_mask,
1423 sizeof(struct rte_flow_item_eth),
1429 * Validate VLAN item.
1432 * Item specification.
1433 * @param[in] item_flags
1434 * Bit-fields that holds the items detected until now.
1436 * Ethernet device flow is being created on.
1438 * Pointer to error structure.
1441 * 0 on success, a negative errno value otherwise and rte_errno is set.
1444 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1445 uint64_t item_flags,
1446 struct rte_eth_dev *dev,
1447 struct rte_flow_error *error)
1449 const struct rte_flow_item_vlan *spec = item->spec;
1450 const struct rte_flow_item_vlan *mask = item->mask;
1451 const struct rte_flow_item_vlan nic_mask = {
1452 .tci = RTE_BE16(UINT16_MAX),
1453 .inner_type = RTE_BE16(UINT16_MAX),
1455 uint16_t vlan_tag = 0;
1456 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1458 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1459 MLX5_FLOW_LAYER_INNER_L4) :
1460 (MLX5_FLOW_LAYER_OUTER_L3 |
1461 MLX5_FLOW_LAYER_OUTER_L4);
1462 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1463 MLX5_FLOW_LAYER_OUTER_VLAN;
1465 if (item_flags & vlanm)
1466 return rte_flow_error_set(error, EINVAL,
1467 RTE_FLOW_ERROR_TYPE_ITEM, item,
1468 "multiple VLAN layers not supported");
1469 else if ((item_flags & l34m) != 0)
1470 return rte_flow_error_set(error, EINVAL,
1471 RTE_FLOW_ERROR_TYPE_ITEM, item,
1472 "VLAN cannot follow L3/L4 layer");
1474 mask = &rte_flow_item_vlan_mask;
1475 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1476 (const uint8_t *)&nic_mask,
1477 sizeof(struct rte_flow_item_vlan),
1481 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1482 struct mlx5_priv *priv = dev->data->dev_private;
1484 if (priv->vmwa_context) {
1486 * Non-NULL context means we have a virtual machine
1487 * and SR-IOV enabled, we have to create VLAN interface
1488 * to make hypervisor to setup E-Switch vport
1489 * context correctly. We avoid creating the multiple
1490 * VLAN interfaces, so we cannot support VLAN tag mask.
1492 return rte_flow_error_set(error, EINVAL,
1493 RTE_FLOW_ERROR_TYPE_ITEM,
1495 "VLAN tag mask is not"
1496 " supported in virtual"
1501 vlan_tag = spec->tci;
1502 vlan_tag &= mask->tci;
1505 * From verbs perspective an empty VLAN is equivalent
1506 * to a packet without VLAN layer.
1509 return rte_flow_error_set(error, EINVAL,
1510 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1512 "VLAN cannot be empty");
1517 * Validate IPV4 item.
1520 * Item specification.
1521 * @param[in] item_flags
1522 * Bit-fields that holds the items detected until now.
1523 * @param[in] acc_mask
1524 * Acceptable mask, if NULL default internal default mask
1525 * will be used to check whether item fields are supported.
1527 * Pointer to error structure.
1530 * 0 on success, a negative errno value otherwise and rte_errno is set.
1533 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1534 uint64_t item_flags,
1536 uint16_t ether_type,
1537 const struct rte_flow_item_ipv4 *acc_mask,
1538 struct rte_flow_error *error)
1540 const struct rte_flow_item_ipv4 *mask = item->mask;
1541 const struct rte_flow_item_ipv4 *spec = item->spec;
1542 const struct rte_flow_item_ipv4 nic_mask = {
1544 .src_addr = RTE_BE32(0xffffffff),
1545 .dst_addr = RTE_BE32(0xffffffff),
1546 .type_of_service = 0xff,
1547 .next_proto_id = 0xff,
1550 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1551 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1552 MLX5_FLOW_LAYER_OUTER_L3;
1553 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1554 MLX5_FLOW_LAYER_OUTER_L4;
1556 uint8_t next_proto = 0xFF;
1557 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1558 MLX5_FLOW_LAYER_OUTER_VLAN |
1559 MLX5_FLOW_LAYER_INNER_VLAN);
1561 if ((last_item & l2_vlan) && ether_type &&
1562 ether_type != RTE_ETHER_TYPE_IPV4)
1563 return rte_flow_error_set(error, EINVAL,
1564 RTE_FLOW_ERROR_TYPE_ITEM, item,
1565 "IPv4 cannot follow L2/VLAN layer "
1566 "which ether type is not IPv4");
1567 if (item_flags & MLX5_FLOW_LAYER_IPIP) {
1569 next_proto = mask->hdr.next_proto_id &
1570 spec->hdr.next_proto_id;
1571 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1572 return rte_flow_error_set(error, EINVAL,
1573 RTE_FLOW_ERROR_TYPE_ITEM,
1578 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
1579 return rte_flow_error_set(error, EINVAL,
1580 RTE_FLOW_ERROR_TYPE_ITEM, item,
1581 "wrong tunnel type - IPv6 specified "
1582 "but IPv4 item provided");
1583 if (item_flags & l3m)
1584 return rte_flow_error_set(error, ENOTSUP,
1585 RTE_FLOW_ERROR_TYPE_ITEM, item,
1586 "multiple L3 layers not supported");
1587 else if (item_flags & l4m)
1588 return rte_flow_error_set(error, EINVAL,
1589 RTE_FLOW_ERROR_TYPE_ITEM, item,
1590 "L3 cannot follow an L4 layer.");
1591 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1592 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1593 return rte_flow_error_set(error, EINVAL,
1594 RTE_FLOW_ERROR_TYPE_ITEM, item,
1595 "L3 cannot follow an NVGRE layer.");
1597 mask = &rte_flow_item_ipv4_mask;
1598 else if (mask->hdr.next_proto_id != 0 &&
1599 mask->hdr.next_proto_id != 0xff)
1600 return rte_flow_error_set(error, EINVAL,
1601 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1602 "partial mask is not supported"
1604 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1605 acc_mask ? (const uint8_t *)acc_mask
1606 : (const uint8_t *)&nic_mask,
1607 sizeof(struct rte_flow_item_ipv4),
1615 * Validate IPV6 item.
1618 * Item specification.
1619 * @param[in] item_flags
1620 * Bit-fields that holds the items detected until now.
1621 * @param[in] acc_mask
1622 * Acceptable mask, if NULL default internal default mask
1623 * will be used to check whether item fields are supported.
1625 * Pointer to error structure.
1628 * 0 on success, a negative errno value otherwise and rte_errno is set.
1631 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1632 uint64_t item_flags,
1634 uint16_t ether_type,
1635 const struct rte_flow_item_ipv6 *acc_mask,
1636 struct rte_flow_error *error)
1638 const struct rte_flow_item_ipv6 *mask = item->mask;
1639 const struct rte_flow_item_ipv6 *spec = item->spec;
1640 const struct rte_flow_item_ipv6 nic_mask = {
1643 "\xff\xff\xff\xff\xff\xff\xff\xff"
1644 "\xff\xff\xff\xff\xff\xff\xff\xff",
1646 "\xff\xff\xff\xff\xff\xff\xff\xff"
1647 "\xff\xff\xff\xff\xff\xff\xff\xff",
1648 .vtc_flow = RTE_BE32(0xffffffff),
1653 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1654 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1655 MLX5_FLOW_LAYER_OUTER_L3;
1656 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1657 MLX5_FLOW_LAYER_OUTER_L4;
1659 uint8_t next_proto = 0xFF;
1660 const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
1661 MLX5_FLOW_LAYER_OUTER_VLAN |
1662 MLX5_FLOW_LAYER_INNER_VLAN);
1664 if ((last_item & l2_vlan) && ether_type &&
1665 ether_type != RTE_ETHER_TYPE_IPV6)
1666 return rte_flow_error_set(error, EINVAL,
1667 RTE_FLOW_ERROR_TYPE_ITEM, item,
1668 "IPv6 cannot follow L2/VLAN layer "
1669 "which ether type is not IPv6");
1670 if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP) {
1672 next_proto = mask->hdr.proto & spec->hdr.proto;
1673 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
1674 return rte_flow_error_set(error, EINVAL,
1675 RTE_FLOW_ERROR_TYPE_ITEM,
1680 if (item_flags & MLX5_FLOW_LAYER_IPIP)
1681 return rte_flow_error_set(error, EINVAL,
1682 RTE_FLOW_ERROR_TYPE_ITEM, item,
1683 "wrong tunnel type - IPv4 specified "
1684 "but IPv6 item provided");
1685 if (item_flags & l3m)
1686 return rte_flow_error_set(error, ENOTSUP,
1687 RTE_FLOW_ERROR_TYPE_ITEM, item,
1688 "multiple L3 layers not supported");
1689 else if (item_flags & l4m)
1690 return rte_flow_error_set(error, EINVAL,
1691 RTE_FLOW_ERROR_TYPE_ITEM, item,
1692 "L3 cannot follow an L4 layer.");
1693 else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
1694 !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
1695 return rte_flow_error_set(error, EINVAL,
1696 RTE_FLOW_ERROR_TYPE_ITEM, item,
1697 "L3 cannot follow an NVGRE layer.");
1699 mask = &rte_flow_item_ipv6_mask;
1700 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1701 acc_mask ? (const uint8_t *)acc_mask
1702 : (const uint8_t *)&nic_mask,
1703 sizeof(struct rte_flow_item_ipv6),
1711 * Validate UDP item.
1714 * Item specification.
1715 * @param[in] item_flags
1716 * Bit-fields that holds the items detected until now.
1717 * @param[in] target_protocol
1718 * The next protocol in the previous item.
1719 * @param[in] flow_mask
1720 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
1722 * Pointer to error structure.
1725 * 0 on success, a negative errno value otherwise and rte_errno is set.
1728 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1729 uint64_t item_flags,
1730 uint8_t target_protocol,
1731 struct rte_flow_error *error)
1733 const struct rte_flow_item_udp *mask = item->mask;
1734 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1735 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1736 MLX5_FLOW_LAYER_OUTER_L3;
1737 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1738 MLX5_FLOW_LAYER_OUTER_L4;
1741 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1742 return rte_flow_error_set(error, EINVAL,
1743 RTE_FLOW_ERROR_TYPE_ITEM, item,
1744 "protocol filtering not compatible"
1746 if (!(item_flags & l3m))
1747 return rte_flow_error_set(error, EINVAL,
1748 RTE_FLOW_ERROR_TYPE_ITEM, item,
1749 "L3 is mandatory to filter on L4");
1750 if (item_flags & l4m)
1751 return rte_flow_error_set(error, EINVAL,
1752 RTE_FLOW_ERROR_TYPE_ITEM, item,
1753 "multiple L4 layers not supported");
1755 mask = &rte_flow_item_udp_mask;
1756 ret = mlx5_flow_item_acceptable
1757 (item, (const uint8_t *)mask,
1758 (const uint8_t *)&rte_flow_item_udp_mask,
1759 sizeof(struct rte_flow_item_udp), error);
1766 * Validate TCP item.
1769 * Item specification.
1770 * @param[in] item_flags
1771 * Bit-fields that holds the items detected until now.
1772 * @param[in] target_protocol
1773 * The next protocol in the previous item.
1775 * Pointer to error structure.
1778 * 0 on success, a negative errno value otherwise and rte_errno is set.
1781 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1782 uint64_t item_flags,
1783 uint8_t target_protocol,
1784 const struct rte_flow_item_tcp *flow_mask,
1785 struct rte_flow_error *error)
1787 const struct rte_flow_item_tcp *mask = item->mask;
1788 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1789 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1790 MLX5_FLOW_LAYER_OUTER_L3;
1791 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1792 MLX5_FLOW_LAYER_OUTER_L4;
1796 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1797 return rte_flow_error_set(error, EINVAL,
1798 RTE_FLOW_ERROR_TYPE_ITEM, item,
1799 "protocol filtering not compatible"
1801 if (!(item_flags & l3m))
1802 return rte_flow_error_set(error, EINVAL,
1803 RTE_FLOW_ERROR_TYPE_ITEM, item,
1804 "L3 is mandatory to filter on L4");
1805 if (item_flags & l4m)
1806 return rte_flow_error_set(error, EINVAL,
1807 RTE_FLOW_ERROR_TYPE_ITEM, item,
1808 "multiple L4 layers not supported");
1810 mask = &rte_flow_item_tcp_mask;
1811 ret = mlx5_flow_item_acceptable
1812 (item, (const uint8_t *)mask,
1813 (const uint8_t *)flow_mask,
1814 sizeof(struct rte_flow_item_tcp), error);
1821 * Validate VXLAN item.
1824 * Item specification.
1825 * @param[in] item_flags
1826 * Bit-fields that holds the items detected until now.
1827 * @param[in] target_protocol
1828 * The next protocol in the previous item.
1830 * Pointer to error structure.
1833 * 0 on success, a negative errno value otherwise and rte_errno is set.
1836 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1837 uint64_t item_flags,
1838 struct rte_flow_error *error)
1840 const struct rte_flow_item_vxlan *spec = item->spec;
1841 const struct rte_flow_item_vxlan *mask = item->mask;
1846 } id = { .vlan_id = 0, };
1847 uint32_t vlan_id = 0;
1850 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1851 return rte_flow_error_set(error, ENOTSUP,
1852 RTE_FLOW_ERROR_TYPE_ITEM, item,
1853 "multiple tunnel layers not"
1856 * Verify only UDPv4 is present as defined in
1857 * https://tools.ietf.org/html/rfc7348
1859 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1860 return rte_flow_error_set(error, EINVAL,
1861 RTE_FLOW_ERROR_TYPE_ITEM, item,
1862 "no outer UDP layer found");
1864 mask = &rte_flow_item_vxlan_mask;
1865 ret = mlx5_flow_item_acceptable
1866 (item, (const uint8_t *)mask,
1867 (const uint8_t *)&rte_flow_item_vxlan_mask,
1868 sizeof(struct rte_flow_item_vxlan),
1873 memcpy(&id.vni[1], spec->vni, 3);
1874 vlan_id = id.vlan_id;
1875 memcpy(&id.vni[1], mask->vni, 3);
1876 vlan_id &= id.vlan_id;
1879 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1880 * only this layer is defined in the Verbs specification it is
1881 * interpreted as wildcard and all packets will match this
1882 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1883 * udp), all packets matching the layers before will also
1884 * match this rule. To avoid such situation, VNI 0 is
1885 * currently refused.
1888 return rte_flow_error_set(error, ENOTSUP,
1889 RTE_FLOW_ERROR_TYPE_ITEM, item,
1890 "VXLAN vni cannot be 0");
1891 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1892 return rte_flow_error_set(error, ENOTSUP,
1893 RTE_FLOW_ERROR_TYPE_ITEM, item,
1894 "VXLAN tunnel must be fully defined");
1899 * Validate VXLAN_GPE item.
1902 * Item specification.
1903 * @param[in] item_flags
1904 * Bit-fields that holds the items detected until now.
1906 * Pointer to the private data structure.
1907 * @param[in] target_protocol
1908 * The next protocol in the previous item.
1910 * Pointer to error structure.
1913 * 0 on success, a negative errno value otherwise and rte_errno is set.
1916 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1917 uint64_t item_flags,
1918 struct rte_eth_dev *dev,
1919 struct rte_flow_error *error)
1921 struct mlx5_priv *priv = dev->data->dev_private;
1922 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1923 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1928 } id = { .vlan_id = 0, };
1929 uint32_t vlan_id = 0;
1931 if (!priv->config.l3_vxlan_en)
1932 return rte_flow_error_set(error, ENOTSUP,
1933 RTE_FLOW_ERROR_TYPE_ITEM, item,
1934 "L3 VXLAN is not enabled by device"
1935 " parameter and/or not configured in"
1937 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1938 return rte_flow_error_set(error, ENOTSUP,
1939 RTE_FLOW_ERROR_TYPE_ITEM, item,
1940 "multiple tunnel layers not"
1943 * Verify only UDPv4 is present as defined in
1944 * https://tools.ietf.org/html/rfc7348
1946 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1947 return rte_flow_error_set(error, EINVAL,
1948 RTE_FLOW_ERROR_TYPE_ITEM, item,
1949 "no outer UDP layer found");
1951 mask = &rte_flow_item_vxlan_gpe_mask;
1952 ret = mlx5_flow_item_acceptable
1953 (item, (const uint8_t *)mask,
1954 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1955 sizeof(struct rte_flow_item_vxlan_gpe),
1961 return rte_flow_error_set(error, ENOTSUP,
1962 RTE_FLOW_ERROR_TYPE_ITEM,
1964 "VxLAN-GPE protocol"
1966 memcpy(&id.vni[1], spec->vni, 3);
1967 vlan_id = id.vlan_id;
1968 memcpy(&id.vni[1], mask->vni, 3);
1969 vlan_id &= id.vlan_id;
1972 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1973 * layer is defined in the Verbs specification it is interpreted as
1974 * wildcard and all packets will match this rule, if it follows a full
1975 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1976 * before will also match this rule. To avoid such situation, VNI 0
1977 * is currently refused.
1980 return rte_flow_error_set(error, ENOTSUP,
1981 RTE_FLOW_ERROR_TYPE_ITEM, item,
1982 "VXLAN-GPE vni cannot be 0");
1983 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1984 return rte_flow_error_set(error, ENOTSUP,
1985 RTE_FLOW_ERROR_TYPE_ITEM, item,
1986 "VXLAN-GPE tunnel must be fully"
1991 * Validate GRE Key item.
1994 * Item specification.
1995 * @param[in] item_flags
1996 * Bit flags to mark detected items.
1997 * @param[in] gre_item
1998 * Pointer to gre_item
2000 * Pointer to error structure.
2003 * 0 on success, a negative errno value otherwise and rte_errno is set.
2006 mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
2007 uint64_t item_flags,
2008 const struct rte_flow_item *gre_item,
2009 struct rte_flow_error *error)
2011 const rte_be32_t *mask = item->mask;
2013 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
2014 const struct rte_flow_item_gre *gre_spec;
2015 const struct rte_flow_item_gre *gre_mask;
2017 if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
2018 return rte_flow_error_set(error, ENOTSUP,
2019 RTE_FLOW_ERROR_TYPE_ITEM, item,
2020 "Multiple GRE key not support");
2021 if (!(item_flags & MLX5_FLOW_LAYER_GRE))
2022 return rte_flow_error_set(error, ENOTSUP,
2023 RTE_FLOW_ERROR_TYPE_ITEM, item,
2024 "No preceding GRE header");
2025 if (item_flags & MLX5_FLOW_LAYER_INNER)
2026 return rte_flow_error_set(error, ENOTSUP,
2027 RTE_FLOW_ERROR_TYPE_ITEM, item,
2028 "GRE key following a wrong item");
2029 gre_mask = gre_item->mask;
2031 gre_mask = &rte_flow_item_gre_mask;
2032 gre_spec = gre_item->spec;
2033 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
2034 !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
2035 return rte_flow_error_set(error, EINVAL,
2036 RTE_FLOW_ERROR_TYPE_ITEM, item,
2037 "Key bit must be on");
2040 mask = &gre_key_default_mask;
2041 ret = mlx5_flow_item_acceptable
2042 (item, (const uint8_t *)mask,
2043 (const uint8_t *)&gre_key_default_mask,
2044 sizeof(rte_be32_t), error);
2049 * Validate GRE item.
2052 * Item specification.
2053 * @param[in] item_flags
2054 * Bit flags to mark detected items.
2055 * @param[in] target_protocol
2056 * The next protocol in the previous item.
2058 * Pointer to error structure.
2061 * 0 on success, a negative errno value otherwise and rte_errno is set.
2064 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
2065 uint64_t item_flags,
2066 uint8_t target_protocol,
2067 struct rte_flow_error *error)
2069 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
2070 const struct rte_flow_item_gre *mask = item->mask;
2072 const struct rte_flow_item_gre nic_mask = {
2073 .c_rsvd0_ver = RTE_BE16(0xB000),
2074 .protocol = RTE_BE16(UINT16_MAX),
2077 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2078 return rte_flow_error_set(error, EINVAL,
2079 RTE_FLOW_ERROR_TYPE_ITEM, item,
2080 "protocol filtering not compatible"
2081 " with this GRE layer");
2082 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2083 return rte_flow_error_set(error, ENOTSUP,
2084 RTE_FLOW_ERROR_TYPE_ITEM, item,
2085 "multiple tunnel layers not"
2087 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2088 return rte_flow_error_set(error, ENOTSUP,
2089 RTE_FLOW_ERROR_TYPE_ITEM, item,
2090 "L3 Layer is missing");
2092 mask = &rte_flow_item_gre_mask;
2093 ret = mlx5_flow_item_acceptable
2094 (item, (const uint8_t *)mask,
2095 (const uint8_t *)&nic_mask,
2096 sizeof(struct rte_flow_item_gre), error);
2099 #ifndef HAVE_MLX5DV_DR
2100 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
2101 if (spec && (spec->protocol & mask->protocol))
2102 return rte_flow_error_set(error, ENOTSUP,
2103 RTE_FLOW_ERROR_TYPE_ITEM, item,
2104 "without MPLS support the"
2105 " specification cannot be used for"
2113 * Validate Geneve item.
2116 * Item specification.
2117 * @param[in] itemFlags
2118 * Bit-fields that holds the items detected until now.
2120 * Pointer to the private data structure.
2122 * Pointer to error structure.
2125 * 0 on success, a negative errno value otherwise and rte_errno is set.
2129 mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
2130 uint64_t item_flags,
2131 struct rte_eth_dev *dev,
2132 struct rte_flow_error *error)
2134 struct mlx5_priv *priv = dev->data->dev_private;
2135 const struct rte_flow_item_geneve *spec = item->spec;
2136 const struct rte_flow_item_geneve *mask = item->mask;
2139 uint8_t opt_len = priv->config.hca_attr.geneve_max_opt_len ?
2140 MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
2141 const struct rte_flow_item_geneve nic_mask = {
2142 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
2143 .vni = "\xff\xff\xff",
2144 .protocol = RTE_BE16(UINT16_MAX),
2147 if (!(priv->config.hca_attr.flex_parser_protocols &
2148 MLX5_HCA_FLEX_GENEVE_ENABLED) ||
2149 !priv->config.hca_attr.tunnel_stateless_geneve_rx)
2150 return rte_flow_error_set(error, ENOTSUP,
2151 RTE_FLOW_ERROR_TYPE_ITEM, item,
2152 "L3 Geneve is not enabled by device"
2153 " parameter and/or not configured in"
2155 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2156 return rte_flow_error_set(error, ENOTSUP,
2157 RTE_FLOW_ERROR_TYPE_ITEM, item,
2158 "multiple tunnel layers not"
2161 * Verify only UDPv4 is present as defined in
2162 * https://tools.ietf.org/html/rfc7348
2164 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2165 return rte_flow_error_set(error, EINVAL,
2166 RTE_FLOW_ERROR_TYPE_ITEM, item,
2167 "no outer UDP layer found");
2169 mask = &rte_flow_item_geneve_mask;
2170 ret = mlx5_flow_item_acceptable
2171 (item, (const uint8_t *)mask,
2172 (const uint8_t *)&nic_mask,
2173 sizeof(struct rte_flow_item_geneve), error);
2177 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
2178 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
2179 MLX5_GENEVE_CRITO_VAL(gbhdr) ||
2180 MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
2181 return rte_flow_error_set(error, ENOTSUP,
2182 RTE_FLOW_ERROR_TYPE_ITEM,
2184 "Geneve protocol unsupported"
2185 " fields are being used");
2186 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
2187 return rte_flow_error_set
2189 RTE_FLOW_ERROR_TYPE_ITEM,
2191 "Unsupported Geneve options length");
2193 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
2194 return rte_flow_error_set
2196 RTE_FLOW_ERROR_TYPE_ITEM, item,
2197 "Geneve tunnel must be fully defined");
2202 * Validate MPLS item.
2205 * Pointer to the rte_eth_dev structure.
2207 * Item specification.
2208 * @param[in] item_flags
2209 * Bit-fields that holds the items detected until now.
2210 * @param[in] prev_layer
2211 * The protocol layer indicated in previous item.
2213 * Pointer to error structure.
2216 * 0 on success, a negative errno value otherwise and rte_errno is set.
2219 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
2220 const struct rte_flow_item *item __rte_unused,
2221 uint64_t item_flags __rte_unused,
2222 uint64_t prev_layer __rte_unused,
2223 struct rte_flow_error *error)
2225 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2226 const struct rte_flow_item_mpls *mask = item->mask;
2227 struct mlx5_priv *priv = dev->data->dev_private;
2230 if (!priv->config.mpls_en)
2231 return rte_flow_error_set(error, ENOTSUP,
2232 RTE_FLOW_ERROR_TYPE_ITEM, item,
2233 "MPLS not supported or"
2234 " disabled in firmware"
2236 /* MPLS over IP, UDP, GRE is allowed */
2237 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
2238 MLX5_FLOW_LAYER_OUTER_L4_UDP |
2239 MLX5_FLOW_LAYER_GRE)))
2240 return rte_flow_error_set(error, EINVAL,
2241 RTE_FLOW_ERROR_TYPE_ITEM, item,
2242 "protocol filtering not compatible"
2243 " with MPLS layer");
2244 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
2245 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
2246 !(item_flags & MLX5_FLOW_LAYER_GRE))
2247 return rte_flow_error_set(error, ENOTSUP,
2248 RTE_FLOW_ERROR_TYPE_ITEM, item,
2249 "multiple tunnel layers not"
2252 mask = &rte_flow_item_mpls_mask;
2253 ret = mlx5_flow_item_acceptable
2254 (item, (const uint8_t *)mask,
2255 (const uint8_t *)&rte_flow_item_mpls_mask,
2256 sizeof(struct rte_flow_item_mpls), error);
2261 return rte_flow_error_set(error, ENOTSUP,
2262 RTE_FLOW_ERROR_TYPE_ITEM, item,
2263 "MPLS is not supported by Verbs, please"
2268 * Validate NVGRE item.
2271 * Item specification.
2272 * @param[in] item_flags
2273 * Bit flags to mark detected items.
2274 * @param[in] target_protocol
2275 * The next protocol in the previous item.
2277 * Pointer to error structure.
2280 * 0 on success, a negative errno value otherwise and rte_errno is set.
2283 mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
2284 uint64_t item_flags,
2285 uint8_t target_protocol,
2286 struct rte_flow_error *error)
2288 const struct rte_flow_item_nvgre *mask = item->mask;
2291 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
2292 return rte_flow_error_set(error, EINVAL,
2293 RTE_FLOW_ERROR_TYPE_ITEM, item,
2294 "protocol filtering not compatible"
2295 " with this GRE layer");
2296 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2297 return rte_flow_error_set(error, ENOTSUP,
2298 RTE_FLOW_ERROR_TYPE_ITEM, item,
2299 "multiple tunnel layers not"
2301 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
2302 return rte_flow_error_set(error, ENOTSUP,
2303 RTE_FLOW_ERROR_TYPE_ITEM, item,
2304 "L3 Layer is missing");
2306 mask = &rte_flow_item_nvgre_mask;
2307 ret = mlx5_flow_item_acceptable
2308 (item, (const uint8_t *)mask,
2309 (const uint8_t *)&rte_flow_item_nvgre_mask,
2310 sizeof(struct rte_flow_item_nvgre), error);
2316 /* Allocate unique ID for the split Q/RSS subflows. */
2318 flow_qrss_get_id(struct rte_eth_dev *dev)
2320 struct mlx5_priv *priv = dev->data->dev_private;
2321 uint32_t qrss_id, ret;
2323 ret = mlx5_flow_id_get(priv->qrss_id_pool, &qrss_id);
2330 /* Free unique ID for the split Q/RSS subflows. */
2332 flow_qrss_free_id(struct rte_eth_dev *dev, uint32_t qrss_id)
2334 struct mlx5_priv *priv = dev->data->dev_private;
2337 mlx5_flow_id_release(priv->qrss_id_pool, qrss_id);
2341 * Release resource related QUEUE/RSS action split.
2344 * Pointer to Ethernet device.
2346 * Flow to release id's from.
2349 flow_mreg_split_qrss_release(struct rte_eth_dev *dev,
2350 struct rte_flow *flow)
2352 struct mlx5_flow *dev_flow;
2354 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
2355 if (dev_flow->qrss_id)
2356 flow_qrss_free_id(dev, dev_flow->qrss_id);
2360 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
2361 const struct rte_flow_attr *attr __rte_unused,
2362 const struct rte_flow_item items[] __rte_unused,
2363 const struct rte_flow_action actions[] __rte_unused,
2364 bool external __rte_unused,
2365 struct rte_flow_error *error)
2367 return rte_flow_error_set(error, ENOTSUP,
2368 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2371 static struct mlx5_flow *
2372 flow_null_prepare(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 rte_flow_error_set(error, ENOTSUP,
2378 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2383 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
2384 struct mlx5_flow *dev_flow __rte_unused,
2385 const struct rte_flow_attr *attr __rte_unused,
2386 const struct rte_flow_item items[] __rte_unused,
2387 const struct rte_flow_action actions[] __rte_unused,
2388 struct rte_flow_error *error)
2390 return rte_flow_error_set(error, ENOTSUP,
2391 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2395 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
2396 struct rte_flow *flow __rte_unused,
2397 struct rte_flow_error *error)
2399 return rte_flow_error_set(error, ENOTSUP,
2400 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2404 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
2405 struct rte_flow *flow __rte_unused)
2410 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
2411 struct rte_flow *flow __rte_unused)
2416 flow_null_query(struct rte_eth_dev *dev __rte_unused,
2417 struct rte_flow *flow __rte_unused,
2418 const struct rte_flow_action *actions __rte_unused,
2419 void *data __rte_unused,
2420 struct rte_flow_error *error)
2422 return rte_flow_error_set(error, ENOTSUP,
2423 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
2426 /* Void driver to protect from null pointer reference. */
2427 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
2428 .validate = flow_null_validate,
2429 .prepare = flow_null_prepare,
2430 .translate = flow_null_translate,
2431 .apply = flow_null_apply,
2432 .remove = flow_null_remove,
2433 .destroy = flow_null_destroy,
2434 .query = flow_null_query,
2438 * Select flow driver type according to flow attributes and device
2442 * Pointer to the dev structure.
2444 * Pointer to the flow attributes.
2447 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
2449 static enum mlx5_flow_drv_type
2450 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
2452 struct mlx5_priv *priv = dev->data->dev_private;
2453 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
2455 if (attr->transfer && priv->config.dv_esw_en)
2456 type = MLX5_FLOW_TYPE_DV;
2457 if (!attr->transfer)
2458 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
2459 MLX5_FLOW_TYPE_VERBS;
2463 #define flow_get_drv_ops(type) flow_drv_ops[type]
2466 * Flow driver validation API. This abstracts calling driver specific functions.
2467 * The type of flow driver is determined according to flow attributes.
2470 * Pointer to the dev structure.
2472 * Pointer to the flow attributes.
2474 * Pointer to the list of items.
2475 * @param[in] actions
2476 * Pointer to the list of actions.
2477 * @param[in] external
2478 * This flow rule is created by request external to PMD.
2480 * Pointer to the error structure.
2483 * 0 on success, a negative errno value otherwise and rte_errno is set.
2486 flow_drv_validate(struct rte_eth_dev *dev,
2487 const struct rte_flow_attr *attr,
2488 const struct rte_flow_item items[],
2489 const struct rte_flow_action actions[],
2490 bool external, struct rte_flow_error *error)
2492 const struct mlx5_flow_driver_ops *fops;
2493 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
2495 fops = flow_get_drv_ops(type);
2496 return fops->validate(dev, attr, items, actions, external, error);
2500 * Flow driver preparation API. This abstracts calling driver specific
2501 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2502 * calculates the size of memory required for device flow, allocates the memory,
2503 * initializes the device flow and returns the pointer.
2506 * This function initializes device flow structure such as dv or verbs in
2507 * struct mlx5_flow. However, it is caller's responsibility to initialize the
2508 * rest. For example, adding returning device flow to flow->dev_flow list and
2509 * setting backward reference to the flow should be done out of this function.
2510 * layers field is not filled either.
2513 * Pointer to the flow attributes.
2515 * Pointer to the list of items.
2516 * @param[in] actions
2517 * Pointer to the list of actions.
2519 * Pointer to the error structure.
2522 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
2524 static inline struct mlx5_flow *
2525 flow_drv_prepare(const struct rte_flow *flow,
2526 const struct rte_flow_attr *attr,
2527 const struct rte_flow_item items[],
2528 const struct rte_flow_action actions[],
2529 struct rte_flow_error *error)
2531 const struct mlx5_flow_driver_ops *fops;
2532 enum mlx5_flow_drv_type type = flow->drv_type;
2534 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2535 fops = flow_get_drv_ops(type);
2536 return fops->prepare(attr, items, actions, error);
2540 * Flow driver translation API. This abstracts calling driver specific
2541 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
2542 * translates a generic flow into a driver flow. flow_drv_prepare() must
2546 * dev_flow->layers could be filled as a result of parsing during translation
2547 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
2548 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
2549 * flow->actions could be overwritten even though all the expanded dev_flows
2550 * have the same actions.
2553 * Pointer to the rte dev structure.
2554 * @param[in, out] dev_flow
2555 * Pointer to the mlx5 flow.
2557 * Pointer to the flow attributes.
2559 * Pointer to the list of items.
2560 * @param[in] actions
2561 * Pointer to the list of actions.
2563 * Pointer to the error structure.
2566 * 0 on success, a negative errno value otherwise and rte_errno is set.
2569 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
2570 const struct rte_flow_attr *attr,
2571 const struct rte_flow_item items[],
2572 const struct rte_flow_action actions[],
2573 struct rte_flow_error *error)
2575 const struct mlx5_flow_driver_ops *fops;
2576 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
2578 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2579 fops = flow_get_drv_ops(type);
2580 return fops->translate(dev, dev_flow, attr, items, actions, error);
2584 * Flow driver apply API. This abstracts calling driver specific functions.
2585 * Parent flow (rte_flow) should have driver type (drv_type). It applies
2586 * translated driver flows on to device. flow_drv_translate() must precede.
2589 * Pointer to Ethernet device structure.
2590 * @param[in, out] flow
2591 * Pointer to flow structure.
2593 * Pointer to error structure.
2596 * 0 on success, a negative errno value otherwise and rte_errno is set.
2599 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
2600 struct rte_flow_error *error)
2602 const struct mlx5_flow_driver_ops *fops;
2603 enum mlx5_flow_drv_type type = flow->drv_type;
2605 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2606 fops = flow_get_drv_ops(type);
2607 return fops->apply(dev, flow, error);
2611 * Flow driver remove API. This abstracts calling driver specific functions.
2612 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2613 * on device. All the resources of the flow should be freed by calling
2614 * flow_drv_destroy().
2617 * Pointer to Ethernet device.
2618 * @param[in, out] flow
2619 * Pointer to flow structure.
2622 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
2624 const struct mlx5_flow_driver_ops *fops;
2625 enum mlx5_flow_drv_type type = flow->drv_type;
2627 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2628 fops = flow_get_drv_ops(type);
2629 fops->remove(dev, flow);
2633 * Flow driver destroy API. This abstracts calling driver specific functions.
2634 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
2635 * on device and releases resources of the flow.
2638 * Pointer to Ethernet device.
2639 * @param[in, out] flow
2640 * Pointer to flow structure.
2643 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
2645 const struct mlx5_flow_driver_ops *fops;
2646 enum mlx5_flow_drv_type type = flow->drv_type;
2648 flow_mreg_split_qrss_release(dev, flow);
2649 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
2650 fops = flow_get_drv_ops(type);
2651 fops->destroy(dev, flow);
2655 * Validate a flow supported by the NIC.
2657 * @see rte_flow_validate()
2661 mlx5_flow_validate(struct rte_eth_dev *dev,
2662 const struct rte_flow_attr *attr,
2663 const struct rte_flow_item items[],
2664 const struct rte_flow_action actions[],
2665 struct rte_flow_error *error)
2669 ret = flow_drv_validate(dev, attr, items, actions, true, error);
2676 * Get port id item from the item list.
2679 * Pointer to the list of items.
2682 * Pointer to the port id item if exist, else return NULL.
2684 static const struct rte_flow_item *
2685 find_port_id_item(const struct rte_flow_item *item)
2688 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2689 if (item->type == RTE_FLOW_ITEM_TYPE_PORT_ID)
2696 * Get RSS action from the action list.
2698 * @param[in] actions
2699 * Pointer to the list of actions.
2702 * Pointer to the RSS action if exist, else return NULL.
2704 static const struct rte_flow_action_rss*
2705 flow_get_rss_action(const struct rte_flow_action actions[])
2707 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2708 switch (actions->type) {
2709 case RTE_FLOW_ACTION_TYPE_RSS:
2710 return (const struct rte_flow_action_rss *)
2720 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
2722 const struct rte_flow_item *item;
2723 unsigned int has_vlan = 0;
2725 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2726 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2732 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
2733 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
2734 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
2735 MLX5_EXPANSION_ROOT_OUTER;
2739 * Get QUEUE/RSS action from the action list.
2741 * @param[in] actions
2742 * Pointer to the list of actions.
2744 * Pointer to the return pointer.
2745 * @param[out] qrss_type
2746 * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
2747 * if no QUEUE/RSS is found.
2750 * Total number of actions.
2753 flow_parse_qrss_action(const struct rte_flow_action actions[],
2754 const struct rte_flow_action **qrss)
2758 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2759 switch (actions->type) {
2760 case RTE_FLOW_ACTION_TYPE_QUEUE:
2761 case RTE_FLOW_ACTION_TYPE_RSS:
2769 /* Count RTE_FLOW_ACTION_TYPE_END. */
2770 return actions_n + 1;
2774 * Check meter action from the action list.
2776 * @param[in] actions
2777 * Pointer to the list of actions.
2779 * Pointer to the meter exist flag.
2782 * Total number of actions.
2785 flow_check_meter_action(const struct rte_flow_action actions[], uint32_t *mtr)
2791 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2792 switch (actions->type) {
2793 case RTE_FLOW_ACTION_TYPE_METER:
2801 /* Count RTE_FLOW_ACTION_TYPE_END. */
2802 return actions_n + 1;
2806 * Check if the flow should be splited due to hairpin.
2807 * The reason for the split is that in current HW we can't
2808 * support encap on Rx, so if a flow have encap we move it
2812 * Pointer to Ethernet device.
2814 * Flow rule attributes.
2815 * @param[in] actions
2816 * Associated actions (list terminated by the END action).
2819 * > 0 the number of actions and the flow should be split,
2820 * 0 when no split required.
2823 flow_check_hairpin_split(struct rte_eth_dev *dev,
2824 const struct rte_flow_attr *attr,
2825 const struct rte_flow_action actions[])
2827 int queue_action = 0;
2830 const struct rte_flow_action_queue *queue;
2831 const struct rte_flow_action_rss *rss;
2832 const struct rte_flow_action_raw_encap *raw_encap;
2836 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2837 switch (actions->type) {
2838 case RTE_FLOW_ACTION_TYPE_QUEUE:
2839 queue = actions->conf;
2842 if (mlx5_rxq_get_type(dev, queue->index) !=
2843 MLX5_RXQ_TYPE_HAIRPIN)
2848 case RTE_FLOW_ACTION_TYPE_RSS:
2849 rss = actions->conf;
2850 if (rss == NULL || rss->queue_num == 0)
2852 if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
2853 MLX5_RXQ_TYPE_HAIRPIN)
2858 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
2859 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
2863 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
2864 raw_encap = actions->conf;
2865 if (raw_encap->size >
2866 (sizeof(struct rte_flow_item_eth) +
2867 sizeof(struct rte_flow_item_ipv4)))
2876 if (encap == 1 && queue_action)
2881 /* Declare flow create/destroy prototype in advance. */
2882 static struct rte_flow *
2883 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
2884 const struct rte_flow_attr *attr,
2885 const struct rte_flow_item items[],
2886 const struct rte_flow_action actions[],
2887 bool external, struct rte_flow_error *error);
2890 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
2891 struct rte_flow *flow);
2894 * Add a flow of copying flow metadata registers in RX_CP_TBL.
2896 * As mark_id is unique, if there's already a registered flow for the mark_id,
2897 * return by increasing the reference counter of the resource. Otherwise, create
2898 * the resource (mcp_res) and flow.
2901 * - If ingress port is ANY and reg_c[1] is mark_id,
2902 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
2904 * For default flow (zero mark_id), flow is like,
2905 * - If ingress port is ANY,
2906 * reg_b := reg_c[0] and jump to RX_ACT_TBL.
2909 * Pointer to Ethernet device.
2911 * ID of MARK action, zero means default flow for META.
2913 * Perform verbose error reporting if not NULL.
2916 * Associated resource on success, NULL otherwise and rte_errno is set.
2918 static struct mlx5_flow_mreg_copy_resource *
2919 flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
2920 struct rte_flow_error *error)
2922 struct mlx5_priv *priv = dev->data->dev_private;
2923 struct rte_flow_attr attr = {
2924 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
2927 struct mlx5_rte_flow_item_tag tag_spec = {
2930 struct rte_flow_item items[] = {
2931 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
2933 struct rte_flow_action_mark ftag = {
2936 struct mlx5_flow_action_copy_mreg cp_mreg = {
2940 struct rte_flow_action_jump jump = {
2941 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
2943 struct rte_flow_action actions[] = {
2944 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
2946 struct mlx5_flow_mreg_copy_resource *mcp_res;
2949 /* Fill the register fileds in the flow. */
2950 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2954 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
2958 /* Check if already registered. */
2959 assert(priv->mreg_cp_tbl);
2960 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id);
2962 /* For non-default rule. */
2963 if (mark_id != MLX5_DEFAULT_COPY_ID)
2965 assert(mark_id != MLX5_DEFAULT_COPY_ID || mcp_res->refcnt == 1);
2968 /* Provide the full width of FLAG specific value. */
2969 if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
2970 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
2971 /* Build a new flow. */
2972 if (mark_id != MLX5_DEFAULT_COPY_ID) {
2973 items[0] = (struct rte_flow_item){
2974 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
2977 items[1] = (struct rte_flow_item){
2978 .type = RTE_FLOW_ITEM_TYPE_END,
2980 actions[0] = (struct rte_flow_action){
2981 .type = MLX5_RTE_FLOW_ACTION_TYPE_MARK,
2984 actions[1] = (struct rte_flow_action){
2985 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
2988 actions[2] = (struct rte_flow_action){
2989 .type = RTE_FLOW_ACTION_TYPE_JUMP,
2992 actions[3] = (struct rte_flow_action){
2993 .type = RTE_FLOW_ACTION_TYPE_END,
2996 /* Default rule, wildcard match. */
2997 attr.priority = MLX5_FLOW_PRIO_RSVD;
2998 items[0] = (struct rte_flow_item){
2999 .type = RTE_FLOW_ITEM_TYPE_END,
3001 actions[0] = (struct rte_flow_action){
3002 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3005 actions[1] = (struct rte_flow_action){
3006 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3009 actions[2] = (struct rte_flow_action){
3010 .type = RTE_FLOW_ACTION_TYPE_END,
3013 /* Build a new entry. */
3014 mcp_res = rte_zmalloc(__func__, sizeof(*mcp_res), 0);
3020 * The copy Flows are not included in any list. There
3021 * ones are referenced from other Flows and can not
3022 * be applied, removed, deleted in ardbitrary order
3023 * by list traversing.
3025 mcp_res->flow = flow_list_create(dev, NULL, &attr, items,
3026 actions, false, error);
3030 mcp_res->hlist_ent.key = mark_id;
3031 ret = mlx5_hlist_insert(priv->mreg_cp_tbl,
3032 &mcp_res->hlist_ent);
3039 flow_list_destroy(dev, NULL, mcp_res->flow);
3045 * Release flow in RX_CP_TBL.
3048 * Pointer to Ethernet device.
3050 * Parent flow for wich copying is provided.
3053 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
3054 struct rte_flow *flow)
3056 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3057 struct mlx5_priv *priv = dev->data->dev_private;
3059 if (!mcp_res || !priv->mreg_cp_tbl)
3061 if (flow->copy_applied) {
3062 assert(mcp_res->appcnt);
3063 flow->copy_applied = 0;
3065 if (!mcp_res->appcnt)
3066 flow_drv_remove(dev, mcp_res->flow);
3069 * We do not check availability of metadata registers here,
3070 * because copy resources are not allocated in this case.
3072 if (--mcp_res->refcnt)
3074 assert(mcp_res->flow);
3075 flow_list_destroy(dev, NULL, mcp_res->flow);
3076 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3078 flow->mreg_copy = NULL;
3082 * Start flow in RX_CP_TBL.
3085 * Pointer to Ethernet device.
3087 * Parent flow for wich copying is provided.
3090 * 0 on success, a negative errno value otherwise and rte_errno is set.
3093 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
3094 struct rte_flow *flow)
3096 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3099 if (!mcp_res || flow->copy_applied)
3101 if (!mcp_res->appcnt) {
3102 ret = flow_drv_apply(dev, mcp_res->flow, NULL);
3107 flow->copy_applied = 1;
3112 * Stop flow in RX_CP_TBL.
3115 * Pointer to Ethernet device.
3117 * Parent flow for wich copying is provided.
3120 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
3121 struct rte_flow *flow)
3123 struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
3125 if (!mcp_res || !flow->copy_applied)
3127 assert(mcp_res->appcnt);
3129 flow->copy_applied = 0;
3130 if (!mcp_res->appcnt)
3131 flow_drv_remove(dev, mcp_res->flow);
3135 * Remove the default copy action from RX_CP_TBL.
3138 * Pointer to Ethernet device.
3141 flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
3143 struct mlx5_flow_mreg_copy_resource *mcp_res;
3144 struct mlx5_priv *priv = dev->data->dev_private;
3146 /* Check if default flow is registered. */
3147 if (!priv->mreg_cp_tbl)
3149 mcp_res = (void *)mlx5_hlist_lookup(priv->mreg_cp_tbl,
3150 MLX5_DEFAULT_COPY_ID);
3153 assert(mcp_res->flow);
3154 flow_list_destroy(dev, NULL, mcp_res->flow);
3155 mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
3160 * Add the default copy action in in RX_CP_TBL.
3163 * Pointer to Ethernet device.
3165 * Perform verbose error reporting if not NULL.
3168 * 0 for success, negative value otherwise and rte_errno is set.
3171 flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
3172 struct rte_flow_error *error)
3174 struct mlx5_priv *priv = dev->data->dev_private;
3175 struct mlx5_flow_mreg_copy_resource *mcp_res;
3177 /* Check whether extensive metadata feature is engaged. */
3178 if (!priv->config.dv_flow_en ||
3179 priv->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3180 !mlx5_flow_ext_mreg_supported(dev) ||
3181 !priv->sh->dv_regc0_mask)
3183 mcp_res = flow_mreg_add_copy_action(dev, MLX5_DEFAULT_COPY_ID, error);
3190 * Add a flow of copying flow metadata registers in RX_CP_TBL.
3192 * All the flow having Q/RSS action should be split by
3193 * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
3194 * performs the following,
3195 * - CQE->flow_tag := reg_c[1] (MARK)
3196 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3197 * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
3198 * but there should be a flow per each MARK ID set by MARK action.
3200 * For the aforementioned reason, if there's a MARK action in flow's action
3201 * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
3202 * the MARK ID to CQE's flow_tag like,
3203 * - If reg_c[1] is mark_id,
3204 * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3206 * For SET_META action which stores value in reg_c[0], as the destination is
3207 * also a flow metadata register (reg_b), adding a default flow is enough. Zero
3208 * MARK ID means the default flow. The default flow looks like,
3209 * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
3212 * Pointer to Ethernet device.
3214 * Pointer to flow structure.
3215 * @param[in] actions
3216 * Pointer to the list of actions.
3218 * Perform verbose error reporting if not NULL.
3221 * 0 on success, negative value otherwise and rte_errno is set.
3224 flow_mreg_update_copy_table(struct rte_eth_dev *dev,
3225 struct rte_flow *flow,
3226 const struct rte_flow_action *actions,
3227 struct rte_flow_error *error)
3229 struct mlx5_priv *priv = dev->data->dev_private;
3230 struct mlx5_dev_config *config = &priv->config;
3231 struct mlx5_flow_mreg_copy_resource *mcp_res;
3232 const struct rte_flow_action_mark *mark;
3234 /* Check whether extensive metadata feature is engaged. */
3235 if (!config->dv_flow_en ||
3236 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3237 !mlx5_flow_ext_mreg_supported(dev) ||
3238 !priv->sh->dv_regc0_mask)
3240 /* Find MARK action. */
3241 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3242 switch (actions->type) {
3243 case RTE_FLOW_ACTION_TYPE_FLAG:
3244 mcp_res = flow_mreg_add_copy_action
3245 (dev, MLX5_FLOW_MARK_DEFAULT, error);
3248 flow->mreg_copy = mcp_res;
3249 if (dev->data->dev_started) {
3251 flow->copy_applied = 1;
3254 case RTE_FLOW_ACTION_TYPE_MARK:
3255 mark = (const struct rte_flow_action_mark *)
3258 flow_mreg_add_copy_action(dev, mark->id, error);
3261 flow->mreg_copy = mcp_res;
3262 if (dev->data->dev_started) {
3264 flow->copy_applied = 1;
3274 #define MLX5_MAX_SPLIT_ACTIONS 24
3275 #define MLX5_MAX_SPLIT_ITEMS 24
3278 * Split the hairpin flow.
3279 * Since HW can't support encap on Rx we move the encap to Tx.
3280 * If the count action is after the encap then we also
3281 * move the count action. in this case the count will also measure
3285 * Pointer to Ethernet device.
3286 * @param[in] actions
3287 * Associated actions (list terminated by the END action).
3288 * @param[out] actions_rx
3290 * @param[out] actions_tx
3292 * @param[out] pattern_tx
3293 * The pattern items for the Tx flow.
3294 * @param[out] flow_id
3295 * The flow ID connected to this flow.
3301 flow_hairpin_split(struct rte_eth_dev *dev,
3302 const struct rte_flow_action actions[],
3303 struct rte_flow_action actions_rx[],
3304 struct rte_flow_action actions_tx[],
3305 struct rte_flow_item pattern_tx[],
3308 struct mlx5_priv *priv = dev->data->dev_private;
3309 const struct rte_flow_action_raw_encap *raw_encap;
3310 const struct rte_flow_action_raw_decap *raw_decap;
3311 struct mlx5_rte_flow_action_set_tag *set_tag;
3312 struct rte_flow_action *tag_action;
3313 struct mlx5_rte_flow_item_tag *tag_item;
3314 struct rte_flow_item *item;
3318 mlx5_flow_id_get(priv->sh->flow_id_pool, flow_id);
3319 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3320 switch (actions->type) {
3321 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3322 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
3323 rte_memcpy(actions_tx, actions,
3324 sizeof(struct rte_flow_action));
3327 case RTE_FLOW_ACTION_TYPE_COUNT:
3329 rte_memcpy(actions_tx, actions,
3330 sizeof(struct rte_flow_action));
3333 rte_memcpy(actions_rx, actions,
3334 sizeof(struct rte_flow_action));
3338 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3339 raw_encap = actions->conf;
3340 if (raw_encap->size >
3341 (sizeof(struct rte_flow_item_eth) +
3342 sizeof(struct rte_flow_item_ipv4))) {
3343 memcpy(actions_tx, actions,
3344 sizeof(struct rte_flow_action));
3348 rte_memcpy(actions_rx, actions,
3349 sizeof(struct rte_flow_action));
3353 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3354 raw_decap = actions->conf;
3355 if (raw_decap->size <
3356 (sizeof(struct rte_flow_item_eth) +
3357 sizeof(struct rte_flow_item_ipv4))) {
3358 memcpy(actions_tx, actions,
3359 sizeof(struct rte_flow_action));
3362 rte_memcpy(actions_rx, actions,
3363 sizeof(struct rte_flow_action));
3368 rte_memcpy(actions_rx, actions,
3369 sizeof(struct rte_flow_action));
3374 /* Add set meta action and end action for the Rx flow. */
3375 tag_action = actions_rx;
3376 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3378 rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
3380 set_tag = (void *)actions_rx;
3381 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL);
3382 assert(set_tag->id > REG_NONE);
3383 set_tag->data = *flow_id;
3384 tag_action->conf = set_tag;
3385 /* Create Tx item list. */
3386 rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
3387 addr = (void *)&pattern_tx[2];
3389 item->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
3390 tag_item = (void *)addr;
3391 tag_item->data = *flow_id;
3392 tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
3393 assert(set_tag->id > REG_NONE);
3394 item->spec = tag_item;
3395 addr += sizeof(struct mlx5_rte_flow_item_tag);
3396 tag_item = (void *)addr;
3397 tag_item->data = UINT32_MAX;
3398 tag_item->id = UINT16_MAX;
3399 item->mask = tag_item;
3400 addr += sizeof(struct mlx5_rte_flow_item_tag);
3403 item->type = RTE_FLOW_ITEM_TYPE_END;
3408 * The last stage of splitting chain, just creates the subflow
3409 * without any modification.
3412 * Pointer to Ethernet device.
3414 * Parent flow structure pointer.
3415 * @param[in, out] sub_flow
3416 * Pointer to return the created subflow, may be NULL.
3418 * Flow rule attributes.
3420 * Pattern specification (list terminated by the END pattern item).
3421 * @param[in] actions
3422 * Associated actions (list terminated by the END action).
3423 * @param[in] external
3424 * This flow rule is created by request external to PMD.
3426 * Perform verbose error reporting if not NULL.
3428 * 0 on success, negative value otherwise
3431 flow_create_split_inner(struct rte_eth_dev *dev,
3432 struct rte_flow *flow,
3433 struct mlx5_flow **sub_flow,
3434 const struct rte_flow_attr *attr,
3435 const struct rte_flow_item items[],
3436 const struct rte_flow_action actions[],
3437 bool external, struct rte_flow_error *error)
3439 struct mlx5_flow *dev_flow;
3441 dev_flow = flow_drv_prepare(flow, attr, items, actions, error);
3444 dev_flow->flow = flow;
3445 dev_flow->external = external;
3446 /* Subflow object was created, we must include one in the list. */
3447 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
3449 *sub_flow = dev_flow;
3450 return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
3454 * Split the meter flow.
3456 * As meter flow will split to three sub flow, other than meter
3457 * action, the other actions make sense to only meter accepts
3458 * the packet. If it need to be dropped, no other additional
3459 * actions should be take.
3461 * One kind of special action which decapsulates the L3 tunnel
3462 * header will be in the prefix sub flow, as not to take the
3463 * L3 tunnel header into account.
3466 * Pointer to Ethernet device.
3467 * @param[in] actions
3468 * Associated actions (list terminated by the END action).
3469 * @param[out] actions_sfx
3470 * Suffix flow actions.
3471 * @param[out] actions_pre
3472 * Prefix flow actions.
3473 * @param[out] pattern_sfx
3474 * The pattern items for the suffix flow.
3475 * @param[out] tag_sfx
3476 * Pointer to suffix flow tag.
3482 flow_meter_split_prep(struct rte_eth_dev *dev,
3483 const struct rte_flow_action actions[],
3484 struct rte_flow_action actions_sfx[],
3485 struct rte_flow_action actions_pre[])
3487 struct rte_flow_action *tag_action;
3488 struct mlx5_rte_flow_action_set_tag *set_tag;
3489 struct rte_flow_error error;
3490 const struct rte_flow_action_raw_encap *raw_encap;
3491 const struct rte_flow_action_raw_decap *raw_decap;
3494 /* Add the extra tag action first. */
3495 tag_action = actions_pre;
3496 tag_action->type = MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3498 /* Prepare the actions for prefix and suffix flow. */
3499 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
3500 switch (actions->type) {
3501 case RTE_FLOW_ACTION_TYPE_METER:
3502 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3503 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
3504 memcpy(actions_pre, actions,
3505 sizeof(struct rte_flow_action));
3508 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
3509 raw_encap = actions->conf;
3510 if (raw_encap->size >
3511 (sizeof(struct rte_flow_item_eth) +
3512 sizeof(struct rte_flow_item_ipv4))) {
3513 memcpy(actions_sfx, actions,
3514 sizeof(struct rte_flow_action));
3517 rte_memcpy(actions_pre, actions,
3518 sizeof(struct rte_flow_action));
3522 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
3523 raw_decap = actions->conf;
3524 /* Size 0 decap means 50 bytes as vxlan decap. */
3525 if (raw_decap->size && (raw_decap->size <
3526 (sizeof(struct rte_flow_item_eth) +
3527 sizeof(struct rte_flow_item_ipv4)))) {
3528 memcpy(actions_sfx, actions,
3529 sizeof(struct rte_flow_action));
3532 rte_memcpy(actions_pre, actions,
3533 sizeof(struct rte_flow_action));
3538 memcpy(actions_sfx, actions,
3539 sizeof(struct rte_flow_action));
3544 /* Add end action to the actions. */
3545 actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
3546 actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
3549 set_tag = (void *)actions_pre;
3550 set_tag->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0, &error);
3552 * Get the id from the qrss_pool to make qrss share the id with meter.
3554 tag_id = flow_qrss_get_id(dev);
3555 set_tag->data = rte_cpu_to_be_32(tag_id);
3556 tag_action->conf = set_tag;
3561 * Split action list having QUEUE/RSS for metadata register copy.
3563 * Once Q/RSS action is detected in user's action list, the flow action
3564 * should be split in order to copy metadata registers, which will happen in
3566 * - CQE->flow_tag := reg_c[1] (MARK)
3567 * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
3568 * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
3569 * This is because the last action of each flow must be a terminal action
3570 * (QUEUE, RSS or DROP).
3572 * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
3573 * stored and kept in the mlx5_flow structure per each sub_flow.
3575 * The Q/RSS action is replaced with,
3576 * - SET_TAG, setting the allocated flow ID to reg_c[2].
3577 * And the following JUMP action is added at the end,
3578 * - JUMP, to RX_CP_TBL.
3580 * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
3581 * flow_create_split_metadata() routine. The flow will look like,
3582 * - If flow ID matches (reg_c[2]), perform Q/RSS.
3585 * Pointer to Ethernet device.
3586 * @param[out] split_actions
3587 * Pointer to store split actions to jump to CP_TBL.
3588 * @param[in] actions
3589 * Pointer to the list of original flow actions.
3591 * Pointer to the Q/RSS action.
3592 * @param[in] actions_n
3593 * Number of original actions.
3595 * Perform verbose error reporting if not NULL.
3598 * non-zero unique flow_id on success, otherwise 0 and
3599 * error/rte_error are set.
3602 flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
3603 struct rte_flow_action *split_actions,
3604 const struct rte_flow_action *actions,
3605 const struct rte_flow_action *qrss,
3606 int actions_n, struct rte_flow_error *error)
3608 struct mlx5_rte_flow_action_set_tag *set_tag;
3609 struct rte_flow_action_jump *jump;
3610 const int qrss_idx = qrss - actions;
3611 uint32_t flow_id = 0;
3615 * Given actions will be split
3616 * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
3617 * - Add jump to mreg CP_TBL.
3618 * As a result, there will be one more action.
3621 memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
3622 set_tag = (void *)(split_actions + actions_n);
3624 * If tag action is not set to void(it means we are not the meter
3625 * suffix flow), add the tag action. Since meter suffix flow already
3626 * has the tag added.
3628 if (split_actions[qrss_idx].type != RTE_FLOW_ACTION_TYPE_VOID) {
3630 * Allocate the new subflow ID. This one is unique within
3631 * device and not shared with representors. Otherwise,
3632 * we would have to resolve multi-thread access synch
3633 * issue. Each flow on the shared device is appended
3634 * with source vport identifier, so the resulting
3635 * flows will be unique in the shared (by master and
3636 * representors) domain even if they have coinciding
3639 flow_id = flow_qrss_get_id(dev);
3641 return rte_flow_error_set(error, ENOMEM,
3642 RTE_FLOW_ERROR_TYPE_ACTION,
3643 NULL, "can't allocate id "
3644 "for split Q/RSS subflow");
3645 /* Internal SET_TAG action to set flow ID. */
3646 *set_tag = (struct mlx5_rte_flow_action_set_tag){
3649 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
3653 /* Construct new actions array. */
3654 /* Replace QUEUE/RSS action. */
3655 split_actions[qrss_idx] = (struct rte_flow_action){
3656 .type = MLX5_RTE_FLOW_ACTION_TYPE_TAG,
3660 /* JUMP action to jump to mreg copy table (CP_TBL). */
3661 jump = (void *)(set_tag + 1);
3662 *jump = (struct rte_flow_action_jump){
3663 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
3665 split_actions[actions_n - 2] = (struct rte_flow_action){
3666 .type = RTE_FLOW_ACTION_TYPE_JUMP,
3669 split_actions[actions_n - 1] = (struct rte_flow_action){
3670 .type = RTE_FLOW_ACTION_TYPE_END,
3676 * Extend the given action list for Tx metadata copy.
3678 * Copy the given action list to the ext_actions and add flow metadata register
3679 * copy action in order to copy reg_a set by WQE to reg_c[0].
3681 * @param[out] ext_actions
3682 * Pointer to the extended action list.
3683 * @param[in] actions
3684 * Pointer to the list of actions.
3685 * @param[in] actions_n
3686 * Number of actions in the list.
3688 * Perform verbose error reporting if not NULL.
3691 * 0 on success, negative value otherwise
3694 flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
3695 struct rte_flow_action *ext_actions,
3696 const struct rte_flow_action *actions,
3697 int actions_n, struct rte_flow_error *error)
3699 struct mlx5_flow_action_copy_mreg *cp_mreg =
3700 (struct mlx5_flow_action_copy_mreg *)
3701 (ext_actions + actions_n + 1);
3704 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
3708 ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
3712 memcpy(ext_actions, actions,
3713 sizeof(*ext_actions) * actions_n);
3714 ext_actions[actions_n - 1] = (struct rte_flow_action){
3715 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
3718 ext_actions[actions_n] = (struct rte_flow_action){
3719 .type = RTE_FLOW_ACTION_TYPE_END,
3725 * The splitting for metadata feature.
3727 * - Q/RSS action on NIC Rx should be split in order to pass by
3728 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3729 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3731 * - All the actions on NIC Tx should have a mreg copy action to
3732 * copy reg_a from WQE to reg_c[0].
3735 * Pointer to Ethernet device.
3737 * Parent flow structure pointer.
3739 * Flow rule attributes.
3741 * Pattern specification (list terminated by the END pattern item).
3742 * @param[in] actions
3743 * Associated actions (list terminated by the END action).
3744 * @param[in] external
3745 * This flow rule is created by request external to PMD.
3747 * Perform verbose error reporting if not NULL.
3749 * 0 on success, negative value otherwise
3752 flow_create_split_metadata(struct rte_eth_dev *dev,
3753 struct rte_flow *flow,
3754 const struct rte_flow_attr *attr,
3755 const struct rte_flow_item items[],
3756 const struct rte_flow_action actions[],
3757 bool external, struct rte_flow_error *error)
3759 struct mlx5_priv *priv = dev->data->dev_private;
3760 struct mlx5_dev_config *config = &priv->config;
3761 const struct rte_flow_action *qrss = NULL;
3762 struct rte_flow_action *ext_actions = NULL;
3763 struct mlx5_flow *dev_flow = NULL;
3764 uint32_t qrss_id = 0;
3770 /* Check whether extensive metadata feature is engaged. */
3771 if (!config->dv_flow_en ||
3772 config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
3773 !mlx5_flow_ext_mreg_supported(dev))
3774 return flow_create_split_inner(dev, flow, NULL, attr, items,
3775 actions, external, error);
3776 actions_n = flow_parse_qrss_action(actions, &qrss);
3778 /* Exclude hairpin flows from splitting. */
3779 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
3780 const struct rte_flow_action_queue *queue;
3783 if (mlx5_rxq_get_type(dev, queue->index) ==
3784 MLX5_RXQ_TYPE_HAIRPIN)
3786 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
3787 const struct rte_flow_action_rss *rss;
3790 if (mlx5_rxq_get_type(dev, rss->queue[0]) ==
3791 MLX5_RXQ_TYPE_HAIRPIN)
3796 /* Check if it is in meter suffix table. */
3797 mtr_sfx = attr->group == (attr->transfer ?
3798 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
3799 MLX5_FLOW_TABLE_LEVEL_SUFFIX);
3801 * Q/RSS action on NIC Rx should be split in order to pass by
3802 * the mreg copy table (RX_CP_TBL) and then it jumps to the
3803 * action table (RX_ACT_TBL) which has the split Q/RSS action.
3805 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3806 sizeof(struct rte_flow_action_set_tag) +
3807 sizeof(struct rte_flow_action_jump);
3808 ext_actions = rte_zmalloc(__func__, act_size, 0);
3810 return rte_flow_error_set(error, ENOMEM,
3811 RTE_FLOW_ERROR_TYPE_ACTION,
3812 NULL, "no memory to split "
3815 * If we are the suffix flow of meter, tag already exist.
3816 * Set the tag action to void.
3819 ext_actions[qrss - actions].type =
3820 RTE_FLOW_ACTION_TYPE_VOID;
3822 ext_actions[qrss - actions].type =
3823 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
3825 * Create the new actions list with removed Q/RSS action
3826 * and appended set tag and jump to register copy table
3827 * (RX_CP_TBL). We should preallocate unique tag ID here
3828 * in advance, because it is needed for set tag action.
3830 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
3831 qrss, actions_n, error);
3832 if (!mtr_sfx && !qrss_id) {
3836 } else if (attr->egress && !attr->transfer) {
3838 * All the actions on NIC Tx should have a metadata register
3839 * copy action to copy reg_a from WQE to reg_c[meta]
3841 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
3842 sizeof(struct mlx5_flow_action_copy_mreg);
3843 ext_actions = rte_zmalloc(__func__, act_size, 0);
3845 return rte_flow_error_set(error, ENOMEM,
3846 RTE_FLOW_ERROR_TYPE_ACTION,
3847 NULL, "no memory to split "
3849 /* Create the action list appended with copy register. */
3850 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
3855 /* Add the unmodified original or prefix subflow. */
3856 ret = flow_create_split_inner(dev, flow, &dev_flow, attr, items,
3857 ext_actions ? ext_actions : actions,
3863 const struct rte_flow_attr q_attr = {
3864 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
3867 /* Internal PMD action to set register. */
3868 struct mlx5_rte_flow_item_tag q_tag_spec = {
3872 struct rte_flow_item q_items[] = {
3874 .type = MLX5_RTE_FLOW_ITEM_TYPE_TAG,
3875 .spec = &q_tag_spec,
3880 .type = RTE_FLOW_ITEM_TYPE_END,
3883 struct rte_flow_action q_actions[] = {
3889 .type = RTE_FLOW_ACTION_TYPE_END,
3892 uint64_t hash_fields = dev_flow->hash_fields;
3895 * Configure the tag item only if there is no meter subflow.
3896 * Since tag is already marked in the meter suffix subflow
3897 * we can just use the meter suffix items as is.
3900 /* Not meter subflow. */
3903 * Put unique id in prefix flow due to it is destroyed
3904 * after suffix flow and id will be freed after there
3905 * is no actual flows with this id and identifier
3906 * reallocation becomes possible (for example, for
3907 * other flows in other threads).
3909 dev_flow->qrss_id = qrss_id;
3911 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
3915 q_tag_spec.id = ret;
3918 /* Add suffix subflow to execute Q/RSS. */
3919 ret = flow_create_split_inner(dev, flow, &dev_flow,
3920 &q_attr, mtr_sfx ? items :
3926 dev_flow->hash_fields = hash_fields;
3931 * We do not destroy the partially created sub_flows in case of error.
3932 * These ones are included into parent flow list and will be destroyed
3933 * by flow_drv_destroy.
3935 flow_qrss_free_id(dev, qrss_id);
3936 rte_free(ext_actions);
3941 * The splitting for meter feature.
3943 * - The meter flow will be split to two flows as prefix and
3944 * suffix flow. The packets make sense only it pass the prefix
3947 * - Reg_C_5 is used for the packet to match betweend prefix and
3951 * Pointer to Ethernet device.
3953 * Parent flow structure pointer.
3955 * Flow rule attributes.
3957 * Pattern specification (list terminated by the END pattern item).
3958 * @param[in] actions
3959 * Associated actions (list terminated by the END action).
3960 * @param[in] external
3961 * This flow rule is created by request external to PMD.
3963 * Perform verbose error reporting if not NULL.
3965 * 0 on success, negative value otherwise
3968 flow_create_split_meter(struct rte_eth_dev *dev,
3969 struct rte_flow *flow,
3970 const struct rte_flow_attr *attr,
3971 const struct rte_flow_item items[],
3972 const struct rte_flow_action actions[],
3973 bool external, struct rte_flow_error *error)
3975 struct mlx5_priv *priv = dev->data->dev_private;
3976 struct rte_flow_action *sfx_actions = NULL;
3977 struct rte_flow_action *pre_actions = NULL;
3978 struct rte_flow_item *sfx_items = NULL;
3979 const struct rte_flow_item *sfx_port_id_item;
3980 struct mlx5_flow *dev_flow = NULL;
3981 struct rte_flow_attr sfx_attr = *attr;
3983 uint32_t mtr_tag_id = 0;
3990 actions_n = flow_check_meter_action(actions, &mtr);
3992 struct mlx5_rte_flow_item_tag *tag_spec;
3993 /* The five prefix actions: meter, decap, encap, tag, end. */
3994 act_size = sizeof(struct rte_flow_action) * (actions_n + 5) +
3995 sizeof(struct rte_flow_action_set_tag);
3997 #define METER_SUFFIX_ITEM 3
3998 item_size = sizeof(struct rte_flow_item) * METER_SUFFIX_ITEM +
3999 sizeof(struct mlx5_rte_flow_item_tag);
4000 sfx_actions = rte_zmalloc(__func__, (act_size + item_size), 0);
4002 return rte_flow_error_set(error, ENOMEM,
4003 RTE_FLOW_ERROR_TYPE_ACTION,
4004 NULL, "no memory to split "
4006 pre_actions = sfx_actions + actions_n;
4007 mtr_tag_id = flow_meter_split_prep(dev, actions, sfx_actions,
4013 /* Add the prefix subflow. */
4014 ret = flow_create_split_inner(dev, flow, &dev_flow, attr, items,
4015 pre_actions, external, error);
4020 dev_flow->mtr_flow_id = mtr_tag_id;
4021 /* Prepare the suffix flow match pattern. */
4022 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
4024 tag_spec = (struct mlx5_rte_flow_item_tag *)(sfx_items +
4026 tag_spec->data = rte_cpu_to_be_32(dev_flow->mtr_flow_id);
4027 tag_spec->id = mlx5_flow_get_reg_id(dev, MLX5_MTR_SFX, 0,
4029 sfx_items->type = MLX5_RTE_FLOW_ITEM_TYPE_TAG;
4030 sfx_items->spec = tag_spec;
4031 sfx_items->last = NULL;
4032 sfx_items->mask = NULL;
4034 sfx_port_id_item = find_port_id_item(items);
4035 if (sfx_port_id_item) {
4036 memcpy(sfx_items, sfx_port_id_item,
4037 sizeof(*sfx_items));
4040 sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
4041 sfx_items -= METER_SUFFIX_ITEM;
4042 /* Setting the sfx group atrr. */
4043 sfx_attr.group = sfx_attr.transfer ?
4044 (MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
4045 MLX5_FLOW_TABLE_LEVEL_SUFFIX;
4047 /* Add the prefix subflow. */
4048 ret = flow_create_split_metadata(dev, flow, &sfx_attr,
4049 sfx_items ? sfx_items : items,
4050 sfx_actions ? sfx_actions : actions,
4054 rte_free(sfx_actions);
4059 * Split the flow to subflow set. The splitters might be linked
4060 * in the chain, like this:
4061 * flow_create_split_outer() calls:
4062 * flow_create_split_meter() calls:
4063 * flow_create_split_metadata(meter_subflow_0) calls:
4064 * flow_create_split_inner(metadata_subflow_0)
4065 * flow_create_split_inner(metadata_subflow_1)
4066 * flow_create_split_inner(metadata_subflow_2)
4067 * flow_create_split_metadata(meter_subflow_1) calls:
4068 * flow_create_split_inner(metadata_subflow_0)
4069 * flow_create_split_inner(metadata_subflow_1)
4070 * flow_create_split_inner(metadata_subflow_2)
4072 * This provide flexible way to add new levels of flow splitting.
4073 * The all of successfully created subflows are included to the
4074 * parent flow dev_flow list.
4077 * Pointer to Ethernet device.
4079 * Parent flow structure pointer.
4081 * Flow rule attributes.
4083 * Pattern specification (list terminated by the END pattern item).
4084 * @param[in] actions
4085 * Associated actions (list terminated by the END action).
4086 * @param[in] external
4087 * This flow rule is created by request external to PMD.
4089 * Perform verbose error reporting if not NULL.
4091 * 0 on success, negative value otherwise
4094 flow_create_split_outer(struct rte_eth_dev *dev,
4095 struct rte_flow *flow,
4096 const struct rte_flow_attr *attr,
4097 const struct rte_flow_item items[],
4098 const struct rte_flow_action actions[],
4099 bool external, struct rte_flow_error *error)
4103 ret = flow_create_split_meter(dev, flow, attr, items,
4104 actions, external, error);
4110 * Create a flow and add it to @p list.
4113 * Pointer to Ethernet device.
4115 * Pointer to a TAILQ flow list. If this parameter NULL,
4116 * no list insertion occurred, flow is just created,
4117 * this is caller's responsibility to track the
4120 * Flow rule attributes.
4122 * Pattern specification (list terminated by the END pattern item).
4123 * @param[in] actions
4124 * Associated actions (list terminated by the END action).
4125 * @param[in] external
4126 * This flow rule is created by request external to PMD.
4128 * Perform verbose error reporting if not NULL.
4131 * A flow on success, NULL otherwise and rte_errno is set.
4133 static struct rte_flow *
4134 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
4135 const struct rte_flow_attr *attr,
4136 const struct rte_flow_item items[],
4137 const struct rte_flow_action actions[],
4138 bool external, struct rte_flow_error *error)
4140 struct mlx5_priv *priv = dev->data->dev_private;
4141 struct rte_flow *flow = NULL;
4142 struct mlx5_flow *dev_flow;
4143 const struct rte_flow_action_rss *rss;
4145 struct rte_flow_expand_rss buf;
4146 uint8_t buffer[2048];
4149 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4150 uint8_t buffer[2048];
4153 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
4154 uint8_t buffer[2048];
4155 } actions_hairpin_tx;
4157 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
4158 uint8_t buffer[2048];
4160 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
4161 const struct rte_flow_action *p_actions_rx = actions;
4165 int hairpin_flow = 0;
4166 uint32_t hairpin_id = 0;
4167 struct rte_flow_attr attr_tx = { .priority = 0 };
4169 hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
4170 if (hairpin_flow > 0) {
4171 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
4175 flow_hairpin_split(dev, actions, actions_rx.actions,
4176 actions_hairpin_tx.actions, items_tx.items,
4178 p_actions_rx = actions_rx.actions;
4180 ret = flow_drv_validate(dev, attr, items, p_actions_rx, external,
4183 goto error_before_flow;
4184 flow_size = sizeof(struct rte_flow);
4185 rss = flow_get_rss_action(p_actions_rx);
4187 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
4190 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
4191 flow = rte_calloc(__func__, 1, flow_size, 0);
4194 goto error_before_flow;
4196 flow->drv_type = flow_get_drv_type(dev, attr);
4197 if (hairpin_id != 0)
4198 flow->hairpin_flow_id = hairpin_id;
4199 assert(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
4200 flow->drv_type < MLX5_FLOW_TYPE_MAX);
4201 flow->rss.queue = (void *)(flow + 1);
4204 * The following information is required by
4205 * mlx5_flow_hashfields_adjust() in advance.
4207 flow->rss.level = rss->level;
4208 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
4209 flow->rss.types = !rss->types ? ETH_RSS_IP : rss->types;
4211 LIST_INIT(&flow->dev_flows);
4212 if (rss && rss->types) {
4213 unsigned int graph_root;
4215 graph_root = find_graph_root(items, rss->level);
4216 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
4218 mlx5_support_expansion,
4221 (unsigned int)ret < sizeof(expand_buffer.buffer));
4224 buf->entry[0].pattern = (void *)(uintptr_t)items;
4226 for (i = 0; i < buf->entries; ++i) {
4228 * The splitter may create multiple dev_flows,
4229 * depending on configuration. In the simplest
4230 * case it just creates unmodified original flow.
4232 ret = flow_create_split_outer(dev, flow, attr,
4233 buf->entry[i].pattern,
4234 p_actions_rx, external,
4239 /* Create the tx flow. */
4241 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
4242 attr_tx.ingress = 0;
4244 dev_flow = flow_drv_prepare(flow, &attr_tx, items_tx.items,
4245 actions_hairpin_tx.actions, error);
4248 dev_flow->flow = flow;
4249 dev_flow->external = 0;
4250 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
4251 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
4253 actions_hairpin_tx.actions, error);
4258 * Update the metadata register copy table. If extensive
4259 * metadata feature is enabled and registers are supported
4260 * we might create the extra rte_flow for each unique
4261 * MARK/FLAG action ID.
4263 * The table is updated for ingress Flows only, because
4264 * the egress Flows belong to the different device and
4265 * copy table should be updated in peer NIC Rx domain.
4267 if (attr->ingress &&
4268 (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
4269 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
4273 if (dev->data->dev_started) {
4274 ret = flow_drv_apply(dev, flow, error);
4279 TAILQ_INSERT_TAIL(list, flow, next);
4280 flow_rxq_flags_set(dev, flow);
4284 mlx5_flow_id_release(priv->sh->flow_id_pool,
4289 flow_mreg_del_copy_action(dev, flow);
4290 ret = rte_errno; /* Save rte_errno before cleanup. */
4291 if (flow->hairpin_flow_id)
4292 mlx5_flow_id_release(priv->sh->flow_id_pool,
4293 flow->hairpin_flow_id);
4295 flow_drv_destroy(dev, flow);
4297 rte_errno = ret; /* Restore rte_errno. */
4302 * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
4303 * incoming packets to table 1.
4305 * Other flow rules, requested for group n, will be created in
4306 * e-switch table n+1.
4307 * Jump action to e-switch group n will be created to group n+1.
4309 * Used when working in switchdev mode, to utilise advantages of table 1
4313 * Pointer to Ethernet device.
4316 * Pointer to flow on success, NULL otherwise and rte_errno is set.
4319 mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
4321 const struct rte_flow_attr attr = {
4328 const struct rte_flow_item pattern = {
4329 .type = RTE_FLOW_ITEM_TYPE_END,
4331 struct rte_flow_action_jump jump = {
4334 const struct rte_flow_action actions[] = {
4336 .type = RTE_FLOW_ACTION_TYPE_JUMP,
4340 .type = RTE_FLOW_ACTION_TYPE_END,
4343 struct mlx5_priv *priv = dev->data->dev_private;
4344 struct rte_flow_error error;
4346 return flow_list_create(dev, &priv->ctrl_flows, &attr, &pattern,
4347 actions, false, &error);
4353 * @see rte_flow_create()
4357 mlx5_flow_create(struct rte_eth_dev *dev,
4358 const struct rte_flow_attr *attr,
4359 const struct rte_flow_item items[],
4360 const struct rte_flow_action actions[],
4361 struct rte_flow_error *error)
4363 struct mlx5_priv *priv = dev->data->dev_private;
4365 return flow_list_create(dev, &priv->flows,
4366 attr, items, actions, true, error);
4370 * Destroy a flow in a list.
4373 * Pointer to Ethernet device.
4375 * Pointer to a TAILQ flow list. If this parameter NULL,
4376 * there is no flow removal from the list.
4381 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
4382 struct rte_flow *flow)
4384 struct mlx5_priv *priv = dev->data->dev_private;
4387 * Update RX queue flags only if port is started, otherwise it is
4390 if (dev->data->dev_started)
4391 flow_rxq_flags_trim(dev, flow);
4392 if (flow->hairpin_flow_id)
4393 mlx5_flow_id_release(priv->sh->flow_id_pool,
4394 flow->hairpin_flow_id);
4395 flow_drv_destroy(dev, flow);
4397 TAILQ_REMOVE(list, flow, next);
4398 flow_mreg_del_copy_action(dev, flow);
4399 rte_free(flow->fdir);
4404 * Destroy all flows.
4407 * Pointer to Ethernet device.
4409 * Pointer to a TAILQ flow list.
4412 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
4414 while (!TAILQ_EMPTY(list)) {
4415 struct rte_flow *flow;
4417 flow = TAILQ_FIRST(list);
4418 flow_list_destroy(dev, list, flow);
4426 * Pointer to Ethernet device.
4428 * Pointer to a TAILQ flow list.
4431 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
4433 struct rte_flow *flow;
4435 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next) {
4436 flow_drv_remove(dev, flow);
4437 flow_mreg_stop_copy_action(dev, flow);
4439 flow_mreg_del_default_copy_action(dev);
4440 flow_rxq_flags_clear(dev);
4447 * Pointer to Ethernet device.
4449 * Pointer to a TAILQ flow list.
4452 * 0 on success, a negative errno value otherwise and rte_errno is set.
4455 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
4457 struct rte_flow *flow;
4458 struct rte_flow_error error;
4461 /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
4462 ret = flow_mreg_add_default_copy_action(dev, &error);
4465 /* Apply Flows created by application. */
4466 TAILQ_FOREACH(flow, list, next) {
4467 ret = flow_mreg_start_copy_action(dev, flow);
4470 ret = flow_drv_apply(dev, flow, &error);
4473 flow_rxq_flags_set(dev, flow);
4477 ret = rte_errno; /* Save rte_errno before cleanup. */
4478 mlx5_flow_stop(dev, list);
4479 rte_errno = ret; /* Restore rte_errno. */
4484 * Verify the flow list is empty
4487 * Pointer to Ethernet device.
4489 * @return the number of flows not released.
4492 mlx5_flow_verify(struct rte_eth_dev *dev)
4494 struct mlx5_priv *priv = dev->data->dev_private;
4495 struct rte_flow *flow;
4498 TAILQ_FOREACH(flow, &priv->flows, next) {
4499 DRV_LOG(DEBUG, "port %u flow %p still referenced",
4500 dev->data->port_id, (void *)flow);
4507 * Enable default hairpin egress flow.
4510 * Pointer to Ethernet device.
4515 * 0 on success, a negative errno value otherwise and rte_errno is set.
4518 mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
4521 struct mlx5_priv *priv = dev->data->dev_private;
4522 const struct rte_flow_attr attr = {
4526 struct mlx5_rte_flow_item_tx_queue queue_spec = {
4529 struct mlx5_rte_flow_item_tx_queue queue_mask = {
4530 .queue = UINT32_MAX,
4532 struct rte_flow_item items[] = {
4534 .type = MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
4535 .spec = &queue_spec,
4537 .mask = &queue_mask,
4540 .type = RTE_FLOW_ITEM_TYPE_END,
4543 struct rte_flow_action_jump jump = {
4544 .group = MLX5_HAIRPIN_TX_TABLE,
4546 struct rte_flow_action actions[2];
4547 struct rte_flow *flow;
4548 struct rte_flow_error error;
4550 actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
4551 actions[0].conf = &jump;
4552 actions[1].type = RTE_FLOW_ACTION_TYPE_END;
4553 flow = flow_list_create(dev, &priv->ctrl_flows,
4554 &attr, items, actions, false, &error);
4557 "Failed to create ctrl flow: rte_errno(%d),"
4558 " type(%d), message(%s)",
4559 rte_errno, error.type,
4560 error.message ? error.message : " (no stated reason)");
4567 * Enable a control flow configured from the control plane.
4570 * Pointer to Ethernet device.
4572 * An Ethernet flow spec to apply.
4574 * An Ethernet flow mask to apply.
4576 * A VLAN flow spec to apply.
4578 * A VLAN flow mask to apply.
4581 * 0 on success, a negative errno value otherwise and rte_errno is set.
4584 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
4585 struct rte_flow_item_eth *eth_spec,
4586 struct rte_flow_item_eth *eth_mask,
4587 struct rte_flow_item_vlan *vlan_spec,
4588 struct rte_flow_item_vlan *vlan_mask)
4590 struct mlx5_priv *priv = dev->data->dev_private;
4591 const struct rte_flow_attr attr = {
4593 .priority = MLX5_FLOW_PRIO_RSVD,
4595 struct rte_flow_item items[] = {
4597 .type = RTE_FLOW_ITEM_TYPE_ETH,
4603 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
4604 RTE_FLOW_ITEM_TYPE_END,
4610 .type = RTE_FLOW_ITEM_TYPE_END,
4613 uint16_t queue[priv->reta_idx_n];
4614 struct rte_flow_action_rss action_rss = {
4615 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4617 .types = priv->rss_conf.rss_hf,
4618 .key_len = priv->rss_conf.rss_key_len,
4619 .queue_num = priv->reta_idx_n,
4620 .key = priv->rss_conf.rss_key,
4623 struct rte_flow_action actions[] = {
4625 .type = RTE_FLOW_ACTION_TYPE_RSS,
4626 .conf = &action_rss,
4629 .type = RTE_FLOW_ACTION_TYPE_END,
4632 struct rte_flow *flow;
4633 struct rte_flow_error error;
4636 if (!priv->reta_idx_n || !priv->rxqs_n) {
4639 for (i = 0; i != priv->reta_idx_n; ++i)
4640 queue[i] = (*priv->reta_idx)[i];
4641 flow = flow_list_create(dev, &priv->ctrl_flows,
4642 &attr, items, actions, false, &error);
4649 * Enable a flow control configured from the control plane.
4652 * Pointer to Ethernet device.
4654 * An Ethernet flow spec to apply.
4656 * An Ethernet flow mask to apply.
4659 * 0 on success, a negative errno value otherwise and rte_errno is set.
4662 mlx5_ctrl_flow(struct rte_eth_dev *dev,
4663 struct rte_flow_item_eth *eth_spec,
4664 struct rte_flow_item_eth *eth_mask)
4666 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
4672 * @see rte_flow_destroy()
4676 mlx5_flow_destroy(struct rte_eth_dev *dev,
4677 struct rte_flow *flow,
4678 struct rte_flow_error *error __rte_unused)
4680 struct mlx5_priv *priv = dev->data->dev_private;
4682 flow_list_destroy(dev, &priv->flows, flow);
4687 * Destroy all flows.
4689 * @see rte_flow_flush()
4693 mlx5_flow_flush(struct rte_eth_dev *dev,
4694 struct rte_flow_error *error __rte_unused)
4696 struct mlx5_priv *priv = dev->data->dev_private;
4698 mlx5_flow_list_flush(dev, &priv->flows);
4705 * @see rte_flow_isolate()
4709 mlx5_flow_isolate(struct rte_eth_dev *dev,
4711 struct rte_flow_error *error)
4713 struct mlx5_priv *priv = dev->data->dev_private;
4715 if (dev->data->dev_started) {
4716 rte_flow_error_set(error, EBUSY,
4717 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4719 "port must be stopped first");
4722 priv->isolated = !!enable;
4724 dev->dev_ops = &mlx5_dev_ops_isolate;
4726 dev->dev_ops = &mlx5_dev_ops;
4733 * @see rte_flow_query()
4737 flow_drv_query(struct rte_eth_dev *dev,
4738 struct rte_flow *flow,
4739 const struct rte_flow_action *actions,
4741 struct rte_flow_error *error)
4743 const struct mlx5_flow_driver_ops *fops;
4744 enum mlx5_flow_drv_type ftype = flow->drv_type;
4746 assert(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
4747 fops = flow_get_drv_ops(ftype);
4749 return fops->query(dev, flow, actions, data, error);
4755 * @see rte_flow_query()
4759 mlx5_flow_query(struct rte_eth_dev *dev,
4760 struct rte_flow *flow,
4761 const struct rte_flow_action *actions,
4763 struct rte_flow_error *error)
4767 ret = flow_drv_query(dev, flow, actions, data, error);
4774 * Convert a flow director filter to a generic flow.
4777 * Pointer to Ethernet device.
4778 * @param fdir_filter
4779 * Flow director filter to add.
4781 * Generic flow parameters structure.
4784 * 0 on success, a negative errno value otherwise and rte_errno is set.
4787 flow_fdir_filter_convert(struct rte_eth_dev *dev,
4788 const struct rte_eth_fdir_filter *fdir_filter,
4789 struct mlx5_fdir *attributes)
4791 struct mlx5_priv *priv = dev->data->dev_private;
4792 const struct rte_eth_fdir_input *input = &fdir_filter->input;
4793 const struct rte_eth_fdir_masks *mask =
4794 &dev->data->dev_conf.fdir_conf.mask;
4796 /* Validate queue number. */
4797 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
4798 DRV_LOG(ERR, "port %u invalid queue number %d",
4799 dev->data->port_id, fdir_filter->action.rx_queue);
4803 attributes->attr.ingress = 1;
4804 attributes->items[0] = (struct rte_flow_item) {
4805 .type = RTE_FLOW_ITEM_TYPE_ETH,
4806 .spec = &attributes->l2,
4807 .mask = &attributes->l2_mask,
4809 switch (fdir_filter->action.behavior) {
4810 case RTE_ETH_FDIR_ACCEPT:
4811 attributes->actions[0] = (struct rte_flow_action){
4812 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
4813 .conf = &attributes->queue,
4816 case RTE_ETH_FDIR_REJECT:
4817 attributes->actions[0] = (struct rte_flow_action){
4818 .type = RTE_FLOW_ACTION_TYPE_DROP,
4822 DRV_LOG(ERR, "port %u invalid behavior %d",
4824 fdir_filter->action.behavior);
4825 rte_errno = ENOTSUP;
4828 attributes->queue.index = fdir_filter->action.rx_queue;
4830 switch (fdir_filter->input.flow_type) {
4831 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4832 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4833 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
4834 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
4835 .src_addr = input->flow.ip4_flow.src_ip,
4836 .dst_addr = input->flow.ip4_flow.dst_ip,
4837 .time_to_live = input->flow.ip4_flow.ttl,
4838 .type_of_service = input->flow.ip4_flow.tos,
4840 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
4841 .src_addr = mask->ipv4_mask.src_ip,
4842 .dst_addr = mask->ipv4_mask.dst_ip,
4843 .time_to_live = mask->ipv4_mask.ttl,
4844 .type_of_service = mask->ipv4_mask.tos,
4845 .next_proto_id = mask->ipv4_mask.proto,
4847 attributes->items[1] = (struct rte_flow_item){
4848 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4849 .spec = &attributes->l3,
4850 .mask = &attributes->l3_mask,
4853 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
4854 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
4855 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
4856 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
4857 .hop_limits = input->flow.ipv6_flow.hop_limits,
4858 .proto = input->flow.ipv6_flow.proto,
4861 memcpy(attributes->l3.ipv6.hdr.src_addr,
4862 input->flow.ipv6_flow.src_ip,
4863 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4864 memcpy(attributes->l3.ipv6.hdr.dst_addr,
4865 input->flow.ipv6_flow.dst_ip,
4866 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
4867 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
4868 mask->ipv6_mask.src_ip,
4869 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4870 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
4871 mask->ipv6_mask.dst_ip,
4872 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
4873 attributes->items[1] = (struct rte_flow_item){
4874 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4875 .spec = &attributes->l3,
4876 .mask = &attributes->l3_mask,
4880 DRV_LOG(ERR, "port %u invalid flow type%d",
4881 dev->data->port_id, fdir_filter->input.flow_type);
4882 rte_errno = ENOTSUP;
4886 switch (fdir_filter->input.flow_type) {
4887 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
4888 attributes->l4.udp.hdr = (struct rte_udp_hdr){
4889 .src_port = input->flow.udp4_flow.src_port,
4890 .dst_port = input->flow.udp4_flow.dst_port,
4892 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
4893 .src_port = mask->src_port_mask,
4894 .dst_port = mask->dst_port_mask,
4896 attributes->items[2] = (struct rte_flow_item){
4897 .type = RTE_FLOW_ITEM_TYPE_UDP,
4898 .spec = &attributes->l4,
4899 .mask = &attributes->l4_mask,
4902 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
4903 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
4904 .src_port = input->flow.tcp4_flow.src_port,
4905 .dst_port = input->flow.tcp4_flow.dst_port,
4907 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
4908 .src_port = mask->src_port_mask,
4909 .dst_port = mask->dst_port_mask,
4911 attributes->items[2] = (struct rte_flow_item){
4912 .type = RTE_FLOW_ITEM_TYPE_TCP,
4913 .spec = &attributes->l4,
4914 .mask = &attributes->l4_mask,
4917 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
4918 attributes->l4.udp.hdr = (struct rte_udp_hdr){
4919 .src_port = input->flow.udp6_flow.src_port,
4920 .dst_port = input->flow.udp6_flow.dst_port,
4922 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
4923 .src_port = mask->src_port_mask,
4924 .dst_port = mask->dst_port_mask,
4926 attributes->items[2] = (struct rte_flow_item){
4927 .type = RTE_FLOW_ITEM_TYPE_UDP,
4928 .spec = &attributes->l4,
4929 .mask = &attributes->l4_mask,
4932 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
4933 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
4934 .src_port = input->flow.tcp6_flow.src_port,
4935 .dst_port = input->flow.tcp6_flow.dst_port,
4937 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
4938 .src_port = mask->src_port_mask,
4939 .dst_port = mask->dst_port_mask,
4941 attributes->items[2] = (struct rte_flow_item){
4942 .type = RTE_FLOW_ITEM_TYPE_TCP,
4943 .spec = &attributes->l4,
4944 .mask = &attributes->l4_mask,
4947 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
4948 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
4951 DRV_LOG(ERR, "port %u invalid flow type%d",
4952 dev->data->port_id, fdir_filter->input.flow_type);
4953 rte_errno = ENOTSUP;
4959 #define FLOW_FDIR_CMP(f1, f2, fld) \
4960 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
4963 * Compare two FDIR flows. If items and actions are identical, the two flows are
4967 * Pointer to Ethernet device.
4969 * FDIR flow to compare.
4971 * FDIR flow to compare.
4974 * Zero on match, 1 otherwise.
4977 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
4979 if (FLOW_FDIR_CMP(f1, f2, attr) ||
4980 FLOW_FDIR_CMP(f1, f2, l2) ||
4981 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
4982 FLOW_FDIR_CMP(f1, f2, l3) ||
4983 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
4984 FLOW_FDIR_CMP(f1, f2, l4) ||
4985 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
4986 FLOW_FDIR_CMP(f1, f2, actions[0].type))
4988 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
4989 FLOW_FDIR_CMP(f1, f2, queue))
4995 * Search device flow list to find out a matched FDIR flow.
4998 * Pointer to Ethernet device.
5000 * FDIR flow to lookup.
5003 * Pointer of flow if found, NULL otherwise.
5005 static struct rte_flow *
5006 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
5008 struct mlx5_priv *priv = dev->data->dev_private;
5009 struct rte_flow *flow = NULL;
5012 TAILQ_FOREACH(flow, &priv->flows, next) {
5013 if (flow->fdir && !flow_fdir_cmp(flow->fdir, fdir_flow)) {
5014 DRV_LOG(DEBUG, "port %u found FDIR flow %p",
5015 dev->data->port_id, (void *)flow);
5023 * Add new flow director filter and store it in list.
5026 * Pointer to Ethernet device.
5027 * @param fdir_filter
5028 * Flow director filter to add.
5031 * 0 on success, a negative errno value otherwise and rte_errno is set.
5034 flow_fdir_filter_add(struct rte_eth_dev *dev,
5035 const struct rte_eth_fdir_filter *fdir_filter)
5037 struct mlx5_priv *priv = dev->data->dev_private;
5038 struct mlx5_fdir *fdir_flow;
5039 struct rte_flow *flow;
5042 fdir_flow = rte_zmalloc(__func__, sizeof(*fdir_flow), 0);
5047 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
5050 flow = flow_fdir_filter_lookup(dev, fdir_flow);
5055 flow = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
5056 fdir_flow->items, fdir_flow->actions, true,
5060 assert(!flow->fdir);
5061 flow->fdir = fdir_flow;
5062 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
5063 dev->data->port_id, (void *)flow);
5066 rte_free(fdir_flow);
5071 * Delete specific filter.
5074 * Pointer to Ethernet device.
5075 * @param fdir_filter
5076 * Filter to be deleted.
5079 * 0 on success, a negative errno value otherwise and rte_errno is set.
5082 flow_fdir_filter_delete(struct rte_eth_dev *dev,
5083 const struct rte_eth_fdir_filter *fdir_filter)
5085 struct mlx5_priv *priv = dev->data->dev_private;
5086 struct rte_flow *flow;
5087 struct mlx5_fdir fdir_flow = {
5092 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
5095 flow = flow_fdir_filter_lookup(dev, &fdir_flow);
5100 flow_list_destroy(dev, &priv->flows, flow);
5101 DRV_LOG(DEBUG, "port %u deleted FDIR flow %p",
5102 dev->data->port_id, (void *)flow);
5107 * Update queue for specific filter.
5110 * Pointer to Ethernet device.
5111 * @param fdir_filter
5112 * Filter to be updated.
5115 * 0 on success, a negative errno value otherwise and rte_errno is set.
5118 flow_fdir_filter_update(struct rte_eth_dev *dev,
5119 const struct rte_eth_fdir_filter *fdir_filter)
5123 ret = flow_fdir_filter_delete(dev, fdir_filter);
5126 return flow_fdir_filter_add(dev, fdir_filter);
5130 * Flush all filters.
5133 * Pointer to Ethernet device.
5136 flow_fdir_filter_flush(struct rte_eth_dev *dev)
5138 struct mlx5_priv *priv = dev->data->dev_private;
5140 mlx5_flow_list_flush(dev, &priv->flows);
5144 * Get flow director information.
5147 * Pointer to Ethernet device.
5148 * @param[out] fdir_info
5149 * Resulting flow director information.
5152 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
5154 struct rte_eth_fdir_masks *mask =
5155 &dev->data->dev_conf.fdir_conf.mask;
5157 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
5158 fdir_info->guarant_spc = 0;
5159 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
5160 fdir_info->max_flexpayload = 0;
5161 fdir_info->flow_types_mask[0] = 0;
5162 fdir_info->flex_payload_unit = 0;
5163 fdir_info->max_flex_payload_segment_num = 0;
5164 fdir_info->flex_payload_limit = 0;
5165 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
5169 * Deal with flow director operations.
5172 * Pointer to Ethernet device.
5174 * Operation to perform.
5176 * Pointer to operation-specific structure.
5179 * 0 on success, a negative errno value otherwise and rte_errno is set.
5182 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
5185 enum rte_fdir_mode fdir_mode =
5186 dev->data->dev_conf.fdir_conf.mode;
5188 if (filter_op == RTE_ETH_FILTER_NOP)
5190 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
5191 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5192 DRV_LOG(ERR, "port %u flow director mode %d not supported",
5193 dev->data->port_id, fdir_mode);
5197 switch (filter_op) {
5198 case RTE_ETH_FILTER_ADD:
5199 return flow_fdir_filter_add(dev, arg);
5200 case RTE_ETH_FILTER_UPDATE:
5201 return flow_fdir_filter_update(dev, arg);
5202 case RTE_ETH_FILTER_DELETE:
5203 return flow_fdir_filter_delete(dev, arg);
5204 case RTE_ETH_FILTER_FLUSH:
5205 flow_fdir_filter_flush(dev);
5207 case RTE_ETH_FILTER_INFO:
5208 flow_fdir_info_get(dev, arg);
5211 DRV_LOG(DEBUG, "port %u unknown operation %u",
5212 dev->data->port_id, filter_op);
5220 * Manage filter operations.
5223 * Pointer to Ethernet device structure.
5224 * @param filter_type
5227 * Operation to perform.
5229 * Pointer to operation-specific structure.
5232 * 0 on success, a negative errno value otherwise and rte_errno is set.
5235 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
5236 enum rte_filter_type filter_type,
5237 enum rte_filter_op filter_op,
5240 switch (filter_type) {
5241 case RTE_ETH_FILTER_GENERIC:
5242 if (filter_op != RTE_ETH_FILTER_GET) {
5246 *(const void **)arg = &mlx5_flow_ops;
5248 case RTE_ETH_FILTER_FDIR:
5249 return flow_fdir_ctrl_func(dev, filter_op, arg);
5251 DRV_LOG(ERR, "port %u filter type (%d) not supported",
5252 dev->data->port_id, filter_type);
5253 rte_errno = ENOTSUP;
5260 * Create the needed meter and suffix tables.
5263 * Pointer to Ethernet device.
5265 * Pointer to the flow meter.
5268 * Pointer to table set on success, NULL otherwise.
5270 struct mlx5_meter_domains_infos *
5271 mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
5272 const struct mlx5_flow_meter *fm)
5274 const struct mlx5_flow_driver_ops *fops;
5276 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5277 return fops->create_mtr_tbls(dev, fm);
5281 * Destroy the meter table set.
5284 * Pointer to Ethernet device.
5286 * Pointer to the meter table set.
5292 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
5293 struct mlx5_meter_domains_infos *tbls)
5295 const struct mlx5_flow_driver_ops *fops;
5297 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5298 return fops->destroy_mtr_tbls(dev, tbls);
5302 * Create policer rules.
5305 * Pointer to Ethernet device.
5307 * Pointer to flow meter structure.
5309 * Pointer to flow attributes.
5312 * 0 on success, -1 otherwise.
5315 mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
5316 struct mlx5_flow_meter *fm,
5317 const struct rte_flow_attr *attr)
5319 const struct mlx5_flow_driver_ops *fops;
5321 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5322 return fops->create_policer_rules(dev, fm, attr);
5326 * Destroy policer rules.
5329 * Pointer to flow meter structure.
5331 * Pointer to flow attributes.
5334 * 0 on success, -1 otherwise.
5337 mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
5338 struct mlx5_flow_meter *fm,
5339 const struct rte_flow_attr *attr)
5341 const struct mlx5_flow_driver_ops *fops;
5343 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5344 return fops->destroy_policer_rules(dev, fm, attr);
5348 * Allocate a counter.
5351 * Pointer to Ethernet device structure.
5354 * Pointer to allocated counter on success, NULL otherwise.
5356 struct mlx5_flow_counter *
5357 mlx5_counter_alloc(struct rte_eth_dev *dev)
5359 const struct mlx5_flow_driver_ops *fops;
5360 struct rte_flow_attr attr = { .transfer = 0 };
5362 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5363 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5364 return fops->counter_alloc(dev);
5367 "port %u counter allocate is not supported.",
5368 dev->data->port_id);
5376 * Pointer to Ethernet device structure.
5378 * Pointer to counter to be free.
5381 mlx5_counter_free(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt)
5383 const struct mlx5_flow_driver_ops *fops;
5384 struct rte_flow_attr attr = { .transfer = 0 };
5386 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5387 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5388 fops->counter_free(dev, cnt);
5392 "port %u counter free is not supported.",
5393 dev->data->port_id);
5397 * Query counter statistics.
5400 * Pointer to Ethernet device structure.
5402 * Pointer to counter to query.
5404 * Set to clear counter statistics.
5406 * The counter hits packets number to save.
5408 * The counter hits bytes number to save.
5411 * 0 on success, a negative errno value otherwise.
5414 mlx5_counter_query(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt,
5415 bool clear, uint64_t *pkts, uint64_t *bytes)
5417 const struct mlx5_flow_driver_ops *fops;
5418 struct rte_flow_attr attr = { .transfer = 0 };
5420 if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
5421 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
5422 return fops->counter_query(dev, cnt, clear, pkts, bytes);
5425 "port %u counter query is not supported.",
5426 dev->data->port_id);
5430 #define MLX5_POOL_QUERY_FREQ_US 1000000
5433 * Set the periodic procedure for triggering asynchronous batch queries for all
5434 * the counter pools.
5437 * Pointer to mlx5_ibv_shared object.
5440 mlx5_set_query_alarm(struct mlx5_ibv_shared *sh)
5442 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(sh, 0, 0);
5443 uint32_t pools_n = rte_atomic16_read(&cont->n_valid);
5446 cont = MLX5_CNT_CONTAINER(sh, 1, 0);
5447 pools_n += rte_atomic16_read(&cont->n_valid);
5448 us = MLX5_POOL_QUERY_FREQ_US / pools_n;
5449 DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
5450 if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
5451 sh->cmng.query_thread_on = 0;
5452 DRV_LOG(ERR, "Cannot reinitialize query alarm");
5454 sh->cmng.query_thread_on = 1;
5459 * The periodic procedure for triggering asynchronous batch queries for all the
5460 * counter pools. This function is probably called by the host thread.
5463 * The parameter for the alarm process.
5466 mlx5_flow_query_alarm(void *arg)
5468 struct mlx5_ibv_shared *sh = arg;
5469 struct mlx5_devx_obj *dcs;
5472 uint8_t batch = sh->cmng.batch;
5473 uint16_t pool_index = sh->cmng.pool_index;
5474 struct mlx5_pools_container *cont;
5475 struct mlx5_pools_container *mcont;
5476 struct mlx5_flow_counter_pool *pool;
5478 if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES)
5481 cont = MLX5_CNT_CONTAINER(sh, batch, 1);
5482 mcont = MLX5_CNT_CONTAINER(sh, batch, 0);
5483 /* Check if resize was done and need to flip a container. */
5484 if (cont != mcont) {
5486 /* Clean the old container. */
5487 rte_free(cont->pools);
5488 memset(cont, 0, sizeof(*cont));
5491 /* Flip the host container. */
5492 sh->cmng.mhi[batch] ^= (uint8_t)2;
5496 /* 2 empty containers case is unexpected. */
5497 if (unlikely(batch != sh->cmng.batch))
5501 goto next_container;
5503 pool = cont->pools[pool_index];
5505 /* There is a pool query in progress. */
5508 LIST_FIRST(&sh->cmng.free_stat_raws);
5510 /* No free counter statistics raw memory. */
5512 dcs = (struct mlx5_devx_obj *)(uintptr_t)rte_atomic64_read
5514 offset = batch ? 0 : dcs->id % MLX5_COUNTERS_PER_POOL;
5515 ret = mlx5_devx_cmd_flow_counter_query(dcs, 0, MLX5_COUNTERS_PER_POOL -
5517 pool->raw_hw->mem_mng->dm->id,
5519 (pool->raw_hw->data + offset),
5521 (uint64_t)(uintptr_t)pool);
5523 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
5524 " %d", pool->min_dcs->id);
5525 pool->raw_hw = NULL;
5528 pool->raw_hw->min_dcs_id = dcs->id;
5529 LIST_REMOVE(pool->raw_hw, next);
5530 sh->cmng.pending_queries++;
5532 if (pool_index >= rte_atomic16_read(&cont->n_valid)) {
5537 sh->cmng.batch = batch;
5538 sh->cmng.pool_index = pool_index;
5539 mlx5_set_query_alarm(sh);
5543 * Handler for the HW respond about ready values from an asynchronous batch
5544 * query. This function is probably called by the host thread.
5547 * The pointer to the shared IB device context.
5548 * @param[in] async_id
5549 * The Devx async ID.
5551 * The status of the completion.
5554 mlx5_flow_async_pool_query_handle(struct mlx5_ibv_shared *sh,
5555 uint64_t async_id, int status)
5557 struct mlx5_flow_counter_pool *pool =
5558 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
5559 struct mlx5_counter_stats_raw *raw_to_free;
5561 if (unlikely(status)) {
5562 raw_to_free = pool->raw_hw;
5564 raw_to_free = pool->raw;
5565 rte_spinlock_lock(&pool->sl);
5566 pool->raw = pool->raw_hw;
5567 rte_spinlock_unlock(&pool->sl);
5568 rte_atomic64_add(&pool->query_gen, 1);
5569 /* Be sure the new raw counters data is updated in memory. */
5572 LIST_INSERT_HEAD(&sh->cmng.free_stat_raws, raw_to_free, next);
5573 pool->raw_hw = NULL;
5574 sh->cmng.pending_queries--;
5578 * Translate the rte_flow group index to HW table value.
5580 * @param[in] attributes
5581 * Pointer to flow attributes
5582 * @param[in] external
5583 * Value is part of flow rule created by request external to PMD.
5585 * rte_flow group index value.
5589 * Pointer to error structure.
5592 * 0 on success, a negative errno value otherwise and rte_errno is set.
5595 mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, bool external,
5596 uint32_t group, uint32_t *table,
5597 struct rte_flow_error *error)
5599 if (attributes->transfer && external) {
5600 if (group == UINT32_MAX)
5601 return rte_flow_error_set
5603 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5605 "group index not supported");
5614 * Discover availability of metadata reg_c's.
5616 * Iteratively use test flows to check availability.
5619 * Pointer to the Ethernet device structure.
5622 * 0 on success, a negative errno value otherwise and rte_errno is set.
5625 mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
5627 struct mlx5_priv *priv = dev->data->dev_private;
5628 struct mlx5_dev_config *config = &priv->config;
5629 enum modify_reg idx;
5632 /* reg_c[0] and reg_c[1] are reserved. */
5633 config->flow_mreg_c[n++] = REG_C_0;
5634 config->flow_mreg_c[n++] = REG_C_1;
5635 /* Discover availability of other reg_c's. */
5636 for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
5637 struct rte_flow_attr attr = {
5638 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5639 .priority = MLX5_FLOW_PRIO_RSVD,
5642 struct rte_flow_item items[] = {
5644 .type = RTE_FLOW_ITEM_TYPE_END,
5647 struct rte_flow_action actions[] = {
5649 .type = MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5650 .conf = &(struct mlx5_flow_action_copy_mreg){
5656 .type = RTE_FLOW_ACTION_TYPE_JUMP,
5657 .conf = &(struct rte_flow_action_jump){
5658 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5662 .type = RTE_FLOW_ACTION_TYPE_END,
5665 struct rte_flow *flow;
5666 struct rte_flow_error error;
5668 if (!config->dv_flow_en)
5670 /* Create internal flow, validation skips copy action. */
5671 flow = flow_list_create(dev, NULL, &attr, items,
5672 actions, false, &error);
5675 if (dev->data->dev_started || !flow_drv_apply(dev, flow, NULL))
5676 config->flow_mreg_c[n++] = idx;
5677 flow_list_destroy(dev, NULL, flow);
5679 for (; n < MLX5_MREG_C_NUM; ++n)
5680 config->flow_mreg_c[n] = REG_NONE;
5685 * Dump flow raw hw data to file
5688 * The pointer to Ethernet device.
5690 * A pointer to a file for output.
5692 * Perform verbose error reporting if not NULL. PMDs initialize this
5693 * structure in case of error only.
5695 * 0 on success, a nagative value otherwise.
5698 mlx5_flow_dev_dump(struct rte_eth_dev *dev,
5700 struct rte_flow_error *error __rte_unused)
5702 struct mlx5_priv *priv = dev->data->dev_private;
5704 return mlx5_devx_cmd_flow_dump(priv->sh, file);