1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Mellanox Technologies, Ltd
11 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
13 #pragma GCC diagnostic ignored "-Wpedantic"
15 #include <infiniband/verbs.h>
17 #pragma GCC diagnostic error "-Wpedantic"
20 #include <rte_common.h>
21 #include <rte_ether.h>
22 #include <rte_eth_ctrl.h>
23 #include <rte_ethdev_driver.h>
25 #include <rte_flow_driver.h>
26 #include <rte_malloc.h>
31 #include "mlx5_defs.h"
33 #include "mlx5_glue.h"
34 #include "mlx5_flow.h"
36 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
42 * Pointer to the rte_eth_dev structure.
46 * Attributes of flow that includes this item.
48 * Pointer to error structure.
51 * 0 on success, a negative errno value otherwise and rte_errno is set.
54 flow_dv_validate_item_meta(struct rte_eth_dev *dev,
55 const struct rte_flow_item *item,
56 const struct rte_flow_attr *attr,
57 struct rte_flow_error *error)
59 const struct rte_flow_item_meta *spec = item->spec;
60 const struct rte_flow_item_meta *mask = item->mask;
61 const struct rte_flow_item_meta nic_mask = {
62 .data = RTE_BE32(UINT32_MAX)
65 uint64_t offloads = dev->data->dev_conf.txmode.offloads;
67 if (!(offloads & DEV_TX_OFFLOAD_MATCH_METADATA))
68 return rte_flow_error_set(error, EPERM,
69 RTE_FLOW_ERROR_TYPE_ITEM,
71 "match on metadata offload "
72 "configuration is off for this port");
74 return rte_flow_error_set(error, EINVAL,
75 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
77 "data cannot be empty");
79 return rte_flow_error_set(error, EINVAL,
80 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
82 "data cannot be zero");
84 mask = &rte_flow_item_meta_mask;
85 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
86 (const uint8_t *)&nic_mask,
87 sizeof(struct rte_flow_item_meta),
92 return rte_flow_error_set(error, ENOTSUP,
93 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
95 "pattern not supported for ingress");
100 * Validate the L2 encap action.
102 * @param[in] action_flags
103 * Holds the actions detected until now.
105 * Pointer to the encap action.
107 * Pointer to flow attributes
109 * Pointer to error structure.
112 * 0 on success, a negative errno value otherwise and rte_errno is set.
115 flow_dv_validate_action_l2_encap(uint64_t action_flags,
116 const struct rte_flow_action *action,
117 const struct rte_flow_attr *attr,
118 struct rte_flow_error *error)
121 return rte_flow_error_set(error, EINVAL,
122 RTE_FLOW_ERROR_TYPE_ACTION, action,
123 "configuration cannot be null");
124 if (action_flags & MLX5_FLOW_ACTION_DROP)
125 return rte_flow_error_set(error, EINVAL,
126 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
127 "can't drop and encap in same flow");
128 if (action_flags & (MLX5_FLOW_ENCAP_ACTIONS | MLX5_FLOW_DECAP_ACTIONS))
129 return rte_flow_error_set(error, EINVAL,
130 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
131 "can only have a single encap or"
132 " decap action in a flow");
134 return rte_flow_error_set(error, ENOTSUP,
135 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
137 "encap action not supported for "
143 * Validate the L2 decap action.
145 * @param[in] action_flags
146 * Holds the actions detected until now.
148 * Pointer to flow attributes
150 * Pointer to error structure.
153 * 0 on success, a negative errno value otherwise and rte_errno is set.
156 flow_dv_validate_action_l2_decap(uint64_t action_flags,
157 const struct rte_flow_attr *attr,
158 struct rte_flow_error *error)
160 if (action_flags & MLX5_FLOW_ACTION_DROP)
161 return rte_flow_error_set(error, EINVAL,
162 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
163 "can't drop and decap in same flow");
164 if (action_flags & (MLX5_FLOW_ENCAP_ACTIONS | MLX5_FLOW_DECAP_ACTIONS))
165 return rte_flow_error_set(error, EINVAL,
166 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
167 "can only have a single encap or"
168 " decap action in a flow");
170 return rte_flow_error_set(error, ENOTSUP,
171 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
173 "decap action not supported for "
179 * Validate the raw encap action.
181 * @param[in] action_flags
182 * Holds the actions detected until now.
184 * Pointer to the encap action.
186 * Pointer to flow attributes
188 * Pointer to error structure.
191 * 0 on success, a negative errno value otherwise and rte_errno is set.
194 flow_dv_validate_action_raw_encap(uint64_t action_flags,
195 const struct rte_flow_action *action,
196 const struct rte_flow_attr *attr,
197 struct rte_flow_error *error)
200 return rte_flow_error_set(error, EINVAL,
201 RTE_FLOW_ERROR_TYPE_ACTION, action,
202 "configuration cannot be null");
203 if (action_flags & MLX5_FLOW_ACTION_DROP)
204 return rte_flow_error_set(error, EINVAL,
205 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
206 "can't drop and encap in same flow");
207 if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
208 return rte_flow_error_set(error, EINVAL,
209 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
210 "can only have a single encap"
211 " action in a flow");
212 /* encap without preceding decap is not supported for ingress */
213 if (attr->ingress && !(action_flags & MLX5_FLOW_ACTION_RAW_DECAP))
214 return rte_flow_error_set(error, ENOTSUP,
215 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
217 "encap action not supported for "
223 * Validate the raw decap action.
225 * @param[in] action_flags
226 * Holds the actions detected until now.
228 * Pointer to the encap action.
230 * Pointer to flow attributes
232 * Pointer to error structure.
235 * 0 on success, a negative errno value otherwise and rte_errno is set.
238 flow_dv_validate_action_raw_decap(uint64_t action_flags,
239 const struct rte_flow_action *action,
240 const struct rte_flow_attr *attr,
241 struct rte_flow_error *error)
243 if (action_flags & MLX5_FLOW_ACTION_DROP)
244 return rte_flow_error_set(error, EINVAL,
245 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
246 "can't drop and decap in same flow");
247 if (action_flags & MLX5_FLOW_ENCAP_ACTIONS)
248 return rte_flow_error_set(error, EINVAL,
249 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
250 "can't have encap action before"
252 if (action_flags & MLX5_FLOW_DECAP_ACTIONS)
253 return rte_flow_error_set(error, EINVAL,
254 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
255 "can only have a single decap"
256 " action in a flow");
257 /* decap action is valid on egress only if it is followed by encap */
259 for (; action->type != RTE_FLOW_ACTION_TYPE_END &&
260 action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP;
263 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP)
264 return rte_flow_error_set
266 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
267 NULL, "decap action not supported"
275 * Find existing encap/decap resource or create and register a new one.
277 * @param dev[in, out]
278 * Pointer to rte_eth_dev structure.
279 * @param[in, out] resource
280 * Pointer to encap/decap resource.
281 * @parm[in, out] dev_flow
282 * Pointer to the dev_flow.
284 * pointer to error structure.
287 * 0 on success otherwise -errno and errno is set.
290 flow_dv_encap_decap_resource_register
291 (struct rte_eth_dev *dev,
292 struct mlx5_flow_dv_encap_decap_resource *resource,
293 struct mlx5_flow *dev_flow,
294 struct rte_flow_error *error)
296 struct priv *priv = dev->data->dev_private;
297 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
299 /* Lookup a matching resource from cache. */
300 LIST_FOREACH(cache_resource, &priv->encaps_decaps, next) {
301 if (resource->reformat_type == cache_resource->reformat_type &&
302 resource->ft_type == cache_resource->ft_type &&
303 resource->size == cache_resource->size &&
304 !memcmp((const void *)resource->buf,
305 (const void *)cache_resource->buf,
307 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d++",
308 (void *)cache_resource,
309 rte_atomic32_read(&cache_resource->refcnt));
310 rte_atomic32_inc(&cache_resource->refcnt);
311 dev_flow->dv.encap_decap = cache_resource;
315 /* Register new encap/decap resource. */
316 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
318 return rte_flow_error_set(error, ENOMEM,
319 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
320 "cannot allocate resource memory");
321 *cache_resource = *resource;
322 cache_resource->verbs_action =
323 mlx5_glue->dv_create_flow_action_packet_reformat
324 (priv->ctx, cache_resource->size,
325 (cache_resource->size ? cache_resource->buf : NULL),
326 cache_resource->reformat_type,
327 cache_resource->ft_type);
328 if (!cache_resource->verbs_action) {
329 rte_free(cache_resource);
330 return rte_flow_error_set(error, ENOMEM,
331 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
332 NULL, "cannot create action");
334 rte_atomic32_init(&cache_resource->refcnt);
335 rte_atomic32_inc(&cache_resource->refcnt);
336 LIST_INSERT_HEAD(&priv->encaps_decaps, cache_resource, next);
337 dev_flow->dv.encap_decap = cache_resource;
338 DRV_LOG(DEBUG, "new encap/decap resource %p: refcnt %d++",
339 (void *)cache_resource,
340 rte_atomic32_read(&cache_resource->refcnt));
345 * Get the size of specific rte_flow_item_type
347 * @param[in] item_type
348 * Tested rte_flow_item_type.
351 * sizeof struct item_type, 0 if void or irrelevant.
354 flow_dv_get_item_len(const enum rte_flow_item_type item_type)
359 case RTE_FLOW_ITEM_TYPE_ETH:
360 retval = sizeof(struct rte_flow_item_eth);
362 case RTE_FLOW_ITEM_TYPE_VLAN:
363 retval = sizeof(struct rte_flow_item_vlan);
365 case RTE_FLOW_ITEM_TYPE_IPV4:
366 retval = sizeof(struct rte_flow_item_ipv4);
368 case RTE_FLOW_ITEM_TYPE_IPV6:
369 retval = sizeof(struct rte_flow_item_ipv6);
371 case RTE_FLOW_ITEM_TYPE_UDP:
372 retval = sizeof(struct rte_flow_item_udp);
374 case RTE_FLOW_ITEM_TYPE_TCP:
375 retval = sizeof(struct rte_flow_item_tcp);
377 case RTE_FLOW_ITEM_TYPE_VXLAN:
378 retval = sizeof(struct rte_flow_item_vxlan);
380 case RTE_FLOW_ITEM_TYPE_GRE:
381 retval = sizeof(struct rte_flow_item_gre);
383 case RTE_FLOW_ITEM_TYPE_NVGRE:
384 retval = sizeof(struct rte_flow_item_nvgre);
386 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
387 retval = sizeof(struct rte_flow_item_vxlan_gpe);
389 case RTE_FLOW_ITEM_TYPE_MPLS:
390 retval = sizeof(struct rte_flow_item_mpls);
392 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
400 #define MLX5_ENCAP_IPV4_VERSION 0x40
401 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
402 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
403 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
404 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
405 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
406 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
409 * Convert the encap action data from list of rte_flow_item to raw buffer
412 * Pointer to rte_flow_item objects list.
414 * Pointer to the output buffer.
416 * Pointer to the output buffer size.
418 * Pointer to the error structure.
421 * 0 on success, a negative errno value otherwise and rte_errno is set.
424 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
425 size_t *size, struct rte_flow_error *error)
427 struct ether_hdr *eth = NULL;
428 struct vlan_hdr *vlan = NULL;
429 struct ipv4_hdr *ipv4 = NULL;
430 struct ipv6_hdr *ipv6 = NULL;
431 struct udp_hdr *udp = NULL;
432 struct vxlan_hdr *vxlan = NULL;
433 struct vxlan_gpe_hdr *vxlan_gpe = NULL;
434 struct gre_hdr *gre = NULL;
436 size_t temp_size = 0;
439 return rte_flow_error_set(error, EINVAL,
440 RTE_FLOW_ERROR_TYPE_ACTION,
441 NULL, "invalid empty data");
442 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
443 len = flow_dv_get_item_len(items->type);
444 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
445 return rte_flow_error_set(error, EINVAL,
446 RTE_FLOW_ERROR_TYPE_ACTION,
448 "items total size is too big"
449 " for encap action");
450 rte_memcpy((void *)&buf[temp_size], items->spec, len);
451 switch (items->type) {
452 case RTE_FLOW_ITEM_TYPE_ETH:
453 eth = (struct ether_hdr *)&buf[temp_size];
455 case RTE_FLOW_ITEM_TYPE_VLAN:
456 vlan = (struct vlan_hdr *)&buf[temp_size];
458 return rte_flow_error_set(error, EINVAL,
459 RTE_FLOW_ERROR_TYPE_ACTION,
461 "eth header not found");
462 if (!eth->ether_type)
463 eth->ether_type = RTE_BE16(ETHER_TYPE_VLAN);
465 case RTE_FLOW_ITEM_TYPE_IPV4:
466 ipv4 = (struct ipv4_hdr *)&buf[temp_size];
468 return rte_flow_error_set(error, EINVAL,
469 RTE_FLOW_ERROR_TYPE_ACTION,
471 "neither eth nor vlan"
473 if (vlan && !vlan->eth_proto)
474 vlan->eth_proto = RTE_BE16(ETHER_TYPE_IPv4);
475 else if (eth && !eth->ether_type)
476 eth->ether_type = RTE_BE16(ETHER_TYPE_IPv4);
477 if (!ipv4->version_ihl)
478 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
479 MLX5_ENCAP_IPV4_IHL_MIN;
480 if (!ipv4->time_to_live)
481 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
483 case RTE_FLOW_ITEM_TYPE_IPV6:
484 ipv6 = (struct ipv6_hdr *)&buf[temp_size];
486 return rte_flow_error_set(error, EINVAL,
487 RTE_FLOW_ERROR_TYPE_ACTION,
489 "neither eth nor vlan"
491 if (vlan && !vlan->eth_proto)
492 vlan->eth_proto = RTE_BE16(ETHER_TYPE_IPv6);
493 else if (eth && !eth->ether_type)
494 eth->ether_type = RTE_BE16(ETHER_TYPE_IPv6);
497 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
498 if (!ipv6->hop_limits)
499 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
501 case RTE_FLOW_ITEM_TYPE_UDP:
502 udp = (struct udp_hdr *)&buf[temp_size];
504 return rte_flow_error_set(error, EINVAL,
505 RTE_FLOW_ERROR_TYPE_ACTION,
507 "ip header not found");
508 if (ipv4 && !ipv4->next_proto_id)
509 ipv4->next_proto_id = IPPROTO_UDP;
510 else if (ipv6 && !ipv6->proto)
511 ipv6->proto = IPPROTO_UDP;
513 case RTE_FLOW_ITEM_TYPE_VXLAN:
514 vxlan = (struct vxlan_hdr *)&buf[temp_size];
516 return rte_flow_error_set(error, EINVAL,
517 RTE_FLOW_ERROR_TYPE_ACTION,
519 "udp header not found");
521 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
522 if (!vxlan->vx_flags)
524 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
526 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
527 vxlan_gpe = (struct vxlan_gpe_hdr *)&buf[temp_size];
529 return rte_flow_error_set(error, EINVAL,
530 RTE_FLOW_ERROR_TYPE_ACTION,
532 "udp header not found");
533 if (!vxlan_gpe->proto)
534 return rte_flow_error_set(error, EINVAL,
535 RTE_FLOW_ERROR_TYPE_ACTION,
537 "next protocol not found");
540 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
541 if (!vxlan_gpe->vx_flags)
542 vxlan_gpe->vx_flags =
543 MLX5_ENCAP_VXLAN_GPE_FLAGS;
545 case RTE_FLOW_ITEM_TYPE_GRE:
546 case RTE_FLOW_ITEM_TYPE_NVGRE:
547 gre = (struct gre_hdr *)&buf[temp_size];
549 return rte_flow_error_set(error, EINVAL,
550 RTE_FLOW_ERROR_TYPE_ACTION,
552 "next protocol not found");
554 return rte_flow_error_set(error, EINVAL,
555 RTE_FLOW_ERROR_TYPE_ACTION,
557 "ip header not found");
558 if (ipv4 && !ipv4->next_proto_id)
559 ipv4->next_proto_id = IPPROTO_GRE;
560 else if (ipv6 && !ipv6->proto)
561 ipv6->proto = IPPROTO_GRE;
563 case RTE_FLOW_ITEM_TYPE_VOID:
566 return rte_flow_error_set(error, EINVAL,
567 RTE_FLOW_ERROR_TYPE_ACTION,
569 "unsupported item type");
579 * Convert L2 encap action to DV specification.
582 * Pointer to rte_eth_dev structure.
584 * Pointer to action structure.
585 * @param[in, out] dev_flow
586 * Pointer to the mlx5_flow.
588 * Pointer to the error structure.
591 * 0 on success, a negative errno value otherwise and rte_errno is set.
594 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
595 const struct rte_flow_action *action,
596 struct mlx5_flow *dev_flow,
597 struct rte_flow_error *error)
599 const struct rte_flow_item *encap_data;
600 const struct rte_flow_action_raw_encap *raw_encap_data;
601 struct mlx5_flow_dv_encap_decap_resource res = {
603 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
604 .ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
607 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
609 (const struct rte_flow_action_raw_encap *)action->conf;
610 res.size = raw_encap_data->size;
611 memcpy(res.buf, raw_encap_data->data, res.size);
613 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
615 ((const struct rte_flow_action_vxlan_encap *)
616 action->conf)->definition;
619 ((const struct rte_flow_action_nvgre_encap *)
620 action->conf)->definition;
621 if (flow_dv_convert_encap_data(encap_data, res.buf,
625 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
626 return rte_flow_error_set(error, EINVAL,
627 RTE_FLOW_ERROR_TYPE_ACTION,
628 NULL, "can't create L2 encap action");
633 * Convert L2 decap action to DV specification.
636 * Pointer to rte_eth_dev structure.
637 * @param[in, out] dev_flow
638 * Pointer to the mlx5_flow.
640 * Pointer to the error structure.
643 * 0 on success, a negative errno value otherwise and rte_errno is set.
646 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
647 struct mlx5_flow *dev_flow,
648 struct rte_flow_error *error)
650 struct mlx5_flow_dv_encap_decap_resource res = {
653 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
654 .ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
657 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
658 return rte_flow_error_set(error, EINVAL,
659 RTE_FLOW_ERROR_TYPE_ACTION,
660 NULL, "can't create L2 decap action");
665 * Convert raw decap/encap (L3 tunnel) action to DV specification.
668 * Pointer to rte_eth_dev structure.
670 * Pointer to action structure.
671 * @param[in, out] dev_flow
672 * Pointer to the mlx5_flow.
674 * Pointer to the flow attributes.
676 * Pointer to the error structure.
679 * 0 on success, a negative errno value otherwise and rte_errno is set.
682 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
683 const struct rte_flow_action *action,
684 struct mlx5_flow *dev_flow,
685 const struct rte_flow_attr *attr,
686 struct rte_flow_error *error)
688 const struct rte_flow_action_raw_encap *encap_data;
689 struct mlx5_flow_dv_encap_decap_resource res;
691 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
692 res.size = encap_data->size;
693 memcpy(res.buf, encap_data->data, res.size);
694 res.reformat_type = attr->egress ?
695 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL :
696 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2;
697 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
698 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
699 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
700 return rte_flow_error_set(error, EINVAL,
701 RTE_FLOW_ERROR_TYPE_ACTION,
702 NULL, "can't create encap action");
707 * Verify the @p attributes will be correctly understood by the NIC and store
708 * them in the @p flow if everything is correct.
711 * Pointer to dev struct.
712 * @param[in] attributes
713 * Pointer to flow attributes
715 * Pointer to error structure.
718 * 0 on success, a negative errno value otherwise and rte_errno is set.
721 flow_dv_validate_attributes(struct rte_eth_dev *dev,
722 const struct rte_flow_attr *attributes,
723 struct rte_flow_error *error)
725 struct priv *priv = dev->data->dev_private;
726 uint32_t priority_max = priv->config.flow_prio - 1;
728 if (attributes->group)
729 return rte_flow_error_set(error, ENOTSUP,
730 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
732 "groups is not supported");
733 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
734 attributes->priority >= priority_max)
735 return rte_flow_error_set(error, ENOTSUP,
736 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
738 "priority out of range");
739 if (attributes->transfer)
740 return rte_flow_error_set(error, ENOTSUP,
741 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
743 "transfer is not supported");
744 if (!(attributes->egress ^ attributes->ingress))
745 return rte_flow_error_set(error, ENOTSUP,
746 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
747 "must specify exactly one of "
748 "ingress or egress");
753 * Internal validation function. For validating both actions and items.
756 * Pointer to the rte_eth_dev structure.
758 * Pointer to the flow attributes.
760 * Pointer to the list of items.
762 * Pointer to the list of actions.
764 * Pointer to the error structure.
767 * 0 on success, a negative errno value otherwise and rte_ernno is set.
770 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
771 const struct rte_flow_item items[],
772 const struct rte_flow_action actions[],
773 struct rte_flow_error *error)
776 uint64_t action_flags = 0;
777 uint64_t item_flags = 0;
779 uint8_t next_protocol = 0xff;
784 ret = flow_dv_validate_attributes(dev, attr, error);
787 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
788 tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
789 switch (items->type) {
790 case RTE_FLOW_ITEM_TYPE_VOID:
792 case RTE_FLOW_ITEM_TYPE_ETH:
793 ret = mlx5_flow_validate_item_eth(items, item_flags,
797 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
798 MLX5_FLOW_LAYER_OUTER_L2;
800 case RTE_FLOW_ITEM_TYPE_VLAN:
801 ret = mlx5_flow_validate_item_vlan(items, item_flags,
805 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
806 MLX5_FLOW_LAYER_OUTER_VLAN;
808 case RTE_FLOW_ITEM_TYPE_IPV4:
809 ret = mlx5_flow_validate_item_ipv4(items, item_flags,
813 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
814 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
815 if (items->mask != NULL &&
816 ((const struct rte_flow_item_ipv4 *)
817 items->mask)->hdr.next_proto_id)
819 ((const struct rte_flow_item_ipv4 *)
820 (items->spec))->hdr.next_proto_id;
822 case RTE_FLOW_ITEM_TYPE_IPV6:
823 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
827 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
828 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
829 if (items->mask != NULL &&
830 ((const struct rte_flow_item_ipv6 *)
831 items->mask)->hdr.proto)
833 ((const struct rte_flow_item_ipv6 *)
834 items->spec)->hdr.proto;
836 case RTE_FLOW_ITEM_TYPE_TCP:
837 ret = mlx5_flow_validate_item_tcp
840 &rte_flow_item_tcp_mask,
844 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
845 MLX5_FLOW_LAYER_OUTER_L4_TCP;
847 case RTE_FLOW_ITEM_TYPE_UDP:
848 ret = mlx5_flow_validate_item_udp(items, item_flags,
853 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
854 MLX5_FLOW_LAYER_OUTER_L4_UDP;
856 case RTE_FLOW_ITEM_TYPE_GRE:
857 case RTE_FLOW_ITEM_TYPE_NVGRE:
858 ret = mlx5_flow_validate_item_gre(items, item_flags,
859 next_protocol, error);
862 item_flags |= MLX5_FLOW_LAYER_GRE;
864 case RTE_FLOW_ITEM_TYPE_VXLAN:
865 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
869 item_flags |= MLX5_FLOW_LAYER_VXLAN;
871 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
872 ret = mlx5_flow_validate_item_vxlan_gpe(items,
877 item_flags |= MLX5_FLOW_LAYER_VXLAN_GPE;
879 case RTE_FLOW_ITEM_TYPE_META:
880 ret = flow_dv_validate_item_meta(dev, items, attr,
884 item_flags |= MLX5_FLOW_ITEM_METADATA;
887 return rte_flow_error_set(error, ENOTSUP,
888 RTE_FLOW_ERROR_TYPE_ITEM,
889 NULL, "item not supported");
892 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
893 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
894 return rte_flow_error_set(error, ENOTSUP,
895 RTE_FLOW_ERROR_TYPE_ACTION,
896 actions, "too many actions");
897 switch (actions->type) {
898 case RTE_FLOW_ACTION_TYPE_VOID:
900 case RTE_FLOW_ACTION_TYPE_FLAG:
901 ret = mlx5_flow_validate_action_flag(action_flags,
905 action_flags |= MLX5_FLOW_ACTION_FLAG;
908 case RTE_FLOW_ACTION_TYPE_MARK:
909 ret = mlx5_flow_validate_action_mark(actions,
914 action_flags |= MLX5_FLOW_ACTION_MARK;
917 case RTE_FLOW_ACTION_TYPE_DROP:
918 ret = mlx5_flow_validate_action_drop(action_flags,
922 action_flags |= MLX5_FLOW_ACTION_DROP;
925 case RTE_FLOW_ACTION_TYPE_QUEUE:
926 ret = mlx5_flow_validate_action_queue(actions,
931 action_flags |= MLX5_FLOW_ACTION_QUEUE;
934 case RTE_FLOW_ACTION_TYPE_RSS:
935 ret = mlx5_flow_validate_action_rss(actions,
940 action_flags |= MLX5_FLOW_ACTION_RSS;
943 case RTE_FLOW_ACTION_TYPE_COUNT:
944 ret = mlx5_flow_validate_action_count(dev, attr, error);
947 action_flags |= MLX5_FLOW_ACTION_COUNT;
950 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
951 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
952 ret = flow_dv_validate_action_l2_encap(action_flags,
957 action_flags |= actions->type ==
958 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ?
959 MLX5_FLOW_ACTION_VXLAN_ENCAP :
960 MLX5_FLOW_ACTION_NVGRE_ENCAP;
963 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
964 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
965 ret = flow_dv_validate_action_l2_decap(action_flags,
969 action_flags |= actions->type ==
970 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP ?
971 MLX5_FLOW_ACTION_VXLAN_DECAP :
972 MLX5_FLOW_ACTION_NVGRE_DECAP;
975 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
976 ret = flow_dv_validate_action_raw_encap(action_flags,
981 action_flags |= MLX5_FLOW_ACTION_RAW_ENCAP;
984 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
985 ret = flow_dv_validate_action_raw_decap(action_flags,
990 action_flags |= MLX5_FLOW_ACTION_RAW_DECAP;
994 return rte_flow_error_set(error, ENOTSUP,
995 RTE_FLOW_ERROR_TYPE_ACTION,
997 "action not supported");
1000 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
1001 return rte_flow_error_set(error, EINVAL,
1002 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1003 "no fate action is found");
1008 * Internal preparation function. Allocates the DV flow size,
1009 * this size is constant.
1012 * Pointer to the flow attributes.
1014 * Pointer to the list of items.
1015 * @param[in] actions
1016 * Pointer to the list of actions.
1018 * Pointer to the error structure.
1021 * Pointer to mlx5_flow object on success,
1022 * otherwise NULL and rte_ernno is set.
1024 static struct mlx5_flow *
1025 flow_dv_prepare(const struct rte_flow_attr *attr __rte_unused,
1026 const struct rte_flow_item items[] __rte_unused,
1027 const struct rte_flow_action actions[] __rte_unused,
1028 struct rte_flow_error *error)
1030 uint32_t size = sizeof(struct mlx5_flow);
1031 struct mlx5_flow *flow;
1033 flow = rte_calloc(__func__, 1, size, 0);
1035 rte_flow_error_set(error, ENOMEM,
1036 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1037 "not enough memory to create flow");
1040 flow->dv.value.size = MLX5_ST_SZ_DB(fte_match_param);
1045 * Add Ethernet item to matcher and to the value.
1047 * @param[in, out] matcher
1049 * @param[in, out] key
1050 * Flow matcher value.
1052 * Flow pattern to translate.
1054 * Item is inner pattern.
1057 flow_dv_translate_item_eth(void *matcher, void *key,
1058 const struct rte_flow_item *item, int inner)
1060 const struct rte_flow_item_eth *eth_m = item->mask;
1061 const struct rte_flow_item_eth *eth_v = item->spec;
1062 const struct rte_flow_item_eth nic_mask = {
1063 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1064 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1065 .type = RTE_BE16(0xffff),
1077 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1079 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
1081 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1083 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
1085 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, dmac_47_16),
1086 ð_m->dst, sizeof(eth_m->dst));
1087 /* The value must be in the range of the mask. */
1088 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, dmac_47_16);
1089 for (i = 0; i < sizeof(eth_m->dst); ++i)
1090 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
1091 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, smac_47_16),
1092 ð_m->src, sizeof(eth_m->src));
1093 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, smac_47_16);
1094 /* The value must be in the range of the mask. */
1095 for (i = 0; i < sizeof(eth_m->dst); ++i)
1096 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
1097 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
1098 rte_be_to_cpu_16(eth_m->type));
1099 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, ethertype);
1100 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
1104 * Add VLAN item to matcher and to the value.
1106 * @param[in, out] matcher
1108 * @param[in, out] key
1109 * Flow matcher value.
1111 * Flow pattern to translate.
1113 * Item is inner pattern.
1116 flow_dv_translate_item_vlan(void *matcher, void *key,
1117 const struct rte_flow_item *item,
1120 const struct rte_flow_item_vlan *vlan_m = item->mask;
1121 const struct rte_flow_item_vlan *vlan_v = item->spec;
1122 const struct rte_flow_item_vlan nic_mask = {
1123 .tci = RTE_BE16(0x0fff),
1124 .inner_type = RTE_BE16(0xffff),
1136 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1138 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
1140 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1142 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
1144 tci_m = rte_be_to_cpu_16(vlan_m->tci);
1145 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
1146 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
1147 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
1148 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_vid, tci_m);
1149 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, tci_v);
1150 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_cfi, tci_m >> 12);
1151 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_cfi, tci_v >> 12);
1152 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_prio, tci_m >> 13);
1153 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, tci_v >> 13);
1157 * Add IPV4 item to matcher and to the value.
1159 * @param[in, out] matcher
1161 * @param[in, out] key
1162 * Flow matcher value.
1164 * Flow pattern to translate.
1166 * Item is inner pattern.
1169 flow_dv_translate_item_ipv4(void *matcher, void *key,
1170 const struct rte_flow_item *item,
1173 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
1174 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
1175 const struct rte_flow_item_ipv4 nic_mask = {
1177 .src_addr = RTE_BE32(0xffffffff),
1178 .dst_addr = RTE_BE32(0xffffffff),
1179 .type_of_service = 0xff,
1180 .next_proto_id = 0xff,
1190 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1192 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
1194 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1196 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
1198 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
1199 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 4);
1204 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
1205 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
1206 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
1207 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
1208 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
1209 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
1210 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
1211 src_ipv4_src_ipv6.ipv4_layout.ipv4);
1212 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
1213 src_ipv4_src_ipv6.ipv4_layout.ipv4);
1214 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
1215 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
1216 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
1217 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
1218 ipv4_m->hdr.type_of_service);
1219 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
1220 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
1221 ipv4_m->hdr.type_of_service >> 2);
1222 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
1223 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
1224 ipv4_m->hdr.next_proto_id);
1225 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
1226 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
1230 * Add IPV6 item to matcher and to the value.
1232 * @param[in, out] matcher
1234 * @param[in, out] key
1235 * Flow matcher value.
1237 * Flow pattern to translate.
1239 * Item is inner pattern.
1242 flow_dv_translate_item_ipv6(void *matcher, void *key,
1243 const struct rte_flow_item *item,
1246 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
1247 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
1248 const struct rte_flow_item_ipv6 nic_mask = {
1251 "\xff\xff\xff\xff\xff\xff\xff\xff"
1252 "\xff\xff\xff\xff\xff\xff\xff\xff",
1254 "\xff\xff\xff\xff\xff\xff\xff\xff"
1255 "\xff\xff\xff\xff\xff\xff\xff\xff",
1256 .vtc_flow = RTE_BE32(0xffffffff),
1263 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
1264 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
1273 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1275 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
1277 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1279 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
1281 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
1282 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 6);
1287 size = sizeof(ipv6_m->hdr.dst_addr);
1288 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
1289 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
1290 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
1291 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
1292 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
1293 for (i = 0; i < size; ++i)
1294 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
1295 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
1296 src_ipv4_src_ipv6.ipv6_layout.ipv6);
1297 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
1298 src_ipv4_src_ipv6.ipv6_layout.ipv6);
1299 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
1300 for (i = 0; i < size; ++i)
1301 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
1303 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
1304 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
1305 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
1306 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
1307 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
1308 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
1311 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
1313 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
1316 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
1318 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
1322 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
1324 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
1325 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
1329 * Add TCP item to matcher and to the value.
1331 * @param[in, out] matcher
1333 * @param[in, out] key
1334 * Flow matcher value.
1336 * Flow pattern to translate.
1338 * Item is inner pattern.
1341 flow_dv_translate_item_tcp(void *matcher, void *key,
1342 const struct rte_flow_item *item,
1345 const struct rte_flow_item_tcp *tcp_m = item->mask;
1346 const struct rte_flow_item_tcp *tcp_v = item->spec;
1351 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1353 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
1355 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1357 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
1359 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
1360 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
1364 tcp_m = &rte_flow_item_tcp_mask;
1365 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
1366 rte_be_to_cpu_16(tcp_m->hdr.src_port));
1367 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
1368 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
1369 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
1370 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
1371 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
1372 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
1376 * Add UDP item to matcher and to the value.
1378 * @param[in, out] matcher
1380 * @param[in, out] key
1381 * Flow matcher value.
1383 * Flow pattern to translate.
1385 * Item is inner pattern.
1388 flow_dv_translate_item_udp(void *matcher, void *key,
1389 const struct rte_flow_item *item,
1392 const struct rte_flow_item_udp *udp_m = item->mask;
1393 const struct rte_flow_item_udp *udp_v = item->spec;
1398 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1400 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
1402 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1404 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
1406 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
1407 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
1411 udp_m = &rte_flow_item_udp_mask;
1412 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
1413 rte_be_to_cpu_16(udp_m->hdr.src_port));
1414 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
1415 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
1416 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
1417 rte_be_to_cpu_16(udp_m->hdr.dst_port));
1418 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
1419 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
1423 * Add GRE item to matcher and to the value.
1425 * @param[in, out] matcher
1427 * @param[in, out] key
1428 * Flow matcher value.
1430 * Flow pattern to translate.
1432 * Item is inner pattern.
1435 flow_dv_translate_item_gre(void *matcher, void *key,
1436 const struct rte_flow_item *item,
1439 const struct rte_flow_item_gre *gre_m = item->mask;
1440 const struct rte_flow_item_gre *gre_v = item->spec;
1443 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
1444 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
1447 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1449 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
1451 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1453 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
1455 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
1456 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
1460 gre_m = &rte_flow_item_gre_mask;
1461 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
1462 rte_be_to_cpu_16(gre_m->protocol));
1463 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
1464 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
1468 * Add NVGRE item to matcher and to the value.
1470 * @param[in, out] matcher
1472 * @param[in, out] key
1473 * Flow matcher value.
1475 * Flow pattern to translate.
1477 * Item is inner pattern.
1480 flow_dv_translate_item_nvgre(void *matcher, void *key,
1481 const struct rte_flow_item *item,
1484 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
1485 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
1486 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
1487 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
1488 const char *tni_flow_id_m = (const char *)nvgre_m->tni;
1489 const char *tni_flow_id_v = (const char *)nvgre_v->tni;
1495 flow_dv_translate_item_gre(matcher, key, item, inner);
1499 nvgre_m = &rte_flow_item_nvgre_mask;
1500 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
1501 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
1502 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
1503 memcpy(gre_key_m, tni_flow_id_m, size);
1504 for (i = 0; i < size; ++i)
1505 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
1509 * Add VXLAN item to matcher and to the value.
1511 * @param[in, out] matcher
1513 * @param[in, out] key
1514 * Flow matcher value.
1516 * Flow pattern to translate.
1518 * Item is inner pattern.
1521 flow_dv_translate_item_vxlan(void *matcher, void *key,
1522 const struct rte_flow_item *item,
1525 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
1526 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
1529 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
1530 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
1538 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1540 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
1542 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
1544 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
1546 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
1547 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
1548 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
1549 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
1550 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
1555 vxlan_m = &rte_flow_item_vxlan_mask;
1556 size = sizeof(vxlan_m->vni);
1557 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
1558 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
1559 memcpy(vni_m, vxlan_m->vni, size);
1560 for (i = 0; i < size; ++i)
1561 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
1565 * Add META item to matcher
1567 * @param[in, out] matcher
1569 * @param[in, out] key
1570 * Flow matcher value.
1572 * Flow pattern to translate.
1574 * Item is inner pattern.
1577 flow_dv_translate_item_meta(void *matcher, void *key,
1578 const struct rte_flow_item *item)
1580 const struct rte_flow_item_meta *meta_m;
1581 const struct rte_flow_item_meta *meta_v;
1583 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
1585 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
1587 meta_m = (const void *)item->mask;
1589 meta_m = &rte_flow_item_meta_mask;
1590 meta_v = (const void *)item->spec;
1592 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a,
1593 rte_be_to_cpu_32(meta_m->data));
1594 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a,
1595 rte_be_to_cpu_32(meta_v->data & meta_m->data));
1599 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
1601 #define HEADER_IS_ZERO(match_criteria, headers) \
1602 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
1603 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
1606 * Calculate flow matcher enable bitmap.
1608 * @param match_criteria
1609 * Pointer to flow matcher criteria.
1612 * Bitmap of enabled fields.
1615 flow_dv_matcher_enable(uint32_t *match_criteria)
1617 uint8_t match_criteria_enable;
1619 match_criteria_enable =
1620 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
1621 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
1622 match_criteria_enable |=
1623 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
1624 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
1625 match_criteria_enable |=
1626 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
1627 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
1628 match_criteria_enable |=
1629 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
1630 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
1632 return match_criteria_enable;
1636 * Register the flow matcher.
1638 * @param dev[in, out]
1639 * Pointer to rte_eth_dev structure.
1640 * @param[in, out] matcher
1641 * Pointer to flow matcher.
1642 * @parm[in, out] dev_flow
1643 * Pointer to the dev_flow.
1645 * pointer to error structure.
1648 * 0 on success otherwise -errno and errno is set.
1651 flow_dv_matcher_register(struct rte_eth_dev *dev,
1652 struct mlx5_flow_dv_matcher *matcher,
1653 struct mlx5_flow *dev_flow,
1654 struct rte_flow_error *error)
1656 struct priv *priv = dev->data->dev_private;
1657 struct mlx5_flow_dv_matcher *cache_matcher;
1658 struct mlx5dv_flow_matcher_attr dv_attr = {
1659 .type = IBV_FLOW_ATTR_NORMAL,
1660 .match_mask = (void *)&matcher->mask,
1663 /* Lookup from cache. */
1664 LIST_FOREACH(cache_matcher, &priv->matchers, next) {
1665 if (matcher->crc == cache_matcher->crc &&
1666 matcher->priority == cache_matcher->priority &&
1667 matcher->egress == cache_matcher->egress &&
1668 !memcmp((const void *)matcher->mask.buf,
1669 (const void *)cache_matcher->mask.buf,
1670 cache_matcher->mask.size)) {
1672 "priority %hd use %s matcher %p: refcnt %d++",
1673 cache_matcher->priority,
1674 cache_matcher->egress ? "tx" : "rx",
1675 (void *)cache_matcher,
1676 rte_atomic32_read(&cache_matcher->refcnt));
1677 rte_atomic32_inc(&cache_matcher->refcnt);
1678 dev_flow->dv.matcher = cache_matcher;
1682 /* Register new matcher. */
1683 cache_matcher = rte_calloc(__func__, 1, sizeof(*cache_matcher), 0);
1685 return rte_flow_error_set(error, ENOMEM,
1686 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1687 "cannot allocate matcher memory");
1688 *cache_matcher = *matcher;
1689 dv_attr.match_criteria_enable =
1690 flow_dv_matcher_enable(cache_matcher->mask.buf);
1691 dv_attr.priority = matcher->priority;
1692 if (matcher->egress)
1693 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
1694 cache_matcher->matcher_object =
1695 mlx5_glue->dv_create_flow_matcher(priv->ctx, &dv_attr);
1696 if (!cache_matcher->matcher_object) {
1697 rte_free(cache_matcher);
1698 return rte_flow_error_set(error, ENOMEM,
1699 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1700 NULL, "cannot create matcher");
1702 rte_atomic32_inc(&cache_matcher->refcnt);
1703 LIST_INSERT_HEAD(&priv->matchers, cache_matcher, next);
1704 dev_flow->dv.matcher = cache_matcher;
1705 DRV_LOG(DEBUG, "priority %hd new %s matcher %p: refcnt %d",
1706 cache_matcher->priority,
1707 cache_matcher->egress ? "tx" : "rx", (void *)cache_matcher,
1708 rte_atomic32_read(&cache_matcher->refcnt));
1713 * Fill the flow with DV spec.
1716 * Pointer to rte_eth_dev structure.
1717 * @param[in, out] dev_flow
1718 * Pointer to the sub flow.
1720 * Pointer to the flow attributes.
1722 * Pointer to the list of items.
1723 * @param[in] actions
1724 * Pointer to the list of actions.
1726 * Pointer to the error structure.
1729 * 0 on success, a negative errno value otherwise and rte_ernno is set.
1732 flow_dv_translate(struct rte_eth_dev *dev,
1733 struct mlx5_flow *dev_flow,
1734 const struct rte_flow_attr *attr,
1735 const struct rte_flow_item items[],
1736 const struct rte_flow_action actions[],
1737 struct rte_flow_error *error)
1739 struct priv *priv = dev->data->dev_private;
1740 struct rte_flow *flow = dev_flow->flow;
1741 uint64_t item_flags = 0;
1742 uint64_t action_flags = 0;
1743 uint64_t priority = attr->priority;
1744 struct mlx5_flow_dv_matcher matcher = {
1746 .size = sizeof(matcher.mask.buf),
1751 if (priority == MLX5_FLOW_PRIO_RSVD)
1752 priority = priv->config.flow_prio - 1;
1753 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
1754 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1755 void *match_mask = matcher.mask.buf;
1756 void *match_value = dev_flow->dv.value.buf;
1758 switch (items->type) {
1759 case RTE_FLOW_ITEM_TYPE_ETH:
1760 flow_dv_translate_item_eth(match_mask, match_value,
1762 matcher.priority = MLX5_PRIORITY_MAP_L2;
1763 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
1764 MLX5_FLOW_LAYER_OUTER_L2;
1766 case RTE_FLOW_ITEM_TYPE_VLAN:
1767 flow_dv_translate_item_vlan(match_mask, match_value,
1769 matcher.priority = MLX5_PRIORITY_MAP_L2;
1770 item_flags |= tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
1771 MLX5_FLOW_LAYER_INNER_VLAN) :
1772 (MLX5_FLOW_LAYER_OUTER_L2 |
1773 MLX5_FLOW_LAYER_OUTER_VLAN);
1775 case RTE_FLOW_ITEM_TYPE_IPV4:
1776 flow_dv_translate_item_ipv4(match_mask, match_value,
1778 matcher.priority = MLX5_PRIORITY_MAP_L3;
1779 dev_flow->dv.hash_fields |=
1780 mlx5_flow_hashfields_adjust
1782 MLX5_IPV4_LAYER_TYPES,
1783 MLX5_IPV4_IBV_RX_HASH);
1784 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
1785 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
1787 case RTE_FLOW_ITEM_TYPE_IPV6:
1788 flow_dv_translate_item_ipv6(match_mask, match_value,
1790 matcher.priority = MLX5_PRIORITY_MAP_L3;
1791 dev_flow->dv.hash_fields |=
1792 mlx5_flow_hashfields_adjust
1794 MLX5_IPV6_LAYER_TYPES,
1795 MLX5_IPV6_IBV_RX_HASH);
1796 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
1797 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
1799 case RTE_FLOW_ITEM_TYPE_TCP:
1800 flow_dv_translate_item_tcp(match_mask, match_value,
1802 matcher.priority = MLX5_PRIORITY_MAP_L4;
1803 dev_flow->dv.hash_fields |=
1804 mlx5_flow_hashfields_adjust
1805 (dev_flow, tunnel, ETH_RSS_TCP,
1806 IBV_RX_HASH_SRC_PORT_TCP |
1807 IBV_RX_HASH_DST_PORT_TCP);
1808 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
1809 MLX5_FLOW_LAYER_OUTER_L4_TCP;
1811 case RTE_FLOW_ITEM_TYPE_UDP:
1812 flow_dv_translate_item_udp(match_mask, match_value,
1814 matcher.priority = MLX5_PRIORITY_MAP_L4;
1815 dev_flow->verbs.hash_fields |=
1816 mlx5_flow_hashfields_adjust
1817 (dev_flow, tunnel, ETH_RSS_UDP,
1818 IBV_RX_HASH_SRC_PORT_UDP |
1819 IBV_RX_HASH_DST_PORT_UDP);
1820 item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
1821 MLX5_FLOW_LAYER_OUTER_L4_UDP;
1823 case RTE_FLOW_ITEM_TYPE_GRE:
1824 flow_dv_translate_item_gre(match_mask, match_value,
1826 item_flags |= MLX5_FLOW_LAYER_GRE;
1828 case RTE_FLOW_ITEM_TYPE_NVGRE:
1829 flow_dv_translate_item_nvgre(match_mask, match_value,
1831 item_flags |= MLX5_FLOW_LAYER_GRE;
1833 case RTE_FLOW_ITEM_TYPE_VXLAN:
1834 flow_dv_translate_item_vxlan(match_mask, match_value,
1836 item_flags |= MLX5_FLOW_LAYER_VXLAN;
1838 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
1839 flow_dv_translate_item_vxlan(match_mask, match_value,
1841 item_flags |= MLX5_FLOW_LAYER_VXLAN_GPE;
1843 case RTE_FLOW_ITEM_TYPE_META:
1844 flow_dv_translate_item_meta(match_mask, match_value,
1846 item_flags |= MLX5_FLOW_ITEM_METADATA;
1852 dev_flow->layers = item_flags;
1853 /* Register matcher. */
1854 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
1856 matcher.priority = mlx5_flow_adjust_priority(dev, priority,
1858 matcher.egress = attr->egress;
1859 if (flow_dv_matcher_register(dev, &matcher, dev_flow, error))
1861 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1862 const struct rte_flow_action_queue *queue;
1863 const struct rte_flow_action_rss *rss;
1864 const struct rte_flow_action *action = actions;
1865 const uint8_t *rss_key;
1867 switch (actions->type) {
1868 case RTE_FLOW_ACTION_TYPE_VOID:
1870 case RTE_FLOW_ACTION_TYPE_FLAG:
1871 dev_flow->dv.actions[actions_n].type =
1872 MLX5DV_FLOW_ACTION_TAG;
1873 dev_flow->dv.actions[actions_n].tag_value =
1874 mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
1876 action_flags |= MLX5_FLOW_ACTION_FLAG;
1878 case RTE_FLOW_ACTION_TYPE_MARK:
1879 dev_flow->dv.actions[actions_n].type =
1880 MLX5DV_FLOW_ACTION_TAG;
1881 dev_flow->dv.actions[actions_n].tag_value =
1883 (((const struct rte_flow_action_mark *)
1884 (actions->conf))->id);
1886 action_flags |= MLX5_FLOW_ACTION_MARK;
1888 case RTE_FLOW_ACTION_TYPE_DROP:
1889 dev_flow->dv.actions[actions_n].type =
1890 MLX5DV_FLOW_ACTION_DROP;
1891 action_flags |= MLX5_FLOW_ACTION_DROP;
1893 case RTE_FLOW_ACTION_TYPE_QUEUE:
1894 queue = actions->conf;
1895 flow->rss.queue_num = 1;
1896 (*flow->queue)[0] = queue->index;
1897 action_flags |= MLX5_FLOW_ACTION_QUEUE;
1899 case RTE_FLOW_ACTION_TYPE_RSS:
1900 rss = actions->conf;
1902 memcpy((*flow->queue), rss->queue,
1903 rss->queue_num * sizeof(uint16_t));
1904 flow->rss.queue_num = rss->queue_num;
1905 /* NULL RSS key indicates default RSS key. */
1906 rss_key = !rss->key ? rss_hash_default_key : rss->key;
1907 memcpy(flow->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
1908 /* RSS type 0 indicates default RSS type ETH_RSS_IP. */
1909 flow->rss.types = !rss->types ? ETH_RSS_IP : rss->types;
1910 flow->rss.level = rss->level;
1911 action_flags |= MLX5_FLOW_ACTION_RSS;
1913 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
1914 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
1915 if (flow_dv_create_action_l2_encap(dev, actions,
1918 dev_flow->dv.actions[actions_n].type =
1919 MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
1920 dev_flow->dv.actions[actions_n].action =
1921 dev_flow->dv.encap_decap->verbs_action;
1923 action_flags |= actions->type ==
1924 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ?
1925 MLX5_FLOW_ACTION_VXLAN_ENCAP :
1926 MLX5_FLOW_ACTION_NVGRE_ENCAP;
1928 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
1929 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
1930 if (flow_dv_create_action_l2_decap(dev, dev_flow,
1933 dev_flow->dv.actions[actions_n].type =
1934 MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
1935 dev_flow->dv.actions[actions_n].action =
1936 dev_flow->dv.encap_decap->verbs_action;
1938 action_flags |= actions->type ==
1939 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP ?
1940 MLX5_FLOW_ACTION_VXLAN_DECAP :
1941 MLX5_FLOW_ACTION_NVGRE_DECAP;
1943 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
1944 /* Handle encap with preceding decap. */
1945 if (action_flags & MLX5_FLOW_ACTION_RAW_DECAP) {
1946 if (flow_dv_create_action_raw_encap
1947 (dev, actions, dev_flow, attr, error))
1949 dev_flow->dv.actions[actions_n].type =
1950 MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
1951 dev_flow->dv.actions[actions_n].action =
1952 dev_flow->dv.encap_decap->verbs_action;
1954 /* Handle encap without preceding decap. */
1955 if (flow_dv_create_action_l2_encap(dev, actions,
1959 dev_flow->dv.actions[actions_n].type =
1960 MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
1961 dev_flow->dv.actions[actions_n].action =
1962 dev_flow->dv.encap_decap->verbs_action;
1965 action_flags |= MLX5_FLOW_ACTION_RAW_ENCAP;
1967 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
1968 /* Check if this decap is followed by encap. */
1969 for (; action->type != RTE_FLOW_ACTION_TYPE_END &&
1970 action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP;
1973 /* Handle decap only if it isn't followed by encap. */
1974 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
1975 if (flow_dv_create_action_l2_decap(dev,
1979 dev_flow->dv.actions[actions_n].type =
1980 MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
1981 dev_flow->dv.actions[actions_n].action =
1982 dev_flow->dv.encap_decap->verbs_action;
1985 /* If decap is followed by encap, handle it at encap. */
1986 action_flags |= MLX5_FLOW_ACTION_RAW_DECAP;
1992 dev_flow->dv.actions_n = actions_n;
1993 flow->actions = action_flags;
1998 * Apply the flow to the NIC.
2001 * Pointer to the Ethernet device structure.
2002 * @param[in, out] flow
2003 * Pointer to flow structure.
2005 * Pointer to error structure.
2008 * 0 on success, a negative errno value otherwise and rte_errno is set.
2011 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
2012 struct rte_flow_error *error)
2014 struct mlx5_flow_dv *dv;
2015 struct mlx5_flow *dev_flow;
2019 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
2022 if (flow->actions & MLX5_FLOW_ACTION_DROP) {
2023 dv->hrxq = mlx5_hrxq_drop_new(dev);
2027 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2028 "cannot get drop hash queue");
2031 dv->actions[n].type = MLX5DV_FLOW_ACTION_DEST_IBV_QP;
2032 dv->actions[n].qp = dv->hrxq->qp;
2034 } else if (flow->actions &
2035 (MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)) {
2036 struct mlx5_hrxq *hrxq;
2037 hrxq = mlx5_hrxq_get(dev, flow->key,
2038 MLX5_RSS_HASH_KEY_LEN,
2041 flow->rss.queue_num);
2043 hrxq = mlx5_hrxq_new
2044 (dev, flow->key, MLX5_RSS_HASH_KEY_LEN,
2045 dv->hash_fields, (*flow->queue),
2046 flow->rss.queue_num,
2047 !!(dev_flow->layers &
2048 MLX5_FLOW_LAYER_TUNNEL));
2052 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2053 "cannot get hash queue");
2057 dv->actions[n].type = MLX5DV_FLOW_ACTION_DEST_IBV_QP;
2058 dv->actions[n].qp = hrxq->qp;
2062 mlx5_glue->dv_create_flow(dv->matcher->matcher_object,
2063 (void *)&dv->value, n,
2066 rte_flow_error_set(error, errno,
2067 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2069 "hardware refuses to create flow");
2075 err = rte_errno; /* Save rte_errno before cleanup. */
2076 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
2077 struct mlx5_flow_dv *dv = &dev_flow->dv;
2079 if (flow->actions & MLX5_FLOW_ACTION_DROP)
2080 mlx5_hrxq_drop_release(dev);
2082 mlx5_hrxq_release(dev, dv->hrxq);
2086 rte_errno = err; /* Restore rte_errno. */
2091 * Release the flow matcher.
2094 * Pointer to Ethernet device.
2096 * Pointer to mlx5_flow.
2099 * 1 while a reference on it exists, 0 when freed.
2102 flow_dv_matcher_release(struct rte_eth_dev *dev,
2103 struct mlx5_flow *flow)
2105 struct mlx5_flow_dv_matcher *matcher = flow->dv.matcher;
2107 assert(matcher->matcher_object);
2108 DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--",
2109 dev->data->port_id, (void *)matcher,
2110 rte_atomic32_read(&matcher->refcnt));
2111 if (rte_atomic32_dec_and_test(&matcher->refcnt)) {
2112 claim_zero(mlx5_glue->dv_destroy_flow_matcher
2113 (matcher->matcher_object));
2114 LIST_REMOVE(matcher, next);
2116 DRV_LOG(DEBUG, "port %u matcher %p: removed",
2117 dev->data->port_id, (void *)matcher);
2124 * Release an encap/decap resource.
2127 * Pointer to mlx5_flow.
2130 * 1 while a reference on it exists, 0 when freed.
2133 flow_dv_encap_decap_resource_release(struct mlx5_flow *flow)
2135 struct mlx5_flow_dv_encap_decap_resource *cache_resource =
2136 flow->dv.encap_decap;
2138 assert(cache_resource->verbs_action);
2139 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d--",
2140 (void *)cache_resource,
2141 rte_atomic32_read(&cache_resource->refcnt));
2142 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
2143 claim_zero(mlx5_glue->destroy_flow_action
2144 (cache_resource->verbs_action));
2145 LIST_REMOVE(cache_resource, next);
2146 rte_free(cache_resource);
2147 DRV_LOG(DEBUG, "encap/decap resource %p: removed",
2148 (void *)cache_resource);
2155 * Remove the flow from the NIC but keeps it in memory.
2158 * Pointer to Ethernet device.
2159 * @param[in, out] flow
2160 * Pointer to flow structure.
2163 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
2165 struct mlx5_flow_dv *dv;
2166 struct mlx5_flow *dev_flow;
2170 LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
2173 claim_zero(mlx5_glue->destroy_flow(dv->flow));
2177 if (flow->actions & MLX5_FLOW_ACTION_DROP)
2178 mlx5_hrxq_drop_release(dev);
2180 mlx5_hrxq_release(dev, dv->hrxq);
2185 flow->counter = NULL;
2189 * Remove the flow from the NIC and the memory.
2192 * Pointer to the Ethernet device structure.
2193 * @param[in, out] flow
2194 * Pointer to flow structure.
2197 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
2199 struct mlx5_flow *dev_flow;
2203 flow_dv_remove(dev, flow);
2204 while (!LIST_EMPTY(&flow->dev_flows)) {
2205 dev_flow = LIST_FIRST(&flow->dev_flows);
2206 LIST_REMOVE(dev_flow, next);
2207 if (dev_flow->dv.matcher)
2208 flow_dv_matcher_release(dev, dev_flow);
2209 if (dev_flow->dv.encap_decap)
2210 flow_dv_encap_decap_resource_release(dev_flow);
2218 * @see rte_flow_query()
2222 flow_dv_query(struct rte_eth_dev *dev __rte_unused,
2223 struct rte_flow *flow __rte_unused,
2224 const struct rte_flow_action *actions __rte_unused,
2225 void *data __rte_unused,
2226 struct rte_flow_error *error __rte_unused)
2228 rte_errno = ENOTSUP;
2233 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
2234 .validate = flow_dv_validate,
2235 .prepare = flow_dv_prepare,
2236 .translate = flow_dv_translate,
2237 .apply = flow_dv_apply,
2238 .remove = flow_dv_remove,
2239 .destroy = flow_dv_destroy,
2240 .query = flow_dv_query,
2243 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */