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,
131 .type = RTE_FLOW_ITEM_TYPE_IPV4,
132 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
133 ETH_RSS_NONFRAG_IPV4_OTHER,
135 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
136 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
137 MLX5_EXPANSION_VXLAN_GPE),
138 .type = RTE_FLOW_ITEM_TYPE_UDP,
139 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
141 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
142 .type = RTE_FLOW_ITEM_TYPE_TCP,
143 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
145 [MLX5_EXPANSION_OUTER_IPV6] = {
146 .next = RTE_FLOW_EXPAND_RSS_NEXT
147 (MLX5_EXPANSION_OUTER_IPV6_UDP,
148 MLX5_EXPANSION_OUTER_IPV6_TCP),
149 .type = RTE_FLOW_ITEM_TYPE_IPV6,
150 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
151 ETH_RSS_NONFRAG_IPV6_OTHER,
153 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
154 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
155 MLX5_EXPANSION_VXLAN_GPE),
156 .type = RTE_FLOW_ITEM_TYPE_UDP,
157 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
159 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
160 .type = RTE_FLOW_ITEM_TYPE_TCP,
161 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
163 [MLX5_EXPANSION_VXLAN] = {
164 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
165 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
167 [MLX5_EXPANSION_VXLAN_GPE] = {
168 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
170 MLX5_EXPANSION_IPV6),
171 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
173 [MLX5_EXPANSION_GRE] = {
174 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
175 .type = RTE_FLOW_ITEM_TYPE_GRE,
177 [MLX5_EXPANSION_MPLS] = {
178 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
179 MLX5_EXPANSION_IPV6),
180 .type = RTE_FLOW_ITEM_TYPE_MPLS,
182 [MLX5_EXPANSION_ETH] = {
183 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
184 MLX5_EXPANSION_IPV6),
185 .type = RTE_FLOW_ITEM_TYPE_ETH,
187 [MLX5_EXPANSION_ETH_VLAN] = {
188 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
189 .type = RTE_FLOW_ITEM_TYPE_ETH,
191 [MLX5_EXPANSION_VLAN] = {
192 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
193 MLX5_EXPANSION_IPV6),
194 .type = RTE_FLOW_ITEM_TYPE_VLAN,
196 [MLX5_EXPANSION_IPV4] = {
197 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
198 MLX5_EXPANSION_IPV4_TCP),
199 .type = RTE_FLOW_ITEM_TYPE_IPV4,
200 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
201 ETH_RSS_NONFRAG_IPV4_OTHER,
203 [MLX5_EXPANSION_IPV4_UDP] = {
204 .type = RTE_FLOW_ITEM_TYPE_UDP,
205 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
207 [MLX5_EXPANSION_IPV4_TCP] = {
208 .type = RTE_FLOW_ITEM_TYPE_TCP,
209 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
211 [MLX5_EXPANSION_IPV6] = {
212 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
213 MLX5_EXPANSION_IPV6_TCP),
214 .type = RTE_FLOW_ITEM_TYPE_IPV6,
215 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
216 ETH_RSS_NONFRAG_IPV6_OTHER,
218 [MLX5_EXPANSION_IPV6_UDP] = {
219 .type = RTE_FLOW_ITEM_TYPE_UDP,
220 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
222 [MLX5_EXPANSION_IPV6_TCP] = {
223 .type = RTE_FLOW_ITEM_TYPE_TCP,
224 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
228 static const struct rte_flow_ops mlx5_flow_ops = {
229 .validate = mlx5_flow_validate,
230 .create = mlx5_flow_create,
231 .destroy = mlx5_flow_destroy,
232 .flush = mlx5_flow_flush,
233 .isolate = mlx5_flow_isolate,
234 .query = mlx5_flow_query,
237 /* Convert FDIR request to Generic flow. */
239 struct rte_flow_attr attr;
240 struct rte_flow_item items[4];
241 struct rte_flow_item_eth l2;
242 struct rte_flow_item_eth l2_mask;
244 struct rte_flow_item_ipv4 ipv4;
245 struct rte_flow_item_ipv6 ipv6;
248 struct rte_flow_item_ipv4 ipv4;
249 struct rte_flow_item_ipv6 ipv6;
252 struct rte_flow_item_udp udp;
253 struct rte_flow_item_tcp tcp;
256 struct rte_flow_item_udp udp;
257 struct rte_flow_item_tcp tcp;
259 struct rte_flow_action actions[2];
260 struct rte_flow_action_queue queue;
263 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
264 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
265 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
268 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
269 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
270 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
271 { 9, 10, 11 }, { 12, 13, 14 },
274 /* Tunnel information. */
275 struct mlx5_flow_tunnel_info {
276 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
277 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
280 static struct mlx5_flow_tunnel_info tunnels_info[] = {
282 .tunnel = MLX5_FLOW_LAYER_VXLAN,
283 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
286 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
287 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
290 .tunnel = MLX5_FLOW_LAYER_GRE,
291 .ptype = RTE_PTYPE_TUNNEL_GRE,
294 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
295 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
298 .tunnel = MLX5_FLOW_LAYER_MPLS,
299 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
304 * Discover the maximum number of priority available.
307 * Pointer to the Ethernet device structure.
310 * number of supported flow priority on success, a negative errno
311 * value otherwise and rte_errno is set.
314 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
316 struct mlx5_priv *priv = dev->data->dev_private;
318 struct ibv_flow_attr attr;
319 struct ibv_flow_spec_eth eth;
320 struct ibv_flow_spec_action_drop drop;
324 .port = (uint8_t)priv->ibv_port,
327 .type = IBV_FLOW_SPEC_ETH,
328 .size = sizeof(struct ibv_flow_spec_eth),
331 .size = sizeof(struct ibv_flow_spec_action_drop),
332 .type = IBV_FLOW_SPEC_ACTION_DROP,
335 struct ibv_flow *flow;
336 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
337 uint16_t vprio[] = { 8, 16 };
345 for (i = 0; i != RTE_DIM(vprio); i++) {
346 flow_attr.attr.priority = vprio[i] - 1;
347 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
350 claim_zero(mlx5_glue->destroy_flow(flow));
353 mlx5_hrxq_drop_release(dev);
356 priority = RTE_DIM(priority_map_3);
359 priority = RTE_DIM(priority_map_5);
364 "port %u verbs maximum priority: %d expected 8/16",
365 dev->data->port_id, priority);
368 DRV_LOG(INFO, "port %u flow maximum priority: %d",
369 dev->data->port_id, priority);
374 * Adjust flow priority based on the highest layer and the request priority.
377 * Pointer to the Ethernet device structure.
378 * @param[in] priority
379 * The rule base priority.
380 * @param[in] subpriority
381 * The priority based on the items.
386 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
387 uint32_t subpriority)
390 struct mlx5_priv *priv = dev->data->dev_private;
392 switch (priv->config.flow_prio) {
393 case RTE_DIM(priority_map_3):
394 res = priority_map_3[priority][subpriority];
396 case RTE_DIM(priority_map_5):
397 res = priority_map_5[priority][subpriority];
404 * Verify the @p item specifications (spec, last, mask) are compatible with the
408 * Item specification.
410 * @p item->mask or flow default bit-masks.
411 * @param[in] nic_mask
412 * Bit-masks covering supported fields by the NIC to compare with user mask.
414 * Bit-masks size in bytes.
416 * Pointer to error structure.
419 * 0 on success, a negative errno value otherwise and rte_errno is set.
422 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
424 const uint8_t *nic_mask,
426 struct rte_flow_error *error)
431 for (i = 0; i < size; ++i)
432 if ((nic_mask[i] | mask[i]) != nic_mask[i])
433 return rte_flow_error_set(error, ENOTSUP,
434 RTE_FLOW_ERROR_TYPE_ITEM,
436 "mask enables non supported"
438 if (!item->spec && (item->mask || item->last))
439 return rte_flow_error_set(error, EINVAL,
440 RTE_FLOW_ERROR_TYPE_ITEM, item,
441 "mask/last without a spec is not"
443 if (item->spec && item->last) {
449 for (i = 0; i < size; ++i) {
450 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
451 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
453 ret = memcmp(spec, last, size);
455 return rte_flow_error_set(error, EINVAL,
456 RTE_FLOW_ERROR_TYPE_ITEM,
458 "range is not valid");
464 * Adjust the hash fields according to the @p flow information.
466 * @param[in] dev_flow.
467 * Pointer to the mlx5_flow.
469 * 1 when the hash field is for a tunnel item.
470 * @param[in] layer_types
472 * @param[in] hash_fields
476 * The hash fileds that should be used.
479 mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow,
480 int tunnel __rte_unused, uint64_t layer_types,
481 uint64_t hash_fields)
483 struct rte_flow *flow = dev_flow->flow;
484 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
485 int rss_request_inner = flow->rss.level >= 2;
487 /* Check RSS hash level for tunnel. */
488 if (tunnel && rss_request_inner)
489 hash_fields |= IBV_RX_HASH_INNER;
490 else if (tunnel || rss_request_inner)
493 /* Check if requested layer matches RSS hash fields. */
494 if (!(flow->rss.types & layer_types))
500 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
501 * if several tunnel rules are used on this queue, the tunnel ptype will be
505 * Rx queue to update.
508 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
511 uint32_t tunnel_ptype = 0;
513 /* Look up for the ptype to use. */
514 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
515 if (!rxq_ctrl->flow_tunnels_n[i])
518 tunnel_ptype = tunnels_info[i].ptype;
524 rxq_ctrl->rxq.tunnel = tunnel_ptype;
528 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
532 * Pointer to the Ethernet device structure.
533 * @param[in] dev_flow
534 * Pointer to device flow structure.
537 flow_drv_rxq_flags_set(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
539 struct mlx5_priv *priv = dev->data->dev_private;
540 struct rte_flow *flow = dev_flow->flow;
541 const int mark = !!(flow->actions &
542 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
543 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
546 for (i = 0; i != flow->rss.queue_num; ++i) {
547 int idx = (*flow->queue)[i];
548 struct mlx5_rxq_ctrl *rxq_ctrl =
549 container_of((*priv->rxqs)[idx],
550 struct mlx5_rxq_ctrl, rxq);
553 rxq_ctrl->rxq.mark = 1;
554 rxq_ctrl->flow_mark_n++;
559 /* Increase the counter matching the flow. */
560 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
561 if ((tunnels_info[j].tunnel &
563 tunnels_info[j].tunnel) {
564 rxq_ctrl->flow_tunnels_n[j]++;
568 flow_rxq_tunnel_ptype_update(rxq_ctrl);
574 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
577 * Pointer to the Ethernet device structure.
579 * Pointer to flow structure.
582 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
584 struct mlx5_flow *dev_flow;
586 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
587 flow_drv_rxq_flags_set(dev, dev_flow);
591 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
592 * device flow if no other flow uses it with the same kind of request.
595 * Pointer to Ethernet device.
596 * @param[in] dev_flow
597 * Pointer to the device flow.
600 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
602 struct mlx5_priv *priv = dev->data->dev_private;
603 struct rte_flow *flow = dev_flow->flow;
604 const int mark = !!(flow->actions &
605 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
606 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
609 assert(dev->data->dev_started);
610 for (i = 0; i != flow->rss.queue_num; ++i) {
611 int idx = (*flow->queue)[i];
612 struct mlx5_rxq_ctrl *rxq_ctrl =
613 container_of((*priv->rxqs)[idx],
614 struct mlx5_rxq_ctrl, rxq);
617 rxq_ctrl->flow_mark_n--;
618 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
623 /* Decrease the counter matching the flow. */
624 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
625 if ((tunnels_info[j].tunnel &
627 tunnels_info[j].tunnel) {
628 rxq_ctrl->flow_tunnels_n[j]--;
632 flow_rxq_tunnel_ptype_update(rxq_ctrl);
638 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
639 * @p flow if no other flow uses it with the same kind of request.
642 * Pointer to Ethernet device.
644 * Pointer to the flow.
647 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
649 struct mlx5_flow *dev_flow;
651 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
652 flow_drv_rxq_flags_trim(dev, dev_flow);
656 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
659 * Pointer to Ethernet device.
662 flow_rxq_flags_clear(struct rte_eth_dev *dev)
664 struct mlx5_priv *priv = dev->data->dev_private;
667 for (i = 0; i != priv->rxqs_n; ++i) {
668 struct mlx5_rxq_ctrl *rxq_ctrl;
671 if (!(*priv->rxqs)[i])
673 rxq_ctrl = container_of((*priv->rxqs)[i],
674 struct mlx5_rxq_ctrl, rxq);
675 rxq_ctrl->flow_mark_n = 0;
676 rxq_ctrl->rxq.mark = 0;
677 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
678 rxq_ctrl->flow_tunnels_n[j] = 0;
679 rxq_ctrl->rxq.tunnel = 0;
684 * Validate the flag action.
686 * @param[in] action_flags
687 * Bit-fields that holds the actions detected until now.
689 * Attributes of flow that includes this action.
691 * Pointer to error structure.
694 * 0 on success, a negative errno value otherwise and rte_errno is set.
697 mlx5_flow_validate_action_flag(uint64_t action_flags,
698 const struct rte_flow_attr *attr,
699 struct rte_flow_error *error)
702 if (action_flags & MLX5_FLOW_ACTION_DROP)
703 return rte_flow_error_set(error, EINVAL,
704 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
705 "can't drop and flag in same flow");
706 if (action_flags & MLX5_FLOW_ACTION_MARK)
707 return rte_flow_error_set(error, EINVAL,
708 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
709 "can't mark and flag in same flow");
710 if (action_flags & MLX5_FLOW_ACTION_FLAG)
711 return rte_flow_error_set(error, EINVAL,
712 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
714 " actions in same flow");
716 return rte_flow_error_set(error, ENOTSUP,
717 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
718 "flag action not supported for "
724 * Validate the mark action.
727 * Pointer to the queue action.
728 * @param[in] action_flags
729 * Bit-fields that holds the actions detected until now.
731 * Attributes of flow that includes this action.
733 * Pointer to error structure.
736 * 0 on success, a negative errno value otherwise and rte_errno is set.
739 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
740 uint64_t action_flags,
741 const struct rte_flow_attr *attr,
742 struct rte_flow_error *error)
744 const struct rte_flow_action_mark *mark = action->conf;
747 return rte_flow_error_set(error, EINVAL,
748 RTE_FLOW_ERROR_TYPE_ACTION,
750 "configuration cannot be null");
751 if (mark->id >= MLX5_FLOW_MARK_MAX)
752 return rte_flow_error_set(error, EINVAL,
753 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
755 "mark id must in 0 <= id < "
756 RTE_STR(MLX5_FLOW_MARK_MAX));
757 if (action_flags & MLX5_FLOW_ACTION_DROP)
758 return rte_flow_error_set(error, EINVAL,
759 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
760 "can't drop and mark in same flow");
761 if (action_flags & MLX5_FLOW_ACTION_FLAG)
762 return rte_flow_error_set(error, EINVAL,
763 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
764 "can't flag and mark in same flow");
765 if (action_flags & MLX5_FLOW_ACTION_MARK)
766 return rte_flow_error_set(error, EINVAL,
767 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
768 "can't have 2 mark actions in same"
771 return rte_flow_error_set(error, ENOTSUP,
772 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
773 "mark action not supported for "
779 * Validate the drop action.
781 * @param[in] action_flags
782 * Bit-fields that holds the actions detected until now.
784 * Attributes of flow that includes this action.
786 * Pointer to error structure.
789 * 0 on success, a negative errno value otherwise and rte_errno is set.
792 mlx5_flow_validate_action_drop(uint64_t action_flags,
793 const struct rte_flow_attr *attr,
794 struct rte_flow_error *error)
796 if (action_flags & MLX5_FLOW_ACTION_FLAG)
797 return rte_flow_error_set(error, EINVAL,
798 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
799 "can't drop and flag in same flow");
800 if (action_flags & MLX5_FLOW_ACTION_MARK)
801 return rte_flow_error_set(error, EINVAL,
802 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
803 "can't drop and mark in same flow");
804 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
805 return rte_flow_error_set(error, EINVAL,
806 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
807 "can't have 2 fate actions in"
810 return rte_flow_error_set(error, ENOTSUP,
811 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
812 "drop action not supported for "
818 * Validate the queue action.
821 * Pointer to the queue action.
822 * @param[in] action_flags
823 * Bit-fields that holds the actions detected until now.
825 * Pointer to the Ethernet device structure.
827 * Attributes of flow that includes this action.
829 * Pointer to error structure.
832 * 0 on success, a negative errno value otherwise and rte_errno is set.
835 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
836 uint64_t action_flags,
837 struct rte_eth_dev *dev,
838 const struct rte_flow_attr *attr,
839 struct rte_flow_error *error)
841 struct mlx5_priv *priv = dev->data->dev_private;
842 const struct rte_flow_action_queue *queue = action->conf;
844 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
845 return rte_flow_error_set(error, EINVAL,
846 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
847 "can't have 2 fate actions in"
850 return rte_flow_error_set(error, EINVAL,
851 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
852 NULL, "No Rx queues configured");
853 if (queue->index >= priv->rxqs_n)
854 return rte_flow_error_set(error, EINVAL,
855 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
857 "queue index out of range");
858 if (!(*priv->rxqs)[queue->index])
859 return rte_flow_error_set(error, EINVAL,
860 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
862 "queue is not configured");
864 return rte_flow_error_set(error, ENOTSUP,
865 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
866 "queue action not supported for "
872 * Validate the rss action.
875 * Pointer to the queue action.
876 * @param[in] action_flags
877 * Bit-fields that holds the actions detected until now.
879 * Pointer to the Ethernet device structure.
881 * Attributes of flow that includes this action.
882 * @param[in] item_flags
883 * Items that were detected.
885 * Pointer to error structure.
888 * 0 on success, a negative errno value otherwise and rte_errno is set.
891 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
892 uint64_t action_flags,
893 struct rte_eth_dev *dev,
894 const struct rte_flow_attr *attr,
896 struct rte_flow_error *error)
898 struct mlx5_priv *priv = dev->data->dev_private;
899 const struct rte_flow_action_rss *rss = action->conf;
900 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
903 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
904 return rte_flow_error_set(error, EINVAL,
905 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
906 "can't have 2 fate actions"
908 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
909 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
910 return rte_flow_error_set(error, ENOTSUP,
911 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
913 "RSS hash function not supported");
914 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
919 return rte_flow_error_set(error, ENOTSUP,
920 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
922 "tunnel RSS is not supported");
923 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
924 if (rss->key_len == 0 && rss->key != NULL)
925 return rte_flow_error_set(error, ENOTSUP,
926 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
928 "RSS hash key length 0");
929 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
930 return rte_flow_error_set(error, ENOTSUP,
931 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
933 "RSS hash key too small");
934 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
935 return rte_flow_error_set(error, ENOTSUP,
936 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
938 "RSS hash key too large");
939 if (rss->queue_num > priv->config.ind_table_max_size)
940 return rte_flow_error_set(error, ENOTSUP,
941 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
943 "number of queues too large");
944 if (rss->types & MLX5_RSS_HF_MASK)
945 return rte_flow_error_set(error, ENOTSUP,
946 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
948 "some RSS protocols are not"
951 return rte_flow_error_set(error, EINVAL,
952 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
953 NULL, "No Rx queues configured");
955 return rte_flow_error_set(error, EINVAL,
956 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
957 NULL, "No queues configured");
958 for (i = 0; i != rss->queue_num; ++i) {
959 if (!(*priv->rxqs)[rss->queue[i]])
960 return rte_flow_error_set
961 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
962 &rss->queue[i], "queue is not configured");
965 return rte_flow_error_set(error, ENOTSUP,
966 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
967 "rss action not supported for "
969 if (rss->level > 1 && !tunnel)
970 return rte_flow_error_set(error, EINVAL,
971 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
972 "inner RSS is not supported for "
978 * Validate the count action.
981 * Pointer to the Ethernet device structure.
983 * Attributes of flow that includes this action.
985 * Pointer to error structure.
988 * 0 on success, a negative errno value otherwise and rte_errno is set.
991 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
992 const struct rte_flow_attr *attr,
993 struct rte_flow_error *error)
996 return rte_flow_error_set(error, ENOTSUP,
997 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
998 "count action not supported for "
1004 * Verify the @p attributes will be correctly understood by the NIC and store
1005 * them in the @p flow if everything is correct.
1008 * Pointer to the Ethernet device structure.
1009 * @param[in] attributes
1010 * Pointer to flow attributes
1012 * Pointer to error structure.
1015 * 0 on success, a negative errno value otherwise and rte_errno is set.
1018 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1019 const struct rte_flow_attr *attributes,
1020 struct rte_flow_error *error)
1022 struct mlx5_priv *priv = dev->data->dev_private;
1023 uint32_t priority_max = priv->config.flow_prio - 1;
1025 if (attributes->group)
1026 return rte_flow_error_set(error, ENOTSUP,
1027 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1028 NULL, "groups is not supported");
1029 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1030 attributes->priority >= priority_max)
1031 return rte_flow_error_set(error, ENOTSUP,
1032 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1033 NULL, "priority out of range");
1034 if (attributes->egress)
1035 return rte_flow_error_set(error, ENOTSUP,
1036 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1037 "egress is not supported");
1038 if (attributes->transfer && !priv->config.dv_esw_en)
1039 return rte_flow_error_set(error, ENOTSUP,
1040 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1041 NULL, "transfer is not supported");
1042 if (!attributes->ingress)
1043 return rte_flow_error_set(error, EINVAL,
1044 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1046 "ingress attribute is mandatory");
1051 * Validate Ethernet item.
1054 * Item specification.
1055 * @param[in] item_flags
1056 * Bit-fields that holds the items detected until now.
1058 * Pointer to error structure.
1061 * 0 on success, a negative errno value otherwise and rte_errno is set.
1064 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1065 uint64_t item_flags,
1066 struct rte_flow_error *error)
1068 const struct rte_flow_item_eth *mask = item->mask;
1069 const struct rte_flow_item_eth nic_mask = {
1070 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1071 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1072 .type = RTE_BE16(0xffff),
1075 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1076 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1077 MLX5_FLOW_LAYER_OUTER_L2;
1079 if (item_flags & ethm)
1080 return rte_flow_error_set(error, ENOTSUP,
1081 RTE_FLOW_ERROR_TYPE_ITEM, item,
1082 "multiple L2 layers not supported");
1084 mask = &rte_flow_item_eth_mask;
1085 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1086 (const uint8_t *)&nic_mask,
1087 sizeof(struct rte_flow_item_eth),
1093 * Validate VLAN item.
1096 * Item specification.
1097 * @param[in] item_flags
1098 * Bit-fields that holds the items detected until now.
1100 * Pointer to error structure.
1103 * 0 on success, a negative errno value otherwise and rte_errno is set.
1106 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1107 uint64_t item_flags,
1108 struct rte_flow_error *error)
1110 const struct rte_flow_item_vlan *spec = item->spec;
1111 const struct rte_flow_item_vlan *mask = item->mask;
1112 const struct rte_flow_item_vlan nic_mask = {
1113 .tci = RTE_BE16(0x0fff),
1114 .inner_type = RTE_BE16(0xffff),
1116 uint16_t vlan_tag = 0;
1117 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1119 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1120 MLX5_FLOW_LAYER_INNER_L4) :
1121 (MLX5_FLOW_LAYER_OUTER_L3 |
1122 MLX5_FLOW_LAYER_OUTER_L4);
1123 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1124 MLX5_FLOW_LAYER_OUTER_VLAN;
1126 if (item_flags & vlanm)
1127 return rte_flow_error_set(error, EINVAL,
1128 RTE_FLOW_ERROR_TYPE_ITEM, item,
1129 "multiple VLAN layers not supported");
1130 else if ((item_flags & l34m) != 0)
1131 return rte_flow_error_set(error, EINVAL,
1132 RTE_FLOW_ERROR_TYPE_ITEM, item,
1133 "L2 layer cannot follow L3/L4 layer");
1135 mask = &rte_flow_item_vlan_mask;
1136 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1137 (const uint8_t *)&nic_mask,
1138 sizeof(struct rte_flow_item_vlan),
1143 vlan_tag = spec->tci;
1144 vlan_tag &= mask->tci;
1147 * From verbs perspective an empty VLAN is equivalent
1148 * to a packet without VLAN layer.
1151 return rte_flow_error_set(error, EINVAL,
1152 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1154 "VLAN cannot be empty");
1159 * Validate IPV4 item.
1162 * Item specification.
1163 * @param[in] item_flags
1164 * Bit-fields that holds the items detected until now.
1165 * @param[in] acc_mask
1166 * Acceptable mask, if NULL default internal default mask
1167 * will be used to check whether item fields are supported.
1169 * Pointer to error structure.
1172 * 0 on success, a negative errno value otherwise and rte_errno is set.
1175 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1176 uint64_t item_flags,
1177 const struct rte_flow_item_ipv4 *acc_mask,
1178 struct rte_flow_error *error)
1180 const struct rte_flow_item_ipv4 *mask = item->mask;
1181 const struct rte_flow_item_ipv4 nic_mask = {
1183 .src_addr = RTE_BE32(0xffffffff),
1184 .dst_addr = RTE_BE32(0xffffffff),
1185 .type_of_service = 0xff,
1186 .next_proto_id = 0xff,
1189 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1190 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1191 MLX5_FLOW_LAYER_OUTER_L3;
1192 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1193 MLX5_FLOW_LAYER_OUTER_L4;
1196 if (item_flags & l3m)
1197 return rte_flow_error_set(error, ENOTSUP,
1198 RTE_FLOW_ERROR_TYPE_ITEM, item,
1199 "multiple L3 layers not supported");
1200 else if (item_flags & l4m)
1201 return rte_flow_error_set(error, EINVAL,
1202 RTE_FLOW_ERROR_TYPE_ITEM, item,
1203 "L3 cannot follow an L4 layer.");
1205 mask = &rte_flow_item_ipv4_mask;
1206 else if (mask->hdr.next_proto_id != 0 &&
1207 mask->hdr.next_proto_id != 0xff)
1208 return rte_flow_error_set(error, EINVAL,
1209 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1210 "partial mask is not supported"
1212 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1213 acc_mask ? (const uint8_t *)acc_mask
1214 : (const uint8_t *)&nic_mask,
1215 sizeof(struct rte_flow_item_ipv4),
1223 * Validate IPV6 item.
1226 * Item specification.
1227 * @param[in] item_flags
1228 * Bit-fields that holds the items detected until now.
1229 * @param[in] acc_mask
1230 * Acceptable mask, if NULL default internal default mask
1231 * will be used to check whether item fields are supported.
1233 * Pointer to error structure.
1236 * 0 on success, a negative errno value otherwise and rte_errno is set.
1239 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1240 uint64_t item_flags,
1241 const struct rte_flow_item_ipv6 *acc_mask,
1242 struct rte_flow_error *error)
1244 const struct rte_flow_item_ipv6 *mask = item->mask;
1245 const struct rte_flow_item_ipv6 nic_mask = {
1248 "\xff\xff\xff\xff\xff\xff\xff\xff"
1249 "\xff\xff\xff\xff\xff\xff\xff\xff",
1251 "\xff\xff\xff\xff\xff\xff\xff\xff"
1252 "\xff\xff\xff\xff\xff\xff\xff\xff",
1253 .vtc_flow = RTE_BE32(0xffffffff),
1258 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1259 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1260 MLX5_FLOW_LAYER_OUTER_L3;
1261 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1262 MLX5_FLOW_LAYER_OUTER_L4;
1265 if (item_flags & l3m)
1266 return rte_flow_error_set(error, ENOTSUP,
1267 RTE_FLOW_ERROR_TYPE_ITEM, item,
1268 "multiple L3 layers not supported");
1269 else if (item_flags & l4m)
1270 return rte_flow_error_set(error, EINVAL,
1271 RTE_FLOW_ERROR_TYPE_ITEM, item,
1272 "L3 cannot follow an L4 layer.");
1274 mask = &rte_flow_item_ipv6_mask;
1275 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1276 acc_mask ? (const uint8_t *)acc_mask
1277 : (const uint8_t *)&nic_mask,
1278 sizeof(struct rte_flow_item_ipv6),
1286 * Validate UDP item.
1289 * Item specification.
1290 * @param[in] item_flags
1291 * Bit-fields that holds the items detected until now.
1292 * @param[in] target_protocol
1293 * The next protocol in the previous item.
1294 * @param[in] flow_mask
1295 * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
1297 * Pointer to error structure.
1300 * 0 on success, a negative errno value otherwise and rte_errno is set.
1303 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1304 uint64_t item_flags,
1305 uint8_t target_protocol,
1306 struct rte_flow_error *error)
1308 const struct rte_flow_item_udp *mask = item->mask;
1309 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1310 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1311 MLX5_FLOW_LAYER_OUTER_L3;
1312 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1313 MLX5_FLOW_LAYER_OUTER_L4;
1316 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1317 return rte_flow_error_set(error, EINVAL,
1318 RTE_FLOW_ERROR_TYPE_ITEM, item,
1319 "protocol filtering not compatible"
1321 if (!(item_flags & l3m))
1322 return rte_flow_error_set(error, EINVAL,
1323 RTE_FLOW_ERROR_TYPE_ITEM, item,
1324 "L3 is mandatory to filter on L4");
1325 if (item_flags & l4m)
1326 return rte_flow_error_set(error, EINVAL,
1327 RTE_FLOW_ERROR_TYPE_ITEM, item,
1328 "multiple L4 layers not supported");
1330 mask = &rte_flow_item_udp_mask;
1331 ret = mlx5_flow_item_acceptable
1332 (item, (const uint8_t *)mask,
1333 (const uint8_t *)&rte_flow_item_udp_mask,
1334 sizeof(struct rte_flow_item_udp), error);
1341 * Validate TCP item.
1344 * Item specification.
1345 * @param[in] item_flags
1346 * Bit-fields that holds the items detected until now.
1347 * @param[in] target_protocol
1348 * The next protocol in the previous item.
1350 * Pointer to error structure.
1353 * 0 on success, a negative errno value otherwise and rte_errno is set.
1356 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1357 uint64_t item_flags,
1358 uint8_t target_protocol,
1359 const struct rte_flow_item_tcp *flow_mask,
1360 struct rte_flow_error *error)
1362 const struct rte_flow_item_tcp *mask = item->mask;
1363 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1364 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1365 MLX5_FLOW_LAYER_OUTER_L3;
1366 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1367 MLX5_FLOW_LAYER_OUTER_L4;
1371 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1372 return rte_flow_error_set(error, EINVAL,
1373 RTE_FLOW_ERROR_TYPE_ITEM, item,
1374 "protocol filtering not compatible"
1376 if (!(item_flags & l3m))
1377 return rte_flow_error_set(error, EINVAL,
1378 RTE_FLOW_ERROR_TYPE_ITEM, item,
1379 "L3 is mandatory to filter on L4");
1380 if (item_flags & l4m)
1381 return rte_flow_error_set(error, EINVAL,
1382 RTE_FLOW_ERROR_TYPE_ITEM, item,
1383 "multiple L4 layers not supported");
1385 mask = &rte_flow_item_tcp_mask;
1386 ret = mlx5_flow_item_acceptable
1387 (item, (const uint8_t *)mask,
1388 (const uint8_t *)flow_mask,
1389 sizeof(struct rte_flow_item_tcp), error);
1396 * Validate VXLAN item.
1399 * Item specification.
1400 * @param[in] item_flags
1401 * Bit-fields that holds the items detected until now.
1402 * @param[in] target_protocol
1403 * The next protocol in the previous item.
1405 * Pointer to error structure.
1408 * 0 on success, a negative errno value otherwise and rte_errno is set.
1411 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1412 uint64_t item_flags,
1413 struct rte_flow_error *error)
1415 const struct rte_flow_item_vxlan *spec = item->spec;
1416 const struct rte_flow_item_vxlan *mask = item->mask;
1421 } id = { .vlan_id = 0, };
1422 uint32_t vlan_id = 0;
1425 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1426 return rte_flow_error_set(error, ENOTSUP,
1427 RTE_FLOW_ERROR_TYPE_ITEM, item,
1428 "multiple tunnel layers not"
1431 * Verify only UDPv4 is present as defined in
1432 * https://tools.ietf.org/html/rfc7348
1434 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1435 return rte_flow_error_set(error, EINVAL,
1436 RTE_FLOW_ERROR_TYPE_ITEM, item,
1437 "no outer UDP layer found");
1439 mask = &rte_flow_item_vxlan_mask;
1440 ret = mlx5_flow_item_acceptable
1441 (item, (const uint8_t *)mask,
1442 (const uint8_t *)&rte_flow_item_vxlan_mask,
1443 sizeof(struct rte_flow_item_vxlan),
1448 memcpy(&id.vni[1], spec->vni, 3);
1449 vlan_id = id.vlan_id;
1450 memcpy(&id.vni[1], mask->vni, 3);
1451 vlan_id &= id.vlan_id;
1454 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1455 * only this layer is defined in the Verbs specification it is
1456 * interpreted as wildcard and all packets will match this
1457 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1458 * udp), all packets matching the layers before will also
1459 * match this rule. To avoid such situation, VNI 0 is
1460 * currently refused.
1463 return rte_flow_error_set(error, ENOTSUP,
1464 RTE_FLOW_ERROR_TYPE_ITEM, item,
1465 "VXLAN vni cannot be 0");
1466 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1467 return rte_flow_error_set(error, ENOTSUP,
1468 RTE_FLOW_ERROR_TYPE_ITEM, item,
1469 "VXLAN tunnel must be fully defined");
1474 * Validate VXLAN_GPE item.
1477 * Item specification.
1478 * @param[in] item_flags
1479 * Bit-fields that holds the items detected until now.
1481 * Pointer to the private data structure.
1482 * @param[in] target_protocol
1483 * The next protocol in the previous item.
1485 * Pointer to error structure.
1488 * 0 on success, a negative errno value otherwise and rte_errno is set.
1491 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1492 uint64_t item_flags,
1493 struct rte_eth_dev *dev,
1494 struct rte_flow_error *error)
1496 struct mlx5_priv *priv = dev->data->dev_private;
1497 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1498 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1503 } id = { .vlan_id = 0, };
1504 uint32_t vlan_id = 0;
1506 if (!priv->config.l3_vxlan_en)
1507 return rte_flow_error_set(error, ENOTSUP,
1508 RTE_FLOW_ERROR_TYPE_ITEM, item,
1509 "L3 VXLAN is not enabled by device"
1510 " parameter and/or not configured in"
1512 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1513 return rte_flow_error_set(error, ENOTSUP,
1514 RTE_FLOW_ERROR_TYPE_ITEM, item,
1515 "multiple tunnel layers not"
1518 * Verify only UDPv4 is present as defined in
1519 * https://tools.ietf.org/html/rfc7348
1521 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1522 return rte_flow_error_set(error, EINVAL,
1523 RTE_FLOW_ERROR_TYPE_ITEM, item,
1524 "no outer UDP layer found");
1526 mask = &rte_flow_item_vxlan_gpe_mask;
1527 ret = mlx5_flow_item_acceptable
1528 (item, (const uint8_t *)mask,
1529 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1530 sizeof(struct rte_flow_item_vxlan_gpe),
1536 return rte_flow_error_set(error, ENOTSUP,
1537 RTE_FLOW_ERROR_TYPE_ITEM,
1539 "VxLAN-GPE protocol"
1541 memcpy(&id.vni[1], spec->vni, 3);
1542 vlan_id = id.vlan_id;
1543 memcpy(&id.vni[1], mask->vni, 3);
1544 vlan_id &= id.vlan_id;
1547 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1548 * layer is defined in the Verbs specification it is interpreted as
1549 * wildcard and all packets will match this rule, if it follows a full
1550 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1551 * before will also match this rule. To avoid such situation, VNI 0
1552 * is currently refused.
1555 return rte_flow_error_set(error, ENOTSUP,
1556 RTE_FLOW_ERROR_TYPE_ITEM, item,
1557 "VXLAN-GPE vni cannot be 0");
1558 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1559 return rte_flow_error_set(error, ENOTSUP,
1560 RTE_FLOW_ERROR_TYPE_ITEM, item,
1561 "VXLAN-GPE tunnel must be fully"
1567 * Validate GRE item.
1570 * Item specification.
1571 * @param[in] item_flags
1572 * Bit flags to mark detected items.
1573 * @param[in] target_protocol
1574 * The next protocol in the previous item.
1576 * Pointer to error structure.
1579 * 0 on success, a negative errno value otherwise and rte_errno is set.
1582 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
1583 uint64_t item_flags,
1584 uint8_t target_protocol,
1585 struct rte_flow_error *error)
1587 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
1588 const struct rte_flow_item_gre *mask = item->mask;
1591 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
1592 return rte_flow_error_set(error, EINVAL,
1593 RTE_FLOW_ERROR_TYPE_ITEM, item,
1594 "protocol filtering not compatible"
1595 " with this GRE layer");
1596 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1597 return rte_flow_error_set(error, ENOTSUP,
1598 RTE_FLOW_ERROR_TYPE_ITEM, item,
1599 "multiple tunnel layers not"
1601 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
1602 return rte_flow_error_set(error, ENOTSUP,
1603 RTE_FLOW_ERROR_TYPE_ITEM, item,
1604 "L3 Layer is missing");
1606 mask = &rte_flow_item_gre_mask;
1607 ret = mlx5_flow_item_acceptable
1608 (item, (const uint8_t *)mask,
1609 (const uint8_t *)&rte_flow_item_gre_mask,
1610 sizeof(struct rte_flow_item_gre), error);
1613 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
1614 if (spec && (spec->protocol & mask->protocol))
1615 return rte_flow_error_set(error, ENOTSUP,
1616 RTE_FLOW_ERROR_TYPE_ITEM, item,
1617 "without MPLS support the"
1618 " specification cannot be used for"
1625 * Validate MPLS item.
1628 * Pointer to the rte_eth_dev structure.
1630 * Item specification.
1631 * @param[in] item_flags
1632 * Bit-fields that holds the items detected until now.
1633 * @param[in] prev_layer
1634 * The protocol layer indicated in previous item.
1636 * Pointer to error structure.
1639 * 0 on success, a negative errno value otherwise and rte_errno is set.
1642 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
1643 const struct rte_flow_item *item __rte_unused,
1644 uint64_t item_flags __rte_unused,
1645 uint64_t prev_layer __rte_unused,
1646 struct rte_flow_error *error)
1648 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
1649 const struct rte_flow_item_mpls *mask = item->mask;
1650 struct mlx5_priv *priv = dev->data->dev_private;
1653 if (!priv->config.mpls_en)
1654 return rte_flow_error_set(error, ENOTSUP,
1655 RTE_FLOW_ERROR_TYPE_ITEM, item,
1656 "MPLS not supported or"
1657 " disabled in firmware"
1659 /* MPLS over IP, UDP, GRE is allowed */
1660 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
1661 MLX5_FLOW_LAYER_OUTER_L4_UDP |
1662 MLX5_FLOW_LAYER_GRE)))
1663 return rte_flow_error_set(error, EINVAL,
1664 RTE_FLOW_ERROR_TYPE_ITEM, item,
1665 "protocol filtering not compatible"
1666 " with MPLS layer");
1667 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
1668 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
1669 !(item_flags & MLX5_FLOW_LAYER_GRE))
1670 return rte_flow_error_set(error, ENOTSUP,
1671 RTE_FLOW_ERROR_TYPE_ITEM, item,
1672 "multiple tunnel layers not"
1675 mask = &rte_flow_item_mpls_mask;
1676 ret = mlx5_flow_item_acceptable
1677 (item, (const uint8_t *)mask,
1678 (const uint8_t *)&rte_flow_item_mpls_mask,
1679 sizeof(struct rte_flow_item_mpls), error);
1684 return rte_flow_error_set(error, ENOTSUP,
1685 RTE_FLOW_ERROR_TYPE_ITEM, item,
1686 "MPLS is not supported by Verbs, please"
1691 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
1692 const struct rte_flow_attr *attr __rte_unused,
1693 const struct rte_flow_item items[] __rte_unused,
1694 const struct rte_flow_action actions[] __rte_unused,
1695 struct rte_flow_error *error)
1697 return rte_flow_error_set(error, ENOTSUP,
1698 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
1701 static struct mlx5_flow *
1702 flow_null_prepare(const struct rte_flow_attr *attr __rte_unused,
1703 const struct rte_flow_item items[] __rte_unused,
1704 const struct rte_flow_action actions[] __rte_unused,
1705 struct rte_flow_error *error)
1707 rte_flow_error_set(error, ENOTSUP,
1708 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
1713 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
1714 struct mlx5_flow *dev_flow __rte_unused,
1715 const struct rte_flow_attr *attr __rte_unused,
1716 const struct rte_flow_item items[] __rte_unused,
1717 const struct rte_flow_action actions[] __rte_unused,
1718 struct rte_flow_error *error)
1720 return rte_flow_error_set(error, ENOTSUP,
1721 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
1725 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
1726 struct rte_flow *flow __rte_unused,
1727 struct rte_flow_error *error)
1729 return rte_flow_error_set(error, ENOTSUP,
1730 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
1734 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
1735 struct rte_flow *flow __rte_unused)
1740 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
1741 struct rte_flow *flow __rte_unused)
1746 flow_null_query(struct rte_eth_dev *dev __rte_unused,
1747 struct rte_flow *flow __rte_unused,
1748 const struct rte_flow_action *actions __rte_unused,
1749 void *data __rte_unused,
1750 struct rte_flow_error *error)
1752 return rte_flow_error_set(error, ENOTSUP,
1753 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
1756 /* Void driver to protect from null pointer reference. */
1757 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
1758 .validate = flow_null_validate,
1759 .prepare = flow_null_prepare,
1760 .translate = flow_null_translate,
1761 .apply = flow_null_apply,
1762 .remove = flow_null_remove,
1763 .destroy = flow_null_destroy,
1764 .query = flow_null_query,
1768 * Select flow driver type according to flow attributes and device
1772 * Pointer to the dev structure.
1774 * Pointer to the flow attributes.
1777 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
1779 static enum mlx5_flow_drv_type
1780 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
1782 struct mlx5_priv *priv = dev->data->dev_private;
1783 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
1785 if (attr->transfer && priv->config.dv_esw_en)
1786 type = MLX5_FLOW_TYPE_DV;
1787 if (!attr->transfer)
1788 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
1789 MLX5_FLOW_TYPE_VERBS;
1793 #define flow_get_drv_ops(type) flow_drv_ops[type]
1796 * Flow driver validation API. This abstracts calling driver specific functions.
1797 * The type of flow driver is determined according to flow attributes.
1800 * Pointer to the dev structure.
1802 * Pointer to the flow attributes.
1804 * Pointer to the list of items.
1805 * @param[in] actions
1806 * Pointer to the list of actions.
1808 * Pointer to the error structure.
1811 * 0 on success, a negative errno value otherwise and rte_errno is set.
1814 flow_drv_validate(struct rte_eth_dev *dev,
1815 const struct rte_flow_attr *attr,
1816 const struct rte_flow_item items[],
1817 const struct rte_flow_action actions[],
1818 struct rte_flow_error *error)
1820 const struct mlx5_flow_driver_ops *fops;
1821 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
1823 fops = flow_get_drv_ops(type);
1824 return fops->validate(dev, attr, items, actions, error);
1828 * Flow driver preparation API. This abstracts calling driver specific
1829 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
1830 * calculates the size of memory required for device flow, allocates the memory,
1831 * initializes the device flow and returns the pointer.
1834 * This function initializes device flow structure such as dv or verbs in
1835 * struct mlx5_flow. However, it is caller's responsibility to initialize the
1836 * rest. For example, adding returning device flow to flow->dev_flow list and
1837 * setting backward reference to the flow should be done out of this function.
1838 * layers field is not filled either.
1841 * Pointer to the flow attributes.
1843 * Pointer to the list of items.
1844 * @param[in] actions
1845 * Pointer to the list of actions.
1847 * Pointer to the error structure.
1850 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
1852 static inline struct mlx5_flow *
1853 flow_drv_prepare(const struct rte_flow *flow,
1854 const struct rte_flow_attr *attr,
1855 const struct rte_flow_item items[],
1856 const struct rte_flow_action actions[],
1857 struct rte_flow_error *error)
1859 const struct mlx5_flow_driver_ops *fops;
1860 enum mlx5_flow_drv_type type = flow->drv_type;
1862 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1863 fops = flow_get_drv_ops(type);
1864 return fops->prepare(attr, items, actions, error);
1868 * Flow driver translation API. This abstracts calling driver specific
1869 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
1870 * translates a generic flow into a driver flow. flow_drv_prepare() must
1874 * dev_flow->layers could be filled as a result of parsing during translation
1875 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
1876 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
1877 * flow->actions could be overwritten even though all the expanded dev_flows
1878 * have the same actions.
1881 * Pointer to the rte dev structure.
1882 * @param[in, out] dev_flow
1883 * Pointer to the mlx5 flow.
1885 * Pointer to the flow attributes.
1887 * Pointer to the list of items.
1888 * @param[in] actions
1889 * Pointer to the list of actions.
1891 * Pointer to the error structure.
1894 * 0 on success, a negative errno value otherwise and rte_errno is set.
1897 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
1898 const struct rte_flow_attr *attr,
1899 const struct rte_flow_item items[],
1900 const struct rte_flow_action actions[],
1901 struct rte_flow_error *error)
1903 const struct mlx5_flow_driver_ops *fops;
1904 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
1906 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1907 fops = flow_get_drv_ops(type);
1908 return fops->translate(dev, dev_flow, attr, items, actions, error);
1912 * Flow driver apply API. This abstracts calling driver specific functions.
1913 * Parent flow (rte_flow) should have driver type (drv_type). It applies
1914 * translated driver flows on to device. flow_drv_translate() must precede.
1917 * Pointer to Ethernet device structure.
1918 * @param[in, out] flow
1919 * Pointer to flow structure.
1921 * Pointer to error structure.
1924 * 0 on success, a negative errno value otherwise and rte_errno is set.
1927 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
1928 struct rte_flow_error *error)
1930 const struct mlx5_flow_driver_ops *fops;
1931 enum mlx5_flow_drv_type type = flow->drv_type;
1933 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1934 fops = flow_get_drv_ops(type);
1935 return fops->apply(dev, flow, error);
1939 * Flow driver remove API. This abstracts calling driver specific functions.
1940 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
1941 * on device. All the resources of the flow should be freed by calling
1942 * flow_drv_destroy().
1945 * Pointer to Ethernet device.
1946 * @param[in, out] flow
1947 * Pointer to flow structure.
1950 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
1952 const struct mlx5_flow_driver_ops *fops;
1953 enum mlx5_flow_drv_type type = flow->drv_type;
1955 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1956 fops = flow_get_drv_ops(type);
1957 fops->remove(dev, flow);
1961 * Flow driver destroy API. This abstracts calling driver specific functions.
1962 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
1963 * on device and releases resources of the flow.
1966 * Pointer to Ethernet device.
1967 * @param[in, out] flow
1968 * Pointer to flow structure.
1971 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
1973 const struct mlx5_flow_driver_ops *fops;
1974 enum mlx5_flow_drv_type type = flow->drv_type;
1976 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1977 fops = flow_get_drv_ops(type);
1978 fops->destroy(dev, flow);
1982 * Validate a flow supported by the NIC.
1984 * @see rte_flow_validate()
1988 mlx5_flow_validate(struct rte_eth_dev *dev,
1989 const struct rte_flow_attr *attr,
1990 const struct rte_flow_item items[],
1991 const struct rte_flow_action actions[],
1992 struct rte_flow_error *error)
1996 ret = flow_drv_validate(dev, attr, items, actions, error);
2003 * Get RSS action from the action list.
2005 * @param[in] actions
2006 * Pointer to the list of actions.
2009 * Pointer to the RSS action if exist, else return NULL.
2011 static const struct rte_flow_action_rss*
2012 flow_get_rss_action(const struct rte_flow_action actions[])
2014 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2015 switch (actions->type) {
2016 case RTE_FLOW_ACTION_TYPE_RSS:
2017 return (const struct rte_flow_action_rss *)
2027 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
2029 const struct rte_flow_item *item;
2030 unsigned int has_vlan = 0;
2032 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2033 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2039 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
2040 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
2041 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
2042 MLX5_EXPANSION_ROOT_OUTER;
2046 * Create a flow and add it to @p list.
2049 * Pointer to Ethernet device.
2051 * Pointer to a TAILQ flow list.
2053 * Flow rule attributes.
2055 * Pattern specification (list terminated by the END pattern item).
2056 * @param[in] actions
2057 * Associated actions (list terminated by the END action).
2059 * Perform verbose error reporting if not NULL.
2062 * A flow on success, NULL otherwise and rte_errno is set.
2064 static struct rte_flow *
2065 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
2066 const struct rte_flow_attr *attr,
2067 const struct rte_flow_item items[],
2068 const struct rte_flow_action actions[],
2069 struct rte_flow_error *error)
2071 struct rte_flow *flow = NULL;
2072 struct mlx5_flow *dev_flow;
2073 const struct rte_flow_action_rss *rss;
2075 struct rte_flow_expand_rss buf;
2076 uint8_t buffer[2048];
2078 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
2083 ret = flow_drv_validate(dev, attr, items, actions, error);
2086 flow_size = sizeof(struct rte_flow);
2087 rss = flow_get_rss_action(actions);
2089 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
2092 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
2093 flow = rte_calloc(__func__, 1, flow_size, 0);
2094 flow->drv_type = flow_get_drv_type(dev, attr);
2095 flow->ingress = attr->ingress;
2096 flow->transfer = attr->transfer;
2097 assert(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
2098 flow->drv_type < MLX5_FLOW_TYPE_MAX);
2099 flow->queue = (void *)(flow + 1);
2100 LIST_INIT(&flow->dev_flows);
2101 if (rss && rss->types) {
2102 unsigned int graph_root;
2104 graph_root = find_graph_root(items, rss->level);
2105 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
2107 mlx5_support_expansion,
2110 (unsigned int)ret < sizeof(expand_buffer.buffer));
2113 buf->entry[0].pattern = (void *)(uintptr_t)items;
2115 for (i = 0; i < buf->entries; ++i) {
2116 dev_flow = flow_drv_prepare(flow, attr, buf->entry[i].pattern,
2120 dev_flow->flow = flow;
2121 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
2122 ret = flow_drv_translate(dev, dev_flow, attr,
2123 buf->entry[i].pattern,
2128 if (dev->data->dev_started) {
2129 ret = flow_drv_apply(dev, flow, error);
2133 TAILQ_INSERT_TAIL(list, flow, next);
2134 flow_rxq_flags_set(dev, flow);
2137 ret = rte_errno; /* Save rte_errno before cleanup. */
2139 flow_drv_destroy(dev, flow);
2141 rte_errno = ret; /* Restore rte_errno. */
2148 * @see rte_flow_create()
2152 mlx5_flow_create(struct rte_eth_dev *dev,
2153 const struct rte_flow_attr *attr,
2154 const struct rte_flow_item items[],
2155 const struct rte_flow_action actions[],
2156 struct rte_flow_error *error)
2158 struct mlx5_priv *priv = dev->data->dev_private;
2160 return flow_list_create(dev, &priv->flows,
2161 attr, items, actions, error);
2165 * Destroy a flow in a list.
2168 * Pointer to Ethernet device.
2170 * Pointer to a TAILQ flow list.
2175 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
2176 struct rte_flow *flow)
2179 * Update RX queue flags only if port is started, otherwise it is
2182 if (dev->data->dev_started)
2183 flow_rxq_flags_trim(dev, flow);
2184 flow_drv_destroy(dev, flow);
2185 TAILQ_REMOVE(list, flow, next);
2186 rte_free(flow->fdir);
2191 * Destroy all flows.
2194 * Pointer to Ethernet device.
2196 * Pointer to a TAILQ flow list.
2199 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
2201 while (!TAILQ_EMPTY(list)) {
2202 struct rte_flow *flow;
2204 flow = TAILQ_FIRST(list);
2205 flow_list_destroy(dev, list, flow);
2213 * Pointer to Ethernet device.
2215 * Pointer to a TAILQ flow list.
2218 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
2220 struct rte_flow *flow;
2222 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next)
2223 flow_drv_remove(dev, flow);
2224 flow_rxq_flags_clear(dev);
2231 * Pointer to Ethernet device.
2233 * Pointer to a TAILQ flow list.
2236 * 0 on success, a negative errno value otherwise and rte_errno is set.
2239 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
2241 struct rte_flow *flow;
2242 struct rte_flow_error error;
2245 TAILQ_FOREACH(flow, list, next) {
2246 ret = flow_drv_apply(dev, flow, &error);
2249 flow_rxq_flags_set(dev, flow);
2253 ret = rte_errno; /* Save rte_errno before cleanup. */
2254 mlx5_flow_stop(dev, list);
2255 rte_errno = ret; /* Restore rte_errno. */
2260 * Verify the flow list is empty
2263 * Pointer to Ethernet device.
2265 * @return the number of flows not released.
2268 mlx5_flow_verify(struct rte_eth_dev *dev)
2270 struct mlx5_priv *priv = dev->data->dev_private;
2271 struct rte_flow *flow;
2274 TAILQ_FOREACH(flow, &priv->flows, next) {
2275 DRV_LOG(DEBUG, "port %u flow %p still referenced",
2276 dev->data->port_id, (void *)flow);
2283 * Enable a control flow configured from the control plane.
2286 * Pointer to Ethernet device.
2288 * An Ethernet flow spec to apply.
2290 * An Ethernet flow mask to apply.
2292 * A VLAN flow spec to apply.
2294 * A VLAN flow mask to apply.
2297 * 0 on success, a negative errno value otherwise and rte_errno is set.
2300 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
2301 struct rte_flow_item_eth *eth_spec,
2302 struct rte_flow_item_eth *eth_mask,
2303 struct rte_flow_item_vlan *vlan_spec,
2304 struct rte_flow_item_vlan *vlan_mask)
2306 struct mlx5_priv *priv = dev->data->dev_private;
2307 const struct rte_flow_attr attr = {
2309 .priority = MLX5_FLOW_PRIO_RSVD,
2311 struct rte_flow_item items[] = {
2313 .type = RTE_FLOW_ITEM_TYPE_ETH,
2319 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
2320 RTE_FLOW_ITEM_TYPE_END,
2326 .type = RTE_FLOW_ITEM_TYPE_END,
2329 uint16_t queue[priv->reta_idx_n];
2330 struct rte_flow_action_rss action_rss = {
2331 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
2333 .types = priv->rss_conf.rss_hf,
2334 .key_len = priv->rss_conf.rss_key_len,
2335 .queue_num = priv->reta_idx_n,
2336 .key = priv->rss_conf.rss_key,
2339 struct rte_flow_action actions[] = {
2341 .type = RTE_FLOW_ACTION_TYPE_RSS,
2342 .conf = &action_rss,
2345 .type = RTE_FLOW_ACTION_TYPE_END,
2348 struct rte_flow *flow;
2349 struct rte_flow_error error;
2352 if (!priv->reta_idx_n || !priv->rxqs_n) {
2355 for (i = 0; i != priv->reta_idx_n; ++i)
2356 queue[i] = (*priv->reta_idx)[i];
2357 flow = flow_list_create(dev, &priv->ctrl_flows,
2358 &attr, items, actions, &error);
2365 * Enable a flow control configured from the control plane.
2368 * Pointer to Ethernet device.
2370 * An Ethernet flow spec to apply.
2372 * An Ethernet flow mask to apply.
2375 * 0 on success, a negative errno value otherwise and rte_errno is set.
2378 mlx5_ctrl_flow(struct rte_eth_dev *dev,
2379 struct rte_flow_item_eth *eth_spec,
2380 struct rte_flow_item_eth *eth_mask)
2382 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
2388 * @see rte_flow_destroy()
2392 mlx5_flow_destroy(struct rte_eth_dev *dev,
2393 struct rte_flow *flow,
2394 struct rte_flow_error *error __rte_unused)
2396 struct mlx5_priv *priv = dev->data->dev_private;
2398 flow_list_destroy(dev, &priv->flows, flow);
2403 * Destroy all flows.
2405 * @see rte_flow_flush()
2409 mlx5_flow_flush(struct rte_eth_dev *dev,
2410 struct rte_flow_error *error __rte_unused)
2412 struct mlx5_priv *priv = dev->data->dev_private;
2414 mlx5_flow_list_flush(dev, &priv->flows);
2421 * @see rte_flow_isolate()
2425 mlx5_flow_isolate(struct rte_eth_dev *dev,
2427 struct rte_flow_error *error)
2429 struct mlx5_priv *priv = dev->data->dev_private;
2431 if (dev->data->dev_started) {
2432 rte_flow_error_set(error, EBUSY,
2433 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2435 "port must be stopped first");
2438 priv->isolated = !!enable;
2440 dev->dev_ops = &mlx5_dev_ops_isolate;
2442 dev->dev_ops = &mlx5_dev_ops;
2449 * @see rte_flow_query()
2453 flow_drv_query(struct rte_eth_dev *dev,
2454 struct rte_flow *flow,
2455 const struct rte_flow_action *actions,
2457 struct rte_flow_error *error)
2459 const struct mlx5_flow_driver_ops *fops;
2460 enum mlx5_flow_drv_type ftype = flow->drv_type;
2462 assert(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
2463 fops = flow_get_drv_ops(ftype);
2465 return fops->query(dev, flow, actions, data, error);
2471 * @see rte_flow_query()
2475 mlx5_flow_query(struct rte_eth_dev *dev,
2476 struct rte_flow *flow,
2477 const struct rte_flow_action *actions,
2479 struct rte_flow_error *error)
2483 ret = flow_drv_query(dev, flow, actions, data, error);
2490 * Convert a flow director filter to a generic flow.
2493 * Pointer to Ethernet device.
2494 * @param fdir_filter
2495 * Flow director filter to add.
2497 * Generic flow parameters structure.
2500 * 0 on success, a negative errno value otherwise and rte_errno is set.
2503 flow_fdir_filter_convert(struct rte_eth_dev *dev,
2504 const struct rte_eth_fdir_filter *fdir_filter,
2505 struct mlx5_fdir *attributes)
2507 struct mlx5_priv *priv = dev->data->dev_private;
2508 const struct rte_eth_fdir_input *input = &fdir_filter->input;
2509 const struct rte_eth_fdir_masks *mask =
2510 &dev->data->dev_conf.fdir_conf.mask;
2512 /* Validate queue number. */
2513 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
2514 DRV_LOG(ERR, "port %u invalid queue number %d",
2515 dev->data->port_id, fdir_filter->action.rx_queue);
2519 attributes->attr.ingress = 1;
2520 attributes->items[0] = (struct rte_flow_item) {
2521 .type = RTE_FLOW_ITEM_TYPE_ETH,
2522 .spec = &attributes->l2,
2523 .mask = &attributes->l2_mask,
2525 switch (fdir_filter->action.behavior) {
2526 case RTE_ETH_FDIR_ACCEPT:
2527 attributes->actions[0] = (struct rte_flow_action){
2528 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
2529 .conf = &attributes->queue,
2532 case RTE_ETH_FDIR_REJECT:
2533 attributes->actions[0] = (struct rte_flow_action){
2534 .type = RTE_FLOW_ACTION_TYPE_DROP,
2538 DRV_LOG(ERR, "port %u invalid behavior %d",
2540 fdir_filter->action.behavior);
2541 rte_errno = ENOTSUP;
2544 attributes->queue.index = fdir_filter->action.rx_queue;
2546 switch (fdir_filter->input.flow_type) {
2547 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2548 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2549 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2550 attributes->l3.ipv4.hdr = (struct rte_ipv4_hdr){
2551 .src_addr = input->flow.ip4_flow.src_ip,
2552 .dst_addr = input->flow.ip4_flow.dst_ip,
2553 .time_to_live = input->flow.ip4_flow.ttl,
2554 .type_of_service = input->flow.ip4_flow.tos,
2556 attributes->l3_mask.ipv4.hdr = (struct rte_ipv4_hdr){
2557 .src_addr = mask->ipv4_mask.src_ip,
2558 .dst_addr = mask->ipv4_mask.dst_ip,
2559 .time_to_live = mask->ipv4_mask.ttl,
2560 .type_of_service = mask->ipv4_mask.tos,
2561 .next_proto_id = mask->ipv4_mask.proto,
2563 attributes->items[1] = (struct rte_flow_item){
2564 .type = RTE_FLOW_ITEM_TYPE_IPV4,
2565 .spec = &attributes->l3,
2566 .mask = &attributes->l3_mask,
2569 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2570 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2571 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2572 attributes->l3.ipv6.hdr = (struct rte_ipv6_hdr){
2573 .hop_limits = input->flow.ipv6_flow.hop_limits,
2574 .proto = input->flow.ipv6_flow.proto,
2577 memcpy(attributes->l3.ipv6.hdr.src_addr,
2578 input->flow.ipv6_flow.src_ip,
2579 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2580 memcpy(attributes->l3.ipv6.hdr.dst_addr,
2581 input->flow.ipv6_flow.dst_ip,
2582 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2583 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
2584 mask->ipv6_mask.src_ip,
2585 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2586 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
2587 mask->ipv6_mask.dst_ip,
2588 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2589 attributes->items[1] = (struct rte_flow_item){
2590 .type = RTE_FLOW_ITEM_TYPE_IPV6,
2591 .spec = &attributes->l3,
2592 .mask = &attributes->l3_mask,
2596 DRV_LOG(ERR, "port %u invalid flow type%d",
2597 dev->data->port_id, fdir_filter->input.flow_type);
2598 rte_errno = ENOTSUP;
2602 switch (fdir_filter->input.flow_type) {
2603 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2604 attributes->l4.udp.hdr = (struct rte_udp_hdr){
2605 .src_port = input->flow.udp4_flow.src_port,
2606 .dst_port = input->flow.udp4_flow.dst_port,
2608 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
2609 .src_port = mask->src_port_mask,
2610 .dst_port = mask->dst_port_mask,
2612 attributes->items[2] = (struct rte_flow_item){
2613 .type = RTE_FLOW_ITEM_TYPE_UDP,
2614 .spec = &attributes->l4,
2615 .mask = &attributes->l4_mask,
2618 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2619 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
2620 .src_port = input->flow.tcp4_flow.src_port,
2621 .dst_port = input->flow.tcp4_flow.dst_port,
2623 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
2624 .src_port = mask->src_port_mask,
2625 .dst_port = mask->dst_port_mask,
2627 attributes->items[2] = (struct rte_flow_item){
2628 .type = RTE_FLOW_ITEM_TYPE_TCP,
2629 .spec = &attributes->l4,
2630 .mask = &attributes->l4_mask,
2633 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2634 attributes->l4.udp.hdr = (struct rte_udp_hdr){
2635 .src_port = input->flow.udp6_flow.src_port,
2636 .dst_port = input->flow.udp6_flow.dst_port,
2638 attributes->l4_mask.udp.hdr = (struct rte_udp_hdr){
2639 .src_port = mask->src_port_mask,
2640 .dst_port = mask->dst_port_mask,
2642 attributes->items[2] = (struct rte_flow_item){
2643 .type = RTE_FLOW_ITEM_TYPE_UDP,
2644 .spec = &attributes->l4,
2645 .mask = &attributes->l4_mask,
2648 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2649 attributes->l4.tcp.hdr = (struct rte_tcp_hdr){
2650 .src_port = input->flow.tcp6_flow.src_port,
2651 .dst_port = input->flow.tcp6_flow.dst_port,
2653 attributes->l4_mask.tcp.hdr = (struct rte_tcp_hdr){
2654 .src_port = mask->src_port_mask,
2655 .dst_port = mask->dst_port_mask,
2657 attributes->items[2] = (struct rte_flow_item){
2658 .type = RTE_FLOW_ITEM_TYPE_TCP,
2659 .spec = &attributes->l4,
2660 .mask = &attributes->l4_mask,
2663 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2664 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2667 DRV_LOG(ERR, "port %u invalid flow type%d",
2668 dev->data->port_id, fdir_filter->input.flow_type);
2669 rte_errno = ENOTSUP;
2675 #define FLOW_FDIR_CMP(f1, f2, fld) \
2676 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
2679 * Compare two FDIR flows. If items and actions are identical, the two flows are
2683 * Pointer to Ethernet device.
2685 * FDIR flow to compare.
2687 * FDIR flow to compare.
2690 * Zero on match, 1 otherwise.
2693 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
2695 if (FLOW_FDIR_CMP(f1, f2, attr) ||
2696 FLOW_FDIR_CMP(f1, f2, l2) ||
2697 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
2698 FLOW_FDIR_CMP(f1, f2, l3) ||
2699 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
2700 FLOW_FDIR_CMP(f1, f2, l4) ||
2701 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
2702 FLOW_FDIR_CMP(f1, f2, actions[0].type))
2704 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
2705 FLOW_FDIR_CMP(f1, f2, queue))
2711 * Search device flow list to find out a matched FDIR flow.
2714 * Pointer to Ethernet device.
2716 * FDIR flow to lookup.
2719 * Pointer of flow if found, NULL otherwise.
2721 static struct rte_flow *
2722 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
2724 struct mlx5_priv *priv = dev->data->dev_private;
2725 struct rte_flow *flow = NULL;
2728 TAILQ_FOREACH(flow, &priv->flows, next) {
2729 if (flow->fdir && !flow_fdir_cmp(flow->fdir, fdir_flow)) {
2730 DRV_LOG(DEBUG, "port %u found FDIR flow %p",
2731 dev->data->port_id, (void *)flow);
2739 * Add new flow director filter and store it in list.
2742 * Pointer to Ethernet device.
2743 * @param fdir_filter
2744 * Flow director filter to add.
2747 * 0 on success, a negative errno value otherwise and rte_errno is set.
2750 flow_fdir_filter_add(struct rte_eth_dev *dev,
2751 const struct rte_eth_fdir_filter *fdir_filter)
2753 struct mlx5_priv *priv = dev->data->dev_private;
2754 struct mlx5_fdir *fdir_flow;
2755 struct rte_flow *flow;
2758 fdir_flow = rte_zmalloc(__func__, sizeof(*fdir_flow), 0);
2763 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
2766 flow = flow_fdir_filter_lookup(dev, fdir_flow);
2771 flow = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
2772 fdir_flow->items, fdir_flow->actions, NULL);
2775 assert(!flow->fdir);
2776 flow->fdir = fdir_flow;
2777 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
2778 dev->data->port_id, (void *)flow);
2781 rte_free(fdir_flow);
2786 * Delete specific filter.
2789 * Pointer to Ethernet device.
2790 * @param fdir_filter
2791 * Filter to be deleted.
2794 * 0 on success, a negative errno value otherwise and rte_errno is set.
2797 flow_fdir_filter_delete(struct rte_eth_dev *dev,
2798 const struct rte_eth_fdir_filter *fdir_filter)
2800 struct mlx5_priv *priv = dev->data->dev_private;
2801 struct rte_flow *flow;
2802 struct mlx5_fdir fdir_flow = {
2807 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
2810 flow = flow_fdir_filter_lookup(dev, &fdir_flow);
2815 flow_list_destroy(dev, &priv->flows, flow);
2816 DRV_LOG(DEBUG, "port %u deleted FDIR flow %p",
2817 dev->data->port_id, (void *)flow);
2822 * Update queue for specific filter.
2825 * Pointer to Ethernet device.
2826 * @param fdir_filter
2827 * Filter to be updated.
2830 * 0 on success, a negative errno value otherwise and rte_errno is set.
2833 flow_fdir_filter_update(struct rte_eth_dev *dev,
2834 const struct rte_eth_fdir_filter *fdir_filter)
2838 ret = flow_fdir_filter_delete(dev, fdir_filter);
2841 return flow_fdir_filter_add(dev, fdir_filter);
2845 * Flush all filters.
2848 * Pointer to Ethernet device.
2851 flow_fdir_filter_flush(struct rte_eth_dev *dev)
2853 struct mlx5_priv *priv = dev->data->dev_private;
2855 mlx5_flow_list_flush(dev, &priv->flows);
2859 * Get flow director information.
2862 * Pointer to Ethernet device.
2863 * @param[out] fdir_info
2864 * Resulting flow director information.
2867 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
2869 struct rte_eth_fdir_masks *mask =
2870 &dev->data->dev_conf.fdir_conf.mask;
2872 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
2873 fdir_info->guarant_spc = 0;
2874 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
2875 fdir_info->max_flexpayload = 0;
2876 fdir_info->flow_types_mask[0] = 0;
2877 fdir_info->flex_payload_unit = 0;
2878 fdir_info->max_flex_payload_segment_num = 0;
2879 fdir_info->flex_payload_limit = 0;
2880 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
2884 * Deal with flow director operations.
2887 * Pointer to Ethernet device.
2889 * Operation to perform.
2891 * Pointer to operation-specific structure.
2894 * 0 on success, a negative errno value otherwise and rte_errno is set.
2897 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
2900 enum rte_fdir_mode fdir_mode =
2901 dev->data->dev_conf.fdir_conf.mode;
2903 if (filter_op == RTE_ETH_FILTER_NOP)
2905 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
2906 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2907 DRV_LOG(ERR, "port %u flow director mode %d not supported",
2908 dev->data->port_id, fdir_mode);
2912 switch (filter_op) {
2913 case RTE_ETH_FILTER_ADD:
2914 return flow_fdir_filter_add(dev, arg);
2915 case RTE_ETH_FILTER_UPDATE:
2916 return flow_fdir_filter_update(dev, arg);
2917 case RTE_ETH_FILTER_DELETE:
2918 return flow_fdir_filter_delete(dev, arg);
2919 case RTE_ETH_FILTER_FLUSH:
2920 flow_fdir_filter_flush(dev);
2922 case RTE_ETH_FILTER_INFO:
2923 flow_fdir_info_get(dev, arg);
2926 DRV_LOG(DEBUG, "port %u unknown operation %u",
2927 dev->data->port_id, filter_op);
2935 * Manage filter operations.
2938 * Pointer to Ethernet device structure.
2939 * @param filter_type
2942 * Operation to perform.
2944 * Pointer to operation-specific structure.
2947 * 0 on success, a negative errno value otherwise and rte_errno is set.
2950 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
2951 enum rte_filter_type filter_type,
2952 enum rte_filter_op filter_op,
2955 switch (filter_type) {
2956 case RTE_ETH_FILTER_GENERIC:
2957 if (filter_op != RTE_ETH_FILTER_GET) {
2961 *(const void **)arg = &mlx5_flow_ops;
2963 case RTE_ETH_FILTER_FDIR:
2964 return flow_fdir_ctrl_func(dev, filter_op, arg);
2966 DRV_LOG(ERR, "port %u filter type (%d) not supported",
2967 dev->data->port_id, filter_type);
2968 rte_errno = ENOTSUP;