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 <ethdev_driver.h>
15 #include <rte_flow_driver.h>
16 #include <rte_malloc.h>
17 #include <rte_cycles.h>
18 #include <rte_bus_pci.h>
21 #include <rte_vxlan.h>
23 #include <rte_eal_paging.h>
26 #include <rte_mtr_driver.h>
27 #include <rte_tailq.h>
29 #include <mlx5_glue.h>
30 #include <mlx5_devx_cmds.h>
32 #include <mlx5_malloc.h>
34 #include "mlx5_defs.h"
36 #include "mlx5_common_os.h"
37 #include "mlx5_flow.h"
38 #include "mlx5_flow_os.h"
41 #include "rte_pmd_mlx5.h"
43 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
45 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
46 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
49 #ifndef HAVE_MLX5DV_DR_ESWITCH
50 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
51 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
55 #ifndef HAVE_MLX5DV_DR
56 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
59 /* VLAN header definitions */
60 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
61 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
62 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
63 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
64 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
79 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
80 struct mlx5_flow_tbl_resource *tbl);
83 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
84 uint32_t encap_decap_idx);
87 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
90 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss);
93 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
97 flow_dv_get_esw_manager_vport_id(struct rte_eth_dev *dev)
99 struct mlx5_priv *priv = dev->data->dev_private;
101 if (priv->pci_dev == NULL)
103 switch (priv->pci_dev->id.device_id) {
104 case PCI_DEVICE_ID_MELLANOX_CONNECTX5BF:
105 case PCI_DEVICE_ID_MELLANOX_CONNECTX6DXBF:
106 case PCI_DEVICE_ID_MELLANOX_CONNECTX7BF:
107 return (int16_t)0xfffe;
114 * Initialize flow attributes structure according to flow items' types.
116 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
117 * mode. For tunnel mode, the items to be modified are the outermost ones.
120 * Pointer to item specification.
122 * Pointer to flow attributes structure.
123 * @param[in] dev_flow
124 * Pointer to the sub flow.
125 * @param[in] tunnel_decap
126 * Whether action is after tunnel decapsulation.
129 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
130 struct mlx5_flow *dev_flow, bool tunnel_decap)
132 uint64_t layers = dev_flow->handle->layers;
135 * If layers is already initialized, it means this dev_flow is the
136 * suffix flow, the layers flags is set by the prefix flow. Need to
137 * use the layer flags from prefix flow as the suffix flow may not
138 * have the user defined items as the flow is split.
141 if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
143 else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
145 if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
147 else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
152 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
153 uint8_t next_protocol = 0xff;
154 switch (item->type) {
155 case RTE_FLOW_ITEM_TYPE_GRE:
156 case RTE_FLOW_ITEM_TYPE_NVGRE:
157 case RTE_FLOW_ITEM_TYPE_VXLAN:
158 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
159 case RTE_FLOW_ITEM_TYPE_GENEVE:
160 case RTE_FLOW_ITEM_TYPE_MPLS:
164 case RTE_FLOW_ITEM_TYPE_IPV4:
167 if (item->mask != NULL &&
168 ((const struct rte_flow_item_ipv4 *)
169 item->mask)->hdr.next_proto_id)
171 ((const struct rte_flow_item_ipv4 *)
172 (item->spec))->hdr.next_proto_id &
173 ((const struct rte_flow_item_ipv4 *)
174 (item->mask))->hdr.next_proto_id;
175 if ((next_protocol == IPPROTO_IPIP ||
176 next_protocol == IPPROTO_IPV6) && tunnel_decap)
179 case RTE_FLOW_ITEM_TYPE_IPV6:
182 if (item->mask != NULL &&
183 ((const struct rte_flow_item_ipv6 *)
184 item->mask)->hdr.proto)
186 ((const struct rte_flow_item_ipv6 *)
187 (item->spec))->hdr.proto &
188 ((const struct rte_flow_item_ipv6 *)
189 (item->mask))->hdr.proto;
190 if ((next_protocol == IPPROTO_IPIP ||
191 next_protocol == IPPROTO_IPV6) && tunnel_decap)
194 case RTE_FLOW_ITEM_TYPE_UDP:
198 case RTE_FLOW_ITEM_TYPE_TCP:
210 * Convert rte_mtr_color to mlx5 color.
219 rte_col_2_mlx5_col(enum rte_color rcol)
222 case RTE_COLOR_GREEN:
223 return MLX5_FLOW_COLOR_GREEN;
224 case RTE_COLOR_YELLOW:
225 return MLX5_FLOW_COLOR_YELLOW;
227 return MLX5_FLOW_COLOR_RED;
231 return MLX5_FLOW_COLOR_UNDEFINED;
234 struct field_modify_info {
235 uint32_t size; /* Size of field in protocol header, in bytes. */
236 uint32_t offset; /* Offset of field in protocol header, in bytes. */
237 enum mlx5_modification_field id;
240 struct field_modify_info modify_eth[] = {
241 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
242 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
243 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
244 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
248 struct field_modify_info modify_vlan_out_first_vid[] = {
249 /* Size in bits !!! */
250 {12, 0, MLX5_MODI_OUT_FIRST_VID},
254 struct field_modify_info modify_ipv4[] = {
255 {1, 1, MLX5_MODI_OUT_IP_DSCP},
256 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
257 {4, 12, MLX5_MODI_OUT_SIPV4},
258 {4, 16, MLX5_MODI_OUT_DIPV4},
262 struct field_modify_info modify_ipv6[] = {
263 {1, 0, MLX5_MODI_OUT_IP_DSCP},
264 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
265 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
266 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
267 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
268 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
269 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
270 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
271 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
272 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
276 struct field_modify_info modify_udp[] = {
277 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
278 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
282 struct field_modify_info modify_tcp[] = {
283 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
284 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
285 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
286 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
291 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
292 uint8_t next_protocol, uint64_t *item_flags,
295 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
296 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
297 if (next_protocol == IPPROTO_IPIP) {
298 *item_flags |= MLX5_FLOW_LAYER_IPIP;
301 if (next_protocol == IPPROTO_IPV6) {
302 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
307 static inline struct mlx5_hlist *
308 flow_dv_hlist_prepare(struct mlx5_dev_ctx_shared *sh, struct mlx5_hlist **phl,
309 const char *name, uint32_t size, bool direct_key,
310 bool lcores_share, void *ctx,
311 mlx5_list_create_cb cb_create,
312 mlx5_list_match_cb cb_match,
313 mlx5_list_remove_cb cb_remove,
314 mlx5_list_clone_cb cb_clone,
315 mlx5_list_clone_free_cb cb_clone_free)
317 struct mlx5_hlist *hl;
318 struct mlx5_hlist *expected = NULL;
319 char s[MLX5_NAME_SIZE];
321 hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
324 snprintf(s, sizeof(s), "%s_%s", sh->ibdev_name, name);
325 hl = mlx5_hlist_create(s, size, direct_key, lcores_share,
326 ctx, cb_create, cb_match, cb_remove, cb_clone,
329 DRV_LOG(ERR, "%s hash creation failed", name);
333 if (!__atomic_compare_exchange_n(phl, &expected, hl, false,
336 mlx5_hlist_destroy(hl);
337 hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
342 /* Update VLAN's VID/PCP based on input rte_flow_action.
345 * Pointer to struct rte_flow_action.
347 * Pointer to struct rte_vlan_hdr.
350 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
351 struct rte_vlan_hdr *vlan)
354 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
356 ((const struct rte_flow_action_of_set_vlan_pcp *)
357 action->conf)->vlan_pcp;
358 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
359 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
360 vlan->vlan_tci |= vlan_tci;
361 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
362 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
363 vlan->vlan_tci |= rte_be_to_cpu_16
364 (((const struct rte_flow_action_of_set_vlan_vid *)
365 action->conf)->vlan_vid);
370 * Fetch 1, 2, 3 or 4 byte field from the byte array
371 * and return as unsigned integer in host-endian format.
374 * Pointer to data array.
376 * Size of field to extract.
379 * converted field in host endian format.
381 static inline uint32_t
382 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
391 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
394 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
395 ret = (ret << 8) | *(data + sizeof(uint16_t));
398 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
409 * Convert modify-header action to DV specification.
411 * Data length of each action is determined by provided field description
412 * and the item mask. Data bit offset and width of each action is determined
413 * by provided item mask.
416 * Pointer to item specification.
418 * Pointer to field modification information.
419 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
420 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
421 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
423 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
424 * Negative offset value sets the same offset as source offset.
425 * size field is ignored, value is taken from source field.
426 * @param[in,out] resource
427 * Pointer to the modify-header resource.
429 * Type of modification.
431 * Pointer to the error structure.
434 * 0 on success, a negative errno value otherwise and rte_errno is set.
437 flow_dv_convert_modify_action(struct rte_flow_item *item,
438 struct field_modify_info *field,
439 struct field_modify_info *dcopy,
440 struct mlx5_flow_dv_modify_hdr_resource *resource,
441 uint32_t type, struct rte_flow_error *error)
443 uint32_t i = resource->actions_num;
444 struct mlx5_modification_cmd *actions = resource->actions;
445 uint32_t carry_b = 0;
448 * The item and mask are provided in big-endian format.
449 * The fields should be presented as in big-endian format either.
450 * Mask must be always present, it defines the actual field width.
452 MLX5_ASSERT(item->mask);
453 MLX5_ASSERT(field->size);
459 bool next_field = true;
460 bool next_dcopy = true;
462 if (i >= MLX5_MAX_MODIFY_NUM)
463 return rte_flow_error_set(error, EINVAL,
464 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
465 "too many items to modify");
466 /* Fetch variable byte size mask from the array. */
467 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
468 field->offset, field->size);
473 /* Deduce actual data width in bits from mask value. */
474 off_b = rte_bsf32(mask) + carry_b;
475 size_b = sizeof(uint32_t) * CHAR_BIT -
476 off_b - __builtin_clz(mask);
478 actions[i] = (struct mlx5_modification_cmd) {
482 .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
485 if (type == MLX5_MODIFICATION_TYPE_COPY) {
487 actions[i].dst_field = dcopy->id;
488 actions[i].dst_offset =
489 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
490 /* Convert entire record to big-endian format. */
491 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
493 * Destination field overflow. Copy leftovers of
494 * a source field to the next destination field.
497 if ((size_b > dcopy->size * CHAR_BIT - dcopy->offset) &&
500 dcopy->size * CHAR_BIT - dcopy->offset;
501 carry_b = actions[i].length;
505 * Not enough bits in a source filed to fill a
506 * destination field. Switch to the next source.
508 if ((size_b < dcopy->size * CHAR_BIT - dcopy->offset) &&
509 (size_b == field->size * CHAR_BIT - off_b)) {
511 field->size * CHAR_BIT - off_b;
512 dcopy->offset += actions[i].length;
518 MLX5_ASSERT(item->spec);
519 data = flow_dv_fetch_field((const uint8_t *)item->spec +
520 field->offset, field->size);
521 /* Shift out the trailing masked bits from data. */
522 data = (data & mask) >> off_b;
523 actions[i].data1 = rte_cpu_to_be_32(data);
525 /* Convert entire record to expected big-endian format. */
526 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
530 } while (field->size);
531 if (resource->actions_num == i)
532 return rte_flow_error_set(error, EINVAL,
533 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
534 "invalid modification flow item");
535 resource->actions_num = i;
540 * Convert modify-header set IPv4 address action to DV specification.
542 * @param[in,out] resource
543 * Pointer to the modify-header resource.
545 * Pointer to action specification.
547 * Pointer to the error structure.
550 * 0 on success, a negative errno value otherwise and rte_errno is set.
553 flow_dv_convert_action_modify_ipv4
554 (struct mlx5_flow_dv_modify_hdr_resource *resource,
555 const struct rte_flow_action *action,
556 struct rte_flow_error *error)
558 const struct rte_flow_action_set_ipv4 *conf =
559 (const struct rte_flow_action_set_ipv4 *)(action->conf);
560 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
561 struct rte_flow_item_ipv4 ipv4;
562 struct rte_flow_item_ipv4 ipv4_mask;
564 memset(&ipv4, 0, sizeof(ipv4));
565 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
566 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
567 ipv4.hdr.src_addr = conf->ipv4_addr;
568 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
570 ipv4.hdr.dst_addr = conf->ipv4_addr;
571 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
574 item.mask = &ipv4_mask;
575 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
576 MLX5_MODIFICATION_TYPE_SET, error);
580 * Convert modify-header set IPv6 address action to DV specification.
582 * @param[in,out] resource
583 * Pointer to the modify-header resource.
585 * Pointer to action specification.
587 * Pointer to the error structure.
590 * 0 on success, a negative errno value otherwise and rte_errno is set.
593 flow_dv_convert_action_modify_ipv6
594 (struct mlx5_flow_dv_modify_hdr_resource *resource,
595 const struct rte_flow_action *action,
596 struct rte_flow_error *error)
598 const struct rte_flow_action_set_ipv6 *conf =
599 (const struct rte_flow_action_set_ipv6 *)(action->conf);
600 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
601 struct rte_flow_item_ipv6 ipv6;
602 struct rte_flow_item_ipv6 ipv6_mask;
604 memset(&ipv6, 0, sizeof(ipv6));
605 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
606 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
607 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
608 sizeof(ipv6.hdr.src_addr));
609 memcpy(&ipv6_mask.hdr.src_addr,
610 &rte_flow_item_ipv6_mask.hdr.src_addr,
611 sizeof(ipv6.hdr.src_addr));
613 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
614 sizeof(ipv6.hdr.dst_addr));
615 memcpy(&ipv6_mask.hdr.dst_addr,
616 &rte_flow_item_ipv6_mask.hdr.dst_addr,
617 sizeof(ipv6.hdr.dst_addr));
620 item.mask = &ipv6_mask;
621 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
622 MLX5_MODIFICATION_TYPE_SET, error);
626 * Convert modify-header set MAC address action to DV specification.
628 * @param[in,out] resource
629 * Pointer to the modify-header resource.
631 * Pointer to action specification.
633 * Pointer to the error structure.
636 * 0 on success, a negative errno value otherwise and rte_errno is set.
639 flow_dv_convert_action_modify_mac
640 (struct mlx5_flow_dv_modify_hdr_resource *resource,
641 const struct rte_flow_action *action,
642 struct rte_flow_error *error)
644 const struct rte_flow_action_set_mac *conf =
645 (const struct rte_flow_action_set_mac *)(action->conf);
646 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
647 struct rte_flow_item_eth eth;
648 struct rte_flow_item_eth eth_mask;
650 memset(ð, 0, sizeof(eth));
651 memset(ð_mask, 0, sizeof(eth_mask));
652 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
653 memcpy(ð.src.addr_bytes, &conf->mac_addr,
654 sizeof(eth.src.addr_bytes));
655 memcpy(ð_mask.src.addr_bytes,
656 &rte_flow_item_eth_mask.src.addr_bytes,
657 sizeof(eth_mask.src.addr_bytes));
659 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
660 sizeof(eth.dst.addr_bytes));
661 memcpy(ð_mask.dst.addr_bytes,
662 &rte_flow_item_eth_mask.dst.addr_bytes,
663 sizeof(eth_mask.dst.addr_bytes));
666 item.mask = ð_mask;
667 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
668 MLX5_MODIFICATION_TYPE_SET, error);
672 * Convert modify-header set VLAN VID action to DV specification.
674 * @param[in,out] resource
675 * Pointer to the modify-header resource.
677 * Pointer to action specification.
679 * Pointer to the error structure.
682 * 0 on success, a negative errno value otherwise and rte_errno is set.
685 flow_dv_convert_action_modify_vlan_vid
686 (struct mlx5_flow_dv_modify_hdr_resource *resource,
687 const struct rte_flow_action *action,
688 struct rte_flow_error *error)
690 const struct rte_flow_action_of_set_vlan_vid *conf =
691 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
692 int i = resource->actions_num;
693 struct mlx5_modification_cmd *actions = resource->actions;
694 struct field_modify_info *field = modify_vlan_out_first_vid;
696 if (i >= MLX5_MAX_MODIFY_NUM)
697 return rte_flow_error_set(error, EINVAL,
698 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
699 "too many items to modify");
700 actions[i] = (struct mlx5_modification_cmd) {
701 .action_type = MLX5_MODIFICATION_TYPE_SET,
703 .length = field->size,
704 .offset = field->offset,
706 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
707 actions[i].data1 = conf->vlan_vid;
708 actions[i].data1 = actions[i].data1 << 16;
709 resource->actions_num = ++i;
714 * Convert modify-header set TP action to DV specification.
716 * @param[in,out] resource
717 * Pointer to the modify-header resource.
719 * Pointer to action specification.
721 * Pointer to rte_flow_item objects list.
723 * Pointer to flow attributes structure.
724 * @param[in] dev_flow
725 * Pointer to the sub flow.
726 * @param[in] tunnel_decap
727 * Whether action is after tunnel decapsulation.
729 * Pointer to the error structure.
732 * 0 on success, a negative errno value otherwise and rte_errno is set.
735 flow_dv_convert_action_modify_tp
736 (struct mlx5_flow_dv_modify_hdr_resource *resource,
737 const struct rte_flow_action *action,
738 const struct rte_flow_item *items,
739 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
740 bool tunnel_decap, struct rte_flow_error *error)
742 const struct rte_flow_action_set_tp *conf =
743 (const struct rte_flow_action_set_tp *)(action->conf);
744 struct rte_flow_item item;
745 struct rte_flow_item_udp udp;
746 struct rte_flow_item_udp udp_mask;
747 struct rte_flow_item_tcp tcp;
748 struct rte_flow_item_tcp tcp_mask;
749 struct field_modify_info *field;
752 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
754 memset(&udp, 0, sizeof(udp));
755 memset(&udp_mask, 0, sizeof(udp_mask));
756 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
757 udp.hdr.src_port = conf->port;
758 udp_mask.hdr.src_port =
759 rte_flow_item_udp_mask.hdr.src_port;
761 udp.hdr.dst_port = conf->port;
762 udp_mask.hdr.dst_port =
763 rte_flow_item_udp_mask.hdr.dst_port;
765 item.type = RTE_FLOW_ITEM_TYPE_UDP;
767 item.mask = &udp_mask;
770 MLX5_ASSERT(attr->tcp);
771 memset(&tcp, 0, sizeof(tcp));
772 memset(&tcp_mask, 0, sizeof(tcp_mask));
773 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
774 tcp.hdr.src_port = conf->port;
775 tcp_mask.hdr.src_port =
776 rte_flow_item_tcp_mask.hdr.src_port;
778 tcp.hdr.dst_port = conf->port;
779 tcp_mask.hdr.dst_port =
780 rte_flow_item_tcp_mask.hdr.dst_port;
782 item.type = RTE_FLOW_ITEM_TYPE_TCP;
784 item.mask = &tcp_mask;
787 return flow_dv_convert_modify_action(&item, field, NULL, resource,
788 MLX5_MODIFICATION_TYPE_SET, error);
792 * Convert modify-header set TTL action to DV specification.
794 * @param[in,out] resource
795 * Pointer to the modify-header resource.
797 * Pointer to action specification.
799 * Pointer to rte_flow_item objects list.
801 * Pointer to flow attributes structure.
802 * @param[in] dev_flow
803 * Pointer to the sub flow.
804 * @param[in] tunnel_decap
805 * Whether action is after tunnel decapsulation.
807 * Pointer to the error structure.
810 * 0 on success, a negative errno value otherwise and rte_errno is set.
813 flow_dv_convert_action_modify_ttl
814 (struct mlx5_flow_dv_modify_hdr_resource *resource,
815 const struct rte_flow_action *action,
816 const struct rte_flow_item *items,
817 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
818 bool tunnel_decap, struct rte_flow_error *error)
820 const struct rte_flow_action_set_ttl *conf =
821 (const struct rte_flow_action_set_ttl *)(action->conf);
822 struct rte_flow_item item;
823 struct rte_flow_item_ipv4 ipv4;
824 struct rte_flow_item_ipv4 ipv4_mask;
825 struct rte_flow_item_ipv6 ipv6;
826 struct rte_flow_item_ipv6 ipv6_mask;
827 struct field_modify_info *field;
830 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
832 memset(&ipv4, 0, sizeof(ipv4));
833 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
834 ipv4.hdr.time_to_live = conf->ttl_value;
835 ipv4_mask.hdr.time_to_live = 0xFF;
836 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
838 item.mask = &ipv4_mask;
841 MLX5_ASSERT(attr->ipv6);
842 memset(&ipv6, 0, sizeof(ipv6));
843 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
844 ipv6.hdr.hop_limits = conf->ttl_value;
845 ipv6_mask.hdr.hop_limits = 0xFF;
846 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
848 item.mask = &ipv6_mask;
851 return flow_dv_convert_modify_action(&item, field, NULL, resource,
852 MLX5_MODIFICATION_TYPE_SET, error);
856 * Convert modify-header decrement TTL action to DV specification.
858 * @param[in,out] resource
859 * Pointer to the modify-header resource.
861 * Pointer to action specification.
863 * Pointer to rte_flow_item objects list.
865 * Pointer to flow attributes structure.
866 * @param[in] dev_flow
867 * Pointer to the sub flow.
868 * @param[in] tunnel_decap
869 * Whether action is after tunnel decapsulation.
871 * Pointer to the error structure.
874 * 0 on success, a negative errno value otherwise and rte_errno is set.
877 flow_dv_convert_action_modify_dec_ttl
878 (struct mlx5_flow_dv_modify_hdr_resource *resource,
879 const struct rte_flow_item *items,
880 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
881 bool tunnel_decap, struct rte_flow_error *error)
883 struct rte_flow_item item;
884 struct rte_flow_item_ipv4 ipv4;
885 struct rte_flow_item_ipv4 ipv4_mask;
886 struct rte_flow_item_ipv6 ipv6;
887 struct rte_flow_item_ipv6 ipv6_mask;
888 struct field_modify_info *field;
891 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
893 memset(&ipv4, 0, sizeof(ipv4));
894 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
895 ipv4.hdr.time_to_live = 0xFF;
896 ipv4_mask.hdr.time_to_live = 0xFF;
897 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
899 item.mask = &ipv4_mask;
902 MLX5_ASSERT(attr->ipv6);
903 memset(&ipv6, 0, sizeof(ipv6));
904 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
905 ipv6.hdr.hop_limits = 0xFF;
906 ipv6_mask.hdr.hop_limits = 0xFF;
907 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
909 item.mask = &ipv6_mask;
912 return flow_dv_convert_modify_action(&item, field, NULL, resource,
913 MLX5_MODIFICATION_TYPE_ADD, error);
917 * Convert modify-header increment/decrement TCP Sequence number
918 * to DV specification.
920 * @param[in,out] resource
921 * Pointer to the modify-header resource.
923 * Pointer to action specification.
925 * Pointer to the error structure.
928 * 0 on success, a negative errno value otherwise and rte_errno is set.
931 flow_dv_convert_action_modify_tcp_seq
932 (struct mlx5_flow_dv_modify_hdr_resource *resource,
933 const struct rte_flow_action *action,
934 struct rte_flow_error *error)
936 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
937 uint64_t value = rte_be_to_cpu_32(*conf);
938 struct rte_flow_item item;
939 struct rte_flow_item_tcp tcp;
940 struct rte_flow_item_tcp tcp_mask;
942 memset(&tcp, 0, sizeof(tcp));
943 memset(&tcp_mask, 0, sizeof(tcp_mask));
944 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
946 * The HW has no decrement operation, only increment operation.
947 * To simulate decrement X from Y using increment operation
948 * we need to add UINT32_MAX X times to Y.
949 * Each adding of UINT32_MAX decrements Y by 1.
952 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
953 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
954 item.type = RTE_FLOW_ITEM_TYPE_TCP;
956 item.mask = &tcp_mask;
957 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
958 MLX5_MODIFICATION_TYPE_ADD, error);
962 * Convert modify-header increment/decrement TCP Acknowledgment number
963 * to DV specification.
965 * @param[in,out] resource
966 * Pointer to the modify-header resource.
968 * Pointer to action specification.
970 * Pointer to the error structure.
973 * 0 on success, a negative errno value otherwise and rte_errno is set.
976 flow_dv_convert_action_modify_tcp_ack
977 (struct mlx5_flow_dv_modify_hdr_resource *resource,
978 const struct rte_flow_action *action,
979 struct rte_flow_error *error)
981 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
982 uint64_t value = rte_be_to_cpu_32(*conf);
983 struct rte_flow_item item;
984 struct rte_flow_item_tcp tcp;
985 struct rte_flow_item_tcp tcp_mask;
987 memset(&tcp, 0, sizeof(tcp));
988 memset(&tcp_mask, 0, sizeof(tcp_mask));
989 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
991 * The HW has no decrement operation, only increment operation.
992 * To simulate decrement X from Y using increment operation
993 * we need to add UINT32_MAX X times to Y.
994 * Each adding of UINT32_MAX decrements Y by 1.
997 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
998 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
999 item.type = RTE_FLOW_ITEM_TYPE_TCP;
1001 item.mask = &tcp_mask;
1002 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
1003 MLX5_MODIFICATION_TYPE_ADD, error);
1006 static enum mlx5_modification_field reg_to_field[] = {
1007 [REG_NON] = MLX5_MODI_OUT_NONE,
1008 [REG_A] = MLX5_MODI_META_DATA_REG_A,
1009 [REG_B] = MLX5_MODI_META_DATA_REG_B,
1010 [REG_C_0] = MLX5_MODI_META_REG_C_0,
1011 [REG_C_1] = MLX5_MODI_META_REG_C_1,
1012 [REG_C_2] = MLX5_MODI_META_REG_C_2,
1013 [REG_C_3] = MLX5_MODI_META_REG_C_3,
1014 [REG_C_4] = MLX5_MODI_META_REG_C_4,
1015 [REG_C_5] = MLX5_MODI_META_REG_C_5,
1016 [REG_C_6] = MLX5_MODI_META_REG_C_6,
1017 [REG_C_7] = MLX5_MODI_META_REG_C_7,
1021 * Convert register set to DV specification.
1023 * @param[in,out] resource
1024 * Pointer to the modify-header resource.
1026 * Pointer to action specification.
1028 * Pointer to the error structure.
1031 * 0 on success, a negative errno value otherwise and rte_errno is set.
1034 flow_dv_convert_action_set_reg
1035 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1036 const struct rte_flow_action *action,
1037 struct rte_flow_error *error)
1039 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
1040 struct mlx5_modification_cmd *actions = resource->actions;
1041 uint32_t i = resource->actions_num;
1043 if (i >= MLX5_MAX_MODIFY_NUM)
1044 return rte_flow_error_set(error, EINVAL,
1045 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1046 "too many items to modify");
1047 MLX5_ASSERT(conf->id != REG_NON);
1048 MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
1049 actions[i] = (struct mlx5_modification_cmd) {
1050 .action_type = MLX5_MODIFICATION_TYPE_SET,
1051 .field = reg_to_field[conf->id],
1052 .offset = conf->offset,
1053 .length = conf->length,
1055 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
1056 actions[i].data1 = rte_cpu_to_be_32(conf->data);
1058 resource->actions_num = i;
1063 * Convert SET_TAG action to DV specification.
1066 * Pointer to the rte_eth_dev structure.
1067 * @param[in,out] resource
1068 * Pointer to the modify-header resource.
1070 * Pointer to action specification.
1072 * Pointer to the error structure.
1075 * 0 on success, a negative errno value otherwise and rte_errno is set.
1078 flow_dv_convert_action_set_tag
1079 (struct rte_eth_dev *dev,
1080 struct mlx5_flow_dv_modify_hdr_resource *resource,
1081 const struct rte_flow_action_set_tag *conf,
1082 struct rte_flow_error *error)
1084 rte_be32_t data = rte_cpu_to_be_32(conf->data);
1085 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1086 struct rte_flow_item item = {
1090 struct field_modify_info reg_c_x[] = {
1093 enum mlx5_modification_field reg_type;
1096 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1099 MLX5_ASSERT(ret != REG_NON);
1100 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1101 reg_type = reg_to_field[ret];
1102 MLX5_ASSERT(reg_type > 0);
1103 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1104 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1105 MLX5_MODIFICATION_TYPE_SET, error);
1109 * Convert internal COPY_REG action to DV specification.
1112 * Pointer to the rte_eth_dev structure.
1113 * @param[in,out] res
1114 * Pointer to the modify-header resource.
1116 * Pointer to action specification.
1118 * Pointer to the error structure.
1121 * 0 on success, a negative errno value otherwise and rte_errno is set.
1124 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1125 struct mlx5_flow_dv_modify_hdr_resource *res,
1126 const struct rte_flow_action *action,
1127 struct rte_flow_error *error)
1129 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1130 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1131 struct rte_flow_item item = {
1135 struct field_modify_info reg_src[] = {
1136 {4, 0, reg_to_field[conf->src]},
1139 struct field_modify_info reg_dst = {
1141 .id = reg_to_field[conf->dst],
1143 /* Adjust reg_c[0] usage according to reported mask. */
1144 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1145 struct mlx5_priv *priv = dev->data->dev_private;
1146 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1148 MLX5_ASSERT(reg_c0);
1149 MLX5_ASSERT(priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1150 if (conf->dst == REG_C_0) {
1151 /* Copy to reg_c[0], within mask only. */
1152 reg_dst.offset = rte_bsf32(reg_c0);
1153 mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1156 mask = rte_cpu_to_be_32(reg_c0);
1159 return flow_dv_convert_modify_action(&item,
1160 reg_src, ®_dst, res,
1161 MLX5_MODIFICATION_TYPE_COPY,
1166 * Convert MARK action to DV specification. This routine is used
1167 * in extensive metadata only and requires metadata register to be
1168 * handled. In legacy mode hardware tag resource is engaged.
1171 * Pointer to the rte_eth_dev structure.
1173 * Pointer to MARK action specification.
1174 * @param[in,out] resource
1175 * Pointer to the modify-header resource.
1177 * Pointer to the error structure.
1180 * 0 on success, a negative errno value otherwise and rte_errno is set.
1183 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1184 const struct rte_flow_action_mark *conf,
1185 struct mlx5_flow_dv_modify_hdr_resource *resource,
1186 struct rte_flow_error *error)
1188 struct mlx5_priv *priv = dev->data->dev_private;
1189 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1190 priv->sh->dv_mark_mask);
1191 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1192 struct rte_flow_item item = {
1196 struct field_modify_info reg_c_x[] = {
1202 return rte_flow_error_set(error, EINVAL,
1203 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1204 NULL, "zero mark action mask");
1205 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1208 MLX5_ASSERT(reg > 0);
1209 if (reg == REG_C_0) {
1210 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1211 uint32_t shl_c0 = rte_bsf32(msk_c0);
1213 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1214 mask = rte_cpu_to_be_32(mask) & msk_c0;
1215 mask = rte_cpu_to_be_32(mask << shl_c0);
1217 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1218 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1219 MLX5_MODIFICATION_TYPE_SET, error);
1223 * Get metadata register index for specified steering domain.
1226 * Pointer to the rte_eth_dev structure.
1228 * Attributes of flow to determine steering domain.
1230 * Pointer to the error structure.
1233 * positive index on success, a negative errno value otherwise
1234 * and rte_errno is set.
1236 static enum modify_reg
1237 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1238 const struct rte_flow_attr *attr,
1239 struct rte_flow_error *error)
1242 mlx5_flow_get_reg_id(dev, attr->transfer ?
1246 MLX5_METADATA_RX, 0, error);
1248 return rte_flow_error_set(error,
1249 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1250 NULL, "unavailable "
1251 "metadata register");
1256 * Convert SET_META action to DV specification.
1259 * Pointer to the rte_eth_dev structure.
1260 * @param[in,out] resource
1261 * Pointer to the modify-header resource.
1263 * Attributes of flow that includes this item.
1265 * Pointer to action specification.
1267 * Pointer to the error structure.
1270 * 0 on success, a negative errno value otherwise and rte_errno is set.
1273 flow_dv_convert_action_set_meta
1274 (struct rte_eth_dev *dev,
1275 struct mlx5_flow_dv_modify_hdr_resource *resource,
1276 const struct rte_flow_attr *attr,
1277 const struct rte_flow_action_set_meta *conf,
1278 struct rte_flow_error *error)
1280 uint32_t mask = rte_cpu_to_be_32(conf->mask);
1281 uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1282 struct rte_flow_item item = {
1286 struct field_modify_info reg_c_x[] = {
1289 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1293 MLX5_ASSERT(reg != REG_NON);
1294 if (reg == REG_C_0) {
1295 struct mlx5_priv *priv = dev->data->dev_private;
1296 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1297 uint32_t shl_c0 = rte_bsf32(msk_c0);
1299 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1300 mask = rte_cpu_to_be_32(mask) & msk_c0;
1301 mask = rte_cpu_to_be_32(mask << shl_c0);
1303 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1304 /* The routine expects parameters in memory as big-endian ones. */
1305 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1306 MLX5_MODIFICATION_TYPE_SET, error);
1310 * Convert modify-header set IPv4 DSCP action to DV specification.
1312 * @param[in,out] resource
1313 * Pointer to the modify-header resource.
1315 * Pointer to action specification.
1317 * Pointer to the error structure.
1320 * 0 on success, a negative errno value otherwise and rte_errno is set.
1323 flow_dv_convert_action_modify_ipv4_dscp
1324 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1325 const struct rte_flow_action *action,
1326 struct rte_flow_error *error)
1328 const struct rte_flow_action_set_dscp *conf =
1329 (const struct rte_flow_action_set_dscp *)(action->conf);
1330 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1331 struct rte_flow_item_ipv4 ipv4;
1332 struct rte_flow_item_ipv4 ipv4_mask;
1334 memset(&ipv4, 0, sizeof(ipv4));
1335 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1336 ipv4.hdr.type_of_service = conf->dscp;
1337 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1339 item.mask = &ipv4_mask;
1340 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1341 MLX5_MODIFICATION_TYPE_SET, error);
1345 * Convert modify-header set IPv6 DSCP action to DV specification.
1347 * @param[in,out] resource
1348 * Pointer to the modify-header resource.
1350 * Pointer to action specification.
1352 * Pointer to the error structure.
1355 * 0 on success, a negative errno value otherwise and rte_errno is set.
1358 flow_dv_convert_action_modify_ipv6_dscp
1359 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1360 const struct rte_flow_action *action,
1361 struct rte_flow_error *error)
1363 const struct rte_flow_action_set_dscp *conf =
1364 (const struct rte_flow_action_set_dscp *)(action->conf);
1365 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1366 struct rte_flow_item_ipv6 ipv6;
1367 struct rte_flow_item_ipv6 ipv6_mask;
1369 memset(&ipv6, 0, sizeof(ipv6));
1370 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1372 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1373 * rdma-core only accept the DSCP bits byte aligned start from
1374 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1375 * bits in IPv6 case as rdma-core requires byte aligned value.
1377 ipv6.hdr.vtc_flow = conf->dscp;
1378 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1380 item.mask = &ipv6_mask;
1381 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1382 MLX5_MODIFICATION_TYPE_SET, error);
1386 mlx5_flow_item_field_width(struct rte_eth_dev *dev,
1387 enum rte_flow_field_id field, int inherit,
1388 const struct rte_flow_attr *attr,
1389 struct rte_flow_error *error)
1391 struct mlx5_priv *priv = dev->data->dev_private;
1394 case RTE_FLOW_FIELD_START:
1396 case RTE_FLOW_FIELD_MAC_DST:
1397 case RTE_FLOW_FIELD_MAC_SRC:
1399 case RTE_FLOW_FIELD_VLAN_TYPE:
1401 case RTE_FLOW_FIELD_VLAN_ID:
1403 case RTE_FLOW_FIELD_MAC_TYPE:
1405 case RTE_FLOW_FIELD_IPV4_DSCP:
1407 case RTE_FLOW_FIELD_IPV4_TTL:
1409 case RTE_FLOW_FIELD_IPV4_SRC:
1410 case RTE_FLOW_FIELD_IPV4_DST:
1412 case RTE_FLOW_FIELD_IPV6_DSCP:
1414 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1416 case RTE_FLOW_FIELD_IPV6_SRC:
1417 case RTE_FLOW_FIELD_IPV6_DST:
1419 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1420 case RTE_FLOW_FIELD_TCP_PORT_DST:
1422 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1423 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1425 case RTE_FLOW_FIELD_TCP_FLAGS:
1427 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1428 case RTE_FLOW_FIELD_UDP_PORT_DST:
1430 case RTE_FLOW_FIELD_VXLAN_VNI:
1431 case RTE_FLOW_FIELD_GENEVE_VNI:
1433 case RTE_FLOW_FIELD_GTP_TEID:
1434 case RTE_FLOW_FIELD_TAG:
1436 case RTE_FLOW_FIELD_MARK:
1437 return __builtin_popcount(priv->sh->dv_mark_mask);
1438 case RTE_FLOW_FIELD_META:
1439 return (flow_dv_get_metadata_reg(dev, attr, error) == REG_C_0) ?
1440 __builtin_popcount(priv->sh->dv_meta_mask) : 32;
1441 case RTE_FLOW_FIELD_POINTER:
1442 case RTE_FLOW_FIELD_VALUE:
1443 return inherit < 0 ? 0 : inherit;
1451 mlx5_flow_field_id_to_modify_info
1452 (const struct rte_flow_action_modify_data *data,
1453 struct field_modify_info *info, uint32_t *mask,
1454 uint32_t width, uint32_t *shift, struct rte_eth_dev *dev,
1455 const struct rte_flow_attr *attr, struct rte_flow_error *error)
1457 struct mlx5_priv *priv = dev->data->dev_private;
1461 switch (data->field) {
1462 case RTE_FLOW_FIELD_START:
1463 /* not supported yet */
1466 case RTE_FLOW_FIELD_MAC_DST:
1467 off = data->offset > 16 ? data->offset - 16 : 0;
1469 if (data->offset < 16) {
1470 info[idx] = (struct field_modify_info){2, 4,
1471 MLX5_MODI_OUT_DMAC_15_0};
1473 mask[1] = rte_cpu_to_be_16(0xffff >>
1477 mask[1] = RTE_BE16(0xffff);
1484 info[idx] = (struct field_modify_info){4, 0,
1485 MLX5_MODI_OUT_DMAC_47_16};
1486 mask[0] = rte_cpu_to_be_32((0xffffffff >>
1487 (32 - width)) << off);
1489 if (data->offset < 16)
1490 info[idx++] = (struct field_modify_info){2, 0,
1491 MLX5_MODI_OUT_DMAC_15_0};
1492 info[idx] = (struct field_modify_info){4, off,
1493 MLX5_MODI_OUT_DMAC_47_16};
1496 case RTE_FLOW_FIELD_MAC_SRC:
1497 off = data->offset > 16 ? data->offset - 16 : 0;
1499 if (data->offset < 16) {
1500 info[idx] = (struct field_modify_info){2, 4,
1501 MLX5_MODI_OUT_SMAC_15_0};
1503 mask[1] = rte_cpu_to_be_16(0xffff >>
1507 mask[1] = RTE_BE16(0xffff);
1514 info[idx] = (struct field_modify_info){4, 0,
1515 MLX5_MODI_OUT_SMAC_47_16};
1516 mask[0] = rte_cpu_to_be_32((0xffffffff >>
1517 (32 - width)) << off);
1519 if (data->offset < 16)
1520 info[idx++] = (struct field_modify_info){2, 0,
1521 MLX5_MODI_OUT_SMAC_15_0};
1522 info[idx] = (struct field_modify_info){4, off,
1523 MLX5_MODI_OUT_SMAC_47_16};
1526 case RTE_FLOW_FIELD_VLAN_TYPE:
1527 /* not supported yet */
1529 case RTE_FLOW_FIELD_VLAN_ID:
1530 info[idx] = (struct field_modify_info){2, 0,
1531 MLX5_MODI_OUT_FIRST_VID};
1533 mask[idx] = rte_cpu_to_be_16(0x0fff >> (12 - width));
1535 case RTE_FLOW_FIELD_MAC_TYPE:
1536 info[idx] = (struct field_modify_info){2, 0,
1537 MLX5_MODI_OUT_ETHERTYPE};
1539 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1541 case RTE_FLOW_FIELD_IPV4_DSCP:
1542 info[idx] = (struct field_modify_info){1, 0,
1543 MLX5_MODI_OUT_IP_DSCP};
1545 mask[idx] = 0x3f >> (6 - width);
1547 case RTE_FLOW_FIELD_IPV4_TTL:
1548 info[idx] = (struct field_modify_info){1, 0,
1549 MLX5_MODI_OUT_IPV4_TTL};
1551 mask[idx] = 0xff >> (8 - width);
1553 case RTE_FLOW_FIELD_IPV4_SRC:
1554 info[idx] = (struct field_modify_info){4, 0,
1555 MLX5_MODI_OUT_SIPV4};
1557 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1560 case RTE_FLOW_FIELD_IPV4_DST:
1561 info[idx] = (struct field_modify_info){4, 0,
1562 MLX5_MODI_OUT_DIPV4};
1564 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1567 case RTE_FLOW_FIELD_IPV6_DSCP:
1568 info[idx] = (struct field_modify_info){1, 0,
1569 MLX5_MODI_OUT_IP_DSCP};
1571 mask[idx] = 0x3f >> (6 - width);
1573 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1574 info[idx] = (struct field_modify_info){1, 0,
1575 MLX5_MODI_OUT_IPV6_HOPLIMIT};
1577 mask[idx] = 0xff >> (8 - width);
1579 case RTE_FLOW_FIELD_IPV6_SRC:
1581 if (data->offset < 32) {
1582 info[idx] = (struct field_modify_info){4, 12,
1583 MLX5_MODI_OUT_SIPV6_31_0};
1586 rte_cpu_to_be_32(0xffffffff >>
1590 mask[3] = RTE_BE32(0xffffffff);
1597 if (data->offset < 64) {
1598 info[idx] = (struct field_modify_info){4, 8,
1599 MLX5_MODI_OUT_SIPV6_63_32};
1602 rte_cpu_to_be_32(0xffffffff >>
1606 mask[2] = RTE_BE32(0xffffffff);
1613 if (data->offset < 96) {
1614 info[idx] = (struct field_modify_info){4, 4,
1615 MLX5_MODI_OUT_SIPV6_95_64};
1618 rte_cpu_to_be_32(0xffffffff >>
1622 mask[1] = RTE_BE32(0xffffffff);
1629 info[idx] = (struct field_modify_info){4, 0,
1630 MLX5_MODI_OUT_SIPV6_127_96};
1631 mask[0] = rte_cpu_to_be_32(0xffffffff >> (32 - width));
1633 if (data->offset < 32)
1634 info[idx++] = (struct field_modify_info){4, 0,
1635 MLX5_MODI_OUT_SIPV6_31_0};
1636 if (data->offset < 64)
1637 info[idx++] = (struct field_modify_info){4, 0,
1638 MLX5_MODI_OUT_SIPV6_63_32};
1639 if (data->offset < 96)
1640 info[idx++] = (struct field_modify_info){4, 0,
1641 MLX5_MODI_OUT_SIPV6_95_64};
1642 if (data->offset < 128)
1643 info[idx++] = (struct field_modify_info){4, 0,
1644 MLX5_MODI_OUT_SIPV6_127_96};
1647 case RTE_FLOW_FIELD_IPV6_DST:
1649 if (data->offset < 32) {
1650 info[idx] = (struct field_modify_info){4, 12,
1651 MLX5_MODI_OUT_DIPV6_31_0};
1654 rte_cpu_to_be_32(0xffffffff >>
1658 mask[3] = RTE_BE32(0xffffffff);
1665 if (data->offset < 64) {
1666 info[idx] = (struct field_modify_info){4, 8,
1667 MLX5_MODI_OUT_DIPV6_63_32};
1670 rte_cpu_to_be_32(0xffffffff >>
1674 mask[2] = RTE_BE32(0xffffffff);
1681 if (data->offset < 96) {
1682 info[idx] = (struct field_modify_info){4, 4,
1683 MLX5_MODI_OUT_DIPV6_95_64};
1686 rte_cpu_to_be_32(0xffffffff >>
1690 mask[1] = RTE_BE32(0xffffffff);
1697 info[idx] = (struct field_modify_info){4, 0,
1698 MLX5_MODI_OUT_DIPV6_127_96};
1699 mask[0] = rte_cpu_to_be_32(0xffffffff >> (32 - width));
1701 if (data->offset < 32)
1702 info[idx++] = (struct field_modify_info){4, 0,
1703 MLX5_MODI_OUT_DIPV6_31_0};
1704 if (data->offset < 64)
1705 info[idx++] = (struct field_modify_info){4, 0,
1706 MLX5_MODI_OUT_DIPV6_63_32};
1707 if (data->offset < 96)
1708 info[idx++] = (struct field_modify_info){4, 0,
1709 MLX5_MODI_OUT_DIPV6_95_64};
1710 if (data->offset < 128)
1711 info[idx++] = (struct field_modify_info){4, 0,
1712 MLX5_MODI_OUT_DIPV6_127_96};
1715 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1716 info[idx] = (struct field_modify_info){2, 0,
1717 MLX5_MODI_OUT_TCP_SPORT};
1719 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1721 case RTE_FLOW_FIELD_TCP_PORT_DST:
1722 info[idx] = (struct field_modify_info){2, 0,
1723 MLX5_MODI_OUT_TCP_DPORT};
1725 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1727 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1728 info[idx] = (struct field_modify_info){4, 0,
1729 MLX5_MODI_OUT_TCP_SEQ_NUM};
1731 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1734 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1735 info[idx] = (struct field_modify_info){4, 0,
1736 MLX5_MODI_OUT_TCP_ACK_NUM};
1738 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1741 case RTE_FLOW_FIELD_TCP_FLAGS:
1742 info[idx] = (struct field_modify_info){2, 0,
1743 MLX5_MODI_OUT_TCP_FLAGS};
1745 mask[idx] = rte_cpu_to_be_16(0x1ff >> (9 - width));
1747 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1748 info[idx] = (struct field_modify_info){2, 0,
1749 MLX5_MODI_OUT_UDP_SPORT};
1751 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1753 case RTE_FLOW_FIELD_UDP_PORT_DST:
1754 info[idx] = (struct field_modify_info){2, 0,
1755 MLX5_MODI_OUT_UDP_DPORT};
1757 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1759 case RTE_FLOW_FIELD_VXLAN_VNI:
1760 /* not supported yet */
1762 case RTE_FLOW_FIELD_GENEVE_VNI:
1763 /* not supported yet*/
1765 case RTE_FLOW_FIELD_GTP_TEID:
1766 info[idx] = (struct field_modify_info){4, 0,
1767 MLX5_MODI_GTP_TEID};
1769 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1772 case RTE_FLOW_FIELD_TAG:
1774 int reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
1775 data->level, error);
1778 MLX5_ASSERT(reg != REG_NON);
1779 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1780 info[idx] = (struct field_modify_info){4, 0,
1784 rte_cpu_to_be_32(0xffffffff >>
1788 case RTE_FLOW_FIELD_MARK:
1790 uint32_t mark_mask = priv->sh->dv_mark_mask;
1791 uint32_t mark_count = __builtin_popcount(mark_mask);
1792 int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
1796 MLX5_ASSERT(reg != REG_NON);
1797 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1798 info[idx] = (struct field_modify_info){4, 0,
1801 mask[idx] = rte_cpu_to_be_32((mark_mask >>
1802 (mark_count - width)) & mark_mask);
1805 case RTE_FLOW_FIELD_META:
1807 uint32_t meta_mask = priv->sh->dv_meta_mask;
1808 uint32_t meta_count = __builtin_popcount(meta_mask);
1810 rte_cpu_to_be_32(priv->sh->dv_regc0_mask);
1811 uint32_t shl_c0 = rte_bsf32(msk_c0);
1812 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1815 MLX5_ASSERT(reg != REG_NON);
1816 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1819 info[idx] = (struct field_modify_info){4, 0,
1822 mask[idx] = rte_cpu_to_be_32((meta_mask >>
1823 (meta_count - width)) & meta_mask);
1826 case RTE_FLOW_FIELD_POINTER:
1827 case RTE_FLOW_FIELD_VALUE:
1835 * Convert modify_field action to DV specification.
1838 * Pointer to the rte_eth_dev structure.
1839 * @param[in,out] resource
1840 * Pointer to the modify-header resource.
1842 * Pointer to action specification.
1844 * Attributes of flow that includes this item.
1846 * Pointer to the error structure.
1849 * 0 on success, a negative errno value otherwise and rte_errno is set.
1852 flow_dv_convert_action_modify_field
1853 (struct rte_eth_dev *dev,
1854 struct mlx5_flow_dv_modify_hdr_resource *resource,
1855 const struct rte_flow_action *action,
1856 const struct rte_flow_attr *attr,
1857 struct rte_flow_error *error)
1859 const struct rte_flow_action_modify_field *conf =
1860 (const struct rte_flow_action_modify_field *)(action->conf);
1861 struct rte_flow_item item = {
1865 struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1867 struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1869 uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1870 uint32_t type, meta = 0;
1873 if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1874 conf->src.field == RTE_FLOW_FIELD_VALUE) {
1875 type = MLX5_MODIFICATION_TYPE_SET;
1876 /** For SET fill the destination field (field) first. */
1877 mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1878 conf->width, &shift, dev,
1880 item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
1881 (void *)(uintptr_t)conf->src.pvalue :
1882 (void *)(uintptr_t)&conf->src.value;
1883 if (conf->dst.field == RTE_FLOW_FIELD_META) {
1884 meta = *(const unaligned_uint32_t *)item.spec;
1885 meta = rte_cpu_to_be_32(meta);
1889 type = MLX5_MODIFICATION_TYPE_COPY;
1890 /** For COPY fill the destination field (dcopy) without mask. */
1891 mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1892 conf->width, &shift, dev,
1894 /** Then construct the source field (field) with mask. */
1895 mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1896 conf->width, &shift,
1900 return flow_dv_convert_modify_action(&item,
1901 field, dcopy, resource, type, error);
1905 * Validate MARK item.
1908 * Pointer to the rte_eth_dev structure.
1910 * Item specification.
1912 * Attributes of flow that includes this item.
1914 * Pointer to error structure.
1917 * 0 on success, a negative errno value otherwise and rte_errno is set.
1920 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1921 const struct rte_flow_item *item,
1922 const struct rte_flow_attr *attr __rte_unused,
1923 struct rte_flow_error *error)
1925 struct mlx5_priv *priv = dev->data->dev_private;
1926 struct mlx5_dev_config *config = &priv->config;
1927 const struct rte_flow_item_mark *spec = item->spec;
1928 const struct rte_flow_item_mark *mask = item->mask;
1929 const struct rte_flow_item_mark nic_mask = {
1930 .id = priv->sh->dv_mark_mask,
1934 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1935 return rte_flow_error_set(error, ENOTSUP,
1936 RTE_FLOW_ERROR_TYPE_ITEM, item,
1937 "extended metadata feature"
1939 if (!mlx5_flow_ext_mreg_supported(dev))
1940 return rte_flow_error_set(error, ENOTSUP,
1941 RTE_FLOW_ERROR_TYPE_ITEM, item,
1942 "extended metadata register"
1943 " isn't supported");
1945 return rte_flow_error_set(error, ENOTSUP,
1946 RTE_FLOW_ERROR_TYPE_ITEM, item,
1947 "extended metadata register"
1948 " isn't available");
1949 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1953 return rte_flow_error_set(error, EINVAL,
1954 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1956 "data cannot be empty");
1957 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1958 return rte_flow_error_set(error, EINVAL,
1959 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1961 "mark id exceeds the limit");
1965 return rte_flow_error_set(error, EINVAL,
1966 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1967 "mask cannot be zero");
1969 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1970 (const uint8_t *)&nic_mask,
1971 sizeof(struct rte_flow_item_mark),
1972 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1979 * Validate META item.
1982 * Pointer to the rte_eth_dev structure.
1984 * Item specification.
1986 * Attributes of flow that includes this item.
1988 * Pointer to error structure.
1991 * 0 on success, a negative errno value otherwise and rte_errno is set.
1994 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1995 const struct rte_flow_item *item,
1996 const struct rte_flow_attr *attr,
1997 struct rte_flow_error *error)
1999 struct mlx5_priv *priv = dev->data->dev_private;
2000 struct mlx5_dev_config *config = &priv->config;
2001 const struct rte_flow_item_meta *spec = item->spec;
2002 const struct rte_flow_item_meta *mask = item->mask;
2003 struct rte_flow_item_meta nic_mask = {
2010 return rte_flow_error_set(error, EINVAL,
2011 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2013 "data cannot be empty");
2014 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2015 if (!mlx5_flow_ext_mreg_supported(dev))
2016 return rte_flow_error_set(error, ENOTSUP,
2017 RTE_FLOW_ERROR_TYPE_ITEM, item,
2018 "extended metadata register"
2019 " isn't supported");
2020 reg = flow_dv_get_metadata_reg(dev, attr, error);
2024 return rte_flow_error_set(error, ENOTSUP,
2025 RTE_FLOW_ERROR_TYPE_ITEM, item,
2026 "unavailable extended metadata register");
2028 return rte_flow_error_set(error, ENOTSUP,
2029 RTE_FLOW_ERROR_TYPE_ITEM, item,
2033 nic_mask.data = priv->sh->dv_meta_mask;
2036 return rte_flow_error_set(error, ENOTSUP,
2037 RTE_FLOW_ERROR_TYPE_ITEM, item,
2038 "extended metadata feature "
2039 "should be enabled when "
2040 "meta item is requested "
2041 "with e-switch mode ");
2043 return rte_flow_error_set(error, ENOTSUP,
2044 RTE_FLOW_ERROR_TYPE_ITEM, item,
2045 "match on metadata for ingress "
2046 "is not supported in legacy "
2050 mask = &rte_flow_item_meta_mask;
2052 return rte_flow_error_set(error, EINVAL,
2053 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2054 "mask cannot be zero");
2056 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2057 (const uint8_t *)&nic_mask,
2058 sizeof(struct rte_flow_item_meta),
2059 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2064 * Validate TAG item.
2067 * Pointer to the rte_eth_dev structure.
2069 * Item specification.
2071 * Attributes of flow that includes this item.
2073 * Pointer to error structure.
2076 * 0 on success, a negative errno value otherwise and rte_errno is set.
2079 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2080 const struct rte_flow_item *item,
2081 const struct rte_flow_attr *attr __rte_unused,
2082 struct rte_flow_error *error)
2084 const struct rte_flow_item_tag *spec = item->spec;
2085 const struct rte_flow_item_tag *mask = item->mask;
2086 const struct rte_flow_item_tag nic_mask = {
2087 .data = RTE_BE32(UINT32_MAX),
2092 if (!mlx5_flow_ext_mreg_supported(dev))
2093 return rte_flow_error_set(error, ENOTSUP,
2094 RTE_FLOW_ERROR_TYPE_ITEM, item,
2095 "extensive metadata register"
2096 " isn't supported");
2098 return rte_flow_error_set(error, EINVAL,
2099 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2101 "data cannot be empty");
2103 mask = &rte_flow_item_tag_mask;
2105 return rte_flow_error_set(error, EINVAL,
2106 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2107 "mask cannot be zero");
2109 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2110 (const uint8_t *)&nic_mask,
2111 sizeof(struct rte_flow_item_tag),
2112 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2115 if (mask->index != 0xff)
2116 return rte_flow_error_set(error, EINVAL,
2117 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2118 "partial mask for tag index"
2119 " is not supported");
2120 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2123 MLX5_ASSERT(ret != REG_NON);
2128 * Validate vport item.
2131 * Pointer to the rte_eth_dev structure.
2133 * Item specification.
2135 * Attributes of flow that includes this item.
2136 * @param[in] item_flags
2137 * Bit-fields that holds the items detected until now.
2139 * Pointer to error structure.
2142 * 0 on success, a negative errno value otherwise and rte_errno is set.
2145 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2146 const struct rte_flow_item *item,
2147 const struct rte_flow_attr *attr,
2148 uint64_t item_flags,
2149 struct rte_flow_error *error)
2151 const struct rte_flow_item_port_id *spec = item->spec;
2152 const struct rte_flow_item_port_id *mask = item->mask;
2153 const struct rte_flow_item_port_id switch_mask = {
2156 struct mlx5_priv *esw_priv;
2157 struct mlx5_priv *dev_priv;
2160 if (!attr->transfer)
2161 return rte_flow_error_set(error, EINVAL,
2162 RTE_FLOW_ERROR_TYPE_ITEM,
2164 "match on port id is valid only"
2165 " when transfer flag is enabled");
2166 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2167 return rte_flow_error_set(error, ENOTSUP,
2168 RTE_FLOW_ERROR_TYPE_ITEM, item,
2169 "multiple source ports are not"
2172 mask = &switch_mask;
2173 if (mask->id != 0xffffffff)
2174 return rte_flow_error_set(error, ENOTSUP,
2175 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2177 "no support for partial mask on"
2179 ret = mlx5_flow_item_acceptable
2180 (item, (const uint8_t *)mask,
2181 (const uint8_t *)&rte_flow_item_port_id_mask,
2182 sizeof(struct rte_flow_item_port_id),
2183 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2188 if (spec->id == MLX5_PORT_ESW_MGR)
2190 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2192 return rte_flow_error_set(error, rte_errno,
2193 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2194 "failed to obtain E-Switch info for"
2196 dev_priv = mlx5_dev_to_eswitch_info(dev);
2198 return rte_flow_error_set(error, rte_errno,
2199 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2201 "failed to obtain E-Switch info");
2202 if (esw_priv->domain_id != dev_priv->domain_id)
2203 return rte_flow_error_set(error, EINVAL,
2204 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2205 "cannot match on a port from a"
2206 " different E-Switch");
2211 * Validate VLAN item.
2214 * Item specification.
2215 * @param[in] item_flags
2216 * Bit-fields that holds the items detected until now.
2218 * Ethernet device flow is being created on.
2220 * Pointer to error structure.
2223 * 0 on success, a negative errno value otherwise and rte_errno is set.
2226 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2227 uint64_t item_flags,
2228 struct rte_eth_dev *dev,
2229 struct rte_flow_error *error)
2231 const struct rte_flow_item_vlan *mask = item->mask;
2232 const struct rte_flow_item_vlan nic_mask = {
2233 .tci = RTE_BE16(UINT16_MAX),
2234 .inner_type = RTE_BE16(UINT16_MAX),
2237 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2239 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2240 MLX5_FLOW_LAYER_INNER_L4) :
2241 (MLX5_FLOW_LAYER_OUTER_L3 |
2242 MLX5_FLOW_LAYER_OUTER_L4);
2243 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2244 MLX5_FLOW_LAYER_OUTER_VLAN;
2246 if (item_flags & vlanm)
2247 return rte_flow_error_set(error, EINVAL,
2248 RTE_FLOW_ERROR_TYPE_ITEM, item,
2249 "multiple VLAN layers not supported");
2250 else if ((item_flags & l34m) != 0)
2251 return rte_flow_error_set(error, EINVAL,
2252 RTE_FLOW_ERROR_TYPE_ITEM, item,
2253 "VLAN cannot follow L3/L4 layer");
2255 mask = &rte_flow_item_vlan_mask;
2256 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2257 (const uint8_t *)&nic_mask,
2258 sizeof(struct rte_flow_item_vlan),
2259 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2262 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2263 struct mlx5_priv *priv = dev->data->dev_private;
2265 if (priv->vmwa_context) {
2267 * Non-NULL context means we have a virtual machine
2268 * and SR-IOV enabled, we have to create VLAN interface
2269 * to make hypervisor to setup E-Switch vport
2270 * context correctly. We avoid creating the multiple
2271 * VLAN interfaces, so we cannot support VLAN tag mask.
2273 return rte_flow_error_set(error, EINVAL,
2274 RTE_FLOW_ERROR_TYPE_ITEM,
2276 "VLAN tag mask is not"
2277 " supported in virtual"
2285 * GTP flags are contained in 1 byte of the format:
2286 * -------------------------------------------
2287 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2288 * |-----------------------------------------|
2289 * | value | Version | PT | Res | E | S | PN |
2290 * -------------------------------------------
2292 * Matching is supported only for GTP flags E, S, PN.
2294 #define MLX5_GTP_FLAGS_MASK 0x07
2297 * Validate GTP item.
2300 * Pointer to the rte_eth_dev structure.
2302 * Item specification.
2303 * @param[in] item_flags
2304 * Bit-fields that holds the items detected until now.
2306 * Pointer to error structure.
2309 * 0 on success, a negative errno value otherwise and rte_errno is set.
2312 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2313 const struct rte_flow_item *item,
2314 uint64_t item_flags,
2315 struct rte_flow_error *error)
2317 struct mlx5_priv *priv = dev->data->dev_private;
2318 const struct rte_flow_item_gtp *spec = item->spec;
2319 const struct rte_flow_item_gtp *mask = item->mask;
2320 const struct rte_flow_item_gtp nic_mask = {
2321 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
2323 .teid = RTE_BE32(0xffffffff),
2326 if (!priv->config.hca_attr.tunnel_stateless_gtp)
2327 return rte_flow_error_set(error, ENOTSUP,
2328 RTE_FLOW_ERROR_TYPE_ITEM, item,
2329 "GTP support is not enabled");
2330 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2331 return rte_flow_error_set(error, ENOTSUP,
2332 RTE_FLOW_ERROR_TYPE_ITEM, item,
2333 "multiple tunnel layers not"
2335 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2336 return rte_flow_error_set(error, EINVAL,
2337 RTE_FLOW_ERROR_TYPE_ITEM, item,
2338 "no outer UDP layer found");
2340 mask = &rte_flow_item_gtp_mask;
2341 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
2342 return rte_flow_error_set(error, ENOTSUP,
2343 RTE_FLOW_ERROR_TYPE_ITEM, item,
2344 "Match is supported for GTP"
2346 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2347 (const uint8_t *)&nic_mask,
2348 sizeof(struct rte_flow_item_gtp),
2349 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2353 * Validate GTP PSC item.
2356 * Item specification.
2357 * @param[in] last_item
2358 * Previous validated item in the pattern items.
2359 * @param[in] gtp_item
2360 * Previous GTP item specification.
2362 * Pointer to flow attributes.
2364 * Pointer to error structure.
2367 * 0 on success, a negative errno value otherwise and rte_errno is set.
2370 flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2372 const struct rte_flow_item *gtp_item,
2373 const struct rte_flow_attr *attr,
2374 struct rte_flow_error *error)
2376 const struct rte_flow_item_gtp *gtp_spec;
2377 const struct rte_flow_item_gtp *gtp_mask;
2378 const struct rte_flow_item_gtp_psc *mask;
2379 const struct rte_flow_item_gtp_psc nic_mask = {
2384 if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2385 return rte_flow_error_set
2386 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2387 "GTP PSC item must be preceded with GTP item");
2388 gtp_spec = gtp_item->spec;
2389 gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2390 /* GTP spec and E flag is requested to match zero. */
2392 (gtp_mask->v_pt_rsv_flags &
2393 ~gtp_spec->v_pt_rsv_flags & MLX5_GTP_EXT_HEADER_FLAG))
2394 return rte_flow_error_set
2395 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2396 "GTP E flag must be 1 to match GTP PSC");
2397 /* Check the flow is not created in group zero. */
2398 if (!attr->transfer && !attr->group)
2399 return rte_flow_error_set
2400 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2401 "GTP PSC is not supported for group 0");
2402 /* GTP spec is here and E flag is requested to match zero. */
2405 mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2406 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2407 (const uint8_t *)&nic_mask,
2408 sizeof(struct rte_flow_item_gtp_psc),
2409 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2413 * Validate IPV4 item.
2414 * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2415 * add specific validation of fragment_offset field,
2418 * Item specification.
2419 * @param[in] item_flags
2420 * Bit-fields that holds the items detected until now.
2422 * Pointer to error structure.
2425 * 0 on success, a negative errno value otherwise and rte_errno is set.
2428 flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
2429 const struct rte_flow_item *item,
2430 uint64_t item_flags, uint64_t last_item,
2431 uint16_t ether_type, struct rte_flow_error *error)
2434 struct mlx5_priv *priv = dev->data->dev_private;
2435 const struct rte_flow_item_ipv4 *spec = item->spec;
2436 const struct rte_flow_item_ipv4 *last = item->last;
2437 const struct rte_flow_item_ipv4 *mask = item->mask;
2438 rte_be16_t fragment_offset_spec = 0;
2439 rte_be16_t fragment_offset_last = 0;
2440 struct rte_flow_item_ipv4 nic_ipv4_mask = {
2442 .src_addr = RTE_BE32(0xffffffff),
2443 .dst_addr = RTE_BE32(0xffffffff),
2444 .type_of_service = 0xff,
2445 .fragment_offset = RTE_BE16(0xffff),
2446 .next_proto_id = 0xff,
2447 .time_to_live = 0xff,
2451 if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
2452 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2453 bool ihl_cap = !tunnel ? priv->config.hca_attr.outer_ipv4_ihl :
2454 priv->config.hca_attr.inner_ipv4_ihl;
2456 return rte_flow_error_set(error, ENOTSUP,
2457 RTE_FLOW_ERROR_TYPE_ITEM,
2459 "IPV4 ihl offload not supported");
2460 nic_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
2462 ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2463 ether_type, &nic_ipv4_mask,
2464 MLX5_ITEM_RANGE_ACCEPTED, error);
2468 fragment_offset_spec = spec->hdr.fragment_offset &
2469 mask->hdr.fragment_offset;
2470 if (!fragment_offset_spec)
2473 * spec and mask are valid, enforce using full mask to make sure the
2474 * complete value is used correctly.
2476 if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2477 != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2478 return rte_flow_error_set(error, EINVAL,
2479 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2480 item, "must use full mask for"
2481 " fragment_offset");
2483 * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
2484 * indicating this is 1st fragment of fragmented packet.
2485 * This is not yet supported in MLX5, return appropriate error message.
2487 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
2488 return rte_flow_error_set(error, ENOTSUP,
2489 RTE_FLOW_ERROR_TYPE_ITEM, item,
2490 "match on first fragment not "
2492 if (fragment_offset_spec && !last)
2493 return rte_flow_error_set(error, ENOTSUP,
2494 RTE_FLOW_ERROR_TYPE_ITEM, item,
2495 "specified value not supported");
2496 /* spec and last are valid, validate the specified range. */
2497 fragment_offset_last = last->hdr.fragment_offset &
2498 mask->hdr.fragment_offset;
2500 * Match on fragment_offset spec 0x2001 and last 0x3fff
2501 * means MF is 1 and frag-offset is > 0.
2502 * This packet is fragment 2nd and onward, excluding last.
2503 * This is not yet supported in MLX5, return appropriate
2506 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
2507 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2508 return rte_flow_error_set(error, ENOTSUP,
2509 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2510 last, "match on following "
2511 "fragments not supported");
2513 * Match on fragment_offset spec 0x0001 and last 0x1fff
2514 * means MF is 0 and frag-offset is > 0.
2515 * This packet is last fragment of fragmented packet.
2516 * This is not yet supported in MLX5, return appropriate
2519 if (fragment_offset_spec == RTE_BE16(1) &&
2520 fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
2521 return rte_flow_error_set(error, ENOTSUP,
2522 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2523 last, "match on last "
2524 "fragment not supported");
2526 * Match on fragment_offset spec 0x0001 and last 0x3fff
2527 * means MF and/or frag-offset is not 0.
2528 * This is a fragmented packet.
2529 * Other range values are invalid and rejected.
2531 if (!(fragment_offset_spec == RTE_BE16(1) &&
2532 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
2533 return rte_flow_error_set(error, ENOTSUP,
2534 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2535 "specified range not supported");
2540 * Validate IPV6 fragment extension item.
2543 * Item specification.
2544 * @param[in] item_flags
2545 * Bit-fields that holds the items detected until now.
2547 * Pointer to error structure.
2550 * 0 on success, a negative errno value otherwise and rte_errno is set.
2553 flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
2554 uint64_t item_flags,
2555 struct rte_flow_error *error)
2557 const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
2558 const struct rte_flow_item_ipv6_frag_ext *last = item->last;
2559 const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
2560 rte_be16_t frag_data_spec = 0;
2561 rte_be16_t frag_data_last = 0;
2562 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2563 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2564 MLX5_FLOW_LAYER_OUTER_L4;
2566 struct rte_flow_item_ipv6_frag_ext nic_mask = {
2568 .next_header = 0xff,
2569 .frag_data = RTE_BE16(0xffff),
2573 if (item_flags & l4m)
2574 return rte_flow_error_set(error, EINVAL,
2575 RTE_FLOW_ERROR_TYPE_ITEM, item,
2576 "ipv6 fragment extension item cannot "
2578 if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
2579 (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
2580 return rte_flow_error_set(error, EINVAL,
2581 RTE_FLOW_ERROR_TYPE_ITEM, item,
2582 "ipv6 fragment extension item must "
2583 "follow ipv6 item");
2585 frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
2586 if (!frag_data_spec)
2589 * spec and mask are valid, enforce using full mask to make sure the
2590 * complete value is used correctly.
2592 if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
2593 RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2594 return rte_flow_error_set(error, EINVAL,
2595 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2596 item, "must use full mask for"
2599 * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2600 * This is 1st fragment of fragmented packet.
2602 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2603 return rte_flow_error_set(error, ENOTSUP,
2604 RTE_FLOW_ERROR_TYPE_ITEM, item,
2605 "match on first fragment not "
2607 if (frag_data_spec && !last)
2608 return rte_flow_error_set(error, EINVAL,
2609 RTE_FLOW_ERROR_TYPE_ITEM, item,
2610 "specified value not supported");
2611 ret = mlx5_flow_item_acceptable
2612 (item, (const uint8_t *)mask,
2613 (const uint8_t *)&nic_mask,
2614 sizeof(struct rte_flow_item_ipv6_frag_ext),
2615 MLX5_ITEM_RANGE_ACCEPTED, error);
2618 /* spec and last are valid, validate the specified range. */
2619 frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2621 * Match on frag_data spec 0x0009 and last 0xfff9
2622 * means M is 1 and frag-offset is > 0.
2623 * This packet is fragment 2nd and onward, excluding last.
2624 * This is not yet supported in MLX5, return appropriate
2627 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2628 RTE_IPV6_EHDR_MF_MASK) &&
2629 frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2630 return rte_flow_error_set(error, ENOTSUP,
2631 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2632 last, "match on following "
2633 "fragments not supported");
2635 * Match on frag_data spec 0x0008 and last 0xfff8
2636 * means M is 0 and frag-offset is > 0.
2637 * This packet is last fragment of fragmented packet.
2638 * This is not yet supported in MLX5, return appropriate
2641 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2642 frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2643 return rte_flow_error_set(error, ENOTSUP,
2644 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2645 last, "match on last "
2646 "fragment not supported");
2647 /* Other range values are invalid and rejected. */
2648 return rte_flow_error_set(error, EINVAL,
2649 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2650 "specified range not supported");
2654 * Validate ASO CT item.
2657 * Pointer to the rte_eth_dev structure.
2659 * Item specification.
2660 * @param[in] item_flags
2661 * Pointer to bit-fields that holds the items detected until now.
2663 * Pointer to error structure.
2666 * 0 on success, a negative errno value otherwise and rte_errno is set.
2669 flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
2670 const struct rte_flow_item *item,
2671 uint64_t *item_flags,
2672 struct rte_flow_error *error)
2674 const struct rte_flow_item_conntrack *spec = item->spec;
2675 const struct rte_flow_item_conntrack *mask = item->mask;
2679 if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
2680 return rte_flow_error_set(error, EINVAL,
2681 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2682 "Only one CT is supported");
2684 mask = &rte_flow_item_conntrack_mask;
2685 flags = spec->flags & mask->flags;
2686 if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
2687 ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
2688 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
2689 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
2690 return rte_flow_error_set(error, EINVAL,
2691 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2692 "Conflict status bits");
2693 /* State change also needs to be considered. */
2694 *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
2699 * Validate the pop VLAN action.
2702 * Pointer to the rte_eth_dev structure.
2703 * @param[in] action_flags
2704 * Holds the actions detected until now.
2706 * Pointer to the pop vlan action.
2707 * @param[in] item_flags
2708 * The items found in this flow rule.
2710 * Pointer to flow attributes.
2712 * Pointer to error structure.
2715 * 0 on success, a negative errno value otherwise and rte_errno is set.
2718 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
2719 uint64_t action_flags,
2720 const struct rte_flow_action *action,
2721 uint64_t item_flags,
2722 const struct rte_flow_attr *attr,
2723 struct rte_flow_error *error)
2725 const struct mlx5_priv *priv = dev->data->dev_private;
2726 struct mlx5_dev_ctx_shared *sh = priv->sh;
2727 bool direction_error = false;
2729 if (!priv->sh->pop_vlan_action)
2730 return rte_flow_error_set(error, ENOTSUP,
2731 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2733 "pop vlan action is not supported");
2734 /* Pop VLAN is not supported in egress except for CX6 FDB mode. */
2735 if (attr->transfer) {
2736 bool fdb_tx = priv->representor_id != UINT16_MAX;
2737 bool is_cx5 = sh->steering_format_version ==
2738 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
2740 if (fdb_tx && is_cx5)
2741 direction_error = true;
2742 } else if (attr->egress) {
2743 direction_error = true;
2745 if (direction_error)
2746 return rte_flow_error_set(error, ENOTSUP,
2747 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2749 "pop vlan action not supported for egress");
2750 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
2751 return rte_flow_error_set(error, ENOTSUP,
2752 RTE_FLOW_ERROR_TYPE_ACTION, action,
2753 "no support for multiple VLAN "
2755 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
2756 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
2757 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
2758 return rte_flow_error_set(error, ENOTSUP,
2759 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2761 "cannot pop vlan after decap without "
2762 "match on inner vlan in the flow");
2763 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
2764 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
2765 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2766 return rte_flow_error_set(error, ENOTSUP,
2767 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2769 "cannot pop vlan without a "
2770 "match on (outer) vlan in the flow");
2771 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2772 return rte_flow_error_set(error, EINVAL,
2773 RTE_FLOW_ERROR_TYPE_ACTION, action,
2774 "wrong action order, port_id should "
2775 "be after pop VLAN action");
2776 if (!attr->transfer && priv->representor)
2777 return rte_flow_error_set(error, ENOTSUP,
2778 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2779 "pop vlan action for VF representor "
2780 "not supported on NIC table");
2785 * Get VLAN default info from vlan match info.
2788 * the list of item specifications.
2790 * pointer VLAN info to fill to.
2793 * 0 on success, a negative errno value otherwise and rte_errno is set.
2796 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
2797 struct rte_vlan_hdr *vlan)
2799 const struct rte_flow_item_vlan nic_mask = {
2800 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
2801 MLX5DV_FLOW_VLAN_VID_MASK),
2802 .inner_type = RTE_BE16(0xffff),
2807 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2808 int type = items->type;
2810 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
2811 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
2814 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
2815 const struct rte_flow_item_vlan *vlan_m = items->mask;
2816 const struct rte_flow_item_vlan *vlan_v = items->spec;
2818 /* If VLAN item in pattern doesn't contain data, return here. */
2823 /* Only full match values are accepted */
2824 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
2825 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
2826 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
2828 rte_be_to_cpu_16(vlan_v->tci &
2829 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
2831 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
2832 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
2833 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
2835 rte_be_to_cpu_16(vlan_v->tci &
2836 MLX5DV_FLOW_VLAN_VID_MASK_BE);
2838 if (vlan_m->inner_type == nic_mask.inner_type)
2839 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
2840 vlan_m->inner_type);
2845 * Validate the push VLAN action.
2848 * Pointer to the rte_eth_dev structure.
2849 * @param[in] action_flags
2850 * Holds the actions detected until now.
2851 * @param[in] item_flags
2852 * The items found in this flow rule.
2854 * Pointer to the action structure.
2856 * Pointer to flow attributes
2858 * Pointer to error structure.
2861 * 0 on success, a negative errno value otherwise and rte_errno is set.
2864 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
2865 uint64_t action_flags,
2866 const struct rte_flow_item_vlan *vlan_m,
2867 const struct rte_flow_action *action,
2868 const struct rte_flow_attr *attr,
2869 struct rte_flow_error *error)
2871 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
2872 const struct mlx5_priv *priv = dev->data->dev_private;
2873 struct mlx5_dev_ctx_shared *sh = priv->sh;
2874 bool direction_error = false;
2876 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
2877 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
2878 return rte_flow_error_set(error, EINVAL,
2879 RTE_FLOW_ERROR_TYPE_ACTION, action,
2880 "invalid vlan ethertype");
2881 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2882 return rte_flow_error_set(error, EINVAL,
2883 RTE_FLOW_ERROR_TYPE_ACTION, action,
2884 "wrong action order, port_id should "
2885 "be after push VLAN");
2886 /* Push VLAN is not supported in ingress except for CX6 FDB mode. */
2887 if (attr->transfer) {
2888 bool fdb_tx = priv->representor_id != UINT16_MAX;
2889 bool is_cx5 = sh->steering_format_version ==
2890 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
2892 if (!fdb_tx && is_cx5)
2893 direction_error = true;
2894 } else if (attr->ingress) {
2895 direction_error = true;
2897 if (direction_error)
2898 return rte_flow_error_set(error, ENOTSUP,
2899 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2901 "push vlan action not supported for ingress");
2902 if (!attr->transfer && priv->representor)
2903 return rte_flow_error_set(error, ENOTSUP,
2904 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2905 "push vlan action for VF representor "
2906 "not supported on NIC table");
2908 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
2909 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
2910 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
2911 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
2912 !(mlx5_flow_find_action
2913 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
2914 return rte_flow_error_set(error, EINVAL,
2915 RTE_FLOW_ERROR_TYPE_ACTION, action,
2916 "not full match mask on VLAN PCP and "
2917 "there is no of_set_vlan_pcp action, "
2918 "push VLAN action cannot figure out "
2921 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
2922 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
2923 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
2924 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
2925 !(mlx5_flow_find_action
2926 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
2927 return rte_flow_error_set(error, EINVAL,
2928 RTE_FLOW_ERROR_TYPE_ACTION, action,
2929 "not full match mask on VLAN VID and "
2930 "there is no of_set_vlan_vid action, "
2931 "push VLAN action cannot figure out "
2938 * Validate the set VLAN PCP.
2940 * @param[in] action_flags
2941 * Holds the actions detected until now.
2942 * @param[in] actions
2943 * Pointer to the list of actions remaining in the flow rule.
2945 * Pointer to error structure.
2948 * 0 on success, a negative errno value otherwise and rte_errno is set.
2951 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2952 const struct rte_flow_action actions[],
2953 struct rte_flow_error *error)
2955 const struct rte_flow_action *action = actions;
2956 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2958 if (conf->vlan_pcp > 7)
2959 return rte_flow_error_set(error, EINVAL,
2960 RTE_FLOW_ERROR_TYPE_ACTION, action,
2961 "VLAN PCP value is too big");
2962 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2963 return rte_flow_error_set(error, ENOTSUP,
2964 RTE_FLOW_ERROR_TYPE_ACTION, action,
2965 "set VLAN PCP action must follow "
2966 "the push VLAN action");
2967 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2968 return rte_flow_error_set(error, ENOTSUP,
2969 RTE_FLOW_ERROR_TYPE_ACTION, action,
2970 "Multiple VLAN PCP modification are "
2972 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2973 return rte_flow_error_set(error, EINVAL,
2974 RTE_FLOW_ERROR_TYPE_ACTION, action,
2975 "wrong action order, port_id should "
2976 "be after set VLAN PCP");
2981 * Validate the set VLAN VID.
2983 * @param[in] item_flags
2984 * Holds the items detected in this rule.
2985 * @param[in] action_flags
2986 * Holds the actions detected until now.
2987 * @param[in] actions
2988 * Pointer to the list of actions remaining in the flow rule.
2990 * Pointer to error structure.
2993 * 0 on success, a negative errno value otherwise and rte_errno is set.
2996 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2997 uint64_t action_flags,
2998 const struct rte_flow_action actions[],
2999 struct rte_flow_error *error)
3001 const struct rte_flow_action *action = actions;
3002 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3004 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3005 return rte_flow_error_set(error, EINVAL,
3006 RTE_FLOW_ERROR_TYPE_ACTION, action,
3007 "VLAN VID value is too big");
3008 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3009 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3010 return rte_flow_error_set(error, ENOTSUP,
3011 RTE_FLOW_ERROR_TYPE_ACTION, action,
3012 "set VLAN VID action must follow push"
3013 " VLAN action or match on VLAN item");
3014 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3015 return rte_flow_error_set(error, ENOTSUP,
3016 RTE_FLOW_ERROR_TYPE_ACTION, action,
3017 "Multiple VLAN VID modifications are "
3019 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3020 return rte_flow_error_set(error, EINVAL,
3021 RTE_FLOW_ERROR_TYPE_ACTION, action,
3022 "wrong action order, port_id should "
3023 "be after set VLAN VID");
3028 * Validate the FLAG action.
3031 * Pointer to the rte_eth_dev structure.
3032 * @param[in] action_flags
3033 * Holds the actions detected until now.
3035 * Pointer to flow attributes
3037 * Pointer to error structure.
3040 * 0 on success, a negative errno value otherwise and rte_errno is set.
3043 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3044 uint64_t action_flags,
3045 const struct rte_flow_attr *attr,
3046 struct rte_flow_error *error)
3048 struct mlx5_priv *priv = dev->data->dev_private;
3049 struct mlx5_dev_config *config = &priv->config;
3052 /* Fall back if no extended metadata register support. */
3053 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3054 return mlx5_flow_validate_action_flag(action_flags, attr,
3056 /* Extensive metadata mode requires registers. */
3057 if (!mlx5_flow_ext_mreg_supported(dev))
3058 return rte_flow_error_set(error, ENOTSUP,
3059 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3060 "no metadata registers "
3061 "to support flag action");
3062 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3063 return rte_flow_error_set(error, ENOTSUP,
3064 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3065 "extended metadata register"
3066 " isn't available");
3067 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3070 MLX5_ASSERT(ret > 0);
3071 if (action_flags & MLX5_FLOW_ACTION_MARK)
3072 return rte_flow_error_set(error, EINVAL,
3073 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3074 "can't mark and flag in same flow");
3075 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3076 return rte_flow_error_set(error, EINVAL,
3077 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3079 " actions in same flow");
3084 * Validate MARK action.
3087 * Pointer to the rte_eth_dev structure.
3089 * Pointer to action.
3090 * @param[in] action_flags
3091 * Holds the actions detected until now.
3093 * Pointer to flow attributes
3095 * Pointer to error structure.
3098 * 0 on success, a negative errno value otherwise and rte_errno is set.
3101 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3102 const struct rte_flow_action *action,
3103 uint64_t action_flags,
3104 const struct rte_flow_attr *attr,
3105 struct rte_flow_error *error)
3107 struct mlx5_priv *priv = dev->data->dev_private;
3108 struct mlx5_dev_config *config = &priv->config;
3109 const struct rte_flow_action_mark *mark = action->conf;
3112 if (is_tunnel_offload_active(dev))
3113 return rte_flow_error_set(error, ENOTSUP,
3114 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3116 "if tunnel offload active");
3117 /* Fall back if no extended metadata register support. */
3118 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3119 return mlx5_flow_validate_action_mark(action, action_flags,
3121 /* Extensive metadata mode requires registers. */
3122 if (!mlx5_flow_ext_mreg_supported(dev))
3123 return rte_flow_error_set(error, ENOTSUP,
3124 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3125 "no metadata registers "
3126 "to support mark action");
3127 if (!priv->sh->dv_mark_mask)
3128 return rte_flow_error_set(error, ENOTSUP,
3129 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3130 "extended metadata register"
3131 " isn't available");
3132 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3135 MLX5_ASSERT(ret > 0);
3137 return rte_flow_error_set(error, EINVAL,
3138 RTE_FLOW_ERROR_TYPE_ACTION, action,
3139 "configuration cannot be null");
3140 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3141 return rte_flow_error_set(error, EINVAL,
3142 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3144 "mark id exceeds the limit");
3145 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3146 return rte_flow_error_set(error, EINVAL,
3147 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3148 "can't flag and mark in same flow");
3149 if (action_flags & MLX5_FLOW_ACTION_MARK)
3150 return rte_flow_error_set(error, EINVAL,
3151 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3152 "can't have 2 mark actions in same"
3158 * Validate SET_META action.
3161 * Pointer to the rte_eth_dev structure.
3163 * Pointer to the action structure.
3164 * @param[in] action_flags
3165 * Holds the actions detected until now.
3167 * Pointer to flow attributes
3169 * Pointer to error structure.
3172 * 0 on success, a negative errno value otherwise and rte_errno is set.
3175 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3176 const struct rte_flow_action *action,
3177 uint64_t action_flags __rte_unused,
3178 const struct rte_flow_attr *attr,
3179 struct rte_flow_error *error)
3181 struct mlx5_priv *priv = dev->data->dev_private;
3182 struct mlx5_dev_config *config = &priv->config;
3183 const struct rte_flow_action_set_meta *conf;
3184 uint32_t nic_mask = UINT32_MAX;
3187 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3188 !mlx5_flow_ext_mreg_supported(dev))
3189 return rte_flow_error_set(error, ENOTSUP,
3190 RTE_FLOW_ERROR_TYPE_ACTION, action,
3191 "extended metadata register"
3192 " isn't supported");
3193 reg = flow_dv_get_metadata_reg(dev, attr, error);
3197 return rte_flow_error_set(error, ENOTSUP,
3198 RTE_FLOW_ERROR_TYPE_ACTION, action,
3199 "unavailable extended metadata register");
3200 if (reg != REG_A && reg != REG_B) {
3201 struct mlx5_priv *priv = dev->data->dev_private;
3203 nic_mask = priv->sh->dv_meta_mask;
3205 if (!(action->conf))
3206 return rte_flow_error_set(error, EINVAL,
3207 RTE_FLOW_ERROR_TYPE_ACTION, action,
3208 "configuration cannot be null");
3209 conf = (const struct rte_flow_action_set_meta *)action->conf;
3211 return rte_flow_error_set(error, EINVAL,
3212 RTE_FLOW_ERROR_TYPE_ACTION, action,
3213 "zero mask doesn't have any effect");
3214 if (conf->mask & ~nic_mask)
3215 return rte_flow_error_set(error, EINVAL,
3216 RTE_FLOW_ERROR_TYPE_ACTION, action,
3217 "meta data must be within reg C0");
3222 * Validate SET_TAG action.
3225 * Pointer to the rte_eth_dev structure.
3227 * Pointer to the action structure.
3228 * @param[in] action_flags
3229 * Holds the actions detected until now.
3231 * Pointer to flow attributes
3233 * Pointer to error structure.
3236 * 0 on success, a negative errno value otherwise and rte_errno is set.
3239 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3240 const struct rte_flow_action *action,
3241 uint64_t action_flags,
3242 const struct rte_flow_attr *attr,
3243 struct rte_flow_error *error)
3245 const struct rte_flow_action_set_tag *conf;
3246 const uint64_t terminal_action_flags =
3247 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3248 MLX5_FLOW_ACTION_RSS;
3251 if (!mlx5_flow_ext_mreg_supported(dev))
3252 return rte_flow_error_set(error, ENOTSUP,
3253 RTE_FLOW_ERROR_TYPE_ACTION, action,
3254 "extensive metadata register"
3255 " isn't supported");
3256 if (!(action->conf))
3257 return rte_flow_error_set(error, EINVAL,
3258 RTE_FLOW_ERROR_TYPE_ACTION, action,
3259 "configuration cannot be null");
3260 conf = (const struct rte_flow_action_set_tag *)action->conf;
3262 return rte_flow_error_set(error, EINVAL,
3263 RTE_FLOW_ERROR_TYPE_ACTION, action,
3264 "zero mask doesn't have any effect");
3265 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3268 if (!attr->transfer && attr->ingress &&
3269 (action_flags & terminal_action_flags))
3270 return rte_flow_error_set(error, EINVAL,
3271 RTE_FLOW_ERROR_TYPE_ACTION, action,
3272 "set_tag has no effect"
3273 " with terminal actions");
3278 * Validate count action.
3281 * Pointer to rte_eth_dev structure.
3283 * Indicator if action is shared.
3284 * @param[in] action_flags
3285 * Holds the actions detected until now.
3287 * Pointer to error structure.
3290 * 0 on success, a negative errno value otherwise and rte_errno is set.
3293 flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3294 uint64_t action_flags,
3295 struct rte_flow_error *error)
3297 struct mlx5_priv *priv = dev->data->dev_private;
3299 if (!priv->sh->devx)
3301 if (action_flags & MLX5_FLOW_ACTION_COUNT)
3302 return rte_flow_error_set(error, EINVAL,
3303 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3304 "duplicate count actions set");
3305 if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
3306 !priv->sh->flow_hit_aso_en)
3307 return rte_flow_error_set(error, EINVAL,
3308 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3309 "old age and shared count combination is not supported");
3310 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3314 return rte_flow_error_set
3316 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3318 "count action not supported");
3322 * Validate the L2 encap action.
3325 * Pointer to the rte_eth_dev structure.
3326 * @param[in] action_flags
3327 * Holds the actions detected until now.
3329 * Pointer to the action structure.
3331 * Pointer to flow attributes.
3333 * Pointer to error structure.
3336 * 0 on success, a negative errno value otherwise and rte_errno is set.
3339 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3340 uint64_t action_flags,
3341 const struct rte_flow_action *action,
3342 const struct rte_flow_attr *attr,
3343 struct rte_flow_error *error)
3345 const struct mlx5_priv *priv = dev->data->dev_private;
3347 if (!(action->conf))
3348 return rte_flow_error_set(error, EINVAL,
3349 RTE_FLOW_ERROR_TYPE_ACTION, action,
3350 "configuration cannot be null");
3351 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3352 return rte_flow_error_set(error, EINVAL,
3353 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3354 "can only have a single encap action "
3356 if (!attr->transfer && priv->representor)
3357 return rte_flow_error_set(error, ENOTSUP,
3358 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3359 "encap action for VF representor "
3360 "not supported on NIC table");
3365 * Validate a decap action.
3368 * Pointer to the rte_eth_dev structure.
3369 * @param[in] action_flags
3370 * Holds the actions detected until now.
3372 * Pointer to the action structure.
3373 * @param[in] item_flags
3374 * Holds the items detected.
3376 * Pointer to flow attributes
3378 * Pointer to error structure.
3381 * 0 on success, a negative errno value otherwise and rte_errno is set.
3384 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3385 uint64_t action_flags,
3386 const struct rte_flow_action *action,
3387 const uint64_t item_flags,
3388 const struct rte_flow_attr *attr,
3389 struct rte_flow_error *error)
3391 const struct mlx5_priv *priv = dev->data->dev_private;
3393 if (priv->config.hca_attr.scatter_fcs_w_decap_disable &&
3394 !priv->config.decap_en)
3395 return rte_flow_error_set(error, ENOTSUP,
3396 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3397 "decap is not enabled");
3398 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3399 return rte_flow_error_set(error, ENOTSUP,
3400 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3402 MLX5_FLOW_ACTION_DECAP ? "can only "
3403 "have a single decap action" : "decap "
3404 "after encap is not supported");
3405 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3406 return rte_flow_error_set(error, EINVAL,
3407 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3408 "can't have decap action after"
3411 return rte_flow_error_set(error, ENOTSUP,
3412 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3414 "decap action not supported for "
3416 if (!attr->transfer && priv->representor)
3417 return rte_flow_error_set(error, ENOTSUP,
3418 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3419 "decap action for VF representor "
3420 "not supported on NIC table");
3421 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3422 !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3423 return rte_flow_error_set(error, ENOTSUP,
3424 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3425 "VXLAN item should be present for VXLAN decap");
3429 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3432 * Validate the raw encap and decap actions.
3435 * Pointer to the rte_eth_dev structure.
3437 * Pointer to the decap action.
3439 * Pointer to the encap action.
3441 * Pointer to flow attributes
3442 * @param[in/out] action_flags
3443 * Holds the actions detected until now.
3444 * @param[out] actions_n
3445 * pointer to the number of actions counter.
3447 * Pointer to the action structure.
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_raw_encap_decap
3458 (struct rte_eth_dev *dev,
3459 const struct rte_flow_action_raw_decap *decap,
3460 const struct rte_flow_action_raw_encap *encap,
3461 const struct rte_flow_attr *attr, uint64_t *action_flags,
3462 int *actions_n, const struct rte_flow_action *action,
3463 uint64_t item_flags, struct rte_flow_error *error)
3465 const struct mlx5_priv *priv = dev->data->dev_private;
3468 if (encap && (!encap->size || !encap->data))
3469 return rte_flow_error_set(error, EINVAL,
3470 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3471 "raw encap data cannot be empty");
3472 if (decap && encap) {
3473 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3474 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3477 else if (encap->size <=
3478 MLX5_ENCAPSULATION_DECISION_SIZE &&
3480 MLX5_ENCAPSULATION_DECISION_SIZE)
3483 else if (encap->size >
3484 MLX5_ENCAPSULATION_DECISION_SIZE &&
3486 MLX5_ENCAPSULATION_DECISION_SIZE)
3487 /* 2 L2 actions: encap and decap. */
3490 return rte_flow_error_set(error,
3492 RTE_FLOW_ERROR_TYPE_ACTION,
3493 NULL, "unsupported too small "
3494 "raw decap and too small raw "
3495 "encap combination");
3498 ret = flow_dv_validate_action_decap(dev, *action_flags, action,
3499 item_flags, attr, error);
3502 *action_flags |= MLX5_FLOW_ACTION_DECAP;
3506 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
3507 return rte_flow_error_set(error, ENOTSUP,
3508 RTE_FLOW_ERROR_TYPE_ACTION,
3510 "small raw encap size");
3511 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
3512 return rte_flow_error_set(error, EINVAL,
3513 RTE_FLOW_ERROR_TYPE_ACTION,
3515 "more than one encap action");
3516 if (!attr->transfer && priv->representor)
3517 return rte_flow_error_set
3519 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3520 "encap action for VF representor "
3521 "not supported on NIC table");
3522 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
3529 * Validate the ASO CT action.
3532 * Pointer to the rte_eth_dev structure.
3533 * @param[in] action_flags
3534 * Holds the actions detected until now.
3535 * @param[in] item_flags
3536 * The items found in this flow rule.
3538 * Pointer to flow attributes.
3540 * Pointer to error structure.
3543 * 0 on success, a negative errno value otherwise and rte_errno is set.
3546 flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
3547 uint64_t action_flags,
3548 uint64_t item_flags,
3549 const struct rte_flow_attr *attr,
3550 struct rte_flow_error *error)
3554 if (attr->group == 0 && !attr->transfer)
3555 return rte_flow_error_set(error, ENOTSUP,
3556 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3558 "Only support non-root table");
3559 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
3560 return rte_flow_error_set(error, ENOTSUP,
3561 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3562 "CT cannot follow a fate action");
3563 if ((action_flags & MLX5_FLOW_ACTION_METER) ||
3564 (action_flags & MLX5_FLOW_ACTION_AGE))
3565 return rte_flow_error_set(error, EINVAL,
3566 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3567 "Only one ASO action is supported");
3568 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3569 return rte_flow_error_set(error, EINVAL,
3570 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3571 "Encap cannot exist before CT");
3572 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3573 return rte_flow_error_set(error, EINVAL,
3574 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3575 "Not a outer TCP packet");
3580 flow_dv_encap_decap_match_cb(void *tool_ctx __rte_unused,
3581 struct mlx5_list_entry *entry, void *cb_ctx)
3583 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3584 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3585 struct mlx5_flow_dv_encap_decap_resource *resource;
3587 resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
3589 if (resource->reformat_type == ctx_resource->reformat_type &&
3590 resource->ft_type == ctx_resource->ft_type &&
3591 resource->flags == ctx_resource->flags &&
3592 resource->size == ctx_resource->size &&
3593 !memcmp((const void *)resource->buf,
3594 (const void *)ctx_resource->buf,
3600 struct mlx5_list_entry *
3601 flow_dv_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
3603 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3604 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3605 struct mlx5dv_dr_domain *domain;
3606 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3607 struct mlx5_flow_dv_encap_decap_resource *resource;
3611 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3612 domain = sh->fdb_domain;
3613 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3614 domain = sh->rx_domain;
3616 domain = sh->tx_domain;
3617 /* Register new encap/decap resource. */
3618 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
3620 rte_flow_error_set(ctx->error, ENOMEM,
3621 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3622 "cannot allocate resource memory");
3625 *resource = *ctx_resource;
3626 resource->idx = idx;
3627 ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
3631 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
3632 rte_flow_error_set(ctx->error, ENOMEM,
3633 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3634 NULL, "cannot create action");
3638 return &resource->entry;
3641 struct mlx5_list_entry *
3642 flow_dv_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
3645 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3646 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3647 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3650 cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
3652 if (!cache_resource) {
3653 rte_flow_error_set(ctx->error, ENOMEM,
3654 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3655 "cannot allocate resource memory");
3658 memcpy(cache_resource, oentry, sizeof(*cache_resource));
3659 cache_resource->idx = idx;
3660 return &cache_resource->entry;
3664 flow_dv_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3666 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3667 struct mlx5_flow_dv_encap_decap_resource *res =
3668 container_of(entry, typeof(*res), entry);
3670 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
3674 * Find existing encap/decap resource or create and register a new one.
3676 * @param[in, out] dev
3677 * Pointer to rte_eth_dev structure.
3678 * @param[in, out] resource
3679 * Pointer to encap/decap resource.
3680 * @parm[in, out] dev_flow
3681 * Pointer to the dev_flow.
3683 * pointer to error structure.
3686 * 0 on success otherwise -errno and errno is set.
3689 flow_dv_encap_decap_resource_register
3690 (struct rte_eth_dev *dev,
3691 struct mlx5_flow_dv_encap_decap_resource *resource,
3692 struct mlx5_flow *dev_flow,
3693 struct rte_flow_error *error)
3695 struct mlx5_priv *priv = dev->data->dev_private;
3696 struct mlx5_dev_ctx_shared *sh = priv->sh;
3697 struct mlx5_list_entry *entry;
3701 uint32_t refmt_type:8;
3703 * Header reformat actions can be shared between
3704 * non-root tables. One bit to indicate non-root
3708 uint32_t reserve:15;
3711 } encap_decap_key = {
3713 .ft_type = resource->ft_type,
3714 .refmt_type = resource->reformat_type,
3715 .is_root = !!dev_flow->dv.group,
3719 struct mlx5_flow_cb_ctx ctx = {
3723 struct mlx5_hlist *encaps_decaps;
3726 encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
3728 MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
3730 flow_dv_encap_decap_create_cb,
3731 flow_dv_encap_decap_match_cb,
3732 flow_dv_encap_decap_remove_cb,
3733 flow_dv_encap_decap_clone_cb,
3734 flow_dv_encap_decap_clone_free_cb);
3735 if (unlikely(!encaps_decaps))
3737 resource->flags = dev_flow->dv.group ? 0 : 1;
3738 key64 = __rte_raw_cksum(&encap_decap_key.v32,
3739 sizeof(encap_decap_key.v32), 0);
3740 if (resource->reformat_type !=
3741 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
3743 key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
3744 entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
3747 resource = container_of(entry, typeof(*resource), entry);
3748 dev_flow->dv.encap_decap = resource;
3749 dev_flow->handle->dvh.rix_encap_decap = resource->idx;
3754 * Find existing table jump resource or create and register a new one.
3756 * @param[in, out] dev
3757 * Pointer to rte_eth_dev structure.
3758 * @param[in, out] tbl
3759 * Pointer to flow table resource.
3760 * @parm[in, out] dev_flow
3761 * Pointer to the dev_flow.
3763 * pointer to error structure.
3766 * 0 on success otherwise -errno and errno is set.
3769 flow_dv_jump_tbl_resource_register
3770 (struct rte_eth_dev *dev __rte_unused,
3771 struct mlx5_flow_tbl_resource *tbl,
3772 struct mlx5_flow *dev_flow,
3773 struct rte_flow_error *error __rte_unused)
3775 struct mlx5_flow_tbl_data_entry *tbl_data =
3776 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
3779 MLX5_ASSERT(tbl_data->jump.action);
3780 dev_flow->handle->rix_jump = tbl_data->idx;
3781 dev_flow->dv.jump = &tbl_data->jump;
3786 flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
3787 struct mlx5_list_entry *entry, void *cb_ctx)
3789 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3790 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3791 struct mlx5_flow_dv_port_id_action_resource *res =
3792 container_of(entry, typeof(*res), entry);
3794 return ref->port_id != res->port_id;
3797 struct mlx5_list_entry *
3798 flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
3800 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3801 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3802 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3803 struct mlx5_flow_dv_port_id_action_resource *resource;
3807 /* Register new port id action resource. */
3808 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3810 rte_flow_error_set(ctx->error, ENOMEM,
3811 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3812 "cannot allocate port_id action memory");
3816 ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
3820 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
3821 rte_flow_error_set(ctx->error, ENOMEM,
3822 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3823 "cannot create action");
3826 resource->idx = idx;
3827 return &resource->entry;
3830 struct mlx5_list_entry *
3831 flow_dv_port_id_clone_cb(void *tool_ctx,
3832 struct mlx5_list_entry *entry __rte_unused,
3835 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3836 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3837 struct mlx5_flow_dv_port_id_action_resource *resource;
3840 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3842 rte_flow_error_set(ctx->error, ENOMEM,
3843 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3844 "cannot allocate port_id action memory");
3847 memcpy(resource, entry, sizeof(*resource));
3848 resource->idx = idx;
3849 return &resource->entry;
3853 flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3855 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3856 struct mlx5_flow_dv_port_id_action_resource *resource =
3857 container_of(entry, typeof(*resource), entry);
3859 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
3863 * Find existing table port ID resource or create and register a new one.
3865 * @param[in, out] dev
3866 * Pointer to rte_eth_dev structure.
3867 * @param[in, out] ref
3868 * Pointer to port ID action resource reference.
3869 * @parm[in, out] dev_flow
3870 * Pointer to the dev_flow.
3872 * pointer to error structure.
3875 * 0 on success otherwise -errno and errno is set.
3878 flow_dv_port_id_action_resource_register
3879 (struct rte_eth_dev *dev,
3880 struct mlx5_flow_dv_port_id_action_resource *ref,
3881 struct mlx5_flow *dev_flow,
3882 struct rte_flow_error *error)
3884 struct mlx5_priv *priv = dev->data->dev_private;
3885 struct mlx5_list_entry *entry;
3886 struct mlx5_flow_dv_port_id_action_resource *resource;
3887 struct mlx5_flow_cb_ctx ctx = {
3892 entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
3895 resource = container_of(entry, typeof(*resource), entry);
3896 dev_flow->dv.port_id_action = resource;
3897 dev_flow->handle->rix_port_id_action = resource->idx;
3902 flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
3903 struct mlx5_list_entry *entry, void *cb_ctx)
3905 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3906 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3907 struct mlx5_flow_dv_push_vlan_action_resource *res =
3908 container_of(entry, typeof(*res), entry);
3910 return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
3913 struct mlx5_list_entry *
3914 flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
3916 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3917 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3918 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3919 struct mlx5_flow_dv_push_vlan_action_resource *resource;
3920 struct mlx5dv_dr_domain *domain;
3924 /* Register new port id action resource. */
3925 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3927 rte_flow_error_set(ctx->error, ENOMEM,
3928 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3929 "cannot allocate push_vlan action memory");
3933 if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3934 domain = sh->fdb_domain;
3935 else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3936 domain = sh->rx_domain;
3938 domain = sh->tx_domain;
3939 ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
3942 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
3943 rte_flow_error_set(ctx->error, ENOMEM,
3944 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3945 "cannot create push vlan action");
3948 resource->idx = idx;
3949 return &resource->entry;
3952 struct mlx5_list_entry *
3953 flow_dv_push_vlan_clone_cb(void *tool_ctx,
3954 struct mlx5_list_entry *entry __rte_unused,
3957 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3958 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3959 struct mlx5_flow_dv_push_vlan_action_resource *resource;
3962 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3964 rte_flow_error_set(ctx->error, ENOMEM,
3965 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3966 "cannot allocate push_vlan action memory");
3969 memcpy(resource, entry, sizeof(*resource));
3970 resource->idx = idx;
3971 return &resource->entry;
3975 flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3977 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3978 struct mlx5_flow_dv_push_vlan_action_resource *resource =
3979 container_of(entry, typeof(*resource), entry);
3981 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
3985 * Find existing push vlan resource or create and register a new one.
3987 * @param [in, out] dev
3988 * Pointer to rte_eth_dev structure.
3989 * @param[in, out] ref
3990 * Pointer to port ID action resource reference.
3991 * @parm[in, out] dev_flow
3992 * Pointer to the dev_flow.
3994 * pointer to error structure.
3997 * 0 on success otherwise -errno and errno is set.
4000 flow_dv_push_vlan_action_resource_register
4001 (struct rte_eth_dev *dev,
4002 struct mlx5_flow_dv_push_vlan_action_resource *ref,
4003 struct mlx5_flow *dev_flow,
4004 struct rte_flow_error *error)
4006 struct mlx5_priv *priv = dev->data->dev_private;
4007 struct mlx5_flow_dv_push_vlan_action_resource *resource;
4008 struct mlx5_list_entry *entry;
4009 struct mlx5_flow_cb_ctx ctx = {
4014 entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4017 resource = container_of(entry, typeof(*resource), entry);
4019 dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4020 dev_flow->dv.push_vlan_res = resource;
4025 * Get the size of specific rte_flow_item_type hdr size
4027 * @param[in] item_type
4028 * Tested rte_flow_item_type.
4031 * sizeof struct item_type, 0 if void or irrelevant.
4034 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4038 switch (item_type) {
4039 case RTE_FLOW_ITEM_TYPE_ETH:
4040 retval = sizeof(struct rte_ether_hdr);
4042 case RTE_FLOW_ITEM_TYPE_VLAN:
4043 retval = sizeof(struct rte_vlan_hdr);
4045 case RTE_FLOW_ITEM_TYPE_IPV4:
4046 retval = sizeof(struct rte_ipv4_hdr);
4048 case RTE_FLOW_ITEM_TYPE_IPV6:
4049 retval = sizeof(struct rte_ipv6_hdr);
4051 case RTE_FLOW_ITEM_TYPE_UDP:
4052 retval = sizeof(struct rte_udp_hdr);
4054 case RTE_FLOW_ITEM_TYPE_TCP:
4055 retval = sizeof(struct rte_tcp_hdr);
4057 case RTE_FLOW_ITEM_TYPE_VXLAN:
4058 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4059 retval = sizeof(struct rte_vxlan_hdr);
4061 case RTE_FLOW_ITEM_TYPE_GRE:
4062 case RTE_FLOW_ITEM_TYPE_NVGRE:
4063 retval = sizeof(struct rte_gre_hdr);
4065 case RTE_FLOW_ITEM_TYPE_MPLS:
4066 retval = sizeof(struct rte_mpls_hdr);
4068 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4076 #define MLX5_ENCAP_IPV4_VERSION 0x40
4077 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4078 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4079 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4080 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4081 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4082 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4085 * Convert the encap action data from list of rte_flow_item to raw buffer
4088 * Pointer to rte_flow_item objects list.
4090 * Pointer to the output buffer.
4092 * Pointer to the output buffer size.
4094 * Pointer to the error structure.
4097 * 0 on success, a negative errno value otherwise and rte_errno is set.
4100 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4101 size_t *size, struct rte_flow_error *error)
4103 struct rte_ether_hdr *eth = NULL;
4104 struct rte_vlan_hdr *vlan = NULL;
4105 struct rte_ipv4_hdr *ipv4 = NULL;
4106 struct rte_ipv6_hdr *ipv6 = NULL;
4107 struct rte_udp_hdr *udp = NULL;
4108 struct rte_vxlan_hdr *vxlan = NULL;
4109 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4110 struct rte_gre_hdr *gre = NULL;
4112 size_t temp_size = 0;
4115 return rte_flow_error_set(error, EINVAL,
4116 RTE_FLOW_ERROR_TYPE_ACTION,
4117 NULL, "invalid empty data");
4118 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4119 len = flow_dv_get_item_hdr_len(items->type);
4120 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4121 return rte_flow_error_set(error, EINVAL,
4122 RTE_FLOW_ERROR_TYPE_ACTION,
4123 (void *)items->type,
4124 "items total size is too big"
4125 " for encap action");
4126 rte_memcpy((void *)&buf[temp_size], items->spec, len);
4127 switch (items->type) {
4128 case RTE_FLOW_ITEM_TYPE_ETH:
4129 eth = (struct rte_ether_hdr *)&buf[temp_size];
4131 case RTE_FLOW_ITEM_TYPE_VLAN:
4132 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4134 return rte_flow_error_set(error, EINVAL,
4135 RTE_FLOW_ERROR_TYPE_ACTION,
4136 (void *)items->type,
4137 "eth header not found");
4138 if (!eth->ether_type)
4139 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4141 case RTE_FLOW_ITEM_TYPE_IPV4:
4142 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4144 return rte_flow_error_set(error, EINVAL,
4145 RTE_FLOW_ERROR_TYPE_ACTION,
4146 (void *)items->type,
4147 "neither eth nor vlan"
4149 if (vlan && !vlan->eth_proto)
4150 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4151 else if (eth && !eth->ether_type)
4152 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4153 if (!ipv4->version_ihl)
4154 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4155 MLX5_ENCAP_IPV4_IHL_MIN;
4156 if (!ipv4->time_to_live)
4157 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4159 case RTE_FLOW_ITEM_TYPE_IPV6:
4160 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4162 return rte_flow_error_set(error, EINVAL,
4163 RTE_FLOW_ERROR_TYPE_ACTION,
4164 (void *)items->type,
4165 "neither eth nor vlan"
4167 if (vlan && !vlan->eth_proto)
4168 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4169 else if (eth && !eth->ether_type)
4170 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4171 if (!ipv6->vtc_flow)
4173 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4174 if (!ipv6->hop_limits)
4175 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4177 case RTE_FLOW_ITEM_TYPE_UDP:
4178 udp = (struct rte_udp_hdr *)&buf[temp_size];
4180 return rte_flow_error_set(error, EINVAL,
4181 RTE_FLOW_ERROR_TYPE_ACTION,
4182 (void *)items->type,
4183 "ip header not found");
4184 if (ipv4 && !ipv4->next_proto_id)
4185 ipv4->next_proto_id = IPPROTO_UDP;
4186 else if (ipv6 && !ipv6->proto)
4187 ipv6->proto = IPPROTO_UDP;
4189 case RTE_FLOW_ITEM_TYPE_VXLAN:
4190 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4192 return rte_flow_error_set(error, EINVAL,
4193 RTE_FLOW_ERROR_TYPE_ACTION,
4194 (void *)items->type,
4195 "udp header not found");
4197 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4198 if (!vxlan->vx_flags)
4200 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4202 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4203 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4205 return rte_flow_error_set(error, EINVAL,
4206 RTE_FLOW_ERROR_TYPE_ACTION,
4207 (void *)items->type,
4208 "udp header not found");
4209 if (!vxlan_gpe->proto)
4210 return rte_flow_error_set(error, EINVAL,
4211 RTE_FLOW_ERROR_TYPE_ACTION,
4212 (void *)items->type,
4213 "next protocol not found");
4216 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4217 if (!vxlan_gpe->vx_flags)
4218 vxlan_gpe->vx_flags =
4219 MLX5_ENCAP_VXLAN_GPE_FLAGS;
4221 case RTE_FLOW_ITEM_TYPE_GRE:
4222 case RTE_FLOW_ITEM_TYPE_NVGRE:
4223 gre = (struct rte_gre_hdr *)&buf[temp_size];
4225 return rte_flow_error_set(error, EINVAL,
4226 RTE_FLOW_ERROR_TYPE_ACTION,
4227 (void *)items->type,
4228 "next protocol not found");
4230 return rte_flow_error_set(error, EINVAL,
4231 RTE_FLOW_ERROR_TYPE_ACTION,
4232 (void *)items->type,
4233 "ip header not found");
4234 if (ipv4 && !ipv4->next_proto_id)
4235 ipv4->next_proto_id = IPPROTO_GRE;
4236 else if (ipv6 && !ipv6->proto)
4237 ipv6->proto = IPPROTO_GRE;
4239 case RTE_FLOW_ITEM_TYPE_VOID:
4242 return rte_flow_error_set(error, EINVAL,
4243 RTE_FLOW_ERROR_TYPE_ACTION,
4244 (void *)items->type,
4245 "unsupported item type");
4255 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4257 struct rte_ether_hdr *eth = NULL;
4258 struct rte_vlan_hdr *vlan = NULL;
4259 struct rte_ipv6_hdr *ipv6 = NULL;
4260 struct rte_udp_hdr *udp = NULL;
4264 eth = (struct rte_ether_hdr *)data;
4265 next_hdr = (char *)(eth + 1);
4266 proto = RTE_BE16(eth->ether_type);
4269 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4270 vlan = (struct rte_vlan_hdr *)next_hdr;
4271 proto = RTE_BE16(vlan->eth_proto);
4272 next_hdr += sizeof(struct rte_vlan_hdr);
4275 /* HW calculates IPv4 csum. no need to proceed */
4276 if (proto == RTE_ETHER_TYPE_IPV4)
4279 /* non IPv4/IPv6 header. not supported */
4280 if (proto != RTE_ETHER_TYPE_IPV6) {
4281 return rte_flow_error_set(error, ENOTSUP,
4282 RTE_FLOW_ERROR_TYPE_ACTION,
4283 NULL, "Cannot offload non IPv4/IPv6");
4286 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4288 /* ignore non UDP */
4289 if (ipv6->proto != IPPROTO_UDP)
4292 udp = (struct rte_udp_hdr *)(ipv6 + 1);
4293 udp->dgram_cksum = 0;
4299 * Convert L2 encap action to DV specification.
4302 * Pointer to rte_eth_dev structure.
4304 * Pointer to action structure.
4305 * @param[in, out] dev_flow
4306 * Pointer to the mlx5_flow.
4307 * @param[in] transfer
4308 * Mark if the flow is E-Switch flow.
4310 * Pointer to the error structure.
4313 * 0 on success, a negative errno value otherwise and rte_errno is set.
4316 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4317 const struct rte_flow_action *action,
4318 struct mlx5_flow *dev_flow,
4320 struct rte_flow_error *error)
4322 const struct rte_flow_item *encap_data;
4323 const struct rte_flow_action_raw_encap *raw_encap_data;
4324 struct mlx5_flow_dv_encap_decap_resource res = {
4326 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4327 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4328 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4331 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4333 (const struct rte_flow_action_raw_encap *)action->conf;
4334 res.size = raw_encap_data->size;
4335 memcpy(res.buf, raw_encap_data->data, res.size);
4337 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4339 ((const struct rte_flow_action_vxlan_encap *)
4340 action->conf)->definition;
4343 ((const struct rte_flow_action_nvgre_encap *)
4344 action->conf)->definition;
4345 if (flow_dv_convert_encap_data(encap_data, res.buf,
4349 if (flow_dv_zero_encap_udp_csum(res.buf, error))
4351 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4352 return rte_flow_error_set(error, EINVAL,
4353 RTE_FLOW_ERROR_TYPE_ACTION,
4354 NULL, "can't create L2 encap action");
4359 * Convert L2 decap action to DV specification.
4362 * Pointer to rte_eth_dev structure.
4363 * @param[in, out] dev_flow
4364 * Pointer to the mlx5_flow.
4365 * @param[in] transfer
4366 * Mark if the flow is E-Switch flow.
4368 * Pointer to the error structure.
4371 * 0 on success, a negative errno value otherwise and rte_errno is set.
4374 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
4375 struct mlx5_flow *dev_flow,
4377 struct rte_flow_error *error)
4379 struct mlx5_flow_dv_encap_decap_resource res = {
4382 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
4383 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4384 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
4387 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4388 return rte_flow_error_set(error, EINVAL,
4389 RTE_FLOW_ERROR_TYPE_ACTION,
4390 NULL, "can't create L2 decap action");
4395 * Convert raw decap/encap (L3 tunnel) action to DV specification.
4398 * Pointer to rte_eth_dev structure.
4400 * Pointer to action structure.
4401 * @param[in, out] dev_flow
4402 * Pointer to the mlx5_flow.
4404 * Pointer to the flow attributes.
4406 * Pointer to the error structure.
4409 * 0 on success, a negative errno value otherwise and rte_errno is set.
4412 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
4413 const struct rte_flow_action *action,
4414 struct mlx5_flow *dev_flow,
4415 const struct rte_flow_attr *attr,
4416 struct rte_flow_error *error)
4418 const struct rte_flow_action_raw_encap *encap_data;
4419 struct mlx5_flow_dv_encap_decap_resource res;
4421 memset(&res, 0, sizeof(res));
4422 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
4423 res.size = encap_data->size;
4424 memcpy(res.buf, encap_data->data, res.size);
4425 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
4426 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
4427 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
4429 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4431 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4432 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4433 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4434 return rte_flow_error_set(error, EINVAL,
4435 RTE_FLOW_ERROR_TYPE_ACTION,
4436 NULL, "can't create encap action");
4441 * Create action push VLAN.
4444 * Pointer to rte_eth_dev structure.
4446 * Pointer to the flow attributes.
4448 * Pointer to the vlan to push to the Ethernet header.
4449 * @param[in, out] dev_flow
4450 * Pointer to the mlx5_flow.
4452 * Pointer to the error structure.
4455 * 0 on success, a negative errno value otherwise and rte_errno is set.
4458 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
4459 const struct rte_flow_attr *attr,
4460 const struct rte_vlan_hdr *vlan,
4461 struct mlx5_flow *dev_flow,
4462 struct rte_flow_error *error)
4464 struct mlx5_flow_dv_push_vlan_action_resource res;
4466 memset(&res, 0, sizeof(res));
4468 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
4471 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4473 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4474 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4475 return flow_dv_push_vlan_action_resource_register
4476 (dev, &res, dev_flow, error);
4480 * Validate the modify-header actions.
4482 * @param[in] action_flags
4483 * Holds the actions detected until now.
4485 * Pointer to the modify action.
4487 * Pointer to error structure.
4490 * 0 on success, a negative errno value otherwise and rte_errno is set.
4493 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
4494 const struct rte_flow_action *action,
4495 struct rte_flow_error *error)
4497 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
4498 return rte_flow_error_set(error, EINVAL,
4499 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4500 NULL, "action configuration not set");
4501 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4502 return rte_flow_error_set(error, EINVAL,
4503 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4504 "can't have encap action before"
4510 * Validate the modify-header MAC address actions.
4512 * @param[in] action_flags
4513 * Holds the actions detected until now.
4515 * Pointer to the modify action.
4516 * @param[in] item_flags
4517 * Holds the items detected.
4519 * Pointer to error structure.
4522 * 0 on success, a negative errno value otherwise and rte_errno is set.
4525 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
4526 const struct rte_flow_action *action,
4527 const uint64_t item_flags,
4528 struct rte_flow_error *error)
4532 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4534 if (!(item_flags & MLX5_FLOW_LAYER_L2))
4535 return rte_flow_error_set(error, EINVAL,
4536 RTE_FLOW_ERROR_TYPE_ACTION,
4538 "no L2 item in pattern");
4544 * Validate the modify-header IPv4 address actions.
4546 * @param[in] action_flags
4547 * Holds the actions detected until now.
4549 * Pointer to the modify action.
4550 * @param[in] item_flags
4551 * Holds the items detected.
4553 * Pointer to error structure.
4556 * 0 on success, a negative errno value otherwise and rte_errno is set.
4559 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
4560 const struct rte_flow_action *action,
4561 const uint64_t item_flags,
4562 struct rte_flow_error *error)
4567 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4569 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4570 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4571 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4572 if (!(item_flags & layer))
4573 return rte_flow_error_set(error, EINVAL,
4574 RTE_FLOW_ERROR_TYPE_ACTION,
4576 "no ipv4 item in pattern");
4582 * Validate the modify-header IPv6 address actions.
4584 * @param[in] action_flags
4585 * Holds the actions detected until now.
4587 * Pointer to the modify action.
4588 * @param[in] item_flags
4589 * Holds the items detected.
4591 * Pointer to error structure.
4594 * 0 on success, a negative errno value otherwise and rte_errno is set.
4597 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
4598 const struct rte_flow_action *action,
4599 const uint64_t item_flags,
4600 struct rte_flow_error *error)
4605 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4607 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4608 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4609 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4610 if (!(item_flags & layer))
4611 return rte_flow_error_set(error, EINVAL,
4612 RTE_FLOW_ERROR_TYPE_ACTION,
4614 "no ipv6 item in pattern");
4620 * Validate the modify-header TP actions.
4622 * @param[in] action_flags
4623 * Holds the actions detected until now.
4625 * Pointer to the modify action.
4626 * @param[in] item_flags
4627 * Holds the items detected.
4629 * Pointer to error structure.
4632 * 0 on success, a negative errno value otherwise and rte_errno is set.
4635 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
4636 const struct rte_flow_action *action,
4637 const uint64_t item_flags,
4638 struct rte_flow_error *error)
4643 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4645 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4646 MLX5_FLOW_LAYER_INNER_L4 :
4647 MLX5_FLOW_LAYER_OUTER_L4;
4648 if (!(item_flags & layer))
4649 return rte_flow_error_set(error, EINVAL,
4650 RTE_FLOW_ERROR_TYPE_ACTION,
4651 NULL, "no transport layer "
4658 * Validate the modify-header actions of increment/decrement
4659 * TCP Sequence-number.
4661 * @param[in] action_flags
4662 * Holds the actions detected until now.
4664 * Pointer to the modify action.
4665 * @param[in] item_flags
4666 * Holds the items detected.
4668 * Pointer to error structure.
4671 * 0 on success, a negative errno value otherwise and rte_errno is set.
4674 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
4675 const struct rte_flow_action *action,
4676 const uint64_t item_flags,
4677 struct rte_flow_error *error)
4682 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4684 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4685 MLX5_FLOW_LAYER_INNER_L4_TCP :
4686 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4687 if (!(item_flags & layer))
4688 return rte_flow_error_set(error, EINVAL,
4689 RTE_FLOW_ERROR_TYPE_ACTION,
4690 NULL, "no TCP item in"
4692 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
4693 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
4694 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
4695 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
4696 return rte_flow_error_set(error, EINVAL,
4697 RTE_FLOW_ERROR_TYPE_ACTION,
4699 "cannot decrease and increase"
4700 " TCP sequence number"
4701 " at the same time");
4707 * Validate the modify-header actions of increment/decrement
4708 * TCP Acknowledgment number.
4710 * @param[in] action_flags
4711 * Holds the actions detected until now.
4713 * Pointer to the modify action.
4714 * @param[in] item_flags
4715 * Holds the items detected.
4717 * Pointer to error structure.
4720 * 0 on success, a negative errno value otherwise and rte_errno is set.
4723 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
4724 const struct rte_flow_action *action,
4725 const uint64_t item_flags,
4726 struct rte_flow_error *error)
4731 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4733 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4734 MLX5_FLOW_LAYER_INNER_L4_TCP :
4735 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4736 if (!(item_flags & layer))
4737 return rte_flow_error_set(error, EINVAL,
4738 RTE_FLOW_ERROR_TYPE_ACTION,
4739 NULL, "no TCP item in"
4741 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
4742 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
4743 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
4744 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
4745 return rte_flow_error_set(error, EINVAL,
4746 RTE_FLOW_ERROR_TYPE_ACTION,
4748 "cannot decrease and increase"
4749 " TCP acknowledgment number"
4750 " at the same time");
4756 * Validate the modify-header TTL actions.
4758 * @param[in] action_flags
4759 * Holds the actions detected until now.
4761 * Pointer to the modify action.
4762 * @param[in] item_flags
4763 * Holds the items detected.
4765 * Pointer to error structure.
4768 * 0 on success, a negative errno value otherwise and rte_errno is set.
4771 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
4772 const struct rte_flow_action *action,
4773 const uint64_t item_flags,
4774 struct rte_flow_error *error)
4779 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4781 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4782 MLX5_FLOW_LAYER_INNER_L3 :
4783 MLX5_FLOW_LAYER_OUTER_L3;
4784 if (!(item_flags & layer))
4785 return rte_flow_error_set(error, EINVAL,
4786 RTE_FLOW_ERROR_TYPE_ACTION,
4788 "no IP protocol in pattern");
4794 * Validate the generic modify field actions.
4796 * Pointer to the rte_eth_dev structure.
4797 * @param[in] action_flags
4798 * Holds the actions detected until now.
4800 * Pointer to the modify action.
4802 * Pointer to the flow attributes.
4804 * Pointer to error structure.
4807 * Number of header fields to modify (0 or more) on success,
4808 * a negative errno value otherwise and rte_errno is set.
4811 flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
4812 const uint64_t action_flags,
4813 const struct rte_flow_action *action,
4814 const struct rte_flow_attr *attr,
4815 struct rte_flow_error *error)
4818 struct mlx5_priv *priv = dev->data->dev_private;
4819 struct mlx5_dev_config *config = &priv->config;
4820 const struct rte_flow_action_modify_field *action_modify_field =
4822 uint32_t dst_width = mlx5_flow_item_field_width(dev,
4823 action_modify_field->dst.field,
4825 uint32_t src_width = mlx5_flow_item_field_width(dev,
4826 action_modify_field->src.field,
4827 dst_width, attr, error);
4829 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4833 if (action_modify_field->width == 0)
4834 return rte_flow_error_set(error, EINVAL,
4835 RTE_FLOW_ERROR_TYPE_ACTION, action,
4836 "no bits are requested to be modified");
4837 else if (action_modify_field->width > dst_width ||
4838 action_modify_field->width > src_width)
4839 return rte_flow_error_set(error, EINVAL,
4840 RTE_FLOW_ERROR_TYPE_ACTION, action,
4841 "cannot modify more bits than"
4842 " the width of a field");
4843 if (action_modify_field->dst.field != RTE_FLOW_FIELD_VALUE &&
4844 action_modify_field->dst.field != RTE_FLOW_FIELD_POINTER) {
4845 if ((action_modify_field->dst.offset +
4846 action_modify_field->width > dst_width) ||
4847 (action_modify_field->dst.offset % 32))
4848 return rte_flow_error_set(error, EINVAL,
4849 RTE_FLOW_ERROR_TYPE_ACTION, action,
4850 "destination offset is too big"
4851 " or not aligned to 4 bytes");
4852 if (action_modify_field->dst.level &&
4853 action_modify_field->dst.field != RTE_FLOW_FIELD_TAG)
4854 return rte_flow_error_set(error, ENOTSUP,
4855 RTE_FLOW_ERROR_TYPE_ACTION, action,
4856 "inner header fields modification"
4857 " is not supported");
4859 if (action_modify_field->src.field != RTE_FLOW_FIELD_VALUE &&
4860 action_modify_field->src.field != RTE_FLOW_FIELD_POINTER) {
4861 if (!attr->transfer && !attr->group)
4862 return rte_flow_error_set(error, ENOTSUP,
4863 RTE_FLOW_ERROR_TYPE_ACTION, action,
4864 "modify field action is not"
4865 " supported for group 0");
4866 if ((action_modify_field->src.offset +
4867 action_modify_field->width > src_width) ||
4868 (action_modify_field->src.offset % 32))
4869 return rte_flow_error_set(error, EINVAL,
4870 RTE_FLOW_ERROR_TYPE_ACTION, action,
4871 "source offset is too big"
4872 " or not aligned to 4 bytes");
4873 if (action_modify_field->src.level &&
4874 action_modify_field->src.field != RTE_FLOW_FIELD_TAG)
4875 return rte_flow_error_set(error, ENOTSUP,
4876 RTE_FLOW_ERROR_TYPE_ACTION, action,
4877 "inner header fields modification"
4878 " is not supported");
4880 if ((action_modify_field->dst.field ==
4881 action_modify_field->src.field) &&
4882 (action_modify_field->dst.level ==
4883 action_modify_field->src.level))
4884 return rte_flow_error_set(error, EINVAL,
4885 RTE_FLOW_ERROR_TYPE_ACTION, action,
4886 "source and destination fields"
4887 " cannot be the same");
4888 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VALUE ||
4889 action_modify_field->dst.field == RTE_FLOW_FIELD_POINTER ||
4890 action_modify_field->dst.field == RTE_FLOW_FIELD_MARK)
4891 return rte_flow_error_set(error, EINVAL,
4892 RTE_FLOW_ERROR_TYPE_ACTION, action,
4893 "mark, immediate value or a pointer to it"
4894 " cannot be used as a destination");
4895 if (action_modify_field->dst.field == RTE_FLOW_FIELD_START ||
4896 action_modify_field->src.field == RTE_FLOW_FIELD_START)
4897 return rte_flow_error_set(error, ENOTSUP,
4898 RTE_FLOW_ERROR_TYPE_ACTION, action,
4899 "modifications of an arbitrary"
4900 " place in a packet is not supported");
4901 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VLAN_TYPE ||
4902 action_modify_field->src.field == RTE_FLOW_FIELD_VLAN_TYPE)
4903 return rte_flow_error_set(error, ENOTSUP,
4904 RTE_FLOW_ERROR_TYPE_ACTION, action,
4905 "modifications of the 802.1Q Tag"
4906 " Identifier is not supported");
4907 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VXLAN_VNI ||
4908 action_modify_field->src.field == RTE_FLOW_FIELD_VXLAN_VNI)
4909 return rte_flow_error_set(error, ENOTSUP,
4910 RTE_FLOW_ERROR_TYPE_ACTION, action,
4911 "modifications of the VXLAN Network"
4912 " Identifier is not supported");
4913 if (action_modify_field->dst.field == RTE_FLOW_FIELD_GENEVE_VNI ||
4914 action_modify_field->src.field == RTE_FLOW_FIELD_GENEVE_VNI)
4915 return rte_flow_error_set(error, ENOTSUP,
4916 RTE_FLOW_ERROR_TYPE_ACTION, action,
4917 "modifications of the GENEVE Network"
4918 " Identifier is not supported");
4919 if (action_modify_field->dst.field == RTE_FLOW_FIELD_MARK ||
4920 action_modify_field->src.field == RTE_FLOW_FIELD_MARK)
4921 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4922 !mlx5_flow_ext_mreg_supported(dev))
4923 return rte_flow_error_set(error, ENOTSUP,
4924 RTE_FLOW_ERROR_TYPE_ACTION, action,
4925 "cannot modify mark in legacy mode"
4926 " or without extensive registers");
4927 if (action_modify_field->dst.field == RTE_FLOW_FIELD_META ||
4928 action_modify_field->src.field == RTE_FLOW_FIELD_META) {
4929 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
4930 !mlx5_flow_ext_mreg_supported(dev))
4931 return rte_flow_error_set(error, ENOTSUP,
4932 RTE_FLOW_ERROR_TYPE_ACTION, action,
4933 "cannot modify meta without"
4934 " extensive registers support");
4935 ret = flow_dv_get_metadata_reg(dev, attr, error);
4936 if (ret < 0 || ret == REG_NON)
4937 return rte_flow_error_set(error, ENOTSUP,
4938 RTE_FLOW_ERROR_TYPE_ACTION, action,
4939 "cannot modify meta without"
4940 " extensive registers available");
4942 if (action_modify_field->operation != RTE_FLOW_MODIFY_SET)
4943 return rte_flow_error_set(error, ENOTSUP,
4944 RTE_FLOW_ERROR_TYPE_ACTION, action,
4945 "add and sub operations"
4946 " are not supported");
4947 return (action_modify_field->width / 32) +
4948 !!(action_modify_field->width % 32);
4952 * Validate jump action.
4955 * Pointer to the jump action.
4956 * @param[in] action_flags
4957 * Holds the actions detected until now.
4958 * @param[in] attributes
4959 * Pointer to flow attributes
4960 * @param[in] external
4961 * Action belongs to flow rule created by request external to PMD.
4963 * Pointer to error structure.
4966 * 0 on success, a negative errno value otherwise and rte_errno is set.
4969 flow_dv_validate_action_jump(struct rte_eth_dev *dev,
4970 const struct mlx5_flow_tunnel *tunnel,
4971 const struct rte_flow_action *action,
4972 uint64_t action_flags,
4973 const struct rte_flow_attr *attributes,
4974 bool external, struct rte_flow_error *error)
4976 uint32_t target_group, table = 0;
4978 struct flow_grp_info grp_info = {
4979 .external = !!external,
4980 .transfer = !!attributes->transfer,
4984 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4985 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4986 return rte_flow_error_set(error, EINVAL,
4987 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4988 "can't have 2 fate actions in"
4991 return rte_flow_error_set(error, EINVAL,
4992 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4993 NULL, "action configuration not set");
4995 ((const struct rte_flow_action_jump *)action->conf)->group;
4996 ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5000 if (attributes->group == target_group &&
5001 !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
5002 MLX5_FLOW_ACTION_TUNNEL_MATCH)))
5003 return rte_flow_error_set(error, EINVAL,
5004 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5005 "target group must be other than"
5006 " the current flow group");
5008 return rte_flow_error_set(error, EINVAL,
5009 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5010 NULL, "root table shouldn't be destination");
5015 * Validate action PORT_ID / REPRESENTED_PORT.
5018 * Pointer to rte_eth_dev structure.
5019 * @param[in] action_flags
5020 * Bit-fields that holds the actions detected until now.
5022 * PORT_ID / REPRESENTED_PORT action structure.
5024 * Attributes of flow that includes this action.
5026 * Pointer to error structure.
5029 * 0 on success, a negative errno value otherwise and rte_errno is set.
5032 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5033 uint64_t action_flags,
5034 const struct rte_flow_action *action,
5035 const struct rte_flow_attr *attr,
5036 struct rte_flow_error *error)
5038 const struct rte_flow_action_port_id *port_id;
5039 const struct rte_flow_action_ethdev *ethdev;
5040 struct mlx5_priv *act_priv;
5041 struct mlx5_priv *dev_priv;
5044 if (!attr->transfer)
5045 return rte_flow_error_set(error, ENOTSUP,
5046 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5048 "port action is valid in transfer"
5050 if (!action || !action->conf)
5051 return rte_flow_error_set(error, ENOTSUP,
5052 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5054 "port action parameters must be"
5056 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5057 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5058 return rte_flow_error_set(error, EINVAL,
5059 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5060 "can have only one fate actions in"
5062 dev_priv = mlx5_dev_to_eswitch_info(dev);
5064 return rte_flow_error_set(error, rte_errno,
5065 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5067 "failed to obtain E-Switch info");
5068 switch (action->type) {
5069 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5070 port_id = action->conf;
5071 port = port_id->original ? dev->data->port_id : port_id->id;
5073 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5074 ethdev = action->conf;
5075 port = ethdev->port_id;
5079 return rte_flow_error_set
5081 RTE_FLOW_ERROR_TYPE_ACTION, action,
5082 "unknown E-Switch action");
5084 act_priv = mlx5_port_to_eswitch_info(port, false);
5086 return rte_flow_error_set
5088 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5089 "failed to obtain E-Switch port id for port");
5090 if (act_priv->domain_id != dev_priv->domain_id)
5091 return rte_flow_error_set
5093 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5094 "port does not belong to"
5095 " E-Switch being configured");
5100 * Get the maximum number of modify header actions.
5103 * Pointer to rte_eth_dev structure.
5105 * Whether action is on root table.
5108 * Max number of modify header actions device can support.
5110 static inline unsigned int
5111 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5115 * There's no way to directly query the max capacity from FW.
5116 * The maximal value on root table should be assumed to be supported.
5119 return MLX5_MAX_MODIFY_NUM;
5121 return MLX5_ROOT_TBL_MODIFY_NUM;
5125 * Validate the meter action.
5128 * Pointer to rte_eth_dev structure.
5129 * @param[in] action_flags
5130 * Bit-fields that holds the actions detected until now.
5131 * @param[in] item_flags
5132 * Holds the items detected.
5134 * Pointer to the meter action.
5136 * Attributes of flow that includes this action.
5137 * @param[in] port_id_item
5138 * Pointer to item indicating port id.
5140 * Pointer to error structure.
5143 * 0 on success, a negative errno value otherwise and rte_errno is set.
5146 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5147 uint64_t action_flags, uint64_t item_flags,
5148 const struct rte_flow_action *action,
5149 const struct rte_flow_attr *attr,
5150 const struct rte_flow_item *port_id_item,
5152 struct rte_flow_error *error)
5154 struct mlx5_priv *priv = dev->data->dev_private;
5155 const struct rte_flow_action_meter *am = action->conf;
5156 struct mlx5_flow_meter_info *fm;
5157 struct mlx5_flow_meter_policy *mtr_policy;
5158 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5161 return rte_flow_error_set(error, EINVAL,
5162 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5163 "meter action conf is NULL");
5165 if (action_flags & MLX5_FLOW_ACTION_METER)
5166 return rte_flow_error_set(error, ENOTSUP,
5167 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5168 "meter chaining not support");
5169 if (action_flags & MLX5_FLOW_ACTION_JUMP)
5170 return rte_flow_error_set(error, ENOTSUP,
5171 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5172 "meter with jump not support");
5174 return rte_flow_error_set(error, ENOTSUP,
5175 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5177 "meter action not supported");
5178 fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5180 return rte_flow_error_set(error, EINVAL,
5181 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5183 /* aso meter can always be shared by different domains */
5184 if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5185 !(fm->transfer == attr->transfer ||
5186 (!fm->ingress && !attr->ingress && attr->egress) ||
5187 (!fm->egress && !attr->egress && attr->ingress)))
5188 return rte_flow_error_set(error, EINVAL,
5189 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5190 "Flow attributes domain are either invalid "
5191 "or have a domain conflict with current "
5192 "meter attributes");
5193 if (fm->def_policy) {
5194 if (!((attr->transfer &&
5195 mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
5197 mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
5199 mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
5200 return rte_flow_error_set(error, EINVAL,
5201 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5202 "Flow attributes domain "
5203 "have a conflict with current "
5204 "meter domain attributes");
5207 mtr_policy = mlx5_flow_meter_policy_find(dev,
5208 fm->policy_id, NULL);
5210 return rte_flow_error_set(error, EINVAL,
5211 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5212 "Invalid policy id for meter ");
5213 if (!((attr->transfer && mtr_policy->transfer) ||
5214 (attr->egress && mtr_policy->egress) ||
5215 (attr->ingress && mtr_policy->ingress)))
5216 return rte_flow_error_set(error, EINVAL,
5217 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5218 "Flow attributes domain "
5219 "have a conflict with current "
5220 "meter domain attributes");
5221 if (attr->transfer && mtr_policy->dev) {
5223 * When policy has fate action of port_id,
5224 * the flow should have the same src port as policy.
5226 struct mlx5_priv *policy_port_priv =
5227 mtr_policy->dev->data->dev_private;
5228 int32_t flow_src_port = priv->representor_id;
5231 const struct rte_flow_item_port_id *spec =
5233 struct mlx5_priv *port_priv =
5234 mlx5_port_to_eswitch_info(spec->id,
5237 return rte_flow_error_set(error,
5239 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5241 "Failed to get port info.");
5242 flow_src_port = port_priv->representor_id;
5244 if (flow_src_port != policy_port_priv->representor_id)
5245 return rte_flow_error_set(error,
5247 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5249 "Flow and meter policy "
5250 "have different src port.");
5251 } else if (mtr_policy->is_rss) {
5252 struct mlx5_flow_meter_policy *fp;
5253 struct mlx5_meter_policy_action_container *acg;
5254 struct mlx5_meter_policy_action_container *acy;
5255 const struct rte_flow_action *rss_act;
5258 fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
5261 return rte_flow_error_set(error, EINVAL,
5262 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5263 "Unable to get the final "
5264 "policy in the hierarchy");
5265 acg = &fp->act_cnt[RTE_COLOR_GREEN];
5266 acy = &fp->act_cnt[RTE_COLOR_YELLOW];
5267 MLX5_ASSERT(acg->fate_action ==
5268 MLX5_FLOW_FATE_SHARED_RSS ||
5270 MLX5_FLOW_FATE_SHARED_RSS);
5271 if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
5275 ret = mlx5_flow_validate_action_rss(rss_act,
5276 action_flags, dev, attr,
5281 *def_policy = false;
5287 * Validate the age action.
5289 * @param[in] action_flags
5290 * Holds the actions detected until now.
5292 * Pointer to the age action.
5294 * Pointer to the Ethernet device structure.
5296 * Pointer to error structure.
5299 * 0 on success, a negative errno value otherwise and rte_errno is set.
5302 flow_dv_validate_action_age(uint64_t action_flags,
5303 const struct rte_flow_action *action,
5304 struct rte_eth_dev *dev,
5305 struct rte_flow_error *error)
5307 struct mlx5_priv *priv = dev->data->dev_private;
5308 const struct rte_flow_action_age *age = action->conf;
5310 if (!priv->sh->devx || (priv->sh->cmng.counter_fallback &&
5311 !priv->sh->aso_age_mng))
5312 return rte_flow_error_set(error, ENOTSUP,
5313 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5315 "age action not supported");
5316 if (!(action->conf))
5317 return rte_flow_error_set(error, EINVAL,
5318 RTE_FLOW_ERROR_TYPE_ACTION, action,
5319 "configuration cannot be null");
5320 if (!(age->timeout))
5321 return rte_flow_error_set(error, EINVAL,
5322 RTE_FLOW_ERROR_TYPE_ACTION, action,
5323 "invalid timeout value 0");
5324 if (action_flags & MLX5_FLOW_ACTION_AGE)
5325 return rte_flow_error_set(error, EINVAL,
5326 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5327 "duplicate age actions set");
5332 * Validate the modify-header IPv4 DSCP actions.
5334 * @param[in] action_flags
5335 * Holds the actions detected until now.
5337 * Pointer to the modify action.
5338 * @param[in] item_flags
5339 * Holds the items detected.
5341 * Pointer to error structure.
5344 * 0 on success, a negative errno value otherwise and rte_errno is set.
5347 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
5348 const struct rte_flow_action *action,
5349 const uint64_t item_flags,
5350 struct rte_flow_error *error)
5354 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5356 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
5357 return rte_flow_error_set(error, EINVAL,
5358 RTE_FLOW_ERROR_TYPE_ACTION,
5360 "no ipv4 item in pattern");
5366 * Validate the modify-header IPv6 DSCP actions.
5368 * @param[in] action_flags
5369 * Holds the actions detected until now.
5371 * Pointer to the modify action.
5372 * @param[in] item_flags
5373 * Holds the items detected.
5375 * Pointer to error structure.
5378 * 0 on success, a negative errno value otherwise and rte_errno is set.
5381 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
5382 const struct rte_flow_action *action,
5383 const uint64_t item_flags,
5384 struct rte_flow_error *error)
5388 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5390 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
5391 return rte_flow_error_set(error, EINVAL,
5392 RTE_FLOW_ERROR_TYPE_ACTION,
5394 "no ipv6 item in pattern");
5400 flow_dv_modify_match_cb(void *tool_ctx __rte_unused,
5401 struct mlx5_list_entry *entry, void *cb_ctx)
5403 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5404 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5405 struct mlx5_flow_dv_modify_hdr_resource *resource =
5406 container_of(entry, typeof(*resource), entry);
5407 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5409 key_len += ref->actions_num * sizeof(ref->actions[0]);
5410 return ref->actions_num != resource->actions_num ||
5411 memcmp(&ref->ft_type, &resource->ft_type, key_len);
5414 static struct mlx5_indexed_pool *
5415 flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
5417 struct mlx5_indexed_pool *ipool = __atomic_load_n
5418 (&sh->mdh_ipools[index], __ATOMIC_SEQ_CST);
5421 struct mlx5_indexed_pool *expected = NULL;
5422 struct mlx5_indexed_pool_config cfg =
5423 (struct mlx5_indexed_pool_config) {
5424 .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
5426 sizeof(struct mlx5_modification_cmd),
5431 .release_mem_en = !!sh->reclaim_mode,
5432 .per_core_cache = sh->reclaim_mode ? 0 : (1 << 16),
5433 .malloc = mlx5_malloc,
5435 .type = "mlx5_modify_action_resource",
5438 cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
5439 ipool = mlx5_ipool_create(&cfg);
5442 if (!__atomic_compare_exchange_n(&sh->mdh_ipools[index],
5443 &expected, ipool, false,
5445 __ATOMIC_SEQ_CST)) {
5446 mlx5_ipool_destroy(ipool);
5447 ipool = __atomic_load_n(&sh->mdh_ipools[index],
5454 struct mlx5_list_entry *
5455 flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
5457 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5458 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5459 struct mlx5dv_dr_domain *ns;
5460 struct mlx5_flow_dv_modify_hdr_resource *entry;
5461 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5462 struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
5463 ref->actions_num - 1);
5465 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5466 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5469 if (unlikely(!ipool)) {
5470 rte_flow_error_set(ctx->error, ENOMEM,
5471 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5472 NULL, "cannot allocate modify ipool");
5475 entry = mlx5_ipool_zmalloc(ipool, &idx);
5477 rte_flow_error_set(ctx->error, ENOMEM,
5478 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5479 "cannot allocate resource memory");
5482 rte_memcpy(&entry->ft_type,
5483 RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
5484 key_len + data_len);
5485 if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
5486 ns = sh->fdb_domain;
5487 else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
5491 ret = mlx5_flow_os_create_flow_action_modify_header
5492 (sh->cdev->ctx, ns, entry,
5493 data_len, &entry->action);
5495 mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
5496 rte_flow_error_set(ctx->error, ENOMEM,
5497 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5498 NULL, "cannot create modification action");
5502 return &entry->entry;
5505 struct mlx5_list_entry *
5506 flow_dv_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5509 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5510 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5511 struct mlx5_flow_dv_modify_hdr_resource *entry;
5512 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5513 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5516 entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
5519 rte_flow_error_set(ctx->error, ENOMEM,
5520 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5521 "cannot allocate resource memory");
5524 memcpy(entry, oentry, sizeof(*entry) + data_len);
5526 return &entry->entry;
5530 flow_dv_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5532 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5533 struct mlx5_flow_dv_modify_hdr_resource *res =
5534 container_of(entry, typeof(*res), entry);
5536 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
5540 * Validate the sample action.
5542 * @param[in, out] action_flags
5543 * Holds the actions detected until now.
5545 * Pointer to the sample action.
5547 * Pointer to the Ethernet device structure.
5549 * Attributes of flow that includes this action.
5550 * @param[in] item_flags
5551 * Holds the items detected.
5553 * Pointer to the RSS action.
5554 * @param[out] sample_rss
5555 * Pointer to the RSS action in sample action list.
5557 * Pointer to the COUNT action in sample action list.
5558 * @param[out] fdb_mirror_limit
5559 * Pointer to the FDB mirror limitation flag.
5561 * Pointer to error structure.
5564 * 0 on success, a negative errno value otherwise and rte_errno is set.
5567 flow_dv_validate_action_sample(uint64_t *action_flags,
5568 const struct rte_flow_action *action,
5569 struct rte_eth_dev *dev,
5570 const struct rte_flow_attr *attr,
5571 uint64_t item_flags,
5572 const struct rte_flow_action_rss *rss,
5573 const struct rte_flow_action_rss **sample_rss,
5574 const struct rte_flow_action_count **count,
5575 int *fdb_mirror_limit,
5576 struct rte_flow_error *error)
5578 struct mlx5_priv *priv = dev->data->dev_private;
5579 struct mlx5_dev_config *dev_conf = &priv->config;
5580 const struct rte_flow_action_sample *sample = action->conf;
5581 const struct rte_flow_action *act;
5582 uint64_t sub_action_flags = 0;
5583 uint16_t queue_index = 0xFFFF;
5588 return rte_flow_error_set(error, EINVAL,
5589 RTE_FLOW_ERROR_TYPE_ACTION, action,
5590 "configuration cannot be NULL");
5591 if (sample->ratio == 0)
5592 return rte_flow_error_set(error, EINVAL,
5593 RTE_FLOW_ERROR_TYPE_ACTION, action,
5594 "ratio value starts from 1");
5595 if (!priv->sh->devx || (sample->ratio > 0 && !priv->sampler_en))
5596 return rte_flow_error_set(error, ENOTSUP,
5597 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5599 "sample action not supported");
5600 if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
5601 return rte_flow_error_set(error, EINVAL,
5602 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5603 "Multiple sample actions not "
5605 if (*action_flags & MLX5_FLOW_ACTION_METER)
5606 return rte_flow_error_set(error, EINVAL,
5607 RTE_FLOW_ERROR_TYPE_ACTION, action,
5608 "wrong action order, meter should "
5609 "be after sample action");
5610 if (*action_flags & MLX5_FLOW_ACTION_JUMP)
5611 return rte_flow_error_set(error, EINVAL,
5612 RTE_FLOW_ERROR_TYPE_ACTION, action,
5613 "wrong action order, jump should "
5614 "be after sample action");
5615 if (*action_flags & MLX5_FLOW_ACTION_CT)
5616 return rte_flow_error_set(error, EINVAL,
5617 RTE_FLOW_ERROR_TYPE_ACTION, action,
5618 "Sample after CT not supported");
5619 act = sample->actions;
5620 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
5621 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5622 return rte_flow_error_set(error, ENOTSUP,
5623 RTE_FLOW_ERROR_TYPE_ACTION,
5624 act, "too many actions");
5625 switch (act->type) {
5626 case RTE_FLOW_ACTION_TYPE_QUEUE:
5627 ret = mlx5_flow_validate_action_queue(act,
5633 queue_index = ((const struct rte_flow_action_queue *)
5634 (act->conf))->index;
5635 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
5638 case RTE_FLOW_ACTION_TYPE_RSS:
5639 *sample_rss = act->conf;
5640 ret = mlx5_flow_validate_action_rss(act,
5647 if (rss && *sample_rss &&
5648 ((*sample_rss)->level != rss->level ||
5649 (*sample_rss)->types != rss->types))
5650 return rte_flow_error_set(error, ENOTSUP,
5651 RTE_FLOW_ERROR_TYPE_ACTION,
5653 "Can't use the different RSS types "
5654 "or level in the same flow");
5655 if (*sample_rss != NULL && (*sample_rss)->queue_num)
5656 queue_index = (*sample_rss)->queue[0];
5657 sub_action_flags |= MLX5_FLOW_ACTION_RSS;
5660 case RTE_FLOW_ACTION_TYPE_MARK:
5661 ret = flow_dv_validate_action_mark(dev, act,
5666 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
5667 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
5668 MLX5_FLOW_ACTION_MARK_EXT;
5670 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
5673 case RTE_FLOW_ACTION_TYPE_COUNT:
5674 ret = flow_dv_validate_action_count
5675 (dev, false, *action_flags | sub_action_flags,
5680 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
5681 *action_flags |= MLX5_FLOW_ACTION_COUNT;
5684 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5685 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5686 ret = flow_dv_validate_action_port_id(dev,
5693 sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5696 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5697 ret = flow_dv_validate_action_raw_encap_decap
5698 (dev, NULL, act->conf, attr, &sub_action_flags,
5699 &actions_n, action, item_flags, error);
5704 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5705 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5706 ret = flow_dv_validate_action_l2_encap(dev,
5712 sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
5716 return rte_flow_error_set(error, ENOTSUP,
5717 RTE_FLOW_ERROR_TYPE_ACTION,
5719 "Doesn't support optional "
5723 if (attr->ingress && !attr->transfer) {
5724 if (!(sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
5725 MLX5_FLOW_ACTION_RSS)))
5726 return rte_flow_error_set(error, EINVAL,
5727 RTE_FLOW_ERROR_TYPE_ACTION,
5729 "Ingress must has a dest "
5730 "QUEUE for Sample");
5731 } else if (attr->egress && !attr->transfer) {
5732 return rte_flow_error_set(error, ENOTSUP,
5733 RTE_FLOW_ERROR_TYPE_ACTION,
5735 "Sample Only support Ingress "
5737 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
5738 MLX5_ASSERT(attr->transfer);
5739 if (sample->ratio > 1)
5740 return rte_flow_error_set(error, ENOTSUP,
5741 RTE_FLOW_ERROR_TYPE_ACTION,
5743 "E-Switch doesn't support "
5744 "any optional action "
5746 if (sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
5747 return rte_flow_error_set(error, ENOTSUP,
5748 RTE_FLOW_ERROR_TYPE_ACTION,
5750 "unsupported action QUEUE");
5751 if (sub_action_flags & MLX5_FLOW_ACTION_RSS)
5752 return rte_flow_error_set(error, ENOTSUP,
5753 RTE_FLOW_ERROR_TYPE_ACTION,
5755 "unsupported action QUEUE");
5756 if (!(sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
5757 return rte_flow_error_set(error, EINVAL,
5758 RTE_FLOW_ERROR_TYPE_ACTION,
5760 "E-Switch must has a dest "
5761 "port for mirroring");
5762 if (!priv->config.hca_attr.reg_c_preserve &&
5763 priv->representor_id != UINT16_MAX)
5764 *fdb_mirror_limit = 1;
5766 /* Continue validation for Xcap actions.*/
5767 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
5768 (queue_index == 0xFFFF ||
5769 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5770 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5771 MLX5_FLOW_XCAP_ACTIONS)
5772 return rte_flow_error_set(error, ENOTSUP,
5773 RTE_FLOW_ERROR_TYPE_ACTION,
5774 NULL, "encap and decap "
5775 "combination aren't "
5777 if (!attr->transfer && attr->ingress && (sub_action_flags &
5778 MLX5_FLOW_ACTION_ENCAP))
5779 return rte_flow_error_set(error, ENOTSUP,
5780 RTE_FLOW_ERROR_TYPE_ACTION,
5781 NULL, "encap is not supported"
5782 " for ingress traffic");
5788 * Find existing modify-header resource or create and register a new one.
5790 * @param dev[in, out]
5791 * Pointer to rte_eth_dev structure.
5792 * @param[in, out] resource
5793 * Pointer to modify-header resource.
5794 * @parm[in, out] dev_flow
5795 * Pointer to the dev_flow.
5797 * pointer to error structure.
5800 * 0 on success otherwise -errno and errno is set.
5803 flow_dv_modify_hdr_resource_register
5804 (struct rte_eth_dev *dev,
5805 struct mlx5_flow_dv_modify_hdr_resource *resource,
5806 struct mlx5_flow *dev_flow,
5807 struct rte_flow_error *error)
5809 struct mlx5_priv *priv = dev->data->dev_private;
5810 struct mlx5_dev_ctx_shared *sh = priv->sh;
5811 uint32_t key_len = sizeof(*resource) -
5812 offsetof(typeof(*resource), ft_type) +
5813 resource->actions_num * sizeof(resource->actions[0]);
5814 struct mlx5_list_entry *entry;
5815 struct mlx5_flow_cb_ctx ctx = {
5819 struct mlx5_hlist *modify_cmds;
5822 modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
5824 MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
5826 flow_dv_modify_create_cb,
5827 flow_dv_modify_match_cb,
5828 flow_dv_modify_remove_cb,
5829 flow_dv_modify_clone_cb,
5830 flow_dv_modify_clone_free_cb);
5831 if (unlikely(!modify_cmds))
5833 resource->root = !dev_flow->dv.group;
5834 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
5836 return rte_flow_error_set(error, EOVERFLOW,
5837 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5838 "too many modify header items");
5839 key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
5840 entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
5843 resource = container_of(entry, typeof(*resource), entry);
5844 dev_flow->handle->dvh.modify_hdr = resource;
5849 * Get DV flow counter by index.
5852 * Pointer to the Ethernet device structure.
5854 * mlx5 flow counter index in the container.
5856 * mlx5 flow counter pool in the container.
5859 * Pointer to the counter, NULL otherwise.
5861 static struct mlx5_flow_counter *
5862 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
5864 struct mlx5_flow_counter_pool **ppool)
5866 struct mlx5_priv *priv = dev->data->dev_private;
5867 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5868 struct mlx5_flow_counter_pool *pool;
5870 /* Decrease to original index and clear shared bit. */
5871 idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
5872 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cmng->n);
5873 pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
5877 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
5881 * Check the devx counter belongs to the pool.
5884 * Pointer to the counter pool.
5886 * The counter devx ID.
5889 * True if counter belongs to the pool, false otherwise.
5892 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
5894 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
5895 MLX5_COUNTERS_PER_POOL;
5897 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
5903 * Get a pool by devx counter ID.
5906 * Pointer to the counter management.
5908 * The counter devx ID.
5911 * The counter pool pointer if exists, NULL otherwise,
5913 static struct mlx5_flow_counter_pool *
5914 flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
5917 struct mlx5_flow_counter_pool *pool = NULL;
5919 rte_spinlock_lock(&cmng->pool_update_sl);
5920 /* Check last used pool. */
5921 if (cmng->last_pool_idx != POOL_IDX_INVALID &&
5922 flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
5923 pool = cmng->pools[cmng->last_pool_idx];
5926 /* ID out of range means no suitable pool in the container. */
5927 if (id > cmng->max_id || id < cmng->min_id)
5930 * Find the pool from the end of the container, since mostly counter
5931 * ID is sequence increasing, and the last pool should be the needed
5936 struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
5938 if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
5944 rte_spinlock_unlock(&cmng->pool_update_sl);
5949 * Resize a counter container.
5952 * Pointer to the Ethernet device structure.
5955 * 0 on success, otherwise negative errno value and rte_errno is set.
5958 flow_dv_container_resize(struct rte_eth_dev *dev)
5960 struct mlx5_priv *priv = dev->data->dev_private;
5961 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5962 void *old_pools = cmng->pools;
5963 uint32_t resize = cmng->n + MLX5_CNT_CONTAINER_RESIZE;
5964 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
5965 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
5972 memcpy(pools, old_pools, cmng->n *
5973 sizeof(struct mlx5_flow_counter_pool *));
5975 cmng->pools = pools;
5977 mlx5_free(old_pools);
5982 * Query a devx flow counter.
5985 * Pointer to the Ethernet device structure.
5986 * @param[in] counter
5987 * Index to the flow counter.
5989 * The statistics value of packets.
5991 * The statistics value of bytes.
5994 * 0 on success, otherwise a negative errno value and rte_errno is set.
5997 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6000 struct mlx5_priv *priv = dev->data->dev_private;
6001 struct mlx5_flow_counter_pool *pool = NULL;
6002 struct mlx5_flow_counter *cnt;
6005 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6007 if (priv->sh->cmng.counter_fallback)
6008 return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6009 0, pkts, bytes, 0, NULL, NULL, 0);
6010 rte_spinlock_lock(&pool->sl);
6015 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6016 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6017 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6019 rte_spinlock_unlock(&pool->sl);
6024 * Create and initialize a new counter pool.
6027 * Pointer to the Ethernet device structure.
6029 * The devX counter handle.
6031 * Whether the pool is for counter that was allocated for aging.
6032 * @param[in/out] cont_cur
6033 * Pointer to the container pointer, it will be update in pool resize.
6036 * The pool container pointer on success, NULL otherwise and rte_errno is set.
6038 static struct mlx5_flow_counter_pool *
6039 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6042 struct mlx5_priv *priv = dev->data->dev_private;
6043 struct mlx5_flow_counter_pool *pool;
6044 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6045 bool fallback = priv->sh->cmng.counter_fallback;
6046 uint32_t size = sizeof(*pool);
6048 size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6049 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6050 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6056 pool->is_aged = !!age;
6057 pool->query_gen = 0;
6058 pool->min_dcs = dcs;
6059 rte_spinlock_init(&pool->sl);
6060 rte_spinlock_init(&pool->csl);
6061 TAILQ_INIT(&pool->counters[0]);
6062 TAILQ_INIT(&pool->counters[1]);
6063 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6064 rte_spinlock_lock(&cmng->pool_update_sl);
6065 pool->index = cmng->n_valid;
6066 if (pool->index == cmng->n && flow_dv_container_resize(dev)) {
6068 rte_spinlock_unlock(&cmng->pool_update_sl);
6071 cmng->pools[pool->index] = pool;
6073 if (unlikely(fallback)) {
6074 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6076 if (base < cmng->min_id)
6077 cmng->min_id = base;
6078 if (base > cmng->max_id)
6079 cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6080 cmng->last_pool_idx = pool->index;
6082 rte_spinlock_unlock(&cmng->pool_update_sl);
6087 * Prepare a new counter and/or a new counter pool.
6090 * Pointer to the Ethernet device structure.
6091 * @param[out] cnt_free
6092 * Where to put the pointer of a new counter.
6094 * Whether the pool is for counter that was allocated for aging.
6097 * The counter pool pointer and @p cnt_free is set on success,
6098 * NULL otherwise and rte_errno is set.
6100 static struct mlx5_flow_counter_pool *
6101 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6102 struct mlx5_flow_counter **cnt_free,
6105 struct mlx5_priv *priv = dev->data->dev_private;
6106 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6107 struct mlx5_flow_counter_pool *pool;
6108 struct mlx5_counters tmp_tq;
6109 struct mlx5_devx_obj *dcs = NULL;
6110 struct mlx5_flow_counter *cnt;
6111 enum mlx5_counter_type cnt_type =
6112 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6113 bool fallback = priv->sh->cmng.counter_fallback;
6117 /* bulk_bitmap must be 0 for single counter allocation. */
6118 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6121 pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6123 pool = flow_dv_pool_create(dev, dcs, age);
6125 mlx5_devx_cmd_destroy(dcs);
6129 i = dcs->id % MLX5_COUNTERS_PER_POOL;
6130 cnt = MLX5_POOL_GET_CNT(pool, i);
6132 cnt->dcs_when_free = dcs;
6136 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6138 rte_errno = ENODATA;
6141 pool = flow_dv_pool_create(dev, dcs, age);
6143 mlx5_devx_cmd_destroy(dcs);
6146 TAILQ_INIT(&tmp_tq);
6147 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6148 cnt = MLX5_POOL_GET_CNT(pool, i);
6150 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6152 rte_spinlock_lock(&cmng->csl[cnt_type]);
6153 TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6154 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6155 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6156 (*cnt_free)->pool = pool;
6161 * Allocate a flow counter.
6164 * Pointer to the Ethernet device structure.
6166 * Whether the counter was allocated for aging.
6169 * Index to flow counter on success, 0 otherwise and rte_errno is set.
6172 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6174 struct mlx5_priv *priv = dev->data->dev_private;
6175 struct mlx5_flow_counter_pool *pool = NULL;
6176 struct mlx5_flow_counter *cnt_free = NULL;
6177 bool fallback = priv->sh->cmng.counter_fallback;
6178 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6179 enum mlx5_counter_type cnt_type =
6180 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6183 if (!priv->sh->devx) {
6184 rte_errno = ENOTSUP;
6187 /* Get free counters from container. */
6188 rte_spinlock_lock(&cmng->csl[cnt_type]);
6189 cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6191 TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6192 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6193 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6195 pool = cnt_free->pool;
6197 cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6198 /* Create a DV counter action only in the first time usage. */
6199 if (!cnt_free->action) {
6201 struct mlx5_devx_obj *dcs;
6205 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
6206 dcs = pool->min_dcs;
6209 dcs = cnt_free->dcs_when_free;
6211 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
6218 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
6219 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
6220 /* Update the counter reset values. */
6221 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
6224 if (!fallback && !priv->sh->cmng.query_thread_on)
6225 /* Start the asynchronous batch query by the host thread. */
6226 mlx5_set_query_alarm(priv->sh);
6228 * When the count action isn't shared (by ID), shared_info field is
6229 * used for indirect action API's refcnt.
6230 * When the counter action is not shared neither by ID nor by indirect
6231 * action API, shared info must be 1.
6233 cnt_free->shared_info.refcnt = 1;
6237 cnt_free->pool = pool;
6239 cnt_free->dcs_when_free = cnt_free->dcs_when_active;
6240 rte_spinlock_lock(&cmng->csl[cnt_type]);
6241 TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
6242 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6248 * Get age param from counter index.
6251 * Pointer to the Ethernet device structure.
6252 * @param[in] counter
6253 * Index to the counter handler.
6256 * The aging parameter specified for the counter index.
6258 static struct mlx5_age_param*
6259 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
6262 struct mlx5_flow_counter *cnt;
6263 struct mlx5_flow_counter_pool *pool = NULL;
6265 flow_dv_counter_get_by_idx(dev, counter, &pool);
6266 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
6267 cnt = MLX5_POOL_GET_CNT(pool, counter);
6268 return MLX5_CNT_TO_AGE(cnt);
6272 * Remove a flow counter from aged counter list.
6275 * Pointer to the Ethernet device structure.
6276 * @param[in] counter
6277 * Index to the counter handler.
6279 * Pointer to the counter handler.
6282 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
6283 uint32_t counter, struct mlx5_flow_counter *cnt)
6285 struct mlx5_age_info *age_info;
6286 struct mlx5_age_param *age_param;
6287 struct mlx5_priv *priv = dev->data->dev_private;
6288 uint16_t expected = AGE_CANDIDATE;
6290 age_info = GET_PORT_AGE_INFO(priv);
6291 age_param = flow_dv_counter_idx_get_age(dev, counter);
6292 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
6293 AGE_FREE, false, __ATOMIC_RELAXED,
6294 __ATOMIC_RELAXED)) {
6296 * We need the lock even it is age timeout,
6297 * since counter may still in process.
6299 rte_spinlock_lock(&age_info->aged_sl);
6300 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
6301 rte_spinlock_unlock(&age_info->aged_sl);
6302 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
6307 * Release a flow counter.
6310 * Pointer to the Ethernet device structure.
6311 * @param[in] counter
6312 * Index to the counter handler.
6315 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
6317 struct mlx5_priv *priv = dev->data->dev_private;
6318 struct mlx5_flow_counter_pool *pool = NULL;
6319 struct mlx5_flow_counter *cnt;
6320 enum mlx5_counter_type cnt_type;
6324 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6326 if (pool->is_aged) {
6327 flow_dv_counter_remove_from_age(dev, counter, cnt);
6330 * If the counter action is shared by indirect action API,
6331 * the atomic function reduces its references counter.
6332 * If after the reduction the action is still referenced, the
6333 * function returns here and does not release it.
6334 * When the counter action is not shared by
6335 * indirect action API, shared info is 1 before the reduction,
6336 * so this condition is failed and function doesn't return here.
6338 if (__atomic_sub_fetch(&cnt->shared_info.refcnt, 1,
6344 * Put the counter back to list to be updated in none fallback mode.
6345 * Currently, we are using two list alternately, while one is in query,
6346 * add the freed counter to the other list based on the pool query_gen
6347 * value. After query finishes, add counter the list to the global
6348 * container counter list. The list changes while query starts. In
6349 * this case, lock will not be needed as query callback and release
6350 * function both operate with the different list.
6352 if (!priv->sh->cmng.counter_fallback) {
6353 rte_spinlock_lock(&pool->csl);
6354 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
6355 rte_spinlock_unlock(&pool->csl);
6357 cnt->dcs_when_free = cnt->dcs_when_active;
6358 cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6359 MLX5_COUNTER_TYPE_ORIGIN;
6360 rte_spinlock_lock(&priv->sh->cmng.csl[cnt_type]);
6361 TAILQ_INSERT_TAIL(&priv->sh->cmng.counters[cnt_type],
6363 rte_spinlock_unlock(&priv->sh->cmng.csl[cnt_type]);
6368 * Resize a meter id container.
6371 * Pointer to the Ethernet device structure.
6374 * 0 on success, otherwise negative errno value and rte_errno is set.
6377 flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
6379 struct mlx5_priv *priv = dev->data->dev_private;
6380 struct mlx5_aso_mtr_pools_mng *pools_mng =
6381 &priv->sh->mtrmng->pools_mng;
6382 void *old_pools = pools_mng->pools;
6383 uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
6384 uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
6385 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
6392 if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER)) {
6397 memcpy(pools, old_pools, pools_mng->n *
6398 sizeof(struct mlx5_aso_mtr_pool *));
6399 pools_mng->n = resize;
6400 pools_mng->pools = pools;
6402 mlx5_free(old_pools);
6407 * Prepare a new meter and/or a new meter pool.
6410 * Pointer to the Ethernet device structure.
6411 * @param[out] mtr_free
6412 * Where to put the pointer of a new meter.g.
6415 * The meter pool pointer and @mtr_free is set on success,
6416 * NULL otherwise and rte_errno is set.
6418 static struct mlx5_aso_mtr_pool *
6419 flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
6421 struct mlx5_priv *priv = dev->data->dev_private;
6422 struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
6423 struct mlx5_aso_mtr_pool *pool = NULL;
6424 struct mlx5_devx_obj *dcs = NULL;
6426 uint32_t log_obj_size;
6428 log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
6429 dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
6430 priv->sh->cdev->pdn,
6433 rte_errno = ENODATA;
6436 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
6439 claim_zero(mlx5_devx_cmd_destroy(dcs));
6442 pool->devx_obj = dcs;
6443 rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
6444 pool->index = pools_mng->n_valid;
6445 if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
6447 claim_zero(mlx5_devx_cmd_destroy(dcs));
6448 rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
6451 pools_mng->pools[pool->index] = pool;
6452 pools_mng->n_valid++;
6453 rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
6454 for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
6455 pool->mtrs[i].offset = i;
6456 LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
6458 pool->mtrs[0].offset = 0;
6459 *mtr_free = &pool->mtrs[0];
6464 * Release a flow meter into pool.
6467 * Pointer to the Ethernet device structure.
6468 * @param[in] mtr_idx
6469 * Index to aso flow meter.
6472 flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
6474 struct mlx5_priv *priv = dev->data->dev_private;
6475 struct mlx5_aso_mtr_pools_mng *pools_mng =
6476 &priv->sh->mtrmng->pools_mng;
6477 struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
6479 MLX5_ASSERT(aso_mtr);
6480 rte_spinlock_lock(&pools_mng->mtrsl);
6481 memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
6482 aso_mtr->state = ASO_METER_FREE;
6483 LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
6484 rte_spinlock_unlock(&pools_mng->mtrsl);
6488 * Allocate a aso flow meter.
6491 * Pointer to the Ethernet device structure.
6494 * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
6497 flow_dv_mtr_alloc(struct rte_eth_dev *dev)
6499 struct mlx5_priv *priv = dev->data->dev_private;
6500 struct mlx5_aso_mtr *mtr_free = NULL;
6501 struct mlx5_aso_mtr_pools_mng *pools_mng =
6502 &priv->sh->mtrmng->pools_mng;
6503 struct mlx5_aso_mtr_pool *pool;
6504 uint32_t mtr_idx = 0;
6506 if (!priv->sh->devx) {
6507 rte_errno = ENOTSUP;
6510 /* Allocate the flow meter memory. */
6511 /* Get free meters from management. */
6512 rte_spinlock_lock(&pools_mng->mtrsl);
6513 mtr_free = LIST_FIRST(&pools_mng->meters);
6515 LIST_REMOVE(mtr_free, next);
6516 if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
6517 rte_spinlock_unlock(&pools_mng->mtrsl);
6520 mtr_free->state = ASO_METER_WAIT;
6521 rte_spinlock_unlock(&pools_mng->mtrsl);
6522 pool = container_of(mtr_free,
6523 struct mlx5_aso_mtr_pool,
6524 mtrs[mtr_free->offset]);
6525 mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
6526 if (!mtr_free->fm.meter_action) {
6527 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
6528 struct rte_flow_error error;
6531 reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
6532 mtr_free->fm.meter_action =
6533 mlx5_glue->dv_create_flow_action_aso
6534 (priv->sh->rx_domain,
6535 pool->devx_obj->obj,
6537 (1 << MLX5_FLOW_COLOR_GREEN),
6539 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
6540 if (!mtr_free->fm.meter_action) {
6541 flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
6549 * Verify the @p attributes will be correctly understood by the NIC and store
6550 * them in the @p flow if everything is correct.
6553 * Pointer to dev struct.
6554 * @param[in] attributes
6555 * Pointer to flow attributes
6556 * @param[in] external
6557 * This flow rule is created by request external to PMD.
6559 * Pointer to error structure.
6562 * - 0 on success and non root table.
6563 * - 1 on success and root table.
6564 * - a negative errno value otherwise and rte_errno is set.
6567 flow_dv_validate_attributes(struct rte_eth_dev *dev,
6568 const struct mlx5_flow_tunnel *tunnel,
6569 const struct rte_flow_attr *attributes,
6570 const struct flow_grp_info *grp_info,
6571 struct rte_flow_error *error)
6573 struct mlx5_priv *priv = dev->data->dev_private;
6574 uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
6577 #ifndef HAVE_MLX5DV_DR
6578 RTE_SET_USED(tunnel);
6579 RTE_SET_USED(grp_info);
6580 if (attributes->group)
6581 return rte_flow_error_set(error, ENOTSUP,
6582 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6584 "groups are not supported");
6588 ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
6593 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
6595 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
6596 attributes->priority > lowest_priority)
6597 return rte_flow_error_set(error, ENOTSUP,
6598 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
6600 "priority out of range");
6601 if (attributes->transfer) {
6602 if (!priv->config.dv_esw_en)
6603 return rte_flow_error_set
6605 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6606 "E-Switch dr is not supported");
6607 if (!(priv->representor || priv->master))
6608 return rte_flow_error_set
6609 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6610 NULL, "E-Switch configuration can only be"
6611 " done by a master or a representor device");
6612 if (attributes->egress)
6613 return rte_flow_error_set
6615 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
6616 "egress is not supported");
6618 if (!(attributes->egress ^ attributes->ingress))
6619 return rte_flow_error_set(error, ENOTSUP,
6620 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6621 "must specify exactly one of "
6622 "ingress or egress");
6627 validate_integrity_bits(const struct rte_flow_item_integrity *mask,
6628 int64_t pattern_flags, uint64_t l3_flags,
6629 uint64_t l4_flags, uint64_t ip4_flag,
6630 struct rte_flow_error *error)
6632 if (mask->l3_ok && !(pattern_flags & l3_flags))
6633 return rte_flow_error_set(error, EINVAL,
6634 RTE_FLOW_ERROR_TYPE_ITEM,
6635 NULL, "missing L3 protocol");
6637 if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
6638 return rte_flow_error_set(error, EINVAL,
6639 RTE_FLOW_ERROR_TYPE_ITEM,
6640 NULL, "missing IPv4 protocol");
6642 if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
6643 return rte_flow_error_set(error, EINVAL,
6644 RTE_FLOW_ERROR_TYPE_ITEM,
6645 NULL, "missing L4 protocol");
6651 flow_dv_validate_item_integrity_post(const struct
6652 rte_flow_item *integrity_items[2],
6653 int64_t pattern_flags,
6654 struct rte_flow_error *error)
6656 const struct rte_flow_item_integrity *mask;
6659 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
6660 mask = (typeof(mask))integrity_items[0]->mask;
6661 ret = validate_integrity_bits(mask, pattern_flags,
6662 MLX5_FLOW_LAYER_OUTER_L3,
6663 MLX5_FLOW_LAYER_OUTER_L4,
6664 MLX5_FLOW_LAYER_OUTER_L3_IPV4,
6669 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
6670 mask = (typeof(mask))integrity_items[1]->mask;
6671 ret = validate_integrity_bits(mask, pattern_flags,
6672 MLX5_FLOW_LAYER_INNER_L3,
6673 MLX5_FLOW_LAYER_INNER_L4,
6674 MLX5_FLOW_LAYER_INNER_L3_IPV4,
6683 flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
6684 const struct rte_flow_item *integrity_item,
6685 uint64_t pattern_flags, uint64_t *last_item,
6686 const struct rte_flow_item *integrity_items[2],
6687 struct rte_flow_error *error)
6689 struct mlx5_priv *priv = dev->data->dev_private;
6690 const struct rte_flow_item_integrity *mask = (typeof(mask))
6691 integrity_item->mask;
6692 const struct rte_flow_item_integrity *spec = (typeof(spec))
6693 integrity_item->spec;
6695 if (!priv->config.hca_attr.pkt_integrity_match)
6696 return rte_flow_error_set(error, ENOTSUP,
6697 RTE_FLOW_ERROR_TYPE_ITEM,
6699 "packet integrity integrity_item not supported");
6701 return rte_flow_error_set(error, ENOTSUP,
6702 RTE_FLOW_ERROR_TYPE_ITEM,
6704 "no spec for integrity item");
6706 mask = &rte_flow_item_integrity_mask;
6707 if (!mlx5_validate_integrity_item(mask))
6708 return rte_flow_error_set(error, ENOTSUP,
6709 RTE_FLOW_ERROR_TYPE_ITEM,
6711 "unsupported integrity filter");
6712 if (spec->level > 1) {
6713 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
6714 return rte_flow_error_set
6716 RTE_FLOW_ERROR_TYPE_ITEM,
6717 NULL, "multiple inner integrity items not supported");
6718 integrity_items[1] = integrity_item;
6719 *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
6721 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
6722 return rte_flow_error_set
6724 RTE_FLOW_ERROR_TYPE_ITEM,
6725 NULL, "multiple outer integrity items not supported");
6726 integrity_items[0] = integrity_item;
6727 *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
6733 flow_dv_validate_item_flex(struct rte_eth_dev *dev,
6734 const struct rte_flow_item *item,
6735 uint64_t item_flags,
6736 uint64_t *last_item,
6738 struct rte_flow_error *error)
6740 const struct rte_flow_item_flex *flow_spec = item->spec;
6741 const struct rte_flow_item_flex *flow_mask = item->mask;
6742 struct mlx5_flex_item *flex;
6745 return rte_flow_error_set(error, EINVAL,
6746 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6747 "flex flow item spec cannot be NULL");
6749 return rte_flow_error_set(error, EINVAL,
6750 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6751 "flex flow item mask cannot be NULL");
6753 return rte_flow_error_set(error, ENOTSUP,
6754 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6755 "flex flow item last not supported");
6756 if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
6757 return rte_flow_error_set(error, EINVAL,
6758 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6759 "invalid flex flow item handle");
6760 flex = (struct mlx5_flex_item *)flow_spec->handle;
6761 switch (flex->tunnel_mode) {
6762 case FLEX_TUNNEL_MODE_SINGLE:
6764 (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
6765 rte_flow_error_set(error, EINVAL,
6766 RTE_FLOW_ERROR_TYPE_ITEM,
6767 NULL, "multiple flex items not supported");
6769 case FLEX_TUNNEL_MODE_OUTER:
6771 rte_flow_error_set(error, EINVAL,
6772 RTE_FLOW_ERROR_TYPE_ITEM,
6773 NULL, "inner flex item was not configured");
6774 if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
6775 rte_flow_error_set(error, ENOTSUP,
6776 RTE_FLOW_ERROR_TYPE_ITEM,
6777 NULL, "multiple flex items not supported");
6779 case FLEX_TUNNEL_MODE_INNER:
6781 rte_flow_error_set(error, EINVAL,
6782 RTE_FLOW_ERROR_TYPE_ITEM,
6783 NULL, "outer flex item was not configured");
6784 if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
6785 rte_flow_error_set(error, EINVAL,
6786 RTE_FLOW_ERROR_TYPE_ITEM,
6787 NULL, "multiple flex items not supported");
6789 case FLEX_TUNNEL_MODE_MULTI:
6790 if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
6791 (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
6792 rte_flow_error_set(error, EINVAL,
6793 RTE_FLOW_ERROR_TYPE_ITEM,
6794 NULL, "multiple flex items not supported");
6797 case FLEX_TUNNEL_MODE_TUNNEL:
6798 if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
6799 rte_flow_error_set(error, EINVAL,
6800 RTE_FLOW_ERROR_TYPE_ITEM,
6801 NULL, "multiple flex tunnel items not supported");
6804 rte_flow_error_set(error, EINVAL,
6805 RTE_FLOW_ERROR_TYPE_ITEM,
6806 NULL, "invalid flex item configuration");
6808 *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
6809 MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
6810 MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
6815 * Internal validation function. For validating both actions and items.
6818 * Pointer to the rte_eth_dev structure.
6820 * Pointer to the flow attributes.
6822 * Pointer to the list of items.
6823 * @param[in] actions
6824 * Pointer to the list of actions.
6825 * @param[in] external
6826 * This flow rule is created by request external to PMD.
6827 * @param[in] hairpin
6828 * Number of hairpin TX actions, 0 means classic flow.
6830 * Pointer to the error structure.
6833 * 0 on success, a negative errno value otherwise and rte_errno is set.
6836 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
6837 const struct rte_flow_item items[],
6838 const struct rte_flow_action actions[],
6839 bool external, int hairpin, struct rte_flow_error *error)
6842 uint64_t action_flags = 0;
6843 uint64_t item_flags = 0;
6844 uint64_t last_item = 0;
6845 uint8_t next_protocol = 0xff;
6846 uint16_t ether_type = 0;
6848 uint8_t item_ipv6_proto = 0;
6849 int fdb_mirror_limit = 0;
6850 int modify_after_mirror = 0;
6851 const struct rte_flow_item *geneve_item = NULL;
6852 const struct rte_flow_item *gre_item = NULL;
6853 const struct rte_flow_item *gtp_item = NULL;
6854 const struct rte_flow_action_raw_decap *decap;
6855 const struct rte_flow_action_raw_encap *encap;
6856 const struct rte_flow_action_rss *rss = NULL;
6857 const struct rte_flow_action_rss *sample_rss = NULL;
6858 const struct rte_flow_action_count *sample_count = NULL;
6859 const struct rte_flow_item_tcp nic_tcp_mask = {
6862 .src_port = RTE_BE16(UINT16_MAX),
6863 .dst_port = RTE_BE16(UINT16_MAX),
6866 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
6869 "\xff\xff\xff\xff\xff\xff\xff\xff"
6870 "\xff\xff\xff\xff\xff\xff\xff\xff",
6872 "\xff\xff\xff\xff\xff\xff\xff\xff"
6873 "\xff\xff\xff\xff\xff\xff\xff\xff",
6874 .vtc_flow = RTE_BE32(0xffffffff),
6880 const struct rte_flow_item_ecpri nic_ecpri_mask = {
6884 RTE_BE32(((const struct rte_ecpri_common_hdr) {
6888 .dummy[0] = 0xffffffff,
6891 struct mlx5_priv *priv = dev->data->dev_private;
6892 struct mlx5_dev_config *dev_conf = &priv->config;
6893 uint16_t queue_index = 0xFFFF;
6894 const struct rte_flow_item_vlan *vlan_m = NULL;
6895 uint32_t rw_act_num = 0;
6897 const struct mlx5_flow_tunnel *tunnel;
6898 enum mlx5_tof_rule_type tof_rule_type;
6899 struct flow_grp_info grp_info = {
6900 .external = !!external,
6901 .transfer = !!attr->transfer,
6902 .fdb_def_rule = !!priv->fdb_def_rule,
6903 .std_tbl_fix = true,
6905 const struct rte_eth_hairpin_conf *conf;
6906 const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
6907 const struct rte_flow_item *port_id_item = NULL;
6908 bool def_policy = false;
6909 uint16_t udp_dport = 0;
6913 tunnel = is_tunnel_offload_active(dev) ?
6914 mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
6916 if (!priv->config.dv_flow_en)
6917 return rte_flow_error_set
6919 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6920 NULL, "tunnel offload requires DV flow interface");
6921 if (priv->representor)
6922 return rte_flow_error_set
6924 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6925 NULL, "decap not supported for VF representor");
6926 if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
6927 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6928 else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
6929 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
6930 MLX5_FLOW_ACTION_DECAP;
6931 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
6932 (dev, attr, tunnel, tof_rule_type);
6934 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
6937 is_root = (uint64_t)ret;
6938 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6939 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
6940 int type = items->type;
6942 if (!mlx5_flow_os_item_supported(type))
6943 return rte_flow_error_set(error, ENOTSUP,
6944 RTE_FLOW_ERROR_TYPE_ITEM,
6945 NULL, "item not supported");
6947 case RTE_FLOW_ITEM_TYPE_VOID:
6949 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6950 ret = flow_dv_validate_item_port_id
6951 (dev, items, attr, item_flags, error);
6954 last_item = MLX5_FLOW_ITEM_PORT_ID;
6955 port_id_item = items;
6957 case RTE_FLOW_ITEM_TYPE_ETH:
6958 ret = mlx5_flow_validate_item_eth(items, item_flags,
6962 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
6963 MLX5_FLOW_LAYER_OUTER_L2;
6964 if (items->mask != NULL && items->spec != NULL) {
6966 ((const struct rte_flow_item_eth *)
6969 ((const struct rte_flow_item_eth *)
6971 ether_type = rte_be_to_cpu_16(ether_type);
6976 case RTE_FLOW_ITEM_TYPE_VLAN:
6977 ret = flow_dv_validate_item_vlan(items, item_flags,
6981 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
6982 MLX5_FLOW_LAYER_OUTER_VLAN;
6983 if (items->mask != NULL && items->spec != NULL) {
6985 ((const struct rte_flow_item_vlan *)
6986 items->spec)->inner_type;
6988 ((const struct rte_flow_item_vlan *)
6989 items->mask)->inner_type;
6990 ether_type = rte_be_to_cpu_16(ether_type);
6994 /* Store outer VLAN mask for of_push_vlan action. */
6996 vlan_m = items->mask;
6998 case RTE_FLOW_ITEM_TYPE_IPV4:
6999 mlx5_flow_tunnel_ip_check(items, next_protocol,
7000 &item_flags, &tunnel);
7001 ret = flow_dv_validate_item_ipv4(dev, items, item_flags,
7002 last_item, ether_type,
7006 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7007 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7008 if (items->mask != NULL &&
7009 ((const struct rte_flow_item_ipv4 *)
7010 items->mask)->hdr.next_proto_id) {
7012 ((const struct rte_flow_item_ipv4 *)
7013 (items->spec))->hdr.next_proto_id;
7015 ((const struct rte_flow_item_ipv4 *)
7016 (items->mask))->hdr.next_proto_id;
7018 /* Reset for inner layer. */
7019 next_protocol = 0xff;
7022 case RTE_FLOW_ITEM_TYPE_IPV6:
7023 mlx5_flow_tunnel_ip_check(items, next_protocol,
7024 &item_flags, &tunnel);
7025 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
7032 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7033 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7034 if (items->mask != NULL &&
7035 ((const struct rte_flow_item_ipv6 *)
7036 items->mask)->hdr.proto) {
7038 ((const struct rte_flow_item_ipv6 *)
7039 items->spec)->hdr.proto;
7041 ((const struct rte_flow_item_ipv6 *)
7042 items->spec)->hdr.proto;
7044 ((const struct rte_flow_item_ipv6 *)
7045 items->mask)->hdr.proto;
7047 /* Reset for inner layer. */
7048 next_protocol = 0xff;
7051 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7052 ret = flow_dv_validate_item_ipv6_frag_ext(items,
7057 last_item = tunnel ?
7058 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
7059 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
7060 if (items->mask != NULL &&
7061 ((const struct rte_flow_item_ipv6_frag_ext *)
7062 items->mask)->hdr.next_header) {
7064 ((const struct rte_flow_item_ipv6_frag_ext *)
7065 items->spec)->hdr.next_header;
7067 ((const struct rte_flow_item_ipv6_frag_ext *)
7068 items->mask)->hdr.next_header;
7070 /* Reset for inner layer. */
7071 next_protocol = 0xff;
7074 case RTE_FLOW_ITEM_TYPE_TCP:
7075 ret = mlx5_flow_validate_item_tcp
7082 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7083 MLX5_FLOW_LAYER_OUTER_L4_TCP;
7085 case RTE_FLOW_ITEM_TYPE_UDP:
7086 ret = mlx5_flow_validate_item_udp(items, item_flags,
7089 const struct rte_flow_item_udp *spec = items->spec;
7090 const struct rte_flow_item_udp *mask = items->mask;
7092 mask = &rte_flow_item_udp_mask;
7094 udp_dport = rte_be_to_cpu_16
7095 (spec->hdr.dst_port &
7096 mask->hdr.dst_port);
7099 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
7100 MLX5_FLOW_LAYER_OUTER_L4_UDP;
7102 case RTE_FLOW_ITEM_TYPE_GRE:
7103 ret = mlx5_flow_validate_item_gre(items, item_flags,
7104 next_protocol, error);
7108 last_item = MLX5_FLOW_LAYER_GRE;
7110 case RTE_FLOW_ITEM_TYPE_NVGRE:
7111 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
7116 last_item = MLX5_FLOW_LAYER_NVGRE;
7118 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7119 ret = mlx5_flow_validate_item_gre_key
7120 (items, item_flags, gre_item, error);
7123 last_item = MLX5_FLOW_LAYER_GRE_KEY;
7125 case RTE_FLOW_ITEM_TYPE_VXLAN:
7126 ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
7131 last_item = MLX5_FLOW_LAYER_VXLAN;
7133 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7134 ret = mlx5_flow_validate_item_vxlan_gpe(items,
7139 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
7141 case RTE_FLOW_ITEM_TYPE_GENEVE:
7142 ret = mlx5_flow_validate_item_geneve(items,
7147 geneve_item = items;
7148 last_item = MLX5_FLOW_LAYER_GENEVE;
7150 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
7151 ret = mlx5_flow_validate_item_geneve_opt(items,
7158 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
7160 case RTE_FLOW_ITEM_TYPE_MPLS:
7161 ret = mlx5_flow_validate_item_mpls(dev, items,
7166 last_item = MLX5_FLOW_LAYER_MPLS;
7169 case RTE_FLOW_ITEM_TYPE_MARK:
7170 ret = flow_dv_validate_item_mark(dev, items, attr,
7174 last_item = MLX5_FLOW_ITEM_MARK;
7176 case RTE_FLOW_ITEM_TYPE_META:
7177 ret = flow_dv_validate_item_meta(dev, items, attr,
7181 last_item = MLX5_FLOW_ITEM_METADATA;
7183 case RTE_FLOW_ITEM_TYPE_ICMP:
7184 ret = mlx5_flow_validate_item_icmp(items, item_flags,
7189 last_item = MLX5_FLOW_LAYER_ICMP;
7191 case RTE_FLOW_ITEM_TYPE_ICMP6:
7192 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
7197 item_ipv6_proto = IPPROTO_ICMPV6;
7198 last_item = MLX5_FLOW_LAYER_ICMP6;
7200 case RTE_FLOW_ITEM_TYPE_TAG:
7201 ret = flow_dv_validate_item_tag(dev, items,
7205 last_item = MLX5_FLOW_ITEM_TAG;
7207 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7208 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
7210 case RTE_FLOW_ITEM_TYPE_GTP:
7211 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
7216 last_item = MLX5_FLOW_LAYER_GTP;
7218 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
7219 ret = flow_dv_validate_item_gtp_psc(items, last_item,
7224 last_item = MLX5_FLOW_LAYER_GTP_PSC;
7226 case RTE_FLOW_ITEM_TYPE_ECPRI:
7227 /* Capacity will be checked in the translate stage. */
7228 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
7235 last_item = MLX5_FLOW_LAYER_ECPRI;
7237 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
7238 ret = flow_dv_validate_item_integrity(dev, items,
7246 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
7247 ret = flow_dv_validate_item_aso_ct(dev, items,
7248 &item_flags, error);
7252 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
7253 /* tunnel offload item was processed before
7254 * list it here as a supported type
7257 case RTE_FLOW_ITEM_TYPE_FLEX:
7258 ret = flow_dv_validate_item_flex(dev, items, item_flags,
7260 tunnel != 0, error);
7265 return rte_flow_error_set(error, ENOTSUP,
7266 RTE_FLOW_ERROR_TYPE_ITEM,
7267 NULL, "item not supported");
7269 item_flags |= last_item;
7271 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
7272 ret = flow_dv_validate_item_integrity_post(integrity_items,
7277 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
7278 int type = actions->type;
7279 bool shared_count = false;
7281 if (!mlx5_flow_os_action_supported(type))
7282 return rte_flow_error_set(error, ENOTSUP,
7283 RTE_FLOW_ERROR_TYPE_ACTION,
7285 "action not supported");
7286 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
7287 return rte_flow_error_set(error, ENOTSUP,
7288 RTE_FLOW_ERROR_TYPE_ACTION,
7289 actions, "too many actions");
7291 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
7292 return rte_flow_error_set(error, ENOTSUP,
7293 RTE_FLOW_ERROR_TYPE_ACTION,
7294 NULL, "meter action with policy "
7295 "must be the last action");
7297 case RTE_FLOW_ACTION_TYPE_VOID:
7299 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7300 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
7301 ret = flow_dv_validate_action_port_id(dev,
7308 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7311 case RTE_FLOW_ACTION_TYPE_FLAG:
7312 ret = flow_dv_validate_action_flag(dev, action_flags,
7316 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7317 /* Count all modify-header actions as one. */
7318 if (!(action_flags &
7319 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7321 action_flags |= MLX5_FLOW_ACTION_FLAG |
7322 MLX5_FLOW_ACTION_MARK_EXT;
7323 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7324 modify_after_mirror = 1;
7327 action_flags |= MLX5_FLOW_ACTION_FLAG;
7330 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7332 case RTE_FLOW_ACTION_TYPE_MARK:
7333 ret = flow_dv_validate_action_mark(dev, actions,
7338 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7339 /* Count all modify-header actions as one. */
7340 if (!(action_flags &
7341 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7343 action_flags |= MLX5_FLOW_ACTION_MARK |
7344 MLX5_FLOW_ACTION_MARK_EXT;
7345 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7346 modify_after_mirror = 1;
7348 action_flags |= MLX5_FLOW_ACTION_MARK;
7351 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7353 case RTE_FLOW_ACTION_TYPE_SET_META:
7354 ret = flow_dv_validate_action_set_meta(dev, actions,
7359 /* Count all modify-header actions as one action. */
7360 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7362 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7363 modify_after_mirror = 1;
7364 action_flags |= MLX5_FLOW_ACTION_SET_META;
7365 rw_act_num += MLX5_ACT_NUM_SET_META;
7367 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7368 ret = flow_dv_validate_action_set_tag(dev, actions,
7373 /* Count all modify-header actions as one action. */
7374 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7376 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7377 modify_after_mirror = 1;
7378 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7379 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7381 case RTE_FLOW_ACTION_TYPE_DROP:
7382 ret = mlx5_flow_validate_action_drop(action_flags,
7386 action_flags |= MLX5_FLOW_ACTION_DROP;
7389 case RTE_FLOW_ACTION_TYPE_QUEUE:
7390 ret = mlx5_flow_validate_action_queue(actions,
7395 queue_index = ((const struct rte_flow_action_queue *)
7396 (actions->conf))->index;
7397 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7400 case RTE_FLOW_ACTION_TYPE_RSS:
7401 rss = actions->conf;
7402 ret = mlx5_flow_validate_action_rss(actions,
7408 if (rss && sample_rss &&
7409 (sample_rss->level != rss->level ||
7410 sample_rss->types != rss->types))
7411 return rte_flow_error_set(error, ENOTSUP,
7412 RTE_FLOW_ERROR_TYPE_ACTION,
7414 "Can't use the different RSS types "
7415 "or level in the same flow");
7416 if (rss != NULL && rss->queue_num)
7417 queue_index = rss->queue[0];
7418 action_flags |= MLX5_FLOW_ACTION_RSS;
7421 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7423 mlx5_flow_validate_action_default_miss(action_flags,
7427 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
7430 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
7431 shared_count = true;
7433 case RTE_FLOW_ACTION_TYPE_COUNT:
7434 ret = flow_dv_validate_action_count(dev, shared_count,
7439 action_flags |= MLX5_FLOW_ACTION_COUNT;
7442 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7443 if (flow_dv_validate_action_pop_vlan(dev,
7449 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7450 modify_after_mirror = 1;
7451 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7454 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7455 ret = flow_dv_validate_action_push_vlan(dev,
7462 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7463 modify_after_mirror = 1;
7464 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7467 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7468 ret = flow_dv_validate_action_set_vlan_pcp
7469 (action_flags, actions, error);
7472 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7473 modify_after_mirror = 1;
7474 /* Count PCP with push_vlan command. */
7475 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
7477 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7478 ret = flow_dv_validate_action_set_vlan_vid
7479 (item_flags, action_flags,
7483 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7484 modify_after_mirror = 1;
7485 /* Count VID with push_vlan command. */
7486 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7487 rw_act_num += MLX5_ACT_NUM_MDF_VID;
7489 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7490 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7491 ret = flow_dv_validate_action_l2_encap(dev,
7497 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7500 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7501 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7502 ret = flow_dv_validate_action_decap(dev, action_flags,
7503 actions, item_flags,
7507 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7508 modify_after_mirror = 1;
7509 action_flags |= MLX5_FLOW_ACTION_DECAP;
7512 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7513 ret = flow_dv_validate_action_raw_encap_decap
7514 (dev, NULL, actions->conf, attr, &action_flags,
7515 &actions_n, actions, item_flags, error);
7519 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7520 decap = actions->conf;
7521 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
7523 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7527 encap = actions->conf;
7529 ret = flow_dv_validate_action_raw_encap_decap
7531 decap ? decap : &empty_decap, encap,
7532 attr, &action_flags, &actions_n,
7533 actions, item_flags, error);
7536 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7537 (action_flags & MLX5_FLOW_ACTION_DECAP))
7538 modify_after_mirror = 1;
7540 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7541 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7542 ret = flow_dv_validate_action_modify_mac(action_flags,
7548 /* Count all modify-header actions as one action. */
7549 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7551 action_flags |= actions->type ==
7552 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7553 MLX5_FLOW_ACTION_SET_MAC_SRC :
7554 MLX5_FLOW_ACTION_SET_MAC_DST;
7555 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7556 modify_after_mirror = 1;
7558 * Even if the source and destination MAC addresses have
7559 * overlap in the header with 4B alignment, the convert
7560 * function will handle them separately and 4 SW actions
7561 * will be created. And 2 actions will be added each
7562 * time no matter how many bytes of address will be set.
7564 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
7566 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7567 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7568 ret = flow_dv_validate_action_modify_ipv4(action_flags,
7574 /* Count all modify-header actions as one action. */
7575 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7577 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7578 modify_after_mirror = 1;
7579 action_flags |= actions->type ==
7580 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7581 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7582 MLX5_FLOW_ACTION_SET_IPV4_DST;
7583 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
7585 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7586 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7587 ret = flow_dv_validate_action_modify_ipv6(action_flags,
7593 if (item_ipv6_proto == IPPROTO_ICMPV6)
7594 return rte_flow_error_set(error, ENOTSUP,
7595 RTE_FLOW_ERROR_TYPE_ACTION,
7597 "Can't change header "
7598 "with ICMPv6 proto");
7599 /* Count all modify-header actions as one action. */
7600 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7602 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7603 modify_after_mirror = 1;
7604 action_flags |= actions->type ==
7605 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7606 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7607 MLX5_FLOW_ACTION_SET_IPV6_DST;
7608 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
7610 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7611 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7612 ret = flow_dv_validate_action_modify_tp(action_flags,
7618 /* Count all modify-header actions as one action. */
7619 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7621 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7622 modify_after_mirror = 1;
7623 action_flags |= actions->type ==
7624 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7625 MLX5_FLOW_ACTION_SET_TP_SRC :
7626 MLX5_FLOW_ACTION_SET_TP_DST;
7627 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
7629 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7630 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7631 ret = flow_dv_validate_action_modify_ttl(action_flags,
7637 /* Count all modify-header actions as one action. */
7638 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7640 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7641 modify_after_mirror = 1;
7642 action_flags |= actions->type ==
7643 RTE_FLOW_ACTION_TYPE_SET_TTL ?
7644 MLX5_FLOW_ACTION_SET_TTL :
7645 MLX5_FLOW_ACTION_DEC_TTL;
7646 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
7648 case RTE_FLOW_ACTION_TYPE_JUMP:
7649 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
7655 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7657 return rte_flow_error_set(error, EINVAL,
7658 RTE_FLOW_ERROR_TYPE_ACTION,
7660 "sample and jump action combination is not supported");
7662 action_flags |= MLX5_FLOW_ACTION_JUMP;
7664 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7665 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7666 ret = flow_dv_validate_action_modify_tcp_seq
7673 /* Count all modify-header actions as one action. */
7674 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7676 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7677 modify_after_mirror = 1;
7678 action_flags |= actions->type ==
7679 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7680 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7681 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7682 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
7684 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7685 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7686 ret = flow_dv_validate_action_modify_tcp_ack
7693 /* Count all modify-header actions as one action. */
7694 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7696 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7697 modify_after_mirror = 1;
7698 action_flags |= actions->type ==
7699 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7700 MLX5_FLOW_ACTION_INC_TCP_ACK :
7701 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7702 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
7704 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7706 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7707 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7708 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7710 case RTE_FLOW_ACTION_TYPE_METER:
7711 ret = mlx5_flow_validate_action_meter(dev,
7720 action_flags |= MLX5_FLOW_ACTION_METER;
7723 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
7725 /* Meter action will add one more TAG action. */
7726 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7728 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
7729 if (!attr->transfer && !attr->group)
7730 return rte_flow_error_set(error, ENOTSUP,
7731 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7733 "Shared ASO age action is not supported for group 0");
7734 if (action_flags & MLX5_FLOW_ACTION_AGE)
7735 return rte_flow_error_set
7737 RTE_FLOW_ERROR_TYPE_ACTION,
7739 "duplicate age actions set");
7740 action_flags |= MLX5_FLOW_ACTION_AGE;
7743 case RTE_FLOW_ACTION_TYPE_AGE:
7744 ret = flow_dv_validate_action_age(action_flags,
7750 * Validate the regular AGE action (using counter)
7751 * mutual exclusion with share counter actions.
7753 if (!priv->sh->flow_hit_aso_en) {
7755 return rte_flow_error_set
7757 RTE_FLOW_ERROR_TYPE_ACTION,
7759 "old age and shared count combination is not supported");
7761 return rte_flow_error_set
7763 RTE_FLOW_ERROR_TYPE_ACTION,
7765 "old age action and count must be in the same sub flow");
7767 action_flags |= MLX5_FLOW_ACTION_AGE;
7770 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7771 ret = flow_dv_validate_action_modify_ipv4_dscp
7778 /* Count all modify-header actions as one action. */
7779 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7781 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7782 modify_after_mirror = 1;
7783 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7784 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7786 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7787 ret = flow_dv_validate_action_modify_ipv6_dscp
7794 /* Count all modify-header actions as one action. */
7795 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7797 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7798 modify_after_mirror = 1;
7799 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7800 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7802 case RTE_FLOW_ACTION_TYPE_SAMPLE:
7803 ret = flow_dv_validate_action_sample(&action_flags,
7812 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
7815 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7816 ret = flow_dv_validate_action_modify_field(dev,
7823 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7824 modify_after_mirror = 1;
7825 /* Count all modify-header actions as one action. */
7826 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7828 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
7831 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7832 ret = flow_dv_validate_action_aso_ct(dev, action_flags,
7837 action_flags |= MLX5_FLOW_ACTION_CT;
7839 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
7840 /* tunnel offload action was processed before
7841 * list it here as a supported type
7845 return rte_flow_error_set(error, ENOTSUP,
7846 RTE_FLOW_ERROR_TYPE_ACTION,
7848 "action not supported");
7852 * Validate actions in flow rules
7853 * - Explicit decap action is prohibited by the tunnel offload API.
7854 * - Drop action in tunnel steer rule is prohibited by the API.
7855 * - Application cannot use MARK action because it's value can mask
7856 * tunnel default miss notification.
7857 * - JUMP in tunnel match rule has no support in current PMD
7859 * - TAG & META are reserved for future uses.
7861 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
7862 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
7863 MLX5_FLOW_ACTION_MARK |
7864 MLX5_FLOW_ACTION_SET_TAG |
7865 MLX5_FLOW_ACTION_SET_META |
7866 MLX5_FLOW_ACTION_DROP;
7868 if (action_flags & bad_actions_mask)
7869 return rte_flow_error_set
7871 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7872 "Invalid RTE action in tunnel "
7874 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
7875 return rte_flow_error_set
7877 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7878 "tunnel set decap rule must terminate "
7881 return rte_flow_error_set
7883 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7884 "tunnel flows for ingress traffic only");
7886 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
7887 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
7888 MLX5_FLOW_ACTION_MARK |
7889 MLX5_FLOW_ACTION_SET_TAG |
7890 MLX5_FLOW_ACTION_SET_META;
7892 if (action_flags & bad_actions_mask)
7893 return rte_flow_error_set
7895 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7896 "Invalid RTE action in tunnel "
7900 * Validate the drop action mutual exclusion with other actions.
7901 * Drop action is mutually-exclusive with any other action, except for
7903 * Drop action compatibility with tunnel offload was already validated.
7905 if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
7906 MLX5_FLOW_ACTION_TUNNEL_MATCH));
7907 else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
7908 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
7909 return rte_flow_error_set(error, EINVAL,
7910 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7911 "Drop action is mutually-exclusive "
7912 "with any other action, except for "
7914 /* Eswitch has few restrictions on using items and actions */
7915 if (attr->transfer) {
7916 if (!mlx5_flow_ext_mreg_supported(dev) &&
7917 action_flags & MLX5_FLOW_ACTION_FLAG)
7918 return rte_flow_error_set(error, ENOTSUP,
7919 RTE_FLOW_ERROR_TYPE_ACTION,
7921 "unsupported action FLAG");
7922 if (!mlx5_flow_ext_mreg_supported(dev) &&
7923 action_flags & MLX5_FLOW_ACTION_MARK)
7924 return rte_flow_error_set(error, ENOTSUP,
7925 RTE_FLOW_ERROR_TYPE_ACTION,
7927 "unsupported action MARK");
7928 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
7929 return rte_flow_error_set(error, ENOTSUP,
7930 RTE_FLOW_ERROR_TYPE_ACTION,
7932 "unsupported action QUEUE");
7933 if (action_flags & MLX5_FLOW_ACTION_RSS)
7934 return rte_flow_error_set(error, ENOTSUP,
7935 RTE_FLOW_ERROR_TYPE_ACTION,
7937 "unsupported action RSS");
7938 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
7939 return rte_flow_error_set(error, EINVAL,
7940 RTE_FLOW_ERROR_TYPE_ACTION,
7942 "no fate action is found");
7944 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
7945 return rte_flow_error_set(error, EINVAL,
7946 RTE_FLOW_ERROR_TYPE_ACTION,
7948 "no fate action is found");
7951 * Continue validation for Xcap and VLAN actions.
7952 * If hairpin is working in explicit TX rule mode, there is no actions
7953 * splitting and the validation of hairpin ingress flow should be the
7954 * same as other standard flows.
7956 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
7957 MLX5_FLOW_VLAN_ACTIONS)) &&
7958 (queue_index == 0xFFFF ||
7959 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN ||
7960 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
7961 conf->tx_explicit != 0))) {
7962 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
7963 MLX5_FLOW_XCAP_ACTIONS)
7964 return rte_flow_error_set(error, ENOTSUP,
7965 RTE_FLOW_ERROR_TYPE_ACTION,
7966 NULL, "encap and decap "
7967 "combination aren't supported");
7968 if (!attr->transfer && attr->ingress) {
7969 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7970 return rte_flow_error_set
7972 RTE_FLOW_ERROR_TYPE_ACTION,
7973 NULL, "encap is not supported"
7974 " for ingress traffic");
7975 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7976 return rte_flow_error_set
7978 RTE_FLOW_ERROR_TYPE_ACTION,
7979 NULL, "push VLAN action not "
7980 "supported for ingress");
7981 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
7982 MLX5_FLOW_VLAN_ACTIONS)
7983 return rte_flow_error_set
7985 RTE_FLOW_ERROR_TYPE_ACTION,
7986 NULL, "no support for "
7987 "multiple VLAN actions");
7990 if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
7991 if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
7992 ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
7994 return rte_flow_error_set
7996 RTE_FLOW_ERROR_TYPE_ACTION,
7997 NULL, "fate action not supported for "
7998 "meter with policy");
8000 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
8001 return rte_flow_error_set
8003 RTE_FLOW_ERROR_TYPE_ACTION,
8004 NULL, "modify header action in egress "
8005 "cannot be done before meter action");
8006 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
8007 return rte_flow_error_set
8009 RTE_FLOW_ERROR_TYPE_ACTION,
8010 NULL, "encap action in egress "
8011 "cannot be done before meter action");
8012 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
8013 return rte_flow_error_set
8015 RTE_FLOW_ERROR_TYPE_ACTION,
8016 NULL, "push vlan action in egress "
8017 "cannot be done before meter action");
8021 * Hairpin flow will add one more TAG action in TX implicit mode.
8022 * In TX explicit mode, there will be no hairpin flow ID.
8025 rw_act_num += MLX5_ACT_NUM_SET_TAG;
8026 /* extra metadata enabled: one more TAG action will be add. */
8027 if (dev_conf->dv_flow_en &&
8028 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
8029 mlx5_flow_ext_mreg_supported(dev))
8030 rw_act_num += MLX5_ACT_NUM_SET_TAG;
8032 flow_dv_modify_hdr_action_max(dev, is_root)) {
8033 return rte_flow_error_set(error, ENOTSUP,
8034 RTE_FLOW_ERROR_TYPE_ACTION,
8035 NULL, "too many header modify"
8036 " actions to support");
8038 /* Eswitch egress mirror and modify flow has limitation on CX5 */
8039 if (fdb_mirror_limit && modify_after_mirror)
8040 return rte_flow_error_set(error, EINVAL,
8041 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8042 "sample before modify action is not supported");
8047 * Internal preparation function. Allocates the DV flow size,
8048 * this size is constant.
8051 * Pointer to the rte_eth_dev structure.
8053 * Pointer to the flow attributes.
8055 * Pointer to the list of items.
8056 * @param[in] actions
8057 * Pointer to the list of actions.
8059 * Pointer to the error structure.
8062 * Pointer to mlx5_flow object on success,
8063 * otherwise NULL and rte_errno is set.
8065 static struct mlx5_flow *
8066 flow_dv_prepare(struct rte_eth_dev *dev,
8067 const struct rte_flow_attr *attr __rte_unused,
8068 const struct rte_flow_item items[] __rte_unused,
8069 const struct rte_flow_action actions[] __rte_unused,
8070 struct rte_flow_error *error)
8072 uint32_t handle_idx = 0;
8073 struct mlx5_flow *dev_flow;
8074 struct mlx5_flow_handle *dev_handle;
8075 struct mlx5_priv *priv = dev->data->dev_private;
8076 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
8079 wks->skip_matcher_reg = 0;
8081 wks->final_policy = NULL;
8082 /* In case of corrupting the memory. */
8083 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
8084 rte_flow_error_set(error, ENOSPC,
8085 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8086 "not free temporary device flow");
8089 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8092 rte_flow_error_set(error, ENOMEM,
8093 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8094 "not enough memory to create flow handle");
8097 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
8098 dev_flow = &wks->flows[wks->flow_idx++];
8099 memset(dev_flow, 0, sizeof(*dev_flow));
8100 dev_flow->handle = dev_handle;
8101 dev_flow->handle_idx = handle_idx;
8102 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
8103 dev_flow->ingress = attr->ingress;
8104 dev_flow->dv.transfer = attr->transfer;
8108 #ifdef RTE_LIBRTE_MLX5_DEBUG
8110 * Sanity check for match mask and value. Similar to check_valid_spec() in
8111 * kernel driver. If unmasked bit is present in value, it returns failure.
8114 * pointer to match mask buffer.
8115 * @param match_value
8116 * pointer to match value buffer.
8119 * 0 if valid, -EINVAL otherwise.
8122 flow_dv_check_valid_spec(void *match_mask, void *match_value)
8124 uint8_t *m = match_mask;
8125 uint8_t *v = match_value;
8128 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
8131 "match_value differs from match_criteria"
8132 " %p[%u] != %p[%u]",
8133 match_value, i, match_mask, i);
8142 * Add match of ip_version.
8146 * @param[in] headers_v
8147 * Values header pointer.
8148 * @param[in] headers_m
8149 * Masks header pointer.
8150 * @param[in] ip_version
8151 * The IP version to set.
8154 flow_dv_set_match_ip_version(uint32_t group,
8160 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
8162 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
8164 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
8165 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
8166 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
8170 * Add Ethernet item to matcher and to the value.
8172 * @param[in, out] matcher
8174 * @param[in, out] key
8175 * Flow matcher value.
8177 * Flow pattern to translate.
8179 * Item is inner pattern.
8182 flow_dv_translate_item_eth(void *matcher, void *key,
8183 const struct rte_flow_item *item, int inner,
8186 const struct rte_flow_item_eth *eth_m = item->mask;
8187 const struct rte_flow_item_eth *eth_v = item->spec;
8188 const struct rte_flow_item_eth nic_mask = {
8189 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8190 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8191 .type = RTE_BE16(0xffff),
8204 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8206 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8208 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8210 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8212 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
8213 ð_m->dst, sizeof(eth_m->dst));
8214 /* The value must be in the range of the mask. */
8215 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
8216 for (i = 0; i < sizeof(eth_m->dst); ++i)
8217 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
8218 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
8219 ð_m->src, sizeof(eth_m->src));
8220 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
8221 /* The value must be in the range of the mask. */
8222 for (i = 0; i < sizeof(eth_m->dst); ++i)
8223 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
8225 * HW supports match on one Ethertype, the Ethertype following the last
8226 * VLAN tag of the packet (see PRM).
8227 * Set match on ethertype only if ETH header is not followed by VLAN.
8228 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8229 * ethertype, and use ip_version field instead.
8230 * eCPRI over Ether layer will use type value 0xAEFE.
8232 if (eth_m->type == 0xFFFF) {
8233 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
8234 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8235 switch (eth_v->type) {
8236 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8237 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8239 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
8240 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8241 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8243 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8244 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8246 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8247 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8253 if (eth_m->has_vlan) {
8254 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8255 if (eth_v->has_vlan) {
8257 * Here, when also has_more_vlan field in VLAN item is
8258 * not set, only single-tagged packets will be matched.
8260 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8264 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8265 rte_be_to_cpu_16(eth_m->type));
8266 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
8267 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
8271 * Add VLAN item to matcher and to the value.
8273 * @param[in, out] dev_flow
8275 * @param[in, out] matcher
8277 * @param[in, out] key
8278 * Flow matcher value.
8280 * Flow pattern to translate.
8282 * Item is inner pattern.
8285 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
8286 void *matcher, void *key,
8287 const struct rte_flow_item *item,
8288 int inner, uint32_t group)
8290 const struct rte_flow_item_vlan *vlan_m = item->mask;
8291 const struct rte_flow_item_vlan *vlan_v = item->spec;
8298 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8300 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8302 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8304 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8306 * This is workaround, masks are not supported,
8307 * and pre-validated.
8310 dev_flow->handle->vf_vlan.tag =
8311 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
8314 * When VLAN item exists in flow, mark packet as tagged,
8315 * even if TCI is not specified.
8317 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
8318 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8319 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8324 vlan_m = &rte_flow_item_vlan_mask;
8325 tci_m = rte_be_to_cpu_16(vlan_m->tci);
8326 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
8327 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
8328 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
8329 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
8330 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
8331 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
8332 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
8334 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8335 * ethertype, and use ip_version field instead.
8337 if (vlan_m->inner_type == 0xFFFF) {
8338 switch (vlan_v->inner_type) {
8339 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8340 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8341 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8342 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8344 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8345 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8347 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8348 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8354 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
8355 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8356 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8357 /* Only one vlan_tag bit can be set. */
8358 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8361 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8362 rte_be_to_cpu_16(vlan_m->inner_type));
8363 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
8364 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
8368 * Add IPV4 item to matcher and to the value.
8370 * @param[in, out] matcher
8372 * @param[in, out] key
8373 * Flow matcher value.
8375 * Flow pattern to translate.
8377 * Item is inner pattern.
8379 * The group to insert the rule.
8382 flow_dv_translate_item_ipv4(void *matcher, void *key,
8383 const struct rte_flow_item *item,
8384 int inner, uint32_t group)
8386 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
8387 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
8388 const struct rte_flow_item_ipv4 nic_mask = {
8390 .src_addr = RTE_BE32(0xffffffff),
8391 .dst_addr = RTE_BE32(0xffffffff),
8392 .type_of_service = 0xff,
8393 .next_proto_id = 0xff,
8394 .time_to_live = 0xff,
8401 uint8_t tos, ihl_m, ihl_v;
8404 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8406 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8408 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8410 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8412 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
8417 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8418 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8419 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8420 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8421 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
8422 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
8423 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8424 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8425 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8426 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8427 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
8428 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
8429 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
8430 ihl_m = ipv4_m->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8431 ihl_v = ipv4_v->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8432 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_ihl, ihl_m);
8433 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl, ihl_m & ihl_v);
8434 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
8435 ipv4_m->hdr.type_of_service);
8436 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
8437 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
8438 ipv4_m->hdr.type_of_service >> 2);
8439 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
8440 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8441 ipv4_m->hdr.next_proto_id);
8442 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8443 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
8444 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8445 ipv4_m->hdr.time_to_live);
8446 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8447 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
8448 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8449 !!(ipv4_m->hdr.fragment_offset));
8450 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8451 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
8455 * Add IPV6 item to matcher and to the value.
8457 * @param[in, out] matcher
8459 * @param[in, out] key
8460 * Flow matcher value.
8462 * Flow pattern to translate.
8464 * Item is inner pattern.
8466 * The group to insert the rule.
8469 flow_dv_translate_item_ipv6(void *matcher, void *key,
8470 const struct rte_flow_item *item,
8471 int inner, uint32_t group)
8473 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
8474 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
8475 const struct rte_flow_item_ipv6 nic_mask = {
8478 "\xff\xff\xff\xff\xff\xff\xff\xff"
8479 "\xff\xff\xff\xff\xff\xff\xff\xff",
8481 "\xff\xff\xff\xff\xff\xff\xff\xff"
8482 "\xff\xff\xff\xff\xff\xff\xff\xff",
8483 .vtc_flow = RTE_BE32(0xffffffff),
8490 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8491 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8500 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8502 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8504 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8506 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8508 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
8513 size = sizeof(ipv6_m->hdr.dst_addr);
8514 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8515 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8516 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8517 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8518 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
8519 for (i = 0; i < size; ++i)
8520 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
8521 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8522 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8523 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8524 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8525 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
8526 for (i = 0; i < size; ++i)
8527 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
8529 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
8530 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
8531 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
8532 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
8533 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
8534 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
8537 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
8539 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
8542 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
8544 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
8548 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8550 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8551 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
8553 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8554 ipv6_m->hdr.hop_limits);
8555 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8556 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
8557 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8558 !!(ipv6_m->has_frag_ext));
8559 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8560 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
8564 * Add IPV6 fragment extension item to matcher and to the value.
8566 * @param[in, out] matcher
8568 * @param[in, out] key
8569 * Flow matcher value.
8571 * Flow pattern to translate.
8573 * Item is inner pattern.
8576 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
8577 const struct rte_flow_item *item,
8580 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
8581 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
8582 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
8584 .next_header = 0xff,
8585 .frag_data = RTE_BE16(0xffff),
8592 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8594 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8596 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8598 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8600 /* IPv6 fragment extension item exists, so packet is IP fragment. */
8601 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
8602 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
8603 if (!ipv6_frag_ext_v)
8605 if (!ipv6_frag_ext_m)
8606 ipv6_frag_ext_m = &nic_mask;
8607 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8608 ipv6_frag_ext_m->hdr.next_header);
8609 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8610 ipv6_frag_ext_v->hdr.next_header &
8611 ipv6_frag_ext_m->hdr.next_header);
8615 * Add TCP item to matcher and to the value.
8617 * @param[in, out] matcher
8619 * @param[in, out] key
8620 * Flow matcher value.
8622 * Flow pattern to translate.
8624 * Item is inner pattern.
8627 flow_dv_translate_item_tcp(void *matcher, void *key,
8628 const struct rte_flow_item *item,
8631 const struct rte_flow_item_tcp *tcp_m = item->mask;
8632 const struct rte_flow_item_tcp *tcp_v = item->spec;
8637 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8639 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8641 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8643 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8645 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8646 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
8650 tcp_m = &rte_flow_item_tcp_mask;
8651 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
8652 rte_be_to_cpu_16(tcp_m->hdr.src_port));
8653 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
8654 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
8655 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
8656 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
8657 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
8658 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
8659 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
8660 tcp_m->hdr.tcp_flags);
8661 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
8662 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
8666 * Add UDP item to matcher and to the value.
8668 * @param[in, out] matcher
8670 * @param[in, out] key
8671 * Flow matcher value.
8673 * Flow pattern to translate.
8675 * Item is inner pattern.
8678 flow_dv_translate_item_udp(void *matcher, void *key,
8679 const struct rte_flow_item *item,
8682 const struct rte_flow_item_udp *udp_m = item->mask;
8683 const struct rte_flow_item_udp *udp_v = item->spec;
8688 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8690 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8692 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8694 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8696 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8697 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
8701 udp_m = &rte_flow_item_udp_mask;
8702 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
8703 rte_be_to_cpu_16(udp_m->hdr.src_port));
8704 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
8705 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
8706 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
8707 rte_be_to_cpu_16(udp_m->hdr.dst_port));
8708 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8709 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
8713 * Add GRE optional Key item to matcher and to the value.
8715 * @param[in, out] matcher
8717 * @param[in, out] key
8718 * Flow matcher value.
8720 * Flow pattern to translate.
8722 * Item is inner pattern.
8725 flow_dv_translate_item_gre_key(void *matcher, void *key,
8726 const struct rte_flow_item *item)
8728 const rte_be32_t *key_m = item->mask;
8729 const rte_be32_t *key_v = item->spec;
8730 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8731 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8732 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
8734 /* GRE K bit must be on and should already be validated */
8735 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
8736 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
8740 key_m = &gre_key_default_mask;
8741 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
8742 rte_be_to_cpu_32(*key_m) >> 8);
8743 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
8744 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
8745 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
8746 rte_be_to_cpu_32(*key_m) & 0xFF);
8747 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
8748 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
8752 * Add GRE item to matcher and to the value.
8754 * @param[in, out] matcher
8756 * @param[in, out] key
8757 * Flow matcher value.
8759 * Flow pattern to translate.
8760 * @param[in] pattern_flags
8761 * Accumulated pattern flags.
8764 flow_dv_translate_item_gre(void *matcher, void *key,
8765 const struct rte_flow_item *item,
8766 uint64_t pattern_flags)
8768 static const struct rte_flow_item_gre empty_gre = {0,};
8769 const struct rte_flow_item_gre *gre_m = item->mask;
8770 const struct rte_flow_item_gre *gre_v = item->spec;
8771 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
8772 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8773 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8774 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8781 uint16_t s_present:1;
8782 uint16_t k_present:1;
8783 uint16_t rsvd_bit1:1;
8784 uint16_t c_present:1;
8788 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
8789 uint16_t protocol_m, protocol_v;
8791 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8792 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
8798 gre_m = &rte_flow_item_gre_mask;
8800 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
8801 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
8802 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
8803 gre_crks_rsvd0_ver_m.c_present);
8804 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
8805 gre_crks_rsvd0_ver_v.c_present &
8806 gre_crks_rsvd0_ver_m.c_present);
8807 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
8808 gre_crks_rsvd0_ver_m.k_present);
8809 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
8810 gre_crks_rsvd0_ver_v.k_present &
8811 gre_crks_rsvd0_ver_m.k_present);
8812 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
8813 gre_crks_rsvd0_ver_m.s_present);
8814 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
8815 gre_crks_rsvd0_ver_v.s_present &
8816 gre_crks_rsvd0_ver_m.s_present);
8817 protocol_m = rte_be_to_cpu_16(gre_m->protocol);
8818 protocol_v = rte_be_to_cpu_16(gre_v->protocol);
8820 /* Force next protocol to prevent matchers duplication */
8821 protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
8823 protocol_m = 0xFFFF;
8825 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, protocol_m);
8826 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8827 protocol_m & protocol_v);
8831 * Add NVGRE item to matcher and to the value.
8833 * @param[in, out] matcher
8835 * @param[in, out] key
8836 * Flow matcher value.
8838 * Flow pattern to translate.
8839 * @param[in] pattern_flags
8840 * Accumulated pattern flags.
8843 flow_dv_translate_item_nvgre(void *matcher, void *key,
8844 const struct rte_flow_item *item,
8845 unsigned long pattern_flags)
8847 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
8848 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
8849 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8850 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8851 const char *tni_flow_id_m;
8852 const char *tni_flow_id_v;
8858 /* For NVGRE, GRE header fields must be set with defined values. */
8859 const struct rte_flow_item_gre gre_spec = {
8860 .c_rsvd0_ver = RTE_BE16(0x2000),
8861 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
8863 const struct rte_flow_item_gre gre_mask = {
8864 .c_rsvd0_ver = RTE_BE16(0xB000),
8865 .protocol = RTE_BE16(UINT16_MAX),
8867 const struct rte_flow_item gre_item = {
8872 flow_dv_translate_item_gre(matcher, key, &gre_item, pattern_flags);
8876 nvgre_m = &rte_flow_item_nvgre_mask;
8877 tni_flow_id_m = (const char *)nvgre_m->tni;
8878 tni_flow_id_v = (const char *)nvgre_v->tni;
8879 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
8880 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
8881 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
8882 memcpy(gre_key_m, tni_flow_id_m, size);
8883 for (i = 0; i < size; ++i)
8884 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
8888 * Add VXLAN item to matcher and to the value.
8891 * Pointer to the Ethernet device structure.
8893 * Flow rule attributes.
8894 * @param[in, out] matcher
8896 * @param[in, out] key
8897 * Flow matcher value.
8899 * Flow pattern to translate.
8901 * Item is inner pattern.
8904 flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
8905 const struct rte_flow_attr *attr,
8906 void *matcher, void *key,
8907 const struct rte_flow_item *item,
8910 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
8911 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
8916 uint32_t *tunnel_header_v;
8917 uint32_t *tunnel_header_m;
8919 struct mlx5_priv *priv = dev->data->dev_private;
8920 const struct rte_flow_item_vxlan nic_mask = {
8921 .vni = "\xff\xff\xff",
8926 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8928 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8930 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8932 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8934 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8935 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8936 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8937 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8938 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8940 dport = MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport);
8944 if ((!attr->group && !priv->sh->tunnel_header_0_1) ||
8945 (attr->group && !priv->sh->misc5_cap))
8946 vxlan_m = &rte_flow_item_vxlan_mask;
8948 vxlan_m = &nic_mask;
8950 if ((priv->sh->steering_format_version ==
8951 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
8952 dport != MLX5_UDP_PORT_VXLAN) ||
8953 (!attr->group && !attr->transfer && !priv->sh->tunnel_header_0_1) ||
8954 ((attr->group || attr->transfer) && !priv->sh->misc5_cap)) {
8961 misc_m = MLX5_ADDR_OF(fte_match_param,
8962 matcher, misc_parameters);
8963 misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8964 size = sizeof(vxlan_m->vni);
8965 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
8966 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
8967 memcpy(vni_m, vxlan_m->vni, size);
8968 for (i = 0; i < size; ++i)
8969 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8972 misc5_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_5);
8973 misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
8974 tunnel_header_v = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
8977 tunnel_header_m = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
8980 *tunnel_header_v = (vxlan_v->vni[0] & vxlan_m->vni[0]) |
8981 (vxlan_v->vni[1] & vxlan_m->vni[1]) << 8 |
8982 (vxlan_v->vni[2] & vxlan_m->vni[2]) << 16;
8983 if (*tunnel_header_v)
8984 *tunnel_header_m = vxlan_m->vni[0] |
8985 vxlan_m->vni[1] << 8 |
8986 vxlan_m->vni[2] << 16;
8988 *tunnel_header_m = 0x0;
8989 *tunnel_header_v |= (vxlan_v->rsvd1 & vxlan_m->rsvd1) << 24;
8990 if (vxlan_v->rsvd1 & vxlan_m->rsvd1)
8991 *tunnel_header_m |= vxlan_m->rsvd1 << 24;
8995 * Add VXLAN-GPE item to matcher and to the value.
8997 * @param[in, out] matcher
8999 * @param[in, out] key
9000 * Flow matcher value.
9002 * Flow pattern to translate.
9004 * Item is inner pattern.
9008 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
9009 const struct rte_flow_item *item,
9010 const uint64_t pattern_flags)
9012 static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {0, };
9013 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
9014 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
9015 /* The item was validated to be on the outer side */
9016 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9017 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9019 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
9021 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9023 MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
9025 MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
9026 int i, size = sizeof(vxlan_m->vni);
9027 uint8_t flags_m = 0xff;
9028 uint8_t flags_v = 0xc;
9029 uint8_t m_protocol, v_protocol;
9031 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9032 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9033 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9034 MLX5_UDP_PORT_VXLAN_GPE);
9037 vxlan_v = &dummy_vxlan_gpe_hdr;
9038 vxlan_m = &dummy_vxlan_gpe_hdr;
9041 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
9043 memcpy(vni_m, vxlan_m->vni, size);
9044 for (i = 0; i < size; ++i)
9045 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
9046 if (vxlan_m->flags) {
9047 flags_m = vxlan_m->flags;
9048 flags_v = vxlan_v->flags;
9050 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
9051 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
9052 m_protocol = vxlan_m->protocol;
9053 v_protocol = vxlan_v->protocol;
9055 /* Force next protocol to ensure next headers parsing. */
9056 if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
9057 v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
9058 else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
9059 v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
9060 else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
9061 v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
9065 MLX5_SET(fte_match_set_misc3, misc_m,
9066 outer_vxlan_gpe_next_protocol, m_protocol);
9067 MLX5_SET(fte_match_set_misc3, misc_v,
9068 outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
9072 * Add Geneve item to matcher and to the value.
9074 * @param[in, out] matcher
9076 * @param[in, out] key
9077 * Flow matcher value.
9079 * Flow pattern to translate.
9081 * Item is inner pattern.
9085 flow_dv_translate_item_geneve(void *matcher, void *key,
9086 const struct rte_flow_item *item,
9087 uint64_t pattern_flags)
9089 static const struct rte_flow_item_geneve empty_geneve = {0,};
9090 const struct rte_flow_item_geneve *geneve_m = item->mask;
9091 const struct rte_flow_item_geneve *geneve_v = item->spec;
9092 /* GENEVE flow item validation allows single tunnel item */
9093 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9094 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9095 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9096 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9099 char *vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
9100 char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
9101 size_t size = sizeof(geneve_m->vni), i;
9102 uint16_t protocol_m, protocol_v;
9104 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9105 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9106 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9107 MLX5_UDP_PORT_GENEVE);
9110 geneve_v = &empty_geneve;
9111 geneve_m = &empty_geneve;
9114 geneve_m = &rte_flow_item_geneve_mask;
9116 memcpy(vni_m, geneve_m->vni, size);
9117 for (i = 0; i < size; ++i)
9118 vni_v[i] = vni_m[i] & geneve_v->vni[i];
9119 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
9120 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
9121 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
9122 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9123 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
9124 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9125 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9126 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9127 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9128 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
9129 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9130 protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
9131 protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
9133 /* Force next protocol to prevent matchers duplication */
9134 protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9136 protocol_m = 0xFFFF;
9138 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type, protocol_m);
9139 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
9140 protocol_m & protocol_v);
9144 * Create Geneve TLV option resource.
9146 * @param dev[in, out]
9147 * Pointer to rte_eth_dev structure.
9148 * @param[in, out] tag_be24
9149 * Tag value in big endian then R-shift 8.
9150 * @parm[in, out] dev_flow
9151 * Pointer to the dev_flow.
9153 * pointer to error structure.
9156 * 0 on success otherwise -errno and errno is set.
9160 flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
9161 const struct rte_flow_item *item,
9162 struct rte_flow_error *error)
9164 struct mlx5_priv *priv = dev->data->dev_private;
9165 struct mlx5_dev_ctx_shared *sh = priv->sh;
9166 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
9167 sh->geneve_tlv_option_resource;
9168 struct mlx5_devx_obj *obj;
9169 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9174 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
9175 if (geneve_opt_resource != NULL) {
9176 if (geneve_opt_resource->option_class ==
9177 geneve_opt_v->option_class &&
9178 geneve_opt_resource->option_type ==
9179 geneve_opt_v->option_type &&
9180 geneve_opt_resource->length ==
9181 geneve_opt_v->option_len) {
9182 /* We already have GENEVE TLV option obj allocated. */
9183 __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
9186 ret = rte_flow_error_set(error, ENOMEM,
9187 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9188 "Only one GENEVE TLV option supported");
9192 /* Create a GENEVE TLV object and resource. */
9193 obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
9194 geneve_opt_v->option_class,
9195 geneve_opt_v->option_type,
9196 geneve_opt_v->option_len);
9198 ret = rte_flow_error_set(error, ENODATA,
9199 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9200 "Failed to create GENEVE TLV Devx object");
9203 sh->geneve_tlv_option_resource =
9204 mlx5_malloc(MLX5_MEM_ZERO,
9205 sizeof(*geneve_opt_resource),
9207 if (!sh->geneve_tlv_option_resource) {
9208 claim_zero(mlx5_devx_cmd_destroy(obj));
9209 ret = rte_flow_error_set(error, ENOMEM,
9210 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9211 "GENEVE TLV object memory allocation failed");
9214 geneve_opt_resource = sh->geneve_tlv_option_resource;
9215 geneve_opt_resource->obj = obj;
9216 geneve_opt_resource->option_class = geneve_opt_v->option_class;
9217 geneve_opt_resource->option_type = geneve_opt_v->option_type;
9218 geneve_opt_resource->length = geneve_opt_v->option_len;
9219 __atomic_store_n(&geneve_opt_resource->refcnt, 1,
9223 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
9228 * Add Geneve TLV option item to matcher.
9230 * @param[in, out] dev
9231 * Pointer to rte_eth_dev structure.
9232 * @param[in, out] matcher
9234 * @param[in, out] key
9235 * Flow matcher value.
9237 * Flow pattern to translate.
9239 * Pointer to error structure.
9242 flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *matcher,
9243 void *key, const struct rte_flow_item *item,
9244 struct rte_flow_error *error)
9246 const struct rte_flow_item_geneve_opt *geneve_opt_m = item->mask;
9247 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9248 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9249 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9250 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9252 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9253 rte_be32_t opt_data_key = 0, opt_data_mask = 0;
9259 geneve_opt_m = &rte_flow_item_geneve_opt_mask;
9260 ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
9263 DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
9267 * Set the option length in GENEVE header if not requested.
9268 * The GENEVE TLV option length is expressed by the option length field
9269 * in the GENEVE header.
9270 * If the option length was not requested but the GENEVE TLV option item
9271 * is present we set the option length field implicitly.
9273 if (!MLX5_GET16(fte_match_set_misc, misc_m, geneve_opt_len)) {
9274 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9275 MLX5_GENEVE_OPTLEN_MASK);
9276 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9277 geneve_opt_v->option_len + 1);
9279 MLX5_SET(fte_match_set_misc, misc_m, geneve_tlv_option_0_exist, 1);
9280 MLX5_SET(fte_match_set_misc, misc_v, geneve_tlv_option_0_exist, 1);
9282 if (geneve_opt_v->data) {
9283 memcpy(&opt_data_key, geneve_opt_v->data,
9284 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9285 sizeof(opt_data_key)));
9286 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9287 sizeof(opt_data_key));
9288 memcpy(&opt_data_mask, geneve_opt_m->data,
9289 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9290 sizeof(opt_data_mask)));
9291 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9292 sizeof(opt_data_mask));
9293 MLX5_SET(fte_match_set_misc3, misc3_m,
9294 geneve_tlv_option_0_data,
9295 rte_be_to_cpu_32(opt_data_mask));
9296 MLX5_SET(fte_match_set_misc3, misc3_v,
9297 geneve_tlv_option_0_data,
9298 rte_be_to_cpu_32(opt_data_key & opt_data_mask));
9304 * Add MPLS item to matcher and to the value.
9306 * @param[in, out] matcher
9308 * @param[in, out] key
9309 * Flow matcher value.
9311 * Flow pattern to translate.
9312 * @param[in] prev_layer
9313 * The protocol layer indicated in previous item.
9315 * Item is inner pattern.
9318 flow_dv_translate_item_mpls(void *matcher, void *key,
9319 const struct rte_flow_item *item,
9320 uint64_t prev_layer,
9323 const uint32_t *in_mpls_m = item->mask;
9324 const uint32_t *in_mpls_v = item->spec;
9325 uint32_t *out_mpls_m = 0;
9326 uint32_t *out_mpls_v = 0;
9327 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9328 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9329 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
9331 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9332 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9333 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9335 switch (prev_layer) {
9336 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9337 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9338 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
9340 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9341 MLX5_UDP_PORT_MPLS);
9344 case MLX5_FLOW_LAYER_GRE:
9346 case MLX5_FLOW_LAYER_GRE_KEY:
9347 if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
9348 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
9350 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9351 RTE_ETHER_TYPE_MPLS);
9360 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
9361 switch (prev_layer) {
9362 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9364 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9365 outer_first_mpls_over_udp);
9367 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9368 outer_first_mpls_over_udp);
9370 case MLX5_FLOW_LAYER_GRE:
9372 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9373 outer_first_mpls_over_gre);
9375 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9376 outer_first_mpls_over_gre);
9379 /* Inner MPLS not over GRE is not supported. */
9382 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9386 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9392 if (out_mpls_m && out_mpls_v) {
9393 *out_mpls_m = *in_mpls_m;
9394 *out_mpls_v = *in_mpls_v & *in_mpls_m;
9399 * Add metadata register item to matcher
9401 * @param[in, out] matcher
9403 * @param[in, out] key
9404 * Flow matcher value.
9405 * @param[in] reg_type
9406 * Type of device metadata register
9413 flow_dv_match_meta_reg(void *matcher, void *key,
9414 enum modify_reg reg_type,
9415 uint32_t data, uint32_t mask)
9418 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
9420 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9426 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
9427 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
9430 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
9431 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
9435 * The metadata register C0 field might be divided into
9436 * source vport index and META item value, we should set
9437 * this field according to specified mask, not as whole one.
9439 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
9441 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
9442 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
9445 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
9448 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
9449 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
9452 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
9453 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
9456 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
9457 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
9460 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
9461 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
9464 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
9465 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
9468 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
9469 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
9472 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
9473 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
9482 * Add MARK item to matcher
9485 * The device to configure through.
9486 * @param[in, out] matcher
9488 * @param[in, out] key
9489 * Flow matcher value.
9491 * Flow pattern to translate.
9494 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
9495 void *matcher, void *key,
9496 const struct rte_flow_item *item)
9498 struct mlx5_priv *priv = dev->data->dev_private;
9499 const struct rte_flow_item_mark *mark;
9503 mark = item->mask ? (const void *)item->mask :
9504 &rte_flow_item_mark_mask;
9505 mask = mark->id & priv->sh->dv_mark_mask;
9506 mark = (const void *)item->spec;
9508 value = mark->id & priv->sh->dv_mark_mask & mask;
9510 enum modify_reg reg;
9512 /* Get the metadata register index for the mark. */
9513 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
9514 MLX5_ASSERT(reg > 0);
9515 if (reg == REG_C_0) {
9516 struct mlx5_priv *priv = dev->data->dev_private;
9517 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9518 uint32_t shl_c0 = rte_bsf32(msk_c0);
9524 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9529 * Add META item to matcher
9532 * The devich to configure through.
9533 * @param[in, out] matcher
9535 * @param[in, out] key
9536 * Flow matcher value.
9538 * Attributes of flow that includes this item.
9540 * Flow pattern to translate.
9543 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
9544 void *matcher, void *key,
9545 const struct rte_flow_attr *attr,
9546 const struct rte_flow_item *item)
9548 const struct rte_flow_item_meta *meta_m;
9549 const struct rte_flow_item_meta *meta_v;
9551 meta_m = (const void *)item->mask;
9553 meta_m = &rte_flow_item_meta_mask;
9554 meta_v = (const void *)item->spec;
9557 uint32_t value = meta_v->data;
9558 uint32_t mask = meta_m->data;
9560 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
9563 MLX5_ASSERT(reg != REG_NON);
9564 if (reg == REG_C_0) {
9565 struct mlx5_priv *priv = dev->data->dev_private;
9566 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9567 uint32_t shl_c0 = rte_bsf32(msk_c0);
9573 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9578 * Add vport metadata Reg C0 item to matcher
9580 * @param[in, out] matcher
9582 * @param[in, out] key
9583 * Flow matcher value.
9585 * Flow pattern to translate.
9588 flow_dv_translate_item_meta_vport(void *matcher, void *key,
9589 uint32_t value, uint32_t mask)
9591 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
9595 * Add tag item to matcher
9598 * The devich to configure through.
9599 * @param[in, out] matcher
9601 * @param[in, out] key
9602 * Flow matcher value.
9604 * Flow pattern to translate.
9607 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
9608 void *matcher, void *key,
9609 const struct rte_flow_item *item)
9611 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
9612 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
9613 uint32_t mask, value;
9616 value = tag_v->data;
9617 mask = tag_m ? tag_m->data : UINT32_MAX;
9618 if (tag_v->id == REG_C_0) {
9619 struct mlx5_priv *priv = dev->data->dev_private;
9620 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9621 uint32_t shl_c0 = rte_bsf32(msk_c0);
9627 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
9631 * Add TAG item to matcher
9634 * The devich to configure through.
9635 * @param[in, out] matcher
9637 * @param[in, out] key
9638 * Flow matcher value.
9640 * Flow pattern to translate.
9643 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
9644 void *matcher, void *key,
9645 const struct rte_flow_item *item)
9647 const struct rte_flow_item_tag *tag_v = item->spec;
9648 const struct rte_flow_item_tag *tag_m = item->mask;
9649 enum modify_reg reg;
9652 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
9653 /* Get the metadata register index for the tag. */
9654 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
9655 MLX5_ASSERT(reg > 0);
9656 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
9660 * Add source vport match to the specified matcher.
9662 * @param[in, out] matcher
9664 * @param[in, out] key
9665 * Flow matcher value.
9667 * Source vport value to match
9672 flow_dv_translate_item_source_vport(void *matcher, void *key,
9673 int16_t port, uint16_t mask)
9675 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9676 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9678 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
9679 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
9683 * Translate port-id item to eswitch match on port-id.
9686 * The devich to configure through.
9687 * @param[in, out] matcher
9689 * @param[in, out] key
9690 * Flow matcher value.
9692 * Flow pattern to translate.
9697 * 0 on success, a negative errno value otherwise.
9700 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
9701 void *key, const struct rte_flow_item *item,
9702 const struct rte_flow_attr *attr)
9704 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
9705 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
9706 struct mlx5_priv *priv;
9709 if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
9710 flow_dv_translate_item_source_vport(matcher, key,
9711 flow_dv_get_esw_manager_vport_id(dev), 0xffff);
9714 mask = pid_m ? pid_m->id : 0xffff;
9715 id = pid_v ? pid_v->id : dev->data->port_id;
9716 priv = mlx5_port_to_eswitch_info(id, item == NULL);
9720 * Translate to vport field or to metadata, depending on mode.
9721 * Kernel can use either misc.source_port or half of C0 metadata
9724 if (priv->vport_meta_mask) {
9726 * Provide the hint for SW steering library
9727 * to insert the flow into ingress domain and
9728 * save the extra vport match.
9730 if (mask == 0xffff && priv->vport_id == 0xffff &&
9731 priv->pf_bond < 0 && attr->transfer)
9732 flow_dv_translate_item_source_vport
9733 (matcher, key, priv->vport_id, mask);
9735 * We should always set the vport metadata register,
9736 * otherwise the SW steering library can drop
9737 * the rule if wire vport metadata value is not zero,
9738 * it depends on kernel configuration.
9740 flow_dv_translate_item_meta_vport(matcher, key,
9741 priv->vport_meta_tag,
9742 priv->vport_meta_mask);
9744 flow_dv_translate_item_source_vport(matcher, key,
9745 priv->vport_id, mask);
9751 * Add ICMP6 item to matcher and to the value.
9753 * @param[in, out] matcher
9755 * @param[in, out] key
9756 * Flow matcher value.
9758 * Flow pattern to translate.
9760 * Item is inner pattern.
9763 flow_dv_translate_item_icmp6(void *matcher, void *key,
9764 const struct rte_flow_item *item,
9767 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
9768 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
9771 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9773 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9775 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9777 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9779 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9781 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9783 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9784 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
9788 icmp6_m = &rte_flow_item_icmp6_mask;
9789 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
9790 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
9791 icmp6_v->type & icmp6_m->type);
9792 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
9793 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
9794 icmp6_v->code & icmp6_m->code);
9798 * Add ICMP item to matcher and to the value.
9800 * @param[in, out] matcher
9802 * @param[in, out] key
9803 * Flow matcher value.
9805 * Flow pattern to translate.
9807 * Item is inner pattern.
9810 flow_dv_translate_item_icmp(void *matcher, void *key,
9811 const struct rte_flow_item *item,
9814 const struct rte_flow_item_icmp *icmp_m = item->mask;
9815 const struct rte_flow_item_icmp *icmp_v = item->spec;
9816 uint32_t icmp_header_data_m = 0;
9817 uint32_t icmp_header_data_v = 0;
9820 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9822 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9824 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9826 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9828 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9830 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9832 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9833 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
9837 icmp_m = &rte_flow_item_icmp_mask;
9838 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
9839 icmp_m->hdr.icmp_type);
9840 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
9841 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
9842 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
9843 icmp_m->hdr.icmp_code);
9844 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
9845 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
9846 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
9847 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
9848 if (icmp_header_data_m) {
9849 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
9850 icmp_header_data_v |=
9851 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
9852 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
9853 icmp_header_data_m);
9854 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
9855 icmp_header_data_v & icmp_header_data_m);
9860 * Add GTP item to matcher and to the value.
9862 * @param[in, out] matcher
9864 * @param[in, out] key
9865 * Flow matcher value.
9867 * Flow pattern to translate.
9869 * Item is inner pattern.
9872 flow_dv_translate_item_gtp(void *matcher, void *key,
9873 const struct rte_flow_item *item, int inner)
9875 const struct rte_flow_item_gtp *gtp_m = item->mask;
9876 const struct rte_flow_item_gtp *gtp_v = item->spec;
9879 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9881 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9882 uint16_t dport = RTE_GTPU_UDP_PORT;
9885 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9887 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9889 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9891 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9893 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9894 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9895 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
9900 gtp_m = &rte_flow_item_gtp_mask;
9901 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
9902 gtp_m->v_pt_rsv_flags);
9903 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
9904 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
9905 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
9906 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
9907 gtp_v->msg_type & gtp_m->msg_type);
9908 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
9909 rte_be_to_cpu_32(gtp_m->teid));
9910 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
9911 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
9915 * Add GTP PSC item to matcher.
9917 * @param[in, out] matcher
9919 * @param[in, out] key
9920 * Flow matcher value.
9922 * Flow pattern to translate.
9925 flow_dv_translate_item_gtp_psc(void *matcher, void *key,
9926 const struct rte_flow_item *item)
9928 const struct rte_flow_item_gtp_psc *gtp_psc_m = item->mask;
9929 const struct rte_flow_item_gtp_psc *gtp_psc_v = item->spec;
9930 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9932 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9938 uint8_t next_ext_header_type;
9943 /* Always set E-flag match on one, regardless of GTP item settings. */
9944 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_m, gtpu_msg_flags);
9945 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9946 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags, gtp_flags);
9947 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
9948 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9949 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
9950 /*Set next extension header type. */
9953 dw_2.next_ext_header_type = 0xff;
9954 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_dw_2,
9955 rte_cpu_to_be_32(dw_2.w32));
9958 dw_2.next_ext_header_type = 0x85;
9959 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
9960 rte_cpu_to_be_32(dw_2.w32));
9972 /*Set extension header PDU type and Qos. */
9974 gtp_psc_m = &rte_flow_item_gtp_psc_mask;
9976 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_m->hdr.type);
9977 dw_0.qfi = gtp_psc_m->hdr.qfi;
9978 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_first_ext_dw_0,
9979 rte_cpu_to_be_32(dw_0.w32));
9981 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
9982 gtp_psc_m->hdr.type);
9983 dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
9984 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
9985 rte_cpu_to_be_32(dw_0.w32));
9991 * Add eCPRI item to matcher and to the value.
9994 * The devich to configure through.
9995 * @param[in, out] matcher
9997 * @param[in, out] key
9998 * Flow matcher value.
10000 * Flow pattern to translate.
10001 * @param[in] last_item
10005 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
10006 void *key, const struct rte_flow_item *item,
10007 uint64_t last_item)
10009 struct mlx5_priv *priv = dev->data->dev_private;
10010 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
10011 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
10012 struct rte_ecpri_common_hdr common;
10013 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
10014 misc_parameters_4);
10015 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
10021 * In case of eCPRI over Ethernet, if EtherType is not specified,
10022 * match on eCPRI EtherType implicitly.
10024 if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
10025 void *hdrs_m, *hdrs_v, *l2m, *l2v;
10027 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
10028 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10029 l2m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, ethertype);
10030 l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
10031 if (*(uint16_t *)l2m == 0 && *(uint16_t *)l2v == 0) {
10032 *(uint16_t *)l2m = UINT16_MAX;
10033 *(uint16_t *)l2v = RTE_BE16(RTE_ETHER_TYPE_ECPRI);
10039 ecpri_m = &rte_flow_item_ecpri_mask;
10041 * Maximal four DW samples are supported in a single matching now.
10042 * Two are used now for a eCPRI matching:
10043 * 1. Type: one byte, mask should be 0x00ff0000 in network order
10044 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
10047 if (!ecpri_m->hdr.common.u32)
10049 samples = priv->sh->ecpri_parser.ids;
10050 /* Need to take the whole DW as the mask to fill the entry. */
10051 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
10052 prog_sample_field_value_0);
10053 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
10054 prog_sample_field_value_0);
10055 /* Already big endian (network order) in the header. */
10056 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
10057 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
10058 /* Sample#0, used for matching type, offset 0. */
10059 MLX5_SET(fte_match_set_misc4, misc4_m,
10060 prog_sample_field_id_0, samples[0]);
10061 /* It makes no sense to set the sample ID in the mask field. */
10062 MLX5_SET(fte_match_set_misc4, misc4_v,
10063 prog_sample_field_id_0, samples[0]);
10065 * Checking if message body part needs to be matched.
10066 * Some wildcard rules only matching type field should be supported.
10068 if (ecpri_m->hdr.dummy[0]) {
10069 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
10070 switch (common.type) {
10071 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
10072 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
10073 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
10074 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
10075 prog_sample_field_value_1);
10076 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
10077 prog_sample_field_value_1);
10078 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
10079 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
10080 ecpri_m->hdr.dummy[0];
10081 /* Sample#1, to match message body, offset 4. */
10082 MLX5_SET(fte_match_set_misc4, misc4_m,
10083 prog_sample_field_id_1, samples[1]);
10084 MLX5_SET(fte_match_set_misc4, misc4_v,
10085 prog_sample_field_id_1, samples[1]);
10088 /* Others, do not match any sample ID. */
10095 * Add connection tracking status item to matcher
10098 * The devich to configure through.
10099 * @param[in, out] matcher
10101 * @param[in, out] key
10102 * Flow matcher value.
10104 * Flow pattern to translate.
10107 flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
10108 void *matcher, void *key,
10109 const struct rte_flow_item *item)
10111 uint32_t reg_value = 0;
10113 /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
10114 uint32_t reg_mask = 0;
10115 const struct rte_flow_item_conntrack *spec = item->spec;
10116 const struct rte_flow_item_conntrack *mask = item->mask;
10118 struct rte_flow_error error;
10121 mask = &rte_flow_item_conntrack_mask;
10122 if (!spec || !mask->flags)
10124 flags = spec->flags & mask->flags;
10125 /* The conflict should be checked in the validation. */
10126 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
10127 reg_value |= MLX5_CT_SYNDROME_VALID;
10128 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
10129 reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
10130 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
10131 reg_value |= MLX5_CT_SYNDROME_INVALID;
10132 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
10133 reg_value |= MLX5_CT_SYNDROME_TRAP;
10134 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10135 reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
10136 if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
10137 RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
10138 RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
10140 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
10141 reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
10142 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10143 reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
10144 /* The REG_C_x value could be saved during startup. */
10145 reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
10146 if (reg_id == REG_NON)
10148 flow_dv_match_meta_reg(matcher, key, (enum modify_reg)reg_id,
10149 reg_value, reg_mask);
10153 flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
10154 const struct rte_flow_item *item,
10155 struct mlx5_flow *dev_flow, bool is_inner)
10157 const struct rte_flow_item_flex *spec =
10158 (const struct rte_flow_item_flex *)item->spec;
10159 int index = mlx5_flex_acquire_index(dev, spec->handle, false);
10161 MLX5_ASSERT(index >= 0 && index <= (int)(sizeof(uint32_t) * CHAR_BIT));
10164 if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
10165 /* Don't count both inner and outer flex items in one rule. */
10166 if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
10167 MLX5_ASSERT(false);
10168 dev_flow->handle->flex_item |= RTE_BIT32(index);
10170 mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
10173 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
10175 #define HEADER_IS_ZERO(match_criteria, headers) \
10176 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
10177 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
10180 * Calculate flow matcher enable bitmap.
10182 * @param match_criteria
10183 * Pointer to flow matcher criteria.
10186 * Bitmap of enabled fields.
10189 flow_dv_matcher_enable(uint32_t *match_criteria)
10191 uint8_t match_criteria_enable;
10193 match_criteria_enable =
10194 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
10195 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
10196 match_criteria_enable |=
10197 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
10198 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
10199 match_criteria_enable |=
10200 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
10201 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
10202 match_criteria_enable |=
10203 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
10204 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
10205 match_criteria_enable |=
10206 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
10207 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
10208 match_criteria_enable |=
10209 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
10210 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
10211 match_criteria_enable |=
10212 (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
10213 MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
10214 return match_criteria_enable;
10218 __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
10221 * Check flow matching criteria first, subtract misc5/4 length if flow
10222 * doesn't own misc5/4 parameters. In some old rdma-core releases,
10223 * misc5/4 are not supported, and matcher creation failure is expected
10224 * w/o subtraction. If misc5 is provided, misc4 must be counted in since
10225 * misc5 is right after misc4.
10227 if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
10228 *size = MLX5_ST_SZ_BYTES(fte_match_param) -
10229 MLX5_ST_SZ_BYTES(fte_match_set_misc5);
10230 if (!(match_criteria & (1 <<
10231 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
10232 *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
10237 static struct mlx5_list_entry *
10238 flow_dv_matcher_clone_cb(void *tool_ctx __rte_unused,
10239 struct mlx5_list_entry *entry, void *cb_ctx)
10241 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10242 struct mlx5_flow_dv_matcher *ref = ctx->data;
10243 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10244 typeof(*tbl), tbl);
10245 struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
10250 rte_flow_error_set(ctx->error, ENOMEM,
10251 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10252 "cannot create matcher");
10255 memcpy(resource, entry, sizeof(*resource));
10256 resource->tbl = &tbl->tbl;
10257 return &resource->entry;
10261 flow_dv_matcher_clone_free_cb(void *tool_ctx __rte_unused,
10262 struct mlx5_list_entry *entry)
10267 struct mlx5_list_entry *
10268 flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
10270 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10271 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10272 struct rte_eth_dev *dev = ctx->dev;
10273 struct mlx5_flow_tbl_data_entry *tbl_data;
10274 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
10275 struct rte_flow_error *error = ctx->error;
10276 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10277 struct mlx5_flow_tbl_resource *tbl;
10282 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10284 rte_flow_error_set(error, ENOMEM,
10285 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10287 "cannot allocate flow table data entry");
10290 tbl_data->idx = idx;
10291 tbl_data->tunnel = tt_prm->tunnel;
10292 tbl_data->group_id = tt_prm->group_id;
10293 tbl_data->external = !!tt_prm->external;
10294 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
10295 tbl_data->is_egress = !!key.is_egress;
10296 tbl_data->is_transfer = !!key.is_fdb;
10297 tbl_data->dummy = !!key.dummy;
10298 tbl_data->level = key.level;
10299 tbl_data->id = key.id;
10300 tbl = &tbl_data->tbl;
10302 return &tbl_data->entry;
10304 domain = sh->fdb_domain;
10305 else if (key.is_egress)
10306 domain = sh->tx_domain;
10308 domain = sh->rx_domain;
10309 ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
10311 rte_flow_error_set(error, ENOMEM,
10312 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10313 NULL, "cannot create flow table object");
10314 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10317 if (key.level != 0) {
10318 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
10319 (tbl->obj, &tbl_data->jump.action);
10321 rte_flow_error_set(error, ENOMEM,
10322 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10324 "cannot create flow jump action");
10325 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10326 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10330 MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
10331 key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
10332 key.level, key.id);
10333 tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
10334 flow_dv_matcher_create_cb,
10335 flow_dv_matcher_match_cb,
10336 flow_dv_matcher_remove_cb,
10337 flow_dv_matcher_clone_cb,
10338 flow_dv_matcher_clone_free_cb);
10339 if (!tbl_data->matchers) {
10340 rte_flow_error_set(error, ENOMEM,
10341 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10343 "cannot create tbl matcher list");
10344 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10345 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10346 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10349 return &tbl_data->entry;
10353 flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
10356 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10357 struct mlx5_flow_tbl_data_entry *tbl_data =
10358 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10359 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10361 return tbl_data->level != key.level ||
10362 tbl_data->id != key.id ||
10363 tbl_data->dummy != key.dummy ||
10364 tbl_data->is_transfer != !!key.is_fdb ||
10365 tbl_data->is_egress != !!key.is_egress;
10368 struct mlx5_list_entry *
10369 flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
10372 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10373 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10374 struct mlx5_flow_tbl_data_entry *tbl_data;
10375 struct rte_flow_error *error = ctx->error;
10378 tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10380 rte_flow_error_set(error, ENOMEM,
10381 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10383 "cannot allocate flow table data entry");
10386 memcpy(tbl_data, oentry, sizeof(*tbl_data));
10387 tbl_data->idx = idx;
10388 return &tbl_data->entry;
10392 flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10394 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10395 struct mlx5_flow_tbl_data_entry *tbl_data =
10396 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10398 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10402 * Get a flow table.
10404 * @param[in, out] dev
10405 * Pointer to rte_eth_dev structure.
10406 * @param[in] table_level
10407 * Table level to use.
10408 * @param[in] egress
10409 * Direction of the table.
10410 * @param[in] transfer
10411 * E-Switch or NIC flow.
10413 * Dummy entry for dv API.
10414 * @param[in] table_id
10416 * @param[out] error
10417 * pointer to error structure.
10420 * Returns tables resource based on the index, NULL in case of failed.
10422 struct mlx5_flow_tbl_resource *
10423 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
10424 uint32_t table_level, uint8_t egress,
10427 const struct mlx5_flow_tunnel *tunnel,
10428 uint32_t group_id, uint8_t dummy,
10430 struct rte_flow_error *error)
10432 struct mlx5_priv *priv = dev->data->dev_private;
10433 union mlx5_flow_tbl_key table_key = {
10435 .level = table_level,
10439 .is_fdb = !!transfer,
10440 .is_egress = !!egress,
10443 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
10445 .group_id = group_id,
10446 .external = external,
10448 struct mlx5_flow_cb_ctx ctx = {
10451 .data = &table_key.v64,
10454 struct mlx5_list_entry *entry;
10455 struct mlx5_flow_tbl_data_entry *tbl_data;
10457 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
10459 rte_flow_error_set(error, ENOMEM,
10460 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10461 "cannot get table");
10464 DRV_LOG(DEBUG, "table_level %u table_id %u "
10465 "tunnel %u group %u registered.",
10466 table_level, table_id,
10467 tunnel ? tunnel->tunnel_id : 0, group_id);
10468 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10469 return &tbl_data->tbl;
10473 flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10475 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10476 struct mlx5_flow_tbl_data_entry *tbl_data =
10477 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10479 MLX5_ASSERT(entry && sh);
10480 if (tbl_data->jump.action)
10481 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10482 if (tbl_data->tbl.obj)
10483 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
10484 if (tbl_data->tunnel_offload && tbl_data->external) {
10485 struct mlx5_list_entry *he;
10486 struct mlx5_hlist *tunnel_grp_hash;
10487 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
10488 union tunnel_tbl_key tunnel_key = {
10489 .tunnel_id = tbl_data->tunnel ?
10490 tbl_data->tunnel->tunnel_id : 0,
10491 .group = tbl_data->group_id
10493 uint32_t table_level = tbl_data->level;
10494 struct mlx5_flow_cb_ctx ctx = {
10495 .data = (void *)&tunnel_key.val,
10498 tunnel_grp_hash = tbl_data->tunnel ?
10499 tbl_data->tunnel->groups :
10501 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
10503 mlx5_hlist_unregister(tunnel_grp_hash, he);
10505 "table_level %u id %u tunnel %u group %u released.",
10509 tbl_data->tunnel->tunnel_id : 0,
10510 tbl_data->group_id);
10512 mlx5_list_destroy(tbl_data->matchers);
10513 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10517 * Release a flow table.
10520 * Pointer to device shared structure.
10522 * Table resource to be released.
10525 * Returns 0 if table was released, else return 1;
10528 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
10529 struct mlx5_flow_tbl_resource *tbl)
10531 struct mlx5_flow_tbl_data_entry *tbl_data =
10532 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10536 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
10540 flow_dv_matcher_match_cb(void *tool_ctx __rte_unused,
10541 struct mlx5_list_entry *entry, void *cb_ctx)
10543 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10544 struct mlx5_flow_dv_matcher *ref = ctx->data;
10545 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
10548 return cur->crc != ref->crc ||
10549 cur->priority != ref->priority ||
10550 memcmp((const void *)cur->mask.buf,
10551 (const void *)ref->mask.buf, ref->mask.size);
10554 struct mlx5_list_entry *
10555 flow_dv_matcher_create_cb(void *tool_ctx, void *cb_ctx)
10557 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10558 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10559 struct mlx5_flow_dv_matcher *ref = ctx->data;
10560 struct mlx5_flow_dv_matcher *resource;
10561 struct mlx5dv_flow_matcher_attr dv_attr = {
10562 .type = IBV_FLOW_ATTR_NORMAL,
10563 .match_mask = (void *)&ref->mask,
10565 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10566 typeof(*tbl), tbl);
10569 resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
10572 rte_flow_error_set(ctx->error, ENOMEM,
10573 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10574 "cannot create matcher");
10578 dv_attr.match_criteria_enable =
10579 flow_dv_matcher_enable(resource->mask.buf);
10580 __flow_dv_adjust_buf_size(&ref->mask.size,
10581 dv_attr.match_criteria_enable);
10582 dv_attr.priority = ref->priority;
10583 if (tbl->is_egress)
10584 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
10585 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
10587 &resource->matcher_object);
10589 mlx5_free(resource);
10590 rte_flow_error_set(ctx->error, ENOMEM,
10591 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10592 "cannot create matcher");
10595 return &resource->entry;
10599 * Register the flow matcher.
10601 * @param[in, out] dev
10602 * Pointer to rte_eth_dev structure.
10603 * @param[in, out] matcher
10604 * Pointer to flow matcher.
10605 * @param[in, out] key
10606 * Pointer to flow table key.
10607 * @parm[in, out] dev_flow
10608 * Pointer to the dev_flow.
10609 * @param[out] error
10610 * pointer to error structure.
10613 * 0 on success otherwise -errno and errno is set.
10616 flow_dv_matcher_register(struct rte_eth_dev *dev,
10617 struct mlx5_flow_dv_matcher *ref,
10618 union mlx5_flow_tbl_key *key,
10619 struct mlx5_flow *dev_flow,
10620 const struct mlx5_flow_tunnel *tunnel,
10622 struct rte_flow_error *error)
10624 struct mlx5_list_entry *entry;
10625 struct mlx5_flow_dv_matcher *resource;
10626 struct mlx5_flow_tbl_resource *tbl;
10627 struct mlx5_flow_tbl_data_entry *tbl_data;
10628 struct mlx5_flow_cb_ctx ctx = {
10633 * tunnel offload API requires this registration for cases when
10634 * tunnel match rule was inserted before tunnel set rule.
10636 tbl = flow_dv_tbl_resource_get(dev, key->level,
10637 key->is_egress, key->is_fdb,
10638 dev_flow->external, tunnel,
10639 group_id, 0, key->id, error);
10641 return -rte_errno; /* No need to refill the error info */
10642 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10644 entry = mlx5_list_register(tbl_data->matchers, &ctx);
10646 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
10647 return rte_flow_error_set(error, ENOMEM,
10648 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10649 "cannot allocate ref memory");
10651 resource = container_of(entry, typeof(*resource), entry);
10652 dev_flow->handle->dvh.matcher = resource;
10656 struct mlx5_list_entry *
10657 flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
10659 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10660 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10661 struct mlx5_flow_dv_tag_resource *entry;
10665 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10667 rte_flow_error_set(ctx->error, ENOMEM,
10668 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10669 "cannot allocate resource memory");
10673 entry->tag_id = *(uint32_t *)(ctx->data);
10674 ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
10677 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
10678 rte_flow_error_set(ctx->error, ENOMEM,
10679 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10680 NULL, "cannot create action");
10683 return &entry->entry;
10687 flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
10690 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10691 struct mlx5_flow_dv_tag_resource *tag =
10692 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10694 return *(uint32_t *)(ctx->data) != tag->tag_id;
10697 struct mlx5_list_entry *
10698 flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
10701 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10702 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10703 struct mlx5_flow_dv_tag_resource *entry;
10706 entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10708 rte_flow_error_set(ctx->error, ENOMEM,
10709 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10710 "cannot allocate tag resource memory");
10713 memcpy(entry, oentry, sizeof(*entry));
10715 return &entry->entry;
10719 flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10721 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10722 struct mlx5_flow_dv_tag_resource *tag =
10723 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10725 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10729 * Find existing tag resource or create and register a new one.
10731 * @param dev[in, out]
10732 * Pointer to rte_eth_dev structure.
10733 * @param[in, out] tag_be24
10734 * Tag value in big endian then R-shift 8.
10735 * @parm[in, out] dev_flow
10736 * Pointer to the dev_flow.
10737 * @param[out] error
10738 * pointer to error structure.
10741 * 0 on success otherwise -errno and errno is set.
10744 flow_dv_tag_resource_register
10745 (struct rte_eth_dev *dev,
10747 struct mlx5_flow *dev_flow,
10748 struct rte_flow_error *error)
10750 struct mlx5_priv *priv = dev->data->dev_private;
10751 struct mlx5_flow_dv_tag_resource *resource;
10752 struct mlx5_list_entry *entry;
10753 struct mlx5_flow_cb_ctx ctx = {
10757 struct mlx5_hlist *tag_table;
10759 tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
10761 MLX5_TAGS_HLIST_ARRAY_SIZE,
10762 false, false, priv->sh,
10763 flow_dv_tag_create_cb,
10764 flow_dv_tag_match_cb,
10765 flow_dv_tag_remove_cb,
10766 flow_dv_tag_clone_cb,
10767 flow_dv_tag_clone_free_cb);
10768 if (unlikely(!tag_table))
10770 entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
10772 resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
10774 dev_flow->handle->dvh.rix_tag = resource->idx;
10775 dev_flow->dv.tag_resource = resource;
10782 flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10784 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10785 struct mlx5_flow_dv_tag_resource *tag =
10786 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10788 MLX5_ASSERT(tag && sh && tag->action);
10789 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
10790 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
10791 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10798 * Pointer to Ethernet device.
10803 * 1 while a reference on it exists, 0 when freed.
10806 flow_dv_tag_release(struct rte_eth_dev *dev,
10809 struct mlx5_priv *priv = dev->data->dev_private;
10810 struct mlx5_flow_dv_tag_resource *tag;
10812 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
10815 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
10816 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
10817 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
10821 * Translate action PORT_ID / REPRESENTED_PORT to vport.
10824 * Pointer to rte_eth_dev structure.
10825 * @param[in] action
10826 * Pointer to action PORT_ID / REPRESENTED_PORT.
10827 * @param[out] dst_port_id
10828 * The target port ID.
10829 * @param[out] error
10830 * Pointer to the error structure.
10833 * 0 on success, a negative errno value otherwise and rte_errno is set.
10836 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
10837 const struct rte_flow_action *action,
10838 uint32_t *dst_port_id,
10839 struct rte_flow_error *error)
10842 struct mlx5_priv *priv;
10844 switch (action->type) {
10845 case RTE_FLOW_ACTION_TYPE_PORT_ID: {
10846 const struct rte_flow_action_port_id *conf;
10848 conf = (const struct rte_flow_action_port_id *)action->conf;
10849 port = conf->original ? dev->data->port_id : conf->id;
10852 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
10853 const struct rte_flow_action_ethdev *ethdev;
10855 ethdev = (const struct rte_flow_action_ethdev *)action->conf;
10856 port = ethdev->port_id;
10860 MLX5_ASSERT(false);
10861 return rte_flow_error_set(error, EINVAL,
10862 RTE_FLOW_ERROR_TYPE_ACTION, action,
10863 "unknown E-Switch action");
10866 priv = mlx5_port_to_eswitch_info(port, false);
10868 return rte_flow_error_set(error, -rte_errno,
10869 RTE_FLOW_ERROR_TYPE_ACTION,
10871 "No eswitch info was found for port");
10872 #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
10874 * This parameter is transferred to
10875 * mlx5dv_dr_action_create_dest_ib_port().
10877 *dst_port_id = priv->dev_port;
10880 * Legacy mode, no LAG configurations is supported.
10881 * This parameter is transferred to
10882 * mlx5dv_dr_action_create_dest_vport().
10884 *dst_port_id = priv->vport_id;
10890 * Create a counter with aging configuration.
10893 * Pointer to rte_eth_dev structure.
10894 * @param[in] dev_flow
10895 * Pointer to the mlx5_flow.
10896 * @param[out] count
10897 * Pointer to the counter action configuration.
10899 * Pointer to the aging action configuration.
10902 * Index to flow counter on success, 0 otherwise.
10905 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
10906 struct mlx5_flow *dev_flow,
10907 const struct rte_flow_action_count *count
10909 const struct rte_flow_action_age *age)
10912 struct mlx5_age_param *age_param;
10914 counter = flow_dv_counter_alloc(dev, !!age);
10915 if (!counter || age == NULL)
10917 age_param = flow_dv_counter_idx_get_age(dev, counter);
10918 age_param->context = age->context ? age->context :
10919 (void *)(uintptr_t)(dev_flow->flow_idx);
10920 age_param->timeout = age->timeout;
10921 age_param->port_id = dev->data->port_id;
10922 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
10923 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
10928 * Add Tx queue matcher
10931 * Pointer to the dev struct.
10932 * @param[in, out] matcher
10934 * @param[in, out] key
10935 * Flow matcher value.
10937 * Flow pattern to translate.
10939 * Item is inner pattern.
10942 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
10943 void *matcher, void *key,
10944 const struct rte_flow_item *item)
10946 const struct mlx5_rte_flow_item_tx_queue *queue_m;
10947 const struct mlx5_rte_flow_item_tx_queue *queue_v;
10949 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
10951 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10952 struct mlx5_txq_ctrl *txq;
10953 uint32_t queue, mask;
10955 queue_m = (const void *)item->mask;
10956 queue_v = (const void *)item->spec;
10959 txq = mlx5_txq_get(dev, queue_v->queue);
10962 if (txq->type == MLX5_TXQ_TYPE_HAIRPIN)
10963 queue = txq->obj->sq->id;
10965 queue = txq->obj->sq_obj.sq->id;
10966 mask = queue_m == NULL ? UINT32_MAX : queue_m->queue;
10967 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, mask);
10968 MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue & mask);
10969 mlx5_txq_release(dev, queue_v->queue);
10973 * Set the hash fields according to the @p flow information.
10975 * @param[in] dev_flow
10976 * Pointer to the mlx5_flow.
10977 * @param[in] rss_desc
10978 * Pointer to the mlx5_flow_rss_desc.
10981 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
10982 struct mlx5_flow_rss_desc *rss_desc)
10984 uint64_t items = dev_flow->handle->layers;
10986 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
10988 dev_flow->hash_fields = 0;
10989 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
10990 if (rss_desc->level >= 2)
10993 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
10994 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
10995 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
10996 if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
10997 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
10998 else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
10999 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
11001 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
11003 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
11004 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
11005 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
11006 if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
11007 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
11008 else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
11009 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
11011 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
11014 if (dev_flow->hash_fields == 0)
11016 * There is no match between the RSS types and the
11017 * L3 protocol (IPv4/IPv6) defined in the flow rule.
11020 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
11021 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
11022 if (rss_types & RTE_ETH_RSS_UDP) {
11023 if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
11024 dev_flow->hash_fields |=
11025 IBV_RX_HASH_SRC_PORT_UDP;
11026 else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
11027 dev_flow->hash_fields |=
11028 IBV_RX_HASH_DST_PORT_UDP;
11030 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
11032 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
11033 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
11034 if (rss_types & RTE_ETH_RSS_TCP) {
11035 if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
11036 dev_flow->hash_fields |=
11037 IBV_RX_HASH_SRC_PORT_TCP;
11038 else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
11039 dev_flow->hash_fields |=
11040 IBV_RX_HASH_DST_PORT_TCP;
11042 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
11046 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
11050 * Prepare an Rx Hash queue.
11053 * Pointer to Ethernet device.
11054 * @param[in] dev_flow
11055 * Pointer to the mlx5_flow.
11056 * @param[in] rss_desc
11057 * Pointer to the mlx5_flow_rss_desc.
11058 * @param[out] hrxq_idx
11059 * Hash Rx queue index.
11062 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
11064 static struct mlx5_hrxq *
11065 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
11066 struct mlx5_flow *dev_flow,
11067 struct mlx5_flow_rss_desc *rss_desc,
11068 uint32_t *hrxq_idx)
11070 struct mlx5_priv *priv = dev->data->dev_private;
11071 struct mlx5_flow_handle *dh = dev_flow->handle;
11072 struct mlx5_hrxq *hrxq;
11074 MLX5_ASSERT(rss_desc->queue_num);
11075 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
11076 rss_desc->hash_fields = dev_flow->hash_fields;
11077 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
11078 rss_desc->shared_rss = 0;
11079 if (rss_desc->hash_fields == 0)
11080 rss_desc->queue_num = 1;
11081 *hrxq_idx = mlx5_hrxq_get(dev, rss_desc);
11084 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
11090 * Release sample sub action resource.
11092 * @param[in, out] dev
11093 * Pointer to rte_eth_dev structure.
11094 * @param[in] act_res
11095 * Pointer to sample sub action resource.
11098 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
11099 struct mlx5_flow_sub_actions_idx *act_res)
11101 if (act_res->rix_hrxq) {
11102 mlx5_hrxq_release(dev, act_res->rix_hrxq);
11103 act_res->rix_hrxq = 0;
11105 if (act_res->rix_encap_decap) {
11106 flow_dv_encap_decap_resource_release(dev,
11107 act_res->rix_encap_decap);
11108 act_res->rix_encap_decap = 0;
11110 if (act_res->rix_port_id_action) {
11111 flow_dv_port_id_action_resource_release(dev,
11112 act_res->rix_port_id_action);
11113 act_res->rix_port_id_action = 0;
11115 if (act_res->rix_tag) {
11116 flow_dv_tag_release(dev, act_res->rix_tag);
11117 act_res->rix_tag = 0;
11119 if (act_res->rix_jump) {
11120 flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
11121 act_res->rix_jump = 0;
11126 flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
11127 struct mlx5_list_entry *entry, void *cb_ctx)
11129 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11130 struct rte_eth_dev *dev = ctx->dev;
11131 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
11132 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
11136 if (ctx_resource->ratio == resource->ratio &&
11137 ctx_resource->ft_type == resource->ft_type &&
11138 ctx_resource->ft_id == resource->ft_id &&
11139 ctx_resource->set_action == resource->set_action &&
11140 !memcmp((void *)&ctx_resource->sample_act,
11141 (void *)&resource->sample_act,
11142 sizeof(struct mlx5_flow_sub_actions_list))) {
11144 * Existing sample action should release the prepared
11145 * sub-actions reference counter.
11147 flow_dv_sample_sub_actions_release(dev,
11148 &ctx_resource->sample_idx);
11154 struct mlx5_list_entry *
11155 flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11157 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11158 struct rte_eth_dev *dev = ctx->dev;
11159 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
11160 void **sample_dv_actions = ctx_resource->sub_actions;
11161 struct mlx5_flow_dv_sample_resource *resource;
11162 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
11163 struct mlx5_priv *priv = dev->data->dev_private;
11164 struct mlx5_dev_ctx_shared *sh = priv->sh;
11165 struct mlx5_flow_tbl_resource *tbl;
11167 const uint32_t next_ft_step = 1;
11168 uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
11169 uint8_t is_egress = 0;
11170 uint8_t is_transfer = 0;
11171 struct rte_flow_error *error = ctx->error;
11173 /* Register new sample resource. */
11174 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11176 rte_flow_error_set(error, ENOMEM,
11177 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11179 "cannot allocate resource memory");
11182 *resource = *ctx_resource;
11183 /* Create normal path table level */
11184 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11186 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
11188 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
11189 is_egress, is_transfer,
11190 true, NULL, 0, 0, 0, error);
11192 rte_flow_error_set(error, ENOMEM,
11193 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11195 "fail to create normal path table "
11199 resource->normal_path_tbl = tbl;
11200 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
11201 if (!sh->default_miss_action) {
11202 rte_flow_error_set(error, ENOMEM,
11203 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11205 "default miss action was not "
11209 sample_dv_actions[ctx_resource->sample_act.actions_num++] =
11210 sh->default_miss_action;
11212 /* Create a DR sample action */
11213 sampler_attr.sample_ratio = resource->ratio;
11214 sampler_attr.default_next_table = tbl->obj;
11215 sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
11216 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
11217 &sample_dv_actions[0];
11218 sampler_attr.action = resource->set_action;
11219 if (mlx5_os_flow_dr_create_flow_action_sampler
11220 (&sampler_attr, &resource->verbs_action)) {
11221 rte_flow_error_set(error, ENOMEM,
11222 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11223 NULL, "cannot create sample action");
11226 resource->idx = idx;
11227 resource->dev = dev;
11228 return &resource->entry;
11230 if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
11231 flow_dv_sample_sub_actions_release(dev,
11232 &resource->sample_idx);
11233 if (resource->normal_path_tbl)
11234 flow_dv_tbl_resource_release(MLX5_SH(dev),
11235 resource->normal_path_tbl);
11236 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
11241 struct mlx5_list_entry *
11242 flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
11243 struct mlx5_list_entry *entry __rte_unused,
11246 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11247 struct rte_eth_dev *dev = ctx->dev;
11248 struct mlx5_flow_dv_sample_resource *resource;
11249 struct mlx5_priv *priv = dev->data->dev_private;
11250 struct mlx5_dev_ctx_shared *sh = priv->sh;
11253 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11255 rte_flow_error_set(ctx->error, ENOMEM,
11256 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11258 "cannot allocate resource memory");
11261 memcpy(resource, entry, sizeof(*resource));
11262 resource->idx = idx;
11263 resource->dev = dev;
11264 return &resource->entry;
11268 flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
11269 struct mlx5_list_entry *entry)
11271 struct mlx5_flow_dv_sample_resource *resource =
11272 container_of(entry, typeof(*resource), entry);
11273 struct rte_eth_dev *dev = resource->dev;
11274 struct mlx5_priv *priv = dev->data->dev_private;
11276 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
11280 * Find existing sample resource or create and register a new one.
11282 * @param[in, out] dev
11283 * Pointer to rte_eth_dev structure.
11285 * Pointer to sample resource reference.
11286 * @parm[in, out] dev_flow
11287 * Pointer to the dev_flow.
11288 * @param[out] error
11289 * pointer to error structure.
11292 * 0 on success otherwise -errno and errno is set.
11295 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
11296 struct mlx5_flow_dv_sample_resource *ref,
11297 struct mlx5_flow *dev_flow,
11298 struct rte_flow_error *error)
11300 struct mlx5_flow_dv_sample_resource *resource;
11301 struct mlx5_list_entry *entry;
11302 struct mlx5_priv *priv = dev->data->dev_private;
11303 struct mlx5_flow_cb_ctx ctx = {
11309 entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
11312 resource = container_of(entry, typeof(*resource), entry);
11313 dev_flow->handle->dvh.rix_sample = resource->idx;
11314 dev_flow->dv.sample_res = resource;
11319 flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
11320 struct mlx5_list_entry *entry, void *cb_ctx)
11322 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11323 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11324 struct rte_eth_dev *dev = ctx->dev;
11325 struct mlx5_flow_dv_dest_array_resource *resource =
11326 container_of(entry, typeof(*resource), entry);
11329 if (ctx_resource->num_of_dest == resource->num_of_dest &&
11330 ctx_resource->ft_type == resource->ft_type &&
11331 !memcmp((void *)resource->sample_act,
11332 (void *)ctx_resource->sample_act,
11333 (ctx_resource->num_of_dest *
11334 sizeof(struct mlx5_flow_sub_actions_list)))) {
11336 * Existing sample action should release the prepared
11337 * sub-actions reference counter.
11339 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11340 flow_dv_sample_sub_actions_release(dev,
11341 &ctx_resource->sample_idx[idx]);
11347 struct mlx5_list_entry *
11348 flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11350 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11351 struct rte_eth_dev *dev = ctx->dev;
11352 struct mlx5_flow_dv_dest_array_resource *resource;
11353 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11354 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
11355 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
11356 struct mlx5_priv *priv = dev->data->dev_private;
11357 struct mlx5_dev_ctx_shared *sh = priv->sh;
11358 struct mlx5_flow_sub_actions_list *sample_act;
11359 struct mlx5dv_dr_domain *domain;
11360 uint32_t idx = 0, res_idx = 0;
11361 struct rte_flow_error *error = ctx->error;
11362 uint64_t action_flags;
11365 /* Register new destination array resource. */
11366 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11369 rte_flow_error_set(error, ENOMEM,
11370 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11372 "cannot allocate resource memory");
11375 *resource = *ctx_resource;
11376 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11377 domain = sh->fdb_domain;
11378 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
11379 domain = sh->rx_domain;
11381 domain = sh->tx_domain;
11382 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11383 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
11384 mlx5_malloc(MLX5_MEM_ZERO,
11385 sizeof(struct mlx5dv_dr_action_dest_attr),
11387 if (!dest_attr[idx]) {
11388 rte_flow_error_set(error, ENOMEM,
11389 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11391 "cannot allocate resource memory");
11394 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
11395 sample_act = &ctx_resource->sample_act[idx];
11396 action_flags = sample_act->action_flags;
11397 switch (action_flags) {
11398 case MLX5_FLOW_ACTION_QUEUE:
11399 dest_attr[idx]->dest = sample_act->dr_queue_action;
11401 case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
11402 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
11403 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
11404 dest_attr[idx]->dest_reformat->reformat =
11405 sample_act->dr_encap_action;
11406 dest_attr[idx]->dest_reformat->dest =
11407 sample_act->dr_port_id_action;
11409 case MLX5_FLOW_ACTION_PORT_ID:
11410 dest_attr[idx]->dest = sample_act->dr_port_id_action;
11412 case MLX5_FLOW_ACTION_JUMP:
11413 dest_attr[idx]->dest = sample_act->dr_jump_action;
11416 rte_flow_error_set(error, EINVAL,
11417 RTE_FLOW_ERROR_TYPE_ACTION,
11419 "unsupported actions type");
11423 /* create a dest array action */
11424 ret = mlx5_os_flow_dr_create_flow_action_dest_array
11426 resource->num_of_dest,
11428 &resource->action);
11430 rte_flow_error_set(error, ENOMEM,
11431 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11433 "cannot create destination array action");
11436 resource->idx = res_idx;
11437 resource->dev = dev;
11438 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11439 mlx5_free(dest_attr[idx]);
11440 return &resource->entry;
11442 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11443 flow_dv_sample_sub_actions_release(dev,
11444 &resource->sample_idx[idx]);
11445 if (dest_attr[idx])
11446 mlx5_free(dest_attr[idx]);
11448 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
11452 struct mlx5_list_entry *
11453 flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
11454 struct mlx5_list_entry *entry __rte_unused,
11457 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11458 struct rte_eth_dev *dev = ctx->dev;
11459 struct mlx5_flow_dv_dest_array_resource *resource;
11460 struct mlx5_priv *priv = dev->data->dev_private;
11461 struct mlx5_dev_ctx_shared *sh = priv->sh;
11462 uint32_t res_idx = 0;
11463 struct rte_flow_error *error = ctx->error;
11465 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11468 rte_flow_error_set(error, ENOMEM,
11469 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11471 "cannot allocate dest-array memory");
11474 memcpy(resource, entry, sizeof(*resource));
11475 resource->idx = res_idx;
11476 resource->dev = dev;
11477 return &resource->entry;
11481 flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
11482 struct mlx5_list_entry *entry)
11484 struct mlx5_flow_dv_dest_array_resource *resource =
11485 container_of(entry, typeof(*resource), entry);
11486 struct rte_eth_dev *dev = resource->dev;
11487 struct mlx5_priv *priv = dev->data->dev_private;
11489 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
11493 * Find existing destination array resource or create and register a new one.
11495 * @param[in, out] dev
11496 * Pointer to rte_eth_dev structure.
11498 * Pointer to destination array resource reference.
11499 * @parm[in, out] dev_flow
11500 * Pointer to the dev_flow.
11501 * @param[out] error
11502 * pointer to error structure.
11505 * 0 on success otherwise -errno and errno is set.
11508 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
11509 struct mlx5_flow_dv_dest_array_resource *ref,
11510 struct mlx5_flow *dev_flow,
11511 struct rte_flow_error *error)
11513 struct mlx5_flow_dv_dest_array_resource *resource;
11514 struct mlx5_priv *priv = dev->data->dev_private;
11515 struct mlx5_list_entry *entry;
11516 struct mlx5_flow_cb_ctx ctx = {
11522 entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
11525 resource = container_of(entry, typeof(*resource), entry);
11526 dev_flow->handle->dvh.rix_dest_array = resource->idx;
11527 dev_flow->dv.dest_array_res = resource;
11532 * Convert Sample action to DV specification.
11535 * Pointer to rte_eth_dev structure.
11536 * @param[in] action
11537 * Pointer to sample action structure.
11538 * @param[in, out] dev_flow
11539 * Pointer to the mlx5_flow.
11541 * Pointer to the flow attributes.
11542 * @param[in, out] num_of_dest
11543 * Pointer to the num of destination.
11544 * @param[in, out] sample_actions
11545 * Pointer to sample actions list.
11546 * @param[in, out] res
11547 * Pointer to sample resource.
11548 * @param[out] error
11549 * Pointer to the error structure.
11552 * 0 on success, a negative errno value otherwise and rte_errno is set.
11555 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
11556 const struct rte_flow_action_sample *action,
11557 struct mlx5_flow *dev_flow,
11558 const struct rte_flow_attr *attr,
11559 uint32_t *num_of_dest,
11560 void **sample_actions,
11561 struct mlx5_flow_dv_sample_resource *res,
11562 struct rte_flow_error *error)
11564 struct mlx5_priv *priv = dev->data->dev_private;
11565 const struct rte_flow_action *sub_actions;
11566 struct mlx5_flow_sub_actions_list *sample_act;
11567 struct mlx5_flow_sub_actions_idx *sample_idx;
11568 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11569 struct rte_flow *flow = dev_flow->flow;
11570 struct mlx5_flow_rss_desc *rss_desc;
11571 uint64_t action_flags = 0;
11574 rss_desc = &wks->rss_desc;
11575 sample_act = &res->sample_act;
11576 sample_idx = &res->sample_idx;
11577 res->ratio = action->ratio;
11578 sub_actions = action->actions;
11579 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
11580 int type = sub_actions->type;
11581 uint32_t pre_rix = 0;
11584 case RTE_FLOW_ACTION_TYPE_QUEUE:
11586 const struct rte_flow_action_queue *queue;
11587 struct mlx5_hrxq *hrxq;
11590 queue = sub_actions->conf;
11591 rss_desc->queue_num = 1;
11592 rss_desc->queue[0] = queue->index;
11593 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11594 rss_desc, &hrxq_idx);
11596 return rte_flow_error_set
11598 RTE_FLOW_ERROR_TYPE_ACTION,
11600 "cannot create fate queue");
11601 sample_act->dr_queue_action = hrxq->action;
11602 sample_idx->rix_hrxq = hrxq_idx;
11603 sample_actions[sample_act->actions_num++] =
11606 action_flags |= MLX5_FLOW_ACTION_QUEUE;
11607 if (action_flags & MLX5_FLOW_ACTION_MARK)
11608 dev_flow->handle->rix_hrxq = hrxq_idx;
11609 dev_flow->handle->fate_action =
11610 MLX5_FLOW_FATE_QUEUE;
11613 case RTE_FLOW_ACTION_TYPE_RSS:
11615 struct mlx5_hrxq *hrxq;
11617 const struct rte_flow_action_rss *rss;
11618 const uint8_t *rss_key;
11620 rss = sub_actions->conf;
11621 memcpy(rss_desc->queue, rss->queue,
11622 rss->queue_num * sizeof(uint16_t));
11623 rss_desc->queue_num = rss->queue_num;
11624 /* NULL RSS key indicates default RSS key. */
11625 rss_key = !rss->key ? rss_hash_default_key : rss->key;
11626 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
11628 * rss->level and rss.types should be set in advance
11629 * when expanding items for RSS.
11631 flow_dv_hashfields_set(dev_flow, rss_desc);
11632 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11633 rss_desc, &hrxq_idx);
11635 return rte_flow_error_set
11637 RTE_FLOW_ERROR_TYPE_ACTION,
11639 "cannot create fate queue");
11640 sample_act->dr_queue_action = hrxq->action;
11641 sample_idx->rix_hrxq = hrxq_idx;
11642 sample_actions[sample_act->actions_num++] =
11645 action_flags |= MLX5_FLOW_ACTION_RSS;
11646 if (action_flags & MLX5_FLOW_ACTION_MARK)
11647 dev_flow->handle->rix_hrxq = hrxq_idx;
11648 dev_flow->handle->fate_action =
11649 MLX5_FLOW_FATE_QUEUE;
11652 case RTE_FLOW_ACTION_TYPE_MARK:
11654 uint32_t tag_be = mlx5_flow_mark_set
11655 (((const struct rte_flow_action_mark *)
11656 (sub_actions->conf))->id);
11659 pre_rix = dev_flow->handle->dvh.rix_tag;
11660 /* Save the mark resource before sample */
11661 pre_r = dev_flow->dv.tag_resource;
11662 if (flow_dv_tag_resource_register(dev, tag_be,
11665 MLX5_ASSERT(dev_flow->dv.tag_resource);
11666 sample_act->dr_tag_action =
11667 dev_flow->dv.tag_resource->action;
11668 sample_idx->rix_tag =
11669 dev_flow->handle->dvh.rix_tag;
11670 sample_actions[sample_act->actions_num++] =
11671 sample_act->dr_tag_action;
11672 /* Recover the mark resource after sample */
11673 dev_flow->dv.tag_resource = pre_r;
11674 dev_flow->handle->dvh.rix_tag = pre_rix;
11675 action_flags |= MLX5_FLOW_ACTION_MARK;
11678 case RTE_FLOW_ACTION_TYPE_COUNT:
11680 if (!flow->counter) {
11682 flow_dv_translate_create_counter(dev,
11683 dev_flow, sub_actions->conf,
11685 if (!flow->counter)
11686 return rte_flow_error_set
11688 RTE_FLOW_ERROR_TYPE_ACTION,
11690 "cannot create counter"
11693 sample_act->dr_cnt_action =
11694 (flow_dv_counter_get_by_idx(dev,
11695 flow->counter, NULL))->action;
11696 sample_actions[sample_act->actions_num++] =
11697 sample_act->dr_cnt_action;
11698 action_flags |= MLX5_FLOW_ACTION_COUNT;
11701 case RTE_FLOW_ACTION_TYPE_PORT_ID:
11702 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
11704 struct mlx5_flow_dv_port_id_action_resource
11706 uint32_t port_id = 0;
11708 memset(&port_id_resource, 0, sizeof(port_id_resource));
11709 /* Save the port id resource before sample */
11710 pre_rix = dev_flow->handle->rix_port_id_action;
11711 pre_r = dev_flow->dv.port_id_action;
11712 if (flow_dv_translate_action_port_id(dev, sub_actions,
11715 port_id_resource.port_id = port_id;
11716 if (flow_dv_port_id_action_resource_register
11717 (dev, &port_id_resource, dev_flow, error))
11719 sample_act->dr_port_id_action =
11720 dev_flow->dv.port_id_action->action;
11721 sample_idx->rix_port_id_action =
11722 dev_flow->handle->rix_port_id_action;
11723 sample_actions[sample_act->actions_num++] =
11724 sample_act->dr_port_id_action;
11725 /* Recover the port id resource after sample */
11726 dev_flow->dv.port_id_action = pre_r;
11727 dev_flow->handle->rix_port_id_action = pre_rix;
11729 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
11732 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11733 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11734 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11735 /* Save the encap resource before sample */
11736 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
11737 pre_r = dev_flow->dv.encap_decap;
11738 if (flow_dv_create_action_l2_encap(dev, sub_actions,
11743 sample_act->dr_encap_action =
11744 dev_flow->dv.encap_decap->action;
11745 sample_idx->rix_encap_decap =
11746 dev_flow->handle->dvh.rix_encap_decap;
11747 sample_actions[sample_act->actions_num++] =
11748 sample_act->dr_encap_action;
11749 /* Recover the encap resource after sample */
11750 dev_flow->dv.encap_decap = pre_r;
11751 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
11752 action_flags |= MLX5_FLOW_ACTION_ENCAP;
11755 return rte_flow_error_set(error, EINVAL,
11756 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11758 "Not support for sampler action");
11761 sample_act->action_flags = action_flags;
11762 res->ft_id = dev_flow->dv.group;
11763 if (attr->transfer) {
11765 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
11766 uint64_t set_action;
11767 } action_ctx = { .set_action = 0 };
11769 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
11770 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
11771 MLX5_MODIFICATION_TYPE_SET);
11772 MLX5_SET(set_action_in, action_ctx.action_in, field,
11773 MLX5_MODI_META_REG_C_0);
11774 MLX5_SET(set_action_in, action_ctx.action_in, data,
11775 priv->vport_meta_tag);
11776 res->set_action = action_ctx.set_action;
11777 } else if (attr->ingress) {
11778 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
11780 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
11786 * Convert Sample action to DV specification.
11789 * Pointer to rte_eth_dev structure.
11790 * @param[in, out] dev_flow
11791 * Pointer to the mlx5_flow.
11792 * @param[in] num_of_dest
11793 * The num of destination.
11794 * @param[in, out] res
11795 * Pointer to sample resource.
11796 * @param[in, out] mdest_res
11797 * Pointer to destination array resource.
11798 * @param[in] sample_actions
11799 * Pointer to sample path actions list.
11800 * @param[in] action_flags
11801 * Holds the actions detected until now.
11802 * @param[out] error
11803 * Pointer to the error structure.
11806 * 0 on success, a negative errno value otherwise and rte_errno is set.
11809 flow_dv_create_action_sample(struct rte_eth_dev *dev,
11810 struct mlx5_flow *dev_flow,
11811 uint32_t num_of_dest,
11812 struct mlx5_flow_dv_sample_resource *res,
11813 struct mlx5_flow_dv_dest_array_resource *mdest_res,
11814 void **sample_actions,
11815 uint64_t action_flags,
11816 struct rte_flow_error *error)
11818 /* update normal path action resource into last index of array */
11819 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
11820 struct mlx5_flow_sub_actions_list *sample_act =
11821 &mdest_res->sample_act[dest_index];
11822 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11823 struct mlx5_flow_rss_desc *rss_desc;
11824 uint32_t normal_idx = 0;
11825 struct mlx5_hrxq *hrxq;
11829 rss_desc = &wks->rss_desc;
11830 if (num_of_dest > 1) {
11831 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
11832 /* Handle QP action for mirroring */
11833 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11834 rss_desc, &hrxq_idx);
11836 return rte_flow_error_set
11838 RTE_FLOW_ERROR_TYPE_ACTION,
11840 "cannot create rx queue");
11842 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
11843 sample_act->dr_queue_action = hrxq->action;
11844 if (action_flags & MLX5_FLOW_ACTION_MARK)
11845 dev_flow->handle->rix_hrxq = hrxq_idx;
11846 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
11848 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
11850 mdest_res->sample_idx[dest_index].rix_encap_decap =
11851 dev_flow->handle->dvh.rix_encap_decap;
11852 sample_act->dr_encap_action =
11853 dev_flow->dv.encap_decap->action;
11854 dev_flow->handle->dvh.rix_encap_decap = 0;
11856 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
11858 mdest_res->sample_idx[dest_index].rix_port_id_action =
11859 dev_flow->handle->rix_port_id_action;
11860 sample_act->dr_port_id_action =
11861 dev_flow->dv.port_id_action->action;
11862 dev_flow->handle->rix_port_id_action = 0;
11864 if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
11866 mdest_res->sample_idx[dest_index].rix_jump =
11867 dev_flow->handle->rix_jump;
11868 sample_act->dr_jump_action =
11869 dev_flow->dv.jump->action;
11870 dev_flow->handle->rix_jump = 0;
11872 sample_act->actions_num = normal_idx;
11873 /* update sample action resource into first index of array */
11874 mdest_res->ft_type = res->ft_type;
11875 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
11876 sizeof(struct mlx5_flow_sub_actions_idx));
11877 memcpy(&mdest_res->sample_act[0], &res->sample_act,
11878 sizeof(struct mlx5_flow_sub_actions_list));
11879 mdest_res->num_of_dest = num_of_dest;
11880 if (flow_dv_dest_array_resource_register(dev, mdest_res,
11882 return rte_flow_error_set(error, EINVAL,
11883 RTE_FLOW_ERROR_TYPE_ACTION,
11884 NULL, "can't create sample "
11887 res->sub_actions = sample_actions;
11888 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
11889 return rte_flow_error_set(error, EINVAL,
11890 RTE_FLOW_ERROR_TYPE_ACTION,
11892 "can't create sample action");
11898 * Remove an ASO age action from age actions list.
11901 * Pointer to the Ethernet device structure.
11903 * Pointer to the aso age action handler.
11906 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
11907 struct mlx5_aso_age_action *age)
11909 struct mlx5_age_info *age_info;
11910 struct mlx5_age_param *age_param = &age->age_params;
11911 struct mlx5_priv *priv = dev->data->dev_private;
11912 uint16_t expected = AGE_CANDIDATE;
11914 age_info = GET_PORT_AGE_INFO(priv);
11915 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
11916 AGE_FREE, false, __ATOMIC_RELAXED,
11917 __ATOMIC_RELAXED)) {
11919 * We need the lock even it is age timeout,
11920 * since age action may still in process.
11922 rte_spinlock_lock(&age_info->aged_sl);
11923 LIST_REMOVE(age, next);
11924 rte_spinlock_unlock(&age_info->aged_sl);
11925 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
11930 * Release an ASO age action.
11933 * Pointer to the Ethernet device structure.
11934 * @param[in] age_idx
11935 * Index of ASO age action to release.
11937 * True if the release operation is during flow destroy operation.
11938 * False if the release operation is during action destroy operation.
11941 * 0 when age action was removed, otherwise the number of references.
11944 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
11946 struct mlx5_priv *priv = dev->data->dev_private;
11947 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11948 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
11949 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
11952 flow_dv_aso_age_remove_from_age(dev, age);
11953 rte_spinlock_lock(&mng->free_sl);
11954 LIST_INSERT_HEAD(&mng->free, age, next);
11955 rte_spinlock_unlock(&mng->free_sl);
11961 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
11964 * Pointer to the Ethernet device structure.
11967 * 0 on success, otherwise negative errno value and rte_errno is set.
11970 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
11972 struct mlx5_priv *priv = dev->data->dev_private;
11973 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11974 void *old_pools = mng->pools;
11975 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
11976 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
11977 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11980 rte_errno = ENOMEM;
11984 memcpy(pools, old_pools,
11985 mng->n * sizeof(struct mlx5_flow_counter_pool *));
11986 mlx5_free(old_pools);
11988 /* First ASO flow hit allocation - starting ASO data-path. */
11989 int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
11997 mng->pools = pools;
12002 * Create and initialize a new ASO aging pool.
12005 * Pointer to the Ethernet device structure.
12006 * @param[out] age_free
12007 * Where to put the pointer of a new age action.
12010 * The age actions pool pointer and @p age_free is set on success,
12011 * NULL otherwise and rte_errno is set.
12013 static struct mlx5_aso_age_pool *
12014 flow_dv_age_pool_create(struct rte_eth_dev *dev,
12015 struct mlx5_aso_age_action **age_free)
12017 struct mlx5_priv *priv = dev->data->dev_private;
12018 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12019 struct mlx5_aso_age_pool *pool = NULL;
12020 struct mlx5_devx_obj *obj = NULL;
12023 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
12024 priv->sh->cdev->pdn);
12026 rte_errno = ENODATA;
12027 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
12030 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
12032 claim_zero(mlx5_devx_cmd_destroy(obj));
12033 rte_errno = ENOMEM;
12036 pool->flow_hit_aso_obj = obj;
12037 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
12038 rte_rwlock_write_lock(&mng->resize_rwl);
12039 pool->index = mng->next;
12040 /* Resize pools array if there is no room for the new pool in it. */
12041 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
12042 claim_zero(mlx5_devx_cmd_destroy(obj));
12044 rte_rwlock_write_unlock(&mng->resize_rwl);
12047 mng->pools[pool->index] = pool;
12049 rte_rwlock_write_unlock(&mng->resize_rwl);
12050 /* Assign the first action in the new pool, the rest go to free list. */
12051 *age_free = &pool->actions[0];
12052 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
12053 pool->actions[i].offset = i;
12054 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
12060 * Allocate a ASO aging bit.
12063 * Pointer to the Ethernet device structure.
12064 * @param[out] error
12065 * Pointer to the error structure.
12068 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
12071 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
12073 struct mlx5_priv *priv = dev->data->dev_private;
12074 const struct mlx5_aso_age_pool *pool;
12075 struct mlx5_aso_age_action *age_free = NULL;
12076 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12079 /* Try to get the next free age action bit. */
12080 rte_spinlock_lock(&mng->free_sl);
12081 age_free = LIST_FIRST(&mng->free);
12083 LIST_REMOVE(age_free, next);
12084 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
12085 rte_spinlock_unlock(&mng->free_sl);
12086 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
12087 NULL, "failed to create ASO age pool");
12088 return 0; /* 0 is an error. */
12090 rte_spinlock_unlock(&mng->free_sl);
12091 pool = container_of
12092 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
12093 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
12095 if (!age_free->dr_action) {
12096 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
12100 rte_flow_error_set(error, rte_errno,
12101 RTE_FLOW_ERROR_TYPE_ACTION,
12102 NULL, "failed to get reg_c "
12103 "for ASO flow hit");
12104 return 0; /* 0 is an error. */
12106 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
12107 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
12108 (priv->sh->rx_domain,
12109 pool->flow_hit_aso_obj->obj, age_free->offset,
12110 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
12111 (reg_c - REG_C_0));
12112 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
12113 if (!age_free->dr_action) {
12115 rte_spinlock_lock(&mng->free_sl);
12116 LIST_INSERT_HEAD(&mng->free, age_free, next);
12117 rte_spinlock_unlock(&mng->free_sl);
12118 rte_flow_error_set(error, rte_errno,
12119 RTE_FLOW_ERROR_TYPE_ACTION,
12120 NULL, "failed to create ASO "
12121 "flow hit action");
12122 return 0; /* 0 is an error. */
12125 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
12126 return pool->index | ((age_free->offset + 1) << 16);
12130 * Initialize flow ASO age parameters.
12133 * Pointer to rte_eth_dev structure.
12134 * @param[in] age_idx
12135 * Index of ASO age action.
12136 * @param[in] context
12137 * Pointer to flow counter age context.
12138 * @param[in] timeout
12139 * Aging timeout in seconds.
12143 flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
12148 struct mlx5_aso_age_action *aso_age;
12150 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
12151 MLX5_ASSERT(aso_age);
12152 aso_age->age_params.context = context;
12153 aso_age->age_params.timeout = timeout;
12154 aso_age->age_params.port_id = dev->data->port_id;
12155 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
12157 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
12162 flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
12163 const struct rte_flow_item_integrity *value,
12164 void *headers_m, void *headers_v)
12167 /* RTE l4_ok filter aggregates hardware l4_ok and
12168 * l4_checksum_ok filters.
12169 * Positive RTE l4_ok match requires hardware match on both L4
12170 * hardware integrity bits.
12171 * For negative match, check hardware l4_checksum_ok bit only,
12172 * because hardware sets that bit to 0 for all packets
12175 if (value->l4_ok) {
12176 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_ok, 1);
12177 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_ok, 1);
12179 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok, 1);
12180 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_checksum_ok,
12183 if (mask->l4_csum_ok) {
12184 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok, 1);
12185 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_checksum_ok,
12186 value->l4_csum_ok);
12191 flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
12192 const struct rte_flow_item_integrity *value,
12193 void *headers_m, void *headers_v, bool is_ipv4)
12196 /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
12197 * ipv4_csum_ok filters.
12198 * Positive RTE l3_ok match requires hardware match on both L3
12199 * hardware integrity bits.
12200 * For negative match, check hardware l3_csum_ok bit only,
12201 * because hardware sets that bit to 0 for all packets
12205 if (value->l3_ok) {
12206 MLX5_SET(fte_match_set_lyr_2_4, headers_m,
12208 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12211 MLX5_SET(fte_match_set_lyr_2_4, headers_m,
12212 ipv4_checksum_ok, 1);
12213 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12214 ipv4_checksum_ok, !!value->l3_ok);
12216 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l3_ok, 1);
12217 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l3_ok,
12221 if (mask->ipv4_csum_ok) {
12222 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok, 1);
12223 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
12224 value->ipv4_csum_ok);
12229 set_integrity_bits(void *headers_m, void *headers_v,
12230 const struct rte_flow_item *integrity_item, bool is_l3_ip4)
12232 const struct rte_flow_item_integrity *spec = integrity_item->spec;
12233 const struct rte_flow_item_integrity *mask = integrity_item->mask;
12235 /* Integrity bits validation cleared spec pointer */
12236 MLX5_ASSERT(spec != NULL);
12238 mask = &rte_flow_item_integrity_mask;
12239 flow_dv_translate_integrity_l3(mask, spec, headers_m, headers_v,
12241 flow_dv_translate_integrity_l4(mask, spec, headers_m, headers_v);
12245 flow_dv_translate_item_integrity_post(void *matcher, void *key,
12247 struct rte_flow_item *integrity_items[2],
12248 uint64_t pattern_flags)
12250 void *headers_m, *headers_v;
12253 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
12254 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12256 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
12257 is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
12259 set_integrity_bits(headers_m, headers_v,
12260 integrity_items[1], is_l3_ip4);
12262 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
12263 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12265 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
12266 is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
12268 set_integrity_bits(headers_m, headers_v,
12269 integrity_items[0], is_l3_ip4);
12274 flow_dv_translate_item_integrity(const struct rte_flow_item *item,
12275 const struct rte_flow_item *integrity_items[2],
12276 uint64_t *last_item)
12278 const struct rte_flow_item_integrity *spec = (typeof(spec))item->spec;
12280 /* integrity bits validation cleared spec pointer */
12281 MLX5_ASSERT(spec != NULL);
12282 if (spec->level > 1) {
12283 integrity_items[1] = item;
12284 *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
12286 integrity_items[0] = item;
12287 *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
12292 * Prepares DV flow counter with aging configuration.
12293 * Gets it by index when exists, creates a new one when doesn't.
12296 * Pointer to rte_eth_dev structure.
12297 * @param[in] dev_flow
12298 * Pointer to the mlx5_flow.
12299 * @param[in, out] flow
12300 * Pointer to the sub flow.
12302 * Pointer to the counter action configuration.
12304 * Pointer to the aging action configuration.
12305 * @param[out] error
12306 * Pointer to the error structure.
12309 * Pointer to the counter, NULL otherwise.
12311 static struct mlx5_flow_counter *
12312 flow_dv_prepare_counter(struct rte_eth_dev *dev,
12313 struct mlx5_flow *dev_flow,
12314 struct rte_flow *flow,
12315 const struct rte_flow_action_count *count,
12316 const struct rte_flow_action_age *age,
12317 struct rte_flow_error *error)
12319 if (!flow->counter) {
12320 flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
12322 if (!flow->counter) {
12323 rte_flow_error_set(error, rte_errno,
12324 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12325 "cannot create counter object.");
12329 return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
12333 * Release an ASO CT action by its own device.
12336 * Pointer to the Ethernet device structure.
12338 * Index of ASO CT action to release.
12341 * 0 when CT action was removed, otherwise the number of references.
12344 flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
12346 struct mlx5_priv *priv = dev->data->dev_private;
12347 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12349 struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12350 enum mlx5_aso_ct_state state =
12351 __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
12353 /* Cannot release when CT is in the ASO SQ. */
12354 if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
12356 ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
12358 if (ct->dr_action_orig) {
12359 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12360 claim_zero(mlx5_glue->destroy_flow_action
12361 (ct->dr_action_orig));
12363 ct->dr_action_orig = NULL;
12365 if (ct->dr_action_rply) {
12366 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12367 claim_zero(mlx5_glue->destroy_flow_action
12368 (ct->dr_action_rply));
12370 ct->dr_action_rply = NULL;
12372 /* Clear the state to free, no need in 1st allocation. */
12373 MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
12374 rte_spinlock_lock(&mng->ct_sl);
12375 LIST_INSERT_HEAD(&mng->free_cts, ct, next);
12376 rte_spinlock_unlock(&mng->ct_sl);
12382 flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
12383 struct rte_flow_error *error)
12385 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
12386 uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
12387 struct rte_eth_dev *owndev = &rte_eth_devices[owner];
12390 MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
12391 if (dev->data->dev_started != 1)
12392 return rte_flow_error_set(error, EAGAIN,
12393 RTE_FLOW_ERROR_TYPE_ACTION,
12395 "Indirect CT action cannot be destroyed when the port is stopped");
12396 ret = flow_dv_aso_ct_dev_release(owndev, idx);
12398 return rte_flow_error_set(error, EAGAIN,
12399 RTE_FLOW_ERROR_TYPE_ACTION,
12401 "Current state prevents indirect CT action from being destroyed");
12406 * Resize the ASO CT pools array by 64 pools.
12409 * Pointer to the Ethernet device structure.
12412 * 0 on success, otherwise negative errno value and rte_errno is set.
12415 flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
12417 struct mlx5_priv *priv = dev->data->dev_private;
12418 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12419 void *old_pools = mng->pools;
12420 /* Magic number now, need a macro. */
12421 uint32_t resize = mng->n + 64;
12422 uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
12423 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
12426 rte_errno = ENOMEM;
12429 rte_rwlock_write_lock(&mng->resize_rwl);
12430 /* ASO SQ/QP was already initialized in the startup. */
12432 /* Realloc could be an alternative choice. */
12433 rte_memcpy(pools, old_pools,
12434 mng->n * sizeof(struct mlx5_aso_ct_pool *));
12435 mlx5_free(old_pools);
12438 mng->pools = pools;
12439 rte_rwlock_write_unlock(&mng->resize_rwl);
12444 * Create and initialize a new ASO CT pool.
12447 * Pointer to the Ethernet device structure.
12448 * @param[out] ct_free
12449 * Where to put the pointer of a new CT action.
12452 * The CT actions pool pointer and @p ct_free is set on success,
12453 * NULL otherwise and rte_errno is set.
12455 static struct mlx5_aso_ct_pool *
12456 flow_dv_ct_pool_create(struct rte_eth_dev *dev,
12457 struct mlx5_aso_ct_action **ct_free)
12459 struct mlx5_priv *priv = dev->data->dev_private;
12460 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12461 struct mlx5_aso_ct_pool *pool = NULL;
12462 struct mlx5_devx_obj *obj = NULL;
12464 uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
12466 obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
12467 priv->sh->cdev->pdn,
12470 rte_errno = ENODATA;
12471 DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
12474 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
12476 rte_errno = ENOMEM;
12477 claim_zero(mlx5_devx_cmd_destroy(obj));
12480 pool->devx_obj = obj;
12481 pool->index = mng->next;
12482 /* Resize pools array if there is no room for the new pool in it. */
12483 if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
12484 claim_zero(mlx5_devx_cmd_destroy(obj));
12488 mng->pools[pool->index] = pool;
12490 /* Assign the first action in the new pool, the rest go to free list. */
12491 *ct_free = &pool->actions[0];
12492 /* Lock outside, the list operation is safe here. */
12493 for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
12494 /* refcnt is 0 when allocating the memory. */
12495 pool->actions[i].offset = i;
12496 LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
12502 * Allocate a ASO CT action from free list.
12505 * Pointer to the Ethernet device structure.
12506 * @param[out] error
12507 * Pointer to the error structure.
12510 * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
12513 flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
12515 struct mlx5_priv *priv = dev->data->dev_private;
12516 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12517 struct mlx5_aso_ct_action *ct = NULL;
12518 struct mlx5_aso_ct_pool *pool;
12523 if (!priv->sh->devx) {
12524 rte_errno = ENOTSUP;
12527 /* Get a free CT action, if no, a new pool will be created. */
12528 rte_spinlock_lock(&mng->ct_sl);
12529 ct = LIST_FIRST(&mng->free_cts);
12531 LIST_REMOVE(ct, next);
12532 } else if (!flow_dv_ct_pool_create(dev, &ct)) {
12533 rte_spinlock_unlock(&mng->ct_sl);
12534 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
12535 NULL, "failed to create ASO CT pool");
12538 rte_spinlock_unlock(&mng->ct_sl);
12539 pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
12540 ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
12541 /* 0: inactive, 1: created, 2+: used by flows. */
12542 __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
12543 reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
12544 if (!ct->dr_action_orig) {
12545 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12546 ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
12547 (priv->sh->rx_domain, pool->devx_obj->obj,
12549 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
12552 RTE_SET_USED(reg_c);
12554 if (!ct->dr_action_orig) {
12555 flow_dv_aso_ct_dev_release(dev, ct_idx);
12556 rte_flow_error_set(error, rte_errno,
12557 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12558 "failed to create ASO CT action");
12562 if (!ct->dr_action_rply) {
12563 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12564 ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
12565 (priv->sh->rx_domain, pool->devx_obj->obj,
12567 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
12570 if (!ct->dr_action_rply) {
12571 flow_dv_aso_ct_dev_release(dev, ct_idx);
12572 rte_flow_error_set(error, rte_errno,
12573 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12574 "failed to create ASO CT action");
12582 * Create a conntrack object with context and actions by using ASO mechanism.
12585 * Pointer to rte_eth_dev structure.
12587 * Pointer to conntrack information profile.
12588 * @param[out] error
12589 * Pointer to the error structure.
12592 * Index to conntrack object on success, 0 otherwise.
12595 flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
12596 const struct rte_flow_action_conntrack *pro,
12597 struct rte_flow_error *error)
12599 struct mlx5_priv *priv = dev->data->dev_private;
12600 struct mlx5_dev_ctx_shared *sh = priv->sh;
12601 struct mlx5_aso_ct_action *ct;
12604 if (!sh->ct_aso_en)
12605 return rte_flow_error_set(error, ENOTSUP,
12606 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12607 "Connection is not supported");
12608 idx = flow_dv_aso_ct_alloc(dev, error);
12610 return rte_flow_error_set(error, rte_errno,
12611 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12612 "Failed to allocate CT object");
12613 ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12614 if (mlx5_aso_ct_update_by_wqe(sh, ct, pro))
12615 return rte_flow_error_set(error, EBUSY,
12616 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12617 "Failed to update CT");
12618 ct->is_original = !!pro->is_original_dir;
12619 ct->peer = pro->peer_port;
12624 * Fill the flow with DV spec, lock free
12625 * (mutex should be acquired by caller).
12628 * Pointer to rte_eth_dev structure.
12629 * @param[in, out] dev_flow
12630 * Pointer to the sub flow.
12632 * Pointer to the flow attributes.
12634 * Pointer to the list of items.
12635 * @param[in] actions
12636 * Pointer to the list of actions.
12637 * @param[out] error
12638 * Pointer to the error structure.
12641 * 0 on success, a negative errno value otherwise and rte_errno is set.
12644 flow_dv_translate(struct rte_eth_dev *dev,
12645 struct mlx5_flow *dev_flow,
12646 const struct rte_flow_attr *attr,
12647 const struct rte_flow_item items[],
12648 const struct rte_flow_action actions[],
12649 struct rte_flow_error *error)
12651 struct mlx5_priv *priv = dev->data->dev_private;
12652 struct mlx5_dev_config *dev_conf = &priv->config;
12653 struct rte_flow *flow = dev_flow->flow;
12654 struct mlx5_flow_handle *handle = dev_flow->handle;
12655 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12656 struct mlx5_flow_rss_desc *rss_desc;
12657 uint64_t item_flags = 0;
12658 uint64_t last_item = 0;
12659 uint64_t action_flags = 0;
12660 struct mlx5_flow_dv_matcher matcher = {
12662 .size = sizeof(matcher.mask.buf),
12666 bool actions_end = false;
12668 struct mlx5_flow_dv_modify_hdr_resource res;
12669 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
12670 sizeof(struct mlx5_modification_cmd) *
12671 (MLX5_MAX_MODIFY_NUM + 1)];
12673 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
12674 const struct rte_flow_action_count *count = NULL;
12675 const struct rte_flow_action_age *non_shared_age = NULL;
12676 union flow_dv_attr flow_attr = { .attr = 0 };
12678 union mlx5_flow_tbl_key tbl_key;
12679 uint32_t modify_action_position = UINT32_MAX;
12680 void *match_mask = matcher.mask.buf;
12681 void *match_value = dev_flow->dv.value.buf;
12682 uint8_t next_protocol = 0xff;
12683 struct rte_vlan_hdr vlan = { 0 };
12684 struct mlx5_flow_dv_dest_array_resource mdest_res;
12685 struct mlx5_flow_dv_sample_resource sample_res;
12686 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
12687 const struct rte_flow_action_sample *sample = NULL;
12688 struct mlx5_flow_sub_actions_list *sample_act;
12689 uint32_t sample_act_pos = UINT32_MAX;
12690 uint32_t age_act_pos = UINT32_MAX;
12691 uint32_t num_of_dest = 0;
12692 int tmp_actions_n = 0;
12695 const struct mlx5_flow_tunnel *tunnel = NULL;
12696 struct flow_grp_info grp_info = {
12697 .external = !!dev_flow->external,
12698 .transfer = !!attr->transfer,
12699 .fdb_def_rule = !!priv->fdb_def_rule,
12700 .skip_scale = dev_flow->skip_scale &
12701 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
12702 .std_tbl_fix = true,
12704 const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
12705 const struct rte_flow_item *tunnel_item = NULL;
12708 return rte_flow_error_set(error, ENOMEM,
12709 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12711 "failed to push flow workspace");
12712 rss_desc = &wks->rss_desc;
12713 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
12714 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
12715 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12716 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12717 /* update normal path action resource into last index of array */
12718 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
12719 if (is_tunnel_offload_active(dev)) {
12720 if (dev_flow->tunnel) {
12721 RTE_VERIFY(dev_flow->tof_type ==
12722 MLX5_TUNNEL_OFFLOAD_MISS_RULE);
12723 tunnel = dev_flow->tunnel;
12725 tunnel = mlx5_get_tof(items, actions,
12726 &dev_flow->tof_type);
12727 dev_flow->tunnel = tunnel;
12729 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
12730 (dev, attr, tunnel, dev_flow->tof_type);
12732 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12733 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12734 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
12738 dev_flow->dv.group = table;
12739 if (attr->transfer)
12740 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12741 /* number of actions must be set to 0 in case of dirty stack. */
12742 mhdr_res->actions_num = 0;
12743 if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
12745 * do not add decap action if match rule drops packet
12746 * HW rejects rules with decap & drop
12748 * if tunnel match rule was inserted before matching tunnel set
12749 * rule flow table used in the match rule must be registered.
12750 * current implementation handles that in the
12751 * flow_dv_match_register() at the function end.
12753 bool add_decap = true;
12754 const struct rte_flow_action *ptr = actions;
12756 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
12757 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
12763 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12767 dev_flow->dv.actions[actions_n++] =
12768 dev_flow->dv.encap_decap->action;
12769 action_flags |= MLX5_FLOW_ACTION_DECAP;
12772 for (; !actions_end ; actions++) {
12773 const struct rte_flow_action_queue *queue;
12774 const struct rte_flow_action_rss *rss;
12775 const struct rte_flow_action *action = actions;
12776 const uint8_t *rss_key;
12777 struct mlx5_flow_tbl_resource *tbl;
12778 struct mlx5_aso_age_action *age_act;
12779 struct mlx5_flow_counter *cnt_act;
12780 uint32_t port_id = 0;
12781 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
12782 int action_type = actions->type;
12783 const struct rte_flow_action *found_action = NULL;
12784 uint32_t jump_group = 0;
12785 uint32_t owner_idx;
12786 struct mlx5_aso_ct_action *ct;
12788 if (!mlx5_flow_os_action_supported(action_type))
12789 return rte_flow_error_set(error, ENOTSUP,
12790 RTE_FLOW_ERROR_TYPE_ACTION,
12792 "action not supported");
12793 switch (action_type) {
12794 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
12795 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
12797 case RTE_FLOW_ACTION_TYPE_VOID:
12799 case RTE_FLOW_ACTION_TYPE_PORT_ID:
12800 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
12801 if (flow_dv_translate_action_port_id(dev, action,
12804 port_id_resource.port_id = port_id;
12805 MLX5_ASSERT(!handle->rix_port_id_action);
12806 if (flow_dv_port_id_action_resource_register
12807 (dev, &port_id_resource, dev_flow, error))
12809 dev_flow->dv.actions[actions_n++] =
12810 dev_flow->dv.port_id_action->action;
12811 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12812 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
12813 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12816 case RTE_FLOW_ACTION_TYPE_FLAG:
12817 action_flags |= MLX5_FLOW_ACTION_FLAG;
12819 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12820 struct rte_flow_action_mark mark = {
12821 .id = MLX5_FLOW_MARK_DEFAULT,
12824 if (flow_dv_convert_action_mark(dev, &mark,
12828 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12831 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
12833 * Only one FLAG or MARK is supported per device flow
12834 * right now. So the pointer to the tag resource must be
12835 * zero before the register process.
12837 MLX5_ASSERT(!handle->dvh.rix_tag);
12838 if (flow_dv_tag_resource_register(dev, tag_be,
12841 MLX5_ASSERT(dev_flow->dv.tag_resource);
12842 dev_flow->dv.actions[actions_n++] =
12843 dev_flow->dv.tag_resource->action;
12845 case RTE_FLOW_ACTION_TYPE_MARK:
12846 action_flags |= MLX5_FLOW_ACTION_MARK;
12848 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12849 const struct rte_flow_action_mark *mark =
12850 (const struct rte_flow_action_mark *)
12853 if (flow_dv_convert_action_mark(dev, mark,
12857 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12861 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
12862 /* Legacy (non-extensive) MARK action. */
12863 tag_be = mlx5_flow_mark_set
12864 (((const struct rte_flow_action_mark *)
12865 (actions->conf))->id);
12866 MLX5_ASSERT(!handle->dvh.rix_tag);
12867 if (flow_dv_tag_resource_register(dev, tag_be,
12870 MLX5_ASSERT(dev_flow->dv.tag_resource);
12871 dev_flow->dv.actions[actions_n++] =
12872 dev_flow->dv.tag_resource->action;
12874 case RTE_FLOW_ACTION_TYPE_SET_META:
12875 if (flow_dv_convert_action_set_meta
12876 (dev, mhdr_res, attr,
12877 (const struct rte_flow_action_set_meta *)
12878 actions->conf, error))
12880 action_flags |= MLX5_FLOW_ACTION_SET_META;
12882 case RTE_FLOW_ACTION_TYPE_SET_TAG:
12883 if (flow_dv_convert_action_set_tag
12885 (const struct rte_flow_action_set_tag *)
12886 actions->conf, error))
12888 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12890 case RTE_FLOW_ACTION_TYPE_DROP:
12891 action_flags |= MLX5_FLOW_ACTION_DROP;
12892 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
12894 case RTE_FLOW_ACTION_TYPE_QUEUE:
12895 queue = actions->conf;
12896 rss_desc->queue_num = 1;
12897 rss_desc->queue[0] = queue->index;
12898 action_flags |= MLX5_FLOW_ACTION_QUEUE;
12899 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
12900 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
12903 case RTE_FLOW_ACTION_TYPE_RSS:
12904 rss = actions->conf;
12905 memcpy(rss_desc->queue, rss->queue,
12906 rss->queue_num * sizeof(uint16_t));
12907 rss_desc->queue_num = rss->queue_num;
12908 /* NULL RSS key indicates default RSS key. */
12909 rss_key = !rss->key ? rss_hash_default_key : rss->key;
12910 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12912 * rss->level and rss.types should be set in advance
12913 * when expanding items for RSS.
12915 action_flags |= MLX5_FLOW_ACTION_RSS;
12916 dev_flow->handle->fate_action = rss_desc->shared_rss ?
12917 MLX5_FLOW_FATE_SHARED_RSS :
12918 MLX5_FLOW_FATE_QUEUE;
12920 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
12921 owner_idx = (uint32_t)(uintptr_t)action->conf;
12922 age_act = flow_aso_age_get_by_idx(dev, owner_idx);
12923 if (flow->age == 0) {
12924 flow->age = owner_idx;
12925 __atomic_fetch_add(&age_act->refcnt, 1,
12928 age_act_pos = actions_n++;
12929 action_flags |= MLX5_FLOW_ACTION_AGE;
12931 case RTE_FLOW_ACTION_TYPE_AGE:
12932 non_shared_age = action->conf;
12933 age_act_pos = actions_n++;
12934 action_flags |= MLX5_FLOW_ACTION_AGE;
12936 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
12937 owner_idx = (uint32_t)(uintptr_t)action->conf;
12938 cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
12940 MLX5_ASSERT(cnt_act != NULL);
12942 * When creating meter drop flow in drop table, the
12943 * counter should not overwrite the rte flow counter.
12945 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
12946 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
12947 dev_flow->dv.actions[actions_n++] =
12950 if (flow->counter == 0) {
12951 flow->counter = owner_idx;
12953 (&cnt_act->shared_info.refcnt,
12954 1, __ATOMIC_RELAXED);
12956 /* Save information first, will apply later. */
12957 action_flags |= MLX5_FLOW_ACTION_COUNT;
12960 case RTE_FLOW_ACTION_TYPE_COUNT:
12961 if (!priv->sh->devx) {
12962 return rte_flow_error_set
12964 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12966 "count action not supported");
12968 /* Save information first, will apply later. */
12969 count = action->conf;
12970 action_flags |= MLX5_FLOW_ACTION_COUNT;
12972 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
12973 dev_flow->dv.actions[actions_n++] =
12974 priv->sh->pop_vlan_action;
12975 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
12977 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
12978 if (!(action_flags &
12979 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
12980 flow_dev_get_vlan_info_from_items(items, &vlan);
12981 vlan.eth_proto = rte_be_to_cpu_16
12982 ((((const struct rte_flow_action_of_push_vlan *)
12983 actions->conf)->ethertype));
12984 found_action = mlx5_flow_find_action
12986 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
12988 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12989 found_action = mlx5_flow_find_action
12991 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
12993 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12994 if (flow_dv_create_action_push_vlan
12995 (dev, attr, &vlan, dev_flow, error))
12997 dev_flow->dv.actions[actions_n++] =
12998 dev_flow->dv.push_vlan_res->action;
12999 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
13001 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
13002 /* of_vlan_push action handled this action */
13003 MLX5_ASSERT(action_flags &
13004 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
13006 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
13007 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
13009 flow_dev_get_vlan_info_from_items(items, &vlan);
13010 mlx5_update_vlan_vid_pcp(actions, &vlan);
13011 /* If no VLAN push - this is a modify header action */
13012 if (flow_dv_convert_action_modify_vlan_vid
13013 (mhdr_res, actions, error))
13015 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
13017 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13018 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13019 if (flow_dv_create_action_l2_encap(dev, actions,
13024 dev_flow->dv.actions[actions_n++] =
13025 dev_flow->dv.encap_decap->action;
13026 action_flags |= MLX5_FLOW_ACTION_ENCAP;
13027 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
13028 sample_act->action_flags |=
13029 MLX5_FLOW_ACTION_ENCAP;
13031 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
13032 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
13033 if (flow_dv_create_action_l2_decap(dev, dev_flow,
13037 dev_flow->dv.actions[actions_n++] =
13038 dev_flow->dv.encap_decap->action;
13039 action_flags |= MLX5_FLOW_ACTION_DECAP;
13041 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13042 /* Handle encap with preceding decap. */
13043 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
13044 if (flow_dv_create_action_raw_encap
13045 (dev, actions, dev_flow, attr, error))
13047 dev_flow->dv.actions[actions_n++] =
13048 dev_flow->dv.encap_decap->action;
13050 /* Handle encap without preceding decap. */
13051 if (flow_dv_create_action_l2_encap
13052 (dev, actions, dev_flow, attr->transfer,
13055 dev_flow->dv.actions[actions_n++] =
13056 dev_flow->dv.encap_decap->action;
13058 action_flags |= MLX5_FLOW_ACTION_ENCAP;
13059 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
13060 sample_act->action_flags |=
13061 MLX5_FLOW_ACTION_ENCAP;
13063 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
13064 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
13066 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
13067 if (flow_dv_create_action_l2_decap
13068 (dev, dev_flow, attr->transfer, error))
13070 dev_flow->dv.actions[actions_n++] =
13071 dev_flow->dv.encap_decap->action;
13073 /* If decap is followed by encap, handle it at encap. */
13074 action_flags |= MLX5_FLOW_ACTION_DECAP;
13076 case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
13077 dev_flow->dv.actions[actions_n++] =
13078 (void *)(uintptr_t)action->conf;
13079 action_flags |= MLX5_FLOW_ACTION_JUMP;
13081 case RTE_FLOW_ACTION_TYPE_JUMP:
13082 jump_group = ((const struct rte_flow_action_jump *)
13083 action->conf)->group;
13084 grp_info.std_tbl_fix = 0;
13085 if (dev_flow->skip_scale &
13086 (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
13087 grp_info.skip_scale = 1;
13089 grp_info.skip_scale = 0;
13090 ret = mlx5_flow_group_to_table(dev, tunnel,
13096 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
13098 !!dev_flow->external,
13099 tunnel, jump_group, 0,
13102 return rte_flow_error_set
13104 RTE_FLOW_ERROR_TYPE_ACTION,
13106 "cannot create jump action.");
13107 if (flow_dv_jump_tbl_resource_register
13108 (dev, tbl, dev_flow, error)) {
13109 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
13110 return rte_flow_error_set
13112 RTE_FLOW_ERROR_TYPE_ACTION,
13114 "cannot create jump action.");
13116 dev_flow->dv.actions[actions_n++] =
13117 dev_flow->dv.jump->action;
13118 action_flags |= MLX5_FLOW_ACTION_JUMP;
13119 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
13120 sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
13123 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
13124 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
13125 if (flow_dv_convert_action_modify_mac
13126 (mhdr_res, actions, error))
13128 action_flags |= actions->type ==
13129 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
13130 MLX5_FLOW_ACTION_SET_MAC_SRC :
13131 MLX5_FLOW_ACTION_SET_MAC_DST;
13133 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
13134 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
13135 if (flow_dv_convert_action_modify_ipv4
13136 (mhdr_res, actions, error))
13138 action_flags |= actions->type ==
13139 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
13140 MLX5_FLOW_ACTION_SET_IPV4_SRC :
13141 MLX5_FLOW_ACTION_SET_IPV4_DST;
13143 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
13144 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
13145 if (flow_dv_convert_action_modify_ipv6
13146 (mhdr_res, actions, error))
13148 action_flags |= actions->type ==
13149 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
13150 MLX5_FLOW_ACTION_SET_IPV6_SRC :
13151 MLX5_FLOW_ACTION_SET_IPV6_DST;
13153 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
13154 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
13155 if (flow_dv_convert_action_modify_tp
13156 (mhdr_res, actions, items,
13157 &flow_attr, dev_flow, !!(action_flags &
13158 MLX5_FLOW_ACTION_DECAP), error))
13160 action_flags |= actions->type ==
13161 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
13162 MLX5_FLOW_ACTION_SET_TP_SRC :
13163 MLX5_FLOW_ACTION_SET_TP_DST;
13165 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
13166 if (flow_dv_convert_action_modify_dec_ttl
13167 (mhdr_res, items, &flow_attr, dev_flow,
13169 MLX5_FLOW_ACTION_DECAP), error))
13171 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
13173 case RTE_FLOW_ACTION_TYPE_SET_TTL:
13174 if (flow_dv_convert_action_modify_ttl
13175 (mhdr_res, actions, items, &flow_attr,
13176 dev_flow, !!(action_flags &
13177 MLX5_FLOW_ACTION_DECAP), error))
13179 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
13181 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
13182 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
13183 if (flow_dv_convert_action_modify_tcp_seq
13184 (mhdr_res, actions, error))
13186 action_flags |= actions->type ==
13187 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
13188 MLX5_FLOW_ACTION_INC_TCP_SEQ :
13189 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
13192 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
13193 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
13194 if (flow_dv_convert_action_modify_tcp_ack
13195 (mhdr_res, actions, error))
13197 action_flags |= actions->type ==
13198 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
13199 MLX5_FLOW_ACTION_INC_TCP_ACK :
13200 MLX5_FLOW_ACTION_DEC_TCP_ACK;
13202 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
13203 if (flow_dv_convert_action_set_reg
13204 (mhdr_res, actions, error))
13206 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13208 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
13209 if (flow_dv_convert_action_copy_mreg
13210 (dev, mhdr_res, actions, error))
13212 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13214 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
13215 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
13216 dev_flow->handle->fate_action =
13217 MLX5_FLOW_FATE_DEFAULT_MISS;
13219 case RTE_FLOW_ACTION_TYPE_METER:
13221 return rte_flow_error_set(error, rte_errno,
13222 RTE_FLOW_ERROR_TYPE_ACTION,
13223 NULL, "Failed to get meter in flow.");
13224 /* Set the meter action. */
13225 dev_flow->dv.actions[actions_n++] =
13226 wks->fm->meter_action;
13227 action_flags |= MLX5_FLOW_ACTION_METER;
13229 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
13230 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
13233 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
13235 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
13236 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
13239 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
13241 case RTE_FLOW_ACTION_TYPE_SAMPLE:
13242 sample_act_pos = actions_n;
13243 sample = (const struct rte_flow_action_sample *)
13246 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
13247 /* put encap action into group if work with port id */
13248 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
13249 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
13250 sample_act->action_flags |=
13251 MLX5_FLOW_ACTION_ENCAP;
13253 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
13254 if (flow_dv_convert_action_modify_field
13255 (dev, mhdr_res, actions, attr, error))
13257 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
13259 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
13260 owner_idx = (uint32_t)(uintptr_t)action->conf;
13261 ct = flow_aso_ct_get_by_idx(dev, owner_idx);
13263 return rte_flow_error_set(error, EINVAL,
13264 RTE_FLOW_ERROR_TYPE_ACTION,
13266 "Failed to get CT object.");
13267 if (mlx5_aso_ct_available(priv->sh, ct))
13268 return rte_flow_error_set(error, rte_errno,
13269 RTE_FLOW_ERROR_TYPE_ACTION,
13271 "CT is unavailable.");
13272 if (ct->is_original)
13273 dev_flow->dv.actions[actions_n] =
13274 ct->dr_action_orig;
13276 dev_flow->dv.actions[actions_n] =
13277 ct->dr_action_rply;
13278 if (flow->ct == 0) {
13279 flow->indirect_type =
13280 MLX5_INDIRECT_ACTION_TYPE_CT;
13281 flow->ct = owner_idx;
13282 __atomic_fetch_add(&ct->refcnt, 1,
13286 action_flags |= MLX5_FLOW_ACTION_CT;
13288 case RTE_FLOW_ACTION_TYPE_END:
13289 actions_end = true;
13290 if (mhdr_res->actions_num) {
13291 /* create modify action if needed. */
13292 if (flow_dv_modify_hdr_resource_register
13293 (dev, mhdr_res, dev_flow, error))
13295 dev_flow->dv.actions[modify_action_position] =
13296 handle->dvh.modify_hdr->action;
13299 * Handle AGE and COUNT action by single HW counter
13300 * when they are not shared.
13302 if (action_flags & MLX5_FLOW_ACTION_AGE) {
13303 if ((non_shared_age && count) ||
13304 !(priv->sh->flow_hit_aso_en &&
13305 (attr->group || attr->transfer))) {
13306 /* Creates age by counters. */
13307 cnt_act = flow_dv_prepare_counter
13314 dev_flow->dv.actions[age_act_pos] =
13318 if (!flow->age && non_shared_age) {
13319 flow->age = flow_dv_aso_age_alloc
13323 flow_dv_aso_age_params_init
13325 non_shared_age->context ?
13326 non_shared_age->context :
13327 (void *)(uintptr_t)
13328 (dev_flow->flow_idx),
13329 non_shared_age->timeout);
13331 age_act = flow_aso_age_get_by_idx(dev,
13333 dev_flow->dv.actions[age_act_pos] =
13334 age_act->dr_action;
13336 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
13338 * Create one count action, to be used
13339 * by all sub-flows.
13341 cnt_act = flow_dv_prepare_counter(dev, dev_flow,
13346 dev_flow->dv.actions[actions_n++] =
13352 if (mhdr_res->actions_num &&
13353 modify_action_position == UINT32_MAX)
13354 modify_action_position = actions_n++;
13356 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
13357 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
13358 int item_type = items->type;
13360 if (!mlx5_flow_os_item_supported(item_type))
13361 return rte_flow_error_set(error, ENOTSUP,
13362 RTE_FLOW_ERROR_TYPE_ITEM,
13363 NULL, "item not supported");
13364 switch (item_type) {
13365 case RTE_FLOW_ITEM_TYPE_PORT_ID:
13366 flow_dv_translate_item_port_id
13367 (dev, match_mask, match_value, items, attr);
13368 last_item = MLX5_FLOW_ITEM_PORT_ID;
13370 case RTE_FLOW_ITEM_TYPE_ETH:
13371 flow_dv_translate_item_eth(match_mask, match_value,
13373 dev_flow->dv.group);
13374 matcher.priority = action_flags &
13375 MLX5_FLOW_ACTION_DEFAULT_MISS &&
13376 !dev_flow->external ?
13377 MLX5_PRIORITY_MAP_L3 :
13378 MLX5_PRIORITY_MAP_L2;
13379 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
13380 MLX5_FLOW_LAYER_OUTER_L2;
13382 case RTE_FLOW_ITEM_TYPE_VLAN:
13383 flow_dv_translate_item_vlan(dev_flow,
13384 match_mask, match_value,
13386 dev_flow->dv.group);
13387 matcher.priority = MLX5_PRIORITY_MAP_L2;
13388 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
13389 MLX5_FLOW_LAYER_INNER_VLAN) :
13390 (MLX5_FLOW_LAYER_OUTER_L2 |
13391 MLX5_FLOW_LAYER_OUTER_VLAN);
13393 case RTE_FLOW_ITEM_TYPE_IPV4:
13394 mlx5_flow_tunnel_ip_check(items, next_protocol,
13395 &item_flags, &tunnel);
13396 flow_dv_translate_item_ipv4(match_mask, match_value,
13398 dev_flow->dv.group);
13399 matcher.priority = MLX5_PRIORITY_MAP_L3;
13400 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
13401 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
13402 if (items->mask != NULL &&
13403 ((const struct rte_flow_item_ipv4 *)
13404 items->mask)->hdr.next_proto_id) {
13406 ((const struct rte_flow_item_ipv4 *)
13407 (items->spec))->hdr.next_proto_id;
13409 ((const struct rte_flow_item_ipv4 *)
13410 (items->mask))->hdr.next_proto_id;
13412 /* Reset for inner layer. */
13413 next_protocol = 0xff;
13416 case RTE_FLOW_ITEM_TYPE_IPV6:
13417 mlx5_flow_tunnel_ip_check(items, next_protocol,
13418 &item_flags, &tunnel);
13419 flow_dv_translate_item_ipv6(match_mask, match_value,
13421 dev_flow->dv.group);
13422 matcher.priority = MLX5_PRIORITY_MAP_L3;
13423 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
13424 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
13425 if (items->mask != NULL &&
13426 ((const struct rte_flow_item_ipv6 *)
13427 items->mask)->hdr.proto) {
13429 ((const struct rte_flow_item_ipv6 *)
13430 items->spec)->hdr.proto;
13432 ((const struct rte_flow_item_ipv6 *)
13433 items->mask)->hdr.proto;
13435 /* Reset for inner layer. */
13436 next_protocol = 0xff;
13439 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
13440 flow_dv_translate_item_ipv6_frag_ext(match_mask,
13443 last_item = tunnel ?
13444 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
13445 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
13446 if (items->mask != NULL &&
13447 ((const struct rte_flow_item_ipv6_frag_ext *)
13448 items->mask)->hdr.next_header) {
13450 ((const struct rte_flow_item_ipv6_frag_ext *)
13451 items->spec)->hdr.next_header;
13453 ((const struct rte_flow_item_ipv6_frag_ext *)
13454 items->mask)->hdr.next_header;
13456 /* Reset for inner layer. */
13457 next_protocol = 0xff;
13460 case RTE_FLOW_ITEM_TYPE_TCP:
13461 flow_dv_translate_item_tcp(match_mask, match_value,
13463 matcher.priority = MLX5_PRIORITY_MAP_L4;
13464 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
13465 MLX5_FLOW_LAYER_OUTER_L4_TCP;
13467 case RTE_FLOW_ITEM_TYPE_UDP:
13468 flow_dv_translate_item_udp(match_mask, match_value,
13470 matcher.priority = MLX5_PRIORITY_MAP_L4;
13471 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
13472 MLX5_FLOW_LAYER_OUTER_L4_UDP;
13474 case RTE_FLOW_ITEM_TYPE_GRE:
13475 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13476 last_item = MLX5_FLOW_LAYER_GRE;
13477 tunnel_item = items;
13479 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
13480 flow_dv_translate_item_gre_key(match_mask,
13481 match_value, items);
13482 last_item = MLX5_FLOW_LAYER_GRE_KEY;
13484 case RTE_FLOW_ITEM_TYPE_NVGRE:
13485 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13486 last_item = MLX5_FLOW_LAYER_GRE;
13487 tunnel_item = items;
13489 case RTE_FLOW_ITEM_TYPE_VXLAN:
13490 flow_dv_translate_item_vxlan(dev, attr,
13491 match_mask, match_value,
13493 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13494 last_item = MLX5_FLOW_LAYER_VXLAN;
13496 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
13497 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13498 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
13499 tunnel_item = items;
13501 case RTE_FLOW_ITEM_TYPE_GENEVE:
13502 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13503 last_item = MLX5_FLOW_LAYER_GENEVE;
13504 tunnel_item = items;
13506 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
13507 ret = flow_dv_translate_item_geneve_opt(dev, match_mask,
13511 return rte_flow_error_set(error, -ret,
13512 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13513 "cannot create GENEVE TLV option");
13514 flow->geneve_tlv_option = 1;
13515 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
13517 case RTE_FLOW_ITEM_TYPE_MPLS:
13518 flow_dv_translate_item_mpls(match_mask, match_value,
13519 items, last_item, tunnel);
13520 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13521 last_item = MLX5_FLOW_LAYER_MPLS;
13523 case RTE_FLOW_ITEM_TYPE_MARK:
13524 flow_dv_translate_item_mark(dev, match_mask,
13525 match_value, items);
13526 last_item = MLX5_FLOW_ITEM_MARK;
13528 case RTE_FLOW_ITEM_TYPE_META:
13529 flow_dv_translate_item_meta(dev, match_mask,
13530 match_value, attr, items);
13531 last_item = MLX5_FLOW_ITEM_METADATA;
13533 case RTE_FLOW_ITEM_TYPE_ICMP:
13534 flow_dv_translate_item_icmp(match_mask, match_value,
13536 last_item = MLX5_FLOW_LAYER_ICMP;
13538 case RTE_FLOW_ITEM_TYPE_ICMP6:
13539 flow_dv_translate_item_icmp6(match_mask, match_value,
13541 last_item = MLX5_FLOW_LAYER_ICMP6;
13543 case RTE_FLOW_ITEM_TYPE_TAG:
13544 flow_dv_translate_item_tag(dev, match_mask,
13545 match_value, items);
13546 last_item = MLX5_FLOW_ITEM_TAG;
13548 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
13549 flow_dv_translate_mlx5_item_tag(dev, match_mask,
13550 match_value, items);
13551 last_item = MLX5_FLOW_ITEM_TAG;
13553 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
13554 flow_dv_translate_item_tx_queue(dev, match_mask,
13557 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
13559 case RTE_FLOW_ITEM_TYPE_GTP:
13560 flow_dv_translate_item_gtp(match_mask, match_value,
13562 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13563 last_item = MLX5_FLOW_LAYER_GTP;
13565 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
13566 ret = flow_dv_translate_item_gtp_psc(match_mask,
13570 return rte_flow_error_set(error, -ret,
13571 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13572 "cannot create GTP PSC item");
13573 last_item = MLX5_FLOW_LAYER_GTP_PSC;
13575 case RTE_FLOW_ITEM_TYPE_ECPRI:
13576 if (!mlx5_flex_parser_ecpri_exist(dev)) {
13577 /* Create it only the first time to be used. */
13578 ret = mlx5_flex_parser_ecpri_alloc(dev);
13580 return rte_flow_error_set
13582 RTE_FLOW_ERROR_TYPE_ITEM,
13584 "cannot create eCPRI parser");
13586 flow_dv_translate_item_ecpri(dev, match_mask,
13587 match_value, items,
13589 /* No other protocol should follow eCPRI layer. */
13590 last_item = MLX5_FLOW_LAYER_ECPRI;
13592 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
13593 flow_dv_translate_item_integrity(items, integrity_items,
13596 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
13597 flow_dv_translate_item_aso_ct(dev, match_mask,
13598 match_value, items);
13600 case RTE_FLOW_ITEM_TYPE_FLEX:
13601 flow_dv_translate_item_flex(dev, match_mask,
13602 match_value, items,
13603 dev_flow, tunnel != 0);
13604 last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
13605 MLX5_FLOW_ITEM_OUTER_FLEX;
13610 item_flags |= last_item;
13613 * When E-Switch mode is enabled, we have two cases where we need to
13614 * set the source port manually.
13615 * The first one, is in case of Nic steering rule, and the second is
13616 * E-Switch rule where no port_id item was found. In both cases
13617 * the source port is set according the current port in use.
13619 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
13620 (priv->representor || priv->master)) {
13621 if (flow_dv_translate_item_port_id(dev, match_mask,
13622 match_value, NULL, attr))
13625 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
13626 flow_dv_translate_item_integrity_post(match_mask, match_value,
13630 if (item_flags & MLX5_FLOW_LAYER_VXLAN_GPE)
13631 flow_dv_translate_item_vxlan_gpe(match_mask, match_value,
13632 tunnel_item, item_flags);
13633 else if (item_flags & MLX5_FLOW_LAYER_GENEVE)
13634 flow_dv_translate_item_geneve(match_mask, match_value,
13635 tunnel_item, item_flags);
13636 else if (item_flags & MLX5_FLOW_LAYER_GRE) {
13637 if (tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE)
13638 flow_dv_translate_item_gre(match_mask, match_value,
13639 tunnel_item, item_flags);
13640 else if (tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE)
13641 flow_dv_translate_item_nvgre(match_mask, match_value,
13642 tunnel_item, item_flags);
13644 MLX5_ASSERT(false);
13646 #ifdef RTE_LIBRTE_MLX5_DEBUG
13647 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
13648 dev_flow->dv.value.buf));
13651 * Layers may be already initialized from prefix flow if this dev_flow
13652 * is the suffix flow.
13654 handle->layers |= item_flags;
13655 if (action_flags & MLX5_FLOW_ACTION_RSS)
13656 flow_dv_hashfields_set(dev_flow, rss_desc);
13657 /* If has RSS action in the sample action, the Sample/Mirror resource
13658 * should be registered after the hash filed be update.
13660 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
13661 ret = flow_dv_translate_action_sample(dev,
13670 ret = flow_dv_create_action_sample(dev,
13679 return rte_flow_error_set
13681 RTE_FLOW_ERROR_TYPE_ACTION,
13683 "cannot create sample action");
13684 if (num_of_dest > 1) {
13685 dev_flow->dv.actions[sample_act_pos] =
13686 dev_flow->dv.dest_array_res->action;
13688 dev_flow->dv.actions[sample_act_pos] =
13689 dev_flow->dv.sample_res->verbs_action;
13693 * For multiple destination (sample action with ratio=1), the encap
13694 * action and port id action will be combined into group action.
13695 * So need remove the original these actions in the flow and only
13696 * use the sample action instead of.
13698 if (num_of_dest > 1 &&
13699 (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
13701 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
13703 for (i = 0; i < actions_n; i++) {
13704 if ((sample_act->dr_encap_action &&
13705 sample_act->dr_encap_action ==
13706 dev_flow->dv.actions[i]) ||
13707 (sample_act->dr_port_id_action &&
13708 sample_act->dr_port_id_action ==
13709 dev_flow->dv.actions[i]) ||
13710 (sample_act->dr_jump_action &&
13711 sample_act->dr_jump_action ==
13712 dev_flow->dv.actions[i]))
13714 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
13716 memcpy((void *)dev_flow->dv.actions,
13717 (void *)temp_actions,
13718 tmp_actions_n * sizeof(void *));
13719 actions_n = tmp_actions_n;
13721 dev_flow->dv.actions_n = actions_n;
13722 dev_flow->act_flags = action_flags;
13723 if (wks->skip_matcher_reg)
13725 /* Register matcher. */
13726 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
13727 matcher.mask.size);
13728 matcher.priority = mlx5_get_matcher_priority(dev, attr,
13730 dev_flow->external);
13732 * When creating meter drop flow in drop table, using original
13733 * 5-tuple match, the matcher priority should be lower than
13736 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
13737 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
13738 matcher.priority <= MLX5_REG_BITS)
13739 matcher.priority += MLX5_REG_BITS;
13740 /* reserved field no needs to be set to 0 here. */
13741 tbl_key.is_fdb = attr->transfer;
13742 tbl_key.is_egress = attr->egress;
13743 tbl_key.level = dev_flow->dv.group;
13744 tbl_key.id = dev_flow->dv.table_id;
13745 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
13746 tunnel, attr->group, error))
13752 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13755 * @param[in, out] action
13756 * Shred RSS action holding hash RX queue objects.
13757 * @param[in] hash_fields
13758 * Defines combination of packet fields to participate in RX hash.
13759 * @param[in] tunnel
13761 * @param[in] hrxq_idx
13762 * Hash RX queue index to set.
13765 * 0 on success, otherwise negative errno value.
13768 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
13769 const uint64_t hash_fields,
13772 uint32_t *hrxqs = action->hrxq;
13774 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13775 case MLX5_RSS_HASH_IPV4:
13776 /* fall-through. */
13777 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13778 /* fall-through. */
13779 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13780 hrxqs[0] = hrxq_idx;
13782 case MLX5_RSS_HASH_IPV4_TCP:
13783 /* fall-through. */
13784 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13785 /* fall-through. */
13786 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13787 hrxqs[1] = hrxq_idx;
13789 case MLX5_RSS_HASH_IPV4_UDP:
13790 /* fall-through. */
13791 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13792 /* fall-through. */
13793 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13794 hrxqs[2] = hrxq_idx;
13796 case MLX5_RSS_HASH_IPV6:
13797 /* fall-through. */
13798 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13799 /* fall-through. */
13800 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13801 hrxqs[3] = hrxq_idx;
13803 case MLX5_RSS_HASH_IPV6_TCP:
13804 /* fall-through. */
13805 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13806 /* fall-through. */
13807 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13808 hrxqs[4] = hrxq_idx;
13810 case MLX5_RSS_HASH_IPV6_UDP:
13811 /* fall-through. */
13812 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13813 /* fall-through. */
13814 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13815 hrxqs[5] = hrxq_idx;
13817 case MLX5_RSS_HASH_NONE:
13818 hrxqs[6] = hrxq_idx;
13826 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13830 * Pointer to the Ethernet device structure.
13832 * Shared RSS action ID holding hash RX queue objects.
13833 * @param[in] hash_fields
13834 * Defines combination of packet fields to participate in RX hash.
13835 * @param[in] tunnel
13839 * Valid hash RX queue index, otherwise 0.
13842 __flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
13843 const uint64_t hash_fields)
13845 struct mlx5_priv *priv = dev->data->dev_private;
13846 struct mlx5_shared_action_rss *shared_rss =
13847 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
13848 const uint32_t *hrxqs = shared_rss->hrxq;
13850 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13851 case MLX5_RSS_HASH_IPV4:
13852 /* fall-through. */
13853 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13854 /* fall-through. */
13855 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13857 case MLX5_RSS_HASH_IPV4_TCP:
13858 /* fall-through. */
13859 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13860 /* fall-through. */
13861 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13863 case MLX5_RSS_HASH_IPV4_UDP:
13864 /* fall-through. */
13865 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13866 /* fall-through. */
13867 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13869 case MLX5_RSS_HASH_IPV6:
13870 /* fall-through. */
13871 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13872 /* fall-through. */
13873 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13875 case MLX5_RSS_HASH_IPV6_TCP:
13876 /* fall-through. */
13877 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13878 /* fall-through. */
13879 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13881 case MLX5_RSS_HASH_IPV6_UDP:
13882 /* fall-through. */
13883 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13884 /* fall-through. */
13885 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13887 case MLX5_RSS_HASH_NONE:
13896 * Apply the flow to the NIC, lock free,
13897 * (mutex should be acquired by caller).
13900 * Pointer to the Ethernet device structure.
13901 * @param[in, out] flow
13902 * Pointer to flow structure.
13903 * @param[out] error
13904 * Pointer to error structure.
13907 * 0 on success, a negative errno value otherwise and rte_errno is set.
13910 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
13911 struct rte_flow_error *error)
13913 struct mlx5_flow_dv_workspace *dv;
13914 struct mlx5_flow_handle *dh;
13915 struct mlx5_flow_handle_dv *dv_h;
13916 struct mlx5_flow *dev_flow;
13917 struct mlx5_priv *priv = dev->data->dev_private;
13918 uint32_t handle_idx;
13922 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13923 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
13927 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
13928 dev_flow = &wks->flows[idx];
13929 dv = &dev_flow->dv;
13930 dh = dev_flow->handle;
13933 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
13934 if (dv->transfer) {
13935 MLX5_ASSERT(priv->sh->dr_drop_action);
13936 dv->actions[n++] = priv->sh->dr_drop_action;
13938 #ifdef HAVE_MLX5DV_DR
13939 /* DR supports drop action placeholder. */
13940 MLX5_ASSERT(priv->sh->dr_drop_action);
13941 dv->actions[n++] = dv->group ?
13942 priv->sh->dr_drop_action :
13943 priv->root_drop_action;
13945 /* For DV we use the explicit drop queue. */
13946 MLX5_ASSERT(priv->drop_queue.hrxq);
13948 priv->drop_queue.hrxq->action;
13951 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
13952 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
13953 struct mlx5_hrxq *hrxq;
13956 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
13961 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13962 "cannot get hash queue");
13965 dh->rix_hrxq = hrxq_idx;
13966 dv->actions[n++] = hrxq->action;
13967 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13968 struct mlx5_hrxq *hrxq = NULL;
13971 hrxq_idx = __flow_dv_action_rss_hrxq_lookup(dev,
13972 rss_desc->shared_rss,
13973 dev_flow->hash_fields);
13975 hrxq = mlx5_ipool_get
13976 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
13981 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13982 "cannot get hash queue");
13985 dh->rix_srss = rss_desc->shared_rss;
13986 dv->actions[n++] = hrxq->action;
13987 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
13988 if (!priv->sh->default_miss_action) {
13991 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13992 "default miss action not be created.");
13995 dv->actions[n++] = priv->sh->default_miss_action;
13997 misc_mask = flow_dv_matcher_enable(dv->value.buf);
13998 __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
13999 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
14000 (void *)&dv->value, n,
14001 dv->actions, &dh->drv_flow);
14005 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14007 (!priv->config.allow_duplicate_pattern &&
14009 "duplicating pattern is not allowed" :
14010 "hardware refuses to create flow");
14013 if (priv->vmwa_context &&
14014 dh->vf_vlan.tag && !dh->vf_vlan.created) {
14016 * The rule contains the VLAN pattern.
14017 * For VF we are going to create VLAN
14018 * interface to make hypervisor set correct
14019 * e-Switch vport context.
14021 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
14026 err = rte_errno; /* Save rte_errno before cleanup. */
14027 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
14028 handle_idx, dh, next) {
14029 /* hrxq is union, don't clear it if the flag is not set. */
14030 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
14031 mlx5_hrxq_release(dev, dh->rix_hrxq);
14033 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
14036 if (dh->vf_vlan.tag && dh->vf_vlan.created)
14037 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
14039 rte_errno = err; /* Restore rte_errno. */
14044 flow_dv_matcher_remove_cb(void *tool_ctx __rte_unused,
14045 struct mlx5_list_entry *entry)
14047 struct mlx5_flow_dv_matcher *resource = container_of(entry,
14051 claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
14052 mlx5_free(resource);
14056 * Release the flow matcher.
14059 * Pointer to Ethernet device.
14061 * Index to port ID action resource.
14064 * 1 while a reference on it exists, 0 when freed.
14067 flow_dv_matcher_release(struct rte_eth_dev *dev,
14068 struct mlx5_flow_handle *handle)
14070 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
14071 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
14072 typeof(*tbl), tbl);
14075 MLX5_ASSERT(matcher->matcher_object);
14076 ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
14077 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
14082 flow_dv_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14084 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14085 struct mlx5_flow_dv_encap_decap_resource *res =
14086 container_of(entry, typeof(*res), entry);
14088 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
14089 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
14093 * Release an encap/decap resource.
14096 * Pointer to Ethernet device.
14097 * @param encap_decap_idx
14098 * Index of encap decap resource.
14101 * 1 while a reference on it exists, 0 when freed.
14104 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
14105 uint32_t encap_decap_idx)
14107 struct mlx5_priv *priv = dev->data->dev_private;
14108 struct mlx5_flow_dv_encap_decap_resource *resource;
14110 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
14114 MLX5_ASSERT(resource->action);
14115 return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
14119 * Release an jump to table action resource.
14122 * Pointer to Ethernet device.
14124 * Index to the jump action resource.
14127 * 1 while a reference on it exists, 0 when freed.
14130 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
14133 struct mlx5_priv *priv = dev->data->dev_private;
14134 struct mlx5_flow_tbl_data_entry *tbl_data;
14136 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
14140 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
14144 flow_dv_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14146 struct mlx5_flow_dv_modify_hdr_resource *res =
14147 container_of(entry, typeof(*res), entry);
14148 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14150 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
14151 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
14155 * Release a modify-header resource.
14158 * Pointer to Ethernet device.
14160 * Pointer to mlx5_flow_handle.
14163 * 1 while a reference on it exists, 0 when freed.
14166 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
14167 struct mlx5_flow_handle *handle)
14169 struct mlx5_priv *priv = dev->data->dev_private;
14170 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
14172 MLX5_ASSERT(entry->action);
14173 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
14177 flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14179 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14180 struct mlx5_flow_dv_port_id_action_resource *resource =
14181 container_of(entry, typeof(*resource), entry);
14183 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14184 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
14188 * Release port ID action resource.
14191 * Pointer to Ethernet device.
14193 * Pointer to mlx5_flow_handle.
14196 * 1 while a reference on it exists, 0 when freed.
14199 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
14202 struct mlx5_priv *priv = dev->data->dev_private;
14203 struct mlx5_flow_dv_port_id_action_resource *resource;
14205 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
14208 MLX5_ASSERT(resource->action);
14209 return mlx5_list_unregister(priv->sh->port_id_action_list,
14214 * Release shared RSS action resource.
14217 * Pointer to Ethernet device.
14219 * Shared RSS action index.
14222 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
14224 struct mlx5_priv *priv = dev->data->dev_private;
14225 struct mlx5_shared_action_rss *shared_rss;
14227 shared_rss = mlx5_ipool_get
14228 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
14229 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14233 flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14235 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14236 struct mlx5_flow_dv_push_vlan_action_resource *resource =
14237 container_of(entry, typeof(*resource), entry);
14239 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14240 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
14244 * Release push vlan action resource.
14247 * Pointer to Ethernet device.
14249 * Pointer to mlx5_flow_handle.
14252 * 1 while a reference on it exists, 0 when freed.
14255 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
14256 struct mlx5_flow_handle *handle)
14258 struct mlx5_priv *priv = dev->data->dev_private;
14259 struct mlx5_flow_dv_push_vlan_action_resource *resource;
14260 uint32_t idx = handle->dvh.rix_push_vlan;
14262 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
14265 MLX5_ASSERT(resource->action);
14266 return mlx5_list_unregister(priv->sh->push_vlan_action_list,
14271 * Release the fate resource.
14274 * Pointer to Ethernet device.
14276 * Pointer to mlx5_flow_handle.
14279 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
14280 struct mlx5_flow_handle *handle)
14282 if (!handle->rix_fate)
14284 switch (handle->fate_action) {
14285 case MLX5_FLOW_FATE_QUEUE:
14286 if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
14287 mlx5_hrxq_release(dev, handle->rix_hrxq);
14289 case MLX5_FLOW_FATE_JUMP:
14290 flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
14292 case MLX5_FLOW_FATE_PORT_ID:
14293 flow_dv_port_id_action_resource_release(dev,
14294 handle->rix_port_id_action);
14297 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
14300 handle->rix_fate = 0;
14304 flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
14305 struct mlx5_list_entry *entry)
14307 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
14310 struct rte_eth_dev *dev = resource->dev;
14311 struct mlx5_priv *priv = dev->data->dev_private;
14313 if (resource->verbs_action)
14314 claim_zero(mlx5_flow_os_destroy_flow_action
14315 (resource->verbs_action));
14316 if (resource->normal_path_tbl)
14317 flow_dv_tbl_resource_release(MLX5_SH(dev),
14318 resource->normal_path_tbl);
14319 flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
14320 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
14321 DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
14325 * Release an sample resource.
14328 * Pointer to Ethernet device.
14330 * Pointer to mlx5_flow_handle.
14333 * 1 while a reference on it exists, 0 when freed.
14336 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
14337 struct mlx5_flow_handle *handle)
14339 struct mlx5_priv *priv = dev->data->dev_private;
14340 struct mlx5_flow_dv_sample_resource *resource;
14342 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
14343 handle->dvh.rix_sample);
14346 MLX5_ASSERT(resource->verbs_action);
14347 return mlx5_list_unregister(priv->sh->sample_action_list,
14352 flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
14353 struct mlx5_list_entry *entry)
14355 struct mlx5_flow_dv_dest_array_resource *resource =
14356 container_of(entry, typeof(*resource), entry);
14357 struct rte_eth_dev *dev = resource->dev;
14358 struct mlx5_priv *priv = dev->data->dev_private;
14361 MLX5_ASSERT(resource->action);
14362 if (resource->action)
14363 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14364 for (; i < resource->num_of_dest; i++)
14365 flow_dv_sample_sub_actions_release(dev,
14366 &resource->sample_idx[i]);
14367 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
14368 DRV_LOG(DEBUG, "destination array resource %p: removed",
14373 * Release an destination array resource.
14376 * Pointer to Ethernet device.
14378 * Pointer to mlx5_flow_handle.
14381 * 1 while a reference on it exists, 0 when freed.
14384 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
14385 struct mlx5_flow_handle *handle)
14387 struct mlx5_priv *priv = dev->data->dev_private;
14388 struct mlx5_flow_dv_dest_array_resource *resource;
14390 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
14391 handle->dvh.rix_dest_array);
14394 MLX5_ASSERT(resource->action);
14395 return mlx5_list_unregister(priv->sh->dest_array_list,
14400 flow_dv_geneve_tlv_option_resource_release(struct rte_eth_dev *dev)
14402 struct mlx5_priv *priv = dev->data->dev_private;
14403 struct mlx5_dev_ctx_shared *sh = priv->sh;
14404 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
14405 sh->geneve_tlv_option_resource;
14406 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
14407 if (geneve_opt_resource) {
14408 if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
14409 __ATOMIC_RELAXED))) {
14410 claim_zero(mlx5_devx_cmd_destroy
14411 (geneve_opt_resource->obj));
14412 mlx5_free(sh->geneve_tlv_option_resource);
14413 sh->geneve_tlv_option_resource = NULL;
14416 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
14420 * Remove the flow from the NIC but keeps it in memory.
14421 * Lock free, (mutex should be acquired by caller).
14424 * Pointer to Ethernet device.
14425 * @param[in, out] flow
14426 * Pointer to flow structure.
14429 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
14431 struct mlx5_flow_handle *dh;
14432 uint32_t handle_idx;
14433 struct mlx5_priv *priv = dev->data->dev_private;
14437 handle_idx = flow->dev_handles;
14438 while (handle_idx) {
14439 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14443 if (dh->drv_flow) {
14444 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
14445 dh->drv_flow = NULL;
14447 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
14448 flow_dv_fate_resource_release(dev, dh);
14449 if (dh->vf_vlan.tag && dh->vf_vlan.created)
14450 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
14451 handle_idx = dh->next.next;
14456 * Remove the flow from the NIC and the memory.
14457 * Lock free, (mutex should be acquired by caller).
14460 * Pointer to the Ethernet device structure.
14461 * @param[in, out] flow
14462 * Pointer to flow structure.
14465 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
14467 struct mlx5_flow_handle *dev_handle;
14468 struct mlx5_priv *priv = dev->data->dev_private;
14469 struct mlx5_flow_meter_info *fm = NULL;
14474 flow_dv_remove(dev, flow);
14475 if (flow->counter) {
14476 flow_dv_counter_free(dev, flow->counter);
14480 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
14482 mlx5_flow_meter_detach(priv, fm);
14485 /* Keep the current age handling by default. */
14486 if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
14487 flow_dv_aso_ct_release(dev, flow->ct, NULL);
14488 else if (flow->age)
14489 flow_dv_aso_age_release(dev, flow->age);
14490 if (flow->geneve_tlv_option) {
14491 flow_dv_geneve_tlv_option_resource_release(dev);
14492 flow->geneve_tlv_option = 0;
14494 while (flow->dev_handles) {
14495 uint32_t tmp_idx = flow->dev_handles;
14497 dev_handle = mlx5_ipool_get(priv->sh->ipool
14498 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
14501 flow->dev_handles = dev_handle->next.next;
14502 while (dev_handle->flex_item) {
14503 int index = rte_bsf32(dev_handle->flex_item);
14505 mlx5_flex_release_index(dev, index);
14506 dev_handle->flex_item &= ~RTE_BIT32(index);
14508 if (dev_handle->dvh.matcher)
14509 flow_dv_matcher_release(dev, dev_handle);
14510 if (dev_handle->dvh.rix_sample)
14511 flow_dv_sample_resource_release(dev, dev_handle);
14512 if (dev_handle->dvh.rix_dest_array)
14513 flow_dv_dest_array_resource_release(dev, dev_handle);
14514 if (dev_handle->dvh.rix_encap_decap)
14515 flow_dv_encap_decap_resource_release(dev,
14516 dev_handle->dvh.rix_encap_decap);
14517 if (dev_handle->dvh.modify_hdr)
14518 flow_dv_modify_hdr_resource_release(dev, dev_handle);
14519 if (dev_handle->dvh.rix_push_vlan)
14520 flow_dv_push_vlan_action_resource_release(dev,
14522 if (dev_handle->dvh.rix_tag)
14523 flow_dv_tag_release(dev,
14524 dev_handle->dvh.rix_tag);
14525 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
14526 flow_dv_fate_resource_release(dev, dev_handle);
14528 srss = dev_handle->rix_srss;
14529 if (fm && dev_handle->is_meter_flow_id &&
14530 dev_handle->split_flow_id)
14531 mlx5_ipool_free(fm->flow_ipool,
14532 dev_handle->split_flow_id);
14533 else if (dev_handle->split_flow_id &&
14534 !dev_handle->is_meter_flow_id)
14535 mlx5_ipool_free(priv->sh->ipool
14536 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
14537 dev_handle->split_flow_id);
14538 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14542 flow_dv_shared_rss_action_release(dev, srss);
14546 * Release array of hash RX queue objects.
14550 * Pointer to the Ethernet device structure.
14551 * @param[in, out] hrxqs
14552 * Array of hash RX queue objects.
14555 * Total number of references to hash RX queue objects in *hrxqs* array
14556 * after this operation.
14559 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
14560 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
14565 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
14566 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
14576 * Release all hash RX queue objects representing shared RSS action.
14579 * Pointer to the Ethernet device structure.
14580 * @param[in, out] action
14581 * Shared RSS action to remove hash RX queue objects from.
14584 * Total number of references to hash RX queue objects stored in *action*
14585 * after this operation.
14586 * Expected to be 0 if no external references held.
14589 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
14590 struct mlx5_shared_action_rss *shared_rss)
14592 return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
14596 * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
14599 * Only one hash value is available for one L3+L4 combination:
14601 * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
14602 * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
14603 * same slot in mlx5_rss_hash_fields.
14606 * Pointer to the shared action RSS conf.
14607 * @param[in, out] hash_field
14608 * hash_field variable needed to be adjusted.
14614 __flow_dv_action_rss_l34_hash_adjust(struct mlx5_shared_action_rss *rss,
14615 uint64_t *hash_field)
14617 uint64_t rss_types = rss->origin.types;
14619 switch (*hash_field & ~IBV_RX_HASH_INNER) {
14620 case MLX5_RSS_HASH_IPV4:
14621 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
14622 *hash_field &= ~MLX5_RSS_HASH_IPV4;
14623 if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
14624 *hash_field |= IBV_RX_HASH_DST_IPV4;
14625 else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
14626 *hash_field |= IBV_RX_HASH_SRC_IPV4;
14628 *hash_field |= MLX5_RSS_HASH_IPV4;
14631 case MLX5_RSS_HASH_IPV6:
14632 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
14633 *hash_field &= ~MLX5_RSS_HASH_IPV6;
14634 if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
14635 *hash_field |= IBV_RX_HASH_DST_IPV6;
14636 else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
14637 *hash_field |= IBV_RX_HASH_SRC_IPV6;
14639 *hash_field |= MLX5_RSS_HASH_IPV6;
14642 case MLX5_RSS_HASH_IPV4_UDP:
14643 /* fall-through. */
14644 case MLX5_RSS_HASH_IPV6_UDP:
14645 if (rss_types & RTE_ETH_RSS_UDP) {
14646 *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
14647 if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
14648 *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
14649 else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
14650 *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
14652 *hash_field |= MLX5_UDP_IBV_RX_HASH;
14655 case MLX5_RSS_HASH_IPV4_TCP:
14656 /* fall-through. */
14657 case MLX5_RSS_HASH_IPV6_TCP:
14658 if (rss_types & RTE_ETH_RSS_TCP) {
14659 *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
14660 if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
14661 *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
14662 else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
14663 *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
14665 *hash_field |= MLX5_TCP_IBV_RX_HASH;
14674 * Setup shared RSS action.
14675 * Prepare set of hash RX queue objects sufficient to handle all valid
14676 * hash_fields combinations (see enum ibv_rx_hash_fields).
14679 * Pointer to the Ethernet device structure.
14680 * @param[in] action_idx
14681 * Shared RSS action ipool index.
14682 * @param[in, out] action
14683 * Partially initialized shared RSS action.
14684 * @param[out] error
14685 * Perform verbose error reporting if not NULL. Initialized in case of
14689 * 0 on success, otherwise negative errno value.
14692 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
14693 uint32_t action_idx,
14694 struct mlx5_shared_action_rss *shared_rss,
14695 struct rte_flow_error *error)
14697 struct mlx5_flow_rss_desc rss_desc = { 0 };
14701 if (mlx5_ind_table_obj_setup(dev, shared_rss->ind_tbl,
14702 !!dev->data->dev_started)) {
14703 return rte_flow_error_set(error, rte_errno,
14704 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14705 "cannot setup indirection table");
14707 memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
14708 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
14709 rss_desc.const_q = shared_rss->origin.queue;
14710 rss_desc.queue_num = shared_rss->origin.queue_num;
14711 /* Set non-zero value to indicate a shared RSS. */
14712 rss_desc.shared_rss = action_idx;
14713 rss_desc.ind_tbl = shared_rss->ind_tbl;
14714 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
14716 uint64_t hash_fields = mlx5_rss_hash_fields[i];
14719 __flow_dv_action_rss_l34_hash_adjust(shared_rss, &hash_fields);
14720 if (shared_rss->origin.level > 1) {
14721 hash_fields |= IBV_RX_HASH_INNER;
14724 rss_desc.tunnel = tunnel;
14725 rss_desc.hash_fields = hash_fields;
14726 hrxq_idx = mlx5_hrxq_get(dev, &rss_desc);
14730 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14731 "cannot get hash queue");
14732 goto error_hrxq_new;
14734 err = __flow_dv_action_rss_hrxq_set
14735 (shared_rss, hash_fields, hrxq_idx);
14741 __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14742 if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true, true))
14743 shared_rss->ind_tbl = NULL;
14749 * Create shared RSS action.
14752 * Pointer to the Ethernet device structure.
14754 * Shared action configuration.
14756 * RSS action specification used to create shared action.
14757 * @param[out] error
14758 * Perform verbose error reporting if not NULL. Initialized in case of
14762 * A valid shared action ID in case of success, 0 otherwise and
14763 * rte_errno is set.
14766 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
14767 const struct rte_flow_indir_action_conf *conf,
14768 const struct rte_flow_action_rss *rss,
14769 struct rte_flow_error *error)
14771 struct mlx5_priv *priv = dev->data->dev_private;
14772 struct mlx5_shared_action_rss *shared_rss = NULL;
14773 void *queue = NULL;
14774 struct rte_flow_action_rss *origin;
14775 const uint8_t *rss_key;
14776 uint32_t queue_size = rss->queue_num * sizeof(uint16_t);
14779 RTE_SET_USED(conf);
14780 queue = mlx5_malloc(0, RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14782 shared_rss = mlx5_ipool_zmalloc
14783 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
14784 if (!shared_rss || !queue) {
14785 rte_flow_error_set(error, ENOMEM,
14786 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14787 "cannot allocate resource memory");
14788 goto error_rss_init;
14790 if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
14791 rte_flow_error_set(error, E2BIG,
14792 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14793 "rss action number out of range");
14794 goto error_rss_init;
14796 shared_rss->ind_tbl = mlx5_malloc(MLX5_MEM_ZERO,
14797 sizeof(*shared_rss->ind_tbl),
14799 if (!shared_rss->ind_tbl) {
14800 rte_flow_error_set(error, ENOMEM,
14801 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14802 "cannot allocate resource memory");
14803 goto error_rss_init;
14805 memcpy(queue, rss->queue, queue_size);
14806 shared_rss->ind_tbl->queues = queue;
14807 shared_rss->ind_tbl->queues_n = rss->queue_num;
14808 origin = &shared_rss->origin;
14809 origin->func = rss->func;
14810 origin->level = rss->level;
14811 /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
14812 origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
14813 /* NULL RSS key indicates default RSS key. */
14814 rss_key = !rss->key ? rss_hash_default_key : rss->key;
14815 memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
14816 origin->key = &shared_rss->key[0];
14817 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
14818 origin->queue = queue;
14819 origin->queue_num = rss->queue_num;
14820 if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
14821 goto error_rss_init;
14822 rte_spinlock_init(&shared_rss->action_rss_sl);
14823 __atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14824 rte_spinlock_lock(&priv->shared_act_sl);
14825 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14826 &priv->rss_shared_actions, idx, shared_rss, next);
14827 rte_spinlock_unlock(&priv->shared_act_sl);
14831 if (shared_rss->ind_tbl)
14832 mlx5_free(shared_rss->ind_tbl);
14833 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14842 * Destroy the shared RSS action.
14843 * Release related hash RX queue objects.
14846 * Pointer to the Ethernet device structure.
14848 * The shared RSS action object ID to be removed.
14849 * @param[out] error
14850 * Perform verbose error reporting if not NULL. Initialized in case of
14854 * 0 on success, otherwise negative errno value.
14857 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
14858 struct rte_flow_error *error)
14860 struct mlx5_priv *priv = dev->data->dev_private;
14861 struct mlx5_shared_action_rss *shared_rss =
14862 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14863 uint32_t old_refcnt = 1;
14865 uint16_t *queue = NULL;
14868 return rte_flow_error_set(error, EINVAL,
14869 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14870 "invalid shared action");
14871 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
14872 0, 0, __ATOMIC_ACQUIRE,
14874 return rte_flow_error_set(error, EBUSY,
14875 RTE_FLOW_ERROR_TYPE_ACTION,
14877 "shared rss has references");
14878 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14880 return rte_flow_error_set(error, EBUSY,
14881 RTE_FLOW_ERROR_TYPE_ACTION,
14883 "shared rss hrxq has references");
14884 queue = shared_rss->ind_tbl->queues;
14885 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true,
14886 !!dev->data->dev_started);
14888 return rte_flow_error_set(error, EBUSY,
14889 RTE_FLOW_ERROR_TYPE_ACTION,
14891 "shared rss indirection table has"
14894 rte_spinlock_lock(&priv->shared_act_sl);
14895 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14896 &priv->rss_shared_actions, idx, shared_rss, next);
14897 rte_spinlock_unlock(&priv->shared_act_sl);
14898 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14904 * Create indirect action, lock free,
14905 * (mutex should be acquired by caller).
14906 * Dispatcher for action type specific call.
14909 * Pointer to the Ethernet device structure.
14911 * Shared action configuration.
14912 * @param[in] action
14913 * Action specification used to create indirect action.
14914 * @param[out] error
14915 * Perform verbose error reporting if not NULL. Initialized in case of
14919 * A valid shared action handle in case of success, NULL otherwise and
14920 * rte_errno is set.
14922 static struct rte_flow_action_handle *
14923 flow_dv_action_create(struct rte_eth_dev *dev,
14924 const struct rte_flow_indir_action_conf *conf,
14925 const struct rte_flow_action *action,
14926 struct rte_flow_error *err)
14928 struct mlx5_priv *priv = dev->data->dev_private;
14929 uint32_t age_idx = 0;
14933 switch (action->type) {
14934 case RTE_FLOW_ACTION_TYPE_RSS:
14935 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
14936 idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
14937 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14939 case RTE_FLOW_ACTION_TYPE_AGE:
14940 age_idx = flow_dv_aso_age_alloc(dev, err);
14945 idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
14946 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
14947 flow_dv_aso_age_params_init(dev, age_idx,
14948 ((const struct rte_flow_action_age *)
14949 action->conf)->context ?
14950 ((const struct rte_flow_action_age *)
14951 action->conf)->context :
14952 (void *)(uintptr_t)idx,
14953 ((const struct rte_flow_action_age *)
14954 action->conf)->timeout);
14957 case RTE_FLOW_ACTION_TYPE_COUNT:
14958 ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
14959 idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
14960 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14962 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
14963 ret = flow_dv_translate_create_conntrack(dev, action->conf,
14965 idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
14968 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
14969 NULL, "action type not supported");
14972 return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
14976 * Destroy the indirect action.
14977 * Release action related resources on the NIC and the memory.
14978 * Lock free, (mutex should be acquired by caller).
14979 * Dispatcher for action type specific call.
14982 * Pointer to the Ethernet device structure.
14983 * @param[in] handle
14984 * The indirect action object handle to be removed.
14985 * @param[out] error
14986 * Perform verbose error reporting if not NULL. Initialized in case of
14990 * 0 on success, otherwise negative errno value.
14993 flow_dv_action_destroy(struct rte_eth_dev *dev,
14994 struct rte_flow_action_handle *handle,
14995 struct rte_flow_error *error)
14997 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14998 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14999 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15000 struct mlx5_flow_counter *cnt;
15001 uint32_t no_flow_refcnt = 1;
15005 case MLX5_INDIRECT_ACTION_TYPE_RSS:
15006 return __flow_dv_action_rss_release(dev, idx, error);
15007 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15008 cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
15009 if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
15010 &no_flow_refcnt, 1, false,
15013 return rte_flow_error_set(error, EBUSY,
15014 RTE_FLOW_ERROR_TYPE_ACTION,
15016 "Indirect count action has references");
15017 flow_dv_counter_free(dev, idx);
15019 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15020 ret = flow_dv_aso_age_release(dev, idx);
15023 * In this case, the last flow has a reference will
15024 * actually release the age action.
15026 DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
15027 " released with references %d.", idx, ret);
15029 case MLX5_INDIRECT_ACTION_TYPE_CT:
15030 ret = flow_dv_aso_ct_release(dev, idx, error);
15034 DRV_LOG(DEBUG, "Connection tracking object %u still "
15035 "has references %d.", idx, ret);
15038 return rte_flow_error_set(error, ENOTSUP,
15039 RTE_FLOW_ERROR_TYPE_ACTION,
15041 "action type not supported");
15046 * Updates in place shared RSS action configuration.
15049 * Pointer to the Ethernet device structure.
15051 * The shared RSS action object ID to be updated.
15052 * @param[in] action_conf
15053 * RSS action specification used to modify *shared_rss*.
15054 * @param[out] error
15055 * Perform verbose error reporting if not NULL. Initialized in case of
15059 * 0 on success, otherwise negative errno value.
15060 * @note: currently only support update of RSS queues.
15063 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
15064 const struct rte_flow_action_rss *action_conf,
15065 struct rte_flow_error *error)
15067 struct mlx5_priv *priv = dev->data->dev_private;
15068 struct mlx5_shared_action_rss *shared_rss =
15069 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
15071 void *queue = NULL;
15072 uint16_t *queue_old = NULL;
15073 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
15074 bool dev_started = !!dev->data->dev_started;
15077 return rte_flow_error_set(error, EINVAL,
15078 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15079 "invalid shared action to update");
15080 if (priv->obj_ops.ind_table_modify == NULL)
15081 return rte_flow_error_set(error, ENOTSUP,
15082 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15083 "cannot modify indirection table");
15084 queue = mlx5_malloc(MLX5_MEM_ZERO,
15085 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
15088 return rte_flow_error_set(error, ENOMEM,
15089 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15091 "cannot allocate resource memory");
15092 memcpy(queue, action_conf->queue, queue_size);
15093 MLX5_ASSERT(shared_rss->ind_tbl);
15094 rte_spinlock_lock(&shared_rss->action_rss_sl);
15095 queue_old = shared_rss->ind_tbl->queues;
15096 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
15097 queue, action_conf->queue_num,
15098 true /* standalone */,
15099 dev_started /* ref_new_qs */,
15100 dev_started /* deref_old_qs */);
15103 ret = rte_flow_error_set(error, rte_errno,
15104 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15105 "cannot update indirection table");
15107 mlx5_free(queue_old);
15108 shared_rss->origin.queue = queue;
15109 shared_rss->origin.queue_num = action_conf->queue_num;
15111 rte_spinlock_unlock(&shared_rss->action_rss_sl);
15116 * Updates in place conntrack context or direction.
15117 * Context update should be synchronized.
15120 * Pointer to the Ethernet device structure.
15122 * The conntrack object ID to be updated.
15123 * @param[in] update
15124 * Pointer to the structure of information to update.
15125 * @param[out] error
15126 * Perform verbose error reporting if not NULL. Initialized in case of
15130 * 0 on success, otherwise negative errno value.
15133 __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
15134 const struct rte_flow_modify_conntrack *update,
15135 struct rte_flow_error *error)
15137 struct mlx5_priv *priv = dev->data->dev_private;
15138 struct mlx5_aso_ct_action *ct;
15139 const struct rte_flow_action_conntrack *new_prf;
15141 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
15144 if (PORT_ID(priv) != owner)
15145 return rte_flow_error_set(error, EACCES,
15146 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15148 "CT object owned by another port");
15149 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
15150 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
15152 return rte_flow_error_set(error, ENOMEM,
15153 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15155 "CT object is inactive");
15156 new_prf = &update->new_ct;
15157 if (update->direction)
15158 ct->is_original = !!new_prf->is_original_dir;
15159 if (update->state) {
15160 /* Only validate the profile when it needs to be updated. */
15161 ret = mlx5_validate_action_ct(dev, new_prf, error);
15164 ret = mlx5_aso_ct_update_by_wqe(priv->sh, ct, new_prf);
15166 return rte_flow_error_set(error, EIO,
15167 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15169 "Failed to send CT context update WQE");
15170 /* Block until ready or a failure. */
15171 ret = mlx5_aso_ct_available(priv->sh, ct);
15173 rte_flow_error_set(error, rte_errno,
15174 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15176 "Timeout to get the CT update");
15182 * Updates in place shared action configuration, lock free,
15183 * (mutex should be acquired by caller).
15186 * Pointer to the Ethernet device structure.
15187 * @param[in] handle
15188 * The indirect action object handle to be updated.
15189 * @param[in] update
15190 * Action specification used to modify the action pointed by *handle*.
15191 * *update* could be of same type with the action pointed by the *handle*
15192 * handle argument, or some other structures like a wrapper, depending on
15193 * the indirect action type.
15194 * @param[out] error
15195 * Perform verbose error reporting if not NULL. Initialized in case of
15199 * 0 on success, otherwise negative errno value.
15202 flow_dv_action_update(struct rte_eth_dev *dev,
15203 struct rte_flow_action_handle *handle,
15204 const void *update,
15205 struct rte_flow_error *err)
15207 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15208 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15209 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15210 const void *action_conf;
15213 case MLX5_INDIRECT_ACTION_TYPE_RSS:
15214 action_conf = ((const struct rte_flow_action *)update)->conf;
15215 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
15216 case MLX5_INDIRECT_ACTION_TYPE_CT:
15217 return __flow_dv_action_ct_update(dev, idx, update, err);
15219 return rte_flow_error_set(err, ENOTSUP,
15220 RTE_FLOW_ERROR_TYPE_ACTION,
15222 "action type update not supported");
15227 * Destroy the meter sub policy table rules.
15228 * Lock free, (mutex should be acquired by caller).
15231 * Pointer to Ethernet device.
15232 * @param[in] sub_policy
15233 * Pointer to meter sub policy table.
15236 __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
15237 struct mlx5_flow_meter_sub_policy *sub_policy)
15239 struct mlx5_priv *priv = dev->data->dev_private;
15240 struct mlx5_flow_tbl_data_entry *tbl;
15241 struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
15242 struct mlx5_flow_meter_info *next_fm;
15243 struct mlx5_sub_policy_color_rule *color_rule;
15247 for (i = 0; i < RTE_COLORS; i++) {
15249 if (i == RTE_COLOR_GREEN && policy &&
15250 policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
15251 next_fm = mlx5_flow_meter_find(priv,
15252 policy->act_cnt[i].next_mtr_id, NULL);
15253 RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
15255 claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
15256 tbl = container_of(color_rule->matcher->tbl,
15257 typeof(*tbl), tbl);
15258 mlx5_list_unregister(tbl->matchers,
15259 &color_rule->matcher->entry);
15260 TAILQ_REMOVE(&sub_policy->color_rules[i],
15261 color_rule, next_port);
15262 mlx5_free(color_rule);
15264 mlx5_flow_meter_detach(priv, next_fm);
15267 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15268 if (sub_policy->rix_hrxq[i]) {
15269 if (policy && !policy->is_hierarchy)
15270 mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
15271 sub_policy->rix_hrxq[i] = 0;
15273 if (sub_policy->jump_tbl[i]) {
15274 flow_dv_tbl_resource_release(MLX5_SH(dev),
15275 sub_policy->jump_tbl[i]);
15276 sub_policy->jump_tbl[i] = NULL;
15279 if (sub_policy->tbl_rsc) {
15280 flow_dv_tbl_resource_release(MLX5_SH(dev),
15281 sub_policy->tbl_rsc);
15282 sub_policy->tbl_rsc = NULL;
15287 * Destroy policy rules, lock free,
15288 * (mutex should be acquired by caller).
15289 * Dispatcher for action type specific call.
15292 * Pointer to the Ethernet device structure.
15293 * @param[in] mtr_policy
15294 * Meter policy struct.
15297 flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
15298 struct mlx5_flow_meter_policy *mtr_policy)
15301 struct mlx5_flow_meter_sub_policy *sub_policy;
15302 uint16_t sub_policy_num;
15304 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15305 sub_policy_num = (mtr_policy->sub_policy_num >>
15306 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15307 MLX5_MTR_SUB_POLICY_NUM_MASK;
15308 for (j = 0; j < sub_policy_num; j++) {
15309 sub_policy = mtr_policy->sub_policys[i][j];
15311 __flow_dv_destroy_sub_policy_rules(dev,
15318 * Destroy policy action, lock free,
15319 * (mutex should be acquired by caller).
15320 * Dispatcher for action type specific call.
15323 * Pointer to the Ethernet device structure.
15324 * @param[in] mtr_policy
15325 * Meter policy struct.
15328 flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
15329 struct mlx5_flow_meter_policy *mtr_policy)
15331 struct rte_flow_action *rss_action;
15332 struct mlx5_flow_handle dev_handle;
15335 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15336 if (mtr_policy->act_cnt[i].rix_mark) {
15337 flow_dv_tag_release(dev,
15338 mtr_policy->act_cnt[i].rix_mark);
15339 mtr_policy->act_cnt[i].rix_mark = 0;
15341 if (mtr_policy->act_cnt[i].modify_hdr) {
15342 dev_handle.dvh.modify_hdr =
15343 mtr_policy->act_cnt[i].modify_hdr;
15344 flow_dv_modify_hdr_resource_release(dev, &dev_handle);
15346 switch (mtr_policy->act_cnt[i].fate_action) {
15347 case MLX5_FLOW_FATE_SHARED_RSS:
15348 rss_action = mtr_policy->act_cnt[i].rss;
15349 mlx5_free(rss_action);
15351 case MLX5_FLOW_FATE_PORT_ID:
15352 if (mtr_policy->act_cnt[i].rix_port_id_action) {
15353 flow_dv_port_id_action_resource_release(dev,
15354 mtr_policy->act_cnt[i].rix_port_id_action);
15355 mtr_policy->act_cnt[i].rix_port_id_action = 0;
15358 case MLX5_FLOW_FATE_DROP:
15359 case MLX5_FLOW_FATE_JUMP:
15360 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15361 mtr_policy->act_cnt[i].dr_jump_action[j] =
15365 /*Queue action do nothing*/
15369 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15370 mtr_policy->dr_drop_action[j] = NULL;
15374 * Create policy action per domain, lock free,
15375 * (mutex should be acquired by caller).
15376 * Dispatcher for action type specific call.
15379 * Pointer to the Ethernet device structure.
15380 * @param[in] mtr_policy
15381 * Meter policy struct.
15382 * @param[in] action
15383 * Action specification used to create meter actions.
15384 * @param[out] error
15385 * Perform verbose error reporting if not NULL. Initialized in case of
15389 * 0 on success, otherwise negative errno value.
15392 __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
15393 struct mlx5_flow_meter_policy *mtr_policy,
15394 const struct rte_flow_action *actions[RTE_COLORS],
15395 enum mlx5_meter_domain domain,
15396 struct rte_mtr_error *error)
15398 struct mlx5_priv *priv = dev->data->dev_private;
15399 struct rte_flow_error flow_err;
15400 const struct rte_flow_action *act;
15401 uint64_t action_flags;
15402 struct mlx5_flow_handle dh;
15403 struct mlx5_flow dev_flow;
15404 struct mlx5_flow_dv_port_id_action_resource port_id_action;
15406 uint8_t egress, transfer;
15407 struct mlx5_meter_policy_action_container *act_cnt = NULL;
15409 struct mlx5_flow_dv_modify_hdr_resource res;
15410 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
15411 sizeof(struct mlx5_modification_cmd) *
15412 (MLX5_MAX_MODIFY_NUM + 1)];
15414 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
15415 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15418 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15419 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15420 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
15421 memset(&dev_flow, 0, sizeof(struct mlx5_flow));
15422 memset(&port_id_action, 0,
15423 sizeof(struct mlx5_flow_dv_port_id_action_resource));
15424 memset(mhdr_res, 0, sizeof(*mhdr_res));
15425 mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
15426 (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15427 MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
15428 dev_flow.handle = &dh;
15429 dev_flow.dv.port_id_action = &port_id_action;
15430 dev_flow.external = true;
15431 for (i = 0; i < RTE_COLORS; i++) {
15432 if (i < MLX5_MTR_RTE_COLORS)
15433 act_cnt = &mtr_policy->act_cnt[i];
15434 /* Skip the color policy actions creation. */
15435 if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
15436 (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
15439 for (act = actions[i];
15440 act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
15441 switch (act->type) {
15442 case RTE_FLOW_ACTION_TYPE_MARK:
15444 uint32_t tag_be = mlx5_flow_mark_set
15445 (((const struct rte_flow_action_mark *)
15448 if (i >= MLX5_MTR_RTE_COLORS)
15449 return -rte_mtr_error_set(error,
15451 RTE_MTR_ERROR_TYPE_METER_POLICY,
15453 "cannot create policy "
15454 "mark action for this color");
15456 if (flow_dv_tag_resource_register(dev, tag_be,
15457 &dev_flow, &flow_err))
15458 return -rte_mtr_error_set(error,
15460 RTE_MTR_ERROR_TYPE_METER_POLICY,
15462 "cannot setup policy mark action");
15463 MLX5_ASSERT(dev_flow.dv.tag_resource);
15464 act_cnt->rix_mark =
15465 dev_flow.handle->dvh.rix_tag;
15466 action_flags |= MLX5_FLOW_ACTION_MARK;
15469 case RTE_FLOW_ACTION_TYPE_SET_TAG:
15470 if (i >= MLX5_MTR_RTE_COLORS)
15471 return -rte_mtr_error_set(error,
15473 RTE_MTR_ERROR_TYPE_METER_POLICY,
15475 "cannot create policy "
15476 "set tag action for this color");
15477 if (flow_dv_convert_action_set_tag
15479 (const struct rte_flow_action_set_tag *)
15480 act->conf, &flow_err))
15481 return -rte_mtr_error_set(error,
15483 RTE_MTR_ERROR_TYPE_METER_POLICY,
15484 NULL, "cannot convert policy "
15486 if (!mhdr_res->actions_num)
15487 return -rte_mtr_error_set(error,
15489 RTE_MTR_ERROR_TYPE_METER_POLICY,
15490 NULL, "cannot find policy "
15492 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15494 case RTE_FLOW_ACTION_TYPE_DROP:
15496 struct mlx5_flow_mtr_mng *mtrmng =
15498 struct mlx5_flow_tbl_data_entry *tbl_data;
15501 * Create the drop table with
15502 * METER DROP level.
15504 if (!mtrmng->drop_tbl[domain]) {
15505 mtrmng->drop_tbl[domain] =
15506 flow_dv_tbl_resource_get(dev,
15507 MLX5_FLOW_TABLE_LEVEL_METER,
15508 egress, transfer, false, NULL, 0,
15509 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
15510 if (!mtrmng->drop_tbl[domain])
15511 return -rte_mtr_error_set
15513 RTE_MTR_ERROR_TYPE_METER_POLICY,
15515 "Failed to create meter drop table");
15517 tbl_data = container_of
15518 (mtrmng->drop_tbl[domain],
15519 struct mlx5_flow_tbl_data_entry, tbl);
15520 if (i < MLX5_MTR_RTE_COLORS) {
15521 act_cnt->dr_jump_action[domain] =
15522 tbl_data->jump.action;
15523 act_cnt->fate_action =
15524 MLX5_FLOW_FATE_DROP;
15526 if (i == RTE_COLOR_RED)
15527 mtr_policy->dr_drop_action[domain] =
15528 tbl_data->jump.action;
15529 action_flags |= MLX5_FLOW_ACTION_DROP;
15532 case RTE_FLOW_ACTION_TYPE_QUEUE:
15534 if (i >= MLX5_MTR_RTE_COLORS)
15535 return -rte_mtr_error_set(error,
15537 RTE_MTR_ERROR_TYPE_METER_POLICY,
15538 NULL, "cannot create policy "
15539 "fate queue for this color");
15541 ((const struct rte_flow_action_queue *)
15542 (act->conf))->index;
15543 act_cnt->fate_action =
15544 MLX5_FLOW_FATE_QUEUE;
15545 dev_flow.handle->fate_action =
15546 MLX5_FLOW_FATE_QUEUE;
15547 mtr_policy->is_queue = 1;
15548 action_flags |= MLX5_FLOW_ACTION_QUEUE;
15551 case RTE_FLOW_ACTION_TYPE_RSS:
15555 if (i >= MLX5_MTR_RTE_COLORS)
15556 return -rte_mtr_error_set(error,
15558 RTE_MTR_ERROR_TYPE_METER_POLICY,
15560 "cannot create policy "
15561 "rss action for this color");
15563 * Save RSS conf into policy struct
15564 * for translate stage.
15566 rss_size = (int)rte_flow_conv
15567 (RTE_FLOW_CONV_OP_ACTION,
15568 NULL, 0, act, &flow_err);
15570 return -rte_mtr_error_set(error,
15572 RTE_MTR_ERROR_TYPE_METER_POLICY,
15573 NULL, "Get the wrong "
15574 "rss action struct size");
15575 act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
15576 rss_size, 0, SOCKET_ID_ANY);
15578 return -rte_mtr_error_set(error,
15580 RTE_MTR_ERROR_TYPE_METER_POLICY,
15582 "Fail to malloc rss action memory");
15583 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
15584 act_cnt->rss, rss_size,
15587 return -rte_mtr_error_set(error,
15589 RTE_MTR_ERROR_TYPE_METER_POLICY,
15590 NULL, "Fail to save "
15591 "rss action into policy struct");
15592 act_cnt->fate_action =
15593 MLX5_FLOW_FATE_SHARED_RSS;
15594 action_flags |= MLX5_FLOW_ACTION_RSS;
15597 case RTE_FLOW_ACTION_TYPE_PORT_ID:
15598 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15600 struct mlx5_flow_dv_port_id_action_resource
15602 uint32_t port_id = 0;
15604 if (i >= MLX5_MTR_RTE_COLORS)
15605 return -rte_mtr_error_set(error,
15607 RTE_MTR_ERROR_TYPE_METER_POLICY,
15608 NULL, "cannot create policy "
15609 "port action for this color");
15610 memset(&port_id_resource, 0,
15611 sizeof(port_id_resource));
15612 if (flow_dv_translate_action_port_id(dev, act,
15613 &port_id, &flow_err))
15614 return -rte_mtr_error_set(error,
15616 RTE_MTR_ERROR_TYPE_METER_POLICY,
15617 NULL, "cannot translate "
15618 "policy port action");
15619 port_id_resource.port_id = port_id;
15620 if (flow_dv_port_id_action_resource_register
15621 (dev, &port_id_resource,
15622 &dev_flow, &flow_err))
15623 return -rte_mtr_error_set(error,
15625 RTE_MTR_ERROR_TYPE_METER_POLICY,
15626 NULL, "cannot setup "
15627 "policy port action");
15628 act_cnt->rix_port_id_action =
15629 dev_flow.handle->rix_port_id_action;
15630 act_cnt->fate_action =
15631 MLX5_FLOW_FATE_PORT_ID;
15632 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15635 case RTE_FLOW_ACTION_TYPE_JUMP:
15637 uint32_t jump_group = 0;
15638 uint32_t table = 0;
15639 struct mlx5_flow_tbl_data_entry *tbl_data;
15640 struct flow_grp_info grp_info = {
15641 .external = !!dev_flow.external,
15642 .transfer = !!transfer,
15643 .fdb_def_rule = !!priv->fdb_def_rule,
15645 .skip_scale = dev_flow.skip_scale &
15646 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
15648 struct mlx5_flow_meter_sub_policy *sub_policy =
15649 mtr_policy->sub_policys[domain][0];
15651 if (i >= MLX5_MTR_RTE_COLORS)
15652 return -rte_mtr_error_set(error,
15654 RTE_MTR_ERROR_TYPE_METER_POLICY,
15656 "cannot create policy "
15657 "jump action for this color");
15659 ((const struct rte_flow_action_jump *)
15661 if (mlx5_flow_group_to_table(dev, NULL,
15664 &grp_info, &flow_err))
15665 return -rte_mtr_error_set(error,
15667 RTE_MTR_ERROR_TYPE_METER_POLICY,
15668 NULL, "cannot setup "
15669 "policy jump action");
15670 sub_policy->jump_tbl[i] =
15671 flow_dv_tbl_resource_get(dev,
15674 !!dev_flow.external,
15675 NULL, jump_group, 0,
15678 (!sub_policy->jump_tbl[i])
15679 return -rte_mtr_error_set(error,
15681 RTE_MTR_ERROR_TYPE_METER_POLICY,
15682 NULL, "cannot create jump action.");
15683 tbl_data = container_of
15684 (sub_policy->jump_tbl[i],
15685 struct mlx5_flow_tbl_data_entry, tbl);
15686 act_cnt->dr_jump_action[domain] =
15687 tbl_data->jump.action;
15688 act_cnt->fate_action =
15689 MLX5_FLOW_FATE_JUMP;
15690 action_flags |= MLX5_FLOW_ACTION_JUMP;
15694 * No need to check meter hierarchy for Y or R colors
15695 * here since it is done in the validation stage.
15697 case RTE_FLOW_ACTION_TYPE_METER:
15699 const struct rte_flow_action_meter *mtr;
15700 struct mlx5_flow_meter_info *next_fm;
15701 struct mlx5_flow_meter_policy *next_policy;
15702 struct rte_flow_action tag_action;
15703 struct mlx5_rte_flow_action_set_tag set_tag;
15704 uint32_t next_mtr_idx = 0;
15707 next_fm = mlx5_flow_meter_find(priv,
15711 return -rte_mtr_error_set(error, EINVAL,
15712 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15713 "Fail to find next meter.");
15714 if (next_fm->def_policy)
15715 return -rte_mtr_error_set(error, EINVAL,
15716 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15717 "Hierarchy only supports termination meter.");
15718 next_policy = mlx5_flow_meter_policy_find(dev,
15719 next_fm->policy_id, NULL);
15720 MLX5_ASSERT(next_policy);
15721 if (next_fm->drop_cnt) {
15724 mlx5_flow_get_reg_id(dev,
15727 (struct rte_flow_error *)error);
15728 set_tag.offset = (priv->mtr_reg_share ?
15729 MLX5_MTR_COLOR_BITS : 0);
15730 set_tag.length = (priv->mtr_reg_share ?
15731 MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
15733 set_tag.data = next_mtr_idx;
15735 (enum rte_flow_action_type)
15736 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
15737 tag_action.conf = &set_tag;
15738 if (flow_dv_convert_action_set_reg
15739 (mhdr_res, &tag_action,
15740 (struct rte_flow_error *)error))
15743 MLX5_FLOW_ACTION_SET_TAG;
15745 act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
15746 act_cnt->next_mtr_id = next_fm->meter_id;
15747 act_cnt->next_sub_policy = NULL;
15748 mtr_policy->is_hierarchy = 1;
15749 mtr_policy->dev = next_policy->dev;
15751 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
15755 return -rte_mtr_error_set(error, ENOTSUP,
15756 RTE_MTR_ERROR_TYPE_METER_POLICY,
15757 NULL, "action type not supported");
15759 if (action_flags & MLX5_FLOW_ACTION_SET_TAG) {
15760 /* create modify action if needed. */
15761 dev_flow.dv.group = 1;
15762 if (flow_dv_modify_hdr_resource_register
15763 (dev, mhdr_res, &dev_flow, &flow_err))
15764 return -rte_mtr_error_set(error,
15766 RTE_MTR_ERROR_TYPE_METER_POLICY,
15767 NULL, "cannot register policy "
15769 act_cnt->modify_hdr =
15770 dev_flow.handle->dvh.modify_hdr;
15778 * Create policy action per domain, lock free,
15779 * (mutex should be acquired by caller).
15780 * Dispatcher for action type specific call.
15783 * Pointer to the Ethernet device structure.
15784 * @param[in] mtr_policy
15785 * Meter policy struct.
15786 * @param[in] action
15787 * Action specification used to create meter actions.
15788 * @param[out] error
15789 * Perform verbose error reporting if not NULL. Initialized in case of
15793 * 0 on success, otherwise negative errno value.
15796 flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
15797 struct mlx5_flow_meter_policy *mtr_policy,
15798 const struct rte_flow_action *actions[RTE_COLORS],
15799 struct rte_mtr_error *error)
15802 uint16_t sub_policy_num;
15804 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15805 sub_policy_num = (mtr_policy->sub_policy_num >>
15806 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15807 MLX5_MTR_SUB_POLICY_NUM_MASK;
15808 if (sub_policy_num) {
15809 ret = __flow_dv_create_domain_policy_acts(dev,
15810 mtr_policy, actions,
15811 (enum mlx5_meter_domain)i, error);
15812 /* Cleaning resource is done in the caller level. */
15821 * Query a DV flow rule for its statistics via DevX.
15824 * Pointer to Ethernet device.
15825 * @param[in] cnt_idx
15826 * Index to the flow counter.
15828 * Data retrieved by the query.
15829 * @param[out] error
15830 * Perform verbose error reporting if not NULL.
15833 * 0 on success, a negative errno value otherwise and rte_errno is set.
15836 flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
15837 struct rte_flow_error *error)
15839 struct mlx5_priv *priv = dev->data->dev_private;
15840 struct rte_flow_query_count *qc = data;
15842 if (!priv->sh->devx)
15843 return rte_flow_error_set(error, ENOTSUP,
15844 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15846 "counters are not supported");
15848 uint64_t pkts, bytes;
15849 struct mlx5_flow_counter *cnt;
15850 int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
15853 return rte_flow_error_set(error, -err,
15854 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15855 NULL, "cannot read counters");
15856 cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
15859 qc->hits = pkts - cnt->hits;
15860 qc->bytes = bytes - cnt->bytes;
15863 cnt->bytes = bytes;
15867 return rte_flow_error_set(error, EINVAL,
15868 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15870 "counters are not available");
15875 * Query counter's action pointer for a DV flow rule via DevX.
15878 * Pointer to Ethernet device.
15879 * @param[in] cnt_idx
15880 * Index to the flow counter.
15881 * @param[out] action_ptr
15882 * Action pointer for counter.
15883 * @param[out] error
15884 * Perform verbose error reporting if not NULL.
15887 * 0 on success, a negative errno value otherwise and rte_errno is set.
15890 flow_dv_query_count_ptr(struct rte_eth_dev *dev, uint32_t cnt_idx,
15891 void **action_ptr, struct rte_flow_error *error)
15893 struct mlx5_priv *priv = dev->data->dev_private;
15895 if (!priv->sh->devx || !action_ptr)
15896 return rte_flow_error_set(error, ENOTSUP,
15897 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15899 "counters are not supported");
15902 struct mlx5_flow_counter *cnt = NULL;
15903 cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
15905 *action_ptr = cnt->action;
15909 return rte_flow_error_set(error, EINVAL,
15910 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15912 "counters are not available");
15916 flow_dv_action_query(struct rte_eth_dev *dev,
15917 const struct rte_flow_action_handle *handle, void *data,
15918 struct rte_flow_error *error)
15920 struct mlx5_age_param *age_param;
15921 struct rte_flow_query_age *resp;
15922 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15923 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15924 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15925 struct mlx5_priv *priv = dev->data->dev_private;
15926 struct mlx5_aso_ct_action *ct;
15931 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15932 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
15934 resp->aged = __atomic_load_n(&age_param->state,
15935 __ATOMIC_RELAXED) == AGE_TMOUT ?
15937 resp->sec_since_last_hit_valid = !resp->aged;
15938 if (resp->sec_since_last_hit_valid)
15939 resp->sec_since_last_hit = __atomic_load_n
15940 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15942 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15943 return flow_dv_query_count(dev, idx, data, error);
15944 case MLX5_INDIRECT_ACTION_TYPE_CT:
15945 owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
15946 if (owner != PORT_ID(priv))
15947 return rte_flow_error_set(error, EACCES,
15948 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15950 "CT object owned by another port");
15951 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
15952 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
15955 return rte_flow_error_set(error, EFAULT,
15956 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15958 "CT object is inactive");
15959 ((struct rte_flow_action_conntrack *)data)->peer_port =
15961 ((struct rte_flow_action_conntrack *)data)->is_original_dir =
15963 if (mlx5_aso_ct_query_by_wqe(priv->sh, ct, data))
15964 return rte_flow_error_set(error, EIO,
15965 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15967 "Failed to query CT context");
15970 return rte_flow_error_set(error, ENOTSUP,
15971 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15972 "action type query not supported");
15977 * Query a flow rule AGE action for aging information.
15980 * Pointer to Ethernet device.
15982 * Pointer to the sub flow.
15984 * data retrieved by the query.
15985 * @param[out] error
15986 * Perform verbose error reporting if not NULL.
15989 * 0 on success, a negative errno value otherwise and rte_errno is set.
15992 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
15993 void *data, struct rte_flow_error *error)
15995 struct rte_flow_query_age *resp = data;
15996 struct mlx5_age_param *age_param;
15999 struct mlx5_aso_age_action *act =
16000 flow_aso_age_get_by_idx(dev, flow->age);
16002 age_param = &act->age_params;
16003 } else if (flow->counter) {
16004 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
16006 if (!age_param || !age_param->timeout)
16007 return rte_flow_error_set
16009 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16010 NULL, "cannot read age data");
16012 return rte_flow_error_set(error, EINVAL,
16013 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16014 NULL, "age data not available");
16016 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
16018 resp->sec_since_last_hit_valid = !resp->aged;
16019 if (resp->sec_since_last_hit_valid)
16020 resp->sec_since_last_hit = __atomic_load_n
16021 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
16028 * @see rte_flow_query()
16029 * @see rte_flow_ops
16032 flow_dv_query(struct rte_eth_dev *dev,
16033 struct rte_flow *flow __rte_unused,
16034 const struct rte_flow_action *actions __rte_unused,
16035 void *data __rte_unused,
16036 struct rte_flow_error *error __rte_unused)
16040 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
16041 switch (actions->type) {
16042 case RTE_FLOW_ACTION_TYPE_VOID:
16044 case RTE_FLOW_ACTION_TYPE_COUNT:
16045 ret = flow_dv_query_count(dev, flow->counter, data,
16048 case RTE_FLOW_ACTION_TYPE_AGE:
16049 ret = flow_dv_query_age(dev, flow, data, error);
16052 return rte_flow_error_set(error, ENOTSUP,
16053 RTE_FLOW_ERROR_TYPE_ACTION,
16055 "action not supported");
16062 * Destroy the meter table set.
16063 * Lock free, (mutex should be acquired by caller).
16066 * Pointer to Ethernet device.
16068 * Meter information table.
16071 flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
16072 struct mlx5_flow_meter_info *fm)
16074 struct mlx5_priv *priv = dev->data->dev_private;
16077 if (!fm || !priv->config.dv_flow_en)
16079 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16080 if (fm->drop_rule[i]) {
16081 claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
16082 fm->drop_rule[i] = NULL;
16088 flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
16090 struct mlx5_priv *priv = dev->data->dev_private;
16091 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16092 struct mlx5_flow_tbl_data_entry *tbl;
16095 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16096 if (mtrmng->def_rule[i]) {
16097 claim_zero(mlx5_flow_os_destroy_flow
16098 (mtrmng->def_rule[i]));
16099 mtrmng->def_rule[i] = NULL;
16101 if (mtrmng->def_matcher[i]) {
16102 tbl = container_of(mtrmng->def_matcher[i]->tbl,
16103 struct mlx5_flow_tbl_data_entry, tbl);
16104 mlx5_list_unregister(tbl->matchers,
16105 &mtrmng->def_matcher[i]->entry);
16106 mtrmng->def_matcher[i] = NULL;
16108 for (j = 0; j < MLX5_REG_BITS; j++) {
16109 if (mtrmng->drop_matcher[i][j]) {
16111 container_of(mtrmng->drop_matcher[i][j]->tbl,
16112 struct mlx5_flow_tbl_data_entry,
16114 mlx5_list_unregister(tbl->matchers,
16115 &mtrmng->drop_matcher[i][j]->entry);
16116 mtrmng->drop_matcher[i][j] = NULL;
16119 if (mtrmng->drop_tbl[i]) {
16120 flow_dv_tbl_resource_release(MLX5_SH(dev),
16121 mtrmng->drop_tbl[i]);
16122 mtrmng->drop_tbl[i] = NULL;
16127 /* Number of meter flow actions, count and jump or count and drop. */
16128 #define METER_ACTIONS 2
16131 __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
16132 enum mlx5_meter_domain domain)
16134 struct mlx5_priv *priv = dev->data->dev_private;
16135 struct mlx5_flow_meter_def_policy *def_policy =
16136 priv->sh->mtrmng->def_policy[domain];
16138 __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
16139 mlx5_free(def_policy);
16140 priv->sh->mtrmng->def_policy[domain] = NULL;
16144 * Destroy the default policy table set.
16147 * Pointer to Ethernet device.
16150 flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
16152 struct mlx5_priv *priv = dev->data->dev_private;
16155 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
16156 if (priv->sh->mtrmng->def_policy[i])
16157 __flow_dv_destroy_domain_def_policy(dev,
16158 (enum mlx5_meter_domain)i);
16159 priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
16163 __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
16164 uint32_t color_reg_c_idx,
16165 enum rte_color color, void *matcher_object,
16166 int actions_n, void *actions,
16167 bool match_src_port, const struct rte_flow_item *item,
16168 void **rule, const struct rte_flow_attr *attr)
16171 struct mlx5_flow_dv_match_params value = {
16172 .size = sizeof(value.buf),
16174 struct mlx5_flow_dv_match_params matcher = {
16175 .size = sizeof(matcher.buf),
16177 struct mlx5_priv *priv = dev->data->dev_private;
16180 if (match_src_port && (priv->representor || priv->master)) {
16181 if (flow_dv_translate_item_port_id(dev, matcher.buf,
16182 value.buf, item, attr)) {
16183 DRV_LOG(ERR, "Failed to create meter policy%d flow's"
16184 " value with port.", color);
16188 flow_dv_match_meta_reg(matcher.buf, value.buf,
16189 (enum modify_reg)color_reg_c_idx,
16190 rte_col_2_mlx5_col(color), UINT32_MAX);
16191 misc_mask = flow_dv_matcher_enable(value.buf);
16192 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16193 ret = mlx5_flow_os_create_flow(matcher_object, (void *)&value,
16194 actions_n, actions, rule);
16196 DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
16203 __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
16204 uint32_t color_reg_c_idx,
16206 struct mlx5_flow_meter_sub_policy *sub_policy,
16207 const struct rte_flow_attr *attr,
16208 bool match_src_port,
16209 const struct rte_flow_item *item,
16210 struct mlx5_flow_dv_matcher **policy_matcher,
16211 struct rte_flow_error *error)
16213 struct mlx5_list_entry *entry;
16214 struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
16215 struct mlx5_flow_dv_matcher matcher = {
16217 .size = sizeof(matcher.mask.buf),
16221 struct mlx5_flow_dv_match_params value = {
16222 .size = sizeof(value.buf),
16224 struct mlx5_flow_cb_ctx ctx = {
16228 struct mlx5_flow_tbl_data_entry *tbl_data;
16229 struct mlx5_priv *priv = dev->data->dev_private;
16230 const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
16232 if (match_src_port && (priv->representor || priv->master)) {
16233 if (flow_dv_translate_item_port_id(dev, matcher.mask.buf,
16234 value.buf, item, attr)) {
16235 DRV_LOG(ERR, "Failed to register meter policy%d matcher"
16236 " with port.", priority);
16240 tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
16241 if (priority < RTE_COLOR_RED)
16242 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16243 (enum modify_reg)color_reg_c_idx, 0, color_mask);
16244 matcher.priority = priority;
16245 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
16246 matcher.mask.size);
16247 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16249 DRV_LOG(ERR, "Failed to register meter drop matcher.");
16253 container_of(entry, struct mlx5_flow_dv_matcher, entry);
16258 * Create the policy rules per domain.
16261 * Pointer to Ethernet device.
16262 * @param[in] sub_policy
16263 * Pointer to sub policy table..
16264 * @param[in] egress
16265 * Direction of the table.
16266 * @param[in] transfer
16267 * E-Switch or NIC flow.
16269 * Pointer to policy action list per color.
16272 * 0 on success, -1 otherwise.
16275 __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
16276 struct mlx5_flow_meter_sub_policy *sub_policy,
16277 uint8_t egress, uint8_t transfer, bool match_src_port,
16278 struct mlx5_meter_policy_acts acts[RTE_COLORS])
16280 struct mlx5_priv *priv = dev->data->dev_private;
16281 struct rte_flow_error flow_err;
16282 uint32_t color_reg_c_idx;
16283 struct rte_flow_attr attr = {
16284 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
16287 .egress = !!egress,
16288 .transfer = !!transfer,
16292 int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
16293 struct mlx5_sub_policy_color_rule *color_rule;
16295 struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
16299 /* Create policy table with POLICY level. */
16300 if (!sub_policy->tbl_rsc)
16301 sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
16302 MLX5_FLOW_TABLE_LEVEL_POLICY,
16303 egress, transfer, false, NULL, 0, 0,
16304 sub_policy->idx, &flow_err);
16305 if (!sub_policy->tbl_rsc) {
16307 "Failed to create meter sub policy table.");
16310 /* Prepare matchers. */
16311 color_reg_c_idx = ret;
16312 for (i = 0; i < RTE_COLORS; i++) {
16313 TAILQ_INIT(&sub_policy->color_rules[i]);
16314 if (!acts[i].actions_n)
16316 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
16317 sizeof(struct mlx5_sub_policy_color_rule),
16320 DRV_LOG(ERR, "No memory to create color rule.");
16323 tmp_rules[i] = color_rule;
16324 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
16325 color_rule, next_port);
16326 color_rule->src_port = priv->representor_id;
16329 /* Create matchers for colors. */
16330 svport_match = (i != RTE_COLOR_RED) ? match_src_port : false;
16331 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
16332 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
16333 &attr, svport_match, NULL,
16334 &color_rule->matcher, &flow_err)) {
16335 DRV_LOG(ERR, "Failed to create color%u matcher.", i);
16338 /* Create flow, matching color. */
16339 if (__flow_dv_create_policy_flow(dev,
16340 color_reg_c_idx, (enum rte_color)i,
16341 color_rule->matcher->matcher_object,
16342 acts[i].actions_n, acts[i].dv_actions,
16343 svport_match, NULL, &color_rule->rule,
16345 DRV_LOG(ERR, "Failed to create color%u rule.", i);
16351 /* All the policy rules will be cleared. */
16353 color_rule = tmp_rules[i];
16355 if (color_rule->rule)
16356 mlx5_flow_os_destroy_flow(color_rule->rule);
16357 if (color_rule->matcher) {
16358 struct mlx5_flow_tbl_data_entry *tbl =
16359 container_of(color_rule->matcher->tbl,
16360 typeof(*tbl), tbl);
16361 mlx5_list_unregister(tbl->matchers,
16362 &color_rule->matcher->entry);
16364 TAILQ_REMOVE(&sub_policy->color_rules[i],
16365 color_rule, next_port);
16366 mlx5_free(color_rule);
16373 __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
16374 struct mlx5_flow_meter_policy *mtr_policy,
16375 struct mlx5_flow_meter_sub_policy *sub_policy,
16378 struct mlx5_priv *priv = dev->data->dev_private;
16379 struct mlx5_meter_policy_acts acts[RTE_COLORS];
16380 struct mlx5_flow_dv_tag_resource *tag;
16381 struct mlx5_flow_dv_port_id_action_resource *port_action;
16382 struct mlx5_hrxq *hrxq;
16383 struct mlx5_flow_meter_info *next_fm = NULL;
16384 struct mlx5_flow_meter_policy *next_policy;
16385 struct mlx5_flow_meter_sub_policy *next_sub_policy;
16386 struct mlx5_flow_tbl_data_entry *tbl_data;
16387 struct rte_flow_error error;
16388 uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16389 uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16390 bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
16391 bool match_src_port = false;
16394 /* If RSS or Queue, no previous actions / rules is created. */
16395 for (i = 0; i < RTE_COLORS; i++) {
16396 acts[i].actions_n = 0;
16397 if (i == RTE_COLOR_RED) {
16398 /* Only support drop on red. */
16399 acts[i].dv_actions[0] =
16400 mtr_policy->dr_drop_action[domain];
16401 acts[i].actions_n = 1;
16404 if (i == RTE_COLOR_GREEN &&
16405 mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
16406 struct rte_flow_attr attr = {
16407 .transfer = transfer
16410 next_fm = mlx5_flow_meter_find(priv,
16411 mtr_policy->act_cnt[i].next_mtr_id,
16415 "Failed to get next hierarchy meter.");
16418 if (mlx5_flow_meter_attach(priv, next_fm,
16420 DRV_LOG(ERR, "%s", error.message);
16424 /* Meter action must be the first for TX. */
16426 acts[i].dv_actions[acts[i].actions_n] =
16427 next_fm->meter_action;
16428 acts[i].actions_n++;
16431 if (mtr_policy->act_cnt[i].rix_mark) {
16432 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
16433 mtr_policy->act_cnt[i].rix_mark);
16435 DRV_LOG(ERR, "Failed to find "
16436 "mark action for policy.");
16439 acts[i].dv_actions[acts[i].actions_n] = tag->action;
16440 acts[i].actions_n++;
16442 if (mtr_policy->act_cnt[i].modify_hdr) {
16443 acts[i].dv_actions[acts[i].actions_n] =
16444 mtr_policy->act_cnt[i].modify_hdr->action;
16445 acts[i].actions_n++;
16447 if (mtr_policy->act_cnt[i].fate_action) {
16448 switch (mtr_policy->act_cnt[i].fate_action) {
16449 case MLX5_FLOW_FATE_PORT_ID:
16450 port_action = mlx5_ipool_get
16451 (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
16452 mtr_policy->act_cnt[i].rix_port_id_action);
16453 if (!port_action) {
16454 DRV_LOG(ERR, "Failed to find "
16455 "port action for policy.");
16458 acts[i].dv_actions[acts[i].actions_n] =
16459 port_action->action;
16460 acts[i].actions_n++;
16461 mtr_policy->dev = dev;
16462 match_src_port = true;
16464 case MLX5_FLOW_FATE_DROP:
16465 case MLX5_FLOW_FATE_JUMP:
16466 acts[i].dv_actions[acts[i].actions_n] =
16467 mtr_policy->act_cnt[i].dr_jump_action[domain];
16468 acts[i].actions_n++;
16470 case MLX5_FLOW_FATE_SHARED_RSS:
16471 case MLX5_FLOW_FATE_QUEUE:
16472 hrxq = mlx5_ipool_get
16473 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16474 sub_policy->rix_hrxq[i]);
16476 DRV_LOG(ERR, "Failed to find "
16477 "queue action for policy.");
16480 acts[i].dv_actions[acts[i].actions_n] =
16482 acts[i].actions_n++;
16484 case MLX5_FLOW_FATE_MTR:
16487 "No next hierarchy meter.");
16491 acts[i].dv_actions[acts[i].actions_n] =
16492 next_fm->meter_action;
16493 acts[i].actions_n++;
16495 if (mtr_policy->act_cnt[i].next_sub_policy) {
16497 mtr_policy->act_cnt[i].next_sub_policy;
16500 mlx5_flow_meter_policy_find(dev,
16501 next_fm->policy_id, NULL);
16502 MLX5_ASSERT(next_policy);
16504 next_policy->sub_policys[domain][0];
16507 container_of(next_sub_policy->tbl_rsc,
16508 struct mlx5_flow_tbl_data_entry, tbl);
16509 acts[i].dv_actions[acts[i].actions_n++] =
16510 tbl_data->jump.action;
16511 if (mtr_policy->act_cnt[i].modify_hdr)
16512 match_src_port = !!transfer;
16515 /*Queue action do nothing*/
16520 if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
16521 egress, transfer, match_src_port, acts)) {
16523 "Failed to create policy rules per domain.");
16529 mlx5_flow_meter_detach(priv, next_fm);
16534 * Create the policy rules.
16537 * Pointer to Ethernet device.
16538 * @param[in,out] mtr_policy
16539 * Pointer to meter policy table.
16542 * 0 on success, -1 otherwise.
16545 flow_dv_create_policy_rules(struct rte_eth_dev *dev,
16546 struct mlx5_flow_meter_policy *mtr_policy)
16549 uint16_t sub_policy_num;
16551 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16552 sub_policy_num = (mtr_policy->sub_policy_num >>
16553 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
16554 MLX5_MTR_SUB_POLICY_NUM_MASK;
16555 if (!sub_policy_num)
16557 /* Prepare actions list and create policy rules. */
16558 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16559 mtr_policy->sub_policys[i][0], i)) {
16560 DRV_LOG(ERR, "Failed to create policy action "
16561 "list per domain.");
16569 __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
16571 struct mlx5_priv *priv = dev->data->dev_private;
16572 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16573 struct mlx5_flow_meter_def_policy *def_policy;
16574 struct mlx5_flow_tbl_resource *jump_tbl;
16575 struct mlx5_flow_tbl_data_entry *tbl_data;
16576 uint8_t egress, transfer;
16577 struct rte_flow_error error;
16578 struct mlx5_meter_policy_acts acts[RTE_COLORS];
16581 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16582 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16583 def_policy = mtrmng->def_policy[domain];
16585 def_policy = mlx5_malloc(MLX5_MEM_ZERO,
16586 sizeof(struct mlx5_flow_meter_def_policy),
16587 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
16589 DRV_LOG(ERR, "Failed to alloc default policy table.");
16590 goto def_policy_error;
16592 mtrmng->def_policy[domain] = def_policy;
16593 /* Create the meter suffix table with SUFFIX level. */
16594 jump_tbl = flow_dv_tbl_resource_get(dev,
16595 MLX5_FLOW_TABLE_LEVEL_METER,
16596 egress, transfer, false, NULL, 0,
16597 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
16600 "Failed to create meter suffix table.");
16601 goto def_policy_error;
16603 def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
16604 tbl_data = container_of(jump_tbl,
16605 struct mlx5_flow_tbl_data_entry, tbl);
16606 def_policy->dr_jump_action[RTE_COLOR_GREEN] =
16607 tbl_data->jump.action;
16608 acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
16609 acts[RTE_COLOR_GREEN].actions_n = 1;
16611 * YELLOW has the same default policy as GREEN does.
16612 * G & Y share the same table and action. The 2nd time of table
16613 * resource getting is just to update the reference count for
16614 * the releasing stage.
16616 jump_tbl = flow_dv_tbl_resource_get(dev,
16617 MLX5_FLOW_TABLE_LEVEL_METER,
16618 egress, transfer, false, NULL, 0,
16619 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
16622 "Failed to get meter suffix table.");
16623 goto def_policy_error;
16625 def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
16626 tbl_data = container_of(jump_tbl,
16627 struct mlx5_flow_tbl_data_entry, tbl);
16628 def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
16629 tbl_data->jump.action;
16630 acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
16631 acts[RTE_COLOR_YELLOW].actions_n = 1;
16632 /* Create jump action to the drop table. */
16633 if (!mtrmng->drop_tbl[domain]) {
16634 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
16635 (dev, MLX5_FLOW_TABLE_LEVEL_METER,
16636 egress, transfer, false, NULL, 0,
16637 0, MLX5_MTR_TABLE_ID_DROP, &error);
16638 if (!mtrmng->drop_tbl[domain]) {
16639 DRV_LOG(ERR, "Failed to create meter "
16640 "drop table for default policy.");
16641 goto def_policy_error;
16644 /* all RED: unique Drop table for jump action. */
16645 tbl_data = container_of(mtrmng->drop_tbl[domain],
16646 struct mlx5_flow_tbl_data_entry, tbl);
16647 def_policy->dr_jump_action[RTE_COLOR_RED] =
16648 tbl_data->jump.action;
16649 acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
16650 acts[RTE_COLOR_RED].actions_n = 1;
16651 /* Create default policy rules. */
16652 ret = __flow_dv_create_domain_policy_rules(dev,
16653 &def_policy->sub_policy,
16654 egress, transfer, false, acts);
16656 DRV_LOG(ERR, "Failed to create default policy rules.");
16657 goto def_policy_error;
16662 __flow_dv_destroy_domain_def_policy(dev,
16663 (enum mlx5_meter_domain)domain);
16668 * Create the default policy table set.
16671 * Pointer to Ethernet device.
16673 * 0 on success, -1 otherwise.
16676 flow_dv_create_def_policy(struct rte_eth_dev *dev)
16678 struct mlx5_priv *priv = dev->data->dev_private;
16681 /* Non-termination policy table. */
16682 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16683 if (!priv->config.dv_esw_en && i == MLX5_MTR_DOMAIN_TRANSFER)
16685 if (__flow_dv_create_domain_def_policy(dev, i)) {
16686 DRV_LOG(ERR, "Failed to create default policy");
16687 /* Rollback the created default policies for others. */
16688 flow_dv_destroy_def_policy(dev);
16696 * Create the needed meter tables.
16697 * Lock free, (mutex should be acquired by caller).
16700 * Pointer to Ethernet device.
16702 * Meter information table.
16703 * @param[in] mtr_idx
16705 * @param[in] domain_bitmap
16708 * 0 on success, -1 otherwise.
16711 flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
16712 struct mlx5_flow_meter_info *fm,
16714 uint8_t domain_bitmap)
16716 struct mlx5_priv *priv = dev->data->dev_private;
16717 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16718 struct rte_flow_error error;
16719 struct mlx5_flow_tbl_data_entry *tbl_data;
16720 uint8_t egress, transfer;
16721 void *actions[METER_ACTIONS];
16722 int domain, ret, i;
16723 struct mlx5_flow_counter *cnt;
16724 struct mlx5_flow_dv_match_params value = {
16725 .size = sizeof(value.buf),
16727 struct mlx5_flow_dv_match_params matcher_para = {
16728 .size = sizeof(matcher_para.buf),
16730 int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
16732 uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
16733 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
16734 struct mlx5_list_entry *entry;
16735 struct mlx5_flow_dv_matcher matcher = {
16737 .size = sizeof(matcher.mask.buf),
16740 struct mlx5_flow_dv_matcher *drop_matcher;
16741 struct mlx5_flow_cb_ctx ctx = {
16747 if (!priv->mtr_en || mtr_id_reg_c < 0) {
16748 rte_errno = ENOTSUP;
16751 for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
16752 if (!(domain_bitmap & (1 << domain)) ||
16753 (mtrmng->def_rule[domain] && !fm->drop_cnt))
16755 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16756 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16757 /* Create the drop table with METER DROP level. */
16758 if (!mtrmng->drop_tbl[domain]) {
16759 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
16760 MLX5_FLOW_TABLE_LEVEL_METER,
16761 egress, transfer, false, NULL, 0,
16762 0, MLX5_MTR_TABLE_ID_DROP, &error);
16763 if (!mtrmng->drop_tbl[domain]) {
16764 DRV_LOG(ERR, "Failed to create meter drop table.");
16768 /* Create default matcher in drop table. */
16769 matcher.tbl = mtrmng->drop_tbl[domain],
16770 tbl_data = container_of(mtrmng->drop_tbl[domain],
16771 struct mlx5_flow_tbl_data_entry, tbl);
16772 if (!mtrmng->def_matcher[domain]) {
16773 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16774 (enum modify_reg)mtr_id_reg_c,
16776 matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
16777 matcher.crc = rte_raw_cksum
16778 ((const void *)matcher.mask.buf,
16779 matcher.mask.size);
16780 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16782 DRV_LOG(ERR, "Failed to register meter "
16783 "drop default matcher.");
16786 mtrmng->def_matcher[domain] = container_of(entry,
16787 struct mlx5_flow_dv_matcher, entry);
16789 /* Create default rule in drop table. */
16790 if (!mtrmng->def_rule[domain]) {
16792 actions[i++] = priv->sh->dr_drop_action;
16793 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16794 (enum modify_reg)mtr_id_reg_c, 0, 0);
16795 misc_mask = flow_dv_matcher_enable(value.buf);
16796 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16797 ret = mlx5_flow_os_create_flow
16798 (mtrmng->def_matcher[domain]->matcher_object,
16799 (void *)&value, i, actions,
16800 &mtrmng->def_rule[domain]);
16802 DRV_LOG(ERR, "Failed to create meter "
16803 "default drop rule for drop table.");
16809 MLX5_ASSERT(mtrmng->max_mtr_bits);
16810 if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
16811 /* Create matchers for Drop. */
16812 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16813 (enum modify_reg)mtr_id_reg_c, 0,
16814 (mtr_id_mask << mtr_id_offset));
16815 matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
16816 matcher.crc = rte_raw_cksum
16817 ((const void *)matcher.mask.buf,
16818 matcher.mask.size);
16819 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16822 "Failed to register meter drop matcher.");
16825 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
16826 container_of(entry, struct mlx5_flow_dv_matcher,
16830 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
16831 /* Create drop rule, matching meter_id only. */
16832 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16833 (enum modify_reg)mtr_id_reg_c,
16834 (mtr_idx << mtr_id_offset), UINT32_MAX);
16836 cnt = flow_dv_counter_get_by_idx(dev,
16837 fm->drop_cnt, NULL);
16838 actions[i++] = cnt->action;
16839 actions[i++] = priv->sh->dr_drop_action;
16840 misc_mask = flow_dv_matcher_enable(value.buf);
16841 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16842 ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
16843 (void *)&value, i, actions,
16844 &fm->drop_rule[domain]);
16846 DRV_LOG(ERR, "Failed to create meter "
16847 "drop rule for drop table.");
16853 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16854 if (fm->drop_rule[i]) {
16855 claim_zero(mlx5_flow_os_destroy_flow
16856 (fm->drop_rule[i]));
16857 fm->drop_rule[i] = NULL;
16863 static struct mlx5_flow_meter_sub_policy *
16864 __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
16865 struct mlx5_flow_meter_policy *mtr_policy,
16866 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
16867 struct mlx5_flow_meter_sub_policy *next_sub_policy,
16870 struct mlx5_priv *priv = dev->data->dev_private;
16871 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16872 uint32_t sub_policy_idx = 0;
16873 uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
16875 struct mlx5_hrxq *hrxq;
16876 struct mlx5_flow_handle dh;
16877 struct mlx5_meter_policy_action_container *act_cnt;
16878 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16879 uint16_t sub_policy_num;
16880 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
16883 rte_spinlock_lock(&mtr_policy->sl);
16884 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16887 hrxq_idx[i] = mlx5_hrxq_get(dev, rss_desc[i]);
16888 if (!hrxq_idx[i]) {
16889 rte_spinlock_unlock(&mtr_policy->sl);
16893 sub_policy_num = (mtr_policy->sub_policy_num >>
16894 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16895 MLX5_MTR_SUB_POLICY_NUM_MASK;
16896 for (j = 0; j < sub_policy_num; j++) {
16897 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16900 mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
16903 if (i >= MLX5_MTR_RTE_COLORS) {
16905 * Found the sub policy table with
16906 * the same queue per color.
16908 rte_spinlock_unlock(&mtr_policy->sl);
16909 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
16910 mlx5_hrxq_release(dev, hrxq_idx[i]);
16912 return mtr_policy->sub_policys[domain][j];
16915 /* Create sub policy. */
16916 if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[0]) {
16917 /* Reuse the first pre-allocated sub_policy. */
16918 sub_policy = mtr_policy->sub_policys[domain][0];
16919 sub_policy_idx = sub_policy->idx;
16921 sub_policy = mlx5_ipool_zmalloc
16922 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16925 sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
16926 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
16927 mlx5_hrxq_release(dev, hrxq_idx[i]);
16928 goto rss_sub_policy_error;
16930 sub_policy->idx = sub_policy_idx;
16931 sub_policy->main_policy = mtr_policy;
16933 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16936 sub_policy->rix_hrxq[i] = hrxq_idx[i];
16937 if (mtr_policy->is_hierarchy) {
16938 act_cnt = &mtr_policy->act_cnt[i];
16939 act_cnt->next_sub_policy = next_sub_policy;
16940 mlx5_hrxq_release(dev, hrxq_idx[i]);
16943 * Overwrite the last action from
16944 * RSS action to Queue action.
16946 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
16949 DRV_LOG(ERR, "Failed to get policy hrxq");
16950 goto rss_sub_policy_error;
16952 act_cnt = &mtr_policy->act_cnt[i];
16953 if (act_cnt->rix_mark || act_cnt->modify_hdr) {
16954 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
16955 if (act_cnt->rix_mark)
16957 dh.fate_action = MLX5_FLOW_FATE_QUEUE;
16958 dh.rix_hrxq = hrxq_idx[i];
16959 flow_drv_rxq_flags_set(dev, &dh);
16963 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16964 sub_policy, domain)) {
16965 DRV_LOG(ERR, "Failed to create policy "
16966 "rules for ingress domain.");
16967 goto rss_sub_policy_error;
16969 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16970 i = (mtr_policy->sub_policy_num >>
16971 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16972 MLX5_MTR_SUB_POLICY_NUM_MASK;
16973 if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
16974 DRV_LOG(ERR, "No free sub-policy slot.");
16975 goto rss_sub_policy_error;
16977 mtr_policy->sub_policys[domain][i] = sub_policy;
16979 mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16980 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
16981 mtr_policy->sub_policy_num |=
16982 (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16983 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
16985 rte_spinlock_unlock(&mtr_policy->sl);
16988 rss_sub_policy_error:
16990 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
16991 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16992 i = (mtr_policy->sub_policy_num >>
16993 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16994 MLX5_MTR_SUB_POLICY_NUM_MASK;
16995 mtr_policy->sub_policys[domain][i] = NULL;
16996 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17000 rte_spinlock_unlock(&mtr_policy->sl);
17005 * Find the policy table for prefix table with RSS.
17008 * Pointer to Ethernet device.
17009 * @param[in] mtr_policy
17010 * Pointer to meter policy table.
17011 * @param[in] rss_desc
17012 * Pointer to rss_desc
17014 * Pointer to table set on success, NULL otherwise and rte_errno is set.
17016 static struct mlx5_flow_meter_sub_policy *
17017 flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
17018 struct mlx5_flow_meter_policy *mtr_policy,
17019 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
17021 struct mlx5_priv *priv = dev->data->dev_private;
17022 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
17023 struct mlx5_flow_meter_info *next_fm;
17024 struct mlx5_flow_meter_policy *next_policy;
17025 struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
17026 struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
17027 struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
17028 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
17029 bool reuse_sub_policy;
17034 /* Iterate hierarchy to get all policies in this hierarchy. */
17035 policies[i++] = mtr_policy;
17036 if (!mtr_policy->is_hierarchy)
17038 if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
17039 DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
17042 next_fm = mlx5_flow_meter_find(priv,
17043 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
17045 DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
17049 mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
17051 MLX5_ASSERT(next_policy);
17052 mtr_policy = next_policy;
17056 * From last policy to the first one in hierarchy,
17057 * create / get the sub policy for each of them.
17059 sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
17063 &reuse_sub_policy);
17065 DRV_LOG(ERR, "Failed to get the sub policy.");
17068 if (!reuse_sub_policy)
17069 sub_policies[j++] = sub_policy;
17070 next_sub_policy = sub_policy;
17075 uint16_t sub_policy_num;
17077 sub_policy = sub_policies[--j];
17078 mtr_policy = sub_policy->main_policy;
17079 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
17080 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
17081 sub_policy_num = (mtr_policy->sub_policy_num >>
17082 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17083 MLX5_MTR_SUB_POLICY_NUM_MASK;
17084 mtr_policy->sub_policys[domain][sub_policy_num - 1] =
17087 mtr_policy->sub_policy_num &=
17088 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17089 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
17090 mtr_policy->sub_policy_num |=
17091 (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17092 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
17093 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17101 * Create the sub policy tag rule for all meters in hierarchy.
17104 * Pointer to Ethernet device.
17106 * Meter information table.
17107 * @param[in] src_port
17108 * The src port this extra rule should use.
17110 * The src port match item.
17111 * @param[out] error
17112 * Perform verbose error reporting if not NULL.
17114 * 0 on success, a negative errno value otherwise and rte_errno is set.
17117 flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
17118 struct mlx5_flow_meter_info *fm,
17120 const struct rte_flow_item *item,
17121 struct rte_flow_error *error)
17123 struct mlx5_priv *priv = dev->data->dev_private;
17124 struct mlx5_flow_meter_policy *mtr_policy;
17125 struct mlx5_flow_meter_sub_policy *sub_policy;
17126 struct mlx5_flow_meter_info *next_fm = NULL;
17127 struct mlx5_flow_meter_policy *next_policy;
17128 struct mlx5_flow_meter_sub_policy *next_sub_policy;
17129 struct mlx5_flow_tbl_data_entry *tbl_data;
17130 struct mlx5_sub_policy_color_rule *color_rule;
17131 struct mlx5_meter_policy_acts acts;
17132 uint32_t color_reg_c_idx;
17133 bool mtr_first = (src_port != UINT16_MAX) ? true : false;
17134 struct rte_flow_attr attr = {
17135 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
17142 uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
17145 mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
17146 MLX5_ASSERT(mtr_policy);
17147 if (!mtr_policy->is_hierarchy)
17149 next_fm = mlx5_flow_meter_find(priv,
17150 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
17152 return rte_flow_error_set(error, EINVAL,
17153 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17154 "Failed to find next meter in hierarchy.");
17156 if (!next_fm->drop_cnt)
17158 color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
17159 sub_policy = mtr_policy->sub_policys[domain][0];
17160 for (i = 0; i < RTE_COLORS; i++) {
17161 bool rule_exist = false;
17162 struct mlx5_meter_policy_action_container *act_cnt;
17164 if (i >= RTE_COLOR_YELLOW)
17166 TAILQ_FOREACH(color_rule,
17167 &sub_policy->color_rules[i], next_port)
17168 if (color_rule->src_port == src_port) {
17174 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
17175 sizeof(struct mlx5_sub_policy_color_rule),
17178 return rte_flow_error_set(error, ENOMEM,
17179 RTE_FLOW_ERROR_TYPE_ACTION,
17180 NULL, "No memory to create tag color rule.");
17181 color_rule->src_port = src_port;
17183 next_policy = mlx5_flow_meter_policy_find(dev,
17184 next_fm->policy_id, NULL);
17185 MLX5_ASSERT(next_policy);
17186 next_sub_policy = next_policy->sub_policys[domain][0];
17187 tbl_data = container_of(next_sub_policy->tbl_rsc,
17188 struct mlx5_flow_tbl_data_entry, tbl);
17189 act_cnt = &mtr_policy->act_cnt[i];
17191 acts.dv_actions[0] = next_fm->meter_action;
17192 acts.dv_actions[1] = act_cnt->modify_hdr->action;
17194 acts.dv_actions[0] = act_cnt->modify_hdr->action;
17195 acts.dv_actions[1] = next_fm->meter_action;
17197 acts.dv_actions[2] = tbl_data->jump.action;
17198 acts.actions_n = 3;
17199 if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
17203 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
17204 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
17206 &color_rule->matcher, error)) {
17207 rte_flow_error_set(error, errno,
17208 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17209 "Failed to create hierarchy meter matcher.");
17212 if (__flow_dv_create_policy_flow(dev, color_reg_c_idx,
17214 color_rule->matcher->matcher_object,
17215 acts.actions_n, acts.dv_actions,
17217 &color_rule->rule, &attr)) {
17218 rte_flow_error_set(error, errno,
17219 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17220 "Failed to create hierarchy meter rule.");
17223 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
17224 color_rule, next_port);
17228 * Recursive call to iterate all meters in hierarchy and
17229 * create needed rules.
17231 return flow_dv_meter_hierarchy_rule_create(dev, next_fm,
17232 src_port, item, error);
17235 if (color_rule->rule)
17236 mlx5_flow_os_destroy_flow(color_rule->rule);
17237 if (color_rule->matcher) {
17238 struct mlx5_flow_tbl_data_entry *tbl =
17239 container_of(color_rule->matcher->tbl,
17240 typeof(*tbl), tbl);
17241 mlx5_list_unregister(tbl->matchers,
17242 &color_rule->matcher->entry);
17244 mlx5_free(color_rule);
17247 mlx5_flow_meter_detach(priv, next_fm);
17252 * Destroy the sub policy table with RX queue.
17255 * Pointer to Ethernet device.
17256 * @param[in] mtr_policy
17257 * Pointer to meter policy table.
17260 flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
17261 struct mlx5_flow_meter_policy *mtr_policy)
17263 struct mlx5_priv *priv = dev->data->dev_private;
17264 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
17265 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
17267 uint16_t sub_policy_num, new_policy_num;
17269 rte_spinlock_lock(&mtr_policy->sl);
17270 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17271 switch (mtr_policy->act_cnt[i].fate_action) {
17272 case MLX5_FLOW_FATE_SHARED_RSS:
17273 sub_policy_num = (mtr_policy->sub_policy_num >>
17274 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17275 MLX5_MTR_SUB_POLICY_NUM_MASK;
17276 new_policy_num = sub_policy_num;
17277 for (j = 0; j < sub_policy_num; j++) {
17279 mtr_policy->sub_policys[domain][j];
17281 __flow_dv_destroy_sub_policy_rules(dev,
17284 mtr_policy->sub_policys[domain][0]) {
17285 mtr_policy->sub_policys[domain][j] =
17288 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17294 if (new_policy_num != sub_policy_num) {
17295 mtr_policy->sub_policy_num &=
17296 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17297 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
17298 mtr_policy->sub_policy_num |=
17300 MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17301 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
17304 case MLX5_FLOW_FATE_QUEUE:
17305 sub_policy = mtr_policy->sub_policys[domain][0];
17306 __flow_dv_destroy_sub_policy_rules(dev,
17310 /*Other actions without queue and do nothing*/
17314 rte_spinlock_unlock(&mtr_policy->sl);
17317 * Check whether the DR drop action is supported on the root table or not.
17319 * Create a simple flow with DR drop action on root table to validate
17320 * if DR drop action on root table is supported or not.
17323 * Pointer to rte_eth_dev structure.
17326 * 0 on success, a negative errno value otherwise and rte_errno is set.
17329 mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
17331 struct mlx5_priv *priv = dev->data->dev_private;
17332 struct mlx5_dev_ctx_shared *sh = priv->sh;
17333 struct mlx5_flow_dv_match_params mask = {
17334 .size = sizeof(mask.buf),
17336 struct mlx5_flow_dv_match_params value = {
17337 .size = sizeof(value.buf),
17339 struct mlx5dv_flow_matcher_attr dv_attr = {
17340 .type = IBV_FLOW_ATTR_NORMAL,
17342 .match_criteria_enable = 0,
17343 .match_mask = (void *)&mask,
17345 struct mlx5_flow_tbl_resource *tbl = NULL;
17346 void *matcher = NULL;
17350 tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
17354 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
17355 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
17356 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
17357 tbl->obj, &matcher);
17360 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
17361 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
17362 &sh->dr_drop_action, &flow);
17365 * If DR drop action is not supported on root table, flow create will
17366 * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
17370 (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
17371 DRV_LOG(INFO, "DR drop action is not supported in root table.");
17373 DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
17376 claim_zero(mlx5_flow_os_destroy_flow(flow));
17379 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
17381 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
17386 * Validate the batch counter support in root table.
17388 * Create a simple flow with invalid counter and drop action on root table to
17389 * validate if batch counter with offset on root table is supported or not.
17392 * Pointer to rte_eth_dev structure.
17395 * 0 on success, a negative errno value otherwise and rte_errno is set.
17398 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
17400 struct mlx5_priv *priv = dev->data->dev_private;
17401 struct mlx5_dev_ctx_shared *sh = priv->sh;
17402 struct mlx5_flow_dv_match_params mask = {
17403 .size = sizeof(mask.buf),
17405 struct mlx5_flow_dv_match_params value = {
17406 .size = sizeof(value.buf),
17408 struct mlx5dv_flow_matcher_attr dv_attr = {
17409 .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
17411 .match_criteria_enable = 0,
17412 .match_mask = (void *)&mask,
17414 void *actions[2] = { 0 };
17415 struct mlx5_flow_tbl_resource *tbl = NULL;
17416 struct mlx5_devx_obj *dcs = NULL;
17417 void *matcher = NULL;
17421 tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
17425 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
17428 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
17432 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
17433 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
17434 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
17435 tbl->obj, &matcher);
17438 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
17439 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
17443 * If batch counter with offset is not supported, the driver will not
17444 * validate the invalid offset value, flow create should success.
17445 * In this case, it means batch counter is not supported in root table.
17447 * Otherwise, if flow create is failed, counter offset is supported.
17450 DRV_LOG(INFO, "Batch counter is not supported in root "
17451 "table. Switch to fallback mode.");
17452 rte_errno = ENOTSUP;
17454 claim_zero(mlx5_flow_os_destroy_flow(flow));
17456 /* Check matcher to make sure validate fail at flow create. */
17457 if (!matcher || (matcher && errno != EINVAL))
17458 DRV_LOG(ERR, "Unexpected error in counter offset "
17459 "support detection");
17463 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
17465 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
17467 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
17469 claim_zero(mlx5_devx_cmd_destroy(dcs));
17474 * Query a devx counter.
17477 * Pointer to the Ethernet device structure.
17479 * Index to the flow counter.
17481 * Set to clear the counter statistics.
17483 * The statistics value of packets.
17484 * @param[out] bytes
17485 * The statistics value of bytes.
17488 * 0 on success, otherwise return -1.
17491 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
17492 uint64_t *pkts, uint64_t *bytes)
17494 struct mlx5_priv *priv = dev->data->dev_private;
17495 struct mlx5_flow_counter *cnt;
17496 uint64_t inn_pkts, inn_bytes;
17499 if (!priv->sh->devx)
17502 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
17505 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
17506 *pkts = inn_pkts - cnt->hits;
17507 *bytes = inn_bytes - cnt->bytes;
17509 cnt->hits = inn_pkts;
17510 cnt->bytes = inn_bytes;
17516 * Get aged-out flows.
17519 * Pointer to the Ethernet device structure.
17520 * @param[in] context
17521 * The address of an array of pointers to the aged-out flows contexts.
17522 * @param[in] nb_contexts
17523 * The length of context array pointers.
17524 * @param[out] error
17525 * Perform verbose error reporting if not NULL. Initialized in case of
17529 * how many contexts get in success, otherwise negative errno value.
17530 * if nb_contexts is 0, return the amount of all aged contexts.
17531 * if nb_contexts is not 0 , return the amount of aged flows reported
17532 * in the context array.
17533 * @note: only stub for now
17536 flow_dv_get_aged_flows(struct rte_eth_dev *dev,
17538 uint32_t nb_contexts,
17539 struct rte_flow_error *error)
17541 struct mlx5_priv *priv = dev->data->dev_private;
17542 struct mlx5_age_info *age_info;
17543 struct mlx5_age_param *age_param;
17544 struct mlx5_flow_counter *counter;
17545 struct mlx5_aso_age_action *act;
17548 if (nb_contexts && !context)
17549 return rte_flow_error_set(error, EINVAL,
17550 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17551 NULL, "empty context");
17552 age_info = GET_PORT_AGE_INFO(priv);
17553 rte_spinlock_lock(&age_info->aged_sl);
17554 LIST_FOREACH(act, &age_info->aged_aso, next) {
17557 context[nb_flows - 1] =
17558 act->age_params.context;
17559 if (!(--nb_contexts))
17563 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
17566 age_param = MLX5_CNT_TO_AGE(counter);
17567 context[nb_flows - 1] = age_param->context;
17568 if (!(--nb_contexts))
17572 rte_spinlock_unlock(&age_info->aged_sl);
17573 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
17578 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
17581 flow_dv_counter_allocate(struct rte_eth_dev *dev)
17583 return flow_dv_counter_alloc(dev, 0);
17587 * Validate indirect action.
17588 * Dispatcher for action type specific validation.
17591 * Pointer to the Ethernet device structure.
17593 * Indirect action configuration.
17594 * @param[in] action
17595 * The indirect action object to validate.
17596 * @param[out] error
17597 * Perform verbose error reporting if not NULL. Initialized in case of
17601 * 0 on success, otherwise negative errno value.
17604 flow_dv_action_validate(struct rte_eth_dev *dev,
17605 const struct rte_flow_indir_action_conf *conf,
17606 const struct rte_flow_action *action,
17607 struct rte_flow_error *err)
17609 struct mlx5_priv *priv = dev->data->dev_private;
17611 RTE_SET_USED(conf);
17612 switch (action->type) {
17613 case RTE_FLOW_ACTION_TYPE_RSS:
17615 * priv->obj_ops is set according to driver capabilities.
17616 * When DevX capabilities are
17617 * sufficient, it is set to devx_obj_ops.
17618 * Otherwise, it is set to ibv_obj_ops.
17619 * ibv_obj_ops doesn't support ind_table_modify operation.
17620 * In this case the indirect RSS action can't be used.
17622 if (priv->obj_ops.ind_table_modify == NULL)
17623 return rte_flow_error_set
17625 RTE_FLOW_ERROR_TYPE_ACTION,
17627 "Indirect RSS action not supported");
17628 return mlx5_validate_action_rss(dev, action, err);
17629 case RTE_FLOW_ACTION_TYPE_AGE:
17630 if (!priv->sh->aso_age_mng)
17631 return rte_flow_error_set(err, ENOTSUP,
17632 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17634 "Indirect age action not supported");
17635 return flow_dv_validate_action_age(0, action, dev, err);
17636 case RTE_FLOW_ACTION_TYPE_COUNT:
17637 return flow_dv_validate_action_count(dev, true, 0, err);
17638 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17639 if (!priv->sh->ct_aso_en)
17640 return rte_flow_error_set(err, ENOTSUP,
17641 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17642 "ASO CT is not supported");
17643 return mlx5_validate_action_ct(dev, action->conf, err);
17645 return rte_flow_error_set(err, ENOTSUP,
17646 RTE_FLOW_ERROR_TYPE_ACTION,
17648 "action type not supported");
17653 * Check if the RSS configurations for colors of a meter policy match
17654 * each other, except the queues.
17657 * Pointer to the first RSS flow action.
17659 * Pointer to the second RSS flow action.
17662 * 0 on match, 1 on conflict.
17665 flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
17666 const struct rte_flow_action_rss *r2)
17668 if (r1 == NULL || r2 == NULL)
17670 if (!(r1->level <= 1 && r2->level <= 1) &&
17671 !(r1->level > 1 && r2->level > 1))
17673 if (r1->types != r2->types &&
17674 !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
17675 (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
17677 if (r1->key || r2->key) {
17678 const void *key1 = r1->key ? r1->key : rss_hash_default_key;
17679 const void *key2 = r2->key ? r2->key : rss_hash_default_key;
17681 if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
17688 * Validate the meter hierarchy chain for meter policy.
17691 * Pointer to the Ethernet device structure.
17692 * @param[in] meter_id
17694 * @param[in] action_flags
17695 * Holds the actions detected until now.
17696 * @param[out] is_rss
17698 * @param[out] hierarchy_domain
17699 * The domain bitmap for hierarchy policy.
17700 * @param[out] error
17701 * Perform verbose error reporting if not NULL. Initialized in case of
17705 * 0 on success, otherwise negative errno value with error set.
17708 flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
17710 uint64_t action_flags,
17712 uint8_t *hierarchy_domain,
17713 struct rte_mtr_error *error)
17715 struct mlx5_priv *priv = dev->data->dev_private;
17716 struct mlx5_flow_meter_info *fm;
17717 struct mlx5_flow_meter_policy *policy;
17720 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
17721 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
17722 return -rte_mtr_error_set(error, EINVAL,
17723 RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
17725 "Multiple fate actions not supported.");
17726 *hierarchy_domain = 0;
17728 fm = mlx5_flow_meter_find(priv, meter_id, NULL);
17730 return -rte_mtr_error_set(error, EINVAL,
17731 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17732 "Meter not found in meter hierarchy.");
17733 if (fm->def_policy)
17734 return -rte_mtr_error_set(error, EINVAL,
17735 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17736 "Non termination meter not supported in hierarchy.");
17737 policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
17738 MLX5_ASSERT(policy);
17740 * Only inherit the supported domains of the first meter in
17742 * One meter supports at least one domain.
17744 if (!*hierarchy_domain) {
17745 if (policy->transfer)
17746 *hierarchy_domain |=
17747 MLX5_MTR_DOMAIN_TRANSFER_BIT;
17748 if (policy->ingress)
17749 *hierarchy_domain |=
17750 MLX5_MTR_DOMAIN_INGRESS_BIT;
17751 if (policy->egress)
17752 *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
17754 if (!policy->is_hierarchy) {
17755 *is_rss = policy->is_rss;
17758 meter_id = policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id;
17759 if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
17760 return -rte_mtr_error_set(error, EINVAL,
17761 RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
17762 "Exceed max hierarchy meter number.");
17768 * Validate meter policy actions.
17769 * Dispatcher for action type specific validation.
17772 * Pointer to the Ethernet device structure.
17773 * @param[in] action
17774 * The meter policy action object to validate.
17776 * Attributes of flow to determine steering domain.
17777 * @param[out] error
17778 * Perform verbose error reporting if not NULL. Initialized in case of
17782 * 0 on success, otherwise negative errno value.
17785 flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
17786 const struct rte_flow_action *actions[RTE_COLORS],
17787 struct rte_flow_attr *attr,
17789 uint8_t *domain_bitmap,
17790 uint8_t *policy_mode,
17791 struct rte_mtr_error *error)
17793 struct mlx5_priv *priv = dev->data->dev_private;
17794 struct mlx5_dev_config *dev_conf = &priv->config;
17795 const struct rte_flow_action *act;
17796 uint64_t action_flags[RTE_COLORS] = {0};
17799 struct rte_flow_error flow_err;
17800 uint8_t domain_color[RTE_COLORS] = {0};
17801 uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
17802 uint8_t hierarchy_domain = 0;
17803 const struct rte_flow_action_meter *mtr;
17804 bool def_green = false;
17805 bool def_yellow = false;
17806 const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
17808 if (!priv->config.dv_esw_en)
17809 def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
17810 *domain_bitmap = def_domain;
17811 /* Red color could only support DROP action. */
17812 if (!actions[RTE_COLOR_RED] ||
17813 actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
17814 return -rte_mtr_error_set(error, ENOTSUP,
17815 RTE_MTR_ERROR_TYPE_METER_POLICY,
17816 NULL, "Red color only supports drop action.");
17818 * Check default policy actions:
17819 * Green / Yellow: no action, Red: drop action
17820 * Either G or Y will trigger default policy actions to be created.
17822 if (!actions[RTE_COLOR_GREEN] ||
17823 actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
17825 if (!actions[RTE_COLOR_YELLOW] ||
17826 actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
17828 if (def_green && def_yellow) {
17829 *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
17831 } else if (!def_green && def_yellow) {
17832 *policy_mode = MLX5_MTR_POLICY_MODE_OG;
17833 } else if (def_green && !def_yellow) {
17834 *policy_mode = MLX5_MTR_POLICY_MODE_OY;
17836 *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
17838 /* Set to empty string in case of NULL pointer access by user. */
17839 flow_err.message = "";
17840 for (i = 0; i < RTE_COLORS; i++) {
17842 for (action_flags[i] = 0, actions_n = 0;
17843 act && act->type != RTE_FLOW_ACTION_TYPE_END;
17845 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
17846 return -rte_mtr_error_set(error, ENOTSUP,
17847 RTE_MTR_ERROR_TYPE_METER_POLICY,
17848 NULL, "too many actions");
17849 switch (act->type) {
17850 case RTE_FLOW_ACTION_TYPE_PORT_ID:
17851 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17852 if (!priv->config.dv_esw_en)
17853 return -rte_mtr_error_set(error,
17855 RTE_MTR_ERROR_TYPE_METER_POLICY,
17856 NULL, "PORT action validate check"
17857 " fail for ESW disable");
17858 ret = flow_dv_validate_action_port_id(dev,
17860 act, attr, &flow_err);
17862 return -rte_mtr_error_set(error,
17864 RTE_MTR_ERROR_TYPE_METER_POLICY,
17865 NULL, flow_err.message ?
17867 "PORT action validate check fail");
17869 action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
17871 case RTE_FLOW_ACTION_TYPE_MARK:
17872 ret = flow_dv_validate_action_mark(dev, act,
17876 return -rte_mtr_error_set(error,
17878 RTE_MTR_ERROR_TYPE_METER_POLICY,
17879 NULL, flow_err.message ?
17881 "Mark action validate check fail");
17882 if (dev_conf->dv_xmeta_en !=
17883 MLX5_XMETA_MODE_LEGACY)
17884 return -rte_mtr_error_set(error,
17886 RTE_MTR_ERROR_TYPE_METER_POLICY,
17887 NULL, "Extend MARK action is "
17888 "not supported. Please try use "
17889 "default policy for meter.");
17890 action_flags[i] |= MLX5_FLOW_ACTION_MARK;
17893 case RTE_FLOW_ACTION_TYPE_SET_TAG:
17894 ret = flow_dv_validate_action_set_tag(dev,
17895 act, action_flags[i],
17898 return -rte_mtr_error_set(error,
17900 RTE_MTR_ERROR_TYPE_METER_POLICY,
17901 NULL, flow_err.message ?
17903 "Set tag action validate check fail");
17904 action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
17907 case RTE_FLOW_ACTION_TYPE_DROP:
17908 ret = mlx5_flow_validate_action_drop
17909 (action_flags[i], attr, &flow_err);
17911 return -rte_mtr_error_set(error,
17913 RTE_MTR_ERROR_TYPE_METER_POLICY,
17914 NULL, flow_err.message ?
17916 "Drop action validate check fail");
17917 action_flags[i] |= MLX5_FLOW_ACTION_DROP;
17920 case RTE_FLOW_ACTION_TYPE_QUEUE:
17922 * Check whether extensive
17923 * metadata feature is engaged.
17925 if (dev_conf->dv_flow_en &&
17926 (dev_conf->dv_xmeta_en !=
17927 MLX5_XMETA_MODE_LEGACY) &&
17928 mlx5_flow_ext_mreg_supported(dev))
17929 return -rte_mtr_error_set(error,
17931 RTE_MTR_ERROR_TYPE_METER_POLICY,
17932 NULL, "Queue action with meta "
17933 "is not supported. Please try use "
17934 "default policy for meter.");
17935 ret = mlx5_flow_validate_action_queue(act,
17936 action_flags[i], dev,
17939 return -rte_mtr_error_set(error,
17941 RTE_MTR_ERROR_TYPE_METER_POLICY,
17942 NULL, flow_err.message ?
17944 "Queue action validate check fail");
17945 action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
17948 case RTE_FLOW_ACTION_TYPE_RSS:
17949 if (dev_conf->dv_flow_en &&
17950 (dev_conf->dv_xmeta_en !=
17951 MLX5_XMETA_MODE_LEGACY) &&
17952 mlx5_flow_ext_mreg_supported(dev))
17953 return -rte_mtr_error_set(error,
17955 RTE_MTR_ERROR_TYPE_METER_POLICY,
17956 NULL, "RSS action with meta "
17957 "is not supported. Please try use "
17958 "default policy for meter.");
17959 ret = mlx5_validate_action_rss(dev, act,
17962 return -rte_mtr_error_set(error,
17964 RTE_MTR_ERROR_TYPE_METER_POLICY,
17965 NULL, flow_err.message ?
17967 "RSS action validate check fail");
17968 action_flags[i] |= MLX5_FLOW_ACTION_RSS;
17970 /* Either G or Y will set the RSS. */
17971 rss_color[i] = act->conf;
17973 case RTE_FLOW_ACTION_TYPE_JUMP:
17974 ret = flow_dv_validate_action_jump(dev,
17975 NULL, act, action_flags[i],
17976 attr, true, &flow_err);
17978 return -rte_mtr_error_set(error,
17980 RTE_MTR_ERROR_TYPE_METER_POLICY,
17981 NULL, flow_err.message ?
17983 "Jump action validate check fail");
17985 action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
17988 * Only the last meter in the hierarchy will support
17989 * the YELLOW color steering. Then in the meter policy
17990 * actions list, there should be no other meter inside.
17992 case RTE_FLOW_ACTION_TYPE_METER:
17993 if (i != RTE_COLOR_GREEN)
17994 return -rte_mtr_error_set(error,
17996 RTE_MTR_ERROR_TYPE_METER_POLICY,
17998 "Meter hierarchy only supports GREEN color.");
17999 if (*policy_mode != MLX5_MTR_POLICY_MODE_OG)
18000 return -rte_mtr_error_set(error,
18002 RTE_MTR_ERROR_TYPE_METER_POLICY,
18004 "No yellow policy should be provided in meter hierarchy.");
18006 ret = flow_dv_validate_policy_mtr_hierarchy(dev,
18016 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
18019 return -rte_mtr_error_set(error, ENOTSUP,
18020 RTE_MTR_ERROR_TYPE_METER_POLICY,
18022 "Doesn't support optional action");
18025 if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
18026 domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
18027 } else if ((action_flags[i] &
18028 (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
18029 (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
18031 * Only support MLX5_XMETA_MODE_LEGACY
18032 * so MARK action is only in ingress domain.
18034 domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
18036 domain_color[i] = def_domain;
18037 if (action_flags[i] &&
18038 !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
18040 ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
18042 if (action_flags[i] &
18043 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
18044 domain_color[i] &= hierarchy_domain;
18046 * Non-termination actions only support NIC Tx domain.
18047 * The adjustion should be skipped when there is no
18048 * action or only END is provided. The default domains
18049 * bit-mask is set to find the MIN intersection.
18050 * The action flags checking should also be skipped.
18052 if ((def_green && i == RTE_COLOR_GREEN) ||
18053 (def_yellow && i == RTE_COLOR_YELLOW))
18056 * Validate the drop action mutual exclusion
18057 * with other actions. Drop action is mutually-exclusive
18058 * with any other action, except for Count action.
18060 if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
18061 (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
18062 return -rte_mtr_error_set(error, ENOTSUP,
18063 RTE_MTR_ERROR_TYPE_METER_POLICY,
18064 NULL, "Drop action is mutually-exclusive "
18065 "with any other action");
18067 /* Eswitch has few restrictions on using items and actions */
18068 if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
18069 if (!mlx5_flow_ext_mreg_supported(dev) &&
18070 action_flags[i] & MLX5_FLOW_ACTION_MARK)
18071 return -rte_mtr_error_set(error, ENOTSUP,
18072 RTE_MTR_ERROR_TYPE_METER_POLICY,
18073 NULL, "unsupported action MARK");
18074 if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
18075 return -rte_mtr_error_set(error, ENOTSUP,
18076 RTE_MTR_ERROR_TYPE_METER_POLICY,
18077 NULL, "unsupported action QUEUE");
18078 if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
18079 return -rte_mtr_error_set(error, ENOTSUP,
18080 RTE_MTR_ERROR_TYPE_METER_POLICY,
18081 NULL, "unsupported action RSS");
18082 if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
18083 return -rte_mtr_error_set(error, ENOTSUP,
18084 RTE_MTR_ERROR_TYPE_METER_POLICY,
18085 NULL, "no fate action is found");
18087 if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
18088 (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
18089 if ((domain_color[i] &
18090 MLX5_MTR_DOMAIN_EGRESS_BIT))
18092 MLX5_MTR_DOMAIN_EGRESS_BIT;
18094 return -rte_mtr_error_set(error,
18096 RTE_MTR_ERROR_TYPE_METER_POLICY,
18098 "no fate action is found");
18102 /* If both colors have RSS, the attributes should be the same. */
18103 if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
18104 rss_color[RTE_COLOR_YELLOW]))
18105 return -rte_mtr_error_set(error, EINVAL,
18106 RTE_MTR_ERROR_TYPE_METER_POLICY,
18107 NULL, "policy RSS attr conflict");
18108 if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
18110 /* "domain_color[C]" is non-zero for each color, default is ALL. */
18111 if (!def_green && !def_yellow &&
18112 domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
18113 !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
18114 !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
18115 return -rte_mtr_error_set(error, EINVAL,
18116 RTE_MTR_ERROR_TYPE_METER_POLICY,
18117 NULL, "policy domains conflict");
18119 * At least one color policy is listed in the actions, the domains
18120 * to be supported should be the intersection.
18122 *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
18123 domain_color[RTE_COLOR_YELLOW];
18128 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
18130 struct mlx5_priv *priv = dev->data->dev_private;
18133 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
18134 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
18139 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
18140 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
18144 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
18145 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
18153 * Discover the number of available flow priorities
18154 * by trying to create a flow with the highest priority value
18155 * for each possible number.
18160 * List of possible number of available priorities.
18161 * @param[in] vprio_n
18162 * Size of @p vprio array.
18164 * On success, number of available flow priorities.
18165 * On failure, a negative errno-style code and rte_errno is set.
18168 flow_dv_discover_priorities(struct rte_eth_dev *dev,
18169 const uint16_t *vprio, int vprio_n)
18171 struct mlx5_priv *priv = dev->data->dev_private;
18172 struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
18173 struct rte_flow_item_eth eth;
18174 struct rte_flow_item item = {
18175 .type = RTE_FLOW_ITEM_TYPE_ETH,
18179 struct mlx5_flow_dv_matcher matcher = {
18181 .size = sizeof(matcher.mask.buf),
18184 union mlx5_flow_tbl_key tbl_key;
18185 struct mlx5_flow flow;
18187 struct rte_flow_error error;
18189 int i, err, ret = -ENOTSUP;
18192 * Prepare a flow with a catch-all pattern and a drop action.
18193 * Use drop queue, because shared drop action may be unavailable.
18195 action = priv->drop_queue.hrxq->action;
18196 if (action == NULL) {
18197 DRV_LOG(ERR, "Priority discovery requires a drop action");
18198 rte_errno = ENOTSUP;
18201 memset(&flow, 0, sizeof(flow));
18202 flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
18203 if (flow.handle == NULL) {
18204 DRV_LOG(ERR, "Cannot create flow handle");
18205 rte_errno = ENOMEM;
18208 flow.ingress = true;
18209 flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
18210 flow.dv.actions[0] = action;
18211 flow.dv.actions_n = 1;
18212 memset(ð, 0, sizeof(eth));
18213 flow_dv_translate_item_eth(matcher.mask.buf, flow.dv.value.buf,
18214 &item, /* inner */ false, /* group */ 0);
18215 matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
18216 for (i = 0; i < vprio_n; i++) {
18217 /* Configure the next proposed maximum priority. */
18218 matcher.priority = vprio[i] - 1;
18219 memset(&tbl_key, 0, sizeof(tbl_key));
18220 err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
18225 /* This action is pure SW and must always succeed. */
18226 DRV_LOG(ERR, "Cannot register matcher");
18230 /* Try to apply the flow to HW. */
18231 misc_mask = flow_dv_matcher_enable(flow.dv.value.buf);
18232 __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
18233 err = mlx5_flow_os_create_flow
18234 (flow.handle->dvh.matcher->matcher_object,
18235 (void *)&flow.dv.value, flow.dv.actions_n,
18236 flow.dv.actions, &flow.handle->drv_flow);
18238 claim_zero(mlx5_flow_os_destroy_flow
18239 (flow.handle->drv_flow));
18240 flow.handle->drv_flow = NULL;
18242 claim_zero(flow_dv_matcher_release(dev, flow.handle));
18247 mlx5_ipool_free(pool, flow.handle_idx);
18248 /* Set rte_errno if no expected priority value matched. */
18254 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
18255 .validate = flow_dv_validate,
18256 .prepare = flow_dv_prepare,
18257 .translate = flow_dv_translate,
18258 .apply = flow_dv_apply,
18259 .remove = flow_dv_remove,
18260 .destroy = flow_dv_destroy,
18261 .query = flow_dv_query,
18262 .create_mtr_tbls = flow_dv_create_mtr_tbls,
18263 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
18264 .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
18265 .create_meter = flow_dv_mtr_alloc,
18266 .free_meter = flow_dv_aso_mtr_release_to_pool,
18267 .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
18268 .create_mtr_acts = flow_dv_create_mtr_policy_acts,
18269 .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
18270 .create_policy_rules = flow_dv_create_policy_rules,
18271 .destroy_policy_rules = flow_dv_destroy_policy_rules,
18272 .create_def_policy = flow_dv_create_def_policy,
18273 .destroy_def_policy = flow_dv_destroy_def_policy,
18274 .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
18275 .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
18276 .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
18277 .counter_alloc = flow_dv_counter_allocate,
18278 .counter_free = flow_dv_counter_free,
18279 .counter_query = flow_dv_counter_query,
18280 .get_aged_flows = flow_dv_get_aged_flows,
18281 .action_validate = flow_dv_action_validate,
18282 .action_create = flow_dv_action_create,
18283 .action_destroy = flow_dv_action_destroy,
18284 .action_update = flow_dv_action_update,
18285 .action_query = flow_dv_action_query,
18286 .sync_domain = flow_dv_sync_domain,
18287 .discover_priorities = flow_dv_discover_priorities,
18288 .item_create = flow_dv_item_create,
18289 .item_release = flow_dv_item_release,
18292 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */