1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Mellanox Technologies, Ltd
12 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
14 #pragma GCC diagnostic ignored "-Wpedantic"
16 #include <infiniband/verbs.h>
18 #pragma GCC diagnostic error "-Wpedantic"
21 #include <rte_common.h>
22 #include <rte_ether.h>
23 #include <rte_ethdev_driver.h>
25 #include <rte_flow_driver.h>
26 #include <rte_malloc.h>
27 #include <rte_cycles.h>
30 #include <rte_vxlan.h>
33 #include <mlx5_glue.h>
34 #include <mlx5_devx_cmds.h>
37 #include "mlx5_defs.h"
39 #include "mlx5_flow.h"
40 #include "mlx5_rxtx.h"
42 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
44 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
45 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
48 #ifndef HAVE_MLX5DV_DR_ESWITCH
49 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
50 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
54 #ifndef HAVE_MLX5DV_DR
55 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
58 /* VLAN header definitions */
59 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
60 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
61 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
62 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
63 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
78 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
79 struct mlx5_flow_tbl_resource *tbl);
82 * Initialize flow attributes structure according to flow items' types.
84 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
85 * mode. For tunnel mode, the items to be modified are the outermost ones.
88 * Pointer to item specification.
90 * Pointer to flow attributes structure.
92 * Pointer to the sub flow.
93 * @param[in] tunnel_decap
94 * Whether action is after tunnel decapsulation.
97 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
98 struct mlx5_flow *dev_flow, bool tunnel_decap)
100 uint64_t layers = dev_flow->handle->layers;
103 * If layers is already initialized, it means this dev_flow is the
104 * suffix flow, the layers flags is set by the prefix flow. Need to
105 * use the layer flags from prefix flow as the suffix flow may not
106 * have the user defined items as the flow is split.
109 if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
111 else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
113 if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
115 else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
120 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
121 uint8_t next_protocol = 0xff;
122 switch (item->type) {
123 case RTE_FLOW_ITEM_TYPE_GRE:
124 case RTE_FLOW_ITEM_TYPE_NVGRE:
125 case RTE_FLOW_ITEM_TYPE_VXLAN:
126 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
127 case RTE_FLOW_ITEM_TYPE_GENEVE:
128 case RTE_FLOW_ITEM_TYPE_MPLS:
132 case RTE_FLOW_ITEM_TYPE_IPV4:
135 if (item->mask != NULL &&
136 ((const struct rte_flow_item_ipv4 *)
137 item->mask)->hdr.next_proto_id)
139 ((const struct rte_flow_item_ipv4 *)
140 (item->spec))->hdr.next_proto_id &
141 ((const struct rte_flow_item_ipv4 *)
142 (item->mask))->hdr.next_proto_id;
143 if ((next_protocol == IPPROTO_IPIP ||
144 next_protocol == IPPROTO_IPV6) && tunnel_decap)
147 case RTE_FLOW_ITEM_TYPE_IPV6:
150 if (item->mask != NULL &&
151 ((const struct rte_flow_item_ipv6 *)
152 item->mask)->hdr.proto)
154 ((const struct rte_flow_item_ipv6 *)
155 (item->spec))->hdr.proto &
156 ((const struct rte_flow_item_ipv6 *)
157 (item->mask))->hdr.proto;
158 if ((next_protocol == IPPROTO_IPIP ||
159 next_protocol == IPPROTO_IPV6) && tunnel_decap)
162 case RTE_FLOW_ITEM_TYPE_UDP:
166 case RTE_FLOW_ITEM_TYPE_TCP:
178 * Convert rte_mtr_color to mlx5 color.
187 rte_col_2_mlx5_col(enum rte_color rcol)
190 case RTE_COLOR_GREEN:
191 return MLX5_FLOW_COLOR_GREEN;
192 case RTE_COLOR_YELLOW:
193 return MLX5_FLOW_COLOR_YELLOW;
195 return MLX5_FLOW_COLOR_RED;
199 return MLX5_FLOW_COLOR_UNDEFINED;
202 struct field_modify_info {
203 uint32_t size; /* Size of field in protocol header, in bytes. */
204 uint32_t offset; /* Offset of field in protocol header, in bytes. */
205 enum mlx5_modification_field id;
208 struct field_modify_info modify_eth[] = {
209 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
210 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
211 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
212 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
216 struct field_modify_info modify_vlan_out_first_vid[] = {
217 /* Size in bits !!! */
218 {12, 0, MLX5_MODI_OUT_FIRST_VID},
222 struct field_modify_info modify_ipv4[] = {
223 {1, 1, MLX5_MODI_OUT_IP_DSCP},
224 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
225 {4, 12, MLX5_MODI_OUT_SIPV4},
226 {4, 16, MLX5_MODI_OUT_DIPV4},
230 struct field_modify_info modify_ipv6[] = {
231 {1, 0, MLX5_MODI_OUT_IP_DSCP},
232 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
233 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
234 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
235 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
236 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
237 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
238 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
239 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
240 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
244 struct field_modify_info modify_udp[] = {
245 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
246 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
250 struct field_modify_info modify_tcp[] = {
251 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
252 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
253 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
254 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
259 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
260 uint8_t next_protocol, uint64_t *item_flags,
263 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
264 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
265 if (next_protocol == IPPROTO_IPIP) {
266 *item_flags |= MLX5_FLOW_LAYER_IPIP;
269 if (next_protocol == IPPROTO_IPV6) {
270 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
276 * Acquire the synchronizing object to protect multithreaded access
277 * to shared dv context. Lock occurs only if context is actually
278 * shared, i.e. we have multiport IB device and representors are
282 * Pointer to the rte_eth_dev structure.
285 flow_dv_shared_lock(struct rte_eth_dev *dev)
287 struct mlx5_priv *priv = dev->data->dev_private;
288 struct mlx5_ibv_shared *sh = priv->sh;
290 if (sh->dv_refcnt > 1) {
293 ret = pthread_mutex_lock(&sh->dv_mutex);
300 flow_dv_shared_unlock(struct rte_eth_dev *dev)
302 struct mlx5_priv *priv = dev->data->dev_private;
303 struct mlx5_ibv_shared *sh = priv->sh;
305 if (sh->dv_refcnt > 1) {
308 ret = pthread_mutex_unlock(&sh->dv_mutex);
314 /* Update VLAN's VID/PCP based on input rte_flow_action.
317 * Pointer to struct rte_flow_action.
319 * Pointer to struct rte_vlan_hdr.
322 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
323 struct rte_vlan_hdr *vlan)
326 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
328 ((const struct rte_flow_action_of_set_vlan_pcp *)
329 action->conf)->vlan_pcp;
330 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
331 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
332 vlan->vlan_tci |= vlan_tci;
333 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
334 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
335 vlan->vlan_tci |= rte_be_to_cpu_16
336 (((const struct rte_flow_action_of_set_vlan_vid *)
337 action->conf)->vlan_vid);
342 * Fetch 1, 2, 3 or 4 byte field from the byte array
343 * and return as unsigned integer in host-endian format.
346 * Pointer to data array.
348 * Size of field to extract.
351 * converted field in host endian format.
353 static inline uint32_t
354 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
363 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
366 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
367 ret = (ret << 8) | *(data + sizeof(uint16_t));
370 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
381 * Convert modify-header action to DV specification.
383 * Data length of each action is determined by provided field description
384 * and the item mask. Data bit offset and width of each action is determined
385 * by provided item mask.
388 * Pointer to item specification.
390 * Pointer to field modification information.
391 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
392 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
393 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
395 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
396 * Negative offset value sets the same offset as source offset.
397 * size field is ignored, value is taken from source field.
398 * @param[in,out] resource
399 * Pointer to the modify-header resource.
401 * Type of modification.
403 * Pointer to the error structure.
406 * 0 on success, a negative errno value otherwise and rte_errno is set.
409 flow_dv_convert_modify_action(struct rte_flow_item *item,
410 struct field_modify_info *field,
411 struct field_modify_info *dcopy,
412 struct mlx5_flow_dv_modify_hdr_resource *resource,
413 uint32_t type, struct rte_flow_error *error)
415 uint32_t i = resource->actions_num;
416 struct mlx5_modification_cmd *actions = resource->actions;
419 * The item and mask are provided in big-endian format.
420 * The fields should be presented as in big-endian format either.
421 * Mask must be always present, it defines the actual field width.
423 MLX5_ASSERT(item->mask);
424 MLX5_ASSERT(field->size);
431 if (i >= MLX5_MAX_MODIFY_NUM)
432 return rte_flow_error_set(error, EINVAL,
433 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
434 "too many items to modify");
435 /* Fetch variable byte size mask from the array. */
436 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
437 field->offset, field->size);
442 /* Deduce actual data width in bits from mask value. */
443 off_b = rte_bsf32(mask);
444 size_b = sizeof(uint32_t) * CHAR_BIT -
445 off_b - __builtin_clz(mask);
447 size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
448 actions[i] = (struct mlx5_modification_cmd) {
454 /* Convert entire record to expected big-endian format. */
455 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
456 if (type == MLX5_MODIFICATION_TYPE_COPY) {
458 actions[i].dst_field = dcopy->id;
459 actions[i].dst_offset =
460 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
461 /* Convert entire record to big-endian format. */
462 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
464 MLX5_ASSERT(item->spec);
465 data = flow_dv_fetch_field((const uint8_t *)item->spec +
466 field->offset, field->size);
467 /* Shift out the trailing masked bits from data. */
468 data = (data & mask) >> off_b;
469 actions[i].data1 = rte_cpu_to_be_32(data);
473 } while (field->size);
474 if (resource->actions_num == i)
475 return rte_flow_error_set(error, EINVAL,
476 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
477 "invalid modification flow item");
478 resource->actions_num = i;
483 * Convert modify-header set IPv4 address action to DV specification.
485 * @param[in,out] resource
486 * Pointer to the modify-header resource.
488 * Pointer to action specification.
490 * Pointer to the error structure.
493 * 0 on success, a negative errno value otherwise and rte_errno is set.
496 flow_dv_convert_action_modify_ipv4
497 (struct mlx5_flow_dv_modify_hdr_resource *resource,
498 const struct rte_flow_action *action,
499 struct rte_flow_error *error)
501 const struct rte_flow_action_set_ipv4 *conf =
502 (const struct rte_flow_action_set_ipv4 *)(action->conf);
503 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
504 struct rte_flow_item_ipv4 ipv4;
505 struct rte_flow_item_ipv4 ipv4_mask;
507 memset(&ipv4, 0, sizeof(ipv4));
508 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
509 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
510 ipv4.hdr.src_addr = conf->ipv4_addr;
511 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
513 ipv4.hdr.dst_addr = conf->ipv4_addr;
514 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
517 item.mask = &ipv4_mask;
518 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
519 MLX5_MODIFICATION_TYPE_SET, error);
523 * Convert modify-header set IPv6 address action to DV specification.
525 * @param[in,out] resource
526 * Pointer to the modify-header resource.
528 * Pointer to action specification.
530 * Pointer to the error structure.
533 * 0 on success, a negative errno value otherwise and rte_errno is set.
536 flow_dv_convert_action_modify_ipv6
537 (struct mlx5_flow_dv_modify_hdr_resource *resource,
538 const struct rte_flow_action *action,
539 struct rte_flow_error *error)
541 const struct rte_flow_action_set_ipv6 *conf =
542 (const struct rte_flow_action_set_ipv6 *)(action->conf);
543 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
544 struct rte_flow_item_ipv6 ipv6;
545 struct rte_flow_item_ipv6 ipv6_mask;
547 memset(&ipv6, 0, sizeof(ipv6));
548 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
549 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
550 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
551 sizeof(ipv6.hdr.src_addr));
552 memcpy(&ipv6_mask.hdr.src_addr,
553 &rte_flow_item_ipv6_mask.hdr.src_addr,
554 sizeof(ipv6.hdr.src_addr));
556 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
557 sizeof(ipv6.hdr.dst_addr));
558 memcpy(&ipv6_mask.hdr.dst_addr,
559 &rte_flow_item_ipv6_mask.hdr.dst_addr,
560 sizeof(ipv6.hdr.dst_addr));
563 item.mask = &ipv6_mask;
564 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
565 MLX5_MODIFICATION_TYPE_SET, error);
569 * Convert modify-header set MAC address action to DV specification.
571 * @param[in,out] resource
572 * Pointer to the modify-header resource.
574 * Pointer to action specification.
576 * Pointer to the error structure.
579 * 0 on success, a negative errno value otherwise and rte_errno is set.
582 flow_dv_convert_action_modify_mac
583 (struct mlx5_flow_dv_modify_hdr_resource *resource,
584 const struct rte_flow_action *action,
585 struct rte_flow_error *error)
587 const struct rte_flow_action_set_mac *conf =
588 (const struct rte_flow_action_set_mac *)(action->conf);
589 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
590 struct rte_flow_item_eth eth;
591 struct rte_flow_item_eth eth_mask;
593 memset(ð, 0, sizeof(eth));
594 memset(ð_mask, 0, sizeof(eth_mask));
595 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
596 memcpy(ð.src.addr_bytes, &conf->mac_addr,
597 sizeof(eth.src.addr_bytes));
598 memcpy(ð_mask.src.addr_bytes,
599 &rte_flow_item_eth_mask.src.addr_bytes,
600 sizeof(eth_mask.src.addr_bytes));
602 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
603 sizeof(eth.dst.addr_bytes));
604 memcpy(ð_mask.dst.addr_bytes,
605 &rte_flow_item_eth_mask.dst.addr_bytes,
606 sizeof(eth_mask.dst.addr_bytes));
609 item.mask = ð_mask;
610 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
611 MLX5_MODIFICATION_TYPE_SET, error);
615 * Convert modify-header set VLAN VID action to DV specification.
617 * @param[in,out] resource
618 * Pointer to the modify-header resource.
620 * Pointer to action specification.
622 * Pointer to the error structure.
625 * 0 on success, a negative errno value otherwise and rte_errno is set.
628 flow_dv_convert_action_modify_vlan_vid
629 (struct mlx5_flow_dv_modify_hdr_resource *resource,
630 const struct rte_flow_action *action,
631 struct rte_flow_error *error)
633 const struct rte_flow_action_of_set_vlan_vid *conf =
634 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
635 int i = resource->actions_num;
636 struct mlx5_modification_cmd *actions = resource->actions;
637 struct field_modify_info *field = modify_vlan_out_first_vid;
639 if (i >= MLX5_MAX_MODIFY_NUM)
640 return rte_flow_error_set(error, EINVAL,
641 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
642 "too many items to modify");
643 actions[i] = (struct mlx5_modification_cmd) {
644 .action_type = MLX5_MODIFICATION_TYPE_SET,
646 .length = field->size,
647 .offset = field->offset,
649 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
650 actions[i].data1 = conf->vlan_vid;
651 actions[i].data1 = actions[i].data1 << 16;
652 resource->actions_num = ++i;
657 * Convert modify-header set TP action to DV specification.
659 * @param[in,out] resource
660 * Pointer to the modify-header resource.
662 * Pointer to action specification.
664 * Pointer to rte_flow_item objects list.
666 * Pointer to flow attributes structure.
667 * @param[in] dev_flow
668 * Pointer to the sub flow.
669 * @param[in] tunnel_decap
670 * Whether action is after tunnel decapsulation.
672 * Pointer to the error structure.
675 * 0 on success, a negative errno value otherwise and rte_errno is set.
678 flow_dv_convert_action_modify_tp
679 (struct mlx5_flow_dv_modify_hdr_resource *resource,
680 const struct rte_flow_action *action,
681 const struct rte_flow_item *items,
682 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
683 bool tunnel_decap, struct rte_flow_error *error)
685 const struct rte_flow_action_set_tp *conf =
686 (const struct rte_flow_action_set_tp *)(action->conf);
687 struct rte_flow_item item;
688 struct rte_flow_item_udp udp;
689 struct rte_flow_item_udp udp_mask;
690 struct rte_flow_item_tcp tcp;
691 struct rte_flow_item_tcp tcp_mask;
692 struct field_modify_info *field;
695 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
697 memset(&udp, 0, sizeof(udp));
698 memset(&udp_mask, 0, sizeof(udp_mask));
699 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
700 udp.hdr.src_port = conf->port;
701 udp_mask.hdr.src_port =
702 rte_flow_item_udp_mask.hdr.src_port;
704 udp.hdr.dst_port = conf->port;
705 udp_mask.hdr.dst_port =
706 rte_flow_item_udp_mask.hdr.dst_port;
708 item.type = RTE_FLOW_ITEM_TYPE_UDP;
710 item.mask = &udp_mask;
713 MLX5_ASSERT(attr->tcp);
714 memset(&tcp, 0, sizeof(tcp));
715 memset(&tcp_mask, 0, sizeof(tcp_mask));
716 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
717 tcp.hdr.src_port = conf->port;
718 tcp_mask.hdr.src_port =
719 rte_flow_item_tcp_mask.hdr.src_port;
721 tcp.hdr.dst_port = conf->port;
722 tcp_mask.hdr.dst_port =
723 rte_flow_item_tcp_mask.hdr.dst_port;
725 item.type = RTE_FLOW_ITEM_TYPE_TCP;
727 item.mask = &tcp_mask;
730 return flow_dv_convert_modify_action(&item, field, NULL, resource,
731 MLX5_MODIFICATION_TYPE_SET, error);
735 * Convert modify-header set TTL action to DV specification.
737 * @param[in,out] resource
738 * Pointer to the modify-header resource.
740 * Pointer to action specification.
742 * Pointer to rte_flow_item objects list.
744 * Pointer to flow attributes structure.
745 * @param[in] dev_flow
746 * Pointer to the sub flow.
747 * @param[in] tunnel_decap
748 * Whether action is after tunnel decapsulation.
750 * Pointer to the error structure.
753 * 0 on success, a negative errno value otherwise and rte_errno is set.
756 flow_dv_convert_action_modify_ttl
757 (struct mlx5_flow_dv_modify_hdr_resource *resource,
758 const struct rte_flow_action *action,
759 const struct rte_flow_item *items,
760 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
761 bool tunnel_decap, struct rte_flow_error *error)
763 const struct rte_flow_action_set_ttl *conf =
764 (const struct rte_flow_action_set_ttl *)(action->conf);
765 struct rte_flow_item item;
766 struct rte_flow_item_ipv4 ipv4;
767 struct rte_flow_item_ipv4 ipv4_mask;
768 struct rte_flow_item_ipv6 ipv6;
769 struct rte_flow_item_ipv6 ipv6_mask;
770 struct field_modify_info *field;
773 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
775 memset(&ipv4, 0, sizeof(ipv4));
776 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
777 ipv4.hdr.time_to_live = conf->ttl_value;
778 ipv4_mask.hdr.time_to_live = 0xFF;
779 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
781 item.mask = &ipv4_mask;
784 MLX5_ASSERT(attr->ipv6);
785 memset(&ipv6, 0, sizeof(ipv6));
786 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
787 ipv6.hdr.hop_limits = conf->ttl_value;
788 ipv6_mask.hdr.hop_limits = 0xFF;
789 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
791 item.mask = &ipv6_mask;
794 return flow_dv_convert_modify_action(&item, field, NULL, resource,
795 MLX5_MODIFICATION_TYPE_SET, error);
799 * Convert modify-header decrement TTL action to DV specification.
801 * @param[in,out] resource
802 * Pointer to the modify-header resource.
804 * Pointer to action specification.
806 * Pointer to rte_flow_item objects list.
808 * Pointer to flow attributes structure.
809 * @param[in] dev_flow
810 * Pointer to the sub flow.
811 * @param[in] tunnel_decap
812 * Whether action is after tunnel decapsulation.
814 * Pointer to the error structure.
817 * 0 on success, a negative errno value otherwise and rte_errno is set.
820 flow_dv_convert_action_modify_dec_ttl
821 (struct mlx5_flow_dv_modify_hdr_resource *resource,
822 const struct rte_flow_item *items,
823 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
824 bool tunnel_decap, struct rte_flow_error *error)
826 struct rte_flow_item item;
827 struct rte_flow_item_ipv4 ipv4;
828 struct rte_flow_item_ipv4 ipv4_mask;
829 struct rte_flow_item_ipv6 ipv6;
830 struct rte_flow_item_ipv6 ipv6_mask;
831 struct field_modify_info *field;
834 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
836 memset(&ipv4, 0, sizeof(ipv4));
837 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
838 ipv4.hdr.time_to_live = 0xFF;
839 ipv4_mask.hdr.time_to_live = 0xFF;
840 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
842 item.mask = &ipv4_mask;
845 MLX5_ASSERT(attr->ipv6);
846 memset(&ipv6, 0, sizeof(ipv6));
847 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
848 ipv6.hdr.hop_limits = 0xFF;
849 ipv6_mask.hdr.hop_limits = 0xFF;
850 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
852 item.mask = &ipv6_mask;
855 return flow_dv_convert_modify_action(&item, field, NULL, resource,
856 MLX5_MODIFICATION_TYPE_ADD, error);
860 * Convert modify-header increment/decrement TCP Sequence number
861 * to DV specification.
863 * @param[in,out] resource
864 * Pointer to the modify-header resource.
866 * Pointer to action specification.
868 * Pointer to the error structure.
871 * 0 on success, a negative errno value otherwise and rte_errno is set.
874 flow_dv_convert_action_modify_tcp_seq
875 (struct mlx5_flow_dv_modify_hdr_resource *resource,
876 const struct rte_flow_action *action,
877 struct rte_flow_error *error)
879 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
880 uint64_t value = rte_be_to_cpu_32(*conf);
881 struct rte_flow_item item;
882 struct rte_flow_item_tcp tcp;
883 struct rte_flow_item_tcp tcp_mask;
885 memset(&tcp, 0, sizeof(tcp));
886 memset(&tcp_mask, 0, sizeof(tcp_mask));
887 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
889 * The HW has no decrement operation, only increment operation.
890 * To simulate decrement X from Y using increment operation
891 * we need to add UINT32_MAX X times to Y.
892 * Each adding of UINT32_MAX decrements Y by 1.
895 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
896 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
897 item.type = RTE_FLOW_ITEM_TYPE_TCP;
899 item.mask = &tcp_mask;
900 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
901 MLX5_MODIFICATION_TYPE_ADD, error);
905 * Convert modify-header increment/decrement TCP Acknowledgment number
906 * to DV specification.
908 * @param[in,out] resource
909 * Pointer to the modify-header resource.
911 * Pointer to action specification.
913 * Pointer to the error structure.
916 * 0 on success, a negative errno value otherwise and rte_errno is set.
919 flow_dv_convert_action_modify_tcp_ack
920 (struct mlx5_flow_dv_modify_hdr_resource *resource,
921 const struct rte_flow_action *action,
922 struct rte_flow_error *error)
924 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
925 uint64_t value = rte_be_to_cpu_32(*conf);
926 struct rte_flow_item item;
927 struct rte_flow_item_tcp tcp;
928 struct rte_flow_item_tcp tcp_mask;
930 memset(&tcp, 0, sizeof(tcp));
931 memset(&tcp_mask, 0, sizeof(tcp_mask));
932 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
934 * The HW has no decrement operation, only increment operation.
935 * To simulate decrement X from Y using increment operation
936 * we need to add UINT32_MAX X times to Y.
937 * Each adding of UINT32_MAX decrements Y by 1.
940 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
941 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
942 item.type = RTE_FLOW_ITEM_TYPE_TCP;
944 item.mask = &tcp_mask;
945 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
946 MLX5_MODIFICATION_TYPE_ADD, error);
949 static enum mlx5_modification_field reg_to_field[] = {
950 [REG_NONE] = MLX5_MODI_OUT_NONE,
951 [REG_A] = MLX5_MODI_META_DATA_REG_A,
952 [REG_B] = MLX5_MODI_META_DATA_REG_B,
953 [REG_C_0] = MLX5_MODI_META_REG_C_0,
954 [REG_C_1] = MLX5_MODI_META_REG_C_1,
955 [REG_C_2] = MLX5_MODI_META_REG_C_2,
956 [REG_C_3] = MLX5_MODI_META_REG_C_3,
957 [REG_C_4] = MLX5_MODI_META_REG_C_4,
958 [REG_C_5] = MLX5_MODI_META_REG_C_5,
959 [REG_C_6] = MLX5_MODI_META_REG_C_6,
960 [REG_C_7] = MLX5_MODI_META_REG_C_7,
964 * Convert register set to DV specification.
966 * @param[in,out] resource
967 * Pointer to the modify-header resource.
969 * Pointer to action specification.
971 * Pointer to the error structure.
974 * 0 on success, a negative errno value otherwise and rte_errno is set.
977 flow_dv_convert_action_set_reg
978 (struct mlx5_flow_dv_modify_hdr_resource *resource,
979 const struct rte_flow_action *action,
980 struct rte_flow_error *error)
982 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
983 struct mlx5_modification_cmd *actions = resource->actions;
984 uint32_t i = resource->actions_num;
986 if (i >= MLX5_MAX_MODIFY_NUM)
987 return rte_flow_error_set(error, EINVAL,
988 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
989 "too many items to modify");
990 MLX5_ASSERT(conf->id != REG_NONE);
991 MLX5_ASSERT(conf->id < RTE_DIM(reg_to_field));
992 actions[i] = (struct mlx5_modification_cmd) {
993 .action_type = MLX5_MODIFICATION_TYPE_SET,
994 .field = reg_to_field[conf->id],
996 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
997 actions[i].data1 = rte_cpu_to_be_32(conf->data);
999 resource->actions_num = i;
1004 * Convert SET_TAG action to DV specification.
1007 * Pointer to the rte_eth_dev structure.
1008 * @param[in,out] resource
1009 * Pointer to the modify-header resource.
1011 * Pointer to action specification.
1013 * Pointer to the error structure.
1016 * 0 on success, a negative errno value otherwise and rte_errno is set.
1019 flow_dv_convert_action_set_tag
1020 (struct rte_eth_dev *dev,
1021 struct mlx5_flow_dv_modify_hdr_resource *resource,
1022 const struct rte_flow_action_set_tag *conf,
1023 struct rte_flow_error *error)
1025 rte_be32_t data = rte_cpu_to_be_32(conf->data);
1026 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1027 struct rte_flow_item item = {
1031 struct field_modify_info reg_c_x[] = {
1034 enum mlx5_modification_field reg_type;
1037 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1040 MLX5_ASSERT(ret != REG_NONE);
1041 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1042 reg_type = reg_to_field[ret];
1043 MLX5_ASSERT(reg_type > 0);
1044 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1045 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1046 MLX5_MODIFICATION_TYPE_SET, error);
1050 * Convert internal COPY_REG action to DV specification.
1053 * Pointer to the rte_eth_dev structure.
1054 * @param[in,out] res
1055 * Pointer to the modify-header resource.
1057 * Pointer to action specification.
1059 * Pointer to the error structure.
1062 * 0 on success, a negative errno value otherwise and rte_errno is set.
1065 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1066 struct mlx5_flow_dv_modify_hdr_resource *res,
1067 const struct rte_flow_action *action,
1068 struct rte_flow_error *error)
1070 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1071 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1072 struct rte_flow_item item = {
1076 struct field_modify_info reg_src[] = {
1077 {4, 0, reg_to_field[conf->src]},
1080 struct field_modify_info reg_dst = {
1082 .id = reg_to_field[conf->dst],
1084 /* Adjust reg_c[0] usage according to reported mask. */
1085 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1086 struct mlx5_priv *priv = dev->data->dev_private;
1087 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1089 MLX5_ASSERT(reg_c0);
1090 MLX5_ASSERT(priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1091 if (conf->dst == REG_C_0) {
1092 /* Copy to reg_c[0], within mask only. */
1093 reg_dst.offset = rte_bsf32(reg_c0);
1095 * Mask is ignoring the enianness, because
1096 * there is no conversion in datapath.
1098 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1099 /* Copy from destination lower bits to reg_c[0]. */
1100 mask = reg_c0 >> reg_dst.offset;
1102 /* Copy from destination upper bits to reg_c[0]. */
1103 mask = reg_c0 << (sizeof(reg_c0) * CHAR_BIT -
1104 rte_fls_u32(reg_c0));
1107 mask = rte_cpu_to_be_32(reg_c0);
1108 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1109 /* Copy from reg_c[0] to destination lower bits. */
1112 /* Copy from reg_c[0] to destination upper bits. */
1113 reg_dst.offset = sizeof(reg_c0) * CHAR_BIT -
1114 (rte_fls_u32(reg_c0) -
1119 return flow_dv_convert_modify_action(&item,
1120 reg_src, ®_dst, res,
1121 MLX5_MODIFICATION_TYPE_COPY,
1126 * Convert MARK action to DV specification. This routine is used
1127 * in extensive metadata only and requires metadata register to be
1128 * handled. In legacy mode hardware tag resource is engaged.
1131 * Pointer to the rte_eth_dev structure.
1133 * Pointer to MARK action specification.
1134 * @param[in,out] resource
1135 * Pointer to the modify-header resource.
1137 * Pointer to the error structure.
1140 * 0 on success, a negative errno value otherwise and rte_errno is set.
1143 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1144 const struct rte_flow_action_mark *conf,
1145 struct mlx5_flow_dv_modify_hdr_resource *resource,
1146 struct rte_flow_error *error)
1148 struct mlx5_priv *priv = dev->data->dev_private;
1149 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1150 priv->sh->dv_mark_mask);
1151 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1152 struct rte_flow_item item = {
1156 struct field_modify_info reg_c_x[] = {
1157 {4, 0, 0}, /* dynamic instead of MLX5_MODI_META_REG_C_1. */
1163 return rte_flow_error_set(error, EINVAL,
1164 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1165 NULL, "zero mark action mask");
1166 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1169 MLX5_ASSERT(reg > 0);
1170 if (reg == REG_C_0) {
1171 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1172 uint32_t shl_c0 = rte_bsf32(msk_c0);
1174 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1175 mask = rte_cpu_to_be_32(mask) & msk_c0;
1176 mask = rte_cpu_to_be_32(mask << shl_c0);
1178 reg_c_x[0].id = reg_to_field[reg];
1179 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1180 MLX5_MODIFICATION_TYPE_SET, error);
1184 * Get metadata register index for specified steering domain.
1187 * Pointer to the rte_eth_dev structure.
1189 * Attributes of flow to determine steering domain.
1191 * Pointer to the error structure.
1194 * positive index on success, a negative errno value otherwise
1195 * and rte_errno is set.
1197 static enum modify_reg
1198 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1199 const struct rte_flow_attr *attr,
1200 struct rte_flow_error *error)
1203 mlx5_flow_get_reg_id(dev, attr->transfer ?
1207 MLX5_METADATA_RX, 0, error);
1209 return rte_flow_error_set(error,
1210 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1211 NULL, "unavailable "
1212 "metadata register");
1217 * Convert SET_META action to DV specification.
1220 * Pointer to the rte_eth_dev structure.
1221 * @param[in,out] resource
1222 * Pointer to the modify-header resource.
1224 * Attributes of flow that includes this item.
1226 * Pointer to action specification.
1228 * Pointer to the error structure.
1231 * 0 on success, a negative errno value otherwise and rte_errno is set.
1234 flow_dv_convert_action_set_meta
1235 (struct rte_eth_dev *dev,
1236 struct mlx5_flow_dv_modify_hdr_resource *resource,
1237 const struct rte_flow_attr *attr,
1238 const struct rte_flow_action_set_meta *conf,
1239 struct rte_flow_error *error)
1241 uint32_t data = conf->data;
1242 uint32_t mask = conf->mask;
1243 struct rte_flow_item item = {
1247 struct field_modify_info reg_c_x[] = {
1250 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1255 * In datapath code there is no endianness
1256 * coversions for perfromance reasons, all
1257 * pattern conversions are done in rte_flow.
1259 if (reg == REG_C_0) {
1260 struct mlx5_priv *priv = dev->data->dev_private;
1261 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1264 MLX5_ASSERT(msk_c0);
1265 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1266 shl_c0 = rte_bsf32(msk_c0);
1268 shl_c0 = sizeof(msk_c0) * CHAR_BIT - rte_fls_u32(msk_c0);
1272 MLX5_ASSERT(!(~msk_c0 & rte_cpu_to_be_32(mask)));
1274 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1275 /* The routine expects parameters in memory as big-endian ones. */
1276 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1277 MLX5_MODIFICATION_TYPE_SET, error);
1281 * Convert modify-header set IPv4 DSCP action to DV specification.
1283 * @param[in,out] resource
1284 * Pointer to the modify-header resource.
1286 * Pointer to action specification.
1288 * Pointer to the error structure.
1291 * 0 on success, a negative errno value otherwise and rte_errno is set.
1294 flow_dv_convert_action_modify_ipv4_dscp
1295 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1296 const struct rte_flow_action *action,
1297 struct rte_flow_error *error)
1299 const struct rte_flow_action_set_dscp *conf =
1300 (const struct rte_flow_action_set_dscp *)(action->conf);
1301 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1302 struct rte_flow_item_ipv4 ipv4;
1303 struct rte_flow_item_ipv4 ipv4_mask;
1305 memset(&ipv4, 0, sizeof(ipv4));
1306 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1307 ipv4.hdr.type_of_service = conf->dscp;
1308 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1310 item.mask = &ipv4_mask;
1311 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1312 MLX5_MODIFICATION_TYPE_SET, error);
1316 * Convert modify-header set IPv6 DSCP action to DV specification.
1318 * @param[in,out] resource
1319 * Pointer to the modify-header resource.
1321 * Pointer to action specification.
1323 * Pointer to the error structure.
1326 * 0 on success, a negative errno value otherwise and rte_errno is set.
1329 flow_dv_convert_action_modify_ipv6_dscp
1330 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1331 const struct rte_flow_action *action,
1332 struct rte_flow_error *error)
1334 const struct rte_flow_action_set_dscp *conf =
1335 (const struct rte_flow_action_set_dscp *)(action->conf);
1336 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1337 struct rte_flow_item_ipv6 ipv6;
1338 struct rte_flow_item_ipv6 ipv6_mask;
1340 memset(&ipv6, 0, sizeof(ipv6));
1341 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1343 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1344 * rdma-core only accept the DSCP bits byte aligned start from
1345 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1346 * bits in IPv6 case as rdma-core requires byte aligned value.
1348 ipv6.hdr.vtc_flow = conf->dscp;
1349 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1351 item.mask = &ipv6_mask;
1352 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1353 MLX5_MODIFICATION_TYPE_SET, error);
1357 * Validate MARK item.
1360 * Pointer to the rte_eth_dev structure.
1362 * Item specification.
1364 * Attributes of flow that includes this item.
1366 * Pointer to error structure.
1369 * 0 on success, a negative errno value otherwise and rte_errno is set.
1372 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1373 const struct rte_flow_item *item,
1374 const struct rte_flow_attr *attr __rte_unused,
1375 struct rte_flow_error *error)
1377 struct mlx5_priv *priv = dev->data->dev_private;
1378 struct mlx5_dev_config *config = &priv->config;
1379 const struct rte_flow_item_mark *spec = item->spec;
1380 const struct rte_flow_item_mark *mask = item->mask;
1381 const struct rte_flow_item_mark nic_mask = {
1382 .id = priv->sh->dv_mark_mask,
1386 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1387 return rte_flow_error_set(error, ENOTSUP,
1388 RTE_FLOW_ERROR_TYPE_ITEM, item,
1389 "extended metadata feature"
1391 if (!mlx5_flow_ext_mreg_supported(dev))
1392 return rte_flow_error_set(error, ENOTSUP,
1393 RTE_FLOW_ERROR_TYPE_ITEM, item,
1394 "extended metadata register"
1395 " isn't supported");
1397 return rte_flow_error_set(error, ENOTSUP,
1398 RTE_FLOW_ERROR_TYPE_ITEM, item,
1399 "extended metadata register"
1400 " isn't available");
1401 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1405 return rte_flow_error_set(error, EINVAL,
1406 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1408 "data cannot be empty");
1409 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1410 return rte_flow_error_set(error, EINVAL,
1411 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1413 "mark id exceeds the limit");
1417 return rte_flow_error_set(error, EINVAL,
1418 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1419 "mask cannot be zero");
1421 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1422 (const uint8_t *)&nic_mask,
1423 sizeof(struct rte_flow_item_mark),
1431 * Validate META item.
1434 * Pointer to the rte_eth_dev structure.
1436 * Item specification.
1438 * Attributes of flow that includes this item.
1440 * Pointer to error structure.
1443 * 0 on success, a negative errno value otherwise and rte_errno is set.
1446 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1447 const struct rte_flow_item *item,
1448 const struct rte_flow_attr *attr,
1449 struct rte_flow_error *error)
1451 struct mlx5_priv *priv = dev->data->dev_private;
1452 struct mlx5_dev_config *config = &priv->config;
1453 const struct rte_flow_item_meta *spec = item->spec;
1454 const struct rte_flow_item_meta *mask = item->mask;
1455 struct rte_flow_item_meta nic_mask = {
1462 return rte_flow_error_set(error, EINVAL,
1463 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1465 "data cannot be empty");
1466 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1467 if (!mlx5_flow_ext_mreg_supported(dev))
1468 return rte_flow_error_set(error, ENOTSUP,
1469 RTE_FLOW_ERROR_TYPE_ITEM, item,
1470 "extended metadata register"
1471 " isn't supported");
1472 reg = flow_dv_get_metadata_reg(dev, attr, error);
1476 return rte_flow_error_set(error, ENOTSUP,
1477 RTE_FLOW_ERROR_TYPE_ITEM, item,
1481 nic_mask.data = priv->sh->dv_meta_mask;
1484 mask = &rte_flow_item_meta_mask;
1486 return rte_flow_error_set(error, EINVAL,
1487 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1488 "mask cannot be zero");
1490 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1491 (const uint8_t *)&nic_mask,
1492 sizeof(struct rte_flow_item_meta),
1498 * Validate TAG item.
1501 * Pointer to the rte_eth_dev structure.
1503 * Item specification.
1505 * Attributes of flow that includes this item.
1507 * Pointer to error structure.
1510 * 0 on success, a negative errno value otherwise and rte_errno is set.
1513 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
1514 const struct rte_flow_item *item,
1515 const struct rte_flow_attr *attr __rte_unused,
1516 struct rte_flow_error *error)
1518 const struct rte_flow_item_tag *spec = item->spec;
1519 const struct rte_flow_item_tag *mask = item->mask;
1520 const struct rte_flow_item_tag nic_mask = {
1521 .data = RTE_BE32(UINT32_MAX),
1526 if (!mlx5_flow_ext_mreg_supported(dev))
1527 return rte_flow_error_set(error, ENOTSUP,
1528 RTE_FLOW_ERROR_TYPE_ITEM, item,
1529 "extensive metadata register"
1530 " isn't supported");
1532 return rte_flow_error_set(error, EINVAL,
1533 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1535 "data cannot be empty");
1537 mask = &rte_flow_item_tag_mask;
1539 return rte_flow_error_set(error, EINVAL,
1540 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1541 "mask cannot be zero");
1543 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1544 (const uint8_t *)&nic_mask,
1545 sizeof(struct rte_flow_item_tag),
1549 if (mask->index != 0xff)
1550 return rte_flow_error_set(error, EINVAL,
1551 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1552 "partial mask for tag index"
1553 " is not supported");
1554 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
1557 MLX5_ASSERT(ret != REG_NONE);
1562 * Validate vport item.
1565 * Pointer to the rte_eth_dev structure.
1567 * Item specification.
1569 * Attributes of flow that includes this item.
1570 * @param[in] item_flags
1571 * Bit-fields that holds the items detected until now.
1573 * Pointer to error structure.
1576 * 0 on success, a negative errno value otherwise and rte_errno is set.
1579 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
1580 const struct rte_flow_item *item,
1581 const struct rte_flow_attr *attr,
1582 uint64_t item_flags,
1583 struct rte_flow_error *error)
1585 const struct rte_flow_item_port_id *spec = item->spec;
1586 const struct rte_flow_item_port_id *mask = item->mask;
1587 const struct rte_flow_item_port_id switch_mask = {
1590 struct mlx5_priv *esw_priv;
1591 struct mlx5_priv *dev_priv;
1594 if (!attr->transfer)
1595 return rte_flow_error_set(error, EINVAL,
1596 RTE_FLOW_ERROR_TYPE_ITEM,
1598 "match on port id is valid only"
1599 " when transfer flag is enabled");
1600 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
1601 return rte_flow_error_set(error, ENOTSUP,
1602 RTE_FLOW_ERROR_TYPE_ITEM, item,
1603 "multiple source ports are not"
1606 mask = &switch_mask;
1607 if (mask->id != 0xffffffff)
1608 return rte_flow_error_set(error, ENOTSUP,
1609 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
1611 "no support for partial mask on"
1613 ret = mlx5_flow_item_acceptable
1614 (item, (const uint8_t *)mask,
1615 (const uint8_t *)&rte_flow_item_port_id_mask,
1616 sizeof(struct rte_flow_item_port_id),
1622 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
1624 return rte_flow_error_set(error, rte_errno,
1625 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1626 "failed to obtain E-Switch info for"
1628 dev_priv = mlx5_dev_to_eswitch_info(dev);
1630 return rte_flow_error_set(error, rte_errno,
1631 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1633 "failed to obtain E-Switch info");
1634 if (esw_priv->domain_id != dev_priv->domain_id)
1635 return rte_flow_error_set(error, EINVAL,
1636 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1637 "cannot match on a port from a"
1638 " different E-Switch");
1643 * Validate VLAN item.
1646 * Item specification.
1647 * @param[in] item_flags
1648 * Bit-fields that holds the items detected until now.
1650 * Ethernet device flow is being created on.
1652 * Pointer to error structure.
1655 * 0 on success, a negative errno value otherwise and rte_errno is set.
1658 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
1659 uint64_t item_flags,
1660 struct rte_eth_dev *dev,
1661 struct rte_flow_error *error)
1663 const struct rte_flow_item_vlan *mask = item->mask;
1664 const struct rte_flow_item_vlan nic_mask = {
1665 .tci = RTE_BE16(UINT16_MAX),
1666 .inner_type = RTE_BE16(UINT16_MAX),
1668 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1670 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1671 MLX5_FLOW_LAYER_INNER_L4) :
1672 (MLX5_FLOW_LAYER_OUTER_L3 |
1673 MLX5_FLOW_LAYER_OUTER_L4);
1674 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1675 MLX5_FLOW_LAYER_OUTER_VLAN;
1677 if (item_flags & vlanm)
1678 return rte_flow_error_set(error, EINVAL,
1679 RTE_FLOW_ERROR_TYPE_ITEM, item,
1680 "multiple VLAN layers not supported");
1681 else if ((item_flags & l34m) != 0)
1682 return rte_flow_error_set(error, EINVAL,
1683 RTE_FLOW_ERROR_TYPE_ITEM, item,
1684 "VLAN cannot follow L3/L4 layer");
1686 mask = &rte_flow_item_vlan_mask;
1687 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1688 (const uint8_t *)&nic_mask,
1689 sizeof(struct rte_flow_item_vlan),
1693 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1694 struct mlx5_priv *priv = dev->data->dev_private;
1696 if (priv->vmwa_context) {
1698 * Non-NULL context means we have a virtual machine
1699 * and SR-IOV enabled, we have to create VLAN interface
1700 * to make hypervisor to setup E-Switch vport
1701 * context correctly. We avoid creating the multiple
1702 * VLAN interfaces, so we cannot support VLAN tag mask.
1704 return rte_flow_error_set(error, EINVAL,
1705 RTE_FLOW_ERROR_TYPE_ITEM,
1707 "VLAN tag mask is not"
1708 " supported in virtual"
1716 * Validate GTP item.
1719 * Pointer to the rte_eth_dev structure.
1721 * Item specification.
1722 * @param[in] item_flags
1723 * Bit-fields that holds the items detected until now.
1725 * Pointer to error structure.
1728 * 0 on success, a negative errno value otherwise and rte_errno is set.
1731 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
1732 const struct rte_flow_item *item,
1733 uint64_t item_flags,
1734 struct rte_flow_error *error)
1736 struct mlx5_priv *priv = dev->data->dev_private;
1737 const struct rte_flow_item_gtp *mask = item->mask;
1738 const struct rte_flow_item_gtp nic_mask = {
1740 .teid = RTE_BE32(0xffffffff),
1743 if (!priv->config.hca_attr.tunnel_stateless_gtp)
1744 return rte_flow_error_set(error, ENOTSUP,
1745 RTE_FLOW_ERROR_TYPE_ITEM, item,
1746 "GTP support is not enabled");
1747 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1748 return rte_flow_error_set(error, ENOTSUP,
1749 RTE_FLOW_ERROR_TYPE_ITEM, item,
1750 "multiple tunnel layers not"
1752 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1753 return rte_flow_error_set(error, EINVAL,
1754 RTE_FLOW_ERROR_TYPE_ITEM, item,
1755 "no outer UDP layer found");
1757 mask = &rte_flow_item_gtp_mask;
1758 return mlx5_flow_item_acceptable
1759 (item, (const uint8_t *)mask,
1760 (const uint8_t *)&nic_mask,
1761 sizeof(struct rte_flow_item_gtp),
1766 * Validate the pop VLAN action.
1769 * Pointer to the rte_eth_dev structure.
1770 * @param[in] action_flags
1771 * Holds the actions detected until now.
1773 * Pointer to the pop vlan action.
1774 * @param[in] item_flags
1775 * The items found in this flow rule.
1777 * Pointer to flow attributes.
1779 * Pointer to error structure.
1782 * 0 on success, a negative errno value otherwise and rte_errno is set.
1785 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
1786 uint64_t action_flags,
1787 const struct rte_flow_action *action,
1788 uint64_t item_flags,
1789 const struct rte_flow_attr *attr,
1790 struct rte_flow_error *error)
1792 const struct mlx5_priv *priv = dev->data->dev_private;
1796 if (!priv->sh->pop_vlan_action)
1797 return rte_flow_error_set(error, ENOTSUP,
1798 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1800 "pop vlan action is not supported");
1802 return rte_flow_error_set(error, ENOTSUP,
1803 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1805 "pop vlan action not supported for "
1807 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
1808 return rte_flow_error_set(error, ENOTSUP,
1809 RTE_FLOW_ERROR_TYPE_ACTION, action,
1810 "no support for multiple VLAN "
1812 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1813 return rte_flow_error_set(error, ENOTSUP,
1814 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1816 "cannot pop vlan without a "
1817 "match on (outer) vlan in the flow");
1818 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1819 return rte_flow_error_set(error, EINVAL,
1820 RTE_FLOW_ERROR_TYPE_ACTION, action,
1821 "wrong action order, port_id should "
1822 "be after pop VLAN action");
1823 if (!attr->transfer && priv->representor)
1824 return rte_flow_error_set(error, ENOTSUP,
1825 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1826 "pop vlan action for VF representor "
1827 "not supported on NIC table");
1832 * Get VLAN default info from vlan match info.
1835 * the list of item specifications.
1837 * pointer VLAN info to fill to.
1840 * 0 on success, a negative errno value otherwise and rte_errno is set.
1843 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
1844 struct rte_vlan_hdr *vlan)
1846 const struct rte_flow_item_vlan nic_mask = {
1847 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
1848 MLX5DV_FLOW_VLAN_VID_MASK),
1849 .inner_type = RTE_BE16(0xffff),
1854 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
1855 int type = items->type;
1857 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
1858 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
1861 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
1862 const struct rte_flow_item_vlan *vlan_m = items->mask;
1863 const struct rte_flow_item_vlan *vlan_v = items->spec;
1867 /* Only full match values are accepted */
1868 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
1869 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
1870 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
1872 rte_be_to_cpu_16(vlan_v->tci &
1873 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
1875 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
1876 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
1877 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
1879 rte_be_to_cpu_16(vlan_v->tci &
1880 MLX5DV_FLOW_VLAN_VID_MASK_BE);
1882 if (vlan_m->inner_type == nic_mask.inner_type)
1883 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
1884 vlan_m->inner_type);
1889 * Validate the push VLAN action.
1892 * Pointer to the rte_eth_dev structure.
1893 * @param[in] action_flags
1894 * Holds the actions detected until now.
1895 * @param[in] item_flags
1896 * The items found in this flow rule.
1898 * Pointer to the action structure.
1900 * Pointer to flow attributes
1902 * Pointer to error structure.
1905 * 0 on success, a negative errno value otherwise and rte_errno is set.
1908 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
1909 uint64_t action_flags,
1910 const struct rte_flow_item_vlan *vlan_m,
1911 const struct rte_flow_action *action,
1912 const struct rte_flow_attr *attr,
1913 struct rte_flow_error *error)
1915 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
1916 const struct mlx5_priv *priv = dev->data->dev_private;
1918 if (!attr->transfer && attr->ingress)
1919 return rte_flow_error_set(error, ENOTSUP,
1920 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1922 "push VLAN action not supported for "
1924 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
1925 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
1926 return rte_flow_error_set(error, EINVAL,
1927 RTE_FLOW_ERROR_TYPE_ACTION, action,
1928 "invalid vlan ethertype");
1929 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
1930 return rte_flow_error_set(error, ENOTSUP,
1931 RTE_FLOW_ERROR_TYPE_ACTION, action,
1932 "no support for multiple VLAN "
1934 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1935 return rte_flow_error_set(error, EINVAL,
1936 RTE_FLOW_ERROR_TYPE_ACTION, action,
1937 "wrong action order, port_id should "
1938 "be after push VLAN");
1939 if (!attr->transfer && priv->representor)
1940 return rte_flow_error_set(error, ENOTSUP,
1941 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1942 "push vlan action for VF representor "
1943 "not supported on NIC table");
1945 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
1946 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
1947 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
1948 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
1949 !(mlx5_flow_find_action
1950 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
1951 return rte_flow_error_set(error, EINVAL,
1952 RTE_FLOW_ERROR_TYPE_ACTION, action,
1953 "not full match mask on VLAN PCP and "
1954 "there is no of_set_vlan_pcp action, "
1955 "push VLAN action cannot figure out "
1958 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
1959 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
1960 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
1961 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
1962 !(mlx5_flow_find_action
1963 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
1964 return rte_flow_error_set(error, EINVAL,
1965 RTE_FLOW_ERROR_TYPE_ACTION, action,
1966 "not full match mask on VLAN VID and "
1967 "there is no of_set_vlan_vid action, "
1968 "push VLAN action cannot figure out "
1975 * Validate the set VLAN PCP.
1977 * @param[in] action_flags
1978 * Holds the actions detected until now.
1979 * @param[in] actions
1980 * Pointer to the list of actions remaining in the flow rule.
1982 * Pointer to error structure.
1985 * 0 on success, a negative errno value otherwise and rte_errno is set.
1988 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
1989 const struct rte_flow_action actions[],
1990 struct rte_flow_error *error)
1992 const struct rte_flow_action *action = actions;
1993 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
1995 if (conf->vlan_pcp > 7)
1996 return rte_flow_error_set(error, EINVAL,
1997 RTE_FLOW_ERROR_TYPE_ACTION, action,
1998 "VLAN PCP value is too big");
1999 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2000 return rte_flow_error_set(error, ENOTSUP,
2001 RTE_FLOW_ERROR_TYPE_ACTION, action,
2002 "set VLAN PCP action must follow "
2003 "the push VLAN action");
2004 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2005 return rte_flow_error_set(error, ENOTSUP,
2006 RTE_FLOW_ERROR_TYPE_ACTION, action,
2007 "Multiple VLAN PCP modification are "
2009 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2010 return rte_flow_error_set(error, EINVAL,
2011 RTE_FLOW_ERROR_TYPE_ACTION, action,
2012 "wrong action order, port_id should "
2013 "be after set VLAN PCP");
2018 * Validate the set VLAN VID.
2020 * @param[in] item_flags
2021 * Holds the items detected in this rule.
2022 * @param[in] action_flags
2023 * Holds the actions detected until now.
2024 * @param[in] actions
2025 * Pointer to the list of actions remaining in the flow rule.
2027 * Pointer to error structure.
2030 * 0 on success, a negative errno value otherwise and rte_errno is set.
2033 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2034 uint64_t action_flags,
2035 const struct rte_flow_action actions[],
2036 struct rte_flow_error *error)
2038 const struct rte_flow_action *action = actions;
2039 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
2041 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
2042 return rte_flow_error_set(error, EINVAL,
2043 RTE_FLOW_ERROR_TYPE_ACTION, action,
2044 "VLAN VID value is too big");
2045 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
2046 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2047 return rte_flow_error_set(error, ENOTSUP,
2048 RTE_FLOW_ERROR_TYPE_ACTION, action,
2049 "set VLAN VID action must follow push"
2050 " VLAN action or match on VLAN item");
2051 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
2052 return rte_flow_error_set(error, ENOTSUP,
2053 RTE_FLOW_ERROR_TYPE_ACTION, action,
2054 "Multiple VLAN VID modifications are "
2056 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2057 return rte_flow_error_set(error, EINVAL,
2058 RTE_FLOW_ERROR_TYPE_ACTION, action,
2059 "wrong action order, port_id should "
2060 "be after set VLAN VID");
2065 * Validate the FLAG action.
2068 * Pointer to the rte_eth_dev structure.
2069 * @param[in] action_flags
2070 * Holds the actions detected until now.
2072 * Pointer to flow attributes
2074 * Pointer to error structure.
2077 * 0 on success, a negative errno value otherwise and rte_errno is set.
2080 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
2081 uint64_t action_flags,
2082 const struct rte_flow_attr *attr,
2083 struct rte_flow_error *error)
2085 struct mlx5_priv *priv = dev->data->dev_private;
2086 struct mlx5_dev_config *config = &priv->config;
2089 /* Fall back if no extended metadata register support. */
2090 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2091 return mlx5_flow_validate_action_flag(action_flags, attr,
2093 /* Extensive metadata mode requires registers. */
2094 if (!mlx5_flow_ext_mreg_supported(dev))
2095 return rte_flow_error_set(error, ENOTSUP,
2096 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2097 "no metadata registers "
2098 "to support flag action");
2099 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
2100 return rte_flow_error_set(error, ENOTSUP,
2101 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2102 "extended metadata register"
2103 " isn't available");
2104 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2107 MLX5_ASSERT(ret > 0);
2108 if (action_flags & MLX5_FLOW_ACTION_MARK)
2109 return rte_flow_error_set(error, EINVAL,
2110 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2111 "can't mark and flag in same flow");
2112 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2113 return rte_flow_error_set(error, EINVAL,
2114 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2116 " actions in same flow");
2121 * Validate MARK action.
2124 * Pointer to the rte_eth_dev structure.
2126 * Pointer to action.
2127 * @param[in] action_flags
2128 * Holds the actions detected until now.
2130 * Pointer to flow attributes
2132 * Pointer to error structure.
2135 * 0 on success, a negative errno value otherwise and rte_errno is set.
2138 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
2139 const struct rte_flow_action *action,
2140 uint64_t action_flags,
2141 const struct rte_flow_attr *attr,
2142 struct rte_flow_error *error)
2144 struct mlx5_priv *priv = dev->data->dev_private;
2145 struct mlx5_dev_config *config = &priv->config;
2146 const struct rte_flow_action_mark *mark = action->conf;
2149 /* Fall back if no extended metadata register support. */
2150 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2151 return mlx5_flow_validate_action_mark(action, action_flags,
2153 /* Extensive metadata mode requires registers. */
2154 if (!mlx5_flow_ext_mreg_supported(dev))
2155 return rte_flow_error_set(error, ENOTSUP,
2156 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2157 "no metadata registers "
2158 "to support mark action");
2159 if (!priv->sh->dv_mark_mask)
2160 return rte_flow_error_set(error, ENOTSUP,
2161 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2162 "extended metadata register"
2163 " isn't available");
2164 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2167 MLX5_ASSERT(ret > 0);
2169 return rte_flow_error_set(error, EINVAL,
2170 RTE_FLOW_ERROR_TYPE_ACTION, action,
2171 "configuration cannot be null");
2172 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
2173 return rte_flow_error_set(error, EINVAL,
2174 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2176 "mark id exceeds the limit");
2177 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2178 return rte_flow_error_set(error, EINVAL,
2179 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2180 "can't flag and mark in same flow");
2181 if (action_flags & MLX5_FLOW_ACTION_MARK)
2182 return rte_flow_error_set(error, EINVAL,
2183 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2184 "can't have 2 mark actions in same"
2190 * Validate SET_META action.
2193 * Pointer to the rte_eth_dev structure.
2195 * Pointer to the action structure.
2196 * @param[in] action_flags
2197 * Holds the actions detected until now.
2199 * Pointer to flow attributes
2201 * Pointer to error structure.
2204 * 0 on success, a negative errno value otherwise and rte_errno is set.
2207 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
2208 const struct rte_flow_action *action,
2209 uint64_t action_flags __rte_unused,
2210 const struct rte_flow_attr *attr,
2211 struct rte_flow_error *error)
2213 const struct rte_flow_action_set_meta *conf;
2214 uint32_t nic_mask = UINT32_MAX;
2217 if (!mlx5_flow_ext_mreg_supported(dev))
2218 return rte_flow_error_set(error, ENOTSUP,
2219 RTE_FLOW_ERROR_TYPE_ACTION, action,
2220 "extended metadata register"
2221 " isn't supported");
2222 reg = flow_dv_get_metadata_reg(dev, attr, error);
2225 if (reg != REG_A && reg != REG_B) {
2226 struct mlx5_priv *priv = dev->data->dev_private;
2228 nic_mask = priv->sh->dv_meta_mask;
2230 if (!(action->conf))
2231 return rte_flow_error_set(error, EINVAL,
2232 RTE_FLOW_ERROR_TYPE_ACTION, action,
2233 "configuration cannot be null");
2234 conf = (const struct rte_flow_action_set_meta *)action->conf;
2236 return rte_flow_error_set(error, EINVAL,
2237 RTE_FLOW_ERROR_TYPE_ACTION, action,
2238 "zero mask doesn't have any effect");
2239 if (conf->mask & ~nic_mask)
2240 return rte_flow_error_set(error, EINVAL,
2241 RTE_FLOW_ERROR_TYPE_ACTION, action,
2242 "meta data must be within reg C0");
2247 * Validate SET_TAG action.
2250 * Pointer to the rte_eth_dev structure.
2252 * Pointer to the action structure.
2253 * @param[in] action_flags
2254 * Holds the actions detected until now.
2256 * Pointer to flow attributes
2258 * Pointer to error structure.
2261 * 0 on success, a negative errno value otherwise and rte_errno is set.
2264 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
2265 const struct rte_flow_action *action,
2266 uint64_t action_flags,
2267 const struct rte_flow_attr *attr,
2268 struct rte_flow_error *error)
2270 const struct rte_flow_action_set_tag *conf;
2271 const uint64_t terminal_action_flags =
2272 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
2273 MLX5_FLOW_ACTION_RSS;
2276 if (!mlx5_flow_ext_mreg_supported(dev))
2277 return rte_flow_error_set(error, ENOTSUP,
2278 RTE_FLOW_ERROR_TYPE_ACTION, action,
2279 "extensive metadata register"
2280 " isn't supported");
2281 if (!(action->conf))
2282 return rte_flow_error_set(error, EINVAL,
2283 RTE_FLOW_ERROR_TYPE_ACTION, action,
2284 "configuration cannot be null");
2285 conf = (const struct rte_flow_action_set_tag *)action->conf;
2287 return rte_flow_error_set(error, EINVAL,
2288 RTE_FLOW_ERROR_TYPE_ACTION, action,
2289 "zero mask doesn't have any effect");
2290 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
2293 if (!attr->transfer && attr->ingress &&
2294 (action_flags & terminal_action_flags))
2295 return rte_flow_error_set(error, EINVAL,
2296 RTE_FLOW_ERROR_TYPE_ACTION, action,
2297 "set_tag has no effect"
2298 " with terminal actions");
2303 * Validate count action.
2306 * Pointer to rte_eth_dev structure.
2308 * Pointer to error structure.
2311 * 0 on success, a negative errno value otherwise and rte_errno is set.
2314 flow_dv_validate_action_count(struct rte_eth_dev *dev,
2315 struct rte_flow_error *error)
2317 struct mlx5_priv *priv = dev->data->dev_private;
2319 if (!priv->config.devx)
2321 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
2325 return rte_flow_error_set
2327 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2329 "count action not supported");
2333 * Validate the L2 encap action.
2336 * Pointer to the rte_eth_dev structure.
2337 * @param[in] action_flags
2338 * Holds the actions detected until now.
2340 * Pointer to the action structure.
2342 * Pointer to flow attributes.
2344 * Pointer to error structure.
2347 * 0 on success, a negative errno value otherwise and rte_errno is set.
2350 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
2351 uint64_t action_flags,
2352 const struct rte_flow_action *action,
2353 const struct rte_flow_attr *attr,
2354 struct rte_flow_error *error)
2356 const struct mlx5_priv *priv = dev->data->dev_private;
2358 if (!(action->conf))
2359 return rte_flow_error_set(error, EINVAL,
2360 RTE_FLOW_ERROR_TYPE_ACTION, action,
2361 "configuration cannot be null");
2362 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
2363 return rte_flow_error_set(error, EINVAL,
2364 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2365 "can only have a single encap action "
2367 if (!attr->transfer && priv->representor)
2368 return rte_flow_error_set(error, ENOTSUP,
2369 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2370 "encap action for VF representor "
2371 "not supported on NIC table");
2376 * Validate a decap action.
2379 * Pointer to the rte_eth_dev structure.
2380 * @param[in] action_flags
2381 * Holds the actions detected until now.
2383 * Pointer to flow attributes
2385 * Pointer to error structure.
2388 * 0 on success, a negative errno value otherwise and rte_errno is set.
2391 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
2392 uint64_t action_flags,
2393 const struct rte_flow_attr *attr,
2394 struct rte_flow_error *error)
2396 const struct mlx5_priv *priv = dev->data->dev_private;
2398 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
2399 return rte_flow_error_set(error, ENOTSUP,
2400 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2402 MLX5_FLOW_ACTION_DECAP ? "can only "
2403 "have a single decap action" : "decap "
2404 "after encap is not supported");
2405 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
2406 return rte_flow_error_set(error, EINVAL,
2407 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2408 "can't have decap action after"
2411 return rte_flow_error_set(error, ENOTSUP,
2412 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2414 "decap action not supported for "
2416 if (!attr->transfer && priv->representor)
2417 return rte_flow_error_set(error, ENOTSUP,
2418 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2419 "decap action for VF representor "
2420 "not supported on NIC table");
2424 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
2427 * Validate the raw encap and decap actions.
2430 * Pointer to the rte_eth_dev structure.
2432 * Pointer to the decap action.
2434 * Pointer to the encap action.
2436 * Pointer to flow attributes
2437 * @param[in/out] action_flags
2438 * Holds the actions detected until now.
2439 * @param[out] actions_n
2440 * pointer to the number of actions counter.
2442 * Pointer to error structure.
2445 * 0 on success, a negative errno value otherwise and rte_errno is set.
2448 flow_dv_validate_action_raw_encap_decap
2449 (struct rte_eth_dev *dev,
2450 const struct rte_flow_action_raw_decap *decap,
2451 const struct rte_flow_action_raw_encap *encap,
2452 const struct rte_flow_attr *attr, uint64_t *action_flags,
2453 int *actions_n, struct rte_flow_error *error)
2455 const struct mlx5_priv *priv = dev->data->dev_private;
2458 if (encap && (!encap->size || !encap->data))
2459 return rte_flow_error_set(error, EINVAL,
2460 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2461 "raw encap data cannot be empty");
2462 if (decap && encap) {
2463 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
2464 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
2467 else if (encap->size <=
2468 MLX5_ENCAPSULATION_DECISION_SIZE &&
2470 MLX5_ENCAPSULATION_DECISION_SIZE)
2473 else if (encap->size >
2474 MLX5_ENCAPSULATION_DECISION_SIZE &&
2476 MLX5_ENCAPSULATION_DECISION_SIZE)
2477 /* 2 L2 actions: encap and decap. */
2480 return rte_flow_error_set(error,
2482 RTE_FLOW_ERROR_TYPE_ACTION,
2483 NULL, "unsupported too small "
2484 "raw decap and too small raw "
2485 "encap combination");
2488 ret = flow_dv_validate_action_decap(dev, *action_flags, attr,
2492 *action_flags |= MLX5_FLOW_ACTION_DECAP;
2496 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
2497 return rte_flow_error_set(error, ENOTSUP,
2498 RTE_FLOW_ERROR_TYPE_ACTION,
2500 "small raw encap size");
2501 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
2502 return rte_flow_error_set(error, EINVAL,
2503 RTE_FLOW_ERROR_TYPE_ACTION,
2505 "more than one encap action");
2506 if (!attr->transfer && priv->representor)
2507 return rte_flow_error_set
2509 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2510 "encap action for VF representor "
2511 "not supported on NIC table");
2512 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
2519 * Find existing encap/decap resource or create and register a new one.
2521 * @param[in, out] dev
2522 * Pointer to rte_eth_dev structure.
2523 * @param[in, out] resource
2524 * Pointer to encap/decap resource.
2525 * @parm[in, out] dev_flow
2526 * Pointer to the dev_flow.
2528 * pointer to error structure.
2531 * 0 on success otherwise -errno and errno is set.
2534 flow_dv_encap_decap_resource_register
2535 (struct rte_eth_dev *dev,
2536 struct mlx5_flow_dv_encap_decap_resource *resource,
2537 struct mlx5_flow *dev_flow,
2538 struct rte_flow_error *error)
2540 struct mlx5_priv *priv = dev->data->dev_private;
2541 struct mlx5_ibv_shared *sh = priv->sh;
2542 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
2543 struct mlx5dv_dr_domain *domain;
2546 resource->flags = dev_flow->dv.group ? 0 : 1;
2547 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2548 domain = sh->fdb_domain;
2549 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2550 domain = sh->rx_domain;
2552 domain = sh->tx_domain;
2553 /* Lookup a matching resource from cache. */
2554 ILIST_FOREACH(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], sh->encaps_decaps, idx,
2555 cache_resource, next) {
2556 if (resource->reformat_type == cache_resource->reformat_type &&
2557 resource->ft_type == cache_resource->ft_type &&
2558 resource->flags == cache_resource->flags &&
2559 resource->size == cache_resource->size &&
2560 !memcmp((const void *)resource->buf,
2561 (const void *)cache_resource->buf,
2563 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d++",
2564 (void *)cache_resource,
2565 rte_atomic32_read(&cache_resource->refcnt));
2566 rte_atomic32_inc(&cache_resource->refcnt);
2567 dev_flow->handle->dvh.rix_encap_decap = idx;
2568 dev_flow->dv.encap_decap = cache_resource;
2572 /* Register new encap/decap resource. */
2573 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
2574 &dev_flow->handle->dvh.rix_encap_decap);
2575 if (!cache_resource)
2576 return rte_flow_error_set(error, ENOMEM,
2577 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2578 "cannot allocate resource memory");
2579 *cache_resource = *resource;
2580 cache_resource->verbs_action =
2581 mlx5_glue->dv_create_flow_action_packet_reformat
2582 (sh->ctx, cache_resource->reformat_type,
2583 cache_resource->ft_type, domain, cache_resource->flags,
2584 cache_resource->size,
2585 (cache_resource->size ? cache_resource->buf : NULL));
2586 if (!cache_resource->verbs_action) {
2587 rte_free(cache_resource);
2588 return rte_flow_error_set(error, ENOMEM,
2589 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2590 NULL, "cannot create action");
2592 rte_atomic32_init(&cache_resource->refcnt);
2593 rte_atomic32_inc(&cache_resource->refcnt);
2594 ILIST_INSERT(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &sh->encaps_decaps,
2595 dev_flow->handle->dvh.rix_encap_decap, cache_resource,
2597 dev_flow->dv.encap_decap = cache_resource;
2598 DRV_LOG(DEBUG, "new encap/decap resource %p: refcnt %d++",
2599 (void *)cache_resource,
2600 rte_atomic32_read(&cache_resource->refcnt));
2605 * Find existing table jump resource or create and register a new one.
2607 * @param[in, out] dev
2608 * Pointer to rte_eth_dev structure.
2609 * @param[in, out] tbl
2610 * Pointer to flow table resource.
2611 * @parm[in, out] dev_flow
2612 * Pointer to the dev_flow.
2614 * pointer to error structure.
2617 * 0 on success otherwise -errno and errno is set.
2620 flow_dv_jump_tbl_resource_register
2621 (struct rte_eth_dev *dev __rte_unused,
2622 struct mlx5_flow_tbl_resource *tbl,
2623 struct mlx5_flow *dev_flow,
2624 struct rte_flow_error *error)
2626 struct mlx5_flow_tbl_data_entry *tbl_data =
2627 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
2631 cnt = rte_atomic32_read(&tbl_data->jump.refcnt);
2633 tbl_data->jump.action =
2634 mlx5_glue->dr_create_flow_action_dest_flow_tbl
2636 if (!tbl_data->jump.action)
2637 return rte_flow_error_set(error, ENOMEM,
2638 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2639 NULL, "cannot create jump action");
2640 DRV_LOG(DEBUG, "new jump table resource %p: refcnt %d++",
2641 (void *)&tbl_data->jump, cnt);
2643 /* old jump should not make the table ref++. */
2644 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
2645 MLX5_ASSERT(tbl_data->jump.action);
2646 DRV_LOG(DEBUG, "existed jump table resource %p: refcnt %d++",
2647 (void *)&tbl_data->jump, cnt);
2649 rte_atomic32_inc(&tbl_data->jump.refcnt);
2650 dev_flow->handle->rix_jump = tbl_data->idx;
2651 dev_flow->dv.jump = &tbl_data->jump;
2656 * Find existing table port ID resource or create and register a new one.
2658 * @param[in, out] dev
2659 * Pointer to rte_eth_dev structure.
2660 * @param[in, out] resource
2661 * Pointer to port ID action resource.
2662 * @parm[in, out] dev_flow
2663 * Pointer to the dev_flow.
2665 * pointer to error structure.
2668 * 0 on success otherwise -errno and errno is set.
2671 flow_dv_port_id_action_resource_register
2672 (struct rte_eth_dev *dev,
2673 struct mlx5_flow_dv_port_id_action_resource *resource,
2674 struct mlx5_flow *dev_flow,
2675 struct rte_flow_error *error)
2677 struct mlx5_priv *priv = dev->data->dev_private;
2678 struct mlx5_ibv_shared *sh = priv->sh;
2679 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
2682 /* Lookup a matching resource from cache. */
2683 ILIST_FOREACH(sh->ipool[MLX5_IPOOL_PORT_ID], sh->port_id_action_list,
2684 idx, cache_resource, next) {
2685 if (resource->port_id == cache_resource->port_id) {
2686 DRV_LOG(DEBUG, "port id action resource resource %p: "
2688 (void *)cache_resource,
2689 rte_atomic32_read(&cache_resource->refcnt));
2690 rte_atomic32_inc(&cache_resource->refcnt);
2691 dev_flow->handle->rix_port_id_action = idx;
2692 dev_flow->dv.port_id_action = cache_resource;
2696 /* Register new port id action resource. */
2697 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID],
2698 &dev_flow->handle->rix_port_id_action);
2699 if (!cache_resource)
2700 return rte_flow_error_set(error, ENOMEM,
2701 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2702 "cannot allocate resource memory");
2703 *cache_resource = *resource;
2705 * Depending on rdma_core version the glue routine calls
2706 * either mlx5dv_dr_action_create_dest_ib_port(domain, ibv_port)
2707 * or mlx5dv_dr_action_create_dest_vport(domain, vport_id).
2709 cache_resource->action =
2710 mlx5_glue->dr_create_flow_action_dest_port
2711 (priv->sh->fdb_domain, resource->port_id);
2712 if (!cache_resource->action) {
2713 rte_free(cache_resource);
2714 return rte_flow_error_set(error, ENOMEM,
2715 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2716 NULL, "cannot create action");
2718 rte_atomic32_init(&cache_resource->refcnt);
2719 rte_atomic32_inc(&cache_resource->refcnt);
2720 ILIST_INSERT(sh->ipool[MLX5_IPOOL_PORT_ID], &sh->port_id_action_list,
2721 dev_flow->handle->rix_port_id_action, cache_resource,
2723 dev_flow->dv.port_id_action = cache_resource;
2724 DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++",
2725 (void *)cache_resource,
2726 rte_atomic32_read(&cache_resource->refcnt));
2731 * Find existing push vlan resource or create and register a new one.
2733 * @param [in, out] dev
2734 * Pointer to rte_eth_dev structure.
2735 * @param[in, out] resource
2736 * Pointer to port ID action resource.
2737 * @parm[in, out] dev_flow
2738 * Pointer to the dev_flow.
2740 * pointer to error structure.
2743 * 0 on success otherwise -errno and errno is set.
2746 flow_dv_push_vlan_action_resource_register
2747 (struct rte_eth_dev *dev,
2748 struct mlx5_flow_dv_push_vlan_action_resource *resource,
2749 struct mlx5_flow *dev_flow,
2750 struct rte_flow_error *error)
2752 struct mlx5_priv *priv = dev->data->dev_private;
2753 struct mlx5_ibv_shared *sh = priv->sh;
2754 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
2755 struct mlx5dv_dr_domain *domain;
2758 /* Lookup a matching resource from cache. */
2759 ILIST_FOREACH(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2760 sh->push_vlan_action_list, idx, cache_resource, next) {
2761 if (resource->vlan_tag == cache_resource->vlan_tag &&
2762 resource->ft_type == cache_resource->ft_type) {
2763 DRV_LOG(DEBUG, "push-VLAN action resource resource %p: "
2765 (void *)cache_resource,
2766 rte_atomic32_read(&cache_resource->refcnt));
2767 rte_atomic32_inc(&cache_resource->refcnt);
2768 dev_flow->handle->dvh.rix_push_vlan = idx;
2769 dev_flow->dv.push_vlan_res = cache_resource;
2773 /* Register new push_vlan action resource. */
2774 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2775 &dev_flow->handle->dvh.rix_push_vlan);
2776 if (!cache_resource)
2777 return rte_flow_error_set(error, ENOMEM,
2778 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2779 "cannot allocate resource memory");
2780 *cache_resource = *resource;
2781 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2782 domain = sh->fdb_domain;
2783 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2784 domain = sh->rx_domain;
2786 domain = sh->tx_domain;
2787 cache_resource->action =
2788 mlx5_glue->dr_create_flow_action_push_vlan(domain,
2789 resource->vlan_tag);
2790 if (!cache_resource->action) {
2791 rte_free(cache_resource);
2792 return rte_flow_error_set(error, ENOMEM,
2793 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2794 NULL, "cannot create action");
2796 rte_atomic32_init(&cache_resource->refcnt);
2797 rte_atomic32_inc(&cache_resource->refcnt);
2798 ILIST_INSERT(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2799 &sh->push_vlan_action_list,
2800 dev_flow->handle->dvh.rix_push_vlan,
2801 cache_resource, next);
2802 dev_flow->dv.push_vlan_res = cache_resource;
2803 DRV_LOG(DEBUG, "new push vlan action resource %p: refcnt %d++",
2804 (void *)cache_resource,
2805 rte_atomic32_read(&cache_resource->refcnt));
2809 * Get the size of specific rte_flow_item_type
2811 * @param[in] item_type
2812 * Tested rte_flow_item_type.
2815 * sizeof struct item_type, 0 if void or irrelevant.
2818 flow_dv_get_item_len(const enum rte_flow_item_type item_type)
2822 switch (item_type) {
2823 case RTE_FLOW_ITEM_TYPE_ETH:
2824 retval = sizeof(struct rte_flow_item_eth);
2826 case RTE_FLOW_ITEM_TYPE_VLAN:
2827 retval = sizeof(struct rte_flow_item_vlan);
2829 case RTE_FLOW_ITEM_TYPE_IPV4:
2830 retval = sizeof(struct rte_flow_item_ipv4);
2832 case RTE_FLOW_ITEM_TYPE_IPV6:
2833 retval = sizeof(struct rte_flow_item_ipv6);
2835 case RTE_FLOW_ITEM_TYPE_UDP:
2836 retval = sizeof(struct rte_flow_item_udp);
2838 case RTE_FLOW_ITEM_TYPE_TCP:
2839 retval = sizeof(struct rte_flow_item_tcp);
2841 case RTE_FLOW_ITEM_TYPE_VXLAN:
2842 retval = sizeof(struct rte_flow_item_vxlan);
2844 case RTE_FLOW_ITEM_TYPE_GRE:
2845 retval = sizeof(struct rte_flow_item_gre);
2847 case RTE_FLOW_ITEM_TYPE_NVGRE:
2848 retval = sizeof(struct rte_flow_item_nvgre);
2850 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
2851 retval = sizeof(struct rte_flow_item_vxlan_gpe);
2853 case RTE_FLOW_ITEM_TYPE_MPLS:
2854 retval = sizeof(struct rte_flow_item_mpls);
2856 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
2864 #define MLX5_ENCAP_IPV4_VERSION 0x40
2865 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
2866 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
2867 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
2868 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
2869 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
2870 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
2873 * Convert the encap action data from list of rte_flow_item to raw buffer
2876 * Pointer to rte_flow_item objects list.
2878 * Pointer to the output buffer.
2880 * Pointer to the output buffer size.
2882 * Pointer to the error structure.
2885 * 0 on success, a negative errno value otherwise and rte_errno is set.
2888 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
2889 size_t *size, struct rte_flow_error *error)
2891 struct rte_ether_hdr *eth = NULL;
2892 struct rte_vlan_hdr *vlan = NULL;
2893 struct rte_ipv4_hdr *ipv4 = NULL;
2894 struct rte_ipv6_hdr *ipv6 = NULL;
2895 struct rte_udp_hdr *udp = NULL;
2896 struct rte_vxlan_hdr *vxlan = NULL;
2897 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
2898 struct rte_gre_hdr *gre = NULL;
2900 size_t temp_size = 0;
2903 return rte_flow_error_set(error, EINVAL,
2904 RTE_FLOW_ERROR_TYPE_ACTION,
2905 NULL, "invalid empty data");
2906 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2907 len = flow_dv_get_item_len(items->type);
2908 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
2909 return rte_flow_error_set(error, EINVAL,
2910 RTE_FLOW_ERROR_TYPE_ACTION,
2911 (void *)items->type,
2912 "items total size is too big"
2913 " for encap action");
2914 rte_memcpy((void *)&buf[temp_size], items->spec, len);
2915 switch (items->type) {
2916 case RTE_FLOW_ITEM_TYPE_ETH:
2917 eth = (struct rte_ether_hdr *)&buf[temp_size];
2919 case RTE_FLOW_ITEM_TYPE_VLAN:
2920 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
2922 return rte_flow_error_set(error, EINVAL,
2923 RTE_FLOW_ERROR_TYPE_ACTION,
2924 (void *)items->type,
2925 "eth header not found");
2926 if (!eth->ether_type)
2927 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
2929 case RTE_FLOW_ITEM_TYPE_IPV4:
2930 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
2932 return rte_flow_error_set(error, EINVAL,
2933 RTE_FLOW_ERROR_TYPE_ACTION,
2934 (void *)items->type,
2935 "neither eth nor vlan"
2937 if (vlan && !vlan->eth_proto)
2938 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
2939 else if (eth && !eth->ether_type)
2940 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
2941 if (!ipv4->version_ihl)
2942 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
2943 MLX5_ENCAP_IPV4_IHL_MIN;
2944 if (!ipv4->time_to_live)
2945 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
2947 case RTE_FLOW_ITEM_TYPE_IPV6:
2948 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
2950 return rte_flow_error_set(error, EINVAL,
2951 RTE_FLOW_ERROR_TYPE_ACTION,
2952 (void *)items->type,
2953 "neither eth nor vlan"
2955 if (vlan && !vlan->eth_proto)
2956 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
2957 else if (eth && !eth->ether_type)
2958 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
2959 if (!ipv6->vtc_flow)
2961 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
2962 if (!ipv6->hop_limits)
2963 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
2965 case RTE_FLOW_ITEM_TYPE_UDP:
2966 udp = (struct rte_udp_hdr *)&buf[temp_size];
2968 return rte_flow_error_set(error, EINVAL,
2969 RTE_FLOW_ERROR_TYPE_ACTION,
2970 (void *)items->type,
2971 "ip header not found");
2972 if (ipv4 && !ipv4->next_proto_id)
2973 ipv4->next_proto_id = IPPROTO_UDP;
2974 else if (ipv6 && !ipv6->proto)
2975 ipv6->proto = IPPROTO_UDP;
2977 case RTE_FLOW_ITEM_TYPE_VXLAN:
2978 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
2980 return rte_flow_error_set(error, EINVAL,
2981 RTE_FLOW_ERROR_TYPE_ACTION,
2982 (void *)items->type,
2983 "udp header not found");
2985 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
2986 if (!vxlan->vx_flags)
2988 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
2990 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
2991 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
2993 return rte_flow_error_set(error, EINVAL,
2994 RTE_FLOW_ERROR_TYPE_ACTION,
2995 (void *)items->type,
2996 "udp header not found");
2997 if (!vxlan_gpe->proto)
2998 return rte_flow_error_set(error, EINVAL,
2999 RTE_FLOW_ERROR_TYPE_ACTION,
3000 (void *)items->type,
3001 "next protocol not found");
3004 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
3005 if (!vxlan_gpe->vx_flags)
3006 vxlan_gpe->vx_flags =
3007 MLX5_ENCAP_VXLAN_GPE_FLAGS;
3009 case RTE_FLOW_ITEM_TYPE_GRE:
3010 case RTE_FLOW_ITEM_TYPE_NVGRE:
3011 gre = (struct rte_gre_hdr *)&buf[temp_size];
3013 return rte_flow_error_set(error, EINVAL,
3014 RTE_FLOW_ERROR_TYPE_ACTION,
3015 (void *)items->type,
3016 "next protocol not found");
3018 return rte_flow_error_set(error, EINVAL,
3019 RTE_FLOW_ERROR_TYPE_ACTION,
3020 (void *)items->type,
3021 "ip header not found");
3022 if (ipv4 && !ipv4->next_proto_id)
3023 ipv4->next_proto_id = IPPROTO_GRE;
3024 else if (ipv6 && !ipv6->proto)
3025 ipv6->proto = IPPROTO_GRE;
3027 case RTE_FLOW_ITEM_TYPE_VOID:
3030 return rte_flow_error_set(error, EINVAL,
3031 RTE_FLOW_ERROR_TYPE_ACTION,
3032 (void *)items->type,
3033 "unsupported item type");
3043 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
3045 struct rte_ether_hdr *eth = NULL;
3046 struct rte_vlan_hdr *vlan = NULL;
3047 struct rte_ipv6_hdr *ipv6 = NULL;
3048 struct rte_udp_hdr *udp = NULL;
3052 eth = (struct rte_ether_hdr *)data;
3053 next_hdr = (char *)(eth + 1);
3054 proto = RTE_BE16(eth->ether_type);
3057 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
3058 vlan = (struct rte_vlan_hdr *)next_hdr;
3059 proto = RTE_BE16(vlan->eth_proto);
3060 next_hdr += sizeof(struct rte_vlan_hdr);
3063 /* HW calculates IPv4 csum. no need to proceed */
3064 if (proto == RTE_ETHER_TYPE_IPV4)
3067 /* non IPv4/IPv6 header. not supported */
3068 if (proto != RTE_ETHER_TYPE_IPV6) {
3069 return rte_flow_error_set(error, ENOTSUP,
3070 RTE_FLOW_ERROR_TYPE_ACTION,
3071 NULL, "Cannot offload non IPv4/IPv6");
3074 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
3076 /* ignore non UDP */
3077 if (ipv6->proto != IPPROTO_UDP)
3080 udp = (struct rte_udp_hdr *)(ipv6 + 1);
3081 udp->dgram_cksum = 0;
3087 * Convert L2 encap action to DV specification.
3090 * Pointer to rte_eth_dev structure.
3092 * Pointer to action structure.
3093 * @param[in, out] dev_flow
3094 * Pointer to the mlx5_flow.
3095 * @param[in] transfer
3096 * Mark if the flow is E-Switch flow.
3098 * Pointer to the error structure.
3101 * 0 on success, a negative errno value otherwise and rte_errno is set.
3104 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
3105 const struct rte_flow_action *action,
3106 struct mlx5_flow *dev_flow,
3108 struct rte_flow_error *error)
3110 const struct rte_flow_item *encap_data;
3111 const struct rte_flow_action_raw_encap *raw_encap_data;
3112 struct mlx5_flow_dv_encap_decap_resource res = {
3114 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
3115 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
3116 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
3119 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
3121 (const struct rte_flow_action_raw_encap *)action->conf;
3122 res.size = raw_encap_data->size;
3123 memcpy(res.buf, raw_encap_data->data, res.size);
3125 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
3127 ((const struct rte_flow_action_vxlan_encap *)
3128 action->conf)->definition;
3131 ((const struct rte_flow_action_nvgre_encap *)
3132 action->conf)->definition;
3133 if (flow_dv_convert_encap_data(encap_data, res.buf,
3137 if (flow_dv_zero_encap_udp_csum(res.buf, error))
3139 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3140 return rte_flow_error_set(error, EINVAL,
3141 RTE_FLOW_ERROR_TYPE_ACTION,
3142 NULL, "can't create L2 encap action");
3147 * Convert L2 decap action to DV specification.
3150 * Pointer to rte_eth_dev structure.
3151 * @param[in, out] dev_flow
3152 * Pointer to the mlx5_flow.
3153 * @param[in] transfer
3154 * Mark if the flow is E-Switch flow.
3156 * Pointer to the error structure.
3159 * 0 on success, a negative errno value otherwise and rte_errno is set.
3162 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
3163 struct mlx5_flow *dev_flow,
3165 struct rte_flow_error *error)
3167 struct mlx5_flow_dv_encap_decap_resource res = {
3170 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
3171 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
3172 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
3175 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3176 return rte_flow_error_set(error, EINVAL,
3177 RTE_FLOW_ERROR_TYPE_ACTION,
3178 NULL, "can't create L2 decap action");
3183 * Convert raw decap/encap (L3 tunnel) action to DV specification.
3186 * Pointer to rte_eth_dev structure.
3188 * Pointer to action structure.
3189 * @param[in, out] dev_flow
3190 * Pointer to the mlx5_flow.
3192 * Pointer to the flow attributes.
3194 * Pointer to the error structure.
3197 * 0 on success, a negative errno value otherwise and rte_errno is set.
3200 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
3201 const struct rte_flow_action *action,
3202 struct mlx5_flow *dev_flow,
3203 const struct rte_flow_attr *attr,
3204 struct rte_flow_error *error)
3206 const struct rte_flow_action_raw_encap *encap_data;
3207 struct mlx5_flow_dv_encap_decap_resource res;
3209 memset(&res, 0, sizeof(res));
3210 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
3211 res.size = encap_data->size;
3212 memcpy(res.buf, encap_data->data, res.size);
3213 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
3214 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
3215 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
3217 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3219 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3220 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3221 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3222 return rte_flow_error_set(error, EINVAL,
3223 RTE_FLOW_ERROR_TYPE_ACTION,
3224 NULL, "can't create encap action");
3229 * Create action push VLAN.
3232 * Pointer to rte_eth_dev structure.
3234 * Pointer to the flow attributes.
3236 * Pointer to the vlan to push to the Ethernet header.
3237 * @param[in, out] dev_flow
3238 * Pointer to the mlx5_flow.
3240 * Pointer to the error structure.
3243 * 0 on success, a negative errno value otherwise and rte_errno is set.
3246 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
3247 const struct rte_flow_attr *attr,
3248 const struct rte_vlan_hdr *vlan,
3249 struct mlx5_flow *dev_flow,
3250 struct rte_flow_error *error)
3252 struct mlx5_flow_dv_push_vlan_action_resource res;
3254 memset(&res, 0, sizeof(res));
3256 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
3259 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3261 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3262 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3263 return flow_dv_push_vlan_action_resource_register
3264 (dev, &res, dev_flow, error);
3268 * Validate the modify-header actions.
3270 * @param[in] action_flags
3271 * Holds the actions detected until now.
3273 * Pointer to the modify action.
3275 * Pointer to error structure.
3278 * 0 on success, a negative errno value otherwise and rte_errno is set.
3281 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
3282 const struct rte_flow_action *action,
3283 struct rte_flow_error *error)
3285 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
3286 return rte_flow_error_set(error, EINVAL,
3287 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3288 NULL, "action configuration not set");
3289 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3290 return rte_flow_error_set(error, EINVAL,
3291 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3292 "can't have encap action before"
3298 * Validate the modify-header MAC address actions.
3300 * @param[in] action_flags
3301 * Holds the actions detected until now.
3303 * Pointer to the modify action.
3304 * @param[in] item_flags
3305 * Holds the items detected.
3307 * Pointer to error structure.
3310 * 0 on success, a negative errno value otherwise and rte_errno is set.
3313 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
3314 const struct rte_flow_action *action,
3315 const uint64_t item_flags,
3316 struct rte_flow_error *error)
3320 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3322 if (!(item_flags & MLX5_FLOW_LAYER_L2))
3323 return rte_flow_error_set(error, EINVAL,
3324 RTE_FLOW_ERROR_TYPE_ACTION,
3326 "no L2 item in pattern");
3332 * Validate the modify-header IPv4 address actions.
3334 * @param[in] action_flags
3335 * Holds the actions detected until now.
3337 * Pointer to the modify action.
3338 * @param[in] item_flags
3339 * Holds the items detected.
3341 * Pointer to error structure.
3344 * 0 on success, a negative errno value otherwise and rte_errno is set.
3347 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
3348 const struct rte_flow_action *action,
3349 const uint64_t item_flags,
3350 struct rte_flow_error *error)
3355 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3357 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3358 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
3359 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3360 if (!(item_flags & layer))
3361 return rte_flow_error_set(error, EINVAL,
3362 RTE_FLOW_ERROR_TYPE_ACTION,
3364 "no ipv4 item in pattern");
3370 * Validate the modify-header IPv6 address actions.
3372 * @param[in] action_flags
3373 * Holds the actions detected until now.
3375 * Pointer to the modify action.
3376 * @param[in] item_flags
3377 * Holds the items detected.
3379 * Pointer to error structure.
3382 * 0 on success, a negative errno value otherwise and rte_errno is set.
3385 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
3386 const struct rte_flow_action *action,
3387 const uint64_t item_flags,
3388 struct rte_flow_error *error)
3393 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3395 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3396 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
3397 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3398 if (!(item_flags & layer))
3399 return rte_flow_error_set(error, EINVAL,
3400 RTE_FLOW_ERROR_TYPE_ACTION,
3402 "no ipv6 item in pattern");
3408 * Validate the modify-header TP actions.
3410 * @param[in] action_flags
3411 * Holds the actions detected until now.
3413 * Pointer to the modify action.
3414 * @param[in] item_flags
3415 * Holds the items detected.
3417 * Pointer to error structure.
3420 * 0 on success, a negative errno value otherwise and rte_errno is set.
3423 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
3424 const struct rte_flow_action *action,
3425 const uint64_t item_flags,
3426 struct rte_flow_error *error)
3431 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3433 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3434 MLX5_FLOW_LAYER_INNER_L4 :
3435 MLX5_FLOW_LAYER_OUTER_L4;
3436 if (!(item_flags & layer))
3437 return rte_flow_error_set(error, EINVAL,
3438 RTE_FLOW_ERROR_TYPE_ACTION,
3439 NULL, "no transport layer "
3446 * Validate the modify-header actions of increment/decrement
3447 * TCP Sequence-number.
3449 * @param[in] action_flags
3450 * Holds the actions detected until now.
3452 * Pointer to the modify action.
3453 * @param[in] item_flags
3454 * Holds the items detected.
3456 * Pointer to error structure.
3459 * 0 on success, a negative errno value otherwise and rte_errno is set.
3462 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
3463 const struct rte_flow_action *action,
3464 const uint64_t item_flags,
3465 struct rte_flow_error *error)
3470 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3472 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3473 MLX5_FLOW_LAYER_INNER_L4_TCP :
3474 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3475 if (!(item_flags & layer))
3476 return rte_flow_error_set(error, EINVAL,
3477 RTE_FLOW_ERROR_TYPE_ACTION,
3478 NULL, "no TCP item in"
3480 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
3481 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
3482 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
3483 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
3484 return rte_flow_error_set(error, EINVAL,
3485 RTE_FLOW_ERROR_TYPE_ACTION,
3487 "cannot decrease and increase"
3488 " TCP sequence number"
3489 " at the same time");
3495 * Validate the modify-header actions of increment/decrement
3496 * TCP Acknowledgment number.
3498 * @param[in] action_flags
3499 * Holds the actions detected until now.
3501 * Pointer to the modify action.
3502 * @param[in] item_flags
3503 * Holds the items detected.
3505 * Pointer to error structure.
3508 * 0 on success, a negative errno value otherwise and rte_errno is set.
3511 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
3512 const struct rte_flow_action *action,
3513 const uint64_t item_flags,
3514 struct rte_flow_error *error)
3519 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3521 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3522 MLX5_FLOW_LAYER_INNER_L4_TCP :
3523 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3524 if (!(item_flags & layer))
3525 return rte_flow_error_set(error, EINVAL,
3526 RTE_FLOW_ERROR_TYPE_ACTION,
3527 NULL, "no TCP item in"
3529 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
3530 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
3531 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
3532 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
3533 return rte_flow_error_set(error, EINVAL,
3534 RTE_FLOW_ERROR_TYPE_ACTION,
3536 "cannot decrease and increase"
3537 " TCP acknowledgment number"
3538 " at the same time");
3544 * Validate the modify-header TTL actions.
3546 * @param[in] action_flags
3547 * Holds the actions detected until now.
3549 * Pointer to the modify action.
3550 * @param[in] item_flags
3551 * Holds the items detected.
3553 * Pointer to error structure.
3556 * 0 on success, a negative errno value otherwise and rte_errno is set.
3559 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
3560 const struct rte_flow_action *action,
3561 const uint64_t item_flags,
3562 struct rte_flow_error *error)
3567 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3569 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3570 MLX5_FLOW_LAYER_INNER_L3 :
3571 MLX5_FLOW_LAYER_OUTER_L3;
3572 if (!(item_flags & layer))
3573 return rte_flow_error_set(error, EINVAL,
3574 RTE_FLOW_ERROR_TYPE_ACTION,
3576 "no IP protocol in pattern");
3582 * Validate jump action.
3585 * Pointer to the jump action.
3586 * @param[in] action_flags
3587 * Holds the actions detected until now.
3588 * @param[in] attributes
3589 * Pointer to flow attributes
3590 * @param[in] external
3591 * Action belongs to flow rule created by request external to PMD.
3593 * Pointer to error structure.
3596 * 0 on success, a negative errno value otherwise and rte_errno is set.
3599 flow_dv_validate_action_jump(const struct rte_flow_action *action,
3600 uint64_t action_flags,
3601 const struct rte_flow_attr *attributes,
3602 bool external, struct rte_flow_error *error)
3604 uint32_t target_group, table;
3607 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3608 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3609 return rte_flow_error_set(error, EINVAL,
3610 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3611 "can't have 2 fate actions in"
3613 if (action_flags & MLX5_FLOW_ACTION_METER)
3614 return rte_flow_error_set(error, ENOTSUP,
3615 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3616 "jump with meter not support");
3618 return rte_flow_error_set(error, EINVAL,
3619 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3620 NULL, "action configuration not set");
3622 ((const struct rte_flow_action_jump *)action->conf)->group;
3623 ret = mlx5_flow_group_to_table(attributes, external, target_group,
3624 true, &table, error);
3627 if (attributes->group == target_group)
3628 return rte_flow_error_set(error, EINVAL,
3629 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3630 "target group must be other than"
3631 " the current flow group");
3636 * Validate the port_id action.
3639 * Pointer to rte_eth_dev structure.
3640 * @param[in] action_flags
3641 * Bit-fields that holds the actions detected until now.
3643 * Port_id RTE action structure.
3645 * Attributes of flow that includes this action.
3647 * Pointer to error structure.
3650 * 0 on success, a negative errno value otherwise and rte_errno is set.
3653 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
3654 uint64_t action_flags,
3655 const struct rte_flow_action *action,
3656 const struct rte_flow_attr *attr,
3657 struct rte_flow_error *error)
3659 const struct rte_flow_action_port_id *port_id;
3660 struct mlx5_priv *act_priv;
3661 struct mlx5_priv *dev_priv;
3664 if (!attr->transfer)
3665 return rte_flow_error_set(error, ENOTSUP,
3666 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3668 "port id action is valid in transfer"
3670 if (!action || !action->conf)
3671 return rte_flow_error_set(error, ENOTSUP,
3672 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3674 "port id action parameters must be"
3676 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3677 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3678 return rte_flow_error_set(error, EINVAL,
3679 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3680 "can have only one fate actions in"
3682 dev_priv = mlx5_dev_to_eswitch_info(dev);
3684 return rte_flow_error_set(error, rte_errno,
3685 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3687 "failed to obtain E-Switch info");
3688 port_id = action->conf;
3689 port = port_id->original ? dev->data->port_id : port_id->id;
3690 act_priv = mlx5_port_to_eswitch_info(port, false);
3692 return rte_flow_error_set
3694 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
3695 "failed to obtain E-Switch port id for port");
3696 if (act_priv->domain_id != dev_priv->domain_id)
3697 return rte_flow_error_set
3699 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3700 "port does not belong to"
3701 " E-Switch being configured");
3706 * Get the maximum number of modify header actions.
3709 * Pointer to rte_eth_dev structure.
3711 * Flags bits to check if root level.
3714 * Max number of modify header actions device can support.
3716 static inline unsigned int
3717 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
3721 * There's no way to directly query the max capacity from FW.
3722 * The maximal value on root table should be assumed to be supported.
3724 if (!(flags & MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL))
3725 return MLX5_MAX_MODIFY_NUM;
3727 return MLX5_ROOT_TBL_MODIFY_NUM;
3731 * Validate the meter action.
3734 * Pointer to rte_eth_dev structure.
3735 * @param[in] action_flags
3736 * Bit-fields that holds the actions detected until now.
3738 * Pointer to the meter action.
3740 * Attributes of flow that includes this action.
3742 * Pointer to error structure.
3745 * 0 on success, a negative errno value otherwise and rte_ernno is set.
3748 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
3749 uint64_t action_flags,
3750 const struct rte_flow_action *action,
3751 const struct rte_flow_attr *attr,
3752 struct rte_flow_error *error)
3754 struct mlx5_priv *priv = dev->data->dev_private;
3755 const struct rte_flow_action_meter *am = action->conf;
3756 struct mlx5_flow_meter *fm;
3759 return rte_flow_error_set(error, EINVAL,
3760 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3761 "meter action conf is NULL");
3763 if (action_flags & MLX5_FLOW_ACTION_METER)
3764 return rte_flow_error_set(error, ENOTSUP,
3765 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3766 "meter chaining not support");
3767 if (action_flags & MLX5_FLOW_ACTION_JUMP)
3768 return rte_flow_error_set(error, ENOTSUP,
3769 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3770 "meter with jump not support");
3772 return rte_flow_error_set(error, ENOTSUP,
3773 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3775 "meter action not supported");
3776 fm = mlx5_flow_meter_find(priv, am->mtr_id);
3778 return rte_flow_error_set(error, EINVAL,
3779 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3781 if (fm->ref_cnt && (!(fm->transfer == attr->transfer ||
3782 (!fm->ingress && !attr->ingress && attr->egress) ||
3783 (!fm->egress && !attr->egress && attr->ingress))))
3784 return rte_flow_error_set(error, EINVAL,
3785 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3786 "Flow attributes are either invalid "
3787 "or have a conflict with current "
3788 "meter attributes");
3793 * Validate the age action.
3795 * @param[in] action_flags
3796 * Holds the actions detected until now.
3798 * Pointer to the age action.
3800 * Pointer to the Ethernet device structure.
3802 * Pointer to error structure.
3805 * 0 on success, a negative errno value otherwise and rte_errno is set.
3808 flow_dv_validate_action_age(uint64_t action_flags,
3809 const struct rte_flow_action *action,
3810 struct rte_eth_dev *dev,
3811 struct rte_flow_error *error)
3813 struct mlx5_priv *priv = dev->data->dev_private;
3814 const struct rte_flow_action_age *age = action->conf;
3816 if (!priv->config.devx || priv->counter_fallback)
3817 return rte_flow_error_set(error, ENOTSUP,
3818 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3820 "age action not supported");
3821 if (!(action->conf))
3822 return rte_flow_error_set(error, EINVAL,
3823 RTE_FLOW_ERROR_TYPE_ACTION, action,
3824 "configuration cannot be null");
3825 if (age->timeout >= UINT16_MAX / 2 / 10)
3826 return rte_flow_error_set(error, ENOTSUP,
3827 RTE_FLOW_ERROR_TYPE_ACTION, action,
3828 "Max age time: 3275 seconds");
3829 if (action_flags & MLX5_FLOW_ACTION_AGE)
3830 return rte_flow_error_set(error, EINVAL,
3831 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3832 "Duplicate age ctions set");
3837 * Validate the modify-header IPv4 DSCP actions.
3839 * @param[in] action_flags
3840 * Holds the actions detected until now.
3842 * Pointer to the modify action.
3843 * @param[in] item_flags
3844 * Holds the items detected.
3846 * Pointer to error structure.
3849 * 0 on success, a negative errno value otherwise and rte_errno is set.
3852 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
3853 const struct rte_flow_action *action,
3854 const uint64_t item_flags,
3855 struct rte_flow_error *error)
3859 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3861 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
3862 return rte_flow_error_set(error, EINVAL,
3863 RTE_FLOW_ERROR_TYPE_ACTION,
3865 "no ipv4 item in pattern");
3871 * Validate the modify-header IPv6 DSCP actions.
3873 * @param[in] action_flags
3874 * Holds the actions detected until now.
3876 * Pointer to the modify action.
3877 * @param[in] item_flags
3878 * Holds the items detected.
3880 * Pointer to error structure.
3883 * 0 on success, a negative errno value otherwise and rte_errno is set.
3886 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
3887 const struct rte_flow_action *action,
3888 const uint64_t item_flags,
3889 struct rte_flow_error *error)
3893 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3895 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
3896 return rte_flow_error_set(error, EINVAL,
3897 RTE_FLOW_ERROR_TYPE_ACTION,
3899 "no ipv6 item in pattern");
3905 * Find existing modify-header resource or create and register a new one.
3907 * @param dev[in, out]
3908 * Pointer to rte_eth_dev structure.
3909 * @param[in, out] resource
3910 * Pointer to modify-header resource.
3911 * @parm[in, out] dev_flow
3912 * Pointer to the dev_flow.
3914 * pointer to error structure.
3917 * 0 on success otherwise -errno and errno is set.
3920 flow_dv_modify_hdr_resource_register
3921 (struct rte_eth_dev *dev,
3922 struct mlx5_flow_dv_modify_hdr_resource *resource,
3923 struct mlx5_flow *dev_flow,
3924 struct rte_flow_error *error)
3926 struct mlx5_priv *priv = dev->data->dev_private;
3927 struct mlx5_ibv_shared *sh = priv->sh;
3928 struct mlx5_flow_dv_modify_hdr_resource *cache_resource;
3929 struct mlx5dv_dr_domain *ns;
3930 uint32_t actions_len;
3932 resource->flags = dev_flow->dv.group ? 0 :
3933 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
3934 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
3936 return rte_flow_error_set(error, EOVERFLOW,
3937 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3938 "too many modify header items");
3939 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3940 ns = sh->fdb_domain;
3941 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
3945 /* Lookup a matching resource from cache. */
3946 actions_len = resource->actions_num * sizeof(resource->actions[0]);
3947 LIST_FOREACH(cache_resource, &sh->modify_cmds, next) {
3948 if (resource->ft_type == cache_resource->ft_type &&
3949 resource->actions_num == cache_resource->actions_num &&
3950 resource->flags == cache_resource->flags &&
3951 !memcmp((const void *)resource->actions,
3952 (const void *)cache_resource->actions,
3954 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d++",
3955 (void *)cache_resource,
3956 rte_atomic32_read(&cache_resource->refcnt));
3957 rte_atomic32_inc(&cache_resource->refcnt);
3958 dev_flow->handle->dvh.modify_hdr = cache_resource;
3962 /* Register new modify-header resource. */
3963 cache_resource = rte_calloc(__func__, 1,
3964 sizeof(*cache_resource) + actions_len, 0);
3965 if (!cache_resource)
3966 return rte_flow_error_set(error, ENOMEM,
3967 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3968 "cannot allocate resource memory");
3969 *cache_resource = *resource;
3970 rte_memcpy(cache_resource->actions, resource->actions, actions_len);
3971 cache_resource->verbs_action =
3972 mlx5_glue->dv_create_flow_action_modify_header
3973 (sh->ctx, cache_resource->ft_type, ns,
3974 cache_resource->flags, actions_len,
3975 (uint64_t *)cache_resource->actions);
3976 if (!cache_resource->verbs_action) {
3977 rte_free(cache_resource);
3978 return rte_flow_error_set(error, ENOMEM,
3979 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3980 NULL, "cannot create action");
3982 rte_atomic32_init(&cache_resource->refcnt);
3983 rte_atomic32_inc(&cache_resource->refcnt);
3984 LIST_INSERT_HEAD(&sh->modify_cmds, cache_resource, next);
3985 dev_flow->handle->dvh.modify_hdr = cache_resource;
3986 DRV_LOG(DEBUG, "new modify-header resource %p: refcnt %d++",
3987 (void *)cache_resource,
3988 rte_atomic32_read(&cache_resource->refcnt));
3993 * Get DV flow counter by index.
3996 * Pointer to the Ethernet device structure.
3998 * mlx5 flow counter index in the container.
4000 * mlx5 flow counter pool in the container,
4003 * Pointer to the counter, NULL otherwise.
4005 static struct mlx5_flow_counter *
4006 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
4008 struct mlx5_flow_counter_pool **ppool)
4010 struct mlx5_priv *priv = dev->data->dev_private;
4011 struct mlx5_pools_container *cont;
4012 struct mlx5_flow_counter_pool *pool;
4013 uint32_t batch = 0, age = 0;
4016 age = MLX_CNT_IS_AGE(idx);
4017 idx = age ? idx - MLX5_CNT_AGE_OFFSET : idx;
4018 if (idx >= MLX5_CNT_BATCH_OFFSET) {
4019 idx -= MLX5_CNT_BATCH_OFFSET;
4022 cont = MLX5_CNT_CONTAINER(priv->sh, batch, 0, age);
4023 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cont->n);
4024 pool = cont->pools[idx / MLX5_COUNTERS_PER_POOL];
4028 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
4032 * Get a pool by devx counter ID.
4035 * Pointer to the counter container.
4037 * The counter devx ID.
4040 * The counter pool pointer if exists, NULL otherwise,
4042 static struct mlx5_flow_counter_pool *
4043 flow_dv_find_pool_by_id(struct mlx5_pools_container *cont, int id)
4046 uint32_t n_valid = rte_atomic16_read(&cont->n_valid);
4048 for (i = 0; i < n_valid; i++) {
4049 struct mlx5_flow_counter_pool *pool = cont->pools[i];
4050 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
4051 MLX5_COUNTERS_PER_POOL;
4053 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL) {
4055 * Move the pool to the head, as counter allocate
4056 * always gets the first pool in the container.
4058 if (pool != TAILQ_FIRST(&cont->pool_list)) {
4059 TAILQ_REMOVE(&cont->pool_list, pool, next);
4060 TAILQ_INSERT_HEAD(&cont->pool_list, pool, next);
4069 * Allocate a new memory for the counter values wrapped by all the needed
4073 * Pointer to the Ethernet device structure.
4075 * The raw memory areas - each one for MLX5_COUNTERS_PER_POOL counters.
4078 * The new memory management pointer on success, otherwise NULL and rte_errno
4081 static struct mlx5_counter_stats_mem_mng *
4082 flow_dv_create_counter_stat_mem_mng(struct rte_eth_dev *dev, int raws_n)
4084 struct mlx5_ibv_shared *sh = ((struct mlx5_priv *)
4085 (dev->data->dev_private))->sh;
4086 struct mlx5_devx_mkey_attr mkey_attr;
4087 struct mlx5_counter_stats_mem_mng *mem_mng;
4088 volatile struct flow_counter_stats *raw_data;
4089 int size = (sizeof(struct flow_counter_stats) *
4090 MLX5_COUNTERS_PER_POOL +
4091 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
4092 sizeof(struct mlx5_counter_stats_mem_mng);
4093 uint8_t *mem = rte_calloc(__func__, 1, size, sysconf(_SC_PAGESIZE));
4100 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
4101 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
4102 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
4103 IBV_ACCESS_LOCAL_WRITE);
4104 if (!mem_mng->umem) {
4109 mkey_attr.addr = (uintptr_t)mem;
4110 mkey_attr.size = size;
4111 mkey_attr.umem_id = mem_mng->umem->umem_id;
4112 mkey_attr.pd = sh->pdn;
4113 mkey_attr.log_entity_size = 0;
4114 mkey_attr.pg_access = 0;
4115 mkey_attr.klm_array = NULL;
4116 mkey_attr.klm_num = 0;
4117 mkey_attr.relaxed_ordering = 1;
4118 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
4120 mlx5_glue->devx_umem_dereg(mem_mng->umem);
4125 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
4126 raw_data = (volatile struct flow_counter_stats *)mem;
4127 for (i = 0; i < raws_n; ++i) {
4128 mem_mng->raws[i].mem_mng = mem_mng;
4129 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
4131 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
4136 * Resize a counter container.
4139 * Pointer to the Ethernet device structure.
4141 * Whether the pool is for counter that was allocated by batch command.
4143 * Whether the pool is for Aging counter.
4146 * The new container pointer on success, otherwise NULL and rte_errno is set.
4148 static struct mlx5_pools_container *
4149 flow_dv_container_resize(struct rte_eth_dev *dev,
4150 uint32_t batch, uint32_t age)
4152 struct mlx5_priv *priv = dev->data->dev_private;
4153 struct mlx5_pools_container *cont =
4154 MLX5_CNT_CONTAINER(priv->sh, batch, 0, age);
4155 struct mlx5_pools_container *new_cont =
4156 MLX5_CNT_CONTAINER_UNUSED(priv->sh, batch, 0, age);
4157 struct mlx5_counter_stats_mem_mng *mem_mng = NULL;
4158 uint32_t resize = cont->n + MLX5_CNT_CONTAINER_RESIZE;
4159 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
4162 /* Fallback mode has no background thread. Skip the check. */
4163 if (!priv->counter_fallback &&
4164 cont != MLX5_CNT_CONTAINER(priv->sh, batch, 1, age)) {
4165 /* The last resize still hasn't detected by the host thread. */
4169 new_cont->pools = rte_calloc(__func__, 1, mem_size, 0);
4170 if (!new_cont->pools) {
4175 memcpy(new_cont->pools, cont->pools, cont->n *
4176 sizeof(struct mlx5_flow_counter_pool *));
4178 * Fallback mode query the counter directly, no background query
4179 * resources are needed.
4181 if (!priv->counter_fallback) {
4182 mem_mng = flow_dv_create_counter_stat_mem_mng(dev,
4183 MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES);
4185 rte_free(new_cont->pools);
4188 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
4189 LIST_INSERT_HEAD(&priv->sh->cmng.free_stat_raws,
4191 MLX5_CNT_CONTAINER_RESIZE +
4195 * Release the old container pools directly as no background
4196 * thread helps that.
4198 rte_free(cont->pools);
4200 new_cont->n = resize;
4201 rte_atomic16_set(&new_cont->n_valid, rte_atomic16_read(&cont->n_valid));
4202 TAILQ_INIT(&new_cont->pool_list);
4203 TAILQ_CONCAT(&new_cont->pool_list, &cont->pool_list, next);
4204 new_cont->init_mem_mng = mem_mng;
4206 /* Flip the master container. */
4207 priv->sh->cmng.mhi[batch][age] ^= (uint8_t)1;
4212 * Query a devx flow counter.
4215 * Pointer to the Ethernet device structure.
4217 * Index to the flow counter.
4219 * The statistics value of packets.
4221 * The statistics value of bytes.
4224 * 0 on success, otherwise a negative errno value and rte_errno is set.
4227 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
4230 struct mlx5_priv *priv = dev->data->dev_private;
4231 struct mlx5_flow_counter_pool *pool = NULL;
4232 struct mlx5_flow_counter *cnt;
4233 struct mlx5_flow_counter_ext *cnt_ext = NULL;
4236 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
4238 if (counter < MLX5_CNT_BATCH_OFFSET) {
4239 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt);
4240 if (priv->counter_fallback)
4241 return mlx5_devx_cmd_flow_counter_query(cnt_ext->dcs, 0,
4242 0, pkts, bytes, 0, NULL, NULL, 0);
4245 rte_spinlock_lock(&pool->sl);
4247 * The single counters allocation may allocate smaller ID than the
4248 * current allocated in parallel to the host reading.
4249 * In this case the new counter values must be reported as 0.
4251 if (unlikely(cnt_ext && cnt_ext->dcs->id < pool->raw->min_dcs_id)) {
4255 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
4256 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
4257 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
4259 rte_spinlock_unlock(&pool->sl);
4264 * Create and initialize a new counter pool.
4267 * Pointer to the Ethernet device structure.
4269 * The devX counter handle.
4271 * Whether the pool is for counter that was allocated by batch command.
4273 * Whether the pool is for counter that was allocated for aging.
4274 * @param[in/out] cont_cur
4275 * Pointer to the container pointer, it will be update in pool resize.
4278 * The pool container pointer on success, NULL otherwise and rte_errno is set.
4280 static struct mlx5_pools_container *
4281 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
4282 uint32_t batch, uint32_t age)
4284 struct mlx5_priv *priv = dev->data->dev_private;
4285 struct mlx5_flow_counter_pool *pool;
4286 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4288 int16_t n_valid = rte_atomic16_read(&cont->n_valid);
4289 uint32_t size = sizeof(*pool);
4291 if (cont->n == n_valid) {
4292 cont = flow_dv_container_resize(dev, batch, age);
4296 size += MLX5_COUNTERS_PER_POOL * CNT_SIZE;
4297 size += (batch ? 0 : MLX5_COUNTERS_PER_POOL * CNTEXT_SIZE);
4298 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * AGE_SIZE);
4299 pool = rte_calloc(__func__, 1, size, 0);
4304 pool->min_dcs = dcs;
4305 if (!priv->counter_fallback)
4306 pool->raw = cont->init_mem_mng->raws + n_valid %
4307 MLX5_CNT_CONTAINER_RESIZE;
4308 pool->raw_hw = NULL;
4310 pool->type |= (batch ? 0 : CNT_POOL_TYPE_EXT);
4311 pool->type |= (!age ? 0 : CNT_POOL_TYPE_AGE);
4312 rte_spinlock_init(&pool->sl);
4314 * The generation of the new allocated counters in this pool is 0, 2 in
4315 * the pool generation makes all the counters valid for allocation.
4316 * The start and end query generation protect the counters be released
4317 * between the query and update gap period will not be reallocated
4318 * without the last query finished and stats updated to the memory.
4320 rte_atomic64_set(&pool->start_query_gen, 0x2);
4322 * There's no background query thread for fallback mode, set the
4323 * end_query_gen to the maximum value since no need to wait for
4324 * statistics update.
4326 rte_atomic64_set(&pool->end_query_gen, priv->counter_fallback ?
4328 TAILQ_INIT(&pool->counters);
4329 TAILQ_INSERT_HEAD(&cont->pool_list, pool, next);
4330 pool->index = n_valid;
4331 cont->pools[n_valid] = pool;
4332 /* Pool initialization must be updated before host thread access. */
4334 rte_atomic16_add(&cont->n_valid, 1);
4339 * Update the minimum dcs-id for aged or no-aged counter pool.
4342 * Pointer to the Ethernet device structure.
4344 * Current counter pool.
4346 * Whether the pool is for counter that was allocated by batch command.
4348 * Whether the counter is for aging.
4351 flow_dv_counter_update_min_dcs(struct rte_eth_dev *dev,
4352 struct mlx5_flow_counter_pool *pool,
4353 uint32_t batch, uint32_t age)
4355 struct mlx5_priv *priv = dev->data->dev_private;
4356 struct mlx5_flow_counter_pool *other;
4357 struct mlx5_pools_container *cont;
4359 cont = MLX5_CNT_CONTAINER(priv->sh, batch, 0, (age ^ 0x1));
4360 other = flow_dv_find_pool_by_id(cont, pool->min_dcs->id);
4363 if (pool->min_dcs->id < other->min_dcs->id) {
4364 rte_atomic64_set(&other->a64_dcs,
4365 rte_atomic64_read(&pool->a64_dcs));
4367 rte_atomic64_set(&pool->a64_dcs,
4368 rte_atomic64_read(&other->a64_dcs));
4372 * Prepare a new counter and/or a new counter pool.
4375 * Pointer to the Ethernet device structure.
4376 * @param[out] cnt_free
4377 * Where to put the pointer of a new counter.
4379 * Whether the pool is for counter that was allocated by batch command.
4381 * Whether the pool is for counter that was allocated for aging.
4384 * The counter container pointer and @p cnt_free is set on success,
4385 * NULL otherwise and rte_errno is set.
4387 static struct mlx5_pools_container *
4388 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
4389 struct mlx5_flow_counter **cnt_free,
4390 uint32_t batch, uint32_t age)
4392 struct mlx5_priv *priv = dev->data->dev_private;
4393 struct mlx5_pools_container *cont;
4394 struct mlx5_flow_counter_pool *pool;
4395 struct mlx5_devx_obj *dcs = NULL;
4396 struct mlx5_flow_counter *cnt;
4399 cont = MLX5_CNT_CONTAINER(priv->sh, batch, 0, age);
4401 /* bulk_bitmap must be 0 for single counter allocation. */
4402 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
4405 pool = flow_dv_find_pool_by_id(cont, dcs->id);
4407 cont = flow_dv_pool_create(dev, dcs, batch, age);
4409 mlx5_devx_cmd_destroy(dcs);
4412 pool = TAILQ_FIRST(&cont->pool_list);
4413 } else if (dcs->id < pool->min_dcs->id) {
4414 rte_atomic64_set(&pool->a64_dcs,
4415 (int64_t)(uintptr_t)dcs);
4417 flow_dv_counter_update_min_dcs(dev,
4419 i = dcs->id % MLX5_COUNTERS_PER_POOL;
4420 cnt = MLX5_POOL_GET_CNT(pool, i);
4421 TAILQ_INSERT_HEAD(&pool->counters, cnt, next);
4422 MLX5_GET_POOL_CNT_EXT(pool, i)->dcs = dcs;
4426 /* bulk_bitmap is in 128 counters units. */
4427 if (priv->config.hca_attr.flow_counter_bulk_alloc_bitmap & 0x4)
4428 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
4430 rte_errno = ENODATA;
4433 cont = flow_dv_pool_create(dev, dcs, batch, age);
4435 mlx5_devx_cmd_destroy(dcs);
4438 pool = TAILQ_FIRST(&cont->pool_list);
4439 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
4440 cnt = MLX5_POOL_GET_CNT(pool, i);
4441 TAILQ_INSERT_HEAD(&pool->counters, cnt, next);
4443 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
4448 * Search for existed shared counter.
4451 * Pointer to the relevant counter pool container.
4453 * The shared counter ID to search.
4455 * mlx5 flow counter pool in the container,
4458 * NULL if not existed, otherwise pointer to the shared extend counter.
4460 static struct mlx5_flow_counter_ext *
4461 flow_dv_counter_shared_search(struct mlx5_pools_container *cont, uint32_t id,
4462 struct mlx5_flow_counter_pool **ppool)
4464 static struct mlx5_flow_counter_ext *cnt;
4465 struct mlx5_flow_counter_pool *pool;
4467 uint32_t n_valid = rte_atomic16_read(&cont->n_valid);
4469 for (i = 0; i < n_valid; i++) {
4470 pool = cont->pools[i];
4471 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
4472 cnt = MLX5_GET_POOL_CNT_EXT(pool, i);
4473 if (cnt->ref_cnt && cnt->shared && cnt->id == id) {
4475 *ppool = cont->pools[i];
4484 * Allocate a flow counter.
4487 * Pointer to the Ethernet device structure.
4489 * Indicate if this counter is shared with other flows.
4491 * Counter identifier.
4493 * Counter flow group.
4495 * Whether the counter was allocated for aging.
4498 * Index to flow counter on success, 0 otherwise and rte_errno is set.
4501 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t shared, uint32_t id,
4502 uint16_t group, uint32_t age)
4504 struct mlx5_priv *priv = dev->data->dev_private;
4505 struct mlx5_flow_counter_pool *pool = NULL;
4506 struct mlx5_flow_counter *cnt_free = NULL;
4507 struct mlx5_flow_counter_ext *cnt_ext = NULL;
4509 * Currently group 0 flow counter cannot be assigned to a flow if it is
4510 * not the first one in the batch counter allocation, so it is better
4511 * to allocate counters one by one for these flows in a separate
4513 * A counter can be shared between different groups so need to take
4514 * shared counters from the single container.
4516 uint32_t batch = (group && !shared && !priv->counter_fallback) ? 1 : 0;
4517 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4521 if (!priv->config.devx) {
4522 rte_errno = ENOTSUP;
4526 cnt_ext = flow_dv_counter_shared_search(cont, id, &pool);
4528 if (cnt_ext->ref_cnt + 1 == 0) {
4533 cnt_idx = pool->index * MLX5_COUNTERS_PER_POOL +
4534 (cnt_ext->dcs->id % MLX5_COUNTERS_PER_POOL)
4539 /* Pools which has a free counters are in the start. */
4540 TAILQ_FOREACH(pool, &cont->pool_list, next) {
4542 * The free counter reset values must be updated between the
4543 * counter release to the counter allocation, so, at least one
4544 * query must be done in this time. ensure it by saving the
4545 * query generation in the release time.
4546 * The free list is sorted according to the generation - so if
4547 * the first one is not updated, all the others are not
4550 cnt_free = TAILQ_FIRST(&pool->counters);
4551 if (cnt_free && cnt_free->query_gen <
4552 rte_atomic64_read(&pool->end_query_gen))
4557 cont = flow_dv_counter_pool_prepare(dev, &cnt_free, batch, age);
4560 pool = TAILQ_FIRST(&cont->pool_list);
4563 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt_free);
4564 /* Create a DV counter action only in the first time usage. */
4565 if (!cnt_free->action) {
4567 struct mlx5_devx_obj *dcs;
4570 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
4571 dcs = pool->min_dcs;
4576 cnt_free->action = mlx5_glue->dv_create_flow_action_counter
4578 if (!cnt_free->action) {
4583 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
4584 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
4585 cnt_idx += batch * MLX5_CNT_BATCH_OFFSET;
4586 cnt_idx += age * MLX5_CNT_AGE_OFFSET;
4587 /* Update the counter reset values. */
4588 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
4592 cnt_ext->shared = shared;
4593 cnt_ext->ref_cnt = 1;
4596 if (!priv->counter_fallback && !priv->sh->cmng.query_thread_on)
4597 /* Start the asynchronous batch query by the host thread. */
4598 mlx5_set_query_alarm(priv->sh);
4599 TAILQ_REMOVE(&pool->counters, cnt_free, next);
4600 if (TAILQ_EMPTY(&pool->counters)) {
4601 /* Move the pool to the end of the container pool list. */
4602 TAILQ_REMOVE(&cont->pool_list, pool, next);
4603 TAILQ_INSERT_TAIL(&cont->pool_list, pool, next);
4609 * Get age param from counter index.
4612 * Pointer to the Ethernet device structure.
4613 * @param[in] counter
4614 * Index to the counter handler.
4617 * The aging parameter specified for the counter index.
4619 static struct mlx5_age_param*
4620 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
4623 struct mlx5_flow_counter *cnt;
4624 struct mlx5_flow_counter_pool *pool = NULL;
4626 flow_dv_counter_get_by_idx(dev, counter, &pool);
4627 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
4628 cnt = MLX5_POOL_GET_CNT(pool, counter);
4629 return MLX5_CNT_TO_AGE(cnt);
4633 * Remove a flow counter from aged counter list.
4636 * Pointer to the Ethernet device structure.
4637 * @param[in] counter
4638 * Index to the counter handler.
4640 * Pointer to the counter handler.
4643 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
4644 uint32_t counter, struct mlx5_flow_counter *cnt)
4646 struct mlx5_age_info *age_info;
4647 struct mlx5_age_param *age_param;
4648 struct mlx5_priv *priv = dev->data->dev_private;
4650 age_info = GET_PORT_AGE_INFO(priv);
4651 age_param = flow_dv_counter_idx_get_age(dev, counter);
4652 if (rte_atomic16_cmpset((volatile uint16_t *)
4654 AGE_CANDIDATE, AGE_FREE)
4657 * We need the lock even it is age timeout,
4658 * since counter may still in process.
4660 rte_spinlock_lock(&age_info->aged_sl);
4661 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
4662 rte_spinlock_unlock(&age_info->aged_sl);
4664 rte_atomic16_set(&age_param->state, AGE_FREE);
4667 * Release a flow counter.
4670 * Pointer to the Ethernet device structure.
4671 * @param[in] counter
4672 * Index to the counter handler.
4675 flow_dv_counter_release(struct rte_eth_dev *dev, uint32_t counter)
4677 struct mlx5_flow_counter_pool *pool = NULL;
4678 struct mlx5_flow_counter *cnt;
4679 struct mlx5_flow_counter_ext *cnt_ext = NULL;
4683 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
4685 if (counter < MLX5_CNT_BATCH_OFFSET) {
4686 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt);
4687 if (cnt_ext && --cnt_ext->ref_cnt)
4690 if (IS_AGE_POOL(pool))
4691 flow_dv_counter_remove_from_age(dev, counter, cnt);
4692 /* Put the counter in the end - the last updated one. */
4693 TAILQ_INSERT_TAIL(&pool->counters, cnt, next);
4695 * Counters released between query trigger and handler need
4696 * to wait the next round of query. Since the packets arrive
4697 * in the gap period will not be taken into account to the
4700 cnt->query_gen = rte_atomic64_read(&pool->start_query_gen);
4704 * Verify the @p attributes will be correctly understood by the NIC and store
4705 * them in the @p flow if everything is correct.
4708 * Pointer to dev struct.
4709 * @param[in] attributes
4710 * Pointer to flow attributes
4711 * @param[in] external
4712 * This flow rule is created by request external to PMD.
4714 * Pointer to error structure.
4717 * - 0 on success and non root table.
4718 * - 1 on success and root table.
4719 * - a negative errno value otherwise and rte_errno is set.
4722 flow_dv_validate_attributes(struct rte_eth_dev *dev,
4723 const struct rte_flow_attr *attributes,
4724 bool external __rte_unused,
4725 struct rte_flow_error *error)
4727 struct mlx5_priv *priv = dev->data->dev_private;
4728 uint32_t priority_max = priv->config.flow_prio - 1;
4731 #ifndef HAVE_MLX5DV_DR
4732 if (attributes->group)
4733 return rte_flow_error_set(error, ENOTSUP,
4734 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
4736 "groups are not supported");
4740 ret = mlx5_flow_group_to_table(attributes, external,
4741 attributes->group, !!priv->fdb_def_rule,
4746 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
4748 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
4749 attributes->priority >= priority_max)
4750 return rte_flow_error_set(error, ENOTSUP,
4751 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
4753 "priority out of range");
4754 if (attributes->transfer) {
4755 if (!priv->config.dv_esw_en)
4756 return rte_flow_error_set
4758 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4759 "E-Switch dr is not supported");
4760 if (!(priv->representor || priv->master))
4761 return rte_flow_error_set
4762 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4763 NULL, "E-Switch configuration can only be"
4764 " done by a master or a representor device");
4765 if (attributes->egress)
4766 return rte_flow_error_set
4768 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
4769 "egress is not supported");
4771 if (!(attributes->egress ^ attributes->ingress))
4772 return rte_flow_error_set(error, ENOTSUP,
4773 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
4774 "must specify exactly one of "
4775 "ingress or egress");
4780 * Internal validation function. For validating both actions and items.
4783 * Pointer to the rte_eth_dev structure.
4785 * Pointer to the flow attributes.
4787 * Pointer to the list of items.
4788 * @param[in] actions
4789 * Pointer to the list of actions.
4790 * @param[in] external
4791 * This flow rule is created by request external to PMD.
4792 * @param[in] hairpin
4793 * Number of hairpin TX actions, 0 means classic flow.
4795 * Pointer to the error structure.
4798 * 0 on success, a negative errno value otherwise and rte_errno is set.
4801 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
4802 const struct rte_flow_item items[],
4803 const struct rte_flow_action actions[],
4804 bool external, int hairpin, struct rte_flow_error *error)
4807 uint64_t action_flags = 0;
4808 uint64_t item_flags = 0;
4809 uint64_t last_item = 0;
4810 uint8_t next_protocol = 0xff;
4811 uint16_t ether_type = 0;
4813 uint8_t item_ipv6_proto = 0;
4814 const struct rte_flow_item *gre_item = NULL;
4815 const struct rte_flow_action_raw_decap *decap;
4816 const struct rte_flow_action_raw_encap *encap;
4817 const struct rte_flow_action_rss *rss;
4818 const struct rte_flow_item_tcp nic_tcp_mask = {
4821 .src_port = RTE_BE16(UINT16_MAX),
4822 .dst_port = RTE_BE16(UINT16_MAX),
4825 const struct rte_flow_item_ipv4 nic_ipv4_mask = {
4827 .src_addr = RTE_BE32(0xffffffff),
4828 .dst_addr = RTE_BE32(0xffffffff),
4829 .type_of_service = 0xff,
4830 .next_proto_id = 0xff,
4831 .time_to_live = 0xff,
4834 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
4837 "\xff\xff\xff\xff\xff\xff\xff\xff"
4838 "\xff\xff\xff\xff\xff\xff\xff\xff",
4840 "\xff\xff\xff\xff\xff\xff\xff\xff"
4841 "\xff\xff\xff\xff\xff\xff\xff\xff",
4842 .vtc_flow = RTE_BE32(0xffffffff),
4847 struct mlx5_priv *priv = dev->data->dev_private;
4848 struct mlx5_dev_config *dev_conf = &priv->config;
4849 uint16_t queue_index = 0xFFFF;
4850 const struct rte_flow_item_vlan *vlan_m = NULL;
4851 int16_t rw_act_num = 0;
4856 ret = flow_dv_validate_attributes(dev, attr, external, error);
4859 is_root = (uint64_t)ret;
4860 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4861 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
4862 int type = items->type;
4865 case RTE_FLOW_ITEM_TYPE_VOID:
4867 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4868 ret = flow_dv_validate_item_port_id
4869 (dev, items, attr, item_flags, error);
4872 last_item = MLX5_FLOW_ITEM_PORT_ID;
4874 case RTE_FLOW_ITEM_TYPE_ETH:
4875 ret = mlx5_flow_validate_item_eth(items, item_flags,
4879 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
4880 MLX5_FLOW_LAYER_OUTER_L2;
4881 if (items->mask != NULL && items->spec != NULL) {
4883 ((const struct rte_flow_item_eth *)
4886 ((const struct rte_flow_item_eth *)
4888 ether_type = rte_be_to_cpu_16(ether_type);
4893 case RTE_FLOW_ITEM_TYPE_VLAN:
4894 ret = flow_dv_validate_item_vlan(items, item_flags,
4898 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
4899 MLX5_FLOW_LAYER_OUTER_VLAN;
4900 if (items->mask != NULL && items->spec != NULL) {
4902 ((const struct rte_flow_item_vlan *)
4903 items->spec)->inner_type;
4905 ((const struct rte_flow_item_vlan *)
4906 items->mask)->inner_type;
4907 ether_type = rte_be_to_cpu_16(ether_type);
4911 /* Store outer VLAN mask for of_push_vlan action. */
4913 vlan_m = items->mask;
4915 case RTE_FLOW_ITEM_TYPE_IPV4:
4916 mlx5_flow_tunnel_ip_check(items, next_protocol,
4917 &item_flags, &tunnel);
4918 ret = mlx5_flow_validate_item_ipv4(items, item_flags,
4925 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4926 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4927 if (items->mask != NULL &&
4928 ((const struct rte_flow_item_ipv4 *)
4929 items->mask)->hdr.next_proto_id) {
4931 ((const struct rte_flow_item_ipv4 *)
4932 (items->spec))->hdr.next_proto_id;
4934 ((const struct rte_flow_item_ipv4 *)
4935 (items->mask))->hdr.next_proto_id;
4937 /* Reset for inner layer. */
4938 next_protocol = 0xff;
4941 case RTE_FLOW_ITEM_TYPE_IPV6:
4942 mlx5_flow_tunnel_ip_check(items, next_protocol,
4943 &item_flags, &tunnel);
4944 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
4951 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4952 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4953 if (items->mask != NULL &&
4954 ((const struct rte_flow_item_ipv6 *)
4955 items->mask)->hdr.proto) {
4957 ((const struct rte_flow_item_ipv6 *)
4958 items->spec)->hdr.proto;
4960 ((const struct rte_flow_item_ipv6 *)
4961 items->spec)->hdr.proto;
4963 ((const struct rte_flow_item_ipv6 *)
4964 items->mask)->hdr.proto;
4966 /* Reset for inner layer. */
4967 next_protocol = 0xff;
4970 case RTE_FLOW_ITEM_TYPE_TCP:
4971 ret = mlx5_flow_validate_item_tcp
4978 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
4979 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4981 case RTE_FLOW_ITEM_TYPE_UDP:
4982 ret = mlx5_flow_validate_item_udp(items, item_flags,
4987 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
4988 MLX5_FLOW_LAYER_OUTER_L4_UDP;
4990 case RTE_FLOW_ITEM_TYPE_GRE:
4991 ret = mlx5_flow_validate_item_gre(items, item_flags,
4992 next_protocol, error);
4996 last_item = MLX5_FLOW_LAYER_GRE;
4998 case RTE_FLOW_ITEM_TYPE_NVGRE:
4999 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
5004 last_item = MLX5_FLOW_LAYER_NVGRE;
5006 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
5007 ret = mlx5_flow_validate_item_gre_key
5008 (items, item_flags, gre_item, error);
5011 last_item = MLX5_FLOW_LAYER_GRE_KEY;
5013 case RTE_FLOW_ITEM_TYPE_VXLAN:
5014 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
5018 last_item = MLX5_FLOW_LAYER_VXLAN;
5020 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
5021 ret = mlx5_flow_validate_item_vxlan_gpe(items,
5026 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
5028 case RTE_FLOW_ITEM_TYPE_GENEVE:
5029 ret = mlx5_flow_validate_item_geneve(items,
5034 last_item = MLX5_FLOW_LAYER_GENEVE;
5036 case RTE_FLOW_ITEM_TYPE_MPLS:
5037 ret = mlx5_flow_validate_item_mpls(dev, items,
5042 last_item = MLX5_FLOW_LAYER_MPLS;
5045 case RTE_FLOW_ITEM_TYPE_MARK:
5046 ret = flow_dv_validate_item_mark(dev, items, attr,
5050 last_item = MLX5_FLOW_ITEM_MARK;
5052 case RTE_FLOW_ITEM_TYPE_META:
5053 ret = flow_dv_validate_item_meta(dev, items, attr,
5057 last_item = MLX5_FLOW_ITEM_METADATA;
5059 case RTE_FLOW_ITEM_TYPE_ICMP:
5060 ret = mlx5_flow_validate_item_icmp(items, item_flags,
5065 last_item = MLX5_FLOW_LAYER_ICMP;
5067 case RTE_FLOW_ITEM_TYPE_ICMP6:
5068 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
5073 item_ipv6_proto = IPPROTO_ICMPV6;
5074 last_item = MLX5_FLOW_LAYER_ICMP6;
5076 case RTE_FLOW_ITEM_TYPE_TAG:
5077 ret = flow_dv_validate_item_tag(dev, items,
5081 last_item = MLX5_FLOW_ITEM_TAG;
5083 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
5084 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
5086 case RTE_FLOW_ITEM_TYPE_GTP:
5087 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
5091 last_item = MLX5_FLOW_LAYER_GTP;
5094 return rte_flow_error_set(error, ENOTSUP,
5095 RTE_FLOW_ERROR_TYPE_ITEM,
5096 NULL, "item not supported");
5098 item_flags |= last_item;
5100 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5101 int type = actions->type;
5102 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5103 return rte_flow_error_set(error, ENOTSUP,
5104 RTE_FLOW_ERROR_TYPE_ACTION,
5105 actions, "too many actions");
5107 case RTE_FLOW_ACTION_TYPE_VOID:
5109 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5110 ret = flow_dv_validate_action_port_id(dev,
5117 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5120 case RTE_FLOW_ACTION_TYPE_FLAG:
5121 ret = flow_dv_validate_action_flag(dev, action_flags,
5125 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
5126 /* Count all modify-header actions as one. */
5127 if (!(action_flags &
5128 MLX5_FLOW_MODIFY_HDR_ACTIONS))
5130 action_flags |= MLX5_FLOW_ACTION_FLAG |
5131 MLX5_FLOW_ACTION_MARK_EXT;
5133 action_flags |= MLX5_FLOW_ACTION_FLAG;
5136 rw_act_num += MLX5_ACT_NUM_SET_MARK;
5138 case RTE_FLOW_ACTION_TYPE_MARK:
5139 ret = flow_dv_validate_action_mark(dev, actions,
5144 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
5145 /* Count all modify-header actions as one. */
5146 if (!(action_flags &
5147 MLX5_FLOW_MODIFY_HDR_ACTIONS))
5149 action_flags |= MLX5_FLOW_ACTION_MARK |
5150 MLX5_FLOW_ACTION_MARK_EXT;
5152 action_flags |= MLX5_FLOW_ACTION_MARK;
5155 rw_act_num += MLX5_ACT_NUM_SET_MARK;
5157 case RTE_FLOW_ACTION_TYPE_SET_META:
5158 ret = flow_dv_validate_action_set_meta(dev, actions,
5163 /* Count all modify-header actions as one action. */
5164 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5166 action_flags |= MLX5_FLOW_ACTION_SET_META;
5167 rw_act_num += MLX5_ACT_NUM_SET_META;
5169 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5170 ret = flow_dv_validate_action_set_tag(dev, actions,
5175 /* Count all modify-header actions as one action. */
5176 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5178 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
5179 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5181 case RTE_FLOW_ACTION_TYPE_DROP:
5182 ret = mlx5_flow_validate_action_drop(action_flags,
5186 action_flags |= MLX5_FLOW_ACTION_DROP;
5189 case RTE_FLOW_ACTION_TYPE_QUEUE:
5190 ret = mlx5_flow_validate_action_queue(actions,
5195 queue_index = ((const struct rte_flow_action_queue *)
5196 (actions->conf))->index;
5197 action_flags |= MLX5_FLOW_ACTION_QUEUE;
5200 case RTE_FLOW_ACTION_TYPE_RSS:
5201 rss = actions->conf;
5202 ret = mlx5_flow_validate_action_rss(actions,
5208 if (rss != NULL && rss->queue_num)
5209 queue_index = rss->queue[0];
5210 action_flags |= MLX5_FLOW_ACTION_RSS;
5213 case RTE_FLOW_ACTION_TYPE_COUNT:
5214 ret = flow_dv_validate_action_count(dev, error);
5217 action_flags |= MLX5_FLOW_ACTION_COUNT;
5220 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5221 if (flow_dv_validate_action_pop_vlan(dev,
5227 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
5230 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5231 ret = flow_dv_validate_action_push_vlan(dev,
5238 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
5241 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5242 ret = flow_dv_validate_action_set_vlan_pcp
5243 (action_flags, actions, error);
5246 /* Count PCP with push_vlan command. */
5247 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
5249 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5250 ret = flow_dv_validate_action_set_vlan_vid
5251 (item_flags, action_flags,
5255 /* Count VID with push_vlan command. */
5256 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
5257 rw_act_num += MLX5_ACT_NUM_MDF_VID;
5259 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5260 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5261 ret = flow_dv_validate_action_l2_encap(dev,
5267 action_flags |= MLX5_FLOW_ACTION_ENCAP;
5270 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5271 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5272 ret = flow_dv_validate_action_decap(dev, action_flags,
5276 action_flags |= MLX5_FLOW_ACTION_DECAP;
5279 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5280 ret = flow_dv_validate_action_raw_encap_decap
5281 (dev, NULL, actions->conf, attr, &action_flags,
5286 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5287 decap = actions->conf;
5288 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
5290 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5294 encap = actions->conf;
5296 ret = flow_dv_validate_action_raw_encap_decap
5298 decap ? decap : &empty_decap, encap,
5299 attr, &action_flags, &actions_n,
5304 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5305 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5306 ret = flow_dv_validate_action_modify_mac(action_flags,
5312 /* Count all modify-header actions as one action. */
5313 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5315 action_flags |= actions->type ==
5316 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
5317 MLX5_FLOW_ACTION_SET_MAC_SRC :
5318 MLX5_FLOW_ACTION_SET_MAC_DST;
5320 * Even if the source and destination MAC addresses have
5321 * overlap in the header with 4B alignment, the convert
5322 * function will handle them separately and 4 SW actions
5323 * will be created. And 2 actions will be added each
5324 * time no matter how many bytes of address will be set.
5326 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
5328 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5329 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5330 ret = flow_dv_validate_action_modify_ipv4(action_flags,
5336 /* Count all modify-header actions as one action. */
5337 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5339 action_flags |= actions->type ==
5340 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
5341 MLX5_FLOW_ACTION_SET_IPV4_SRC :
5342 MLX5_FLOW_ACTION_SET_IPV4_DST;
5343 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
5345 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5346 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5347 ret = flow_dv_validate_action_modify_ipv6(action_flags,
5353 if (item_ipv6_proto == IPPROTO_ICMPV6)
5354 return rte_flow_error_set(error, ENOTSUP,
5355 RTE_FLOW_ERROR_TYPE_ACTION,
5357 "Can't change header "
5358 "with ICMPv6 proto");
5359 /* Count all modify-header actions as one action. */
5360 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5362 action_flags |= actions->type ==
5363 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
5364 MLX5_FLOW_ACTION_SET_IPV6_SRC :
5365 MLX5_FLOW_ACTION_SET_IPV6_DST;
5366 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
5368 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5369 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5370 ret = flow_dv_validate_action_modify_tp(action_flags,
5376 /* Count all modify-header actions as one action. */
5377 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5379 action_flags |= actions->type ==
5380 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
5381 MLX5_FLOW_ACTION_SET_TP_SRC :
5382 MLX5_FLOW_ACTION_SET_TP_DST;
5383 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
5385 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5386 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5387 ret = flow_dv_validate_action_modify_ttl(action_flags,
5393 /* Count all modify-header actions as one action. */
5394 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5396 action_flags |= actions->type ==
5397 RTE_FLOW_ACTION_TYPE_SET_TTL ?
5398 MLX5_FLOW_ACTION_SET_TTL :
5399 MLX5_FLOW_ACTION_DEC_TTL;
5400 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
5402 case RTE_FLOW_ACTION_TYPE_JUMP:
5403 ret = flow_dv_validate_action_jump(actions,
5410 action_flags |= MLX5_FLOW_ACTION_JUMP;
5412 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5413 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5414 ret = flow_dv_validate_action_modify_tcp_seq
5421 /* Count all modify-header actions as one action. */
5422 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5424 action_flags |= actions->type ==
5425 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
5426 MLX5_FLOW_ACTION_INC_TCP_SEQ :
5427 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
5428 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
5430 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5431 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5432 ret = flow_dv_validate_action_modify_tcp_ack
5439 /* Count all modify-header actions as one action. */
5440 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5442 action_flags |= actions->type ==
5443 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
5444 MLX5_FLOW_ACTION_INC_TCP_ACK :
5445 MLX5_FLOW_ACTION_DEC_TCP_ACK;
5446 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
5448 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
5450 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
5451 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
5452 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5454 case RTE_FLOW_ACTION_TYPE_METER:
5455 ret = mlx5_flow_validate_action_meter(dev,
5461 action_flags |= MLX5_FLOW_ACTION_METER;
5463 /* Meter action will add one more TAG action. */
5464 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5466 case RTE_FLOW_ACTION_TYPE_AGE:
5467 ret = flow_dv_validate_action_age(action_flags,
5472 action_flags |= MLX5_FLOW_ACTION_AGE;
5475 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5476 ret = flow_dv_validate_action_modify_ipv4_dscp
5483 /* Count all modify-header actions as one action. */
5484 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5486 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
5487 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
5489 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5490 ret = flow_dv_validate_action_modify_ipv6_dscp
5497 /* Count all modify-header actions as one action. */
5498 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5500 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
5501 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
5504 return rte_flow_error_set(error, ENOTSUP,
5505 RTE_FLOW_ERROR_TYPE_ACTION,
5507 "action not supported");
5511 * Validate the drop action mutual exclusion with other actions.
5512 * Drop action is mutually-exclusive with any other action, except for
5515 if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
5516 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
5517 return rte_flow_error_set(error, EINVAL,
5518 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5519 "Drop action is mutually-exclusive "
5520 "with any other action, except for "
5522 /* Eswitch has few restrictions on using items and actions */
5523 if (attr->transfer) {
5524 if (!mlx5_flow_ext_mreg_supported(dev) &&
5525 action_flags & MLX5_FLOW_ACTION_FLAG)
5526 return rte_flow_error_set(error, ENOTSUP,
5527 RTE_FLOW_ERROR_TYPE_ACTION,
5529 "unsupported action FLAG");
5530 if (!mlx5_flow_ext_mreg_supported(dev) &&
5531 action_flags & MLX5_FLOW_ACTION_MARK)
5532 return rte_flow_error_set(error, ENOTSUP,
5533 RTE_FLOW_ERROR_TYPE_ACTION,
5535 "unsupported action MARK");
5536 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
5537 return rte_flow_error_set(error, ENOTSUP,
5538 RTE_FLOW_ERROR_TYPE_ACTION,
5540 "unsupported action QUEUE");
5541 if (action_flags & MLX5_FLOW_ACTION_RSS)
5542 return rte_flow_error_set(error, ENOTSUP,
5543 RTE_FLOW_ERROR_TYPE_ACTION,
5545 "unsupported action RSS");
5546 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5547 return rte_flow_error_set(error, EINVAL,
5548 RTE_FLOW_ERROR_TYPE_ACTION,
5550 "no fate action is found");
5552 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
5553 return rte_flow_error_set(error, EINVAL,
5554 RTE_FLOW_ERROR_TYPE_ACTION,
5556 "no fate action is found");
5558 /* Continue validation for Xcap actions.*/
5559 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) && (queue_index == 0xFFFF ||
5560 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5561 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5562 MLX5_FLOW_XCAP_ACTIONS)
5563 return rte_flow_error_set(error, ENOTSUP,
5564 RTE_FLOW_ERROR_TYPE_ACTION,
5565 NULL, "encap and decap "
5566 "combination aren't supported");
5567 if (!attr->transfer && attr->ingress && (action_flags &
5568 MLX5_FLOW_ACTION_ENCAP))
5569 return rte_flow_error_set(error, ENOTSUP,
5570 RTE_FLOW_ERROR_TYPE_ACTION,
5571 NULL, "encap is not supported"
5572 " for ingress traffic");
5574 /* Hairpin flow will add one more TAG action. */
5576 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5577 /* extra metadata enabled: one more TAG action will be add. */
5578 if (dev_conf->dv_flow_en &&
5579 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5580 mlx5_flow_ext_mreg_supported(dev))
5581 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5582 if ((uint32_t)rw_act_num >
5583 flow_dv_modify_hdr_action_max(dev, is_root)) {
5584 return rte_flow_error_set(error, ENOTSUP,
5585 RTE_FLOW_ERROR_TYPE_ACTION,
5586 NULL, "too many header modify"
5587 " actions to support");
5593 * Internal preparation function. Allocates the DV flow size,
5594 * this size is constant.
5597 * Pointer to the rte_eth_dev structure.
5599 * Pointer to the flow attributes.
5601 * Pointer to the list of items.
5602 * @param[in] actions
5603 * Pointer to the list of actions.
5605 * Pointer to the error structure.
5608 * Pointer to mlx5_flow object on success,
5609 * otherwise NULL and rte_errno is set.
5611 static struct mlx5_flow *
5612 flow_dv_prepare(struct rte_eth_dev *dev,
5613 const struct rte_flow_attr *attr __rte_unused,
5614 const struct rte_flow_item items[] __rte_unused,
5615 const struct rte_flow_action actions[] __rte_unused,
5616 struct rte_flow_error *error)
5618 uint32_t handle_idx = 0;
5619 struct mlx5_flow *dev_flow;
5620 struct mlx5_flow_handle *dev_handle;
5621 struct mlx5_priv *priv = dev->data->dev_private;
5623 /* In case of corrupting the memory. */
5624 if (priv->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
5625 rte_flow_error_set(error, ENOSPC,
5626 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5627 "not free temporary device flow");
5630 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
5633 rte_flow_error_set(error, ENOMEM,
5634 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5635 "not enough memory to create flow handle");
5638 /* No multi-thread supporting. */
5639 dev_flow = &((struct mlx5_flow *)priv->inter_flows)[priv->flow_idx++];
5640 dev_flow->handle = dev_handle;
5641 dev_flow->handle_idx = handle_idx;
5642 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
5644 * The matching value needs to be cleared to 0 before using. In the
5645 * past, it will be automatically cleared when using rte_*alloc
5646 * API. The time consumption will be almost the same as before.
5648 memset(dev_flow->dv.value.buf, 0, MLX5_ST_SZ_BYTES(fte_match_param));
5649 dev_flow->ingress = attr->ingress;
5650 dev_flow->dv.transfer = attr->transfer;
5654 #ifdef RTE_LIBRTE_MLX5_DEBUG
5656 * Sanity check for match mask and value. Similar to check_valid_spec() in
5657 * kernel driver. If unmasked bit is present in value, it returns failure.
5660 * pointer to match mask buffer.
5661 * @param match_value
5662 * pointer to match value buffer.
5665 * 0 if valid, -EINVAL otherwise.
5668 flow_dv_check_valid_spec(void *match_mask, void *match_value)
5670 uint8_t *m = match_mask;
5671 uint8_t *v = match_value;
5674 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
5677 "match_value differs from match_criteria"
5678 " %p[%u] != %p[%u]",
5679 match_value, i, match_mask, i);
5688 * Add match of ip_version.
5692 * @param[in] headers_v
5693 * Values header pointer.
5694 * @param[in] headers_m
5695 * Masks header pointer.
5696 * @param[in] ip_version
5697 * The IP version to set.
5700 flow_dv_set_match_ip_version(uint32_t group,
5706 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
5708 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
5710 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
5711 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
5712 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
5716 * Add Ethernet item to matcher and to the value.
5718 * @param[in, out] matcher
5720 * @param[in, out] key
5721 * Flow matcher value.
5723 * Flow pattern to translate.
5725 * Item is inner pattern.
5728 flow_dv_translate_item_eth(void *matcher, void *key,
5729 const struct rte_flow_item *item, int inner,
5732 const struct rte_flow_item_eth *eth_m = item->mask;
5733 const struct rte_flow_item_eth *eth_v = item->spec;
5734 const struct rte_flow_item_eth nic_mask = {
5735 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
5736 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
5737 .type = RTE_BE16(0xffff),
5749 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5751 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5753 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5755 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5757 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, dmac_47_16),
5758 ð_m->dst, sizeof(eth_m->dst));
5759 /* The value must be in the range of the mask. */
5760 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, dmac_47_16);
5761 for (i = 0; i < sizeof(eth_m->dst); ++i)
5762 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
5763 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, smac_47_16),
5764 ð_m->src, sizeof(eth_m->src));
5765 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, smac_47_16);
5766 /* The value must be in the range of the mask. */
5767 for (i = 0; i < sizeof(eth_m->dst); ++i)
5768 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
5770 /* When ethertype is present set mask for tagged VLAN. */
5771 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5772 /* Set value for tagged VLAN if ethertype is 802.1Q. */
5773 if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_VLAN) ||
5774 eth_v->type == RTE_BE16(RTE_ETHER_TYPE_QINQ)) {
5775 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag,
5777 /* Return here to avoid setting match on ethertype. */
5782 * HW supports match on one Ethertype, the Ethertype following the last
5783 * VLAN tag of the packet (see PRM).
5784 * Set match on ethertype only if ETH header is not followed by VLAN.
5785 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
5786 * ethertype, and use ip_version field instead.
5788 if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_IPV4) &&
5789 eth_m->type == 0xFFFF) {
5790 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
5791 } else if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_IPV6) &&
5792 eth_m->type == 0xFFFF) {
5793 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
5795 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
5796 rte_be_to_cpu_16(eth_m->type));
5797 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5799 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
5804 * Add VLAN item to matcher and to the value.
5806 * @param[in, out] dev_flow
5808 * @param[in, out] matcher
5810 * @param[in, out] key
5811 * Flow matcher value.
5813 * Flow pattern to translate.
5815 * Item is inner pattern.
5818 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
5819 void *matcher, void *key,
5820 const struct rte_flow_item *item,
5821 int inner, uint32_t group)
5823 const struct rte_flow_item_vlan *vlan_m = item->mask;
5824 const struct rte_flow_item_vlan *vlan_v = item->spec;
5831 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5833 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5835 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5837 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5839 * This is workaround, masks are not supported,
5840 * and pre-validated.
5843 dev_flow->handle->vf_vlan.tag =
5844 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
5847 * When VLAN item exists in flow, mark packet as tagged,
5848 * even if TCI is not specified.
5850 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5851 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
5855 vlan_m = &rte_flow_item_vlan_mask;
5856 tci_m = rte_be_to_cpu_16(vlan_m->tci);
5857 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
5858 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_vid, tci_m);
5859 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, tci_v);
5860 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_cfi, tci_m >> 12);
5861 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_cfi, tci_v >> 12);
5862 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_prio, tci_m >> 13);
5863 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, tci_v >> 13);
5865 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
5866 * ethertype, and use ip_version field instead.
5868 if (vlan_v->inner_type == RTE_BE16(RTE_ETHER_TYPE_IPV4) &&
5869 vlan_m->inner_type == 0xFFFF) {
5870 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
5871 } else if (vlan_v->inner_type == RTE_BE16(RTE_ETHER_TYPE_IPV6) &&
5872 vlan_m->inner_type == 0xFFFF) {
5873 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
5875 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
5876 rte_be_to_cpu_16(vlan_m->inner_type));
5877 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
5878 rte_be_to_cpu_16(vlan_m->inner_type &
5879 vlan_v->inner_type));
5884 * Add IPV4 item to matcher and to the value.
5886 * @param[in, out] matcher
5888 * @param[in, out] key
5889 * Flow matcher value.
5891 * Flow pattern to translate.
5892 * @param[in] item_flags
5893 * Bit-fields that holds the items detected until now.
5895 * Item is inner pattern.
5897 * The group to insert the rule.
5900 flow_dv_translate_item_ipv4(void *matcher, void *key,
5901 const struct rte_flow_item *item,
5902 const uint64_t item_flags,
5903 int inner, uint32_t group)
5905 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
5906 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
5907 const struct rte_flow_item_ipv4 nic_mask = {
5909 .src_addr = RTE_BE32(0xffffffff),
5910 .dst_addr = RTE_BE32(0xffffffff),
5911 .type_of_service = 0xff,
5912 .next_proto_id = 0xff,
5913 .time_to_live = 0xff,
5923 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5925 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5927 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5929 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5931 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
5933 * On outer header (which must contains L2), or inner header with L2,
5934 * set cvlan_tag mask bit to mark this packet as untagged.
5935 * This should be done even if item->spec is empty.
5937 if (!inner || item_flags & MLX5_FLOW_LAYER_INNER_L2)
5938 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5943 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5944 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
5945 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5946 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
5947 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
5948 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
5949 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5950 src_ipv4_src_ipv6.ipv4_layout.ipv4);
5951 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5952 src_ipv4_src_ipv6.ipv4_layout.ipv4);
5953 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
5954 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
5955 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
5956 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
5957 ipv4_m->hdr.type_of_service);
5958 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
5959 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
5960 ipv4_m->hdr.type_of_service >> 2);
5961 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
5962 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
5963 ipv4_m->hdr.next_proto_id);
5964 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
5965 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
5966 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
5967 ipv4_m->hdr.time_to_live);
5968 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
5969 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
5973 * Add IPV6 item to matcher and to the value.
5975 * @param[in, out] matcher
5977 * @param[in, out] key
5978 * Flow matcher value.
5980 * Flow pattern to translate.
5981 * @param[in] item_flags
5982 * Bit-fields that holds the items detected until now.
5984 * Item is inner pattern.
5986 * The group to insert the rule.
5989 flow_dv_translate_item_ipv6(void *matcher, void *key,
5990 const struct rte_flow_item *item,
5991 const uint64_t item_flags,
5992 int inner, uint32_t group)
5994 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
5995 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
5996 const struct rte_flow_item_ipv6 nic_mask = {
5999 "\xff\xff\xff\xff\xff\xff\xff\xff"
6000 "\xff\xff\xff\xff\xff\xff\xff\xff",
6002 "\xff\xff\xff\xff\xff\xff\xff\xff"
6003 "\xff\xff\xff\xff\xff\xff\xff\xff",
6004 .vtc_flow = RTE_BE32(0xffffffff),
6011 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6012 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6021 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6023 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6025 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6027 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6029 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
6031 * On outer header (which must contains L2), or inner header with L2,
6032 * set cvlan_tag mask bit to mark this packet as untagged.
6033 * This should be done even if item->spec is empty.
6035 if (!inner || item_flags & MLX5_FLOW_LAYER_INNER_L2)
6036 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
6041 size = sizeof(ipv6_m->hdr.dst_addr);
6042 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6043 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
6044 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6045 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
6046 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
6047 for (i = 0; i < size; ++i)
6048 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
6049 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6050 src_ipv4_src_ipv6.ipv6_layout.ipv6);
6051 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6052 src_ipv4_src_ipv6.ipv6_layout.ipv6);
6053 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
6054 for (i = 0; i < size; ++i)
6055 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
6057 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
6058 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
6059 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
6060 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
6061 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
6062 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
6065 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
6067 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
6070 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
6072 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
6076 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
6078 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6079 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
6081 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
6082 ipv6_m->hdr.hop_limits);
6083 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
6084 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
6088 * Add TCP item to matcher and to the value.
6090 * @param[in, out] matcher
6092 * @param[in, out] key
6093 * Flow matcher value.
6095 * Flow pattern to translate.
6097 * Item is inner pattern.
6100 flow_dv_translate_item_tcp(void *matcher, void *key,
6101 const struct rte_flow_item *item,
6104 const struct rte_flow_item_tcp *tcp_m = item->mask;
6105 const struct rte_flow_item_tcp *tcp_v = item->spec;
6110 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6112 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6114 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6116 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6118 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6119 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
6123 tcp_m = &rte_flow_item_tcp_mask;
6124 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
6125 rte_be_to_cpu_16(tcp_m->hdr.src_port));
6126 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
6127 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
6128 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
6129 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
6130 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
6131 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
6132 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
6133 tcp_m->hdr.tcp_flags);
6134 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
6135 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
6139 * Add UDP item to matcher and to the value.
6141 * @param[in, out] matcher
6143 * @param[in, out] key
6144 * Flow matcher value.
6146 * Flow pattern to translate.
6148 * Item is inner pattern.
6151 flow_dv_translate_item_udp(void *matcher, void *key,
6152 const struct rte_flow_item *item,
6155 const struct rte_flow_item_udp *udp_m = item->mask;
6156 const struct rte_flow_item_udp *udp_v = item->spec;
6161 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6163 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6165 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6167 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6169 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6170 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
6174 udp_m = &rte_flow_item_udp_mask;
6175 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
6176 rte_be_to_cpu_16(udp_m->hdr.src_port));
6177 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
6178 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
6179 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
6180 rte_be_to_cpu_16(udp_m->hdr.dst_port));
6181 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
6182 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
6186 * Add GRE optional Key item to matcher and to the value.
6188 * @param[in, out] matcher
6190 * @param[in, out] key
6191 * Flow matcher value.
6193 * Flow pattern to translate.
6195 * Item is inner pattern.
6198 flow_dv_translate_item_gre_key(void *matcher, void *key,
6199 const struct rte_flow_item *item)
6201 const rte_be32_t *key_m = item->mask;
6202 const rte_be32_t *key_v = item->spec;
6203 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6204 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6205 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6207 /* GRE K bit must be on and should already be validated */
6208 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
6209 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
6213 key_m = &gre_key_default_mask;
6214 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
6215 rte_be_to_cpu_32(*key_m) >> 8);
6216 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
6217 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
6218 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
6219 rte_be_to_cpu_32(*key_m) & 0xFF);
6220 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
6221 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
6225 * Add GRE item to matcher and to the value.
6227 * @param[in, out] matcher
6229 * @param[in, out] key
6230 * Flow matcher value.
6232 * Flow pattern to translate.
6234 * Item is inner pattern.
6237 flow_dv_translate_item_gre(void *matcher, void *key,
6238 const struct rte_flow_item *item,
6241 const struct rte_flow_item_gre *gre_m = item->mask;
6242 const struct rte_flow_item_gre *gre_v = item->spec;
6245 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6246 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6253 uint16_t s_present:1;
6254 uint16_t k_present:1;
6255 uint16_t rsvd_bit1:1;
6256 uint16_t c_present:1;
6260 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
6263 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6265 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6267 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6269 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6271 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6272 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
6276 gre_m = &rte_flow_item_gre_mask;
6277 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
6278 rte_be_to_cpu_16(gre_m->protocol));
6279 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
6280 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
6281 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
6282 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
6283 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
6284 gre_crks_rsvd0_ver_m.c_present);
6285 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
6286 gre_crks_rsvd0_ver_v.c_present &
6287 gre_crks_rsvd0_ver_m.c_present);
6288 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
6289 gre_crks_rsvd0_ver_m.k_present);
6290 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
6291 gre_crks_rsvd0_ver_v.k_present &
6292 gre_crks_rsvd0_ver_m.k_present);
6293 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
6294 gre_crks_rsvd0_ver_m.s_present);
6295 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
6296 gre_crks_rsvd0_ver_v.s_present &
6297 gre_crks_rsvd0_ver_m.s_present);
6301 * Add NVGRE item to matcher and to the value.
6303 * @param[in, out] matcher
6305 * @param[in, out] key
6306 * Flow matcher value.
6308 * Flow pattern to translate.
6310 * Item is inner pattern.
6313 flow_dv_translate_item_nvgre(void *matcher, void *key,
6314 const struct rte_flow_item *item,
6317 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
6318 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
6319 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6320 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6321 const char *tni_flow_id_m = (const char *)nvgre_m->tni;
6322 const char *tni_flow_id_v = (const char *)nvgre_v->tni;
6328 /* For NVGRE, GRE header fields must be set with defined values. */
6329 const struct rte_flow_item_gre gre_spec = {
6330 .c_rsvd0_ver = RTE_BE16(0x2000),
6331 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
6333 const struct rte_flow_item_gre gre_mask = {
6334 .c_rsvd0_ver = RTE_BE16(0xB000),
6335 .protocol = RTE_BE16(UINT16_MAX),
6337 const struct rte_flow_item gre_item = {
6342 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
6346 nvgre_m = &rte_flow_item_nvgre_mask;
6347 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
6348 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
6349 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
6350 memcpy(gre_key_m, tni_flow_id_m, size);
6351 for (i = 0; i < size; ++i)
6352 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
6356 * Add VXLAN item to matcher and to the value.
6358 * @param[in, out] matcher
6360 * @param[in, out] key
6361 * Flow matcher value.
6363 * Flow pattern to translate.
6365 * Item is inner pattern.
6368 flow_dv_translate_item_vxlan(void *matcher, void *key,
6369 const struct rte_flow_item *item,
6372 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
6373 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
6376 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6377 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6385 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6387 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6389 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6391 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6393 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
6394 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
6395 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6396 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6397 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6402 vxlan_m = &rte_flow_item_vxlan_mask;
6403 size = sizeof(vxlan_m->vni);
6404 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
6405 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
6406 memcpy(vni_m, vxlan_m->vni, size);
6407 for (i = 0; i < size; ++i)
6408 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
6412 * Add VXLAN-GPE item to matcher and to the value.
6414 * @param[in, out] matcher
6416 * @param[in, out] key
6417 * Flow matcher value.
6419 * Flow pattern to translate.
6421 * Item is inner pattern.
6425 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
6426 const struct rte_flow_item *item, int inner)
6428 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
6429 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
6433 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
6435 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6441 uint8_t flags_m = 0xff;
6442 uint8_t flags_v = 0xc;
6445 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6447 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6449 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6451 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6453 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
6454 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
6455 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6456 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6457 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6462 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
6463 size = sizeof(vxlan_m->vni);
6464 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
6465 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
6466 memcpy(vni_m, vxlan_m->vni, size);
6467 for (i = 0; i < size; ++i)
6468 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
6469 if (vxlan_m->flags) {
6470 flags_m = vxlan_m->flags;
6471 flags_v = vxlan_v->flags;
6473 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
6474 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
6475 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
6477 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
6482 * Add Geneve item to matcher and to the value.
6484 * @param[in, out] matcher
6486 * @param[in, out] key
6487 * Flow matcher value.
6489 * Flow pattern to translate.
6491 * Item is inner pattern.
6495 flow_dv_translate_item_geneve(void *matcher, void *key,
6496 const struct rte_flow_item *item, int inner)
6498 const struct rte_flow_item_geneve *geneve_m = item->mask;
6499 const struct rte_flow_item_geneve *geneve_v = item->spec;
6502 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6503 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6512 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6514 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6516 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6518 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6520 dport = MLX5_UDP_PORT_GENEVE;
6521 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6522 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6523 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6528 geneve_m = &rte_flow_item_geneve_mask;
6529 size = sizeof(geneve_m->vni);
6530 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
6531 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
6532 memcpy(vni_m, geneve_m->vni, size);
6533 for (i = 0; i < size; ++i)
6534 vni_v[i] = vni_m[i] & geneve_v->vni[i];
6535 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
6536 rte_be_to_cpu_16(geneve_m->protocol));
6537 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
6538 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
6539 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
6540 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
6541 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
6542 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
6543 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
6544 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
6545 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
6546 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
6547 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
6548 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
6549 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
6553 * Add MPLS item to matcher and to the value.
6555 * @param[in, out] matcher
6557 * @param[in, out] key
6558 * Flow matcher value.
6560 * Flow pattern to translate.
6561 * @param[in] prev_layer
6562 * The protocol layer indicated in previous item.
6564 * Item is inner pattern.
6567 flow_dv_translate_item_mpls(void *matcher, void *key,
6568 const struct rte_flow_item *item,
6569 uint64_t prev_layer,
6572 const uint32_t *in_mpls_m = item->mask;
6573 const uint32_t *in_mpls_v = item->spec;
6574 uint32_t *out_mpls_m = 0;
6575 uint32_t *out_mpls_v = 0;
6576 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6577 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6578 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
6580 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
6581 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
6582 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6584 switch (prev_layer) {
6585 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
6586 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
6587 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
6588 MLX5_UDP_PORT_MPLS);
6590 case MLX5_FLOW_LAYER_GRE:
6591 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
6592 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
6593 RTE_ETHER_TYPE_MPLS);
6596 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6597 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6604 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
6605 switch (prev_layer) {
6606 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
6608 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
6609 outer_first_mpls_over_udp);
6611 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
6612 outer_first_mpls_over_udp);
6614 case MLX5_FLOW_LAYER_GRE:
6616 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
6617 outer_first_mpls_over_gre);
6619 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
6620 outer_first_mpls_over_gre);
6623 /* Inner MPLS not over GRE is not supported. */
6626 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
6630 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
6636 if (out_mpls_m && out_mpls_v) {
6637 *out_mpls_m = *in_mpls_m;
6638 *out_mpls_v = *in_mpls_v & *in_mpls_m;
6643 * Add metadata register item to matcher
6645 * @param[in, out] matcher
6647 * @param[in, out] key
6648 * Flow matcher value.
6649 * @param[in] reg_type
6650 * Type of device metadata register
6657 flow_dv_match_meta_reg(void *matcher, void *key,
6658 enum modify_reg reg_type,
6659 uint32_t data, uint32_t mask)
6662 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
6664 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
6670 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
6671 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
6674 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
6675 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
6679 * The metadata register C0 field might be divided into
6680 * source vport index and META item value, we should set
6681 * this field according to specified mask, not as whole one.
6683 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
6685 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
6686 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
6689 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
6692 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
6693 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
6696 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
6697 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
6700 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
6701 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
6704 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
6705 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
6708 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
6709 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
6712 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
6713 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
6716 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
6717 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
6726 * Add MARK item to matcher
6729 * The device to configure through.
6730 * @param[in, out] matcher
6732 * @param[in, out] key
6733 * Flow matcher value.
6735 * Flow pattern to translate.
6738 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
6739 void *matcher, void *key,
6740 const struct rte_flow_item *item)
6742 struct mlx5_priv *priv = dev->data->dev_private;
6743 const struct rte_flow_item_mark *mark;
6747 mark = item->mask ? (const void *)item->mask :
6748 &rte_flow_item_mark_mask;
6749 mask = mark->id & priv->sh->dv_mark_mask;
6750 mark = (const void *)item->spec;
6752 value = mark->id & priv->sh->dv_mark_mask & mask;
6754 enum modify_reg reg;
6756 /* Get the metadata register index for the mark. */
6757 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
6758 MLX5_ASSERT(reg > 0);
6759 if (reg == REG_C_0) {
6760 struct mlx5_priv *priv = dev->data->dev_private;
6761 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6762 uint32_t shl_c0 = rte_bsf32(msk_c0);
6768 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6773 * Add META item to matcher
6776 * The devich to configure through.
6777 * @param[in, out] matcher
6779 * @param[in, out] key
6780 * Flow matcher value.
6782 * Attributes of flow that includes this item.
6784 * Flow pattern to translate.
6787 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
6788 void *matcher, void *key,
6789 const struct rte_flow_attr *attr,
6790 const struct rte_flow_item *item)
6792 const struct rte_flow_item_meta *meta_m;
6793 const struct rte_flow_item_meta *meta_v;
6795 meta_m = (const void *)item->mask;
6797 meta_m = &rte_flow_item_meta_mask;
6798 meta_v = (const void *)item->spec;
6801 uint32_t value = meta_v->data;
6802 uint32_t mask = meta_m->data;
6804 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
6808 * In datapath code there is no endianness
6809 * coversions for perfromance reasons, all
6810 * pattern conversions are done in rte_flow.
6812 value = rte_cpu_to_be_32(value);
6813 mask = rte_cpu_to_be_32(mask);
6814 if (reg == REG_C_0) {
6815 struct mlx5_priv *priv = dev->data->dev_private;
6816 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6817 uint32_t shl_c0 = rte_bsf32(msk_c0);
6818 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
6819 uint32_t shr_c0 = __builtin_clz(priv->sh->dv_meta_mask);
6826 MLX5_ASSERT(msk_c0);
6827 MLX5_ASSERT(!(~msk_c0 & mask));
6829 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6834 * Add vport metadata Reg C0 item to matcher
6836 * @param[in, out] matcher
6838 * @param[in, out] key
6839 * Flow matcher value.
6841 * Flow pattern to translate.
6844 flow_dv_translate_item_meta_vport(void *matcher, void *key,
6845 uint32_t value, uint32_t mask)
6847 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
6851 * Add tag item to matcher
6854 * The devich to configure through.
6855 * @param[in, out] matcher
6857 * @param[in, out] key
6858 * Flow matcher value.
6860 * Flow pattern to translate.
6863 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
6864 void *matcher, void *key,
6865 const struct rte_flow_item *item)
6867 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
6868 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
6869 uint32_t mask, value;
6872 value = tag_v->data;
6873 mask = tag_m ? tag_m->data : UINT32_MAX;
6874 if (tag_v->id == REG_C_0) {
6875 struct mlx5_priv *priv = dev->data->dev_private;
6876 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6877 uint32_t shl_c0 = rte_bsf32(msk_c0);
6883 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
6887 * Add TAG item to matcher
6890 * The devich to configure through.
6891 * @param[in, out] matcher
6893 * @param[in, out] key
6894 * Flow matcher value.
6896 * Flow pattern to translate.
6899 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
6900 void *matcher, void *key,
6901 const struct rte_flow_item *item)
6903 const struct rte_flow_item_tag *tag_v = item->spec;
6904 const struct rte_flow_item_tag *tag_m = item->mask;
6905 enum modify_reg reg;
6908 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
6909 /* Get the metadata register index for the tag. */
6910 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
6911 MLX5_ASSERT(reg > 0);
6912 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
6916 * Add source vport match to the specified matcher.
6918 * @param[in, out] matcher
6920 * @param[in, out] key
6921 * Flow matcher value.
6923 * Source vport value to match
6928 flow_dv_translate_item_source_vport(void *matcher, void *key,
6929 int16_t port, uint16_t mask)
6931 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6932 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6934 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
6935 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
6939 * Translate port-id item to eswitch match on port-id.
6942 * The devich to configure through.
6943 * @param[in, out] matcher
6945 * @param[in, out] key
6946 * Flow matcher value.
6948 * Flow pattern to translate.
6951 * 0 on success, a negative errno value otherwise.
6954 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
6955 void *key, const struct rte_flow_item *item)
6957 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
6958 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
6959 struct mlx5_priv *priv;
6962 mask = pid_m ? pid_m->id : 0xffff;
6963 id = pid_v ? pid_v->id : dev->data->port_id;
6964 priv = mlx5_port_to_eswitch_info(id, item == NULL);
6967 /* Translate to vport field or to metadata, depending on mode. */
6968 if (priv->vport_meta_mask)
6969 flow_dv_translate_item_meta_vport(matcher, key,
6970 priv->vport_meta_tag,
6971 priv->vport_meta_mask);
6973 flow_dv_translate_item_source_vport(matcher, key,
6974 priv->vport_id, mask);
6979 * Add ICMP6 item to matcher and to the value.
6981 * @param[in, out] matcher
6983 * @param[in, out] key
6984 * Flow matcher value.
6986 * Flow pattern to translate.
6988 * Item is inner pattern.
6991 flow_dv_translate_item_icmp6(void *matcher, void *key,
6992 const struct rte_flow_item *item,
6995 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
6996 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
6999 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7001 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7003 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7005 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7007 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7009 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7011 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
7012 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
7016 icmp6_m = &rte_flow_item_icmp6_mask;
7018 * Force flow only to match the non-fragmented IPv6 ICMPv6 packets.
7019 * If only the protocol is specified, no need to match the frag.
7021 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
7022 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
7023 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
7024 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
7025 icmp6_v->type & icmp6_m->type);
7026 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
7027 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
7028 icmp6_v->code & icmp6_m->code);
7032 * Add ICMP item to matcher and to the value.
7034 * @param[in, out] matcher
7036 * @param[in, out] key
7037 * Flow matcher value.
7039 * Flow pattern to translate.
7041 * Item is inner pattern.
7044 flow_dv_translate_item_icmp(void *matcher, void *key,
7045 const struct rte_flow_item *item,
7048 const struct rte_flow_item_icmp *icmp_m = item->mask;
7049 const struct rte_flow_item_icmp *icmp_v = item->spec;
7052 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7054 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7056 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7058 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7060 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7062 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7064 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
7065 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
7069 icmp_m = &rte_flow_item_icmp_mask;
7071 * Force flow only to match the non-fragmented IPv4 ICMP packets.
7072 * If only the protocol is specified, no need to match the frag.
7074 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
7075 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
7076 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
7077 icmp_m->hdr.icmp_type);
7078 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
7079 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
7080 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
7081 icmp_m->hdr.icmp_code);
7082 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
7083 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
7087 * Add GTP item to matcher and to the value.
7089 * @param[in, out] matcher
7091 * @param[in, out] key
7092 * Flow matcher value.
7094 * Flow pattern to translate.
7096 * Item is inner pattern.
7099 flow_dv_translate_item_gtp(void *matcher, void *key,
7100 const struct rte_flow_item *item, int inner)
7102 const struct rte_flow_item_gtp *gtp_m = item->mask;
7103 const struct rte_flow_item_gtp *gtp_v = item->spec;
7106 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7108 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7109 uint16_t dport = RTE_GTPU_UDP_PORT;
7112 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7114 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7116 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7118 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7120 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
7121 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
7122 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
7127 gtp_m = &rte_flow_item_gtp_mask;
7128 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
7129 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
7130 gtp_v->msg_type & gtp_m->msg_type);
7131 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
7132 rte_be_to_cpu_32(gtp_m->teid));
7133 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
7134 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
7137 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
7139 #define HEADER_IS_ZERO(match_criteria, headers) \
7140 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
7141 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
7144 * Calculate flow matcher enable bitmap.
7146 * @param match_criteria
7147 * Pointer to flow matcher criteria.
7150 * Bitmap of enabled fields.
7153 flow_dv_matcher_enable(uint32_t *match_criteria)
7155 uint8_t match_criteria_enable;
7157 match_criteria_enable =
7158 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
7159 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
7160 match_criteria_enable |=
7161 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
7162 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
7163 match_criteria_enable |=
7164 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
7165 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
7166 match_criteria_enable |=
7167 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
7168 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
7169 match_criteria_enable |=
7170 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
7171 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
7172 return match_criteria_enable;
7179 * @param[in, out] dev
7180 * Pointer to rte_eth_dev structure.
7181 * @param[in] table_id
7184 * Direction of the table.
7185 * @param[in] transfer
7186 * E-Switch or NIC flow.
7188 * pointer to error structure.
7191 * Returns tables resource based on the index, NULL in case of failed.
7193 static struct mlx5_flow_tbl_resource *
7194 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
7195 uint32_t table_id, uint8_t egress,
7197 struct rte_flow_error *error)
7199 struct mlx5_priv *priv = dev->data->dev_private;
7200 struct mlx5_ibv_shared *sh = priv->sh;
7201 struct mlx5_flow_tbl_resource *tbl;
7202 union mlx5_flow_tbl_key table_key = {
7204 .table_id = table_id,
7206 .domain = !!transfer,
7207 .direction = !!egress,
7210 struct mlx5_hlist_entry *pos = mlx5_hlist_lookup(sh->flow_tbls,
7212 struct mlx5_flow_tbl_data_entry *tbl_data;
7218 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
7220 tbl = &tbl_data->tbl;
7221 rte_atomic32_inc(&tbl->refcnt);
7224 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
7226 rte_flow_error_set(error, ENOMEM,
7227 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7229 "cannot allocate flow table data entry");
7232 tbl_data->idx = idx;
7233 tbl = &tbl_data->tbl;
7234 pos = &tbl_data->entry;
7236 domain = sh->fdb_domain;
7238 domain = sh->tx_domain;
7240 domain = sh->rx_domain;
7241 tbl->obj = mlx5_glue->dr_create_flow_tbl(domain, table_id);
7243 rte_flow_error_set(error, ENOMEM,
7244 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7245 NULL, "cannot create flow table object");
7246 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
7250 * No multi-threads now, but still better to initialize the reference
7251 * count before insert it into the hash list.
7253 rte_atomic32_init(&tbl->refcnt);
7254 /* Jump action reference count is initialized here. */
7255 rte_atomic32_init(&tbl_data->jump.refcnt);
7256 pos->key = table_key.v64;
7257 ret = mlx5_hlist_insert(sh->flow_tbls, pos);
7259 rte_flow_error_set(error, -ret,
7260 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7261 "cannot insert flow table data entry");
7262 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
7263 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
7265 rte_atomic32_inc(&tbl->refcnt);
7270 * Release a flow table.
7273 * Pointer to rte_eth_dev structure.
7275 * Table resource to be released.
7278 * Returns 0 if table was released, else return 1;
7281 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
7282 struct mlx5_flow_tbl_resource *tbl)
7284 struct mlx5_priv *priv = dev->data->dev_private;
7285 struct mlx5_ibv_shared *sh = priv->sh;
7286 struct mlx5_flow_tbl_data_entry *tbl_data =
7287 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
7291 if (rte_atomic32_dec_and_test(&tbl->refcnt)) {
7292 struct mlx5_hlist_entry *pos = &tbl_data->entry;
7294 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
7296 /* remove the entry from the hash list and free memory. */
7297 mlx5_hlist_remove(sh->flow_tbls, pos);
7298 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_JUMP],
7306 * Register the flow matcher.
7308 * @param[in, out] dev
7309 * Pointer to rte_eth_dev structure.
7310 * @param[in, out] matcher
7311 * Pointer to flow matcher.
7312 * @param[in, out] key
7313 * Pointer to flow table key.
7314 * @parm[in, out] dev_flow
7315 * Pointer to the dev_flow.
7317 * pointer to error structure.
7320 * 0 on success otherwise -errno and errno is set.
7323 flow_dv_matcher_register(struct rte_eth_dev *dev,
7324 struct mlx5_flow_dv_matcher *matcher,
7325 union mlx5_flow_tbl_key *key,
7326 struct mlx5_flow *dev_flow,
7327 struct rte_flow_error *error)
7329 struct mlx5_priv *priv = dev->data->dev_private;
7330 struct mlx5_ibv_shared *sh = priv->sh;
7331 struct mlx5_flow_dv_matcher *cache_matcher;
7332 struct mlx5dv_flow_matcher_attr dv_attr = {
7333 .type = IBV_FLOW_ATTR_NORMAL,
7334 .match_mask = (void *)&matcher->mask,
7336 struct mlx5_flow_tbl_resource *tbl;
7337 struct mlx5_flow_tbl_data_entry *tbl_data;
7339 tbl = flow_dv_tbl_resource_get(dev, key->table_id, key->direction,
7340 key->domain, error);
7342 return -rte_errno; /* No need to refill the error info */
7343 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
7344 /* Lookup from cache. */
7345 LIST_FOREACH(cache_matcher, &tbl_data->matchers, next) {
7346 if (matcher->crc == cache_matcher->crc &&
7347 matcher->priority == cache_matcher->priority &&
7348 !memcmp((const void *)matcher->mask.buf,
7349 (const void *)cache_matcher->mask.buf,
7350 cache_matcher->mask.size)) {
7352 "%s group %u priority %hd use %s "
7353 "matcher %p: refcnt %d++",
7354 key->domain ? "FDB" : "NIC", key->table_id,
7355 cache_matcher->priority,
7356 key->direction ? "tx" : "rx",
7357 (void *)cache_matcher,
7358 rte_atomic32_read(&cache_matcher->refcnt));
7359 rte_atomic32_inc(&cache_matcher->refcnt);
7360 dev_flow->handle->dvh.matcher = cache_matcher;
7361 /* old matcher should not make the table ref++. */
7362 flow_dv_tbl_resource_release(dev, tbl);
7366 /* Register new matcher. */
7367 cache_matcher = rte_calloc(__func__, 1, sizeof(*cache_matcher), 0);
7368 if (!cache_matcher) {
7369 flow_dv_tbl_resource_release(dev, tbl);
7370 return rte_flow_error_set(error, ENOMEM,
7371 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7372 "cannot allocate matcher memory");
7374 *cache_matcher = *matcher;
7375 dv_attr.match_criteria_enable =
7376 flow_dv_matcher_enable(cache_matcher->mask.buf);
7377 dv_attr.priority = matcher->priority;
7379 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
7380 cache_matcher->matcher_object =
7381 mlx5_glue->dv_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj);
7382 if (!cache_matcher->matcher_object) {
7383 rte_free(cache_matcher);
7384 #ifdef HAVE_MLX5DV_DR
7385 flow_dv_tbl_resource_release(dev, tbl);
7387 return rte_flow_error_set(error, ENOMEM,
7388 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7389 NULL, "cannot create matcher");
7391 /* Save the table information */
7392 cache_matcher->tbl = tbl;
7393 rte_atomic32_init(&cache_matcher->refcnt);
7394 /* only matcher ref++, table ref++ already done above in get API. */
7395 rte_atomic32_inc(&cache_matcher->refcnt);
7396 LIST_INSERT_HEAD(&tbl_data->matchers, cache_matcher, next);
7397 dev_flow->handle->dvh.matcher = cache_matcher;
7398 DRV_LOG(DEBUG, "%s group %u priority %hd new %s matcher %p: refcnt %d",
7399 key->domain ? "FDB" : "NIC", key->table_id,
7400 cache_matcher->priority,
7401 key->direction ? "tx" : "rx", (void *)cache_matcher,
7402 rte_atomic32_read(&cache_matcher->refcnt));
7407 * Find existing tag resource or create and register a new one.
7409 * @param dev[in, out]
7410 * Pointer to rte_eth_dev structure.
7411 * @param[in, out] tag_be24
7412 * Tag value in big endian then R-shift 8.
7413 * @parm[in, out] dev_flow
7414 * Pointer to the dev_flow.
7416 * pointer to error structure.
7419 * 0 on success otherwise -errno and errno is set.
7422 flow_dv_tag_resource_register
7423 (struct rte_eth_dev *dev,
7425 struct mlx5_flow *dev_flow,
7426 struct rte_flow_error *error)
7428 struct mlx5_priv *priv = dev->data->dev_private;
7429 struct mlx5_ibv_shared *sh = priv->sh;
7430 struct mlx5_flow_dv_tag_resource *cache_resource;
7431 struct mlx5_hlist_entry *entry;
7433 /* Lookup a matching resource from cache. */
7434 entry = mlx5_hlist_lookup(sh->tag_table, (uint64_t)tag_be24);
7436 cache_resource = container_of
7437 (entry, struct mlx5_flow_dv_tag_resource, entry);
7438 rte_atomic32_inc(&cache_resource->refcnt);
7439 dev_flow->handle->dvh.rix_tag = cache_resource->idx;
7440 dev_flow->dv.tag_resource = cache_resource;
7441 DRV_LOG(DEBUG, "cached tag resource %p: refcnt now %d++",
7442 (void *)cache_resource,
7443 rte_atomic32_read(&cache_resource->refcnt));
7446 /* Register new resource. */
7447 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG],
7448 &dev_flow->handle->dvh.rix_tag);
7449 if (!cache_resource)
7450 return rte_flow_error_set(error, ENOMEM,
7451 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7452 "cannot allocate resource memory");
7453 cache_resource->entry.key = (uint64_t)tag_be24;
7454 cache_resource->action = mlx5_glue->dv_create_flow_action_tag(tag_be24);
7455 if (!cache_resource->action) {
7456 rte_free(cache_resource);
7457 return rte_flow_error_set(error, ENOMEM,
7458 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7459 NULL, "cannot create action");
7461 rte_atomic32_init(&cache_resource->refcnt);
7462 rte_atomic32_inc(&cache_resource->refcnt);
7463 if (mlx5_hlist_insert(sh->tag_table, &cache_resource->entry)) {
7464 mlx5_glue->destroy_flow_action(cache_resource->action);
7465 rte_free(cache_resource);
7466 return rte_flow_error_set(error, EEXIST,
7467 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7468 NULL, "cannot insert tag");
7470 dev_flow->dv.tag_resource = cache_resource;
7471 DRV_LOG(DEBUG, "new tag resource %p: refcnt now %d++",
7472 (void *)cache_resource,
7473 rte_atomic32_read(&cache_resource->refcnt));
7481 * Pointer to Ethernet device.
7486 * 1 while a reference on it exists, 0 when freed.
7489 flow_dv_tag_release(struct rte_eth_dev *dev,
7492 struct mlx5_priv *priv = dev->data->dev_private;
7493 struct mlx5_ibv_shared *sh = priv->sh;
7494 struct mlx5_flow_dv_tag_resource *tag;
7496 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
7499 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
7500 dev->data->port_id, (void *)tag,
7501 rte_atomic32_read(&tag->refcnt));
7502 if (rte_atomic32_dec_and_test(&tag->refcnt)) {
7503 claim_zero(mlx5_glue->destroy_flow_action(tag->action));
7504 mlx5_hlist_remove(sh->tag_table, &tag->entry);
7505 DRV_LOG(DEBUG, "port %u tag %p: removed",
7506 dev->data->port_id, (void *)tag);
7507 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
7514 * Translate port ID action to vport.
7517 * Pointer to rte_eth_dev structure.
7519 * Pointer to the port ID action.
7520 * @param[out] dst_port_id
7521 * The target port ID.
7523 * Pointer to the error structure.
7526 * 0 on success, a negative errno value otherwise and rte_errno is set.
7529 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
7530 const struct rte_flow_action *action,
7531 uint32_t *dst_port_id,
7532 struct rte_flow_error *error)
7535 struct mlx5_priv *priv;
7536 const struct rte_flow_action_port_id *conf =
7537 (const struct rte_flow_action_port_id *)action->conf;
7539 port = conf->original ? dev->data->port_id : conf->id;
7540 priv = mlx5_port_to_eswitch_info(port, false);
7542 return rte_flow_error_set(error, -rte_errno,
7543 RTE_FLOW_ERROR_TYPE_ACTION,
7545 "No eswitch info was found for port");
7546 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
7548 * This parameter is transferred to
7549 * mlx5dv_dr_action_create_dest_ib_port().
7551 *dst_port_id = priv->ibv_port;
7554 * Legacy mode, no LAG configurations is supported.
7555 * This parameter is transferred to
7556 * mlx5dv_dr_action_create_dest_vport().
7558 *dst_port_id = priv->vport_id;
7564 * Create a counter with aging configuration.
7567 * Pointer to rte_eth_dev structure.
7569 * Pointer to the counter action configuration.
7571 * Pointer to the aging action configuration.
7574 * Index to flow counter on success, 0 otherwise.
7577 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
7578 struct mlx5_flow *dev_flow,
7579 const struct rte_flow_action_count *count,
7580 const struct rte_flow_action_age *age)
7583 struct mlx5_age_param *age_param;
7585 counter = flow_dv_counter_alloc(dev,
7586 count ? count->shared : 0,
7587 count ? count->id : 0,
7588 dev_flow->dv.group, !!age);
7589 if (!counter || age == NULL)
7591 age_param = flow_dv_counter_idx_get_age(dev, counter);
7593 * The counter age accuracy may have a bit delay. Have 3/4
7594 * second bias on the timeount in order to let it age in time.
7596 age_param->context = age->context ? age->context :
7597 (void *)(uintptr_t)(dev_flow->flow_idx);
7599 * The counter age accuracy may have a bit delay. Have 3/4
7600 * second bias on the timeount in order to let it age in time.
7602 age_param->timeout = age->timeout * 10 - MLX5_AGING_TIME_DELAY;
7603 /* Set expire time in unit of 0.1 sec. */
7604 age_param->port_id = dev->data->port_id;
7605 age_param->expire = age_param->timeout +
7606 rte_rdtsc() / (rte_get_tsc_hz() / 10);
7607 rte_atomic16_set(&age_param->state, AGE_CANDIDATE);
7611 * Add Tx queue matcher
7614 * Pointer to the dev struct.
7615 * @param[in, out] matcher
7617 * @param[in, out] key
7618 * Flow matcher value.
7620 * Flow pattern to translate.
7622 * Item is inner pattern.
7625 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
7626 void *matcher, void *key,
7627 const struct rte_flow_item *item)
7629 const struct mlx5_rte_flow_item_tx_queue *queue_m;
7630 const struct mlx5_rte_flow_item_tx_queue *queue_v;
7632 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7634 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7635 struct mlx5_txq_ctrl *txq;
7639 queue_m = (const void *)item->mask;
7642 queue_v = (const void *)item->spec;
7645 txq = mlx5_txq_get(dev, queue_v->queue);
7648 queue = txq->obj->sq->id;
7649 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
7650 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
7651 queue & queue_m->queue);
7652 mlx5_txq_release(dev, queue_v->queue);
7656 * Set the hash fields according to the @p flow information.
7658 * @param[in] dev_flow
7659 * Pointer to the mlx5_flow.
7660 * @param[in] rss_desc
7661 * Pointer to the mlx5_flow_rss_desc.
7664 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
7665 struct mlx5_flow_rss_desc *rss_desc)
7667 uint64_t items = dev_flow->handle->layers;
7669 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
7671 dev_flow->hash_fields = 0;
7672 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
7673 if (rss_desc->level >= 2) {
7674 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
7678 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
7679 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
7680 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
7681 if (rss_types & ETH_RSS_L3_SRC_ONLY)
7682 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
7683 else if (rss_types & ETH_RSS_L3_DST_ONLY)
7684 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
7686 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
7688 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
7689 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
7690 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
7691 if (rss_types & ETH_RSS_L3_SRC_ONLY)
7692 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
7693 else if (rss_types & ETH_RSS_L3_DST_ONLY)
7694 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
7696 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
7699 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
7700 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
7701 if (rss_types & ETH_RSS_UDP) {
7702 if (rss_types & ETH_RSS_L4_SRC_ONLY)
7703 dev_flow->hash_fields |=
7704 IBV_RX_HASH_SRC_PORT_UDP;
7705 else if (rss_types & ETH_RSS_L4_DST_ONLY)
7706 dev_flow->hash_fields |=
7707 IBV_RX_HASH_DST_PORT_UDP;
7709 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
7711 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
7712 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
7713 if (rss_types & ETH_RSS_TCP) {
7714 if (rss_types & ETH_RSS_L4_SRC_ONLY)
7715 dev_flow->hash_fields |=
7716 IBV_RX_HASH_SRC_PORT_TCP;
7717 else if (rss_types & ETH_RSS_L4_DST_ONLY)
7718 dev_flow->hash_fields |=
7719 IBV_RX_HASH_DST_PORT_TCP;
7721 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
7727 * Fill the flow with DV spec, lock free
7728 * (mutex should be acquired by caller).
7731 * Pointer to rte_eth_dev structure.
7732 * @param[in, out] dev_flow
7733 * Pointer to the sub flow.
7735 * Pointer to the flow attributes.
7737 * Pointer to the list of items.
7738 * @param[in] actions
7739 * Pointer to the list of actions.
7741 * Pointer to the error structure.
7744 * 0 on success, a negative errno value otherwise and rte_errno is set.
7747 __flow_dv_translate(struct rte_eth_dev *dev,
7748 struct mlx5_flow *dev_flow,
7749 const struct rte_flow_attr *attr,
7750 const struct rte_flow_item items[],
7751 const struct rte_flow_action actions[],
7752 struct rte_flow_error *error)
7754 struct mlx5_priv *priv = dev->data->dev_private;
7755 struct mlx5_dev_config *dev_conf = &priv->config;
7756 struct rte_flow *flow = dev_flow->flow;
7757 struct mlx5_flow_handle *handle = dev_flow->handle;
7758 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
7760 [!!priv->flow_nested_idx];
7761 uint64_t item_flags = 0;
7762 uint64_t last_item = 0;
7763 uint64_t action_flags = 0;
7764 uint64_t priority = attr->priority;
7765 struct mlx5_flow_dv_matcher matcher = {
7767 .size = sizeof(matcher.mask.buf),
7771 bool actions_end = false;
7773 struct mlx5_flow_dv_modify_hdr_resource res;
7774 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
7775 sizeof(struct mlx5_modification_cmd) *
7776 (MLX5_MAX_MODIFY_NUM + 1)];
7778 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
7779 const struct rte_flow_action_count *count = NULL;
7780 const struct rte_flow_action_age *age = NULL;
7781 union flow_dv_attr flow_attr = { .attr = 0 };
7783 union mlx5_flow_tbl_key tbl_key;
7784 uint32_t modify_action_position = UINT32_MAX;
7785 void *match_mask = matcher.mask.buf;
7786 void *match_value = dev_flow->dv.value.buf;
7787 uint8_t next_protocol = 0xff;
7788 struct rte_vlan_hdr vlan = { 0 };
7792 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
7793 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
7794 ret = mlx5_flow_group_to_table(attr, dev_flow->external, attr->group,
7795 !!priv->fdb_def_rule, &table, error);
7798 dev_flow->dv.group = table;
7800 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
7801 if (priority == MLX5_FLOW_PRIO_RSVD)
7802 priority = dev_conf->flow_prio - 1;
7803 /* number of actions must be set to 0 in case of dirty stack. */
7804 mhdr_res->actions_num = 0;
7805 for (; !actions_end ; actions++) {
7806 const struct rte_flow_action_queue *queue;
7807 const struct rte_flow_action_rss *rss;
7808 const struct rte_flow_action *action = actions;
7809 const uint8_t *rss_key;
7810 const struct rte_flow_action_jump *jump_data;
7811 const struct rte_flow_action_meter *mtr;
7812 struct mlx5_flow_tbl_resource *tbl;
7813 uint32_t port_id = 0;
7814 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
7815 int action_type = actions->type;
7816 const struct rte_flow_action *found_action = NULL;
7817 struct mlx5_flow_meter *fm = NULL;
7819 switch (action_type) {
7820 case RTE_FLOW_ACTION_TYPE_VOID:
7822 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7823 if (flow_dv_translate_action_port_id(dev, action,
7826 memset(&port_id_resource, 0, sizeof(port_id_resource));
7827 port_id_resource.port_id = port_id;
7828 if (flow_dv_port_id_action_resource_register
7829 (dev, &port_id_resource, dev_flow, error))
7831 MLX5_ASSERT(!handle->rix_port_id_action);
7832 dev_flow->dv.actions[actions_n++] =
7833 dev_flow->dv.port_id_action->action;
7834 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7835 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
7837 case RTE_FLOW_ACTION_TYPE_FLAG:
7838 action_flags |= MLX5_FLOW_ACTION_FLAG;
7839 dev_flow->handle->mark = 1;
7840 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7841 struct rte_flow_action_mark mark = {
7842 .id = MLX5_FLOW_MARK_DEFAULT,
7845 if (flow_dv_convert_action_mark(dev, &mark,
7849 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
7852 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
7854 * Only one FLAG or MARK is supported per device flow
7855 * right now. So the pointer to the tag resource must be
7856 * zero before the register process.
7858 MLX5_ASSERT(!handle->dvh.rix_tag);
7859 if (flow_dv_tag_resource_register(dev, tag_be,
7862 MLX5_ASSERT(dev_flow->dv.tag_resource);
7863 dev_flow->dv.actions[actions_n++] =
7864 dev_flow->dv.tag_resource->action;
7866 case RTE_FLOW_ACTION_TYPE_MARK:
7867 action_flags |= MLX5_FLOW_ACTION_MARK;
7868 dev_flow->handle->mark = 1;
7869 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7870 const struct rte_flow_action_mark *mark =
7871 (const struct rte_flow_action_mark *)
7874 if (flow_dv_convert_action_mark(dev, mark,
7878 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
7882 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7883 /* Legacy (non-extensive) MARK action. */
7884 tag_be = mlx5_flow_mark_set
7885 (((const struct rte_flow_action_mark *)
7886 (actions->conf))->id);
7887 MLX5_ASSERT(!handle->dvh.rix_tag);
7888 if (flow_dv_tag_resource_register(dev, tag_be,
7891 MLX5_ASSERT(dev_flow->dv.tag_resource);
7892 dev_flow->dv.actions[actions_n++] =
7893 dev_flow->dv.tag_resource->action;
7895 case RTE_FLOW_ACTION_TYPE_SET_META:
7896 if (flow_dv_convert_action_set_meta
7897 (dev, mhdr_res, attr,
7898 (const struct rte_flow_action_set_meta *)
7899 actions->conf, error))
7901 action_flags |= MLX5_FLOW_ACTION_SET_META;
7903 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7904 if (flow_dv_convert_action_set_tag
7906 (const struct rte_flow_action_set_tag *)
7907 actions->conf, error))
7909 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7911 case RTE_FLOW_ACTION_TYPE_DROP:
7912 action_flags |= MLX5_FLOW_ACTION_DROP;
7913 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
7915 case RTE_FLOW_ACTION_TYPE_QUEUE:
7916 queue = actions->conf;
7917 rss_desc->queue_num = 1;
7918 rss_desc->queue[0] = queue->index;
7919 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7920 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
7922 case RTE_FLOW_ACTION_TYPE_RSS:
7923 rss = actions->conf;
7924 memcpy(rss_desc->queue, rss->queue,
7925 rss->queue_num * sizeof(uint16_t));
7926 rss_desc->queue_num = rss->queue_num;
7927 /* NULL RSS key indicates default RSS key. */
7928 rss_key = !rss->key ? rss_hash_default_key : rss->key;
7929 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
7931 * rss->level and rss.types should be set in advance
7932 * when expanding items for RSS.
7934 action_flags |= MLX5_FLOW_ACTION_RSS;
7935 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
7937 case RTE_FLOW_ACTION_TYPE_AGE:
7938 case RTE_FLOW_ACTION_TYPE_COUNT:
7939 if (!dev_conf->devx) {
7940 return rte_flow_error_set
7942 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7944 "count action not supported");
7946 /* Save information first, will apply later. */
7947 if (actions->type == RTE_FLOW_ACTION_TYPE_COUNT)
7948 count = action->conf;
7951 action_flags |= MLX5_FLOW_ACTION_COUNT;
7953 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7954 dev_flow->dv.actions[actions_n++] =
7955 priv->sh->pop_vlan_action;
7956 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7958 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7959 if (!(action_flags &
7960 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
7961 flow_dev_get_vlan_info_from_items(items, &vlan);
7962 vlan.eth_proto = rte_be_to_cpu_16
7963 ((((const struct rte_flow_action_of_push_vlan *)
7964 actions->conf)->ethertype));
7965 found_action = mlx5_flow_find_action
7967 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
7969 mlx5_update_vlan_vid_pcp(found_action, &vlan);
7970 found_action = mlx5_flow_find_action
7972 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
7974 mlx5_update_vlan_vid_pcp(found_action, &vlan);
7975 if (flow_dv_create_action_push_vlan
7976 (dev, attr, &vlan, dev_flow, error))
7978 dev_flow->dv.actions[actions_n++] =
7979 dev_flow->dv.push_vlan_res->action;
7980 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7982 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7983 /* of_vlan_push action handled this action */
7984 MLX5_ASSERT(action_flags &
7985 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
7987 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7988 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7990 flow_dev_get_vlan_info_from_items(items, &vlan);
7991 mlx5_update_vlan_vid_pcp(actions, &vlan);
7992 /* If no VLAN push - this is a modify header action */
7993 if (flow_dv_convert_action_modify_vlan_vid
7994 (mhdr_res, actions, error))
7996 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7998 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7999 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8000 if (flow_dv_create_action_l2_encap(dev, actions,
8005 dev_flow->dv.actions[actions_n++] =
8006 dev_flow->dv.encap_decap->verbs_action;
8007 action_flags |= MLX5_FLOW_ACTION_ENCAP;
8009 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8010 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8011 if (flow_dv_create_action_l2_decap(dev, dev_flow,
8015 dev_flow->dv.actions[actions_n++] =
8016 dev_flow->dv.encap_decap->verbs_action;
8017 action_flags |= MLX5_FLOW_ACTION_DECAP;
8019 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8020 /* Handle encap with preceding decap. */
8021 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
8022 if (flow_dv_create_action_raw_encap
8023 (dev, actions, dev_flow, attr, error))
8025 dev_flow->dv.actions[actions_n++] =
8026 dev_flow->dv.encap_decap->verbs_action;
8028 /* Handle encap without preceding decap. */
8029 if (flow_dv_create_action_l2_encap
8030 (dev, actions, dev_flow, attr->transfer,
8033 dev_flow->dv.actions[actions_n++] =
8034 dev_flow->dv.encap_decap->verbs_action;
8036 action_flags |= MLX5_FLOW_ACTION_ENCAP;
8038 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8039 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
8041 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8042 if (flow_dv_create_action_l2_decap
8043 (dev, dev_flow, attr->transfer, error))
8045 dev_flow->dv.actions[actions_n++] =
8046 dev_flow->dv.encap_decap->verbs_action;
8048 /* If decap is followed by encap, handle it at encap. */
8049 action_flags |= MLX5_FLOW_ACTION_DECAP;
8051 case RTE_FLOW_ACTION_TYPE_JUMP:
8052 jump_data = action->conf;
8053 ret = mlx5_flow_group_to_table(attr, dev_flow->external,
8055 !!priv->fdb_def_rule,
8059 tbl = flow_dv_tbl_resource_get(dev, table,
8061 attr->transfer, error);
8063 return rte_flow_error_set
8065 RTE_FLOW_ERROR_TYPE_ACTION,
8067 "cannot create jump action.");
8068 if (flow_dv_jump_tbl_resource_register
8069 (dev, tbl, dev_flow, error)) {
8070 flow_dv_tbl_resource_release(dev, tbl);
8071 return rte_flow_error_set
8073 RTE_FLOW_ERROR_TYPE_ACTION,
8075 "cannot create jump action.");
8077 dev_flow->dv.actions[actions_n++] =
8078 dev_flow->dv.jump->action;
8079 action_flags |= MLX5_FLOW_ACTION_JUMP;
8080 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
8082 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8083 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8084 if (flow_dv_convert_action_modify_mac
8085 (mhdr_res, actions, error))
8087 action_flags |= actions->type ==
8088 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8089 MLX5_FLOW_ACTION_SET_MAC_SRC :
8090 MLX5_FLOW_ACTION_SET_MAC_DST;
8092 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8093 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8094 if (flow_dv_convert_action_modify_ipv4
8095 (mhdr_res, actions, error))
8097 action_flags |= actions->type ==
8098 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8099 MLX5_FLOW_ACTION_SET_IPV4_SRC :
8100 MLX5_FLOW_ACTION_SET_IPV4_DST;
8102 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8103 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8104 if (flow_dv_convert_action_modify_ipv6
8105 (mhdr_res, actions, error))
8107 action_flags |= actions->type ==
8108 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8109 MLX5_FLOW_ACTION_SET_IPV6_SRC :
8110 MLX5_FLOW_ACTION_SET_IPV6_DST;
8112 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8113 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8114 if (flow_dv_convert_action_modify_tp
8115 (mhdr_res, actions, items,
8116 &flow_attr, dev_flow, !!(action_flags &
8117 MLX5_FLOW_ACTION_DECAP), error))
8119 action_flags |= actions->type ==
8120 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8121 MLX5_FLOW_ACTION_SET_TP_SRC :
8122 MLX5_FLOW_ACTION_SET_TP_DST;
8124 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8125 if (flow_dv_convert_action_modify_dec_ttl
8126 (mhdr_res, items, &flow_attr, dev_flow,
8128 MLX5_FLOW_ACTION_DECAP), error))
8130 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
8132 case RTE_FLOW_ACTION_TYPE_SET_TTL:
8133 if (flow_dv_convert_action_modify_ttl
8134 (mhdr_res, actions, items, &flow_attr,
8135 dev_flow, !!(action_flags &
8136 MLX5_FLOW_ACTION_DECAP), error))
8138 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
8140 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8141 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8142 if (flow_dv_convert_action_modify_tcp_seq
8143 (mhdr_res, actions, error))
8145 action_flags |= actions->type ==
8146 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8147 MLX5_FLOW_ACTION_INC_TCP_SEQ :
8148 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8151 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8152 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8153 if (flow_dv_convert_action_modify_tcp_ack
8154 (mhdr_res, actions, error))
8156 action_flags |= actions->type ==
8157 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8158 MLX5_FLOW_ACTION_INC_TCP_ACK :
8159 MLX5_FLOW_ACTION_DEC_TCP_ACK;
8161 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8162 if (flow_dv_convert_action_set_reg
8163 (mhdr_res, actions, error))
8165 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8167 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8168 if (flow_dv_convert_action_copy_mreg
8169 (dev, mhdr_res, actions, error))
8171 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8173 case RTE_FLOW_ACTION_TYPE_METER:
8174 mtr = actions->conf;
8176 fm = mlx5_flow_meter_attach(priv, mtr->mtr_id,
8179 return rte_flow_error_set(error,
8181 RTE_FLOW_ERROR_TYPE_ACTION,
8184 "or invalid parameters");
8185 flow->meter = fm->idx;
8187 /* Set the meter action. */
8189 fm = mlx5_ipool_get(priv->sh->ipool
8190 [MLX5_IPOOL_MTR], flow->meter);
8192 return rte_flow_error_set(error,
8194 RTE_FLOW_ERROR_TYPE_ACTION,
8197 "or invalid parameters");
8199 dev_flow->dv.actions[actions_n++] =
8200 fm->mfts->meter_action;
8201 action_flags |= MLX5_FLOW_ACTION_METER;
8203 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8204 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
8207 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8209 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8210 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
8213 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8215 case RTE_FLOW_ACTION_TYPE_END:
8217 if (mhdr_res->actions_num) {
8218 /* create modify action if needed. */
8219 if (flow_dv_modify_hdr_resource_register
8220 (dev, mhdr_res, dev_flow, error))
8222 dev_flow->dv.actions[modify_action_position] =
8223 handle->dvh.modify_hdr->verbs_action;
8225 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
8227 flow_dv_translate_create_counter(dev,
8228 dev_flow, count, age);
8231 return rte_flow_error_set
8233 RTE_FLOW_ERROR_TYPE_ACTION,
8235 "cannot create counter"
8237 dev_flow->dv.actions[actions_n++] =
8238 (flow_dv_counter_get_by_idx(dev,
8239 flow->counter, NULL))->action;
8245 if (mhdr_res->actions_num &&
8246 modify_action_position == UINT32_MAX)
8247 modify_action_position = actions_n++;
8249 dev_flow->dv.actions_n = actions_n;
8250 dev_flow->act_flags = action_flags;
8251 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
8252 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
8253 int item_type = items->type;
8255 switch (item_type) {
8256 case RTE_FLOW_ITEM_TYPE_PORT_ID:
8257 flow_dv_translate_item_port_id(dev, match_mask,
8258 match_value, items);
8259 last_item = MLX5_FLOW_ITEM_PORT_ID;
8261 case RTE_FLOW_ITEM_TYPE_ETH:
8262 flow_dv_translate_item_eth(match_mask, match_value,
8264 dev_flow->dv.group);
8265 matcher.priority = MLX5_PRIORITY_MAP_L2;
8266 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
8267 MLX5_FLOW_LAYER_OUTER_L2;
8269 case RTE_FLOW_ITEM_TYPE_VLAN:
8270 flow_dv_translate_item_vlan(dev_flow,
8271 match_mask, match_value,
8273 dev_flow->dv.group);
8274 matcher.priority = MLX5_PRIORITY_MAP_L2;
8275 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
8276 MLX5_FLOW_LAYER_INNER_VLAN) :
8277 (MLX5_FLOW_LAYER_OUTER_L2 |
8278 MLX5_FLOW_LAYER_OUTER_VLAN);
8280 case RTE_FLOW_ITEM_TYPE_IPV4:
8281 mlx5_flow_tunnel_ip_check(items, next_protocol,
8282 &item_flags, &tunnel);
8283 flow_dv_translate_item_ipv4(match_mask, match_value,
8284 items, item_flags, tunnel,
8285 dev_flow->dv.group);
8286 matcher.priority = MLX5_PRIORITY_MAP_L3;
8287 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
8288 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
8289 if (items->mask != NULL &&
8290 ((const struct rte_flow_item_ipv4 *)
8291 items->mask)->hdr.next_proto_id) {
8293 ((const struct rte_flow_item_ipv4 *)
8294 (items->spec))->hdr.next_proto_id;
8296 ((const struct rte_flow_item_ipv4 *)
8297 (items->mask))->hdr.next_proto_id;
8299 /* Reset for inner layer. */
8300 next_protocol = 0xff;
8303 case RTE_FLOW_ITEM_TYPE_IPV6:
8304 mlx5_flow_tunnel_ip_check(items, next_protocol,
8305 &item_flags, &tunnel);
8306 flow_dv_translate_item_ipv6(match_mask, match_value,
8307 items, item_flags, tunnel,
8308 dev_flow->dv.group);
8309 matcher.priority = MLX5_PRIORITY_MAP_L3;
8310 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
8311 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
8312 if (items->mask != NULL &&
8313 ((const struct rte_flow_item_ipv6 *)
8314 items->mask)->hdr.proto) {
8316 ((const struct rte_flow_item_ipv6 *)
8317 items->spec)->hdr.proto;
8319 ((const struct rte_flow_item_ipv6 *)
8320 items->mask)->hdr.proto;
8322 /* Reset for inner layer. */
8323 next_protocol = 0xff;
8326 case RTE_FLOW_ITEM_TYPE_TCP:
8327 flow_dv_translate_item_tcp(match_mask, match_value,
8329 matcher.priority = MLX5_PRIORITY_MAP_L4;
8330 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
8331 MLX5_FLOW_LAYER_OUTER_L4_TCP;
8333 case RTE_FLOW_ITEM_TYPE_UDP:
8334 flow_dv_translate_item_udp(match_mask, match_value,
8336 matcher.priority = MLX5_PRIORITY_MAP_L4;
8337 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
8338 MLX5_FLOW_LAYER_OUTER_L4_UDP;
8340 case RTE_FLOW_ITEM_TYPE_GRE:
8341 flow_dv_translate_item_gre(match_mask, match_value,
8343 matcher.priority = rss_desc->level >= 2 ?
8344 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8345 last_item = MLX5_FLOW_LAYER_GRE;
8347 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
8348 flow_dv_translate_item_gre_key(match_mask,
8349 match_value, items);
8350 last_item = MLX5_FLOW_LAYER_GRE_KEY;
8352 case RTE_FLOW_ITEM_TYPE_NVGRE:
8353 flow_dv_translate_item_nvgre(match_mask, match_value,
8355 matcher.priority = rss_desc->level >= 2 ?
8356 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8357 last_item = MLX5_FLOW_LAYER_GRE;
8359 case RTE_FLOW_ITEM_TYPE_VXLAN:
8360 flow_dv_translate_item_vxlan(match_mask, match_value,
8362 matcher.priority = rss_desc->level >= 2 ?
8363 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8364 last_item = MLX5_FLOW_LAYER_VXLAN;
8366 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
8367 flow_dv_translate_item_vxlan_gpe(match_mask,
8370 matcher.priority = rss_desc->level >= 2 ?
8371 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8372 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
8374 case RTE_FLOW_ITEM_TYPE_GENEVE:
8375 flow_dv_translate_item_geneve(match_mask, match_value,
8377 matcher.priority = rss_desc->level >= 2 ?
8378 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8379 last_item = MLX5_FLOW_LAYER_GENEVE;
8381 case RTE_FLOW_ITEM_TYPE_MPLS:
8382 flow_dv_translate_item_mpls(match_mask, match_value,
8383 items, last_item, tunnel);
8384 matcher.priority = rss_desc->level >= 2 ?
8385 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8386 last_item = MLX5_FLOW_LAYER_MPLS;
8388 case RTE_FLOW_ITEM_TYPE_MARK:
8389 flow_dv_translate_item_mark(dev, match_mask,
8390 match_value, items);
8391 last_item = MLX5_FLOW_ITEM_MARK;
8393 case RTE_FLOW_ITEM_TYPE_META:
8394 flow_dv_translate_item_meta(dev, match_mask,
8395 match_value, attr, items);
8396 last_item = MLX5_FLOW_ITEM_METADATA;
8398 case RTE_FLOW_ITEM_TYPE_ICMP:
8399 flow_dv_translate_item_icmp(match_mask, match_value,
8401 last_item = MLX5_FLOW_LAYER_ICMP;
8403 case RTE_FLOW_ITEM_TYPE_ICMP6:
8404 flow_dv_translate_item_icmp6(match_mask, match_value,
8406 last_item = MLX5_FLOW_LAYER_ICMP6;
8408 case RTE_FLOW_ITEM_TYPE_TAG:
8409 flow_dv_translate_item_tag(dev, match_mask,
8410 match_value, items);
8411 last_item = MLX5_FLOW_ITEM_TAG;
8413 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8414 flow_dv_translate_mlx5_item_tag(dev, match_mask,
8415 match_value, items);
8416 last_item = MLX5_FLOW_ITEM_TAG;
8418 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
8419 flow_dv_translate_item_tx_queue(dev, match_mask,
8422 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
8424 case RTE_FLOW_ITEM_TYPE_GTP:
8425 flow_dv_translate_item_gtp(match_mask, match_value,
8427 matcher.priority = rss_desc->level >= 2 ?
8428 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8429 last_item = MLX5_FLOW_LAYER_GTP;
8434 item_flags |= last_item;
8437 * When E-Switch mode is enabled, we have two cases where we need to
8438 * set the source port manually.
8439 * The first one, is in case of Nic steering rule, and the second is
8440 * E-Switch rule where no port_id item was found. In both cases
8441 * the source port is set according the current port in use.
8443 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
8444 (priv->representor || priv->master)) {
8445 if (flow_dv_translate_item_port_id(dev, match_mask,
8449 #ifdef RTE_LIBRTE_MLX5_DEBUG
8450 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
8451 dev_flow->dv.value.buf));
8454 * Layers may be already initialized from prefix flow if this dev_flow
8455 * is the suffix flow.
8457 handle->layers |= item_flags;
8458 if (action_flags & MLX5_FLOW_ACTION_RSS)
8459 flow_dv_hashfields_set(dev_flow, rss_desc);
8460 /* Register matcher. */
8461 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
8463 matcher.priority = mlx5_flow_adjust_priority(dev, priority,
8465 /* reserved field no needs to be set to 0 here. */
8466 tbl_key.domain = attr->transfer;
8467 tbl_key.direction = attr->egress;
8468 tbl_key.table_id = dev_flow->dv.group;
8469 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow, error))
8475 * Apply the flow to the NIC, lock free,
8476 * (mutex should be acquired by caller).
8479 * Pointer to the Ethernet device structure.
8480 * @param[in, out] flow
8481 * Pointer to flow structure.
8483 * Pointer to error structure.
8486 * 0 on success, a negative errno value otherwise and rte_errno is set.
8489 __flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
8490 struct rte_flow_error *error)
8492 struct mlx5_flow_dv_workspace *dv;
8493 struct mlx5_flow_handle *dh;
8494 struct mlx5_flow_handle_dv *dv_h;
8495 struct mlx5_flow *dev_flow;
8496 struct mlx5_priv *priv = dev->data->dev_private;
8497 uint32_t handle_idx;
8502 for (idx = priv->flow_idx - 1; idx >= priv->flow_nested_idx; idx--) {
8503 dev_flow = &((struct mlx5_flow *)priv->inter_flows)[idx];
8505 dh = dev_flow->handle;
8508 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
8510 dv->actions[n++] = priv->sh->esw_drop_action;
8512 struct mlx5_hrxq *drop_hrxq;
8513 drop_hrxq = mlx5_hrxq_drop_new(dev);
8517 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8519 "cannot get drop hash queue");
8523 * Drop queues will be released by the specify
8524 * mlx5_hrxq_drop_release() function. Assign
8525 * the special index to hrxq to mark the queue
8526 * has been allocated.
8528 dh->rix_hrxq = UINT32_MAX;
8529 dv->actions[n++] = drop_hrxq->action;
8531 } else if (dh->fate_action == MLX5_FLOW_FATE_QUEUE) {
8532 struct mlx5_hrxq *hrxq;
8534 struct mlx5_flow_rss_desc *rss_desc =
8535 &((struct mlx5_flow_rss_desc *)priv->rss_desc)
8536 [!!priv->flow_nested_idx];
8538 MLX5_ASSERT(rss_desc->queue_num);
8539 hrxq_idx = mlx5_hrxq_get(dev, rss_desc->key,
8540 MLX5_RSS_HASH_KEY_LEN,
8541 dev_flow->hash_fields,
8543 rss_desc->queue_num);
8545 hrxq_idx = mlx5_hrxq_new
8546 (dev, rss_desc->key,
8547 MLX5_RSS_HASH_KEY_LEN,
8548 dev_flow->hash_fields,
8550 rss_desc->queue_num,
8552 MLX5_FLOW_LAYER_TUNNEL));
8554 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
8559 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8560 "cannot get hash queue");
8563 dh->rix_hrxq = hrxq_idx;
8564 dv->actions[n++] = hrxq->action;
8567 mlx5_glue->dv_create_flow(dv_h->matcher->matcher_object,
8568 (void *)&dv->value, n,
8571 rte_flow_error_set(error, errno,
8572 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8574 "hardware refuses to create flow");
8577 if (priv->vmwa_context &&
8578 dh->vf_vlan.tag && !dh->vf_vlan.created) {
8580 * The rule contains the VLAN pattern.
8581 * For VF we are going to create VLAN
8582 * interface to make hypervisor set correct
8583 * e-Switch vport context.
8585 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
8590 err = rte_errno; /* Save rte_errno before cleanup. */
8591 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
8592 handle_idx, dh, next) {
8593 /* hrxq is union, don't clear it if the flag is not set. */
8595 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
8596 mlx5_hrxq_drop_release(dev);
8598 } else if (dh->fate_action == MLX5_FLOW_FATE_QUEUE) {
8599 mlx5_hrxq_release(dev, dh->rix_hrxq);
8603 if (dh->vf_vlan.tag && dh->vf_vlan.created)
8604 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
8606 rte_errno = err; /* Restore rte_errno. */
8611 * Release the flow matcher.
8614 * Pointer to Ethernet device.
8616 * Pointer to mlx5_flow_handle.
8619 * 1 while a reference on it exists, 0 when freed.
8622 flow_dv_matcher_release(struct rte_eth_dev *dev,
8623 struct mlx5_flow_handle *handle)
8625 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
8627 MLX5_ASSERT(matcher->matcher_object);
8628 DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--",
8629 dev->data->port_id, (void *)matcher,
8630 rte_atomic32_read(&matcher->refcnt));
8631 if (rte_atomic32_dec_and_test(&matcher->refcnt)) {
8632 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8633 (matcher->matcher_object));
8634 LIST_REMOVE(matcher, next);
8635 /* table ref-- in release interface. */
8636 flow_dv_tbl_resource_release(dev, matcher->tbl);
8638 DRV_LOG(DEBUG, "port %u matcher %p: removed",
8639 dev->data->port_id, (void *)matcher);
8646 * Release an encap/decap resource.
8649 * Pointer to Ethernet device.
8651 * Pointer to mlx5_flow_handle.
8654 * 1 while a reference on it exists, 0 when freed.
8657 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
8658 struct mlx5_flow_handle *handle)
8660 struct mlx5_priv *priv = dev->data->dev_private;
8661 uint32_t idx = handle->dvh.rix_encap_decap;
8662 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
8664 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
8666 if (!cache_resource)
8668 MLX5_ASSERT(cache_resource->verbs_action);
8669 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d--",
8670 (void *)cache_resource,
8671 rte_atomic32_read(&cache_resource->refcnt));
8672 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8673 claim_zero(mlx5_glue->destroy_flow_action
8674 (cache_resource->verbs_action));
8675 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
8676 &priv->sh->encaps_decaps, idx,
8677 cache_resource, next);
8678 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
8679 DRV_LOG(DEBUG, "encap/decap resource %p: removed",
8680 (void *)cache_resource);
8687 * Release an jump to table action resource.
8690 * Pointer to Ethernet device.
8692 * Pointer to mlx5_flow_handle.
8695 * 1 while a reference on it exists, 0 when freed.
8698 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
8699 struct mlx5_flow_handle *handle)
8701 struct mlx5_priv *priv = dev->data->dev_private;
8702 struct mlx5_flow_dv_jump_tbl_resource *cache_resource;
8703 struct mlx5_flow_tbl_data_entry *tbl_data;
8705 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
8709 cache_resource = &tbl_data->jump;
8710 MLX5_ASSERT(cache_resource->action);
8711 DRV_LOG(DEBUG, "jump table resource %p: refcnt %d--",
8712 (void *)cache_resource,
8713 rte_atomic32_read(&cache_resource->refcnt));
8714 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8715 claim_zero(mlx5_glue->destroy_flow_action
8716 (cache_resource->action));
8717 /* jump action memory free is inside the table release. */
8718 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
8719 DRV_LOG(DEBUG, "jump table resource %p: removed",
8720 (void *)cache_resource);
8727 * Release a modify-header resource.
8730 * Pointer to mlx5_flow_handle.
8733 * 1 while a reference on it exists, 0 when freed.
8736 flow_dv_modify_hdr_resource_release(struct mlx5_flow_handle *handle)
8738 struct mlx5_flow_dv_modify_hdr_resource *cache_resource =
8739 handle->dvh.modify_hdr;
8741 MLX5_ASSERT(cache_resource->verbs_action);
8742 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d--",
8743 (void *)cache_resource,
8744 rte_atomic32_read(&cache_resource->refcnt));
8745 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8746 claim_zero(mlx5_glue->destroy_flow_action
8747 (cache_resource->verbs_action));
8748 LIST_REMOVE(cache_resource, next);
8749 rte_free(cache_resource);
8750 DRV_LOG(DEBUG, "modify-header resource %p: removed",
8751 (void *)cache_resource);
8758 * Release port ID action resource.
8761 * Pointer to Ethernet device.
8763 * Pointer to mlx5_flow_handle.
8766 * 1 while a reference on it exists, 0 when freed.
8769 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
8770 struct mlx5_flow_handle *handle)
8772 struct mlx5_priv *priv = dev->data->dev_private;
8773 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
8774 uint32_t idx = handle->rix_port_id_action;
8776 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
8778 if (!cache_resource)
8780 MLX5_ASSERT(cache_resource->action);
8781 DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--",
8782 (void *)cache_resource,
8783 rte_atomic32_read(&cache_resource->refcnt));
8784 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8785 claim_zero(mlx5_glue->destroy_flow_action
8786 (cache_resource->action));
8787 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
8788 &priv->sh->port_id_action_list, idx,
8789 cache_resource, next);
8790 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_PORT_ID], idx);
8791 DRV_LOG(DEBUG, "port id action resource %p: removed",
8792 (void *)cache_resource);
8799 * Release push vlan action resource.
8802 * Pointer to Ethernet device.
8804 * Pointer to mlx5_flow_handle.
8807 * 1 while a reference on it exists, 0 when freed.
8810 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
8811 struct mlx5_flow_handle *handle)
8813 struct mlx5_priv *priv = dev->data->dev_private;
8814 uint32_t idx = handle->dvh.rix_push_vlan;
8815 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
8817 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN],
8819 if (!cache_resource)
8821 MLX5_ASSERT(cache_resource->action);
8822 DRV_LOG(DEBUG, "push VLAN action resource %p: refcnt %d--",
8823 (void *)cache_resource,
8824 rte_atomic32_read(&cache_resource->refcnt));
8825 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8826 claim_zero(mlx5_glue->destroy_flow_action
8827 (cache_resource->action));
8828 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN],
8829 &priv->sh->push_vlan_action_list, idx,
8830 cache_resource, next);
8831 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
8832 DRV_LOG(DEBUG, "push vlan action resource %p: removed",
8833 (void *)cache_resource);
8840 * Release the fate resource.
8843 * Pointer to Ethernet device.
8845 * Pointer to mlx5_flow_handle.
8848 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
8849 struct mlx5_flow_handle *handle)
8851 if (!handle->rix_fate)
8853 if (handle->fate_action == MLX5_FLOW_FATE_DROP)
8854 mlx5_hrxq_drop_release(dev);
8855 else if (handle->fate_action == MLX5_FLOW_FATE_QUEUE)
8856 mlx5_hrxq_release(dev, handle->rix_hrxq);
8857 else if (handle->fate_action == MLX5_FLOW_FATE_JUMP)
8858 flow_dv_jump_tbl_resource_release(dev, handle);
8859 else if (handle->fate_action == MLX5_FLOW_FATE_PORT_ID)
8860 flow_dv_port_id_action_resource_release(dev, handle);
8862 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
8863 handle->rix_fate = 0;
8867 * Remove the flow from the NIC but keeps it in memory.
8868 * Lock free, (mutex should be acquired by caller).
8871 * Pointer to Ethernet device.
8872 * @param[in, out] flow
8873 * Pointer to flow structure.
8876 __flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
8878 struct mlx5_flow_handle *dh;
8879 uint32_t handle_idx;
8880 struct mlx5_priv *priv = dev->data->dev_private;
8884 handle_idx = flow->dev_handles;
8885 while (handle_idx) {
8886 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8891 claim_zero(mlx5_glue->dv_destroy_flow(dh->ib_flow));
8894 if (dh->fate_action == MLX5_FLOW_FATE_DROP ||
8895 dh->fate_action == MLX5_FLOW_FATE_QUEUE)
8896 flow_dv_fate_resource_release(dev, dh);
8897 if (dh->vf_vlan.tag && dh->vf_vlan.created)
8898 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
8899 handle_idx = dh->next.next;
8904 * Remove the flow from the NIC and the memory.
8905 * Lock free, (mutex should be acquired by caller).
8908 * Pointer to the Ethernet device structure.
8909 * @param[in, out] flow
8910 * Pointer to flow structure.
8913 __flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
8915 struct mlx5_flow_handle *dev_handle;
8916 struct mlx5_priv *priv = dev->data->dev_private;
8920 __flow_dv_remove(dev, flow);
8921 if (flow->counter) {
8922 flow_dv_counter_release(dev, flow->counter);
8926 struct mlx5_flow_meter *fm;
8928 fm = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MTR],
8931 mlx5_flow_meter_detach(fm);
8934 while (flow->dev_handles) {
8935 uint32_t tmp_idx = flow->dev_handles;
8937 dev_handle = mlx5_ipool_get(priv->sh->ipool
8938 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
8941 flow->dev_handles = dev_handle->next.next;
8942 if (dev_handle->dvh.matcher)
8943 flow_dv_matcher_release(dev, dev_handle);
8944 if (dev_handle->dvh.rix_encap_decap)
8945 flow_dv_encap_decap_resource_release(dev, dev_handle);
8946 if (dev_handle->dvh.modify_hdr)
8947 flow_dv_modify_hdr_resource_release(dev_handle);
8948 if (dev_handle->dvh.rix_push_vlan)
8949 flow_dv_push_vlan_action_resource_release(dev,
8951 if (dev_handle->dvh.rix_tag)
8952 flow_dv_tag_release(dev,
8953 dev_handle->dvh.rix_tag);
8954 flow_dv_fate_resource_release(dev, dev_handle);
8955 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8961 * Query a dv flow rule for its statistics via devx.
8964 * Pointer to Ethernet device.
8966 * Pointer to the sub flow.
8968 * data retrieved by the query.
8970 * Perform verbose error reporting if not NULL.
8973 * 0 on success, a negative errno value otherwise and rte_errno is set.
8976 flow_dv_query_count(struct rte_eth_dev *dev, struct rte_flow *flow,
8977 void *data, struct rte_flow_error *error)
8979 struct mlx5_priv *priv = dev->data->dev_private;
8980 struct rte_flow_query_count *qc = data;
8982 if (!priv->config.devx)
8983 return rte_flow_error_set(error, ENOTSUP,
8984 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8986 "counters are not supported");
8987 if (flow->counter) {
8988 uint64_t pkts, bytes;
8989 struct mlx5_flow_counter *cnt;
8991 cnt = flow_dv_counter_get_by_idx(dev, flow->counter,
8993 int err = _flow_dv_query_count(dev, flow->counter, &pkts,
8997 return rte_flow_error_set(error, -err,
8998 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8999 NULL, "cannot read counters");
9002 qc->hits = pkts - cnt->hits;
9003 qc->bytes = bytes - cnt->bytes;
9010 return rte_flow_error_set(error, EINVAL,
9011 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9013 "counters are not available");
9019 * @see rte_flow_query()
9023 flow_dv_query(struct rte_eth_dev *dev,
9024 struct rte_flow *flow __rte_unused,
9025 const struct rte_flow_action *actions __rte_unused,
9026 void *data __rte_unused,
9027 struct rte_flow_error *error __rte_unused)
9031 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
9032 switch (actions->type) {
9033 case RTE_FLOW_ACTION_TYPE_VOID:
9035 case RTE_FLOW_ACTION_TYPE_COUNT:
9036 ret = flow_dv_query_count(dev, flow, data, error);
9039 return rte_flow_error_set(error, ENOTSUP,
9040 RTE_FLOW_ERROR_TYPE_ACTION,
9042 "action not supported");
9049 * Destroy the meter table set.
9050 * Lock free, (mutex should be acquired by caller).
9053 * Pointer to Ethernet device.
9055 * Pointer to the meter table set.
9061 flow_dv_destroy_mtr_tbl(struct rte_eth_dev *dev,
9062 struct mlx5_meter_domains_infos *tbl)
9064 struct mlx5_priv *priv = dev->data->dev_private;
9065 struct mlx5_meter_domains_infos *mtd =
9066 (struct mlx5_meter_domains_infos *)tbl;
9068 if (!mtd || !priv->config.dv_flow_en)
9070 if (mtd->ingress.policer_rules[RTE_MTR_DROPPED])
9071 claim_zero(mlx5_glue->dv_destroy_flow
9072 (mtd->ingress.policer_rules[RTE_MTR_DROPPED]));
9073 if (mtd->egress.policer_rules[RTE_MTR_DROPPED])
9074 claim_zero(mlx5_glue->dv_destroy_flow
9075 (mtd->egress.policer_rules[RTE_MTR_DROPPED]));
9076 if (mtd->transfer.policer_rules[RTE_MTR_DROPPED])
9077 claim_zero(mlx5_glue->dv_destroy_flow
9078 (mtd->transfer.policer_rules[RTE_MTR_DROPPED]));
9079 if (mtd->egress.color_matcher)
9080 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9081 (mtd->egress.color_matcher));
9082 if (mtd->egress.any_matcher)
9083 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9084 (mtd->egress.any_matcher));
9085 if (mtd->egress.tbl)
9086 flow_dv_tbl_resource_release(dev, mtd->egress.tbl);
9087 if (mtd->egress.sfx_tbl)
9088 flow_dv_tbl_resource_release(dev, mtd->egress.sfx_tbl);
9089 if (mtd->ingress.color_matcher)
9090 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9091 (mtd->ingress.color_matcher));
9092 if (mtd->ingress.any_matcher)
9093 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9094 (mtd->ingress.any_matcher));
9095 if (mtd->ingress.tbl)
9096 flow_dv_tbl_resource_release(dev, mtd->ingress.tbl);
9097 if (mtd->ingress.sfx_tbl)
9098 flow_dv_tbl_resource_release(dev, mtd->ingress.sfx_tbl);
9099 if (mtd->transfer.color_matcher)
9100 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9101 (mtd->transfer.color_matcher));
9102 if (mtd->transfer.any_matcher)
9103 claim_zero(mlx5_glue->dv_destroy_flow_matcher
9104 (mtd->transfer.any_matcher));
9105 if (mtd->transfer.tbl)
9106 flow_dv_tbl_resource_release(dev, mtd->transfer.tbl);
9107 if (mtd->transfer.sfx_tbl)
9108 flow_dv_tbl_resource_release(dev, mtd->transfer.sfx_tbl);
9110 claim_zero(mlx5_glue->destroy_flow_action(mtd->drop_actn));
9115 /* Number of meter flow actions, count and jump or count and drop. */
9116 #define METER_ACTIONS 2
9119 * Create specify domain meter table and suffix table.
9122 * Pointer to Ethernet device.
9123 * @param[in,out] mtb
9124 * Pointer to DV meter table set.
9127 * @param[in] transfer
9129 * @param[in] color_reg_c_idx
9130 * Reg C index for color match.
9133 * 0 on success, -1 otherwise and rte_errno is set.
9136 flow_dv_prepare_mtr_tables(struct rte_eth_dev *dev,
9137 struct mlx5_meter_domains_infos *mtb,
9138 uint8_t egress, uint8_t transfer,
9139 uint32_t color_reg_c_idx)
9141 struct mlx5_priv *priv = dev->data->dev_private;
9142 struct mlx5_ibv_shared *sh = priv->sh;
9143 struct mlx5_flow_dv_match_params mask = {
9144 .size = sizeof(mask.buf),
9146 struct mlx5_flow_dv_match_params value = {
9147 .size = sizeof(value.buf),
9149 struct mlx5dv_flow_matcher_attr dv_attr = {
9150 .type = IBV_FLOW_ATTR_NORMAL,
9152 .match_criteria_enable = 0,
9153 .match_mask = (void *)&mask,
9155 void *actions[METER_ACTIONS];
9156 struct mlx5_meter_domain_info *dtb;
9157 struct rte_flow_error error;
9161 dtb = &mtb->transfer;
9165 dtb = &mtb->ingress;
9166 /* Create the meter table with METER level. */
9167 dtb->tbl = flow_dv_tbl_resource_get(dev, MLX5_FLOW_TABLE_LEVEL_METER,
9168 egress, transfer, &error);
9170 DRV_LOG(ERR, "Failed to create meter policer table.");
9173 /* Create the meter suffix table with SUFFIX level. */
9174 dtb->sfx_tbl = flow_dv_tbl_resource_get(dev,
9175 MLX5_FLOW_TABLE_LEVEL_SUFFIX,
9176 egress, transfer, &error);
9177 if (!dtb->sfx_tbl) {
9178 DRV_LOG(ERR, "Failed to create meter suffix table.");
9181 /* Create matchers, Any and Color. */
9182 dv_attr.priority = 3;
9183 dv_attr.match_criteria_enable = 0;
9184 dtb->any_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
9187 if (!dtb->any_matcher) {
9188 DRV_LOG(ERR, "Failed to create meter"
9189 " policer default matcher.");
9192 dv_attr.priority = 0;
9193 dv_attr.match_criteria_enable =
9194 1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
9195 flow_dv_match_meta_reg(mask.buf, value.buf, color_reg_c_idx,
9196 rte_col_2_mlx5_col(RTE_COLORS), UINT8_MAX);
9197 dtb->color_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
9200 if (!dtb->color_matcher) {
9201 DRV_LOG(ERR, "Failed to create meter policer color matcher.");
9204 if (mtb->count_actns[RTE_MTR_DROPPED])
9205 actions[i++] = mtb->count_actns[RTE_MTR_DROPPED];
9206 actions[i++] = mtb->drop_actn;
9207 /* Default rule: lowest priority, match any, actions: drop. */
9208 dtb->policer_rules[RTE_MTR_DROPPED] =
9209 mlx5_glue->dv_create_flow(dtb->any_matcher,
9210 (void *)&value, i, actions);
9211 if (!dtb->policer_rules[RTE_MTR_DROPPED]) {
9212 DRV_LOG(ERR, "Failed to create meter policer drop rule.");
9221 * Create the needed meter and suffix tables.
9222 * Lock free, (mutex should be acquired by caller).
9225 * Pointer to Ethernet device.
9227 * Pointer to the flow meter.
9230 * Pointer to table set on success, NULL otherwise and rte_errno is set.
9232 static struct mlx5_meter_domains_infos *
9233 flow_dv_create_mtr_tbl(struct rte_eth_dev *dev,
9234 const struct mlx5_flow_meter *fm)
9236 struct mlx5_priv *priv = dev->data->dev_private;
9237 struct mlx5_meter_domains_infos *mtb;
9241 if (!priv->mtr_en) {
9242 rte_errno = ENOTSUP;
9245 mtb = rte_calloc(__func__, 1, sizeof(*mtb), 0);
9247 DRV_LOG(ERR, "Failed to allocate memory for meter.");
9250 /* Create meter count actions */
9251 for (i = 0; i <= RTE_MTR_DROPPED; i++) {
9252 struct mlx5_flow_counter *cnt;
9253 if (!fm->policer_stats.cnt[i])
9255 cnt = flow_dv_counter_get_by_idx(dev,
9256 fm->policer_stats.cnt[i], NULL);
9257 mtb->count_actns[i] = cnt->action;
9259 /* Create drop action. */
9260 mtb->drop_actn = mlx5_glue->dr_create_flow_action_drop();
9261 if (!mtb->drop_actn) {
9262 DRV_LOG(ERR, "Failed to create drop action.");
9265 /* Egress meter table. */
9266 ret = flow_dv_prepare_mtr_tables(dev, mtb, 1, 0, priv->mtr_color_reg);
9268 DRV_LOG(ERR, "Failed to prepare egress meter table.");
9271 /* Ingress meter table. */
9272 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 0, priv->mtr_color_reg);
9274 DRV_LOG(ERR, "Failed to prepare ingress meter table.");
9277 /* FDB meter table. */
9278 if (priv->config.dv_esw_en) {
9279 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 1,
9280 priv->mtr_color_reg);
9282 DRV_LOG(ERR, "Failed to prepare fdb meter table.");
9288 flow_dv_destroy_mtr_tbl(dev, mtb);
9293 * Destroy domain policer rule.
9296 * Pointer to domain table.
9299 flow_dv_destroy_domain_policer_rule(struct mlx5_meter_domain_info *dt)
9303 for (i = 0; i < RTE_MTR_DROPPED; i++) {
9304 if (dt->policer_rules[i]) {
9305 claim_zero(mlx5_glue->dv_destroy_flow
9306 (dt->policer_rules[i]));
9307 dt->policer_rules[i] = NULL;
9310 if (dt->jump_actn) {
9311 claim_zero(mlx5_glue->destroy_flow_action(dt->jump_actn));
9312 dt->jump_actn = NULL;
9317 * Destroy policer rules.
9320 * Pointer to Ethernet device.
9322 * Pointer to flow meter structure.
9324 * Pointer to flow attributes.
9330 flow_dv_destroy_policer_rules(struct rte_eth_dev *dev __rte_unused,
9331 const struct mlx5_flow_meter *fm,
9332 const struct rte_flow_attr *attr)
9334 struct mlx5_meter_domains_infos *mtb = fm ? fm->mfts : NULL;
9339 flow_dv_destroy_domain_policer_rule(&mtb->egress);
9341 flow_dv_destroy_domain_policer_rule(&mtb->ingress);
9343 flow_dv_destroy_domain_policer_rule(&mtb->transfer);
9348 * Create specify domain meter policer rule.
9351 * Pointer to flow meter structure.
9353 * Pointer to DV meter table set.
9354 * @param[in] mtr_reg_c
9355 * Color match REG_C.
9358 * 0 on success, -1 otherwise.
9361 flow_dv_create_policer_forward_rule(struct mlx5_flow_meter *fm,
9362 struct mlx5_meter_domain_info *dtb,
9365 struct mlx5_flow_dv_match_params matcher = {
9366 .size = sizeof(matcher.buf),
9368 struct mlx5_flow_dv_match_params value = {
9369 .size = sizeof(value.buf),
9371 struct mlx5_meter_domains_infos *mtb = fm->mfts;
9372 void *actions[METER_ACTIONS];
9375 /* Create jump action. */
9376 if (!dtb->jump_actn)
9378 mlx5_glue->dr_create_flow_action_dest_flow_tbl
9379 (dtb->sfx_tbl->obj);
9380 if (!dtb->jump_actn) {
9381 DRV_LOG(ERR, "Failed to create policer jump action.");
9384 for (i = 0; i < RTE_MTR_DROPPED; i++) {
9387 flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
9388 rte_col_2_mlx5_col(i), UINT8_MAX);
9389 if (mtb->count_actns[i])
9390 actions[j++] = mtb->count_actns[i];
9391 if (fm->action[i] == MTR_POLICER_ACTION_DROP)
9392 actions[j++] = mtb->drop_actn;
9394 actions[j++] = dtb->jump_actn;
9395 dtb->policer_rules[i] =
9396 mlx5_glue->dv_create_flow(dtb->color_matcher,
9399 if (!dtb->policer_rules[i]) {
9400 DRV_LOG(ERR, "Failed to create policer rule.");
9411 * Create policer rules.
9414 * Pointer to Ethernet device.
9416 * Pointer to flow meter structure.
9418 * Pointer to flow attributes.
9421 * 0 on success, -1 otherwise.
9424 flow_dv_create_policer_rules(struct rte_eth_dev *dev,
9425 struct mlx5_flow_meter *fm,
9426 const struct rte_flow_attr *attr)
9428 struct mlx5_priv *priv = dev->data->dev_private;
9429 struct mlx5_meter_domains_infos *mtb = fm->mfts;
9433 ret = flow_dv_create_policer_forward_rule(fm, &mtb->egress,
9434 priv->mtr_color_reg);
9436 DRV_LOG(ERR, "Failed to create egress policer.");
9440 if (attr->ingress) {
9441 ret = flow_dv_create_policer_forward_rule(fm, &mtb->ingress,
9442 priv->mtr_color_reg);
9444 DRV_LOG(ERR, "Failed to create ingress policer.");
9448 if (attr->transfer) {
9449 ret = flow_dv_create_policer_forward_rule(fm, &mtb->transfer,
9450 priv->mtr_color_reg);
9452 DRV_LOG(ERR, "Failed to create transfer policer.");
9458 flow_dv_destroy_policer_rules(dev, fm, attr);
9463 * Query a devx counter.
9466 * Pointer to the Ethernet device structure.
9468 * Index to the flow counter.
9470 * Set to clear the counter statistics.
9472 * The statistics value of packets.
9474 * The statistics value of bytes.
9477 * 0 on success, otherwise return -1.
9480 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
9481 uint64_t *pkts, uint64_t *bytes)
9483 struct mlx5_priv *priv = dev->data->dev_private;
9484 struct mlx5_flow_counter *cnt;
9485 uint64_t inn_pkts, inn_bytes;
9488 if (!priv->config.devx)
9491 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
9494 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
9495 *pkts = inn_pkts - cnt->hits;
9496 *bytes = inn_bytes - cnt->bytes;
9498 cnt->hits = inn_pkts;
9499 cnt->bytes = inn_bytes;
9505 * Get aged-out flows.
9508 * Pointer to the Ethernet device structure.
9509 * @param[in] context
9510 * The address of an array of pointers to the aged-out flows contexts.
9511 * @param[in] nb_contexts
9512 * The length of context array pointers.
9514 * Perform verbose error reporting if not NULL. Initialized in case of
9518 * how many contexts get in success, otherwise negative errno value.
9519 * if nb_contexts is 0, return the amount of all aged contexts.
9520 * if nb_contexts is not 0 , return the amount of aged flows reported
9521 * in the context array.
9522 * @note: only stub for now
9525 flow_get_aged_flows(struct rte_eth_dev *dev,
9527 uint32_t nb_contexts,
9528 struct rte_flow_error *error)
9530 struct mlx5_priv *priv = dev->data->dev_private;
9531 struct mlx5_age_info *age_info;
9532 struct mlx5_age_param *age_param;
9533 struct mlx5_flow_counter *counter;
9536 if (nb_contexts && !context)
9537 return rte_flow_error_set(error, EINVAL,
9538 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9540 "Should assign at least one flow or"
9541 " context to get if nb_contexts != 0");
9542 age_info = GET_PORT_AGE_INFO(priv);
9543 rte_spinlock_lock(&age_info->aged_sl);
9544 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
9547 age_param = MLX5_CNT_TO_AGE(counter);
9548 context[nb_flows - 1] = age_param->context;
9549 if (!(--nb_contexts))
9553 rte_spinlock_unlock(&age_info->aged_sl);
9554 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
9559 * Mutex-protected thunk to lock-free __flow_dv_translate().
9562 flow_dv_translate(struct rte_eth_dev *dev,
9563 struct mlx5_flow *dev_flow,
9564 const struct rte_flow_attr *attr,
9565 const struct rte_flow_item items[],
9566 const struct rte_flow_action actions[],
9567 struct rte_flow_error *error)
9571 flow_dv_shared_lock(dev);
9572 ret = __flow_dv_translate(dev, dev_flow, attr, items, actions, error);
9573 flow_dv_shared_unlock(dev);
9578 * Mutex-protected thunk to lock-free __flow_dv_apply().
9581 flow_dv_apply(struct rte_eth_dev *dev,
9582 struct rte_flow *flow,
9583 struct rte_flow_error *error)
9587 flow_dv_shared_lock(dev);
9588 ret = __flow_dv_apply(dev, flow, error);
9589 flow_dv_shared_unlock(dev);
9594 * Mutex-protected thunk to lock-free __flow_dv_remove().
9597 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
9599 flow_dv_shared_lock(dev);
9600 __flow_dv_remove(dev, flow);
9601 flow_dv_shared_unlock(dev);
9605 * Mutex-protected thunk to lock-free __flow_dv_destroy().
9608 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
9610 flow_dv_shared_lock(dev);
9611 __flow_dv_destroy(dev, flow);
9612 flow_dv_shared_unlock(dev);
9616 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
9619 flow_dv_counter_allocate(struct rte_eth_dev *dev)
9623 flow_dv_shared_lock(dev);
9624 cnt = flow_dv_counter_alloc(dev, 0, 0, 1, 0);
9625 flow_dv_shared_unlock(dev);
9630 * Mutex-protected thunk to lock-free flow_dv_counter_release().
9633 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
9635 flow_dv_shared_lock(dev);
9636 flow_dv_counter_release(dev, cnt);
9637 flow_dv_shared_unlock(dev);
9640 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
9641 .validate = flow_dv_validate,
9642 .prepare = flow_dv_prepare,
9643 .translate = flow_dv_translate,
9644 .apply = flow_dv_apply,
9645 .remove = flow_dv_remove,
9646 .destroy = flow_dv_destroy,
9647 .query = flow_dv_query,
9648 .create_mtr_tbls = flow_dv_create_mtr_tbl,
9649 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbl,
9650 .create_policer_rules = flow_dv_create_policer_rules,
9651 .destroy_policer_rules = flow_dv_destroy_policer_rules,
9652 .counter_alloc = flow_dv_counter_allocate,
9653 .counter_free = flow_dv_counter_free,
9654 .counter_query = flow_dv_counter_query,
9655 .get_aged_flows = flow_get_aged_flows,
9658 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */