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 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
449 * if several tunnel rules are used on this queue, the tunnel ptype will be
453 * Rx queue to update.
456 mlx5_flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
459 uint32_t tunnel_ptype = 0;
461 /* Look up for the ptype to use. */
462 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
463 if (!rxq_ctrl->flow_tunnels_n[i])
466 tunnel_ptype = tunnels_info[i].ptype;
472 rxq_ctrl->rxq.tunnel = tunnel_ptype;
476 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the flow.
479 * Pointer to the Ethernet device structure.
481 * Pointer to flow structure.
484 mlx5_flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
486 struct priv *priv = dev->data->dev_private;
487 const int mark = !!(flow->actions &
488 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
489 const int tunnel = !!(flow->layers & MLX5_FLOW_LAYER_TUNNEL);
492 for (i = 0; i != flow->rss.queue_num; ++i) {
493 int idx = (*flow->queue)[i];
494 struct mlx5_rxq_ctrl *rxq_ctrl =
495 container_of((*priv->rxqs)[idx],
496 struct mlx5_rxq_ctrl, rxq);
499 rxq_ctrl->rxq.mark = 1;
500 rxq_ctrl->flow_mark_n++;
505 /* Increase the counter matching the flow. */
506 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
507 if ((tunnels_info[j].tunnel & flow->layers) ==
508 tunnels_info[j].tunnel) {
509 rxq_ctrl->flow_tunnels_n[j]++;
513 mlx5_flow_rxq_tunnel_ptype_update(rxq_ctrl);
519 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
520 * @p flow if no other flow uses it with the same kind of request.
523 * Pointer to Ethernet device.
525 * Pointer to the flow.
528 mlx5_flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
530 struct priv *priv = dev->data->dev_private;
531 const int mark = !!(flow->actions &
532 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
533 const int tunnel = !!(flow->layers & MLX5_FLOW_LAYER_TUNNEL);
536 assert(dev->data->dev_started);
537 for (i = 0; i != flow->rss.queue_num; ++i) {
538 int idx = (*flow->queue)[i];
539 struct mlx5_rxq_ctrl *rxq_ctrl =
540 container_of((*priv->rxqs)[idx],
541 struct mlx5_rxq_ctrl, rxq);
544 rxq_ctrl->flow_mark_n--;
545 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
550 /* Decrease the counter matching the flow. */
551 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
552 if ((tunnels_info[j].tunnel & flow->layers) ==
553 tunnels_info[j].tunnel) {
554 rxq_ctrl->flow_tunnels_n[j]--;
558 mlx5_flow_rxq_tunnel_ptype_update(rxq_ctrl);
564 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
567 * Pointer to Ethernet device.
570 mlx5_flow_rxq_flags_clear(struct rte_eth_dev *dev)
572 struct priv *priv = dev->data->dev_private;
575 for (i = 0; i != priv->rxqs_n; ++i) {
576 struct mlx5_rxq_ctrl *rxq_ctrl;
579 if (!(*priv->rxqs)[i])
581 rxq_ctrl = container_of((*priv->rxqs)[i],
582 struct mlx5_rxq_ctrl, rxq);
583 rxq_ctrl->flow_mark_n = 0;
584 rxq_ctrl->rxq.mark = 0;
585 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
586 rxq_ctrl->flow_tunnels_n[j] = 0;
587 rxq_ctrl->rxq.tunnel = 0;
592 * Validate the flag action.
594 * @param[in] action_flags
595 * Bit-fields that holds the actions detected until now.
597 * Pointer to error structure.
600 * 0 on success, a negative errno value otherwise and rte_errno is set.
603 mlx5_flow_validate_action_flag(uint64_t action_flags,
604 struct rte_flow_error *error)
607 if (action_flags & MLX5_FLOW_ACTION_DROP)
608 return rte_flow_error_set(error, EINVAL,
609 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
610 "can't drop and flag in same flow");
611 if (action_flags & MLX5_FLOW_ACTION_MARK)
612 return rte_flow_error_set(error, EINVAL,
613 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
614 "can't mark and flag in same flow");
615 if (action_flags & MLX5_FLOW_ACTION_FLAG)
616 return rte_flow_error_set(error, EINVAL,
617 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
619 " actions in same flow");
624 * Validate the mark action.
627 * Pointer to the queue action.
628 * @param[in] action_flags
629 * Bit-fields that holds the actions detected until now.
631 * Pointer to error structure.
634 * 0 on success, a negative errno value otherwise and rte_errno is set.
637 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
638 uint64_t action_flags,
639 struct rte_flow_error *error)
641 const struct rte_flow_action_mark *mark = action->conf;
644 return rte_flow_error_set(error, EINVAL,
645 RTE_FLOW_ERROR_TYPE_ACTION,
647 "configuration cannot be null");
648 if (mark->id >= MLX5_FLOW_MARK_MAX)
649 return rte_flow_error_set(error, EINVAL,
650 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
652 "mark id must in 0 <= id < "
653 RTE_STR(MLX5_FLOW_MARK_MAX));
654 if (action_flags & MLX5_FLOW_ACTION_DROP)
655 return rte_flow_error_set(error, EINVAL,
656 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
657 "can't drop and mark in same flow");
658 if (action_flags & MLX5_FLOW_ACTION_FLAG)
659 return rte_flow_error_set(error, EINVAL,
660 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
661 "can't flag and mark in same flow");
662 if (action_flags & MLX5_FLOW_ACTION_MARK)
663 return rte_flow_error_set(error, EINVAL,
664 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
665 "can't have 2 mark actions in same"
671 * Validate the drop action.
673 * @param[in] action_flags
674 * Bit-fields that holds the actions detected until now.
676 * Pointer to error structure.
679 * 0 on success, a negative errno value otherwise and rte_ernno is set.
682 mlx5_flow_validate_action_drop(uint64_t action_flags,
683 struct rte_flow_error *error)
685 if (action_flags & MLX5_FLOW_ACTION_FLAG)
686 return rte_flow_error_set(error, EINVAL,
687 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
688 "can't drop and flag in same flow");
689 if (action_flags & MLX5_FLOW_ACTION_MARK)
690 return rte_flow_error_set(error, EINVAL,
691 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
692 "can't drop and mark in same flow");
693 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
694 return rte_flow_error_set(error, EINVAL,
695 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
696 "can't have 2 fate actions in"
702 * Validate the queue action.
705 * Pointer to the queue action.
706 * @param[in] action_flags
707 * Bit-fields that holds the actions detected until now.
709 * Pointer to the Ethernet device structure.
711 * Pointer to error structure.
714 * 0 on success, a negative errno value otherwise and rte_ernno is set.
717 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
718 uint64_t action_flags,
719 struct rte_eth_dev *dev,
720 struct rte_flow_error *error)
722 struct priv *priv = dev->data->dev_private;
723 const struct rte_flow_action_queue *queue = action->conf;
725 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
726 return rte_flow_error_set(error, EINVAL,
727 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
728 "can't have 2 fate actions in"
730 if (queue->index >= priv->rxqs_n)
731 return rte_flow_error_set(error, EINVAL,
732 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
734 "queue index out of range");
735 if (!(*priv->rxqs)[queue->index])
736 return rte_flow_error_set(error, EINVAL,
737 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
739 "queue is not configured");
744 * Validate the rss action.
747 * Pointer to the queue action.
748 * @param[in] action_flags
749 * Bit-fields that holds the actions detected until now.
751 * Pointer to the Ethernet device structure.
753 * Pointer to error structure.
756 * 0 on success, a negative errno value otherwise and rte_ernno is set.
759 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
760 uint64_t action_flags,
761 struct rte_eth_dev *dev,
762 struct rte_flow_error *error)
764 struct priv *priv = dev->data->dev_private;
765 const struct rte_flow_action_rss *rss = action->conf;
768 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
769 return rte_flow_error_set(error, EINVAL,
770 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
771 "can't have 2 fate actions"
773 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
774 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
775 return rte_flow_error_set(error, ENOTSUP,
776 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
778 "RSS hash function not supported");
779 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
784 return rte_flow_error_set(error, ENOTSUP,
785 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
787 "tunnel RSS is not supported");
788 if (rss->key_len < MLX5_RSS_HASH_KEY_LEN)
789 return rte_flow_error_set(error, ENOTSUP,
790 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
792 "RSS hash key too small");
793 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
794 return rte_flow_error_set(error, ENOTSUP,
795 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
797 "RSS hash key too large");
798 if (rss->queue_num > priv->config.ind_table_max_size)
799 return rte_flow_error_set(error, ENOTSUP,
800 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
802 "number of queues too large");
803 if (rss->types & MLX5_RSS_HF_MASK)
804 return rte_flow_error_set(error, ENOTSUP,
805 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
807 "some RSS protocols are not"
809 for (i = 0; i != rss->queue_num; ++i) {
810 if (!(*priv->rxqs)[rss->queue[i]])
811 return rte_flow_error_set
812 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
813 &rss->queue[i], "queue is not configured");
819 * Validate the count action.
822 * Pointer to the Ethernet device structure.
824 * Pointer to error structure.
827 * 0 on success, a negative errno value otherwise and rte_ernno is set.
830 mlx5_flow_validate_action_count(struct rte_eth_dev *dev,
831 struct rte_flow_error *error)
833 struct priv *priv = dev->data->dev_private;
835 if (!priv->config.flow_counter_en)
836 return rte_flow_error_set(error, ENOTSUP,
837 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
838 "flow counters are not supported.");
843 * Verify the @p attributes will be correctly understood by the NIC and store
844 * them in the @p flow if everything is correct.
847 * Pointer to the Ethernet device structure.
848 * @param[in] attributes
849 * Pointer to flow attributes
851 * Pointer to error structure.
854 * 0 on success, a negative errno value otherwise and rte_errno is set.
857 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
858 const struct rte_flow_attr *attributes,
859 struct rte_flow_error *error)
861 struct priv *priv = dev->data->dev_private;
862 uint32_t priority_max = priv->config.flow_prio - 1;
864 if (attributes->group)
865 return rte_flow_error_set(error, ENOTSUP,
866 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
867 NULL, "groups is not supported");
868 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
869 attributes->priority >= priority_max)
870 return rte_flow_error_set(error, ENOTSUP,
871 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
872 NULL, "priority out of range");
873 if (attributes->egress)
874 return rte_flow_error_set(error, ENOTSUP,
875 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
876 "egress is not supported");
877 if (attributes->transfer)
878 return rte_flow_error_set(error, ENOTSUP,
879 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
880 NULL, "transfer is not supported");
881 if (!attributes->ingress)
882 return rte_flow_error_set(error, EINVAL,
883 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
885 "ingress attribute is mandatory");
890 * Validate Ethernet item.
893 * Item specification.
894 * @param[in] item_flags
895 * Bit-fields that holds the items detected until now.
897 * Pointer to error structure.
900 * 0 on success, a negative errno value otherwise and rte_errno is set.
903 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
905 struct rte_flow_error *error)
907 const struct rte_flow_item_eth *mask = item->mask;
908 const struct rte_flow_item_eth nic_mask = {
909 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
910 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
911 .type = RTE_BE16(0xffff),
914 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
916 if (item_flags & MLX5_FLOW_LAYER_OUTER_L2)
917 return rte_flow_error_set(error, ENOTSUP,
918 RTE_FLOW_ERROR_TYPE_ITEM, item,
919 "3 levels of l2 are not supported");
920 if ((item_flags & MLX5_FLOW_LAYER_INNER_L2) && !tunnel)
921 return rte_flow_error_set(error, ENOTSUP,
922 RTE_FLOW_ERROR_TYPE_ITEM, item,
923 "2 L2 without tunnel are not supported");
925 mask = &rte_flow_item_eth_mask;
926 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
927 (const uint8_t *)&nic_mask,
928 sizeof(struct rte_flow_item_eth),
934 * Validate VLAN item.
937 * Item specification.
938 * @param[in] item_flags
939 * Bit-fields that holds the items detected until now.
941 * Pointer to error structure.
944 * 0 on success, a negative errno value otherwise and rte_errno is set.
947 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
949 struct rte_flow_error *error)
951 const struct rte_flow_item_vlan *spec = item->spec;
952 const struct rte_flow_item_vlan *mask = item->mask;
953 const struct rte_flow_item_vlan nic_mask = {
954 .tci = RTE_BE16(0x0fff),
955 .inner_type = RTE_BE16(0xffff),
957 uint16_t vlan_tag = 0;
958 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
960 const uint32_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
961 MLX5_FLOW_LAYER_INNER_L4) :
962 (MLX5_FLOW_LAYER_OUTER_L3 |
963 MLX5_FLOW_LAYER_OUTER_L4);
964 const uint32_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
965 MLX5_FLOW_LAYER_OUTER_VLAN;
967 if (item_flags & vlanm)
968 return rte_flow_error_set(error, EINVAL,
969 RTE_FLOW_ERROR_TYPE_ITEM, item,
970 "VLAN layer already configured");
971 else if ((item_flags & l34m) != 0)
972 return rte_flow_error_set(error, EINVAL,
973 RTE_FLOW_ERROR_TYPE_ITEM, item,
974 "L2 layer cannot follow L3/L4 layer");
976 mask = &rte_flow_item_vlan_mask;
977 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
978 (const uint8_t *)&nic_mask,
979 sizeof(struct rte_flow_item_vlan),
984 vlan_tag = spec->tci;
985 vlan_tag &= mask->tci;
988 * From verbs perspective an empty VLAN is equivalent
989 * to a packet without VLAN layer.
992 return rte_flow_error_set(error, EINVAL,
993 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
995 "VLAN cannot be empty");
1000 * Validate IPV4 item.
1003 * Item specification.
1004 * @param[in] item_flags
1005 * Bit-fields that holds the items detected until now.
1007 * Pointer to error structure.
1010 * 0 on success, a negative errno value otherwise and rte_errno is set.
1013 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1015 struct rte_flow_error *error)
1017 const struct rte_flow_item_ipv4 *mask = item->mask;
1018 const struct rte_flow_item_ipv4 nic_mask = {
1020 .src_addr = RTE_BE32(0xffffffff),
1021 .dst_addr = RTE_BE32(0xffffffff),
1022 .type_of_service = 0xff,
1023 .next_proto_id = 0xff,
1026 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1029 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1030 MLX5_FLOW_LAYER_OUTER_L3))
1031 return rte_flow_error_set(error, ENOTSUP,
1032 RTE_FLOW_ERROR_TYPE_ITEM, item,
1033 "multiple L3 layers not supported");
1034 else if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1035 MLX5_FLOW_LAYER_OUTER_L4))
1036 return rte_flow_error_set(error, EINVAL,
1037 RTE_FLOW_ERROR_TYPE_ITEM, item,
1038 "L3 cannot follow an L4 layer.");
1040 mask = &rte_flow_item_ipv4_mask;
1041 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1042 (const uint8_t *)&nic_mask,
1043 sizeof(struct rte_flow_item_ipv4),
1051 * Validate IPV6 item.
1054 * Item specification.
1055 * @param[in] item_flags
1056 * Bit-fields that holds the items detected until now.
1058 * Pointer to error structure.
1061 * 0 on success, a negative errno value otherwise and rte_errno is set.
1064 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1065 uint64_t item_flags,
1066 struct rte_flow_error *error)
1068 const struct rte_flow_item_ipv6 *mask = item->mask;
1069 const struct rte_flow_item_ipv6 nic_mask = {
1072 "\xff\xff\xff\xff\xff\xff\xff\xff"
1073 "\xff\xff\xff\xff\xff\xff\xff\xff",
1075 "\xff\xff\xff\xff\xff\xff\xff\xff"
1076 "\xff\xff\xff\xff\xff\xff\xff\xff",
1077 .vtc_flow = RTE_BE32(0xffffffff),
1082 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1085 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1086 MLX5_FLOW_LAYER_OUTER_L3))
1087 return rte_flow_error_set(error, ENOTSUP,
1088 RTE_FLOW_ERROR_TYPE_ITEM, item,
1089 "multiple L3 layers not supported");
1090 else if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1091 MLX5_FLOW_LAYER_OUTER_L4))
1092 return rte_flow_error_set(error, EINVAL,
1093 RTE_FLOW_ERROR_TYPE_ITEM, item,
1094 "L3 cannot follow an L4 layer.");
1096 * IPv6 is not recognised by the NIC inside a GRE tunnel.
1097 * Such support has to be disabled as the rule will be
1098 * accepted. Issue reproduced with Mellanox OFED 4.3-3.0.2.1 and
1099 * Mellanox OFED 4.4-1.0.0.0.
1101 if (tunnel && item_flags & MLX5_FLOW_LAYER_GRE)
1102 return rte_flow_error_set(error, ENOTSUP,
1103 RTE_FLOW_ERROR_TYPE_ITEM, item,
1104 "IPv6 inside a GRE tunnel is"
1105 " not recognised.");
1107 mask = &rte_flow_item_ipv6_mask;
1108 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1109 (const uint8_t *)&nic_mask,
1110 sizeof(struct rte_flow_item_ipv6),
1118 * Validate UDP item.
1121 * Item specification.
1122 * @param[in] item_flags
1123 * Bit-fields that holds the items detected until now.
1124 * @param[in] target_protocol
1125 * The next protocol in the previous item.
1127 * Pointer to error structure.
1130 * 0 on success, a negative errno value otherwise and rte_errno is set.
1133 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1134 uint64_t item_flags,
1135 uint8_t target_protocol,
1136 struct rte_flow_error *error)
1138 const struct rte_flow_item_udp *mask = item->mask;
1139 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1142 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1143 return rte_flow_error_set(error, EINVAL,
1144 RTE_FLOW_ERROR_TYPE_ITEM, item,
1145 "protocol filtering not compatible"
1147 if (!(item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1148 MLX5_FLOW_LAYER_OUTER_L3)))
1149 return rte_flow_error_set(error, EINVAL,
1150 RTE_FLOW_ERROR_TYPE_ITEM, item,
1151 "L3 is mandatory to filter on L4");
1152 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1153 MLX5_FLOW_LAYER_OUTER_L4))
1154 return rte_flow_error_set(error, EINVAL,
1155 RTE_FLOW_ERROR_TYPE_ITEM, item,
1156 "L4 layer is already present");
1158 mask = &rte_flow_item_udp_mask;
1159 ret = mlx5_flow_item_acceptable
1160 (item, (const uint8_t *)mask,
1161 (const uint8_t *)&rte_flow_item_udp_mask,
1162 sizeof(struct rte_flow_item_udp), error);
1169 * Validate TCP item.
1172 * Item specification.
1173 * @param[in] item_flags
1174 * Bit-fields that holds the items detected until now.
1175 * @param[in] target_protocol
1176 * The next protocol in the previous item.
1178 * Pointer to error structure.
1181 * 0 on success, a negative errno value otherwise and rte_errno is set.
1184 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1185 uint64_t item_flags,
1186 uint8_t target_protocol,
1187 struct rte_flow_error *error)
1189 const struct rte_flow_item_tcp *mask = item->mask;
1190 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1193 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1194 return rte_flow_error_set(error, EINVAL,
1195 RTE_FLOW_ERROR_TYPE_ITEM, item,
1196 "protocol filtering not compatible"
1198 if (!(item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1199 MLX5_FLOW_LAYER_OUTER_L3)))
1200 return rte_flow_error_set(error, EINVAL,
1201 RTE_FLOW_ERROR_TYPE_ITEM, item,
1202 "L3 is mandatory to filter on L4");
1203 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1204 MLX5_FLOW_LAYER_OUTER_L4))
1205 return rte_flow_error_set(error, EINVAL,
1206 RTE_FLOW_ERROR_TYPE_ITEM, item,
1207 "L4 layer is already present");
1209 mask = &rte_flow_item_tcp_mask;
1210 ret = mlx5_flow_item_acceptable
1211 (item, (const uint8_t *)mask,
1212 (const uint8_t *)&rte_flow_item_tcp_mask,
1213 sizeof(struct rte_flow_item_tcp), error);
1220 * Validate VXLAN item.
1223 * Item specification.
1224 * @param[in] item_flags
1225 * Bit-fields that holds the items detected until now.
1226 * @param[in] target_protocol
1227 * The next protocol in the previous item.
1229 * Pointer to error structure.
1232 * 0 on success, a negative errno value otherwise and rte_errno is set.
1235 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1236 uint64_t item_flags,
1237 struct rte_flow_error *error)
1239 const struct rte_flow_item_vxlan *spec = item->spec;
1240 const struct rte_flow_item_vxlan *mask = item->mask;
1245 } id = { .vlan_id = 0, };
1246 uint32_t vlan_id = 0;
1249 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1250 return rte_flow_error_set(error, ENOTSUP,
1251 RTE_FLOW_ERROR_TYPE_ITEM, item,
1252 "a tunnel is already present");
1254 * Verify only UDPv4 is present as defined in
1255 * https://tools.ietf.org/html/rfc7348
1257 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1258 return rte_flow_error_set(error, EINVAL,
1259 RTE_FLOW_ERROR_TYPE_ITEM, item,
1260 "no outer UDP layer found");
1262 mask = &rte_flow_item_vxlan_mask;
1263 ret = mlx5_flow_item_acceptable
1264 (item, (const uint8_t *)mask,
1265 (const uint8_t *)&rte_flow_item_vxlan_mask,
1266 sizeof(struct rte_flow_item_vxlan),
1271 memcpy(&id.vni[1], spec->vni, 3);
1272 vlan_id = id.vlan_id;
1273 memcpy(&id.vni[1], mask->vni, 3);
1274 vlan_id &= id.vlan_id;
1277 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1278 * only this layer is defined in the Verbs specification it is
1279 * interpreted as wildcard and all packets will match this
1280 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1281 * udp), all packets matching the layers before will also
1282 * match this rule. To avoid such situation, VNI 0 is
1283 * currently refused.
1286 return rte_flow_error_set(error, ENOTSUP,
1287 RTE_FLOW_ERROR_TYPE_ITEM, item,
1288 "VXLAN vni cannot be 0");
1289 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1290 return rte_flow_error_set(error, ENOTSUP,
1291 RTE_FLOW_ERROR_TYPE_ITEM, item,
1292 "VXLAN tunnel must be fully defined");
1297 * Validate VXLAN_GPE item.
1300 * Item specification.
1301 * @param[in] item_flags
1302 * Bit-fields that holds the items detected until now.
1304 * Pointer to the private data structure.
1305 * @param[in] target_protocol
1306 * The next protocol in the previous item.
1308 * Pointer to error structure.
1311 * 0 on success, a negative errno value otherwise and rte_errno is set.
1314 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1315 uint64_t item_flags,
1316 struct rte_eth_dev *dev,
1317 struct rte_flow_error *error)
1319 struct priv *priv = dev->data->dev_private;
1320 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1321 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1326 } id = { .vlan_id = 0, };
1327 uint32_t vlan_id = 0;
1329 if (!priv->config.l3_vxlan_en)
1330 return rte_flow_error_set(error, ENOTSUP,
1331 RTE_FLOW_ERROR_TYPE_ITEM, item,
1332 "L3 VXLAN is not enabled by device"
1333 " parameter and/or not configured in"
1335 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1336 return rte_flow_error_set(error, ENOTSUP,
1337 RTE_FLOW_ERROR_TYPE_ITEM, item,
1338 "a tunnel is already present");
1340 * Verify only UDPv4 is present as defined in
1341 * https://tools.ietf.org/html/rfc7348
1343 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1344 return rte_flow_error_set(error, EINVAL,
1345 RTE_FLOW_ERROR_TYPE_ITEM, item,
1346 "no outer UDP layer found");
1348 mask = &rte_flow_item_vxlan_gpe_mask;
1349 ret = mlx5_flow_item_acceptable
1350 (item, (const uint8_t *)mask,
1351 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1352 sizeof(struct rte_flow_item_vxlan_gpe),
1358 return rte_flow_error_set(error, ENOTSUP,
1359 RTE_FLOW_ERROR_TYPE_ITEM,
1361 "VxLAN-GPE protocol"
1363 memcpy(&id.vni[1], spec->vni, 3);
1364 vlan_id = id.vlan_id;
1365 memcpy(&id.vni[1], mask->vni, 3);
1366 vlan_id &= id.vlan_id;
1369 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1370 * layer is defined in the Verbs specification it is interpreted as
1371 * wildcard and all packets will match this rule, if it follows a full
1372 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1373 * before will also match this rule. To avoid such situation, VNI 0
1374 * is currently refused.
1377 return rte_flow_error_set(error, ENOTSUP,
1378 RTE_FLOW_ERROR_TYPE_ITEM, item,
1379 "VXLAN-GPE vni cannot be 0");
1380 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1381 return rte_flow_error_set(error, ENOTSUP,
1382 RTE_FLOW_ERROR_TYPE_ITEM, item,
1383 "VXLAN-GPE tunnel must be fully"
1389 * Validate GRE item.
1392 * Item specification.
1393 * @param[in] item_flags
1394 * Bit flags to mark detected items.
1395 * @param[in] target_protocol
1396 * The next protocol in the previous item.
1398 * Pointer to error structure.
1401 * 0 on success, a negative errno value otherwise and rte_errno is set.
1404 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
1405 uint64_t item_flags,
1406 uint8_t target_protocol,
1407 struct rte_flow_error *error)
1409 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
1410 const struct rte_flow_item_gre *mask = item->mask;
1413 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
1414 return rte_flow_error_set(error, EINVAL,
1415 RTE_FLOW_ERROR_TYPE_ITEM, item,
1416 "protocol filtering not compatible"
1417 " with this GRE layer");
1418 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1419 return rte_flow_error_set(error, ENOTSUP,
1420 RTE_FLOW_ERROR_TYPE_ITEM, item,
1421 "a tunnel is already present");
1422 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
1423 return rte_flow_error_set(error, ENOTSUP,
1424 RTE_FLOW_ERROR_TYPE_ITEM, item,
1425 "L3 Layer is missing");
1427 mask = &rte_flow_item_gre_mask;
1428 ret = mlx5_flow_item_acceptable
1429 (item, (const uint8_t *)mask,
1430 (const uint8_t *)&rte_flow_item_gre_mask,
1431 sizeof(struct rte_flow_item_gre), error);
1434 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
1435 if (spec && (spec->protocol & mask->protocol))
1436 return rte_flow_error_set(error, ENOTSUP,
1437 RTE_FLOW_ERROR_TYPE_ITEM, item,
1438 "without MPLS support the"
1439 " specification cannot be used for"
1446 * Validate MPLS item.
1449 * Item specification.
1450 * @param[in] item_flags
1451 * Bit-fields that holds the items detected until now.
1452 * @param[in] target_protocol
1453 * The next protocol in the previous item.
1455 * Pointer to error structure.
1458 * 0 on success, a negative errno value otherwise and rte_errno is set.
1461 mlx5_flow_validate_item_mpls(const struct rte_flow_item *item __rte_unused,
1462 uint64_t item_flags __rte_unused,
1463 uint8_t target_protocol __rte_unused,
1464 struct rte_flow_error *error)
1466 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
1467 const struct rte_flow_item_mpls *mask = item->mask;
1470 if (target_protocol != 0xff && target_protocol != IPPROTO_MPLS)
1471 return rte_flow_error_set(error, EINVAL,
1472 RTE_FLOW_ERROR_TYPE_ITEM, item,
1473 "protocol filtering not compatible"
1474 " with MPLS layer");
1475 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1476 return rte_flow_error_set(error, ENOTSUP,
1477 RTE_FLOW_ERROR_TYPE_ITEM, item,
1478 "a tunnel is already"
1481 mask = &rte_flow_item_mpls_mask;
1482 ret = mlx5_flow_item_acceptable
1483 (item, (const uint8_t *)mask,
1484 (const uint8_t *)&rte_flow_item_mpls_mask,
1485 sizeof(struct rte_flow_item_mpls), error);
1490 return rte_flow_error_set(error, ENOTSUP,
1491 RTE_FLOW_ERROR_TYPE_ITEM, item,
1492 "MPLS is not supported by Verbs, please"
1497 * Validate a flow supported by the NIC.
1499 * @see rte_flow_validate()
1503 mlx5_flow_validate(struct rte_eth_dev *dev,
1504 const struct rte_flow_attr *attr,
1505 const struct rte_flow_item items[],
1506 const struct rte_flow_action actions[],
1507 struct rte_flow_error *error)
1511 ret = nic_ops.validate(dev, attr, items, actions, error);
1518 * Get RSS action from the action list.
1520 * @param[in] actions
1521 * Pointer to the list of actions.
1524 * Pointer to the RSS action if exist, else return NULL.
1526 static const struct rte_flow_action_rss*
1527 mlx5_flow_get_rss_action(const struct rte_flow_action actions[])
1529 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1530 switch (actions->type) {
1531 case RTE_FLOW_ACTION_TYPE_RSS:
1532 return (const struct rte_flow_action_rss *)
1542 mlx5_find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
1544 const struct rte_flow_item *item;
1545 unsigned int has_vlan = 0;
1547 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1548 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1554 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
1555 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
1556 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
1557 MLX5_EXPANSION_ROOT_OUTER;
1561 * Create a flow and add it to @p list.
1564 * Pointer to Ethernet device.
1566 * Pointer to a TAILQ flow list.
1568 * Flow rule attributes.
1570 * Pattern specification (list terminated by the END pattern item).
1571 * @param[in] actions
1572 * Associated actions (list terminated by the END action).
1574 * Perform verbose error reporting if not NULL.
1577 * A flow on success, NULL otherwise and rte_errno is set.
1579 static struct rte_flow *
1580 mlx5_flow_list_create(struct rte_eth_dev *dev,
1581 struct mlx5_flows *list,
1582 const struct rte_flow_attr *attr,
1583 const struct rte_flow_item items[],
1584 const struct rte_flow_action actions[],
1585 struct rte_flow_error *error)
1587 struct rte_flow *flow = NULL;
1588 struct mlx5_flow *dev_flow;
1589 uint64_t action_flags = 0;
1590 uint64_t item_flags = 0;
1591 const struct rte_flow_action_rss *rss;
1593 struct rte_flow_expand_rss buf;
1594 uint8_t buffer[2048];
1596 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
1601 ret = mlx5_flow_validate(dev, attr, items, actions, error);
1604 flow_size = sizeof(struct rte_flow);
1605 rss = mlx5_flow_get_rss_action(actions);
1607 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
1610 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
1611 flow = rte_calloc(__func__, 1, flow_size, 0);
1612 flow->queue = (void *)(flow + 1);
1613 LIST_INIT(&flow->dev_flows);
1614 if (rss && rss->types) {
1615 unsigned int graph_root;
1617 graph_root = mlx5_find_graph_root(items, rss->level);
1618 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
1620 mlx5_support_expansion,
1623 (unsigned int)ret < sizeof(expand_buffer.buffer));
1626 buf->entry[0].pattern = (void *)(uintptr_t)items;
1628 for (i = 0; i < buf->entries; ++i) {
1629 dev_flow = nic_ops.prepare(attr, buf->entry[i].pattern,
1630 actions, &item_flags,
1631 &action_flags, error);
1634 dev_flow->flow = flow;
1635 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
1636 ret = nic_ops.translate(dev, dev_flow, attr,
1637 buf->entry[i].pattern,
1642 if (dev->data->dev_started) {
1643 ret = nic_ops.apply(dev, flow, error);
1647 TAILQ_INSERT_TAIL(list, flow, next);
1648 mlx5_flow_rxq_flags_set(dev, flow);
1651 ret = rte_errno; /* Save rte_errno before cleanup. */
1653 nic_ops.destroy(dev, flow);
1655 rte_errno = ret; /* Restore rte_errno. */
1662 * @see rte_flow_create()
1666 mlx5_flow_create(struct rte_eth_dev *dev,
1667 const struct rte_flow_attr *attr,
1668 const struct rte_flow_item items[],
1669 const struct rte_flow_action actions[],
1670 struct rte_flow_error *error)
1672 return mlx5_flow_list_create
1673 (dev, &((struct priv *)dev->data->dev_private)->flows,
1674 attr, items, actions, error);
1678 * Destroy a flow in a list.
1681 * Pointer to Ethernet device.
1683 * Pointer to a TAILQ flow list.
1688 mlx5_flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
1689 struct rte_flow *flow)
1691 nic_ops.destroy(dev, flow);
1692 TAILQ_REMOVE(list, flow, next);
1694 * Update RX queue flags only if port is started, otherwise it is
1697 if (dev->data->dev_started)
1698 mlx5_flow_rxq_flags_trim(dev, flow);
1703 * Destroy all flows.
1706 * Pointer to Ethernet device.
1708 * Pointer to a TAILQ flow list.
1711 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
1713 while (!TAILQ_EMPTY(list)) {
1714 struct rte_flow *flow;
1716 flow = TAILQ_FIRST(list);
1717 mlx5_flow_list_destroy(dev, list, flow);
1725 * Pointer to Ethernet device.
1727 * Pointer to a TAILQ flow list.
1730 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
1732 struct rte_flow *flow;
1734 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next)
1735 nic_ops.remove(dev, flow);
1736 mlx5_flow_rxq_flags_clear(dev);
1743 * Pointer to Ethernet device.
1745 * Pointer to a TAILQ flow list.
1748 * 0 on success, a negative errno value otherwise and rte_errno is set.
1751 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
1753 struct rte_flow *flow;
1754 struct rte_flow_error error;
1757 TAILQ_FOREACH(flow, list, next) {
1758 ret = nic_ops.apply(dev, flow, &error);
1761 mlx5_flow_rxq_flags_set(dev, flow);
1765 ret = rte_errno; /* Save rte_errno before cleanup. */
1766 mlx5_flow_stop(dev, list);
1767 rte_errno = ret; /* Restore rte_errno. */
1772 * Verify the flow list is empty
1775 * Pointer to Ethernet device.
1777 * @return the number of flows not released.
1780 mlx5_flow_verify(struct rte_eth_dev *dev)
1782 struct priv *priv = dev->data->dev_private;
1783 struct rte_flow *flow;
1786 TAILQ_FOREACH(flow, &priv->flows, next) {
1787 DRV_LOG(DEBUG, "port %u flow %p still referenced",
1788 dev->data->port_id, (void *)flow);
1795 * Enable a control flow configured from the control plane.
1798 * Pointer to Ethernet device.
1800 * An Ethernet flow spec to apply.
1802 * An Ethernet flow mask to apply.
1804 * A VLAN flow spec to apply.
1806 * A VLAN flow mask to apply.
1809 * 0 on success, a negative errno value otherwise and rte_errno is set.
1812 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
1813 struct rte_flow_item_eth *eth_spec,
1814 struct rte_flow_item_eth *eth_mask,
1815 struct rte_flow_item_vlan *vlan_spec,
1816 struct rte_flow_item_vlan *vlan_mask)
1818 struct priv *priv = dev->data->dev_private;
1819 const struct rte_flow_attr attr = {
1821 .priority = MLX5_FLOW_PRIO_RSVD,
1823 struct rte_flow_item items[] = {
1825 .type = RTE_FLOW_ITEM_TYPE_ETH,
1831 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
1832 RTE_FLOW_ITEM_TYPE_END,
1838 .type = RTE_FLOW_ITEM_TYPE_END,
1841 uint16_t queue[priv->reta_idx_n];
1842 struct rte_flow_action_rss action_rss = {
1843 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
1845 .types = priv->rss_conf.rss_hf,
1846 .key_len = priv->rss_conf.rss_key_len,
1847 .queue_num = priv->reta_idx_n,
1848 .key = priv->rss_conf.rss_key,
1851 struct rte_flow_action actions[] = {
1853 .type = RTE_FLOW_ACTION_TYPE_RSS,
1854 .conf = &action_rss,
1857 .type = RTE_FLOW_ACTION_TYPE_END,
1860 struct rte_flow *flow;
1861 struct rte_flow_error error;
1864 if (!priv->reta_idx_n) {
1868 for (i = 0; i != priv->reta_idx_n; ++i)
1869 queue[i] = (*priv->reta_idx)[i];
1870 flow = mlx5_flow_list_create(dev, &priv->ctrl_flows, &attr, items,
1878 * Enable a flow control configured from the control plane.
1881 * Pointer to Ethernet device.
1883 * An Ethernet flow spec to apply.
1885 * An Ethernet flow mask to apply.
1888 * 0 on success, a negative errno value otherwise and rte_errno is set.
1891 mlx5_ctrl_flow(struct rte_eth_dev *dev,
1892 struct rte_flow_item_eth *eth_spec,
1893 struct rte_flow_item_eth *eth_mask)
1895 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
1901 * @see rte_flow_destroy()
1905 mlx5_flow_destroy(struct rte_eth_dev *dev,
1906 struct rte_flow *flow,
1907 struct rte_flow_error *error __rte_unused)
1909 struct priv *priv = dev->data->dev_private;
1911 mlx5_flow_list_destroy(dev, &priv->flows, flow);
1916 * Destroy all flows.
1918 * @see rte_flow_flush()
1922 mlx5_flow_flush(struct rte_eth_dev *dev,
1923 struct rte_flow_error *error __rte_unused)
1925 struct priv *priv = dev->data->dev_private;
1927 mlx5_flow_list_flush(dev, &priv->flows);
1934 * @see rte_flow_isolate()
1938 mlx5_flow_isolate(struct rte_eth_dev *dev,
1940 struct rte_flow_error *error)
1942 struct priv *priv = dev->data->dev_private;
1944 if (dev->data->dev_started) {
1945 rte_flow_error_set(error, EBUSY,
1946 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1948 "port must be stopped first");
1951 priv->isolated = !!enable;
1953 dev->dev_ops = &mlx5_dev_ops_isolate;
1955 dev->dev_ops = &mlx5_dev_ops;
1960 * Query flow counter.
1963 * Pointer to the flow.
1966 * 0 on success, a negative errno value otherwise and rte_errno is set.
1969 mlx5_flow_query_count(struct rte_flow *flow __rte_unused,
1970 void *data __rte_unused,
1971 struct rte_flow_error *error)
1973 #ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
1974 if (flow->actions & MLX5_FLOW_ACTION_COUNT) {
1975 struct rte_flow_query_count *qc = data;
1976 uint64_t counters[2] = {0, 0};
1977 struct ibv_query_counter_set_attr query_cs_attr = {
1978 .cs = flow->counter->cs,
1979 .query_flags = IBV_COUNTER_SET_FORCE_UPDATE,
1981 struct ibv_counter_set_data query_out = {
1983 .outlen = 2 * sizeof(uint64_t),
1985 int err = mlx5_glue->query_counter_set(&query_cs_attr,
1989 return rte_flow_error_set
1991 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1993 "cannot read counter");
1996 qc->hits = counters[0] - flow->counter->hits;
1997 qc->bytes = counters[1] - flow->counter->bytes;
1999 flow->counter->hits = counters[0];
2000 flow->counter->bytes = counters[1];
2004 return rte_flow_error_set(error, ENOTSUP,
2005 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2007 "flow does not have counter");
2009 return rte_flow_error_set(error, ENOTSUP,
2010 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2012 "counters are not available");
2018 * @see rte_flow_query()
2022 mlx5_flow_query(struct rte_eth_dev *dev __rte_unused,
2023 struct rte_flow *flow,
2024 const struct rte_flow_action *actions,
2026 struct rte_flow_error *error)
2030 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2031 switch (actions->type) {
2032 case RTE_FLOW_ACTION_TYPE_VOID:
2034 case RTE_FLOW_ACTION_TYPE_COUNT:
2035 ret = mlx5_flow_query_count(flow, data, error);
2038 return rte_flow_error_set(error, ENOTSUP,
2039 RTE_FLOW_ERROR_TYPE_ACTION,
2041 "action not supported");
2050 * Convert a flow director filter to a generic flow.
2053 * Pointer to Ethernet device.
2054 * @param fdir_filter
2055 * Flow director filter to add.
2057 * Generic flow parameters structure.
2060 * 0 on success, a negative errno value otherwise and rte_errno is set.
2063 mlx5_fdir_filter_convert(struct rte_eth_dev *dev,
2064 const struct rte_eth_fdir_filter *fdir_filter,
2065 struct mlx5_fdir *attributes)
2067 struct priv *priv = dev->data->dev_private;
2068 const struct rte_eth_fdir_input *input = &fdir_filter->input;
2069 const struct rte_eth_fdir_masks *mask =
2070 &dev->data->dev_conf.fdir_conf.mask;
2072 /* Validate queue number. */
2073 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
2074 DRV_LOG(ERR, "port %u invalid queue number %d",
2075 dev->data->port_id, fdir_filter->action.rx_queue);
2079 attributes->attr.ingress = 1;
2080 attributes->items[0] = (struct rte_flow_item) {
2081 .type = RTE_FLOW_ITEM_TYPE_ETH,
2082 .spec = &attributes->l2,
2083 .mask = &attributes->l2_mask,
2085 switch (fdir_filter->action.behavior) {
2086 case RTE_ETH_FDIR_ACCEPT:
2087 attributes->actions[0] = (struct rte_flow_action){
2088 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
2089 .conf = &attributes->queue,
2092 case RTE_ETH_FDIR_REJECT:
2093 attributes->actions[0] = (struct rte_flow_action){
2094 .type = RTE_FLOW_ACTION_TYPE_DROP,
2098 DRV_LOG(ERR, "port %u invalid behavior %d",
2100 fdir_filter->action.behavior);
2101 rte_errno = ENOTSUP;
2104 attributes->queue.index = fdir_filter->action.rx_queue;
2106 switch (fdir_filter->input.flow_type) {
2107 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2108 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2109 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2110 attributes->l3.ipv4.hdr = (struct ipv4_hdr){
2111 .src_addr = input->flow.ip4_flow.src_ip,
2112 .dst_addr = input->flow.ip4_flow.dst_ip,
2113 .time_to_live = input->flow.ip4_flow.ttl,
2114 .type_of_service = input->flow.ip4_flow.tos,
2116 attributes->l3_mask.ipv4.hdr = (struct ipv4_hdr){
2117 .src_addr = mask->ipv4_mask.src_ip,
2118 .dst_addr = mask->ipv4_mask.dst_ip,
2119 .time_to_live = mask->ipv4_mask.ttl,
2120 .type_of_service = mask->ipv4_mask.tos,
2121 .next_proto_id = mask->ipv4_mask.proto,
2123 attributes->items[1] = (struct rte_flow_item){
2124 .type = RTE_FLOW_ITEM_TYPE_IPV4,
2125 .spec = &attributes->l3,
2126 .mask = &attributes->l3_mask,
2129 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2130 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2131 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2132 attributes->l3.ipv6.hdr = (struct ipv6_hdr){
2133 .hop_limits = input->flow.ipv6_flow.hop_limits,
2134 .proto = input->flow.ipv6_flow.proto,
2137 memcpy(attributes->l3.ipv6.hdr.src_addr,
2138 input->flow.ipv6_flow.src_ip,
2139 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2140 memcpy(attributes->l3.ipv6.hdr.dst_addr,
2141 input->flow.ipv6_flow.dst_ip,
2142 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2143 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
2144 mask->ipv6_mask.src_ip,
2145 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2146 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
2147 mask->ipv6_mask.dst_ip,
2148 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2149 attributes->items[1] = (struct rte_flow_item){
2150 .type = RTE_FLOW_ITEM_TYPE_IPV6,
2151 .spec = &attributes->l3,
2152 .mask = &attributes->l3_mask,
2156 DRV_LOG(ERR, "port %u invalid flow type%d",
2157 dev->data->port_id, fdir_filter->input.flow_type);
2158 rte_errno = ENOTSUP;
2162 switch (fdir_filter->input.flow_type) {
2163 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2164 attributes->l4.udp.hdr = (struct udp_hdr){
2165 .src_port = input->flow.udp4_flow.src_port,
2166 .dst_port = input->flow.udp4_flow.dst_port,
2168 attributes->l4_mask.udp.hdr = (struct udp_hdr){
2169 .src_port = mask->src_port_mask,
2170 .dst_port = mask->dst_port_mask,
2172 attributes->items[2] = (struct rte_flow_item){
2173 .type = RTE_FLOW_ITEM_TYPE_UDP,
2174 .spec = &attributes->l4,
2175 .mask = &attributes->l4_mask,
2178 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2179 attributes->l4.tcp.hdr = (struct tcp_hdr){
2180 .src_port = input->flow.tcp4_flow.src_port,
2181 .dst_port = input->flow.tcp4_flow.dst_port,
2183 attributes->l4_mask.tcp.hdr = (struct tcp_hdr){
2184 .src_port = mask->src_port_mask,
2185 .dst_port = mask->dst_port_mask,
2187 attributes->items[2] = (struct rte_flow_item){
2188 .type = RTE_FLOW_ITEM_TYPE_TCP,
2189 .spec = &attributes->l4,
2190 .mask = &attributes->l4_mask,
2193 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2194 attributes->l4.udp.hdr = (struct udp_hdr){
2195 .src_port = input->flow.udp6_flow.src_port,
2196 .dst_port = input->flow.udp6_flow.dst_port,
2198 attributes->l4_mask.udp.hdr = (struct udp_hdr){
2199 .src_port = mask->src_port_mask,
2200 .dst_port = mask->dst_port_mask,
2202 attributes->items[2] = (struct rte_flow_item){
2203 .type = RTE_FLOW_ITEM_TYPE_UDP,
2204 .spec = &attributes->l4,
2205 .mask = &attributes->l4_mask,
2208 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2209 attributes->l4.tcp.hdr = (struct tcp_hdr){
2210 .src_port = input->flow.tcp6_flow.src_port,
2211 .dst_port = input->flow.tcp6_flow.dst_port,
2213 attributes->l4_mask.tcp.hdr = (struct tcp_hdr){
2214 .src_port = mask->src_port_mask,
2215 .dst_port = mask->dst_port_mask,
2217 attributes->items[2] = (struct rte_flow_item){
2218 .type = RTE_FLOW_ITEM_TYPE_TCP,
2219 .spec = &attributes->l4,
2220 .mask = &attributes->l4_mask,
2223 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2224 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2227 DRV_LOG(ERR, "port %u invalid flow type%d",
2228 dev->data->port_id, fdir_filter->input.flow_type);
2229 rte_errno = ENOTSUP;
2236 * Add new flow director filter and store it in list.
2239 * Pointer to Ethernet device.
2240 * @param fdir_filter
2241 * Flow director filter to add.
2244 * 0 on success, a negative errno value otherwise and rte_errno is set.
2247 mlx5_fdir_filter_add(struct rte_eth_dev *dev,
2248 const struct rte_eth_fdir_filter *fdir_filter)
2250 struct priv *priv = dev->data->dev_private;
2251 struct mlx5_fdir attributes = {
2254 .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
2255 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
2259 struct rte_flow_error error;
2260 struct rte_flow *flow;
2263 ret = mlx5_fdir_filter_convert(dev, fdir_filter, &attributes);
2266 flow = mlx5_flow_list_create(dev, &priv->flows, &attributes.attr,
2267 attributes.items, attributes.actions,
2270 DRV_LOG(DEBUG, "port %u FDIR created %p", dev->data->port_id,
2278 * Delete specific filter.
2281 * Pointer to Ethernet device.
2282 * @param fdir_filter
2283 * Filter to be deleted.
2286 * 0 on success, a negative errno value otherwise and rte_errno is set.
2289 mlx5_fdir_filter_delete(struct rte_eth_dev *dev __rte_unused,
2290 const struct rte_eth_fdir_filter *fdir_filter
2293 rte_errno = ENOTSUP;
2298 * Update queue for specific filter.
2301 * Pointer to Ethernet device.
2302 * @param fdir_filter
2303 * Filter to be updated.
2306 * 0 on success, a negative errno value otherwise and rte_errno is set.
2309 mlx5_fdir_filter_update(struct rte_eth_dev *dev,
2310 const struct rte_eth_fdir_filter *fdir_filter)
2314 ret = mlx5_fdir_filter_delete(dev, fdir_filter);
2317 return mlx5_fdir_filter_add(dev, fdir_filter);
2321 * Flush all filters.
2324 * Pointer to Ethernet device.
2327 mlx5_fdir_filter_flush(struct rte_eth_dev *dev)
2329 struct priv *priv = dev->data->dev_private;
2331 mlx5_flow_list_flush(dev, &priv->flows);
2335 * Get flow director information.
2338 * Pointer to Ethernet device.
2339 * @param[out] fdir_info
2340 * Resulting flow director information.
2343 mlx5_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
2345 struct rte_eth_fdir_masks *mask =
2346 &dev->data->dev_conf.fdir_conf.mask;
2348 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
2349 fdir_info->guarant_spc = 0;
2350 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
2351 fdir_info->max_flexpayload = 0;
2352 fdir_info->flow_types_mask[0] = 0;
2353 fdir_info->flex_payload_unit = 0;
2354 fdir_info->max_flex_payload_segment_num = 0;
2355 fdir_info->flex_payload_limit = 0;
2356 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
2360 * Deal with flow director operations.
2363 * Pointer to Ethernet device.
2365 * Operation to perform.
2367 * Pointer to operation-specific structure.
2370 * 0 on success, a negative errno value otherwise and rte_errno is set.
2373 mlx5_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
2376 enum rte_fdir_mode fdir_mode =
2377 dev->data->dev_conf.fdir_conf.mode;
2379 if (filter_op == RTE_ETH_FILTER_NOP)
2381 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
2382 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2383 DRV_LOG(ERR, "port %u flow director mode %d not supported",
2384 dev->data->port_id, fdir_mode);
2388 switch (filter_op) {
2389 case RTE_ETH_FILTER_ADD:
2390 return mlx5_fdir_filter_add(dev, arg);
2391 case RTE_ETH_FILTER_UPDATE:
2392 return mlx5_fdir_filter_update(dev, arg);
2393 case RTE_ETH_FILTER_DELETE:
2394 return mlx5_fdir_filter_delete(dev, arg);
2395 case RTE_ETH_FILTER_FLUSH:
2396 mlx5_fdir_filter_flush(dev);
2398 case RTE_ETH_FILTER_INFO:
2399 mlx5_fdir_info_get(dev, arg);
2402 DRV_LOG(DEBUG, "port %u unknown operation %u",
2403 dev->data->port_id, filter_op);
2411 * Manage filter operations.
2414 * Pointer to Ethernet device structure.
2415 * @param filter_type
2418 * Operation to perform.
2420 * Pointer to operation-specific structure.
2423 * 0 on success, a negative errno value otherwise and rte_errno is set.
2426 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
2427 enum rte_filter_type filter_type,
2428 enum rte_filter_op filter_op,
2431 switch (filter_type) {
2432 case RTE_ETH_FILTER_GENERIC:
2433 if (filter_op != RTE_ETH_FILTER_GET) {
2437 *(const void **)arg = &mlx5_flow_ops;
2439 case RTE_ETH_FILTER_FDIR:
2440 return mlx5_fdir_ctrl_func(dev, filter_op, arg);
2442 DRV_LOG(ERR, "port %u filter type (%d) not supported",
2443 dev->data->port_id, filter_type);
2444 rte_errno = ENOTSUP;
2451 * Init the driver ops structure.
2454 * Pointer to Ethernet device structure.
2457 mlx5_flow_init_driver_ops(struct rte_eth_dev *dev __rte_unused)
2459 mlx5_flow_verbs_get_driver_ops(&nic_ops);