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"
33 #include "mlx5_flow.h"
34 #include "mlx5_glue.h"
36 #include "mlx5_rxtx.h"
38 /* Dev ops structure defined in mlx5.c */
39 extern const struct eth_dev_ops mlx5_dev_ops;
40 extern const struct eth_dev_ops mlx5_dev_ops_isolate;
42 /** Device flow drivers. */
43 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
44 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
46 extern const struct mlx5_flow_driver_ops mlx5_flow_tcf_drv_ops;
47 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
49 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
51 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
52 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
53 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
54 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
56 [MLX5_FLOW_TYPE_TCF] = &mlx5_flow_tcf_drv_ops,
57 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
58 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
63 MLX5_EXPANSION_ROOT_OUTER,
64 MLX5_EXPANSION_ROOT_ETH_VLAN,
65 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
66 MLX5_EXPANSION_OUTER_ETH,
67 MLX5_EXPANSION_OUTER_ETH_VLAN,
68 MLX5_EXPANSION_OUTER_VLAN,
69 MLX5_EXPANSION_OUTER_IPV4,
70 MLX5_EXPANSION_OUTER_IPV4_UDP,
71 MLX5_EXPANSION_OUTER_IPV4_TCP,
72 MLX5_EXPANSION_OUTER_IPV6,
73 MLX5_EXPANSION_OUTER_IPV6_UDP,
74 MLX5_EXPANSION_OUTER_IPV6_TCP,
76 MLX5_EXPANSION_VXLAN_GPE,
80 MLX5_EXPANSION_ETH_VLAN,
83 MLX5_EXPANSION_IPV4_UDP,
84 MLX5_EXPANSION_IPV4_TCP,
86 MLX5_EXPANSION_IPV6_UDP,
87 MLX5_EXPANSION_IPV6_TCP,
90 /** Supported expansion of items. */
91 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
92 [MLX5_EXPANSION_ROOT] = {
93 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
96 .type = RTE_FLOW_ITEM_TYPE_END,
98 [MLX5_EXPANSION_ROOT_OUTER] = {
99 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
100 MLX5_EXPANSION_OUTER_IPV4,
101 MLX5_EXPANSION_OUTER_IPV6),
102 .type = RTE_FLOW_ITEM_TYPE_END,
104 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
105 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
106 .type = RTE_FLOW_ITEM_TYPE_END,
108 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
109 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
110 .type = RTE_FLOW_ITEM_TYPE_END,
112 [MLX5_EXPANSION_OUTER_ETH] = {
113 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
114 MLX5_EXPANSION_OUTER_IPV6,
115 MLX5_EXPANSION_MPLS),
116 .type = RTE_FLOW_ITEM_TYPE_ETH,
119 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
120 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
121 .type = RTE_FLOW_ITEM_TYPE_ETH,
124 [MLX5_EXPANSION_OUTER_VLAN] = {
125 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
126 MLX5_EXPANSION_OUTER_IPV6),
127 .type = RTE_FLOW_ITEM_TYPE_VLAN,
129 [MLX5_EXPANSION_OUTER_IPV4] = {
130 .next = RTE_FLOW_EXPAND_RSS_NEXT
131 (MLX5_EXPANSION_OUTER_IPV4_UDP,
132 MLX5_EXPANSION_OUTER_IPV4_TCP,
134 .type = RTE_FLOW_ITEM_TYPE_IPV4,
135 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
136 ETH_RSS_NONFRAG_IPV4_OTHER,
138 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
139 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
140 MLX5_EXPANSION_VXLAN_GPE),
141 .type = RTE_FLOW_ITEM_TYPE_UDP,
142 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
144 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
145 .type = RTE_FLOW_ITEM_TYPE_TCP,
146 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
148 [MLX5_EXPANSION_OUTER_IPV6] = {
149 .next = RTE_FLOW_EXPAND_RSS_NEXT
150 (MLX5_EXPANSION_OUTER_IPV6_UDP,
151 MLX5_EXPANSION_OUTER_IPV6_TCP),
152 .type = RTE_FLOW_ITEM_TYPE_IPV6,
153 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
154 ETH_RSS_NONFRAG_IPV6_OTHER,
156 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
157 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
158 MLX5_EXPANSION_VXLAN_GPE),
159 .type = RTE_FLOW_ITEM_TYPE_UDP,
160 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
162 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
163 .type = RTE_FLOW_ITEM_TYPE_TCP,
164 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
166 [MLX5_EXPANSION_VXLAN] = {
167 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
168 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
170 [MLX5_EXPANSION_VXLAN_GPE] = {
171 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
173 MLX5_EXPANSION_IPV6),
174 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
176 [MLX5_EXPANSION_GRE] = {
177 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
178 .type = RTE_FLOW_ITEM_TYPE_GRE,
180 [MLX5_EXPANSION_MPLS] = {
181 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
182 MLX5_EXPANSION_IPV6),
183 .type = RTE_FLOW_ITEM_TYPE_MPLS,
185 [MLX5_EXPANSION_ETH] = {
186 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
187 MLX5_EXPANSION_IPV6),
188 .type = RTE_FLOW_ITEM_TYPE_ETH,
190 [MLX5_EXPANSION_ETH_VLAN] = {
191 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
192 .type = RTE_FLOW_ITEM_TYPE_ETH,
194 [MLX5_EXPANSION_VLAN] = {
195 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
196 MLX5_EXPANSION_IPV6),
197 .type = RTE_FLOW_ITEM_TYPE_VLAN,
199 [MLX5_EXPANSION_IPV4] = {
200 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
201 MLX5_EXPANSION_IPV4_TCP),
202 .type = RTE_FLOW_ITEM_TYPE_IPV4,
203 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
204 ETH_RSS_NONFRAG_IPV4_OTHER,
206 [MLX5_EXPANSION_IPV4_UDP] = {
207 .type = RTE_FLOW_ITEM_TYPE_UDP,
208 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
210 [MLX5_EXPANSION_IPV4_TCP] = {
211 .type = RTE_FLOW_ITEM_TYPE_TCP,
212 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
214 [MLX5_EXPANSION_IPV6] = {
215 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
216 MLX5_EXPANSION_IPV6_TCP),
217 .type = RTE_FLOW_ITEM_TYPE_IPV6,
218 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
219 ETH_RSS_NONFRAG_IPV6_OTHER,
221 [MLX5_EXPANSION_IPV6_UDP] = {
222 .type = RTE_FLOW_ITEM_TYPE_UDP,
223 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
225 [MLX5_EXPANSION_IPV6_TCP] = {
226 .type = RTE_FLOW_ITEM_TYPE_TCP,
227 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
231 static const struct rte_flow_ops mlx5_flow_ops = {
232 .validate = mlx5_flow_validate,
233 .create = mlx5_flow_create,
234 .destroy = mlx5_flow_destroy,
235 .flush = mlx5_flow_flush,
236 .isolate = mlx5_flow_isolate,
237 .query = mlx5_flow_query,
240 /* Convert FDIR request to Generic flow. */
242 struct rte_flow_attr attr;
243 struct rte_flow_item items[4];
244 struct rte_flow_item_eth l2;
245 struct rte_flow_item_eth l2_mask;
247 struct rte_flow_item_ipv4 ipv4;
248 struct rte_flow_item_ipv6 ipv6;
251 struct rte_flow_item_ipv4 ipv4;
252 struct rte_flow_item_ipv6 ipv6;
255 struct rte_flow_item_udp udp;
256 struct rte_flow_item_tcp tcp;
259 struct rte_flow_item_udp udp;
260 struct rte_flow_item_tcp tcp;
262 struct rte_flow_action actions[2];
263 struct rte_flow_action_queue queue;
266 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
267 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
268 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
271 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
272 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
273 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
274 { 9, 10, 11 }, { 12, 13, 14 },
277 /* Tunnel information. */
278 struct mlx5_flow_tunnel_info {
279 uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
280 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
283 static struct mlx5_flow_tunnel_info tunnels_info[] = {
285 .tunnel = MLX5_FLOW_LAYER_VXLAN,
286 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
289 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
290 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
293 .tunnel = MLX5_FLOW_LAYER_GRE,
294 .ptype = RTE_PTYPE_TUNNEL_GRE,
297 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
298 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
301 .tunnel = MLX5_FLOW_LAYER_MPLS,
302 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
307 * Discover the maximum number of priority available.
310 * Pointer to the Ethernet device structure.
313 * number of supported flow priority on success, a negative errno
314 * value otherwise and rte_errno is set.
317 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
319 struct mlx5_priv *priv = dev->data->dev_private;
321 struct ibv_flow_attr attr;
322 struct ibv_flow_spec_eth eth;
323 struct ibv_flow_spec_action_drop drop;
327 .port = (uint8_t)priv->ibv_port,
330 .type = IBV_FLOW_SPEC_ETH,
331 .size = sizeof(struct ibv_flow_spec_eth),
334 .size = sizeof(struct ibv_flow_spec_action_drop),
335 .type = IBV_FLOW_SPEC_ACTION_DROP,
338 struct ibv_flow *flow;
339 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
340 uint16_t vprio[] = { 8, 16 };
348 for (i = 0; i != RTE_DIM(vprio); i++) {
349 flow_attr.attr.priority = vprio[i] - 1;
350 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
353 claim_zero(mlx5_glue->destroy_flow(flow));
356 mlx5_hrxq_drop_release(dev);
359 priority = RTE_DIM(priority_map_3);
362 priority = RTE_DIM(priority_map_5);
367 "port %u verbs maximum priority: %d expected 8/16",
368 dev->data->port_id, priority);
371 DRV_LOG(INFO, "port %u flow maximum priority: %d",
372 dev->data->port_id, priority);
377 * Adjust flow priority based on the highest layer and the request priority.
380 * Pointer to the Ethernet device structure.
381 * @param[in] priority
382 * The rule base priority.
383 * @param[in] subpriority
384 * The priority based on the items.
389 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
390 uint32_t subpriority)
393 struct mlx5_priv *priv = dev->data->dev_private;
395 switch (priv->config.flow_prio) {
396 case RTE_DIM(priority_map_3):
397 res = priority_map_3[priority][subpriority];
399 case RTE_DIM(priority_map_5):
400 res = priority_map_5[priority][subpriority];
407 * Verify the @p item specifications (spec, last, mask) are compatible with the
411 * Item specification.
413 * @p item->mask or flow default bit-masks.
414 * @param[in] nic_mask
415 * Bit-masks covering supported fields by the NIC to compare with user mask.
417 * Bit-masks size in bytes.
419 * Pointer to error structure.
422 * 0 on success, a negative errno value otherwise and rte_errno is set.
425 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
427 const uint8_t *nic_mask,
429 struct rte_flow_error *error)
434 for (i = 0; i < size; ++i)
435 if ((nic_mask[i] | mask[i]) != nic_mask[i])
436 return rte_flow_error_set(error, ENOTSUP,
437 RTE_FLOW_ERROR_TYPE_ITEM,
439 "mask enables non supported"
441 if (!item->spec && (item->mask || item->last))
442 return rte_flow_error_set(error, EINVAL,
443 RTE_FLOW_ERROR_TYPE_ITEM, item,
444 "mask/last without a spec is not"
446 if (item->spec && item->last) {
452 for (i = 0; i < size; ++i) {
453 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
454 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
456 ret = memcmp(spec, last, size);
458 return rte_flow_error_set(error, EINVAL,
459 RTE_FLOW_ERROR_TYPE_ITEM,
461 "range is not valid");
467 * Adjust the hash fields according to the @p flow information.
469 * @param[in] dev_flow.
470 * Pointer to the mlx5_flow.
472 * 1 when the hash field is for a tunnel item.
473 * @param[in] layer_types
475 * @param[in] hash_fields
479 * The hash fileds that should be used.
482 mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow,
483 int tunnel __rte_unused, uint64_t layer_types,
484 uint64_t hash_fields)
486 struct rte_flow *flow = dev_flow->flow;
487 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
488 int rss_request_inner = flow->rss.level >= 2;
490 /* Check RSS hash level for tunnel. */
491 if (tunnel && rss_request_inner)
492 hash_fields |= IBV_RX_HASH_INNER;
493 else if (tunnel || rss_request_inner)
496 /* Check if requested layer matches RSS hash fields. */
497 if (!(flow->rss.types & layer_types))
503 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
504 * if several tunnel rules are used on this queue, the tunnel ptype will be
508 * Rx queue to update.
511 flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
514 uint32_t tunnel_ptype = 0;
516 /* Look up for the ptype to use. */
517 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
518 if (!rxq_ctrl->flow_tunnels_n[i])
521 tunnel_ptype = tunnels_info[i].ptype;
527 rxq_ctrl->rxq.tunnel = tunnel_ptype;
531 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the devive
535 * Pointer to the Ethernet device structure.
536 * @param[in] dev_flow
537 * Pointer to device flow structure.
540 flow_drv_rxq_flags_set(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
542 struct mlx5_priv *priv = dev->data->dev_private;
543 struct rte_flow *flow = dev_flow->flow;
544 const int mark = !!(flow->actions &
545 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
546 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
549 for (i = 0; i != flow->rss.queue_num; ++i) {
550 int idx = (*flow->queue)[i];
551 struct mlx5_rxq_ctrl *rxq_ctrl =
552 container_of((*priv->rxqs)[idx],
553 struct mlx5_rxq_ctrl, rxq);
556 rxq_ctrl->rxq.mark = 1;
557 rxq_ctrl->flow_mark_n++;
562 /* Increase the counter matching the flow. */
563 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
564 if ((tunnels_info[j].tunnel &
566 tunnels_info[j].tunnel) {
567 rxq_ctrl->flow_tunnels_n[j]++;
571 flow_rxq_tunnel_ptype_update(rxq_ctrl);
577 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
580 * Pointer to the Ethernet device structure.
582 * Pointer to flow structure.
585 flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
587 struct mlx5_flow *dev_flow;
589 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
590 flow_drv_rxq_flags_set(dev, dev_flow);
594 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
595 * device flow if no other flow uses it with the same kind of request.
598 * Pointer to Ethernet device.
599 * @param[in] dev_flow
600 * Pointer to the device flow.
603 flow_drv_rxq_flags_trim(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow)
605 struct mlx5_priv *priv = dev->data->dev_private;
606 struct rte_flow *flow = dev_flow->flow;
607 const int mark = !!(flow->actions &
608 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
609 const int tunnel = !!(dev_flow->layers & MLX5_FLOW_LAYER_TUNNEL);
612 assert(dev->data->dev_started);
613 for (i = 0; i != flow->rss.queue_num; ++i) {
614 int idx = (*flow->queue)[i];
615 struct mlx5_rxq_ctrl *rxq_ctrl =
616 container_of((*priv->rxqs)[idx],
617 struct mlx5_rxq_ctrl, rxq);
620 rxq_ctrl->flow_mark_n--;
621 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
626 /* Decrease the counter matching the flow. */
627 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
628 if ((tunnels_info[j].tunnel &
630 tunnels_info[j].tunnel) {
631 rxq_ctrl->flow_tunnels_n[j]--;
635 flow_rxq_tunnel_ptype_update(rxq_ctrl);
641 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
642 * @p flow if no other flow uses it with the same kind of request.
645 * Pointer to Ethernet device.
647 * Pointer to the flow.
650 flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
652 struct mlx5_flow *dev_flow;
654 LIST_FOREACH(dev_flow, &flow->dev_flows, next)
655 flow_drv_rxq_flags_trim(dev, dev_flow);
659 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
662 * Pointer to Ethernet device.
665 flow_rxq_flags_clear(struct rte_eth_dev *dev)
667 struct mlx5_priv *priv = dev->data->dev_private;
670 for (i = 0; i != priv->rxqs_n; ++i) {
671 struct mlx5_rxq_ctrl *rxq_ctrl;
674 if (!(*priv->rxqs)[i])
676 rxq_ctrl = container_of((*priv->rxqs)[i],
677 struct mlx5_rxq_ctrl, rxq);
678 rxq_ctrl->flow_mark_n = 0;
679 rxq_ctrl->rxq.mark = 0;
680 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
681 rxq_ctrl->flow_tunnels_n[j] = 0;
682 rxq_ctrl->rxq.tunnel = 0;
687 * Validate the flag action.
689 * @param[in] action_flags
690 * Bit-fields that holds the actions detected until now.
692 * Attributes of flow that includes this action.
694 * Pointer to error structure.
697 * 0 on success, a negative errno value otherwise and rte_errno is set.
700 mlx5_flow_validate_action_flag(uint64_t action_flags,
701 const struct rte_flow_attr *attr,
702 struct rte_flow_error *error)
705 if (action_flags & MLX5_FLOW_ACTION_DROP)
706 return rte_flow_error_set(error, EINVAL,
707 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
708 "can't drop and flag in same flow");
709 if (action_flags & MLX5_FLOW_ACTION_MARK)
710 return rte_flow_error_set(error, EINVAL,
711 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
712 "can't mark and flag in same flow");
713 if (action_flags & MLX5_FLOW_ACTION_FLAG)
714 return rte_flow_error_set(error, EINVAL,
715 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
717 " actions in same flow");
719 return rte_flow_error_set(error, ENOTSUP,
720 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
721 "flag action not supported for "
727 * Validate the mark action.
730 * Pointer to the queue action.
731 * @param[in] action_flags
732 * Bit-fields that holds the actions detected until now.
734 * Attributes of flow that includes this action.
736 * Pointer to error structure.
739 * 0 on success, a negative errno value otherwise and rte_errno is set.
742 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
743 uint64_t action_flags,
744 const struct rte_flow_attr *attr,
745 struct rte_flow_error *error)
747 const struct rte_flow_action_mark *mark = action->conf;
750 return rte_flow_error_set(error, EINVAL,
751 RTE_FLOW_ERROR_TYPE_ACTION,
753 "configuration cannot be null");
754 if (mark->id >= MLX5_FLOW_MARK_MAX)
755 return rte_flow_error_set(error, EINVAL,
756 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
758 "mark id must in 0 <= id < "
759 RTE_STR(MLX5_FLOW_MARK_MAX));
760 if (action_flags & MLX5_FLOW_ACTION_DROP)
761 return rte_flow_error_set(error, EINVAL,
762 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
763 "can't drop and mark in same flow");
764 if (action_flags & MLX5_FLOW_ACTION_FLAG)
765 return rte_flow_error_set(error, EINVAL,
766 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
767 "can't flag and mark in same flow");
768 if (action_flags & MLX5_FLOW_ACTION_MARK)
769 return rte_flow_error_set(error, EINVAL,
770 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
771 "can't have 2 mark actions in same"
774 return rte_flow_error_set(error, ENOTSUP,
775 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
776 "mark action not supported for "
782 * Validate the drop action.
784 * @param[in] action_flags
785 * Bit-fields that holds the actions detected until now.
787 * Attributes of flow that includes this action.
789 * Pointer to error structure.
792 * 0 on success, a negative errno value otherwise and rte_errno is set.
795 mlx5_flow_validate_action_drop(uint64_t action_flags,
796 const struct rte_flow_attr *attr,
797 struct rte_flow_error *error)
799 if (action_flags & MLX5_FLOW_ACTION_FLAG)
800 return rte_flow_error_set(error, EINVAL,
801 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
802 "can't drop and flag in same flow");
803 if (action_flags & MLX5_FLOW_ACTION_MARK)
804 return rte_flow_error_set(error, EINVAL,
805 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
806 "can't drop and mark in same flow");
807 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
808 return rte_flow_error_set(error, EINVAL,
809 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
810 "can't have 2 fate actions in"
813 return rte_flow_error_set(error, ENOTSUP,
814 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
815 "drop action not supported for "
821 * Validate the queue action.
824 * Pointer to the queue action.
825 * @param[in] action_flags
826 * Bit-fields that holds the actions detected until now.
828 * Pointer to the Ethernet device structure.
830 * Attributes of flow that includes this action.
832 * Pointer to error structure.
835 * 0 on success, a negative errno value otherwise and rte_errno is set.
838 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
839 uint64_t action_flags,
840 struct rte_eth_dev *dev,
841 const struct rte_flow_attr *attr,
842 struct rte_flow_error *error)
844 struct mlx5_priv *priv = dev->data->dev_private;
845 const struct rte_flow_action_queue *queue = action->conf;
847 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
848 return rte_flow_error_set(error, EINVAL,
849 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
850 "can't have 2 fate actions in"
853 return rte_flow_error_set(error, EINVAL,
854 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
855 NULL, "No Rx queues configured");
856 if (queue->index >= priv->rxqs_n)
857 return rte_flow_error_set(error, EINVAL,
858 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
860 "queue index out of range");
861 if (!(*priv->rxqs)[queue->index])
862 return rte_flow_error_set(error, EINVAL,
863 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
865 "queue is not configured");
867 return rte_flow_error_set(error, ENOTSUP,
868 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
869 "queue action not supported for "
875 * Validate the rss action.
878 * Pointer to the queue action.
879 * @param[in] action_flags
880 * Bit-fields that holds the actions detected until now.
882 * Pointer to the Ethernet device structure.
884 * Attributes of flow that includes this action.
886 * Pointer to error structure.
889 * 0 on success, a negative errno value otherwise and rte_errno is set.
892 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
893 uint64_t action_flags,
894 struct rte_eth_dev *dev,
895 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;
902 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
903 return rte_flow_error_set(error, EINVAL,
904 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
905 "can't have 2 fate actions"
907 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
908 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
909 return rte_flow_error_set(error, ENOTSUP,
910 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
912 "RSS hash function not supported");
913 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
918 return rte_flow_error_set(error, ENOTSUP,
919 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
921 "tunnel RSS is not supported");
922 /* allow RSS key_len 0 in case of NULL (default) RSS key. */
923 if (rss->key_len == 0 && rss->key != NULL)
924 return rte_flow_error_set(error, ENOTSUP,
925 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
927 "RSS hash key length 0");
928 if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
929 return rte_flow_error_set(error, ENOTSUP,
930 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
932 "RSS hash key too small");
933 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
934 return rte_flow_error_set(error, ENOTSUP,
935 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
937 "RSS hash key too large");
938 if (rss->queue_num > priv->config.ind_table_max_size)
939 return rte_flow_error_set(error, ENOTSUP,
940 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
942 "number of queues too large");
943 if (rss->types & MLX5_RSS_HF_MASK)
944 return rte_flow_error_set(error, ENOTSUP,
945 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
947 "some RSS protocols are not"
950 return rte_flow_error_set(error, EINVAL,
951 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
952 NULL, "No Rx queues configured");
954 return rte_flow_error_set(error, EINVAL,
955 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
956 NULL, "No queues configured");
957 for (i = 0; i != rss->queue_num; ++i) {
958 if (!(*priv->rxqs)[rss->queue[i]])
959 return rte_flow_error_set
960 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
961 &rss->queue[i], "queue is not configured");
964 return rte_flow_error_set(error, ENOTSUP,
965 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
966 "rss action not supported for "
972 * Validate the count action.
975 * Pointer to the Ethernet device structure.
977 * Attributes of flow that includes this action.
979 * Pointer to error structure.
982 * 0 on success, a negative errno value otherwise and rte_errno is set.
985 mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
986 const struct rte_flow_attr *attr,
987 struct rte_flow_error *error)
990 return rte_flow_error_set(error, ENOTSUP,
991 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
992 "count action not supported for "
998 * Verify the @p attributes will be correctly understood by the NIC and store
999 * them in the @p flow if everything is correct.
1002 * Pointer to the Ethernet device structure.
1003 * @param[in] attributes
1004 * Pointer to flow attributes
1006 * Pointer to error structure.
1009 * 0 on success, a negative errno value otherwise and rte_errno is set.
1012 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1013 const struct rte_flow_attr *attributes,
1014 struct rte_flow_error *error)
1016 struct mlx5_priv *priv = dev->data->dev_private;
1017 uint32_t priority_max = priv->config.flow_prio - 1;
1019 if (attributes->group)
1020 return rte_flow_error_set(error, ENOTSUP,
1021 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1022 NULL, "groups is not supported");
1023 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
1024 attributes->priority >= priority_max)
1025 return rte_flow_error_set(error, ENOTSUP,
1026 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1027 NULL, "priority out of range");
1028 if (attributes->egress)
1029 return rte_flow_error_set(error, ENOTSUP,
1030 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1031 "egress is not supported");
1032 if (attributes->transfer)
1033 return rte_flow_error_set(error, ENOTSUP,
1034 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1035 NULL, "transfer is not supported");
1036 if (!attributes->ingress)
1037 return rte_flow_error_set(error, EINVAL,
1038 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1040 "ingress attribute is mandatory");
1045 * Validate Ethernet item.
1048 * Item specification.
1049 * @param[in] item_flags
1050 * Bit-fields that holds the items detected until now.
1052 * Pointer to error structure.
1055 * 0 on success, a negative errno value otherwise and rte_errno is set.
1058 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1059 uint64_t item_flags,
1060 struct rte_flow_error *error)
1062 const struct rte_flow_item_eth *mask = item->mask;
1063 const struct rte_flow_item_eth nic_mask = {
1064 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1065 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1066 .type = RTE_BE16(0xffff),
1069 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1070 const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1071 MLX5_FLOW_LAYER_OUTER_L2;
1073 if (item_flags & ethm)
1074 return rte_flow_error_set(error, ENOTSUP,
1075 RTE_FLOW_ERROR_TYPE_ITEM, item,
1076 "multiple L2 layers not supported");
1078 mask = &rte_flow_item_eth_mask;
1079 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1080 (const uint8_t *)&nic_mask,
1081 sizeof(struct rte_flow_item_eth),
1087 * Validate VLAN item.
1090 * Item specification.
1091 * @param[in] item_flags
1092 * Bit-fields that holds the items detected until now.
1094 * Pointer to error structure.
1097 * 0 on success, a negative errno value otherwise and rte_errno is set.
1100 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1101 uint64_t item_flags,
1102 struct rte_flow_error *error)
1104 const struct rte_flow_item_vlan *spec = item->spec;
1105 const struct rte_flow_item_vlan *mask = item->mask;
1106 const struct rte_flow_item_vlan nic_mask = {
1107 .tci = RTE_BE16(0x0fff),
1108 .inner_type = RTE_BE16(0xffff),
1110 uint16_t vlan_tag = 0;
1111 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1113 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1114 MLX5_FLOW_LAYER_INNER_L4) :
1115 (MLX5_FLOW_LAYER_OUTER_L3 |
1116 MLX5_FLOW_LAYER_OUTER_L4);
1117 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1118 MLX5_FLOW_LAYER_OUTER_VLAN;
1120 if (item_flags & vlanm)
1121 return rte_flow_error_set(error, EINVAL,
1122 RTE_FLOW_ERROR_TYPE_ITEM, item,
1123 "multiple VLAN layers not supported");
1124 else if ((item_flags & l34m) != 0)
1125 return rte_flow_error_set(error, EINVAL,
1126 RTE_FLOW_ERROR_TYPE_ITEM, item,
1127 "L2 layer cannot follow L3/L4 layer");
1129 mask = &rte_flow_item_vlan_mask;
1130 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1131 (const uint8_t *)&nic_mask,
1132 sizeof(struct rte_flow_item_vlan),
1137 vlan_tag = spec->tci;
1138 vlan_tag &= mask->tci;
1141 * From verbs perspective an empty VLAN is equivalent
1142 * to a packet without VLAN layer.
1145 return rte_flow_error_set(error, EINVAL,
1146 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1148 "VLAN cannot be empty");
1153 * Validate IPV4 item.
1156 * Item specification.
1157 * @param[in] item_flags
1158 * Bit-fields that holds the items detected until now.
1159 * @param[in] acc_mask
1160 * Acceptable mask, if NULL default internal default mask
1161 * will be used to check whether item fields are supported.
1163 * Pointer to error structure.
1166 * 0 on success, a negative errno value otherwise and rte_errno is set.
1169 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1170 uint64_t item_flags,
1171 const struct rte_flow_item_ipv4 *acc_mask,
1172 struct rte_flow_error *error)
1174 const struct rte_flow_item_ipv4 *mask = item->mask;
1175 const struct rte_flow_item_ipv4 nic_mask = {
1177 .src_addr = RTE_BE32(0xffffffff),
1178 .dst_addr = RTE_BE32(0xffffffff),
1179 .type_of_service = 0xff,
1180 .next_proto_id = 0xff,
1183 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1184 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1185 MLX5_FLOW_LAYER_OUTER_L3;
1186 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1187 MLX5_FLOW_LAYER_OUTER_L4;
1190 if (item_flags & l3m)
1191 return rte_flow_error_set(error, ENOTSUP,
1192 RTE_FLOW_ERROR_TYPE_ITEM, item,
1193 "multiple L3 layers not supported");
1194 else if (item_flags & l4m)
1195 return rte_flow_error_set(error, EINVAL,
1196 RTE_FLOW_ERROR_TYPE_ITEM, item,
1197 "L3 cannot follow an L4 layer.");
1199 mask = &rte_flow_item_ipv4_mask;
1200 else if (mask->hdr.next_proto_id != 0 &&
1201 mask->hdr.next_proto_id != 0xff)
1202 return rte_flow_error_set(error, EINVAL,
1203 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
1204 "partial mask is not supported"
1206 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1207 acc_mask ? (const uint8_t *)acc_mask
1208 : (const uint8_t *)&nic_mask,
1209 sizeof(struct rte_flow_item_ipv4),
1217 * Validate IPV6 item.
1220 * Item specification.
1221 * @param[in] item_flags
1222 * Bit-fields that holds the items detected until now.
1223 * @param[in] acc_mask
1224 * Acceptable mask, if NULL default internal default mask
1225 * will be used to check whether item fields are supported.
1227 * Pointer to error structure.
1230 * 0 on success, a negative errno value otherwise and rte_errno is set.
1233 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1234 uint64_t item_flags,
1235 const struct rte_flow_item_ipv6 *acc_mask,
1236 struct rte_flow_error *error)
1238 const struct rte_flow_item_ipv6 *mask = item->mask;
1239 const struct rte_flow_item_ipv6 nic_mask = {
1242 "\xff\xff\xff\xff\xff\xff\xff\xff"
1243 "\xff\xff\xff\xff\xff\xff\xff\xff",
1245 "\xff\xff\xff\xff\xff\xff\xff\xff"
1246 "\xff\xff\xff\xff\xff\xff\xff\xff",
1247 .vtc_flow = RTE_BE32(0xffffffff),
1252 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1253 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1254 MLX5_FLOW_LAYER_OUTER_L3;
1255 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1256 MLX5_FLOW_LAYER_OUTER_L4;
1259 if (item_flags & l3m)
1260 return rte_flow_error_set(error, ENOTSUP,
1261 RTE_FLOW_ERROR_TYPE_ITEM, item,
1262 "multiple L3 layers not supported");
1263 else if (item_flags & l4m)
1264 return rte_flow_error_set(error, EINVAL,
1265 RTE_FLOW_ERROR_TYPE_ITEM, item,
1266 "L3 cannot follow an L4 layer.");
1268 mask = &rte_flow_item_ipv6_mask;
1269 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1270 acc_mask ? (const uint8_t *)acc_mask
1271 : (const uint8_t *)&nic_mask,
1272 sizeof(struct rte_flow_item_ipv6),
1280 * Validate UDP item.
1283 * Item specification.
1284 * @param[in] item_flags
1285 * Bit-fields that holds the items detected until now.
1286 * @param[in] target_protocol
1287 * The next protocol in the previous item.
1288 * @param[in] flow_mask
1289 * mlx5 flow-specific (TCF, DV, verbs, etc.) supported header fields mask.
1291 * Pointer to error structure.
1294 * 0 on success, a negative errno value otherwise and rte_errno is set.
1297 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1298 uint64_t item_flags,
1299 uint8_t target_protocol,
1300 struct rte_flow_error *error)
1302 const struct rte_flow_item_udp *mask = item->mask;
1303 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1304 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1305 MLX5_FLOW_LAYER_OUTER_L3;
1306 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1307 MLX5_FLOW_LAYER_OUTER_L4;
1310 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1311 return rte_flow_error_set(error, EINVAL,
1312 RTE_FLOW_ERROR_TYPE_ITEM, item,
1313 "protocol filtering not compatible"
1315 if (!(item_flags & l3m))
1316 return rte_flow_error_set(error, EINVAL,
1317 RTE_FLOW_ERROR_TYPE_ITEM, item,
1318 "L3 is mandatory to filter on L4");
1319 if (item_flags & l4m)
1320 return rte_flow_error_set(error, EINVAL,
1321 RTE_FLOW_ERROR_TYPE_ITEM, item,
1322 "multiple L4 layers not supported");
1324 mask = &rte_flow_item_udp_mask;
1325 ret = mlx5_flow_item_acceptable
1326 (item, (const uint8_t *)mask,
1327 (const uint8_t *)&rte_flow_item_udp_mask,
1328 sizeof(struct rte_flow_item_udp), error);
1335 * Validate TCP item.
1338 * Item specification.
1339 * @param[in] item_flags
1340 * Bit-fields that holds the items detected until now.
1341 * @param[in] target_protocol
1342 * The next protocol in the previous item.
1344 * Pointer to error structure.
1347 * 0 on success, a negative errno value otherwise and rte_errno is set.
1350 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1351 uint64_t item_flags,
1352 uint8_t target_protocol,
1353 const struct rte_flow_item_tcp *flow_mask,
1354 struct rte_flow_error *error)
1356 const struct rte_flow_item_tcp *mask = item->mask;
1357 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1358 const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1359 MLX5_FLOW_LAYER_OUTER_L3;
1360 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1361 MLX5_FLOW_LAYER_OUTER_L4;
1365 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1366 return rte_flow_error_set(error, EINVAL,
1367 RTE_FLOW_ERROR_TYPE_ITEM, item,
1368 "protocol filtering not compatible"
1370 if (!(item_flags & l3m))
1371 return rte_flow_error_set(error, EINVAL,
1372 RTE_FLOW_ERROR_TYPE_ITEM, item,
1373 "L3 is mandatory to filter on L4");
1374 if (item_flags & l4m)
1375 return rte_flow_error_set(error, EINVAL,
1376 RTE_FLOW_ERROR_TYPE_ITEM, item,
1377 "multiple L4 layers not supported");
1379 mask = &rte_flow_item_tcp_mask;
1380 ret = mlx5_flow_item_acceptable
1381 (item, (const uint8_t *)mask,
1382 (const uint8_t *)flow_mask,
1383 sizeof(struct rte_flow_item_tcp), error);
1390 * Validate VXLAN item.
1393 * Item specification.
1394 * @param[in] item_flags
1395 * Bit-fields that holds the items detected until now.
1396 * @param[in] target_protocol
1397 * The next protocol in the previous item.
1399 * Pointer to error structure.
1402 * 0 on success, a negative errno value otherwise and rte_errno is set.
1405 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1406 uint64_t item_flags,
1407 struct rte_flow_error *error)
1409 const struct rte_flow_item_vxlan *spec = item->spec;
1410 const struct rte_flow_item_vxlan *mask = item->mask;
1415 } id = { .vlan_id = 0, };
1416 uint32_t vlan_id = 0;
1419 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1420 return rte_flow_error_set(error, ENOTSUP,
1421 RTE_FLOW_ERROR_TYPE_ITEM, item,
1422 "multiple tunnel layers not"
1425 * Verify only UDPv4 is present as defined in
1426 * https://tools.ietf.org/html/rfc7348
1428 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1429 return rte_flow_error_set(error, EINVAL,
1430 RTE_FLOW_ERROR_TYPE_ITEM, item,
1431 "no outer UDP layer found");
1433 mask = &rte_flow_item_vxlan_mask;
1434 ret = mlx5_flow_item_acceptable
1435 (item, (const uint8_t *)mask,
1436 (const uint8_t *)&rte_flow_item_vxlan_mask,
1437 sizeof(struct rte_flow_item_vxlan),
1442 memcpy(&id.vni[1], spec->vni, 3);
1443 vlan_id = id.vlan_id;
1444 memcpy(&id.vni[1], mask->vni, 3);
1445 vlan_id &= id.vlan_id;
1448 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1449 * only this layer is defined in the Verbs specification it is
1450 * interpreted as wildcard and all packets will match this
1451 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1452 * udp), all packets matching the layers before will also
1453 * match this rule. To avoid such situation, VNI 0 is
1454 * currently refused.
1457 return rte_flow_error_set(error, ENOTSUP,
1458 RTE_FLOW_ERROR_TYPE_ITEM, item,
1459 "VXLAN vni cannot be 0");
1460 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1461 return rte_flow_error_set(error, ENOTSUP,
1462 RTE_FLOW_ERROR_TYPE_ITEM, item,
1463 "VXLAN tunnel must be fully defined");
1468 * Validate VXLAN_GPE item.
1471 * Item specification.
1472 * @param[in] item_flags
1473 * Bit-fields that holds the items detected until now.
1475 * Pointer to the private data structure.
1476 * @param[in] target_protocol
1477 * The next protocol in the previous item.
1479 * Pointer to error structure.
1482 * 0 on success, a negative errno value otherwise and rte_errno is set.
1485 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1486 uint64_t item_flags,
1487 struct rte_eth_dev *dev,
1488 struct rte_flow_error *error)
1490 struct mlx5_priv *priv = dev->data->dev_private;
1491 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1492 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1497 } id = { .vlan_id = 0, };
1498 uint32_t vlan_id = 0;
1500 if (!priv->config.l3_vxlan_en)
1501 return rte_flow_error_set(error, ENOTSUP,
1502 RTE_FLOW_ERROR_TYPE_ITEM, item,
1503 "L3 VXLAN is not enabled by device"
1504 " parameter and/or not configured in"
1506 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1507 return rte_flow_error_set(error, ENOTSUP,
1508 RTE_FLOW_ERROR_TYPE_ITEM, item,
1509 "multiple tunnel layers not"
1512 * Verify only UDPv4 is present as defined in
1513 * https://tools.ietf.org/html/rfc7348
1515 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1516 return rte_flow_error_set(error, EINVAL,
1517 RTE_FLOW_ERROR_TYPE_ITEM, item,
1518 "no outer UDP layer found");
1520 mask = &rte_flow_item_vxlan_gpe_mask;
1521 ret = mlx5_flow_item_acceptable
1522 (item, (const uint8_t *)mask,
1523 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1524 sizeof(struct rte_flow_item_vxlan_gpe),
1530 return rte_flow_error_set(error, ENOTSUP,
1531 RTE_FLOW_ERROR_TYPE_ITEM,
1533 "VxLAN-GPE protocol"
1535 memcpy(&id.vni[1], spec->vni, 3);
1536 vlan_id = id.vlan_id;
1537 memcpy(&id.vni[1], mask->vni, 3);
1538 vlan_id &= id.vlan_id;
1541 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1542 * layer is defined in the Verbs specification it is interpreted as
1543 * wildcard and all packets will match this rule, if it follows a full
1544 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1545 * before will also match this rule. To avoid such situation, VNI 0
1546 * is currently refused.
1549 return rte_flow_error_set(error, ENOTSUP,
1550 RTE_FLOW_ERROR_TYPE_ITEM, item,
1551 "VXLAN-GPE vni cannot be 0");
1552 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1553 return rte_flow_error_set(error, ENOTSUP,
1554 RTE_FLOW_ERROR_TYPE_ITEM, item,
1555 "VXLAN-GPE tunnel must be fully"
1561 * Validate GRE item.
1564 * Item specification.
1565 * @param[in] item_flags
1566 * Bit flags to mark detected items.
1567 * @param[in] target_protocol
1568 * The next protocol in the previous item.
1570 * Pointer to error structure.
1573 * 0 on success, a negative errno value otherwise and rte_errno is set.
1576 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
1577 uint64_t item_flags,
1578 uint8_t target_protocol,
1579 struct rte_flow_error *error)
1581 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
1582 const struct rte_flow_item_gre *mask = item->mask;
1585 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
1586 return rte_flow_error_set(error, EINVAL,
1587 RTE_FLOW_ERROR_TYPE_ITEM, item,
1588 "protocol filtering not compatible"
1589 " with this GRE layer");
1590 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1591 return rte_flow_error_set(error, ENOTSUP,
1592 RTE_FLOW_ERROR_TYPE_ITEM, item,
1593 "multiple tunnel layers not"
1595 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
1596 return rte_flow_error_set(error, ENOTSUP,
1597 RTE_FLOW_ERROR_TYPE_ITEM, item,
1598 "L3 Layer is missing");
1600 mask = &rte_flow_item_gre_mask;
1601 ret = mlx5_flow_item_acceptable
1602 (item, (const uint8_t *)mask,
1603 (const uint8_t *)&rte_flow_item_gre_mask,
1604 sizeof(struct rte_flow_item_gre), error);
1607 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
1608 if (spec && (spec->protocol & mask->protocol))
1609 return rte_flow_error_set(error, ENOTSUP,
1610 RTE_FLOW_ERROR_TYPE_ITEM, item,
1611 "without MPLS support the"
1612 " specification cannot be used for"
1619 * Validate MPLS item.
1622 * Pointer to the rte_eth_dev structure.
1624 * Item specification.
1625 * @param[in] item_flags
1626 * Bit-fields that holds the items detected until now.
1627 * @param[in] prev_layer
1628 * The protocol layer indicated in previous item.
1630 * Pointer to error structure.
1633 * 0 on success, a negative errno value otherwise and rte_errno is set.
1636 mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
1637 const struct rte_flow_item *item __rte_unused,
1638 uint64_t item_flags __rte_unused,
1639 uint64_t prev_layer __rte_unused,
1640 struct rte_flow_error *error)
1642 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
1643 const struct rte_flow_item_mpls *mask = item->mask;
1644 struct mlx5_priv *priv = dev->data->dev_private;
1647 if (!priv->config.mpls_en)
1648 return rte_flow_error_set(error, ENOTSUP,
1649 RTE_FLOW_ERROR_TYPE_ITEM, item,
1650 "MPLS not supported or"
1651 " disabled in firmware"
1653 /* MPLS over IP, UDP, GRE is allowed */
1654 if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L3 |
1655 MLX5_FLOW_LAYER_OUTER_L4_UDP |
1656 MLX5_FLOW_LAYER_GRE)))
1657 return rte_flow_error_set(error, EINVAL,
1658 RTE_FLOW_ERROR_TYPE_ITEM, item,
1659 "protocol filtering not compatible"
1660 " with MPLS layer");
1661 /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
1662 if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
1663 !(item_flags & MLX5_FLOW_LAYER_GRE))
1664 return rte_flow_error_set(error, ENOTSUP,
1665 RTE_FLOW_ERROR_TYPE_ITEM, item,
1666 "multiple tunnel layers not"
1669 mask = &rte_flow_item_mpls_mask;
1670 ret = mlx5_flow_item_acceptable
1671 (item, (const uint8_t *)mask,
1672 (const uint8_t *)&rte_flow_item_mpls_mask,
1673 sizeof(struct rte_flow_item_mpls), error);
1678 return rte_flow_error_set(error, ENOTSUP,
1679 RTE_FLOW_ERROR_TYPE_ITEM, item,
1680 "MPLS is not supported by Verbs, please"
1685 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
1686 const struct rte_flow_attr *attr __rte_unused,
1687 const struct rte_flow_item items[] __rte_unused,
1688 const struct rte_flow_action actions[] __rte_unused,
1689 struct rte_flow_error *error __rte_unused)
1691 rte_errno = ENOTSUP;
1695 static struct mlx5_flow *
1696 flow_null_prepare(const struct rte_flow_attr *attr __rte_unused,
1697 const struct rte_flow_item items[] __rte_unused,
1698 const struct rte_flow_action actions[] __rte_unused,
1699 struct rte_flow_error *error __rte_unused)
1701 rte_errno = ENOTSUP;
1706 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
1707 struct mlx5_flow *dev_flow __rte_unused,
1708 const struct rte_flow_attr *attr __rte_unused,
1709 const struct rte_flow_item items[] __rte_unused,
1710 const struct rte_flow_action actions[] __rte_unused,
1711 struct rte_flow_error *error __rte_unused)
1713 rte_errno = ENOTSUP;
1718 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
1719 struct rte_flow *flow __rte_unused,
1720 struct rte_flow_error *error __rte_unused)
1722 rte_errno = ENOTSUP;
1727 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
1728 struct rte_flow *flow __rte_unused)
1733 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
1734 struct rte_flow *flow __rte_unused)
1739 flow_null_query(struct rte_eth_dev *dev __rte_unused,
1740 struct rte_flow *flow __rte_unused,
1741 const struct rte_flow_action *actions __rte_unused,
1742 void *data __rte_unused,
1743 struct rte_flow_error *error __rte_unused)
1745 rte_errno = ENOTSUP;
1749 /* Void driver to protect from null pointer reference. */
1750 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
1751 .validate = flow_null_validate,
1752 .prepare = flow_null_prepare,
1753 .translate = flow_null_translate,
1754 .apply = flow_null_apply,
1755 .remove = flow_null_remove,
1756 .destroy = flow_null_destroy,
1757 .query = flow_null_query,
1761 * Select flow driver type according to flow attributes and device
1765 * Pointer to the dev structure.
1767 * Pointer to the flow attributes.
1770 * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
1772 static enum mlx5_flow_drv_type
1773 flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
1775 struct mlx5_priv *priv = dev->data->dev_private;
1776 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
1779 type = MLX5_FLOW_TYPE_TCF;
1781 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
1782 MLX5_FLOW_TYPE_VERBS;
1786 #define flow_get_drv_ops(type) flow_drv_ops[type]
1789 * Flow driver validation API. This abstracts calling driver specific functions.
1790 * The type of flow driver is determined according to flow attributes.
1793 * Pointer to the dev structure.
1795 * Pointer to the flow attributes.
1797 * Pointer to the list of items.
1798 * @param[in] actions
1799 * Pointer to the list of actions.
1801 * Pointer to the error structure.
1804 * 0 on success, a negative errno value otherwise and rte_errno is set.
1807 flow_drv_validate(struct rte_eth_dev *dev,
1808 const struct rte_flow_attr *attr,
1809 const struct rte_flow_item items[],
1810 const struct rte_flow_action actions[],
1811 struct rte_flow_error *error)
1813 const struct mlx5_flow_driver_ops *fops;
1814 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
1816 fops = flow_get_drv_ops(type);
1817 return fops->validate(dev, attr, items, actions, error);
1821 * Flow driver preparation API. This abstracts calling driver specific
1822 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
1823 * calculates the size of memory required for device flow, allocates the memory,
1824 * initializes the device flow and returns the pointer.
1827 * This function initializes device flow structure such as dv, tcf or verbs in
1828 * struct mlx5_flow. However, it is caller's responsibility to initialize the
1829 * rest. For example, adding returning device flow to flow->dev_flow list and
1830 * setting backward reference to the flow should be done out of this function.
1831 * layers field is not filled either.
1834 * Pointer to the flow attributes.
1836 * Pointer to the list of items.
1837 * @param[in] actions
1838 * Pointer to the list of actions.
1840 * Pointer to the error structure.
1843 * Pointer to device flow on success, otherwise NULL and rte_errno is set.
1845 static inline struct mlx5_flow *
1846 flow_drv_prepare(const struct rte_flow *flow,
1847 const struct rte_flow_attr *attr,
1848 const struct rte_flow_item items[],
1849 const struct rte_flow_action actions[],
1850 struct rte_flow_error *error)
1852 const struct mlx5_flow_driver_ops *fops;
1853 enum mlx5_flow_drv_type type = flow->drv_type;
1855 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1856 fops = flow_get_drv_ops(type);
1857 return fops->prepare(attr, items, actions, error);
1861 * Flow driver translation API. This abstracts calling driver specific
1862 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
1863 * translates a generic flow into a driver flow. flow_drv_prepare() must
1867 * dev_flow->layers could be filled as a result of parsing during translation
1868 * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
1869 * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
1870 * flow->actions could be overwritten even though all the expanded dev_flows
1871 * have the same actions.
1874 * Pointer to the rte dev structure.
1875 * @param[in, out] dev_flow
1876 * Pointer to the mlx5 flow.
1878 * Pointer to the flow attributes.
1880 * Pointer to the list of items.
1881 * @param[in] actions
1882 * Pointer to the list of actions.
1884 * Pointer to the error structure.
1887 * 0 on success, a negative errno value otherwise and rte_errno is set.
1890 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
1891 const struct rte_flow_attr *attr,
1892 const struct rte_flow_item items[],
1893 const struct rte_flow_action actions[],
1894 struct rte_flow_error *error)
1896 const struct mlx5_flow_driver_ops *fops;
1897 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
1899 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1900 fops = flow_get_drv_ops(type);
1901 return fops->translate(dev, dev_flow, attr, items, actions, error);
1905 * Flow driver apply API. This abstracts calling driver specific functions.
1906 * Parent flow (rte_flow) should have driver type (drv_type). It applies
1907 * translated driver flows on to device. flow_drv_translate() must precede.
1910 * Pointer to Ethernet device structure.
1911 * @param[in, out] flow
1912 * Pointer to flow structure.
1914 * Pointer to error structure.
1917 * 0 on success, a negative errno value otherwise and rte_errno is set.
1920 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
1921 struct rte_flow_error *error)
1923 const struct mlx5_flow_driver_ops *fops;
1924 enum mlx5_flow_drv_type type = flow->drv_type;
1926 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1927 fops = flow_get_drv_ops(type);
1928 return fops->apply(dev, flow, error);
1932 * Flow driver remove API. This abstracts calling driver specific functions.
1933 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
1934 * on device. All the resources of the flow should be freed by calling
1935 * flow_drv_destroy().
1938 * Pointer to Ethernet device.
1939 * @param[in, out] flow
1940 * Pointer to flow structure.
1943 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
1945 const struct mlx5_flow_driver_ops *fops;
1946 enum mlx5_flow_drv_type type = flow->drv_type;
1948 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1949 fops = flow_get_drv_ops(type);
1950 fops->remove(dev, flow);
1954 * Flow driver destroy API. This abstracts calling driver specific functions.
1955 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
1956 * on device and releases resources of the flow.
1959 * Pointer to Ethernet device.
1960 * @param[in, out] flow
1961 * Pointer to flow structure.
1964 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
1966 const struct mlx5_flow_driver_ops *fops;
1967 enum mlx5_flow_drv_type type = flow->drv_type;
1969 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1970 fops = flow_get_drv_ops(type);
1971 fops->destroy(dev, flow);
1975 * Validate a flow supported by the NIC.
1977 * @see rte_flow_validate()
1981 mlx5_flow_validate(struct rte_eth_dev *dev,
1982 const struct rte_flow_attr *attr,
1983 const struct rte_flow_item items[],
1984 const struct rte_flow_action actions[],
1985 struct rte_flow_error *error)
1989 ret = flow_drv_validate(dev, attr, items, actions, error);
1996 * Get RSS action from the action list.
1998 * @param[in] actions
1999 * Pointer to the list of actions.
2002 * Pointer to the RSS action if exist, else return NULL.
2004 static const struct rte_flow_action_rss*
2005 flow_get_rss_action(const struct rte_flow_action actions[])
2007 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2008 switch (actions->type) {
2009 case RTE_FLOW_ACTION_TYPE_RSS:
2010 return (const struct rte_flow_action_rss *)
2020 find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
2022 const struct rte_flow_item *item;
2023 unsigned int has_vlan = 0;
2025 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2026 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2032 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
2033 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
2034 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
2035 MLX5_EXPANSION_ROOT_OUTER;
2039 * Create a flow and add it to @p list.
2042 * Pointer to Ethernet device.
2044 * Pointer to a TAILQ flow list.
2046 * Flow rule attributes.
2048 * Pattern specification (list terminated by the END pattern item).
2049 * @param[in] actions
2050 * Associated actions (list terminated by the END action).
2052 * Perform verbose error reporting if not NULL.
2055 * A flow on success, NULL otherwise and rte_errno is set.
2057 static struct rte_flow *
2058 flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list,
2059 const struct rte_flow_attr *attr,
2060 const struct rte_flow_item items[],
2061 const struct rte_flow_action actions[],
2062 struct rte_flow_error *error)
2064 struct rte_flow *flow = NULL;
2065 struct mlx5_flow *dev_flow;
2066 const struct rte_flow_action_rss *rss;
2068 struct rte_flow_expand_rss buf;
2069 uint8_t buffer[2048];
2071 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
2076 ret = flow_drv_validate(dev, attr, items, actions, error);
2079 flow_size = sizeof(struct rte_flow);
2080 rss = flow_get_rss_action(actions);
2082 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
2085 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
2086 flow = rte_calloc(__func__, 1, flow_size, 0);
2087 flow->drv_type = flow_get_drv_type(dev, attr);
2088 flow->ingress = attr->ingress;
2089 assert(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
2090 flow->drv_type < MLX5_FLOW_TYPE_MAX);
2091 flow->queue = (void *)(flow + 1);
2092 LIST_INIT(&flow->dev_flows);
2093 if (rss && rss->types) {
2094 unsigned int graph_root;
2096 graph_root = find_graph_root(items, rss->level);
2097 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
2099 mlx5_support_expansion,
2102 (unsigned int)ret < sizeof(expand_buffer.buffer));
2105 buf->entry[0].pattern = (void *)(uintptr_t)items;
2107 for (i = 0; i < buf->entries; ++i) {
2108 dev_flow = flow_drv_prepare(flow, attr, buf->entry[i].pattern,
2112 dev_flow->flow = flow;
2113 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
2114 ret = flow_drv_translate(dev, dev_flow, attr,
2115 buf->entry[i].pattern,
2120 if (dev->data->dev_started) {
2121 ret = flow_drv_apply(dev, flow, error);
2125 TAILQ_INSERT_TAIL(list, flow, next);
2126 flow_rxq_flags_set(dev, flow);
2129 ret = rte_errno; /* Save rte_errno before cleanup. */
2131 flow_drv_destroy(dev, flow);
2133 rte_errno = ret; /* Restore rte_errno. */
2140 * @see rte_flow_create()
2144 mlx5_flow_create(struct rte_eth_dev *dev,
2145 const struct rte_flow_attr *attr,
2146 const struct rte_flow_item items[],
2147 const struct rte_flow_action actions[],
2148 struct rte_flow_error *error)
2150 struct mlx5_priv *priv = (struct mlx5_priv *)dev->data->dev_private;
2152 return flow_list_create(dev, &priv->flows,
2153 attr, items, actions, error);
2157 * Destroy a flow in a list.
2160 * Pointer to Ethernet device.
2162 * Pointer to a TAILQ flow list.
2167 flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
2168 struct rte_flow *flow)
2171 * Update RX queue flags only if port is started, otherwise it is
2174 if (dev->data->dev_started)
2175 flow_rxq_flags_trim(dev, flow);
2176 flow_drv_destroy(dev, flow);
2177 TAILQ_REMOVE(list, flow, next);
2178 rte_free(flow->fdir);
2183 * Destroy all flows.
2186 * Pointer to Ethernet device.
2188 * Pointer to a TAILQ flow list.
2191 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
2193 while (!TAILQ_EMPTY(list)) {
2194 struct rte_flow *flow;
2196 flow = TAILQ_FIRST(list);
2197 flow_list_destroy(dev, list, flow);
2205 * Pointer to Ethernet device.
2207 * Pointer to a TAILQ flow list.
2210 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
2212 struct rte_flow *flow;
2214 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next)
2215 flow_drv_remove(dev, flow);
2216 flow_rxq_flags_clear(dev);
2223 * Pointer to Ethernet device.
2225 * Pointer to a TAILQ flow list.
2228 * 0 on success, a negative errno value otherwise and rte_errno is set.
2231 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
2233 struct rte_flow *flow;
2234 struct rte_flow_error error;
2237 TAILQ_FOREACH(flow, list, next) {
2238 ret = flow_drv_apply(dev, flow, &error);
2241 flow_rxq_flags_set(dev, flow);
2245 ret = rte_errno; /* Save rte_errno before cleanup. */
2246 mlx5_flow_stop(dev, list);
2247 rte_errno = ret; /* Restore rte_errno. */
2252 * Verify the flow list is empty
2255 * Pointer to Ethernet device.
2257 * @return the number of flows not released.
2260 mlx5_flow_verify(struct rte_eth_dev *dev)
2262 struct mlx5_priv *priv = dev->data->dev_private;
2263 struct rte_flow *flow;
2266 TAILQ_FOREACH(flow, &priv->flows, next) {
2267 DRV_LOG(DEBUG, "port %u flow %p still referenced",
2268 dev->data->port_id, (void *)flow);
2275 * Enable a control flow configured from the control plane.
2278 * Pointer to Ethernet device.
2280 * An Ethernet flow spec to apply.
2282 * An Ethernet flow mask to apply.
2284 * A VLAN flow spec to apply.
2286 * A VLAN flow mask to apply.
2289 * 0 on success, a negative errno value otherwise and rte_errno is set.
2292 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
2293 struct rte_flow_item_eth *eth_spec,
2294 struct rte_flow_item_eth *eth_mask,
2295 struct rte_flow_item_vlan *vlan_spec,
2296 struct rte_flow_item_vlan *vlan_mask)
2298 struct mlx5_priv *priv = dev->data->dev_private;
2299 const struct rte_flow_attr attr = {
2301 .priority = MLX5_FLOW_PRIO_RSVD,
2303 struct rte_flow_item items[] = {
2305 .type = RTE_FLOW_ITEM_TYPE_ETH,
2311 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
2312 RTE_FLOW_ITEM_TYPE_END,
2318 .type = RTE_FLOW_ITEM_TYPE_END,
2321 uint16_t queue[priv->reta_idx_n];
2322 struct rte_flow_action_rss action_rss = {
2323 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
2325 .types = priv->rss_conf.rss_hf,
2326 .key_len = priv->rss_conf.rss_key_len,
2327 .queue_num = priv->reta_idx_n,
2328 .key = priv->rss_conf.rss_key,
2331 struct rte_flow_action actions[] = {
2333 .type = RTE_FLOW_ACTION_TYPE_RSS,
2334 .conf = &action_rss,
2337 .type = RTE_FLOW_ACTION_TYPE_END,
2340 struct rte_flow *flow;
2341 struct rte_flow_error error;
2344 if (!priv->reta_idx_n || !priv->rxqs_n) {
2347 for (i = 0; i != priv->reta_idx_n; ++i)
2348 queue[i] = (*priv->reta_idx)[i];
2349 flow = flow_list_create(dev, &priv->ctrl_flows,
2350 &attr, items, actions, &error);
2357 * Enable a flow control configured from the control plane.
2360 * Pointer to Ethernet device.
2362 * An Ethernet flow spec to apply.
2364 * An Ethernet flow mask to apply.
2367 * 0 on success, a negative errno value otherwise and rte_errno is set.
2370 mlx5_ctrl_flow(struct rte_eth_dev *dev,
2371 struct rte_flow_item_eth *eth_spec,
2372 struct rte_flow_item_eth *eth_mask)
2374 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
2380 * @see rte_flow_destroy()
2384 mlx5_flow_destroy(struct rte_eth_dev *dev,
2385 struct rte_flow *flow,
2386 struct rte_flow_error *error __rte_unused)
2388 struct mlx5_priv *priv = dev->data->dev_private;
2390 flow_list_destroy(dev, &priv->flows, flow);
2395 * Destroy all flows.
2397 * @see rte_flow_flush()
2401 mlx5_flow_flush(struct rte_eth_dev *dev,
2402 struct rte_flow_error *error __rte_unused)
2404 struct mlx5_priv *priv = dev->data->dev_private;
2406 mlx5_flow_list_flush(dev, &priv->flows);
2413 * @see rte_flow_isolate()
2417 mlx5_flow_isolate(struct rte_eth_dev *dev,
2419 struct rte_flow_error *error)
2421 struct mlx5_priv *priv = dev->data->dev_private;
2423 if (dev->data->dev_started) {
2424 rte_flow_error_set(error, EBUSY,
2425 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2427 "port must be stopped first");
2430 priv->isolated = !!enable;
2432 dev->dev_ops = &mlx5_dev_ops_isolate;
2434 dev->dev_ops = &mlx5_dev_ops;
2441 * @see rte_flow_query()
2445 flow_drv_query(struct rte_eth_dev *dev,
2446 struct rte_flow *flow,
2447 const struct rte_flow_action *actions,
2449 struct rte_flow_error *error)
2451 const struct mlx5_flow_driver_ops *fops;
2452 enum mlx5_flow_drv_type ftype = flow->drv_type;
2454 assert(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
2455 fops = flow_get_drv_ops(ftype);
2457 return fops->query(dev, flow, actions, data, error);
2463 * @see rte_flow_query()
2467 mlx5_flow_query(struct rte_eth_dev *dev,
2468 struct rte_flow *flow,
2469 const struct rte_flow_action *actions,
2471 struct rte_flow_error *error)
2475 ret = flow_drv_query(dev, flow, actions, data, error);
2482 * Convert a flow director filter to a generic flow.
2485 * Pointer to Ethernet device.
2486 * @param fdir_filter
2487 * Flow director filter to add.
2489 * Generic flow parameters structure.
2492 * 0 on success, a negative errno value otherwise and rte_errno is set.
2495 flow_fdir_filter_convert(struct rte_eth_dev *dev,
2496 const struct rte_eth_fdir_filter *fdir_filter,
2497 struct mlx5_fdir *attributes)
2499 struct mlx5_priv *priv = dev->data->dev_private;
2500 const struct rte_eth_fdir_input *input = &fdir_filter->input;
2501 const struct rte_eth_fdir_masks *mask =
2502 &dev->data->dev_conf.fdir_conf.mask;
2504 /* Validate queue number. */
2505 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
2506 DRV_LOG(ERR, "port %u invalid queue number %d",
2507 dev->data->port_id, fdir_filter->action.rx_queue);
2511 attributes->attr.ingress = 1;
2512 attributes->items[0] = (struct rte_flow_item) {
2513 .type = RTE_FLOW_ITEM_TYPE_ETH,
2514 .spec = &attributes->l2,
2515 .mask = &attributes->l2_mask,
2517 switch (fdir_filter->action.behavior) {
2518 case RTE_ETH_FDIR_ACCEPT:
2519 attributes->actions[0] = (struct rte_flow_action){
2520 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
2521 .conf = &attributes->queue,
2524 case RTE_ETH_FDIR_REJECT:
2525 attributes->actions[0] = (struct rte_flow_action){
2526 .type = RTE_FLOW_ACTION_TYPE_DROP,
2530 DRV_LOG(ERR, "port %u invalid behavior %d",
2532 fdir_filter->action.behavior);
2533 rte_errno = ENOTSUP;
2536 attributes->queue.index = fdir_filter->action.rx_queue;
2538 switch (fdir_filter->input.flow_type) {
2539 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2540 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2541 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2542 attributes->l3.ipv4.hdr = (struct ipv4_hdr){
2543 .src_addr = input->flow.ip4_flow.src_ip,
2544 .dst_addr = input->flow.ip4_flow.dst_ip,
2545 .time_to_live = input->flow.ip4_flow.ttl,
2546 .type_of_service = input->flow.ip4_flow.tos,
2548 attributes->l3_mask.ipv4.hdr = (struct ipv4_hdr){
2549 .src_addr = mask->ipv4_mask.src_ip,
2550 .dst_addr = mask->ipv4_mask.dst_ip,
2551 .time_to_live = mask->ipv4_mask.ttl,
2552 .type_of_service = mask->ipv4_mask.tos,
2553 .next_proto_id = mask->ipv4_mask.proto,
2555 attributes->items[1] = (struct rte_flow_item){
2556 .type = RTE_FLOW_ITEM_TYPE_IPV4,
2557 .spec = &attributes->l3,
2558 .mask = &attributes->l3_mask,
2561 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2562 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2563 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2564 attributes->l3.ipv6.hdr = (struct ipv6_hdr){
2565 .hop_limits = input->flow.ipv6_flow.hop_limits,
2566 .proto = input->flow.ipv6_flow.proto,
2569 memcpy(attributes->l3.ipv6.hdr.src_addr,
2570 input->flow.ipv6_flow.src_ip,
2571 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2572 memcpy(attributes->l3.ipv6.hdr.dst_addr,
2573 input->flow.ipv6_flow.dst_ip,
2574 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2575 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
2576 mask->ipv6_mask.src_ip,
2577 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2578 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
2579 mask->ipv6_mask.dst_ip,
2580 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2581 attributes->items[1] = (struct rte_flow_item){
2582 .type = RTE_FLOW_ITEM_TYPE_IPV6,
2583 .spec = &attributes->l3,
2584 .mask = &attributes->l3_mask,
2588 DRV_LOG(ERR, "port %u invalid flow type%d",
2589 dev->data->port_id, fdir_filter->input.flow_type);
2590 rte_errno = ENOTSUP;
2594 switch (fdir_filter->input.flow_type) {
2595 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2596 attributes->l4.udp.hdr = (struct udp_hdr){
2597 .src_port = input->flow.udp4_flow.src_port,
2598 .dst_port = input->flow.udp4_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_IPV4_TCP:
2611 attributes->l4.tcp.hdr = (struct tcp_hdr){
2612 .src_port = input->flow.tcp4_flow.src_port,
2613 .dst_port = input->flow.tcp4_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_IPV6_UDP:
2626 attributes->l4.udp.hdr = (struct udp_hdr){
2627 .src_port = input->flow.udp6_flow.src_port,
2628 .dst_port = input->flow.udp6_flow.dst_port,
2630 attributes->l4_mask.udp.hdr = (struct udp_hdr){
2631 .src_port = mask->src_port_mask,
2632 .dst_port = mask->dst_port_mask,
2634 attributes->items[2] = (struct rte_flow_item){
2635 .type = RTE_FLOW_ITEM_TYPE_UDP,
2636 .spec = &attributes->l4,
2637 .mask = &attributes->l4_mask,
2640 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2641 attributes->l4.tcp.hdr = (struct tcp_hdr){
2642 .src_port = input->flow.tcp6_flow.src_port,
2643 .dst_port = input->flow.tcp6_flow.dst_port,
2645 attributes->l4_mask.tcp.hdr = (struct tcp_hdr){
2646 .src_port = mask->src_port_mask,
2647 .dst_port = mask->dst_port_mask,
2649 attributes->items[2] = (struct rte_flow_item){
2650 .type = RTE_FLOW_ITEM_TYPE_TCP,
2651 .spec = &attributes->l4,
2652 .mask = &attributes->l4_mask,
2655 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2656 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2659 DRV_LOG(ERR, "port %u invalid flow type%d",
2660 dev->data->port_id, fdir_filter->input.flow_type);
2661 rte_errno = ENOTSUP;
2667 #define FLOW_FDIR_CMP(f1, f2, fld) \
2668 memcmp(&(f1)->fld, &(f2)->fld, sizeof(f1->fld))
2671 * Compare two FDIR flows. If items and actions are identical, the two flows are
2675 * Pointer to Ethernet device.
2677 * FDIR flow to compare.
2679 * FDIR flow to compare.
2682 * Zero on match, 1 otherwise.
2685 flow_fdir_cmp(const struct mlx5_fdir *f1, const struct mlx5_fdir *f2)
2687 if (FLOW_FDIR_CMP(f1, f2, attr) ||
2688 FLOW_FDIR_CMP(f1, f2, l2) ||
2689 FLOW_FDIR_CMP(f1, f2, l2_mask) ||
2690 FLOW_FDIR_CMP(f1, f2, l3) ||
2691 FLOW_FDIR_CMP(f1, f2, l3_mask) ||
2692 FLOW_FDIR_CMP(f1, f2, l4) ||
2693 FLOW_FDIR_CMP(f1, f2, l4_mask) ||
2694 FLOW_FDIR_CMP(f1, f2, actions[0].type))
2696 if (f1->actions[0].type == RTE_FLOW_ACTION_TYPE_QUEUE &&
2697 FLOW_FDIR_CMP(f1, f2, queue))
2703 * Search device flow list to find out a matched FDIR flow.
2706 * Pointer to Ethernet device.
2708 * FDIR flow to lookup.
2711 * Pointer of flow if found, NULL otherwise.
2713 static struct rte_flow *
2714 flow_fdir_filter_lookup(struct rte_eth_dev *dev, struct mlx5_fdir *fdir_flow)
2716 struct mlx5_priv *priv = dev->data->dev_private;
2717 struct rte_flow *flow = NULL;
2720 TAILQ_FOREACH(flow, &priv->flows, next) {
2721 if (flow->fdir && !flow_fdir_cmp(flow->fdir, fdir_flow)) {
2722 DRV_LOG(DEBUG, "port %u found FDIR flow %p",
2723 dev->data->port_id, (void *)flow);
2731 * Add new flow director filter and store it in list.
2734 * Pointer to Ethernet device.
2735 * @param fdir_filter
2736 * Flow director filter to add.
2739 * 0 on success, a negative errno value otherwise and rte_errno is set.
2742 flow_fdir_filter_add(struct rte_eth_dev *dev,
2743 const struct rte_eth_fdir_filter *fdir_filter)
2745 struct mlx5_priv *priv = dev->data->dev_private;
2746 struct mlx5_fdir *fdir_flow;
2747 struct rte_flow *flow;
2750 fdir_flow = rte_zmalloc(__func__, sizeof(*fdir_flow), 0);
2755 ret = flow_fdir_filter_convert(dev, fdir_filter, fdir_flow);
2758 flow = flow_fdir_filter_lookup(dev, fdir_flow);
2763 flow = flow_list_create(dev, &priv->flows, &fdir_flow->attr,
2764 fdir_flow->items, fdir_flow->actions, NULL);
2767 assert(!flow->fdir);
2768 flow->fdir = fdir_flow;
2769 DRV_LOG(DEBUG, "port %u created FDIR flow %p",
2770 dev->data->port_id, (void *)flow);
2773 rte_free(fdir_flow);
2778 * Delete specific filter.
2781 * Pointer to Ethernet device.
2782 * @param fdir_filter
2783 * Filter to be deleted.
2786 * 0 on success, a negative errno value otherwise and rte_errno is set.
2789 flow_fdir_filter_delete(struct rte_eth_dev *dev,
2790 const struct rte_eth_fdir_filter *fdir_filter)
2792 struct mlx5_priv *priv = dev->data->dev_private;
2793 struct rte_flow *flow;
2794 struct mlx5_fdir fdir_flow = {
2799 ret = flow_fdir_filter_convert(dev, fdir_filter, &fdir_flow);
2802 flow = flow_fdir_filter_lookup(dev, &fdir_flow);
2807 flow_list_destroy(dev, &priv->flows, flow);
2808 DRV_LOG(DEBUG, "port %u deleted FDIR flow %p",
2809 dev->data->port_id, (void *)flow);
2814 * Update queue for specific filter.
2817 * Pointer to Ethernet device.
2818 * @param fdir_filter
2819 * Filter to be updated.
2822 * 0 on success, a negative errno value otherwise and rte_errno is set.
2825 flow_fdir_filter_update(struct rte_eth_dev *dev,
2826 const struct rte_eth_fdir_filter *fdir_filter)
2830 ret = flow_fdir_filter_delete(dev, fdir_filter);
2833 return flow_fdir_filter_add(dev, fdir_filter);
2837 * Flush all filters.
2840 * Pointer to Ethernet device.
2843 flow_fdir_filter_flush(struct rte_eth_dev *dev)
2845 struct mlx5_priv *priv = dev->data->dev_private;
2847 mlx5_flow_list_flush(dev, &priv->flows);
2851 * Get flow director information.
2854 * Pointer to Ethernet device.
2855 * @param[out] fdir_info
2856 * Resulting flow director information.
2859 flow_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
2861 struct rte_eth_fdir_masks *mask =
2862 &dev->data->dev_conf.fdir_conf.mask;
2864 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
2865 fdir_info->guarant_spc = 0;
2866 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
2867 fdir_info->max_flexpayload = 0;
2868 fdir_info->flow_types_mask[0] = 0;
2869 fdir_info->flex_payload_unit = 0;
2870 fdir_info->max_flex_payload_segment_num = 0;
2871 fdir_info->flex_payload_limit = 0;
2872 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
2876 * Deal with flow director operations.
2879 * Pointer to Ethernet device.
2881 * Operation to perform.
2883 * Pointer to operation-specific structure.
2886 * 0 on success, a negative errno value otherwise and rte_errno is set.
2889 flow_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
2892 enum rte_fdir_mode fdir_mode =
2893 dev->data->dev_conf.fdir_conf.mode;
2895 if (filter_op == RTE_ETH_FILTER_NOP)
2897 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
2898 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2899 DRV_LOG(ERR, "port %u flow director mode %d not supported",
2900 dev->data->port_id, fdir_mode);
2904 switch (filter_op) {
2905 case RTE_ETH_FILTER_ADD:
2906 return flow_fdir_filter_add(dev, arg);
2907 case RTE_ETH_FILTER_UPDATE:
2908 return flow_fdir_filter_update(dev, arg);
2909 case RTE_ETH_FILTER_DELETE:
2910 return flow_fdir_filter_delete(dev, arg);
2911 case RTE_ETH_FILTER_FLUSH:
2912 flow_fdir_filter_flush(dev);
2914 case RTE_ETH_FILTER_INFO:
2915 flow_fdir_info_get(dev, arg);
2918 DRV_LOG(DEBUG, "port %u unknown operation %u",
2919 dev->data->port_id, filter_op);
2927 * Manage filter operations.
2930 * Pointer to Ethernet device structure.
2931 * @param filter_type
2934 * Operation to perform.
2936 * Pointer to operation-specific structure.
2939 * 0 on success, a negative errno value otherwise and rte_errno is set.
2942 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
2943 enum rte_filter_type filter_type,
2944 enum rte_filter_op filter_op,
2947 switch (filter_type) {
2948 case RTE_ETH_FILTER_GENERIC:
2949 if (filter_op != RTE_ETH_FILTER_GET) {
2953 *(const void **)arg = &mlx5_flow_ops;
2955 case RTE_ETH_FILTER_FDIR:
2956 return flow_fdir_ctrl_func(dev, filter_op, arg);
2958 DRV_LOG(ERR, "port %u filter type (%d) not supported",
2959 dev->data->port_id, filter_type);
2960 rte_errno = ENOTSUP;