1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
6 #include <netinet/in.h>
13 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
15 #pragma GCC diagnostic ignored "-Wpedantic"
17 #include <infiniband/verbs.h>
19 #pragma GCC diagnostic error "-Wpedantic"
22 #include <rte_common.h>
23 #include <rte_ether.h>
24 #include <rte_eth_ctrl.h>
25 #include <rte_ethdev_driver.h>
27 #include <rte_flow_driver.h>
28 #include <rte_malloc.h>
32 #include "mlx5_defs.h"
34 #include "mlx5_glue.h"
35 #include "mlx5_flow.h"
37 /* Dev ops structure defined in mlx5.c */
38 extern const struct eth_dev_ops mlx5_dev_ops;
39 extern const struct eth_dev_ops mlx5_dev_ops_isolate;
41 /** Device flow drivers. */
42 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
43 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
45 extern const struct mlx5_flow_driver_ops mlx5_flow_tcf_drv_ops;
46 extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
48 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
50 const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
51 [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
52 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
53 [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
55 [MLX5_FLOW_TYPE_TCF] = &mlx5_flow_tcf_drv_ops,
56 [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
57 [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
62 MLX5_EXPANSION_ROOT_OUTER,
63 MLX5_EXPANSION_ROOT_ETH_VLAN,
64 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN,
65 MLX5_EXPANSION_OUTER_ETH,
66 MLX5_EXPANSION_OUTER_ETH_VLAN,
67 MLX5_EXPANSION_OUTER_VLAN,
68 MLX5_EXPANSION_OUTER_IPV4,
69 MLX5_EXPANSION_OUTER_IPV4_UDP,
70 MLX5_EXPANSION_OUTER_IPV4_TCP,
71 MLX5_EXPANSION_OUTER_IPV6,
72 MLX5_EXPANSION_OUTER_IPV6_UDP,
73 MLX5_EXPANSION_OUTER_IPV6_TCP,
75 MLX5_EXPANSION_VXLAN_GPE,
79 MLX5_EXPANSION_ETH_VLAN,
82 MLX5_EXPANSION_IPV4_UDP,
83 MLX5_EXPANSION_IPV4_TCP,
85 MLX5_EXPANSION_IPV6_UDP,
86 MLX5_EXPANSION_IPV6_TCP,
89 /** Supported expansion of items. */
90 static const struct rte_flow_expand_node mlx5_support_expansion[] = {
91 [MLX5_EXPANSION_ROOT] = {
92 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
95 .type = RTE_FLOW_ITEM_TYPE_END,
97 [MLX5_EXPANSION_ROOT_OUTER] = {
98 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
99 MLX5_EXPANSION_OUTER_IPV4,
100 MLX5_EXPANSION_OUTER_IPV6),
101 .type = RTE_FLOW_ITEM_TYPE_END,
103 [MLX5_EXPANSION_ROOT_ETH_VLAN] = {
104 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH_VLAN),
105 .type = RTE_FLOW_ITEM_TYPE_END,
107 [MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN] = {
108 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH_VLAN),
109 .type = RTE_FLOW_ITEM_TYPE_END,
111 [MLX5_EXPANSION_OUTER_ETH] = {
112 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
113 MLX5_EXPANSION_OUTER_IPV6,
114 MLX5_EXPANSION_MPLS),
115 .type = RTE_FLOW_ITEM_TYPE_ETH,
118 [MLX5_EXPANSION_OUTER_ETH_VLAN] = {
119 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
120 .type = RTE_FLOW_ITEM_TYPE_ETH,
123 [MLX5_EXPANSION_OUTER_VLAN] = {
124 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
125 MLX5_EXPANSION_OUTER_IPV6),
126 .type = RTE_FLOW_ITEM_TYPE_VLAN,
128 [MLX5_EXPANSION_OUTER_IPV4] = {
129 .next = RTE_FLOW_EXPAND_RSS_NEXT
130 (MLX5_EXPANSION_OUTER_IPV4_UDP,
131 MLX5_EXPANSION_OUTER_IPV4_TCP,
133 .type = RTE_FLOW_ITEM_TYPE_IPV4,
134 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
135 ETH_RSS_NONFRAG_IPV4_OTHER,
137 [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
138 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
139 MLX5_EXPANSION_VXLAN_GPE),
140 .type = RTE_FLOW_ITEM_TYPE_UDP,
141 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
143 [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
144 .type = RTE_FLOW_ITEM_TYPE_TCP,
145 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
147 [MLX5_EXPANSION_OUTER_IPV6] = {
148 .next = RTE_FLOW_EXPAND_RSS_NEXT
149 (MLX5_EXPANSION_OUTER_IPV6_UDP,
150 MLX5_EXPANSION_OUTER_IPV6_TCP),
151 .type = RTE_FLOW_ITEM_TYPE_IPV6,
152 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
153 ETH_RSS_NONFRAG_IPV6_OTHER,
155 [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
156 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
157 MLX5_EXPANSION_VXLAN_GPE),
158 .type = RTE_FLOW_ITEM_TYPE_UDP,
159 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
161 [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
162 .type = RTE_FLOW_ITEM_TYPE_TCP,
163 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
165 [MLX5_EXPANSION_VXLAN] = {
166 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
167 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
169 [MLX5_EXPANSION_VXLAN_GPE] = {
170 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
172 MLX5_EXPANSION_IPV6),
173 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
175 [MLX5_EXPANSION_GRE] = {
176 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4),
177 .type = RTE_FLOW_ITEM_TYPE_GRE,
179 [MLX5_EXPANSION_MPLS] = {
180 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
181 MLX5_EXPANSION_IPV6),
182 .type = RTE_FLOW_ITEM_TYPE_MPLS,
184 [MLX5_EXPANSION_ETH] = {
185 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
186 MLX5_EXPANSION_IPV6),
187 .type = RTE_FLOW_ITEM_TYPE_ETH,
189 [MLX5_EXPANSION_ETH_VLAN] = {
190 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
191 .type = RTE_FLOW_ITEM_TYPE_ETH,
193 [MLX5_EXPANSION_VLAN] = {
194 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
195 MLX5_EXPANSION_IPV6),
196 .type = RTE_FLOW_ITEM_TYPE_VLAN,
198 [MLX5_EXPANSION_IPV4] = {
199 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
200 MLX5_EXPANSION_IPV4_TCP),
201 .type = RTE_FLOW_ITEM_TYPE_IPV4,
202 .rss_types = ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
203 ETH_RSS_NONFRAG_IPV4_OTHER,
205 [MLX5_EXPANSION_IPV4_UDP] = {
206 .type = RTE_FLOW_ITEM_TYPE_UDP,
207 .rss_types = ETH_RSS_NONFRAG_IPV4_UDP,
209 [MLX5_EXPANSION_IPV4_TCP] = {
210 .type = RTE_FLOW_ITEM_TYPE_TCP,
211 .rss_types = ETH_RSS_NONFRAG_IPV4_TCP,
213 [MLX5_EXPANSION_IPV6] = {
214 .next = RTE_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
215 MLX5_EXPANSION_IPV6_TCP),
216 .type = RTE_FLOW_ITEM_TYPE_IPV6,
217 .rss_types = ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
218 ETH_RSS_NONFRAG_IPV6_OTHER,
220 [MLX5_EXPANSION_IPV6_UDP] = {
221 .type = RTE_FLOW_ITEM_TYPE_UDP,
222 .rss_types = ETH_RSS_NONFRAG_IPV6_UDP,
224 [MLX5_EXPANSION_IPV6_TCP] = {
225 .type = RTE_FLOW_ITEM_TYPE_TCP,
226 .rss_types = ETH_RSS_NONFRAG_IPV6_TCP,
230 static const struct rte_flow_ops mlx5_flow_ops = {
231 .validate = mlx5_flow_validate,
232 .create = mlx5_flow_create,
233 .destroy = mlx5_flow_destroy,
234 .flush = mlx5_flow_flush,
235 .isolate = mlx5_flow_isolate,
236 .query = mlx5_flow_query,
239 /* Convert FDIR request to Generic flow. */
241 struct rte_flow_attr attr;
242 struct rte_flow_action actions[2];
243 struct rte_flow_item items[4];
244 struct rte_flow_item_eth l2;
245 struct rte_flow_item_eth l2_mask;
247 struct rte_flow_item_ipv4 ipv4;
248 struct rte_flow_item_ipv6 ipv6;
251 struct rte_flow_item_ipv4 ipv4;
252 struct rte_flow_item_ipv6 ipv6;
255 struct rte_flow_item_udp udp;
256 struct rte_flow_item_tcp tcp;
259 struct rte_flow_item_udp udp;
260 struct rte_flow_item_tcp tcp;
262 struct rte_flow_action_queue queue;
265 /* Map of Verbs to Flow priority with 8 Verbs priorities. */
266 static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
267 { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
270 /* Map of Verbs to Flow priority with 16 Verbs priorities. */
271 static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
272 { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
273 { 9, 10, 11 }, { 12, 13, 14 },
276 /* Tunnel information. */
277 struct mlx5_flow_tunnel_info {
278 uint32_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
279 uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
282 static struct mlx5_flow_tunnel_info tunnels_info[] = {
284 .tunnel = MLX5_FLOW_LAYER_VXLAN,
285 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
288 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
289 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
292 .tunnel = MLX5_FLOW_LAYER_GRE,
293 .ptype = RTE_PTYPE_TUNNEL_GRE,
296 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
297 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE | RTE_PTYPE_L4_UDP,
300 .tunnel = MLX5_FLOW_LAYER_MPLS,
301 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
306 * Discover the maximum number of priority available.
309 * Pointer to the Ethernet device structure.
312 * number of supported flow priority on success, a negative errno
313 * value otherwise and rte_errno is set.
316 mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
319 struct ibv_flow_attr attr;
320 struct ibv_flow_spec_eth eth;
321 struct ibv_flow_spec_action_drop drop;
327 .type = IBV_FLOW_SPEC_ETH,
328 .size = sizeof(struct ibv_flow_spec_eth),
331 .size = sizeof(struct ibv_flow_spec_action_drop),
332 .type = IBV_FLOW_SPEC_ACTION_DROP,
335 struct ibv_flow *flow;
336 struct mlx5_hrxq *drop = mlx5_hrxq_drop_new(dev);
337 uint16_t vprio[] = { 8, 16 };
345 for (i = 0; i != RTE_DIM(vprio); i++) {
346 flow_attr.attr.priority = vprio[i] - 1;
347 flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
350 claim_zero(mlx5_glue->destroy_flow(flow));
355 priority = RTE_DIM(priority_map_3);
358 priority = RTE_DIM(priority_map_5);
363 "port %u verbs maximum priority: %d expected 8/16",
364 dev->data->port_id, vprio[i]);
367 mlx5_hrxq_drop_release(dev);
368 DRV_LOG(INFO, "port %u flow maximum priority: %d",
369 dev->data->port_id, priority);
374 * Adjust flow priority based on the highest layer and the request priority.
377 * Pointer to the Ethernet device structure.
378 * @param[in] priority
379 * The rule base priority.
380 * @param[in] subpriority
381 * The priority based on the items.
386 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
387 uint32_t subpriority)
390 struct priv *priv = dev->data->dev_private;
392 switch (priv->config.flow_prio) {
393 case RTE_DIM(priority_map_3):
394 res = priority_map_3[priority][subpriority];
396 case RTE_DIM(priority_map_5):
397 res = priority_map_5[priority][subpriority];
404 * Verify the @p item specifications (spec, last, mask) are compatible with the
408 * Item specification.
410 * @p item->mask or flow default bit-masks.
411 * @param[in] nic_mask
412 * Bit-masks covering supported fields by the NIC to compare with user mask.
414 * Bit-masks size in bytes.
416 * Pointer to error structure.
419 * 0 on success, a negative errno value otherwise and rte_errno is set.
422 mlx5_flow_item_acceptable(const struct rte_flow_item *item,
424 const uint8_t *nic_mask,
426 struct rte_flow_error *error)
431 for (i = 0; i < size; ++i)
432 if ((nic_mask[i] | mask[i]) != nic_mask[i])
433 return rte_flow_error_set(error, ENOTSUP,
434 RTE_FLOW_ERROR_TYPE_ITEM,
436 "mask enables non supported"
438 if (!item->spec && (item->mask || item->last))
439 return rte_flow_error_set(error, EINVAL,
440 RTE_FLOW_ERROR_TYPE_ITEM, item,
441 "mask/last without a spec is not"
443 if (item->spec && item->last) {
449 for (i = 0; i < size; ++i) {
450 spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
451 last[i] = ((const uint8_t *)item->last)[i] & mask[i];
453 ret = memcmp(spec, last, size);
455 return rte_flow_error_set(error, EINVAL,
456 RTE_FLOW_ERROR_TYPE_ITEM,
458 "range is not valid");
464 * Adjust the hash fields according to the @p flow information.
466 * @param[in] dev_flow.
467 * Pointer to the mlx5_flow.
469 * 1 when the hash field is for a tunnel item.
470 * @param[in] layer_types
472 * @param[in] hash_fields
476 * The hash fileds that should be used.
479 mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow,
480 int tunnel __rte_unused, uint32_t layer_types,
481 uint64_t hash_fields)
483 struct rte_flow *flow = dev_flow->flow;
484 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
485 int rss_request_inner = flow->rss.level >= 2;
487 /* Check RSS hash level for tunnel. */
488 if (tunnel && rss_request_inner)
489 hash_fields |= IBV_RX_HASH_INNER;
490 else if (tunnel || rss_request_inner)
493 /* Check if requested layer matches RSS hash fields. */
494 if (!(flow->rss.types & layer_types))
500 * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
501 * if several tunnel rules are used on this queue, the tunnel ptype will be
505 * Rx queue to update.
508 mlx5_flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
511 uint32_t tunnel_ptype = 0;
513 /* Look up for the ptype to use. */
514 for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
515 if (!rxq_ctrl->flow_tunnels_n[i])
518 tunnel_ptype = tunnels_info[i].ptype;
524 rxq_ctrl->rxq.tunnel = tunnel_ptype;
528 * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the flow.
531 * Pointer to the Ethernet device structure.
533 * Pointer to flow structure.
536 mlx5_flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
538 struct priv *priv = dev->data->dev_private;
539 const int mark = !!(flow->actions &
540 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
541 const int tunnel = !!(flow->layers & MLX5_FLOW_LAYER_TUNNEL);
544 for (i = 0; i != flow->rss.queue_num; ++i) {
545 int idx = (*flow->queue)[i];
546 struct mlx5_rxq_ctrl *rxq_ctrl =
547 container_of((*priv->rxqs)[idx],
548 struct mlx5_rxq_ctrl, rxq);
551 rxq_ctrl->rxq.mark = 1;
552 rxq_ctrl->flow_mark_n++;
557 /* Increase the counter matching the flow. */
558 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
559 if ((tunnels_info[j].tunnel & flow->layers) ==
560 tunnels_info[j].tunnel) {
561 rxq_ctrl->flow_tunnels_n[j]++;
565 mlx5_flow_rxq_tunnel_ptype_update(rxq_ctrl);
571 * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
572 * @p flow if no other flow uses it with the same kind of request.
575 * Pointer to Ethernet device.
577 * Pointer to the flow.
580 mlx5_flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
582 struct priv *priv = dev->data->dev_private;
583 const int mark = !!(flow->actions &
584 (MLX5_FLOW_ACTION_FLAG | MLX5_FLOW_ACTION_MARK));
585 const int tunnel = !!(flow->layers & MLX5_FLOW_LAYER_TUNNEL);
588 assert(dev->data->dev_started);
589 for (i = 0; i != flow->rss.queue_num; ++i) {
590 int idx = (*flow->queue)[i];
591 struct mlx5_rxq_ctrl *rxq_ctrl =
592 container_of((*priv->rxqs)[idx],
593 struct mlx5_rxq_ctrl, rxq);
596 rxq_ctrl->flow_mark_n--;
597 rxq_ctrl->rxq.mark = !!rxq_ctrl->flow_mark_n;
602 /* Decrease the counter matching the flow. */
603 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
604 if ((tunnels_info[j].tunnel & flow->layers) ==
605 tunnels_info[j].tunnel) {
606 rxq_ctrl->flow_tunnels_n[j]--;
610 mlx5_flow_rxq_tunnel_ptype_update(rxq_ctrl);
616 * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
619 * Pointer to Ethernet device.
622 mlx5_flow_rxq_flags_clear(struct rte_eth_dev *dev)
624 struct priv *priv = dev->data->dev_private;
627 for (i = 0; i != priv->rxqs_n; ++i) {
628 struct mlx5_rxq_ctrl *rxq_ctrl;
631 if (!(*priv->rxqs)[i])
633 rxq_ctrl = container_of((*priv->rxqs)[i],
634 struct mlx5_rxq_ctrl, rxq);
635 rxq_ctrl->flow_mark_n = 0;
636 rxq_ctrl->rxq.mark = 0;
637 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
638 rxq_ctrl->flow_tunnels_n[j] = 0;
639 rxq_ctrl->rxq.tunnel = 0;
644 * Validate the flag action.
646 * @param[in] action_flags
647 * Bit-fields that holds the actions detected until now.
649 * Attributes of flow that includes this action.
651 * Pointer to error structure.
654 * 0 on success, a negative errno value otherwise and rte_errno is set.
657 mlx5_flow_validate_action_flag(uint64_t action_flags,
658 const struct rte_flow_attr *attr,
659 struct rte_flow_error *error)
662 if (action_flags & MLX5_FLOW_ACTION_DROP)
663 return rte_flow_error_set(error, EINVAL,
664 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
665 "can't drop and flag in same flow");
666 if (action_flags & MLX5_FLOW_ACTION_MARK)
667 return rte_flow_error_set(error, EINVAL,
668 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
669 "can't mark and flag in same flow");
670 if (action_flags & MLX5_FLOW_ACTION_FLAG)
671 return rte_flow_error_set(error, EINVAL,
672 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
674 " actions in same flow");
676 return rte_flow_error_set(error, ENOTSUP,
677 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
678 "flag action not supported for "
684 * Validate the mark action.
687 * Pointer to the queue action.
688 * @param[in] action_flags
689 * Bit-fields that holds the actions detected until now.
691 * Attributes of flow that includes this action.
693 * Pointer to error structure.
696 * 0 on success, a negative errno value otherwise and rte_errno is set.
699 mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
700 uint64_t action_flags,
701 const struct rte_flow_attr *attr,
702 struct rte_flow_error *error)
704 const struct rte_flow_action_mark *mark = action->conf;
707 return rte_flow_error_set(error, EINVAL,
708 RTE_FLOW_ERROR_TYPE_ACTION,
710 "configuration cannot be null");
711 if (mark->id >= MLX5_FLOW_MARK_MAX)
712 return rte_flow_error_set(error, EINVAL,
713 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
715 "mark id must in 0 <= id < "
716 RTE_STR(MLX5_FLOW_MARK_MAX));
717 if (action_flags & MLX5_FLOW_ACTION_DROP)
718 return rte_flow_error_set(error, EINVAL,
719 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
720 "can't drop and mark in same flow");
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 flag and mark 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 have 2 mark actions in same"
731 return rte_flow_error_set(error, ENOTSUP,
732 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
733 "mark action not supported for "
739 * Validate the drop action.
741 * @param[in] action_flags
742 * Bit-fields that holds the actions detected until now.
744 * Attributes of flow that includes this action.
746 * Pointer to error structure.
749 * 0 on success, a negative errno value otherwise and rte_ernno is set.
752 mlx5_flow_validate_action_drop(uint64_t action_flags,
753 const struct rte_flow_attr *attr,
754 struct rte_flow_error *error)
756 if (action_flags & MLX5_FLOW_ACTION_FLAG)
757 return rte_flow_error_set(error, EINVAL,
758 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
759 "can't drop and flag in same flow");
760 if (action_flags & MLX5_FLOW_ACTION_MARK)
761 return rte_flow_error_set(error, EINVAL,
762 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
763 "can't drop and mark in same flow");
764 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
765 return rte_flow_error_set(error, EINVAL,
766 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
767 "can't have 2 fate actions in"
770 return rte_flow_error_set(error, ENOTSUP,
771 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
772 "drop action not supported for "
778 * Validate the queue action.
781 * Pointer to the queue action.
782 * @param[in] action_flags
783 * Bit-fields that holds the actions detected until now.
785 * Pointer to the Ethernet device structure.
787 * Attributes of flow that includes this action.
789 * Pointer to error structure.
792 * 0 on success, a negative errno value otherwise and rte_ernno is set.
795 mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
796 uint64_t action_flags,
797 struct rte_eth_dev *dev,
798 const struct rte_flow_attr *attr,
799 struct rte_flow_error *error)
801 struct priv *priv = dev->data->dev_private;
802 const struct rte_flow_action_queue *queue = 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 in"
809 if (queue->index >= priv->rxqs_n)
810 return rte_flow_error_set(error, EINVAL,
811 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
813 "queue index out of range");
814 if (!(*priv->rxqs)[queue->index])
815 return rte_flow_error_set(error, EINVAL,
816 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
818 "queue is not configured");
820 return rte_flow_error_set(error, ENOTSUP,
821 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
822 "queue action not supported for "
828 * Validate the rss action.
831 * Pointer to the queue action.
832 * @param[in] action_flags
833 * Bit-fields that holds the actions detected until now.
835 * Pointer to the Ethernet device structure.
837 * Attributes of flow that includes this action.
839 * Pointer to error structure.
842 * 0 on success, a negative errno value otherwise and rte_ernno is set.
845 mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
846 uint64_t action_flags,
847 struct rte_eth_dev *dev,
848 const struct rte_flow_attr *attr,
849 struct rte_flow_error *error)
851 struct priv *priv = dev->data->dev_private;
852 const struct rte_flow_action_rss *rss = action->conf;
855 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
856 return rte_flow_error_set(error, EINVAL,
857 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
858 "can't have 2 fate actions"
860 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
861 rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
862 return rte_flow_error_set(error, ENOTSUP,
863 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
865 "RSS hash function not supported");
866 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
871 return rte_flow_error_set(error, ENOTSUP,
872 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
874 "tunnel RSS is not supported");
875 if (rss->key_len < MLX5_RSS_HASH_KEY_LEN)
876 return rte_flow_error_set(error, ENOTSUP,
877 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
879 "RSS hash key too small");
880 if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
881 return rte_flow_error_set(error, ENOTSUP,
882 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
884 "RSS hash key too large");
885 if (rss->queue_num > priv->config.ind_table_max_size)
886 return rte_flow_error_set(error, ENOTSUP,
887 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
889 "number of queues too large");
890 if (rss->types & MLX5_RSS_HF_MASK)
891 return rte_flow_error_set(error, ENOTSUP,
892 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
894 "some RSS protocols are not"
896 for (i = 0; i != rss->queue_num; ++i) {
897 if (!(*priv->rxqs)[rss->queue[i]])
898 return rte_flow_error_set
899 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_CONF,
900 &rss->queue[i], "queue is not configured");
903 return rte_flow_error_set(error, ENOTSUP,
904 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
905 "rss action not supported for "
911 * Validate the count action.
914 * Pointer to the Ethernet device structure.
916 * Attributes of flow that includes this action.
918 * Pointer to error structure.
921 * 0 on success, a negative errno value otherwise and rte_ernno is set.
924 mlx5_flow_validate_action_count(struct rte_eth_dev *dev,
925 const struct rte_flow_attr *attr,
926 struct rte_flow_error *error)
928 struct priv *priv = dev->data->dev_private;
930 if (!priv->config.flow_counter_en)
931 return rte_flow_error_set(error, ENOTSUP,
932 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
933 "flow counters are not supported.");
935 return rte_flow_error_set(error, ENOTSUP,
936 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
937 "count action not supported for "
943 * Verify the @p attributes will be correctly understood by the NIC and store
944 * them in the @p flow if everything is correct.
947 * Pointer to the Ethernet device structure.
948 * @param[in] attributes
949 * Pointer to flow attributes
951 * Pointer to error structure.
954 * 0 on success, a negative errno value otherwise and rte_errno is set.
957 mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
958 const struct rte_flow_attr *attributes,
959 struct rte_flow_error *error)
961 struct priv *priv = dev->data->dev_private;
962 uint32_t priority_max = priv->config.flow_prio - 1;
964 if (attributes->group)
965 return rte_flow_error_set(error, ENOTSUP,
966 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
967 NULL, "groups is not supported");
968 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
969 attributes->priority >= priority_max)
970 return rte_flow_error_set(error, ENOTSUP,
971 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
972 NULL, "priority out of range");
973 if (attributes->egress)
974 return rte_flow_error_set(error, ENOTSUP,
975 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
976 "egress is not supported");
977 if (attributes->transfer)
978 return rte_flow_error_set(error, ENOTSUP,
979 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
980 NULL, "transfer is not supported");
981 if (!attributes->ingress)
982 return rte_flow_error_set(error, EINVAL,
983 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
985 "ingress attribute is mandatory");
990 * Validate Ethernet item.
993 * Item specification.
994 * @param[in] item_flags
995 * Bit-fields that holds the items detected until now.
997 * Pointer to error structure.
1000 * 0 on success, a negative errno value otherwise and rte_errno is set.
1003 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1004 uint64_t item_flags,
1005 struct rte_flow_error *error)
1007 const struct rte_flow_item_eth *mask = item->mask;
1008 const struct rte_flow_item_eth nic_mask = {
1009 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1010 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1011 .type = RTE_BE16(0xffff),
1014 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1016 if (item_flags & MLX5_FLOW_LAYER_OUTER_L2)
1017 return rte_flow_error_set(error, ENOTSUP,
1018 RTE_FLOW_ERROR_TYPE_ITEM, item,
1019 "3 levels of l2 are not supported");
1020 if ((item_flags & MLX5_FLOW_LAYER_INNER_L2) && !tunnel)
1021 return rte_flow_error_set(error, ENOTSUP,
1022 RTE_FLOW_ERROR_TYPE_ITEM, item,
1023 "2 L2 without tunnel are not supported");
1025 mask = &rte_flow_item_eth_mask;
1026 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1027 (const uint8_t *)&nic_mask,
1028 sizeof(struct rte_flow_item_eth),
1034 * Validate VLAN item.
1037 * Item specification.
1038 * @param[in] item_flags
1039 * Bit-fields that holds the items detected until now.
1041 * Pointer to error structure.
1044 * 0 on success, a negative errno value otherwise and rte_errno is set.
1047 mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1049 struct rte_flow_error *error)
1051 const struct rte_flow_item_vlan *spec = item->spec;
1052 const struct rte_flow_item_vlan *mask = item->mask;
1053 const struct rte_flow_item_vlan nic_mask = {
1054 .tci = RTE_BE16(0x0fff),
1055 .inner_type = RTE_BE16(0xffff),
1057 uint16_t vlan_tag = 0;
1058 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1060 const uint32_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1061 MLX5_FLOW_LAYER_INNER_L4) :
1062 (MLX5_FLOW_LAYER_OUTER_L3 |
1063 MLX5_FLOW_LAYER_OUTER_L4);
1064 const uint32_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1065 MLX5_FLOW_LAYER_OUTER_VLAN;
1067 if (item_flags & vlanm)
1068 return rte_flow_error_set(error, EINVAL,
1069 RTE_FLOW_ERROR_TYPE_ITEM, item,
1070 "VLAN layer already configured");
1071 else if ((item_flags & l34m) != 0)
1072 return rte_flow_error_set(error, EINVAL,
1073 RTE_FLOW_ERROR_TYPE_ITEM, item,
1074 "L2 layer cannot follow L3/L4 layer");
1076 mask = &rte_flow_item_vlan_mask;
1077 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1078 (const uint8_t *)&nic_mask,
1079 sizeof(struct rte_flow_item_vlan),
1084 vlan_tag = spec->tci;
1085 vlan_tag &= mask->tci;
1088 * From verbs perspective an empty VLAN is equivalent
1089 * to a packet without VLAN layer.
1092 return rte_flow_error_set(error, EINVAL,
1093 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1095 "VLAN cannot be empty");
1100 * Validate IPV4 item.
1103 * Item specification.
1104 * @param[in] item_flags
1105 * Bit-fields that holds the items detected until now.
1107 * Pointer to error structure.
1110 * 0 on success, a negative errno value otherwise and rte_errno is set.
1113 mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1115 struct rte_flow_error *error)
1117 const struct rte_flow_item_ipv4 *mask = item->mask;
1118 const struct rte_flow_item_ipv4 nic_mask = {
1120 .src_addr = RTE_BE32(0xffffffff),
1121 .dst_addr = RTE_BE32(0xffffffff),
1122 .type_of_service = 0xff,
1123 .next_proto_id = 0xff,
1126 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1129 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1130 MLX5_FLOW_LAYER_OUTER_L3))
1131 return rte_flow_error_set(error, ENOTSUP,
1132 RTE_FLOW_ERROR_TYPE_ITEM, item,
1133 "multiple L3 layers not supported");
1134 else if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1135 MLX5_FLOW_LAYER_OUTER_L4))
1136 return rte_flow_error_set(error, EINVAL,
1137 RTE_FLOW_ERROR_TYPE_ITEM, item,
1138 "L3 cannot follow an L4 layer.");
1140 mask = &rte_flow_item_ipv4_mask;
1141 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1142 (const uint8_t *)&nic_mask,
1143 sizeof(struct rte_flow_item_ipv4),
1151 * Validate IPV6 item.
1154 * Item specification.
1155 * @param[in] item_flags
1156 * Bit-fields that holds the items detected until now.
1158 * Pointer to error structure.
1161 * 0 on success, a negative errno value otherwise and rte_errno is set.
1164 mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1165 uint64_t item_flags,
1166 struct rte_flow_error *error)
1168 const struct rte_flow_item_ipv6 *mask = item->mask;
1169 const struct rte_flow_item_ipv6 nic_mask = {
1172 "\xff\xff\xff\xff\xff\xff\xff\xff"
1173 "\xff\xff\xff\xff\xff\xff\xff\xff",
1175 "\xff\xff\xff\xff\xff\xff\xff\xff"
1176 "\xff\xff\xff\xff\xff\xff\xff\xff",
1177 .vtc_flow = RTE_BE32(0xffffffff),
1182 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1185 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1186 MLX5_FLOW_LAYER_OUTER_L3))
1187 return rte_flow_error_set(error, ENOTSUP,
1188 RTE_FLOW_ERROR_TYPE_ITEM, item,
1189 "multiple L3 layers not supported");
1190 else if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1191 MLX5_FLOW_LAYER_OUTER_L4))
1192 return rte_flow_error_set(error, EINVAL,
1193 RTE_FLOW_ERROR_TYPE_ITEM, item,
1194 "L3 cannot follow an L4 layer.");
1196 * IPv6 is not recognised by the NIC inside a GRE tunnel.
1197 * Such support has to be disabled as the rule will be
1198 * accepted. Issue reproduced with Mellanox OFED 4.3-3.0.2.1 and
1199 * Mellanox OFED 4.4-1.0.0.0.
1201 if (tunnel && item_flags & MLX5_FLOW_LAYER_GRE)
1202 return rte_flow_error_set(error, ENOTSUP,
1203 RTE_FLOW_ERROR_TYPE_ITEM, item,
1204 "IPv6 inside a GRE tunnel is"
1205 " not recognised.");
1207 mask = &rte_flow_item_ipv6_mask;
1208 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1209 (const uint8_t *)&nic_mask,
1210 sizeof(struct rte_flow_item_ipv6),
1218 * Validate UDP item.
1221 * Item specification.
1222 * @param[in] item_flags
1223 * Bit-fields that holds the items detected until now.
1224 * @param[in] target_protocol
1225 * The next protocol in the previous item.
1226 * @param[in] flow_mask
1227 * mlx5 flow-specific (TCF, DV, verbs, etc.) supported header fields mask.
1229 * Pointer to error structure.
1232 * 0 on success, a negative errno value otherwise and rte_errno is set.
1235 mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1236 uint64_t item_flags,
1237 uint8_t target_protocol,
1238 struct rte_flow_error *error)
1240 const struct rte_flow_item_udp *mask = item->mask;
1241 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1244 if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
1245 return rte_flow_error_set(error, EINVAL,
1246 RTE_FLOW_ERROR_TYPE_ITEM, item,
1247 "protocol filtering not compatible"
1249 if (!(item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1250 MLX5_FLOW_LAYER_OUTER_L3)))
1251 return rte_flow_error_set(error, EINVAL,
1252 RTE_FLOW_ERROR_TYPE_ITEM, item,
1253 "L3 is mandatory to filter on L4");
1254 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1255 MLX5_FLOW_LAYER_OUTER_L4))
1256 return rte_flow_error_set(error, EINVAL,
1257 RTE_FLOW_ERROR_TYPE_ITEM, item,
1258 "L4 layer is already present");
1260 mask = &rte_flow_item_udp_mask;
1261 ret = mlx5_flow_item_acceptable
1262 (item, (const uint8_t *)mask,
1263 (const uint8_t *)&rte_flow_item_udp_mask,
1264 sizeof(struct rte_flow_item_udp), error);
1271 * Validate TCP item.
1274 * Item specification.
1275 * @param[in] item_flags
1276 * Bit-fields that holds the items detected until now.
1277 * @param[in] target_protocol
1278 * The next protocol in the previous item.
1280 * Pointer to error structure.
1283 * 0 on success, a negative errno value otherwise and rte_errno is set.
1286 mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1287 uint64_t item_flags,
1288 uint8_t target_protocol,
1289 const struct rte_flow_item_tcp *flow_mask,
1290 struct rte_flow_error *error)
1292 const struct rte_flow_item_tcp *mask = item->mask;
1293 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1297 if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
1298 return rte_flow_error_set(error, EINVAL,
1299 RTE_FLOW_ERROR_TYPE_ITEM, item,
1300 "protocol filtering not compatible"
1302 if (!(item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
1303 MLX5_FLOW_LAYER_OUTER_L3)))
1304 return rte_flow_error_set(error, EINVAL,
1305 RTE_FLOW_ERROR_TYPE_ITEM, item,
1306 "L3 is mandatory to filter on L4");
1307 if (item_flags & (tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1308 MLX5_FLOW_LAYER_OUTER_L4))
1309 return rte_flow_error_set(error, EINVAL,
1310 RTE_FLOW_ERROR_TYPE_ITEM, item,
1311 "L4 layer is already present");
1313 mask = &rte_flow_item_tcp_mask;
1314 ret = mlx5_flow_item_acceptable
1315 (item, (const uint8_t *)mask,
1316 (const uint8_t *)flow_mask,
1317 sizeof(struct rte_flow_item_tcp), error);
1324 * Validate VXLAN item.
1327 * Item specification.
1328 * @param[in] item_flags
1329 * Bit-fields that holds the items detected until now.
1330 * @param[in] target_protocol
1331 * The next protocol in the previous item.
1333 * Pointer to error structure.
1336 * 0 on success, a negative errno value otherwise and rte_errno is set.
1339 mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1340 uint64_t item_flags,
1341 struct rte_flow_error *error)
1343 const struct rte_flow_item_vxlan *spec = item->spec;
1344 const struct rte_flow_item_vxlan *mask = item->mask;
1349 } id = { .vlan_id = 0, };
1350 uint32_t vlan_id = 0;
1353 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1354 return rte_flow_error_set(error, ENOTSUP,
1355 RTE_FLOW_ERROR_TYPE_ITEM, item,
1356 "a tunnel is already present");
1358 * Verify only UDPv4 is present as defined in
1359 * https://tools.ietf.org/html/rfc7348
1361 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1362 return rte_flow_error_set(error, EINVAL,
1363 RTE_FLOW_ERROR_TYPE_ITEM, item,
1364 "no outer UDP layer found");
1366 mask = &rte_flow_item_vxlan_mask;
1367 ret = mlx5_flow_item_acceptable
1368 (item, (const uint8_t *)mask,
1369 (const uint8_t *)&rte_flow_item_vxlan_mask,
1370 sizeof(struct rte_flow_item_vxlan),
1375 memcpy(&id.vni[1], spec->vni, 3);
1376 vlan_id = id.vlan_id;
1377 memcpy(&id.vni[1], mask->vni, 3);
1378 vlan_id &= id.vlan_id;
1381 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if
1382 * only this layer is defined in the Verbs specification it is
1383 * interpreted as wildcard and all packets will match this
1384 * rule, if it follows a full stack layer (ex: eth / ipv4 /
1385 * udp), all packets matching the layers before will also
1386 * match this rule. To avoid such situation, VNI 0 is
1387 * currently refused.
1390 return rte_flow_error_set(error, ENOTSUP,
1391 RTE_FLOW_ERROR_TYPE_ITEM, item,
1392 "VXLAN vni cannot be 0");
1393 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1394 return rte_flow_error_set(error, ENOTSUP,
1395 RTE_FLOW_ERROR_TYPE_ITEM, item,
1396 "VXLAN tunnel must be fully defined");
1401 * Validate VXLAN_GPE item.
1404 * Item specification.
1405 * @param[in] item_flags
1406 * Bit-fields that holds the items detected until now.
1408 * Pointer to the private data structure.
1409 * @param[in] target_protocol
1410 * The next protocol in the previous item.
1412 * Pointer to error structure.
1415 * 0 on success, a negative errno value otherwise and rte_errno is set.
1418 mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1419 uint64_t item_flags,
1420 struct rte_eth_dev *dev,
1421 struct rte_flow_error *error)
1423 struct priv *priv = dev->data->dev_private;
1424 const struct rte_flow_item_vxlan_gpe *spec = item->spec;
1425 const struct rte_flow_item_vxlan_gpe *mask = item->mask;
1430 } id = { .vlan_id = 0, };
1431 uint32_t vlan_id = 0;
1433 if (!priv->config.l3_vxlan_en)
1434 return rte_flow_error_set(error, ENOTSUP,
1435 RTE_FLOW_ERROR_TYPE_ITEM, item,
1436 "L3 VXLAN is not enabled by device"
1437 " parameter and/or not configured in"
1439 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1440 return rte_flow_error_set(error, ENOTSUP,
1441 RTE_FLOW_ERROR_TYPE_ITEM, item,
1442 "a tunnel is already present");
1444 * Verify only UDPv4 is present as defined in
1445 * https://tools.ietf.org/html/rfc7348
1447 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1448 return rte_flow_error_set(error, EINVAL,
1449 RTE_FLOW_ERROR_TYPE_ITEM, item,
1450 "no outer UDP layer found");
1452 mask = &rte_flow_item_vxlan_gpe_mask;
1453 ret = mlx5_flow_item_acceptable
1454 (item, (const uint8_t *)mask,
1455 (const uint8_t *)&rte_flow_item_vxlan_gpe_mask,
1456 sizeof(struct rte_flow_item_vxlan_gpe),
1462 return rte_flow_error_set(error, ENOTSUP,
1463 RTE_FLOW_ERROR_TYPE_ITEM,
1465 "VxLAN-GPE protocol"
1467 memcpy(&id.vni[1], spec->vni, 3);
1468 vlan_id = id.vlan_id;
1469 memcpy(&id.vni[1], mask->vni, 3);
1470 vlan_id &= id.vlan_id;
1473 * Tunnel id 0 is equivalent as not adding a VXLAN layer, if only this
1474 * layer is defined in the Verbs specification it is interpreted as
1475 * wildcard and all packets will match this rule, if it follows a full
1476 * stack layer (ex: eth / ipv4 / udp), all packets matching the layers
1477 * before will also match this rule. To avoid such situation, VNI 0
1478 * is currently refused.
1481 return rte_flow_error_set(error, ENOTSUP,
1482 RTE_FLOW_ERROR_TYPE_ITEM, item,
1483 "VXLAN-GPE vni cannot be 0");
1484 if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
1485 return rte_flow_error_set(error, ENOTSUP,
1486 RTE_FLOW_ERROR_TYPE_ITEM, item,
1487 "VXLAN-GPE tunnel must be fully"
1493 * Validate GRE item.
1496 * Item specification.
1497 * @param[in] item_flags
1498 * Bit flags to mark detected items.
1499 * @param[in] target_protocol
1500 * The next protocol in the previous item.
1502 * Pointer to error structure.
1505 * 0 on success, a negative errno value otherwise and rte_errno is set.
1508 mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
1509 uint64_t item_flags,
1510 uint8_t target_protocol,
1511 struct rte_flow_error *error)
1513 const struct rte_flow_item_gre *spec __rte_unused = item->spec;
1514 const struct rte_flow_item_gre *mask = item->mask;
1517 if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
1518 return rte_flow_error_set(error, EINVAL,
1519 RTE_FLOW_ERROR_TYPE_ITEM, item,
1520 "protocol filtering not compatible"
1521 " with this GRE layer");
1522 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1523 return rte_flow_error_set(error, ENOTSUP,
1524 RTE_FLOW_ERROR_TYPE_ITEM, item,
1525 "a tunnel is already present");
1526 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
1527 return rte_flow_error_set(error, ENOTSUP,
1528 RTE_FLOW_ERROR_TYPE_ITEM, item,
1529 "L3 Layer is missing");
1531 mask = &rte_flow_item_gre_mask;
1532 ret = mlx5_flow_item_acceptable
1533 (item, (const uint8_t *)mask,
1534 (const uint8_t *)&rte_flow_item_gre_mask,
1535 sizeof(struct rte_flow_item_gre), error);
1538 #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
1539 if (spec && (spec->protocol & mask->protocol))
1540 return rte_flow_error_set(error, ENOTSUP,
1541 RTE_FLOW_ERROR_TYPE_ITEM, item,
1542 "without MPLS support the"
1543 " specification cannot be used for"
1550 * Validate MPLS item.
1553 * Item specification.
1554 * @param[in] item_flags
1555 * Bit-fields that holds the items detected until now.
1556 * @param[in] target_protocol
1557 * The next protocol in the previous item.
1559 * Pointer to error structure.
1562 * 0 on success, a negative errno value otherwise and rte_errno is set.
1565 mlx5_flow_validate_item_mpls(const struct rte_flow_item *item __rte_unused,
1566 uint64_t item_flags __rte_unused,
1567 uint8_t target_protocol __rte_unused,
1568 struct rte_flow_error *error)
1570 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
1571 const struct rte_flow_item_mpls *mask = item->mask;
1574 if (target_protocol != 0xff && target_protocol != IPPROTO_MPLS)
1575 return rte_flow_error_set(error, EINVAL,
1576 RTE_FLOW_ERROR_TYPE_ITEM, item,
1577 "protocol filtering not compatible"
1578 " with MPLS layer");
1579 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1580 return rte_flow_error_set(error, ENOTSUP,
1581 RTE_FLOW_ERROR_TYPE_ITEM, item,
1582 "a tunnel is already"
1585 mask = &rte_flow_item_mpls_mask;
1586 ret = mlx5_flow_item_acceptable
1587 (item, (const uint8_t *)mask,
1588 (const uint8_t *)&rte_flow_item_mpls_mask,
1589 sizeof(struct rte_flow_item_mpls), error);
1594 return rte_flow_error_set(error, ENOTSUP,
1595 RTE_FLOW_ERROR_TYPE_ITEM, item,
1596 "MPLS is not supported by Verbs, please"
1601 flow_null_validate(struct rte_eth_dev *dev __rte_unused,
1602 const struct rte_flow_attr *attr __rte_unused,
1603 const struct rte_flow_item items[] __rte_unused,
1604 const struct rte_flow_action actions[] __rte_unused,
1605 struct rte_flow_error *error __rte_unused)
1607 rte_errno = ENOTSUP;
1611 static struct mlx5_flow *
1612 flow_null_prepare(const struct rte_flow_attr *attr __rte_unused,
1613 const struct rte_flow_item items[] __rte_unused,
1614 const struct rte_flow_action actions[] __rte_unused,
1615 uint64_t *item_flags __rte_unused,
1616 uint64_t *action_flags __rte_unused,
1617 struct rte_flow_error *error __rte_unused)
1619 rte_errno = ENOTSUP;
1624 flow_null_translate(struct rte_eth_dev *dev __rte_unused,
1625 struct mlx5_flow *dev_flow __rte_unused,
1626 const struct rte_flow_attr *attr __rte_unused,
1627 const struct rte_flow_item items[] __rte_unused,
1628 const struct rte_flow_action actions[] __rte_unused,
1629 struct rte_flow_error *error __rte_unused)
1631 rte_errno = ENOTSUP;
1636 flow_null_apply(struct rte_eth_dev *dev __rte_unused,
1637 struct rte_flow *flow __rte_unused,
1638 struct rte_flow_error *error __rte_unused)
1640 rte_errno = ENOTSUP;
1645 flow_null_remove(struct rte_eth_dev *dev __rte_unused,
1646 struct rte_flow *flow __rte_unused)
1651 flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
1652 struct rte_flow *flow __rte_unused)
1657 flow_null_query(struct rte_eth_dev *dev __rte_unused,
1658 struct rte_flow *flow __rte_unused,
1659 const struct rte_flow_action *actions __rte_unused,
1660 void *data __rte_unused,
1661 struct rte_flow_error *error __rte_unused)
1663 rte_errno = ENOTSUP;
1667 /* Void driver to protect from null pointer reference. */
1668 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
1669 .validate = flow_null_validate,
1670 .prepare = flow_null_prepare,
1671 .translate = flow_null_translate,
1672 .apply = flow_null_apply,
1673 .remove = flow_null_remove,
1674 .destroy = flow_null_destroy,
1675 .query = flow_null_query,
1679 * Select flow driver type according to flow attributes and device
1683 * Pointer to the dev structure.
1685 * Pointer to the flow attributes.
1688 * flow driver type if supported, MLX5_FLOW_TYPE_MAX otherwise.
1690 static enum mlx5_flow_drv_type
1691 flow_get_drv_type(struct rte_eth_dev *dev __rte_unused,
1692 const struct rte_flow_attr *attr)
1694 struct priv *priv __rte_unused = dev->data->dev_private;
1695 enum mlx5_flow_drv_type type = MLX5_FLOW_TYPE_MAX;
1697 if (attr->transfer) {
1698 type = MLX5_FLOW_TYPE_TCF;
1700 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
1701 type = priv->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
1702 MLX5_FLOW_TYPE_VERBS;
1704 type = MLX5_FLOW_TYPE_VERBS;
1710 #define flow_get_drv_ops(type) flow_drv_ops[type]
1713 * Flow driver validation API. This abstracts calling driver specific functions.
1714 * The type of flow driver is determined according to flow attributes.
1717 * Pointer to the dev structure.
1719 * Pointer to the flow attributes.
1721 * Pointer to the list of items.
1722 * @param[in] actions
1723 * Pointer to the list of actions.
1725 * Pointer to the error structure.
1728 * 0 on success, a negative errno value otherwise and rte_ernno is set.
1731 flow_drv_validate(struct rte_eth_dev *dev,
1732 const struct rte_flow_attr *attr,
1733 const struct rte_flow_item items[],
1734 const struct rte_flow_action actions[],
1735 struct rte_flow_error *error)
1737 const struct mlx5_flow_driver_ops *fops;
1738 enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
1740 fops = flow_get_drv_ops(type);
1741 return fops->validate(dev, attr, items, actions, error);
1745 * Flow driver preparation API. This abstracts calling driver specific
1746 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
1747 * calculates the size of memory required for device flow, allocates the memory,
1748 * initializes the device flow and returns the pointer.
1751 * Pointer to the flow attributes.
1753 * Pointer to the list of items.
1754 * @param[in] actions
1755 * Pointer to the list of actions.
1756 * @param[out] item_flags
1757 * Pointer to bit mask of all items detected.
1758 * @param[out] action_flags
1759 * Pointer to bit mask of all actions detected.
1761 * Pointer to the error structure.
1764 * Pointer to device flow on success, otherwise NULL and rte_ernno is set.
1766 static inline struct mlx5_flow *
1767 flow_drv_prepare(struct rte_flow *flow,
1768 const struct rte_flow_attr *attr,
1769 const struct rte_flow_item items[],
1770 const struct rte_flow_action actions[],
1771 uint64_t *item_flags,
1772 uint64_t *action_flags,
1773 struct rte_flow_error *error)
1775 const struct mlx5_flow_driver_ops *fops;
1776 enum mlx5_flow_drv_type type = flow->drv_type;
1778 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1779 fops = flow_get_drv_ops(type);
1780 return fops->prepare(attr, items, actions, item_flags, action_flags,
1785 * Flow driver translation API. This abstracts calling driver specific
1786 * functions. Parent flow (rte_flow) should have driver type (drv_type). It
1787 * translates a generic flow into a driver flow. flow_drv_prepare() must
1792 * Pointer to the rte dev structure.
1793 * @param[in, out] dev_flow
1794 * Pointer to the mlx5 flow.
1796 * Pointer to the flow attributes.
1798 * Pointer to the list of items.
1799 * @param[in] actions
1800 * Pointer to the list of actions.
1802 * Pointer to the error structure.
1805 * 0 on success, a negative errno value otherwise and rte_ernno is set.
1808 flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
1809 const struct rte_flow_attr *attr,
1810 const struct rte_flow_item items[],
1811 const struct rte_flow_action actions[],
1812 struct rte_flow_error *error)
1814 const struct mlx5_flow_driver_ops *fops;
1815 enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
1817 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1818 fops = flow_get_drv_ops(type);
1819 return fops->translate(dev, dev_flow, attr, items, actions, error);
1823 * Flow driver apply API. This abstracts calling driver specific functions.
1824 * Parent flow (rte_flow) should have driver type (drv_type). It applies
1825 * translated driver flows on to device. flow_drv_translate() must precede.
1828 * Pointer to Ethernet device structure.
1829 * @param[in, out] flow
1830 * Pointer to flow structure.
1832 * Pointer to error structure.
1835 * 0 on success, a negative errno value otherwise and rte_errno is set.
1838 flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
1839 struct rte_flow_error *error)
1841 const struct mlx5_flow_driver_ops *fops;
1842 enum mlx5_flow_drv_type type = flow->drv_type;
1844 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1845 fops = flow_get_drv_ops(type);
1846 return fops->apply(dev, flow, error);
1850 * Flow driver remove API. This abstracts calling driver specific functions.
1851 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
1852 * on device. All the resources of the flow should be freed by calling
1853 * flow_dv_destroy().
1856 * Pointer to Ethernet device.
1857 * @param[in, out] flow
1858 * Pointer to flow structure.
1861 flow_drv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
1863 const struct mlx5_flow_driver_ops *fops;
1864 enum mlx5_flow_drv_type type = flow->drv_type;
1866 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1867 fops = flow_get_drv_ops(type);
1868 fops->remove(dev, flow);
1872 * Flow driver destroy API. This abstracts calling driver specific functions.
1873 * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
1874 * on device and releases resources of the flow.
1877 * Pointer to Ethernet device.
1878 * @param[in, out] flow
1879 * Pointer to flow structure.
1882 flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
1884 const struct mlx5_flow_driver_ops *fops;
1885 enum mlx5_flow_drv_type type = flow->drv_type;
1887 assert(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
1888 fops = flow_get_drv_ops(type);
1889 fops->destroy(dev, flow);
1893 * Validate a flow supported by the NIC.
1895 * @see rte_flow_validate()
1899 mlx5_flow_validate(struct rte_eth_dev *dev,
1900 const struct rte_flow_attr *attr,
1901 const struct rte_flow_item items[],
1902 const struct rte_flow_action actions[],
1903 struct rte_flow_error *error)
1907 ret = flow_drv_validate(dev, attr, items, actions, error);
1914 * Get RSS action from the action list.
1916 * @param[in] actions
1917 * Pointer to the list of actions.
1920 * Pointer to the RSS action if exist, else return NULL.
1922 static const struct rte_flow_action_rss*
1923 mlx5_flow_get_rss_action(const struct rte_flow_action actions[])
1925 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1926 switch (actions->type) {
1927 case RTE_FLOW_ACTION_TYPE_RSS:
1928 return (const struct rte_flow_action_rss *)
1938 mlx5_find_graph_root(const struct rte_flow_item pattern[], uint32_t rss_level)
1940 const struct rte_flow_item *item;
1941 unsigned int has_vlan = 0;
1943 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1944 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1950 return rss_level < 2 ? MLX5_EXPANSION_ROOT_ETH_VLAN :
1951 MLX5_EXPANSION_ROOT_OUTER_ETH_VLAN;
1952 return rss_level < 2 ? MLX5_EXPANSION_ROOT :
1953 MLX5_EXPANSION_ROOT_OUTER;
1957 * Create a flow and add it to @p list.
1960 * Pointer to Ethernet device.
1962 * Pointer to a TAILQ flow list.
1964 * Flow rule attributes.
1966 * Pattern specification (list terminated by the END pattern item).
1967 * @param[in] actions
1968 * Associated actions (list terminated by the END action).
1970 * Perform verbose error reporting if not NULL.
1973 * A flow on success, NULL otherwise and rte_errno is set.
1975 static struct rte_flow *
1976 mlx5_flow_list_create(struct rte_eth_dev *dev,
1977 struct mlx5_flows *list,
1978 const struct rte_flow_attr *attr,
1979 const struct rte_flow_item items[],
1980 const struct rte_flow_action actions[],
1981 struct rte_flow_error *error)
1983 struct rte_flow *flow = NULL;
1984 struct mlx5_flow *dev_flow;
1985 uint64_t action_flags = 0;
1986 uint64_t item_flags = 0;
1987 const struct rte_flow_action_rss *rss;
1989 struct rte_flow_expand_rss buf;
1990 uint8_t buffer[2048];
1992 struct rte_flow_expand_rss *buf = &expand_buffer.buf;
1997 ret = flow_drv_validate(dev, attr, items, actions, error);
2000 flow_size = sizeof(struct rte_flow);
2001 rss = mlx5_flow_get_rss_action(actions);
2003 flow_size += RTE_ALIGN_CEIL(rss->queue_num * sizeof(uint16_t),
2006 flow_size += RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *));
2007 flow = rte_calloc(__func__, 1, flow_size, 0);
2008 flow->drv_type = flow_get_drv_type(dev, attr);
2009 assert(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
2010 flow->drv_type < MLX5_FLOW_TYPE_MAX);
2011 flow->queue = (void *)(flow + 1);
2012 LIST_INIT(&flow->dev_flows);
2013 if (rss && rss->types) {
2014 unsigned int graph_root;
2016 graph_root = mlx5_find_graph_root(items, rss->level);
2017 ret = rte_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
2019 mlx5_support_expansion,
2022 (unsigned int)ret < sizeof(expand_buffer.buffer));
2025 buf->entry[0].pattern = (void *)(uintptr_t)items;
2027 for (i = 0; i < buf->entries; ++i) {
2028 dev_flow = flow_drv_prepare(flow, attr, buf->entry[i].pattern,
2029 actions, &item_flags, &action_flags,
2033 dev_flow->flow = flow;
2034 LIST_INSERT_HEAD(&flow->dev_flows, dev_flow, next);
2035 ret = flow_drv_translate(dev, dev_flow, attr,
2036 buf->entry[i].pattern,
2041 if (dev->data->dev_started) {
2042 ret = flow_drv_apply(dev, flow, error);
2046 TAILQ_INSERT_TAIL(list, flow, next);
2047 mlx5_flow_rxq_flags_set(dev, flow);
2050 ret = rte_errno; /* Save rte_errno before cleanup. */
2052 flow_drv_destroy(dev, flow);
2054 rte_errno = ret; /* Restore rte_errno. */
2061 * @see rte_flow_create()
2065 mlx5_flow_create(struct rte_eth_dev *dev,
2066 const struct rte_flow_attr *attr,
2067 const struct rte_flow_item items[],
2068 const struct rte_flow_action actions[],
2069 struct rte_flow_error *error)
2071 return mlx5_flow_list_create
2072 (dev, &((struct priv *)dev->data->dev_private)->flows,
2073 attr, items, actions, error);
2077 * Destroy a flow in a list.
2080 * Pointer to Ethernet device.
2082 * Pointer to a TAILQ flow list.
2087 mlx5_flow_list_destroy(struct rte_eth_dev *dev, struct mlx5_flows *list,
2088 struct rte_flow *flow)
2090 flow_drv_destroy(dev, flow);
2091 TAILQ_REMOVE(list, flow, next);
2093 * Update RX queue flags only if port is started, otherwise it is
2096 if (dev->data->dev_started)
2097 mlx5_flow_rxq_flags_trim(dev, flow);
2102 * Destroy all flows.
2105 * Pointer to Ethernet device.
2107 * Pointer to a TAILQ flow list.
2110 mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list)
2112 while (!TAILQ_EMPTY(list)) {
2113 struct rte_flow *flow;
2115 flow = TAILQ_FIRST(list);
2116 mlx5_flow_list_destroy(dev, list, flow);
2124 * Pointer to Ethernet device.
2126 * Pointer to a TAILQ flow list.
2129 mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list)
2131 struct rte_flow *flow;
2133 TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next)
2134 flow_drv_remove(dev, flow);
2135 mlx5_flow_rxq_flags_clear(dev);
2142 * Pointer to Ethernet device.
2144 * Pointer to a TAILQ flow list.
2147 * 0 on success, a negative errno value otherwise and rte_errno is set.
2150 mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list)
2152 struct rte_flow *flow;
2153 struct rte_flow_error error;
2156 TAILQ_FOREACH(flow, list, next) {
2157 ret = flow_drv_apply(dev, flow, &error);
2160 mlx5_flow_rxq_flags_set(dev, flow);
2164 ret = rte_errno; /* Save rte_errno before cleanup. */
2165 mlx5_flow_stop(dev, list);
2166 rte_errno = ret; /* Restore rte_errno. */
2171 * Verify the flow list is empty
2174 * Pointer to Ethernet device.
2176 * @return the number of flows not released.
2179 mlx5_flow_verify(struct rte_eth_dev *dev)
2181 struct priv *priv = dev->data->dev_private;
2182 struct rte_flow *flow;
2185 TAILQ_FOREACH(flow, &priv->flows, next) {
2186 DRV_LOG(DEBUG, "port %u flow %p still referenced",
2187 dev->data->port_id, (void *)flow);
2194 * Enable a control flow configured from the control plane.
2197 * Pointer to Ethernet device.
2199 * An Ethernet flow spec to apply.
2201 * An Ethernet flow mask to apply.
2203 * A VLAN flow spec to apply.
2205 * A VLAN flow mask to apply.
2208 * 0 on success, a negative errno value otherwise and rte_errno is set.
2211 mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
2212 struct rte_flow_item_eth *eth_spec,
2213 struct rte_flow_item_eth *eth_mask,
2214 struct rte_flow_item_vlan *vlan_spec,
2215 struct rte_flow_item_vlan *vlan_mask)
2217 struct priv *priv = dev->data->dev_private;
2218 const struct rte_flow_attr attr = {
2220 .priority = MLX5_FLOW_PRIO_RSVD,
2222 struct rte_flow_item items[] = {
2224 .type = RTE_FLOW_ITEM_TYPE_ETH,
2230 .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
2231 RTE_FLOW_ITEM_TYPE_END,
2237 .type = RTE_FLOW_ITEM_TYPE_END,
2240 uint16_t queue[priv->reta_idx_n];
2241 struct rte_flow_action_rss action_rss = {
2242 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
2244 .types = priv->rss_conf.rss_hf,
2245 .key_len = priv->rss_conf.rss_key_len,
2246 .queue_num = priv->reta_idx_n,
2247 .key = priv->rss_conf.rss_key,
2250 struct rte_flow_action actions[] = {
2252 .type = RTE_FLOW_ACTION_TYPE_RSS,
2253 .conf = &action_rss,
2256 .type = RTE_FLOW_ACTION_TYPE_END,
2259 struct rte_flow *flow;
2260 struct rte_flow_error error;
2263 if (!priv->reta_idx_n) {
2267 for (i = 0; i != priv->reta_idx_n; ++i)
2268 queue[i] = (*priv->reta_idx)[i];
2269 flow = mlx5_flow_list_create(dev, &priv->ctrl_flows, &attr, items,
2277 * Enable a flow control configured from the control plane.
2280 * Pointer to Ethernet device.
2282 * An Ethernet flow spec to apply.
2284 * An Ethernet flow mask to apply.
2287 * 0 on success, a negative errno value otherwise and rte_errno is set.
2290 mlx5_ctrl_flow(struct rte_eth_dev *dev,
2291 struct rte_flow_item_eth *eth_spec,
2292 struct rte_flow_item_eth *eth_mask)
2294 return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
2300 * @see rte_flow_destroy()
2304 mlx5_flow_destroy(struct rte_eth_dev *dev,
2305 struct rte_flow *flow,
2306 struct rte_flow_error *error __rte_unused)
2308 struct priv *priv = dev->data->dev_private;
2310 mlx5_flow_list_destroy(dev, &priv->flows, flow);
2315 * Destroy all flows.
2317 * @see rte_flow_flush()
2321 mlx5_flow_flush(struct rte_eth_dev *dev,
2322 struct rte_flow_error *error __rte_unused)
2324 struct priv *priv = dev->data->dev_private;
2326 mlx5_flow_list_flush(dev, &priv->flows);
2333 * @see rte_flow_isolate()
2337 mlx5_flow_isolate(struct rte_eth_dev *dev,
2339 struct rte_flow_error *error)
2341 struct priv *priv = dev->data->dev_private;
2343 if (dev->data->dev_started) {
2344 rte_flow_error_set(error, EBUSY,
2345 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2347 "port must be stopped first");
2350 priv->isolated = !!enable;
2352 dev->dev_ops = &mlx5_dev_ops_isolate;
2354 dev->dev_ops = &mlx5_dev_ops;
2361 * @see rte_flow_query()
2365 flow_drv_query(struct rte_eth_dev *dev,
2366 struct rte_flow *flow,
2367 const struct rte_flow_action *actions,
2369 struct rte_flow_error *error)
2371 const struct mlx5_flow_driver_ops *fops;
2372 enum mlx5_flow_drv_type ftype = flow->drv_type;
2374 assert(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
2375 fops = flow_get_drv_ops(ftype);
2377 return fops->query(dev, flow, actions, data, error);
2383 * @see rte_flow_query()
2387 mlx5_flow_query(struct rte_eth_dev *dev,
2388 struct rte_flow *flow,
2389 const struct rte_flow_action *actions,
2391 struct rte_flow_error *error)
2395 ret = flow_drv_query(dev, flow, actions, data, error);
2402 * Convert a flow director filter to a generic flow.
2405 * Pointer to Ethernet device.
2406 * @param fdir_filter
2407 * Flow director filter to add.
2409 * Generic flow parameters structure.
2412 * 0 on success, a negative errno value otherwise and rte_errno is set.
2415 mlx5_fdir_filter_convert(struct rte_eth_dev *dev,
2416 const struct rte_eth_fdir_filter *fdir_filter,
2417 struct mlx5_fdir *attributes)
2419 struct priv *priv = dev->data->dev_private;
2420 const struct rte_eth_fdir_input *input = &fdir_filter->input;
2421 const struct rte_eth_fdir_masks *mask =
2422 &dev->data->dev_conf.fdir_conf.mask;
2424 /* Validate queue number. */
2425 if (fdir_filter->action.rx_queue >= priv->rxqs_n) {
2426 DRV_LOG(ERR, "port %u invalid queue number %d",
2427 dev->data->port_id, fdir_filter->action.rx_queue);
2431 attributes->attr.ingress = 1;
2432 attributes->items[0] = (struct rte_flow_item) {
2433 .type = RTE_FLOW_ITEM_TYPE_ETH,
2434 .spec = &attributes->l2,
2435 .mask = &attributes->l2_mask,
2437 switch (fdir_filter->action.behavior) {
2438 case RTE_ETH_FDIR_ACCEPT:
2439 attributes->actions[0] = (struct rte_flow_action){
2440 .type = RTE_FLOW_ACTION_TYPE_QUEUE,
2441 .conf = &attributes->queue,
2444 case RTE_ETH_FDIR_REJECT:
2445 attributes->actions[0] = (struct rte_flow_action){
2446 .type = RTE_FLOW_ACTION_TYPE_DROP,
2450 DRV_LOG(ERR, "port %u invalid behavior %d",
2452 fdir_filter->action.behavior);
2453 rte_errno = ENOTSUP;
2456 attributes->queue.index = fdir_filter->action.rx_queue;
2458 switch (fdir_filter->input.flow_type) {
2459 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2460 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2461 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2462 attributes->l3.ipv4.hdr = (struct ipv4_hdr){
2463 .src_addr = input->flow.ip4_flow.src_ip,
2464 .dst_addr = input->flow.ip4_flow.dst_ip,
2465 .time_to_live = input->flow.ip4_flow.ttl,
2466 .type_of_service = input->flow.ip4_flow.tos,
2468 attributes->l3_mask.ipv4.hdr = (struct ipv4_hdr){
2469 .src_addr = mask->ipv4_mask.src_ip,
2470 .dst_addr = mask->ipv4_mask.dst_ip,
2471 .time_to_live = mask->ipv4_mask.ttl,
2472 .type_of_service = mask->ipv4_mask.tos,
2473 .next_proto_id = mask->ipv4_mask.proto,
2475 attributes->items[1] = (struct rte_flow_item){
2476 .type = RTE_FLOW_ITEM_TYPE_IPV4,
2477 .spec = &attributes->l3,
2478 .mask = &attributes->l3_mask,
2481 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2482 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2483 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2484 attributes->l3.ipv6.hdr = (struct ipv6_hdr){
2485 .hop_limits = input->flow.ipv6_flow.hop_limits,
2486 .proto = input->flow.ipv6_flow.proto,
2489 memcpy(attributes->l3.ipv6.hdr.src_addr,
2490 input->flow.ipv6_flow.src_ip,
2491 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2492 memcpy(attributes->l3.ipv6.hdr.dst_addr,
2493 input->flow.ipv6_flow.dst_ip,
2494 RTE_DIM(attributes->l3.ipv6.hdr.src_addr));
2495 memcpy(attributes->l3_mask.ipv6.hdr.src_addr,
2496 mask->ipv6_mask.src_ip,
2497 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2498 memcpy(attributes->l3_mask.ipv6.hdr.dst_addr,
2499 mask->ipv6_mask.dst_ip,
2500 RTE_DIM(attributes->l3_mask.ipv6.hdr.src_addr));
2501 attributes->items[1] = (struct rte_flow_item){
2502 .type = RTE_FLOW_ITEM_TYPE_IPV6,
2503 .spec = &attributes->l3,
2504 .mask = &attributes->l3_mask,
2508 DRV_LOG(ERR, "port %u invalid flow type%d",
2509 dev->data->port_id, fdir_filter->input.flow_type);
2510 rte_errno = ENOTSUP;
2514 switch (fdir_filter->input.flow_type) {
2515 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2516 attributes->l4.udp.hdr = (struct udp_hdr){
2517 .src_port = input->flow.udp4_flow.src_port,
2518 .dst_port = input->flow.udp4_flow.dst_port,
2520 attributes->l4_mask.udp.hdr = (struct udp_hdr){
2521 .src_port = mask->src_port_mask,
2522 .dst_port = mask->dst_port_mask,
2524 attributes->items[2] = (struct rte_flow_item){
2525 .type = RTE_FLOW_ITEM_TYPE_UDP,
2526 .spec = &attributes->l4,
2527 .mask = &attributes->l4_mask,
2530 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2531 attributes->l4.tcp.hdr = (struct tcp_hdr){
2532 .src_port = input->flow.tcp4_flow.src_port,
2533 .dst_port = input->flow.tcp4_flow.dst_port,
2535 attributes->l4_mask.tcp.hdr = (struct tcp_hdr){
2536 .src_port = mask->src_port_mask,
2537 .dst_port = mask->dst_port_mask,
2539 attributes->items[2] = (struct rte_flow_item){
2540 .type = RTE_FLOW_ITEM_TYPE_TCP,
2541 .spec = &attributes->l4,
2542 .mask = &attributes->l4_mask,
2545 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2546 attributes->l4.udp.hdr = (struct udp_hdr){
2547 .src_port = input->flow.udp6_flow.src_port,
2548 .dst_port = input->flow.udp6_flow.dst_port,
2550 attributes->l4_mask.udp.hdr = (struct udp_hdr){
2551 .src_port = mask->src_port_mask,
2552 .dst_port = mask->dst_port_mask,
2554 attributes->items[2] = (struct rte_flow_item){
2555 .type = RTE_FLOW_ITEM_TYPE_UDP,
2556 .spec = &attributes->l4,
2557 .mask = &attributes->l4_mask,
2560 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2561 attributes->l4.tcp.hdr = (struct tcp_hdr){
2562 .src_port = input->flow.tcp6_flow.src_port,
2563 .dst_port = input->flow.tcp6_flow.dst_port,
2565 attributes->l4_mask.tcp.hdr = (struct tcp_hdr){
2566 .src_port = mask->src_port_mask,
2567 .dst_port = mask->dst_port_mask,
2569 attributes->items[2] = (struct rte_flow_item){
2570 .type = RTE_FLOW_ITEM_TYPE_TCP,
2571 .spec = &attributes->l4,
2572 .mask = &attributes->l4_mask,
2575 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2576 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2579 DRV_LOG(ERR, "port %u invalid flow type%d",
2580 dev->data->port_id, fdir_filter->input.flow_type);
2581 rte_errno = ENOTSUP;
2588 * Add new flow director filter and store it in list.
2591 * Pointer to Ethernet device.
2592 * @param fdir_filter
2593 * Flow director filter to add.
2596 * 0 on success, a negative errno value otherwise and rte_errno is set.
2599 mlx5_fdir_filter_add(struct rte_eth_dev *dev,
2600 const struct rte_eth_fdir_filter *fdir_filter)
2602 struct priv *priv = dev->data->dev_private;
2603 struct mlx5_fdir attributes = {
2606 .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
2607 .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
2611 struct rte_flow_error error;
2612 struct rte_flow *flow;
2615 ret = mlx5_fdir_filter_convert(dev, fdir_filter, &attributes);
2618 flow = mlx5_flow_list_create(dev, &priv->flows, &attributes.attr,
2619 attributes.items, attributes.actions,
2622 DRV_LOG(DEBUG, "port %u FDIR created %p", dev->data->port_id,
2630 * Delete specific filter.
2633 * Pointer to Ethernet device.
2634 * @param fdir_filter
2635 * Filter to be deleted.
2638 * 0 on success, a negative errno value otherwise and rte_errno is set.
2641 mlx5_fdir_filter_delete(struct rte_eth_dev *dev __rte_unused,
2642 const struct rte_eth_fdir_filter *fdir_filter
2645 rte_errno = ENOTSUP;
2650 * Update queue for specific filter.
2653 * Pointer to Ethernet device.
2654 * @param fdir_filter
2655 * Filter to be updated.
2658 * 0 on success, a negative errno value otherwise and rte_errno is set.
2661 mlx5_fdir_filter_update(struct rte_eth_dev *dev,
2662 const struct rte_eth_fdir_filter *fdir_filter)
2666 ret = mlx5_fdir_filter_delete(dev, fdir_filter);
2669 return mlx5_fdir_filter_add(dev, fdir_filter);
2673 * Flush all filters.
2676 * Pointer to Ethernet device.
2679 mlx5_fdir_filter_flush(struct rte_eth_dev *dev)
2681 struct priv *priv = dev->data->dev_private;
2683 mlx5_flow_list_flush(dev, &priv->flows);
2687 * Get flow director information.
2690 * Pointer to Ethernet device.
2691 * @param[out] fdir_info
2692 * Resulting flow director information.
2695 mlx5_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
2697 struct rte_eth_fdir_masks *mask =
2698 &dev->data->dev_conf.fdir_conf.mask;
2700 fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
2701 fdir_info->guarant_spc = 0;
2702 rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
2703 fdir_info->max_flexpayload = 0;
2704 fdir_info->flow_types_mask[0] = 0;
2705 fdir_info->flex_payload_unit = 0;
2706 fdir_info->max_flex_payload_segment_num = 0;
2707 fdir_info->flex_payload_limit = 0;
2708 memset(&fdir_info->flex_conf, 0, sizeof(fdir_info->flex_conf));
2712 * Deal with flow director operations.
2715 * Pointer to Ethernet device.
2717 * Operation to perform.
2719 * Pointer to operation-specific structure.
2722 * 0 on success, a negative errno value otherwise and rte_errno is set.
2725 mlx5_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
2728 enum rte_fdir_mode fdir_mode =
2729 dev->data->dev_conf.fdir_conf.mode;
2731 if (filter_op == RTE_ETH_FILTER_NOP)
2733 if (fdir_mode != RTE_FDIR_MODE_PERFECT &&
2734 fdir_mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2735 DRV_LOG(ERR, "port %u flow director mode %d not supported",
2736 dev->data->port_id, fdir_mode);
2740 switch (filter_op) {
2741 case RTE_ETH_FILTER_ADD:
2742 return mlx5_fdir_filter_add(dev, arg);
2743 case RTE_ETH_FILTER_UPDATE:
2744 return mlx5_fdir_filter_update(dev, arg);
2745 case RTE_ETH_FILTER_DELETE:
2746 return mlx5_fdir_filter_delete(dev, arg);
2747 case RTE_ETH_FILTER_FLUSH:
2748 mlx5_fdir_filter_flush(dev);
2750 case RTE_ETH_FILTER_INFO:
2751 mlx5_fdir_info_get(dev, arg);
2754 DRV_LOG(DEBUG, "port %u unknown operation %u",
2755 dev->data->port_id, filter_op);
2763 * Manage filter operations.
2766 * Pointer to Ethernet device structure.
2767 * @param filter_type
2770 * Operation to perform.
2772 * Pointer to operation-specific structure.
2775 * 0 on success, a negative errno value otherwise and rte_errno is set.
2778 mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
2779 enum rte_filter_type filter_type,
2780 enum rte_filter_op filter_op,
2783 switch (filter_type) {
2784 case RTE_ETH_FILTER_GENERIC:
2785 if (filter_op != RTE_ETH_FILTER_GET) {
2789 *(const void **)arg = &mlx5_flow_ops;
2791 case RTE_ETH_FILTER_FDIR:
2792 return mlx5_fdir_ctrl_func(dev, filter_op, arg);
2794 DRV_LOG(ERR, "port %u filter type (%d) not supported",
2795 dev->data->port_id, filter_type);
2796 rte_errno = ENOTSUP;