1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Mellanox Technologies, Ltd
11 #include <rte_common.h>
12 #include <rte_ether.h>
13 #include <rte_ethdev_driver.h>
15 #include <rte_flow_driver.h>
16 #include <rte_malloc.h>
17 #include <rte_cycles.h>
20 #include <rte_vxlan.h>
22 #include <rte_eal_paging.h>
25 #include <mlx5_glue.h>
26 #include <mlx5_devx_cmds.h>
28 #include <mlx5_malloc.h>
30 #include "mlx5_defs.h"
32 #include "mlx5_common_os.h"
33 #include "mlx5_flow.h"
34 #include "mlx5_flow_os.h"
35 #include "mlx5_rxtx.h"
37 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
39 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
40 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
43 #ifndef HAVE_MLX5DV_DR_ESWITCH
44 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
45 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
49 #ifndef HAVE_MLX5DV_DR
50 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
53 /* VLAN header definitions */
54 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
55 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
56 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
57 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
58 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
73 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
74 struct mlx5_flow_tbl_resource *tbl);
77 flow_dv_default_miss_resource_release(struct rte_eth_dev *dev);
80 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
81 uint32_t encap_decap_idx);
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_dev_ctx_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_dev_ctx_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_NON] = 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_NON);
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_NON);
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[] = {
1164 return rte_flow_error_set(error, EINVAL,
1165 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1166 NULL, "zero mark action mask");
1167 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1170 MLX5_ASSERT(reg > 0);
1171 if (reg == REG_C_0) {
1172 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1173 uint32_t shl_c0 = rte_bsf32(msk_c0);
1175 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1176 mask = rte_cpu_to_be_32(mask) & msk_c0;
1177 mask = rte_cpu_to_be_32(mask << shl_c0);
1179 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1180 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1181 MLX5_MODIFICATION_TYPE_SET, error);
1185 * Get metadata register index for specified steering domain.
1188 * Pointer to the rte_eth_dev structure.
1190 * Attributes of flow to determine steering domain.
1192 * Pointer to the error structure.
1195 * positive index on success, a negative errno value otherwise
1196 * and rte_errno is set.
1198 static enum modify_reg
1199 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1200 const struct rte_flow_attr *attr,
1201 struct rte_flow_error *error)
1204 mlx5_flow_get_reg_id(dev, attr->transfer ?
1208 MLX5_METADATA_RX, 0, error);
1210 return rte_flow_error_set(error,
1211 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1212 NULL, "unavailable "
1213 "metadata register");
1218 * Convert SET_META action to DV specification.
1221 * Pointer to the rte_eth_dev structure.
1222 * @param[in,out] resource
1223 * Pointer to the modify-header resource.
1225 * Attributes of flow that includes this item.
1227 * Pointer to action specification.
1229 * Pointer to the error structure.
1232 * 0 on success, a negative errno value otherwise and rte_errno is set.
1235 flow_dv_convert_action_set_meta
1236 (struct rte_eth_dev *dev,
1237 struct mlx5_flow_dv_modify_hdr_resource *resource,
1238 const struct rte_flow_attr *attr,
1239 const struct rte_flow_action_set_meta *conf,
1240 struct rte_flow_error *error)
1242 uint32_t data = conf->data;
1243 uint32_t mask = conf->mask;
1244 struct rte_flow_item item = {
1248 struct field_modify_info reg_c_x[] = {
1251 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1256 * In datapath code there is no endianness
1257 * coversions for perfromance reasons, all
1258 * pattern conversions are done in rte_flow.
1260 if (reg == REG_C_0) {
1261 struct mlx5_priv *priv = dev->data->dev_private;
1262 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1265 MLX5_ASSERT(msk_c0);
1266 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1267 shl_c0 = rte_bsf32(msk_c0);
1269 shl_c0 = sizeof(msk_c0) * CHAR_BIT - rte_fls_u32(msk_c0);
1273 MLX5_ASSERT(!(~msk_c0 & rte_cpu_to_be_32(mask)));
1275 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1276 /* The routine expects parameters in memory as big-endian ones. */
1277 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1278 MLX5_MODIFICATION_TYPE_SET, error);
1282 * Convert modify-header set IPv4 DSCP action to DV specification.
1284 * @param[in,out] resource
1285 * Pointer to the modify-header resource.
1287 * Pointer to action specification.
1289 * Pointer to the error structure.
1292 * 0 on success, a negative errno value otherwise and rte_errno is set.
1295 flow_dv_convert_action_modify_ipv4_dscp
1296 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1297 const struct rte_flow_action *action,
1298 struct rte_flow_error *error)
1300 const struct rte_flow_action_set_dscp *conf =
1301 (const struct rte_flow_action_set_dscp *)(action->conf);
1302 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1303 struct rte_flow_item_ipv4 ipv4;
1304 struct rte_flow_item_ipv4 ipv4_mask;
1306 memset(&ipv4, 0, sizeof(ipv4));
1307 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1308 ipv4.hdr.type_of_service = conf->dscp;
1309 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1311 item.mask = &ipv4_mask;
1312 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1313 MLX5_MODIFICATION_TYPE_SET, error);
1317 * Convert modify-header set IPv6 DSCP action to DV specification.
1319 * @param[in,out] resource
1320 * Pointer to the modify-header resource.
1322 * Pointer to action specification.
1324 * Pointer to the error structure.
1327 * 0 on success, a negative errno value otherwise and rte_errno is set.
1330 flow_dv_convert_action_modify_ipv6_dscp
1331 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1332 const struct rte_flow_action *action,
1333 struct rte_flow_error *error)
1335 const struct rte_flow_action_set_dscp *conf =
1336 (const struct rte_flow_action_set_dscp *)(action->conf);
1337 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1338 struct rte_flow_item_ipv6 ipv6;
1339 struct rte_flow_item_ipv6 ipv6_mask;
1341 memset(&ipv6, 0, sizeof(ipv6));
1342 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1344 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1345 * rdma-core only accept the DSCP bits byte aligned start from
1346 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1347 * bits in IPv6 case as rdma-core requires byte aligned value.
1349 ipv6.hdr.vtc_flow = conf->dscp;
1350 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1352 item.mask = &ipv6_mask;
1353 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1354 MLX5_MODIFICATION_TYPE_SET, error);
1358 * Validate MARK item.
1361 * Pointer to the rte_eth_dev structure.
1363 * Item specification.
1365 * Attributes of flow that includes this item.
1367 * Pointer to error structure.
1370 * 0 on success, a negative errno value otherwise and rte_errno is set.
1373 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1374 const struct rte_flow_item *item,
1375 const struct rte_flow_attr *attr __rte_unused,
1376 struct rte_flow_error *error)
1378 struct mlx5_priv *priv = dev->data->dev_private;
1379 struct mlx5_dev_config *config = &priv->config;
1380 const struct rte_flow_item_mark *spec = item->spec;
1381 const struct rte_flow_item_mark *mask = item->mask;
1382 const struct rte_flow_item_mark nic_mask = {
1383 .id = priv->sh->dv_mark_mask,
1387 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1388 return rte_flow_error_set(error, ENOTSUP,
1389 RTE_FLOW_ERROR_TYPE_ITEM, item,
1390 "extended metadata feature"
1392 if (!mlx5_flow_ext_mreg_supported(dev))
1393 return rte_flow_error_set(error, ENOTSUP,
1394 RTE_FLOW_ERROR_TYPE_ITEM, item,
1395 "extended metadata register"
1396 " isn't supported");
1398 return rte_flow_error_set(error, ENOTSUP,
1399 RTE_FLOW_ERROR_TYPE_ITEM, item,
1400 "extended metadata register"
1401 " isn't available");
1402 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1406 return rte_flow_error_set(error, EINVAL,
1407 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1409 "data cannot be empty");
1410 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1411 return rte_flow_error_set(error, EINVAL,
1412 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1414 "mark id exceeds the limit");
1418 return rte_flow_error_set(error, EINVAL,
1419 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1420 "mask cannot be zero");
1422 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1423 (const uint8_t *)&nic_mask,
1424 sizeof(struct rte_flow_item_mark),
1432 * Validate META item.
1435 * Pointer to the rte_eth_dev structure.
1437 * Item specification.
1439 * Attributes of flow that includes this item.
1441 * Pointer to error structure.
1444 * 0 on success, a negative errno value otherwise and rte_errno is set.
1447 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1448 const struct rte_flow_item *item,
1449 const struct rte_flow_attr *attr,
1450 struct rte_flow_error *error)
1452 struct mlx5_priv *priv = dev->data->dev_private;
1453 struct mlx5_dev_config *config = &priv->config;
1454 const struct rte_flow_item_meta *spec = item->spec;
1455 const struct rte_flow_item_meta *mask = item->mask;
1456 struct rte_flow_item_meta nic_mask = {
1463 return rte_flow_error_set(error, EINVAL,
1464 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1466 "data cannot be empty");
1467 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1468 if (!mlx5_flow_ext_mreg_supported(dev))
1469 return rte_flow_error_set(error, ENOTSUP,
1470 RTE_FLOW_ERROR_TYPE_ITEM, item,
1471 "extended metadata register"
1472 " isn't supported");
1473 reg = flow_dv_get_metadata_reg(dev, attr, error);
1477 return rte_flow_error_set(error, ENOTSUP,
1478 RTE_FLOW_ERROR_TYPE_ITEM, item,
1482 nic_mask.data = priv->sh->dv_meta_mask;
1483 } else if (attr->transfer) {
1484 return rte_flow_error_set(error, ENOTSUP,
1485 RTE_FLOW_ERROR_TYPE_ITEM, item,
1486 "extended metadata feature "
1487 "should be enabled when "
1488 "meta item is requested "
1489 "with e-switch mode ");
1492 mask = &rte_flow_item_meta_mask;
1494 return rte_flow_error_set(error, EINVAL,
1495 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1496 "mask cannot be zero");
1498 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1499 (const uint8_t *)&nic_mask,
1500 sizeof(struct rte_flow_item_meta),
1506 * Validate TAG item.
1509 * Pointer to the rte_eth_dev structure.
1511 * Item specification.
1513 * Attributes of flow that includes this item.
1515 * Pointer to error structure.
1518 * 0 on success, a negative errno value otherwise and rte_errno is set.
1521 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
1522 const struct rte_flow_item *item,
1523 const struct rte_flow_attr *attr __rte_unused,
1524 struct rte_flow_error *error)
1526 const struct rte_flow_item_tag *spec = item->spec;
1527 const struct rte_flow_item_tag *mask = item->mask;
1528 const struct rte_flow_item_tag nic_mask = {
1529 .data = RTE_BE32(UINT32_MAX),
1534 if (!mlx5_flow_ext_mreg_supported(dev))
1535 return rte_flow_error_set(error, ENOTSUP,
1536 RTE_FLOW_ERROR_TYPE_ITEM, item,
1537 "extensive metadata register"
1538 " isn't supported");
1540 return rte_flow_error_set(error, EINVAL,
1541 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1543 "data cannot be empty");
1545 mask = &rte_flow_item_tag_mask;
1547 return rte_flow_error_set(error, EINVAL,
1548 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1549 "mask cannot be zero");
1551 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1552 (const uint8_t *)&nic_mask,
1553 sizeof(struct rte_flow_item_tag),
1557 if (mask->index != 0xff)
1558 return rte_flow_error_set(error, EINVAL,
1559 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1560 "partial mask for tag index"
1561 " is not supported");
1562 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
1565 MLX5_ASSERT(ret != REG_NON);
1570 * Validate vport item.
1573 * Pointer to the rte_eth_dev structure.
1575 * Item specification.
1577 * Attributes of flow that includes this item.
1578 * @param[in] item_flags
1579 * Bit-fields that holds the items detected until now.
1581 * Pointer to error structure.
1584 * 0 on success, a negative errno value otherwise and rte_errno is set.
1587 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
1588 const struct rte_flow_item *item,
1589 const struct rte_flow_attr *attr,
1590 uint64_t item_flags,
1591 struct rte_flow_error *error)
1593 const struct rte_flow_item_port_id *spec = item->spec;
1594 const struct rte_flow_item_port_id *mask = item->mask;
1595 const struct rte_flow_item_port_id switch_mask = {
1598 struct mlx5_priv *esw_priv;
1599 struct mlx5_priv *dev_priv;
1602 if (!attr->transfer)
1603 return rte_flow_error_set(error, EINVAL,
1604 RTE_FLOW_ERROR_TYPE_ITEM,
1606 "match on port id is valid only"
1607 " when transfer flag is enabled");
1608 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
1609 return rte_flow_error_set(error, ENOTSUP,
1610 RTE_FLOW_ERROR_TYPE_ITEM, item,
1611 "multiple source ports are not"
1614 mask = &switch_mask;
1615 if (mask->id != 0xffffffff)
1616 return rte_flow_error_set(error, ENOTSUP,
1617 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
1619 "no support for partial mask on"
1621 ret = mlx5_flow_item_acceptable
1622 (item, (const uint8_t *)mask,
1623 (const uint8_t *)&rte_flow_item_port_id_mask,
1624 sizeof(struct rte_flow_item_port_id),
1630 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
1632 return rte_flow_error_set(error, rte_errno,
1633 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1634 "failed to obtain E-Switch info for"
1636 dev_priv = mlx5_dev_to_eswitch_info(dev);
1638 return rte_flow_error_set(error, rte_errno,
1639 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1641 "failed to obtain E-Switch info");
1642 if (esw_priv->domain_id != dev_priv->domain_id)
1643 return rte_flow_error_set(error, EINVAL,
1644 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1645 "cannot match on a port from a"
1646 " different E-Switch");
1651 * Validate VLAN item.
1654 * Item specification.
1655 * @param[in] item_flags
1656 * Bit-fields that holds the items detected until now.
1658 * Ethernet device flow is being created on.
1660 * Pointer to error structure.
1663 * 0 on success, a negative errno value otherwise and rte_errno is set.
1666 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
1667 uint64_t item_flags,
1668 struct rte_eth_dev *dev,
1669 struct rte_flow_error *error)
1671 const struct rte_flow_item_vlan *mask = item->mask;
1672 const struct rte_flow_item_vlan nic_mask = {
1673 .tci = RTE_BE16(UINT16_MAX),
1674 .inner_type = RTE_BE16(UINT16_MAX),
1676 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1678 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1679 MLX5_FLOW_LAYER_INNER_L4) :
1680 (MLX5_FLOW_LAYER_OUTER_L3 |
1681 MLX5_FLOW_LAYER_OUTER_L4);
1682 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1683 MLX5_FLOW_LAYER_OUTER_VLAN;
1685 if (item_flags & vlanm)
1686 return rte_flow_error_set(error, EINVAL,
1687 RTE_FLOW_ERROR_TYPE_ITEM, item,
1688 "multiple VLAN layers not supported");
1689 else if ((item_flags & l34m) != 0)
1690 return rte_flow_error_set(error, EINVAL,
1691 RTE_FLOW_ERROR_TYPE_ITEM, item,
1692 "VLAN cannot follow L3/L4 layer");
1694 mask = &rte_flow_item_vlan_mask;
1695 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1696 (const uint8_t *)&nic_mask,
1697 sizeof(struct rte_flow_item_vlan),
1701 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1702 struct mlx5_priv *priv = dev->data->dev_private;
1704 if (priv->vmwa_context) {
1706 * Non-NULL context means we have a virtual machine
1707 * and SR-IOV enabled, we have to create VLAN interface
1708 * to make hypervisor to setup E-Switch vport
1709 * context correctly. We avoid creating the multiple
1710 * VLAN interfaces, so we cannot support VLAN tag mask.
1712 return rte_flow_error_set(error, EINVAL,
1713 RTE_FLOW_ERROR_TYPE_ITEM,
1715 "VLAN tag mask is not"
1716 " supported in virtual"
1724 * GTP flags are contained in 1 byte of the format:
1725 * -------------------------------------------
1726 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
1727 * |-----------------------------------------|
1728 * | value | Version | PT | Res | E | S | PN |
1729 * -------------------------------------------
1731 * Matching is supported only for GTP flags E, S, PN.
1733 #define MLX5_GTP_FLAGS_MASK 0x07
1736 * Validate GTP item.
1739 * Pointer to the rte_eth_dev structure.
1741 * Item specification.
1742 * @param[in] item_flags
1743 * Bit-fields that holds the items detected until now.
1745 * Pointer to error structure.
1748 * 0 on success, a negative errno value otherwise and rte_errno is set.
1751 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
1752 const struct rte_flow_item *item,
1753 uint64_t item_flags,
1754 struct rte_flow_error *error)
1756 struct mlx5_priv *priv = dev->data->dev_private;
1757 const struct rte_flow_item_gtp *spec = item->spec;
1758 const struct rte_flow_item_gtp *mask = item->mask;
1759 const struct rte_flow_item_gtp nic_mask = {
1760 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
1762 .teid = RTE_BE32(0xffffffff),
1765 if (!priv->config.hca_attr.tunnel_stateless_gtp)
1766 return rte_flow_error_set(error, ENOTSUP,
1767 RTE_FLOW_ERROR_TYPE_ITEM, item,
1768 "GTP support is not enabled");
1769 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1770 return rte_flow_error_set(error, ENOTSUP,
1771 RTE_FLOW_ERROR_TYPE_ITEM, item,
1772 "multiple tunnel layers not"
1774 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1775 return rte_flow_error_set(error, EINVAL,
1776 RTE_FLOW_ERROR_TYPE_ITEM, item,
1777 "no outer UDP layer found");
1779 mask = &rte_flow_item_gtp_mask;
1780 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
1781 return rte_flow_error_set(error, ENOTSUP,
1782 RTE_FLOW_ERROR_TYPE_ITEM, item,
1783 "Match is supported for GTP"
1785 return mlx5_flow_item_acceptable
1786 (item, (const uint8_t *)mask,
1787 (const uint8_t *)&nic_mask,
1788 sizeof(struct rte_flow_item_gtp),
1793 * Validate the pop VLAN action.
1796 * Pointer to the rte_eth_dev structure.
1797 * @param[in] action_flags
1798 * Holds the actions detected until now.
1800 * Pointer to the pop vlan action.
1801 * @param[in] item_flags
1802 * The items found in this flow rule.
1804 * Pointer to flow attributes.
1806 * Pointer to error structure.
1809 * 0 on success, a negative errno value otherwise and rte_errno is set.
1812 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
1813 uint64_t action_flags,
1814 const struct rte_flow_action *action,
1815 uint64_t item_flags,
1816 const struct rte_flow_attr *attr,
1817 struct rte_flow_error *error)
1819 const struct mlx5_priv *priv = dev->data->dev_private;
1823 if (!priv->sh->pop_vlan_action)
1824 return rte_flow_error_set(error, ENOTSUP,
1825 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1827 "pop vlan action is not supported");
1829 return rte_flow_error_set(error, ENOTSUP,
1830 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1832 "pop vlan action not supported for "
1834 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
1835 return rte_flow_error_set(error, ENOTSUP,
1836 RTE_FLOW_ERROR_TYPE_ACTION, action,
1837 "no support for multiple VLAN "
1839 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
1840 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
1841 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
1842 return rte_flow_error_set(error, ENOTSUP,
1843 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1845 "cannot pop vlan after decap without "
1846 "match on inner vlan in the flow");
1847 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
1848 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
1849 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
1850 return rte_flow_error_set(error, ENOTSUP,
1851 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1853 "cannot pop vlan without a "
1854 "match on (outer) vlan in the flow");
1855 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1856 return rte_flow_error_set(error, EINVAL,
1857 RTE_FLOW_ERROR_TYPE_ACTION, action,
1858 "wrong action order, port_id should "
1859 "be after pop VLAN action");
1860 if (!attr->transfer && priv->representor)
1861 return rte_flow_error_set(error, ENOTSUP,
1862 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1863 "pop vlan action for VF representor "
1864 "not supported on NIC table");
1869 * Get VLAN default info from vlan match info.
1872 * the list of item specifications.
1874 * pointer VLAN info to fill to.
1877 * 0 on success, a negative errno value otherwise and rte_errno is set.
1880 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
1881 struct rte_vlan_hdr *vlan)
1883 const struct rte_flow_item_vlan nic_mask = {
1884 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
1885 MLX5DV_FLOW_VLAN_VID_MASK),
1886 .inner_type = RTE_BE16(0xffff),
1891 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
1892 int type = items->type;
1894 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
1895 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
1898 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
1899 const struct rte_flow_item_vlan *vlan_m = items->mask;
1900 const struct rte_flow_item_vlan *vlan_v = items->spec;
1902 /* If VLAN item in pattern doesn't contain data, return here. */
1907 /* Only full match values are accepted */
1908 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
1909 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
1910 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
1912 rte_be_to_cpu_16(vlan_v->tci &
1913 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
1915 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
1916 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
1917 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
1919 rte_be_to_cpu_16(vlan_v->tci &
1920 MLX5DV_FLOW_VLAN_VID_MASK_BE);
1922 if (vlan_m->inner_type == nic_mask.inner_type)
1923 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
1924 vlan_m->inner_type);
1929 * Validate the push VLAN action.
1932 * Pointer to the rte_eth_dev structure.
1933 * @param[in] action_flags
1934 * Holds the actions detected until now.
1935 * @param[in] item_flags
1936 * The items found in this flow rule.
1938 * Pointer to the action structure.
1940 * Pointer to flow attributes
1942 * Pointer to error structure.
1945 * 0 on success, a negative errno value otherwise and rte_errno is set.
1948 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
1949 uint64_t action_flags,
1950 const struct rte_flow_item_vlan *vlan_m,
1951 const struct rte_flow_action *action,
1952 const struct rte_flow_attr *attr,
1953 struct rte_flow_error *error)
1955 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
1956 const struct mlx5_priv *priv = dev->data->dev_private;
1958 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
1959 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
1960 return rte_flow_error_set(error, EINVAL,
1961 RTE_FLOW_ERROR_TYPE_ACTION, action,
1962 "invalid vlan ethertype");
1963 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
1964 return rte_flow_error_set(error, EINVAL,
1965 RTE_FLOW_ERROR_TYPE_ACTION, action,
1966 "wrong action order, port_id should "
1967 "be after push VLAN");
1968 if (!attr->transfer && priv->representor)
1969 return rte_flow_error_set(error, ENOTSUP,
1970 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1971 "push vlan action for VF representor "
1972 "not supported on NIC table");
1974 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
1975 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
1976 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
1977 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
1978 !(mlx5_flow_find_action
1979 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
1980 return rte_flow_error_set(error, EINVAL,
1981 RTE_FLOW_ERROR_TYPE_ACTION, action,
1982 "not full match mask on VLAN PCP and "
1983 "there is no of_set_vlan_pcp action, "
1984 "push VLAN action cannot figure out "
1987 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
1988 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
1989 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
1990 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
1991 !(mlx5_flow_find_action
1992 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
1993 return rte_flow_error_set(error, EINVAL,
1994 RTE_FLOW_ERROR_TYPE_ACTION, action,
1995 "not full match mask on VLAN VID and "
1996 "there is no of_set_vlan_vid action, "
1997 "push VLAN action cannot figure out "
2004 * Validate the set VLAN PCP.
2006 * @param[in] action_flags
2007 * Holds the actions detected until now.
2008 * @param[in] actions
2009 * Pointer to the list of actions remaining in the flow rule.
2011 * Pointer to error structure.
2014 * 0 on success, a negative errno value otherwise and rte_errno is set.
2017 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2018 const struct rte_flow_action actions[],
2019 struct rte_flow_error *error)
2021 const struct rte_flow_action *action = actions;
2022 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2024 if (conf->vlan_pcp > 7)
2025 return rte_flow_error_set(error, EINVAL,
2026 RTE_FLOW_ERROR_TYPE_ACTION, action,
2027 "VLAN PCP value is too big");
2028 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2029 return rte_flow_error_set(error, ENOTSUP,
2030 RTE_FLOW_ERROR_TYPE_ACTION, action,
2031 "set VLAN PCP action must follow "
2032 "the push VLAN action");
2033 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2034 return rte_flow_error_set(error, ENOTSUP,
2035 RTE_FLOW_ERROR_TYPE_ACTION, action,
2036 "Multiple VLAN PCP modification are "
2038 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2039 return rte_flow_error_set(error, EINVAL,
2040 RTE_FLOW_ERROR_TYPE_ACTION, action,
2041 "wrong action order, port_id should "
2042 "be after set VLAN PCP");
2047 * Validate the set VLAN VID.
2049 * @param[in] item_flags
2050 * Holds the items detected in this rule.
2051 * @param[in] action_flags
2052 * Holds the actions detected until now.
2053 * @param[in] actions
2054 * Pointer to the list of actions remaining in the flow rule.
2056 * Pointer to error structure.
2059 * 0 on success, a negative errno value otherwise and rte_errno is set.
2062 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2063 uint64_t action_flags,
2064 const struct rte_flow_action actions[],
2065 struct rte_flow_error *error)
2067 const struct rte_flow_action *action = actions;
2068 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
2070 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
2071 return rte_flow_error_set(error, EINVAL,
2072 RTE_FLOW_ERROR_TYPE_ACTION, action,
2073 "VLAN VID value is too big");
2074 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
2075 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2076 return rte_flow_error_set(error, ENOTSUP,
2077 RTE_FLOW_ERROR_TYPE_ACTION, action,
2078 "set VLAN VID action must follow push"
2079 " VLAN action or match on VLAN item");
2080 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
2081 return rte_flow_error_set(error, ENOTSUP,
2082 RTE_FLOW_ERROR_TYPE_ACTION, action,
2083 "Multiple VLAN VID modifications are "
2085 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2086 return rte_flow_error_set(error, EINVAL,
2087 RTE_FLOW_ERROR_TYPE_ACTION, action,
2088 "wrong action order, port_id should "
2089 "be after set VLAN VID");
2094 * Validate the FLAG action.
2097 * Pointer to the rte_eth_dev structure.
2098 * @param[in] action_flags
2099 * Holds the actions detected until now.
2101 * Pointer to flow attributes
2103 * Pointer to error structure.
2106 * 0 on success, a negative errno value otherwise and rte_errno is set.
2109 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
2110 uint64_t action_flags,
2111 const struct rte_flow_attr *attr,
2112 struct rte_flow_error *error)
2114 struct mlx5_priv *priv = dev->data->dev_private;
2115 struct mlx5_dev_config *config = &priv->config;
2118 /* Fall back if no extended metadata register support. */
2119 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2120 return mlx5_flow_validate_action_flag(action_flags, attr,
2122 /* Extensive metadata mode requires registers. */
2123 if (!mlx5_flow_ext_mreg_supported(dev))
2124 return rte_flow_error_set(error, ENOTSUP,
2125 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2126 "no metadata registers "
2127 "to support flag action");
2128 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
2129 return rte_flow_error_set(error, ENOTSUP,
2130 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2131 "extended metadata register"
2132 " isn't available");
2133 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2136 MLX5_ASSERT(ret > 0);
2137 if (action_flags & MLX5_FLOW_ACTION_MARK)
2138 return rte_flow_error_set(error, EINVAL,
2139 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2140 "can't mark and flag in same flow");
2141 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2142 return rte_flow_error_set(error, EINVAL,
2143 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2145 " actions in same flow");
2150 * Validate MARK action.
2153 * Pointer to the rte_eth_dev structure.
2155 * Pointer to action.
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_mark(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 struct mlx5_priv *priv = dev->data->dev_private;
2174 struct mlx5_dev_config *config = &priv->config;
2175 const struct rte_flow_action_mark *mark = action->conf;
2178 /* Fall back if no extended metadata register support. */
2179 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2180 return mlx5_flow_validate_action_mark(action, action_flags,
2182 /* Extensive metadata mode requires registers. */
2183 if (!mlx5_flow_ext_mreg_supported(dev))
2184 return rte_flow_error_set(error, ENOTSUP,
2185 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2186 "no metadata registers "
2187 "to support mark action");
2188 if (!priv->sh->dv_mark_mask)
2189 return rte_flow_error_set(error, ENOTSUP,
2190 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2191 "extended metadata register"
2192 " isn't available");
2193 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2196 MLX5_ASSERT(ret > 0);
2198 return rte_flow_error_set(error, EINVAL,
2199 RTE_FLOW_ERROR_TYPE_ACTION, action,
2200 "configuration cannot be null");
2201 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
2202 return rte_flow_error_set(error, EINVAL,
2203 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2205 "mark id exceeds the limit");
2206 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2207 return rte_flow_error_set(error, EINVAL,
2208 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2209 "can't flag and mark in same flow");
2210 if (action_flags & MLX5_FLOW_ACTION_MARK)
2211 return rte_flow_error_set(error, EINVAL,
2212 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2213 "can't have 2 mark actions in same"
2219 * Validate SET_META action.
2222 * Pointer to the rte_eth_dev structure.
2224 * Pointer to the action structure.
2225 * @param[in] action_flags
2226 * Holds the actions detected until now.
2228 * Pointer to flow attributes
2230 * Pointer to error structure.
2233 * 0 on success, a negative errno value otherwise and rte_errno is set.
2236 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
2237 const struct rte_flow_action *action,
2238 uint64_t action_flags __rte_unused,
2239 const struct rte_flow_attr *attr,
2240 struct rte_flow_error *error)
2242 const struct rte_flow_action_set_meta *conf;
2243 uint32_t nic_mask = UINT32_MAX;
2246 if (!mlx5_flow_ext_mreg_supported(dev))
2247 return rte_flow_error_set(error, ENOTSUP,
2248 RTE_FLOW_ERROR_TYPE_ACTION, action,
2249 "extended metadata register"
2250 " isn't supported");
2251 reg = flow_dv_get_metadata_reg(dev, attr, error);
2254 if (reg != REG_A && reg != REG_B) {
2255 struct mlx5_priv *priv = dev->data->dev_private;
2257 nic_mask = priv->sh->dv_meta_mask;
2259 if (!(action->conf))
2260 return rte_flow_error_set(error, EINVAL,
2261 RTE_FLOW_ERROR_TYPE_ACTION, action,
2262 "configuration cannot be null");
2263 conf = (const struct rte_flow_action_set_meta *)action->conf;
2265 return rte_flow_error_set(error, EINVAL,
2266 RTE_FLOW_ERROR_TYPE_ACTION, action,
2267 "zero mask doesn't have any effect");
2268 if (conf->mask & ~nic_mask)
2269 return rte_flow_error_set(error, EINVAL,
2270 RTE_FLOW_ERROR_TYPE_ACTION, action,
2271 "meta data must be within reg C0");
2276 * Validate SET_TAG action.
2279 * Pointer to the rte_eth_dev structure.
2281 * Pointer to the action structure.
2282 * @param[in] action_flags
2283 * Holds the actions detected until now.
2285 * Pointer to flow attributes
2287 * Pointer to error structure.
2290 * 0 on success, a negative errno value otherwise and rte_errno is set.
2293 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
2294 const struct rte_flow_action *action,
2295 uint64_t action_flags,
2296 const struct rte_flow_attr *attr,
2297 struct rte_flow_error *error)
2299 const struct rte_flow_action_set_tag *conf;
2300 const uint64_t terminal_action_flags =
2301 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
2302 MLX5_FLOW_ACTION_RSS;
2305 if (!mlx5_flow_ext_mreg_supported(dev))
2306 return rte_flow_error_set(error, ENOTSUP,
2307 RTE_FLOW_ERROR_TYPE_ACTION, action,
2308 "extensive metadata register"
2309 " isn't supported");
2310 if (!(action->conf))
2311 return rte_flow_error_set(error, EINVAL,
2312 RTE_FLOW_ERROR_TYPE_ACTION, action,
2313 "configuration cannot be null");
2314 conf = (const struct rte_flow_action_set_tag *)action->conf;
2316 return rte_flow_error_set(error, EINVAL,
2317 RTE_FLOW_ERROR_TYPE_ACTION, action,
2318 "zero mask doesn't have any effect");
2319 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
2322 if (!attr->transfer && attr->ingress &&
2323 (action_flags & terminal_action_flags))
2324 return rte_flow_error_set(error, EINVAL,
2325 RTE_FLOW_ERROR_TYPE_ACTION, action,
2326 "set_tag has no effect"
2327 " with terminal actions");
2332 * Validate count action.
2335 * Pointer to rte_eth_dev structure.
2337 * Pointer to error structure.
2340 * 0 on success, a negative errno value otherwise and rte_errno is set.
2343 flow_dv_validate_action_count(struct rte_eth_dev *dev,
2344 struct rte_flow_error *error)
2346 struct mlx5_priv *priv = dev->data->dev_private;
2348 if (!priv->config.devx)
2350 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
2354 return rte_flow_error_set
2356 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2358 "count action not supported");
2362 * Validate the L2 encap action.
2365 * Pointer to the rte_eth_dev structure.
2366 * @param[in] action_flags
2367 * Holds the actions detected until now.
2369 * Pointer to the action structure.
2371 * Pointer to flow attributes.
2373 * Pointer to error structure.
2376 * 0 on success, a negative errno value otherwise and rte_errno is set.
2379 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
2380 uint64_t action_flags,
2381 const struct rte_flow_action *action,
2382 const struct rte_flow_attr *attr,
2383 struct rte_flow_error *error)
2385 const struct mlx5_priv *priv = dev->data->dev_private;
2387 if (!(action->conf))
2388 return rte_flow_error_set(error, EINVAL,
2389 RTE_FLOW_ERROR_TYPE_ACTION, action,
2390 "configuration cannot be null");
2391 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
2392 return rte_flow_error_set(error, EINVAL,
2393 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2394 "can only have a single encap action "
2396 if (!attr->transfer && priv->representor)
2397 return rte_flow_error_set(error, ENOTSUP,
2398 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2399 "encap action for VF representor "
2400 "not supported on NIC table");
2405 * Validate a decap action.
2408 * Pointer to the rte_eth_dev structure.
2409 * @param[in] action_flags
2410 * Holds the actions detected until now.
2412 * Pointer to flow attributes
2414 * Pointer to error structure.
2417 * 0 on success, a negative errno value otherwise and rte_errno is set.
2420 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
2421 uint64_t action_flags,
2422 const struct rte_flow_attr *attr,
2423 struct rte_flow_error *error)
2425 const struct mlx5_priv *priv = dev->data->dev_private;
2427 if (priv->config.hca_attr.scatter_fcs_w_decap_disable &&
2428 !priv->config.decap_en)
2429 return rte_flow_error_set(error, ENOTSUP,
2430 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2431 "decap is not enabled");
2432 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
2433 return rte_flow_error_set(error, ENOTSUP,
2434 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2436 MLX5_FLOW_ACTION_DECAP ? "can only "
2437 "have a single decap action" : "decap "
2438 "after encap is not supported");
2439 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
2440 return rte_flow_error_set(error, EINVAL,
2441 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2442 "can't have decap action after"
2445 return rte_flow_error_set(error, ENOTSUP,
2446 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2448 "decap action not supported for "
2450 if (!attr->transfer && priv->representor)
2451 return rte_flow_error_set(error, ENOTSUP,
2452 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2453 "decap action for VF representor "
2454 "not supported on NIC table");
2458 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
2461 * Validate the raw encap and decap actions.
2464 * Pointer to the rte_eth_dev structure.
2466 * Pointer to the decap action.
2468 * Pointer to the encap action.
2470 * Pointer to flow attributes
2471 * @param[in/out] action_flags
2472 * Holds the actions detected until now.
2473 * @param[out] actions_n
2474 * pointer to the number of actions counter.
2476 * Pointer to error structure.
2479 * 0 on success, a negative errno value otherwise and rte_errno is set.
2482 flow_dv_validate_action_raw_encap_decap
2483 (struct rte_eth_dev *dev,
2484 const struct rte_flow_action_raw_decap *decap,
2485 const struct rte_flow_action_raw_encap *encap,
2486 const struct rte_flow_attr *attr, uint64_t *action_flags,
2487 int *actions_n, struct rte_flow_error *error)
2489 const struct mlx5_priv *priv = dev->data->dev_private;
2492 if (encap && (!encap->size || !encap->data))
2493 return rte_flow_error_set(error, EINVAL,
2494 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2495 "raw encap data cannot be empty");
2496 if (decap && encap) {
2497 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
2498 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
2501 else if (encap->size <=
2502 MLX5_ENCAPSULATION_DECISION_SIZE &&
2504 MLX5_ENCAPSULATION_DECISION_SIZE)
2507 else if (encap->size >
2508 MLX5_ENCAPSULATION_DECISION_SIZE &&
2510 MLX5_ENCAPSULATION_DECISION_SIZE)
2511 /* 2 L2 actions: encap and decap. */
2514 return rte_flow_error_set(error,
2516 RTE_FLOW_ERROR_TYPE_ACTION,
2517 NULL, "unsupported too small "
2518 "raw decap and too small raw "
2519 "encap combination");
2522 ret = flow_dv_validate_action_decap(dev, *action_flags, attr,
2526 *action_flags |= MLX5_FLOW_ACTION_DECAP;
2530 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
2531 return rte_flow_error_set(error, ENOTSUP,
2532 RTE_FLOW_ERROR_TYPE_ACTION,
2534 "small raw encap size");
2535 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
2536 return rte_flow_error_set(error, EINVAL,
2537 RTE_FLOW_ERROR_TYPE_ACTION,
2539 "more than one encap action");
2540 if (!attr->transfer && priv->representor)
2541 return rte_flow_error_set
2543 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2544 "encap action for VF representor "
2545 "not supported on NIC table");
2546 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
2553 * Match encap_decap resource.
2556 * Pointer to exist resource entry object.
2558 * Pointer to new encap_decap resource.
2561 * 0 on matching, -1 otherwise.
2564 flow_dv_encap_decap_resource_match(struct mlx5_hlist_entry *entry, void *ctx)
2566 struct mlx5_flow_dv_encap_decap_resource *resource;
2567 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
2569 resource = (struct mlx5_flow_dv_encap_decap_resource *)ctx;
2570 cache_resource = container_of(entry,
2571 struct mlx5_flow_dv_encap_decap_resource,
2573 if (resource->entry.key == cache_resource->entry.key &&
2574 resource->reformat_type == cache_resource->reformat_type &&
2575 resource->ft_type == cache_resource->ft_type &&
2576 resource->flags == cache_resource->flags &&
2577 resource->size == cache_resource->size &&
2578 !memcmp((const void *)resource->buf,
2579 (const void *)cache_resource->buf,
2586 * Find existing encap/decap resource or create and register a new one.
2588 * @param[in, out] dev
2589 * Pointer to rte_eth_dev structure.
2590 * @param[in, out] resource
2591 * Pointer to encap/decap resource.
2592 * @parm[in, out] dev_flow
2593 * Pointer to the dev_flow.
2595 * pointer to error structure.
2598 * 0 on success otherwise -errno and errno is set.
2601 flow_dv_encap_decap_resource_register
2602 (struct rte_eth_dev *dev,
2603 struct mlx5_flow_dv_encap_decap_resource *resource,
2604 struct mlx5_flow *dev_flow,
2605 struct rte_flow_error *error)
2607 struct mlx5_priv *priv = dev->data->dev_private;
2608 struct mlx5_dev_ctx_shared *sh = priv->sh;
2609 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
2610 struct mlx5dv_dr_domain *domain;
2611 struct mlx5_hlist_entry *entry;
2612 union mlx5_flow_encap_decap_key encap_decap_key = {
2614 .ft_type = resource->ft_type,
2615 .refmt_type = resource->reformat_type,
2616 .buf_size = resource->size,
2617 .table_level = !!dev_flow->dv.group,
2623 resource->flags = dev_flow->dv.group ? 0 : 1;
2624 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2625 domain = sh->fdb_domain;
2626 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2627 domain = sh->rx_domain;
2629 domain = sh->tx_domain;
2630 encap_decap_key.cksum = __rte_raw_cksum(resource->buf,
2632 resource->entry.key = encap_decap_key.v64;
2633 /* Lookup a matching resource from cache. */
2634 entry = mlx5_hlist_lookup_ex(sh->encaps_decaps, resource->entry.key,
2635 flow_dv_encap_decap_resource_match,
2638 cache_resource = container_of(entry,
2639 struct mlx5_flow_dv_encap_decap_resource, entry);
2640 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d++",
2641 (void *)cache_resource,
2642 rte_atomic32_read(&cache_resource->refcnt));
2643 rte_atomic32_inc(&cache_resource->refcnt);
2644 dev_flow->handle->dvh.rix_encap_decap = cache_resource->idx;
2645 dev_flow->dv.encap_decap = cache_resource;
2648 /* Register new encap/decap resource. */
2649 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
2650 &dev_flow->handle->dvh.rix_encap_decap);
2651 if (!cache_resource)
2652 return rte_flow_error_set(error, ENOMEM,
2653 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2654 "cannot allocate resource memory");
2655 *cache_resource = *resource;
2656 cache_resource->idx = dev_flow->handle->dvh.rix_encap_decap;
2657 ret = mlx5_flow_os_create_flow_action_packet_reformat
2658 (sh->ctx, domain, cache_resource,
2659 &cache_resource->action);
2661 mlx5_free(cache_resource);
2662 return rte_flow_error_set(error, ENOMEM,
2663 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2664 NULL, "cannot create action");
2666 rte_atomic32_init(&cache_resource->refcnt);
2667 rte_atomic32_inc(&cache_resource->refcnt);
2668 if (mlx5_hlist_insert_ex(sh->encaps_decaps, &cache_resource->entry,
2669 flow_dv_encap_decap_resource_match,
2670 (void *)cache_resource)) {
2671 claim_zero(mlx5_flow_os_destroy_flow_action
2672 (cache_resource->action));
2673 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
2674 cache_resource->idx);
2675 return rte_flow_error_set(error, EEXIST,
2676 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2677 NULL, "action exist");
2679 dev_flow->dv.encap_decap = cache_resource;
2680 DRV_LOG(DEBUG, "new encap/decap resource %p: refcnt %d++",
2681 (void *)cache_resource,
2682 rte_atomic32_read(&cache_resource->refcnt));
2687 * Find existing table jump resource or create and register a new one.
2689 * @param[in, out] dev
2690 * Pointer to rte_eth_dev structure.
2691 * @param[in, out] tbl
2692 * Pointer to flow table resource.
2693 * @parm[in, out] dev_flow
2694 * Pointer to the dev_flow.
2696 * pointer to error structure.
2699 * 0 on success otherwise -errno and errno is set.
2702 flow_dv_jump_tbl_resource_register
2703 (struct rte_eth_dev *dev __rte_unused,
2704 struct mlx5_flow_tbl_resource *tbl,
2705 struct mlx5_flow *dev_flow,
2706 struct rte_flow_error *error)
2708 struct mlx5_flow_tbl_data_entry *tbl_data =
2709 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
2713 cnt = rte_atomic32_read(&tbl_data->jump.refcnt);
2715 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
2716 (tbl->obj, &tbl_data->jump.action);
2718 return rte_flow_error_set(error, ENOMEM,
2719 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2720 NULL, "cannot create jump action");
2721 DRV_LOG(DEBUG, "new jump table resource %p: refcnt %d++",
2722 (void *)&tbl_data->jump, cnt);
2724 /* old jump should not make the table ref++. */
2725 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
2726 MLX5_ASSERT(tbl_data->jump.action);
2727 DRV_LOG(DEBUG, "existed jump table resource %p: refcnt %d++",
2728 (void *)&tbl_data->jump, cnt);
2730 rte_atomic32_inc(&tbl_data->jump.refcnt);
2731 dev_flow->handle->rix_jump = tbl_data->idx;
2732 dev_flow->dv.jump = &tbl_data->jump;
2737 * Find existing default miss resource or create and register a new one.
2739 * @param[in, out] dev
2740 * Pointer to rte_eth_dev structure.
2742 * pointer to error structure.
2745 * 0 on success otherwise -errno and errno is set.
2748 flow_dv_default_miss_resource_register(struct rte_eth_dev *dev,
2749 struct rte_flow_error *error)
2751 struct mlx5_priv *priv = dev->data->dev_private;
2752 struct mlx5_dev_ctx_shared *sh = priv->sh;
2753 struct mlx5_flow_default_miss_resource *cache_resource =
2755 int cnt = rte_atomic32_read(&cache_resource->refcnt);
2758 MLX5_ASSERT(cache_resource->action);
2759 cache_resource->action =
2760 mlx5_glue->dr_create_flow_action_default_miss();
2761 if (!cache_resource->action)
2762 return rte_flow_error_set(error, ENOMEM,
2763 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2764 "cannot create default miss action");
2765 DRV_LOG(DEBUG, "new default miss resource %p: refcnt %d++",
2766 (void *)cache_resource->action, cnt);
2768 rte_atomic32_inc(&cache_resource->refcnt);
2773 * Find existing table port ID resource or create and register a new one.
2775 * @param[in, out] dev
2776 * Pointer to rte_eth_dev structure.
2777 * @param[in, out] resource
2778 * Pointer to port ID action resource.
2779 * @parm[in, out] dev_flow
2780 * Pointer to the dev_flow.
2782 * pointer to error structure.
2785 * 0 on success otherwise -errno and errno is set.
2788 flow_dv_port_id_action_resource_register
2789 (struct rte_eth_dev *dev,
2790 struct mlx5_flow_dv_port_id_action_resource *resource,
2791 struct mlx5_flow *dev_flow,
2792 struct rte_flow_error *error)
2794 struct mlx5_priv *priv = dev->data->dev_private;
2795 struct mlx5_dev_ctx_shared *sh = priv->sh;
2796 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
2800 /* Lookup a matching resource from cache. */
2801 ILIST_FOREACH(sh->ipool[MLX5_IPOOL_PORT_ID], sh->port_id_action_list,
2802 idx, cache_resource, next) {
2803 if (resource->port_id == cache_resource->port_id) {
2804 DRV_LOG(DEBUG, "port id action resource resource %p: "
2806 (void *)cache_resource,
2807 rte_atomic32_read(&cache_resource->refcnt));
2808 rte_atomic32_inc(&cache_resource->refcnt);
2809 dev_flow->handle->rix_port_id_action = idx;
2810 dev_flow->dv.port_id_action = cache_resource;
2814 /* Register new port id action resource. */
2815 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID],
2816 &dev_flow->handle->rix_port_id_action);
2817 if (!cache_resource)
2818 return rte_flow_error_set(error, ENOMEM,
2819 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2820 "cannot allocate resource memory");
2821 *cache_resource = *resource;
2822 ret = mlx5_flow_os_create_flow_action_dest_port
2823 (priv->sh->fdb_domain, resource->port_id,
2824 &cache_resource->action);
2826 mlx5_free(cache_resource);
2827 return rte_flow_error_set(error, ENOMEM,
2828 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2829 NULL, "cannot create action");
2831 rte_atomic32_init(&cache_resource->refcnt);
2832 rte_atomic32_inc(&cache_resource->refcnt);
2833 ILIST_INSERT(sh->ipool[MLX5_IPOOL_PORT_ID], &sh->port_id_action_list,
2834 dev_flow->handle->rix_port_id_action, cache_resource,
2836 dev_flow->dv.port_id_action = cache_resource;
2837 DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++",
2838 (void *)cache_resource,
2839 rte_atomic32_read(&cache_resource->refcnt));
2844 * Find existing push vlan resource or create and register a new one.
2846 * @param [in, out] dev
2847 * Pointer to rte_eth_dev structure.
2848 * @param[in, out] resource
2849 * Pointer to port ID action resource.
2850 * @parm[in, out] dev_flow
2851 * Pointer to the dev_flow.
2853 * pointer to error structure.
2856 * 0 on success otherwise -errno and errno is set.
2859 flow_dv_push_vlan_action_resource_register
2860 (struct rte_eth_dev *dev,
2861 struct mlx5_flow_dv_push_vlan_action_resource *resource,
2862 struct mlx5_flow *dev_flow,
2863 struct rte_flow_error *error)
2865 struct mlx5_priv *priv = dev->data->dev_private;
2866 struct mlx5_dev_ctx_shared *sh = priv->sh;
2867 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
2868 struct mlx5dv_dr_domain *domain;
2872 /* Lookup a matching resource from cache. */
2873 ILIST_FOREACH(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2874 sh->push_vlan_action_list, idx, cache_resource, next) {
2875 if (resource->vlan_tag == cache_resource->vlan_tag &&
2876 resource->ft_type == cache_resource->ft_type) {
2877 DRV_LOG(DEBUG, "push-VLAN action resource resource %p: "
2879 (void *)cache_resource,
2880 rte_atomic32_read(&cache_resource->refcnt));
2881 rte_atomic32_inc(&cache_resource->refcnt);
2882 dev_flow->handle->dvh.rix_push_vlan = idx;
2883 dev_flow->dv.push_vlan_res = cache_resource;
2887 /* Register new push_vlan action resource. */
2888 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2889 &dev_flow->handle->dvh.rix_push_vlan);
2890 if (!cache_resource)
2891 return rte_flow_error_set(error, ENOMEM,
2892 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2893 "cannot allocate resource memory");
2894 *cache_resource = *resource;
2895 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2896 domain = sh->fdb_domain;
2897 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2898 domain = sh->rx_domain;
2900 domain = sh->tx_domain;
2901 ret = mlx5_flow_os_create_flow_action_push_vlan
2902 (domain, resource->vlan_tag,
2903 &cache_resource->action);
2905 mlx5_free(cache_resource);
2906 return rte_flow_error_set(error, ENOMEM,
2907 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2908 NULL, "cannot create action");
2910 rte_atomic32_init(&cache_resource->refcnt);
2911 rte_atomic32_inc(&cache_resource->refcnt);
2912 ILIST_INSERT(sh->ipool[MLX5_IPOOL_PUSH_VLAN],
2913 &sh->push_vlan_action_list,
2914 dev_flow->handle->dvh.rix_push_vlan,
2915 cache_resource, next);
2916 dev_flow->dv.push_vlan_res = cache_resource;
2917 DRV_LOG(DEBUG, "new push vlan action resource %p: refcnt %d++",
2918 (void *)cache_resource,
2919 rte_atomic32_read(&cache_resource->refcnt));
2923 * Get the size of specific rte_flow_item_type hdr size
2925 * @param[in] item_type
2926 * Tested rte_flow_item_type.
2929 * sizeof struct item_type, 0 if void or irrelevant.
2932 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
2936 switch (item_type) {
2937 case RTE_FLOW_ITEM_TYPE_ETH:
2938 retval = sizeof(struct rte_ether_hdr);
2940 case RTE_FLOW_ITEM_TYPE_VLAN:
2941 retval = sizeof(struct rte_vlan_hdr);
2943 case RTE_FLOW_ITEM_TYPE_IPV4:
2944 retval = sizeof(struct rte_ipv4_hdr);
2946 case RTE_FLOW_ITEM_TYPE_IPV6:
2947 retval = sizeof(struct rte_ipv6_hdr);
2949 case RTE_FLOW_ITEM_TYPE_UDP:
2950 retval = sizeof(struct rte_udp_hdr);
2952 case RTE_FLOW_ITEM_TYPE_TCP:
2953 retval = sizeof(struct rte_tcp_hdr);
2955 case RTE_FLOW_ITEM_TYPE_VXLAN:
2956 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
2957 retval = sizeof(struct rte_vxlan_hdr);
2959 case RTE_FLOW_ITEM_TYPE_GRE:
2960 case RTE_FLOW_ITEM_TYPE_NVGRE:
2961 retval = sizeof(struct rte_gre_hdr);
2963 case RTE_FLOW_ITEM_TYPE_MPLS:
2964 retval = sizeof(struct rte_mpls_hdr);
2966 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
2974 #define MLX5_ENCAP_IPV4_VERSION 0x40
2975 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
2976 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
2977 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
2978 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
2979 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
2980 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
2983 * Convert the encap action data from list of rte_flow_item to raw buffer
2986 * Pointer to rte_flow_item objects list.
2988 * Pointer to the output buffer.
2990 * Pointer to the output buffer size.
2992 * Pointer to the error structure.
2995 * 0 on success, a negative errno value otherwise and rte_errno is set.
2998 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
2999 size_t *size, struct rte_flow_error *error)
3001 struct rte_ether_hdr *eth = NULL;
3002 struct rte_vlan_hdr *vlan = NULL;
3003 struct rte_ipv4_hdr *ipv4 = NULL;
3004 struct rte_ipv6_hdr *ipv6 = NULL;
3005 struct rte_udp_hdr *udp = NULL;
3006 struct rte_vxlan_hdr *vxlan = NULL;
3007 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
3008 struct rte_gre_hdr *gre = NULL;
3010 size_t temp_size = 0;
3013 return rte_flow_error_set(error, EINVAL,
3014 RTE_FLOW_ERROR_TYPE_ACTION,
3015 NULL, "invalid empty data");
3016 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3017 len = flow_dv_get_item_hdr_len(items->type);
3018 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
3019 return rte_flow_error_set(error, EINVAL,
3020 RTE_FLOW_ERROR_TYPE_ACTION,
3021 (void *)items->type,
3022 "items total size is too big"
3023 " for encap action");
3024 rte_memcpy((void *)&buf[temp_size], items->spec, len);
3025 switch (items->type) {
3026 case RTE_FLOW_ITEM_TYPE_ETH:
3027 eth = (struct rte_ether_hdr *)&buf[temp_size];
3029 case RTE_FLOW_ITEM_TYPE_VLAN:
3030 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
3032 return rte_flow_error_set(error, EINVAL,
3033 RTE_FLOW_ERROR_TYPE_ACTION,
3034 (void *)items->type,
3035 "eth header not found");
3036 if (!eth->ether_type)
3037 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
3039 case RTE_FLOW_ITEM_TYPE_IPV4:
3040 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
3042 return rte_flow_error_set(error, EINVAL,
3043 RTE_FLOW_ERROR_TYPE_ACTION,
3044 (void *)items->type,
3045 "neither eth nor vlan"
3047 if (vlan && !vlan->eth_proto)
3048 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3049 else if (eth && !eth->ether_type)
3050 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3051 if (!ipv4->version_ihl)
3052 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
3053 MLX5_ENCAP_IPV4_IHL_MIN;
3054 if (!ipv4->time_to_live)
3055 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
3057 case RTE_FLOW_ITEM_TYPE_IPV6:
3058 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
3060 return rte_flow_error_set(error, EINVAL,
3061 RTE_FLOW_ERROR_TYPE_ACTION,
3062 (void *)items->type,
3063 "neither eth nor vlan"
3065 if (vlan && !vlan->eth_proto)
3066 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3067 else if (eth && !eth->ether_type)
3068 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3069 if (!ipv6->vtc_flow)
3071 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
3072 if (!ipv6->hop_limits)
3073 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
3075 case RTE_FLOW_ITEM_TYPE_UDP:
3076 udp = (struct rte_udp_hdr *)&buf[temp_size];
3078 return rte_flow_error_set(error, EINVAL,
3079 RTE_FLOW_ERROR_TYPE_ACTION,
3080 (void *)items->type,
3081 "ip header not found");
3082 if (ipv4 && !ipv4->next_proto_id)
3083 ipv4->next_proto_id = IPPROTO_UDP;
3084 else if (ipv6 && !ipv6->proto)
3085 ipv6->proto = IPPROTO_UDP;
3087 case RTE_FLOW_ITEM_TYPE_VXLAN:
3088 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
3090 return rte_flow_error_set(error, EINVAL,
3091 RTE_FLOW_ERROR_TYPE_ACTION,
3092 (void *)items->type,
3093 "udp header not found");
3095 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
3096 if (!vxlan->vx_flags)
3098 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
3100 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
3101 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
3103 return rte_flow_error_set(error, EINVAL,
3104 RTE_FLOW_ERROR_TYPE_ACTION,
3105 (void *)items->type,
3106 "udp header not found");
3107 if (!vxlan_gpe->proto)
3108 return rte_flow_error_set(error, EINVAL,
3109 RTE_FLOW_ERROR_TYPE_ACTION,
3110 (void *)items->type,
3111 "next protocol not found");
3114 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
3115 if (!vxlan_gpe->vx_flags)
3116 vxlan_gpe->vx_flags =
3117 MLX5_ENCAP_VXLAN_GPE_FLAGS;
3119 case RTE_FLOW_ITEM_TYPE_GRE:
3120 case RTE_FLOW_ITEM_TYPE_NVGRE:
3121 gre = (struct rte_gre_hdr *)&buf[temp_size];
3123 return rte_flow_error_set(error, EINVAL,
3124 RTE_FLOW_ERROR_TYPE_ACTION,
3125 (void *)items->type,
3126 "next protocol not found");
3128 return rte_flow_error_set(error, EINVAL,
3129 RTE_FLOW_ERROR_TYPE_ACTION,
3130 (void *)items->type,
3131 "ip header not found");
3132 if (ipv4 && !ipv4->next_proto_id)
3133 ipv4->next_proto_id = IPPROTO_GRE;
3134 else if (ipv6 && !ipv6->proto)
3135 ipv6->proto = IPPROTO_GRE;
3137 case RTE_FLOW_ITEM_TYPE_VOID:
3140 return rte_flow_error_set(error, EINVAL,
3141 RTE_FLOW_ERROR_TYPE_ACTION,
3142 (void *)items->type,
3143 "unsupported item type");
3153 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
3155 struct rte_ether_hdr *eth = NULL;
3156 struct rte_vlan_hdr *vlan = NULL;
3157 struct rte_ipv6_hdr *ipv6 = NULL;
3158 struct rte_udp_hdr *udp = NULL;
3162 eth = (struct rte_ether_hdr *)data;
3163 next_hdr = (char *)(eth + 1);
3164 proto = RTE_BE16(eth->ether_type);
3167 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
3168 vlan = (struct rte_vlan_hdr *)next_hdr;
3169 proto = RTE_BE16(vlan->eth_proto);
3170 next_hdr += sizeof(struct rte_vlan_hdr);
3173 /* HW calculates IPv4 csum. no need to proceed */
3174 if (proto == RTE_ETHER_TYPE_IPV4)
3177 /* non IPv4/IPv6 header. not supported */
3178 if (proto != RTE_ETHER_TYPE_IPV6) {
3179 return rte_flow_error_set(error, ENOTSUP,
3180 RTE_FLOW_ERROR_TYPE_ACTION,
3181 NULL, "Cannot offload non IPv4/IPv6");
3184 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
3186 /* ignore non UDP */
3187 if (ipv6->proto != IPPROTO_UDP)
3190 udp = (struct rte_udp_hdr *)(ipv6 + 1);
3191 udp->dgram_cksum = 0;
3197 * Convert L2 encap action to DV specification.
3200 * Pointer to rte_eth_dev structure.
3202 * Pointer to action structure.
3203 * @param[in, out] dev_flow
3204 * Pointer to the mlx5_flow.
3205 * @param[in] transfer
3206 * Mark if the flow is E-Switch flow.
3208 * Pointer to the error structure.
3211 * 0 on success, a negative errno value otherwise and rte_errno is set.
3214 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
3215 const struct rte_flow_action *action,
3216 struct mlx5_flow *dev_flow,
3218 struct rte_flow_error *error)
3220 const struct rte_flow_item *encap_data;
3221 const struct rte_flow_action_raw_encap *raw_encap_data;
3222 struct mlx5_flow_dv_encap_decap_resource res = {
3224 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
3225 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
3226 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
3229 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
3231 (const struct rte_flow_action_raw_encap *)action->conf;
3232 res.size = raw_encap_data->size;
3233 memcpy(res.buf, raw_encap_data->data, res.size);
3235 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
3237 ((const struct rte_flow_action_vxlan_encap *)
3238 action->conf)->definition;
3241 ((const struct rte_flow_action_nvgre_encap *)
3242 action->conf)->definition;
3243 if (flow_dv_convert_encap_data(encap_data, res.buf,
3247 if (flow_dv_zero_encap_udp_csum(res.buf, error))
3249 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3250 return rte_flow_error_set(error, EINVAL,
3251 RTE_FLOW_ERROR_TYPE_ACTION,
3252 NULL, "can't create L2 encap action");
3257 * Convert L2 decap action to DV specification.
3260 * Pointer to rte_eth_dev structure.
3261 * @param[in, out] dev_flow
3262 * Pointer to the mlx5_flow.
3263 * @param[in] transfer
3264 * Mark if the flow is E-Switch flow.
3266 * Pointer to the error structure.
3269 * 0 on success, a negative errno value otherwise and rte_errno is set.
3272 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
3273 struct mlx5_flow *dev_flow,
3275 struct rte_flow_error *error)
3277 struct mlx5_flow_dv_encap_decap_resource res = {
3280 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
3281 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
3282 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
3285 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3286 return rte_flow_error_set(error, EINVAL,
3287 RTE_FLOW_ERROR_TYPE_ACTION,
3288 NULL, "can't create L2 decap action");
3293 * Convert raw decap/encap (L3 tunnel) action to DV specification.
3296 * Pointer to rte_eth_dev structure.
3298 * Pointer to action structure.
3299 * @param[in, out] dev_flow
3300 * Pointer to the mlx5_flow.
3302 * Pointer to the flow attributes.
3304 * Pointer to the error structure.
3307 * 0 on success, a negative errno value otherwise and rte_errno is set.
3310 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
3311 const struct rte_flow_action *action,
3312 struct mlx5_flow *dev_flow,
3313 const struct rte_flow_attr *attr,
3314 struct rte_flow_error *error)
3316 const struct rte_flow_action_raw_encap *encap_data;
3317 struct mlx5_flow_dv_encap_decap_resource res;
3319 memset(&res, 0, sizeof(res));
3320 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
3321 res.size = encap_data->size;
3322 memcpy(res.buf, encap_data->data, res.size);
3323 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
3324 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
3325 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
3327 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3329 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3330 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3331 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3332 return rte_flow_error_set(error, EINVAL,
3333 RTE_FLOW_ERROR_TYPE_ACTION,
3334 NULL, "can't create encap action");
3339 * Create action push VLAN.
3342 * Pointer to rte_eth_dev structure.
3344 * Pointer to the flow attributes.
3346 * Pointer to the vlan to push to the Ethernet header.
3347 * @param[in, out] dev_flow
3348 * Pointer to the mlx5_flow.
3350 * Pointer to the error structure.
3353 * 0 on success, a negative errno value otherwise and rte_errno is set.
3356 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
3357 const struct rte_flow_attr *attr,
3358 const struct rte_vlan_hdr *vlan,
3359 struct mlx5_flow *dev_flow,
3360 struct rte_flow_error *error)
3362 struct mlx5_flow_dv_push_vlan_action_resource res;
3364 memset(&res, 0, sizeof(res));
3366 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
3369 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3371 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3372 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3373 return flow_dv_push_vlan_action_resource_register
3374 (dev, &res, dev_flow, error);
3378 * Validate the modify-header actions.
3380 * @param[in] action_flags
3381 * Holds the actions detected until now.
3383 * Pointer to the modify action.
3385 * Pointer to error structure.
3388 * 0 on success, a negative errno value otherwise and rte_errno is set.
3391 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
3392 const struct rte_flow_action *action,
3393 struct rte_flow_error *error)
3395 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
3396 return rte_flow_error_set(error, EINVAL,
3397 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3398 NULL, "action configuration not set");
3399 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3400 return rte_flow_error_set(error, EINVAL,
3401 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3402 "can't have encap action before"
3408 * Validate the modify-header MAC address actions.
3410 * @param[in] action_flags
3411 * Holds the actions detected until now.
3413 * Pointer to the modify action.
3414 * @param[in] item_flags
3415 * Holds the items detected.
3417 * Pointer to error structure.
3420 * 0 on success, a negative errno value otherwise and rte_errno is set.
3423 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
3424 const struct rte_flow_action *action,
3425 const uint64_t item_flags,
3426 struct rte_flow_error *error)
3430 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3432 if (!(item_flags & MLX5_FLOW_LAYER_L2))
3433 return rte_flow_error_set(error, EINVAL,
3434 RTE_FLOW_ERROR_TYPE_ACTION,
3436 "no L2 item in pattern");
3442 * Validate the modify-header IPv4 address actions.
3444 * @param[in] action_flags
3445 * Holds the actions detected until now.
3447 * Pointer to the modify action.
3448 * @param[in] item_flags
3449 * Holds the items detected.
3451 * Pointer to error structure.
3454 * 0 on success, a negative errno value otherwise and rte_errno is set.
3457 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
3458 const struct rte_flow_action *action,
3459 const uint64_t item_flags,
3460 struct rte_flow_error *error)
3465 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3467 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3468 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
3469 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3470 if (!(item_flags & layer))
3471 return rte_flow_error_set(error, EINVAL,
3472 RTE_FLOW_ERROR_TYPE_ACTION,
3474 "no ipv4 item in pattern");
3480 * Validate the modify-header IPv6 address actions.
3482 * @param[in] action_flags
3483 * Holds the actions detected until now.
3485 * Pointer to the modify action.
3486 * @param[in] item_flags
3487 * Holds the items detected.
3489 * Pointer to error structure.
3492 * 0 on success, a negative errno value otherwise and rte_errno is set.
3495 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
3496 const struct rte_flow_action *action,
3497 const uint64_t item_flags,
3498 struct rte_flow_error *error)
3503 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3505 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3506 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
3507 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3508 if (!(item_flags & layer))
3509 return rte_flow_error_set(error, EINVAL,
3510 RTE_FLOW_ERROR_TYPE_ACTION,
3512 "no ipv6 item in pattern");
3518 * Validate the modify-header TP actions.
3520 * @param[in] action_flags
3521 * Holds the actions detected until now.
3523 * Pointer to the modify action.
3524 * @param[in] item_flags
3525 * Holds the items detected.
3527 * Pointer to error structure.
3530 * 0 on success, a negative errno value otherwise and rte_errno is set.
3533 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
3534 const struct rte_flow_action *action,
3535 const uint64_t item_flags,
3536 struct rte_flow_error *error)
3541 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3543 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3544 MLX5_FLOW_LAYER_INNER_L4 :
3545 MLX5_FLOW_LAYER_OUTER_L4;
3546 if (!(item_flags & layer))
3547 return rte_flow_error_set(error, EINVAL,
3548 RTE_FLOW_ERROR_TYPE_ACTION,
3549 NULL, "no transport layer "
3556 * Validate the modify-header actions of increment/decrement
3557 * TCP Sequence-number.
3559 * @param[in] action_flags
3560 * Holds the actions detected until now.
3562 * Pointer to the modify action.
3563 * @param[in] item_flags
3564 * Holds the items detected.
3566 * Pointer to error structure.
3569 * 0 on success, a negative errno value otherwise and rte_errno is set.
3572 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
3573 const struct rte_flow_action *action,
3574 const uint64_t item_flags,
3575 struct rte_flow_error *error)
3580 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3582 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3583 MLX5_FLOW_LAYER_INNER_L4_TCP :
3584 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3585 if (!(item_flags & layer))
3586 return rte_flow_error_set(error, EINVAL,
3587 RTE_FLOW_ERROR_TYPE_ACTION,
3588 NULL, "no TCP item in"
3590 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
3591 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
3592 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
3593 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
3594 return rte_flow_error_set(error, EINVAL,
3595 RTE_FLOW_ERROR_TYPE_ACTION,
3597 "cannot decrease and increase"
3598 " TCP sequence number"
3599 " at the same time");
3605 * Validate the modify-header actions of increment/decrement
3606 * TCP Acknowledgment number.
3608 * @param[in] action_flags
3609 * Holds the actions detected until now.
3611 * Pointer to the modify action.
3612 * @param[in] item_flags
3613 * Holds the items detected.
3615 * Pointer to error structure.
3618 * 0 on success, a negative errno value otherwise and rte_errno is set.
3621 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
3622 const struct rte_flow_action *action,
3623 const uint64_t item_flags,
3624 struct rte_flow_error *error)
3629 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3631 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3632 MLX5_FLOW_LAYER_INNER_L4_TCP :
3633 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3634 if (!(item_flags & layer))
3635 return rte_flow_error_set(error, EINVAL,
3636 RTE_FLOW_ERROR_TYPE_ACTION,
3637 NULL, "no TCP item in"
3639 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
3640 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
3641 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
3642 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
3643 return rte_flow_error_set(error, EINVAL,
3644 RTE_FLOW_ERROR_TYPE_ACTION,
3646 "cannot decrease and increase"
3647 " TCP acknowledgment number"
3648 " at the same time");
3654 * Validate the modify-header TTL actions.
3656 * @param[in] action_flags
3657 * Holds the actions detected until now.
3659 * Pointer to the modify action.
3660 * @param[in] item_flags
3661 * Holds the items detected.
3663 * Pointer to error structure.
3666 * 0 on success, a negative errno value otherwise and rte_errno is set.
3669 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
3670 const struct rte_flow_action *action,
3671 const uint64_t item_flags,
3672 struct rte_flow_error *error)
3677 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3679 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3680 MLX5_FLOW_LAYER_INNER_L3 :
3681 MLX5_FLOW_LAYER_OUTER_L3;
3682 if (!(item_flags & layer))
3683 return rte_flow_error_set(error, EINVAL,
3684 RTE_FLOW_ERROR_TYPE_ACTION,
3686 "no IP protocol in pattern");
3692 * Validate jump action.
3695 * Pointer to the jump action.
3696 * @param[in] action_flags
3697 * Holds the actions detected until now.
3698 * @param[in] attributes
3699 * Pointer to flow attributes
3700 * @param[in] external
3701 * Action belongs to flow rule created by request external to PMD.
3703 * Pointer to error structure.
3706 * 0 on success, a negative errno value otherwise and rte_errno is set.
3709 flow_dv_validate_action_jump(const struct rte_flow_action *action,
3710 uint64_t action_flags,
3711 const struct rte_flow_attr *attributes,
3712 bool external, struct rte_flow_error *error)
3714 uint32_t target_group, table;
3717 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3718 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3719 return rte_flow_error_set(error, EINVAL,
3720 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3721 "can't have 2 fate actions in"
3723 if (action_flags & MLX5_FLOW_ACTION_METER)
3724 return rte_flow_error_set(error, ENOTSUP,
3725 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3726 "jump with meter not support");
3728 return rte_flow_error_set(error, EINVAL,
3729 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3730 NULL, "action configuration not set");
3732 ((const struct rte_flow_action_jump *)action->conf)->group;
3733 ret = mlx5_flow_group_to_table(attributes, external, target_group,
3734 true, &table, error);
3737 if (attributes->group == target_group)
3738 return rte_flow_error_set(error, EINVAL,
3739 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3740 "target group must be other than"
3741 " the current flow group");
3746 * Validate the port_id action.
3749 * Pointer to rte_eth_dev structure.
3750 * @param[in] action_flags
3751 * Bit-fields that holds the actions detected until now.
3753 * Port_id RTE action structure.
3755 * Attributes of flow that includes this action.
3757 * Pointer to error structure.
3760 * 0 on success, a negative errno value otherwise and rte_errno is set.
3763 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
3764 uint64_t action_flags,
3765 const struct rte_flow_action *action,
3766 const struct rte_flow_attr *attr,
3767 struct rte_flow_error *error)
3769 const struct rte_flow_action_port_id *port_id;
3770 struct mlx5_priv *act_priv;
3771 struct mlx5_priv *dev_priv;
3774 if (!attr->transfer)
3775 return rte_flow_error_set(error, ENOTSUP,
3776 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3778 "port id action is valid in transfer"
3780 if (!action || !action->conf)
3781 return rte_flow_error_set(error, ENOTSUP,
3782 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3784 "port id action parameters must be"
3786 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
3787 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
3788 return rte_flow_error_set(error, EINVAL,
3789 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3790 "can have only one fate actions in"
3792 dev_priv = mlx5_dev_to_eswitch_info(dev);
3794 return rte_flow_error_set(error, rte_errno,
3795 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3797 "failed to obtain E-Switch info");
3798 port_id = action->conf;
3799 port = port_id->original ? dev->data->port_id : port_id->id;
3800 act_priv = mlx5_port_to_eswitch_info(port, false);
3802 return rte_flow_error_set
3804 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
3805 "failed to obtain E-Switch port id for port");
3806 if (act_priv->domain_id != dev_priv->domain_id)
3807 return rte_flow_error_set
3809 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3810 "port does not belong to"
3811 " E-Switch being configured");
3816 * Get the maximum number of modify header actions.
3819 * Pointer to rte_eth_dev structure.
3821 * Flags bits to check if root level.
3824 * Max number of modify header actions device can support.
3826 static inline unsigned int
3827 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
3831 * There's no way to directly query the max capacity from FW.
3832 * The maximal value on root table should be assumed to be supported.
3834 if (!(flags & MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL))
3835 return MLX5_MAX_MODIFY_NUM;
3837 return MLX5_ROOT_TBL_MODIFY_NUM;
3841 * Validate the meter action.
3844 * Pointer to rte_eth_dev structure.
3845 * @param[in] action_flags
3846 * Bit-fields that holds the actions detected until now.
3848 * Pointer to the meter action.
3850 * Attributes of flow that includes this action.
3852 * Pointer to error structure.
3855 * 0 on success, a negative errno value otherwise and rte_ernno is set.
3858 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
3859 uint64_t action_flags,
3860 const struct rte_flow_action *action,
3861 const struct rte_flow_attr *attr,
3862 struct rte_flow_error *error)
3864 struct mlx5_priv *priv = dev->data->dev_private;
3865 const struct rte_flow_action_meter *am = action->conf;
3866 struct mlx5_flow_meter *fm;
3869 return rte_flow_error_set(error, EINVAL,
3870 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3871 "meter action conf is NULL");
3873 if (action_flags & MLX5_FLOW_ACTION_METER)
3874 return rte_flow_error_set(error, ENOTSUP,
3875 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3876 "meter chaining not support");
3877 if (action_flags & MLX5_FLOW_ACTION_JUMP)
3878 return rte_flow_error_set(error, ENOTSUP,
3879 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3880 "meter with jump not support");
3882 return rte_flow_error_set(error, ENOTSUP,
3883 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3885 "meter action not supported");
3886 fm = mlx5_flow_meter_find(priv, am->mtr_id);
3888 return rte_flow_error_set(error, EINVAL,
3889 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3891 if (fm->ref_cnt && (!(fm->transfer == attr->transfer ||
3892 (!fm->ingress && !attr->ingress && attr->egress) ||
3893 (!fm->egress && !attr->egress && attr->ingress))))
3894 return rte_flow_error_set(error, EINVAL,
3895 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3896 "Flow attributes are either invalid "
3897 "or have a conflict with current "
3898 "meter attributes");
3903 * Validate the age action.
3905 * @param[in] action_flags
3906 * Holds the actions detected until now.
3908 * Pointer to the age action.
3910 * Pointer to the Ethernet device structure.
3912 * Pointer to error structure.
3915 * 0 on success, a negative errno value otherwise and rte_errno is set.
3918 flow_dv_validate_action_age(uint64_t action_flags,
3919 const struct rte_flow_action *action,
3920 struct rte_eth_dev *dev,
3921 struct rte_flow_error *error)
3923 struct mlx5_priv *priv = dev->data->dev_private;
3924 const struct rte_flow_action_age *age = action->conf;
3926 if (!priv->config.devx || priv->counter_fallback)
3927 return rte_flow_error_set(error, ENOTSUP,
3928 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3930 "age action not supported");
3931 if (!(action->conf))
3932 return rte_flow_error_set(error, EINVAL,
3933 RTE_FLOW_ERROR_TYPE_ACTION, action,
3934 "configuration cannot be null");
3935 if (age->timeout >= UINT16_MAX / 2 / 10)
3936 return rte_flow_error_set(error, ENOTSUP,
3937 RTE_FLOW_ERROR_TYPE_ACTION, action,
3938 "Max age time: 3275 seconds");
3939 if (action_flags & MLX5_FLOW_ACTION_AGE)
3940 return rte_flow_error_set(error, EINVAL,
3941 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3942 "Duplicate age ctions set");
3947 * Validate the modify-header IPv4 DSCP actions.
3949 * @param[in] action_flags
3950 * Holds the actions detected until now.
3952 * Pointer to the modify action.
3953 * @param[in] item_flags
3954 * Holds the items detected.
3956 * Pointer to error structure.
3959 * 0 on success, a negative errno value otherwise and rte_errno is set.
3962 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
3963 const struct rte_flow_action *action,
3964 const uint64_t item_flags,
3965 struct rte_flow_error *error)
3969 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3971 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
3972 return rte_flow_error_set(error, EINVAL,
3973 RTE_FLOW_ERROR_TYPE_ACTION,
3975 "no ipv4 item in pattern");
3981 * Validate the modify-header IPv6 DSCP actions.
3983 * @param[in] action_flags
3984 * Holds the actions detected until now.
3986 * Pointer to the modify action.
3987 * @param[in] item_flags
3988 * Holds the items detected.
3990 * Pointer to error structure.
3993 * 0 on success, a negative errno value otherwise and rte_errno is set.
3996 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
3997 const struct rte_flow_action *action,
3998 const uint64_t item_flags,
3999 struct rte_flow_error *error)
4003 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4005 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
4006 return rte_flow_error_set(error, EINVAL,
4007 RTE_FLOW_ERROR_TYPE_ACTION,
4009 "no ipv6 item in pattern");
4015 * Match modify-header resource.
4018 * Pointer to exist resource entry object.
4020 * Pointer to new modify-header resource.
4023 * 0 on matching, -1 otherwise.
4026 flow_dv_modify_hdr_resource_match(struct mlx5_hlist_entry *entry, void *ctx)
4028 struct mlx5_flow_dv_modify_hdr_resource *resource;
4029 struct mlx5_flow_dv_modify_hdr_resource *cache_resource;
4030 uint32_t actions_len;
4032 resource = (struct mlx5_flow_dv_modify_hdr_resource *)ctx;
4033 cache_resource = container_of(entry,
4034 struct mlx5_flow_dv_modify_hdr_resource,
4036 actions_len = resource->actions_num * sizeof(resource->actions[0]);
4037 if (resource->entry.key == cache_resource->entry.key &&
4038 resource->ft_type == cache_resource->ft_type &&
4039 resource->actions_num == cache_resource->actions_num &&
4040 resource->flags == cache_resource->flags &&
4041 !memcmp((const void *)resource->actions,
4042 (const void *)cache_resource->actions,
4049 * Validate the sample action.
4051 * @param[in] action_flags
4052 * Holds the actions detected until now.
4054 * Pointer to the sample action.
4056 * Pointer to the Ethernet device structure.
4058 * Attributes of flow that includes this action.
4060 * Pointer to error structure.
4063 * 0 on success, a negative errno value otherwise and rte_errno is set.
4066 flow_dv_validate_action_sample(uint64_t action_flags,
4067 const struct rte_flow_action *action,
4068 struct rte_eth_dev *dev,
4069 const struct rte_flow_attr *attr,
4070 struct rte_flow_error *error)
4072 struct mlx5_priv *priv = dev->data->dev_private;
4073 struct mlx5_dev_config *dev_conf = &priv->config;
4074 const struct rte_flow_action_sample *sample = action->conf;
4075 const struct rte_flow_action *act;
4076 uint64_t sub_action_flags = 0;
4081 return rte_flow_error_set(error, EINVAL,
4082 RTE_FLOW_ERROR_TYPE_ACTION, action,
4083 "configuration cannot be NULL");
4084 if (sample->ratio == 0)
4085 return rte_flow_error_set(error, EINVAL,
4086 RTE_FLOW_ERROR_TYPE_ACTION, action,
4087 "ratio value starts from 1");
4088 if (!priv->config.devx || (sample->ratio > 0 && !priv->sampler_en))
4089 return rte_flow_error_set(error, ENOTSUP,
4090 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4092 "sample action not supported");
4093 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
4094 return rte_flow_error_set(error, EINVAL,
4095 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4096 "Multiple sample actions not "
4098 if (action_flags & MLX5_FLOW_ACTION_METER)
4099 return rte_flow_error_set(error, EINVAL,
4100 RTE_FLOW_ERROR_TYPE_ACTION, action,
4101 "wrong action order, meter should "
4102 "be after sample action");
4103 if (action_flags & MLX5_FLOW_ACTION_JUMP)
4104 return rte_flow_error_set(error, EINVAL,
4105 RTE_FLOW_ERROR_TYPE_ACTION, action,
4106 "wrong action order, jump should "
4107 "be after sample action");
4108 act = sample->actions;
4109 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
4110 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
4111 return rte_flow_error_set(error, ENOTSUP,
4112 RTE_FLOW_ERROR_TYPE_ACTION,
4113 act, "too many actions");
4114 switch (act->type) {
4115 case RTE_FLOW_ACTION_TYPE_QUEUE:
4116 ret = mlx5_flow_validate_action_queue(act,
4122 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
4125 case RTE_FLOW_ACTION_TYPE_MARK:
4126 ret = flow_dv_validate_action_mark(dev, act,
4131 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
4132 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
4133 MLX5_FLOW_ACTION_MARK_EXT;
4135 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
4138 case RTE_FLOW_ACTION_TYPE_COUNT:
4139 ret = flow_dv_validate_action_count(dev, error);
4142 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
4146 return rte_flow_error_set(error, ENOTSUP,
4147 RTE_FLOW_ERROR_TYPE_ACTION,
4149 "Doesn't support optional "
4153 if (attr->ingress && !attr->transfer) {
4154 if (!(sub_action_flags & MLX5_FLOW_ACTION_QUEUE))
4155 return rte_flow_error_set(error, EINVAL,
4156 RTE_FLOW_ERROR_TYPE_ACTION,
4158 "Ingress must has a dest "
4159 "QUEUE for Sample");
4160 } else if (attr->egress && !attr->transfer) {
4161 return rte_flow_error_set(error, ENOTSUP,
4162 RTE_FLOW_ERROR_TYPE_ACTION,
4164 "Sample Only support Ingress "
4166 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
4167 MLX5_ASSERT(attr->transfer);
4168 return rte_flow_error_set(error, ENOTSUP,
4169 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4170 "E-Switch doesn't support any "
4171 "optional action for sampling");
4177 * Find existing modify-header resource or create and register a new one.
4179 * @param dev[in, out]
4180 * Pointer to rte_eth_dev structure.
4181 * @param[in, out] resource
4182 * Pointer to modify-header resource.
4183 * @parm[in, out] dev_flow
4184 * Pointer to the dev_flow.
4186 * pointer to error structure.
4189 * 0 on success otherwise -errno and errno is set.
4192 flow_dv_modify_hdr_resource_register
4193 (struct rte_eth_dev *dev,
4194 struct mlx5_flow_dv_modify_hdr_resource *resource,
4195 struct mlx5_flow *dev_flow,
4196 struct rte_flow_error *error)
4198 struct mlx5_priv *priv = dev->data->dev_private;
4199 struct mlx5_dev_ctx_shared *sh = priv->sh;
4200 struct mlx5_flow_dv_modify_hdr_resource *cache_resource;
4201 struct mlx5dv_dr_domain *ns;
4202 uint32_t actions_len;
4203 struct mlx5_hlist_entry *entry;
4204 union mlx5_flow_modify_hdr_key hdr_mod_key = {
4206 .ft_type = resource->ft_type,
4207 .actions_num = resource->actions_num,
4208 .group = dev_flow->dv.group,
4214 resource->flags = dev_flow->dv.group ? 0 :
4215 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
4216 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
4218 return rte_flow_error_set(error, EOVERFLOW,
4219 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4220 "too many modify header items");
4221 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4222 ns = sh->fdb_domain;
4223 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
4227 /* Lookup a matching resource from cache. */
4228 actions_len = resource->actions_num * sizeof(resource->actions[0]);
4229 hdr_mod_key.cksum = __rte_raw_cksum(resource->actions, actions_len, 0);
4230 resource->entry.key = hdr_mod_key.v64;
4231 entry = mlx5_hlist_lookup_ex(sh->modify_cmds, resource->entry.key,
4232 flow_dv_modify_hdr_resource_match,
4235 cache_resource = container_of(entry,
4236 struct mlx5_flow_dv_modify_hdr_resource,
4238 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d++",
4239 (void *)cache_resource,
4240 rte_atomic32_read(&cache_resource->refcnt));
4241 rte_atomic32_inc(&cache_resource->refcnt);
4242 dev_flow->handle->dvh.modify_hdr = cache_resource;
4246 /* Register new modify-header resource. */
4247 cache_resource = mlx5_malloc(MLX5_MEM_ZERO,
4248 sizeof(*cache_resource) + actions_len, 0,
4250 if (!cache_resource)
4251 return rte_flow_error_set(error, ENOMEM,
4252 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4253 "cannot allocate resource memory");
4254 *cache_resource = *resource;
4255 rte_memcpy(cache_resource->actions, resource->actions, actions_len);
4256 ret = mlx5_flow_os_create_flow_action_modify_header
4257 (sh->ctx, ns, cache_resource,
4258 actions_len, &cache_resource->action);
4260 mlx5_free(cache_resource);
4261 return rte_flow_error_set(error, ENOMEM,
4262 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4263 NULL, "cannot create action");
4265 rte_atomic32_init(&cache_resource->refcnt);
4266 rte_atomic32_inc(&cache_resource->refcnt);
4267 if (mlx5_hlist_insert_ex(sh->modify_cmds, &cache_resource->entry,
4268 flow_dv_modify_hdr_resource_match,
4269 (void *)cache_resource)) {
4270 claim_zero(mlx5_flow_os_destroy_flow_action
4271 (cache_resource->action));
4272 mlx5_free(cache_resource);
4273 return rte_flow_error_set(error, EEXIST,
4274 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4275 NULL, "action exist");
4277 dev_flow->handle->dvh.modify_hdr = cache_resource;
4278 DRV_LOG(DEBUG, "new modify-header resource %p: refcnt %d++",
4279 (void *)cache_resource,
4280 rte_atomic32_read(&cache_resource->refcnt));
4285 * Get DV flow counter by index.
4288 * Pointer to the Ethernet device structure.
4290 * mlx5 flow counter index in the container.
4292 * mlx5 flow counter pool in the container,
4295 * Pointer to the counter, NULL otherwise.
4297 static struct mlx5_flow_counter *
4298 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
4300 struct mlx5_flow_counter_pool **ppool)
4302 struct mlx5_priv *priv = dev->data->dev_private;
4303 struct mlx5_pools_container *cont;
4304 struct mlx5_flow_counter_pool *pool;
4305 uint32_t batch = 0, age = 0;
4308 age = MLX_CNT_IS_AGE(idx);
4309 idx = age ? idx - MLX5_CNT_AGE_OFFSET : idx;
4310 if (idx >= MLX5_CNT_BATCH_OFFSET) {
4311 idx -= MLX5_CNT_BATCH_OFFSET;
4314 cont = MLX5_CNT_CONTAINER(priv->sh, batch, age);
4315 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cont->n);
4316 pool = cont->pools[idx / MLX5_COUNTERS_PER_POOL];
4320 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
4324 * Check the devx counter belongs to the pool.
4327 * Pointer to the counter pool.
4329 * The counter devx ID.
4332 * True if counter belongs to the pool, false otherwise.
4335 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
4337 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
4338 MLX5_COUNTERS_PER_POOL;
4340 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
4346 * Get a pool by devx counter ID.
4349 * Pointer to the counter container.
4351 * The counter devx ID.
4354 * The counter pool pointer if exists, NULL otherwise,
4356 static struct mlx5_flow_counter_pool *
4357 flow_dv_find_pool_by_id(struct mlx5_pools_container *cont, int id)
4361 /* Check last used pool. */
4362 if (cont->last_pool_idx != POOL_IDX_INVALID &&
4363 flow_dv_is_counter_in_pool(cont->pools[cont->last_pool_idx], id))
4364 return cont->pools[cont->last_pool_idx];
4365 /* ID out of range means no suitable pool in the container. */
4366 if (id > cont->max_id || id < cont->min_id)
4369 * Find the pool from the end of the container, since mostly counter
4370 * ID is sequence increasing, and the last pool should be the needed
4373 i = rte_atomic16_read(&cont->n_valid);
4375 struct mlx5_flow_counter_pool *pool = cont->pools[i];
4377 if (flow_dv_is_counter_in_pool(pool, id))
4384 * Allocate a new memory for the counter values wrapped by all the needed
4388 * Pointer to the Ethernet device structure.
4390 * The raw memory areas - each one for MLX5_COUNTERS_PER_POOL counters.
4393 * The new memory management pointer on success, otherwise NULL and rte_errno
4396 static struct mlx5_counter_stats_mem_mng *
4397 flow_dv_create_counter_stat_mem_mng(struct rte_eth_dev *dev, int raws_n)
4399 struct mlx5_priv *priv = dev->data->dev_private;
4400 struct mlx5_dev_ctx_shared *sh = priv->sh;
4401 struct mlx5_devx_mkey_attr mkey_attr;
4402 struct mlx5_counter_stats_mem_mng *mem_mng;
4403 volatile struct flow_counter_stats *raw_data;
4404 int size = (sizeof(struct flow_counter_stats) *
4405 MLX5_COUNTERS_PER_POOL +
4406 sizeof(struct mlx5_counter_stats_raw)) * raws_n +
4407 sizeof(struct mlx5_counter_stats_mem_mng);
4408 size_t pgsize = rte_mem_page_size();
4409 if (pgsize == (size_t)-1) {
4410 DRV_LOG(ERR, "Failed to get mem page size");
4414 uint8_t *mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize,
4422 mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
4423 size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
4424 mem_mng->umem = mlx5_glue->devx_umem_reg(sh->ctx, mem, size,
4425 IBV_ACCESS_LOCAL_WRITE);
4426 if (!mem_mng->umem) {
4431 mkey_attr.addr = (uintptr_t)mem;
4432 mkey_attr.size = size;
4433 mkey_attr.umem_id = mlx5_os_get_umem_id(mem_mng->umem);
4434 mkey_attr.pd = sh->pdn;
4435 mkey_attr.log_entity_size = 0;
4436 mkey_attr.pg_access = 0;
4437 mkey_attr.klm_array = NULL;
4438 mkey_attr.klm_num = 0;
4439 if (priv->config.hca_attr.relaxed_ordering_write &&
4440 priv->config.hca_attr.relaxed_ordering_read &&
4441 !haswell_broadwell_cpu)
4442 mkey_attr.relaxed_ordering = 1;
4443 mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
4445 mlx5_glue->devx_umem_dereg(mem_mng->umem);
4450 mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
4451 raw_data = (volatile struct flow_counter_stats *)mem;
4452 for (i = 0; i < raws_n; ++i) {
4453 mem_mng->raws[i].mem_mng = mem_mng;
4454 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
4456 LIST_INSERT_HEAD(&sh->cmng.mem_mngs, mem_mng, next);
4461 * Resize a counter container.
4464 * Pointer to the Ethernet device structure.
4466 * Whether the pool is for counter that was allocated by batch command.
4468 * Whether the pool is for Aging counter.
4471 * 0 on success, otherwise negative errno value and rte_errno is set.
4474 flow_dv_container_resize(struct rte_eth_dev *dev,
4475 uint32_t batch, uint32_t age)
4477 struct mlx5_priv *priv = dev->data->dev_private;
4478 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4480 struct mlx5_counter_stats_mem_mng *mem_mng = NULL;
4481 void *old_pools = cont->pools;
4482 uint32_t resize = cont->n + MLX5_CNT_CONTAINER_RESIZE;
4483 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
4484 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
4491 memcpy(pools, old_pools, cont->n *
4492 sizeof(struct mlx5_flow_counter_pool *));
4494 * Fallback mode query the counter directly, no background query
4495 * resources are needed.
4497 if (!priv->counter_fallback) {
4500 mem_mng = flow_dv_create_counter_stat_mem_mng(dev,
4501 MLX5_CNT_CONTAINER_RESIZE + MLX5_MAX_PENDING_QUERIES);
4506 for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
4507 LIST_INSERT_HEAD(&priv->sh->cmng.free_stat_raws,
4509 MLX5_CNT_CONTAINER_RESIZE +
4512 rte_spinlock_lock(&cont->resize_sl);
4514 cont->mem_mng = mem_mng;
4515 cont->pools = pools;
4516 rte_spinlock_unlock(&cont->resize_sl);
4518 mlx5_free(old_pools);
4523 * Query a devx flow counter.
4526 * Pointer to the Ethernet device structure.
4528 * Index to the flow counter.
4530 * The statistics value of packets.
4532 * The statistics value of bytes.
4535 * 0 on success, otherwise a negative errno value and rte_errno is set.
4538 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
4541 struct mlx5_priv *priv = dev->data->dev_private;
4542 struct mlx5_flow_counter_pool *pool = NULL;
4543 struct mlx5_flow_counter *cnt;
4544 struct mlx5_flow_counter_ext *cnt_ext = NULL;
4547 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
4549 if (counter < MLX5_CNT_BATCH_OFFSET) {
4550 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt);
4551 if (priv->counter_fallback)
4552 return mlx5_devx_cmd_flow_counter_query(cnt_ext->dcs, 0,
4553 0, pkts, bytes, 0, NULL, NULL, 0);
4556 rte_spinlock_lock(&pool->sl);
4558 * The single counters allocation may allocate smaller ID than the
4559 * current allocated in parallel to the host reading.
4560 * In this case the new counter values must be reported as 0.
4562 if (unlikely(cnt_ext && cnt_ext->dcs->id < pool->raw->min_dcs_id)) {
4566 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
4567 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
4568 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
4570 rte_spinlock_unlock(&pool->sl);
4575 * Create and initialize a new counter pool.
4578 * Pointer to the Ethernet device structure.
4580 * The devX counter handle.
4582 * Whether the pool is for counter that was allocated by batch command.
4584 * Whether the pool is for counter that was allocated for aging.
4585 * @param[in/out] cont_cur
4586 * Pointer to the container pointer, it will be update in pool resize.
4589 * The pool container pointer on success, NULL otherwise and rte_errno is set.
4591 static struct mlx5_flow_counter_pool *
4592 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
4593 uint32_t batch, uint32_t age)
4595 struct mlx5_priv *priv = dev->data->dev_private;
4596 struct mlx5_flow_counter_pool *pool;
4597 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4599 int16_t n_valid = rte_atomic16_read(&cont->n_valid);
4600 uint32_t size = sizeof(*pool);
4602 if (cont->n == n_valid && flow_dv_container_resize(dev, batch, age))
4604 size += MLX5_COUNTERS_PER_POOL * CNT_SIZE;
4605 size += (batch ? 0 : MLX5_COUNTERS_PER_POOL * CNTEXT_SIZE);
4606 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * AGE_SIZE);
4607 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
4612 pool->min_dcs = dcs;
4613 if (!priv->counter_fallback)
4614 pool->raw = cont->mem_mng->raws + n_valid %
4615 MLX5_CNT_CONTAINER_RESIZE;
4616 pool->raw_hw = NULL;
4618 pool->type |= (batch ? 0 : CNT_POOL_TYPE_EXT);
4619 pool->type |= (!age ? 0 : CNT_POOL_TYPE_AGE);
4620 pool->query_gen = 0;
4621 rte_spinlock_init(&pool->sl);
4622 TAILQ_INIT(&pool->counters[0]);
4623 TAILQ_INIT(&pool->counters[1]);
4624 TAILQ_INSERT_HEAD(&cont->pool_list, pool, next);
4625 pool->index = n_valid;
4626 cont->pools[n_valid] = pool;
4628 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
4630 if (base < cont->min_id)
4631 cont->min_id = base;
4632 if (base > cont->max_id)
4633 cont->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
4634 cont->last_pool_idx = pool->index;
4636 /* Pool initialization must be updated before host thread access. */
4638 rte_atomic16_add(&cont->n_valid, 1);
4643 * Restore skipped counters in the pool.
4645 * As counter pool query requires the first counter dcs
4646 * ID start with 4 alinged, if the pool counters with
4647 * min_dcs ID are not aligned with 4, the counters will
4649 * Once other min_dcs ID less than these skipped counter
4650 * dcs ID appears, the skipped counters will be safe to
4652 * Should be called when min_dcs is updated.
4655 * Current counter pool.
4656 * @param[in] last_min_dcs
4660 flow_dv_counter_restore(struct mlx5_flow_counter_pool *pool,
4661 struct mlx5_devx_obj *last_min_dcs)
4663 struct mlx5_flow_counter_ext *cnt_ext;
4664 uint32_t offset, new_offset;
4665 uint32_t skip_cnt = 0;
4668 if (!pool->skip_cnt)
4671 * If last min_dcs is not valid. The skipped counter may even after
4672 * last min_dcs, set the offset to the whole pool.
4674 if (last_min_dcs->id & (MLX5_CNT_BATCH_QUERY_ID_ALIGNMENT - 1))
4675 offset = MLX5_COUNTERS_PER_POOL;
4677 offset = last_min_dcs->id % MLX5_COUNTERS_PER_POOL;
4678 new_offset = pool->min_dcs->id % MLX5_COUNTERS_PER_POOL;
4680 * Check the counters from 1 to the last_min_dcs range. Counters
4681 * before new min_dcs indicates pool still has skipped counters.
4682 * Counters be skipped after new min_dcs will be ready to use.
4683 * Offset 0 counter must be empty or min_dcs, start from 1.
4685 for (i = 1; i < offset; i++) {
4686 cnt_ext = MLX5_GET_POOL_CNT_EXT(pool, i);
4687 if (cnt_ext->skipped) {
4688 if (i > new_offset) {
4689 cnt_ext->skipped = 0;
4691 (&pool->counters[pool->query_gen],
4692 MLX5_POOL_GET_CNT(pool, i), next);
4703 * Prepare a new counter and/or a new counter pool.
4706 * Pointer to the Ethernet device structure.
4707 * @param[out] cnt_free
4708 * Where to put the pointer of a new counter.
4710 * Whether the pool is for counter that was allocated by batch command.
4712 * Whether the pool is for counter that was allocated for aging.
4715 * The counter pool pointer and @p cnt_free is set on success,
4716 * NULL otherwise and rte_errno is set.
4718 static struct mlx5_flow_counter_pool *
4719 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
4720 struct mlx5_flow_counter **cnt_free,
4721 uint32_t batch, uint32_t age)
4723 struct mlx5_priv *priv = dev->data->dev_private;
4724 struct mlx5_pools_container *cont;
4725 struct mlx5_flow_counter_pool *pool;
4726 struct mlx5_counters tmp_tq;
4727 struct mlx5_devx_obj *last_min_dcs;
4728 struct mlx5_devx_obj *dcs = NULL;
4729 struct mlx5_flow_counter *cnt;
4733 cont = MLX5_CNT_CONTAINER(priv->sh, batch, age);
4737 /* bulk_bitmap must be 0 for single counter allocation. */
4738 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
4741 pool = flow_dv_find_pool_by_id(cont, dcs->id);
4742 /* Check if counter belongs to exist pool ID range. */
4744 pool = flow_dv_find_pool_by_id
4746 (priv->sh, batch, (age ^ 0x1)), dcs->id);
4748 * Pool eixsts, counter will be added to the other
4749 * container, need to reallocate it later.
4754 pool = flow_dv_pool_create(dev, dcs, batch,
4757 mlx5_devx_cmd_destroy(dcs);
4762 if ((dcs->id < pool->min_dcs->id ||
4764 (MLX5_CNT_BATCH_QUERY_ID_ALIGNMENT - 1)) &&
4765 !(dcs->id & (MLX5_CNT_BATCH_QUERY_ID_ALIGNMENT - 1))) {
4767 * Update the pool min_dcs only if current dcs is
4768 * valid and exist min_dcs is not valid or greater
4771 last_min_dcs = pool->min_dcs;
4772 rte_atomic64_set(&pool->a64_dcs,
4773 (int64_t)(uintptr_t)dcs);
4775 * Restore any skipped counters if the new min_dcs
4776 * ID is smaller or min_dcs is not valid.
4778 if (dcs->id < last_min_dcs->id ||
4780 (MLX5_CNT_BATCH_QUERY_ID_ALIGNMENT - 1))
4781 flow_dv_counter_restore(pool, last_min_dcs);
4783 i = dcs->id % MLX5_COUNTERS_PER_POOL;
4784 cnt = MLX5_POOL_GET_CNT(pool, i);
4786 MLX5_GET_POOL_CNT_EXT(pool, i)->dcs = dcs;
4788 * If min_dcs is not valid, it means the new allocated dcs
4789 * also fail to become the valid min_dcs, just skip it.
4790 * Or if min_dcs is valid, and new dcs ID is smaller than
4791 * min_dcs, but not become the min_dcs, also skip it.
4793 if (pool->min_dcs->id &
4794 (MLX5_CNT_BATCH_QUERY_ID_ALIGNMENT - 1) ||
4795 dcs->id < pool->min_dcs->id) {
4796 MLX5_GET_POOL_CNT_EXT(pool, i)->skipped = 1;
4801 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen],
4808 /* bulk_bitmap is in 128 counters units. */
4809 if (priv->config.hca_attr.flow_counter_bulk_alloc_bitmap & 0x4)
4810 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
4812 rte_errno = ENODATA;
4815 pool = flow_dv_pool_create(dev, dcs, batch, age);
4817 mlx5_devx_cmd_destroy(dcs);
4820 TAILQ_INIT(&tmp_tq);
4821 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
4822 cnt = MLX5_POOL_GET_CNT(pool, i);
4824 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
4826 rte_spinlock_lock(&cont->csl);
4827 TAILQ_CONCAT(&cont->counters, &tmp_tq, next);
4828 rte_spinlock_unlock(&cont->csl);
4829 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
4830 (*cnt_free)->pool = pool;
4835 * Search for existed shared counter.
4838 * Pointer to the Ethernet device structure.
4840 * The shared counter ID to search.
4842 * mlx5 flow counter pool in the container,
4845 * NULL if not existed, otherwise pointer to the shared extend counter.
4847 static struct mlx5_flow_counter_ext *
4848 flow_dv_counter_shared_search(struct rte_eth_dev *dev, uint32_t id,
4849 struct mlx5_flow_counter_pool **ppool)
4851 struct mlx5_priv *priv = dev->data->dev_private;
4852 union mlx5_l3t_data data;
4855 if (mlx5_l3t_get_entry(priv->sh->cnt_id_tbl, id, &data) || !data.dword)
4857 cnt_idx = data.dword;
4859 * Shared counters don't have age info. The counter extend is after
4860 * the counter datat structure.
4862 return (struct mlx5_flow_counter_ext *)
4863 ((flow_dv_counter_get_by_idx(dev, cnt_idx, ppool)) + 1);
4867 * Allocate a flow counter.
4870 * Pointer to the Ethernet device structure.
4872 * Indicate if this counter is shared with other flows.
4874 * Counter identifier.
4876 * Counter flow group.
4878 * Whether the counter was allocated for aging.
4881 * Index to flow counter on success, 0 otherwise and rte_errno is set.
4884 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t shared, uint32_t id,
4885 uint16_t group, uint32_t age)
4887 struct mlx5_priv *priv = dev->data->dev_private;
4888 struct mlx5_flow_counter_pool *pool = NULL;
4889 struct mlx5_flow_counter *cnt_free = NULL;
4890 struct mlx5_flow_counter_ext *cnt_ext = NULL;
4892 * Currently group 0 flow counter cannot be assigned to a flow if it is
4893 * not the first one in the batch counter allocation, so it is better
4894 * to allocate counters one by one for these flows in a separate
4896 * A counter can be shared between different groups so need to take
4897 * shared counters from the single container.
4899 uint32_t batch = (group && !shared && !priv->counter_fallback) ? 1 : 0;
4900 struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch,
4904 if (!priv->config.devx) {
4905 rte_errno = ENOTSUP;
4909 cnt_ext = flow_dv_counter_shared_search(dev, id, &pool);
4911 if (cnt_ext->ref_cnt + 1 == 0) {
4916 cnt_idx = pool->index * MLX5_COUNTERS_PER_POOL +
4917 (cnt_ext->dcs->id % MLX5_COUNTERS_PER_POOL)
4922 /* Get free counters from container. */
4923 rte_spinlock_lock(&cont->csl);
4924 cnt_free = TAILQ_FIRST(&cont->counters);
4926 TAILQ_REMOVE(&cont->counters, cnt_free, next);
4927 rte_spinlock_unlock(&cont->csl);
4928 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free,
4931 pool = cnt_free->pool;
4933 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt_free);
4934 /* Create a DV counter action only in the first time usage. */
4935 if (!cnt_free->action) {
4937 struct mlx5_devx_obj *dcs;
4941 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
4942 dcs = pool->min_dcs;
4947 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
4954 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
4955 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
4956 cnt_idx += batch * MLX5_CNT_BATCH_OFFSET;
4957 cnt_idx += age * MLX5_CNT_AGE_OFFSET;
4958 /* Update the counter reset values. */
4959 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
4963 cnt_ext->shared = shared;
4964 cnt_ext->ref_cnt = 1;
4967 union mlx5_l3t_data data;
4969 data.dword = cnt_idx;
4970 if (mlx5_l3t_set_entry(priv->sh->cnt_id_tbl, id, &data))
4974 if (!priv->counter_fallback && !priv->sh->cmng.query_thread_on)
4975 /* Start the asynchronous batch query by the host thread. */
4976 mlx5_set_query_alarm(priv->sh);
4980 cnt_free->pool = pool;
4981 rte_spinlock_lock(&cont->csl);
4982 TAILQ_INSERT_TAIL(&cont->counters, cnt_free, next);
4983 rte_spinlock_unlock(&cont->csl);
4989 * Get age param from counter index.
4992 * Pointer to the Ethernet device structure.
4993 * @param[in] counter
4994 * Index to the counter handler.
4997 * The aging parameter specified for the counter index.
4999 static struct mlx5_age_param*
5000 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
5003 struct mlx5_flow_counter *cnt;
5004 struct mlx5_flow_counter_pool *pool = NULL;
5006 flow_dv_counter_get_by_idx(dev, counter, &pool);
5007 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
5008 cnt = MLX5_POOL_GET_CNT(pool, counter);
5009 return MLX5_CNT_TO_AGE(cnt);
5013 * Remove a flow counter from aged counter list.
5016 * Pointer to the Ethernet device structure.
5017 * @param[in] counter
5018 * Index to the counter handler.
5020 * Pointer to the counter handler.
5023 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
5024 uint32_t counter, struct mlx5_flow_counter *cnt)
5026 struct mlx5_age_info *age_info;
5027 struct mlx5_age_param *age_param;
5028 struct mlx5_priv *priv = dev->data->dev_private;
5030 age_info = GET_PORT_AGE_INFO(priv);
5031 age_param = flow_dv_counter_idx_get_age(dev, counter);
5032 if (rte_atomic16_cmpset((volatile uint16_t *)
5034 AGE_CANDIDATE, AGE_FREE)
5037 * We need the lock even it is age timeout,
5038 * since counter may still in process.
5040 rte_spinlock_lock(&age_info->aged_sl);
5041 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
5042 rte_spinlock_unlock(&age_info->aged_sl);
5044 rte_atomic16_set(&age_param->state, AGE_FREE);
5047 * Release a flow counter.
5050 * Pointer to the Ethernet device structure.
5051 * @param[in] counter
5052 * Index to the counter handler.
5055 flow_dv_counter_release(struct rte_eth_dev *dev, uint32_t counter)
5057 struct mlx5_priv *priv = dev->data->dev_private;
5058 struct mlx5_flow_counter_pool *pool = NULL;
5059 struct mlx5_flow_counter *cnt;
5060 struct mlx5_flow_counter_ext *cnt_ext = NULL;
5064 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
5066 if (counter < MLX5_CNT_BATCH_OFFSET) {
5067 cnt_ext = MLX5_CNT_TO_CNT_EXT(pool, cnt);
5069 if (--cnt_ext->ref_cnt)
5071 if (cnt_ext->shared)
5072 mlx5_l3t_clear_entry(priv->sh->cnt_id_tbl,
5076 if (IS_AGE_POOL(pool))
5077 flow_dv_counter_remove_from_age(dev, counter, cnt);
5080 * Put the counter back to list to be updated in none fallback mode.
5081 * Currently, we are using two list alternately, while one is in query,
5082 * add the freed counter to the other list based on the pool query_gen
5083 * value. After query finishes, add counter the list to the global
5084 * container counter list. The list changes while query starts. In
5085 * this case, lock will not be needed as query callback and release
5086 * function both operate with the different list.
5089 if (!priv->counter_fallback)
5090 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
5092 TAILQ_INSERT_TAIL(&((MLX5_CNT_CONTAINER
5093 (priv->sh, 0, 0))->counters),
5098 * Verify the @p attributes will be correctly understood by the NIC and store
5099 * them in the @p flow if everything is correct.
5102 * Pointer to dev struct.
5103 * @param[in] attributes
5104 * Pointer to flow attributes
5105 * @param[in] external
5106 * This flow rule is created by request external to PMD.
5108 * Pointer to error structure.
5111 * - 0 on success and non root table.
5112 * - 1 on success and root table.
5113 * - a negative errno value otherwise and rte_errno is set.
5116 flow_dv_validate_attributes(struct rte_eth_dev *dev,
5117 const struct rte_flow_attr *attributes,
5118 bool external __rte_unused,
5119 struct rte_flow_error *error)
5121 struct mlx5_priv *priv = dev->data->dev_private;
5122 uint32_t priority_max = priv->config.flow_prio - 1;
5125 #ifndef HAVE_MLX5DV_DR
5126 if (attributes->group)
5127 return rte_flow_error_set(error, ENOTSUP,
5128 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5130 "groups are not supported");
5134 ret = mlx5_flow_group_to_table(attributes, external,
5135 attributes->group, !!priv->fdb_def_rule,
5140 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
5142 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
5143 attributes->priority >= priority_max)
5144 return rte_flow_error_set(error, ENOTSUP,
5145 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
5147 "priority out of range");
5148 if (attributes->transfer) {
5149 if (!priv->config.dv_esw_en)
5150 return rte_flow_error_set
5152 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5153 "E-Switch dr is not supported");
5154 if (!(priv->representor || priv->master))
5155 return rte_flow_error_set
5156 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5157 NULL, "E-Switch configuration can only be"
5158 " done by a master or a representor device");
5159 if (attributes->egress)
5160 return rte_flow_error_set
5162 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
5163 "egress is not supported");
5165 if (!(attributes->egress ^ attributes->ingress))
5166 return rte_flow_error_set(error, ENOTSUP,
5167 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
5168 "must specify exactly one of "
5169 "ingress or egress");
5174 * Internal validation function. For validating both actions and items.
5177 * Pointer to the rte_eth_dev structure.
5179 * Pointer to the flow attributes.
5181 * Pointer to the list of items.
5182 * @param[in] actions
5183 * Pointer to the list of actions.
5184 * @param[in] external
5185 * This flow rule is created by request external to PMD.
5186 * @param[in] hairpin
5187 * Number of hairpin TX actions, 0 means classic flow.
5189 * Pointer to the error structure.
5192 * 0 on success, a negative errno value otherwise and rte_errno is set.
5195 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
5196 const struct rte_flow_item items[],
5197 const struct rte_flow_action actions[],
5198 bool external, int hairpin, struct rte_flow_error *error)
5201 uint64_t action_flags = 0;
5202 uint64_t item_flags = 0;
5203 uint64_t last_item = 0;
5204 uint8_t next_protocol = 0xff;
5205 uint16_t ether_type = 0;
5207 uint8_t item_ipv6_proto = 0;
5208 const struct rte_flow_item *gre_item = NULL;
5209 const struct rte_flow_action_raw_decap *decap;
5210 const struct rte_flow_action_raw_encap *encap;
5211 const struct rte_flow_action_rss *rss;
5212 const struct rte_flow_item_tcp nic_tcp_mask = {
5215 .src_port = RTE_BE16(UINT16_MAX),
5216 .dst_port = RTE_BE16(UINT16_MAX),
5219 const struct rte_flow_item_ipv4 nic_ipv4_mask = {
5221 .src_addr = RTE_BE32(0xffffffff),
5222 .dst_addr = RTE_BE32(0xffffffff),
5223 .type_of_service = 0xff,
5224 .next_proto_id = 0xff,
5225 .time_to_live = 0xff,
5228 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
5231 "\xff\xff\xff\xff\xff\xff\xff\xff"
5232 "\xff\xff\xff\xff\xff\xff\xff\xff",
5234 "\xff\xff\xff\xff\xff\xff\xff\xff"
5235 "\xff\xff\xff\xff\xff\xff\xff\xff",
5236 .vtc_flow = RTE_BE32(0xffffffff),
5241 const struct rte_flow_item_ecpri nic_ecpri_mask = {
5245 RTE_BE32(((const struct rte_ecpri_common_hdr) {
5249 .dummy[0] = 0xffffffff,
5252 struct mlx5_priv *priv = dev->data->dev_private;
5253 struct mlx5_dev_config *dev_conf = &priv->config;
5254 uint16_t queue_index = 0xFFFF;
5255 const struct rte_flow_item_vlan *vlan_m = NULL;
5256 int16_t rw_act_num = 0;
5261 ret = flow_dv_validate_attributes(dev, attr, external, error);
5264 is_root = (uint64_t)ret;
5265 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5266 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
5267 int type = items->type;
5269 if (!mlx5_flow_os_item_supported(type))
5270 return rte_flow_error_set(error, ENOTSUP,
5271 RTE_FLOW_ERROR_TYPE_ITEM,
5272 NULL, "item not supported");
5274 case RTE_FLOW_ITEM_TYPE_VOID:
5276 case RTE_FLOW_ITEM_TYPE_PORT_ID:
5277 ret = flow_dv_validate_item_port_id
5278 (dev, items, attr, item_flags, error);
5281 last_item = MLX5_FLOW_ITEM_PORT_ID;
5283 case RTE_FLOW_ITEM_TYPE_ETH:
5284 ret = mlx5_flow_validate_item_eth(items, item_flags,
5288 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
5289 MLX5_FLOW_LAYER_OUTER_L2;
5290 if (items->mask != NULL && items->spec != NULL) {
5292 ((const struct rte_flow_item_eth *)
5295 ((const struct rte_flow_item_eth *)
5297 ether_type = rte_be_to_cpu_16(ether_type);
5302 case RTE_FLOW_ITEM_TYPE_VLAN:
5303 ret = flow_dv_validate_item_vlan(items, item_flags,
5307 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
5308 MLX5_FLOW_LAYER_OUTER_VLAN;
5309 if (items->mask != NULL && items->spec != NULL) {
5311 ((const struct rte_flow_item_vlan *)
5312 items->spec)->inner_type;
5314 ((const struct rte_flow_item_vlan *)
5315 items->mask)->inner_type;
5316 ether_type = rte_be_to_cpu_16(ether_type);
5320 /* Store outer VLAN mask for of_push_vlan action. */
5322 vlan_m = items->mask;
5324 case RTE_FLOW_ITEM_TYPE_IPV4:
5325 mlx5_flow_tunnel_ip_check(items, next_protocol,
5326 &item_flags, &tunnel);
5327 ret = mlx5_flow_validate_item_ipv4(items, item_flags,
5334 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5335 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5336 if (items->mask != NULL &&
5337 ((const struct rte_flow_item_ipv4 *)
5338 items->mask)->hdr.next_proto_id) {
5340 ((const struct rte_flow_item_ipv4 *)
5341 (items->spec))->hdr.next_proto_id;
5343 ((const struct rte_flow_item_ipv4 *)
5344 (items->mask))->hdr.next_proto_id;
5346 /* Reset for inner layer. */
5347 next_protocol = 0xff;
5350 case RTE_FLOW_ITEM_TYPE_IPV6:
5351 mlx5_flow_tunnel_ip_check(items, next_protocol,
5352 &item_flags, &tunnel);
5353 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
5360 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5361 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5362 if (items->mask != NULL &&
5363 ((const struct rte_flow_item_ipv6 *)
5364 items->mask)->hdr.proto) {
5366 ((const struct rte_flow_item_ipv6 *)
5367 items->spec)->hdr.proto;
5369 ((const struct rte_flow_item_ipv6 *)
5370 items->spec)->hdr.proto;
5372 ((const struct rte_flow_item_ipv6 *)
5373 items->mask)->hdr.proto;
5375 /* Reset for inner layer. */
5376 next_protocol = 0xff;
5379 case RTE_FLOW_ITEM_TYPE_TCP:
5380 ret = mlx5_flow_validate_item_tcp
5387 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
5388 MLX5_FLOW_LAYER_OUTER_L4_TCP;
5390 case RTE_FLOW_ITEM_TYPE_UDP:
5391 ret = mlx5_flow_validate_item_udp(items, item_flags,
5396 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
5397 MLX5_FLOW_LAYER_OUTER_L4_UDP;
5399 case RTE_FLOW_ITEM_TYPE_GRE:
5400 ret = mlx5_flow_validate_item_gre(items, item_flags,
5401 next_protocol, error);
5405 last_item = MLX5_FLOW_LAYER_GRE;
5407 case RTE_FLOW_ITEM_TYPE_NVGRE:
5408 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
5413 last_item = MLX5_FLOW_LAYER_NVGRE;
5415 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
5416 ret = mlx5_flow_validate_item_gre_key
5417 (items, item_flags, gre_item, error);
5420 last_item = MLX5_FLOW_LAYER_GRE_KEY;
5422 case RTE_FLOW_ITEM_TYPE_VXLAN:
5423 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
5427 last_item = MLX5_FLOW_LAYER_VXLAN;
5429 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
5430 ret = mlx5_flow_validate_item_vxlan_gpe(items,
5435 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
5437 case RTE_FLOW_ITEM_TYPE_GENEVE:
5438 ret = mlx5_flow_validate_item_geneve(items,
5443 last_item = MLX5_FLOW_LAYER_GENEVE;
5445 case RTE_FLOW_ITEM_TYPE_MPLS:
5446 ret = mlx5_flow_validate_item_mpls(dev, items,
5451 last_item = MLX5_FLOW_LAYER_MPLS;
5454 case RTE_FLOW_ITEM_TYPE_MARK:
5455 ret = flow_dv_validate_item_mark(dev, items, attr,
5459 last_item = MLX5_FLOW_ITEM_MARK;
5461 case RTE_FLOW_ITEM_TYPE_META:
5462 ret = flow_dv_validate_item_meta(dev, items, attr,
5466 last_item = MLX5_FLOW_ITEM_METADATA;
5468 case RTE_FLOW_ITEM_TYPE_ICMP:
5469 ret = mlx5_flow_validate_item_icmp(items, item_flags,
5474 last_item = MLX5_FLOW_LAYER_ICMP;
5476 case RTE_FLOW_ITEM_TYPE_ICMP6:
5477 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
5482 item_ipv6_proto = IPPROTO_ICMPV6;
5483 last_item = MLX5_FLOW_LAYER_ICMP6;
5485 case RTE_FLOW_ITEM_TYPE_TAG:
5486 ret = flow_dv_validate_item_tag(dev, items,
5490 last_item = MLX5_FLOW_ITEM_TAG;
5492 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
5493 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
5495 case RTE_FLOW_ITEM_TYPE_GTP:
5496 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
5500 last_item = MLX5_FLOW_LAYER_GTP;
5502 case RTE_FLOW_ITEM_TYPE_ECPRI:
5503 /* Capacity will be checked in the translate stage. */
5504 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
5511 last_item = MLX5_FLOW_LAYER_ECPRI;
5514 return rte_flow_error_set(error, ENOTSUP,
5515 RTE_FLOW_ERROR_TYPE_ITEM,
5516 NULL, "item not supported");
5518 item_flags |= last_item;
5520 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5521 int type = actions->type;
5523 if (!mlx5_flow_os_action_supported(type))
5524 return rte_flow_error_set(error, ENOTSUP,
5525 RTE_FLOW_ERROR_TYPE_ACTION,
5527 "action not supported");
5528 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5529 return rte_flow_error_set(error, ENOTSUP,
5530 RTE_FLOW_ERROR_TYPE_ACTION,
5531 actions, "too many actions");
5533 case RTE_FLOW_ACTION_TYPE_VOID:
5535 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5536 ret = flow_dv_validate_action_port_id(dev,
5543 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5546 case RTE_FLOW_ACTION_TYPE_FLAG:
5547 ret = flow_dv_validate_action_flag(dev, action_flags,
5551 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
5552 /* Count all modify-header actions as one. */
5553 if (!(action_flags &
5554 MLX5_FLOW_MODIFY_HDR_ACTIONS))
5556 action_flags |= MLX5_FLOW_ACTION_FLAG |
5557 MLX5_FLOW_ACTION_MARK_EXT;
5559 action_flags |= MLX5_FLOW_ACTION_FLAG;
5562 rw_act_num += MLX5_ACT_NUM_SET_MARK;
5564 case RTE_FLOW_ACTION_TYPE_MARK:
5565 ret = flow_dv_validate_action_mark(dev, actions,
5570 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
5571 /* Count all modify-header actions as one. */
5572 if (!(action_flags &
5573 MLX5_FLOW_MODIFY_HDR_ACTIONS))
5575 action_flags |= MLX5_FLOW_ACTION_MARK |
5576 MLX5_FLOW_ACTION_MARK_EXT;
5578 action_flags |= MLX5_FLOW_ACTION_MARK;
5581 rw_act_num += MLX5_ACT_NUM_SET_MARK;
5583 case RTE_FLOW_ACTION_TYPE_SET_META:
5584 ret = flow_dv_validate_action_set_meta(dev, actions,
5589 /* Count all modify-header actions as one action. */
5590 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5592 action_flags |= MLX5_FLOW_ACTION_SET_META;
5593 rw_act_num += MLX5_ACT_NUM_SET_META;
5595 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5596 ret = flow_dv_validate_action_set_tag(dev, actions,
5601 /* Count all modify-header actions as one action. */
5602 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5604 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
5605 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5607 case RTE_FLOW_ACTION_TYPE_DROP:
5608 ret = mlx5_flow_validate_action_drop(action_flags,
5612 action_flags |= MLX5_FLOW_ACTION_DROP;
5615 case RTE_FLOW_ACTION_TYPE_QUEUE:
5616 ret = mlx5_flow_validate_action_queue(actions,
5621 queue_index = ((const struct rte_flow_action_queue *)
5622 (actions->conf))->index;
5623 action_flags |= MLX5_FLOW_ACTION_QUEUE;
5626 case RTE_FLOW_ACTION_TYPE_RSS:
5627 rss = actions->conf;
5628 ret = mlx5_flow_validate_action_rss(actions,
5634 if (rss != NULL && rss->queue_num)
5635 queue_index = rss->queue[0];
5636 action_flags |= MLX5_FLOW_ACTION_RSS;
5639 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
5641 mlx5_flow_validate_action_default_miss(action_flags,
5645 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
5648 case RTE_FLOW_ACTION_TYPE_COUNT:
5649 ret = flow_dv_validate_action_count(dev, error);
5652 action_flags |= MLX5_FLOW_ACTION_COUNT;
5655 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5656 if (flow_dv_validate_action_pop_vlan(dev,
5662 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
5665 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5666 ret = flow_dv_validate_action_push_vlan(dev,
5673 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
5676 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5677 ret = flow_dv_validate_action_set_vlan_pcp
5678 (action_flags, actions, error);
5681 /* Count PCP with push_vlan command. */
5682 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
5684 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5685 ret = flow_dv_validate_action_set_vlan_vid
5686 (item_flags, action_flags,
5690 /* Count VID with push_vlan command. */
5691 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
5692 rw_act_num += MLX5_ACT_NUM_MDF_VID;
5694 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5695 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5696 ret = flow_dv_validate_action_l2_encap(dev,
5702 action_flags |= MLX5_FLOW_ACTION_ENCAP;
5705 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5706 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5707 ret = flow_dv_validate_action_decap(dev, action_flags,
5711 action_flags |= MLX5_FLOW_ACTION_DECAP;
5714 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5715 ret = flow_dv_validate_action_raw_encap_decap
5716 (dev, NULL, actions->conf, attr, &action_flags,
5721 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5722 decap = actions->conf;
5723 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
5725 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5729 encap = actions->conf;
5731 ret = flow_dv_validate_action_raw_encap_decap
5733 decap ? decap : &empty_decap, encap,
5734 attr, &action_flags, &actions_n,
5739 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5740 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5741 ret = flow_dv_validate_action_modify_mac(action_flags,
5747 /* Count all modify-header actions as one action. */
5748 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5750 action_flags |= actions->type ==
5751 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
5752 MLX5_FLOW_ACTION_SET_MAC_SRC :
5753 MLX5_FLOW_ACTION_SET_MAC_DST;
5755 * Even if the source and destination MAC addresses have
5756 * overlap in the header with 4B alignment, the convert
5757 * function will handle them separately and 4 SW actions
5758 * will be created. And 2 actions will be added each
5759 * time no matter how many bytes of address will be set.
5761 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
5763 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5764 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5765 ret = flow_dv_validate_action_modify_ipv4(action_flags,
5771 /* Count all modify-header actions as one action. */
5772 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5774 action_flags |= actions->type ==
5775 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
5776 MLX5_FLOW_ACTION_SET_IPV4_SRC :
5777 MLX5_FLOW_ACTION_SET_IPV4_DST;
5778 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
5780 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5781 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5782 ret = flow_dv_validate_action_modify_ipv6(action_flags,
5788 if (item_ipv6_proto == IPPROTO_ICMPV6)
5789 return rte_flow_error_set(error, ENOTSUP,
5790 RTE_FLOW_ERROR_TYPE_ACTION,
5792 "Can't change header "
5793 "with ICMPv6 proto");
5794 /* Count all modify-header actions as one action. */
5795 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5797 action_flags |= actions->type ==
5798 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
5799 MLX5_FLOW_ACTION_SET_IPV6_SRC :
5800 MLX5_FLOW_ACTION_SET_IPV6_DST;
5801 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
5803 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5804 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5805 ret = flow_dv_validate_action_modify_tp(action_flags,
5811 /* Count all modify-header actions as one action. */
5812 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5814 action_flags |= actions->type ==
5815 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
5816 MLX5_FLOW_ACTION_SET_TP_SRC :
5817 MLX5_FLOW_ACTION_SET_TP_DST;
5818 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
5820 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5821 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5822 ret = flow_dv_validate_action_modify_ttl(action_flags,
5828 /* Count all modify-header actions as one action. */
5829 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5831 action_flags |= actions->type ==
5832 RTE_FLOW_ACTION_TYPE_SET_TTL ?
5833 MLX5_FLOW_ACTION_SET_TTL :
5834 MLX5_FLOW_ACTION_DEC_TTL;
5835 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
5837 case RTE_FLOW_ACTION_TYPE_JUMP:
5838 ret = flow_dv_validate_action_jump(actions,
5845 action_flags |= MLX5_FLOW_ACTION_JUMP;
5847 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
5848 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
5849 ret = flow_dv_validate_action_modify_tcp_seq
5856 /* Count all modify-header actions as one action. */
5857 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5859 action_flags |= actions->type ==
5860 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
5861 MLX5_FLOW_ACTION_INC_TCP_SEQ :
5862 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
5863 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
5865 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
5866 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
5867 ret = flow_dv_validate_action_modify_tcp_ack
5874 /* Count all modify-header actions as one action. */
5875 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5877 action_flags |= actions->type ==
5878 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
5879 MLX5_FLOW_ACTION_INC_TCP_ACK :
5880 MLX5_FLOW_ACTION_DEC_TCP_ACK;
5881 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
5883 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
5885 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
5886 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
5887 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5889 case RTE_FLOW_ACTION_TYPE_METER:
5890 ret = mlx5_flow_validate_action_meter(dev,
5896 action_flags |= MLX5_FLOW_ACTION_METER;
5898 /* Meter action will add one more TAG action. */
5899 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5901 case RTE_FLOW_ACTION_TYPE_AGE:
5902 ret = flow_dv_validate_action_age(action_flags,
5907 action_flags |= MLX5_FLOW_ACTION_AGE;
5910 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
5911 ret = flow_dv_validate_action_modify_ipv4_dscp
5918 /* Count all modify-header actions as one action. */
5919 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5921 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
5922 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
5924 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
5925 ret = flow_dv_validate_action_modify_ipv6_dscp
5932 /* Count all modify-header actions as one action. */
5933 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5935 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
5936 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
5938 case RTE_FLOW_ACTION_TYPE_SAMPLE:
5939 ret = flow_dv_validate_action_sample(action_flags,
5944 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
5948 return rte_flow_error_set(error, ENOTSUP,
5949 RTE_FLOW_ERROR_TYPE_ACTION,
5951 "action not supported");
5955 * Validate the drop action mutual exclusion with other actions.
5956 * Drop action is mutually-exclusive with any other action, except for
5959 if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
5960 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
5961 return rte_flow_error_set(error, EINVAL,
5962 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5963 "Drop action is mutually-exclusive "
5964 "with any other action, except for "
5966 /* Eswitch has few restrictions on using items and actions */
5967 if (attr->transfer) {
5968 if (!mlx5_flow_ext_mreg_supported(dev) &&
5969 action_flags & MLX5_FLOW_ACTION_FLAG)
5970 return rte_flow_error_set(error, ENOTSUP,
5971 RTE_FLOW_ERROR_TYPE_ACTION,
5973 "unsupported action FLAG");
5974 if (!mlx5_flow_ext_mreg_supported(dev) &&
5975 action_flags & MLX5_FLOW_ACTION_MARK)
5976 return rte_flow_error_set(error, ENOTSUP,
5977 RTE_FLOW_ERROR_TYPE_ACTION,
5979 "unsupported action MARK");
5980 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
5981 return rte_flow_error_set(error, ENOTSUP,
5982 RTE_FLOW_ERROR_TYPE_ACTION,
5984 "unsupported action QUEUE");
5985 if (action_flags & MLX5_FLOW_ACTION_RSS)
5986 return rte_flow_error_set(error, ENOTSUP,
5987 RTE_FLOW_ERROR_TYPE_ACTION,
5989 "unsupported action RSS");
5990 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5991 return rte_flow_error_set(error, EINVAL,
5992 RTE_FLOW_ERROR_TYPE_ACTION,
5994 "no fate action is found");
5996 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
5997 return rte_flow_error_set(error, EINVAL,
5998 RTE_FLOW_ERROR_TYPE_ACTION,
6000 "no fate action is found");
6002 /* Continue validation for Xcap and VLAN actions.*/
6003 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
6004 MLX5_FLOW_VLAN_ACTIONS)) &&
6005 (queue_index == 0xFFFF ||
6006 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
6007 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
6008 MLX5_FLOW_XCAP_ACTIONS)
6009 return rte_flow_error_set(error, ENOTSUP,
6010 RTE_FLOW_ERROR_TYPE_ACTION,
6011 NULL, "encap and decap "
6012 "combination aren't supported");
6013 if (!attr->transfer && attr->ingress) {
6014 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
6015 return rte_flow_error_set
6017 RTE_FLOW_ERROR_TYPE_ACTION,
6018 NULL, "encap is not supported"
6019 " for ingress traffic");
6020 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
6021 return rte_flow_error_set
6023 RTE_FLOW_ERROR_TYPE_ACTION,
6024 NULL, "push VLAN action not "
6025 "supported for ingress");
6026 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
6027 MLX5_FLOW_VLAN_ACTIONS)
6028 return rte_flow_error_set
6030 RTE_FLOW_ERROR_TYPE_ACTION,
6031 NULL, "no support for "
6032 "multiple VLAN actions");
6035 /* Hairpin flow will add one more TAG action. */
6037 rw_act_num += MLX5_ACT_NUM_SET_TAG;
6038 /* extra metadata enabled: one more TAG action will be add. */
6039 if (dev_conf->dv_flow_en &&
6040 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
6041 mlx5_flow_ext_mreg_supported(dev))
6042 rw_act_num += MLX5_ACT_NUM_SET_TAG;
6043 if ((uint32_t)rw_act_num >
6044 flow_dv_modify_hdr_action_max(dev, is_root)) {
6045 return rte_flow_error_set(error, ENOTSUP,
6046 RTE_FLOW_ERROR_TYPE_ACTION,
6047 NULL, "too many header modify"
6048 " actions to support");
6054 * Internal preparation function. Allocates the DV flow size,
6055 * this size is constant.
6058 * Pointer to the rte_eth_dev structure.
6060 * Pointer to the flow attributes.
6062 * Pointer to the list of items.
6063 * @param[in] actions
6064 * Pointer to the list of actions.
6066 * Pointer to the error structure.
6069 * Pointer to mlx5_flow object on success,
6070 * otherwise NULL and rte_errno is set.
6072 static struct mlx5_flow *
6073 flow_dv_prepare(struct rte_eth_dev *dev,
6074 const struct rte_flow_attr *attr __rte_unused,
6075 const struct rte_flow_item items[] __rte_unused,
6076 const struct rte_flow_action actions[] __rte_unused,
6077 struct rte_flow_error *error)
6079 uint32_t handle_idx = 0;
6080 struct mlx5_flow *dev_flow;
6081 struct mlx5_flow_handle *dev_handle;
6082 struct mlx5_priv *priv = dev->data->dev_private;
6084 /* In case of corrupting the memory. */
6085 if (priv->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
6086 rte_flow_error_set(error, ENOSPC,
6087 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6088 "not free temporary device flow");
6091 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
6094 rte_flow_error_set(error, ENOMEM,
6095 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6096 "not enough memory to create flow handle");
6099 /* No multi-thread supporting. */
6100 dev_flow = &((struct mlx5_flow *)priv->inter_flows)[priv->flow_idx++];
6101 dev_flow->handle = dev_handle;
6102 dev_flow->handle_idx = handle_idx;
6104 * In some old rdma-core releases, before continuing, a check of the
6105 * length of matching parameter will be done at first. It needs to use
6106 * the length without misc4 param. If the flow has misc4 support, then
6107 * the length needs to be adjusted accordingly. Each param member is
6108 * aligned with a 64B boundary naturally.
6110 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param) -
6111 MLX5_ST_SZ_BYTES(fte_match_set_misc4);
6113 * The matching value needs to be cleared to 0 before using. In the
6114 * past, it will be automatically cleared when using rte_*alloc
6115 * API. The time consumption will be almost the same as before.
6117 memset(dev_flow->dv.value.buf, 0, MLX5_ST_SZ_BYTES(fte_match_param));
6118 dev_flow->ingress = attr->ingress;
6119 dev_flow->dv.transfer = attr->transfer;
6123 #ifdef RTE_LIBRTE_MLX5_DEBUG
6125 * Sanity check for match mask and value. Similar to check_valid_spec() in
6126 * kernel driver. If unmasked bit is present in value, it returns failure.
6129 * pointer to match mask buffer.
6130 * @param match_value
6131 * pointer to match value buffer.
6134 * 0 if valid, -EINVAL otherwise.
6137 flow_dv_check_valid_spec(void *match_mask, void *match_value)
6139 uint8_t *m = match_mask;
6140 uint8_t *v = match_value;
6143 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
6146 "match_value differs from match_criteria"
6147 " %p[%u] != %p[%u]",
6148 match_value, i, match_mask, i);
6157 * Add match of ip_version.
6161 * @param[in] headers_v
6162 * Values header pointer.
6163 * @param[in] headers_m
6164 * Masks header pointer.
6165 * @param[in] ip_version
6166 * The IP version to set.
6169 flow_dv_set_match_ip_version(uint32_t group,
6175 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
6177 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
6179 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
6180 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
6181 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
6185 * Add Ethernet item to matcher and to the value.
6187 * @param[in, out] matcher
6189 * @param[in, out] key
6190 * Flow matcher value.
6192 * Flow pattern to translate.
6194 * Item is inner pattern.
6197 flow_dv_translate_item_eth(void *matcher, void *key,
6198 const struct rte_flow_item *item, int inner,
6201 const struct rte_flow_item_eth *eth_m = item->mask;
6202 const struct rte_flow_item_eth *eth_v = item->spec;
6203 const struct rte_flow_item_eth nic_mask = {
6204 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
6205 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
6206 .type = RTE_BE16(0xffff),
6218 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6220 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6222 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6224 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6226 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, dmac_47_16),
6227 ð_m->dst, sizeof(eth_m->dst));
6228 /* The value must be in the range of the mask. */
6229 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, dmac_47_16);
6230 for (i = 0; i < sizeof(eth_m->dst); ++i)
6231 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
6232 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m, smac_47_16),
6233 ð_m->src, sizeof(eth_m->src));
6234 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v, smac_47_16);
6235 /* The value must be in the range of the mask. */
6236 for (i = 0; i < sizeof(eth_m->dst); ++i)
6237 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
6239 /* When ethertype is present set mask for tagged VLAN. */
6240 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
6241 /* Set value for tagged VLAN if ethertype is 802.1Q. */
6242 if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_VLAN) ||
6243 eth_v->type == RTE_BE16(RTE_ETHER_TYPE_QINQ)) {
6244 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag,
6246 /* Return here to avoid setting match on ethertype. */
6251 * HW supports match on one Ethertype, the Ethertype following the last
6252 * VLAN tag of the packet (see PRM).
6253 * Set match on ethertype only if ETH header is not followed by VLAN.
6254 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
6255 * ethertype, and use ip_version field instead.
6256 * eCPRI over Ether layer will use type value 0xAEFE.
6258 if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_IPV4) &&
6259 eth_m->type == 0xFFFF) {
6260 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
6261 } else if (eth_v->type == RTE_BE16(RTE_ETHER_TYPE_IPV6) &&
6262 eth_m->type == 0xFFFF) {
6263 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
6265 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
6266 rte_be_to_cpu_16(eth_m->type));
6267 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6269 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
6274 * Add VLAN item to matcher and to the value.
6276 * @param[in, out] dev_flow
6278 * @param[in, out] matcher
6280 * @param[in, out] key
6281 * Flow matcher value.
6283 * Flow pattern to translate.
6285 * Item is inner pattern.
6288 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
6289 void *matcher, void *key,
6290 const struct rte_flow_item *item,
6291 int inner, uint32_t group)
6293 const struct rte_flow_item_vlan *vlan_m = item->mask;
6294 const struct rte_flow_item_vlan *vlan_v = item->spec;
6301 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6303 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6305 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6307 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6309 * This is workaround, masks are not supported,
6310 * and pre-validated.
6313 dev_flow->handle->vf_vlan.tag =
6314 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
6317 * When VLAN item exists in flow, mark packet as tagged,
6318 * even if TCI is not specified.
6320 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
6321 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
6325 vlan_m = &rte_flow_item_vlan_mask;
6326 tci_m = rte_be_to_cpu_16(vlan_m->tci);
6327 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
6328 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_vid, tci_m);
6329 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, tci_v);
6330 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_cfi, tci_m >> 12);
6331 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_cfi, tci_v >> 12);
6332 MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_prio, tci_m >> 13);
6333 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, tci_v >> 13);
6335 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
6336 * ethertype, and use ip_version field instead.
6338 if (vlan_v->inner_type == RTE_BE16(RTE_ETHER_TYPE_IPV4) &&
6339 vlan_m->inner_type == 0xFFFF) {
6340 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
6341 } else if (vlan_v->inner_type == RTE_BE16(RTE_ETHER_TYPE_IPV6) &&
6342 vlan_m->inner_type == 0xFFFF) {
6343 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
6345 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
6346 rte_be_to_cpu_16(vlan_m->inner_type));
6347 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
6348 rte_be_to_cpu_16(vlan_m->inner_type &
6349 vlan_v->inner_type));
6354 * Add IPV4 item to matcher and to the value.
6356 * @param[in, out] matcher
6358 * @param[in, out] key
6359 * Flow matcher value.
6361 * Flow pattern to translate.
6362 * @param[in] item_flags
6363 * Bit-fields that holds the items detected until now.
6365 * Item is inner pattern.
6367 * The group to insert the rule.
6370 flow_dv_translate_item_ipv4(void *matcher, void *key,
6371 const struct rte_flow_item *item,
6372 const uint64_t item_flags,
6373 int inner, uint32_t group)
6375 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
6376 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
6377 const struct rte_flow_item_ipv4 nic_mask = {
6379 .src_addr = RTE_BE32(0xffffffff),
6380 .dst_addr = RTE_BE32(0xffffffff),
6381 .type_of_service = 0xff,
6382 .next_proto_id = 0xff,
6383 .time_to_live = 0xff,
6393 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6395 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6397 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6399 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6401 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
6403 * On outer header (which must contains L2), or inner header with L2,
6404 * set cvlan_tag mask bit to mark this packet as untagged.
6405 * This should be done even if item->spec is empty.
6407 if (!inner || item_flags & MLX5_FLOW_LAYER_INNER_L2)
6408 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
6413 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6414 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
6415 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6416 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
6417 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
6418 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
6419 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6420 src_ipv4_src_ipv6.ipv4_layout.ipv4);
6421 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6422 src_ipv4_src_ipv6.ipv4_layout.ipv4);
6423 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
6424 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
6425 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
6426 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
6427 ipv4_m->hdr.type_of_service);
6428 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
6429 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
6430 ipv4_m->hdr.type_of_service >> 2);
6431 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
6432 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
6433 ipv4_m->hdr.next_proto_id);
6434 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6435 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
6436 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
6437 ipv4_m->hdr.time_to_live);
6438 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
6439 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
6443 * Add IPV6 item to matcher and to the value.
6445 * @param[in, out] matcher
6447 * @param[in, out] key
6448 * Flow matcher value.
6450 * Flow pattern to translate.
6451 * @param[in] item_flags
6452 * Bit-fields that holds the items detected until now.
6454 * Item is inner pattern.
6456 * The group to insert the rule.
6459 flow_dv_translate_item_ipv6(void *matcher, void *key,
6460 const struct rte_flow_item *item,
6461 const uint64_t item_flags,
6462 int inner, uint32_t group)
6464 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
6465 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
6466 const struct rte_flow_item_ipv6 nic_mask = {
6469 "\xff\xff\xff\xff\xff\xff\xff\xff"
6470 "\xff\xff\xff\xff\xff\xff\xff\xff",
6472 "\xff\xff\xff\xff\xff\xff\xff\xff"
6473 "\xff\xff\xff\xff\xff\xff\xff\xff",
6474 .vtc_flow = RTE_BE32(0xffffffff),
6481 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6482 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6491 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6493 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6495 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6497 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6499 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
6501 * On outer header (which must contains L2), or inner header with L2,
6502 * set cvlan_tag mask bit to mark this packet as untagged.
6503 * This should be done even if item->spec is empty.
6505 if (!inner || item_flags & MLX5_FLOW_LAYER_INNER_L2)
6506 MLX5_SET(fte_match_set_lyr_2_4, headers_m, cvlan_tag, 1);
6511 size = sizeof(ipv6_m->hdr.dst_addr);
6512 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6513 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
6514 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6515 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
6516 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
6517 for (i = 0; i < size; ++i)
6518 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
6519 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6520 src_ipv4_src_ipv6.ipv6_layout.ipv6);
6521 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6522 src_ipv4_src_ipv6.ipv6_layout.ipv6);
6523 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
6524 for (i = 0; i < size; ++i)
6525 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
6527 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
6528 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
6529 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
6530 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
6531 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
6532 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
6535 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
6537 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
6540 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
6542 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
6546 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
6548 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6549 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
6551 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
6552 ipv6_m->hdr.hop_limits);
6553 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
6554 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
6558 * Add TCP item to matcher and to the value.
6560 * @param[in, out] matcher
6562 * @param[in, out] key
6563 * Flow matcher value.
6565 * Flow pattern to translate.
6567 * Item is inner pattern.
6570 flow_dv_translate_item_tcp(void *matcher, void *key,
6571 const struct rte_flow_item *item,
6574 const struct rte_flow_item_tcp *tcp_m = item->mask;
6575 const struct rte_flow_item_tcp *tcp_v = item->spec;
6580 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6582 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6584 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6586 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6588 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6589 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
6593 tcp_m = &rte_flow_item_tcp_mask;
6594 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
6595 rte_be_to_cpu_16(tcp_m->hdr.src_port));
6596 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
6597 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
6598 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
6599 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
6600 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
6601 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
6602 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
6603 tcp_m->hdr.tcp_flags);
6604 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
6605 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
6609 * Add UDP item to matcher and to the value.
6611 * @param[in, out] matcher
6613 * @param[in, out] key
6614 * Flow matcher value.
6616 * Flow pattern to translate.
6618 * Item is inner pattern.
6621 flow_dv_translate_item_udp(void *matcher, void *key,
6622 const struct rte_flow_item *item,
6625 const struct rte_flow_item_udp *udp_m = item->mask;
6626 const struct rte_flow_item_udp *udp_v = item->spec;
6631 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6633 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6635 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6637 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6639 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6640 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
6644 udp_m = &rte_flow_item_udp_mask;
6645 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
6646 rte_be_to_cpu_16(udp_m->hdr.src_port));
6647 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
6648 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
6649 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
6650 rte_be_to_cpu_16(udp_m->hdr.dst_port));
6651 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
6652 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
6656 * Add GRE optional Key item to matcher and to the value.
6658 * @param[in, out] matcher
6660 * @param[in, out] key
6661 * Flow matcher value.
6663 * Flow pattern to translate.
6665 * Item is inner pattern.
6668 flow_dv_translate_item_gre_key(void *matcher, void *key,
6669 const struct rte_flow_item *item)
6671 const rte_be32_t *key_m = item->mask;
6672 const rte_be32_t *key_v = item->spec;
6673 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6674 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6675 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6677 /* GRE K bit must be on and should already be validated */
6678 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
6679 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
6683 key_m = &gre_key_default_mask;
6684 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
6685 rte_be_to_cpu_32(*key_m) >> 8);
6686 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
6687 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
6688 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
6689 rte_be_to_cpu_32(*key_m) & 0xFF);
6690 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
6691 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
6695 * Add GRE item to matcher and to the value.
6697 * @param[in, out] matcher
6699 * @param[in, out] key
6700 * Flow matcher value.
6702 * Flow pattern to translate.
6704 * Item is inner pattern.
6707 flow_dv_translate_item_gre(void *matcher, void *key,
6708 const struct rte_flow_item *item,
6711 const struct rte_flow_item_gre *gre_m = item->mask;
6712 const struct rte_flow_item_gre *gre_v = item->spec;
6715 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6716 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6723 uint16_t s_present:1;
6724 uint16_t k_present:1;
6725 uint16_t rsvd_bit1:1;
6726 uint16_t c_present:1;
6730 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
6733 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6735 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6737 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6739 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6741 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6742 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
6746 gre_m = &rte_flow_item_gre_mask;
6747 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
6748 rte_be_to_cpu_16(gre_m->protocol));
6749 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
6750 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
6751 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
6752 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
6753 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
6754 gre_crks_rsvd0_ver_m.c_present);
6755 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
6756 gre_crks_rsvd0_ver_v.c_present &
6757 gre_crks_rsvd0_ver_m.c_present);
6758 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
6759 gre_crks_rsvd0_ver_m.k_present);
6760 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
6761 gre_crks_rsvd0_ver_v.k_present &
6762 gre_crks_rsvd0_ver_m.k_present);
6763 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
6764 gre_crks_rsvd0_ver_m.s_present);
6765 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
6766 gre_crks_rsvd0_ver_v.s_present &
6767 gre_crks_rsvd0_ver_m.s_present);
6771 * Add NVGRE item to matcher and to the value.
6773 * @param[in, out] matcher
6775 * @param[in, out] key
6776 * Flow matcher value.
6778 * Flow pattern to translate.
6780 * Item is inner pattern.
6783 flow_dv_translate_item_nvgre(void *matcher, void *key,
6784 const struct rte_flow_item *item,
6787 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
6788 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
6789 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6790 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6791 const char *tni_flow_id_m;
6792 const char *tni_flow_id_v;
6798 /* For NVGRE, GRE header fields must be set with defined values. */
6799 const struct rte_flow_item_gre gre_spec = {
6800 .c_rsvd0_ver = RTE_BE16(0x2000),
6801 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
6803 const struct rte_flow_item_gre gre_mask = {
6804 .c_rsvd0_ver = RTE_BE16(0xB000),
6805 .protocol = RTE_BE16(UINT16_MAX),
6807 const struct rte_flow_item gre_item = {
6812 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
6816 nvgre_m = &rte_flow_item_nvgre_mask;
6817 tni_flow_id_m = (const char *)nvgre_m->tni;
6818 tni_flow_id_v = (const char *)nvgre_v->tni;
6819 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
6820 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
6821 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
6822 memcpy(gre_key_m, tni_flow_id_m, size);
6823 for (i = 0; i < size; ++i)
6824 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
6828 * Add VXLAN item to matcher and to the value.
6830 * @param[in, out] matcher
6832 * @param[in, out] key
6833 * Flow matcher value.
6835 * Flow pattern to translate.
6837 * Item is inner pattern.
6840 flow_dv_translate_item_vxlan(void *matcher, void *key,
6841 const struct rte_flow_item *item,
6844 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
6845 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
6848 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6849 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6857 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6859 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6861 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6863 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6865 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
6866 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
6867 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6868 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6869 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6874 vxlan_m = &rte_flow_item_vxlan_mask;
6875 size = sizeof(vxlan_m->vni);
6876 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
6877 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
6878 memcpy(vni_m, vxlan_m->vni, size);
6879 for (i = 0; i < size; ++i)
6880 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
6884 * Add VXLAN-GPE item to matcher and to the value.
6886 * @param[in, out] matcher
6888 * @param[in, out] key
6889 * Flow matcher value.
6891 * Flow pattern to translate.
6893 * Item is inner pattern.
6897 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
6898 const struct rte_flow_item *item, int inner)
6900 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
6901 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
6905 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
6907 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
6913 uint8_t flags_m = 0xff;
6914 uint8_t flags_v = 0xc;
6917 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6919 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6921 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6923 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6925 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
6926 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
6927 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6928 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6929 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
6934 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
6935 size = sizeof(vxlan_m->vni);
6936 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
6937 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
6938 memcpy(vni_m, vxlan_m->vni, size);
6939 for (i = 0; i < size; ++i)
6940 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
6941 if (vxlan_m->flags) {
6942 flags_m = vxlan_m->flags;
6943 flags_v = vxlan_v->flags;
6945 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
6946 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
6947 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
6949 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
6954 * Add Geneve item to matcher and to the value.
6956 * @param[in, out] matcher
6958 * @param[in, out] key
6959 * Flow matcher value.
6961 * Flow pattern to translate.
6963 * Item is inner pattern.
6967 flow_dv_translate_item_geneve(void *matcher, void *key,
6968 const struct rte_flow_item *item, int inner)
6970 const struct rte_flow_item_geneve *geneve_m = item->mask;
6971 const struct rte_flow_item_geneve *geneve_v = item->spec;
6974 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6975 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6984 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6986 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6988 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6990 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6992 dport = MLX5_UDP_PORT_GENEVE;
6993 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
6994 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
6995 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
7000 geneve_m = &rte_flow_item_geneve_mask;
7001 size = sizeof(geneve_m->vni);
7002 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
7003 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
7004 memcpy(vni_m, geneve_m->vni, size);
7005 for (i = 0; i < size; ++i)
7006 vni_v[i] = vni_m[i] & geneve_v->vni[i];
7007 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
7008 rte_be_to_cpu_16(geneve_m->protocol));
7009 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
7010 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
7011 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
7012 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
7013 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
7014 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
7015 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
7016 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
7017 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
7018 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
7019 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
7020 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
7021 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
7025 * Add MPLS item to matcher and to the value.
7027 * @param[in, out] matcher
7029 * @param[in, out] key
7030 * Flow matcher value.
7032 * Flow pattern to translate.
7033 * @param[in] prev_layer
7034 * The protocol layer indicated in previous item.
7036 * Item is inner pattern.
7039 flow_dv_translate_item_mpls(void *matcher, void *key,
7040 const struct rte_flow_item *item,
7041 uint64_t prev_layer,
7044 const uint32_t *in_mpls_m = item->mask;
7045 const uint32_t *in_mpls_v = item->spec;
7046 uint32_t *out_mpls_m = 0;
7047 uint32_t *out_mpls_v = 0;
7048 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7049 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7050 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
7052 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
7053 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
7054 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7056 switch (prev_layer) {
7057 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
7058 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
7059 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
7060 MLX5_UDP_PORT_MPLS);
7062 case MLX5_FLOW_LAYER_GRE:
7063 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
7064 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
7065 RTE_ETHER_TYPE_MPLS);
7068 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
7069 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
7076 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
7077 switch (prev_layer) {
7078 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
7080 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
7081 outer_first_mpls_over_udp);
7083 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
7084 outer_first_mpls_over_udp);
7086 case MLX5_FLOW_LAYER_GRE:
7088 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
7089 outer_first_mpls_over_gre);
7091 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
7092 outer_first_mpls_over_gre);
7095 /* Inner MPLS not over GRE is not supported. */
7098 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
7102 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
7108 if (out_mpls_m && out_mpls_v) {
7109 *out_mpls_m = *in_mpls_m;
7110 *out_mpls_v = *in_mpls_v & *in_mpls_m;
7115 * Add metadata register item to matcher
7117 * @param[in, out] matcher
7119 * @param[in, out] key
7120 * Flow matcher value.
7121 * @param[in] reg_type
7122 * Type of device metadata register
7129 flow_dv_match_meta_reg(void *matcher, void *key,
7130 enum modify_reg reg_type,
7131 uint32_t data, uint32_t mask)
7134 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
7136 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
7142 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
7143 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
7146 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
7147 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
7151 * The metadata register C0 field might be divided into
7152 * source vport index and META item value, we should set
7153 * this field according to specified mask, not as whole one.
7155 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
7157 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
7158 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
7161 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
7164 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
7165 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
7168 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
7169 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
7172 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
7173 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
7176 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
7177 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
7180 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
7181 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
7184 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
7185 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
7188 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
7189 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
7198 * Add MARK item to matcher
7201 * The device to configure through.
7202 * @param[in, out] matcher
7204 * @param[in, out] key
7205 * Flow matcher value.
7207 * Flow pattern to translate.
7210 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
7211 void *matcher, void *key,
7212 const struct rte_flow_item *item)
7214 struct mlx5_priv *priv = dev->data->dev_private;
7215 const struct rte_flow_item_mark *mark;
7219 mark = item->mask ? (const void *)item->mask :
7220 &rte_flow_item_mark_mask;
7221 mask = mark->id & priv->sh->dv_mark_mask;
7222 mark = (const void *)item->spec;
7224 value = mark->id & priv->sh->dv_mark_mask & mask;
7226 enum modify_reg reg;
7228 /* Get the metadata register index for the mark. */
7229 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
7230 MLX5_ASSERT(reg > 0);
7231 if (reg == REG_C_0) {
7232 struct mlx5_priv *priv = dev->data->dev_private;
7233 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
7234 uint32_t shl_c0 = rte_bsf32(msk_c0);
7240 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
7245 * Add META item to matcher
7248 * The devich to configure through.
7249 * @param[in, out] matcher
7251 * @param[in, out] key
7252 * Flow matcher value.
7254 * Attributes of flow that includes this item.
7256 * Flow pattern to translate.
7259 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
7260 void *matcher, void *key,
7261 const struct rte_flow_attr *attr,
7262 const struct rte_flow_item *item)
7264 const struct rte_flow_item_meta *meta_m;
7265 const struct rte_flow_item_meta *meta_v;
7267 meta_m = (const void *)item->mask;
7269 meta_m = &rte_flow_item_meta_mask;
7270 meta_v = (const void *)item->spec;
7273 uint32_t value = meta_v->data;
7274 uint32_t mask = meta_m->data;
7276 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
7280 * In datapath code there is no endianness
7281 * coversions for perfromance reasons, all
7282 * pattern conversions are done in rte_flow.
7284 value = rte_cpu_to_be_32(value);
7285 mask = rte_cpu_to_be_32(mask);
7286 if (reg == REG_C_0) {
7287 struct mlx5_priv *priv = dev->data->dev_private;
7288 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
7289 uint32_t shl_c0 = rte_bsf32(msk_c0);
7290 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
7291 uint32_t shr_c0 = __builtin_clz(priv->sh->dv_meta_mask);
7298 MLX5_ASSERT(msk_c0);
7299 MLX5_ASSERT(!(~msk_c0 & mask));
7301 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
7306 * Add vport metadata Reg C0 item to matcher
7308 * @param[in, out] matcher
7310 * @param[in, out] key
7311 * Flow matcher value.
7313 * Flow pattern to translate.
7316 flow_dv_translate_item_meta_vport(void *matcher, void *key,
7317 uint32_t value, uint32_t mask)
7319 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
7323 * Add tag item to matcher
7326 * The devich to configure through.
7327 * @param[in, out] matcher
7329 * @param[in, out] key
7330 * Flow matcher value.
7332 * Flow pattern to translate.
7335 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
7336 void *matcher, void *key,
7337 const struct rte_flow_item *item)
7339 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
7340 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
7341 uint32_t mask, value;
7344 value = tag_v->data;
7345 mask = tag_m ? tag_m->data : UINT32_MAX;
7346 if (tag_v->id == REG_C_0) {
7347 struct mlx5_priv *priv = dev->data->dev_private;
7348 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
7349 uint32_t shl_c0 = rte_bsf32(msk_c0);
7355 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
7359 * Add TAG item to matcher
7362 * The devich to configure through.
7363 * @param[in, out] matcher
7365 * @param[in, out] key
7366 * Flow matcher value.
7368 * Flow pattern to translate.
7371 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
7372 void *matcher, void *key,
7373 const struct rte_flow_item *item)
7375 const struct rte_flow_item_tag *tag_v = item->spec;
7376 const struct rte_flow_item_tag *tag_m = item->mask;
7377 enum modify_reg reg;
7380 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
7381 /* Get the metadata register index for the tag. */
7382 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
7383 MLX5_ASSERT(reg > 0);
7384 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
7388 * Add source vport match to the specified matcher.
7390 * @param[in, out] matcher
7392 * @param[in, out] key
7393 * Flow matcher value.
7395 * Source vport value to match
7400 flow_dv_translate_item_source_vport(void *matcher, void *key,
7401 int16_t port, uint16_t mask)
7403 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7404 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7406 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
7407 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
7411 * Translate port-id item to eswitch match on port-id.
7414 * The devich to configure through.
7415 * @param[in, out] matcher
7417 * @param[in, out] key
7418 * Flow matcher value.
7420 * Flow pattern to translate.
7423 * 0 on success, a negative errno value otherwise.
7426 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
7427 void *key, const struct rte_flow_item *item)
7429 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
7430 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
7431 struct mlx5_priv *priv;
7434 mask = pid_m ? pid_m->id : 0xffff;
7435 id = pid_v ? pid_v->id : dev->data->port_id;
7436 priv = mlx5_port_to_eswitch_info(id, item == NULL);
7439 /* Translate to vport field or to metadata, depending on mode. */
7440 if (priv->vport_meta_mask)
7441 flow_dv_translate_item_meta_vport(matcher, key,
7442 priv->vport_meta_tag,
7443 priv->vport_meta_mask);
7445 flow_dv_translate_item_source_vport(matcher, key,
7446 priv->vport_id, mask);
7451 * Add ICMP6 item to matcher and to the value.
7453 * @param[in, out] matcher
7455 * @param[in, out] key
7456 * Flow matcher value.
7458 * Flow pattern to translate.
7460 * Item is inner pattern.
7463 flow_dv_translate_item_icmp6(void *matcher, void *key,
7464 const struct rte_flow_item *item,
7467 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
7468 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
7471 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7473 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7475 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7477 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7479 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7481 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7483 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
7484 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
7488 icmp6_m = &rte_flow_item_icmp6_mask;
7490 * Force flow only to match the non-fragmented IPv6 ICMPv6 packets.
7491 * If only the protocol is specified, no need to match the frag.
7493 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
7494 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
7495 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
7496 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
7497 icmp6_v->type & icmp6_m->type);
7498 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
7499 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
7500 icmp6_v->code & icmp6_m->code);
7504 * Add ICMP item to matcher and to the value.
7506 * @param[in, out] matcher
7508 * @param[in, out] key
7509 * Flow matcher value.
7511 * Flow pattern to translate.
7513 * Item is inner pattern.
7516 flow_dv_translate_item_icmp(void *matcher, void *key,
7517 const struct rte_flow_item *item,
7520 const struct rte_flow_item_icmp *icmp_m = item->mask;
7521 const struct rte_flow_item_icmp *icmp_v = item->spec;
7522 uint32_t icmp_header_data_m = 0;
7523 uint32_t icmp_header_data_v = 0;
7526 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7528 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7530 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7532 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7534 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7536 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7538 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
7539 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
7543 icmp_m = &rte_flow_item_icmp_mask;
7545 * Force flow only to match the non-fragmented IPv4 ICMP packets.
7546 * If only the protocol is specified, no need to match the frag.
7548 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
7549 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
7550 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
7551 icmp_m->hdr.icmp_type);
7552 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
7553 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
7554 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
7555 icmp_m->hdr.icmp_code);
7556 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
7557 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
7558 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
7559 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
7560 if (icmp_header_data_m) {
7561 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
7562 icmp_header_data_v |=
7563 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
7564 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
7565 icmp_header_data_m);
7566 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
7567 icmp_header_data_v & icmp_header_data_m);
7572 * Add GTP item to matcher and to the value.
7574 * @param[in, out] matcher
7576 * @param[in, out] key
7577 * Flow matcher value.
7579 * Flow pattern to translate.
7581 * Item is inner pattern.
7584 flow_dv_translate_item_gtp(void *matcher, void *key,
7585 const struct rte_flow_item *item, int inner)
7587 const struct rte_flow_item_gtp *gtp_m = item->mask;
7588 const struct rte_flow_item_gtp *gtp_v = item->spec;
7591 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7593 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7594 uint16_t dport = RTE_GTPU_UDP_PORT;
7597 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7599 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7601 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7603 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7605 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
7606 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
7607 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
7612 gtp_m = &rte_flow_item_gtp_mask;
7613 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
7614 gtp_m->v_pt_rsv_flags);
7615 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
7616 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
7617 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
7618 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
7619 gtp_v->msg_type & gtp_m->msg_type);
7620 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
7621 rte_be_to_cpu_32(gtp_m->teid));
7622 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
7623 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
7627 * Add eCPRI item to matcher and to the value.
7630 * The devich to configure through.
7631 * @param[in, out] matcher
7633 * @param[in, out] key
7634 * Flow matcher value.
7636 * Flow pattern to translate.
7637 * @param[in] samples
7638 * Sample IDs to be used in the matching.
7641 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
7642 void *key, const struct rte_flow_item *item)
7644 struct mlx5_priv *priv = dev->data->dev_private;
7645 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
7646 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
7647 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
7649 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
7657 ecpri_m = &rte_flow_item_ecpri_mask;
7659 * Maximal four DW samples are supported in a single matching now.
7660 * Two are used now for a eCPRI matching:
7661 * 1. Type: one byte, mask should be 0x00ff0000 in network order
7662 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
7665 if (!ecpri_m->hdr.common.u32)
7667 samples = priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0].ids;
7668 /* Need to take the whole DW as the mask to fill the entry. */
7669 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
7670 prog_sample_field_value_0);
7671 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
7672 prog_sample_field_value_0);
7673 /* Already big endian (network order) in the header. */
7674 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
7675 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32;
7676 /* Sample#0, used for matching type, offset 0. */
7677 MLX5_SET(fte_match_set_misc4, misc4_m,
7678 prog_sample_field_id_0, samples[0]);
7679 /* It makes no sense to set the sample ID in the mask field. */
7680 MLX5_SET(fte_match_set_misc4, misc4_v,
7681 prog_sample_field_id_0, samples[0]);
7683 * Checking if message body part needs to be matched.
7684 * Some wildcard rules only matching type field should be supported.
7686 if (ecpri_m->hdr.dummy[0]) {
7687 switch (ecpri_v->hdr.common.type) {
7688 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
7689 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
7690 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
7691 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
7692 prog_sample_field_value_1);
7693 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
7694 prog_sample_field_value_1);
7695 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
7696 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0];
7697 /* Sample#1, to match message body, offset 4. */
7698 MLX5_SET(fte_match_set_misc4, misc4_m,
7699 prog_sample_field_id_1, samples[1]);
7700 MLX5_SET(fte_match_set_misc4, misc4_v,
7701 prog_sample_field_id_1, samples[1]);
7704 /* Others, do not match any sample ID. */
7710 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
7712 #define HEADER_IS_ZERO(match_criteria, headers) \
7713 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
7714 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
7717 * Calculate flow matcher enable bitmap.
7719 * @param match_criteria
7720 * Pointer to flow matcher criteria.
7723 * Bitmap of enabled fields.
7726 flow_dv_matcher_enable(uint32_t *match_criteria)
7728 uint8_t match_criteria_enable;
7730 match_criteria_enable =
7731 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
7732 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
7733 match_criteria_enable |=
7734 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
7735 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
7736 match_criteria_enable |=
7737 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
7738 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
7739 match_criteria_enable |=
7740 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
7741 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
7742 match_criteria_enable |=
7743 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
7744 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
7745 match_criteria_enable |=
7746 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
7747 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
7748 return match_criteria_enable;
7755 * @param[in, out] dev
7756 * Pointer to rte_eth_dev structure.
7757 * @param[in] table_id
7760 * Direction of the table.
7761 * @param[in] transfer
7762 * E-Switch or NIC flow.
7764 * pointer to error structure.
7767 * Returns tables resource based on the index, NULL in case of failed.
7769 static struct mlx5_flow_tbl_resource *
7770 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
7771 uint32_t table_id, uint8_t egress,
7773 struct rte_flow_error *error)
7775 struct mlx5_priv *priv = dev->data->dev_private;
7776 struct mlx5_dev_ctx_shared *sh = priv->sh;
7777 struct mlx5_flow_tbl_resource *tbl;
7778 union mlx5_flow_tbl_key table_key = {
7780 .table_id = table_id,
7782 .domain = !!transfer,
7783 .direction = !!egress,
7786 struct mlx5_hlist_entry *pos = mlx5_hlist_lookup(sh->flow_tbls,
7788 struct mlx5_flow_tbl_data_entry *tbl_data;
7794 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
7796 tbl = &tbl_data->tbl;
7797 rte_atomic32_inc(&tbl->refcnt);
7800 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
7802 rte_flow_error_set(error, ENOMEM,
7803 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7805 "cannot allocate flow table data entry");
7808 tbl_data->idx = idx;
7809 tbl = &tbl_data->tbl;
7810 pos = &tbl_data->entry;
7812 domain = sh->fdb_domain;
7814 domain = sh->tx_domain;
7816 domain = sh->rx_domain;
7817 ret = mlx5_flow_os_create_flow_tbl(domain, table_id, &tbl->obj);
7819 rte_flow_error_set(error, ENOMEM,
7820 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7821 NULL, "cannot create flow table object");
7822 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
7826 * No multi-threads now, but still better to initialize the reference
7827 * count before insert it into the hash list.
7829 rte_atomic32_init(&tbl->refcnt);
7830 /* Jump action reference count is initialized here. */
7831 rte_atomic32_init(&tbl_data->jump.refcnt);
7832 pos->key = table_key.v64;
7833 ret = mlx5_hlist_insert(sh->flow_tbls, pos);
7835 rte_flow_error_set(error, -ret,
7836 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7837 "cannot insert flow table data entry");
7838 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
7839 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
7841 rte_atomic32_inc(&tbl->refcnt);
7846 * Release a flow table.
7849 * Pointer to rte_eth_dev structure.
7851 * Table resource to be released.
7854 * Returns 0 if table was released, else return 1;
7857 flow_dv_tbl_resource_release(struct rte_eth_dev *dev,
7858 struct mlx5_flow_tbl_resource *tbl)
7860 struct mlx5_priv *priv = dev->data->dev_private;
7861 struct mlx5_dev_ctx_shared *sh = priv->sh;
7862 struct mlx5_flow_tbl_data_entry *tbl_data =
7863 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
7867 if (rte_atomic32_dec_and_test(&tbl->refcnt)) {
7868 struct mlx5_hlist_entry *pos = &tbl_data->entry;
7870 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
7872 /* remove the entry from the hash list and free memory. */
7873 mlx5_hlist_remove(sh->flow_tbls, pos);
7874 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_JUMP],
7882 * Register the flow matcher.
7884 * @param[in, out] dev
7885 * Pointer to rte_eth_dev structure.
7886 * @param[in, out] matcher
7887 * Pointer to flow matcher.
7888 * @param[in, out] key
7889 * Pointer to flow table key.
7890 * @parm[in, out] dev_flow
7891 * Pointer to the dev_flow.
7893 * pointer to error structure.
7896 * 0 on success otherwise -errno and errno is set.
7899 flow_dv_matcher_register(struct rte_eth_dev *dev,
7900 struct mlx5_flow_dv_matcher *matcher,
7901 union mlx5_flow_tbl_key *key,
7902 struct mlx5_flow *dev_flow,
7903 struct rte_flow_error *error)
7905 struct mlx5_priv *priv = dev->data->dev_private;
7906 struct mlx5_dev_ctx_shared *sh = priv->sh;
7907 struct mlx5_flow_dv_matcher *cache_matcher;
7908 struct mlx5dv_flow_matcher_attr dv_attr = {
7909 .type = IBV_FLOW_ATTR_NORMAL,
7910 .match_mask = (void *)&matcher->mask,
7912 struct mlx5_flow_tbl_resource *tbl;
7913 struct mlx5_flow_tbl_data_entry *tbl_data;
7916 tbl = flow_dv_tbl_resource_get(dev, key->table_id, key->direction,
7917 key->domain, error);
7919 return -rte_errno; /* No need to refill the error info */
7920 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
7921 /* Lookup from cache. */
7922 LIST_FOREACH(cache_matcher, &tbl_data->matchers, next) {
7923 if (matcher->crc == cache_matcher->crc &&
7924 matcher->priority == cache_matcher->priority &&
7925 !memcmp((const void *)matcher->mask.buf,
7926 (const void *)cache_matcher->mask.buf,
7927 cache_matcher->mask.size)) {
7929 "%s group %u priority %hd use %s "
7930 "matcher %p: refcnt %d++",
7931 key->domain ? "FDB" : "NIC", key->table_id,
7932 cache_matcher->priority,
7933 key->direction ? "tx" : "rx",
7934 (void *)cache_matcher,
7935 rte_atomic32_read(&cache_matcher->refcnt));
7936 rte_atomic32_inc(&cache_matcher->refcnt);
7937 dev_flow->handle->dvh.matcher = cache_matcher;
7938 /* old matcher should not make the table ref++. */
7939 flow_dv_tbl_resource_release(dev, tbl);
7943 /* Register new matcher. */
7944 cache_matcher = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*cache_matcher), 0,
7946 if (!cache_matcher) {
7947 flow_dv_tbl_resource_release(dev, tbl);
7948 return rte_flow_error_set(error, ENOMEM,
7949 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7950 "cannot allocate matcher memory");
7952 *cache_matcher = *matcher;
7953 dv_attr.match_criteria_enable =
7954 flow_dv_matcher_enable(cache_matcher->mask.buf);
7955 dv_attr.priority = matcher->priority;
7957 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
7958 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
7959 &cache_matcher->matcher_object);
7961 mlx5_free(cache_matcher);
7962 #ifdef HAVE_MLX5DV_DR
7963 flow_dv_tbl_resource_release(dev, tbl);
7965 return rte_flow_error_set(error, ENOMEM,
7966 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7967 NULL, "cannot create matcher");
7969 /* Save the table information */
7970 cache_matcher->tbl = tbl;
7971 rte_atomic32_init(&cache_matcher->refcnt);
7972 /* only matcher ref++, table ref++ already done above in get API. */
7973 rte_atomic32_inc(&cache_matcher->refcnt);
7974 LIST_INSERT_HEAD(&tbl_data->matchers, cache_matcher, next);
7975 dev_flow->handle->dvh.matcher = cache_matcher;
7976 DRV_LOG(DEBUG, "%s group %u priority %hd new %s matcher %p: refcnt %d",
7977 key->domain ? "FDB" : "NIC", key->table_id,
7978 cache_matcher->priority,
7979 key->direction ? "tx" : "rx", (void *)cache_matcher,
7980 rte_atomic32_read(&cache_matcher->refcnt));
7985 * Find existing tag resource or create and register a new one.
7987 * @param dev[in, out]
7988 * Pointer to rte_eth_dev structure.
7989 * @param[in, out] tag_be24
7990 * Tag value in big endian then R-shift 8.
7991 * @parm[in, out] dev_flow
7992 * Pointer to the dev_flow.
7994 * pointer to error structure.
7997 * 0 on success otherwise -errno and errno is set.
8000 flow_dv_tag_resource_register
8001 (struct rte_eth_dev *dev,
8003 struct mlx5_flow *dev_flow,
8004 struct rte_flow_error *error)
8006 struct mlx5_priv *priv = dev->data->dev_private;
8007 struct mlx5_dev_ctx_shared *sh = priv->sh;
8008 struct mlx5_flow_dv_tag_resource *cache_resource;
8009 struct mlx5_hlist_entry *entry;
8012 /* Lookup a matching resource from cache. */
8013 entry = mlx5_hlist_lookup(sh->tag_table, (uint64_t)tag_be24);
8015 cache_resource = container_of
8016 (entry, struct mlx5_flow_dv_tag_resource, entry);
8017 rte_atomic32_inc(&cache_resource->refcnt);
8018 dev_flow->handle->dvh.rix_tag = cache_resource->idx;
8019 dev_flow->dv.tag_resource = cache_resource;
8020 DRV_LOG(DEBUG, "cached tag resource %p: refcnt now %d++",
8021 (void *)cache_resource,
8022 rte_atomic32_read(&cache_resource->refcnt));
8025 /* Register new resource. */
8026 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG],
8027 &dev_flow->handle->dvh.rix_tag);
8028 if (!cache_resource)
8029 return rte_flow_error_set(error, ENOMEM,
8030 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8031 "cannot allocate resource memory");
8032 cache_resource->entry.key = (uint64_t)tag_be24;
8033 ret = mlx5_flow_os_create_flow_action_tag(tag_be24,
8034 &cache_resource->action);
8036 mlx5_free(cache_resource);
8037 return rte_flow_error_set(error, ENOMEM,
8038 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8039 NULL, "cannot create action");
8041 rte_atomic32_init(&cache_resource->refcnt);
8042 rte_atomic32_inc(&cache_resource->refcnt);
8043 if (mlx5_hlist_insert(sh->tag_table, &cache_resource->entry)) {
8044 mlx5_flow_os_destroy_flow_action(cache_resource->action);
8045 mlx5_free(cache_resource);
8046 return rte_flow_error_set(error, EEXIST,
8047 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8048 NULL, "cannot insert tag");
8050 dev_flow->dv.tag_resource = cache_resource;
8051 DRV_LOG(DEBUG, "new tag resource %p: refcnt now %d++",
8052 (void *)cache_resource,
8053 rte_atomic32_read(&cache_resource->refcnt));
8061 * Pointer to Ethernet device.
8066 * 1 while a reference on it exists, 0 when freed.
8069 flow_dv_tag_release(struct rte_eth_dev *dev,
8072 struct mlx5_priv *priv = dev->data->dev_private;
8073 struct mlx5_dev_ctx_shared *sh = priv->sh;
8074 struct mlx5_flow_dv_tag_resource *tag;
8076 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
8079 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
8080 dev->data->port_id, (void *)tag,
8081 rte_atomic32_read(&tag->refcnt));
8082 if (rte_atomic32_dec_and_test(&tag->refcnt)) {
8083 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
8084 mlx5_hlist_remove(sh->tag_table, &tag->entry);
8085 DRV_LOG(DEBUG, "port %u tag %p: removed",
8086 dev->data->port_id, (void *)tag);
8087 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
8094 * Translate port ID action to vport.
8097 * Pointer to rte_eth_dev structure.
8099 * Pointer to the port ID action.
8100 * @param[out] dst_port_id
8101 * The target port ID.
8103 * Pointer to the error structure.
8106 * 0 on success, a negative errno value otherwise and rte_errno is set.
8109 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
8110 const struct rte_flow_action *action,
8111 uint32_t *dst_port_id,
8112 struct rte_flow_error *error)
8115 struct mlx5_priv *priv;
8116 const struct rte_flow_action_port_id *conf =
8117 (const struct rte_flow_action_port_id *)action->conf;
8119 port = conf->original ? dev->data->port_id : conf->id;
8120 priv = mlx5_port_to_eswitch_info(port, false);
8122 return rte_flow_error_set(error, -rte_errno,
8123 RTE_FLOW_ERROR_TYPE_ACTION,
8125 "No eswitch info was found for port");
8126 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
8128 * This parameter is transferred to
8129 * mlx5dv_dr_action_create_dest_ib_port().
8131 *dst_port_id = priv->dev_port;
8134 * Legacy mode, no LAG configurations is supported.
8135 * This parameter is transferred to
8136 * mlx5dv_dr_action_create_dest_vport().
8138 *dst_port_id = priv->vport_id;
8144 * Create a counter with aging configuration.
8147 * Pointer to rte_eth_dev structure.
8149 * Pointer to the counter action configuration.
8151 * Pointer to the aging action configuration.
8154 * Index to flow counter on success, 0 otherwise.
8157 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
8158 struct mlx5_flow *dev_flow,
8159 const struct rte_flow_action_count *count,
8160 const struct rte_flow_action_age *age)
8163 struct mlx5_age_param *age_param;
8165 counter = flow_dv_counter_alloc(dev,
8166 count ? count->shared : 0,
8167 count ? count->id : 0,
8168 dev_flow->dv.group, !!age);
8169 if (!counter || age == NULL)
8171 age_param = flow_dv_counter_idx_get_age(dev, counter);
8173 * The counter age accuracy may have a bit delay. Have 3/4
8174 * second bias on the timeount in order to let it age in time.
8176 age_param->context = age->context ? age->context :
8177 (void *)(uintptr_t)(dev_flow->flow_idx);
8179 * The counter age accuracy may have a bit delay. Have 3/4
8180 * second bias on the timeount in order to let it age in time.
8182 age_param->timeout = age->timeout * 10 - MLX5_AGING_TIME_DELAY;
8183 /* Set expire time in unit of 0.1 sec. */
8184 age_param->port_id = dev->data->port_id;
8185 age_param->expire = age_param->timeout +
8186 rte_rdtsc() / (rte_get_tsc_hz() / 10);
8187 rte_atomic16_set(&age_param->state, AGE_CANDIDATE);
8191 * Add Tx queue matcher
8194 * Pointer to the dev struct.
8195 * @param[in, out] matcher
8197 * @param[in, out] key
8198 * Flow matcher value.
8200 * Flow pattern to translate.
8202 * Item is inner pattern.
8205 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
8206 void *matcher, void *key,
8207 const struct rte_flow_item *item)
8209 const struct mlx5_rte_flow_item_tx_queue *queue_m;
8210 const struct mlx5_rte_flow_item_tx_queue *queue_v;
8212 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8214 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8215 struct mlx5_txq_ctrl *txq;
8219 queue_m = (const void *)item->mask;
8222 queue_v = (const void *)item->spec;
8225 txq = mlx5_txq_get(dev, queue_v->queue);
8228 queue = txq->obj->sq->id;
8229 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
8230 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
8231 queue & queue_m->queue);
8232 mlx5_txq_release(dev, queue_v->queue);
8236 * Set the hash fields according to the @p flow information.
8238 * @param[in] dev_flow
8239 * Pointer to the mlx5_flow.
8240 * @param[in] rss_desc
8241 * Pointer to the mlx5_flow_rss_desc.
8244 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
8245 struct mlx5_flow_rss_desc *rss_desc)
8247 uint64_t items = dev_flow->handle->layers;
8249 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
8251 dev_flow->hash_fields = 0;
8252 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
8253 if (rss_desc->level >= 2) {
8254 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
8258 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
8259 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
8260 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
8261 if (rss_types & ETH_RSS_L3_SRC_ONLY)
8262 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
8263 else if (rss_types & ETH_RSS_L3_DST_ONLY)
8264 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
8266 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
8268 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
8269 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
8270 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
8271 if (rss_types & ETH_RSS_L3_SRC_ONLY)
8272 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
8273 else if (rss_types & ETH_RSS_L3_DST_ONLY)
8274 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
8276 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
8279 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
8280 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
8281 if (rss_types & ETH_RSS_UDP) {
8282 if (rss_types & ETH_RSS_L4_SRC_ONLY)
8283 dev_flow->hash_fields |=
8284 IBV_RX_HASH_SRC_PORT_UDP;
8285 else if (rss_types & ETH_RSS_L4_DST_ONLY)
8286 dev_flow->hash_fields |=
8287 IBV_RX_HASH_DST_PORT_UDP;
8289 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
8291 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
8292 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
8293 if (rss_types & ETH_RSS_TCP) {
8294 if (rss_types & ETH_RSS_L4_SRC_ONLY)
8295 dev_flow->hash_fields |=
8296 IBV_RX_HASH_SRC_PORT_TCP;
8297 else if (rss_types & ETH_RSS_L4_DST_ONLY)
8298 dev_flow->hash_fields |=
8299 IBV_RX_HASH_DST_PORT_TCP;
8301 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
8307 * Create an Rx Hash queue.
8310 * Pointer to Ethernet device.
8311 * @param[in] dev_flow
8312 * Pointer to the mlx5_flow.
8313 * @param[in] rss_desc
8314 * Pointer to the mlx5_flow_rss_desc.
8315 * @param[out] hrxq_idx
8316 * Hash Rx queue index.
8319 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
8321 static struct mlx5_hrxq *
8322 flow_dv_handle_rx_queue(struct rte_eth_dev *dev,
8323 struct mlx5_flow *dev_flow,
8324 struct mlx5_flow_rss_desc *rss_desc,
8327 struct mlx5_priv *priv = dev->data->dev_private;
8328 struct mlx5_flow_handle *dh = dev_flow->handle;
8329 struct mlx5_hrxq *hrxq;
8331 MLX5_ASSERT(rss_desc->queue_num);
8332 *hrxq_idx = mlx5_hrxq_get(dev, rss_desc->key,
8333 MLX5_RSS_HASH_KEY_LEN,
8334 dev_flow->hash_fields,
8336 rss_desc->queue_num);
8338 *hrxq_idx = mlx5_hrxq_new
8339 (dev, rss_desc->key,
8340 MLX5_RSS_HASH_KEY_LEN,
8341 dev_flow->hash_fields,
8343 rss_desc->queue_num,
8345 MLX5_FLOW_LAYER_TUNNEL));
8349 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
8355 * Find existing sample resource or create and register a new one.
8357 * @param[in, out] dev
8358 * Pointer to rte_eth_dev structure.
8360 * Attributes of flow that includes this item.
8361 * @param[in] resource
8362 * Pointer to sample resource.
8363 * @parm[in, out] dev_flow
8364 * Pointer to the dev_flow.
8365 * @param[in, out] sample_dv_actions
8366 * Pointer to sample actions list.
8368 * pointer to error structure.
8371 * 0 on success otherwise -errno and errno is set.
8374 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
8375 const struct rte_flow_attr *attr,
8376 struct mlx5_flow_dv_sample_resource *resource,
8377 struct mlx5_flow *dev_flow,
8378 void **sample_dv_actions,
8379 struct rte_flow_error *error)
8381 struct mlx5_flow_dv_sample_resource *cache_resource;
8382 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
8383 struct mlx5_priv *priv = dev->data->dev_private;
8384 struct mlx5_dev_ctx_shared *sh = priv->sh;
8385 struct mlx5_flow_tbl_resource *tbl;
8387 const uint32_t next_ft_step = 1;
8388 uint32_t next_ft_id = resource->ft_id + next_ft_step;
8390 /* Lookup a matching resource from cache. */
8391 ILIST_FOREACH(sh->ipool[MLX5_IPOOL_SAMPLE], sh->sample_action_list,
8392 idx, cache_resource, next) {
8393 if (resource->ratio == cache_resource->ratio &&
8394 resource->ft_type == cache_resource->ft_type &&
8395 resource->ft_id == cache_resource->ft_id &&
8396 resource->set_action == cache_resource->set_action &&
8397 !memcmp((void *)&resource->sample_act,
8398 (void *)&cache_resource->sample_act,
8399 sizeof(struct mlx5_flow_sub_actions_list))) {
8400 DRV_LOG(DEBUG, "sample resource %p: refcnt %d++",
8401 (void *)cache_resource,
8402 __atomic_load_n(&cache_resource->refcnt,
8404 __atomic_fetch_add(&cache_resource->refcnt, 1,
8406 dev_flow->handle->dvh.rix_sample = idx;
8407 dev_flow->dv.sample_res = cache_resource;
8411 /* Register new sample resource. */
8412 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE],
8413 &dev_flow->handle->dvh.rix_sample);
8414 if (!cache_resource)
8415 return rte_flow_error_set(error, ENOMEM,
8416 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8418 "cannot allocate resource memory");
8419 *cache_resource = *resource;
8420 /* Create normal path table level */
8421 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
8422 attr->egress, attr->transfer, error);
8424 rte_flow_error_set(error, ENOMEM,
8425 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8427 "fail to create normal path table "
8431 cache_resource->normal_path_tbl = tbl;
8432 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
8433 cache_resource->default_miss =
8434 mlx5_glue->dr_create_flow_action_default_miss();
8435 if (!cache_resource->default_miss) {
8436 rte_flow_error_set(error, ENOMEM,
8437 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8439 "cannot create default miss "
8443 sample_dv_actions[resource->sample_act.actions_num++] =
8444 cache_resource->default_miss;
8446 /* Create a DR sample action */
8447 sampler_attr.sample_ratio = cache_resource->ratio;
8448 sampler_attr.default_next_table = tbl->obj;
8449 sampler_attr.num_sample_actions = resource->sample_act.actions_num;
8450 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
8451 &sample_dv_actions[0];
8452 sampler_attr.action = cache_resource->set_action;
8453 cache_resource->verbs_action =
8454 mlx5_glue->dr_create_flow_action_sampler(&sampler_attr);
8455 if (!cache_resource->verbs_action) {
8456 rte_flow_error_set(error, ENOMEM,
8457 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8458 NULL, "cannot create sample action");
8461 __atomic_store_n(&cache_resource->refcnt, 1, __ATOMIC_RELAXED);
8462 ILIST_INSERT(sh->ipool[MLX5_IPOOL_SAMPLE], &sh->sample_action_list,
8463 dev_flow->handle->dvh.rix_sample, cache_resource,
8465 dev_flow->dv.sample_res = cache_resource;
8466 DRV_LOG(DEBUG, "new sample resource %p: refcnt %d++",
8467 (void *)cache_resource,
8468 __atomic_load_n(&cache_resource->refcnt, __ATOMIC_RELAXED));
8471 if (cache_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
8472 if (cache_resource->default_miss)
8473 claim_zero(mlx5_glue->destroy_flow_action
8474 (cache_resource->default_miss));
8476 if (cache_resource->sample_idx.rix_hrxq &&
8477 !mlx5_hrxq_release(dev,
8478 cache_resource->sample_idx.rix_hrxq))
8479 cache_resource->sample_idx.rix_hrxq = 0;
8480 if (cache_resource->sample_idx.rix_tag &&
8481 !flow_dv_tag_release(dev,
8482 cache_resource->sample_idx.rix_tag))
8483 cache_resource->sample_idx.rix_tag = 0;
8484 if (cache_resource->sample_idx.cnt) {
8485 flow_dv_counter_release(dev,
8486 cache_resource->sample_idx.cnt);
8487 cache_resource->sample_idx.cnt = 0;
8490 if (cache_resource->normal_path_tbl)
8491 flow_dv_tbl_resource_release(dev,
8492 cache_resource->normal_path_tbl);
8493 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE],
8494 dev_flow->handle->dvh.rix_sample);
8495 dev_flow->handle->dvh.rix_sample = 0;
8500 * Convert Sample action to DV specification.
8503 * Pointer to rte_eth_dev structure.
8505 * Pointer to action structure.
8506 * @param[in, out] dev_flow
8507 * Pointer to the mlx5_flow.
8509 * Pointer to the flow attributes.
8510 * @param[in, out] sample_actions
8511 * Pointer to sample actions list.
8512 * @param[in, out] res
8513 * Pointer to sample resource.
8515 * Pointer to the error structure.
8518 * 0 on success, a negative errno value otherwise and rte_errno is set.
8521 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
8522 const struct rte_flow_action *action,
8523 struct mlx5_flow *dev_flow,
8524 const struct rte_flow_attr *attr,
8525 void **sample_actions,
8526 struct mlx5_flow_dv_sample_resource *res,
8527 struct rte_flow_error *error)
8529 struct mlx5_priv *priv = dev->data->dev_private;
8530 const struct rte_flow_action_sample *sample_action;
8531 const struct rte_flow_action *sub_actions;
8532 const struct rte_flow_action_queue *queue;
8533 struct mlx5_flow_sub_actions_list *sample_act;
8534 struct mlx5_flow_sub_actions_idx *sample_idx;
8535 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
8537 [!!priv->flow_nested_idx];
8538 uint64_t action_flags = 0;
8540 sample_act = &res->sample_act;
8541 sample_idx = &res->sample_idx;
8542 sample_action = (const struct rte_flow_action_sample *)action->conf;
8543 res->ratio = sample_action->ratio;
8544 sub_actions = sample_action->actions;
8545 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
8546 int type = sub_actions->type;
8547 uint32_t pre_rix = 0;
8550 case RTE_FLOW_ACTION_TYPE_QUEUE:
8552 struct mlx5_hrxq *hrxq;
8555 queue = sub_actions->conf;
8556 rss_desc->queue_num = 1;
8557 rss_desc->queue[0] = queue->index;
8558 hrxq = flow_dv_handle_rx_queue(dev, dev_flow,
8559 rss_desc, &hrxq_idx);
8561 return rte_flow_error_set
8563 RTE_FLOW_ERROR_TYPE_ACTION,
8565 "cannot create fate queue");
8566 sample_act->dr_queue_action = hrxq->action;
8567 sample_idx->rix_hrxq = hrxq_idx;
8568 sample_actions[sample_act->actions_num++] =
8570 action_flags |= MLX5_FLOW_ACTION_QUEUE;
8571 if (action_flags & MLX5_FLOW_ACTION_MARK)
8572 dev_flow->handle->rix_hrxq = hrxq_idx;
8573 dev_flow->handle->fate_action =
8574 MLX5_FLOW_FATE_QUEUE;
8577 case RTE_FLOW_ACTION_TYPE_MARK:
8579 uint32_t tag_be = mlx5_flow_mark_set
8580 (((const struct rte_flow_action_mark *)
8581 (sub_actions->conf))->id);
8582 dev_flow->handle->mark = 1;
8583 pre_rix = dev_flow->handle->dvh.rix_tag;
8584 /* Save the mark resource before sample */
8585 pre_r = dev_flow->dv.tag_resource;
8586 if (flow_dv_tag_resource_register(dev, tag_be,
8589 MLX5_ASSERT(dev_flow->dv.tag_resource);
8590 sample_act->dr_tag_action =
8591 dev_flow->dv.tag_resource->action;
8592 sample_idx->rix_tag =
8593 dev_flow->handle->dvh.rix_tag;
8594 sample_actions[sample_act->actions_num++] =
8595 sample_act->dr_tag_action;
8596 /* Recover the mark resource after sample */
8597 dev_flow->dv.tag_resource = pre_r;
8598 dev_flow->handle->dvh.rix_tag = pre_rix;
8599 action_flags |= MLX5_FLOW_ACTION_MARK;
8602 case RTE_FLOW_ACTION_TYPE_COUNT:
8606 counter = flow_dv_translate_create_counter(dev,
8607 dev_flow, sub_actions->conf, 0);
8609 return rte_flow_error_set
8611 RTE_FLOW_ERROR_TYPE_ACTION,
8613 "cannot create counter"
8615 sample_idx->cnt = counter;
8616 sample_act->dr_cnt_action =
8617 (flow_dv_counter_get_by_idx(dev,
8618 counter, NULL))->action;
8619 sample_actions[sample_act->actions_num++] =
8620 sample_act->dr_cnt_action;
8621 action_flags |= MLX5_FLOW_ACTION_COUNT;
8625 return rte_flow_error_set(error, EINVAL,
8626 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8628 "Not support for sampler action");
8631 sample_act->action_flags = action_flags;
8632 res->ft_id = dev_flow->dv.group;
8633 if (attr->transfer) {
8635 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
8636 uint64_t set_action;
8637 } action_ctx = { .set_action = 0 };
8639 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
8640 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
8641 MLX5_MODIFICATION_TYPE_SET);
8642 MLX5_SET(set_action_in, action_ctx.action_in, field,
8643 MLX5_MODI_META_REG_C_0);
8644 MLX5_SET(set_action_in, action_ctx.action_in, data,
8645 priv->vport_meta_tag);
8646 res->set_action = action_ctx.set_action;
8647 } else if (attr->ingress) {
8648 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
8654 * Convert Sample action to DV specification.
8657 * Pointer to rte_eth_dev structure.
8658 * @param[in, out] dev_flow
8659 * Pointer to the mlx5_flow.
8661 * Pointer to the flow attributes.
8662 * @param[in, out] res
8663 * Pointer to sample resource.
8664 * @param[in] sample_actions
8665 * Pointer to sample path actions list.
8667 * Pointer to the error structure.
8670 * 0 on success, a negative errno value otherwise and rte_errno is set.
8673 flow_dv_create_action_sample(struct rte_eth_dev *dev,
8674 struct mlx5_flow *dev_flow,
8675 const struct rte_flow_attr *attr,
8676 struct mlx5_flow_dv_sample_resource *res,
8677 void **sample_actions,
8678 struct rte_flow_error *error)
8680 if (flow_dv_sample_resource_register(dev, attr, res, dev_flow,
8681 sample_actions, error))
8682 return rte_flow_error_set(error, EINVAL,
8683 RTE_FLOW_ERROR_TYPE_ACTION,
8684 NULL, "can't create sample action");
8689 * Fill the flow with DV spec, lock free
8690 * (mutex should be acquired by caller).
8693 * Pointer to rte_eth_dev structure.
8694 * @param[in, out] dev_flow
8695 * Pointer to the sub flow.
8697 * Pointer to the flow attributes.
8699 * Pointer to the list of items.
8700 * @param[in] actions
8701 * Pointer to the list of actions.
8703 * Pointer to the error structure.
8706 * 0 on success, a negative errno value otherwise and rte_errno is set.
8709 __flow_dv_translate(struct rte_eth_dev *dev,
8710 struct mlx5_flow *dev_flow,
8711 const struct rte_flow_attr *attr,
8712 const struct rte_flow_item items[],
8713 const struct rte_flow_action actions[],
8714 struct rte_flow_error *error)
8716 struct mlx5_priv *priv = dev->data->dev_private;
8717 struct mlx5_dev_config *dev_conf = &priv->config;
8718 struct rte_flow *flow = dev_flow->flow;
8719 struct mlx5_flow_handle *handle = dev_flow->handle;
8720 struct mlx5_flow_rss_desc *rss_desc = &((struct mlx5_flow_rss_desc *)
8722 [!!priv->flow_nested_idx];
8723 uint64_t item_flags = 0;
8724 uint64_t last_item = 0;
8725 uint64_t action_flags = 0;
8726 uint64_t priority = attr->priority;
8727 struct mlx5_flow_dv_matcher matcher = {
8729 .size = sizeof(matcher.mask.buf) -
8730 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
8734 bool actions_end = false;
8736 struct mlx5_flow_dv_modify_hdr_resource res;
8737 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
8738 sizeof(struct mlx5_modification_cmd) *
8739 (MLX5_MAX_MODIFY_NUM + 1)];
8741 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
8742 const struct rte_flow_action_count *count = NULL;
8743 const struct rte_flow_action_age *age = NULL;
8744 union flow_dv_attr flow_attr = { .attr = 0 };
8746 union mlx5_flow_tbl_key tbl_key;
8747 uint32_t modify_action_position = UINT32_MAX;
8748 void *match_mask = matcher.mask.buf;
8749 void *match_value = dev_flow->dv.value.buf;
8750 uint8_t next_protocol = 0xff;
8751 struct rte_vlan_hdr vlan = { 0 };
8752 struct mlx5_flow_dv_sample_resource sample_res;
8753 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
8754 uint32_t sample_act_pos = UINT32_MAX;
8758 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
8759 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
8760 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
8761 ret = mlx5_flow_group_to_table(attr, dev_flow->external, attr->group,
8762 !!priv->fdb_def_rule, &table, error);
8765 dev_flow->dv.group = table;
8767 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
8768 if (priority == MLX5_FLOW_PRIO_RSVD)
8769 priority = dev_conf->flow_prio - 1;
8770 /* number of actions must be set to 0 in case of dirty stack. */
8771 mhdr_res->actions_num = 0;
8772 for (; !actions_end ; actions++) {
8773 const struct rte_flow_action_queue *queue;
8774 const struct rte_flow_action_rss *rss;
8775 const struct rte_flow_action *action = actions;
8776 const uint8_t *rss_key;
8777 const struct rte_flow_action_meter *mtr;
8778 struct mlx5_flow_tbl_resource *tbl;
8779 uint32_t port_id = 0;
8780 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
8781 int action_type = actions->type;
8782 const struct rte_flow_action *found_action = NULL;
8783 struct mlx5_flow_meter *fm = NULL;
8784 uint32_t jump_group = 0;
8786 if (!mlx5_flow_os_action_supported(action_type))
8787 return rte_flow_error_set(error, ENOTSUP,
8788 RTE_FLOW_ERROR_TYPE_ACTION,
8790 "action not supported");
8791 switch (action_type) {
8792 case RTE_FLOW_ACTION_TYPE_VOID:
8794 case RTE_FLOW_ACTION_TYPE_PORT_ID:
8795 if (flow_dv_translate_action_port_id(dev, action,
8798 port_id_resource.port_id = port_id;
8799 MLX5_ASSERT(!handle->rix_port_id_action);
8800 if (flow_dv_port_id_action_resource_register
8801 (dev, &port_id_resource, dev_flow, error))
8803 dev_flow->dv.actions[actions_n++] =
8804 dev_flow->dv.port_id_action->action;
8805 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
8806 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
8808 case RTE_FLOW_ACTION_TYPE_FLAG:
8809 action_flags |= MLX5_FLOW_ACTION_FLAG;
8810 dev_flow->handle->mark = 1;
8811 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8812 struct rte_flow_action_mark mark = {
8813 .id = MLX5_FLOW_MARK_DEFAULT,
8816 if (flow_dv_convert_action_mark(dev, &mark,
8820 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
8823 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
8825 * Only one FLAG or MARK is supported per device flow
8826 * right now. So the pointer to the tag resource must be
8827 * zero before the register process.
8829 MLX5_ASSERT(!handle->dvh.rix_tag);
8830 if (flow_dv_tag_resource_register(dev, tag_be,
8833 MLX5_ASSERT(dev_flow->dv.tag_resource);
8834 dev_flow->dv.actions[actions_n++] =
8835 dev_flow->dv.tag_resource->action;
8837 case RTE_FLOW_ACTION_TYPE_MARK:
8838 action_flags |= MLX5_FLOW_ACTION_MARK;
8839 dev_flow->handle->mark = 1;
8840 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8841 const struct rte_flow_action_mark *mark =
8842 (const struct rte_flow_action_mark *)
8845 if (flow_dv_convert_action_mark(dev, mark,
8849 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
8853 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
8854 /* Legacy (non-extensive) MARK action. */
8855 tag_be = mlx5_flow_mark_set
8856 (((const struct rte_flow_action_mark *)
8857 (actions->conf))->id);
8858 MLX5_ASSERT(!handle->dvh.rix_tag);
8859 if (flow_dv_tag_resource_register(dev, tag_be,
8862 MLX5_ASSERT(dev_flow->dv.tag_resource);
8863 dev_flow->dv.actions[actions_n++] =
8864 dev_flow->dv.tag_resource->action;
8866 case RTE_FLOW_ACTION_TYPE_SET_META:
8867 if (flow_dv_convert_action_set_meta
8868 (dev, mhdr_res, attr,
8869 (const struct rte_flow_action_set_meta *)
8870 actions->conf, error))
8872 action_flags |= MLX5_FLOW_ACTION_SET_META;
8874 case RTE_FLOW_ACTION_TYPE_SET_TAG:
8875 if (flow_dv_convert_action_set_tag
8877 (const struct rte_flow_action_set_tag *)
8878 actions->conf, error))
8880 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8882 case RTE_FLOW_ACTION_TYPE_DROP:
8883 action_flags |= MLX5_FLOW_ACTION_DROP;
8884 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
8886 case RTE_FLOW_ACTION_TYPE_QUEUE:
8887 queue = actions->conf;
8888 rss_desc->queue_num = 1;
8889 rss_desc->queue[0] = queue->index;
8890 action_flags |= MLX5_FLOW_ACTION_QUEUE;
8891 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
8893 case RTE_FLOW_ACTION_TYPE_RSS:
8894 rss = actions->conf;
8895 memcpy(rss_desc->queue, rss->queue,
8896 rss->queue_num * sizeof(uint16_t));
8897 rss_desc->queue_num = rss->queue_num;
8898 /* NULL RSS key indicates default RSS key. */
8899 rss_key = !rss->key ? rss_hash_default_key : rss->key;
8900 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
8902 * rss->level and rss.types should be set in advance
8903 * when expanding items for RSS.
8905 action_flags |= MLX5_FLOW_ACTION_RSS;
8906 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
8908 case RTE_FLOW_ACTION_TYPE_AGE:
8909 case RTE_FLOW_ACTION_TYPE_COUNT:
8910 if (!dev_conf->devx) {
8911 return rte_flow_error_set
8913 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8915 "count action not supported");
8917 /* Save information first, will apply later. */
8918 if (actions->type == RTE_FLOW_ACTION_TYPE_COUNT)
8919 count = action->conf;
8922 action_flags |= MLX5_FLOW_ACTION_COUNT;
8924 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
8925 dev_flow->dv.actions[actions_n++] =
8926 priv->sh->pop_vlan_action;
8927 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8929 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8930 if (!(action_flags &
8931 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
8932 flow_dev_get_vlan_info_from_items(items, &vlan);
8933 vlan.eth_proto = rte_be_to_cpu_16
8934 ((((const struct rte_flow_action_of_push_vlan *)
8935 actions->conf)->ethertype));
8936 found_action = mlx5_flow_find_action
8938 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
8940 mlx5_update_vlan_vid_pcp(found_action, &vlan);
8941 found_action = mlx5_flow_find_action
8943 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
8945 mlx5_update_vlan_vid_pcp(found_action, &vlan);
8946 if (flow_dv_create_action_push_vlan
8947 (dev, attr, &vlan, dev_flow, error))
8949 dev_flow->dv.actions[actions_n++] =
8950 dev_flow->dv.push_vlan_res->action;
8951 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8953 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8954 /* of_vlan_push action handled this action */
8955 MLX5_ASSERT(action_flags &
8956 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
8958 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8959 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
8961 flow_dev_get_vlan_info_from_items(items, &vlan);
8962 mlx5_update_vlan_vid_pcp(actions, &vlan);
8963 /* If no VLAN push - this is a modify header action */
8964 if (flow_dv_convert_action_modify_vlan_vid
8965 (mhdr_res, actions, error))
8967 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8969 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8970 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8971 if (flow_dv_create_action_l2_encap(dev, actions,
8976 dev_flow->dv.actions[actions_n++] =
8977 dev_flow->dv.encap_decap->action;
8978 action_flags |= MLX5_FLOW_ACTION_ENCAP;
8980 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8981 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8982 if (flow_dv_create_action_l2_decap(dev, dev_flow,
8986 dev_flow->dv.actions[actions_n++] =
8987 dev_flow->dv.encap_decap->action;
8988 action_flags |= MLX5_FLOW_ACTION_DECAP;
8990 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8991 /* Handle encap with preceding decap. */
8992 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
8993 if (flow_dv_create_action_raw_encap
8994 (dev, actions, dev_flow, attr, error))
8996 dev_flow->dv.actions[actions_n++] =
8997 dev_flow->dv.encap_decap->action;
8999 /* Handle encap without preceding decap. */
9000 if (flow_dv_create_action_l2_encap
9001 (dev, actions, dev_flow, attr->transfer,
9004 dev_flow->dv.actions[actions_n++] =
9005 dev_flow->dv.encap_decap->action;
9007 action_flags |= MLX5_FLOW_ACTION_ENCAP;
9009 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
9010 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
9012 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
9013 if (flow_dv_create_action_l2_decap
9014 (dev, dev_flow, attr->transfer, error))
9016 dev_flow->dv.actions[actions_n++] =
9017 dev_flow->dv.encap_decap->action;
9019 /* If decap is followed by encap, handle it at encap. */
9020 action_flags |= MLX5_FLOW_ACTION_DECAP;
9022 case RTE_FLOW_ACTION_TYPE_JUMP:
9023 jump_group = ((const struct rte_flow_action_jump *)
9024 action->conf)->group;
9025 if (dev_flow->external && jump_group <
9026 MLX5_MAX_TABLES_EXTERNAL)
9027 jump_group *= MLX5_FLOW_TABLE_FACTOR;
9028 ret = mlx5_flow_group_to_table(attr, dev_flow->external,
9030 !!priv->fdb_def_rule,
9034 tbl = flow_dv_tbl_resource_get(dev, table,
9036 attr->transfer, error);
9038 return rte_flow_error_set
9040 RTE_FLOW_ERROR_TYPE_ACTION,
9042 "cannot create jump action.");
9043 if (flow_dv_jump_tbl_resource_register
9044 (dev, tbl, dev_flow, error)) {
9045 flow_dv_tbl_resource_release(dev, tbl);
9046 return rte_flow_error_set
9048 RTE_FLOW_ERROR_TYPE_ACTION,
9050 "cannot create jump action.");
9052 dev_flow->dv.actions[actions_n++] =
9053 dev_flow->dv.jump->action;
9054 action_flags |= MLX5_FLOW_ACTION_JUMP;
9055 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
9057 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
9058 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
9059 if (flow_dv_convert_action_modify_mac
9060 (mhdr_res, actions, error))
9062 action_flags |= actions->type ==
9063 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
9064 MLX5_FLOW_ACTION_SET_MAC_SRC :
9065 MLX5_FLOW_ACTION_SET_MAC_DST;
9067 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
9068 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
9069 if (flow_dv_convert_action_modify_ipv4
9070 (mhdr_res, actions, error))
9072 action_flags |= actions->type ==
9073 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
9074 MLX5_FLOW_ACTION_SET_IPV4_SRC :
9075 MLX5_FLOW_ACTION_SET_IPV4_DST;
9077 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
9078 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
9079 if (flow_dv_convert_action_modify_ipv6
9080 (mhdr_res, actions, error))
9082 action_flags |= actions->type ==
9083 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
9084 MLX5_FLOW_ACTION_SET_IPV6_SRC :
9085 MLX5_FLOW_ACTION_SET_IPV6_DST;
9087 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
9088 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
9089 if (flow_dv_convert_action_modify_tp
9090 (mhdr_res, actions, items,
9091 &flow_attr, dev_flow, !!(action_flags &
9092 MLX5_FLOW_ACTION_DECAP), error))
9094 action_flags |= actions->type ==
9095 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
9096 MLX5_FLOW_ACTION_SET_TP_SRC :
9097 MLX5_FLOW_ACTION_SET_TP_DST;
9099 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
9100 if (flow_dv_convert_action_modify_dec_ttl
9101 (mhdr_res, items, &flow_attr, dev_flow,
9103 MLX5_FLOW_ACTION_DECAP), error))
9105 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
9107 case RTE_FLOW_ACTION_TYPE_SET_TTL:
9108 if (flow_dv_convert_action_modify_ttl
9109 (mhdr_res, actions, items, &flow_attr,
9110 dev_flow, !!(action_flags &
9111 MLX5_FLOW_ACTION_DECAP), error))
9113 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
9115 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
9116 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
9117 if (flow_dv_convert_action_modify_tcp_seq
9118 (mhdr_res, actions, error))
9120 action_flags |= actions->type ==
9121 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
9122 MLX5_FLOW_ACTION_INC_TCP_SEQ :
9123 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
9126 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
9127 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
9128 if (flow_dv_convert_action_modify_tcp_ack
9129 (mhdr_res, actions, error))
9131 action_flags |= actions->type ==
9132 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
9133 MLX5_FLOW_ACTION_INC_TCP_ACK :
9134 MLX5_FLOW_ACTION_DEC_TCP_ACK;
9136 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
9137 if (flow_dv_convert_action_set_reg
9138 (mhdr_res, actions, error))
9140 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
9142 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
9143 if (flow_dv_convert_action_copy_mreg
9144 (dev, mhdr_res, actions, error))
9146 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
9148 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
9149 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
9150 dev_flow->handle->fate_action =
9151 MLX5_FLOW_FATE_DEFAULT_MISS;
9153 case RTE_FLOW_ACTION_TYPE_METER:
9154 mtr = actions->conf;
9156 fm = mlx5_flow_meter_attach(priv, mtr->mtr_id,
9159 return rte_flow_error_set(error,
9161 RTE_FLOW_ERROR_TYPE_ACTION,
9164 "or invalid parameters");
9165 flow->meter = fm->idx;
9167 /* Set the meter action. */
9169 fm = mlx5_ipool_get(priv->sh->ipool
9170 [MLX5_IPOOL_MTR], flow->meter);
9172 return rte_flow_error_set(error,
9174 RTE_FLOW_ERROR_TYPE_ACTION,
9177 "or invalid parameters");
9179 dev_flow->dv.actions[actions_n++] =
9180 fm->mfts->meter_action;
9181 action_flags |= MLX5_FLOW_ACTION_METER;
9183 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
9184 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
9187 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
9189 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
9190 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
9193 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
9195 case RTE_FLOW_ACTION_TYPE_SAMPLE:
9196 sample_act_pos = actions_n;
9197 ret = flow_dv_translate_action_sample(dev,
9206 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
9208 case RTE_FLOW_ACTION_TYPE_END:
9210 if (mhdr_res->actions_num) {
9211 /* create modify action if needed. */
9212 if (flow_dv_modify_hdr_resource_register
9213 (dev, mhdr_res, dev_flow, error))
9215 dev_flow->dv.actions[modify_action_position] =
9216 handle->dvh.modify_hdr->action;
9218 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
9220 flow_dv_translate_create_counter(dev,
9221 dev_flow, count, age);
9224 return rte_flow_error_set
9226 RTE_FLOW_ERROR_TYPE_ACTION,
9228 "cannot create counter"
9230 dev_flow->dv.actions[actions_n++] =
9231 (flow_dv_counter_get_by_idx(dev,
9232 flow->counter, NULL))->action;
9234 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
9235 ret = flow_dv_create_action_sample(dev,
9241 return rte_flow_error_set
9243 RTE_FLOW_ERROR_TYPE_ACTION,
9245 "cannot create sample action");
9246 dev_flow->dv.actions[sample_act_pos] =
9247 dev_flow->dv.sample_res->verbs_action;
9253 if (mhdr_res->actions_num &&
9254 modify_action_position == UINT32_MAX)
9255 modify_action_position = actions_n++;
9257 dev_flow->dv.actions_n = actions_n;
9258 dev_flow->act_flags = action_flags;
9259 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
9260 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
9261 int item_type = items->type;
9263 if (!mlx5_flow_os_item_supported(item_type))
9264 return rte_flow_error_set(error, ENOTSUP,
9265 RTE_FLOW_ERROR_TYPE_ITEM,
9266 NULL, "item not supported");
9267 switch (item_type) {
9268 case RTE_FLOW_ITEM_TYPE_PORT_ID:
9269 flow_dv_translate_item_port_id(dev, match_mask,
9270 match_value, items);
9271 last_item = MLX5_FLOW_ITEM_PORT_ID;
9273 case RTE_FLOW_ITEM_TYPE_ETH:
9274 flow_dv_translate_item_eth(match_mask, match_value,
9276 dev_flow->dv.group);
9277 matcher.priority = action_flags &
9278 MLX5_FLOW_ACTION_DEFAULT_MISS &&
9279 !dev_flow->external ?
9280 MLX5_PRIORITY_MAP_L3 :
9281 MLX5_PRIORITY_MAP_L2;
9282 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
9283 MLX5_FLOW_LAYER_OUTER_L2;
9285 case RTE_FLOW_ITEM_TYPE_VLAN:
9286 flow_dv_translate_item_vlan(dev_flow,
9287 match_mask, match_value,
9289 dev_flow->dv.group);
9290 matcher.priority = MLX5_PRIORITY_MAP_L2;
9291 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
9292 MLX5_FLOW_LAYER_INNER_VLAN) :
9293 (MLX5_FLOW_LAYER_OUTER_L2 |
9294 MLX5_FLOW_LAYER_OUTER_VLAN);
9296 case RTE_FLOW_ITEM_TYPE_IPV4:
9297 mlx5_flow_tunnel_ip_check(items, next_protocol,
9298 &item_flags, &tunnel);
9299 flow_dv_translate_item_ipv4(match_mask, match_value,
9300 items, item_flags, tunnel,
9301 dev_flow->dv.group);
9302 matcher.priority = MLX5_PRIORITY_MAP_L3;
9303 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
9304 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
9305 if (items->mask != NULL &&
9306 ((const struct rte_flow_item_ipv4 *)
9307 items->mask)->hdr.next_proto_id) {
9309 ((const struct rte_flow_item_ipv4 *)
9310 (items->spec))->hdr.next_proto_id;
9312 ((const struct rte_flow_item_ipv4 *)
9313 (items->mask))->hdr.next_proto_id;
9315 /* Reset for inner layer. */
9316 next_protocol = 0xff;
9319 case RTE_FLOW_ITEM_TYPE_IPV6:
9320 mlx5_flow_tunnel_ip_check(items, next_protocol,
9321 &item_flags, &tunnel);
9322 flow_dv_translate_item_ipv6(match_mask, match_value,
9323 items, item_flags, tunnel,
9324 dev_flow->dv.group);
9325 matcher.priority = MLX5_PRIORITY_MAP_L3;
9326 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
9327 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
9328 if (items->mask != NULL &&
9329 ((const struct rte_flow_item_ipv6 *)
9330 items->mask)->hdr.proto) {
9332 ((const struct rte_flow_item_ipv6 *)
9333 items->spec)->hdr.proto;
9335 ((const struct rte_flow_item_ipv6 *)
9336 items->mask)->hdr.proto;
9338 /* Reset for inner layer. */
9339 next_protocol = 0xff;
9342 case RTE_FLOW_ITEM_TYPE_TCP:
9343 flow_dv_translate_item_tcp(match_mask, match_value,
9345 matcher.priority = MLX5_PRIORITY_MAP_L4;
9346 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
9347 MLX5_FLOW_LAYER_OUTER_L4_TCP;
9349 case RTE_FLOW_ITEM_TYPE_UDP:
9350 flow_dv_translate_item_udp(match_mask, match_value,
9352 matcher.priority = MLX5_PRIORITY_MAP_L4;
9353 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
9354 MLX5_FLOW_LAYER_OUTER_L4_UDP;
9356 case RTE_FLOW_ITEM_TYPE_GRE:
9357 flow_dv_translate_item_gre(match_mask, match_value,
9359 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
9360 last_item = MLX5_FLOW_LAYER_GRE;
9362 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
9363 flow_dv_translate_item_gre_key(match_mask,
9364 match_value, items);
9365 last_item = MLX5_FLOW_LAYER_GRE_KEY;
9367 case RTE_FLOW_ITEM_TYPE_NVGRE:
9368 flow_dv_translate_item_nvgre(match_mask, match_value,
9370 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
9371 last_item = MLX5_FLOW_LAYER_GRE;
9373 case RTE_FLOW_ITEM_TYPE_VXLAN:
9374 flow_dv_translate_item_vxlan(match_mask, match_value,
9376 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
9377 last_item = MLX5_FLOW_LAYER_VXLAN;
9379 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
9380 flow_dv_translate_item_vxlan_gpe(match_mask,
9383 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
9384 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
9386 case RTE_FLOW_ITEM_TYPE_GENEVE:
9387 flow_dv_translate_item_geneve(match_mask, match_value,
9389 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
9390 last_item = MLX5_FLOW_LAYER_GENEVE;
9392 case RTE_FLOW_ITEM_TYPE_MPLS:
9393 flow_dv_translate_item_mpls(match_mask, match_value,
9394 items, last_item, tunnel);
9395 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
9396 last_item = MLX5_FLOW_LAYER_MPLS;
9398 case RTE_FLOW_ITEM_TYPE_MARK:
9399 flow_dv_translate_item_mark(dev, match_mask,
9400 match_value, items);
9401 last_item = MLX5_FLOW_ITEM_MARK;
9403 case RTE_FLOW_ITEM_TYPE_META:
9404 flow_dv_translate_item_meta(dev, match_mask,
9405 match_value, attr, items);
9406 last_item = MLX5_FLOW_ITEM_METADATA;
9408 case RTE_FLOW_ITEM_TYPE_ICMP:
9409 flow_dv_translate_item_icmp(match_mask, match_value,
9411 last_item = MLX5_FLOW_LAYER_ICMP;
9413 case RTE_FLOW_ITEM_TYPE_ICMP6:
9414 flow_dv_translate_item_icmp6(match_mask, match_value,
9416 last_item = MLX5_FLOW_LAYER_ICMP6;
9418 case RTE_FLOW_ITEM_TYPE_TAG:
9419 flow_dv_translate_item_tag(dev, match_mask,
9420 match_value, items);
9421 last_item = MLX5_FLOW_ITEM_TAG;
9423 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
9424 flow_dv_translate_mlx5_item_tag(dev, match_mask,
9425 match_value, items);
9426 last_item = MLX5_FLOW_ITEM_TAG;
9428 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
9429 flow_dv_translate_item_tx_queue(dev, match_mask,
9432 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
9434 case RTE_FLOW_ITEM_TYPE_GTP:
9435 flow_dv_translate_item_gtp(match_mask, match_value,
9437 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
9438 last_item = MLX5_FLOW_LAYER_GTP;
9440 case RTE_FLOW_ITEM_TYPE_ECPRI:
9441 if (!mlx5_flex_parser_ecpri_exist(dev)) {
9442 /* Create it only the first time to be used. */
9443 ret = mlx5_flex_parser_ecpri_alloc(dev);
9445 return rte_flow_error_set
9447 RTE_FLOW_ERROR_TYPE_ITEM,
9449 "cannot create eCPRI parser");
9451 /* Adjust the length matcher and device flow value. */
9452 matcher.mask.size = MLX5_ST_SZ_BYTES(fte_match_param);
9453 dev_flow->dv.value.size =
9454 MLX5_ST_SZ_BYTES(fte_match_param);
9455 flow_dv_translate_item_ecpri(dev, match_mask,
9456 match_value, items);
9457 /* No other protocol should follow eCPRI layer. */
9458 last_item = MLX5_FLOW_LAYER_ECPRI;
9463 item_flags |= last_item;
9466 * When E-Switch mode is enabled, we have two cases where we need to
9467 * set the source port manually.
9468 * The first one, is in case of Nic steering rule, and the second is
9469 * E-Switch rule where no port_id item was found. In both cases
9470 * the source port is set according the current port in use.
9472 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
9473 (priv->representor || priv->master)) {
9474 if (flow_dv_translate_item_port_id(dev, match_mask,
9478 #ifdef RTE_LIBRTE_MLX5_DEBUG
9479 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
9480 dev_flow->dv.value.buf));
9483 * Layers may be already initialized from prefix flow if this dev_flow
9484 * is the suffix flow.
9486 handle->layers |= item_flags;
9487 if (action_flags & MLX5_FLOW_ACTION_RSS)
9488 flow_dv_hashfields_set(dev_flow, rss_desc);
9489 /* Register matcher. */
9490 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
9492 matcher.priority = mlx5_flow_adjust_priority(dev, priority,
9494 /* reserved field no needs to be set to 0 here. */
9495 tbl_key.domain = attr->transfer;
9496 tbl_key.direction = attr->egress;
9497 tbl_key.table_id = dev_flow->dv.group;
9498 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow, error))
9504 * Apply the flow to the NIC, lock free,
9505 * (mutex should be acquired by caller).
9508 * Pointer to the Ethernet device structure.
9509 * @param[in, out] flow
9510 * Pointer to flow structure.
9512 * Pointer to error structure.
9515 * 0 on success, a negative errno value otherwise and rte_errno is set.
9518 __flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
9519 struct rte_flow_error *error)
9521 struct mlx5_flow_dv_workspace *dv;
9522 struct mlx5_flow_handle *dh;
9523 struct mlx5_flow_handle_dv *dv_h;
9524 struct mlx5_flow *dev_flow;
9525 struct mlx5_priv *priv = dev->data->dev_private;
9526 uint32_t handle_idx;
9531 for (idx = priv->flow_idx - 1; idx >= priv->flow_nested_idx; idx--) {
9532 dev_flow = &((struct mlx5_flow *)priv->inter_flows)[idx];
9534 dh = dev_flow->handle;
9537 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
9539 dv->actions[n++] = priv->sh->esw_drop_action;
9541 struct mlx5_hrxq *drop_hrxq;
9542 drop_hrxq = mlx5_drop_action_create(dev);
9546 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9548 "cannot get drop hash queue");
9552 * Drop queues will be released by the specify
9553 * mlx5_drop_action_destroy() function. Assign
9554 * the special index to hrxq to mark the queue
9555 * has been allocated.
9557 dh->rix_hrxq = UINT32_MAX;
9558 dv->actions[n++] = drop_hrxq->action;
9560 } else if (dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
9561 !dv_h->rix_sample) {
9562 struct mlx5_hrxq *hrxq;
9564 struct mlx5_flow_rss_desc *rss_desc =
9565 &((struct mlx5_flow_rss_desc *)priv->rss_desc)
9566 [!!priv->flow_nested_idx];
9568 MLX5_ASSERT(rss_desc->queue_num);
9569 hrxq_idx = mlx5_hrxq_get(dev, rss_desc->key,
9570 MLX5_RSS_HASH_KEY_LEN,
9571 dev_flow->hash_fields,
9573 rss_desc->queue_num);
9575 hrxq_idx = mlx5_hrxq_new
9576 (dev, rss_desc->key,
9577 MLX5_RSS_HASH_KEY_LEN,
9578 dev_flow->hash_fields,
9580 rss_desc->queue_num,
9582 MLX5_FLOW_LAYER_TUNNEL));
9584 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
9589 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9590 "cannot get hash queue");
9593 dh->rix_hrxq = hrxq_idx;
9594 dv->actions[n++] = hrxq->action;
9595 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
9596 if (flow_dv_default_miss_resource_register
9600 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9601 "cannot create default miss resource");
9602 goto error_default_miss;
9604 dh->rix_default_fate = MLX5_FLOW_FATE_DEFAULT_MISS;
9605 dv->actions[n++] = priv->sh->default_miss.action;
9607 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
9608 (void *)&dv->value, n,
9609 dv->actions, &dh->drv_flow);
9611 rte_flow_error_set(error, errno,
9612 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9614 "hardware refuses to create flow");
9617 if (priv->vmwa_context &&
9618 dh->vf_vlan.tag && !dh->vf_vlan.created) {
9620 * The rule contains the VLAN pattern.
9621 * For VF we are going to create VLAN
9622 * interface to make hypervisor set correct
9623 * e-Switch vport context.
9625 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
9630 if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS)
9631 flow_dv_default_miss_resource_release(dev);
9633 err = rte_errno; /* Save rte_errno before cleanup. */
9634 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
9635 handle_idx, dh, next) {
9636 /* hrxq is union, don't clear it if the flag is not set. */
9638 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
9639 mlx5_drop_action_destroy(dev);
9641 } else if (dh->fate_action == MLX5_FLOW_FATE_QUEUE) {
9642 mlx5_hrxq_release(dev, dh->rix_hrxq);
9646 if (dh->vf_vlan.tag && dh->vf_vlan.created)
9647 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
9649 rte_errno = err; /* Restore rte_errno. */
9654 * Release the flow matcher.
9657 * Pointer to Ethernet device.
9659 * Pointer to mlx5_flow_handle.
9662 * 1 while a reference on it exists, 0 when freed.
9665 flow_dv_matcher_release(struct rte_eth_dev *dev,
9666 struct mlx5_flow_handle *handle)
9668 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
9670 MLX5_ASSERT(matcher->matcher_object);
9671 DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--",
9672 dev->data->port_id, (void *)matcher,
9673 rte_atomic32_read(&matcher->refcnt));
9674 if (rte_atomic32_dec_and_test(&matcher->refcnt)) {
9675 claim_zero(mlx5_flow_os_destroy_flow_matcher
9676 (matcher->matcher_object));
9677 LIST_REMOVE(matcher, next);
9678 /* table ref-- in release interface. */
9679 flow_dv_tbl_resource_release(dev, matcher->tbl);
9681 DRV_LOG(DEBUG, "port %u matcher %p: removed",
9682 dev->data->port_id, (void *)matcher);
9689 * Release an encap/decap resource.
9692 * Pointer to Ethernet device.
9693 * @param encap_decap_idx
9694 * Index of encap decap resource.
9697 * 1 while a reference on it exists, 0 when freed.
9700 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
9701 uint32_t encap_decap_idx)
9703 struct mlx5_priv *priv = dev->data->dev_private;
9704 uint32_t idx = encap_decap_idx;
9705 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
9707 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
9709 if (!cache_resource)
9711 MLX5_ASSERT(cache_resource->action);
9712 DRV_LOG(DEBUG, "encap/decap resource %p: refcnt %d--",
9713 (void *)cache_resource,
9714 rte_atomic32_read(&cache_resource->refcnt));
9715 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9716 claim_zero(mlx5_flow_os_destroy_flow_action
9717 (cache_resource->action));
9718 mlx5_hlist_remove(priv->sh->encaps_decaps,
9719 &cache_resource->entry);
9720 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
9721 DRV_LOG(DEBUG, "encap/decap resource %p: removed",
9722 (void *)cache_resource);
9729 * Release an jump to table action resource.
9732 * Pointer to Ethernet device.
9734 * Pointer to mlx5_flow_handle.
9737 * 1 while a reference on it exists, 0 when freed.
9740 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
9741 struct mlx5_flow_handle *handle)
9743 struct mlx5_priv *priv = dev->data->dev_private;
9744 struct mlx5_flow_dv_jump_tbl_resource *cache_resource;
9745 struct mlx5_flow_tbl_data_entry *tbl_data;
9747 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
9751 cache_resource = &tbl_data->jump;
9752 MLX5_ASSERT(cache_resource->action);
9753 DRV_LOG(DEBUG, "jump table resource %p: refcnt %d--",
9754 (void *)cache_resource,
9755 rte_atomic32_read(&cache_resource->refcnt));
9756 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9757 claim_zero(mlx5_flow_os_destroy_flow_action
9758 (cache_resource->action));
9759 /* jump action memory free is inside the table release. */
9760 flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
9761 DRV_LOG(DEBUG, "jump table resource %p: removed",
9762 (void *)cache_resource);
9769 * Release a default miss resource.
9772 * Pointer to Ethernet device.
9774 * 1 while a reference on it exists, 0 when freed.
9777 flow_dv_default_miss_resource_release(struct rte_eth_dev *dev)
9779 struct mlx5_priv *priv = dev->data->dev_private;
9780 struct mlx5_dev_ctx_shared *sh = priv->sh;
9781 struct mlx5_flow_default_miss_resource *cache_resource =
9784 MLX5_ASSERT(cache_resource->action);
9785 DRV_LOG(DEBUG, "default miss resource %p: refcnt %d--",
9786 (void *)cache_resource->action,
9787 rte_atomic32_read(&cache_resource->refcnt));
9788 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9789 claim_zero(mlx5_glue->destroy_flow_action
9790 (cache_resource->action));
9791 DRV_LOG(DEBUG, "default miss resource %p: removed",
9792 (void *)cache_resource->action);
9799 * Release a modify-header resource.
9802 * Pointer to Ethernet device.
9804 * Pointer to mlx5_flow_handle.
9807 * 1 while a reference on it exists, 0 when freed.
9810 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
9811 struct mlx5_flow_handle *handle)
9813 struct mlx5_priv *priv = dev->data->dev_private;
9814 struct mlx5_flow_dv_modify_hdr_resource *cache_resource =
9815 handle->dvh.modify_hdr;
9817 MLX5_ASSERT(cache_resource->action);
9818 DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d--",
9819 (void *)cache_resource,
9820 rte_atomic32_read(&cache_resource->refcnt));
9821 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9822 claim_zero(mlx5_flow_os_destroy_flow_action
9823 (cache_resource->action));
9824 mlx5_hlist_remove(priv->sh->modify_cmds,
9825 &cache_resource->entry);
9826 mlx5_free(cache_resource);
9827 DRV_LOG(DEBUG, "modify-header resource %p: removed",
9828 (void *)cache_resource);
9835 * Release port ID action resource.
9838 * Pointer to Ethernet device.
9840 * Pointer to mlx5_flow_handle.
9843 * 1 while a reference on it exists, 0 when freed.
9846 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
9847 struct mlx5_flow_handle *handle)
9849 struct mlx5_priv *priv = dev->data->dev_private;
9850 struct mlx5_flow_dv_port_id_action_resource *cache_resource;
9851 uint32_t idx = handle->rix_port_id_action;
9853 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
9855 if (!cache_resource)
9857 MLX5_ASSERT(cache_resource->action);
9858 DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--",
9859 (void *)cache_resource,
9860 rte_atomic32_read(&cache_resource->refcnt));
9861 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9862 claim_zero(mlx5_flow_os_destroy_flow_action
9863 (cache_resource->action));
9864 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
9865 &priv->sh->port_id_action_list, idx,
9866 cache_resource, next);
9867 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_PORT_ID], idx);
9868 DRV_LOG(DEBUG, "port id action resource %p: removed",
9869 (void *)cache_resource);
9876 * Release push vlan action resource.
9879 * Pointer to Ethernet device.
9881 * Pointer to mlx5_flow_handle.
9884 * 1 while a reference on it exists, 0 when freed.
9887 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
9888 struct mlx5_flow_handle *handle)
9890 struct mlx5_priv *priv = dev->data->dev_private;
9891 uint32_t idx = handle->dvh.rix_push_vlan;
9892 struct mlx5_flow_dv_push_vlan_action_resource *cache_resource;
9894 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN],
9896 if (!cache_resource)
9898 MLX5_ASSERT(cache_resource->action);
9899 DRV_LOG(DEBUG, "push VLAN action resource %p: refcnt %d--",
9900 (void *)cache_resource,
9901 rte_atomic32_read(&cache_resource->refcnt));
9902 if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
9903 claim_zero(mlx5_flow_os_destroy_flow_action
9904 (cache_resource->action));
9905 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN],
9906 &priv->sh->push_vlan_action_list, idx,
9907 cache_resource, next);
9908 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
9909 DRV_LOG(DEBUG, "push vlan action resource %p: removed",
9910 (void *)cache_resource);
9917 * Release the fate resource.
9920 * Pointer to Ethernet device.
9922 * Pointer to mlx5_flow_handle.
9925 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
9926 struct mlx5_flow_handle *handle)
9928 if (!handle->rix_fate)
9930 switch (handle->fate_action) {
9931 case MLX5_FLOW_FATE_DROP:
9932 mlx5_drop_action_destroy(dev);
9934 case MLX5_FLOW_FATE_QUEUE:
9935 mlx5_hrxq_release(dev, handle->rix_hrxq);
9937 case MLX5_FLOW_FATE_JUMP:
9938 flow_dv_jump_tbl_resource_release(dev, handle);
9940 case MLX5_FLOW_FATE_PORT_ID:
9941 flow_dv_port_id_action_resource_release(dev, handle);
9943 case MLX5_FLOW_FATE_DEFAULT_MISS:
9944 flow_dv_default_miss_resource_release(dev);
9947 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
9950 handle->rix_fate = 0;
9954 * Release an sample resource.
9957 * Pointer to Ethernet device.
9959 * Pointer to mlx5_flow_handle.
9962 * 1 while a reference on it exists, 0 when freed.
9965 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
9966 struct mlx5_flow_handle *handle)
9968 struct mlx5_priv *priv = dev->data->dev_private;
9969 uint32_t idx = handle->dvh.rix_sample;
9970 struct mlx5_flow_dv_sample_resource *cache_resource;
9972 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
9974 if (!cache_resource)
9976 MLX5_ASSERT(cache_resource->verbs_action);
9977 DRV_LOG(DEBUG, "sample resource %p: refcnt %d--",
9978 (void *)cache_resource,
9979 __atomic_load_n(&cache_resource->refcnt, __ATOMIC_RELAXED));
9980 if (__atomic_sub_fetch(&cache_resource->refcnt, 1,
9981 __ATOMIC_RELAXED) == 0) {
9982 if (cache_resource->verbs_action)
9983 claim_zero(mlx5_glue->destroy_flow_action
9984 (cache_resource->verbs_action));
9985 if (cache_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
9986 if (cache_resource->default_miss)
9987 claim_zero(mlx5_glue->destroy_flow_action
9988 (cache_resource->default_miss));
9990 if (cache_resource->normal_path_tbl)
9991 flow_dv_tbl_resource_release(dev,
9992 cache_resource->normal_path_tbl);
9994 if (cache_resource->sample_idx.rix_hrxq &&
9995 !mlx5_hrxq_release(dev,
9996 cache_resource->sample_idx.rix_hrxq))
9997 cache_resource->sample_idx.rix_hrxq = 0;
9998 if (cache_resource->sample_idx.rix_tag &&
9999 !flow_dv_tag_release(dev,
10000 cache_resource->sample_idx.rix_tag))
10001 cache_resource->sample_idx.rix_tag = 0;
10002 if (cache_resource->sample_idx.cnt) {
10003 flow_dv_counter_release(dev,
10004 cache_resource->sample_idx.cnt);
10005 cache_resource->sample_idx.cnt = 0;
10007 if (!__atomic_load_n(&cache_resource->refcnt, __ATOMIC_RELAXED)) {
10008 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
10009 &priv->sh->sample_action_list, idx,
10010 cache_resource, next);
10011 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], idx);
10012 DRV_LOG(DEBUG, "sample resource %p: removed",
10013 (void *)cache_resource);
10020 * Remove the flow from the NIC but keeps it in memory.
10021 * Lock free, (mutex should be acquired by caller).
10024 * Pointer to Ethernet device.
10025 * @param[in, out] flow
10026 * Pointer to flow structure.
10029 __flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
10031 struct mlx5_flow_handle *dh;
10032 uint32_t handle_idx;
10033 struct mlx5_priv *priv = dev->data->dev_private;
10037 handle_idx = flow->dev_handles;
10038 while (handle_idx) {
10039 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
10043 if (dh->drv_flow) {
10044 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
10045 dh->drv_flow = NULL;
10047 if (dh->fate_action == MLX5_FLOW_FATE_DROP ||
10048 dh->fate_action == MLX5_FLOW_FATE_QUEUE ||
10049 dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS)
10050 flow_dv_fate_resource_release(dev, dh);
10051 if (dh->vf_vlan.tag && dh->vf_vlan.created)
10052 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
10053 handle_idx = dh->next.next;
10058 * Remove the flow from the NIC and the memory.
10059 * Lock free, (mutex should be acquired by caller).
10062 * Pointer to the Ethernet device structure.
10063 * @param[in, out] flow
10064 * Pointer to flow structure.
10067 __flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
10069 struct mlx5_flow_handle *dev_handle;
10070 struct mlx5_priv *priv = dev->data->dev_private;
10074 __flow_dv_remove(dev, flow);
10075 if (flow->counter) {
10076 flow_dv_counter_release(dev, flow->counter);
10080 struct mlx5_flow_meter *fm;
10082 fm = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MTR],
10085 mlx5_flow_meter_detach(fm);
10088 while (flow->dev_handles) {
10089 uint32_t tmp_idx = flow->dev_handles;
10091 dev_handle = mlx5_ipool_get(priv->sh->ipool
10092 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
10095 flow->dev_handles = dev_handle->next.next;
10096 if (dev_handle->dvh.matcher)
10097 flow_dv_matcher_release(dev, dev_handle);
10098 if (dev_handle->dvh.rix_sample)
10099 flow_dv_sample_resource_release(dev, dev_handle);
10100 if (dev_handle->dvh.rix_encap_decap)
10101 flow_dv_encap_decap_resource_release(dev,
10102 dev_handle->dvh.rix_encap_decap);
10103 if (dev_handle->dvh.modify_hdr)
10104 flow_dv_modify_hdr_resource_release(dev, dev_handle);
10105 if (dev_handle->dvh.rix_push_vlan)
10106 flow_dv_push_vlan_action_resource_release(dev,
10108 if (dev_handle->dvh.rix_tag)
10109 flow_dv_tag_release(dev,
10110 dev_handle->dvh.rix_tag);
10111 flow_dv_fate_resource_release(dev, dev_handle);
10112 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
10118 * Query a dv flow rule for its statistics via devx.
10121 * Pointer to Ethernet device.
10123 * Pointer to the sub flow.
10125 * data retrieved by the query.
10126 * @param[out] error
10127 * Perform verbose error reporting if not NULL.
10130 * 0 on success, a negative errno value otherwise and rte_errno is set.
10133 flow_dv_query_count(struct rte_eth_dev *dev, struct rte_flow *flow,
10134 void *data, struct rte_flow_error *error)
10136 struct mlx5_priv *priv = dev->data->dev_private;
10137 struct rte_flow_query_count *qc = data;
10139 if (!priv->config.devx)
10140 return rte_flow_error_set(error, ENOTSUP,
10141 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10143 "counters are not supported");
10144 if (flow->counter) {
10145 uint64_t pkts, bytes;
10146 struct mlx5_flow_counter *cnt;
10148 cnt = flow_dv_counter_get_by_idx(dev, flow->counter,
10150 int err = _flow_dv_query_count(dev, flow->counter, &pkts,
10154 return rte_flow_error_set(error, -err,
10155 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10156 NULL, "cannot read counters");
10159 qc->hits = pkts - cnt->hits;
10160 qc->bytes = bytes - cnt->bytes;
10163 cnt->bytes = bytes;
10167 return rte_flow_error_set(error, EINVAL,
10168 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10170 "counters are not available");
10176 * @see rte_flow_query()
10177 * @see rte_flow_ops
10180 flow_dv_query(struct rte_eth_dev *dev,
10181 struct rte_flow *flow __rte_unused,
10182 const struct rte_flow_action *actions __rte_unused,
10183 void *data __rte_unused,
10184 struct rte_flow_error *error __rte_unused)
10188 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
10189 switch (actions->type) {
10190 case RTE_FLOW_ACTION_TYPE_VOID:
10192 case RTE_FLOW_ACTION_TYPE_COUNT:
10193 ret = flow_dv_query_count(dev, flow, data, error);
10196 return rte_flow_error_set(error, ENOTSUP,
10197 RTE_FLOW_ERROR_TYPE_ACTION,
10199 "action not supported");
10206 * Destroy the meter table set.
10207 * Lock free, (mutex should be acquired by caller).
10210 * Pointer to Ethernet device.
10212 * Pointer to the meter table set.
10218 flow_dv_destroy_mtr_tbl(struct rte_eth_dev *dev,
10219 struct mlx5_meter_domains_infos *tbl)
10221 struct mlx5_priv *priv = dev->data->dev_private;
10222 struct mlx5_meter_domains_infos *mtd =
10223 (struct mlx5_meter_domains_infos *)tbl;
10225 if (!mtd || !priv->config.dv_flow_en)
10227 if (mtd->ingress.policer_rules[RTE_MTR_DROPPED])
10228 claim_zero(mlx5_flow_os_destroy_flow
10229 (mtd->ingress.policer_rules[RTE_MTR_DROPPED]));
10230 if (mtd->egress.policer_rules[RTE_MTR_DROPPED])
10231 claim_zero(mlx5_flow_os_destroy_flow
10232 (mtd->egress.policer_rules[RTE_MTR_DROPPED]));
10233 if (mtd->transfer.policer_rules[RTE_MTR_DROPPED])
10234 claim_zero(mlx5_flow_os_destroy_flow
10235 (mtd->transfer.policer_rules[RTE_MTR_DROPPED]));
10236 if (mtd->egress.color_matcher)
10237 claim_zero(mlx5_flow_os_destroy_flow_matcher
10238 (mtd->egress.color_matcher));
10239 if (mtd->egress.any_matcher)
10240 claim_zero(mlx5_flow_os_destroy_flow_matcher
10241 (mtd->egress.any_matcher));
10242 if (mtd->egress.tbl)
10243 flow_dv_tbl_resource_release(dev, mtd->egress.tbl);
10244 if (mtd->egress.sfx_tbl)
10245 flow_dv_tbl_resource_release(dev, mtd->egress.sfx_tbl);
10246 if (mtd->ingress.color_matcher)
10247 claim_zero(mlx5_flow_os_destroy_flow_matcher
10248 (mtd->ingress.color_matcher));
10249 if (mtd->ingress.any_matcher)
10250 claim_zero(mlx5_flow_os_destroy_flow_matcher
10251 (mtd->ingress.any_matcher));
10252 if (mtd->ingress.tbl)
10253 flow_dv_tbl_resource_release(dev, mtd->ingress.tbl);
10254 if (mtd->ingress.sfx_tbl)
10255 flow_dv_tbl_resource_release(dev, mtd->ingress.sfx_tbl);
10256 if (mtd->transfer.color_matcher)
10257 claim_zero(mlx5_flow_os_destroy_flow_matcher
10258 (mtd->transfer.color_matcher));
10259 if (mtd->transfer.any_matcher)
10260 claim_zero(mlx5_flow_os_destroy_flow_matcher
10261 (mtd->transfer.any_matcher));
10262 if (mtd->transfer.tbl)
10263 flow_dv_tbl_resource_release(dev, mtd->transfer.tbl);
10264 if (mtd->transfer.sfx_tbl)
10265 flow_dv_tbl_resource_release(dev, mtd->transfer.sfx_tbl);
10266 if (mtd->drop_actn)
10267 claim_zero(mlx5_flow_os_destroy_flow_action(mtd->drop_actn));
10272 /* Number of meter flow actions, count and jump or count and drop. */
10273 #define METER_ACTIONS 2
10276 * Create specify domain meter table and suffix table.
10279 * Pointer to Ethernet device.
10280 * @param[in,out] mtb
10281 * Pointer to DV meter table set.
10282 * @param[in] egress
10284 * @param[in] transfer
10286 * @param[in] color_reg_c_idx
10287 * Reg C index for color match.
10290 * 0 on success, -1 otherwise and rte_errno is set.
10293 flow_dv_prepare_mtr_tables(struct rte_eth_dev *dev,
10294 struct mlx5_meter_domains_infos *mtb,
10295 uint8_t egress, uint8_t transfer,
10296 uint32_t color_reg_c_idx)
10298 struct mlx5_priv *priv = dev->data->dev_private;
10299 struct mlx5_dev_ctx_shared *sh = priv->sh;
10300 struct mlx5_flow_dv_match_params mask = {
10301 .size = sizeof(mask.buf),
10303 struct mlx5_flow_dv_match_params value = {
10304 .size = sizeof(value.buf),
10306 struct mlx5dv_flow_matcher_attr dv_attr = {
10307 .type = IBV_FLOW_ATTR_NORMAL,
10309 .match_criteria_enable = 0,
10310 .match_mask = (void *)&mask,
10312 void *actions[METER_ACTIONS];
10313 struct mlx5_meter_domain_info *dtb;
10314 struct rte_flow_error error;
10319 dtb = &mtb->transfer;
10321 dtb = &mtb->egress;
10323 dtb = &mtb->ingress;
10324 /* Create the meter table with METER level. */
10325 dtb->tbl = flow_dv_tbl_resource_get(dev, MLX5_FLOW_TABLE_LEVEL_METER,
10326 egress, transfer, &error);
10328 DRV_LOG(ERR, "Failed to create meter policer table.");
10331 /* Create the meter suffix table with SUFFIX level. */
10332 dtb->sfx_tbl = flow_dv_tbl_resource_get(dev,
10333 MLX5_FLOW_TABLE_LEVEL_SUFFIX,
10334 egress, transfer, &error);
10335 if (!dtb->sfx_tbl) {
10336 DRV_LOG(ERR, "Failed to create meter suffix table.");
10339 /* Create matchers, Any and Color. */
10340 dv_attr.priority = 3;
10341 dv_attr.match_criteria_enable = 0;
10342 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, dtb->tbl->obj,
10343 &dtb->any_matcher);
10345 DRV_LOG(ERR, "Failed to create meter"
10346 " policer default matcher.");
10349 dv_attr.priority = 0;
10350 dv_attr.match_criteria_enable =
10351 1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
10352 flow_dv_match_meta_reg(mask.buf, value.buf, color_reg_c_idx,
10353 rte_col_2_mlx5_col(RTE_COLORS), UINT8_MAX);
10354 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, dtb->tbl->obj,
10355 &dtb->color_matcher);
10357 DRV_LOG(ERR, "Failed to create meter policer color matcher.");
10360 if (mtb->count_actns[RTE_MTR_DROPPED])
10361 actions[i++] = mtb->count_actns[RTE_MTR_DROPPED];
10362 actions[i++] = mtb->drop_actn;
10363 /* Default rule: lowest priority, match any, actions: drop. */
10364 ret = mlx5_flow_os_create_flow(dtb->any_matcher, (void *)&value, i,
10366 &dtb->policer_rules[RTE_MTR_DROPPED]);
10368 DRV_LOG(ERR, "Failed to create meter policer drop rule.");
10377 * Create the needed meter and suffix tables.
10378 * Lock free, (mutex should be acquired by caller).
10381 * Pointer to Ethernet device.
10383 * Pointer to the flow meter.
10386 * Pointer to table set on success, NULL otherwise and rte_errno is set.
10388 static struct mlx5_meter_domains_infos *
10389 flow_dv_create_mtr_tbl(struct rte_eth_dev *dev,
10390 const struct mlx5_flow_meter *fm)
10392 struct mlx5_priv *priv = dev->data->dev_private;
10393 struct mlx5_meter_domains_infos *mtb;
10397 if (!priv->mtr_en) {
10398 rte_errno = ENOTSUP;
10401 mtb = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*mtb), 0, SOCKET_ID_ANY);
10403 DRV_LOG(ERR, "Failed to allocate memory for meter.");
10406 /* Create meter count actions */
10407 for (i = 0; i <= RTE_MTR_DROPPED; i++) {
10408 struct mlx5_flow_counter *cnt;
10409 if (!fm->policer_stats.cnt[i])
10411 cnt = flow_dv_counter_get_by_idx(dev,
10412 fm->policer_stats.cnt[i], NULL);
10413 mtb->count_actns[i] = cnt->action;
10415 /* Create drop action. */
10416 ret = mlx5_flow_os_create_flow_action_drop(&mtb->drop_actn);
10418 DRV_LOG(ERR, "Failed to create drop action.");
10421 /* Egress meter table. */
10422 ret = flow_dv_prepare_mtr_tables(dev, mtb, 1, 0, priv->mtr_color_reg);
10424 DRV_LOG(ERR, "Failed to prepare egress meter table.");
10427 /* Ingress meter table. */
10428 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 0, priv->mtr_color_reg);
10430 DRV_LOG(ERR, "Failed to prepare ingress meter table.");
10433 /* FDB meter table. */
10434 if (priv->config.dv_esw_en) {
10435 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 1,
10436 priv->mtr_color_reg);
10438 DRV_LOG(ERR, "Failed to prepare fdb meter table.");
10444 flow_dv_destroy_mtr_tbl(dev, mtb);
10449 * Destroy domain policer rule.
10452 * Pointer to domain table.
10455 flow_dv_destroy_domain_policer_rule(struct mlx5_meter_domain_info *dt)
10459 for (i = 0; i < RTE_MTR_DROPPED; i++) {
10460 if (dt->policer_rules[i]) {
10461 claim_zero(mlx5_flow_os_destroy_flow
10462 (dt->policer_rules[i]));
10463 dt->policer_rules[i] = NULL;
10466 if (dt->jump_actn) {
10467 claim_zero(mlx5_flow_os_destroy_flow_action(dt->jump_actn));
10468 dt->jump_actn = NULL;
10473 * Destroy policer rules.
10476 * Pointer to Ethernet device.
10478 * Pointer to flow meter structure.
10480 * Pointer to flow attributes.
10486 flow_dv_destroy_policer_rules(struct rte_eth_dev *dev __rte_unused,
10487 const struct mlx5_flow_meter *fm,
10488 const struct rte_flow_attr *attr)
10490 struct mlx5_meter_domains_infos *mtb = fm ? fm->mfts : NULL;
10495 flow_dv_destroy_domain_policer_rule(&mtb->egress);
10497 flow_dv_destroy_domain_policer_rule(&mtb->ingress);
10498 if (attr->transfer)
10499 flow_dv_destroy_domain_policer_rule(&mtb->transfer);
10504 * Create specify domain meter policer rule.
10507 * Pointer to flow meter structure.
10509 * Pointer to DV meter table set.
10510 * @param[in] mtr_reg_c
10511 * Color match REG_C.
10514 * 0 on success, -1 otherwise.
10517 flow_dv_create_policer_forward_rule(struct mlx5_flow_meter *fm,
10518 struct mlx5_meter_domain_info *dtb,
10521 struct mlx5_flow_dv_match_params matcher = {
10522 .size = sizeof(matcher.buf),
10524 struct mlx5_flow_dv_match_params value = {
10525 .size = sizeof(value.buf),
10527 struct mlx5_meter_domains_infos *mtb = fm->mfts;
10528 void *actions[METER_ACTIONS];
10532 /* Create jump action. */
10533 if (!dtb->jump_actn)
10534 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
10535 (dtb->sfx_tbl->obj, &dtb->jump_actn);
10537 DRV_LOG(ERR, "Failed to create policer jump action.");
10540 for (i = 0; i < RTE_MTR_DROPPED; i++) {
10543 flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
10544 rte_col_2_mlx5_col(i), UINT8_MAX);
10545 if (mtb->count_actns[i])
10546 actions[j++] = mtb->count_actns[i];
10547 if (fm->action[i] == MTR_POLICER_ACTION_DROP)
10548 actions[j++] = mtb->drop_actn;
10550 actions[j++] = dtb->jump_actn;
10551 ret = mlx5_flow_os_create_flow(dtb->color_matcher,
10552 (void *)&value, j, actions,
10553 &dtb->policer_rules[i]);
10555 DRV_LOG(ERR, "Failed to create policer rule.");
10566 * Create policer rules.
10569 * Pointer to Ethernet device.
10571 * Pointer to flow meter structure.
10573 * Pointer to flow attributes.
10576 * 0 on success, -1 otherwise.
10579 flow_dv_create_policer_rules(struct rte_eth_dev *dev,
10580 struct mlx5_flow_meter *fm,
10581 const struct rte_flow_attr *attr)
10583 struct mlx5_priv *priv = dev->data->dev_private;
10584 struct mlx5_meter_domains_infos *mtb = fm->mfts;
10587 if (attr->egress) {
10588 ret = flow_dv_create_policer_forward_rule(fm, &mtb->egress,
10589 priv->mtr_color_reg);
10591 DRV_LOG(ERR, "Failed to create egress policer.");
10595 if (attr->ingress) {
10596 ret = flow_dv_create_policer_forward_rule(fm, &mtb->ingress,
10597 priv->mtr_color_reg);
10599 DRV_LOG(ERR, "Failed to create ingress policer.");
10603 if (attr->transfer) {
10604 ret = flow_dv_create_policer_forward_rule(fm, &mtb->transfer,
10605 priv->mtr_color_reg);
10607 DRV_LOG(ERR, "Failed to create transfer policer.");
10613 flow_dv_destroy_policer_rules(dev, fm, attr);
10618 * Query a devx counter.
10621 * Pointer to the Ethernet device structure.
10623 * Index to the flow counter.
10625 * Set to clear the counter statistics.
10627 * The statistics value of packets.
10628 * @param[out] bytes
10629 * The statistics value of bytes.
10632 * 0 on success, otherwise return -1.
10635 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
10636 uint64_t *pkts, uint64_t *bytes)
10638 struct mlx5_priv *priv = dev->data->dev_private;
10639 struct mlx5_flow_counter *cnt;
10640 uint64_t inn_pkts, inn_bytes;
10643 if (!priv->config.devx)
10646 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
10649 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
10650 *pkts = inn_pkts - cnt->hits;
10651 *bytes = inn_bytes - cnt->bytes;
10653 cnt->hits = inn_pkts;
10654 cnt->bytes = inn_bytes;
10660 * Get aged-out flows.
10663 * Pointer to the Ethernet device structure.
10664 * @param[in] context
10665 * The address of an array of pointers to the aged-out flows contexts.
10666 * @param[in] nb_contexts
10667 * The length of context array pointers.
10668 * @param[out] error
10669 * Perform verbose error reporting if not NULL. Initialized in case of
10673 * how many contexts get in success, otherwise negative errno value.
10674 * if nb_contexts is 0, return the amount of all aged contexts.
10675 * if nb_contexts is not 0 , return the amount of aged flows reported
10676 * in the context array.
10677 * @note: only stub for now
10680 flow_get_aged_flows(struct rte_eth_dev *dev,
10682 uint32_t nb_contexts,
10683 struct rte_flow_error *error)
10685 struct mlx5_priv *priv = dev->data->dev_private;
10686 struct mlx5_age_info *age_info;
10687 struct mlx5_age_param *age_param;
10688 struct mlx5_flow_counter *counter;
10691 if (nb_contexts && !context)
10692 return rte_flow_error_set(error, EINVAL,
10693 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10695 "Should assign at least one flow or"
10696 " context to get if nb_contexts != 0");
10697 age_info = GET_PORT_AGE_INFO(priv);
10698 rte_spinlock_lock(&age_info->aged_sl);
10699 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
10702 age_param = MLX5_CNT_TO_AGE(counter);
10703 context[nb_flows - 1] = age_param->context;
10704 if (!(--nb_contexts))
10708 rte_spinlock_unlock(&age_info->aged_sl);
10709 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
10714 * Mutex-protected thunk to lock-free __flow_dv_translate().
10717 flow_dv_translate(struct rte_eth_dev *dev,
10718 struct mlx5_flow *dev_flow,
10719 const struct rte_flow_attr *attr,
10720 const struct rte_flow_item items[],
10721 const struct rte_flow_action actions[],
10722 struct rte_flow_error *error)
10726 flow_dv_shared_lock(dev);
10727 ret = __flow_dv_translate(dev, dev_flow, attr, items, actions, error);
10728 flow_dv_shared_unlock(dev);
10733 * Mutex-protected thunk to lock-free __flow_dv_apply().
10736 flow_dv_apply(struct rte_eth_dev *dev,
10737 struct rte_flow *flow,
10738 struct rte_flow_error *error)
10742 flow_dv_shared_lock(dev);
10743 ret = __flow_dv_apply(dev, flow, error);
10744 flow_dv_shared_unlock(dev);
10749 * Mutex-protected thunk to lock-free __flow_dv_remove().
10752 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
10754 flow_dv_shared_lock(dev);
10755 __flow_dv_remove(dev, flow);
10756 flow_dv_shared_unlock(dev);
10760 * Mutex-protected thunk to lock-free __flow_dv_destroy().
10763 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
10765 flow_dv_shared_lock(dev);
10766 __flow_dv_destroy(dev, flow);
10767 flow_dv_shared_unlock(dev);
10771 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
10774 flow_dv_counter_allocate(struct rte_eth_dev *dev)
10778 flow_dv_shared_lock(dev);
10779 cnt = flow_dv_counter_alloc(dev, 0, 0, 1, 0);
10780 flow_dv_shared_unlock(dev);
10785 * Mutex-protected thunk to lock-free flow_dv_counter_release().
10788 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
10790 flow_dv_shared_lock(dev);
10791 flow_dv_counter_release(dev, cnt);
10792 flow_dv_shared_unlock(dev);
10795 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
10796 .validate = flow_dv_validate,
10797 .prepare = flow_dv_prepare,
10798 .translate = flow_dv_translate,
10799 .apply = flow_dv_apply,
10800 .remove = flow_dv_remove,
10801 .destroy = flow_dv_destroy,
10802 .query = flow_dv_query,
10803 .create_mtr_tbls = flow_dv_create_mtr_tbl,
10804 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbl,
10805 .create_policer_rules = flow_dv_create_policer_rules,
10806 .destroy_policer_rules = flow_dv_destroy_policer_rules,
10807 .counter_alloc = flow_dv_counter_allocate,
10808 .counter_free = flow_dv_counter_free,
10809 .counter_query = flow_dv_counter_query,
10810 .get_aged_flows = flow_get_aged_flows,
10813 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */