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>
29 #include <rte_vxlan.h>
32 #include <mlx5_glue.h>
33 #include <mlx5_devx_cmds.h>
36 #include "mlx5_defs.h"
38 #include "mlx5_flow.h"
39 #include "mlx5_rxtx.h"
41 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
43 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
44 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
47 #ifndef HAVE_MLX5DV_DR_ESWITCH
48 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
49 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
53 #ifndef HAVE_MLX5DV_DR
54 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
57 /* VLAN header definitions */
58 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
59 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
60 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
61 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
62 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
76 static struct mlx5_flow_counter_pool *
77 flow_dv_find_pool_by_id(struct mlx5_pools_container *cont, bool fallback,
79 static struct mlx5_pools_container *
80 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
84 * Initialize flow attributes structure according to flow items' types.
86 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
87 * mode. For tunnel mode, the items to be modified are the outermost ones.
90 * Pointer to item specification.
92 * Pointer to flow attributes structure.
94 * Pointer to the sub flow.
95 * @param[in] tunnel_decap
96 * Whether action is after tunnel decapsulation.
99 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
100 struct mlx5_flow *dev_flow, bool tunnel_decap)
102 uint64_t layers = dev_flow->handle->layers;
105 * If layers is already initialized, it means this dev_flow is the
106 * suffix flow, the layers flags is set by the prefix flow. Need to
107 * use the layer flags from prefix flow as the suffix flow may not
108 * have the user defined items as the flow is split.
111 if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
113 else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
115 if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
117 else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
122 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
123 uint8_t next_protocol = 0xff;
124 switch (item->type) {
125 case RTE_FLOW_ITEM_TYPE_GRE:
126 case RTE_FLOW_ITEM_TYPE_NVGRE:
127 case RTE_FLOW_ITEM_TYPE_VXLAN:
128 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
129 case RTE_FLOW_ITEM_TYPE_GENEVE:
130 case RTE_FLOW_ITEM_TYPE_MPLS:
134 case RTE_FLOW_ITEM_TYPE_IPV4:
137 if (item->mask != NULL &&
138 ((const struct rte_flow_item_ipv4 *)
139 item->mask)->hdr.next_proto_id)
141 ((const struct rte_flow_item_ipv4 *)
142 (item->spec))->hdr.next_proto_id &
143 ((const struct rte_flow_item_ipv4 *)
144 (item->mask))->hdr.next_proto_id;
145 if ((next_protocol == IPPROTO_IPIP ||
146 next_protocol == IPPROTO_IPV6) && tunnel_decap)
149 case RTE_FLOW_ITEM_TYPE_IPV6:
152 if (item->mask != NULL &&
153 ((const struct rte_flow_item_ipv6 *)
154 item->mask)->hdr.proto)
156 ((const struct rte_flow_item_ipv6 *)
157 (item->spec))->hdr.proto &
158 ((const struct rte_flow_item_ipv6 *)
159 (item->mask))->hdr.proto;
160 if ((next_protocol == IPPROTO_IPIP ||
161 next_protocol == IPPROTO_IPV6) && tunnel_decap)
164 case RTE_FLOW_ITEM_TYPE_UDP:
168 case RTE_FLOW_ITEM_TYPE_TCP:
180 * Convert rte_mtr_color to mlx5 color.
189 rte_col_2_mlx5_col(enum rte_color rcol)
192 case RTE_COLOR_GREEN:
193 return MLX5_FLOW_COLOR_GREEN;
194 case RTE_COLOR_YELLOW:
195 return MLX5_FLOW_COLOR_YELLOW;
197 return MLX5_FLOW_COLOR_RED;
201 return MLX5_FLOW_COLOR_UNDEFINED;
204 struct field_modify_info {
205 uint32_t size; /* Size of field in protocol header, in bytes. */
206 uint32_t offset; /* Offset of field in protocol header, in bytes. */
207 enum mlx5_modification_field id;
210 struct field_modify_info modify_eth[] = {
211 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
212 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
213 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
214 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
218 struct field_modify_info modify_vlan_out_first_vid[] = {
219 /* Size in bits !!! */
220 {12, 0, MLX5_MODI_OUT_FIRST_VID},
224 struct field_modify_info modify_ipv4[] = {
225 {1, 1, MLX5_MODI_OUT_IP_DSCP},
226 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
227 {4, 12, MLX5_MODI_OUT_SIPV4},
228 {4, 16, MLX5_MODI_OUT_DIPV4},
232 struct field_modify_info modify_ipv6[] = {
233 {1, 0, MLX5_MODI_OUT_IP_DSCP},
234 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
235 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
236 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
237 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
238 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
239 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
240 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
241 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
242 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
246 struct field_modify_info modify_udp[] = {
247 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
248 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
252 struct field_modify_info modify_tcp[] = {
253 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
254 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
255 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
256 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
261 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
262 uint8_t next_protocol, uint64_t *item_flags,
265 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
266 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
267 if (next_protocol == IPPROTO_IPIP) {
268 *item_flags |= MLX5_FLOW_LAYER_IPIP;
271 if (next_protocol == IPPROTO_IPV6) {
272 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
278 * Acquire the synchronizing object to protect multithreaded access
279 * to shared dv context. Lock occurs only if context is actually
280 * shared, i.e. we have multiport IB device and representors are
284 * Pointer to the rte_eth_dev structure.
287 flow_dv_shared_lock(struct rte_eth_dev *dev)
289 struct mlx5_priv *priv = dev->data->dev_private;
290 struct mlx5_ibv_shared *sh = priv->sh;
292 if (sh->dv_refcnt > 1) {
295 ret = pthread_mutex_lock(&sh->dv_mutex);
302 flow_dv_shared_unlock(struct rte_eth_dev *dev)
304 struct mlx5_priv *priv = dev->data->dev_private;
305 struct mlx5_ibv_shared *sh = priv->sh;
307 if (sh->dv_refcnt > 1) {
310 ret = pthread_mutex_unlock(&sh->dv_mutex);
316 /* Update VLAN's VID/PCP based on input rte_flow_action.
319 * Pointer to struct rte_flow_action.
321 * Pointer to struct rte_vlan_hdr.
324 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
325 struct rte_vlan_hdr *vlan)
328 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
330 ((const struct rte_flow_action_of_set_vlan_pcp *)
331 action->conf)->vlan_pcp;
332 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
333 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
334 vlan->vlan_tci |= vlan_tci;
335 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
336 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
337 vlan->vlan_tci |= rte_be_to_cpu_16
338 (((const struct rte_flow_action_of_set_vlan_vid *)
339 action->conf)->vlan_vid);
344 * Fetch 1, 2, 3 or 4 byte field from the byte array
345 * and return as unsigned integer in host-endian format.
348 * Pointer to data array.
350 * Size of field to extract.
353 * converted field in host endian format.
355 static inline uint32_t
356 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
365 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
368 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
369 ret = (ret << 8) | *(data + sizeof(uint16_t));
372 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
383 * Convert modify-header action to DV specification.
385 * Data length of each action is determined by provided field description
386 * and the item mask. Data bit offset and width of each action is determined
387 * by provided item mask.
390 * Pointer to item specification.
392 * Pointer to field modification information.
393 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
394 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
395 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
397 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
398 * Negative offset value sets the same offset as source offset.
399 * size field is ignored, value is taken from source field.
400 * @param[in,out] resource
401 * Pointer to the modify-header resource.
403 * Type of modification.
405 * Pointer to the error structure.
408 * 0 on success, a negative errno value otherwise and rte_errno is set.
411 flow_dv_convert_modify_action(struct rte_flow_item *item,
412 struct field_modify_info *field,
413 struct field_modify_info *dcopy,
414 struct mlx5_flow_dv_modify_hdr_resource *resource,
415 uint32_t type, struct rte_flow_error *error)
417 uint32_t i = resource->actions_num;
418 struct mlx5_modification_cmd *actions = resource->actions;
421 * The item and mask are provided in big-endian format.
422 * The fields should be presented as in big-endian format either.
423 * Mask must be always present, it defines the actual field width.
425 MLX5_ASSERT(item->mask);
426 MLX5_ASSERT(field->size);
433 if (i >= MLX5_MAX_MODIFY_NUM)
434 return rte_flow_error_set(error, EINVAL,
435 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
436 "too many items to modify");
437 /* Fetch variable byte size mask from the array. */
438 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
439 field->offset, field->size);
444 /* Deduce actual data width in bits from mask value. */
445 off_b = rte_bsf32(mask);
446 size_b = sizeof(uint32_t) * CHAR_BIT -
447 off_b - __builtin_clz(mask);
449 size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
450 actions[i] = (struct mlx5_modification_cmd) {
456 /* Convert entire record to expected big-endian format. */
457 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
458 if (type == MLX5_MODIFICATION_TYPE_COPY) {
460 actions[i].dst_field = dcopy->id;
461 actions[i].dst_offset =
462 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
463 /* Convert entire record to big-endian format. */
464 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
466 MLX5_ASSERT(item->spec);
467 data = flow_dv_fetch_field((const uint8_t *)item->spec +
468 field->offset, field->size);
469 /* Shift out the trailing masked bits from data. */
470 data = (data & mask) >> off_b;
471 actions[i].data1 = rte_cpu_to_be_32(data);
475 } while (field->size);
476 if (resource->actions_num == i)
477 return rte_flow_error_set(error, EINVAL,
478 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
479 "invalid modification flow item");
480 resource->actions_num = i;
485 * Convert modify-header set IPv4 address action to DV specification.
487 * @param[in,out] resource
488 * Pointer to the modify-header resource.
490 * Pointer to action specification.
492 * Pointer to the error structure.
495 * 0 on success, a negative errno value otherwise and rte_errno is set.
498 flow_dv_convert_action_modify_ipv4
499 (struct mlx5_flow_dv_modify_hdr_resource *resource,
500 const struct rte_flow_action *action,
501 struct rte_flow_error *error)
503 const struct rte_flow_action_set_ipv4 *conf =
504 (const struct rte_flow_action_set_ipv4 *)(action->conf);
505 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
506 struct rte_flow_item_ipv4 ipv4;
507 struct rte_flow_item_ipv4 ipv4_mask;
509 memset(&ipv4, 0, sizeof(ipv4));
510 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
511 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
512 ipv4.hdr.src_addr = conf->ipv4_addr;
513 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
515 ipv4.hdr.dst_addr = conf->ipv4_addr;
516 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
519 item.mask = &ipv4_mask;
520 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
521 MLX5_MODIFICATION_TYPE_SET, error);
525 * Convert modify-header set IPv6 address action to DV specification.
527 * @param[in,out] resource
528 * Pointer to the modify-header resource.
530 * Pointer to action specification.
532 * Pointer to the error structure.
535 * 0 on success, a negative errno value otherwise and rte_errno is set.
538 flow_dv_convert_action_modify_ipv6
539 (struct mlx5_flow_dv_modify_hdr_resource *resource,
540 const struct rte_flow_action *action,
541 struct rte_flow_error *error)
543 const struct rte_flow_action_set_ipv6 *conf =
544 (const struct rte_flow_action_set_ipv6 *)(action->conf);
545 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
546 struct rte_flow_item_ipv6 ipv6;
547 struct rte_flow_item_ipv6 ipv6_mask;
549 memset(&ipv6, 0, sizeof(ipv6));
550 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
551 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
552 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
553 sizeof(ipv6.hdr.src_addr));
554 memcpy(&ipv6_mask.hdr.src_addr,
555 &rte_flow_item_ipv6_mask.hdr.src_addr,
556 sizeof(ipv6.hdr.src_addr));
558 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
559 sizeof(ipv6.hdr.dst_addr));
560 memcpy(&ipv6_mask.hdr.dst_addr,
561 &rte_flow_item_ipv6_mask.hdr.dst_addr,
562 sizeof(ipv6.hdr.dst_addr));
565 item.mask = &ipv6_mask;
566 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
567 MLX5_MODIFICATION_TYPE_SET, error);
571 * Convert modify-header set MAC address action to DV specification.
573 * @param[in,out] resource
574 * Pointer to the modify-header resource.
576 * Pointer to action specification.
578 * Pointer to the error structure.
581 * 0 on success, a negative errno value otherwise and rte_errno is set.
584 flow_dv_convert_action_modify_mac
585 (struct mlx5_flow_dv_modify_hdr_resource *resource,
586 const struct rte_flow_action *action,
587 struct rte_flow_error *error)
589 const struct rte_flow_action_set_mac *conf =
590 (const struct rte_flow_action_set_mac *)(action->conf);
591 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
592 struct rte_flow_item_eth eth;
593 struct rte_flow_item_eth eth_mask;
595 memset(ð, 0, sizeof(eth));
596 memset(ð_mask, 0, sizeof(eth_mask));
597 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
598 memcpy(ð.src.addr_bytes, &conf->mac_addr,
599 sizeof(eth.src.addr_bytes));
600 memcpy(ð_mask.src.addr_bytes,
601 &rte_flow_item_eth_mask.src.addr_bytes,
602 sizeof(eth_mask.src.addr_bytes));
604 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
605 sizeof(eth.dst.addr_bytes));
606 memcpy(ð_mask.dst.addr_bytes,
607 &rte_flow_item_eth_mask.dst.addr_bytes,
608 sizeof(eth_mask.dst.addr_bytes));
611 item.mask = ð_mask;
612 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
613 MLX5_MODIFICATION_TYPE_SET, error);
617 * Convert modify-header set VLAN VID action to DV specification.
619 * @param[in,out] resource
620 * Pointer to the modify-header resource.
622 * Pointer to action specification.
624 * Pointer to the error structure.
627 * 0 on success, a negative errno value otherwise and rte_errno is set.
630 flow_dv_convert_action_modify_vlan_vid
631 (struct mlx5_flow_dv_modify_hdr_resource *resource,
632 const struct rte_flow_action *action,
633 struct rte_flow_error *error)
635 const struct rte_flow_action_of_set_vlan_vid *conf =
636 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
637 int i = resource->actions_num;
638 struct mlx5_modification_cmd *actions = resource->actions;
639 struct field_modify_info *field = modify_vlan_out_first_vid;
641 if (i >= MLX5_MAX_MODIFY_NUM)
642 return rte_flow_error_set(error, EINVAL,
643 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
644 "too many items to modify");
645 actions[i] = (struct mlx5_modification_cmd) {
646 .action_type = MLX5_MODIFICATION_TYPE_SET,
648 .length = field->size,
649 .offset = field->offset,
651 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
652 actions[i].data1 = conf->vlan_vid;
653 actions[i].data1 = actions[i].data1 << 16;
654 resource->actions_num = ++i;
659 * Convert modify-header set TP action to DV specification.
661 * @param[in,out] resource
662 * Pointer to the modify-header resource.
664 * Pointer to action specification.
666 * Pointer to rte_flow_item objects list.
668 * Pointer to flow attributes structure.
669 * @param[in] dev_flow
670 * Pointer to the sub flow.
671 * @param[in] tunnel_decap
672 * Whether action is after tunnel decapsulation.
674 * Pointer to the error structure.
677 * 0 on success, a negative errno value otherwise and rte_errno is set.
680 flow_dv_convert_action_modify_tp
681 (struct mlx5_flow_dv_modify_hdr_resource *resource,
682 const struct rte_flow_action *action,
683 const struct rte_flow_item *items,
684 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
685 bool tunnel_decap, struct rte_flow_error *error)
687 const struct rte_flow_action_set_tp *conf =
688 (const struct rte_flow_action_set_tp *)(action->conf);
689 struct rte_flow_item item;
690 struct rte_flow_item_udp udp;
691 struct rte_flow_item_udp udp_mask;
692 struct rte_flow_item_tcp tcp;
693 struct rte_flow_item_tcp tcp_mask;
694 struct field_modify_info *field;
697 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
699 memset(&udp, 0, sizeof(udp));
700 memset(&udp_mask, 0, sizeof(udp_mask));
701 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
702 udp.hdr.src_port = conf->port;
703 udp_mask.hdr.src_port =
704 rte_flow_item_udp_mask.hdr.src_port;
706 udp.hdr.dst_port = conf->port;
707 udp_mask.hdr.dst_port =
708 rte_flow_item_udp_mask.hdr.dst_port;
710 item.type = RTE_FLOW_ITEM_TYPE_UDP;
712 item.mask = &udp_mask;
715 MLX5_ASSERT(attr->tcp);
716 memset(&tcp, 0, sizeof(tcp));
717 memset(&tcp_mask, 0, sizeof(tcp_mask));
718 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
719 tcp.hdr.src_port = conf->port;
720 tcp_mask.hdr.src_port =
721 rte_flow_item_tcp_mask.hdr.src_port;
723 tcp.hdr.dst_port = conf->port;
724 tcp_mask.hdr.dst_port =
725 rte_flow_item_tcp_mask.hdr.dst_port;
727 item.type = RTE_FLOW_ITEM_TYPE_TCP;
729 item.mask = &tcp_mask;
732 return flow_dv_convert_modify_action(&item, field, NULL, resource,
733 MLX5_MODIFICATION_TYPE_SET, error);
737 * Convert modify-header set TTL action to DV specification.
739 * @param[in,out] resource
740 * Pointer to the modify-header resource.
742 * Pointer to action specification.
744 * Pointer to rte_flow_item objects list.
746 * Pointer to flow attributes structure.
747 * @param[in] dev_flow
748 * Pointer to the sub flow.
749 * @param[in] tunnel_decap
750 * Whether action is after tunnel decapsulation.
752 * Pointer to the error structure.
755 * 0 on success, a negative errno value otherwise and rte_errno is set.
758 flow_dv_convert_action_modify_ttl
759 (struct mlx5_flow_dv_modify_hdr_resource *resource,
760 const struct rte_flow_action *action,
761 const struct rte_flow_item *items,
762 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
763 bool tunnel_decap, struct rte_flow_error *error)
765 const struct rte_flow_action_set_ttl *conf =
766 (const struct rte_flow_action_set_ttl *)(action->conf);
767 struct rte_flow_item item;
768 struct rte_flow_item_ipv4 ipv4;
769 struct rte_flow_item_ipv4 ipv4_mask;
770 struct rte_flow_item_ipv6 ipv6;
771 struct rte_flow_item_ipv6 ipv6_mask;
772 struct field_modify_info *field;
775 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
777 memset(&ipv4, 0, sizeof(ipv4));
778 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
779 ipv4.hdr.time_to_live = conf->ttl_value;
780 ipv4_mask.hdr.time_to_live = 0xFF;
781 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
783 item.mask = &ipv4_mask;
786 MLX5_ASSERT(attr->ipv6);
787 memset(&ipv6, 0, sizeof(ipv6));
788 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
789 ipv6.hdr.hop_limits = conf->ttl_value;
790 ipv6_mask.hdr.hop_limits = 0xFF;
791 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
793 item.mask = &ipv6_mask;
796 return flow_dv_convert_modify_action(&item, field, NULL, resource,
797 MLX5_MODIFICATION_TYPE_SET, error);
801 * Convert modify-header decrement TTL action to DV specification.
803 * @param[in,out] resource
804 * Pointer to the modify-header resource.
806 * Pointer to action specification.
808 * Pointer to rte_flow_item objects list.
810 * Pointer to flow attributes structure.
811 * @param[in] dev_flow
812 * Pointer to the sub flow.
813 * @param[in] tunnel_decap
814 * Whether action is after tunnel decapsulation.
816 * Pointer to the error structure.
819 * 0 on success, a negative errno value otherwise and rte_errno is set.
822 flow_dv_convert_action_modify_dec_ttl
823 (struct mlx5_flow_dv_modify_hdr_resource *resource,
824 const struct rte_flow_item *items,
825 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
826 bool tunnel_decap, struct rte_flow_error *error)
828 struct rte_flow_item item;
829 struct rte_flow_item_ipv4 ipv4;
830 struct rte_flow_item_ipv4 ipv4_mask;
831 struct rte_flow_item_ipv6 ipv6;
832 struct rte_flow_item_ipv6 ipv6_mask;
833 struct field_modify_info *field;
836 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
838 memset(&ipv4, 0, sizeof(ipv4));
839 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
840 ipv4.hdr.time_to_live = 0xFF;
841 ipv4_mask.hdr.time_to_live = 0xFF;
842 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
844 item.mask = &ipv4_mask;
847 MLX5_ASSERT(attr->ipv6);
848 memset(&ipv6, 0, sizeof(ipv6));
849 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
850 ipv6.hdr.hop_limits = 0xFF;
851 ipv6_mask.hdr.hop_limits = 0xFF;
852 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
854 item.mask = &ipv6_mask;
857 return flow_dv_convert_modify_action(&item, field, NULL, resource,
858 MLX5_MODIFICATION_TYPE_ADD, error);
862 * Convert modify-header increment/decrement TCP Sequence number
863 * to DV specification.
865 * @param[in,out] resource
866 * Pointer to the modify-header resource.
868 * Pointer to action specification.
870 * Pointer to the error structure.
873 * 0 on success, a negative errno value otherwise and rte_errno is set.
876 flow_dv_convert_action_modify_tcp_seq
877 (struct mlx5_flow_dv_modify_hdr_resource *resource,
878 const struct rte_flow_action *action,
879 struct rte_flow_error *error)
881 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
882 uint64_t value = rte_be_to_cpu_32(*conf);
883 struct rte_flow_item item;
884 struct rte_flow_item_tcp tcp;
885 struct rte_flow_item_tcp tcp_mask;
887 memset(&tcp, 0, sizeof(tcp));
888 memset(&tcp_mask, 0, sizeof(tcp_mask));
889 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
891 * The HW has no decrement operation, only increment operation.
892 * To simulate decrement X from Y using increment operation
893 * we need to add UINT32_MAX X times to Y.
894 * Each adding of UINT32_MAX decrements Y by 1.
897 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
898 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
899 item.type = RTE_FLOW_ITEM_TYPE_TCP;
901 item.mask = &tcp_mask;
902 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
903 MLX5_MODIFICATION_TYPE_ADD, error);
907 * Convert modify-header increment/decrement TCP Acknowledgment number
908 * to DV specification.
910 * @param[in,out] resource
911 * Pointer to the modify-header resource.
913 * Pointer to action specification.
915 * Pointer to the error structure.
918 * 0 on success, a negative errno value otherwise and rte_errno is set.
921 flow_dv_convert_action_modify_tcp_ack
922 (struct mlx5_flow_dv_modify_hdr_resource *resource,
923 const struct rte_flow_action *action,
924 struct rte_flow_error *error)
926 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
927 uint64_t value = rte_be_to_cpu_32(*conf);
928 struct rte_flow_item item;
929 struct rte_flow_item_tcp tcp;
930 struct rte_flow_item_tcp tcp_mask;
932 memset(&tcp, 0, sizeof(tcp));
933 memset(&tcp_mask, 0, sizeof(tcp_mask));
934 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
936 * The HW has no decrement operation, only increment operation.
937 * To simulate decrement X from Y using increment operation
938 * we need to add UINT32_MAX X times to Y.
939 * Each adding of UINT32_MAX decrements Y by 1.
942 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
943 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
944 item.type = RTE_FLOW_ITEM_TYPE_TCP;
946 item.mask = &tcp_mask;
947 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
948 MLX5_MODIFICATION_TYPE_ADD, error);
951 static enum mlx5_modification_field reg_to_field[] = {
952 [REG_NONE] = MLX5_MODI_OUT_NONE,
953 [REG_A] = MLX5_MODI_META_DATA_REG_A,
954 [REG_B] = MLX5_MODI_META_DATA_REG_B,
955 [REG_C_0] = MLX5_MODI_META_REG_C_0,
956 [REG_C_1] = MLX5_MODI_META_REG_C_1,
957 [REG_C_2] = MLX5_MODI_META_REG_C_2,
958 [REG_C_3] = MLX5_MODI_META_REG_C_3,
959 [REG_C_4] = MLX5_MODI_META_REG_C_4,
960 [REG_C_5] = MLX5_MODI_META_REG_C_5,
961 [REG_C_6] = MLX5_MODI_META_REG_C_6,
962 [REG_C_7] = MLX5_MODI_META_REG_C_7,
966 * Convert register set to DV specification.
968 * @param[in,out] resource
969 * Pointer to the modify-header resource.
971 * Pointer to action specification.
973 * Pointer to the error structure.
976 * 0 on success, a negative errno value otherwise and rte_errno is set.
979 flow_dv_convert_action_set_reg
980 (struct mlx5_flow_dv_modify_hdr_resource *resource,
981 const struct rte_flow_action *action,
982 struct rte_flow_error *error)
984 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
985 struct mlx5_modification_cmd *actions = resource->actions;
986 uint32_t i = resource->actions_num;
988 if (i >= MLX5_MAX_MODIFY_NUM)
989 return rte_flow_error_set(error, EINVAL,
990 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
991 "too many items to modify");
992 MLX5_ASSERT(conf->id != REG_NONE);
993 MLX5_ASSERT(conf->id < RTE_DIM(reg_to_field));
994 actions[i] = (struct mlx5_modification_cmd) {
995 .action_type = MLX5_MODIFICATION_TYPE_SET,
996 .field = reg_to_field[conf->id],
998 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
999 actions[i].data1 = rte_cpu_to_be_32(conf->data);
1001 resource->actions_num = i;
1006 * Convert SET_TAG action to DV specification.
1009 * Pointer to the rte_eth_dev structure.
1010 * @param[in,out] resource
1011 * Pointer to the modify-header resource.
1013 * Pointer to action specification.
1015 * Pointer to the error structure.
1018 * 0 on success, a negative errno value otherwise and rte_errno is set.
1021 flow_dv_convert_action_set_tag
1022 (struct rte_eth_dev *dev,
1023 struct mlx5_flow_dv_modify_hdr_resource *resource,
1024 const struct rte_flow_action_set_tag *conf,
1025 struct rte_flow_error *error)
1027 rte_be32_t data = rte_cpu_to_be_32(conf->data);
1028 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1029 struct rte_flow_item item = {
1033 struct field_modify_info reg_c_x[] = {
1036 enum mlx5_modification_field reg_type;
1039 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1042 MLX5_ASSERT(ret != REG_NONE);
1043 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1044 reg_type = reg_to_field[ret];
1045 MLX5_ASSERT(reg_type > 0);
1046 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1047 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1048 MLX5_MODIFICATION_TYPE_SET, error);
1052 * Convert internal COPY_REG action to DV specification.
1055 * Pointer to the rte_eth_dev structure.
1056 * @param[in,out] res
1057 * Pointer to the modify-header resource.
1059 * Pointer to action specification.
1061 * Pointer to the error structure.
1064 * 0 on success, a negative errno value otherwise and rte_errno is set.
1067 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1068 struct mlx5_flow_dv_modify_hdr_resource *res,
1069 const struct rte_flow_action *action,
1070 struct rte_flow_error *error)
1072 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1073 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1074 struct rte_flow_item item = {
1078 struct field_modify_info reg_src[] = {
1079 {4, 0, reg_to_field[conf->src]},
1082 struct field_modify_info reg_dst = {
1084 .id = reg_to_field[conf->dst],
1086 /* Adjust reg_c[0] usage according to reported mask. */
1087 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1088 struct mlx5_priv *priv = dev->data->dev_private;
1089 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1091 MLX5_ASSERT(reg_c0);
1092 MLX5_ASSERT(priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1093 if (conf->dst == REG_C_0) {
1094 /* Copy to reg_c[0], within mask only. */
1095 reg_dst.offset = rte_bsf32(reg_c0);
1097 * Mask is ignoring the enianness, because
1098 * there is no conversion in datapath.
1100 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1101 /* Copy from destination lower bits to reg_c[0]. */
1102 mask = reg_c0 >> reg_dst.offset;
1104 /* Copy from destination upper bits to reg_c[0]. */
1105 mask = reg_c0 << (sizeof(reg_c0) * CHAR_BIT -
1106 rte_fls_u32(reg_c0));
1109 mask = rte_cpu_to_be_32(reg_c0);
1110 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1111 /* Copy from reg_c[0] to destination lower bits. */
1114 /* Copy from reg_c[0] to destination upper bits. */
1115 reg_dst.offset = sizeof(reg_c0) * CHAR_BIT -
1116 (rte_fls_u32(reg_c0) -
1121 return flow_dv_convert_modify_action(&item,
1122 reg_src, ®_dst, res,
1123 MLX5_MODIFICATION_TYPE_COPY,
1128 * Convert MARK action to DV specification. This routine is used
1129 * in extensive metadata only and requires metadata register to be
1130 * handled. In legacy mode hardware tag resource is engaged.
1133 * Pointer to the rte_eth_dev structure.
1135 * Pointer to MARK action specification.
1136 * @param[in,out] resource
1137 * Pointer to the modify-header resource.
1139 * Pointer to the error structure.
1142 * 0 on success, a negative errno value otherwise and rte_errno is set.
1145 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1146 const struct rte_flow_action_mark *conf,
1147 struct mlx5_flow_dv_modify_hdr_resource *resource,
1148 struct rte_flow_error *error)
1150 struct mlx5_priv *priv = dev->data->dev_private;
1151 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1152 priv->sh->dv_mark_mask);
1153 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1154 struct rte_flow_item item = {
1158 struct field_modify_info reg_c_x[] = {
1159 {4, 0, 0}, /* dynamic instead of MLX5_MODI_META_REG_C_1. */
1165 return rte_flow_error_set(error, EINVAL,
1166 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1167 NULL, "zero mark action mask");
1168 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1171 MLX5_ASSERT(reg > 0);
1172 if (reg == REG_C_0) {
1173 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1174 uint32_t shl_c0 = rte_bsf32(msk_c0);
1176 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1177 mask = rte_cpu_to_be_32(mask) & msk_c0;
1178 mask = rte_cpu_to_be_32(mask << shl_c0);
1180 reg_c_x[0].id = reg_to_field[reg];
1181 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1182 MLX5_MODIFICATION_TYPE_SET, error);
1186 * Get metadata register index for specified steering domain.
1189 * Pointer to the rte_eth_dev structure.
1191 * Attributes of flow to determine steering domain.
1193 * Pointer to the error structure.
1196 * positive index on success, a negative errno value otherwise
1197 * and rte_errno is set.
1199 static enum modify_reg
1200 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1201 const struct rte_flow_attr *attr,
1202 struct rte_flow_error *error)
1205 mlx5_flow_get_reg_id(dev, attr->transfer ?
1209 MLX5_METADATA_RX, 0, error);
1211 return rte_flow_error_set(error,
1212 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1213 NULL, "unavailable "
1214 "metadata register");
1219 * Convert SET_META action to DV specification.
1222 * Pointer to the rte_eth_dev structure.
1223 * @param[in,out] resource
1224 * Pointer to the modify-header resource.
1226 * Attributes of flow that includes this item.
1228 * Pointer to action specification.
1230 * Pointer to the error structure.
1233 * 0 on success, a negative errno value otherwise and rte_errno is set.
1236 flow_dv_convert_action_set_meta
1237 (struct rte_eth_dev *dev,
1238 struct mlx5_flow_dv_modify_hdr_resource *resource,
1239 const struct rte_flow_attr *attr,
1240 const struct rte_flow_action_set_meta *conf,
1241 struct rte_flow_error *error)
1243 uint32_t data = conf->data;
1244 uint32_t mask = conf->mask;
1245 struct rte_flow_item item = {
1249 struct field_modify_info reg_c_x[] = {
1252 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1257 * In datapath code there is no endianness
1258 * coversions for perfromance reasons, all
1259 * pattern conversions are done in rte_flow.
1261 if (reg == REG_C_0) {
1262 struct mlx5_priv *priv = dev->data->dev_private;
1263 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1266 MLX5_ASSERT(msk_c0);
1267 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1268 shl_c0 = rte_bsf32(msk_c0);
1270 shl_c0 = sizeof(msk_c0) * CHAR_BIT - rte_fls_u32(msk_c0);
1274 MLX5_ASSERT(!(~msk_c0 & rte_cpu_to_be_32(mask)));
1276 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1277 /* The routine expects parameters in memory as big-endian ones. */
1278 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1279 MLX5_MODIFICATION_TYPE_SET, error);
1283 * Convert modify-header set IPv4 DSCP action to DV specification.
1285 * @param[in,out] resource
1286 * Pointer to the modify-header resource.
1288 * Pointer to action specification.
1290 * Pointer to the error structure.
1293 * 0 on success, a negative errno value otherwise and rte_errno is set.
1296 flow_dv_convert_action_modify_ipv4_dscp
1297 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1298 const struct rte_flow_action *action,
1299 struct rte_flow_error *error)
1301 const struct rte_flow_action_set_dscp *conf =
1302 (const struct rte_flow_action_set_dscp *)(action->conf);
1303 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1304 struct rte_flow_item_ipv4 ipv4;
1305 struct rte_flow_item_ipv4 ipv4_mask;
1307 memset(&ipv4, 0, sizeof(ipv4));
1308 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1309 ipv4.hdr.type_of_service = conf->dscp;
1310 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1312 item.mask = &ipv4_mask;
1313 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1314 MLX5_MODIFICATION_TYPE_SET, error);
1318 * Convert modify-header set IPv6 DSCP action to DV specification.
1320 * @param[in,out] resource
1321 * Pointer to the modify-header resource.
1323 * Pointer to action specification.
1325 * Pointer to the error structure.
1328 * 0 on success, a negative errno value otherwise and rte_errno is set.
1331 flow_dv_convert_action_modify_ipv6_dscp
1332 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1333 const struct rte_flow_action *action,
1334 struct rte_flow_error *error)
1336 const struct rte_flow_action_set_dscp *conf =
1337 (const struct rte_flow_action_set_dscp *)(action->conf);
1338 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1339 struct rte_flow_item_ipv6 ipv6;
1340 struct rte_flow_item_ipv6 ipv6_mask;
1342 memset(&ipv6, 0, sizeof(ipv6));
1343 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1345 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1346 * rdma-core only accept the DSCP bits byte aligned start from
1347 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1348 * bits in IPv6 case as rdma-core requires byte aligned value.
1350 ipv6.hdr.vtc_flow = conf->dscp;
1351 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1353 item.mask = &ipv6_mask;
1354 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1355 MLX5_MODIFICATION_TYPE_SET, error);
1359 * Validate MARK item.
1362 * Pointer to the rte_eth_dev structure.
1364 * Item specification.
1366 * Attributes of flow that includes this item.
1368 * Pointer to error structure.
1371 * 0 on success, a negative errno value otherwise and rte_errno is set.
1374 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1375 const struct rte_flow_item *item,
1376 const struct rte_flow_attr *attr __rte_unused,
1377 struct rte_flow_error *error)
1379 struct mlx5_priv *priv = dev->data->dev_private;
1380 struct mlx5_dev_config *config = &priv->config;
1381 const struct rte_flow_item_mark *spec = item->spec;
1382 const struct rte_flow_item_mark *mask = item->mask;
1383 const struct rte_flow_item_mark nic_mask = {
1384 .id = priv->sh->dv_mark_mask,
1388 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1389 return rte_flow_error_set(error, ENOTSUP,
1390 RTE_FLOW_ERROR_TYPE_ITEM, item,
1391 "extended metadata feature"
1393 if (!mlx5_flow_ext_mreg_supported(dev))
1394 return rte_flow_error_set(error, ENOTSUP,
1395 RTE_FLOW_ERROR_TYPE_ITEM, item,
1396 "extended metadata register"
1397 " isn't supported");
1399 return rte_flow_error_set(error, ENOTSUP,
1400 RTE_FLOW_ERROR_TYPE_ITEM, item,
1401 "extended metadata register"
1402 " isn't available");
1403 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1407 return rte_flow_error_set(error, EINVAL,
1408 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1410 "data cannot be empty");
1411 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1412 return rte_flow_error_set(error, EINVAL,
1413 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1415 "mark id exceeds the limit");
1419 return rte_flow_error_set(error, EINVAL,
1420 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1421 "mask cannot be zero");
1423 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1424 (const uint8_t *)&nic_mask,
1425 sizeof(struct rte_flow_item_mark),
1433 * Validate META item.
1436 * Pointer to the rte_eth_dev structure.
1438 * Item specification.
1440 * Attributes of flow that includes this item.
1442 * Pointer to error structure.
1445 * 0 on success, a negative errno value otherwise and rte_errno is set.
1448 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1449 const struct rte_flow_item *item,
1450 const struct rte_flow_attr *attr,
1451 struct rte_flow_error *error)
1453 struct mlx5_priv *priv = dev->data->dev_private;
1454 struct mlx5_dev_config *config = &priv->config;
1455 const struct rte_flow_item_meta *spec = item->spec;
1456 const struct rte_flow_item_meta *mask = item->mask;
1457 struct rte_flow_item_meta nic_mask = {
1464 return rte_flow_error_set(error, EINVAL,
1465 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1467 "data cannot be empty");
1468 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1469 if (!mlx5_flow_ext_mreg_supported(dev))
1470 return rte_flow_error_set(error, ENOTSUP,
1471 RTE_FLOW_ERROR_TYPE_ITEM, item,
1472 "extended metadata register"
1473 " isn't supported");
1474 reg = flow_dv_get_metadata_reg(dev, attr, error);
1478 return rte_flow_error_set(error, ENOTSUP,
1479 RTE_FLOW_ERROR_TYPE_ITEM, item,
1483 nic_mask.data = priv->sh->dv_meta_mask;
1486 mask = &rte_flow_item_meta_mask;
1488 return rte_flow_error_set(error, EINVAL,
1489 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1490 "mask cannot be zero");
1492 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1493 (const uint8_t *)&nic_mask,
1494 sizeof(struct rte_flow_item_meta),
1500 * Validate TAG item.
1503 * Pointer to the rte_eth_dev structure.
1505 * Item specification.
1507 * Attributes of flow that includes this item.
1509 * Pointer to error structure.
1512 * 0 on success, a negative errno value otherwise and rte_errno is set.
1515 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
1516 const struct rte_flow_item *item,
1517 const struct rte_flow_attr *attr __rte_unused,
1518 struct rte_flow_error *error)
1520 const struct rte_flow_item_tag *spec = item->spec;
1521 const struct rte_flow_item_tag *mask = item->mask;
1522 const struct rte_flow_item_tag nic_mask = {
1523 .data = RTE_BE32(UINT32_MAX),
1528 if (!mlx5_flow_ext_mreg_supported(dev))
1529 return rte_flow_error_set(error, ENOTSUP,
1530 RTE_FLOW_ERROR_TYPE_ITEM, item,
1531 "extensive metadata register"
1532 " isn't supported");
1534 return rte_flow_error_set(error, EINVAL,
1535 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1537 "data cannot be empty");
1539 mask = &rte_flow_item_tag_mask;
1541 return rte_flow_error_set(error, EINVAL,
1542 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1543 "mask cannot be zero");
1545 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1546 (const uint8_t *)&nic_mask,
1547 sizeof(struct rte_flow_item_tag),
1551 if (mask->index != 0xff)
1552 return rte_flow_error_set(error, EINVAL,
1553 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1554 "partial mask for tag index"
1555 " is not supported");
1556 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
1559 MLX5_ASSERT(ret != REG_NONE);
1564 * Validate vport item.
1567 * Pointer to the rte_eth_dev structure.
1569 * Item specification.
1571 * Attributes of flow that includes this item.
1572 * @param[in] item_flags
1573 * Bit-fields that holds the items detected until now.
1575 * Pointer to error structure.
1578 * 0 on success, a negative errno value otherwise and rte_errno is set.
1581 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
1582 const struct rte_flow_item *item,
1583 const struct rte_flow_attr *attr,
1584 uint64_t item_flags,
1585 struct rte_flow_error *error)
1587 const struct rte_flow_item_port_id *spec = item->spec;
1588 const struct rte_flow_item_port_id *mask = item->mask;
1589 const struct rte_flow_item_port_id switch_mask = {
1592 struct mlx5_priv *esw_priv;
1593 struct mlx5_priv *dev_priv;
1596 if (!attr->transfer)
1597 return rte_flow_error_set(error, EINVAL,
1598 RTE_FLOW_ERROR_TYPE_ITEM,
1600 "match on port id is valid only"
1601 " when transfer flag is enabled");
1602 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
1603 return rte_flow_error_set(error, ENOTSUP,
1604 RTE_FLOW_ERROR_TYPE_ITEM, item,
1605 "multiple source ports are not"
1608 mask = &switch_mask;
1609 if (mask->id != 0xffffffff)
1610 return rte_flow_error_set(error, ENOTSUP,
1611 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
1613 "no support for partial mask on"
1615 ret = mlx5_flow_item_acceptable
1616 (item, (const uint8_t *)mask,
1617 (const uint8_t *)&rte_flow_item_port_id_mask,
1618 sizeof(struct rte_flow_item_port_id),
1624 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
1626 return rte_flow_error_set(error, rte_errno,
1627 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1628 "failed to obtain E-Switch info for"
1630 dev_priv = mlx5_dev_to_eswitch_info(dev);
1632 return rte_flow_error_set(error, rte_errno,
1633 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1635 "failed to obtain E-Switch info");
1636 if (esw_priv->domain_id != dev_priv->domain_id)
1637 return rte_flow_error_set(error, EINVAL,
1638 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1639 "cannot match on a port from a"
1640 " different E-Switch");
1645 * Validate GTP item.
1648 * Pointer to the rte_eth_dev structure.
1650 * Item specification.
1651 * @param[in] item_flags
1652 * Bit-fields that holds the items detected until now.
1654 * Pointer to error structure.
1657 * 0 on success, a negative errno value otherwise and rte_errno is set.
1660 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
1661 const struct rte_flow_item *item,
1662 uint64_t item_flags,
1663 struct rte_flow_error *error)
1665 struct mlx5_priv *priv = dev->data->dev_private;
1666 const struct rte_flow_item_gtp *mask = item->mask;
1667 const struct rte_flow_item_gtp nic_mask = {
1669 .teid = RTE_BE32(0xffffffff),
1672 if (!priv->config.hca_attr.tunnel_stateless_gtp)
1673 return rte_flow_error_set(error, ENOTSUP,
1674 RTE_FLOW_ERROR_TYPE_ITEM, item,
1675 "GTP support is not enabled");
1676 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1677 return rte_flow_error_set(error, ENOTSUP,
1678 RTE_FLOW_ERROR_TYPE_ITEM, item,
1679 "multiple tunnel layers not"
1681 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1682 return rte_flow_error_set(error, EINVAL,
1683 RTE_FLOW_ERROR_TYPE_ITEM, item,
1684 "no outer UDP layer found");
1686 mask = &rte_flow_item_gtp_mask;
1687 return mlx5_flow_item_acceptable
1688 (item, (const uint8_t *)mask,
1689 (const uint8_t *)&nic_mask,
1690 sizeof(struct rte_flow_item_gtp),
1695 * Validate the pop VLAN action.
1698 * Pointer to the rte_eth_dev structure.
1699 * @param[in] action_flags
1700 * Holds the actions detected until now.
1702 * Pointer to the pop vlan action.
1703 * @param[in] item_flags
1704 * The items found in this flow rule.
1706 * Pointer to flow attributes.
1708 * Pointer to error structure.
1711 * 0 on success, a negative errno value otherwise and rte_errno is set.
1714 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
1715 uint64_t action_flags,
1716 const struct rte_flow_action *action,
1717 uint64_t item_flags,
1718 const struct rte_flow_attr *attr,
1719 struct rte_flow_error *error)
1721 const struct mlx5_priv *priv = dev->data->dev_private;
1725 if (!priv->sh->pop_vlan_action)
1726 return rte_flow_error_set(error, ENOTSUP,
1727 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1729 "pop vlan action is not supported");
1731 return rte_flow_error_set(error, ENOTSUP,
1732 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1734 "pop vlan action not supported for "
1736 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
1737 return rte_flow_error_set(error, ENOTSUP,
1738 RTE_FLOW_ERROR_TYPE_ACTION, action,
1739 "no support for multiple VLAN "
1741 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1742 return rte_flow_error_set(error, ENOTSUP,
1743 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1745 "cannot pop vlan without a "
1746 "match on (outer) vlan in the flow");
1747 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1748 return rte_flow_error_set(error, EINVAL,
1749 RTE_FLOW_ERROR_TYPE_ACTION, action,
1750 "wrong action order, port_id should "
1751 "be after pop VLAN action");
1752 if (!attr->transfer && priv->representor)
1753 return rte_flow_error_set(error, ENOTSUP,
1754 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1755 "pop vlan action for VF representor "
1756 "not supported on NIC table");
1761 * Get VLAN default info from vlan match info.
1764 * the list of item specifications.
1766 * pointer VLAN info to fill to.
1769 * 0 on success, a negative errno value otherwise and rte_errno is set.
1772 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
1773 struct rte_vlan_hdr *vlan)
1775 const struct rte_flow_item_vlan nic_mask = {
1776 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
1777 MLX5DV_FLOW_VLAN_VID_MASK),
1778 .inner_type = RTE_BE16(0xffff),
1783 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
1784 int type = items->type;
1786 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
1787 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
1790 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
1791 const struct rte_flow_item_vlan *vlan_m = items->mask;
1792 const struct rte_flow_item_vlan *vlan_v = items->spec;
1796 /* Only full match values are accepted */
1797 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
1798 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
1799 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
1801 rte_be_to_cpu_16(vlan_v->tci &
1802 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
1804 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
1805 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
1806 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
1808 rte_be_to_cpu_16(vlan_v->tci &
1809 MLX5DV_FLOW_VLAN_VID_MASK_BE);
1811 if (vlan_m->inner_type == nic_mask.inner_type)
1812 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
1813 vlan_m->inner_type);
1818 * Validate the push VLAN action.
1821 * Pointer to the rte_eth_dev structure.
1822 * @param[in] action_flags
1823 * Holds the actions detected until now.
1824 * @param[in] item_flags
1825 * The items found in this flow rule.
1827 * Pointer to the action structure.
1829 * Pointer to flow attributes
1831 * Pointer to error structure.
1834 * 0 on success, a negative errno value otherwise and rte_errno is set.
1837 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
1838 uint64_t action_flags,
1839 uint64_t item_flags __rte_unused,
1840 const struct rte_flow_action *action,
1841 const struct rte_flow_attr *attr,
1842 struct rte_flow_error *error)
1844 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
1845 const struct mlx5_priv *priv = dev->data->dev_private;
1847 if (!attr->transfer && attr->ingress)
1848 return rte_flow_error_set(error, ENOTSUP,
1849 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1851 "push VLAN action not supported for "
1853 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
1854 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
1855 return rte_flow_error_set(error, EINVAL,
1856 RTE_FLOW_ERROR_TYPE_ACTION, action,
1857 "invalid vlan ethertype");
1858 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
1859 return rte_flow_error_set(error, ENOTSUP,
1860 RTE_FLOW_ERROR_TYPE_ACTION, action,
1861 "no support for multiple VLAN "
1863 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1864 return rte_flow_error_set(error, EINVAL,
1865 RTE_FLOW_ERROR_TYPE_ACTION, action,
1866 "wrong action order, port_id should "
1867 "be after push VLAN");
1868 if (!attr->transfer && priv->representor)
1869 return rte_flow_error_set(error, ENOTSUP,
1870 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1871 "push vlan action for VF representor "
1872 "not supported on NIC table");
1878 * Validate the set VLAN PCP.
1880 * @param[in] action_flags
1881 * Holds the actions detected until now.
1882 * @param[in] actions
1883 * Pointer to the list of actions remaining in the flow rule.
1885 * Pointer to error structure.
1888 * 0 on success, a negative errno value otherwise and rte_errno is set.
1891 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
1892 const struct rte_flow_action actions[],
1893 struct rte_flow_error *error)
1895 const struct rte_flow_action *action = actions;
1896 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
1898 if (conf->vlan_pcp > 7)
1899 return rte_flow_error_set(error, EINVAL,
1900 RTE_FLOW_ERROR_TYPE_ACTION, action,
1901 "VLAN PCP value is too big");
1902 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
1903 return rte_flow_error_set(error, ENOTSUP,
1904 RTE_FLOW_ERROR_TYPE_ACTION, action,
1905 "set VLAN PCP action must follow "
1906 "the push VLAN action");
1907 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
1908 return rte_flow_error_set(error, ENOTSUP,
1909 RTE_FLOW_ERROR_TYPE_ACTION, action,
1910 "Multiple VLAN PCP modification are "
1912 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1913 return rte_flow_error_set(error, EINVAL,
1914 RTE_FLOW_ERROR_TYPE_ACTION, action,
1915 "wrong action order, port_id should "
1916 "be after set VLAN PCP");
1921 * Validate the set VLAN VID.
1923 * @param[in] item_flags
1924 * Holds the items detected in this rule.
1925 * @param[in] action_flags
1926 * Holds the actions detected until now.
1927 * @param[in] actions
1928 * Pointer to the list of actions remaining in the flow rule.
1930 * Pointer to error structure.
1933 * 0 on success, a negative errno value otherwise and rte_errno is set.
1936 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
1937 uint64_t action_flags,
1938 const struct rte_flow_action actions[],
1939 struct rte_flow_error *error)
1941 const struct rte_flow_action *action = actions;
1942 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
1944 if (conf->vlan_vid > RTE_BE16(0xFFE))
1945 return rte_flow_error_set(error, EINVAL,
1946 RTE_FLOW_ERROR_TYPE_ACTION, action,
1947 "VLAN VID value is too big");
1948 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
1949 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1950 return rte_flow_error_set(error, ENOTSUP,
1951 RTE_FLOW_ERROR_TYPE_ACTION, action,
1952 "set VLAN VID action must follow push"
1953 " VLAN action or match on VLAN item");
1954 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
1955 return rte_flow_error_set(error, ENOTSUP,
1956 RTE_FLOW_ERROR_TYPE_ACTION, action,
1957 "Multiple VLAN VID modifications are "
1959 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1960 return rte_flow_error_set(error, EINVAL,
1961 RTE_FLOW_ERROR_TYPE_ACTION, action,
1962 "wrong action order, port_id should "
1963 "be after set VLAN VID");
1968 * Validate the FLAG action.
1971 * Pointer to the rte_eth_dev structure.
1972 * @param[in] action_flags
1973 * Holds the actions detected until now.
1975 * Pointer to flow attributes
1977 * Pointer to error structure.
1980 * 0 on success, a negative errno value otherwise and rte_errno is set.
1983 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
1984 uint64_t action_flags,
1985 const struct rte_flow_attr *attr,
1986 struct rte_flow_error *error)
1988 struct mlx5_priv *priv = dev->data->dev_private;
1989 struct mlx5_dev_config *config = &priv->config;
1992 /* Fall back if no extended metadata register support. */
1993 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1994 return mlx5_flow_validate_action_flag(action_flags, attr,
1996 /* Extensive metadata mode requires registers. */
1997 if (!mlx5_flow_ext_mreg_supported(dev))
1998 return rte_flow_error_set(error, ENOTSUP,
1999 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2000 "no metadata registers "
2001 "to support flag action");
2002 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
2003 return rte_flow_error_set(error, ENOTSUP,
2004 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2005 "extended metadata register"
2006 " isn't available");
2007 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2010 MLX5_ASSERT(ret > 0);
2011 if (action_flags & MLX5_FLOW_ACTION_MARK)
2012 return rte_flow_error_set(error, EINVAL,
2013 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2014 "can't mark and flag in same flow");
2015 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2016 return rte_flow_error_set(error, EINVAL,
2017 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2019 " actions in same flow");
2024 * Validate MARK action.
2027 * Pointer to the rte_eth_dev structure.
2029 * Pointer to action.
2030 * @param[in] action_flags
2031 * Holds the actions detected until now.
2033 * Pointer to flow attributes
2035 * Pointer to error structure.
2038 * 0 on success, a negative errno value otherwise and rte_errno is set.
2041 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
2042 const struct rte_flow_action *action,
2043 uint64_t action_flags,
2044 const struct rte_flow_attr *attr,
2045 struct rte_flow_error *error)
2047 struct mlx5_priv *priv = dev->data->dev_private;
2048 struct mlx5_dev_config *config = &priv->config;
2049 const struct rte_flow_action_mark *mark = action->conf;
2052 /* Fall back if no extended metadata register support. */
2053 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2054 return mlx5_flow_validate_action_mark(action, action_flags,
2056 /* Extensive metadata mode requires registers. */
2057 if (!mlx5_flow_ext_mreg_supported(dev))
2058 return rte_flow_error_set(error, ENOTSUP,
2059 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2060 "no metadata registers "
2061 "to support mark action");
2062 if (!priv->sh->dv_mark_mask)
2063 return rte_flow_error_set(error, ENOTSUP,
2064 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2065 "extended metadata register"
2066 " isn't available");
2067 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2070 MLX5_ASSERT(ret > 0);
2072 return rte_flow_error_set(error, EINVAL,
2073 RTE_FLOW_ERROR_TYPE_ACTION, action,
2074 "configuration cannot be null");
2075 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
2076 return rte_flow_error_set(error, EINVAL,
2077 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2079 "mark id exceeds the limit");
2080 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2081 return rte_flow_error_set(error, EINVAL,
2082 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2083 "can't flag and mark in same flow");
2084 if (action_flags & MLX5_FLOW_ACTION_MARK)
2085 return rte_flow_error_set(error, EINVAL,
2086 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2087 "can't have 2 mark actions in same"
2093 * Validate SET_META action.
2096 * Pointer to the rte_eth_dev structure.
2098 * Pointer to the action structure.
2099 * @param[in] action_flags
2100 * Holds the actions detected until now.
2102 * Pointer to flow attributes
2104 * Pointer to error structure.
2107 * 0 on success, a negative errno value otherwise and rte_errno is set.
2110 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
2111 const struct rte_flow_action *action,
2112 uint64_t action_flags __rte_unused,
2113 const struct rte_flow_attr *attr,
2114 struct rte_flow_error *error)
2116 const struct rte_flow_action_set_meta *conf;
2117 uint32_t nic_mask = UINT32_MAX;
2120 if (!mlx5_flow_ext_mreg_supported(dev))
2121 return rte_flow_error_set(error, ENOTSUP,
2122 RTE_FLOW_ERROR_TYPE_ACTION, action,
2123 "extended metadata register"
2124 " isn't supported");
2125 reg = flow_dv_get_metadata_reg(dev, attr, error);
2128 if (reg != REG_A && reg != REG_B) {
2129 struct mlx5_priv *priv = dev->data->dev_private;
2131 nic_mask = priv->sh->dv_meta_mask;
2133 if (!(action->conf))
2134 return rte_flow_error_set(error, EINVAL,
2135 RTE_FLOW_ERROR_TYPE_ACTION, action,
2136 "configuration cannot be null");
2137 conf = (const struct rte_flow_action_set_meta *)action->conf;
2139 return rte_flow_error_set(error, EINVAL,
2140 RTE_FLOW_ERROR_TYPE_ACTION, action,
2141 "zero mask doesn't have any effect");
2142 if (conf->mask & ~nic_mask)
2143 return rte_flow_error_set(error, EINVAL,
2144 RTE_FLOW_ERROR_TYPE_ACTION, action,
2145 "meta data must be within reg C0");
2150 * Validate SET_TAG action.
2153 * Pointer to the rte_eth_dev structure.
2155 * Pointer to the action structure.
2156 * @param[in] action_flags
2157 * Holds the actions detected until now.
2159 * Pointer to flow attributes
2161 * Pointer to error structure.
2164 * 0 on success, a negative errno value otherwise and rte_errno is set.
2167 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
2168 const struct rte_flow_action *action,
2169 uint64_t action_flags,
2170 const struct rte_flow_attr *attr,
2171 struct rte_flow_error *error)
2173 const struct rte_flow_action_set_tag *conf;
2174 const uint64_t terminal_action_flags =
2175 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
2176 MLX5_FLOW_ACTION_RSS;
2179 if (!mlx5_flow_ext_mreg_supported(dev))
2180 return rte_flow_error_set(error, ENOTSUP,
2181 RTE_FLOW_ERROR_TYPE_ACTION, action,
2182 "extensive metadata register"
2183 " isn't supported");
2184 if (!(action->conf))
2185 return rte_flow_error_set(error, EINVAL,
2186 RTE_FLOW_ERROR_TYPE_ACTION, action,
2187 "configuration cannot be null");
2188 conf = (const struct rte_flow_action_set_tag *)action->conf;
2190 return rte_flow_error_set(error, EINVAL,
2191 RTE_FLOW_ERROR_TYPE_ACTION, action,
2192 "zero mask doesn't have any effect");
2193 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
2196 if (!attr->transfer && attr->ingress &&
2197 (action_flags & terminal_action_flags))
2198 return rte_flow_error_set(error, EINVAL,
2199 RTE_FLOW_ERROR_TYPE_ACTION, action,
2200 "set_tag has no effect"
2201 " with terminal actions");
2206 * Validate count action.
2209 * Pointer to rte_eth_dev structure.
2211 * Pointer to error structure.
2214 * 0 on success, a negative errno value otherwise and rte_errno is set.
2217 flow_dv_validate_action_count(struct rte_eth_dev *dev,
2218 struct rte_flow_error *error)
2220 struct mlx5_priv *priv = dev->data->dev_private;
2222 if (!priv->config.devx)
2224 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
2228 return rte_flow_error_set
2230 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2232 "count action not supported");
2236 * Validate the L2 encap action.
2239 * Pointer to the rte_eth_dev structure.
2240 * @param[in] action_flags
2241 * Holds the actions detected until now.
2243 * Pointer to the action structure.
2245 * Pointer to flow attributes.
2247 * Pointer to error structure.
2250 * 0 on success, a negative errno value otherwise and rte_errno is set.
2253 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
2254 uint64_t action_flags,
2255 const struct rte_flow_action *action,
2256 const struct rte_flow_attr *attr,
2257 struct rte_flow_error *error)
2259 const struct mlx5_priv *priv = dev->data->dev_private;
2261 if (!(action->conf))
2262 return rte_flow_error_set(error, EINVAL,
2263 RTE_FLOW_ERROR_TYPE_ACTION, action,
2264 "configuration cannot be null");
2265 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
2266 return rte_flow_error_set(error, EINVAL,
2267 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2268 "can only have a single encap action "
2270 if (!attr->transfer && priv->representor)
2271 return rte_flow_error_set(error, ENOTSUP,
2272 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2273 "encap action for VF representor "
2274 "not supported on NIC table");
2279 * Validate a decap action.
2282 * Pointer to the rte_eth_dev structure.
2283 * @param[in] action_flags
2284 * Holds the actions detected until now.
2286 * Pointer to flow attributes
2288 * Pointer to error structure.
2291 * 0 on success, a negative errno value otherwise and rte_errno is set.
2294 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
2295 uint64_t action_flags,
2296 const struct rte_flow_attr *attr,
2297 struct rte_flow_error *error)
2299 const struct mlx5_priv *priv = dev->data->dev_private;
2301 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
2302 return rte_flow_error_set(error, ENOTSUP,
2303 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2305 MLX5_FLOW_ACTION_DECAP ? "can only "
2306 "have a single decap action" : "decap "
2307 "after encap is not supported");
2308 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
2309 return rte_flow_error_set(error, EINVAL,
2310 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2311 "can't have decap action after"
2314 return rte_flow_error_set(error, ENOTSUP,
2315 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2317 "decap action not supported for "
2319 if (!attr->transfer && priv->representor)
2320 return rte_flow_error_set(error, ENOTSUP,
2321 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2322 "decap action for VF representor "
2323 "not supported on NIC table");
2327 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
2330 * Validate the raw encap and decap actions.
2333 * Pointer to the rte_eth_dev structure.
2335 * Pointer to the decap action.
2337 * Pointer to the encap action.
2339 * Pointer to flow attributes
2340 * @param[in/out] action_flags
2341 * Holds the actions detected until now.
2342 * @param[out] actions_n
2343 * pointer to the number of actions counter.
2345 * Pointer to error structure.
2348 * 0 on success, a negative errno value otherwise and rte_errno is set.
2351 flow_dv_validate_action_raw_encap_decap
2352 (struct rte_eth_dev *dev,
2353 const struct rte_flow_action_raw_decap *decap,
2354 const struct rte_flow_action_raw_encap *encap,
2355 const struct rte_flow_attr *attr, uint64_t *action_flags,
2356 int *actions_n, struct rte_flow_error *error)
2358 const struct mlx5_priv *priv = dev->data->dev_private;
2361 if (encap && (!encap->size || !encap->data))
2362 return rte_flow_error_set(error, EINVAL,
2363 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2364 "raw encap data cannot be empty");
2365 if (decap && encap) {
2366 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
2367 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
2370 else if (encap->size <=
2371 MLX5_ENCAPSULATION_DECISION_SIZE &&
2373 MLX5_ENCAPSULATION_DECISION_SIZE)
2376 else if (encap->size >
2377 MLX5_ENCAPSULATION_DECISION_SIZE &&
2379 MLX5_ENCAPSULATION_DECISION_SIZE)
2380 /* 2 L2 actions: encap and decap. */
2383 return rte_flow_error_set(error,
2385 RTE_FLOW_ERROR_TYPE_ACTION,
2386 NULL, "unsupported too small "
2387 "raw decap and too small raw "
2388 "encap combination");
2391 ret = flow_dv_validate_action_decap(dev, *action_flags, attr,
2395 *action_flags |= MLX5_FLOW_ACTION_DECAP;
2399 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
2400 return rte_flow_error_set(error, ENOTSUP,
2401 RTE_FLOW_ERROR_TYPE_ACTION,
2403 "small raw encap size");
2404 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
2405 return rte_flow_error_set(error, EINVAL,
2406 RTE_FLOW_ERROR_TYPE_ACTION,
2408 "more than one encap action");
2409 if (!attr->transfer && priv->representor)
2410 return rte_flow_error_set
2412 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2413 "encap action for VF representor "
2414 "not supported on NIC table");
2415 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
2422 * Find existing encap/decap resource or create and register a new one.
2424 * @param[in, out] dev
2425 * Pointer to rte_eth_dev structure.
2426 * @param[in, out] resource
2427 * Pointer to encap/decap resource.
2428 * @parm[in, out] dev_flow
2429 * Pointer to the dev_flow.
2431 * pointer to error structure.
2434 * 0 on success otherwise -errno and errno is set.
2437 flow_dv_encap_decap_resource_register
2438 (struct rte_eth_dev *dev,
2439 struct mlx5_flow_dv_encap_decap_resource *resource,
2440 struct mlx5_flow *dev_flow,
2441 struct rte_flow_error *error)
2443 struct mlx5_priv *priv = dev->data->dev_private;
2444 struct mlx5_ibv_shared *sh = priv->sh;
2445 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
2446 struct mlx5dv_dr_domain *domain;
2448 resource->flags = dev_flow->dv.group ? 0 : 1;
2449 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2450 domain = sh->fdb_domain;
2451 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2452 domain = sh->rx_domain;
2454 domain = sh->tx_domain;
2455 /* Lookup a matching resource from cache. */
2456 LIST_FOREACH(cache_resource, &sh->encaps_decaps, next) {
2457 if (resource->reformat_type == cache_resource->reformat_type &&
2458 resource->ft_type == cache_resource->ft_type &&
2459 resource->flags == cache_resource->flags &&
2460 resource->size == cache_resource->size &&
2461 !memcmp((const void *)resource->buf,
2462 (const void *)cache_resource->buf,
2464 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d++",
2465 (void *)cache_resource,
2466 rte_atomic32_read(&cache_resource->refcnt));
2467 rte_atomic32_inc(&cache_resource->refcnt);
2468 dev_flow->handle->dvh.encap_decap = cache_resource;
2472 /* Register new encap/decap resource. */
2473 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
2474 if (!cache_resource)
2475 return rte_flow_error_set(error, ENOMEM,
2476 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2477 "cannot allocate resource memory");
2478 *cache_resource = *resource;
2479 cache_resource->verbs_action =
2480 mlx5_glue->dv_create_flow_action_packet_reformat
2481 (sh->ctx, cache_resource->reformat_type,
2482 cache_resource->ft_type, domain, cache_resource->flags,
2483 cache_resource->size,
2484 (cache_resource->size ? cache_resource->buf : NULL));
2485 if (!cache_resource->verbs_action) {
2486 rte_free(cache_resource);
2487 return rte_flow_error_set(error, ENOMEM,
2488 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2489 NULL, "cannot create action");
2491 rte_atomic32_init(&cache_resource->refcnt);
2492 rte_atomic32_inc(&cache_resource->refcnt);
2493 LIST_INSERT_HEAD(&sh->encaps_decaps, cache_resource, next);
2494 dev_flow->handle->dvh.encap_decap = cache_resource;
2495 DRV_LOG(DEBUG, "new encap/decap resource %p: refcnt %d++",
2496 (void *)cache_resource,
2497 rte_atomic32_read(&cache_resource->refcnt));
2502 * Find existing table jump resource or create and register a new one.
2504 * @param[in, out] dev
2505 * Pointer to rte_eth_dev structure.
2506 * @param[in, out] tbl
2507 * Pointer to flow table resource.
2508 * @parm[in, out] dev_flow
2509 * Pointer to the dev_flow.
2511 * pointer to error structure.
2514 * 0 on success otherwise -errno and errno is set.
2517 flow_dv_jump_tbl_resource_register
2518 (struct rte_eth_dev *dev __rte_unused,
2519 struct mlx5_flow_tbl_resource *tbl,
2520 struct mlx5_flow *dev_flow,
2521 struct rte_flow_error *error)
2523 struct mlx5_flow_tbl_data_entry *tbl_data =
2524 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
2528 cnt = rte_atomic32_read(&tbl_data->jump.refcnt);
2530 tbl_data->jump.action =
2531 mlx5_glue->dr_create_flow_action_dest_flow_tbl
2533 if (!tbl_data->jump.action)
2534 return rte_flow_error_set(error, ENOMEM,
2535 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2536 NULL, "cannot create jump action");
2537 DRV_LOG(DEBUG, "new jump table resource %p: refcnt %d++",
2538 (void *)&tbl_data->jump, cnt);
2540 MLX5_ASSERT(tbl_data->jump.action);
2541 DRV_LOG(DEBUG, "existed jump table resource %p: refcnt %d++",
2542 (void *)&tbl_data->jump, cnt);
2544 rte_atomic32_inc(&tbl_data->jump.refcnt);
2545 dev_flow->handle->dvh.jump = &tbl_data->jump;
2550 * Find existing table port ID resource or create and register a new one.
2552 * @param[in, out] dev
2553 * Pointer to rte_eth_dev structure.
2554 * @param[in, out] resource
2555 * Pointer to port ID action resource.
2556 * @parm[in, out] dev_flow
2557 * Pointer to the dev_flow.
2559 * pointer to error structure.
2562 * 0 on success otherwise -errno and errno is set.
2565 flow_dv_port_id_action_resource_register
2566 (struct rte_eth_dev *dev,
2567 struct mlx5_flow_dv_port_id_action_resource *resource,
2568 struct mlx5_flow *dev_flow,
2569 struct rte_flow_error *error)
2571 struct mlx5_priv *priv = dev->data->dev_private;
2572 struct mlx5_ibv_shared *sh = priv->sh;
2573 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
2575 /* Lookup a matching resource from cache. */
2576 LIST_FOREACH(cache_resource, &sh->port_id_action_list, next) {
2577 if (resource->port_id == cache_resource->port_id) {
2578 DRV_LOG(DEBUG, "port id action resource resource %p: "
2580 (void *)cache_resource,
2581 rte_atomic32_read(&cache_resource->refcnt));
2582 rte_atomic32_inc(&cache_resource->refcnt);
2583 dev_flow->handle->dvh.port_id_action = cache_resource;
2587 /* Register new port id action resource. */
2588 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
2589 if (!cache_resource)
2590 return rte_flow_error_set(error, ENOMEM,
2591 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2592 "cannot allocate resource memory");
2593 *cache_resource = *resource;
2595 * Depending on rdma_core version the glue routine calls
2596 * either mlx5dv_dr_action_create_dest_ib_port(domain, ibv_port)
2597 * or mlx5dv_dr_action_create_dest_vport(domain, vport_id).
2599 cache_resource->action =
2600 mlx5_glue->dr_create_flow_action_dest_port
2601 (priv->sh->fdb_domain, resource->port_id);
2602 if (!cache_resource->action) {
2603 rte_free(cache_resource);
2604 return rte_flow_error_set(error, ENOMEM,
2605 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2606 NULL, "cannot create action");
2608 rte_atomic32_init(&cache_resource->refcnt);
2609 rte_atomic32_inc(&cache_resource->refcnt);
2610 LIST_INSERT_HEAD(&sh->port_id_action_list, cache_resource, next);
2611 dev_flow->handle->dvh.port_id_action = cache_resource;
2612 DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++",
2613 (void *)cache_resource,
2614 rte_atomic32_read(&cache_resource->refcnt));
2619 * Find existing push vlan resource or create and register a new one.
2621 * @param [in, out] dev
2622 * Pointer to rte_eth_dev structure.
2623 * @param[in, out] resource
2624 * Pointer to port ID action resource.
2625 * @parm[in, out] dev_flow
2626 * Pointer to the dev_flow.
2628 * pointer to error structure.
2631 * 0 on success otherwise -errno and errno is set.
2634 flow_dv_push_vlan_action_resource_register
2635 (struct rte_eth_dev *dev,
2636 struct mlx5_flow_dv_push_vlan_action_resource *resource,
2637 struct mlx5_flow *dev_flow,
2638 struct rte_flow_error *error)
2640 struct mlx5_priv *priv = dev->data->dev_private;
2641 struct mlx5_ibv_shared *sh = priv->sh;
2642 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
2643 struct mlx5dv_dr_domain *domain;
2645 /* Lookup a matching resource from cache. */
2646 LIST_FOREACH(cache_resource, &sh->push_vlan_action_list, next) {
2647 if (resource->vlan_tag == cache_resource->vlan_tag &&
2648 resource->ft_type == cache_resource->ft_type) {
2649 DRV_LOG(DEBUG, "push-VLAN action resource resource %p: "
2651 (void *)cache_resource,
2652 rte_atomic32_read(&cache_resource->refcnt));
2653 rte_atomic32_inc(&cache_resource->refcnt);
2654 dev_flow->handle->dvh.push_vlan_res = cache_resource;
2658 /* Register new push_vlan action resource. */
2659 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
2660 if (!cache_resource)
2661 return rte_flow_error_set(error, ENOMEM,
2662 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2663 "cannot allocate resource memory");
2664 *cache_resource = *resource;
2665 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2666 domain = sh->fdb_domain;
2667 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2668 domain = sh->rx_domain;
2670 domain = sh->tx_domain;
2671 cache_resource->action =
2672 mlx5_glue->dr_create_flow_action_push_vlan(domain,
2673 resource->vlan_tag);
2674 if (!cache_resource->action) {
2675 rte_free(cache_resource);
2676 return rte_flow_error_set(error, ENOMEM,
2677 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2678 NULL, "cannot create action");
2680 rte_atomic32_init(&cache_resource->refcnt);
2681 rte_atomic32_inc(&cache_resource->refcnt);
2682 LIST_INSERT_HEAD(&sh->push_vlan_action_list, cache_resource, next);
2683 dev_flow->handle->dvh.push_vlan_res = cache_resource;
2684 DRV_LOG(DEBUG, "new push vlan action resource %p: refcnt %d++",
2685 (void *)cache_resource,
2686 rte_atomic32_read(&cache_resource->refcnt));
2690 * Get the size of specific rte_flow_item_type
2692 * @param[in] item_type
2693 * Tested rte_flow_item_type.
2696 * sizeof struct item_type, 0 if void or irrelevant.
2699 flow_dv_get_item_len(const enum rte_flow_item_type item_type)
2703 switch (item_type) {
2704 case RTE_FLOW_ITEM_TYPE_ETH:
2705 retval = sizeof(struct rte_flow_item_eth);
2707 case RTE_FLOW_ITEM_TYPE_VLAN:
2708 retval = sizeof(struct rte_flow_item_vlan);
2710 case RTE_FLOW_ITEM_TYPE_IPV4:
2711 retval = sizeof(struct rte_flow_item_ipv4);
2713 case RTE_FLOW_ITEM_TYPE_IPV6:
2714 retval = sizeof(struct rte_flow_item_ipv6);
2716 case RTE_FLOW_ITEM_TYPE_UDP:
2717 retval = sizeof(struct rte_flow_item_udp);
2719 case RTE_FLOW_ITEM_TYPE_TCP:
2720 retval = sizeof(struct rte_flow_item_tcp);
2722 case RTE_FLOW_ITEM_TYPE_VXLAN:
2723 retval = sizeof(struct rte_flow_item_vxlan);
2725 case RTE_FLOW_ITEM_TYPE_GRE:
2726 retval = sizeof(struct rte_flow_item_gre);
2728 case RTE_FLOW_ITEM_TYPE_NVGRE:
2729 retval = sizeof(struct rte_flow_item_nvgre);
2731 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
2732 retval = sizeof(struct rte_flow_item_vxlan_gpe);
2734 case RTE_FLOW_ITEM_TYPE_MPLS:
2735 retval = sizeof(struct rte_flow_item_mpls);
2737 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
2745 #define MLX5_ENCAP_IPV4_VERSION 0x40
2746 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
2747 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
2748 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
2749 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
2750 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
2751 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
2754 * Convert the encap action data from list of rte_flow_item to raw buffer
2757 * Pointer to rte_flow_item objects list.
2759 * Pointer to the output buffer.
2761 * Pointer to the output buffer size.
2763 * Pointer to the error structure.
2766 * 0 on success, a negative errno value otherwise and rte_errno is set.
2769 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
2770 size_t *size, struct rte_flow_error *error)
2772 struct rte_ether_hdr *eth = NULL;
2773 struct rte_vlan_hdr *vlan = NULL;
2774 struct rte_ipv4_hdr *ipv4 = NULL;
2775 struct rte_ipv6_hdr *ipv6 = NULL;
2776 struct rte_udp_hdr *udp = NULL;
2777 struct rte_vxlan_hdr *vxlan = NULL;
2778 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
2779 struct rte_gre_hdr *gre = NULL;
2781 size_t temp_size = 0;
2784 return rte_flow_error_set(error, EINVAL,
2785 RTE_FLOW_ERROR_TYPE_ACTION,
2786 NULL, "invalid empty data");
2787 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2788 len = flow_dv_get_item_len(items->type);
2789 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
2790 return rte_flow_error_set(error, EINVAL,
2791 RTE_FLOW_ERROR_TYPE_ACTION,
2792 (void *)items->type,
2793 "items total size is too big"
2794 " for encap action");
2795 rte_memcpy((void *)&buf[temp_size], items->spec, len);
2796 switch (items->type) {
2797 case RTE_FLOW_ITEM_TYPE_ETH:
2798 eth = (struct rte_ether_hdr *)&buf[temp_size];
2800 case RTE_FLOW_ITEM_TYPE_VLAN:
2801 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
2803 return rte_flow_error_set(error, EINVAL,
2804 RTE_FLOW_ERROR_TYPE_ACTION,
2805 (void *)items->type,
2806 "eth header not found");
2807 if (!eth->ether_type)
2808 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
2810 case RTE_FLOW_ITEM_TYPE_IPV4:
2811 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
2813 return rte_flow_error_set(error, EINVAL,
2814 RTE_FLOW_ERROR_TYPE_ACTION,
2815 (void *)items->type,
2816 "neither eth nor vlan"
2818 if (vlan && !vlan->eth_proto)
2819 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
2820 else if (eth && !eth->ether_type)
2821 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
2822 if (!ipv4->version_ihl)
2823 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
2824 MLX5_ENCAP_IPV4_IHL_MIN;
2825 if (!ipv4->time_to_live)
2826 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
2828 case RTE_FLOW_ITEM_TYPE_IPV6:
2829 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
2831 return rte_flow_error_set(error, EINVAL,
2832 RTE_FLOW_ERROR_TYPE_ACTION,
2833 (void *)items->type,
2834 "neither eth nor vlan"
2836 if (vlan && !vlan->eth_proto)
2837 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
2838 else if (eth && !eth->ether_type)
2839 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
2840 if (!ipv6->vtc_flow)
2842 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
2843 if (!ipv6->hop_limits)
2844 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
2846 case RTE_FLOW_ITEM_TYPE_UDP:
2847 udp = (struct rte_udp_hdr *)&buf[temp_size];
2849 return rte_flow_error_set(error, EINVAL,
2850 RTE_FLOW_ERROR_TYPE_ACTION,
2851 (void *)items->type,
2852 "ip header not found");
2853 if (ipv4 && !ipv4->next_proto_id)
2854 ipv4->next_proto_id = IPPROTO_UDP;
2855 else if (ipv6 && !ipv6->proto)
2856 ipv6->proto = IPPROTO_UDP;
2858 case RTE_FLOW_ITEM_TYPE_VXLAN:
2859 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
2861 return rte_flow_error_set(error, EINVAL,
2862 RTE_FLOW_ERROR_TYPE_ACTION,
2863 (void *)items->type,
2864 "udp header not found");
2866 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
2867 if (!vxlan->vx_flags)
2869 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
2871 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
2872 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
2874 return rte_flow_error_set(error, EINVAL,
2875 RTE_FLOW_ERROR_TYPE_ACTION,
2876 (void *)items->type,
2877 "udp header not found");
2878 if (!vxlan_gpe->proto)
2879 return rte_flow_error_set(error, EINVAL,
2880 RTE_FLOW_ERROR_TYPE_ACTION,
2881 (void *)items->type,
2882 "next protocol not found");
2885 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
2886 if (!vxlan_gpe->vx_flags)
2887 vxlan_gpe->vx_flags =
2888 MLX5_ENCAP_VXLAN_GPE_FLAGS;
2890 case RTE_FLOW_ITEM_TYPE_GRE:
2891 case RTE_FLOW_ITEM_TYPE_NVGRE:
2892 gre = (struct rte_gre_hdr *)&buf[temp_size];
2894 return rte_flow_error_set(error, EINVAL,
2895 RTE_FLOW_ERROR_TYPE_ACTION,
2896 (void *)items->type,
2897 "next protocol not found");
2899 return rte_flow_error_set(error, EINVAL,
2900 RTE_FLOW_ERROR_TYPE_ACTION,
2901 (void *)items->type,
2902 "ip header not found");
2903 if (ipv4 && !ipv4->next_proto_id)
2904 ipv4->next_proto_id = IPPROTO_GRE;
2905 else if (ipv6 && !ipv6->proto)
2906 ipv6->proto = IPPROTO_GRE;
2908 case RTE_FLOW_ITEM_TYPE_VOID:
2911 return rte_flow_error_set(error, EINVAL,
2912 RTE_FLOW_ERROR_TYPE_ACTION,
2913 (void *)items->type,
2914 "unsupported item type");
2924 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
2926 struct rte_ether_hdr *eth = NULL;
2927 struct rte_vlan_hdr *vlan = NULL;
2928 struct rte_ipv6_hdr *ipv6 = NULL;
2929 struct rte_udp_hdr *udp = NULL;
2933 eth = (struct rte_ether_hdr *)data;
2934 next_hdr = (char *)(eth + 1);
2935 proto = RTE_BE16(eth->ether_type);
2938 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
2939 vlan = (struct rte_vlan_hdr *)next_hdr;
2940 proto = RTE_BE16(vlan->eth_proto);
2941 next_hdr += sizeof(struct rte_vlan_hdr);
2944 /* HW calculates IPv4 csum. no need to proceed */
2945 if (proto == RTE_ETHER_TYPE_IPV4)
2948 /* non IPv4/IPv6 header. not supported */
2949 if (proto != RTE_ETHER_TYPE_IPV6) {
2950 return rte_flow_error_set(error, ENOTSUP,
2951 RTE_FLOW_ERROR_TYPE_ACTION,
2952 NULL, "Cannot offload non IPv4/IPv6");
2955 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
2957 /* ignore non UDP */
2958 if (ipv6->proto != IPPROTO_UDP)
2961 udp = (struct rte_udp_hdr *)(ipv6 + 1);
2962 udp->dgram_cksum = 0;
2968 * Convert L2 encap action to DV specification.
2971 * Pointer to rte_eth_dev structure.
2973 * Pointer to action structure.
2974 * @param[in, out] dev_flow
2975 * Pointer to the mlx5_flow.
2976 * @param[in] transfer
2977 * Mark if the flow is E-Switch flow.
2979 * Pointer to the error structure.
2982 * 0 on success, a negative errno value otherwise and rte_errno is set.
2985 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
2986 const struct rte_flow_action *action,
2987 struct mlx5_flow *dev_flow,
2989 struct rte_flow_error *error)
2991 const struct rte_flow_item *encap_data;
2992 const struct rte_flow_action_raw_encap *raw_encap_data;
2993 struct mlx5_flow_dv_encap_decap_resource res = {
2995 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
2996 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
2997 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
3000 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
3002 (const struct rte_flow_action_raw_encap *)action->conf;
3003 res.size = raw_encap_data->size;
3004 memcpy(res.buf, raw_encap_data->data, res.size);
3006 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
3008 ((const struct rte_flow_action_vxlan_encap *)
3009 action->conf)->definition;
3012 ((const struct rte_flow_action_nvgre_encap *)
3013 action->conf)->definition;
3014 if (flow_dv_convert_encap_data(encap_data, res.buf,
3018 if (flow_dv_zero_encap_udp_csum(res.buf, error))
3020 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3021 return rte_flow_error_set(error, EINVAL,
3022 RTE_FLOW_ERROR_TYPE_ACTION,
3023 NULL, "can't create L2 encap action");
3028 * Convert L2 decap action to DV specification.
3031 * Pointer to rte_eth_dev structure.
3032 * @param[in, out] dev_flow
3033 * Pointer to the mlx5_flow.
3034 * @param[in] transfer
3035 * Mark if the flow is E-Switch flow.
3037 * Pointer to the error structure.
3040 * 0 on success, a negative errno value otherwise and rte_errno is set.
3043 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
3044 struct mlx5_flow *dev_flow,
3046 struct rte_flow_error *error)
3048 struct mlx5_flow_dv_encap_decap_resource res = {
3051 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
3052 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
3053 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
3056 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3057 return rte_flow_error_set(error, EINVAL,
3058 RTE_FLOW_ERROR_TYPE_ACTION,
3059 NULL, "can't create L2 decap action");
3064 * Convert raw decap/encap (L3 tunnel) action to DV specification.
3067 * Pointer to rte_eth_dev structure.
3069 * Pointer to action structure.
3070 * @param[in, out] dev_flow
3071 * Pointer to the mlx5_flow.
3073 * Pointer to the flow attributes.
3075 * Pointer to the error structure.
3078 * 0 on success, a negative errno value otherwise and rte_errno is set.
3081 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
3082 const struct rte_flow_action *action,
3083 struct mlx5_flow *dev_flow,
3084 const struct rte_flow_attr *attr,
3085 struct rte_flow_error *error)
3087 const struct rte_flow_action_raw_encap *encap_data;
3088 struct mlx5_flow_dv_encap_decap_resource res;
3090 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
3091 res.size = encap_data->size;
3092 memcpy(res.buf, encap_data->data, res.size);
3093 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
3094 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
3095 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
3097 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3099 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3100 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3101 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3102 return rte_flow_error_set(error, EINVAL,
3103 RTE_FLOW_ERROR_TYPE_ACTION,
3104 NULL, "can't create encap action");
3109 * Create action push VLAN.
3112 * Pointer to rte_eth_dev structure.
3114 * Pointer to the flow attributes.
3116 * Pointer to the vlan to push to the Ethernet header.
3117 * @param[in, out] dev_flow
3118 * Pointer to the mlx5_flow.
3120 * Pointer to the error structure.
3123 * 0 on success, a negative errno value otherwise and rte_errno is set.
3126 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
3127 const struct rte_flow_attr *attr,
3128 const struct rte_vlan_hdr *vlan,
3129 struct mlx5_flow *dev_flow,
3130 struct rte_flow_error *error)
3132 struct mlx5_flow_dv_push_vlan_action_resource res;
3135 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
3138 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3140 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3141 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3142 return flow_dv_push_vlan_action_resource_register
3143 (dev, &res, dev_flow, error);
3147 * Validate the modify-header actions.
3149 * @param[in] action_flags
3150 * Holds the actions detected until now.
3152 * Pointer to the modify action.
3154 * Pointer to error structure.
3157 * 0 on success, a negative errno value otherwise and rte_errno is set.
3160 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
3161 const struct rte_flow_action *action,
3162 struct rte_flow_error *error)
3164 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
3165 return rte_flow_error_set(error, EINVAL,
3166 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3167 NULL, "action configuration not set");
3168 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3169 return rte_flow_error_set(error, EINVAL,
3170 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3171 "can't have encap action before"
3177 * Validate the modify-header MAC address actions.
3179 * @param[in] action_flags
3180 * Holds the actions detected until now.
3182 * Pointer to the modify action.
3183 * @param[in] item_flags
3184 * Holds the items detected.
3186 * Pointer to error structure.
3189 * 0 on success, a negative errno value otherwise and rte_errno is set.
3192 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
3193 const struct rte_flow_action *action,
3194 const uint64_t item_flags,
3195 struct rte_flow_error *error)
3199 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3201 if (!(item_flags & MLX5_FLOW_LAYER_L2))
3202 return rte_flow_error_set(error, EINVAL,
3203 RTE_FLOW_ERROR_TYPE_ACTION,
3205 "no L2 item in pattern");
3211 * Validate the modify-header IPv4 address actions.
3213 * @param[in] action_flags
3214 * Holds the actions detected until now.
3216 * Pointer to the modify action.
3217 * @param[in] item_flags
3218 * Holds the items detected.
3220 * Pointer to error structure.
3223 * 0 on success, a negative errno value otherwise and rte_errno is set.
3226 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
3227 const struct rte_flow_action *action,
3228 const uint64_t item_flags,
3229 struct rte_flow_error *error)
3234 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3236 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3237 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
3238 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3239 if (!(item_flags & layer))
3240 return rte_flow_error_set(error, EINVAL,
3241 RTE_FLOW_ERROR_TYPE_ACTION,
3243 "no ipv4 item in pattern");
3249 * Validate the modify-header IPv6 address actions.
3251 * @param[in] action_flags
3252 * Holds the actions detected until now.
3254 * Pointer to the modify action.
3255 * @param[in] item_flags
3256 * Holds the items detected.
3258 * Pointer to error structure.
3261 * 0 on success, a negative errno value otherwise and rte_errno is set.
3264 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
3265 const struct rte_flow_action *action,
3266 const uint64_t item_flags,
3267 struct rte_flow_error *error)
3272 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3274 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3275 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
3276 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3277 if (!(item_flags & layer))
3278 return rte_flow_error_set(error, EINVAL,
3279 RTE_FLOW_ERROR_TYPE_ACTION,
3281 "no ipv6 item in pattern");
3287 * Validate the modify-header TP actions.
3289 * @param[in] action_flags
3290 * Holds the actions detected until now.
3292 * Pointer to the modify action.
3293 * @param[in] item_flags
3294 * Holds the items detected.
3296 * Pointer to error structure.
3299 * 0 on success, a negative errno value otherwise and rte_errno is set.
3302 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
3303 const struct rte_flow_action *action,
3304 const uint64_t item_flags,
3305 struct rte_flow_error *error)
3310 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3312 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3313 MLX5_FLOW_LAYER_INNER_L4 :
3314 MLX5_FLOW_LAYER_OUTER_L4;
3315 if (!(item_flags & layer))
3316 return rte_flow_error_set(error, EINVAL,
3317 RTE_FLOW_ERROR_TYPE_ACTION,
3318 NULL, "no transport layer "
3325 * Validate the modify-header actions of increment/decrement
3326 * TCP Sequence-number.
3328 * @param[in] action_flags
3329 * Holds the actions detected until now.
3331 * Pointer to the modify action.
3332 * @param[in] item_flags
3333 * Holds the items detected.
3335 * Pointer to error structure.
3338 * 0 on success, a negative errno value otherwise and rte_errno is set.
3341 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
3342 const struct rte_flow_action *action,
3343 const uint64_t item_flags,
3344 struct rte_flow_error *error)
3349 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3351 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3352 MLX5_FLOW_LAYER_INNER_L4_TCP :
3353 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3354 if (!(item_flags & layer))
3355 return rte_flow_error_set(error, EINVAL,
3356 RTE_FLOW_ERROR_TYPE_ACTION,
3357 NULL, "no TCP item in"
3359 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
3360 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
3361 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
3362 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
3363 return rte_flow_error_set(error, EINVAL,
3364 RTE_FLOW_ERROR_TYPE_ACTION,
3366 "cannot decrease and increase"
3367 " TCP sequence number"
3368 " at the same time");
3374 * Validate the modify-header actions of increment/decrement
3375 * TCP Acknowledgment number.
3377 * @param[in] action_flags
3378 * Holds the actions detected until now.
3380 * Pointer to the modify action.
3381 * @param[in] item_flags
3382 * Holds the items detected.
3384 * Pointer to error structure.
3387 * 0 on success, a negative errno value otherwise and rte_errno is set.
3390 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
3391 const struct rte_flow_action *action,
3392 const uint64_t item_flags,
3393 struct rte_flow_error *error)
3398 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3400 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3401 MLX5_FLOW_LAYER_INNER_L4_TCP :
3402 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3403 if (!(item_flags & layer))
3404 return rte_flow_error_set(error, EINVAL,
3405 RTE_FLOW_ERROR_TYPE_ACTION,
3406 NULL, "no TCP item in"
3408 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
3409 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
3410 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
3411 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
3412 return rte_flow_error_set(error, EINVAL,
3413 RTE_FLOW_ERROR_TYPE_ACTION,
3415 "cannot decrease and increase"
3416 " TCP acknowledgment number"
3417 " at the same time");
3423 * Validate the modify-header TTL actions.
3425 * @param[in] action_flags
3426 * Holds the actions detected until now.
3428 * Pointer to the modify action.
3429 * @param[in] item_flags
3430 * Holds the items detected.
3432 * Pointer to error structure.
3435 * 0 on success, a negative errno value otherwise and rte_errno is set.
3438 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
3439 const struct rte_flow_action *action,
3440 const uint64_t item_flags,
3441 struct rte_flow_error *error)
3446 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3448 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3449 MLX5_FLOW_LAYER_INNER_L3 :
3450 MLX5_FLOW_LAYER_OUTER_L3;
3451 if (!(item_flags & layer))
3452 return rte_flow_error_set(error, EINVAL,
3453 RTE_FLOW_ERROR_TYPE_ACTION,
3455 "no IP protocol in pattern");
3461 * Validate jump action.
3464 * Pointer to the jump action.
3465 * @param[in] action_flags
3466 * Holds the actions detected until now.
3467 * @param[in] attributes
3468 * Pointer to flow attributes
3469 * @param[in] external
3470 * Action belongs to flow rule created by request external to PMD.
3472 * Pointer to error structure.
3475 * 0 on success, a negative errno value otherwise and rte_errno is set.
3478 flow_dv_validate_action_jump(const struct rte_flow_action *action,
3479 uint64_t action_flags,
3480 const struct rte_flow_attr *attributes,
3481 bool external, struct rte_flow_error *error)
3483 uint32_t target_group, table;
3486 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3487 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3488 return rte_flow_error_set(error, EINVAL,
3489 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3490 "can't have 2 fate actions in"
3492 if (action_flags & MLX5_FLOW_ACTION_METER)
3493 return rte_flow_error_set(error, ENOTSUP,
3494 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3495 "jump with meter not support");
3497 return rte_flow_error_set(error, EINVAL,
3498 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3499 NULL, "action configuration not set");
3501 ((const struct rte_flow_action_jump *)action->conf)->group;
3502 ret = mlx5_flow_group_to_table(attributes, external, target_group,
3503 true, &table, error);
3506 if (attributes->group == target_group)
3507 return rte_flow_error_set(error, EINVAL,
3508 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3509 "target group must be other than"
3510 " the current flow group");
3515 * Validate the port_id action.
3518 * Pointer to rte_eth_dev structure.
3519 * @param[in] action_flags
3520 * Bit-fields that holds the actions detected until now.
3522 * Port_id RTE action structure.
3524 * Attributes of flow that includes this action.
3526 * Pointer to error structure.
3529 * 0 on success, a negative errno value otherwise and rte_errno is set.
3532 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
3533 uint64_t action_flags,
3534 const struct rte_flow_action *action,
3535 const struct rte_flow_attr *attr,
3536 struct rte_flow_error *error)
3538 const struct rte_flow_action_port_id *port_id;
3539 struct mlx5_priv *act_priv;
3540 struct mlx5_priv *dev_priv;
3543 if (!attr->transfer)
3544 return rte_flow_error_set(error, ENOTSUP,
3545 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3547 "port id action is valid in transfer"
3549 if (!action || !action->conf)
3550 return rte_flow_error_set(error, ENOTSUP,
3551 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3553 "port id action parameters must be"
3555 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3556 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3557 return rte_flow_error_set(error, EINVAL,
3558 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3559 "can have only one fate actions in"
3561 dev_priv = mlx5_dev_to_eswitch_info(dev);
3563 return rte_flow_error_set(error, rte_errno,
3564 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3566 "failed to obtain E-Switch info");
3567 port_id = action->conf;
3568 port = port_id->original ? dev->data->port_id : port_id->id;
3569 act_priv = mlx5_port_to_eswitch_info(port, false);
3571 return rte_flow_error_set
3573 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
3574 "failed to obtain E-Switch port id for port");
3575 if (act_priv->domain_id != dev_priv->domain_id)
3576 return rte_flow_error_set
3578 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3579 "port does not belong to"
3580 " E-Switch being configured");
3585 * Get the maximum number of modify header actions.
3588 * Pointer to rte_eth_dev structure.
3590 * Flags bits to check if root level.
3593 * Max number of modify header actions device can support.
3596 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev, uint64_t flags)
3599 * There's no way to directly query the max cap. Although it has to be
3600 * acquried by iterative trial, it is a safe assumption that more
3601 * actions are supported by FW if extensive metadata register is
3602 * supported. (Only in the root table)
3604 if (!(flags & MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL))
3605 return MLX5_MAX_MODIFY_NUM;
3607 return mlx5_flow_ext_mreg_supported(dev) ?
3608 MLX5_ROOT_TBL_MODIFY_NUM :
3609 MLX5_ROOT_TBL_MODIFY_NUM_NO_MREG;
3613 * Validate the meter action.
3616 * Pointer to rte_eth_dev structure.
3617 * @param[in] action_flags
3618 * Bit-fields that holds the actions detected until now.
3620 * Pointer to the meter action.
3622 * Attributes of flow that includes this action.
3624 * Pointer to error structure.
3627 * 0 on success, a negative errno value otherwise and rte_ernno is set.
3630 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
3631 uint64_t action_flags,
3632 const struct rte_flow_action *action,
3633 const struct rte_flow_attr *attr,
3634 struct rte_flow_error *error)
3636 struct mlx5_priv *priv = dev->data->dev_private;
3637 const struct rte_flow_action_meter *am = action->conf;
3638 struct mlx5_flow_meter *fm;
3641 return rte_flow_error_set(error, EINVAL,
3642 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3643 "meter action conf is NULL");
3645 if (action_flags & MLX5_FLOW_ACTION_METER)
3646 return rte_flow_error_set(error, ENOTSUP,
3647 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3648 "meter chaining not support");
3649 if (action_flags & MLX5_FLOW_ACTION_JUMP)
3650 return rte_flow_error_set(error, ENOTSUP,
3651 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3652 "meter with jump not support");
3654 return rte_flow_error_set(error, ENOTSUP,
3655 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3657 "meter action not supported");
3658 fm = mlx5_flow_meter_find(priv, am->mtr_id);
3660 return rte_flow_error_set(error, EINVAL,
3661 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3663 if (fm->ref_cnt && (!(fm->attr.transfer == attr->transfer ||
3664 (!fm->attr.ingress && !attr->ingress && attr->egress) ||
3665 (!fm->attr.egress && !attr->egress && attr->ingress))))
3666 return rte_flow_error_set(error, EINVAL,
3667 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3668 "Flow attributes are either invalid "
3669 "or have a conflict with current "
3670 "meter attributes");
3675 * Validate the modify-header IPv4 DSCP actions.
3677 * @param[in] action_flags
3678 * Holds the actions detected until now.
3680 * Pointer to the modify action.
3681 * @param[in] item_flags
3682 * Holds the items detected.
3684 * Pointer to error structure.
3687 * 0 on success, a negative errno value otherwise and rte_errno is set.
3690 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
3691 const struct rte_flow_action *action,
3692 const uint64_t item_flags,
3693 struct rte_flow_error *error)
3697 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3699 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
3700 return rte_flow_error_set(error, EINVAL,
3701 RTE_FLOW_ERROR_TYPE_ACTION,
3703 "no ipv4 item in pattern");
3709 * Validate the modify-header IPv6 DSCP actions.
3711 * @param[in] action_flags
3712 * Holds the actions detected until now.
3714 * Pointer to the modify action.
3715 * @param[in] item_flags
3716 * Holds the items detected.
3718 * Pointer to error structure.
3721 * 0 on success, a negative errno value otherwise and rte_errno is set.
3724 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
3725 const struct rte_flow_action *action,
3726 const uint64_t item_flags,
3727 struct rte_flow_error *error)
3731 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3733 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
3734 return rte_flow_error_set(error, EINVAL,
3735 RTE_FLOW_ERROR_TYPE_ACTION,
3737 "no ipv6 item in pattern");
3743 * Find existing modify-header resource or create and register a new one.
3745 * @param dev[in, out]
3746 * Pointer to rte_eth_dev structure.
3747 * @param[in, out] resource
3748 * Pointer to modify-header resource.
3749 * @parm[in, out] dev_flow
3750 * Pointer to the dev_flow.
3752 * pointer to error structure.
3755 * 0 on success otherwise -errno and errno is set.
3758 flow_dv_modify_hdr_resource_register
3759 (struct rte_eth_dev *dev,
3760 struct mlx5_flow_dv_modify_hdr_resource *resource,
3761 struct mlx5_flow *dev_flow,
3762 struct rte_flow_error *error)
3764 struct mlx5_priv *priv = dev->data->dev_private;
3765 struct mlx5_ibv_shared *sh = priv->sh;
3766 struct mlx5_flow_dv_modify_hdr_resource *cache_resource;
3767 struct mlx5dv_dr_domain *ns;
3768 uint32_t actions_len;
3770 resource->flags = dev_flow->dv.group ? 0 :
3771 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
3772 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
3774 return rte_flow_error_set(error, EOVERFLOW,
3775 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3776 "too many modify header items");
3777 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3778 ns = sh->fdb_domain;
3779 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
3783 /* Lookup a matching resource from cache. */
3784 actions_len = resource->actions_num * sizeof(resource->actions[0]);
3785 LIST_FOREACH(cache_resource, &sh->modify_cmds, next) {
3786 if (resource->ft_type == cache_resource->ft_type &&
3787 resource->actions_num == cache_resource->actions_num &&
3788 resource->flags == cache_resource->flags &&
3789 !memcmp((const void *)resource->actions,
3790 (const void *)cache_resource->actions,
3792 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d++",
3793 (void *)cache_resource,
3794 rte_atomic32_read(&cache_resource->refcnt));
3795 rte_atomic32_inc(&cache_resource->refcnt);
3796 dev_flow->handle->dvh.modify_hdr = cache_resource;
3800 /* Register new modify-header resource. */
3801 cache_resource = rte_calloc(__func__, 1,
3802 sizeof(*cache_resource) + actions_len, 0);
3803 if (!cache_resource)
3804 return rte_flow_error_set(error, ENOMEM,
3805 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3806 "cannot allocate resource memory");
3807 *cache_resource = *resource;
3808 rte_memcpy(cache_resource->actions, resource->actions, actions_len);
3809 cache_resource->verbs_action =
3810 mlx5_glue->dv_create_flow_action_modify_header
3811 (sh->ctx, cache_resource->ft_type, ns,
3812 cache_resource->flags, actions_len,
3813 (uint64_t *)cache_resource->actions);
3814 if (!cache_resource->verbs_action) {
3815 rte_free(cache_resource);
3816 return rte_flow_error_set(error, ENOMEM,
3817 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3818 NULL, "cannot create action");
3820 rte_atomic32_init(&cache_resource->refcnt);
3821 rte_atomic32_inc(&cache_resource->refcnt);
3822 LIST_INSERT_HEAD(&sh->modify_cmds, cache_resource, next);
3823 dev_flow->handle->dvh.modify_hdr = cache_resource;
3824 DRV_LOG(DEBUG, "new modify-header resource %p: refcnt %d++",
3825 (void *)cache_resource,
3826 rte_atomic32_read(&cache_resource->refcnt));
3831 * Get or create a flow counter.
3834 * Pointer to the Ethernet device structure.
3836 * Indicate if this counter is shared with other flows.
3838 * Counter identifier.
3841 * Index to flow counter on success, 0 otherwise and rte_errno is set.
3844 flow_dv_counter_alloc_fallback(struct rte_eth_dev *dev, uint32_t shared,
3847 struct mlx5_priv *priv = dev->data->dev_private;
3848 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, 0, 0);
3849 struct mlx5_flow_counter_pool *pool;
3850 struct mlx5_flow_counter *cnt = NULL;
3851 struct mlx5_devx_obj *dcs = NULL;
3854 if (!priv->config.devx) {
3855 rte_errno = ENOTSUP;
3858 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
3861 pool = flow_dv_find_pool_by_id(cont, true, dcs->id);
3863 cont = flow_dv_pool_create(dev, dcs, 0);
3865 mlx5_devx_cmd_destroy(dcs);
3869 pool = TAILQ_FIRST(&cont->pool_list);
3871 offset = dcs->id % MLX5_COUNTERS_PER_POOL;
3872 cnt = &pool->counters_raw[offset];
3873 struct mlx5_flow_counter tmpl = {
3879 tmpl.action = mlx5_glue->dv_create_flow_action_counter(dcs->obj, 0);
3881 claim_zero(mlx5_devx_cmd_destroy(cnt->dcs));
3886 return MLX5_MAKE_CNT_IDX(pool->index, offset);
3890 * Release a flow counter.
3893 * Pointer to the Ethernet device structure.
3894 * @param[in] counter
3895 * Pointer to the counter handler.
3898 flow_dv_counter_release_fallback(struct rte_eth_dev *dev __rte_unused,
3899 struct mlx5_flow_counter *counter)
3903 if (--counter->ref_cnt == 0) {
3904 claim_zero(mlx5_glue->destroy_flow_action(counter->action));
3905 claim_zero(mlx5_devx_cmd_destroy(counter->dcs));
3906 counter->action = NULL;
3907 counter->dcs = NULL;
3912 * Query a devx flow counter.
3915 * Pointer to the Ethernet device structure.
3917 * Pointer to the flow counter.
3919 * The statistics value of packets.
3921 * The statistics value of bytes.
3924 * 0 on success, otherwise a negative errno value and rte_errno is set.
3927 _flow_dv_query_count_fallback(struct rte_eth_dev *dev __rte_unused,
3928 struct mlx5_flow_counter *cnt, uint64_t *pkts,
3931 return mlx5_devx_cmd_flow_counter_query(cnt->dcs, 0, 0, pkts, bytes,
3936 * Get a pool by a counter.
3939 * Pointer to the counter.
3944 static struct mlx5_flow_counter_pool *
3945 flow_dv_counter_pool_get(struct mlx5_flow_counter *cnt)
3948 cnt -= cnt->dcs->id % MLX5_COUNTERS_PER_POOL;
3949 return (struct mlx5_flow_counter_pool *)cnt - 1;
3955 * Get DV flow counter by index.
3958 * Pointer to the Ethernet device structure.
3960 * mlx5 flow counter index in the container.
3962 * mlx5 flow counter pool in the container,
3965 * Pointer to the counter, NULL otherwise.
3967 static struct mlx5_flow_counter *
3968 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
3970 struct mlx5_flow_counter_pool **ppool)
3972 struct mlx5_priv *priv = dev->data->dev_private;
3973 struct mlx5_pools_container *cont;
3974 struct mlx5_flow_counter_pool *pool;
3978 if (idx >= MLX5_CNT_BATCH_OFFSET) {
3979 idx -= MLX5_CNT_BATCH_OFFSET;
3982 cont = MLX5_CNT_CONTAINER(priv->sh, batch, 0);
3983 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cont->n);
3984 pool = cont->pools[idx / MLX5_COUNTERS_PER_POOL];
3988 return &pool->counters_raw[idx % MLX5_COUNTERS_PER_POOL];
3992 * Get a pool by devx counter ID.
3995 * Pointer to the counter container.
3996 * @param[in] fallback
3999 * The counter devx ID.
4002 * The counter pool pointer if exists, NULL otherwise,
4004 static struct mlx5_flow_counter_pool *
4005 flow_dv_find_pool_by_id(struct mlx5_pools_container *cont, bool fallback,
4009 uint32_t n_valid = rte_atomic16_read(&cont->n_valid);
4011 for (i = 0; i < n_valid; i++) {
4012 struct mlx5_flow_counter_pool *pool = cont->pools[i];
4013 int base = ((fallback ? pool->dcs_id : pool->min_dcs->id) /
4014 MLX5_COUNTERS_PER_POOL) * MLX5_COUNTERS_PER_POOL;
4016 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL) {
4018 * Move the pool to the head, as counter allocate
4019 * always gets the first pool in the container.
4021 if (pool != TAILQ_FIRST(&cont->pool_list)) {
4022 TAILQ_REMOVE(&cont->pool_list, pool, next);
4023 TAILQ_INSERT_HEAD(&cont->pool_list, pool, next);
4032 * Allocate a new memory for the counter values wrapped by all the needed
4036 * Pointer to the Ethernet device structure.
4038 * The raw memory areas - each one for MLX5_COUNTERS_PER_POOL counters.
4041 * The new memory management pointer on success, otherwise NULL and rte_errno
4044 static struct mlx5_counter_stats_mem_mng *
4045 flow_dv_create_counter_stat_mem_mng(struct rte_eth_dev *dev, int raws_n)
4047 struct mlx5_ibv_shared *sh = ((struct mlx5_priv *)
4048 (dev->data->dev_private))->sh;
4049 struct mlx5_devx_mkey_attr mkey_attr;
4050 struct mlx5_counter_stats_mem_mng *mem_mng;
4051 volatile struct flow_counter_stats *raw_data;
4052 int size = (sizeof(struct flow_counter_stats) *
4053 MLX5_COUNTERS_PER_POOL +
4054 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
4055 sizeof(struct mlx5_counter_stats_mem_mng);
4056 uint8_t *mem = rte_calloc(__func__, 1, size, sysconf(_SC_PAGESIZE));
4063 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
4064 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
4065 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
4066 IBV_ACCESS_LOCAL_WRITE);
4067 if (!mem_mng->umem) {
4072 mkey_attr.addr = (uintptr_t)mem;
4073 mkey_attr.size = size;
4074 mkey_attr.umem_id = mem_mng->umem->umem_id;
4075 mkey_attr.pd = sh->pdn;
4076 mkey_attr.log_entity_size = 0;
4077 mkey_attr.pg_access = 0;
4078 mkey_attr.klm_array = NULL;
4079 mkey_attr.klm_num = 0;
4080 mkey_attr.relaxed_ordering = 1;
4081 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
4083 mlx5_glue->devx_umem_dereg(mem_mng->umem);
4088 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
4089 raw_data = (volatile struct flow_counter_stats *)mem;
4090 for (i = 0; i < raws_n; ++i) {
4091 mem_mng->raws[i].mem_mng = mem_mng;
4092 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
4094 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
4099 * Resize a counter container.
4102 * Pointer to the Ethernet device structure.
4104 * Whether the pool is for counter that was allocated by batch command.
4107 * The new container pointer on success, otherwise NULL and rte_errno is set.
4109 static struct mlx5_pools_container *
4110 flow_dv_container_resize(struct rte_eth_dev *dev, uint32_t batch)
4112 struct mlx5_priv *priv = dev->data->dev_private;
4113 struct mlx5_pools_container *cont =
4114 MLX5_CNT_CONTAINER(priv->sh, batch, 0);
4115 struct mlx5_pools_container *new_cont =
4116 MLX5_CNT_CONTAINER_UNUSED(priv->sh, batch, 0);
4117 struct mlx5_counter_stats_mem_mng *mem_mng;
4118 uint32_t resize = cont->n + MLX5_CNT_CONTAINER_RESIZE;
4119 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
4122 if (cont != MLX5_CNT_CONTAINER(priv->sh, batch, 1)) {
4123 /* The last resize still hasn't detected by the host thread. */
4127 new_cont->pools = rte_calloc(__func__, 1, mem_size, 0);
4128 if (!new_cont->pools) {
4133 memcpy(new_cont->pools, cont->pools, cont->n *
4134 sizeof(struct mlx5_flow_counter_pool *));
4135 mem_mng = flow_dv_create_counter_stat_mem_mng(dev,
4136 MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES);
4138 rte_free(new_cont->pools);
4141 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
4142 LIST_INSERT_HEAD(&priv->sh->cmng.free_stat_raws,
4143 mem_mng->raws + MLX5_CNT_CONTAINER_RESIZE +
4145 new_cont->n = resize;
4146 rte_atomic16_set(&new_cont->n_valid, rte_atomic16_read(&cont->n_valid));
4147 TAILQ_INIT(&new_cont->pool_list);
4148 TAILQ_CONCAT(&new_cont->pool_list, &cont->pool_list, next);
4149 new_cont->init_mem_mng = mem_mng;
4151 /* Flip the master container. */
4152 priv->sh->cmng.mhi[batch] ^= (uint8_t)1;
4157 * Query a devx flow counter.
4160 * Pointer to the Ethernet device structure.
4162 * Pointer to the flow counter.
4164 * The statistics value of packets.
4166 * The statistics value of bytes.
4169 * 0 on success, otherwise a negative errno value and rte_errno is set.
4172 _flow_dv_query_count(struct rte_eth_dev *dev,
4173 struct mlx5_flow_counter *cnt, uint64_t *pkts,
4176 struct mlx5_priv *priv = dev->data->dev_private;
4177 struct mlx5_flow_counter_pool *pool =
4178 flow_dv_counter_pool_get(cnt);
4179 int offset = cnt - &pool->counters_raw[0];
4181 if (priv->counter_fallback)
4182 return _flow_dv_query_count_fallback(dev, cnt, pkts, bytes);
4184 rte_spinlock_lock(&pool->sl);
4186 * The single counters allocation may allocate smaller ID than the
4187 * current allocated in parallel to the host reading.
4188 * In this case the new counter values must be reported as 0.
4190 if (unlikely(!cnt->batch && cnt->dcs->id < pool->raw->min_dcs_id)) {
4194 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
4195 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
4197 rte_spinlock_unlock(&pool->sl);
4202 * Create and initialize a new counter pool.
4205 * Pointer to the Ethernet device structure.
4207 * The devX counter handle.
4209 * Whether the pool is for counter that was allocated by batch command.
4210 * @param[in/out] cont_cur
4211 * Pointer to the container pointer, it will be update in pool resize.
4214 * The pool container pointer on success, NULL otherwise and rte_errno is set.
4216 static struct mlx5_pools_container *
4217 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
4220 struct mlx5_priv *priv = dev->data->dev_private;
4221 struct mlx5_flow_counter_pool *pool;
4222 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4224 int16_t n_valid = rte_atomic16_read(&cont->n_valid);
4227 if (cont->n == n_valid) {
4228 cont = flow_dv_container_resize(dev, batch);
4232 size = sizeof(*pool) + MLX5_COUNTERS_PER_POOL *
4233 sizeof(struct mlx5_flow_counter);
4234 pool = rte_calloc(__func__, 1, size, 0);
4239 if (priv->counter_fallback)
4240 pool->dcs_id = dcs->id;
4242 pool->min_dcs = dcs;
4243 pool->raw = cont->init_mem_mng->raws + n_valid %
4244 MLX5_CNT_CONTAINER_RESIZE;
4245 pool->raw_hw = NULL;
4246 rte_spinlock_init(&pool->sl);
4248 * The generation of the new allocated counters in this pool is 0, 2 in
4249 * the pool generation makes all the counters valid for allocation.
4250 * The start and end query generation protect the counters be released
4251 * between the query and update gap period will not be reallocated
4252 * without the last query finished and stats updated to the memory.
4254 rte_atomic64_set(&pool->start_query_gen, 0x2);
4255 rte_atomic64_set(&pool->end_query_gen, 0x2);
4256 TAILQ_INIT(&pool->counters);
4257 TAILQ_INSERT_HEAD(&cont->pool_list, pool, next);
4258 pool->index = n_valid;
4259 cont->pools[n_valid] = pool;
4260 /* Pool initialization must be updated before host thread access. */
4262 rte_atomic16_add(&cont->n_valid, 1);
4267 * Prepare a new counter and/or a new counter pool.
4270 * Pointer to the Ethernet device structure.
4271 * @param[out] cnt_free
4272 * Where to put the pointer of a new counter.
4274 * Whether the pool is for counter that was allocated by batch command.
4277 * The counter container pointer and @p cnt_free is set on success,
4278 * NULL otherwise and rte_errno is set.
4280 static struct mlx5_pools_container *
4281 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
4282 struct mlx5_flow_counter **cnt_free,
4285 struct mlx5_priv *priv = dev->data->dev_private;
4286 struct mlx5_pools_container *cont;
4287 struct mlx5_flow_counter_pool *pool;
4288 struct mlx5_devx_obj *dcs = NULL;
4289 struct mlx5_flow_counter *cnt;
4292 cont = MLX5_CNT_CONTAINER(priv->sh, batch, 0);
4294 /* bulk_bitmap must be 0 for single counter allocation. */
4295 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
4298 pool = flow_dv_find_pool_by_id(cont, false, dcs->id);
4300 cont = flow_dv_pool_create(dev, dcs, batch);
4302 mlx5_devx_cmd_destroy(dcs);
4305 pool = TAILQ_FIRST(&cont->pool_list);
4306 } else if (dcs->id < pool->min_dcs->id) {
4307 rte_atomic64_set(&pool->a64_dcs,
4308 (int64_t)(uintptr_t)dcs);
4310 cnt = &pool->counters_raw[dcs->id % MLX5_COUNTERS_PER_POOL];
4311 TAILQ_INSERT_HEAD(&pool->counters, cnt, next);
4316 /* bulk_bitmap is in 128 counters units. */
4317 if (priv->config.hca_attr.flow_counter_bulk_alloc_bitmap & 0x4)
4318 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
4320 rte_errno = ENODATA;
4323 cont = flow_dv_pool_create(dev, dcs, batch);
4325 mlx5_devx_cmd_destroy(dcs);
4328 pool = TAILQ_FIRST(&cont->pool_list);
4329 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
4330 cnt = &pool->counters_raw[i];
4332 TAILQ_INSERT_HEAD(&pool->counters, cnt, next);
4334 *cnt_free = &pool->counters_raw[0];
4339 * Search for existed shared counter.
4342 * Pointer to the relevant counter pool container.
4344 * The shared counter ID to search.
4346 * mlx5 flow counter pool in the container,
4349 * NULL if not existed, otherwise pointer to the shared counter.
4351 static struct mlx5_flow_counter *
4352 flow_dv_counter_shared_search(struct mlx5_pools_container *cont, uint32_t id,
4353 struct mlx5_flow_counter_pool **ppool)
4355 static struct mlx5_flow_counter *cnt;
4356 struct mlx5_flow_counter_pool *pool;
4358 uint32_t n_valid = rte_atomic16_read(&cont->n_valid);
4360 for (i = 0; i < n_valid; i++) {
4361 pool = cont->pools[i];
4362 for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
4363 cnt = &pool->counters_raw[i];
4364 if (cnt->ref_cnt && cnt->shared && cnt->id == id) {
4375 * Allocate a flow counter.
4378 * Pointer to the Ethernet device structure.
4380 * Indicate if this counter is shared with other flows.
4382 * Counter identifier.
4384 * Counter flow group.
4387 * pointer to flow counter on success, NULL otherwise and rte_errno is set.
4389 static struct mlx5_flow_counter *
4390 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t shared, uint32_t id,
4393 struct mlx5_priv *priv = dev->data->dev_private;
4394 struct mlx5_flow_counter_pool *pool = NULL;
4395 struct mlx5_flow_counter *cnt_free = NULL;
4397 * Currently group 0 flow counter cannot be assigned to a flow if it is
4398 * not the first one in the batch counter allocation, so it is better
4399 * to allocate counters one by one for these flows in a separate
4401 * A counter can be shared between different groups so need to take
4402 * shared counters from the single container.
4404 uint32_t batch = (group && !shared) ? 1 : 0;
4405 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4409 if (!priv->config.devx) {
4410 rte_errno = ENOTSUP;
4414 cnt_free = flow_dv_counter_shared_search(cont, id, &pool);
4416 if (cnt_free->ref_cnt + 1 == 0) {
4420 cnt_free->ref_cnt++;
4421 cnt_idx = pool->index * MLX5_COUNTERS_PER_POOL +
4422 (cnt_free - pool->counters_raw) + 1;
4423 return (struct mlx5_flow_counter *)(uintptr_t)cnt_idx;
4426 if (priv->counter_fallback)
4427 return (struct mlx5_flow_counter *)(uintptr_t)
4428 flow_dv_counter_alloc_fallback(dev, shared, id);
4429 /* Pools which has a free counters are in the start. */
4430 TAILQ_FOREACH(pool, &cont->pool_list, next) {
4432 * The free counter reset values must be updated between the
4433 * counter release to the counter allocation, so, at least one
4434 * query must be done in this time. ensure it by saving the
4435 * query generation in the release time.
4436 * The free list is sorted according to the generation - so if
4437 * the first one is not updated, all the others are not
4440 cnt_free = TAILQ_FIRST(&pool->counters);
4441 if (cnt_free && cnt_free->query_gen <
4442 rte_atomic64_read(&pool->end_query_gen))
4447 cont = flow_dv_counter_pool_prepare(dev, &cnt_free, batch);
4450 pool = TAILQ_FIRST(&cont->pool_list);
4452 cnt_free->batch = batch;
4453 /* Create a DV counter action only in the first time usage. */
4454 if (!cnt_free->action) {
4456 struct mlx5_devx_obj *dcs;
4459 offset = cnt_free - &pool->counters_raw[0];
4460 dcs = pool->min_dcs;
4463 dcs = cnt_free->dcs;
4465 cnt_free->action = mlx5_glue->dv_create_flow_action_counter
4467 if (!cnt_free->action) {
4472 /* Update the counter reset values. */
4473 if (_flow_dv_query_count(dev, cnt_free, &cnt_free->hits,
4476 cnt_free->shared = shared;
4477 cnt_free->ref_cnt = 1;
4479 if (!priv->sh->cmng.query_thread_on)
4480 /* Start the asynchronous batch query by the host thread. */
4481 mlx5_set_query_alarm(priv->sh);
4482 TAILQ_REMOVE(&pool->counters, cnt_free, next);
4483 if (TAILQ_EMPTY(&pool->counters)) {
4484 /* Move the pool to the end of the container pool list. */
4485 TAILQ_REMOVE(&cont->pool_list, pool, next);
4486 TAILQ_INSERT_TAIL(&cont->pool_list, pool, next);
4488 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
4489 (cnt_free - pool->counters_raw));
4490 cnt_idx += batch * MLX5_CNT_BATCH_OFFSET;
4491 return (struct mlx5_flow_counter *)(uintptr_t)cnt_idx;
4495 * Release a flow counter.
4498 * Pointer to the Ethernet device structure.
4499 * @param[in] counter
4500 * Pointer to the counter handler.
4503 flow_dv_counter_release(struct rte_eth_dev *dev,
4504 struct mlx5_flow_counter *counter)
4506 struct mlx5_priv *priv = dev->data->dev_private;
4507 struct mlx5_flow_counter_pool *pool;
4508 struct mlx5_flow_counter *cnt;
4512 cnt = flow_dv_counter_get_by_idx(dev, (uintptr_t)counter, &pool);
4513 if (priv->counter_fallback) {
4514 flow_dv_counter_release_fallback(dev, cnt);
4517 if (--cnt->ref_cnt == 0) {
4518 /* Put the counter in the end - the last updated one. */
4519 TAILQ_INSERT_TAIL(&pool->counters, cnt, next);
4521 * Counters released between query trigger and handler need
4522 * to wait the next round of query. Since the packets arrive
4523 * in the gap period will not be taken into account to the
4526 cnt->query_gen = rte_atomic64_read(&pool->start_query_gen);
4531 * Verify the @p attributes will be correctly understood by the NIC and store
4532 * them in the @p flow if everything is correct.
4535 * Pointer to dev struct.
4536 * @param[in] attributes
4537 * Pointer to flow attributes
4538 * @param[in] external
4539 * This flow rule is created by request external to PMD.
4541 * Pointer to error structure.
4544 * 0 on success, a negative errno value otherwise and rte_errno is set.
4547 flow_dv_validate_attributes(struct rte_eth_dev *dev,
4548 const struct rte_flow_attr *attributes,
4549 bool external __rte_unused,
4550 struct rte_flow_error *error)
4552 struct mlx5_priv *priv = dev->data->dev_private;
4553 uint32_t priority_max = priv->config.flow_prio - 1;
4555 #ifndef HAVE_MLX5DV_DR
4556 if (attributes->group)
4557 return rte_flow_error_set(error, ENOTSUP,
4558 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
4560 "groups are not supported");
4565 ret = mlx5_flow_group_to_table(attributes, external,
4566 attributes->group, !!priv->fdb_def_rule,
4571 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
4572 attributes->priority >= priority_max)
4573 return rte_flow_error_set(error, ENOTSUP,
4574 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
4576 "priority out of range");
4577 if (attributes->transfer) {
4578 if (!priv->config.dv_esw_en)
4579 return rte_flow_error_set
4581 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4582 "E-Switch dr is not supported");
4583 if (!(priv->representor || priv->master))
4584 return rte_flow_error_set
4585 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4586 NULL, "E-Switch configuration can only be"
4587 " done by a master or a representor device");
4588 if (attributes->egress)
4589 return rte_flow_error_set
4591 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
4592 "egress is not supported");
4594 if (!(attributes->egress ^ attributes->ingress))
4595 return rte_flow_error_set(error, ENOTSUP,
4596 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
4597 "must specify exactly one of "
4598 "ingress or egress");
4603 * Internal validation function. For validating both actions and items.
4606 * Pointer to the rte_eth_dev structure.
4608 * Pointer to the flow attributes.
4610 * Pointer to the list of items.
4611 * @param[in] actions
4612 * Pointer to the list of actions.
4613 * @param[in] external
4614 * This flow rule is created by request external to PMD.
4616 * Pointer to the error structure.
4619 * 0 on success, a negative errno value otherwise and rte_errno is set.
4622 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
4623 const struct rte_flow_item items[],
4624 const struct rte_flow_action actions[],
4625 bool external, struct rte_flow_error *error)
4628 uint64_t action_flags = 0;
4629 uint64_t item_flags = 0;
4630 uint64_t last_item = 0;
4631 uint8_t next_protocol = 0xff;
4632 uint16_t ether_type = 0;
4634 uint8_t item_ipv6_proto = 0;
4635 const struct rte_flow_item *gre_item = NULL;
4636 const struct rte_flow_action_raw_decap *decap;
4637 const struct rte_flow_action_raw_encap *encap;
4638 const struct rte_flow_action_rss *rss;
4639 const struct rte_flow_item_tcp nic_tcp_mask = {
4642 .src_port = RTE_BE16(UINT16_MAX),
4643 .dst_port = RTE_BE16(UINT16_MAX),
4646 const struct rte_flow_item_ipv4 nic_ipv4_mask = {
4648 .src_addr = RTE_BE32(0xffffffff),
4649 .dst_addr = RTE_BE32(0xffffffff),
4650 .type_of_service = 0xff,
4651 .next_proto_id = 0xff,
4652 .time_to_live = 0xff,
4655 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
4658 "\xff\xff\xff\xff\xff\xff\xff\xff"
4659 "\xff\xff\xff\xff\xff\xff\xff\xff",
4661 "\xff\xff\xff\xff\xff\xff\xff\xff"
4662 "\xff\xff\xff\xff\xff\xff\xff\xff",
4663 .vtc_flow = RTE_BE32(0xffffffff),
4668 struct mlx5_priv *priv = dev->data->dev_private;
4669 struct mlx5_dev_config *dev_conf = &priv->config;
4670 uint16_t queue_index = 0xFFFF;
4674 ret = flow_dv_validate_attributes(dev, attr, external, error);
4677 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4678 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
4679 int type = items->type;
4682 case RTE_FLOW_ITEM_TYPE_VOID:
4684 case RTE_FLOW_ITEM_TYPE_PORT_ID:
4685 ret = flow_dv_validate_item_port_id
4686 (dev, items, attr, item_flags, error);
4689 last_item = MLX5_FLOW_ITEM_PORT_ID;
4691 case RTE_FLOW_ITEM_TYPE_ETH:
4692 ret = mlx5_flow_validate_item_eth(items, item_flags,
4696 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
4697 MLX5_FLOW_LAYER_OUTER_L2;
4698 if (items->mask != NULL && items->spec != NULL) {
4700 ((const struct rte_flow_item_eth *)
4703 ((const struct rte_flow_item_eth *)
4705 ether_type = rte_be_to_cpu_16(ether_type);
4710 case RTE_FLOW_ITEM_TYPE_VLAN:
4711 ret = mlx5_flow_validate_item_vlan(items, item_flags,
4715 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
4716 MLX5_FLOW_LAYER_OUTER_VLAN;
4717 if (items->mask != NULL && items->spec != NULL) {
4719 ((const struct rte_flow_item_vlan *)
4720 items->spec)->inner_type;
4722 ((const struct rte_flow_item_vlan *)
4723 items->mask)->inner_type;
4724 ether_type = rte_be_to_cpu_16(ether_type);
4729 case RTE_FLOW_ITEM_TYPE_IPV4:
4730 mlx5_flow_tunnel_ip_check(items, next_protocol,
4731 &item_flags, &tunnel);
4732 ret = mlx5_flow_validate_item_ipv4(items, item_flags,
4739 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4740 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4741 if (items->mask != NULL &&
4742 ((const struct rte_flow_item_ipv4 *)
4743 items->mask)->hdr.next_proto_id) {
4745 ((const struct rte_flow_item_ipv4 *)
4746 (items->spec))->hdr.next_proto_id;
4748 ((const struct rte_flow_item_ipv4 *)
4749 (items->mask))->hdr.next_proto_id;
4751 /* Reset for inner layer. */
4752 next_protocol = 0xff;
4755 case RTE_FLOW_ITEM_TYPE_IPV6:
4756 mlx5_flow_tunnel_ip_check(items, next_protocol,
4757 &item_flags, &tunnel);
4758 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
4765 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4766 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4767 if (items->mask != NULL &&
4768 ((const struct rte_flow_item_ipv6 *)
4769 items->mask)->hdr.proto) {
4771 ((const struct rte_flow_item_ipv6 *)
4772 items->spec)->hdr.proto;
4774 ((const struct rte_flow_item_ipv6 *)
4775 items->spec)->hdr.proto;
4777 ((const struct rte_flow_item_ipv6 *)
4778 items->mask)->hdr.proto;
4780 /* Reset for inner layer. */
4781 next_protocol = 0xff;
4784 case RTE_FLOW_ITEM_TYPE_TCP:
4785 ret = mlx5_flow_validate_item_tcp
4792 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
4793 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4795 case RTE_FLOW_ITEM_TYPE_UDP:
4796 ret = mlx5_flow_validate_item_udp(items, item_flags,
4801 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
4802 MLX5_FLOW_LAYER_OUTER_L4_UDP;
4804 case RTE_FLOW_ITEM_TYPE_GRE:
4805 ret = mlx5_flow_validate_item_gre(items, item_flags,
4806 next_protocol, error);
4810 last_item = MLX5_FLOW_LAYER_GRE;
4812 case RTE_FLOW_ITEM_TYPE_NVGRE:
4813 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
4818 last_item = MLX5_FLOW_LAYER_NVGRE;
4820 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
4821 ret = mlx5_flow_validate_item_gre_key
4822 (items, item_flags, gre_item, error);
4825 last_item = MLX5_FLOW_LAYER_GRE_KEY;
4827 case RTE_FLOW_ITEM_TYPE_VXLAN:
4828 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
4832 last_item = MLX5_FLOW_LAYER_VXLAN;
4834 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4835 ret = mlx5_flow_validate_item_vxlan_gpe(items,
4840 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
4842 case RTE_FLOW_ITEM_TYPE_GENEVE:
4843 ret = mlx5_flow_validate_item_geneve(items,
4848 last_item = MLX5_FLOW_LAYER_GENEVE;
4850 case RTE_FLOW_ITEM_TYPE_MPLS:
4851 ret = mlx5_flow_validate_item_mpls(dev, items,
4856 last_item = MLX5_FLOW_LAYER_MPLS;
4859 case RTE_FLOW_ITEM_TYPE_MARK:
4860 ret = flow_dv_validate_item_mark(dev, items, attr,
4864 last_item = MLX5_FLOW_ITEM_MARK;
4866 case RTE_FLOW_ITEM_TYPE_META:
4867 ret = flow_dv_validate_item_meta(dev, items, attr,
4871 last_item = MLX5_FLOW_ITEM_METADATA;
4873 case RTE_FLOW_ITEM_TYPE_ICMP:
4874 ret = mlx5_flow_validate_item_icmp(items, item_flags,
4879 last_item = MLX5_FLOW_LAYER_ICMP;
4881 case RTE_FLOW_ITEM_TYPE_ICMP6:
4882 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
4887 item_ipv6_proto = IPPROTO_ICMPV6;
4888 last_item = MLX5_FLOW_LAYER_ICMP6;
4890 case RTE_FLOW_ITEM_TYPE_TAG:
4891 ret = flow_dv_validate_item_tag(dev, items,
4895 last_item = MLX5_FLOW_ITEM_TAG;
4897 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
4898 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
4900 case RTE_FLOW_ITEM_TYPE_GTP:
4901 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
4905 last_item = MLX5_FLOW_LAYER_GTP;
4908 return rte_flow_error_set(error, ENOTSUP,
4909 RTE_FLOW_ERROR_TYPE_ITEM,
4910 NULL, "item not supported");
4912 item_flags |= last_item;
4914 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4915 int type = actions->type;
4916 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
4917 return rte_flow_error_set(error, ENOTSUP,
4918 RTE_FLOW_ERROR_TYPE_ACTION,
4919 actions, "too many actions");
4921 case RTE_FLOW_ACTION_TYPE_VOID:
4923 case RTE_FLOW_ACTION_TYPE_PORT_ID:
4924 ret = flow_dv_validate_action_port_id(dev,
4931 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
4934 case RTE_FLOW_ACTION_TYPE_FLAG:
4935 ret = flow_dv_validate_action_flag(dev, action_flags,
4939 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
4940 /* Count all modify-header actions as one. */
4941 if (!(action_flags &
4942 MLX5_FLOW_MODIFY_HDR_ACTIONS))
4944 action_flags |= MLX5_FLOW_ACTION_FLAG |
4945 MLX5_FLOW_ACTION_MARK_EXT;
4947 action_flags |= MLX5_FLOW_ACTION_FLAG;
4951 case RTE_FLOW_ACTION_TYPE_MARK:
4952 ret = flow_dv_validate_action_mark(dev, actions,
4957 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
4958 /* Count all modify-header actions as one. */
4959 if (!(action_flags &
4960 MLX5_FLOW_MODIFY_HDR_ACTIONS))
4962 action_flags |= MLX5_FLOW_ACTION_MARK |
4963 MLX5_FLOW_ACTION_MARK_EXT;
4965 action_flags |= MLX5_FLOW_ACTION_MARK;
4969 case RTE_FLOW_ACTION_TYPE_SET_META:
4970 ret = flow_dv_validate_action_set_meta(dev, actions,
4975 /* Count all modify-header actions as one action. */
4976 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4978 action_flags |= MLX5_FLOW_ACTION_SET_META;
4980 case RTE_FLOW_ACTION_TYPE_SET_TAG:
4981 ret = flow_dv_validate_action_set_tag(dev, actions,
4986 /* Count all modify-header actions as one action. */
4987 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
4989 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
4991 case RTE_FLOW_ACTION_TYPE_DROP:
4992 ret = mlx5_flow_validate_action_drop(action_flags,
4996 action_flags |= MLX5_FLOW_ACTION_DROP;
4999 case RTE_FLOW_ACTION_TYPE_QUEUE:
5000 ret = mlx5_flow_validate_action_queue(actions,
5005 queue_index = ((const struct rte_flow_action_queue *)
5006 (actions->conf))->index;
5007 action_flags |= MLX5_FLOW_ACTION_QUEUE;
5010 case RTE_FLOW_ACTION_TYPE_RSS:
5011 rss = actions->conf;
5012 ret = mlx5_flow_validate_action_rss(actions,
5018 if (rss != NULL && rss->queue_num)
5019 queue_index = rss->queue[0];
5020 action_flags |= MLX5_FLOW_ACTION_RSS;
5023 case RTE_FLOW_ACTION_TYPE_COUNT:
5024 ret = flow_dv_validate_action_count(dev, error);
5027 action_flags |= MLX5_FLOW_ACTION_COUNT;
5030 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5031 if (flow_dv_validate_action_pop_vlan(dev,
5037 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
5040 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5041 ret = flow_dv_validate_action_push_vlan(dev,
5048 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
5051 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5052 ret = flow_dv_validate_action_set_vlan_pcp
5053 (action_flags, actions, error);
5056 /* Count PCP with push_vlan command. */
5057 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
5059 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5060 ret = flow_dv_validate_action_set_vlan_vid
5061 (item_flags, action_flags,
5065 /* Count VID with push_vlan command. */
5066 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
5068 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5069 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5070 ret = flow_dv_validate_action_l2_encap(dev,
5076 action_flags |= MLX5_FLOW_ACTION_ENCAP;
5079 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5080 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5081 ret = flow_dv_validate_action_decap(dev, action_flags,
5085 action_flags |= MLX5_FLOW_ACTION_DECAP;
5088 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5089 ret = flow_dv_validate_action_raw_encap_decap
5090 (dev, NULL, actions->conf, attr, &action_flags,
5095 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5096 decap = actions->conf;
5097 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
5099 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5103 encap = actions->conf;
5105 ret = flow_dv_validate_action_raw_encap_decap
5107 decap ? decap : &empty_decap, encap,
5108 attr, &action_flags, &actions_n,
5113 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5114 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5115 ret = flow_dv_validate_action_modify_mac(action_flags,
5121 /* Count all modify-header actions as one action. */
5122 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5124 action_flags |= actions->type ==
5125 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
5126 MLX5_FLOW_ACTION_SET_MAC_SRC :
5127 MLX5_FLOW_ACTION_SET_MAC_DST;
5130 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5131 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5132 ret = flow_dv_validate_action_modify_ipv4(action_flags,
5138 /* Count all modify-header actions as one action. */
5139 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5141 action_flags |= actions->type ==
5142 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
5143 MLX5_FLOW_ACTION_SET_IPV4_SRC :
5144 MLX5_FLOW_ACTION_SET_IPV4_DST;
5146 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5147 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5148 ret = flow_dv_validate_action_modify_ipv6(action_flags,
5154 if (item_ipv6_proto == IPPROTO_ICMPV6)
5155 return rte_flow_error_set(error, ENOTSUP,
5156 RTE_FLOW_ERROR_TYPE_ACTION,
5158 "Can't change header "
5159 "with ICMPv6 proto");
5160 /* Count all modify-header actions as one action. */
5161 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5163 action_flags |= actions->type ==
5164 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
5165 MLX5_FLOW_ACTION_SET_IPV6_SRC :
5166 MLX5_FLOW_ACTION_SET_IPV6_DST;
5168 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5169 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5170 ret = flow_dv_validate_action_modify_tp(action_flags,
5176 /* Count all modify-header actions as one action. */
5177 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5179 action_flags |= actions->type ==
5180 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
5181 MLX5_FLOW_ACTION_SET_TP_SRC :
5182 MLX5_FLOW_ACTION_SET_TP_DST;
5184 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5185 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5186 ret = flow_dv_validate_action_modify_ttl(action_flags,
5192 /* Count all modify-header actions as one action. */
5193 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5195 action_flags |= actions->type ==
5196 RTE_FLOW_ACTION_TYPE_SET_TTL ?
5197 MLX5_FLOW_ACTION_SET_TTL :
5198 MLX5_FLOW_ACTION_DEC_TTL;
5200 case RTE_FLOW_ACTION_TYPE_JUMP:
5201 ret = flow_dv_validate_action_jump(actions,
5208 action_flags |= MLX5_FLOW_ACTION_JUMP;
5210 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5211 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5212 ret = flow_dv_validate_action_modify_tcp_seq
5219 /* Count all modify-header actions as one action. */
5220 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5222 action_flags |= actions->type ==
5223 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
5224 MLX5_FLOW_ACTION_INC_TCP_SEQ :
5225 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
5227 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5228 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5229 ret = flow_dv_validate_action_modify_tcp_ack
5236 /* Count all modify-header actions as one action. */
5237 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5239 action_flags |= actions->type ==
5240 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
5241 MLX5_FLOW_ACTION_INC_TCP_ACK :
5242 MLX5_FLOW_ACTION_DEC_TCP_ACK;
5244 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
5245 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
5246 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
5248 case RTE_FLOW_ACTION_TYPE_METER:
5249 ret = mlx5_flow_validate_action_meter(dev,
5255 action_flags |= MLX5_FLOW_ACTION_METER;
5258 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5259 ret = flow_dv_validate_action_modify_ipv4_dscp
5266 /* Count all modify-header actions as one action. */
5267 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5269 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
5271 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5272 ret = flow_dv_validate_action_modify_ipv6_dscp
5279 /* Count all modify-header actions as one action. */
5280 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5282 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
5285 return rte_flow_error_set(error, ENOTSUP,
5286 RTE_FLOW_ERROR_TYPE_ACTION,
5288 "action not supported");
5292 * Validate the drop action mutual exclusion with other actions.
5293 * Drop action is mutually-exclusive with any other action, except for
5296 if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
5297 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
5298 return rte_flow_error_set(error, EINVAL,
5299 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5300 "Drop action is mutually-exclusive "
5301 "with any other action, except for "
5303 /* Eswitch has few restrictions on using items and actions */
5304 if (attr->transfer) {
5305 if (!mlx5_flow_ext_mreg_supported(dev) &&
5306 action_flags & MLX5_FLOW_ACTION_FLAG)
5307 return rte_flow_error_set(error, ENOTSUP,
5308 RTE_FLOW_ERROR_TYPE_ACTION,
5310 "unsupported action FLAG");
5311 if (!mlx5_flow_ext_mreg_supported(dev) &&
5312 action_flags & MLX5_FLOW_ACTION_MARK)
5313 return rte_flow_error_set(error, ENOTSUP,
5314 RTE_FLOW_ERROR_TYPE_ACTION,
5316 "unsupported action MARK");
5317 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
5318 return rte_flow_error_set(error, ENOTSUP,
5319 RTE_FLOW_ERROR_TYPE_ACTION,
5321 "unsupported action QUEUE");
5322 if (action_flags & MLX5_FLOW_ACTION_RSS)
5323 return rte_flow_error_set(error, ENOTSUP,
5324 RTE_FLOW_ERROR_TYPE_ACTION,
5326 "unsupported action RSS");
5327 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5328 return rte_flow_error_set(error, EINVAL,
5329 RTE_FLOW_ERROR_TYPE_ACTION,
5331 "no fate action is found");
5333 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
5334 return rte_flow_error_set(error, EINVAL,
5335 RTE_FLOW_ERROR_TYPE_ACTION,
5337 "no fate action is found");
5339 /* Continue validation for Xcap actions.*/
5340 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) && (queue_index == 0xFFFF ||
5341 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5342 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5343 MLX5_FLOW_XCAP_ACTIONS)
5344 return rte_flow_error_set(error, ENOTSUP,
5345 RTE_FLOW_ERROR_TYPE_ACTION,
5346 NULL, "encap and decap "
5347 "combination aren't supported");
5348 if (!attr->transfer && attr->ingress && (action_flags &
5349 MLX5_FLOW_ACTION_ENCAP))
5350 return rte_flow_error_set(error, ENOTSUP,
5351 RTE_FLOW_ERROR_TYPE_ACTION,
5352 NULL, "encap is not supported"
5353 " for ingress traffic");
5359 * Internal preparation function. Allocates the DV flow size,
5360 * this size is constant.
5363 * Pointer to the rte_eth_dev structure.
5365 * Pointer to the flow attributes.
5367 * Pointer to the list of items.
5368 * @param[in] actions
5369 * Pointer to the list of actions.
5371 * Pointer to the error structure.
5374 * Pointer to mlx5_flow object on success,
5375 * otherwise NULL and rte_errno is set.
5377 static struct mlx5_flow *
5378 flow_dv_prepare(struct rte_eth_dev *dev,
5379 const struct rte_flow_attr *attr __rte_unused,
5380 const struct rte_flow_item items[] __rte_unused,
5381 const struct rte_flow_action actions[] __rte_unused,
5382 struct rte_flow_error *error)
5384 size_t size = sizeof(struct mlx5_flow_handle);
5385 struct mlx5_flow *dev_flow;
5386 struct mlx5_flow_handle *dev_handle;
5387 struct mlx5_priv *priv = dev->data->dev_private;
5389 /* In case of corrupting the memory. */
5390 if (priv->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
5391 rte_flow_error_set(error, ENOSPC,
5392 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5393 "not free temporary device flow");
5396 dev_handle = rte_calloc(__func__, 1, size, 0);
5398 rte_flow_error_set(error, ENOMEM,
5399 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5400 "not enough memory to create flow handle");
5403 /* No multi-thread supporting. */
5404 dev_flow = &((struct mlx5_flow *)priv->inter_flows)[priv->flow_idx++];
5405 dev_flow->handle = dev_handle;
5406 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
5408 * The matching value needs to be cleared to 0 before using. In the
5409 * past, it will be automatically cleared when using rte_*alloc
5410 * API. The time consumption will be almost the same as before.
5412 memset(dev_flow->dv.value.buf, 0, MLX5_ST_SZ_BYTES(fte_match_param));
5413 dev_flow->ingress = attr->ingress;
5414 dev_flow->dv.transfer = attr->transfer;
5418 #ifdef RTE_LIBRTE_MLX5_DEBUG
5420 * Sanity check for match mask and value. Similar to check_valid_spec() in
5421 * kernel driver. If unmasked bit is present in value, it returns failure.
5424 * pointer to match mask buffer.
5425 * @param match_value
5426 * pointer to match value buffer.
5429 * 0 if valid, -EINVAL otherwise.
5432 flow_dv_check_valid_spec(void *match_mask, void *match_value)
5434 uint8_t *m = match_mask;
5435 uint8_t *v = match_value;
5438 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
5441 "match_value differs from match_criteria"
5442 " %p[%u] != %p[%u]",
5443 match_value, i, match_mask, i);
5452 * Add Ethernet item to matcher and to the value.
5454 * @param[in, out] matcher
5456 * @param[in, out] key
5457 * Flow matcher value.
5459 * Flow pattern to translate.
5461 * Item is inner pattern.
5464 flow_dv_translate_item_eth(void *matcher, void *key,
5465 const struct rte_flow_item *item, int inner)
5467 const struct rte_flow_item_eth *eth_m = item->mask;
5468 const struct rte_flow_item_eth *eth_v = item->spec;
5469 const struct rte_flow_item_eth nic_mask = {
5470 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
5471 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
5472 .type = RTE_BE16(0xffff),
5484 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5486 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5488 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5490 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5492 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, dmac_47_16),
5493 ð_m->dst, sizeof(eth_m->dst));
5494 /* The value must be in the range of the mask. */
5495 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, dmac_47_16);
5496 for (i = 0; i < sizeof(eth_m->dst); ++i)
5497 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
5498 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, smac_47_16),
5499 ð_m->src, sizeof(eth_m->src));
5500 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, smac_47_16);
5501 /* The value must be in the range of the mask. */
5502 for (i = 0; i < sizeof(eth_m->dst); ++i)
5503 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
5505 /* When ethertype is present set mask for tagged VLAN. */
5506 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5507 /* Set value for tagged VLAN if ethertype is 802.1Q. */
5508 if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_VLAN) ||
5509 eth_v->type == RTE_BE16(RTE_ETHER_TYPE_QINQ)) {
5510 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag,
5512 /* Return here to avoid setting match on ethertype. */
5517 * HW supports match on one Ethertype, the Ethertype following the last
5518 * VLAN tag of the packet (see PRM).
5519 * Set match on ethertype only if ETH header is not followed by VLAN.
5521 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
5522 rte_be_to_cpu_16(eth_m->type));
5523 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, ethertype);
5524 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
5528 * Add VLAN item to matcher and to the value.
5530 * @param[in, out] dev_flow
5532 * @param[in, out] matcher
5534 * @param[in, out] key
5535 * Flow matcher value.
5537 * Flow pattern to translate.
5539 * Item is inner pattern.
5542 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
5543 void *matcher, void *key,
5544 const struct rte_flow_item *item,
5547 const struct rte_flow_item_vlan *vlan_m = item->mask;
5548 const struct rte_flow_item_vlan *vlan_v = item->spec;
5557 vlan_m = &rte_flow_item_vlan_mask;
5559 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5561 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5563 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5565 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5567 * This is workaround, masks are not supported,
5568 * and pre-validated.
5570 dev_flow->handle->vf_vlan.tag =
5571 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
5573 tci_m = rte_be_to_cpu_16(vlan_m->tci);
5574 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
5575 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5576 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
5577 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_vid, tci_m);
5578 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, tci_v);
5579 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_cfi, tci_m >> 12);
5580 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_cfi, tci_v >> 12);
5581 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_prio, tci_m >> 13);
5582 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, tci_v >> 13);
5583 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
5584 rte_be_to_cpu_16(vlan_m->inner_type));
5585 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
5586 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
5590 * Add IPV4 item to matcher and to the value.
5592 * @param[in, out] matcher
5594 * @param[in, out] key
5595 * Flow matcher value.
5597 * Flow pattern to translate.
5598 * @param[in] item_flags
5599 * Bit-fields that holds the items detected until now.
5601 * Item is inner pattern.
5603 * The group to insert the rule.
5606 flow_dv_translate_item_ipv4(void *matcher, void *key,
5607 const struct rte_flow_item *item,
5608 const uint64_t item_flags,
5609 int inner, uint32_t group)
5611 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
5612 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
5613 const struct rte_flow_item_ipv4 nic_mask = {
5615 .src_addr = RTE_BE32(0xffffffff),
5616 .dst_addr = RTE_BE32(0xffffffff),
5617 .type_of_service = 0xff,
5618 .next_proto_id = 0xff,
5619 .time_to_live = 0xff,
5629 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5631 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5633 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5635 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5638 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
5640 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0x4);
5641 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 4);
5643 * On outer header (which must contains L2), or inner header with L2,
5644 * set cvlan_tag mask bit to mark this packet as untagged.
5645 * This should be done even if item->spec is empty.
5647 if (!inner || item_flags & MLX5_FLOW_LAYER_INNER_L2)
5648 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5653 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5654 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
5655 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5656 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
5657 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
5658 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
5659 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5660 src_ipv4_src_ipv6.ipv4_layout.ipv4);
5661 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5662 src_ipv4_src_ipv6.ipv4_layout.ipv4);
5663 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
5664 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
5665 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
5666 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
5667 ipv4_m->hdr.type_of_service);
5668 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
5669 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
5670 ipv4_m->hdr.type_of_service >> 2);
5671 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
5672 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
5673 ipv4_m->hdr.next_proto_id);
5674 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
5675 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
5676 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
5677 ipv4_m->hdr.time_to_live);
5678 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
5679 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
5683 * Add IPV6 item to matcher and to the value.
5685 * @param[in, out] matcher
5687 * @param[in, out] key
5688 * Flow matcher value.
5690 * Flow pattern to translate.
5691 * @param[in] item_flags
5692 * Bit-fields that holds the items detected until now.
5694 * Item is inner pattern.
5696 * The group to insert the rule.
5699 flow_dv_translate_item_ipv6(void *matcher, void *key,
5700 const struct rte_flow_item *item,
5701 const uint64_t item_flags,
5702 int inner, uint32_t group)
5704 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
5705 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
5706 const struct rte_flow_item_ipv6 nic_mask = {
5709 "\xff\xff\xff\xff\xff\xff\xff\xff"
5710 "\xff\xff\xff\xff\xff\xff\xff\xff",
5712 "\xff\xff\xff\xff\xff\xff\xff\xff"
5713 "\xff\xff\xff\xff\xff\xff\xff\xff",
5714 .vtc_flow = RTE_BE32(0xffffffff),
5721 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5722 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5731 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5733 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5735 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5737 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5740 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
5742 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0x6);
5743 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 6);
5745 * On outer header (which must contains L2), or inner header with L2,
5746 * set cvlan_tag mask bit to mark this packet as untagged.
5747 * This should be done even if item->spec is empty.
5749 if (!inner || item_flags & MLX5_FLOW_LAYER_INNER_L2)
5750 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
5755 size = sizeof(ipv6_m->hdr.dst_addr);
5756 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5757 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
5758 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5759 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
5760 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
5761 for (i = 0; i < size; ++i)
5762 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
5763 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
5764 src_ipv4_src_ipv6.ipv6_layout.ipv6);
5765 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
5766 src_ipv4_src_ipv6.ipv6_layout.ipv6);
5767 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
5768 for (i = 0; i < size; ++i)
5769 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
5771 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
5772 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
5773 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
5774 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
5775 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
5776 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
5779 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
5781 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
5784 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
5786 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
5790 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
5792 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
5793 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
5795 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
5796 ipv6_m->hdr.hop_limits);
5797 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
5798 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
5802 * Add TCP item to matcher and to the value.
5804 * @param[in, out] matcher
5806 * @param[in, out] key
5807 * Flow matcher value.
5809 * Flow pattern to translate.
5811 * Item is inner pattern.
5814 flow_dv_translate_item_tcp(void *matcher, void *key,
5815 const struct rte_flow_item *item,
5818 const struct rte_flow_item_tcp *tcp_m = item->mask;
5819 const struct rte_flow_item_tcp *tcp_v = item->spec;
5824 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5826 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5828 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5830 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5832 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
5833 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
5837 tcp_m = &rte_flow_item_tcp_mask;
5838 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
5839 rte_be_to_cpu_16(tcp_m->hdr.src_port));
5840 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
5841 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
5842 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
5843 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
5844 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
5845 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
5846 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
5847 tcp_m->hdr.tcp_flags);
5848 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
5849 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
5853 * Add UDP item to matcher and to the value.
5855 * @param[in, out] matcher
5857 * @param[in, out] key
5858 * Flow matcher value.
5860 * Flow pattern to translate.
5862 * Item is inner pattern.
5865 flow_dv_translate_item_udp(void *matcher, void *key,
5866 const struct rte_flow_item *item,
5869 const struct rte_flow_item_udp *udp_m = item->mask;
5870 const struct rte_flow_item_udp *udp_v = item->spec;
5875 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5877 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5879 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5881 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5883 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
5884 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
5888 udp_m = &rte_flow_item_udp_mask;
5889 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
5890 rte_be_to_cpu_16(udp_m->hdr.src_port));
5891 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
5892 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
5893 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
5894 rte_be_to_cpu_16(udp_m->hdr.dst_port));
5895 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
5896 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
5900 * Add GRE optional Key item to matcher and to the value.
5902 * @param[in, out] matcher
5904 * @param[in, out] key
5905 * Flow matcher value.
5907 * Flow pattern to translate.
5909 * Item is inner pattern.
5912 flow_dv_translate_item_gre_key(void *matcher, void *key,
5913 const struct rte_flow_item *item)
5915 const rte_be32_t *key_m = item->mask;
5916 const rte_be32_t *key_v = item->spec;
5917 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5918 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5919 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
5921 /* GRE K bit must be on and should already be validated */
5922 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
5923 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
5927 key_m = &gre_key_default_mask;
5928 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
5929 rte_be_to_cpu_32(*key_m) >> 8);
5930 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
5931 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
5932 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
5933 rte_be_to_cpu_32(*key_m) & 0xFF);
5934 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
5935 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
5939 * Add GRE item to matcher and to the value.
5941 * @param[in, out] matcher
5943 * @param[in, out] key
5944 * Flow matcher value.
5946 * Flow pattern to translate.
5948 * Item is inner pattern.
5951 flow_dv_translate_item_gre(void *matcher, void *key,
5952 const struct rte_flow_item *item,
5955 const struct rte_flow_item_gre *gre_m = item->mask;
5956 const struct rte_flow_item_gre *gre_v = item->spec;
5959 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
5960 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
5967 uint16_t s_present:1;
5968 uint16_t k_present:1;
5969 uint16_t rsvd_bit1:1;
5970 uint16_t c_present:1;
5974 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
5977 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5979 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
5981 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
5983 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
5985 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
5986 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
5990 gre_m = &rte_flow_item_gre_mask;
5991 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
5992 rte_be_to_cpu_16(gre_m->protocol));
5993 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
5994 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
5995 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
5996 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
5997 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
5998 gre_crks_rsvd0_ver_m.c_present);
5999 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
6000 gre_crks_rsvd0_ver_v.c_present &
6001 gre_crks_rsvd0_ver_m.c_present);
6002 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
6003 gre_crks_rsvd0_ver_m.k_present);
6004 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
6005 gre_crks_rsvd0_ver_v.k_present &
6006 gre_crks_rsvd0_ver_m.k_present);
6007 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
6008 gre_crks_rsvd0_ver_m.s_present);
6009 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
6010 gre_crks_rsvd0_ver_v.s_present &
6011 gre_crks_rsvd0_ver_m.s_present);
6015 * Add NVGRE item to matcher and to the value.
6017 * @param[in, out] matcher
6019 * @param[in, out] key
6020 * Flow matcher value.
6022 * Flow pattern to translate.
6024 * Item is inner pattern.
6027 flow_dv_translate_item_nvgre(void *matcher, void *key,
6028 const struct rte_flow_item *item,
6031 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
6032 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
6033 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6034 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6035 const char *tni_flow_id_m = (const char *)nvgre_m->tni;
6036 const char *tni_flow_id_v = (const char *)nvgre_v->tni;
6042 /* For NVGRE, GRE header fields must be set with defined values. */
6043 const struct rte_flow_item_gre gre_spec = {
6044 .c_rsvd0_ver = RTE_BE16(0x2000),
6045 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
6047 const struct rte_flow_item_gre gre_mask = {
6048 .c_rsvd0_ver = RTE_BE16(0xB000),
6049 .protocol = RTE_BE16(UINT16_MAX),
6051 const struct rte_flow_item gre_item = {
6056 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
6060 nvgre_m = &rte_flow_item_nvgre_mask;
6061 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
6062 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
6063 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
6064 memcpy(gre_key_m, tni_flow_id_m, size);
6065 for (i = 0; i < size; ++i)
6066 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
6070 * Add VXLAN item to matcher and to the value.
6072 * @param[in, out] matcher
6074 * @param[in, out] key
6075 * Flow matcher value.
6077 * Flow pattern to translate.
6079 * Item is inner pattern.
6082 flow_dv_translate_item_vxlan(void *matcher, void *key,
6083 const struct rte_flow_item *item,
6086 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
6087 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
6090 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6091 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6099 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6101 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6103 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6105 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6107 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
6108 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
6109 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6110 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6111 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6116 vxlan_m = &rte_flow_item_vxlan_mask;
6117 size = sizeof(vxlan_m->vni);
6118 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
6119 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
6120 memcpy(vni_m, vxlan_m->vni, size);
6121 for (i = 0; i < size; ++i)
6122 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
6126 * Add VXLAN-GPE item to matcher and to the value.
6128 * @param[in, out] matcher
6130 * @param[in, out] key
6131 * Flow matcher value.
6133 * Flow pattern to translate.
6135 * Item is inner pattern.
6139 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
6140 const struct rte_flow_item *item, int inner)
6142 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
6143 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
6147 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
6149 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6155 uint8_t flags_m = 0xff;
6156 uint8_t flags_v = 0xc;
6159 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6161 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6163 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6165 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6167 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
6168 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
6169 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6170 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6171 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6176 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
6177 size = sizeof(vxlan_m->vni);
6178 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
6179 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
6180 memcpy(vni_m, vxlan_m->vni, size);
6181 for (i = 0; i < size; ++i)
6182 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
6183 if (vxlan_m->flags) {
6184 flags_m = vxlan_m->flags;
6185 flags_v = vxlan_v->flags;
6187 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
6188 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
6189 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
6191 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
6196 * Add Geneve item to matcher and to the value.
6198 * @param[in, out] matcher
6200 * @param[in, out] key
6201 * Flow matcher value.
6203 * Flow pattern to translate.
6205 * Item is inner pattern.
6209 flow_dv_translate_item_geneve(void *matcher, void *key,
6210 const struct rte_flow_item *item, int inner)
6212 const struct rte_flow_item_geneve *geneve_m = item->mask;
6213 const struct rte_flow_item_geneve *geneve_v = item->spec;
6216 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6217 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6226 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6228 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6230 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6232 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6234 dport = MLX5_UDP_PORT_GENEVE;
6235 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6236 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6237 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6242 geneve_m = &rte_flow_item_geneve_mask;
6243 size = sizeof(geneve_m->vni);
6244 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
6245 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
6246 memcpy(vni_m, geneve_m->vni, size);
6247 for (i = 0; i < size; ++i)
6248 vni_v[i] = vni_m[i] & geneve_v->vni[i];
6249 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
6250 rte_be_to_cpu_16(geneve_m->protocol));
6251 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
6252 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
6253 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
6254 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
6255 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
6256 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
6257 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
6258 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
6259 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
6260 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
6261 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
6262 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
6263 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
6267 * Add MPLS item to matcher and to the value.
6269 * @param[in, out] matcher
6271 * @param[in, out] key
6272 * Flow matcher value.
6274 * Flow pattern to translate.
6275 * @param[in] prev_layer
6276 * The protocol layer indicated in previous item.
6278 * Item is inner pattern.
6281 flow_dv_translate_item_mpls(void *matcher, void *key,
6282 const struct rte_flow_item *item,
6283 uint64_t prev_layer,
6286 const uint32_t *in_mpls_m = item->mask;
6287 const uint32_t *in_mpls_v = item->spec;
6288 uint32_t *out_mpls_m = 0;
6289 uint32_t *out_mpls_v = 0;
6290 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6291 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6292 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
6294 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
6295 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
6296 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6298 switch (prev_layer) {
6299 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
6300 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
6301 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
6302 MLX5_UDP_PORT_MPLS);
6304 case MLX5_FLOW_LAYER_GRE:
6305 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
6306 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
6307 RTE_ETHER_TYPE_MPLS);
6310 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6311 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6318 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
6319 switch (prev_layer) {
6320 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
6322 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
6323 outer_first_mpls_over_udp);
6325 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
6326 outer_first_mpls_over_udp);
6328 case MLX5_FLOW_LAYER_GRE:
6330 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
6331 outer_first_mpls_over_gre);
6333 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
6334 outer_first_mpls_over_gre);
6337 /* Inner MPLS not over GRE is not supported. */
6340 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
6344 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
6350 if (out_mpls_m && out_mpls_v) {
6351 *out_mpls_m = *in_mpls_m;
6352 *out_mpls_v = *in_mpls_v & *in_mpls_m;
6357 * Add metadata register item to matcher
6359 * @param[in, out] matcher
6361 * @param[in, out] key
6362 * Flow matcher value.
6363 * @param[in] reg_type
6364 * Type of device metadata register
6371 flow_dv_match_meta_reg(void *matcher, void *key,
6372 enum modify_reg reg_type,
6373 uint32_t data, uint32_t mask)
6376 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
6378 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
6384 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
6385 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
6388 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
6389 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
6393 * The metadata register C0 field might be divided into
6394 * source vport index and META item value, we should set
6395 * this field according to specified mask, not as whole one.
6397 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
6399 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
6400 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
6403 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
6406 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
6407 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
6410 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
6411 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
6414 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
6415 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
6418 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
6419 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
6422 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
6423 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
6426 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
6427 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
6430 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
6431 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
6440 * Add MARK item to matcher
6443 * The device to configure through.
6444 * @param[in, out] matcher
6446 * @param[in, out] key
6447 * Flow matcher value.
6449 * Flow pattern to translate.
6452 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
6453 void *matcher, void *key,
6454 const struct rte_flow_item *item)
6456 struct mlx5_priv *priv = dev->data->dev_private;
6457 const struct rte_flow_item_mark *mark;
6461 mark = item->mask ? (const void *)item->mask :
6462 &rte_flow_item_mark_mask;
6463 mask = mark->id & priv->sh->dv_mark_mask;
6464 mark = (const void *)item->spec;
6466 value = mark->id & priv->sh->dv_mark_mask & mask;
6468 enum modify_reg reg;
6470 /* Get the metadata register index for the mark. */
6471 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
6472 MLX5_ASSERT(reg > 0);
6473 if (reg == REG_C_0) {
6474 struct mlx5_priv *priv = dev->data->dev_private;
6475 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6476 uint32_t shl_c0 = rte_bsf32(msk_c0);
6482 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6487 * Add META item to matcher
6490 * The devich to configure through.
6491 * @param[in, out] matcher
6493 * @param[in, out] key
6494 * Flow matcher value.
6496 * Attributes of flow that includes this item.
6498 * Flow pattern to translate.
6501 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
6502 void *matcher, void *key,
6503 const struct rte_flow_attr *attr,
6504 const struct rte_flow_item *item)
6506 const struct rte_flow_item_meta *meta_m;
6507 const struct rte_flow_item_meta *meta_v;
6509 meta_m = (const void *)item->mask;
6511 meta_m = &rte_flow_item_meta_mask;
6512 meta_v = (const void *)item->spec;
6515 uint32_t value = meta_v->data;
6516 uint32_t mask = meta_m->data;
6518 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
6522 * In datapath code there is no endianness
6523 * coversions for perfromance reasons, all
6524 * pattern conversions are done in rte_flow.
6526 value = rte_cpu_to_be_32(value);
6527 mask = rte_cpu_to_be_32(mask);
6528 if (reg == REG_C_0) {
6529 struct mlx5_priv *priv = dev->data->dev_private;
6530 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6531 uint32_t shl_c0 = rte_bsf32(msk_c0);
6532 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
6533 uint32_t shr_c0 = __builtin_clz(priv->sh->dv_meta_mask);
6540 MLX5_ASSERT(msk_c0);
6541 MLX5_ASSERT(!(~msk_c0 & mask));
6543 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
6548 * Add vport metadata Reg C0 item to matcher
6550 * @param[in, out] matcher
6552 * @param[in, out] key
6553 * Flow matcher value.
6555 * Flow pattern to translate.
6558 flow_dv_translate_item_meta_vport(void *matcher, void *key,
6559 uint32_t value, uint32_t mask)
6561 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
6565 * Add tag item to matcher
6568 * The devich to configure through.
6569 * @param[in, out] matcher
6571 * @param[in, out] key
6572 * Flow matcher value.
6574 * Flow pattern to translate.
6577 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
6578 void *matcher, void *key,
6579 const struct rte_flow_item *item)
6581 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
6582 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
6583 uint32_t mask, value;
6586 value = tag_v->data;
6587 mask = tag_m ? tag_m->data : UINT32_MAX;
6588 if (tag_v->id == REG_C_0) {
6589 struct mlx5_priv *priv = dev->data->dev_private;
6590 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
6591 uint32_t shl_c0 = rte_bsf32(msk_c0);
6597 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
6601 * Add TAG item to matcher
6604 * The devich to configure through.
6605 * @param[in, out] matcher
6607 * @param[in, out] key
6608 * Flow matcher value.
6610 * Flow pattern to translate.
6613 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
6614 void *matcher, void *key,
6615 const struct rte_flow_item *item)
6617 const struct rte_flow_item_tag *tag_v = item->spec;
6618 const struct rte_flow_item_tag *tag_m = item->mask;
6619 enum modify_reg reg;
6622 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
6623 /* Get the metadata register index for the tag. */
6624 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
6625 MLX5_ASSERT(reg > 0);
6626 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
6630 * Add source vport match to the specified matcher.
6632 * @param[in, out] matcher
6634 * @param[in, out] key
6635 * Flow matcher value.
6637 * Source vport value to match
6642 flow_dv_translate_item_source_vport(void *matcher, void *key,
6643 int16_t port, uint16_t mask)
6645 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6646 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6648 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
6649 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
6653 * Translate port-id item to eswitch match on port-id.
6656 * The devich to configure through.
6657 * @param[in, out] matcher
6659 * @param[in, out] key
6660 * Flow matcher value.
6662 * Flow pattern to translate.
6665 * 0 on success, a negative errno value otherwise.
6668 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
6669 void *key, const struct rte_flow_item *item)
6671 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
6672 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
6673 struct mlx5_priv *priv;
6676 mask = pid_m ? pid_m->id : 0xffff;
6677 id = pid_v ? pid_v->id : dev->data->port_id;
6678 priv = mlx5_port_to_eswitch_info(id, item == NULL);
6681 /* Translate to vport field or to metadata, depending on mode. */
6682 if (priv->vport_meta_mask)
6683 flow_dv_translate_item_meta_vport(matcher, key,
6684 priv->vport_meta_tag,
6685 priv->vport_meta_mask);
6687 flow_dv_translate_item_source_vport(matcher, key,
6688 priv->vport_id, mask);
6693 * Add ICMP6 item to matcher and to the value.
6695 * @param[in, out] matcher
6697 * @param[in, out] key
6698 * Flow matcher value.
6700 * Flow pattern to translate.
6702 * Item is inner pattern.
6705 flow_dv_translate_item_icmp6(void *matcher, void *key,
6706 const struct rte_flow_item *item,
6709 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
6710 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
6713 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
6715 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6717 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6719 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6721 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6723 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6725 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
6726 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
6730 icmp6_m = &rte_flow_item_icmp6_mask;
6732 * Force flow only to match the non-fragmented IPv6 ICMPv6 packets.
6733 * If only the protocol is specified, no need to match the frag.
6735 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
6736 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
6737 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
6738 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
6739 icmp6_v->type & icmp6_m->type);
6740 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
6741 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
6742 icmp6_v->code & icmp6_m->code);
6746 * Add ICMP item to matcher and to the value.
6748 * @param[in, out] matcher
6750 * @param[in, out] key
6751 * Flow matcher value.
6753 * Flow pattern to translate.
6755 * Item is inner pattern.
6758 flow_dv_translate_item_icmp(void *matcher, void *key,
6759 const struct rte_flow_item *item,
6762 const struct rte_flow_item_icmp *icmp_m = item->mask;
6763 const struct rte_flow_item_icmp *icmp_v = item->spec;
6766 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
6768 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6770 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6772 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6774 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6776 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6778 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
6779 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
6783 icmp_m = &rte_flow_item_icmp_mask;
6785 * Force flow only to match the non-fragmented IPv4 ICMP packets.
6786 * If only the protocol is specified, no need to match the frag.
6788 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
6789 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
6790 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
6791 icmp_m->hdr.icmp_type);
6792 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
6793 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
6794 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
6795 icmp_m->hdr.icmp_code);
6796 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
6797 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
6801 * Add GTP item to matcher and to the value.
6803 * @param[in, out] matcher
6805 * @param[in, out] key
6806 * Flow matcher value.
6808 * Flow pattern to translate.
6810 * Item is inner pattern.
6813 flow_dv_translate_item_gtp(void *matcher, void *key,
6814 const struct rte_flow_item *item, int inner)
6816 const struct rte_flow_item_gtp *gtp_m = item->mask;
6817 const struct rte_flow_item_gtp *gtp_v = item->spec;
6820 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
6822 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6823 uint16_t dport = RTE_GTPU_UDP_PORT;
6826 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6828 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6830 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6832 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6834 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6835 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6836 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6841 gtp_m = &rte_flow_item_gtp_mask;
6842 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
6843 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
6844 gtp_v->msg_type & gtp_m->msg_type);
6845 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
6846 rte_be_to_cpu_32(gtp_m->teid));
6847 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
6848 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
6851 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
6853 #define HEADER_IS_ZERO(match_criteria, headers) \
6854 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
6855 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
6858 * Calculate flow matcher enable bitmap.
6860 * @param match_criteria
6861 * Pointer to flow matcher criteria.
6864 * Bitmap of enabled fields.
6867 flow_dv_matcher_enable(uint32_t *match_criteria)
6869 uint8_t match_criteria_enable;
6871 match_criteria_enable =
6872 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
6873 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
6874 match_criteria_enable |=
6875 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
6876 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
6877 match_criteria_enable |=
6878 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
6879 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
6880 match_criteria_enable |=
6881 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
6882 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
6883 match_criteria_enable |=
6884 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
6885 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
6886 return match_criteria_enable;
6893 * @param[in, out] dev
6894 * Pointer to rte_eth_dev structure.
6895 * @param[in] table_id
6898 * Direction of the table.
6899 * @param[in] transfer
6900 * E-Switch or NIC flow.
6902 * pointer to error structure.
6905 * Returns tables resource based on the index, NULL in case of failed.
6907 static struct mlx5_flow_tbl_resource *
6908 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
6909 uint32_t table_id, uint8_t egress,
6911 struct rte_flow_error *error)
6913 struct mlx5_priv *priv = dev->data->dev_private;
6914 struct mlx5_ibv_shared *sh = priv->sh;
6915 struct mlx5_flow_tbl_resource *tbl;
6916 union mlx5_flow_tbl_key table_key = {
6918 .table_id = table_id,
6920 .domain = !!transfer,
6921 .direction = !!egress,
6924 struct mlx5_hlist_entry *pos = mlx5_hlist_lookup(sh->flow_tbls,
6926 struct mlx5_flow_tbl_data_entry *tbl_data;
6931 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
6933 tbl = &tbl_data->tbl;
6934 rte_atomic32_inc(&tbl->refcnt);
6937 tbl_data = rte_zmalloc(NULL, sizeof(*tbl_data), 0);
6939 rte_flow_error_set(error, ENOMEM,
6940 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6942 "cannot allocate flow table data entry");
6945 tbl = &tbl_data->tbl;
6946 pos = &tbl_data->entry;
6948 domain = sh->fdb_domain;
6950 domain = sh->tx_domain;
6952 domain = sh->rx_domain;
6953 tbl->obj = mlx5_glue->dr_create_flow_tbl(domain, table_id);
6955 rte_flow_error_set(error, ENOMEM,
6956 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6957 NULL, "cannot create flow table object");
6962 * No multi-threads now, but still better to initialize the reference
6963 * count before insert it into the hash list.
6965 rte_atomic32_init(&tbl->refcnt);
6966 /* Jump action reference count is initialized here. */
6967 rte_atomic32_init(&tbl_data->jump.refcnt);
6968 pos->key = table_key.v64;
6969 ret = mlx5_hlist_insert(sh->flow_tbls, pos);
6971 rte_flow_error_set(error, -ret,
6972 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6973 "cannot insert flow table data entry");
6974 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
6977 rte_atomic32_inc(&tbl->refcnt);
6982 * Release a flow table.
6985 * Pointer to rte_eth_dev structure.
6987 * Table resource to be released.
6990 * Returns 0 if table was released, else return 1;
6993 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
6994 struct mlx5_flow_tbl_resource *tbl)
6996 struct mlx5_priv *priv = dev->data->dev_private;
6997 struct mlx5_ibv_shared *sh = priv->sh;
6998 struct mlx5_flow_tbl_data_entry *tbl_data =
6999 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
7003 if (rte_atomic32_dec_and_test(&tbl->refcnt)) {
7004 struct mlx5_hlist_entry *pos = &tbl_data->entry;
7006 mlx5_glue->dr_destroy_flow_tbl(tbl->obj);
7008 /* remove the entry from the hash list and free memory. */
7009 mlx5_hlist_remove(sh->flow_tbls, pos);
7017 * Register the flow matcher.
7019 * @param[in, out] dev
7020 * Pointer to rte_eth_dev structure.
7021 * @param[in, out] matcher
7022 * Pointer to flow matcher.
7023 * @param[in, out] key
7024 * Pointer to flow table key.
7025 * @parm[in, out] dev_flow
7026 * Pointer to the dev_flow.
7028 * pointer to error structure.
7031 * 0 on success otherwise -errno and errno is set.
7034 flow_dv_matcher_register(struct rte_eth_dev *dev,
7035 struct mlx5_flow_dv_matcher *matcher,
7036 union mlx5_flow_tbl_key *key,
7037 struct mlx5_flow *dev_flow,
7038 struct rte_flow_error *error)
7040 struct mlx5_priv *priv = dev->data->dev_private;
7041 struct mlx5_ibv_shared *sh = priv->sh;
7042 struct mlx5_flow_dv_matcher *cache_matcher;
7043 struct mlx5dv_flow_matcher_attr dv_attr = {
7044 .type = IBV_FLOW_ATTR_NORMAL,
7045 .match_mask = (void *)&matcher->mask,
7047 struct mlx5_flow_tbl_resource *tbl;
7048 struct mlx5_flow_tbl_data_entry *tbl_data;
7050 tbl = flow_dv_tbl_resource_get(dev, key->table_id, key->direction,
7051 key->domain, error);
7053 return -rte_errno; /* No need to refill the error info */
7054 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
7055 /* Lookup from cache. */
7056 LIST_FOREACH(cache_matcher, &tbl_data->matchers, next) {
7057 if (matcher->crc == cache_matcher->crc &&
7058 matcher->priority == cache_matcher->priority &&
7059 !memcmp((const void *)matcher->mask.buf,
7060 (const void *)cache_matcher->mask.buf,
7061 cache_matcher->mask.size)) {
7063 "%s group %u priority %hd use %s "
7064 "matcher %p: refcnt %d++",
7065 key->domain ? "FDB" : "NIC", key->table_id,
7066 cache_matcher->priority,
7067 key->direction ? "tx" : "rx",
7068 (void *)cache_matcher,
7069 rte_atomic32_read(&cache_matcher->refcnt));
7070 rte_atomic32_inc(&cache_matcher->refcnt);
7071 dev_flow->handle->dvh.matcher = cache_matcher;
7072 /* old matcher should not make the table ref++. */
7073 flow_dv_tbl_resource_release(dev, tbl);
7077 /* Register new matcher. */
7078 cache_matcher = rte_calloc(__func__, 1, sizeof(*cache_matcher), 0);
7079 if (!cache_matcher) {
7080 flow_dv_tbl_resource_release(dev, tbl);
7081 return rte_flow_error_set(error, ENOMEM,
7082 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7083 "cannot allocate matcher memory");
7085 *cache_matcher = *matcher;
7086 dv_attr.match_criteria_enable =
7087 flow_dv_matcher_enable(cache_matcher->mask.buf);
7088 dv_attr.priority = matcher->priority;
7090 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
7091 cache_matcher->matcher_object =
7092 mlx5_glue->dv_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj);
7093 if (!cache_matcher->matcher_object) {
7094 rte_free(cache_matcher);
7095 #ifdef HAVE_MLX5DV_DR
7096 flow_dv_tbl_resource_release(dev, tbl);
7098 return rte_flow_error_set(error, ENOMEM,
7099 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7100 NULL, "cannot create matcher");
7102 /* Save the table information */
7103 cache_matcher->tbl = tbl;
7104 rte_atomic32_init(&cache_matcher->refcnt);
7105 /* only matcher ref++, table ref++ already done above in get API. */
7106 rte_atomic32_inc(&cache_matcher->refcnt);
7107 LIST_INSERT_HEAD(&tbl_data->matchers, cache_matcher, next);
7108 dev_flow->handle->dvh.matcher = cache_matcher;
7109 DRV_LOG(DEBUG, "%s group %u priority %hd new %s matcher %p: refcnt %d",
7110 key->domain ? "FDB" : "NIC", key->table_id,
7111 cache_matcher->priority,
7112 key->direction ? "tx" : "rx", (void *)cache_matcher,
7113 rte_atomic32_read(&cache_matcher->refcnt));
7118 * Find existing tag resource or create and register a new one.
7120 * @param dev[in, out]
7121 * Pointer to rte_eth_dev structure.
7122 * @param[in, out] tag_be24
7123 * Tag value in big endian then R-shift 8.
7124 * @parm[in, out] dev_flow
7125 * Pointer to the dev_flow.
7127 * pointer to error structure.
7130 * 0 on success otherwise -errno and errno is set.
7133 flow_dv_tag_resource_register
7134 (struct rte_eth_dev *dev,
7136 struct mlx5_flow *dev_flow,
7137 struct rte_flow_error *error)
7139 struct mlx5_priv *priv = dev->data->dev_private;
7140 struct mlx5_ibv_shared *sh = priv->sh;
7141 struct mlx5_flow_dv_tag_resource *cache_resource;
7142 struct mlx5_hlist_entry *entry;
7144 /* Lookup a matching resource from cache. */
7145 entry = mlx5_hlist_lookup(sh->tag_table, (uint64_t)tag_be24);
7147 cache_resource = container_of
7148 (entry, struct mlx5_flow_dv_tag_resource, entry);
7149 rte_atomic32_inc(&cache_resource->refcnt);
7150 dev_flow->handle->dvh.tag_resource = cache_resource;
7151 DRV_LOG(DEBUG, "cached tag resource %p: refcnt now %d++",
7152 (void *)cache_resource,
7153 rte_atomic32_read(&cache_resource->refcnt));
7156 /* Register new resource. */
7157 cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
7158 if (!cache_resource)
7159 return rte_flow_error_set(error, ENOMEM,
7160 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7161 "cannot allocate resource memory");
7162 cache_resource->entry.key = (uint64_t)tag_be24;
7163 cache_resource->action = mlx5_glue->dv_create_flow_action_tag(tag_be24);
7164 if (!cache_resource->action) {
7165 rte_free(cache_resource);
7166 return rte_flow_error_set(error, ENOMEM,
7167 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7168 NULL, "cannot create action");
7170 rte_atomic32_init(&cache_resource->refcnt);
7171 rte_atomic32_inc(&cache_resource->refcnt);
7172 if (mlx5_hlist_insert(sh->tag_table, &cache_resource->entry)) {
7173 mlx5_glue->destroy_flow_action(cache_resource->action);
7174 rte_free(cache_resource);
7175 return rte_flow_error_set(error, EEXIST,
7176 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7177 NULL, "cannot insert tag");
7179 dev_flow->handle->dvh.tag_resource = cache_resource;
7180 DRV_LOG(DEBUG, "new tag resource %p: refcnt now %d++",
7181 (void *)cache_resource,
7182 rte_atomic32_read(&cache_resource->refcnt));
7190 * Pointer to Ethernet device.
7192 * Pointer to mlx5_flow.
7195 * 1 while a reference on it exists, 0 when freed.
7198 flow_dv_tag_release(struct rte_eth_dev *dev,
7199 struct mlx5_flow_dv_tag_resource *tag)
7201 struct mlx5_priv *priv = dev->data->dev_private;
7202 struct mlx5_ibv_shared *sh = priv->sh;
7205 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
7206 dev->data->port_id, (void *)tag,
7207 rte_atomic32_read(&tag->refcnt));
7208 if (rte_atomic32_dec_and_test(&tag->refcnt)) {
7209 claim_zero(mlx5_glue->destroy_flow_action(tag->action));
7210 mlx5_hlist_remove(sh->tag_table, &tag->entry);
7211 DRV_LOG(DEBUG, "port %u tag %p: removed",
7212 dev->data->port_id, (void *)tag);
7220 * Translate port ID action to vport.
7223 * Pointer to rte_eth_dev structure.
7225 * Pointer to the port ID action.
7226 * @param[out] dst_port_id
7227 * The target port ID.
7229 * Pointer to the error structure.
7232 * 0 on success, a negative errno value otherwise and rte_errno is set.
7235 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
7236 const struct rte_flow_action *action,
7237 uint32_t *dst_port_id,
7238 struct rte_flow_error *error)
7241 struct mlx5_priv *priv;
7242 const struct rte_flow_action_port_id *conf =
7243 (const struct rte_flow_action_port_id *)action->conf;
7245 port = conf->original ? dev->data->port_id : conf->id;
7246 priv = mlx5_port_to_eswitch_info(port, false);
7248 return rte_flow_error_set(error, -rte_errno,
7249 RTE_FLOW_ERROR_TYPE_ACTION,
7251 "No eswitch info was found for port");
7252 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
7254 * This parameter is transferred to
7255 * mlx5dv_dr_action_create_dest_ib_port().
7257 *dst_port_id = priv->ibv_port;
7260 * Legacy mode, no LAG configurations is supported.
7261 * This parameter is transferred to
7262 * mlx5dv_dr_action_create_dest_vport().
7264 *dst_port_id = priv->vport_id;
7270 * Add Tx queue matcher
7273 * Pointer to the dev struct.
7274 * @param[in, out] matcher
7276 * @param[in, out] key
7277 * Flow matcher value.
7279 * Flow pattern to translate.
7281 * Item is inner pattern.
7284 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
7285 void *matcher, void *key,
7286 const struct rte_flow_item *item)
7288 const struct mlx5_rte_flow_item_tx_queue *queue_m;
7289 const struct mlx5_rte_flow_item_tx_queue *queue_v;
7291 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7293 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7294 struct mlx5_txq_ctrl *txq;
7298 queue_m = (const void *)item->mask;
7301 queue_v = (const void *)item->spec;
7304 txq = mlx5_txq_get(dev, queue_v->queue);
7307 queue = txq->obj->sq->id;
7308 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
7309 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
7310 queue & queue_m->queue);
7311 mlx5_txq_release(dev, queue_v->queue);
7315 * Set the hash fields according to the @p flow information.
7317 * @param[in] dev_flow
7318 * Pointer to the mlx5_flow.
7321 flow_dv_hashfields_set(struct mlx5_flow *dev_flow)
7323 struct rte_flow *flow = dev_flow->flow;
7324 uint64_t items = dev_flow->handle->layers;
7326 uint64_t rss_types = rte_eth_rss_hf_refine(flow->rss.types);
7328 dev_flow->hash_fields = 0;
7329 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
7330 if (flow->rss.level >= 2) {
7331 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
7335 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
7336 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
7337 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
7338 if (rss_types & ETH_RSS_L3_SRC_ONLY)
7339 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
7340 else if (rss_types & ETH_RSS_L3_DST_ONLY)
7341 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
7343 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
7345 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
7346 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
7347 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
7348 if (rss_types & ETH_RSS_L3_SRC_ONLY)
7349 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
7350 else if (rss_types & ETH_RSS_L3_DST_ONLY)
7351 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
7353 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
7356 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
7357 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
7358 if (rss_types & ETH_RSS_UDP) {
7359 if (rss_types & ETH_RSS_L4_SRC_ONLY)
7360 dev_flow->hash_fields |=
7361 IBV_RX_HASH_SRC_PORT_UDP;
7362 else if (rss_types & ETH_RSS_L4_DST_ONLY)
7363 dev_flow->hash_fields |=
7364 IBV_RX_HASH_DST_PORT_UDP;
7366 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
7368 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
7369 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
7370 if (rss_types & ETH_RSS_TCP) {
7371 if (rss_types & ETH_RSS_L4_SRC_ONLY)
7372 dev_flow->hash_fields |=
7373 IBV_RX_HASH_SRC_PORT_TCP;
7374 else if (rss_types & ETH_RSS_L4_DST_ONLY)
7375 dev_flow->hash_fields |=
7376 IBV_RX_HASH_DST_PORT_TCP;
7378 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
7384 * Fill the flow with DV spec, lock free
7385 * (mutex should be acquired by caller).
7388 * Pointer to rte_eth_dev structure.
7389 * @param[in, out] dev_flow
7390 * Pointer to the sub flow.
7392 * Pointer to the flow attributes.
7394 * Pointer to the list of items.
7395 * @param[in] actions
7396 * Pointer to the list of actions.
7398 * Pointer to the error structure.
7401 * 0 on success, a negative errno value otherwise and rte_errno is set.
7404 __flow_dv_translate(struct rte_eth_dev *dev,
7405 struct mlx5_flow *dev_flow,
7406 const struct rte_flow_attr *attr,
7407 const struct rte_flow_item items[],
7408 const struct rte_flow_action actions[],
7409 struct rte_flow_error *error)
7411 struct mlx5_priv *priv = dev->data->dev_private;
7412 struct mlx5_dev_config *dev_conf = &priv->config;
7413 struct rte_flow *flow = dev_flow->flow;
7414 struct mlx5_flow_handle *handle = dev_flow->handle;
7415 uint64_t item_flags = 0;
7416 uint64_t last_item = 0;
7417 uint64_t action_flags = 0;
7418 uint64_t priority = attr->priority;
7419 struct mlx5_flow_dv_matcher matcher = {
7421 .size = sizeof(matcher.mask.buf),
7425 bool actions_end = false;
7427 struct mlx5_flow_dv_modify_hdr_resource res;
7428 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
7429 sizeof(struct mlx5_modification_cmd) *
7430 (MLX5_MAX_MODIFY_NUM + 1)];
7432 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
7433 union flow_dv_attr flow_attr = { .attr = 0 };
7435 union mlx5_flow_tbl_key tbl_key;
7436 uint32_t modify_action_position = UINT32_MAX;
7437 void *match_mask = matcher.mask.buf;
7438 void *match_value = dev_flow->dv.value.buf;
7439 uint8_t next_protocol = 0xff;
7440 struct rte_vlan_hdr vlan = { 0 };
7444 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
7445 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
7446 ret = mlx5_flow_group_to_table(attr, dev_flow->external, attr->group,
7447 !!priv->fdb_def_rule, &table, error);
7450 dev_flow->dv.group = table;
7452 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
7453 if (priority == MLX5_FLOW_PRIO_RSVD)
7454 priority = dev_conf->flow_prio - 1;
7455 /* number of actions must be set to 0 in case of dirty stack. */
7456 mhdr_res->actions_num = 0;
7457 for (; !actions_end ; actions++) {
7458 const struct rte_flow_action_queue *queue;
7459 const struct rte_flow_action_rss *rss;
7460 const struct rte_flow_action *action = actions;
7461 const struct rte_flow_action_count *count = action->conf;
7462 const uint8_t *rss_key;
7463 const struct rte_flow_action_jump *jump_data;
7464 const struct rte_flow_action_meter *mtr;
7465 struct mlx5_flow_tbl_resource *tbl;
7466 uint32_t port_id = 0;
7467 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
7468 int action_type = actions->type;
7469 const struct rte_flow_action *found_action = NULL;
7471 switch (action_type) {
7472 case RTE_FLOW_ACTION_TYPE_VOID:
7474 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7475 if (flow_dv_translate_action_port_id(dev, action,
7478 port_id_resource.port_id = port_id;
7479 if (flow_dv_port_id_action_resource_register
7480 (dev, &port_id_resource, dev_flow, error))
7482 dev_flow->dv.actions[actions_n++] =
7483 handle->dvh.port_id_action->action;
7484 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7486 case RTE_FLOW_ACTION_TYPE_FLAG:
7487 action_flags |= MLX5_FLOW_ACTION_FLAG;
7488 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7489 struct rte_flow_action_mark mark = {
7490 .id = MLX5_FLOW_MARK_DEFAULT,
7493 if (flow_dv_convert_action_mark(dev, &mark,
7497 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
7500 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
7502 * Only one FLAG or MARK is supported per device flow
7503 * right now. So the pointer to the tag resource must be
7504 * zero before the register process.
7506 MLX5_ASSERT(!handle->dvh.tag_resource);
7507 if (flow_dv_tag_resource_register(dev, tag_be,
7510 dev_flow->dv.actions[actions_n++] =
7511 handle->dvh.tag_resource->action;
7513 case RTE_FLOW_ACTION_TYPE_MARK:
7514 action_flags |= MLX5_FLOW_ACTION_MARK;
7515 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7516 const struct rte_flow_action_mark *mark =
7517 (const struct rte_flow_action_mark *)
7520 if (flow_dv_convert_action_mark(dev, mark,
7524 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
7528 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7529 /* Legacy (non-extensive) MARK action. */
7530 tag_be = mlx5_flow_mark_set
7531 (((const struct rte_flow_action_mark *)
7532 (actions->conf))->id);
7533 MLX5_ASSERT(!handle->dvh.tag_resource);
7534 if (flow_dv_tag_resource_register(dev, tag_be,
7537 dev_flow->dv.actions[actions_n++] =
7538 handle->dvh.tag_resource->action;
7540 case RTE_FLOW_ACTION_TYPE_SET_META:
7541 if (flow_dv_convert_action_set_meta
7542 (dev, mhdr_res, attr,
7543 (const struct rte_flow_action_set_meta *)
7544 actions->conf, error))
7546 action_flags |= MLX5_FLOW_ACTION_SET_META;
7548 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7549 if (flow_dv_convert_action_set_tag
7551 (const struct rte_flow_action_set_tag *)
7552 actions->conf, error))
7554 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7556 case RTE_FLOW_ACTION_TYPE_DROP:
7557 action_flags |= MLX5_FLOW_ACTION_DROP;
7559 case RTE_FLOW_ACTION_TYPE_QUEUE:
7560 MLX5_ASSERT(flow->rss.queue);
7561 queue = actions->conf;
7562 flow->rss.queue_num = 1;
7563 (*flow->rss.queue)[0] = queue->index;
7564 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7566 case RTE_FLOW_ACTION_TYPE_RSS:
7567 MLX5_ASSERT(flow->rss.queue);
7568 rss = actions->conf;
7569 if (flow->rss.queue)
7570 memcpy((*flow->rss.queue), rss->queue,
7571 rss->queue_num * sizeof(uint16_t));
7572 flow->rss.queue_num = rss->queue_num;
7573 /* NULL RSS key indicates default RSS key. */
7574 rss_key = !rss->key ? rss_hash_default_key : rss->key;
7575 memcpy(flow->rss.key, rss_key, MLX5_RSS_HASH_KEY_LEN);
7577 * rss->level and rss.types should be set in advance
7578 * when expanding items for RSS.
7580 action_flags |= MLX5_FLOW_ACTION_RSS;
7582 case RTE_FLOW_ACTION_TYPE_COUNT:
7583 if (!dev_conf->devx) {
7584 rte_errno = ENOTSUP;
7587 flow->counter = flow_dv_counter_alloc(dev,
7590 dev_flow->dv.group);
7591 if (flow->counter == NULL)
7593 dev_flow->dv.actions[actions_n++] =
7594 (flow_dv_counter_get_by_idx(dev,
7595 (uintptr_t)flow->counter, NULL))->action;
7596 action_flags |= MLX5_FLOW_ACTION_COUNT;
7599 if (rte_errno == ENOTSUP)
7600 return rte_flow_error_set
7602 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7604 "count action not supported");
7606 return rte_flow_error_set
7608 RTE_FLOW_ERROR_TYPE_ACTION,
7610 "cannot create counter"
7613 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7614 dev_flow->dv.actions[actions_n++] =
7615 priv->sh->pop_vlan_action;
7616 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7618 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7619 flow_dev_get_vlan_info_from_items(items, &vlan);
7620 vlan.eth_proto = rte_be_to_cpu_16
7621 ((((const struct rte_flow_action_of_push_vlan *)
7622 actions->conf)->ethertype));
7623 found_action = mlx5_flow_find_action
7625 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
7627 mlx5_update_vlan_vid_pcp(found_action, &vlan);
7628 found_action = mlx5_flow_find_action
7630 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
7632 mlx5_update_vlan_vid_pcp(found_action, &vlan);
7633 if (flow_dv_create_action_push_vlan
7634 (dev, attr, &vlan, dev_flow, error))
7636 dev_flow->dv.actions[actions_n++] =
7637 handle->dvh.push_vlan_res->action;
7638 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7640 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7641 /* of_vlan_push action handled this action */
7642 MLX5_ASSERT(action_flags &
7643 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
7645 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7646 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7648 flow_dev_get_vlan_info_from_items(items, &vlan);
7649 mlx5_update_vlan_vid_pcp(actions, &vlan);
7650 /* If no VLAN push - this is a modify header action */
7651 if (flow_dv_convert_action_modify_vlan_vid
7652 (mhdr_res, actions, error))
7654 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7656 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7657 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7658 if (flow_dv_create_action_l2_encap(dev, actions,
7663 dev_flow->dv.actions[actions_n++] =
7664 handle->dvh.encap_decap->verbs_action;
7665 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7667 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7668 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7669 if (flow_dv_create_action_l2_decap(dev, dev_flow,
7673 dev_flow->dv.actions[actions_n++] =
7674 handle->dvh.encap_decap->verbs_action;
7675 action_flags |= MLX5_FLOW_ACTION_DECAP;
7677 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7678 /* Handle encap with preceding decap. */
7679 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
7680 if (flow_dv_create_action_raw_encap
7681 (dev, actions, dev_flow, attr, error))
7683 dev_flow->dv.actions[actions_n++] =
7684 handle->dvh.encap_decap->verbs_action;
7686 /* Handle encap without preceding decap. */
7687 if (flow_dv_create_action_l2_encap
7688 (dev, actions, dev_flow, attr->transfer,
7691 dev_flow->dv.actions[actions_n++] =
7692 handle->dvh.encap_decap->verbs_action;
7694 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7696 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7697 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
7699 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7700 if (flow_dv_create_action_l2_decap
7701 (dev, dev_flow, attr->transfer, error))
7703 dev_flow->dv.actions[actions_n++] =
7704 handle->dvh.encap_decap->verbs_action;
7706 /* If decap is followed by encap, handle it at encap. */
7707 action_flags |= MLX5_FLOW_ACTION_DECAP;
7709 case RTE_FLOW_ACTION_TYPE_JUMP:
7710 jump_data = action->conf;
7711 ret = mlx5_flow_group_to_table(attr, dev_flow->external,
7713 !!priv->fdb_def_rule,
7717 tbl = flow_dv_tbl_resource_get(dev, table,
7719 attr->transfer, error);
7721 return rte_flow_error_set
7723 RTE_FLOW_ERROR_TYPE_ACTION,
7725 "cannot create jump action.");
7726 if (flow_dv_jump_tbl_resource_register
7727 (dev, tbl, dev_flow, error)) {
7728 flow_dv_tbl_resource_release(dev, tbl);
7729 return rte_flow_error_set
7731 RTE_FLOW_ERROR_TYPE_ACTION,
7733 "cannot create jump action.");
7735 dev_flow->dv.actions[actions_n++] =
7736 handle->dvh.jump->action;
7737 action_flags |= MLX5_FLOW_ACTION_JUMP;
7739 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7740 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7741 if (flow_dv_convert_action_modify_mac
7742 (mhdr_res, actions, error))
7744 action_flags |= actions->type ==
7745 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7746 MLX5_FLOW_ACTION_SET_MAC_SRC :
7747 MLX5_FLOW_ACTION_SET_MAC_DST;
7749 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7750 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7751 if (flow_dv_convert_action_modify_ipv4
7752 (mhdr_res, actions, error))
7754 action_flags |= actions->type ==
7755 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7756 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7757 MLX5_FLOW_ACTION_SET_IPV4_DST;
7759 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7760 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7761 if (flow_dv_convert_action_modify_ipv6
7762 (mhdr_res, actions, error))
7764 action_flags |= actions->type ==
7765 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7766 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7767 MLX5_FLOW_ACTION_SET_IPV6_DST;
7769 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7770 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7771 if (flow_dv_convert_action_modify_tp
7772 (mhdr_res, actions, items,
7773 &flow_attr, dev_flow, !!(action_flags &
7774 MLX5_FLOW_ACTION_DECAP), error))
7776 action_flags |= actions->type ==
7777 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7778 MLX5_FLOW_ACTION_SET_TP_SRC :
7779 MLX5_FLOW_ACTION_SET_TP_DST;
7781 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7782 if (flow_dv_convert_action_modify_dec_ttl
7783 (mhdr_res, items, &flow_attr, dev_flow,
7785 MLX5_FLOW_ACTION_DECAP), error))
7787 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
7789 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7790 if (flow_dv_convert_action_modify_ttl
7791 (mhdr_res, actions, items, &flow_attr,
7792 dev_flow, !!(action_flags &
7793 MLX5_FLOW_ACTION_DECAP), error))
7795 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
7797 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7798 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7799 if (flow_dv_convert_action_modify_tcp_seq
7800 (mhdr_res, actions, error))
7802 action_flags |= actions->type ==
7803 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7804 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7805 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7808 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7809 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7810 if (flow_dv_convert_action_modify_tcp_ack
7811 (mhdr_res, actions, error))
7813 action_flags |= actions->type ==
7814 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7815 MLX5_FLOW_ACTION_INC_TCP_ACK :
7816 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7818 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7819 if (flow_dv_convert_action_set_reg
7820 (mhdr_res, actions, error))
7822 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7824 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7825 if (flow_dv_convert_action_copy_mreg
7826 (dev, mhdr_res, actions, error))
7828 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7830 case RTE_FLOW_ACTION_TYPE_METER:
7831 mtr = actions->conf;
7833 flow->meter = mlx5_flow_meter_attach(priv,
7837 return rte_flow_error_set(error,
7839 RTE_FLOW_ERROR_TYPE_ACTION,
7842 "or invalid parameters");
7844 /* Set the meter action. */
7845 dev_flow->dv.actions[actions_n++] =
7846 flow->meter->mfts->meter_action;
7847 action_flags |= MLX5_FLOW_ACTION_METER;
7849 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7850 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
7853 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7855 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7856 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
7859 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7861 case RTE_FLOW_ACTION_TYPE_END:
7863 if (mhdr_res->actions_num) {
7864 /* create modify action if needed. */
7865 if (flow_dv_modify_hdr_resource_register
7866 (dev, mhdr_res, dev_flow, error))
7868 dev_flow->dv.actions[modify_action_position] =
7869 handle->dvh.modify_hdr->verbs_action;
7875 if (mhdr_res->actions_num &&
7876 modify_action_position == UINT32_MAX)
7877 modify_action_position = actions_n++;
7879 dev_flow->dv.actions_n = actions_n;
7880 handle->act_flags = action_flags;
7881 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7882 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7883 int item_type = items->type;
7885 switch (item_type) {
7886 case RTE_FLOW_ITEM_TYPE_PORT_ID:
7887 flow_dv_translate_item_port_id(dev, match_mask,
7888 match_value, items);
7889 last_item = MLX5_FLOW_ITEM_PORT_ID;
7891 case RTE_FLOW_ITEM_TYPE_ETH:
7892 flow_dv_translate_item_eth(match_mask, match_value,
7894 matcher.priority = MLX5_PRIORITY_MAP_L2;
7895 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7896 MLX5_FLOW_LAYER_OUTER_L2;
7898 case RTE_FLOW_ITEM_TYPE_VLAN:
7899 flow_dv_translate_item_vlan(dev_flow,
7900 match_mask, match_value,
7902 matcher.priority = MLX5_PRIORITY_MAP_L2;
7903 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
7904 MLX5_FLOW_LAYER_INNER_VLAN) :
7905 (MLX5_FLOW_LAYER_OUTER_L2 |
7906 MLX5_FLOW_LAYER_OUTER_VLAN);
7908 case RTE_FLOW_ITEM_TYPE_IPV4:
7909 mlx5_flow_tunnel_ip_check(items, next_protocol,
7910 &item_flags, &tunnel);
7911 flow_dv_translate_item_ipv4(match_mask, match_value,
7912 items, item_flags, tunnel,
7913 dev_flow->dv.group);
7914 matcher.priority = MLX5_PRIORITY_MAP_L3;
7915 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7916 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7917 if (items->mask != NULL &&
7918 ((const struct rte_flow_item_ipv4 *)
7919 items->mask)->hdr.next_proto_id) {
7921 ((const struct rte_flow_item_ipv4 *)
7922 (items->spec))->hdr.next_proto_id;
7924 ((const struct rte_flow_item_ipv4 *)
7925 (items->mask))->hdr.next_proto_id;
7927 /* Reset for inner layer. */
7928 next_protocol = 0xff;
7931 case RTE_FLOW_ITEM_TYPE_IPV6:
7932 mlx5_flow_tunnel_ip_check(items, next_protocol,
7933 &item_flags, &tunnel);
7934 flow_dv_translate_item_ipv6(match_mask, match_value,
7935 items, item_flags, tunnel,
7936 dev_flow->dv.group);
7937 matcher.priority = MLX5_PRIORITY_MAP_L3;
7938 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7939 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7940 if (items->mask != NULL &&
7941 ((const struct rte_flow_item_ipv6 *)
7942 items->mask)->hdr.proto) {
7944 ((const struct rte_flow_item_ipv6 *)
7945 items->spec)->hdr.proto;
7947 ((const struct rte_flow_item_ipv6 *)
7948 items->mask)->hdr.proto;
7950 /* Reset for inner layer. */
7951 next_protocol = 0xff;
7954 case RTE_FLOW_ITEM_TYPE_TCP:
7955 flow_dv_translate_item_tcp(match_mask, match_value,
7957 matcher.priority = MLX5_PRIORITY_MAP_L4;
7958 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7959 MLX5_FLOW_LAYER_OUTER_L4_TCP;
7961 case RTE_FLOW_ITEM_TYPE_UDP:
7962 flow_dv_translate_item_udp(match_mask, match_value,
7964 matcher.priority = MLX5_PRIORITY_MAP_L4;
7965 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
7966 MLX5_FLOW_LAYER_OUTER_L4_UDP;
7968 case RTE_FLOW_ITEM_TYPE_GRE:
7969 flow_dv_translate_item_gre(match_mask, match_value,
7971 matcher.priority = flow->rss.level >= 2 ?
7972 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
7973 last_item = MLX5_FLOW_LAYER_GRE;
7975 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7976 flow_dv_translate_item_gre_key(match_mask,
7977 match_value, items);
7978 last_item = MLX5_FLOW_LAYER_GRE_KEY;
7980 case RTE_FLOW_ITEM_TYPE_NVGRE:
7981 flow_dv_translate_item_nvgre(match_mask, match_value,
7983 matcher.priority = flow->rss.level >= 2 ?
7984 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
7985 last_item = MLX5_FLOW_LAYER_GRE;
7987 case RTE_FLOW_ITEM_TYPE_VXLAN:
7988 flow_dv_translate_item_vxlan(match_mask, match_value,
7990 matcher.priority = flow->rss.level >= 2 ?
7991 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
7992 last_item = MLX5_FLOW_LAYER_VXLAN;
7994 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7995 flow_dv_translate_item_vxlan_gpe(match_mask,
7998 matcher.priority = flow->rss.level >= 2 ?
7999 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8000 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
8002 case RTE_FLOW_ITEM_TYPE_GENEVE:
8003 flow_dv_translate_item_geneve(match_mask, match_value,
8005 matcher.priority = flow->rss.level >= 2 ?
8006 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8007 last_item = MLX5_FLOW_LAYER_GENEVE;
8009 case RTE_FLOW_ITEM_TYPE_MPLS:
8010 flow_dv_translate_item_mpls(match_mask, match_value,
8011 items, last_item, tunnel);
8012 matcher.priority = flow->rss.level >= 2 ?
8013 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8014 last_item = MLX5_FLOW_LAYER_MPLS;
8016 case RTE_FLOW_ITEM_TYPE_MARK:
8017 flow_dv_translate_item_mark(dev, match_mask,
8018 match_value, items);
8019 last_item = MLX5_FLOW_ITEM_MARK;
8021 case RTE_FLOW_ITEM_TYPE_META:
8022 flow_dv_translate_item_meta(dev, match_mask,
8023 match_value, attr, items);
8024 last_item = MLX5_FLOW_ITEM_METADATA;
8026 case RTE_FLOW_ITEM_TYPE_ICMP:
8027 flow_dv_translate_item_icmp(match_mask, match_value,
8029 last_item = MLX5_FLOW_LAYER_ICMP;
8031 case RTE_FLOW_ITEM_TYPE_ICMP6:
8032 flow_dv_translate_item_icmp6(match_mask, match_value,
8034 last_item = MLX5_FLOW_LAYER_ICMP6;
8036 case RTE_FLOW_ITEM_TYPE_TAG:
8037 flow_dv_translate_item_tag(dev, match_mask,
8038 match_value, items);
8039 last_item = MLX5_FLOW_ITEM_TAG;
8041 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8042 flow_dv_translate_mlx5_item_tag(dev, match_mask,
8043 match_value, items);
8044 last_item = MLX5_FLOW_ITEM_TAG;
8046 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
8047 flow_dv_translate_item_tx_queue(dev, match_mask,
8050 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
8052 case RTE_FLOW_ITEM_TYPE_GTP:
8053 flow_dv_translate_item_gtp(match_mask, match_value,
8055 matcher.priority = flow->rss.level >= 2 ?
8056 MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4;
8057 last_item = MLX5_FLOW_LAYER_GTP;
8062 item_flags |= last_item;
8065 * When E-Switch mode is enabled, we have two cases where we need to
8066 * set the source port manually.
8067 * The first one, is in case of Nic steering rule, and the second is
8068 * E-Switch rule where no port_id item was found. In both cases
8069 * the source port is set according the current port in use.
8071 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
8072 (priv->representor || priv->master)) {
8073 if (flow_dv_translate_item_port_id(dev, match_mask,
8077 #ifdef RTE_LIBRTE_MLX5_DEBUG
8078 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
8079 dev_flow->dv.value.buf));
8082 * Layers may be already initialized from prefix flow if this dev_flow
8083 * is the suffix flow.
8085 handle->layers |= item_flags;
8086 if (action_flags & MLX5_FLOW_ACTION_RSS)
8087 flow_dv_hashfields_set(dev_flow);
8088 /* Register matcher. */
8089 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
8091 matcher.priority = mlx5_flow_adjust_priority(dev, priority,
8093 /* reserved field no needs to be set to 0 here. */
8094 tbl_key.domain = attr->transfer;
8095 tbl_key.direction = attr->egress;
8096 tbl_key.table_id = dev_flow->dv.group;
8097 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow, error))
8103 * Apply the flow to the NIC, lock free,
8104 * (mutex should be acquired by caller).
8107 * Pointer to the Ethernet device structure.
8108 * @param[in, out] flow
8109 * Pointer to flow structure.
8111 * Pointer to error structure.
8114 * 0 on success, a negative errno value otherwise and rte_errno is set.
8117 __flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
8118 struct rte_flow_error *error)
8120 struct mlx5_flow_dv_workspace *dv;
8121 struct mlx5_flow_handle *dh;
8122 struct mlx5_flow_handle_dv *dv_h;
8123 struct mlx5_flow *dev_flow;
8124 struct mlx5_priv *priv = dev->data->dev_private;
8129 for (idx = priv->flow_idx - 1; idx >= 0; idx--) {
8130 dev_flow = &((struct mlx5_flow *)priv->inter_flows)[idx];
8132 dh = dev_flow->handle;
8135 if (dh->act_flags & MLX5_FLOW_ACTION_DROP) {
8137 dv->actions[n++] = priv->sh->esw_drop_action;
8139 dh->hrxq = mlx5_hrxq_drop_new(dev);
8143 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8145 "cannot get drop hash queue");
8148 dv->actions[n++] = dh->hrxq->action;
8150 } else if (dh->act_flags &
8151 (MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)) {
8152 struct mlx5_hrxq *hrxq;
8154 MLX5_ASSERT(flow->rss.queue);
8155 hrxq = mlx5_hrxq_get(dev, flow->rss.key,
8156 MLX5_RSS_HASH_KEY_LEN,
8157 dev_flow->hash_fields,
8159 flow->rss.queue_num);
8161 hrxq = mlx5_hrxq_new
8162 (dev, flow->rss.key,
8163 MLX5_RSS_HASH_KEY_LEN,
8164 dev_flow->hash_fields,
8166 flow->rss.queue_num,
8168 MLX5_FLOW_LAYER_TUNNEL));
8173 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8174 "cannot get hash queue");
8178 dv->actions[n++] = dh->hrxq->action;
8181 mlx5_glue->dv_create_flow(dv_h->matcher->matcher_object,
8182 (void *)&dv->value, n,
8185 rte_flow_error_set(error, errno,
8186 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8188 "hardware refuses to create flow");
8191 if (priv->vmwa_context &&
8192 dh->vf_vlan.tag && !dh->vf_vlan.created) {
8194 * The rule contains the VLAN pattern.
8195 * For VF we are going to create VLAN
8196 * interface to make hypervisor set correct
8197 * e-Switch vport context.
8199 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
8204 err = rte_errno; /* Save rte_errno before cleanup. */
8205 LIST_FOREACH(dh, &flow->dev_handles, next) {
8207 if (dh->act_flags & MLX5_FLOW_ACTION_DROP)
8208 mlx5_hrxq_drop_release(dev);
8210 mlx5_hrxq_release(dev, dh->hrxq);
8213 if (dh->vf_vlan.tag && dh->vf_vlan.created)
8214 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
8216 rte_errno = err; /* Restore rte_errno. */
8221 * Release the flow matcher.
8224 * Pointer to Ethernet device.
8226 * Pointer to mlx5_flow_handle.
8229 * 1 while a reference on it exists, 0 when freed.
8232 flow_dv_matcher_release(struct rte_eth_dev *dev,
8233 struct mlx5_flow_handle *handle)
8235 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
8237 MLX5_ASSERT(matcher->matcher_object);
8238 DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--",
8239 dev->data->port_id, (void *)matcher,
8240 rte_atomic32_read(&matcher->refcnt));
8241 if (rte_atomic32_dec_and_test(&matcher->refcnt)) {
8242 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8243 (matcher->matcher_object));
8244 LIST_REMOVE(matcher, next);
8245 /* table ref-- in release interface. */
8246 flow_dv_tbl_resource_release(dev, matcher->tbl);
8248 DRV_LOG(DEBUG, "port %u matcher %p: removed",
8249 dev->data->port_id, (void *)matcher);
8256 * Release an encap/decap resource.
8259 * Pointer to mlx5_flow_handle.
8262 * 1 while a reference on it exists, 0 when freed.
8265 flow_dv_encap_decap_resource_release(struct mlx5_flow_handle *handle)
8267 struct mlx5_flow_dv_encap_decap_resource *cache_resource =
8268 handle->dvh.encap_decap;
8270 MLX5_ASSERT(cache_resource->verbs_action);
8271 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d--",
8272 (void *)cache_resource,
8273 rte_atomic32_read(&cache_resource->refcnt));
8274 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8275 claim_zero(mlx5_glue->destroy_flow_action
8276 (cache_resource->verbs_action));
8277 LIST_REMOVE(cache_resource, next);
8278 rte_free(cache_resource);
8279 DRV_LOG(DEBUG, "encap/decap resource %p: removed",
8280 (void *)cache_resource);
8287 * Release an jump to table action resource.
8290 * Pointer to Ethernet device.
8292 * Pointer to mlx5_flow_handle.
8295 * 1 while a reference on it exists, 0 when freed.
8298 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
8299 struct mlx5_flow_handle *handle)
8301 struct mlx5_flow_dv_jump_tbl_resource *cache_resource =
8303 struct mlx5_flow_tbl_data_entry *tbl_data =
8304 container_of(cache_resource,
8305 struct mlx5_flow_tbl_data_entry, jump);
8307 MLX5_ASSERT(cache_resource->action);
8308 DRV_LOG(DEBUG, "jump table resource %p: refcnt %d--",
8309 (void *)cache_resource,
8310 rte_atomic32_read(&cache_resource->refcnt));
8311 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8312 claim_zero(mlx5_glue->destroy_flow_action
8313 (cache_resource->action));
8314 /* jump action memory free is inside the table release. */
8315 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
8316 DRV_LOG(DEBUG, "jump table resource %p: removed",
8317 (void *)cache_resource);
8324 * Release a modify-header resource.
8327 * Pointer to mlx5_flow_handle.
8330 * 1 while a reference on it exists, 0 when freed.
8333 flow_dv_modify_hdr_resource_release(struct mlx5_flow_handle *handle)
8335 struct mlx5_flow_dv_modify_hdr_resource *cache_resource =
8336 handle->dvh.modify_hdr;
8338 MLX5_ASSERT(cache_resource->verbs_action);
8339 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d--",
8340 (void *)cache_resource,
8341 rte_atomic32_read(&cache_resource->refcnt));
8342 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8343 claim_zero(mlx5_glue->destroy_flow_action
8344 (cache_resource->verbs_action));
8345 LIST_REMOVE(cache_resource, next);
8346 rte_free(cache_resource);
8347 DRV_LOG(DEBUG, "modify-header resource %p: removed",
8348 (void *)cache_resource);
8355 * Release port ID action resource.
8358 * Pointer to mlx5_flow_handle.
8361 * 1 while a reference on it exists, 0 when freed.
8364 flow_dv_port_id_action_resource_release(struct mlx5_flow_handle *handle)
8366 struct mlx5_flow_dv_port_id_action_resource *cache_resource =
8367 handle->dvh.port_id_action;
8369 MLX5_ASSERT(cache_resource->action);
8370 DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--",
8371 (void *)cache_resource,
8372 rte_atomic32_read(&cache_resource->refcnt));
8373 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8374 claim_zero(mlx5_glue->destroy_flow_action
8375 (cache_resource->action));
8376 LIST_REMOVE(cache_resource, next);
8377 rte_free(cache_resource);
8378 DRV_LOG(DEBUG, "port id action resource %p: removed",
8379 (void *)cache_resource);
8386 * Release push vlan action resource.
8389 * Pointer to mlx5_flow_handle.
8392 * 1 while a reference on it exists, 0 when freed.
8395 flow_dv_push_vlan_action_resource_release(struct mlx5_flow_handle *handle)
8397 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource =
8398 handle->dvh.push_vlan_res;
8400 MLX5_ASSERT(cache_resource->action);
8401 DRV_LOG(DEBUG, "push VLAN action resource %p: refcnt %d--",
8402 (void *)cache_resource,
8403 rte_atomic32_read(&cache_resource->refcnt));
8404 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
8405 claim_zero(mlx5_glue->destroy_flow_action
8406 (cache_resource->action));
8407 LIST_REMOVE(cache_resource, next);
8408 rte_free(cache_resource);
8409 DRV_LOG(DEBUG, "push vlan action resource %p: removed",
8410 (void *)cache_resource);
8417 * Remove the flow from the NIC but keeps it in memory.
8418 * Lock free, (mutex should be acquired by caller).
8421 * Pointer to Ethernet device.
8422 * @param[in, out] flow
8423 * Pointer to flow structure.
8426 __flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
8428 struct mlx5_flow_handle *dh;
8432 LIST_FOREACH(dh, &flow->dev_handles, next) {
8434 claim_zero(mlx5_glue->dv_destroy_flow(dh->ib_flow));
8438 if (dh->act_flags & MLX5_FLOW_ACTION_DROP)
8439 mlx5_hrxq_drop_release(dev);
8441 mlx5_hrxq_release(dev, dh->hrxq);
8444 if (dh->vf_vlan.tag && dh->vf_vlan.created)
8445 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
8450 * Remove the flow from the NIC and the memory.
8451 * Lock free, (mutex should be acquired by caller).
8454 * Pointer to the Ethernet device structure.
8455 * @param[in, out] flow
8456 * Pointer to flow structure.
8459 __flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
8461 struct mlx5_flow_handle *dev_handle;
8465 __flow_dv_remove(dev, flow);
8466 if (flow->counter) {
8467 flow_dv_counter_release(dev, flow->counter);
8468 flow->counter = NULL;
8471 mlx5_flow_meter_detach(flow->meter);
8474 while (!LIST_EMPTY(&flow->dev_handles)) {
8475 dev_handle = LIST_FIRST(&flow->dev_handles);
8476 LIST_REMOVE(dev_handle, next);
8477 if (dev_handle->dvh.matcher)
8478 flow_dv_matcher_release(dev, dev_handle);
8479 if (dev_handle->dvh.encap_decap)
8480 flow_dv_encap_decap_resource_release(dev_handle);
8481 if (dev_handle->dvh.modify_hdr)
8482 flow_dv_modify_hdr_resource_release(dev_handle);
8483 if (dev_handle->dvh.jump)
8484 flow_dv_jump_tbl_resource_release(dev, dev_handle);
8485 if (dev_handle->dvh.port_id_action)
8486 flow_dv_port_id_action_resource_release(dev_handle);
8487 if (dev_handle->dvh.push_vlan_res)
8488 flow_dv_push_vlan_action_resource_release(dev_handle);
8489 if (dev_handle->dvh.tag_resource)
8490 flow_dv_tag_release(dev,
8491 dev_handle->dvh.tag_resource);
8492 rte_free(dev_handle);
8497 * Query a dv flow rule for its statistics via devx.
8500 * Pointer to Ethernet device.
8502 * Pointer to the sub flow.
8504 * data retrieved by the query.
8506 * Perform verbose error reporting if not NULL.
8509 * 0 on success, a negative errno value otherwise and rte_errno is set.
8512 flow_dv_query_count(struct rte_eth_dev *dev, struct rte_flow *flow,
8513 void *data, struct rte_flow_error *error)
8515 struct mlx5_priv *priv = dev->data->dev_private;
8516 struct rte_flow_query_count *qc = data;
8518 if (!priv->config.devx)
8519 return rte_flow_error_set(error, ENOTSUP,
8520 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8522 "counters are not supported");
8523 if (flow->counter) {
8524 uint64_t pkts, bytes;
8525 struct mlx5_flow_counter *cnt;
8527 cnt = flow_dv_counter_get_by_idx(dev, (uintptr_t)flow->counter,
8529 int err = _flow_dv_query_count(dev, cnt, &pkts,
8533 return rte_flow_error_set(error, -err,
8534 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8535 NULL, "cannot read counters");
8538 qc->hits = pkts - cnt->hits;
8539 qc->bytes = bytes - cnt->bytes;
8546 return rte_flow_error_set(error, EINVAL,
8547 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8549 "counters are not available");
8555 * @see rte_flow_query()
8559 flow_dv_query(struct rte_eth_dev *dev,
8560 struct rte_flow *flow __rte_unused,
8561 const struct rte_flow_action *actions __rte_unused,
8562 void *data __rte_unused,
8563 struct rte_flow_error *error __rte_unused)
8567 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
8568 switch (actions->type) {
8569 case RTE_FLOW_ACTION_TYPE_VOID:
8571 case RTE_FLOW_ACTION_TYPE_COUNT:
8572 ret = flow_dv_query_count(dev, flow, data, error);
8575 return rte_flow_error_set(error, ENOTSUP,
8576 RTE_FLOW_ERROR_TYPE_ACTION,
8578 "action not supported");
8585 * Destroy the meter table set.
8586 * Lock free, (mutex should be acquired by caller).
8589 * Pointer to Ethernet device.
8591 * Pointer to the meter table set.
8597 flow_dv_destroy_mtr_tbl(struct rte_eth_dev *dev,
8598 struct mlx5_meter_domains_infos *tbl)
8600 struct mlx5_priv *priv = dev->data->dev_private;
8601 struct mlx5_meter_domains_infos *mtd =
8602 (struct mlx5_meter_domains_infos *)tbl;
8604 if (!mtd || !priv->config.dv_flow_en)
8606 if (mtd->ingress.policer_rules[RTE_MTR_DROPPED])
8607 claim_zero(mlx5_glue->dv_destroy_flow
8608 (mtd->ingress.policer_rules[RTE_MTR_DROPPED]));
8609 if (mtd->egress.policer_rules[RTE_MTR_DROPPED])
8610 claim_zero(mlx5_glue->dv_destroy_flow
8611 (mtd->egress.policer_rules[RTE_MTR_DROPPED]));
8612 if (mtd->transfer.policer_rules[RTE_MTR_DROPPED])
8613 claim_zero(mlx5_glue->dv_destroy_flow
8614 (mtd->transfer.policer_rules[RTE_MTR_DROPPED]));
8615 if (mtd->egress.color_matcher)
8616 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8617 (mtd->egress.color_matcher));
8618 if (mtd->egress.any_matcher)
8619 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8620 (mtd->egress.any_matcher));
8621 if (mtd->egress.tbl)
8622 claim_zero(flow_dv_tbl_resource_release(dev,
8624 if (mtd->ingress.color_matcher)
8625 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8626 (mtd->ingress.color_matcher));
8627 if (mtd->ingress.any_matcher)
8628 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8629 (mtd->ingress.any_matcher));
8630 if (mtd->ingress.tbl)
8631 claim_zero(flow_dv_tbl_resource_release(dev,
8633 if (mtd->transfer.color_matcher)
8634 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8635 (mtd->transfer.color_matcher));
8636 if (mtd->transfer.any_matcher)
8637 claim_zero(mlx5_glue->dv_destroy_flow_matcher
8638 (mtd->transfer.any_matcher));
8639 if (mtd->transfer.tbl)
8640 claim_zero(flow_dv_tbl_resource_release(dev,
8641 mtd->transfer.tbl));
8643 claim_zero(mlx5_glue->destroy_flow_action(mtd->drop_actn));
8648 /* Number of meter flow actions, count and jump or count and drop. */
8649 #define METER_ACTIONS 2
8652 * Create specify domain meter table and suffix table.
8655 * Pointer to Ethernet device.
8656 * @param[in,out] mtb
8657 * Pointer to DV meter table set.
8660 * @param[in] transfer
8662 * @param[in] color_reg_c_idx
8663 * Reg C index for color match.
8666 * 0 on success, -1 otherwise and rte_errno is set.
8669 flow_dv_prepare_mtr_tables(struct rte_eth_dev *dev,
8670 struct mlx5_meter_domains_infos *mtb,
8671 uint8_t egress, uint8_t transfer,
8672 uint32_t color_reg_c_idx)
8674 struct mlx5_priv *priv = dev->data->dev_private;
8675 struct mlx5_ibv_shared *sh = priv->sh;
8676 struct mlx5_flow_dv_match_params mask = {
8677 .size = sizeof(mask.buf),
8679 struct mlx5_flow_dv_match_params value = {
8680 .size = sizeof(value.buf),
8682 struct mlx5dv_flow_matcher_attr dv_attr = {
8683 .type = IBV_FLOW_ATTR_NORMAL,
8685 .match_criteria_enable = 0,
8686 .match_mask = (void *)&mask,
8688 void *actions[METER_ACTIONS];
8689 struct mlx5_flow_tbl_resource **sfx_tbl;
8690 struct mlx5_meter_domain_info *dtb;
8691 struct rte_flow_error error;
8695 sfx_tbl = &sh->fdb_mtr_sfx_tbl;
8696 dtb = &mtb->transfer;
8697 } else if (egress) {
8698 sfx_tbl = &sh->tx_mtr_sfx_tbl;
8701 sfx_tbl = &sh->rx_mtr_sfx_tbl;
8702 dtb = &mtb->ingress;
8704 /* If the suffix table in missing, create it. */
8706 *sfx_tbl = flow_dv_tbl_resource_get(dev,
8707 MLX5_FLOW_TABLE_LEVEL_SUFFIX,
8708 egress, transfer, &error);
8710 DRV_LOG(ERR, "Failed to create meter suffix table.");
8714 /* Create the meter table with METER level. */
8715 dtb->tbl = flow_dv_tbl_resource_get(dev, MLX5_FLOW_TABLE_LEVEL_METER,
8716 egress, transfer, &error);
8718 DRV_LOG(ERR, "Failed to create meter policer table.");
8721 /* Create matchers, Any and Color. */
8722 dv_attr.priority = 3;
8723 dv_attr.match_criteria_enable = 0;
8724 dtb->any_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
8727 if (!dtb->any_matcher) {
8728 DRV_LOG(ERR, "Failed to create meter"
8729 " policer default matcher.");
8732 dv_attr.priority = 0;
8733 dv_attr.match_criteria_enable =
8734 1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
8735 flow_dv_match_meta_reg(mask.buf, value.buf, color_reg_c_idx,
8736 rte_col_2_mlx5_col(RTE_COLORS), UINT8_MAX);
8737 dtb->color_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
8740 if (!dtb->color_matcher) {
8741 DRV_LOG(ERR, "Failed to create meter policer color matcher.");
8744 if (mtb->count_actns[RTE_MTR_DROPPED])
8745 actions[i++] = mtb->count_actns[RTE_MTR_DROPPED];
8746 actions[i++] = mtb->drop_actn;
8747 /* Default rule: lowest priority, match any, actions: drop. */
8748 dtb->policer_rules[RTE_MTR_DROPPED] =
8749 mlx5_glue->dv_create_flow(dtb->any_matcher,
8750 (void *)&value, i, actions);
8751 if (!dtb->policer_rules[RTE_MTR_DROPPED]) {
8752 DRV_LOG(ERR, "Failed to create meter policer drop rule.");
8761 * Create the needed meter and suffix tables.
8762 * Lock free, (mutex should be acquired by caller).
8765 * Pointer to Ethernet device.
8767 * Pointer to the flow meter.
8770 * Pointer to table set on success, NULL otherwise and rte_errno is set.
8772 static struct mlx5_meter_domains_infos *
8773 flow_dv_create_mtr_tbl(struct rte_eth_dev *dev,
8774 const struct mlx5_flow_meter *fm)
8776 struct mlx5_priv *priv = dev->data->dev_private;
8777 struct mlx5_meter_domains_infos *mtb;
8781 if (!priv->mtr_en) {
8782 rte_errno = ENOTSUP;
8785 mtb = rte_calloc(__func__, 1, sizeof(*mtb), 0);
8787 DRV_LOG(ERR, "Failed to allocate memory for meter.");
8790 /* Create meter count actions */
8791 for (i = 0; i <= RTE_MTR_DROPPED; i++) {
8792 struct mlx5_flow_counter *cnt;
8793 if (!fm->policer_stats.cnt[i])
8795 cnt = flow_dv_counter_get_by_idx(dev,
8796 (uintptr_t)fm->policer_stats.cnt[i], NULL);
8797 mtb->count_actns[i] = cnt->action;
8799 /* Create drop action. */
8800 mtb->drop_actn = mlx5_glue->dr_create_flow_action_drop();
8801 if (!mtb->drop_actn) {
8802 DRV_LOG(ERR, "Failed to create drop action.");
8805 /* Egress meter table. */
8806 ret = flow_dv_prepare_mtr_tables(dev, mtb, 1, 0, priv->mtr_color_reg);
8808 DRV_LOG(ERR, "Failed to prepare egress meter table.");
8811 /* Ingress meter table. */
8812 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 0, priv->mtr_color_reg);
8814 DRV_LOG(ERR, "Failed to prepare ingress meter table.");
8817 /* FDB meter table. */
8818 if (priv->config.dv_esw_en) {
8819 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 1,
8820 priv->mtr_color_reg);
8822 DRV_LOG(ERR, "Failed to prepare fdb meter table.");
8828 flow_dv_destroy_mtr_tbl(dev, mtb);
8833 * Destroy domain policer rule.
8836 * Pointer to domain table.
8839 flow_dv_destroy_domain_policer_rule(struct mlx5_meter_domain_info *dt)
8843 for (i = 0; i < RTE_MTR_DROPPED; i++) {
8844 if (dt->policer_rules[i]) {
8845 claim_zero(mlx5_glue->dv_destroy_flow
8846 (dt->policer_rules[i]));
8847 dt->policer_rules[i] = NULL;
8850 if (dt->jump_actn) {
8851 claim_zero(mlx5_glue->destroy_flow_action(dt->jump_actn));
8852 dt->jump_actn = NULL;
8857 * Destroy policer rules.
8860 * Pointer to Ethernet device.
8862 * Pointer to flow meter structure.
8864 * Pointer to flow attributes.
8870 flow_dv_destroy_policer_rules(struct rte_eth_dev *dev __rte_unused,
8871 const struct mlx5_flow_meter *fm,
8872 const struct rte_flow_attr *attr)
8874 struct mlx5_meter_domains_infos *mtb = fm ? fm->mfts : NULL;
8879 flow_dv_destroy_domain_policer_rule(&mtb->egress);
8881 flow_dv_destroy_domain_policer_rule(&mtb->ingress);
8883 flow_dv_destroy_domain_policer_rule(&mtb->transfer);
8888 * Create specify domain meter policer rule.
8891 * Pointer to flow meter structure.
8893 * Pointer to DV meter table set.
8895 * Pointer to suffix table.
8896 * @param[in] mtr_reg_c
8897 * Color match REG_C.
8900 * 0 on success, -1 otherwise.
8903 flow_dv_create_policer_forward_rule(struct mlx5_flow_meter *fm,
8904 struct mlx5_meter_domain_info *dtb,
8905 struct mlx5_flow_tbl_resource *sfx_tb,
8908 struct mlx5_flow_dv_match_params matcher = {
8909 .size = sizeof(matcher.buf),
8911 struct mlx5_flow_dv_match_params value = {
8912 .size = sizeof(value.buf),
8914 struct mlx5_meter_domains_infos *mtb = fm->mfts;
8915 void *actions[METER_ACTIONS];
8918 /* Create jump action. */
8921 if (!dtb->jump_actn)
8923 mlx5_glue->dr_create_flow_action_dest_flow_tbl
8925 if (!dtb->jump_actn) {
8926 DRV_LOG(ERR, "Failed to create policer jump action.");
8929 for (i = 0; i < RTE_MTR_DROPPED; i++) {
8932 flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
8933 rte_col_2_mlx5_col(i), UINT8_MAX);
8934 if (mtb->count_actns[i])
8935 actions[j++] = mtb->count_actns[i];
8936 if (fm->params.action[i] == MTR_POLICER_ACTION_DROP)
8937 actions[j++] = mtb->drop_actn;
8939 actions[j++] = dtb->jump_actn;
8940 dtb->policer_rules[i] =
8941 mlx5_glue->dv_create_flow(dtb->color_matcher,
8944 if (!dtb->policer_rules[i]) {
8945 DRV_LOG(ERR, "Failed to create policer rule.");
8956 * Create policer rules.
8959 * Pointer to Ethernet device.
8961 * Pointer to flow meter structure.
8963 * Pointer to flow attributes.
8966 * 0 on success, -1 otherwise.
8969 flow_dv_create_policer_rules(struct rte_eth_dev *dev,
8970 struct mlx5_flow_meter *fm,
8971 const struct rte_flow_attr *attr)
8973 struct mlx5_priv *priv = dev->data->dev_private;
8974 struct mlx5_meter_domains_infos *mtb = fm->mfts;
8978 ret = flow_dv_create_policer_forward_rule(fm, &mtb->egress,
8979 priv->sh->tx_mtr_sfx_tbl,
8980 priv->mtr_color_reg);
8982 DRV_LOG(ERR, "Failed to create egress policer.");
8986 if (attr->ingress) {
8987 ret = flow_dv_create_policer_forward_rule(fm, &mtb->ingress,
8988 priv->sh->rx_mtr_sfx_tbl,
8989 priv->mtr_color_reg);
8991 DRV_LOG(ERR, "Failed to create ingress policer.");
8995 if (attr->transfer) {
8996 ret = flow_dv_create_policer_forward_rule(fm, &mtb->transfer,
8997 priv->sh->fdb_mtr_sfx_tbl,
8998 priv->mtr_color_reg);
9000 DRV_LOG(ERR, "Failed to create transfer policer.");
9006 flow_dv_destroy_policer_rules(dev, fm, attr);
9011 * Query a devx counter.
9014 * Pointer to the Ethernet device structure.
9016 * Pointer to the flow counter.
9018 * Set to clear the counter statistics.
9020 * The statistics value of packets.
9022 * The statistics value of bytes.
9025 * 0 on success, otherwise return -1.
9028 flow_dv_counter_query(struct rte_eth_dev *dev,
9029 struct mlx5_flow_counter *counter, bool clear,
9030 uint64_t *pkts, uint64_t *bytes)
9032 struct mlx5_priv *priv = dev->data->dev_private;
9033 struct mlx5_flow_counter *cnt;
9034 uint64_t inn_pkts, inn_bytes;
9037 if (!priv->config.devx)
9040 cnt = flow_dv_counter_get_by_idx(dev, (uintptr_t)counter, NULL);
9041 ret = _flow_dv_query_count(dev, cnt, &inn_pkts, &inn_bytes);
9044 *pkts = inn_pkts - cnt->hits;
9045 *bytes = inn_bytes - cnt->bytes;
9047 cnt->hits = inn_pkts;
9048 cnt->bytes = inn_bytes;
9054 * Mutex-protected thunk to lock-free __flow_dv_translate().
9057 flow_dv_translate(struct rte_eth_dev *dev,
9058 struct mlx5_flow *dev_flow,
9059 const struct rte_flow_attr *attr,
9060 const struct rte_flow_item items[],
9061 const struct rte_flow_action actions[],
9062 struct rte_flow_error *error)
9066 flow_dv_shared_lock(dev);
9067 ret = __flow_dv_translate(dev, dev_flow, attr, items, actions, error);
9068 flow_dv_shared_unlock(dev);
9073 * Mutex-protected thunk to lock-free __flow_dv_apply().
9076 flow_dv_apply(struct rte_eth_dev *dev,
9077 struct rte_flow *flow,
9078 struct rte_flow_error *error)
9082 flow_dv_shared_lock(dev);
9083 ret = __flow_dv_apply(dev, flow, error);
9084 flow_dv_shared_unlock(dev);
9089 * Mutex-protected thunk to lock-free __flow_dv_remove().
9092 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
9094 flow_dv_shared_lock(dev);
9095 __flow_dv_remove(dev, flow);
9096 flow_dv_shared_unlock(dev);
9100 * Mutex-protected thunk to lock-free __flow_dv_destroy().
9103 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
9105 flow_dv_shared_lock(dev);
9106 __flow_dv_destroy(dev, flow);
9107 flow_dv_shared_unlock(dev);
9111 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
9113 static struct mlx5_flow_counter *
9114 flow_dv_counter_allocate(struct rte_eth_dev *dev)
9116 struct mlx5_flow_counter *cnt;
9118 flow_dv_shared_lock(dev);
9119 cnt = flow_dv_counter_alloc(dev, 0, 0, 1);
9120 flow_dv_shared_unlock(dev);
9125 * Mutex-protected thunk to lock-free flow_dv_counter_release().
9128 flow_dv_counter_free(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt)
9130 flow_dv_shared_lock(dev);
9131 flow_dv_counter_release(dev, cnt);
9132 flow_dv_shared_unlock(dev);
9135 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
9136 .validate = flow_dv_validate,
9137 .prepare = flow_dv_prepare,
9138 .translate = flow_dv_translate,
9139 .apply = flow_dv_apply,
9140 .remove = flow_dv_remove,
9141 .destroy = flow_dv_destroy,
9142 .query = flow_dv_query,
9143 .create_mtr_tbls = flow_dv_create_mtr_tbl,
9144 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbl,
9145 .create_policer_rules = flow_dv_create_policer_rules,
9146 .destroy_policer_rules = flow_dv_destroy_policer_rules,
9147 .counter_alloc = flow_dv_counter_allocate,
9148 .counter_free = flow_dv_counter_free,
9149 .counter_query = flow_dv_counter_query,
9152 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */