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_eth_ctrl.h>
25 #include <rte_ethdev_driver.h>
27 #include <rte_flow_driver.h>
28 #include <rte_malloc.h>
32 #include "mlx5_defs.h"
34 #include "mlx5_glue.h"
35 #include "mlx5_flow.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_tcf_drv_ops;
46 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
48 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
50 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
51 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
52 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
53 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
55 [MLX5_FLOW_TYPE_TCF] = &mlx5_flow_tcf_drv_ops,
56 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
57 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
62 MLX5_EXPANSION_ROOT_OUTER,
63 MLX5_EXPANSION_ROOT_ETH_VLAN,
64 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
65 MLX5_EXPANSION_OUTER_ETH,
66 MLX5_EXPANSION_OUTER_ETH_VLAN,
67 MLX5_EXPANSION_OUTER_VLAN,
68 MLX5_EXPANSION_OUTER_IPV4,
69 MLX5_EXPANSION_OUTER_IPV4_UDP,
70 MLX5_EXPANSION_OUTER_IPV4_TCP,
71 MLX5_EXPANSION_OUTER_IPV6,
72 MLX5_EXPANSION_OUTER_IPV6_UDP,
73 MLX5_EXPANSION_OUTER_IPV6_TCP,
75 MLX5_EXPANSION_VXLAN_GPE,
79 MLX5_EXPANSION_ETH_VLAN,
82 MLX5_EXPANSION_IPV4_UDP,
83 MLX5_EXPANSION_IPV4_TCP,
85 MLX5_EXPANSION_IPV6_UDP,
86 MLX5_EXPANSION_IPV6_TCP,
89 /** Supported expansion of items. */
90 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
91 [MLX5_EXPANSION_ROOT] = {
92 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
95 .type = RTE_FLOW_ITEM_TYPE_END,
97 [MLX5_EXPANSION_ROOT_OUTER] = {
98 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
99 MLX5_EXPANSION_OUTER_IPV4,
100 MLX5_EXPANSION_OUTER_IPV6),
101 .type = RTE_FLOW_ITEM_TYPE_END,
103 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
104 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
105 .type = RTE_FLOW_ITEM_TYPE_END,
107 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
108 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
109 .type = RTE_FLOW_ITEM_TYPE_END,
111 [MLX5_EXPANSION_OUTER_ETH] = {
112 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
113 MLX5_EXPANSION_OUTER_IPV6,
114 MLX5_EXPANSION_MPLS),
115 .type = RTE_FLOW_ITEM_TYPE_ETH,
118 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
119 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
120 .type = RTE_FLOW_ITEM_TYPE_ETH,
123 [MLX5_EXPANSION_OUTER_VLAN] = {
124 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
125 MLX5_EXPANSION_OUTER_IPV6),
126 .type = RTE_FLOW_ITEM_TYPE_VLAN,
128 [MLX5_EXPANSION_OUTER_IPV4] = {
129 .next = RTE_FLOW_EXPAND_RSS_NEXT
130 (MLX5_EXPANSION_OUTER_IPV4_UDP,
131 MLX5_EXPANSION_OUTER_IPV4_TCP,
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),
151 .type = RTE_FLOW_ITEM_TYPE_IPV6,
152 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
153 ETH_RSS_NONFRAG_IPV6_OTHER,
155 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
156 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
157 MLX5_EXPANSION_VXLAN_GPE),
158 .type = RTE_FLOW_ITEM_TYPE_UDP,
159 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
161 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
162 .type = RTE_FLOW_ITEM_TYPE_TCP,
163 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
165 [MLX5_EXPANSION_VXLAN] = {
166 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
167 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
169 [MLX5_EXPANSION_VXLAN_GPE] = {
170 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
172 MLX5_EXPANSION_IPV6),
173 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
175 [MLX5_EXPANSION_GRE] = {
176 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
177 .type = RTE_FLOW_ITEM_TYPE_GRE,
179 [MLX5_EXPANSION_MPLS] = {
180 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
181 MLX5_EXPANSION_IPV6),
182 .type = RTE_FLOW_ITEM_TYPE_MPLS,
184 [MLX5_EXPANSION_ETH] = {
185 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
186 MLX5_EXPANSION_IPV6),
187 .type = RTE_FLOW_ITEM_TYPE_ETH,
189 [MLX5_EXPANSION_ETH_VLAN] = {
190 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
191 .type = RTE_FLOW_ITEM_TYPE_ETH,
193 [MLX5_EXPANSION_VLAN] = {
194 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
195 MLX5_EXPANSION_IPV6),
196 .type = RTE_FLOW_ITEM_TYPE_VLAN,
198 [MLX5_EXPANSION_IPV4] = {
199 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
200 MLX5_EXPANSION_IPV4_TCP),
201 .type = RTE_FLOW_ITEM_TYPE_IPV4,
202 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
203 ETH_RSS_NONFRAG_IPV4_OTHER,
205 [MLX5_EXPANSION_IPV4_UDP] = {
206 .type = RTE_FLOW_ITEM_TYPE_UDP,
207 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
209 [MLX5_EXPANSION_IPV4_TCP] = {
210 .type = RTE_FLOW_ITEM_TYPE_TCP,
211 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
213 [MLX5_EXPANSION_IPV6] = {
214 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
215 MLX5_EXPANSION_IPV6_TCP),
216 .type = RTE_FLOW_ITEM_TYPE_IPV6,
217 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
218 ETH_RSS_NONFRAG_IPV6_OTHER,
220 [MLX5_EXPANSION_IPV6_UDP] = {
221 .type = RTE_FLOW_ITEM_TYPE_UDP,
222 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
224 [MLX5_EXPANSION_IPV6_TCP] = {
225 .type = RTE_FLOW_ITEM_TYPE_TCP,
226 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
230 static const struct rte_flow_ops mlx5_flow_ops = {
231 .validate = mlx5_flow_validate,
232 .create = mlx5_flow_create,
233 .destroy = mlx5_flow_destroy,
234 .flush = mlx5_flow_flush,
235 .isolate = mlx5_flow_isolate,
236 .query = mlx5_flow_query,
239 /* Convert FDIR request to Generic flow. */
241 struct rte_flow_attr attr;
242 struct rte_flow_item items[4];
243 struct rte_flow_item_eth l2;
244 struct rte_flow_item_eth l2_mask;
246 struct rte_flow_item_ipv4 ipv4;
247 struct rte_flow_item_ipv6 ipv6;
250 struct rte_flow_item_ipv4 ipv4;
251 struct rte_flow_item_ipv6 ipv6;
254 struct rte_flow_item_udp udp;
255 struct rte_flow_item_tcp tcp;
258 struct rte_flow_item_udp udp;
259 struct rte_flow_item_tcp tcp;
261 struct rte_flow_action actions[2];
262 struct rte_flow_action_queue queue;
265 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
266 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
267 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
270 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
271 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
272 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
273 { 9, 10, 11 }, { 12, 13, 14 },
276 /* Tunnel information. */
277 struct mlx5_flow_tunnel_info {
278 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
279 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
282 static struct mlx5_flow_tunnel_info tunnels_info[] = {
284 .tunnel = MLX5_FLOW_LAYER_VXLAN,
285 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
288 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
289 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
292 .tunnel = MLX5_FLOW_LAYER_GRE,
293 .ptype = RTE_PTYPE_TUNNEL_GRE,
296 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
297 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE | RTE_PTYPE_L4_UDP,
300 .tunnel = MLX5_FLOW_LAYER_MPLS,
301 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
306 * Discover the maximum number of priority available.
309 * Pointer to the Ethernet device structure.
312 * number of supported flow priority on success, a negative errno
313 * value otherwise and rte_errno is set.
316 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
319 struct ibv_flow_attr attr;
320 struct ibv_flow_spec_eth eth;
321 struct ibv_flow_spec_action_drop drop;
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));
355 priority = RTE_DIM(priority_map_3);
358 priority = RTE_DIM(priority_map_5);
363 "port %u verbs maximum priority: %d expected 8/16",
364 dev->data->port_id, vprio[i]);
367 mlx5_hrxq_drop_release(dev);
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 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 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 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 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_ernno 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_ernno 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 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"
849 if (queue->index >= priv->rxqs_n)
850 return rte_flow_error_set(error, EINVAL,
851 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
853 "queue index out of range");
854 if (!(*priv->rxqs)[queue->index])
855 return rte_flow_error_set(error, EINVAL,
856 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
858 "queue is not configured");
860 return rte_flow_error_set(error, ENOTSUP,
861 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
862 "queue action not supported for "
868 * Validate the rss action.
871 * Pointer to the queue action.
872 * @param[in] action_flags
873 * Bit-fields that holds the actions detected until now.
875 * Pointer to the Ethernet device structure.
877 * Attributes of flow that includes this action.
879 * Pointer to error structure.
882 * 0 on success, a negative errno value otherwise and rte_ernno is set.
885 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
886 uint64_t action_flags,
887 struct rte_eth_dev *dev,
888 const struct rte_flow_attr *attr,
889 struct rte_flow_error *error)
891 struct priv *priv = dev->data->dev_private;
892 const struct rte_flow_action_rss *rss = action->conf;
895 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
896 return rte_flow_error_set(error, EINVAL,
897 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
898 "can't have 2 fate actions"
900 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
901 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
902 return rte_flow_error_set(error, ENOTSUP,
903 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
905 "RSS hash function not supported");
906 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
911 return rte_flow_error_set(error, ENOTSUP,
912 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
914 "tunnel RSS is not supported");
915 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
916 if (rss->key_len == 0 && rss->key != NULL)
917 return rte_flow_error_set(error, ENOTSUP,
918 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
920 "RSS hash key length 0");
921 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
922 return rte_flow_error_set(error, ENOTSUP,
923 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
925 "RSS hash key too small");
926 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
927 return rte_flow_error_set(error, ENOTSUP,
928 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
930 "RSS hash key too large");
931 if (rss->queue_num > priv->config.ind_table_max_size)
932 return rte_flow_error_set(error, ENOTSUP,
933 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
935 "number of queues too large");
936 if (rss->types & MLX5_RSS_HF_MASK)
937 return rte_flow_error_set(error, ENOTSUP,
938 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
940 "some RSS protocols are not"
942 for (i = 0; i != rss->queue_num; ++i) {
943 if (!(*priv->rxqs)[rss->queue[i]])
944 return rte_flow_error_set
945 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
946 &rss->queue[i], "queue is not configured");
949 return rte_flow_error_set(error, ENOTSUP,
950 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
951 "rss action not supported for "
957 * Validate the count action.
960 * Pointer to the Ethernet device structure.
962 * Attributes of flow that includes this action.
964 * Pointer to error structure.
967 * 0 on success, a negative errno value otherwise and rte_ernno is set.
970 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
971 const struct rte_flow_attr *attr,
972 struct rte_flow_error *error)
975 return rte_flow_error_set(error, ENOTSUP,
976 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
977 "count action not supported for "
983 * Verify the @p attributes will be correctly understood by the NIC and store
984 * them in the @p flow if everything is correct.
987 * Pointer to the Ethernet device structure.
988 * @param[in] attributes
989 * Pointer to flow attributes
991 * Pointer to error structure.
994 * 0 on success, a negative errno value otherwise and rte_errno is set.
997 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
998 const struct rte_flow_attr *attributes,
999 struct rte_flow_error *error)
1001 struct priv *priv = dev->data->dev_private;
1002 uint32_t priority_max = priv->config.flow_prio - 1;
1004 if (attributes->group)
1005 return rte_flow_error_set(error, ENOTSUP,
1006 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1007 NULL, "groups is not supported");
1008 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1009 attributes->priority >= priority_max)
1010 return rte_flow_error_set(error, ENOTSUP,
1011 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1012 NULL, "priority out of range");
1013 if (attributes->egress)
1014 return rte_flow_error_set(error, ENOTSUP,
1015 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1016 "egress is not supported");
1017 if (attributes->transfer)
1018 return rte_flow_error_set(error, ENOTSUP,
1019 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1020 NULL, "transfer is not supported");
1021 if (!attributes->ingress)
1022 return rte_flow_error_set(error, EINVAL,
1023 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1025 "ingress attribute is mandatory");
1030 * Validate Ethernet item.
1033 * Item specification.
1034 * @param[in] item_flags
1035 * Bit-fields that holds the items detected until now.
1037 * Pointer to error structure.
1040 * 0 on success, a negative errno value otherwise and rte_errno is set.
1043 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1044 uint64_t item_flags,
1045 struct rte_flow_error *error)
1047 const struct rte_flow_item_eth *mask = item->mask;
1048 const struct rte_flow_item_eth nic_mask = {
1049 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1050 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1051 .type = RTE_BE16(0xffff),
1054 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1055 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1056 MLX5_FLOW_LAYER_OUTER_L2;
1058 if (item_flags & ethm)
1059 return rte_flow_error_set(error, ENOTSUP,
1060 RTE_FLOW_ERROR_TYPE_ITEM, item,
1061 "multiple L2 layers not supported");
1063 mask = &rte_flow_item_eth_mask;
1064 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1065 (const uint8_t *)&nic_mask,
1066 sizeof(struct rte_flow_item_eth),
1072 * Validate VLAN item.
1075 * Item specification.
1076 * @param[in] item_flags
1077 * Bit-fields that holds the items detected until now.
1079 * Pointer to error structure.
1082 * 0 on success, a negative errno value otherwise and rte_errno is set.
1085 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1086 uint64_t item_flags,
1087 struct rte_flow_error *error)
1089 const struct rte_flow_item_vlan *spec = item->spec;
1090 const struct rte_flow_item_vlan *mask = item->mask;
1091 const struct rte_flow_item_vlan nic_mask = {
1092 .tci = RTE_BE16(0x0fff),
1093 .inner_type = RTE_BE16(0xffff),
1095 uint16_t vlan_tag = 0;
1096 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1098 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1099 MLX5_FLOW_LAYER_INNER_L4) :
1100 (MLX5_FLOW_LAYER_OUTER_L3 |
1101 MLX5_FLOW_LAYER_OUTER_L4);
1102 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1103 MLX5_FLOW_LAYER_OUTER_VLAN;
1105 if (item_flags & vlanm)
1106 return rte_flow_error_set(error, EINVAL,
1107 RTE_FLOW_ERROR_TYPE_ITEM, item,
1108 "multiple VLAN layers not supported");
1109 else if ((item_flags & l34m) != 0)
1110 return rte_flow_error_set(error, EINVAL,
1111 RTE_FLOW_ERROR_TYPE_ITEM, item,
1112 "L2 layer cannot follow L3/L4 layer");
1114 mask = &rte_flow_item_vlan_mask;
1115 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1116 (const uint8_t *)&nic_mask,
1117 sizeof(struct rte_flow_item_vlan),
1122 vlan_tag = spec->tci;
1123 vlan_tag &= mask->tci;
1126 * From verbs perspective an empty VLAN is equivalent
1127 * to a packet without VLAN layer.
1130 return rte_flow_error_set(error, EINVAL,
1131 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1133 "VLAN cannot be empty");
1138 * Validate IPV4 item.
1141 * Item specification.
1142 * @param[in] item_flags
1143 * Bit-fields that holds the items detected until now.
1145 * Pointer to error structure.
1148 * 0 on success, a negative errno value otherwise and rte_errno is set.
1151 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1152 uint64_t item_flags,
1153 struct rte_flow_error *error)
1155 const struct rte_flow_item_ipv4 *mask = item->mask;
1156 const struct rte_flow_item_ipv4 nic_mask = {
1158 .src_addr = RTE_BE32(0xffffffff),
1159 .dst_addr = RTE_BE32(0xffffffff),
1160 .type_of_service = 0xff,
1161 .next_proto_id = 0xff,
1164 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1165 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1166 MLX5_FLOW_LAYER_OUTER_L3;
1167 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1168 MLX5_FLOW_LAYER_OUTER_L4;
1171 if (item_flags & l3m)
1172 return rte_flow_error_set(error, ENOTSUP,
1173 RTE_FLOW_ERROR_TYPE_ITEM, item,
1174 "multiple L3 layers not supported");
1175 else if (item_flags & l4m)
1176 return rte_flow_error_set(error, EINVAL,
1177 RTE_FLOW_ERROR_TYPE_ITEM, item,
1178 "L3 cannot follow an L4 layer.");
1180 mask = &rte_flow_item_ipv4_mask;
1181 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1182 (const uint8_t *)&nic_mask,
1183 sizeof(struct rte_flow_item_ipv4),
1191 * Validate IPV6 item.
1194 * Item specification.
1195 * @param[in] item_flags
1196 * Bit-fields that holds the items detected until now.
1198 * Pointer to error structure.
1201 * 0 on success, a negative errno value otherwise and rte_errno is set.
1204 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1205 uint64_t item_flags,
1206 struct rte_flow_error *error)
1208 const struct rte_flow_item_ipv6 *mask = item->mask;
1209 const struct rte_flow_item_ipv6 nic_mask = {
1212 "\xff\xff\xff\xff\xff\xff\xff\xff"
1213 "\xff\xff\xff\xff\xff\xff\xff\xff",
1215 "\xff\xff\xff\xff\xff\xff\xff\xff"
1216 "\xff\xff\xff\xff\xff\xff\xff\xff",
1217 .vtc_flow = RTE_BE32(0xffffffff),
1222 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1223 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1224 MLX5_FLOW_LAYER_OUTER_L3;
1225 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1226 MLX5_FLOW_LAYER_OUTER_L4;
1229 if (item_flags & l3m)
1230 return rte_flow_error_set(error, ENOTSUP,
1231 RTE_FLOW_ERROR_TYPE_ITEM, item,
1232 "multiple L3 layers not supported");
1233 else if (item_flags & l4m)
1234 return rte_flow_error_set(error, EINVAL,
1235 RTE_FLOW_ERROR_TYPE_ITEM, item,
1236 "L3 cannot follow an L4 layer.");
1238 * IPv6 is not recognised by the NIC inside a GRE tunnel.
1239 * Such support has to be disabled as the rule will be
1240 * accepted. Issue reproduced with Mellanox OFED 4.3-3.0.2.1 and
1241 * Mellanox OFED 4.4-1.0.0.0.
1243 if (tunnel && item_flags & MLX5_FLOW_LAYER_GRE)
1244 return rte_flow_error_set(error, ENOTSUP,
1245 RTE_FLOW_ERROR_TYPE_ITEM, item,
1246 "IPv6 inside a GRE tunnel is"
1247 " not recognised.");
1249 mask = &rte_flow_item_ipv6_mask;
1250 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1251 (const uint8_t *)&nic_mask,
1252 sizeof(struct rte_flow_item_ipv6),
1260 * Validate UDP item.
1263 * Item specification.
1264 * @param[in] item_flags
1265 * Bit-fields that holds the items detected until now.
1266 * @param[in] target_protocol
1267 * The next protocol in the previous item.
1268 * @param[in] flow_mask
1269 * mlx5 flow-specific (TCF, DV, verbs, etc.) supported header fields mask.
1271 * Pointer to error structure.
1274 * 0 on success, a negative errno value otherwise and rte_errno is set.
1277 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1278 uint64_t item_flags,
1279 uint8_t target_protocol,
1280 struct rte_flow_error *error)
1282 const struct rte_flow_item_udp *mask = item->mask;
1283 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1284 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1285 MLX5_FLOW_LAYER_OUTER_L3;
1286 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1287 MLX5_FLOW_LAYER_OUTER_L4;
1290 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1291 return rte_flow_error_set(error, EINVAL,
1292 RTE_FLOW_ERROR_TYPE_ITEM, item,
1293 "protocol filtering not compatible"
1295 if (!(item_flags & l3m))
1296 return rte_flow_error_set(error, EINVAL,
1297 RTE_FLOW_ERROR_TYPE_ITEM, item,
1298 "L3 is mandatory to filter on L4");
1299 if (item_flags & l4m)
1300 return rte_flow_error_set(error, EINVAL,
1301 RTE_FLOW_ERROR_TYPE_ITEM, item,
1302 "multiple L4 layers not supported");
1304 mask = &rte_flow_item_udp_mask;
1305 ret = mlx5_flow_item_acceptable
1306 (item, (const uint8_t *)mask,
1307 (const uint8_t *)&rte_flow_item_udp_mask,
1308 sizeof(struct rte_flow_item_udp), error);
1315 * Validate TCP item.
1318 * Item specification.
1319 * @param[in] item_flags
1320 * Bit-fields that holds the items detected until now.
1321 * @param[in] target_protocol
1322 * The next protocol in the previous item.
1324 * Pointer to error structure.
1327 * 0 on success, a negative errno value otherwise and rte_errno is set.
1330 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1331 uint64_t item_flags,
1332 uint8_t target_protocol,
1333 const struct rte_flow_item_tcp *flow_mask,
1334 struct rte_flow_error *error)
1336 const struct rte_flow_item_tcp *mask = item->mask;
1337 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1338 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1339 MLX5_FLOW_LAYER_OUTER_L3;
1340 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1341 MLX5_FLOW_LAYER_OUTER_L4;
1345 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1346 return rte_flow_error_set(error, EINVAL,
1347 RTE_FLOW_ERROR_TYPE_ITEM, item,
1348 "protocol filtering not compatible"
1350 if (!(item_flags & l3m))
1351 return rte_flow_error_set(error, EINVAL,
1352 RTE_FLOW_ERROR_TYPE_ITEM, item,
1353 "L3 is mandatory to filter on L4");
1354 if (item_flags & l4m)
1355 return rte_flow_error_set(error, EINVAL,
1356 RTE_FLOW_ERROR_TYPE_ITEM, item,
1357 "multiple L4 layers not supported");
1359 mask = &rte_flow_item_tcp_mask;
1360 ret = mlx5_flow_item_acceptable
1361 (item, (const uint8_t *)mask,
1362 (const uint8_t *)flow_mask,
1363 sizeof(struct rte_flow_item_tcp), error);
1370 * Validate VXLAN item.
1373 * Item specification.
1374 * @param[in] item_flags
1375 * Bit-fields that holds the items detected until now.
1376 * @param[in] target_protocol
1377 * The next protocol in the previous item.
1379 * Pointer to error structure.
1382 * 0 on success, a negative errno value otherwise and rte_errno is set.
1385 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1386 uint64_t item_flags,
1387 struct rte_flow_error *error)
1389 const struct rte_flow_item_vxlan *spec = item->spec;
1390 const struct rte_flow_item_vxlan *mask = item->mask;
1395 } id = { .vlan_id = 0, };
1396 uint32_t vlan_id = 0;
1399 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1400 return rte_flow_error_set(error, ENOTSUP,
1401 RTE_FLOW_ERROR_TYPE_ITEM, item,
1402 "multiple tunnel layers not"
1405 * Verify only UDPv4 is present as defined in
1406 * https://tools.ietf.org/html/rfc7348
1408 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1409 return rte_flow_error_set(error, EINVAL,
1410 RTE_FLOW_ERROR_TYPE_ITEM, item,
1411 "no outer UDP layer found");
1413 mask = &rte_flow_item_vxlan_mask;
1414 ret = mlx5_flow_item_acceptable
1415 (item, (const uint8_t *)mask,
1416 (const uint8_t *)&rte_flow_item_vxlan_mask,
1417 sizeof(struct rte_flow_item_vxlan),
1422 memcpy(&id.vni[1], spec->vni, 3);
1423 vlan_id = id.vlan_id;
1424 memcpy(&id.vni[1], mask->vni, 3);
1425 vlan_id &= id.vlan_id;
1428 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1429 * only this layer is defined in the Verbs specification it is
1430 * interpreted as wildcard and all packets will match this
1431 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1432 * udp), all packets matching the layers before will also
1433 * match this rule. To avoid such situation, VNI 0 is
1434 * currently refused.
1437 return rte_flow_error_set(error, ENOTSUP,
1438 RTE_FLOW_ERROR_TYPE_ITEM, item,
1439 "VXLAN vni cannot be 0");
1440 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1441 return rte_flow_error_set(error, ENOTSUP,
1442 RTE_FLOW_ERROR_TYPE_ITEM, item,
1443 "VXLAN tunnel must be fully defined");
1448 * Validate VXLAN_GPE item.
1451 * Item specification.
1452 * @param[in] item_flags
1453 * Bit-fields that holds the items detected until now.
1455 * Pointer to the private data structure.
1456 * @param[in] target_protocol
1457 * The next protocol in the previous item.
1459 * Pointer to error structure.
1462 * 0 on success, a negative errno value otherwise and rte_errno is set.
1465 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1466 uint64_t item_flags,
1467 struct rte_eth_dev *dev,
1468 struct rte_flow_error *error)
1470 struct priv *priv = dev->data->dev_private;
1471 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1472 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1477 } id = { .vlan_id = 0, };
1478 uint32_t vlan_id = 0;
1480 if (!priv->config.l3_vxlan_en)
1481 return rte_flow_error_set(error, ENOTSUP,
1482 RTE_FLOW_ERROR_TYPE_ITEM, item,
1483 "L3 VXLAN is not enabled by device"
1484 " parameter and/or not configured in"
1486 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1487 return rte_flow_error_set(error, ENOTSUP,
1488 RTE_FLOW_ERROR_TYPE_ITEM, item,
1489 "multiple tunnel layers not"
1492 * Verify only UDPv4 is present as defined in
1493 * https://tools.ietf.org/html/rfc7348
1495 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1496 return rte_flow_error_set(error, EINVAL,
1497 RTE_FLOW_ERROR_TYPE_ITEM, item,
1498 "no outer UDP layer found");
1500 mask = &rte_flow_item_vxlan_gpe_mask;
1501 ret = mlx5_flow_item_acceptable
1502 (item, (const uint8_t *)mask,
1503 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1504 sizeof(struct rte_flow_item_vxlan_gpe),
1510 return rte_flow_error_set(error, ENOTSUP,
1511 RTE_FLOW_ERROR_TYPE_ITEM,
1513 "VxLAN-GPE protocol"
1515 memcpy(&id.vni[1], spec->vni, 3);
1516 vlan_id = id.vlan_id;
1517 memcpy(&id.vni[1], mask->vni, 3);
1518 vlan_id &= id.vlan_id;
1521 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1522 * layer is defined in the Verbs specification it is interpreted as
1523 * wildcard and all packets will match this rule, if it follows a full
1524 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1525 * before will also match this rule. To avoid such situation, VNI 0
1526 * is currently refused.
1529 return rte_flow_error_set(error, ENOTSUP,
1530 RTE_FLOW_ERROR_TYPE_ITEM, item,
1531 "VXLAN-GPE vni cannot be 0");
1532 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1533 return rte_flow_error_set(error, ENOTSUP,
1534 RTE_FLOW_ERROR_TYPE_ITEM, item,
1535 "VXLAN-GPE tunnel must be fully"
1541 * Validate GRE item.
1544 * Item specification.
1545 * @param[in] item_flags
1546 * Bit flags to mark detected items.
1547 * @param[in] target_protocol
1548 * The next protocol in the previous item.
1550 * Pointer to error structure.
1553 * 0 on success, a negative errno value otherwise and rte_errno is set.
1556 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
1557 uint64_t item_flags,
1558 uint8_t target_protocol,
1559 struct rte_flow_error *error)
1561 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
1562 const struct rte_flow_item_gre *mask = item->mask;
1565 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
1566 return rte_flow_error_set(error, EINVAL,
1567 RTE_FLOW_ERROR_TYPE_ITEM, item,
1568 "protocol filtering not compatible"
1569 " with this GRE layer");
1570 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1571 return rte_flow_error_set(error, ENOTSUP,
1572 RTE_FLOW_ERROR_TYPE_ITEM, item,
1573 "multiple tunnel layers not"
1575 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
1576 return rte_flow_error_set(error, ENOTSUP,
1577 RTE_FLOW_ERROR_TYPE_ITEM, item,
1578 "L3 Layer is missing");
1580 mask = &rte_flow_item_gre_mask;
1581 ret = mlx5_flow_item_acceptable
1582 (item, (const uint8_t *)mask,
1583 (const uint8_t *)&rte_flow_item_gre_mask,
1584 sizeof(struct rte_flow_item_gre), error);
1587 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
1588 if (spec && (spec->protocol & mask->protocol))
1589 return rte_flow_error_set(error, ENOTSUP,
1590 RTE_FLOW_ERROR_TYPE_ITEM, item,
1591 "without MPLS support the"
1592 " specification cannot be used for"
1599 * Validate MPLS item.
1602 * Item specification.
1603 * @param[in] item_flags
1604 * Bit-fields that holds the items detected until now.
1605 * @param[in] target_protocol
1606 * The next protocol in the previous item.
1608 * Pointer to error structure.
1611 * 0 on success, a negative errno value otherwise and rte_errno is set.
1614 mlx5_flow_validate_item_mpls(const struct rte_flow_item *item __rte_unused,
1615 uint64_t item_flags __rte_unused,
1616 uint8_t target_protocol __rte_unused,
1617 struct rte_flow_error *error)
1619 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
1620 const struct rte_flow_item_mpls *mask = item->mask;
1623 if (target_protocol != 0xff && target_protocol != IPPROTO_MPLS)
1624 return rte_flow_error_set(error, EINVAL,
1625 RTE_FLOW_ERROR_TYPE_ITEM, item,
1626 "protocol filtering not compatible"
1627 " with MPLS layer");
1628 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
1629 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
1630 !(item_flags & MLX5_FLOW_LAYER_GRE))
1631 return rte_flow_error_set(error, ENOTSUP,
1632 RTE_FLOW_ERROR_TYPE_ITEM, item,
1633 "multiple tunnel layers not"
1636 mask = &rte_flow_item_mpls_mask;
1637 ret = mlx5_flow_item_acceptable
1638 (item, (const uint8_t *)mask,
1639 (const uint8_t *)&rte_flow_item_mpls_mask,
1640 sizeof(struct rte_flow_item_mpls), error);
1645 return rte_flow_error_set(error, ENOTSUP,
1646 RTE_FLOW_ERROR_TYPE_ITEM, item,
1647 "MPLS is not supported by Verbs, please"
1652 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
1653 const struct rte_flow_attr *attr __rte_unused,
1654 const struct rte_flow_item items[] __rte_unused,
1655 const struct rte_flow_action actions[] __rte_unused,
1656 struct rte_flow_error *error __rte_unused)
1658 rte_errno = ENOTSUP;
1662 static struct mlx5_flow *
1663 flow_null_prepare(const struct rte_flow_attr *attr __rte_unused,
1664 const struct rte_flow_item items[] __rte_unused,
1665 const struct rte_flow_action actions[] __rte_unused,
1666 uint64_t *item_flags __rte_unused,
1667 uint64_t *action_flags __rte_unused,
1668 struct rte_flow_error *error __rte_unused)
1670 rte_errno = ENOTSUP;
1675 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
1676 struct mlx5_flow *dev_flow __rte_unused,
1677 const struct rte_flow_attr *attr __rte_unused,
1678 const struct rte_flow_item items[] __rte_unused,
1679 const struct rte_flow_action actions[] __rte_unused,
1680 struct rte_flow_error *error __rte_unused)
1682 rte_errno = ENOTSUP;
1687 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
1688 struct rte_flow *flow __rte_unused,
1689 struct rte_flow_error *error __rte_unused)
1691 rte_errno = ENOTSUP;
1696 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
1697 struct rte_flow *flow __rte_unused)
1702 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
1703 struct rte_flow *flow __rte_unused)
1708 flow_null_query(struct rte_eth_dev *dev __rte_unused,
1709 struct rte_flow *flow __rte_unused,
1710 const struct rte_flow_action *actions __rte_unused,
1711 void *data __rte_unused,
1712 struct rte_flow_error *error __rte_unused)
1714 rte_errno = ENOTSUP;
1718 /* Void driver to protect from null pointer reference. */
1719 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
1720 .validate = flow_null_validate,
1721 .prepare = flow_null_prepare,
1722 .translate = flow_null_translate,
1723 .apply = flow_null_apply,
1724 .remove = flow_null_remove,
1725 .destroy = flow_null_destroy,
1726 .query = flow_null_query,
1730 * Select flow driver type according to flow attributes and device
1734 * Pointer to the dev structure.
1736 * Pointer to the flow attributes.
1739 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
1741 static enum mlx5_flow_drv_type
1742 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
1744 struct priv *priv = dev->data->dev_private;
1745 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
1748 type = MLX5_FLOW_TYPE_TCF;
1750 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
1751 MLX5_FLOW_TYPE_VERBS;
1755 #define flow_get_drv_ops(type) flow_drv_ops[type]
1758 * Flow driver validation API. This abstracts calling driver specific functions.
1759 * The type of flow driver is determined according to flow attributes.
1762 * Pointer to the dev structure.
1764 * Pointer to the flow attributes.
1766 * Pointer to the list of items.
1767 * @param[in] actions
1768 * Pointer to the list of actions.
1770 * Pointer to the error structure.
1773 * 0 on success, a negative errno value otherwise and rte_ernno is set.
1776 flow_drv_validate(struct rte_eth_dev *dev,
1777 const struct rte_flow_attr *attr,
1778 const struct rte_flow_item items[],
1779 const struct rte_flow_action actions[],
1780 struct rte_flow_error *error)
1782 const struct mlx5_flow_driver_ops *fops;
1783 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
1785 fops = flow_get_drv_ops(type);
1786 return fops->validate(dev, attr, items, actions, error);
1790 * Flow driver preparation API. This abstracts calling driver specific
1791 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
1792 * calculates the size of memory required for device flow, allocates the memory,
1793 * initializes the device flow and returns the pointer.
1796 * Pointer to the flow attributes.
1798 * Pointer to the list of items.
1799 * @param[in] actions
1800 * Pointer to the list of actions.
1801 * @param[out] item_flags
1802 * Pointer to bit mask of all items detected.
1803 * @param[out] action_flags
1804 * Pointer to bit mask of all actions detected.
1806 * Pointer to the error structure.
1809 * Pointer to device flow on success, otherwise NULL and rte_ernno is set.
1811 static inline struct mlx5_flow *
1812 flow_drv_prepare(struct rte_flow *flow,
1813 const struct rte_flow_attr *attr,
1814 const struct rte_flow_item items[],
1815 const struct rte_flow_action actions[],
1816 uint64_t *item_flags,
1817 uint64_t *action_flags,
1818 struct rte_flow_error *error)
1820 const struct mlx5_flow_driver_ops *fops;
1821 enum mlx5_flow_drv_type type = flow->drv_type;
1823 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1824 fops = flow_get_drv_ops(type);
1825 return fops->prepare(attr, items, actions, item_flags, action_flags,
1830 * Flow driver translation API. This abstracts calling driver specific
1831 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
1832 * translates a generic flow into a driver flow. flow_drv_prepare() must
1837 * Pointer to the rte dev structure.
1838 * @param[in, out] dev_flow
1839 * Pointer to the mlx5 flow.
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 * 0 on success, a negative errno value otherwise and rte_ernno is set.
1853 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_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 = dev_flow->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->translate(dev, dev_flow, attr, items, actions, error);
1868 * Flow driver apply API. This abstracts calling driver specific functions.
1869 * Parent flow (rte_flow) should have driver type (drv_type). It applies
1870 * translated driver flows on to device. flow_drv_translate() must precede.
1873 * Pointer to Ethernet device structure.
1874 * @param[in, out] flow
1875 * Pointer to flow structure.
1877 * Pointer to error structure.
1880 * 0 on success, a negative errno value otherwise and rte_errno is set.
1883 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
1884 struct rte_flow_error *error)
1886 const struct mlx5_flow_driver_ops *fops;
1887 enum mlx5_flow_drv_type type = flow->drv_type;
1889 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1890 fops = flow_get_drv_ops(type);
1891 return fops->apply(dev, flow, error);
1895 * Flow driver remove API. This abstracts calling driver specific functions.
1896 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
1897 * on device. All the resources of the flow should be freed by calling
1898 * flow_dv_destroy().
1901 * Pointer to Ethernet device.
1902 * @param[in, out] flow
1903 * Pointer to flow structure.
1906 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
1908 const struct mlx5_flow_driver_ops *fops;
1909 enum mlx5_flow_drv_type type = flow->drv_type;
1911 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1912 fops = flow_get_drv_ops(type);
1913 fops->remove(dev, flow);
1917 * Flow driver destroy API. This abstracts calling driver specific functions.
1918 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
1919 * on device and releases resources of the flow.
1922 * Pointer to Ethernet device.
1923 * @param[in, out] flow
1924 * Pointer to flow structure.
1927 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
1929 const struct mlx5_flow_driver_ops *fops;
1930 enum mlx5_flow_drv_type type = flow->drv_type;
1932 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1933 fops = flow_get_drv_ops(type);
1934 fops->destroy(dev, flow);
1938 * Validate a flow supported by the NIC.
1940 * @see rte_flow_validate()
1944 mlx5_flow_validate(struct rte_eth_dev *dev,
1945 const struct rte_flow_attr *attr,
1946 const struct rte_flow_item items[],
1947 const struct rte_flow_action actions[],
1948 struct rte_flow_error *error)
1952 ret = flow_drv_validate(dev, attr, items, actions, error);
1959 * Get RSS action from the action list.
1961 * @param[in] actions
1962 * Pointer to the list of actions.
1965 * Pointer to the RSS action if exist, else return NULL.
1967 static const struct rte_flow_action_rss*
1968 flow_get_rss_action(const struct rte_flow_action actions[])
1970 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1971 switch (actions->type) {
1972 case RTE_FLOW_ACTION_TYPE_RSS:
1973 return (const struct rte_flow_action_rss *)
1983 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
1985 const struct rte_flow_item *item;
1986 unsigned int has_vlan = 0;
1988 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1989 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1995 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
1996 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
1997 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
1998 MLX5_EXPANSION_ROOT_OUTER;
2002 * Create a flow and add it to @p list.
2005 * Pointer to Ethernet device.
2007 * Pointer to a TAILQ flow list.
2009 * Flow rule attributes.
2011 * Pattern specification (list terminated by the END pattern item).
2012 * @param[in] actions
2013 * Associated actions (list terminated by the END action).
2015 * Perform verbose error reporting if not NULL.
2018 * A flow on success, NULL otherwise and rte_errno is set.
2020 static struct rte_flow *
2021 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
2022 const struct rte_flow_attr *attr,
2023 const struct rte_flow_item items[],
2024 const struct rte_flow_action actions[],
2025 struct rte_flow_error *error)
2027 struct rte_flow *flow = NULL;
2028 struct mlx5_flow *dev_flow;
2029 uint64_t action_flags = 0;
2030 uint64_t item_flags = 0;
2031 const struct rte_flow_action_rss *rss;
2033 struct rte_flow_expand_rss buf;
2034 uint8_t buffer[2048];
2036 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
2041 ret = flow_drv_validate(dev, attr, items, actions, error);
2044 flow_size = sizeof(struct rte_flow);
2045 rss = flow_get_rss_action(actions);
2047 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
2050 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
2051 flow = rte_calloc(__func__, 1, flow_size, 0);
2052 flow->drv_type = flow_get_drv_type(dev, attr);
2053 assert(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
2054 flow->drv_type < MLX5_FLOW_TYPE_MAX);
2055 flow->queue = (void *)(flow + 1);
2056 LIST_INIT(&flow->dev_flows);
2057 if (rss && rss->types) {
2058 unsigned int graph_root;
2060 graph_root = find_graph_root(items, rss->level);
2061 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
2063 mlx5_support_expansion,
2066 (unsigned int)ret < sizeof(expand_buffer.buffer));
2069 buf->entry[0].pattern = (void *)(uintptr_t)items;
2071 for (i = 0; i < buf->entries; ++i) {
2072 dev_flow = flow_drv_prepare(flow, attr, buf->entry[i].pattern,
2073 actions, &item_flags, &action_flags,
2077 dev_flow->flow = flow;
2078 dev_flow->layers = item_flags;
2079 /* Store actions once as expanded flows have same actions. */
2081 flow->actions = action_flags;
2082 assert(flow->actions == action_flags);
2083 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
2084 ret = flow_drv_translate(dev, dev_flow, attr,
2085 buf->entry[i].pattern,
2090 if (dev->data->dev_started) {
2091 ret = flow_drv_apply(dev, flow, error);
2095 TAILQ_INSERT_TAIL(list, flow, next);
2096 flow_rxq_flags_set(dev, flow);
2099 ret = rte_errno; /* Save rte_errno before cleanup. */
2101 flow_drv_destroy(dev, flow);
2103 rte_errno = ret; /* Restore rte_errno. */
2110 * @see rte_flow_create()
2114 mlx5_flow_create(struct rte_eth_dev *dev,
2115 const struct rte_flow_attr *attr,
2116 const struct rte_flow_item items[],
2117 const struct rte_flow_action actions[],
2118 struct rte_flow_error *error)
2120 return flow_list_create(dev,
2121 &((struct priv *)dev->data->dev_private)->flows,
2122 attr, items, actions, error);
2126 * Destroy a flow in a list.
2129 * Pointer to Ethernet device.
2131 * Pointer to a TAILQ flow list.
2136 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
2137 struct rte_flow *flow)
2139 flow_drv_destroy(dev, flow);
2140 TAILQ_REMOVE(list, flow, next);
2142 * Update RX queue flags only if port is started, otherwise it is
2145 if (dev->data->dev_started)
2146 flow_rxq_flags_trim(dev, flow);
2147 rte_free(flow->fdir);
2152 * Destroy all flows.
2155 * Pointer to Ethernet device.
2157 * Pointer to a TAILQ flow list.
2160 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
2162 while (!TAILQ_EMPTY(list)) {
2163 struct rte_flow *flow;
2165 flow = TAILQ_FIRST(list);
2166 flow_list_destroy(dev, list, flow);
2174 * Pointer to Ethernet device.
2176 * Pointer to a TAILQ flow list.
2179 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
2181 struct rte_flow *flow;
2183 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next)
2184 flow_drv_remove(dev, flow);
2185 flow_rxq_flags_clear(dev);
2192 * Pointer to Ethernet device.
2194 * Pointer to a TAILQ flow list.
2197 * 0 on success, a negative errno value otherwise and rte_errno is set.
2200 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
2202 struct rte_flow *flow;
2203 struct rte_flow_error error;
2206 TAILQ_FOREACH(flow, list, next) {
2207 ret = flow_drv_apply(dev, flow, &error);
2210 flow_rxq_flags_set(dev, flow);
2214 ret = rte_errno; /* Save rte_errno before cleanup. */
2215 mlx5_flow_stop(dev, list);
2216 rte_errno = ret; /* Restore rte_errno. */
2221 * Verify the flow list is empty
2224 * Pointer to Ethernet device.
2226 * @return the number of flows not released.
2229 mlx5_flow_verify(struct rte_eth_dev *dev)
2231 struct priv *priv = dev->data->dev_private;
2232 struct rte_flow *flow;
2235 TAILQ_FOREACH(flow, &priv->flows, next) {
2236 DRV_LOG(DEBUG, "port %u flow %p still referenced",
2237 dev->data->port_id, (void *)flow);
2244 * Enable a control flow configured from the control plane.
2247 * Pointer to Ethernet device.
2249 * An Ethernet flow spec to apply.
2251 * An Ethernet flow mask to apply.
2253 * A VLAN flow spec to apply.
2255 * A VLAN flow mask to apply.
2258 * 0 on success, a negative errno value otherwise and rte_errno is set.
2261 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
2262 struct rte_flow_item_eth *eth_spec,
2263 struct rte_flow_item_eth *eth_mask,
2264 struct rte_flow_item_vlan *vlan_spec,
2265 struct rte_flow_item_vlan *vlan_mask)
2267 struct priv *priv = dev->data->dev_private;
2268 const struct rte_flow_attr attr = {
2270 .priority = MLX5_FLOW_PRIO_RSVD,
2272 struct rte_flow_item items[] = {
2274 .type = RTE_FLOW_ITEM_TYPE_ETH,
2280 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
2281 RTE_FLOW_ITEM_TYPE_END,
2287 .type = RTE_FLOW_ITEM_TYPE_END,
2290 uint16_t queue[priv->reta_idx_n];
2291 struct rte_flow_action_rss action_rss = {
2292 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
2294 .types = priv->rss_conf.rss_hf,
2295 .key_len = priv->rss_conf.rss_key_len,
2296 .queue_num = priv->reta_idx_n,
2297 .key = priv->rss_conf.rss_key,
2300 struct rte_flow_action actions[] = {
2302 .type = RTE_FLOW_ACTION_TYPE_RSS,
2303 .conf = &action_rss,
2306 .type = RTE_FLOW_ACTION_TYPE_END,
2309 struct rte_flow *flow;
2310 struct rte_flow_error error;
2313 if (!priv->reta_idx_n) {
2317 for (i = 0; i != priv->reta_idx_n; ++i)
2318 queue[i] = (*priv->reta_idx)[i];
2319 flow = flow_list_create(dev, &priv->ctrl_flows,
2320 &attr, items, actions, &error);
2327 * Enable a flow control configured from the control plane.
2330 * Pointer to Ethernet device.
2332 * An Ethernet flow spec to apply.
2334 * An Ethernet flow mask to apply.
2337 * 0 on success, a negative errno value otherwise and rte_errno is set.
2340 mlx5_ctrl_flow(struct rte_eth_dev *dev,
2341 struct rte_flow_item_eth *eth_spec,
2342 struct rte_flow_item_eth *eth_mask)
2344 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
2350 * @see rte_flow_destroy()
2354 mlx5_flow_destroy(struct rte_eth_dev *dev,
2355 struct rte_flow *flow,
2356 struct rte_flow_error *error __rte_unused)
2358 struct priv *priv = dev->data->dev_private;
2360 flow_list_destroy(dev, &priv->flows, flow);
2365 * Destroy all flows.
2367 * @see rte_flow_flush()
2371 mlx5_flow_flush(struct rte_eth_dev *dev,
2372 struct rte_flow_error *error __rte_unused)
2374 struct priv *priv = dev->data->dev_private;
2376 mlx5_flow_list_flush(dev, &priv->flows);
2383 * @see rte_flow_isolate()
2387 mlx5_flow_isolate(struct rte_eth_dev *dev,
2389 struct rte_flow_error *error)
2391 struct priv *priv = dev->data->dev_private;
2393 if (dev->data->dev_started) {
2394 rte_flow_error_set(error, EBUSY,
2395 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2397 "port must be stopped first");
2400 priv->isolated = !!enable;
2402 dev->dev_ops = &mlx5_dev_ops_isolate;
2404 dev->dev_ops = &mlx5_dev_ops;
2411 * @see rte_flow_query()
2415 flow_drv_query(struct rte_eth_dev *dev,
2416 struct rte_flow *flow,
2417 const struct rte_flow_action *actions,
2419 struct rte_flow_error *error)
2421 const struct mlx5_flow_driver_ops *fops;
2422 enum mlx5_flow_drv_type ftype = flow->drv_type;
2424 assert(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
2425 fops = flow_get_drv_ops(ftype);
2427 return fops->query(dev, flow, actions, data, error);
2433 * @see rte_flow_query()
2437 mlx5_flow_query(struct rte_eth_dev *dev,
2438 struct rte_flow *flow,
2439 const struct rte_flow_action *actions,
2441 struct rte_flow_error *error)
2445 ret = flow_drv_query(dev, flow, actions, data, error);
2452 * Convert a flow director filter to a generic flow.
2455 * Pointer to Ethernet device.
2456 * @param fdir_filter
2457 * Flow director filter to add.
2459 * Generic flow parameters structure.
2462 * 0 on success, a negative errno value otherwise and rte_errno is set.
2465 flow_fdir_filter_convert(struct rte_eth_dev *dev,
2466 const struct rte_eth_fdir_filter *fdir_filter,
2467 struct mlx5_fdir *attributes)
2469 struct priv *priv = dev->data->dev_private;
2470 const struct rte_eth_fdir_input *input = &fdir_filter->input;
2471 const struct rte_eth_fdir_masks *mask =
2472 &dev->data->dev_conf.fdir_conf.mask;
2474 /* Validate queue number. */
2475 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
2476 DRV_LOG(ERR, "port %u invalid queue number %d",
2477 dev->data->port_id, fdir_filter->action.rx_queue);
2481 attributes->attr.ingress = 1;
2482 attributes->items[0] = (struct rte_flow_item) {
2483 .type = RTE_FLOW_ITEM_TYPE_ETH,
2484 .spec = &attributes->l2,
2485 .mask = &attributes->l2_mask,
2487 switch (fdir_filter->action.behavior) {
2488 case RTE_ETH_FDIR_ACCEPT:
2489 attributes->actions[0] = (struct rte_flow_action){
2490 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
2491 .conf = &attributes->queue,
2494 case RTE_ETH_FDIR_REJECT:
2495 attributes->actions[0] = (struct rte_flow_action){
2496 .type = RTE_FLOW_ACTION_TYPE_DROP,
2500 DRV_LOG(ERR, "port %u invalid behavior %d",
2502 fdir_filter->action.behavior);
2503 rte_errno = ENOTSUP;
2506 attributes->queue.index = fdir_filter->action.rx_queue;
2508 switch (fdir_filter->input.flow_type) {
2509 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2510 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2511 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2512 attributes->l3.ipv4.hdr = (struct ipv4_hdr){
2513 .src_addr = input->flow.ip4_flow.src_ip,
2514 .dst_addr = input->flow.ip4_flow.dst_ip,
2515 .time_to_live = input->flow.ip4_flow.ttl,
2516 .type_of_service = input->flow.ip4_flow.tos,
2518 attributes->l3_mask.ipv4.hdr = (struct ipv4_hdr){
2519 .src_addr = mask->ipv4_mask.src_ip,
2520 .dst_addr = mask->ipv4_mask.dst_ip,
2521 .time_to_live = mask->ipv4_mask.ttl,
2522 .type_of_service = mask->ipv4_mask.tos,
2523 .next_proto_id = mask->ipv4_mask.proto,
2525 attributes->items[1] = (struct rte_flow_item){
2526 .type = RTE_FLOW_ITEM_TYPE_IPV4,
2527 .spec = &attributes->l3,
2528 .mask = &attributes->l3_mask,
2531 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2532 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2533 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2534 attributes->l3.ipv6.hdr = (struct ipv6_hdr){
2535 .hop_limits = input->flow.ipv6_flow.hop_limits,
2536 .proto = input->flow.ipv6_flow.proto,
2539 memcpy(attributes->l3.ipv6.hdr.src_addr,
2540 input->flow.ipv6_flow.src_ip,
2541 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2542 memcpy(attributes->l3.ipv6.hdr.dst_addr,
2543 input->flow.ipv6_flow.dst_ip,
2544 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2545 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
2546 mask->ipv6_mask.src_ip,
2547 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2548 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
2549 mask->ipv6_mask.dst_ip,
2550 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2551 attributes->items[1] = (struct rte_flow_item){
2552 .type = RTE_FLOW_ITEM_TYPE_IPV6,
2553 .spec = &attributes->l3,
2554 .mask = &attributes->l3_mask,
2558 DRV_LOG(ERR, "port %u invalid flow type%d",
2559 dev->data->port_id, fdir_filter->input.flow_type);
2560 rte_errno = ENOTSUP;
2564 switch (fdir_filter->input.flow_type) {
2565 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2566 attributes->l4.udp.hdr = (struct udp_hdr){
2567 .src_port = input->flow.udp4_flow.src_port,
2568 .dst_port = input->flow.udp4_flow.dst_port,
2570 attributes->l4_mask.udp.hdr = (struct udp_hdr){
2571 .src_port = mask->src_port_mask,
2572 .dst_port = mask->dst_port_mask,
2574 attributes->items[2] = (struct rte_flow_item){
2575 .type = RTE_FLOW_ITEM_TYPE_UDP,
2576 .spec = &attributes->l4,
2577 .mask = &attributes->l4_mask,
2580 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2581 attributes->l4.tcp.hdr = (struct tcp_hdr){
2582 .src_port = input->flow.tcp4_flow.src_port,
2583 .dst_port = input->flow.tcp4_flow.dst_port,
2585 attributes->l4_mask.tcp.hdr = (struct tcp_hdr){
2586 .src_port = mask->src_port_mask,
2587 .dst_port = mask->dst_port_mask,
2589 attributes->items[2] = (struct rte_flow_item){
2590 .type = RTE_FLOW_ITEM_TYPE_TCP,
2591 .spec = &attributes->l4,
2592 .mask = &attributes->l4_mask,
2595 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2596 attributes->l4.udp.hdr = (struct udp_hdr){
2597 .src_port = input->flow.udp6_flow.src_port,
2598 .dst_port = input->flow.udp6_flow.dst_port,
2600 attributes->l4_mask.udp.hdr = (struct udp_hdr){
2601 .src_port = mask->src_port_mask,
2602 .dst_port = mask->dst_port_mask,
2604 attributes->items[2] = (struct rte_flow_item){
2605 .type = RTE_FLOW_ITEM_TYPE_UDP,
2606 .spec = &attributes->l4,
2607 .mask = &attributes->l4_mask,
2610 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2611 attributes->l4.tcp.hdr = (struct tcp_hdr){
2612 .src_port = input->flow.tcp6_flow.src_port,
2613 .dst_port = input->flow.tcp6_flow.dst_port,
2615 attributes->l4_mask.tcp.hdr = (struct tcp_hdr){
2616 .src_port = mask->src_port_mask,
2617 .dst_port = mask->dst_port_mask,
2619 attributes->items[2] = (struct rte_flow_item){
2620 .type = RTE_FLOW_ITEM_TYPE_TCP,
2621 .spec = &attributes->l4,
2622 .mask = &attributes->l4_mask,
2625 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2626 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2629 DRV_LOG(ERR, "port %u invalid flow type%d",
2630 dev->data->port_id, fdir_filter->input.flow_type);
2631 rte_errno = ENOTSUP;
2637 #define FLOW_FDIR_CMP(f1, f2, fld) \
2638 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
2641 * Compare two FDIR flows. If items and actions are identical, the two flows are
2645 * Pointer to Ethernet device.
2647 * FDIR flow to compare.
2649 * FDIR flow to compare.
2652 * Zero on match, 1 otherwise.
2655 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
2657 if (FLOW_FDIR_CMP(f1, f2, attr) ||
2658 FLOW_FDIR_CMP(f1, f2, l2) ||
2659 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
2660 FLOW_FDIR_CMP(f1, f2, l3) ||
2661 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
2662 FLOW_FDIR_CMP(f1, f2, l4) ||
2663 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
2664 FLOW_FDIR_CMP(f1, f2, actions[0]))
2666 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
2667 FLOW_FDIR_CMP(f1, f2, queue))
2673 * Search device flow list to find out a matched FDIR flow.
2676 * Pointer to Ethernet device.
2678 * FDIR flow to lookup.
2681 * Pointer of flow if found, NULL otherwise.
2683 static struct rte_flow *
2684 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
2686 struct priv *priv = dev->data->dev_private;
2687 struct rte_flow *flow = NULL;
2690 TAILQ_FOREACH(flow, &priv->flows, next) {
2691 if (flow->fdir && !flow_fdir_cmp(flow->fdir, fdir_flow)) {
2692 DRV_LOG(DEBUG, "port %u found FDIR flow %p",
2693 dev->data->port_id, (void *)flow);
2701 * Add new flow director filter and store it in list.
2704 * Pointer to Ethernet device.
2705 * @param fdir_filter
2706 * Flow director filter to add.
2709 * 0 on success, a negative errno value otherwise and rte_errno is set.
2712 flow_fdir_filter_add(struct rte_eth_dev *dev,
2713 const struct rte_eth_fdir_filter *fdir_filter)
2715 struct priv *priv = dev->data->dev_private;
2716 struct mlx5_fdir *fdir_flow;
2717 struct rte_flow *flow;
2720 fdir_flow = rte_zmalloc(__func__, sizeof(*fdir_flow), 0);
2725 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
2728 flow = flow_fdir_filter_lookup(dev, fdir_flow);
2733 flow = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
2734 fdir_flow->items, fdir_flow->actions, NULL);
2737 assert(!flow->fdir);
2738 flow->fdir = fdir_flow;
2739 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
2740 dev->data->port_id, (void *)flow);
2743 rte_free(fdir_flow);
2748 * Delete specific filter.
2751 * Pointer to Ethernet device.
2752 * @param fdir_filter
2753 * Filter to be deleted.
2756 * 0 on success, a negative errno value otherwise and rte_errno is set.
2759 flow_fdir_filter_delete(struct rte_eth_dev *dev,
2760 const struct rte_eth_fdir_filter *fdir_filter)
2762 struct priv *priv = dev->data->dev_private;
2763 struct rte_flow *flow;
2764 struct mlx5_fdir fdir_flow = {
2769 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
2772 flow = flow_fdir_filter_lookup(dev, &fdir_flow);
2777 flow_list_destroy(dev, &priv->flows, flow);
2778 DRV_LOG(DEBUG, "port %u deleted FDIR flow %p",
2779 dev->data->port_id, (void *)flow);
2784 * Update queue for specific filter.
2787 * Pointer to Ethernet device.
2788 * @param fdir_filter
2789 * Filter to be updated.
2792 * 0 on success, a negative errno value otherwise and rte_errno is set.
2795 flow_fdir_filter_update(struct rte_eth_dev *dev,
2796 const struct rte_eth_fdir_filter *fdir_filter)
2800 ret = flow_fdir_filter_delete(dev, fdir_filter);
2803 return flow_fdir_filter_add(dev, fdir_filter);
2807 * Flush all filters.
2810 * Pointer to Ethernet device.
2813 flow_fdir_filter_flush(struct rte_eth_dev *dev)
2815 struct priv *priv = dev->data->dev_private;
2817 mlx5_flow_list_flush(dev, &priv->flows);
2821 * Get flow director information.
2824 * Pointer to Ethernet device.
2825 * @param[out] fdir_info
2826 * Resulting flow director information.
2829 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
2831 struct rte_eth_fdir_masks *mask =
2832 &dev->data->dev_conf.fdir_conf.mask;
2834 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
2835 fdir_info->guarant_spc = 0;
2836 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
2837 fdir_info->max_flexpayload = 0;
2838 fdir_info->flow_types_mask[0] = 0;
2839 fdir_info->flex_payload_unit = 0;
2840 fdir_info->max_flex_payload_segment_num = 0;
2841 fdir_info->flex_payload_limit = 0;
2842 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
2846 * Deal with flow director operations.
2849 * Pointer to Ethernet device.
2851 * Operation to perform.
2853 * Pointer to operation-specific structure.
2856 * 0 on success, a negative errno value otherwise and rte_errno is set.
2859 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
2862 enum rte_fdir_mode fdir_mode =
2863 dev->data->dev_conf.fdir_conf.mode;
2865 if (filter_op == RTE_ETH_FILTER_NOP)
2867 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
2868 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2869 DRV_LOG(ERR, "port %u flow director mode %d not supported",
2870 dev->data->port_id, fdir_mode);
2874 switch (filter_op) {
2875 case RTE_ETH_FILTER_ADD:
2876 return flow_fdir_filter_add(dev, arg);
2877 case RTE_ETH_FILTER_UPDATE:
2878 return flow_fdir_filter_update(dev, arg);
2879 case RTE_ETH_FILTER_DELETE:
2880 return flow_fdir_filter_delete(dev, arg);
2881 case RTE_ETH_FILTER_FLUSH:
2882 flow_fdir_filter_flush(dev);
2884 case RTE_ETH_FILTER_INFO:
2885 flow_fdir_info_get(dev, arg);
2888 DRV_LOG(DEBUG, "port %u unknown operation %u",
2889 dev->data->port_id, filter_op);
2897 * Manage filter operations.
2900 * Pointer to Ethernet device structure.
2901 * @param filter_type
2904 * Operation to perform.
2906 * Pointer to operation-specific structure.
2909 * 0 on success, a negative errno value otherwise and rte_errno is set.
2912 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
2913 enum rte_filter_type filter_type,
2914 enum rte_filter_op filter_op,
2917 switch (filter_type) {
2918 case RTE_ETH_FILTER_GENERIC:
2919 if (filter_op != RTE_ETH_FILTER_GET) {
2923 *(const void **)arg = &mlx5_flow_ops;
2925 case RTE_ETH_FILTER_FDIR:
2926 return flow_fdir_ctrl_func(dev, filter_op, arg);
2928 DRV_LOG(ERR, "port %u filter type (%d) not supported",
2929 dev->data->port_id, filter_type);
2930 rte_errno = ENOTSUP;