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:
168 case RTE_FLOW_ITEM_TYPE_IPV4:
171 if (item->mask != NULL &&
172 ((const struct rte_flow_item_ipv4 *)
173 item->mask)->hdr.next_proto_id)
175 ((const struct rte_flow_item_ipv4 *)
176 (item->spec))->hdr.next_proto_id &
177 ((const struct rte_flow_item_ipv4 *)
178 (item->mask))->hdr.next_proto_id;
179 if ((next_protocol == IPPROTO_IPIP ||
180 next_protocol == IPPROTO_IPV6) && tunnel_decap)
183 case RTE_FLOW_ITEM_TYPE_IPV6:
186 if (item->mask != NULL &&
187 ((const struct rte_flow_item_ipv6 *)
188 item->mask)->hdr.proto)
190 ((const struct rte_flow_item_ipv6 *)
191 (item->spec))->hdr.proto &
192 ((const struct rte_flow_item_ipv6 *)
193 (item->mask))->hdr.proto;
194 if ((next_protocol == IPPROTO_IPIP ||
195 next_protocol == IPPROTO_IPV6) && tunnel_decap)
198 case RTE_FLOW_ITEM_TYPE_UDP:
202 case RTE_FLOW_ITEM_TYPE_TCP:
214 * Convert rte_mtr_color to mlx5 color.
223 rte_col_2_mlx5_col(enum rte_color rcol)
226 case RTE_COLOR_GREEN:
227 return MLX5_FLOW_COLOR_GREEN;
228 case RTE_COLOR_YELLOW:
229 return MLX5_FLOW_COLOR_YELLOW;
231 return MLX5_FLOW_COLOR_RED;
235 return MLX5_FLOW_COLOR_UNDEFINED;
238 struct field_modify_info {
239 uint32_t size; /* Size of field in protocol header, in bytes. */
240 uint32_t offset; /* Offset of field in protocol header, in bytes. */
241 enum mlx5_modification_field id;
244 struct field_modify_info modify_eth[] = {
245 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
246 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
247 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
248 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
252 struct field_modify_info modify_vlan_out_first_vid[] = {
253 /* Size in bits !!! */
254 {12, 0, MLX5_MODI_OUT_FIRST_VID},
258 struct field_modify_info modify_ipv4[] = {
259 {1, 1, MLX5_MODI_OUT_IP_DSCP},
260 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
261 {4, 12, MLX5_MODI_OUT_SIPV4},
262 {4, 16, MLX5_MODI_OUT_DIPV4},
266 struct field_modify_info modify_ipv6[] = {
267 {1, 0, MLX5_MODI_OUT_IP_DSCP},
268 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
269 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
270 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
271 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
272 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
273 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
274 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
275 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
276 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
280 struct field_modify_info modify_udp[] = {
281 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
282 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
286 struct field_modify_info modify_tcp[] = {
287 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
288 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
289 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
290 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
295 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
296 uint8_t next_protocol, uint64_t *item_flags,
299 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
300 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
301 if (next_protocol == IPPROTO_IPIP) {
302 *item_flags |= MLX5_FLOW_LAYER_IPIP;
305 if (next_protocol == IPPROTO_IPV6) {
306 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
311 static inline struct mlx5_hlist *
312 flow_dv_hlist_prepare(struct mlx5_dev_ctx_shared *sh, struct mlx5_hlist **phl,
313 const char *name, uint32_t size, bool direct_key,
314 bool lcores_share, void *ctx,
315 mlx5_list_create_cb cb_create,
316 mlx5_list_match_cb cb_match,
317 mlx5_list_remove_cb cb_remove,
318 mlx5_list_clone_cb cb_clone,
319 mlx5_list_clone_free_cb cb_clone_free,
320 struct rte_flow_error *error)
322 struct mlx5_hlist *hl;
323 struct mlx5_hlist *expected = NULL;
324 char s[MLX5_NAME_SIZE];
326 hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
329 snprintf(s, sizeof(s), "%s_%s", sh->ibdev_name, name);
330 hl = mlx5_hlist_create(s, size, direct_key, lcores_share,
331 ctx, cb_create, cb_match, cb_remove, cb_clone,
334 DRV_LOG(ERR, "%s hash creation failed", name);
335 rte_flow_error_set(error, ENOMEM,
336 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
337 "cannot allocate resource memory");
340 if (!__atomic_compare_exchange_n(phl, &expected, hl, false,
343 mlx5_hlist_destroy(hl);
344 hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
349 /* Update VLAN's VID/PCP based on input rte_flow_action.
352 * Pointer to struct rte_flow_action.
354 * Pointer to struct rte_vlan_hdr.
357 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
358 struct rte_vlan_hdr *vlan)
361 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
363 ((const struct rte_flow_action_of_set_vlan_pcp *)
364 action->conf)->vlan_pcp;
365 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
366 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
367 vlan->vlan_tci |= vlan_tci;
368 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
369 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
370 vlan->vlan_tci |= rte_be_to_cpu_16
371 (((const struct rte_flow_action_of_set_vlan_vid *)
372 action->conf)->vlan_vid);
377 * Fetch 1, 2, 3 or 4 byte field from the byte array
378 * and return as unsigned integer in host-endian format.
381 * Pointer to data array.
383 * Size of field to extract.
386 * converted field in host endian format.
388 static inline uint32_t
389 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
398 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
401 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
402 ret = (ret << 8) | *(data + sizeof(uint16_t));
405 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
416 * Convert modify-header action to DV specification.
418 * Data length of each action is determined by provided field description
419 * and the item mask. Data bit offset and width of each action is determined
420 * by provided item mask.
423 * Pointer to item specification.
425 * Pointer to field modification information.
426 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
427 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
428 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
430 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
431 * Negative offset value sets the same offset as source offset.
432 * size field is ignored, value is taken from source field.
433 * @param[in,out] resource
434 * Pointer to the modify-header resource.
436 * Type of modification.
438 * Pointer to the error structure.
441 * 0 on success, a negative errno value otherwise and rte_errno is set.
444 flow_dv_convert_modify_action(struct rte_flow_item *item,
445 struct field_modify_info *field,
446 struct field_modify_info *dcopy,
447 struct mlx5_flow_dv_modify_hdr_resource *resource,
448 uint32_t type, struct rte_flow_error *error)
450 uint32_t i = resource->actions_num;
451 struct mlx5_modification_cmd *actions = resource->actions;
452 uint32_t carry_b = 0;
455 * The item and mask are provided in big-endian format.
456 * The fields should be presented as in big-endian format either.
457 * Mask must be always present, it defines the actual field width.
459 MLX5_ASSERT(item->mask);
460 MLX5_ASSERT(field->size);
466 bool next_field = true;
467 bool next_dcopy = true;
469 if (i >= MLX5_MAX_MODIFY_NUM)
470 return rte_flow_error_set(error, EINVAL,
471 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
472 "too many items to modify");
473 /* Fetch variable byte size mask from the array. */
474 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
475 field->offset, field->size);
480 /* Deduce actual data width in bits from mask value. */
481 off_b = rte_bsf32(mask) + carry_b;
482 size_b = sizeof(uint32_t) * CHAR_BIT -
483 off_b - __builtin_clz(mask);
485 actions[i] = (struct mlx5_modification_cmd) {
489 .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
492 if (type == MLX5_MODIFICATION_TYPE_COPY) {
494 actions[i].dst_field = dcopy->id;
495 actions[i].dst_offset =
496 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
497 /* Convert entire record to big-endian format. */
498 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
500 * Destination field overflow. Copy leftovers of
501 * a source field to the next destination field.
504 if ((size_b > dcopy->size * CHAR_BIT - dcopy->offset) &&
507 dcopy->size * CHAR_BIT - dcopy->offset;
508 carry_b = actions[i].length;
512 * Not enough bits in a source filed to fill a
513 * destination field. Switch to the next source.
515 if ((size_b < dcopy->size * CHAR_BIT - dcopy->offset) &&
516 (size_b == field->size * CHAR_BIT - off_b)) {
518 field->size * CHAR_BIT - off_b;
519 dcopy->offset += actions[i].length;
525 MLX5_ASSERT(item->spec);
526 data = flow_dv_fetch_field((const uint8_t *)item->spec +
527 field->offset, field->size);
528 /* Shift out the trailing masked bits from data. */
529 data = (data & mask) >> off_b;
530 actions[i].data1 = rte_cpu_to_be_32(data);
532 /* Convert entire record to expected big-endian format. */
533 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
537 } while (field->size);
538 if (resource->actions_num == i)
539 return rte_flow_error_set(error, EINVAL,
540 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
541 "invalid modification flow item");
542 resource->actions_num = i;
547 * Convert modify-header set IPv4 address action to DV specification.
549 * @param[in,out] resource
550 * Pointer to the modify-header resource.
552 * Pointer to action specification.
554 * Pointer to the error structure.
557 * 0 on success, a negative errno value otherwise and rte_errno is set.
560 flow_dv_convert_action_modify_ipv4
561 (struct mlx5_flow_dv_modify_hdr_resource *resource,
562 const struct rte_flow_action *action,
563 struct rte_flow_error *error)
565 const struct rte_flow_action_set_ipv4 *conf =
566 (const struct rte_flow_action_set_ipv4 *)(action->conf);
567 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
568 struct rte_flow_item_ipv4 ipv4;
569 struct rte_flow_item_ipv4 ipv4_mask;
571 memset(&ipv4, 0, sizeof(ipv4));
572 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
573 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
574 ipv4.hdr.src_addr = conf->ipv4_addr;
575 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
577 ipv4.hdr.dst_addr = conf->ipv4_addr;
578 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
581 item.mask = &ipv4_mask;
582 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
583 MLX5_MODIFICATION_TYPE_SET, error);
587 * Convert modify-header set IPv6 address action to DV specification.
589 * @param[in,out] resource
590 * Pointer to the modify-header resource.
592 * Pointer to action specification.
594 * Pointer to the error structure.
597 * 0 on success, a negative errno value otherwise and rte_errno is set.
600 flow_dv_convert_action_modify_ipv6
601 (struct mlx5_flow_dv_modify_hdr_resource *resource,
602 const struct rte_flow_action *action,
603 struct rte_flow_error *error)
605 const struct rte_flow_action_set_ipv6 *conf =
606 (const struct rte_flow_action_set_ipv6 *)(action->conf);
607 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
608 struct rte_flow_item_ipv6 ipv6;
609 struct rte_flow_item_ipv6 ipv6_mask;
611 memset(&ipv6, 0, sizeof(ipv6));
612 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
613 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
614 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
615 sizeof(ipv6.hdr.src_addr));
616 memcpy(&ipv6_mask.hdr.src_addr,
617 &rte_flow_item_ipv6_mask.hdr.src_addr,
618 sizeof(ipv6.hdr.src_addr));
620 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
621 sizeof(ipv6.hdr.dst_addr));
622 memcpy(&ipv6_mask.hdr.dst_addr,
623 &rte_flow_item_ipv6_mask.hdr.dst_addr,
624 sizeof(ipv6.hdr.dst_addr));
627 item.mask = &ipv6_mask;
628 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
629 MLX5_MODIFICATION_TYPE_SET, error);
633 * Convert modify-header set MAC address action to DV specification.
635 * @param[in,out] resource
636 * Pointer to the modify-header resource.
638 * Pointer to action specification.
640 * Pointer to the error structure.
643 * 0 on success, a negative errno value otherwise and rte_errno is set.
646 flow_dv_convert_action_modify_mac
647 (struct mlx5_flow_dv_modify_hdr_resource *resource,
648 const struct rte_flow_action *action,
649 struct rte_flow_error *error)
651 const struct rte_flow_action_set_mac *conf =
652 (const struct rte_flow_action_set_mac *)(action->conf);
653 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
654 struct rte_flow_item_eth eth;
655 struct rte_flow_item_eth eth_mask;
657 memset(ð, 0, sizeof(eth));
658 memset(ð_mask, 0, sizeof(eth_mask));
659 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
660 memcpy(ð.src.addr_bytes, &conf->mac_addr,
661 sizeof(eth.src.addr_bytes));
662 memcpy(ð_mask.src.addr_bytes,
663 &rte_flow_item_eth_mask.src.addr_bytes,
664 sizeof(eth_mask.src.addr_bytes));
666 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
667 sizeof(eth.dst.addr_bytes));
668 memcpy(ð_mask.dst.addr_bytes,
669 &rte_flow_item_eth_mask.dst.addr_bytes,
670 sizeof(eth_mask.dst.addr_bytes));
673 item.mask = ð_mask;
674 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
675 MLX5_MODIFICATION_TYPE_SET, error);
679 * Convert modify-header set VLAN VID action to DV specification.
681 * @param[in,out] resource
682 * Pointer to the modify-header resource.
684 * Pointer to action specification.
686 * Pointer to the error structure.
689 * 0 on success, a negative errno value otherwise and rte_errno is set.
692 flow_dv_convert_action_modify_vlan_vid
693 (struct mlx5_flow_dv_modify_hdr_resource *resource,
694 const struct rte_flow_action *action,
695 struct rte_flow_error *error)
697 const struct rte_flow_action_of_set_vlan_vid *conf =
698 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
699 int i = resource->actions_num;
700 struct mlx5_modification_cmd *actions = resource->actions;
701 struct field_modify_info *field = modify_vlan_out_first_vid;
703 if (i >= MLX5_MAX_MODIFY_NUM)
704 return rte_flow_error_set(error, EINVAL,
705 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
706 "too many items to modify");
707 actions[i] = (struct mlx5_modification_cmd) {
708 .action_type = MLX5_MODIFICATION_TYPE_SET,
710 .length = field->size,
711 .offset = field->offset,
713 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
714 actions[i].data1 = conf->vlan_vid;
715 actions[i].data1 = actions[i].data1 << 16;
716 resource->actions_num = ++i;
721 * Convert modify-header set TP action to DV specification.
723 * @param[in,out] resource
724 * Pointer to the modify-header resource.
726 * Pointer to action specification.
728 * Pointer to rte_flow_item objects list.
730 * Pointer to flow attributes structure.
731 * @param[in] dev_flow
732 * Pointer to the sub flow.
733 * @param[in] tunnel_decap
734 * Whether action is after tunnel decapsulation.
736 * Pointer to the error structure.
739 * 0 on success, a negative errno value otherwise and rte_errno is set.
742 flow_dv_convert_action_modify_tp
743 (struct mlx5_flow_dv_modify_hdr_resource *resource,
744 const struct rte_flow_action *action,
745 const struct rte_flow_item *items,
746 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
747 bool tunnel_decap, struct rte_flow_error *error)
749 const struct rte_flow_action_set_tp *conf =
750 (const struct rte_flow_action_set_tp *)(action->conf);
751 struct rte_flow_item item;
752 struct rte_flow_item_udp udp;
753 struct rte_flow_item_udp udp_mask;
754 struct rte_flow_item_tcp tcp;
755 struct rte_flow_item_tcp tcp_mask;
756 struct field_modify_info *field;
759 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
761 memset(&udp, 0, sizeof(udp));
762 memset(&udp_mask, 0, sizeof(udp_mask));
763 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
764 udp.hdr.src_port = conf->port;
765 udp_mask.hdr.src_port =
766 rte_flow_item_udp_mask.hdr.src_port;
768 udp.hdr.dst_port = conf->port;
769 udp_mask.hdr.dst_port =
770 rte_flow_item_udp_mask.hdr.dst_port;
772 item.type = RTE_FLOW_ITEM_TYPE_UDP;
774 item.mask = &udp_mask;
777 MLX5_ASSERT(attr->tcp);
778 memset(&tcp, 0, sizeof(tcp));
779 memset(&tcp_mask, 0, sizeof(tcp_mask));
780 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
781 tcp.hdr.src_port = conf->port;
782 tcp_mask.hdr.src_port =
783 rte_flow_item_tcp_mask.hdr.src_port;
785 tcp.hdr.dst_port = conf->port;
786 tcp_mask.hdr.dst_port =
787 rte_flow_item_tcp_mask.hdr.dst_port;
789 item.type = RTE_FLOW_ITEM_TYPE_TCP;
791 item.mask = &tcp_mask;
794 return flow_dv_convert_modify_action(&item, field, NULL, resource,
795 MLX5_MODIFICATION_TYPE_SET, error);
799 * Convert modify-header set TTL action to DV specification.
801 * @param[in,out] resource
802 * Pointer to the modify-header resource.
804 * Pointer to action specification.
806 * Pointer to rte_flow_item objects list.
808 * Pointer to flow attributes structure.
809 * @param[in] dev_flow
810 * Pointer to the sub flow.
811 * @param[in] tunnel_decap
812 * Whether action is after tunnel decapsulation.
814 * Pointer to the error structure.
817 * 0 on success, a negative errno value otherwise and rte_errno is set.
820 flow_dv_convert_action_modify_ttl
821 (struct mlx5_flow_dv_modify_hdr_resource *resource,
822 const struct rte_flow_action *action,
823 const struct rte_flow_item *items,
824 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
825 bool tunnel_decap, struct rte_flow_error *error)
827 const struct rte_flow_action_set_ttl *conf =
828 (const struct rte_flow_action_set_ttl *)(action->conf);
829 struct rte_flow_item item;
830 struct rte_flow_item_ipv4 ipv4;
831 struct rte_flow_item_ipv4 ipv4_mask;
832 struct rte_flow_item_ipv6 ipv6;
833 struct rte_flow_item_ipv6 ipv6_mask;
834 struct field_modify_info *field;
837 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
839 memset(&ipv4, 0, sizeof(ipv4));
840 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
841 ipv4.hdr.time_to_live = conf->ttl_value;
842 ipv4_mask.hdr.time_to_live = 0xFF;
843 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
845 item.mask = &ipv4_mask;
848 MLX5_ASSERT(attr->ipv6);
849 memset(&ipv6, 0, sizeof(ipv6));
850 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
851 ipv6.hdr.hop_limits = conf->ttl_value;
852 ipv6_mask.hdr.hop_limits = 0xFF;
853 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
855 item.mask = &ipv6_mask;
858 return flow_dv_convert_modify_action(&item, field, NULL, resource,
859 MLX5_MODIFICATION_TYPE_SET, error);
863 * Convert modify-header decrement TTL action to DV specification.
865 * @param[in,out] resource
866 * Pointer to the modify-header resource.
868 * Pointer to action specification.
870 * Pointer to rte_flow_item objects list.
872 * Pointer to flow attributes structure.
873 * @param[in] dev_flow
874 * Pointer to the sub flow.
875 * @param[in] tunnel_decap
876 * Whether action is after tunnel decapsulation.
878 * Pointer to the error structure.
881 * 0 on success, a negative errno value otherwise and rte_errno is set.
884 flow_dv_convert_action_modify_dec_ttl
885 (struct mlx5_flow_dv_modify_hdr_resource *resource,
886 const struct rte_flow_item *items,
887 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
888 bool tunnel_decap, struct rte_flow_error *error)
890 struct rte_flow_item item;
891 struct rte_flow_item_ipv4 ipv4;
892 struct rte_flow_item_ipv4 ipv4_mask;
893 struct rte_flow_item_ipv6 ipv6;
894 struct rte_flow_item_ipv6 ipv6_mask;
895 struct field_modify_info *field;
898 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
900 memset(&ipv4, 0, sizeof(ipv4));
901 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
902 ipv4.hdr.time_to_live = 0xFF;
903 ipv4_mask.hdr.time_to_live = 0xFF;
904 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
906 item.mask = &ipv4_mask;
909 MLX5_ASSERT(attr->ipv6);
910 memset(&ipv6, 0, sizeof(ipv6));
911 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
912 ipv6.hdr.hop_limits = 0xFF;
913 ipv6_mask.hdr.hop_limits = 0xFF;
914 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
916 item.mask = &ipv6_mask;
919 return flow_dv_convert_modify_action(&item, field, NULL, resource,
920 MLX5_MODIFICATION_TYPE_ADD, error);
924 * Convert modify-header increment/decrement TCP Sequence number
925 * to DV specification.
927 * @param[in,out] resource
928 * Pointer to the modify-header resource.
930 * Pointer to action specification.
932 * Pointer to the error structure.
935 * 0 on success, a negative errno value otherwise and rte_errno is set.
938 flow_dv_convert_action_modify_tcp_seq
939 (struct mlx5_flow_dv_modify_hdr_resource *resource,
940 const struct rte_flow_action *action,
941 struct rte_flow_error *error)
943 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
944 uint64_t value = rte_be_to_cpu_32(*conf);
945 struct rte_flow_item item;
946 struct rte_flow_item_tcp tcp;
947 struct rte_flow_item_tcp tcp_mask;
949 memset(&tcp, 0, sizeof(tcp));
950 memset(&tcp_mask, 0, sizeof(tcp_mask));
951 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
953 * The HW has no decrement operation, only increment operation.
954 * To simulate decrement X from Y using increment operation
955 * we need to add UINT32_MAX X times to Y.
956 * Each adding of UINT32_MAX decrements Y by 1.
959 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
960 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
961 item.type = RTE_FLOW_ITEM_TYPE_TCP;
963 item.mask = &tcp_mask;
964 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
965 MLX5_MODIFICATION_TYPE_ADD, error);
969 * Convert modify-header increment/decrement TCP Acknowledgment number
970 * to DV specification.
972 * @param[in,out] resource
973 * Pointer to the modify-header resource.
975 * Pointer to action specification.
977 * Pointer to the error structure.
980 * 0 on success, a negative errno value otherwise and rte_errno is set.
983 flow_dv_convert_action_modify_tcp_ack
984 (struct mlx5_flow_dv_modify_hdr_resource *resource,
985 const struct rte_flow_action *action,
986 struct rte_flow_error *error)
988 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
989 uint64_t value = rte_be_to_cpu_32(*conf);
990 struct rte_flow_item item;
991 struct rte_flow_item_tcp tcp;
992 struct rte_flow_item_tcp tcp_mask;
994 memset(&tcp, 0, sizeof(tcp));
995 memset(&tcp_mask, 0, sizeof(tcp_mask));
996 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
998 * The HW has no decrement operation, only increment operation.
999 * To simulate decrement X from Y using increment operation
1000 * we need to add UINT32_MAX X times to Y.
1001 * Each adding of UINT32_MAX decrements Y by 1.
1003 value *= UINT32_MAX;
1004 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
1005 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
1006 item.type = RTE_FLOW_ITEM_TYPE_TCP;
1008 item.mask = &tcp_mask;
1009 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
1010 MLX5_MODIFICATION_TYPE_ADD, error);
1013 static enum mlx5_modification_field reg_to_field[] = {
1014 [REG_NON] = MLX5_MODI_OUT_NONE,
1015 [REG_A] = MLX5_MODI_META_DATA_REG_A,
1016 [REG_B] = MLX5_MODI_META_DATA_REG_B,
1017 [REG_C_0] = MLX5_MODI_META_REG_C_0,
1018 [REG_C_1] = MLX5_MODI_META_REG_C_1,
1019 [REG_C_2] = MLX5_MODI_META_REG_C_2,
1020 [REG_C_3] = MLX5_MODI_META_REG_C_3,
1021 [REG_C_4] = MLX5_MODI_META_REG_C_4,
1022 [REG_C_5] = MLX5_MODI_META_REG_C_5,
1023 [REG_C_6] = MLX5_MODI_META_REG_C_6,
1024 [REG_C_7] = MLX5_MODI_META_REG_C_7,
1028 * Convert register set to DV specification.
1030 * @param[in,out] resource
1031 * Pointer to the modify-header resource.
1033 * Pointer to action specification.
1035 * Pointer to the error structure.
1038 * 0 on success, a negative errno value otherwise and rte_errno is set.
1041 flow_dv_convert_action_set_reg
1042 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1043 const struct rte_flow_action *action,
1044 struct rte_flow_error *error)
1046 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
1047 struct mlx5_modification_cmd *actions = resource->actions;
1048 uint32_t i = resource->actions_num;
1050 if (i >= MLX5_MAX_MODIFY_NUM)
1051 return rte_flow_error_set(error, EINVAL,
1052 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1053 "too many items to modify");
1054 MLX5_ASSERT(conf->id != REG_NON);
1055 MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
1056 actions[i] = (struct mlx5_modification_cmd) {
1057 .action_type = MLX5_MODIFICATION_TYPE_SET,
1058 .field = reg_to_field[conf->id],
1059 .offset = conf->offset,
1060 .length = conf->length,
1062 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
1063 actions[i].data1 = rte_cpu_to_be_32(conf->data);
1065 resource->actions_num = i;
1070 * Convert SET_TAG action to DV specification.
1073 * Pointer to the rte_eth_dev structure.
1074 * @param[in,out] resource
1075 * Pointer to the modify-header resource.
1077 * Pointer to action specification.
1079 * Pointer to the error structure.
1082 * 0 on success, a negative errno value otherwise and rte_errno is set.
1085 flow_dv_convert_action_set_tag
1086 (struct rte_eth_dev *dev,
1087 struct mlx5_flow_dv_modify_hdr_resource *resource,
1088 const struct rte_flow_action_set_tag *conf,
1089 struct rte_flow_error *error)
1091 rte_be32_t data = rte_cpu_to_be_32(conf->data);
1092 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1093 struct rte_flow_item item = {
1097 struct field_modify_info reg_c_x[] = {
1100 enum mlx5_modification_field reg_type;
1103 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1106 MLX5_ASSERT(ret != REG_NON);
1107 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1108 reg_type = reg_to_field[ret];
1109 MLX5_ASSERT(reg_type > 0);
1110 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1111 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1112 MLX5_MODIFICATION_TYPE_SET, error);
1116 * Convert internal COPY_REG action to DV specification.
1119 * Pointer to the rte_eth_dev structure.
1120 * @param[in,out] res
1121 * Pointer to the modify-header resource.
1123 * Pointer to action specification.
1125 * Pointer to the error structure.
1128 * 0 on success, a negative errno value otherwise and rte_errno is set.
1131 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1132 struct mlx5_flow_dv_modify_hdr_resource *res,
1133 const struct rte_flow_action *action,
1134 struct rte_flow_error *error)
1136 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1137 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1138 struct rte_flow_item item = {
1142 struct field_modify_info reg_src[] = {
1143 {4, 0, reg_to_field[conf->src]},
1146 struct field_modify_info reg_dst = {
1148 .id = reg_to_field[conf->dst],
1150 /* Adjust reg_c[0] usage according to reported mask. */
1151 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1152 struct mlx5_priv *priv = dev->data->dev_private;
1153 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1155 MLX5_ASSERT(reg_c0);
1156 MLX5_ASSERT(priv->sh->config.dv_xmeta_en !=
1157 MLX5_XMETA_MODE_LEGACY);
1158 if (conf->dst == REG_C_0) {
1159 /* Copy to reg_c[0], within mask only. */
1160 reg_dst.offset = rte_bsf32(reg_c0);
1161 mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1164 mask = rte_cpu_to_be_32(reg_c0);
1167 return flow_dv_convert_modify_action(&item,
1168 reg_src, ®_dst, res,
1169 MLX5_MODIFICATION_TYPE_COPY,
1174 * Convert MARK action to DV specification. This routine is used
1175 * in extensive metadata only and requires metadata register to be
1176 * handled. In legacy mode hardware tag resource is engaged.
1179 * Pointer to the rte_eth_dev structure.
1181 * Pointer to MARK action specification.
1182 * @param[in,out] resource
1183 * Pointer to the modify-header resource.
1185 * Pointer to the error structure.
1188 * 0 on success, a negative errno value otherwise and rte_errno is set.
1191 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1192 const struct rte_flow_action_mark *conf,
1193 struct mlx5_flow_dv_modify_hdr_resource *resource,
1194 struct rte_flow_error *error)
1196 struct mlx5_priv *priv = dev->data->dev_private;
1197 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1198 priv->sh->dv_mark_mask);
1199 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1200 struct rte_flow_item item = {
1204 struct field_modify_info reg_c_x[] = {
1210 return rte_flow_error_set(error, EINVAL,
1211 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1212 NULL, "zero mark action mask");
1213 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1216 MLX5_ASSERT(reg > 0);
1217 if (reg == REG_C_0) {
1218 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1219 uint32_t shl_c0 = rte_bsf32(msk_c0);
1221 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1222 mask = rte_cpu_to_be_32(mask) & msk_c0;
1223 mask = rte_cpu_to_be_32(mask << shl_c0);
1225 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1226 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1227 MLX5_MODIFICATION_TYPE_SET, error);
1231 * Get metadata register index for specified steering domain.
1234 * Pointer to the rte_eth_dev structure.
1236 * Attributes of flow to determine steering domain.
1238 * Pointer to the error structure.
1241 * positive index on success, a negative errno value otherwise
1242 * and rte_errno is set.
1244 static enum modify_reg
1245 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1246 const struct rte_flow_attr *attr,
1247 struct rte_flow_error *error)
1250 mlx5_flow_get_reg_id(dev, attr->transfer ?
1254 MLX5_METADATA_RX, 0, error);
1256 return rte_flow_error_set(error,
1257 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1258 NULL, "unavailable "
1259 "metadata register");
1264 * Convert SET_META action to DV specification.
1267 * Pointer to the rte_eth_dev structure.
1268 * @param[in,out] resource
1269 * Pointer to the modify-header resource.
1271 * Attributes of flow that includes this item.
1273 * Pointer to action specification.
1275 * Pointer to the error structure.
1278 * 0 on success, a negative errno value otherwise and rte_errno is set.
1281 flow_dv_convert_action_set_meta
1282 (struct rte_eth_dev *dev,
1283 struct mlx5_flow_dv_modify_hdr_resource *resource,
1284 const struct rte_flow_attr *attr,
1285 const struct rte_flow_action_set_meta *conf,
1286 struct rte_flow_error *error)
1288 uint32_t mask = rte_cpu_to_be_32(conf->mask);
1289 uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1290 struct rte_flow_item item = {
1294 struct field_modify_info reg_c_x[] = {
1297 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1301 MLX5_ASSERT(reg != REG_NON);
1302 if (reg == REG_C_0) {
1303 struct mlx5_priv *priv = dev->data->dev_private;
1304 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1305 uint32_t shl_c0 = rte_bsf32(msk_c0);
1307 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1308 mask = rte_cpu_to_be_32(mask) & msk_c0;
1309 mask = rte_cpu_to_be_32(mask << shl_c0);
1311 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1312 /* The routine expects parameters in memory as big-endian ones. */
1313 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1314 MLX5_MODIFICATION_TYPE_SET, error);
1318 * Convert modify-header set IPv4 DSCP action to DV specification.
1320 * @param[in,out] resource
1321 * Pointer to the modify-header resource.
1323 * Pointer to action specification.
1325 * Pointer to the error structure.
1328 * 0 on success, a negative errno value otherwise and rte_errno is set.
1331 flow_dv_convert_action_modify_ipv4_dscp
1332 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1333 const struct rte_flow_action *action,
1334 struct rte_flow_error *error)
1336 const struct rte_flow_action_set_dscp *conf =
1337 (const struct rte_flow_action_set_dscp *)(action->conf);
1338 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1339 struct rte_flow_item_ipv4 ipv4;
1340 struct rte_flow_item_ipv4 ipv4_mask;
1342 memset(&ipv4, 0, sizeof(ipv4));
1343 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1344 ipv4.hdr.type_of_service = conf->dscp;
1345 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1347 item.mask = &ipv4_mask;
1348 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1349 MLX5_MODIFICATION_TYPE_SET, error);
1353 * Convert modify-header set IPv6 DSCP action to DV specification.
1355 * @param[in,out] resource
1356 * Pointer to the modify-header resource.
1358 * Pointer to action specification.
1360 * Pointer to the error structure.
1363 * 0 on success, a negative errno value otherwise and rte_errno is set.
1366 flow_dv_convert_action_modify_ipv6_dscp
1367 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1368 const struct rte_flow_action *action,
1369 struct rte_flow_error *error)
1371 const struct rte_flow_action_set_dscp *conf =
1372 (const struct rte_flow_action_set_dscp *)(action->conf);
1373 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1374 struct rte_flow_item_ipv6 ipv6;
1375 struct rte_flow_item_ipv6 ipv6_mask;
1377 memset(&ipv6, 0, sizeof(ipv6));
1378 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1380 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1381 * rdma-core only accept the DSCP bits byte aligned start from
1382 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1383 * bits in IPv6 case as rdma-core requires byte aligned value.
1385 ipv6.hdr.vtc_flow = conf->dscp;
1386 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1388 item.mask = &ipv6_mask;
1389 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1390 MLX5_MODIFICATION_TYPE_SET, error);
1394 mlx5_flow_item_field_width(struct rte_eth_dev *dev,
1395 enum rte_flow_field_id field, int inherit,
1396 const struct rte_flow_attr *attr,
1397 struct rte_flow_error *error)
1399 struct mlx5_priv *priv = dev->data->dev_private;
1402 case RTE_FLOW_FIELD_START:
1404 case RTE_FLOW_FIELD_MAC_DST:
1405 case RTE_FLOW_FIELD_MAC_SRC:
1407 case RTE_FLOW_FIELD_VLAN_TYPE:
1409 case RTE_FLOW_FIELD_VLAN_ID:
1411 case RTE_FLOW_FIELD_MAC_TYPE:
1413 case RTE_FLOW_FIELD_IPV4_DSCP:
1415 case RTE_FLOW_FIELD_IPV4_TTL:
1417 case RTE_FLOW_FIELD_IPV4_SRC:
1418 case RTE_FLOW_FIELD_IPV4_DST:
1420 case RTE_FLOW_FIELD_IPV6_DSCP:
1422 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1424 case RTE_FLOW_FIELD_IPV6_SRC:
1425 case RTE_FLOW_FIELD_IPV6_DST:
1427 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1428 case RTE_FLOW_FIELD_TCP_PORT_DST:
1430 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1431 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1433 case RTE_FLOW_FIELD_TCP_FLAGS:
1435 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1436 case RTE_FLOW_FIELD_UDP_PORT_DST:
1438 case RTE_FLOW_FIELD_VXLAN_VNI:
1439 case RTE_FLOW_FIELD_GENEVE_VNI:
1441 case RTE_FLOW_FIELD_GTP_TEID:
1442 case RTE_FLOW_FIELD_TAG:
1444 case RTE_FLOW_FIELD_MARK:
1445 return __builtin_popcount(priv->sh->dv_mark_mask);
1446 case RTE_FLOW_FIELD_META:
1447 return (flow_dv_get_metadata_reg(dev, attr, error) == REG_C_0) ?
1448 __builtin_popcount(priv->sh->dv_meta_mask) : 32;
1449 case RTE_FLOW_FIELD_POINTER:
1450 case RTE_FLOW_FIELD_VALUE:
1451 return inherit < 0 ? 0 : inherit;
1459 mlx5_flow_field_id_to_modify_info
1460 (const struct rte_flow_action_modify_data *data,
1461 struct field_modify_info *info, uint32_t *mask,
1462 uint32_t width, struct rte_eth_dev *dev,
1463 const struct rte_flow_attr *attr, struct rte_flow_error *error)
1465 struct mlx5_priv *priv = dev->data->dev_private;
1469 switch (data->field) {
1470 case RTE_FLOW_FIELD_START:
1471 /* not supported yet */
1474 case RTE_FLOW_FIELD_MAC_DST:
1475 off = data->offset > 16 ? data->offset - 16 : 0;
1477 if (data->offset < 16) {
1478 info[idx] = (struct field_modify_info){2, 4,
1479 MLX5_MODI_OUT_DMAC_15_0};
1481 mask[1] = rte_cpu_to_be_16(0xffff >>
1485 mask[1] = RTE_BE16(0xffff);
1492 info[idx] = (struct field_modify_info){4, 0,
1493 MLX5_MODI_OUT_DMAC_47_16};
1494 mask[0] = rte_cpu_to_be_32((0xffffffff >>
1495 (32 - width)) << off);
1497 if (data->offset < 16)
1498 info[idx++] = (struct field_modify_info){2, 0,
1499 MLX5_MODI_OUT_DMAC_15_0};
1500 info[idx] = (struct field_modify_info){4, off,
1501 MLX5_MODI_OUT_DMAC_47_16};
1504 case RTE_FLOW_FIELD_MAC_SRC:
1505 off = data->offset > 16 ? data->offset - 16 : 0;
1507 if (data->offset < 16) {
1508 info[idx] = (struct field_modify_info){2, 4,
1509 MLX5_MODI_OUT_SMAC_15_0};
1511 mask[1] = rte_cpu_to_be_16(0xffff >>
1515 mask[1] = RTE_BE16(0xffff);
1522 info[idx] = (struct field_modify_info){4, 0,
1523 MLX5_MODI_OUT_SMAC_47_16};
1524 mask[0] = rte_cpu_to_be_32((0xffffffff >>
1525 (32 - width)) << off);
1527 if (data->offset < 16)
1528 info[idx++] = (struct field_modify_info){2, 0,
1529 MLX5_MODI_OUT_SMAC_15_0};
1530 info[idx] = (struct field_modify_info){4, off,
1531 MLX5_MODI_OUT_SMAC_47_16};
1534 case RTE_FLOW_FIELD_VLAN_TYPE:
1535 /* not supported yet */
1537 case RTE_FLOW_FIELD_VLAN_ID:
1538 info[idx] = (struct field_modify_info){2, 0,
1539 MLX5_MODI_OUT_FIRST_VID};
1541 mask[idx] = rte_cpu_to_be_16(0x0fff >> (12 - width));
1543 case RTE_FLOW_FIELD_MAC_TYPE:
1544 info[idx] = (struct field_modify_info){2, 0,
1545 MLX5_MODI_OUT_ETHERTYPE};
1547 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1549 case RTE_FLOW_FIELD_IPV4_DSCP:
1550 info[idx] = (struct field_modify_info){1, 0,
1551 MLX5_MODI_OUT_IP_DSCP};
1553 mask[idx] = 0x3f >> (6 - width);
1555 case RTE_FLOW_FIELD_IPV4_TTL:
1556 info[idx] = (struct field_modify_info){1, 0,
1557 MLX5_MODI_OUT_IPV4_TTL};
1559 mask[idx] = 0xff >> (8 - width);
1561 case RTE_FLOW_FIELD_IPV4_SRC:
1562 info[idx] = (struct field_modify_info){4, 0,
1563 MLX5_MODI_OUT_SIPV4};
1565 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1568 case RTE_FLOW_FIELD_IPV4_DST:
1569 info[idx] = (struct field_modify_info){4, 0,
1570 MLX5_MODI_OUT_DIPV4};
1572 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1575 case RTE_FLOW_FIELD_IPV6_DSCP:
1576 info[idx] = (struct field_modify_info){1, 0,
1577 MLX5_MODI_OUT_IP_DSCP};
1579 mask[idx] = 0x3f >> (6 - width);
1581 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1582 info[idx] = (struct field_modify_info){1, 0,
1583 MLX5_MODI_OUT_IPV6_HOPLIMIT};
1585 mask[idx] = 0xff >> (8 - width);
1587 case RTE_FLOW_FIELD_IPV6_SRC:
1589 if (data->offset < 32) {
1590 info[idx] = (struct field_modify_info){4, 12,
1591 MLX5_MODI_OUT_SIPV6_31_0};
1594 rte_cpu_to_be_32(0xffffffff >>
1598 mask[3] = RTE_BE32(0xffffffff);
1605 if (data->offset < 64) {
1606 info[idx] = (struct field_modify_info){4, 8,
1607 MLX5_MODI_OUT_SIPV6_63_32};
1610 rte_cpu_to_be_32(0xffffffff >>
1614 mask[2] = RTE_BE32(0xffffffff);
1621 if (data->offset < 96) {
1622 info[idx] = (struct field_modify_info){4, 4,
1623 MLX5_MODI_OUT_SIPV6_95_64};
1626 rte_cpu_to_be_32(0xffffffff >>
1630 mask[1] = RTE_BE32(0xffffffff);
1637 info[idx] = (struct field_modify_info){4, 0,
1638 MLX5_MODI_OUT_SIPV6_127_96};
1639 mask[0] = rte_cpu_to_be_32(0xffffffff >> (32 - width));
1641 if (data->offset < 32)
1642 info[idx++] = (struct field_modify_info){4, 0,
1643 MLX5_MODI_OUT_SIPV6_31_0};
1644 if (data->offset < 64)
1645 info[idx++] = (struct field_modify_info){4, 0,
1646 MLX5_MODI_OUT_SIPV6_63_32};
1647 if (data->offset < 96)
1648 info[idx++] = (struct field_modify_info){4, 0,
1649 MLX5_MODI_OUT_SIPV6_95_64};
1650 if (data->offset < 128)
1651 info[idx++] = (struct field_modify_info){4, 0,
1652 MLX5_MODI_OUT_SIPV6_127_96};
1655 case RTE_FLOW_FIELD_IPV6_DST:
1657 if (data->offset < 32) {
1658 info[idx] = (struct field_modify_info){4, 12,
1659 MLX5_MODI_OUT_DIPV6_31_0};
1662 rte_cpu_to_be_32(0xffffffff >>
1666 mask[3] = RTE_BE32(0xffffffff);
1673 if (data->offset < 64) {
1674 info[idx] = (struct field_modify_info){4, 8,
1675 MLX5_MODI_OUT_DIPV6_63_32};
1678 rte_cpu_to_be_32(0xffffffff >>
1682 mask[2] = RTE_BE32(0xffffffff);
1689 if (data->offset < 96) {
1690 info[idx] = (struct field_modify_info){4, 4,
1691 MLX5_MODI_OUT_DIPV6_95_64};
1694 rte_cpu_to_be_32(0xffffffff >>
1698 mask[1] = RTE_BE32(0xffffffff);
1705 info[idx] = (struct field_modify_info){4, 0,
1706 MLX5_MODI_OUT_DIPV6_127_96};
1707 mask[0] = rte_cpu_to_be_32(0xffffffff >> (32 - width));
1709 if (data->offset < 32)
1710 info[idx++] = (struct field_modify_info){4, 0,
1711 MLX5_MODI_OUT_DIPV6_31_0};
1712 if (data->offset < 64)
1713 info[idx++] = (struct field_modify_info){4, 0,
1714 MLX5_MODI_OUT_DIPV6_63_32};
1715 if (data->offset < 96)
1716 info[idx++] = (struct field_modify_info){4, 0,
1717 MLX5_MODI_OUT_DIPV6_95_64};
1718 if (data->offset < 128)
1719 info[idx++] = (struct field_modify_info){4, 0,
1720 MLX5_MODI_OUT_DIPV6_127_96};
1723 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1724 info[idx] = (struct field_modify_info){2, 0,
1725 MLX5_MODI_OUT_TCP_SPORT};
1727 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1729 case RTE_FLOW_FIELD_TCP_PORT_DST:
1730 info[idx] = (struct field_modify_info){2, 0,
1731 MLX5_MODI_OUT_TCP_DPORT};
1733 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1735 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1736 info[idx] = (struct field_modify_info){4, 0,
1737 MLX5_MODI_OUT_TCP_SEQ_NUM};
1739 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1742 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1743 info[idx] = (struct field_modify_info){4, 0,
1744 MLX5_MODI_OUT_TCP_ACK_NUM};
1746 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1749 case RTE_FLOW_FIELD_TCP_FLAGS:
1750 info[idx] = (struct field_modify_info){2, 0,
1751 MLX5_MODI_OUT_TCP_FLAGS};
1753 mask[idx] = rte_cpu_to_be_16(0x1ff >> (9 - width));
1755 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1756 info[idx] = (struct field_modify_info){2, 0,
1757 MLX5_MODI_OUT_UDP_SPORT};
1759 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1761 case RTE_FLOW_FIELD_UDP_PORT_DST:
1762 info[idx] = (struct field_modify_info){2, 0,
1763 MLX5_MODI_OUT_UDP_DPORT};
1765 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1767 case RTE_FLOW_FIELD_VXLAN_VNI:
1768 /* not supported yet */
1770 case RTE_FLOW_FIELD_GENEVE_VNI:
1771 /* not supported yet*/
1773 case RTE_FLOW_FIELD_GTP_TEID:
1774 info[idx] = (struct field_modify_info){4, 0,
1775 MLX5_MODI_GTP_TEID};
1777 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1780 case RTE_FLOW_FIELD_TAG:
1782 int reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
1783 data->level, error);
1786 MLX5_ASSERT(reg != REG_NON);
1787 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1788 info[idx] = (struct field_modify_info){4, 0,
1792 rte_cpu_to_be_32(0xffffffff >>
1796 case RTE_FLOW_FIELD_MARK:
1798 uint32_t mark_mask = priv->sh->dv_mark_mask;
1799 uint32_t mark_count = __builtin_popcount(mark_mask);
1800 int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
1804 MLX5_ASSERT(reg != REG_NON);
1805 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1806 info[idx] = (struct field_modify_info){4, 0,
1809 mask[idx] = rte_cpu_to_be_32((mark_mask >>
1810 (mark_count - width)) & mark_mask);
1813 case RTE_FLOW_FIELD_META:
1815 uint32_t meta_mask = priv->sh->dv_meta_mask;
1816 uint32_t meta_count = __builtin_popcount(meta_mask);
1817 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1820 MLX5_ASSERT(reg != REG_NON);
1821 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1822 info[idx] = (struct field_modify_info){4, 0,
1825 mask[idx] = rte_cpu_to_be_32((meta_mask >>
1826 (meta_count - width)) & meta_mask);
1829 case RTE_FLOW_FIELD_POINTER:
1830 case RTE_FLOW_FIELD_VALUE:
1838 * Convert modify_field action to DV specification.
1841 * Pointer to the rte_eth_dev structure.
1842 * @param[in,out] resource
1843 * Pointer to the modify-header resource.
1845 * Pointer to action specification.
1847 * Attributes of flow that includes this item.
1849 * Pointer to the error structure.
1852 * 0 on success, a negative errno value otherwise and rte_errno is set.
1855 flow_dv_convert_action_modify_field
1856 (struct rte_eth_dev *dev,
1857 struct mlx5_flow_dv_modify_hdr_resource *resource,
1858 const struct rte_flow_action *action,
1859 const struct rte_flow_attr *attr,
1860 struct rte_flow_error *error)
1862 const struct rte_flow_action_modify_field *conf =
1863 (const struct rte_flow_action_modify_field *)(action->conf);
1864 struct rte_flow_item item = {
1868 struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1870 struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1872 uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1873 uint32_t type, meta = 0;
1875 if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1876 conf->src.field == RTE_FLOW_FIELD_VALUE) {
1877 type = MLX5_MODIFICATION_TYPE_SET;
1878 /** For SET fill the destination field (field) first. */
1879 mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1882 item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
1883 (void *)(uintptr_t)conf->src.pvalue :
1884 (void *)(uintptr_t)&conf->src.value;
1885 if (conf->dst.field == RTE_FLOW_FIELD_META) {
1886 meta = *(const unaligned_uint32_t *)item.spec;
1887 meta = rte_cpu_to_be_32(meta);
1891 type = MLX5_MODIFICATION_TYPE_COPY;
1892 /** For COPY fill the destination field (dcopy) without mask. */
1893 mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1896 /** Then construct the source field (field) with mask. */
1897 mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1902 return flow_dv_convert_modify_action(&item,
1903 field, dcopy, resource, type, error);
1907 * Validate MARK item.
1910 * Pointer to the rte_eth_dev structure.
1912 * Item specification.
1914 * Attributes of flow that includes this item.
1916 * Pointer to error structure.
1919 * 0 on success, a negative errno value otherwise and rte_errno is set.
1922 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1923 const struct rte_flow_item *item,
1924 const struct rte_flow_attr *attr __rte_unused,
1925 struct rte_flow_error *error)
1927 struct mlx5_priv *priv = dev->data->dev_private;
1928 struct mlx5_sh_config *config = &priv->sh->config;
1929 const struct rte_flow_item_mark *spec = item->spec;
1930 const struct rte_flow_item_mark *mask = item->mask;
1931 const struct rte_flow_item_mark nic_mask = {
1932 .id = priv->sh->dv_mark_mask,
1936 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1937 return rte_flow_error_set(error, ENOTSUP,
1938 RTE_FLOW_ERROR_TYPE_ITEM, item,
1939 "extended metadata feature"
1941 if (!mlx5_flow_ext_mreg_supported(dev))
1942 return rte_flow_error_set(error, ENOTSUP,
1943 RTE_FLOW_ERROR_TYPE_ITEM, item,
1944 "extended metadata register"
1945 " isn't supported");
1947 return rte_flow_error_set(error, ENOTSUP,
1948 RTE_FLOW_ERROR_TYPE_ITEM, item,
1949 "extended metadata register"
1950 " isn't available");
1951 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1955 return rte_flow_error_set(error, EINVAL,
1956 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1958 "data cannot be empty");
1959 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1960 return rte_flow_error_set(error, EINVAL,
1961 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1963 "mark id exceeds the limit");
1967 return rte_flow_error_set(error, EINVAL,
1968 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1969 "mask cannot be zero");
1971 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1972 (const uint8_t *)&nic_mask,
1973 sizeof(struct rte_flow_item_mark),
1974 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1981 * Validate META item.
1984 * Pointer to the rte_eth_dev structure.
1986 * Item specification.
1988 * Attributes of flow that includes this item.
1990 * Pointer to error structure.
1993 * 0 on success, a negative errno value otherwise and rte_errno is set.
1996 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1997 const struct rte_flow_item *item,
1998 const struct rte_flow_attr *attr,
1999 struct rte_flow_error *error)
2001 struct mlx5_priv *priv = dev->data->dev_private;
2002 struct mlx5_sh_config *config = &priv->sh->config;
2003 const struct rte_flow_item_meta *spec = item->spec;
2004 const struct rte_flow_item_meta *mask = item->mask;
2005 struct rte_flow_item_meta nic_mask = {
2012 return rte_flow_error_set(error, EINVAL,
2013 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2015 "data cannot be empty");
2016 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2017 if (!mlx5_flow_ext_mreg_supported(dev))
2018 return rte_flow_error_set(error, ENOTSUP,
2019 RTE_FLOW_ERROR_TYPE_ITEM, item,
2020 "extended metadata register"
2021 " isn't supported");
2022 reg = flow_dv_get_metadata_reg(dev, attr, error);
2026 return rte_flow_error_set(error, ENOTSUP,
2027 RTE_FLOW_ERROR_TYPE_ITEM, item,
2028 "unavailable extended metadata register");
2030 return rte_flow_error_set(error, ENOTSUP,
2031 RTE_FLOW_ERROR_TYPE_ITEM, item,
2035 nic_mask.data = priv->sh->dv_meta_mask;
2038 return rte_flow_error_set(error, ENOTSUP,
2039 RTE_FLOW_ERROR_TYPE_ITEM, item,
2040 "extended metadata feature "
2041 "should be enabled when "
2042 "meta item is requested "
2043 "with e-switch mode ");
2045 return rte_flow_error_set(error, ENOTSUP,
2046 RTE_FLOW_ERROR_TYPE_ITEM, item,
2047 "match on metadata for ingress "
2048 "is not supported in legacy "
2052 mask = &rte_flow_item_meta_mask;
2054 return rte_flow_error_set(error, EINVAL,
2055 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2056 "mask cannot be zero");
2058 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2059 (const uint8_t *)&nic_mask,
2060 sizeof(struct rte_flow_item_meta),
2061 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2066 * Validate TAG item.
2069 * Pointer to the rte_eth_dev structure.
2071 * Item specification.
2073 * Attributes of flow that includes this item.
2075 * Pointer to error structure.
2078 * 0 on success, a negative errno value otherwise and rte_errno is set.
2081 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2082 const struct rte_flow_item *item,
2083 const struct rte_flow_attr *attr __rte_unused,
2084 struct rte_flow_error *error)
2086 const struct rte_flow_item_tag *spec = item->spec;
2087 const struct rte_flow_item_tag *mask = item->mask;
2088 const struct rte_flow_item_tag nic_mask = {
2089 .data = RTE_BE32(UINT32_MAX),
2094 if (!mlx5_flow_ext_mreg_supported(dev))
2095 return rte_flow_error_set(error, ENOTSUP,
2096 RTE_FLOW_ERROR_TYPE_ITEM, item,
2097 "extensive metadata register"
2098 " isn't supported");
2100 return rte_flow_error_set(error, EINVAL,
2101 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2103 "data cannot be empty");
2105 mask = &rte_flow_item_tag_mask;
2107 return rte_flow_error_set(error, EINVAL,
2108 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2109 "mask cannot be zero");
2111 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2112 (const uint8_t *)&nic_mask,
2113 sizeof(struct rte_flow_item_tag),
2114 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2117 if (mask->index != 0xff)
2118 return rte_flow_error_set(error, EINVAL,
2119 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2120 "partial mask for tag index"
2121 " is not supported");
2122 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2125 MLX5_ASSERT(ret != REG_NON);
2130 * Validate vport item.
2133 * Pointer to the rte_eth_dev structure.
2135 * Item specification.
2137 * Attributes of flow that includes this item.
2138 * @param[in] item_flags
2139 * Bit-fields that holds the items detected until now.
2141 * Pointer to error structure.
2144 * 0 on success, a negative errno value otherwise and rte_errno is set.
2147 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2148 const struct rte_flow_item *item,
2149 const struct rte_flow_attr *attr,
2150 uint64_t item_flags,
2151 struct rte_flow_error *error)
2153 const struct rte_flow_item_port_id *spec = item->spec;
2154 const struct rte_flow_item_port_id *mask = item->mask;
2155 const struct rte_flow_item_port_id switch_mask = {
2158 struct mlx5_priv *esw_priv;
2159 struct mlx5_priv *dev_priv;
2162 if (!attr->transfer)
2163 return rte_flow_error_set(error, EINVAL,
2164 RTE_FLOW_ERROR_TYPE_ITEM,
2166 "match on port id is valid only"
2167 " when transfer flag is enabled");
2168 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2169 return rte_flow_error_set(error, ENOTSUP,
2170 RTE_FLOW_ERROR_TYPE_ITEM, item,
2171 "multiple source ports are not"
2174 mask = &switch_mask;
2175 if (mask->id != 0xffffffff)
2176 return rte_flow_error_set(error, ENOTSUP,
2177 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2179 "no support for partial mask on"
2181 ret = mlx5_flow_item_acceptable
2182 (item, (const uint8_t *)mask,
2183 (const uint8_t *)&rte_flow_item_port_id_mask,
2184 sizeof(struct rte_flow_item_port_id),
2185 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2190 if (spec->id == MLX5_PORT_ESW_MGR)
2192 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2194 return rte_flow_error_set(error, rte_errno,
2195 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2196 "failed to obtain E-Switch info for"
2198 dev_priv = mlx5_dev_to_eswitch_info(dev);
2200 return rte_flow_error_set(error, rte_errno,
2201 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2203 "failed to obtain E-Switch info");
2204 if (esw_priv->domain_id != dev_priv->domain_id)
2205 return rte_flow_error_set(error, EINVAL,
2206 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2207 "cannot match on a port from a"
2208 " different E-Switch");
2213 * Validate VLAN item.
2216 * Item specification.
2217 * @param[in] item_flags
2218 * Bit-fields that holds the items detected until now.
2220 * Ethernet device flow is being created on.
2222 * Pointer to error structure.
2225 * 0 on success, a negative errno value otherwise and rte_errno is set.
2228 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2229 uint64_t item_flags,
2230 struct rte_eth_dev *dev,
2231 struct rte_flow_error *error)
2233 const struct rte_flow_item_vlan *mask = item->mask;
2234 const struct rte_flow_item_vlan nic_mask = {
2235 .tci = RTE_BE16(UINT16_MAX),
2236 .inner_type = RTE_BE16(UINT16_MAX),
2239 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2241 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2242 MLX5_FLOW_LAYER_INNER_L4) :
2243 (MLX5_FLOW_LAYER_OUTER_L3 |
2244 MLX5_FLOW_LAYER_OUTER_L4);
2245 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2246 MLX5_FLOW_LAYER_OUTER_VLAN;
2248 if (item_flags & vlanm)
2249 return rte_flow_error_set(error, EINVAL,
2250 RTE_FLOW_ERROR_TYPE_ITEM, item,
2251 "multiple VLAN layers not supported");
2252 else if ((item_flags & l34m) != 0)
2253 return rte_flow_error_set(error, EINVAL,
2254 RTE_FLOW_ERROR_TYPE_ITEM, item,
2255 "VLAN cannot follow L3/L4 layer");
2257 mask = &rte_flow_item_vlan_mask;
2258 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2259 (const uint8_t *)&nic_mask,
2260 sizeof(struct rte_flow_item_vlan),
2261 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2264 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2265 struct mlx5_priv *priv = dev->data->dev_private;
2267 if (priv->vmwa_context) {
2269 * Non-NULL context means we have a virtual machine
2270 * and SR-IOV enabled, we have to create VLAN interface
2271 * to make hypervisor to setup E-Switch vport
2272 * context correctly. We avoid creating the multiple
2273 * VLAN interfaces, so we cannot support VLAN tag mask.
2275 return rte_flow_error_set(error, EINVAL,
2276 RTE_FLOW_ERROR_TYPE_ITEM,
2278 "VLAN tag mask is not"
2279 " supported in virtual"
2287 * GTP flags are contained in 1 byte of the format:
2288 * -------------------------------------------
2289 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2290 * |-----------------------------------------|
2291 * | value | Version | PT | Res | E | S | PN |
2292 * -------------------------------------------
2294 * Matching is supported only for GTP flags E, S, PN.
2296 #define MLX5_GTP_FLAGS_MASK 0x07
2299 * Validate GTP item.
2302 * Pointer to the rte_eth_dev structure.
2304 * Item specification.
2305 * @param[in] item_flags
2306 * Bit-fields that holds the items detected until now.
2308 * Pointer to error structure.
2311 * 0 on success, a negative errno value otherwise and rte_errno is set.
2314 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2315 const struct rte_flow_item *item,
2316 uint64_t item_flags,
2317 struct rte_flow_error *error)
2319 struct mlx5_priv *priv = dev->data->dev_private;
2320 const struct rte_flow_item_gtp *spec = item->spec;
2321 const struct rte_flow_item_gtp *mask = item->mask;
2322 const struct rte_flow_item_gtp nic_mask = {
2323 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
2325 .teid = RTE_BE32(0xffffffff),
2328 if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_gtp)
2329 return rte_flow_error_set(error, ENOTSUP,
2330 RTE_FLOW_ERROR_TYPE_ITEM, item,
2331 "GTP support is not enabled");
2332 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2333 return rte_flow_error_set(error, ENOTSUP,
2334 RTE_FLOW_ERROR_TYPE_ITEM, item,
2335 "multiple tunnel layers not"
2337 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2338 return rte_flow_error_set(error, EINVAL,
2339 RTE_FLOW_ERROR_TYPE_ITEM, item,
2340 "no outer UDP layer found");
2342 mask = &rte_flow_item_gtp_mask;
2343 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
2344 return rte_flow_error_set(error, ENOTSUP,
2345 RTE_FLOW_ERROR_TYPE_ITEM, item,
2346 "Match is supported for GTP"
2348 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2349 (const uint8_t *)&nic_mask,
2350 sizeof(struct rte_flow_item_gtp),
2351 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2355 * Validate GTP PSC item.
2358 * Item specification.
2359 * @param[in] last_item
2360 * Previous validated item in the pattern items.
2361 * @param[in] gtp_item
2362 * Previous GTP item specification.
2364 * Pointer to flow attributes.
2366 * Pointer to error structure.
2369 * 0 on success, a negative errno value otherwise and rte_errno is set.
2372 flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2374 const struct rte_flow_item *gtp_item,
2375 const struct rte_flow_attr *attr,
2376 struct rte_flow_error *error)
2378 const struct rte_flow_item_gtp *gtp_spec;
2379 const struct rte_flow_item_gtp *gtp_mask;
2380 const struct rte_flow_item_gtp_psc *mask;
2381 const struct rte_flow_item_gtp_psc nic_mask = {
2386 if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2387 return rte_flow_error_set
2388 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2389 "GTP PSC item must be preceded with GTP item");
2390 gtp_spec = gtp_item->spec;
2391 gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2392 /* GTP spec and E flag is requested to match zero. */
2394 (gtp_mask->v_pt_rsv_flags &
2395 ~gtp_spec->v_pt_rsv_flags & MLX5_GTP_EXT_HEADER_FLAG))
2396 return rte_flow_error_set
2397 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2398 "GTP E flag must be 1 to match GTP PSC");
2399 /* Check the flow is not created in group zero. */
2400 if (!attr->transfer && !attr->group)
2401 return rte_flow_error_set
2402 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2403 "GTP PSC is not supported for group 0");
2404 /* GTP spec is here and E flag is requested to match zero. */
2407 mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2408 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2409 (const uint8_t *)&nic_mask,
2410 sizeof(struct rte_flow_item_gtp_psc),
2411 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2415 * Validate IPV4 item.
2416 * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2417 * add specific validation of fragment_offset field,
2420 * Item specification.
2421 * @param[in] item_flags
2422 * Bit-fields that holds the items detected until now.
2424 * Pointer to error structure.
2427 * 0 on success, a negative errno value otherwise and rte_errno is set.
2430 flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
2431 const struct rte_flow_item *item,
2432 uint64_t item_flags, uint64_t last_item,
2433 uint16_t ether_type, struct rte_flow_error *error)
2436 struct mlx5_priv *priv = dev->data->dev_private;
2437 struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
2438 const struct rte_flow_item_ipv4 *spec = item->spec;
2439 const struct rte_flow_item_ipv4 *last = item->last;
2440 const struct rte_flow_item_ipv4 *mask = item->mask;
2441 rte_be16_t fragment_offset_spec = 0;
2442 rte_be16_t fragment_offset_last = 0;
2443 struct rte_flow_item_ipv4 nic_ipv4_mask = {
2445 .src_addr = RTE_BE32(0xffffffff),
2446 .dst_addr = RTE_BE32(0xffffffff),
2447 .type_of_service = 0xff,
2448 .fragment_offset = RTE_BE16(0xffff),
2449 .next_proto_id = 0xff,
2450 .time_to_live = 0xff,
2454 if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
2455 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2456 bool ihl_cap = !tunnel ?
2457 attr->outer_ipv4_ihl : attr->inner_ipv4_ihl;
2459 return rte_flow_error_set(error, ENOTSUP,
2460 RTE_FLOW_ERROR_TYPE_ITEM,
2462 "IPV4 ihl offload not supported");
2463 nic_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
2465 ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2466 ether_type, &nic_ipv4_mask,
2467 MLX5_ITEM_RANGE_ACCEPTED, error);
2471 fragment_offset_spec = spec->hdr.fragment_offset &
2472 mask->hdr.fragment_offset;
2473 if (!fragment_offset_spec)
2476 * spec and mask are valid, enforce using full mask to make sure the
2477 * complete value is used correctly.
2479 if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2480 != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2481 return rte_flow_error_set(error, EINVAL,
2482 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2483 item, "must use full mask for"
2484 " fragment_offset");
2486 * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
2487 * indicating this is 1st fragment of fragmented packet.
2488 * This is not yet supported in MLX5, return appropriate error message.
2490 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
2491 return rte_flow_error_set(error, ENOTSUP,
2492 RTE_FLOW_ERROR_TYPE_ITEM, item,
2493 "match on first fragment not "
2495 if (fragment_offset_spec && !last)
2496 return rte_flow_error_set(error, ENOTSUP,
2497 RTE_FLOW_ERROR_TYPE_ITEM, item,
2498 "specified value not supported");
2499 /* spec and last are valid, validate the specified range. */
2500 fragment_offset_last = last->hdr.fragment_offset &
2501 mask->hdr.fragment_offset;
2503 * Match on fragment_offset spec 0x2001 and last 0x3fff
2504 * means MF is 1 and frag-offset is > 0.
2505 * This packet is fragment 2nd and onward, excluding last.
2506 * This is not yet supported in MLX5, return appropriate
2509 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
2510 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2511 return rte_flow_error_set(error, ENOTSUP,
2512 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2513 last, "match on following "
2514 "fragments not supported");
2516 * Match on fragment_offset spec 0x0001 and last 0x1fff
2517 * means MF is 0 and frag-offset is > 0.
2518 * This packet is last fragment of fragmented packet.
2519 * This is not yet supported in MLX5, return appropriate
2522 if (fragment_offset_spec == RTE_BE16(1) &&
2523 fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
2524 return rte_flow_error_set(error, ENOTSUP,
2525 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2526 last, "match on last "
2527 "fragment not supported");
2529 * Match on fragment_offset spec 0x0001 and last 0x3fff
2530 * means MF and/or frag-offset is not 0.
2531 * This is a fragmented packet.
2532 * Other range values are invalid and rejected.
2534 if (!(fragment_offset_spec == RTE_BE16(1) &&
2535 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
2536 return rte_flow_error_set(error, ENOTSUP,
2537 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2538 "specified range not supported");
2543 * Validate IPV6 fragment extension item.
2546 * Item specification.
2547 * @param[in] item_flags
2548 * Bit-fields that holds the items detected until now.
2550 * Pointer to error structure.
2553 * 0 on success, a negative errno value otherwise and rte_errno is set.
2556 flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
2557 uint64_t item_flags,
2558 struct rte_flow_error *error)
2560 const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
2561 const struct rte_flow_item_ipv6_frag_ext *last = item->last;
2562 const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
2563 rte_be16_t frag_data_spec = 0;
2564 rte_be16_t frag_data_last = 0;
2565 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2566 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2567 MLX5_FLOW_LAYER_OUTER_L4;
2569 struct rte_flow_item_ipv6_frag_ext nic_mask = {
2571 .next_header = 0xff,
2572 .frag_data = RTE_BE16(0xffff),
2576 if (item_flags & l4m)
2577 return rte_flow_error_set(error, EINVAL,
2578 RTE_FLOW_ERROR_TYPE_ITEM, item,
2579 "ipv6 fragment extension item cannot "
2581 if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
2582 (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
2583 return rte_flow_error_set(error, EINVAL,
2584 RTE_FLOW_ERROR_TYPE_ITEM, item,
2585 "ipv6 fragment extension item must "
2586 "follow ipv6 item");
2588 frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
2589 if (!frag_data_spec)
2592 * spec and mask are valid, enforce using full mask to make sure the
2593 * complete value is used correctly.
2595 if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
2596 RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2597 return rte_flow_error_set(error, EINVAL,
2598 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2599 item, "must use full mask for"
2602 * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2603 * This is 1st fragment of fragmented packet.
2605 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2606 return rte_flow_error_set(error, ENOTSUP,
2607 RTE_FLOW_ERROR_TYPE_ITEM, item,
2608 "match on first fragment not "
2610 if (frag_data_spec && !last)
2611 return rte_flow_error_set(error, EINVAL,
2612 RTE_FLOW_ERROR_TYPE_ITEM, item,
2613 "specified value not supported");
2614 ret = mlx5_flow_item_acceptable
2615 (item, (const uint8_t *)mask,
2616 (const uint8_t *)&nic_mask,
2617 sizeof(struct rte_flow_item_ipv6_frag_ext),
2618 MLX5_ITEM_RANGE_ACCEPTED, error);
2621 /* spec and last are valid, validate the specified range. */
2622 frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2624 * Match on frag_data spec 0x0009 and last 0xfff9
2625 * means M is 1 and frag-offset is > 0.
2626 * This packet is fragment 2nd and onward, excluding last.
2627 * This is not yet supported in MLX5, return appropriate
2630 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2631 RTE_IPV6_EHDR_MF_MASK) &&
2632 frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2633 return rte_flow_error_set(error, ENOTSUP,
2634 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2635 last, "match on following "
2636 "fragments not supported");
2638 * Match on frag_data spec 0x0008 and last 0xfff8
2639 * means M is 0 and frag-offset is > 0.
2640 * This packet is last fragment of fragmented packet.
2641 * This is not yet supported in MLX5, return appropriate
2644 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2645 frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2646 return rte_flow_error_set(error, ENOTSUP,
2647 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2648 last, "match on last "
2649 "fragment not supported");
2650 /* Other range values are invalid and rejected. */
2651 return rte_flow_error_set(error, EINVAL,
2652 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2653 "specified range not supported");
2657 * Validate ASO CT item.
2660 * Pointer to the rte_eth_dev structure.
2662 * Item specification.
2663 * @param[in] item_flags
2664 * Pointer to bit-fields that holds the items detected until now.
2666 * Pointer to error structure.
2669 * 0 on success, a negative errno value otherwise and rte_errno is set.
2672 flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
2673 const struct rte_flow_item *item,
2674 uint64_t *item_flags,
2675 struct rte_flow_error *error)
2677 const struct rte_flow_item_conntrack *spec = item->spec;
2678 const struct rte_flow_item_conntrack *mask = item->mask;
2682 if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
2683 return rte_flow_error_set(error, EINVAL,
2684 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2685 "Only one CT is supported");
2687 mask = &rte_flow_item_conntrack_mask;
2688 flags = spec->flags & mask->flags;
2689 if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
2690 ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
2691 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
2692 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
2693 return rte_flow_error_set(error, EINVAL,
2694 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2695 "Conflict status bits");
2696 /* State change also needs to be considered. */
2697 *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
2702 * Validate the pop VLAN action.
2705 * Pointer to the rte_eth_dev structure.
2706 * @param[in] action_flags
2707 * Holds the actions detected until now.
2709 * Pointer to the pop vlan action.
2710 * @param[in] item_flags
2711 * The items found in this flow rule.
2713 * Pointer to flow attributes.
2715 * Pointer to error structure.
2718 * 0 on success, a negative errno value otherwise and rte_errno is set.
2721 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
2722 uint64_t action_flags,
2723 const struct rte_flow_action *action,
2724 uint64_t item_flags,
2725 const struct rte_flow_attr *attr,
2726 struct rte_flow_error *error)
2728 const struct mlx5_priv *priv = dev->data->dev_private;
2729 struct mlx5_dev_ctx_shared *sh = priv->sh;
2730 bool direction_error = false;
2732 if (!priv->sh->pop_vlan_action)
2733 return rte_flow_error_set(error, ENOTSUP,
2734 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2736 "pop vlan action is not supported");
2737 /* Pop VLAN is not supported in egress except for CX6 FDB mode. */
2738 if (attr->transfer) {
2739 bool fdb_tx = priv->representor_id != UINT16_MAX;
2740 bool is_cx5 = sh->steering_format_version ==
2741 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
2743 if (fdb_tx && is_cx5)
2744 direction_error = true;
2745 } else if (attr->egress) {
2746 direction_error = true;
2748 if (direction_error)
2749 return rte_flow_error_set(error, ENOTSUP,
2750 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2752 "pop vlan action not supported for egress");
2753 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
2754 return rte_flow_error_set(error, ENOTSUP,
2755 RTE_FLOW_ERROR_TYPE_ACTION, action,
2756 "no support for multiple VLAN "
2758 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
2759 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
2760 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
2761 return rte_flow_error_set(error, ENOTSUP,
2762 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2764 "cannot pop vlan after decap without "
2765 "match on inner vlan in the flow");
2766 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
2767 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
2768 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2769 return rte_flow_error_set(error, ENOTSUP,
2770 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2772 "cannot pop vlan without a "
2773 "match on (outer) vlan in the flow");
2774 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2775 return rte_flow_error_set(error, EINVAL,
2776 RTE_FLOW_ERROR_TYPE_ACTION, action,
2777 "wrong action order, port_id should "
2778 "be after pop VLAN action");
2779 if (!attr->transfer && priv->representor)
2780 return rte_flow_error_set(error, ENOTSUP,
2781 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2782 "pop vlan action for VF representor "
2783 "not supported on NIC table");
2788 * Get VLAN default info from vlan match info.
2791 * the list of item specifications.
2793 * pointer VLAN info to fill to.
2796 * 0 on success, a negative errno value otherwise and rte_errno is set.
2799 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
2800 struct rte_vlan_hdr *vlan)
2802 const struct rte_flow_item_vlan nic_mask = {
2803 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
2804 MLX5DV_FLOW_VLAN_VID_MASK),
2805 .inner_type = RTE_BE16(0xffff),
2810 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2811 int type = items->type;
2813 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
2814 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
2817 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
2818 const struct rte_flow_item_vlan *vlan_m = items->mask;
2819 const struct rte_flow_item_vlan *vlan_v = items->spec;
2821 /* If VLAN item in pattern doesn't contain data, return here. */
2826 /* Only full match values are accepted */
2827 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
2828 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
2829 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
2831 rte_be_to_cpu_16(vlan_v->tci &
2832 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
2834 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
2835 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
2836 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
2838 rte_be_to_cpu_16(vlan_v->tci &
2839 MLX5DV_FLOW_VLAN_VID_MASK_BE);
2841 if (vlan_m->inner_type == nic_mask.inner_type)
2842 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
2843 vlan_m->inner_type);
2848 * Validate the push VLAN action.
2851 * Pointer to the rte_eth_dev structure.
2852 * @param[in] action_flags
2853 * Holds the actions detected until now.
2854 * @param[in] item_flags
2855 * The items found in this flow rule.
2857 * Pointer to the action structure.
2859 * Pointer to flow attributes
2861 * Pointer to error structure.
2864 * 0 on success, a negative errno value otherwise and rte_errno is set.
2867 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
2868 uint64_t action_flags,
2869 const struct rte_flow_item_vlan *vlan_m,
2870 const struct rte_flow_action *action,
2871 const struct rte_flow_attr *attr,
2872 struct rte_flow_error *error)
2874 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
2875 const struct mlx5_priv *priv = dev->data->dev_private;
2876 struct mlx5_dev_ctx_shared *sh = priv->sh;
2877 bool direction_error = false;
2879 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
2880 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
2881 return rte_flow_error_set(error, EINVAL,
2882 RTE_FLOW_ERROR_TYPE_ACTION, action,
2883 "invalid vlan ethertype");
2884 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2885 return rte_flow_error_set(error, EINVAL,
2886 RTE_FLOW_ERROR_TYPE_ACTION, action,
2887 "wrong action order, port_id should "
2888 "be after push VLAN");
2889 /* Push VLAN is not supported in ingress except for CX6 FDB mode. */
2890 if (attr->transfer) {
2891 bool fdb_tx = priv->representor_id != UINT16_MAX;
2892 bool is_cx5 = sh->steering_format_version ==
2893 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
2895 if (!fdb_tx && is_cx5)
2896 direction_error = true;
2897 } else if (attr->ingress) {
2898 direction_error = true;
2900 if (direction_error)
2901 return rte_flow_error_set(error, ENOTSUP,
2902 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2904 "push vlan action not supported for ingress");
2905 if (!attr->transfer && priv->representor)
2906 return rte_flow_error_set(error, ENOTSUP,
2907 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2908 "push vlan action for VF representor "
2909 "not supported on NIC table");
2911 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
2912 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
2913 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
2914 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
2915 !(mlx5_flow_find_action
2916 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
2917 return rte_flow_error_set(error, EINVAL,
2918 RTE_FLOW_ERROR_TYPE_ACTION, action,
2919 "not full match mask on VLAN PCP and "
2920 "there is no of_set_vlan_pcp action, "
2921 "push VLAN action cannot figure out "
2924 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
2925 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
2926 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
2927 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
2928 !(mlx5_flow_find_action
2929 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
2930 return rte_flow_error_set(error, EINVAL,
2931 RTE_FLOW_ERROR_TYPE_ACTION, action,
2932 "not full match mask on VLAN VID and "
2933 "there is no of_set_vlan_vid action, "
2934 "push VLAN action cannot figure out "
2941 * Validate the set VLAN PCP.
2943 * @param[in] action_flags
2944 * Holds the actions detected until now.
2945 * @param[in] actions
2946 * Pointer to the list of actions remaining in the flow rule.
2948 * Pointer to error structure.
2951 * 0 on success, a negative errno value otherwise and rte_errno is set.
2954 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2955 const struct rte_flow_action actions[],
2956 struct rte_flow_error *error)
2958 const struct rte_flow_action *action = actions;
2959 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2961 if (conf->vlan_pcp > 7)
2962 return rte_flow_error_set(error, EINVAL,
2963 RTE_FLOW_ERROR_TYPE_ACTION, action,
2964 "VLAN PCP value is too big");
2965 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2966 return rte_flow_error_set(error, ENOTSUP,
2967 RTE_FLOW_ERROR_TYPE_ACTION, action,
2968 "set VLAN PCP action must follow "
2969 "the push VLAN action");
2970 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2971 return rte_flow_error_set(error, ENOTSUP,
2972 RTE_FLOW_ERROR_TYPE_ACTION, action,
2973 "Multiple VLAN PCP modification are "
2975 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2976 return rte_flow_error_set(error, EINVAL,
2977 RTE_FLOW_ERROR_TYPE_ACTION, action,
2978 "wrong action order, port_id should "
2979 "be after set VLAN PCP");
2984 * Validate the set VLAN VID.
2986 * @param[in] item_flags
2987 * Holds the items detected in this rule.
2988 * @param[in] action_flags
2989 * Holds the actions detected until now.
2990 * @param[in] actions
2991 * Pointer to the list of actions remaining in the flow rule.
2993 * Pointer to error structure.
2996 * 0 on success, a negative errno value otherwise and rte_errno is set.
2999 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3000 uint64_t action_flags,
3001 const struct rte_flow_action actions[],
3002 struct rte_flow_error *error)
3004 const struct rte_flow_action *action = actions;
3005 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3007 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3008 return rte_flow_error_set(error, EINVAL,
3009 RTE_FLOW_ERROR_TYPE_ACTION, action,
3010 "VLAN VID value is too big");
3011 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3012 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3013 return rte_flow_error_set(error, ENOTSUP,
3014 RTE_FLOW_ERROR_TYPE_ACTION, action,
3015 "set VLAN VID action must follow push"
3016 " VLAN action or match on VLAN item");
3017 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3018 return rte_flow_error_set(error, ENOTSUP,
3019 RTE_FLOW_ERROR_TYPE_ACTION, action,
3020 "Multiple VLAN VID modifications are "
3022 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3023 return rte_flow_error_set(error, EINVAL,
3024 RTE_FLOW_ERROR_TYPE_ACTION, action,
3025 "wrong action order, port_id should "
3026 "be after set VLAN VID");
3031 * Validate the FLAG action.
3034 * Pointer to the rte_eth_dev structure.
3035 * @param[in] action_flags
3036 * Holds the actions detected until now.
3038 * Pointer to flow attributes
3040 * Pointer to error structure.
3043 * 0 on success, a negative errno value otherwise and rte_errno is set.
3046 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3047 uint64_t action_flags,
3048 const struct rte_flow_attr *attr,
3049 struct rte_flow_error *error)
3051 struct mlx5_priv *priv = dev->data->dev_private;
3052 struct mlx5_sh_config *config = &priv->sh->config;
3055 /* Fall back if no extended metadata register support. */
3056 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3057 return mlx5_flow_validate_action_flag(action_flags, attr,
3059 /* Extensive metadata mode requires registers. */
3060 if (!mlx5_flow_ext_mreg_supported(dev))
3061 return rte_flow_error_set(error, ENOTSUP,
3062 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3063 "no metadata registers "
3064 "to support flag action");
3065 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3066 return rte_flow_error_set(error, ENOTSUP,
3067 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3068 "extended metadata register"
3069 " isn't available");
3070 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3073 MLX5_ASSERT(ret > 0);
3074 if (action_flags & MLX5_FLOW_ACTION_MARK)
3075 return rte_flow_error_set(error, EINVAL,
3076 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3077 "can't mark and flag in same flow");
3078 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3079 return rte_flow_error_set(error, EINVAL,
3080 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3082 " actions in same flow");
3087 * Validate MARK action.
3090 * Pointer to the rte_eth_dev structure.
3092 * Pointer to action.
3093 * @param[in] action_flags
3094 * Holds the actions detected until now.
3096 * Pointer to flow attributes
3098 * Pointer to error structure.
3101 * 0 on success, a negative errno value otherwise and rte_errno is set.
3104 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3105 const struct rte_flow_action *action,
3106 uint64_t action_flags,
3107 const struct rte_flow_attr *attr,
3108 struct rte_flow_error *error)
3110 struct mlx5_priv *priv = dev->data->dev_private;
3111 struct mlx5_sh_config *config = &priv->sh->config;
3112 const struct rte_flow_action_mark *mark = action->conf;
3115 if (is_tunnel_offload_active(dev))
3116 return rte_flow_error_set(error, ENOTSUP,
3117 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3119 "if tunnel offload active");
3120 /* Fall back if no extended metadata register support. */
3121 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3122 return mlx5_flow_validate_action_mark(action, action_flags,
3124 /* Extensive metadata mode requires registers. */
3125 if (!mlx5_flow_ext_mreg_supported(dev))
3126 return rte_flow_error_set(error, ENOTSUP,
3127 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3128 "no metadata registers "
3129 "to support mark action");
3130 if (!priv->sh->dv_mark_mask)
3131 return rte_flow_error_set(error, ENOTSUP,
3132 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3133 "extended metadata register"
3134 " isn't available");
3135 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3138 MLX5_ASSERT(ret > 0);
3140 return rte_flow_error_set(error, EINVAL,
3141 RTE_FLOW_ERROR_TYPE_ACTION, action,
3142 "configuration cannot be null");
3143 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3144 return rte_flow_error_set(error, EINVAL,
3145 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3147 "mark id exceeds the limit");
3148 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3149 return rte_flow_error_set(error, EINVAL,
3150 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3151 "can't flag and mark in same flow");
3152 if (action_flags & MLX5_FLOW_ACTION_MARK)
3153 return rte_flow_error_set(error, EINVAL,
3154 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3155 "can't have 2 mark actions in same"
3161 * Validate SET_META action.
3164 * Pointer to the rte_eth_dev structure.
3166 * Pointer to the action structure.
3167 * @param[in] action_flags
3168 * Holds the actions detected until now.
3170 * Pointer to flow attributes
3172 * Pointer to error structure.
3175 * 0 on success, a negative errno value otherwise and rte_errno is set.
3178 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3179 const struct rte_flow_action *action,
3180 uint64_t action_flags __rte_unused,
3181 const struct rte_flow_attr *attr,
3182 struct rte_flow_error *error)
3184 struct mlx5_priv *priv = dev->data->dev_private;
3185 struct mlx5_sh_config *config = &priv->sh->config;
3186 const struct rte_flow_action_set_meta *conf;
3187 uint32_t nic_mask = UINT32_MAX;
3190 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3191 !mlx5_flow_ext_mreg_supported(dev))
3192 return rte_flow_error_set(error, ENOTSUP,
3193 RTE_FLOW_ERROR_TYPE_ACTION, action,
3194 "extended metadata register"
3195 " isn't supported");
3196 reg = flow_dv_get_metadata_reg(dev, attr, error);
3200 return rte_flow_error_set(error, ENOTSUP,
3201 RTE_FLOW_ERROR_TYPE_ACTION, action,
3202 "unavailable extended metadata register");
3203 if (reg != REG_A && reg != REG_B) {
3204 struct mlx5_priv *priv = dev->data->dev_private;
3206 nic_mask = priv->sh->dv_meta_mask;
3208 if (!(action->conf))
3209 return rte_flow_error_set(error, EINVAL,
3210 RTE_FLOW_ERROR_TYPE_ACTION, action,
3211 "configuration cannot be null");
3212 conf = (const struct rte_flow_action_set_meta *)action->conf;
3214 return rte_flow_error_set(error, EINVAL,
3215 RTE_FLOW_ERROR_TYPE_ACTION, action,
3216 "zero mask doesn't have any effect");
3217 if (conf->mask & ~nic_mask)
3218 return rte_flow_error_set(error, EINVAL,
3219 RTE_FLOW_ERROR_TYPE_ACTION, action,
3220 "meta data must be within reg C0");
3225 * Validate SET_TAG action.
3228 * Pointer to the rte_eth_dev structure.
3230 * Pointer to the action structure.
3231 * @param[in] action_flags
3232 * Holds the actions detected until now.
3234 * Pointer to flow attributes
3236 * Pointer to error structure.
3239 * 0 on success, a negative errno value otherwise and rte_errno is set.
3242 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3243 const struct rte_flow_action *action,
3244 uint64_t action_flags,
3245 const struct rte_flow_attr *attr,
3246 struct rte_flow_error *error)
3248 const struct rte_flow_action_set_tag *conf;
3249 const uint64_t terminal_action_flags =
3250 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3251 MLX5_FLOW_ACTION_RSS;
3254 if (!mlx5_flow_ext_mreg_supported(dev))
3255 return rte_flow_error_set(error, ENOTSUP,
3256 RTE_FLOW_ERROR_TYPE_ACTION, action,
3257 "extensive metadata register"
3258 " isn't supported");
3259 if (!(action->conf))
3260 return rte_flow_error_set(error, EINVAL,
3261 RTE_FLOW_ERROR_TYPE_ACTION, action,
3262 "configuration cannot be null");
3263 conf = (const struct rte_flow_action_set_tag *)action->conf;
3265 return rte_flow_error_set(error, EINVAL,
3266 RTE_FLOW_ERROR_TYPE_ACTION, action,
3267 "zero mask doesn't have any effect");
3268 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3271 if (!attr->transfer && attr->ingress &&
3272 (action_flags & terminal_action_flags))
3273 return rte_flow_error_set(error, EINVAL,
3274 RTE_FLOW_ERROR_TYPE_ACTION, action,
3275 "set_tag has no effect"
3276 " with terminal actions");
3281 * Validate count action.
3284 * Pointer to rte_eth_dev structure.
3286 * Indicator if action is shared.
3287 * @param[in] action_flags
3288 * Holds the actions detected until now.
3290 * Pointer to error structure.
3293 * 0 on success, a negative errno value otherwise and rte_errno is set.
3296 flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3297 uint64_t action_flags,
3298 struct rte_flow_error *error)
3300 struct mlx5_priv *priv = dev->data->dev_private;
3302 if (!priv->sh->cdev->config.devx)
3304 if (action_flags & MLX5_FLOW_ACTION_COUNT)
3305 return rte_flow_error_set(error, EINVAL,
3306 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3307 "duplicate count actions set");
3308 if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
3309 !priv->sh->flow_hit_aso_en)
3310 return rte_flow_error_set(error, EINVAL,
3311 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3312 "old age and shared count combination is not supported");
3313 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3317 return rte_flow_error_set
3319 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3321 "count action not supported");
3325 * Validate the L2 encap action.
3328 * Pointer to the rte_eth_dev structure.
3329 * @param[in] action_flags
3330 * Holds the actions detected until now.
3332 * Pointer to the action structure.
3334 * Pointer to flow attributes.
3336 * Pointer to error structure.
3339 * 0 on success, a negative errno value otherwise and rte_errno is set.
3342 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3343 uint64_t action_flags,
3344 const struct rte_flow_action *action,
3345 const struct rte_flow_attr *attr,
3346 struct rte_flow_error *error)
3348 const struct mlx5_priv *priv = dev->data->dev_private;
3350 if (!(action->conf))
3351 return rte_flow_error_set(error, EINVAL,
3352 RTE_FLOW_ERROR_TYPE_ACTION, action,
3353 "configuration cannot be null");
3354 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3355 return rte_flow_error_set(error, EINVAL,
3356 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3357 "can only have a single encap action "
3359 if (!attr->transfer && priv->representor)
3360 return rte_flow_error_set(error, ENOTSUP,
3361 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3362 "encap action for VF representor "
3363 "not supported on NIC table");
3368 * Validate a decap action.
3371 * Pointer to the rte_eth_dev structure.
3372 * @param[in] action_flags
3373 * Holds the actions detected until now.
3375 * Pointer to the action structure.
3376 * @param[in] item_flags
3377 * Holds the items detected.
3379 * Pointer to flow attributes
3381 * Pointer to error structure.
3384 * 0 on success, a negative errno value otherwise and rte_errno is set.
3387 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3388 uint64_t action_flags,
3389 const struct rte_flow_action *action,
3390 const uint64_t item_flags,
3391 const struct rte_flow_attr *attr,
3392 struct rte_flow_error *error)
3394 const struct mlx5_priv *priv = dev->data->dev_private;
3396 if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3397 !priv->sh->config.decap_en)
3398 return rte_flow_error_set(error, ENOTSUP,
3399 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3400 "decap is not enabled");
3401 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3402 return rte_flow_error_set(error, ENOTSUP,
3403 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3405 MLX5_FLOW_ACTION_DECAP ? "can only "
3406 "have a single decap action" : "decap "
3407 "after encap is not supported");
3408 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3409 return rte_flow_error_set(error, EINVAL,
3410 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3411 "can't have decap action after"
3414 return rte_flow_error_set(error, ENOTSUP,
3415 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3417 "decap action not supported for "
3419 if (!attr->transfer && priv->representor)
3420 return rte_flow_error_set(error, ENOTSUP,
3421 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3422 "decap action for VF representor "
3423 "not supported on NIC table");
3424 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3425 !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3426 return rte_flow_error_set(error, ENOTSUP,
3427 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3428 "VXLAN item should be present for VXLAN decap");
3432 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3435 * Validate the raw encap and decap actions.
3438 * Pointer to the rte_eth_dev structure.
3440 * Pointer to the decap action.
3442 * Pointer to the encap action.
3444 * Pointer to flow attributes
3445 * @param[in/out] action_flags
3446 * Holds the actions detected until now.
3447 * @param[out] actions_n
3448 * pointer to the number of actions counter.
3450 * Pointer to the action structure.
3451 * @param[in] item_flags
3452 * Holds the items detected.
3454 * Pointer to error structure.
3457 * 0 on success, a negative errno value otherwise and rte_errno is set.
3460 flow_dv_validate_action_raw_encap_decap
3461 (struct rte_eth_dev *dev,
3462 const struct rte_flow_action_raw_decap *decap,
3463 const struct rte_flow_action_raw_encap *encap,
3464 const struct rte_flow_attr *attr, uint64_t *action_flags,
3465 int *actions_n, const struct rte_flow_action *action,
3466 uint64_t item_flags, struct rte_flow_error *error)
3468 const struct mlx5_priv *priv = dev->data->dev_private;
3471 if (encap && (!encap->size || !encap->data))
3472 return rte_flow_error_set(error, EINVAL,
3473 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3474 "raw encap data cannot be empty");
3475 if (decap && encap) {
3476 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3477 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3480 else if (encap->size <=
3481 MLX5_ENCAPSULATION_DECISION_SIZE &&
3483 MLX5_ENCAPSULATION_DECISION_SIZE)
3486 else if (encap->size >
3487 MLX5_ENCAPSULATION_DECISION_SIZE &&
3489 MLX5_ENCAPSULATION_DECISION_SIZE)
3490 /* 2 L2 actions: encap and decap. */
3493 return rte_flow_error_set(error,
3495 RTE_FLOW_ERROR_TYPE_ACTION,
3496 NULL, "unsupported too small "
3497 "raw decap and too small raw "
3498 "encap combination");
3501 ret = flow_dv_validate_action_decap(dev, *action_flags, action,
3502 item_flags, attr, error);
3505 *action_flags |= MLX5_FLOW_ACTION_DECAP;
3509 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
3510 return rte_flow_error_set(error, ENOTSUP,
3511 RTE_FLOW_ERROR_TYPE_ACTION,
3513 "small raw encap size");
3514 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
3515 return rte_flow_error_set(error, EINVAL,
3516 RTE_FLOW_ERROR_TYPE_ACTION,
3518 "more than one encap action");
3519 if (!attr->transfer && priv->representor)
3520 return rte_flow_error_set
3522 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3523 "encap action for VF representor "
3524 "not supported on NIC table");
3525 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
3532 * Validate the ASO CT action.
3535 * Pointer to the rte_eth_dev structure.
3536 * @param[in] action_flags
3537 * Holds the actions detected until now.
3538 * @param[in] item_flags
3539 * The items found in this flow rule.
3541 * Pointer to flow attributes.
3543 * Pointer to error structure.
3546 * 0 on success, a negative errno value otherwise and rte_errno is set.
3549 flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
3550 uint64_t action_flags,
3551 uint64_t item_flags,
3552 const struct rte_flow_attr *attr,
3553 struct rte_flow_error *error)
3557 if (attr->group == 0 && !attr->transfer)
3558 return rte_flow_error_set(error, ENOTSUP,
3559 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3561 "Only support non-root table");
3562 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
3563 return rte_flow_error_set(error, ENOTSUP,
3564 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3565 "CT cannot follow a fate action");
3566 if ((action_flags & MLX5_FLOW_ACTION_METER) ||
3567 (action_flags & MLX5_FLOW_ACTION_AGE))
3568 return rte_flow_error_set(error, EINVAL,
3569 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3570 "Only one ASO action is supported");
3571 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3572 return rte_flow_error_set(error, EINVAL,
3573 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3574 "Encap cannot exist before CT");
3575 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3576 return rte_flow_error_set(error, EINVAL,
3577 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3578 "Not a outer TCP packet");
3583 flow_dv_encap_decap_match_cb(void *tool_ctx __rte_unused,
3584 struct mlx5_list_entry *entry, void *cb_ctx)
3586 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3587 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3588 struct mlx5_flow_dv_encap_decap_resource *resource;
3590 resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
3592 if (resource->reformat_type == ctx_resource->reformat_type &&
3593 resource->ft_type == ctx_resource->ft_type &&
3594 resource->flags == ctx_resource->flags &&
3595 resource->size == ctx_resource->size &&
3596 !memcmp((const void *)resource->buf,
3597 (const void *)ctx_resource->buf,
3603 struct mlx5_list_entry *
3604 flow_dv_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
3606 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3607 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3608 struct mlx5dv_dr_domain *domain;
3609 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3610 struct mlx5_flow_dv_encap_decap_resource *resource;
3614 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3615 domain = sh->fdb_domain;
3616 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3617 domain = sh->rx_domain;
3619 domain = sh->tx_domain;
3620 /* Register new encap/decap resource. */
3621 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
3623 rte_flow_error_set(ctx->error, ENOMEM,
3624 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3625 "cannot allocate resource memory");
3628 *resource = *ctx_resource;
3629 resource->idx = idx;
3630 ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
3634 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
3635 rte_flow_error_set(ctx->error, ENOMEM,
3636 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3637 NULL, "cannot create action");
3641 return &resource->entry;
3644 struct mlx5_list_entry *
3645 flow_dv_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
3648 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3649 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3650 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3653 cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
3655 if (!cache_resource) {
3656 rte_flow_error_set(ctx->error, ENOMEM,
3657 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3658 "cannot allocate resource memory");
3661 memcpy(cache_resource, oentry, sizeof(*cache_resource));
3662 cache_resource->idx = idx;
3663 return &cache_resource->entry;
3667 flow_dv_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3669 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3670 struct mlx5_flow_dv_encap_decap_resource *res =
3671 container_of(entry, typeof(*res), entry);
3673 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
3677 * Find existing encap/decap resource or create and register a new one.
3679 * @param[in, out] dev
3680 * Pointer to rte_eth_dev structure.
3681 * @param[in, out] resource
3682 * Pointer to encap/decap resource.
3683 * @parm[in, out] dev_flow
3684 * Pointer to the dev_flow.
3686 * pointer to error structure.
3689 * 0 on success otherwise -errno and errno is set.
3692 flow_dv_encap_decap_resource_register
3693 (struct rte_eth_dev *dev,
3694 struct mlx5_flow_dv_encap_decap_resource *resource,
3695 struct mlx5_flow *dev_flow,
3696 struct rte_flow_error *error)
3698 struct mlx5_priv *priv = dev->data->dev_private;
3699 struct mlx5_dev_ctx_shared *sh = priv->sh;
3700 struct mlx5_list_entry *entry;
3704 uint32_t refmt_type:8;
3706 * Header reformat actions can be shared between
3707 * non-root tables. One bit to indicate non-root
3711 uint32_t reserve:15;
3714 } encap_decap_key = {
3716 .ft_type = resource->ft_type,
3717 .refmt_type = resource->reformat_type,
3718 .is_root = !!dev_flow->dv.group,
3722 struct mlx5_flow_cb_ctx ctx = {
3726 struct mlx5_hlist *encaps_decaps;
3729 encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
3731 MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
3733 flow_dv_encap_decap_create_cb,
3734 flow_dv_encap_decap_match_cb,
3735 flow_dv_encap_decap_remove_cb,
3736 flow_dv_encap_decap_clone_cb,
3737 flow_dv_encap_decap_clone_free_cb,
3739 if (unlikely(!encaps_decaps))
3741 resource->flags = dev_flow->dv.group ? 0 : 1;
3742 key64 = __rte_raw_cksum(&encap_decap_key.v32,
3743 sizeof(encap_decap_key.v32), 0);
3744 if (resource->reformat_type !=
3745 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
3747 key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
3748 entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
3751 resource = container_of(entry, typeof(*resource), entry);
3752 dev_flow->dv.encap_decap = resource;
3753 dev_flow->handle->dvh.rix_encap_decap = resource->idx;
3758 * Find existing table jump resource or create and register a new one.
3760 * @param[in, out] dev
3761 * Pointer to rte_eth_dev structure.
3762 * @param[in, out] tbl
3763 * Pointer to flow table resource.
3764 * @parm[in, out] dev_flow
3765 * Pointer to the dev_flow.
3767 * pointer to error structure.
3770 * 0 on success otherwise -errno and errno is set.
3773 flow_dv_jump_tbl_resource_register
3774 (struct rte_eth_dev *dev __rte_unused,
3775 struct mlx5_flow_tbl_resource *tbl,
3776 struct mlx5_flow *dev_flow,
3777 struct rte_flow_error *error __rte_unused)
3779 struct mlx5_flow_tbl_data_entry *tbl_data =
3780 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
3783 MLX5_ASSERT(tbl_data->jump.action);
3784 dev_flow->handle->rix_jump = tbl_data->idx;
3785 dev_flow->dv.jump = &tbl_data->jump;
3790 flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
3791 struct mlx5_list_entry *entry, void *cb_ctx)
3793 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3794 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3795 struct mlx5_flow_dv_port_id_action_resource *res =
3796 container_of(entry, typeof(*res), entry);
3798 return ref->port_id != res->port_id;
3801 struct mlx5_list_entry *
3802 flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
3804 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3805 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3806 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3807 struct mlx5_flow_dv_port_id_action_resource *resource;
3811 /* Register new port id action resource. */
3812 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3814 rte_flow_error_set(ctx->error, ENOMEM,
3815 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3816 "cannot allocate port_id action memory");
3820 ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
3824 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
3825 rte_flow_error_set(ctx->error, ENOMEM,
3826 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3827 "cannot create action");
3830 resource->idx = idx;
3831 return &resource->entry;
3834 struct mlx5_list_entry *
3835 flow_dv_port_id_clone_cb(void *tool_ctx,
3836 struct mlx5_list_entry *entry __rte_unused,
3839 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3840 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3841 struct mlx5_flow_dv_port_id_action_resource *resource;
3844 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3846 rte_flow_error_set(ctx->error, ENOMEM,
3847 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3848 "cannot allocate port_id action memory");
3851 memcpy(resource, entry, sizeof(*resource));
3852 resource->idx = idx;
3853 return &resource->entry;
3857 flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3859 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3860 struct mlx5_flow_dv_port_id_action_resource *resource =
3861 container_of(entry, typeof(*resource), entry);
3863 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
3867 * Find existing table port ID resource or create and register a new one.
3869 * @param[in, out] dev
3870 * Pointer to rte_eth_dev structure.
3871 * @param[in, out] ref
3872 * Pointer to port ID action resource reference.
3873 * @parm[in, out] dev_flow
3874 * Pointer to the dev_flow.
3876 * pointer to error structure.
3879 * 0 on success otherwise -errno and errno is set.
3882 flow_dv_port_id_action_resource_register
3883 (struct rte_eth_dev *dev,
3884 struct mlx5_flow_dv_port_id_action_resource *ref,
3885 struct mlx5_flow *dev_flow,
3886 struct rte_flow_error *error)
3888 struct mlx5_priv *priv = dev->data->dev_private;
3889 struct mlx5_list_entry *entry;
3890 struct mlx5_flow_dv_port_id_action_resource *resource;
3891 struct mlx5_flow_cb_ctx ctx = {
3896 entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
3899 resource = container_of(entry, typeof(*resource), entry);
3900 dev_flow->dv.port_id_action = resource;
3901 dev_flow->handle->rix_port_id_action = resource->idx;
3906 flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
3907 struct mlx5_list_entry *entry, void *cb_ctx)
3909 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3910 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3911 struct mlx5_flow_dv_push_vlan_action_resource *res =
3912 container_of(entry, typeof(*res), entry);
3914 return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
3917 struct mlx5_list_entry *
3918 flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
3920 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3921 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3922 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3923 struct mlx5_flow_dv_push_vlan_action_resource *resource;
3924 struct mlx5dv_dr_domain *domain;
3928 /* Register new port id action resource. */
3929 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3931 rte_flow_error_set(ctx->error, ENOMEM,
3932 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3933 "cannot allocate push_vlan action memory");
3937 if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3938 domain = sh->fdb_domain;
3939 else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3940 domain = sh->rx_domain;
3942 domain = sh->tx_domain;
3943 ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
3946 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
3947 rte_flow_error_set(ctx->error, ENOMEM,
3948 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3949 "cannot create push vlan action");
3952 resource->idx = idx;
3953 return &resource->entry;
3956 struct mlx5_list_entry *
3957 flow_dv_push_vlan_clone_cb(void *tool_ctx,
3958 struct mlx5_list_entry *entry __rte_unused,
3961 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3962 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3963 struct mlx5_flow_dv_push_vlan_action_resource *resource;
3966 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3968 rte_flow_error_set(ctx->error, ENOMEM,
3969 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3970 "cannot allocate push_vlan action memory");
3973 memcpy(resource, entry, sizeof(*resource));
3974 resource->idx = idx;
3975 return &resource->entry;
3979 flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3981 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3982 struct mlx5_flow_dv_push_vlan_action_resource *resource =
3983 container_of(entry, typeof(*resource), entry);
3985 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
3989 * Find existing push vlan resource or create and register a new one.
3991 * @param [in, out] dev
3992 * Pointer to rte_eth_dev structure.
3993 * @param[in, out] ref
3994 * Pointer to port ID action resource reference.
3995 * @parm[in, out] dev_flow
3996 * Pointer to the dev_flow.
3998 * pointer to error structure.
4001 * 0 on success otherwise -errno and errno is set.
4004 flow_dv_push_vlan_action_resource_register
4005 (struct rte_eth_dev *dev,
4006 struct mlx5_flow_dv_push_vlan_action_resource *ref,
4007 struct mlx5_flow *dev_flow,
4008 struct rte_flow_error *error)
4010 struct mlx5_priv *priv = dev->data->dev_private;
4011 struct mlx5_flow_dv_push_vlan_action_resource *resource;
4012 struct mlx5_list_entry *entry;
4013 struct mlx5_flow_cb_ctx ctx = {
4018 entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4021 resource = container_of(entry, typeof(*resource), entry);
4023 dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4024 dev_flow->dv.push_vlan_res = resource;
4029 * Get the size of specific rte_flow_item_type hdr size
4031 * @param[in] item_type
4032 * Tested rte_flow_item_type.
4035 * sizeof struct item_type, 0 if void or irrelevant.
4038 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4042 switch (item_type) {
4043 case RTE_FLOW_ITEM_TYPE_ETH:
4044 retval = sizeof(struct rte_ether_hdr);
4046 case RTE_FLOW_ITEM_TYPE_VLAN:
4047 retval = sizeof(struct rte_vlan_hdr);
4049 case RTE_FLOW_ITEM_TYPE_IPV4:
4050 retval = sizeof(struct rte_ipv4_hdr);
4052 case RTE_FLOW_ITEM_TYPE_IPV6:
4053 retval = sizeof(struct rte_ipv6_hdr);
4055 case RTE_FLOW_ITEM_TYPE_UDP:
4056 retval = sizeof(struct rte_udp_hdr);
4058 case RTE_FLOW_ITEM_TYPE_TCP:
4059 retval = sizeof(struct rte_tcp_hdr);
4061 case RTE_FLOW_ITEM_TYPE_VXLAN:
4062 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4063 retval = sizeof(struct rte_vxlan_hdr);
4065 case RTE_FLOW_ITEM_TYPE_GRE:
4066 case RTE_FLOW_ITEM_TYPE_NVGRE:
4067 retval = sizeof(struct rte_gre_hdr);
4069 case RTE_FLOW_ITEM_TYPE_MPLS:
4070 retval = sizeof(struct rte_mpls_hdr);
4072 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4080 #define MLX5_ENCAP_IPV4_VERSION 0x40
4081 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4082 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4083 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4084 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4085 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4086 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4089 * Convert the encap action data from list of rte_flow_item to raw buffer
4092 * Pointer to rte_flow_item objects list.
4094 * Pointer to the output buffer.
4096 * Pointer to the output buffer size.
4098 * Pointer to the error structure.
4101 * 0 on success, a negative errno value otherwise and rte_errno is set.
4104 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4105 size_t *size, struct rte_flow_error *error)
4107 struct rte_ether_hdr *eth = NULL;
4108 struct rte_vlan_hdr *vlan = NULL;
4109 struct rte_ipv4_hdr *ipv4 = NULL;
4110 struct rte_ipv6_hdr *ipv6 = NULL;
4111 struct rte_udp_hdr *udp = NULL;
4112 struct rte_vxlan_hdr *vxlan = NULL;
4113 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4114 struct rte_gre_hdr *gre = NULL;
4116 size_t temp_size = 0;
4119 return rte_flow_error_set(error, EINVAL,
4120 RTE_FLOW_ERROR_TYPE_ACTION,
4121 NULL, "invalid empty data");
4122 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4123 len = flow_dv_get_item_hdr_len(items->type);
4124 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4125 return rte_flow_error_set(error, EINVAL,
4126 RTE_FLOW_ERROR_TYPE_ACTION,
4127 (void *)items->type,
4128 "items total size is too big"
4129 " for encap action");
4130 rte_memcpy((void *)&buf[temp_size], items->spec, len);
4131 switch (items->type) {
4132 case RTE_FLOW_ITEM_TYPE_ETH:
4133 eth = (struct rte_ether_hdr *)&buf[temp_size];
4135 case RTE_FLOW_ITEM_TYPE_VLAN:
4136 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4138 return rte_flow_error_set(error, EINVAL,
4139 RTE_FLOW_ERROR_TYPE_ACTION,
4140 (void *)items->type,
4141 "eth header not found");
4142 if (!eth->ether_type)
4143 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4145 case RTE_FLOW_ITEM_TYPE_IPV4:
4146 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4148 return rte_flow_error_set(error, EINVAL,
4149 RTE_FLOW_ERROR_TYPE_ACTION,
4150 (void *)items->type,
4151 "neither eth nor vlan"
4153 if (vlan && !vlan->eth_proto)
4154 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4155 else if (eth && !eth->ether_type)
4156 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4157 if (!ipv4->version_ihl)
4158 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4159 MLX5_ENCAP_IPV4_IHL_MIN;
4160 if (!ipv4->time_to_live)
4161 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4163 case RTE_FLOW_ITEM_TYPE_IPV6:
4164 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4166 return rte_flow_error_set(error, EINVAL,
4167 RTE_FLOW_ERROR_TYPE_ACTION,
4168 (void *)items->type,
4169 "neither eth nor vlan"
4171 if (vlan && !vlan->eth_proto)
4172 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4173 else if (eth && !eth->ether_type)
4174 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4175 if (!ipv6->vtc_flow)
4177 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4178 if (!ipv6->hop_limits)
4179 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4181 case RTE_FLOW_ITEM_TYPE_UDP:
4182 udp = (struct rte_udp_hdr *)&buf[temp_size];
4184 return rte_flow_error_set(error, EINVAL,
4185 RTE_FLOW_ERROR_TYPE_ACTION,
4186 (void *)items->type,
4187 "ip header not found");
4188 if (ipv4 && !ipv4->next_proto_id)
4189 ipv4->next_proto_id = IPPROTO_UDP;
4190 else if (ipv6 && !ipv6->proto)
4191 ipv6->proto = IPPROTO_UDP;
4193 case RTE_FLOW_ITEM_TYPE_VXLAN:
4194 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4196 return rte_flow_error_set(error, EINVAL,
4197 RTE_FLOW_ERROR_TYPE_ACTION,
4198 (void *)items->type,
4199 "udp header not found");
4201 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4202 if (!vxlan->vx_flags)
4204 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4206 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4207 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4209 return rte_flow_error_set(error, EINVAL,
4210 RTE_FLOW_ERROR_TYPE_ACTION,
4211 (void *)items->type,
4212 "udp header not found");
4213 if (!vxlan_gpe->proto)
4214 return rte_flow_error_set(error, EINVAL,
4215 RTE_FLOW_ERROR_TYPE_ACTION,
4216 (void *)items->type,
4217 "next protocol not found");
4220 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4221 if (!vxlan_gpe->vx_flags)
4222 vxlan_gpe->vx_flags =
4223 MLX5_ENCAP_VXLAN_GPE_FLAGS;
4225 case RTE_FLOW_ITEM_TYPE_GRE:
4226 case RTE_FLOW_ITEM_TYPE_NVGRE:
4227 gre = (struct rte_gre_hdr *)&buf[temp_size];
4229 return rte_flow_error_set(error, EINVAL,
4230 RTE_FLOW_ERROR_TYPE_ACTION,
4231 (void *)items->type,
4232 "next protocol not found");
4234 return rte_flow_error_set(error, EINVAL,
4235 RTE_FLOW_ERROR_TYPE_ACTION,
4236 (void *)items->type,
4237 "ip header not found");
4238 if (ipv4 && !ipv4->next_proto_id)
4239 ipv4->next_proto_id = IPPROTO_GRE;
4240 else if (ipv6 && !ipv6->proto)
4241 ipv6->proto = IPPROTO_GRE;
4243 case RTE_FLOW_ITEM_TYPE_VOID:
4246 return rte_flow_error_set(error, EINVAL,
4247 RTE_FLOW_ERROR_TYPE_ACTION,
4248 (void *)items->type,
4249 "unsupported item type");
4259 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4261 struct rte_ether_hdr *eth = NULL;
4262 struct rte_vlan_hdr *vlan = NULL;
4263 struct rte_ipv6_hdr *ipv6 = NULL;
4264 struct rte_udp_hdr *udp = NULL;
4268 eth = (struct rte_ether_hdr *)data;
4269 next_hdr = (char *)(eth + 1);
4270 proto = RTE_BE16(eth->ether_type);
4273 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4274 vlan = (struct rte_vlan_hdr *)next_hdr;
4275 proto = RTE_BE16(vlan->eth_proto);
4276 next_hdr += sizeof(struct rte_vlan_hdr);
4279 /* HW calculates IPv4 csum. no need to proceed */
4280 if (proto == RTE_ETHER_TYPE_IPV4)
4283 /* non IPv4/IPv6 header. not supported */
4284 if (proto != RTE_ETHER_TYPE_IPV6) {
4285 return rte_flow_error_set(error, ENOTSUP,
4286 RTE_FLOW_ERROR_TYPE_ACTION,
4287 NULL, "Cannot offload non IPv4/IPv6");
4290 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4292 /* ignore non UDP */
4293 if (ipv6->proto != IPPROTO_UDP)
4296 udp = (struct rte_udp_hdr *)(ipv6 + 1);
4297 udp->dgram_cksum = 0;
4303 * Convert L2 encap action to DV specification.
4306 * Pointer to rte_eth_dev structure.
4308 * Pointer to action structure.
4309 * @param[in, out] dev_flow
4310 * Pointer to the mlx5_flow.
4311 * @param[in] transfer
4312 * Mark if the flow is E-Switch flow.
4314 * Pointer to the error structure.
4317 * 0 on success, a negative errno value otherwise and rte_errno is set.
4320 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4321 const struct rte_flow_action *action,
4322 struct mlx5_flow *dev_flow,
4324 struct rte_flow_error *error)
4326 const struct rte_flow_item *encap_data;
4327 const struct rte_flow_action_raw_encap *raw_encap_data;
4328 struct mlx5_flow_dv_encap_decap_resource res = {
4330 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4331 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4332 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4335 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4337 (const struct rte_flow_action_raw_encap *)action->conf;
4338 res.size = raw_encap_data->size;
4339 memcpy(res.buf, raw_encap_data->data, res.size);
4341 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4343 ((const struct rte_flow_action_vxlan_encap *)
4344 action->conf)->definition;
4347 ((const struct rte_flow_action_nvgre_encap *)
4348 action->conf)->definition;
4349 if (flow_dv_convert_encap_data(encap_data, res.buf,
4353 if (flow_dv_zero_encap_udp_csum(res.buf, error))
4355 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4356 return rte_flow_error_set(error, EINVAL,
4357 RTE_FLOW_ERROR_TYPE_ACTION,
4358 NULL, "can't create L2 encap action");
4363 * Convert L2 decap action to DV specification.
4366 * Pointer to rte_eth_dev structure.
4367 * @param[in, out] dev_flow
4368 * Pointer to the mlx5_flow.
4369 * @param[in] transfer
4370 * Mark if the flow is E-Switch flow.
4372 * Pointer to the error structure.
4375 * 0 on success, a negative errno value otherwise and rte_errno is set.
4378 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
4379 struct mlx5_flow *dev_flow,
4381 struct rte_flow_error *error)
4383 struct mlx5_flow_dv_encap_decap_resource res = {
4386 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
4387 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4388 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
4391 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4392 return rte_flow_error_set(error, EINVAL,
4393 RTE_FLOW_ERROR_TYPE_ACTION,
4394 NULL, "can't create L2 decap action");
4399 * Convert raw decap/encap (L3 tunnel) action to DV specification.
4402 * Pointer to rte_eth_dev structure.
4404 * Pointer to action structure.
4405 * @param[in, out] dev_flow
4406 * Pointer to the mlx5_flow.
4408 * Pointer to the flow attributes.
4410 * Pointer to the error structure.
4413 * 0 on success, a negative errno value otherwise and rte_errno is set.
4416 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
4417 const struct rte_flow_action *action,
4418 struct mlx5_flow *dev_flow,
4419 const struct rte_flow_attr *attr,
4420 struct rte_flow_error *error)
4422 const struct rte_flow_action_raw_encap *encap_data;
4423 struct mlx5_flow_dv_encap_decap_resource res;
4425 memset(&res, 0, sizeof(res));
4426 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
4427 res.size = encap_data->size;
4428 memcpy(res.buf, encap_data->data, res.size);
4429 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
4430 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
4431 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
4433 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4435 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4436 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4437 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4438 return rte_flow_error_set(error, EINVAL,
4439 RTE_FLOW_ERROR_TYPE_ACTION,
4440 NULL, "can't create encap action");
4445 * Create action push VLAN.
4448 * Pointer to rte_eth_dev structure.
4450 * Pointer to the flow attributes.
4452 * Pointer to the vlan to push to the Ethernet header.
4453 * @param[in, out] dev_flow
4454 * Pointer to the mlx5_flow.
4456 * Pointer to the error structure.
4459 * 0 on success, a negative errno value otherwise and rte_errno is set.
4462 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
4463 const struct rte_flow_attr *attr,
4464 const struct rte_vlan_hdr *vlan,
4465 struct mlx5_flow *dev_flow,
4466 struct rte_flow_error *error)
4468 struct mlx5_flow_dv_push_vlan_action_resource res;
4470 memset(&res, 0, sizeof(res));
4472 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
4475 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4477 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4478 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4479 return flow_dv_push_vlan_action_resource_register
4480 (dev, &res, dev_flow, error);
4484 * Validate the modify-header actions.
4486 * @param[in] action_flags
4487 * Holds the actions detected until now.
4489 * Pointer to the modify action.
4491 * Pointer to error structure.
4494 * 0 on success, a negative errno value otherwise and rte_errno is set.
4497 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
4498 const struct rte_flow_action *action,
4499 struct rte_flow_error *error)
4501 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
4502 return rte_flow_error_set(error, EINVAL,
4503 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4504 NULL, "action configuration not set");
4505 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4506 return rte_flow_error_set(error, EINVAL,
4507 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4508 "can't have encap action before"
4514 * Validate the modify-header MAC address actions.
4516 * @param[in] action_flags
4517 * Holds the actions detected until now.
4519 * Pointer to the modify action.
4520 * @param[in] item_flags
4521 * Holds the items detected.
4523 * Pointer to error structure.
4526 * 0 on success, a negative errno value otherwise and rte_errno is set.
4529 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
4530 const struct rte_flow_action *action,
4531 const uint64_t item_flags,
4532 struct rte_flow_error *error)
4536 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4538 if (!(item_flags & MLX5_FLOW_LAYER_L2))
4539 return rte_flow_error_set(error, EINVAL,
4540 RTE_FLOW_ERROR_TYPE_ACTION,
4542 "no L2 item in pattern");
4548 * Validate the modify-header IPv4 address actions.
4550 * @param[in] action_flags
4551 * Holds the actions detected until now.
4553 * Pointer to the modify action.
4554 * @param[in] item_flags
4555 * Holds the items detected.
4557 * Pointer to error structure.
4560 * 0 on success, a negative errno value otherwise and rte_errno is set.
4563 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
4564 const struct rte_flow_action *action,
4565 const uint64_t item_flags,
4566 struct rte_flow_error *error)
4571 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4573 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4574 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4575 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4576 if (!(item_flags & layer))
4577 return rte_flow_error_set(error, EINVAL,
4578 RTE_FLOW_ERROR_TYPE_ACTION,
4580 "no ipv4 item in pattern");
4586 * Validate the modify-header IPv6 address actions.
4588 * @param[in] action_flags
4589 * Holds the actions detected until now.
4591 * Pointer to the modify action.
4592 * @param[in] item_flags
4593 * Holds the items detected.
4595 * Pointer to error structure.
4598 * 0 on success, a negative errno value otherwise and rte_errno is set.
4601 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
4602 const struct rte_flow_action *action,
4603 const uint64_t item_flags,
4604 struct rte_flow_error *error)
4609 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4611 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4612 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4613 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4614 if (!(item_flags & layer))
4615 return rte_flow_error_set(error, EINVAL,
4616 RTE_FLOW_ERROR_TYPE_ACTION,
4618 "no ipv6 item in pattern");
4624 * Validate the modify-header TP actions.
4626 * @param[in] action_flags
4627 * Holds the actions detected until now.
4629 * Pointer to the modify action.
4630 * @param[in] item_flags
4631 * Holds the items detected.
4633 * Pointer to error structure.
4636 * 0 on success, a negative errno value otherwise and rte_errno is set.
4639 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
4640 const struct rte_flow_action *action,
4641 const uint64_t item_flags,
4642 struct rte_flow_error *error)
4647 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4649 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4650 MLX5_FLOW_LAYER_INNER_L4 :
4651 MLX5_FLOW_LAYER_OUTER_L4;
4652 if (!(item_flags & layer))
4653 return rte_flow_error_set(error, EINVAL,
4654 RTE_FLOW_ERROR_TYPE_ACTION,
4655 NULL, "no transport layer "
4662 * Validate the modify-header actions of increment/decrement
4663 * TCP Sequence-number.
4665 * @param[in] action_flags
4666 * Holds the actions detected until now.
4668 * Pointer to the modify action.
4669 * @param[in] item_flags
4670 * Holds the items detected.
4672 * Pointer to error structure.
4675 * 0 on success, a negative errno value otherwise and rte_errno is set.
4678 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
4679 const struct rte_flow_action *action,
4680 const uint64_t item_flags,
4681 struct rte_flow_error *error)
4686 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4688 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4689 MLX5_FLOW_LAYER_INNER_L4_TCP :
4690 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4691 if (!(item_flags & layer))
4692 return rte_flow_error_set(error, EINVAL,
4693 RTE_FLOW_ERROR_TYPE_ACTION,
4694 NULL, "no TCP item in"
4696 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
4697 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
4698 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
4699 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
4700 return rte_flow_error_set(error, EINVAL,
4701 RTE_FLOW_ERROR_TYPE_ACTION,
4703 "cannot decrease and increase"
4704 " TCP sequence number"
4705 " at the same time");
4711 * Validate the modify-header actions of increment/decrement
4712 * TCP Acknowledgment number.
4714 * @param[in] action_flags
4715 * Holds the actions detected until now.
4717 * Pointer to the modify action.
4718 * @param[in] item_flags
4719 * Holds the items detected.
4721 * Pointer to error structure.
4724 * 0 on success, a negative errno value otherwise and rte_errno is set.
4727 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
4728 const struct rte_flow_action *action,
4729 const uint64_t item_flags,
4730 struct rte_flow_error *error)
4735 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4737 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4738 MLX5_FLOW_LAYER_INNER_L4_TCP :
4739 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4740 if (!(item_flags & layer))
4741 return rte_flow_error_set(error, EINVAL,
4742 RTE_FLOW_ERROR_TYPE_ACTION,
4743 NULL, "no TCP item in"
4745 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
4746 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
4747 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
4748 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
4749 return rte_flow_error_set(error, EINVAL,
4750 RTE_FLOW_ERROR_TYPE_ACTION,
4752 "cannot decrease and increase"
4753 " TCP acknowledgment number"
4754 " at the same time");
4760 * Validate the modify-header TTL actions.
4762 * @param[in] action_flags
4763 * Holds the actions detected until now.
4765 * Pointer to the modify action.
4766 * @param[in] item_flags
4767 * Holds the items detected.
4769 * Pointer to error structure.
4772 * 0 on success, a negative errno value otherwise and rte_errno is set.
4775 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
4776 const struct rte_flow_action *action,
4777 const uint64_t item_flags,
4778 struct rte_flow_error *error)
4783 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4785 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4786 MLX5_FLOW_LAYER_INNER_L3 :
4787 MLX5_FLOW_LAYER_OUTER_L3;
4788 if (!(item_flags & layer))
4789 return rte_flow_error_set(error, EINVAL,
4790 RTE_FLOW_ERROR_TYPE_ACTION,
4792 "no IP protocol in pattern");
4798 * Validate the generic modify field actions.
4800 * Pointer to the rte_eth_dev structure.
4801 * @param[in] action_flags
4802 * Holds the actions detected until now.
4804 * Pointer to the modify action.
4806 * Pointer to the flow attributes.
4808 * Pointer to error structure.
4811 * Number of header fields to modify (0 or more) on success,
4812 * a negative errno value otherwise and rte_errno is set.
4815 flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
4816 const uint64_t action_flags,
4817 const struct rte_flow_action *action,
4818 const struct rte_flow_attr *attr,
4819 struct rte_flow_error *error)
4822 struct mlx5_priv *priv = dev->data->dev_private;
4823 struct mlx5_sh_config *config = &priv->sh->config;
4824 const struct rte_flow_action_modify_field *action_modify_field =
4826 uint32_t dst_width = mlx5_flow_item_field_width(dev,
4827 action_modify_field->dst.field,
4829 uint32_t src_width = mlx5_flow_item_field_width(dev,
4830 action_modify_field->src.field,
4831 dst_width, attr, error);
4833 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4837 if (action_modify_field->width == 0)
4838 return rte_flow_error_set(error, EINVAL,
4839 RTE_FLOW_ERROR_TYPE_ACTION, action,
4840 "no bits are requested to be modified");
4841 else if (action_modify_field->width > dst_width ||
4842 action_modify_field->width > src_width)
4843 return rte_flow_error_set(error, EINVAL,
4844 RTE_FLOW_ERROR_TYPE_ACTION, action,
4845 "cannot modify more bits than"
4846 " the width of a field");
4847 if (action_modify_field->dst.field != RTE_FLOW_FIELD_VALUE &&
4848 action_modify_field->dst.field != RTE_FLOW_FIELD_POINTER) {
4849 if ((action_modify_field->dst.offset +
4850 action_modify_field->width > dst_width) ||
4851 (action_modify_field->dst.offset % 32))
4852 return rte_flow_error_set(error, EINVAL,
4853 RTE_FLOW_ERROR_TYPE_ACTION, action,
4854 "destination offset is too big"
4855 " or not aligned to 4 bytes");
4856 if (action_modify_field->dst.level &&
4857 action_modify_field->dst.field != RTE_FLOW_FIELD_TAG)
4858 return rte_flow_error_set(error, ENOTSUP,
4859 RTE_FLOW_ERROR_TYPE_ACTION, action,
4860 "inner header fields modification"
4861 " is not supported");
4863 if (action_modify_field->src.field != RTE_FLOW_FIELD_VALUE &&
4864 action_modify_field->src.field != RTE_FLOW_FIELD_POINTER) {
4865 if (!attr->transfer && !attr->group)
4866 return rte_flow_error_set(error, ENOTSUP,
4867 RTE_FLOW_ERROR_TYPE_ACTION, action,
4868 "modify field action is not"
4869 " supported for group 0");
4870 if ((action_modify_field->src.offset +
4871 action_modify_field->width > src_width) ||
4872 (action_modify_field->src.offset % 32))
4873 return rte_flow_error_set(error, EINVAL,
4874 RTE_FLOW_ERROR_TYPE_ACTION, action,
4875 "source offset is too big"
4876 " or not aligned to 4 bytes");
4877 if (action_modify_field->src.level &&
4878 action_modify_field->src.field != RTE_FLOW_FIELD_TAG)
4879 return rte_flow_error_set(error, ENOTSUP,
4880 RTE_FLOW_ERROR_TYPE_ACTION, action,
4881 "inner header fields modification"
4882 " is not supported");
4884 if ((action_modify_field->dst.field ==
4885 action_modify_field->src.field) &&
4886 (action_modify_field->dst.level ==
4887 action_modify_field->src.level))
4888 return rte_flow_error_set(error, EINVAL,
4889 RTE_FLOW_ERROR_TYPE_ACTION, action,
4890 "source and destination fields"
4891 " cannot be the same");
4892 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VALUE ||
4893 action_modify_field->dst.field == RTE_FLOW_FIELD_POINTER ||
4894 action_modify_field->dst.field == RTE_FLOW_FIELD_MARK)
4895 return rte_flow_error_set(error, EINVAL,
4896 RTE_FLOW_ERROR_TYPE_ACTION, action,
4897 "mark, immediate value or a pointer to it"
4898 " cannot be used as a destination");
4899 if (action_modify_field->dst.field == RTE_FLOW_FIELD_START ||
4900 action_modify_field->src.field == RTE_FLOW_FIELD_START)
4901 return rte_flow_error_set(error, ENOTSUP,
4902 RTE_FLOW_ERROR_TYPE_ACTION, action,
4903 "modifications of an arbitrary"
4904 " place in a packet is not supported");
4905 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VLAN_TYPE ||
4906 action_modify_field->src.field == RTE_FLOW_FIELD_VLAN_TYPE)
4907 return rte_flow_error_set(error, ENOTSUP,
4908 RTE_FLOW_ERROR_TYPE_ACTION, action,
4909 "modifications of the 802.1Q Tag"
4910 " Identifier is not supported");
4911 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VXLAN_VNI ||
4912 action_modify_field->src.field == RTE_FLOW_FIELD_VXLAN_VNI)
4913 return rte_flow_error_set(error, ENOTSUP,
4914 RTE_FLOW_ERROR_TYPE_ACTION, action,
4915 "modifications of the VXLAN Network"
4916 " Identifier is not supported");
4917 if (action_modify_field->dst.field == RTE_FLOW_FIELD_GENEVE_VNI ||
4918 action_modify_field->src.field == RTE_FLOW_FIELD_GENEVE_VNI)
4919 return rte_flow_error_set(error, ENOTSUP,
4920 RTE_FLOW_ERROR_TYPE_ACTION, action,
4921 "modifications of the GENEVE Network"
4922 " Identifier is not supported");
4923 if (action_modify_field->dst.field == RTE_FLOW_FIELD_MARK ||
4924 action_modify_field->src.field == RTE_FLOW_FIELD_MARK)
4925 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4926 !mlx5_flow_ext_mreg_supported(dev))
4927 return rte_flow_error_set(error, ENOTSUP,
4928 RTE_FLOW_ERROR_TYPE_ACTION, action,
4929 "cannot modify mark in legacy mode"
4930 " or without extensive registers");
4931 if (action_modify_field->dst.field == RTE_FLOW_FIELD_META ||
4932 action_modify_field->src.field == RTE_FLOW_FIELD_META) {
4933 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
4934 !mlx5_flow_ext_mreg_supported(dev))
4935 return rte_flow_error_set(error, ENOTSUP,
4936 RTE_FLOW_ERROR_TYPE_ACTION, action,
4937 "cannot modify meta without"
4938 " extensive registers support");
4939 ret = flow_dv_get_metadata_reg(dev, attr, error);
4940 if (ret < 0 || ret == REG_NON)
4941 return rte_flow_error_set(error, ENOTSUP,
4942 RTE_FLOW_ERROR_TYPE_ACTION, action,
4943 "cannot modify meta without"
4944 " extensive registers available");
4946 if (action_modify_field->operation != RTE_FLOW_MODIFY_SET)
4947 return rte_flow_error_set(error, ENOTSUP,
4948 RTE_FLOW_ERROR_TYPE_ACTION, action,
4949 "add and sub operations"
4950 " are not supported");
4951 return (action_modify_field->width / 32) +
4952 !!(action_modify_field->width % 32);
4956 * Validate jump action.
4959 * Pointer to the jump action.
4960 * @param[in] action_flags
4961 * Holds the actions detected until now.
4962 * @param[in] attributes
4963 * Pointer to flow attributes
4964 * @param[in] external
4965 * Action belongs to flow rule created by request external to PMD.
4967 * Pointer to error structure.
4970 * 0 on success, a negative errno value otherwise and rte_errno is set.
4973 flow_dv_validate_action_jump(struct rte_eth_dev *dev,
4974 const struct mlx5_flow_tunnel *tunnel,
4975 const struct rte_flow_action *action,
4976 uint64_t action_flags,
4977 const struct rte_flow_attr *attributes,
4978 bool external, struct rte_flow_error *error)
4980 uint32_t target_group, table = 0;
4982 struct flow_grp_info grp_info = {
4983 .external = !!external,
4984 .transfer = !!attributes->transfer,
4988 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4989 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4990 return rte_flow_error_set(error, EINVAL,
4991 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4992 "can't have 2 fate actions in"
4995 return rte_flow_error_set(error, EINVAL,
4996 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4997 NULL, "action configuration not set");
4999 ((const struct rte_flow_action_jump *)action->conf)->group;
5000 ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5004 if (attributes->group == target_group &&
5005 !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
5006 MLX5_FLOW_ACTION_TUNNEL_MATCH)))
5007 return rte_flow_error_set(error, EINVAL,
5008 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5009 "target group must be other than"
5010 " the current flow group");
5012 return rte_flow_error_set(error, EINVAL,
5013 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5014 NULL, "root table shouldn't be destination");
5019 * Validate action PORT_ID / REPRESENTED_PORT.
5022 * Pointer to rte_eth_dev structure.
5023 * @param[in] action_flags
5024 * Bit-fields that holds the actions detected until now.
5026 * PORT_ID / REPRESENTED_PORT action structure.
5028 * Attributes of flow that includes this action.
5030 * Pointer to error structure.
5033 * 0 on success, a negative errno value otherwise and rte_errno is set.
5036 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5037 uint64_t action_flags,
5038 const struct rte_flow_action *action,
5039 const struct rte_flow_attr *attr,
5040 struct rte_flow_error *error)
5042 const struct rte_flow_action_port_id *port_id;
5043 const struct rte_flow_action_ethdev *ethdev;
5044 struct mlx5_priv *act_priv;
5045 struct mlx5_priv *dev_priv;
5048 if (!attr->transfer)
5049 return rte_flow_error_set(error, ENOTSUP,
5050 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5052 "port action is valid in transfer"
5054 if (!action || !action->conf)
5055 return rte_flow_error_set(error, ENOTSUP,
5056 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5058 "port action parameters must be"
5060 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5061 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5062 return rte_flow_error_set(error, EINVAL,
5063 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5064 "can have only one fate actions in"
5066 dev_priv = mlx5_dev_to_eswitch_info(dev);
5068 return rte_flow_error_set(error, rte_errno,
5069 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5071 "failed to obtain E-Switch info");
5072 switch (action->type) {
5073 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5074 port_id = action->conf;
5075 port = port_id->original ? dev->data->port_id : port_id->id;
5077 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5078 ethdev = action->conf;
5079 port = ethdev->port_id;
5083 return rte_flow_error_set
5085 RTE_FLOW_ERROR_TYPE_ACTION, action,
5086 "unknown E-Switch action");
5088 act_priv = mlx5_port_to_eswitch_info(port, false);
5090 return rte_flow_error_set
5092 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5093 "failed to obtain E-Switch port id for port");
5094 if (act_priv->domain_id != dev_priv->domain_id)
5095 return rte_flow_error_set
5097 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5098 "port does not belong to"
5099 " E-Switch being configured");
5104 * Get the maximum number of modify header actions.
5107 * Pointer to rte_eth_dev structure.
5109 * Whether action is on root table.
5112 * Max number of modify header actions device can support.
5114 static inline unsigned int
5115 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5119 * There's no way to directly query the max capacity from FW.
5120 * The maximal value on root table should be assumed to be supported.
5123 return MLX5_MAX_MODIFY_NUM;
5125 return MLX5_ROOT_TBL_MODIFY_NUM;
5129 * Validate the meter action.
5132 * Pointer to rte_eth_dev structure.
5133 * @param[in] action_flags
5134 * Bit-fields that holds the actions detected until now.
5135 * @param[in] item_flags
5136 * Holds the items detected.
5138 * Pointer to the meter action.
5140 * Attributes of flow that includes this action.
5141 * @param[in] port_id_item
5142 * Pointer to item indicating port id.
5144 * Pointer to error structure.
5147 * 0 on success, a negative errno value otherwise and rte_errno is set.
5150 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5151 uint64_t action_flags, uint64_t item_flags,
5152 const struct rte_flow_action *action,
5153 const struct rte_flow_attr *attr,
5154 const struct rte_flow_item *port_id_item,
5156 struct rte_flow_error *error)
5158 struct mlx5_priv *priv = dev->data->dev_private;
5159 const struct rte_flow_action_meter *am = action->conf;
5160 struct mlx5_flow_meter_info *fm;
5161 struct mlx5_flow_meter_policy *mtr_policy;
5162 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5165 return rte_flow_error_set(error, EINVAL,
5166 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5167 "meter action conf is NULL");
5169 if (action_flags & MLX5_FLOW_ACTION_METER)
5170 return rte_flow_error_set(error, ENOTSUP,
5171 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5172 "meter chaining not support");
5173 if (action_flags & MLX5_FLOW_ACTION_JUMP)
5174 return rte_flow_error_set(error, ENOTSUP,
5175 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5176 "meter with jump not support");
5178 return rte_flow_error_set(error, ENOTSUP,
5179 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5181 "meter action not supported");
5182 fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5184 return rte_flow_error_set(error, EINVAL,
5185 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5187 /* aso meter can always be shared by different domains */
5188 if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5189 !(fm->transfer == attr->transfer ||
5190 (!fm->ingress && !attr->ingress && attr->egress) ||
5191 (!fm->egress && !attr->egress && attr->ingress)))
5192 return rte_flow_error_set(error, EINVAL,
5193 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5194 "Flow attributes domain are either invalid "
5195 "or have a domain conflict with current "
5196 "meter attributes");
5197 if (fm->def_policy) {
5198 if (!((attr->transfer &&
5199 mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
5201 mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
5203 mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
5204 return rte_flow_error_set(error, EINVAL,
5205 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5206 "Flow attributes domain "
5207 "have a conflict with current "
5208 "meter domain attributes");
5211 mtr_policy = mlx5_flow_meter_policy_find(dev,
5212 fm->policy_id, NULL);
5214 return rte_flow_error_set(error, EINVAL,
5215 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5216 "Invalid policy id for meter ");
5217 if (!((attr->transfer && mtr_policy->transfer) ||
5218 (attr->egress && mtr_policy->egress) ||
5219 (attr->ingress && mtr_policy->ingress)))
5220 return rte_flow_error_set(error, EINVAL,
5221 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5222 "Flow attributes domain "
5223 "have a conflict with current "
5224 "meter domain attributes");
5225 if (attr->transfer && mtr_policy->dev) {
5227 * When policy has fate action of port_id,
5228 * the flow should have the same src port as policy.
5230 struct mlx5_priv *policy_port_priv =
5231 mtr_policy->dev->data->dev_private;
5232 int32_t flow_src_port = priv->representor_id;
5235 const struct rte_flow_item_port_id *spec =
5237 struct mlx5_priv *port_priv =
5238 mlx5_port_to_eswitch_info(spec->id,
5241 return rte_flow_error_set(error,
5243 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5245 "Failed to get port info.");
5246 flow_src_port = port_priv->representor_id;
5248 if (flow_src_port != policy_port_priv->representor_id)
5249 return rte_flow_error_set(error,
5251 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5253 "Flow and meter policy "
5254 "have different src port.");
5255 } else if (mtr_policy->is_rss) {
5256 struct mlx5_flow_meter_policy *fp;
5257 struct mlx5_meter_policy_action_container *acg;
5258 struct mlx5_meter_policy_action_container *acy;
5259 const struct rte_flow_action *rss_act;
5262 fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
5265 return rte_flow_error_set(error, EINVAL,
5266 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5267 "Unable to get the final "
5268 "policy in the hierarchy");
5269 acg = &fp->act_cnt[RTE_COLOR_GREEN];
5270 acy = &fp->act_cnt[RTE_COLOR_YELLOW];
5271 MLX5_ASSERT(acg->fate_action ==
5272 MLX5_FLOW_FATE_SHARED_RSS ||
5274 MLX5_FLOW_FATE_SHARED_RSS);
5275 if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
5279 ret = mlx5_flow_validate_action_rss(rss_act,
5280 action_flags, dev, attr,
5285 *def_policy = false;
5291 * Validate the age action.
5293 * @param[in] action_flags
5294 * Holds the actions detected until now.
5296 * Pointer to the age action.
5298 * Pointer to the Ethernet device structure.
5300 * Pointer to error structure.
5303 * 0 on success, a negative errno value otherwise and rte_errno is set.
5306 flow_dv_validate_action_age(uint64_t action_flags,
5307 const struct rte_flow_action *action,
5308 struct rte_eth_dev *dev,
5309 struct rte_flow_error *error)
5311 struct mlx5_priv *priv = dev->data->dev_private;
5312 const struct rte_flow_action_age *age = action->conf;
5314 if (!priv->sh->cdev->config.devx ||
5315 (priv->sh->cmng.counter_fallback && !priv->sh->aso_age_mng))
5316 return rte_flow_error_set(error, ENOTSUP,
5317 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5319 "age action not supported");
5320 if (!(action->conf))
5321 return rte_flow_error_set(error, EINVAL,
5322 RTE_FLOW_ERROR_TYPE_ACTION, action,
5323 "configuration cannot be null");
5324 if (!(age->timeout))
5325 return rte_flow_error_set(error, EINVAL,
5326 RTE_FLOW_ERROR_TYPE_ACTION, action,
5327 "invalid timeout value 0");
5328 if (action_flags & MLX5_FLOW_ACTION_AGE)
5329 return rte_flow_error_set(error, EINVAL,
5330 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5331 "duplicate age actions set");
5336 * Validate the modify-header IPv4 DSCP actions.
5338 * @param[in] action_flags
5339 * Holds the actions detected until now.
5341 * Pointer to the modify action.
5342 * @param[in] item_flags
5343 * Holds the items detected.
5345 * Pointer to error structure.
5348 * 0 on success, a negative errno value otherwise and rte_errno is set.
5351 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
5352 const struct rte_flow_action *action,
5353 const uint64_t item_flags,
5354 struct rte_flow_error *error)
5358 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5360 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
5361 return rte_flow_error_set(error, EINVAL,
5362 RTE_FLOW_ERROR_TYPE_ACTION,
5364 "no ipv4 item in pattern");
5370 * Validate the modify-header IPv6 DSCP actions.
5372 * @param[in] action_flags
5373 * Holds the actions detected until now.
5375 * Pointer to the modify action.
5376 * @param[in] item_flags
5377 * Holds the items detected.
5379 * Pointer to error structure.
5382 * 0 on success, a negative errno value otherwise and rte_errno is set.
5385 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
5386 const struct rte_flow_action *action,
5387 const uint64_t item_flags,
5388 struct rte_flow_error *error)
5392 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5394 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
5395 return rte_flow_error_set(error, EINVAL,
5396 RTE_FLOW_ERROR_TYPE_ACTION,
5398 "no ipv6 item in pattern");
5404 flow_dv_modify_match_cb(void *tool_ctx __rte_unused,
5405 struct mlx5_list_entry *entry, void *cb_ctx)
5407 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5408 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5409 struct mlx5_flow_dv_modify_hdr_resource *resource =
5410 container_of(entry, typeof(*resource), entry);
5411 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5413 key_len += ref->actions_num * sizeof(ref->actions[0]);
5414 return ref->actions_num != resource->actions_num ||
5415 memcmp(&ref->ft_type, &resource->ft_type, key_len);
5418 static struct mlx5_indexed_pool *
5419 flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
5421 struct mlx5_indexed_pool *ipool = __atomic_load_n
5422 (&sh->mdh_ipools[index], __ATOMIC_SEQ_CST);
5425 struct mlx5_indexed_pool *expected = NULL;
5426 struct mlx5_indexed_pool_config cfg =
5427 (struct mlx5_indexed_pool_config) {
5428 .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
5430 sizeof(struct mlx5_modification_cmd),
5435 .release_mem_en = !!sh->config.reclaim_mode,
5437 sh->config.reclaim_mode ? 0 : (1 << 16),
5438 .malloc = mlx5_malloc,
5440 .type = "mlx5_modify_action_resource",
5443 cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
5444 ipool = mlx5_ipool_create(&cfg);
5447 if (!__atomic_compare_exchange_n(&sh->mdh_ipools[index],
5448 &expected, ipool, false,
5450 __ATOMIC_SEQ_CST)) {
5451 mlx5_ipool_destroy(ipool);
5452 ipool = __atomic_load_n(&sh->mdh_ipools[index],
5459 struct mlx5_list_entry *
5460 flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
5462 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5463 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5464 struct mlx5dv_dr_domain *ns;
5465 struct mlx5_flow_dv_modify_hdr_resource *entry;
5466 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5467 struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
5468 ref->actions_num - 1);
5470 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5471 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5474 if (unlikely(!ipool)) {
5475 rte_flow_error_set(ctx->error, ENOMEM,
5476 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5477 NULL, "cannot allocate modify ipool");
5480 entry = mlx5_ipool_zmalloc(ipool, &idx);
5482 rte_flow_error_set(ctx->error, ENOMEM,
5483 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5484 "cannot allocate resource memory");
5487 rte_memcpy(&entry->ft_type,
5488 RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
5489 key_len + data_len);
5490 if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
5491 ns = sh->fdb_domain;
5492 else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
5496 ret = mlx5_flow_os_create_flow_action_modify_header
5497 (sh->cdev->ctx, ns, entry,
5498 data_len, &entry->action);
5500 mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
5501 rte_flow_error_set(ctx->error, ENOMEM,
5502 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5503 NULL, "cannot create modification action");
5507 return &entry->entry;
5510 struct mlx5_list_entry *
5511 flow_dv_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5514 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5515 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5516 struct mlx5_flow_dv_modify_hdr_resource *entry;
5517 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5518 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5521 entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
5524 rte_flow_error_set(ctx->error, ENOMEM,
5525 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5526 "cannot allocate resource memory");
5529 memcpy(entry, oentry, sizeof(*entry) + data_len);
5531 return &entry->entry;
5535 flow_dv_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5537 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5538 struct mlx5_flow_dv_modify_hdr_resource *res =
5539 container_of(entry, typeof(*res), entry);
5541 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
5545 * Validate the sample action.
5547 * @param[in, out] action_flags
5548 * Holds the actions detected until now.
5550 * Pointer to the sample action.
5552 * Pointer to the Ethernet device structure.
5554 * Attributes of flow that includes this action.
5555 * @param[in] item_flags
5556 * Holds the items detected.
5558 * Pointer to the RSS action.
5559 * @param[out] sample_rss
5560 * Pointer to the RSS action in sample action list.
5562 * Pointer to the COUNT action in sample action list.
5563 * @param[out] fdb_mirror_limit
5564 * Pointer to the FDB mirror limitation flag.
5566 * Pointer to error structure.
5569 * 0 on success, a negative errno value otherwise and rte_errno is set.
5572 flow_dv_validate_action_sample(uint64_t *action_flags,
5573 const struct rte_flow_action *action,
5574 struct rte_eth_dev *dev,
5575 const struct rte_flow_attr *attr,
5576 uint64_t item_flags,
5577 const struct rte_flow_action_rss *rss,
5578 const struct rte_flow_action_rss **sample_rss,
5579 const struct rte_flow_action_count **count,
5580 int *fdb_mirror_limit,
5581 struct rte_flow_error *error)
5583 struct mlx5_priv *priv = dev->data->dev_private;
5584 struct mlx5_sh_config *dev_conf = &priv->sh->config;
5585 const struct rte_flow_action_sample *sample = action->conf;
5586 const struct rte_flow_action *act;
5587 uint64_t sub_action_flags = 0;
5588 uint16_t queue_index = 0xFFFF;
5593 return rte_flow_error_set(error, EINVAL,
5594 RTE_FLOW_ERROR_TYPE_ACTION, action,
5595 "configuration cannot be NULL");
5596 if (sample->ratio == 0)
5597 return rte_flow_error_set(error, EINVAL,
5598 RTE_FLOW_ERROR_TYPE_ACTION, action,
5599 "ratio value starts from 1");
5600 if (!priv->sh->cdev->config.devx ||
5601 (sample->ratio > 0 && !priv->sampler_en))
5602 return rte_flow_error_set(error, ENOTSUP,
5603 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5605 "sample action not supported");
5606 if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
5607 return rte_flow_error_set(error, EINVAL,
5608 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5609 "Multiple sample actions not "
5611 if (*action_flags & MLX5_FLOW_ACTION_METER)
5612 return rte_flow_error_set(error, EINVAL,
5613 RTE_FLOW_ERROR_TYPE_ACTION, action,
5614 "wrong action order, meter should "
5615 "be after sample action");
5616 if (*action_flags & MLX5_FLOW_ACTION_JUMP)
5617 return rte_flow_error_set(error, EINVAL,
5618 RTE_FLOW_ERROR_TYPE_ACTION, action,
5619 "wrong action order, jump should "
5620 "be after sample action");
5621 if (*action_flags & MLX5_FLOW_ACTION_CT)
5622 return rte_flow_error_set(error, EINVAL,
5623 RTE_FLOW_ERROR_TYPE_ACTION, action,
5624 "Sample after CT not supported");
5625 act = sample->actions;
5626 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
5627 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5628 return rte_flow_error_set(error, ENOTSUP,
5629 RTE_FLOW_ERROR_TYPE_ACTION,
5630 act, "too many actions");
5631 switch (act->type) {
5632 case RTE_FLOW_ACTION_TYPE_QUEUE:
5633 ret = mlx5_flow_validate_action_queue(act,
5639 queue_index = ((const struct rte_flow_action_queue *)
5640 (act->conf))->index;
5641 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
5644 case RTE_FLOW_ACTION_TYPE_RSS:
5645 *sample_rss = act->conf;
5646 ret = mlx5_flow_validate_action_rss(act,
5653 if (rss && *sample_rss &&
5654 ((*sample_rss)->level != rss->level ||
5655 (*sample_rss)->types != rss->types))
5656 return rte_flow_error_set(error, ENOTSUP,
5657 RTE_FLOW_ERROR_TYPE_ACTION,
5659 "Can't use the different RSS types "
5660 "or level in the same flow");
5661 if (*sample_rss != NULL && (*sample_rss)->queue_num)
5662 queue_index = (*sample_rss)->queue[0];
5663 sub_action_flags |= MLX5_FLOW_ACTION_RSS;
5666 case RTE_FLOW_ACTION_TYPE_MARK:
5667 ret = flow_dv_validate_action_mark(dev, act,
5672 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
5673 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
5674 MLX5_FLOW_ACTION_MARK_EXT;
5676 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
5679 case RTE_FLOW_ACTION_TYPE_COUNT:
5680 ret = flow_dv_validate_action_count
5681 (dev, false, *action_flags | sub_action_flags,
5686 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
5687 *action_flags |= MLX5_FLOW_ACTION_COUNT;
5690 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5691 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5692 ret = flow_dv_validate_action_port_id(dev,
5699 sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5702 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5703 ret = flow_dv_validate_action_raw_encap_decap
5704 (dev, NULL, act->conf, attr, &sub_action_flags,
5705 &actions_n, action, item_flags, error);
5710 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5711 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5712 ret = flow_dv_validate_action_l2_encap(dev,
5718 sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
5722 return rte_flow_error_set(error, ENOTSUP,
5723 RTE_FLOW_ERROR_TYPE_ACTION,
5725 "Doesn't support optional "
5729 if (attr->ingress && !attr->transfer) {
5730 if (!(sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
5731 MLX5_FLOW_ACTION_RSS)))
5732 return rte_flow_error_set(error, EINVAL,
5733 RTE_FLOW_ERROR_TYPE_ACTION,
5735 "Ingress must has a dest "
5736 "QUEUE for Sample");
5737 } else if (attr->egress && !attr->transfer) {
5738 return rte_flow_error_set(error, ENOTSUP,
5739 RTE_FLOW_ERROR_TYPE_ACTION,
5741 "Sample Only support Ingress "
5743 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
5744 MLX5_ASSERT(attr->transfer);
5745 if (sample->ratio > 1)
5746 return rte_flow_error_set(error, ENOTSUP,
5747 RTE_FLOW_ERROR_TYPE_ACTION,
5749 "E-Switch doesn't support "
5750 "any optional action "
5752 if (sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
5753 return rte_flow_error_set(error, ENOTSUP,
5754 RTE_FLOW_ERROR_TYPE_ACTION,
5756 "unsupported action QUEUE");
5757 if (sub_action_flags & MLX5_FLOW_ACTION_RSS)
5758 return rte_flow_error_set(error, ENOTSUP,
5759 RTE_FLOW_ERROR_TYPE_ACTION,
5761 "unsupported action QUEUE");
5762 if (!(sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
5763 return rte_flow_error_set(error, EINVAL,
5764 RTE_FLOW_ERROR_TYPE_ACTION,
5766 "E-Switch must has a dest "
5767 "port for mirroring");
5768 if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
5769 priv->representor_id != UINT16_MAX)
5770 *fdb_mirror_limit = 1;
5772 /* Continue validation for Xcap actions.*/
5773 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
5774 (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index))) {
5775 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5776 MLX5_FLOW_XCAP_ACTIONS)
5777 return rte_flow_error_set(error, ENOTSUP,
5778 RTE_FLOW_ERROR_TYPE_ACTION,
5779 NULL, "encap and decap "
5780 "combination aren't "
5782 if (!attr->transfer && attr->ingress && (sub_action_flags &
5783 MLX5_FLOW_ACTION_ENCAP))
5784 return rte_flow_error_set(error, ENOTSUP,
5785 RTE_FLOW_ERROR_TYPE_ACTION,
5786 NULL, "encap is not supported"
5787 " for ingress traffic");
5793 * Find existing modify-header resource or create and register a new one.
5795 * @param dev[in, out]
5796 * Pointer to rte_eth_dev structure.
5797 * @param[in, out] resource
5798 * Pointer to modify-header resource.
5799 * @parm[in, out] dev_flow
5800 * Pointer to the dev_flow.
5802 * pointer to error structure.
5805 * 0 on success otherwise -errno and errno is set.
5808 flow_dv_modify_hdr_resource_register
5809 (struct rte_eth_dev *dev,
5810 struct mlx5_flow_dv_modify_hdr_resource *resource,
5811 struct mlx5_flow *dev_flow,
5812 struct rte_flow_error *error)
5814 struct mlx5_priv *priv = dev->data->dev_private;
5815 struct mlx5_dev_ctx_shared *sh = priv->sh;
5816 uint32_t key_len = sizeof(*resource) -
5817 offsetof(typeof(*resource), ft_type) +
5818 resource->actions_num * sizeof(resource->actions[0]);
5819 struct mlx5_list_entry *entry;
5820 struct mlx5_flow_cb_ctx ctx = {
5824 struct mlx5_hlist *modify_cmds;
5827 modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
5829 MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
5831 flow_dv_modify_create_cb,
5832 flow_dv_modify_match_cb,
5833 flow_dv_modify_remove_cb,
5834 flow_dv_modify_clone_cb,
5835 flow_dv_modify_clone_free_cb,
5837 if (unlikely(!modify_cmds))
5839 resource->root = !dev_flow->dv.group;
5840 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
5842 return rte_flow_error_set(error, EOVERFLOW,
5843 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5844 "too many modify header items");
5845 key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
5846 entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
5849 resource = container_of(entry, typeof(*resource), entry);
5850 dev_flow->handle->dvh.modify_hdr = resource;
5855 * Get DV flow counter by index.
5858 * Pointer to the Ethernet device structure.
5860 * mlx5 flow counter index in the container.
5862 * mlx5 flow counter pool in the container.
5865 * Pointer to the counter, NULL otherwise.
5867 static struct mlx5_flow_counter *
5868 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
5870 struct mlx5_flow_counter_pool **ppool)
5872 struct mlx5_priv *priv = dev->data->dev_private;
5873 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5874 struct mlx5_flow_counter_pool *pool;
5876 /* Decrease to original index and clear shared bit. */
5877 idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
5878 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cmng->n);
5879 pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
5883 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
5887 * Check the devx counter belongs to the pool.
5890 * Pointer to the counter pool.
5892 * The counter devx ID.
5895 * True if counter belongs to the pool, false otherwise.
5898 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
5900 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
5901 MLX5_COUNTERS_PER_POOL;
5903 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
5909 * Get a pool by devx counter ID.
5912 * Pointer to the counter management.
5914 * The counter devx ID.
5917 * The counter pool pointer if exists, NULL otherwise,
5919 static struct mlx5_flow_counter_pool *
5920 flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
5923 struct mlx5_flow_counter_pool *pool = NULL;
5925 rte_spinlock_lock(&cmng->pool_update_sl);
5926 /* Check last used pool. */
5927 if (cmng->last_pool_idx != POOL_IDX_INVALID &&
5928 flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
5929 pool = cmng->pools[cmng->last_pool_idx];
5932 /* ID out of range means no suitable pool in the container. */
5933 if (id > cmng->max_id || id < cmng->min_id)
5936 * Find the pool from the end of the container, since mostly counter
5937 * ID is sequence increasing, and the last pool should be the needed
5942 struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
5944 if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
5950 rte_spinlock_unlock(&cmng->pool_update_sl);
5955 * Resize a counter container.
5958 * Pointer to the Ethernet device structure.
5961 * 0 on success, otherwise negative errno value and rte_errno is set.
5964 flow_dv_container_resize(struct rte_eth_dev *dev)
5966 struct mlx5_priv *priv = dev->data->dev_private;
5967 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5968 void *old_pools = cmng->pools;
5969 uint32_t resize = cmng->n + MLX5_CNT_CONTAINER_RESIZE;
5970 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
5971 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
5978 memcpy(pools, old_pools, cmng->n *
5979 sizeof(struct mlx5_flow_counter_pool *));
5981 cmng->pools = pools;
5983 mlx5_free(old_pools);
5988 * Query a devx flow counter.
5991 * Pointer to the Ethernet device structure.
5992 * @param[in] counter
5993 * Index to the flow counter.
5995 * The statistics value of packets.
5997 * The statistics value of bytes.
6000 * 0 on success, otherwise a negative errno value and rte_errno is set.
6003 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6006 struct mlx5_priv *priv = dev->data->dev_private;
6007 struct mlx5_flow_counter_pool *pool = NULL;
6008 struct mlx5_flow_counter *cnt;
6011 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6013 if (priv->sh->cmng.counter_fallback)
6014 return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6015 0, pkts, bytes, 0, NULL, NULL, 0);
6016 rte_spinlock_lock(&pool->sl);
6021 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6022 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6023 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6025 rte_spinlock_unlock(&pool->sl);
6030 * Create and initialize a new counter pool.
6033 * Pointer to the Ethernet device structure.
6035 * The devX counter handle.
6037 * Whether the pool is for counter that was allocated for aging.
6038 * @param[in/out] cont_cur
6039 * Pointer to the container pointer, it will be update in pool resize.
6042 * The pool container pointer on success, NULL otherwise and rte_errno is set.
6044 static struct mlx5_flow_counter_pool *
6045 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6048 struct mlx5_priv *priv = dev->data->dev_private;
6049 struct mlx5_flow_counter_pool *pool;
6050 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6051 bool fallback = priv->sh->cmng.counter_fallback;
6052 uint32_t size = sizeof(*pool);
6054 size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6055 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6056 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6062 pool->is_aged = !!age;
6063 pool->query_gen = 0;
6064 pool->min_dcs = dcs;
6065 rte_spinlock_init(&pool->sl);
6066 rte_spinlock_init(&pool->csl);
6067 TAILQ_INIT(&pool->counters[0]);
6068 TAILQ_INIT(&pool->counters[1]);
6069 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6070 rte_spinlock_lock(&cmng->pool_update_sl);
6071 pool->index = cmng->n_valid;
6072 if (pool->index == cmng->n && flow_dv_container_resize(dev)) {
6074 rte_spinlock_unlock(&cmng->pool_update_sl);
6077 cmng->pools[pool->index] = pool;
6079 if (unlikely(fallback)) {
6080 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6082 if (base < cmng->min_id)
6083 cmng->min_id = base;
6084 if (base > cmng->max_id)
6085 cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6086 cmng->last_pool_idx = pool->index;
6088 rte_spinlock_unlock(&cmng->pool_update_sl);
6093 * Prepare a new counter and/or a new counter pool.
6096 * Pointer to the Ethernet device structure.
6097 * @param[out] cnt_free
6098 * Where to put the pointer of a new counter.
6100 * Whether the pool is for counter that was allocated for aging.
6103 * The counter pool pointer and @p cnt_free is set on success,
6104 * NULL otherwise and rte_errno is set.
6106 static struct mlx5_flow_counter_pool *
6107 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6108 struct mlx5_flow_counter **cnt_free,
6111 struct mlx5_priv *priv = dev->data->dev_private;
6112 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6113 struct mlx5_flow_counter_pool *pool;
6114 struct mlx5_counters tmp_tq;
6115 struct mlx5_devx_obj *dcs = NULL;
6116 struct mlx5_flow_counter *cnt;
6117 enum mlx5_counter_type cnt_type =
6118 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6119 bool fallback = priv->sh->cmng.counter_fallback;
6123 /* bulk_bitmap must be 0 for single counter allocation. */
6124 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6127 pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6129 pool = flow_dv_pool_create(dev, dcs, age);
6131 mlx5_devx_cmd_destroy(dcs);
6135 i = dcs->id % MLX5_COUNTERS_PER_POOL;
6136 cnt = MLX5_POOL_GET_CNT(pool, i);
6138 cnt->dcs_when_free = dcs;
6142 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6144 rte_errno = ENODATA;
6147 pool = flow_dv_pool_create(dev, dcs, age);
6149 mlx5_devx_cmd_destroy(dcs);
6152 TAILQ_INIT(&tmp_tq);
6153 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6154 cnt = MLX5_POOL_GET_CNT(pool, i);
6156 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6158 rte_spinlock_lock(&cmng->csl[cnt_type]);
6159 TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6160 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6161 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6162 (*cnt_free)->pool = pool;
6167 * Allocate a flow counter.
6170 * Pointer to the Ethernet device structure.
6172 * Whether the counter was allocated for aging.
6175 * Index to flow counter on success, 0 otherwise and rte_errno is set.
6178 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6180 struct mlx5_priv *priv = dev->data->dev_private;
6181 struct mlx5_flow_counter_pool *pool = NULL;
6182 struct mlx5_flow_counter *cnt_free = NULL;
6183 bool fallback = priv->sh->cmng.counter_fallback;
6184 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6185 enum mlx5_counter_type cnt_type =
6186 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6189 if (!priv->sh->cdev->config.devx) {
6190 rte_errno = ENOTSUP;
6193 /* Get free counters from container. */
6194 rte_spinlock_lock(&cmng->csl[cnt_type]);
6195 cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6197 TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6198 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6199 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6201 pool = cnt_free->pool;
6203 cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6204 /* Create a DV counter action only in the first time usage. */
6205 if (!cnt_free->action) {
6207 struct mlx5_devx_obj *dcs;
6211 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
6212 dcs = pool->min_dcs;
6215 dcs = cnt_free->dcs_when_free;
6217 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
6224 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
6225 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
6226 /* Update the counter reset values. */
6227 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
6230 if (!fallback && !priv->sh->cmng.query_thread_on)
6231 /* Start the asynchronous batch query by the host thread. */
6232 mlx5_set_query_alarm(priv->sh);
6234 * When the count action isn't shared (by ID), shared_info field is
6235 * used for indirect action API's refcnt.
6236 * When the counter action is not shared neither by ID nor by indirect
6237 * action API, shared info must be 1.
6239 cnt_free->shared_info.refcnt = 1;
6243 cnt_free->pool = pool;
6245 cnt_free->dcs_when_free = cnt_free->dcs_when_active;
6246 rte_spinlock_lock(&cmng->csl[cnt_type]);
6247 TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
6248 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6254 * Get age param from counter index.
6257 * Pointer to the Ethernet device structure.
6258 * @param[in] counter
6259 * Index to the counter handler.
6262 * The aging parameter specified for the counter index.
6264 static struct mlx5_age_param*
6265 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
6268 struct mlx5_flow_counter *cnt;
6269 struct mlx5_flow_counter_pool *pool = NULL;
6271 flow_dv_counter_get_by_idx(dev, counter, &pool);
6272 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
6273 cnt = MLX5_POOL_GET_CNT(pool, counter);
6274 return MLX5_CNT_TO_AGE(cnt);
6278 * Remove a flow counter from aged counter list.
6281 * Pointer to the Ethernet device structure.
6282 * @param[in] counter
6283 * Index to the counter handler.
6285 * Pointer to the counter handler.
6288 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
6289 uint32_t counter, struct mlx5_flow_counter *cnt)
6291 struct mlx5_age_info *age_info;
6292 struct mlx5_age_param *age_param;
6293 struct mlx5_priv *priv = dev->data->dev_private;
6294 uint16_t expected = AGE_CANDIDATE;
6296 age_info = GET_PORT_AGE_INFO(priv);
6297 age_param = flow_dv_counter_idx_get_age(dev, counter);
6298 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
6299 AGE_FREE, false, __ATOMIC_RELAXED,
6300 __ATOMIC_RELAXED)) {
6302 * We need the lock even it is age timeout,
6303 * since counter may still in process.
6305 rte_spinlock_lock(&age_info->aged_sl);
6306 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
6307 rte_spinlock_unlock(&age_info->aged_sl);
6308 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
6313 * Release a flow counter.
6316 * Pointer to the Ethernet device structure.
6317 * @param[in] counter
6318 * Index to the counter handler.
6321 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
6323 struct mlx5_priv *priv = dev->data->dev_private;
6324 struct mlx5_flow_counter_pool *pool = NULL;
6325 struct mlx5_flow_counter *cnt;
6326 enum mlx5_counter_type cnt_type;
6330 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6332 if (pool->is_aged) {
6333 flow_dv_counter_remove_from_age(dev, counter, cnt);
6336 * If the counter action is shared by indirect action API,
6337 * the atomic function reduces its references counter.
6338 * If after the reduction the action is still referenced, the
6339 * function returns here and does not release it.
6340 * When the counter action is not shared by
6341 * indirect action API, shared info is 1 before the reduction,
6342 * so this condition is failed and function doesn't return here.
6344 if (__atomic_sub_fetch(&cnt->shared_info.refcnt, 1,
6350 * Put the counter back to list to be updated in none fallback mode.
6351 * Currently, we are using two list alternately, while one is in query,
6352 * add the freed counter to the other list based on the pool query_gen
6353 * value. After query finishes, add counter the list to the global
6354 * container counter list. The list changes while query starts. In
6355 * this case, lock will not be needed as query callback and release
6356 * function both operate with the different list.
6358 if (!priv->sh->cmng.counter_fallback) {
6359 rte_spinlock_lock(&pool->csl);
6360 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
6361 rte_spinlock_unlock(&pool->csl);
6363 cnt->dcs_when_free = cnt->dcs_when_active;
6364 cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6365 MLX5_COUNTER_TYPE_ORIGIN;
6366 rte_spinlock_lock(&priv->sh->cmng.csl[cnt_type]);
6367 TAILQ_INSERT_TAIL(&priv->sh->cmng.counters[cnt_type],
6369 rte_spinlock_unlock(&priv->sh->cmng.csl[cnt_type]);
6374 * Resize a meter id container.
6377 * Pointer to the Ethernet device structure.
6380 * 0 on success, otherwise negative errno value and rte_errno is set.
6383 flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
6385 struct mlx5_priv *priv = dev->data->dev_private;
6386 struct mlx5_aso_mtr_pools_mng *pools_mng =
6387 &priv->sh->mtrmng->pools_mng;
6388 void *old_pools = pools_mng->pools;
6389 uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
6390 uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
6391 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
6398 if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER)) {
6403 memcpy(pools, old_pools, pools_mng->n *
6404 sizeof(struct mlx5_aso_mtr_pool *));
6405 pools_mng->n = resize;
6406 pools_mng->pools = pools;
6408 mlx5_free(old_pools);
6413 * Prepare a new meter and/or a new meter pool.
6416 * Pointer to the Ethernet device structure.
6417 * @param[out] mtr_free
6418 * Where to put the pointer of a new meter.g.
6421 * The meter pool pointer and @mtr_free is set on success,
6422 * NULL otherwise and rte_errno is set.
6424 static struct mlx5_aso_mtr_pool *
6425 flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
6427 struct mlx5_priv *priv = dev->data->dev_private;
6428 struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
6429 struct mlx5_aso_mtr_pool *pool = NULL;
6430 struct mlx5_devx_obj *dcs = NULL;
6432 uint32_t log_obj_size;
6434 log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
6435 dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
6436 priv->sh->cdev->pdn,
6439 rte_errno = ENODATA;
6442 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
6445 claim_zero(mlx5_devx_cmd_destroy(dcs));
6448 pool->devx_obj = dcs;
6449 rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
6450 pool->index = pools_mng->n_valid;
6451 if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
6453 claim_zero(mlx5_devx_cmd_destroy(dcs));
6454 rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
6457 pools_mng->pools[pool->index] = pool;
6458 pools_mng->n_valid++;
6459 rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
6460 for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
6461 pool->mtrs[i].offset = i;
6462 LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
6464 pool->mtrs[0].offset = 0;
6465 *mtr_free = &pool->mtrs[0];
6470 * Release a flow meter into pool.
6473 * Pointer to the Ethernet device structure.
6474 * @param[in] mtr_idx
6475 * Index to aso flow meter.
6478 flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
6480 struct mlx5_priv *priv = dev->data->dev_private;
6481 struct mlx5_aso_mtr_pools_mng *pools_mng =
6482 &priv->sh->mtrmng->pools_mng;
6483 struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
6485 MLX5_ASSERT(aso_mtr);
6486 rte_spinlock_lock(&pools_mng->mtrsl);
6487 memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
6488 aso_mtr->state = ASO_METER_FREE;
6489 LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
6490 rte_spinlock_unlock(&pools_mng->mtrsl);
6494 * Allocate a aso flow meter.
6497 * Pointer to the Ethernet device structure.
6500 * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
6503 flow_dv_mtr_alloc(struct rte_eth_dev *dev)
6505 struct mlx5_priv *priv = dev->data->dev_private;
6506 struct mlx5_aso_mtr *mtr_free = NULL;
6507 struct mlx5_aso_mtr_pools_mng *pools_mng =
6508 &priv->sh->mtrmng->pools_mng;
6509 struct mlx5_aso_mtr_pool *pool;
6510 uint32_t mtr_idx = 0;
6512 if (!priv->sh->cdev->config.devx) {
6513 rte_errno = ENOTSUP;
6516 /* Allocate the flow meter memory. */
6517 /* Get free meters from management. */
6518 rte_spinlock_lock(&pools_mng->mtrsl);
6519 mtr_free = LIST_FIRST(&pools_mng->meters);
6521 LIST_REMOVE(mtr_free, next);
6522 if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
6523 rte_spinlock_unlock(&pools_mng->mtrsl);
6526 mtr_free->state = ASO_METER_WAIT;
6527 rte_spinlock_unlock(&pools_mng->mtrsl);
6528 pool = container_of(mtr_free,
6529 struct mlx5_aso_mtr_pool,
6530 mtrs[mtr_free->offset]);
6531 mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
6532 if (!mtr_free->fm.meter_action) {
6533 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
6534 struct rte_flow_error error;
6537 reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
6538 mtr_free->fm.meter_action =
6539 mlx5_glue->dv_create_flow_action_aso
6540 (priv->sh->rx_domain,
6541 pool->devx_obj->obj,
6543 (1 << MLX5_FLOW_COLOR_GREEN),
6545 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
6546 if (!mtr_free->fm.meter_action) {
6547 flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
6555 * Verify the @p attributes will be correctly understood by the NIC and store
6556 * them in the @p flow if everything is correct.
6559 * Pointer to dev struct.
6560 * @param[in] attributes
6561 * Pointer to flow attributes
6562 * @param[in] external
6563 * This flow rule is created by request external to PMD.
6565 * Pointer to error structure.
6568 * - 0 on success and non root table.
6569 * - 1 on success and root table.
6570 * - a negative errno value otherwise and rte_errno is set.
6573 flow_dv_validate_attributes(struct rte_eth_dev *dev,
6574 const struct mlx5_flow_tunnel *tunnel,
6575 const struct rte_flow_attr *attributes,
6576 const struct flow_grp_info *grp_info,
6577 struct rte_flow_error *error)
6579 struct mlx5_priv *priv = dev->data->dev_private;
6580 uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
6583 #ifndef HAVE_MLX5DV_DR
6584 RTE_SET_USED(tunnel);
6585 RTE_SET_USED(grp_info);
6586 if (attributes->group)
6587 return rte_flow_error_set(error, ENOTSUP,
6588 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6590 "groups are not supported");
6594 ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
6599 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
6601 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
6602 attributes->priority > lowest_priority)
6603 return rte_flow_error_set(error, ENOTSUP,
6604 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
6606 "priority out of range");
6607 if (attributes->transfer) {
6608 if (!priv->sh->config.dv_esw_en)
6609 return rte_flow_error_set
6611 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6612 "E-Switch dr is not supported");
6613 if (attributes->egress)
6614 return rte_flow_error_set
6616 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
6617 "egress is not supported");
6619 if (!(attributes->egress ^ attributes->ingress))
6620 return rte_flow_error_set(error, ENOTSUP,
6621 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6622 "must specify exactly one of "
6623 "ingress or egress");
6628 validate_integrity_bits(const struct rte_flow_item_integrity *mask,
6629 int64_t pattern_flags, uint64_t l3_flags,
6630 uint64_t l4_flags, uint64_t ip4_flag,
6631 struct rte_flow_error *error)
6633 if (mask->l3_ok && !(pattern_flags & l3_flags))
6634 return rte_flow_error_set(error, EINVAL,
6635 RTE_FLOW_ERROR_TYPE_ITEM,
6636 NULL, "missing L3 protocol");
6638 if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
6639 return rte_flow_error_set(error, EINVAL,
6640 RTE_FLOW_ERROR_TYPE_ITEM,
6641 NULL, "missing IPv4 protocol");
6643 if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
6644 return rte_flow_error_set(error, EINVAL,
6645 RTE_FLOW_ERROR_TYPE_ITEM,
6646 NULL, "missing L4 protocol");
6652 flow_dv_validate_item_integrity_post(const struct
6653 rte_flow_item *integrity_items[2],
6654 int64_t pattern_flags,
6655 struct rte_flow_error *error)
6657 const struct rte_flow_item_integrity *mask;
6660 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
6661 mask = (typeof(mask))integrity_items[0]->mask;
6662 ret = validate_integrity_bits(mask, pattern_flags,
6663 MLX5_FLOW_LAYER_OUTER_L3,
6664 MLX5_FLOW_LAYER_OUTER_L4,
6665 MLX5_FLOW_LAYER_OUTER_L3_IPV4,
6670 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
6671 mask = (typeof(mask))integrity_items[1]->mask;
6672 ret = validate_integrity_bits(mask, pattern_flags,
6673 MLX5_FLOW_LAYER_INNER_L3,
6674 MLX5_FLOW_LAYER_INNER_L4,
6675 MLX5_FLOW_LAYER_INNER_L3_IPV4,
6684 flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
6685 const struct rte_flow_item *integrity_item,
6686 uint64_t pattern_flags, uint64_t *last_item,
6687 const struct rte_flow_item *integrity_items[2],
6688 struct rte_flow_error *error)
6690 struct mlx5_priv *priv = dev->data->dev_private;
6691 const struct rte_flow_item_integrity *mask = (typeof(mask))
6692 integrity_item->mask;
6693 const struct rte_flow_item_integrity *spec = (typeof(spec))
6694 integrity_item->spec;
6696 if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
6697 return rte_flow_error_set(error, ENOTSUP,
6698 RTE_FLOW_ERROR_TYPE_ITEM,
6700 "packet integrity integrity_item not supported");
6702 return rte_flow_error_set(error, ENOTSUP,
6703 RTE_FLOW_ERROR_TYPE_ITEM,
6705 "no spec for integrity item");
6707 mask = &rte_flow_item_integrity_mask;
6708 if (!mlx5_validate_integrity_item(mask))
6709 return rte_flow_error_set(error, ENOTSUP,
6710 RTE_FLOW_ERROR_TYPE_ITEM,
6712 "unsupported integrity filter");
6713 if (spec->level > 1) {
6714 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
6715 return rte_flow_error_set
6717 RTE_FLOW_ERROR_TYPE_ITEM,
6718 NULL, "multiple inner integrity items not supported");
6719 integrity_items[1] = integrity_item;
6720 *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
6722 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
6723 return rte_flow_error_set
6725 RTE_FLOW_ERROR_TYPE_ITEM,
6726 NULL, "multiple outer integrity items not supported");
6727 integrity_items[0] = integrity_item;
6728 *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
6734 flow_dv_validate_item_flex(struct rte_eth_dev *dev,
6735 const struct rte_flow_item *item,
6736 uint64_t item_flags,
6737 uint64_t *last_item,
6739 struct rte_flow_error *error)
6741 const struct rte_flow_item_flex *flow_spec = item->spec;
6742 const struct rte_flow_item_flex *flow_mask = item->mask;
6743 struct mlx5_flex_item *flex;
6746 return rte_flow_error_set(error, EINVAL,
6747 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6748 "flex flow item spec cannot be NULL");
6750 return rte_flow_error_set(error, EINVAL,
6751 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6752 "flex flow item mask cannot be NULL");
6754 return rte_flow_error_set(error, ENOTSUP,
6755 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6756 "flex flow item last not supported");
6757 if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
6758 return rte_flow_error_set(error, EINVAL,
6759 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
6760 "invalid flex flow item handle");
6761 flex = (struct mlx5_flex_item *)flow_spec->handle;
6762 switch (flex->tunnel_mode) {
6763 case FLEX_TUNNEL_MODE_SINGLE:
6765 (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
6766 rte_flow_error_set(error, EINVAL,
6767 RTE_FLOW_ERROR_TYPE_ITEM,
6768 NULL, "multiple flex items not supported");
6770 case FLEX_TUNNEL_MODE_OUTER:
6772 rte_flow_error_set(error, EINVAL,
6773 RTE_FLOW_ERROR_TYPE_ITEM,
6774 NULL, "inner flex item was not configured");
6775 if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
6776 rte_flow_error_set(error, ENOTSUP,
6777 RTE_FLOW_ERROR_TYPE_ITEM,
6778 NULL, "multiple flex items not supported");
6780 case FLEX_TUNNEL_MODE_INNER:
6782 rte_flow_error_set(error, EINVAL,
6783 RTE_FLOW_ERROR_TYPE_ITEM,
6784 NULL, "outer flex item was not configured");
6785 if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
6786 rte_flow_error_set(error, EINVAL,
6787 RTE_FLOW_ERROR_TYPE_ITEM,
6788 NULL, "multiple flex items not supported");
6790 case FLEX_TUNNEL_MODE_MULTI:
6791 if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
6792 (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
6793 rte_flow_error_set(error, EINVAL,
6794 RTE_FLOW_ERROR_TYPE_ITEM,
6795 NULL, "multiple flex items not supported");
6798 case FLEX_TUNNEL_MODE_TUNNEL:
6799 if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
6800 rte_flow_error_set(error, EINVAL,
6801 RTE_FLOW_ERROR_TYPE_ITEM,
6802 NULL, "multiple flex tunnel items not supported");
6805 rte_flow_error_set(error, EINVAL,
6806 RTE_FLOW_ERROR_TYPE_ITEM,
6807 NULL, "invalid flex item configuration");
6809 *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
6810 MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
6811 MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
6816 * Internal validation function. For validating both actions and items.
6819 * Pointer to the rte_eth_dev structure.
6821 * Pointer to the flow attributes.
6823 * Pointer to the list of items.
6824 * @param[in] actions
6825 * Pointer to the list of actions.
6826 * @param[in] external
6827 * This flow rule is created by request external to PMD.
6828 * @param[in] hairpin
6829 * Number of hairpin TX actions, 0 means classic flow.
6831 * Pointer to the error structure.
6834 * 0 on success, a negative errno value otherwise and rte_errno is set.
6837 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
6838 const struct rte_flow_item items[],
6839 const struct rte_flow_action actions[],
6840 bool external, int hairpin, struct rte_flow_error *error)
6843 uint64_t action_flags = 0;
6844 uint64_t item_flags = 0;
6845 uint64_t last_item = 0;
6846 uint8_t next_protocol = 0xff;
6847 uint16_t ether_type = 0;
6849 uint8_t item_ipv6_proto = 0;
6850 int fdb_mirror_limit = 0;
6851 int modify_after_mirror = 0;
6852 const struct rte_flow_item *geneve_item = NULL;
6853 const struct rte_flow_item *gre_item = NULL;
6854 const struct rte_flow_item *gtp_item = NULL;
6855 const struct rte_flow_action_raw_decap *decap;
6856 const struct rte_flow_action_raw_encap *encap;
6857 const struct rte_flow_action_rss *rss = NULL;
6858 const struct rte_flow_action_rss *sample_rss = NULL;
6859 const struct rte_flow_action_count *sample_count = NULL;
6860 const struct rte_flow_item_tcp nic_tcp_mask = {
6863 .src_port = RTE_BE16(UINT16_MAX),
6864 .dst_port = RTE_BE16(UINT16_MAX),
6867 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
6870 "\xff\xff\xff\xff\xff\xff\xff\xff"
6871 "\xff\xff\xff\xff\xff\xff\xff\xff",
6873 "\xff\xff\xff\xff\xff\xff\xff\xff"
6874 "\xff\xff\xff\xff\xff\xff\xff\xff",
6875 .vtc_flow = RTE_BE32(0xffffffff),
6881 const struct rte_flow_item_ecpri nic_ecpri_mask = {
6885 RTE_BE32(((const struct rte_ecpri_common_hdr) {
6889 .dummy[0] = 0xffffffff,
6892 struct mlx5_priv *priv = dev->data->dev_private;
6893 struct mlx5_sh_config *dev_conf = &priv->sh->config;
6894 uint16_t queue_index = 0xFFFF;
6895 const struct rte_flow_item_vlan *vlan_m = NULL;
6896 uint32_t rw_act_num = 0;
6898 const struct mlx5_flow_tunnel *tunnel;
6899 enum mlx5_tof_rule_type tof_rule_type;
6900 struct flow_grp_info grp_info = {
6901 .external = !!external,
6902 .transfer = !!attr->transfer,
6903 .fdb_def_rule = !!priv->fdb_def_rule,
6904 .std_tbl_fix = true,
6906 const struct rte_eth_hairpin_conf *conf;
6907 const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
6908 const struct rte_flow_item *port_id_item = NULL;
6909 bool def_policy = false;
6910 uint16_t udp_dport = 0;
6914 tunnel = is_tunnel_offload_active(dev) ?
6915 mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
6917 if (!dev_conf->dv_flow_en)
6918 return rte_flow_error_set
6920 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6921 NULL, "tunnel offload requires DV flow interface");
6922 if (priv->representor)
6923 return rte_flow_error_set
6925 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6926 NULL, "decap not supported for VF representor");
6927 if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
6928 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6929 else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
6930 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
6931 MLX5_FLOW_ACTION_DECAP;
6932 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
6933 (dev, attr, tunnel, tof_rule_type);
6935 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
6938 is_root = (uint64_t)ret;
6939 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6940 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
6941 int type = items->type;
6943 if (!mlx5_flow_os_item_supported(type))
6944 return rte_flow_error_set(error, ENOTSUP,
6945 RTE_FLOW_ERROR_TYPE_ITEM,
6946 NULL, "item not supported");
6948 case RTE_FLOW_ITEM_TYPE_VOID:
6950 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6951 ret = flow_dv_validate_item_port_id
6952 (dev, items, attr, item_flags, error);
6955 last_item = MLX5_FLOW_ITEM_PORT_ID;
6956 port_id_item = items;
6958 case RTE_FLOW_ITEM_TYPE_ETH:
6959 ret = mlx5_flow_validate_item_eth(items, item_flags,
6963 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
6964 MLX5_FLOW_LAYER_OUTER_L2;
6965 if (items->mask != NULL && items->spec != NULL) {
6967 ((const struct rte_flow_item_eth *)
6970 ((const struct rte_flow_item_eth *)
6972 ether_type = rte_be_to_cpu_16(ether_type);
6977 case RTE_FLOW_ITEM_TYPE_VLAN:
6978 ret = flow_dv_validate_item_vlan(items, item_flags,
6982 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
6983 MLX5_FLOW_LAYER_OUTER_VLAN;
6984 if (items->mask != NULL && items->spec != NULL) {
6986 ((const struct rte_flow_item_vlan *)
6987 items->spec)->inner_type;
6989 ((const struct rte_flow_item_vlan *)
6990 items->mask)->inner_type;
6991 ether_type = rte_be_to_cpu_16(ether_type);
6995 /* Store outer VLAN mask for of_push_vlan action. */
6997 vlan_m = items->mask;
6999 case RTE_FLOW_ITEM_TYPE_IPV4:
7000 mlx5_flow_tunnel_ip_check(items, next_protocol,
7001 &item_flags, &tunnel);
7002 ret = flow_dv_validate_item_ipv4(dev, items, item_flags,
7003 last_item, ether_type,
7007 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7008 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7009 if (items->mask != NULL &&
7010 ((const struct rte_flow_item_ipv4 *)
7011 items->mask)->hdr.next_proto_id) {
7013 ((const struct rte_flow_item_ipv4 *)
7014 (items->spec))->hdr.next_proto_id;
7016 ((const struct rte_flow_item_ipv4 *)
7017 (items->mask))->hdr.next_proto_id;
7019 /* Reset for inner layer. */
7020 next_protocol = 0xff;
7023 case RTE_FLOW_ITEM_TYPE_IPV6:
7024 mlx5_flow_tunnel_ip_check(items, next_protocol,
7025 &item_flags, &tunnel);
7026 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
7033 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7034 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7035 if (items->mask != NULL &&
7036 ((const struct rte_flow_item_ipv6 *)
7037 items->mask)->hdr.proto) {
7039 ((const struct rte_flow_item_ipv6 *)
7040 items->spec)->hdr.proto;
7042 ((const struct rte_flow_item_ipv6 *)
7043 items->spec)->hdr.proto;
7045 ((const struct rte_flow_item_ipv6 *)
7046 items->mask)->hdr.proto;
7048 /* Reset for inner layer. */
7049 next_protocol = 0xff;
7052 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7053 ret = flow_dv_validate_item_ipv6_frag_ext(items,
7058 last_item = tunnel ?
7059 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
7060 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
7061 if (items->mask != NULL &&
7062 ((const struct rte_flow_item_ipv6_frag_ext *)
7063 items->mask)->hdr.next_header) {
7065 ((const struct rte_flow_item_ipv6_frag_ext *)
7066 items->spec)->hdr.next_header;
7068 ((const struct rte_flow_item_ipv6_frag_ext *)
7069 items->mask)->hdr.next_header;
7071 /* Reset for inner layer. */
7072 next_protocol = 0xff;
7075 case RTE_FLOW_ITEM_TYPE_TCP:
7076 ret = mlx5_flow_validate_item_tcp
7083 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7084 MLX5_FLOW_LAYER_OUTER_L4_TCP;
7086 case RTE_FLOW_ITEM_TYPE_UDP:
7087 ret = mlx5_flow_validate_item_udp(items, item_flags,
7090 const struct rte_flow_item_udp *spec = items->spec;
7091 const struct rte_flow_item_udp *mask = items->mask;
7093 mask = &rte_flow_item_udp_mask;
7095 udp_dport = rte_be_to_cpu_16
7096 (spec->hdr.dst_port &
7097 mask->hdr.dst_port);
7100 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
7101 MLX5_FLOW_LAYER_OUTER_L4_UDP;
7103 case RTE_FLOW_ITEM_TYPE_GRE:
7104 ret = mlx5_flow_validate_item_gre(items, item_flags,
7105 next_protocol, error);
7109 last_item = MLX5_FLOW_LAYER_GRE;
7111 case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
7112 ret = mlx5_flow_validate_item_gre_option(dev, items, item_flags,
7113 attr, gre_item, error);
7116 last_item = MLX5_FLOW_LAYER_GRE;
7118 case RTE_FLOW_ITEM_TYPE_NVGRE:
7119 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
7124 last_item = MLX5_FLOW_LAYER_NVGRE;
7126 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7127 ret = mlx5_flow_validate_item_gre_key
7128 (items, item_flags, gre_item, error);
7131 last_item = MLX5_FLOW_LAYER_GRE_KEY;
7133 case RTE_FLOW_ITEM_TYPE_VXLAN:
7134 ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
7139 last_item = MLX5_FLOW_LAYER_VXLAN;
7141 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7142 ret = mlx5_flow_validate_item_vxlan_gpe(items,
7147 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
7149 case RTE_FLOW_ITEM_TYPE_GENEVE:
7150 ret = mlx5_flow_validate_item_geneve(items,
7155 geneve_item = items;
7156 last_item = MLX5_FLOW_LAYER_GENEVE;
7158 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
7159 ret = mlx5_flow_validate_item_geneve_opt(items,
7166 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
7168 case RTE_FLOW_ITEM_TYPE_MPLS:
7169 ret = mlx5_flow_validate_item_mpls(dev, items,
7174 last_item = MLX5_FLOW_LAYER_MPLS;
7177 case RTE_FLOW_ITEM_TYPE_MARK:
7178 ret = flow_dv_validate_item_mark(dev, items, attr,
7182 last_item = MLX5_FLOW_ITEM_MARK;
7184 case RTE_FLOW_ITEM_TYPE_META:
7185 ret = flow_dv_validate_item_meta(dev, items, attr,
7189 last_item = MLX5_FLOW_ITEM_METADATA;
7191 case RTE_FLOW_ITEM_TYPE_ICMP:
7192 ret = mlx5_flow_validate_item_icmp(items, item_flags,
7197 last_item = MLX5_FLOW_LAYER_ICMP;
7199 case RTE_FLOW_ITEM_TYPE_ICMP6:
7200 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
7205 item_ipv6_proto = IPPROTO_ICMPV6;
7206 last_item = MLX5_FLOW_LAYER_ICMP6;
7208 case RTE_FLOW_ITEM_TYPE_TAG:
7209 ret = flow_dv_validate_item_tag(dev, items,
7213 last_item = MLX5_FLOW_ITEM_TAG;
7215 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7216 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
7218 case RTE_FLOW_ITEM_TYPE_GTP:
7219 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
7224 last_item = MLX5_FLOW_LAYER_GTP;
7226 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
7227 ret = flow_dv_validate_item_gtp_psc(items, last_item,
7232 last_item = MLX5_FLOW_LAYER_GTP_PSC;
7234 case RTE_FLOW_ITEM_TYPE_ECPRI:
7235 /* Capacity will be checked in the translate stage. */
7236 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
7243 last_item = MLX5_FLOW_LAYER_ECPRI;
7245 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
7246 ret = flow_dv_validate_item_integrity(dev, items,
7254 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
7255 ret = flow_dv_validate_item_aso_ct(dev, items,
7256 &item_flags, error);
7260 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
7261 /* tunnel offload item was processed before
7262 * list it here as a supported type
7265 case RTE_FLOW_ITEM_TYPE_FLEX:
7266 ret = flow_dv_validate_item_flex(dev, items, item_flags,
7268 tunnel != 0, error);
7273 return rte_flow_error_set(error, ENOTSUP,
7274 RTE_FLOW_ERROR_TYPE_ITEM,
7275 NULL, "item not supported");
7277 item_flags |= last_item;
7279 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
7280 ret = flow_dv_validate_item_integrity_post(integrity_items,
7285 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
7286 int type = actions->type;
7287 bool shared_count = false;
7289 if (!mlx5_flow_os_action_supported(type))
7290 return rte_flow_error_set(error, ENOTSUP,
7291 RTE_FLOW_ERROR_TYPE_ACTION,
7293 "action not supported");
7294 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
7295 return rte_flow_error_set(error, ENOTSUP,
7296 RTE_FLOW_ERROR_TYPE_ACTION,
7297 actions, "too many actions");
7299 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
7300 return rte_flow_error_set(error, ENOTSUP,
7301 RTE_FLOW_ERROR_TYPE_ACTION,
7302 NULL, "meter action with policy "
7303 "must be the last action");
7305 case RTE_FLOW_ACTION_TYPE_VOID:
7307 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7308 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
7309 ret = flow_dv_validate_action_port_id(dev,
7316 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7319 case RTE_FLOW_ACTION_TYPE_FLAG:
7320 ret = flow_dv_validate_action_flag(dev, action_flags,
7324 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7325 /* Count all modify-header actions as one. */
7326 if (!(action_flags &
7327 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7329 action_flags |= MLX5_FLOW_ACTION_FLAG |
7330 MLX5_FLOW_ACTION_MARK_EXT;
7331 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7332 modify_after_mirror = 1;
7335 action_flags |= MLX5_FLOW_ACTION_FLAG;
7338 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7340 case RTE_FLOW_ACTION_TYPE_MARK:
7341 ret = flow_dv_validate_action_mark(dev, actions,
7346 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7347 /* Count all modify-header actions as one. */
7348 if (!(action_flags &
7349 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7351 action_flags |= MLX5_FLOW_ACTION_MARK |
7352 MLX5_FLOW_ACTION_MARK_EXT;
7353 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7354 modify_after_mirror = 1;
7356 action_flags |= MLX5_FLOW_ACTION_MARK;
7359 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7361 case RTE_FLOW_ACTION_TYPE_SET_META:
7362 ret = flow_dv_validate_action_set_meta(dev, actions,
7367 /* Count all modify-header actions as one action. */
7368 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7370 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7371 modify_after_mirror = 1;
7372 action_flags |= MLX5_FLOW_ACTION_SET_META;
7373 rw_act_num += MLX5_ACT_NUM_SET_META;
7375 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7376 ret = flow_dv_validate_action_set_tag(dev, actions,
7381 /* Count all modify-header actions as one action. */
7382 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7384 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7385 modify_after_mirror = 1;
7386 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7387 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7389 case RTE_FLOW_ACTION_TYPE_DROP:
7390 ret = mlx5_flow_validate_action_drop(action_flags,
7394 action_flags |= MLX5_FLOW_ACTION_DROP;
7397 case RTE_FLOW_ACTION_TYPE_QUEUE:
7398 ret = mlx5_flow_validate_action_queue(actions,
7403 queue_index = ((const struct rte_flow_action_queue *)
7404 (actions->conf))->index;
7405 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7408 case RTE_FLOW_ACTION_TYPE_RSS:
7409 rss = actions->conf;
7410 ret = mlx5_flow_validate_action_rss(actions,
7416 if (rss && sample_rss &&
7417 (sample_rss->level != rss->level ||
7418 sample_rss->types != rss->types))
7419 return rte_flow_error_set(error, ENOTSUP,
7420 RTE_FLOW_ERROR_TYPE_ACTION,
7422 "Can't use the different RSS types "
7423 "or level in the same flow");
7424 if (rss != NULL && rss->queue_num)
7425 queue_index = rss->queue[0];
7426 action_flags |= MLX5_FLOW_ACTION_RSS;
7429 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7431 mlx5_flow_validate_action_default_miss(action_flags,
7435 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
7438 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
7439 shared_count = true;
7441 case RTE_FLOW_ACTION_TYPE_COUNT:
7442 ret = flow_dv_validate_action_count(dev, shared_count,
7447 action_flags |= MLX5_FLOW_ACTION_COUNT;
7450 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7451 if (flow_dv_validate_action_pop_vlan(dev,
7457 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7458 modify_after_mirror = 1;
7459 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7462 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7463 ret = flow_dv_validate_action_push_vlan(dev,
7470 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7471 modify_after_mirror = 1;
7472 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7475 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7476 ret = flow_dv_validate_action_set_vlan_pcp
7477 (action_flags, actions, error);
7480 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7481 modify_after_mirror = 1;
7482 /* Count PCP with push_vlan command. */
7483 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
7485 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7486 ret = flow_dv_validate_action_set_vlan_vid
7487 (item_flags, action_flags,
7491 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7492 modify_after_mirror = 1;
7493 /* Count VID with push_vlan command. */
7494 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7495 rw_act_num += MLX5_ACT_NUM_MDF_VID;
7497 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7498 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7499 ret = flow_dv_validate_action_l2_encap(dev,
7505 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7508 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7509 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7510 ret = flow_dv_validate_action_decap(dev, action_flags,
7511 actions, item_flags,
7515 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7516 modify_after_mirror = 1;
7517 action_flags |= MLX5_FLOW_ACTION_DECAP;
7520 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7521 ret = flow_dv_validate_action_raw_encap_decap
7522 (dev, NULL, actions->conf, attr, &action_flags,
7523 &actions_n, actions, item_flags, error);
7527 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7528 decap = actions->conf;
7529 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
7531 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7535 encap = actions->conf;
7537 ret = flow_dv_validate_action_raw_encap_decap
7539 decap ? decap : &empty_decap, encap,
7540 attr, &action_flags, &actions_n,
7541 actions, item_flags, error);
7544 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7545 (action_flags & MLX5_FLOW_ACTION_DECAP))
7546 modify_after_mirror = 1;
7548 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7549 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7550 ret = flow_dv_validate_action_modify_mac(action_flags,
7556 /* Count all modify-header actions as one action. */
7557 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7559 action_flags |= actions->type ==
7560 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7561 MLX5_FLOW_ACTION_SET_MAC_SRC :
7562 MLX5_FLOW_ACTION_SET_MAC_DST;
7563 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7564 modify_after_mirror = 1;
7566 * Even if the source and destination MAC addresses have
7567 * overlap in the header with 4B alignment, the convert
7568 * function will handle them separately and 4 SW actions
7569 * will be created. And 2 actions will be added each
7570 * time no matter how many bytes of address will be set.
7572 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
7574 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7575 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7576 ret = flow_dv_validate_action_modify_ipv4(action_flags,
7582 /* Count all modify-header actions as one action. */
7583 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7585 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7586 modify_after_mirror = 1;
7587 action_flags |= actions->type ==
7588 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7589 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7590 MLX5_FLOW_ACTION_SET_IPV4_DST;
7591 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
7593 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7594 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7595 ret = flow_dv_validate_action_modify_ipv6(action_flags,
7601 if (item_ipv6_proto == IPPROTO_ICMPV6)
7602 return rte_flow_error_set(error, ENOTSUP,
7603 RTE_FLOW_ERROR_TYPE_ACTION,
7605 "Can't change header "
7606 "with ICMPv6 proto");
7607 /* Count all modify-header actions as one action. */
7608 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7610 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7611 modify_after_mirror = 1;
7612 action_flags |= actions->type ==
7613 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7614 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7615 MLX5_FLOW_ACTION_SET_IPV6_DST;
7616 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
7618 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7619 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7620 ret = flow_dv_validate_action_modify_tp(action_flags,
7626 /* Count all modify-header actions as one action. */
7627 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7629 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7630 modify_after_mirror = 1;
7631 action_flags |= actions->type ==
7632 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7633 MLX5_FLOW_ACTION_SET_TP_SRC :
7634 MLX5_FLOW_ACTION_SET_TP_DST;
7635 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
7637 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7638 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7639 ret = flow_dv_validate_action_modify_ttl(action_flags,
7645 /* Count all modify-header actions as one action. */
7646 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7648 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7649 modify_after_mirror = 1;
7650 action_flags |= actions->type ==
7651 RTE_FLOW_ACTION_TYPE_SET_TTL ?
7652 MLX5_FLOW_ACTION_SET_TTL :
7653 MLX5_FLOW_ACTION_DEC_TTL;
7654 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
7656 case RTE_FLOW_ACTION_TYPE_JUMP:
7657 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
7663 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7665 return rte_flow_error_set(error, EINVAL,
7666 RTE_FLOW_ERROR_TYPE_ACTION,
7668 "sample and jump action combination is not supported");
7670 action_flags |= MLX5_FLOW_ACTION_JUMP;
7672 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7673 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7674 ret = flow_dv_validate_action_modify_tcp_seq
7681 /* Count all modify-header actions as one action. */
7682 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7684 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7685 modify_after_mirror = 1;
7686 action_flags |= actions->type ==
7687 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7688 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7689 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7690 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
7692 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7693 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7694 ret = flow_dv_validate_action_modify_tcp_ack
7701 /* Count all modify-header actions as one action. */
7702 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7704 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7705 modify_after_mirror = 1;
7706 action_flags |= actions->type ==
7707 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7708 MLX5_FLOW_ACTION_INC_TCP_ACK :
7709 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7710 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
7712 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7714 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7715 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7716 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7718 case RTE_FLOW_ACTION_TYPE_METER:
7719 ret = mlx5_flow_validate_action_meter(dev,
7728 action_flags |= MLX5_FLOW_ACTION_METER;
7731 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
7733 /* Meter action will add one more TAG action. */
7734 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7736 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
7737 if (!attr->transfer && !attr->group)
7738 return rte_flow_error_set(error, ENOTSUP,
7739 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7741 "Shared ASO age action is not supported for group 0");
7742 if (action_flags & MLX5_FLOW_ACTION_AGE)
7743 return rte_flow_error_set
7745 RTE_FLOW_ERROR_TYPE_ACTION,
7747 "duplicate age actions set");
7748 action_flags |= MLX5_FLOW_ACTION_AGE;
7751 case RTE_FLOW_ACTION_TYPE_AGE:
7752 ret = flow_dv_validate_action_age(action_flags,
7758 * Validate the regular AGE action (using counter)
7759 * mutual exclusion with share counter actions.
7761 if (!priv->sh->flow_hit_aso_en) {
7763 return rte_flow_error_set
7765 RTE_FLOW_ERROR_TYPE_ACTION,
7767 "old age and shared count combination is not supported");
7769 return rte_flow_error_set
7771 RTE_FLOW_ERROR_TYPE_ACTION,
7773 "old age action and count must be in the same sub flow");
7775 action_flags |= MLX5_FLOW_ACTION_AGE;
7778 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7779 ret = flow_dv_validate_action_modify_ipv4_dscp
7786 /* Count all modify-header actions as one action. */
7787 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7789 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7790 modify_after_mirror = 1;
7791 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7792 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7794 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7795 ret = flow_dv_validate_action_modify_ipv6_dscp
7802 /* Count all modify-header actions as one action. */
7803 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7805 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7806 modify_after_mirror = 1;
7807 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7808 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7810 case RTE_FLOW_ACTION_TYPE_SAMPLE:
7811 ret = flow_dv_validate_action_sample(&action_flags,
7820 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
7823 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7824 ret = flow_dv_validate_action_modify_field(dev,
7831 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7832 modify_after_mirror = 1;
7833 /* Count all modify-header actions as one action. */
7834 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7836 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
7839 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7840 ret = flow_dv_validate_action_aso_ct(dev, action_flags,
7845 action_flags |= MLX5_FLOW_ACTION_CT;
7847 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
7848 /* tunnel offload action was processed before
7849 * list it here as a supported type
7853 return rte_flow_error_set(error, ENOTSUP,
7854 RTE_FLOW_ERROR_TYPE_ACTION,
7856 "action not supported");
7860 * Validate actions in flow rules
7861 * - Explicit decap action is prohibited by the tunnel offload API.
7862 * - Drop action in tunnel steer rule is prohibited by the API.
7863 * - Application cannot use MARK action because it's value can mask
7864 * tunnel default miss notification.
7865 * - JUMP in tunnel match rule has no support in current PMD
7867 * - TAG & META are reserved for future uses.
7869 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
7870 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
7871 MLX5_FLOW_ACTION_MARK |
7872 MLX5_FLOW_ACTION_SET_TAG |
7873 MLX5_FLOW_ACTION_SET_META |
7874 MLX5_FLOW_ACTION_DROP;
7876 if (action_flags & bad_actions_mask)
7877 return rte_flow_error_set
7879 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7880 "Invalid RTE action in tunnel "
7882 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
7883 return rte_flow_error_set
7885 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7886 "tunnel set decap rule must terminate "
7889 return rte_flow_error_set
7891 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7892 "tunnel flows for ingress traffic only");
7894 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
7895 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
7896 MLX5_FLOW_ACTION_MARK |
7897 MLX5_FLOW_ACTION_SET_TAG |
7898 MLX5_FLOW_ACTION_SET_META;
7900 if (action_flags & bad_actions_mask)
7901 return rte_flow_error_set
7903 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7904 "Invalid RTE action in tunnel "
7908 * Validate the drop action mutual exclusion with other actions.
7909 * Drop action is mutually-exclusive with any other action, except for
7911 * Drop action compatibility with tunnel offload was already validated.
7913 if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
7914 MLX5_FLOW_ACTION_TUNNEL_MATCH));
7915 else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
7916 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
7917 return rte_flow_error_set(error, EINVAL,
7918 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7919 "Drop action is mutually-exclusive "
7920 "with any other action, except for "
7922 /* Eswitch has few restrictions on using items and actions */
7923 if (attr->transfer) {
7924 if (!mlx5_flow_ext_mreg_supported(dev) &&
7925 action_flags & MLX5_FLOW_ACTION_FLAG)
7926 return rte_flow_error_set(error, ENOTSUP,
7927 RTE_FLOW_ERROR_TYPE_ACTION,
7929 "unsupported action FLAG");
7930 if (!mlx5_flow_ext_mreg_supported(dev) &&
7931 action_flags & MLX5_FLOW_ACTION_MARK)
7932 return rte_flow_error_set(error, ENOTSUP,
7933 RTE_FLOW_ERROR_TYPE_ACTION,
7935 "unsupported action MARK");
7936 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
7937 return rte_flow_error_set(error, ENOTSUP,
7938 RTE_FLOW_ERROR_TYPE_ACTION,
7940 "unsupported action QUEUE");
7941 if (action_flags & MLX5_FLOW_ACTION_RSS)
7942 return rte_flow_error_set(error, ENOTSUP,
7943 RTE_FLOW_ERROR_TYPE_ACTION,
7945 "unsupported action RSS");
7946 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
7947 return rte_flow_error_set(error, EINVAL,
7948 RTE_FLOW_ERROR_TYPE_ACTION,
7950 "no fate action is found");
7952 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
7953 return rte_flow_error_set(error, EINVAL,
7954 RTE_FLOW_ERROR_TYPE_ACTION,
7956 "no fate action is found");
7959 * Continue validation for Xcap and VLAN actions.
7960 * If hairpin is working in explicit TX rule mode, there is no actions
7961 * splitting and the validation of hairpin ingress flow should be the
7962 * same as other standard flows.
7964 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
7965 MLX5_FLOW_VLAN_ACTIONS)) &&
7966 (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index) ||
7967 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
7968 conf->tx_explicit != 0))) {
7969 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
7970 MLX5_FLOW_XCAP_ACTIONS)
7971 return rte_flow_error_set(error, ENOTSUP,
7972 RTE_FLOW_ERROR_TYPE_ACTION,
7973 NULL, "encap and decap "
7974 "combination aren't supported");
7975 if (!attr->transfer && attr->ingress) {
7976 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7977 return rte_flow_error_set
7979 RTE_FLOW_ERROR_TYPE_ACTION,
7980 NULL, "encap is not supported"
7981 " for ingress traffic");
7982 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7983 return rte_flow_error_set
7985 RTE_FLOW_ERROR_TYPE_ACTION,
7986 NULL, "push VLAN action not "
7987 "supported for ingress");
7988 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
7989 MLX5_FLOW_VLAN_ACTIONS)
7990 return rte_flow_error_set
7992 RTE_FLOW_ERROR_TYPE_ACTION,
7993 NULL, "no support for "
7994 "multiple VLAN actions");
7997 if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
7998 if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
7999 ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
8001 return rte_flow_error_set
8003 RTE_FLOW_ERROR_TYPE_ACTION,
8004 NULL, "fate action not supported for "
8005 "meter with policy");
8007 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
8008 return rte_flow_error_set
8010 RTE_FLOW_ERROR_TYPE_ACTION,
8011 NULL, "modify header action in egress "
8012 "cannot be done before meter action");
8013 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
8014 return rte_flow_error_set
8016 RTE_FLOW_ERROR_TYPE_ACTION,
8017 NULL, "encap action in egress "
8018 "cannot be done before meter action");
8019 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
8020 return rte_flow_error_set
8022 RTE_FLOW_ERROR_TYPE_ACTION,
8023 NULL, "push vlan action in egress "
8024 "cannot be done before meter action");
8028 * Hairpin flow will add one more TAG action in TX implicit mode.
8029 * In TX explicit mode, there will be no hairpin flow ID.
8032 rw_act_num += MLX5_ACT_NUM_SET_TAG;
8033 /* extra metadata enabled: one more TAG action will be add. */
8034 if (dev_conf->dv_flow_en &&
8035 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
8036 mlx5_flow_ext_mreg_supported(dev))
8037 rw_act_num += MLX5_ACT_NUM_SET_TAG;
8039 flow_dv_modify_hdr_action_max(dev, is_root)) {
8040 return rte_flow_error_set(error, ENOTSUP,
8041 RTE_FLOW_ERROR_TYPE_ACTION,
8042 NULL, "too many header modify"
8043 " actions to support");
8045 /* Eswitch egress mirror and modify flow has limitation on CX5 */
8046 if (fdb_mirror_limit && modify_after_mirror)
8047 return rte_flow_error_set(error, EINVAL,
8048 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8049 "sample before modify action is not supported");
8054 * Internal preparation function. Allocates the DV flow size,
8055 * this size is constant.
8058 * Pointer to the rte_eth_dev structure.
8060 * Pointer to the flow attributes.
8062 * Pointer to the list of items.
8063 * @param[in] actions
8064 * Pointer to the list of actions.
8066 * Pointer to the error structure.
8069 * Pointer to mlx5_flow object on success,
8070 * otherwise NULL and rte_errno is set.
8072 static struct mlx5_flow *
8073 flow_dv_prepare(struct rte_eth_dev *dev,
8074 const struct rte_flow_attr *attr __rte_unused,
8075 const struct rte_flow_item items[] __rte_unused,
8076 const struct rte_flow_action actions[] __rte_unused,
8077 struct rte_flow_error *error)
8079 uint32_t handle_idx = 0;
8080 struct mlx5_flow *dev_flow;
8081 struct mlx5_flow_handle *dev_handle;
8082 struct mlx5_priv *priv = dev->data->dev_private;
8083 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
8086 wks->skip_matcher_reg = 0;
8088 wks->final_policy = NULL;
8089 /* In case of corrupting the memory. */
8090 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
8091 rte_flow_error_set(error, ENOSPC,
8092 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8093 "not free temporary device flow");
8096 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8099 rte_flow_error_set(error, ENOMEM,
8100 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8101 "not enough memory to create flow handle");
8104 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
8105 dev_flow = &wks->flows[wks->flow_idx++];
8106 memset(dev_flow, 0, sizeof(*dev_flow));
8107 dev_flow->handle = dev_handle;
8108 dev_flow->handle_idx = handle_idx;
8109 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
8110 dev_flow->ingress = attr->ingress;
8111 dev_flow->dv.transfer = attr->transfer;
8115 #ifdef RTE_LIBRTE_MLX5_DEBUG
8117 * Sanity check for match mask and value. Similar to check_valid_spec() in
8118 * kernel driver. If unmasked bit is present in value, it returns failure.
8121 * pointer to match mask buffer.
8122 * @param match_value
8123 * pointer to match value buffer.
8126 * 0 if valid, -EINVAL otherwise.
8129 flow_dv_check_valid_spec(void *match_mask, void *match_value)
8131 uint8_t *m = match_mask;
8132 uint8_t *v = match_value;
8135 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
8138 "match_value differs from match_criteria"
8139 " %p[%u] != %p[%u]",
8140 match_value, i, match_mask, i);
8149 * Add match of ip_version.
8153 * @param[in] headers_v
8154 * Values header pointer.
8155 * @param[in] headers_m
8156 * Masks header pointer.
8157 * @param[in] ip_version
8158 * The IP version to set.
8161 flow_dv_set_match_ip_version(uint32_t group,
8167 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
8169 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
8171 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
8172 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
8173 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
8177 * Add Ethernet item to matcher and to the value.
8179 * @param[in, out] matcher
8181 * @param[in, out] key
8182 * Flow matcher value.
8184 * Flow pattern to translate.
8186 * Item is inner pattern.
8189 flow_dv_translate_item_eth(void *matcher, void *key,
8190 const struct rte_flow_item *item, int inner,
8193 const struct rte_flow_item_eth *eth_m = item->mask;
8194 const struct rte_flow_item_eth *eth_v = item->spec;
8195 const struct rte_flow_item_eth nic_mask = {
8196 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8197 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8198 .type = RTE_BE16(0xffff),
8211 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8213 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8215 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8217 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8219 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
8220 ð_m->dst, sizeof(eth_m->dst));
8221 /* The value must be in the range of the mask. */
8222 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
8223 for (i = 0; i < sizeof(eth_m->dst); ++i)
8224 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
8225 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
8226 ð_m->src, sizeof(eth_m->src));
8227 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
8228 /* The value must be in the range of the mask. */
8229 for (i = 0; i < sizeof(eth_m->dst); ++i)
8230 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
8232 * HW supports match on one Ethertype, the Ethertype following the last
8233 * VLAN tag of the packet (see PRM).
8234 * Set match on ethertype only if ETH header is not followed by VLAN.
8235 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8236 * ethertype, and use ip_version field instead.
8237 * eCPRI over Ether layer will use type value 0xAEFE.
8239 if (eth_m->type == 0xFFFF) {
8240 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
8241 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8242 switch (eth_v->type) {
8243 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8244 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8246 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
8247 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8248 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8250 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8251 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8253 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8254 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8260 if (eth_m->has_vlan) {
8261 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8262 if (eth_v->has_vlan) {
8264 * Here, when also has_more_vlan field in VLAN item is
8265 * not set, only single-tagged packets will be matched.
8267 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8271 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8272 rte_be_to_cpu_16(eth_m->type));
8273 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
8274 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
8278 * Add VLAN item to matcher and to the value.
8280 * @param[in, out] dev_flow
8282 * @param[in, out] matcher
8284 * @param[in, out] key
8285 * Flow matcher value.
8287 * Flow pattern to translate.
8289 * Item is inner pattern.
8292 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
8293 void *matcher, void *key,
8294 const struct rte_flow_item *item,
8295 int inner, uint32_t group)
8297 const struct rte_flow_item_vlan *vlan_m = item->mask;
8298 const struct rte_flow_item_vlan *vlan_v = item->spec;
8305 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8307 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8309 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8311 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8313 * This is workaround, masks are not supported,
8314 * and pre-validated.
8317 dev_flow->handle->vf_vlan.tag =
8318 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
8321 * When VLAN item exists in flow, mark packet as tagged,
8322 * even if TCI is not specified.
8324 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
8325 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8326 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8331 vlan_m = &rte_flow_item_vlan_mask;
8332 tci_m = rte_be_to_cpu_16(vlan_m->tci);
8333 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
8334 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
8335 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
8336 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
8337 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
8338 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
8339 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
8341 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8342 * ethertype, and use ip_version field instead.
8344 if (vlan_m->inner_type == 0xFFFF) {
8345 switch (vlan_v->inner_type) {
8346 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8347 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8348 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8349 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8351 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8352 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8354 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8355 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8361 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
8362 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8363 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8364 /* Only one vlan_tag bit can be set. */
8365 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8368 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8369 rte_be_to_cpu_16(vlan_m->inner_type));
8370 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
8371 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
8375 * Add IPV4 item to matcher and to the value.
8377 * @param[in, out] matcher
8379 * @param[in, out] key
8380 * Flow matcher value.
8382 * Flow pattern to translate.
8384 * Item is inner pattern.
8386 * The group to insert the rule.
8389 flow_dv_translate_item_ipv4(void *matcher, void *key,
8390 const struct rte_flow_item *item,
8391 int inner, uint32_t group)
8393 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
8394 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
8395 const struct rte_flow_item_ipv4 nic_mask = {
8397 .src_addr = RTE_BE32(0xffffffff),
8398 .dst_addr = RTE_BE32(0xffffffff),
8399 .type_of_service = 0xff,
8400 .next_proto_id = 0xff,
8401 .time_to_live = 0xff,
8408 uint8_t tos, ihl_m, ihl_v;
8411 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8413 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8415 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8417 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8419 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
8424 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8425 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8426 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8427 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8428 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
8429 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
8430 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8431 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8432 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8433 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8434 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
8435 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
8436 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
8437 ihl_m = ipv4_m->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8438 ihl_v = ipv4_v->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8439 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_ihl, ihl_m);
8440 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl, ihl_m & ihl_v);
8441 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
8442 ipv4_m->hdr.type_of_service);
8443 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
8444 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
8445 ipv4_m->hdr.type_of_service >> 2);
8446 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
8447 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8448 ipv4_m->hdr.next_proto_id);
8449 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8450 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
8451 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8452 ipv4_m->hdr.time_to_live);
8453 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8454 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
8455 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8456 !!(ipv4_m->hdr.fragment_offset));
8457 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8458 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
8462 * Add IPV6 item to matcher and to the value.
8464 * @param[in, out] matcher
8466 * @param[in, out] key
8467 * Flow matcher value.
8469 * Flow pattern to translate.
8471 * Item is inner pattern.
8473 * The group to insert the rule.
8476 flow_dv_translate_item_ipv6(void *matcher, void *key,
8477 const struct rte_flow_item *item,
8478 int inner, uint32_t group)
8480 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
8481 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
8482 const struct rte_flow_item_ipv6 nic_mask = {
8485 "\xff\xff\xff\xff\xff\xff\xff\xff"
8486 "\xff\xff\xff\xff\xff\xff\xff\xff",
8488 "\xff\xff\xff\xff\xff\xff\xff\xff"
8489 "\xff\xff\xff\xff\xff\xff\xff\xff",
8490 .vtc_flow = RTE_BE32(0xffffffff),
8497 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8498 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8507 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8509 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8511 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8513 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8515 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
8520 size = sizeof(ipv6_m->hdr.dst_addr);
8521 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8522 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8523 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8524 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8525 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
8526 for (i = 0; i < size; ++i)
8527 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
8528 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8529 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8530 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8531 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8532 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
8533 for (i = 0; i < size; ++i)
8534 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
8536 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
8537 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
8538 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
8539 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
8540 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
8541 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
8544 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
8546 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
8549 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
8551 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
8555 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8557 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8558 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
8560 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8561 ipv6_m->hdr.hop_limits);
8562 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8563 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
8564 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8565 !!(ipv6_m->has_frag_ext));
8566 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8567 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
8571 * Add IPV6 fragment extension item to matcher and to the value.
8573 * @param[in, out] matcher
8575 * @param[in, out] key
8576 * Flow matcher value.
8578 * Flow pattern to translate.
8580 * Item is inner pattern.
8583 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
8584 const struct rte_flow_item *item,
8587 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
8588 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
8589 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
8591 .next_header = 0xff,
8592 .frag_data = RTE_BE16(0xffff),
8599 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8601 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8603 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8605 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8607 /* IPv6 fragment extension item exists, so packet is IP fragment. */
8608 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
8609 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
8610 if (!ipv6_frag_ext_v)
8612 if (!ipv6_frag_ext_m)
8613 ipv6_frag_ext_m = &nic_mask;
8614 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8615 ipv6_frag_ext_m->hdr.next_header);
8616 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8617 ipv6_frag_ext_v->hdr.next_header &
8618 ipv6_frag_ext_m->hdr.next_header);
8622 * Add TCP item to matcher and to the value.
8624 * @param[in, out] matcher
8626 * @param[in, out] key
8627 * Flow matcher value.
8629 * Flow pattern to translate.
8631 * Item is inner pattern.
8634 flow_dv_translate_item_tcp(void *matcher, void *key,
8635 const struct rte_flow_item *item,
8638 const struct rte_flow_item_tcp *tcp_m = item->mask;
8639 const struct rte_flow_item_tcp *tcp_v = item->spec;
8644 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8646 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8648 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8650 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8652 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8653 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
8657 tcp_m = &rte_flow_item_tcp_mask;
8658 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
8659 rte_be_to_cpu_16(tcp_m->hdr.src_port));
8660 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
8661 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
8662 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
8663 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
8664 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
8665 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
8666 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
8667 tcp_m->hdr.tcp_flags);
8668 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
8669 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
8673 * Add UDP item to matcher and to the value.
8675 * @param[in, out] matcher
8677 * @param[in, out] key
8678 * Flow matcher value.
8680 * Flow pattern to translate.
8682 * Item is inner pattern.
8685 flow_dv_translate_item_udp(void *matcher, void *key,
8686 const struct rte_flow_item *item,
8689 const struct rte_flow_item_udp *udp_m = item->mask;
8690 const struct rte_flow_item_udp *udp_v = item->spec;
8695 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8697 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8699 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8701 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8703 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8704 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
8708 udp_m = &rte_flow_item_udp_mask;
8709 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
8710 rte_be_to_cpu_16(udp_m->hdr.src_port));
8711 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
8712 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
8713 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
8714 rte_be_to_cpu_16(udp_m->hdr.dst_port));
8715 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8716 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
8720 * Add GRE optional Key item to matcher and to the value.
8722 * @param[in, out] matcher
8724 * @param[in, out] key
8725 * Flow matcher value.
8727 * Flow pattern to translate.
8729 * Item is inner pattern.
8732 flow_dv_translate_item_gre_key(void *matcher, void *key,
8733 const struct rte_flow_item *item)
8735 const rte_be32_t *key_m = item->mask;
8736 const rte_be32_t *key_v = item->spec;
8737 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8738 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8739 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
8741 /* GRE K bit must be on and should already be validated */
8742 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
8743 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
8747 key_m = &gre_key_default_mask;
8748 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
8749 rte_be_to_cpu_32(*key_m) >> 8);
8750 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
8751 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
8752 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
8753 rte_be_to_cpu_32(*key_m) & 0xFF);
8754 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
8755 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
8759 * Add GRE item to matcher and to the value.
8761 * @param[in, out] matcher
8763 * @param[in, out] key
8764 * Flow matcher value.
8766 * Flow pattern to translate.
8767 * @param[in] pattern_flags
8768 * Accumulated pattern flags.
8771 flow_dv_translate_item_gre(void *matcher, void *key,
8772 const struct rte_flow_item *item,
8773 uint64_t pattern_flags)
8775 static const struct rte_flow_item_gre empty_gre = {0,};
8776 const struct rte_flow_item_gre *gre_m = item->mask;
8777 const struct rte_flow_item_gre *gre_v = item->spec;
8778 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
8779 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8780 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8781 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8788 uint16_t s_present:1;
8789 uint16_t k_present:1;
8790 uint16_t rsvd_bit1:1;
8791 uint16_t c_present:1;
8795 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
8796 uint16_t protocol_m, protocol_v;
8798 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8799 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
8805 gre_m = &rte_flow_item_gre_mask;
8807 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
8808 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
8809 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
8810 gre_crks_rsvd0_ver_m.c_present);
8811 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
8812 gre_crks_rsvd0_ver_v.c_present &
8813 gre_crks_rsvd0_ver_m.c_present);
8814 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
8815 gre_crks_rsvd0_ver_m.k_present);
8816 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
8817 gre_crks_rsvd0_ver_v.k_present &
8818 gre_crks_rsvd0_ver_m.k_present);
8819 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
8820 gre_crks_rsvd0_ver_m.s_present);
8821 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
8822 gre_crks_rsvd0_ver_v.s_present &
8823 gre_crks_rsvd0_ver_m.s_present);
8824 protocol_m = rte_be_to_cpu_16(gre_m->protocol);
8825 protocol_v = rte_be_to_cpu_16(gre_v->protocol);
8827 /* Force next protocol to prevent matchers duplication */
8828 protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
8830 protocol_m = 0xFFFF;
8832 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, protocol_m);
8833 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8834 protocol_m & protocol_v);
8838 * Add GRE optional items to matcher and to the value.
8840 * @param[in, out] matcher
8842 * @param[in, out] key
8843 * Flow matcher value.
8845 * Flow pattern to translate.
8846 * @param[in] gre_item
8847 * Pointer to gre_item.
8848 * @param[in] pattern_flags
8849 * Accumulated pattern flags.
8852 flow_dv_translate_item_gre_option(void *matcher, void *key,
8853 const struct rte_flow_item *item,
8854 const struct rte_flow_item *gre_item,
8855 uint64_t pattern_flags)
8857 const struct rte_flow_item_gre_opt *option_m = item->mask;
8858 const struct rte_flow_item_gre_opt *option_v = item->spec;
8859 const struct rte_flow_item_gre *gre_m = gre_item->mask;
8860 const struct rte_flow_item_gre *gre_v = gre_item->spec;
8861 static const struct rte_flow_item_gre empty_gre = {0};
8862 struct rte_flow_item gre_key_item;
8863 uint16_t c_rsvd0_ver_m, c_rsvd0_ver_v;
8864 uint16_t protocol_m, protocol_v;
8869 * If only match key field, keep using misc for matching.
8870 * If need to match checksum or sequence, using misc5 and do
8871 * not need using misc.
8873 if (!(option_m->sequence.sequence ||
8874 option_m->checksum_rsvd.checksum)) {
8875 flow_dv_translate_item_gre(matcher, key, gre_item,
8877 gre_key_item.spec = &option_v->key.key;
8878 gre_key_item.mask = &option_m->key.key;
8879 flow_dv_translate_item_gre_key(matcher, key, &gre_key_item);
8887 gre_m = &rte_flow_item_gre_mask;
8889 protocol_v = gre_v->protocol;
8890 protocol_m = gre_m->protocol;
8892 /* Force next protocol to prevent matchers duplication */
8893 uint16_t ether_type =
8894 mlx5_translate_tunnel_etypes(pattern_flags);
8896 protocol_v = rte_be_to_cpu_16(ether_type);
8897 protocol_m = UINT16_MAX;
8900 c_rsvd0_ver_v = gre_v->c_rsvd0_ver;
8901 c_rsvd0_ver_m = gre_m->c_rsvd0_ver;
8902 if (option_m->sequence.sequence) {
8903 c_rsvd0_ver_v |= RTE_BE16(0x1000);
8904 c_rsvd0_ver_m |= RTE_BE16(0x1000);
8906 if (option_m->key.key) {
8907 c_rsvd0_ver_v |= RTE_BE16(0x2000);
8908 c_rsvd0_ver_m |= RTE_BE16(0x2000);
8910 if (option_m->checksum_rsvd.checksum) {
8911 c_rsvd0_ver_v |= RTE_BE16(0x8000);
8912 c_rsvd0_ver_m |= RTE_BE16(0x8000);
8915 * Hardware parses GRE optional field into the fixed location,
8916 * do not need to adjust the tunnel dword indices.
8918 misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
8919 misc5_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_5);
8920 MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0,
8921 rte_be_to_cpu_32((c_rsvd0_ver_v | protocol_v << 16) &
8922 (c_rsvd0_ver_m | protocol_m << 16)));
8923 MLX5_SET(fte_match_set_misc5, misc5_m, tunnel_header_0,
8924 rte_be_to_cpu_32(c_rsvd0_ver_m | protocol_m << 16));
8925 MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1,
8926 rte_be_to_cpu_32(option_v->checksum_rsvd.checksum &
8927 option_m->checksum_rsvd.checksum));
8928 MLX5_SET(fte_match_set_misc5, misc5_m, tunnel_header_1,
8929 rte_be_to_cpu_32(option_m->checksum_rsvd.checksum));
8930 MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_2,
8931 rte_be_to_cpu_32(option_v->key.key & option_m->key.key));
8932 MLX5_SET(fte_match_set_misc5, misc5_m, tunnel_header_2,
8933 rte_be_to_cpu_32(option_m->key.key));
8934 MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_3,
8935 rte_be_to_cpu_32(option_v->sequence.sequence &
8936 option_m->sequence.sequence));
8937 MLX5_SET(fte_match_set_misc5, misc5_m, tunnel_header_3,
8938 rte_be_to_cpu_32(option_m->sequence.sequence));
8942 * Add NVGRE 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.
8950 * @param[in] pattern_flags
8951 * Accumulated pattern flags.
8954 flow_dv_translate_item_nvgre(void *matcher, void *key,
8955 const struct rte_flow_item *item,
8956 unsigned long pattern_flags)
8958 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
8959 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
8960 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8961 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8962 const char *tni_flow_id_m;
8963 const char *tni_flow_id_v;
8969 /* For NVGRE, GRE header fields must be set with defined values. */
8970 const struct rte_flow_item_gre gre_spec = {
8971 .c_rsvd0_ver = RTE_BE16(0x2000),
8972 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
8974 const struct rte_flow_item_gre gre_mask = {
8975 .c_rsvd0_ver = RTE_BE16(0xB000),
8976 .protocol = RTE_BE16(UINT16_MAX),
8978 const struct rte_flow_item gre_item = {
8983 flow_dv_translate_item_gre(matcher, key, &gre_item, pattern_flags);
8987 nvgre_m = &rte_flow_item_nvgre_mask;
8988 tni_flow_id_m = (const char *)nvgre_m->tni;
8989 tni_flow_id_v = (const char *)nvgre_v->tni;
8990 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
8991 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
8992 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
8993 memcpy(gre_key_m, tni_flow_id_m, size);
8994 for (i = 0; i < size; ++i)
8995 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
8999 * Add VXLAN item to matcher and to the value.
9002 * Pointer to the Ethernet device structure.
9004 * Flow rule attributes.
9005 * @param[in, out] matcher
9007 * @param[in, out] key
9008 * Flow matcher value.
9010 * Flow pattern to translate.
9012 * Item is inner pattern.
9015 flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
9016 const struct rte_flow_attr *attr,
9017 void *matcher, void *key,
9018 const struct rte_flow_item *item,
9021 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
9022 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
9027 uint32_t *tunnel_header_v;
9028 uint32_t *tunnel_header_m;
9030 struct mlx5_priv *priv = dev->data->dev_private;
9031 const struct rte_flow_item_vxlan nic_mask = {
9032 .vni = "\xff\xff\xff",
9037 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9039 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9041 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9043 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9045 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
9046 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
9047 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9048 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9049 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
9051 dport = MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport);
9055 if ((!attr->group && !priv->sh->tunnel_header_0_1) ||
9056 (attr->group && !priv->sh->misc5_cap))
9057 vxlan_m = &rte_flow_item_vxlan_mask;
9059 vxlan_m = &nic_mask;
9061 if ((priv->sh->steering_format_version ==
9062 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
9063 dport != MLX5_UDP_PORT_VXLAN) ||
9064 (!attr->group && !attr->transfer && !priv->sh->tunnel_header_0_1) ||
9065 ((attr->group || attr->transfer) && !priv->sh->misc5_cap)) {
9072 misc_m = MLX5_ADDR_OF(fte_match_param,
9073 matcher, misc_parameters);
9074 misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9075 size = sizeof(vxlan_m->vni);
9076 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
9077 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
9078 memcpy(vni_m, vxlan_m->vni, size);
9079 for (i = 0; i < size; ++i)
9080 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
9083 misc5_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_5);
9084 misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9085 tunnel_header_v = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
9088 tunnel_header_m = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
9091 *tunnel_header_v = (vxlan_v->vni[0] & vxlan_m->vni[0]) |
9092 (vxlan_v->vni[1] & vxlan_m->vni[1]) << 8 |
9093 (vxlan_v->vni[2] & vxlan_m->vni[2]) << 16;
9094 if (*tunnel_header_v)
9095 *tunnel_header_m = vxlan_m->vni[0] |
9096 vxlan_m->vni[1] << 8 |
9097 vxlan_m->vni[2] << 16;
9099 *tunnel_header_m = 0x0;
9100 *tunnel_header_v |= (vxlan_v->rsvd1 & vxlan_m->rsvd1) << 24;
9101 if (vxlan_v->rsvd1 & vxlan_m->rsvd1)
9102 *tunnel_header_m |= vxlan_m->rsvd1 << 24;
9106 * Add VXLAN-GPE item to matcher and to the value.
9108 * @param[in, out] matcher
9110 * @param[in, out] key
9111 * Flow matcher value.
9113 * Flow pattern to translate.
9115 * Item is inner pattern.
9119 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
9120 const struct rte_flow_item *item,
9121 const uint64_t pattern_flags)
9123 static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {0, };
9124 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
9125 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
9126 /* The item was validated to be on the outer side */
9127 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9128 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9130 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
9132 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9134 MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
9136 MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
9137 int i, size = sizeof(vxlan_m->vni);
9138 uint8_t flags_m = 0xff;
9139 uint8_t flags_v = 0xc;
9140 uint8_t m_protocol, v_protocol;
9142 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9143 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9144 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9145 MLX5_UDP_PORT_VXLAN_GPE);
9148 vxlan_v = &dummy_vxlan_gpe_hdr;
9149 vxlan_m = &dummy_vxlan_gpe_hdr;
9152 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
9154 memcpy(vni_m, vxlan_m->vni, size);
9155 for (i = 0; i < size; ++i)
9156 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
9157 if (vxlan_m->flags) {
9158 flags_m = vxlan_m->flags;
9159 flags_v = vxlan_v->flags;
9161 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
9162 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
9163 m_protocol = vxlan_m->protocol;
9164 v_protocol = vxlan_v->protocol;
9166 /* Force next protocol to ensure next headers parsing. */
9167 if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
9168 v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
9169 else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
9170 v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
9171 else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
9172 v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
9176 MLX5_SET(fte_match_set_misc3, misc_m,
9177 outer_vxlan_gpe_next_protocol, m_protocol);
9178 MLX5_SET(fte_match_set_misc3, misc_v,
9179 outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
9183 * Add Geneve item to matcher and to the value.
9185 * @param[in, out] matcher
9187 * @param[in, out] key
9188 * Flow matcher value.
9190 * Flow pattern to translate.
9192 * Item is inner pattern.
9196 flow_dv_translate_item_geneve(void *matcher, void *key,
9197 const struct rte_flow_item *item,
9198 uint64_t pattern_flags)
9200 static const struct rte_flow_item_geneve empty_geneve = {0,};
9201 const struct rte_flow_item_geneve *geneve_m = item->mask;
9202 const struct rte_flow_item_geneve *geneve_v = item->spec;
9203 /* GENEVE flow item validation allows single tunnel item */
9204 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9205 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9206 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9207 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9210 char *vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
9211 char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
9212 size_t size = sizeof(geneve_m->vni), i;
9213 uint16_t protocol_m, protocol_v;
9215 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9216 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9217 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9218 MLX5_UDP_PORT_GENEVE);
9221 geneve_v = &empty_geneve;
9222 geneve_m = &empty_geneve;
9225 geneve_m = &rte_flow_item_geneve_mask;
9227 memcpy(vni_m, geneve_m->vni, size);
9228 for (i = 0; i < size; ++i)
9229 vni_v[i] = vni_m[i] & geneve_v->vni[i];
9230 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
9231 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
9232 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
9233 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9234 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
9235 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9236 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9237 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9238 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9239 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
9240 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9241 protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
9242 protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
9244 /* Force next protocol to prevent matchers duplication */
9245 protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9247 protocol_m = 0xFFFF;
9249 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type, protocol_m);
9250 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
9251 protocol_m & protocol_v);
9255 * Create Geneve TLV option resource.
9257 * @param dev[in, out]
9258 * Pointer to rte_eth_dev structure.
9259 * @param[in, out] tag_be24
9260 * Tag value in big endian then R-shift 8.
9261 * @parm[in, out] dev_flow
9262 * Pointer to the dev_flow.
9264 * pointer to error structure.
9267 * 0 on success otherwise -errno and errno is set.
9271 flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
9272 const struct rte_flow_item *item,
9273 struct rte_flow_error *error)
9275 struct mlx5_priv *priv = dev->data->dev_private;
9276 struct mlx5_dev_ctx_shared *sh = priv->sh;
9277 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
9278 sh->geneve_tlv_option_resource;
9279 struct mlx5_devx_obj *obj;
9280 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9285 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
9286 if (geneve_opt_resource != NULL) {
9287 if (geneve_opt_resource->option_class ==
9288 geneve_opt_v->option_class &&
9289 geneve_opt_resource->option_type ==
9290 geneve_opt_v->option_type &&
9291 geneve_opt_resource->length ==
9292 geneve_opt_v->option_len) {
9293 /* We already have GENEVE TLV option obj allocated. */
9294 __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
9297 ret = rte_flow_error_set(error, ENOMEM,
9298 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9299 "Only one GENEVE TLV option supported");
9303 /* Create a GENEVE TLV object and resource. */
9304 obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
9305 geneve_opt_v->option_class,
9306 geneve_opt_v->option_type,
9307 geneve_opt_v->option_len);
9309 ret = rte_flow_error_set(error, ENODATA,
9310 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9311 "Failed to create GENEVE TLV Devx object");
9314 sh->geneve_tlv_option_resource =
9315 mlx5_malloc(MLX5_MEM_ZERO,
9316 sizeof(*geneve_opt_resource),
9318 if (!sh->geneve_tlv_option_resource) {
9319 claim_zero(mlx5_devx_cmd_destroy(obj));
9320 ret = rte_flow_error_set(error, ENOMEM,
9321 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9322 "GENEVE TLV object memory allocation failed");
9325 geneve_opt_resource = sh->geneve_tlv_option_resource;
9326 geneve_opt_resource->obj = obj;
9327 geneve_opt_resource->option_class = geneve_opt_v->option_class;
9328 geneve_opt_resource->option_type = geneve_opt_v->option_type;
9329 geneve_opt_resource->length = geneve_opt_v->option_len;
9330 __atomic_store_n(&geneve_opt_resource->refcnt, 1,
9334 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
9339 * Add Geneve TLV option item to matcher.
9341 * @param[in, out] dev
9342 * Pointer to rte_eth_dev structure.
9343 * @param[in, out] matcher
9345 * @param[in, out] key
9346 * Flow matcher value.
9348 * Flow pattern to translate.
9350 * Pointer to error structure.
9353 flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *matcher,
9354 void *key, const struct rte_flow_item *item,
9355 struct rte_flow_error *error)
9357 const struct rte_flow_item_geneve_opt *geneve_opt_m = item->mask;
9358 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9359 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9360 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9361 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9363 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9364 rte_be32_t opt_data_key = 0, opt_data_mask = 0;
9370 geneve_opt_m = &rte_flow_item_geneve_opt_mask;
9371 ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
9374 DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
9378 * Set the option length in GENEVE header if not requested.
9379 * The GENEVE TLV option length is expressed by the option length field
9380 * in the GENEVE header.
9381 * If the option length was not requested but the GENEVE TLV option item
9382 * is present we set the option length field implicitly.
9384 if (!MLX5_GET16(fte_match_set_misc, misc_m, geneve_opt_len)) {
9385 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9386 MLX5_GENEVE_OPTLEN_MASK);
9387 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9388 geneve_opt_v->option_len + 1);
9390 MLX5_SET(fte_match_set_misc, misc_m, geneve_tlv_option_0_exist, 1);
9391 MLX5_SET(fte_match_set_misc, misc_v, geneve_tlv_option_0_exist, 1);
9393 if (geneve_opt_v->data) {
9394 memcpy(&opt_data_key, geneve_opt_v->data,
9395 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9396 sizeof(opt_data_key)));
9397 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9398 sizeof(opt_data_key));
9399 memcpy(&opt_data_mask, geneve_opt_m->data,
9400 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9401 sizeof(opt_data_mask)));
9402 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9403 sizeof(opt_data_mask));
9404 MLX5_SET(fte_match_set_misc3, misc3_m,
9405 geneve_tlv_option_0_data,
9406 rte_be_to_cpu_32(opt_data_mask));
9407 MLX5_SET(fte_match_set_misc3, misc3_v,
9408 geneve_tlv_option_0_data,
9409 rte_be_to_cpu_32(opt_data_key & opt_data_mask));
9415 * Add MPLS item to matcher and to the value.
9417 * @param[in, out] matcher
9419 * @param[in, out] key
9420 * Flow matcher value.
9422 * Flow pattern to translate.
9423 * @param[in] prev_layer
9424 * The protocol layer indicated in previous item.
9426 * Item is inner pattern.
9429 flow_dv_translate_item_mpls(void *matcher, void *key,
9430 const struct rte_flow_item *item,
9431 uint64_t prev_layer,
9434 const uint32_t *in_mpls_m = item->mask;
9435 const uint32_t *in_mpls_v = item->spec;
9436 uint32_t *out_mpls_m = 0;
9437 uint32_t *out_mpls_v = 0;
9438 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9439 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9440 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
9442 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9443 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9444 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9446 switch (prev_layer) {
9447 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9448 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9449 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
9451 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9452 MLX5_UDP_PORT_MPLS);
9455 case MLX5_FLOW_LAYER_GRE:
9457 case MLX5_FLOW_LAYER_GRE_KEY:
9458 if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
9459 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
9461 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9462 RTE_ETHER_TYPE_MPLS);
9471 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
9472 switch (prev_layer) {
9473 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9475 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9476 outer_first_mpls_over_udp);
9478 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9479 outer_first_mpls_over_udp);
9481 case MLX5_FLOW_LAYER_GRE:
9483 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9484 outer_first_mpls_over_gre);
9486 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9487 outer_first_mpls_over_gre);
9490 /* Inner MPLS not over GRE is not supported. */
9493 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9497 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9503 if (out_mpls_m && out_mpls_v) {
9504 *out_mpls_m = *in_mpls_m;
9505 *out_mpls_v = *in_mpls_v & *in_mpls_m;
9510 * Add metadata register item to matcher
9512 * @param[in, out] matcher
9514 * @param[in, out] key
9515 * Flow matcher value.
9516 * @param[in] reg_type
9517 * Type of device metadata register
9524 flow_dv_match_meta_reg(void *matcher, void *key,
9525 enum modify_reg reg_type,
9526 uint32_t data, uint32_t mask)
9529 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
9531 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9537 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
9538 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
9541 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
9542 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
9546 * The metadata register C0 field might be divided into
9547 * source vport index and META item value, we should set
9548 * this field according to specified mask, not as whole one.
9550 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
9552 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
9553 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
9556 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
9559 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
9560 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
9563 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
9564 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
9567 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
9568 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
9571 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
9572 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
9575 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
9576 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
9579 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
9580 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
9583 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
9584 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
9593 * Add MARK item to matcher
9596 * The device to configure through.
9597 * @param[in, out] matcher
9599 * @param[in, out] key
9600 * Flow matcher value.
9602 * Flow pattern to translate.
9605 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
9606 void *matcher, void *key,
9607 const struct rte_flow_item *item)
9609 struct mlx5_priv *priv = dev->data->dev_private;
9610 const struct rte_flow_item_mark *mark;
9614 mark = item->mask ? (const void *)item->mask :
9615 &rte_flow_item_mark_mask;
9616 mask = mark->id & priv->sh->dv_mark_mask;
9617 mark = (const void *)item->spec;
9619 value = mark->id & priv->sh->dv_mark_mask & mask;
9621 enum modify_reg reg;
9623 /* Get the metadata register index for the mark. */
9624 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
9625 MLX5_ASSERT(reg > 0);
9626 if (reg == REG_C_0) {
9627 struct mlx5_priv *priv = dev->data->dev_private;
9628 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9629 uint32_t shl_c0 = rte_bsf32(msk_c0);
9635 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9640 * Add META item to matcher
9643 * The devich to configure through.
9644 * @param[in, out] matcher
9646 * @param[in, out] key
9647 * Flow matcher value.
9649 * Attributes of flow that includes this item.
9651 * Flow pattern to translate.
9654 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
9655 void *matcher, void *key,
9656 const struct rte_flow_attr *attr,
9657 const struct rte_flow_item *item)
9659 const struct rte_flow_item_meta *meta_m;
9660 const struct rte_flow_item_meta *meta_v;
9662 meta_m = (const void *)item->mask;
9664 meta_m = &rte_flow_item_meta_mask;
9665 meta_v = (const void *)item->spec;
9668 uint32_t value = meta_v->data;
9669 uint32_t mask = meta_m->data;
9671 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
9674 MLX5_ASSERT(reg != REG_NON);
9675 if (reg == REG_C_0) {
9676 struct mlx5_priv *priv = dev->data->dev_private;
9677 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9678 uint32_t shl_c0 = rte_bsf32(msk_c0);
9684 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9689 * Add vport metadata Reg C0 item to matcher
9691 * @param[in, out] matcher
9693 * @param[in, out] key
9694 * Flow matcher value.
9696 * Flow pattern to translate.
9699 flow_dv_translate_item_meta_vport(void *matcher, void *key,
9700 uint32_t value, uint32_t mask)
9702 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
9706 * Add tag item to matcher
9709 * The devich to configure through.
9710 * @param[in, out] matcher
9712 * @param[in, out] key
9713 * Flow matcher value.
9715 * Flow pattern to translate.
9718 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
9719 void *matcher, void *key,
9720 const struct rte_flow_item *item)
9722 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
9723 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
9724 uint32_t mask, value;
9727 value = tag_v->data;
9728 mask = tag_m ? tag_m->data : UINT32_MAX;
9729 if (tag_v->id == REG_C_0) {
9730 struct mlx5_priv *priv = dev->data->dev_private;
9731 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9732 uint32_t shl_c0 = rte_bsf32(msk_c0);
9738 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
9742 * Add TAG item to matcher
9745 * The devich to configure through.
9746 * @param[in, out] matcher
9748 * @param[in, out] key
9749 * Flow matcher value.
9751 * Flow pattern to translate.
9754 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
9755 void *matcher, void *key,
9756 const struct rte_flow_item *item)
9758 const struct rte_flow_item_tag *tag_v = item->spec;
9759 const struct rte_flow_item_tag *tag_m = item->mask;
9760 enum modify_reg reg;
9763 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
9764 /* Get the metadata register index for the tag. */
9765 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
9766 MLX5_ASSERT(reg > 0);
9767 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
9771 * Add source vport match to the specified matcher.
9773 * @param[in, out] matcher
9775 * @param[in, out] key
9776 * Flow matcher value.
9778 * Source vport value to match
9783 flow_dv_translate_item_source_vport(void *matcher, void *key,
9784 int16_t port, uint16_t mask)
9786 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9787 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9789 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
9790 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
9794 * Translate port-id item to eswitch match on port-id.
9797 * The devich to configure through.
9798 * @param[in, out] matcher
9800 * @param[in, out] key
9801 * Flow matcher value.
9803 * Flow pattern to translate.
9808 * 0 on success, a negative errno value otherwise.
9811 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
9812 void *key, const struct rte_flow_item *item,
9813 const struct rte_flow_attr *attr)
9815 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
9816 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
9817 struct mlx5_priv *priv;
9820 if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
9821 flow_dv_translate_item_source_vport(matcher, key,
9822 flow_dv_get_esw_manager_vport_id(dev), 0xffff);
9825 mask = pid_m ? pid_m->id : 0xffff;
9826 id = pid_v ? pid_v->id : dev->data->port_id;
9827 priv = mlx5_port_to_eswitch_info(id, item == NULL);
9831 * Translate to vport field or to metadata, depending on mode.
9832 * Kernel can use either misc.source_port or half of C0 metadata
9835 if (priv->vport_meta_mask) {
9837 * Provide the hint for SW steering library
9838 * to insert the flow into ingress domain and
9839 * save the extra vport match.
9841 if (mask == 0xffff && priv->vport_id == 0xffff &&
9842 priv->pf_bond < 0 && attr->transfer)
9843 flow_dv_translate_item_source_vport
9844 (matcher, key, priv->vport_id, mask);
9846 * We should always set the vport metadata register,
9847 * otherwise the SW steering library can drop
9848 * the rule if wire vport metadata value is not zero,
9849 * it depends on kernel configuration.
9851 flow_dv_translate_item_meta_vport(matcher, key,
9852 priv->vport_meta_tag,
9853 priv->vport_meta_mask);
9855 flow_dv_translate_item_source_vport(matcher, key,
9856 priv->vport_id, mask);
9862 * Add ICMP6 item to matcher and to the value.
9864 * @param[in, out] matcher
9866 * @param[in, out] key
9867 * Flow matcher value.
9869 * Flow pattern to translate.
9871 * Item is inner pattern.
9874 flow_dv_translate_item_icmp6(void *matcher, void *key,
9875 const struct rte_flow_item *item,
9878 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
9879 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
9882 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9884 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9886 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9888 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9890 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9892 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9894 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9895 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
9899 icmp6_m = &rte_flow_item_icmp6_mask;
9900 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
9901 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
9902 icmp6_v->type & icmp6_m->type);
9903 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
9904 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
9905 icmp6_v->code & icmp6_m->code);
9909 * Add ICMP item to matcher and to the value.
9911 * @param[in, out] matcher
9913 * @param[in, out] key
9914 * Flow matcher value.
9916 * Flow pattern to translate.
9918 * Item is inner pattern.
9921 flow_dv_translate_item_icmp(void *matcher, void *key,
9922 const struct rte_flow_item *item,
9925 const struct rte_flow_item_icmp *icmp_m = item->mask;
9926 const struct rte_flow_item_icmp *icmp_v = item->spec;
9927 uint32_t icmp_header_data_m = 0;
9928 uint32_t icmp_header_data_v = 0;
9931 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9933 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9935 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9937 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9939 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9941 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9943 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9944 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
9948 icmp_m = &rte_flow_item_icmp_mask;
9949 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
9950 icmp_m->hdr.icmp_type);
9951 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
9952 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
9953 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
9954 icmp_m->hdr.icmp_code);
9955 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
9956 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
9957 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
9958 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
9959 if (icmp_header_data_m) {
9960 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
9961 icmp_header_data_v |=
9962 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
9963 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
9964 icmp_header_data_m);
9965 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
9966 icmp_header_data_v & icmp_header_data_m);
9971 * Add GTP item to matcher and to the value.
9973 * @param[in, out] matcher
9975 * @param[in, out] key
9976 * Flow matcher value.
9978 * Flow pattern to translate.
9980 * Item is inner pattern.
9983 flow_dv_translate_item_gtp(void *matcher, void *key,
9984 const struct rte_flow_item *item, int inner)
9986 const struct rte_flow_item_gtp *gtp_m = item->mask;
9987 const struct rte_flow_item_gtp *gtp_v = item->spec;
9990 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9992 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9993 uint16_t dport = RTE_GTPU_UDP_PORT;
9996 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9998 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
10000 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
10002 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10004 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10005 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
10006 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
10011 gtp_m = &rte_flow_item_gtp_mask;
10012 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
10013 gtp_m->v_pt_rsv_flags);
10014 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
10015 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
10016 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
10017 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
10018 gtp_v->msg_type & gtp_m->msg_type);
10019 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
10020 rte_be_to_cpu_32(gtp_m->teid));
10021 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
10022 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
10026 * Add GTP PSC item to matcher.
10028 * @param[in, out] matcher
10030 * @param[in, out] key
10031 * Flow matcher value.
10033 * Flow pattern to translate.
10036 flow_dv_translate_item_gtp_psc(void *matcher, void *key,
10037 const struct rte_flow_item *item)
10039 const struct rte_flow_item_gtp_psc *gtp_psc_m = item->mask;
10040 const struct rte_flow_item_gtp_psc *gtp_psc_v = item->spec;
10041 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
10042 misc_parameters_3);
10043 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10049 uint8_t next_ext_header_type;
10054 /* Always set E-flag match on one, regardless of GTP item settings. */
10055 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_m, gtpu_msg_flags);
10056 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
10057 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags, gtp_flags);
10058 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
10059 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
10060 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
10061 /*Set next extension header type. */
10064 dw_2.next_ext_header_type = 0xff;
10065 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_dw_2,
10066 rte_cpu_to_be_32(dw_2.w32));
10069 dw_2.next_ext_header_type = 0x85;
10070 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
10071 rte_cpu_to_be_32(dw_2.w32));
10077 uint8_t type_flags;
10083 /*Set extension header PDU type and Qos. */
10085 gtp_psc_m = &rte_flow_item_gtp_psc_mask;
10087 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_m->hdr.type);
10088 dw_0.qfi = gtp_psc_m->hdr.qfi;
10089 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_first_ext_dw_0,
10090 rte_cpu_to_be_32(dw_0.w32));
10092 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
10093 gtp_psc_m->hdr.type);
10094 dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
10095 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
10096 rte_cpu_to_be_32(dw_0.w32));
10102 * Add eCPRI item to matcher and to the value.
10105 * The devich to configure through.
10106 * @param[in, out] matcher
10108 * @param[in, out] key
10109 * Flow matcher value.
10111 * Flow pattern to translate.
10112 * @param[in] last_item
10116 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
10117 void *key, const struct rte_flow_item *item,
10118 uint64_t last_item)
10120 struct mlx5_priv *priv = dev->data->dev_private;
10121 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
10122 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
10123 struct rte_ecpri_common_hdr common;
10124 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
10125 misc_parameters_4);
10126 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
10132 * In case of eCPRI over Ethernet, if EtherType is not specified,
10133 * match on eCPRI EtherType implicitly.
10135 if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
10136 void *hdrs_m, *hdrs_v, *l2m, *l2v;
10138 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
10139 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10140 l2m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, ethertype);
10141 l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
10142 if (*(uint16_t *)l2m == 0 && *(uint16_t *)l2v == 0) {
10143 *(uint16_t *)l2m = UINT16_MAX;
10144 *(uint16_t *)l2v = RTE_BE16(RTE_ETHER_TYPE_ECPRI);
10150 ecpri_m = &rte_flow_item_ecpri_mask;
10152 * Maximal four DW samples are supported in a single matching now.
10153 * Two are used now for a eCPRI matching:
10154 * 1. Type: one byte, mask should be 0x00ff0000 in network order
10155 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
10158 if (!ecpri_m->hdr.common.u32)
10160 samples = priv->sh->ecpri_parser.ids;
10161 /* Need to take the whole DW as the mask to fill the entry. */
10162 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
10163 prog_sample_field_value_0);
10164 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
10165 prog_sample_field_value_0);
10166 /* Already big endian (network order) in the header. */
10167 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
10168 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
10169 /* Sample#0, used for matching type, offset 0. */
10170 MLX5_SET(fte_match_set_misc4, misc4_m,
10171 prog_sample_field_id_0, samples[0]);
10172 /* It makes no sense to set the sample ID in the mask field. */
10173 MLX5_SET(fte_match_set_misc4, misc4_v,
10174 prog_sample_field_id_0, samples[0]);
10176 * Checking if message body part needs to be matched.
10177 * Some wildcard rules only matching type field should be supported.
10179 if (ecpri_m->hdr.dummy[0]) {
10180 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
10181 switch (common.type) {
10182 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
10183 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
10184 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
10185 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
10186 prog_sample_field_value_1);
10187 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
10188 prog_sample_field_value_1);
10189 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
10190 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
10191 ecpri_m->hdr.dummy[0];
10192 /* Sample#1, to match message body, offset 4. */
10193 MLX5_SET(fte_match_set_misc4, misc4_m,
10194 prog_sample_field_id_1, samples[1]);
10195 MLX5_SET(fte_match_set_misc4, misc4_v,
10196 prog_sample_field_id_1, samples[1]);
10199 /* Others, do not match any sample ID. */
10206 * Add connection tracking status item to matcher
10209 * The devich to configure through.
10210 * @param[in, out] matcher
10212 * @param[in, out] key
10213 * Flow matcher value.
10215 * Flow pattern to translate.
10218 flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
10219 void *matcher, void *key,
10220 const struct rte_flow_item *item)
10222 uint32_t reg_value = 0;
10224 /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
10225 uint32_t reg_mask = 0;
10226 const struct rte_flow_item_conntrack *spec = item->spec;
10227 const struct rte_flow_item_conntrack *mask = item->mask;
10229 struct rte_flow_error error;
10232 mask = &rte_flow_item_conntrack_mask;
10233 if (!spec || !mask->flags)
10235 flags = spec->flags & mask->flags;
10236 /* The conflict should be checked in the validation. */
10237 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
10238 reg_value |= MLX5_CT_SYNDROME_VALID;
10239 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
10240 reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
10241 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
10242 reg_value |= MLX5_CT_SYNDROME_INVALID;
10243 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
10244 reg_value |= MLX5_CT_SYNDROME_TRAP;
10245 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10246 reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
10247 if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
10248 RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
10249 RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
10251 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
10252 reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
10253 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10254 reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
10255 /* The REG_C_x value could be saved during startup. */
10256 reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
10257 if (reg_id == REG_NON)
10259 flow_dv_match_meta_reg(matcher, key, (enum modify_reg)reg_id,
10260 reg_value, reg_mask);
10264 flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
10265 const struct rte_flow_item *item,
10266 struct mlx5_flow *dev_flow, bool is_inner)
10268 const struct rte_flow_item_flex *spec =
10269 (const struct rte_flow_item_flex *)item->spec;
10270 int index = mlx5_flex_acquire_index(dev, spec->handle, false);
10272 MLX5_ASSERT(index >= 0 && index <= (int)(sizeof(uint32_t) * CHAR_BIT));
10275 if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
10276 /* Don't count both inner and outer flex items in one rule. */
10277 if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
10278 MLX5_ASSERT(false);
10279 dev_flow->handle->flex_item |= RTE_BIT32(index);
10281 mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
10284 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
10286 #define HEADER_IS_ZERO(match_criteria, headers) \
10287 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
10288 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
10291 * Calculate flow matcher enable bitmap.
10293 * @param match_criteria
10294 * Pointer to flow matcher criteria.
10297 * Bitmap of enabled fields.
10300 flow_dv_matcher_enable(uint32_t *match_criteria)
10302 uint8_t match_criteria_enable;
10304 match_criteria_enable =
10305 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
10306 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
10307 match_criteria_enable |=
10308 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
10309 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
10310 match_criteria_enable |=
10311 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
10312 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
10313 match_criteria_enable |=
10314 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
10315 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
10316 match_criteria_enable |=
10317 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
10318 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
10319 match_criteria_enable |=
10320 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
10321 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
10322 match_criteria_enable |=
10323 (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
10324 MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
10325 return match_criteria_enable;
10329 __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
10332 * Check flow matching criteria first, subtract misc5/4 length if flow
10333 * doesn't own misc5/4 parameters. In some old rdma-core releases,
10334 * misc5/4 are not supported, and matcher creation failure is expected
10335 * w/o subtraction. If misc5 is provided, misc4 must be counted in since
10336 * misc5 is right after misc4.
10338 if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
10339 *size = MLX5_ST_SZ_BYTES(fte_match_param) -
10340 MLX5_ST_SZ_BYTES(fte_match_set_misc5);
10341 if (!(match_criteria & (1 <<
10342 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
10343 *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
10348 static struct mlx5_list_entry *
10349 flow_dv_matcher_clone_cb(void *tool_ctx __rte_unused,
10350 struct mlx5_list_entry *entry, void *cb_ctx)
10352 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10353 struct mlx5_flow_dv_matcher *ref = ctx->data;
10354 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10355 typeof(*tbl), tbl);
10356 struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
10361 rte_flow_error_set(ctx->error, ENOMEM,
10362 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10363 "cannot create matcher");
10366 memcpy(resource, entry, sizeof(*resource));
10367 resource->tbl = &tbl->tbl;
10368 return &resource->entry;
10372 flow_dv_matcher_clone_free_cb(void *tool_ctx __rte_unused,
10373 struct mlx5_list_entry *entry)
10378 struct mlx5_list_entry *
10379 flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
10381 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10382 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10383 struct rte_eth_dev *dev = ctx->dev;
10384 struct mlx5_flow_tbl_data_entry *tbl_data;
10385 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
10386 struct rte_flow_error *error = ctx->error;
10387 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10388 struct mlx5_flow_tbl_resource *tbl;
10393 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10395 rte_flow_error_set(error, ENOMEM,
10396 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10398 "cannot allocate flow table data entry");
10401 tbl_data->idx = idx;
10402 tbl_data->tunnel = tt_prm->tunnel;
10403 tbl_data->group_id = tt_prm->group_id;
10404 tbl_data->external = !!tt_prm->external;
10405 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
10406 tbl_data->is_egress = !!key.is_egress;
10407 tbl_data->is_transfer = !!key.is_fdb;
10408 tbl_data->dummy = !!key.dummy;
10409 tbl_data->level = key.level;
10410 tbl_data->id = key.id;
10411 tbl = &tbl_data->tbl;
10413 return &tbl_data->entry;
10415 domain = sh->fdb_domain;
10416 else if (key.is_egress)
10417 domain = sh->tx_domain;
10419 domain = sh->rx_domain;
10420 ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
10422 rte_flow_error_set(error, ENOMEM,
10423 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10424 NULL, "cannot create flow table object");
10425 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10428 if (key.level != 0) {
10429 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
10430 (tbl->obj, &tbl_data->jump.action);
10432 rte_flow_error_set(error, ENOMEM,
10433 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10435 "cannot create flow jump action");
10436 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10437 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10441 MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
10442 key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
10443 key.level, key.id);
10444 tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
10445 flow_dv_matcher_create_cb,
10446 flow_dv_matcher_match_cb,
10447 flow_dv_matcher_remove_cb,
10448 flow_dv_matcher_clone_cb,
10449 flow_dv_matcher_clone_free_cb);
10450 if (!tbl_data->matchers) {
10451 rte_flow_error_set(error, ENOMEM,
10452 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10454 "cannot create tbl matcher list");
10455 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10456 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10457 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10460 return &tbl_data->entry;
10464 flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
10467 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10468 struct mlx5_flow_tbl_data_entry *tbl_data =
10469 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10470 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10472 return tbl_data->level != key.level ||
10473 tbl_data->id != key.id ||
10474 tbl_data->dummy != key.dummy ||
10475 tbl_data->is_transfer != !!key.is_fdb ||
10476 tbl_data->is_egress != !!key.is_egress;
10479 struct mlx5_list_entry *
10480 flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
10483 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10484 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10485 struct mlx5_flow_tbl_data_entry *tbl_data;
10486 struct rte_flow_error *error = ctx->error;
10489 tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10491 rte_flow_error_set(error, ENOMEM,
10492 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10494 "cannot allocate flow table data entry");
10497 memcpy(tbl_data, oentry, sizeof(*tbl_data));
10498 tbl_data->idx = idx;
10499 return &tbl_data->entry;
10503 flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10505 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10506 struct mlx5_flow_tbl_data_entry *tbl_data =
10507 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10509 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10513 * Get a flow table.
10515 * @param[in, out] dev
10516 * Pointer to rte_eth_dev structure.
10517 * @param[in] table_level
10518 * Table level to use.
10519 * @param[in] egress
10520 * Direction of the table.
10521 * @param[in] transfer
10522 * E-Switch or NIC flow.
10524 * Dummy entry for dv API.
10525 * @param[in] table_id
10527 * @param[out] error
10528 * pointer to error structure.
10531 * Returns tables resource based on the index, NULL in case of failed.
10533 struct mlx5_flow_tbl_resource *
10534 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
10535 uint32_t table_level, uint8_t egress,
10538 const struct mlx5_flow_tunnel *tunnel,
10539 uint32_t group_id, uint8_t dummy,
10541 struct rte_flow_error *error)
10543 struct mlx5_priv *priv = dev->data->dev_private;
10544 union mlx5_flow_tbl_key table_key = {
10546 .level = table_level,
10550 .is_fdb = !!transfer,
10551 .is_egress = !!egress,
10554 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
10556 .group_id = group_id,
10557 .external = external,
10559 struct mlx5_flow_cb_ctx ctx = {
10562 .data = &table_key.v64,
10565 struct mlx5_list_entry *entry;
10566 struct mlx5_flow_tbl_data_entry *tbl_data;
10568 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
10570 rte_flow_error_set(error, ENOMEM,
10571 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10572 "cannot get table");
10575 DRV_LOG(DEBUG, "table_level %u table_id %u "
10576 "tunnel %u group %u registered.",
10577 table_level, table_id,
10578 tunnel ? tunnel->tunnel_id : 0, group_id);
10579 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10580 return &tbl_data->tbl;
10584 flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10586 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10587 struct mlx5_flow_tbl_data_entry *tbl_data =
10588 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10590 MLX5_ASSERT(entry && sh);
10591 if (tbl_data->jump.action)
10592 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10593 if (tbl_data->tbl.obj)
10594 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
10595 if (tbl_data->tunnel_offload && tbl_data->external) {
10596 struct mlx5_list_entry *he;
10597 struct mlx5_hlist *tunnel_grp_hash;
10598 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
10599 union tunnel_tbl_key tunnel_key = {
10600 .tunnel_id = tbl_data->tunnel ?
10601 tbl_data->tunnel->tunnel_id : 0,
10602 .group = tbl_data->group_id
10604 uint32_t table_level = tbl_data->level;
10605 struct mlx5_flow_cb_ctx ctx = {
10606 .data = (void *)&tunnel_key.val,
10609 tunnel_grp_hash = tbl_data->tunnel ?
10610 tbl_data->tunnel->groups :
10612 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
10614 mlx5_hlist_unregister(tunnel_grp_hash, he);
10616 "table_level %u id %u tunnel %u group %u released.",
10620 tbl_data->tunnel->tunnel_id : 0,
10621 tbl_data->group_id);
10623 if (tbl_data->matchers)
10624 mlx5_list_destroy(tbl_data->matchers);
10625 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10629 * Release a flow table.
10632 * Pointer to device shared structure.
10634 * Table resource to be released.
10637 * Returns 0 if table was released, else return 1;
10640 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
10641 struct mlx5_flow_tbl_resource *tbl)
10643 struct mlx5_flow_tbl_data_entry *tbl_data =
10644 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10648 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
10652 flow_dv_matcher_match_cb(void *tool_ctx __rte_unused,
10653 struct mlx5_list_entry *entry, void *cb_ctx)
10655 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10656 struct mlx5_flow_dv_matcher *ref = ctx->data;
10657 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
10660 return cur->crc != ref->crc ||
10661 cur->priority != ref->priority ||
10662 memcmp((const void *)cur->mask.buf,
10663 (const void *)ref->mask.buf, ref->mask.size);
10666 struct mlx5_list_entry *
10667 flow_dv_matcher_create_cb(void *tool_ctx, void *cb_ctx)
10669 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10670 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10671 struct mlx5_flow_dv_matcher *ref = ctx->data;
10672 struct mlx5_flow_dv_matcher *resource;
10673 struct mlx5dv_flow_matcher_attr dv_attr = {
10674 .type = IBV_FLOW_ATTR_NORMAL,
10675 .match_mask = (void *)&ref->mask,
10677 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10678 typeof(*tbl), tbl);
10681 resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
10684 rte_flow_error_set(ctx->error, ENOMEM,
10685 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10686 "cannot create matcher");
10690 dv_attr.match_criteria_enable =
10691 flow_dv_matcher_enable(resource->mask.buf);
10692 __flow_dv_adjust_buf_size(&ref->mask.size,
10693 dv_attr.match_criteria_enable);
10694 dv_attr.priority = ref->priority;
10695 if (tbl->is_egress)
10696 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
10697 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
10699 &resource->matcher_object);
10701 mlx5_free(resource);
10702 rte_flow_error_set(ctx->error, ENOMEM,
10703 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10704 "cannot create matcher");
10707 return &resource->entry;
10711 * Register the flow matcher.
10713 * @param[in, out] dev
10714 * Pointer to rte_eth_dev structure.
10715 * @param[in, out] matcher
10716 * Pointer to flow matcher.
10717 * @param[in, out] key
10718 * Pointer to flow table key.
10719 * @parm[in, out] dev_flow
10720 * Pointer to the dev_flow.
10721 * @param[out] error
10722 * pointer to error structure.
10725 * 0 on success otherwise -errno and errno is set.
10728 flow_dv_matcher_register(struct rte_eth_dev *dev,
10729 struct mlx5_flow_dv_matcher *ref,
10730 union mlx5_flow_tbl_key *key,
10731 struct mlx5_flow *dev_flow,
10732 const struct mlx5_flow_tunnel *tunnel,
10734 struct rte_flow_error *error)
10736 struct mlx5_list_entry *entry;
10737 struct mlx5_flow_dv_matcher *resource;
10738 struct mlx5_flow_tbl_resource *tbl;
10739 struct mlx5_flow_tbl_data_entry *tbl_data;
10740 struct mlx5_flow_cb_ctx ctx = {
10745 * tunnel offload API requires this registration for cases when
10746 * tunnel match rule was inserted before tunnel set rule.
10748 tbl = flow_dv_tbl_resource_get(dev, key->level,
10749 key->is_egress, key->is_fdb,
10750 dev_flow->external, tunnel,
10751 group_id, 0, key->id, error);
10753 return -rte_errno; /* No need to refill the error info */
10754 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10756 entry = mlx5_list_register(tbl_data->matchers, &ctx);
10758 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
10759 return rte_flow_error_set(error, ENOMEM,
10760 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10761 "cannot allocate ref memory");
10763 resource = container_of(entry, typeof(*resource), entry);
10764 dev_flow->handle->dvh.matcher = resource;
10768 struct mlx5_list_entry *
10769 flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
10771 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10772 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10773 struct mlx5_flow_dv_tag_resource *entry;
10777 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10779 rte_flow_error_set(ctx->error, ENOMEM,
10780 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10781 "cannot allocate resource memory");
10785 entry->tag_id = *(uint32_t *)(ctx->data);
10786 ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
10789 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
10790 rte_flow_error_set(ctx->error, ENOMEM,
10791 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10792 NULL, "cannot create action");
10795 return &entry->entry;
10799 flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
10802 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10803 struct mlx5_flow_dv_tag_resource *tag =
10804 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10806 return *(uint32_t *)(ctx->data) != tag->tag_id;
10809 struct mlx5_list_entry *
10810 flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
10813 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10814 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10815 struct mlx5_flow_dv_tag_resource *entry;
10818 entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10820 rte_flow_error_set(ctx->error, ENOMEM,
10821 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10822 "cannot allocate tag resource memory");
10825 memcpy(entry, oentry, sizeof(*entry));
10827 return &entry->entry;
10831 flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10833 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10834 struct mlx5_flow_dv_tag_resource *tag =
10835 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10837 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10841 * Find existing tag resource or create and register a new one.
10843 * @param dev[in, out]
10844 * Pointer to rte_eth_dev structure.
10845 * @param[in, out] tag_be24
10846 * Tag value in big endian then R-shift 8.
10847 * @parm[in, out] dev_flow
10848 * Pointer to the dev_flow.
10849 * @param[out] error
10850 * pointer to error structure.
10853 * 0 on success otherwise -errno and errno is set.
10856 flow_dv_tag_resource_register
10857 (struct rte_eth_dev *dev,
10859 struct mlx5_flow *dev_flow,
10860 struct rte_flow_error *error)
10862 struct mlx5_priv *priv = dev->data->dev_private;
10863 struct mlx5_flow_dv_tag_resource *resource;
10864 struct mlx5_list_entry *entry;
10865 struct mlx5_flow_cb_ctx ctx = {
10869 struct mlx5_hlist *tag_table;
10871 tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
10873 MLX5_TAGS_HLIST_ARRAY_SIZE,
10874 false, false, priv->sh,
10875 flow_dv_tag_create_cb,
10876 flow_dv_tag_match_cb,
10877 flow_dv_tag_remove_cb,
10878 flow_dv_tag_clone_cb,
10879 flow_dv_tag_clone_free_cb,
10881 if (unlikely(!tag_table))
10883 entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
10885 resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
10887 dev_flow->handle->dvh.rix_tag = resource->idx;
10888 dev_flow->dv.tag_resource = resource;
10895 flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10897 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10898 struct mlx5_flow_dv_tag_resource *tag =
10899 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10901 MLX5_ASSERT(tag && sh && tag->action);
10902 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
10903 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
10904 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10911 * Pointer to Ethernet device.
10916 * 1 while a reference on it exists, 0 when freed.
10919 flow_dv_tag_release(struct rte_eth_dev *dev,
10922 struct mlx5_priv *priv = dev->data->dev_private;
10923 struct mlx5_flow_dv_tag_resource *tag;
10925 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
10928 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
10929 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
10930 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
10934 * Translate action PORT_ID / REPRESENTED_PORT to vport.
10937 * Pointer to rte_eth_dev structure.
10938 * @param[in] action
10939 * Pointer to action PORT_ID / REPRESENTED_PORT.
10940 * @param[out] dst_port_id
10941 * The target port ID.
10942 * @param[out] error
10943 * Pointer to the error structure.
10946 * 0 on success, a negative errno value otherwise and rte_errno is set.
10949 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
10950 const struct rte_flow_action *action,
10951 uint32_t *dst_port_id,
10952 struct rte_flow_error *error)
10955 struct mlx5_priv *priv;
10957 switch (action->type) {
10958 case RTE_FLOW_ACTION_TYPE_PORT_ID: {
10959 const struct rte_flow_action_port_id *conf;
10961 conf = (const struct rte_flow_action_port_id *)action->conf;
10962 port = conf->original ? dev->data->port_id : conf->id;
10965 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
10966 const struct rte_flow_action_ethdev *ethdev;
10968 ethdev = (const struct rte_flow_action_ethdev *)action->conf;
10969 port = ethdev->port_id;
10973 MLX5_ASSERT(false);
10974 return rte_flow_error_set(error, EINVAL,
10975 RTE_FLOW_ERROR_TYPE_ACTION, action,
10976 "unknown E-Switch action");
10979 priv = mlx5_port_to_eswitch_info(port, false);
10981 return rte_flow_error_set(error, -rte_errno,
10982 RTE_FLOW_ERROR_TYPE_ACTION,
10984 "No eswitch info was found for port");
10985 #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
10987 * This parameter is transferred to
10988 * mlx5dv_dr_action_create_dest_ib_port().
10990 *dst_port_id = priv->dev_port;
10993 * Legacy mode, no LAG configurations is supported.
10994 * This parameter is transferred to
10995 * mlx5dv_dr_action_create_dest_vport().
10997 *dst_port_id = priv->vport_id;
11003 * Create a counter with aging configuration.
11006 * Pointer to rte_eth_dev structure.
11007 * @param[in] dev_flow
11008 * Pointer to the mlx5_flow.
11009 * @param[out] count
11010 * Pointer to the counter action configuration.
11012 * Pointer to the aging action configuration.
11015 * Index to flow counter on success, 0 otherwise.
11018 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
11019 struct mlx5_flow *dev_flow,
11020 const struct rte_flow_action_count *count
11022 const struct rte_flow_action_age *age)
11025 struct mlx5_age_param *age_param;
11027 counter = flow_dv_counter_alloc(dev, !!age);
11028 if (!counter || age == NULL)
11030 age_param = flow_dv_counter_idx_get_age(dev, counter);
11031 age_param->context = age->context ? age->context :
11032 (void *)(uintptr_t)(dev_flow->flow_idx);
11033 age_param->timeout = age->timeout;
11034 age_param->port_id = dev->data->port_id;
11035 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
11036 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
11041 * Add Tx queue matcher
11044 * Pointer to the dev struct.
11045 * @param[in, out] matcher
11047 * @param[in, out] key
11048 * Flow matcher value.
11050 * Flow pattern to translate.
11052 * Item is inner pattern.
11055 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
11056 void *matcher, void *key,
11057 const struct rte_flow_item *item)
11059 const struct mlx5_rte_flow_item_tx_queue *queue_m;
11060 const struct mlx5_rte_flow_item_tx_queue *queue_v;
11061 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
11062 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11063 struct mlx5_txq_ctrl *txq;
11064 uint32_t queue, mask;
11066 queue_m = (const void *)item->mask;
11067 queue_v = (const void *)item->spec;
11070 txq = mlx5_txq_get(dev, queue_v->queue);
11073 if (txq->is_hairpin)
11074 queue = txq->obj->sq->id;
11076 queue = txq->obj->sq_obj.sq->id;
11077 mask = queue_m == NULL ? UINT32_MAX : queue_m->queue;
11078 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, mask);
11079 MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue & mask);
11080 mlx5_txq_release(dev, queue_v->queue);
11084 * Set the hash fields according to the @p flow information.
11086 * @param[in] item_flags
11087 * The match pattern item flags.
11088 * @param[in] rss_desc
11089 * Pointer to the mlx5_flow_rss_desc.
11090 * @param[out] hash_fields
11091 * Pointer to the RSS hash fields.
11094 flow_dv_hashfields_set(uint64_t item_flags,
11095 struct mlx5_flow_rss_desc *rss_desc,
11096 uint64_t *hash_fields)
11098 uint64_t items = item_flags;
11099 uint64_t fields = 0;
11101 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
11104 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
11105 if (rss_desc->level >= 2)
11108 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
11109 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4)) ||
11111 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
11112 if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
11113 fields |= IBV_RX_HASH_SRC_IPV4;
11114 else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
11115 fields |= IBV_RX_HASH_DST_IPV4;
11117 fields |= MLX5_IPV4_IBV_RX_HASH;
11119 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
11120 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6)) ||
11122 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
11123 if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
11124 fields |= IBV_RX_HASH_SRC_IPV6;
11125 else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
11126 fields |= IBV_RX_HASH_DST_IPV6;
11128 fields |= MLX5_IPV6_IBV_RX_HASH;
11133 * There is no match between the RSS types and the
11134 * L3 protocol (IPv4/IPv6) defined in the flow rule.
11137 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
11138 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP)) ||
11140 if (rss_types & RTE_ETH_RSS_UDP) {
11141 if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
11142 fields |= IBV_RX_HASH_SRC_PORT_UDP;
11143 else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
11144 fields |= IBV_RX_HASH_DST_PORT_UDP;
11146 fields |= MLX5_UDP_IBV_RX_HASH;
11148 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
11149 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP)) ||
11151 if (rss_types & RTE_ETH_RSS_TCP) {
11152 if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
11153 fields |= IBV_RX_HASH_SRC_PORT_TCP;
11154 else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
11155 fields |= IBV_RX_HASH_DST_PORT_TCP;
11157 fields |= MLX5_TCP_IBV_RX_HASH;
11161 fields |= IBV_RX_HASH_INNER;
11162 *hash_fields = fields;
11166 * Prepare an Rx Hash queue.
11169 * Pointer to Ethernet device.
11170 * @param[in] dev_flow
11171 * Pointer to the mlx5_flow.
11172 * @param[in] rss_desc
11173 * Pointer to the mlx5_flow_rss_desc.
11174 * @param[out] hrxq_idx
11175 * Hash Rx queue index.
11178 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
11180 static struct mlx5_hrxq *
11181 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
11182 struct mlx5_flow *dev_flow,
11183 struct mlx5_flow_rss_desc *rss_desc,
11184 uint32_t *hrxq_idx)
11186 struct mlx5_flow_handle *dh = dev_flow->handle;
11187 struct mlx5_hrxq *hrxq;
11189 MLX5_ASSERT(rss_desc->queue_num);
11190 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
11191 rss_desc->hash_fields = dev_flow->hash_fields;
11192 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
11193 rss_desc->shared_rss = 0;
11194 if (rss_desc->hash_fields == 0)
11195 rss_desc->queue_num = 1;
11196 hrxq = mlx5_hrxq_get(dev, rss_desc);
11197 *hrxq_idx = hrxq ? hrxq->idx : 0;
11202 * Release sample sub action resource.
11204 * @param[in, out] dev
11205 * Pointer to rte_eth_dev structure.
11206 * @param[in] act_res
11207 * Pointer to sample sub action resource.
11210 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
11211 struct mlx5_flow_sub_actions_idx *act_res)
11213 if (act_res->rix_hrxq) {
11214 mlx5_hrxq_release(dev, act_res->rix_hrxq);
11215 act_res->rix_hrxq = 0;
11217 if (act_res->rix_encap_decap) {
11218 flow_dv_encap_decap_resource_release(dev,
11219 act_res->rix_encap_decap);
11220 act_res->rix_encap_decap = 0;
11222 if (act_res->rix_port_id_action) {
11223 flow_dv_port_id_action_resource_release(dev,
11224 act_res->rix_port_id_action);
11225 act_res->rix_port_id_action = 0;
11227 if (act_res->rix_tag) {
11228 flow_dv_tag_release(dev, act_res->rix_tag);
11229 act_res->rix_tag = 0;
11231 if (act_res->rix_jump) {
11232 flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
11233 act_res->rix_jump = 0;
11238 flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
11239 struct mlx5_list_entry *entry, void *cb_ctx)
11241 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11242 struct rte_eth_dev *dev = ctx->dev;
11243 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
11244 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
11248 if (ctx_resource->ratio == resource->ratio &&
11249 ctx_resource->ft_type == resource->ft_type &&
11250 ctx_resource->ft_id == resource->ft_id &&
11251 ctx_resource->set_action == resource->set_action &&
11252 !memcmp((void *)&ctx_resource->sample_act,
11253 (void *)&resource->sample_act,
11254 sizeof(struct mlx5_flow_sub_actions_list))) {
11256 * Existing sample action should release the prepared
11257 * sub-actions reference counter.
11259 flow_dv_sample_sub_actions_release(dev,
11260 &ctx_resource->sample_idx);
11266 struct mlx5_list_entry *
11267 flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11269 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11270 struct rte_eth_dev *dev = ctx->dev;
11271 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
11272 void **sample_dv_actions = ctx_resource->sub_actions;
11273 struct mlx5_flow_dv_sample_resource *resource;
11274 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
11275 struct mlx5_priv *priv = dev->data->dev_private;
11276 struct mlx5_dev_ctx_shared *sh = priv->sh;
11277 struct mlx5_flow_tbl_resource *tbl;
11279 const uint32_t next_ft_step = 1;
11280 uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
11281 uint8_t is_egress = 0;
11282 uint8_t is_transfer = 0;
11283 struct rte_flow_error *error = ctx->error;
11285 /* Register new sample resource. */
11286 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11288 rte_flow_error_set(error, ENOMEM,
11289 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11291 "cannot allocate resource memory");
11294 *resource = *ctx_resource;
11295 /* Create normal path table level */
11296 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11298 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
11300 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
11301 is_egress, is_transfer,
11302 true, NULL, 0, 0, 0, error);
11304 rte_flow_error_set(error, ENOMEM,
11305 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11307 "fail to create normal path table "
11311 resource->normal_path_tbl = tbl;
11312 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
11313 if (!sh->default_miss_action) {
11314 rte_flow_error_set(error, ENOMEM,
11315 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11317 "default miss action was not "
11321 sample_dv_actions[ctx_resource->sample_act.actions_num++] =
11322 sh->default_miss_action;
11324 /* Create a DR sample action */
11325 sampler_attr.sample_ratio = resource->ratio;
11326 sampler_attr.default_next_table = tbl->obj;
11327 sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
11328 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
11329 &sample_dv_actions[0];
11330 sampler_attr.action = resource->set_action;
11331 if (mlx5_os_flow_dr_create_flow_action_sampler
11332 (&sampler_attr, &resource->verbs_action)) {
11333 rte_flow_error_set(error, ENOMEM,
11334 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11335 NULL, "cannot create sample action");
11338 resource->idx = idx;
11339 resource->dev = dev;
11340 return &resource->entry;
11342 if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
11343 flow_dv_sample_sub_actions_release(dev,
11344 &resource->sample_idx);
11345 if (resource->normal_path_tbl)
11346 flow_dv_tbl_resource_release(MLX5_SH(dev),
11347 resource->normal_path_tbl);
11348 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
11353 struct mlx5_list_entry *
11354 flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
11355 struct mlx5_list_entry *entry __rte_unused,
11358 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11359 struct rte_eth_dev *dev = ctx->dev;
11360 struct mlx5_flow_dv_sample_resource *resource;
11361 struct mlx5_priv *priv = dev->data->dev_private;
11362 struct mlx5_dev_ctx_shared *sh = priv->sh;
11365 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11367 rte_flow_error_set(ctx->error, ENOMEM,
11368 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11370 "cannot allocate resource memory");
11373 memcpy(resource, entry, sizeof(*resource));
11374 resource->idx = idx;
11375 resource->dev = dev;
11376 return &resource->entry;
11380 flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
11381 struct mlx5_list_entry *entry)
11383 struct mlx5_flow_dv_sample_resource *resource =
11384 container_of(entry, typeof(*resource), entry);
11385 struct rte_eth_dev *dev = resource->dev;
11386 struct mlx5_priv *priv = dev->data->dev_private;
11388 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
11392 * Find existing sample resource or create and register a new one.
11394 * @param[in, out] dev
11395 * Pointer to rte_eth_dev structure.
11397 * Pointer to sample resource reference.
11398 * @parm[in, out] dev_flow
11399 * Pointer to the dev_flow.
11400 * @param[out] error
11401 * pointer to error structure.
11404 * 0 on success otherwise -errno and errno is set.
11407 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
11408 struct mlx5_flow_dv_sample_resource *ref,
11409 struct mlx5_flow *dev_flow,
11410 struct rte_flow_error *error)
11412 struct mlx5_flow_dv_sample_resource *resource;
11413 struct mlx5_list_entry *entry;
11414 struct mlx5_priv *priv = dev->data->dev_private;
11415 struct mlx5_flow_cb_ctx ctx = {
11421 entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
11424 resource = container_of(entry, typeof(*resource), entry);
11425 dev_flow->handle->dvh.rix_sample = resource->idx;
11426 dev_flow->dv.sample_res = resource;
11431 flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
11432 struct mlx5_list_entry *entry, void *cb_ctx)
11434 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11435 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11436 struct rte_eth_dev *dev = ctx->dev;
11437 struct mlx5_flow_dv_dest_array_resource *resource =
11438 container_of(entry, typeof(*resource), entry);
11441 if (ctx_resource->num_of_dest == resource->num_of_dest &&
11442 ctx_resource->ft_type == resource->ft_type &&
11443 !memcmp((void *)resource->sample_act,
11444 (void *)ctx_resource->sample_act,
11445 (ctx_resource->num_of_dest *
11446 sizeof(struct mlx5_flow_sub_actions_list)))) {
11448 * Existing sample action should release the prepared
11449 * sub-actions reference counter.
11451 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11452 flow_dv_sample_sub_actions_release(dev,
11453 &ctx_resource->sample_idx[idx]);
11459 struct mlx5_list_entry *
11460 flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11462 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11463 struct rte_eth_dev *dev = ctx->dev;
11464 struct mlx5_flow_dv_dest_array_resource *resource;
11465 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11466 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
11467 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
11468 struct mlx5_priv *priv = dev->data->dev_private;
11469 struct mlx5_dev_ctx_shared *sh = priv->sh;
11470 struct mlx5_flow_sub_actions_list *sample_act;
11471 struct mlx5dv_dr_domain *domain;
11472 uint32_t idx = 0, res_idx = 0;
11473 struct rte_flow_error *error = ctx->error;
11474 uint64_t action_flags;
11477 /* Register new destination array resource. */
11478 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11481 rte_flow_error_set(error, ENOMEM,
11482 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11484 "cannot allocate resource memory");
11487 *resource = *ctx_resource;
11488 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11489 domain = sh->fdb_domain;
11490 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
11491 domain = sh->rx_domain;
11493 domain = sh->tx_domain;
11494 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11495 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
11496 mlx5_malloc(MLX5_MEM_ZERO,
11497 sizeof(struct mlx5dv_dr_action_dest_attr),
11499 if (!dest_attr[idx]) {
11500 rte_flow_error_set(error, ENOMEM,
11501 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11503 "cannot allocate resource memory");
11506 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
11507 sample_act = &ctx_resource->sample_act[idx];
11508 action_flags = sample_act->action_flags;
11509 switch (action_flags) {
11510 case MLX5_FLOW_ACTION_QUEUE:
11511 dest_attr[idx]->dest = sample_act->dr_queue_action;
11513 case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
11514 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
11515 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
11516 dest_attr[idx]->dest_reformat->reformat =
11517 sample_act->dr_encap_action;
11518 dest_attr[idx]->dest_reformat->dest =
11519 sample_act->dr_port_id_action;
11521 case MLX5_FLOW_ACTION_PORT_ID:
11522 dest_attr[idx]->dest = sample_act->dr_port_id_action;
11524 case MLX5_FLOW_ACTION_JUMP:
11525 dest_attr[idx]->dest = sample_act->dr_jump_action;
11528 rte_flow_error_set(error, EINVAL,
11529 RTE_FLOW_ERROR_TYPE_ACTION,
11531 "unsupported actions type");
11535 /* create a dest array action */
11536 ret = mlx5_os_flow_dr_create_flow_action_dest_array
11538 resource->num_of_dest,
11540 &resource->action);
11542 rte_flow_error_set(error, ENOMEM,
11543 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11545 "cannot create destination array action");
11548 resource->idx = res_idx;
11549 resource->dev = dev;
11550 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11551 mlx5_free(dest_attr[idx]);
11552 return &resource->entry;
11554 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11555 flow_dv_sample_sub_actions_release(dev,
11556 &resource->sample_idx[idx]);
11557 if (dest_attr[idx])
11558 mlx5_free(dest_attr[idx]);
11560 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
11564 struct mlx5_list_entry *
11565 flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
11566 struct mlx5_list_entry *entry __rte_unused,
11569 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11570 struct rte_eth_dev *dev = ctx->dev;
11571 struct mlx5_flow_dv_dest_array_resource *resource;
11572 struct mlx5_priv *priv = dev->data->dev_private;
11573 struct mlx5_dev_ctx_shared *sh = priv->sh;
11574 uint32_t res_idx = 0;
11575 struct rte_flow_error *error = ctx->error;
11577 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11580 rte_flow_error_set(error, ENOMEM,
11581 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11583 "cannot allocate dest-array memory");
11586 memcpy(resource, entry, sizeof(*resource));
11587 resource->idx = res_idx;
11588 resource->dev = dev;
11589 return &resource->entry;
11593 flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
11594 struct mlx5_list_entry *entry)
11596 struct mlx5_flow_dv_dest_array_resource *resource =
11597 container_of(entry, typeof(*resource), entry);
11598 struct rte_eth_dev *dev = resource->dev;
11599 struct mlx5_priv *priv = dev->data->dev_private;
11601 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
11605 * Find existing destination array resource or create and register a new one.
11607 * @param[in, out] dev
11608 * Pointer to rte_eth_dev structure.
11610 * Pointer to destination array resource reference.
11611 * @parm[in, out] dev_flow
11612 * Pointer to the dev_flow.
11613 * @param[out] error
11614 * pointer to error structure.
11617 * 0 on success otherwise -errno and errno is set.
11620 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
11621 struct mlx5_flow_dv_dest_array_resource *ref,
11622 struct mlx5_flow *dev_flow,
11623 struct rte_flow_error *error)
11625 struct mlx5_flow_dv_dest_array_resource *resource;
11626 struct mlx5_priv *priv = dev->data->dev_private;
11627 struct mlx5_list_entry *entry;
11628 struct mlx5_flow_cb_ctx ctx = {
11634 entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
11637 resource = container_of(entry, typeof(*resource), entry);
11638 dev_flow->handle->dvh.rix_dest_array = resource->idx;
11639 dev_flow->dv.dest_array_res = resource;
11644 * Convert Sample action to DV specification.
11647 * Pointer to rte_eth_dev structure.
11648 * @param[in] action
11649 * Pointer to sample action structure.
11650 * @param[in, out] dev_flow
11651 * Pointer to the mlx5_flow.
11653 * Pointer to the flow attributes.
11654 * @param[in, out] num_of_dest
11655 * Pointer to the num of destination.
11656 * @param[in, out] sample_actions
11657 * Pointer to sample actions list.
11658 * @param[in, out] res
11659 * Pointer to sample resource.
11660 * @param[out] error
11661 * Pointer to the error structure.
11664 * 0 on success, a negative errno value otherwise and rte_errno is set.
11667 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
11668 const struct rte_flow_action_sample *action,
11669 struct mlx5_flow *dev_flow,
11670 const struct rte_flow_attr *attr,
11671 uint32_t *num_of_dest,
11672 void **sample_actions,
11673 struct mlx5_flow_dv_sample_resource *res,
11674 struct rte_flow_error *error)
11676 struct mlx5_priv *priv = dev->data->dev_private;
11677 const struct rte_flow_action *sub_actions;
11678 struct mlx5_flow_sub_actions_list *sample_act;
11679 struct mlx5_flow_sub_actions_idx *sample_idx;
11680 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11681 struct rte_flow *flow = dev_flow->flow;
11682 struct mlx5_flow_rss_desc *rss_desc;
11683 uint64_t action_flags = 0;
11686 rss_desc = &wks->rss_desc;
11687 sample_act = &res->sample_act;
11688 sample_idx = &res->sample_idx;
11689 res->ratio = action->ratio;
11690 sub_actions = action->actions;
11691 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
11692 int type = sub_actions->type;
11693 uint32_t pre_rix = 0;
11696 case RTE_FLOW_ACTION_TYPE_QUEUE:
11698 const struct rte_flow_action_queue *queue;
11699 struct mlx5_hrxq *hrxq;
11702 queue = sub_actions->conf;
11703 rss_desc->queue_num = 1;
11704 rss_desc->queue[0] = queue->index;
11705 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11706 rss_desc, &hrxq_idx);
11708 return rte_flow_error_set
11710 RTE_FLOW_ERROR_TYPE_ACTION,
11712 "cannot create fate queue");
11713 sample_act->dr_queue_action = hrxq->action;
11714 sample_idx->rix_hrxq = hrxq_idx;
11715 sample_actions[sample_act->actions_num++] =
11718 action_flags |= MLX5_FLOW_ACTION_QUEUE;
11719 if (action_flags & MLX5_FLOW_ACTION_MARK)
11720 dev_flow->handle->rix_hrxq = hrxq_idx;
11721 dev_flow->handle->fate_action =
11722 MLX5_FLOW_FATE_QUEUE;
11725 case RTE_FLOW_ACTION_TYPE_RSS:
11727 struct mlx5_hrxq *hrxq;
11729 const struct rte_flow_action_rss *rss;
11730 const uint8_t *rss_key;
11732 rss = sub_actions->conf;
11733 memcpy(rss_desc->queue, rss->queue,
11734 rss->queue_num * sizeof(uint16_t));
11735 rss_desc->queue_num = rss->queue_num;
11736 /* NULL RSS key indicates default RSS key. */
11737 rss_key = !rss->key ? rss_hash_default_key : rss->key;
11738 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
11740 * rss->level and rss.types should be set in advance
11741 * when expanding items for RSS.
11743 flow_dv_hashfields_set(dev_flow->handle->layers,
11745 &dev_flow->hash_fields);
11746 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11747 rss_desc, &hrxq_idx);
11749 return rte_flow_error_set
11751 RTE_FLOW_ERROR_TYPE_ACTION,
11753 "cannot create fate queue");
11754 sample_act->dr_queue_action = hrxq->action;
11755 sample_idx->rix_hrxq = hrxq_idx;
11756 sample_actions[sample_act->actions_num++] =
11759 action_flags |= MLX5_FLOW_ACTION_RSS;
11760 if (action_flags & MLX5_FLOW_ACTION_MARK)
11761 dev_flow->handle->rix_hrxq = hrxq_idx;
11762 dev_flow->handle->fate_action =
11763 MLX5_FLOW_FATE_QUEUE;
11766 case RTE_FLOW_ACTION_TYPE_MARK:
11768 uint32_t tag_be = mlx5_flow_mark_set
11769 (((const struct rte_flow_action_mark *)
11770 (sub_actions->conf))->id);
11773 pre_rix = dev_flow->handle->dvh.rix_tag;
11774 /* Save the mark resource before sample */
11775 pre_r = dev_flow->dv.tag_resource;
11776 if (flow_dv_tag_resource_register(dev, tag_be,
11779 MLX5_ASSERT(dev_flow->dv.tag_resource);
11780 sample_act->dr_tag_action =
11781 dev_flow->dv.tag_resource->action;
11782 sample_idx->rix_tag =
11783 dev_flow->handle->dvh.rix_tag;
11784 sample_actions[sample_act->actions_num++] =
11785 sample_act->dr_tag_action;
11786 /* Recover the mark resource after sample */
11787 dev_flow->dv.tag_resource = pre_r;
11788 dev_flow->handle->dvh.rix_tag = pre_rix;
11789 action_flags |= MLX5_FLOW_ACTION_MARK;
11792 case RTE_FLOW_ACTION_TYPE_COUNT:
11794 if (!flow->counter) {
11796 flow_dv_translate_create_counter(dev,
11797 dev_flow, sub_actions->conf,
11799 if (!flow->counter)
11800 return rte_flow_error_set
11802 RTE_FLOW_ERROR_TYPE_ACTION,
11804 "cannot create counter"
11807 sample_act->dr_cnt_action =
11808 (flow_dv_counter_get_by_idx(dev,
11809 flow->counter, NULL))->action;
11810 sample_actions[sample_act->actions_num++] =
11811 sample_act->dr_cnt_action;
11812 action_flags |= MLX5_FLOW_ACTION_COUNT;
11815 case RTE_FLOW_ACTION_TYPE_PORT_ID:
11816 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
11818 struct mlx5_flow_dv_port_id_action_resource
11820 uint32_t port_id = 0;
11822 memset(&port_id_resource, 0, sizeof(port_id_resource));
11823 /* Save the port id resource before sample */
11824 pre_rix = dev_flow->handle->rix_port_id_action;
11825 pre_r = dev_flow->dv.port_id_action;
11826 if (flow_dv_translate_action_port_id(dev, sub_actions,
11829 port_id_resource.port_id = port_id;
11830 if (flow_dv_port_id_action_resource_register
11831 (dev, &port_id_resource, dev_flow, error))
11833 sample_act->dr_port_id_action =
11834 dev_flow->dv.port_id_action->action;
11835 sample_idx->rix_port_id_action =
11836 dev_flow->handle->rix_port_id_action;
11837 sample_actions[sample_act->actions_num++] =
11838 sample_act->dr_port_id_action;
11839 /* Recover the port id resource after sample */
11840 dev_flow->dv.port_id_action = pre_r;
11841 dev_flow->handle->rix_port_id_action = pre_rix;
11843 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
11846 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11847 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11848 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11849 /* Save the encap resource before sample */
11850 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
11851 pre_r = dev_flow->dv.encap_decap;
11852 if (flow_dv_create_action_l2_encap(dev, sub_actions,
11857 sample_act->dr_encap_action =
11858 dev_flow->dv.encap_decap->action;
11859 sample_idx->rix_encap_decap =
11860 dev_flow->handle->dvh.rix_encap_decap;
11861 sample_actions[sample_act->actions_num++] =
11862 sample_act->dr_encap_action;
11863 /* Recover the encap resource after sample */
11864 dev_flow->dv.encap_decap = pre_r;
11865 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
11866 action_flags |= MLX5_FLOW_ACTION_ENCAP;
11869 return rte_flow_error_set(error, EINVAL,
11870 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11872 "Not support for sampler action");
11875 sample_act->action_flags = action_flags;
11876 res->ft_id = dev_flow->dv.group;
11877 if (attr->transfer) {
11879 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
11880 uint64_t set_action;
11881 } action_ctx = { .set_action = 0 };
11883 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
11884 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
11885 MLX5_MODIFICATION_TYPE_SET);
11886 MLX5_SET(set_action_in, action_ctx.action_in, field,
11887 MLX5_MODI_META_REG_C_0);
11888 MLX5_SET(set_action_in, action_ctx.action_in, data,
11889 priv->vport_meta_tag);
11890 res->set_action = action_ctx.set_action;
11891 } else if (attr->ingress) {
11892 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
11894 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
11900 * Convert Sample action to DV specification.
11903 * Pointer to rte_eth_dev structure.
11904 * @param[in, out] dev_flow
11905 * Pointer to the mlx5_flow.
11906 * @param[in] num_of_dest
11907 * The num of destination.
11908 * @param[in, out] res
11909 * Pointer to sample resource.
11910 * @param[in, out] mdest_res
11911 * Pointer to destination array resource.
11912 * @param[in] sample_actions
11913 * Pointer to sample path actions list.
11914 * @param[in] action_flags
11915 * Holds the actions detected until now.
11916 * @param[out] error
11917 * Pointer to the error structure.
11920 * 0 on success, a negative errno value otherwise and rte_errno is set.
11923 flow_dv_create_action_sample(struct rte_eth_dev *dev,
11924 struct mlx5_flow *dev_flow,
11925 uint32_t num_of_dest,
11926 struct mlx5_flow_dv_sample_resource *res,
11927 struct mlx5_flow_dv_dest_array_resource *mdest_res,
11928 void **sample_actions,
11929 uint64_t action_flags,
11930 struct rte_flow_error *error)
11932 /* update normal path action resource into last index of array */
11933 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
11934 struct mlx5_flow_sub_actions_list *sample_act =
11935 &mdest_res->sample_act[dest_index];
11936 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11937 struct mlx5_flow_rss_desc *rss_desc;
11938 uint32_t normal_idx = 0;
11939 struct mlx5_hrxq *hrxq;
11943 rss_desc = &wks->rss_desc;
11944 if (num_of_dest > 1) {
11945 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
11946 /* Handle QP action for mirroring */
11947 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11948 rss_desc, &hrxq_idx);
11950 return rte_flow_error_set
11952 RTE_FLOW_ERROR_TYPE_ACTION,
11954 "cannot create rx queue");
11956 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
11957 sample_act->dr_queue_action = hrxq->action;
11958 if (action_flags & MLX5_FLOW_ACTION_MARK)
11959 dev_flow->handle->rix_hrxq = hrxq_idx;
11960 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
11962 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
11964 mdest_res->sample_idx[dest_index].rix_encap_decap =
11965 dev_flow->handle->dvh.rix_encap_decap;
11966 sample_act->dr_encap_action =
11967 dev_flow->dv.encap_decap->action;
11968 dev_flow->handle->dvh.rix_encap_decap = 0;
11970 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
11972 mdest_res->sample_idx[dest_index].rix_port_id_action =
11973 dev_flow->handle->rix_port_id_action;
11974 sample_act->dr_port_id_action =
11975 dev_flow->dv.port_id_action->action;
11976 dev_flow->handle->rix_port_id_action = 0;
11978 if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
11980 mdest_res->sample_idx[dest_index].rix_jump =
11981 dev_flow->handle->rix_jump;
11982 sample_act->dr_jump_action =
11983 dev_flow->dv.jump->action;
11984 dev_flow->handle->rix_jump = 0;
11986 sample_act->actions_num = normal_idx;
11987 /* update sample action resource into first index of array */
11988 mdest_res->ft_type = res->ft_type;
11989 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
11990 sizeof(struct mlx5_flow_sub_actions_idx));
11991 memcpy(&mdest_res->sample_act[0], &res->sample_act,
11992 sizeof(struct mlx5_flow_sub_actions_list));
11993 mdest_res->num_of_dest = num_of_dest;
11994 if (flow_dv_dest_array_resource_register(dev, mdest_res,
11996 return rte_flow_error_set(error, EINVAL,
11997 RTE_FLOW_ERROR_TYPE_ACTION,
11998 NULL, "can't create sample "
12001 res->sub_actions = sample_actions;
12002 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
12003 return rte_flow_error_set(error, EINVAL,
12004 RTE_FLOW_ERROR_TYPE_ACTION,
12006 "can't create sample action");
12012 * Remove an ASO age action from age actions list.
12015 * Pointer to the Ethernet device structure.
12017 * Pointer to the aso age action handler.
12020 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
12021 struct mlx5_aso_age_action *age)
12023 struct mlx5_age_info *age_info;
12024 struct mlx5_age_param *age_param = &age->age_params;
12025 struct mlx5_priv *priv = dev->data->dev_private;
12026 uint16_t expected = AGE_CANDIDATE;
12028 age_info = GET_PORT_AGE_INFO(priv);
12029 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
12030 AGE_FREE, false, __ATOMIC_RELAXED,
12031 __ATOMIC_RELAXED)) {
12033 * We need the lock even it is age timeout,
12034 * since age action may still in process.
12036 rte_spinlock_lock(&age_info->aged_sl);
12037 LIST_REMOVE(age, next);
12038 rte_spinlock_unlock(&age_info->aged_sl);
12039 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
12044 * Release an ASO age action.
12047 * Pointer to the Ethernet device structure.
12048 * @param[in] age_idx
12049 * Index of ASO age action to release.
12051 * True if the release operation is during flow destroy operation.
12052 * False if the release operation is during action destroy operation.
12055 * 0 when age action was removed, otherwise the number of references.
12058 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
12060 struct mlx5_priv *priv = dev->data->dev_private;
12061 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12062 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
12063 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
12066 flow_dv_aso_age_remove_from_age(dev, age);
12067 rte_spinlock_lock(&mng->free_sl);
12068 LIST_INSERT_HEAD(&mng->free, age, next);
12069 rte_spinlock_unlock(&mng->free_sl);
12075 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
12078 * Pointer to the Ethernet device structure.
12081 * 0 on success, otherwise negative errno value and rte_errno is set.
12084 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
12086 struct mlx5_priv *priv = dev->data->dev_private;
12087 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12088 void *old_pools = mng->pools;
12089 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
12090 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
12091 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
12094 rte_errno = ENOMEM;
12098 memcpy(pools, old_pools,
12099 mng->n * sizeof(struct mlx5_flow_counter_pool *));
12100 mlx5_free(old_pools);
12102 /* First ASO flow hit allocation - starting ASO data-path. */
12103 int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
12111 mng->pools = pools;
12116 * Create and initialize a new ASO aging pool.
12119 * Pointer to the Ethernet device structure.
12120 * @param[out] age_free
12121 * Where to put the pointer of a new age action.
12124 * The age actions pool pointer and @p age_free is set on success,
12125 * NULL otherwise and rte_errno is set.
12127 static struct mlx5_aso_age_pool *
12128 flow_dv_age_pool_create(struct rte_eth_dev *dev,
12129 struct mlx5_aso_age_action **age_free)
12131 struct mlx5_priv *priv = dev->data->dev_private;
12132 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12133 struct mlx5_aso_age_pool *pool = NULL;
12134 struct mlx5_devx_obj *obj = NULL;
12137 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
12138 priv->sh->cdev->pdn);
12140 rte_errno = ENODATA;
12141 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
12144 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
12146 claim_zero(mlx5_devx_cmd_destroy(obj));
12147 rte_errno = ENOMEM;
12150 pool->flow_hit_aso_obj = obj;
12151 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
12152 rte_rwlock_write_lock(&mng->resize_rwl);
12153 pool->index = mng->next;
12154 /* Resize pools array if there is no room for the new pool in it. */
12155 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
12156 claim_zero(mlx5_devx_cmd_destroy(obj));
12158 rte_rwlock_write_unlock(&mng->resize_rwl);
12161 mng->pools[pool->index] = pool;
12163 rte_rwlock_write_unlock(&mng->resize_rwl);
12164 /* Assign the first action in the new pool, the rest go to free list. */
12165 *age_free = &pool->actions[0];
12166 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
12167 pool->actions[i].offset = i;
12168 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
12174 * Allocate a ASO aging bit.
12177 * Pointer to the Ethernet device structure.
12178 * @param[out] error
12179 * Pointer to the error structure.
12182 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
12185 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
12187 struct mlx5_priv *priv = dev->data->dev_private;
12188 const struct mlx5_aso_age_pool *pool;
12189 struct mlx5_aso_age_action *age_free = NULL;
12190 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
12193 /* Try to get the next free age action bit. */
12194 rte_spinlock_lock(&mng->free_sl);
12195 age_free = LIST_FIRST(&mng->free);
12197 LIST_REMOVE(age_free, next);
12198 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
12199 rte_spinlock_unlock(&mng->free_sl);
12200 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
12201 NULL, "failed to create ASO age pool");
12202 return 0; /* 0 is an error. */
12204 rte_spinlock_unlock(&mng->free_sl);
12205 pool = container_of
12206 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
12207 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
12209 if (!age_free->dr_action) {
12210 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
12214 rte_flow_error_set(error, rte_errno,
12215 RTE_FLOW_ERROR_TYPE_ACTION,
12216 NULL, "failed to get reg_c "
12217 "for ASO flow hit");
12218 return 0; /* 0 is an error. */
12220 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
12221 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
12222 (priv->sh->rx_domain,
12223 pool->flow_hit_aso_obj->obj, age_free->offset,
12224 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
12225 (reg_c - REG_C_0));
12226 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
12227 if (!age_free->dr_action) {
12229 rte_spinlock_lock(&mng->free_sl);
12230 LIST_INSERT_HEAD(&mng->free, age_free, next);
12231 rte_spinlock_unlock(&mng->free_sl);
12232 rte_flow_error_set(error, rte_errno,
12233 RTE_FLOW_ERROR_TYPE_ACTION,
12234 NULL, "failed to create ASO "
12235 "flow hit action");
12236 return 0; /* 0 is an error. */
12239 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
12240 return pool->index | ((age_free->offset + 1) << 16);
12244 * Initialize flow ASO age parameters.
12247 * Pointer to rte_eth_dev structure.
12248 * @param[in] age_idx
12249 * Index of ASO age action.
12250 * @param[in] context
12251 * Pointer to flow counter age context.
12252 * @param[in] timeout
12253 * Aging timeout in seconds.
12257 flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
12262 struct mlx5_aso_age_action *aso_age;
12264 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
12265 MLX5_ASSERT(aso_age);
12266 aso_age->age_params.context = context;
12267 aso_age->age_params.timeout = timeout;
12268 aso_age->age_params.port_id = dev->data->port_id;
12269 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
12271 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
12276 flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
12277 const struct rte_flow_item_integrity *value,
12278 void *headers_m, void *headers_v)
12281 /* RTE l4_ok filter aggregates hardware l4_ok and
12282 * l4_checksum_ok filters.
12283 * Positive RTE l4_ok match requires hardware match on both L4
12284 * hardware integrity bits.
12285 * For negative match, check hardware l4_checksum_ok bit only,
12286 * because hardware sets that bit to 0 for all packets
12289 if (value->l4_ok) {
12290 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_ok, 1);
12291 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_ok, 1);
12293 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok, 1);
12294 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_checksum_ok,
12297 if (mask->l4_csum_ok) {
12298 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok, 1);
12299 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_checksum_ok,
12300 value->l4_csum_ok);
12305 flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
12306 const struct rte_flow_item_integrity *value,
12307 void *headers_m, void *headers_v, bool is_ipv4)
12310 /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
12311 * ipv4_csum_ok filters.
12312 * Positive RTE l3_ok match requires hardware match on both L3
12313 * hardware integrity bits.
12314 * For negative match, check hardware l3_csum_ok bit only,
12315 * because hardware sets that bit to 0 for all packets
12319 if (value->l3_ok) {
12320 MLX5_SET(fte_match_set_lyr_2_4, headers_m,
12322 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12325 MLX5_SET(fte_match_set_lyr_2_4, headers_m,
12326 ipv4_checksum_ok, 1);
12327 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12328 ipv4_checksum_ok, !!value->l3_ok);
12330 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l3_ok, 1);
12331 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l3_ok,
12335 if (mask->ipv4_csum_ok) {
12336 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok, 1);
12337 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
12338 value->ipv4_csum_ok);
12343 set_integrity_bits(void *headers_m, void *headers_v,
12344 const struct rte_flow_item *integrity_item, bool is_l3_ip4)
12346 const struct rte_flow_item_integrity *spec = integrity_item->spec;
12347 const struct rte_flow_item_integrity *mask = integrity_item->mask;
12349 /* Integrity bits validation cleared spec pointer */
12350 MLX5_ASSERT(spec != NULL);
12352 mask = &rte_flow_item_integrity_mask;
12353 flow_dv_translate_integrity_l3(mask, spec, headers_m, headers_v,
12355 flow_dv_translate_integrity_l4(mask, spec, headers_m, headers_v);
12359 flow_dv_translate_item_integrity_post(void *matcher, void *key,
12361 struct rte_flow_item *integrity_items[2],
12362 uint64_t pattern_flags)
12364 void *headers_m, *headers_v;
12367 if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
12368 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12370 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
12371 is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
12373 set_integrity_bits(headers_m, headers_v,
12374 integrity_items[1], is_l3_ip4);
12376 if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
12377 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12379 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
12380 is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
12382 set_integrity_bits(headers_m, headers_v,
12383 integrity_items[0], is_l3_ip4);
12388 flow_dv_translate_item_integrity(const struct rte_flow_item *item,
12389 const struct rte_flow_item *integrity_items[2],
12390 uint64_t *last_item)
12392 const struct rte_flow_item_integrity *spec = (typeof(spec))item->spec;
12394 /* integrity bits validation cleared spec pointer */
12395 MLX5_ASSERT(spec != NULL);
12396 if (spec->level > 1) {
12397 integrity_items[1] = item;
12398 *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
12400 integrity_items[0] = item;
12401 *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
12406 * Prepares DV flow counter with aging configuration.
12407 * Gets it by index when exists, creates a new one when doesn't.
12410 * Pointer to rte_eth_dev structure.
12411 * @param[in] dev_flow
12412 * Pointer to the mlx5_flow.
12413 * @param[in, out] flow
12414 * Pointer to the sub flow.
12416 * Pointer to the counter action configuration.
12418 * Pointer to the aging action configuration.
12419 * @param[out] error
12420 * Pointer to the error structure.
12423 * Pointer to the counter, NULL otherwise.
12425 static struct mlx5_flow_counter *
12426 flow_dv_prepare_counter(struct rte_eth_dev *dev,
12427 struct mlx5_flow *dev_flow,
12428 struct rte_flow *flow,
12429 const struct rte_flow_action_count *count,
12430 const struct rte_flow_action_age *age,
12431 struct rte_flow_error *error)
12433 if (!flow->counter) {
12434 flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
12436 if (!flow->counter) {
12437 rte_flow_error_set(error, rte_errno,
12438 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12439 "cannot create counter object.");
12443 return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
12447 * Release an ASO CT action by its own device.
12450 * Pointer to the Ethernet device structure.
12452 * Index of ASO CT action to release.
12455 * 0 when CT action was removed, otherwise the number of references.
12458 flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
12460 struct mlx5_priv *priv = dev->data->dev_private;
12461 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12463 struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12464 enum mlx5_aso_ct_state state =
12465 __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
12467 /* Cannot release when CT is in the ASO SQ. */
12468 if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
12470 ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
12472 if (ct->dr_action_orig) {
12473 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12474 claim_zero(mlx5_glue->destroy_flow_action
12475 (ct->dr_action_orig));
12477 ct->dr_action_orig = NULL;
12479 if (ct->dr_action_rply) {
12480 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12481 claim_zero(mlx5_glue->destroy_flow_action
12482 (ct->dr_action_rply));
12484 ct->dr_action_rply = NULL;
12486 /* Clear the state to free, no need in 1st allocation. */
12487 MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
12488 rte_spinlock_lock(&mng->ct_sl);
12489 LIST_INSERT_HEAD(&mng->free_cts, ct, next);
12490 rte_spinlock_unlock(&mng->ct_sl);
12496 flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
12497 struct rte_flow_error *error)
12499 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
12500 uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
12501 struct rte_eth_dev *owndev = &rte_eth_devices[owner];
12504 MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
12505 if (dev->data->dev_started != 1)
12506 return rte_flow_error_set(error, EAGAIN,
12507 RTE_FLOW_ERROR_TYPE_ACTION,
12509 "Indirect CT action cannot be destroyed when the port is stopped");
12510 ret = flow_dv_aso_ct_dev_release(owndev, idx);
12512 return rte_flow_error_set(error, EAGAIN,
12513 RTE_FLOW_ERROR_TYPE_ACTION,
12515 "Current state prevents indirect CT action from being destroyed");
12520 * Resize the ASO CT pools array by 64 pools.
12523 * Pointer to the Ethernet device structure.
12526 * 0 on success, otherwise negative errno value and rte_errno is set.
12529 flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
12531 struct mlx5_priv *priv = dev->data->dev_private;
12532 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12533 void *old_pools = mng->pools;
12534 /* Magic number now, need a macro. */
12535 uint32_t resize = mng->n + 64;
12536 uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
12537 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
12540 rte_errno = ENOMEM;
12543 rte_rwlock_write_lock(&mng->resize_rwl);
12544 /* ASO SQ/QP was already initialized in the startup. */
12546 /* Realloc could be an alternative choice. */
12547 rte_memcpy(pools, old_pools,
12548 mng->n * sizeof(struct mlx5_aso_ct_pool *));
12549 mlx5_free(old_pools);
12552 mng->pools = pools;
12553 rte_rwlock_write_unlock(&mng->resize_rwl);
12558 * Create and initialize a new ASO CT pool.
12561 * Pointer to the Ethernet device structure.
12562 * @param[out] ct_free
12563 * Where to put the pointer of a new CT action.
12566 * The CT actions pool pointer and @p ct_free is set on success,
12567 * NULL otherwise and rte_errno is set.
12569 static struct mlx5_aso_ct_pool *
12570 flow_dv_ct_pool_create(struct rte_eth_dev *dev,
12571 struct mlx5_aso_ct_action **ct_free)
12573 struct mlx5_priv *priv = dev->data->dev_private;
12574 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12575 struct mlx5_aso_ct_pool *pool = NULL;
12576 struct mlx5_devx_obj *obj = NULL;
12578 uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
12580 obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
12581 priv->sh->cdev->pdn,
12584 rte_errno = ENODATA;
12585 DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
12588 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
12590 rte_errno = ENOMEM;
12591 claim_zero(mlx5_devx_cmd_destroy(obj));
12594 pool->devx_obj = obj;
12595 pool->index = mng->next;
12596 /* Resize pools array if there is no room for the new pool in it. */
12597 if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
12598 claim_zero(mlx5_devx_cmd_destroy(obj));
12602 mng->pools[pool->index] = pool;
12604 /* Assign the first action in the new pool, the rest go to free list. */
12605 *ct_free = &pool->actions[0];
12606 /* Lock outside, the list operation is safe here. */
12607 for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
12608 /* refcnt is 0 when allocating the memory. */
12609 pool->actions[i].offset = i;
12610 LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
12616 * Allocate a ASO CT action from free list.
12619 * Pointer to the Ethernet device structure.
12620 * @param[out] error
12621 * Pointer to the error structure.
12624 * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
12627 flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
12629 struct mlx5_priv *priv = dev->data->dev_private;
12630 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12631 struct mlx5_aso_ct_action *ct = NULL;
12632 struct mlx5_aso_ct_pool *pool;
12637 if (!priv->sh->cdev->config.devx) {
12638 rte_errno = ENOTSUP;
12641 /* Get a free CT action, if no, a new pool will be created. */
12642 rte_spinlock_lock(&mng->ct_sl);
12643 ct = LIST_FIRST(&mng->free_cts);
12645 LIST_REMOVE(ct, next);
12646 } else if (!flow_dv_ct_pool_create(dev, &ct)) {
12647 rte_spinlock_unlock(&mng->ct_sl);
12648 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
12649 NULL, "failed to create ASO CT pool");
12652 rte_spinlock_unlock(&mng->ct_sl);
12653 pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
12654 ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
12655 /* 0: inactive, 1: created, 2+: used by flows. */
12656 __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
12657 reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
12658 if (!ct->dr_action_orig) {
12659 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12660 ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
12661 (priv->sh->rx_domain, pool->devx_obj->obj,
12663 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
12666 RTE_SET_USED(reg_c);
12668 if (!ct->dr_action_orig) {
12669 flow_dv_aso_ct_dev_release(dev, ct_idx);
12670 rte_flow_error_set(error, rte_errno,
12671 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12672 "failed to create ASO CT action");
12676 if (!ct->dr_action_rply) {
12677 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12678 ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
12679 (priv->sh->rx_domain, pool->devx_obj->obj,
12681 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
12684 if (!ct->dr_action_rply) {
12685 flow_dv_aso_ct_dev_release(dev, ct_idx);
12686 rte_flow_error_set(error, rte_errno,
12687 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12688 "failed to create ASO CT action");
12696 * Create a conntrack object with context and actions by using ASO mechanism.
12699 * Pointer to rte_eth_dev structure.
12701 * Pointer to conntrack information profile.
12702 * @param[out] error
12703 * Pointer to the error structure.
12706 * Index to conntrack object on success, 0 otherwise.
12709 flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
12710 const struct rte_flow_action_conntrack *pro,
12711 struct rte_flow_error *error)
12713 struct mlx5_priv *priv = dev->data->dev_private;
12714 struct mlx5_dev_ctx_shared *sh = priv->sh;
12715 struct mlx5_aso_ct_action *ct;
12718 if (!sh->ct_aso_en)
12719 return rte_flow_error_set(error, ENOTSUP,
12720 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12721 "Connection is not supported");
12722 idx = flow_dv_aso_ct_alloc(dev, error);
12724 return rte_flow_error_set(error, rte_errno,
12725 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12726 "Failed to allocate CT object");
12727 ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12728 if (mlx5_aso_ct_update_by_wqe(sh, ct, pro))
12729 return rte_flow_error_set(error, EBUSY,
12730 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12731 "Failed to update CT");
12732 ct->is_original = !!pro->is_original_dir;
12733 ct->peer = pro->peer_port;
12738 * Fill the flow with DV spec, lock free
12739 * (mutex should be acquired by caller).
12742 * Pointer to rte_eth_dev structure.
12743 * @param[in, out] dev_flow
12744 * Pointer to the sub flow.
12746 * Pointer to the flow attributes.
12748 * Pointer to the list of items.
12749 * @param[in] actions
12750 * Pointer to the list of actions.
12751 * @param[out] error
12752 * Pointer to the error structure.
12755 * 0 on success, a negative errno value otherwise and rte_errno is set.
12758 flow_dv_translate(struct rte_eth_dev *dev,
12759 struct mlx5_flow *dev_flow,
12760 const struct rte_flow_attr *attr,
12761 const struct rte_flow_item items[],
12762 const struct rte_flow_action actions[],
12763 struct rte_flow_error *error)
12765 struct mlx5_priv *priv = dev->data->dev_private;
12766 struct mlx5_sh_config *dev_conf = &priv->sh->config;
12767 struct rte_flow *flow = dev_flow->flow;
12768 struct mlx5_flow_handle *handle = dev_flow->handle;
12769 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12770 struct mlx5_flow_rss_desc *rss_desc;
12771 uint64_t item_flags = 0;
12772 uint64_t last_item = 0;
12773 uint64_t action_flags = 0;
12774 struct mlx5_flow_dv_matcher matcher = {
12776 .size = sizeof(matcher.mask.buf),
12780 bool actions_end = false;
12782 struct mlx5_flow_dv_modify_hdr_resource res;
12783 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
12784 sizeof(struct mlx5_modification_cmd) *
12785 (MLX5_MAX_MODIFY_NUM + 1)];
12787 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
12788 const struct rte_flow_action_count *count = NULL;
12789 const struct rte_flow_action_age *non_shared_age = NULL;
12790 union flow_dv_attr flow_attr = { .attr = 0 };
12792 union mlx5_flow_tbl_key tbl_key;
12793 uint32_t modify_action_position = UINT32_MAX;
12794 void *match_mask = matcher.mask.buf;
12795 void *match_value = dev_flow->dv.value.buf;
12796 uint8_t next_protocol = 0xff;
12797 struct rte_vlan_hdr vlan = { 0 };
12798 struct mlx5_flow_dv_dest_array_resource mdest_res;
12799 struct mlx5_flow_dv_sample_resource sample_res;
12800 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
12801 const struct rte_flow_action_sample *sample = NULL;
12802 struct mlx5_flow_sub_actions_list *sample_act;
12803 uint32_t sample_act_pos = UINT32_MAX;
12804 uint32_t age_act_pos = UINT32_MAX;
12805 uint32_t num_of_dest = 0;
12806 int tmp_actions_n = 0;
12809 const struct mlx5_flow_tunnel *tunnel = NULL;
12810 struct flow_grp_info grp_info = {
12811 .external = !!dev_flow->external,
12812 .transfer = !!attr->transfer,
12813 .fdb_def_rule = !!priv->fdb_def_rule,
12814 .skip_scale = dev_flow->skip_scale &
12815 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
12816 .std_tbl_fix = true,
12818 const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
12819 const struct rte_flow_item *tunnel_item = NULL;
12820 const struct rte_flow_item *gre_item = NULL;
12823 return rte_flow_error_set(error, ENOMEM,
12824 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12826 "failed to push flow workspace");
12827 rss_desc = &wks->rss_desc;
12828 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
12829 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
12830 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12831 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12832 /* update normal path action resource into last index of array */
12833 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
12834 if (is_tunnel_offload_active(dev)) {
12835 if (dev_flow->tunnel) {
12836 RTE_VERIFY(dev_flow->tof_type ==
12837 MLX5_TUNNEL_OFFLOAD_MISS_RULE);
12838 tunnel = dev_flow->tunnel;
12840 tunnel = mlx5_get_tof(items, actions,
12841 &dev_flow->tof_type);
12842 dev_flow->tunnel = tunnel;
12844 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
12845 (dev, attr, tunnel, dev_flow->tof_type);
12847 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12848 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12849 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
12853 dev_flow->dv.group = table;
12854 if (attr->transfer)
12855 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12856 /* number of actions must be set to 0 in case of dirty stack. */
12857 mhdr_res->actions_num = 0;
12858 if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
12860 * do not add decap action if match rule drops packet
12861 * HW rejects rules with decap & drop
12863 * if tunnel match rule was inserted before matching tunnel set
12864 * rule flow table used in the match rule must be registered.
12865 * current implementation handles that in the
12866 * flow_dv_match_register() at the function end.
12868 bool add_decap = true;
12869 const struct rte_flow_action *ptr = actions;
12871 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
12872 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
12878 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12882 dev_flow->dv.actions[actions_n++] =
12883 dev_flow->dv.encap_decap->action;
12884 action_flags |= MLX5_FLOW_ACTION_DECAP;
12887 for (; !actions_end ; actions++) {
12888 const struct rte_flow_action_queue *queue;
12889 const struct rte_flow_action_rss *rss;
12890 const struct rte_flow_action *action = actions;
12891 const uint8_t *rss_key;
12892 struct mlx5_flow_tbl_resource *tbl;
12893 struct mlx5_aso_age_action *age_act;
12894 struct mlx5_flow_counter *cnt_act;
12895 uint32_t port_id = 0;
12896 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
12897 int action_type = actions->type;
12898 const struct rte_flow_action *found_action = NULL;
12899 uint32_t jump_group = 0;
12900 uint32_t owner_idx;
12901 struct mlx5_aso_ct_action *ct;
12903 if (!mlx5_flow_os_action_supported(action_type))
12904 return rte_flow_error_set(error, ENOTSUP,
12905 RTE_FLOW_ERROR_TYPE_ACTION,
12907 "action not supported");
12908 switch (action_type) {
12909 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
12910 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
12912 case RTE_FLOW_ACTION_TYPE_VOID:
12914 case RTE_FLOW_ACTION_TYPE_PORT_ID:
12915 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
12916 if (flow_dv_translate_action_port_id(dev, action,
12919 port_id_resource.port_id = port_id;
12920 MLX5_ASSERT(!handle->rix_port_id_action);
12921 if (flow_dv_port_id_action_resource_register
12922 (dev, &port_id_resource, dev_flow, error))
12924 dev_flow->dv.actions[actions_n++] =
12925 dev_flow->dv.port_id_action->action;
12926 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12927 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
12928 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12931 case RTE_FLOW_ACTION_TYPE_FLAG:
12932 action_flags |= MLX5_FLOW_ACTION_FLAG;
12934 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12935 struct rte_flow_action_mark mark = {
12936 .id = MLX5_FLOW_MARK_DEFAULT,
12939 if (flow_dv_convert_action_mark(dev, &mark,
12943 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12946 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
12948 * Only one FLAG or MARK is supported per device flow
12949 * right now. So the pointer to the tag resource must be
12950 * zero before the register process.
12952 MLX5_ASSERT(!handle->dvh.rix_tag);
12953 if (flow_dv_tag_resource_register(dev, tag_be,
12956 MLX5_ASSERT(dev_flow->dv.tag_resource);
12957 dev_flow->dv.actions[actions_n++] =
12958 dev_flow->dv.tag_resource->action;
12960 case RTE_FLOW_ACTION_TYPE_MARK:
12961 action_flags |= MLX5_FLOW_ACTION_MARK;
12963 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12964 const struct rte_flow_action_mark *mark =
12965 (const struct rte_flow_action_mark *)
12968 if (flow_dv_convert_action_mark(dev, mark,
12972 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12976 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
12977 /* Legacy (non-extensive) MARK action. */
12978 tag_be = mlx5_flow_mark_set
12979 (((const struct rte_flow_action_mark *)
12980 (actions->conf))->id);
12981 MLX5_ASSERT(!handle->dvh.rix_tag);
12982 if (flow_dv_tag_resource_register(dev, tag_be,
12985 MLX5_ASSERT(dev_flow->dv.tag_resource);
12986 dev_flow->dv.actions[actions_n++] =
12987 dev_flow->dv.tag_resource->action;
12989 case RTE_FLOW_ACTION_TYPE_SET_META:
12990 if (flow_dv_convert_action_set_meta
12991 (dev, mhdr_res, attr,
12992 (const struct rte_flow_action_set_meta *)
12993 actions->conf, error))
12995 action_flags |= MLX5_FLOW_ACTION_SET_META;
12997 case RTE_FLOW_ACTION_TYPE_SET_TAG:
12998 if (flow_dv_convert_action_set_tag
13000 (const struct rte_flow_action_set_tag *)
13001 actions->conf, error))
13003 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13005 case RTE_FLOW_ACTION_TYPE_DROP:
13006 action_flags |= MLX5_FLOW_ACTION_DROP;
13007 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
13009 case RTE_FLOW_ACTION_TYPE_QUEUE:
13010 queue = actions->conf;
13011 rss_desc->queue_num = 1;
13012 rss_desc->queue[0] = queue->index;
13013 action_flags |= MLX5_FLOW_ACTION_QUEUE;
13014 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
13015 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
13018 case RTE_FLOW_ACTION_TYPE_RSS:
13019 rss = actions->conf;
13020 memcpy(rss_desc->queue, rss->queue,
13021 rss->queue_num * sizeof(uint16_t));
13022 rss_desc->queue_num = rss->queue_num;
13023 /* NULL RSS key indicates default RSS key. */
13024 rss_key = !rss->key ? rss_hash_default_key : rss->key;
13025 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
13027 * rss->level and rss.types should be set in advance
13028 * when expanding items for RSS.
13030 action_flags |= MLX5_FLOW_ACTION_RSS;
13031 dev_flow->handle->fate_action = rss_desc->shared_rss ?
13032 MLX5_FLOW_FATE_SHARED_RSS :
13033 MLX5_FLOW_FATE_QUEUE;
13035 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
13036 owner_idx = (uint32_t)(uintptr_t)action->conf;
13037 age_act = flow_aso_age_get_by_idx(dev, owner_idx);
13038 if (flow->age == 0) {
13039 flow->age = owner_idx;
13040 __atomic_fetch_add(&age_act->refcnt, 1,
13043 age_act_pos = actions_n++;
13044 action_flags |= MLX5_FLOW_ACTION_AGE;
13046 case RTE_FLOW_ACTION_TYPE_AGE:
13047 non_shared_age = action->conf;
13048 age_act_pos = actions_n++;
13049 action_flags |= MLX5_FLOW_ACTION_AGE;
13051 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
13052 owner_idx = (uint32_t)(uintptr_t)action->conf;
13053 cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
13055 MLX5_ASSERT(cnt_act != NULL);
13057 * When creating meter drop flow in drop table, the
13058 * counter should not overwrite the rte flow counter.
13060 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
13061 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
13062 dev_flow->dv.actions[actions_n++] =
13065 if (flow->counter == 0) {
13066 flow->counter = owner_idx;
13068 (&cnt_act->shared_info.refcnt,
13069 1, __ATOMIC_RELAXED);
13071 /* Save information first, will apply later. */
13072 action_flags |= MLX5_FLOW_ACTION_COUNT;
13075 case RTE_FLOW_ACTION_TYPE_COUNT:
13076 if (!priv->sh->cdev->config.devx) {
13077 return rte_flow_error_set
13079 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13081 "count action not supported");
13083 /* Save information first, will apply later. */
13084 count = action->conf;
13085 action_flags |= MLX5_FLOW_ACTION_COUNT;
13087 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
13088 dev_flow->dv.actions[actions_n++] =
13089 priv->sh->pop_vlan_action;
13090 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
13092 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
13093 if (!(action_flags &
13094 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
13095 flow_dev_get_vlan_info_from_items(items, &vlan);
13096 vlan.eth_proto = rte_be_to_cpu_16
13097 ((((const struct rte_flow_action_of_push_vlan *)
13098 actions->conf)->ethertype));
13099 found_action = mlx5_flow_find_action
13101 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
13103 mlx5_update_vlan_vid_pcp(found_action, &vlan);
13104 found_action = mlx5_flow_find_action
13106 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
13108 mlx5_update_vlan_vid_pcp(found_action, &vlan);
13109 if (flow_dv_create_action_push_vlan
13110 (dev, attr, &vlan, dev_flow, error))
13112 dev_flow->dv.actions[actions_n++] =
13113 dev_flow->dv.push_vlan_res->action;
13114 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
13116 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
13117 /* of_vlan_push action handled this action */
13118 MLX5_ASSERT(action_flags &
13119 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
13121 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
13122 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
13124 flow_dev_get_vlan_info_from_items(items, &vlan);
13125 mlx5_update_vlan_vid_pcp(actions, &vlan);
13126 /* If no VLAN push - this is a modify header action */
13127 if (flow_dv_convert_action_modify_vlan_vid
13128 (mhdr_res, actions, error))
13130 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
13132 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13133 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13134 if (flow_dv_create_action_l2_encap(dev, actions,
13139 dev_flow->dv.actions[actions_n++] =
13140 dev_flow->dv.encap_decap->action;
13141 action_flags |= MLX5_FLOW_ACTION_ENCAP;
13142 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
13143 sample_act->action_flags |=
13144 MLX5_FLOW_ACTION_ENCAP;
13146 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
13147 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
13148 if (flow_dv_create_action_l2_decap(dev, dev_flow,
13152 dev_flow->dv.actions[actions_n++] =
13153 dev_flow->dv.encap_decap->action;
13154 action_flags |= MLX5_FLOW_ACTION_DECAP;
13156 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13157 /* Handle encap with preceding decap. */
13158 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
13159 if (flow_dv_create_action_raw_encap
13160 (dev, actions, dev_flow, attr, error))
13162 dev_flow->dv.actions[actions_n++] =
13163 dev_flow->dv.encap_decap->action;
13165 /* Handle encap without preceding decap. */
13166 if (flow_dv_create_action_l2_encap
13167 (dev, actions, dev_flow, attr->transfer,
13170 dev_flow->dv.actions[actions_n++] =
13171 dev_flow->dv.encap_decap->action;
13173 action_flags |= MLX5_FLOW_ACTION_ENCAP;
13174 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
13175 sample_act->action_flags |=
13176 MLX5_FLOW_ACTION_ENCAP;
13178 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
13179 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
13181 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
13182 if (flow_dv_create_action_l2_decap
13183 (dev, dev_flow, attr->transfer, error))
13185 dev_flow->dv.actions[actions_n++] =
13186 dev_flow->dv.encap_decap->action;
13188 /* If decap is followed by encap, handle it at encap. */
13189 action_flags |= MLX5_FLOW_ACTION_DECAP;
13191 case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
13192 dev_flow->dv.actions[actions_n++] =
13193 (void *)(uintptr_t)action->conf;
13194 action_flags |= MLX5_FLOW_ACTION_JUMP;
13196 case RTE_FLOW_ACTION_TYPE_JUMP:
13197 jump_group = ((const struct rte_flow_action_jump *)
13198 action->conf)->group;
13199 grp_info.std_tbl_fix = 0;
13200 if (dev_flow->skip_scale &
13201 (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
13202 grp_info.skip_scale = 1;
13204 grp_info.skip_scale = 0;
13205 ret = mlx5_flow_group_to_table(dev, tunnel,
13211 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
13213 !!dev_flow->external,
13214 tunnel, jump_group, 0,
13217 return rte_flow_error_set
13219 RTE_FLOW_ERROR_TYPE_ACTION,
13221 "cannot create jump action.");
13222 if (flow_dv_jump_tbl_resource_register
13223 (dev, tbl, dev_flow, error)) {
13224 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
13225 return rte_flow_error_set
13227 RTE_FLOW_ERROR_TYPE_ACTION,
13229 "cannot create jump action.");
13231 dev_flow->dv.actions[actions_n++] =
13232 dev_flow->dv.jump->action;
13233 action_flags |= MLX5_FLOW_ACTION_JUMP;
13234 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
13235 sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
13238 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
13239 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
13240 if (flow_dv_convert_action_modify_mac
13241 (mhdr_res, actions, error))
13243 action_flags |= actions->type ==
13244 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
13245 MLX5_FLOW_ACTION_SET_MAC_SRC :
13246 MLX5_FLOW_ACTION_SET_MAC_DST;
13248 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
13249 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
13250 if (flow_dv_convert_action_modify_ipv4
13251 (mhdr_res, actions, error))
13253 action_flags |= actions->type ==
13254 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
13255 MLX5_FLOW_ACTION_SET_IPV4_SRC :
13256 MLX5_FLOW_ACTION_SET_IPV4_DST;
13258 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
13259 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
13260 if (flow_dv_convert_action_modify_ipv6
13261 (mhdr_res, actions, error))
13263 action_flags |= actions->type ==
13264 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
13265 MLX5_FLOW_ACTION_SET_IPV6_SRC :
13266 MLX5_FLOW_ACTION_SET_IPV6_DST;
13268 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
13269 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
13270 if (flow_dv_convert_action_modify_tp
13271 (mhdr_res, actions, items,
13272 &flow_attr, dev_flow, !!(action_flags &
13273 MLX5_FLOW_ACTION_DECAP), error))
13275 action_flags |= actions->type ==
13276 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
13277 MLX5_FLOW_ACTION_SET_TP_SRC :
13278 MLX5_FLOW_ACTION_SET_TP_DST;
13280 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
13281 if (flow_dv_convert_action_modify_dec_ttl
13282 (mhdr_res, items, &flow_attr, dev_flow,
13284 MLX5_FLOW_ACTION_DECAP), error))
13286 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
13288 case RTE_FLOW_ACTION_TYPE_SET_TTL:
13289 if (flow_dv_convert_action_modify_ttl
13290 (mhdr_res, actions, items, &flow_attr,
13291 dev_flow, !!(action_flags &
13292 MLX5_FLOW_ACTION_DECAP), error))
13294 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
13296 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
13297 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
13298 if (flow_dv_convert_action_modify_tcp_seq
13299 (mhdr_res, actions, error))
13301 action_flags |= actions->type ==
13302 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
13303 MLX5_FLOW_ACTION_INC_TCP_SEQ :
13304 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
13307 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
13308 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
13309 if (flow_dv_convert_action_modify_tcp_ack
13310 (mhdr_res, actions, error))
13312 action_flags |= actions->type ==
13313 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
13314 MLX5_FLOW_ACTION_INC_TCP_ACK :
13315 MLX5_FLOW_ACTION_DEC_TCP_ACK;
13317 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
13318 if (flow_dv_convert_action_set_reg
13319 (mhdr_res, actions, error))
13321 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13323 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
13324 if (flow_dv_convert_action_copy_mreg
13325 (dev, mhdr_res, actions, error))
13327 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13329 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
13330 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
13331 dev_flow->handle->fate_action =
13332 MLX5_FLOW_FATE_DEFAULT_MISS;
13334 case RTE_FLOW_ACTION_TYPE_METER:
13336 return rte_flow_error_set(error, rte_errno,
13337 RTE_FLOW_ERROR_TYPE_ACTION,
13338 NULL, "Failed to get meter in flow.");
13339 /* Set the meter action. */
13340 dev_flow->dv.actions[actions_n++] =
13341 wks->fm->meter_action;
13342 action_flags |= MLX5_FLOW_ACTION_METER;
13344 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
13345 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
13348 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
13350 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
13351 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
13354 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
13356 case RTE_FLOW_ACTION_TYPE_SAMPLE:
13357 sample_act_pos = actions_n;
13358 sample = (const struct rte_flow_action_sample *)
13361 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
13362 /* put encap action into group if work with port id */
13363 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
13364 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
13365 sample_act->action_flags |=
13366 MLX5_FLOW_ACTION_ENCAP;
13368 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
13369 if (flow_dv_convert_action_modify_field
13370 (dev, mhdr_res, actions, attr, error))
13372 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
13374 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
13375 owner_idx = (uint32_t)(uintptr_t)action->conf;
13376 ct = flow_aso_ct_get_by_idx(dev, owner_idx);
13378 return rte_flow_error_set(error, EINVAL,
13379 RTE_FLOW_ERROR_TYPE_ACTION,
13381 "Failed to get CT object.");
13382 if (mlx5_aso_ct_available(priv->sh, ct))
13383 return rte_flow_error_set(error, rte_errno,
13384 RTE_FLOW_ERROR_TYPE_ACTION,
13386 "CT is unavailable.");
13387 if (ct->is_original)
13388 dev_flow->dv.actions[actions_n] =
13389 ct->dr_action_orig;
13391 dev_flow->dv.actions[actions_n] =
13392 ct->dr_action_rply;
13393 if (flow->ct == 0) {
13394 flow->indirect_type =
13395 MLX5_INDIRECT_ACTION_TYPE_CT;
13396 flow->ct = owner_idx;
13397 __atomic_fetch_add(&ct->refcnt, 1,
13401 action_flags |= MLX5_FLOW_ACTION_CT;
13403 case RTE_FLOW_ACTION_TYPE_END:
13404 actions_end = true;
13405 if (mhdr_res->actions_num) {
13406 /* create modify action if needed. */
13407 if (flow_dv_modify_hdr_resource_register
13408 (dev, mhdr_res, dev_flow, error))
13410 dev_flow->dv.actions[modify_action_position] =
13411 handle->dvh.modify_hdr->action;
13414 * Handle AGE and COUNT action by single HW counter
13415 * when they are not shared.
13417 if (action_flags & MLX5_FLOW_ACTION_AGE) {
13418 if ((non_shared_age && count) ||
13419 !(priv->sh->flow_hit_aso_en &&
13420 (attr->group || attr->transfer))) {
13421 /* Creates age by counters. */
13422 cnt_act = flow_dv_prepare_counter
13429 dev_flow->dv.actions[age_act_pos] =
13433 if (!flow->age && non_shared_age) {
13434 flow->age = flow_dv_aso_age_alloc
13438 flow_dv_aso_age_params_init
13440 non_shared_age->context ?
13441 non_shared_age->context :
13442 (void *)(uintptr_t)
13443 (dev_flow->flow_idx),
13444 non_shared_age->timeout);
13446 age_act = flow_aso_age_get_by_idx(dev,
13448 dev_flow->dv.actions[age_act_pos] =
13449 age_act->dr_action;
13451 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
13453 * Create one count action, to be used
13454 * by all sub-flows.
13456 cnt_act = flow_dv_prepare_counter(dev, dev_flow,
13461 dev_flow->dv.actions[actions_n++] =
13467 if (mhdr_res->actions_num &&
13468 modify_action_position == UINT32_MAX)
13469 modify_action_position = actions_n++;
13471 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
13472 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
13473 int item_type = items->type;
13475 if (!mlx5_flow_os_item_supported(item_type))
13476 return rte_flow_error_set(error, ENOTSUP,
13477 RTE_FLOW_ERROR_TYPE_ITEM,
13478 NULL, "item not supported");
13479 switch (item_type) {
13480 case RTE_FLOW_ITEM_TYPE_PORT_ID:
13481 flow_dv_translate_item_port_id
13482 (dev, match_mask, match_value, items, attr);
13483 last_item = MLX5_FLOW_ITEM_PORT_ID;
13485 case RTE_FLOW_ITEM_TYPE_ETH:
13486 flow_dv_translate_item_eth(match_mask, match_value,
13488 dev_flow->dv.group);
13489 matcher.priority = action_flags &
13490 MLX5_FLOW_ACTION_DEFAULT_MISS &&
13491 !dev_flow->external ?
13492 MLX5_PRIORITY_MAP_L3 :
13493 MLX5_PRIORITY_MAP_L2;
13494 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
13495 MLX5_FLOW_LAYER_OUTER_L2;
13497 case RTE_FLOW_ITEM_TYPE_VLAN:
13498 flow_dv_translate_item_vlan(dev_flow,
13499 match_mask, match_value,
13501 dev_flow->dv.group);
13502 matcher.priority = MLX5_PRIORITY_MAP_L2;
13503 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
13504 MLX5_FLOW_LAYER_INNER_VLAN) :
13505 (MLX5_FLOW_LAYER_OUTER_L2 |
13506 MLX5_FLOW_LAYER_OUTER_VLAN);
13508 case RTE_FLOW_ITEM_TYPE_IPV4:
13509 mlx5_flow_tunnel_ip_check(items, next_protocol,
13510 &item_flags, &tunnel);
13511 flow_dv_translate_item_ipv4(match_mask, match_value,
13513 dev_flow->dv.group);
13514 matcher.priority = MLX5_PRIORITY_MAP_L3;
13515 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
13516 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
13517 if (items->mask != NULL &&
13518 ((const struct rte_flow_item_ipv4 *)
13519 items->mask)->hdr.next_proto_id) {
13521 ((const struct rte_flow_item_ipv4 *)
13522 (items->spec))->hdr.next_proto_id;
13524 ((const struct rte_flow_item_ipv4 *)
13525 (items->mask))->hdr.next_proto_id;
13527 /* Reset for inner layer. */
13528 next_protocol = 0xff;
13531 case RTE_FLOW_ITEM_TYPE_IPV6:
13532 mlx5_flow_tunnel_ip_check(items, next_protocol,
13533 &item_flags, &tunnel);
13534 flow_dv_translate_item_ipv6(match_mask, match_value,
13536 dev_flow->dv.group);
13537 matcher.priority = MLX5_PRIORITY_MAP_L3;
13538 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
13539 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
13540 if (items->mask != NULL &&
13541 ((const struct rte_flow_item_ipv6 *)
13542 items->mask)->hdr.proto) {
13544 ((const struct rte_flow_item_ipv6 *)
13545 items->spec)->hdr.proto;
13547 ((const struct rte_flow_item_ipv6 *)
13548 items->mask)->hdr.proto;
13550 /* Reset for inner layer. */
13551 next_protocol = 0xff;
13554 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
13555 flow_dv_translate_item_ipv6_frag_ext(match_mask,
13558 last_item = tunnel ?
13559 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
13560 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
13561 if (items->mask != NULL &&
13562 ((const struct rte_flow_item_ipv6_frag_ext *)
13563 items->mask)->hdr.next_header) {
13565 ((const struct rte_flow_item_ipv6_frag_ext *)
13566 items->spec)->hdr.next_header;
13568 ((const struct rte_flow_item_ipv6_frag_ext *)
13569 items->mask)->hdr.next_header;
13571 /* Reset for inner layer. */
13572 next_protocol = 0xff;
13575 case RTE_FLOW_ITEM_TYPE_TCP:
13576 flow_dv_translate_item_tcp(match_mask, match_value,
13578 matcher.priority = MLX5_PRIORITY_MAP_L4;
13579 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
13580 MLX5_FLOW_LAYER_OUTER_L4_TCP;
13582 case RTE_FLOW_ITEM_TYPE_UDP:
13583 flow_dv_translate_item_udp(match_mask, match_value,
13585 matcher.priority = MLX5_PRIORITY_MAP_L4;
13586 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
13587 MLX5_FLOW_LAYER_OUTER_L4_UDP;
13589 case RTE_FLOW_ITEM_TYPE_GRE:
13590 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13591 last_item = MLX5_FLOW_LAYER_GRE;
13592 tunnel_item = items;
13595 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
13596 flow_dv_translate_item_gre_key(match_mask,
13597 match_value, items);
13598 last_item = MLX5_FLOW_LAYER_GRE_KEY;
13600 case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
13601 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13602 last_item = MLX5_FLOW_LAYER_GRE;
13603 tunnel_item = items;
13605 case RTE_FLOW_ITEM_TYPE_NVGRE:
13606 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13607 last_item = MLX5_FLOW_LAYER_GRE;
13608 tunnel_item = items;
13610 case RTE_FLOW_ITEM_TYPE_VXLAN:
13611 flow_dv_translate_item_vxlan(dev, attr,
13612 match_mask, match_value,
13614 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13615 last_item = MLX5_FLOW_LAYER_VXLAN;
13617 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
13618 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13619 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
13620 tunnel_item = items;
13622 case RTE_FLOW_ITEM_TYPE_GENEVE:
13623 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13624 last_item = MLX5_FLOW_LAYER_GENEVE;
13625 tunnel_item = items;
13627 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
13628 ret = flow_dv_translate_item_geneve_opt(dev, match_mask,
13632 return rte_flow_error_set(error, -ret,
13633 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13634 "cannot create GENEVE TLV option");
13635 flow->geneve_tlv_option = 1;
13636 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
13638 case RTE_FLOW_ITEM_TYPE_MPLS:
13639 flow_dv_translate_item_mpls(match_mask, match_value,
13640 items, last_item, tunnel);
13641 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13642 last_item = MLX5_FLOW_LAYER_MPLS;
13644 case RTE_FLOW_ITEM_TYPE_MARK:
13645 flow_dv_translate_item_mark(dev, match_mask,
13646 match_value, items);
13647 last_item = MLX5_FLOW_ITEM_MARK;
13649 case RTE_FLOW_ITEM_TYPE_META:
13650 flow_dv_translate_item_meta(dev, match_mask,
13651 match_value, attr, items);
13652 last_item = MLX5_FLOW_ITEM_METADATA;
13654 case RTE_FLOW_ITEM_TYPE_ICMP:
13655 flow_dv_translate_item_icmp(match_mask, match_value,
13657 last_item = MLX5_FLOW_LAYER_ICMP;
13659 case RTE_FLOW_ITEM_TYPE_ICMP6:
13660 flow_dv_translate_item_icmp6(match_mask, match_value,
13662 last_item = MLX5_FLOW_LAYER_ICMP6;
13664 case RTE_FLOW_ITEM_TYPE_TAG:
13665 flow_dv_translate_item_tag(dev, match_mask,
13666 match_value, items);
13667 last_item = MLX5_FLOW_ITEM_TAG;
13669 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
13670 flow_dv_translate_mlx5_item_tag(dev, match_mask,
13671 match_value, items);
13672 last_item = MLX5_FLOW_ITEM_TAG;
13674 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
13675 flow_dv_translate_item_tx_queue(dev, match_mask,
13678 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
13680 case RTE_FLOW_ITEM_TYPE_GTP:
13681 flow_dv_translate_item_gtp(match_mask, match_value,
13683 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13684 last_item = MLX5_FLOW_LAYER_GTP;
13686 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
13687 ret = flow_dv_translate_item_gtp_psc(match_mask,
13691 return rte_flow_error_set(error, -ret,
13692 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13693 "cannot create GTP PSC item");
13694 last_item = MLX5_FLOW_LAYER_GTP_PSC;
13696 case RTE_FLOW_ITEM_TYPE_ECPRI:
13697 if (!mlx5_flex_parser_ecpri_exist(dev)) {
13698 /* Create it only the first time to be used. */
13699 ret = mlx5_flex_parser_ecpri_alloc(dev);
13701 return rte_flow_error_set
13703 RTE_FLOW_ERROR_TYPE_ITEM,
13705 "cannot create eCPRI parser");
13707 flow_dv_translate_item_ecpri(dev, match_mask,
13708 match_value, items,
13710 /* No other protocol should follow eCPRI layer. */
13711 last_item = MLX5_FLOW_LAYER_ECPRI;
13713 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
13714 flow_dv_translate_item_integrity(items, integrity_items,
13717 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
13718 flow_dv_translate_item_aso_ct(dev, match_mask,
13719 match_value, items);
13721 case RTE_FLOW_ITEM_TYPE_FLEX:
13722 flow_dv_translate_item_flex(dev, match_mask,
13723 match_value, items,
13724 dev_flow, tunnel != 0);
13725 last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
13726 MLX5_FLOW_ITEM_OUTER_FLEX;
13731 item_flags |= last_item;
13734 * When E-Switch mode is enabled, we have two cases where we need to
13735 * set the source port manually.
13736 * The first one, is in case of Nic steering rule, and the second is
13737 * E-Switch rule where no port_id item was found. In both cases
13738 * the source port is set according the current port in use.
13740 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) && priv->sh->esw_mode) {
13741 if (flow_dv_translate_item_port_id(dev, match_mask,
13742 match_value, NULL, attr))
13745 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
13746 flow_dv_translate_item_integrity_post(match_mask, match_value,
13750 if (item_flags & MLX5_FLOW_LAYER_VXLAN_GPE)
13751 flow_dv_translate_item_vxlan_gpe(match_mask, match_value,
13752 tunnel_item, item_flags);
13753 else if (item_flags & MLX5_FLOW_LAYER_GENEVE)
13754 flow_dv_translate_item_geneve(match_mask, match_value,
13755 tunnel_item, item_flags);
13756 else if (item_flags & MLX5_FLOW_LAYER_GRE) {
13757 if (tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE)
13758 flow_dv_translate_item_gre(match_mask, match_value,
13759 tunnel_item, item_flags);
13760 else if (tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE)
13761 flow_dv_translate_item_nvgre(match_mask, match_value,
13762 tunnel_item, item_flags);
13763 else if (tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION)
13764 flow_dv_translate_item_gre_option(match_mask, match_value,
13765 tunnel_item, gre_item, item_flags);
13767 MLX5_ASSERT(false);
13769 #ifdef RTE_LIBRTE_MLX5_DEBUG
13770 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
13771 dev_flow->dv.value.buf));
13774 * Layers may be already initialized from prefix flow if this dev_flow
13775 * is the suffix flow.
13777 handle->layers |= item_flags;
13778 if (action_flags & MLX5_FLOW_ACTION_RSS)
13779 flow_dv_hashfields_set(dev_flow->handle->layers,
13781 &dev_flow->hash_fields);
13782 /* If has RSS action in the sample action, the Sample/Mirror resource
13783 * should be registered after the hash filed be update.
13785 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
13786 ret = flow_dv_translate_action_sample(dev,
13795 ret = flow_dv_create_action_sample(dev,
13804 return rte_flow_error_set
13806 RTE_FLOW_ERROR_TYPE_ACTION,
13808 "cannot create sample action");
13809 if (num_of_dest > 1) {
13810 dev_flow->dv.actions[sample_act_pos] =
13811 dev_flow->dv.dest_array_res->action;
13813 dev_flow->dv.actions[sample_act_pos] =
13814 dev_flow->dv.sample_res->verbs_action;
13818 * For multiple destination (sample action with ratio=1), the encap
13819 * action and port id action will be combined into group action.
13820 * So need remove the original these actions in the flow and only
13821 * use the sample action instead of.
13823 if (num_of_dest > 1 &&
13824 (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
13826 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
13828 for (i = 0; i < actions_n; i++) {
13829 if ((sample_act->dr_encap_action &&
13830 sample_act->dr_encap_action ==
13831 dev_flow->dv.actions[i]) ||
13832 (sample_act->dr_port_id_action &&
13833 sample_act->dr_port_id_action ==
13834 dev_flow->dv.actions[i]) ||
13835 (sample_act->dr_jump_action &&
13836 sample_act->dr_jump_action ==
13837 dev_flow->dv.actions[i]))
13839 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
13841 memcpy((void *)dev_flow->dv.actions,
13842 (void *)temp_actions,
13843 tmp_actions_n * sizeof(void *));
13844 actions_n = tmp_actions_n;
13846 dev_flow->dv.actions_n = actions_n;
13847 dev_flow->act_flags = action_flags;
13848 if (wks->skip_matcher_reg)
13850 /* Register matcher. */
13851 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
13852 matcher.mask.size);
13853 matcher.priority = mlx5_get_matcher_priority(dev, attr,
13855 dev_flow->external);
13857 * When creating meter drop flow in drop table, using original
13858 * 5-tuple match, the matcher priority should be lower than
13861 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
13862 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
13863 matcher.priority <= MLX5_REG_BITS)
13864 matcher.priority += MLX5_REG_BITS;
13865 /* reserved field no needs to be set to 0 here. */
13866 tbl_key.is_fdb = attr->transfer;
13867 tbl_key.is_egress = attr->egress;
13868 tbl_key.level = dev_flow->dv.group;
13869 tbl_key.id = dev_flow->dv.table_id;
13870 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
13871 tunnel, attr->group, error))
13877 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13880 * @param[in, out] action
13881 * Shred RSS action holding hash RX queue objects.
13882 * @param[in] hash_fields
13883 * Defines combination of packet fields to participate in RX hash.
13884 * @param[in] tunnel
13886 * @param[in] hrxq_idx
13887 * Hash RX queue index to set.
13890 * 0 on success, otherwise negative errno value.
13893 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
13894 const uint64_t hash_fields,
13897 uint32_t *hrxqs = action->hrxq;
13899 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13900 case MLX5_RSS_HASH_IPV4:
13901 /* fall-through. */
13902 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13903 /* fall-through. */
13904 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13905 hrxqs[0] = hrxq_idx;
13907 case MLX5_RSS_HASH_IPV4_TCP:
13908 /* fall-through. */
13909 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13910 /* fall-through. */
13911 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13912 hrxqs[1] = hrxq_idx;
13914 case MLX5_RSS_HASH_IPV4_UDP:
13915 /* fall-through. */
13916 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13917 /* fall-through. */
13918 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13919 hrxqs[2] = hrxq_idx;
13921 case MLX5_RSS_HASH_IPV6:
13922 /* fall-through. */
13923 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13924 /* fall-through. */
13925 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13926 hrxqs[3] = hrxq_idx;
13928 case MLX5_RSS_HASH_IPV6_TCP:
13929 /* fall-through. */
13930 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13931 /* fall-through. */
13932 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13933 hrxqs[4] = hrxq_idx;
13935 case MLX5_RSS_HASH_IPV6_UDP:
13936 /* fall-through. */
13937 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13938 /* fall-through. */
13939 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13940 hrxqs[5] = hrxq_idx;
13942 case MLX5_RSS_HASH_NONE:
13943 hrxqs[6] = hrxq_idx;
13951 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13955 * Pointer to the Ethernet device structure.
13957 * Shared RSS action ID holding hash RX queue objects.
13958 * @param[in] hash_fields
13959 * Defines combination of packet fields to participate in RX hash.
13960 * @param[in] tunnel
13964 * Valid hash RX queue index, otherwise 0.
13967 flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
13968 const uint64_t hash_fields)
13970 struct mlx5_priv *priv = dev->data->dev_private;
13971 struct mlx5_shared_action_rss *shared_rss =
13972 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
13973 const uint32_t *hrxqs = shared_rss->hrxq;
13975 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13976 case MLX5_RSS_HASH_IPV4:
13977 /* fall-through. */
13978 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13979 /* fall-through. */
13980 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13982 case MLX5_RSS_HASH_IPV4_TCP:
13983 /* fall-through. */
13984 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13985 /* fall-through. */
13986 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13988 case MLX5_RSS_HASH_IPV4_UDP:
13989 /* fall-through. */
13990 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13991 /* fall-through. */
13992 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13994 case MLX5_RSS_HASH_IPV6:
13995 /* fall-through. */
13996 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13997 /* fall-through. */
13998 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
14000 case MLX5_RSS_HASH_IPV6_TCP:
14001 /* fall-through. */
14002 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
14003 /* fall-through. */
14004 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
14006 case MLX5_RSS_HASH_IPV6_UDP:
14007 /* fall-through. */
14008 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
14009 /* fall-through. */
14010 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
14012 case MLX5_RSS_HASH_NONE:
14021 * Apply the flow to the NIC, lock free,
14022 * (mutex should be acquired by caller).
14025 * Pointer to the Ethernet device structure.
14026 * @param[in, out] flow
14027 * Pointer to flow structure.
14028 * @param[out] error
14029 * Pointer to error structure.
14032 * 0 on success, a negative errno value otherwise and rte_errno is set.
14035 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
14036 struct rte_flow_error *error)
14038 struct mlx5_flow_dv_workspace *dv;
14039 struct mlx5_flow_handle *dh;
14040 struct mlx5_flow_handle_dv *dv_h;
14041 struct mlx5_flow *dev_flow;
14042 struct mlx5_priv *priv = dev->data->dev_private;
14043 uint32_t handle_idx;
14047 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
14048 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
14052 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
14053 dev_flow = &wks->flows[idx];
14054 dv = &dev_flow->dv;
14055 dh = dev_flow->handle;
14058 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
14059 if (dv->transfer) {
14060 MLX5_ASSERT(priv->sh->dr_drop_action);
14061 dv->actions[n++] = priv->sh->dr_drop_action;
14063 #ifdef HAVE_MLX5DV_DR
14064 /* DR supports drop action placeholder. */
14065 MLX5_ASSERT(priv->sh->dr_drop_action);
14066 dv->actions[n++] = dv->group ?
14067 priv->sh->dr_drop_action :
14068 priv->root_drop_action;
14070 /* For DV we use the explicit drop queue. */
14071 MLX5_ASSERT(priv->drop_queue.hrxq);
14073 priv->drop_queue.hrxq->action;
14076 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
14077 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
14078 struct mlx5_hrxq *hrxq;
14081 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
14086 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14087 "cannot get hash queue");
14090 dh->rix_hrxq = hrxq_idx;
14091 dv->actions[n++] = hrxq->action;
14092 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
14093 struct mlx5_hrxq *hrxq = NULL;
14096 hrxq_idx = flow_dv_action_rss_hrxq_lookup(dev,
14097 rss_desc->shared_rss,
14098 dev_flow->hash_fields);
14100 hrxq = mlx5_ipool_get
14101 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
14106 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14107 "cannot get hash queue");
14110 dh->rix_srss = rss_desc->shared_rss;
14111 dv->actions[n++] = hrxq->action;
14112 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
14113 if (!priv->sh->default_miss_action) {
14116 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14117 "default miss action not be created.");
14120 dv->actions[n++] = priv->sh->default_miss_action;
14122 misc_mask = flow_dv_matcher_enable(dv->value.buf);
14123 __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
14124 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
14125 (void *)&dv->value, n,
14126 dv->actions, &dh->drv_flow);
14130 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14132 (!priv->sh->config.allow_duplicate_pattern &&
14134 "duplicating pattern is not allowed" :
14135 "hardware refuses to create flow");
14138 if (priv->vmwa_context &&
14139 dh->vf_vlan.tag && !dh->vf_vlan.created) {
14141 * The rule contains the VLAN pattern.
14142 * For VF we are going to create VLAN
14143 * interface to make hypervisor set correct
14144 * e-Switch vport context.
14146 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
14151 err = rte_errno; /* Save rte_errno before cleanup. */
14152 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
14153 handle_idx, dh, next) {
14154 /* hrxq is union, don't clear it if the flag is not set. */
14155 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
14156 mlx5_hrxq_release(dev, dh->rix_hrxq);
14158 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
14161 if (dh->vf_vlan.tag && dh->vf_vlan.created)
14162 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
14164 rte_errno = err; /* Restore rte_errno. */
14169 flow_dv_matcher_remove_cb(void *tool_ctx __rte_unused,
14170 struct mlx5_list_entry *entry)
14172 struct mlx5_flow_dv_matcher *resource = container_of(entry,
14176 claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
14177 mlx5_free(resource);
14181 * Release the flow matcher.
14184 * Pointer to Ethernet device.
14186 * Index to port ID action resource.
14189 * 1 while a reference on it exists, 0 when freed.
14192 flow_dv_matcher_release(struct rte_eth_dev *dev,
14193 struct mlx5_flow_handle *handle)
14195 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
14196 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
14197 typeof(*tbl), tbl);
14200 MLX5_ASSERT(matcher->matcher_object);
14201 ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
14202 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
14207 flow_dv_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14209 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14210 struct mlx5_flow_dv_encap_decap_resource *res =
14211 container_of(entry, typeof(*res), entry);
14213 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
14214 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
14218 * Release an encap/decap resource.
14221 * Pointer to Ethernet device.
14222 * @param encap_decap_idx
14223 * Index of encap decap resource.
14226 * 1 while a reference on it exists, 0 when freed.
14229 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
14230 uint32_t encap_decap_idx)
14232 struct mlx5_priv *priv = dev->data->dev_private;
14233 struct mlx5_flow_dv_encap_decap_resource *resource;
14235 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
14239 MLX5_ASSERT(resource->action);
14240 return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
14244 * Release an jump to table action resource.
14247 * Pointer to Ethernet device.
14249 * Index to the jump action resource.
14252 * 1 while a reference on it exists, 0 when freed.
14255 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
14258 struct mlx5_priv *priv = dev->data->dev_private;
14259 struct mlx5_flow_tbl_data_entry *tbl_data;
14261 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
14265 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
14269 flow_dv_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14271 struct mlx5_flow_dv_modify_hdr_resource *res =
14272 container_of(entry, typeof(*res), entry);
14273 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14275 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
14276 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
14280 * Release a modify-header resource.
14283 * Pointer to Ethernet device.
14285 * Pointer to mlx5_flow_handle.
14288 * 1 while a reference on it exists, 0 when freed.
14291 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
14292 struct mlx5_flow_handle *handle)
14294 struct mlx5_priv *priv = dev->data->dev_private;
14295 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
14297 MLX5_ASSERT(entry->action);
14298 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
14302 flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14304 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14305 struct mlx5_flow_dv_port_id_action_resource *resource =
14306 container_of(entry, typeof(*resource), entry);
14308 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14309 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
14313 * Release port ID action resource.
14316 * Pointer to Ethernet device.
14318 * Pointer to mlx5_flow_handle.
14321 * 1 while a reference on it exists, 0 when freed.
14324 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
14327 struct mlx5_priv *priv = dev->data->dev_private;
14328 struct mlx5_flow_dv_port_id_action_resource *resource;
14330 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
14333 MLX5_ASSERT(resource->action);
14334 return mlx5_list_unregister(priv->sh->port_id_action_list,
14339 * Release shared RSS action resource.
14342 * Pointer to Ethernet device.
14344 * Shared RSS action index.
14347 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
14349 struct mlx5_priv *priv = dev->data->dev_private;
14350 struct mlx5_shared_action_rss *shared_rss;
14352 shared_rss = mlx5_ipool_get
14353 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
14354 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14358 flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14360 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14361 struct mlx5_flow_dv_push_vlan_action_resource *resource =
14362 container_of(entry, typeof(*resource), entry);
14364 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14365 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
14369 * Release push vlan action resource.
14372 * Pointer to Ethernet device.
14374 * Pointer to mlx5_flow_handle.
14377 * 1 while a reference on it exists, 0 when freed.
14380 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
14381 struct mlx5_flow_handle *handle)
14383 struct mlx5_priv *priv = dev->data->dev_private;
14384 struct mlx5_flow_dv_push_vlan_action_resource *resource;
14385 uint32_t idx = handle->dvh.rix_push_vlan;
14387 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
14390 MLX5_ASSERT(resource->action);
14391 return mlx5_list_unregister(priv->sh->push_vlan_action_list,
14396 * Release the fate resource.
14399 * Pointer to Ethernet device.
14401 * Pointer to mlx5_flow_handle.
14404 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
14405 struct mlx5_flow_handle *handle)
14407 if (!handle->rix_fate)
14409 switch (handle->fate_action) {
14410 case MLX5_FLOW_FATE_QUEUE:
14411 if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
14412 mlx5_hrxq_release(dev, handle->rix_hrxq);
14414 case MLX5_FLOW_FATE_JUMP:
14415 flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
14417 case MLX5_FLOW_FATE_PORT_ID:
14418 flow_dv_port_id_action_resource_release(dev,
14419 handle->rix_port_id_action);
14422 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
14425 handle->rix_fate = 0;
14429 flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
14430 struct mlx5_list_entry *entry)
14432 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
14435 struct rte_eth_dev *dev = resource->dev;
14436 struct mlx5_priv *priv = dev->data->dev_private;
14438 if (resource->verbs_action)
14439 claim_zero(mlx5_flow_os_destroy_flow_action
14440 (resource->verbs_action));
14441 if (resource->normal_path_tbl)
14442 flow_dv_tbl_resource_release(MLX5_SH(dev),
14443 resource->normal_path_tbl);
14444 flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
14445 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
14446 DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
14450 * Release an sample resource.
14453 * Pointer to Ethernet device.
14455 * Pointer to mlx5_flow_handle.
14458 * 1 while a reference on it exists, 0 when freed.
14461 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
14462 struct mlx5_flow_handle *handle)
14464 struct mlx5_priv *priv = dev->data->dev_private;
14465 struct mlx5_flow_dv_sample_resource *resource;
14467 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
14468 handle->dvh.rix_sample);
14471 MLX5_ASSERT(resource->verbs_action);
14472 return mlx5_list_unregister(priv->sh->sample_action_list,
14477 flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
14478 struct mlx5_list_entry *entry)
14480 struct mlx5_flow_dv_dest_array_resource *resource =
14481 container_of(entry, typeof(*resource), entry);
14482 struct rte_eth_dev *dev = resource->dev;
14483 struct mlx5_priv *priv = dev->data->dev_private;
14486 MLX5_ASSERT(resource->action);
14487 if (resource->action)
14488 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14489 for (; i < resource->num_of_dest; i++)
14490 flow_dv_sample_sub_actions_release(dev,
14491 &resource->sample_idx[i]);
14492 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
14493 DRV_LOG(DEBUG, "destination array resource %p: removed",
14498 * Release an destination array resource.
14501 * Pointer to Ethernet device.
14503 * Pointer to mlx5_flow_handle.
14506 * 1 while a reference on it exists, 0 when freed.
14509 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
14510 struct mlx5_flow_handle *handle)
14512 struct mlx5_priv *priv = dev->data->dev_private;
14513 struct mlx5_flow_dv_dest_array_resource *resource;
14515 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
14516 handle->dvh.rix_dest_array);
14519 MLX5_ASSERT(resource->action);
14520 return mlx5_list_unregister(priv->sh->dest_array_list,
14525 flow_dv_geneve_tlv_option_resource_release(struct rte_eth_dev *dev)
14527 struct mlx5_priv *priv = dev->data->dev_private;
14528 struct mlx5_dev_ctx_shared *sh = priv->sh;
14529 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
14530 sh->geneve_tlv_option_resource;
14531 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
14532 if (geneve_opt_resource) {
14533 if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
14534 __ATOMIC_RELAXED))) {
14535 claim_zero(mlx5_devx_cmd_destroy
14536 (geneve_opt_resource->obj));
14537 mlx5_free(sh->geneve_tlv_option_resource);
14538 sh->geneve_tlv_option_resource = NULL;
14541 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
14545 * Remove the flow from the NIC but keeps it in memory.
14546 * Lock free, (mutex should be acquired by caller).
14549 * Pointer to Ethernet device.
14550 * @param[in, out] flow
14551 * Pointer to flow structure.
14554 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
14556 struct mlx5_flow_handle *dh;
14557 uint32_t handle_idx;
14558 struct mlx5_priv *priv = dev->data->dev_private;
14562 handle_idx = flow->dev_handles;
14563 while (handle_idx) {
14564 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14568 if (dh->drv_flow) {
14569 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
14570 dh->drv_flow = NULL;
14572 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
14573 flow_dv_fate_resource_release(dev, dh);
14574 if (dh->vf_vlan.tag && dh->vf_vlan.created)
14575 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
14576 handle_idx = dh->next.next;
14581 * Remove the flow from the NIC and the memory.
14582 * Lock free, (mutex should be acquired by caller).
14585 * Pointer to the Ethernet device structure.
14586 * @param[in, out] flow
14587 * Pointer to flow structure.
14590 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
14592 struct mlx5_flow_handle *dev_handle;
14593 struct mlx5_priv *priv = dev->data->dev_private;
14594 struct mlx5_flow_meter_info *fm = NULL;
14599 flow_dv_remove(dev, flow);
14600 if (flow->counter) {
14601 flow_dv_counter_free(dev, flow->counter);
14605 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
14607 mlx5_flow_meter_detach(priv, fm);
14610 /* Keep the current age handling by default. */
14611 if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
14612 flow_dv_aso_ct_release(dev, flow->ct, NULL);
14613 else if (flow->age)
14614 flow_dv_aso_age_release(dev, flow->age);
14615 if (flow->geneve_tlv_option) {
14616 flow_dv_geneve_tlv_option_resource_release(dev);
14617 flow->geneve_tlv_option = 0;
14619 while (flow->dev_handles) {
14620 uint32_t tmp_idx = flow->dev_handles;
14622 dev_handle = mlx5_ipool_get(priv->sh->ipool
14623 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
14626 flow->dev_handles = dev_handle->next.next;
14627 while (dev_handle->flex_item) {
14628 int index = rte_bsf32(dev_handle->flex_item);
14630 mlx5_flex_release_index(dev, index);
14631 dev_handle->flex_item &= ~RTE_BIT32(index);
14633 if (dev_handle->dvh.matcher)
14634 flow_dv_matcher_release(dev, dev_handle);
14635 if (dev_handle->dvh.rix_sample)
14636 flow_dv_sample_resource_release(dev, dev_handle);
14637 if (dev_handle->dvh.rix_dest_array)
14638 flow_dv_dest_array_resource_release(dev, dev_handle);
14639 if (dev_handle->dvh.rix_encap_decap)
14640 flow_dv_encap_decap_resource_release(dev,
14641 dev_handle->dvh.rix_encap_decap);
14642 if (dev_handle->dvh.modify_hdr)
14643 flow_dv_modify_hdr_resource_release(dev, dev_handle);
14644 if (dev_handle->dvh.rix_push_vlan)
14645 flow_dv_push_vlan_action_resource_release(dev,
14647 if (dev_handle->dvh.rix_tag)
14648 flow_dv_tag_release(dev,
14649 dev_handle->dvh.rix_tag);
14650 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
14651 flow_dv_fate_resource_release(dev, dev_handle);
14653 srss = dev_handle->rix_srss;
14654 if (fm && dev_handle->is_meter_flow_id &&
14655 dev_handle->split_flow_id)
14656 mlx5_ipool_free(fm->flow_ipool,
14657 dev_handle->split_flow_id);
14658 else if (dev_handle->split_flow_id &&
14659 !dev_handle->is_meter_flow_id)
14660 mlx5_ipool_free(priv->sh->ipool
14661 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
14662 dev_handle->split_flow_id);
14663 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14667 flow_dv_shared_rss_action_release(dev, srss);
14671 * Release array of hash RX queue objects.
14675 * Pointer to the Ethernet device structure.
14676 * @param[in, out] hrxqs
14677 * Array of hash RX queue objects.
14680 * Total number of references to hash RX queue objects in *hrxqs* array
14681 * after this operation.
14684 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
14685 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
14690 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
14691 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
14701 * Release all hash RX queue objects representing shared RSS action.
14704 * Pointer to the Ethernet device structure.
14705 * @param[in, out] action
14706 * Shared RSS action to remove hash RX queue objects from.
14709 * Total number of references to hash RX queue objects stored in *action*
14710 * after this operation.
14711 * Expected to be 0 if no external references held.
14714 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
14715 struct mlx5_shared_action_rss *shared_rss)
14717 return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
14721 * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
14724 * Only one hash value is available for one L3+L4 combination:
14726 * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
14727 * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
14728 * same slot in mlx5_rss_hash_fields.
14730 * @param[in] rss_types
14732 * @param[in, out] hash_field
14733 * hash_field variable needed to be adjusted.
14739 flow_dv_action_rss_l34_hash_adjust(uint64_t rss_types,
14740 uint64_t *hash_field)
14742 switch (*hash_field & ~IBV_RX_HASH_INNER) {
14743 case MLX5_RSS_HASH_IPV4:
14744 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
14745 *hash_field &= ~MLX5_RSS_HASH_IPV4;
14746 if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
14747 *hash_field |= IBV_RX_HASH_DST_IPV4;
14748 else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
14749 *hash_field |= IBV_RX_HASH_SRC_IPV4;
14751 *hash_field |= MLX5_RSS_HASH_IPV4;
14754 case MLX5_RSS_HASH_IPV6:
14755 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
14756 *hash_field &= ~MLX5_RSS_HASH_IPV6;
14757 if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
14758 *hash_field |= IBV_RX_HASH_DST_IPV6;
14759 else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
14760 *hash_field |= IBV_RX_HASH_SRC_IPV6;
14762 *hash_field |= MLX5_RSS_HASH_IPV6;
14765 case MLX5_RSS_HASH_IPV4_UDP:
14766 /* fall-through. */
14767 case MLX5_RSS_HASH_IPV6_UDP:
14768 if (rss_types & RTE_ETH_RSS_UDP) {
14769 *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
14770 if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
14771 *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
14772 else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
14773 *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
14775 *hash_field |= MLX5_UDP_IBV_RX_HASH;
14778 case MLX5_RSS_HASH_IPV4_TCP:
14779 /* fall-through. */
14780 case MLX5_RSS_HASH_IPV6_TCP:
14781 if (rss_types & RTE_ETH_RSS_TCP) {
14782 *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
14783 if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
14784 *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
14785 else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
14786 *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
14788 *hash_field |= MLX5_TCP_IBV_RX_HASH;
14797 * Setup shared RSS action.
14798 * Prepare set of hash RX queue objects sufficient to handle all valid
14799 * hash_fields combinations (see enum ibv_rx_hash_fields).
14802 * Pointer to the Ethernet device structure.
14803 * @param[in] action_idx
14804 * Shared RSS action ipool index.
14805 * @param[in, out] action
14806 * Partially initialized shared RSS action.
14807 * @param[out] error
14808 * Perform verbose error reporting if not NULL. Initialized in case of
14812 * 0 on success, otherwise negative errno value.
14815 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
14816 uint32_t action_idx,
14817 struct mlx5_shared_action_rss *shared_rss,
14818 struct rte_flow_error *error)
14820 struct mlx5_priv *priv = dev->data->dev_private;
14821 struct mlx5_flow_rss_desc rss_desc = { 0 };
14825 shared_rss->ind_tbl = mlx5_ind_table_obj_new
14826 (dev, shared_rss->origin.queue,
14827 shared_rss->origin.queue_num,
14829 !!dev->data->dev_started);
14830 if (!shared_rss->ind_tbl)
14831 return rte_flow_error_set(error, rte_errno,
14832 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14833 "cannot setup indirection table");
14834 memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
14835 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
14836 rss_desc.const_q = shared_rss->origin.queue;
14837 rss_desc.queue_num = shared_rss->origin.queue_num;
14838 /* Set non-zero value to indicate a shared RSS. */
14839 rss_desc.shared_rss = action_idx;
14840 rss_desc.ind_tbl = shared_rss->ind_tbl;
14841 if (priv->sh->config.dv_flow_en == 2)
14842 rss_desc.hws_flags = MLX5DR_ACTION_FLAG_HWS_RX;
14843 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
14844 struct mlx5_hrxq *hrxq;
14845 uint64_t hash_fields = mlx5_rss_hash_fields[i];
14848 flow_dv_action_rss_l34_hash_adjust(shared_rss->origin.types,
14850 if (shared_rss->origin.level > 1) {
14851 hash_fields |= IBV_RX_HASH_INNER;
14854 rss_desc.tunnel = tunnel;
14855 rss_desc.hash_fields = hash_fields;
14856 hrxq = mlx5_hrxq_get(dev, &rss_desc);
14860 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14861 "cannot get hash queue");
14862 goto error_hrxq_new;
14864 err = __flow_dv_action_rss_hrxq_set
14865 (shared_rss, hash_fields, hrxq->idx);
14871 __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14872 if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
14873 shared_rss->ind_tbl = NULL;
14879 * Create shared RSS action.
14882 * Pointer to the Ethernet device structure.
14884 * Shared action configuration.
14886 * RSS action specification used to create shared action.
14887 * @param[out] error
14888 * Perform verbose error reporting if not NULL. Initialized in case of
14892 * A valid shared action ID in case of success, 0 otherwise and
14893 * rte_errno is set.
14896 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
14897 const struct rte_flow_indir_action_conf *conf,
14898 const struct rte_flow_action_rss *rss,
14899 struct rte_flow_error *error)
14901 struct mlx5_priv *priv = dev->data->dev_private;
14902 struct mlx5_shared_action_rss *shared_rss = NULL;
14903 struct rte_flow_action_rss *origin;
14904 const uint8_t *rss_key;
14907 RTE_SET_USED(conf);
14908 shared_rss = mlx5_ipool_zmalloc
14909 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
14911 rte_flow_error_set(error, ENOMEM,
14912 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14913 "cannot allocate resource memory");
14914 goto error_rss_init;
14916 if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
14917 rte_flow_error_set(error, E2BIG,
14918 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14919 "rss action number out of range");
14920 goto error_rss_init;
14922 origin = &shared_rss->origin;
14923 origin->func = rss->func;
14924 origin->level = rss->level;
14925 /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
14926 origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
14927 /* NULL RSS key indicates default RSS key. */
14928 rss_key = !rss->key ? rss_hash_default_key : rss->key;
14929 memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
14930 origin->key = &shared_rss->key[0];
14931 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
14932 origin->queue = rss->queue;
14933 origin->queue_num = rss->queue_num;
14934 if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
14935 goto error_rss_init;
14936 /* Update queue with indirect table queue memoyr. */
14937 origin->queue = shared_rss->ind_tbl->queues;
14938 rte_spinlock_init(&shared_rss->action_rss_sl);
14939 __atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14940 rte_spinlock_lock(&priv->shared_act_sl);
14941 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14942 &priv->rss_shared_actions, idx, shared_rss, next);
14943 rte_spinlock_unlock(&priv->shared_act_sl);
14947 if (shared_rss->ind_tbl)
14948 mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
14949 !!dev->data->dev_started);
14950 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14957 * Destroy the shared RSS action.
14958 * Release related hash RX queue objects.
14961 * Pointer to the Ethernet device structure.
14963 * The shared RSS action object ID to be removed.
14964 * @param[out] error
14965 * Perform verbose error reporting if not NULL. Initialized in case of
14969 * 0 on success, otherwise negative errno value.
14972 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
14973 struct rte_flow_error *error)
14975 struct mlx5_priv *priv = dev->data->dev_private;
14976 struct mlx5_shared_action_rss *shared_rss =
14977 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14978 uint32_t old_refcnt = 1;
14982 return rte_flow_error_set(error, EINVAL,
14983 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14984 "invalid shared action");
14985 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
14986 0, 0, __ATOMIC_ACQUIRE,
14988 return rte_flow_error_set(error, EBUSY,
14989 RTE_FLOW_ERROR_TYPE_ACTION,
14991 "shared rss has references");
14992 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14994 return rte_flow_error_set(error, EBUSY,
14995 RTE_FLOW_ERROR_TYPE_ACTION,
14997 "shared rss hrxq has references");
14998 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
14999 !!dev->data->dev_started);
15001 return rte_flow_error_set(error, EBUSY,
15002 RTE_FLOW_ERROR_TYPE_ACTION,
15004 "shared rss indirection table has"
15006 rte_spinlock_lock(&priv->shared_act_sl);
15007 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
15008 &priv->rss_shared_actions, idx, shared_rss, next);
15009 rte_spinlock_unlock(&priv->shared_act_sl);
15010 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
15016 * Create indirect action, lock free,
15017 * (mutex should be acquired by caller).
15018 * Dispatcher for action type specific call.
15021 * Pointer to the Ethernet device structure.
15023 * Shared action configuration.
15024 * @param[in] action
15025 * Action specification used to create indirect action.
15026 * @param[out] error
15027 * Perform verbose error reporting if not NULL. Initialized in case of
15031 * A valid shared action handle in case of success, NULL otherwise and
15032 * rte_errno is set.
15034 struct rte_flow_action_handle *
15035 flow_dv_action_create(struct rte_eth_dev *dev,
15036 const struct rte_flow_indir_action_conf *conf,
15037 const struct rte_flow_action *action,
15038 struct rte_flow_error *err)
15040 struct mlx5_priv *priv = dev->data->dev_private;
15041 uint32_t age_idx = 0;
15045 switch (action->type) {
15046 case RTE_FLOW_ACTION_TYPE_RSS:
15047 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
15048 idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
15049 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
15051 case RTE_FLOW_ACTION_TYPE_AGE:
15052 age_idx = flow_dv_aso_age_alloc(dev, err);
15057 idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
15058 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
15059 flow_dv_aso_age_params_init(dev, age_idx,
15060 ((const struct rte_flow_action_age *)
15061 action->conf)->context ?
15062 ((const struct rte_flow_action_age *)
15063 action->conf)->context :
15064 (void *)(uintptr_t)idx,
15065 ((const struct rte_flow_action_age *)
15066 action->conf)->timeout);
15069 case RTE_FLOW_ACTION_TYPE_COUNT:
15070 ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
15071 idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
15072 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
15074 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
15075 ret = flow_dv_translate_create_conntrack(dev, action->conf,
15077 idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
15080 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
15081 NULL, "action type not supported");
15084 return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
15088 * Destroy the indirect action.
15089 * Release action related resources on the NIC and the memory.
15090 * Lock free, (mutex should be acquired by caller).
15091 * Dispatcher for action type specific call.
15094 * Pointer to the Ethernet device structure.
15095 * @param[in] handle
15096 * The indirect action object handle to be removed.
15097 * @param[out] error
15098 * Perform verbose error reporting if not NULL. Initialized in case of
15102 * 0 on success, otherwise negative errno value.
15105 flow_dv_action_destroy(struct rte_eth_dev *dev,
15106 struct rte_flow_action_handle *handle,
15107 struct rte_flow_error *error)
15109 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15110 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15111 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15112 struct mlx5_flow_counter *cnt;
15113 uint32_t no_flow_refcnt = 1;
15117 case MLX5_INDIRECT_ACTION_TYPE_RSS:
15118 return __flow_dv_action_rss_release(dev, idx, error);
15119 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15120 cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
15121 if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
15122 &no_flow_refcnt, 1, false,
15125 return rte_flow_error_set(error, EBUSY,
15126 RTE_FLOW_ERROR_TYPE_ACTION,
15128 "Indirect count action has references");
15129 flow_dv_counter_free(dev, idx);
15131 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15132 ret = flow_dv_aso_age_release(dev, idx);
15135 * In this case, the last flow has a reference will
15136 * actually release the age action.
15138 DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
15139 " released with references %d.", idx, ret);
15141 case MLX5_INDIRECT_ACTION_TYPE_CT:
15142 ret = flow_dv_aso_ct_release(dev, idx, error);
15146 DRV_LOG(DEBUG, "Connection tracking object %u still "
15147 "has references %d.", idx, ret);
15150 return rte_flow_error_set(error, ENOTSUP,
15151 RTE_FLOW_ERROR_TYPE_ACTION,
15153 "action type not supported");
15158 * Updates in place shared RSS action configuration.
15161 * Pointer to the Ethernet device structure.
15163 * The shared RSS action object ID to be updated.
15164 * @param[in] action_conf
15165 * RSS action specification used to modify *shared_rss*.
15166 * @param[out] error
15167 * Perform verbose error reporting if not NULL. Initialized in case of
15171 * 0 on success, otherwise negative errno value.
15172 * @note: currently only support update of RSS queues.
15175 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
15176 const struct rte_flow_action_rss *action_conf,
15177 struct rte_flow_error *error)
15179 struct mlx5_priv *priv = dev->data->dev_private;
15180 struct mlx5_shared_action_rss *shared_rss =
15181 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
15183 void *queue = NULL;
15184 void *queue_i = NULL;
15185 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
15186 bool dev_started = !!dev->data->dev_started;
15189 return rte_flow_error_set(error, EINVAL,
15190 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15191 "invalid shared action to update");
15192 if (priv->obj_ops.ind_table_modify == NULL)
15193 return rte_flow_error_set(error, ENOTSUP,
15194 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15195 "cannot modify indirection table");
15196 queue = mlx5_malloc(MLX5_MEM_ZERO,
15197 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
15200 return rte_flow_error_set(error, ENOMEM,
15201 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15203 "cannot allocate resource memory");
15204 memcpy(queue, action_conf->queue, queue_size);
15205 MLX5_ASSERT(shared_rss->ind_tbl);
15206 rte_spinlock_lock(&shared_rss->action_rss_sl);
15207 queue_i = shared_rss->ind_tbl->queues;
15208 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
15209 queue, action_conf->queue_num,
15210 true /* standalone */,
15211 dev_started /* ref_new_qs */,
15212 dev_started /* deref_old_qs */);
15214 ret = rte_flow_error_set(error, rte_errno,
15215 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15216 "cannot update indirection table");
15218 /* Restore the queue to indirect table internal queue. */
15219 memcpy(queue_i, queue, queue_size);
15220 shared_rss->ind_tbl->queues = queue_i;
15221 shared_rss->origin.queue_num = action_conf->queue_num;
15224 rte_spinlock_unlock(&shared_rss->action_rss_sl);
15229 * Updates in place conntrack context or direction.
15230 * Context update should be synchronized.
15233 * Pointer to the Ethernet device structure.
15235 * The conntrack object ID to be updated.
15236 * @param[in] update
15237 * Pointer to the structure of information to update.
15238 * @param[out] error
15239 * Perform verbose error reporting if not NULL. Initialized in case of
15243 * 0 on success, otherwise negative errno value.
15246 __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
15247 const struct rte_flow_modify_conntrack *update,
15248 struct rte_flow_error *error)
15250 struct mlx5_priv *priv = dev->data->dev_private;
15251 struct mlx5_aso_ct_action *ct;
15252 const struct rte_flow_action_conntrack *new_prf;
15254 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
15257 if (PORT_ID(priv) != owner)
15258 return rte_flow_error_set(error, EACCES,
15259 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15261 "CT object owned by another port");
15262 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
15263 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
15265 return rte_flow_error_set(error, ENOMEM,
15266 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15268 "CT object is inactive");
15269 new_prf = &update->new_ct;
15270 if (update->direction)
15271 ct->is_original = !!new_prf->is_original_dir;
15272 if (update->state) {
15273 /* Only validate the profile when it needs to be updated. */
15274 ret = mlx5_validate_action_ct(dev, new_prf, error);
15277 ret = mlx5_aso_ct_update_by_wqe(priv->sh, ct, new_prf);
15279 return rte_flow_error_set(error, EIO,
15280 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15282 "Failed to send CT context update WQE");
15283 /* Block until ready or a failure. */
15284 ret = mlx5_aso_ct_available(priv->sh, ct);
15286 rte_flow_error_set(error, rte_errno,
15287 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15289 "Timeout to get the CT update");
15295 * Updates in place shared action configuration, lock free,
15296 * (mutex should be acquired by caller).
15299 * Pointer to the Ethernet device structure.
15300 * @param[in] handle
15301 * The indirect action object handle to be updated.
15302 * @param[in] update
15303 * Action specification used to modify the action pointed by *handle*.
15304 * *update* could be of same type with the action pointed by the *handle*
15305 * handle argument, or some other structures like a wrapper, depending on
15306 * the indirect action type.
15307 * @param[out] error
15308 * Perform verbose error reporting if not NULL. Initialized in case of
15312 * 0 on success, otherwise negative errno value.
15315 flow_dv_action_update(struct rte_eth_dev *dev,
15316 struct rte_flow_action_handle *handle,
15317 const void *update,
15318 struct rte_flow_error *err)
15320 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15321 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15322 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15323 const void *action_conf;
15326 case MLX5_INDIRECT_ACTION_TYPE_RSS:
15327 action_conf = ((const struct rte_flow_action *)update)->conf;
15328 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
15329 case MLX5_INDIRECT_ACTION_TYPE_CT:
15330 return __flow_dv_action_ct_update(dev, idx, update, err);
15332 return rte_flow_error_set(err, ENOTSUP,
15333 RTE_FLOW_ERROR_TYPE_ACTION,
15335 "action type update not supported");
15340 * Destroy the meter sub policy table rules.
15341 * Lock free, (mutex should be acquired by caller).
15344 * Pointer to Ethernet device.
15345 * @param[in] sub_policy
15346 * Pointer to meter sub policy table.
15349 __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
15350 struct mlx5_flow_meter_sub_policy *sub_policy)
15352 struct mlx5_priv *priv = dev->data->dev_private;
15353 struct mlx5_flow_tbl_data_entry *tbl;
15354 struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
15355 struct mlx5_flow_meter_info *next_fm;
15356 struct mlx5_sub_policy_color_rule *color_rule;
15360 for (i = 0; i < RTE_COLORS; i++) {
15362 if (i == RTE_COLOR_GREEN && policy &&
15363 policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
15364 next_fm = mlx5_flow_meter_find(priv,
15365 policy->act_cnt[i].next_mtr_id, NULL);
15366 RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
15368 claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
15369 tbl = container_of(color_rule->matcher->tbl,
15370 typeof(*tbl), tbl);
15371 mlx5_list_unregister(tbl->matchers,
15372 &color_rule->matcher->entry);
15373 TAILQ_REMOVE(&sub_policy->color_rules[i],
15374 color_rule, next_port);
15375 mlx5_free(color_rule);
15377 mlx5_flow_meter_detach(priv, next_fm);
15380 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15381 if (sub_policy->rix_hrxq[i]) {
15382 if (policy && !policy->is_hierarchy)
15383 mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
15384 sub_policy->rix_hrxq[i] = 0;
15386 if (sub_policy->jump_tbl[i]) {
15387 flow_dv_tbl_resource_release(MLX5_SH(dev),
15388 sub_policy->jump_tbl[i]);
15389 sub_policy->jump_tbl[i] = NULL;
15392 if (sub_policy->tbl_rsc) {
15393 flow_dv_tbl_resource_release(MLX5_SH(dev),
15394 sub_policy->tbl_rsc);
15395 sub_policy->tbl_rsc = NULL;
15400 * Destroy policy rules, lock free,
15401 * (mutex should be acquired by caller).
15402 * Dispatcher for action type specific call.
15405 * Pointer to the Ethernet device structure.
15406 * @param[in] mtr_policy
15407 * Meter policy struct.
15410 flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
15411 struct mlx5_flow_meter_policy *mtr_policy)
15414 struct mlx5_flow_meter_sub_policy *sub_policy;
15415 uint16_t sub_policy_num;
15417 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15418 sub_policy_num = (mtr_policy->sub_policy_num >>
15419 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15420 MLX5_MTR_SUB_POLICY_NUM_MASK;
15421 for (j = 0; j < sub_policy_num; j++) {
15422 sub_policy = mtr_policy->sub_policys[i][j];
15424 __flow_dv_destroy_sub_policy_rules(dev,
15431 * Destroy policy action, lock free,
15432 * (mutex should be acquired by caller).
15433 * Dispatcher for action type specific call.
15436 * Pointer to the Ethernet device structure.
15437 * @param[in] mtr_policy
15438 * Meter policy struct.
15441 flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
15442 struct mlx5_flow_meter_policy *mtr_policy)
15444 struct rte_flow_action *rss_action;
15445 struct mlx5_flow_handle dev_handle;
15448 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15449 if (mtr_policy->act_cnt[i].rix_mark) {
15450 flow_dv_tag_release(dev,
15451 mtr_policy->act_cnt[i].rix_mark);
15452 mtr_policy->act_cnt[i].rix_mark = 0;
15454 if (mtr_policy->act_cnt[i].modify_hdr) {
15455 dev_handle.dvh.modify_hdr =
15456 mtr_policy->act_cnt[i].modify_hdr;
15457 flow_dv_modify_hdr_resource_release(dev, &dev_handle);
15459 switch (mtr_policy->act_cnt[i].fate_action) {
15460 case MLX5_FLOW_FATE_SHARED_RSS:
15461 rss_action = mtr_policy->act_cnt[i].rss;
15462 mlx5_free(rss_action);
15464 case MLX5_FLOW_FATE_PORT_ID:
15465 if (mtr_policy->act_cnt[i].rix_port_id_action) {
15466 flow_dv_port_id_action_resource_release(dev,
15467 mtr_policy->act_cnt[i].rix_port_id_action);
15468 mtr_policy->act_cnt[i].rix_port_id_action = 0;
15471 case MLX5_FLOW_FATE_DROP:
15472 case MLX5_FLOW_FATE_JUMP:
15473 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15474 mtr_policy->act_cnt[i].dr_jump_action[j] =
15478 /*Queue action do nothing*/
15482 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15483 mtr_policy->dr_drop_action[j] = NULL;
15487 * Create policy action per domain, lock free,
15488 * (mutex should be acquired by caller).
15489 * Dispatcher for action type specific call.
15492 * Pointer to the Ethernet device structure.
15493 * @param[in] mtr_policy
15494 * Meter policy struct.
15495 * @param[in] action
15496 * Action specification used to create meter actions.
15497 * @param[out] error
15498 * Perform verbose error reporting if not NULL. Initialized in case of
15502 * 0 on success, otherwise negative errno value.
15505 __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
15506 struct mlx5_flow_meter_policy *mtr_policy,
15507 const struct rte_flow_action *actions[RTE_COLORS],
15508 enum mlx5_meter_domain domain,
15509 struct rte_mtr_error *error)
15511 struct mlx5_priv *priv = dev->data->dev_private;
15512 struct rte_flow_error flow_err;
15513 const struct rte_flow_action *act;
15514 uint64_t action_flags;
15515 struct mlx5_flow_handle dh;
15516 struct mlx5_flow dev_flow;
15517 struct mlx5_flow_dv_port_id_action_resource port_id_action;
15519 uint8_t egress, transfer;
15520 struct mlx5_meter_policy_action_container *act_cnt = NULL;
15522 struct mlx5_flow_dv_modify_hdr_resource res;
15523 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
15524 sizeof(struct mlx5_modification_cmd) *
15525 (MLX5_MAX_MODIFY_NUM + 1)];
15527 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
15528 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15531 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15532 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15533 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
15534 memset(&dev_flow, 0, sizeof(struct mlx5_flow));
15535 memset(&port_id_action, 0,
15536 sizeof(struct mlx5_flow_dv_port_id_action_resource));
15537 memset(mhdr_res, 0, sizeof(*mhdr_res));
15538 mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
15539 (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15540 MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
15541 dev_flow.handle = &dh;
15542 dev_flow.dv.port_id_action = &port_id_action;
15543 dev_flow.external = true;
15544 for (i = 0; i < RTE_COLORS; i++) {
15545 if (i < MLX5_MTR_RTE_COLORS)
15546 act_cnt = &mtr_policy->act_cnt[i];
15547 /* Skip the color policy actions creation. */
15548 if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
15549 (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
15552 for (act = actions[i];
15553 act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
15554 switch (act->type) {
15555 case RTE_FLOW_ACTION_TYPE_MARK:
15557 uint32_t tag_be = mlx5_flow_mark_set
15558 (((const struct rte_flow_action_mark *)
15561 if (i >= MLX5_MTR_RTE_COLORS)
15562 return -rte_mtr_error_set(error,
15564 RTE_MTR_ERROR_TYPE_METER_POLICY,
15566 "cannot create policy "
15567 "mark action for this color");
15569 if (flow_dv_tag_resource_register(dev, tag_be,
15570 &dev_flow, &flow_err))
15571 return -rte_mtr_error_set(error,
15573 RTE_MTR_ERROR_TYPE_METER_POLICY,
15575 "cannot setup policy mark action");
15576 MLX5_ASSERT(dev_flow.dv.tag_resource);
15577 act_cnt->rix_mark =
15578 dev_flow.handle->dvh.rix_tag;
15579 action_flags |= MLX5_FLOW_ACTION_MARK;
15582 case RTE_FLOW_ACTION_TYPE_SET_TAG:
15583 if (i >= MLX5_MTR_RTE_COLORS)
15584 return -rte_mtr_error_set(error,
15586 RTE_MTR_ERROR_TYPE_METER_POLICY,
15588 "cannot create policy "
15589 "set tag action for this color");
15590 if (flow_dv_convert_action_set_tag
15592 (const struct rte_flow_action_set_tag *)
15593 act->conf, &flow_err))
15594 return -rte_mtr_error_set(error,
15596 RTE_MTR_ERROR_TYPE_METER_POLICY,
15597 NULL, "cannot convert policy "
15599 if (!mhdr_res->actions_num)
15600 return -rte_mtr_error_set(error,
15602 RTE_MTR_ERROR_TYPE_METER_POLICY,
15603 NULL, "cannot find policy "
15605 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15607 case RTE_FLOW_ACTION_TYPE_DROP:
15609 struct mlx5_flow_mtr_mng *mtrmng =
15611 struct mlx5_flow_tbl_data_entry *tbl_data;
15614 * Create the drop table with
15615 * METER DROP level.
15617 if (!mtrmng->drop_tbl[domain]) {
15618 mtrmng->drop_tbl[domain] =
15619 flow_dv_tbl_resource_get(dev,
15620 MLX5_FLOW_TABLE_LEVEL_METER,
15621 egress, transfer, false, NULL, 0,
15622 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
15623 if (!mtrmng->drop_tbl[domain])
15624 return -rte_mtr_error_set
15626 RTE_MTR_ERROR_TYPE_METER_POLICY,
15628 "Failed to create meter drop table");
15630 tbl_data = container_of
15631 (mtrmng->drop_tbl[domain],
15632 struct mlx5_flow_tbl_data_entry, tbl);
15633 if (i < MLX5_MTR_RTE_COLORS) {
15634 act_cnt->dr_jump_action[domain] =
15635 tbl_data->jump.action;
15636 act_cnt->fate_action =
15637 MLX5_FLOW_FATE_DROP;
15639 if (i == RTE_COLOR_RED)
15640 mtr_policy->dr_drop_action[domain] =
15641 tbl_data->jump.action;
15642 action_flags |= MLX5_FLOW_ACTION_DROP;
15645 case RTE_FLOW_ACTION_TYPE_QUEUE:
15647 if (i >= MLX5_MTR_RTE_COLORS)
15648 return -rte_mtr_error_set(error,
15650 RTE_MTR_ERROR_TYPE_METER_POLICY,
15651 NULL, "cannot create policy "
15652 "fate queue for this color");
15654 ((const struct rte_flow_action_queue *)
15655 (act->conf))->index;
15656 act_cnt->fate_action =
15657 MLX5_FLOW_FATE_QUEUE;
15658 dev_flow.handle->fate_action =
15659 MLX5_FLOW_FATE_QUEUE;
15660 mtr_policy->is_queue = 1;
15661 action_flags |= MLX5_FLOW_ACTION_QUEUE;
15664 case RTE_FLOW_ACTION_TYPE_RSS:
15668 if (i >= MLX5_MTR_RTE_COLORS)
15669 return -rte_mtr_error_set(error,
15671 RTE_MTR_ERROR_TYPE_METER_POLICY,
15673 "cannot create policy "
15674 "rss action for this color");
15676 * Save RSS conf into policy struct
15677 * for translate stage.
15679 rss_size = (int)rte_flow_conv
15680 (RTE_FLOW_CONV_OP_ACTION,
15681 NULL, 0, act, &flow_err);
15683 return -rte_mtr_error_set(error,
15685 RTE_MTR_ERROR_TYPE_METER_POLICY,
15686 NULL, "Get the wrong "
15687 "rss action struct size");
15688 act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
15689 rss_size, 0, SOCKET_ID_ANY);
15691 return -rte_mtr_error_set(error,
15693 RTE_MTR_ERROR_TYPE_METER_POLICY,
15695 "Fail to malloc rss action memory");
15696 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
15697 act_cnt->rss, rss_size,
15700 return -rte_mtr_error_set(error,
15702 RTE_MTR_ERROR_TYPE_METER_POLICY,
15703 NULL, "Fail to save "
15704 "rss action into policy struct");
15705 act_cnt->fate_action =
15706 MLX5_FLOW_FATE_SHARED_RSS;
15707 action_flags |= MLX5_FLOW_ACTION_RSS;
15710 case RTE_FLOW_ACTION_TYPE_PORT_ID:
15711 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15713 struct mlx5_flow_dv_port_id_action_resource
15715 uint32_t port_id = 0;
15717 if (i >= MLX5_MTR_RTE_COLORS)
15718 return -rte_mtr_error_set(error,
15720 RTE_MTR_ERROR_TYPE_METER_POLICY,
15721 NULL, "cannot create policy "
15722 "port action for this color");
15723 memset(&port_id_resource, 0,
15724 sizeof(port_id_resource));
15725 if (flow_dv_translate_action_port_id(dev, act,
15726 &port_id, &flow_err))
15727 return -rte_mtr_error_set(error,
15729 RTE_MTR_ERROR_TYPE_METER_POLICY,
15730 NULL, "cannot translate "
15731 "policy port action");
15732 port_id_resource.port_id = port_id;
15733 if (flow_dv_port_id_action_resource_register
15734 (dev, &port_id_resource,
15735 &dev_flow, &flow_err))
15736 return -rte_mtr_error_set(error,
15738 RTE_MTR_ERROR_TYPE_METER_POLICY,
15739 NULL, "cannot setup "
15740 "policy port action");
15741 act_cnt->rix_port_id_action =
15742 dev_flow.handle->rix_port_id_action;
15743 act_cnt->fate_action =
15744 MLX5_FLOW_FATE_PORT_ID;
15745 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15748 case RTE_FLOW_ACTION_TYPE_JUMP:
15750 uint32_t jump_group = 0;
15751 uint32_t table = 0;
15752 struct mlx5_flow_tbl_data_entry *tbl_data;
15753 struct flow_grp_info grp_info = {
15754 .external = !!dev_flow.external,
15755 .transfer = !!transfer,
15756 .fdb_def_rule = !!priv->fdb_def_rule,
15758 .skip_scale = dev_flow.skip_scale &
15759 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
15761 struct mlx5_flow_meter_sub_policy *sub_policy =
15762 mtr_policy->sub_policys[domain][0];
15764 if (i >= MLX5_MTR_RTE_COLORS)
15765 return -rte_mtr_error_set(error,
15767 RTE_MTR_ERROR_TYPE_METER_POLICY,
15769 "cannot create policy "
15770 "jump action for this color");
15772 ((const struct rte_flow_action_jump *)
15774 if (mlx5_flow_group_to_table(dev, NULL,
15777 &grp_info, &flow_err))
15778 return -rte_mtr_error_set(error,
15780 RTE_MTR_ERROR_TYPE_METER_POLICY,
15781 NULL, "cannot setup "
15782 "policy jump action");
15783 sub_policy->jump_tbl[i] =
15784 flow_dv_tbl_resource_get(dev,
15787 !!dev_flow.external,
15788 NULL, jump_group, 0,
15791 (!sub_policy->jump_tbl[i])
15792 return -rte_mtr_error_set(error,
15794 RTE_MTR_ERROR_TYPE_METER_POLICY,
15795 NULL, "cannot create jump action.");
15796 tbl_data = container_of
15797 (sub_policy->jump_tbl[i],
15798 struct mlx5_flow_tbl_data_entry, tbl);
15799 act_cnt->dr_jump_action[domain] =
15800 tbl_data->jump.action;
15801 act_cnt->fate_action =
15802 MLX5_FLOW_FATE_JUMP;
15803 action_flags |= MLX5_FLOW_ACTION_JUMP;
15807 * No need to check meter hierarchy for Y or R colors
15808 * here since it is done in the validation stage.
15810 case RTE_FLOW_ACTION_TYPE_METER:
15812 const struct rte_flow_action_meter *mtr;
15813 struct mlx5_flow_meter_info *next_fm;
15814 struct mlx5_flow_meter_policy *next_policy;
15815 struct rte_flow_action tag_action;
15816 struct mlx5_rte_flow_action_set_tag set_tag;
15817 uint32_t next_mtr_idx = 0;
15820 next_fm = mlx5_flow_meter_find(priv,
15824 return -rte_mtr_error_set(error, EINVAL,
15825 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15826 "Fail to find next meter.");
15827 if (next_fm->def_policy)
15828 return -rte_mtr_error_set(error, EINVAL,
15829 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15830 "Hierarchy only supports termination meter.");
15831 next_policy = mlx5_flow_meter_policy_find(dev,
15832 next_fm->policy_id, NULL);
15833 MLX5_ASSERT(next_policy);
15834 if (next_fm->drop_cnt) {
15837 mlx5_flow_get_reg_id(dev,
15840 (struct rte_flow_error *)error);
15841 set_tag.offset = (priv->mtr_reg_share ?
15842 MLX5_MTR_COLOR_BITS : 0);
15843 set_tag.length = (priv->mtr_reg_share ?
15844 MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
15846 set_tag.data = next_mtr_idx;
15848 (enum rte_flow_action_type)
15849 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
15850 tag_action.conf = &set_tag;
15851 if (flow_dv_convert_action_set_reg
15852 (mhdr_res, &tag_action,
15853 (struct rte_flow_error *)error))
15856 MLX5_FLOW_ACTION_SET_TAG;
15858 act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
15859 act_cnt->next_mtr_id = next_fm->meter_id;
15860 act_cnt->next_sub_policy = NULL;
15861 mtr_policy->is_hierarchy = 1;
15862 mtr_policy->dev = next_policy->dev;
15864 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
15868 return -rte_mtr_error_set(error, ENOTSUP,
15869 RTE_MTR_ERROR_TYPE_METER_POLICY,
15870 NULL, "action type not supported");
15872 if (action_flags & MLX5_FLOW_ACTION_SET_TAG) {
15873 /* create modify action if needed. */
15874 dev_flow.dv.group = 1;
15875 if (flow_dv_modify_hdr_resource_register
15876 (dev, mhdr_res, &dev_flow, &flow_err))
15877 return -rte_mtr_error_set(error,
15879 RTE_MTR_ERROR_TYPE_METER_POLICY,
15880 NULL, "cannot register policy "
15882 act_cnt->modify_hdr =
15883 dev_flow.handle->dvh.modify_hdr;
15891 * Create policy action per domain, lock free,
15892 * (mutex should be acquired by caller).
15893 * Dispatcher for action type specific call.
15896 * Pointer to the Ethernet device structure.
15897 * @param[in] mtr_policy
15898 * Meter policy struct.
15899 * @param[in] action
15900 * Action specification used to create meter actions.
15901 * @param[out] error
15902 * Perform verbose error reporting if not NULL. Initialized in case of
15906 * 0 on success, otherwise negative errno value.
15909 flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
15910 struct mlx5_flow_meter_policy *mtr_policy,
15911 const struct rte_flow_action *actions[RTE_COLORS],
15912 struct rte_mtr_error *error)
15915 uint16_t sub_policy_num;
15917 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15918 sub_policy_num = (mtr_policy->sub_policy_num >>
15919 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15920 MLX5_MTR_SUB_POLICY_NUM_MASK;
15921 if (sub_policy_num) {
15922 ret = __flow_dv_create_domain_policy_acts(dev,
15923 mtr_policy, actions,
15924 (enum mlx5_meter_domain)i, error);
15925 /* Cleaning resource is done in the caller level. */
15934 * Query a DV flow rule for its statistics via DevX.
15937 * Pointer to Ethernet device.
15938 * @param[in] cnt_idx
15939 * Index to the flow counter.
15941 * Data retrieved by the query.
15942 * @param[out] error
15943 * Perform verbose error reporting if not NULL.
15946 * 0 on success, a negative errno value otherwise and rte_errno is set.
15949 flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
15950 struct rte_flow_error *error)
15952 struct mlx5_priv *priv = dev->data->dev_private;
15953 struct rte_flow_query_count *qc = data;
15955 if (!priv->sh->cdev->config.devx)
15956 return rte_flow_error_set(error, ENOTSUP,
15957 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15959 "counters are not supported");
15961 uint64_t pkts, bytes;
15962 struct mlx5_flow_counter *cnt;
15963 int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
15966 return rte_flow_error_set(error, -err,
15967 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15968 NULL, "cannot read counters");
15969 cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
15972 qc->hits = pkts - cnt->hits;
15973 qc->bytes = bytes - cnt->bytes;
15976 cnt->bytes = bytes;
15980 return rte_flow_error_set(error, EINVAL,
15981 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15983 "counters are not available");
15987 flow_dv_action_query(struct rte_eth_dev *dev,
15988 const struct rte_flow_action_handle *handle, void *data,
15989 struct rte_flow_error *error)
15991 struct mlx5_age_param *age_param;
15992 struct rte_flow_query_age *resp;
15993 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15994 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15995 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15996 struct mlx5_priv *priv = dev->data->dev_private;
15997 struct mlx5_aso_ct_action *ct;
16002 case MLX5_INDIRECT_ACTION_TYPE_AGE:
16003 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
16005 resp->aged = __atomic_load_n(&age_param->state,
16006 __ATOMIC_RELAXED) == AGE_TMOUT ?
16008 resp->sec_since_last_hit_valid = !resp->aged;
16009 if (resp->sec_since_last_hit_valid)
16010 resp->sec_since_last_hit = __atomic_load_n
16011 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
16013 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
16014 return flow_dv_query_count(dev, idx, data, error);
16015 case MLX5_INDIRECT_ACTION_TYPE_CT:
16016 owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
16017 if (owner != PORT_ID(priv))
16018 return rte_flow_error_set(error, EACCES,
16019 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16021 "CT object owned by another port");
16022 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
16023 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
16026 return rte_flow_error_set(error, EFAULT,
16027 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16029 "CT object is inactive");
16030 ((struct rte_flow_action_conntrack *)data)->peer_port =
16032 ((struct rte_flow_action_conntrack *)data)->is_original_dir =
16034 if (mlx5_aso_ct_query_by_wqe(priv->sh, ct, data))
16035 return rte_flow_error_set(error, EIO,
16036 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16038 "Failed to query CT context");
16041 return rte_flow_error_set(error, ENOTSUP,
16042 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16043 "action type query not supported");
16048 * Query a flow rule AGE action for aging information.
16051 * Pointer to Ethernet device.
16053 * Pointer to the sub flow.
16055 * data retrieved by the query.
16056 * @param[out] error
16057 * Perform verbose error reporting if not NULL.
16060 * 0 on success, a negative errno value otherwise and rte_errno is set.
16063 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
16064 void *data, struct rte_flow_error *error)
16066 struct rte_flow_query_age *resp = data;
16067 struct mlx5_age_param *age_param;
16070 struct mlx5_aso_age_action *act =
16071 flow_aso_age_get_by_idx(dev, flow->age);
16073 age_param = &act->age_params;
16074 } else if (flow->counter) {
16075 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
16077 if (!age_param || !age_param->timeout)
16078 return rte_flow_error_set
16080 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16081 NULL, "cannot read age data");
16083 return rte_flow_error_set(error, EINVAL,
16084 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16085 NULL, "age data not available");
16087 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
16089 resp->sec_since_last_hit_valid = !resp->aged;
16090 if (resp->sec_since_last_hit_valid)
16091 resp->sec_since_last_hit = __atomic_load_n
16092 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
16099 * @see rte_flow_query()
16100 * @see rte_flow_ops
16103 flow_dv_query(struct rte_eth_dev *dev,
16104 struct rte_flow *flow __rte_unused,
16105 const struct rte_flow_action *actions __rte_unused,
16106 void *data __rte_unused,
16107 struct rte_flow_error *error __rte_unused)
16111 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
16112 switch (actions->type) {
16113 case RTE_FLOW_ACTION_TYPE_VOID:
16115 case RTE_FLOW_ACTION_TYPE_COUNT:
16116 ret = flow_dv_query_count(dev, flow->counter, data,
16119 case RTE_FLOW_ACTION_TYPE_AGE:
16120 ret = flow_dv_query_age(dev, flow, data, error);
16123 return rte_flow_error_set(error, ENOTSUP,
16124 RTE_FLOW_ERROR_TYPE_ACTION,
16126 "action not supported");
16133 * Destroy the meter table set.
16134 * Lock free, (mutex should be acquired by caller).
16137 * Pointer to Ethernet device.
16139 * Meter information table.
16142 flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
16143 struct mlx5_flow_meter_info *fm)
16145 struct mlx5_priv *priv = dev->data->dev_private;
16148 if (!fm || !priv->sh->config.dv_flow_en)
16150 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16151 if (fm->drop_rule[i]) {
16152 claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
16153 fm->drop_rule[i] = NULL;
16159 flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
16161 struct mlx5_priv *priv = dev->data->dev_private;
16162 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16163 struct mlx5_flow_tbl_data_entry *tbl;
16166 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16167 if (mtrmng->def_rule[i]) {
16168 claim_zero(mlx5_flow_os_destroy_flow
16169 (mtrmng->def_rule[i]));
16170 mtrmng->def_rule[i] = NULL;
16172 if (mtrmng->def_matcher[i]) {
16173 tbl = container_of(mtrmng->def_matcher[i]->tbl,
16174 struct mlx5_flow_tbl_data_entry, tbl);
16175 mlx5_list_unregister(tbl->matchers,
16176 &mtrmng->def_matcher[i]->entry);
16177 mtrmng->def_matcher[i] = NULL;
16179 for (j = 0; j < MLX5_REG_BITS; j++) {
16180 if (mtrmng->drop_matcher[i][j]) {
16182 container_of(mtrmng->drop_matcher[i][j]->tbl,
16183 struct mlx5_flow_tbl_data_entry,
16185 mlx5_list_unregister(tbl->matchers,
16186 &mtrmng->drop_matcher[i][j]->entry);
16187 mtrmng->drop_matcher[i][j] = NULL;
16190 if (mtrmng->drop_tbl[i]) {
16191 flow_dv_tbl_resource_release(MLX5_SH(dev),
16192 mtrmng->drop_tbl[i]);
16193 mtrmng->drop_tbl[i] = NULL;
16198 /* Number of meter flow actions, count and jump or count and drop. */
16199 #define METER_ACTIONS 2
16202 __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
16203 enum mlx5_meter_domain domain)
16205 struct mlx5_priv *priv = dev->data->dev_private;
16206 struct mlx5_flow_meter_def_policy *def_policy =
16207 priv->sh->mtrmng->def_policy[domain];
16209 __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
16210 mlx5_free(def_policy);
16211 priv->sh->mtrmng->def_policy[domain] = NULL;
16215 * Destroy the default policy table set.
16218 * Pointer to Ethernet device.
16221 flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
16223 struct mlx5_priv *priv = dev->data->dev_private;
16226 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
16227 if (priv->sh->mtrmng->def_policy[i])
16228 __flow_dv_destroy_domain_def_policy(dev,
16229 (enum mlx5_meter_domain)i);
16230 priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
16234 __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
16235 uint32_t color_reg_c_idx,
16236 enum rte_color color, void *matcher_object,
16237 int actions_n, void *actions,
16238 bool match_src_port, const struct rte_flow_item *item,
16239 void **rule, const struct rte_flow_attr *attr)
16242 struct mlx5_flow_dv_match_params value = {
16243 .size = sizeof(value.buf),
16245 struct mlx5_flow_dv_match_params matcher = {
16246 .size = sizeof(matcher.buf),
16248 struct mlx5_priv *priv = dev->data->dev_private;
16251 if (match_src_port && priv->sh->esw_mode) {
16252 if (flow_dv_translate_item_port_id(dev, matcher.buf,
16253 value.buf, item, attr)) {
16254 DRV_LOG(ERR, "Failed to create meter policy%d flow's"
16255 " value with port.", color);
16259 flow_dv_match_meta_reg(matcher.buf, value.buf,
16260 (enum modify_reg)color_reg_c_idx,
16261 rte_col_2_mlx5_col(color), UINT32_MAX);
16262 misc_mask = flow_dv_matcher_enable(value.buf);
16263 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16264 ret = mlx5_flow_os_create_flow(matcher_object, (void *)&value,
16265 actions_n, actions, rule);
16267 DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
16274 __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
16275 uint32_t color_reg_c_idx,
16277 struct mlx5_flow_meter_sub_policy *sub_policy,
16278 const struct rte_flow_attr *attr,
16279 bool match_src_port,
16280 const struct rte_flow_item *item,
16281 struct mlx5_flow_dv_matcher **policy_matcher,
16282 struct rte_flow_error *error)
16284 struct mlx5_list_entry *entry;
16285 struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
16286 struct mlx5_flow_dv_matcher matcher = {
16288 .size = sizeof(matcher.mask.buf),
16292 struct mlx5_flow_dv_match_params value = {
16293 .size = sizeof(value.buf),
16295 struct mlx5_flow_cb_ctx ctx = {
16299 struct mlx5_flow_tbl_data_entry *tbl_data;
16300 struct mlx5_priv *priv = dev->data->dev_private;
16301 const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
16303 if (match_src_port && priv->sh->esw_mode) {
16304 if (flow_dv_translate_item_port_id(dev, matcher.mask.buf,
16305 value.buf, item, attr)) {
16306 DRV_LOG(ERR, "Failed to register meter policy%d matcher"
16307 " with port.", priority);
16311 tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
16312 if (priority < RTE_COLOR_RED)
16313 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16314 (enum modify_reg)color_reg_c_idx, 0, color_mask);
16315 matcher.priority = priority;
16316 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
16317 matcher.mask.size);
16318 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16320 DRV_LOG(ERR, "Failed to register meter drop matcher.");
16324 container_of(entry, struct mlx5_flow_dv_matcher, entry);
16329 * Create the policy rules per domain.
16332 * Pointer to Ethernet device.
16333 * @param[in] sub_policy
16334 * Pointer to sub policy table..
16335 * @param[in] egress
16336 * Direction of the table.
16337 * @param[in] transfer
16338 * E-Switch or NIC flow.
16340 * Pointer to policy action list per color.
16343 * 0 on success, -1 otherwise.
16346 __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
16347 struct mlx5_flow_meter_sub_policy *sub_policy,
16348 uint8_t egress, uint8_t transfer, bool match_src_port,
16349 struct mlx5_meter_policy_acts acts[RTE_COLORS])
16351 struct mlx5_priv *priv = dev->data->dev_private;
16352 struct rte_flow_error flow_err;
16353 uint32_t color_reg_c_idx;
16354 struct rte_flow_attr attr = {
16355 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
16358 .egress = !!egress,
16359 .transfer = !!transfer,
16363 int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
16364 struct mlx5_sub_policy_color_rule *color_rule;
16366 struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
16370 /* Create policy table with POLICY level. */
16371 if (!sub_policy->tbl_rsc)
16372 sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
16373 MLX5_FLOW_TABLE_LEVEL_POLICY,
16374 egress, transfer, false, NULL, 0, 0,
16375 sub_policy->idx, &flow_err);
16376 if (!sub_policy->tbl_rsc) {
16378 "Failed to create meter sub policy table.");
16381 /* Prepare matchers. */
16382 color_reg_c_idx = ret;
16383 for (i = 0; i < RTE_COLORS; i++) {
16384 TAILQ_INIT(&sub_policy->color_rules[i]);
16385 if (!acts[i].actions_n)
16387 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
16388 sizeof(struct mlx5_sub_policy_color_rule),
16391 DRV_LOG(ERR, "No memory to create color rule.");
16394 tmp_rules[i] = color_rule;
16395 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
16396 color_rule, next_port);
16397 color_rule->src_port = priv->representor_id;
16400 /* Create matchers for colors. */
16401 svport_match = (i != RTE_COLOR_RED) ? match_src_port : false;
16402 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
16403 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
16404 &attr, svport_match, NULL,
16405 &color_rule->matcher, &flow_err)) {
16406 DRV_LOG(ERR, "Failed to create color%u matcher.", i);
16409 /* Create flow, matching color. */
16410 if (__flow_dv_create_policy_flow(dev,
16411 color_reg_c_idx, (enum rte_color)i,
16412 color_rule->matcher->matcher_object,
16413 acts[i].actions_n, acts[i].dv_actions,
16414 svport_match, NULL, &color_rule->rule,
16416 DRV_LOG(ERR, "Failed to create color%u rule.", i);
16422 /* All the policy rules will be cleared. */
16424 color_rule = tmp_rules[i];
16426 if (color_rule->rule)
16427 mlx5_flow_os_destroy_flow(color_rule->rule);
16428 if (color_rule->matcher) {
16429 struct mlx5_flow_tbl_data_entry *tbl =
16430 container_of(color_rule->matcher->tbl,
16431 typeof(*tbl), tbl);
16432 mlx5_list_unregister(tbl->matchers,
16433 &color_rule->matcher->entry);
16435 TAILQ_REMOVE(&sub_policy->color_rules[i],
16436 color_rule, next_port);
16437 mlx5_free(color_rule);
16444 __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
16445 struct mlx5_flow_meter_policy *mtr_policy,
16446 struct mlx5_flow_meter_sub_policy *sub_policy,
16449 struct mlx5_priv *priv = dev->data->dev_private;
16450 struct mlx5_meter_policy_acts acts[RTE_COLORS];
16451 struct mlx5_flow_dv_tag_resource *tag;
16452 struct mlx5_flow_dv_port_id_action_resource *port_action;
16453 struct mlx5_hrxq *hrxq;
16454 struct mlx5_flow_meter_info *next_fm = NULL;
16455 struct mlx5_flow_meter_policy *next_policy;
16456 struct mlx5_flow_meter_sub_policy *next_sub_policy;
16457 struct mlx5_flow_tbl_data_entry *tbl_data;
16458 struct rte_flow_error error;
16459 uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16460 uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16461 bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
16462 bool match_src_port = false;
16465 /* If RSS or Queue, no previous actions / rules is created. */
16466 for (i = 0; i < RTE_COLORS; i++) {
16467 acts[i].actions_n = 0;
16468 if (i == RTE_COLOR_RED) {
16469 /* Only support drop on red. */
16470 acts[i].dv_actions[0] =
16471 mtr_policy->dr_drop_action[domain];
16472 acts[i].actions_n = 1;
16475 if (i == RTE_COLOR_GREEN &&
16476 mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
16477 struct rte_flow_attr attr = {
16478 .transfer = transfer
16481 next_fm = mlx5_flow_meter_find(priv,
16482 mtr_policy->act_cnt[i].next_mtr_id,
16486 "Failed to get next hierarchy meter.");
16489 if (mlx5_flow_meter_attach(priv, next_fm,
16491 DRV_LOG(ERR, "%s", error.message);
16495 /* Meter action must be the first for TX. */
16497 acts[i].dv_actions[acts[i].actions_n] =
16498 next_fm->meter_action;
16499 acts[i].actions_n++;
16502 if (mtr_policy->act_cnt[i].rix_mark) {
16503 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
16504 mtr_policy->act_cnt[i].rix_mark);
16506 DRV_LOG(ERR, "Failed to find "
16507 "mark action for policy.");
16510 acts[i].dv_actions[acts[i].actions_n] = tag->action;
16511 acts[i].actions_n++;
16513 if (mtr_policy->act_cnt[i].modify_hdr) {
16514 acts[i].dv_actions[acts[i].actions_n] =
16515 mtr_policy->act_cnt[i].modify_hdr->action;
16516 acts[i].actions_n++;
16518 if (mtr_policy->act_cnt[i].fate_action) {
16519 switch (mtr_policy->act_cnt[i].fate_action) {
16520 case MLX5_FLOW_FATE_PORT_ID:
16521 port_action = mlx5_ipool_get
16522 (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
16523 mtr_policy->act_cnt[i].rix_port_id_action);
16524 if (!port_action) {
16525 DRV_LOG(ERR, "Failed to find "
16526 "port action for policy.");
16529 acts[i].dv_actions[acts[i].actions_n] =
16530 port_action->action;
16531 acts[i].actions_n++;
16532 mtr_policy->dev = dev;
16533 match_src_port = true;
16535 case MLX5_FLOW_FATE_DROP:
16536 case MLX5_FLOW_FATE_JUMP:
16537 acts[i].dv_actions[acts[i].actions_n] =
16538 mtr_policy->act_cnt[i].dr_jump_action[domain];
16539 acts[i].actions_n++;
16541 case MLX5_FLOW_FATE_SHARED_RSS:
16542 case MLX5_FLOW_FATE_QUEUE:
16543 hrxq = mlx5_ipool_get
16544 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16545 sub_policy->rix_hrxq[i]);
16547 DRV_LOG(ERR, "Failed to find "
16548 "queue action for policy.");
16551 acts[i].dv_actions[acts[i].actions_n] =
16553 acts[i].actions_n++;
16555 case MLX5_FLOW_FATE_MTR:
16558 "No next hierarchy meter.");
16562 acts[i].dv_actions[acts[i].actions_n] =
16563 next_fm->meter_action;
16564 acts[i].actions_n++;
16566 if (mtr_policy->act_cnt[i].next_sub_policy) {
16568 mtr_policy->act_cnt[i].next_sub_policy;
16571 mlx5_flow_meter_policy_find(dev,
16572 next_fm->policy_id, NULL);
16573 MLX5_ASSERT(next_policy);
16575 next_policy->sub_policys[domain][0];
16578 container_of(next_sub_policy->tbl_rsc,
16579 struct mlx5_flow_tbl_data_entry, tbl);
16580 acts[i].dv_actions[acts[i].actions_n++] =
16581 tbl_data->jump.action;
16582 if (mtr_policy->act_cnt[i].modify_hdr)
16583 match_src_port = !!transfer;
16586 /*Queue action do nothing*/
16591 if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
16592 egress, transfer, match_src_port, acts)) {
16594 "Failed to create policy rules per domain.");
16600 mlx5_flow_meter_detach(priv, next_fm);
16605 * Create the policy rules.
16608 * Pointer to Ethernet device.
16609 * @param[in,out] mtr_policy
16610 * Pointer to meter policy table.
16613 * 0 on success, -1 otherwise.
16616 flow_dv_create_policy_rules(struct rte_eth_dev *dev,
16617 struct mlx5_flow_meter_policy *mtr_policy)
16620 uint16_t sub_policy_num;
16622 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16623 sub_policy_num = (mtr_policy->sub_policy_num >>
16624 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
16625 MLX5_MTR_SUB_POLICY_NUM_MASK;
16626 if (!sub_policy_num)
16628 /* Prepare actions list and create policy rules. */
16629 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16630 mtr_policy->sub_policys[i][0], i)) {
16631 DRV_LOG(ERR, "Failed to create policy action "
16632 "list per domain.");
16640 __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
16642 struct mlx5_priv *priv = dev->data->dev_private;
16643 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16644 struct mlx5_flow_meter_def_policy *def_policy;
16645 struct mlx5_flow_tbl_resource *jump_tbl;
16646 struct mlx5_flow_tbl_data_entry *tbl_data;
16647 uint8_t egress, transfer;
16648 struct rte_flow_error error;
16649 struct mlx5_meter_policy_acts acts[RTE_COLORS];
16652 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16653 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16654 def_policy = mtrmng->def_policy[domain];
16656 def_policy = mlx5_malloc(MLX5_MEM_ZERO,
16657 sizeof(struct mlx5_flow_meter_def_policy),
16658 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
16660 DRV_LOG(ERR, "Failed to alloc default policy table.");
16661 goto def_policy_error;
16663 mtrmng->def_policy[domain] = def_policy;
16664 /* Create the meter suffix table with SUFFIX level. */
16665 jump_tbl = flow_dv_tbl_resource_get(dev,
16666 MLX5_FLOW_TABLE_LEVEL_METER,
16667 egress, transfer, false, NULL, 0,
16668 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
16671 "Failed to create meter suffix table.");
16672 goto def_policy_error;
16674 def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
16675 tbl_data = container_of(jump_tbl,
16676 struct mlx5_flow_tbl_data_entry, tbl);
16677 def_policy->dr_jump_action[RTE_COLOR_GREEN] =
16678 tbl_data->jump.action;
16679 acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
16680 acts[RTE_COLOR_GREEN].actions_n = 1;
16682 * YELLOW has the same default policy as GREEN does.
16683 * G & Y share the same table and action. The 2nd time of table
16684 * resource getting is just to update the reference count for
16685 * the releasing stage.
16687 jump_tbl = flow_dv_tbl_resource_get(dev,
16688 MLX5_FLOW_TABLE_LEVEL_METER,
16689 egress, transfer, false, NULL, 0,
16690 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
16693 "Failed to get meter suffix table.");
16694 goto def_policy_error;
16696 def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
16697 tbl_data = container_of(jump_tbl,
16698 struct mlx5_flow_tbl_data_entry, tbl);
16699 def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
16700 tbl_data->jump.action;
16701 acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
16702 acts[RTE_COLOR_YELLOW].actions_n = 1;
16703 /* Create jump action to the drop table. */
16704 if (!mtrmng->drop_tbl[domain]) {
16705 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
16706 (dev, MLX5_FLOW_TABLE_LEVEL_METER,
16707 egress, transfer, false, NULL, 0,
16708 0, MLX5_MTR_TABLE_ID_DROP, &error);
16709 if (!mtrmng->drop_tbl[domain]) {
16710 DRV_LOG(ERR, "Failed to create meter "
16711 "drop table for default policy.");
16712 goto def_policy_error;
16715 /* all RED: unique Drop table for jump action. */
16716 tbl_data = container_of(mtrmng->drop_tbl[domain],
16717 struct mlx5_flow_tbl_data_entry, tbl);
16718 def_policy->dr_jump_action[RTE_COLOR_RED] =
16719 tbl_data->jump.action;
16720 acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
16721 acts[RTE_COLOR_RED].actions_n = 1;
16722 /* Create default policy rules. */
16723 ret = __flow_dv_create_domain_policy_rules(dev,
16724 &def_policy->sub_policy,
16725 egress, transfer, false, acts);
16727 DRV_LOG(ERR, "Failed to create default policy rules.");
16728 goto def_policy_error;
16733 __flow_dv_destroy_domain_def_policy(dev,
16734 (enum mlx5_meter_domain)domain);
16739 * Create the default policy table set.
16742 * Pointer to Ethernet device.
16744 * 0 on success, -1 otherwise.
16747 flow_dv_create_def_policy(struct rte_eth_dev *dev)
16749 struct mlx5_priv *priv = dev->data->dev_private;
16752 /* Non-termination policy table. */
16753 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16754 if (!priv->sh->config.dv_esw_en &&
16755 i == MLX5_MTR_DOMAIN_TRANSFER)
16757 if (__flow_dv_create_domain_def_policy(dev, i)) {
16758 DRV_LOG(ERR, "Failed to create default policy");
16759 /* Rollback the created default policies for others. */
16760 flow_dv_destroy_def_policy(dev);
16768 * Create the needed meter tables.
16769 * Lock free, (mutex should be acquired by caller).
16772 * Pointer to Ethernet device.
16774 * Meter information table.
16775 * @param[in] mtr_idx
16777 * @param[in] domain_bitmap
16780 * 0 on success, -1 otherwise.
16783 flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
16784 struct mlx5_flow_meter_info *fm,
16786 uint8_t domain_bitmap)
16788 struct mlx5_priv *priv = dev->data->dev_private;
16789 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16790 struct rte_flow_error error;
16791 struct mlx5_flow_tbl_data_entry *tbl_data;
16792 uint8_t egress, transfer;
16793 void *actions[METER_ACTIONS];
16794 int domain, ret, i;
16795 struct mlx5_flow_counter *cnt;
16796 struct mlx5_flow_dv_match_params value = {
16797 .size = sizeof(value.buf),
16799 struct mlx5_flow_dv_match_params matcher_para = {
16800 .size = sizeof(matcher_para.buf),
16802 int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
16804 uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
16805 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
16806 struct mlx5_list_entry *entry;
16807 struct mlx5_flow_dv_matcher matcher = {
16809 .size = sizeof(matcher.mask.buf),
16812 struct mlx5_flow_dv_matcher *drop_matcher;
16813 struct mlx5_flow_cb_ctx ctx = {
16819 if (!priv->mtr_en || mtr_id_reg_c < 0) {
16820 rte_errno = ENOTSUP;
16823 for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
16824 if (!(domain_bitmap & (1 << domain)) ||
16825 (mtrmng->def_rule[domain] && !fm->drop_cnt))
16827 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16828 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16829 /* Create the drop table with METER DROP level. */
16830 if (!mtrmng->drop_tbl[domain]) {
16831 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
16832 MLX5_FLOW_TABLE_LEVEL_METER,
16833 egress, transfer, false, NULL, 0,
16834 0, MLX5_MTR_TABLE_ID_DROP, &error);
16835 if (!mtrmng->drop_tbl[domain]) {
16836 DRV_LOG(ERR, "Failed to create meter drop table.");
16840 /* Create default matcher in drop table. */
16841 matcher.tbl = mtrmng->drop_tbl[domain],
16842 tbl_data = container_of(mtrmng->drop_tbl[domain],
16843 struct mlx5_flow_tbl_data_entry, tbl);
16844 if (!mtrmng->def_matcher[domain]) {
16845 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16846 (enum modify_reg)mtr_id_reg_c,
16848 matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
16849 matcher.crc = rte_raw_cksum
16850 ((const void *)matcher.mask.buf,
16851 matcher.mask.size);
16852 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16854 DRV_LOG(ERR, "Failed to register meter "
16855 "drop default matcher.");
16858 mtrmng->def_matcher[domain] = container_of(entry,
16859 struct mlx5_flow_dv_matcher, entry);
16861 /* Create default rule in drop table. */
16862 if (!mtrmng->def_rule[domain]) {
16864 actions[i++] = priv->sh->dr_drop_action;
16865 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16866 (enum modify_reg)mtr_id_reg_c, 0, 0);
16867 misc_mask = flow_dv_matcher_enable(value.buf);
16868 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16869 ret = mlx5_flow_os_create_flow
16870 (mtrmng->def_matcher[domain]->matcher_object,
16871 (void *)&value, i, actions,
16872 &mtrmng->def_rule[domain]);
16874 DRV_LOG(ERR, "Failed to create meter "
16875 "default drop rule for drop table.");
16881 MLX5_ASSERT(mtrmng->max_mtr_bits);
16882 if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
16883 /* Create matchers for Drop. */
16884 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16885 (enum modify_reg)mtr_id_reg_c, 0,
16886 (mtr_id_mask << mtr_id_offset));
16887 matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
16888 matcher.crc = rte_raw_cksum
16889 ((const void *)matcher.mask.buf,
16890 matcher.mask.size);
16891 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16894 "Failed to register meter drop matcher.");
16897 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
16898 container_of(entry, struct mlx5_flow_dv_matcher,
16902 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
16903 /* Create drop rule, matching meter_id only. */
16904 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16905 (enum modify_reg)mtr_id_reg_c,
16906 (mtr_idx << mtr_id_offset), UINT32_MAX);
16908 cnt = flow_dv_counter_get_by_idx(dev,
16909 fm->drop_cnt, NULL);
16910 actions[i++] = cnt->action;
16911 actions[i++] = priv->sh->dr_drop_action;
16912 misc_mask = flow_dv_matcher_enable(value.buf);
16913 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16914 ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
16915 (void *)&value, i, actions,
16916 &fm->drop_rule[domain]);
16918 DRV_LOG(ERR, "Failed to create meter "
16919 "drop rule for drop table.");
16925 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16926 if (fm->drop_rule[i]) {
16927 claim_zero(mlx5_flow_os_destroy_flow
16928 (fm->drop_rule[i]));
16929 fm->drop_rule[i] = NULL;
16935 static struct mlx5_flow_meter_sub_policy *
16936 __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
16937 struct mlx5_flow_meter_policy *mtr_policy,
16938 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
16939 struct mlx5_flow_meter_sub_policy *next_sub_policy,
16942 struct mlx5_priv *priv = dev->data->dev_private;
16943 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16944 uint32_t sub_policy_idx = 0;
16945 uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
16947 struct mlx5_hrxq *hrxq;
16948 struct mlx5_flow_handle dh;
16949 struct mlx5_meter_policy_action_container *act_cnt;
16950 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16951 uint16_t sub_policy_num;
16952 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
16955 rte_spinlock_lock(&mtr_policy->sl);
16956 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16959 hrxq = mlx5_hrxq_get(dev, rss_desc[i]);
16961 rte_spinlock_unlock(&mtr_policy->sl);
16964 hrxq_idx[i] = hrxq->idx;
16966 sub_policy_num = (mtr_policy->sub_policy_num >>
16967 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16968 MLX5_MTR_SUB_POLICY_NUM_MASK;
16969 for (j = 0; j < sub_policy_num; j++) {
16970 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16973 mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
16976 if (i >= MLX5_MTR_RTE_COLORS) {
16978 * Found the sub policy table with
16979 * the same queue per color.
16981 rte_spinlock_unlock(&mtr_policy->sl);
16982 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
16983 mlx5_hrxq_release(dev, hrxq_idx[i]);
16985 return mtr_policy->sub_policys[domain][j];
16988 /* Create sub policy. */
16989 if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[0]) {
16990 /* Reuse the first pre-allocated sub_policy. */
16991 sub_policy = mtr_policy->sub_policys[domain][0];
16992 sub_policy_idx = sub_policy->idx;
16994 sub_policy = mlx5_ipool_zmalloc
16995 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16998 sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
16999 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
17000 mlx5_hrxq_release(dev, hrxq_idx[i]);
17001 goto rss_sub_policy_error;
17003 sub_policy->idx = sub_policy_idx;
17004 sub_policy->main_policy = mtr_policy;
17006 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17009 sub_policy->rix_hrxq[i] = hrxq_idx[i];
17010 if (mtr_policy->is_hierarchy) {
17011 act_cnt = &mtr_policy->act_cnt[i];
17012 act_cnt->next_sub_policy = next_sub_policy;
17013 mlx5_hrxq_release(dev, hrxq_idx[i]);
17016 * Overwrite the last action from
17017 * RSS action to Queue action.
17019 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
17022 DRV_LOG(ERR, "Failed to get policy hrxq");
17023 goto rss_sub_policy_error;
17025 act_cnt = &mtr_policy->act_cnt[i];
17026 if (act_cnt->rix_mark || act_cnt->modify_hdr) {
17027 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
17028 if (act_cnt->rix_mark)
17030 dh.fate_action = MLX5_FLOW_FATE_QUEUE;
17031 dh.rix_hrxq = hrxq_idx[i];
17032 flow_drv_rxq_flags_set(dev, &dh);
17036 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
17037 sub_policy, domain)) {
17038 DRV_LOG(ERR, "Failed to create policy "
17039 "rules for ingress domain.");
17040 goto rss_sub_policy_error;
17042 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
17043 i = (mtr_policy->sub_policy_num >>
17044 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17045 MLX5_MTR_SUB_POLICY_NUM_MASK;
17046 if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
17047 DRV_LOG(ERR, "No free sub-policy slot.");
17048 goto rss_sub_policy_error;
17050 mtr_policy->sub_policys[domain][i] = sub_policy;
17052 mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17053 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
17054 mtr_policy->sub_policy_num |=
17055 (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17056 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
17058 rte_spinlock_unlock(&mtr_policy->sl);
17061 rss_sub_policy_error:
17063 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
17064 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
17065 i = (mtr_policy->sub_policy_num >>
17066 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17067 MLX5_MTR_SUB_POLICY_NUM_MASK;
17068 mtr_policy->sub_policys[domain][i] = NULL;
17069 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17073 rte_spinlock_unlock(&mtr_policy->sl);
17078 * Find the policy table for prefix table with RSS.
17081 * Pointer to Ethernet device.
17082 * @param[in] mtr_policy
17083 * Pointer to meter policy table.
17084 * @param[in] rss_desc
17085 * Pointer to rss_desc
17087 * Pointer to table set on success, NULL otherwise and rte_errno is set.
17089 static struct mlx5_flow_meter_sub_policy *
17090 flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
17091 struct mlx5_flow_meter_policy *mtr_policy,
17092 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
17094 struct mlx5_priv *priv = dev->data->dev_private;
17095 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
17096 struct mlx5_flow_meter_info *next_fm;
17097 struct mlx5_flow_meter_policy *next_policy;
17098 struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
17099 struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
17100 struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
17101 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
17102 bool reuse_sub_policy;
17107 /* Iterate hierarchy to get all policies in this hierarchy. */
17108 policies[i++] = mtr_policy;
17109 if (!mtr_policy->is_hierarchy)
17111 if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
17112 DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
17115 next_fm = mlx5_flow_meter_find(priv,
17116 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
17118 DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
17122 mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
17124 MLX5_ASSERT(next_policy);
17125 mtr_policy = next_policy;
17129 * From last policy to the first one in hierarchy,
17130 * create / get the sub policy for each of them.
17132 sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
17136 &reuse_sub_policy);
17138 DRV_LOG(ERR, "Failed to get the sub policy.");
17141 if (!reuse_sub_policy)
17142 sub_policies[j++] = sub_policy;
17143 next_sub_policy = sub_policy;
17148 uint16_t sub_policy_num;
17150 sub_policy = sub_policies[--j];
17151 mtr_policy = sub_policy->main_policy;
17152 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
17153 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
17154 sub_policy_num = (mtr_policy->sub_policy_num >>
17155 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17156 MLX5_MTR_SUB_POLICY_NUM_MASK;
17157 mtr_policy->sub_policys[domain][sub_policy_num - 1] =
17160 mtr_policy->sub_policy_num &=
17161 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17162 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
17163 mtr_policy->sub_policy_num |=
17164 (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17165 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
17166 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17174 * Create the sub policy tag rule for all meters in hierarchy.
17177 * Pointer to Ethernet device.
17179 * Meter information table.
17180 * @param[in] src_port
17181 * The src port this extra rule should use.
17183 * The src port match item.
17184 * @param[out] error
17185 * Perform verbose error reporting if not NULL.
17187 * 0 on success, a negative errno value otherwise and rte_errno is set.
17190 flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
17191 struct mlx5_flow_meter_info *fm,
17193 const struct rte_flow_item *item,
17194 struct rte_flow_error *error)
17196 struct mlx5_priv *priv = dev->data->dev_private;
17197 struct mlx5_flow_meter_policy *mtr_policy;
17198 struct mlx5_flow_meter_sub_policy *sub_policy;
17199 struct mlx5_flow_meter_info *next_fm = NULL;
17200 struct mlx5_flow_meter_policy *next_policy;
17201 struct mlx5_flow_meter_sub_policy *next_sub_policy;
17202 struct mlx5_flow_tbl_data_entry *tbl_data;
17203 struct mlx5_sub_policy_color_rule *color_rule;
17204 struct mlx5_meter_policy_acts acts;
17205 uint32_t color_reg_c_idx;
17206 bool mtr_first = (src_port != UINT16_MAX) ? true : false;
17207 struct rte_flow_attr attr = {
17208 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
17215 uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
17218 mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
17219 MLX5_ASSERT(mtr_policy);
17220 if (!mtr_policy->is_hierarchy)
17222 next_fm = mlx5_flow_meter_find(priv,
17223 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
17225 return rte_flow_error_set(error, EINVAL,
17226 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17227 "Failed to find next meter in hierarchy.");
17229 if (!next_fm->drop_cnt)
17231 color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
17232 sub_policy = mtr_policy->sub_policys[domain][0];
17233 for (i = 0; i < RTE_COLORS; i++) {
17234 bool rule_exist = false;
17235 struct mlx5_meter_policy_action_container *act_cnt;
17237 if (i >= RTE_COLOR_YELLOW)
17239 TAILQ_FOREACH(color_rule,
17240 &sub_policy->color_rules[i], next_port)
17241 if (color_rule->src_port == src_port) {
17247 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
17248 sizeof(struct mlx5_sub_policy_color_rule),
17251 return rte_flow_error_set(error, ENOMEM,
17252 RTE_FLOW_ERROR_TYPE_ACTION,
17253 NULL, "No memory to create tag color rule.");
17254 color_rule->src_port = src_port;
17256 next_policy = mlx5_flow_meter_policy_find(dev,
17257 next_fm->policy_id, NULL);
17258 MLX5_ASSERT(next_policy);
17259 next_sub_policy = next_policy->sub_policys[domain][0];
17260 tbl_data = container_of(next_sub_policy->tbl_rsc,
17261 struct mlx5_flow_tbl_data_entry, tbl);
17262 act_cnt = &mtr_policy->act_cnt[i];
17264 acts.dv_actions[0] = next_fm->meter_action;
17265 acts.dv_actions[1] = act_cnt->modify_hdr->action;
17267 acts.dv_actions[0] = act_cnt->modify_hdr->action;
17268 acts.dv_actions[1] = next_fm->meter_action;
17270 acts.dv_actions[2] = tbl_data->jump.action;
17271 acts.actions_n = 3;
17272 if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
17276 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
17277 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
17279 &color_rule->matcher, error)) {
17280 rte_flow_error_set(error, errno,
17281 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17282 "Failed to create hierarchy meter matcher.");
17285 if (__flow_dv_create_policy_flow(dev, color_reg_c_idx,
17287 color_rule->matcher->matcher_object,
17288 acts.actions_n, acts.dv_actions,
17290 &color_rule->rule, &attr)) {
17291 rte_flow_error_set(error, errno,
17292 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17293 "Failed to create hierarchy meter rule.");
17296 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
17297 color_rule, next_port);
17301 * Recursive call to iterate all meters in hierarchy and
17302 * create needed rules.
17304 return flow_dv_meter_hierarchy_rule_create(dev, next_fm,
17305 src_port, item, error);
17308 if (color_rule->rule)
17309 mlx5_flow_os_destroy_flow(color_rule->rule);
17310 if (color_rule->matcher) {
17311 struct mlx5_flow_tbl_data_entry *tbl =
17312 container_of(color_rule->matcher->tbl,
17313 typeof(*tbl), tbl);
17314 mlx5_list_unregister(tbl->matchers,
17315 &color_rule->matcher->entry);
17317 mlx5_free(color_rule);
17320 mlx5_flow_meter_detach(priv, next_fm);
17325 * Destroy the sub policy table with RX queue.
17328 * Pointer to Ethernet device.
17329 * @param[in] mtr_policy
17330 * Pointer to meter policy table.
17333 flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
17334 struct mlx5_flow_meter_policy *mtr_policy)
17336 struct mlx5_priv *priv = dev->data->dev_private;
17337 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
17338 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
17340 uint16_t sub_policy_num, new_policy_num;
17342 rte_spinlock_lock(&mtr_policy->sl);
17343 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17344 switch (mtr_policy->act_cnt[i].fate_action) {
17345 case MLX5_FLOW_FATE_SHARED_RSS:
17346 sub_policy_num = (mtr_policy->sub_policy_num >>
17347 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17348 MLX5_MTR_SUB_POLICY_NUM_MASK;
17349 new_policy_num = sub_policy_num;
17350 for (j = 0; j < sub_policy_num; j++) {
17352 mtr_policy->sub_policys[domain][j];
17354 __flow_dv_destroy_sub_policy_rules(dev,
17357 mtr_policy->sub_policys[domain][0]) {
17358 mtr_policy->sub_policys[domain][j] =
17361 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17367 if (new_policy_num != sub_policy_num) {
17368 mtr_policy->sub_policy_num &=
17369 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17370 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
17371 mtr_policy->sub_policy_num |=
17373 MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17374 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
17377 case MLX5_FLOW_FATE_QUEUE:
17378 sub_policy = mtr_policy->sub_policys[domain][0];
17379 __flow_dv_destroy_sub_policy_rules(dev,
17383 /*Other actions without queue and do nothing*/
17387 rte_spinlock_unlock(&mtr_policy->sl);
17390 * Check whether the DR drop action is supported on the root table or not.
17392 * Create a simple flow with DR drop action on root table to validate
17393 * if DR drop action on root table is supported or not.
17396 * Pointer to rte_eth_dev structure.
17399 * 0 on success, a negative errno value otherwise and rte_errno is set.
17402 mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
17404 struct mlx5_priv *priv = dev->data->dev_private;
17405 struct mlx5_dev_ctx_shared *sh = priv->sh;
17406 struct mlx5_flow_dv_match_params mask = {
17407 .size = sizeof(mask.buf),
17409 struct mlx5_flow_dv_match_params value = {
17410 .size = sizeof(value.buf),
17412 struct mlx5dv_flow_matcher_attr dv_attr = {
17413 .type = IBV_FLOW_ATTR_NORMAL,
17415 .match_criteria_enable = 0,
17416 .match_mask = (void *)&mask,
17418 struct mlx5_flow_tbl_resource *tbl = NULL;
17419 void *matcher = NULL;
17423 tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
17427 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
17428 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
17429 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
17430 tbl->obj, &matcher);
17433 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
17434 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
17435 &sh->dr_drop_action, &flow);
17438 * If DR drop action is not supported on root table, flow create will
17439 * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
17443 (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
17444 DRV_LOG(INFO, "DR drop action is not supported in root table.");
17446 DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
17449 claim_zero(mlx5_flow_os_destroy_flow(flow));
17452 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
17454 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
17459 * Validate the batch counter support in root table.
17461 * Create a simple flow with invalid counter and drop action on root table to
17462 * validate if batch counter with offset on root table is supported or not.
17465 * Pointer to rte_eth_dev structure.
17468 * 0 on success, a negative errno value otherwise and rte_errno is set.
17471 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
17473 struct mlx5_priv *priv = dev->data->dev_private;
17474 struct mlx5_dev_ctx_shared *sh = priv->sh;
17475 struct mlx5_flow_dv_match_params mask = {
17476 .size = sizeof(mask.buf),
17478 struct mlx5_flow_dv_match_params value = {
17479 .size = sizeof(value.buf),
17481 struct mlx5dv_flow_matcher_attr dv_attr = {
17482 .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
17484 .match_criteria_enable = 0,
17485 .match_mask = (void *)&mask,
17487 void *actions[2] = { 0 };
17488 struct mlx5_flow_tbl_resource *tbl = NULL;
17489 struct mlx5_devx_obj *dcs = NULL;
17490 void *matcher = NULL;
17494 tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
17498 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
17501 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
17505 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
17506 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
17507 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
17508 tbl->obj, &matcher);
17511 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
17512 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
17516 * If batch counter with offset is not supported, the driver will not
17517 * validate the invalid offset value, flow create should success.
17518 * In this case, it means batch counter is not supported in root table.
17520 * Otherwise, if flow create is failed, counter offset is supported.
17523 DRV_LOG(INFO, "Batch counter is not supported in root "
17524 "table. Switch to fallback mode.");
17525 rte_errno = ENOTSUP;
17527 claim_zero(mlx5_flow_os_destroy_flow(flow));
17529 /* Check matcher to make sure validate fail at flow create. */
17530 if (!matcher || (matcher && errno != EINVAL))
17531 DRV_LOG(ERR, "Unexpected error in counter offset "
17532 "support detection");
17536 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
17538 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
17540 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
17542 claim_zero(mlx5_devx_cmd_destroy(dcs));
17547 * Query a devx counter.
17550 * Pointer to the Ethernet device structure.
17552 * Index to the flow counter.
17554 * Set to clear the counter statistics.
17556 * The statistics value of packets.
17557 * @param[out] bytes
17558 * The statistics value of bytes.
17561 * 0 on success, otherwise return -1.
17564 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
17565 uint64_t *pkts, uint64_t *bytes, void **action)
17567 struct mlx5_priv *priv = dev->data->dev_private;
17568 struct mlx5_flow_counter *cnt;
17569 uint64_t inn_pkts, inn_bytes;
17572 if (!priv->sh->cdev->config.devx)
17575 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
17578 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
17580 *action = cnt->action;
17582 *pkts = inn_pkts - cnt->hits;
17583 *bytes = inn_bytes - cnt->bytes;
17585 cnt->hits = inn_pkts;
17586 cnt->bytes = inn_bytes;
17592 * Get aged-out flows.
17595 * Pointer to the Ethernet device structure.
17596 * @param[in] context
17597 * The address of an array of pointers to the aged-out flows contexts.
17598 * @param[in] nb_contexts
17599 * The length of context array pointers.
17600 * @param[out] error
17601 * Perform verbose error reporting if not NULL. Initialized in case of
17605 * how many contexts get in success, otherwise negative errno value.
17606 * if nb_contexts is 0, return the amount of all aged contexts.
17607 * if nb_contexts is not 0 , return the amount of aged flows reported
17608 * in the context array.
17609 * @note: only stub for now
17612 flow_dv_get_aged_flows(struct rte_eth_dev *dev,
17614 uint32_t nb_contexts,
17615 struct rte_flow_error *error)
17617 struct mlx5_priv *priv = dev->data->dev_private;
17618 struct mlx5_age_info *age_info;
17619 struct mlx5_age_param *age_param;
17620 struct mlx5_flow_counter *counter;
17621 struct mlx5_aso_age_action *act;
17624 if (nb_contexts && !context)
17625 return rte_flow_error_set(error, EINVAL,
17626 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17627 NULL, "empty context");
17628 age_info = GET_PORT_AGE_INFO(priv);
17629 rte_spinlock_lock(&age_info->aged_sl);
17630 LIST_FOREACH(act, &age_info->aged_aso, next) {
17633 context[nb_flows - 1] =
17634 act->age_params.context;
17635 if (!(--nb_contexts))
17639 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
17642 age_param = MLX5_CNT_TO_AGE(counter);
17643 context[nb_flows - 1] = age_param->context;
17644 if (!(--nb_contexts))
17648 rte_spinlock_unlock(&age_info->aged_sl);
17649 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
17654 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
17657 flow_dv_counter_allocate(struct rte_eth_dev *dev)
17659 return flow_dv_counter_alloc(dev, 0);
17663 * Validate indirect action.
17664 * Dispatcher for action type specific validation.
17667 * Pointer to the Ethernet device structure.
17669 * Indirect action configuration.
17670 * @param[in] action
17671 * The indirect action object to validate.
17672 * @param[out] error
17673 * Perform verbose error reporting if not NULL. Initialized in case of
17677 * 0 on success, otherwise negative errno value.
17680 flow_dv_action_validate(struct rte_eth_dev *dev,
17681 const struct rte_flow_indir_action_conf *conf,
17682 const struct rte_flow_action *action,
17683 struct rte_flow_error *err)
17685 struct mlx5_priv *priv = dev->data->dev_private;
17687 RTE_SET_USED(conf);
17688 switch (action->type) {
17689 case RTE_FLOW_ACTION_TYPE_RSS:
17691 * priv->obj_ops is set according to driver capabilities.
17692 * When DevX capabilities are
17693 * sufficient, it is set to devx_obj_ops.
17694 * Otherwise, it is set to ibv_obj_ops.
17695 * ibv_obj_ops doesn't support ind_table_modify operation.
17696 * In this case the indirect RSS action can't be used.
17698 if (priv->obj_ops.ind_table_modify == NULL)
17699 return rte_flow_error_set
17701 RTE_FLOW_ERROR_TYPE_ACTION,
17703 "Indirect RSS action not supported");
17704 return mlx5_validate_action_rss(dev, action, err);
17705 case RTE_FLOW_ACTION_TYPE_AGE:
17706 if (!priv->sh->aso_age_mng)
17707 return rte_flow_error_set(err, ENOTSUP,
17708 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17710 "Indirect age action not supported");
17711 return flow_dv_validate_action_age(0, action, dev, err);
17712 case RTE_FLOW_ACTION_TYPE_COUNT:
17713 return flow_dv_validate_action_count(dev, true, 0, err);
17714 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17715 if (!priv->sh->ct_aso_en)
17716 return rte_flow_error_set(err, ENOTSUP,
17717 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17718 "ASO CT is not supported");
17719 return mlx5_validate_action_ct(dev, action->conf, err);
17721 return rte_flow_error_set(err, ENOTSUP,
17722 RTE_FLOW_ERROR_TYPE_ACTION,
17724 "action type not supported");
17729 * Check if the RSS configurations for colors of a meter policy match
17730 * each other, except the queues.
17733 * Pointer to the first RSS flow action.
17735 * Pointer to the second RSS flow action.
17738 * 0 on match, 1 on conflict.
17741 flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
17742 const struct rte_flow_action_rss *r2)
17744 if (r1 == NULL || r2 == NULL)
17746 if (!(r1->level <= 1 && r2->level <= 1) &&
17747 !(r1->level > 1 && r2->level > 1))
17749 if (r1->types != r2->types &&
17750 !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
17751 (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
17753 if (r1->key || r2->key) {
17754 const void *key1 = r1->key ? r1->key : rss_hash_default_key;
17755 const void *key2 = r2->key ? r2->key : rss_hash_default_key;
17757 if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
17764 * Validate the meter hierarchy chain for meter policy.
17767 * Pointer to the Ethernet device structure.
17768 * @param[in] meter_id
17770 * @param[in] action_flags
17771 * Holds the actions detected until now.
17772 * @param[out] is_rss
17774 * @param[out] hierarchy_domain
17775 * The domain bitmap for hierarchy policy.
17776 * @param[out] error
17777 * Perform verbose error reporting if not NULL. Initialized in case of
17781 * 0 on success, otherwise negative errno value with error set.
17784 flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
17786 uint64_t action_flags,
17788 uint8_t *hierarchy_domain,
17789 struct rte_mtr_error *error)
17791 struct mlx5_priv *priv = dev->data->dev_private;
17792 struct mlx5_flow_meter_info *fm;
17793 struct mlx5_flow_meter_policy *policy;
17796 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
17797 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
17798 return -rte_mtr_error_set(error, EINVAL,
17799 RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
17801 "Multiple fate actions not supported.");
17802 *hierarchy_domain = 0;
17804 fm = mlx5_flow_meter_find(priv, meter_id, NULL);
17806 return -rte_mtr_error_set(error, EINVAL,
17807 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17808 "Meter not found in meter hierarchy.");
17809 if (fm->def_policy)
17810 return -rte_mtr_error_set(error, EINVAL,
17811 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17812 "Non termination meter not supported in hierarchy.");
17813 policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
17814 MLX5_ASSERT(policy);
17816 * Only inherit the supported domains of the first meter in
17818 * One meter supports at least one domain.
17820 if (!*hierarchy_domain) {
17821 if (policy->transfer)
17822 *hierarchy_domain |=
17823 MLX5_MTR_DOMAIN_TRANSFER_BIT;
17824 if (policy->ingress)
17825 *hierarchy_domain |=
17826 MLX5_MTR_DOMAIN_INGRESS_BIT;
17827 if (policy->egress)
17828 *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
17830 if (!policy->is_hierarchy) {
17831 *is_rss = policy->is_rss;
17834 meter_id = policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id;
17835 if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
17836 return -rte_mtr_error_set(error, EINVAL,
17837 RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
17838 "Exceed max hierarchy meter number.");
17844 * Validate meter policy actions.
17845 * Dispatcher for action type specific validation.
17848 * Pointer to the Ethernet device structure.
17849 * @param[in] action
17850 * The meter policy action object to validate.
17852 * Attributes of flow to determine steering domain.
17853 * @param[out] error
17854 * Perform verbose error reporting if not NULL. Initialized in case of
17858 * 0 on success, otherwise negative errno value.
17861 flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
17862 const struct rte_flow_action *actions[RTE_COLORS],
17863 struct rte_flow_attr *attr,
17865 uint8_t *domain_bitmap,
17866 uint8_t *policy_mode,
17867 struct rte_mtr_error *error)
17869 struct mlx5_priv *priv = dev->data->dev_private;
17870 struct mlx5_sh_config *dev_conf = &priv->sh->config;
17871 const struct rte_flow_action *act;
17872 uint64_t action_flags[RTE_COLORS] = {0};
17875 struct rte_flow_error flow_err;
17876 uint8_t domain_color[RTE_COLORS] = {0};
17877 uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
17878 uint8_t hierarchy_domain = 0;
17879 const struct rte_flow_action_meter *mtr;
17880 bool def_green = false;
17881 bool def_yellow = false;
17882 const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
17884 if (!dev_conf->dv_esw_en)
17885 def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
17886 *domain_bitmap = def_domain;
17887 /* Red color could only support DROP action. */
17888 if (!actions[RTE_COLOR_RED] ||
17889 actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
17890 return -rte_mtr_error_set(error, ENOTSUP,
17891 RTE_MTR_ERROR_TYPE_METER_POLICY,
17892 NULL, "Red color only supports drop action.");
17894 * Check default policy actions:
17895 * Green / Yellow: no action, Red: drop action
17896 * Either G or Y will trigger default policy actions to be created.
17898 if (!actions[RTE_COLOR_GREEN] ||
17899 actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
17901 if (!actions[RTE_COLOR_YELLOW] ||
17902 actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
17904 if (def_green && def_yellow) {
17905 *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
17907 } else if (!def_green && def_yellow) {
17908 *policy_mode = MLX5_MTR_POLICY_MODE_OG;
17909 } else if (def_green && !def_yellow) {
17910 *policy_mode = MLX5_MTR_POLICY_MODE_OY;
17912 *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
17914 /* Set to empty string in case of NULL pointer access by user. */
17915 flow_err.message = "";
17916 for (i = 0; i < RTE_COLORS; i++) {
17918 for (action_flags[i] = 0, actions_n = 0;
17919 act && act->type != RTE_FLOW_ACTION_TYPE_END;
17921 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
17922 return -rte_mtr_error_set(error, ENOTSUP,
17923 RTE_MTR_ERROR_TYPE_METER_POLICY,
17924 NULL, "too many actions");
17925 switch (act->type) {
17926 case RTE_FLOW_ACTION_TYPE_PORT_ID:
17927 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17928 if (!dev_conf->dv_esw_en)
17929 return -rte_mtr_error_set(error,
17931 RTE_MTR_ERROR_TYPE_METER_POLICY,
17932 NULL, "PORT action validate check"
17933 " fail for ESW disable");
17934 ret = flow_dv_validate_action_port_id(dev,
17936 act, attr, &flow_err);
17938 return -rte_mtr_error_set(error,
17940 RTE_MTR_ERROR_TYPE_METER_POLICY,
17941 NULL, flow_err.message ?
17943 "PORT action validate check fail");
17945 action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
17947 case RTE_FLOW_ACTION_TYPE_MARK:
17948 ret = flow_dv_validate_action_mark(dev, act,
17952 return -rte_mtr_error_set(error,
17954 RTE_MTR_ERROR_TYPE_METER_POLICY,
17955 NULL, flow_err.message ?
17957 "Mark action validate check fail");
17958 if (dev_conf->dv_xmeta_en !=
17959 MLX5_XMETA_MODE_LEGACY)
17960 return -rte_mtr_error_set(error,
17962 RTE_MTR_ERROR_TYPE_METER_POLICY,
17963 NULL, "Extend MARK action is "
17964 "not supported. Please try use "
17965 "default policy for meter.");
17966 action_flags[i] |= MLX5_FLOW_ACTION_MARK;
17969 case RTE_FLOW_ACTION_TYPE_SET_TAG:
17970 ret = flow_dv_validate_action_set_tag(dev,
17971 act, action_flags[i],
17974 return -rte_mtr_error_set(error,
17976 RTE_MTR_ERROR_TYPE_METER_POLICY,
17977 NULL, flow_err.message ?
17979 "Set tag action validate check fail");
17980 action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
17983 case RTE_FLOW_ACTION_TYPE_DROP:
17984 ret = mlx5_flow_validate_action_drop
17985 (action_flags[i], attr, &flow_err);
17987 return -rte_mtr_error_set(error,
17989 RTE_MTR_ERROR_TYPE_METER_POLICY,
17990 NULL, flow_err.message ?
17992 "Drop action validate check fail");
17993 action_flags[i] |= MLX5_FLOW_ACTION_DROP;
17996 case RTE_FLOW_ACTION_TYPE_QUEUE:
17998 * Check whether extensive
17999 * metadata feature is engaged.
18001 if (dev_conf->dv_flow_en &&
18002 (dev_conf->dv_xmeta_en !=
18003 MLX5_XMETA_MODE_LEGACY) &&
18004 mlx5_flow_ext_mreg_supported(dev))
18005 return -rte_mtr_error_set(error,
18007 RTE_MTR_ERROR_TYPE_METER_POLICY,
18008 NULL, "Queue action with meta "
18009 "is not supported. Please try use "
18010 "default policy for meter.");
18011 ret = mlx5_flow_validate_action_queue(act,
18012 action_flags[i], dev,
18015 return -rte_mtr_error_set(error,
18017 RTE_MTR_ERROR_TYPE_METER_POLICY,
18018 NULL, flow_err.message ?
18020 "Queue action validate check fail");
18021 action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
18024 case RTE_FLOW_ACTION_TYPE_RSS:
18025 if (dev_conf->dv_flow_en &&
18026 (dev_conf->dv_xmeta_en !=
18027 MLX5_XMETA_MODE_LEGACY) &&
18028 mlx5_flow_ext_mreg_supported(dev))
18029 return -rte_mtr_error_set(error,
18031 RTE_MTR_ERROR_TYPE_METER_POLICY,
18032 NULL, "RSS action with meta "
18033 "is not supported. Please try use "
18034 "default policy for meter.");
18035 ret = mlx5_validate_action_rss(dev, act,
18038 return -rte_mtr_error_set(error,
18040 RTE_MTR_ERROR_TYPE_METER_POLICY,
18041 NULL, flow_err.message ?
18043 "RSS action validate check fail");
18044 action_flags[i] |= MLX5_FLOW_ACTION_RSS;
18046 /* Either G or Y will set the RSS. */
18047 rss_color[i] = act->conf;
18049 case RTE_FLOW_ACTION_TYPE_JUMP:
18050 ret = flow_dv_validate_action_jump(dev,
18051 NULL, act, action_flags[i],
18052 attr, true, &flow_err);
18054 return -rte_mtr_error_set(error,
18056 RTE_MTR_ERROR_TYPE_METER_POLICY,
18057 NULL, flow_err.message ?
18059 "Jump action validate check fail");
18061 action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
18064 * Only the last meter in the hierarchy will support
18065 * the YELLOW color steering. Then in the meter policy
18066 * actions list, there should be no other meter inside.
18068 case RTE_FLOW_ACTION_TYPE_METER:
18069 if (i != RTE_COLOR_GREEN)
18070 return -rte_mtr_error_set(error,
18072 RTE_MTR_ERROR_TYPE_METER_POLICY,
18074 "Meter hierarchy only supports GREEN color.");
18075 if (*policy_mode != MLX5_MTR_POLICY_MODE_OG)
18076 return -rte_mtr_error_set(error,
18078 RTE_MTR_ERROR_TYPE_METER_POLICY,
18080 "No yellow policy should be provided in meter hierarchy.");
18082 ret = flow_dv_validate_policy_mtr_hierarchy(dev,
18092 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
18095 return -rte_mtr_error_set(error, ENOTSUP,
18096 RTE_MTR_ERROR_TYPE_METER_POLICY,
18098 "Doesn't support optional action");
18101 if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
18102 domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
18103 } else if ((action_flags[i] &
18104 (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
18105 (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
18107 * Only support MLX5_XMETA_MODE_LEGACY
18108 * so MARK action is only in ingress domain.
18110 domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
18112 domain_color[i] = def_domain;
18113 if (action_flags[i] &&
18114 !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
18116 ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
18118 if (action_flags[i] &
18119 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
18120 domain_color[i] &= hierarchy_domain;
18122 * Non-termination actions only support NIC Tx domain.
18123 * The adjustion should be skipped when there is no
18124 * action or only END is provided. The default domains
18125 * bit-mask is set to find the MIN intersection.
18126 * The action flags checking should also be skipped.
18128 if ((def_green && i == RTE_COLOR_GREEN) ||
18129 (def_yellow && i == RTE_COLOR_YELLOW))
18132 * Validate the drop action mutual exclusion
18133 * with other actions. Drop action is mutually-exclusive
18134 * with any other action, except for Count action.
18136 if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
18137 (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
18138 return -rte_mtr_error_set(error, ENOTSUP,
18139 RTE_MTR_ERROR_TYPE_METER_POLICY,
18140 NULL, "Drop action is mutually-exclusive "
18141 "with any other action");
18143 /* Eswitch has few restrictions on using items and actions */
18144 if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
18145 if (!mlx5_flow_ext_mreg_supported(dev) &&
18146 action_flags[i] & MLX5_FLOW_ACTION_MARK)
18147 return -rte_mtr_error_set(error, ENOTSUP,
18148 RTE_MTR_ERROR_TYPE_METER_POLICY,
18149 NULL, "unsupported action MARK");
18150 if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
18151 return -rte_mtr_error_set(error, ENOTSUP,
18152 RTE_MTR_ERROR_TYPE_METER_POLICY,
18153 NULL, "unsupported action QUEUE");
18154 if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
18155 return -rte_mtr_error_set(error, ENOTSUP,
18156 RTE_MTR_ERROR_TYPE_METER_POLICY,
18157 NULL, "unsupported action RSS");
18158 if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
18159 return -rte_mtr_error_set(error, ENOTSUP,
18160 RTE_MTR_ERROR_TYPE_METER_POLICY,
18161 NULL, "no fate action is found");
18163 if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
18164 (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
18165 if ((domain_color[i] &
18166 MLX5_MTR_DOMAIN_EGRESS_BIT))
18168 MLX5_MTR_DOMAIN_EGRESS_BIT;
18170 return -rte_mtr_error_set(error,
18172 RTE_MTR_ERROR_TYPE_METER_POLICY,
18174 "no fate action is found");
18178 /* If both colors have RSS, the attributes should be the same. */
18179 if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
18180 rss_color[RTE_COLOR_YELLOW]))
18181 return -rte_mtr_error_set(error, EINVAL,
18182 RTE_MTR_ERROR_TYPE_METER_POLICY,
18183 NULL, "policy RSS attr conflict");
18184 if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
18186 /* "domain_color[C]" is non-zero for each color, default is ALL. */
18187 if (!def_green && !def_yellow &&
18188 domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
18189 !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
18190 !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
18191 return -rte_mtr_error_set(error, EINVAL,
18192 RTE_MTR_ERROR_TYPE_METER_POLICY,
18193 NULL, "policy domains conflict");
18195 * At least one color policy is listed in the actions, the domains
18196 * to be supported should be the intersection.
18198 *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
18199 domain_color[RTE_COLOR_YELLOW];
18204 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
18206 struct mlx5_priv *priv = dev->data->dev_private;
18209 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
18210 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
18215 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
18216 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
18220 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
18221 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
18229 * Discover the number of available flow priorities
18230 * by trying to create a flow with the highest priority value
18231 * for each possible number.
18236 * List of possible number of available priorities.
18237 * @param[in] vprio_n
18238 * Size of @p vprio array.
18240 * On success, number of available flow priorities.
18241 * On failure, a negative errno-style code and rte_errno is set.
18244 flow_dv_discover_priorities(struct rte_eth_dev *dev,
18245 const uint16_t *vprio, int vprio_n)
18247 struct mlx5_priv *priv = dev->data->dev_private;
18248 struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
18249 struct rte_flow_item_eth eth;
18250 struct rte_flow_item item = {
18251 .type = RTE_FLOW_ITEM_TYPE_ETH,
18255 struct mlx5_flow_dv_matcher matcher = {
18257 .size = sizeof(matcher.mask.buf),
18260 union mlx5_flow_tbl_key tbl_key;
18261 struct mlx5_flow flow;
18263 struct rte_flow_error error;
18265 int i, err, ret = -ENOTSUP;
18268 * Prepare a flow with a catch-all pattern and a drop action.
18269 * Use drop queue, because shared drop action may be unavailable.
18271 action = priv->drop_queue.hrxq->action;
18272 if (action == NULL) {
18273 DRV_LOG(ERR, "Priority discovery requires a drop action");
18274 rte_errno = ENOTSUP;
18277 memset(&flow, 0, sizeof(flow));
18278 flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
18279 if (flow.handle == NULL) {
18280 DRV_LOG(ERR, "Cannot create flow handle");
18281 rte_errno = ENOMEM;
18284 flow.ingress = true;
18285 flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
18286 flow.dv.actions[0] = action;
18287 flow.dv.actions_n = 1;
18288 memset(ð, 0, sizeof(eth));
18289 flow_dv_translate_item_eth(matcher.mask.buf, flow.dv.value.buf,
18290 &item, /* inner */ false, /* group */ 0);
18291 matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
18292 for (i = 0; i < vprio_n; i++) {
18293 /* Configure the next proposed maximum priority. */
18294 matcher.priority = vprio[i] - 1;
18295 memset(&tbl_key, 0, sizeof(tbl_key));
18296 err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
18301 /* This action is pure SW and must always succeed. */
18302 DRV_LOG(ERR, "Cannot register matcher");
18306 /* Try to apply the flow to HW. */
18307 misc_mask = flow_dv_matcher_enable(flow.dv.value.buf);
18308 __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
18309 err = mlx5_flow_os_create_flow
18310 (flow.handle->dvh.matcher->matcher_object,
18311 (void *)&flow.dv.value, flow.dv.actions_n,
18312 flow.dv.actions, &flow.handle->drv_flow);
18314 claim_zero(mlx5_flow_os_destroy_flow
18315 (flow.handle->drv_flow));
18316 flow.handle->drv_flow = NULL;
18318 claim_zero(flow_dv_matcher_release(dev, flow.handle));
18323 mlx5_ipool_free(pool, flow.handle_idx);
18324 /* Set rte_errno if no expected priority value matched. */
18330 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
18331 .validate = flow_dv_validate,
18332 .prepare = flow_dv_prepare,
18333 .translate = flow_dv_translate,
18334 .apply = flow_dv_apply,
18335 .remove = flow_dv_remove,
18336 .destroy = flow_dv_destroy,
18337 .query = flow_dv_query,
18338 .create_mtr_tbls = flow_dv_create_mtr_tbls,
18339 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
18340 .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
18341 .create_meter = flow_dv_mtr_alloc,
18342 .free_meter = flow_dv_aso_mtr_release_to_pool,
18343 .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
18344 .create_mtr_acts = flow_dv_create_mtr_policy_acts,
18345 .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
18346 .create_policy_rules = flow_dv_create_policy_rules,
18347 .destroy_policy_rules = flow_dv_destroy_policy_rules,
18348 .create_def_policy = flow_dv_create_def_policy,
18349 .destroy_def_policy = flow_dv_destroy_def_policy,
18350 .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
18351 .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
18352 .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
18353 .counter_alloc = flow_dv_counter_allocate,
18354 .counter_free = flow_dv_counter_free,
18355 .counter_query = flow_dv_counter_query,
18356 .get_aged_flows = flow_dv_get_aged_flows,
18357 .action_validate = flow_dv_action_validate,
18358 .action_create = flow_dv_action_create,
18359 .action_destroy = flow_dv_action_destroy,
18360 .action_update = flow_dv_action_update,
18361 .action_query = flow_dv_action_query,
18362 .sync_domain = flow_dv_sync_domain,
18363 .discover_priorities = flow_dv_discover_priorities,
18364 .item_create = flow_dv_item_create,
18365 .item_release = flow_dv_item_release,
18368 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */