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;
100 struct mlx5_common_device *cdev = priv->sh->cdev;
102 if (cdev->config.hca_attr.esw_mgr_vport_id_valid)
103 return (int16_t)cdev->config.hca_attr.esw_mgr_vport_id;
105 if (priv->pci_dev == NULL)
107 switch (priv->pci_dev->id.device_id) {
108 case PCI_DEVICE_ID_MELLANOX_CONNECTX5BF:
109 case PCI_DEVICE_ID_MELLANOX_CONNECTX6DXBF:
110 case PCI_DEVICE_ID_MELLANOX_CONNECTX7BF:
111 return (int16_t)0xfffe;
118 * Initialize flow attributes structure according to flow items' types.
120 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
121 * mode. For tunnel mode, the items to be modified are the outermost ones.
124 * Pointer to item specification.
126 * Pointer to flow attributes structure.
127 * @param[in] dev_flow
128 * Pointer to the sub flow.
129 * @param[in] tunnel_decap
130 * Whether action is after tunnel decapsulation.
133 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
134 struct mlx5_flow *dev_flow, bool tunnel_decap)
136 uint64_t layers = dev_flow->handle->layers;
139 * If layers is already initialized, it means this dev_flow is the
140 * suffix flow, the layers flags is set by the prefix flow. Need to
141 * use the layer flags from prefix flow as the suffix flow may not
142 * have the user defined items as the flow is split.
145 if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
147 else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
149 if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
151 else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
156 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
157 uint8_t next_protocol = 0xff;
158 switch (item->type) {
159 case RTE_FLOW_ITEM_TYPE_GRE:
160 case RTE_FLOW_ITEM_TYPE_NVGRE:
161 case RTE_FLOW_ITEM_TYPE_VXLAN:
162 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
163 case RTE_FLOW_ITEM_TYPE_GENEVE:
164 case RTE_FLOW_ITEM_TYPE_MPLS:
165 case RTE_FLOW_ITEM_TYPE_GTP:
169 case RTE_FLOW_ITEM_TYPE_IPV4:
172 if (item->mask != NULL &&
173 ((const struct rte_flow_item_ipv4 *)
174 item->mask)->hdr.next_proto_id)
176 ((const struct rte_flow_item_ipv4 *)
177 (item->spec))->hdr.next_proto_id &
178 ((const struct rte_flow_item_ipv4 *)
179 (item->mask))->hdr.next_proto_id;
180 if ((next_protocol == IPPROTO_IPIP ||
181 next_protocol == IPPROTO_IPV6) && tunnel_decap)
184 case RTE_FLOW_ITEM_TYPE_IPV6:
187 if (item->mask != NULL &&
188 ((const struct rte_flow_item_ipv6 *)
189 item->mask)->hdr.proto)
191 ((const struct rte_flow_item_ipv6 *)
192 (item->spec))->hdr.proto &
193 ((const struct rte_flow_item_ipv6 *)
194 (item->mask))->hdr.proto;
195 if ((next_protocol == IPPROTO_IPIP ||
196 next_protocol == IPPROTO_IPV6) && tunnel_decap)
199 case RTE_FLOW_ITEM_TYPE_UDP:
203 case RTE_FLOW_ITEM_TYPE_TCP:
215 * Convert rte_mtr_color to mlx5 color.
224 rte_col_2_mlx5_col(enum rte_color rcol)
227 case RTE_COLOR_GREEN:
228 return MLX5_FLOW_COLOR_GREEN;
229 case RTE_COLOR_YELLOW:
230 return MLX5_FLOW_COLOR_YELLOW;
232 return MLX5_FLOW_COLOR_RED;
236 return MLX5_FLOW_COLOR_UNDEFINED;
239 struct field_modify_info {
240 uint32_t size; /* Size of field in protocol header, in bytes. */
241 uint32_t offset; /* Offset of field in protocol header, in bytes. */
242 enum mlx5_modification_field id;
245 struct field_modify_info modify_eth[] = {
246 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
247 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
248 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
249 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
253 struct field_modify_info modify_vlan_out_first_vid[] = {
254 /* Size in bits !!! */
255 {12, 0, MLX5_MODI_OUT_FIRST_VID},
259 struct field_modify_info modify_ipv4[] = {
260 {1, 1, MLX5_MODI_OUT_IP_DSCP},
261 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
262 {4, 12, MLX5_MODI_OUT_SIPV4},
263 {4, 16, MLX5_MODI_OUT_DIPV4},
267 struct field_modify_info modify_ipv6[] = {
268 {1, 0, MLX5_MODI_OUT_IP_DSCP},
269 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
270 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
271 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
272 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
273 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
274 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
275 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
276 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
277 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
281 struct field_modify_info modify_udp[] = {
282 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
283 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
287 struct field_modify_info modify_tcp[] = {
288 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
289 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
290 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
291 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
296 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
297 uint8_t next_protocol, uint64_t *item_flags,
300 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
301 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
302 if (next_protocol == IPPROTO_IPIP) {
303 *item_flags |= MLX5_FLOW_LAYER_IPIP;
306 if (next_protocol == IPPROTO_IPV6) {
307 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
312 static inline struct mlx5_hlist *
313 flow_dv_hlist_prepare(struct mlx5_dev_ctx_shared *sh, struct mlx5_hlist **phl,
314 const char *name, uint32_t size, bool direct_key,
315 bool lcores_share, void *ctx,
316 mlx5_list_create_cb cb_create,
317 mlx5_list_match_cb cb_match,
318 mlx5_list_remove_cb cb_remove,
319 mlx5_list_clone_cb cb_clone,
320 mlx5_list_clone_free_cb cb_clone_free,
321 struct rte_flow_error *error)
323 struct mlx5_hlist *hl;
324 struct mlx5_hlist *expected = NULL;
325 char s[MLX5_NAME_SIZE];
327 hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
330 snprintf(s, sizeof(s), "%s_%s", sh->ibdev_name, name);
331 hl = mlx5_hlist_create(s, size, direct_key, lcores_share,
332 ctx, cb_create, cb_match, cb_remove, cb_clone,
335 DRV_LOG(ERR, "%s hash creation failed", name);
336 rte_flow_error_set(error, ENOMEM,
337 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
338 "cannot allocate resource memory");
341 if (!__atomic_compare_exchange_n(phl, &expected, hl, false,
344 mlx5_hlist_destroy(hl);
345 hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
350 /* Update VLAN's VID/PCP based on input rte_flow_action.
353 * Pointer to struct rte_flow_action.
355 * Pointer to struct rte_vlan_hdr.
358 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
359 struct rte_vlan_hdr *vlan)
362 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
364 ((const struct rte_flow_action_of_set_vlan_pcp *)
365 action->conf)->vlan_pcp;
366 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
367 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
368 vlan->vlan_tci |= vlan_tci;
369 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
370 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
371 vlan->vlan_tci |= rte_be_to_cpu_16
372 (((const struct rte_flow_action_of_set_vlan_vid *)
373 action->conf)->vlan_vid);
378 * Fetch 1, 2, 3 or 4 byte field from the byte array
379 * and return as unsigned integer in host-endian format.
382 * Pointer to data array.
384 * Size of field to extract.
387 * converted field in host endian format.
389 static inline uint32_t
390 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
399 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
402 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
403 ret = (ret << 8) | *(data + sizeof(uint16_t));
406 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
417 * Convert modify-header action to DV specification.
419 * Data length of each action is determined by provided field description
420 * and the item mask. Data bit offset and width of each action is determined
421 * by provided item mask.
424 * Pointer to item specification.
426 * Pointer to field modification information.
427 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
428 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
429 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
431 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
432 * Negative offset value sets the same offset as source offset.
433 * size field is ignored, value is taken from source field.
434 * @param[in,out] resource
435 * Pointer to the modify-header resource.
437 * Type of modification.
439 * Pointer to the error structure.
442 * 0 on success, a negative errno value otherwise and rte_errno is set.
445 flow_dv_convert_modify_action(struct rte_flow_item *item,
446 struct field_modify_info *field,
447 struct field_modify_info *dcopy,
448 struct mlx5_flow_dv_modify_hdr_resource *resource,
449 uint32_t type, struct rte_flow_error *error)
451 uint32_t i = resource->actions_num;
452 struct mlx5_modification_cmd *actions = resource->actions;
453 uint32_t carry_b = 0;
456 * The item and mask are provided in big-endian format.
457 * The fields should be presented as in big-endian format either.
458 * Mask must be always present, it defines the actual field width.
460 MLX5_ASSERT(item->mask);
461 MLX5_ASSERT(field->size);
467 bool next_field = true;
468 bool next_dcopy = true;
470 if (i >= MLX5_MAX_MODIFY_NUM)
471 return rte_flow_error_set(error, EINVAL,
472 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
473 "too many items to modify");
474 /* Fetch variable byte size mask from the array. */
475 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
476 field->offset, field->size);
481 /* Deduce actual data width in bits from mask value. */
482 off_b = rte_bsf32(mask) + carry_b;
483 size_b = sizeof(uint32_t) * CHAR_BIT -
484 off_b - __builtin_clz(mask);
486 actions[i] = (struct mlx5_modification_cmd) {
490 .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
493 if (type == MLX5_MODIFICATION_TYPE_COPY) {
495 actions[i].dst_field = dcopy->id;
496 actions[i].dst_offset =
497 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
498 /* Convert entire record to big-endian format. */
499 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
501 * Destination field overflow. Copy leftovers of
502 * a source field to the next destination field.
505 if ((size_b > dcopy->size * CHAR_BIT - dcopy->offset) &&
508 dcopy->size * CHAR_BIT - dcopy->offset;
509 carry_b = actions[i].length;
513 * Not enough bits in a source filed to fill a
514 * destination field. Switch to the next source.
516 if ((size_b < dcopy->size * CHAR_BIT - dcopy->offset) &&
517 (size_b == field->size * CHAR_BIT - off_b)) {
519 field->size * CHAR_BIT - off_b;
520 dcopy->offset += actions[i].length;
526 MLX5_ASSERT(item->spec);
527 data = flow_dv_fetch_field((const uint8_t *)item->spec +
528 field->offset, field->size);
529 /* Shift out the trailing masked bits from data. */
530 data = (data & mask) >> off_b;
531 actions[i].data1 = rte_cpu_to_be_32(data);
533 /* Convert entire record to expected big-endian format. */
534 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
538 } while (field->size);
539 if (resource->actions_num == i)
540 return rte_flow_error_set(error, EINVAL,
541 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
542 "invalid modification flow item");
543 resource->actions_num = i;
548 * Convert modify-header set IPv4 address action to DV specification.
550 * @param[in,out] resource
551 * Pointer to the modify-header resource.
553 * Pointer to action specification.
555 * Pointer to the error structure.
558 * 0 on success, a negative errno value otherwise and rte_errno is set.
561 flow_dv_convert_action_modify_ipv4
562 (struct mlx5_flow_dv_modify_hdr_resource *resource,
563 const struct rte_flow_action *action,
564 struct rte_flow_error *error)
566 const struct rte_flow_action_set_ipv4 *conf =
567 (const struct rte_flow_action_set_ipv4 *)(action->conf);
568 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
569 struct rte_flow_item_ipv4 ipv4;
570 struct rte_flow_item_ipv4 ipv4_mask;
572 memset(&ipv4, 0, sizeof(ipv4));
573 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
574 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
575 ipv4.hdr.src_addr = conf->ipv4_addr;
576 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
578 ipv4.hdr.dst_addr = conf->ipv4_addr;
579 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
582 item.mask = &ipv4_mask;
583 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
584 MLX5_MODIFICATION_TYPE_SET, error);
588 * Convert modify-header set IPv6 address action to DV specification.
590 * @param[in,out] resource
591 * Pointer to the modify-header resource.
593 * Pointer to action specification.
595 * Pointer to the error structure.
598 * 0 on success, a negative errno value otherwise and rte_errno is set.
601 flow_dv_convert_action_modify_ipv6
602 (struct mlx5_flow_dv_modify_hdr_resource *resource,
603 const struct rte_flow_action *action,
604 struct rte_flow_error *error)
606 const struct rte_flow_action_set_ipv6 *conf =
607 (const struct rte_flow_action_set_ipv6 *)(action->conf);
608 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
609 struct rte_flow_item_ipv6 ipv6;
610 struct rte_flow_item_ipv6 ipv6_mask;
612 memset(&ipv6, 0, sizeof(ipv6));
613 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
614 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
615 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
616 sizeof(ipv6.hdr.src_addr));
617 memcpy(&ipv6_mask.hdr.src_addr,
618 &rte_flow_item_ipv6_mask.hdr.src_addr,
619 sizeof(ipv6.hdr.src_addr));
621 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
622 sizeof(ipv6.hdr.dst_addr));
623 memcpy(&ipv6_mask.hdr.dst_addr,
624 &rte_flow_item_ipv6_mask.hdr.dst_addr,
625 sizeof(ipv6.hdr.dst_addr));
628 item.mask = &ipv6_mask;
629 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
630 MLX5_MODIFICATION_TYPE_SET, error);
634 * Convert modify-header set MAC address action to DV specification.
636 * @param[in,out] resource
637 * Pointer to the modify-header resource.
639 * Pointer to action specification.
641 * Pointer to the error structure.
644 * 0 on success, a negative errno value otherwise and rte_errno is set.
647 flow_dv_convert_action_modify_mac
648 (struct mlx5_flow_dv_modify_hdr_resource *resource,
649 const struct rte_flow_action *action,
650 struct rte_flow_error *error)
652 const struct rte_flow_action_set_mac *conf =
653 (const struct rte_flow_action_set_mac *)(action->conf);
654 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
655 struct rte_flow_item_eth eth;
656 struct rte_flow_item_eth eth_mask;
658 memset(ð, 0, sizeof(eth));
659 memset(ð_mask, 0, sizeof(eth_mask));
660 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
661 memcpy(ð.src.addr_bytes, &conf->mac_addr,
662 sizeof(eth.src.addr_bytes));
663 memcpy(ð_mask.src.addr_bytes,
664 &rte_flow_item_eth_mask.src.addr_bytes,
665 sizeof(eth_mask.src.addr_bytes));
667 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
668 sizeof(eth.dst.addr_bytes));
669 memcpy(ð_mask.dst.addr_bytes,
670 &rte_flow_item_eth_mask.dst.addr_bytes,
671 sizeof(eth_mask.dst.addr_bytes));
674 item.mask = ð_mask;
675 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
676 MLX5_MODIFICATION_TYPE_SET, error);
680 * Convert modify-header set VLAN VID action to DV specification.
682 * @param[in,out] resource
683 * Pointer to the modify-header resource.
685 * Pointer to action specification.
687 * Pointer to the error structure.
690 * 0 on success, a negative errno value otherwise and rte_errno is set.
693 flow_dv_convert_action_modify_vlan_vid
694 (struct mlx5_flow_dv_modify_hdr_resource *resource,
695 const struct rte_flow_action *action,
696 struct rte_flow_error *error)
698 const struct rte_flow_action_of_set_vlan_vid *conf =
699 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
700 int i = resource->actions_num;
701 struct mlx5_modification_cmd *actions = resource->actions;
702 struct field_modify_info *field = modify_vlan_out_first_vid;
704 if (i >= MLX5_MAX_MODIFY_NUM)
705 return rte_flow_error_set(error, EINVAL,
706 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
707 "too many items to modify");
708 actions[i] = (struct mlx5_modification_cmd) {
709 .action_type = MLX5_MODIFICATION_TYPE_SET,
711 .length = field->size,
712 .offset = field->offset,
714 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
715 actions[i].data1 = conf->vlan_vid;
716 actions[i].data1 = actions[i].data1 << 16;
717 resource->actions_num = ++i;
722 * Convert modify-header set TP action to DV specification.
724 * @param[in,out] resource
725 * Pointer to the modify-header resource.
727 * Pointer to action specification.
729 * Pointer to rte_flow_item objects list.
731 * Pointer to flow attributes structure.
732 * @param[in] dev_flow
733 * Pointer to the sub flow.
734 * @param[in] tunnel_decap
735 * Whether action is after tunnel decapsulation.
737 * Pointer to the error structure.
740 * 0 on success, a negative errno value otherwise and rte_errno is set.
743 flow_dv_convert_action_modify_tp
744 (struct mlx5_flow_dv_modify_hdr_resource *resource,
745 const struct rte_flow_action *action,
746 const struct rte_flow_item *items,
747 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
748 bool tunnel_decap, struct rte_flow_error *error)
750 const struct rte_flow_action_set_tp *conf =
751 (const struct rte_flow_action_set_tp *)(action->conf);
752 struct rte_flow_item item;
753 struct rte_flow_item_udp udp;
754 struct rte_flow_item_udp udp_mask;
755 struct rte_flow_item_tcp tcp;
756 struct rte_flow_item_tcp tcp_mask;
757 struct field_modify_info *field;
760 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
762 memset(&udp, 0, sizeof(udp));
763 memset(&udp_mask, 0, sizeof(udp_mask));
764 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
765 udp.hdr.src_port = conf->port;
766 udp_mask.hdr.src_port =
767 rte_flow_item_udp_mask.hdr.src_port;
769 udp.hdr.dst_port = conf->port;
770 udp_mask.hdr.dst_port =
771 rte_flow_item_udp_mask.hdr.dst_port;
773 item.type = RTE_FLOW_ITEM_TYPE_UDP;
775 item.mask = &udp_mask;
778 MLX5_ASSERT(attr->tcp);
779 memset(&tcp, 0, sizeof(tcp));
780 memset(&tcp_mask, 0, sizeof(tcp_mask));
781 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
782 tcp.hdr.src_port = conf->port;
783 tcp_mask.hdr.src_port =
784 rte_flow_item_tcp_mask.hdr.src_port;
786 tcp.hdr.dst_port = conf->port;
787 tcp_mask.hdr.dst_port =
788 rte_flow_item_tcp_mask.hdr.dst_port;
790 item.type = RTE_FLOW_ITEM_TYPE_TCP;
792 item.mask = &tcp_mask;
795 return flow_dv_convert_modify_action(&item, field, NULL, resource,
796 MLX5_MODIFICATION_TYPE_SET, error);
800 * Convert modify-header set TTL action to DV specification.
802 * @param[in,out] resource
803 * Pointer to the modify-header resource.
805 * Pointer to action specification.
807 * Pointer to rte_flow_item objects list.
809 * Pointer to flow attributes structure.
810 * @param[in] dev_flow
811 * Pointer to the sub flow.
812 * @param[in] tunnel_decap
813 * Whether action is after tunnel decapsulation.
815 * Pointer to the error structure.
818 * 0 on success, a negative errno value otherwise and rte_errno is set.
821 flow_dv_convert_action_modify_ttl
822 (struct mlx5_flow_dv_modify_hdr_resource *resource,
823 const struct rte_flow_action *action,
824 const struct rte_flow_item *items,
825 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
826 bool tunnel_decap, struct rte_flow_error *error)
828 const struct rte_flow_action_set_ttl *conf =
829 (const struct rte_flow_action_set_ttl *)(action->conf);
830 struct rte_flow_item item;
831 struct rte_flow_item_ipv4 ipv4;
832 struct rte_flow_item_ipv4 ipv4_mask;
833 struct rte_flow_item_ipv6 ipv6;
834 struct rte_flow_item_ipv6 ipv6_mask;
835 struct field_modify_info *field;
838 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
840 memset(&ipv4, 0, sizeof(ipv4));
841 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
842 ipv4.hdr.time_to_live = conf->ttl_value;
843 ipv4_mask.hdr.time_to_live = 0xFF;
844 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
846 item.mask = &ipv4_mask;
849 MLX5_ASSERT(attr->ipv6);
850 memset(&ipv6, 0, sizeof(ipv6));
851 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
852 ipv6.hdr.hop_limits = conf->ttl_value;
853 ipv6_mask.hdr.hop_limits = 0xFF;
854 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
856 item.mask = &ipv6_mask;
859 return flow_dv_convert_modify_action(&item, field, NULL, resource,
860 MLX5_MODIFICATION_TYPE_SET, error);
864 * Convert modify-header decrement TTL action to DV specification.
866 * @param[in,out] resource
867 * Pointer to the modify-header resource.
869 * Pointer to action specification.
871 * Pointer to rte_flow_item objects list.
873 * Pointer to flow attributes structure.
874 * @param[in] dev_flow
875 * Pointer to the sub flow.
876 * @param[in] tunnel_decap
877 * Whether action is after tunnel decapsulation.
879 * Pointer to the error structure.
882 * 0 on success, a negative errno value otherwise and rte_errno is set.
885 flow_dv_convert_action_modify_dec_ttl
886 (struct mlx5_flow_dv_modify_hdr_resource *resource,
887 const struct rte_flow_item *items,
888 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
889 bool tunnel_decap, struct rte_flow_error *error)
891 struct rte_flow_item item;
892 struct rte_flow_item_ipv4 ipv4;
893 struct rte_flow_item_ipv4 ipv4_mask;
894 struct rte_flow_item_ipv6 ipv6;
895 struct rte_flow_item_ipv6 ipv6_mask;
896 struct field_modify_info *field;
899 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
901 memset(&ipv4, 0, sizeof(ipv4));
902 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
903 ipv4.hdr.time_to_live = 0xFF;
904 ipv4_mask.hdr.time_to_live = 0xFF;
905 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
907 item.mask = &ipv4_mask;
910 MLX5_ASSERT(attr->ipv6);
911 memset(&ipv6, 0, sizeof(ipv6));
912 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
913 ipv6.hdr.hop_limits = 0xFF;
914 ipv6_mask.hdr.hop_limits = 0xFF;
915 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
917 item.mask = &ipv6_mask;
920 return flow_dv_convert_modify_action(&item, field, NULL, resource,
921 MLX5_MODIFICATION_TYPE_ADD, error);
925 * Convert modify-header increment/decrement TCP Sequence number
926 * to DV specification.
928 * @param[in,out] resource
929 * Pointer to the modify-header resource.
931 * Pointer to action specification.
933 * Pointer to the error structure.
936 * 0 on success, a negative errno value otherwise and rte_errno is set.
939 flow_dv_convert_action_modify_tcp_seq
940 (struct mlx5_flow_dv_modify_hdr_resource *resource,
941 const struct rte_flow_action *action,
942 struct rte_flow_error *error)
944 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
945 uint64_t value = rte_be_to_cpu_32(*conf);
946 struct rte_flow_item item;
947 struct rte_flow_item_tcp tcp;
948 struct rte_flow_item_tcp tcp_mask;
950 memset(&tcp, 0, sizeof(tcp));
951 memset(&tcp_mask, 0, sizeof(tcp_mask));
952 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
954 * The HW has no decrement operation, only increment operation.
955 * To simulate decrement X from Y using increment operation
956 * we need to add UINT32_MAX X times to Y.
957 * Each adding of UINT32_MAX decrements Y by 1.
960 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
961 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
962 item.type = RTE_FLOW_ITEM_TYPE_TCP;
964 item.mask = &tcp_mask;
965 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
966 MLX5_MODIFICATION_TYPE_ADD, error);
970 * Convert modify-header increment/decrement TCP Acknowledgment number
971 * to DV specification.
973 * @param[in,out] resource
974 * Pointer to the modify-header resource.
976 * Pointer to action specification.
978 * Pointer to the error structure.
981 * 0 on success, a negative errno value otherwise and rte_errno is set.
984 flow_dv_convert_action_modify_tcp_ack
985 (struct mlx5_flow_dv_modify_hdr_resource *resource,
986 const struct rte_flow_action *action,
987 struct rte_flow_error *error)
989 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
990 uint64_t value = rte_be_to_cpu_32(*conf);
991 struct rte_flow_item item;
992 struct rte_flow_item_tcp tcp;
993 struct rte_flow_item_tcp tcp_mask;
995 memset(&tcp, 0, sizeof(tcp));
996 memset(&tcp_mask, 0, sizeof(tcp_mask));
997 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
999 * The HW has no decrement operation, only increment operation.
1000 * To simulate decrement X from Y using increment operation
1001 * we need to add UINT32_MAX X times to Y.
1002 * Each adding of UINT32_MAX decrements Y by 1.
1004 value *= UINT32_MAX;
1005 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
1006 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
1007 item.type = RTE_FLOW_ITEM_TYPE_TCP;
1009 item.mask = &tcp_mask;
1010 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
1011 MLX5_MODIFICATION_TYPE_ADD, error);
1014 static enum mlx5_modification_field reg_to_field[] = {
1015 [REG_NON] = MLX5_MODI_OUT_NONE,
1016 [REG_A] = MLX5_MODI_META_DATA_REG_A,
1017 [REG_B] = MLX5_MODI_META_DATA_REG_B,
1018 [REG_C_0] = MLX5_MODI_META_REG_C_0,
1019 [REG_C_1] = MLX5_MODI_META_REG_C_1,
1020 [REG_C_2] = MLX5_MODI_META_REG_C_2,
1021 [REG_C_3] = MLX5_MODI_META_REG_C_3,
1022 [REG_C_4] = MLX5_MODI_META_REG_C_4,
1023 [REG_C_5] = MLX5_MODI_META_REG_C_5,
1024 [REG_C_6] = MLX5_MODI_META_REG_C_6,
1025 [REG_C_7] = MLX5_MODI_META_REG_C_7,
1029 * Convert register set to DV specification.
1031 * @param[in,out] resource
1032 * Pointer to the modify-header resource.
1034 * Pointer to action specification.
1036 * Pointer to the error structure.
1039 * 0 on success, a negative errno value otherwise and rte_errno is set.
1042 flow_dv_convert_action_set_reg
1043 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1044 const struct rte_flow_action *action,
1045 struct rte_flow_error *error)
1047 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
1048 struct mlx5_modification_cmd *actions = resource->actions;
1049 uint32_t i = resource->actions_num;
1051 if (i >= MLX5_MAX_MODIFY_NUM)
1052 return rte_flow_error_set(error, EINVAL,
1053 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1054 "too many items to modify");
1055 MLX5_ASSERT(conf->id != REG_NON);
1056 MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
1057 actions[i] = (struct mlx5_modification_cmd) {
1058 .action_type = MLX5_MODIFICATION_TYPE_SET,
1059 .field = reg_to_field[conf->id],
1060 .offset = conf->offset,
1061 .length = conf->length,
1063 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
1064 actions[i].data1 = rte_cpu_to_be_32(conf->data);
1066 resource->actions_num = i;
1071 * Convert SET_TAG action to DV specification.
1074 * Pointer to the rte_eth_dev structure.
1075 * @param[in,out] resource
1076 * Pointer to the modify-header resource.
1078 * Pointer to action specification.
1080 * Pointer to the error structure.
1083 * 0 on success, a negative errno value otherwise and rte_errno is set.
1086 flow_dv_convert_action_set_tag
1087 (struct rte_eth_dev *dev,
1088 struct mlx5_flow_dv_modify_hdr_resource *resource,
1089 const struct rte_flow_action_set_tag *conf,
1090 struct rte_flow_error *error)
1092 rte_be32_t data = rte_cpu_to_be_32(conf->data);
1093 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1094 struct rte_flow_item item = {
1098 struct field_modify_info reg_c_x[] = {
1101 enum mlx5_modification_field reg_type;
1104 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1107 MLX5_ASSERT(ret != REG_NON);
1108 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1109 reg_type = reg_to_field[ret];
1110 MLX5_ASSERT(reg_type > 0);
1111 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1112 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1113 MLX5_MODIFICATION_TYPE_SET, error);
1117 * Convert internal COPY_REG action to DV specification.
1120 * Pointer to the rte_eth_dev structure.
1121 * @param[in,out] res
1122 * Pointer to the modify-header resource.
1124 * Pointer to action specification.
1126 * Pointer to the error structure.
1129 * 0 on success, a negative errno value otherwise and rte_errno is set.
1132 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1133 struct mlx5_flow_dv_modify_hdr_resource *res,
1134 const struct rte_flow_action *action,
1135 struct rte_flow_error *error)
1137 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1138 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1139 struct rte_flow_item item = {
1143 struct field_modify_info reg_src[] = {
1144 {4, 0, reg_to_field[conf->src]},
1147 struct field_modify_info reg_dst = {
1149 .id = reg_to_field[conf->dst],
1151 /* Adjust reg_c[0] usage according to reported mask. */
1152 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1153 struct mlx5_priv *priv = dev->data->dev_private;
1154 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1156 MLX5_ASSERT(reg_c0);
1157 MLX5_ASSERT(priv->sh->config.dv_xmeta_en !=
1158 MLX5_XMETA_MODE_LEGACY);
1159 if (conf->dst == REG_C_0) {
1160 /* Copy to reg_c[0], within mask only. */
1161 reg_dst.offset = rte_bsf32(reg_c0);
1162 mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1165 mask = rte_cpu_to_be_32(reg_c0);
1168 return flow_dv_convert_modify_action(&item,
1169 reg_src, ®_dst, res,
1170 MLX5_MODIFICATION_TYPE_COPY,
1175 * Convert MARK action to DV specification. This routine is used
1176 * in extensive metadata only and requires metadata register to be
1177 * handled. In legacy mode hardware tag resource is engaged.
1180 * Pointer to the rte_eth_dev structure.
1182 * Pointer to MARK action specification.
1183 * @param[in,out] resource
1184 * Pointer to the modify-header resource.
1186 * Pointer to the error structure.
1189 * 0 on success, a negative errno value otherwise and rte_errno is set.
1192 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1193 const struct rte_flow_action_mark *conf,
1194 struct mlx5_flow_dv_modify_hdr_resource *resource,
1195 struct rte_flow_error *error)
1197 struct mlx5_priv *priv = dev->data->dev_private;
1198 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1199 priv->sh->dv_mark_mask);
1200 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1201 struct rte_flow_item item = {
1205 struct field_modify_info reg_c_x[] = {
1211 return rte_flow_error_set(error, EINVAL,
1212 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1213 NULL, "zero mark action mask");
1214 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1217 MLX5_ASSERT(reg > 0);
1218 if (reg == REG_C_0) {
1219 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1220 uint32_t shl_c0 = rte_bsf32(msk_c0);
1222 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1223 mask = rte_cpu_to_be_32(mask) & msk_c0;
1224 mask = rte_cpu_to_be_32(mask << shl_c0);
1226 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1227 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1228 MLX5_MODIFICATION_TYPE_SET, error);
1232 * Get metadata register index for specified steering domain.
1235 * Pointer to the rte_eth_dev structure.
1237 * Attributes of flow to determine steering domain.
1239 * Pointer to the error structure.
1242 * positive index on success, a negative errno value otherwise
1243 * and rte_errno is set.
1245 static enum modify_reg
1246 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1247 const struct rte_flow_attr *attr,
1248 struct rte_flow_error *error)
1251 mlx5_flow_get_reg_id(dev, attr->transfer ?
1255 MLX5_METADATA_RX, 0, error);
1257 return rte_flow_error_set(error,
1258 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1259 NULL, "unavailable "
1260 "metadata register");
1265 * Convert SET_META action to DV specification.
1268 * Pointer to the rte_eth_dev structure.
1269 * @param[in,out] resource
1270 * Pointer to the modify-header resource.
1272 * Attributes of flow that includes this item.
1274 * Pointer to action specification.
1276 * Pointer to the error structure.
1279 * 0 on success, a negative errno value otherwise and rte_errno is set.
1282 flow_dv_convert_action_set_meta
1283 (struct rte_eth_dev *dev,
1284 struct mlx5_flow_dv_modify_hdr_resource *resource,
1285 const struct rte_flow_attr *attr,
1286 const struct rte_flow_action_set_meta *conf,
1287 struct rte_flow_error *error)
1289 uint32_t mask = rte_cpu_to_be_32(conf->mask);
1290 uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1291 struct rte_flow_item item = {
1295 struct field_modify_info reg_c_x[] = {
1298 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1302 MLX5_ASSERT(reg != REG_NON);
1303 if (reg == REG_C_0) {
1304 struct mlx5_priv *priv = dev->data->dev_private;
1305 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1306 uint32_t shl_c0 = rte_bsf32(msk_c0);
1308 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1309 mask = rte_cpu_to_be_32(mask) & msk_c0;
1310 mask = rte_cpu_to_be_32(mask << shl_c0);
1312 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1313 /* The routine expects parameters in memory as big-endian ones. */
1314 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1315 MLX5_MODIFICATION_TYPE_SET, error);
1319 * Convert modify-header set IPv4 DSCP action to DV specification.
1321 * @param[in,out] resource
1322 * Pointer to the modify-header resource.
1324 * Pointer to action specification.
1326 * Pointer to the error structure.
1329 * 0 on success, a negative errno value otherwise and rte_errno is set.
1332 flow_dv_convert_action_modify_ipv4_dscp
1333 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1334 const struct rte_flow_action *action,
1335 struct rte_flow_error *error)
1337 const struct rte_flow_action_set_dscp *conf =
1338 (const struct rte_flow_action_set_dscp *)(action->conf);
1339 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1340 struct rte_flow_item_ipv4 ipv4;
1341 struct rte_flow_item_ipv4 ipv4_mask;
1343 memset(&ipv4, 0, sizeof(ipv4));
1344 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1345 ipv4.hdr.type_of_service = conf->dscp;
1346 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1348 item.mask = &ipv4_mask;
1349 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1350 MLX5_MODIFICATION_TYPE_SET, error);
1354 * Convert modify-header set IPv6 DSCP action to DV specification.
1356 * @param[in,out] resource
1357 * Pointer to the modify-header resource.
1359 * Pointer to action specification.
1361 * Pointer to the error structure.
1364 * 0 on success, a negative errno value otherwise and rte_errno is set.
1367 flow_dv_convert_action_modify_ipv6_dscp
1368 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1369 const struct rte_flow_action *action,
1370 struct rte_flow_error *error)
1372 const struct rte_flow_action_set_dscp *conf =
1373 (const struct rte_flow_action_set_dscp *)(action->conf);
1374 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1375 struct rte_flow_item_ipv6 ipv6;
1376 struct rte_flow_item_ipv6 ipv6_mask;
1378 memset(&ipv6, 0, sizeof(ipv6));
1379 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1381 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1382 * rdma-core only accept the DSCP bits byte aligned start from
1383 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1384 * bits in IPv6 case as rdma-core requires byte aligned value.
1386 ipv6.hdr.vtc_flow = conf->dscp;
1387 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1389 item.mask = &ipv6_mask;
1390 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1391 MLX5_MODIFICATION_TYPE_SET, error);
1395 mlx5_flow_item_field_width(struct rte_eth_dev *dev,
1396 enum rte_flow_field_id field, int inherit,
1397 const struct rte_flow_attr *attr,
1398 struct rte_flow_error *error)
1400 struct mlx5_priv *priv = dev->data->dev_private;
1403 case RTE_FLOW_FIELD_START:
1405 case RTE_FLOW_FIELD_MAC_DST:
1406 case RTE_FLOW_FIELD_MAC_SRC:
1408 case RTE_FLOW_FIELD_VLAN_TYPE:
1410 case RTE_FLOW_FIELD_VLAN_ID:
1412 case RTE_FLOW_FIELD_MAC_TYPE:
1414 case RTE_FLOW_FIELD_IPV4_DSCP:
1416 case RTE_FLOW_FIELD_IPV4_TTL:
1418 case RTE_FLOW_FIELD_IPV4_SRC:
1419 case RTE_FLOW_FIELD_IPV4_DST:
1421 case RTE_FLOW_FIELD_IPV6_DSCP:
1423 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1425 case RTE_FLOW_FIELD_IPV6_SRC:
1426 case RTE_FLOW_FIELD_IPV6_DST:
1428 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1429 case RTE_FLOW_FIELD_TCP_PORT_DST:
1431 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1432 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1434 case RTE_FLOW_FIELD_TCP_FLAGS:
1436 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1437 case RTE_FLOW_FIELD_UDP_PORT_DST:
1439 case RTE_FLOW_FIELD_VXLAN_VNI:
1440 case RTE_FLOW_FIELD_GENEVE_VNI:
1442 case RTE_FLOW_FIELD_GTP_TEID:
1443 case RTE_FLOW_FIELD_TAG:
1445 case RTE_FLOW_FIELD_MARK:
1446 return __builtin_popcount(priv->sh->dv_mark_mask);
1447 case RTE_FLOW_FIELD_META:
1448 return (flow_dv_get_metadata_reg(dev, attr, error) == REG_C_0) ?
1449 __builtin_popcount(priv->sh->dv_meta_mask) : 32;
1450 case RTE_FLOW_FIELD_POINTER:
1451 case RTE_FLOW_FIELD_VALUE:
1452 return inherit < 0 ? 0 : inherit;
1453 case RTE_FLOW_FIELD_IPV4_ECN:
1454 case RTE_FLOW_FIELD_IPV6_ECN:
1463 mlx5_flow_field_id_to_modify_info
1464 (const struct rte_flow_action_modify_data *data,
1465 struct field_modify_info *info, uint32_t *mask,
1466 uint32_t width, struct rte_eth_dev *dev,
1467 const struct rte_flow_attr *attr, struct rte_flow_error *error)
1469 struct mlx5_priv *priv = dev->data->dev_private;
1473 switch (data->field) {
1474 case RTE_FLOW_FIELD_START:
1475 /* not supported yet */
1478 case RTE_FLOW_FIELD_MAC_DST:
1479 off = data->offset > 16 ? data->offset - 16 : 0;
1481 if (data->offset < 16) {
1482 info[idx] = (struct field_modify_info){2, 4,
1483 MLX5_MODI_OUT_DMAC_15_0};
1485 mask[1] = rte_cpu_to_be_16(0xffff >>
1489 mask[1] = RTE_BE16(0xffff);
1496 info[idx] = (struct field_modify_info){4, 0,
1497 MLX5_MODI_OUT_DMAC_47_16};
1498 mask[0] = rte_cpu_to_be_32((0xffffffff >>
1499 (32 - width)) << off);
1501 if (data->offset < 16)
1502 info[idx++] = (struct field_modify_info){2, 0,
1503 MLX5_MODI_OUT_DMAC_15_0};
1504 info[idx] = (struct field_modify_info){4, off,
1505 MLX5_MODI_OUT_DMAC_47_16};
1508 case RTE_FLOW_FIELD_MAC_SRC:
1509 off = data->offset > 16 ? data->offset - 16 : 0;
1511 if (data->offset < 16) {
1512 info[idx] = (struct field_modify_info){2, 4,
1513 MLX5_MODI_OUT_SMAC_15_0};
1515 mask[1] = rte_cpu_to_be_16(0xffff >>
1519 mask[1] = RTE_BE16(0xffff);
1526 info[idx] = (struct field_modify_info){4, 0,
1527 MLX5_MODI_OUT_SMAC_47_16};
1528 mask[0] = rte_cpu_to_be_32((0xffffffff >>
1529 (32 - width)) << off);
1531 if (data->offset < 16)
1532 info[idx++] = (struct field_modify_info){2, 0,
1533 MLX5_MODI_OUT_SMAC_15_0};
1534 info[idx] = (struct field_modify_info){4, off,
1535 MLX5_MODI_OUT_SMAC_47_16};
1538 case RTE_FLOW_FIELD_VLAN_TYPE:
1539 /* not supported yet */
1541 case RTE_FLOW_FIELD_VLAN_ID:
1542 info[idx] = (struct field_modify_info){2, 0,
1543 MLX5_MODI_OUT_FIRST_VID};
1545 mask[idx] = rte_cpu_to_be_16(0x0fff >> (12 - width));
1547 case RTE_FLOW_FIELD_MAC_TYPE:
1548 info[idx] = (struct field_modify_info){2, 0,
1549 MLX5_MODI_OUT_ETHERTYPE};
1551 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1553 case RTE_FLOW_FIELD_IPV4_DSCP:
1554 info[idx] = (struct field_modify_info){1, 0,
1555 MLX5_MODI_OUT_IP_DSCP};
1557 mask[idx] = 0x3f >> (6 - width);
1559 case RTE_FLOW_FIELD_IPV4_TTL:
1560 info[idx] = (struct field_modify_info){1, 0,
1561 MLX5_MODI_OUT_IPV4_TTL};
1563 mask[idx] = 0xff >> (8 - width);
1565 case RTE_FLOW_FIELD_IPV4_SRC:
1566 info[idx] = (struct field_modify_info){4, 0,
1567 MLX5_MODI_OUT_SIPV4};
1569 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1572 case RTE_FLOW_FIELD_IPV4_DST:
1573 info[idx] = (struct field_modify_info){4, 0,
1574 MLX5_MODI_OUT_DIPV4};
1576 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1579 case RTE_FLOW_FIELD_IPV6_DSCP:
1580 info[idx] = (struct field_modify_info){1, 0,
1581 MLX5_MODI_OUT_IP_DSCP};
1583 mask[idx] = 0x3f >> (6 - width);
1585 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1586 info[idx] = (struct field_modify_info){1, 0,
1587 MLX5_MODI_OUT_IPV6_HOPLIMIT};
1589 mask[idx] = 0xff >> (8 - width);
1591 case RTE_FLOW_FIELD_IPV6_SRC:
1593 if (data->offset < 32) {
1594 info[idx] = (struct field_modify_info){4, 12,
1595 MLX5_MODI_OUT_SIPV6_31_0};
1598 rte_cpu_to_be_32(0xffffffff >>
1602 mask[3] = RTE_BE32(0xffffffff);
1609 if (data->offset < 64) {
1610 info[idx] = (struct field_modify_info){4, 8,
1611 MLX5_MODI_OUT_SIPV6_63_32};
1614 rte_cpu_to_be_32(0xffffffff >>
1618 mask[2] = RTE_BE32(0xffffffff);
1625 if (data->offset < 96) {
1626 info[idx] = (struct field_modify_info){4, 4,
1627 MLX5_MODI_OUT_SIPV6_95_64};
1630 rte_cpu_to_be_32(0xffffffff >>
1634 mask[1] = RTE_BE32(0xffffffff);
1641 info[idx] = (struct field_modify_info){4, 0,
1642 MLX5_MODI_OUT_SIPV6_127_96};
1643 mask[0] = rte_cpu_to_be_32(0xffffffff >> (32 - width));
1645 if (data->offset < 32)
1646 info[idx++] = (struct field_modify_info){4, 0,
1647 MLX5_MODI_OUT_SIPV6_31_0};
1648 if (data->offset < 64)
1649 info[idx++] = (struct field_modify_info){4, 0,
1650 MLX5_MODI_OUT_SIPV6_63_32};
1651 if (data->offset < 96)
1652 info[idx++] = (struct field_modify_info){4, 0,
1653 MLX5_MODI_OUT_SIPV6_95_64};
1654 if (data->offset < 128)
1655 info[idx++] = (struct field_modify_info){4, 0,
1656 MLX5_MODI_OUT_SIPV6_127_96};
1659 case RTE_FLOW_FIELD_IPV6_DST:
1661 if (data->offset < 32) {
1662 info[idx] = (struct field_modify_info){4, 12,
1663 MLX5_MODI_OUT_DIPV6_31_0};
1666 rte_cpu_to_be_32(0xffffffff >>
1670 mask[3] = RTE_BE32(0xffffffff);
1677 if (data->offset < 64) {
1678 info[idx] = (struct field_modify_info){4, 8,
1679 MLX5_MODI_OUT_DIPV6_63_32};
1682 rte_cpu_to_be_32(0xffffffff >>
1686 mask[2] = RTE_BE32(0xffffffff);
1693 if (data->offset < 96) {
1694 info[idx] = (struct field_modify_info){4, 4,
1695 MLX5_MODI_OUT_DIPV6_95_64};
1698 rte_cpu_to_be_32(0xffffffff >>
1702 mask[1] = RTE_BE32(0xffffffff);
1709 info[idx] = (struct field_modify_info){4, 0,
1710 MLX5_MODI_OUT_DIPV6_127_96};
1711 mask[0] = rte_cpu_to_be_32(0xffffffff >> (32 - width));
1713 if (data->offset < 32)
1714 info[idx++] = (struct field_modify_info){4, 0,
1715 MLX5_MODI_OUT_DIPV6_31_0};
1716 if (data->offset < 64)
1717 info[idx++] = (struct field_modify_info){4, 0,
1718 MLX5_MODI_OUT_DIPV6_63_32};
1719 if (data->offset < 96)
1720 info[idx++] = (struct field_modify_info){4, 0,
1721 MLX5_MODI_OUT_DIPV6_95_64};
1722 if (data->offset < 128)
1723 info[idx++] = (struct field_modify_info){4, 0,
1724 MLX5_MODI_OUT_DIPV6_127_96};
1727 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1728 info[idx] = (struct field_modify_info){2, 0,
1729 MLX5_MODI_OUT_TCP_SPORT};
1731 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1733 case RTE_FLOW_FIELD_TCP_PORT_DST:
1734 info[idx] = (struct field_modify_info){2, 0,
1735 MLX5_MODI_OUT_TCP_DPORT};
1737 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1739 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1740 info[idx] = (struct field_modify_info){4, 0,
1741 MLX5_MODI_OUT_TCP_SEQ_NUM};
1743 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1746 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1747 info[idx] = (struct field_modify_info){4, 0,
1748 MLX5_MODI_OUT_TCP_ACK_NUM};
1750 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1753 case RTE_FLOW_FIELD_TCP_FLAGS:
1754 info[idx] = (struct field_modify_info){2, 0,
1755 MLX5_MODI_OUT_TCP_FLAGS};
1757 mask[idx] = rte_cpu_to_be_16(0x1ff >> (9 - width));
1759 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1760 info[idx] = (struct field_modify_info){2, 0,
1761 MLX5_MODI_OUT_UDP_SPORT};
1763 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1765 case RTE_FLOW_FIELD_UDP_PORT_DST:
1766 info[idx] = (struct field_modify_info){2, 0,
1767 MLX5_MODI_OUT_UDP_DPORT};
1769 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1771 case RTE_FLOW_FIELD_VXLAN_VNI:
1772 /* not supported yet */
1774 case RTE_FLOW_FIELD_GENEVE_VNI:
1775 /* not supported yet*/
1777 case RTE_FLOW_FIELD_GTP_TEID:
1778 info[idx] = (struct field_modify_info){4, 0,
1779 MLX5_MODI_GTP_TEID};
1781 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1784 case RTE_FLOW_FIELD_TAG:
1786 int reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
1787 data->level, error);
1790 MLX5_ASSERT(reg != REG_NON);
1791 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1792 info[idx] = (struct field_modify_info){4, 0,
1796 rte_cpu_to_be_32(0xffffffff >>
1800 case RTE_FLOW_FIELD_MARK:
1802 uint32_t mark_mask = priv->sh->dv_mark_mask;
1803 uint32_t mark_count = __builtin_popcount(mark_mask);
1804 int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
1808 MLX5_ASSERT(reg != REG_NON);
1809 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1810 info[idx] = (struct field_modify_info){4, 0,
1813 mask[idx] = rte_cpu_to_be_32((mark_mask >>
1814 (mark_count - width)) & mark_mask);
1817 case RTE_FLOW_FIELD_META:
1819 uint32_t meta_mask = priv->sh->dv_meta_mask;
1820 uint32_t meta_count = __builtin_popcount(meta_mask);
1821 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1824 MLX5_ASSERT(reg != REG_NON);
1825 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1826 info[idx] = (struct field_modify_info){4, 0,
1829 mask[idx] = rte_cpu_to_be_32((meta_mask >>
1830 (meta_count - width)) & meta_mask);
1833 case RTE_FLOW_FIELD_IPV4_ECN:
1834 case RTE_FLOW_FIELD_IPV6_ECN:
1835 info[idx] = (struct field_modify_info){1, 0,
1836 MLX5_MODI_OUT_IP_ECN};
1838 mask[idx] = 0x3 >> (2 - width);
1840 case RTE_FLOW_FIELD_POINTER:
1841 case RTE_FLOW_FIELD_VALUE:
1849 * Convert modify_field action to DV specification.
1852 * Pointer to the rte_eth_dev structure.
1853 * @param[in,out] resource
1854 * Pointer to the modify-header resource.
1856 * Pointer to action specification.
1858 * Attributes of flow that includes this item.
1860 * Pointer to the error structure.
1863 * 0 on success, a negative errno value otherwise and rte_errno is set.
1866 flow_dv_convert_action_modify_field
1867 (struct rte_eth_dev *dev,
1868 struct mlx5_flow_dv_modify_hdr_resource *resource,
1869 const struct rte_flow_action *action,
1870 const struct rte_flow_attr *attr,
1871 struct rte_flow_error *error)
1873 const struct rte_flow_action_modify_field *conf =
1874 (const struct rte_flow_action_modify_field *)(action->conf);
1875 struct rte_flow_item item = {
1879 struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1881 struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1883 uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1884 uint32_t type, meta = 0;
1886 if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1887 conf->src.field == RTE_FLOW_FIELD_VALUE) {
1888 type = MLX5_MODIFICATION_TYPE_SET;
1889 /** For SET fill the destination field (field) first. */
1890 mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1893 item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
1894 (void *)(uintptr_t)conf->src.pvalue :
1895 (void *)(uintptr_t)&conf->src.value;
1896 if (conf->dst.field == RTE_FLOW_FIELD_META) {
1897 meta = *(const unaligned_uint32_t *)item.spec;
1898 meta = rte_cpu_to_be_32(meta);
1902 type = MLX5_MODIFICATION_TYPE_COPY;
1903 /** For COPY fill the destination field (dcopy) without mask. */
1904 mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1907 /** Then construct the source field (field) with mask. */
1908 mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1913 return flow_dv_convert_modify_action(&item,
1914 field, dcopy, resource, type, error);
1918 * Validate MARK item.
1921 * Pointer to the rte_eth_dev structure.
1923 * Item specification.
1925 * Attributes of flow that includes this item.
1927 * Pointer to error structure.
1930 * 0 on success, a negative errno value otherwise and rte_errno is set.
1933 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1934 const struct rte_flow_item *item,
1935 const struct rte_flow_attr *attr __rte_unused,
1936 struct rte_flow_error *error)
1938 struct mlx5_priv *priv = dev->data->dev_private;
1939 struct mlx5_sh_config *config = &priv->sh->config;
1940 const struct rte_flow_item_mark *spec = item->spec;
1941 const struct rte_flow_item_mark *mask = item->mask;
1942 const struct rte_flow_item_mark nic_mask = {
1943 .id = priv->sh->dv_mark_mask,
1947 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1948 return rte_flow_error_set(error, ENOTSUP,
1949 RTE_FLOW_ERROR_TYPE_ITEM, item,
1950 "extended metadata feature"
1952 if (!mlx5_flow_ext_mreg_supported(dev))
1953 return rte_flow_error_set(error, ENOTSUP,
1954 RTE_FLOW_ERROR_TYPE_ITEM, item,
1955 "extended metadata register"
1956 " isn't supported");
1958 return rte_flow_error_set(error, ENOTSUP,
1959 RTE_FLOW_ERROR_TYPE_ITEM, item,
1960 "extended metadata register"
1961 " isn't available");
1962 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1966 return rte_flow_error_set(error, EINVAL,
1967 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1969 "data cannot be empty");
1970 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1971 return rte_flow_error_set(error, EINVAL,
1972 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1974 "mark id exceeds the limit");
1978 return rte_flow_error_set(error, EINVAL,
1979 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1980 "mask cannot be zero");
1982 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1983 (const uint8_t *)&nic_mask,
1984 sizeof(struct rte_flow_item_mark),
1985 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1992 * Validate META item.
1995 * Pointer to the rte_eth_dev structure.
1997 * Item specification.
1999 * Attributes of flow that includes this item.
2001 * Pointer to error structure.
2004 * 0 on success, a negative errno value otherwise and rte_errno is set.
2007 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
2008 const struct rte_flow_item *item,
2009 const struct rte_flow_attr *attr,
2010 struct rte_flow_error *error)
2012 struct mlx5_priv *priv = dev->data->dev_private;
2013 struct mlx5_sh_config *config = &priv->sh->config;
2014 const struct rte_flow_item_meta *spec = item->spec;
2015 const struct rte_flow_item_meta *mask = item->mask;
2016 struct rte_flow_item_meta nic_mask = {
2023 return rte_flow_error_set(error, EINVAL,
2024 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2026 "data cannot be empty");
2027 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2028 if (!mlx5_flow_ext_mreg_supported(dev))
2029 return rte_flow_error_set(error, ENOTSUP,
2030 RTE_FLOW_ERROR_TYPE_ITEM, item,
2031 "extended metadata register"
2032 " isn't supported");
2033 reg = flow_dv_get_metadata_reg(dev, attr, error);
2037 return rte_flow_error_set(error, ENOTSUP,
2038 RTE_FLOW_ERROR_TYPE_ITEM, item,
2039 "unavailable extended metadata register");
2041 return rte_flow_error_set(error, ENOTSUP,
2042 RTE_FLOW_ERROR_TYPE_ITEM, item,
2046 nic_mask.data = priv->sh->dv_meta_mask;
2049 return rte_flow_error_set(error, ENOTSUP,
2050 RTE_FLOW_ERROR_TYPE_ITEM, item,
2051 "extended metadata feature "
2052 "should be enabled when "
2053 "meta item is requested "
2054 "with e-switch mode ");
2056 return rte_flow_error_set(error, ENOTSUP,
2057 RTE_FLOW_ERROR_TYPE_ITEM, item,
2058 "match on metadata for ingress "
2059 "is not supported in legacy "
2063 mask = &rte_flow_item_meta_mask;
2065 return rte_flow_error_set(error, EINVAL,
2066 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2067 "mask cannot be zero");
2069 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2070 (const uint8_t *)&nic_mask,
2071 sizeof(struct rte_flow_item_meta),
2072 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2077 * Validate TAG item.
2080 * Pointer to the rte_eth_dev structure.
2082 * Item specification.
2084 * Attributes of flow that includes this item.
2086 * Pointer to error structure.
2089 * 0 on success, a negative errno value otherwise and rte_errno is set.
2092 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2093 const struct rte_flow_item *item,
2094 const struct rte_flow_attr *attr __rte_unused,
2095 struct rte_flow_error *error)
2097 const struct rte_flow_item_tag *spec = item->spec;
2098 const struct rte_flow_item_tag *mask = item->mask;
2099 const struct rte_flow_item_tag nic_mask = {
2100 .data = RTE_BE32(UINT32_MAX),
2105 if (!mlx5_flow_ext_mreg_supported(dev))
2106 return rte_flow_error_set(error, ENOTSUP,
2107 RTE_FLOW_ERROR_TYPE_ITEM, item,
2108 "extensive metadata register"
2109 " isn't supported");
2111 return rte_flow_error_set(error, EINVAL,
2112 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2114 "data cannot be empty");
2116 mask = &rte_flow_item_tag_mask;
2118 return rte_flow_error_set(error, EINVAL,
2119 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2120 "mask cannot be zero");
2122 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2123 (const uint8_t *)&nic_mask,
2124 sizeof(struct rte_flow_item_tag),
2125 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2128 if (mask->index != 0xff)
2129 return rte_flow_error_set(error, EINVAL,
2130 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2131 "partial mask for tag index"
2132 " is not supported");
2133 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2136 MLX5_ASSERT(ret != REG_NON);
2141 * Validate vport item.
2144 * Pointer to the rte_eth_dev structure.
2146 * Item specification.
2148 * Attributes of flow that includes this item.
2149 * @param[in] item_flags
2150 * Bit-fields that holds the items detected until now.
2152 * Pointer to error structure.
2155 * 0 on success, a negative errno value otherwise and rte_errno is set.
2158 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2159 const struct rte_flow_item *item,
2160 const struct rte_flow_attr *attr,
2161 uint64_t item_flags,
2162 struct rte_flow_error *error)
2164 const struct rte_flow_item_port_id *spec = item->spec;
2165 const struct rte_flow_item_port_id *mask = item->mask;
2166 const struct rte_flow_item_port_id switch_mask = {
2169 struct mlx5_priv *esw_priv;
2170 struct mlx5_priv *dev_priv;
2173 if (!attr->transfer)
2174 return rte_flow_error_set(error, EINVAL,
2175 RTE_FLOW_ERROR_TYPE_ITEM,
2177 "match on port id is valid only"
2178 " when transfer flag is enabled");
2179 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2180 return rte_flow_error_set(error, ENOTSUP,
2181 RTE_FLOW_ERROR_TYPE_ITEM, item,
2182 "multiple source ports are not"
2185 mask = &switch_mask;
2186 if (mask->id != 0xffffffff)
2187 return rte_flow_error_set(error, ENOTSUP,
2188 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2190 "no support for partial mask on"
2192 ret = mlx5_flow_item_acceptable
2193 (item, (const uint8_t *)mask,
2194 (const uint8_t *)&rte_flow_item_port_id_mask,
2195 sizeof(struct rte_flow_item_port_id),
2196 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2201 if (spec->id == MLX5_PORT_ESW_MGR)
2203 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2205 return rte_flow_error_set(error, rte_errno,
2206 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2207 "failed to obtain E-Switch info for"
2209 dev_priv = mlx5_dev_to_eswitch_info(dev);
2211 return rte_flow_error_set(error, rte_errno,
2212 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2214 "failed to obtain E-Switch info");
2215 if (esw_priv->domain_id != dev_priv->domain_id)
2216 return rte_flow_error_set(error, EINVAL,
2217 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2218 "cannot match on a port from a"
2219 " different E-Switch");
2224 * Validate represented port item.
2227 * Pointer to the rte_eth_dev structure.
2229 * Item specification.
2231 * Attributes of flow that includes this item.
2232 * @param[in] item_flags
2233 * Bit-fields that holds the items detected until now.
2235 * Pointer to error structure.
2238 * 0 on success, a negative errno value otherwise and rte_errno is set.
2241 flow_dv_validate_item_represented_port(struct rte_eth_dev *dev,
2242 const struct rte_flow_item *item,
2243 const struct rte_flow_attr *attr,
2244 uint64_t item_flags,
2245 struct rte_flow_error *error)
2247 const struct rte_flow_item_ethdev *spec = item->spec;
2248 const struct rte_flow_item_ethdev *mask = item->mask;
2249 const struct rte_flow_item_ethdev switch_mask = {
2250 .port_id = UINT16_MAX,
2252 struct mlx5_priv *esw_priv;
2253 struct mlx5_priv *dev_priv;
2256 if (!attr->transfer)
2257 return rte_flow_error_set(error, EINVAL,
2258 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2259 "match on port id is valid only when transfer flag is enabled");
2260 if (item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT)
2261 return rte_flow_error_set(error, ENOTSUP,
2262 RTE_FLOW_ERROR_TYPE_ITEM, item,
2263 "multiple source ports are not supported");
2265 mask = &switch_mask;
2266 if (mask->port_id != UINT16_MAX)
2267 return rte_flow_error_set(error, ENOTSUP,
2268 RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2269 "no support for partial mask on \"id\" field");
2270 ret = mlx5_flow_item_acceptable
2271 (item, (const uint8_t *)mask,
2272 (const uint8_t *)&rte_flow_item_ethdev_mask,
2273 sizeof(struct rte_flow_item_ethdev),
2274 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2277 if (!spec || spec->port_id == UINT16_MAX)
2279 esw_priv = mlx5_port_to_eswitch_info(spec->port_id, false);
2281 return rte_flow_error_set(error, rte_errno,
2282 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2283 "failed to obtain E-Switch info for port");
2284 dev_priv = mlx5_dev_to_eswitch_info(dev);
2286 return rte_flow_error_set(error, rte_errno,
2287 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2289 "failed to obtain E-Switch info");
2290 if (esw_priv->domain_id != dev_priv->domain_id)
2291 return rte_flow_error_set(error, EINVAL,
2292 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2293 "cannot match on a port from a different E-Switch");
2298 * Validate VLAN item.
2301 * Item specification.
2302 * @param[in] item_flags
2303 * Bit-fields that holds the items detected until now.
2305 * Ethernet device flow is being created on.
2307 * Pointer to error structure.
2310 * 0 on success, a negative errno value otherwise and rte_errno is set.
2313 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2314 uint64_t item_flags,
2315 struct rte_eth_dev *dev,
2316 struct rte_flow_error *error)
2318 const struct rte_flow_item_vlan *mask = item->mask;
2319 const struct rte_flow_item_vlan nic_mask = {
2320 .tci = RTE_BE16(UINT16_MAX),
2321 .inner_type = RTE_BE16(UINT16_MAX),
2324 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2326 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2327 MLX5_FLOW_LAYER_INNER_L4) :
2328 (MLX5_FLOW_LAYER_OUTER_L3 |
2329 MLX5_FLOW_LAYER_OUTER_L4);
2330 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2331 MLX5_FLOW_LAYER_OUTER_VLAN;
2333 if (item_flags & vlanm)
2334 return rte_flow_error_set(error, EINVAL,
2335 RTE_FLOW_ERROR_TYPE_ITEM, item,
2336 "multiple VLAN layers not supported");
2337 else if ((item_flags & l34m) != 0)
2338 return rte_flow_error_set(error, EINVAL,
2339 RTE_FLOW_ERROR_TYPE_ITEM, item,
2340 "VLAN cannot follow L3/L4 layer");
2342 mask = &rte_flow_item_vlan_mask;
2343 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2344 (const uint8_t *)&nic_mask,
2345 sizeof(struct rte_flow_item_vlan),
2346 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2349 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2350 struct mlx5_priv *priv = dev->data->dev_private;
2352 if (priv->vmwa_context) {
2354 * Non-NULL context means we have a virtual machine
2355 * and SR-IOV enabled, we have to create VLAN interface
2356 * to make hypervisor to setup E-Switch vport
2357 * context correctly. We avoid creating the multiple
2358 * VLAN interfaces, so we cannot support VLAN tag mask.
2360 return rte_flow_error_set(error, EINVAL,
2361 RTE_FLOW_ERROR_TYPE_ITEM,
2363 "VLAN tag mask is not"
2364 " supported in virtual"
2372 * GTP flags are contained in 1 byte of the format:
2373 * -------------------------------------------
2374 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2375 * |-----------------------------------------|
2376 * | value | Version | PT | Res | E | S | PN |
2377 * -------------------------------------------
2379 * Matching is supported only for GTP flags E, S, PN.
2381 #define MLX5_GTP_FLAGS_MASK 0x07
2384 * Validate GTP item.
2387 * Pointer to the rte_eth_dev structure.
2389 * Item specification.
2390 * @param[in] item_flags
2391 * Bit-fields that holds the items detected until now.
2393 * Pointer to error structure.
2396 * 0 on success, a negative errno value otherwise and rte_errno is set.
2399 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2400 const struct rte_flow_item *item,
2401 uint64_t item_flags,
2402 struct rte_flow_error *error)
2404 struct mlx5_priv *priv = dev->data->dev_private;
2405 const struct rte_flow_item_gtp *spec = item->spec;
2406 const struct rte_flow_item_gtp *mask = item->mask;
2407 const struct rte_flow_item_gtp nic_mask = {
2408 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
2410 .teid = RTE_BE32(0xffffffff),
2413 if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_gtp)
2414 return rte_flow_error_set(error, ENOTSUP,
2415 RTE_FLOW_ERROR_TYPE_ITEM, item,
2416 "GTP support is not enabled");
2417 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2418 return rte_flow_error_set(error, ENOTSUP,
2419 RTE_FLOW_ERROR_TYPE_ITEM, item,
2420 "multiple tunnel layers not"
2422 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2423 return rte_flow_error_set(error, EINVAL,
2424 RTE_FLOW_ERROR_TYPE_ITEM, item,
2425 "no outer UDP layer found");
2427 mask = &rte_flow_item_gtp_mask;
2428 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
2429 return rte_flow_error_set(error, ENOTSUP,
2430 RTE_FLOW_ERROR_TYPE_ITEM, item,
2431 "Match is supported for GTP"
2433 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2434 (const uint8_t *)&nic_mask,
2435 sizeof(struct rte_flow_item_gtp),
2436 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2440 * Validate GTP PSC item.
2443 * Item specification.
2444 * @param[in] last_item
2445 * Previous validated item in the pattern items.
2446 * @param[in] gtp_item
2447 * Previous GTP item specification.
2449 * Pointer to flow attributes.
2451 * Pointer to error structure.
2454 * 0 on success, a negative errno value otherwise and rte_errno is set.
2457 flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2459 const struct rte_flow_item *gtp_item,
2460 const struct rte_flow_attr *attr,
2461 struct rte_flow_error *error)
2463 const struct rte_flow_item_gtp *gtp_spec;
2464 const struct rte_flow_item_gtp *gtp_mask;
2465 const struct rte_flow_item_gtp_psc *mask;
2466 const struct rte_flow_item_gtp_psc nic_mask = {
2471 if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2472 return rte_flow_error_set
2473 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2474 "GTP PSC item must be preceded with GTP item");
2475 gtp_spec = gtp_item->spec;
2476 gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2477 /* GTP spec and E flag is requested to match zero. */
2479 (gtp_mask->v_pt_rsv_flags &
2480 ~gtp_spec->v_pt_rsv_flags & MLX5_GTP_EXT_HEADER_FLAG))
2481 return rte_flow_error_set
2482 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2483 "GTP E flag must be 1 to match GTP PSC");
2484 /* Check the flow is not created in group zero. */
2485 if (!attr->transfer && !attr->group)
2486 return rte_flow_error_set
2487 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2488 "GTP PSC is not supported for group 0");
2489 /* GTP spec is here and E flag is requested to match zero. */
2492 mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2493 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2494 (const uint8_t *)&nic_mask,
2495 sizeof(struct rte_flow_item_gtp_psc),
2496 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2500 * Validate IPV4 item.
2501 * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2502 * add specific validation of fragment_offset field,
2505 * Item specification.
2506 * @param[in] item_flags
2507 * Bit-fields that holds the items detected until now.
2509 * Pointer to error structure.
2512 * 0 on success, a negative errno value otherwise and rte_errno is set.
2515 flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
2516 const struct rte_flow_item *item,
2517 uint64_t item_flags, uint64_t last_item,
2518 uint16_t ether_type, struct rte_flow_error *error)
2521 struct mlx5_priv *priv = dev->data->dev_private;
2522 struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
2523 const struct rte_flow_item_ipv4 *spec = item->spec;
2524 const struct rte_flow_item_ipv4 *last = item->last;
2525 const struct rte_flow_item_ipv4 *mask = item->mask;
2526 rte_be16_t fragment_offset_spec = 0;
2527 rte_be16_t fragment_offset_last = 0;
2528 struct rte_flow_item_ipv4 nic_ipv4_mask = {
2530 .src_addr = RTE_BE32(0xffffffff),
2531 .dst_addr = RTE_BE32(0xffffffff),
2532 .type_of_service = 0xff,
2533 .fragment_offset = RTE_BE16(0xffff),
2534 .next_proto_id = 0xff,
2535 .time_to_live = 0xff,
2539 if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
2540 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2541 bool ihl_cap = !tunnel ?
2542 attr->outer_ipv4_ihl : attr->inner_ipv4_ihl;
2544 return rte_flow_error_set(error, ENOTSUP,
2545 RTE_FLOW_ERROR_TYPE_ITEM,
2547 "IPV4 ihl offload not supported");
2548 nic_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
2550 ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2551 ether_type, &nic_ipv4_mask,
2552 MLX5_ITEM_RANGE_ACCEPTED, error);
2556 fragment_offset_spec = spec->hdr.fragment_offset &
2557 mask->hdr.fragment_offset;
2558 if (!fragment_offset_spec)
2561 * spec and mask are valid, enforce using full mask to make sure the
2562 * complete value is used correctly.
2564 if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2565 != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2566 return rte_flow_error_set(error, EINVAL,
2567 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2568 item, "must use full mask for"
2569 " fragment_offset");
2571 * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
2572 * indicating this is 1st fragment of fragmented packet.
2573 * This is not yet supported in MLX5, return appropriate error message.
2575 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
2576 return rte_flow_error_set(error, ENOTSUP,
2577 RTE_FLOW_ERROR_TYPE_ITEM, item,
2578 "match on first fragment not "
2580 if (fragment_offset_spec && !last)
2581 return rte_flow_error_set(error, ENOTSUP,
2582 RTE_FLOW_ERROR_TYPE_ITEM, item,
2583 "specified value not supported");
2584 /* spec and last are valid, validate the specified range. */
2585 fragment_offset_last = last->hdr.fragment_offset &
2586 mask->hdr.fragment_offset;
2588 * Match on fragment_offset spec 0x2001 and last 0x3fff
2589 * means MF is 1 and frag-offset is > 0.
2590 * This packet is fragment 2nd and onward, excluding last.
2591 * This is not yet supported in MLX5, return appropriate
2594 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
2595 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2596 return rte_flow_error_set(error, ENOTSUP,
2597 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2598 last, "match on following "
2599 "fragments not supported");
2601 * Match on fragment_offset spec 0x0001 and last 0x1fff
2602 * means MF is 0 and frag-offset is > 0.
2603 * This packet is last fragment of fragmented packet.
2604 * This is not yet supported in MLX5, return appropriate
2607 if (fragment_offset_spec == RTE_BE16(1) &&
2608 fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
2609 return rte_flow_error_set(error, ENOTSUP,
2610 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2611 last, "match on last "
2612 "fragment not supported");
2614 * Match on fragment_offset spec 0x0001 and last 0x3fff
2615 * means MF and/or frag-offset is not 0.
2616 * This is a fragmented packet.
2617 * Other range values are invalid and rejected.
2619 if (!(fragment_offset_spec == RTE_BE16(1) &&
2620 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
2621 return rte_flow_error_set(error, ENOTSUP,
2622 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2623 "specified range not supported");
2628 * Validate IPV6 fragment extension item.
2631 * Item specification.
2632 * @param[in] item_flags
2633 * Bit-fields that holds the items detected until now.
2635 * Pointer to error structure.
2638 * 0 on success, a negative errno value otherwise and rte_errno is set.
2641 flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
2642 uint64_t item_flags,
2643 struct rte_flow_error *error)
2645 const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
2646 const struct rte_flow_item_ipv6_frag_ext *last = item->last;
2647 const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
2648 rte_be16_t frag_data_spec = 0;
2649 rte_be16_t frag_data_last = 0;
2650 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2651 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2652 MLX5_FLOW_LAYER_OUTER_L4;
2654 struct rte_flow_item_ipv6_frag_ext nic_mask = {
2656 .next_header = 0xff,
2657 .frag_data = RTE_BE16(0xffff),
2661 if (item_flags & l4m)
2662 return rte_flow_error_set(error, EINVAL,
2663 RTE_FLOW_ERROR_TYPE_ITEM, item,
2664 "ipv6 fragment extension item cannot "
2666 if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
2667 (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
2668 return rte_flow_error_set(error, EINVAL,
2669 RTE_FLOW_ERROR_TYPE_ITEM, item,
2670 "ipv6 fragment extension item must "
2671 "follow ipv6 item");
2673 frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
2674 if (!frag_data_spec)
2677 * spec and mask are valid, enforce using full mask to make sure the
2678 * complete value is used correctly.
2680 if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
2681 RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2682 return rte_flow_error_set(error, EINVAL,
2683 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2684 item, "must use full mask for"
2687 * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2688 * This is 1st fragment of fragmented packet.
2690 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2691 return rte_flow_error_set(error, ENOTSUP,
2692 RTE_FLOW_ERROR_TYPE_ITEM, item,
2693 "match on first fragment not "
2695 if (frag_data_spec && !last)
2696 return rte_flow_error_set(error, EINVAL,
2697 RTE_FLOW_ERROR_TYPE_ITEM, item,
2698 "specified value not supported");
2699 ret = mlx5_flow_item_acceptable
2700 (item, (const uint8_t *)mask,
2701 (const uint8_t *)&nic_mask,
2702 sizeof(struct rte_flow_item_ipv6_frag_ext),
2703 MLX5_ITEM_RANGE_ACCEPTED, error);
2706 /* spec and last are valid, validate the specified range. */
2707 frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2709 * Match on frag_data spec 0x0009 and last 0xfff9
2710 * means M is 1 and frag-offset is > 0.
2711 * This packet is fragment 2nd and onward, excluding last.
2712 * This is not yet supported in MLX5, return appropriate
2715 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2716 RTE_IPV6_EHDR_MF_MASK) &&
2717 frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2718 return rte_flow_error_set(error, ENOTSUP,
2719 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2720 last, "match on following "
2721 "fragments not supported");
2723 * Match on frag_data spec 0x0008 and last 0xfff8
2724 * means M is 0 and frag-offset is > 0.
2725 * This packet is last fragment of fragmented packet.
2726 * This is not yet supported in MLX5, return appropriate
2729 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2730 frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2731 return rte_flow_error_set(error, ENOTSUP,
2732 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2733 last, "match on last "
2734 "fragment not supported");
2735 /* Other range values are invalid and rejected. */
2736 return rte_flow_error_set(error, EINVAL,
2737 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2738 "specified range not supported");
2742 * Validate ASO CT item.
2745 * Pointer to the rte_eth_dev structure.
2747 * Item specification.
2748 * @param[in] item_flags
2749 * Pointer to bit-fields that holds the items detected until now.
2751 * Pointer to error structure.
2754 * 0 on success, a negative errno value otherwise and rte_errno is set.
2757 flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
2758 const struct rte_flow_item *item,
2759 uint64_t *item_flags,
2760 struct rte_flow_error *error)
2762 const struct rte_flow_item_conntrack *spec = item->spec;
2763 const struct rte_flow_item_conntrack *mask = item->mask;
2767 if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
2768 return rte_flow_error_set(error, EINVAL,
2769 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2770 "Only one CT is supported");
2772 mask = &rte_flow_item_conntrack_mask;
2773 flags = spec->flags & mask->flags;
2774 if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
2775 ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
2776 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
2777 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
2778 return rte_flow_error_set(error, EINVAL,
2779 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2780 "Conflict status bits");
2781 /* State change also needs to be considered. */
2782 *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
2787 * Validate the pop VLAN action.
2790 * Pointer to the rte_eth_dev structure.
2791 * @param[in] action_flags
2792 * Holds the actions detected until now.
2794 * Pointer to the pop vlan action.
2795 * @param[in] item_flags
2796 * The items found in this flow rule.
2798 * Pointer to flow attributes.
2800 * Pointer to error structure.
2803 * 0 on success, a negative errno value otherwise and rte_errno is set.
2806 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
2807 uint64_t action_flags,
2808 const struct rte_flow_action *action,
2809 uint64_t item_flags,
2810 const struct rte_flow_attr *attr,
2811 struct rte_flow_error *error)
2813 const struct mlx5_priv *priv = dev->data->dev_private;
2814 struct mlx5_dev_ctx_shared *sh = priv->sh;
2815 bool direction_error = false;
2817 if (!priv->sh->pop_vlan_action)
2818 return rte_flow_error_set(error, ENOTSUP,
2819 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2821 "pop vlan action is not supported");
2822 /* Pop VLAN is not supported in egress except for CX6 FDB mode. */
2823 if (attr->transfer) {
2824 bool fdb_tx = priv->representor_id != UINT16_MAX;
2825 bool is_cx5 = sh->steering_format_version ==
2826 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
2828 if (fdb_tx && is_cx5)
2829 direction_error = true;
2830 } else if (attr->egress) {
2831 direction_error = true;
2833 if (direction_error)
2834 return rte_flow_error_set(error, ENOTSUP,
2835 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2837 "pop vlan action not supported for egress");
2838 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
2839 return rte_flow_error_set(error, ENOTSUP,
2840 RTE_FLOW_ERROR_TYPE_ACTION, action,
2841 "no support for multiple VLAN "
2843 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
2844 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
2845 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
2846 return rte_flow_error_set(error, ENOTSUP,
2847 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2849 "cannot pop vlan after decap without "
2850 "match on inner vlan in the flow");
2851 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
2852 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
2853 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2854 return rte_flow_error_set(error, ENOTSUP,
2855 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2857 "cannot pop vlan without a "
2858 "match on (outer) vlan in the flow");
2859 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2860 return rte_flow_error_set(error, EINVAL,
2861 RTE_FLOW_ERROR_TYPE_ACTION, action,
2862 "wrong action order, port_id should "
2863 "be after pop VLAN action");
2864 if (!attr->transfer && priv->representor)
2865 return rte_flow_error_set(error, ENOTSUP,
2866 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2867 "pop vlan action for VF representor "
2868 "not supported on NIC table");
2873 * Get VLAN default info from vlan match info.
2876 * the list of item specifications.
2878 * pointer VLAN info to fill to.
2881 * 0 on success, a negative errno value otherwise and rte_errno is set.
2884 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
2885 struct rte_vlan_hdr *vlan)
2887 const struct rte_flow_item_vlan nic_mask = {
2888 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
2889 MLX5DV_FLOW_VLAN_VID_MASK),
2890 .inner_type = RTE_BE16(0xffff),
2895 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2896 int type = items->type;
2898 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
2899 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
2902 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
2903 const struct rte_flow_item_vlan *vlan_m = items->mask;
2904 const struct rte_flow_item_vlan *vlan_v = items->spec;
2906 /* If VLAN item in pattern doesn't contain data, return here. */
2911 /* Only full match values are accepted */
2912 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
2913 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
2914 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
2916 rte_be_to_cpu_16(vlan_v->tci &
2917 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
2919 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
2920 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
2921 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
2923 rte_be_to_cpu_16(vlan_v->tci &
2924 MLX5DV_FLOW_VLAN_VID_MASK_BE);
2926 if (vlan_m->inner_type == nic_mask.inner_type)
2927 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
2928 vlan_m->inner_type);
2933 * Validate the push VLAN action.
2936 * Pointer to the rte_eth_dev structure.
2937 * @param[in] action_flags
2938 * Holds the actions detected until now.
2939 * @param[in] item_flags
2940 * The items found in this flow rule.
2942 * Pointer to the action structure.
2944 * Pointer to flow attributes
2946 * Pointer to error structure.
2949 * 0 on success, a negative errno value otherwise and rte_errno is set.
2952 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
2953 uint64_t action_flags,
2954 const struct rte_flow_item_vlan *vlan_m,
2955 const struct rte_flow_action *action,
2956 const struct rte_flow_attr *attr,
2957 struct rte_flow_error *error)
2959 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
2960 const struct mlx5_priv *priv = dev->data->dev_private;
2962 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
2963 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
2964 return rte_flow_error_set(error, EINVAL,
2965 RTE_FLOW_ERROR_TYPE_ACTION, action,
2966 "invalid vlan ethertype");
2967 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2968 return rte_flow_error_set(error, EINVAL,
2969 RTE_FLOW_ERROR_TYPE_ACTION, action,
2970 "wrong action order, port_id should "
2971 "be after push VLAN");
2972 if (!attr->transfer && priv->representor)
2973 return rte_flow_error_set(error, ENOTSUP,
2974 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2975 "push vlan action for VF representor "
2976 "not supported on NIC table");
2978 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
2979 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
2980 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
2981 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
2982 !(mlx5_flow_find_action
2983 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
2984 return rte_flow_error_set(error, EINVAL,
2985 RTE_FLOW_ERROR_TYPE_ACTION, action,
2986 "not full match mask on VLAN PCP and "
2987 "there is no of_set_vlan_pcp action, "
2988 "push VLAN action cannot figure out "
2991 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
2992 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
2993 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
2994 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
2995 !(mlx5_flow_find_action
2996 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
2997 return rte_flow_error_set(error, EINVAL,
2998 RTE_FLOW_ERROR_TYPE_ACTION, action,
2999 "not full match mask on VLAN VID and "
3000 "there is no of_set_vlan_vid action, "
3001 "push VLAN action cannot figure out "
3008 * Validate the set VLAN PCP.
3010 * @param[in] action_flags
3011 * Holds the actions detected until now.
3012 * @param[in] actions
3013 * Pointer to the list of actions remaining in the flow rule.
3015 * Pointer to error structure.
3018 * 0 on success, a negative errno value otherwise and rte_errno is set.
3021 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
3022 const struct rte_flow_action actions[],
3023 struct rte_flow_error *error)
3025 const struct rte_flow_action *action = actions;
3026 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
3028 if (conf->vlan_pcp > 7)
3029 return rte_flow_error_set(error, EINVAL,
3030 RTE_FLOW_ERROR_TYPE_ACTION, action,
3031 "VLAN PCP value is too big");
3032 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
3033 return rte_flow_error_set(error, ENOTSUP,
3034 RTE_FLOW_ERROR_TYPE_ACTION, action,
3035 "set VLAN PCP action must follow "
3036 "the push VLAN action");
3037 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
3038 return rte_flow_error_set(error, ENOTSUP,
3039 RTE_FLOW_ERROR_TYPE_ACTION, action,
3040 "Multiple VLAN PCP modification are "
3042 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3043 return rte_flow_error_set(error, EINVAL,
3044 RTE_FLOW_ERROR_TYPE_ACTION, action,
3045 "wrong action order, port_id should "
3046 "be after set VLAN PCP");
3051 * Validate the set VLAN VID.
3053 * @param[in] item_flags
3054 * Holds the items detected in this rule.
3055 * @param[in] action_flags
3056 * Holds the actions detected until now.
3057 * @param[in] actions
3058 * Pointer to the list of actions remaining in the flow rule.
3060 * Pointer to error structure.
3063 * 0 on success, a negative errno value otherwise and rte_errno is set.
3066 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3067 uint64_t action_flags,
3068 const struct rte_flow_action actions[],
3069 struct rte_flow_error *error)
3071 const struct rte_flow_action *action = actions;
3072 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3074 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3075 return rte_flow_error_set(error, EINVAL,
3076 RTE_FLOW_ERROR_TYPE_ACTION, action,
3077 "VLAN VID value is too big");
3078 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3079 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3080 return rte_flow_error_set(error, ENOTSUP,
3081 RTE_FLOW_ERROR_TYPE_ACTION, action,
3082 "set VLAN VID action must follow push"
3083 " VLAN action or match on VLAN item");
3084 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3085 return rte_flow_error_set(error, ENOTSUP,
3086 RTE_FLOW_ERROR_TYPE_ACTION, action,
3087 "Multiple VLAN VID modifications are "
3089 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3090 return rte_flow_error_set(error, EINVAL,
3091 RTE_FLOW_ERROR_TYPE_ACTION, action,
3092 "wrong action order, port_id should "
3093 "be after set VLAN VID");
3098 * Validate the FLAG action.
3101 * Pointer to the rte_eth_dev structure.
3102 * @param[in] action_flags
3103 * Holds the actions detected until now.
3105 * Pointer to flow attributes
3107 * Pointer to error structure.
3110 * 0 on success, a negative errno value otherwise and rte_errno is set.
3113 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3114 uint64_t action_flags,
3115 const struct rte_flow_attr *attr,
3116 struct rte_flow_error *error)
3118 struct mlx5_priv *priv = dev->data->dev_private;
3119 struct mlx5_sh_config *config = &priv->sh->config;
3122 /* Fall back if no extended metadata register support. */
3123 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3124 return mlx5_flow_validate_action_flag(action_flags, attr,
3126 /* Extensive metadata mode requires registers. */
3127 if (!mlx5_flow_ext_mreg_supported(dev))
3128 return rte_flow_error_set(error, ENOTSUP,
3129 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3130 "no metadata registers "
3131 "to support flag action");
3132 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3133 return rte_flow_error_set(error, ENOTSUP,
3134 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3135 "extended metadata register"
3136 " isn't available");
3137 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3140 MLX5_ASSERT(ret > 0);
3141 if (action_flags & MLX5_FLOW_ACTION_MARK)
3142 return rte_flow_error_set(error, EINVAL,
3143 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3144 "can't mark and flag in same flow");
3145 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3146 return rte_flow_error_set(error, EINVAL,
3147 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3149 " actions in same flow");
3154 * Validate MARK action.
3157 * Pointer to the rte_eth_dev structure.
3159 * Pointer to action.
3160 * @param[in] action_flags
3161 * Holds the actions detected until now.
3163 * Pointer to flow attributes
3165 * Pointer to error structure.
3168 * 0 on success, a negative errno value otherwise and rte_errno is set.
3171 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3172 const struct rte_flow_action *action,
3173 uint64_t action_flags,
3174 const struct rte_flow_attr *attr,
3175 struct rte_flow_error *error)
3177 struct mlx5_priv *priv = dev->data->dev_private;
3178 struct mlx5_sh_config *config = &priv->sh->config;
3179 const struct rte_flow_action_mark *mark = action->conf;
3182 if (is_tunnel_offload_active(dev))
3183 return rte_flow_error_set(error, ENOTSUP,
3184 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3186 "if tunnel offload active");
3187 /* Fall back if no extended metadata register support. */
3188 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3189 return mlx5_flow_validate_action_mark(action, action_flags,
3191 /* Extensive metadata mode requires registers. */
3192 if (!mlx5_flow_ext_mreg_supported(dev))
3193 return rte_flow_error_set(error, ENOTSUP,
3194 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3195 "no metadata registers "
3196 "to support mark action");
3197 if (!priv->sh->dv_mark_mask)
3198 return rte_flow_error_set(error, ENOTSUP,
3199 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3200 "extended metadata register"
3201 " isn't available");
3202 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3205 MLX5_ASSERT(ret > 0);
3207 return rte_flow_error_set(error, EINVAL,
3208 RTE_FLOW_ERROR_TYPE_ACTION, action,
3209 "configuration cannot be null");
3210 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3211 return rte_flow_error_set(error, EINVAL,
3212 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3214 "mark id exceeds the limit");
3215 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3216 return rte_flow_error_set(error, EINVAL,
3217 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3218 "can't flag and mark in same flow");
3219 if (action_flags & MLX5_FLOW_ACTION_MARK)
3220 return rte_flow_error_set(error, EINVAL,
3221 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3222 "can't have 2 mark actions in same"
3228 * Validate SET_META action.
3231 * Pointer to the rte_eth_dev structure.
3233 * Pointer to the action structure.
3234 * @param[in] action_flags
3235 * Holds the actions detected until now.
3237 * Pointer to flow attributes
3239 * Pointer to error structure.
3242 * 0 on success, a negative errno value otherwise and rte_errno is set.
3245 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3246 const struct rte_flow_action *action,
3247 uint64_t action_flags __rte_unused,
3248 const struct rte_flow_attr *attr,
3249 struct rte_flow_error *error)
3251 struct mlx5_priv *priv = dev->data->dev_private;
3252 struct mlx5_sh_config *config = &priv->sh->config;
3253 const struct rte_flow_action_set_meta *conf;
3254 uint32_t nic_mask = UINT32_MAX;
3257 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3258 !mlx5_flow_ext_mreg_supported(dev))
3259 return rte_flow_error_set(error, ENOTSUP,
3260 RTE_FLOW_ERROR_TYPE_ACTION, action,
3261 "extended metadata register"
3262 " isn't supported");
3263 reg = flow_dv_get_metadata_reg(dev, attr, error);
3267 return rte_flow_error_set(error, ENOTSUP,
3268 RTE_FLOW_ERROR_TYPE_ACTION, action,
3269 "unavailable extended metadata register");
3270 if (reg != REG_A && reg != REG_B) {
3271 struct mlx5_priv *priv = dev->data->dev_private;
3273 nic_mask = priv->sh->dv_meta_mask;
3275 if (!(action->conf))
3276 return rte_flow_error_set(error, EINVAL,
3277 RTE_FLOW_ERROR_TYPE_ACTION, action,
3278 "configuration cannot be null");
3279 conf = (const struct rte_flow_action_set_meta *)action->conf;
3281 return rte_flow_error_set(error, EINVAL,
3282 RTE_FLOW_ERROR_TYPE_ACTION, action,
3283 "zero mask doesn't have any effect");
3284 if (conf->mask & ~nic_mask)
3285 return rte_flow_error_set(error, EINVAL,
3286 RTE_FLOW_ERROR_TYPE_ACTION, action,
3287 "meta data must be within reg C0");
3292 * Validate SET_TAG action.
3295 * Pointer to the rte_eth_dev structure.
3297 * Pointer to the action structure.
3298 * @param[in] action_flags
3299 * Holds the actions detected until now.
3301 * Pointer to flow attributes
3303 * Pointer to error structure.
3306 * 0 on success, a negative errno value otherwise and rte_errno is set.
3309 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3310 const struct rte_flow_action *action,
3311 uint64_t action_flags,
3312 const struct rte_flow_attr *attr,
3313 struct rte_flow_error *error)
3315 const struct rte_flow_action_set_tag *conf;
3316 const uint64_t terminal_action_flags =
3317 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3318 MLX5_FLOW_ACTION_RSS;
3321 if (!mlx5_flow_ext_mreg_supported(dev))
3322 return rte_flow_error_set(error, ENOTSUP,
3323 RTE_FLOW_ERROR_TYPE_ACTION, action,
3324 "extensive metadata register"
3325 " isn't supported");
3326 if (!(action->conf))
3327 return rte_flow_error_set(error, EINVAL,
3328 RTE_FLOW_ERROR_TYPE_ACTION, action,
3329 "configuration cannot be null");
3330 conf = (const struct rte_flow_action_set_tag *)action->conf;
3332 return rte_flow_error_set(error, EINVAL,
3333 RTE_FLOW_ERROR_TYPE_ACTION, action,
3334 "zero mask doesn't have any effect");
3335 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3338 if (!attr->transfer && attr->ingress &&
3339 (action_flags & terminal_action_flags))
3340 return rte_flow_error_set(error, EINVAL,
3341 RTE_FLOW_ERROR_TYPE_ACTION, action,
3342 "set_tag has no effect"
3343 " with terminal actions");
3348 * Indicates whether ASO aging is supported.
3351 * Pointer to shared device context structure.
3353 * Attributes of flow that includes AGE action.
3356 * True when ASO aging is supported, false otherwise.
3359 flow_hit_aso_supported(const struct mlx5_dev_ctx_shared *sh,
3360 const struct rte_flow_attr *attr)
3362 MLX5_ASSERT(sh && attr);
3363 return (sh->flow_hit_aso_en && (attr->transfer || attr->group));
3367 * Validate count action.
3370 * Pointer to rte_eth_dev structure.
3372 * Indicator if action is shared.
3373 * @param[in] action_flags
3374 * Holds the actions detected until now.
3376 * Attributes of flow that includes this action.
3378 * Pointer to error structure.
3381 * 0 on success, a negative errno value otherwise and rte_errno is set.
3384 flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3385 uint64_t action_flags,
3386 const struct rte_flow_attr *attr,
3387 struct rte_flow_error *error)
3389 struct mlx5_priv *priv = dev->data->dev_private;
3391 if (!priv->sh->cdev->config.devx)
3393 if (action_flags & MLX5_FLOW_ACTION_COUNT)
3394 return rte_flow_error_set(error, EINVAL,
3395 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3396 "duplicate count actions set");
3397 if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
3398 !flow_hit_aso_supported(priv->sh, attr))
3399 return rte_flow_error_set(error, EINVAL,
3400 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3401 "old age and indirect count combination is not supported");
3402 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3406 return rte_flow_error_set
3408 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3410 "count action not supported");
3414 * Validate the L2 encap action.
3417 * Pointer to the rte_eth_dev structure.
3418 * @param[in] action_flags
3419 * Holds the actions detected until now.
3421 * Pointer to the action structure.
3423 * Pointer to flow attributes.
3425 * Pointer to error structure.
3428 * 0 on success, a negative errno value otherwise and rte_errno is set.
3431 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3432 uint64_t action_flags,
3433 const struct rte_flow_action *action,
3434 const struct rte_flow_attr *attr,
3435 struct rte_flow_error *error)
3437 const struct mlx5_priv *priv = dev->data->dev_private;
3439 if (!(action->conf))
3440 return rte_flow_error_set(error, EINVAL,
3441 RTE_FLOW_ERROR_TYPE_ACTION, action,
3442 "configuration cannot be null");
3443 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3444 return rte_flow_error_set(error, EINVAL,
3445 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3446 "can only have a single encap action "
3448 if (!attr->transfer && priv->representor)
3449 return rte_flow_error_set(error, ENOTSUP,
3450 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3451 "encap action for VF representor "
3452 "not supported on NIC table");
3457 * Validate a decap action.
3460 * Pointer to the rte_eth_dev structure.
3461 * @param[in] action_flags
3462 * Holds the actions detected until now.
3464 * Pointer to the action structure.
3465 * @param[in] item_flags
3466 * Holds the items detected.
3468 * Pointer to flow attributes
3470 * Pointer to error structure.
3473 * 0 on success, a negative errno value otherwise and rte_errno is set.
3476 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3477 uint64_t action_flags,
3478 const struct rte_flow_action *action,
3479 const uint64_t item_flags,
3480 const struct rte_flow_attr *attr,
3481 struct rte_flow_error *error)
3483 const struct mlx5_priv *priv = dev->data->dev_private;
3485 if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3486 !priv->sh->config.decap_en)
3487 return rte_flow_error_set(error, ENOTSUP,
3488 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3489 "decap is not enabled");
3490 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3491 return rte_flow_error_set(error, ENOTSUP,
3492 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3494 MLX5_FLOW_ACTION_DECAP ? "can only "
3495 "have a single decap action" : "decap "
3496 "after encap is not supported");
3497 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3498 return rte_flow_error_set(error, EINVAL,
3499 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3500 "can't have decap action after"
3503 return rte_flow_error_set(error, ENOTSUP,
3504 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3506 "decap action not supported for "
3508 if (!attr->transfer && priv->representor)
3509 return rte_flow_error_set(error, ENOTSUP,
3510 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3511 "decap action for VF representor "
3512 "not supported on NIC table");
3513 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3514 !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3515 return rte_flow_error_set(error, ENOTSUP,
3516 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3517 "VXLAN item should be present for VXLAN decap");
3521 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3524 * Validate the raw encap and decap actions.
3527 * Pointer to the rte_eth_dev structure.
3529 * Pointer to the decap action.
3531 * Pointer to the encap action.
3533 * Pointer to flow attributes
3534 * @param[in/out] action_flags
3535 * Holds the actions detected until now.
3536 * @param[out] actions_n
3537 * pointer to the number of actions counter.
3539 * Pointer to the action structure.
3540 * @param[in] item_flags
3541 * Holds the items detected.
3543 * Pointer to error structure.
3546 * 0 on success, a negative errno value otherwise and rte_errno is set.
3549 flow_dv_validate_action_raw_encap_decap
3550 (struct rte_eth_dev *dev,
3551 const struct rte_flow_action_raw_decap *decap,
3552 const struct rte_flow_action_raw_encap *encap,
3553 const struct rte_flow_attr *attr, uint64_t *action_flags,
3554 int *actions_n, const struct rte_flow_action *action,
3555 uint64_t item_flags, struct rte_flow_error *error)
3557 const struct mlx5_priv *priv = dev->data->dev_private;
3560 if (encap && (!encap->size || !encap->data))
3561 return rte_flow_error_set(error, EINVAL,
3562 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3563 "raw encap data cannot be empty");
3564 if (decap && encap) {
3565 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3566 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3569 else if (encap->size <=
3570 MLX5_ENCAPSULATION_DECISION_SIZE &&
3572 MLX5_ENCAPSULATION_DECISION_SIZE)
3575 else if (encap->size >
3576 MLX5_ENCAPSULATION_DECISION_SIZE &&
3578 MLX5_ENCAPSULATION_DECISION_SIZE)
3579 /* 2 L2 actions: encap and decap. */
3582 return rte_flow_error_set(error,
3584 RTE_FLOW_ERROR_TYPE_ACTION,
3585 NULL, "unsupported too small "
3586 "raw decap and too small raw "
3587 "encap combination");
3590 ret = flow_dv_validate_action_decap(dev, *action_flags, action,
3591 item_flags, attr, error);
3594 *action_flags |= MLX5_FLOW_ACTION_DECAP;
3598 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
3599 return rte_flow_error_set(error, ENOTSUP,
3600 RTE_FLOW_ERROR_TYPE_ACTION,
3602 "small raw encap size");
3603 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
3604 return rte_flow_error_set(error, EINVAL,
3605 RTE_FLOW_ERROR_TYPE_ACTION,
3607 "more than one encap action");
3608 if (!attr->transfer && priv->representor)
3609 return rte_flow_error_set
3611 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3612 "encap action for VF representor "
3613 "not supported on NIC table");
3614 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
3621 * Validate the ASO CT action.
3624 * Pointer to the rte_eth_dev structure.
3625 * @param[in] action_flags
3626 * Holds the actions detected until now.
3627 * @param[in] item_flags
3628 * The items found in this flow rule.
3630 * Pointer to flow attributes.
3632 * Pointer to error structure.
3635 * 0 on success, a negative errno value otherwise and rte_errno is set.
3638 flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
3639 uint64_t action_flags,
3640 uint64_t item_flags,
3641 const struct rte_flow_attr *attr,
3642 struct rte_flow_error *error)
3646 if (attr->group == 0 && !attr->transfer)
3647 return rte_flow_error_set(error, ENOTSUP,
3648 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3650 "Only support non-root table");
3651 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
3652 return rte_flow_error_set(error, ENOTSUP,
3653 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3654 "CT cannot follow a fate action");
3655 if ((action_flags & MLX5_FLOW_ACTION_METER) ||
3656 (action_flags & MLX5_FLOW_ACTION_AGE))
3657 return rte_flow_error_set(error, EINVAL,
3658 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3659 "Only one ASO action is supported");
3660 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3661 return rte_flow_error_set(error, EINVAL,
3662 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3663 "Encap cannot exist before CT");
3664 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3665 return rte_flow_error_set(error, EINVAL,
3666 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3667 "Not a outer TCP packet");
3672 flow_dv_encap_decap_match_cb(void *tool_ctx __rte_unused,
3673 struct mlx5_list_entry *entry, void *cb_ctx)
3675 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3676 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3677 struct mlx5_flow_dv_encap_decap_resource *resource;
3679 resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
3681 if (resource->reformat_type == ctx_resource->reformat_type &&
3682 resource->ft_type == ctx_resource->ft_type &&
3683 resource->flags == ctx_resource->flags &&
3684 resource->size == ctx_resource->size &&
3685 !memcmp((const void *)resource->buf,
3686 (const void *)ctx_resource->buf,
3692 struct mlx5_list_entry *
3693 flow_dv_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
3695 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3696 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3697 struct mlx5dv_dr_domain *domain;
3698 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3699 struct mlx5_flow_dv_encap_decap_resource *resource;
3703 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3704 domain = sh->fdb_domain;
3705 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3706 domain = sh->rx_domain;
3708 domain = sh->tx_domain;
3709 /* Register new encap/decap resource. */
3710 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
3712 rte_flow_error_set(ctx->error, ENOMEM,
3713 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3714 "cannot allocate resource memory");
3717 *resource = *ctx_resource;
3718 resource->idx = idx;
3719 ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
3723 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
3724 rte_flow_error_set(ctx->error, ENOMEM,
3725 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3726 NULL, "cannot create action");
3730 return &resource->entry;
3733 struct mlx5_list_entry *
3734 flow_dv_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
3737 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3738 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3739 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3742 cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
3744 if (!cache_resource) {
3745 rte_flow_error_set(ctx->error, ENOMEM,
3746 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3747 "cannot allocate resource memory");
3750 memcpy(cache_resource, oentry, sizeof(*cache_resource));
3751 cache_resource->idx = idx;
3752 return &cache_resource->entry;
3756 flow_dv_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3758 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3759 struct mlx5_flow_dv_encap_decap_resource *res =
3760 container_of(entry, typeof(*res), entry);
3762 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
3766 * Find existing encap/decap resource or create and register a new one.
3768 * @param[in, out] dev
3769 * Pointer to rte_eth_dev structure.
3770 * @param[in, out] resource
3771 * Pointer to encap/decap resource.
3772 * @parm[in, out] dev_flow
3773 * Pointer to the dev_flow.
3775 * pointer to error structure.
3778 * 0 on success otherwise -errno and errno is set.
3781 flow_dv_encap_decap_resource_register
3782 (struct rte_eth_dev *dev,
3783 struct mlx5_flow_dv_encap_decap_resource *resource,
3784 struct mlx5_flow *dev_flow,
3785 struct rte_flow_error *error)
3787 struct mlx5_priv *priv = dev->data->dev_private;
3788 struct mlx5_dev_ctx_shared *sh = priv->sh;
3789 struct mlx5_list_entry *entry;
3793 uint32_t refmt_type:8;
3795 * Header reformat actions can be shared between
3796 * non-root tables. One bit to indicate non-root
3800 uint32_t reserve:15;
3803 } encap_decap_key = {
3805 .ft_type = resource->ft_type,
3806 .refmt_type = resource->reformat_type,
3807 .is_root = !!dev_flow->dv.group,
3811 struct mlx5_flow_cb_ctx ctx = {
3815 struct mlx5_hlist *encaps_decaps;
3818 encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
3820 MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
3822 flow_dv_encap_decap_create_cb,
3823 flow_dv_encap_decap_match_cb,
3824 flow_dv_encap_decap_remove_cb,
3825 flow_dv_encap_decap_clone_cb,
3826 flow_dv_encap_decap_clone_free_cb,
3828 if (unlikely(!encaps_decaps))
3830 resource->flags = dev_flow->dv.group ? 0 : 1;
3831 key64 = __rte_raw_cksum(&encap_decap_key.v32,
3832 sizeof(encap_decap_key.v32), 0);
3833 if (resource->reformat_type !=
3834 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
3836 key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
3837 entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
3840 resource = container_of(entry, typeof(*resource), entry);
3841 dev_flow->dv.encap_decap = resource;
3842 dev_flow->handle->dvh.rix_encap_decap = resource->idx;
3847 * Find existing table jump resource or create and register a new one.
3849 * @param[in, out] dev
3850 * Pointer to rte_eth_dev structure.
3851 * @param[in, out] tbl
3852 * Pointer to flow table resource.
3853 * @parm[in, out] dev_flow
3854 * Pointer to the dev_flow.
3856 * pointer to error structure.
3859 * 0 on success otherwise -errno and errno is set.
3862 flow_dv_jump_tbl_resource_register
3863 (struct rte_eth_dev *dev __rte_unused,
3864 struct mlx5_flow_tbl_resource *tbl,
3865 struct mlx5_flow *dev_flow,
3866 struct rte_flow_error *error __rte_unused)
3868 struct mlx5_flow_tbl_data_entry *tbl_data =
3869 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
3872 MLX5_ASSERT(tbl_data->jump.action);
3873 dev_flow->handle->rix_jump = tbl_data->idx;
3874 dev_flow->dv.jump = &tbl_data->jump;
3879 flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
3880 struct mlx5_list_entry *entry, void *cb_ctx)
3882 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3883 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3884 struct mlx5_flow_dv_port_id_action_resource *res =
3885 container_of(entry, typeof(*res), entry);
3887 return ref->port_id != res->port_id;
3890 struct mlx5_list_entry *
3891 flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
3893 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3894 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3895 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3896 struct mlx5_flow_dv_port_id_action_resource *resource;
3900 /* Register new port id action resource. */
3901 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3903 rte_flow_error_set(ctx->error, ENOMEM,
3904 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3905 "cannot allocate port_id action memory");
3909 ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
3913 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
3914 rte_flow_error_set(ctx->error, ENOMEM,
3915 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3916 "cannot create action");
3919 resource->idx = idx;
3920 return &resource->entry;
3923 struct mlx5_list_entry *
3924 flow_dv_port_id_clone_cb(void *tool_ctx,
3925 struct mlx5_list_entry *entry __rte_unused,
3928 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3929 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3930 struct mlx5_flow_dv_port_id_action_resource *resource;
3933 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3935 rte_flow_error_set(ctx->error, ENOMEM,
3936 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3937 "cannot allocate port_id action memory");
3940 memcpy(resource, entry, sizeof(*resource));
3941 resource->idx = idx;
3942 return &resource->entry;
3946 flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3948 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3949 struct mlx5_flow_dv_port_id_action_resource *resource =
3950 container_of(entry, typeof(*resource), entry);
3952 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
3956 * Find existing table port ID resource or create and register a new one.
3958 * @param[in, out] dev
3959 * Pointer to rte_eth_dev structure.
3960 * @param[in, out] ref
3961 * Pointer to port ID action resource reference.
3962 * @parm[in, out] dev_flow
3963 * Pointer to the dev_flow.
3965 * pointer to error structure.
3968 * 0 on success otherwise -errno and errno is set.
3971 flow_dv_port_id_action_resource_register
3972 (struct rte_eth_dev *dev,
3973 struct mlx5_flow_dv_port_id_action_resource *ref,
3974 struct mlx5_flow *dev_flow,
3975 struct rte_flow_error *error)
3977 struct mlx5_priv *priv = dev->data->dev_private;
3978 struct mlx5_list_entry *entry;
3979 struct mlx5_flow_dv_port_id_action_resource *resource;
3980 struct mlx5_flow_cb_ctx ctx = {
3985 entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
3988 resource = container_of(entry, typeof(*resource), entry);
3989 dev_flow->dv.port_id_action = resource;
3990 dev_flow->handle->rix_port_id_action = resource->idx;
3995 flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
3996 struct mlx5_list_entry *entry, void *cb_ctx)
3998 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3999 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4000 struct mlx5_flow_dv_push_vlan_action_resource *res =
4001 container_of(entry, typeof(*res), entry);
4003 return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
4006 struct mlx5_list_entry *
4007 flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
4009 struct mlx5_dev_ctx_shared *sh = tool_ctx;
4010 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4011 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4012 struct mlx5_flow_dv_push_vlan_action_resource *resource;
4013 struct mlx5dv_dr_domain *domain;
4017 /* Register new port id action resource. */
4018 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4020 rte_flow_error_set(ctx->error, ENOMEM,
4021 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4022 "cannot allocate push_vlan action memory");
4026 if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4027 domain = sh->fdb_domain;
4028 else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4029 domain = sh->rx_domain;
4031 domain = sh->tx_domain;
4032 ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
4035 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
4036 rte_flow_error_set(ctx->error, ENOMEM,
4037 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4038 "cannot create push vlan action");
4041 resource->idx = idx;
4042 return &resource->entry;
4045 struct mlx5_list_entry *
4046 flow_dv_push_vlan_clone_cb(void *tool_ctx,
4047 struct mlx5_list_entry *entry __rte_unused,
4050 struct mlx5_dev_ctx_shared *sh = tool_ctx;
4051 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4052 struct mlx5_flow_dv_push_vlan_action_resource *resource;
4055 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4057 rte_flow_error_set(ctx->error, ENOMEM,
4058 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4059 "cannot allocate push_vlan action memory");
4062 memcpy(resource, entry, sizeof(*resource));
4063 resource->idx = idx;
4064 return &resource->entry;
4068 flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4070 struct mlx5_dev_ctx_shared *sh = tool_ctx;
4071 struct mlx5_flow_dv_push_vlan_action_resource *resource =
4072 container_of(entry, typeof(*resource), entry);
4074 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
4078 * Find existing push vlan resource or create and register a new one.
4080 * @param [in, out] dev
4081 * Pointer to rte_eth_dev structure.
4082 * @param[in, out] ref
4083 * Pointer to port ID action resource reference.
4084 * @parm[in, out] dev_flow
4085 * Pointer to the dev_flow.
4087 * pointer to error structure.
4090 * 0 on success otherwise -errno and errno is set.
4093 flow_dv_push_vlan_action_resource_register
4094 (struct rte_eth_dev *dev,
4095 struct mlx5_flow_dv_push_vlan_action_resource *ref,
4096 struct mlx5_flow *dev_flow,
4097 struct rte_flow_error *error)
4099 struct mlx5_priv *priv = dev->data->dev_private;
4100 struct mlx5_flow_dv_push_vlan_action_resource *resource;
4101 struct mlx5_list_entry *entry;
4102 struct mlx5_flow_cb_ctx ctx = {
4107 entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4110 resource = container_of(entry, typeof(*resource), entry);
4112 dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4113 dev_flow->dv.push_vlan_res = resource;
4118 * Get the size of specific rte_flow_item_type hdr size
4120 * @param[in] item_type
4121 * Tested rte_flow_item_type.
4124 * sizeof struct item_type, 0 if void or irrelevant.
4127 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4131 switch (item_type) {
4132 case RTE_FLOW_ITEM_TYPE_ETH:
4133 retval = sizeof(struct rte_ether_hdr);
4135 case RTE_FLOW_ITEM_TYPE_VLAN:
4136 retval = sizeof(struct rte_vlan_hdr);
4138 case RTE_FLOW_ITEM_TYPE_IPV4:
4139 retval = sizeof(struct rte_ipv4_hdr);
4141 case RTE_FLOW_ITEM_TYPE_IPV6:
4142 retval = sizeof(struct rte_ipv6_hdr);
4144 case RTE_FLOW_ITEM_TYPE_UDP:
4145 retval = sizeof(struct rte_udp_hdr);
4147 case RTE_FLOW_ITEM_TYPE_TCP:
4148 retval = sizeof(struct rte_tcp_hdr);
4150 case RTE_FLOW_ITEM_TYPE_VXLAN:
4151 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4152 retval = sizeof(struct rte_vxlan_hdr);
4154 case RTE_FLOW_ITEM_TYPE_GRE:
4155 case RTE_FLOW_ITEM_TYPE_NVGRE:
4156 retval = sizeof(struct rte_gre_hdr);
4158 case RTE_FLOW_ITEM_TYPE_MPLS:
4159 retval = sizeof(struct rte_mpls_hdr);
4161 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4169 #define MLX5_ENCAP_IPV4_VERSION 0x40
4170 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4171 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4172 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4173 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4174 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4175 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4178 * Convert the encap action data from list of rte_flow_item to raw buffer
4181 * Pointer to rte_flow_item objects list.
4183 * Pointer to the output buffer.
4185 * Pointer to the output buffer size.
4187 * Pointer to the error structure.
4190 * 0 on success, a negative errno value otherwise and rte_errno is set.
4193 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4194 size_t *size, struct rte_flow_error *error)
4196 struct rte_ether_hdr *eth = NULL;
4197 struct rte_vlan_hdr *vlan = NULL;
4198 struct rte_ipv4_hdr *ipv4 = NULL;
4199 struct rte_ipv6_hdr *ipv6 = NULL;
4200 struct rte_udp_hdr *udp = NULL;
4201 struct rte_vxlan_hdr *vxlan = NULL;
4202 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4203 struct rte_gre_hdr *gre = NULL;
4205 size_t temp_size = 0;
4208 return rte_flow_error_set(error, EINVAL,
4209 RTE_FLOW_ERROR_TYPE_ACTION,
4210 NULL, "invalid empty data");
4211 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4212 len = flow_dv_get_item_hdr_len(items->type);
4213 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4214 return rte_flow_error_set(error, EINVAL,
4215 RTE_FLOW_ERROR_TYPE_ACTION,
4216 (void *)items->type,
4217 "items total size is too big"
4218 " for encap action");
4219 rte_memcpy((void *)&buf[temp_size], items->spec, len);
4220 switch (items->type) {
4221 case RTE_FLOW_ITEM_TYPE_ETH:
4222 eth = (struct rte_ether_hdr *)&buf[temp_size];
4224 case RTE_FLOW_ITEM_TYPE_VLAN:
4225 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4227 return rte_flow_error_set(error, EINVAL,
4228 RTE_FLOW_ERROR_TYPE_ACTION,
4229 (void *)items->type,
4230 "eth header not found");
4231 if (!eth->ether_type)
4232 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4234 case RTE_FLOW_ITEM_TYPE_IPV4:
4235 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4237 return rte_flow_error_set(error, EINVAL,
4238 RTE_FLOW_ERROR_TYPE_ACTION,
4239 (void *)items->type,
4240 "neither eth nor vlan"
4242 if (vlan && !vlan->eth_proto)
4243 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4244 else if (eth && !eth->ether_type)
4245 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4246 if (!ipv4->version_ihl)
4247 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4248 MLX5_ENCAP_IPV4_IHL_MIN;
4249 if (!ipv4->time_to_live)
4250 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4252 case RTE_FLOW_ITEM_TYPE_IPV6:
4253 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4255 return rte_flow_error_set(error, EINVAL,
4256 RTE_FLOW_ERROR_TYPE_ACTION,
4257 (void *)items->type,
4258 "neither eth nor vlan"
4260 if (vlan && !vlan->eth_proto)
4261 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4262 else if (eth && !eth->ether_type)
4263 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4264 if (!ipv6->vtc_flow)
4266 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4267 if (!ipv6->hop_limits)
4268 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4270 case RTE_FLOW_ITEM_TYPE_UDP:
4271 udp = (struct rte_udp_hdr *)&buf[temp_size];
4273 return rte_flow_error_set(error, EINVAL,
4274 RTE_FLOW_ERROR_TYPE_ACTION,
4275 (void *)items->type,
4276 "ip header not found");
4277 if (ipv4 && !ipv4->next_proto_id)
4278 ipv4->next_proto_id = IPPROTO_UDP;
4279 else if (ipv6 && !ipv6->proto)
4280 ipv6->proto = IPPROTO_UDP;
4282 case RTE_FLOW_ITEM_TYPE_VXLAN:
4283 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4285 return rte_flow_error_set(error, EINVAL,
4286 RTE_FLOW_ERROR_TYPE_ACTION,
4287 (void *)items->type,
4288 "udp header not found");
4290 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4291 if (!vxlan->vx_flags)
4293 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4295 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4296 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4298 return rte_flow_error_set(error, EINVAL,
4299 RTE_FLOW_ERROR_TYPE_ACTION,
4300 (void *)items->type,
4301 "udp header not found");
4302 if (!vxlan_gpe->proto)
4303 return rte_flow_error_set(error, EINVAL,
4304 RTE_FLOW_ERROR_TYPE_ACTION,
4305 (void *)items->type,
4306 "next protocol not found");
4309 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4310 if (!vxlan_gpe->vx_flags)
4311 vxlan_gpe->vx_flags =
4312 MLX5_ENCAP_VXLAN_GPE_FLAGS;
4314 case RTE_FLOW_ITEM_TYPE_GRE:
4315 case RTE_FLOW_ITEM_TYPE_NVGRE:
4316 gre = (struct rte_gre_hdr *)&buf[temp_size];
4318 return rte_flow_error_set(error, EINVAL,
4319 RTE_FLOW_ERROR_TYPE_ACTION,
4320 (void *)items->type,
4321 "next protocol not found");
4323 return rte_flow_error_set(error, EINVAL,
4324 RTE_FLOW_ERROR_TYPE_ACTION,
4325 (void *)items->type,
4326 "ip header not found");
4327 if (ipv4 && !ipv4->next_proto_id)
4328 ipv4->next_proto_id = IPPROTO_GRE;
4329 else if (ipv6 && !ipv6->proto)
4330 ipv6->proto = IPPROTO_GRE;
4332 case RTE_FLOW_ITEM_TYPE_VOID:
4335 return rte_flow_error_set(error, EINVAL,
4336 RTE_FLOW_ERROR_TYPE_ACTION,
4337 (void *)items->type,
4338 "unsupported item type");
4348 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4350 struct rte_ether_hdr *eth = NULL;
4351 struct rte_vlan_hdr *vlan = NULL;
4352 struct rte_ipv6_hdr *ipv6 = NULL;
4353 struct rte_udp_hdr *udp = NULL;
4357 eth = (struct rte_ether_hdr *)data;
4358 next_hdr = (char *)(eth + 1);
4359 proto = RTE_BE16(eth->ether_type);
4362 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4363 vlan = (struct rte_vlan_hdr *)next_hdr;
4364 proto = RTE_BE16(vlan->eth_proto);
4365 next_hdr += sizeof(struct rte_vlan_hdr);
4368 /* HW calculates IPv4 csum. no need to proceed */
4369 if (proto == RTE_ETHER_TYPE_IPV4)
4372 /* non IPv4/IPv6 header. not supported */
4373 if (proto != RTE_ETHER_TYPE_IPV6) {
4374 return rte_flow_error_set(error, ENOTSUP,
4375 RTE_FLOW_ERROR_TYPE_ACTION,
4376 NULL, "Cannot offload non IPv4/IPv6");
4379 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4381 /* ignore non UDP */
4382 if (ipv6->proto != IPPROTO_UDP)
4385 udp = (struct rte_udp_hdr *)(ipv6 + 1);
4386 udp->dgram_cksum = 0;
4392 * Convert L2 encap action to DV specification.
4395 * Pointer to rte_eth_dev structure.
4397 * Pointer to action structure.
4398 * @param[in, out] dev_flow
4399 * Pointer to the mlx5_flow.
4400 * @param[in] transfer
4401 * Mark if the flow is E-Switch flow.
4403 * Pointer to the error structure.
4406 * 0 on success, a negative errno value otherwise and rte_errno is set.
4409 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4410 const struct rte_flow_action *action,
4411 struct mlx5_flow *dev_flow,
4413 struct rte_flow_error *error)
4415 const struct rte_flow_item *encap_data;
4416 const struct rte_flow_action_raw_encap *raw_encap_data;
4417 struct mlx5_flow_dv_encap_decap_resource res = {
4419 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4420 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4421 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4424 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4426 (const struct rte_flow_action_raw_encap *)action->conf;
4427 res.size = raw_encap_data->size;
4428 memcpy(res.buf, raw_encap_data->data, res.size);
4430 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4432 ((const struct rte_flow_action_vxlan_encap *)
4433 action->conf)->definition;
4436 ((const struct rte_flow_action_nvgre_encap *)
4437 action->conf)->definition;
4438 if (flow_dv_convert_encap_data(encap_data, res.buf,
4442 if (flow_dv_zero_encap_udp_csum(res.buf, error))
4444 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4445 return rte_flow_error_set(error, EINVAL,
4446 RTE_FLOW_ERROR_TYPE_ACTION,
4447 NULL, "can't create L2 encap action");
4452 * Convert L2 decap action to DV specification.
4455 * Pointer to rte_eth_dev structure.
4456 * @param[in, out] dev_flow
4457 * Pointer to the mlx5_flow.
4458 * @param[in] transfer
4459 * Mark if the flow is E-Switch flow.
4461 * Pointer to the error structure.
4464 * 0 on success, a negative errno value otherwise and rte_errno is set.
4467 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
4468 struct mlx5_flow *dev_flow,
4470 struct rte_flow_error *error)
4472 struct mlx5_flow_dv_encap_decap_resource res = {
4475 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
4476 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4477 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
4480 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4481 return rte_flow_error_set(error, EINVAL,
4482 RTE_FLOW_ERROR_TYPE_ACTION,
4483 NULL, "can't create L2 decap action");
4488 * Convert raw decap/encap (L3 tunnel) action to DV specification.
4491 * Pointer to rte_eth_dev structure.
4493 * Pointer to action structure.
4494 * @param[in, out] dev_flow
4495 * Pointer to the mlx5_flow.
4497 * Pointer to the flow attributes.
4499 * Pointer to the error structure.
4502 * 0 on success, a negative errno value otherwise and rte_errno is set.
4505 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
4506 const struct rte_flow_action *action,
4507 struct mlx5_flow *dev_flow,
4508 const struct rte_flow_attr *attr,
4509 struct rte_flow_error *error)
4511 const struct rte_flow_action_raw_encap *encap_data;
4512 struct mlx5_flow_dv_encap_decap_resource res;
4514 memset(&res, 0, sizeof(res));
4515 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
4516 res.size = encap_data->size;
4517 memcpy(res.buf, encap_data->data, res.size);
4518 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
4519 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
4520 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
4522 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4524 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4525 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4526 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4527 return rte_flow_error_set(error, EINVAL,
4528 RTE_FLOW_ERROR_TYPE_ACTION,
4529 NULL, "can't create encap action");
4534 * Create action push VLAN.
4537 * Pointer to rte_eth_dev structure.
4539 * Pointer to the flow attributes.
4541 * Pointer to the vlan to push to the Ethernet header.
4542 * @param[in, out] dev_flow
4543 * Pointer to the mlx5_flow.
4545 * Pointer to the error structure.
4548 * 0 on success, a negative errno value otherwise and rte_errno is set.
4551 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
4552 const struct rte_flow_attr *attr,
4553 const struct rte_vlan_hdr *vlan,
4554 struct mlx5_flow *dev_flow,
4555 struct rte_flow_error *error)
4557 struct mlx5_flow_dv_push_vlan_action_resource res;
4559 memset(&res, 0, sizeof(res));
4561 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
4564 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4566 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4567 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4568 return flow_dv_push_vlan_action_resource_register
4569 (dev, &res, dev_flow, error);
4573 * Validate the modify-header actions.
4575 * @param[in] action_flags
4576 * Holds the actions detected until now.
4578 * Pointer to the modify action.
4580 * Pointer to error structure.
4583 * 0 on success, a negative errno value otherwise and rte_errno is set.
4586 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
4587 const struct rte_flow_action *action,
4588 struct rte_flow_error *error)
4590 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
4591 return rte_flow_error_set(error, EINVAL,
4592 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4593 NULL, "action configuration not set");
4594 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4595 return rte_flow_error_set(error, EINVAL,
4596 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4597 "can't have encap action before"
4603 * Validate the modify-header MAC address actions.
4605 * @param[in] action_flags
4606 * Holds the actions detected until now.
4608 * Pointer to the modify action.
4609 * @param[in] item_flags
4610 * Holds the items detected.
4612 * Pointer to error structure.
4615 * 0 on success, a negative errno value otherwise and rte_errno is set.
4618 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
4619 const struct rte_flow_action *action,
4620 const uint64_t item_flags,
4621 struct rte_flow_error *error)
4625 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4627 if (!(item_flags & MLX5_FLOW_LAYER_L2))
4628 return rte_flow_error_set(error, EINVAL,
4629 RTE_FLOW_ERROR_TYPE_ACTION,
4631 "no L2 item in pattern");
4637 * Validate the modify-header IPv4 address actions.
4639 * @param[in] action_flags
4640 * Holds the actions detected until now.
4642 * Pointer to the modify action.
4643 * @param[in] item_flags
4644 * Holds the items detected.
4646 * Pointer to error structure.
4649 * 0 on success, a negative errno value otherwise and rte_errno is set.
4652 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
4653 const struct rte_flow_action *action,
4654 const uint64_t item_flags,
4655 struct rte_flow_error *error)
4660 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4662 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4663 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4664 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4665 if (!(item_flags & layer))
4666 return rte_flow_error_set(error, EINVAL,
4667 RTE_FLOW_ERROR_TYPE_ACTION,
4669 "no ipv4 item in pattern");
4675 * Validate the modify-header IPv6 address actions.
4677 * @param[in] action_flags
4678 * Holds the actions detected until now.
4680 * Pointer to the modify action.
4681 * @param[in] item_flags
4682 * Holds the items detected.
4684 * Pointer to error structure.
4687 * 0 on success, a negative errno value otherwise and rte_errno is set.
4690 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
4691 const struct rte_flow_action *action,
4692 const uint64_t item_flags,
4693 struct rte_flow_error *error)
4698 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4700 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4701 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4702 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4703 if (!(item_flags & layer))
4704 return rte_flow_error_set(error, EINVAL,
4705 RTE_FLOW_ERROR_TYPE_ACTION,
4707 "no ipv6 item in pattern");
4713 * Validate the modify-header TP actions.
4715 * @param[in] action_flags
4716 * Holds the actions detected until now.
4718 * Pointer to the modify action.
4719 * @param[in] item_flags
4720 * Holds the items detected.
4722 * Pointer to error structure.
4725 * 0 on success, a negative errno value otherwise and rte_errno is set.
4728 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
4729 const struct rte_flow_action *action,
4730 const uint64_t item_flags,
4731 struct rte_flow_error *error)
4736 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4738 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4739 MLX5_FLOW_LAYER_INNER_L4 :
4740 MLX5_FLOW_LAYER_OUTER_L4;
4741 if (!(item_flags & layer))
4742 return rte_flow_error_set(error, EINVAL,
4743 RTE_FLOW_ERROR_TYPE_ACTION,
4744 NULL, "no transport layer "
4751 * Validate the modify-header actions of increment/decrement
4752 * TCP Sequence-number.
4754 * @param[in] action_flags
4755 * Holds the actions detected until now.
4757 * Pointer to the modify action.
4758 * @param[in] item_flags
4759 * Holds the items detected.
4761 * Pointer to error structure.
4764 * 0 on success, a negative errno value otherwise and rte_errno is set.
4767 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
4768 const struct rte_flow_action *action,
4769 const uint64_t item_flags,
4770 struct rte_flow_error *error)
4775 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4777 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4778 MLX5_FLOW_LAYER_INNER_L4_TCP :
4779 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4780 if (!(item_flags & layer))
4781 return rte_flow_error_set(error, EINVAL,
4782 RTE_FLOW_ERROR_TYPE_ACTION,
4783 NULL, "no TCP item in"
4785 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
4786 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
4787 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
4788 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
4789 return rte_flow_error_set(error, EINVAL,
4790 RTE_FLOW_ERROR_TYPE_ACTION,
4792 "cannot decrease and increase"
4793 " TCP sequence number"
4794 " at the same time");
4800 * Validate the modify-header actions of increment/decrement
4801 * TCP Acknowledgment number.
4803 * @param[in] action_flags
4804 * Holds the actions detected until now.
4806 * Pointer to the modify action.
4807 * @param[in] item_flags
4808 * Holds the items detected.
4810 * Pointer to error structure.
4813 * 0 on success, a negative errno value otherwise and rte_errno is set.
4816 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
4817 const struct rte_flow_action *action,
4818 const uint64_t item_flags,
4819 struct rte_flow_error *error)
4824 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4826 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4827 MLX5_FLOW_LAYER_INNER_L4_TCP :
4828 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4829 if (!(item_flags & layer))
4830 return rte_flow_error_set(error, EINVAL,
4831 RTE_FLOW_ERROR_TYPE_ACTION,
4832 NULL, "no TCP item in"
4834 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
4835 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
4836 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
4837 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
4838 return rte_flow_error_set(error, EINVAL,
4839 RTE_FLOW_ERROR_TYPE_ACTION,
4841 "cannot decrease and increase"
4842 " TCP acknowledgment number"
4843 " at the same time");
4849 * Validate the modify-header TTL actions.
4851 * @param[in] action_flags
4852 * Holds the actions detected until now.
4854 * Pointer to the modify action.
4855 * @param[in] item_flags
4856 * Holds the items detected.
4858 * Pointer to error structure.
4861 * 0 on success, a negative errno value otherwise and rte_errno is set.
4864 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
4865 const struct rte_flow_action *action,
4866 const uint64_t item_flags,
4867 struct rte_flow_error *error)
4872 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4874 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4875 MLX5_FLOW_LAYER_INNER_L3 :
4876 MLX5_FLOW_LAYER_OUTER_L3;
4877 if (!(item_flags & layer))
4878 return rte_flow_error_set(error, EINVAL,
4879 RTE_FLOW_ERROR_TYPE_ACTION,
4881 "no IP protocol in pattern");
4887 * Validate the generic modify field actions.
4889 * Pointer to the rte_eth_dev structure.
4890 * @param[in] action_flags
4891 * Holds the actions detected until now.
4893 * Pointer to the modify action.
4895 * Pointer to the flow attributes.
4897 * Pointer to error structure.
4900 * Number of header fields to modify (0 or more) on success,
4901 * a negative errno value otherwise and rte_errno is set.
4904 flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
4905 const uint64_t action_flags,
4906 const struct rte_flow_action *action,
4907 const struct rte_flow_attr *attr,
4908 struct rte_flow_error *error)
4911 struct mlx5_priv *priv = dev->data->dev_private;
4912 struct mlx5_sh_config *config = &priv->sh->config;
4913 struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
4914 const struct rte_flow_action_modify_field *action_modify_field =
4916 uint32_t dst_width = mlx5_flow_item_field_width(dev,
4917 action_modify_field->dst.field,
4919 uint32_t src_width = mlx5_flow_item_field_width(dev,
4920 action_modify_field->src.field,
4921 dst_width, attr, error);
4923 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4927 if (action_modify_field->width == 0)
4928 return rte_flow_error_set(error, EINVAL,
4929 RTE_FLOW_ERROR_TYPE_ACTION, action,
4930 "no bits are requested to be modified");
4931 else if (action_modify_field->width > dst_width ||
4932 action_modify_field->width > src_width)
4933 return rte_flow_error_set(error, EINVAL,
4934 RTE_FLOW_ERROR_TYPE_ACTION, action,
4935 "cannot modify more bits than"
4936 " the width of a field");
4937 if (action_modify_field->dst.field != RTE_FLOW_FIELD_VALUE &&
4938 action_modify_field->dst.field != RTE_FLOW_FIELD_POINTER) {
4939 if ((action_modify_field->dst.offset +
4940 action_modify_field->width > dst_width) ||
4941 (action_modify_field->dst.offset % 32))
4942 return rte_flow_error_set(error, EINVAL,
4943 RTE_FLOW_ERROR_TYPE_ACTION, action,
4944 "destination offset is too big"
4945 " or not aligned to 4 bytes");
4946 if (action_modify_field->dst.level &&
4947 action_modify_field->dst.field != RTE_FLOW_FIELD_TAG)
4948 return rte_flow_error_set(error, ENOTSUP,
4949 RTE_FLOW_ERROR_TYPE_ACTION, action,
4950 "inner header fields modification"
4951 " is not supported");
4953 if (action_modify_field->src.field != RTE_FLOW_FIELD_VALUE &&
4954 action_modify_field->src.field != RTE_FLOW_FIELD_POINTER) {
4955 if (!attr->transfer && !attr->group)
4956 return rte_flow_error_set(error, ENOTSUP,
4957 RTE_FLOW_ERROR_TYPE_ACTION, action,
4958 "modify field action is not"
4959 " supported for group 0");
4960 if ((action_modify_field->src.offset +
4961 action_modify_field->width > src_width) ||
4962 (action_modify_field->src.offset % 32))
4963 return rte_flow_error_set(error, EINVAL,
4964 RTE_FLOW_ERROR_TYPE_ACTION, action,
4965 "source offset is too big"
4966 " or not aligned to 4 bytes");
4967 if (action_modify_field->src.level &&
4968 action_modify_field->src.field != RTE_FLOW_FIELD_TAG)
4969 return rte_flow_error_set(error, ENOTSUP,
4970 RTE_FLOW_ERROR_TYPE_ACTION, action,
4971 "inner header fields modification"
4972 " is not supported");
4974 if ((action_modify_field->dst.field ==
4975 action_modify_field->src.field) &&
4976 (action_modify_field->dst.level ==
4977 action_modify_field->src.level))
4978 return rte_flow_error_set(error, EINVAL,
4979 RTE_FLOW_ERROR_TYPE_ACTION, action,
4980 "source and destination fields"
4981 " cannot be the same");
4982 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VALUE ||
4983 action_modify_field->dst.field == RTE_FLOW_FIELD_POINTER ||
4984 action_modify_field->dst.field == RTE_FLOW_FIELD_MARK)
4985 return rte_flow_error_set(error, EINVAL,
4986 RTE_FLOW_ERROR_TYPE_ACTION, action,
4987 "mark, immediate value or a pointer to it"
4988 " cannot be used as a destination");
4989 if (action_modify_field->dst.field == RTE_FLOW_FIELD_START ||
4990 action_modify_field->src.field == RTE_FLOW_FIELD_START)
4991 return rte_flow_error_set(error, ENOTSUP,
4992 RTE_FLOW_ERROR_TYPE_ACTION, action,
4993 "modifications of an arbitrary"
4994 " place in a packet is not supported");
4995 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VLAN_TYPE ||
4996 action_modify_field->src.field == RTE_FLOW_FIELD_VLAN_TYPE)
4997 return rte_flow_error_set(error, ENOTSUP,
4998 RTE_FLOW_ERROR_TYPE_ACTION, action,
4999 "modifications of the 802.1Q Tag"
5000 " Identifier is not supported");
5001 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VXLAN_VNI ||
5002 action_modify_field->src.field == RTE_FLOW_FIELD_VXLAN_VNI)
5003 return rte_flow_error_set(error, ENOTSUP,
5004 RTE_FLOW_ERROR_TYPE_ACTION, action,
5005 "modifications of the VXLAN Network"
5006 " Identifier is not supported");
5007 if (action_modify_field->dst.field == RTE_FLOW_FIELD_GENEVE_VNI ||
5008 action_modify_field->src.field == RTE_FLOW_FIELD_GENEVE_VNI)
5009 return rte_flow_error_set(error, ENOTSUP,
5010 RTE_FLOW_ERROR_TYPE_ACTION, action,
5011 "modifications of the GENEVE Network"
5012 " Identifier is not supported");
5013 if (action_modify_field->dst.field == RTE_FLOW_FIELD_MARK ||
5014 action_modify_field->src.field == RTE_FLOW_FIELD_MARK)
5015 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5016 !mlx5_flow_ext_mreg_supported(dev))
5017 return rte_flow_error_set(error, ENOTSUP,
5018 RTE_FLOW_ERROR_TYPE_ACTION, action,
5019 "cannot modify mark in legacy mode"
5020 " or without extensive registers");
5021 if (action_modify_field->dst.field == RTE_FLOW_FIELD_META ||
5022 action_modify_field->src.field == RTE_FLOW_FIELD_META) {
5023 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5024 !mlx5_flow_ext_mreg_supported(dev))
5025 return rte_flow_error_set(error, ENOTSUP,
5026 RTE_FLOW_ERROR_TYPE_ACTION, action,
5027 "cannot modify meta without"
5028 " extensive registers support");
5029 ret = flow_dv_get_metadata_reg(dev, attr, error);
5030 if (ret < 0 || ret == REG_NON)
5031 return rte_flow_error_set(error, ENOTSUP,
5032 RTE_FLOW_ERROR_TYPE_ACTION, action,
5033 "cannot modify meta without"
5034 " extensive registers available");
5036 if (action_modify_field->operation != RTE_FLOW_MODIFY_SET)
5037 return rte_flow_error_set(error, ENOTSUP,
5038 RTE_FLOW_ERROR_TYPE_ACTION, action,
5039 "add and sub operations"
5040 " are not supported");
5041 if (action_modify_field->dst.field == RTE_FLOW_FIELD_IPV4_ECN ||
5042 action_modify_field->src.field == RTE_FLOW_FIELD_IPV4_ECN ||
5043 action_modify_field->dst.field == RTE_FLOW_FIELD_IPV6_ECN ||
5044 action_modify_field->src.field == RTE_FLOW_FIELD_IPV6_ECN)
5045 if (!hca_attr->modify_outer_ip_ecn &&
5046 !attr->transfer && !attr->group)
5047 return rte_flow_error_set(error, ENOTSUP,
5048 RTE_FLOW_ERROR_TYPE_ACTION, action,
5049 "modifications of the ECN for current firmware is not supported");
5050 return (action_modify_field->width / 32) +
5051 !!(action_modify_field->width % 32);
5055 * Validate jump action.
5058 * Pointer to the jump action.
5059 * @param[in] action_flags
5060 * Holds the actions detected until now.
5061 * @param[in] attributes
5062 * Pointer to flow attributes
5063 * @param[in] external
5064 * Action belongs to flow rule created by request external to PMD.
5066 * Pointer to error structure.
5069 * 0 on success, a negative errno value otherwise and rte_errno is set.
5072 flow_dv_validate_action_jump(struct rte_eth_dev *dev,
5073 const struct mlx5_flow_tunnel *tunnel,
5074 const struct rte_flow_action *action,
5075 uint64_t action_flags,
5076 const struct rte_flow_attr *attributes,
5077 bool external, struct rte_flow_error *error)
5079 uint32_t target_group, table = 0;
5081 struct flow_grp_info grp_info = {
5082 .external = !!external,
5083 .transfer = !!attributes->transfer,
5087 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5088 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5089 return rte_flow_error_set(error, EINVAL,
5090 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5091 "can't have 2 fate actions in"
5094 return rte_flow_error_set(error, EINVAL,
5095 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5096 NULL, "action configuration not set");
5098 ((const struct rte_flow_action_jump *)action->conf)->group;
5099 ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5103 if (attributes->group == target_group &&
5104 !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
5105 MLX5_FLOW_ACTION_TUNNEL_MATCH)))
5106 return rte_flow_error_set(error, EINVAL,
5107 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5108 "target group must be other than"
5109 " the current flow group");
5111 return rte_flow_error_set(error, EINVAL,
5112 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5113 NULL, "root table shouldn't be destination");
5118 * Validate action PORT_ID / REPRESENTED_PORT.
5121 * Pointer to rte_eth_dev structure.
5122 * @param[in] action_flags
5123 * Bit-fields that holds the actions detected until now.
5125 * PORT_ID / REPRESENTED_PORT action structure.
5127 * Attributes of flow that includes this action.
5129 * Pointer to error structure.
5132 * 0 on success, a negative errno value otherwise and rte_errno is set.
5135 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5136 uint64_t action_flags,
5137 const struct rte_flow_action *action,
5138 const struct rte_flow_attr *attr,
5139 struct rte_flow_error *error)
5141 const struct rte_flow_action_port_id *port_id;
5142 const struct rte_flow_action_ethdev *ethdev;
5143 struct mlx5_priv *act_priv;
5144 struct mlx5_priv *dev_priv;
5147 if (!attr->transfer)
5148 return rte_flow_error_set(error, ENOTSUP,
5149 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5151 "port action is valid in transfer"
5153 if (!action || !action->conf)
5154 return rte_flow_error_set(error, ENOTSUP,
5155 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5157 "port action parameters must be"
5159 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5160 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5161 return rte_flow_error_set(error, EINVAL,
5162 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5163 "can have only one fate actions in"
5165 dev_priv = mlx5_dev_to_eswitch_info(dev);
5167 return rte_flow_error_set(error, rte_errno,
5168 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5170 "failed to obtain E-Switch info");
5171 switch (action->type) {
5172 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5173 port_id = action->conf;
5174 port = port_id->original ? dev->data->port_id : port_id->id;
5176 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5177 ethdev = action->conf;
5178 port = ethdev->port_id;
5182 return rte_flow_error_set
5184 RTE_FLOW_ERROR_TYPE_ACTION, action,
5185 "unknown E-Switch action");
5187 act_priv = mlx5_port_to_eswitch_info(port, false);
5189 return rte_flow_error_set
5191 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5192 "failed to obtain E-Switch port id for port");
5193 if (act_priv->domain_id != dev_priv->domain_id)
5194 return rte_flow_error_set
5196 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5197 "port does not belong to"
5198 " E-Switch being configured");
5203 * Get the maximum number of modify header actions.
5206 * Pointer to rte_eth_dev structure.
5208 * Whether action is on root table.
5211 * Max number of modify header actions device can support.
5213 static inline unsigned int
5214 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5218 * There's no way to directly query the max capacity from FW.
5219 * The maximal value on root table should be assumed to be supported.
5222 return MLX5_MAX_MODIFY_NUM;
5224 return MLX5_ROOT_TBL_MODIFY_NUM;
5228 * Validate the meter action.
5231 * Pointer to rte_eth_dev structure.
5232 * @param[in] action_flags
5233 * Bit-fields that holds the actions detected until now.
5234 * @param[in] item_flags
5235 * Holds the items detected.
5237 * Pointer to the meter action.
5239 * Attributes of flow that includes this action.
5240 * @param[in] port_id_item
5241 * Pointer to item indicating port id.
5243 * Pointer to error structure.
5246 * 0 on success, a negative errno value otherwise and rte_errno is set.
5249 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5250 uint64_t action_flags, uint64_t item_flags,
5251 const struct rte_flow_action *action,
5252 const struct rte_flow_attr *attr,
5253 const struct rte_flow_item *port_id_item,
5255 struct rte_flow_error *error)
5257 struct mlx5_priv *priv = dev->data->dev_private;
5258 const struct rte_flow_action_meter *am = action->conf;
5259 struct mlx5_flow_meter_info *fm;
5260 struct mlx5_flow_meter_policy *mtr_policy;
5261 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5264 return rte_flow_error_set(error, EINVAL,
5265 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5266 "meter action conf is NULL");
5268 if (action_flags & MLX5_FLOW_ACTION_METER)
5269 return rte_flow_error_set(error, ENOTSUP,
5270 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5271 "meter chaining not support");
5272 if (action_flags & MLX5_FLOW_ACTION_JUMP)
5273 return rte_flow_error_set(error, ENOTSUP,
5274 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5275 "meter with jump not support");
5277 return rte_flow_error_set(error, ENOTSUP,
5278 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5280 "meter action not supported");
5281 fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5283 return rte_flow_error_set(error, EINVAL,
5284 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5286 /* aso meter can always be shared by different domains */
5287 if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5288 !(fm->transfer == attr->transfer ||
5289 (!fm->ingress && !attr->ingress && attr->egress) ||
5290 (!fm->egress && !attr->egress && attr->ingress)))
5291 return rte_flow_error_set(error, EINVAL,
5292 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5293 "Flow attributes domain are either invalid "
5294 "or have a domain conflict with current "
5295 "meter attributes");
5296 if (fm->def_policy) {
5297 if (!((attr->transfer &&
5298 mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
5300 mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
5302 mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
5303 return rte_flow_error_set(error, EINVAL,
5304 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5305 "Flow attributes domain "
5306 "have a conflict with current "
5307 "meter domain attributes");
5310 mtr_policy = mlx5_flow_meter_policy_find(dev,
5311 fm->policy_id, NULL);
5313 return rte_flow_error_set(error, EINVAL,
5314 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5315 "Invalid policy id for meter ");
5316 if (!((attr->transfer && mtr_policy->transfer) ||
5317 (attr->egress && mtr_policy->egress) ||
5318 (attr->ingress && mtr_policy->ingress)))
5319 return rte_flow_error_set(error, EINVAL,
5320 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5321 "Flow attributes domain "
5322 "have a conflict with current "
5323 "meter domain attributes");
5324 if (attr->transfer && mtr_policy->dev) {
5326 * When policy has fate action of port_id,
5327 * the flow should have the same src port as policy.
5329 struct mlx5_priv *policy_port_priv =
5330 mtr_policy->dev->data->dev_private;
5331 int32_t flow_src_port = priv->representor_id;
5334 const struct rte_flow_item_port_id *spec =
5336 struct mlx5_priv *port_priv =
5337 mlx5_port_to_eswitch_info(spec->id,
5340 return rte_flow_error_set(error,
5342 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5344 "Failed to get port info.");
5345 flow_src_port = port_priv->representor_id;
5347 if (flow_src_port != policy_port_priv->representor_id)
5348 return rte_flow_error_set(error,
5350 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5352 "Flow and meter policy "
5353 "have different src port.");
5354 } else if (mtr_policy->is_rss) {
5355 struct mlx5_flow_meter_policy *fp;
5356 struct mlx5_meter_policy_action_container *acg;
5357 struct mlx5_meter_policy_action_container *acy;
5358 const struct rte_flow_action *rss_act;
5361 fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
5364 return rte_flow_error_set(error, EINVAL,
5365 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5366 "Unable to get the final "
5367 "policy in the hierarchy");
5368 acg = &fp->act_cnt[RTE_COLOR_GREEN];
5369 acy = &fp->act_cnt[RTE_COLOR_YELLOW];
5370 MLX5_ASSERT(acg->fate_action ==
5371 MLX5_FLOW_FATE_SHARED_RSS ||
5373 MLX5_FLOW_FATE_SHARED_RSS);
5374 if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
5378 ret = mlx5_flow_validate_action_rss(rss_act,
5379 action_flags, dev, attr,
5384 *def_policy = false;
5390 * Validate the age action.
5392 * @param[in] action_flags
5393 * Holds the actions detected until now.
5395 * Pointer to the age action.
5397 * Pointer to the Ethernet device structure.
5399 * Pointer to error structure.
5402 * 0 on success, a negative errno value otherwise and rte_errno is set.
5405 flow_dv_validate_action_age(uint64_t action_flags,
5406 const struct rte_flow_action *action,
5407 struct rte_eth_dev *dev,
5408 struct rte_flow_error *error)
5410 struct mlx5_priv *priv = dev->data->dev_private;
5411 const struct rte_flow_action_age *age = action->conf;
5413 if (!priv->sh->cdev->config.devx ||
5414 (priv->sh->cmng.counter_fallback && !priv->sh->aso_age_mng))
5415 return rte_flow_error_set(error, ENOTSUP,
5416 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5418 "age action not supported");
5419 if (!(action->conf))
5420 return rte_flow_error_set(error, EINVAL,
5421 RTE_FLOW_ERROR_TYPE_ACTION, action,
5422 "configuration cannot be null");
5423 if (!(age->timeout))
5424 return rte_flow_error_set(error, EINVAL,
5425 RTE_FLOW_ERROR_TYPE_ACTION, action,
5426 "invalid timeout value 0");
5427 if (action_flags & MLX5_FLOW_ACTION_AGE)
5428 return rte_flow_error_set(error, EINVAL,
5429 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5430 "duplicate age actions set");
5435 * Validate the modify-header IPv4 DSCP actions.
5437 * @param[in] action_flags
5438 * Holds the actions detected until now.
5440 * Pointer to the modify action.
5441 * @param[in] item_flags
5442 * Holds the items detected.
5444 * Pointer to error structure.
5447 * 0 on success, a negative errno value otherwise and rte_errno is set.
5450 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
5451 const struct rte_flow_action *action,
5452 const uint64_t item_flags,
5453 struct rte_flow_error *error)
5457 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5459 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
5460 return rte_flow_error_set(error, EINVAL,
5461 RTE_FLOW_ERROR_TYPE_ACTION,
5463 "no ipv4 item in pattern");
5469 * Validate the modify-header IPv6 DSCP actions.
5471 * @param[in] action_flags
5472 * Holds the actions detected until now.
5474 * Pointer to the modify action.
5475 * @param[in] item_flags
5476 * Holds the items detected.
5478 * Pointer to error structure.
5481 * 0 on success, a negative errno value otherwise and rte_errno is set.
5484 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
5485 const struct rte_flow_action *action,
5486 const uint64_t item_flags,
5487 struct rte_flow_error *error)
5491 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5493 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
5494 return rte_flow_error_set(error, EINVAL,
5495 RTE_FLOW_ERROR_TYPE_ACTION,
5497 "no ipv6 item in pattern");
5503 flow_dv_modify_match_cb(void *tool_ctx __rte_unused,
5504 struct mlx5_list_entry *entry, void *cb_ctx)
5506 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5507 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5508 struct mlx5_flow_dv_modify_hdr_resource *resource =
5509 container_of(entry, typeof(*resource), entry);
5510 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5512 key_len += ref->actions_num * sizeof(ref->actions[0]);
5513 return ref->actions_num != resource->actions_num ||
5514 memcmp(&ref->ft_type, &resource->ft_type, key_len);
5517 static struct mlx5_indexed_pool *
5518 flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
5520 struct mlx5_indexed_pool *ipool = __atomic_load_n
5521 (&sh->mdh_ipools[index], __ATOMIC_SEQ_CST);
5524 struct mlx5_indexed_pool *expected = NULL;
5525 struct mlx5_indexed_pool_config cfg =
5526 (struct mlx5_indexed_pool_config) {
5527 .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
5529 sizeof(struct mlx5_modification_cmd),
5534 .release_mem_en = !!sh->config.reclaim_mode,
5536 sh->config.reclaim_mode ? 0 : (1 << 16),
5537 .malloc = mlx5_malloc,
5539 .type = "mlx5_modify_action_resource",
5542 cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
5543 ipool = mlx5_ipool_create(&cfg);
5546 if (!__atomic_compare_exchange_n(&sh->mdh_ipools[index],
5547 &expected, ipool, false,
5549 __ATOMIC_SEQ_CST)) {
5550 mlx5_ipool_destroy(ipool);
5551 ipool = __atomic_load_n(&sh->mdh_ipools[index],
5558 struct mlx5_list_entry *
5559 flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
5561 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5562 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5563 struct mlx5dv_dr_domain *ns;
5564 struct mlx5_flow_dv_modify_hdr_resource *entry;
5565 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5566 struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
5567 ref->actions_num - 1);
5569 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5570 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5573 if (unlikely(!ipool)) {
5574 rte_flow_error_set(ctx->error, ENOMEM,
5575 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5576 NULL, "cannot allocate modify ipool");
5579 entry = mlx5_ipool_zmalloc(ipool, &idx);
5581 rte_flow_error_set(ctx->error, ENOMEM,
5582 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5583 "cannot allocate resource memory");
5586 rte_memcpy(&entry->ft_type,
5587 RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
5588 key_len + data_len);
5589 if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
5590 ns = sh->fdb_domain;
5591 else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
5595 ret = mlx5_flow_os_create_flow_action_modify_header
5596 (sh->cdev->ctx, ns, entry,
5597 data_len, &entry->action);
5599 mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
5600 rte_flow_error_set(ctx->error, ENOMEM,
5601 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5602 NULL, "cannot create modification action");
5606 return &entry->entry;
5609 struct mlx5_list_entry *
5610 flow_dv_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5613 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5614 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5615 struct mlx5_flow_dv_modify_hdr_resource *entry;
5616 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5617 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5620 entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
5623 rte_flow_error_set(ctx->error, ENOMEM,
5624 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5625 "cannot allocate resource memory");
5628 memcpy(entry, oentry, sizeof(*entry) + data_len);
5630 return &entry->entry;
5634 flow_dv_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5636 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5637 struct mlx5_flow_dv_modify_hdr_resource *res =
5638 container_of(entry, typeof(*res), entry);
5640 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
5644 * Validate the sample action.
5646 * @param[in, out] action_flags
5647 * Holds the actions detected until now.
5649 * Pointer to the sample action.
5651 * Pointer to the Ethernet device structure.
5653 * Attributes of flow that includes this action.
5654 * @param[in] item_flags
5655 * Holds the items detected.
5657 * Pointer to the RSS action.
5658 * @param[out] sample_rss
5659 * Pointer to the RSS action in sample action list.
5661 * Pointer to the COUNT action in sample action list.
5662 * @param[out] fdb_mirror_limit
5663 * Pointer to the FDB mirror limitation flag.
5665 * Pointer to error structure.
5668 * 0 on success, a negative errno value otherwise and rte_errno is set.
5671 flow_dv_validate_action_sample(uint64_t *action_flags,
5672 const struct rte_flow_action *action,
5673 struct rte_eth_dev *dev,
5674 const struct rte_flow_attr *attr,
5675 uint64_t item_flags,
5676 const struct rte_flow_action_rss *rss,
5677 const struct rte_flow_action_rss **sample_rss,
5678 const struct rte_flow_action_count **count,
5679 int *fdb_mirror_limit,
5680 struct rte_flow_error *error)
5682 struct mlx5_priv *priv = dev->data->dev_private;
5683 struct mlx5_sh_config *dev_conf = &priv->sh->config;
5684 const struct rte_flow_action_sample *sample = action->conf;
5685 const struct rte_flow_action *act;
5686 uint64_t sub_action_flags = 0;
5687 uint16_t queue_index = 0xFFFF;
5692 return rte_flow_error_set(error, EINVAL,
5693 RTE_FLOW_ERROR_TYPE_ACTION, action,
5694 "configuration cannot be NULL");
5695 if (sample->ratio == 0)
5696 return rte_flow_error_set(error, EINVAL,
5697 RTE_FLOW_ERROR_TYPE_ACTION, action,
5698 "ratio value starts from 1");
5699 if (!priv->sh->cdev->config.devx ||
5700 (sample->ratio > 0 && !priv->sampler_en))
5701 return rte_flow_error_set(error, ENOTSUP,
5702 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5704 "sample action not supported");
5705 if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
5706 return rte_flow_error_set(error, EINVAL,
5707 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5708 "Multiple sample actions not "
5710 if (*action_flags & MLX5_FLOW_ACTION_METER)
5711 return rte_flow_error_set(error, EINVAL,
5712 RTE_FLOW_ERROR_TYPE_ACTION, action,
5713 "wrong action order, meter should "
5714 "be after sample action");
5715 if (*action_flags & MLX5_FLOW_ACTION_JUMP)
5716 return rte_flow_error_set(error, EINVAL,
5717 RTE_FLOW_ERROR_TYPE_ACTION, action,
5718 "wrong action order, jump should "
5719 "be after sample action");
5720 if (*action_flags & MLX5_FLOW_ACTION_CT)
5721 return rte_flow_error_set(error, EINVAL,
5722 RTE_FLOW_ERROR_TYPE_ACTION, action,
5723 "Sample after CT not supported");
5724 act = sample->actions;
5725 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
5726 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5727 return rte_flow_error_set(error, ENOTSUP,
5728 RTE_FLOW_ERROR_TYPE_ACTION,
5729 act, "too many actions");
5730 switch (act->type) {
5731 case RTE_FLOW_ACTION_TYPE_QUEUE:
5732 ret = mlx5_flow_validate_action_queue(act,
5738 queue_index = ((const struct rte_flow_action_queue *)
5739 (act->conf))->index;
5740 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
5743 case RTE_FLOW_ACTION_TYPE_RSS:
5744 *sample_rss = act->conf;
5745 ret = mlx5_flow_validate_action_rss(act,
5752 if (rss && *sample_rss &&
5753 ((*sample_rss)->level != rss->level ||
5754 (*sample_rss)->types != rss->types))
5755 return rte_flow_error_set(error, ENOTSUP,
5756 RTE_FLOW_ERROR_TYPE_ACTION,
5758 "Can't use the different RSS types "
5759 "or level in the same flow");
5760 if (*sample_rss != NULL && (*sample_rss)->queue_num)
5761 queue_index = (*sample_rss)->queue[0];
5762 sub_action_flags |= MLX5_FLOW_ACTION_RSS;
5765 case RTE_FLOW_ACTION_TYPE_MARK:
5766 ret = flow_dv_validate_action_mark(dev, act,
5771 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
5772 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
5773 MLX5_FLOW_ACTION_MARK_EXT;
5775 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
5778 case RTE_FLOW_ACTION_TYPE_COUNT:
5779 ret = flow_dv_validate_action_count
5780 (dev, false, *action_flags | sub_action_flags,
5785 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
5786 *action_flags |= MLX5_FLOW_ACTION_COUNT;
5789 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5790 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5791 ret = flow_dv_validate_action_port_id(dev,
5798 sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5801 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5802 ret = flow_dv_validate_action_raw_encap_decap
5803 (dev, NULL, act->conf, attr, &sub_action_flags,
5804 &actions_n, action, item_flags, error);
5809 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5810 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5811 ret = flow_dv_validate_action_l2_encap(dev,
5817 sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
5821 return rte_flow_error_set(error, ENOTSUP,
5822 RTE_FLOW_ERROR_TYPE_ACTION,
5824 "Doesn't support optional "
5828 if (attr->ingress && !attr->transfer) {
5829 if (!(sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
5830 MLX5_FLOW_ACTION_RSS)))
5831 return rte_flow_error_set(error, EINVAL,
5832 RTE_FLOW_ERROR_TYPE_ACTION,
5834 "Ingress must has a dest "
5835 "QUEUE for Sample");
5836 } else if (attr->egress && !attr->transfer) {
5837 return rte_flow_error_set(error, ENOTSUP,
5838 RTE_FLOW_ERROR_TYPE_ACTION,
5840 "Sample Only support Ingress "
5842 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
5843 MLX5_ASSERT(attr->transfer);
5844 if (sample->ratio > 1)
5845 return rte_flow_error_set(error, ENOTSUP,
5846 RTE_FLOW_ERROR_TYPE_ACTION,
5848 "E-Switch doesn't support "
5849 "any optional action "
5851 if (sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
5852 return rte_flow_error_set(error, ENOTSUP,
5853 RTE_FLOW_ERROR_TYPE_ACTION,
5855 "unsupported action QUEUE");
5856 if (sub_action_flags & MLX5_FLOW_ACTION_RSS)
5857 return rte_flow_error_set(error, ENOTSUP,
5858 RTE_FLOW_ERROR_TYPE_ACTION,
5860 "unsupported action QUEUE");
5861 if (!(sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
5862 return rte_flow_error_set(error, EINVAL,
5863 RTE_FLOW_ERROR_TYPE_ACTION,
5865 "E-Switch must has a dest "
5866 "port for mirroring");
5867 if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
5868 priv->representor_id != UINT16_MAX)
5869 *fdb_mirror_limit = 1;
5871 /* Continue validation for Xcap actions.*/
5872 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
5873 (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index))) {
5874 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5875 MLX5_FLOW_XCAP_ACTIONS)
5876 return rte_flow_error_set(error, ENOTSUP,
5877 RTE_FLOW_ERROR_TYPE_ACTION,
5878 NULL, "encap and decap "
5879 "combination aren't "
5881 if (!attr->transfer && attr->ingress && (sub_action_flags &
5882 MLX5_FLOW_ACTION_ENCAP))
5883 return rte_flow_error_set(error, ENOTSUP,
5884 RTE_FLOW_ERROR_TYPE_ACTION,
5885 NULL, "encap is not supported"
5886 " for ingress traffic");
5892 * Find existing modify-header resource or create and register a new one.
5894 * @param dev[in, out]
5895 * Pointer to rte_eth_dev structure.
5896 * @param[in, out] resource
5897 * Pointer to modify-header resource.
5898 * @parm[in, out] dev_flow
5899 * Pointer to the dev_flow.
5901 * pointer to error structure.
5904 * 0 on success otherwise -errno and errno is set.
5907 flow_dv_modify_hdr_resource_register
5908 (struct rte_eth_dev *dev,
5909 struct mlx5_flow_dv_modify_hdr_resource *resource,
5910 struct mlx5_flow *dev_flow,
5911 struct rte_flow_error *error)
5913 struct mlx5_priv *priv = dev->data->dev_private;
5914 struct mlx5_dev_ctx_shared *sh = priv->sh;
5915 uint32_t key_len = sizeof(*resource) -
5916 offsetof(typeof(*resource), ft_type) +
5917 resource->actions_num * sizeof(resource->actions[0]);
5918 struct mlx5_list_entry *entry;
5919 struct mlx5_flow_cb_ctx ctx = {
5923 struct mlx5_hlist *modify_cmds;
5926 modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
5928 MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
5930 flow_dv_modify_create_cb,
5931 flow_dv_modify_match_cb,
5932 flow_dv_modify_remove_cb,
5933 flow_dv_modify_clone_cb,
5934 flow_dv_modify_clone_free_cb,
5936 if (unlikely(!modify_cmds))
5938 resource->root = !dev_flow->dv.group;
5939 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
5941 return rte_flow_error_set(error, EOVERFLOW,
5942 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5943 "too many modify header items");
5944 key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
5945 entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
5948 resource = container_of(entry, typeof(*resource), entry);
5949 dev_flow->handle->dvh.modify_hdr = resource;
5954 * Get DV flow counter by index.
5957 * Pointer to the Ethernet device structure.
5959 * mlx5 flow counter index in the container.
5961 * mlx5 flow counter pool in the container.
5964 * Pointer to the counter, NULL otherwise.
5966 static struct mlx5_flow_counter *
5967 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
5969 struct mlx5_flow_counter_pool **ppool)
5971 struct mlx5_priv *priv = dev->data->dev_private;
5972 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5973 struct mlx5_flow_counter_pool *pool;
5975 /* Decrease to original index and clear shared bit. */
5976 idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
5977 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cmng->n);
5978 pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
5982 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
5986 * Check the devx counter belongs to the pool.
5989 * Pointer to the counter pool.
5991 * The counter devx ID.
5994 * True if counter belongs to the pool, false otherwise.
5997 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
5999 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
6000 MLX5_COUNTERS_PER_POOL;
6002 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
6008 * Get a pool by devx counter ID.
6011 * Pointer to the counter management.
6013 * The counter devx ID.
6016 * The counter pool pointer if exists, NULL otherwise,
6018 static struct mlx5_flow_counter_pool *
6019 flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
6022 struct mlx5_flow_counter_pool *pool = NULL;
6024 rte_spinlock_lock(&cmng->pool_update_sl);
6025 /* Check last used pool. */
6026 if (cmng->last_pool_idx != POOL_IDX_INVALID &&
6027 flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
6028 pool = cmng->pools[cmng->last_pool_idx];
6031 /* ID out of range means no suitable pool in the container. */
6032 if (id > cmng->max_id || id < cmng->min_id)
6035 * Find the pool from the end of the container, since mostly counter
6036 * ID is sequence increasing, and the last pool should be the needed
6041 struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
6043 if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
6049 rte_spinlock_unlock(&cmng->pool_update_sl);
6054 * Resize a counter container.
6057 * Pointer to the Ethernet device structure.
6060 * 0 on success, otherwise negative errno value and rte_errno is set.
6063 flow_dv_container_resize(struct rte_eth_dev *dev)
6065 struct mlx5_priv *priv = dev->data->dev_private;
6066 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6067 void *old_pools = cmng->pools;
6068 uint32_t resize = cmng->n + MLX5_CNT_CONTAINER_RESIZE;
6069 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
6070 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
6077 memcpy(pools, old_pools, cmng->n *
6078 sizeof(struct mlx5_flow_counter_pool *));
6080 cmng->pools = pools;
6082 mlx5_free(old_pools);
6087 * Query a devx flow counter.
6090 * Pointer to the Ethernet device structure.
6091 * @param[in] counter
6092 * Index to the flow counter.
6094 * The statistics value of packets.
6096 * The statistics value of bytes.
6099 * 0 on success, otherwise a negative errno value and rte_errno is set.
6102 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6105 struct mlx5_priv *priv = dev->data->dev_private;
6106 struct mlx5_flow_counter_pool *pool = NULL;
6107 struct mlx5_flow_counter *cnt;
6110 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6112 if (priv->sh->cmng.counter_fallback)
6113 return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6114 0, pkts, bytes, 0, NULL, NULL, 0);
6115 rte_spinlock_lock(&pool->sl);
6120 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6121 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6122 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6124 rte_spinlock_unlock(&pool->sl);
6129 * Create and initialize a new counter pool.
6132 * Pointer to the Ethernet device structure.
6134 * The devX counter handle.
6136 * Whether the pool is for counter that was allocated for aging.
6137 * @param[in/out] cont_cur
6138 * Pointer to the container pointer, it will be update in pool resize.
6141 * The pool container pointer on success, NULL otherwise and rte_errno is set.
6143 static struct mlx5_flow_counter_pool *
6144 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6147 struct mlx5_priv *priv = dev->data->dev_private;
6148 struct mlx5_flow_counter_pool *pool;
6149 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6150 bool fallback = priv->sh->cmng.counter_fallback;
6151 uint32_t size = sizeof(*pool);
6153 size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6154 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6155 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6161 pool->is_aged = !!age;
6162 pool->query_gen = 0;
6163 pool->min_dcs = dcs;
6164 rte_spinlock_init(&pool->sl);
6165 rte_spinlock_init(&pool->csl);
6166 TAILQ_INIT(&pool->counters[0]);
6167 TAILQ_INIT(&pool->counters[1]);
6168 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6169 rte_spinlock_lock(&cmng->pool_update_sl);
6170 pool->index = cmng->n_valid;
6171 if (pool->index == cmng->n && flow_dv_container_resize(dev)) {
6173 rte_spinlock_unlock(&cmng->pool_update_sl);
6176 cmng->pools[pool->index] = pool;
6178 if (unlikely(fallback)) {
6179 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6181 if (base < cmng->min_id)
6182 cmng->min_id = base;
6183 if (base > cmng->max_id)
6184 cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6185 cmng->last_pool_idx = pool->index;
6187 rte_spinlock_unlock(&cmng->pool_update_sl);
6192 * Prepare a new counter and/or a new counter pool.
6195 * Pointer to the Ethernet device structure.
6196 * @param[out] cnt_free
6197 * Where to put the pointer of a new counter.
6199 * Whether the pool is for counter that was allocated for aging.
6202 * The counter pool pointer and @p cnt_free is set on success,
6203 * NULL otherwise and rte_errno is set.
6205 static struct mlx5_flow_counter_pool *
6206 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6207 struct mlx5_flow_counter **cnt_free,
6210 struct mlx5_priv *priv = dev->data->dev_private;
6211 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6212 struct mlx5_flow_counter_pool *pool;
6213 struct mlx5_counters tmp_tq;
6214 struct mlx5_devx_obj *dcs = NULL;
6215 struct mlx5_flow_counter *cnt;
6216 enum mlx5_counter_type cnt_type =
6217 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6218 bool fallback = priv->sh->cmng.counter_fallback;
6222 /* bulk_bitmap must be 0 for single counter allocation. */
6223 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6226 pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6228 pool = flow_dv_pool_create(dev, dcs, age);
6230 mlx5_devx_cmd_destroy(dcs);
6234 i = dcs->id % MLX5_COUNTERS_PER_POOL;
6235 cnt = MLX5_POOL_GET_CNT(pool, i);
6237 cnt->dcs_when_free = dcs;
6241 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6243 rte_errno = ENODATA;
6246 pool = flow_dv_pool_create(dev, dcs, age);
6248 mlx5_devx_cmd_destroy(dcs);
6251 TAILQ_INIT(&tmp_tq);
6252 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6253 cnt = MLX5_POOL_GET_CNT(pool, i);
6255 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6257 rte_spinlock_lock(&cmng->csl[cnt_type]);
6258 TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6259 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6260 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6261 (*cnt_free)->pool = pool;
6266 * Allocate a flow counter.
6269 * Pointer to the Ethernet device structure.
6271 * Whether the counter was allocated for aging.
6274 * Index to flow counter on success, 0 otherwise and rte_errno is set.
6277 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6279 struct mlx5_priv *priv = dev->data->dev_private;
6280 struct mlx5_flow_counter_pool *pool = NULL;
6281 struct mlx5_flow_counter *cnt_free = NULL;
6282 bool fallback = priv->sh->cmng.counter_fallback;
6283 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6284 enum mlx5_counter_type cnt_type =
6285 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6288 if (!priv->sh->cdev->config.devx) {
6289 rte_errno = ENOTSUP;
6292 /* Get free counters from container. */
6293 rte_spinlock_lock(&cmng->csl[cnt_type]);
6294 cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6296 TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6297 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6298 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6300 pool = cnt_free->pool;
6302 cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6303 /* Create a DV counter action only in the first time usage. */
6304 if (!cnt_free->action) {
6306 struct mlx5_devx_obj *dcs;
6310 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
6311 dcs = pool->min_dcs;
6314 dcs = cnt_free->dcs_when_free;
6316 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
6323 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
6324 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
6325 /* Update the counter reset values. */
6326 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
6329 if (!fallback && !priv->sh->cmng.query_thread_on)
6330 /* Start the asynchronous batch query by the host thread. */
6331 mlx5_set_query_alarm(priv->sh);
6333 * When the count action isn't shared (by ID), shared_info field is
6334 * used for indirect action API's refcnt.
6335 * When the counter action is not shared neither by ID nor by indirect
6336 * action API, shared info must be 1.
6338 cnt_free->shared_info.refcnt = 1;
6342 cnt_free->pool = pool;
6344 cnt_free->dcs_when_free = cnt_free->dcs_when_active;
6345 rte_spinlock_lock(&cmng->csl[cnt_type]);
6346 TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
6347 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6353 * Get age param from counter index.
6356 * Pointer to the Ethernet device structure.
6357 * @param[in] counter
6358 * Index to the counter handler.
6361 * The aging parameter specified for the counter index.
6363 static struct mlx5_age_param*
6364 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
6367 struct mlx5_flow_counter *cnt;
6368 struct mlx5_flow_counter_pool *pool = NULL;
6370 flow_dv_counter_get_by_idx(dev, counter, &pool);
6371 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
6372 cnt = MLX5_POOL_GET_CNT(pool, counter);
6373 return MLX5_CNT_TO_AGE(cnt);
6377 * Remove a flow counter from aged counter list.
6380 * Pointer to the Ethernet device structure.
6381 * @param[in] counter
6382 * Index to the counter handler.
6384 * Pointer to the counter handler.
6387 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
6388 uint32_t counter, struct mlx5_flow_counter *cnt)
6390 struct mlx5_age_info *age_info;
6391 struct mlx5_age_param *age_param;
6392 struct mlx5_priv *priv = dev->data->dev_private;
6393 uint16_t expected = AGE_CANDIDATE;
6395 age_info = GET_PORT_AGE_INFO(priv);
6396 age_param = flow_dv_counter_idx_get_age(dev, counter);
6397 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
6398 AGE_FREE, false, __ATOMIC_RELAXED,
6399 __ATOMIC_RELAXED)) {
6401 * We need the lock even it is age timeout,
6402 * since counter may still in process.
6404 rte_spinlock_lock(&age_info->aged_sl);
6405 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
6406 rte_spinlock_unlock(&age_info->aged_sl);
6407 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
6412 * Release a flow counter.
6415 * Pointer to the Ethernet device structure.
6416 * @param[in] counter
6417 * Index to the counter handler.
6420 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
6422 struct mlx5_priv *priv = dev->data->dev_private;
6423 struct mlx5_flow_counter_pool *pool = NULL;
6424 struct mlx5_flow_counter *cnt;
6425 enum mlx5_counter_type cnt_type;
6429 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6431 if (pool->is_aged) {
6432 flow_dv_counter_remove_from_age(dev, counter, cnt);
6435 * If the counter action is shared by indirect action API,
6436 * the atomic function reduces its references counter.
6437 * If after the reduction the action is still referenced, the
6438 * function returns here and does not release it.
6439 * When the counter action is not shared by
6440 * indirect action API, shared info is 1 before the reduction,
6441 * so this condition is failed and function doesn't return here.
6443 if (__atomic_sub_fetch(&cnt->shared_info.refcnt, 1,
6449 * Put the counter back to list to be updated in none fallback mode.
6450 * Currently, we are using two list alternately, while one is in query,
6451 * add the freed counter to the other list based on the pool query_gen
6452 * value. After query finishes, add counter the list to the global
6453 * container counter list. The list changes while query starts. In
6454 * this case, lock will not be needed as query callback and release
6455 * function both operate with the different list.
6457 if (!priv->sh->cmng.counter_fallback) {
6458 rte_spinlock_lock(&pool->csl);
6459 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
6460 rte_spinlock_unlock(&pool->csl);
6462 cnt->dcs_when_free = cnt->dcs_when_active;
6463 cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6464 MLX5_COUNTER_TYPE_ORIGIN;
6465 rte_spinlock_lock(&priv->sh->cmng.csl[cnt_type]);
6466 TAILQ_INSERT_TAIL(&priv->sh->cmng.counters[cnt_type],
6468 rte_spinlock_unlock(&priv->sh->cmng.csl[cnt_type]);
6473 * Resize a meter id container.
6476 * Pointer to the Ethernet device structure.
6479 * 0 on success, otherwise negative errno value and rte_errno is set.
6482 flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
6484 struct mlx5_priv *priv = dev->data->dev_private;
6485 struct mlx5_aso_mtr_pools_mng *pools_mng =
6486 &priv->sh->mtrmng->pools_mng;
6487 void *old_pools = pools_mng->pools;
6488 uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
6489 uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
6490 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
6497 if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER)) {
6502 memcpy(pools, old_pools, pools_mng->n *
6503 sizeof(struct mlx5_aso_mtr_pool *));
6504 pools_mng->n = resize;
6505 pools_mng->pools = pools;
6507 mlx5_free(old_pools);
6512 * Prepare a new meter and/or a new meter pool.
6515 * Pointer to the Ethernet device structure.
6516 * @param[out] mtr_free
6517 * Where to put the pointer of a new meter.g.
6520 * The meter pool pointer and @mtr_free is set on success,
6521 * NULL otherwise and rte_errno is set.
6523 static struct mlx5_aso_mtr_pool *
6524 flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
6526 struct mlx5_priv *priv = dev->data->dev_private;
6527 struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
6528 struct mlx5_aso_mtr_pool *pool = NULL;
6529 struct mlx5_devx_obj *dcs = NULL;
6531 uint32_t log_obj_size;
6533 log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
6534 dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
6535 priv->sh->cdev->pdn,
6538 rte_errno = ENODATA;
6541 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
6544 claim_zero(mlx5_devx_cmd_destroy(dcs));
6547 pool->devx_obj = dcs;
6548 rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
6549 pool->index = pools_mng->n_valid;
6550 if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
6552 claim_zero(mlx5_devx_cmd_destroy(dcs));
6553 rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
6556 pools_mng->pools[pool->index] = pool;
6557 pools_mng->n_valid++;
6558 rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
6559 for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
6560 pool->mtrs[i].offset = i;
6561 LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
6563 pool->mtrs[0].offset = 0;
6564 *mtr_free = &pool->mtrs[0];
6569 * Release a flow meter into pool.
6572 * Pointer to the Ethernet device structure.
6573 * @param[in] mtr_idx
6574 * Index to aso flow meter.
6577 flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
6579 struct mlx5_priv *priv = dev->data->dev_private;
6580 struct mlx5_aso_mtr_pools_mng *pools_mng =
6581 &priv->sh->mtrmng->pools_mng;
6582 struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
6584 MLX5_ASSERT(aso_mtr);
6585 rte_spinlock_lock(&pools_mng->mtrsl);
6586 memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
6587 aso_mtr->state = ASO_METER_FREE;
6588 LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
6589 rte_spinlock_unlock(&pools_mng->mtrsl);
6593 * Allocate a aso flow meter.
6596 * Pointer to the Ethernet device structure.
6599 * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
6602 flow_dv_mtr_alloc(struct rte_eth_dev *dev)
6604 struct mlx5_priv *priv = dev->data->dev_private;
6605 struct mlx5_aso_mtr *mtr_free = NULL;
6606 struct mlx5_aso_mtr_pools_mng *pools_mng =
6607 &priv->sh->mtrmng->pools_mng;
6608 struct mlx5_aso_mtr_pool *pool;
6609 uint32_t mtr_idx = 0;
6611 if (!priv->sh->cdev->config.devx) {
6612 rte_errno = ENOTSUP;
6615 /* Allocate the flow meter memory. */
6616 /* Get free meters from management. */
6617 rte_spinlock_lock(&pools_mng->mtrsl);
6618 mtr_free = LIST_FIRST(&pools_mng->meters);
6620 LIST_REMOVE(mtr_free, next);
6621 if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
6622 rte_spinlock_unlock(&pools_mng->mtrsl);
6625 mtr_free->state = ASO_METER_WAIT;
6626 rte_spinlock_unlock(&pools_mng->mtrsl);
6627 pool = container_of(mtr_free,
6628 struct mlx5_aso_mtr_pool,
6629 mtrs[mtr_free->offset]);
6630 mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
6631 if (!mtr_free->fm.meter_action_g) {
6632 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
6633 struct rte_flow_error error;
6636 reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
6637 mtr_free->fm.meter_action_g =
6638 mlx5_glue->dv_create_flow_action_aso
6639 (priv->sh->rx_domain,
6640 pool->devx_obj->obj,
6642 (1 << MLX5_FLOW_COLOR_GREEN),
6644 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
6645 if (!mtr_free->fm.meter_action_g) {
6646 flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
6654 * Verify the @p attributes will be correctly understood by the NIC and store
6655 * them in the @p flow if everything is correct.
6658 * Pointer to dev struct.
6659 * @param[in] attributes
6660 * Pointer to flow attributes
6661 * @param[in] external
6662 * This flow rule is created by request external to PMD.
6664 * Pointer to error structure.
6667 * - 0 on success and non root table.
6668 * - 1 on success and root table.
6669 * - a negative errno value otherwise and rte_errno is set.
6672 flow_dv_validate_attributes(struct rte_eth_dev *dev,
6673 const struct mlx5_flow_tunnel *tunnel,
6674 const struct rte_flow_attr *attributes,
6675 const struct flow_grp_info *grp_info,
6676 struct rte_flow_error *error)
6678 struct mlx5_priv *priv = dev->data->dev_private;
6679 uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
6682 #ifndef HAVE_MLX5DV_DR
6683 RTE_SET_USED(tunnel);
6684 RTE_SET_USED(grp_info);
6685 if (attributes->group)
6686 return rte_flow_error_set(error, ENOTSUP,
6687 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6689 "groups are not supported");
6693 ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
6698 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
6700 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
6701 attributes->priority > lowest_priority)
6702 return rte_flow_error_set(error, ENOTSUP,
6703 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
6705 "priority out of range");
6706 if (attributes->transfer) {
6707 if (!priv->sh->config.dv_esw_en)
6708 return rte_flow_error_set
6710 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6711 "E-Switch dr is not supported");
6712 if (attributes->egress)
6713 return rte_flow_error_set
6715 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
6716 "egress is not supported");
6718 if (!(attributes->egress ^ attributes->ingress))
6719 return rte_flow_error_set(error, ENOTSUP,
6720 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6721 "must specify exactly one of "
6722 "ingress or egress");
6727 validate_integrity_bits(const struct rte_flow_item_integrity *mask,
6728 int64_t pattern_flags, uint64_t l3_flags,
6729 uint64_t l4_flags, uint64_t ip4_flag,
6730 struct rte_flow_error *error)
6732 if (mask->l3_ok && !(pattern_flags & l3_flags))
6733 return rte_flow_error_set(error, EINVAL,
6734 RTE_FLOW_ERROR_TYPE_ITEM,
6735 NULL, "missing L3 protocol");
6737 if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
6738 return rte_flow_error_set(error, EINVAL,
6739 RTE_FLOW_ERROR_TYPE_ITEM,
6740 NULL, "missing IPv4 protocol");
6742 if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
6743 return rte_flow_error_set(error, EINVAL,
6744 RTE_FLOW_ERROR_TYPE_ITEM,
6745 NULL, "missing L4 protocol");
6751 flow_dv_validate_item_integrity_post(const struct
6752 rte_flow_item *integrity_items[2],
6753 int64_t pattern_flags,
6754 struct rte_flow_error *error)
6756 const struct rte_flow_item_integrity *mask;
6759 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
6760 mask = (typeof(mask))integrity_items[0]->mask;
6761 ret = validate_integrity_bits(mask, pattern_flags,
6762 MLX5_FLOW_LAYER_OUTER_L3,
6763 MLX5_FLOW_LAYER_OUTER_L4,
6764 MLX5_FLOW_LAYER_OUTER_L3_IPV4,
6769 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
6770 mask = (typeof(mask))integrity_items[1]->mask;
6771 ret = validate_integrity_bits(mask, pattern_flags,
6772 MLX5_FLOW_LAYER_INNER_L3,
6773 MLX5_FLOW_LAYER_INNER_L4,
6774 MLX5_FLOW_LAYER_INNER_L3_IPV4,
6783 flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
6784 const struct rte_flow_item *integrity_item,
6785 uint64_t pattern_flags, uint64_t *last_item,
6786 const struct rte_flow_item *integrity_items[2],
6787 struct rte_flow_error *error)
6789 struct mlx5_priv *priv = dev->data->dev_private;
6790 const struct rte_flow_item_integrity *mask = (typeof(mask))
6791 integrity_item->mask;
6792 const struct rte_flow_item_integrity *spec = (typeof(spec))
6793 integrity_item->spec;
6795 if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
6796 return rte_flow_error_set(error, ENOTSUP,
6797 RTE_FLOW_ERROR_TYPE_ITEM,
6799 "packet integrity integrity_item not supported");
6801 return rte_flow_error_set(error, ENOTSUP,
6802 RTE_FLOW_ERROR_TYPE_ITEM,
6804 "no spec for integrity item");
6806 mask = &rte_flow_item_integrity_mask;
6807 if (!mlx5_validate_integrity_item(mask))
6808 return rte_flow_error_set(error, ENOTSUP,
6809 RTE_FLOW_ERROR_TYPE_ITEM,
6811 "unsupported integrity filter");
6812 if (spec->level > 1) {
6813 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
6814 return rte_flow_error_set
6816 RTE_FLOW_ERROR_TYPE_ITEM,
6817 NULL, "multiple inner integrity items not supported");
6818 integrity_items[1] = integrity_item;
6819 *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
6821 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
6822 return rte_flow_error_set
6824 RTE_FLOW_ERROR_TYPE_ITEM,
6825 NULL, "multiple outer integrity items not supported");
6826 integrity_items[0] = integrity_item;
6827 *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
6833 flow_dv_validate_item_flex(struct rte_eth_dev *dev,
6834 const struct rte_flow_item *item,
6835 uint64_t item_flags,
6836 uint64_t *last_item,
6838 struct rte_flow_error *error)
6840 const struct rte_flow_item_flex *flow_spec = item->spec;
6841 const struct rte_flow_item_flex *flow_mask = item->mask;
6842 struct mlx5_flex_item *flex;
6845 return rte_flow_error_set(error, EINVAL,
6846 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6847 "flex flow item spec cannot be NULL");
6849 return rte_flow_error_set(error, EINVAL,
6850 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6851 "flex flow item mask cannot be NULL");
6853 return rte_flow_error_set(error, ENOTSUP,
6854 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6855 "flex flow item last not supported");
6856 if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
6857 return rte_flow_error_set(error, EINVAL,
6858 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6859 "invalid flex flow item handle");
6860 flex = (struct mlx5_flex_item *)flow_spec->handle;
6861 switch (flex->tunnel_mode) {
6862 case FLEX_TUNNEL_MODE_SINGLE:
6864 (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
6865 rte_flow_error_set(error, EINVAL,
6866 RTE_FLOW_ERROR_TYPE_ITEM,
6867 NULL, "multiple flex items not supported");
6869 case FLEX_TUNNEL_MODE_OUTER:
6871 rte_flow_error_set(error, EINVAL,
6872 RTE_FLOW_ERROR_TYPE_ITEM,
6873 NULL, "inner flex item was not configured");
6874 if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
6875 rte_flow_error_set(error, ENOTSUP,
6876 RTE_FLOW_ERROR_TYPE_ITEM,
6877 NULL, "multiple flex items not supported");
6879 case FLEX_TUNNEL_MODE_INNER:
6881 rte_flow_error_set(error, EINVAL,
6882 RTE_FLOW_ERROR_TYPE_ITEM,
6883 NULL, "outer flex item was not configured");
6884 if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
6885 rte_flow_error_set(error, EINVAL,
6886 RTE_FLOW_ERROR_TYPE_ITEM,
6887 NULL, "multiple flex items not supported");
6889 case FLEX_TUNNEL_MODE_MULTI:
6890 if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
6891 (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
6892 rte_flow_error_set(error, EINVAL,
6893 RTE_FLOW_ERROR_TYPE_ITEM,
6894 NULL, "multiple flex items not supported");
6897 case FLEX_TUNNEL_MODE_TUNNEL:
6898 if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
6899 rte_flow_error_set(error, EINVAL,
6900 RTE_FLOW_ERROR_TYPE_ITEM,
6901 NULL, "multiple flex tunnel items not supported");
6904 rte_flow_error_set(error, EINVAL,
6905 RTE_FLOW_ERROR_TYPE_ITEM,
6906 NULL, "invalid flex item configuration");
6908 *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
6909 MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
6910 MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
6915 * Internal validation function. For validating both actions and items.
6918 * Pointer to the rte_eth_dev structure.
6920 * Pointer to the flow attributes.
6922 * Pointer to the list of items.
6923 * @param[in] actions
6924 * Pointer to the list of actions.
6925 * @param[in] external
6926 * This flow rule is created by request external to PMD.
6927 * @param[in] hairpin
6928 * Number of hairpin TX actions, 0 means classic flow.
6930 * Pointer to the error structure.
6933 * 0 on success, a negative errno value otherwise and rte_errno is set.
6936 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
6937 const struct rte_flow_item items[],
6938 const struct rte_flow_action actions[],
6939 bool external, int hairpin, struct rte_flow_error *error)
6942 uint64_t aso_mask, action_flags = 0;
6943 uint64_t item_flags = 0;
6944 uint64_t last_item = 0;
6945 uint8_t next_protocol = 0xff;
6946 uint16_t ether_type = 0;
6948 uint8_t item_ipv6_proto = 0;
6949 int fdb_mirror_limit = 0;
6950 int modify_after_mirror = 0;
6951 const struct rte_flow_item *geneve_item = NULL;
6952 const struct rte_flow_item *gre_item = NULL;
6953 const struct rte_flow_item *gtp_item = NULL;
6954 const struct rte_flow_action_raw_decap *decap;
6955 const struct rte_flow_action_raw_encap *encap;
6956 const struct rte_flow_action_rss *rss = NULL;
6957 const struct rte_flow_action_rss *sample_rss = NULL;
6958 const struct rte_flow_action_count *sample_count = NULL;
6959 const struct rte_flow_item_tcp nic_tcp_mask = {
6962 .src_port = RTE_BE16(UINT16_MAX),
6963 .dst_port = RTE_BE16(UINT16_MAX),
6966 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
6969 "\xff\xff\xff\xff\xff\xff\xff\xff"
6970 "\xff\xff\xff\xff\xff\xff\xff\xff",
6972 "\xff\xff\xff\xff\xff\xff\xff\xff"
6973 "\xff\xff\xff\xff\xff\xff\xff\xff",
6974 .vtc_flow = RTE_BE32(0xffffffff),
6980 const struct rte_flow_item_ecpri nic_ecpri_mask = {
6984 RTE_BE32(((const struct rte_ecpri_common_hdr) {
6988 .dummy[0] = 0xffffffff,
6991 struct mlx5_priv *priv = dev->data->dev_private;
6992 struct mlx5_sh_config *dev_conf = &priv->sh->config;
6993 uint16_t queue_index = 0xFFFF;
6994 const struct rte_flow_item_vlan *vlan_m = NULL;
6995 uint32_t rw_act_num = 0;
6997 const struct mlx5_flow_tunnel *tunnel;
6998 enum mlx5_tof_rule_type tof_rule_type;
6999 struct flow_grp_info grp_info = {
7000 .external = !!external,
7001 .transfer = !!attr->transfer,
7002 .fdb_def_rule = !!priv->fdb_def_rule,
7003 .std_tbl_fix = true,
7005 const struct rte_eth_hairpin_conf *conf;
7006 const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
7007 const struct rte_flow_item *port_id_item = NULL;
7008 bool def_policy = false;
7009 bool shared_count = false;
7010 uint16_t udp_dport = 0;
7011 uint32_t tag_id = 0;
7012 const struct rte_flow_action_age *non_shared_age = NULL;
7013 const struct rte_flow_action_count *count = NULL;
7017 tunnel = is_tunnel_offload_active(dev) ?
7018 mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
7020 if (!dev_conf->dv_flow_en)
7021 return rte_flow_error_set
7023 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7024 NULL, "tunnel offload requires DV flow interface");
7025 if (priv->representor)
7026 return rte_flow_error_set
7028 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7029 NULL, "decap not supported for VF representor");
7030 if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
7031 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
7032 else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
7033 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
7034 MLX5_FLOW_ACTION_DECAP;
7035 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
7036 (dev, attr, tunnel, tof_rule_type);
7038 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
7041 is_root = (uint64_t)ret;
7042 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7043 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7044 int type = items->type;
7046 if (!mlx5_flow_os_item_supported(type))
7047 return rte_flow_error_set(error, ENOTSUP,
7048 RTE_FLOW_ERROR_TYPE_ITEM,
7049 NULL, "item not supported");
7051 case RTE_FLOW_ITEM_TYPE_VOID:
7053 case RTE_FLOW_ITEM_TYPE_ESP:
7054 ret = mlx5_flow_os_validate_item_esp(items, item_flags,
7059 last_item = MLX5_FLOW_ITEM_ESP;
7061 case RTE_FLOW_ITEM_TYPE_PORT_ID:
7062 ret = flow_dv_validate_item_port_id
7063 (dev, items, attr, item_flags, error);
7066 last_item = MLX5_FLOW_ITEM_PORT_ID;
7067 port_id_item = items;
7069 case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
7070 ret = flow_dv_validate_item_represented_port
7071 (dev, items, attr, item_flags, error);
7074 last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
7076 case RTE_FLOW_ITEM_TYPE_ETH:
7077 ret = mlx5_flow_validate_item_eth(items, item_flags,
7081 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7082 MLX5_FLOW_LAYER_OUTER_L2;
7083 if (items->mask != NULL && items->spec != NULL) {
7085 ((const struct rte_flow_item_eth *)
7088 ((const struct rte_flow_item_eth *)
7090 ether_type = rte_be_to_cpu_16(ether_type);
7095 case RTE_FLOW_ITEM_TYPE_VLAN:
7096 ret = flow_dv_validate_item_vlan(items, item_flags,
7100 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
7101 MLX5_FLOW_LAYER_OUTER_VLAN;
7102 if (items->mask != NULL && items->spec != NULL) {
7104 ((const struct rte_flow_item_vlan *)
7105 items->spec)->inner_type;
7107 ((const struct rte_flow_item_vlan *)
7108 items->mask)->inner_type;
7109 ether_type = rte_be_to_cpu_16(ether_type);
7113 /* Store outer VLAN mask for of_push_vlan action. */
7115 vlan_m = items->mask;
7117 case RTE_FLOW_ITEM_TYPE_IPV4:
7118 mlx5_flow_tunnel_ip_check(items, next_protocol,
7119 &item_flags, &tunnel);
7120 ret = flow_dv_validate_item_ipv4(dev, items, item_flags,
7121 last_item, ether_type,
7125 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7126 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7127 if (items->mask != NULL &&
7128 ((const struct rte_flow_item_ipv4 *)
7129 items->mask)->hdr.next_proto_id) {
7131 ((const struct rte_flow_item_ipv4 *)
7132 (items->spec))->hdr.next_proto_id;
7134 ((const struct rte_flow_item_ipv4 *)
7135 (items->mask))->hdr.next_proto_id;
7137 /* Reset for inner layer. */
7138 next_protocol = 0xff;
7141 case RTE_FLOW_ITEM_TYPE_IPV6:
7142 mlx5_flow_tunnel_ip_check(items, next_protocol,
7143 &item_flags, &tunnel);
7144 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
7151 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7152 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7153 if (items->mask != NULL &&
7154 ((const struct rte_flow_item_ipv6 *)
7155 items->mask)->hdr.proto) {
7157 ((const struct rte_flow_item_ipv6 *)
7158 items->spec)->hdr.proto;
7160 ((const struct rte_flow_item_ipv6 *)
7161 items->spec)->hdr.proto;
7163 ((const struct rte_flow_item_ipv6 *)
7164 items->mask)->hdr.proto;
7166 /* Reset for inner layer. */
7167 next_protocol = 0xff;
7170 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7171 ret = flow_dv_validate_item_ipv6_frag_ext(items,
7176 last_item = tunnel ?
7177 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
7178 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
7179 if (items->mask != NULL &&
7180 ((const struct rte_flow_item_ipv6_frag_ext *)
7181 items->mask)->hdr.next_header) {
7183 ((const struct rte_flow_item_ipv6_frag_ext *)
7184 items->spec)->hdr.next_header;
7186 ((const struct rte_flow_item_ipv6_frag_ext *)
7187 items->mask)->hdr.next_header;
7189 /* Reset for inner layer. */
7190 next_protocol = 0xff;
7193 case RTE_FLOW_ITEM_TYPE_TCP:
7194 ret = mlx5_flow_validate_item_tcp
7201 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7202 MLX5_FLOW_LAYER_OUTER_L4_TCP;
7204 case RTE_FLOW_ITEM_TYPE_UDP:
7205 ret = mlx5_flow_validate_item_udp(items, item_flags,
7208 const struct rte_flow_item_udp *spec = items->spec;
7209 const struct rte_flow_item_udp *mask = items->mask;
7211 mask = &rte_flow_item_udp_mask;
7213 udp_dport = rte_be_to_cpu_16
7214 (spec->hdr.dst_port &
7215 mask->hdr.dst_port);
7218 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
7219 MLX5_FLOW_LAYER_OUTER_L4_UDP;
7221 case RTE_FLOW_ITEM_TYPE_GRE:
7222 ret = mlx5_flow_validate_item_gre(items, item_flags,
7223 next_protocol, error);
7227 last_item = MLX5_FLOW_LAYER_GRE;
7229 case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
7230 ret = mlx5_flow_validate_item_gre_option(dev, items, item_flags,
7231 attr, gre_item, error);
7234 last_item = MLX5_FLOW_LAYER_GRE;
7236 case RTE_FLOW_ITEM_TYPE_NVGRE:
7237 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
7242 last_item = MLX5_FLOW_LAYER_NVGRE;
7244 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7245 ret = mlx5_flow_validate_item_gre_key
7246 (items, item_flags, gre_item, error);
7249 last_item = MLX5_FLOW_LAYER_GRE_KEY;
7251 case RTE_FLOW_ITEM_TYPE_VXLAN:
7252 ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
7257 last_item = MLX5_FLOW_LAYER_VXLAN;
7259 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7260 ret = mlx5_flow_validate_item_vxlan_gpe(items,
7265 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
7267 case RTE_FLOW_ITEM_TYPE_GENEVE:
7268 ret = mlx5_flow_validate_item_geneve(items,
7273 geneve_item = items;
7274 last_item = MLX5_FLOW_LAYER_GENEVE;
7276 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
7277 ret = mlx5_flow_validate_item_geneve_opt(items,
7284 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
7286 case RTE_FLOW_ITEM_TYPE_MPLS:
7287 ret = mlx5_flow_validate_item_mpls(dev, items,
7292 last_item = MLX5_FLOW_LAYER_MPLS;
7295 case RTE_FLOW_ITEM_TYPE_MARK:
7296 ret = flow_dv_validate_item_mark(dev, items, attr,
7300 last_item = MLX5_FLOW_ITEM_MARK;
7302 case RTE_FLOW_ITEM_TYPE_META:
7303 ret = flow_dv_validate_item_meta(dev, items, attr,
7307 last_item = MLX5_FLOW_ITEM_METADATA;
7309 case RTE_FLOW_ITEM_TYPE_ICMP:
7310 ret = mlx5_flow_validate_item_icmp(items, item_flags,
7315 last_item = MLX5_FLOW_LAYER_ICMP;
7317 case RTE_FLOW_ITEM_TYPE_ICMP6:
7318 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
7323 item_ipv6_proto = IPPROTO_ICMPV6;
7324 last_item = MLX5_FLOW_LAYER_ICMP6;
7326 case RTE_FLOW_ITEM_TYPE_TAG:
7327 ret = flow_dv_validate_item_tag(dev, items,
7331 last_item = MLX5_FLOW_ITEM_TAG;
7333 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
7334 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
7336 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7338 case RTE_FLOW_ITEM_TYPE_GTP:
7339 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
7344 last_item = MLX5_FLOW_LAYER_GTP;
7346 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
7347 ret = flow_dv_validate_item_gtp_psc(items, last_item,
7352 last_item = MLX5_FLOW_LAYER_GTP_PSC;
7354 case RTE_FLOW_ITEM_TYPE_ECPRI:
7355 /* Capacity will be checked in the translate stage. */
7356 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
7363 last_item = MLX5_FLOW_LAYER_ECPRI;
7365 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
7366 ret = flow_dv_validate_item_integrity(dev, items,
7374 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
7375 ret = flow_dv_validate_item_aso_ct(dev, items,
7376 &item_flags, error);
7380 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
7381 /* tunnel offload item was processed before
7382 * list it here as a supported type
7385 case RTE_FLOW_ITEM_TYPE_FLEX:
7386 ret = flow_dv_validate_item_flex(dev, items, item_flags,
7388 tunnel != 0, error);
7393 return rte_flow_error_set(error, ENOTSUP,
7394 RTE_FLOW_ERROR_TYPE_ITEM,
7395 NULL, "item not supported");
7397 item_flags |= last_item;
7399 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
7400 ret = flow_dv_validate_item_integrity_post(integrity_items,
7405 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
7406 int type = actions->type;
7408 if (!mlx5_flow_os_action_supported(type))
7409 return rte_flow_error_set(error, ENOTSUP,
7410 RTE_FLOW_ERROR_TYPE_ACTION,
7412 "action not supported");
7413 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
7414 return rte_flow_error_set(error, ENOTSUP,
7415 RTE_FLOW_ERROR_TYPE_ACTION,
7416 actions, "too many actions");
7418 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
7419 return rte_flow_error_set(error, ENOTSUP,
7420 RTE_FLOW_ERROR_TYPE_ACTION,
7421 NULL, "meter action with policy "
7422 "must be the last action");
7424 case RTE_FLOW_ACTION_TYPE_VOID:
7426 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7427 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
7428 ret = flow_dv_validate_action_port_id(dev,
7435 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7438 case RTE_FLOW_ACTION_TYPE_FLAG:
7439 ret = flow_dv_validate_action_flag(dev, action_flags,
7443 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7444 /* Count all modify-header actions as one. */
7445 if (!(action_flags &
7446 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7448 action_flags |= MLX5_FLOW_ACTION_FLAG |
7449 MLX5_FLOW_ACTION_MARK_EXT;
7450 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7451 modify_after_mirror = 1;
7454 action_flags |= MLX5_FLOW_ACTION_FLAG;
7457 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7459 case RTE_FLOW_ACTION_TYPE_MARK:
7460 ret = flow_dv_validate_action_mark(dev, actions,
7465 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7466 /* Count all modify-header actions as one. */
7467 if (!(action_flags &
7468 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7470 action_flags |= MLX5_FLOW_ACTION_MARK |
7471 MLX5_FLOW_ACTION_MARK_EXT;
7472 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7473 modify_after_mirror = 1;
7475 action_flags |= MLX5_FLOW_ACTION_MARK;
7478 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7480 case RTE_FLOW_ACTION_TYPE_SET_META:
7481 ret = flow_dv_validate_action_set_meta(dev, actions,
7486 /* Count all modify-header actions as one action. */
7487 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7489 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7490 modify_after_mirror = 1;
7491 action_flags |= MLX5_FLOW_ACTION_SET_META;
7492 rw_act_num += MLX5_ACT_NUM_SET_META;
7494 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7495 ret = flow_dv_validate_action_set_tag(dev, actions,
7500 /* Count all modify-header actions as one action. */
7501 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7503 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7504 modify_after_mirror = 1;
7505 tag_id = ((const struct rte_flow_action_set_tag *)
7506 actions->conf)->index;
7507 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7508 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7510 case RTE_FLOW_ACTION_TYPE_DROP:
7511 ret = mlx5_flow_validate_action_drop(action_flags,
7515 action_flags |= MLX5_FLOW_ACTION_DROP;
7518 case RTE_FLOW_ACTION_TYPE_QUEUE:
7519 ret = mlx5_flow_validate_action_queue(actions,
7524 queue_index = ((const struct rte_flow_action_queue *)
7525 (actions->conf))->index;
7526 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7529 case RTE_FLOW_ACTION_TYPE_RSS:
7530 rss = actions->conf;
7531 ret = mlx5_flow_validate_action_rss(actions,
7537 if (rss && sample_rss &&
7538 (sample_rss->level != rss->level ||
7539 sample_rss->types != rss->types))
7540 return rte_flow_error_set(error, ENOTSUP,
7541 RTE_FLOW_ERROR_TYPE_ACTION,
7543 "Can't use the different RSS types "
7544 "or level in the same flow");
7545 if (rss != NULL && rss->queue_num)
7546 queue_index = rss->queue[0];
7547 action_flags |= MLX5_FLOW_ACTION_RSS;
7550 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7552 mlx5_flow_validate_action_default_miss(action_flags,
7556 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
7559 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
7560 shared_count = true;
7562 case RTE_FLOW_ACTION_TYPE_COUNT:
7563 ret = flow_dv_validate_action_count(dev, shared_count,
7568 count = actions->conf;
7569 action_flags |= MLX5_FLOW_ACTION_COUNT;
7572 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7573 if (flow_dv_validate_action_pop_vlan(dev,
7579 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7580 modify_after_mirror = 1;
7581 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7584 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7585 ret = flow_dv_validate_action_push_vlan(dev,
7592 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7593 modify_after_mirror = 1;
7594 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7597 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7598 ret = flow_dv_validate_action_set_vlan_pcp
7599 (action_flags, actions, error);
7602 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7603 modify_after_mirror = 1;
7604 /* Count PCP with push_vlan command. */
7605 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
7607 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7608 ret = flow_dv_validate_action_set_vlan_vid
7609 (item_flags, action_flags,
7613 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7614 modify_after_mirror = 1;
7615 /* Count VID with push_vlan command. */
7616 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7617 rw_act_num += MLX5_ACT_NUM_MDF_VID;
7619 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7620 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7621 ret = flow_dv_validate_action_l2_encap(dev,
7627 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7630 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7631 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7632 ret = flow_dv_validate_action_decap(dev, action_flags,
7633 actions, item_flags,
7637 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7638 modify_after_mirror = 1;
7639 action_flags |= MLX5_FLOW_ACTION_DECAP;
7642 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7643 ret = flow_dv_validate_action_raw_encap_decap
7644 (dev, NULL, actions->conf, attr, &action_flags,
7645 &actions_n, actions, item_flags, error);
7649 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7650 decap = actions->conf;
7651 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
7653 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7657 encap = actions->conf;
7659 ret = flow_dv_validate_action_raw_encap_decap
7661 decap ? decap : &empty_decap, encap,
7662 attr, &action_flags, &actions_n,
7663 actions, item_flags, error);
7666 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7667 (action_flags & MLX5_FLOW_ACTION_DECAP))
7668 modify_after_mirror = 1;
7670 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7671 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7672 ret = flow_dv_validate_action_modify_mac(action_flags,
7678 /* Count all modify-header actions as one action. */
7679 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7681 action_flags |= actions->type ==
7682 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7683 MLX5_FLOW_ACTION_SET_MAC_SRC :
7684 MLX5_FLOW_ACTION_SET_MAC_DST;
7685 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7686 modify_after_mirror = 1;
7688 * Even if the source and destination MAC addresses have
7689 * overlap in the header with 4B alignment, the convert
7690 * function will handle them separately and 4 SW actions
7691 * will be created. And 2 actions will be added each
7692 * time no matter how many bytes of address will be set.
7694 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
7696 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7697 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7698 ret = flow_dv_validate_action_modify_ipv4(action_flags,
7704 /* Count all modify-header actions as one action. */
7705 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7707 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7708 modify_after_mirror = 1;
7709 action_flags |= actions->type ==
7710 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7711 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7712 MLX5_FLOW_ACTION_SET_IPV4_DST;
7713 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
7715 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7716 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7717 ret = flow_dv_validate_action_modify_ipv6(action_flags,
7723 if (item_ipv6_proto == IPPROTO_ICMPV6)
7724 return rte_flow_error_set(error, ENOTSUP,
7725 RTE_FLOW_ERROR_TYPE_ACTION,
7727 "Can't change header "
7728 "with ICMPv6 proto");
7729 /* Count all modify-header actions as one action. */
7730 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7732 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7733 modify_after_mirror = 1;
7734 action_flags |= actions->type ==
7735 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7736 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7737 MLX5_FLOW_ACTION_SET_IPV6_DST;
7738 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
7740 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7741 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7742 ret = flow_dv_validate_action_modify_tp(action_flags,
7748 /* Count all modify-header actions as one action. */
7749 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7751 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7752 modify_after_mirror = 1;
7753 action_flags |= actions->type ==
7754 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7755 MLX5_FLOW_ACTION_SET_TP_SRC :
7756 MLX5_FLOW_ACTION_SET_TP_DST;
7757 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
7759 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7760 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7761 ret = flow_dv_validate_action_modify_ttl(action_flags,
7767 /* Count all modify-header actions as one action. */
7768 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7770 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7771 modify_after_mirror = 1;
7772 action_flags |= actions->type ==
7773 RTE_FLOW_ACTION_TYPE_SET_TTL ?
7774 MLX5_FLOW_ACTION_SET_TTL :
7775 MLX5_FLOW_ACTION_DEC_TTL;
7776 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
7778 case RTE_FLOW_ACTION_TYPE_JUMP:
7779 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
7785 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7787 return rte_flow_error_set(error, EINVAL,
7788 RTE_FLOW_ERROR_TYPE_ACTION,
7790 "sample and jump action combination is not supported");
7792 action_flags |= MLX5_FLOW_ACTION_JUMP;
7794 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7795 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7796 ret = flow_dv_validate_action_modify_tcp_seq
7803 /* Count all modify-header actions as one action. */
7804 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7806 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7807 modify_after_mirror = 1;
7808 action_flags |= actions->type ==
7809 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7810 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7811 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7812 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
7814 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7815 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7816 ret = flow_dv_validate_action_modify_tcp_ack
7823 /* Count all modify-header actions as one action. */
7824 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7826 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7827 modify_after_mirror = 1;
7828 action_flags |= actions->type ==
7829 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7830 MLX5_FLOW_ACTION_INC_TCP_ACK :
7831 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7832 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
7834 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7836 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7837 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7838 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7840 case RTE_FLOW_ACTION_TYPE_METER:
7841 ret = mlx5_flow_validate_action_meter(dev,
7850 action_flags |= MLX5_FLOW_ACTION_METER;
7853 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
7855 /* Meter action will add one more TAG action. */
7856 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7858 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
7859 if (!attr->transfer && !attr->group)
7860 return rte_flow_error_set(error, ENOTSUP,
7861 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7863 "Shared ASO age action is not supported for group 0");
7864 if (action_flags & MLX5_FLOW_ACTION_AGE)
7865 return rte_flow_error_set
7867 RTE_FLOW_ERROR_TYPE_ACTION,
7869 "duplicate age actions set");
7870 action_flags |= MLX5_FLOW_ACTION_AGE;
7873 case RTE_FLOW_ACTION_TYPE_AGE:
7874 non_shared_age = actions->conf;
7875 ret = flow_dv_validate_action_age(action_flags,
7881 * Validate the regular AGE action (using counter)
7882 * mutual exclusion with indirect counter actions.
7884 if (!flow_hit_aso_supported(priv->sh, attr)) {
7886 return rte_flow_error_set
7888 RTE_FLOW_ERROR_TYPE_ACTION,
7890 "old age and indirect count combination is not supported");
7892 return rte_flow_error_set
7894 RTE_FLOW_ERROR_TYPE_ACTION,
7896 "old age action and count must be in the same sub flow");
7898 action_flags |= MLX5_FLOW_ACTION_AGE;
7901 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7902 ret = flow_dv_validate_action_modify_ipv4_dscp
7909 /* Count all modify-header actions as one action. */
7910 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7912 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7913 modify_after_mirror = 1;
7914 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7915 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7917 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7918 ret = flow_dv_validate_action_modify_ipv6_dscp
7925 /* Count all modify-header actions as one action. */
7926 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7928 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7929 modify_after_mirror = 1;
7930 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7931 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7933 case RTE_FLOW_ACTION_TYPE_SAMPLE:
7934 ret = flow_dv_validate_action_sample(&action_flags,
7943 if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) &&
7944 tag_id == 0 && priv->mtr_color_reg == REG_NON)
7945 return rte_flow_error_set(error, EINVAL,
7946 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7947 "sample after tag action causes metadata tag index 0 corruption");
7948 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
7951 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7952 ret = flow_dv_validate_action_modify_field(dev,
7959 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7960 modify_after_mirror = 1;
7961 /* Count all modify-header actions as one action. */
7962 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7964 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
7967 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7968 ret = flow_dv_validate_action_aso_ct(dev, action_flags,
7973 action_flags |= MLX5_FLOW_ACTION_CT;
7975 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
7976 /* tunnel offload action was processed before
7977 * list it here as a supported type
7981 return rte_flow_error_set(error, ENOTSUP,
7982 RTE_FLOW_ERROR_TYPE_ACTION,
7984 "action not supported");
7988 * Validate actions in flow rules
7989 * - Explicit decap action is prohibited by the tunnel offload API.
7990 * - Drop action in tunnel steer rule is prohibited by the API.
7991 * - Application cannot use MARK action because it's value can mask
7992 * tunnel default miss notification.
7993 * - JUMP in tunnel match rule has no support in current PMD
7995 * - TAG & META are reserved for future uses.
7997 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
7998 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
7999 MLX5_FLOW_ACTION_MARK |
8000 MLX5_FLOW_ACTION_SET_TAG |
8001 MLX5_FLOW_ACTION_SET_META |
8002 MLX5_FLOW_ACTION_DROP;
8004 if (action_flags & bad_actions_mask)
8005 return rte_flow_error_set
8007 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8008 "Invalid RTE action in tunnel "
8010 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
8011 return rte_flow_error_set
8013 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8014 "tunnel set decap rule must terminate "
8017 return rte_flow_error_set
8019 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8020 "tunnel flows for ingress traffic only");
8022 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
8023 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
8024 MLX5_FLOW_ACTION_MARK |
8025 MLX5_FLOW_ACTION_SET_TAG |
8026 MLX5_FLOW_ACTION_SET_META;
8028 if (action_flags & bad_actions_mask)
8029 return rte_flow_error_set
8031 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8032 "Invalid RTE action in tunnel "
8036 * Validate the drop action mutual exclusion with other actions.
8037 * Drop action is mutually-exclusive with any other action, except for
8039 * Drop action compatibility with tunnel offload was already validated.
8041 if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
8042 MLX5_FLOW_ACTION_TUNNEL_MATCH));
8043 else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
8044 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
8045 return rte_flow_error_set(error, EINVAL,
8046 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8047 "Drop action is mutually-exclusive "
8048 "with any other action, except for "
8050 /* Eswitch has few restrictions on using items and actions */
8051 if (attr->transfer) {
8052 if (!mlx5_flow_ext_mreg_supported(dev) &&
8053 action_flags & MLX5_FLOW_ACTION_FLAG)
8054 return rte_flow_error_set(error, ENOTSUP,
8055 RTE_FLOW_ERROR_TYPE_ACTION,
8057 "unsupported action FLAG");
8058 if (!mlx5_flow_ext_mreg_supported(dev) &&
8059 action_flags & MLX5_FLOW_ACTION_MARK)
8060 return rte_flow_error_set(error, ENOTSUP,
8061 RTE_FLOW_ERROR_TYPE_ACTION,
8063 "unsupported action MARK");
8064 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
8065 return rte_flow_error_set(error, ENOTSUP,
8066 RTE_FLOW_ERROR_TYPE_ACTION,
8068 "unsupported action QUEUE");
8069 if (action_flags & MLX5_FLOW_ACTION_RSS)
8070 return rte_flow_error_set(error, ENOTSUP,
8071 RTE_FLOW_ERROR_TYPE_ACTION,
8073 "unsupported action RSS");
8074 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
8075 return rte_flow_error_set(error, EINVAL,
8076 RTE_FLOW_ERROR_TYPE_ACTION,
8078 "no fate action is found");
8080 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
8081 return rte_flow_error_set(error, EINVAL,
8082 RTE_FLOW_ERROR_TYPE_ACTION,
8084 "no fate action is found");
8087 * Continue validation for Xcap and VLAN actions.
8088 * If hairpin is working in explicit TX rule mode, there is no actions
8089 * splitting and the validation of hairpin ingress flow should be the
8090 * same as other standard flows.
8092 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
8093 MLX5_FLOW_VLAN_ACTIONS)) &&
8094 (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index) ||
8095 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
8096 conf->tx_explicit != 0))) {
8097 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
8098 MLX5_FLOW_XCAP_ACTIONS)
8099 return rte_flow_error_set(error, ENOTSUP,
8100 RTE_FLOW_ERROR_TYPE_ACTION,
8101 NULL, "encap and decap "
8102 "combination aren't supported");
8103 /* Push VLAN is not supported in ingress except for NICs newer than CX5. */
8104 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
8105 struct mlx5_dev_ctx_shared *sh = priv->sh;
8106 bool direction_error = false;
8108 if (attr->transfer) {
8109 bool fdb_tx = priv->representor_id != UINT16_MAX;
8110 bool is_cx5 = sh->steering_format_version ==
8111 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
8113 if (!fdb_tx && is_cx5)
8114 direction_error = true;
8115 } else if (attr->ingress) {
8116 direction_error = true;
8118 if (direction_error)
8119 return rte_flow_error_set(error, ENOTSUP,
8120 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
8122 "push VLAN action not supported "
8125 if (!attr->transfer && attr->ingress) {
8126 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
8127 return rte_flow_error_set
8129 RTE_FLOW_ERROR_TYPE_ACTION,
8130 NULL, "encap is not supported"
8131 " for ingress traffic");
8132 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
8133 MLX5_FLOW_VLAN_ACTIONS)
8134 return rte_flow_error_set
8136 RTE_FLOW_ERROR_TYPE_ACTION,
8137 NULL, "no support for "
8138 "multiple VLAN actions");
8141 if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
8142 if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
8143 ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
8145 return rte_flow_error_set
8147 RTE_FLOW_ERROR_TYPE_ACTION,
8148 NULL, "fate action not supported for "
8149 "meter with policy");
8151 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
8152 return rte_flow_error_set
8154 RTE_FLOW_ERROR_TYPE_ACTION,
8155 NULL, "modify header action in egress "
8156 "cannot be done before meter action");
8157 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
8158 return rte_flow_error_set
8160 RTE_FLOW_ERROR_TYPE_ACTION,
8161 NULL, "encap action in egress "
8162 "cannot be done before meter action");
8163 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
8164 return rte_flow_error_set
8166 RTE_FLOW_ERROR_TYPE_ACTION,
8167 NULL, "push vlan action in egress "
8168 "cannot be done before meter action");
8172 * Only support one ASO action in a single flow rule.
8173 * non-shared AGE + counter will fallback to use HW counter, no ASO hit object.
8174 * Group 0 uses HW counter for AGE too even if no counter action.
8176 aso_mask = (action_flags & MLX5_FLOW_ACTION_METER && priv->sh->meter_aso_en) << 2 |
8177 (action_flags & MLX5_FLOW_ACTION_CT && priv->sh->ct_aso_en) << 1 |
8178 (action_flags & MLX5_FLOW_ACTION_AGE &&
8179 !(non_shared_age && count) &&
8180 (attr->group || (attr->transfer && priv->fdb_def_rule)) &&
8181 priv->sh->flow_hit_aso_en);
8182 if (__builtin_popcountl(aso_mask) > 1)
8183 return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
8184 NULL, "unsupported combining AGE, METER, CT ASO actions in a single rule");
8186 * Hairpin flow will add one more TAG action in TX implicit mode.
8187 * In TX explicit mode, there will be no hairpin flow ID.
8190 rw_act_num += MLX5_ACT_NUM_SET_TAG;
8191 /* extra metadata enabled: one more TAG action will be add. */
8192 if (dev_conf->dv_flow_en &&
8193 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
8194 mlx5_flow_ext_mreg_supported(dev))
8195 rw_act_num += MLX5_ACT_NUM_SET_TAG;
8197 flow_dv_modify_hdr_action_max(dev, is_root)) {
8198 return rte_flow_error_set(error, ENOTSUP,
8199 RTE_FLOW_ERROR_TYPE_ACTION,
8200 NULL, "too many header modify"
8201 " actions to support");
8203 /* Eswitch egress mirror and modify flow has limitation on CX5 */
8204 if (fdb_mirror_limit && modify_after_mirror)
8205 return rte_flow_error_set(error, EINVAL,
8206 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8207 "sample before modify action is not supported");
8209 * Validation the NIC Egress flow on representor, except implicit
8210 * hairpin default egress flow with TX_QUEUE item, other flows not
8211 * work due to metadata regC0 mismatch.
8213 if ((!attr->transfer && attr->egress) && priv->representor &&
8214 !(item_flags & MLX5_FLOW_ITEM_TX_QUEUE))
8215 return rte_flow_error_set(error, EINVAL,
8216 RTE_FLOW_ERROR_TYPE_ITEM,
8218 "NIC egress rules on representors"
8219 " is not supported");
8224 * Internal preparation function. Allocates the DV flow size,
8225 * this size is constant.
8228 * Pointer to the rte_eth_dev structure.
8230 * Pointer to the flow attributes.
8232 * Pointer to the list of items.
8233 * @param[in] actions
8234 * Pointer to the list of actions.
8236 * Pointer to the error structure.
8239 * Pointer to mlx5_flow object on success,
8240 * otherwise NULL and rte_errno is set.
8242 static struct mlx5_flow *
8243 flow_dv_prepare(struct rte_eth_dev *dev,
8244 const struct rte_flow_attr *attr __rte_unused,
8245 const struct rte_flow_item items[] __rte_unused,
8246 const struct rte_flow_action actions[] __rte_unused,
8247 struct rte_flow_error *error)
8249 uint32_t handle_idx = 0;
8250 struct mlx5_flow *dev_flow;
8251 struct mlx5_flow_handle *dev_handle;
8252 struct mlx5_priv *priv = dev->data->dev_private;
8253 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
8256 wks->skip_matcher_reg = 0;
8258 wks->final_policy = NULL;
8259 /* In case of corrupting the memory. */
8260 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
8261 rte_flow_error_set(error, ENOSPC,
8262 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8263 "not free temporary device flow");
8266 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8269 rte_flow_error_set(error, ENOMEM,
8270 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8271 "not enough memory to create flow handle");
8274 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
8275 dev_flow = &wks->flows[wks->flow_idx++];
8276 memset(dev_flow, 0, sizeof(*dev_flow));
8277 dev_flow->handle = dev_handle;
8278 dev_flow->handle_idx = handle_idx;
8279 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
8280 dev_flow->ingress = attr->ingress;
8281 dev_flow->dv.transfer = attr->transfer;
8285 #ifdef RTE_LIBRTE_MLX5_DEBUG
8287 * Sanity check for match mask and value. Similar to check_valid_spec() in
8288 * kernel driver. If unmasked bit is present in value, it returns failure.
8291 * pointer to match mask buffer.
8292 * @param match_value
8293 * pointer to match value buffer.
8296 * 0 if valid, -EINVAL otherwise.
8299 flow_dv_check_valid_spec(void *match_mask, void *match_value)
8301 uint8_t *m = match_mask;
8302 uint8_t *v = match_value;
8305 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
8308 "match_value differs from match_criteria"
8309 " %p[%u] != %p[%u]",
8310 match_value, i, match_mask, i);
8319 * Add match of ip_version.
8323 * @param[in] headers_v
8324 * Values header pointer.
8325 * @param[in] headers_m
8326 * Masks header pointer.
8327 * @param[in] ip_version
8328 * The IP version to set.
8331 flow_dv_set_match_ip_version(uint32_t group,
8337 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
8339 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
8341 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
8342 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
8343 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
8347 * Add Ethernet item to matcher and to the value.
8349 * @param[in, out] matcher
8351 * @param[in, out] key
8352 * Flow matcher value.
8354 * Flow pattern to translate.
8356 * Item is inner pattern.
8359 flow_dv_translate_item_eth(void *matcher, void *key,
8360 const struct rte_flow_item *item, int inner,
8363 const struct rte_flow_item_eth *eth_m = item->mask;
8364 const struct rte_flow_item_eth *eth_v = item->spec;
8365 const struct rte_flow_item_eth nic_mask = {
8366 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8367 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8368 .type = RTE_BE16(0xffff),
8381 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8383 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8385 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8387 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8389 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
8390 ð_m->dst, sizeof(eth_m->dst));
8391 /* The value must be in the range of the mask. */
8392 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
8393 for (i = 0; i < sizeof(eth_m->dst); ++i)
8394 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
8395 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
8396 ð_m->src, sizeof(eth_m->src));
8397 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
8398 /* The value must be in the range of the mask. */
8399 for (i = 0; i < sizeof(eth_m->dst); ++i)
8400 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
8402 * HW supports match on one Ethertype, the Ethertype following the last
8403 * VLAN tag of the packet (see PRM).
8404 * Set match on ethertype only if ETH header is not followed by VLAN.
8405 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8406 * ethertype, and use ip_version field instead.
8407 * eCPRI over Ether layer will use type value 0xAEFE.
8409 if (eth_m->type == 0xFFFF) {
8410 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
8411 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8412 switch (eth_v->type) {
8413 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8414 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8416 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
8417 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8418 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8420 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8421 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8423 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8424 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8430 if (eth_m->has_vlan) {
8431 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8432 if (eth_v->has_vlan) {
8434 * Here, when also has_more_vlan field in VLAN item is
8435 * not set, only single-tagged packets will be matched.
8437 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8441 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8442 rte_be_to_cpu_16(eth_m->type));
8443 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
8444 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
8448 * Add VLAN item to matcher and to the value.
8450 * @param[in, out] dev_flow
8452 * @param[in, out] matcher
8454 * @param[in, out] key
8455 * Flow matcher value.
8457 * Flow pattern to translate.
8459 * Item is inner pattern.
8462 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
8463 void *matcher, void *key,
8464 const struct rte_flow_item *item,
8465 int inner, uint32_t group)
8467 const struct rte_flow_item_vlan *vlan_m = item->mask;
8468 const struct rte_flow_item_vlan *vlan_v = item->spec;
8475 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8477 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8479 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8481 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8483 * This is workaround, masks are not supported,
8484 * and pre-validated.
8487 dev_flow->handle->vf_vlan.tag =
8488 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
8491 * When VLAN item exists in flow, mark packet as tagged,
8492 * even if TCI is not specified.
8494 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
8495 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8496 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8501 vlan_m = &rte_flow_item_vlan_mask;
8502 tci_m = rte_be_to_cpu_16(vlan_m->tci);
8503 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
8504 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
8505 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
8506 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
8507 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
8508 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
8509 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
8511 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8512 * ethertype, and use ip_version field instead.
8514 if (vlan_m->inner_type == 0xFFFF) {
8515 switch (vlan_v->inner_type) {
8516 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8517 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8518 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8519 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8521 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8522 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8524 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8525 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8531 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
8532 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8533 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8534 /* Only one vlan_tag bit can be set. */
8535 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8538 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8539 rte_be_to_cpu_16(vlan_m->inner_type));
8540 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
8541 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
8545 * Add IPV4 item to matcher and to the value.
8547 * @param[in, out] matcher
8549 * @param[in, out] key
8550 * Flow matcher value.
8552 * Flow pattern to translate.
8554 * Item is inner pattern.
8556 * The group to insert the rule.
8559 flow_dv_translate_item_ipv4(void *matcher, void *key,
8560 const struct rte_flow_item *item,
8561 int inner, uint32_t group)
8563 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
8564 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
8565 const struct rte_flow_item_ipv4 nic_mask = {
8567 .src_addr = RTE_BE32(0xffffffff),
8568 .dst_addr = RTE_BE32(0xffffffff),
8569 .type_of_service = 0xff,
8570 .next_proto_id = 0xff,
8571 .time_to_live = 0xff,
8578 uint8_t tos, ihl_m, ihl_v;
8581 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8583 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8585 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8587 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8589 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
8594 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8595 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8596 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8597 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8598 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
8599 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
8600 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8601 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8602 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8603 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8604 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
8605 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
8606 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
8607 ihl_m = ipv4_m->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8608 ihl_v = ipv4_v->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8609 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_ihl, ihl_m);
8610 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl, ihl_m & ihl_v);
8611 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
8612 ipv4_m->hdr.type_of_service);
8613 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
8614 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
8615 ipv4_m->hdr.type_of_service >> 2);
8616 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
8617 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8618 ipv4_m->hdr.next_proto_id);
8619 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8620 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
8621 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8622 ipv4_m->hdr.time_to_live);
8623 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8624 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
8625 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8626 !!(ipv4_m->hdr.fragment_offset));
8627 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8628 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
8632 * Add IPV6 item to matcher and to the value.
8634 * @param[in, out] matcher
8636 * @param[in, out] key
8637 * Flow matcher value.
8639 * Flow pattern to translate.
8641 * Item is inner pattern.
8643 * The group to insert the rule.
8646 flow_dv_translate_item_ipv6(void *matcher, void *key,
8647 const struct rte_flow_item *item,
8648 int inner, uint32_t group)
8650 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
8651 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
8652 const struct rte_flow_item_ipv6 nic_mask = {
8655 "\xff\xff\xff\xff\xff\xff\xff\xff"
8656 "\xff\xff\xff\xff\xff\xff\xff\xff",
8658 "\xff\xff\xff\xff\xff\xff\xff\xff"
8659 "\xff\xff\xff\xff\xff\xff\xff\xff",
8660 .vtc_flow = RTE_BE32(0xffffffff),
8667 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8668 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8677 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8679 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8681 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8683 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8685 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
8690 size = sizeof(ipv6_m->hdr.dst_addr);
8691 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8692 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8693 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8694 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8695 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
8696 for (i = 0; i < size; ++i)
8697 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
8698 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8699 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8700 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8701 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8702 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
8703 for (i = 0; i < size; ++i)
8704 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
8706 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
8707 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
8708 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
8709 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
8710 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
8711 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
8714 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
8716 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
8719 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
8721 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
8725 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8727 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8728 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
8730 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8731 ipv6_m->hdr.hop_limits);
8732 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8733 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
8734 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8735 !!(ipv6_m->has_frag_ext));
8736 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8737 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
8741 * Add IPV6 fragment extension item to matcher and to the value.
8743 * @param[in, out] matcher
8745 * @param[in, out] key
8746 * Flow matcher value.
8748 * Flow pattern to translate.
8750 * Item is inner pattern.
8753 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
8754 const struct rte_flow_item *item,
8757 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
8758 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
8759 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
8761 .next_header = 0xff,
8762 .frag_data = RTE_BE16(0xffff),
8769 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8771 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8773 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8775 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8777 /* IPv6 fragment extension item exists, so packet is IP fragment. */
8778 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
8779 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
8780 if (!ipv6_frag_ext_v)
8782 if (!ipv6_frag_ext_m)
8783 ipv6_frag_ext_m = &nic_mask;
8784 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8785 ipv6_frag_ext_m->hdr.next_header);
8786 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8787 ipv6_frag_ext_v->hdr.next_header &
8788 ipv6_frag_ext_m->hdr.next_header);
8792 * Add TCP item to matcher and to the value.
8794 * @param[in, out] matcher
8796 * @param[in, out] key
8797 * Flow matcher value.
8799 * Flow pattern to translate.
8801 * Item is inner pattern.
8804 flow_dv_translate_item_tcp(void *matcher, void *key,
8805 const struct rte_flow_item *item,
8808 const struct rte_flow_item_tcp *tcp_m = item->mask;
8809 const struct rte_flow_item_tcp *tcp_v = item->spec;
8814 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8816 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8818 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8820 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8822 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8823 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
8827 tcp_m = &rte_flow_item_tcp_mask;
8828 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
8829 rte_be_to_cpu_16(tcp_m->hdr.src_port));
8830 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
8831 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
8832 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
8833 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
8834 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
8835 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
8836 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
8837 tcp_m->hdr.tcp_flags);
8838 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
8839 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
8843 * Add ESP item to matcher and to the value.
8845 * @param[in, out] matcher
8847 * @param[in, out] key
8848 * Flow matcher value.
8850 * Flow pattern to translate.
8852 * Item is inner pattern.
8855 flow_dv_translate_item_esp(void *matcher, void *key,
8856 const struct rte_flow_item *item,
8859 const struct rte_flow_item_esp *esp_m = item->mask;
8860 const struct rte_flow_item_esp *esp_v = item->spec;
8867 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8869 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8871 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8873 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8875 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8876 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ESP);
8880 esp_m = &rte_flow_item_esp_mask;
8881 headers_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8882 headers_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8884 spi_m = MLX5_ADDR_OF(fte_match_set_misc, headers_m, inner_esp_spi);
8885 spi_v = MLX5_ADDR_OF(fte_match_set_misc, headers_v, inner_esp_spi);
8887 spi_m = MLX5_ADDR_OF(fte_match_set_misc, headers_m, outer_esp_spi);
8888 spi_v = MLX5_ADDR_OF(fte_match_set_misc, headers_v, outer_esp_spi);
8890 *(uint32_t *)spi_m = esp_m->hdr.spi;
8891 *(uint32_t *)spi_v = esp_m->hdr.spi & esp_v->hdr.spi;
8895 * Add UDP item to matcher and to the value.
8897 * @param[in, out] matcher
8899 * @param[in, out] key
8900 * Flow matcher value.
8902 * Flow pattern to translate.
8904 * Item is inner pattern.
8907 flow_dv_translate_item_udp(void *matcher, void *key,
8908 const struct rte_flow_item *item,
8911 const struct rte_flow_item_udp *udp_m = item->mask;
8912 const struct rte_flow_item_udp *udp_v = item->spec;
8917 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8919 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8921 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8923 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8925 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8926 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
8930 udp_m = &rte_flow_item_udp_mask;
8931 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
8932 rte_be_to_cpu_16(udp_m->hdr.src_port));
8933 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
8934 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
8935 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
8936 rte_be_to_cpu_16(udp_m->hdr.dst_port));
8937 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8938 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
8942 * Add GRE optional Key item to matcher and to the value.
8944 * @param[in, out] matcher
8946 * @param[in, out] key
8947 * Flow matcher value.
8949 * Flow pattern to translate.
8951 * Item is inner pattern.
8954 flow_dv_translate_item_gre_key(void *matcher, void *key,
8955 const struct rte_flow_item *item)
8957 const rte_be32_t *key_m = item->mask;
8958 const rte_be32_t *key_v = item->spec;
8959 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8960 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8961 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
8963 /* GRE K bit must be on and should already be validated */
8964 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
8965 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
8969 key_m = &gre_key_default_mask;
8970 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
8971 rte_be_to_cpu_32(*key_m) >> 8);
8972 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
8973 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
8974 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
8975 rte_be_to_cpu_32(*key_m) & 0xFF);
8976 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
8977 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
8981 * Add GRE item to matcher and to the value.
8983 * @param[in, out] matcher
8985 * @param[in, out] key
8986 * Flow matcher value.
8988 * Flow pattern to translate.
8989 * @param[in] pattern_flags
8990 * Accumulated pattern flags.
8993 flow_dv_translate_item_gre(void *matcher, void *key,
8994 const struct rte_flow_item *item,
8995 uint64_t pattern_flags)
8997 static const struct rte_flow_item_gre empty_gre = {0,};
8998 const struct rte_flow_item_gre *gre_m = item->mask;
8999 const struct rte_flow_item_gre *gre_v = item->spec;
9000 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9001 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9002 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9003 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9010 uint16_t s_present:1;
9011 uint16_t k_present:1;
9012 uint16_t rsvd_bit1:1;
9013 uint16_t c_present:1;
9017 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
9018 uint16_t protocol_m, protocol_v;
9020 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
9021 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
9027 gre_m = &rte_flow_item_gre_mask;
9029 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
9030 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
9031 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
9032 gre_crks_rsvd0_ver_m.c_present);
9033 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
9034 gre_crks_rsvd0_ver_v.c_present &
9035 gre_crks_rsvd0_ver_m.c_present);
9036 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
9037 gre_crks_rsvd0_ver_m.k_present);
9038 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
9039 gre_crks_rsvd0_ver_v.k_present &
9040 gre_crks_rsvd0_ver_m.k_present);
9041 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
9042 gre_crks_rsvd0_ver_m.s_present);
9043 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
9044 gre_crks_rsvd0_ver_v.s_present &
9045 gre_crks_rsvd0_ver_m.s_present);
9046 protocol_m = rte_be_to_cpu_16(gre_m->protocol);
9047 protocol_v = rte_be_to_cpu_16(gre_v->protocol);
9049 /* Force next protocol to prevent matchers duplication */
9050 protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9052 protocol_m = 0xFFFF;
9054 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, protocol_m);
9055 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9056 protocol_m & protocol_v);
9060 * Add GRE optional items to matcher and to the value.
9062 * @param[in, out] matcher
9064 * @param[in, out] key
9065 * Flow matcher value.
9067 * Flow pattern to translate.
9068 * @param[in] gre_item
9069 * Pointer to gre_item.
9070 * @param[in] pattern_flags
9071 * Accumulated pattern flags.
9074 flow_dv_translate_item_gre_option(void *matcher, void *key,
9075 const struct rte_flow_item *item,
9076 const struct rte_flow_item *gre_item,
9077 uint64_t pattern_flags)
9079 const struct rte_flow_item_gre_opt *option_m = item->mask;
9080 const struct rte_flow_item_gre_opt *option_v = item->spec;
9081 const struct rte_flow_item_gre *gre_m = gre_item->mask;
9082 const struct rte_flow_item_gre *gre_v = gre_item->spec;
9083 static const struct rte_flow_item_gre empty_gre = {0};
9084 struct rte_flow_item gre_key_item;
9085 uint16_t c_rsvd0_ver_m, c_rsvd0_ver_v;
9086 uint16_t protocol_m, protocol_v;
9091 * If only match key field, keep using misc for matching.
9092 * If need to match checksum or sequence, using misc5 and do
9093 * not need using misc.
9095 if (!(option_m->sequence.sequence ||
9096 option_m->checksum_rsvd.checksum)) {
9097 flow_dv_translate_item_gre(matcher, key, gre_item,
9099 gre_key_item.spec = &option_v->key.key;
9100 gre_key_item.mask = &option_m->key.key;
9101 flow_dv_translate_item_gre_key(matcher, key, &gre_key_item);
9109 gre_m = &rte_flow_item_gre_mask;
9111 protocol_v = gre_v->protocol;
9112 protocol_m = gre_m->protocol;
9114 /* Force next protocol to prevent matchers duplication */
9115 uint16_t ether_type =
9116 mlx5_translate_tunnel_etypes(pattern_flags);
9118 protocol_v = rte_be_to_cpu_16(ether_type);
9119 protocol_m = UINT16_MAX;
9122 c_rsvd0_ver_v = gre_v->c_rsvd0_ver;
9123 c_rsvd0_ver_m = gre_m->c_rsvd0_ver;
9124 if (option_m->sequence.sequence) {
9125 c_rsvd0_ver_v |= RTE_BE16(0x1000);
9126 c_rsvd0_ver_m |= RTE_BE16(0x1000);
9128 if (option_m->key.key) {
9129 c_rsvd0_ver_v |= RTE_BE16(0x2000);
9130 c_rsvd0_ver_m |= RTE_BE16(0x2000);
9132 if (option_m->checksum_rsvd.checksum) {
9133 c_rsvd0_ver_v |= RTE_BE16(0x8000);
9134 c_rsvd0_ver_m |= RTE_BE16(0x8000);
9137 * Hardware parses GRE optional field into the fixed location,
9138 * do not need to adjust the tunnel dword indices.
9140 misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9141 misc5_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_5);
9142 MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0,
9143 rte_be_to_cpu_32((c_rsvd0_ver_v | protocol_v << 16) &
9144 (c_rsvd0_ver_m | protocol_m << 16)));
9145 MLX5_SET(fte_match_set_misc5, misc5_m, tunnel_header_0,
9146 rte_be_to_cpu_32(c_rsvd0_ver_m | protocol_m << 16));
9147 MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1,
9148 rte_be_to_cpu_32(option_v->checksum_rsvd.checksum &
9149 option_m->checksum_rsvd.checksum));
9150 MLX5_SET(fte_match_set_misc5, misc5_m, tunnel_header_1,
9151 rte_be_to_cpu_32(option_m->checksum_rsvd.checksum));
9152 MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_2,
9153 rte_be_to_cpu_32(option_v->key.key & option_m->key.key));
9154 MLX5_SET(fte_match_set_misc5, misc5_m, tunnel_header_2,
9155 rte_be_to_cpu_32(option_m->key.key));
9156 MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_3,
9157 rte_be_to_cpu_32(option_v->sequence.sequence &
9158 option_m->sequence.sequence));
9159 MLX5_SET(fte_match_set_misc5, misc5_m, tunnel_header_3,
9160 rte_be_to_cpu_32(option_m->sequence.sequence));
9164 * Add NVGRE item to matcher and to the value.
9166 * @param[in, out] matcher
9168 * @param[in, out] key
9169 * Flow matcher value.
9171 * Flow pattern to translate.
9172 * @param[in] pattern_flags
9173 * Accumulated pattern flags.
9176 flow_dv_translate_item_nvgre(void *matcher, void *key,
9177 const struct rte_flow_item *item,
9178 unsigned long pattern_flags)
9180 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
9181 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
9182 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9183 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9184 const char *tni_flow_id_m;
9185 const char *tni_flow_id_v;
9191 /* For NVGRE, GRE header fields must be set with defined values. */
9192 const struct rte_flow_item_gre gre_spec = {
9193 .c_rsvd0_ver = RTE_BE16(0x2000),
9194 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
9196 const struct rte_flow_item_gre gre_mask = {
9197 .c_rsvd0_ver = RTE_BE16(0xB000),
9198 .protocol = RTE_BE16(UINT16_MAX),
9200 const struct rte_flow_item gre_item = {
9205 flow_dv_translate_item_gre(matcher, key, &gre_item, pattern_flags);
9209 nvgre_m = &rte_flow_item_nvgre_mask;
9210 tni_flow_id_m = (const char *)nvgre_m->tni;
9211 tni_flow_id_v = (const char *)nvgre_v->tni;
9212 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
9213 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
9214 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
9215 memcpy(gre_key_m, tni_flow_id_m, size);
9216 for (i = 0; i < size; ++i)
9217 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
9221 * Add VXLAN item to matcher and to the value.
9224 * Pointer to the Ethernet device structure.
9226 * Flow rule attributes.
9227 * @param[in, out] matcher
9229 * @param[in, out] key
9230 * Flow matcher value.
9232 * Flow pattern to translate.
9234 * Item is inner pattern.
9237 flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
9238 const struct rte_flow_attr *attr,
9239 void *matcher, void *key,
9240 const struct rte_flow_item *item,
9243 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
9244 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
9249 uint32_t *tunnel_header_v;
9250 uint32_t *tunnel_header_m;
9252 struct mlx5_priv *priv = dev->data->dev_private;
9253 const struct rte_flow_item_vxlan nic_mask = {
9254 .vni = "\xff\xff\xff",
9259 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9261 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9263 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9265 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9267 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
9268 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
9269 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9270 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9271 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
9273 dport = MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport);
9277 if ((!attr->group && !priv->sh->tunnel_header_0_1) ||
9278 (attr->group && !priv->sh->misc5_cap))
9279 vxlan_m = &rte_flow_item_vxlan_mask;
9281 vxlan_m = &nic_mask;
9283 if ((priv->sh->steering_format_version ==
9284 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
9285 dport != MLX5_UDP_PORT_VXLAN) ||
9286 (!attr->group && !attr->transfer && !priv->sh->tunnel_header_0_1) ||
9287 ((attr->group || attr->transfer) && !priv->sh->misc5_cap)) {
9294 misc_m = MLX5_ADDR_OF(fte_match_param,
9295 matcher, misc_parameters);
9296 misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9297 size = sizeof(vxlan_m->vni);
9298 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
9299 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
9300 memcpy(vni_m, vxlan_m->vni, size);
9301 for (i = 0; i < size; ++i)
9302 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
9305 misc5_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_5);
9306 misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9307 tunnel_header_v = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
9310 tunnel_header_m = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
9313 *tunnel_header_v = (vxlan_v->vni[0] & vxlan_m->vni[0]) |
9314 (vxlan_v->vni[1] & vxlan_m->vni[1]) << 8 |
9315 (vxlan_v->vni[2] & vxlan_m->vni[2]) << 16;
9316 if (*tunnel_header_v)
9317 *tunnel_header_m = vxlan_m->vni[0] |
9318 vxlan_m->vni[1] << 8 |
9319 vxlan_m->vni[2] << 16;
9321 *tunnel_header_m = 0x0;
9322 *tunnel_header_v |= (vxlan_v->rsvd1 & vxlan_m->rsvd1) << 24;
9323 if (vxlan_v->rsvd1 & vxlan_m->rsvd1)
9324 *tunnel_header_m |= vxlan_m->rsvd1 << 24;
9328 * Add VXLAN-GPE item to matcher and to the value.
9330 * @param[in, out] matcher
9332 * @param[in, out] key
9333 * Flow matcher value.
9335 * Flow pattern to translate.
9337 * Item is inner pattern.
9341 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
9342 const struct rte_flow_item *item,
9343 const uint64_t pattern_flags)
9345 static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {0, };
9346 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
9347 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
9348 /* The item was validated to be on the outer side */
9349 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9350 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9352 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
9354 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9356 MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
9358 MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
9359 int i, size = sizeof(vxlan_m->vni);
9360 uint8_t flags_m = 0xff;
9361 uint8_t flags_v = 0xc;
9362 uint8_t m_protocol, v_protocol;
9364 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9365 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9366 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9367 MLX5_UDP_PORT_VXLAN_GPE);
9370 vxlan_v = &dummy_vxlan_gpe_hdr;
9371 vxlan_m = &dummy_vxlan_gpe_hdr;
9374 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
9376 memcpy(vni_m, vxlan_m->vni, size);
9377 for (i = 0; i < size; ++i)
9378 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
9379 if (vxlan_m->flags) {
9380 flags_m = vxlan_m->flags;
9381 flags_v = vxlan_v->flags;
9383 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
9384 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
9385 m_protocol = vxlan_m->protocol;
9386 v_protocol = vxlan_v->protocol;
9388 /* Force next protocol to ensure next headers parsing. */
9389 if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
9390 v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
9391 else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
9392 v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
9393 else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
9394 v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
9398 MLX5_SET(fte_match_set_misc3, misc_m,
9399 outer_vxlan_gpe_next_protocol, m_protocol);
9400 MLX5_SET(fte_match_set_misc3, misc_v,
9401 outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
9405 * Add Geneve item to matcher and to the value.
9407 * @param[in, out] matcher
9409 * @param[in, out] key
9410 * Flow matcher value.
9412 * Flow pattern to translate.
9414 * Item is inner pattern.
9418 flow_dv_translate_item_geneve(void *matcher, void *key,
9419 const struct rte_flow_item *item,
9420 uint64_t pattern_flags)
9422 static const struct rte_flow_item_geneve empty_geneve = {0,};
9423 const struct rte_flow_item_geneve *geneve_m = item->mask;
9424 const struct rte_flow_item_geneve *geneve_v = item->spec;
9425 /* GENEVE flow item validation allows single tunnel item */
9426 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9427 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9428 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9429 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9432 char *vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
9433 char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
9434 size_t size = sizeof(geneve_m->vni), i;
9435 uint16_t protocol_m, protocol_v;
9437 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9438 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9439 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9440 MLX5_UDP_PORT_GENEVE);
9443 geneve_v = &empty_geneve;
9444 geneve_m = &empty_geneve;
9447 geneve_m = &rte_flow_item_geneve_mask;
9449 memcpy(vni_m, geneve_m->vni, size);
9450 for (i = 0; i < size; ++i)
9451 vni_v[i] = vni_m[i] & geneve_v->vni[i];
9452 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
9453 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
9454 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
9455 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9456 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
9457 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9458 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9459 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9460 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9461 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
9462 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9463 protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
9464 protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
9466 /* Force next protocol to prevent matchers duplication */
9467 protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9469 protocol_m = 0xFFFF;
9471 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type, protocol_m);
9472 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
9473 protocol_m & protocol_v);
9477 * Create Geneve TLV option resource.
9479 * @param dev[in, out]
9480 * Pointer to rte_eth_dev structure.
9481 * @param[in, out] tag_be24
9482 * Tag value in big endian then R-shift 8.
9483 * @parm[in, out] dev_flow
9484 * Pointer to the dev_flow.
9486 * pointer to error structure.
9489 * 0 on success otherwise -errno and errno is set.
9493 flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
9494 const struct rte_flow_item *item,
9495 struct rte_flow_error *error)
9497 struct mlx5_priv *priv = dev->data->dev_private;
9498 struct mlx5_dev_ctx_shared *sh = priv->sh;
9499 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
9500 sh->geneve_tlv_option_resource;
9501 struct mlx5_devx_obj *obj;
9502 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9507 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
9508 if (geneve_opt_resource != NULL) {
9509 if (geneve_opt_resource->option_class ==
9510 geneve_opt_v->option_class &&
9511 geneve_opt_resource->option_type ==
9512 geneve_opt_v->option_type &&
9513 geneve_opt_resource->length ==
9514 geneve_opt_v->option_len) {
9515 /* We already have GENEVE TLV option obj allocated. */
9516 __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
9519 ret = rte_flow_error_set(error, ENOMEM,
9520 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9521 "Only one GENEVE TLV option supported");
9525 /* Create a GENEVE TLV object and resource. */
9526 obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
9527 geneve_opt_v->option_class,
9528 geneve_opt_v->option_type,
9529 geneve_opt_v->option_len);
9531 ret = rte_flow_error_set(error, ENODATA,
9532 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9533 "Failed to create GENEVE TLV Devx object");
9536 sh->geneve_tlv_option_resource =
9537 mlx5_malloc(MLX5_MEM_ZERO,
9538 sizeof(*geneve_opt_resource),
9540 if (!sh->geneve_tlv_option_resource) {
9541 claim_zero(mlx5_devx_cmd_destroy(obj));
9542 ret = rte_flow_error_set(error, ENOMEM,
9543 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9544 "GENEVE TLV object memory allocation failed");
9547 geneve_opt_resource = sh->geneve_tlv_option_resource;
9548 geneve_opt_resource->obj = obj;
9549 geneve_opt_resource->option_class = geneve_opt_v->option_class;
9550 geneve_opt_resource->option_type = geneve_opt_v->option_type;
9551 geneve_opt_resource->length = geneve_opt_v->option_len;
9552 __atomic_store_n(&geneve_opt_resource->refcnt, 1,
9556 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
9561 * Add Geneve TLV option item to matcher.
9563 * @param[in, out] dev
9564 * Pointer to rte_eth_dev structure.
9565 * @param[in, out] matcher
9567 * @param[in, out] key
9568 * Flow matcher value.
9570 * Flow pattern to translate.
9572 * Pointer to error structure.
9575 flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *matcher,
9576 void *key, const struct rte_flow_item *item,
9577 struct rte_flow_error *error)
9579 const struct rte_flow_item_geneve_opt *geneve_opt_m = item->mask;
9580 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9581 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9582 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9583 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9585 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9586 rte_be32_t opt_data_key = 0, opt_data_mask = 0;
9592 geneve_opt_m = &rte_flow_item_geneve_opt_mask;
9593 ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
9596 DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
9600 * Set the option length in GENEVE header if not requested.
9601 * The GENEVE TLV option length is expressed by the option length field
9602 * in the GENEVE header.
9603 * If the option length was not requested but the GENEVE TLV option item
9604 * is present we set the option length field implicitly.
9606 if (!MLX5_GET16(fte_match_set_misc, misc_m, geneve_opt_len)) {
9607 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9608 MLX5_GENEVE_OPTLEN_MASK);
9609 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9610 geneve_opt_v->option_len + 1);
9612 MLX5_SET(fte_match_set_misc, misc_m, geneve_tlv_option_0_exist, 1);
9613 MLX5_SET(fte_match_set_misc, misc_v, geneve_tlv_option_0_exist, 1);
9615 if (geneve_opt_v->data) {
9616 memcpy(&opt_data_key, geneve_opt_v->data,
9617 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9618 sizeof(opt_data_key)));
9619 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9620 sizeof(opt_data_key));
9621 memcpy(&opt_data_mask, geneve_opt_m->data,
9622 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9623 sizeof(opt_data_mask)));
9624 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9625 sizeof(opt_data_mask));
9626 MLX5_SET(fte_match_set_misc3, misc3_m,
9627 geneve_tlv_option_0_data,
9628 rte_be_to_cpu_32(opt_data_mask));
9629 MLX5_SET(fte_match_set_misc3, misc3_v,
9630 geneve_tlv_option_0_data,
9631 rte_be_to_cpu_32(opt_data_key & opt_data_mask));
9637 * Add MPLS item to matcher and to the value.
9639 * @param[in, out] matcher
9641 * @param[in, out] key
9642 * Flow matcher value.
9644 * Flow pattern to translate.
9645 * @param[in] prev_layer
9646 * The protocol layer indicated in previous item.
9648 * Item is inner pattern.
9651 flow_dv_translate_item_mpls(void *matcher, void *key,
9652 const struct rte_flow_item *item,
9653 uint64_t prev_layer,
9656 const uint32_t *in_mpls_m = item->mask;
9657 const uint32_t *in_mpls_v = item->spec;
9658 uint32_t *out_mpls_m = 0;
9659 uint32_t *out_mpls_v = 0;
9660 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9661 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9662 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
9664 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9665 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9666 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9668 switch (prev_layer) {
9669 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9670 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9671 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
9673 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9674 MLX5_UDP_PORT_MPLS);
9677 case MLX5_FLOW_LAYER_GRE:
9679 case MLX5_FLOW_LAYER_GRE_KEY:
9680 if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
9681 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
9683 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9684 RTE_ETHER_TYPE_MPLS);
9693 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
9694 switch (prev_layer) {
9695 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9697 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9698 outer_first_mpls_over_udp);
9700 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9701 outer_first_mpls_over_udp);
9703 case MLX5_FLOW_LAYER_GRE:
9705 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9706 outer_first_mpls_over_gre);
9708 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9709 outer_first_mpls_over_gre);
9712 /* Inner MPLS not over GRE is not supported. */
9715 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9719 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9725 if (out_mpls_m && out_mpls_v) {
9726 *out_mpls_m = *in_mpls_m;
9727 *out_mpls_v = *in_mpls_v & *in_mpls_m;
9732 * Add metadata register item to matcher
9734 * @param[in, out] matcher
9736 * @param[in, out] key
9737 * Flow matcher value.
9738 * @param[in] reg_type
9739 * Type of device metadata register
9746 flow_dv_match_meta_reg(void *matcher, void *key,
9747 enum modify_reg reg_type,
9748 uint32_t data, uint32_t mask)
9751 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
9753 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9759 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
9760 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
9763 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
9764 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
9768 * The metadata register C0 field might be divided into
9769 * source vport index and META item value, we should set
9770 * this field according to specified mask, not as whole one.
9772 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
9774 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
9775 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
9778 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
9781 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
9782 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
9785 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
9786 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
9789 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
9790 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
9793 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
9794 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
9797 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
9798 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
9801 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
9802 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
9805 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
9806 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
9815 * Add MARK item to matcher
9818 * The device to configure through.
9819 * @param[in, out] matcher
9821 * @param[in, out] key
9822 * Flow matcher value.
9824 * Flow pattern to translate.
9827 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
9828 void *matcher, void *key,
9829 const struct rte_flow_item *item)
9831 struct mlx5_priv *priv = dev->data->dev_private;
9832 const struct rte_flow_item_mark *mark;
9836 mark = item->mask ? (const void *)item->mask :
9837 &rte_flow_item_mark_mask;
9838 mask = mark->id & priv->sh->dv_mark_mask;
9839 mark = (const void *)item->spec;
9841 value = mark->id & priv->sh->dv_mark_mask & mask;
9843 enum modify_reg reg;
9845 /* Get the metadata register index for the mark. */
9846 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
9847 MLX5_ASSERT(reg > 0);
9848 if (reg == REG_C_0) {
9849 struct mlx5_priv *priv = dev->data->dev_private;
9850 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9851 uint32_t shl_c0 = rte_bsf32(msk_c0);
9857 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9862 * Add META item to matcher
9865 * The devich to configure through.
9866 * @param[in, out] matcher
9868 * @param[in, out] key
9869 * Flow matcher value.
9871 * Attributes of flow that includes this item.
9873 * Flow pattern to translate.
9876 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
9877 void *matcher, void *key,
9878 const struct rte_flow_attr *attr,
9879 const struct rte_flow_item *item)
9881 const struct rte_flow_item_meta *meta_m;
9882 const struct rte_flow_item_meta *meta_v;
9884 meta_m = (const void *)item->mask;
9886 meta_m = &rte_flow_item_meta_mask;
9887 meta_v = (const void *)item->spec;
9890 uint32_t value = meta_v->data;
9891 uint32_t mask = meta_m->data;
9893 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
9896 MLX5_ASSERT(reg != REG_NON);
9897 if (reg == REG_C_0) {
9898 struct mlx5_priv *priv = dev->data->dev_private;
9899 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9900 uint32_t shl_c0 = rte_bsf32(msk_c0);
9906 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9911 * Add vport metadata Reg C0 item to matcher
9913 * @param[in, out] matcher
9915 * @param[in, out] key
9916 * Flow matcher value.
9918 * Flow pattern to translate.
9921 flow_dv_translate_item_meta_vport(void *matcher, void *key,
9922 uint32_t value, uint32_t mask)
9924 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
9928 * Add tag item to matcher
9931 * The devich to configure through.
9932 * @param[in, out] matcher
9934 * @param[in, out] key
9935 * Flow matcher value.
9937 * Flow pattern to translate.
9940 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
9941 void *matcher, void *key,
9942 const struct rte_flow_item *item)
9944 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
9945 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
9946 uint32_t mask, value;
9949 value = tag_v->data;
9950 mask = tag_m ? tag_m->data : UINT32_MAX;
9951 if (tag_v->id == REG_C_0) {
9952 struct mlx5_priv *priv = dev->data->dev_private;
9953 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9954 uint32_t shl_c0 = rte_bsf32(msk_c0);
9960 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
9964 * Add TAG item to matcher
9967 * The devich to configure through.
9968 * @param[in, out] matcher
9970 * @param[in, out] key
9971 * Flow matcher value.
9973 * Flow pattern to translate.
9976 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
9977 void *matcher, void *key,
9978 const struct rte_flow_item *item)
9980 const struct rte_flow_item_tag *tag_v = item->spec;
9981 const struct rte_flow_item_tag *tag_m = item->mask;
9982 enum modify_reg reg;
9985 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
9986 /* Get the metadata register index for the tag. */
9987 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
9988 MLX5_ASSERT(reg > 0);
9989 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
9993 * Add source vport match to the specified matcher.
9995 * @param[in, out] matcher
9997 * @param[in, out] key
9998 * Flow matcher value.
10000 * Source vport value to match
10005 flow_dv_translate_item_source_vport(void *matcher, void *key,
10006 int16_t port, uint16_t mask)
10008 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
10009 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10011 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
10012 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
10016 * Translate port-id item to eswitch match on port-id.
10019 * The devich to configure through.
10020 * @param[in, out] matcher
10022 * @param[in, out] key
10023 * Flow matcher value.
10025 * Flow pattern to translate.
10030 * 0 on success, a negative errno value otherwise.
10033 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
10034 void *key, const struct rte_flow_item *item,
10035 const struct rte_flow_attr *attr)
10037 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
10038 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
10039 struct mlx5_priv *priv;
10042 if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
10043 flow_dv_translate_item_source_vport(matcher, key,
10044 flow_dv_get_esw_manager_vport_id(dev), 0xffff);
10047 mask = pid_m ? pid_m->id : 0xffff;
10048 id = pid_v ? pid_v->id : dev->data->port_id;
10049 priv = mlx5_port_to_eswitch_info(id, item == NULL);
10053 * Translate to vport field or to metadata, depending on mode.
10054 * Kernel can use either misc.source_port or half of C0 metadata
10057 if (priv->vport_meta_mask) {
10059 * Provide the hint for SW steering library
10060 * to insert the flow into ingress domain and
10061 * save the extra vport match.
10063 if (mask == 0xffff && priv->vport_id == 0xffff &&
10064 priv->pf_bond < 0 && attr->transfer)
10065 flow_dv_translate_item_source_vport
10066 (matcher, key, priv->vport_id, mask);
10068 * We should always set the vport metadata register,
10069 * otherwise the SW steering library can drop
10070 * the rule if wire vport metadata value is not zero,
10071 * it depends on kernel configuration.
10073 flow_dv_translate_item_meta_vport(matcher, key,
10074 priv->vport_meta_tag,
10075 priv->vport_meta_mask);
10077 flow_dv_translate_item_source_vport(matcher, key,
10078 priv->vport_id, mask);
10084 * Translate represented port item to eswitch match on port id.
10087 * The devich to configure through.
10088 * @param[in, out] matcher
10090 * @param[in, out] key
10091 * Flow matcher value.
10093 * Flow pattern to translate.
10098 * 0 on success, a negative errno value otherwise.
10101 flow_dv_translate_item_represented_port(struct rte_eth_dev *dev, void *matcher,
10103 const struct rte_flow_item *item,
10104 const struct rte_flow_attr *attr)
10106 const struct rte_flow_item_ethdev *pid_m = item ? item->mask : NULL;
10107 const struct rte_flow_item_ethdev *pid_v = item ? item->spec : NULL;
10108 struct mlx5_priv *priv;
10111 if (!pid_m && !pid_v)
10113 if (pid_v && pid_v->port_id == UINT16_MAX) {
10114 flow_dv_translate_item_source_vport(matcher, key,
10115 flow_dv_get_esw_manager_vport_id(dev), UINT16_MAX);
10118 mask = pid_m ? pid_m->port_id : UINT16_MAX;
10119 id = pid_v ? pid_v->port_id : dev->data->port_id;
10120 priv = mlx5_port_to_eswitch_info(id, item == NULL);
10124 * Translate to vport field or to metadata, depending on mode.
10125 * Kernel can use either misc.source_port or half of C0 metadata
10128 if (priv->vport_meta_mask) {
10130 * Provide the hint for SW steering library
10131 * to insert the flow into ingress domain and
10132 * save the extra vport match.
10134 if (mask == UINT16_MAX && priv->vport_id == UINT16_MAX &&
10135 priv->pf_bond < 0 && attr->transfer)
10136 flow_dv_translate_item_source_vport
10137 (matcher, key, priv->vport_id, mask);
10139 * We should always set the vport metadata register,
10140 * otherwise the SW steering library can drop
10141 * the rule if wire vport metadata value is not zero,
10142 * it depends on kernel configuration.
10144 flow_dv_translate_item_meta_vport(matcher, key,
10145 priv->vport_meta_tag,
10146 priv->vport_meta_mask);
10148 flow_dv_translate_item_source_vport(matcher, key,
10149 priv->vport_id, mask);
10155 * Add ICMP6 item to matcher and to the value.
10157 * @param[in, out] matcher
10159 * @param[in, out] key
10160 * Flow matcher value.
10162 * Flow pattern to translate.
10164 * Item is inner pattern.
10167 flow_dv_translate_item_icmp6(void *matcher, void *key,
10168 const struct rte_flow_item *item,
10171 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
10172 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
10175 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
10176 misc_parameters_3);
10177 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10179 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
10181 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
10183 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
10185 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10187 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
10188 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
10192 icmp6_m = &rte_flow_item_icmp6_mask;
10193 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
10194 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
10195 icmp6_v->type & icmp6_m->type);
10196 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
10197 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
10198 icmp6_v->code & icmp6_m->code);
10202 * Add ICMP item to matcher and to the value.
10204 * @param[in, out] matcher
10206 * @param[in, out] key
10207 * Flow matcher value.
10209 * Flow pattern to translate.
10211 * Item is inner pattern.
10214 flow_dv_translate_item_icmp(void *matcher, void *key,
10215 const struct rte_flow_item *item,
10218 const struct rte_flow_item_icmp *icmp_m = item->mask;
10219 const struct rte_flow_item_icmp *icmp_v = item->spec;
10220 uint32_t icmp_header_data_m = 0;
10221 uint32_t icmp_header_data_v = 0;
10224 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
10225 misc_parameters_3);
10226 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10228 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
10230 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
10232 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
10234 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10236 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
10237 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
10241 icmp_m = &rte_flow_item_icmp_mask;
10242 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
10243 icmp_m->hdr.icmp_type);
10244 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
10245 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
10246 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
10247 icmp_m->hdr.icmp_code);
10248 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
10249 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
10250 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
10251 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
10252 if (icmp_header_data_m) {
10253 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
10254 icmp_header_data_v |=
10255 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
10256 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
10257 icmp_header_data_m);
10258 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
10259 icmp_header_data_v & icmp_header_data_m);
10264 * Add GTP item to matcher and to the value.
10266 * @param[in, out] matcher
10268 * @param[in, out] key
10269 * Flow matcher value.
10271 * Flow pattern to translate.
10273 * Item is inner pattern.
10276 flow_dv_translate_item_gtp(void *matcher, void *key,
10277 const struct rte_flow_item *item, int inner)
10279 const struct rte_flow_item_gtp *gtp_m = item->mask;
10280 const struct rte_flow_item_gtp *gtp_v = item->spec;
10283 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
10284 misc_parameters_3);
10285 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10286 uint16_t dport = RTE_GTPU_UDP_PORT;
10289 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
10291 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
10293 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
10295 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10297 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10298 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
10299 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
10304 gtp_m = &rte_flow_item_gtp_mask;
10305 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
10306 gtp_m->v_pt_rsv_flags);
10307 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
10308 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
10309 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
10310 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
10311 gtp_v->msg_type & gtp_m->msg_type);
10312 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
10313 rte_be_to_cpu_32(gtp_m->teid));
10314 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
10315 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
10319 * Add GTP PSC item to matcher.
10321 * @param[in, out] matcher
10323 * @param[in, out] key
10324 * Flow matcher value.
10326 * Flow pattern to translate.
10329 flow_dv_translate_item_gtp_psc(void *matcher, void *key,
10330 const struct rte_flow_item *item)
10332 const struct rte_flow_item_gtp_psc *gtp_psc_m = item->mask;
10333 const struct rte_flow_item_gtp_psc *gtp_psc_v = item->spec;
10334 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
10335 misc_parameters_3);
10336 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10342 uint8_t next_ext_header_type;
10347 /* Always set E-flag match on one, regardless of GTP item settings. */
10348 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_m, gtpu_msg_flags);
10349 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
10350 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags, gtp_flags);
10351 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
10352 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
10353 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
10354 /*Set next extension header type. */
10357 dw_2.next_ext_header_type = 0xff;
10358 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_dw_2,
10359 rte_cpu_to_be_32(dw_2.w32));
10362 dw_2.next_ext_header_type = 0x85;
10363 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
10364 rte_cpu_to_be_32(dw_2.w32));
10370 uint8_t type_flags;
10376 /*Set extension header PDU type and Qos. */
10378 gtp_psc_m = &rte_flow_item_gtp_psc_mask;
10380 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_m->hdr.type);
10381 dw_0.qfi = gtp_psc_m->hdr.qfi;
10382 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_first_ext_dw_0,
10383 rte_cpu_to_be_32(dw_0.w32));
10385 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
10386 gtp_psc_m->hdr.type);
10387 dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
10388 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
10389 rte_cpu_to_be_32(dw_0.w32));
10395 * Add eCPRI item to matcher and to the value.
10398 * The devich to configure through.
10399 * @param[in, out] matcher
10401 * @param[in, out] key
10402 * Flow matcher value.
10404 * Flow pattern to translate.
10405 * @param[in] last_item
10409 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
10410 void *key, const struct rte_flow_item *item,
10411 uint64_t last_item)
10413 struct mlx5_priv *priv = dev->data->dev_private;
10414 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
10415 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
10416 struct rte_ecpri_common_hdr common;
10417 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
10418 misc_parameters_4);
10419 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
10425 * In case of eCPRI over Ethernet, if EtherType is not specified,
10426 * match on eCPRI EtherType implicitly.
10428 if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
10429 void *hdrs_m, *hdrs_v, *l2m, *l2v;
10431 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
10432 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10433 l2m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, ethertype);
10434 l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
10435 if (*(uint16_t *)l2m == 0 && *(uint16_t *)l2v == 0) {
10436 *(uint16_t *)l2m = UINT16_MAX;
10437 *(uint16_t *)l2v = RTE_BE16(RTE_ETHER_TYPE_ECPRI);
10443 ecpri_m = &rte_flow_item_ecpri_mask;
10445 * Maximal four DW samples are supported in a single matching now.
10446 * Two are used now for a eCPRI matching:
10447 * 1. Type: one byte, mask should be 0x00ff0000 in network order
10448 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
10451 if (!ecpri_m->hdr.common.u32)
10453 samples = priv->sh->ecpri_parser.ids;
10454 /* Need to take the whole DW as the mask to fill the entry. */
10455 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
10456 prog_sample_field_value_0);
10457 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
10458 prog_sample_field_value_0);
10459 /* Already big endian (network order) in the header. */
10460 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
10461 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
10462 /* Sample#0, used for matching type, offset 0. */
10463 MLX5_SET(fte_match_set_misc4, misc4_m,
10464 prog_sample_field_id_0, samples[0]);
10465 /* It makes no sense to set the sample ID in the mask field. */
10466 MLX5_SET(fte_match_set_misc4, misc4_v,
10467 prog_sample_field_id_0, samples[0]);
10469 * Checking if message body part needs to be matched.
10470 * Some wildcard rules only matching type field should be supported.
10472 if (ecpri_m->hdr.dummy[0]) {
10473 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
10474 switch (common.type) {
10475 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
10476 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
10477 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
10478 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
10479 prog_sample_field_value_1);
10480 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
10481 prog_sample_field_value_1);
10482 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
10483 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
10484 ecpri_m->hdr.dummy[0];
10485 /* Sample#1, to match message body, offset 4. */
10486 MLX5_SET(fte_match_set_misc4, misc4_m,
10487 prog_sample_field_id_1, samples[1]);
10488 MLX5_SET(fte_match_set_misc4, misc4_v,
10489 prog_sample_field_id_1, samples[1]);
10492 /* Others, do not match any sample ID. */
10499 * Add connection tracking status item to matcher
10502 * The devich to configure through.
10503 * @param[in, out] matcher
10505 * @param[in, out] key
10506 * Flow matcher value.
10508 * Flow pattern to translate.
10511 flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
10512 void *matcher, void *key,
10513 const struct rte_flow_item *item)
10515 uint32_t reg_value = 0;
10517 /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
10518 uint32_t reg_mask = 0;
10519 const struct rte_flow_item_conntrack *spec = item->spec;
10520 const struct rte_flow_item_conntrack *mask = item->mask;
10522 struct rte_flow_error error;
10525 mask = &rte_flow_item_conntrack_mask;
10526 if (!spec || !mask->flags)
10528 flags = spec->flags & mask->flags;
10529 /* The conflict should be checked in the validation. */
10530 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
10531 reg_value |= MLX5_CT_SYNDROME_VALID;
10532 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
10533 reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
10534 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
10535 reg_value |= MLX5_CT_SYNDROME_INVALID;
10536 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
10537 reg_value |= MLX5_CT_SYNDROME_TRAP;
10538 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10539 reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
10540 if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
10541 RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
10542 RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
10544 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
10545 reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
10546 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10547 reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
10548 /* The REG_C_x value could be saved during startup. */
10549 reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
10550 if (reg_id == REG_NON)
10552 flow_dv_match_meta_reg(matcher, key, (enum modify_reg)reg_id,
10553 reg_value, reg_mask);
10557 flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
10558 const struct rte_flow_item *item,
10559 struct mlx5_flow *dev_flow, bool is_inner)
10561 const struct rte_flow_item_flex *spec =
10562 (const struct rte_flow_item_flex *)item->spec;
10563 int index = mlx5_flex_acquire_index(dev, spec->handle, false);
10565 MLX5_ASSERT(index >= 0 && index <= (int)(sizeof(uint32_t) * CHAR_BIT));
10568 if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
10569 /* Don't count both inner and outer flex items in one rule. */
10570 if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
10571 MLX5_ASSERT(false);
10572 dev_flow->handle->flex_item |= (uint8_t)RTE_BIT32(index);
10574 mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
10577 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
10579 #define HEADER_IS_ZERO(match_criteria, headers) \
10580 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
10581 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
10584 * Calculate flow matcher enable bitmap.
10586 * @param match_criteria
10587 * Pointer to flow matcher criteria.
10590 * Bitmap of enabled fields.
10593 flow_dv_matcher_enable(uint32_t *match_criteria)
10595 uint8_t match_criteria_enable;
10597 match_criteria_enable =
10598 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
10599 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
10600 match_criteria_enable |=
10601 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
10602 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
10603 match_criteria_enable |=
10604 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
10605 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
10606 match_criteria_enable |=
10607 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
10608 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
10609 match_criteria_enable |=
10610 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
10611 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
10612 match_criteria_enable |=
10613 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
10614 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
10615 match_criteria_enable |=
10616 (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
10617 MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
10618 return match_criteria_enable;
10622 __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
10625 * Check flow matching criteria first, subtract misc5/4 length if flow
10626 * doesn't own misc5/4 parameters. In some old rdma-core releases,
10627 * misc5/4 are not supported, and matcher creation failure is expected
10628 * w/o subtraction. If misc5 is provided, misc4 must be counted in since
10629 * misc5 is right after misc4.
10631 if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
10632 *size = MLX5_ST_SZ_BYTES(fte_match_param) -
10633 MLX5_ST_SZ_BYTES(fte_match_set_misc5);
10634 if (!(match_criteria & (1 <<
10635 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
10636 *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
10641 static struct mlx5_list_entry *
10642 flow_dv_matcher_clone_cb(void *tool_ctx __rte_unused,
10643 struct mlx5_list_entry *entry, void *cb_ctx)
10645 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10646 struct mlx5_flow_dv_matcher *ref = ctx->data;
10647 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10648 typeof(*tbl), tbl);
10649 struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
10654 rte_flow_error_set(ctx->error, ENOMEM,
10655 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10656 "cannot create matcher");
10659 memcpy(resource, entry, sizeof(*resource));
10660 resource->tbl = &tbl->tbl;
10661 return &resource->entry;
10665 flow_dv_matcher_clone_free_cb(void *tool_ctx __rte_unused,
10666 struct mlx5_list_entry *entry)
10671 struct mlx5_list_entry *
10672 flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
10674 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10675 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10676 struct rte_eth_dev *dev = ctx->dev;
10677 struct mlx5_flow_tbl_data_entry *tbl_data;
10678 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
10679 struct rte_flow_error *error = ctx->error;
10680 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10681 struct mlx5_flow_tbl_resource *tbl;
10686 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10688 rte_flow_error_set(error, ENOMEM,
10689 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10691 "cannot allocate flow table data entry");
10694 tbl_data->idx = idx;
10695 tbl_data->tunnel = tt_prm->tunnel;
10696 tbl_data->group_id = tt_prm->group_id;
10697 tbl_data->external = !!tt_prm->external;
10698 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
10699 tbl_data->is_egress = !!key.is_egress;
10700 tbl_data->is_transfer = !!key.is_fdb;
10701 tbl_data->dummy = !!key.dummy;
10702 tbl_data->level = key.level;
10703 tbl_data->id = key.id;
10704 tbl = &tbl_data->tbl;
10706 return &tbl_data->entry;
10708 domain = sh->fdb_domain;
10709 else if (key.is_egress)
10710 domain = sh->tx_domain;
10712 domain = sh->rx_domain;
10713 ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
10715 rte_flow_error_set(error, ENOMEM,
10716 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10717 NULL, "cannot create flow table object");
10718 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10721 if (key.level != 0) {
10722 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
10723 (tbl->obj, &tbl_data->jump.action);
10725 rte_flow_error_set(error, ENOMEM,
10726 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10728 "cannot create flow jump action");
10729 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10730 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10734 MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
10735 key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
10736 key.level, key.id);
10737 tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
10738 flow_dv_matcher_create_cb,
10739 flow_dv_matcher_match_cb,
10740 flow_dv_matcher_remove_cb,
10741 flow_dv_matcher_clone_cb,
10742 flow_dv_matcher_clone_free_cb);
10743 if (!tbl_data->matchers) {
10744 rte_flow_error_set(error, ENOMEM,
10745 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10747 "cannot create tbl matcher list");
10748 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10749 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10750 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10753 return &tbl_data->entry;
10757 flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
10760 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10761 struct mlx5_flow_tbl_data_entry *tbl_data =
10762 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10763 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10765 return tbl_data->level != key.level ||
10766 tbl_data->id != key.id ||
10767 tbl_data->dummy != key.dummy ||
10768 tbl_data->is_transfer != !!key.is_fdb ||
10769 tbl_data->is_egress != !!key.is_egress;
10772 struct mlx5_list_entry *
10773 flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
10776 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10777 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10778 struct mlx5_flow_tbl_data_entry *tbl_data;
10779 struct rte_flow_error *error = ctx->error;
10782 tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10784 rte_flow_error_set(error, ENOMEM,
10785 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10787 "cannot allocate flow table data entry");
10790 memcpy(tbl_data, oentry, sizeof(*tbl_data));
10791 tbl_data->idx = idx;
10792 return &tbl_data->entry;
10796 flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10798 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10799 struct mlx5_flow_tbl_data_entry *tbl_data =
10800 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10802 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10806 * Get a flow table.
10808 * @param[in, out] dev
10809 * Pointer to rte_eth_dev structure.
10810 * @param[in] table_level
10811 * Table level to use.
10812 * @param[in] egress
10813 * Direction of the table.
10814 * @param[in] transfer
10815 * E-Switch or NIC flow.
10817 * Dummy entry for dv API.
10818 * @param[in] table_id
10820 * @param[out] error
10821 * pointer to error structure.
10824 * Returns tables resource based on the index, NULL in case of failed.
10826 struct mlx5_flow_tbl_resource *
10827 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
10828 uint32_t table_level, uint8_t egress,
10831 const struct mlx5_flow_tunnel *tunnel,
10832 uint32_t group_id, uint8_t dummy,
10834 struct rte_flow_error *error)
10836 struct mlx5_priv *priv = dev->data->dev_private;
10837 union mlx5_flow_tbl_key table_key = {
10839 .level = table_level,
10843 .is_fdb = !!transfer,
10844 .is_egress = !!egress,
10847 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
10849 .group_id = group_id,
10850 .external = external,
10852 struct mlx5_flow_cb_ctx ctx = {
10855 .data = &table_key.v64,
10858 struct mlx5_list_entry *entry;
10859 struct mlx5_flow_tbl_data_entry *tbl_data;
10861 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
10863 rte_flow_error_set(error, ENOMEM,
10864 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10865 "cannot get table");
10868 DRV_LOG(DEBUG, "table_level %u table_id %u "
10869 "tunnel %u group %u registered.",
10870 table_level, table_id,
10871 tunnel ? tunnel->tunnel_id : 0, group_id);
10872 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10873 return &tbl_data->tbl;
10877 flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10879 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10880 struct mlx5_flow_tbl_data_entry *tbl_data =
10881 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10883 MLX5_ASSERT(entry && sh);
10884 if (tbl_data->jump.action)
10885 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10886 if (tbl_data->tbl.obj)
10887 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
10888 if (tbl_data->tunnel_offload && tbl_data->external) {
10889 struct mlx5_list_entry *he;
10890 struct mlx5_hlist *tunnel_grp_hash;
10891 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
10892 union tunnel_tbl_key tunnel_key = {
10893 .tunnel_id = tbl_data->tunnel ?
10894 tbl_data->tunnel->tunnel_id : 0,
10895 .group = tbl_data->group_id
10897 uint32_t table_level = tbl_data->level;
10898 struct mlx5_flow_cb_ctx ctx = {
10899 .data = (void *)&tunnel_key.val,
10902 tunnel_grp_hash = tbl_data->tunnel ?
10903 tbl_data->tunnel->groups :
10905 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
10907 mlx5_hlist_unregister(tunnel_grp_hash, he);
10909 "table_level %u id %u tunnel %u group %u released.",
10913 tbl_data->tunnel->tunnel_id : 0,
10914 tbl_data->group_id);
10916 if (tbl_data->matchers)
10917 mlx5_list_destroy(tbl_data->matchers);
10918 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10922 * Release a flow table.
10925 * Pointer to device shared structure.
10927 * Table resource to be released.
10930 * Returns 0 if table was released, else return 1;
10933 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
10934 struct mlx5_flow_tbl_resource *tbl)
10936 struct mlx5_flow_tbl_data_entry *tbl_data =
10937 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10941 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
10945 flow_dv_matcher_match_cb(void *tool_ctx __rte_unused,
10946 struct mlx5_list_entry *entry, void *cb_ctx)
10948 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10949 struct mlx5_flow_dv_matcher *ref = ctx->data;
10950 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
10953 return cur->crc != ref->crc ||
10954 cur->priority != ref->priority ||
10955 memcmp((const void *)cur->mask.buf,
10956 (const void *)ref->mask.buf, ref->mask.size);
10959 struct mlx5_list_entry *
10960 flow_dv_matcher_create_cb(void *tool_ctx, void *cb_ctx)
10962 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10963 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10964 struct mlx5_flow_dv_matcher *ref = ctx->data;
10965 struct mlx5_flow_dv_matcher *resource;
10966 struct mlx5dv_flow_matcher_attr dv_attr = {
10967 .type = IBV_FLOW_ATTR_NORMAL,
10968 .match_mask = (void *)&ref->mask,
10970 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10971 typeof(*tbl), tbl);
10974 resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
10977 rte_flow_error_set(ctx->error, ENOMEM,
10978 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10979 "cannot create matcher");
10983 dv_attr.match_criteria_enable =
10984 flow_dv_matcher_enable(resource->mask.buf);
10985 __flow_dv_adjust_buf_size(&ref->mask.size,
10986 dv_attr.match_criteria_enable);
10987 dv_attr.priority = ref->priority;
10988 if (tbl->is_egress)
10989 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
10990 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
10992 &resource->matcher_object);
10994 mlx5_free(resource);
10995 rte_flow_error_set(ctx->error, ENOMEM,
10996 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10997 "cannot create matcher");
11000 return &resource->entry;
11004 * Register the flow matcher.
11006 * @param[in, out] dev
11007 * Pointer to rte_eth_dev structure.
11008 * @param[in, out] matcher
11009 * Pointer to flow matcher.
11010 * @param[in, out] key
11011 * Pointer to flow table key.
11012 * @parm[in, out] dev_flow
11013 * Pointer to the dev_flow.
11014 * @param[out] error
11015 * pointer to error structure.
11018 * 0 on success otherwise -errno and errno is set.
11021 flow_dv_matcher_register(struct rte_eth_dev *dev,
11022 struct mlx5_flow_dv_matcher *ref,
11023 union mlx5_flow_tbl_key *key,
11024 struct mlx5_flow *dev_flow,
11025 const struct mlx5_flow_tunnel *tunnel,
11027 struct rte_flow_error *error)
11029 struct mlx5_list_entry *entry;
11030 struct mlx5_flow_dv_matcher *resource;
11031 struct mlx5_flow_tbl_resource *tbl;
11032 struct mlx5_flow_tbl_data_entry *tbl_data;
11033 struct mlx5_flow_cb_ctx ctx = {
11038 * tunnel offload API requires this registration for cases when
11039 * tunnel match rule was inserted before tunnel set rule.
11041 tbl = flow_dv_tbl_resource_get(dev, key->level,
11042 key->is_egress, key->is_fdb,
11043 dev_flow->external, tunnel,
11044 group_id, 0, key->id, error);
11046 return -rte_errno; /* No need to refill the error info */
11047 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
11049 entry = mlx5_list_register(tbl_data->matchers, &ctx);
11051 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
11052 return rte_flow_error_set(error, ENOMEM,
11053 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11054 "cannot allocate ref memory");
11056 resource = container_of(entry, typeof(*resource), entry);
11057 dev_flow->handle->dvh.matcher = resource;
11061 struct mlx5_list_entry *
11062 flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
11064 struct mlx5_dev_ctx_shared *sh = tool_ctx;
11065 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11066 struct mlx5_flow_dv_tag_resource *entry;
11070 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
11072 rte_flow_error_set(ctx->error, ENOMEM,
11073 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11074 "cannot allocate resource memory");
11078 entry->tag_id = *(uint32_t *)(ctx->data);
11079 ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
11082 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
11083 rte_flow_error_set(ctx->error, ENOMEM,
11084 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11085 NULL, "cannot create action");
11088 return &entry->entry;
11092 flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11095 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11096 struct mlx5_flow_dv_tag_resource *tag =
11097 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
11099 return *(uint32_t *)(ctx->data) != tag->tag_id;
11102 struct mlx5_list_entry *
11103 flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11106 struct mlx5_dev_ctx_shared *sh = tool_ctx;
11107 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11108 struct mlx5_flow_dv_tag_resource *entry;
11111 entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
11113 rte_flow_error_set(ctx->error, ENOMEM,
11114 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11115 "cannot allocate tag resource memory");
11118 memcpy(entry, oentry, sizeof(*entry));
11120 return &entry->entry;
11124 flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11126 struct mlx5_dev_ctx_shared *sh = tool_ctx;
11127 struct mlx5_flow_dv_tag_resource *tag =
11128 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
11130 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
11134 * Find existing tag resource or create and register a new one.
11136 * @param dev[in, out]
11137 * Pointer to rte_eth_dev structure.
11138 * @param[in, out] tag_be24
11139 * Tag value in big endian then R-shift 8.
11140 * @parm[in, out] dev_flow
11141 * Pointer to the dev_flow.
11142 * @param[out] error
11143 * pointer to error structure.
11146 * 0 on success otherwise -errno and errno is set.
11149 flow_dv_tag_resource_register
11150 (struct rte_eth_dev *dev,
11152 struct mlx5_flow *dev_flow,
11153 struct rte_flow_error *error)
11155 struct mlx5_priv *priv = dev->data->dev_private;
11156 struct mlx5_flow_dv_tag_resource *resource;
11157 struct mlx5_list_entry *entry;
11158 struct mlx5_flow_cb_ctx ctx = {
11162 struct mlx5_hlist *tag_table;
11164 tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
11166 MLX5_TAGS_HLIST_ARRAY_SIZE,
11167 false, false, priv->sh,
11168 flow_dv_tag_create_cb,
11169 flow_dv_tag_match_cb,
11170 flow_dv_tag_remove_cb,
11171 flow_dv_tag_clone_cb,
11172 flow_dv_tag_clone_free_cb,
11174 if (unlikely(!tag_table))
11176 entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
11178 resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
11180 dev_flow->handle->dvh.rix_tag = resource->idx;
11181 dev_flow->dv.tag_resource = resource;
11188 flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11190 struct mlx5_dev_ctx_shared *sh = tool_ctx;
11191 struct mlx5_flow_dv_tag_resource *tag =
11192 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
11194 MLX5_ASSERT(tag && sh && tag->action);
11195 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
11196 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
11197 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
11204 * Pointer to Ethernet device.
11209 * 1 while a reference on it exists, 0 when freed.
11212 flow_dv_tag_release(struct rte_eth_dev *dev,
11215 struct mlx5_priv *priv = dev->data->dev_private;
11216 struct mlx5_flow_dv_tag_resource *tag;
11218 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
11221 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
11222 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
11223 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
11227 * Translate action PORT_ID / REPRESENTED_PORT to vport.
11230 * Pointer to rte_eth_dev structure.
11231 * @param[in] action
11232 * Pointer to action PORT_ID / REPRESENTED_PORT.
11233 * @param[out] dst_port_id
11234 * The target port ID.
11235 * @param[out] error
11236 * Pointer to the error structure.
11239 * 0 on success, a negative errno value otherwise and rte_errno is set.
11242 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
11243 const struct rte_flow_action *action,
11244 uint32_t *dst_port_id,
11245 struct rte_flow_error *error)
11248 struct mlx5_priv *priv;
11250 switch (action->type) {
11251 case RTE_FLOW_ACTION_TYPE_PORT_ID: {
11252 const struct rte_flow_action_port_id *conf;
11254 conf = (const struct rte_flow_action_port_id *)action->conf;
11255 port = conf->original ? dev->data->port_id : conf->id;
11258 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
11259 const struct rte_flow_action_ethdev *ethdev;
11261 ethdev = (const struct rte_flow_action_ethdev *)action->conf;
11262 port = ethdev->port_id;
11266 MLX5_ASSERT(false);
11267 return rte_flow_error_set(error, EINVAL,
11268 RTE_FLOW_ERROR_TYPE_ACTION, action,
11269 "unknown E-Switch action");
11272 priv = mlx5_port_to_eswitch_info(port, false);
11274 return rte_flow_error_set(error, -rte_errno,
11275 RTE_FLOW_ERROR_TYPE_ACTION,
11277 "No eswitch info was found for port");
11278 #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
11280 * This parameter is transferred to
11281 * mlx5dv_dr_action_create_dest_ib_port().
11283 *dst_port_id = priv->dev_port;
11286 * Legacy mode, no LAG configurations is supported.
11287 * This parameter is transferred to
11288 * mlx5dv_dr_action_create_dest_vport().
11290 *dst_port_id = priv->vport_id;
11296 * Create a counter with aging configuration.
11299 * Pointer to rte_eth_dev structure.
11300 * @param[in] dev_flow
11301 * Pointer to the mlx5_flow.
11302 * @param[out] count
11303 * Pointer to the counter action configuration.
11305 * Pointer to the aging action configuration.
11308 * Index to flow counter on success, 0 otherwise.
11311 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
11312 struct mlx5_flow *dev_flow,
11313 const struct rte_flow_action_count *count
11315 const struct rte_flow_action_age *age)
11318 struct mlx5_age_param *age_param;
11320 counter = flow_dv_counter_alloc(dev, !!age);
11321 if (!counter || age == NULL)
11323 age_param = flow_dv_counter_idx_get_age(dev, counter);
11324 age_param->context = age->context ? age->context :
11325 (void *)(uintptr_t)(dev_flow->flow_idx);
11326 age_param->timeout = age->timeout;
11327 age_param->port_id = dev->data->port_id;
11328 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
11329 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
11334 * Add Tx queue matcher
11337 * Pointer to the dev struct.
11338 * @param[in, out] matcher
11340 * @param[in, out] key
11341 * Flow matcher value.
11343 * Flow pattern to translate.
11345 * Item is inner pattern.
11348 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
11349 void *matcher, void *key,
11350 const struct rte_flow_item *item)
11352 const struct mlx5_rte_flow_item_tx_queue *queue_m;
11353 const struct mlx5_rte_flow_item_tx_queue *queue_v;
11354 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
11355 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11356 struct mlx5_txq_ctrl *txq;
11357 uint32_t queue, mask;
11359 queue_m = (const void *)item->mask;
11360 queue_v = (const void *)item->spec;
11363 txq = mlx5_txq_get(dev, queue_v->queue);
11366 if (txq->is_hairpin)
11367 queue = txq->obj->sq->id;
11369 queue = txq->obj->sq_obj.sq->id;
11370 mask = queue_m == NULL ? UINT32_MAX : queue_m->queue;
11371 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, mask);
11372 MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue & mask);
11373 mlx5_txq_release(dev, queue_v->queue);
11377 * Set the hash fields according to the @p flow information.
11379 * @param[in] item_flags
11380 * The match pattern item flags.
11381 * @param[in] rss_desc
11382 * Pointer to the mlx5_flow_rss_desc.
11383 * @param[out] hash_fields
11384 * Pointer to the RSS hash fields.
11387 flow_dv_hashfields_set(uint64_t item_flags,
11388 struct mlx5_flow_rss_desc *rss_desc,
11389 uint64_t *hash_fields)
11391 uint64_t items = item_flags;
11392 uint64_t fields = 0;
11394 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
11397 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
11398 if (rss_desc->level >= 2)
11401 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
11402 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4)) ||
11404 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
11405 if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
11406 fields |= IBV_RX_HASH_SRC_IPV4;
11407 else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
11408 fields |= IBV_RX_HASH_DST_IPV4;
11410 fields |= MLX5_IPV4_IBV_RX_HASH;
11412 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
11413 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6)) ||
11415 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
11416 if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
11417 fields |= IBV_RX_HASH_SRC_IPV6;
11418 else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
11419 fields |= IBV_RX_HASH_DST_IPV6;
11421 fields |= MLX5_IPV6_IBV_RX_HASH;
11424 if (items & MLX5_FLOW_ITEM_ESP) {
11425 if (rss_types & RTE_ETH_RSS_ESP)
11426 fields |= IBV_RX_HASH_IPSEC_SPI;
11428 if ((fields & ~IBV_RX_HASH_IPSEC_SPI) == 0) {
11429 *hash_fields = fields;
11431 * There is no match between the RSS types and the
11432 * L3 protocol (IPv4/IPv6) defined in the flow rule.
11436 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
11437 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP)) ||
11439 if (rss_types & RTE_ETH_RSS_UDP) {
11440 if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
11441 fields |= IBV_RX_HASH_SRC_PORT_UDP;
11442 else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
11443 fields |= IBV_RX_HASH_DST_PORT_UDP;
11445 fields |= MLX5_UDP_IBV_RX_HASH;
11447 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
11448 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP)) ||
11450 if (rss_types & RTE_ETH_RSS_TCP) {
11451 if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
11452 fields |= IBV_RX_HASH_SRC_PORT_TCP;
11453 else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
11454 fields |= IBV_RX_HASH_DST_PORT_TCP;
11456 fields |= MLX5_TCP_IBV_RX_HASH;
11460 fields |= IBV_RX_HASH_INNER;
11461 *hash_fields = fields;
11465 * Prepare an Rx Hash queue.
11468 * Pointer to Ethernet device.
11469 * @param[in] dev_flow
11470 * Pointer to the mlx5_flow.
11471 * @param[in] rss_desc
11472 * Pointer to the mlx5_flow_rss_desc.
11473 * @param[out] hrxq_idx
11474 * Hash Rx queue index.
11477 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
11479 static struct mlx5_hrxq *
11480 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
11481 struct mlx5_flow *dev_flow,
11482 struct mlx5_flow_rss_desc *rss_desc,
11483 uint32_t *hrxq_idx)
11485 struct mlx5_flow_handle *dh = dev_flow->handle;
11486 uint32_t shared_rss = rss_desc->shared_rss;
11487 struct mlx5_hrxq *hrxq;
11489 MLX5_ASSERT(rss_desc->queue_num);
11490 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
11491 rss_desc->hash_fields = dev_flow->hash_fields;
11492 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
11493 rss_desc->shared_rss = 0;
11494 if (rss_desc->hash_fields == 0)
11495 rss_desc->queue_num = 1;
11496 hrxq = mlx5_hrxq_get(dev, rss_desc);
11497 *hrxq_idx = hrxq ? hrxq->idx : 0;
11498 rss_desc->shared_rss = shared_rss;
11503 * Release sample sub action resource.
11505 * @param[in, out] dev
11506 * Pointer to rte_eth_dev structure.
11507 * @param[in] act_res
11508 * Pointer to sample sub action resource.
11511 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
11512 struct mlx5_flow_sub_actions_idx *act_res)
11514 if (act_res->rix_hrxq) {
11515 mlx5_hrxq_release(dev, act_res->rix_hrxq);
11516 act_res->rix_hrxq = 0;
11518 if (act_res->rix_encap_decap) {
11519 flow_dv_encap_decap_resource_release(dev,
11520 act_res->rix_encap_decap);
11521 act_res->rix_encap_decap = 0;
11523 if (act_res->rix_port_id_action) {
11524 flow_dv_port_id_action_resource_release(dev,
11525 act_res->rix_port_id_action);
11526 act_res->rix_port_id_action = 0;
11528 if (act_res->rix_tag) {
11529 flow_dv_tag_release(dev, act_res->rix_tag);
11530 act_res->rix_tag = 0;
11532 if (act_res->rix_jump) {
11533 flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
11534 act_res->rix_jump = 0;
11539 flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
11540 struct mlx5_list_entry *entry, void *cb_ctx)
11542 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11543 struct rte_eth_dev *dev = ctx->dev;
11544 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
11545 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
11549 if (ctx_resource->ratio == resource->ratio &&
11550 ctx_resource->ft_type == resource->ft_type &&
11551 ctx_resource->ft_id == resource->ft_id &&
11552 ctx_resource->set_action == resource->set_action &&
11553 !memcmp((void *)&ctx_resource->sample_act,
11554 (void *)&resource->sample_act,
11555 sizeof(struct mlx5_flow_sub_actions_list))) {
11557 * Existing sample action should release the prepared
11558 * sub-actions reference counter.
11560 flow_dv_sample_sub_actions_release(dev,
11561 &ctx_resource->sample_idx);
11567 struct mlx5_list_entry *
11568 flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11570 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11571 struct rte_eth_dev *dev = ctx->dev;
11572 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
11573 void **sample_dv_actions = ctx_resource->sub_actions;
11574 struct mlx5_flow_dv_sample_resource *resource;
11575 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
11576 struct mlx5_priv *priv = dev->data->dev_private;
11577 struct mlx5_dev_ctx_shared *sh = priv->sh;
11578 struct mlx5_flow_tbl_resource *tbl;
11580 const uint32_t next_ft_step = 1;
11581 uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
11582 uint8_t is_egress = 0;
11583 uint8_t is_transfer = 0;
11584 struct rte_flow_error *error = ctx->error;
11586 /* Register new sample resource. */
11587 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11589 rte_flow_error_set(error, ENOMEM,
11590 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11592 "cannot allocate resource memory");
11595 *resource = *ctx_resource;
11596 /* Create normal path table level */
11597 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11599 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
11601 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
11602 is_egress, is_transfer,
11603 true, NULL, 0, 0, 0, error);
11605 rte_flow_error_set(error, ENOMEM,
11606 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11608 "fail to create normal path table "
11612 resource->normal_path_tbl = tbl;
11613 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
11614 if (!sh->default_miss_action) {
11615 rte_flow_error_set(error, ENOMEM,
11616 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11618 "default miss action was not "
11622 sample_dv_actions[ctx_resource->sample_act.actions_num++] =
11623 sh->default_miss_action;
11625 /* Create a DR sample action */
11626 sampler_attr.sample_ratio = resource->ratio;
11627 sampler_attr.default_next_table = tbl->obj;
11628 sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
11629 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
11630 &sample_dv_actions[0];
11631 sampler_attr.action = resource->set_action;
11632 if (mlx5_os_flow_dr_create_flow_action_sampler
11633 (&sampler_attr, &resource->verbs_action)) {
11634 rte_flow_error_set(error, ENOMEM,
11635 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11636 NULL, "cannot create sample action");
11639 resource->idx = idx;
11640 resource->dev = dev;
11641 return &resource->entry;
11643 if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
11644 flow_dv_sample_sub_actions_release(dev,
11645 &resource->sample_idx);
11646 if (resource->normal_path_tbl)
11647 flow_dv_tbl_resource_release(MLX5_SH(dev),
11648 resource->normal_path_tbl);
11649 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
11654 struct mlx5_list_entry *
11655 flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
11656 struct mlx5_list_entry *entry __rte_unused,
11659 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11660 struct rte_eth_dev *dev = ctx->dev;
11661 struct mlx5_flow_dv_sample_resource *resource;
11662 struct mlx5_priv *priv = dev->data->dev_private;
11663 struct mlx5_dev_ctx_shared *sh = priv->sh;
11666 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11668 rte_flow_error_set(ctx->error, ENOMEM,
11669 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11671 "cannot allocate resource memory");
11674 memcpy(resource, entry, sizeof(*resource));
11675 resource->idx = idx;
11676 resource->dev = dev;
11677 return &resource->entry;
11681 flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
11682 struct mlx5_list_entry *entry)
11684 struct mlx5_flow_dv_sample_resource *resource =
11685 container_of(entry, typeof(*resource), entry);
11686 struct rte_eth_dev *dev = resource->dev;
11687 struct mlx5_priv *priv = dev->data->dev_private;
11689 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
11693 * Find existing sample resource or create and register a new one.
11695 * @param[in, out] dev
11696 * Pointer to rte_eth_dev structure.
11698 * Pointer to sample resource reference.
11699 * @parm[in, out] dev_flow
11700 * Pointer to the dev_flow.
11701 * @param[out] error
11702 * pointer to error structure.
11705 * 0 on success otherwise -errno and errno is set.
11708 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
11709 struct mlx5_flow_dv_sample_resource *ref,
11710 struct mlx5_flow *dev_flow,
11711 struct rte_flow_error *error)
11713 struct mlx5_flow_dv_sample_resource *resource;
11714 struct mlx5_list_entry *entry;
11715 struct mlx5_priv *priv = dev->data->dev_private;
11716 struct mlx5_flow_cb_ctx ctx = {
11722 entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
11725 resource = container_of(entry, typeof(*resource), entry);
11726 dev_flow->handle->dvh.rix_sample = resource->idx;
11727 dev_flow->dv.sample_res = resource;
11732 flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
11733 struct mlx5_list_entry *entry, void *cb_ctx)
11735 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11736 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11737 struct rte_eth_dev *dev = ctx->dev;
11738 struct mlx5_flow_dv_dest_array_resource *resource =
11739 container_of(entry, typeof(*resource), entry);
11742 if (ctx_resource->num_of_dest == resource->num_of_dest &&
11743 ctx_resource->ft_type == resource->ft_type &&
11744 !memcmp((void *)resource->sample_act,
11745 (void *)ctx_resource->sample_act,
11746 (ctx_resource->num_of_dest *
11747 sizeof(struct mlx5_flow_sub_actions_list)))) {
11749 * Existing sample action should release the prepared
11750 * sub-actions reference counter.
11752 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11753 flow_dv_sample_sub_actions_release(dev,
11754 &ctx_resource->sample_idx[idx]);
11760 struct mlx5_list_entry *
11761 flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11763 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11764 struct rte_eth_dev *dev = ctx->dev;
11765 struct mlx5_flow_dv_dest_array_resource *resource;
11766 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11767 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
11768 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
11769 struct mlx5_priv *priv = dev->data->dev_private;
11770 struct mlx5_dev_ctx_shared *sh = priv->sh;
11771 struct mlx5_flow_sub_actions_list *sample_act;
11772 struct mlx5dv_dr_domain *domain;
11773 uint32_t idx = 0, res_idx = 0;
11774 struct rte_flow_error *error = ctx->error;
11775 uint64_t action_flags;
11778 /* Register new destination array resource. */
11779 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11782 rte_flow_error_set(error, ENOMEM,
11783 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11785 "cannot allocate resource memory");
11788 *resource = *ctx_resource;
11789 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11790 domain = sh->fdb_domain;
11791 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
11792 domain = sh->rx_domain;
11794 domain = sh->tx_domain;
11795 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11796 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
11797 mlx5_malloc(MLX5_MEM_ZERO,
11798 sizeof(struct mlx5dv_dr_action_dest_attr),
11800 if (!dest_attr[idx]) {
11801 rte_flow_error_set(error, ENOMEM,
11802 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11804 "cannot allocate resource memory");
11807 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
11808 sample_act = &ctx_resource->sample_act[idx];
11809 action_flags = sample_act->action_flags;
11810 switch (action_flags) {
11811 case MLX5_FLOW_ACTION_QUEUE:
11812 dest_attr[idx]->dest = sample_act->dr_queue_action;
11814 case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
11815 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
11816 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
11817 dest_attr[idx]->dest_reformat->reformat =
11818 sample_act->dr_encap_action;
11819 dest_attr[idx]->dest_reformat->dest =
11820 sample_act->dr_port_id_action;
11822 case MLX5_FLOW_ACTION_PORT_ID:
11823 dest_attr[idx]->dest = sample_act->dr_port_id_action;
11825 case MLX5_FLOW_ACTION_JUMP:
11826 dest_attr[idx]->dest = sample_act->dr_jump_action;
11829 rte_flow_error_set(error, EINVAL,
11830 RTE_FLOW_ERROR_TYPE_ACTION,
11832 "unsupported actions type");
11836 /* create a dest array action */
11837 ret = mlx5_os_flow_dr_create_flow_action_dest_array
11839 resource->num_of_dest,
11841 &resource->action);
11843 rte_flow_error_set(error, ENOMEM,
11844 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11846 "cannot create destination array action");
11849 resource->idx = res_idx;
11850 resource->dev = dev;
11851 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11852 mlx5_free(dest_attr[idx]);
11853 return &resource->entry;
11855 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11856 flow_dv_sample_sub_actions_release(dev,
11857 &resource->sample_idx[idx]);
11858 if (dest_attr[idx])
11859 mlx5_free(dest_attr[idx]);
11861 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
11865 struct mlx5_list_entry *
11866 flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
11867 struct mlx5_list_entry *entry __rte_unused,
11870 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11871 struct rte_eth_dev *dev = ctx->dev;
11872 struct mlx5_flow_dv_dest_array_resource *resource;
11873 struct mlx5_priv *priv = dev->data->dev_private;
11874 struct mlx5_dev_ctx_shared *sh = priv->sh;
11875 uint32_t res_idx = 0;
11876 struct rte_flow_error *error = ctx->error;
11878 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11881 rte_flow_error_set(error, ENOMEM,
11882 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11884 "cannot allocate dest-array memory");
11887 memcpy(resource, entry, sizeof(*resource));
11888 resource->idx = res_idx;
11889 resource->dev = dev;
11890 return &resource->entry;
11894 flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
11895 struct mlx5_list_entry *entry)
11897 struct mlx5_flow_dv_dest_array_resource *resource =
11898 container_of(entry, typeof(*resource), entry);
11899 struct rte_eth_dev *dev = resource->dev;
11900 struct mlx5_priv *priv = dev->data->dev_private;
11902 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
11906 * Find existing destination array resource or create and register a new one.
11908 * @param[in, out] dev
11909 * Pointer to rte_eth_dev structure.
11911 * Pointer to destination array resource reference.
11912 * @parm[in, out] dev_flow
11913 * Pointer to the dev_flow.
11914 * @param[out] error
11915 * pointer to error structure.
11918 * 0 on success otherwise -errno and errno is set.
11921 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
11922 struct mlx5_flow_dv_dest_array_resource *ref,
11923 struct mlx5_flow *dev_flow,
11924 struct rte_flow_error *error)
11926 struct mlx5_flow_dv_dest_array_resource *resource;
11927 struct mlx5_priv *priv = dev->data->dev_private;
11928 struct mlx5_list_entry *entry;
11929 struct mlx5_flow_cb_ctx ctx = {
11935 entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
11938 resource = container_of(entry, typeof(*resource), entry);
11939 dev_flow->handle->dvh.rix_dest_array = resource->idx;
11940 dev_flow->dv.dest_array_res = resource;
11945 * Convert Sample action to DV specification.
11948 * Pointer to rte_eth_dev structure.
11949 * @param[in] action
11950 * Pointer to sample action structure.
11951 * @param[in, out] dev_flow
11952 * Pointer to the mlx5_flow.
11954 * Pointer to the flow attributes.
11955 * @param[in, out] num_of_dest
11956 * Pointer to the num of destination.
11957 * @param[in, out] sample_actions
11958 * Pointer to sample actions list.
11959 * @param[in, out] res
11960 * Pointer to sample resource.
11961 * @param[out] error
11962 * Pointer to the error structure.
11965 * 0 on success, a negative errno value otherwise and rte_errno is set.
11968 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
11969 const struct rte_flow_action_sample *action,
11970 struct mlx5_flow *dev_flow,
11971 const struct rte_flow_attr *attr,
11972 uint32_t *num_of_dest,
11973 void **sample_actions,
11974 struct mlx5_flow_dv_sample_resource *res,
11975 struct rte_flow_error *error)
11977 struct mlx5_priv *priv = dev->data->dev_private;
11978 const struct rte_flow_action *sub_actions;
11979 struct mlx5_flow_sub_actions_list *sample_act;
11980 struct mlx5_flow_sub_actions_idx *sample_idx;
11981 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11982 struct rte_flow *flow = dev_flow->flow;
11983 struct mlx5_flow_rss_desc *rss_desc;
11984 uint64_t action_flags = 0;
11987 rss_desc = &wks->rss_desc;
11988 sample_act = &res->sample_act;
11989 sample_idx = &res->sample_idx;
11990 res->ratio = action->ratio;
11991 sub_actions = action->actions;
11992 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
11993 int type = sub_actions->type;
11994 uint32_t pre_rix = 0;
11997 case RTE_FLOW_ACTION_TYPE_QUEUE:
11999 const struct rte_flow_action_queue *queue;
12000 struct mlx5_hrxq *hrxq;
12003 queue = sub_actions->conf;
12004 rss_desc->queue_num = 1;
12005 rss_desc->queue[0] = queue->index;
12006 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
12007 rss_desc, &hrxq_idx);
12009 return rte_flow_error_set
12011 RTE_FLOW_ERROR_TYPE_ACTION,
12013 "cannot create fate queue");
12014 sample_act->dr_queue_action = hrxq->action;
12015 sample_idx->rix_hrxq = hrxq_idx;
12016 sample_actions[sample_act->actions_num++] =
12019 action_flags |= MLX5_FLOW_ACTION_QUEUE;
12020 if (action_flags & MLX5_FLOW_ACTION_MARK)
12021 dev_flow->handle->rix_hrxq = hrxq_idx;
12022 dev_flow->handle->fate_action =
12023 MLX5_FLOW_FATE_QUEUE;
12026 case RTE_FLOW_ACTION_TYPE_RSS:
12028 struct mlx5_hrxq *hrxq;
12030 const struct rte_flow_action_rss *rss;
12031 const uint8_t *rss_key;
12033 rss = sub_actions->conf;
12034 memcpy(rss_desc->queue, rss->queue,
12035 rss->queue_num * sizeof(uint16_t));
12036 rss_desc->queue_num = rss->queue_num;
12037 /* NULL RSS key indicates default RSS key. */
12038 rss_key = !rss->key ? rss_hash_default_key : rss->key;
12039 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12041 * rss->level and rss.types should be set in advance
12042 * when expanding items for RSS.
12044 flow_dv_hashfields_set(dev_flow->handle->layers,
12046 &dev_flow->hash_fields);
12047 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
12048 rss_desc, &hrxq_idx);
12050 return rte_flow_error_set
12052 RTE_FLOW_ERROR_TYPE_ACTION,
12054 "cannot create fate queue");
12055 sample_act->dr_queue_action = hrxq->action;
12056 sample_idx->rix_hrxq = hrxq_idx;
12057 sample_actions[sample_act->actions_num++] =
12060 action_flags |= MLX5_FLOW_ACTION_RSS;
12061 if (action_flags & MLX5_FLOW_ACTION_MARK)
12062 dev_flow->handle->rix_hrxq = hrxq_idx;
12063 dev_flow->handle->fate_action =
12064 MLX5_FLOW_FATE_QUEUE;
12067 case RTE_FLOW_ACTION_TYPE_MARK:
12069 uint32_t tag_be = mlx5_flow_mark_set
12070 (((const struct rte_flow_action_mark *)
12071 (sub_actions->conf))->id);
12074 pre_rix = dev_flow->handle->dvh.rix_tag;
12075 /* Save the mark resource before sample */
12076 pre_r = dev_flow->dv.tag_resource;
12077 if (flow_dv_tag_resource_register(dev, tag_be,
12080 MLX5_ASSERT(dev_flow->dv.tag_resource);
12081 sample_act->dr_tag_action =
12082 dev_flow->dv.tag_resource->action;
12083 sample_idx->rix_tag =
12084 dev_flow->handle->dvh.rix_tag;
12085 sample_actions[sample_act->actions_num++] =
12086 sample_act->dr_tag_action;
12087 /* Recover the mark resource after sample */
12088 dev_flow->dv.tag_resource = pre_r;
12089 dev_flow->handle->dvh.rix_tag = pre_rix;
12090 action_flags |= MLX5_FLOW_ACTION_MARK;
12093 case RTE_FLOW_ACTION_TYPE_COUNT:
12095 if (!flow->counter) {
12097 flow_dv_translate_create_counter(dev,
12098 dev_flow, sub_actions->conf,
12100 if (!flow->counter)
12101 return rte_flow_error_set
12103 RTE_FLOW_ERROR_TYPE_ACTION,
12105 "cannot create counter"
12108 sample_act->dr_cnt_action =
12109 (flow_dv_counter_get_by_idx(dev,
12110 flow->counter, NULL))->action;
12111 sample_actions[sample_act->actions_num++] =
12112 sample_act->dr_cnt_action;
12113 action_flags |= MLX5_FLOW_ACTION_COUNT;
12116 case RTE_FLOW_ACTION_TYPE_PORT_ID:
12117 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
12119 struct mlx5_flow_dv_port_id_action_resource
12121 uint32_t port_id = 0;
12123 memset(&port_id_resource, 0, sizeof(port_id_resource));
12124 /* Save the port id resource before sample */
12125 pre_rix = dev_flow->handle->rix_port_id_action;
12126 pre_r = dev_flow->dv.port_id_action;
12127 if (flow_dv_translate_action_port_id(dev, sub_actions,
12130 port_id_resource.port_id = port_id;
12131 if (flow_dv_port_id_action_resource_register
12132 (dev, &port_id_resource, dev_flow, error))
12134 sample_act->dr_port_id_action =
12135 dev_flow->dv.port_id_action->action;
12136 sample_idx->rix_port_id_action =
12137 dev_flow->handle->rix_port_id_action;
12138 sample_actions[sample_act->actions_num++] =
12139 sample_act->dr_port_id_action;
12140 /* Recover the port id resource after sample */
12141 dev_flow->dv.port_id_action = pre_r;
12142 dev_flow->handle->rix_port_id_action = pre_rix;
12144 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12147 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
12148 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
12149 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
12150 /* Save the encap resource before sample */
12151 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
12152 pre_r = dev_flow->dv.encap_decap;
12153 if (flow_dv_create_action_l2_encap(dev, sub_actions,
12158 sample_act->dr_encap_action =
12159 dev_flow->dv.encap_decap->action;
12160 sample_idx->rix_encap_decap =
12161 dev_flow->handle->dvh.rix_encap_decap;
12162 sample_actions[sample_act->actions_num++] =
12163 sample_act->dr_encap_action;
12164 /* Recover the encap resource after sample */
12165 dev_flow->dv.encap_decap = pre_r;
12166 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
12167 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12170 return rte_flow_error_set(error, EINVAL,
12171 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12173 "Not support for sampler action");
12176 sample_act->action_flags = action_flags;
12177 res->ft_id = dev_flow->dv.group;
12178 if (attr->transfer) {
12180 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
12181 uint64_t set_action;
12182 } action_ctx = { .set_action = 0 };
12184 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12185 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
12186 MLX5_MODIFICATION_TYPE_SET);
12187 MLX5_SET(set_action_in, action_ctx.action_in, field,
12188 MLX5_MODI_META_REG_C_0);
12189 MLX5_SET(set_action_in, action_ctx.action_in, data,
12190 priv->vport_meta_tag);
12191 res->set_action = action_ctx.set_action;
12192 } else if (attr->ingress) {
12193 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12195 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
12201 * Convert Sample action to DV specification.
12204 * Pointer to rte_eth_dev structure.
12205 * @param[in, out] dev_flow
12206 * Pointer to the mlx5_flow.
12207 * @param[in] num_of_dest
12208 * The num of destination.
12209 * @param[in, out] res
12210 * Pointer to sample resource.
12211 * @param[in, out] mdest_res
12212 * Pointer to destination array resource.
12213 * @param[in] sample_actions
12214 * Pointer to sample path actions list.
12215 * @param[in] action_flags
12216 * Holds the actions detected until now.
12217 * @param[out] error
12218 * Pointer to the error structure.
12221 * 0 on success, a negative errno value otherwise and rte_errno is set.
12224 flow_dv_create_action_sample(struct rte_eth_dev *dev,
12225 struct mlx5_flow *dev_flow,
12226 uint32_t num_of_dest,
12227 struct mlx5_flow_dv_sample_resource *res,
12228 struct mlx5_flow_dv_dest_array_resource *mdest_res,
12229 void **sample_actions,
12230 uint64_t action_flags,
12231 struct rte_flow_error *error)
12233 /* update normal path action resource into last index of array */
12234 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
12235 struct mlx5_flow_sub_actions_list *sample_act =
12236 &mdest_res->sample_act[dest_index];
12237 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12238 struct mlx5_flow_rss_desc *rss_desc;
12239 uint32_t normal_idx = 0;
12240 struct mlx5_hrxq *hrxq;
12244 rss_desc = &wks->rss_desc;
12245 if (num_of_dest > 1) {
12246 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
12247 /* Handle QP action for mirroring */
12248 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
12249 rss_desc, &hrxq_idx);
12251 return rte_flow_error_set
12253 RTE_FLOW_ERROR_TYPE_ACTION,
12255 "cannot create rx queue");
12257 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
12258 sample_act->dr_queue_action = hrxq->action;
12259 if (action_flags & MLX5_FLOW_ACTION_MARK)
12260 dev_flow->handle->rix_hrxq = hrxq_idx;
12261 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
12263 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
12265 mdest_res->sample_idx[dest_index].rix_encap_decap =
12266 dev_flow->handle->dvh.rix_encap_decap;
12267 sample_act->dr_encap_action =
12268 dev_flow->dv.encap_decap->action;
12269 dev_flow->handle->dvh.rix_encap_decap = 0;
12271 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
12273 mdest_res->sample_idx[dest_index].rix_port_id_action =
12274 dev_flow->handle->rix_port_id_action;
12275 sample_act->dr_port_id_action =
12276 dev_flow->dv.port_id_action->action;
12277 dev_flow->handle->rix_port_id_action = 0;
12279 if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
12281 mdest_res->sample_idx[dest_index].rix_jump =
12282 dev_flow->handle->rix_jump;
12283 sample_act->dr_jump_action =
12284 dev_flow->dv.jump->action;
12285 dev_flow->handle->rix_jump = 0;
12287 sample_act->actions_num = normal_idx;
12288 /* update sample action resource into first index of array */
12289 mdest_res->ft_type = res->ft_type;
12290 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
12291 sizeof(struct mlx5_flow_sub_actions_idx));
12292 memcpy(&mdest_res->sample_act[0], &res->sample_act,
12293 sizeof(struct mlx5_flow_sub_actions_list));
12294 mdest_res->num_of_dest = num_of_dest;
12295 if (flow_dv_dest_array_resource_register(dev, mdest_res,
12297 return rte_flow_error_set(error, EINVAL,
12298 RTE_FLOW_ERROR_TYPE_ACTION,
12299 NULL, "can't create sample "
12302 res->sub_actions = sample_actions;
12303 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
12304 return rte_flow_error_set(error, EINVAL,
12305 RTE_FLOW_ERROR_TYPE_ACTION,
12307 "can't create sample action");
12313 * Remove an ASO age action from age actions list.
12316 * Pointer to the Ethernet device structure.
12318 * Pointer to the aso age action handler.
12321 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
12322 struct mlx5_aso_age_action *age)
12324 struct mlx5_age_info *age_info;
12325 struct mlx5_age_param *age_param = &age->age_params;
12326 struct mlx5_priv *priv = dev->data->dev_private;
12327 uint16_t expected = AGE_CANDIDATE;
12329 age_info = GET_PORT_AGE_INFO(priv);
12330 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
12331 AGE_FREE, false, __ATOMIC_RELAXED,
12332 __ATOMIC_RELAXED)) {
12334 * We need the lock even it is age timeout,
12335 * since age action may still in process.
12337 rte_spinlock_lock(&age_info->aged_sl);
12338 LIST_REMOVE(age, next);
12339 rte_spinlock_unlock(&age_info->aged_sl);
12340 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
12345 * Release an ASO age action.
12348 * Pointer to the Ethernet device structure.
12349 * @param[in] age_idx
12350 * Index of ASO age action to release.
12352 * True if the release operation is during flow destroy operation.
12353 * False if the release operation is during action destroy operation.
12356 * 0 when age action was removed, otherwise the number of references.
12359 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
12361 struct mlx5_priv *priv = dev->data->dev_private;
12362 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12363 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
12364 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
12367 flow_dv_aso_age_remove_from_age(dev, age);
12368 rte_spinlock_lock(&mng->free_sl);
12369 LIST_INSERT_HEAD(&mng->free, age, next);
12370 rte_spinlock_unlock(&mng->free_sl);
12376 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
12379 * Pointer to the Ethernet device structure.
12382 * 0 on success, otherwise negative errno value and rte_errno is set.
12385 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
12387 struct mlx5_priv *priv = dev->data->dev_private;
12388 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12389 void *old_pools = mng->pools;
12390 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
12391 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
12392 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
12395 rte_errno = ENOMEM;
12399 memcpy(pools, old_pools,
12400 mng->n * sizeof(struct mlx5_flow_counter_pool *));
12401 mlx5_free(old_pools);
12403 /* First ASO flow hit allocation - starting ASO data-path. */
12404 int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
12412 mng->pools = pools;
12417 * Create and initialize a new ASO aging pool.
12420 * Pointer to the Ethernet device structure.
12421 * @param[out] age_free
12422 * Where to put the pointer of a new age action.
12425 * The age actions pool pointer and @p age_free is set on success,
12426 * NULL otherwise and rte_errno is set.
12428 static struct mlx5_aso_age_pool *
12429 flow_dv_age_pool_create(struct rte_eth_dev *dev,
12430 struct mlx5_aso_age_action **age_free)
12432 struct mlx5_priv *priv = dev->data->dev_private;
12433 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12434 struct mlx5_aso_age_pool *pool = NULL;
12435 struct mlx5_devx_obj *obj = NULL;
12438 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
12439 priv->sh->cdev->pdn);
12441 rte_errno = ENODATA;
12442 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
12445 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
12447 claim_zero(mlx5_devx_cmd_destroy(obj));
12448 rte_errno = ENOMEM;
12451 pool->flow_hit_aso_obj = obj;
12452 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
12453 rte_rwlock_write_lock(&mng->resize_rwl);
12454 pool->index = mng->next;
12455 /* Resize pools array if there is no room for the new pool in it. */
12456 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
12457 claim_zero(mlx5_devx_cmd_destroy(obj));
12459 rte_rwlock_write_unlock(&mng->resize_rwl);
12462 mng->pools[pool->index] = pool;
12464 rte_rwlock_write_unlock(&mng->resize_rwl);
12465 /* Assign the first action in the new pool, the rest go to free list. */
12466 *age_free = &pool->actions[0];
12467 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
12468 pool->actions[i].offset = i;
12469 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
12475 * Allocate a ASO aging bit.
12478 * Pointer to the Ethernet device structure.
12479 * @param[out] error
12480 * Pointer to the error structure.
12483 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
12486 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
12488 struct mlx5_priv *priv = dev->data->dev_private;
12489 const struct mlx5_aso_age_pool *pool;
12490 struct mlx5_aso_age_action *age_free = NULL;
12491 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12494 /* Try to get the next free age action bit. */
12495 rte_spinlock_lock(&mng->free_sl);
12496 age_free = LIST_FIRST(&mng->free);
12498 LIST_REMOVE(age_free, next);
12499 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
12500 rte_spinlock_unlock(&mng->free_sl);
12501 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
12502 NULL, "failed to create ASO age pool");
12503 return 0; /* 0 is an error. */
12505 rte_spinlock_unlock(&mng->free_sl);
12506 pool = container_of
12507 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
12508 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
12510 if (!age_free->dr_action) {
12511 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
12515 rte_flow_error_set(error, rte_errno,
12516 RTE_FLOW_ERROR_TYPE_ACTION,
12517 NULL, "failed to get reg_c "
12518 "for ASO flow hit");
12519 return 0; /* 0 is an error. */
12521 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
12522 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
12523 (priv->sh->rx_domain,
12524 pool->flow_hit_aso_obj->obj, age_free->offset,
12525 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
12526 (reg_c - REG_C_0));
12527 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
12528 if (!age_free->dr_action) {
12530 rte_spinlock_lock(&mng->free_sl);
12531 LIST_INSERT_HEAD(&mng->free, age_free, next);
12532 rte_spinlock_unlock(&mng->free_sl);
12533 rte_flow_error_set(error, rte_errno,
12534 RTE_FLOW_ERROR_TYPE_ACTION,
12535 NULL, "failed to create ASO "
12536 "flow hit action");
12537 return 0; /* 0 is an error. */
12540 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
12541 return pool->index | ((age_free->offset + 1) << 16);
12545 * Initialize flow ASO age parameters.
12548 * Pointer to rte_eth_dev structure.
12549 * @param[in] age_idx
12550 * Index of ASO age action.
12551 * @param[in] context
12552 * Pointer to flow counter age context.
12553 * @param[in] timeout
12554 * Aging timeout in seconds.
12558 flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
12563 struct mlx5_aso_age_action *aso_age;
12565 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
12566 MLX5_ASSERT(aso_age);
12567 aso_age->age_params.context = context;
12568 aso_age->age_params.timeout = timeout;
12569 aso_age->age_params.port_id = dev->data->port_id;
12570 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
12572 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
12577 flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
12578 const struct rte_flow_item_integrity *value,
12579 void *headers_m, void *headers_v)
12582 /* RTE l4_ok filter aggregates hardware l4_ok and
12583 * l4_checksum_ok filters.
12584 * Positive RTE l4_ok match requires hardware match on both L4
12585 * hardware integrity bits.
12586 * For negative match, check hardware l4_checksum_ok bit only,
12587 * because hardware sets that bit to 0 for all packets
12590 if (value->l4_ok) {
12591 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_ok, 1);
12592 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_ok, 1);
12594 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok, 1);
12595 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_checksum_ok,
12598 if (mask->l4_csum_ok) {
12599 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok, 1);
12600 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_checksum_ok,
12601 value->l4_csum_ok);
12606 flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
12607 const struct rte_flow_item_integrity *value,
12608 void *headers_m, void *headers_v, bool is_ipv4)
12611 /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
12612 * ipv4_csum_ok filters.
12613 * Positive RTE l3_ok match requires hardware match on both L3
12614 * hardware integrity bits.
12615 * For negative match, check hardware l3_csum_ok bit only,
12616 * because hardware sets that bit to 0 for all packets
12620 if (value->l3_ok) {
12621 MLX5_SET(fte_match_set_lyr_2_4, headers_m,
12623 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12626 MLX5_SET(fte_match_set_lyr_2_4, headers_m,
12627 ipv4_checksum_ok, 1);
12628 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12629 ipv4_checksum_ok, !!value->l3_ok);
12631 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l3_ok, 1);
12632 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l3_ok,
12636 if (mask->ipv4_csum_ok) {
12637 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok, 1);
12638 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
12639 value->ipv4_csum_ok);
12644 set_integrity_bits(void *headers_m, void *headers_v,
12645 const struct rte_flow_item *integrity_item, bool is_l3_ip4)
12647 const struct rte_flow_item_integrity *spec = integrity_item->spec;
12648 const struct rte_flow_item_integrity *mask = integrity_item->mask;
12650 /* Integrity bits validation cleared spec pointer */
12651 MLX5_ASSERT(spec != NULL);
12653 mask = &rte_flow_item_integrity_mask;
12654 flow_dv_translate_integrity_l3(mask, spec, headers_m, headers_v,
12656 flow_dv_translate_integrity_l4(mask, spec, headers_m, headers_v);
12660 flow_dv_translate_item_integrity_post(void *matcher, void *key,
12662 struct rte_flow_item *integrity_items[2],
12663 uint64_t pattern_flags)
12665 void *headers_m, *headers_v;
12668 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
12669 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12671 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
12672 is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
12674 set_integrity_bits(headers_m, headers_v,
12675 integrity_items[1], is_l3_ip4);
12677 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
12678 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12680 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
12681 is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
12683 set_integrity_bits(headers_m, headers_v,
12684 integrity_items[0], is_l3_ip4);
12689 flow_dv_translate_item_integrity(const struct rte_flow_item *item,
12690 const struct rte_flow_item *integrity_items[2],
12691 uint64_t *last_item)
12693 const struct rte_flow_item_integrity *spec = (typeof(spec))item->spec;
12695 /* integrity bits validation cleared spec pointer */
12696 MLX5_ASSERT(spec != NULL);
12697 if (spec->level > 1) {
12698 integrity_items[1] = item;
12699 *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
12701 integrity_items[0] = item;
12702 *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
12707 * Prepares DV flow counter with aging configuration.
12708 * Gets it by index when exists, creates a new one when doesn't.
12711 * Pointer to rte_eth_dev structure.
12712 * @param[in] dev_flow
12713 * Pointer to the mlx5_flow.
12714 * @param[in, out] flow
12715 * Pointer to the sub flow.
12717 * Pointer to the counter action configuration.
12719 * Pointer to the aging action configuration.
12720 * @param[out] error
12721 * Pointer to the error structure.
12724 * Pointer to the counter, NULL otherwise.
12726 static struct mlx5_flow_counter *
12727 flow_dv_prepare_counter(struct rte_eth_dev *dev,
12728 struct mlx5_flow *dev_flow,
12729 struct rte_flow *flow,
12730 const struct rte_flow_action_count *count,
12731 const struct rte_flow_action_age *age,
12732 struct rte_flow_error *error)
12734 if (!flow->counter) {
12735 flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
12737 if (!flow->counter) {
12738 rte_flow_error_set(error, rte_errno,
12739 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12740 "cannot create counter object.");
12744 return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
12748 * Release an ASO CT action by its own device.
12751 * Pointer to the Ethernet device structure.
12753 * Index of ASO CT action to release.
12756 * 0 when CT action was removed, otherwise the number of references.
12759 flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
12761 struct mlx5_priv *priv = dev->data->dev_private;
12762 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12764 struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12765 enum mlx5_aso_ct_state state =
12766 __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
12768 /* Cannot release when CT is in the ASO SQ. */
12769 if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
12771 ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
12773 if (ct->dr_action_orig) {
12774 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12775 claim_zero(mlx5_glue->destroy_flow_action
12776 (ct->dr_action_orig));
12778 ct->dr_action_orig = NULL;
12780 if (ct->dr_action_rply) {
12781 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12782 claim_zero(mlx5_glue->destroy_flow_action
12783 (ct->dr_action_rply));
12785 ct->dr_action_rply = NULL;
12787 /* Clear the state to free, no need in 1st allocation. */
12788 MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
12789 rte_spinlock_lock(&mng->ct_sl);
12790 LIST_INSERT_HEAD(&mng->free_cts, ct, next);
12791 rte_spinlock_unlock(&mng->ct_sl);
12797 flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
12798 struct rte_flow_error *error)
12800 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
12801 uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
12802 struct rte_eth_dev *owndev = &rte_eth_devices[owner];
12805 MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
12806 if (dev->data->dev_started != 1)
12807 return rte_flow_error_set(error, EAGAIN,
12808 RTE_FLOW_ERROR_TYPE_ACTION,
12810 "Indirect CT action cannot be destroyed when the port is stopped");
12811 ret = flow_dv_aso_ct_dev_release(owndev, idx);
12813 return rte_flow_error_set(error, EAGAIN,
12814 RTE_FLOW_ERROR_TYPE_ACTION,
12816 "Current state prevents indirect CT action from being destroyed");
12821 * Resize the ASO CT pools array by 64 pools.
12824 * Pointer to the Ethernet device structure.
12827 * 0 on success, otherwise negative errno value and rte_errno is set.
12830 flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
12832 struct mlx5_priv *priv = dev->data->dev_private;
12833 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12834 void *old_pools = mng->pools;
12835 /* Magic number now, need a macro. */
12836 uint32_t resize = mng->n + 64;
12837 uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
12838 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
12841 rte_errno = ENOMEM;
12844 rte_rwlock_write_lock(&mng->resize_rwl);
12845 /* ASO SQ/QP was already initialized in the startup. */
12847 /* Realloc could be an alternative choice. */
12848 rte_memcpy(pools, old_pools,
12849 mng->n * sizeof(struct mlx5_aso_ct_pool *));
12850 mlx5_free(old_pools);
12853 mng->pools = pools;
12854 rte_rwlock_write_unlock(&mng->resize_rwl);
12859 * Create and initialize a new ASO CT pool.
12862 * Pointer to the Ethernet device structure.
12863 * @param[out] ct_free
12864 * Where to put the pointer of a new CT action.
12867 * The CT actions pool pointer and @p ct_free is set on success,
12868 * NULL otherwise and rte_errno is set.
12870 static struct mlx5_aso_ct_pool *
12871 flow_dv_ct_pool_create(struct rte_eth_dev *dev,
12872 struct mlx5_aso_ct_action **ct_free)
12874 struct mlx5_priv *priv = dev->data->dev_private;
12875 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12876 struct mlx5_aso_ct_pool *pool = NULL;
12877 struct mlx5_devx_obj *obj = NULL;
12879 uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
12881 obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
12882 priv->sh->cdev->pdn,
12885 rte_errno = ENODATA;
12886 DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
12889 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
12891 rte_errno = ENOMEM;
12892 claim_zero(mlx5_devx_cmd_destroy(obj));
12895 pool->devx_obj = obj;
12896 pool->index = mng->next;
12897 /* Resize pools array if there is no room for the new pool in it. */
12898 if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
12899 claim_zero(mlx5_devx_cmd_destroy(obj));
12903 mng->pools[pool->index] = pool;
12905 /* Assign the first action in the new pool, the rest go to free list. */
12906 *ct_free = &pool->actions[0];
12907 /* Lock outside, the list operation is safe here. */
12908 for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
12909 /* refcnt is 0 when allocating the memory. */
12910 pool->actions[i].offset = i;
12911 LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
12917 * Allocate a ASO CT action from free list.
12920 * Pointer to the Ethernet device structure.
12921 * @param[out] error
12922 * Pointer to the error structure.
12925 * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
12928 flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
12930 struct mlx5_priv *priv = dev->data->dev_private;
12931 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12932 struct mlx5_aso_ct_action *ct = NULL;
12933 struct mlx5_aso_ct_pool *pool;
12938 if (!priv->sh->cdev->config.devx) {
12939 rte_errno = ENOTSUP;
12942 /* Get a free CT action, if no, a new pool will be created. */
12943 rte_spinlock_lock(&mng->ct_sl);
12944 ct = LIST_FIRST(&mng->free_cts);
12946 LIST_REMOVE(ct, next);
12947 } else if (!flow_dv_ct_pool_create(dev, &ct)) {
12948 rte_spinlock_unlock(&mng->ct_sl);
12949 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
12950 NULL, "failed to create ASO CT pool");
12953 rte_spinlock_unlock(&mng->ct_sl);
12954 pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
12955 ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
12956 /* 0: inactive, 1: created, 2+: used by flows. */
12957 __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
12958 reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
12959 if (!ct->dr_action_orig) {
12960 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12961 ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
12962 (priv->sh->rx_domain, pool->devx_obj->obj,
12964 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
12967 RTE_SET_USED(reg_c);
12969 if (!ct->dr_action_orig) {
12970 flow_dv_aso_ct_dev_release(dev, ct_idx);
12971 rte_flow_error_set(error, rte_errno,
12972 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12973 "failed to create ASO CT action");
12977 if (!ct->dr_action_rply) {
12978 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12979 ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
12980 (priv->sh->rx_domain, pool->devx_obj->obj,
12982 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
12985 if (!ct->dr_action_rply) {
12986 flow_dv_aso_ct_dev_release(dev, ct_idx);
12987 rte_flow_error_set(error, rte_errno,
12988 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12989 "failed to create ASO CT action");
12997 * Create a conntrack object with context and actions by using ASO mechanism.
13000 * Pointer to rte_eth_dev structure.
13002 * Pointer to conntrack information profile.
13003 * @param[out] error
13004 * Pointer to the error structure.
13007 * Index to conntrack object on success, 0 otherwise.
13010 flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
13011 const struct rte_flow_action_conntrack *pro,
13012 struct rte_flow_error *error)
13014 struct mlx5_priv *priv = dev->data->dev_private;
13015 struct mlx5_dev_ctx_shared *sh = priv->sh;
13016 struct mlx5_aso_ct_action *ct;
13019 if (!sh->ct_aso_en)
13020 return rte_flow_error_set(error, ENOTSUP,
13021 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13022 "Connection is not supported");
13023 idx = flow_dv_aso_ct_alloc(dev, error);
13025 return rte_flow_error_set(error, rte_errno,
13026 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13027 "Failed to allocate CT object");
13028 ct = flow_aso_ct_get_by_dev_idx(dev, idx);
13029 if (mlx5_aso_ct_update_by_wqe(sh, ct, pro))
13030 return rte_flow_error_set(error, EBUSY,
13031 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13032 "Failed to update CT");
13033 ct->is_original = !!pro->is_original_dir;
13034 ct->peer = pro->peer_port;
13039 * Fill the flow with DV spec, lock free
13040 * (mutex should be acquired by caller).
13043 * Pointer to rte_eth_dev structure.
13044 * @param[in, out] dev_flow
13045 * Pointer to the sub flow.
13047 * Pointer to the flow attributes.
13049 * Pointer to the list of items.
13050 * @param[in] actions
13051 * Pointer to the list of actions.
13052 * @param[out] error
13053 * Pointer to the error structure.
13056 * 0 on success, a negative errno value otherwise and rte_errno is set.
13059 flow_dv_translate(struct rte_eth_dev *dev,
13060 struct mlx5_flow *dev_flow,
13061 const struct rte_flow_attr *attr,
13062 const struct rte_flow_item items[],
13063 const struct rte_flow_action actions[],
13064 struct rte_flow_error *error)
13066 struct mlx5_priv *priv = dev->data->dev_private;
13067 struct mlx5_sh_config *dev_conf = &priv->sh->config;
13068 struct rte_flow *flow = dev_flow->flow;
13069 struct mlx5_flow_handle *handle = dev_flow->handle;
13070 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13071 struct mlx5_flow_rss_desc *rss_desc;
13072 uint64_t item_flags = 0;
13073 uint64_t last_item = 0;
13074 uint64_t action_flags = 0;
13075 struct mlx5_flow_dv_matcher matcher = {
13077 .size = sizeof(matcher.mask.buf),
13081 bool actions_end = false;
13083 struct mlx5_flow_dv_modify_hdr_resource res;
13084 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
13085 sizeof(struct mlx5_modification_cmd) *
13086 (MLX5_MAX_MODIFY_NUM + 1)];
13088 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
13089 const struct rte_flow_action_count *count = NULL;
13090 const struct rte_flow_action_age *non_shared_age = NULL;
13091 union flow_dv_attr flow_attr = { .attr = 0 };
13093 union mlx5_flow_tbl_key tbl_key;
13094 uint32_t modify_action_position = UINT32_MAX;
13095 void *match_mask = matcher.mask.buf;
13096 void *match_value = dev_flow->dv.value.buf;
13097 uint8_t next_protocol = 0xff;
13098 struct rte_vlan_hdr vlan = { 0 };
13099 struct mlx5_flow_dv_dest_array_resource mdest_res;
13100 struct mlx5_flow_dv_sample_resource sample_res;
13101 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
13102 const struct rte_flow_action_sample *sample = NULL;
13103 struct mlx5_flow_sub_actions_list *sample_act;
13104 uint32_t sample_act_pos = UINT32_MAX;
13105 uint32_t age_act_pos = UINT32_MAX;
13106 uint32_t num_of_dest = 0;
13107 int tmp_actions_n = 0;
13110 const struct mlx5_flow_tunnel *tunnel = NULL;
13111 struct flow_grp_info grp_info = {
13112 .external = !!dev_flow->external,
13113 .transfer = !!attr->transfer,
13114 .fdb_def_rule = !!priv->fdb_def_rule,
13115 .skip_scale = dev_flow->skip_scale &
13116 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
13117 .std_tbl_fix = true,
13119 const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
13120 const struct rte_flow_item *tunnel_item = NULL;
13121 const struct rte_flow_item *gre_item = NULL;
13124 return rte_flow_error_set(error, ENOMEM,
13125 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13127 "failed to push flow workspace");
13128 rss_desc = &wks->rss_desc;
13129 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
13130 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
13131 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
13132 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
13133 /* update normal path action resource into last index of array */
13134 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
13135 if (is_tunnel_offload_active(dev)) {
13136 if (dev_flow->tunnel) {
13137 RTE_VERIFY(dev_flow->tof_type ==
13138 MLX5_TUNNEL_OFFLOAD_MISS_RULE);
13139 tunnel = dev_flow->tunnel;
13141 tunnel = mlx5_get_tof(items, actions,
13142 &dev_flow->tof_type);
13143 dev_flow->tunnel = tunnel;
13145 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
13146 (dev, attr, tunnel, dev_flow->tof_type);
13148 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
13149 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
13150 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
13154 dev_flow->dv.group = table;
13155 if (attr->transfer)
13156 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
13157 /* number of actions must be set to 0 in case of dirty stack. */
13158 mhdr_res->actions_num = 0;
13159 if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
13161 * do not add decap action if match rule drops packet
13162 * HW rejects rules with decap & drop
13164 * if tunnel match rule was inserted before matching tunnel set
13165 * rule flow table used in the match rule must be registered.
13166 * current implementation handles that in the
13167 * flow_dv_match_register() at the function end.
13169 bool add_decap = true;
13170 const struct rte_flow_action *ptr = actions;
13172 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
13173 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
13179 if (flow_dv_create_action_l2_decap(dev, dev_flow,
13183 dev_flow->dv.actions[actions_n++] =
13184 dev_flow->dv.encap_decap->action;
13185 action_flags |= MLX5_FLOW_ACTION_DECAP;
13188 for (; !actions_end ; actions++) {
13189 const struct rte_flow_action_queue *queue;
13190 const struct rte_flow_action_rss *rss;
13191 const struct rte_flow_action *action = actions;
13192 const uint8_t *rss_key;
13193 struct mlx5_flow_tbl_resource *tbl;
13194 struct mlx5_aso_age_action *age_act;
13195 struct mlx5_flow_counter *cnt_act;
13196 uint32_t port_id = 0;
13197 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
13198 int action_type = actions->type;
13199 const struct rte_flow_action *found_action = NULL;
13200 uint32_t jump_group = 0;
13201 uint32_t owner_idx;
13202 struct mlx5_aso_ct_action *ct;
13204 if (!mlx5_flow_os_action_supported(action_type))
13205 return rte_flow_error_set(error, ENOTSUP,
13206 RTE_FLOW_ERROR_TYPE_ACTION,
13208 "action not supported");
13209 switch (action_type) {
13210 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
13211 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
13213 case RTE_FLOW_ACTION_TYPE_VOID:
13215 case RTE_FLOW_ACTION_TYPE_PORT_ID:
13216 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
13217 if (flow_dv_translate_action_port_id(dev, action,
13220 port_id_resource.port_id = port_id;
13221 MLX5_ASSERT(!handle->rix_port_id_action);
13222 if (flow_dv_port_id_action_resource_register
13223 (dev, &port_id_resource, dev_flow, error))
13225 dev_flow->dv.actions[actions_n++] =
13226 dev_flow->dv.port_id_action->action;
13227 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
13228 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
13229 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
13232 case RTE_FLOW_ACTION_TYPE_FLAG:
13233 action_flags |= MLX5_FLOW_ACTION_FLAG;
13235 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
13236 struct rte_flow_action_mark mark = {
13237 .id = MLX5_FLOW_MARK_DEFAULT,
13240 if (flow_dv_convert_action_mark(dev, &mark,
13244 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
13247 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
13249 * Only one FLAG or MARK is supported per device flow
13250 * right now. So the pointer to the tag resource must be
13251 * zero before the register process.
13253 MLX5_ASSERT(!handle->dvh.rix_tag);
13254 if (flow_dv_tag_resource_register(dev, tag_be,
13257 MLX5_ASSERT(dev_flow->dv.tag_resource);
13258 dev_flow->dv.actions[actions_n++] =
13259 dev_flow->dv.tag_resource->action;
13261 case RTE_FLOW_ACTION_TYPE_MARK:
13262 action_flags |= MLX5_FLOW_ACTION_MARK;
13264 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
13265 const struct rte_flow_action_mark *mark =
13266 (const struct rte_flow_action_mark *)
13269 if (flow_dv_convert_action_mark(dev, mark,
13273 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
13277 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
13278 /* Legacy (non-extensive) MARK action. */
13279 tag_be = mlx5_flow_mark_set
13280 (((const struct rte_flow_action_mark *)
13281 (actions->conf))->id);
13282 MLX5_ASSERT(!handle->dvh.rix_tag);
13283 if (flow_dv_tag_resource_register(dev, tag_be,
13286 MLX5_ASSERT(dev_flow->dv.tag_resource);
13287 dev_flow->dv.actions[actions_n++] =
13288 dev_flow->dv.tag_resource->action;
13290 case RTE_FLOW_ACTION_TYPE_SET_META:
13291 if (flow_dv_convert_action_set_meta
13292 (dev, mhdr_res, attr,
13293 (const struct rte_flow_action_set_meta *)
13294 actions->conf, error))
13296 action_flags |= MLX5_FLOW_ACTION_SET_META;
13298 case RTE_FLOW_ACTION_TYPE_SET_TAG:
13299 if (flow_dv_convert_action_set_tag
13301 (const struct rte_flow_action_set_tag *)
13302 actions->conf, error))
13304 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13306 case RTE_FLOW_ACTION_TYPE_DROP:
13307 action_flags |= MLX5_FLOW_ACTION_DROP;
13308 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
13310 case RTE_FLOW_ACTION_TYPE_QUEUE:
13311 queue = actions->conf;
13312 rss_desc->queue_num = 1;
13313 rss_desc->queue[0] = queue->index;
13314 action_flags |= MLX5_FLOW_ACTION_QUEUE;
13315 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
13316 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
13319 case RTE_FLOW_ACTION_TYPE_RSS:
13320 rss = actions->conf;
13321 memcpy(rss_desc->queue, rss->queue,
13322 rss->queue_num * sizeof(uint16_t));
13323 rss_desc->queue_num = rss->queue_num;
13324 /* NULL RSS key indicates default RSS key. */
13325 rss_key = !rss->key ? rss_hash_default_key : rss->key;
13326 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
13328 * rss->level and rss.types should be set in advance
13329 * when expanding items for RSS.
13331 action_flags |= MLX5_FLOW_ACTION_RSS;
13332 dev_flow->handle->fate_action = rss_desc->shared_rss ?
13333 MLX5_FLOW_FATE_SHARED_RSS :
13334 MLX5_FLOW_FATE_QUEUE;
13336 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
13337 owner_idx = (uint32_t)(uintptr_t)action->conf;
13338 age_act = flow_aso_age_get_by_idx(dev, owner_idx);
13339 if (flow->age == 0) {
13340 flow->age = owner_idx;
13341 __atomic_fetch_add(&age_act->refcnt, 1,
13344 age_act_pos = actions_n++;
13345 action_flags |= MLX5_FLOW_ACTION_AGE;
13347 case RTE_FLOW_ACTION_TYPE_AGE:
13348 non_shared_age = action->conf;
13349 age_act_pos = actions_n++;
13350 action_flags |= MLX5_FLOW_ACTION_AGE;
13352 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
13353 owner_idx = (uint32_t)(uintptr_t)action->conf;
13354 cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
13356 MLX5_ASSERT(cnt_act != NULL);
13358 * When creating meter drop flow in drop table, the
13359 * counter should not overwrite the rte flow counter.
13361 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
13362 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
13363 dev_flow->dv.actions[actions_n++] =
13366 if (flow->counter == 0) {
13367 flow->counter = owner_idx;
13369 (&cnt_act->shared_info.refcnt,
13370 1, __ATOMIC_RELAXED);
13372 /* Save information first, will apply later. */
13373 action_flags |= MLX5_FLOW_ACTION_COUNT;
13376 case RTE_FLOW_ACTION_TYPE_COUNT:
13377 if (!priv->sh->cdev->config.devx) {
13378 return rte_flow_error_set
13380 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13382 "count action not supported");
13384 /* Save information first, will apply later. */
13385 count = action->conf;
13386 action_flags |= MLX5_FLOW_ACTION_COUNT;
13388 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
13389 dev_flow->dv.actions[actions_n++] =
13390 priv->sh->pop_vlan_action;
13391 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
13393 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
13394 if (!(action_flags &
13395 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
13396 flow_dev_get_vlan_info_from_items(items, &vlan);
13397 vlan.eth_proto = rte_be_to_cpu_16
13398 ((((const struct rte_flow_action_of_push_vlan *)
13399 actions->conf)->ethertype));
13400 found_action = mlx5_flow_find_action
13402 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
13404 mlx5_update_vlan_vid_pcp(found_action, &vlan);
13405 found_action = mlx5_flow_find_action
13407 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
13409 mlx5_update_vlan_vid_pcp(found_action, &vlan);
13410 if (flow_dv_create_action_push_vlan
13411 (dev, attr, &vlan, dev_flow, error))
13413 dev_flow->dv.actions[actions_n++] =
13414 dev_flow->dv.push_vlan_res->action;
13415 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
13417 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
13418 /* of_vlan_push action handled this action */
13419 MLX5_ASSERT(action_flags &
13420 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
13422 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
13423 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
13425 flow_dev_get_vlan_info_from_items(items, &vlan);
13426 mlx5_update_vlan_vid_pcp(actions, &vlan);
13427 /* If no VLAN push - this is a modify header action */
13428 if (flow_dv_convert_action_modify_vlan_vid
13429 (mhdr_res, actions, error))
13431 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
13433 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13434 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13435 if (flow_dv_create_action_l2_encap(dev, actions,
13440 dev_flow->dv.actions[actions_n++] =
13441 dev_flow->dv.encap_decap->action;
13442 action_flags |= MLX5_FLOW_ACTION_ENCAP;
13443 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
13444 sample_act->action_flags |=
13445 MLX5_FLOW_ACTION_ENCAP;
13447 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
13448 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
13449 if (flow_dv_create_action_l2_decap(dev, dev_flow,
13453 dev_flow->dv.actions[actions_n++] =
13454 dev_flow->dv.encap_decap->action;
13455 action_flags |= MLX5_FLOW_ACTION_DECAP;
13457 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13458 /* Handle encap with preceding decap. */
13459 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
13460 if (flow_dv_create_action_raw_encap
13461 (dev, actions, dev_flow, attr, error))
13463 dev_flow->dv.actions[actions_n++] =
13464 dev_flow->dv.encap_decap->action;
13466 /* Handle encap without preceding decap. */
13467 if (flow_dv_create_action_l2_encap
13468 (dev, actions, dev_flow, attr->transfer,
13471 dev_flow->dv.actions[actions_n++] =
13472 dev_flow->dv.encap_decap->action;
13474 action_flags |= MLX5_FLOW_ACTION_ENCAP;
13475 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
13476 sample_act->action_flags |=
13477 MLX5_FLOW_ACTION_ENCAP;
13479 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
13480 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
13482 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
13483 if (flow_dv_create_action_l2_decap
13484 (dev, dev_flow, attr->transfer, error))
13486 dev_flow->dv.actions[actions_n++] =
13487 dev_flow->dv.encap_decap->action;
13489 /* If decap is followed by encap, handle it at encap. */
13490 action_flags |= MLX5_FLOW_ACTION_DECAP;
13492 case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
13493 dev_flow->dv.actions[actions_n++] =
13494 (void *)(uintptr_t)action->conf;
13495 action_flags |= MLX5_FLOW_ACTION_JUMP;
13497 case RTE_FLOW_ACTION_TYPE_JUMP:
13498 jump_group = ((const struct rte_flow_action_jump *)
13499 action->conf)->group;
13500 grp_info.std_tbl_fix = 0;
13501 if (dev_flow->skip_scale &
13502 (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
13503 grp_info.skip_scale = 1;
13505 grp_info.skip_scale = 0;
13506 ret = mlx5_flow_group_to_table(dev, tunnel,
13512 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
13514 !!dev_flow->external,
13515 tunnel, jump_group, 0,
13518 return rte_flow_error_set
13520 RTE_FLOW_ERROR_TYPE_ACTION,
13522 "cannot create jump action.");
13523 if (flow_dv_jump_tbl_resource_register
13524 (dev, tbl, dev_flow, error)) {
13525 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
13526 return rte_flow_error_set
13528 RTE_FLOW_ERROR_TYPE_ACTION,
13530 "cannot create jump action.");
13532 dev_flow->dv.actions[actions_n++] =
13533 dev_flow->dv.jump->action;
13534 action_flags |= MLX5_FLOW_ACTION_JUMP;
13535 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
13536 sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
13539 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
13540 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
13541 if (flow_dv_convert_action_modify_mac
13542 (mhdr_res, actions, error))
13544 action_flags |= actions->type ==
13545 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
13546 MLX5_FLOW_ACTION_SET_MAC_SRC :
13547 MLX5_FLOW_ACTION_SET_MAC_DST;
13549 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
13550 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
13551 if (flow_dv_convert_action_modify_ipv4
13552 (mhdr_res, actions, error))
13554 action_flags |= actions->type ==
13555 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
13556 MLX5_FLOW_ACTION_SET_IPV4_SRC :
13557 MLX5_FLOW_ACTION_SET_IPV4_DST;
13559 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
13560 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
13561 if (flow_dv_convert_action_modify_ipv6
13562 (mhdr_res, actions, error))
13564 action_flags |= actions->type ==
13565 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
13566 MLX5_FLOW_ACTION_SET_IPV6_SRC :
13567 MLX5_FLOW_ACTION_SET_IPV6_DST;
13569 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
13570 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
13571 if (flow_dv_convert_action_modify_tp
13572 (mhdr_res, actions, items,
13573 &flow_attr, dev_flow, !!(action_flags &
13574 MLX5_FLOW_ACTION_DECAP), error))
13576 action_flags |= actions->type ==
13577 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
13578 MLX5_FLOW_ACTION_SET_TP_SRC :
13579 MLX5_FLOW_ACTION_SET_TP_DST;
13581 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
13582 if (flow_dv_convert_action_modify_dec_ttl
13583 (mhdr_res, items, &flow_attr, dev_flow,
13585 MLX5_FLOW_ACTION_DECAP), error))
13587 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
13589 case RTE_FLOW_ACTION_TYPE_SET_TTL:
13590 if (flow_dv_convert_action_modify_ttl
13591 (mhdr_res, actions, items, &flow_attr,
13592 dev_flow, !!(action_flags &
13593 MLX5_FLOW_ACTION_DECAP), error))
13595 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
13597 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
13598 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
13599 if (flow_dv_convert_action_modify_tcp_seq
13600 (mhdr_res, actions, error))
13602 action_flags |= actions->type ==
13603 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
13604 MLX5_FLOW_ACTION_INC_TCP_SEQ :
13605 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
13608 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
13609 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
13610 if (flow_dv_convert_action_modify_tcp_ack
13611 (mhdr_res, actions, error))
13613 action_flags |= actions->type ==
13614 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
13615 MLX5_FLOW_ACTION_INC_TCP_ACK :
13616 MLX5_FLOW_ACTION_DEC_TCP_ACK;
13618 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
13619 if (flow_dv_convert_action_set_reg
13620 (mhdr_res, actions, error))
13622 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13624 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
13625 if (flow_dv_convert_action_copy_mreg
13626 (dev, mhdr_res, actions, error))
13628 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13630 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
13631 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
13632 dev_flow->handle->fate_action =
13633 MLX5_FLOW_FATE_DEFAULT_MISS;
13635 case RTE_FLOW_ACTION_TYPE_METER:
13637 return rte_flow_error_set(error, rte_errno,
13638 RTE_FLOW_ERROR_TYPE_ACTION,
13639 NULL, "Failed to get meter in flow.");
13640 /* Set the meter action. */
13641 dev_flow->dv.actions[actions_n++] =
13642 wks->fm->meter_action_g;
13643 action_flags |= MLX5_FLOW_ACTION_METER;
13645 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
13646 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
13649 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
13651 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
13652 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
13655 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
13657 case RTE_FLOW_ACTION_TYPE_SAMPLE:
13658 sample_act_pos = actions_n;
13659 sample = (const struct rte_flow_action_sample *)
13662 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
13663 /* put encap action into group if work with port id */
13664 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
13665 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
13666 sample_act->action_flags |=
13667 MLX5_FLOW_ACTION_ENCAP;
13669 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
13670 if (flow_dv_convert_action_modify_field
13671 (dev, mhdr_res, actions, attr, error))
13673 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
13675 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
13676 owner_idx = (uint32_t)(uintptr_t)action->conf;
13677 ct = flow_aso_ct_get_by_idx(dev, owner_idx);
13679 return rte_flow_error_set(error, EINVAL,
13680 RTE_FLOW_ERROR_TYPE_ACTION,
13682 "Failed to get CT object.");
13683 if (mlx5_aso_ct_available(priv->sh, ct))
13684 return rte_flow_error_set(error, rte_errno,
13685 RTE_FLOW_ERROR_TYPE_ACTION,
13687 "CT is unavailable.");
13688 if (ct->is_original)
13689 dev_flow->dv.actions[actions_n] =
13690 ct->dr_action_orig;
13692 dev_flow->dv.actions[actions_n] =
13693 ct->dr_action_rply;
13694 if (flow->ct == 0) {
13695 flow->indirect_type =
13696 MLX5_INDIRECT_ACTION_TYPE_CT;
13697 flow->ct = owner_idx;
13698 __atomic_fetch_add(&ct->refcnt, 1,
13702 action_flags |= MLX5_FLOW_ACTION_CT;
13704 case RTE_FLOW_ACTION_TYPE_END:
13705 actions_end = true;
13706 if (mhdr_res->actions_num) {
13707 /* create modify action if needed. */
13708 if (flow_dv_modify_hdr_resource_register
13709 (dev, mhdr_res, dev_flow, error))
13711 dev_flow->dv.actions[modify_action_position] =
13712 handle->dvh.modify_hdr->action;
13715 * Handle AGE and COUNT action by single HW counter
13716 * when they are not shared.
13718 if (action_flags & MLX5_FLOW_ACTION_AGE) {
13719 if ((non_shared_age && count) ||
13720 !flow_hit_aso_supported(priv->sh, attr)) {
13721 /* Creates age by counters. */
13722 cnt_act = flow_dv_prepare_counter
13729 dev_flow->dv.actions[age_act_pos] =
13733 if (!flow->age && non_shared_age) {
13734 flow->age = flow_dv_aso_age_alloc
13738 flow_dv_aso_age_params_init
13740 non_shared_age->context ?
13741 non_shared_age->context :
13742 (void *)(uintptr_t)
13743 (dev_flow->flow_idx),
13744 non_shared_age->timeout);
13746 age_act = flow_aso_age_get_by_idx(dev,
13748 dev_flow->dv.actions[age_act_pos] =
13749 age_act->dr_action;
13751 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
13753 * Create one count action, to be used
13754 * by all sub-flows.
13756 cnt_act = flow_dv_prepare_counter(dev, dev_flow,
13761 dev_flow->dv.actions[actions_n++] =
13767 if (mhdr_res->actions_num &&
13768 modify_action_position == UINT32_MAX)
13769 modify_action_position = actions_n++;
13771 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
13772 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
13773 int item_type = items->type;
13775 if (!mlx5_flow_os_item_supported(item_type))
13776 return rte_flow_error_set(error, ENOTSUP,
13777 RTE_FLOW_ERROR_TYPE_ITEM,
13778 NULL, "item not supported");
13779 switch (item_type) {
13780 case RTE_FLOW_ITEM_TYPE_ESP:
13781 flow_dv_translate_item_esp(match_mask, match_value,
13783 last_item = MLX5_FLOW_ITEM_ESP;
13785 case RTE_FLOW_ITEM_TYPE_PORT_ID:
13786 flow_dv_translate_item_port_id
13787 (dev, match_mask, match_value, items, attr);
13788 last_item = MLX5_FLOW_ITEM_PORT_ID;
13790 case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
13791 flow_dv_translate_item_represented_port
13792 (dev, match_mask, match_value, items, attr);
13793 last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
13795 case RTE_FLOW_ITEM_TYPE_ETH:
13796 flow_dv_translate_item_eth(match_mask, match_value,
13798 dev_flow->dv.group);
13799 matcher.priority = action_flags &
13800 MLX5_FLOW_ACTION_DEFAULT_MISS &&
13801 !dev_flow->external ?
13802 MLX5_PRIORITY_MAP_L3 :
13803 MLX5_PRIORITY_MAP_L2;
13804 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
13805 MLX5_FLOW_LAYER_OUTER_L2;
13807 case RTE_FLOW_ITEM_TYPE_VLAN:
13808 flow_dv_translate_item_vlan(dev_flow,
13809 match_mask, match_value,
13811 dev_flow->dv.group);
13812 matcher.priority = MLX5_PRIORITY_MAP_L2;
13813 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
13814 MLX5_FLOW_LAYER_INNER_VLAN) :
13815 (MLX5_FLOW_LAYER_OUTER_L2 |
13816 MLX5_FLOW_LAYER_OUTER_VLAN);
13818 case RTE_FLOW_ITEM_TYPE_IPV4:
13819 mlx5_flow_tunnel_ip_check(items, next_protocol,
13820 &item_flags, &tunnel);
13821 flow_dv_translate_item_ipv4(match_mask, match_value,
13823 dev_flow->dv.group);
13824 matcher.priority = MLX5_PRIORITY_MAP_L3;
13825 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
13826 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
13827 if (items->mask != NULL &&
13828 ((const struct rte_flow_item_ipv4 *)
13829 items->mask)->hdr.next_proto_id) {
13831 ((const struct rte_flow_item_ipv4 *)
13832 (items->spec))->hdr.next_proto_id;
13834 ((const struct rte_flow_item_ipv4 *)
13835 (items->mask))->hdr.next_proto_id;
13837 /* Reset for inner layer. */
13838 next_protocol = 0xff;
13841 case RTE_FLOW_ITEM_TYPE_IPV6:
13842 mlx5_flow_tunnel_ip_check(items, next_protocol,
13843 &item_flags, &tunnel);
13844 flow_dv_translate_item_ipv6(match_mask, match_value,
13846 dev_flow->dv.group);
13847 matcher.priority = MLX5_PRIORITY_MAP_L3;
13848 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
13849 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
13850 if (items->mask != NULL &&
13851 ((const struct rte_flow_item_ipv6 *)
13852 items->mask)->hdr.proto) {
13854 ((const struct rte_flow_item_ipv6 *)
13855 items->spec)->hdr.proto;
13857 ((const struct rte_flow_item_ipv6 *)
13858 items->mask)->hdr.proto;
13860 /* Reset for inner layer. */
13861 next_protocol = 0xff;
13864 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
13865 flow_dv_translate_item_ipv6_frag_ext(match_mask,
13868 last_item = tunnel ?
13869 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
13870 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
13871 if (items->mask != NULL &&
13872 ((const struct rte_flow_item_ipv6_frag_ext *)
13873 items->mask)->hdr.next_header) {
13875 ((const struct rte_flow_item_ipv6_frag_ext *)
13876 items->spec)->hdr.next_header;
13878 ((const struct rte_flow_item_ipv6_frag_ext *)
13879 items->mask)->hdr.next_header;
13881 /* Reset for inner layer. */
13882 next_protocol = 0xff;
13885 case RTE_FLOW_ITEM_TYPE_TCP:
13886 flow_dv_translate_item_tcp(match_mask, match_value,
13888 matcher.priority = MLX5_PRIORITY_MAP_L4;
13889 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
13890 MLX5_FLOW_LAYER_OUTER_L4_TCP;
13892 case RTE_FLOW_ITEM_TYPE_UDP:
13893 flow_dv_translate_item_udp(match_mask, match_value,
13895 matcher.priority = MLX5_PRIORITY_MAP_L4;
13896 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
13897 MLX5_FLOW_LAYER_OUTER_L4_UDP;
13899 case RTE_FLOW_ITEM_TYPE_GRE:
13900 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13901 last_item = MLX5_FLOW_LAYER_GRE;
13902 tunnel_item = items;
13905 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
13906 flow_dv_translate_item_gre_key(match_mask,
13907 match_value, items);
13908 last_item = MLX5_FLOW_LAYER_GRE_KEY;
13910 case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
13911 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13912 last_item = MLX5_FLOW_LAYER_GRE;
13913 tunnel_item = items;
13915 case RTE_FLOW_ITEM_TYPE_NVGRE:
13916 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13917 last_item = MLX5_FLOW_LAYER_GRE;
13918 tunnel_item = items;
13920 case RTE_FLOW_ITEM_TYPE_VXLAN:
13921 flow_dv_translate_item_vxlan(dev, attr,
13922 match_mask, match_value,
13924 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13925 last_item = MLX5_FLOW_LAYER_VXLAN;
13927 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
13928 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13929 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
13930 tunnel_item = items;
13932 case RTE_FLOW_ITEM_TYPE_GENEVE:
13933 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13934 last_item = MLX5_FLOW_LAYER_GENEVE;
13935 tunnel_item = items;
13937 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
13938 ret = flow_dv_translate_item_geneve_opt(dev, match_mask,
13942 return rte_flow_error_set(error, -ret,
13943 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13944 "cannot create GENEVE TLV option");
13945 flow->geneve_tlv_option = 1;
13946 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
13948 case RTE_FLOW_ITEM_TYPE_MPLS:
13949 flow_dv_translate_item_mpls(match_mask, match_value,
13950 items, last_item, tunnel);
13951 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13952 last_item = MLX5_FLOW_LAYER_MPLS;
13954 case RTE_FLOW_ITEM_TYPE_MARK:
13955 flow_dv_translate_item_mark(dev, match_mask,
13956 match_value, items);
13957 last_item = MLX5_FLOW_ITEM_MARK;
13959 case RTE_FLOW_ITEM_TYPE_META:
13960 flow_dv_translate_item_meta(dev, match_mask,
13961 match_value, attr, items);
13962 last_item = MLX5_FLOW_ITEM_METADATA;
13964 case RTE_FLOW_ITEM_TYPE_ICMP:
13965 flow_dv_translate_item_icmp(match_mask, match_value,
13967 matcher.priority = MLX5_PRIORITY_MAP_L4;
13968 last_item = MLX5_FLOW_LAYER_ICMP;
13970 case RTE_FLOW_ITEM_TYPE_ICMP6:
13971 flow_dv_translate_item_icmp6(match_mask, match_value,
13973 matcher.priority = MLX5_PRIORITY_MAP_L4;
13974 last_item = MLX5_FLOW_LAYER_ICMP6;
13976 case RTE_FLOW_ITEM_TYPE_TAG:
13977 flow_dv_translate_item_tag(dev, match_mask,
13978 match_value, items);
13979 last_item = MLX5_FLOW_ITEM_TAG;
13981 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
13982 flow_dv_translate_mlx5_item_tag(dev, match_mask,
13983 match_value, items);
13984 last_item = MLX5_FLOW_ITEM_TAG;
13986 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
13987 flow_dv_translate_item_tx_queue(dev, match_mask,
13990 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
13992 case RTE_FLOW_ITEM_TYPE_GTP:
13993 flow_dv_translate_item_gtp(match_mask, match_value,
13995 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13996 last_item = MLX5_FLOW_LAYER_GTP;
13998 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
13999 ret = flow_dv_translate_item_gtp_psc(match_mask,
14003 return rte_flow_error_set(error, -ret,
14004 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14005 "cannot create GTP PSC item");
14006 last_item = MLX5_FLOW_LAYER_GTP_PSC;
14008 case RTE_FLOW_ITEM_TYPE_ECPRI:
14009 if (!mlx5_flex_parser_ecpri_exist(dev)) {
14010 /* Create it only the first time to be used. */
14011 ret = mlx5_flex_parser_ecpri_alloc(dev);
14013 return rte_flow_error_set
14015 RTE_FLOW_ERROR_TYPE_ITEM,
14017 "cannot create eCPRI parser");
14019 flow_dv_translate_item_ecpri(dev, match_mask,
14020 match_value, items,
14022 /* No other protocol should follow eCPRI layer. */
14023 last_item = MLX5_FLOW_LAYER_ECPRI;
14025 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
14026 flow_dv_translate_item_integrity(items, integrity_items,
14029 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14030 flow_dv_translate_item_aso_ct(dev, match_mask,
14031 match_value, items);
14033 case RTE_FLOW_ITEM_TYPE_FLEX:
14034 flow_dv_translate_item_flex(dev, match_mask,
14035 match_value, items,
14036 dev_flow, tunnel != 0);
14037 last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
14038 MLX5_FLOW_ITEM_OUTER_FLEX;
14043 item_flags |= last_item;
14046 * When E-Switch mode is enabled, we have two cases where we need to
14047 * set the source port manually.
14048 * The first one, is in case of NIC ingress steering rule, and the
14049 * second is E-Switch rule where no port_id item was found.
14050 * In both cases the source port is set according the current port
14053 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
14054 !(item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT) && priv->sh->esw_mode &&
14055 !(attr->egress && !attr->transfer)) {
14056 if (flow_dv_translate_item_port_id(dev, match_mask,
14057 match_value, NULL, attr))
14060 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14061 flow_dv_translate_item_integrity_post(match_mask, match_value,
14065 if (item_flags & MLX5_FLOW_LAYER_VXLAN_GPE)
14066 flow_dv_translate_item_vxlan_gpe(match_mask, match_value,
14067 tunnel_item, item_flags);
14068 else if (item_flags & MLX5_FLOW_LAYER_GENEVE)
14069 flow_dv_translate_item_geneve(match_mask, match_value,
14070 tunnel_item, item_flags);
14071 else if (item_flags & MLX5_FLOW_LAYER_GRE) {
14072 if (tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE)
14073 flow_dv_translate_item_gre(match_mask, match_value,
14074 tunnel_item, item_flags);
14075 else if (tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE)
14076 flow_dv_translate_item_nvgre(match_mask, match_value,
14077 tunnel_item, item_flags);
14078 else if (tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION)
14079 flow_dv_translate_item_gre_option(match_mask, match_value,
14080 tunnel_item, gre_item, item_flags);
14082 MLX5_ASSERT(false);
14084 #ifdef RTE_LIBRTE_MLX5_DEBUG
14085 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
14086 dev_flow->dv.value.buf));
14089 * Layers may be already initialized from prefix flow if this dev_flow
14090 * is the suffix flow.
14092 handle->layers |= item_flags;
14093 if (action_flags & MLX5_FLOW_ACTION_RSS)
14094 flow_dv_hashfields_set(dev_flow->handle->layers,
14096 &dev_flow->hash_fields);
14097 /* If has RSS action in the sample action, the Sample/Mirror resource
14098 * should be registered after the hash filed be update.
14100 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
14101 ret = flow_dv_translate_action_sample(dev,
14110 ret = flow_dv_create_action_sample(dev,
14119 return rte_flow_error_set
14121 RTE_FLOW_ERROR_TYPE_ACTION,
14123 "cannot create sample action");
14124 if (num_of_dest > 1) {
14125 dev_flow->dv.actions[sample_act_pos] =
14126 dev_flow->dv.dest_array_res->action;
14128 dev_flow->dv.actions[sample_act_pos] =
14129 dev_flow->dv.sample_res->verbs_action;
14133 * For multiple destination (sample action with ratio=1), the encap
14134 * action and port id action will be combined into group action.
14135 * So need remove the original these actions in the flow and only
14136 * use the sample action instead of.
14138 if (num_of_dest > 1 &&
14139 (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
14141 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
14143 for (i = 0; i < actions_n; i++) {
14144 if ((sample_act->dr_encap_action &&
14145 sample_act->dr_encap_action ==
14146 dev_flow->dv.actions[i]) ||
14147 (sample_act->dr_port_id_action &&
14148 sample_act->dr_port_id_action ==
14149 dev_flow->dv.actions[i]) ||
14150 (sample_act->dr_jump_action &&
14151 sample_act->dr_jump_action ==
14152 dev_flow->dv.actions[i]))
14154 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
14156 memcpy((void *)dev_flow->dv.actions,
14157 (void *)temp_actions,
14158 tmp_actions_n * sizeof(void *));
14159 actions_n = tmp_actions_n;
14161 dev_flow->dv.actions_n = actions_n;
14162 dev_flow->act_flags = action_flags;
14163 if (wks->skip_matcher_reg)
14165 /* Register matcher. */
14166 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
14167 matcher.mask.size);
14168 matcher.priority = mlx5_get_matcher_priority(dev, attr,
14170 dev_flow->external);
14172 * When creating meter drop flow in drop table, using original
14173 * 5-tuple match, the matcher priority should be lower than
14176 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
14177 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
14178 matcher.priority <= MLX5_REG_BITS)
14179 matcher.priority += MLX5_REG_BITS;
14180 /* reserved field no needs to be set to 0 here. */
14181 tbl_key.is_fdb = attr->transfer;
14182 tbl_key.is_egress = attr->egress;
14183 tbl_key.level = dev_flow->dv.group;
14184 tbl_key.id = dev_flow->dv.table_id;
14185 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
14186 tunnel, attr->group, error))
14192 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
14195 * @param[in, out] action
14196 * Shred RSS action holding hash RX queue objects.
14197 * @param[in] hash_fields
14198 * Defines combination of packet fields to participate in RX hash.
14199 * @param[in] tunnel
14201 * @param[in] hrxq_idx
14202 * Hash RX queue index to set.
14205 * 0 on success, otherwise negative errno value.
14208 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
14209 const uint64_t hash_fields,
14212 uint32_t *hrxqs = action->hrxq;
14214 switch (hash_fields & ~IBV_RX_HASH_INNER) {
14215 case MLX5_RSS_HASH_IPV4:
14216 /* fall-through. */
14217 case MLX5_RSS_HASH_IPV4_DST_ONLY:
14218 /* fall-through. */
14219 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
14220 hrxqs[0] = hrxq_idx;
14222 case MLX5_RSS_HASH_IPV4_TCP:
14223 /* fall-through. */
14224 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
14225 /* fall-through. */
14226 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
14227 hrxqs[1] = hrxq_idx;
14229 case MLX5_RSS_HASH_IPV4_UDP:
14230 /* fall-through. */
14231 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
14232 /* fall-through. */
14233 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
14234 hrxqs[2] = hrxq_idx;
14236 case MLX5_RSS_HASH_IPV6:
14237 /* fall-through. */
14238 case MLX5_RSS_HASH_IPV6_DST_ONLY:
14239 /* fall-through. */
14240 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
14241 hrxqs[3] = hrxq_idx;
14243 case MLX5_RSS_HASH_IPV6_TCP:
14244 /* fall-through. */
14245 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
14246 /* fall-through. */
14247 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
14248 hrxqs[4] = hrxq_idx;
14250 case MLX5_RSS_HASH_IPV6_UDP:
14251 /* fall-through. */
14252 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
14253 /* fall-through. */
14254 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
14255 hrxqs[5] = hrxq_idx;
14257 case MLX5_RSS_HASH_NONE:
14258 hrxqs[6] = hrxq_idx;
14260 case MLX5_RSS_HASH_IPV4_ESP:
14261 hrxqs[7] = hrxq_idx;
14263 case MLX5_RSS_HASH_IPV6_ESP:
14264 hrxqs[8] = hrxq_idx;
14266 case MLX5_RSS_HASH_ESP_SPI:
14267 hrxqs[9] = hrxq_idx;
14275 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
14279 * Pointer to the Ethernet device structure.
14281 * Shared RSS action ID holding hash RX queue objects.
14282 * @param[in] hash_fields
14283 * Defines combination of packet fields to participate in RX hash.
14284 * @param[in] tunnel
14288 * Valid hash RX queue index, otherwise 0.
14291 flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
14292 const uint64_t hash_fields)
14294 struct mlx5_priv *priv = dev->data->dev_private;
14295 struct mlx5_shared_action_rss *shared_rss =
14296 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14297 const uint32_t *hrxqs = shared_rss->hrxq;
14299 switch (hash_fields & ~IBV_RX_HASH_INNER) {
14300 case MLX5_RSS_HASH_IPV4:
14301 /* fall-through. */
14302 case MLX5_RSS_HASH_IPV4_DST_ONLY:
14303 /* fall-through. */
14304 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
14306 case MLX5_RSS_HASH_IPV4_TCP:
14307 /* fall-through. */
14308 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
14309 /* fall-through. */
14310 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
14312 case MLX5_RSS_HASH_IPV4_UDP:
14313 /* fall-through. */
14314 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
14315 /* fall-through. */
14316 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
14318 case MLX5_RSS_HASH_IPV6:
14319 /* fall-through. */
14320 case MLX5_RSS_HASH_IPV6_DST_ONLY:
14321 /* fall-through. */
14322 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
14324 case MLX5_RSS_HASH_IPV6_TCP:
14325 /* fall-through. */
14326 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
14327 /* fall-through. */
14328 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
14330 case MLX5_RSS_HASH_IPV6_UDP:
14331 /* fall-through. */
14332 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
14333 /* fall-through. */
14334 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
14336 case MLX5_RSS_HASH_NONE:
14338 case MLX5_RSS_HASH_IPV4_ESP:
14340 case MLX5_RSS_HASH_IPV6_ESP:
14342 case MLX5_RSS_HASH_ESP_SPI:
14351 * Apply the flow to the NIC, lock free,
14352 * (mutex should be acquired by caller).
14355 * Pointer to the Ethernet device structure.
14356 * @param[in, out] flow
14357 * Pointer to flow structure.
14358 * @param[out] error
14359 * Pointer to error structure.
14362 * 0 on success, a negative errno value otherwise and rte_errno is set.
14365 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
14366 struct rte_flow_error *error)
14368 struct mlx5_flow_dv_workspace *dv;
14369 struct mlx5_flow_handle *dh;
14370 struct mlx5_flow_handle_dv *dv_h;
14371 struct mlx5_flow *dev_flow;
14372 struct mlx5_priv *priv = dev->data->dev_private;
14373 uint32_t handle_idx;
14377 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
14378 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
14382 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
14383 dev_flow = &wks->flows[idx];
14384 dv = &dev_flow->dv;
14385 dh = dev_flow->handle;
14388 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
14389 if (dv->transfer) {
14390 MLX5_ASSERT(priv->sh->dr_drop_action);
14391 dv->actions[n++] = priv->sh->dr_drop_action;
14393 #ifdef HAVE_MLX5DV_DR
14394 /* DR supports drop action placeholder. */
14395 MLX5_ASSERT(priv->sh->dr_drop_action);
14396 dv->actions[n++] = dv->group ?
14397 priv->sh->dr_drop_action :
14398 priv->root_drop_action;
14400 /* For DV we use the explicit drop queue. */
14401 MLX5_ASSERT(priv->drop_queue.hrxq);
14403 priv->drop_queue.hrxq->action;
14406 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
14407 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
14408 struct mlx5_hrxq *hrxq;
14411 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
14416 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14417 "cannot get hash queue");
14420 dh->rix_hrxq = hrxq_idx;
14421 dv->actions[n++] = hrxq->action;
14422 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
14423 struct mlx5_hrxq *hrxq = NULL;
14426 hrxq_idx = flow_dv_action_rss_hrxq_lookup(dev,
14427 rss_desc->shared_rss,
14428 dev_flow->hash_fields);
14430 hrxq = mlx5_ipool_get
14431 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
14436 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14437 "cannot get hash queue");
14440 dh->rix_srss = rss_desc->shared_rss;
14441 dv->actions[n++] = hrxq->action;
14442 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
14443 if (!priv->sh->default_miss_action) {
14446 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14447 "default miss action not be created.");
14450 dv->actions[n++] = priv->sh->default_miss_action;
14452 misc_mask = flow_dv_matcher_enable(dv->value.buf);
14453 __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
14454 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
14455 (void *)&dv->value, n,
14456 dv->actions, &dh->drv_flow);
14460 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14462 (!priv->sh->config.allow_duplicate_pattern &&
14464 "duplicating pattern is not allowed" :
14465 "hardware refuses to create flow");
14468 if (priv->vmwa_context &&
14469 dh->vf_vlan.tag && !dh->vf_vlan.created) {
14471 * The rule contains the VLAN pattern.
14472 * For VF we are going to create VLAN
14473 * interface to make hypervisor set correct
14474 * e-Switch vport context.
14476 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
14481 err = rte_errno; /* Save rte_errno before cleanup. */
14482 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
14483 handle_idx, dh, next) {
14484 /* hrxq is union, don't clear it if the flag is not set. */
14485 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
14486 mlx5_hrxq_release(dev, dh->rix_hrxq);
14488 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
14491 if (dh->vf_vlan.tag && dh->vf_vlan.created)
14492 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
14494 rte_errno = err; /* Restore rte_errno. */
14499 flow_dv_matcher_remove_cb(void *tool_ctx __rte_unused,
14500 struct mlx5_list_entry *entry)
14502 struct mlx5_flow_dv_matcher *resource = container_of(entry,
14506 claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
14507 mlx5_free(resource);
14511 * Release the flow matcher.
14514 * Pointer to Ethernet device.
14516 * Index to port ID action resource.
14519 * 1 while a reference on it exists, 0 when freed.
14522 flow_dv_matcher_release(struct rte_eth_dev *dev,
14523 struct mlx5_flow_handle *handle)
14525 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
14526 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
14527 typeof(*tbl), tbl);
14530 MLX5_ASSERT(matcher->matcher_object);
14531 ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
14532 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
14537 flow_dv_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14539 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14540 struct mlx5_flow_dv_encap_decap_resource *res =
14541 container_of(entry, typeof(*res), entry);
14543 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
14544 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
14548 * Release an encap/decap resource.
14551 * Pointer to Ethernet device.
14552 * @param encap_decap_idx
14553 * Index of encap decap resource.
14556 * 1 while a reference on it exists, 0 when freed.
14559 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
14560 uint32_t encap_decap_idx)
14562 struct mlx5_priv *priv = dev->data->dev_private;
14563 struct mlx5_flow_dv_encap_decap_resource *resource;
14565 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
14569 MLX5_ASSERT(resource->action);
14570 return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
14574 * Release an jump to table action resource.
14577 * Pointer to Ethernet device.
14579 * Index to the jump action resource.
14582 * 1 while a reference on it exists, 0 when freed.
14585 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
14588 struct mlx5_priv *priv = dev->data->dev_private;
14589 struct mlx5_flow_tbl_data_entry *tbl_data;
14591 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
14595 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
14599 flow_dv_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14601 struct mlx5_flow_dv_modify_hdr_resource *res =
14602 container_of(entry, typeof(*res), entry);
14603 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14605 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
14606 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
14610 * Release a modify-header resource.
14613 * Pointer to Ethernet device.
14615 * Pointer to mlx5_flow_handle.
14618 * 1 while a reference on it exists, 0 when freed.
14621 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
14622 struct mlx5_flow_handle *handle)
14624 struct mlx5_priv *priv = dev->data->dev_private;
14625 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
14627 MLX5_ASSERT(entry->action);
14628 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
14632 flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14634 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14635 struct mlx5_flow_dv_port_id_action_resource *resource =
14636 container_of(entry, typeof(*resource), entry);
14638 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14639 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
14643 * Release port ID action resource.
14646 * Pointer to Ethernet device.
14648 * Pointer to mlx5_flow_handle.
14651 * 1 while a reference on it exists, 0 when freed.
14654 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
14657 struct mlx5_priv *priv = dev->data->dev_private;
14658 struct mlx5_flow_dv_port_id_action_resource *resource;
14660 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
14663 MLX5_ASSERT(resource->action);
14664 return mlx5_list_unregister(priv->sh->port_id_action_list,
14669 * Release shared RSS action resource.
14672 * Pointer to Ethernet device.
14674 * Shared RSS action index.
14677 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
14679 struct mlx5_priv *priv = dev->data->dev_private;
14680 struct mlx5_shared_action_rss *shared_rss;
14682 shared_rss = mlx5_ipool_get
14683 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
14684 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14688 flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14690 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14691 struct mlx5_flow_dv_push_vlan_action_resource *resource =
14692 container_of(entry, typeof(*resource), entry);
14694 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14695 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
14699 * Release push vlan action resource.
14702 * Pointer to Ethernet device.
14704 * Pointer to mlx5_flow_handle.
14707 * 1 while a reference on it exists, 0 when freed.
14710 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
14711 struct mlx5_flow_handle *handle)
14713 struct mlx5_priv *priv = dev->data->dev_private;
14714 struct mlx5_flow_dv_push_vlan_action_resource *resource;
14715 uint32_t idx = handle->dvh.rix_push_vlan;
14717 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
14720 MLX5_ASSERT(resource->action);
14721 return mlx5_list_unregister(priv->sh->push_vlan_action_list,
14726 * Release the fate resource.
14729 * Pointer to Ethernet device.
14731 * Pointer to mlx5_flow_handle.
14734 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
14735 struct mlx5_flow_handle *handle)
14737 if (!handle->rix_fate)
14739 switch (handle->fate_action) {
14740 case MLX5_FLOW_FATE_QUEUE:
14741 if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
14742 mlx5_hrxq_release(dev, handle->rix_hrxq);
14744 case MLX5_FLOW_FATE_JUMP:
14745 flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
14747 case MLX5_FLOW_FATE_PORT_ID:
14748 flow_dv_port_id_action_resource_release(dev,
14749 handle->rix_port_id_action);
14752 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
14755 handle->rix_fate = 0;
14759 flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
14760 struct mlx5_list_entry *entry)
14762 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
14765 struct rte_eth_dev *dev = resource->dev;
14766 struct mlx5_priv *priv = dev->data->dev_private;
14768 if (resource->verbs_action)
14769 claim_zero(mlx5_flow_os_destroy_flow_action
14770 (resource->verbs_action));
14771 if (resource->normal_path_tbl)
14772 flow_dv_tbl_resource_release(MLX5_SH(dev),
14773 resource->normal_path_tbl);
14774 flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
14775 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
14776 DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
14780 * Release an sample resource.
14783 * Pointer to Ethernet device.
14785 * Pointer to mlx5_flow_handle.
14788 * 1 while a reference on it exists, 0 when freed.
14791 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
14792 struct mlx5_flow_handle *handle)
14794 struct mlx5_priv *priv = dev->data->dev_private;
14795 struct mlx5_flow_dv_sample_resource *resource;
14797 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
14798 handle->dvh.rix_sample);
14801 MLX5_ASSERT(resource->verbs_action);
14802 return mlx5_list_unregister(priv->sh->sample_action_list,
14807 flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
14808 struct mlx5_list_entry *entry)
14810 struct mlx5_flow_dv_dest_array_resource *resource =
14811 container_of(entry, typeof(*resource), entry);
14812 struct rte_eth_dev *dev = resource->dev;
14813 struct mlx5_priv *priv = dev->data->dev_private;
14816 MLX5_ASSERT(resource->action);
14817 if (resource->action)
14818 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14819 for (; i < resource->num_of_dest; i++)
14820 flow_dv_sample_sub_actions_release(dev,
14821 &resource->sample_idx[i]);
14822 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
14823 DRV_LOG(DEBUG, "destination array resource %p: removed",
14828 * Release an destination array resource.
14831 * Pointer to Ethernet device.
14833 * Pointer to mlx5_flow_handle.
14836 * 1 while a reference on it exists, 0 when freed.
14839 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
14840 struct mlx5_flow_handle *handle)
14842 struct mlx5_priv *priv = dev->data->dev_private;
14843 struct mlx5_flow_dv_dest_array_resource *resource;
14845 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
14846 handle->dvh.rix_dest_array);
14849 MLX5_ASSERT(resource->action);
14850 return mlx5_list_unregister(priv->sh->dest_array_list,
14855 flow_dv_geneve_tlv_option_resource_release(struct rte_eth_dev *dev)
14857 struct mlx5_priv *priv = dev->data->dev_private;
14858 struct mlx5_dev_ctx_shared *sh = priv->sh;
14859 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
14860 sh->geneve_tlv_option_resource;
14861 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
14862 if (geneve_opt_resource) {
14863 if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
14864 __ATOMIC_RELAXED))) {
14865 claim_zero(mlx5_devx_cmd_destroy
14866 (geneve_opt_resource->obj));
14867 mlx5_free(sh->geneve_tlv_option_resource);
14868 sh->geneve_tlv_option_resource = NULL;
14871 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
14875 * Remove the flow from the NIC but keeps it in memory.
14876 * Lock free, (mutex should be acquired by caller).
14879 * Pointer to Ethernet device.
14880 * @param[in, out] flow
14881 * Pointer to flow structure.
14884 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
14886 struct mlx5_flow_handle *dh;
14887 uint32_t handle_idx;
14888 struct mlx5_priv *priv = dev->data->dev_private;
14892 handle_idx = flow->dev_handles;
14893 while (handle_idx) {
14894 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14898 if (dh->drv_flow) {
14899 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
14900 dh->drv_flow = NULL;
14902 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
14903 flow_dv_fate_resource_release(dev, dh);
14904 if (dh->vf_vlan.tag && dh->vf_vlan.created)
14905 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
14906 handle_idx = dh->next.next;
14911 * Remove the flow from the NIC and the memory.
14912 * Lock free, (mutex should be acquired by caller).
14915 * Pointer to the Ethernet device structure.
14916 * @param[in, out] flow
14917 * Pointer to flow structure.
14920 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
14922 struct mlx5_flow_handle *dev_handle;
14923 struct mlx5_priv *priv = dev->data->dev_private;
14924 struct mlx5_flow_meter_info *fm = NULL;
14929 flow_dv_remove(dev, flow);
14930 if (flow->counter) {
14931 flow_dv_counter_free(dev, flow->counter);
14935 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
14937 mlx5_flow_meter_detach(priv, fm);
14940 /* Keep the current age handling by default. */
14941 if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
14942 flow_dv_aso_ct_release(dev, flow->ct, NULL);
14943 else if (flow->age)
14944 flow_dv_aso_age_release(dev, flow->age);
14945 if (flow->geneve_tlv_option) {
14946 flow_dv_geneve_tlv_option_resource_release(dev);
14947 flow->geneve_tlv_option = 0;
14949 while (flow->dev_handles) {
14950 uint32_t tmp_idx = flow->dev_handles;
14952 dev_handle = mlx5_ipool_get(priv->sh->ipool
14953 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
14956 flow->dev_handles = dev_handle->next.next;
14957 while (dev_handle->flex_item) {
14958 int index = rte_bsf32(dev_handle->flex_item);
14960 mlx5_flex_release_index(dev, index);
14961 dev_handle->flex_item &= ~(uint8_t)RTE_BIT32(index);
14963 if (dev_handle->dvh.matcher)
14964 flow_dv_matcher_release(dev, dev_handle);
14965 if (dev_handle->dvh.rix_sample)
14966 flow_dv_sample_resource_release(dev, dev_handle);
14967 if (dev_handle->dvh.rix_dest_array)
14968 flow_dv_dest_array_resource_release(dev, dev_handle);
14969 if (dev_handle->dvh.rix_encap_decap)
14970 flow_dv_encap_decap_resource_release(dev,
14971 dev_handle->dvh.rix_encap_decap);
14972 if (dev_handle->dvh.modify_hdr)
14973 flow_dv_modify_hdr_resource_release(dev, dev_handle);
14974 if (dev_handle->dvh.rix_push_vlan)
14975 flow_dv_push_vlan_action_resource_release(dev,
14977 if (dev_handle->dvh.rix_tag)
14978 flow_dv_tag_release(dev,
14979 dev_handle->dvh.rix_tag);
14980 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
14981 flow_dv_fate_resource_release(dev, dev_handle);
14983 srss = dev_handle->rix_srss;
14984 if (fm && dev_handle->is_meter_flow_id &&
14985 dev_handle->split_flow_id)
14986 mlx5_ipool_free(fm->flow_ipool,
14987 dev_handle->split_flow_id);
14988 else if (dev_handle->split_flow_id &&
14989 !dev_handle->is_meter_flow_id)
14990 mlx5_ipool_free(priv->sh->ipool
14991 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
14992 dev_handle->split_flow_id);
14993 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14997 flow_dv_shared_rss_action_release(dev, srss);
15001 * Release array of hash RX queue objects.
15005 * Pointer to the Ethernet device structure.
15006 * @param[in, out] hrxqs
15007 * Array of hash RX queue objects.
15010 * Total number of references to hash RX queue objects in *hrxqs* array
15011 * after this operation.
15014 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
15015 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
15020 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
15021 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
15031 * Release all hash RX queue objects representing shared RSS action.
15034 * Pointer to the Ethernet device structure.
15035 * @param[in, out] action
15036 * Shared RSS action to remove hash RX queue objects from.
15039 * Total number of references to hash RX queue objects stored in *action*
15040 * after this operation.
15041 * Expected to be 0 if no external references held.
15044 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
15045 struct mlx5_shared_action_rss *shared_rss)
15047 return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
15051 * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
15054 * Only one hash value is available for one L3+L4 combination:
15056 * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
15057 * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
15058 * same slot in mlx5_rss_hash_fields.
15060 * @param[in] orig_rss_types
15061 * RSS type as provided in shared RSS action.
15062 * @param[in, out] hash_field
15063 * hash_field variable needed to be adjusted.
15069 flow_dv_action_rss_l34_hash_adjust(uint64_t orig_rss_types,
15070 uint64_t *hash_field)
15072 uint64_t rss_types = rte_eth_rss_hf_refine(orig_rss_types);
15074 switch (*hash_field & ~IBV_RX_HASH_INNER) {
15075 case MLX5_RSS_HASH_IPV4:
15076 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
15077 *hash_field &= ~MLX5_RSS_HASH_IPV4;
15078 if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
15079 *hash_field |= IBV_RX_HASH_DST_IPV4;
15080 else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
15081 *hash_field |= IBV_RX_HASH_SRC_IPV4;
15083 *hash_field |= MLX5_RSS_HASH_IPV4;
15086 case MLX5_RSS_HASH_IPV6:
15087 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
15088 *hash_field &= ~MLX5_RSS_HASH_IPV6;
15089 if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
15090 *hash_field |= IBV_RX_HASH_DST_IPV6;
15091 else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
15092 *hash_field |= IBV_RX_HASH_SRC_IPV6;
15094 *hash_field |= MLX5_RSS_HASH_IPV6;
15097 case MLX5_RSS_HASH_IPV4_UDP:
15098 /* fall-through. */
15099 case MLX5_RSS_HASH_IPV6_UDP:
15100 if (rss_types & RTE_ETH_RSS_UDP) {
15101 *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
15102 if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
15103 *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
15104 else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
15105 *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
15107 *hash_field |= MLX5_UDP_IBV_RX_HASH;
15110 case MLX5_RSS_HASH_IPV4_TCP:
15111 /* fall-through. */
15112 case MLX5_RSS_HASH_IPV6_TCP:
15113 if (rss_types & RTE_ETH_RSS_TCP) {
15114 *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
15115 if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
15116 *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
15117 else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
15118 *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
15120 *hash_field |= MLX5_TCP_IBV_RX_HASH;
15129 * Setup shared RSS action.
15130 * Prepare set of hash RX queue objects sufficient to handle all valid
15131 * hash_fields combinations (see enum ibv_rx_hash_fields).
15134 * Pointer to the Ethernet device structure.
15135 * @param[in] action_idx
15136 * Shared RSS action ipool index.
15137 * @param[in, out] action
15138 * Partially initialized shared RSS action.
15139 * @param[out] error
15140 * Perform verbose error reporting if not NULL. Initialized in case of
15144 * 0 on success, otherwise negative errno value.
15147 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
15148 uint32_t action_idx,
15149 struct mlx5_shared_action_rss *shared_rss,
15150 struct rte_flow_error *error)
15152 struct mlx5_priv *priv = dev->data->dev_private;
15153 struct mlx5_flow_rss_desc rss_desc = { 0 };
15157 shared_rss->ind_tbl = mlx5_ind_table_obj_new
15158 (dev, shared_rss->origin.queue,
15159 shared_rss->origin.queue_num,
15161 !!dev->data->dev_started);
15162 if (!shared_rss->ind_tbl)
15163 return rte_flow_error_set(error, rte_errno,
15164 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15165 "cannot setup indirection table");
15166 memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
15167 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
15168 rss_desc.const_q = shared_rss->origin.queue;
15169 rss_desc.queue_num = shared_rss->origin.queue_num;
15170 /* Set non-zero value to indicate a shared RSS. */
15171 rss_desc.shared_rss = action_idx;
15172 rss_desc.ind_tbl = shared_rss->ind_tbl;
15173 if (priv->sh->config.dv_flow_en == 2)
15174 rss_desc.hws_flags = MLX5DR_ACTION_FLAG_HWS_RX;
15175 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
15176 struct mlx5_hrxq *hrxq;
15177 uint64_t hash_fields = mlx5_rss_hash_fields[i];
15180 flow_dv_action_rss_l34_hash_adjust(shared_rss->origin.types,
15182 if (shared_rss->origin.level > 1) {
15183 hash_fields |= IBV_RX_HASH_INNER;
15186 rss_desc.tunnel = tunnel;
15187 rss_desc.hash_fields = hash_fields;
15188 hrxq = mlx5_hrxq_get(dev, &rss_desc);
15192 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15193 "cannot get hash queue");
15194 goto error_hrxq_new;
15196 err = __flow_dv_action_rss_hrxq_set
15197 (shared_rss, hash_fields, hrxq->idx);
15203 __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
15204 if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
15205 shared_rss->ind_tbl = NULL;
15211 * Create shared RSS action.
15214 * Pointer to the Ethernet device structure.
15216 * Shared action configuration.
15218 * RSS action specification used to create shared action.
15219 * @param[out] error
15220 * Perform verbose error reporting if not NULL. Initialized in case of
15224 * A valid shared action ID in case of success, 0 otherwise and
15225 * rte_errno is set.
15228 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
15229 const struct rte_flow_indir_action_conf *conf,
15230 const struct rte_flow_action_rss *rss,
15231 struct rte_flow_error *error)
15233 struct mlx5_priv *priv = dev->data->dev_private;
15234 struct mlx5_shared_action_rss *shared_rss = NULL;
15235 struct rte_flow_action_rss *origin;
15236 const uint8_t *rss_key;
15239 RTE_SET_USED(conf);
15240 shared_rss = mlx5_ipool_zmalloc
15241 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
15243 rte_flow_error_set(error, ENOMEM,
15244 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15245 "cannot allocate resource memory");
15246 goto error_rss_init;
15248 if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
15249 rte_flow_error_set(error, E2BIG,
15250 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15251 "rss action number out of range");
15252 goto error_rss_init;
15254 origin = &shared_rss->origin;
15255 origin->func = rss->func;
15256 origin->level = rss->level;
15257 /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
15258 origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
15259 /* NULL RSS key indicates default RSS key. */
15260 rss_key = !rss->key ? rss_hash_default_key : rss->key;
15261 memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
15262 origin->key = &shared_rss->key[0];
15263 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
15264 origin->queue = rss->queue;
15265 origin->queue_num = rss->queue_num;
15266 if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
15267 goto error_rss_init;
15268 /* Update queue with indirect table queue memoyr. */
15269 origin->queue = shared_rss->ind_tbl->queues;
15270 rte_spinlock_init(&shared_rss->action_rss_sl);
15271 __atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
15272 rte_spinlock_lock(&priv->shared_act_sl);
15273 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
15274 &priv->rss_shared_actions, idx, shared_rss, next);
15275 rte_spinlock_unlock(&priv->shared_act_sl);
15279 if (shared_rss->ind_tbl)
15280 mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
15281 !!dev->data->dev_started);
15282 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
15289 * Destroy the shared RSS action.
15290 * Release related hash RX queue objects.
15293 * Pointer to the Ethernet device structure.
15295 * The shared RSS action object ID to be removed.
15296 * @param[out] error
15297 * Perform verbose error reporting if not NULL. Initialized in case of
15301 * 0 on success, otherwise negative errno value.
15304 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
15305 struct rte_flow_error *error)
15307 struct mlx5_priv *priv = dev->data->dev_private;
15308 struct mlx5_shared_action_rss *shared_rss =
15309 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
15310 uint32_t old_refcnt = 1;
15314 return rte_flow_error_set(error, EINVAL,
15315 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15316 "invalid shared action");
15317 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
15318 0, 0, __ATOMIC_ACQUIRE,
15320 return rte_flow_error_set(error, EBUSY,
15321 RTE_FLOW_ERROR_TYPE_ACTION,
15323 "shared rss has references");
15324 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
15326 return rte_flow_error_set(error, EBUSY,
15327 RTE_FLOW_ERROR_TYPE_ACTION,
15329 "shared rss hrxq has references");
15330 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
15331 !!dev->data->dev_started);
15333 return rte_flow_error_set(error, EBUSY,
15334 RTE_FLOW_ERROR_TYPE_ACTION,
15336 "shared rss indirection table has"
15338 rte_spinlock_lock(&priv->shared_act_sl);
15339 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
15340 &priv->rss_shared_actions, idx, shared_rss, next);
15341 rte_spinlock_unlock(&priv->shared_act_sl);
15342 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
15348 * Create indirect action, lock free,
15349 * (mutex should be acquired by caller).
15350 * Dispatcher for action type specific call.
15353 * Pointer to the Ethernet device structure.
15355 * Shared action configuration.
15356 * @param[in] action
15357 * Action specification used to create indirect action.
15358 * @param[out] error
15359 * Perform verbose error reporting if not NULL. Initialized in case of
15363 * A valid shared action handle in case of success, NULL otherwise and
15364 * rte_errno is set.
15366 struct rte_flow_action_handle *
15367 flow_dv_action_create(struct rte_eth_dev *dev,
15368 const struct rte_flow_indir_action_conf *conf,
15369 const struct rte_flow_action *action,
15370 struct rte_flow_error *err)
15372 struct mlx5_priv *priv = dev->data->dev_private;
15373 uint32_t age_idx = 0;
15377 switch (action->type) {
15378 case RTE_FLOW_ACTION_TYPE_RSS:
15379 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
15380 idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
15381 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
15383 case RTE_FLOW_ACTION_TYPE_AGE:
15384 age_idx = flow_dv_aso_age_alloc(dev, err);
15389 idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
15390 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
15391 flow_dv_aso_age_params_init(dev, age_idx,
15392 ((const struct rte_flow_action_age *)
15393 action->conf)->context ?
15394 ((const struct rte_flow_action_age *)
15395 action->conf)->context :
15396 (void *)(uintptr_t)idx,
15397 ((const struct rte_flow_action_age *)
15398 action->conf)->timeout);
15401 case RTE_FLOW_ACTION_TYPE_COUNT:
15402 ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
15403 idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
15404 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
15406 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
15407 ret = flow_dv_translate_create_conntrack(dev, action->conf,
15409 idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
15412 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
15413 NULL, "action type not supported");
15416 return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
15420 * Destroy the indirect action.
15421 * Release action related resources on the NIC and the memory.
15422 * Lock free, (mutex should be acquired by caller).
15423 * Dispatcher for action type specific call.
15426 * Pointer to the Ethernet device structure.
15427 * @param[in] handle
15428 * The indirect action object handle to be removed.
15429 * @param[out] error
15430 * Perform verbose error reporting if not NULL. Initialized in case of
15434 * 0 on success, otherwise negative errno value.
15437 flow_dv_action_destroy(struct rte_eth_dev *dev,
15438 struct rte_flow_action_handle *handle,
15439 struct rte_flow_error *error)
15441 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15442 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15443 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15444 struct mlx5_flow_counter *cnt;
15445 uint32_t no_flow_refcnt = 1;
15449 case MLX5_INDIRECT_ACTION_TYPE_RSS:
15450 return __flow_dv_action_rss_release(dev, idx, error);
15451 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15452 cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
15453 if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
15454 &no_flow_refcnt, 1, false,
15457 return rte_flow_error_set(error, EBUSY,
15458 RTE_FLOW_ERROR_TYPE_ACTION,
15460 "Indirect count action has references");
15461 flow_dv_counter_free(dev, idx);
15463 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15464 ret = flow_dv_aso_age_release(dev, idx);
15467 * In this case, the last flow has a reference will
15468 * actually release the age action.
15470 DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
15471 " released with references %d.", idx, ret);
15473 case MLX5_INDIRECT_ACTION_TYPE_CT:
15474 ret = flow_dv_aso_ct_release(dev, idx, error);
15478 DRV_LOG(DEBUG, "Connection tracking object %u still "
15479 "has references %d.", idx, ret);
15482 return rte_flow_error_set(error, ENOTSUP,
15483 RTE_FLOW_ERROR_TYPE_ACTION,
15485 "action type not supported");
15490 * Updates in place shared RSS action configuration.
15493 * Pointer to the Ethernet device structure.
15495 * The shared RSS action object ID to be updated.
15496 * @param[in] action_conf
15497 * RSS action specification used to modify *shared_rss*.
15498 * @param[out] error
15499 * Perform verbose error reporting if not NULL. Initialized in case of
15503 * 0 on success, otherwise negative errno value.
15504 * @note: currently only support update of RSS queues.
15507 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
15508 const struct rte_flow_action_rss *action_conf,
15509 struct rte_flow_error *error)
15511 struct mlx5_priv *priv = dev->data->dev_private;
15512 struct mlx5_shared_action_rss *shared_rss =
15513 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
15515 void *queue = NULL;
15516 void *queue_i = NULL;
15517 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
15518 bool dev_started = !!dev->data->dev_started;
15521 return rte_flow_error_set(error, EINVAL,
15522 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15523 "invalid shared action to update");
15524 if (priv->obj_ops.ind_table_modify == NULL)
15525 return rte_flow_error_set(error, ENOTSUP,
15526 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15527 "cannot modify indirection table");
15528 queue = mlx5_malloc(MLX5_MEM_ZERO,
15529 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
15532 return rte_flow_error_set(error, ENOMEM,
15533 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15535 "cannot allocate resource memory");
15536 memcpy(queue, action_conf->queue, queue_size);
15537 MLX5_ASSERT(shared_rss->ind_tbl);
15538 rte_spinlock_lock(&shared_rss->action_rss_sl);
15539 queue_i = shared_rss->ind_tbl->queues;
15540 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
15541 queue, action_conf->queue_num,
15542 true /* standalone */,
15543 dev_started /* ref_new_qs */,
15544 dev_started /* deref_old_qs */);
15546 ret = rte_flow_error_set(error, rte_errno,
15547 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15548 "cannot update indirection table");
15550 /* Restore the queue to indirect table internal queue. */
15551 memcpy(queue_i, queue, queue_size);
15552 shared_rss->ind_tbl->queues = queue_i;
15553 shared_rss->origin.queue_num = action_conf->queue_num;
15556 rte_spinlock_unlock(&shared_rss->action_rss_sl);
15561 * Updates in place conntrack context or direction.
15562 * Context update should be synchronized.
15565 * Pointer to the Ethernet device structure.
15567 * The conntrack object ID to be updated.
15568 * @param[in] update
15569 * Pointer to the structure of information to update.
15570 * @param[out] error
15571 * Perform verbose error reporting if not NULL. Initialized in case of
15575 * 0 on success, otherwise negative errno value.
15578 __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
15579 const struct rte_flow_modify_conntrack *update,
15580 struct rte_flow_error *error)
15582 struct mlx5_priv *priv = dev->data->dev_private;
15583 struct mlx5_aso_ct_action *ct;
15584 const struct rte_flow_action_conntrack *new_prf;
15586 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
15589 if (PORT_ID(priv) != owner)
15590 return rte_flow_error_set(error, EACCES,
15591 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15593 "CT object owned by another port");
15594 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
15595 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
15597 return rte_flow_error_set(error, ENOMEM,
15598 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15600 "CT object is inactive");
15601 new_prf = &update->new_ct;
15602 if (update->direction)
15603 ct->is_original = !!new_prf->is_original_dir;
15604 if (update->state) {
15605 /* Only validate the profile when it needs to be updated. */
15606 ret = mlx5_validate_action_ct(dev, new_prf, error);
15609 ret = mlx5_aso_ct_update_by_wqe(priv->sh, ct, new_prf);
15611 return rte_flow_error_set(error, EIO,
15612 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15614 "Failed to send CT context update WQE");
15615 /* Block until ready or a failure. */
15616 ret = mlx5_aso_ct_available(priv->sh, ct);
15618 rte_flow_error_set(error, rte_errno,
15619 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15621 "Timeout to get the CT update");
15627 * Updates in place shared action configuration, lock free,
15628 * (mutex should be acquired by caller).
15631 * Pointer to the Ethernet device structure.
15632 * @param[in] handle
15633 * The indirect action object handle to be updated.
15634 * @param[in] update
15635 * Action specification used to modify the action pointed by *handle*.
15636 * *update* could be of same type with the action pointed by the *handle*
15637 * handle argument, or some other structures like a wrapper, depending on
15638 * the indirect action type.
15639 * @param[out] error
15640 * Perform verbose error reporting if not NULL. Initialized in case of
15644 * 0 on success, otherwise negative errno value.
15647 flow_dv_action_update(struct rte_eth_dev *dev,
15648 struct rte_flow_action_handle *handle,
15649 const void *update,
15650 struct rte_flow_error *err)
15652 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15653 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15654 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15655 const void *action_conf;
15658 case MLX5_INDIRECT_ACTION_TYPE_RSS:
15659 action_conf = ((const struct rte_flow_action *)update)->conf;
15660 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
15661 case MLX5_INDIRECT_ACTION_TYPE_CT:
15662 return __flow_dv_action_ct_update(dev, idx, update, err);
15664 return rte_flow_error_set(err, ENOTSUP,
15665 RTE_FLOW_ERROR_TYPE_ACTION,
15667 "action type update not supported");
15672 * Destroy the meter sub policy table rules.
15673 * Lock free, (mutex should be acquired by caller).
15676 * Pointer to Ethernet device.
15677 * @param[in] sub_policy
15678 * Pointer to meter sub policy table.
15681 __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
15682 struct mlx5_flow_meter_sub_policy *sub_policy)
15684 struct mlx5_priv *priv = dev->data->dev_private;
15685 struct mlx5_flow_tbl_data_entry *tbl;
15686 struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
15687 struct mlx5_flow_meter_info *next_fm;
15688 struct mlx5_sub_policy_color_rule *color_rule;
15692 for (i = 0; i < RTE_COLORS; i++) {
15694 if (i <= RTE_COLOR_YELLOW && policy &&
15695 policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
15696 next_fm = mlx5_flow_meter_find(priv,
15697 policy->act_cnt[i].next_mtr_id, NULL);
15698 RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
15700 claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
15701 tbl = container_of(color_rule->matcher->tbl,
15702 typeof(*tbl), tbl);
15703 mlx5_list_unregister(tbl->matchers,
15704 &color_rule->matcher->entry);
15705 TAILQ_REMOVE(&sub_policy->color_rules[i],
15706 color_rule, next_port);
15707 mlx5_free(color_rule);
15709 mlx5_flow_meter_detach(priv, next_fm);
15712 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15713 if (sub_policy->rix_hrxq[i]) {
15714 if (policy && !policy->is_hierarchy)
15715 mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
15716 sub_policy->rix_hrxq[i] = 0;
15718 if (sub_policy->jump_tbl[i]) {
15719 flow_dv_tbl_resource_release(MLX5_SH(dev),
15720 sub_policy->jump_tbl[i]);
15721 sub_policy->jump_tbl[i] = NULL;
15724 if (sub_policy->tbl_rsc) {
15725 flow_dv_tbl_resource_release(MLX5_SH(dev),
15726 sub_policy->tbl_rsc);
15727 sub_policy->tbl_rsc = NULL;
15732 * Destroy policy rules, lock free,
15733 * (mutex should be acquired by caller).
15734 * Dispatcher for action type specific call.
15737 * Pointer to the Ethernet device structure.
15738 * @param[in] mtr_policy
15739 * Meter policy struct.
15742 flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
15743 struct mlx5_flow_meter_policy *mtr_policy)
15746 struct mlx5_flow_meter_sub_policy *sub_policy;
15747 uint16_t sub_policy_num;
15749 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15750 sub_policy_num = (mtr_policy->sub_policy_num >>
15751 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15752 MLX5_MTR_SUB_POLICY_NUM_MASK;
15753 for (j = 0; j < sub_policy_num; j++) {
15754 sub_policy = mtr_policy->sub_policys[i][j];
15756 __flow_dv_destroy_sub_policy_rules(dev,
15763 * Destroy policy action, lock free,
15764 * (mutex should be acquired by caller).
15765 * Dispatcher for action type specific call.
15768 * Pointer to the Ethernet device structure.
15769 * @param[in] mtr_policy
15770 * Meter policy struct.
15773 flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
15774 struct mlx5_flow_meter_policy *mtr_policy)
15776 struct rte_flow_action *rss_action;
15777 struct mlx5_flow_handle dev_handle;
15780 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15781 if (mtr_policy->act_cnt[i].rix_mark) {
15782 flow_dv_tag_release(dev,
15783 mtr_policy->act_cnt[i].rix_mark);
15784 mtr_policy->act_cnt[i].rix_mark = 0;
15786 if (mtr_policy->act_cnt[i].modify_hdr) {
15787 dev_handle.dvh.modify_hdr =
15788 mtr_policy->act_cnt[i].modify_hdr;
15789 flow_dv_modify_hdr_resource_release(dev, &dev_handle);
15791 switch (mtr_policy->act_cnt[i].fate_action) {
15792 case MLX5_FLOW_FATE_SHARED_RSS:
15793 rss_action = mtr_policy->act_cnt[i].rss;
15794 mlx5_free(rss_action);
15796 case MLX5_FLOW_FATE_PORT_ID:
15797 if (mtr_policy->act_cnt[i].rix_port_id_action) {
15798 flow_dv_port_id_action_resource_release(dev,
15799 mtr_policy->act_cnt[i].rix_port_id_action);
15800 mtr_policy->act_cnt[i].rix_port_id_action = 0;
15803 case MLX5_FLOW_FATE_DROP:
15804 case MLX5_FLOW_FATE_JUMP:
15805 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15806 mtr_policy->act_cnt[i].dr_jump_action[j] =
15810 /*Queue action do nothing*/
15814 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15815 mtr_policy->dr_drop_action[j] = NULL;
15819 * Create yellow action for color aware meter.
15822 * Pointer to the Ethernet device structure.
15824 * Meter information table.
15825 * @param[out] error
15826 * Perform verbose error reporting if not NULL. Initialized in case of
15830 * 0 on success, a negative errno value otherwise and rte_errno is set.
15833 __flow_dv_create_mtr_yellow_action(struct rte_eth_dev *dev,
15834 struct mlx5_flow_meter_info *fm,
15835 struct rte_mtr_error *error)
15837 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
15838 struct mlx5_priv *priv = dev->data->dev_private;
15839 struct rte_flow_error flow_err;
15840 struct mlx5_aso_mtr *aso_mtr;
15841 struct mlx5_aso_mtr_pool *pool;
15844 aso_mtr = container_of(fm, struct mlx5_aso_mtr, fm);
15845 pool = container_of(aso_mtr, struct mlx5_aso_mtr_pool, mtrs[aso_mtr->offset]);
15846 reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
15847 fm->meter_action_y =
15848 mlx5_glue->dv_create_flow_action_aso(priv->sh->rx_domain,
15849 pool->devx_obj->obj,
15851 (1 << MLX5_FLOW_COLOR_YELLOW),
15856 if (!fm->meter_action_y) {
15857 return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15858 "Fail to create yellow meter action.");
15864 * Create policy action per domain, lock free,
15865 * (mutex should be acquired by caller).
15866 * Dispatcher for action type specific call.
15869 * Pointer to the Ethernet device structure.
15870 * @param[in] mtr_policy
15871 * Meter policy struct.
15872 * @param[in] action
15873 * Action specification used to create meter actions.
15875 * Pointer to the flow attributes.
15876 * @param[out] error
15877 * Perform verbose error reporting if not NULL. Initialized in case of
15881 * 0 on success, otherwise negative errno value.
15884 __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
15885 struct mlx5_flow_meter_policy *mtr_policy,
15886 const struct rte_flow_action *actions[RTE_COLORS],
15887 struct rte_flow_attr *attr,
15888 enum mlx5_meter_domain domain,
15889 struct rte_mtr_error *error)
15891 struct mlx5_priv *priv = dev->data->dev_private;
15892 struct rte_flow_error flow_err;
15893 const struct rte_flow_action *act;
15894 uint64_t action_flags;
15895 struct mlx5_flow_handle dh;
15896 struct mlx5_flow dev_flow;
15897 struct mlx5_flow_dv_port_id_action_resource port_id_action;
15899 uint8_t egress, transfer;
15900 struct mlx5_meter_policy_action_container *act_cnt = NULL;
15902 struct mlx5_flow_dv_modify_hdr_resource res;
15903 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
15904 sizeof(struct mlx5_modification_cmd) *
15905 (MLX5_MAX_MODIFY_NUM + 1)];
15907 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
15909 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15910 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15911 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
15912 memset(&dev_flow, 0, sizeof(struct mlx5_flow));
15913 memset(&port_id_action, 0,
15914 sizeof(struct mlx5_flow_dv_port_id_action_resource));
15915 memset(mhdr_res, 0, sizeof(*mhdr_res));
15916 mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
15917 (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15918 MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
15919 dev_flow.handle = &dh;
15920 dev_flow.dv.port_id_action = &port_id_action;
15921 dev_flow.external = true;
15922 for (i = 0; i < RTE_COLORS; i++) {
15923 if (i < MLX5_MTR_RTE_COLORS)
15924 act_cnt = &mtr_policy->act_cnt[i];
15925 /* Skip the color policy actions creation. */
15926 if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
15927 (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
15930 for (act = actions[i];
15931 act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
15932 switch (act->type) {
15933 case RTE_FLOW_ACTION_TYPE_MARK:
15935 uint32_t tag_be = mlx5_flow_mark_set
15936 (((const struct rte_flow_action_mark *)
15939 if (i >= MLX5_MTR_RTE_COLORS)
15940 return -rte_mtr_error_set(error,
15942 RTE_MTR_ERROR_TYPE_METER_POLICY,
15944 "cannot create policy "
15945 "mark action for this color");
15946 if (flow_dv_tag_resource_register(dev, tag_be,
15947 &dev_flow, &flow_err))
15948 return -rte_mtr_error_set(error,
15950 RTE_MTR_ERROR_TYPE_METER_POLICY,
15952 "cannot setup policy mark action");
15953 MLX5_ASSERT(dev_flow.dv.tag_resource);
15954 act_cnt->rix_mark =
15955 dev_flow.handle->dvh.rix_tag;
15956 action_flags |= MLX5_FLOW_ACTION_MARK;
15957 mtr_policy->mark = 1;
15960 case RTE_FLOW_ACTION_TYPE_SET_TAG:
15961 if (i >= MLX5_MTR_RTE_COLORS)
15962 return -rte_mtr_error_set(error,
15964 RTE_MTR_ERROR_TYPE_METER_POLICY,
15966 "cannot create policy "
15967 "set tag action for this color");
15968 if (flow_dv_convert_action_set_tag
15970 (const struct rte_flow_action_set_tag *)
15971 act->conf, &flow_err))
15972 return -rte_mtr_error_set(error,
15974 RTE_MTR_ERROR_TYPE_METER_POLICY,
15975 NULL, "cannot convert policy "
15977 if (!mhdr_res->actions_num)
15978 return -rte_mtr_error_set(error,
15980 RTE_MTR_ERROR_TYPE_METER_POLICY,
15981 NULL, "cannot find policy "
15983 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15985 case RTE_FLOW_ACTION_TYPE_DROP:
15987 struct mlx5_flow_mtr_mng *mtrmng =
15989 struct mlx5_flow_tbl_data_entry *tbl_data;
15992 * Create the drop table with
15993 * METER DROP level.
15995 if (!mtrmng->drop_tbl[domain]) {
15996 mtrmng->drop_tbl[domain] =
15997 flow_dv_tbl_resource_get(dev,
15998 MLX5_FLOW_TABLE_LEVEL_METER,
15999 egress, transfer, false, NULL, 0,
16000 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
16001 if (!mtrmng->drop_tbl[domain])
16002 return -rte_mtr_error_set
16004 RTE_MTR_ERROR_TYPE_METER_POLICY,
16006 "Failed to create meter drop table");
16008 tbl_data = container_of
16009 (mtrmng->drop_tbl[domain],
16010 struct mlx5_flow_tbl_data_entry, tbl);
16011 if (i < MLX5_MTR_RTE_COLORS) {
16012 act_cnt->dr_jump_action[domain] =
16013 tbl_data->jump.action;
16014 act_cnt->fate_action =
16015 MLX5_FLOW_FATE_DROP;
16017 if (i == RTE_COLOR_RED)
16018 mtr_policy->dr_drop_action[domain] =
16019 tbl_data->jump.action;
16020 action_flags |= MLX5_FLOW_ACTION_DROP;
16023 case RTE_FLOW_ACTION_TYPE_QUEUE:
16025 if (i >= MLX5_MTR_RTE_COLORS)
16026 return -rte_mtr_error_set(error,
16028 RTE_MTR_ERROR_TYPE_METER_POLICY,
16029 NULL, "cannot create policy "
16030 "fate queue for this color");
16032 ((const struct rte_flow_action_queue *)
16033 (act->conf))->index;
16034 act_cnt->fate_action =
16035 MLX5_FLOW_FATE_QUEUE;
16036 dev_flow.handle->fate_action =
16037 MLX5_FLOW_FATE_QUEUE;
16038 mtr_policy->is_queue = 1;
16039 action_flags |= MLX5_FLOW_ACTION_QUEUE;
16042 case RTE_FLOW_ACTION_TYPE_RSS:
16046 if (i >= MLX5_MTR_RTE_COLORS)
16047 return -rte_mtr_error_set(error,
16049 RTE_MTR_ERROR_TYPE_METER_POLICY,
16051 "cannot create policy "
16052 "rss action for this color");
16054 * Save RSS conf into policy struct
16055 * for translate stage.
16057 rss_size = (int)rte_flow_conv
16058 (RTE_FLOW_CONV_OP_ACTION,
16059 NULL, 0, act, &flow_err);
16061 return -rte_mtr_error_set(error,
16063 RTE_MTR_ERROR_TYPE_METER_POLICY,
16064 NULL, "Get the wrong "
16065 "rss action struct size");
16066 act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
16067 rss_size, 0, SOCKET_ID_ANY);
16069 return -rte_mtr_error_set(error,
16071 RTE_MTR_ERROR_TYPE_METER_POLICY,
16073 "Fail to malloc rss action memory");
16074 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
16075 act_cnt->rss, rss_size,
16078 return -rte_mtr_error_set(error,
16080 RTE_MTR_ERROR_TYPE_METER_POLICY,
16081 NULL, "Fail to save "
16082 "rss action into policy struct");
16083 act_cnt->fate_action =
16084 MLX5_FLOW_FATE_SHARED_RSS;
16085 action_flags |= MLX5_FLOW_ACTION_RSS;
16088 case RTE_FLOW_ACTION_TYPE_PORT_ID:
16089 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
16091 struct mlx5_flow_dv_port_id_action_resource
16093 uint32_t port_id = 0;
16095 if (i >= MLX5_MTR_RTE_COLORS)
16096 return -rte_mtr_error_set(error,
16098 RTE_MTR_ERROR_TYPE_METER_POLICY,
16099 NULL, "cannot create policy "
16100 "port action for this color");
16101 memset(&port_id_resource, 0,
16102 sizeof(port_id_resource));
16103 if (flow_dv_translate_action_port_id(dev, act,
16104 &port_id, &flow_err))
16105 return -rte_mtr_error_set(error,
16107 RTE_MTR_ERROR_TYPE_METER_POLICY,
16108 NULL, "cannot translate "
16109 "policy port action");
16110 port_id_resource.port_id = port_id;
16111 if (flow_dv_port_id_action_resource_register
16112 (dev, &port_id_resource,
16113 &dev_flow, &flow_err))
16114 return -rte_mtr_error_set(error,
16116 RTE_MTR_ERROR_TYPE_METER_POLICY,
16117 NULL, "cannot setup "
16118 "policy port action");
16119 act_cnt->rix_port_id_action =
16120 dev_flow.handle->rix_port_id_action;
16121 act_cnt->fate_action =
16122 MLX5_FLOW_FATE_PORT_ID;
16123 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
16126 case RTE_FLOW_ACTION_TYPE_JUMP:
16128 uint32_t jump_group = 0;
16129 uint32_t table = 0;
16130 struct mlx5_flow_tbl_data_entry *tbl_data;
16131 struct flow_grp_info grp_info = {
16132 .external = !!dev_flow.external,
16133 .transfer = !!transfer,
16134 .fdb_def_rule = !!priv->fdb_def_rule,
16136 .skip_scale = dev_flow.skip_scale &
16137 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
16139 struct mlx5_flow_meter_sub_policy *sub_policy =
16140 mtr_policy->sub_policys[domain][0];
16142 if (i >= MLX5_MTR_RTE_COLORS)
16143 return -rte_mtr_error_set(error,
16145 RTE_MTR_ERROR_TYPE_METER_POLICY,
16147 "cannot create policy "
16148 "jump action for this color");
16150 ((const struct rte_flow_action_jump *)
16152 if (mlx5_flow_group_to_table(dev, NULL,
16155 &grp_info, &flow_err))
16156 return -rte_mtr_error_set(error,
16158 RTE_MTR_ERROR_TYPE_METER_POLICY,
16159 NULL, "cannot setup "
16160 "policy jump action");
16161 sub_policy->jump_tbl[i] =
16162 flow_dv_tbl_resource_get(dev,
16165 !!dev_flow.external,
16166 NULL, jump_group, 0,
16169 (!sub_policy->jump_tbl[i])
16170 return -rte_mtr_error_set(error,
16172 RTE_MTR_ERROR_TYPE_METER_POLICY,
16173 NULL, "cannot create jump action.");
16174 tbl_data = container_of
16175 (sub_policy->jump_tbl[i],
16176 struct mlx5_flow_tbl_data_entry, tbl);
16177 act_cnt->dr_jump_action[domain] =
16178 tbl_data->jump.action;
16179 act_cnt->fate_action =
16180 MLX5_FLOW_FATE_JUMP;
16181 action_flags |= MLX5_FLOW_ACTION_JUMP;
16184 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
16186 if (i >= MLX5_MTR_RTE_COLORS)
16187 return -rte_mtr_error_set(error,
16189 RTE_MTR_ERROR_TYPE_METER_POLICY,
16191 "cannot create policy modify field for this color");
16192 if (flow_dv_convert_action_modify_field
16193 (dev, mhdr_res, act, attr, &flow_err))
16194 return -rte_mtr_error_set(error,
16196 RTE_MTR_ERROR_TYPE_METER_POLICY,
16197 NULL, "cannot setup policy modify field action");
16198 if (!mhdr_res->actions_num)
16199 return -rte_mtr_error_set(error,
16201 RTE_MTR_ERROR_TYPE_METER_POLICY,
16202 NULL, "cannot find policy modify field action");
16203 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
16207 * No need to check meter hierarchy for R colors
16208 * here since it is done in the validation stage.
16210 case RTE_FLOW_ACTION_TYPE_METER:
16212 const struct rte_flow_action_meter *mtr;
16213 struct mlx5_flow_meter_info *next_fm;
16214 struct mlx5_flow_meter_policy *next_policy;
16215 struct rte_flow_action tag_action;
16216 struct mlx5_rte_flow_action_set_tag set_tag;
16217 uint32_t next_mtr_idx = 0;
16220 next_fm = mlx5_flow_meter_find(priv,
16224 return -rte_mtr_error_set(error, EINVAL,
16225 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
16226 "Fail to find next meter.");
16227 if (next_fm->def_policy)
16228 return -rte_mtr_error_set(error, EINVAL,
16229 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
16230 "Hierarchy only supports termination meter.");
16231 next_policy = mlx5_flow_meter_policy_find(dev,
16232 next_fm->policy_id, NULL);
16233 MLX5_ASSERT(next_policy);
16234 if (next_fm->drop_cnt) {
16237 mlx5_flow_get_reg_id(dev,
16240 (struct rte_flow_error *)error);
16241 set_tag.offset = (priv->mtr_reg_share ?
16242 MLX5_MTR_COLOR_BITS : 0);
16243 set_tag.length = (priv->mtr_reg_share ?
16244 MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
16246 set_tag.data = next_mtr_idx;
16248 (enum rte_flow_action_type)
16249 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
16250 tag_action.conf = &set_tag;
16251 if (flow_dv_convert_action_set_reg
16252 (mhdr_res, &tag_action,
16253 (struct rte_flow_error *)error))
16256 MLX5_FLOW_ACTION_SET_TAG;
16258 if (i == RTE_COLOR_YELLOW && next_fm->color_aware &&
16259 !next_fm->meter_action_y)
16260 if (__flow_dv_create_mtr_yellow_action(dev, next_fm, error))
16262 act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
16263 act_cnt->next_mtr_id = next_fm->meter_id;
16264 act_cnt->next_sub_policy = NULL;
16265 mtr_policy->is_hierarchy = 1;
16266 mtr_policy->dev = next_policy->dev;
16267 if (next_policy->mark)
16268 mtr_policy->mark = 1;
16270 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
16274 return -rte_mtr_error_set(error, ENOTSUP,
16275 RTE_MTR_ERROR_TYPE_METER_POLICY,
16276 NULL, "action type not supported");
16278 if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) ||
16279 (action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD)) {
16280 /* create modify action if needed. */
16281 dev_flow.dv.group = 1;
16282 if (flow_dv_modify_hdr_resource_register
16283 (dev, mhdr_res, &dev_flow, &flow_err))
16284 return -rte_mtr_error_set(error,
16286 RTE_MTR_ERROR_TYPE_METER_POLICY,
16287 NULL, "cannot register policy set tag/modify field action");
16288 act_cnt->modify_hdr =
16289 dev_flow.handle->dvh.modify_hdr;
16297 * Create policy action per domain, lock free,
16298 * (mutex should be acquired by caller).
16299 * Dispatcher for action type specific call.
16302 * Pointer to the Ethernet device structure.
16303 * @param[in] mtr_policy
16304 * Meter policy struct.
16305 * @param[in] action
16306 * Action specification used to create meter actions.
16308 * Pointer to the flow attributes.
16309 * @param[out] error
16310 * Perform verbose error reporting if not NULL. Initialized in case of
16314 * 0 on success, otherwise negative errno value.
16317 flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
16318 struct mlx5_flow_meter_policy *mtr_policy,
16319 const struct rte_flow_action *actions[RTE_COLORS],
16320 struct rte_flow_attr *attr,
16321 struct rte_mtr_error *error)
16324 uint16_t sub_policy_num;
16326 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16327 sub_policy_num = (mtr_policy->sub_policy_num >>
16328 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
16329 MLX5_MTR_SUB_POLICY_NUM_MASK;
16330 if (sub_policy_num) {
16331 ret = __flow_dv_create_domain_policy_acts(dev,
16332 mtr_policy, actions, attr,
16333 (enum mlx5_meter_domain)i, error);
16334 /* Cleaning resource is done in the caller level. */
16343 * Query a DV flow rule for its statistics via DevX.
16346 * Pointer to Ethernet device.
16347 * @param[in] cnt_idx
16348 * Index to the flow counter.
16350 * Data retrieved by the query.
16351 * @param[out] error
16352 * Perform verbose error reporting if not NULL.
16355 * 0 on success, a negative errno value otherwise and rte_errno is set.
16358 flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
16359 struct rte_flow_error *error)
16361 struct mlx5_priv *priv = dev->data->dev_private;
16362 struct rte_flow_query_count *qc = data;
16364 if (!priv->sh->cdev->config.devx)
16365 return rte_flow_error_set(error, ENOTSUP,
16366 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16368 "counters are not supported");
16370 uint64_t pkts, bytes;
16371 struct mlx5_flow_counter *cnt;
16372 int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
16375 return rte_flow_error_set(error, -err,
16376 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16377 NULL, "cannot read counters");
16378 cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
16381 qc->hits = pkts - cnt->hits;
16382 qc->bytes = bytes - cnt->bytes;
16385 cnt->bytes = bytes;
16389 return rte_flow_error_set(error, EINVAL,
16390 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16392 "counters are not available");
16396 flow_dv_action_query(struct rte_eth_dev *dev,
16397 const struct rte_flow_action_handle *handle, void *data,
16398 struct rte_flow_error *error)
16400 struct mlx5_age_param *age_param;
16401 struct rte_flow_query_age *resp;
16402 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
16403 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
16404 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
16405 struct mlx5_priv *priv = dev->data->dev_private;
16406 struct mlx5_aso_ct_action *ct;
16411 case MLX5_INDIRECT_ACTION_TYPE_AGE:
16412 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
16414 resp->aged = __atomic_load_n(&age_param->state,
16415 __ATOMIC_RELAXED) == AGE_TMOUT ?
16417 resp->sec_since_last_hit_valid = !resp->aged;
16418 if (resp->sec_since_last_hit_valid)
16419 resp->sec_since_last_hit = __atomic_load_n
16420 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
16422 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
16423 return flow_dv_query_count(dev, idx, data, error);
16424 case MLX5_INDIRECT_ACTION_TYPE_CT:
16425 owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
16426 if (owner != PORT_ID(priv))
16427 return rte_flow_error_set(error, EACCES,
16428 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16430 "CT object owned by another port");
16431 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
16432 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
16435 return rte_flow_error_set(error, EFAULT,
16436 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16438 "CT object is inactive");
16439 ((struct rte_flow_action_conntrack *)data)->peer_port =
16441 ((struct rte_flow_action_conntrack *)data)->is_original_dir =
16443 if (mlx5_aso_ct_query_by_wqe(priv->sh, ct, data))
16444 return rte_flow_error_set(error, EIO,
16445 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16447 "Failed to query CT context");
16450 return rte_flow_error_set(error, ENOTSUP,
16451 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16452 "action type query not supported");
16457 * Query a flow rule AGE action for aging information.
16460 * Pointer to Ethernet device.
16462 * Pointer to the sub flow.
16464 * data retrieved by the query.
16465 * @param[out] error
16466 * Perform verbose error reporting if not NULL.
16469 * 0 on success, a negative errno value otherwise and rte_errno is set.
16472 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
16473 void *data, struct rte_flow_error *error)
16475 struct rte_flow_query_age *resp = data;
16476 struct mlx5_age_param *age_param;
16479 struct mlx5_aso_age_action *act =
16480 flow_aso_age_get_by_idx(dev, flow->age);
16482 age_param = &act->age_params;
16483 } else if (flow->counter) {
16484 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
16486 if (!age_param || !age_param->timeout)
16487 return rte_flow_error_set
16489 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16490 NULL, "cannot read age data");
16492 return rte_flow_error_set(error, EINVAL,
16493 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16494 NULL, "age data not available");
16496 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
16498 resp->sec_since_last_hit_valid = !resp->aged;
16499 if (resp->sec_since_last_hit_valid)
16500 resp->sec_since_last_hit = __atomic_load_n
16501 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
16508 * @see rte_flow_query()
16509 * @see rte_flow_ops
16512 flow_dv_query(struct rte_eth_dev *dev,
16513 struct rte_flow *flow __rte_unused,
16514 const struct rte_flow_action *actions __rte_unused,
16515 void *data __rte_unused,
16516 struct rte_flow_error *error __rte_unused)
16520 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
16521 switch (actions->type) {
16522 case RTE_FLOW_ACTION_TYPE_VOID:
16524 case RTE_FLOW_ACTION_TYPE_COUNT:
16525 ret = flow_dv_query_count(dev, flow->counter, data,
16528 case RTE_FLOW_ACTION_TYPE_AGE:
16529 ret = flow_dv_query_age(dev, flow, data, error);
16532 return rte_flow_error_set(error, ENOTSUP,
16533 RTE_FLOW_ERROR_TYPE_ACTION,
16535 "action not supported");
16542 * Destroy the meter table set.
16543 * Lock free, (mutex should be acquired by caller).
16546 * Pointer to Ethernet device.
16548 * Meter information table.
16551 flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
16552 struct mlx5_flow_meter_info *fm)
16554 struct mlx5_priv *priv = dev->data->dev_private;
16557 if (!fm || !priv->sh->config.dv_flow_en)
16559 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16560 if (fm->drop_rule[i]) {
16561 claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
16562 fm->drop_rule[i] = NULL;
16568 flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
16570 struct mlx5_priv *priv = dev->data->dev_private;
16571 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16572 struct mlx5_flow_tbl_data_entry *tbl;
16575 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16576 if (mtrmng->def_rule[i]) {
16577 claim_zero(mlx5_flow_os_destroy_flow
16578 (mtrmng->def_rule[i]));
16579 mtrmng->def_rule[i] = NULL;
16581 if (mtrmng->def_matcher[i]) {
16582 tbl = container_of(mtrmng->def_matcher[i]->tbl,
16583 struct mlx5_flow_tbl_data_entry, tbl);
16584 mlx5_list_unregister(tbl->matchers,
16585 &mtrmng->def_matcher[i]->entry);
16586 mtrmng->def_matcher[i] = NULL;
16588 for (j = 0; j < MLX5_REG_BITS; j++) {
16589 if (mtrmng->drop_matcher[i][j]) {
16591 container_of(mtrmng->drop_matcher[i][j]->tbl,
16592 struct mlx5_flow_tbl_data_entry,
16594 mlx5_list_unregister(tbl->matchers,
16595 &mtrmng->drop_matcher[i][j]->entry);
16596 mtrmng->drop_matcher[i][j] = NULL;
16599 if (mtrmng->drop_tbl[i]) {
16600 flow_dv_tbl_resource_release(MLX5_SH(dev),
16601 mtrmng->drop_tbl[i]);
16602 mtrmng->drop_tbl[i] = NULL;
16607 /* Number of meter flow actions, count and jump or count and drop. */
16608 #define METER_ACTIONS 2
16611 __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
16612 enum mlx5_meter_domain domain)
16614 struct mlx5_priv *priv = dev->data->dev_private;
16615 struct mlx5_flow_meter_def_policy *def_policy =
16616 priv->sh->mtrmng->def_policy[domain];
16618 __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
16619 mlx5_free(def_policy);
16620 priv->sh->mtrmng->def_policy[domain] = NULL;
16624 * Destroy the default policy table set.
16627 * Pointer to Ethernet device.
16630 flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
16632 struct mlx5_priv *priv = dev->data->dev_private;
16635 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
16636 if (priv->sh->mtrmng->def_policy[i])
16637 __flow_dv_destroy_domain_def_policy(dev,
16638 (enum mlx5_meter_domain)i);
16639 priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
16643 __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
16644 uint32_t color_reg_c_idx,
16645 enum rte_color color, void *matcher_object,
16646 int actions_n, void *actions,
16647 bool match_src_port, const struct rte_flow_item *item,
16648 void **rule, const struct rte_flow_attr *attr)
16651 struct mlx5_flow_dv_match_params value = {
16652 .size = sizeof(value.buf),
16654 struct mlx5_flow_dv_match_params matcher = {
16655 .size = sizeof(matcher.buf),
16657 struct mlx5_priv *priv = dev->data->dev_private;
16660 if (match_src_port && priv->sh->esw_mode) {
16661 if (flow_dv_translate_item_port_id(dev, matcher.buf,
16662 value.buf, item, attr)) {
16663 DRV_LOG(ERR, "Failed to create meter policy%d flow's"
16664 " value with port.", color);
16668 flow_dv_match_meta_reg(matcher.buf, value.buf,
16669 (enum modify_reg)color_reg_c_idx,
16670 rte_col_2_mlx5_col(color), UINT32_MAX);
16671 misc_mask = flow_dv_matcher_enable(value.buf);
16672 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16673 ret = mlx5_flow_os_create_flow(matcher_object, (void *)&value,
16674 actions_n, actions, rule);
16676 DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
16683 __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
16684 uint32_t color_reg_c_idx,
16686 struct mlx5_flow_meter_sub_policy *sub_policy,
16687 const struct rte_flow_attr *attr,
16688 bool match_src_port,
16689 const struct rte_flow_item *item,
16690 struct mlx5_flow_dv_matcher **policy_matcher,
16691 struct rte_flow_error *error)
16693 struct mlx5_list_entry *entry;
16694 struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
16695 struct mlx5_flow_dv_matcher matcher = {
16697 .size = sizeof(matcher.mask.buf),
16701 struct mlx5_flow_dv_match_params value = {
16702 .size = sizeof(value.buf),
16704 struct mlx5_flow_cb_ctx ctx = {
16708 struct mlx5_flow_tbl_data_entry *tbl_data;
16709 struct mlx5_priv *priv = dev->data->dev_private;
16710 const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
16712 if (match_src_port && priv->sh->esw_mode) {
16713 if (flow_dv_translate_item_port_id(dev, matcher.mask.buf,
16714 value.buf, item, attr)) {
16715 DRV_LOG(ERR, "Failed to register meter policy%d matcher"
16716 " with port.", priority);
16720 tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
16721 if (priority < RTE_COLOR_RED)
16722 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16723 (enum modify_reg)color_reg_c_idx, 0, color_mask);
16724 matcher.priority = priority;
16725 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
16726 matcher.mask.size);
16727 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16729 DRV_LOG(ERR, "Failed to register meter drop matcher.");
16733 container_of(entry, struct mlx5_flow_dv_matcher, entry);
16738 * Create the policy rules per domain.
16741 * Pointer to Ethernet device.
16742 * @param[in] sub_policy
16743 * Pointer to sub policy table..
16744 * @param[in] egress
16745 * Direction of the table.
16746 * @param[in] transfer
16747 * E-Switch or NIC flow.
16749 * Pointer to policy action list per color.
16752 * 0 on success, -1 otherwise.
16755 __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
16756 struct mlx5_flow_meter_sub_policy *sub_policy,
16757 uint8_t egress, uint8_t transfer, bool match_src_port,
16758 struct mlx5_meter_policy_acts acts[RTE_COLORS])
16760 struct mlx5_priv *priv = dev->data->dev_private;
16761 struct rte_flow_error flow_err;
16762 uint32_t color_reg_c_idx;
16763 struct rte_flow_attr attr = {
16764 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
16767 .egress = !!egress,
16768 .transfer = !!transfer,
16772 int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
16773 struct mlx5_sub_policy_color_rule *color_rule;
16775 struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
16779 /* Create policy table with POLICY level. */
16780 if (!sub_policy->tbl_rsc)
16781 sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
16782 MLX5_FLOW_TABLE_LEVEL_POLICY,
16783 egress, transfer, false, NULL, 0, 0,
16784 sub_policy->idx, &flow_err);
16785 if (!sub_policy->tbl_rsc) {
16787 "Failed to create meter sub policy table.");
16790 /* Prepare matchers. */
16791 color_reg_c_idx = ret;
16792 for (i = 0; i < RTE_COLORS; i++) {
16793 TAILQ_INIT(&sub_policy->color_rules[i]);
16794 if (!acts[i].actions_n)
16796 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
16797 sizeof(struct mlx5_sub_policy_color_rule),
16800 DRV_LOG(ERR, "No memory to create color rule.");
16803 tmp_rules[i] = color_rule;
16804 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
16805 color_rule, next_port);
16806 color_rule->src_port = priv->representor_id;
16809 /* Create matchers for colors. */
16810 svport_match = (i != RTE_COLOR_RED) ? match_src_port : false;
16811 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
16812 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
16813 &attr, svport_match, NULL,
16814 &color_rule->matcher, &flow_err)) {
16815 DRV_LOG(ERR, "Failed to create color%u matcher.", i);
16818 /* Create flow, matching color. */
16819 if (__flow_dv_create_policy_flow(dev,
16820 color_reg_c_idx, (enum rte_color)i,
16821 color_rule->matcher->matcher_object,
16822 acts[i].actions_n, acts[i].dv_actions,
16823 svport_match, NULL, &color_rule->rule,
16825 DRV_LOG(ERR, "Failed to create color%u rule.", i);
16831 /* All the policy rules will be cleared. */
16833 color_rule = tmp_rules[i];
16835 if (color_rule->rule)
16836 mlx5_flow_os_destroy_flow(color_rule->rule);
16837 if (color_rule->matcher) {
16838 struct mlx5_flow_tbl_data_entry *tbl =
16839 container_of(color_rule->matcher->tbl,
16840 typeof(*tbl), tbl);
16841 mlx5_list_unregister(tbl->matchers,
16842 &color_rule->matcher->entry);
16844 TAILQ_REMOVE(&sub_policy->color_rules[i],
16845 color_rule, next_port);
16846 mlx5_free(color_rule);
16853 __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
16854 struct mlx5_flow_meter_policy *mtr_policy,
16855 struct mlx5_flow_meter_sub_policy *sub_policy,
16858 struct mlx5_priv *priv = dev->data->dev_private;
16859 struct mlx5_meter_policy_acts acts[RTE_COLORS];
16860 struct mlx5_flow_dv_tag_resource *tag;
16861 struct mlx5_flow_dv_port_id_action_resource *port_action;
16862 struct mlx5_hrxq *hrxq;
16863 struct mlx5_flow_meter_info *next_fm[RTE_COLORS] = {NULL};
16864 struct mlx5_flow_meter_policy *next_policy;
16865 struct mlx5_flow_meter_sub_policy *next_sub_policy;
16866 struct mlx5_flow_tbl_data_entry *tbl_data;
16867 struct rte_flow_error error;
16868 uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16869 uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16870 bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
16871 bool match_src_port = false;
16874 /* If RSS or Queue, no previous actions / rules is created. */
16875 for (i = 0; i < RTE_COLORS; i++) {
16876 acts[i].actions_n = 0;
16877 if (i == RTE_COLOR_RED) {
16878 /* Only support drop on red. */
16879 acts[i].dv_actions[0] =
16880 mtr_policy->dr_drop_action[domain];
16881 acts[i].actions_n = 1;
16884 if (mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
16885 struct rte_flow_attr attr = {
16886 .transfer = transfer
16889 next_fm[i] = mlx5_flow_meter_find(priv,
16890 mtr_policy->act_cnt[i].next_mtr_id,
16894 "Failed to get next hierarchy meter.");
16897 if (mlx5_flow_meter_attach(priv, next_fm[i],
16899 DRV_LOG(ERR, "%s", error.message);
16903 /* Meter action must be the first for TX. */
16905 acts[i].dv_actions[acts[i].actions_n] =
16906 (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
16907 next_fm[i]->meter_action_y :
16908 next_fm[i]->meter_action_g;
16909 acts[i].actions_n++;
16912 if (mtr_policy->act_cnt[i].rix_mark) {
16913 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
16914 mtr_policy->act_cnt[i].rix_mark);
16916 DRV_LOG(ERR, "Failed to find "
16917 "mark action for policy.");
16920 acts[i].dv_actions[acts[i].actions_n] = tag->action;
16921 acts[i].actions_n++;
16923 if (mtr_policy->act_cnt[i].modify_hdr) {
16924 acts[i].dv_actions[acts[i].actions_n] =
16925 mtr_policy->act_cnt[i].modify_hdr->action;
16926 acts[i].actions_n++;
16928 if (mtr_policy->act_cnt[i].fate_action) {
16929 switch (mtr_policy->act_cnt[i].fate_action) {
16930 case MLX5_FLOW_FATE_PORT_ID:
16931 port_action = mlx5_ipool_get
16932 (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
16933 mtr_policy->act_cnt[i].rix_port_id_action);
16934 if (!port_action) {
16935 DRV_LOG(ERR, "Failed to find "
16936 "port action for policy.");
16939 acts[i].dv_actions[acts[i].actions_n] =
16940 port_action->action;
16941 acts[i].actions_n++;
16942 mtr_policy->dev = dev;
16943 match_src_port = true;
16945 case MLX5_FLOW_FATE_DROP:
16946 case MLX5_FLOW_FATE_JUMP:
16947 acts[i].dv_actions[acts[i].actions_n] =
16948 mtr_policy->act_cnt[i].dr_jump_action[domain];
16949 acts[i].actions_n++;
16951 case MLX5_FLOW_FATE_SHARED_RSS:
16952 case MLX5_FLOW_FATE_QUEUE:
16953 hrxq = mlx5_ipool_get
16954 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16955 sub_policy->rix_hrxq[i]);
16957 DRV_LOG(ERR, "Failed to find "
16958 "queue action for policy.");
16961 acts[i].dv_actions[acts[i].actions_n] =
16963 acts[i].actions_n++;
16965 case MLX5_FLOW_FATE_MTR:
16968 "No next hierarchy meter.");
16972 acts[i].dv_actions[acts[i].actions_n] =
16973 (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
16974 next_fm[i]->meter_action_y :
16975 next_fm[i]->meter_action_g;
16976 acts[i].actions_n++;
16978 if (mtr_policy->act_cnt[i].next_sub_policy) {
16980 mtr_policy->act_cnt[i].next_sub_policy;
16983 mlx5_flow_meter_policy_find(dev,
16984 next_fm[i]->policy_id, NULL);
16985 MLX5_ASSERT(next_policy);
16987 next_policy->sub_policys[domain][0];
16990 container_of(next_sub_policy->tbl_rsc,
16991 struct mlx5_flow_tbl_data_entry, tbl);
16992 acts[i].dv_actions[acts[i].actions_n++] =
16993 tbl_data->jump.action;
16994 if (mtr_policy->act_cnt[i].modify_hdr)
16995 match_src_port = !!transfer;
16998 /*Queue action do nothing*/
17003 if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
17004 egress, transfer, match_src_port, acts)) {
17006 "Failed to create policy rules per domain.");
17011 for (i = 0; i < RTE_COLORS; i++)
17013 mlx5_flow_meter_detach(priv, next_fm[i]);
17018 * Create the policy rules.
17021 * Pointer to Ethernet device.
17022 * @param[in,out] mtr_policy
17023 * Pointer to meter policy table.
17026 * 0 on success, -1 otherwise.
17029 flow_dv_create_policy_rules(struct rte_eth_dev *dev,
17030 struct mlx5_flow_meter_policy *mtr_policy)
17033 uint16_t sub_policy_num;
17035 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17036 sub_policy_num = (mtr_policy->sub_policy_num >>
17037 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17038 MLX5_MTR_SUB_POLICY_NUM_MASK;
17039 if (!sub_policy_num)
17041 /* Prepare actions list and create policy rules. */
17042 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
17043 mtr_policy->sub_policys[i][0], i)) {
17044 DRV_LOG(ERR, "Failed to create policy action "
17045 "list per domain.");
17053 __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
17055 struct mlx5_priv *priv = dev->data->dev_private;
17056 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
17057 struct mlx5_flow_meter_def_policy *def_policy;
17058 struct mlx5_flow_tbl_resource *jump_tbl;
17059 struct mlx5_flow_tbl_data_entry *tbl_data;
17060 uint8_t egress, transfer;
17061 struct rte_flow_error error;
17062 struct mlx5_meter_policy_acts acts[RTE_COLORS];
17065 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
17066 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
17067 def_policy = mtrmng->def_policy[domain];
17069 def_policy = mlx5_malloc(MLX5_MEM_ZERO,
17070 sizeof(struct mlx5_flow_meter_def_policy),
17071 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
17073 DRV_LOG(ERR, "Failed to alloc default policy table.");
17074 goto def_policy_error;
17076 mtrmng->def_policy[domain] = def_policy;
17077 /* Create the meter suffix table with SUFFIX level. */
17078 jump_tbl = flow_dv_tbl_resource_get(dev,
17079 MLX5_FLOW_TABLE_LEVEL_METER,
17080 egress, transfer, false, NULL, 0,
17081 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
17084 "Failed to create meter suffix table.");
17085 goto def_policy_error;
17087 def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
17088 tbl_data = container_of(jump_tbl,
17089 struct mlx5_flow_tbl_data_entry, tbl);
17090 def_policy->dr_jump_action[RTE_COLOR_GREEN] =
17091 tbl_data->jump.action;
17092 acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
17093 acts[RTE_COLOR_GREEN].actions_n = 1;
17095 * YELLOW has the same default policy as GREEN does.
17096 * G & Y share the same table and action. The 2nd time of table
17097 * resource getting is just to update the reference count for
17098 * the releasing stage.
17100 jump_tbl = flow_dv_tbl_resource_get(dev,
17101 MLX5_FLOW_TABLE_LEVEL_METER,
17102 egress, transfer, false, NULL, 0,
17103 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
17106 "Failed to get meter suffix table.");
17107 goto def_policy_error;
17109 def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
17110 tbl_data = container_of(jump_tbl,
17111 struct mlx5_flow_tbl_data_entry, tbl);
17112 def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
17113 tbl_data->jump.action;
17114 acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
17115 acts[RTE_COLOR_YELLOW].actions_n = 1;
17116 /* Create jump action to the drop table. */
17117 if (!mtrmng->drop_tbl[domain]) {
17118 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
17119 (dev, MLX5_FLOW_TABLE_LEVEL_METER,
17120 egress, transfer, false, NULL, 0,
17121 0, MLX5_MTR_TABLE_ID_DROP, &error);
17122 if (!mtrmng->drop_tbl[domain]) {
17123 DRV_LOG(ERR, "Failed to create meter "
17124 "drop table for default policy.");
17125 goto def_policy_error;
17128 /* all RED: unique Drop table for jump action. */
17129 tbl_data = container_of(mtrmng->drop_tbl[domain],
17130 struct mlx5_flow_tbl_data_entry, tbl);
17131 def_policy->dr_jump_action[RTE_COLOR_RED] =
17132 tbl_data->jump.action;
17133 acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
17134 acts[RTE_COLOR_RED].actions_n = 1;
17135 /* Create default policy rules. */
17136 ret = __flow_dv_create_domain_policy_rules(dev,
17137 &def_policy->sub_policy,
17138 egress, transfer, false, acts);
17140 DRV_LOG(ERR, "Failed to create default policy rules.");
17141 goto def_policy_error;
17146 __flow_dv_destroy_domain_def_policy(dev,
17147 (enum mlx5_meter_domain)domain);
17152 * Create the default policy table set.
17155 * Pointer to Ethernet device.
17157 * 0 on success, -1 otherwise.
17160 flow_dv_create_def_policy(struct rte_eth_dev *dev)
17162 struct mlx5_priv *priv = dev->data->dev_private;
17165 /* Non-termination policy table. */
17166 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17167 if (!priv->sh->config.dv_esw_en &&
17168 i == MLX5_MTR_DOMAIN_TRANSFER)
17170 if (__flow_dv_create_domain_def_policy(dev, i)) {
17171 DRV_LOG(ERR, "Failed to create default policy");
17172 /* Rollback the created default policies for others. */
17173 flow_dv_destroy_def_policy(dev);
17181 * Create the needed meter tables.
17182 * Lock free, (mutex should be acquired by caller).
17185 * Pointer to Ethernet device.
17187 * Meter information table.
17188 * @param[in] mtr_idx
17190 * @param[in] domain_bitmap
17193 * 0 on success, -1 otherwise.
17196 flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
17197 struct mlx5_flow_meter_info *fm,
17199 uint8_t domain_bitmap)
17201 struct mlx5_priv *priv = dev->data->dev_private;
17202 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
17203 struct rte_flow_error error;
17204 struct mlx5_flow_tbl_data_entry *tbl_data;
17205 uint8_t egress, transfer;
17206 void *actions[METER_ACTIONS];
17207 int domain, ret, i;
17208 struct mlx5_flow_counter *cnt;
17209 struct mlx5_flow_dv_match_params value = {
17210 .size = sizeof(value.buf),
17212 struct mlx5_flow_dv_match_params matcher_para = {
17213 .size = sizeof(matcher_para.buf),
17215 int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
17217 uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
17218 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
17219 struct mlx5_list_entry *entry;
17220 struct mlx5_flow_dv_matcher matcher = {
17222 .size = sizeof(matcher.mask.buf),
17225 struct mlx5_flow_dv_matcher *drop_matcher;
17226 struct mlx5_flow_cb_ctx ctx = {
17232 if (!priv->mtr_en || mtr_id_reg_c < 0) {
17233 rte_errno = ENOTSUP;
17236 for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
17237 if (!(domain_bitmap & (1 << domain)) ||
17238 (mtrmng->def_rule[domain] && !fm->drop_cnt))
17240 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
17241 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
17242 /* Create the drop table with METER DROP level. */
17243 if (!mtrmng->drop_tbl[domain]) {
17244 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
17245 MLX5_FLOW_TABLE_LEVEL_METER,
17246 egress, transfer, false, NULL, 0,
17247 0, MLX5_MTR_TABLE_ID_DROP, &error);
17248 if (!mtrmng->drop_tbl[domain]) {
17249 DRV_LOG(ERR, "Failed to create meter drop table.");
17253 /* Create default matcher in drop table. */
17254 matcher.tbl = mtrmng->drop_tbl[domain],
17255 tbl_data = container_of(mtrmng->drop_tbl[domain],
17256 struct mlx5_flow_tbl_data_entry, tbl);
17257 if (!mtrmng->def_matcher[domain]) {
17258 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
17259 (enum modify_reg)mtr_id_reg_c,
17261 matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
17262 matcher.crc = rte_raw_cksum
17263 ((const void *)matcher.mask.buf,
17264 matcher.mask.size);
17265 entry = mlx5_list_register(tbl_data->matchers, &ctx);
17267 DRV_LOG(ERR, "Failed to register meter "
17268 "drop default matcher.");
17271 mtrmng->def_matcher[domain] = container_of(entry,
17272 struct mlx5_flow_dv_matcher, entry);
17274 /* Create default rule in drop table. */
17275 if (!mtrmng->def_rule[domain]) {
17277 actions[i++] = priv->sh->dr_drop_action;
17278 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
17279 (enum modify_reg)mtr_id_reg_c, 0, 0);
17280 misc_mask = flow_dv_matcher_enable(value.buf);
17281 __flow_dv_adjust_buf_size(&value.size, misc_mask);
17282 ret = mlx5_flow_os_create_flow
17283 (mtrmng->def_matcher[domain]->matcher_object,
17284 (void *)&value, i, actions,
17285 &mtrmng->def_rule[domain]);
17287 DRV_LOG(ERR, "Failed to create meter "
17288 "default drop rule for drop table.");
17294 MLX5_ASSERT(mtrmng->max_mtr_bits);
17295 if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
17296 /* Create matchers for Drop. */
17297 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
17298 (enum modify_reg)mtr_id_reg_c, 0,
17299 (mtr_id_mask << mtr_id_offset));
17300 matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
17301 matcher.crc = rte_raw_cksum
17302 ((const void *)matcher.mask.buf,
17303 matcher.mask.size);
17304 entry = mlx5_list_register(tbl_data->matchers, &ctx);
17307 "Failed to register meter drop matcher.");
17310 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
17311 container_of(entry, struct mlx5_flow_dv_matcher,
17315 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
17316 /* Create drop rule, matching meter_id only. */
17317 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
17318 (enum modify_reg)mtr_id_reg_c,
17319 (mtr_idx << mtr_id_offset), UINT32_MAX);
17321 cnt = flow_dv_counter_get_by_idx(dev,
17322 fm->drop_cnt, NULL);
17323 actions[i++] = cnt->action;
17324 actions[i++] = priv->sh->dr_drop_action;
17325 misc_mask = flow_dv_matcher_enable(value.buf);
17326 __flow_dv_adjust_buf_size(&value.size, misc_mask);
17327 ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
17328 (void *)&value, i, actions,
17329 &fm->drop_rule[domain]);
17331 DRV_LOG(ERR, "Failed to create meter "
17332 "drop rule for drop table.");
17338 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17339 if (fm->drop_rule[i]) {
17340 claim_zero(mlx5_flow_os_destroy_flow
17341 (fm->drop_rule[i]));
17342 fm->drop_rule[i] = NULL;
17348 static struct mlx5_flow_meter_sub_policy *
17349 __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
17350 struct mlx5_flow_meter_policy *mtr_policy,
17351 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
17352 struct mlx5_flow_meter_sub_policy *next_sub_policy,
17355 struct mlx5_priv *priv = dev->data->dev_private;
17356 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
17357 uint32_t sub_policy_idx = 0;
17358 uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
17360 struct mlx5_hrxq *hrxq;
17361 struct mlx5_flow_handle dh;
17362 struct mlx5_meter_policy_action_container *act_cnt;
17363 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
17364 uint16_t sub_policy_num;
17365 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
17368 rte_spinlock_lock(&mtr_policy->sl);
17369 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17372 hrxq = mlx5_hrxq_get(dev, rss_desc[i]);
17374 rte_spinlock_unlock(&mtr_policy->sl);
17377 hrxq_idx[i] = hrxq->idx;
17379 sub_policy_num = (mtr_policy->sub_policy_num >>
17380 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17381 MLX5_MTR_SUB_POLICY_NUM_MASK;
17382 for (j = 0; j < sub_policy_num; j++) {
17383 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17386 mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
17389 if (i >= MLX5_MTR_RTE_COLORS) {
17391 * Found the sub policy table with
17392 * the same queue per color.
17394 rte_spinlock_unlock(&mtr_policy->sl);
17395 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
17396 mlx5_hrxq_release(dev, hrxq_idx[i]);
17398 return mtr_policy->sub_policys[domain][j];
17401 /* Create sub policy. */
17402 if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_GREEN] &&
17403 !mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_YELLOW]) {
17404 /* Reuse the first pre-allocated sub_policy. */
17405 sub_policy = mtr_policy->sub_policys[domain][0];
17406 sub_policy_idx = sub_policy->idx;
17408 sub_policy = mlx5_ipool_zmalloc
17409 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17412 sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
17413 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
17414 mlx5_hrxq_release(dev, hrxq_idx[i]);
17415 goto rss_sub_policy_error;
17417 sub_policy->idx = sub_policy_idx;
17418 sub_policy->main_policy = mtr_policy;
17420 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17423 sub_policy->rix_hrxq[i] = hrxq_idx[i];
17424 if (mtr_policy->is_hierarchy) {
17425 act_cnt = &mtr_policy->act_cnt[i];
17426 act_cnt->next_sub_policy = next_sub_policy;
17427 mlx5_hrxq_release(dev, hrxq_idx[i]);
17430 * Overwrite the last action from
17431 * RSS action to Queue action.
17433 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
17436 DRV_LOG(ERR, "Failed to get policy hrxq");
17437 goto rss_sub_policy_error;
17439 act_cnt = &mtr_policy->act_cnt[i];
17440 if (act_cnt->rix_mark || act_cnt->modify_hdr) {
17441 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
17442 if (act_cnt->rix_mark)
17444 dh.fate_action = MLX5_FLOW_FATE_QUEUE;
17445 dh.rix_hrxq = hrxq_idx[i];
17446 flow_drv_rxq_flags_set(dev, &dh);
17450 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
17451 sub_policy, domain)) {
17452 DRV_LOG(ERR, "Failed to create policy "
17453 "rules for ingress domain.");
17454 goto rss_sub_policy_error;
17456 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
17457 i = (mtr_policy->sub_policy_num >>
17458 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17459 MLX5_MTR_SUB_POLICY_NUM_MASK;
17460 if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
17461 DRV_LOG(ERR, "No free sub-policy slot.");
17462 goto rss_sub_policy_error;
17464 mtr_policy->sub_policys[domain][i] = sub_policy;
17466 mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17467 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
17468 mtr_policy->sub_policy_num |=
17469 (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17470 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
17472 rte_spinlock_unlock(&mtr_policy->sl);
17475 rss_sub_policy_error:
17477 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
17478 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
17479 i = (mtr_policy->sub_policy_num >>
17480 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17481 MLX5_MTR_SUB_POLICY_NUM_MASK;
17482 mtr_policy->sub_policys[domain][i] = NULL;
17483 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17487 rte_spinlock_unlock(&mtr_policy->sl);
17492 * Find the policy table for prefix table with RSS.
17495 * Pointer to Ethernet device.
17496 * @param[in] mtr_policy
17497 * Pointer to meter policy table.
17498 * @param[in] rss_desc
17499 * Pointer to rss_desc
17501 * Pointer to table set on success, NULL otherwise and rte_errno is set.
17503 static struct mlx5_flow_meter_sub_policy *
17504 flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
17505 struct mlx5_flow_meter_policy *mtr_policy,
17506 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
17508 struct mlx5_priv *priv = dev->data->dev_private;
17509 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
17510 struct mlx5_flow_meter_info *next_fm;
17511 struct mlx5_flow_meter_policy *next_policy;
17512 struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
17513 struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
17514 struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
17515 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
17516 bool reuse_sub_policy;
17521 /* Iterate hierarchy to get all policies in this hierarchy. */
17522 policies[i++] = mtr_policy;
17523 if (!mtr_policy->is_hierarchy)
17525 if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
17526 DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
17529 rte_spinlock_lock(&mtr_policy->sl);
17530 next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
17531 rte_spinlock_unlock(&mtr_policy->sl);
17533 DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
17537 mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
17539 MLX5_ASSERT(next_policy);
17540 mtr_policy = next_policy;
17544 * From last policy to the first one in hierarchy,
17545 * create / get the sub policy for each of them.
17547 sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
17551 &reuse_sub_policy);
17553 DRV_LOG(ERR, "Failed to get the sub policy.");
17556 if (!reuse_sub_policy)
17557 sub_policies[j++] = sub_policy;
17558 next_sub_policy = sub_policy;
17563 uint16_t sub_policy_num;
17565 sub_policy = sub_policies[--j];
17566 mtr_policy = sub_policy->main_policy;
17567 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
17568 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
17569 sub_policy_num = (mtr_policy->sub_policy_num >>
17570 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17571 MLX5_MTR_SUB_POLICY_NUM_MASK;
17572 mtr_policy->sub_policys[domain][sub_policy_num - 1] =
17575 mtr_policy->sub_policy_num &=
17576 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17577 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
17578 mtr_policy->sub_policy_num |=
17579 (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17580 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
17581 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17589 * Check if need to create hierarchy tag rule.
17592 * Pointer to mlx5_priv.
17593 * @param[in] mtr_policy
17594 * Pointer to current meter policy.
17595 * @param[in] src_port
17596 * The src port this extra rule should use.
17597 * @param[out] next_fm
17598 * Pointer to next meter in hierarchy.
17600 * Indicate if skip the tag rule creation.
17601 * @param[out] error
17602 * Perform verbose error reporting if not NULL.
17604 * 0 on success, a negative errno value otherwise and rte_errno is set.
17607 mlx5_meter_hierarchy_skip_tag_rule(struct mlx5_priv *priv,
17608 struct mlx5_flow_meter_policy *mtr_policy,
17610 struct mlx5_flow_meter_info **next_fm,
17612 struct rte_flow_error *error)
17614 struct mlx5_flow_meter_sub_policy *sub_policy;
17615 struct mlx5_sub_policy_color_rule *color_rule;
17616 uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
17622 rte_spinlock_lock(&mtr_policy->sl);
17623 if (!mtr_policy->is_hierarchy)
17625 *next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
17627 ret = rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
17628 NULL, "Failed to find next meter in hierarchy.");
17631 if (!(*next_fm)->drop_cnt) {
17635 sub_policy = mtr_policy->sub_policys[domain][0];
17636 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17637 if (mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_MTR)
17639 TAILQ_FOREACH(color_rule, &sub_policy->color_rules[i], next_port)
17640 if (color_rule->src_port == src_port) {
17646 rte_spinlock_unlock(&mtr_policy->sl);
17651 * Create the sub policy tag rule for all meters in hierarchy.
17654 * Pointer to Ethernet device.
17656 * Meter information table.
17657 * @param[in] src_port
17658 * The src port this extra rule should use.
17660 * The src port match item.
17661 * @param[out] error
17662 * Perform verbose error reporting if not NULL.
17664 * 0 on success, a negative errno value otherwise and rte_errno is set.
17667 flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
17668 struct mlx5_flow_meter_info *fm,
17670 const struct rte_flow_item *item,
17671 struct rte_flow_error *error)
17673 struct mlx5_priv *priv = dev->data->dev_private;
17674 struct mlx5_flow_meter_policy *mtr_policy;
17675 struct mlx5_flow_meter_sub_policy *sub_policy;
17676 struct mlx5_flow_meter_info *next_fm = NULL;
17677 struct mlx5_flow_meter_policy *next_policy;
17678 struct mlx5_flow_meter_sub_policy *next_sub_policy;
17679 struct mlx5_flow_tbl_data_entry *tbl_data;
17680 struct mlx5_sub_policy_color_rule *color_rule;
17681 struct mlx5_meter_policy_acts acts;
17682 uint32_t color_reg_c_idx;
17683 bool mtr_first = (src_port != UINT16_MAX) ? true : false;
17684 struct rte_flow_attr attr = {
17685 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
17692 uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
17694 struct mlx5_flow_meter_policy *fm_policy;
17695 struct mlx5_flow_meter_info *next_fm;
17696 struct mlx5_sub_policy_color_rule *tag_rule[MLX5_MTR_RTE_COLORS];
17697 } fm_info[MLX5_MTR_CHAIN_MAX_NUM] = { {0} };
17698 uint32_t fm_cnt = 0;
17701 color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
17702 /* Get all fms who need to create the tag color rule. */
17706 mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
17707 MLX5_ASSERT(mtr_policy);
17708 if (mlx5_meter_hierarchy_skip_tag_rule(priv, mtr_policy, src_port,
17709 &next_fm, &skip, error))
17711 if (next_fm && !skip) {
17712 fm_info[fm_cnt].fm_policy = mtr_policy;
17713 fm_info[fm_cnt].next_fm = next_fm;
17714 if (++fm_cnt >= MLX5_MTR_CHAIN_MAX_NUM) {
17715 rte_flow_error_set(error, errno,
17716 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17717 "Exceed max meter number in hierarchy.");
17723 /* Create tag color rules for all needed fms. */
17724 for (i = 0; i < fm_cnt; i++) {
17727 mtr_policy = fm_info[i].fm_policy;
17728 rte_spinlock_lock(&mtr_policy->sl);
17729 sub_policy = mtr_policy->sub_policys[domain][0];
17730 for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) {
17731 if (mtr_policy->act_cnt[j].fate_action != MLX5_FLOW_FATE_MTR)
17733 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
17734 sizeof(struct mlx5_sub_policy_color_rule),
17737 rte_spinlock_unlock(&mtr_policy->sl);
17738 rte_flow_error_set(error, ENOMEM,
17739 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17740 "No memory to create tag color rule.");
17743 color_rule->src_port = src_port;
17744 next_fm = fm_info[i].next_fm;
17745 if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
17746 mlx5_free(color_rule);
17747 rte_spinlock_unlock(&mtr_policy->sl);
17750 fm_info[i].tag_rule[j] = color_rule;
17751 TAILQ_INSERT_TAIL(&sub_policy->color_rules[j], color_rule, next_port);
17752 /* Prepare to create color rule. */
17753 mtr_action = (next_fm->color_aware && j == RTE_COLOR_YELLOW) ?
17754 next_fm->meter_action_y :
17755 next_fm->meter_action_g;
17756 next_policy = mlx5_flow_meter_policy_find(dev, next_fm->policy_id, NULL);
17757 MLX5_ASSERT(next_policy);
17758 next_sub_policy = next_policy->sub_policys[domain][0];
17759 tbl_data = container_of(next_sub_policy->tbl_rsc,
17760 struct mlx5_flow_tbl_data_entry, tbl);
17762 acts.dv_actions[0] = mtr_action;
17763 acts.dv_actions[1] = mtr_policy->act_cnt[j].modify_hdr->action;
17765 acts.dv_actions[0] = mtr_policy->act_cnt[j].modify_hdr->action;
17766 acts.dv_actions[1] = mtr_action;
17768 acts.dv_actions[2] = tbl_data->jump.action;
17769 acts.actions_n = 3;
17770 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
17771 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
17772 &attr, true, item, &color_rule->matcher, error)) {
17773 rte_spinlock_unlock(&mtr_policy->sl);
17774 rte_flow_error_set(error, errno,
17775 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17776 "Failed to create hierarchy meter matcher.");
17779 if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, (enum rte_color)j,
17780 color_rule->matcher->matcher_object,
17781 acts.actions_n, acts.dv_actions,
17782 true, item, &color_rule->rule, &attr)) {
17783 rte_spinlock_unlock(&mtr_policy->sl);
17784 rte_flow_error_set(error, errno,
17785 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17786 "Failed to create hierarchy meter rule.");
17790 rte_spinlock_unlock(&mtr_policy->sl);
17794 for (i = 0; i < fm_cnt; i++) {
17795 mtr_policy = fm_info[i].fm_policy;
17796 rte_spinlock_lock(&mtr_policy->sl);
17797 sub_policy = mtr_policy->sub_policys[domain][0];
17798 for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) {
17799 color_rule = fm_info[i].tag_rule[j];
17802 if (color_rule->rule)
17803 mlx5_flow_os_destroy_flow(color_rule->rule);
17804 if (color_rule->matcher) {
17805 struct mlx5_flow_tbl_data_entry *tbl =
17806 container_of(color_rule->matcher->tbl, typeof(*tbl), tbl);
17807 mlx5_list_unregister(tbl->matchers, &color_rule->matcher->entry);
17809 if (fm_info[i].next_fm)
17810 mlx5_flow_meter_detach(priv, fm_info[i].next_fm);
17811 TAILQ_REMOVE(&sub_policy->color_rules[j], color_rule, next_port);
17812 mlx5_free(color_rule);
17814 rte_spinlock_unlock(&mtr_policy->sl);
17820 * Destroy the sub policy table with RX queue.
17823 * Pointer to Ethernet device.
17824 * @param[in] mtr_policy
17825 * Pointer to meter policy table.
17828 flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
17829 struct mlx5_flow_meter_policy *mtr_policy)
17831 struct mlx5_priv *priv = dev->data->dev_private;
17832 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
17833 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
17835 uint16_t sub_policy_num, new_policy_num;
17837 rte_spinlock_lock(&mtr_policy->sl);
17838 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17839 switch (mtr_policy->act_cnt[i].fate_action) {
17840 case MLX5_FLOW_FATE_SHARED_RSS:
17841 sub_policy_num = (mtr_policy->sub_policy_num >>
17842 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17843 MLX5_MTR_SUB_POLICY_NUM_MASK;
17844 new_policy_num = sub_policy_num;
17845 for (j = 0; j < sub_policy_num; j++) {
17847 mtr_policy->sub_policys[domain][j];
17849 __flow_dv_destroy_sub_policy_rules(dev,
17852 mtr_policy->sub_policys[domain][0]) {
17853 mtr_policy->sub_policys[domain][j] =
17856 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17862 if (new_policy_num != sub_policy_num) {
17863 mtr_policy->sub_policy_num &=
17864 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17865 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
17866 mtr_policy->sub_policy_num |=
17868 MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17869 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
17872 case MLX5_FLOW_FATE_QUEUE:
17873 sub_policy = mtr_policy->sub_policys[domain][0];
17874 __flow_dv_destroy_sub_policy_rules(dev,
17878 /*Other actions without queue and do nothing*/
17882 rte_spinlock_unlock(&mtr_policy->sl);
17885 * Check whether the DR drop action is supported on the root table or not.
17887 * Create a simple flow with DR drop action on root table to validate
17888 * if DR drop action on root table is supported or not.
17891 * Pointer to rte_eth_dev structure.
17894 * 0 on success, a negative errno value otherwise and rte_errno is set.
17897 mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
17899 struct mlx5_priv *priv = dev->data->dev_private;
17900 struct mlx5_dev_ctx_shared *sh = priv->sh;
17901 struct mlx5_flow_dv_match_params mask = {
17902 .size = sizeof(mask.buf),
17904 struct mlx5_flow_dv_match_params value = {
17905 .size = sizeof(value.buf),
17907 struct mlx5dv_flow_matcher_attr dv_attr = {
17908 .type = IBV_FLOW_ATTR_NORMAL,
17910 .match_criteria_enable = 0,
17911 .match_mask = (void *)&mask,
17913 struct mlx5_flow_tbl_resource *tbl = NULL;
17914 void *matcher = NULL;
17918 tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
17922 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
17923 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
17924 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
17925 tbl->obj, &matcher);
17928 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
17929 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
17930 &sh->dr_drop_action, &flow);
17933 * If DR drop action is not supported on root table, flow create will
17934 * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
17938 (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
17939 DRV_LOG(INFO, "DR drop action is not supported in root table.");
17941 DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
17944 claim_zero(mlx5_flow_os_destroy_flow(flow));
17947 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
17949 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
17954 * Validate the batch counter support in root table.
17956 * Create a simple flow with invalid counter and drop action on root table to
17957 * validate if batch counter with offset on root table is supported or not.
17960 * Pointer to rte_eth_dev structure.
17963 * 0 on success, a negative errno value otherwise and rte_errno is set.
17966 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
17968 struct mlx5_priv *priv = dev->data->dev_private;
17969 struct mlx5_dev_ctx_shared *sh = priv->sh;
17970 struct mlx5_flow_dv_match_params mask = {
17971 .size = sizeof(mask.buf),
17973 struct mlx5_flow_dv_match_params value = {
17974 .size = sizeof(value.buf),
17976 struct mlx5dv_flow_matcher_attr dv_attr = {
17977 .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
17979 .match_criteria_enable = 0,
17980 .match_mask = (void *)&mask,
17982 void *actions[2] = { 0 };
17983 struct mlx5_flow_tbl_resource *tbl = NULL;
17984 struct mlx5_devx_obj *dcs = NULL;
17985 void *matcher = NULL;
17989 tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
17993 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
17996 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
18000 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
18001 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
18002 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
18003 tbl->obj, &matcher);
18006 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
18007 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
18011 * If batch counter with offset is not supported, the driver will not
18012 * validate the invalid offset value, flow create should success.
18013 * In this case, it means batch counter is not supported in root table.
18015 * Otherwise, if flow create is failed, counter offset is supported.
18018 DRV_LOG(INFO, "Batch counter is not supported in root "
18019 "table. Switch to fallback mode.");
18020 rte_errno = ENOTSUP;
18022 claim_zero(mlx5_flow_os_destroy_flow(flow));
18024 /* Check matcher to make sure validate fail at flow create. */
18025 if (!matcher || (matcher && errno != EINVAL))
18026 DRV_LOG(ERR, "Unexpected error in counter offset "
18027 "support detection");
18031 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
18033 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
18035 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
18037 claim_zero(mlx5_devx_cmd_destroy(dcs));
18042 * Query a devx counter.
18045 * Pointer to the Ethernet device structure.
18047 * Index to the flow counter.
18049 * Set to clear the counter statistics.
18051 * The statistics value of packets.
18052 * @param[out] bytes
18053 * The statistics value of bytes.
18056 * 0 on success, otherwise return -1.
18059 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
18060 uint64_t *pkts, uint64_t *bytes, void **action)
18062 struct mlx5_priv *priv = dev->data->dev_private;
18063 struct mlx5_flow_counter *cnt;
18064 uint64_t inn_pkts, inn_bytes;
18067 if (!priv->sh->cdev->config.devx)
18070 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
18073 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
18075 *action = cnt->action;
18077 *pkts = inn_pkts - cnt->hits;
18078 *bytes = inn_bytes - cnt->bytes;
18080 cnt->hits = inn_pkts;
18081 cnt->bytes = inn_bytes;
18087 * Get aged-out flows.
18090 * Pointer to the Ethernet device structure.
18091 * @param[in] context
18092 * The address of an array of pointers to the aged-out flows contexts.
18093 * @param[in] nb_contexts
18094 * The length of context array pointers.
18095 * @param[out] error
18096 * Perform verbose error reporting if not NULL. Initialized in case of
18100 * how many contexts get in success, otherwise negative errno value.
18101 * if nb_contexts is 0, return the amount of all aged contexts.
18102 * if nb_contexts is not 0 , return the amount of aged flows reported
18103 * in the context array.
18104 * @note: only stub for now
18107 flow_dv_get_aged_flows(struct rte_eth_dev *dev,
18109 uint32_t nb_contexts,
18110 struct rte_flow_error *error)
18112 struct mlx5_priv *priv = dev->data->dev_private;
18113 struct mlx5_age_info *age_info;
18114 struct mlx5_age_param *age_param;
18115 struct mlx5_flow_counter *counter;
18116 struct mlx5_aso_age_action *act;
18119 if (nb_contexts && !context)
18120 return rte_flow_error_set(error, EINVAL,
18121 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18122 NULL, "empty context");
18123 age_info = GET_PORT_AGE_INFO(priv);
18124 rte_spinlock_lock(&age_info->aged_sl);
18125 LIST_FOREACH(act, &age_info->aged_aso, next) {
18128 context[nb_flows - 1] =
18129 act->age_params.context;
18130 if (!(--nb_contexts))
18134 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
18137 age_param = MLX5_CNT_TO_AGE(counter);
18138 context[nb_flows - 1] = age_param->context;
18139 if (!(--nb_contexts))
18143 rte_spinlock_unlock(&age_info->aged_sl);
18144 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
18149 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
18152 flow_dv_counter_allocate(struct rte_eth_dev *dev)
18154 return flow_dv_counter_alloc(dev, 0);
18158 * Validate indirect action.
18159 * Dispatcher for action type specific validation.
18162 * Pointer to the Ethernet device structure.
18164 * Indirect action configuration.
18165 * @param[in] action
18166 * The indirect action object to validate.
18167 * @param[out] error
18168 * Perform verbose error reporting if not NULL. Initialized in case of
18172 * 0 on success, otherwise negative errno value.
18175 flow_dv_action_validate(struct rte_eth_dev *dev,
18176 const struct rte_flow_indir_action_conf *conf,
18177 const struct rte_flow_action *action,
18178 struct rte_flow_error *err)
18180 struct mlx5_priv *priv = dev->data->dev_private;
18182 RTE_SET_USED(conf);
18183 switch (action->type) {
18184 case RTE_FLOW_ACTION_TYPE_RSS:
18186 * priv->obj_ops is set according to driver capabilities.
18187 * When DevX capabilities are
18188 * sufficient, it is set to devx_obj_ops.
18189 * Otherwise, it is set to ibv_obj_ops.
18190 * ibv_obj_ops doesn't support ind_table_modify operation.
18191 * In this case the indirect RSS action can't be used.
18193 if (priv->obj_ops.ind_table_modify == NULL)
18194 return rte_flow_error_set
18196 RTE_FLOW_ERROR_TYPE_ACTION,
18198 "Indirect RSS action not supported");
18199 return mlx5_validate_action_rss(dev, action, err);
18200 case RTE_FLOW_ACTION_TYPE_AGE:
18201 if (!priv->sh->aso_age_mng)
18202 return rte_flow_error_set(err, ENOTSUP,
18203 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18205 "Indirect age action not supported");
18206 return flow_dv_validate_action_age(0, action, dev, err);
18207 case RTE_FLOW_ACTION_TYPE_COUNT:
18208 return flow_dv_validate_action_count(dev, true, 0, NULL, err);
18209 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
18210 if (!priv->sh->ct_aso_en)
18211 return rte_flow_error_set(err, ENOTSUP,
18212 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
18213 "ASO CT is not supported");
18214 return mlx5_validate_action_ct(dev, action->conf, err);
18216 return rte_flow_error_set(err, ENOTSUP,
18217 RTE_FLOW_ERROR_TYPE_ACTION,
18219 "action type not supported");
18224 * Check if the RSS configurations for colors of a meter policy match
18225 * each other, except the queues.
18228 * Pointer to the first RSS flow action.
18230 * Pointer to the second RSS flow action.
18233 * 0 on match, 1 on conflict.
18236 flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
18237 const struct rte_flow_action_rss *r2)
18239 if (r1 == NULL || r2 == NULL)
18241 if (!(r1->level <= 1 && r2->level <= 1) &&
18242 !(r1->level > 1 && r2->level > 1))
18244 if (r1->types != r2->types &&
18245 !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
18246 (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
18248 if (r1->key || r2->key) {
18249 const void *key1 = r1->key ? r1->key : rss_hash_default_key;
18250 const void *key2 = r2->key ? r2->key : rss_hash_default_key;
18252 if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
18259 * Validate the meter hierarchy chain for meter policy.
18262 * Pointer to the Ethernet device structure.
18263 * @param[in] meter_id
18265 * @param[in] action_flags
18266 * Holds the actions detected until now.
18267 * @param[out] is_rss
18269 * @param[out] hierarchy_domain
18270 * The domain bitmap for hierarchy policy.
18271 * @param[out] error
18272 * Perform verbose error reporting if not NULL. Initialized in case of
18276 * 0 on success, otherwise negative errno value with error set.
18279 flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
18281 uint64_t action_flags,
18283 uint8_t *hierarchy_domain,
18284 struct rte_mtr_error *error)
18286 struct mlx5_priv *priv = dev->data->dev_private;
18287 struct mlx5_flow_meter_info *fm;
18288 struct mlx5_flow_meter_policy *policy;
18291 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
18292 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
18293 return -rte_mtr_error_set(error, EINVAL,
18294 RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
18296 "Multiple fate actions not supported.");
18297 *hierarchy_domain = 0;
18298 fm = mlx5_flow_meter_find(priv, meter_id, NULL);
18301 return -rte_mtr_error_set(error, EINVAL,
18302 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
18303 "Meter not found in meter hierarchy.");
18304 if (fm->def_policy)
18305 return -rte_mtr_error_set(error, EINVAL,
18306 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
18307 "Non termination meter not supported in hierarchy.");
18309 return -rte_mtr_error_set(error, EINVAL,
18310 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
18311 "Only shared meter supported in hierarchy.");
18312 policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
18313 MLX5_ASSERT(policy);
18315 * Only inherit the supported domains of the first meter in
18317 * One meter supports at least one domain.
18319 if (!*hierarchy_domain) {
18320 if (policy->transfer)
18321 *hierarchy_domain |=
18322 MLX5_MTR_DOMAIN_TRANSFER_BIT;
18323 if (policy->ingress)
18324 *hierarchy_domain |=
18325 MLX5_MTR_DOMAIN_INGRESS_BIT;
18326 if (policy->egress)
18327 *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
18329 if (!policy->is_hierarchy) {
18330 *is_rss = policy->is_rss;
18333 rte_spinlock_lock(&policy->sl);
18334 fm = mlx5_flow_meter_hierarchy_next_meter(priv, policy, NULL);
18335 rte_spinlock_unlock(&policy->sl);
18336 if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
18337 return -rte_mtr_error_set(error, EINVAL,
18338 RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
18339 "Exceed max hierarchy meter number.");
18345 * Validate meter policy actions.
18346 * Dispatcher for action type specific validation.
18349 * Pointer to the Ethernet device structure.
18350 * @param[in] action
18351 * The meter policy action object to validate.
18353 * Attributes of flow to determine steering domain.
18354 * @param[out] error
18355 * Perform verbose error reporting if not NULL. Initialized in case of
18359 * 0 on success, otherwise negative errno value.
18362 flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
18363 const struct rte_flow_action *actions[RTE_COLORS],
18364 struct rte_flow_attr *attr,
18366 uint8_t *domain_bitmap,
18367 uint8_t *policy_mode,
18368 struct rte_mtr_error *error)
18370 struct mlx5_priv *priv = dev->data->dev_private;
18371 struct mlx5_sh_config *dev_conf = &priv->sh->config;
18372 const struct rte_flow_action *act;
18373 uint64_t action_flags[RTE_COLORS] = {0};
18376 struct rte_flow_error flow_err;
18377 uint8_t domain_color[RTE_COLORS] = {0};
18378 uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
18379 uint8_t hierarchy_domain = 0;
18380 const struct rte_flow_action_meter *mtr;
18381 const struct rte_flow_action_meter *next_mtr = NULL;
18382 bool def_green = false;
18383 bool def_yellow = false;
18384 const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
18386 if (!dev_conf->dv_esw_en)
18387 def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
18388 *domain_bitmap = def_domain;
18389 /* Red color could only support DROP action. */
18390 if (!actions[RTE_COLOR_RED] ||
18391 actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
18392 return -rte_mtr_error_set(error, ENOTSUP,
18393 RTE_MTR_ERROR_TYPE_METER_POLICY,
18394 NULL, "Red color only supports drop action.");
18396 * Check default policy actions:
18397 * Green / Yellow: no action, Red: drop action
18398 * Either G or Y will trigger default policy actions to be created.
18400 if (!actions[RTE_COLOR_GREEN] ||
18401 actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
18403 if (!actions[RTE_COLOR_YELLOW] ||
18404 actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
18406 if (def_green && def_yellow) {
18407 *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
18409 } else if (!def_green && def_yellow) {
18410 *policy_mode = MLX5_MTR_POLICY_MODE_OG;
18411 } else if (def_green && !def_yellow) {
18412 *policy_mode = MLX5_MTR_POLICY_MODE_OY;
18414 *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
18416 /* Set to empty string in case of NULL pointer access by user. */
18417 flow_err.message = "";
18418 for (i = 0; i < RTE_COLORS; i++) {
18420 for (action_flags[i] = 0, actions_n = 0;
18421 act && act->type != RTE_FLOW_ACTION_TYPE_END;
18423 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
18424 return -rte_mtr_error_set(error, ENOTSUP,
18425 RTE_MTR_ERROR_TYPE_METER_POLICY,
18426 NULL, "too many actions");
18427 switch (act->type) {
18428 case RTE_FLOW_ACTION_TYPE_PORT_ID:
18429 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
18430 if (!dev_conf->dv_esw_en)
18431 return -rte_mtr_error_set(error,
18433 RTE_MTR_ERROR_TYPE_METER_POLICY,
18434 NULL, "PORT action validate check"
18435 " fail for ESW disable");
18436 ret = flow_dv_validate_action_port_id(dev,
18438 act, attr, &flow_err);
18440 return -rte_mtr_error_set(error,
18442 RTE_MTR_ERROR_TYPE_METER_POLICY,
18443 NULL, flow_err.message ?
18445 "PORT action validate check fail");
18447 action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
18449 case RTE_FLOW_ACTION_TYPE_MARK:
18450 ret = flow_dv_validate_action_mark(dev, act,
18454 return -rte_mtr_error_set(error,
18456 RTE_MTR_ERROR_TYPE_METER_POLICY,
18457 NULL, flow_err.message ?
18459 "Mark action validate check fail");
18460 if (dev_conf->dv_xmeta_en !=
18461 MLX5_XMETA_MODE_LEGACY)
18462 return -rte_mtr_error_set(error,
18464 RTE_MTR_ERROR_TYPE_METER_POLICY,
18465 NULL, "Extend MARK action is "
18466 "not supported. Please try use "
18467 "default policy for meter.");
18468 action_flags[i] |= MLX5_FLOW_ACTION_MARK;
18471 case RTE_FLOW_ACTION_TYPE_SET_TAG:
18472 ret = flow_dv_validate_action_set_tag(dev,
18473 act, action_flags[i],
18476 return -rte_mtr_error_set(error,
18478 RTE_MTR_ERROR_TYPE_METER_POLICY,
18479 NULL, flow_err.message ?
18481 "Set tag action validate check fail");
18482 action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
18485 case RTE_FLOW_ACTION_TYPE_DROP:
18486 ret = mlx5_flow_validate_action_drop
18487 (action_flags[i], attr, &flow_err);
18489 return -rte_mtr_error_set(error,
18491 RTE_MTR_ERROR_TYPE_METER_POLICY,
18492 NULL, flow_err.message ?
18494 "Drop action validate check fail");
18495 action_flags[i] |= MLX5_FLOW_ACTION_DROP;
18498 case RTE_FLOW_ACTION_TYPE_QUEUE:
18500 * Check whether extensive
18501 * metadata feature is engaged.
18503 if (dev_conf->dv_flow_en &&
18504 (dev_conf->dv_xmeta_en !=
18505 MLX5_XMETA_MODE_LEGACY) &&
18506 mlx5_flow_ext_mreg_supported(dev))
18507 return -rte_mtr_error_set(error,
18509 RTE_MTR_ERROR_TYPE_METER_POLICY,
18510 NULL, "Queue action with meta "
18511 "is not supported. Please try use "
18512 "default policy for meter.");
18513 ret = mlx5_flow_validate_action_queue(act,
18514 action_flags[i], dev,
18517 return -rte_mtr_error_set(error,
18519 RTE_MTR_ERROR_TYPE_METER_POLICY,
18520 NULL, flow_err.message ?
18522 "Queue action validate check fail");
18523 action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
18526 case RTE_FLOW_ACTION_TYPE_RSS:
18527 if (dev_conf->dv_flow_en &&
18528 (dev_conf->dv_xmeta_en !=
18529 MLX5_XMETA_MODE_LEGACY) &&
18530 mlx5_flow_ext_mreg_supported(dev))
18531 return -rte_mtr_error_set(error,
18533 RTE_MTR_ERROR_TYPE_METER_POLICY,
18534 NULL, "RSS action with meta "
18535 "is not supported. Please try use "
18536 "default policy for meter.");
18537 ret = mlx5_validate_action_rss(dev, act,
18540 return -rte_mtr_error_set(error,
18542 RTE_MTR_ERROR_TYPE_METER_POLICY,
18543 NULL, flow_err.message ?
18545 "RSS action validate check fail");
18546 action_flags[i] |= MLX5_FLOW_ACTION_RSS;
18548 /* Either G or Y will set the RSS. */
18549 rss_color[i] = act->conf;
18551 case RTE_FLOW_ACTION_TYPE_JUMP:
18552 ret = flow_dv_validate_action_jump(dev,
18553 NULL, act, action_flags[i],
18554 attr, true, &flow_err);
18556 return -rte_mtr_error_set(error,
18558 RTE_MTR_ERROR_TYPE_METER_POLICY,
18559 NULL, flow_err.message ?
18561 "Jump action validate check fail");
18563 action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
18565 case RTE_FLOW_ACTION_TYPE_METER:
18567 if (next_mtr && next_mtr->mtr_id != mtr->mtr_id)
18568 return -rte_mtr_error_set(error, ENOTSUP,
18569 RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
18570 "Green and Yellow must use the same meter.");
18571 ret = flow_dv_validate_policy_mtr_hierarchy(dev,
18581 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
18584 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
18585 ret = flow_dv_validate_action_modify_field(dev,
18586 action_flags[i], act, attr, &flow_err);
18588 return -rte_mtr_error_set(error,
18590 RTE_MTR_ERROR_TYPE_METER_POLICY,
18591 NULL, flow_err.message ?
18593 "Modify field action validate check fail");
18595 action_flags[i] |= MLX5_FLOW_ACTION_MODIFY_FIELD;
18598 return -rte_mtr_error_set(error, ENOTSUP,
18599 RTE_MTR_ERROR_TYPE_METER_POLICY,
18601 "Doesn't support optional action");
18604 if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
18605 domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
18606 } else if ((action_flags[i] &
18607 (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
18608 (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
18610 * Only support MLX5_XMETA_MODE_LEGACY
18611 * so MARK action is only in ingress domain.
18613 domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
18615 domain_color[i] = def_domain;
18616 if (action_flags[i] &&
18617 !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
18619 ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
18621 if (action_flags[i] &
18622 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
18623 domain_color[i] &= hierarchy_domain;
18625 * Non-termination actions only support NIC Tx domain.
18626 * The adjustion should be skipped when there is no
18627 * action or only END is provided. The default domains
18628 * bit-mask is set to find the MIN intersection.
18629 * The action flags checking should also be skipped.
18631 if ((def_green && i == RTE_COLOR_GREEN) ||
18632 (def_yellow && i == RTE_COLOR_YELLOW))
18635 * Validate the drop action mutual exclusion
18636 * with other actions. Drop action is mutually-exclusive
18637 * with any other action, except for Count action.
18639 if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
18640 (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
18641 return -rte_mtr_error_set(error, ENOTSUP,
18642 RTE_MTR_ERROR_TYPE_METER_POLICY,
18643 NULL, "Drop action is mutually-exclusive "
18644 "with any other action");
18646 /* Eswitch has few restrictions on using items and actions */
18647 if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
18648 if (!mlx5_flow_ext_mreg_supported(dev) &&
18649 action_flags[i] & MLX5_FLOW_ACTION_MARK)
18650 return -rte_mtr_error_set(error, ENOTSUP,
18651 RTE_MTR_ERROR_TYPE_METER_POLICY,
18652 NULL, "unsupported action MARK");
18653 if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
18654 return -rte_mtr_error_set(error, ENOTSUP,
18655 RTE_MTR_ERROR_TYPE_METER_POLICY,
18656 NULL, "unsupported action QUEUE");
18657 if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
18658 return -rte_mtr_error_set(error, ENOTSUP,
18659 RTE_MTR_ERROR_TYPE_METER_POLICY,
18660 NULL, "unsupported action RSS");
18661 if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
18662 return -rte_mtr_error_set(error, ENOTSUP,
18663 RTE_MTR_ERROR_TYPE_METER_POLICY,
18664 NULL, "no fate action is found");
18666 if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
18667 (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
18668 if ((domain_color[i] &
18669 MLX5_MTR_DOMAIN_EGRESS_BIT))
18671 MLX5_MTR_DOMAIN_EGRESS_BIT;
18673 return -rte_mtr_error_set(error,
18675 RTE_MTR_ERROR_TYPE_METER_POLICY,
18677 "no fate action is found");
18681 if (next_mtr && *policy_mode == MLX5_MTR_POLICY_MODE_ALL) {
18682 if (!(action_flags[RTE_COLOR_GREEN] & action_flags[RTE_COLOR_YELLOW] &
18683 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY))
18684 return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY,
18686 "Meter hierarchy supports meter action only.");
18688 /* If both colors have RSS, the attributes should be the same. */
18689 if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
18690 rss_color[RTE_COLOR_YELLOW]))
18691 return -rte_mtr_error_set(error, EINVAL,
18692 RTE_MTR_ERROR_TYPE_METER_POLICY,
18693 NULL, "policy RSS attr conflict");
18694 if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
18696 /* "domain_color[C]" is non-zero for each color, default is ALL. */
18697 if (!def_green && !def_yellow &&
18698 domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
18699 !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
18700 !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
18701 return -rte_mtr_error_set(error, EINVAL,
18702 RTE_MTR_ERROR_TYPE_METER_POLICY,
18703 NULL, "policy domains conflict");
18705 * At least one color policy is listed in the actions, the domains
18706 * to be supported should be the intersection.
18708 *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
18709 domain_color[RTE_COLOR_YELLOW];
18714 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
18716 struct mlx5_priv *priv = dev->data->dev_private;
18719 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
18720 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
18725 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
18726 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
18730 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
18731 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
18739 * Discover the number of available flow priorities
18740 * by trying to create a flow with the highest priority value
18741 * for each possible number.
18746 * List of possible number of available priorities.
18747 * @param[in] vprio_n
18748 * Size of @p vprio array.
18750 * On success, number of available flow priorities.
18751 * On failure, a negative errno-style code and rte_errno is set.
18754 flow_dv_discover_priorities(struct rte_eth_dev *dev,
18755 const uint16_t *vprio, int vprio_n)
18757 struct mlx5_priv *priv = dev->data->dev_private;
18758 struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
18759 struct rte_flow_item_eth eth;
18760 struct rte_flow_item item = {
18761 .type = RTE_FLOW_ITEM_TYPE_ETH,
18765 struct mlx5_flow_dv_matcher matcher = {
18767 .size = sizeof(matcher.mask.buf),
18770 union mlx5_flow_tbl_key tbl_key;
18771 struct mlx5_flow flow;
18773 struct rte_flow_error error;
18775 int i, err, ret = -ENOTSUP;
18778 * Prepare a flow with a catch-all pattern and a drop action.
18779 * Use drop queue, because shared drop action may be unavailable.
18781 action = priv->drop_queue.hrxq->action;
18782 if (action == NULL) {
18783 DRV_LOG(ERR, "Priority discovery requires a drop action");
18784 rte_errno = ENOTSUP;
18787 memset(&flow, 0, sizeof(flow));
18788 flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
18789 if (flow.handle == NULL) {
18790 DRV_LOG(ERR, "Cannot create flow handle");
18791 rte_errno = ENOMEM;
18794 flow.ingress = true;
18795 flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
18796 flow.dv.actions[0] = action;
18797 flow.dv.actions_n = 1;
18798 memset(ð, 0, sizeof(eth));
18799 flow_dv_translate_item_eth(matcher.mask.buf, flow.dv.value.buf,
18800 &item, /* inner */ false, /* group */ 0);
18801 matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
18802 for (i = 0; i < vprio_n; i++) {
18803 /* Configure the next proposed maximum priority. */
18804 matcher.priority = vprio[i] - 1;
18805 memset(&tbl_key, 0, sizeof(tbl_key));
18806 err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
18811 /* This action is pure SW and must always succeed. */
18812 DRV_LOG(ERR, "Cannot register matcher");
18816 /* Try to apply the flow to HW. */
18817 misc_mask = flow_dv_matcher_enable(flow.dv.value.buf);
18818 __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
18819 err = mlx5_flow_os_create_flow
18820 (flow.handle->dvh.matcher->matcher_object,
18821 (void *)&flow.dv.value, flow.dv.actions_n,
18822 flow.dv.actions, &flow.handle->drv_flow);
18824 claim_zero(mlx5_flow_os_destroy_flow
18825 (flow.handle->drv_flow));
18826 flow.handle->drv_flow = NULL;
18828 claim_zero(flow_dv_matcher_release(dev, flow.handle));
18833 mlx5_ipool_free(pool, flow.handle_idx);
18834 /* Set rte_errno if no expected priority value matched. */
18840 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
18841 .validate = flow_dv_validate,
18842 .prepare = flow_dv_prepare,
18843 .translate = flow_dv_translate,
18844 .apply = flow_dv_apply,
18845 .remove = flow_dv_remove,
18846 .destroy = flow_dv_destroy,
18847 .query = flow_dv_query,
18848 .create_mtr_tbls = flow_dv_create_mtr_tbls,
18849 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
18850 .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
18851 .create_meter = flow_dv_mtr_alloc,
18852 .free_meter = flow_dv_aso_mtr_release_to_pool,
18853 .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
18854 .create_mtr_acts = flow_dv_create_mtr_policy_acts,
18855 .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
18856 .create_policy_rules = flow_dv_create_policy_rules,
18857 .destroy_policy_rules = flow_dv_destroy_policy_rules,
18858 .create_def_policy = flow_dv_create_def_policy,
18859 .destroy_def_policy = flow_dv_destroy_def_policy,
18860 .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
18861 .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
18862 .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
18863 .counter_alloc = flow_dv_counter_allocate,
18864 .counter_free = flow_dv_counter_free,
18865 .counter_query = flow_dv_counter_query,
18866 .get_aged_flows = flow_dv_get_aged_flows,
18867 .action_validate = flow_dv_action_validate,
18868 .action_create = flow_dv_action_create,
18869 .action_destroy = flow_dv_action_destroy,
18870 .action_update = flow_dv_action_update,
18871 .action_query = flow_dv_action_query,
18872 .sync_domain = flow_dv_sync_domain,
18873 .discover_priorities = flow_dv_discover_priorities,
18874 .item_create = flow_dv_item_create,
18875 .item_release = flow_dv_item_release,
18878 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */