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_verbs_drv_ops;
47 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
49 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
50 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
51 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
52 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
54 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
55 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
60 MLX5_EXPANSION_ROOT_OUTER,
61 MLX5_EXPANSION_ROOT_ETH_VLAN,
62 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
63 MLX5_EXPANSION_OUTER_ETH,
64 MLX5_EXPANSION_OUTER_ETH_VLAN,
65 MLX5_EXPANSION_OUTER_VLAN,
66 MLX5_EXPANSION_OUTER_IPV4,
67 MLX5_EXPANSION_OUTER_IPV4_UDP,
68 MLX5_EXPANSION_OUTER_IPV4_TCP,
69 MLX5_EXPANSION_OUTER_IPV6,
70 MLX5_EXPANSION_OUTER_IPV6_UDP,
71 MLX5_EXPANSION_OUTER_IPV6_TCP,
73 MLX5_EXPANSION_VXLAN_GPE,
77 MLX5_EXPANSION_ETH_VLAN,
80 MLX5_EXPANSION_IPV4_UDP,
81 MLX5_EXPANSION_IPV4_TCP,
83 MLX5_EXPANSION_IPV6_UDP,
84 MLX5_EXPANSION_IPV6_TCP,
87 /** Supported expansion of items. */
88 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
89 [MLX5_EXPANSION_ROOT] = {
90 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
93 .type = RTE_FLOW_ITEM_TYPE_END,
95 [MLX5_EXPANSION_ROOT_OUTER] = {
96 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
97 MLX5_EXPANSION_OUTER_IPV4,
98 MLX5_EXPANSION_OUTER_IPV6),
99 .type = RTE_FLOW_ITEM_TYPE_END,
101 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
102 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
103 .type = RTE_FLOW_ITEM_TYPE_END,
105 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
106 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
107 .type = RTE_FLOW_ITEM_TYPE_END,
109 [MLX5_EXPANSION_OUTER_ETH] = {
110 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
111 MLX5_EXPANSION_OUTER_IPV6,
112 MLX5_EXPANSION_MPLS),
113 .type = RTE_FLOW_ITEM_TYPE_ETH,
116 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
117 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
118 .type = RTE_FLOW_ITEM_TYPE_ETH,
121 [MLX5_EXPANSION_OUTER_VLAN] = {
122 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
123 MLX5_EXPANSION_OUTER_IPV6),
124 .type = RTE_FLOW_ITEM_TYPE_VLAN,
126 [MLX5_EXPANSION_OUTER_IPV4] = {
127 .next = RTE_FLOW_EXPAND_RSS_NEXT
128 (MLX5_EXPANSION_OUTER_IPV4_UDP,
129 MLX5_EXPANSION_OUTER_IPV4_TCP,
131 .type = RTE_FLOW_ITEM_TYPE_IPV4,
132 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
133 ETH_RSS_NONFRAG_IPV4_OTHER,
135 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
136 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
137 MLX5_EXPANSION_VXLAN_GPE),
138 .type = RTE_FLOW_ITEM_TYPE_UDP,
139 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
141 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
142 .type = RTE_FLOW_ITEM_TYPE_TCP,
143 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
145 [MLX5_EXPANSION_OUTER_IPV6] = {
146 .next = RTE_FLOW_EXPAND_RSS_NEXT
147 (MLX5_EXPANSION_OUTER_IPV6_UDP,
148 MLX5_EXPANSION_OUTER_IPV6_TCP),
149 .type = RTE_FLOW_ITEM_TYPE_IPV6,
150 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
151 ETH_RSS_NONFRAG_IPV6_OTHER,
153 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
154 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
155 MLX5_EXPANSION_VXLAN_GPE),
156 .type = RTE_FLOW_ITEM_TYPE_UDP,
157 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
159 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
160 .type = RTE_FLOW_ITEM_TYPE_TCP,
161 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
163 [MLX5_EXPANSION_VXLAN] = {
164 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
165 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
167 [MLX5_EXPANSION_VXLAN_GPE] = {
168 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
170 MLX5_EXPANSION_IPV6),
171 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
173 [MLX5_EXPANSION_GRE] = {
174 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
175 .type = RTE_FLOW_ITEM_TYPE_GRE,
177 [MLX5_EXPANSION_MPLS] = {
178 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
179 MLX5_EXPANSION_IPV6),
180 .type = RTE_FLOW_ITEM_TYPE_MPLS,
182 [MLX5_EXPANSION_ETH] = {
183 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
184 MLX5_EXPANSION_IPV6),
185 .type = RTE_FLOW_ITEM_TYPE_ETH,
187 [MLX5_EXPANSION_ETH_VLAN] = {
188 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
189 .type = RTE_FLOW_ITEM_TYPE_ETH,
191 [MLX5_EXPANSION_VLAN] = {
192 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
193 MLX5_EXPANSION_IPV6),
194 .type = RTE_FLOW_ITEM_TYPE_VLAN,
196 [MLX5_EXPANSION_IPV4] = {
197 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
198 MLX5_EXPANSION_IPV4_TCP),
199 .type = RTE_FLOW_ITEM_TYPE_IPV4,
200 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
201 ETH_RSS_NONFRAG_IPV4_OTHER,
203 [MLX5_EXPANSION_IPV4_UDP] = {
204 .type = RTE_FLOW_ITEM_TYPE_UDP,
205 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
207 [MLX5_EXPANSION_IPV4_TCP] = {
208 .type = RTE_FLOW_ITEM_TYPE_TCP,
209 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
211 [MLX5_EXPANSION_IPV6] = {
212 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
213 MLX5_EXPANSION_IPV6_TCP),
214 .type = RTE_FLOW_ITEM_TYPE_IPV6,
215 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
216 ETH_RSS_NONFRAG_IPV6_OTHER,
218 [MLX5_EXPANSION_IPV6_UDP] = {
219 .type = RTE_FLOW_ITEM_TYPE_UDP,
220 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
222 [MLX5_EXPANSION_IPV6_TCP] = {
223 .type = RTE_FLOW_ITEM_TYPE_TCP,
224 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
228 static const struct rte_flow_ops mlx5_flow_ops = {
229 .validate = mlx5_flow_validate,
230 .create = mlx5_flow_create,
231 .destroy = mlx5_flow_destroy,
232 .flush = mlx5_flow_flush,
233 .isolate = mlx5_flow_isolate,
234 .query = mlx5_flow_query,
237 /* Convert FDIR request to Generic flow. */
239 struct rte_flow_attr attr;
240 struct rte_flow_action actions[2];
241 struct rte_flow_item items[4];
242 struct rte_flow_item_eth l2;
243 struct rte_flow_item_eth l2_mask;
245 struct rte_flow_item_ipv4 ipv4;
246 struct rte_flow_item_ipv6 ipv6;
249 struct rte_flow_item_ipv4 ipv4;
250 struct rte_flow_item_ipv6 ipv6;
253 struct rte_flow_item_udp udp;
254 struct rte_flow_item_tcp tcp;
257 struct rte_flow_item_udp udp;
258 struct rte_flow_item_tcp tcp;
260 struct rte_flow_action_queue queue;
263 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
264 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
265 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
268 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
269 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
270 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
271 { 9, 10, 11 }, { 12, 13, 14 },
274 /* Tunnel information. */
275 struct mlx5_flow_tunnel_info {
276 uint32_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
277 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
280 static struct mlx5_flow_tunnel_info tunnels_info[] = {
282 .tunnel = MLX5_FLOW_LAYER_VXLAN,
283 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
286 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
287 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
290 .tunnel = MLX5_FLOW_LAYER_GRE,
291 .ptype = RTE_PTYPE_TUNNEL_GRE,
294 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
295 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE | RTE_PTYPE_L4_UDP,
298 .tunnel = MLX5_FLOW_LAYER_MPLS,
299 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
304 * Discover the maximum number of priority available.
307 * Pointer to the Ethernet device structure.
310 * number of supported flow priority on success, a negative errno
311 * value otherwise and rte_errno is set.
314 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
317 struct ibv_flow_attr attr;
318 struct ibv_flow_spec_eth eth;
319 struct ibv_flow_spec_action_drop drop;
325 .type = IBV_FLOW_SPEC_ETH,
326 .size = sizeof(struct ibv_flow_spec_eth),
329 .size = sizeof(struct ibv_flow_spec_action_drop),
330 .type = IBV_FLOW_SPEC_ACTION_DROP,
333 struct ibv_flow *flow;
334 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
335 uint16_t vprio[] = { 8, 16 };
343 for (i = 0; i != RTE_DIM(vprio); i++) {
344 flow_attr.attr.priority = vprio[i] - 1;
345 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
348 claim_zero(mlx5_glue->destroy_flow(flow));
353 priority = RTE_DIM(priority_map_3);
356 priority = RTE_DIM(priority_map_5);
361 "port %u verbs maximum priority: %d expected 8/16",
362 dev->data->port_id, vprio[i]);
365 mlx5_hrxq_drop_release(dev);
366 DRV_LOG(INFO, "port %u flow maximum priority: %d",
367 dev->data->port_id, priority);
372 * Adjust flow priority based on the highest layer and the request priority.
375 * Pointer to the Ethernet device structure.
376 * @param[in] priority
377 * The rule base priority.
378 * @param[in] subpriority
379 * The priority based on the items.
384 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
385 uint32_t subpriority)
388 struct priv *priv = dev->data->dev_private;
390 switch (priv->config.flow_prio) {
391 case RTE_DIM(priority_map_3):
392 res = priority_map_3[priority][subpriority];
394 case RTE_DIM(priority_map_5):
395 res = priority_map_5[priority][subpriority];
402 * Verify the @p item specifications (spec, last, mask) are compatible with the
406 * Item specification.
408 * @p item->mask or flow default bit-masks.
409 * @param[in] nic_mask
410 * Bit-masks covering supported fields by the NIC to compare with user mask.
412 * Bit-masks size in bytes.
414 * Pointer to error structure.
417 * 0 on success, a negative errno value otherwise and rte_errno is set.
420 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
422 const uint8_t *nic_mask,
424 struct rte_flow_error *error)
429 for (i = 0; i < size; ++i)
430 if ((nic_mask[i] | mask[i]) != nic_mask[i])
431 return rte_flow_error_set(error, ENOTSUP,
432 RTE_FLOW_ERROR_TYPE_ITEM,
434 "mask enables non supported"
436 if (!item->spec && (item->mask || item->last))
437 return rte_flow_error_set(error, EINVAL,
438 RTE_FLOW_ERROR_TYPE_ITEM, item,
439 "mask/last without a spec is not"
441 if (item->spec && item->last) {
447 for (i = 0; i < size; ++i) {
448 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
449 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
451 ret = memcmp(spec, last, size);
453 return rte_flow_error_set(error, ENOTSUP,
454 RTE_FLOW_ERROR_TYPE_ITEM,
456 "range is not supported");
462 * Adjust the hash fields according to the @p flow information.
464 * @param[in] dev_flow.
465 * Pointer to the mlx5_flow.
467 * 1 when the hash field is for a tunnel item.
468 * @param[in] layer_types
470 * @param[in] hash_fields
474 * The hash fileds that should be used.
477 mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow,
478 int tunnel __rte_unused, uint32_t layer_types,
479 uint64_t hash_fields)
481 struct rte_flow *flow = dev_flow->flow;
482 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
483 int rss_request_inner = flow->rss.level >= 2;
485 /* Check RSS hash level for tunnel. */
486 if (tunnel && rss_request_inner)
487 hash_fields |= IBV_RX_HASH_INNER;
488 else if (tunnel || rss_request_inner)
491 /* Check if requested layer matches RSS hash fields. */
492 if (!(flow->rss.types & layer_types))
498 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
499 * if several tunnel rules are used on this queue, the tunnel ptype will be
503 * Rx queue to update.
506 mlx5_flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
509 uint32_t tunnel_ptype = 0;
511 /* Look up for the ptype to use. */
512 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
513 if (!rxq_ctrl->flow_tunnels_n[i])
516 tunnel_ptype = tunnels_info[i].ptype;
522 rxq_ctrl->rxq.tunnel = tunnel_ptype;
526 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the flow.
529 * Pointer to the Ethernet device structure.
531 * Pointer to flow structure.
534 mlx5_flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
536 struct priv *priv = dev->data->dev_private;
537 const int mark = !!(flow->actions &
538 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
539 const int tunnel = !!(flow->layers & MLX5_FLOW_LAYER_TUNNEL);
542 for (i = 0; i != flow->rss.queue_num; ++i) {
543 int idx = (*flow->queue)[i];
544 struct mlx5_rxq_ctrl *rxq_ctrl =
545 container_of((*priv->rxqs)[idx],
546 struct mlx5_rxq_ctrl, rxq);
549 rxq_ctrl->rxq.mark = 1;
550 rxq_ctrl->flow_mark_n++;
555 /* Increase the counter matching the flow. */
556 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
557 if ((tunnels_info[j].tunnel & flow->layers) ==
558 tunnels_info[j].tunnel) {
559 rxq_ctrl->flow_tunnels_n[j]++;
563 mlx5_flow_rxq_tunnel_ptype_update(rxq_ctrl);
569 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
570 * @p flow if no other flow uses it with the same kind of request.
573 * Pointer to Ethernet device.
575 * Pointer to the flow.
578 mlx5_flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
580 struct priv *priv = dev->data->dev_private;
581 const int mark = !!(flow->actions &
582 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
583 const int tunnel = !!(flow->layers & MLX5_FLOW_LAYER_TUNNEL);
586 assert(dev->data->dev_started);
587 for (i = 0; i != flow->rss.queue_num; ++i) {
588 int idx = (*flow->queue)[i];
589 struct mlx5_rxq_ctrl *rxq_ctrl =
590 container_of((*priv->rxqs)[idx],
591 struct mlx5_rxq_ctrl, rxq);
594 rxq_ctrl->flow_mark_n--;
595 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
600 /* Decrease the counter matching the flow. */
601 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
602 if ((tunnels_info[j].tunnel & flow->layers) ==
603 tunnels_info[j].tunnel) {
604 rxq_ctrl->flow_tunnels_n[j]--;
608 mlx5_flow_rxq_tunnel_ptype_update(rxq_ctrl);
614 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
617 * Pointer to Ethernet device.
620 mlx5_flow_rxq_flags_clear(struct rte_eth_dev *dev)
622 struct priv *priv = dev->data->dev_private;
625 for (i = 0; i != priv->rxqs_n; ++i) {
626 struct mlx5_rxq_ctrl *rxq_ctrl;
629 if (!(*priv->rxqs)[i])
631 rxq_ctrl = container_of((*priv->rxqs)[i],
632 struct mlx5_rxq_ctrl, rxq);
633 rxq_ctrl->flow_mark_n = 0;
634 rxq_ctrl->rxq.mark = 0;
635 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
636 rxq_ctrl->flow_tunnels_n[j] = 0;
637 rxq_ctrl->rxq.tunnel = 0;
642 * Validate the flag action.
644 * @param[in] action_flags
645 * Bit-fields that holds the actions detected until now.
647 * Pointer to error structure.
650 * 0 on success, a negative errno value otherwise and rte_errno is set.
653 mlx5_flow_validate_action_flag(uint64_t action_flags,
654 struct rte_flow_error *error)
657 if (action_flags & MLX5_FLOW_ACTION_DROP)
658 return rte_flow_error_set(error, EINVAL,
659 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
660 "can't drop and flag in same flow");
661 if (action_flags & MLX5_FLOW_ACTION_MARK)
662 return rte_flow_error_set(error, EINVAL,
663 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
664 "can't mark and flag in same flow");
665 if (action_flags & MLX5_FLOW_ACTION_FLAG)
666 return rte_flow_error_set(error, EINVAL,
667 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
669 " actions in same flow");
674 * Validate the mark action.
677 * Pointer to the queue action.
678 * @param[in] action_flags
679 * Bit-fields that holds the actions detected until now.
681 * Pointer to error structure.
684 * 0 on success, a negative errno value otherwise and rte_errno is set.
687 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
688 uint64_t action_flags,
689 struct rte_flow_error *error)
691 const struct rte_flow_action_mark *mark = action->conf;
694 return rte_flow_error_set(error, EINVAL,
695 RTE_FLOW_ERROR_TYPE_ACTION,
697 "configuration cannot be null");
698 if (mark->id >= MLX5_FLOW_MARK_MAX)
699 return rte_flow_error_set(error, EINVAL,
700 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
702 "mark id must in 0 <= id < "
703 RTE_STR(MLX5_FLOW_MARK_MAX));
704 if (action_flags & MLX5_FLOW_ACTION_DROP)
705 return rte_flow_error_set(error, EINVAL,
706 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
707 "can't drop and mark in same flow");
708 if (action_flags & MLX5_FLOW_ACTION_FLAG)
709 return rte_flow_error_set(error, EINVAL,
710 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
711 "can't flag and mark in same flow");
712 if (action_flags & MLX5_FLOW_ACTION_MARK)
713 return rte_flow_error_set(error, EINVAL,
714 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
715 "can't have 2 mark actions in same"
721 * Validate the drop action.
723 * @param[in] action_flags
724 * Bit-fields that holds the actions detected until now.
726 * Pointer to error structure.
729 * 0 on success, a negative errno value otherwise and rte_ernno is set.
732 mlx5_flow_validate_action_drop(uint64_t action_flags,
733 struct rte_flow_error *error)
735 if (action_flags & MLX5_FLOW_ACTION_FLAG)
736 return rte_flow_error_set(error, EINVAL,
737 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
738 "can't drop and flag in same flow");
739 if (action_flags & MLX5_FLOW_ACTION_MARK)
740 return rte_flow_error_set(error, EINVAL,
741 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
742 "can't drop and mark in same flow");
743 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
744 return rte_flow_error_set(error, EINVAL,
745 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
746 "can't have 2 fate actions in"
752 * Validate the queue action.
755 * Pointer to the queue action.
756 * @param[in] action_flags
757 * Bit-fields that holds the actions detected until now.
759 * Pointer to the Ethernet device structure.
761 * Pointer to error structure.
764 * 0 on success, a negative errno value otherwise and rte_ernno is set.
767 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
768 uint64_t action_flags,
769 struct rte_eth_dev *dev,
770 struct rte_flow_error *error)
772 struct priv *priv = dev->data->dev_private;
773 const struct rte_flow_action_queue *queue = action->conf;
775 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
776 return rte_flow_error_set(error, EINVAL,
777 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
778 "can't have 2 fate actions in"
780 if (queue->index >= priv->rxqs_n)
781 return rte_flow_error_set(error, EINVAL,
782 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
784 "queue index out of range");
785 if (!(*priv->rxqs)[queue->index])
786 return rte_flow_error_set(error, EINVAL,
787 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
789 "queue is not configured");
794 * Validate the rss action.
797 * Pointer to the queue action.
798 * @param[in] action_flags
799 * Bit-fields that holds the actions detected until now.
801 * Pointer to the Ethernet device structure.
803 * Pointer to error structure.
806 * 0 on success, a negative errno value otherwise and rte_ernno is set.
809 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
810 uint64_t action_flags,
811 struct rte_eth_dev *dev,
812 struct rte_flow_error *error)
814 struct priv *priv = dev->data->dev_private;
815 const struct rte_flow_action_rss *rss = action->conf;
818 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
819 return rte_flow_error_set(error, EINVAL,
820 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
821 "can't have 2 fate actions"
823 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
824 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
825 return rte_flow_error_set(error, ENOTSUP,
826 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
828 "RSS hash function not supported");
829 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
834 return rte_flow_error_set(error, ENOTSUP,
835 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
837 "tunnel RSS is not supported");
838 if (rss->key_len < MLX5_RSS_HASH_KEY_LEN)
839 return rte_flow_error_set(error, ENOTSUP,
840 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
842 "RSS hash key too small");
843 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
844 return rte_flow_error_set(error, ENOTSUP,
845 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
847 "RSS hash key too large");
848 if (rss->queue_num > priv->config.ind_table_max_size)
849 return rte_flow_error_set(error, ENOTSUP,
850 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
852 "number of queues too large");
853 if (rss->types & MLX5_RSS_HF_MASK)
854 return rte_flow_error_set(error, ENOTSUP,
855 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
857 "some RSS protocols are not"
859 for (i = 0; i != rss->queue_num; ++i) {
860 if (!(*priv->rxqs)[rss->queue[i]])
861 return rte_flow_error_set
862 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
863 &rss->queue[i], "queue is not configured");
869 * Validate the count action.
872 * Pointer to the Ethernet device structure.
874 * Pointer to error structure.
877 * 0 on success, a negative errno value otherwise and rte_ernno is set.
880 mlx5_flow_validate_action_count(struct rte_eth_dev *dev,
881 struct rte_flow_error *error)
883 struct priv *priv = dev->data->dev_private;
885 if (!priv->config.flow_counter_en)
886 return rte_flow_error_set(error, ENOTSUP,
887 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
888 "flow counters are not supported.");
893 * Verify the @p attributes will be correctly understood by the NIC and store
894 * them in the @p flow if everything is correct.
897 * Pointer to the Ethernet device structure.
898 * @param[in] attributes
899 * Pointer to flow attributes
901 * Pointer to error structure.
904 * 0 on success, a negative errno value otherwise and rte_errno is set.
907 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
908 const struct rte_flow_attr *attributes,
909 struct rte_flow_error *error)
911 struct priv *priv = dev->data->dev_private;
912 uint32_t priority_max = priv->config.flow_prio - 1;
914 if (attributes->group)
915 return rte_flow_error_set(error, ENOTSUP,
916 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
917 NULL, "groups is not supported");
918 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
919 attributes->priority >= priority_max)
920 return rte_flow_error_set(error, ENOTSUP,
921 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
922 NULL, "priority out of range");
923 if (attributes->egress)
924 return rte_flow_error_set(error, ENOTSUP,
925 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
926 "egress is not supported");
927 if (attributes->transfer)
928 return rte_flow_error_set(error, ENOTSUP,
929 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
930 NULL, "transfer is not supported");
931 if (!attributes->ingress)
932 return rte_flow_error_set(error, EINVAL,
933 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
935 "ingress attribute is mandatory");
940 * Validate Ethernet item.
943 * Item specification.
944 * @param[in] item_flags
945 * Bit-fields that holds the items detected until now.
947 * Pointer to error structure.
950 * 0 on success, a negative errno value otherwise and rte_errno is set.
953 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
955 struct rte_flow_error *error)
957 const struct rte_flow_item_eth *mask = item->mask;
958 const struct rte_flow_item_eth nic_mask = {
959 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
960 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
961 .type = RTE_BE16(0xffff),
964 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
966 if (item_flags & MLX5_FLOW_LAYER_OUTER_L2)
967 return rte_flow_error_set(error, ENOTSUP,
968 RTE_FLOW_ERROR_TYPE_ITEM, item,
969 "3 levels of l2 are not supported");
970 if ((item_flags & MLX5_FLOW_LAYER_INNER_L2) && !tunnel)
971 return rte_flow_error_set(error, ENOTSUP,
972 RTE_FLOW_ERROR_TYPE_ITEM, item,
973 "2 L2 without tunnel are not supported");
975 mask = &rte_flow_item_eth_mask;
976 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
977 (const uint8_t *)&nic_mask,
978 sizeof(struct rte_flow_item_eth),
984 * Validate VLAN item.
987 * Item specification.
988 * @param[in] item_flags
989 * Bit-fields that holds the items detected until now.
991 * Pointer to error structure.
994 * 0 on success, a negative errno value otherwise and rte_errno is set.
997 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
999 struct rte_flow_error *error)
1001 const struct rte_flow_item_vlan *spec = item->spec;
1002 const struct rte_flow_item_vlan *mask = item->mask;
1003 const struct rte_flow_item_vlan nic_mask = {
1004 .tci = RTE_BE16(0x0fff),
1005 .inner_type = RTE_BE16(0xffff),
1007 uint16_t vlan_tag = 0;
1008 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1010 const uint32_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1011 MLX5_FLOW_LAYER_INNER_L4) :
1012 (MLX5_FLOW_LAYER_OUTER_L3 |
1013 MLX5_FLOW_LAYER_OUTER_L4);
1014 const uint32_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1015 MLX5_FLOW_LAYER_OUTER_VLAN;
1017 if (item_flags & vlanm)
1018 return rte_flow_error_set(error, EINVAL,
1019 RTE_FLOW_ERROR_TYPE_ITEM, item,
1020 "VLAN layer already configured");
1021 else if ((item_flags & l34m) != 0)
1022 return rte_flow_error_set(error, EINVAL,
1023 RTE_FLOW_ERROR_TYPE_ITEM, item,
1024 "L2 layer cannot follow L3/L4 layer");
1026 mask = &rte_flow_item_vlan_mask;
1027 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1028 (const uint8_t *)&nic_mask,
1029 sizeof(struct rte_flow_item_vlan),
1034 vlan_tag = spec->tci;
1035 vlan_tag &= mask->tci;
1038 * From verbs perspective an empty VLAN is equivalent
1039 * to a packet without VLAN layer.
1042 return rte_flow_error_set(error, EINVAL,
1043 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1045 "VLAN cannot be empty");
1050 * Validate IPV4 item.
1053 * Item specification.
1054 * @param[in] item_flags
1055 * Bit-fields that holds the items detected until now.
1057 * Pointer to error structure.
1060 * 0 on success, a negative errno value otherwise and rte_errno is set.
1063 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1065 struct rte_flow_error *error)
1067 const struct rte_flow_item_ipv4 *mask = item->mask;
1068 const struct rte_flow_item_ipv4 nic_mask = {
1070 .src_addr = RTE_BE32(0xffffffff),
1071 .dst_addr = RTE_BE32(0xffffffff),
1072 .type_of_service = 0xff,
1073 .next_proto_id = 0xff,
1076 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1079 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1080 MLX5_FLOW_LAYER_OUTER_L3))
1081 return rte_flow_error_set(error, ENOTSUP,
1082 RTE_FLOW_ERROR_TYPE_ITEM, item,
1083 "multiple L3 layers not supported");
1084 else if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1085 MLX5_FLOW_LAYER_OUTER_L4))
1086 return rte_flow_error_set(error, EINVAL,
1087 RTE_FLOW_ERROR_TYPE_ITEM, item,
1088 "L3 cannot follow an L4 layer.");
1090 mask = &rte_flow_item_ipv4_mask;
1091 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1092 (const uint8_t *)&nic_mask,
1093 sizeof(struct rte_flow_item_ipv4),
1101 * Validate IPV6 item.
1104 * Item specification.
1105 * @param[in] item_flags
1106 * Bit-fields that holds the items detected until now.
1108 * Pointer to error structure.
1111 * 0 on success, a negative errno value otherwise and rte_errno is set.
1114 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1115 uint64_t item_flags,
1116 struct rte_flow_error *error)
1118 const struct rte_flow_item_ipv6 *mask = item->mask;
1119 const struct rte_flow_item_ipv6 nic_mask = {
1122 "\xff\xff\xff\xff\xff\xff\xff\xff"
1123 "\xff\xff\xff\xff\xff\xff\xff\xff",
1125 "\xff\xff\xff\xff\xff\xff\xff\xff"
1126 "\xff\xff\xff\xff\xff\xff\xff\xff",
1127 .vtc_flow = RTE_BE32(0xffffffff),
1132 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1135 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1136 MLX5_FLOW_LAYER_OUTER_L3))
1137 return rte_flow_error_set(error, ENOTSUP,
1138 RTE_FLOW_ERROR_TYPE_ITEM, item,
1139 "multiple L3 layers not supported");
1140 else if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1141 MLX5_FLOW_LAYER_OUTER_L4))
1142 return rte_flow_error_set(error, EINVAL,
1143 RTE_FLOW_ERROR_TYPE_ITEM, item,
1144 "L3 cannot follow an L4 layer.");
1146 * IPv6 is not recognised by the NIC inside a GRE tunnel.
1147 * Such support has to be disabled as the rule will be
1148 * accepted. Issue reproduced with Mellanox OFED 4.3-3.0.2.1 and
1149 * Mellanox OFED 4.4-1.0.0.0.
1151 if (tunnel && item_flags & MLX5_FLOW_LAYER_GRE)
1152 return rte_flow_error_set(error, ENOTSUP,
1153 RTE_FLOW_ERROR_TYPE_ITEM, item,
1154 "IPv6 inside a GRE tunnel is"
1155 " not recognised.");
1157 mask = &rte_flow_item_ipv6_mask;
1158 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1159 (const uint8_t *)&nic_mask,
1160 sizeof(struct rte_flow_item_ipv6),
1168 * Validate UDP item.
1171 * Item specification.
1172 * @param[in] item_flags
1173 * Bit-fields that holds the items detected until now.
1174 * @param[in] target_protocol
1175 * The next protocol in the previous item.
1177 * Pointer to error structure.
1180 * 0 on success, a negative errno value otherwise and rte_errno is set.
1183 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1184 uint64_t item_flags,
1185 uint8_t target_protocol,
1186 struct rte_flow_error *error)
1188 const struct rte_flow_item_udp *mask = item->mask;
1189 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1192 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1193 return rte_flow_error_set(error, EINVAL,
1194 RTE_FLOW_ERROR_TYPE_ITEM, item,
1195 "protocol filtering not compatible"
1197 if (!(item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1198 MLX5_FLOW_LAYER_OUTER_L3)))
1199 return rte_flow_error_set(error, EINVAL,
1200 RTE_FLOW_ERROR_TYPE_ITEM, item,
1201 "L3 is mandatory to filter on L4");
1202 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1203 MLX5_FLOW_LAYER_OUTER_L4))
1204 return rte_flow_error_set(error, EINVAL,
1205 RTE_FLOW_ERROR_TYPE_ITEM, item,
1206 "L4 layer is already present");
1208 mask = &rte_flow_item_udp_mask;
1209 ret = mlx5_flow_item_acceptable
1210 (item, (const uint8_t *)mask,
1211 (const uint8_t *)&rte_flow_item_udp_mask,
1212 sizeof(struct rte_flow_item_udp), error);
1219 * Validate TCP item.
1222 * Item specification.
1223 * @param[in] item_flags
1224 * Bit-fields that holds the items detected until now.
1225 * @param[in] target_protocol
1226 * The next protocol in the previous item.
1228 * Pointer to error structure.
1231 * 0 on success, a negative errno value otherwise and rte_errno is set.
1234 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1235 uint64_t item_flags,
1236 uint8_t target_protocol,
1237 struct rte_flow_error *error)
1239 const struct rte_flow_item_tcp *mask = item->mask;
1240 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1243 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1244 return rte_flow_error_set(error, EINVAL,
1245 RTE_FLOW_ERROR_TYPE_ITEM, item,
1246 "protocol filtering not compatible"
1248 if (!(item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1249 MLX5_FLOW_LAYER_OUTER_L3)))
1250 return rte_flow_error_set(error, EINVAL,
1251 RTE_FLOW_ERROR_TYPE_ITEM, item,
1252 "L3 is mandatory to filter on L4");
1253 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1254 MLX5_FLOW_LAYER_OUTER_L4))
1255 return rte_flow_error_set(error, EINVAL,
1256 RTE_FLOW_ERROR_TYPE_ITEM, item,
1257 "L4 layer is already present");
1259 mask = &rte_flow_item_tcp_mask;
1260 ret = mlx5_flow_item_acceptable
1261 (item, (const uint8_t *)mask,
1262 (const uint8_t *)&rte_flow_item_tcp_mask,
1263 sizeof(struct rte_flow_item_tcp), error);
1270 * Validate VXLAN item.
1273 * Item specification.
1274 * @param[in] item_flags
1275 * Bit-fields that holds the items detected until now.
1276 * @param[in] target_protocol
1277 * The next protocol in the previous item.
1279 * Pointer to error structure.
1282 * 0 on success, a negative errno value otherwise and rte_errno is set.
1285 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1286 uint64_t item_flags,
1287 struct rte_flow_error *error)
1289 const struct rte_flow_item_vxlan *spec = item->spec;
1290 const struct rte_flow_item_vxlan *mask = item->mask;
1295 } id = { .vlan_id = 0, };
1296 uint32_t vlan_id = 0;
1299 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1300 return rte_flow_error_set(error, ENOTSUP,
1301 RTE_FLOW_ERROR_TYPE_ITEM, item,
1302 "a tunnel is already present");
1304 * Verify only UDPv4 is present as defined in
1305 * https://tools.ietf.org/html/rfc7348
1307 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1308 return rte_flow_error_set(error, EINVAL,
1309 RTE_FLOW_ERROR_TYPE_ITEM, item,
1310 "no outer UDP layer found");
1312 mask = &rte_flow_item_vxlan_mask;
1313 ret = mlx5_flow_item_acceptable
1314 (item, (const uint8_t *)mask,
1315 (const uint8_t *)&rte_flow_item_vxlan_mask,
1316 sizeof(struct rte_flow_item_vxlan),
1321 memcpy(&id.vni[1], spec->vni, 3);
1322 vlan_id = id.vlan_id;
1323 memcpy(&id.vni[1], mask->vni, 3);
1324 vlan_id &= id.vlan_id;
1327 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1328 * only this layer is defined in the Verbs specification it is
1329 * interpreted as wildcard and all packets will match this
1330 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1331 * udp), all packets matching the layers before will also
1332 * match this rule. To avoid such situation, VNI 0 is
1333 * currently refused.
1336 return rte_flow_error_set(error, ENOTSUP,
1337 RTE_FLOW_ERROR_TYPE_ITEM, item,
1338 "VXLAN vni cannot be 0");
1339 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1340 return rte_flow_error_set(error, ENOTSUP,
1341 RTE_FLOW_ERROR_TYPE_ITEM, item,
1342 "VXLAN tunnel must be fully defined");
1347 * Validate VXLAN_GPE item.
1350 * Item specification.
1351 * @param[in] item_flags
1352 * Bit-fields that holds the items detected until now.
1354 * Pointer to the private data structure.
1355 * @param[in] target_protocol
1356 * The next protocol in the previous item.
1358 * Pointer to error structure.
1361 * 0 on success, a negative errno value otherwise and rte_errno is set.
1364 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1365 uint64_t item_flags,
1366 struct rte_eth_dev *dev,
1367 struct rte_flow_error *error)
1369 struct priv *priv = dev->data->dev_private;
1370 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1371 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1376 } id = { .vlan_id = 0, };
1377 uint32_t vlan_id = 0;
1379 if (!priv->config.l3_vxlan_en)
1380 return rte_flow_error_set(error, ENOTSUP,
1381 RTE_FLOW_ERROR_TYPE_ITEM, item,
1382 "L3 VXLAN is not enabled by device"
1383 " parameter and/or not configured in"
1385 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1386 return rte_flow_error_set(error, ENOTSUP,
1387 RTE_FLOW_ERROR_TYPE_ITEM, item,
1388 "a tunnel is already present");
1390 * Verify only UDPv4 is present as defined in
1391 * https://tools.ietf.org/html/rfc7348
1393 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1394 return rte_flow_error_set(error, EINVAL,
1395 RTE_FLOW_ERROR_TYPE_ITEM, item,
1396 "no outer UDP layer found");
1398 mask = &rte_flow_item_vxlan_gpe_mask;
1399 ret = mlx5_flow_item_acceptable
1400 (item, (const uint8_t *)mask,
1401 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1402 sizeof(struct rte_flow_item_vxlan_gpe),
1408 return rte_flow_error_set(error, ENOTSUP,
1409 RTE_FLOW_ERROR_TYPE_ITEM,
1411 "VxLAN-GPE protocol"
1413 memcpy(&id.vni[1], spec->vni, 3);
1414 vlan_id = id.vlan_id;
1415 memcpy(&id.vni[1], mask->vni, 3);
1416 vlan_id &= id.vlan_id;
1419 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1420 * layer is defined in the Verbs specification it is interpreted as
1421 * wildcard and all packets will match this rule, if it follows a full
1422 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1423 * before will also match this rule. To avoid such situation, VNI 0
1424 * is currently refused.
1427 return rte_flow_error_set(error, ENOTSUP,
1428 RTE_FLOW_ERROR_TYPE_ITEM, item,
1429 "VXLAN-GPE vni cannot be 0");
1430 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1431 return rte_flow_error_set(error, ENOTSUP,
1432 RTE_FLOW_ERROR_TYPE_ITEM, item,
1433 "VXLAN-GPE tunnel must be fully"
1439 * Validate GRE item.
1442 * Item specification.
1443 * @param[in] item_flags
1444 * Bit flags to mark detected items.
1445 * @param[in] target_protocol
1446 * The next protocol in the previous item.
1448 * Pointer to error structure.
1451 * 0 on success, a negative errno value otherwise and rte_errno is set.
1454 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
1455 uint64_t item_flags,
1456 uint8_t target_protocol,
1457 struct rte_flow_error *error)
1459 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
1460 const struct rte_flow_item_gre *mask = item->mask;
1463 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
1464 return rte_flow_error_set(error, EINVAL,
1465 RTE_FLOW_ERROR_TYPE_ITEM, item,
1466 "protocol filtering not compatible"
1467 " with this GRE layer");
1468 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1469 return rte_flow_error_set(error, ENOTSUP,
1470 RTE_FLOW_ERROR_TYPE_ITEM, item,
1471 "a tunnel is already present");
1472 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
1473 return rte_flow_error_set(error, ENOTSUP,
1474 RTE_FLOW_ERROR_TYPE_ITEM, item,
1475 "L3 Layer is missing");
1477 mask = &rte_flow_item_gre_mask;
1478 ret = mlx5_flow_item_acceptable
1479 (item, (const uint8_t *)mask,
1480 (const uint8_t *)&rte_flow_item_gre_mask,
1481 sizeof(struct rte_flow_item_gre), error);
1484 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
1485 if (spec && (spec->protocol & mask->protocol))
1486 return rte_flow_error_set(error, ENOTSUP,
1487 RTE_FLOW_ERROR_TYPE_ITEM, item,
1488 "without MPLS support the"
1489 " specification cannot be used for"
1496 * Validate MPLS item.
1499 * Item specification.
1500 * @param[in] item_flags
1501 * Bit-fields that holds the items detected until now.
1502 * @param[in] target_protocol
1503 * The next protocol in the previous item.
1505 * Pointer to error structure.
1508 * 0 on success, a negative errno value otherwise and rte_errno is set.
1511 mlx5_flow_validate_item_mpls(const struct rte_flow_item *item __rte_unused,
1512 uint64_t item_flags __rte_unused,
1513 uint8_t target_protocol __rte_unused,
1514 struct rte_flow_error *error)
1516 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
1517 const struct rte_flow_item_mpls *mask = item->mask;
1520 if (target_protocol != 0xff && target_protocol != IPPROTO_MPLS)
1521 return rte_flow_error_set(error, EINVAL,
1522 RTE_FLOW_ERROR_TYPE_ITEM, item,
1523 "protocol filtering not compatible"
1524 " with MPLS layer");
1525 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1526 return rte_flow_error_set(error, ENOTSUP,
1527 RTE_FLOW_ERROR_TYPE_ITEM, item,
1528 "a tunnel is already"
1531 mask = &rte_flow_item_mpls_mask;
1532 ret = mlx5_flow_item_acceptable
1533 (item, (const uint8_t *)mask,
1534 (const uint8_t *)&rte_flow_item_mpls_mask,
1535 sizeof(struct rte_flow_item_mpls), error);
1540 return rte_flow_error_set(error, ENOTSUP,
1541 RTE_FLOW_ERROR_TYPE_ITEM, item,
1542 "MPLS is not supported by Verbs, please"
1547 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
1548 const struct rte_flow_attr *attr __rte_unused,
1549 const struct rte_flow_item items[] __rte_unused,
1550 const struct rte_flow_action actions[] __rte_unused,
1551 struct rte_flow_error *error __rte_unused)
1553 rte_errno = ENOTSUP;
1557 static struct mlx5_flow *
1558 flow_null_prepare(const struct rte_flow_attr *attr __rte_unused,
1559 const struct rte_flow_item items[] __rte_unused,
1560 const struct rte_flow_action actions[] __rte_unused,
1561 uint64_t *item_flags __rte_unused,
1562 uint64_t *action_flags __rte_unused,
1563 struct rte_flow_error *error __rte_unused)
1565 rte_errno = ENOTSUP;
1570 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
1571 struct mlx5_flow *dev_flow __rte_unused,
1572 const struct rte_flow_attr *attr __rte_unused,
1573 const struct rte_flow_item items[] __rte_unused,
1574 const struct rte_flow_action actions[] __rte_unused,
1575 struct rte_flow_error *error __rte_unused)
1577 rte_errno = ENOTSUP;
1582 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
1583 struct rte_flow *flow __rte_unused,
1584 struct rte_flow_error *error __rte_unused)
1586 rte_errno = ENOTSUP;
1591 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
1592 struct rte_flow *flow __rte_unused)
1597 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
1598 struct rte_flow *flow __rte_unused)
1602 /* Void driver to protect from null pointer reference. */
1603 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
1604 .validate = flow_null_validate,
1605 .prepare = flow_null_prepare,
1606 .translate = flow_null_translate,
1607 .apply = flow_null_apply,
1608 .remove = flow_null_remove,
1609 .destroy = flow_null_destroy,
1613 * Select flow driver type according to flow attributes and device
1617 * Pointer to the dev structure.
1619 * Pointer to the flow attributes.
1622 * flow driver type if supported, MLX5_FLOW_TYPE_MAX otherwise.
1624 static enum mlx5_flow_drv_type
1625 flow_get_drv_type(struct rte_eth_dev *dev __rte_unused,
1626 const struct rte_flow_attr *attr)
1628 struct priv *priv __rte_unused = dev->data->dev_private;
1629 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
1631 if (!attr->transfer) {
1632 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
1633 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
1634 MLX5_FLOW_TYPE_VERBS;
1636 type = MLX5_FLOW_TYPE_VERBS;
1642 #define flow_get_drv_ops(type) flow_drv_ops[type]
1645 * Flow driver validation API. This abstracts calling driver specific functions.
1646 * The type of flow driver is determined according to flow attributes.
1649 * Pointer to the dev structure.
1651 * Pointer to the flow attributes.
1653 * Pointer to the list of items.
1654 * @param[in] actions
1655 * Pointer to the list of actions.
1657 * Pointer to the error structure.
1660 * 0 on success, a negative errno value otherwise and rte_ernno is set.
1663 flow_drv_validate(struct rte_eth_dev *dev,
1664 const struct rte_flow_attr *attr,
1665 const struct rte_flow_item items[],
1666 const struct rte_flow_action actions[],
1667 struct rte_flow_error *error)
1669 const struct mlx5_flow_driver_ops *fops;
1670 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
1672 fops = flow_get_drv_ops(type);
1673 return fops->validate(dev, attr, items, actions, error);
1677 * Flow driver preparation API. This abstracts calling driver specific
1678 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
1679 * calculates the size of memory required for device flow, allocates the memory,
1680 * initializes the device flow and returns the pointer.
1683 * Pointer to the flow attributes.
1685 * Pointer to the list of items.
1686 * @param[in] actions
1687 * Pointer to the list of actions.
1688 * @param[out] item_flags
1689 * Pointer to bit mask of all items detected.
1690 * @param[out] action_flags
1691 * Pointer to bit mask of all actions detected.
1693 * Pointer to the error structure.
1696 * Pointer to device flow on success, otherwise NULL and rte_ernno is set.
1698 static inline struct mlx5_flow *
1699 flow_drv_prepare(struct rte_flow *flow,
1700 const struct rte_flow_attr *attr,
1701 const struct rte_flow_item items[],
1702 const struct rte_flow_action actions[],
1703 uint64_t *item_flags,
1704 uint64_t *action_flags,
1705 struct rte_flow_error *error)
1707 const struct mlx5_flow_driver_ops *fops;
1708 enum mlx5_flow_drv_type type = flow->drv_type;
1710 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1711 fops = flow_get_drv_ops(type);
1712 return fops->prepare(attr, items, actions, item_flags, action_flags,
1717 * Flow driver translation API. This abstracts calling driver specific
1718 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
1719 * translates a generic flow into a driver flow. flow_drv_prepare() must
1724 * Pointer to the rte dev structure.
1725 * @param[in, out] dev_flow
1726 * Pointer to the mlx5 flow.
1728 * Pointer to the flow attributes.
1730 * Pointer to the list of items.
1731 * @param[in] actions
1732 * Pointer to the list of actions.
1734 * Pointer to the error structure.
1737 * 0 on success, a negative errno value otherwise and rte_ernno is set.
1740 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
1741 const struct rte_flow_attr *attr,
1742 const struct rte_flow_item items[],
1743 const struct rte_flow_action actions[],
1744 struct rte_flow_error *error)
1746 const struct mlx5_flow_driver_ops *fops;
1747 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
1749 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1750 fops = flow_get_drv_ops(type);
1751 return fops->translate(dev, dev_flow, attr, items, actions, error);
1755 * Flow driver apply API. This abstracts calling driver specific functions.
1756 * Parent flow (rte_flow) should have driver type (drv_type). It applies
1757 * translated driver flows on to device. flow_drv_translate() must precede.
1760 * Pointer to Ethernet device structure.
1761 * @param[in, out] flow
1762 * Pointer to flow structure.
1764 * Pointer to error structure.
1767 * 0 on success, a negative errno value otherwise and rte_errno is set.
1770 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
1771 struct rte_flow_error *error)
1773 const struct mlx5_flow_driver_ops *fops;
1774 enum mlx5_flow_drv_type type = flow->drv_type;
1776 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1777 fops = flow_get_drv_ops(type);
1778 return fops->apply(dev, flow, error);
1782 * Flow driver remove API. This abstracts calling driver specific functions.
1783 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
1784 * on device. All the resources of the flow should be freed by calling
1785 * flow_dv_destroy().
1788 * Pointer to Ethernet device.
1789 * @param[in, out] flow
1790 * Pointer to flow structure.
1793 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
1795 const struct mlx5_flow_driver_ops *fops;
1796 enum mlx5_flow_drv_type type = flow->drv_type;
1798 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1799 fops = flow_get_drv_ops(type);
1800 fops->remove(dev, flow);
1804 * Flow driver destroy API. This abstracts calling driver specific functions.
1805 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
1806 * on device and releases resources of the flow.
1809 * Pointer to Ethernet device.
1810 * @param[in, out] flow
1811 * Pointer to flow structure.
1814 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
1816 const struct mlx5_flow_driver_ops *fops;
1817 enum mlx5_flow_drv_type type = flow->drv_type;
1819 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1820 fops = flow_get_drv_ops(type);
1821 fops->destroy(dev, flow);
1825 * Validate a flow supported by the NIC.
1827 * @see rte_flow_validate()
1831 mlx5_flow_validate(struct rte_eth_dev *dev,
1832 const struct rte_flow_attr *attr,
1833 const struct rte_flow_item items[],
1834 const struct rte_flow_action actions[],
1835 struct rte_flow_error *error)
1839 ret = flow_drv_validate(dev, attr, items, actions, error);
1846 * Get RSS action from the action list.
1848 * @param[in] actions
1849 * Pointer to the list of actions.
1852 * Pointer to the RSS action if exist, else return NULL.
1854 static const struct rte_flow_action_rss*
1855 mlx5_flow_get_rss_action(const struct rte_flow_action actions[])
1857 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1858 switch (actions->type) {
1859 case RTE_FLOW_ACTION_TYPE_RSS:
1860 return (const struct rte_flow_action_rss *)
1870 mlx5_find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
1872 const struct rte_flow_item *item;
1873 unsigned int has_vlan = 0;
1875 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1876 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1882 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
1883 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
1884 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
1885 MLX5_EXPANSION_ROOT_OUTER;
1889 * Create a flow and add it to @p list.
1892 * Pointer to Ethernet device.
1894 * Pointer to a TAILQ flow list.
1896 * Flow rule attributes.
1898 * Pattern specification (list terminated by the END pattern item).
1899 * @param[in] actions
1900 * Associated actions (list terminated by the END action).
1902 * Perform verbose error reporting if not NULL.
1905 * A flow on success, NULL otherwise and rte_errno is set.
1907 static struct rte_flow *
1908 mlx5_flow_list_create(struct rte_eth_dev *dev,
1909 struct mlx5_flows *list,
1910 const struct rte_flow_attr *attr,
1911 const struct rte_flow_item items[],
1912 const struct rte_flow_action actions[],
1913 struct rte_flow_error *error)
1915 struct rte_flow *flow = NULL;
1916 struct mlx5_flow *dev_flow;
1917 uint64_t action_flags = 0;
1918 uint64_t item_flags = 0;
1919 const struct rte_flow_action_rss *rss;
1921 struct rte_flow_expand_rss buf;
1922 uint8_t buffer[2048];
1924 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
1929 ret = flow_drv_validate(dev, attr, items, actions, error);
1932 flow_size = sizeof(struct rte_flow);
1933 rss = mlx5_flow_get_rss_action(actions);
1935 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
1938 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
1939 flow = rte_calloc(__func__, 1, flow_size, 0);
1940 flow->drv_type = flow_get_drv_type(dev, attr);
1941 assert(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
1942 flow->drv_type < MLX5_FLOW_TYPE_MAX);
1943 flow->queue = (void *)(flow + 1);
1944 LIST_INIT(&flow->dev_flows);
1945 if (rss && rss->types) {
1946 unsigned int graph_root;
1948 graph_root = mlx5_find_graph_root(items, rss->level);
1949 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
1951 mlx5_support_expansion,
1954 (unsigned int)ret < sizeof(expand_buffer.buffer));
1957 buf->entry[0].pattern = (void *)(uintptr_t)items;
1959 for (i = 0; i < buf->entries; ++i) {
1960 dev_flow = flow_drv_prepare(flow, attr, buf->entry[i].pattern,
1961 actions, &item_flags, &action_flags,
1965 dev_flow->flow = flow;
1966 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
1967 ret = flow_drv_translate(dev, dev_flow, attr,
1968 buf->entry[i].pattern,
1973 if (dev->data->dev_started) {
1974 ret = flow_drv_apply(dev, flow, error);
1978 TAILQ_INSERT_TAIL(list, flow, next);
1979 mlx5_flow_rxq_flags_set(dev, flow);
1982 ret = rte_errno; /* Save rte_errno before cleanup. */
1984 flow_drv_destroy(dev, flow);
1986 rte_errno = ret; /* Restore rte_errno. */
1993 * @see rte_flow_create()
1997 mlx5_flow_create(struct rte_eth_dev *dev,
1998 const struct rte_flow_attr *attr,
1999 const struct rte_flow_item items[],
2000 const struct rte_flow_action actions[],
2001 struct rte_flow_error *error)
2003 return mlx5_flow_list_create
2004 (dev, &((struct priv *)dev->data->dev_private)->flows,
2005 attr, items, actions, error);
2009 * Destroy a flow in a list.
2012 * Pointer to Ethernet device.
2014 * Pointer to a TAILQ flow list.
2019 mlx5_flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
2020 struct rte_flow *flow)
2022 flow_drv_destroy(dev, flow);
2023 TAILQ_REMOVE(list, flow, next);
2025 * Update RX queue flags only if port is started, otherwise it is
2028 if (dev->data->dev_started)
2029 mlx5_flow_rxq_flags_trim(dev, flow);
2034 * Destroy all flows.
2037 * Pointer to Ethernet device.
2039 * Pointer to a TAILQ flow list.
2042 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
2044 while (!TAILQ_EMPTY(list)) {
2045 struct rte_flow *flow;
2047 flow = TAILQ_FIRST(list);
2048 mlx5_flow_list_destroy(dev, list, flow);
2056 * Pointer to Ethernet device.
2058 * Pointer to a TAILQ flow list.
2061 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
2063 struct rte_flow *flow;
2065 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next)
2066 flow_drv_remove(dev, flow);
2067 mlx5_flow_rxq_flags_clear(dev);
2074 * Pointer to Ethernet device.
2076 * Pointer to a TAILQ flow list.
2079 * 0 on success, a negative errno value otherwise and rte_errno is set.
2082 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
2084 struct rte_flow *flow;
2085 struct rte_flow_error error;
2088 TAILQ_FOREACH(flow, list, next) {
2089 ret = flow_drv_apply(dev, flow, &error);
2092 mlx5_flow_rxq_flags_set(dev, flow);
2096 ret = rte_errno; /* Save rte_errno before cleanup. */
2097 mlx5_flow_stop(dev, list);
2098 rte_errno = ret; /* Restore rte_errno. */
2103 * Verify the flow list is empty
2106 * Pointer to Ethernet device.
2108 * @return the number of flows not released.
2111 mlx5_flow_verify(struct rte_eth_dev *dev)
2113 struct priv *priv = dev->data->dev_private;
2114 struct rte_flow *flow;
2117 TAILQ_FOREACH(flow, &priv->flows, next) {
2118 DRV_LOG(DEBUG, "port %u flow %p still referenced",
2119 dev->data->port_id, (void *)flow);
2126 * Enable a control flow configured from the control plane.
2129 * Pointer to Ethernet device.
2131 * An Ethernet flow spec to apply.
2133 * An Ethernet flow mask to apply.
2135 * A VLAN flow spec to apply.
2137 * A VLAN flow mask to apply.
2140 * 0 on success, a negative errno value otherwise and rte_errno is set.
2143 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
2144 struct rte_flow_item_eth *eth_spec,
2145 struct rte_flow_item_eth *eth_mask,
2146 struct rte_flow_item_vlan *vlan_spec,
2147 struct rte_flow_item_vlan *vlan_mask)
2149 struct priv *priv = dev->data->dev_private;
2150 const struct rte_flow_attr attr = {
2152 .priority = MLX5_FLOW_PRIO_RSVD,
2154 struct rte_flow_item items[] = {
2156 .type = RTE_FLOW_ITEM_TYPE_ETH,
2162 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
2163 RTE_FLOW_ITEM_TYPE_END,
2169 .type = RTE_FLOW_ITEM_TYPE_END,
2172 uint16_t queue[priv->reta_idx_n];
2173 struct rte_flow_action_rss action_rss = {
2174 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
2176 .types = priv->rss_conf.rss_hf,
2177 .key_len = priv->rss_conf.rss_key_len,
2178 .queue_num = priv->reta_idx_n,
2179 .key = priv->rss_conf.rss_key,
2182 struct rte_flow_action actions[] = {
2184 .type = RTE_FLOW_ACTION_TYPE_RSS,
2185 .conf = &action_rss,
2188 .type = RTE_FLOW_ACTION_TYPE_END,
2191 struct rte_flow *flow;
2192 struct rte_flow_error error;
2195 if (!priv->reta_idx_n) {
2199 for (i = 0; i != priv->reta_idx_n; ++i)
2200 queue[i] = (*priv->reta_idx)[i];
2201 flow = mlx5_flow_list_create(dev, &priv->ctrl_flows, &attr, items,
2209 * Enable a flow control configured from the control plane.
2212 * Pointer to Ethernet device.
2214 * An Ethernet flow spec to apply.
2216 * An Ethernet flow mask to apply.
2219 * 0 on success, a negative errno value otherwise and rte_errno is set.
2222 mlx5_ctrl_flow(struct rte_eth_dev *dev,
2223 struct rte_flow_item_eth *eth_spec,
2224 struct rte_flow_item_eth *eth_mask)
2226 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
2232 * @see rte_flow_destroy()
2236 mlx5_flow_destroy(struct rte_eth_dev *dev,
2237 struct rte_flow *flow,
2238 struct rte_flow_error *error __rte_unused)
2240 struct priv *priv = dev->data->dev_private;
2242 mlx5_flow_list_destroy(dev, &priv->flows, flow);
2247 * Destroy all flows.
2249 * @see rte_flow_flush()
2253 mlx5_flow_flush(struct rte_eth_dev *dev,
2254 struct rte_flow_error *error __rte_unused)
2256 struct priv *priv = dev->data->dev_private;
2258 mlx5_flow_list_flush(dev, &priv->flows);
2265 * @see rte_flow_isolate()
2269 mlx5_flow_isolate(struct rte_eth_dev *dev,
2271 struct rte_flow_error *error)
2273 struct priv *priv = dev->data->dev_private;
2275 if (dev->data->dev_started) {
2276 rte_flow_error_set(error, EBUSY,
2277 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2279 "port must be stopped first");
2282 priv->isolated = !!enable;
2284 dev->dev_ops = &mlx5_dev_ops_isolate;
2286 dev->dev_ops = &mlx5_dev_ops;
2291 * Query flow counter.
2294 * Pointer to the flow.
2297 * 0 on success, a negative errno value otherwise and rte_errno is set.
2300 mlx5_flow_query_count(struct rte_flow *flow __rte_unused,
2301 void *data __rte_unused,
2302 struct rte_flow_error *error)
2304 #ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
2305 if (flow->actions & MLX5_FLOW_ACTION_COUNT) {
2306 struct rte_flow_query_count *qc = data;
2307 uint64_t counters[2] = {0, 0};
2308 struct ibv_query_counter_set_attr query_cs_attr = {
2309 .cs = flow->counter->cs,
2310 .query_flags = IBV_COUNTER_SET_FORCE_UPDATE,
2312 struct ibv_counter_set_data query_out = {
2314 .outlen = 2 * sizeof(uint64_t),
2316 int err = mlx5_glue->query_counter_set(&query_cs_attr,
2320 return rte_flow_error_set
2322 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2324 "cannot read counter");
2327 qc->hits = counters[0] - flow->counter->hits;
2328 qc->bytes = counters[1] - flow->counter->bytes;
2330 flow->counter->hits = counters[0];
2331 flow->counter->bytes = counters[1];
2335 return rte_flow_error_set(error, ENOTSUP,
2336 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2338 "flow does not have counter");
2340 return rte_flow_error_set(error, ENOTSUP,
2341 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2343 "counters are not available");
2349 * @see rte_flow_query()
2353 mlx5_flow_query(struct rte_eth_dev *dev __rte_unused,
2354 struct rte_flow *flow,
2355 const struct rte_flow_action *actions,
2357 struct rte_flow_error *error)
2361 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2362 switch (actions->type) {
2363 case RTE_FLOW_ACTION_TYPE_VOID:
2365 case RTE_FLOW_ACTION_TYPE_COUNT:
2366 ret = mlx5_flow_query_count(flow, data, error);
2369 return rte_flow_error_set(error, ENOTSUP,
2370 RTE_FLOW_ERROR_TYPE_ACTION,
2372 "action not supported");
2381 * Convert a flow director filter to a generic flow.
2384 * Pointer to Ethernet device.
2385 * @param fdir_filter
2386 * Flow director filter to add.
2388 * Generic flow parameters structure.
2391 * 0 on success, a negative errno value otherwise and rte_errno is set.
2394 mlx5_fdir_filter_convert(struct rte_eth_dev *dev,
2395 const struct rte_eth_fdir_filter *fdir_filter,
2396 struct mlx5_fdir *attributes)
2398 struct priv *priv = dev->data->dev_private;
2399 const struct rte_eth_fdir_input *input = &fdir_filter->input;
2400 const struct rte_eth_fdir_masks *mask =
2401 &dev->data->dev_conf.fdir_conf.mask;
2403 /* Validate queue number. */
2404 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
2405 DRV_LOG(ERR, "port %u invalid queue number %d",
2406 dev->data->port_id, fdir_filter->action.rx_queue);
2410 attributes->attr.ingress = 1;
2411 attributes->items[0] = (struct rte_flow_item) {
2412 .type = RTE_FLOW_ITEM_TYPE_ETH,
2413 .spec = &attributes->l2,
2414 .mask = &attributes->l2_mask,
2416 switch (fdir_filter->action.behavior) {
2417 case RTE_ETH_FDIR_ACCEPT:
2418 attributes->actions[0] = (struct rte_flow_action){
2419 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
2420 .conf = &attributes->queue,
2423 case RTE_ETH_FDIR_REJECT:
2424 attributes->actions[0] = (struct rte_flow_action){
2425 .type = RTE_FLOW_ACTION_TYPE_DROP,
2429 DRV_LOG(ERR, "port %u invalid behavior %d",
2431 fdir_filter->action.behavior);
2432 rte_errno = ENOTSUP;
2435 attributes->queue.index = fdir_filter->action.rx_queue;
2437 switch (fdir_filter->input.flow_type) {
2438 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2439 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2440 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2441 attributes->l3.ipv4.hdr = (struct ipv4_hdr){
2442 .src_addr = input->flow.ip4_flow.src_ip,
2443 .dst_addr = input->flow.ip4_flow.dst_ip,
2444 .time_to_live = input->flow.ip4_flow.ttl,
2445 .type_of_service = input->flow.ip4_flow.tos,
2447 attributes->l3_mask.ipv4.hdr = (struct ipv4_hdr){
2448 .src_addr = mask->ipv4_mask.src_ip,
2449 .dst_addr = mask->ipv4_mask.dst_ip,
2450 .time_to_live = mask->ipv4_mask.ttl,
2451 .type_of_service = mask->ipv4_mask.tos,
2452 .next_proto_id = mask->ipv4_mask.proto,
2454 attributes->items[1] = (struct rte_flow_item){
2455 .type = RTE_FLOW_ITEM_TYPE_IPV4,
2456 .spec = &attributes->l3,
2457 .mask = &attributes->l3_mask,
2460 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2461 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2462 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2463 attributes->l3.ipv6.hdr = (struct ipv6_hdr){
2464 .hop_limits = input->flow.ipv6_flow.hop_limits,
2465 .proto = input->flow.ipv6_flow.proto,
2468 memcpy(attributes->l3.ipv6.hdr.src_addr,
2469 input->flow.ipv6_flow.src_ip,
2470 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2471 memcpy(attributes->l3.ipv6.hdr.dst_addr,
2472 input->flow.ipv6_flow.dst_ip,
2473 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2474 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
2475 mask->ipv6_mask.src_ip,
2476 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2477 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
2478 mask->ipv6_mask.dst_ip,
2479 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2480 attributes->items[1] = (struct rte_flow_item){
2481 .type = RTE_FLOW_ITEM_TYPE_IPV6,
2482 .spec = &attributes->l3,
2483 .mask = &attributes->l3_mask,
2487 DRV_LOG(ERR, "port %u invalid flow type%d",
2488 dev->data->port_id, fdir_filter->input.flow_type);
2489 rte_errno = ENOTSUP;
2493 switch (fdir_filter->input.flow_type) {
2494 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2495 attributes->l4.udp.hdr = (struct udp_hdr){
2496 .src_port = input->flow.udp4_flow.src_port,
2497 .dst_port = input->flow.udp4_flow.dst_port,
2499 attributes->l4_mask.udp.hdr = (struct udp_hdr){
2500 .src_port = mask->src_port_mask,
2501 .dst_port = mask->dst_port_mask,
2503 attributes->items[2] = (struct rte_flow_item){
2504 .type = RTE_FLOW_ITEM_TYPE_UDP,
2505 .spec = &attributes->l4,
2506 .mask = &attributes->l4_mask,
2509 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2510 attributes->l4.tcp.hdr = (struct tcp_hdr){
2511 .src_port = input->flow.tcp4_flow.src_port,
2512 .dst_port = input->flow.tcp4_flow.dst_port,
2514 attributes->l4_mask.tcp.hdr = (struct tcp_hdr){
2515 .src_port = mask->src_port_mask,
2516 .dst_port = mask->dst_port_mask,
2518 attributes->items[2] = (struct rte_flow_item){
2519 .type = RTE_FLOW_ITEM_TYPE_TCP,
2520 .spec = &attributes->l4,
2521 .mask = &attributes->l4_mask,
2524 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2525 attributes->l4.udp.hdr = (struct udp_hdr){
2526 .src_port = input->flow.udp6_flow.src_port,
2527 .dst_port = input->flow.udp6_flow.dst_port,
2529 attributes->l4_mask.udp.hdr = (struct udp_hdr){
2530 .src_port = mask->src_port_mask,
2531 .dst_port = mask->dst_port_mask,
2533 attributes->items[2] = (struct rte_flow_item){
2534 .type = RTE_FLOW_ITEM_TYPE_UDP,
2535 .spec = &attributes->l4,
2536 .mask = &attributes->l4_mask,
2539 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2540 attributes->l4.tcp.hdr = (struct tcp_hdr){
2541 .src_port = input->flow.tcp6_flow.src_port,
2542 .dst_port = input->flow.tcp6_flow.dst_port,
2544 attributes->l4_mask.tcp.hdr = (struct tcp_hdr){
2545 .src_port = mask->src_port_mask,
2546 .dst_port = mask->dst_port_mask,
2548 attributes->items[2] = (struct rte_flow_item){
2549 .type = RTE_FLOW_ITEM_TYPE_TCP,
2550 .spec = &attributes->l4,
2551 .mask = &attributes->l4_mask,
2554 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2555 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2558 DRV_LOG(ERR, "port %u invalid flow type%d",
2559 dev->data->port_id, fdir_filter->input.flow_type);
2560 rte_errno = ENOTSUP;
2567 * Add new flow director filter and store it in list.
2570 * Pointer to Ethernet device.
2571 * @param fdir_filter
2572 * Flow director filter to add.
2575 * 0 on success, a negative errno value otherwise and rte_errno is set.
2578 mlx5_fdir_filter_add(struct rte_eth_dev *dev,
2579 const struct rte_eth_fdir_filter *fdir_filter)
2581 struct priv *priv = dev->data->dev_private;
2582 struct mlx5_fdir attributes = {
2585 .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
2586 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
2590 struct rte_flow_error error;
2591 struct rte_flow *flow;
2594 ret = mlx5_fdir_filter_convert(dev, fdir_filter, &attributes);
2597 flow = mlx5_flow_list_create(dev, &priv->flows, &attributes.attr,
2598 attributes.items, attributes.actions,
2601 DRV_LOG(DEBUG, "port %u FDIR created %p", dev->data->port_id,
2609 * Delete specific filter.
2612 * Pointer to Ethernet device.
2613 * @param fdir_filter
2614 * Filter to be deleted.
2617 * 0 on success, a negative errno value otherwise and rte_errno is set.
2620 mlx5_fdir_filter_delete(struct rte_eth_dev *dev __rte_unused,
2621 const struct rte_eth_fdir_filter *fdir_filter
2624 rte_errno = ENOTSUP;
2629 * Update queue for specific filter.
2632 * Pointer to Ethernet device.
2633 * @param fdir_filter
2634 * Filter to be updated.
2637 * 0 on success, a negative errno value otherwise and rte_errno is set.
2640 mlx5_fdir_filter_update(struct rte_eth_dev *dev,
2641 const struct rte_eth_fdir_filter *fdir_filter)
2645 ret = mlx5_fdir_filter_delete(dev, fdir_filter);
2648 return mlx5_fdir_filter_add(dev, fdir_filter);
2652 * Flush all filters.
2655 * Pointer to Ethernet device.
2658 mlx5_fdir_filter_flush(struct rte_eth_dev *dev)
2660 struct priv *priv = dev->data->dev_private;
2662 mlx5_flow_list_flush(dev, &priv->flows);
2666 * Get flow director information.
2669 * Pointer to Ethernet device.
2670 * @param[out] fdir_info
2671 * Resulting flow director information.
2674 mlx5_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
2676 struct rte_eth_fdir_masks *mask =
2677 &dev->data->dev_conf.fdir_conf.mask;
2679 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
2680 fdir_info->guarant_spc = 0;
2681 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
2682 fdir_info->max_flexpayload = 0;
2683 fdir_info->flow_types_mask[0] = 0;
2684 fdir_info->flex_payload_unit = 0;
2685 fdir_info->max_flex_payload_segment_num = 0;
2686 fdir_info->flex_payload_limit = 0;
2687 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
2691 * Deal with flow director operations.
2694 * Pointer to Ethernet device.
2696 * Operation to perform.
2698 * Pointer to operation-specific structure.
2701 * 0 on success, a negative errno value otherwise and rte_errno is set.
2704 mlx5_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
2707 enum rte_fdir_mode fdir_mode =
2708 dev->data->dev_conf.fdir_conf.mode;
2710 if (filter_op == RTE_ETH_FILTER_NOP)
2712 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
2713 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2714 DRV_LOG(ERR, "port %u flow director mode %d not supported",
2715 dev->data->port_id, fdir_mode);
2719 switch (filter_op) {
2720 case RTE_ETH_FILTER_ADD:
2721 return mlx5_fdir_filter_add(dev, arg);
2722 case RTE_ETH_FILTER_UPDATE:
2723 return mlx5_fdir_filter_update(dev, arg);
2724 case RTE_ETH_FILTER_DELETE:
2725 return mlx5_fdir_filter_delete(dev, arg);
2726 case RTE_ETH_FILTER_FLUSH:
2727 mlx5_fdir_filter_flush(dev);
2729 case RTE_ETH_FILTER_INFO:
2730 mlx5_fdir_info_get(dev, arg);
2733 DRV_LOG(DEBUG, "port %u unknown operation %u",
2734 dev->data->port_id, filter_op);
2742 * Manage filter operations.
2745 * Pointer to Ethernet device structure.
2746 * @param filter_type
2749 * Operation to perform.
2751 * Pointer to operation-specific structure.
2754 * 0 on success, a negative errno value otherwise and rte_errno is set.
2757 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
2758 enum rte_filter_type filter_type,
2759 enum rte_filter_op filter_op,
2762 switch (filter_type) {
2763 case RTE_ETH_FILTER_GENERIC:
2764 if (filter_op != RTE_ETH_FILTER_GET) {
2768 *(const void **)arg = &mlx5_flow_ops;
2770 case RTE_ETH_FILTER_FDIR:
2771 return mlx5_fdir_ctrl_func(dev, filter_op, arg);
2773 DRV_LOG(ERR, "port %u filter type (%d) not supported",
2774 dev->data->port_id, filter_type);
2775 rte_errno = ENOTSUP;