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;
43 MLX5_EXPANSION_ROOT_OUTER,
44 MLX5_EXPANSION_ROOT_ETH_VLAN,
45 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
46 MLX5_EXPANSION_OUTER_ETH,
47 MLX5_EXPANSION_OUTER_ETH_VLAN,
48 MLX5_EXPANSION_OUTER_VLAN,
49 MLX5_EXPANSION_OUTER_IPV4,
50 MLX5_EXPANSION_OUTER_IPV4_UDP,
51 MLX5_EXPANSION_OUTER_IPV4_TCP,
52 MLX5_EXPANSION_OUTER_IPV6,
53 MLX5_EXPANSION_OUTER_IPV6_UDP,
54 MLX5_EXPANSION_OUTER_IPV6_TCP,
56 MLX5_EXPANSION_VXLAN_GPE,
60 MLX5_EXPANSION_ETH_VLAN,
63 MLX5_EXPANSION_IPV4_UDP,
64 MLX5_EXPANSION_IPV4_TCP,
66 MLX5_EXPANSION_IPV6_UDP,
67 MLX5_EXPANSION_IPV6_TCP,
70 /** Supported expansion of items. */
71 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
72 [MLX5_EXPANSION_ROOT] = {
73 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
76 .type = RTE_FLOW_ITEM_TYPE_END,
78 [MLX5_EXPANSION_ROOT_OUTER] = {
79 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
80 MLX5_EXPANSION_OUTER_IPV4,
81 MLX5_EXPANSION_OUTER_IPV6),
82 .type = RTE_FLOW_ITEM_TYPE_END,
84 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
85 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
86 .type = RTE_FLOW_ITEM_TYPE_END,
88 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
89 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
90 .type = RTE_FLOW_ITEM_TYPE_END,
92 [MLX5_EXPANSION_OUTER_ETH] = {
93 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
94 MLX5_EXPANSION_OUTER_IPV6,
96 .type = RTE_FLOW_ITEM_TYPE_ETH,
99 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
100 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
101 .type = RTE_FLOW_ITEM_TYPE_ETH,
104 [MLX5_EXPANSION_OUTER_VLAN] = {
105 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
106 MLX5_EXPANSION_OUTER_IPV6),
107 .type = RTE_FLOW_ITEM_TYPE_VLAN,
109 [MLX5_EXPANSION_OUTER_IPV4] = {
110 .next = RTE_FLOW_EXPAND_RSS_NEXT
111 (MLX5_EXPANSION_OUTER_IPV4_UDP,
112 MLX5_EXPANSION_OUTER_IPV4_TCP,
114 .type = RTE_FLOW_ITEM_TYPE_IPV4,
115 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
116 ETH_RSS_NONFRAG_IPV4_OTHER,
118 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
119 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
120 MLX5_EXPANSION_VXLAN_GPE),
121 .type = RTE_FLOW_ITEM_TYPE_UDP,
122 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
124 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
125 .type = RTE_FLOW_ITEM_TYPE_TCP,
126 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
128 [MLX5_EXPANSION_OUTER_IPV6] = {
129 .next = RTE_FLOW_EXPAND_RSS_NEXT
130 (MLX5_EXPANSION_OUTER_IPV6_UDP,
131 MLX5_EXPANSION_OUTER_IPV6_TCP),
132 .type = RTE_FLOW_ITEM_TYPE_IPV6,
133 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
134 ETH_RSS_NONFRAG_IPV6_OTHER,
136 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
137 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
138 MLX5_EXPANSION_VXLAN_GPE),
139 .type = RTE_FLOW_ITEM_TYPE_UDP,
140 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
142 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
143 .type = RTE_FLOW_ITEM_TYPE_TCP,
144 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
146 [MLX5_EXPANSION_VXLAN] = {
147 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
148 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
150 [MLX5_EXPANSION_VXLAN_GPE] = {
151 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
153 MLX5_EXPANSION_IPV6),
154 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
156 [MLX5_EXPANSION_GRE] = {
157 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
158 .type = RTE_FLOW_ITEM_TYPE_GRE,
160 [MLX5_EXPANSION_MPLS] = {
161 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
162 MLX5_EXPANSION_IPV6),
163 .type = RTE_FLOW_ITEM_TYPE_MPLS,
165 [MLX5_EXPANSION_ETH] = {
166 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
167 MLX5_EXPANSION_IPV6),
168 .type = RTE_FLOW_ITEM_TYPE_ETH,
170 [MLX5_EXPANSION_ETH_VLAN] = {
171 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
172 .type = RTE_FLOW_ITEM_TYPE_ETH,
174 [MLX5_EXPANSION_VLAN] = {
175 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
176 MLX5_EXPANSION_IPV6),
177 .type = RTE_FLOW_ITEM_TYPE_VLAN,
179 [MLX5_EXPANSION_IPV4] = {
180 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
181 MLX5_EXPANSION_IPV4_TCP),
182 .type = RTE_FLOW_ITEM_TYPE_IPV4,
183 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
184 ETH_RSS_NONFRAG_IPV4_OTHER,
186 [MLX5_EXPANSION_IPV4_UDP] = {
187 .type = RTE_FLOW_ITEM_TYPE_UDP,
188 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
190 [MLX5_EXPANSION_IPV4_TCP] = {
191 .type = RTE_FLOW_ITEM_TYPE_TCP,
192 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
194 [MLX5_EXPANSION_IPV6] = {
195 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
196 MLX5_EXPANSION_IPV6_TCP),
197 .type = RTE_FLOW_ITEM_TYPE_IPV6,
198 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
199 ETH_RSS_NONFRAG_IPV6_OTHER,
201 [MLX5_EXPANSION_IPV6_UDP] = {
202 .type = RTE_FLOW_ITEM_TYPE_UDP,
203 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
205 [MLX5_EXPANSION_IPV6_TCP] = {
206 .type = RTE_FLOW_ITEM_TYPE_TCP,
207 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
211 static const struct rte_flow_ops mlx5_flow_ops = {
212 .validate = mlx5_flow_validate,
213 .create = mlx5_flow_create,
214 .destroy = mlx5_flow_destroy,
215 .flush = mlx5_flow_flush,
216 .isolate = mlx5_flow_isolate,
217 .query = mlx5_flow_query,
220 /* Convert FDIR request to Generic flow. */
222 struct rte_flow_attr attr;
223 struct rte_flow_action actions[2];
224 struct rte_flow_item items[4];
225 struct rte_flow_item_eth l2;
226 struct rte_flow_item_eth l2_mask;
228 struct rte_flow_item_ipv4 ipv4;
229 struct rte_flow_item_ipv6 ipv6;
232 struct rte_flow_item_ipv4 ipv4;
233 struct rte_flow_item_ipv6 ipv6;
236 struct rte_flow_item_udp udp;
237 struct rte_flow_item_tcp tcp;
240 struct rte_flow_item_udp udp;
241 struct rte_flow_item_tcp tcp;
243 struct rte_flow_action_queue queue;
246 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
247 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
248 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
251 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
252 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
253 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
254 { 9, 10, 11 }, { 12, 13, 14 },
257 /* Tunnel information. */
258 struct mlx5_flow_tunnel_info {
259 uint32_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
260 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
263 static struct mlx5_flow_tunnel_info tunnels_info[] = {
265 .tunnel = MLX5_FLOW_LAYER_VXLAN,
266 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
269 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
270 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
273 .tunnel = MLX5_FLOW_LAYER_GRE,
274 .ptype = RTE_PTYPE_TUNNEL_GRE,
277 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
278 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE | RTE_PTYPE_L4_UDP,
281 .tunnel = MLX5_FLOW_LAYER_MPLS,
282 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
286 /* Holds the nic operations that should be used. */
287 struct mlx5_flow_driver_ops nic_ops;
290 * Discover the maximum number of priority available.
293 * Pointer to the Ethernet device structure.
296 * number of supported flow priority on success, a negative errno
297 * value otherwise and rte_errno is set.
300 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
303 struct ibv_flow_attr attr;
304 struct ibv_flow_spec_eth eth;
305 struct ibv_flow_spec_action_drop drop;
311 .type = IBV_FLOW_SPEC_ETH,
312 .size = sizeof(struct ibv_flow_spec_eth),
315 .size = sizeof(struct ibv_flow_spec_action_drop),
316 .type = IBV_FLOW_SPEC_ACTION_DROP,
319 struct ibv_flow *flow;
320 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
321 uint16_t vprio[] = { 8, 16 };
329 for (i = 0; i != RTE_DIM(vprio); i++) {
330 flow_attr.attr.priority = vprio[i] - 1;
331 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
334 claim_zero(mlx5_glue->destroy_flow(flow));
339 priority = RTE_DIM(priority_map_3);
342 priority = RTE_DIM(priority_map_5);
347 "port %u verbs maximum priority: %d expected 8/16",
348 dev->data->port_id, vprio[i]);
351 mlx5_hrxq_drop_release(dev);
352 DRV_LOG(INFO, "port %u flow maximum priority: %d",
353 dev->data->port_id, priority);
358 * Adjust flow priority based on the highest layer and the request priority.
361 * Pointer to the Ethernet device structure.
362 * @param[in] priority
363 * The rule base priority.
364 * @param[in] subpriority
365 * The priority based on the items.
370 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
371 uint32_t subpriority)
374 struct priv *priv = dev->data->dev_private;
376 switch (priv->config.flow_prio) {
377 case RTE_DIM(priority_map_3):
378 res = priority_map_3[priority][subpriority];
380 case RTE_DIM(priority_map_5):
381 res = priority_map_5[priority][subpriority];
388 * Verify the @p item specifications (spec, last, mask) are compatible with the
392 * Item specification.
394 * @p item->mask or flow default bit-masks.
395 * @param[in] nic_mask
396 * Bit-masks covering supported fields by the NIC to compare with user mask.
398 * Bit-masks size in bytes.
400 * Pointer to error structure.
403 * 0 on success, a negative errno value otherwise and rte_errno is set.
406 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
408 const uint8_t *nic_mask,
410 struct rte_flow_error *error)
415 for (i = 0; i < size; ++i)
416 if ((nic_mask[i] | mask[i]) != nic_mask[i])
417 return rte_flow_error_set(error, ENOTSUP,
418 RTE_FLOW_ERROR_TYPE_ITEM,
420 "mask enables non supported"
422 if (!item->spec && (item->mask || item->last))
423 return rte_flow_error_set(error, EINVAL,
424 RTE_FLOW_ERROR_TYPE_ITEM, item,
425 "mask/last without a spec is not"
427 if (item->spec && item->last) {
433 for (i = 0; i < size; ++i) {
434 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
435 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
437 ret = memcmp(spec, last, size);
439 return rte_flow_error_set(error, ENOTSUP,
440 RTE_FLOW_ERROR_TYPE_ITEM,
442 "range is not supported");
448 * Adjust the hash fields according to the @p flow information.
450 * @param[in] dev_flow.
451 * Pointer to the mlx5_flow.
453 * 1 when the hash field is for a tunnel item.
454 * @param[in] layer_types
456 * @param[in] hash_fields
460 * The hash fileds that should be used.
463 mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow,
464 int tunnel __rte_unused, uint32_t layer_types,
465 uint64_t hash_fields)
467 struct rte_flow *flow = dev_flow->flow;
468 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
469 int rss_request_inner = flow->rss.level >= 2;
471 /* Check RSS hash level for tunnel. */
472 if (tunnel && rss_request_inner)
473 hash_fields |= IBV_RX_HASH_INNER;
474 else if (tunnel || rss_request_inner)
477 /* Check if requested layer matches RSS hash fields. */
478 if (!(flow->rss.types & layer_types))
484 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
485 * if several tunnel rules are used on this queue, the tunnel ptype will be
489 * Rx queue to update.
492 mlx5_flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
495 uint32_t tunnel_ptype = 0;
497 /* Look up for the ptype to use. */
498 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
499 if (!rxq_ctrl->flow_tunnels_n[i])
502 tunnel_ptype = tunnels_info[i].ptype;
508 rxq_ctrl->rxq.tunnel = tunnel_ptype;
512 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the flow.
515 * Pointer to the Ethernet device structure.
517 * Pointer to flow structure.
520 mlx5_flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
522 struct priv *priv = dev->data->dev_private;
523 const int mark = !!(flow->actions &
524 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
525 const int tunnel = !!(flow->layers & MLX5_FLOW_LAYER_TUNNEL);
528 for (i = 0; i != flow->rss.queue_num; ++i) {
529 int idx = (*flow->queue)[i];
530 struct mlx5_rxq_ctrl *rxq_ctrl =
531 container_of((*priv->rxqs)[idx],
532 struct mlx5_rxq_ctrl, rxq);
535 rxq_ctrl->rxq.mark = 1;
536 rxq_ctrl->flow_mark_n++;
541 /* Increase the counter matching the flow. */
542 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
543 if ((tunnels_info[j].tunnel & flow->layers) ==
544 tunnels_info[j].tunnel) {
545 rxq_ctrl->flow_tunnels_n[j]++;
549 mlx5_flow_rxq_tunnel_ptype_update(rxq_ctrl);
555 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
556 * @p flow if no other flow uses it with the same kind of request.
559 * Pointer to Ethernet device.
561 * Pointer to the flow.
564 mlx5_flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
566 struct priv *priv = dev->data->dev_private;
567 const int mark = !!(flow->actions &
568 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
569 const int tunnel = !!(flow->layers & MLX5_FLOW_LAYER_TUNNEL);
572 assert(dev->data->dev_started);
573 for (i = 0; i != flow->rss.queue_num; ++i) {
574 int idx = (*flow->queue)[i];
575 struct mlx5_rxq_ctrl *rxq_ctrl =
576 container_of((*priv->rxqs)[idx],
577 struct mlx5_rxq_ctrl, rxq);
580 rxq_ctrl->flow_mark_n--;
581 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
586 /* Decrease the counter matching the flow. */
587 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
588 if ((tunnels_info[j].tunnel & flow->layers) ==
589 tunnels_info[j].tunnel) {
590 rxq_ctrl->flow_tunnels_n[j]--;
594 mlx5_flow_rxq_tunnel_ptype_update(rxq_ctrl);
600 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
603 * Pointer to Ethernet device.
606 mlx5_flow_rxq_flags_clear(struct rte_eth_dev *dev)
608 struct priv *priv = dev->data->dev_private;
611 for (i = 0; i != priv->rxqs_n; ++i) {
612 struct mlx5_rxq_ctrl *rxq_ctrl;
615 if (!(*priv->rxqs)[i])
617 rxq_ctrl = container_of((*priv->rxqs)[i],
618 struct mlx5_rxq_ctrl, rxq);
619 rxq_ctrl->flow_mark_n = 0;
620 rxq_ctrl->rxq.mark = 0;
621 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
622 rxq_ctrl->flow_tunnels_n[j] = 0;
623 rxq_ctrl->rxq.tunnel = 0;
628 * Validate the flag action.
630 * @param[in] action_flags
631 * Bit-fields that holds the actions detected until now.
633 * Pointer to error structure.
636 * 0 on success, a negative errno value otherwise and rte_errno is set.
639 mlx5_flow_validate_action_flag(uint64_t action_flags,
640 struct rte_flow_error *error)
643 if (action_flags & MLX5_FLOW_ACTION_DROP)
644 return rte_flow_error_set(error, EINVAL,
645 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
646 "can't drop and flag in same flow");
647 if (action_flags & MLX5_FLOW_ACTION_MARK)
648 return rte_flow_error_set(error, EINVAL,
649 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
650 "can't mark and flag in same flow");
651 if (action_flags & MLX5_FLOW_ACTION_FLAG)
652 return rte_flow_error_set(error, EINVAL,
653 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
655 " actions in same flow");
660 * Validate the mark action.
663 * Pointer to the queue action.
664 * @param[in] action_flags
665 * Bit-fields that holds the actions detected until now.
667 * Pointer to error structure.
670 * 0 on success, a negative errno value otherwise and rte_errno is set.
673 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
674 uint64_t action_flags,
675 struct rte_flow_error *error)
677 const struct rte_flow_action_mark *mark = action->conf;
680 return rte_flow_error_set(error, EINVAL,
681 RTE_FLOW_ERROR_TYPE_ACTION,
683 "configuration cannot be null");
684 if (mark->id >= MLX5_FLOW_MARK_MAX)
685 return rte_flow_error_set(error, EINVAL,
686 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
688 "mark id must in 0 <= id < "
689 RTE_STR(MLX5_FLOW_MARK_MAX));
690 if (action_flags & MLX5_FLOW_ACTION_DROP)
691 return rte_flow_error_set(error, EINVAL,
692 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
693 "can't drop and mark in same flow");
694 if (action_flags & MLX5_FLOW_ACTION_FLAG)
695 return rte_flow_error_set(error, EINVAL,
696 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
697 "can't flag and mark in same flow");
698 if (action_flags & MLX5_FLOW_ACTION_MARK)
699 return rte_flow_error_set(error, EINVAL,
700 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
701 "can't have 2 mark actions in same"
707 * Validate the drop action.
709 * @param[in] action_flags
710 * Bit-fields that holds the actions detected until now.
712 * Pointer to error structure.
715 * 0 on success, a negative errno value otherwise and rte_ernno is set.
718 mlx5_flow_validate_action_drop(uint64_t action_flags,
719 struct rte_flow_error *error)
721 if (action_flags & MLX5_FLOW_ACTION_FLAG)
722 return rte_flow_error_set(error, EINVAL,
723 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
724 "can't drop and flag in same flow");
725 if (action_flags & MLX5_FLOW_ACTION_MARK)
726 return rte_flow_error_set(error, EINVAL,
727 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
728 "can't drop and mark in same flow");
729 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
730 return rte_flow_error_set(error, EINVAL,
731 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
732 "can't have 2 fate actions in"
738 * Validate the queue action.
741 * Pointer to the queue action.
742 * @param[in] action_flags
743 * Bit-fields that holds the actions detected until now.
745 * Pointer to the Ethernet device structure.
747 * Pointer to error structure.
750 * 0 on success, a negative errno value otherwise and rte_ernno is set.
753 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
754 uint64_t action_flags,
755 struct rte_eth_dev *dev,
756 struct rte_flow_error *error)
758 struct priv *priv = dev->data->dev_private;
759 const struct rte_flow_action_queue *queue = action->conf;
761 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
762 return rte_flow_error_set(error, EINVAL,
763 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
764 "can't have 2 fate actions in"
766 if (queue->index >= priv->rxqs_n)
767 return rte_flow_error_set(error, EINVAL,
768 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
770 "queue index out of range");
771 if (!(*priv->rxqs)[queue->index])
772 return rte_flow_error_set(error, EINVAL,
773 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
775 "queue is not configured");
780 * Validate the rss action.
783 * Pointer to the queue action.
784 * @param[in] action_flags
785 * Bit-fields that holds the actions detected until now.
787 * Pointer to the Ethernet device structure.
789 * Pointer to error structure.
792 * 0 on success, a negative errno value otherwise and rte_ernno is set.
795 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
796 uint64_t action_flags,
797 struct rte_eth_dev *dev,
798 struct rte_flow_error *error)
800 struct priv *priv = dev->data->dev_private;
801 const struct rte_flow_action_rss *rss = action->conf;
804 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
805 return rte_flow_error_set(error, EINVAL,
806 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
807 "can't have 2 fate actions"
809 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
810 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
811 return rte_flow_error_set(error, ENOTSUP,
812 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
814 "RSS hash function not supported");
815 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
820 return rte_flow_error_set(error, ENOTSUP,
821 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
823 "tunnel RSS is not supported");
824 if (rss->key_len < MLX5_RSS_HASH_KEY_LEN)
825 return rte_flow_error_set(error, ENOTSUP,
826 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
828 "RSS hash key too small");
829 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
830 return rte_flow_error_set(error, ENOTSUP,
831 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
833 "RSS hash key too large");
834 if (rss->queue_num > priv->config.ind_table_max_size)
835 return rte_flow_error_set(error, ENOTSUP,
836 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
838 "number of queues too large");
839 if (rss->types & MLX5_RSS_HF_MASK)
840 return rte_flow_error_set(error, ENOTSUP,
841 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
843 "some RSS protocols are not"
845 for (i = 0; i != rss->queue_num; ++i) {
846 if (!(*priv->rxqs)[rss->queue[i]])
847 return rte_flow_error_set
848 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
849 &rss->queue[i], "queue is not configured");
855 * Validate the count action.
858 * Pointer to the Ethernet device structure.
860 * Pointer to error structure.
863 * 0 on success, a negative errno value otherwise and rte_ernno is set.
866 mlx5_flow_validate_action_count(struct rte_eth_dev *dev,
867 struct rte_flow_error *error)
869 struct priv *priv = dev->data->dev_private;
871 if (!priv->config.flow_counter_en)
872 return rte_flow_error_set(error, ENOTSUP,
873 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
874 "flow counters are not supported.");
879 * Verify the @p attributes will be correctly understood by the NIC and store
880 * them in the @p flow if everything is correct.
883 * Pointer to the Ethernet device structure.
884 * @param[in] attributes
885 * Pointer to flow attributes
887 * Pointer to error structure.
890 * 0 on success, a negative errno value otherwise and rte_errno is set.
893 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
894 const struct rte_flow_attr *attributes,
895 struct rte_flow_error *error)
897 struct priv *priv = dev->data->dev_private;
898 uint32_t priority_max = priv->config.flow_prio - 1;
900 if (attributes->group)
901 return rte_flow_error_set(error, ENOTSUP,
902 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
903 NULL, "groups is not supported");
904 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
905 attributes->priority >= priority_max)
906 return rte_flow_error_set(error, ENOTSUP,
907 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
908 NULL, "priority out of range");
909 if (attributes->egress)
910 return rte_flow_error_set(error, ENOTSUP,
911 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
912 "egress is not supported");
913 if (attributes->transfer)
914 return rte_flow_error_set(error, ENOTSUP,
915 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
916 NULL, "transfer is not supported");
917 if (!attributes->ingress)
918 return rte_flow_error_set(error, EINVAL,
919 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
921 "ingress attribute is mandatory");
926 * Validate Ethernet item.
929 * Item specification.
930 * @param[in] item_flags
931 * Bit-fields that holds the items detected until now.
933 * Pointer to error structure.
936 * 0 on success, a negative errno value otherwise and rte_errno is set.
939 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
941 struct rte_flow_error *error)
943 const struct rte_flow_item_eth *mask = item->mask;
944 const struct rte_flow_item_eth nic_mask = {
945 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
946 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
947 .type = RTE_BE16(0xffff),
950 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
952 if (item_flags & MLX5_FLOW_LAYER_OUTER_L2)
953 return rte_flow_error_set(error, ENOTSUP,
954 RTE_FLOW_ERROR_TYPE_ITEM, item,
955 "3 levels of l2 are not supported");
956 if ((item_flags & MLX5_FLOW_LAYER_INNER_L2) && !tunnel)
957 return rte_flow_error_set(error, ENOTSUP,
958 RTE_FLOW_ERROR_TYPE_ITEM, item,
959 "2 L2 without tunnel are not supported");
961 mask = &rte_flow_item_eth_mask;
962 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
963 (const uint8_t *)&nic_mask,
964 sizeof(struct rte_flow_item_eth),
970 * Validate VLAN item.
973 * Item specification.
974 * @param[in] item_flags
975 * Bit-fields that holds the items detected until now.
977 * Pointer to error structure.
980 * 0 on success, a negative errno value otherwise and rte_errno is set.
983 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
985 struct rte_flow_error *error)
987 const struct rte_flow_item_vlan *spec = item->spec;
988 const struct rte_flow_item_vlan *mask = item->mask;
989 const struct rte_flow_item_vlan nic_mask = {
990 .tci = RTE_BE16(0x0fff),
991 .inner_type = RTE_BE16(0xffff),
993 uint16_t vlan_tag = 0;
994 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
996 const uint32_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
997 MLX5_FLOW_LAYER_INNER_L4) :
998 (MLX5_FLOW_LAYER_OUTER_L3 |
999 MLX5_FLOW_LAYER_OUTER_L4);
1000 const uint32_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1001 MLX5_FLOW_LAYER_OUTER_VLAN;
1003 if (item_flags & vlanm)
1004 return rte_flow_error_set(error, EINVAL,
1005 RTE_FLOW_ERROR_TYPE_ITEM, item,
1006 "VLAN layer already configured");
1007 else if ((item_flags & l34m) != 0)
1008 return rte_flow_error_set(error, EINVAL,
1009 RTE_FLOW_ERROR_TYPE_ITEM, item,
1010 "L2 layer cannot follow L3/L4 layer");
1012 mask = &rte_flow_item_vlan_mask;
1013 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1014 (const uint8_t *)&nic_mask,
1015 sizeof(struct rte_flow_item_vlan),
1020 vlan_tag = spec->tci;
1021 vlan_tag &= mask->tci;
1024 * From verbs perspective an empty VLAN is equivalent
1025 * to a packet without VLAN layer.
1028 return rte_flow_error_set(error, EINVAL,
1029 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1031 "VLAN cannot be empty");
1036 * Validate IPV4 item.
1039 * Item specification.
1040 * @param[in] item_flags
1041 * Bit-fields that holds the items detected until now.
1043 * Pointer to error structure.
1046 * 0 on success, a negative errno value otherwise and rte_errno is set.
1049 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1051 struct rte_flow_error *error)
1053 const struct rte_flow_item_ipv4 *mask = item->mask;
1054 const struct rte_flow_item_ipv4 nic_mask = {
1056 .src_addr = RTE_BE32(0xffffffff),
1057 .dst_addr = RTE_BE32(0xffffffff),
1058 .type_of_service = 0xff,
1059 .next_proto_id = 0xff,
1062 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1065 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1066 MLX5_FLOW_LAYER_OUTER_L3))
1067 return rte_flow_error_set(error, ENOTSUP,
1068 RTE_FLOW_ERROR_TYPE_ITEM, item,
1069 "multiple L3 layers not supported");
1070 else if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1071 MLX5_FLOW_LAYER_OUTER_L4))
1072 return rte_flow_error_set(error, EINVAL,
1073 RTE_FLOW_ERROR_TYPE_ITEM, item,
1074 "L3 cannot follow an L4 layer.");
1076 mask = &rte_flow_item_ipv4_mask;
1077 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1078 (const uint8_t *)&nic_mask,
1079 sizeof(struct rte_flow_item_ipv4),
1087 * Validate IPV6 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_ipv6(const struct rte_flow_item *item,
1101 uint64_t item_flags,
1102 struct rte_flow_error *error)
1104 const struct rte_flow_item_ipv6 *mask = item->mask;
1105 const struct rte_flow_item_ipv6 nic_mask = {
1108 "\xff\xff\xff\xff\xff\xff\xff\xff"
1109 "\xff\xff\xff\xff\xff\xff\xff\xff",
1111 "\xff\xff\xff\xff\xff\xff\xff\xff"
1112 "\xff\xff\xff\xff\xff\xff\xff\xff",
1113 .vtc_flow = RTE_BE32(0xffffffff),
1118 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1121 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1122 MLX5_FLOW_LAYER_OUTER_L3))
1123 return rte_flow_error_set(error, ENOTSUP,
1124 RTE_FLOW_ERROR_TYPE_ITEM, item,
1125 "multiple L3 layers not supported");
1126 else if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1127 MLX5_FLOW_LAYER_OUTER_L4))
1128 return rte_flow_error_set(error, EINVAL,
1129 RTE_FLOW_ERROR_TYPE_ITEM, item,
1130 "L3 cannot follow an L4 layer.");
1132 * IPv6 is not recognised by the NIC inside a GRE tunnel.
1133 * Such support has to be disabled as the rule will be
1134 * accepted. Issue reproduced with Mellanox OFED 4.3-3.0.2.1 and
1135 * Mellanox OFED 4.4-1.0.0.0.
1137 if (tunnel && item_flags & MLX5_FLOW_LAYER_GRE)
1138 return rte_flow_error_set(error, ENOTSUP,
1139 RTE_FLOW_ERROR_TYPE_ITEM, item,
1140 "IPv6 inside a GRE tunnel is"
1141 " not recognised.");
1143 mask = &rte_flow_item_ipv6_mask;
1144 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1145 (const uint8_t *)&nic_mask,
1146 sizeof(struct rte_flow_item_ipv6),
1154 * Validate UDP item.
1157 * Item specification.
1158 * @param[in] item_flags
1159 * Bit-fields that holds the items detected until now.
1160 * @param[in] target_protocol
1161 * The next protocol in the previous item.
1163 * Pointer to error structure.
1166 * 0 on success, a negative errno value otherwise and rte_errno is set.
1169 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1170 uint64_t item_flags,
1171 uint8_t target_protocol,
1172 struct rte_flow_error *error)
1174 const struct rte_flow_item_udp *mask = item->mask;
1175 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1178 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1179 return rte_flow_error_set(error, EINVAL,
1180 RTE_FLOW_ERROR_TYPE_ITEM, item,
1181 "protocol filtering not compatible"
1183 if (!(item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1184 MLX5_FLOW_LAYER_OUTER_L3)))
1185 return rte_flow_error_set(error, EINVAL,
1186 RTE_FLOW_ERROR_TYPE_ITEM, item,
1187 "L3 is mandatory to filter on L4");
1188 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1189 MLX5_FLOW_LAYER_OUTER_L4))
1190 return rte_flow_error_set(error, EINVAL,
1191 RTE_FLOW_ERROR_TYPE_ITEM, item,
1192 "L4 layer is already present");
1194 mask = &rte_flow_item_udp_mask;
1195 ret = mlx5_flow_item_acceptable
1196 (item, (const uint8_t *)mask,
1197 (const uint8_t *)&rte_flow_item_udp_mask,
1198 sizeof(struct rte_flow_item_udp), error);
1205 * Validate TCP item.
1208 * Item specification.
1209 * @param[in] item_flags
1210 * Bit-fields that holds the items detected until now.
1211 * @param[in] target_protocol
1212 * The next protocol in the previous item.
1214 * Pointer to error structure.
1217 * 0 on success, a negative errno value otherwise and rte_errno is set.
1220 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1221 uint64_t item_flags,
1222 uint8_t target_protocol,
1223 struct rte_flow_error *error)
1225 const struct rte_flow_item_tcp *mask = item->mask;
1226 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1229 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1230 return rte_flow_error_set(error, EINVAL,
1231 RTE_FLOW_ERROR_TYPE_ITEM, item,
1232 "protocol filtering not compatible"
1234 if (!(item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1235 MLX5_FLOW_LAYER_OUTER_L3)))
1236 return rte_flow_error_set(error, EINVAL,
1237 RTE_FLOW_ERROR_TYPE_ITEM, item,
1238 "L3 is mandatory to filter on L4");
1239 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1240 MLX5_FLOW_LAYER_OUTER_L4))
1241 return rte_flow_error_set(error, EINVAL,
1242 RTE_FLOW_ERROR_TYPE_ITEM, item,
1243 "L4 layer is already present");
1245 mask = &rte_flow_item_tcp_mask;
1246 ret = mlx5_flow_item_acceptable
1247 (item, (const uint8_t *)mask,
1248 (const uint8_t *)&rte_flow_item_tcp_mask,
1249 sizeof(struct rte_flow_item_tcp), error);
1256 * Validate VXLAN item.
1259 * Item specification.
1260 * @param[in] item_flags
1261 * Bit-fields that holds the items detected until now.
1262 * @param[in] target_protocol
1263 * The next protocol in the previous item.
1265 * Pointer to error structure.
1268 * 0 on success, a negative errno value otherwise and rte_errno is set.
1271 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1272 uint64_t item_flags,
1273 struct rte_flow_error *error)
1275 const struct rte_flow_item_vxlan *spec = item->spec;
1276 const struct rte_flow_item_vxlan *mask = item->mask;
1281 } id = { .vlan_id = 0, };
1282 uint32_t vlan_id = 0;
1285 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1286 return rte_flow_error_set(error, ENOTSUP,
1287 RTE_FLOW_ERROR_TYPE_ITEM, item,
1288 "a tunnel is already present");
1290 * Verify only UDPv4 is present as defined in
1291 * https://tools.ietf.org/html/rfc7348
1293 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1294 return rte_flow_error_set(error, EINVAL,
1295 RTE_FLOW_ERROR_TYPE_ITEM, item,
1296 "no outer UDP layer found");
1298 mask = &rte_flow_item_vxlan_mask;
1299 ret = mlx5_flow_item_acceptable
1300 (item, (const uint8_t *)mask,
1301 (const uint8_t *)&rte_flow_item_vxlan_mask,
1302 sizeof(struct rte_flow_item_vxlan),
1307 memcpy(&id.vni[1], spec->vni, 3);
1308 vlan_id = id.vlan_id;
1309 memcpy(&id.vni[1], mask->vni, 3);
1310 vlan_id &= id.vlan_id;
1313 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1314 * only this layer is defined in the Verbs specification it is
1315 * interpreted as wildcard and all packets will match this
1316 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1317 * udp), all packets matching the layers before will also
1318 * match this rule. To avoid such situation, VNI 0 is
1319 * currently refused.
1322 return rte_flow_error_set(error, ENOTSUP,
1323 RTE_FLOW_ERROR_TYPE_ITEM, item,
1324 "VXLAN vni cannot be 0");
1325 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1326 return rte_flow_error_set(error, ENOTSUP,
1327 RTE_FLOW_ERROR_TYPE_ITEM, item,
1328 "VXLAN tunnel must be fully defined");
1333 * Validate VXLAN_GPE item.
1336 * Item specification.
1337 * @param[in] item_flags
1338 * Bit-fields that holds the items detected until now.
1340 * Pointer to the private data structure.
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_vxlan_gpe(const struct rte_flow_item *item,
1351 uint64_t item_flags,
1352 struct rte_eth_dev *dev,
1353 struct rte_flow_error *error)
1355 struct priv *priv = dev->data->dev_private;
1356 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1357 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1362 } id = { .vlan_id = 0, };
1363 uint32_t vlan_id = 0;
1365 if (!priv->config.l3_vxlan_en)
1366 return rte_flow_error_set(error, ENOTSUP,
1367 RTE_FLOW_ERROR_TYPE_ITEM, item,
1368 "L3 VXLAN is not enabled by device"
1369 " parameter and/or not configured in"
1371 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1372 return rte_flow_error_set(error, ENOTSUP,
1373 RTE_FLOW_ERROR_TYPE_ITEM, item,
1374 "a tunnel is already present");
1376 * Verify only UDPv4 is present as defined in
1377 * https://tools.ietf.org/html/rfc7348
1379 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1380 return rte_flow_error_set(error, EINVAL,
1381 RTE_FLOW_ERROR_TYPE_ITEM, item,
1382 "no outer UDP layer found");
1384 mask = &rte_flow_item_vxlan_gpe_mask;
1385 ret = mlx5_flow_item_acceptable
1386 (item, (const uint8_t *)mask,
1387 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1388 sizeof(struct rte_flow_item_vxlan_gpe),
1394 return rte_flow_error_set(error, ENOTSUP,
1395 RTE_FLOW_ERROR_TYPE_ITEM,
1397 "VxLAN-GPE protocol"
1399 memcpy(&id.vni[1], spec->vni, 3);
1400 vlan_id = id.vlan_id;
1401 memcpy(&id.vni[1], mask->vni, 3);
1402 vlan_id &= id.vlan_id;
1405 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1406 * layer is defined in the Verbs specification it is interpreted as
1407 * wildcard and all packets will match this rule, if it follows a full
1408 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1409 * before will also match this rule. To avoid such situation, VNI 0
1410 * is currently refused.
1413 return rte_flow_error_set(error, ENOTSUP,
1414 RTE_FLOW_ERROR_TYPE_ITEM, item,
1415 "VXLAN-GPE vni cannot be 0");
1416 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1417 return rte_flow_error_set(error, ENOTSUP,
1418 RTE_FLOW_ERROR_TYPE_ITEM, item,
1419 "VXLAN-GPE tunnel must be fully"
1425 * Validate GRE item.
1428 * Item specification.
1429 * @param[in] item_flags
1430 * Bit flags to mark detected items.
1431 * @param[in] target_protocol
1432 * The next protocol in the previous item.
1434 * Pointer to error structure.
1437 * 0 on success, a negative errno value otherwise and rte_errno is set.
1440 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
1441 uint64_t item_flags,
1442 uint8_t target_protocol,
1443 struct rte_flow_error *error)
1445 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
1446 const struct rte_flow_item_gre *mask = item->mask;
1449 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
1450 return rte_flow_error_set(error, EINVAL,
1451 RTE_FLOW_ERROR_TYPE_ITEM, item,
1452 "protocol filtering not compatible"
1453 " with this GRE layer");
1454 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1455 return rte_flow_error_set(error, ENOTSUP,
1456 RTE_FLOW_ERROR_TYPE_ITEM, item,
1457 "a tunnel is already present");
1458 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
1459 return rte_flow_error_set(error, ENOTSUP,
1460 RTE_FLOW_ERROR_TYPE_ITEM, item,
1461 "L3 Layer is missing");
1463 mask = &rte_flow_item_gre_mask;
1464 ret = mlx5_flow_item_acceptable
1465 (item, (const uint8_t *)mask,
1466 (const uint8_t *)&rte_flow_item_gre_mask,
1467 sizeof(struct rte_flow_item_gre), error);
1470 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
1471 if (spec && (spec->protocol & mask->protocol))
1472 return rte_flow_error_set(error, ENOTSUP,
1473 RTE_FLOW_ERROR_TYPE_ITEM, item,
1474 "without MPLS support the"
1475 " specification cannot be used for"
1482 * Validate MPLS item.
1485 * Item specification.
1486 * @param[in] item_flags
1487 * Bit-fields that holds the items detected until now.
1488 * @param[in] target_protocol
1489 * The next protocol in the previous item.
1491 * Pointer to error structure.
1494 * 0 on success, a negative errno value otherwise and rte_errno is set.
1497 mlx5_flow_validate_item_mpls(const struct rte_flow_item *item __rte_unused,
1498 uint64_t item_flags __rte_unused,
1499 uint8_t target_protocol __rte_unused,
1500 struct rte_flow_error *error)
1502 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
1503 const struct rte_flow_item_mpls *mask = item->mask;
1506 if (target_protocol != 0xff && target_protocol != IPPROTO_MPLS)
1507 return rte_flow_error_set(error, EINVAL,
1508 RTE_FLOW_ERROR_TYPE_ITEM, item,
1509 "protocol filtering not compatible"
1510 " with MPLS layer");
1511 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1512 return rte_flow_error_set(error, ENOTSUP,
1513 RTE_FLOW_ERROR_TYPE_ITEM, item,
1514 "a tunnel is already"
1517 mask = &rte_flow_item_mpls_mask;
1518 ret = mlx5_flow_item_acceptable
1519 (item, (const uint8_t *)mask,
1520 (const uint8_t *)&rte_flow_item_mpls_mask,
1521 sizeof(struct rte_flow_item_mpls), error);
1526 return rte_flow_error_set(error, ENOTSUP,
1527 RTE_FLOW_ERROR_TYPE_ITEM, item,
1528 "MPLS is not supported by Verbs, please"
1533 * Validate a flow supported by the NIC.
1535 * @see rte_flow_validate()
1539 mlx5_flow_validate(struct rte_eth_dev *dev,
1540 const struct rte_flow_attr *attr,
1541 const struct rte_flow_item items[],
1542 const struct rte_flow_action actions[],
1543 struct rte_flow_error *error)
1547 ret = nic_ops.validate(dev, attr, items, actions, error);
1554 * Get RSS action from the action list.
1556 * @param[in] actions
1557 * Pointer to the list of actions.
1560 * Pointer to the RSS action if exist, else return NULL.
1562 static const struct rte_flow_action_rss*
1563 mlx5_flow_get_rss_action(const struct rte_flow_action actions[])
1565 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1566 switch (actions->type) {
1567 case RTE_FLOW_ACTION_TYPE_RSS:
1568 return (const struct rte_flow_action_rss *)
1578 mlx5_find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
1580 const struct rte_flow_item *item;
1581 unsigned int has_vlan = 0;
1583 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1584 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1590 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
1591 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
1592 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
1593 MLX5_EXPANSION_ROOT_OUTER;
1597 * Create a flow and add it to @p list.
1600 * Pointer to Ethernet device.
1602 * Pointer to a TAILQ flow list.
1604 * Flow rule attributes.
1606 * Pattern specification (list terminated by the END pattern item).
1607 * @param[in] actions
1608 * Associated actions (list terminated by the END action).
1610 * Perform verbose error reporting if not NULL.
1613 * A flow on success, NULL otherwise and rte_errno is set.
1615 static struct rte_flow *
1616 mlx5_flow_list_create(struct rte_eth_dev *dev,
1617 struct mlx5_flows *list,
1618 const struct rte_flow_attr *attr,
1619 const struct rte_flow_item items[],
1620 const struct rte_flow_action actions[],
1621 struct rte_flow_error *error)
1623 struct rte_flow *flow = NULL;
1624 struct mlx5_flow *dev_flow;
1625 uint64_t action_flags = 0;
1626 uint64_t item_flags = 0;
1627 const struct rte_flow_action_rss *rss;
1629 struct rte_flow_expand_rss buf;
1630 uint8_t buffer[2048];
1632 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
1637 ret = mlx5_flow_validate(dev, attr, items, actions, error);
1640 flow_size = sizeof(struct rte_flow);
1641 rss = mlx5_flow_get_rss_action(actions);
1643 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
1646 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
1647 flow = rte_calloc(__func__, 1, flow_size, 0);
1648 flow->queue = (void *)(flow + 1);
1649 LIST_INIT(&flow->dev_flows);
1650 if (rss && rss->types) {
1651 unsigned int graph_root;
1653 graph_root = mlx5_find_graph_root(items, rss->level);
1654 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
1656 mlx5_support_expansion,
1659 (unsigned int)ret < sizeof(expand_buffer.buffer));
1662 buf->entry[0].pattern = (void *)(uintptr_t)items;
1664 for (i = 0; i < buf->entries; ++i) {
1665 dev_flow = nic_ops.prepare(attr, buf->entry[i].pattern,
1666 actions, &item_flags,
1667 &action_flags, error);
1670 dev_flow->flow = flow;
1671 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
1672 ret = nic_ops.translate(dev, dev_flow, attr,
1673 buf->entry[i].pattern,
1678 if (dev->data->dev_started) {
1679 ret = nic_ops.apply(dev, flow, error);
1683 TAILQ_INSERT_TAIL(list, flow, next);
1684 mlx5_flow_rxq_flags_set(dev, flow);
1687 ret = rte_errno; /* Save rte_errno before cleanup. */
1689 nic_ops.destroy(dev, flow);
1691 rte_errno = ret; /* Restore rte_errno. */
1698 * @see rte_flow_create()
1702 mlx5_flow_create(struct rte_eth_dev *dev,
1703 const struct rte_flow_attr *attr,
1704 const struct rte_flow_item items[],
1705 const struct rte_flow_action actions[],
1706 struct rte_flow_error *error)
1708 return mlx5_flow_list_create
1709 (dev, &((struct priv *)dev->data->dev_private)->flows,
1710 attr, items, actions, error);
1714 * Destroy a flow in a list.
1717 * Pointer to Ethernet device.
1719 * Pointer to a TAILQ flow list.
1724 mlx5_flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
1725 struct rte_flow *flow)
1727 nic_ops.destroy(dev, flow);
1728 TAILQ_REMOVE(list, flow, next);
1730 * Update RX queue flags only if port is started, otherwise it is
1733 if (dev->data->dev_started)
1734 mlx5_flow_rxq_flags_trim(dev, flow);
1739 * Destroy all flows.
1742 * Pointer to Ethernet device.
1744 * Pointer to a TAILQ flow list.
1747 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
1749 while (!TAILQ_EMPTY(list)) {
1750 struct rte_flow *flow;
1752 flow = TAILQ_FIRST(list);
1753 mlx5_flow_list_destroy(dev, list, flow);
1761 * Pointer to Ethernet device.
1763 * Pointer to a TAILQ flow list.
1766 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
1768 struct rte_flow *flow;
1770 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next)
1771 nic_ops.remove(dev, flow);
1772 mlx5_flow_rxq_flags_clear(dev);
1779 * Pointer to Ethernet device.
1781 * Pointer to a TAILQ flow list.
1784 * 0 on success, a negative errno value otherwise and rte_errno is set.
1787 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
1789 struct rte_flow *flow;
1790 struct rte_flow_error error;
1793 TAILQ_FOREACH(flow, list, next) {
1794 ret = nic_ops.apply(dev, flow, &error);
1797 mlx5_flow_rxq_flags_set(dev, flow);
1801 ret = rte_errno; /* Save rte_errno before cleanup. */
1802 mlx5_flow_stop(dev, list);
1803 rte_errno = ret; /* Restore rte_errno. */
1808 * Verify the flow list is empty
1811 * Pointer to Ethernet device.
1813 * @return the number of flows not released.
1816 mlx5_flow_verify(struct rte_eth_dev *dev)
1818 struct priv *priv = dev->data->dev_private;
1819 struct rte_flow *flow;
1822 TAILQ_FOREACH(flow, &priv->flows, next) {
1823 DRV_LOG(DEBUG, "port %u flow %p still referenced",
1824 dev->data->port_id, (void *)flow);
1831 * Enable a control flow configured from the control plane.
1834 * Pointer to Ethernet device.
1836 * An Ethernet flow spec to apply.
1838 * An Ethernet flow mask to apply.
1840 * A VLAN flow spec to apply.
1842 * A VLAN flow mask to apply.
1845 * 0 on success, a negative errno value otherwise and rte_errno is set.
1848 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
1849 struct rte_flow_item_eth *eth_spec,
1850 struct rte_flow_item_eth *eth_mask,
1851 struct rte_flow_item_vlan *vlan_spec,
1852 struct rte_flow_item_vlan *vlan_mask)
1854 struct priv *priv = dev->data->dev_private;
1855 const struct rte_flow_attr attr = {
1857 .priority = MLX5_FLOW_PRIO_RSVD,
1859 struct rte_flow_item items[] = {
1861 .type = RTE_FLOW_ITEM_TYPE_ETH,
1867 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
1868 RTE_FLOW_ITEM_TYPE_END,
1874 .type = RTE_FLOW_ITEM_TYPE_END,
1877 uint16_t queue[priv->reta_idx_n];
1878 struct rte_flow_action_rss action_rss = {
1879 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
1881 .types = priv->rss_conf.rss_hf,
1882 .key_len = priv->rss_conf.rss_key_len,
1883 .queue_num = priv->reta_idx_n,
1884 .key = priv->rss_conf.rss_key,
1887 struct rte_flow_action actions[] = {
1889 .type = RTE_FLOW_ACTION_TYPE_RSS,
1890 .conf = &action_rss,
1893 .type = RTE_FLOW_ACTION_TYPE_END,
1896 struct rte_flow *flow;
1897 struct rte_flow_error error;
1900 if (!priv->reta_idx_n) {
1904 for (i = 0; i != priv->reta_idx_n; ++i)
1905 queue[i] = (*priv->reta_idx)[i];
1906 flow = mlx5_flow_list_create(dev, &priv->ctrl_flows, &attr, items,
1914 * Enable a flow control configured from the control plane.
1917 * Pointer to Ethernet device.
1919 * An Ethernet flow spec to apply.
1921 * An Ethernet flow mask to apply.
1924 * 0 on success, a negative errno value otherwise and rte_errno is set.
1927 mlx5_ctrl_flow(struct rte_eth_dev *dev,
1928 struct rte_flow_item_eth *eth_spec,
1929 struct rte_flow_item_eth *eth_mask)
1931 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
1937 * @see rte_flow_destroy()
1941 mlx5_flow_destroy(struct rte_eth_dev *dev,
1942 struct rte_flow *flow,
1943 struct rte_flow_error *error __rte_unused)
1945 struct priv *priv = dev->data->dev_private;
1947 mlx5_flow_list_destroy(dev, &priv->flows, flow);
1952 * Destroy all flows.
1954 * @see rte_flow_flush()
1958 mlx5_flow_flush(struct rte_eth_dev *dev,
1959 struct rte_flow_error *error __rte_unused)
1961 struct priv *priv = dev->data->dev_private;
1963 mlx5_flow_list_flush(dev, &priv->flows);
1970 * @see rte_flow_isolate()
1974 mlx5_flow_isolate(struct rte_eth_dev *dev,
1976 struct rte_flow_error *error)
1978 struct priv *priv = dev->data->dev_private;
1980 if (dev->data->dev_started) {
1981 rte_flow_error_set(error, EBUSY,
1982 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1984 "port must be stopped first");
1987 priv->isolated = !!enable;
1989 dev->dev_ops = &mlx5_dev_ops_isolate;
1991 dev->dev_ops = &mlx5_dev_ops;
1996 * Query flow counter.
1999 * Pointer to the flow.
2002 * 0 on success, a negative errno value otherwise and rte_errno is set.
2005 mlx5_flow_query_count(struct rte_flow *flow __rte_unused,
2006 void *data __rte_unused,
2007 struct rte_flow_error *error)
2009 #ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
2010 if (flow->actions & MLX5_FLOW_ACTION_COUNT) {
2011 struct rte_flow_query_count *qc = data;
2012 uint64_t counters[2] = {0, 0};
2013 struct ibv_query_counter_set_attr query_cs_attr = {
2014 .cs = flow->counter->cs,
2015 .query_flags = IBV_COUNTER_SET_FORCE_UPDATE,
2017 struct ibv_counter_set_data query_out = {
2019 .outlen = 2 * sizeof(uint64_t),
2021 int err = mlx5_glue->query_counter_set(&query_cs_attr,
2025 return rte_flow_error_set
2027 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2029 "cannot read counter");
2032 qc->hits = counters[0] - flow->counter->hits;
2033 qc->bytes = counters[1] - flow->counter->bytes;
2035 flow->counter->hits = counters[0];
2036 flow->counter->bytes = counters[1];
2040 return rte_flow_error_set(error, ENOTSUP,
2041 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2043 "flow does not have counter");
2045 return rte_flow_error_set(error, ENOTSUP,
2046 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2048 "counters are not available");
2054 * @see rte_flow_query()
2058 mlx5_flow_query(struct rte_eth_dev *dev __rte_unused,
2059 struct rte_flow *flow,
2060 const struct rte_flow_action *actions,
2062 struct rte_flow_error *error)
2066 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2067 switch (actions->type) {
2068 case RTE_FLOW_ACTION_TYPE_VOID:
2070 case RTE_FLOW_ACTION_TYPE_COUNT:
2071 ret = mlx5_flow_query_count(flow, data, error);
2074 return rte_flow_error_set(error, ENOTSUP,
2075 RTE_FLOW_ERROR_TYPE_ACTION,
2077 "action not supported");
2086 * Convert a flow director filter to a generic flow.
2089 * Pointer to Ethernet device.
2090 * @param fdir_filter
2091 * Flow director filter to add.
2093 * Generic flow parameters structure.
2096 * 0 on success, a negative errno value otherwise and rte_errno is set.
2099 mlx5_fdir_filter_convert(struct rte_eth_dev *dev,
2100 const struct rte_eth_fdir_filter *fdir_filter,
2101 struct mlx5_fdir *attributes)
2103 struct priv *priv = dev->data->dev_private;
2104 const struct rte_eth_fdir_input *input = &fdir_filter->input;
2105 const struct rte_eth_fdir_masks *mask =
2106 &dev->data->dev_conf.fdir_conf.mask;
2108 /* Validate queue number. */
2109 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
2110 DRV_LOG(ERR, "port %u invalid queue number %d",
2111 dev->data->port_id, fdir_filter->action.rx_queue);
2115 attributes->attr.ingress = 1;
2116 attributes->items[0] = (struct rte_flow_item) {
2117 .type = RTE_FLOW_ITEM_TYPE_ETH,
2118 .spec = &attributes->l2,
2119 .mask = &attributes->l2_mask,
2121 switch (fdir_filter->action.behavior) {
2122 case RTE_ETH_FDIR_ACCEPT:
2123 attributes->actions[0] = (struct rte_flow_action){
2124 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
2125 .conf = &attributes->queue,
2128 case RTE_ETH_FDIR_REJECT:
2129 attributes->actions[0] = (struct rte_flow_action){
2130 .type = RTE_FLOW_ACTION_TYPE_DROP,
2134 DRV_LOG(ERR, "port %u invalid behavior %d",
2136 fdir_filter->action.behavior);
2137 rte_errno = ENOTSUP;
2140 attributes->queue.index = fdir_filter->action.rx_queue;
2142 switch (fdir_filter->input.flow_type) {
2143 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2144 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2145 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2146 attributes->l3.ipv4.hdr = (struct ipv4_hdr){
2147 .src_addr = input->flow.ip4_flow.src_ip,
2148 .dst_addr = input->flow.ip4_flow.dst_ip,
2149 .time_to_live = input->flow.ip4_flow.ttl,
2150 .type_of_service = input->flow.ip4_flow.tos,
2152 attributes->l3_mask.ipv4.hdr = (struct ipv4_hdr){
2153 .src_addr = mask->ipv4_mask.src_ip,
2154 .dst_addr = mask->ipv4_mask.dst_ip,
2155 .time_to_live = mask->ipv4_mask.ttl,
2156 .type_of_service = mask->ipv4_mask.tos,
2157 .next_proto_id = mask->ipv4_mask.proto,
2159 attributes->items[1] = (struct rte_flow_item){
2160 .type = RTE_FLOW_ITEM_TYPE_IPV4,
2161 .spec = &attributes->l3,
2162 .mask = &attributes->l3_mask,
2165 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2166 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2167 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2168 attributes->l3.ipv6.hdr = (struct ipv6_hdr){
2169 .hop_limits = input->flow.ipv6_flow.hop_limits,
2170 .proto = input->flow.ipv6_flow.proto,
2173 memcpy(attributes->l3.ipv6.hdr.src_addr,
2174 input->flow.ipv6_flow.src_ip,
2175 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2176 memcpy(attributes->l3.ipv6.hdr.dst_addr,
2177 input->flow.ipv6_flow.dst_ip,
2178 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2179 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
2180 mask->ipv6_mask.src_ip,
2181 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2182 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
2183 mask->ipv6_mask.dst_ip,
2184 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2185 attributes->items[1] = (struct rte_flow_item){
2186 .type = RTE_FLOW_ITEM_TYPE_IPV6,
2187 .spec = &attributes->l3,
2188 .mask = &attributes->l3_mask,
2192 DRV_LOG(ERR, "port %u invalid flow type%d",
2193 dev->data->port_id, fdir_filter->input.flow_type);
2194 rte_errno = ENOTSUP;
2198 switch (fdir_filter->input.flow_type) {
2199 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2200 attributes->l4.udp.hdr = (struct udp_hdr){
2201 .src_port = input->flow.udp4_flow.src_port,
2202 .dst_port = input->flow.udp4_flow.dst_port,
2204 attributes->l4_mask.udp.hdr = (struct udp_hdr){
2205 .src_port = mask->src_port_mask,
2206 .dst_port = mask->dst_port_mask,
2208 attributes->items[2] = (struct rte_flow_item){
2209 .type = RTE_FLOW_ITEM_TYPE_UDP,
2210 .spec = &attributes->l4,
2211 .mask = &attributes->l4_mask,
2214 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2215 attributes->l4.tcp.hdr = (struct tcp_hdr){
2216 .src_port = input->flow.tcp4_flow.src_port,
2217 .dst_port = input->flow.tcp4_flow.dst_port,
2219 attributes->l4_mask.tcp.hdr = (struct tcp_hdr){
2220 .src_port = mask->src_port_mask,
2221 .dst_port = mask->dst_port_mask,
2223 attributes->items[2] = (struct rte_flow_item){
2224 .type = RTE_FLOW_ITEM_TYPE_TCP,
2225 .spec = &attributes->l4,
2226 .mask = &attributes->l4_mask,
2229 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2230 attributes->l4.udp.hdr = (struct udp_hdr){
2231 .src_port = input->flow.udp6_flow.src_port,
2232 .dst_port = input->flow.udp6_flow.dst_port,
2234 attributes->l4_mask.udp.hdr = (struct udp_hdr){
2235 .src_port = mask->src_port_mask,
2236 .dst_port = mask->dst_port_mask,
2238 attributes->items[2] = (struct rte_flow_item){
2239 .type = RTE_FLOW_ITEM_TYPE_UDP,
2240 .spec = &attributes->l4,
2241 .mask = &attributes->l4_mask,
2244 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2245 attributes->l4.tcp.hdr = (struct tcp_hdr){
2246 .src_port = input->flow.tcp6_flow.src_port,
2247 .dst_port = input->flow.tcp6_flow.dst_port,
2249 attributes->l4_mask.tcp.hdr = (struct tcp_hdr){
2250 .src_port = mask->src_port_mask,
2251 .dst_port = mask->dst_port_mask,
2253 attributes->items[2] = (struct rte_flow_item){
2254 .type = RTE_FLOW_ITEM_TYPE_TCP,
2255 .spec = &attributes->l4,
2256 .mask = &attributes->l4_mask,
2259 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2260 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2263 DRV_LOG(ERR, "port %u invalid flow type%d",
2264 dev->data->port_id, fdir_filter->input.flow_type);
2265 rte_errno = ENOTSUP;
2272 * Add new flow director filter and store it in list.
2275 * Pointer to Ethernet device.
2276 * @param fdir_filter
2277 * Flow director filter to add.
2280 * 0 on success, a negative errno value otherwise and rte_errno is set.
2283 mlx5_fdir_filter_add(struct rte_eth_dev *dev,
2284 const struct rte_eth_fdir_filter *fdir_filter)
2286 struct priv *priv = dev->data->dev_private;
2287 struct mlx5_fdir attributes = {
2290 .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
2291 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
2295 struct rte_flow_error error;
2296 struct rte_flow *flow;
2299 ret = mlx5_fdir_filter_convert(dev, fdir_filter, &attributes);
2302 flow = mlx5_flow_list_create(dev, &priv->flows, &attributes.attr,
2303 attributes.items, attributes.actions,
2306 DRV_LOG(DEBUG, "port %u FDIR created %p", dev->data->port_id,
2314 * Delete specific filter.
2317 * Pointer to Ethernet device.
2318 * @param fdir_filter
2319 * Filter to be deleted.
2322 * 0 on success, a negative errno value otherwise and rte_errno is set.
2325 mlx5_fdir_filter_delete(struct rte_eth_dev *dev __rte_unused,
2326 const struct rte_eth_fdir_filter *fdir_filter
2329 rte_errno = ENOTSUP;
2334 * Update queue for specific filter.
2337 * Pointer to Ethernet device.
2338 * @param fdir_filter
2339 * Filter to be updated.
2342 * 0 on success, a negative errno value otherwise and rte_errno is set.
2345 mlx5_fdir_filter_update(struct rte_eth_dev *dev,
2346 const struct rte_eth_fdir_filter *fdir_filter)
2350 ret = mlx5_fdir_filter_delete(dev, fdir_filter);
2353 return mlx5_fdir_filter_add(dev, fdir_filter);
2357 * Flush all filters.
2360 * Pointer to Ethernet device.
2363 mlx5_fdir_filter_flush(struct rte_eth_dev *dev)
2365 struct priv *priv = dev->data->dev_private;
2367 mlx5_flow_list_flush(dev, &priv->flows);
2371 * Get flow director information.
2374 * Pointer to Ethernet device.
2375 * @param[out] fdir_info
2376 * Resulting flow director information.
2379 mlx5_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
2381 struct rte_eth_fdir_masks *mask =
2382 &dev->data->dev_conf.fdir_conf.mask;
2384 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
2385 fdir_info->guarant_spc = 0;
2386 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
2387 fdir_info->max_flexpayload = 0;
2388 fdir_info->flow_types_mask[0] = 0;
2389 fdir_info->flex_payload_unit = 0;
2390 fdir_info->max_flex_payload_segment_num = 0;
2391 fdir_info->flex_payload_limit = 0;
2392 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
2396 * Deal with flow director operations.
2399 * Pointer to Ethernet device.
2401 * Operation to perform.
2403 * Pointer to operation-specific structure.
2406 * 0 on success, a negative errno value otherwise and rte_errno is set.
2409 mlx5_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
2412 enum rte_fdir_mode fdir_mode =
2413 dev->data->dev_conf.fdir_conf.mode;
2415 if (filter_op == RTE_ETH_FILTER_NOP)
2417 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
2418 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2419 DRV_LOG(ERR, "port %u flow director mode %d not supported",
2420 dev->data->port_id, fdir_mode);
2424 switch (filter_op) {
2425 case RTE_ETH_FILTER_ADD:
2426 return mlx5_fdir_filter_add(dev, arg);
2427 case RTE_ETH_FILTER_UPDATE:
2428 return mlx5_fdir_filter_update(dev, arg);
2429 case RTE_ETH_FILTER_DELETE:
2430 return mlx5_fdir_filter_delete(dev, arg);
2431 case RTE_ETH_FILTER_FLUSH:
2432 mlx5_fdir_filter_flush(dev);
2434 case RTE_ETH_FILTER_INFO:
2435 mlx5_fdir_info_get(dev, arg);
2438 DRV_LOG(DEBUG, "port %u unknown operation %u",
2439 dev->data->port_id, filter_op);
2447 * Manage filter operations.
2450 * Pointer to Ethernet device structure.
2451 * @param filter_type
2454 * Operation to perform.
2456 * Pointer to operation-specific structure.
2459 * 0 on success, a negative errno value otherwise and rte_errno is set.
2462 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
2463 enum rte_filter_type filter_type,
2464 enum rte_filter_op filter_op,
2467 switch (filter_type) {
2468 case RTE_ETH_FILTER_GENERIC:
2469 if (filter_op != RTE_ETH_FILTER_GET) {
2473 *(const void **)arg = &mlx5_flow_ops;
2475 case RTE_ETH_FILTER_FDIR:
2476 return mlx5_fdir_ctrl_func(dev, filter_op, arg);
2478 DRV_LOG(ERR, "port %u filter type (%d) not supported",
2479 dev->data->port_id, filter_type);
2480 rte_errno = ENOTSUP;
2487 * Init the driver ops structure.
2490 * Pointer to Ethernet device structure.
2493 mlx5_flow_init_driver_ops(struct rte_eth_dev *dev)
2495 struct priv *priv __rte_unused = dev->data->dev_private;
2497 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
2498 if (priv->config.dv_flow_en)
2499 mlx5_flow_dv_get_driver_ops(&nic_ops);
2501 mlx5_flow_verbs_get_driver_ops(&nic_ops);
2503 mlx5_flow_verbs_get_driver_ops(&nic_ops);