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>
20 #include <rte_vxlan.h>
22 #include <rte_eal_paging.h>
25 #include <rte_mtr_driver.h>
26 #include <rte_tailq.h>
28 #include <mlx5_glue.h>
29 #include <mlx5_devx_cmds.h>
31 #include <mlx5_malloc.h>
33 #include "mlx5_defs.h"
35 #include "mlx5_common_os.h"
36 #include "mlx5_flow.h"
37 #include "mlx5_flow_os.h"
40 #include "rte_pmd_mlx5.h"
42 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
44 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
45 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
48 #ifndef HAVE_MLX5DV_DR_ESWITCH
49 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
50 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
54 #ifndef HAVE_MLX5DV_DR
55 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
58 /* VLAN header definitions */
59 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
60 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
61 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
62 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
63 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
78 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
79 struct mlx5_flow_tbl_resource *tbl);
82 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
83 uint32_t encap_decap_idx);
86 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
89 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss);
92 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
96 * Initialize flow attributes structure according to flow items' types.
98 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
99 * mode. For tunnel mode, the items to be modified are the outermost ones.
102 * Pointer to item specification.
104 * Pointer to flow attributes structure.
105 * @param[in] dev_flow
106 * Pointer to the sub flow.
107 * @param[in] tunnel_decap
108 * Whether action is after tunnel decapsulation.
111 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
112 struct mlx5_flow *dev_flow, bool tunnel_decap)
114 uint64_t layers = dev_flow->handle->layers;
117 * If layers is already initialized, it means this dev_flow is the
118 * suffix flow, the layers flags is set by the prefix flow. Need to
119 * use the layer flags from prefix flow as the suffix flow may not
120 * have the user defined items as the flow is split.
123 if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
125 else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
127 if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
129 else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
134 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
135 uint8_t next_protocol = 0xff;
136 switch (item->type) {
137 case RTE_FLOW_ITEM_TYPE_GRE:
138 case RTE_FLOW_ITEM_TYPE_NVGRE:
139 case RTE_FLOW_ITEM_TYPE_VXLAN:
140 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
141 case RTE_FLOW_ITEM_TYPE_GENEVE:
142 case RTE_FLOW_ITEM_TYPE_MPLS:
146 case RTE_FLOW_ITEM_TYPE_IPV4:
149 if (item->mask != NULL &&
150 ((const struct rte_flow_item_ipv4 *)
151 item->mask)->hdr.next_proto_id)
153 ((const struct rte_flow_item_ipv4 *)
154 (item->spec))->hdr.next_proto_id &
155 ((const struct rte_flow_item_ipv4 *)
156 (item->mask))->hdr.next_proto_id;
157 if ((next_protocol == IPPROTO_IPIP ||
158 next_protocol == IPPROTO_IPV6) && tunnel_decap)
161 case RTE_FLOW_ITEM_TYPE_IPV6:
164 if (item->mask != NULL &&
165 ((const struct rte_flow_item_ipv6 *)
166 item->mask)->hdr.proto)
168 ((const struct rte_flow_item_ipv6 *)
169 (item->spec))->hdr.proto &
170 ((const struct rte_flow_item_ipv6 *)
171 (item->mask))->hdr.proto;
172 if ((next_protocol == IPPROTO_IPIP ||
173 next_protocol == IPPROTO_IPV6) && tunnel_decap)
176 case RTE_FLOW_ITEM_TYPE_UDP:
180 case RTE_FLOW_ITEM_TYPE_TCP:
192 * Convert rte_mtr_color to mlx5 color.
201 rte_col_2_mlx5_col(enum rte_color rcol)
204 case RTE_COLOR_GREEN:
205 return MLX5_FLOW_COLOR_GREEN;
206 case RTE_COLOR_YELLOW:
207 return MLX5_FLOW_COLOR_YELLOW;
209 return MLX5_FLOW_COLOR_RED;
213 return MLX5_FLOW_COLOR_UNDEFINED;
216 struct field_modify_info {
217 uint32_t size; /* Size of field in protocol header, in bytes. */
218 uint32_t offset; /* Offset of field in protocol header, in bytes. */
219 enum mlx5_modification_field id;
222 struct field_modify_info modify_eth[] = {
223 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
224 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
225 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
226 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
230 struct field_modify_info modify_vlan_out_first_vid[] = {
231 /* Size in bits !!! */
232 {12, 0, MLX5_MODI_OUT_FIRST_VID},
236 struct field_modify_info modify_ipv4[] = {
237 {1, 1, MLX5_MODI_OUT_IP_DSCP},
238 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
239 {4, 12, MLX5_MODI_OUT_SIPV4},
240 {4, 16, MLX5_MODI_OUT_DIPV4},
244 struct field_modify_info modify_ipv6[] = {
245 {1, 0, MLX5_MODI_OUT_IP_DSCP},
246 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
247 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
248 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
249 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
250 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
251 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
252 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
253 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
254 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
258 struct field_modify_info modify_udp[] = {
259 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
260 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
264 struct field_modify_info modify_tcp[] = {
265 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
266 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
267 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
268 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
272 static const struct rte_flow_item *
273 mlx5_flow_find_tunnel_item(const struct rte_flow_item *item)
275 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
276 switch (item->type) {
279 case RTE_FLOW_ITEM_TYPE_VXLAN:
280 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
281 case RTE_FLOW_ITEM_TYPE_GRE:
282 case RTE_FLOW_ITEM_TYPE_MPLS:
283 case RTE_FLOW_ITEM_TYPE_NVGRE:
284 case RTE_FLOW_ITEM_TYPE_GENEVE:
286 case RTE_FLOW_ITEM_TYPE_IPV4:
287 case RTE_FLOW_ITEM_TYPE_IPV6:
288 if (item[1].type == RTE_FLOW_ITEM_TYPE_IPV4 ||
289 item[1].type == RTE_FLOW_ITEM_TYPE_IPV6)
298 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
299 uint8_t next_protocol, uint64_t *item_flags,
302 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
303 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
304 if (next_protocol == IPPROTO_IPIP) {
305 *item_flags |= MLX5_FLOW_LAYER_IPIP;
308 if (next_protocol == IPPROTO_IPV6) {
309 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
314 static inline struct mlx5_hlist *
315 flow_dv_hlist_prepare(struct mlx5_dev_ctx_shared *sh, struct mlx5_hlist **phl,
316 const char *name, uint32_t size, bool direct_key,
317 bool lcores_share, void *ctx,
318 mlx5_list_create_cb cb_create,
319 mlx5_list_match_cb cb_match,
320 mlx5_list_remove_cb cb_remove,
321 mlx5_list_clone_cb cb_clone,
322 mlx5_list_clone_free_cb cb_clone_free)
324 struct mlx5_hlist *hl;
325 struct mlx5_hlist *expected = NULL;
326 char s[MLX5_NAME_SIZE];
328 hl = __atomic_load_n(phl, __ATOMIC_SEQ_CST);
331 snprintf(s, sizeof(s), "%s_%s", sh->ibdev_name, name);
332 hl = mlx5_hlist_create(s, size, direct_key, lcores_share,
333 ctx, cb_create, cb_match, cb_remove, cb_clone,
336 DRV_LOG(ERR, "%s hash creation failed", name);
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->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1157 if (conf->dst == REG_C_0) {
1158 /* Copy to reg_c[0], within mask only. */
1159 reg_dst.offset = rte_bsf32(reg_c0);
1160 mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1163 mask = rte_cpu_to_be_32(reg_c0);
1166 return flow_dv_convert_modify_action(&item,
1167 reg_src, ®_dst, res,
1168 MLX5_MODIFICATION_TYPE_COPY,
1173 * Convert MARK action to DV specification. This routine is used
1174 * in extensive metadata only and requires metadata register to be
1175 * handled. In legacy mode hardware tag resource is engaged.
1178 * Pointer to the rte_eth_dev structure.
1180 * Pointer to MARK action specification.
1181 * @param[in,out] resource
1182 * Pointer to the modify-header resource.
1184 * Pointer to the error structure.
1187 * 0 on success, a negative errno value otherwise and rte_errno is set.
1190 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1191 const struct rte_flow_action_mark *conf,
1192 struct mlx5_flow_dv_modify_hdr_resource *resource,
1193 struct rte_flow_error *error)
1195 struct mlx5_priv *priv = dev->data->dev_private;
1196 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1197 priv->sh->dv_mark_mask);
1198 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1199 struct rte_flow_item item = {
1203 struct field_modify_info reg_c_x[] = {
1209 return rte_flow_error_set(error, EINVAL,
1210 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1211 NULL, "zero mark action mask");
1212 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1215 MLX5_ASSERT(reg > 0);
1216 if (reg == REG_C_0) {
1217 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1218 uint32_t shl_c0 = rte_bsf32(msk_c0);
1220 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1221 mask = rte_cpu_to_be_32(mask) & msk_c0;
1222 mask = rte_cpu_to_be_32(mask << shl_c0);
1224 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1225 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1226 MLX5_MODIFICATION_TYPE_SET, error);
1230 * Get metadata register index for specified steering domain.
1233 * Pointer to the rte_eth_dev structure.
1235 * Attributes of flow to determine steering domain.
1237 * Pointer to the error structure.
1240 * positive index on success, a negative errno value otherwise
1241 * and rte_errno is set.
1243 static enum modify_reg
1244 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1245 const struct rte_flow_attr *attr,
1246 struct rte_flow_error *error)
1249 mlx5_flow_get_reg_id(dev, attr->transfer ?
1253 MLX5_METADATA_RX, 0, error);
1255 return rte_flow_error_set(error,
1256 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1257 NULL, "unavailable "
1258 "metadata register");
1263 * Convert SET_META action to DV specification.
1266 * Pointer to the rte_eth_dev structure.
1267 * @param[in,out] resource
1268 * Pointer to the modify-header resource.
1270 * Attributes of flow that includes this item.
1272 * Pointer to action specification.
1274 * Pointer to the error structure.
1277 * 0 on success, a negative errno value otherwise and rte_errno is set.
1280 flow_dv_convert_action_set_meta
1281 (struct rte_eth_dev *dev,
1282 struct mlx5_flow_dv_modify_hdr_resource *resource,
1283 const struct rte_flow_attr *attr,
1284 const struct rte_flow_action_set_meta *conf,
1285 struct rte_flow_error *error)
1287 uint32_t mask = rte_cpu_to_be_32(conf->mask);
1288 uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1289 struct rte_flow_item item = {
1293 struct field_modify_info reg_c_x[] = {
1296 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1300 MLX5_ASSERT(reg != REG_NON);
1301 if (reg == REG_C_0) {
1302 struct mlx5_priv *priv = dev->data->dev_private;
1303 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1304 uint32_t shl_c0 = rte_bsf32(msk_c0);
1306 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1307 mask = rte_cpu_to_be_32(mask) & msk_c0;
1308 mask = rte_cpu_to_be_32(mask << shl_c0);
1310 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1311 /* The routine expects parameters in memory as big-endian ones. */
1312 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1313 MLX5_MODIFICATION_TYPE_SET, error);
1317 * Convert modify-header set IPv4 DSCP action to DV specification.
1319 * @param[in,out] resource
1320 * Pointer to the modify-header resource.
1322 * Pointer to action specification.
1324 * Pointer to the error structure.
1327 * 0 on success, a negative errno value otherwise and rte_errno is set.
1330 flow_dv_convert_action_modify_ipv4_dscp
1331 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1332 const struct rte_flow_action *action,
1333 struct rte_flow_error *error)
1335 const struct rte_flow_action_set_dscp *conf =
1336 (const struct rte_flow_action_set_dscp *)(action->conf);
1337 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1338 struct rte_flow_item_ipv4 ipv4;
1339 struct rte_flow_item_ipv4 ipv4_mask;
1341 memset(&ipv4, 0, sizeof(ipv4));
1342 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1343 ipv4.hdr.type_of_service = conf->dscp;
1344 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1346 item.mask = &ipv4_mask;
1347 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1348 MLX5_MODIFICATION_TYPE_SET, error);
1352 * Convert modify-header set IPv6 DSCP action to DV specification.
1354 * @param[in,out] resource
1355 * Pointer to the modify-header resource.
1357 * Pointer to action specification.
1359 * Pointer to the error structure.
1362 * 0 on success, a negative errno value otherwise and rte_errno is set.
1365 flow_dv_convert_action_modify_ipv6_dscp
1366 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1367 const struct rte_flow_action *action,
1368 struct rte_flow_error *error)
1370 const struct rte_flow_action_set_dscp *conf =
1371 (const struct rte_flow_action_set_dscp *)(action->conf);
1372 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1373 struct rte_flow_item_ipv6 ipv6;
1374 struct rte_flow_item_ipv6 ipv6_mask;
1376 memset(&ipv6, 0, sizeof(ipv6));
1377 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1379 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1380 * rdma-core only accept the DSCP bits byte aligned start from
1381 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1382 * bits in IPv6 case as rdma-core requires byte aligned value.
1384 ipv6.hdr.vtc_flow = conf->dscp;
1385 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1387 item.mask = &ipv6_mask;
1388 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1389 MLX5_MODIFICATION_TYPE_SET, error);
1393 mlx5_flow_item_field_width(struct mlx5_priv *priv,
1394 enum rte_flow_field_id field)
1397 case RTE_FLOW_FIELD_START:
1399 case RTE_FLOW_FIELD_MAC_DST:
1400 case RTE_FLOW_FIELD_MAC_SRC:
1402 case RTE_FLOW_FIELD_VLAN_TYPE:
1404 case RTE_FLOW_FIELD_VLAN_ID:
1406 case RTE_FLOW_FIELD_MAC_TYPE:
1408 case RTE_FLOW_FIELD_IPV4_DSCP:
1410 case RTE_FLOW_FIELD_IPV4_TTL:
1412 case RTE_FLOW_FIELD_IPV4_SRC:
1413 case RTE_FLOW_FIELD_IPV4_DST:
1415 case RTE_FLOW_FIELD_IPV6_DSCP:
1417 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1419 case RTE_FLOW_FIELD_IPV6_SRC:
1420 case RTE_FLOW_FIELD_IPV6_DST:
1422 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1423 case RTE_FLOW_FIELD_TCP_PORT_DST:
1425 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1426 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1428 case RTE_FLOW_FIELD_TCP_FLAGS:
1430 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1431 case RTE_FLOW_FIELD_UDP_PORT_DST:
1433 case RTE_FLOW_FIELD_VXLAN_VNI:
1434 case RTE_FLOW_FIELD_GENEVE_VNI:
1436 case RTE_FLOW_FIELD_GTP_TEID:
1437 case RTE_FLOW_FIELD_TAG:
1439 case RTE_FLOW_FIELD_MARK:
1440 return __builtin_popcount(priv->sh->dv_mark_mask);
1441 case RTE_FLOW_FIELD_META:
1442 return __builtin_popcount(priv->sh->dv_meta_mask);
1443 case RTE_FLOW_FIELD_POINTER:
1444 case RTE_FLOW_FIELD_VALUE:
1453 mlx5_flow_field_id_to_modify_info
1454 (const struct rte_flow_action_modify_data *data,
1455 struct field_modify_info *info,
1456 uint32_t *mask, uint32_t *value,
1457 uint32_t width, uint32_t dst_width,
1458 uint32_t *shift, struct rte_eth_dev *dev,
1459 const struct rte_flow_attr *attr,
1460 struct rte_flow_error *error)
1462 struct mlx5_priv *priv = dev->data->dev_private;
1466 switch (data->field) {
1467 case RTE_FLOW_FIELD_START:
1468 /* not supported yet */
1471 case RTE_FLOW_FIELD_MAC_DST:
1472 off = data->offset > 16 ? data->offset - 16 : 0;
1474 if (data->offset < 16) {
1475 info[idx] = (struct field_modify_info){2, 0,
1476 MLX5_MODI_OUT_DMAC_15_0};
1478 mask[idx] = rte_cpu_to_be_16(0xffff >>
1482 mask[idx] = RTE_BE16(0xffff);
1489 info[idx] = (struct field_modify_info){4, 4 * idx,
1490 MLX5_MODI_OUT_DMAC_47_16};
1491 mask[idx] = rte_cpu_to_be_32((0xffffffff >>
1492 (32 - width)) << off);
1494 if (data->offset < 16)
1495 info[idx++] = (struct field_modify_info){2, 0,
1496 MLX5_MODI_OUT_DMAC_15_0};
1497 info[idx] = (struct field_modify_info){4, off,
1498 MLX5_MODI_OUT_DMAC_47_16};
1501 case RTE_FLOW_FIELD_MAC_SRC:
1502 off = data->offset > 16 ? data->offset - 16 : 0;
1504 if (data->offset < 16) {
1505 info[idx] = (struct field_modify_info){2, 0,
1506 MLX5_MODI_OUT_SMAC_15_0};
1508 mask[idx] = rte_cpu_to_be_16(0xffff >>
1512 mask[idx] = RTE_BE16(0xffff);
1519 info[idx] = (struct field_modify_info){4, 4 * idx,
1520 MLX5_MODI_OUT_SMAC_47_16};
1521 mask[idx] = rte_cpu_to_be_32((0xffffffff >>
1522 (32 - width)) << off);
1524 if (data->offset < 16)
1525 info[idx++] = (struct field_modify_info){2, 0,
1526 MLX5_MODI_OUT_SMAC_15_0};
1527 info[idx] = (struct field_modify_info){4, off,
1528 MLX5_MODI_OUT_SMAC_47_16};
1531 case RTE_FLOW_FIELD_VLAN_TYPE:
1532 /* not supported yet */
1534 case RTE_FLOW_FIELD_VLAN_ID:
1535 info[idx] = (struct field_modify_info){2, 0,
1536 MLX5_MODI_OUT_FIRST_VID};
1538 mask[idx] = rte_cpu_to_be_16(0x0fff >> (12 - width));
1540 case RTE_FLOW_FIELD_MAC_TYPE:
1541 info[idx] = (struct field_modify_info){2, 0,
1542 MLX5_MODI_OUT_ETHERTYPE};
1544 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1546 case RTE_FLOW_FIELD_IPV4_DSCP:
1547 info[idx] = (struct field_modify_info){1, 0,
1548 MLX5_MODI_OUT_IP_DSCP};
1550 mask[idx] = 0x3f >> (6 - width);
1552 case RTE_FLOW_FIELD_IPV4_TTL:
1553 info[idx] = (struct field_modify_info){1, 0,
1554 MLX5_MODI_OUT_IPV4_TTL};
1556 mask[idx] = 0xff >> (8 - width);
1558 case RTE_FLOW_FIELD_IPV4_SRC:
1559 info[idx] = (struct field_modify_info){4, 0,
1560 MLX5_MODI_OUT_SIPV4};
1562 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1565 case RTE_FLOW_FIELD_IPV4_DST:
1566 info[idx] = (struct field_modify_info){4, 0,
1567 MLX5_MODI_OUT_DIPV4};
1569 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1572 case RTE_FLOW_FIELD_IPV6_DSCP:
1573 info[idx] = (struct field_modify_info){1, 0,
1574 MLX5_MODI_OUT_IP_DSCP};
1576 mask[idx] = 0x3f >> (6 - width);
1578 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1579 info[idx] = (struct field_modify_info){1, 0,
1580 MLX5_MODI_OUT_IPV6_HOPLIMIT};
1582 mask[idx] = 0xff >> (8 - width);
1584 case RTE_FLOW_FIELD_IPV6_SRC:
1586 if (data->offset < 32) {
1587 info[idx] = (struct field_modify_info){4,
1589 MLX5_MODI_OUT_SIPV6_31_0};
1592 rte_cpu_to_be_32(0xffffffff >>
1596 mask[idx] = RTE_BE32(0xffffffff);
1603 if (data->offset < 64) {
1604 info[idx] = (struct field_modify_info){4,
1606 MLX5_MODI_OUT_SIPV6_63_32};
1609 rte_cpu_to_be_32(0xffffffff >>
1613 mask[idx] = RTE_BE32(0xffffffff);
1620 if (data->offset < 96) {
1621 info[idx] = (struct field_modify_info){4,
1623 MLX5_MODI_OUT_SIPV6_95_64};
1626 rte_cpu_to_be_32(0xffffffff >>
1630 mask[idx] = RTE_BE32(0xffffffff);
1637 info[idx] = (struct field_modify_info){4, 4 * idx,
1638 MLX5_MODI_OUT_SIPV6_127_96};
1639 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1642 if (data->offset < 32)
1643 info[idx++] = (struct field_modify_info){4, 0,
1644 MLX5_MODI_OUT_SIPV6_31_0};
1645 if (data->offset < 64)
1646 info[idx++] = (struct field_modify_info){4, 0,
1647 MLX5_MODI_OUT_SIPV6_63_32};
1648 if (data->offset < 96)
1649 info[idx++] = (struct field_modify_info){4, 0,
1650 MLX5_MODI_OUT_SIPV6_95_64};
1651 if (data->offset < 128)
1652 info[idx++] = (struct field_modify_info){4, 0,
1653 MLX5_MODI_OUT_SIPV6_127_96};
1656 case RTE_FLOW_FIELD_IPV6_DST:
1658 if (data->offset < 32) {
1659 info[idx] = (struct field_modify_info){4,
1661 MLX5_MODI_OUT_DIPV6_31_0};
1664 rte_cpu_to_be_32(0xffffffff >>
1668 mask[idx] = RTE_BE32(0xffffffff);
1675 if (data->offset < 64) {
1676 info[idx] = (struct field_modify_info){4,
1678 MLX5_MODI_OUT_DIPV6_63_32};
1681 rte_cpu_to_be_32(0xffffffff >>
1685 mask[idx] = RTE_BE32(0xffffffff);
1692 if (data->offset < 96) {
1693 info[idx] = (struct field_modify_info){4,
1695 MLX5_MODI_OUT_DIPV6_95_64};
1698 rte_cpu_to_be_32(0xffffffff >>
1702 mask[idx] = RTE_BE32(0xffffffff);
1709 info[idx] = (struct field_modify_info){4, 4 * idx,
1710 MLX5_MODI_OUT_DIPV6_127_96};
1711 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1714 if (data->offset < 32)
1715 info[idx++] = (struct field_modify_info){4, 0,
1716 MLX5_MODI_OUT_DIPV6_31_0};
1717 if (data->offset < 64)
1718 info[idx++] = (struct field_modify_info){4, 0,
1719 MLX5_MODI_OUT_DIPV6_63_32};
1720 if (data->offset < 96)
1721 info[idx++] = (struct field_modify_info){4, 0,
1722 MLX5_MODI_OUT_DIPV6_95_64};
1723 if (data->offset < 128)
1724 info[idx++] = (struct field_modify_info){4, 0,
1725 MLX5_MODI_OUT_DIPV6_127_96};
1728 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1729 info[idx] = (struct field_modify_info){2, 0,
1730 MLX5_MODI_OUT_TCP_SPORT};
1732 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1734 case RTE_FLOW_FIELD_TCP_PORT_DST:
1735 info[idx] = (struct field_modify_info){2, 0,
1736 MLX5_MODI_OUT_TCP_DPORT};
1738 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1740 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1741 info[idx] = (struct field_modify_info){4, 0,
1742 MLX5_MODI_OUT_TCP_SEQ_NUM};
1744 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1747 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1748 info[idx] = (struct field_modify_info){4, 0,
1749 MLX5_MODI_OUT_TCP_ACK_NUM};
1751 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1754 case RTE_FLOW_FIELD_TCP_FLAGS:
1755 info[idx] = (struct field_modify_info){2, 0,
1756 MLX5_MODI_OUT_TCP_FLAGS};
1758 mask[idx] = rte_cpu_to_be_16(0x1ff >> (9 - width));
1760 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1761 info[idx] = (struct field_modify_info){2, 0,
1762 MLX5_MODI_OUT_UDP_SPORT};
1764 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1766 case RTE_FLOW_FIELD_UDP_PORT_DST:
1767 info[idx] = (struct field_modify_info){2, 0,
1768 MLX5_MODI_OUT_UDP_DPORT};
1770 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1772 case RTE_FLOW_FIELD_VXLAN_VNI:
1773 /* not supported yet */
1775 case RTE_FLOW_FIELD_GENEVE_VNI:
1776 /* not supported yet*/
1778 case RTE_FLOW_FIELD_GTP_TEID:
1779 info[idx] = (struct field_modify_info){4, 0,
1780 MLX5_MODI_GTP_TEID};
1782 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1785 case RTE_FLOW_FIELD_TAG:
1787 int reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
1788 data->level, error);
1791 MLX5_ASSERT(reg != REG_NON);
1792 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1793 info[idx] = (struct field_modify_info){4, 0,
1797 rte_cpu_to_be_32(0xffffffff >>
1801 case RTE_FLOW_FIELD_MARK:
1803 uint32_t mark_mask = priv->sh->dv_mark_mask;
1804 uint32_t mark_count = __builtin_popcount(mark_mask);
1805 int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
1809 MLX5_ASSERT(reg != REG_NON);
1810 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1811 info[idx] = (struct field_modify_info){4, 0,
1814 mask[idx] = rte_cpu_to_be_32((mark_mask >>
1815 (mark_count - width)) & mark_mask);
1818 case RTE_FLOW_FIELD_META:
1820 uint32_t meta_mask = priv->sh->dv_meta_mask;
1821 uint32_t meta_count = __builtin_popcount(meta_mask);
1823 rte_cpu_to_be_32(priv->sh->dv_regc0_mask);
1824 uint32_t shl_c0 = rte_bsf32(msk_c0);
1825 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1828 MLX5_ASSERT(reg != REG_NON);
1829 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1832 info[idx] = (struct field_modify_info){4, 0,
1835 mask[idx] = rte_cpu_to_be_32((meta_mask >>
1836 (meta_count - width)) & meta_mask);
1839 case RTE_FLOW_FIELD_POINTER:
1840 case RTE_FLOW_FIELD_VALUE:
1841 if (data->field == RTE_FLOW_FIELD_POINTER)
1842 memcpy(&val, (void *)(uintptr_t)data->value,
1846 for (idx = 0; idx < MLX5_ACT_MAX_MOD_FIELDS; idx++) {
1848 if (dst_width == 48) {
1849 /*special case for MAC addresses */
1850 value[idx] = rte_cpu_to_be_16(val);
1853 } else if (dst_width > 16) {
1854 value[idx] = rte_cpu_to_be_32(val);
1856 } else if (dst_width > 8) {
1857 value[idx] = rte_cpu_to_be_16(val);
1860 value[idx] = (uint8_t)val;
1864 value[idx] <<= *shift;
1877 * Convert modify_field action to DV specification.
1880 * Pointer to the rte_eth_dev structure.
1881 * @param[in,out] resource
1882 * Pointer to the modify-header resource.
1884 * Pointer to action specification.
1886 * Attributes of flow that includes this item.
1888 * Pointer to the error structure.
1891 * 0 on success, a negative errno value otherwise and rte_errno is set.
1894 flow_dv_convert_action_modify_field
1895 (struct rte_eth_dev *dev,
1896 struct mlx5_flow_dv_modify_hdr_resource *resource,
1897 const struct rte_flow_action *action,
1898 const struct rte_flow_attr *attr,
1899 struct rte_flow_error *error)
1901 struct mlx5_priv *priv = dev->data->dev_private;
1902 const struct rte_flow_action_modify_field *conf =
1903 (const struct rte_flow_action_modify_field *)(action->conf);
1904 struct rte_flow_item item;
1905 struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1907 struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1909 uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1910 uint32_t value[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1913 uint32_t dst_width = mlx5_flow_item_field_width(priv, conf->dst.field);
1915 if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1916 conf->src.field == RTE_FLOW_FIELD_VALUE) {
1917 type = MLX5_MODIFICATION_TYPE_SET;
1918 /** For SET fill the destination field (field) first. */
1919 mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1920 value, conf->width, dst_width,
1921 &shift, dev, attr, error);
1922 /** Then copy immediate value from source as per mask. */
1923 mlx5_flow_field_id_to_modify_info(&conf->src, dcopy, mask,
1924 value, conf->width, dst_width,
1925 &shift, dev, attr, error);
1928 type = MLX5_MODIFICATION_TYPE_COPY;
1929 /** For COPY fill the destination field (dcopy) without mask. */
1930 mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1931 value, conf->width, dst_width,
1932 &shift, dev, attr, error);
1933 /** Then construct the source field (field) with mask. */
1934 mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1935 value, conf->width, dst_width,
1936 &shift, dev, attr, error);
1939 return flow_dv_convert_modify_action(&item,
1940 field, dcopy, resource, type, error);
1944 * Validate MARK item.
1947 * Pointer to the rte_eth_dev structure.
1949 * Item specification.
1951 * Attributes of flow that includes this item.
1953 * Pointer to error structure.
1956 * 0 on success, a negative errno value otherwise and rte_errno is set.
1959 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1960 const struct rte_flow_item *item,
1961 const struct rte_flow_attr *attr __rte_unused,
1962 struct rte_flow_error *error)
1964 struct mlx5_priv *priv = dev->data->dev_private;
1965 struct mlx5_dev_config *config = &priv->config;
1966 const struct rte_flow_item_mark *spec = item->spec;
1967 const struct rte_flow_item_mark *mask = item->mask;
1968 const struct rte_flow_item_mark nic_mask = {
1969 .id = priv->sh->dv_mark_mask,
1973 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1974 return rte_flow_error_set(error, ENOTSUP,
1975 RTE_FLOW_ERROR_TYPE_ITEM, item,
1976 "extended metadata feature"
1978 if (!mlx5_flow_ext_mreg_supported(dev))
1979 return rte_flow_error_set(error, ENOTSUP,
1980 RTE_FLOW_ERROR_TYPE_ITEM, item,
1981 "extended metadata register"
1982 " isn't supported");
1984 return rte_flow_error_set(error, ENOTSUP,
1985 RTE_FLOW_ERROR_TYPE_ITEM, item,
1986 "extended metadata register"
1987 " isn't available");
1988 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1992 return rte_flow_error_set(error, EINVAL,
1993 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1995 "data cannot be empty");
1996 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1997 return rte_flow_error_set(error, EINVAL,
1998 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2000 "mark id exceeds the limit");
2004 return rte_flow_error_set(error, EINVAL,
2005 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2006 "mask cannot be zero");
2008 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2009 (const uint8_t *)&nic_mask,
2010 sizeof(struct rte_flow_item_mark),
2011 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2018 * Validate META item.
2021 * Pointer to the rte_eth_dev structure.
2023 * Item specification.
2025 * Attributes of flow that includes this item.
2027 * Pointer to error structure.
2030 * 0 on success, a negative errno value otherwise and rte_errno is set.
2033 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
2034 const struct rte_flow_item *item,
2035 const struct rte_flow_attr *attr,
2036 struct rte_flow_error *error)
2038 struct mlx5_priv *priv = dev->data->dev_private;
2039 struct mlx5_dev_config *config = &priv->config;
2040 const struct rte_flow_item_meta *spec = item->spec;
2041 const struct rte_flow_item_meta *mask = item->mask;
2042 struct rte_flow_item_meta nic_mask = {
2049 return rte_flow_error_set(error, EINVAL,
2050 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2052 "data cannot be empty");
2053 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2054 if (!mlx5_flow_ext_mreg_supported(dev))
2055 return rte_flow_error_set(error, ENOTSUP,
2056 RTE_FLOW_ERROR_TYPE_ITEM, item,
2057 "extended metadata register"
2058 " isn't supported");
2059 reg = flow_dv_get_metadata_reg(dev, attr, error);
2063 return rte_flow_error_set(error, ENOTSUP,
2064 RTE_FLOW_ERROR_TYPE_ITEM, item,
2065 "unavalable extended metadata register");
2067 return rte_flow_error_set(error, ENOTSUP,
2068 RTE_FLOW_ERROR_TYPE_ITEM, item,
2072 nic_mask.data = priv->sh->dv_meta_mask;
2075 return rte_flow_error_set(error, ENOTSUP,
2076 RTE_FLOW_ERROR_TYPE_ITEM, item,
2077 "extended metadata feature "
2078 "should be enabled when "
2079 "meta item is requested "
2080 "with e-switch mode ");
2082 return rte_flow_error_set(error, ENOTSUP,
2083 RTE_FLOW_ERROR_TYPE_ITEM, item,
2084 "match on metadata for ingress "
2085 "is not supported in legacy "
2089 mask = &rte_flow_item_meta_mask;
2091 return rte_flow_error_set(error, EINVAL,
2092 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2093 "mask cannot be zero");
2095 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2096 (const uint8_t *)&nic_mask,
2097 sizeof(struct rte_flow_item_meta),
2098 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2103 * Validate TAG item.
2106 * Pointer to the rte_eth_dev structure.
2108 * Item specification.
2110 * Attributes of flow that includes this item.
2112 * Pointer to error structure.
2115 * 0 on success, a negative errno value otherwise and rte_errno is set.
2118 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2119 const struct rte_flow_item *item,
2120 const struct rte_flow_attr *attr __rte_unused,
2121 struct rte_flow_error *error)
2123 const struct rte_flow_item_tag *spec = item->spec;
2124 const struct rte_flow_item_tag *mask = item->mask;
2125 const struct rte_flow_item_tag nic_mask = {
2126 .data = RTE_BE32(UINT32_MAX),
2131 if (!mlx5_flow_ext_mreg_supported(dev))
2132 return rte_flow_error_set(error, ENOTSUP,
2133 RTE_FLOW_ERROR_TYPE_ITEM, item,
2134 "extensive metadata register"
2135 " isn't supported");
2137 return rte_flow_error_set(error, EINVAL,
2138 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2140 "data cannot be empty");
2142 mask = &rte_flow_item_tag_mask;
2144 return rte_flow_error_set(error, EINVAL,
2145 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2146 "mask cannot be zero");
2148 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2149 (const uint8_t *)&nic_mask,
2150 sizeof(struct rte_flow_item_tag),
2151 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2154 if (mask->index != 0xff)
2155 return rte_flow_error_set(error, EINVAL,
2156 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2157 "partial mask for tag index"
2158 " is not supported");
2159 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2162 MLX5_ASSERT(ret != REG_NON);
2167 * Validate vport item.
2170 * Pointer to the rte_eth_dev structure.
2172 * Item specification.
2174 * Attributes of flow that includes this item.
2175 * @param[in] item_flags
2176 * Bit-fields that holds the items detected until now.
2178 * Pointer to error structure.
2181 * 0 on success, a negative errno value otherwise and rte_errno is set.
2184 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2185 const struct rte_flow_item *item,
2186 const struct rte_flow_attr *attr,
2187 uint64_t item_flags,
2188 struct rte_flow_error *error)
2190 const struct rte_flow_item_port_id *spec = item->spec;
2191 const struct rte_flow_item_port_id *mask = item->mask;
2192 const struct rte_flow_item_port_id switch_mask = {
2195 struct mlx5_priv *esw_priv;
2196 struct mlx5_priv *dev_priv;
2199 if (!attr->transfer)
2200 return rte_flow_error_set(error, EINVAL,
2201 RTE_FLOW_ERROR_TYPE_ITEM,
2203 "match on port id is valid only"
2204 " when transfer flag is enabled");
2205 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2206 return rte_flow_error_set(error, ENOTSUP,
2207 RTE_FLOW_ERROR_TYPE_ITEM, item,
2208 "multiple source ports are not"
2211 mask = &switch_mask;
2212 if (mask->id != 0xffffffff)
2213 return rte_flow_error_set(error, ENOTSUP,
2214 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2216 "no support for partial mask on"
2218 ret = mlx5_flow_item_acceptable
2219 (item, (const uint8_t *)mask,
2220 (const uint8_t *)&rte_flow_item_port_id_mask,
2221 sizeof(struct rte_flow_item_port_id),
2222 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2227 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2229 return rte_flow_error_set(error, rte_errno,
2230 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2231 "failed to obtain E-Switch info for"
2233 dev_priv = mlx5_dev_to_eswitch_info(dev);
2235 return rte_flow_error_set(error, rte_errno,
2236 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2238 "failed to obtain E-Switch info");
2239 if (esw_priv->domain_id != dev_priv->domain_id)
2240 return rte_flow_error_set(error, EINVAL,
2241 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2242 "cannot match on a port from a"
2243 " different E-Switch");
2248 * Validate VLAN item.
2251 * Item specification.
2252 * @param[in] item_flags
2253 * Bit-fields that holds the items detected until now.
2255 * Ethernet device flow is being created on.
2257 * Pointer to error structure.
2260 * 0 on success, a negative errno value otherwise and rte_errno is set.
2263 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2264 uint64_t item_flags,
2265 struct rte_eth_dev *dev,
2266 struct rte_flow_error *error)
2268 const struct rte_flow_item_vlan *mask = item->mask;
2269 const struct rte_flow_item_vlan nic_mask = {
2270 .tci = RTE_BE16(UINT16_MAX),
2271 .inner_type = RTE_BE16(UINT16_MAX),
2274 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2276 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2277 MLX5_FLOW_LAYER_INNER_L4) :
2278 (MLX5_FLOW_LAYER_OUTER_L3 |
2279 MLX5_FLOW_LAYER_OUTER_L4);
2280 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2281 MLX5_FLOW_LAYER_OUTER_VLAN;
2283 if (item_flags & vlanm)
2284 return rte_flow_error_set(error, EINVAL,
2285 RTE_FLOW_ERROR_TYPE_ITEM, item,
2286 "multiple VLAN layers not supported");
2287 else if ((item_flags & l34m) != 0)
2288 return rte_flow_error_set(error, EINVAL,
2289 RTE_FLOW_ERROR_TYPE_ITEM, item,
2290 "VLAN cannot follow L3/L4 layer");
2292 mask = &rte_flow_item_vlan_mask;
2293 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2294 (const uint8_t *)&nic_mask,
2295 sizeof(struct rte_flow_item_vlan),
2296 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2299 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2300 struct mlx5_priv *priv = dev->data->dev_private;
2302 if (priv->vmwa_context) {
2304 * Non-NULL context means we have a virtual machine
2305 * and SR-IOV enabled, we have to create VLAN interface
2306 * to make hypervisor to setup E-Switch vport
2307 * context correctly. We avoid creating the multiple
2308 * VLAN interfaces, so we cannot support VLAN tag mask.
2310 return rte_flow_error_set(error, EINVAL,
2311 RTE_FLOW_ERROR_TYPE_ITEM,
2313 "VLAN tag mask is not"
2314 " supported in virtual"
2322 * GTP flags are contained in 1 byte of the format:
2323 * -------------------------------------------
2324 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2325 * |-----------------------------------------|
2326 * | value | Version | PT | Res | E | S | PN |
2327 * -------------------------------------------
2329 * Matching is supported only for GTP flags E, S, PN.
2331 #define MLX5_GTP_FLAGS_MASK 0x07
2334 * Validate GTP item.
2337 * Pointer to the rte_eth_dev structure.
2339 * Item specification.
2340 * @param[in] item_flags
2341 * Bit-fields that holds the items detected until now.
2343 * Pointer to error structure.
2346 * 0 on success, a negative errno value otherwise and rte_errno is set.
2349 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2350 const struct rte_flow_item *item,
2351 uint64_t item_flags,
2352 struct rte_flow_error *error)
2354 struct mlx5_priv *priv = dev->data->dev_private;
2355 const struct rte_flow_item_gtp *spec = item->spec;
2356 const struct rte_flow_item_gtp *mask = item->mask;
2357 const struct rte_flow_item_gtp nic_mask = {
2358 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
2360 .teid = RTE_BE32(0xffffffff),
2363 if (!priv->config.hca_attr.tunnel_stateless_gtp)
2364 return rte_flow_error_set(error, ENOTSUP,
2365 RTE_FLOW_ERROR_TYPE_ITEM, item,
2366 "GTP support is not enabled");
2367 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2368 return rte_flow_error_set(error, ENOTSUP,
2369 RTE_FLOW_ERROR_TYPE_ITEM, item,
2370 "multiple tunnel layers not"
2372 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2373 return rte_flow_error_set(error, EINVAL,
2374 RTE_FLOW_ERROR_TYPE_ITEM, item,
2375 "no outer UDP layer found");
2377 mask = &rte_flow_item_gtp_mask;
2378 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
2379 return rte_flow_error_set(error, ENOTSUP,
2380 RTE_FLOW_ERROR_TYPE_ITEM, item,
2381 "Match is supported for GTP"
2383 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2384 (const uint8_t *)&nic_mask,
2385 sizeof(struct rte_flow_item_gtp),
2386 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2390 * Validate GTP PSC item.
2393 * Item specification.
2394 * @param[in] last_item
2395 * Previous validated item in the pattern items.
2396 * @param[in] gtp_item
2397 * Previous GTP item specification.
2399 * Pointer to flow attributes.
2401 * Pointer to error structure.
2404 * 0 on success, a negative errno value otherwise and rte_errno is set.
2407 flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2409 const struct rte_flow_item *gtp_item,
2410 const struct rte_flow_attr *attr,
2411 struct rte_flow_error *error)
2413 const struct rte_flow_item_gtp *gtp_spec;
2414 const struct rte_flow_item_gtp *gtp_mask;
2415 const struct rte_flow_item_gtp_psc *mask;
2416 const struct rte_flow_item_gtp_psc nic_mask = {
2421 if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2422 return rte_flow_error_set
2423 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2424 "GTP PSC item must be preceded with GTP item");
2425 gtp_spec = gtp_item->spec;
2426 gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2427 /* GTP spec and E flag is requested to match zero. */
2429 (gtp_mask->v_pt_rsv_flags &
2430 ~gtp_spec->v_pt_rsv_flags & MLX5_GTP_EXT_HEADER_FLAG))
2431 return rte_flow_error_set
2432 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2433 "GTP E flag must be 1 to match GTP PSC");
2434 /* Check the flow is not created in group zero. */
2435 if (!attr->transfer && !attr->group)
2436 return rte_flow_error_set
2437 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2438 "GTP PSC is not supported for group 0");
2439 /* GTP spec is here and E flag is requested to match zero. */
2442 mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2443 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2444 (const uint8_t *)&nic_mask,
2445 sizeof(struct rte_flow_item_gtp_psc),
2446 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2450 * Validate IPV4 item.
2451 * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2452 * add specific validation of fragment_offset field,
2455 * Item specification.
2456 * @param[in] item_flags
2457 * Bit-fields that holds the items detected until now.
2459 * Pointer to error structure.
2462 * 0 on success, a negative errno value otherwise and rte_errno is set.
2465 flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
2466 const struct rte_flow_item *item,
2467 uint64_t item_flags, uint64_t last_item,
2468 uint16_t ether_type, struct rte_flow_error *error)
2471 struct mlx5_priv *priv = dev->data->dev_private;
2472 const struct rte_flow_item_ipv4 *spec = item->spec;
2473 const struct rte_flow_item_ipv4 *last = item->last;
2474 const struct rte_flow_item_ipv4 *mask = item->mask;
2475 rte_be16_t fragment_offset_spec = 0;
2476 rte_be16_t fragment_offset_last = 0;
2477 struct rte_flow_item_ipv4 nic_ipv4_mask = {
2479 .src_addr = RTE_BE32(0xffffffff),
2480 .dst_addr = RTE_BE32(0xffffffff),
2481 .type_of_service = 0xff,
2482 .fragment_offset = RTE_BE16(0xffff),
2483 .next_proto_id = 0xff,
2484 .time_to_live = 0xff,
2488 if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
2489 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2490 bool ihl_cap = !tunnel ? priv->config.hca_attr.outer_ipv4_ihl :
2491 priv->config.hca_attr.inner_ipv4_ihl;
2493 return rte_flow_error_set(error, ENOTSUP,
2494 RTE_FLOW_ERROR_TYPE_ITEM,
2496 "IPV4 ihl offload not supported");
2497 nic_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
2499 ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2500 ether_type, &nic_ipv4_mask,
2501 MLX5_ITEM_RANGE_ACCEPTED, error);
2505 fragment_offset_spec = spec->hdr.fragment_offset &
2506 mask->hdr.fragment_offset;
2507 if (!fragment_offset_spec)
2510 * spec and mask are valid, enforce using full mask to make sure the
2511 * complete value is used correctly.
2513 if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2514 != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2515 return rte_flow_error_set(error, EINVAL,
2516 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2517 item, "must use full mask for"
2518 " fragment_offset");
2520 * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
2521 * indicating this is 1st fragment of fragmented packet.
2522 * This is not yet supported in MLX5, return appropriate error message.
2524 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
2525 return rte_flow_error_set(error, ENOTSUP,
2526 RTE_FLOW_ERROR_TYPE_ITEM, item,
2527 "match on first fragment not "
2529 if (fragment_offset_spec && !last)
2530 return rte_flow_error_set(error, ENOTSUP,
2531 RTE_FLOW_ERROR_TYPE_ITEM, item,
2532 "specified value not supported");
2533 /* spec and last are valid, validate the specified range. */
2534 fragment_offset_last = last->hdr.fragment_offset &
2535 mask->hdr.fragment_offset;
2537 * Match on fragment_offset spec 0x2001 and last 0x3fff
2538 * means MF is 1 and frag-offset is > 0.
2539 * This packet is fragment 2nd and onward, excluding last.
2540 * This is not yet supported in MLX5, return appropriate
2543 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
2544 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2545 return rte_flow_error_set(error, ENOTSUP,
2546 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2547 last, "match on following "
2548 "fragments not supported");
2550 * Match on fragment_offset spec 0x0001 and last 0x1fff
2551 * means MF is 0 and frag-offset is > 0.
2552 * This packet is last fragment of fragmented packet.
2553 * This is not yet supported in MLX5, return appropriate
2556 if (fragment_offset_spec == RTE_BE16(1) &&
2557 fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
2558 return rte_flow_error_set(error, ENOTSUP,
2559 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2560 last, "match on last "
2561 "fragment not supported");
2563 * Match on fragment_offset spec 0x0001 and last 0x3fff
2564 * means MF and/or frag-offset is not 0.
2565 * This is a fragmented packet.
2566 * Other range values are invalid and rejected.
2568 if (!(fragment_offset_spec == RTE_BE16(1) &&
2569 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
2570 return rte_flow_error_set(error, ENOTSUP,
2571 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2572 "specified range not supported");
2577 * Validate IPV6 fragment extension item.
2580 * Item specification.
2581 * @param[in] item_flags
2582 * Bit-fields that holds the items detected until now.
2584 * Pointer to error structure.
2587 * 0 on success, a negative errno value otherwise and rte_errno is set.
2590 flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
2591 uint64_t item_flags,
2592 struct rte_flow_error *error)
2594 const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
2595 const struct rte_flow_item_ipv6_frag_ext *last = item->last;
2596 const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
2597 rte_be16_t frag_data_spec = 0;
2598 rte_be16_t frag_data_last = 0;
2599 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2600 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2601 MLX5_FLOW_LAYER_OUTER_L4;
2603 struct rte_flow_item_ipv6_frag_ext nic_mask = {
2605 .next_header = 0xff,
2606 .frag_data = RTE_BE16(0xffff),
2610 if (item_flags & l4m)
2611 return rte_flow_error_set(error, EINVAL,
2612 RTE_FLOW_ERROR_TYPE_ITEM, item,
2613 "ipv6 fragment extension item cannot "
2615 if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
2616 (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
2617 return rte_flow_error_set(error, EINVAL,
2618 RTE_FLOW_ERROR_TYPE_ITEM, item,
2619 "ipv6 fragment extension item must "
2620 "follow ipv6 item");
2622 frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
2623 if (!frag_data_spec)
2626 * spec and mask are valid, enforce using full mask to make sure the
2627 * complete value is used correctly.
2629 if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
2630 RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2631 return rte_flow_error_set(error, EINVAL,
2632 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2633 item, "must use full mask for"
2636 * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2637 * This is 1st fragment of fragmented packet.
2639 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2640 return rte_flow_error_set(error, ENOTSUP,
2641 RTE_FLOW_ERROR_TYPE_ITEM, item,
2642 "match on first fragment not "
2644 if (frag_data_spec && !last)
2645 return rte_flow_error_set(error, EINVAL,
2646 RTE_FLOW_ERROR_TYPE_ITEM, item,
2647 "specified value not supported");
2648 ret = mlx5_flow_item_acceptable
2649 (item, (const uint8_t *)mask,
2650 (const uint8_t *)&nic_mask,
2651 sizeof(struct rte_flow_item_ipv6_frag_ext),
2652 MLX5_ITEM_RANGE_ACCEPTED, error);
2655 /* spec and last are valid, validate the specified range. */
2656 frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2658 * Match on frag_data spec 0x0009 and last 0xfff9
2659 * means M is 1 and frag-offset is > 0.
2660 * This packet is fragment 2nd and onward, excluding last.
2661 * This is not yet supported in MLX5, return appropriate
2664 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2665 RTE_IPV6_EHDR_MF_MASK) &&
2666 frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2667 return rte_flow_error_set(error, ENOTSUP,
2668 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2669 last, "match on following "
2670 "fragments not supported");
2672 * Match on frag_data spec 0x0008 and last 0xfff8
2673 * means M is 0 and frag-offset is > 0.
2674 * This packet is last fragment of fragmented packet.
2675 * This is not yet supported in MLX5, return appropriate
2678 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2679 frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2680 return rte_flow_error_set(error, ENOTSUP,
2681 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2682 last, "match on last "
2683 "fragment not supported");
2684 /* Other range values are invalid and rejected. */
2685 return rte_flow_error_set(error, EINVAL,
2686 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2687 "specified range not supported");
2691 * Validate ASO CT item.
2694 * Pointer to the rte_eth_dev structure.
2696 * Item specification.
2697 * @param[in] item_flags
2698 * Pointer to bit-fields that holds the items detected until now.
2700 * Pointer to error structure.
2703 * 0 on success, a negative errno value otherwise and rte_errno is set.
2706 flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
2707 const struct rte_flow_item *item,
2708 uint64_t *item_flags,
2709 struct rte_flow_error *error)
2711 const struct rte_flow_item_conntrack *spec = item->spec;
2712 const struct rte_flow_item_conntrack *mask = item->mask;
2716 if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
2717 return rte_flow_error_set(error, EINVAL,
2718 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2719 "Only one CT is supported");
2721 mask = &rte_flow_item_conntrack_mask;
2722 flags = spec->flags & mask->flags;
2723 if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
2724 ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
2725 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
2726 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
2727 return rte_flow_error_set(error, EINVAL,
2728 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2729 "Conflict status bits");
2730 /* State change also needs to be considered. */
2731 *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
2736 * Validate the pop VLAN action.
2739 * Pointer to the rte_eth_dev structure.
2740 * @param[in] action_flags
2741 * Holds the actions detected until now.
2743 * Pointer to the pop vlan action.
2744 * @param[in] item_flags
2745 * The items found in this flow rule.
2747 * Pointer to flow attributes.
2749 * Pointer to error structure.
2752 * 0 on success, a negative errno value otherwise and rte_errno is set.
2755 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
2756 uint64_t action_flags,
2757 const struct rte_flow_action *action,
2758 uint64_t item_flags,
2759 const struct rte_flow_attr *attr,
2760 struct rte_flow_error *error)
2762 const struct mlx5_priv *priv = dev->data->dev_private;
2763 struct mlx5_dev_ctx_shared *sh = priv->sh;
2764 bool direction_error = false;
2766 if (!priv->sh->pop_vlan_action)
2767 return rte_flow_error_set(error, ENOTSUP,
2768 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2770 "pop vlan action is not supported");
2771 /* Pop VLAN is not supported in egress except for CX6 FDB mode. */
2772 if (attr->transfer) {
2773 bool fdb_tx = priv->representor_id != UINT16_MAX;
2774 bool is_cx5 = sh->steering_format_version ==
2775 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
2777 if (fdb_tx && is_cx5)
2778 direction_error = true;
2779 } else if (attr->egress) {
2780 direction_error = true;
2782 if (direction_error)
2783 return rte_flow_error_set(error, ENOTSUP,
2784 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2786 "pop vlan action not supported for egress");
2787 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
2788 return rte_flow_error_set(error, ENOTSUP,
2789 RTE_FLOW_ERROR_TYPE_ACTION, action,
2790 "no support for multiple VLAN "
2792 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
2793 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
2794 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
2795 return rte_flow_error_set(error, ENOTSUP,
2796 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2798 "cannot pop vlan after decap without "
2799 "match on inner vlan in the flow");
2800 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
2801 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
2802 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2803 return rte_flow_error_set(error, ENOTSUP,
2804 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2806 "cannot pop vlan without a "
2807 "match on (outer) vlan in the flow");
2808 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2809 return rte_flow_error_set(error, EINVAL,
2810 RTE_FLOW_ERROR_TYPE_ACTION, action,
2811 "wrong action order, port_id should "
2812 "be after pop VLAN action");
2813 if (!attr->transfer && priv->representor)
2814 return rte_flow_error_set(error, ENOTSUP,
2815 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2816 "pop vlan action for VF representor "
2817 "not supported on NIC table");
2822 * Get VLAN default info from vlan match info.
2825 * the list of item specifications.
2827 * pointer VLAN info to fill to.
2830 * 0 on success, a negative errno value otherwise and rte_errno is set.
2833 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
2834 struct rte_vlan_hdr *vlan)
2836 const struct rte_flow_item_vlan nic_mask = {
2837 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
2838 MLX5DV_FLOW_VLAN_VID_MASK),
2839 .inner_type = RTE_BE16(0xffff),
2844 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2845 int type = items->type;
2847 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
2848 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
2851 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
2852 const struct rte_flow_item_vlan *vlan_m = items->mask;
2853 const struct rte_flow_item_vlan *vlan_v = items->spec;
2855 /* If VLAN item in pattern doesn't contain data, return here. */
2860 /* Only full match values are accepted */
2861 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
2862 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
2863 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
2865 rte_be_to_cpu_16(vlan_v->tci &
2866 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
2868 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
2869 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
2870 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
2872 rte_be_to_cpu_16(vlan_v->tci &
2873 MLX5DV_FLOW_VLAN_VID_MASK_BE);
2875 if (vlan_m->inner_type == nic_mask.inner_type)
2876 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
2877 vlan_m->inner_type);
2882 * Validate the push VLAN action.
2885 * Pointer to the rte_eth_dev structure.
2886 * @param[in] action_flags
2887 * Holds the actions detected until now.
2888 * @param[in] item_flags
2889 * The items found in this flow rule.
2891 * Pointer to the action structure.
2893 * Pointer to flow attributes
2895 * Pointer to error structure.
2898 * 0 on success, a negative errno value otherwise and rte_errno is set.
2901 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
2902 uint64_t action_flags,
2903 const struct rte_flow_item_vlan *vlan_m,
2904 const struct rte_flow_action *action,
2905 const struct rte_flow_attr *attr,
2906 struct rte_flow_error *error)
2908 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
2909 const struct mlx5_priv *priv = dev->data->dev_private;
2910 struct mlx5_dev_ctx_shared *sh = priv->sh;
2911 bool direction_error = false;
2913 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
2914 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
2915 return rte_flow_error_set(error, EINVAL,
2916 RTE_FLOW_ERROR_TYPE_ACTION, action,
2917 "invalid vlan ethertype");
2918 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2919 return rte_flow_error_set(error, EINVAL,
2920 RTE_FLOW_ERROR_TYPE_ACTION, action,
2921 "wrong action order, port_id should "
2922 "be after push VLAN");
2923 /* Push VLAN is not supported in ingress except for CX6 FDB mode. */
2924 if (attr->transfer) {
2925 bool fdb_tx = priv->representor_id != UINT16_MAX;
2926 bool is_cx5 = sh->steering_format_version ==
2927 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
2929 if (!fdb_tx && is_cx5)
2930 direction_error = true;
2931 } else if (attr->ingress) {
2932 direction_error = true;
2934 if (direction_error)
2935 return rte_flow_error_set(error, ENOTSUP,
2936 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2938 "push vlan action not supported for ingress");
2939 if (!attr->transfer && priv->representor)
2940 return rte_flow_error_set(error, ENOTSUP,
2941 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2942 "push vlan action for VF representor "
2943 "not supported on NIC table");
2945 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
2946 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
2947 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
2948 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
2949 !(mlx5_flow_find_action
2950 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
2951 return rte_flow_error_set(error, EINVAL,
2952 RTE_FLOW_ERROR_TYPE_ACTION, action,
2953 "not full match mask on VLAN PCP and "
2954 "there is no of_set_vlan_pcp action, "
2955 "push VLAN action cannot figure out "
2958 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
2959 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
2960 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
2961 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
2962 !(mlx5_flow_find_action
2963 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
2964 return rte_flow_error_set(error, EINVAL,
2965 RTE_FLOW_ERROR_TYPE_ACTION, action,
2966 "not full match mask on VLAN VID and "
2967 "there is no of_set_vlan_vid action, "
2968 "push VLAN action cannot figure out "
2975 * Validate the set VLAN PCP.
2977 * @param[in] action_flags
2978 * Holds the actions detected until now.
2979 * @param[in] actions
2980 * Pointer to the list of actions remaining in the flow rule.
2982 * Pointer to error structure.
2985 * 0 on success, a negative errno value otherwise and rte_errno is set.
2988 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2989 const struct rte_flow_action actions[],
2990 struct rte_flow_error *error)
2992 const struct rte_flow_action *action = actions;
2993 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2995 if (conf->vlan_pcp > 7)
2996 return rte_flow_error_set(error, EINVAL,
2997 RTE_FLOW_ERROR_TYPE_ACTION, action,
2998 "VLAN PCP value is too big");
2999 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
3000 return rte_flow_error_set(error, ENOTSUP,
3001 RTE_FLOW_ERROR_TYPE_ACTION, action,
3002 "set VLAN PCP action must follow "
3003 "the push VLAN action");
3004 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
3005 return rte_flow_error_set(error, ENOTSUP,
3006 RTE_FLOW_ERROR_TYPE_ACTION, action,
3007 "Multiple VLAN PCP modification are "
3009 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3010 return rte_flow_error_set(error, EINVAL,
3011 RTE_FLOW_ERROR_TYPE_ACTION, action,
3012 "wrong action order, port_id should "
3013 "be after set VLAN PCP");
3018 * Validate the set VLAN VID.
3020 * @param[in] item_flags
3021 * Holds the items detected in this rule.
3022 * @param[in] action_flags
3023 * Holds the actions detected until now.
3024 * @param[in] actions
3025 * Pointer to the list of actions remaining in the flow rule.
3027 * Pointer to error structure.
3030 * 0 on success, a negative errno value otherwise and rte_errno is set.
3033 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3034 uint64_t action_flags,
3035 const struct rte_flow_action actions[],
3036 struct rte_flow_error *error)
3038 const struct rte_flow_action *action = actions;
3039 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3041 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3042 return rte_flow_error_set(error, EINVAL,
3043 RTE_FLOW_ERROR_TYPE_ACTION, action,
3044 "VLAN VID value is too big");
3045 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3046 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3047 return rte_flow_error_set(error, ENOTSUP,
3048 RTE_FLOW_ERROR_TYPE_ACTION, action,
3049 "set VLAN VID action must follow push"
3050 " VLAN action or match on VLAN item");
3051 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3052 return rte_flow_error_set(error, ENOTSUP,
3053 RTE_FLOW_ERROR_TYPE_ACTION, action,
3054 "Multiple VLAN VID modifications are "
3056 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3057 return rte_flow_error_set(error, EINVAL,
3058 RTE_FLOW_ERROR_TYPE_ACTION, action,
3059 "wrong action order, port_id should "
3060 "be after set VLAN VID");
3065 * Validate the FLAG action.
3068 * Pointer to the rte_eth_dev structure.
3069 * @param[in] action_flags
3070 * Holds the actions detected until now.
3072 * Pointer to flow attributes
3074 * Pointer to error structure.
3077 * 0 on success, a negative errno value otherwise and rte_errno is set.
3080 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3081 uint64_t action_flags,
3082 const struct rte_flow_attr *attr,
3083 struct rte_flow_error *error)
3085 struct mlx5_priv *priv = dev->data->dev_private;
3086 struct mlx5_dev_config *config = &priv->config;
3089 /* Fall back if no extended metadata register support. */
3090 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3091 return mlx5_flow_validate_action_flag(action_flags, attr,
3093 /* Extensive metadata mode requires registers. */
3094 if (!mlx5_flow_ext_mreg_supported(dev))
3095 return rte_flow_error_set(error, ENOTSUP,
3096 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3097 "no metadata registers "
3098 "to support flag action");
3099 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3100 return rte_flow_error_set(error, ENOTSUP,
3101 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3102 "extended metadata register"
3103 " isn't available");
3104 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3107 MLX5_ASSERT(ret > 0);
3108 if (action_flags & MLX5_FLOW_ACTION_MARK)
3109 return rte_flow_error_set(error, EINVAL,
3110 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3111 "can't mark and flag in same flow");
3112 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3113 return rte_flow_error_set(error, EINVAL,
3114 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3116 " actions in same flow");
3121 * Validate MARK action.
3124 * Pointer to the rte_eth_dev structure.
3126 * Pointer to action.
3127 * @param[in] action_flags
3128 * Holds the actions detected until now.
3130 * Pointer to flow attributes
3132 * Pointer to error structure.
3135 * 0 on success, a negative errno value otherwise and rte_errno is set.
3138 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3139 const struct rte_flow_action *action,
3140 uint64_t action_flags,
3141 const struct rte_flow_attr *attr,
3142 struct rte_flow_error *error)
3144 struct mlx5_priv *priv = dev->data->dev_private;
3145 struct mlx5_dev_config *config = &priv->config;
3146 const struct rte_flow_action_mark *mark = action->conf;
3149 if (is_tunnel_offload_active(dev))
3150 return rte_flow_error_set(error, ENOTSUP,
3151 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3153 "if tunnel offload active");
3154 /* Fall back if no extended metadata register support. */
3155 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3156 return mlx5_flow_validate_action_mark(action, action_flags,
3158 /* Extensive metadata mode requires registers. */
3159 if (!mlx5_flow_ext_mreg_supported(dev))
3160 return rte_flow_error_set(error, ENOTSUP,
3161 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3162 "no metadata registers "
3163 "to support mark action");
3164 if (!priv->sh->dv_mark_mask)
3165 return rte_flow_error_set(error, ENOTSUP,
3166 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3167 "extended metadata register"
3168 " isn't available");
3169 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3172 MLX5_ASSERT(ret > 0);
3174 return rte_flow_error_set(error, EINVAL,
3175 RTE_FLOW_ERROR_TYPE_ACTION, action,
3176 "configuration cannot be null");
3177 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3178 return rte_flow_error_set(error, EINVAL,
3179 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3181 "mark id exceeds the limit");
3182 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3183 return rte_flow_error_set(error, EINVAL,
3184 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3185 "can't flag and mark in same flow");
3186 if (action_flags & MLX5_FLOW_ACTION_MARK)
3187 return rte_flow_error_set(error, EINVAL,
3188 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3189 "can't have 2 mark actions in same"
3195 * Validate SET_META action.
3198 * Pointer to the rte_eth_dev structure.
3200 * Pointer to the action structure.
3201 * @param[in] action_flags
3202 * Holds the actions detected until now.
3204 * Pointer to flow attributes
3206 * Pointer to error structure.
3209 * 0 on success, a negative errno value otherwise and rte_errno is set.
3212 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3213 const struct rte_flow_action *action,
3214 uint64_t action_flags __rte_unused,
3215 const struct rte_flow_attr *attr,
3216 struct rte_flow_error *error)
3218 const struct rte_flow_action_set_meta *conf;
3219 uint32_t nic_mask = UINT32_MAX;
3222 if (!mlx5_flow_ext_mreg_supported(dev))
3223 return rte_flow_error_set(error, ENOTSUP,
3224 RTE_FLOW_ERROR_TYPE_ACTION, action,
3225 "extended metadata register"
3226 " isn't supported");
3227 reg = flow_dv_get_metadata_reg(dev, attr, error);
3231 return rte_flow_error_set(error, ENOTSUP,
3232 RTE_FLOW_ERROR_TYPE_ACTION, action,
3233 "unavalable extended metadata register");
3234 if (reg != REG_A && reg != REG_B) {
3235 struct mlx5_priv *priv = dev->data->dev_private;
3237 nic_mask = priv->sh->dv_meta_mask;
3239 if (!(action->conf))
3240 return rte_flow_error_set(error, EINVAL,
3241 RTE_FLOW_ERROR_TYPE_ACTION, action,
3242 "configuration cannot be null");
3243 conf = (const struct rte_flow_action_set_meta *)action->conf;
3245 return rte_flow_error_set(error, EINVAL,
3246 RTE_FLOW_ERROR_TYPE_ACTION, action,
3247 "zero mask doesn't have any effect");
3248 if (conf->mask & ~nic_mask)
3249 return rte_flow_error_set(error, EINVAL,
3250 RTE_FLOW_ERROR_TYPE_ACTION, action,
3251 "meta data must be within reg C0");
3256 * Validate SET_TAG action.
3259 * Pointer to the rte_eth_dev structure.
3261 * Pointer to the action structure.
3262 * @param[in] action_flags
3263 * Holds the actions detected until now.
3265 * Pointer to flow attributes
3267 * Pointer to error structure.
3270 * 0 on success, a negative errno value otherwise and rte_errno is set.
3273 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3274 const struct rte_flow_action *action,
3275 uint64_t action_flags,
3276 const struct rte_flow_attr *attr,
3277 struct rte_flow_error *error)
3279 const struct rte_flow_action_set_tag *conf;
3280 const uint64_t terminal_action_flags =
3281 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3282 MLX5_FLOW_ACTION_RSS;
3285 if (!mlx5_flow_ext_mreg_supported(dev))
3286 return rte_flow_error_set(error, ENOTSUP,
3287 RTE_FLOW_ERROR_TYPE_ACTION, action,
3288 "extensive metadata register"
3289 " isn't supported");
3290 if (!(action->conf))
3291 return rte_flow_error_set(error, EINVAL,
3292 RTE_FLOW_ERROR_TYPE_ACTION, action,
3293 "configuration cannot be null");
3294 conf = (const struct rte_flow_action_set_tag *)action->conf;
3296 return rte_flow_error_set(error, EINVAL,
3297 RTE_FLOW_ERROR_TYPE_ACTION, action,
3298 "zero mask doesn't have any effect");
3299 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3302 if (!attr->transfer && attr->ingress &&
3303 (action_flags & terminal_action_flags))
3304 return rte_flow_error_set(error, EINVAL,
3305 RTE_FLOW_ERROR_TYPE_ACTION, action,
3306 "set_tag has no effect"
3307 " with terminal actions");
3312 * Validate count action.
3315 * Pointer to rte_eth_dev structure.
3317 * Indicator if action is shared.
3318 * @param[in] action_flags
3319 * Holds the actions detected until now.
3321 * Pointer to error structure.
3324 * 0 on success, a negative errno value otherwise and rte_errno is set.
3327 flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3328 uint64_t action_flags,
3329 struct rte_flow_error *error)
3331 struct mlx5_priv *priv = dev->data->dev_private;
3333 if (!priv->config.devx)
3335 if (action_flags & MLX5_FLOW_ACTION_COUNT)
3336 return rte_flow_error_set(error, EINVAL,
3337 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3338 "duplicate count actions set");
3339 if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
3340 !priv->sh->flow_hit_aso_en)
3341 return rte_flow_error_set(error, EINVAL,
3342 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3343 "old age and shared count combination is not supported");
3344 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3348 return rte_flow_error_set
3350 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3352 "count action not supported");
3356 * Validate the L2 encap action.
3359 * Pointer to the rte_eth_dev structure.
3360 * @param[in] action_flags
3361 * Holds the actions detected until now.
3363 * Pointer to the action structure.
3365 * Pointer to flow attributes.
3367 * Pointer to error structure.
3370 * 0 on success, a negative errno value otherwise and rte_errno is set.
3373 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3374 uint64_t action_flags,
3375 const struct rte_flow_action *action,
3376 const struct rte_flow_attr *attr,
3377 struct rte_flow_error *error)
3379 const struct mlx5_priv *priv = dev->data->dev_private;
3381 if (!(action->conf))
3382 return rte_flow_error_set(error, EINVAL,
3383 RTE_FLOW_ERROR_TYPE_ACTION, action,
3384 "configuration cannot be null");
3385 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3386 return rte_flow_error_set(error, EINVAL,
3387 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3388 "can only have a single encap action "
3390 if (!attr->transfer && priv->representor)
3391 return rte_flow_error_set(error, ENOTSUP,
3392 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3393 "encap action for VF representor "
3394 "not supported on NIC table");
3399 * Validate a decap action.
3402 * Pointer to the rte_eth_dev structure.
3403 * @param[in] action_flags
3404 * Holds the actions detected until now.
3406 * Pointer to the action structure.
3407 * @param[in] item_flags
3408 * Holds the items detected.
3410 * Pointer to flow attributes
3412 * Pointer to error structure.
3415 * 0 on success, a negative errno value otherwise and rte_errno is set.
3418 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3419 uint64_t action_flags,
3420 const struct rte_flow_action *action,
3421 const uint64_t item_flags,
3422 const struct rte_flow_attr *attr,
3423 struct rte_flow_error *error)
3425 const struct mlx5_priv *priv = dev->data->dev_private;
3427 if (priv->config.hca_attr.scatter_fcs_w_decap_disable &&
3428 !priv->config.decap_en)
3429 return rte_flow_error_set(error, ENOTSUP,
3430 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3431 "decap is not enabled");
3432 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3433 return rte_flow_error_set(error, ENOTSUP,
3434 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3436 MLX5_FLOW_ACTION_DECAP ? "can only "
3437 "have a single decap action" : "decap "
3438 "after encap is not supported");
3439 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3440 return rte_flow_error_set(error, EINVAL,
3441 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3442 "can't have decap action after"
3445 return rte_flow_error_set(error, ENOTSUP,
3446 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3448 "decap action not supported for "
3450 if (!attr->transfer && priv->representor)
3451 return rte_flow_error_set(error, ENOTSUP,
3452 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3453 "decap action for VF representor "
3454 "not supported on NIC table");
3455 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3456 !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3457 return rte_flow_error_set(error, ENOTSUP,
3458 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3459 "VXLAN item should be present for VXLAN decap");
3463 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3466 * Validate the raw encap and decap actions.
3469 * Pointer to the rte_eth_dev structure.
3471 * Pointer to the decap action.
3473 * Pointer to the encap action.
3475 * Pointer to flow attributes
3476 * @param[in/out] action_flags
3477 * Holds the actions detected until now.
3478 * @param[out] actions_n
3479 * pointer to the number of actions counter.
3481 * Pointer to the action structure.
3482 * @param[in] item_flags
3483 * Holds the items detected.
3485 * Pointer to error structure.
3488 * 0 on success, a negative errno value otherwise and rte_errno is set.
3491 flow_dv_validate_action_raw_encap_decap
3492 (struct rte_eth_dev *dev,
3493 const struct rte_flow_action_raw_decap *decap,
3494 const struct rte_flow_action_raw_encap *encap,
3495 const struct rte_flow_attr *attr, uint64_t *action_flags,
3496 int *actions_n, const struct rte_flow_action *action,
3497 uint64_t item_flags, struct rte_flow_error *error)
3499 const struct mlx5_priv *priv = dev->data->dev_private;
3502 if (encap && (!encap->size || !encap->data))
3503 return rte_flow_error_set(error, EINVAL,
3504 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3505 "raw encap data cannot be empty");
3506 if (decap && encap) {
3507 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3508 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3511 else if (encap->size <=
3512 MLX5_ENCAPSULATION_DECISION_SIZE &&
3514 MLX5_ENCAPSULATION_DECISION_SIZE)
3517 else if (encap->size >
3518 MLX5_ENCAPSULATION_DECISION_SIZE &&
3520 MLX5_ENCAPSULATION_DECISION_SIZE)
3521 /* 2 L2 actions: encap and decap. */
3524 return rte_flow_error_set(error,
3526 RTE_FLOW_ERROR_TYPE_ACTION,
3527 NULL, "unsupported too small "
3528 "raw decap and too small raw "
3529 "encap combination");
3532 ret = flow_dv_validate_action_decap(dev, *action_flags, action,
3533 item_flags, attr, error);
3536 *action_flags |= MLX5_FLOW_ACTION_DECAP;
3540 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
3541 return rte_flow_error_set(error, ENOTSUP,
3542 RTE_FLOW_ERROR_TYPE_ACTION,
3544 "small raw encap size");
3545 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
3546 return rte_flow_error_set(error, EINVAL,
3547 RTE_FLOW_ERROR_TYPE_ACTION,
3549 "more than one encap action");
3550 if (!attr->transfer && priv->representor)
3551 return rte_flow_error_set
3553 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3554 "encap action for VF representor "
3555 "not supported on NIC table");
3556 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
3563 * Validate the ASO CT action.
3566 * Pointer to the rte_eth_dev structure.
3567 * @param[in] action_flags
3568 * Holds the actions detected until now.
3569 * @param[in] item_flags
3570 * The items found in this flow rule.
3572 * Pointer to flow attributes.
3574 * Pointer to error structure.
3577 * 0 on success, a negative errno value otherwise and rte_errno is set.
3580 flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
3581 uint64_t action_flags,
3582 uint64_t item_flags,
3583 const struct rte_flow_attr *attr,
3584 struct rte_flow_error *error)
3588 if (attr->group == 0 && !attr->transfer)
3589 return rte_flow_error_set(error, ENOTSUP,
3590 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3592 "Only support non-root table");
3593 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
3594 return rte_flow_error_set(error, ENOTSUP,
3595 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3596 "CT cannot follow a fate action");
3597 if ((action_flags & MLX5_FLOW_ACTION_METER) ||
3598 (action_flags & MLX5_FLOW_ACTION_AGE))
3599 return rte_flow_error_set(error, EINVAL,
3600 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3601 "Only one ASO action is supported");
3602 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3603 return rte_flow_error_set(error, EINVAL,
3604 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3605 "Encap cannot exist before CT");
3606 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3607 return rte_flow_error_set(error, EINVAL,
3608 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3609 "Not a outer TCP packet");
3614 flow_dv_encap_decap_match_cb(void *tool_ctx __rte_unused,
3615 struct mlx5_list_entry *entry, void *cb_ctx)
3617 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3618 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3619 struct mlx5_flow_dv_encap_decap_resource *resource;
3621 resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
3623 if (resource->reformat_type == ctx_resource->reformat_type &&
3624 resource->ft_type == ctx_resource->ft_type &&
3625 resource->flags == ctx_resource->flags &&
3626 resource->size == ctx_resource->size &&
3627 !memcmp((const void *)resource->buf,
3628 (const void *)ctx_resource->buf,
3634 struct mlx5_list_entry *
3635 flow_dv_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
3637 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3638 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3639 struct mlx5dv_dr_domain *domain;
3640 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3641 struct mlx5_flow_dv_encap_decap_resource *resource;
3645 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3646 domain = sh->fdb_domain;
3647 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3648 domain = sh->rx_domain;
3650 domain = sh->tx_domain;
3651 /* Register new encap/decap resource. */
3652 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
3654 rte_flow_error_set(ctx->error, ENOMEM,
3655 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3656 "cannot allocate resource memory");
3659 *resource = *ctx_resource;
3660 resource->idx = idx;
3661 ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->ctx, domain,
3665 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
3666 rte_flow_error_set(ctx->error, ENOMEM,
3667 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3668 NULL, "cannot create action");
3672 return &resource->entry;
3675 struct mlx5_list_entry *
3676 flow_dv_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
3679 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3680 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3681 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3684 cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
3686 if (!cache_resource) {
3687 rte_flow_error_set(ctx->error, ENOMEM,
3688 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3689 "cannot allocate resource memory");
3692 memcpy(cache_resource, oentry, sizeof(*cache_resource));
3693 cache_resource->idx = idx;
3694 return &cache_resource->entry;
3698 flow_dv_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3700 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3701 struct mlx5_flow_dv_encap_decap_resource *res =
3702 container_of(entry, typeof(*res), entry);
3704 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
3708 * Find existing encap/decap resource or create and register a new one.
3710 * @param[in, out] dev
3711 * Pointer to rte_eth_dev structure.
3712 * @param[in, out] resource
3713 * Pointer to encap/decap resource.
3714 * @parm[in, out] dev_flow
3715 * Pointer to the dev_flow.
3717 * pointer to error structure.
3720 * 0 on success otherwise -errno and errno is set.
3723 flow_dv_encap_decap_resource_register
3724 (struct rte_eth_dev *dev,
3725 struct mlx5_flow_dv_encap_decap_resource *resource,
3726 struct mlx5_flow *dev_flow,
3727 struct rte_flow_error *error)
3729 struct mlx5_priv *priv = dev->data->dev_private;
3730 struct mlx5_dev_ctx_shared *sh = priv->sh;
3731 struct mlx5_list_entry *entry;
3735 uint32_t refmt_type:8;
3737 * Header reformat actions can be shared between
3738 * non-root tables. One bit to indicate non-root
3742 uint32_t reserve:15;
3745 } encap_decap_key = {
3747 .ft_type = resource->ft_type,
3748 .refmt_type = resource->reformat_type,
3749 .is_root = !!dev_flow->dv.group,
3753 struct mlx5_flow_cb_ctx ctx = {
3757 struct mlx5_hlist *encaps_decaps;
3760 encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
3762 MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
3764 flow_dv_encap_decap_create_cb,
3765 flow_dv_encap_decap_match_cb,
3766 flow_dv_encap_decap_remove_cb,
3767 flow_dv_encap_decap_clone_cb,
3768 flow_dv_encap_decap_clone_free_cb);
3769 if (unlikely(!encaps_decaps))
3771 resource->flags = dev_flow->dv.group ? 0 : 1;
3772 key64 = __rte_raw_cksum(&encap_decap_key.v32,
3773 sizeof(encap_decap_key.v32), 0);
3774 if (resource->reformat_type !=
3775 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
3777 key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
3778 entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
3781 resource = container_of(entry, typeof(*resource), entry);
3782 dev_flow->dv.encap_decap = resource;
3783 dev_flow->handle->dvh.rix_encap_decap = resource->idx;
3788 * Find existing table jump resource or create and register a new one.
3790 * @param[in, out] dev
3791 * Pointer to rte_eth_dev structure.
3792 * @param[in, out] tbl
3793 * Pointer to flow table resource.
3794 * @parm[in, out] dev_flow
3795 * Pointer to the dev_flow.
3797 * pointer to error structure.
3800 * 0 on success otherwise -errno and errno is set.
3803 flow_dv_jump_tbl_resource_register
3804 (struct rte_eth_dev *dev __rte_unused,
3805 struct mlx5_flow_tbl_resource *tbl,
3806 struct mlx5_flow *dev_flow,
3807 struct rte_flow_error *error __rte_unused)
3809 struct mlx5_flow_tbl_data_entry *tbl_data =
3810 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
3813 MLX5_ASSERT(tbl_data->jump.action);
3814 dev_flow->handle->rix_jump = tbl_data->idx;
3815 dev_flow->dv.jump = &tbl_data->jump;
3820 flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
3821 struct mlx5_list_entry *entry, void *cb_ctx)
3823 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3824 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3825 struct mlx5_flow_dv_port_id_action_resource *res =
3826 container_of(entry, typeof(*res), entry);
3828 return ref->port_id != res->port_id;
3831 struct mlx5_list_entry *
3832 flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
3834 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3835 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3836 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3837 struct mlx5_flow_dv_port_id_action_resource *resource;
3841 /* Register new port id action resource. */
3842 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3844 rte_flow_error_set(ctx->error, ENOMEM,
3845 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3846 "cannot allocate port_id action memory");
3850 ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
3854 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
3855 rte_flow_error_set(ctx->error, ENOMEM,
3856 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3857 "cannot create action");
3860 resource->idx = idx;
3861 return &resource->entry;
3864 struct mlx5_list_entry *
3865 flow_dv_port_id_clone_cb(void *tool_ctx,
3866 struct mlx5_list_entry *entry __rte_unused,
3869 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3870 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3871 struct mlx5_flow_dv_port_id_action_resource *resource;
3874 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3876 rte_flow_error_set(ctx->error, ENOMEM,
3877 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3878 "cannot allocate port_id action memory");
3881 memcpy(resource, entry, sizeof(*resource));
3882 resource->idx = idx;
3883 return &resource->entry;
3887 flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3889 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3890 struct mlx5_flow_dv_port_id_action_resource *resource =
3891 container_of(entry, typeof(*resource), entry);
3893 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
3897 * Find existing table port ID resource or create and register a new one.
3899 * @param[in, out] dev
3900 * Pointer to rte_eth_dev structure.
3901 * @param[in, out] ref
3902 * Pointer to port ID action resource reference.
3903 * @parm[in, out] dev_flow
3904 * Pointer to the dev_flow.
3906 * pointer to error structure.
3909 * 0 on success otherwise -errno and errno is set.
3912 flow_dv_port_id_action_resource_register
3913 (struct rte_eth_dev *dev,
3914 struct mlx5_flow_dv_port_id_action_resource *ref,
3915 struct mlx5_flow *dev_flow,
3916 struct rte_flow_error *error)
3918 struct mlx5_priv *priv = dev->data->dev_private;
3919 struct mlx5_list_entry *entry;
3920 struct mlx5_flow_dv_port_id_action_resource *resource;
3921 struct mlx5_flow_cb_ctx ctx = {
3926 entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
3929 resource = container_of(entry, typeof(*resource), entry);
3930 dev_flow->dv.port_id_action = resource;
3931 dev_flow->handle->rix_port_id_action = resource->idx;
3936 flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
3937 struct mlx5_list_entry *entry, void *cb_ctx)
3939 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3940 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3941 struct mlx5_flow_dv_push_vlan_action_resource *res =
3942 container_of(entry, typeof(*res), entry);
3944 return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
3947 struct mlx5_list_entry *
3948 flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
3950 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3951 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3952 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3953 struct mlx5_flow_dv_push_vlan_action_resource *resource;
3954 struct mlx5dv_dr_domain *domain;
3958 /* Register new port id action resource. */
3959 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3961 rte_flow_error_set(ctx->error, ENOMEM,
3962 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3963 "cannot allocate push_vlan action memory");
3967 if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3968 domain = sh->fdb_domain;
3969 else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3970 domain = sh->rx_domain;
3972 domain = sh->tx_domain;
3973 ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
3976 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
3977 rte_flow_error_set(ctx->error, ENOMEM,
3978 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3979 "cannot create push vlan action");
3982 resource->idx = idx;
3983 return &resource->entry;
3986 struct mlx5_list_entry *
3987 flow_dv_push_vlan_clone_cb(void *tool_ctx,
3988 struct mlx5_list_entry *entry __rte_unused,
3991 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3992 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3993 struct mlx5_flow_dv_push_vlan_action_resource *resource;
3996 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3998 rte_flow_error_set(ctx->error, ENOMEM,
3999 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4000 "cannot allocate push_vlan action memory");
4003 memcpy(resource, entry, sizeof(*resource));
4004 resource->idx = idx;
4005 return &resource->entry;
4009 flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4011 struct mlx5_dev_ctx_shared *sh = tool_ctx;
4012 struct mlx5_flow_dv_push_vlan_action_resource *resource =
4013 container_of(entry, typeof(*resource), entry);
4015 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
4019 * Find existing push vlan resource or create and register a new one.
4021 * @param [in, out] dev
4022 * Pointer to rte_eth_dev structure.
4023 * @param[in, out] ref
4024 * Pointer to port ID action resource reference.
4025 * @parm[in, out] dev_flow
4026 * Pointer to the dev_flow.
4028 * pointer to error structure.
4031 * 0 on success otherwise -errno and errno is set.
4034 flow_dv_push_vlan_action_resource_register
4035 (struct rte_eth_dev *dev,
4036 struct mlx5_flow_dv_push_vlan_action_resource *ref,
4037 struct mlx5_flow *dev_flow,
4038 struct rte_flow_error *error)
4040 struct mlx5_priv *priv = dev->data->dev_private;
4041 struct mlx5_flow_dv_push_vlan_action_resource *resource;
4042 struct mlx5_list_entry *entry;
4043 struct mlx5_flow_cb_ctx ctx = {
4048 entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4051 resource = container_of(entry, typeof(*resource), entry);
4053 dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4054 dev_flow->dv.push_vlan_res = resource;
4059 * Get the size of specific rte_flow_item_type hdr size
4061 * @param[in] item_type
4062 * Tested rte_flow_item_type.
4065 * sizeof struct item_type, 0 if void or irrelevant.
4068 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4072 switch (item_type) {
4073 case RTE_FLOW_ITEM_TYPE_ETH:
4074 retval = sizeof(struct rte_ether_hdr);
4076 case RTE_FLOW_ITEM_TYPE_VLAN:
4077 retval = sizeof(struct rte_vlan_hdr);
4079 case RTE_FLOW_ITEM_TYPE_IPV4:
4080 retval = sizeof(struct rte_ipv4_hdr);
4082 case RTE_FLOW_ITEM_TYPE_IPV6:
4083 retval = sizeof(struct rte_ipv6_hdr);
4085 case RTE_FLOW_ITEM_TYPE_UDP:
4086 retval = sizeof(struct rte_udp_hdr);
4088 case RTE_FLOW_ITEM_TYPE_TCP:
4089 retval = sizeof(struct rte_tcp_hdr);
4091 case RTE_FLOW_ITEM_TYPE_VXLAN:
4092 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4093 retval = sizeof(struct rte_vxlan_hdr);
4095 case RTE_FLOW_ITEM_TYPE_GRE:
4096 case RTE_FLOW_ITEM_TYPE_NVGRE:
4097 retval = sizeof(struct rte_gre_hdr);
4099 case RTE_FLOW_ITEM_TYPE_MPLS:
4100 retval = sizeof(struct rte_mpls_hdr);
4102 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4110 #define MLX5_ENCAP_IPV4_VERSION 0x40
4111 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4112 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4113 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4114 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4115 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4116 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4119 * Convert the encap action data from list of rte_flow_item to raw buffer
4122 * Pointer to rte_flow_item objects list.
4124 * Pointer to the output buffer.
4126 * Pointer to the output buffer size.
4128 * Pointer to the error structure.
4131 * 0 on success, a negative errno value otherwise and rte_errno is set.
4134 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4135 size_t *size, struct rte_flow_error *error)
4137 struct rte_ether_hdr *eth = NULL;
4138 struct rte_vlan_hdr *vlan = NULL;
4139 struct rte_ipv4_hdr *ipv4 = NULL;
4140 struct rte_ipv6_hdr *ipv6 = NULL;
4141 struct rte_udp_hdr *udp = NULL;
4142 struct rte_vxlan_hdr *vxlan = NULL;
4143 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4144 struct rte_gre_hdr *gre = NULL;
4146 size_t temp_size = 0;
4149 return rte_flow_error_set(error, EINVAL,
4150 RTE_FLOW_ERROR_TYPE_ACTION,
4151 NULL, "invalid empty data");
4152 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4153 len = flow_dv_get_item_hdr_len(items->type);
4154 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4155 return rte_flow_error_set(error, EINVAL,
4156 RTE_FLOW_ERROR_TYPE_ACTION,
4157 (void *)items->type,
4158 "items total size is too big"
4159 " for encap action");
4160 rte_memcpy((void *)&buf[temp_size], items->spec, len);
4161 switch (items->type) {
4162 case RTE_FLOW_ITEM_TYPE_ETH:
4163 eth = (struct rte_ether_hdr *)&buf[temp_size];
4165 case RTE_FLOW_ITEM_TYPE_VLAN:
4166 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4168 return rte_flow_error_set(error, EINVAL,
4169 RTE_FLOW_ERROR_TYPE_ACTION,
4170 (void *)items->type,
4171 "eth header not found");
4172 if (!eth->ether_type)
4173 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4175 case RTE_FLOW_ITEM_TYPE_IPV4:
4176 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4178 return rte_flow_error_set(error, EINVAL,
4179 RTE_FLOW_ERROR_TYPE_ACTION,
4180 (void *)items->type,
4181 "neither eth nor vlan"
4183 if (vlan && !vlan->eth_proto)
4184 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4185 else if (eth && !eth->ether_type)
4186 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4187 if (!ipv4->version_ihl)
4188 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4189 MLX5_ENCAP_IPV4_IHL_MIN;
4190 if (!ipv4->time_to_live)
4191 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4193 case RTE_FLOW_ITEM_TYPE_IPV6:
4194 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4196 return rte_flow_error_set(error, EINVAL,
4197 RTE_FLOW_ERROR_TYPE_ACTION,
4198 (void *)items->type,
4199 "neither eth nor vlan"
4201 if (vlan && !vlan->eth_proto)
4202 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4203 else if (eth && !eth->ether_type)
4204 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4205 if (!ipv6->vtc_flow)
4207 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4208 if (!ipv6->hop_limits)
4209 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4211 case RTE_FLOW_ITEM_TYPE_UDP:
4212 udp = (struct rte_udp_hdr *)&buf[temp_size];
4214 return rte_flow_error_set(error, EINVAL,
4215 RTE_FLOW_ERROR_TYPE_ACTION,
4216 (void *)items->type,
4217 "ip header not found");
4218 if (ipv4 && !ipv4->next_proto_id)
4219 ipv4->next_proto_id = IPPROTO_UDP;
4220 else if (ipv6 && !ipv6->proto)
4221 ipv6->proto = IPPROTO_UDP;
4223 case RTE_FLOW_ITEM_TYPE_VXLAN:
4224 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4226 return rte_flow_error_set(error, EINVAL,
4227 RTE_FLOW_ERROR_TYPE_ACTION,
4228 (void *)items->type,
4229 "udp header not found");
4231 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4232 if (!vxlan->vx_flags)
4234 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4236 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4237 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4239 return rte_flow_error_set(error, EINVAL,
4240 RTE_FLOW_ERROR_TYPE_ACTION,
4241 (void *)items->type,
4242 "udp header not found");
4243 if (!vxlan_gpe->proto)
4244 return rte_flow_error_set(error, EINVAL,
4245 RTE_FLOW_ERROR_TYPE_ACTION,
4246 (void *)items->type,
4247 "next protocol not found");
4250 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4251 if (!vxlan_gpe->vx_flags)
4252 vxlan_gpe->vx_flags =
4253 MLX5_ENCAP_VXLAN_GPE_FLAGS;
4255 case RTE_FLOW_ITEM_TYPE_GRE:
4256 case RTE_FLOW_ITEM_TYPE_NVGRE:
4257 gre = (struct rte_gre_hdr *)&buf[temp_size];
4259 return rte_flow_error_set(error, EINVAL,
4260 RTE_FLOW_ERROR_TYPE_ACTION,
4261 (void *)items->type,
4262 "next protocol not found");
4264 return rte_flow_error_set(error, EINVAL,
4265 RTE_FLOW_ERROR_TYPE_ACTION,
4266 (void *)items->type,
4267 "ip header not found");
4268 if (ipv4 && !ipv4->next_proto_id)
4269 ipv4->next_proto_id = IPPROTO_GRE;
4270 else if (ipv6 && !ipv6->proto)
4271 ipv6->proto = IPPROTO_GRE;
4273 case RTE_FLOW_ITEM_TYPE_VOID:
4276 return rte_flow_error_set(error, EINVAL,
4277 RTE_FLOW_ERROR_TYPE_ACTION,
4278 (void *)items->type,
4279 "unsupported item type");
4289 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4291 struct rte_ether_hdr *eth = NULL;
4292 struct rte_vlan_hdr *vlan = NULL;
4293 struct rte_ipv6_hdr *ipv6 = NULL;
4294 struct rte_udp_hdr *udp = NULL;
4298 eth = (struct rte_ether_hdr *)data;
4299 next_hdr = (char *)(eth + 1);
4300 proto = RTE_BE16(eth->ether_type);
4303 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4304 vlan = (struct rte_vlan_hdr *)next_hdr;
4305 proto = RTE_BE16(vlan->eth_proto);
4306 next_hdr += sizeof(struct rte_vlan_hdr);
4309 /* HW calculates IPv4 csum. no need to proceed */
4310 if (proto == RTE_ETHER_TYPE_IPV4)
4313 /* non IPv4/IPv6 header. not supported */
4314 if (proto != RTE_ETHER_TYPE_IPV6) {
4315 return rte_flow_error_set(error, ENOTSUP,
4316 RTE_FLOW_ERROR_TYPE_ACTION,
4317 NULL, "Cannot offload non IPv4/IPv6");
4320 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4322 /* ignore non UDP */
4323 if (ipv6->proto != IPPROTO_UDP)
4326 udp = (struct rte_udp_hdr *)(ipv6 + 1);
4327 udp->dgram_cksum = 0;
4333 * Convert L2 encap action to DV specification.
4336 * Pointer to rte_eth_dev structure.
4338 * Pointer to action structure.
4339 * @param[in, out] dev_flow
4340 * Pointer to the mlx5_flow.
4341 * @param[in] transfer
4342 * Mark if the flow is E-Switch flow.
4344 * Pointer to the error structure.
4347 * 0 on success, a negative errno value otherwise and rte_errno is set.
4350 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4351 const struct rte_flow_action *action,
4352 struct mlx5_flow *dev_flow,
4354 struct rte_flow_error *error)
4356 const struct rte_flow_item *encap_data;
4357 const struct rte_flow_action_raw_encap *raw_encap_data;
4358 struct mlx5_flow_dv_encap_decap_resource res = {
4360 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4361 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4362 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4365 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4367 (const struct rte_flow_action_raw_encap *)action->conf;
4368 res.size = raw_encap_data->size;
4369 memcpy(res.buf, raw_encap_data->data, res.size);
4371 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4373 ((const struct rte_flow_action_vxlan_encap *)
4374 action->conf)->definition;
4377 ((const struct rte_flow_action_nvgre_encap *)
4378 action->conf)->definition;
4379 if (flow_dv_convert_encap_data(encap_data, res.buf,
4383 if (flow_dv_zero_encap_udp_csum(res.buf, error))
4385 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4386 return rte_flow_error_set(error, EINVAL,
4387 RTE_FLOW_ERROR_TYPE_ACTION,
4388 NULL, "can't create L2 encap action");
4393 * Convert L2 decap action to DV specification.
4396 * Pointer to rte_eth_dev structure.
4397 * @param[in, out] dev_flow
4398 * Pointer to the mlx5_flow.
4399 * @param[in] transfer
4400 * Mark if the flow is E-Switch flow.
4402 * Pointer to the error structure.
4405 * 0 on success, a negative errno value otherwise and rte_errno is set.
4408 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
4409 struct mlx5_flow *dev_flow,
4411 struct rte_flow_error *error)
4413 struct mlx5_flow_dv_encap_decap_resource res = {
4416 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
4417 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4418 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
4421 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4422 return rte_flow_error_set(error, EINVAL,
4423 RTE_FLOW_ERROR_TYPE_ACTION,
4424 NULL, "can't create L2 decap action");
4429 * Convert raw decap/encap (L3 tunnel) action to DV specification.
4432 * Pointer to rte_eth_dev structure.
4434 * Pointer to action structure.
4435 * @param[in, out] dev_flow
4436 * Pointer to the mlx5_flow.
4438 * Pointer to the flow attributes.
4440 * Pointer to the error structure.
4443 * 0 on success, a negative errno value otherwise and rte_errno is set.
4446 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
4447 const struct rte_flow_action *action,
4448 struct mlx5_flow *dev_flow,
4449 const struct rte_flow_attr *attr,
4450 struct rte_flow_error *error)
4452 const struct rte_flow_action_raw_encap *encap_data;
4453 struct mlx5_flow_dv_encap_decap_resource res;
4455 memset(&res, 0, sizeof(res));
4456 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
4457 res.size = encap_data->size;
4458 memcpy(res.buf, encap_data->data, res.size);
4459 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
4460 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
4461 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
4463 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4465 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4466 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4467 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4468 return rte_flow_error_set(error, EINVAL,
4469 RTE_FLOW_ERROR_TYPE_ACTION,
4470 NULL, "can't create encap action");
4475 * Create action push VLAN.
4478 * Pointer to rte_eth_dev structure.
4480 * Pointer to the flow attributes.
4482 * Pointer to the vlan to push to the Ethernet header.
4483 * @param[in, out] dev_flow
4484 * Pointer to the mlx5_flow.
4486 * Pointer to the error structure.
4489 * 0 on success, a negative errno value otherwise and rte_errno is set.
4492 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
4493 const struct rte_flow_attr *attr,
4494 const struct rte_vlan_hdr *vlan,
4495 struct mlx5_flow *dev_flow,
4496 struct rte_flow_error *error)
4498 struct mlx5_flow_dv_push_vlan_action_resource res;
4500 memset(&res, 0, sizeof(res));
4502 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
4505 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4507 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4508 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4509 return flow_dv_push_vlan_action_resource_register
4510 (dev, &res, dev_flow, error);
4514 * Validate the modify-header actions.
4516 * @param[in] action_flags
4517 * Holds the actions detected until now.
4519 * Pointer to the modify action.
4521 * Pointer to error structure.
4524 * 0 on success, a negative errno value otherwise and rte_errno is set.
4527 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
4528 const struct rte_flow_action *action,
4529 struct rte_flow_error *error)
4531 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
4532 return rte_flow_error_set(error, EINVAL,
4533 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4534 NULL, "action configuration not set");
4535 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4536 return rte_flow_error_set(error, EINVAL,
4537 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4538 "can't have encap action before"
4544 * Validate the modify-header MAC address actions.
4546 * @param[in] action_flags
4547 * Holds the actions detected until now.
4549 * Pointer to the modify action.
4550 * @param[in] item_flags
4551 * Holds the items detected.
4553 * Pointer to error structure.
4556 * 0 on success, a negative errno value otherwise and rte_errno is set.
4559 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
4560 const struct rte_flow_action *action,
4561 const uint64_t item_flags,
4562 struct rte_flow_error *error)
4566 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4568 if (!(item_flags & MLX5_FLOW_LAYER_L2))
4569 return rte_flow_error_set(error, EINVAL,
4570 RTE_FLOW_ERROR_TYPE_ACTION,
4572 "no L2 item in pattern");
4578 * Validate the modify-header IPv4 address actions.
4580 * @param[in] action_flags
4581 * Holds the actions detected until now.
4583 * Pointer to the modify action.
4584 * @param[in] item_flags
4585 * Holds the items detected.
4587 * Pointer to error structure.
4590 * 0 on success, a negative errno value otherwise and rte_errno is set.
4593 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
4594 const struct rte_flow_action *action,
4595 const uint64_t item_flags,
4596 struct rte_flow_error *error)
4601 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4603 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4604 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4605 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4606 if (!(item_flags & layer))
4607 return rte_flow_error_set(error, EINVAL,
4608 RTE_FLOW_ERROR_TYPE_ACTION,
4610 "no ipv4 item in pattern");
4616 * Validate the modify-header IPv6 address actions.
4618 * @param[in] action_flags
4619 * Holds the actions detected until now.
4621 * Pointer to the modify action.
4622 * @param[in] item_flags
4623 * Holds the items detected.
4625 * Pointer to error structure.
4628 * 0 on success, a negative errno value otherwise and rte_errno is set.
4631 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
4632 const struct rte_flow_action *action,
4633 const uint64_t item_flags,
4634 struct rte_flow_error *error)
4639 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4641 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4642 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4643 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4644 if (!(item_flags & layer))
4645 return rte_flow_error_set(error, EINVAL,
4646 RTE_FLOW_ERROR_TYPE_ACTION,
4648 "no ipv6 item in pattern");
4654 * Validate the modify-header TP actions.
4656 * @param[in] action_flags
4657 * Holds the actions detected until now.
4659 * Pointer to the modify action.
4660 * @param[in] item_flags
4661 * Holds the items detected.
4663 * Pointer to error structure.
4666 * 0 on success, a negative errno value otherwise and rte_errno is set.
4669 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
4670 const struct rte_flow_action *action,
4671 const uint64_t item_flags,
4672 struct rte_flow_error *error)
4677 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4679 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4680 MLX5_FLOW_LAYER_INNER_L4 :
4681 MLX5_FLOW_LAYER_OUTER_L4;
4682 if (!(item_flags & layer))
4683 return rte_flow_error_set(error, EINVAL,
4684 RTE_FLOW_ERROR_TYPE_ACTION,
4685 NULL, "no transport layer "
4692 * Validate the modify-header actions of increment/decrement
4693 * TCP Sequence-number.
4695 * @param[in] action_flags
4696 * Holds the actions detected until now.
4698 * Pointer to the modify action.
4699 * @param[in] item_flags
4700 * Holds the items detected.
4702 * Pointer to error structure.
4705 * 0 on success, a negative errno value otherwise and rte_errno is set.
4708 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
4709 const struct rte_flow_action *action,
4710 const uint64_t item_flags,
4711 struct rte_flow_error *error)
4716 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4718 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4719 MLX5_FLOW_LAYER_INNER_L4_TCP :
4720 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4721 if (!(item_flags & layer))
4722 return rte_flow_error_set(error, EINVAL,
4723 RTE_FLOW_ERROR_TYPE_ACTION,
4724 NULL, "no TCP item in"
4726 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
4727 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
4728 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
4729 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
4730 return rte_flow_error_set(error, EINVAL,
4731 RTE_FLOW_ERROR_TYPE_ACTION,
4733 "cannot decrease and increase"
4734 " TCP sequence number"
4735 " at the same time");
4741 * Validate the modify-header actions of increment/decrement
4742 * TCP Acknowledgment number.
4744 * @param[in] action_flags
4745 * Holds the actions detected until now.
4747 * Pointer to the modify action.
4748 * @param[in] item_flags
4749 * Holds the items detected.
4751 * Pointer to error structure.
4754 * 0 on success, a negative errno value otherwise and rte_errno is set.
4757 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
4758 const struct rte_flow_action *action,
4759 const uint64_t item_flags,
4760 struct rte_flow_error *error)
4765 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4767 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4768 MLX5_FLOW_LAYER_INNER_L4_TCP :
4769 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4770 if (!(item_flags & layer))
4771 return rte_flow_error_set(error, EINVAL,
4772 RTE_FLOW_ERROR_TYPE_ACTION,
4773 NULL, "no TCP item in"
4775 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
4776 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
4777 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
4778 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
4779 return rte_flow_error_set(error, EINVAL,
4780 RTE_FLOW_ERROR_TYPE_ACTION,
4782 "cannot decrease and increase"
4783 " TCP acknowledgment number"
4784 " at the same time");
4790 * Validate the modify-header TTL actions.
4792 * @param[in] action_flags
4793 * Holds the actions detected until now.
4795 * Pointer to the modify action.
4796 * @param[in] item_flags
4797 * Holds the items detected.
4799 * Pointer to error structure.
4802 * 0 on success, a negative errno value otherwise and rte_errno is set.
4805 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
4806 const struct rte_flow_action *action,
4807 const uint64_t item_flags,
4808 struct rte_flow_error *error)
4813 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4815 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4816 MLX5_FLOW_LAYER_INNER_L3 :
4817 MLX5_FLOW_LAYER_OUTER_L3;
4818 if (!(item_flags & layer))
4819 return rte_flow_error_set(error, EINVAL,
4820 RTE_FLOW_ERROR_TYPE_ACTION,
4822 "no IP protocol in pattern");
4828 * Validate the generic modify field actions.
4830 * Pointer to the rte_eth_dev structure.
4831 * @param[in] action_flags
4832 * Holds the actions detected until now.
4834 * Pointer to the modify action.
4836 * Pointer to the flow attributes.
4838 * Pointer to error structure.
4841 * Number of header fields to modify (0 or more) on success,
4842 * a negative errno value otherwise and rte_errno is set.
4845 flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
4846 const uint64_t action_flags,
4847 const struct rte_flow_action *action,
4848 const struct rte_flow_attr *attr,
4849 struct rte_flow_error *error)
4852 struct mlx5_priv *priv = dev->data->dev_private;
4853 struct mlx5_dev_config *config = &priv->config;
4854 const struct rte_flow_action_modify_field *action_modify_field =
4856 uint32_t dst_width = mlx5_flow_item_field_width(priv,
4857 action_modify_field->dst.field);
4858 uint32_t src_width = mlx5_flow_item_field_width(priv,
4859 action_modify_field->src.field);
4861 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4865 if (action_modify_field->width == 0)
4866 return rte_flow_error_set(error, EINVAL,
4867 RTE_FLOW_ERROR_TYPE_ACTION, action,
4868 "no bits are requested to be modified");
4869 else if (action_modify_field->width > dst_width ||
4870 action_modify_field->width > src_width)
4871 return rte_flow_error_set(error, EINVAL,
4872 RTE_FLOW_ERROR_TYPE_ACTION, action,
4873 "cannot modify more bits than"
4874 " the width of a field");
4875 if (action_modify_field->dst.field != RTE_FLOW_FIELD_VALUE &&
4876 action_modify_field->dst.field != RTE_FLOW_FIELD_POINTER) {
4877 if ((action_modify_field->dst.offset +
4878 action_modify_field->width > dst_width) ||
4879 (action_modify_field->dst.offset % 32))
4880 return rte_flow_error_set(error, EINVAL,
4881 RTE_FLOW_ERROR_TYPE_ACTION, action,
4882 "destination offset is too big"
4883 " or not aligned to 4 bytes");
4884 if (action_modify_field->dst.level &&
4885 action_modify_field->dst.field != RTE_FLOW_FIELD_TAG)
4886 return rte_flow_error_set(error, ENOTSUP,
4887 RTE_FLOW_ERROR_TYPE_ACTION, action,
4888 "inner header fields modification"
4889 " is not supported");
4891 if (action_modify_field->src.field != RTE_FLOW_FIELD_VALUE &&
4892 action_modify_field->src.field != RTE_FLOW_FIELD_POINTER) {
4893 if (!attr->transfer && !attr->group)
4894 return rte_flow_error_set(error, ENOTSUP,
4895 RTE_FLOW_ERROR_TYPE_ACTION, action,
4896 "modify field action is not"
4897 " supported for group 0");
4898 if ((action_modify_field->src.offset +
4899 action_modify_field->width > src_width) ||
4900 (action_modify_field->src.offset % 32))
4901 return rte_flow_error_set(error, EINVAL,
4902 RTE_FLOW_ERROR_TYPE_ACTION, action,
4903 "source offset is too big"
4904 " or not aligned to 4 bytes");
4905 if (action_modify_field->src.level &&
4906 action_modify_field->src.field != RTE_FLOW_FIELD_TAG)
4907 return rte_flow_error_set(error, ENOTSUP,
4908 RTE_FLOW_ERROR_TYPE_ACTION, action,
4909 "inner header fields modification"
4910 " is not supported");
4912 if ((action_modify_field->dst.field ==
4913 action_modify_field->src.field) &&
4914 (action_modify_field->dst.level ==
4915 action_modify_field->src.level))
4916 return rte_flow_error_set(error, EINVAL,
4917 RTE_FLOW_ERROR_TYPE_ACTION, action,
4918 "source and destination fields"
4919 " cannot be the same");
4920 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VALUE ||
4921 action_modify_field->dst.field == RTE_FLOW_FIELD_POINTER ||
4922 action_modify_field->dst.field == RTE_FLOW_FIELD_MARK)
4923 return rte_flow_error_set(error, EINVAL,
4924 RTE_FLOW_ERROR_TYPE_ACTION, action,
4925 "mark, immediate value or a pointer to it"
4926 " cannot be used as a destination");
4927 if (action_modify_field->dst.field == RTE_FLOW_FIELD_START ||
4928 action_modify_field->src.field == RTE_FLOW_FIELD_START)
4929 return rte_flow_error_set(error, ENOTSUP,
4930 RTE_FLOW_ERROR_TYPE_ACTION, action,
4931 "modifications of an arbitrary"
4932 " place in a packet is not supported");
4933 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VLAN_TYPE ||
4934 action_modify_field->src.field == RTE_FLOW_FIELD_VLAN_TYPE)
4935 return rte_flow_error_set(error, ENOTSUP,
4936 RTE_FLOW_ERROR_TYPE_ACTION, action,
4937 "modifications of the 802.1Q Tag"
4938 " Identifier is not supported");
4939 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VXLAN_VNI ||
4940 action_modify_field->src.field == RTE_FLOW_FIELD_VXLAN_VNI)
4941 return rte_flow_error_set(error, ENOTSUP,
4942 RTE_FLOW_ERROR_TYPE_ACTION, action,
4943 "modifications of the VXLAN Network"
4944 " Identifier is not supported");
4945 if (action_modify_field->dst.field == RTE_FLOW_FIELD_GENEVE_VNI ||
4946 action_modify_field->src.field == RTE_FLOW_FIELD_GENEVE_VNI)
4947 return rte_flow_error_set(error, ENOTSUP,
4948 RTE_FLOW_ERROR_TYPE_ACTION, action,
4949 "modifications of the GENEVE Network"
4950 " Identifier is not supported");
4951 if (action_modify_field->dst.field == RTE_FLOW_FIELD_MARK ||
4952 action_modify_field->src.field == RTE_FLOW_FIELD_MARK ||
4953 action_modify_field->dst.field == RTE_FLOW_FIELD_META ||
4954 action_modify_field->src.field == RTE_FLOW_FIELD_META) {
4955 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4956 !mlx5_flow_ext_mreg_supported(dev))
4957 return rte_flow_error_set(error, ENOTSUP,
4958 RTE_FLOW_ERROR_TYPE_ACTION, action,
4959 "cannot modify mark or metadata without"
4960 " extended metadata register support");
4962 if (action_modify_field->operation != RTE_FLOW_MODIFY_SET)
4963 return rte_flow_error_set(error, ENOTSUP,
4964 RTE_FLOW_ERROR_TYPE_ACTION, action,
4965 "add and sub operations"
4966 " are not supported");
4967 return (action_modify_field->width / 32) +
4968 !!(action_modify_field->width % 32);
4972 * Validate jump action.
4975 * Pointer to the jump action.
4976 * @param[in] action_flags
4977 * Holds the actions detected until now.
4978 * @param[in] attributes
4979 * Pointer to flow attributes
4980 * @param[in] external
4981 * Action belongs to flow rule created by request external to PMD.
4983 * Pointer to error structure.
4986 * 0 on success, a negative errno value otherwise and rte_errno is set.
4989 flow_dv_validate_action_jump(struct rte_eth_dev *dev,
4990 const struct mlx5_flow_tunnel *tunnel,
4991 const struct rte_flow_action *action,
4992 uint64_t action_flags,
4993 const struct rte_flow_attr *attributes,
4994 bool external, struct rte_flow_error *error)
4996 uint32_t target_group, table;
4998 struct flow_grp_info grp_info = {
4999 .external = !!external,
5000 .transfer = !!attributes->transfer,
5004 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5005 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5006 return rte_flow_error_set(error, EINVAL,
5007 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5008 "can't have 2 fate actions in"
5011 return rte_flow_error_set(error, EINVAL,
5012 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5013 NULL, "action configuration not set");
5015 ((const struct rte_flow_action_jump *)action->conf)->group;
5016 ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5020 if (attributes->group == target_group &&
5021 !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
5022 MLX5_FLOW_ACTION_TUNNEL_MATCH)))
5023 return rte_flow_error_set(error, EINVAL,
5024 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5025 "target group must be other than"
5026 " the current flow group");
5031 * Validate action PORT_ID / REPRESENTED_PORT.
5034 * Pointer to rte_eth_dev structure.
5035 * @param[in] action_flags
5036 * Bit-fields that holds the actions detected until now.
5038 * PORT_ID / REPRESENTED_PORT action structure.
5040 * Attributes of flow that includes this action.
5042 * Pointer to error structure.
5045 * 0 on success, a negative errno value otherwise and rte_errno is set.
5048 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5049 uint64_t action_flags,
5050 const struct rte_flow_action *action,
5051 const struct rte_flow_attr *attr,
5052 struct rte_flow_error *error)
5054 const struct rte_flow_action_port_id *port_id;
5055 const struct rte_flow_action_ethdev *ethdev;
5056 struct mlx5_priv *act_priv;
5057 struct mlx5_priv *dev_priv;
5060 if (!attr->transfer)
5061 return rte_flow_error_set(error, ENOTSUP,
5062 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5064 "port action is valid in transfer"
5066 if (!action || !action->conf)
5067 return rte_flow_error_set(error, ENOTSUP,
5068 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5070 "port action parameters must be"
5072 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5073 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5074 return rte_flow_error_set(error, EINVAL,
5075 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5076 "can have only one fate actions in"
5078 dev_priv = mlx5_dev_to_eswitch_info(dev);
5080 return rte_flow_error_set(error, rte_errno,
5081 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5083 "failed to obtain E-Switch info");
5084 switch (action->type) {
5085 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5086 port_id = action->conf;
5087 port = port_id->original ? dev->data->port_id : port_id->id;
5089 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5090 ethdev = action->conf;
5091 port = ethdev->port_id;
5095 return rte_flow_error_set
5097 RTE_FLOW_ERROR_TYPE_ACTION, action,
5098 "unknown E-Switch action");
5100 act_priv = mlx5_port_to_eswitch_info(port, false);
5102 return rte_flow_error_set
5104 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5105 "failed to obtain E-Switch port id for port");
5106 if (act_priv->domain_id != dev_priv->domain_id)
5107 return rte_flow_error_set
5109 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5110 "port does not belong to"
5111 " E-Switch being configured");
5116 * Get the maximum number of modify header actions.
5119 * Pointer to rte_eth_dev structure.
5121 * Whether action is on root table.
5124 * Max number of modify header actions device can support.
5126 static inline unsigned int
5127 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5131 * There's no way to directly query the max capacity from FW.
5132 * The maximal value on root table should be assumed to be supported.
5135 return MLX5_MAX_MODIFY_NUM;
5137 return MLX5_ROOT_TBL_MODIFY_NUM;
5141 * Validate the meter action.
5144 * Pointer to rte_eth_dev structure.
5145 * @param[in] action_flags
5146 * Bit-fields that holds the actions detected until now.
5148 * Pointer to the meter action.
5150 * Attributes of flow that includes this action.
5151 * @param[in] port_id_item
5152 * Pointer to item indicating port id.
5154 * Pointer to error structure.
5157 * 0 on success, a negative errno value otherwise and rte_ernno is set.
5160 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5161 uint64_t action_flags,
5162 const struct rte_flow_action *action,
5163 const struct rte_flow_attr *attr,
5164 const struct rte_flow_item *port_id_item,
5166 struct rte_flow_error *error)
5168 struct mlx5_priv *priv = dev->data->dev_private;
5169 const struct rte_flow_action_meter *am = action->conf;
5170 struct mlx5_flow_meter_info *fm;
5171 struct mlx5_flow_meter_policy *mtr_policy;
5172 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5175 return rte_flow_error_set(error, EINVAL,
5176 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5177 "meter action conf is NULL");
5179 if (action_flags & MLX5_FLOW_ACTION_METER)
5180 return rte_flow_error_set(error, ENOTSUP,
5181 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5182 "meter chaining not support");
5183 if (action_flags & MLX5_FLOW_ACTION_JUMP)
5184 return rte_flow_error_set(error, ENOTSUP,
5185 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5186 "meter with jump not support");
5188 return rte_flow_error_set(error, ENOTSUP,
5189 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5191 "meter action not supported");
5192 fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5194 return rte_flow_error_set(error, EINVAL,
5195 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5197 /* aso meter can always be shared by different domains */
5198 if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5199 !(fm->transfer == attr->transfer ||
5200 (!fm->ingress && !attr->ingress && attr->egress) ||
5201 (!fm->egress && !attr->egress && attr->ingress)))
5202 return rte_flow_error_set(error, EINVAL,
5203 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5204 "Flow attributes domain are either invalid "
5205 "or have a domain conflict with current "
5206 "meter attributes");
5207 if (fm->def_policy) {
5208 if (!((attr->transfer &&
5209 mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
5211 mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
5213 mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
5214 return rte_flow_error_set(error, EINVAL,
5215 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5216 "Flow attributes domain "
5217 "have a conflict with current "
5218 "meter domain attributes");
5221 mtr_policy = mlx5_flow_meter_policy_find(dev,
5222 fm->policy_id, NULL);
5224 return rte_flow_error_set(error, EINVAL,
5225 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5226 "Invalid policy id for meter ");
5227 if (!((attr->transfer && mtr_policy->transfer) ||
5228 (attr->egress && mtr_policy->egress) ||
5229 (attr->ingress && mtr_policy->ingress)))
5230 return rte_flow_error_set(error, EINVAL,
5231 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5232 "Flow attributes domain "
5233 "have a conflict with current "
5234 "meter domain attributes");
5235 if (attr->transfer && mtr_policy->dev) {
5237 * When policy has fate action of port_id,
5238 * the flow should have the same src port as policy.
5240 struct mlx5_priv *policy_port_priv =
5241 mtr_policy->dev->data->dev_private;
5242 int32_t flow_src_port = priv->representor_id;
5245 const struct rte_flow_item_port_id *spec =
5247 struct mlx5_priv *port_priv =
5248 mlx5_port_to_eswitch_info(spec->id,
5251 return rte_flow_error_set(error,
5253 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5255 "Failed to get port info.");
5256 flow_src_port = port_priv->representor_id;
5258 if (flow_src_port != policy_port_priv->representor_id)
5259 return rte_flow_error_set(error,
5261 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5263 "Flow and meter policy "
5264 "have different src port.");
5266 *def_policy = false;
5272 * Validate the age action.
5274 * @param[in] action_flags
5275 * Holds the actions detected until now.
5277 * Pointer to the age action.
5279 * Pointer to the Ethernet device structure.
5281 * Pointer to error structure.
5284 * 0 on success, a negative errno value otherwise and rte_errno is set.
5287 flow_dv_validate_action_age(uint64_t action_flags,
5288 const struct rte_flow_action *action,
5289 struct rte_eth_dev *dev,
5290 struct rte_flow_error *error)
5292 struct mlx5_priv *priv = dev->data->dev_private;
5293 const struct rte_flow_action_age *age = action->conf;
5295 if (!priv->config.devx || (priv->sh->cmng.counter_fallback &&
5296 !priv->sh->aso_age_mng))
5297 return rte_flow_error_set(error, ENOTSUP,
5298 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5300 "age action not supported");
5301 if (!(action->conf))
5302 return rte_flow_error_set(error, EINVAL,
5303 RTE_FLOW_ERROR_TYPE_ACTION, action,
5304 "configuration cannot be null");
5305 if (!(age->timeout))
5306 return rte_flow_error_set(error, EINVAL,
5307 RTE_FLOW_ERROR_TYPE_ACTION, action,
5308 "invalid timeout value 0");
5309 if (action_flags & MLX5_FLOW_ACTION_AGE)
5310 return rte_flow_error_set(error, EINVAL,
5311 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5312 "duplicate age actions set");
5317 * Validate the modify-header IPv4 DSCP actions.
5319 * @param[in] action_flags
5320 * Holds the actions detected until now.
5322 * Pointer to the modify action.
5323 * @param[in] item_flags
5324 * Holds the items detected.
5326 * Pointer to error structure.
5329 * 0 on success, a negative errno value otherwise and rte_errno is set.
5332 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
5333 const struct rte_flow_action *action,
5334 const uint64_t item_flags,
5335 struct rte_flow_error *error)
5339 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5341 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
5342 return rte_flow_error_set(error, EINVAL,
5343 RTE_FLOW_ERROR_TYPE_ACTION,
5345 "no ipv4 item in pattern");
5351 * Validate the modify-header IPv6 DSCP actions.
5353 * @param[in] action_flags
5354 * Holds the actions detected until now.
5356 * Pointer to the modify action.
5357 * @param[in] item_flags
5358 * Holds the items detected.
5360 * Pointer to error structure.
5363 * 0 on success, a negative errno value otherwise and rte_errno is set.
5366 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
5367 const struct rte_flow_action *action,
5368 const uint64_t item_flags,
5369 struct rte_flow_error *error)
5373 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5375 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
5376 return rte_flow_error_set(error, EINVAL,
5377 RTE_FLOW_ERROR_TYPE_ACTION,
5379 "no ipv6 item in pattern");
5385 flow_dv_modify_match_cb(void *tool_ctx __rte_unused,
5386 struct mlx5_list_entry *entry, void *cb_ctx)
5388 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5389 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5390 struct mlx5_flow_dv_modify_hdr_resource *resource =
5391 container_of(entry, typeof(*resource), entry);
5392 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5394 key_len += ref->actions_num * sizeof(ref->actions[0]);
5395 return ref->actions_num != resource->actions_num ||
5396 memcmp(&ref->ft_type, &resource->ft_type, key_len);
5399 static struct mlx5_indexed_pool *
5400 flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
5402 struct mlx5_indexed_pool *ipool = __atomic_load_n
5403 (&sh->mdh_ipools[index], __ATOMIC_SEQ_CST);
5406 struct mlx5_indexed_pool *expected = NULL;
5407 struct mlx5_indexed_pool_config cfg =
5408 (struct mlx5_indexed_pool_config) {
5409 .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
5411 sizeof(struct mlx5_modification_cmd),
5416 .release_mem_en = !!sh->reclaim_mode,
5417 .per_core_cache = sh->reclaim_mode ? 0 : (1 << 16),
5418 .malloc = mlx5_malloc,
5420 .type = "mlx5_modify_action_resource",
5423 cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
5424 ipool = mlx5_ipool_create(&cfg);
5427 if (!__atomic_compare_exchange_n(&sh->mdh_ipools[index],
5428 &expected, ipool, false,
5430 __ATOMIC_SEQ_CST)) {
5431 mlx5_ipool_destroy(ipool);
5432 ipool = __atomic_load_n(&sh->mdh_ipools[index],
5439 struct mlx5_list_entry *
5440 flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
5442 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5443 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5444 struct mlx5dv_dr_domain *ns;
5445 struct mlx5_flow_dv_modify_hdr_resource *entry;
5446 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5447 struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
5448 ref->actions_num - 1);
5450 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5451 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5454 if (unlikely(!ipool)) {
5455 rte_flow_error_set(ctx->error, ENOMEM,
5456 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5457 NULL, "cannot allocate modify ipool");
5460 entry = mlx5_ipool_zmalloc(ipool, &idx);
5462 rte_flow_error_set(ctx->error, ENOMEM,
5463 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5464 "cannot allocate resource memory");
5467 rte_memcpy(&entry->ft_type,
5468 RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
5469 key_len + data_len);
5470 if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
5471 ns = sh->fdb_domain;
5472 else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
5476 ret = mlx5_flow_os_create_flow_action_modify_header
5477 (sh->ctx, ns, entry,
5478 data_len, &entry->action);
5480 mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
5481 rte_flow_error_set(ctx->error, ENOMEM,
5482 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5483 NULL, "cannot create modification action");
5487 return &entry->entry;
5490 struct mlx5_list_entry *
5491 flow_dv_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5494 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5495 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5496 struct mlx5_flow_dv_modify_hdr_resource *entry;
5497 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5498 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5501 entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
5504 rte_flow_error_set(ctx->error, ENOMEM,
5505 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5506 "cannot allocate resource memory");
5509 memcpy(entry, oentry, sizeof(*entry) + data_len);
5511 return &entry->entry;
5515 flow_dv_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5517 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5518 struct mlx5_flow_dv_modify_hdr_resource *res =
5519 container_of(entry, typeof(*res), entry);
5521 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
5525 * Validate the sample action.
5527 * @param[in, out] action_flags
5528 * Holds the actions detected until now.
5530 * Pointer to the sample action.
5532 * Pointer to the Ethernet device structure.
5534 * Attributes of flow that includes this action.
5535 * @param[in] item_flags
5536 * Holds the items detected.
5538 * Pointer to the RSS action.
5539 * @param[out] sample_rss
5540 * Pointer to the RSS action in sample action list.
5542 * Pointer to the COUNT action in sample action list.
5543 * @param[out] fdb_mirror_limit
5544 * Pointer to the FDB mirror limitation flag.
5546 * Pointer to error structure.
5549 * 0 on success, a negative errno value otherwise and rte_errno is set.
5552 flow_dv_validate_action_sample(uint64_t *action_flags,
5553 const struct rte_flow_action *action,
5554 struct rte_eth_dev *dev,
5555 const struct rte_flow_attr *attr,
5556 uint64_t item_flags,
5557 const struct rte_flow_action_rss *rss,
5558 const struct rte_flow_action_rss **sample_rss,
5559 const struct rte_flow_action_count **count,
5560 int *fdb_mirror_limit,
5561 struct rte_flow_error *error)
5563 struct mlx5_priv *priv = dev->data->dev_private;
5564 struct mlx5_dev_config *dev_conf = &priv->config;
5565 const struct rte_flow_action_sample *sample = action->conf;
5566 const struct rte_flow_action *act;
5567 uint64_t sub_action_flags = 0;
5568 uint16_t queue_index = 0xFFFF;
5573 return rte_flow_error_set(error, EINVAL,
5574 RTE_FLOW_ERROR_TYPE_ACTION, action,
5575 "configuration cannot be NULL");
5576 if (sample->ratio == 0)
5577 return rte_flow_error_set(error, EINVAL,
5578 RTE_FLOW_ERROR_TYPE_ACTION, action,
5579 "ratio value starts from 1");
5580 if (!priv->config.devx || (sample->ratio > 0 && !priv->sampler_en))
5581 return rte_flow_error_set(error, ENOTSUP,
5582 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5584 "sample action not supported");
5585 if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
5586 return rte_flow_error_set(error, EINVAL,
5587 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5588 "Multiple sample actions not "
5590 if (*action_flags & MLX5_FLOW_ACTION_METER)
5591 return rte_flow_error_set(error, EINVAL,
5592 RTE_FLOW_ERROR_TYPE_ACTION, action,
5593 "wrong action order, meter should "
5594 "be after sample action");
5595 if (*action_flags & MLX5_FLOW_ACTION_JUMP)
5596 return rte_flow_error_set(error, EINVAL,
5597 RTE_FLOW_ERROR_TYPE_ACTION, action,
5598 "wrong action order, jump should "
5599 "be after sample action");
5600 act = sample->actions;
5601 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
5602 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5603 return rte_flow_error_set(error, ENOTSUP,
5604 RTE_FLOW_ERROR_TYPE_ACTION,
5605 act, "too many actions");
5606 switch (act->type) {
5607 case RTE_FLOW_ACTION_TYPE_QUEUE:
5608 ret = mlx5_flow_validate_action_queue(act,
5614 queue_index = ((const struct rte_flow_action_queue *)
5615 (act->conf))->index;
5616 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
5619 case RTE_FLOW_ACTION_TYPE_RSS:
5620 *sample_rss = act->conf;
5621 ret = mlx5_flow_validate_action_rss(act,
5628 if (rss && *sample_rss &&
5629 ((*sample_rss)->level != rss->level ||
5630 (*sample_rss)->types != rss->types))
5631 return rte_flow_error_set(error, ENOTSUP,
5632 RTE_FLOW_ERROR_TYPE_ACTION,
5634 "Can't use the different RSS types "
5635 "or level in the same flow");
5636 if (*sample_rss != NULL && (*sample_rss)->queue_num)
5637 queue_index = (*sample_rss)->queue[0];
5638 sub_action_flags |= MLX5_FLOW_ACTION_RSS;
5641 case RTE_FLOW_ACTION_TYPE_MARK:
5642 ret = flow_dv_validate_action_mark(dev, act,
5647 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
5648 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
5649 MLX5_FLOW_ACTION_MARK_EXT;
5651 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
5654 case RTE_FLOW_ACTION_TYPE_COUNT:
5655 ret = flow_dv_validate_action_count
5656 (dev, false, *action_flags | sub_action_flags,
5661 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
5662 *action_flags |= MLX5_FLOW_ACTION_COUNT;
5665 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5666 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5667 ret = flow_dv_validate_action_port_id(dev,
5674 sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5677 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5678 ret = flow_dv_validate_action_raw_encap_decap
5679 (dev, NULL, act->conf, attr, &sub_action_flags,
5680 &actions_n, action, item_flags, error);
5685 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5686 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5687 ret = flow_dv_validate_action_l2_encap(dev,
5693 sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
5697 return rte_flow_error_set(error, ENOTSUP,
5698 RTE_FLOW_ERROR_TYPE_ACTION,
5700 "Doesn't support optional "
5704 if (attr->ingress && !attr->transfer) {
5705 if (!(sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
5706 MLX5_FLOW_ACTION_RSS)))
5707 return rte_flow_error_set(error, EINVAL,
5708 RTE_FLOW_ERROR_TYPE_ACTION,
5710 "Ingress must has a dest "
5711 "QUEUE for Sample");
5712 } else if (attr->egress && !attr->transfer) {
5713 return rte_flow_error_set(error, ENOTSUP,
5714 RTE_FLOW_ERROR_TYPE_ACTION,
5716 "Sample Only support Ingress "
5718 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
5719 MLX5_ASSERT(attr->transfer);
5720 if (sample->ratio > 1)
5721 return rte_flow_error_set(error, ENOTSUP,
5722 RTE_FLOW_ERROR_TYPE_ACTION,
5724 "E-Switch doesn't support "
5725 "any optional action "
5727 if (sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
5728 return rte_flow_error_set(error, ENOTSUP,
5729 RTE_FLOW_ERROR_TYPE_ACTION,
5731 "unsupported action QUEUE");
5732 if (sub_action_flags & MLX5_FLOW_ACTION_RSS)
5733 return rte_flow_error_set(error, ENOTSUP,
5734 RTE_FLOW_ERROR_TYPE_ACTION,
5736 "unsupported action QUEUE");
5737 if (!(sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
5738 return rte_flow_error_set(error, EINVAL,
5739 RTE_FLOW_ERROR_TYPE_ACTION,
5741 "E-Switch must has a dest "
5742 "port for mirroring");
5743 if (!priv->config.hca_attr.reg_c_preserve &&
5744 priv->representor_id != UINT16_MAX)
5745 *fdb_mirror_limit = 1;
5747 /* Continue validation for Xcap actions.*/
5748 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
5749 (queue_index == 0xFFFF ||
5750 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5751 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5752 MLX5_FLOW_XCAP_ACTIONS)
5753 return rte_flow_error_set(error, ENOTSUP,
5754 RTE_FLOW_ERROR_TYPE_ACTION,
5755 NULL, "encap and decap "
5756 "combination aren't "
5758 if (!attr->transfer && attr->ingress && (sub_action_flags &
5759 MLX5_FLOW_ACTION_ENCAP))
5760 return rte_flow_error_set(error, ENOTSUP,
5761 RTE_FLOW_ERROR_TYPE_ACTION,
5762 NULL, "encap is not supported"
5763 " for ingress traffic");
5769 * Find existing modify-header resource or create and register a new one.
5771 * @param dev[in, out]
5772 * Pointer to rte_eth_dev structure.
5773 * @param[in, out] resource
5774 * Pointer to modify-header resource.
5775 * @parm[in, out] dev_flow
5776 * Pointer to the dev_flow.
5778 * pointer to error structure.
5781 * 0 on success otherwise -errno and errno is set.
5784 flow_dv_modify_hdr_resource_register
5785 (struct rte_eth_dev *dev,
5786 struct mlx5_flow_dv_modify_hdr_resource *resource,
5787 struct mlx5_flow *dev_flow,
5788 struct rte_flow_error *error)
5790 struct mlx5_priv *priv = dev->data->dev_private;
5791 struct mlx5_dev_ctx_shared *sh = priv->sh;
5792 uint32_t key_len = sizeof(*resource) -
5793 offsetof(typeof(*resource), ft_type) +
5794 resource->actions_num * sizeof(resource->actions[0]);
5795 struct mlx5_list_entry *entry;
5796 struct mlx5_flow_cb_ctx ctx = {
5800 struct mlx5_hlist *modify_cmds;
5803 modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
5805 MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
5807 flow_dv_modify_create_cb,
5808 flow_dv_modify_match_cb,
5809 flow_dv_modify_remove_cb,
5810 flow_dv_modify_clone_cb,
5811 flow_dv_modify_clone_free_cb);
5812 if (unlikely(!modify_cmds))
5814 resource->root = !dev_flow->dv.group;
5815 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
5817 return rte_flow_error_set(error, EOVERFLOW,
5818 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5819 "too many modify header items");
5820 key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
5821 entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
5824 resource = container_of(entry, typeof(*resource), entry);
5825 dev_flow->handle->dvh.modify_hdr = resource;
5830 * Get DV flow counter by index.
5833 * Pointer to the Ethernet device structure.
5835 * mlx5 flow counter index in the container.
5837 * mlx5 flow counter pool in the container.
5840 * Pointer to the counter, NULL otherwise.
5842 static struct mlx5_flow_counter *
5843 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
5845 struct mlx5_flow_counter_pool **ppool)
5847 struct mlx5_priv *priv = dev->data->dev_private;
5848 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5849 struct mlx5_flow_counter_pool *pool;
5851 /* Decrease to original index and clear shared bit. */
5852 idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
5853 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cmng->n);
5854 pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
5858 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
5862 * Check the devx counter belongs to the pool.
5865 * Pointer to the counter pool.
5867 * The counter devx ID.
5870 * True if counter belongs to the pool, false otherwise.
5873 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
5875 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
5876 MLX5_COUNTERS_PER_POOL;
5878 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
5884 * Get a pool by devx counter ID.
5887 * Pointer to the counter management.
5889 * The counter devx ID.
5892 * The counter pool pointer if exists, NULL otherwise,
5894 static struct mlx5_flow_counter_pool *
5895 flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
5898 struct mlx5_flow_counter_pool *pool = NULL;
5900 rte_spinlock_lock(&cmng->pool_update_sl);
5901 /* Check last used pool. */
5902 if (cmng->last_pool_idx != POOL_IDX_INVALID &&
5903 flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
5904 pool = cmng->pools[cmng->last_pool_idx];
5907 /* ID out of range means no suitable pool in the container. */
5908 if (id > cmng->max_id || id < cmng->min_id)
5911 * Find the pool from the end of the container, since mostly counter
5912 * ID is sequence increasing, and the last pool should be the needed
5917 struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
5919 if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
5925 rte_spinlock_unlock(&cmng->pool_update_sl);
5930 * Resize a counter container.
5933 * Pointer to the Ethernet device structure.
5936 * 0 on success, otherwise negative errno value and rte_errno is set.
5939 flow_dv_container_resize(struct rte_eth_dev *dev)
5941 struct mlx5_priv *priv = dev->data->dev_private;
5942 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5943 void *old_pools = cmng->pools;
5944 uint32_t resize = cmng->n + MLX5_CNT_CONTAINER_RESIZE;
5945 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
5946 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
5953 memcpy(pools, old_pools, cmng->n *
5954 sizeof(struct mlx5_flow_counter_pool *));
5956 cmng->pools = pools;
5958 mlx5_free(old_pools);
5963 * Query a devx flow counter.
5966 * Pointer to the Ethernet device structure.
5967 * @param[in] counter
5968 * Index to the flow counter.
5970 * The statistics value of packets.
5972 * The statistics value of bytes.
5975 * 0 on success, otherwise a negative errno value and rte_errno is set.
5978 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
5981 struct mlx5_priv *priv = dev->data->dev_private;
5982 struct mlx5_flow_counter_pool *pool = NULL;
5983 struct mlx5_flow_counter *cnt;
5986 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
5988 if (priv->sh->cmng.counter_fallback)
5989 return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
5990 0, pkts, bytes, 0, NULL, NULL, 0);
5991 rte_spinlock_lock(&pool->sl);
5996 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
5997 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
5998 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6000 rte_spinlock_unlock(&pool->sl);
6005 * Create and initialize a new counter pool.
6008 * Pointer to the Ethernet device structure.
6010 * The devX counter handle.
6012 * Whether the pool is for counter that was allocated for aging.
6013 * @param[in/out] cont_cur
6014 * Pointer to the container pointer, it will be update in pool resize.
6017 * The pool container pointer on success, NULL otherwise and rte_errno is set.
6019 static struct mlx5_flow_counter_pool *
6020 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6023 struct mlx5_priv *priv = dev->data->dev_private;
6024 struct mlx5_flow_counter_pool *pool;
6025 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6026 bool fallback = priv->sh->cmng.counter_fallback;
6027 uint32_t size = sizeof(*pool);
6029 size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6030 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6031 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6037 pool->is_aged = !!age;
6038 pool->query_gen = 0;
6039 pool->min_dcs = dcs;
6040 rte_spinlock_init(&pool->sl);
6041 rte_spinlock_init(&pool->csl);
6042 TAILQ_INIT(&pool->counters[0]);
6043 TAILQ_INIT(&pool->counters[1]);
6044 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6045 rte_spinlock_lock(&cmng->pool_update_sl);
6046 pool->index = cmng->n_valid;
6047 if (pool->index == cmng->n && flow_dv_container_resize(dev)) {
6049 rte_spinlock_unlock(&cmng->pool_update_sl);
6052 cmng->pools[pool->index] = pool;
6054 if (unlikely(fallback)) {
6055 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6057 if (base < cmng->min_id)
6058 cmng->min_id = base;
6059 if (base > cmng->max_id)
6060 cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6061 cmng->last_pool_idx = pool->index;
6063 rte_spinlock_unlock(&cmng->pool_update_sl);
6068 * Prepare a new counter and/or a new counter pool.
6071 * Pointer to the Ethernet device structure.
6072 * @param[out] cnt_free
6073 * Where to put the pointer of a new counter.
6075 * Whether the pool is for counter that was allocated for aging.
6078 * The counter pool pointer and @p cnt_free is set on success,
6079 * NULL otherwise and rte_errno is set.
6081 static struct mlx5_flow_counter_pool *
6082 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6083 struct mlx5_flow_counter **cnt_free,
6086 struct mlx5_priv *priv = dev->data->dev_private;
6087 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6088 struct mlx5_flow_counter_pool *pool;
6089 struct mlx5_counters tmp_tq;
6090 struct mlx5_devx_obj *dcs = NULL;
6091 struct mlx5_flow_counter *cnt;
6092 enum mlx5_counter_type cnt_type =
6093 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6094 bool fallback = priv->sh->cmng.counter_fallback;
6098 /* bulk_bitmap must be 0 for single counter allocation. */
6099 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
6102 pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6104 pool = flow_dv_pool_create(dev, dcs, age);
6106 mlx5_devx_cmd_destroy(dcs);
6110 i = dcs->id % MLX5_COUNTERS_PER_POOL;
6111 cnt = MLX5_POOL_GET_CNT(pool, i);
6113 cnt->dcs_when_free = dcs;
6117 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
6119 rte_errno = ENODATA;
6122 pool = flow_dv_pool_create(dev, dcs, age);
6124 mlx5_devx_cmd_destroy(dcs);
6127 TAILQ_INIT(&tmp_tq);
6128 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6129 cnt = MLX5_POOL_GET_CNT(pool, i);
6131 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6133 rte_spinlock_lock(&cmng->csl[cnt_type]);
6134 TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6135 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6136 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6137 (*cnt_free)->pool = pool;
6142 * Allocate a flow counter.
6145 * Pointer to the Ethernet device structure.
6147 * Whether the counter was allocated for aging.
6150 * Index to flow counter on success, 0 otherwise and rte_errno is set.
6153 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6155 struct mlx5_priv *priv = dev->data->dev_private;
6156 struct mlx5_flow_counter_pool *pool = NULL;
6157 struct mlx5_flow_counter *cnt_free = NULL;
6158 bool fallback = priv->sh->cmng.counter_fallback;
6159 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6160 enum mlx5_counter_type cnt_type =
6161 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6164 if (!priv->config.devx) {
6165 rte_errno = ENOTSUP;
6168 /* Get free counters from container. */
6169 rte_spinlock_lock(&cmng->csl[cnt_type]);
6170 cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6172 TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6173 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6174 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6176 pool = cnt_free->pool;
6178 cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6179 /* Create a DV counter action only in the first time usage. */
6180 if (!cnt_free->action) {
6182 struct mlx5_devx_obj *dcs;
6186 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
6187 dcs = pool->min_dcs;
6190 dcs = cnt_free->dcs_when_free;
6192 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
6199 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
6200 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
6201 /* Update the counter reset values. */
6202 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
6205 if (!fallback && !priv->sh->cmng.query_thread_on)
6206 /* Start the asynchronous batch query by the host thread. */
6207 mlx5_set_query_alarm(priv->sh);
6209 * When the count action isn't shared (by ID), shared_info field is
6210 * used for indirect action API's refcnt.
6211 * When the counter action is not shared neither by ID nor by indirect
6212 * action API, shared info must be 1.
6214 cnt_free->shared_info.refcnt = 1;
6218 cnt_free->pool = pool;
6220 cnt_free->dcs_when_free = cnt_free->dcs_when_active;
6221 rte_spinlock_lock(&cmng->csl[cnt_type]);
6222 TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
6223 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6229 * Get age param from counter index.
6232 * Pointer to the Ethernet device structure.
6233 * @param[in] counter
6234 * Index to the counter handler.
6237 * The aging parameter specified for the counter index.
6239 static struct mlx5_age_param*
6240 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
6243 struct mlx5_flow_counter *cnt;
6244 struct mlx5_flow_counter_pool *pool = NULL;
6246 flow_dv_counter_get_by_idx(dev, counter, &pool);
6247 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
6248 cnt = MLX5_POOL_GET_CNT(pool, counter);
6249 return MLX5_CNT_TO_AGE(cnt);
6253 * Remove a flow counter from aged counter list.
6256 * Pointer to the Ethernet device structure.
6257 * @param[in] counter
6258 * Index to the counter handler.
6260 * Pointer to the counter handler.
6263 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
6264 uint32_t counter, struct mlx5_flow_counter *cnt)
6266 struct mlx5_age_info *age_info;
6267 struct mlx5_age_param *age_param;
6268 struct mlx5_priv *priv = dev->data->dev_private;
6269 uint16_t expected = AGE_CANDIDATE;
6271 age_info = GET_PORT_AGE_INFO(priv);
6272 age_param = flow_dv_counter_idx_get_age(dev, counter);
6273 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
6274 AGE_FREE, false, __ATOMIC_RELAXED,
6275 __ATOMIC_RELAXED)) {
6277 * We need the lock even it is age timeout,
6278 * since counter may still in process.
6280 rte_spinlock_lock(&age_info->aged_sl);
6281 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
6282 rte_spinlock_unlock(&age_info->aged_sl);
6283 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
6288 * Release a flow counter.
6291 * Pointer to the Ethernet device structure.
6292 * @param[in] counter
6293 * Index to the counter handler.
6296 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
6298 struct mlx5_priv *priv = dev->data->dev_private;
6299 struct mlx5_flow_counter_pool *pool = NULL;
6300 struct mlx5_flow_counter *cnt;
6301 enum mlx5_counter_type cnt_type;
6305 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6307 if (pool->is_aged) {
6308 flow_dv_counter_remove_from_age(dev, counter, cnt);
6311 * If the counter action is shared by indirect action API,
6312 * the atomic function reduces its references counter.
6313 * If after the reduction the action is still referenced, the
6314 * function returns here and does not release it.
6315 * When the counter action is not shared by
6316 * indirect action API, shared info is 1 before the reduction,
6317 * so this condition is failed and function doesn't return here.
6319 if (__atomic_sub_fetch(&cnt->shared_info.refcnt, 1,
6325 * Put the counter back to list to be updated in none fallback mode.
6326 * Currently, we are using two list alternately, while one is in query,
6327 * add the freed counter to the other list based on the pool query_gen
6328 * value. After query finishes, add counter the list to the global
6329 * container counter list. The list changes while query starts. In
6330 * this case, lock will not be needed as query callback and release
6331 * function both operate with the different list.
6333 if (!priv->sh->cmng.counter_fallback) {
6334 rte_spinlock_lock(&pool->csl);
6335 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
6336 rte_spinlock_unlock(&pool->csl);
6338 cnt->dcs_when_free = cnt->dcs_when_active;
6339 cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6340 MLX5_COUNTER_TYPE_ORIGIN;
6341 rte_spinlock_lock(&priv->sh->cmng.csl[cnt_type]);
6342 TAILQ_INSERT_TAIL(&priv->sh->cmng.counters[cnt_type],
6344 rte_spinlock_unlock(&priv->sh->cmng.csl[cnt_type]);
6349 * Resize a meter id container.
6352 * Pointer to the Ethernet device structure.
6355 * 0 on success, otherwise negative errno value and rte_errno is set.
6358 flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
6360 struct mlx5_priv *priv = dev->data->dev_private;
6361 struct mlx5_aso_mtr_pools_mng *pools_mng =
6362 &priv->sh->mtrmng->pools_mng;
6363 void *old_pools = pools_mng->pools;
6364 uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
6365 uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
6366 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
6373 if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER)) {
6378 memcpy(pools, old_pools, pools_mng->n *
6379 sizeof(struct mlx5_aso_mtr_pool *));
6380 pools_mng->n = resize;
6381 pools_mng->pools = pools;
6383 mlx5_free(old_pools);
6388 * Prepare a new meter and/or a new meter pool.
6391 * Pointer to the Ethernet device structure.
6392 * @param[out] mtr_free
6393 * Where to put the pointer of a new meter.g.
6396 * The meter pool pointer and @mtr_free is set on success,
6397 * NULL otherwise and rte_errno is set.
6399 static struct mlx5_aso_mtr_pool *
6400 flow_dv_mtr_pool_create(struct rte_eth_dev *dev,
6401 struct mlx5_aso_mtr **mtr_free)
6403 struct mlx5_priv *priv = dev->data->dev_private;
6404 struct mlx5_aso_mtr_pools_mng *pools_mng =
6405 &priv->sh->mtrmng->pools_mng;
6406 struct mlx5_aso_mtr_pool *pool = NULL;
6407 struct mlx5_devx_obj *dcs = NULL;
6409 uint32_t log_obj_size;
6411 log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
6412 dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->ctx,
6413 priv->sh->pdn, log_obj_size);
6415 rte_errno = ENODATA;
6418 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
6421 claim_zero(mlx5_devx_cmd_destroy(dcs));
6424 pool->devx_obj = dcs;
6425 pool->index = pools_mng->n_valid;
6426 if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
6428 claim_zero(mlx5_devx_cmd_destroy(dcs));
6431 pools_mng->pools[pool->index] = pool;
6432 pools_mng->n_valid++;
6433 for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
6434 pool->mtrs[i].offset = i;
6435 LIST_INSERT_HEAD(&pools_mng->meters,
6436 &pool->mtrs[i], next);
6438 pool->mtrs[0].offset = 0;
6439 *mtr_free = &pool->mtrs[0];
6444 * Release a flow meter into pool.
6447 * Pointer to the Ethernet device structure.
6448 * @param[in] mtr_idx
6449 * Index to aso flow meter.
6452 flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
6454 struct mlx5_priv *priv = dev->data->dev_private;
6455 struct mlx5_aso_mtr_pools_mng *pools_mng =
6456 &priv->sh->mtrmng->pools_mng;
6457 struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
6459 MLX5_ASSERT(aso_mtr);
6460 rte_spinlock_lock(&pools_mng->mtrsl);
6461 memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
6462 aso_mtr->state = ASO_METER_FREE;
6463 LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
6464 rte_spinlock_unlock(&pools_mng->mtrsl);
6468 * Allocate a aso flow meter.
6471 * Pointer to the Ethernet device structure.
6474 * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
6477 flow_dv_mtr_alloc(struct rte_eth_dev *dev)
6479 struct mlx5_priv *priv = dev->data->dev_private;
6480 struct mlx5_aso_mtr *mtr_free = NULL;
6481 struct mlx5_aso_mtr_pools_mng *pools_mng =
6482 &priv->sh->mtrmng->pools_mng;
6483 struct mlx5_aso_mtr_pool *pool;
6484 uint32_t mtr_idx = 0;
6486 if (!priv->config.devx) {
6487 rte_errno = ENOTSUP;
6490 /* Allocate the flow meter memory. */
6491 /* Get free meters from management. */
6492 rte_spinlock_lock(&pools_mng->mtrsl);
6493 mtr_free = LIST_FIRST(&pools_mng->meters);
6495 LIST_REMOVE(mtr_free, next);
6496 if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
6497 rte_spinlock_unlock(&pools_mng->mtrsl);
6500 mtr_free->state = ASO_METER_WAIT;
6501 rte_spinlock_unlock(&pools_mng->mtrsl);
6502 pool = container_of(mtr_free,
6503 struct mlx5_aso_mtr_pool,
6504 mtrs[mtr_free->offset]);
6505 mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
6506 if (!mtr_free->fm.meter_action) {
6507 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
6508 struct rte_flow_error error;
6511 reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
6512 mtr_free->fm.meter_action =
6513 mlx5_glue->dv_create_flow_action_aso
6514 (priv->sh->rx_domain,
6515 pool->devx_obj->obj,
6517 (1 << MLX5_FLOW_COLOR_GREEN),
6519 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
6520 if (!mtr_free->fm.meter_action) {
6521 flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
6529 * Verify the @p attributes will be correctly understood by the NIC and store
6530 * them in the @p flow if everything is correct.
6533 * Pointer to dev struct.
6534 * @param[in] attributes
6535 * Pointer to flow attributes
6536 * @param[in] external
6537 * This flow rule is created by request external to PMD.
6539 * Pointer to error structure.
6542 * - 0 on success and non root table.
6543 * - 1 on success and root table.
6544 * - a negative errno value otherwise and rte_errno is set.
6547 flow_dv_validate_attributes(struct rte_eth_dev *dev,
6548 const struct mlx5_flow_tunnel *tunnel,
6549 const struct rte_flow_attr *attributes,
6550 const struct flow_grp_info *grp_info,
6551 struct rte_flow_error *error)
6553 struct mlx5_priv *priv = dev->data->dev_private;
6554 uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
6557 #ifndef HAVE_MLX5DV_DR
6558 RTE_SET_USED(tunnel);
6559 RTE_SET_USED(grp_info);
6560 if (attributes->group)
6561 return rte_flow_error_set(error, ENOTSUP,
6562 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6564 "groups are not supported");
6568 ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
6573 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
6575 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
6576 attributes->priority > lowest_priority)
6577 return rte_flow_error_set(error, ENOTSUP,
6578 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
6580 "priority out of range");
6581 if (attributes->transfer) {
6582 if (!priv->config.dv_esw_en)
6583 return rte_flow_error_set
6585 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6586 "E-Switch dr is not supported");
6587 if (!(priv->representor || priv->master))
6588 return rte_flow_error_set
6589 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6590 NULL, "E-Switch configuration can only be"
6591 " done by a master or a representor device");
6592 if (attributes->egress)
6593 return rte_flow_error_set
6595 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
6596 "egress is not supported");
6598 if (!(attributes->egress ^ attributes->ingress))
6599 return rte_flow_error_set(error, ENOTSUP,
6600 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6601 "must specify exactly one of "
6602 "ingress or egress");
6607 mlx5_flow_locate_proto_l3(const struct rte_flow_item **head,
6608 const struct rte_flow_item *end)
6610 const struct rte_flow_item *item = *head;
6611 uint16_t l3_protocol;
6613 for (; item != end; item++) {
6614 switch (item->type) {
6617 case RTE_FLOW_ITEM_TYPE_IPV4:
6618 l3_protocol = RTE_ETHER_TYPE_IPV4;
6620 case RTE_FLOW_ITEM_TYPE_IPV6:
6621 l3_protocol = RTE_ETHER_TYPE_IPV6;
6623 case RTE_FLOW_ITEM_TYPE_ETH:
6624 if (item->mask && item->spec) {
6625 MLX5_ETHER_TYPE_FROM_HEADER(rte_flow_item_eth,
6628 if (l3_protocol == RTE_ETHER_TYPE_IPV4 ||
6629 l3_protocol == RTE_ETHER_TYPE_IPV6)
6633 case RTE_FLOW_ITEM_TYPE_VLAN:
6634 if (item->mask && item->spec) {
6635 MLX5_ETHER_TYPE_FROM_HEADER(rte_flow_item_vlan,
6638 if (l3_protocol == RTE_ETHER_TYPE_IPV4 ||
6639 l3_protocol == RTE_ETHER_TYPE_IPV6)
6652 mlx5_flow_locate_proto_l4(const struct rte_flow_item **head,
6653 const struct rte_flow_item *end)
6655 const struct rte_flow_item *item = *head;
6656 uint8_t l4_protocol;
6658 for (; item != end; item++) {
6659 switch (item->type) {
6662 case RTE_FLOW_ITEM_TYPE_TCP:
6663 l4_protocol = IPPROTO_TCP;
6665 case RTE_FLOW_ITEM_TYPE_UDP:
6666 l4_protocol = IPPROTO_UDP;
6668 case RTE_FLOW_ITEM_TYPE_IPV4:
6669 if (item->mask && item->spec) {
6670 const struct rte_flow_item_ipv4 *mask, *spec;
6672 mask = (typeof(mask))item->mask;
6673 spec = (typeof(spec))item->spec;
6674 l4_protocol = mask->hdr.next_proto_id &
6675 spec->hdr.next_proto_id;
6676 if (l4_protocol == IPPROTO_TCP ||
6677 l4_protocol == IPPROTO_UDP)
6681 case RTE_FLOW_ITEM_TYPE_IPV6:
6682 if (item->mask && item->spec) {
6683 const struct rte_flow_item_ipv6 *mask, *spec;
6684 mask = (typeof(mask))item->mask;
6685 spec = (typeof(spec))item->spec;
6686 l4_protocol = mask->hdr.proto & spec->hdr.proto;
6687 if (l4_protocol == IPPROTO_TCP ||
6688 l4_protocol == IPPROTO_UDP)
6701 flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
6702 const struct rte_flow_item *rule_items,
6703 const struct rte_flow_item *integrity_item,
6704 struct rte_flow_error *error)
6706 struct mlx5_priv *priv = dev->data->dev_private;
6707 const struct rte_flow_item *tunnel_item, *end_item, *item = rule_items;
6708 const struct rte_flow_item_integrity *mask = (typeof(mask))
6709 integrity_item->mask;
6710 const struct rte_flow_item_integrity *spec = (typeof(spec))
6711 integrity_item->spec;
6714 if (!priv->config.hca_attr.pkt_integrity_match)
6715 return rte_flow_error_set(error, ENOTSUP,
6716 RTE_FLOW_ERROR_TYPE_ITEM,
6718 "packet integrity integrity_item not supported");
6720 mask = &rte_flow_item_integrity_mask;
6721 if (!mlx5_validate_integrity_item(mask))
6722 return rte_flow_error_set(error, ENOTSUP,
6723 RTE_FLOW_ERROR_TYPE_ITEM,
6725 "unsupported integrity filter");
6726 tunnel_item = mlx5_flow_find_tunnel_item(rule_items);
6727 if (spec->level > 1) {
6729 return rte_flow_error_set(error, ENOTSUP,
6730 RTE_FLOW_ERROR_TYPE_ITEM,
6732 "missing tunnel item");
6734 end_item = mlx5_find_end_item(tunnel_item);
6736 end_item = tunnel_item ? tunnel_item :
6737 mlx5_find_end_item(integrity_item);
6739 if (mask->l3_ok || mask->ipv4_csum_ok) {
6740 protocol = mlx5_flow_locate_proto_l3(&item, end_item);
6742 return rte_flow_error_set(error, EINVAL,
6743 RTE_FLOW_ERROR_TYPE_ITEM,
6745 "missing L3 protocol");
6747 if (mask->l4_ok || mask->l4_csum_ok) {
6748 protocol = mlx5_flow_locate_proto_l4(&item, end_item);
6750 return rte_flow_error_set(error, EINVAL,
6751 RTE_FLOW_ERROR_TYPE_ITEM,
6753 "missing L4 protocol");
6759 * Internal validation function. For validating both actions and items.
6762 * Pointer to the rte_eth_dev structure.
6764 * Pointer to the flow attributes.
6766 * Pointer to the list of items.
6767 * @param[in] actions
6768 * Pointer to the list of actions.
6769 * @param[in] external
6770 * This flow rule is created by request external to PMD.
6771 * @param[in] hairpin
6772 * Number of hairpin TX actions, 0 means classic flow.
6774 * Pointer to the error structure.
6777 * 0 on success, a negative errno value otherwise and rte_errno is set.
6780 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
6781 const struct rte_flow_item items[],
6782 const struct rte_flow_action actions[],
6783 bool external, int hairpin, struct rte_flow_error *error)
6786 uint64_t action_flags = 0;
6787 uint64_t item_flags = 0;
6788 uint64_t last_item = 0;
6789 uint8_t next_protocol = 0xff;
6790 uint16_t ether_type = 0;
6792 uint8_t item_ipv6_proto = 0;
6793 int fdb_mirror_limit = 0;
6794 int modify_after_mirror = 0;
6795 const struct rte_flow_item *geneve_item = NULL;
6796 const struct rte_flow_item *gre_item = NULL;
6797 const struct rte_flow_item *gtp_item = NULL;
6798 const struct rte_flow_action_raw_decap *decap;
6799 const struct rte_flow_action_raw_encap *encap;
6800 const struct rte_flow_action_rss *rss = NULL;
6801 const struct rte_flow_action_rss *sample_rss = NULL;
6802 const struct rte_flow_action_count *sample_count = NULL;
6803 const struct rte_flow_item_tcp nic_tcp_mask = {
6806 .src_port = RTE_BE16(UINT16_MAX),
6807 .dst_port = RTE_BE16(UINT16_MAX),
6810 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
6813 "\xff\xff\xff\xff\xff\xff\xff\xff"
6814 "\xff\xff\xff\xff\xff\xff\xff\xff",
6816 "\xff\xff\xff\xff\xff\xff\xff\xff"
6817 "\xff\xff\xff\xff\xff\xff\xff\xff",
6818 .vtc_flow = RTE_BE32(0xffffffff),
6824 const struct rte_flow_item_ecpri nic_ecpri_mask = {
6828 RTE_BE32(((const struct rte_ecpri_common_hdr) {
6832 .dummy[0] = 0xffffffff,
6835 struct mlx5_priv *priv = dev->data->dev_private;
6836 struct mlx5_dev_config *dev_conf = &priv->config;
6837 uint16_t queue_index = 0xFFFF;
6838 const struct rte_flow_item_vlan *vlan_m = NULL;
6839 uint32_t rw_act_num = 0;
6841 const struct mlx5_flow_tunnel *tunnel;
6842 enum mlx5_tof_rule_type tof_rule_type;
6843 struct flow_grp_info grp_info = {
6844 .external = !!external,
6845 .transfer = !!attr->transfer,
6846 .fdb_def_rule = !!priv->fdb_def_rule,
6847 .std_tbl_fix = true,
6849 const struct rte_eth_hairpin_conf *conf;
6850 const struct rte_flow_item *rule_items = items;
6851 const struct rte_flow_item *port_id_item = NULL;
6852 bool def_policy = false;
6853 uint16_t udp_dport = 0;
6857 tunnel = is_tunnel_offload_active(dev) ?
6858 mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
6860 if (priv->representor)
6861 return rte_flow_error_set
6863 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6864 NULL, "decap not supported for VF representor");
6865 if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
6866 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6867 else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
6868 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
6869 MLX5_FLOW_ACTION_DECAP;
6870 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
6871 (dev, attr, tunnel, tof_rule_type);
6873 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
6876 is_root = (uint64_t)ret;
6877 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6878 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
6879 int type = items->type;
6881 if (!mlx5_flow_os_item_supported(type))
6882 return rte_flow_error_set(error, ENOTSUP,
6883 RTE_FLOW_ERROR_TYPE_ITEM,
6884 NULL, "item not supported");
6886 case RTE_FLOW_ITEM_TYPE_VOID:
6888 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6889 ret = flow_dv_validate_item_port_id
6890 (dev, items, attr, item_flags, error);
6893 last_item = MLX5_FLOW_ITEM_PORT_ID;
6894 port_id_item = items;
6896 case RTE_FLOW_ITEM_TYPE_ETH:
6897 ret = mlx5_flow_validate_item_eth(items, item_flags,
6901 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
6902 MLX5_FLOW_LAYER_OUTER_L2;
6903 if (items->mask != NULL && items->spec != NULL) {
6905 ((const struct rte_flow_item_eth *)
6908 ((const struct rte_flow_item_eth *)
6910 ether_type = rte_be_to_cpu_16(ether_type);
6915 case RTE_FLOW_ITEM_TYPE_VLAN:
6916 ret = flow_dv_validate_item_vlan(items, item_flags,
6920 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
6921 MLX5_FLOW_LAYER_OUTER_VLAN;
6922 if (items->mask != NULL && items->spec != NULL) {
6924 ((const struct rte_flow_item_vlan *)
6925 items->spec)->inner_type;
6927 ((const struct rte_flow_item_vlan *)
6928 items->mask)->inner_type;
6929 ether_type = rte_be_to_cpu_16(ether_type);
6933 /* Store outer VLAN mask for of_push_vlan action. */
6935 vlan_m = items->mask;
6937 case RTE_FLOW_ITEM_TYPE_IPV4:
6938 mlx5_flow_tunnel_ip_check(items, next_protocol,
6939 &item_flags, &tunnel);
6940 ret = flow_dv_validate_item_ipv4(dev, items, item_flags,
6941 last_item, ether_type,
6945 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
6946 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
6947 if (items->mask != NULL &&
6948 ((const struct rte_flow_item_ipv4 *)
6949 items->mask)->hdr.next_proto_id) {
6951 ((const struct rte_flow_item_ipv4 *)
6952 (items->spec))->hdr.next_proto_id;
6954 ((const struct rte_flow_item_ipv4 *)
6955 (items->mask))->hdr.next_proto_id;
6957 /* Reset for inner layer. */
6958 next_protocol = 0xff;
6961 case RTE_FLOW_ITEM_TYPE_IPV6:
6962 mlx5_flow_tunnel_ip_check(items, next_protocol,
6963 &item_flags, &tunnel);
6964 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
6971 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
6972 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
6973 if (items->mask != NULL &&
6974 ((const struct rte_flow_item_ipv6 *)
6975 items->mask)->hdr.proto) {
6977 ((const struct rte_flow_item_ipv6 *)
6978 items->spec)->hdr.proto;
6980 ((const struct rte_flow_item_ipv6 *)
6981 items->spec)->hdr.proto;
6983 ((const struct rte_flow_item_ipv6 *)
6984 items->mask)->hdr.proto;
6986 /* Reset for inner layer. */
6987 next_protocol = 0xff;
6990 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
6991 ret = flow_dv_validate_item_ipv6_frag_ext(items,
6996 last_item = tunnel ?
6997 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
6998 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
6999 if (items->mask != NULL &&
7000 ((const struct rte_flow_item_ipv6_frag_ext *)
7001 items->mask)->hdr.next_header) {
7003 ((const struct rte_flow_item_ipv6_frag_ext *)
7004 items->spec)->hdr.next_header;
7006 ((const struct rte_flow_item_ipv6_frag_ext *)
7007 items->mask)->hdr.next_header;
7009 /* Reset for inner layer. */
7010 next_protocol = 0xff;
7013 case RTE_FLOW_ITEM_TYPE_TCP:
7014 ret = mlx5_flow_validate_item_tcp
7021 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7022 MLX5_FLOW_LAYER_OUTER_L4_TCP;
7024 case RTE_FLOW_ITEM_TYPE_UDP:
7025 ret = mlx5_flow_validate_item_udp(items, item_flags,
7028 const struct rte_flow_item_udp *spec = items->spec;
7029 const struct rte_flow_item_udp *mask = items->mask;
7031 mask = &rte_flow_item_udp_mask;
7033 udp_dport = rte_be_to_cpu_16
7034 (spec->hdr.dst_port &
7035 mask->hdr.dst_port);
7038 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
7039 MLX5_FLOW_LAYER_OUTER_L4_UDP;
7041 case RTE_FLOW_ITEM_TYPE_GRE:
7042 ret = mlx5_flow_validate_item_gre(items, item_flags,
7043 next_protocol, error);
7047 last_item = MLX5_FLOW_LAYER_GRE;
7049 case RTE_FLOW_ITEM_TYPE_NVGRE:
7050 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
7055 last_item = MLX5_FLOW_LAYER_NVGRE;
7057 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7058 ret = mlx5_flow_validate_item_gre_key
7059 (items, item_flags, gre_item, error);
7062 last_item = MLX5_FLOW_LAYER_GRE_KEY;
7064 case RTE_FLOW_ITEM_TYPE_VXLAN:
7065 ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
7070 last_item = MLX5_FLOW_LAYER_VXLAN;
7072 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7073 ret = mlx5_flow_validate_item_vxlan_gpe(items,
7078 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
7080 case RTE_FLOW_ITEM_TYPE_GENEVE:
7081 ret = mlx5_flow_validate_item_geneve(items,
7086 geneve_item = items;
7087 last_item = MLX5_FLOW_LAYER_GENEVE;
7089 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
7090 ret = mlx5_flow_validate_item_geneve_opt(items,
7097 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
7099 case RTE_FLOW_ITEM_TYPE_MPLS:
7100 ret = mlx5_flow_validate_item_mpls(dev, items,
7105 last_item = MLX5_FLOW_LAYER_MPLS;
7108 case RTE_FLOW_ITEM_TYPE_MARK:
7109 ret = flow_dv_validate_item_mark(dev, items, attr,
7113 last_item = MLX5_FLOW_ITEM_MARK;
7115 case RTE_FLOW_ITEM_TYPE_META:
7116 ret = flow_dv_validate_item_meta(dev, items, attr,
7120 last_item = MLX5_FLOW_ITEM_METADATA;
7122 case RTE_FLOW_ITEM_TYPE_ICMP:
7123 ret = mlx5_flow_validate_item_icmp(items, item_flags,
7128 last_item = MLX5_FLOW_LAYER_ICMP;
7130 case RTE_FLOW_ITEM_TYPE_ICMP6:
7131 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
7136 item_ipv6_proto = IPPROTO_ICMPV6;
7137 last_item = MLX5_FLOW_LAYER_ICMP6;
7139 case RTE_FLOW_ITEM_TYPE_TAG:
7140 ret = flow_dv_validate_item_tag(dev, items,
7144 last_item = MLX5_FLOW_ITEM_TAG;
7146 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7147 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
7149 case RTE_FLOW_ITEM_TYPE_GTP:
7150 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
7155 last_item = MLX5_FLOW_LAYER_GTP;
7157 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
7158 ret = flow_dv_validate_item_gtp_psc(items, last_item,
7163 last_item = MLX5_FLOW_LAYER_GTP_PSC;
7165 case RTE_FLOW_ITEM_TYPE_ECPRI:
7166 /* Capacity will be checked in the translate stage. */
7167 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
7174 last_item = MLX5_FLOW_LAYER_ECPRI;
7176 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
7177 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY)
7178 return rte_flow_error_set
7180 RTE_FLOW_ERROR_TYPE_ITEM,
7181 NULL, "multiple integrity items not supported");
7182 ret = flow_dv_validate_item_integrity(dev, rule_items,
7186 last_item = MLX5_FLOW_ITEM_INTEGRITY;
7188 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
7189 ret = flow_dv_validate_item_aso_ct(dev, items,
7190 &item_flags, error);
7194 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
7195 /* tunnel offload item was processed before
7196 * list it here as a supported type
7200 return rte_flow_error_set(error, ENOTSUP,
7201 RTE_FLOW_ERROR_TYPE_ITEM,
7202 NULL, "item not supported");
7204 item_flags |= last_item;
7206 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
7207 int type = actions->type;
7208 bool shared_count = false;
7210 if (!mlx5_flow_os_action_supported(type))
7211 return rte_flow_error_set(error, ENOTSUP,
7212 RTE_FLOW_ERROR_TYPE_ACTION,
7214 "action not supported");
7215 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
7216 return rte_flow_error_set(error, ENOTSUP,
7217 RTE_FLOW_ERROR_TYPE_ACTION,
7218 actions, "too many actions");
7220 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
7221 return rte_flow_error_set(error, ENOTSUP,
7222 RTE_FLOW_ERROR_TYPE_ACTION,
7223 NULL, "meter action with policy "
7224 "must be the last action");
7226 case RTE_FLOW_ACTION_TYPE_VOID:
7228 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7229 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
7230 ret = flow_dv_validate_action_port_id(dev,
7237 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7240 case RTE_FLOW_ACTION_TYPE_FLAG:
7241 ret = flow_dv_validate_action_flag(dev, action_flags,
7245 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7246 /* Count all modify-header actions as one. */
7247 if (!(action_flags &
7248 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7250 action_flags |= MLX5_FLOW_ACTION_FLAG |
7251 MLX5_FLOW_ACTION_MARK_EXT;
7252 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7253 modify_after_mirror = 1;
7256 action_flags |= MLX5_FLOW_ACTION_FLAG;
7259 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7261 case RTE_FLOW_ACTION_TYPE_MARK:
7262 ret = flow_dv_validate_action_mark(dev, actions,
7267 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7268 /* Count all modify-header actions as one. */
7269 if (!(action_flags &
7270 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7272 action_flags |= MLX5_FLOW_ACTION_MARK |
7273 MLX5_FLOW_ACTION_MARK_EXT;
7274 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7275 modify_after_mirror = 1;
7277 action_flags |= MLX5_FLOW_ACTION_MARK;
7280 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7282 case RTE_FLOW_ACTION_TYPE_SET_META:
7283 ret = flow_dv_validate_action_set_meta(dev, actions,
7288 /* Count all modify-header actions as one action. */
7289 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7291 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7292 modify_after_mirror = 1;
7293 action_flags |= MLX5_FLOW_ACTION_SET_META;
7294 rw_act_num += MLX5_ACT_NUM_SET_META;
7296 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7297 ret = flow_dv_validate_action_set_tag(dev, actions,
7302 /* Count all modify-header actions as one action. */
7303 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7305 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7306 modify_after_mirror = 1;
7307 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7308 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7310 case RTE_FLOW_ACTION_TYPE_DROP:
7311 ret = mlx5_flow_validate_action_drop(action_flags,
7315 action_flags |= MLX5_FLOW_ACTION_DROP;
7318 case RTE_FLOW_ACTION_TYPE_QUEUE:
7319 ret = mlx5_flow_validate_action_queue(actions,
7324 queue_index = ((const struct rte_flow_action_queue *)
7325 (actions->conf))->index;
7326 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7329 case RTE_FLOW_ACTION_TYPE_RSS:
7330 rss = actions->conf;
7331 ret = mlx5_flow_validate_action_rss(actions,
7337 if (rss && sample_rss &&
7338 (sample_rss->level != rss->level ||
7339 sample_rss->types != rss->types))
7340 return rte_flow_error_set(error, ENOTSUP,
7341 RTE_FLOW_ERROR_TYPE_ACTION,
7343 "Can't use the different RSS types "
7344 "or level in the same flow");
7345 if (rss != NULL && rss->queue_num)
7346 queue_index = rss->queue[0];
7347 action_flags |= MLX5_FLOW_ACTION_RSS;
7350 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7352 mlx5_flow_validate_action_default_miss(action_flags,
7356 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
7359 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
7360 shared_count = true;
7362 case RTE_FLOW_ACTION_TYPE_COUNT:
7363 ret = flow_dv_validate_action_count(dev, shared_count,
7368 action_flags |= MLX5_FLOW_ACTION_COUNT;
7371 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7372 if (flow_dv_validate_action_pop_vlan(dev,
7378 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7379 modify_after_mirror = 1;
7380 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7383 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7384 ret = flow_dv_validate_action_push_vlan(dev,
7391 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7392 modify_after_mirror = 1;
7393 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7396 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7397 ret = flow_dv_validate_action_set_vlan_pcp
7398 (action_flags, actions, error);
7401 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7402 modify_after_mirror = 1;
7403 /* Count PCP with push_vlan command. */
7404 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
7406 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7407 ret = flow_dv_validate_action_set_vlan_vid
7408 (item_flags, action_flags,
7412 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7413 modify_after_mirror = 1;
7414 /* Count VID with push_vlan command. */
7415 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7416 rw_act_num += MLX5_ACT_NUM_MDF_VID;
7418 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7419 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7420 ret = flow_dv_validate_action_l2_encap(dev,
7426 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7429 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7430 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7431 ret = flow_dv_validate_action_decap(dev, action_flags,
7432 actions, item_flags,
7436 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7437 modify_after_mirror = 1;
7438 action_flags |= MLX5_FLOW_ACTION_DECAP;
7441 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7442 ret = flow_dv_validate_action_raw_encap_decap
7443 (dev, NULL, actions->conf, attr, &action_flags,
7444 &actions_n, actions, item_flags, error);
7448 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7449 decap = actions->conf;
7450 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
7452 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7456 encap = actions->conf;
7458 ret = flow_dv_validate_action_raw_encap_decap
7460 decap ? decap : &empty_decap, encap,
7461 attr, &action_flags, &actions_n,
7462 actions, item_flags, error);
7465 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7466 (action_flags & MLX5_FLOW_ACTION_DECAP))
7467 modify_after_mirror = 1;
7469 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7470 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7471 ret = flow_dv_validate_action_modify_mac(action_flags,
7477 /* Count all modify-header actions as one action. */
7478 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7480 action_flags |= actions->type ==
7481 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7482 MLX5_FLOW_ACTION_SET_MAC_SRC :
7483 MLX5_FLOW_ACTION_SET_MAC_DST;
7484 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7485 modify_after_mirror = 1;
7487 * Even if the source and destination MAC addresses have
7488 * overlap in the header with 4B alignment, the convert
7489 * function will handle them separately and 4 SW actions
7490 * will be created. And 2 actions will be added each
7491 * time no matter how many bytes of address will be set.
7493 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
7495 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7496 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7497 ret = flow_dv_validate_action_modify_ipv4(action_flags,
7503 /* Count all modify-header actions as one action. */
7504 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7506 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7507 modify_after_mirror = 1;
7508 action_flags |= actions->type ==
7509 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7510 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7511 MLX5_FLOW_ACTION_SET_IPV4_DST;
7512 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
7514 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7515 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7516 ret = flow_dv_validate_action_modify_ipv6(action_flags,
7522 if (item_ipv6_proto == IPPROTO_ICMPV6)
7523 return rte_flow_error_set(error, ENOTSUP,
7524 RTE_FLOW_ERROR_TYPE_ACTION,
7526 "Can't change header "
7527 "with ICMPv6 proto");
7528 /* Count all modify-header actions as one action. */
7529 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7531 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7532 modify_after_mirror = 1;
7533 action_flags |= actions->type ==
7534 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7535 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7536 MLX5_FLOW_ACTION_SET_IPV6_DST;
7537 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
7539 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7540 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7541 ret = flow_dv_validate_action_modify_tp(action_flags,
7547 /* Count all modify-header actions as one action. */
7548 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7550 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7551 modify_after_mirror = 1;
7552 action_flags |= actions->type ==
7553 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7554 MLX5_FLOW_ACTION_SET_TP_SRC :
7555 MLX5_FLOW_ACTION_SET_TP_DST;
7556 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
7558 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7559 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7560 ret = flow_dv_validate_action_modify_ttl(action_flags,
7566 /* Count all modify-header actions as one action. */
7567 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7569 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7570 modify_after_mirror = 1;
7571 action_flags |= actions->type ==
7572 RTE_FLOW_ACTION_TYPE_SET_TTL ?
7573 MLX5_FLOW_ACTION_SET_TTL :
7574 MLX5_FLOW_ACTION_DEC_TTL;
7575 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
7577 case RTE_FLOW_ACTION_TYPE_JUMP:
7578 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
7584 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7586 return rte_flow_error_set(error, EINVAL,
7587 RTE_FLOW_ERROR_TYPE_ACTION,
7589 "sample and jump action combination is not supported");
7591 action_flags |= MLX5_FLOW_ACTION_JUMP;
7593 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7594 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7595 ret = flow_dv_validate_action_modify_tcp_seq
7602 /* Count all modify-header actions as one action. */
7603 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7605 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7606 modify_after_mirror = 1;
7607 action_flags |= actions->type ==
7608 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7609 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7610 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7611 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
7613 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7614 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7615 ret = flow_dv_validate_action_modify_tcp_ack
7622 /* Count all modify-header actions as one action. */
7623 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7625 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7626 modify_after_mirror = 1;
7627 action_flags |= actions->type ==
7628 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7629 MLX5_FLOW_ACTION_INC_TCP_ACK :
7630 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7631 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
7633 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7635 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7636 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7637 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7639 case RTE_FLOW_ACTION_TYPE_METER:
7640 ret = mlx5_flow_validate_action_meter(dev,
7648 action_flags |= MLX5_FLOW_ACTION_METER;
7651 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
7653 /* Meter action will add one more TAG action. */
7654 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7656 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
7657 if (!attr->transfer && !attr->group)
7658 return rte_flow_error_set(error, ENOTSUP,
7659 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7661 "Shared ASO age action is not supported for group 0");
7662 if (action_flags & MLX5_FLOW_ACTION_AGE)
7663 return rte_flow_error_set
7665 RTE_FLOW_ERROR_TYPE_ACTION,
7667 "duplicate age actions set");
7668 action_flags |= MLX5_FLOW_ACTION_AGE;
7671 case RTE_FLOW_ACTION_TYPE_AGE:
7672 ret = flow_dv_validate_action_age(action_flags,
7678 * Validate the regular AGE action (using counter)
7679 * mutual exclusion with share counter actions.
7681 if (!priv->sh->flow_hit_aso_en) {
7683 return rte_flow_error_set
7685 RTE_FLOW_ERROR_TYPE_ACTION,
7687 "old age and shared count combination is not supported");
7689 return rte_flow_error_set
7691 RTE_FLOW_ERROR_TYPE_ACTION,
7693 "old age action and count must be in the same sub flow");
7695 action_flags |= MLX5_FLOW_ACTION_AGE;
7698 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7699 ret = flow_dv_validate_action_modify_ipv4_dscp
7706 /* Count all modify-header actions as one action. */
7707 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7709 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7710 modify_after_mirror = 1;
7711 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7712 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7714 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7715 ret = flow_dv_validate_action_modify_ipv6_dscp
7722 /* Count all modify-header actions as one action. */
7723 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7725 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7726 modify_after_mirror = 1;
7727 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7728 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7730 case RTE_FLOW_ACTION_TYPE_SAMPLE:
7731 ret = flow_dv_validate_action_sample(&action_flags,
7740 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
7743 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7744 ret = flow_dv_validate_action_modify_field(dev,
7751 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7752 modify_after_mirror = 1;
7753 /* Count all modify-header actions as one action. */
7754 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7756 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
7759 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7760 ret = flow_dv_validate_action_aso_ct(dev, action_flags,
7765 action_flags |= MLX5_FLOW_ACTION_CT;
7767 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
7768 /* tunnel offload action was processed before
7769 * list it here as a supported type
7773 return rte_flow_error_set(error, ENOTSUP,
7774 RTE_FLOW_ERROR_TYPE_ACTION,
7776 "action not supported");
7780 * Validate actions in flow rules
7781 * - Explicit decap action is prohibited by the tunnel offload API.
7782 * - Drop action in tunnel steer rule is prohibited by the API.
7783 * - Application cannot use MARK action because it's value can mask
7784 * tunnel default miss nitification.
7785 * - JUMP in tunnel match rule has no support in current PMD
7787 * - TAG & META are reserved for future uses.
7789 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
7790 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
7791 MLX5_FLOW_ACTION_MARK |
7792 MLX5_FLOW_ACTION_SET_TAG |
7793 MLX5_FLOW_ACTION_SET_META |
7794 MLX5_FLOW_ACTION_DROP;
7796 if (action_flags & bad_actions_mask)
7797 return rte_flow_error_set
7799 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7800 "Invalid RTE action in tunnel "
7802 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
7803 return rte_flow_error_set
7805 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7806 "tunnel set decap rule must terminate "
7809 return rte_flow_error_set
7811 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7812 "tunnel flows for ingress traffic only");
7814 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
7815 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
7816 MLX5_FLOW_ACTION_MARK |
7817 MLX5_FLOW_ACTION_SET_TAG |
7818 MLX5_FLOW_ACTION_SET_META;
7820 if (action_flags & bad_actions_mask)
7821 return rte_flow_error_set
7823 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7824 "Invalid RTE action in tunnel "
7828 * Validate the drop action mutual exclusion with other actions.
7829 * Drop action is mutually-exclusive with any other action, except for
7831 * Drop action compatibility with tunnel offload was already validated.
7833 if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
7834 MLX5_FLOW_ACTION_TUNNEL_MATCH));
7835 else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
7836 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
7837 return rte_flow_error_set(error, EINVAL,
7838 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7839 "Drop action is mutually-exclusive "
7840 "with any other action, except for "
7842 /* Eswitch has few restrictions on using items and actions */
7843 if (attr->transfer) {
7844 if (!mlx5_flow_ext_mreg_supported(dev) &&
7845 action_flags & MLX5_FLOW_ACTION_FLAG)
7846 return rte_flow_error_set(error, ENOTSUP,
7847 RTE_FLOW_ERROR_TYPE_ACTION,
7849 "unsupported action FLAG");
7850 if (!mlx5_flow_ext_mreg_supported(dev) &&
7851 action_flags & MLX5_FLOW_ACTION_MARK)
7852 return rte_flow_error_set(error, ENOTSUP,
7853 RTE_FLOW_ERROR_TYPE_ACTION,
7855 "unsupported action MARK");
7856 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
7857 return rte_flow_error_set(error, ENOTSUP,
7858 RTE_FLOW_ERROR_TYPE_ACTION,
7860 "unsupported action QUEUE");
7861 if (action_flags & MLX5_FLOW_ACTION_RSS)
7862 return rte_flow_error_set(error, ENOTSUP,
7863 RTE_FLOW_ERROR_TYPE_ACTION,
7865 "unsupported action RSS");
7866 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
7867 return rte_flow_error_set(error, EINVAL,
7868 RTE_FLOW_ERROR_TYPE_ACTION,
7870 "no fate action is found");
7872 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
7873 return rte_flow_error_set(error, EINVAL,
7874 RTE_FLOW_ERROR_TYPE_ACTION,
7876 "no fate action is found");
7879 * Continue validation for Xcap and VLAN actions.
7880 * If hairpin is working in explicit TX rule mode, there is no actions
7881 * splitting and the validation of hairpin ingress flow should be the
7882 * same as other standard flows.
7884 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
7885 MLX5_FLOW_VLAN_ACTIONS)) &&
7886 (queue_index == 0xFFFF ||
7887 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN ||
7888 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
7889 conf->tx_explicit != 0))) {
7890 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
7891 MLX5_FLOW_XCAP_ACTIONS)
7892 return rte_flow_error_set(error, ENOTSUP,
7893 RTE_FLOW_ERROR_TYPE_ACTION,
7894 NULL, "encap and decap "
7895 "combination aren't supported");
7896 if (!attr->transfer && attr->ingress) {
7897 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7898 return rte_flow_error_set
7900 RTE_FLOW_ERROR_TYPE_ACTION,
7901 NULL, "encap is not supported"
7902 " for ingress traffic");
7903 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7904 return rte_flow_error_set
7906 RTE_FLOW_ERROR_TYPE_ACTION,
7907 NULL, "push VLAN action not "
7908 "supported for ingress");
7909 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
7910 MLX5_FLOW_VLAN_ACTIONS)
7911 return rte_flow_error_set
7913 RTE_FLOW_ERROR_TYPE_ACTION,
7914 NULL, "no support for "
7915 "multiple VLAN actions");
7918 if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
7919 if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
7920 ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
7922 return rte_flow_error_set
7924 RTE_FLOW_ERROR_TYPE_ACTION,
7925 NULL, "fate action not supported for "
7926 "meter with policy");
7928 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
7929 return rte_flow_error_set
7931 RTE_FLOW_ERROR_TYPE_ACTION,
7932 NULL, "modify header action in egress "
7933 "cannot be done before meter action");
7934 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7935 return rte_flow_error_set
7937 RTE_FLOW_ERROR_TYPE_ACTION,
7938 NULL, "encap action in egress "
7939 "cannot be done before meter action");
7940 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7941 return rte_flow_error_set
7943 RTE_FLOW_ERROR_TYPE_ACTION,
7944 NULL, "push vlan action in egress "
7945 "cannot be done before meter action");
7949 * Hairpin flow will add one more TAG action in TX implicit mode.
7950 * In TX explicit mode, there will be no hairpin flow ID.
7953 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7954 /* extra metadata enabled: one more TAG action will be add. */
7955 if (dev_conf->dv_flow_en &&
7956 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
7957 mlx5_flow_ext_mreg_supported(dev))
7958 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7960 flow_dv_modify_hdr_action_max(dev, is_root)) {
7961 return rte_flow_error_set(error, ENOTSUP,
7962 RTE_FLOW_ERROR_TYPE_ACTION,
7963 NULL, "too many header modify"
7964 " actions to support");
7966 /* Eswitch egress mirror and modify flow has limitation on CX5 */
7967 if (fdb_mirror_limit && modify_after_mirror)
7968 return rte_flow_error_set(error, EINVAL,
7969 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7970 "sample before modify action is not supported");
7975 * Internal preparation function. Allocates the DV flow size,
7976 * this size is constant.
7979 * Pointer to the rte_eth_dev structure.
7981 * Pointer to the flow attributes.
7983 * Pointer to the list of items.
7984 * @param[in] actions
7985 * Pointer to the list of actions.
7987 * Pointer to the error structure.
7990 * Pointer to mlx5_flow object on success,
7991 * otherwise NULL and rte_errno is set.
7993 static struct mlx5_flow *
7994 flow_dv_prepare(struct rte_eth_dev *dev,
7995 const struct rte_flow_attr *attr __rte_unused,
7996 const struct rte_flow_item items[] __rte_unused,
7997 const struct rte_flow_action actions[] __rte_unused,
7998 struct rte_flow_error *error)
8000 uint32_t handle_idx = 0;
8001 struct mlx5_flow *dev_flow;
8002 struct mlx5_flow_handle *dev_handle;
8003 struct mlx5_priv *priv = dev->data->dev_private;
8004 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
8007 wks->skip_matcher_reg = 0;
8009 wks->final_policy = NULL;
8010 /* In case of corrupting the memory. */
8011 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
8012 rte_flow_error_set(error, ENOSPC,
8013 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8014 "not free temporary device flow");
8017 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
8020 rte_flow_error_set(error, ENOMEM,
8021 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8022 "not enough memory to create flow handle");
8025 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
8026 dev_flow = &wks->flows[wks->flow_idx++];
8027 memset(dev_flow, 0, sizeof(*dev_flow));
8028 dev_flow->handle = dev_handle;
8029 dev_flow->handle_idx = handle_idx;
8030 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
8031 dev_flow->ingress = attr->ingress;
8032 dev_flow->dv.transfer = attr->transfer;
8036 #ifdef RTE_LIBRTE_MLX5_DEBUG
8038 * Sanity check for match mask and value. Similar to check_valid_spec() in
8039 * kernel driver. If unmasked bit is present in value, it returns failure.
8042 * pointer to match mask buffer.
8043 * @param match_value
8044 * pointer to match value buffer.
8047 * 0 if valid, -EINVAL otherwise.
8050 flow_dv_check_valid_spec(void *match_mask, void *match_value)
8052 uint8_t *m = match_mask;
8053 uint8_t *v = match_value;
8056 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
8059 "match_value differs from match_criteria"
8060 " %p[%u] != %p[%u]",
8061 match_value, i, match_mask, i);
8070 * Add match of ip_version.
8074 * @param[in] headers_v
8075 * Values header pointer.
8076 * @param[in] headers_m
8077 * Masks header pointer.
8078 * @param[in] ip_version
8079 * The IP version to set.
8082 flow_dv_set_match_ip_version(uint32_t group,
8088 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
8090 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
8092 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
8093 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
8094 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
8098 * Add Ethernet item to matcher and to the value.
8100 * @param[in, out] matcher
8102 * @param[in, out] key
8103 * Flow matcher value.
8105 * Flow pattern to translate.
8107 * Item is inner pattern.
8110 flow_dv_translate_item_eth(void *matcher, void *key,
8111 const struct rte_flow_item *item, int inner,
8114 const struct rte_flow_item_eth *eth_m = item->mask;
8115 const struct rte_flow_item_eth *eth_v = item->spec;
8116 const struct rte_flow_item_eth nic_mask = {
8117 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8118 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8119 .type = RTE_BE16(0xffff),
8132 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8134 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8136 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8138 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8140 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
8141 ð_m->dst, sizeof(eth_m->dst));
8142 /* The value must be in the range of the mask. */
8143 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
8144 for (i = 0; i < sizeof(eth_m->dst); ++i)
8145 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
8146 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
8147 ð_m->src, sizeof(eth_m->src));
8148 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
8149 /* The value must be in the range of the mask. */
8150 for (i = 0; i < sizeof(eth_m->dst); ++i)
8151 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
8153 * HW supports match on one Ethertype, the Ethertype following the last
8154 * VLAN tag of the packet (see PRM).
8155 * Set match on ethertype only if ETH header is not followed by VLAN.
8156 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8157 * ethertype, and use ip_version field instead.
8158 * eCPRI over Ether layer will use type value 0xAEFE.
8160 if (eth_m->type == 0xFFFF) {
8161 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
8162 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8163 switch (eth_v->type) {
8164 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8165 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8167 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
8168 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8169 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8171 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8172 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8174 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8175 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8181 if (eth_m->has_vlan) {
8182 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8183 if (eth_v->has_vlan) {
8185 * Here, when also has_more_vlan field in VLAN item is
8186 * not set, only single-tagged packets will be matched.
8188 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8192 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8193 rte_be_to_cpu_16(eth_m->type));
8194 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
8195 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
8199 * Add VLAN item to matcher and to the value.
8201 * @param[in, out] dev_flow
8203 * @param[in, out] matcher
8205 * @param[in, out] key
8206 * Flow matcher value.
8208 * Flow pattern to translate.
8210 * Item is inner pattern.
8213 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
8214 void *matcher, void *key,
8215 const struct rte_flow_item *item,
8216 int inner, uint32_t group)
8218 const struct rte_flow_item_vlan *vlan_m = item->mask;
8219 const struct rte_flow_item_vlan *vlan_v = item->spec;
8226 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8228 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8230 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8232 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8234 * This is workaround, masks are not supported,
8235 * and pre-validated.
8238 dev_flow->handle->vf_vlan.tag =
8239 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
8242 * When VLAN item exists in flow, mark packet as tagged,
8243 * even if TCI is not specified.
8245 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
8246 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8247 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8252 vlan_m = &rte_flow_item_vlan_mask;
8253 tci_m = rte_be_to_cpu_16(vlan_m->tci);
8254 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
8255 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
8256 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
8257 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
8258 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
8259 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
8260 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
8262 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8263 * ethertype, and use ip_version field instead.
8265 if (vlan_m->inner_type == 0xFFFF) {
8266 switch (vlan_v->inner_type) {
8267 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8268 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8269 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8270 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8272 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8273 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8275 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8276 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8282 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
8283 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8284 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8285 /* Only one vlan_tag bit can be set. */
8286 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8289 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8290 rte_be_to_cpu_16(vlan_m->inner_type));
8291 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
8292 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
8296 * Add IPV4 item to matcher and to the value.
8298 * @param[in, out] matcher
8300 * @param[in, out] key
8301 * Flow matcher value.
8303 * Flow pattern to translate.
8305 * Item is inner pattern.
8307 * The group to insert the rule.
8310 flow_dv_translate_item_ipv4(void *matcher, void *key,
8311 const struct rte_flow_item *item,
8312 int inner, uint32_t group)
8314 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
8315 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
8316 const struct rte_flow_item_ipv4 nic_mask = {
8318 .src_addr = RTE_BE32(0xffffffff),
8319 .dst_addr = RTE_BE32(0xffffffff),
8320 .type_of_service = 0xff,
8321 .next_proto_id = 0xff,
8322 .time_to_live = 0xff,
8329 uint8_t tos, ihl_m, ihl_v;
8332 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8334 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8336 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8338 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8340 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
8345 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8346 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8347 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8348 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8349 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
8350 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
8351 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8352 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8353 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8354 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8355 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
8356 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
8357 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
8358 ihl_m = ipv4_m->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8359 ihl_v = ipv4_v->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8360 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_ihl, ihl_m);
8361 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl, ihl_m & ihl_v);
8362 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
8363 ipv4_m->hdr.type_of_service);
8364 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
8365 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
8366 ipv4_m->hdr.type_of_service >> 2);
8367 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
8368 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8369 ipv4_m->hdr.next_proto_id);
8370 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8371 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
8372 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8373 ipv4_m->hdr.time_to_live);
8374 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8375 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
8376 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8377 !!(ipv4_m->hdr.fragment_offset));
8378 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8379 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
8383 * Add IPV6 item to matcher and to the value.
8385 * @param[in, out] matcher
8387 * @param[in, out] key
8388 * Flow matcher value.
8390 * Flow pattern to translate.
8392 * Item is inner pattern.
8394 * The group to insert the rule.
8397 flow_dv_translate_item_ipv6(void *matcher, void *key,
8398 const struct rte_flow_item *item,
8399 int inner, uint32_t group)
8401 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
8402 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
8403 const struct rte_flow_item_ipv6 nic_mask = {
8406 "\xff\xff\xff\xff\xff\xff\xff\xff"
8407 "\xff\xff\xff\xff\xff\xff\xff\xff",
8409 "\xff\xff\xff\xff\xff\xff\xff\xff"
8410 "\xff\xff\xff\xff\xff\xff\xff\xff",
8411 .vtc_flow = RTE_BE32(0xffffffff),
8418 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8419 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8428 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8430 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8432 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8434 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8436 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
8441 size = sizeof(ipv6_m->hdr.dst_addr);
8442 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8443 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8444 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8445 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8446 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
8447 for (i = 0; i < size; ++i)
8448 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
8449 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8450 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8451 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8452 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8453 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
8454 for (i = 0; i < size; ++i)
8455 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
8457 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
8458 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
8459 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
8460 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
8461 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
8462 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
8465 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
8467 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
8470 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
8472 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
8476 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8478 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8479 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
8481 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8482 ipv6_m->hdr.hop_limits);
8483 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8484 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
8485 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8486 !!(ipv6_m->has_frag_ext));
8487 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8488 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
8492 * Add IPV6 fragment extension item to matcher and to the value.
8494 * @param[in, out] matcher
8496 * @param[in, out] key
8497 * Flow matcher value.
8499 * Flow pattern to translate.
8501 * Item is inner pattern.
8504 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
8505 const struct rte_flow_item *item,
8508 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
8509 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
8510 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
8512 .next_header = 0xff,
8513 .frag_data = RTE_BE16(0xffff),
8520 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8522 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8524 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8526 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8528 /* IPv6 fragment extension item exists, so packet is IP fragment. */
8529 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
8530 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
8531 if (!ipv6_frag_ext_v)
8533 if (!ipv6_frag_ext_m)
8534 ipv6_frag_ext_m = &nic_mask;
8535 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8536 ipv6_frag_ext_m->hdr.next_header);
8537 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8538 ipv6_frag_ext_v->hdr.next_header &
8539 ipv6_frag_ext_m->hdr.next_header);
8543 * Add TCP item to matcher and to the value.
8545 * @param[in, out] matcher
8547 * @param[in, out] key
8548 * Flow matcher value.
8550 * Flow pattern to translate.
8552 * Item is inner pattern.
8555 flow_dv_translate_item_tcp(void *matcher, void *key,
8556 const struct rte_flow_item *item,
8559 const struct rte_flow_item_tcp *tcp_m = item->mask;
8560 const struct rte_flow_item_tcp *tcp_v = item->spec;
8565 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8567 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8569 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8571 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8573 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8574 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
8578 tcp_m = &rte_flow_item_tcp_mask;
8579 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
8580 rte_be_to_cpu_16(tcp_m->hdr.src_port));
8581 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
8582 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
8583 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
8584 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
8585 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
8586 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
8587 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
8588 tcp_m->hdr.tcp_flags);
8589 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
8590 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
8594 * Add UDP item to matcher and to the value.
8596 * @param[in, out] matcher
8598 * @param[in, out] key
8599 * Flow matcher value.
8601 * Flow pattern to translate.
8603 * Item is inner pattern.
8606 flow_dv_translate_item_udp(void *matcher, void *key,
8607 const struct rte_flow_item *item,
8610 const struct rte_flow_item_udp *udp_m = item->mask;
8611 const struct rte_flow_item_udp *udp_v = item->spec;
8616 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8618 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8620 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8622 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8624 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8625 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
8629 udp_m = &rte_flow_item_udp_mask;
8630 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
8631 rte_be_to_cpu_16(udp_m->hdr.src_port));
8632 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
8633 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
8634 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
8635 rte_be_to_cpu_16(udp_m->hdr.dst_port));
8636 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8637 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
8641 * Add GRE optional Key item to matcher and to the value.
8643 * @param[in, out] matcher
8645 * @param[in, out] key
8646 * Flow matcher value.
8648 * Flow pattern to translate.
8650 * Item is inner pattern.
8653 flow_dv_translate_item_gre_key(void *matcher, void *key,
8654 const struct rte_flow_item *item)
8656 const rte_be32_t *key_m = item->mask;
8657 const rte_be32_t *key_v = item->spec;
8658 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8659 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8660 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
8662 /* GRE K bit must be on and should already be validated */
8663 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
8664 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
8668 key_m = &gre_key_default_mask;
8669 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
8670 rte_be_to_cpu_32(*key_m) >> 8);
8671 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
8672 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
8673 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
8674 rte_be_to_cpu_32(*key_m) & 0xFF);
8675 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
8676 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
8680 * Add GRE item to matcher and to the value.
8682 * @param[in, out] matcher
8684 * @param[in, out] key
8685 * Flow matcher value.
8687 * Flow pattern to translate.
8689 * Item is inner pattern.
8692 flow_dv_translate_item_gre(void *matcher, void *key,
8693 const struct rte_flow_item *item,
8696 const struct rte_flow_item_gre *gre_m = item->mask;
8697 const struct rte_flow_item_gre *gre_v = item->spec;
8700 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8701 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8708 uint16_t s_present:1;
8709 uint16_t k_present:1;
8710 uint16_t rsvd_bit1:1;
8711 uint16_t c_present:1;
8715 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
8718 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8720 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8722 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8724 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8726 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8727 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
8731 gre_m = &rte_flow_item_gre_mask;
8732 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
8733 rte_be_to_cpu_16(gre_m->protocol));
8734 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8735 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
8736 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
8737 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
8738 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
8739 gre_crks_rsvd0_ver_m.c_present);
8740 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
8741 gre_crks_rsvd0_ver_v.c_present &
8742 gre_crks_rsvd0_ver_m.c_present);
8743 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
8744 gre_crks_rsvd0_ver_m.k_present);
8745 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
8746 gre_crks_rsvd0_ver_v.k_present &
8747 gre_crks_rsvd0_ver_m.k_present);
8748 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
8749 gre_crks_rsvd0_ver_m.s_present);
8750 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
8751 gre_crks_rsvd0_ver_v.s_present &
8752 gre_crks_rsvd0_ver_m.s_present);
8756 * Add NVGRE item to matcher and to the value.
8758 * @param[in, out] matcher
8760 * @param[in, out] key
8761 * Flow matcher value.
8763 * Flow pattern to translate.
8765 * Item is inner pattern.
8768 flow_dv_translate_item_nvgre(void *matcher, void *key,
8769 const struct rte_flow_item *item,
8772 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
8773 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
8774 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8775 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8776 const char *tni_flow_id_m;
8777 const char *tni_flow_id_v;
8783 /* For NVGRE, GRE header fields must be set with defined values. */
8784 const struct rte_flow_item_gre gre_spec = {
8785 .c_rsvd0_ver = RTE_BE16(0x2000),
8786 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
8788 const struct rte_flow_item_gre gre_mask = {
8789 .c_rsvd0_ver = RTE_BE16(0xB000),
8790 .protocol = RTE_BE16(UINT16_MAX),
8792 const struct rte_flow_item gre_item = {
8797 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
8801 nvgre_m = &rte_flow_item_nvgre_mask;
8802 tni_flow_id_m = (const char *)nvgre_m->tni;
8803 tni_flow_id_v = (const char *)nvgre_v->tni;
8804 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
8805 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
8806 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
8807 memcpy(gre_key_m, tni_flow_id_m, size);
8808 for (i = 0; i < size; ++i)
8809 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
8813 * Add VXLAN item to matcher and to the value.
8816 * Pointer to the Ethernet device structure.
8818 * Flow rule attributes.
8819 * @param[in, out] matcher
8821 * @param[in, out] key
8822 * Flow matcher value.
8824 * Flow pattern to translate.
8826 * Item is inner pattern.
8829 flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
8830 const struct rte_flow_attr *attr,
8831 void *matcher, void *key,
8832 const struct rte_flow_item *item,
8835 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
8836 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
8841 uint32_t *tunnel_header_v;
8842 uint32_t *tunnel_header_m;
8844 struct mlx5_priv *priv = dev->data->dev_private;
8845 const struct rte_flow_item_vxlan nic_mask = {
8846 .vni = "\xff\xff\xff",
8851 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8853 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8855 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8857 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8859 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8860 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8861 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8862 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8863 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8865 dport = MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport);
8869 if ((!attr->group && !priv->sh->tunnel_header_0_1) ||
8870 (attr->group && !priv->sh->misc5_cap))
8871 vxlan_m = &rte_flow_item_vxlan_mask;
8873 vxlan_m = &nic_mask;
8875 if ((priv->sh->steering_format_version ==
8876 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
8877 dport != MLX5_UDP_PORT_VXLAN) ||
8878 (!attr->group && !attr->transfer && !priv->sh->tunnel_header_0_1) ||
8879 ((attr->group || attr->transfer) && !priv->sh->misc5_cap)) {
8886 misc_m = MLX5_ADDR_OF(fte_match_param,
8887 matcher, misc_parameters);
8888 misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8889 size = sizeof(vxlan_m->vni);
8890 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
8891 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
8892 memcpy(vni_m, vxlan_m->vni, size);
8893 for (i = 0; i < size; ++i)
8894 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8897 misc5_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_5);
8898 misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
8899 tunnel_header_v = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
8902 tunnel_header_m = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
8905 *tunnel_header_v = (vxlan_v->vni[0] & vxlan_m->vni[0]) |
8906 (vxlan_v->vni[1] & vxlan_m->vni[1]) << 8 |
8907 (vxlan_v->vni[2] & vxlan_m->vni[2]) << 16;
8908 if (*tunnel_header_v)
8909 *tunnel_header_m = vxlan_m->vni[0] |
8910 vxlan_m->vni[1] << 8 |
8911 vxlan_m->vni[2] << 16;
8913 *tunnel_header_m = 0x0;
8914 *tunnel_header_v |= (vxlan_v->rsvd1 & vxlan_m->rsvd1) << 24;
8915 if (vxlan_v->rsvd1 & vxlan_m->rsvd1)
8916 *tunnel_header_m |= vxlan_m->rsvd1 << 24;
8920 * Add VXLAN-GPE item to matcher and to the value.
8922 * @param[in, out] matcher
8924 * @param[in, out] key
8925 * Flow matcher value.
8927 * Flow pattern to translate.
8929 * Item is inner pattern.
8933 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
8934 const struct rte_flow_item *item, int inner)
8936 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
8937 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
8941 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
8943 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8949 uint8_t flags_m = 0xff;
8950 uint8_t flags_v = 0xc;
8953 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8955 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8957 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8959 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8961 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8962 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8963 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8964 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8965 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8970 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
8971 size = sizeof(vxlan_m->vni);
8972 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
8973 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
8974 memcpy(vni_m, vxlan_m->vni, size);
8975 for (i = 0; i < size; ++i)
8976 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8977 if (vxlan_m->flags) {
8978 flags_m = vxlan_m->flags;
8979 flags_v = vxlan_v->flags;
8981 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
8982 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
8983 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
8985 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
8990 * Add Geneve item to matcher and to the value.
8992 * @param[in, out] matcher
8994 * @param[in, out] key
8995 * Flow matcher value.
8997 * Flow pattern to translate.
8999 * Item is inner pattern.
9003 flow_dv_translate_item_geneve(void *matcher, void *key,
9004 const struct rte_flow_item *item, int inner)
9006 const struct rte_flow_item_geneve *geneve_m = item->mask;
9007 const struct rte_flow_item_geneve *geneve_v = item->spec;
9010 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9011 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9020 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9022 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9024 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9026 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9028 dport = MLX5_UDP_PORT_GENEVE;
9029 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9030 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9031 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
9036 geneve_m = &rte_flow_item_geneve_mask;
9037 size = sizeof(geneve_m->vni);
9038 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
9039 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
9040 memcpy(vni_m, geneve_m->vni, size);
9041 for (i = 0; i < size; ++i)
9042 vni_v[i] = vni_m[i] & geneve_v->vni[i];
9043 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
9044 rte_be_to_cpu_16(geneve_m->protocol));
9045 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
9046 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
9047 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
9048 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
9049 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
9050 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9051 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
9052 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9053 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9054 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9055 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9056 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
9057 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9061 * Create Geneve TLV option resource.
9063 * @param dev[in, out]
9064 * Pointer to rte_eth_dev structure.
9065 * @param[in, out] tag_be24
9066 * Tag value in big endian then R-shift 8.
9067 * @parm[in, out] dev_flow
9068 * Pointer to the dev_flow.
9070 * pointer to error structure.
9073 * 0 on success otherwise -errno and errno is set.
9077 flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
9078 const struct rte_flow_item *item,
9079 struct rte_flow_error *error)
9081 struct mlx5_priv *priv = dev->data->dev_private;
9082 struct mlx5_dev_ctx_shared *sh = priv->sh;
9083 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
9084 sh->geneve_tlv_option_resource;
9085 struct mlx5_devx_obj *obj;
9086 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9091 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
9092 if (geneve_opt_resource != NULL) {
9093 if (geneve_opt_resource->option_class ==
9094 geneve_opt_v->option_class &&
9095 geneve_opt_resource->option_type ==
9096 geneve_opt_v->option_type &&
9097 geneve_opt_resource->length ==
9098 geneve_opt_v->option_len) {
9099 /* We already have GENVE TLV option obj allocated. */
9100 __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
9103 ret = rte_flow_error_set(error, ENOMEM,
9104 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9105 "Only one GENEVE TLV option supported");
9109 /* Create a GENEVE TLV object and resource. */
9110 obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->ctx,
9111 geneve_opt_v->option_class,
9112 geneve_opt_v->option_type,
9113 geneve_opt_v->option_len);
9115 ret = rte_flow_error_set(error, ENODATA,
9116 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9117 "Failed to create GENEVE TLV Devx object");
9120 sh->geneve_tlv_option_resource =
9121 mlx5_malloc(MLX5_MEM_ZERO,
9122 sizeof(*geneve_opt_resource),
9124 if (!sh->geneve_tlv_option_resource) {
9125 claim_zero(mlx5_devx_cmd_destroy(obj));
9126 ret = rte_flow_error_set(error, ENOMEM,
9127 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9128 "GENEVE TLV object memory allocation failed");
9131 geneve_opt_resource = sh->geneve_tlv_option_resource;
9132 geneve_opt_resource->obj = obj;
9133 geneve_opt_resource->option_class = geneve_opt_v->option_class;
9134 geneve_opt_resource->option_type = geneve_opt_v->option_type;
9135 geneve_opt_resource->length = geneve_opt_v->option_len;
9136 __atomic_store_n(&geneve_opt_resource->refcnt, 1,
9140 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
9145 * Add Geneve TLV option item to matcher.
9147 * @param[in, out] dev
9148 * Pointer to rte_eth_dev structure.
9149 * @param[in, out] matcher
9151 * @param[in, out] key
9152 * Flow matcher value.
9154 * Flow pattern to translate.
9156 * Pointer to error structure.
9159 flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *matcher,
9160 void *key, const struct rte_flow_item *item,
9161 struct rte_flow_error *error)
9163 const struct rte_flow_item_geneve_opt *geneve_opt_m = item->mask;
9164 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9165 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9166 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9167 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9169 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9170 rte_be32_t opt_data_key = 0, opt_data_mask = 0;
9176 geneve_opt_m = &rte_flow_item_geneve_opt_mask;
9177 ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
9180 DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
9184 * Set the option length in GENEVE header if not requested.
9185 * The GENEVE TLV option length is expressed by the option length field
9186 * in the GENEVE header.
9187 * If the option length was not requested but the GENEVE TLV option item
9188 * is present we set the option length field implicitly.
9190 if (!MLX5_GET16(fte_match_set_misc, misc_m, geneve_opt_len)) {
9191 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9192 MLX5_GENEVE_OPTLEN_MASK);
9193 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9194 geneve_opt_v->option_len + 1);
9196 MLX5_SET(fte_match_set_misc, misc_m, geneve_tlv_option_0_exist, 1);
9197 MLX5_SET(fte_match_set_misc, misc_v, geneve_tlv_option_0_exist, 1);
9199 if (geneve_opt_v->data) {
9200 memcpy(&opt_data_key, geneve_opt_v->data,
9201 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9202 sizeof(opt_data_key)));
9203 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9204 sizeof(opt_data_key));
9205 memcpy(&opt_data_mask, geneve_opt_m->data,
9206 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9207 sizeof(opt_data_mask)));
9208 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9209 sizeof(opt_data_mask));
9210 MLX5_SET(fte_match_set_misc3, misc3_m,
9211 geneve_tlv_option_0_data,
9212 rte_be_to_cpu_32(opt_data_mask));
9213 MLX5_SET(fte_match_set_misc3, misc3_v,
9214 geneve_tlv_option_0_data,
9215 rte_be_to_cpu_32(opt_data_key & opt_data_mask));
9221 * Add MPLS item to matcher and to the value.
9223 * @param[in, out] matcher
9225 * @param[in, out] key
9226 * Flow matcher value.
9228 * Flow pattern to translate.
9229 * @param[in] prev_layer
9230 * The protocol layer indicated in previous item.
9232 * Item is inner pattern.
9235 flow_dv_translate_item_mpls(void *matcher, void *key,
9236 const struct rte_flow_item *item,
9237 uint64_t prev_layer,
9240 const uint32_t *in_mpls_m = item->mask;
9241 const uint32_t *in_mpls_v = item->spec;
9242 uint32_t *out_mpls_m = 0;
9243 uint32_t *out_mpls_v = 0;
9244 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9245 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9246 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
9248 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9249 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9250 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9252 switch (prev_layer) {
9253 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9254 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
9255 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9256 MLX5_UDP_PORT_MPLS);
9258 case MLX5_FLOW_LAYER_GRE:
9260 case MLX5_FLOW_LAYER_GRE_KEY:
9261 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
9262 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9263 RTE_ETHER_TYPE_MPLS);
9271 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
9272 switch (prev_layer) {
9273 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9275 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9276 outer_first_mpls_over_udp);
9278 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9279 outer_first_mpls_over_udp);
9281 case MLX5_FLOW_LAYER_GRE:
9283 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9284 outer_first_mpls_over_gre);
9286 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9287 outer_first_mpls_over_gre);
9290 /* Inner MPLS not over GRE is not supported. */
9293 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9297 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9303 if (out_mpls_m && out_mpls_v) {
9304 *out_mpls_m = *in_mpls_m;
9305 *out_mpls_v = *in_mpls_v & *in_mpls_m;
9310 * Add metadata register item to matcher
9312 * @param[in, out] matcher
9314 * @param[in, out] key
9315 * Flow matcher value.
9316 * @param[in] reg_type
9317 * Type of device metadata register
9324 flow_dv_match_meta_reg(void *matcher, void *key,
9325 enum modify_reg reg_type,
9326 uint32_t data, uint32_t mask)
9329 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
9331 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9337 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
9338 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
9341 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
9342 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
9346 * The metadata register C0 field might be divided into
9347 * source vport index and META item value, we should set
9348 * this field according to specified mask, not as whole one.
9350 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
9352 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
9353 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
9356 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
9359 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
9360 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
9363 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
9364 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
9367 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
9368 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
9371 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
9372 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
9375 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
9376 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
9379 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
9380 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
9383 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
9384 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
9393 * Add MARK item to matcher
9396 * The device to configure through.
9397 * @param[in, out] matcher
9399 * @param[in, out] key
9400 * Flow matcher value.
9402 * Flow pattern to translate.
9405 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
9406 void *matcher, void *key,
9407 const struct rte_flow_item *item)
9409 struct mlx5_priv *priv = dev->data->dev_private;
9410 const struct rte_flow_item_mark *mark;
9414 mark = item->mask ? (const void *)item->mask :
9415 &rte_flow_item_mark_mask;
9416 mask = mark->id & priv->sh->dv_mark_mask;
9417 mark = (const void *)item->spec;
9419 value = mark->id & priv->sh->dv_mark_mask & mask;
9421 enum modify_reg reg;
9423 /* Get the metadata register index for the mark. */
9424 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
9425 MLX5_ASSERT(reg > 0);
9426 if (reg == REG_C_0) {
9427 struct mlx5_priv *priv = dev->data->dev_private;
9428 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9429 uint32_t shl_c0 = rte_bsf32(msk_c0);
9435 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9440 * Add META item to matcher
9443 * The devich to configure through.
9444 * @param[in, out] matcher
9446 * @param[in, out] key
9447 * Flow matcher value.
9449 * Attributes of flow that includes this item.
9451 * Flow pattern to translate.
9454 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
9455 void *matcher, void *key,
9456 const struct rte_flow_attr *attr,
9457 const struct rte_flow_item *item)
9459 const struct rte_flow_item_meta *meta_m;
9460 const struct rte_flow_item_meta *meta_v;
9462 meta_m = (const void *)item->mask;
9464 meta_m = &rte_flow_item_meta_mask;
9465 meta_v = (const void *)item->spec;
9468 uint32_t value = meta_v->data;
9469 uint32_t mask = meta_m->data;
9471 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
9474 MLX5_ASSERT(reg != REG_NON);
9475 if (reg == REG_C_0) {
9476 struct mlx5_priv *priv = dev->data->dev_private;
9477 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9478 uint32_t shl_c0 = rte_bsf32(msk_c0);
9484 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9489 * Add vport metadata Reg C0 item to matcher
9491 * @param[in, out] matcher
9493 * @param[in, out] key
9494 * Flow matcher value.
9496 * Flow pattern to translate.
9499 flow_dv_translate_item_meta_vport(void *matcher, void *key,
9500 uint32_t value, uint32_t mask)
9502 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
9506 * Add tag item to matcher
9509 * The devich to configure through.
9510 * @param[in, out] matcher
9512 * @param[in, out] key
9513 * Flow matcher value.
9515 * Flow pattern to translate.
9518 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
9519 void *matcher, void *key,
9520 const struct rte_flow_item *item)
9522 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
9523 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
9524 uint32_t mask, value;
9527 value = tag_v->data;
9528 mask = tag_m ? tag_m->data : UINT32_MAX;
9529 if (tag_v->id == REG_C_0) {
9530 struct mlx5_priv *priv = dev->data->dev_private;
9531 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9532 uint32_t shl_c0 = rte_bsf32(msk_c0);
9538 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
9542 * Add TAG item to matcher
9545 * The devich to configure through.
9546 * @param[in, out] matcher
9548 * @param[in, out] key
9549 * Flow matcher value.
9551 * Flow pattern to translate.
9554 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
9555 void *matcher, void *key,
9556 const struct rte_flow_item *item)
9558 const struct rte_flow_item_tag *tag_v = item->spec;
9559 const struct rte_flow_item_tag *tag_m = item->mask;
9560 enum modify_reg reg;
9563 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
9564 /* Get the metadata register index for the tag. */
9565 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
9566 MLX5_ASSERT(reg > 0);
9567 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
9571 * Add source vport match to the specified matcher.
9573 * @param[in, out] matcher
9575 * @param[in, out] key
9576 * Flow matcher value.
9578 * Source vport value to match
9583 flow_dv_translate_item_source_vport(void *matcher, void *key,
9584 int16_t port, uint16_t mask)
9586 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9587 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9589 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
9590 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
9594 * Translate port-id item to eswitch match on port-id.
9597 * The devich to configure through.
9598 * @param[in, out] matcher
9600 * @param[in, out] key
9601 * Flow matcher value.
9603 * Flow pattern to translate.
9608 * 0 on success, a negative errno value otherwise.
9611 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
9612 void *key, const struct rte_flow_item *item,
9613 const struct rte_flow_attr *attr)
9615 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
9616 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
9617 struct mlx5_priv *priv;
9620 mask = pid_m ? pid_m->id : 0xffff;
9621 id = pid_v ? pid_v->id : dev->data->port_id;
9622 priv = mlx5_port_to_eswitch_info(id, item == NULL);
9626 * Translate to vport field or to metadata, depending on mode.
9627 * Kernel can use either misc.source_port or half of C0 metadata
9630 if (priv->vport_meta_mask) {
9632 * Provide the hint for SW steering library
9633 * to insert the flow into ingress domain and
9634 * save the extra vport match.
9636 if (mask == 0xffff && priv->vport_id == 0xffff &&
9637 priv->pf_bond < 0 && attr->transfer)
9638 flow_dv_translate_item_source_vport
9639 (matcher, key, priv->vport_id, mask);
9641 * We should always set the vport metadata register,
9642 * otherwise the SW steering library can drop
9643 * the rule if wire vport metadata value is not zero,
9644 * it depends on kernel configuration.
9646 flow_dv_translate_item_meta_vport(matcher, key,
9647 priv->vport_meta_tag,
9648 priv->vport_meta_mask);
9650 flow_dv_translate_item_source_vport(matcher, key,
9651 priv->vport_id, mask);
9657 * Add ICMP6 item to matcher and to the value.
9659 * @param[in, out] matcher
9661 * @param[in, out] key
9662 * Flow matcher value.
9664 * Flow pattern to translate.
9666 * Item is inner pattern.
9669 flow_dv_translate_item_icmp6(void *matcher, void *key,
9670 const struct rte_flow_item *item,
9673 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
9674 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
9677 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9679 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9681 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9683 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9685 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9687 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9689 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9690 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
9694 icmp6_m = &rte_flow_item_icmp6_mask;
9695 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
9696 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
9697 icmp6_v->type & icmp6_m->type);
9698 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
9699 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
9700 icmp6_v->code & icmp6_m->code);
9704 * Add ICMP item to matcher and to the value.
9706 * @param[in, out] matcher
9708 * @param[in, out] key
9709 * Flow matcher value.
9711 * Flow pattern to translate.
9713 * Item is inner pattern.
9716 flow_dv_translate_item_icmp(void *matcher, void *key,
9717 const struct rte_flow_item *item,
9720 const struct rte_flow_item_icmp *icmp_m = item->mask;
9721 const struct rte_flow_item_icmp *icmp_v = item->spec;
9722 uint32_t icmp_header_data_m = 0;
9723 uint32_t icmp_header_data_v = 0;
9726 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9728 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9730 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9732 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9734 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9736 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9738 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9739 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
9743 icmp_m = &rte_flow_item_icmp_mask;
9744 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
9745 icmp_m->hdr.icmp_type);
9746 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
9747 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
9748 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
9749 icmp_m->hdr.icmp_code);
9750 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
9751 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
9752 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
9753 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
9754 if (icmp_header_data_m) {
9755 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
9756 icmp_header_data_v |=
9757 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
9758 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
9759 icmp_header_data_m);
9760 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
9761 icmp_header_data_v & icmp_header_data_m);
9766 * Add GTP item to matcher and to the value.
9768 * @param[in, out] matcher
9770 * @param[in, out] key
9771 * Flow matcher value.
9773 * Flow pattern to translate.
9775 * Item is inner pattern.
9778 flow_dv_translate_item_gtp(void *matcher, void *key,
9779 const struct rte_flow_item *item, int inner)
9781 const struct rte_flow_item_gtp *gtp_m = item->mask;
9782 const struct rte_flow_item_gtp *gtp_v = item->spec;
9785 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9787 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9788 uint16_t dport = RTE_GTPU_UDP_PORT;
9791 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9793 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9795 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9797 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9799 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9800 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9801 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
9806 gtp_m = &rte_flow_item_gtp_mask;
9807 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
9808 gtp_m->v_pt_rsv_flags);
9809 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
9810 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
9811 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
9812 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
9813 gtp_v->msg_type & gtp_m->msg_type);
9814 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
9815 rte_be_to_cpu_32(gtp_m->teid));
9816 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
9817 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
9821 * Add GTP PSC item to matcher.
9823 * @param[in, out] matcher
9825 * @param[in, out] key
9826 * Flow matcher value.
9828 * Flow pattern to translate.
9831 flow_dv_translate_item_gtp_psc(void *matcher, void *key,
9832 const struct rte_flow_item *item)
9834 const struct rte_flow_item_gtp_psc *gtp_psc_m = item->mask;
9835 const struct rte_flow_item_gtp_psc *gtp_psc_v = item->spec;
9836 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9838 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9844 uint8_t next_ext_header_type;
9849 /* Always set E-flag match on one, regardless of GTP item settings. */
9850 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_m, gtpu_msg_flags);
9851 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9852 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags, gtp_flags);
9853 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
9854 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9855 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
9856 /*Set next extension header type. */
9859 dw_2.next_ext_header_type = 0xff;
9860 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_dw_2,
9861 rte_cpu_to_be_32(dw_2.w32));
9864 dw_2.next_ext_header_type = 0x85;
9865 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
9866 rte_cpu_to_be_32(dw_2.w32));
9878 /*Set extension header PDU type and Qos. */
9880 gtp_psc_m = &rte_flow_item_gtp_psc_mask;
9882 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_m->hdr.type);
9883 dw_0.qfi = gtp_psc_m->hdr.qfi;
9884 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_first_ext_dw_0,
9885 rte_cpu_to_be_32(dw_0.w32));
9887 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
9888 gtp_psc_m->hdr.type);
9889 dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
9890 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
9891 rte_cpu_to_be_32(dw_0.w32));
9897 * Add eCPRI item to matcher and to the value.
9900 * The devich to configure through.
9901 * @param[in, out] matcher
9903 * @param[in, out] key
9904 * Flow matcher value.
9906 * Flow pattern to translate.
9907 * @param[in] last_item
9911 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
9912 void *key, const struct rte_flow_item *item,
9915 struct mlx5_priv *priv = dev->data->dev_private;
9916 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
9917 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
9918 struct rte_ecpri_common_hdr common;
9919 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
9921 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
9927 * In case of eCPRI over Ethernet, if EtherType is not specified,
9928 * match on eCPRI EtherType implicitly.
9930 if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
9931 void *hdrs_m, *hdrs_v, *l2m, *l2v;
9933 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9934 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9935 l2m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, ethertype);
9936 l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
9937 if (*(uint16_t *)l2m == 0 && *(uint16_t *)l2v == 0) {
9938 *(uint16_t *)l2m = UINT16_MAX;
9939 *(uint16_t *)l2v = RTE_BE16(RTE_ETHER_TYPE_ECPRI);
9945 ecpri_m = &rte_flow_item_ecpri_mask;
9947 * Maximal four DW samples are supported in a single matching now.
9948 * Two are used now for a eCPRI matching:
9949 * 1. Type: one byte, mask should be 0x00ff0000 in network order
9950 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
9953 if (!ecpri_m->hdr.common.u32)
9955 samples = priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0].ids;
9956 /* Need to take the whole DW as the mask to fill the entry. */
9957 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9958 prog_sample_field_value_0);
9959 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9960 prog_sample_field_value_0);
9961 /* Already big endian (network order) in the header. */
9962 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
9963 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
9964 /* Sample#0, used for matching type, offset 0. */
9965 MLX5_SET(fte_match_set_misc4, misc4_m,
9966 prog_sample_field_id_0, samples[0]);
9967 /* It makes no sense to set the sample ID in the mask field. */
9968 MLX5_SET(fte_match_set_misc4, misc4_v,
9969 prog_sample_field_id_0, samples[0]);
9971 * Checking if message body part needs to be matched.
9972 * Some wildcard rules only matching type field should be supported.
9974 if (ecpri_m->hdr.dummy[0]) {
9975 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
9976 switch (common.type) {
9977 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
9978 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
9979 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
9980 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9981 prog_sample_field_value_1);
9982 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9983 prog_sample_field_value_1);
9984 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
9985 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
9986 ecpri_m->hdr.dummy[0];
9987 /* Sample#1, to match message body, offset 4. */
9988 MLX5_SET(fte_match_set_misc4, misc4_m,
9989 prog_sample_field_id_1, samples[1]);
9990 MLX5_SET(fte_match_set_misc4, misc4_v,
9991 prog_sample_field_id_1, samples[1]);
9994 /* Others, do not match any sample ID. */
10001 * Add connection tracking status item to matcher
10004 * The devich to configure through.
10005 * @param[in, out] matcher
10007 * @param[in, out] key
10008 * Flow matcher value.
10010 * Flow pattern to translate.
10013 flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
10014 void *matcher, void *key,
10015 const struct rte_flow_item *item)
10017 uint32_t reg_value = 0;
10019 /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
10020 uint32_t reg_mask = 0;
10021 const struct rte_flow_item_conntrack *spec = item->spec;
10022 const struct rte_flow_item_conntrack *mask = item->mask;
10024 struct rte_flow_error error;
10027 mask = &rte_flow_item_conntrack_mask;
10028 if (!spec || !mask->flags)
10030 flags = spec->flags & mask->flags;
10031 /* The conflict should be checked in the validation. */
10032 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
10033 reg_value |= MLX5_CT_SYNDROME_VALID;
10034 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
10035 reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
10036 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
10037 reg_value |= MLX5_CT_SYNDROME_INVALID;
10038 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
10039 reg_value |= MLX5_CT_SYNDROME_TRAP;
10040 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10041 reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
10042 if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
10043 RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
10044 RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
10046 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
10047 reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
10048 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10049 reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
10050 /* The REG_C_x value could be saved during startup. */
10051 reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
10052 if (reg_id == REG_NON)
10054 flow_dv_match_meta_reg(matcher, key, (enum modify_reg)reg_id,
10055 reg_value, reg_mask);
10058 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
10060 #define HEADER_IS_ZERO(match_criteria, headers) \
10061 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
10062 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
10065 * Calculate flow matcher enable bitmap.
10067 * @param match_criteria
10068 * Pointer to flow matcher criteria.
10071 * Bitmap of enabled fields.
10074 flow_dv_matcher_enable(uint32_t *match_criteria)
10076 uint8_t match_criteria_enable;
10078 match_criteria_enable =
10079 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
10080 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
10081 match_criteria_enable |=
10082 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
10083 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
10084 match_criteria_enable |=
10085 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
10086 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
10087 match_criteria_enable |=
10088 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
10089 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
10090 match_criteria_enable |=
10091 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
10092 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
10093 match_criteria_enable |=
10094 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
10095 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
10096 match_criteria_enable |=
10097 (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
10098 MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
10099 return match_criteria_enable;
10103 __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
10106 * Check flow matching criteria first, subtract misc5/4 length if flow
10107 * doesn't own misc5/4 parameters. In some old rdma-core releases,
10108 * misc5/4 are not supported, and matcher creation failure is expected
10109 * w/o subtration. If misc5 is provided, misc4 must be counted in since
10110 * misc5 is right after misc4.
10112 if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
10113 *size = MLX5_ST_SZ_BYTES(fte_match_param) -
10114 MLX5_ST_SZ_BYTES(fte_match_set_misc5);
10115 if (!(match_criteria & (1 <<
10116 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
10117 *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
10122 static struct mlx5_list_entry *
10123 flow_dv_matcher_clone_cb(void *tool_ctx __rte_unused,
10124 struct mlx5_list_entry *entry, void *cb_ctx)
10126 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10127 struct mlx5_flow_dv_matcher *ref = ctx->data;
10128 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10129 typeof(*tbl), tbl);
10130 struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
10135 rte_flow_error_set(ctx->error, ENOMEM,
10136 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10137 "cannot create matcher");
10140 memcpy(resource, entry, sizeof(*resource));
10141 resource->tbl = &tbl->tbl;
10142 return &resource->entry;
10146 flow_dv_matcher_clone_free_cb(void *tool_ctx __rte_unused,
10147 struct mlx5_list_entry *entry)
10152 struct mlx5_list_entry *
10153 flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
10155 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10156 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10157 struct rte_eth_dev *dev = ctx->dev;
10158 struct mlx5_flow_tbl_data_entry *tbl_data;
10159 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
10160 struct rte_flow_error *error = ctx->error;
10161 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10162 struct mlx5_flow_tbl_resource *tbl;
10167 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10169 rte_flow_error_set(error, ENOMEM,
10170 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10172 "cannot allocate flow table data entry");
10175 tbl_data->idx = idx;
10176 tbl_data->tunnel = tt_prm->tunnel;
10177 tbl_data->group_id = tt_prm->group_id;
10178 tbl_data->external = !!tt_prm->external;
10179 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
10180 tbl_data->is_egress = !!key.is_egress;
10181 tbl_data->is_transfer = !!key.is_fdb;
10182 tbl_data->dummy = !!key.dummy;
10183 tbl_data->level = key.level;
10184 tbl_data->id = key.id;
10185 tbl = &tbl_data->tbl;
10187 return &tbl_data->entry;
10189 domain = sh->fdb_domain;
10190 else if (key.is_egress)
10191 domain = sh->tx_domain;
10193 domain = sh->rx_domain;
10194 ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
10196 rte_flow_error_set(error, ENOMEM,
10197 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10198 NULL, "cannot create flow table object");
10199 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10202 if (key.level != 0) {
10203 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
10204 (tbl->obj, &tbl_data->jump.action);
10206 rte_flow_error_set(error, ENOMEM,
10207 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10209 "cannot create flow jump action");
10210 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10211 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10215 MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
10216 key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
10217 key.level, key.id);
10218 tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
10219 flow_dv_matcher_create_cb,
10220 flow_dv_matcher_match_cb,
10221 flow_dv_matcher_remove_cb,
10222 flow_dv_matcher_clone_cb,
10223 flow_dv_matcher_clone_free_cb);
10224 if (!tbl_data->matchers) {
10225 rte_flow_error_set(error, ENOMEM,
10226 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10228 "cannot create tbl matcher list");
10229 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10230 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10231 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10234 return &tbl_data->entry;
10238 flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
10241 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10242 struct mlx5_flow_tbl_data_entry *tbl_data =
10243 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10244 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10246 return tbl_data->level != key.level ||
10247 tbl_data->id != key.id ||
10248 tbl_data->dummy != key.dummy ||
10249 tbl_data->is_transfer != !!key.is_fdb ||
10250 tbl_data->is_egress != !!key.is_egress;
10253 struct mlx5_list_entry *
10254 flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
10257 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10258 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10259 struct mlx5_flow_tbl_data_entry *tbl_data;
10260 struct rte_flow_error *error = ctx->error;
10263 tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10265 rte_flow_error_set(error, ENOMEM,
10266 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10268 "cannot allocate flow table data entry");
10271 memcpy(tbl_data, oentry, sizeof(*tbl_data));
10272 tbl_data->idx = idx;
10273 return &tbl_data->entry;
10277 flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10279 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10280 struct mlx5_flow_tbl_data_entry *tbl_data =
10281 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10283 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10287 * Get a flow table.
10289 * @param[in, out] dev
10290 * Pointer to rte_eth_dev structure.
10291 * @param[in] table_level
10292 * Table level to use.
10293 * @param[in] egress
10294 * Direction of the table.
10295 * @param[in] transfer
10296 * E-Switch or NIC flow.
10298 * Dummy entry for dv API.
10299 * @param[in] table_id
10301 * @param[out] error
10302 * pointer to error structure.
10305 * Returns tables resource based on the index, NULL in case of failed.
10307 struct mlx5_flow_tbl_resource *
10308 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
10309 uint32_t table_level, uint8_t egress,
10312 const struct mlx5_flow_tunnel *tunnel,
10313 uint32_t group_id, uint8_t dummy,
10315 struct rte_flow_error *error)
10317 struct mlx5_priv *priv = dev->data->dev_private;
10318 union mlx5_flow_tbl_key table_key = {
10320 .level = table_level,
10324 .is_fdb = !!transfer,
10325 .is_egress = !!egress,
10328 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
10330 .group_id = group_id,
10331 .external = external,
10333 struct mlx5_flow_cb_ctx ctx = {
10336 .data = &table_key.v64,
10339 struct mlx5_list_entry *entry;
10340 struct mlx5_flow_tbl_data_entry *tbl_data;
10342 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
10344 rte_flow_error_set(error, ENOMEM,
10345 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10346 "cannot get table");
10349 DRV_LOG(DEBUG, "table_level %u table_id %u "
10350 "tunnel %u group %u registered.",
10351 table_level, table_id,
10352 tunnel ? tunnel->tunnel_id : 0, group_id);
10353 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10354 return &tbl_data->tbl;
10358 flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10360 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10361 struct mlx5_flow_tbl_data_entry *tbl_data =
10362 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10364 MLX5_ASSERT(entry && sh);
10365 if (tbl_data->jump.action)
10366 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10367 if (tbl_data->tbl.obj)
10368 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
10369 if (tbl_data->tunnel_offload && tbl_data->external) {
10370 struct mlx5_list_entry *he;
10371 struct mlx5_hlist *tunnel_grp_hash;
10372 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
10373 union tunnel_tbl_key tunnel_key = {
10374 .tunnel_id = tbl_data->tunnel ?
10375 tbl_data->tunnel->tunnel_id : 0,
10376 .group = tbl_data->group_id
10378 uint32_t table_level = tbl_data->level;
10379 struct mlx5_flow_cb_ctx ctx = {
10380 .data = (void *)&tunnel_key.val,
10383 tunnel_grp_hash = tbl_data->tunnel ?
10384 tbl_data->tunnel->groups :
10386 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
10388 mlx5_hlist_unregister(tunnel_grp_hash, he);
10390 "table_level %u id %u tunnel %u group %u released.",
10394 tbl_data->tunnel->tunnel_id : 0,
10395 tbl_data->group_id);
10397 mlx5_list_destroy(tbl_data->matchers);
10398 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10402 * Release a flow table.
10405 * Pointer to device shared structure.
10407 * Table resource to be released.
10410 * Returns 0 if table was released, else return 1;
10413 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
10414 struct mlx5_flow_tbl_resource *tbl)
10416 struct mlx5_flow_tbl_data_entry *tbl_data =
10417 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10421 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
10425 flow_dv_matcher_match_cb(void *tool_ctx __rte_unused,
10426 struct mlx5_list_entry *entry, void *cb_ctx)
10428 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10429 struct mlx5_flow_dv_matcher *ref = ctx->data;
10430 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
10433 return cur->crc != ref->crc ||
10434 cur->priority != ref->priority ||
10435 memcmp((const void *)cur->mask.buf,
10436 (const void *)ref->mask.buf, ref->mask.size);
10439 struct mlx5_list_entry *
10440 flow_dv_matcher_create_cb(void *tool_ctx, void *cb_ctx)
10442 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10443 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10444 struct mlx5_flow_dv_matcher *ref = ctx->data;
10445 struct mlx5_flow_dv_matcher *resource;
10446 struct mlx5dv_flow_matcher_attr dv_attr = {
10447 .type = IBV_FLOW_ATTR_NORMAL,
10448 .match_mask = (void *)&ref->mask,
10450 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10451 typeof(*tbl), tbl);
10454 resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
10457 rte_flow_error_set(ctx->error, ENOMEM,
10458 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10459 "cannot create matcher");
10463 dv_attr.match_criteria_enable =
10464 flow_dv_matcher_enable(resource->mask.buf);
10465 __flow_dv_adjust_buf_size(&ref->mask.size,
10466 dv_attr.match_criteria_enable);
10467 dv_attr.priority = ref->priority;
10468 if (tbl->is_egress)
10469 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
10470 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->tbl.obj,
10471 &resource->matcher_object);
10473 mlx5_free(resource);
10474 rte_flow_error_set(ctx->error, ENOMEM,
10475 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10476 "cannot create matcher");
10479 return &resource->entry;
10483 * Register the flow matcher.
10485 * @param[in, out] dev
10486 * Pointer to rte_eth_dev structure.
10487 * @param[in, out] matcher
10488 * Pointer to flow matcher.
10489 * @param[in, out] key
10490 * Pointer to flow table key.
10491 * @parm[in, out] dev_flow
10492 * Pointer to the dev_flow.
10493 * @param[out] error
10494 * pointer to error structure.
10497 * 0 on success otherwise -errno and errno is set.
10500 flow_dv_matcher_register(struct rte_eth_dev *dev,
10501 struct mlx5_flow_dv_matcher *ref,
10502 union mlx5_flow_tbl_key *key,
10503 struct mlx5_flow *dev_flow,
10504 const struct mlx5_flow_tunnel *tunnel,
10506 struct rte_flow_error *error)
10508 struct mlx5_list_entry *entry;
10509 struct mlx5_flow_dv_matcher *resource;
10510 struct mlx5_flow_tbl_resource *tbl;
10511 struct mlx5_flow_tbl_data_entry *tbl_data;
10512 struct mlx5_flow_cb_ctx ctx = {
10517 * tunnel offload API requires this registration for cases when
10518 * tunnel match rule was inserted before tunnel set rule.
10520 tbl = flow_dv_tbl_resource_get(dev, key->level,
10521 key->is_egress, key->is_fdb,
10522 dev_flow->external, tunnel,
10523 group_id, 0, key->id, error);
10525 return -rte_errno; /* No need to refill the error info */
10526 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10528 entry = mlx5_list_register(tbl_data->matchers, &ctx);
10530 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
10531 return rte_flow_error_set(error, ENOMEM,
10532 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10533 "cannot allocate ref memory");
10535 resource = container_of(entry, typeof(*resource), entry);
10536 dev_flow->handle->dvh.matcher = resource;
10540 struct mlx5_list_entry *
10541 flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
10543 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10544 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10545 struct mlx5_flow_dv_tag_resource *entry;
10549 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10551 rte_flow_error_set(ctx->error, ENOMEM,
10552 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10553 "cannot allocate resource memory");
10557 entry->tag_id = *(uint32_t *)(ctx->data);
10558 ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
10561 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
10562 rte_flow_error_set(ctx->error, ENOMEM,
10563 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10564 NULL, "cannot create action");
10567 return &entry->entry;
10571 flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
10574 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10575 struct mlx5_flow_dv_tag_resource *tag =
10576 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10578 return *(uint32_t *)(ctx->data) != tag->tag_id;
10581 struct mlx5_list_entry *
10582 flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
10585 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10586 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10587 struct mlx5_flow_dv_tag_resource *entry;
10590 entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10592 rte_flow_error_set(ctx->error, ENOMEM,
10593 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10594 "cannot allocate tag resource memory");
10597 memcpy(entry, oentry, sizeof(*entry));
10599 return &entry->entry;
10603 flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10605 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10606 struct mlx5_flow_dv_tag_resource *tag =
10607 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10609 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10613 * Find existing tag resource or create and register a new one.
10615 * @param dev[in, out]
10616 * Pointer to rte_eth_dev structure.
10617 * @param[in, out] tag_be24
10618 * Tag value in big endian then R-shift 8.
10619 * @parm[in, out] dev_flow
10620 * Pointer to the dev_flow.
10621 * @param[out] error
10622 * pointer to error structure.
10625 * 0 on success otherwise -errno and errno is set.
10628 flow_dv_tag_resource_register
10629 (struct rte_eth_dev *dev,
10631 struct mlx5_flow *dev_flow,
10632 struct rte_flow_error *error)
10634 struct mlx5_priv *priv = dev->data->dev_private;
10635 struct mlx5_flow_dv_tag_resource *resource;
10636 struct mlx5_list_entry *entry;
10637 struct mlx5_flow_cb_ctx ctx = {
10641 struct mlx5_hlist *tag_table;
10643 tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
10645 MLX5_TAGS_HLIST_ARRAY_SIZE,
10646 false, false, priv->sh,
10647 flow_dv_tag_create_cb,
10648 flow_dv_tag_match_cb,
10649 flow_dv_tag_remove_cb,
10650 flow_dv_tag_clone_cb,
10651 flow_dv_tag_clone_free_cb);
10652 if (unlikely(!tag_table))
10654 entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
10656 resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
10658 dev_flow->handle->dvh.rix_tag = resource->idx;
10659 dev_flow->dv.tag_resource = resource;
10666 flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10668 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10669 struct mlx5_flow_dv_tag_resource *tag =
10670 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10672 MLX5_ASSERT(tag && sh && tag->action);
10673 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
10674 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
10675 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10682 * Pointer to Ethernet device.
10687 * 1 while a reference on it exists, 0 when freed.
10690 flow_dv_tag_release(struct rte_eth_dev *dev,
10693 struct mlx5_priv *priv = dev->data->dev_private;
10694 struct mlx5_flow_dv_tag_resource *tag;
10696 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
10699 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
10700 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
10701 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
10705 * Translate action PORT_ID / REPRESENTED_PORT to vport.
10708 * Pointer to rte_eth_dev structure.
10709 * @param[in] action
10710 * Pointer to action PORT_ID / REPRESENTED_PORT.
10711 * @param[out] dst_port_id
10712 * The target port ID.
10713 * @param[out] error
10714 * Pointer to the error structure.
10717 * 0 on success, a negative errno value otherwise and rte_errno is set.
10720 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
10721 const struct rte_flow_action *action,
10722 uint32_t *dst_port_id,
10723 struct rte_flow_error *error)
10726 struct mlx5_priv *priv;
10728 switch (action->type) {
10729 case RTE_FLOW_ACTION_TYPE_PORT_ID: {
10730 const struct rte_flow_action_port_id *conf;
10732 conf = (const struct rte_flow_action_port_id *)action->conf;
10733 port = conf->original ? dev->data->port_id : conf->id;
10736 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
10737 const struct rte_flow_action_ethdev *ethdev;
10739 ethdev = (const struct rte_flow_action_ethdev *)action->conf;
10740 port = ethdev->port_id;
10744 MLX5_ASSERT(false);
10745 return rte_flow_error_set(error, EINVAL,
10746 RTE_FLOW_ERROR_TYPE_ACTION, action,
10747 "unknown E-Switch action");
10750 priv = mlx5_port_to_eswitch_info(port, false);
10752 return rte_flow_error_set(error, -rte_errno,
10753 RTE_FLOW_ERROR_TYPE_ACTION,
10755 "No eswitch info was found for port");
10756 #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
10758 * This parameter is transferred to
10759 * mlx5dv_dr_action_create_dest_ib_port().
10761 *dst_port_id = priv->dev_port;
10764 * Legacy mode, no LAG configurations is supported.
10765 * This parameter is transferred to
10766 * mlx5dv_dr_action_create_dest_vport().
10768 *dst_port_id = priv->vport_id;
10774 * Create a counter with aging configuration.
10777 * Pointer to rte_eth_dev structure.
10778 * @param[in] dev_flow
10779 * Pointer to the mlx5_flow.
10780 * @param[out] count
10781 * Pointer to the counter action configuration.
10783 * Pointer to the aging action configuration.
10786 * Index to flow counter on success, 0 otherwise.
10789 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
10790 struct mlx5_flow *dev_flow,
10791 const struct rte_flow_action_count *count
10793 const struct rte_flow_action_age *age)
10796 struct mlx5_age_param *age_param;
10798 counter = flow_dv_counter_alloc(dev, !!age);
10799 if (!counter || age == NULL)
10801 age_param = flow_dv_counter_idx_get_age(dev, counter);
10802 age_param->context = age->context ? age->context :
10803 (void *)(uintptr_t)(dev_flow->flow_idx);
10804 age_param->timeout = age->timeout;
10805 age_param->port_id = dev->data->port_id;
10806 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
10807 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
10812 * Add Tx queue matcher
10815 * Pointer to the dev struct.
10816 * @param[in, out] matcher
10818 * @param[in, out] key
10819 * Flow matcher value.
10821 * Flow pattern to translate.
10823 * Item is inner pattern.
10826 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
10827 void *matcher, void *key,
10828 const struct rte_flow_item *item)
10830 const struct mlx5_rte_flow_item_tx_queue *queue_m;
10831 const struct mlx5_rte_flow_item_tx_queue *queue_v;
10833 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
10835 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10836 struct mlx5_txq_ctrl *txq;
10840 queue_m = (const void *)item->mask;
10843 queue_v = (const void *)item->spec;
10846 txq = mlx5_txq_get(dev, queue_v->queue);
10849 queue = txq->obj->sq->id;
10850 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
10851 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
10852 queue & queue_m->queue);
10853 mlx5_txq_release(dev, queue_v->queue);
10857 * Set the hash fields according to the @p flow information.
10859 * @param[in] dev_flow
10860 * Pointer to the mlx5_flow.
10861 * @param[in] rss_desc
10862 * Pointer to the mlx5_flow_rss_desc.
10865 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
10866 struct mlx5_flow_rss_desc *rss_desc)
10868 uint64_t items = dev_flow->handle->layers;
10870 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
10872 dev_flow->hash_fields = 0;
10873 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
10874 if (rss_desc->level >= 2)
10877 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
10878 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
10879 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
10880 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10881 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
10882 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10883 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
10885 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
10887 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
10888 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
10889 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
10890 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10891 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
10892 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10893 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
10895 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
10898 if (dev_flow->hash_fields == 0)
10900 * There is no match between the RSS types and the
10901 * L3 protocol (IPv4/IPv6) defined in the flow rule.
10904 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
10905 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
10906 if (rss_types & ETH_RSS_UDP) {
10907 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10908 dev_flow->hash_fields |=
10909 IBV_RX_HASH_SRC_PORT_UDP;
10910 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10911 dev_flow->hash_fields |=
10912 IBV_RX_HASH_DST_PORT_UDP;
10914 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
10916 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
10917 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
10918 if (rss_types & ETH_RSS_TCP) {
10919 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10920 dev_flow->hash_fields |=
10921 IBV_RX_HASH_SRC_PORT_TCP;
10922 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10923 dev_flow->hash_fields |=
10924 IBV_RX_HASH_DST_PORT_TCP;
10926 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
10930 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
10934 * Prepare an Rx Hash queue.
10937 * Pointer to Ethernet device.
10938 * @param[in] dev_flow
10939 * Pointer to the mlx5_flow.
10940 * @param[in] rss_desc
10941 * Pointer to the mlx5_flow_rss_desc.
10942 * @param[out] hrxq_idx
10943 * Hash Rx queue index.
10946 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
10948 static struct mlx5_hrxq *
10949 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
10950 struct mlx5_flow *dev_flow,
10951 struct mlx5_flow_rss_desc *rss_desc,
10952 uint32_t *hrxq_idx)
10954 struct mlx5_priv *priv = dev->data->dev_private;
10955 struct mlx5_flow_handle *dh = dev_flow->handle;
10956 struct mlx5_hrxq *hrxq;
10958 MLX5_ASSERT(rss_desc->queue_num);
10959 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
10960 rss_desc->hash_fields = dev_flow->hash_fields;
10961 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
10962 rss_desc->shared_rss = 0;
10963 if (rss_desc->hash_fields == 0)
10964 rss_desc->queue_num = 1;
10965 *hrxq_idx = mlx5_hrxq_get(dev, rss_desc);
10968 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
10974 * Release sample sub action resource.
10976 * @param[in, out] dev
10977 * Pointer to rte_eth_dev structure.
10978 * @param[in] act_res
10979 * Pointer to sample sub action resource.
10982 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
10983 struct mlx5_flow_sub_actions_idx *act_res)
10985 if (act_res->rix_hrxq) {
10986 mlx5_hrxq_release(dev, act_res->rix_hrxq);
10987 act_res->rix_hrxq = 0;
10989 if (act_res->rix_encap_decap) {
10990 flow_dv_encap_decap_resource_release(dev,
10991 act_res->rix_encap_decap);
10992 act_res->rix_encap_decap = 0;
10994 if (act_res->rix_port_id_action) {
10995 flow_dv_port_id_action_resource_release(dev,
10996 act_res->rix_port_id_action);
10997 act_res->rix_port_id_action = 0;
10999 if (act_res->rix_tag) {
11000 flow_dv_tag_release(dev, act_res->rix_tag);
11001 act_res->rix_tag = 0;
11003 if (act_res->rix_jump) {
11004 flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
11005 act_res->rix_jump = 0;
11010 flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
11011 struct mlx5_list_entry *entry, void *cb_ctx)
11013 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11014 struct rte_eth_dev *dev = ctx->dev;
11015 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
11016 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
11020 if (ctx_resource->ratio == resource->ratio &&
11021 ctx_resource->ft_type == resource->ft_type &&
11022 ctx_resource->ft_id == resource->ft_id &&
11023 ctx_resource->set_action == resource->set_action &&
11024 !memcmp((void *)&ctx_resource->sample_act,
11025 (void *)&resource->sample_act,
11026 sizeof(struct mlx5_flow_sub_actions_list))) {
11028 * Existing sample action should release the prepared
11029 * sub-actions reference counter.
11031 flow_dv_sample_sub_actions_release(dev,
11032 &ctx_resource->sample_idx);
11038 struct mlx5_list_entry *
11039 flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11041 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11042 struct rte_eth_dev *dev = ctx->dev;
11043 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
11044 void **sample_dv_actions = ctx_resource->sub_actions;
11045 struct mlx5_flow_dv_sample_resource *resource;
11046 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
11047 struct mlx5_priv *priv = dev->data->dev_private;
11048 struct mlx5_dev_ctx_shared *sh = priv->sh;
11049 struct mlx5_flow_tbl_resource *tbl;
11051 const uint32_t next_ft_step = 1;
11052 uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
11053 uint8_t is_egress = 0;
11054 uint8_t is_transfer = 0;
11055 struct rte_flow_error *error = ctx->error;
11057 /* Register new sample resource. */
11058 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11060 rte_flow_error_set(error, ENOMEM,
11061 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11063 "cannot allocate resource memory");
11066 *resource = *ctx_resource;
11067 /* Create normal path table level */
11068 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11070 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
11072 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
11073 is_egress, is_transfer,
11074 true, NULL, 0, 0, 0, error);
11076 rte_flow_error_set(error, ENOMEM,
11077 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11079 "fail to create normal path table "
11083 resource->normal_path_tbl = tbl;
11084 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
11085 if (!sh->default_miss_action) {
11086 rte_flow_error_set(error, ENOMEM,
11087 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11089 "default miss action was not "
11093 sample_dv_actions[ctx_resource->sample_act.actions_num++] =
11094 sh->default_miss_action;
11096 /* Create a DR sample action */
11097 sampler_attr.sample_ratio = resource->ratio;
11098 sampler_attr.default_next_table = tbl->obj;
11099 sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
11100 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
11101 &sample_dv_actions[0];
11102 sampler_attr.action = resource->set_action;
11103 if (mlx5_os_flow_dr_create_flow_action_sampler
11104 (&sampler_attr, &resource->verbs_action)) {
11105 rte_flow_error_set(error, ENOMEM,
11106 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11107 NULL, "cannot create sample action");
11110 resource->idx = idx;
11111 resource->dev = dev;
11112 return &resource->entry;
11114 if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
11115 flow_dv_sample_sub_actions_release(dev,
11116 &resource->sample_idx);
11117 if (resource->normal_path_tbl)
11118 flow_dv_tbl_resource_release(MLX5_SH(dev),
11119 resource->normal_path_tbl);
11120 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
11125 struct mlx5_list_entry *
11126 flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
11127 struct mlx5_list_entry *entry __rte_unused,
11130 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11131 struct rte_eth_dev *dev = ctx->dev;
11132 struct mlx5_flow_dv_sample_resource *resource;
11133 struct mlx5_priv *priv = dev->data->dev_private;
11134 struct mlx5_dev_ctx_shared *sh = priv->sh;
11137 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11139 rte_flow_error_set(ctx->error, ENOMEM,
11140 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11142 "cannot allocate resource memory");
11145 memcpy(resource, entry, sizeof(*resource));
11146 resource->idx = idx;
11147 resource->dev = dev;
11148 return &resource->entry;
11152 flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
11153 struct mlx5_list_entry *entry)
11155 struct mlx5_flow_dv_sample_resource *resource =
11156 container_of(entry, typeof(*resource), entry);
11157 struct rte_eth_dev *dev = resource->dev;
11158 struct mlx5_priv *priv = dev->data->dev_private;
11160 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
11164 * Find existing sample resource or create and register a new one.
11166 * @param[in, out] dev
11167 * Pointer to rte_eth_dev structure.
11169 * Pointer to sample resource reference.
11170 * @parm[in, out] dev_flow
11171 * Pointer to the dev_flow.
11172 * @param[out] error
11173 * pointer to error structure.
11176 * 0 on success otherwise -errno and errno is set.
11179 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
11180 struct mlx5_flow_dv_sample_resource *ref,
11181 struct mlx5_flow *dev_flow,
11182 struct rte_flow_error *error)
11184 struct mlx5_flow_dv_sample_resource *resource;
11185 struct mlx5_list_entry *entry;
11186 struct mlx5_priv *priv = dev->data->dev_private;
11187 struct mlx5_flow_cb_ctx ctx = {
11193 entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
11196 resource = container_of(entry, typeof(*resource), entry);
11197 dev_flow->handle->dvh.rix_sample = resource->idx;
11198 dev_flow->dv.sample_res = resource;
11203 flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
11204 struct mlx5_list_entry *entry, void *cb_ctx)
11206 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11207 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11208 struct rte_eth_dev *dev = ctx->dev;
11209 struct mlx5_flow_dv_dest_array_resource *resource =
11210 container_of(entry, typeof(*resource), entry);
11213 if (ctx_resource->num_of_dest == resource->num_of_dest &&
11214 ctx_resource->ft_type == resource->ft_type &&
11215 !memcmp((void *)resource->sample_act,
11216 (void *)ctx_resource->sample_act,
11217 (ctx_resource->num_of_dest *
11218 sizeof(struct mlx5_flow_sub_actions_list)))) {
11220 * Existing sample action should release the prepared
11221 * sub-actions reference counter.
11223 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11224 flow_dv_sample_sub_actions_release(dev,
11225 &ctx_resource->sample_idx[idx]);
11231 struct mlx5_list_entry *
11232 flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11234 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11235 struct rte_eth_dev *dev = ctx->dev;
11236 struct mlx5_flow_dv_dest_array_resource *resource;
11237 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11238 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
11239 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
11240 struct mlx5_priv *priv = dev->data->dev_private;
11241 struct mlx5_dev_ctx_shared *sh = priv->sh;
11242 struct mlx5_flow_sub_actions_list *sample_act;
11243 struct mlx5dv_dr_domain *domain;
11244 uint32_t idx = 0, res_idx = 0;
11245 struct rte_flow_error *error = ctx->error;
11246 uint64_t action_flags;
11249 /* Register new destination array resource. */
11250 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11253 rte_flow_error_set(error, ENOMEM,
11254 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11256 "cannot allocate resource memory");
11259 *resource = *ctx_resource;
11260 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11261 domain = sh->fdb_domain;
11262 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
11263 domain = sh->rx_domain;
11265 domain = sh->tx_domain;
11266 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11267 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
11268 mlx5_malloc(MLX5_MEM_ZERO,
11269 sizeof(struct mlx5dv_dr_action_dest_attr),
11271 if (!dest_attr[idx]) {
11272 rte_flow_error_set(error, ENOMEM,
11273 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11275 "cannot allocate resource memory");
11278 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
11279 sample_act = &ctx_resource->sample_act[idx];
11280 action_flags = sample_act->action_flags;
11281 switch (action_flags) {
11282 case MLX5_FLOW_ACTION_QUEUE:
11283 dest_attr[idx]->dest = sample_act->dr_queue_action;
11285 case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
11286 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
11287 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
11288 dest_attr[idx]->dest_reformat->reformat =
11289 sample_act->dr_encap_action;
11290 dest_attr[idx]->dest_reformat->dest =
11291 sample_act->dr_port_id_action;
11293 case MLX5_FLOW_ACTION_PORT_ID:
11294 dest_attr[idx]->dest = sample_act->dr_port_id_action;
11296 case MLX5_FLOW_ACTION_JUMP:
11297 dest_attr[idx]->dest = sample_act->dr_jump_action;
11300 rte_flow_error_set(error, EINVAL,
11301 RTE_FLOW_ERROR_TYPE_ACTION,
11303 "unsupported actions type");
11307 /* create a dest array actioin */
11308 ret = mlx5_os_flow_dr_create_flow_action_dest_array
11310 resource->num_of_dest,
11312 &resource->action);
11314 rte_flow_error_set(error, ENOMEM,
11315 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11317 "cannot create destination array action");
11320 resource->idx = res_idx;
11321 resource->dev = dev;
11322 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11323 mlx5_free(dest_attr[idx]);
11324 return &resource->entry;
11326 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11327 flow_dv_sample_sub_actions_release(dev,
11328 &resource->sample_idx[idx]);
11329 if (dest_attr[idx])
11330 mlx5_free(dest_attr[idx]);
11332 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
11336 struct mlx5_list_entry *
11337 flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
11338 struct mlx5_list_entry *entry __rte_unused,
11341 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11342 struct rte_eth_dev *dev = ctx->dev;
11343 struct mlx5_flow_dv_dest_array_resource *resource;
11344 struct mlx5_priv *priv = dev->data->dev_private;
11345 struct mlx5_dev_ctx_shared *sh = priv->sh;
11346 uint32_t res_idx = 0;
11347 struct rte_flow_error *error = ctx->error;
11349 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11352 rte_flow_error_set(error, ENOMEM,
11353 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11355 "cannot allocate dest-array memory");
11358 memcpy(resource, entry, sizeof(*resource));
11359 resource->idx = res_idx;
11360 resource->dev = dev;
11361 return &resource->entry;
11365 flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
11366 struct mlx5_list_entry *entry)
11368 struct mlx5_flow_dv_dest_array_resource *resource =
11369 container_of(entry, typeof(*resource), entry);
11370 struct rte_eth_dev *dev = resource->dev;
11371 struct mlx5_priv *priv = dev->data->dev_private;
11373 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
11377 * Find existing destination array resource or create and register a new one.
11379 * @param[in, out] dev
11380 * Pointer to rte_eth_dev structure.
11382 * Pointer to destination array resource reference.
11383 * @parm[in, out] dev_flow
11384 * Pointer to the dev_flow.
11385 * @param[out] error
11386 * pointer to error structure.
11389 * 0 on success otherwise -errno and errno is set.
11392 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
11393 struct mlx5_flow_dv_dest_array_resource *ref,
11394 struct mlx5_flow *dev_flow,
11395 struct rte_flow_error *error)
11397 struct mlx5_flow_dv_dest_array_resource *resource;
11398 struct mlx5_priv *priv = dev->data->dev_private;
11399 struct mlx5_list_entry *entry;
11400 struct mlx5_flow_cb_ctx ctx = {
11406 entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
11409 resource = container_of(entry, typeof(*resource), entry);
11410 dev_flow->handle->dvh.rix_dest_array = resource->idx;
11411 dev_flow->dv.dest_array_res = resource;
11416 * Convert Sample action to DV specification.
11419 * Pointer to rte_eth_dev structure.
11420 * @param[in] action
11421 * Pointer to sample action structure.
11422 * @param[in, out] dev_flow
11423 * Pointer to the mlx5_flow.
11425 * Pointer to the flow attributes.
11426 * @param[in, out] num_of_dest
11427 * Pointer to the num of destination.
11428 * @param[in, out] sample_actions
11429 * Pointer to sample actions list.
11430 * @param[in, out] res
11431 * Pointer to sample resource.
11432 * @param[out] error
11433 * Pointer to the error structure.
11436 * 0 on success, a negative errno value otherwise and rte_errno is set.
11439 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
11440 const struct rte_flow_action_sample *action,
11441 struct mlx5_flow *dev_flow,
11442 const struct rte_flow_attr *attr,
11443 uint32_t *num_of_dest,
11444 void **sample_actions,
11445 struct mlx5_flow_dv_sample_resource *res,
11446 struct rte_flow_error *error)
11448 struct mlx5_priv *priv = dev->data->dev_private;
11449 const struct rte_flow_action *sub_actions;
11450 struct mlx5_flow_sub_actions_list *sample_act;
11451 struct mlx5_flow_sub_actions_idx *sample_idx;
11452 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11453 struct rte_flow *flow = dev_flow->flow;
11454 struct mlx5_flow_rss_desc *rss_desc;
11455 uint64_t action_flags = 0;
11458 rss_desc = &wks->rss_desc;
11459 sample_act = &res->sample_act;
11460 sample_idx = &res->sample_idx;
11461 res->ratio = action->ratio;
11462 sub_actions = action->actions;
11463 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
11464 int type = sub_actions->type;
11465 uint32_t pre_rix = 0;
11468 case RTE_FLOW_ACTION_TYPE_QUEUE:
11470 const struct rte_flow_action_queue *queue;
11471 struct mlx5_hrxq *hrxq;
11474 queue = sub_actions->conf;
11475 rss_desc->queue_num = 1;
11476 rss_desc->queue[0] = queue->index;
11477 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11478 rss_desc, &hrxq_idx);
11480 return rte_flow_error_set
11482 RTE_FLOW_ERROR_TYPE_ACTION,
11484 "cannot create fate queue");
11485 sample_act->dr_queue_action = hrxq->action;
11486 sample_idx->rix_hrxq = hrxq_idx;
11487 sample_actions[sample_act->actions_num++] =
11490 action_flags |= MLX5_FLOW_ACTION_QUEUE;
11491 if (action_flags & MLX5_FLOW_ACTION_MARK)
11492 dev_flow->handle->rix_hrxq = hrxq_idx;
11493 dev_flow->handle->fate_action =
11494 MLX5_FLOW_FATE_QUEUE;
11497 case RTE_FLOW_ACTION_TYPE_RSS:
11499 struct mlx5_hrxq *hrxq;
11501 const struct rte_flow_action_rss *rss;
11502 const uint8_t *rss_key;
11504 rss = sub_actions->conf;
11505 memcpy(rss_desc->queue, rss->queue,
11506 rss->queue_num * sizeof(uint16_t));
11507 rss_desc->queue_num = rss->queue_num;
11508 /* NULL RSS key indicates default RSS key. */
11509 rss_key = !rss->key ? rss_hash_default_key : rss->key;
11510 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
11512 * rss->level and rss.types should be set in advance
11513 * when expanding items for RSS.
11515 flow_dv_hashfields_set(dev_flow, rss_desc);
11516 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11517 rss_desc, &hrxq_idx);
11519 return rte_flow_error_set
11521 RTE_FLOW_ERROR_TYPE_ACTION,
11523 "cannot create fate queue");
11524 sample_act->dr_queue_action = hrxq->action;
11525 sample_idx->rix_hrxq = hrxq_idx;
11526 sample_actions[sample_act->actions_num++] =
11529 action_flags |= MLX5_FLOW_ACTION_RSS;
11530 if (action_flags & MLX5_FLOW_ACTION_MARK)
11531 dev_flow->handle->rix_hrxq = hrxq_idx;
11532 dev_flow->handle->fate_action =
11533 MLX5_FLOW_FATE_QUEUE;
11536 case RTE_FLOW_ACTION_TYPE_MARK:
11538 uint32_t tag_be = mlx5_flow_mark_set
11539 (((const struct rte_flow_action_mark *)
11540 (sub_actions->conf))->id);
11542 dev_flow->handle->mark = 1;
11543 pre_rix = dev_flow->handle->dvh.rix_tag;
11544 /* Save the mark resource before sample */
11545 pre_r = dev_flow->dv.tag_resource;
11546 if (flow_dv_tag_resource_register(dev, tag_be,
11549 MLX5_ASSERT(dev_flow->dv.tag_resource);
11550 sample_act->dr_tag_action =
11551 dev_flow->dv.tag_resource->action;
11552 sample_idx->rix_tag =
11553 dev_flow->handle->dvh.rix_tag;
11554 sample_actions[sample_act->actions_num++] =
11555 sample_act->dr_tag_action;
11556 /* Recover the mark resource after sample */
11557 dev_flow->dv.tag_resource = pre_r;
11558 dev_flow->handle->dvh.rix_tag = pre_rix;
11559 action_flags |= MLX5_FLOW_ACTION_MARK;
11562 case RTE_FLOW_ACTION_TYPE_COUNT:
11564 if (!flow->counter) {
11566 flow_dv_translate_create_counter(dev,
11567 dev_flow, sub_actions->conf,
11569 if (!flow->counter)
11570 return rte_flow_error_set
11572 RTE_FLOW_ERROR_TYPE_ACTION,
11574 "cannot create counter"
11577 sample_act->dr_cnt_action =
11578 (flow_dv_counter_get_by_idx(dev,
11579 flow->counter, NULL))->action;
11580 sample_actions[sample_act->actions_num++] =
11581 sample_act->dr_cnt_action;
11582 action_flags |= MLX5_FLOW_ACTION_COUNT;
11585 case RTE_FLOW_ACTION_TYPE_PORT_ID:
11586 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
11588 struct mlx5_flow_dv_port_id_action_resource
11590 uint32_t port_id = 0;
11592 memset(&port_id_resource, 0, sizeof(port_id_resource));
11593 /* Save the port id resource before sample */
11594 pre_rix = dev_flow->handle->rix_port_id_action;
11595 pre_r = dev_flow->dv.port_id_action;
11596 if (flow_dv_translate_action_port_id(dev, sub_actions,
11599 port_id_resource.port_id = port_id;
11600 if (flow_dv_port_id_action_resource_register
11601 (dev, &port_id_resource, dev_flow, error))
11603 sample_act->dr_port_id_action =
11604 dev_flow->dv.port_id_action->action;
11605 sample_idx->rix_port_id_action =
11606 dev_flow->handle->rix_port_id_action;
11607 sample_actions[sample_act->actions_num++] =
11608 sample_act->dr_port_id_action;
11609 /* Recover the port id resource after sample */
11610 dev_flow->dv.port_id_action = pre_r;
11611 dev_flow->handle->rix_port_id_action = pre_rix;
11613 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
11616 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11617 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11618 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11619 /* Save the encap resource before sample */
11620 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
11621 pre_r = dev_flow->dv.encap_decap;
11622 if (flow_dv_create_action_l2_encap(dev, sub_actions,
11627 sample_act->dr_encap_action =
11628 dev_flow->dv.encap_decap->action;
11629 sample_idx->rix_encap_decap =
11630 dev_flow->handle->dvh.rix_encap_decap;
11631 sample_actions[sample_act->actions_num++] =
11632 sample_act->dr_encap_action;
11633 /* Recover the encap resource after sample */
11634 dev_flow->dv.encap_decap = pre_r;
11635 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
11636 action_flags |= MLX5_FLOW_ACTION_ENCAP;
11639 return rte_flow_error_set(error, EINVAL,
11640 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11642 "Not support for sampler action");
11645 sample_act->action_flags = action_flags;
11646 res->ft_id = dev_flow->dv.group;
11647 if (attr->transfer) {
11649 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
11650 uint64_t set_action;
11651 } action_ctx = { .set_action = 0 };
11653 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
11654 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
11655 MLX5_MODIFICATION_TYPE_SET);
11656 MLX5_SET(set_action_in, action_ctx.action_in, field,
11657 MLX5_MODI_META_REG_C_0);
11658 MLX5_SET(set_action_in, action_ctx.action_in, data,
11659 priv->vport_meta_tag);
11660 res->set_action = action_ctx.set_action;
11661 } else if (attr->ingress) {
11662 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
11664 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
11670 * Convert Sample action to DV specification.
11673 * Pointer to rte_eth_dev structure.
11674 * @param[in, out] dev_flow
11675 * Pointer to the mlx5_flow.
11676 * @param[in] num_of_dest
11677 * The num of destination.
11678 * @param[in, out] res
11679 * Pointer to sample resource.
11680 * @param[in, out] mdest_res
11681 * Pointer to destination array resource.
11682 * @param[in] sample_actions
11683 * Pointer to sample path actions list.
11684 * @param[in] action_flags
11685 * Holds the actions detected until now.
11686 * @param[out] error
11687 * Pointer to the error structure.
11690 * 0 on success, a negative errno value otherwise and rte_errno is set.
11693 flow_dv_create_action_sample(struct rte_eth_dev *dev,
11694 struct mlx5_flow *dev_flow,
11695 uint32_t num_of_dest,
11696 struct mlx5_flow_dv_sample_resource *res,
11697 struct mlx5_flow_dv_dest_array_resource *mdest_res,
11698 void **sample_actions,
11699 uint64_t action_flags,
11700 struct rte_flow_error *error)
11702 /* update normal path action resource into last index of array */
11703 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
11704 struct mlx5_flow_sub_actions_list *sample_act =
11705 &mdest_res->sample_act[dest_index];
11706 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11707 struct mlx5_flow_rss_desc *rss_desc;
11708 uint32_t normal_idx = 0;
11709 struct mlx5_hrxq *hrxq;
11713 rss_desc = &wks->rss_desc;
11714 if (num_of_dest > 1) {
11715 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
11716 /* Handle QP action for mirroring */
11717 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11718 rss_desc, &hrxq_idx);
11720 return rte_flow_error_set
11722 RTE_FLOW_ERROR_TYPE_ACTION,
11724 "cannot create rx queue");
11726 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
11727 sample_act->dr_queue_action = hrxq->action;
11728 if (action_flags & MLX5_FLOW_ACTION_MARK)
11729 dev_flow->handle->rix_hrxq = hrxq_idx;
11730 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
11732 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
11734 mdest_res->sample_idx[dest_index].rix_encap_decap =
11735 dev_flow->handle->dvh.rix_encap_decap;
11736 sample_act->dr_encap_action =
11737 dev_flow->dv.encap_decap->action;
11738 dev_flow->handle->dvh.rix_encap_decap = 0;
11740 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
11742 mdest_res->sample_idx[dest_index].rix_port_id_action =
11743 dev_flow->handle->rix_port_id_action;
11744 sample_act->dr_port_id_action =
11745 dev_flow->dv.port_id_action->action;
11746 dev_flow->handle->rix_port_id_action = 0;
11748 if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
11750 mdest_res->sample_idx[dest_index].rix_jump =
11751 dev_flow->handle->rix_jump;
11752 sample_act->dr_jump_action =
11753 dev_flow->dv.jump->action;
11754 dev_flow->handle->rix_jump = 0;
11756 sample_act->actions_num = normal_idx;
11757 /* update sample action resource into first index of array */
11758 mdest_res->ft_type = res->ft_type;
11759 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
11760 sizeof(struct mlx5_flow_sub_actions_idx));
11761 memcpy(&mdest_res->sample_act[0], &res->sample_act,
11762 sizeof(struct mlx5_flow_sub_actions_list));
11763 mdest_res->num_of_dest = num_of_dest;
11764 if (flow_dv_dest_array_resource_register(dev, mdest_res,
11766 return rte_flow_error_set(error, EINVAL,
11767 RTE_FLOW_ERROR_TYPE_ACTION,
11768 NULL, "can't create sample "
11771 res->sub_actions = sample_actions;
11772 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
11773 return rte_flow_error_set(error, EINVAL,
11774 RTE_FLOW_ERROR_TYPE_ACTION,
11776 "can't create sample action");
11782 * Remove an ASO age action from age actions list.
11785 * Pointer to the Ethernet device structure.
11787 * Pointer to the aso age action handler.
11790 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
11791 struct mlx5_aso_age_action *age)
11793 struct mlx5_age_info *age_info;
11794 struct mlx5_age_param *age_param = &age->age_params;
11795 struct mlx5_priv *priv = dev->data->dev_private;
11796 uint16_t expected = AGE_CANDIDATE;
11798 age_info = GET_PORT_AGE_INFO(priv);
11799 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
11800 AGE_FREE, false, __ATOMIC_RELAXED,
11801 __ATOMIC_RELAXED)) {
11803 * We need the lock even it is age timeout,
11804 * since age action may still in process.
11806 rte_spinlock_lock(&age_info->aged_sl);
11807 LIST_REMOVE(age, next);
11808 rte_spinlock_unlock(&age_info->aged_sl);
11809 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
11814 * Release an ASO age action.
11817 * Pointer to the Ethernet device structure.
11818 * @param[in] age_idx
11819 * Index of ASO age action to release.
11821 * True if the release operation is during flow destroy operation.
11822 * False if the release operation is during action destroy operation.
11825 * 0 when age action was removed, otherwise the number of references.
11828 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
11830 struct mlx5_priv *priv = dev->data->dev_private;
11831 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11832 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
11833 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
11836 flow_dv_aso_age_remove_from_age(dev, age);
11837 rte_spinlock_lock(&mng->free_sl);
11838 LIST_INSERT_HEAD(&mng->free, age, next);
11839 rte_spinlock_unlock(&mng->free_sl);
11845 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
11848 * Pointer to the Ethernet device structure.
11851 * 0 on success, otherwise negative errno value and rte_errno is set.
11854 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
11856 struct mlx5_priv *priv = dev->data->dev_private;
11857 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11858 void *old_pools = mng->pools;
11859 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
11860 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
11861 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11864 rte_errno = ENOMEM;
11868 memcpy(pools, old_pools,
11869 mng->n * sizeof(struct mlx5_flow_counter_pool *));
11870 mlx5_free(old_pools);
11872 /* First ASO flow hit allocation - starting ASO data-path. */
11873 int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
11881 mng->pools = pools;
11886 * Create and initialize a new ASO aging pool.
11889 * Pointer to the Ethernet device structure.
11890 * @param[out] age_free
11891 * Where to put the pointer of a new age action.
11894 * The age actions pool pointer and @p age_free is set on success,
11895 * NULL otherwise and rte_errno is set.
11897 static struct mlx5_aso_age_pool *
11898 flow_dv_age_pool_create(struct rte_eth_dev *dev,
11899 struct mlx5_aso_age_action **age_free)
11901 struct mlx5_priv *priv = dev->data->dev_private;
11902 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11903 struct mlx5_aso_age_pool *pool = NULL;
11904 struct mlx5_devx_obj *obj = NULL;
11907 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->ctx,
11910 rte_errno = ENODATA;
11911 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
11914 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
11916 claim_zero(mlx5_devx_cmd_destroy(obj));
11917 rte_errno = ENOMEM;
11920 pool->flow_hit_aso_obj = obj;
11921 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
11922 rte_spinlock_lock(&mng->resize_sl);
11923 pool->index = mng->next;
11924 /* Resize pools array if there is no room for the new pool in it. */
11925 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
11926 claim_zero(mlx5_devx_cmd_destroy(obj));
11928 rte_spinlock_unlock(&mng->resize_sl);
11931 mng->pools[pool->index] = pool;
11933 rte_spinlock_unlock(&mng->resize_sl);
11934 /* Assign the first action in the new pool, the rest go to free list. */
11935 *age_free = &pool->actions[0];
11936 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
11937 pool->actions[i].offset = i;
11938 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
11944 * Allocate a ASO aging bit.
11947 * Pointer to the Ethernet device structure.
11948 * @param[out] error
11949 * Pointer to the error structure.
11952 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
11955 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
11957 struct mlx5_priv *priv = dev->data->dev_private;
11958 const struct mlx5_aso_age_pool *pool;
11959 struct mlx5_aso_age_action *age_free = NULL;
11960 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11963 /* Try to get the next free age action bit. */
11964 rte_spinlock_lock(&mng->free_sl);
11965 age_free = LIST_FIRST(&mng->free);
11967 LIST_REMOVE(age_free, next);
11968 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
11969 rte_spinlock_unlock(&mng->free_sl);
11970 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
11971 NULL, "failed to create ASO age pool");
11972 return 0; /* 0 is an error. */
11974 rte_spinlock_unlock(&mng->free_sl);
11975 pool = container_of
11976 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
11977 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
11979 if (!age_free->dr_action) {
11980 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
11984 rte_flow_error_set(error, rte_errno,
11985 RTE_FLOW_ERROR_TYPE_ACTION,
11986 NULL, "failed to get reg_c "
11987 "for ASO flow hit");
11988 return 0; /* 0 is an error. */
11990 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
11991 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
11992 (priv->sh->rx_domain,
11993 pool->flow_hit_aso_obj->obj, age_free->offset,
11994 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
11995 (reg_c - REG_C_0));
11996 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
11997 if (!age_free->dr_action) {
11999 rte_spinlock_lock(&mng->free_sl);
12000 LIST_INSERT_HEAD(&mng->free, age_free, next);
12001 rte_spinlock_unlock(&mng->free_sl);
12002 rte_flow_error_set(error, rte_errno,
12003 RTE_FLOW_ERROR_TYPE_ACTION,
12004 NULL, "failed to create ASO "
12005 "flow hit action");
12006 return 0; /* 0 is an error. */
12009 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
12010 return pool->index | ((age_free->offset + 1) << 16);
12014 * Initialize flow ASO age parameters.
12017 * Pointer to rte_eth_dev structure.
12018 * @param[in] age_idx
12019 * Index of ASO age action.
12020 * @param[in] context
12021 * Pointer to flow counter age context.
12022 * @param[in] timeout
12023 * Aging timeout in seconds.
12027 flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
12032 struct mlx5_aso_age_action *aso_age;
12034 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
12035 MLX5_ASSERT(aso_age);
12036 aso_age->age_params.context = context;
12037 aso_age->age_params.timeout = timeout;
12038 aso_age->age_params.port_id = dev->data->port_id;
12039 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
12041 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
12046 flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
12047 const struct rte_flow_item_integrity *value,
12048 void *headers_m, void *headers_v)
12051 /* application l4_ok filter aggregates all hardware l4 filters
12052 * therefore hw l4_checksum_ok must be implicitly added here.
12054 struct rte_flow_item_integrity local_item;
12056 local_item.l4_csum_ok = 1;
12057 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
12058 local_item.l4_csum_ok);
12059 if (value->l4_ok) {
12060 /* application l4_ok = 1 matches sets both hw flags
12061 * l4_ok and l4_checksum_ok flags to 1.
12063 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12064 l4_checksum_ok, local_item.l4_csum_ok);
12065 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_ok,
12067 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_ok,
12070 /* application l4_ok = 0 matches on hw flag
12071 * l4_checksum_ok = 0 only.
12073 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12074 l4_checksum_ok, 0);
12076 } else if (mask->l4_csum_ok) {
12077 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
12079 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_checksum_ok,
12080 value->l4_csum_ok);
12085 flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
12086 const struct rte_flow_item_integrity *value,
12087 void *headers_m, void *headers_v,
12091 /* application l3_ok filter aggregates all hardware l3 filters
12092 * therefore hw ipv4_checksum_ok must be implicitly added here.
12094 struct rte_flow_item_integrity local_item;
12096 local_item.ipv4_csum_ok = !!is_ipv4;
12097 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
12098 local_item.ipv4_csum_ok);
12099 if (value->l3_ok) {
12100 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12101 ipv4_checksum_ok, local_item.ipv4_csum_ok);
12102 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l3_ok,
12104 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l3_ok,
12107 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12108 ipv4_checksum_ok, 0);
12110 } else if (mask->ipv4_csum_ok) {
12111 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
12112 mask->ipv4_csum_ok);
12113 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
12114 value->ipv4_csum_ok);
12119 flow_dv_translate_item_integrity(void *matcher, void *key,
12120 const struct rte_flow_item *head_item,
12121 const struct rte_flow_item *integrity_item)
12123 const struct rte_flow_item_integrity *mask = integrity_item->mask;
12124 const struct rte_flow_item_integrity *value = integrity_item->spec;
12125 const struct rte_flow_item *tunnel_item, *end_item, *item;
12128 uint32_t l3_protocol;
12133 mask = &rte_flow_item_integrity_mask;
12134 if (value->level > 1) {
12135 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12137 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
12139 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12141 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
12143 tunnel_item = mlx5_flow_find_tunnel_item(head_item);
12144 if (value->level > 1) {
12145 /* tunnel item was verified during the item validation */
12146 item = tunnel_item;
12147 end_item = mlx5_find_end_item(tunnel_item);
12150 end_item = tunnel_item ? tunnel_item :
12151 mlx5_find_end_item(integrity_item);
12153 l3_protocol = mask->l3_ok ?
12154 mlx5_flow_locate_proto_l3(&item, end_item) : 0;
12155 flow_dv_translate_integrity_l3(mask, value, headers_m, headers_v,
12156 l3_protocol == RTE_ETHER_TYPE_IPV4);
12157 flow_dv_translate_integrity_l4(mask, value, headers_m, headers_v);
12161 * Prepares DV flow counter with aging configuration.
12162 * Gets it by index when exists, creates a new one when doesn't.
12165 * Pointer to rte_eth_dev structure.
12166 * @param[in] dev_flow
12167 * Pointer to the mlx5_flow.
12168 * @param[in, out] flow
12169 * Pointer to the sub flow.
12171 * Pointer to the counter action configuration.
12173 * Pointer to the aging action configuration.
12174 * @param[out] error
12175 * Pointer to the error structure.
12178 * Pointer to the counter, NULL otherwise.
12180 static struct mlx5_flow_counter *
12181 flow_dv_prepare_counter(struct rte_eth_dev *dev,
12182 struct mlx5_flow *dev_flow,
12183 struct rte_flow *flow,
12184 const struct rte_flow_action_count *count,
12185 const struct rte_flow_action_age *age,
12186 struct rte_flow_error *error)
12188 if (!flow->counter) {
12189 flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
12191 if (!flow->counter) {
12192 rte_flow_error_set(error, rte_errno,
12193 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12194 "cannot create counter object.");
12198 return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
12202 * Release an ASO CT action by its own device.
12205 * Pointer to the Ethernet device structure.
12207 * Index of ASO CT action to release.
12210 * 0 when CT action was removed, otherwise the number of references.
12213 flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
12215 struct mlx5_priv *priv = dev->data->dev_private;
12216 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12218 struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12219 enum mlx5_aso_ct_state state =
12220 __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
12222 /* Cannot release when CT is in the ASO SQ. */
12223 if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
12225 ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
12227 if (ct->dr_action_orig) {
12228 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12229 claim_zero(mlx5_glue->destroy_flow_action
12230 (ct->dr_action_orig));
12232 ct->dr_action_orig = NULL;
12234 if (ct->dr_action_rply) {
12235 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12236 claim_zero(mlx5_glue->destroy_flow_action
12237 (ct->dr_action_rply));
12239 ct->dr_action_rply = NULL;
12241 /* Clear the state to free, no need in 1st allocation. */
12242 MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
12243 rte_spinlock_lock(&mng->ct_sl);
12244 LIST_INSERT_HEAD(&mng->free_cts, ct, next);
12245 rte_spinlock_unlock(&mng->ct_sl);
12251 flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
12252 struct rte_flow_error *error)
12254 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
12255 uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
12256 struct rte_eth_dev *owndev = &rte_eth_devices[owner];
12259 MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
12260 if (dev->data->dev_started != 1)
12261 return rte_flow_error_set(error, EAGAIN,
12262 RTE_FLOW_ERROR_TYPE_ACTION,
12264 "Indirect CT action cannot be destroyed when the port is stopped");
12265 ret = flow_dv_aso_ct_dev_release(owndev, idx);
12267 return rte_flow_error_set(error, EAGAIN,
12268 RTE_FLOW_ERROR_TYPE_ACTION,
12270 "Current state prevents indirect CT action from being destroyed");
12275 * Resize the ASO CT pools array by 64 pools.
12278 * Pointer to the Ethernet device structure.
12281 * 0 on success, otherwise negative errno value and rte_errno is set.
12284 flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
12286 struct mlx5_priv *priv = dev->data->dev_private;
12287 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12288 void *old_pools = mng->pools;
12289 /* Magic number now, need a macro. */
12290 uint32_t resize = mng->n + 64;
12291 uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
12292 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
12295 rte_errno = ENOMEM;
12298 rte_rwlock_write_lock(&mng->resize_rwl);
12299 /* ASO SQ/QP was already initialized in the startup. */
12301 /* Realloc could be an alternative choice. */
12302 rte_memcpy(pools, old_pools,
12303 mng->n * sizeof(struct mlx5_aso_ct_pool *));
12304 mlx5_free(old_pools);
12307 mng->pools = pools;
12308 rte_rwlock_write_unlock(&mng->resize_rwl);
12313 * Create and initialize a new ASO CT pool.
12316 * Pointer to the Ethernet device structure.
12317 * @param[out] ct_free
12318 * Where to put the pointer of a new CT action.
12321 * The CT actions pool pointer and @p ct_free is set on success,
12322 * NULL otherwise and rte_errno is set.
12324 static struct mlx5_aso_ct_pool *
12325 flow_dv_ct_pool_create(struct rte_eth_dev *dev,
12326 struct mlx5_aso_ct_action **ct_free)
12328 struct mlx5_priv *priv = dev->data->dev_private;
12329 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12330 struct mlx5_aso_ct_pool *pool = NULL;
12331 struct mlx5_devx_obj *obj = NULL;
12333 uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
12335 obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->ctx,
12336 priv->sh->pdn, log_obj_size);
12338 rte_errno = ENODATA;
12339 DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
12342 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
12344 rte_errno = ENOMEM;
12345 claim_zero(mlx5_devx_cmd_destroy(obj));
12348 pool->devx_obj = obj;
12349 pool->index = mng->next;
12350 /* Resize pools array if there is no room for the new pool in it. */
12351 if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
12352 claim_zero(mlx5_devx_cmd_destroy(obj));
12356 mng->pools[pool->index] = pool;
12358 /* Assign the first action in the new pool, the rest go to free list. */
12359 *ct_free = &pool->actions[0];
12360 /* Lock outside, the list operation is safe here. */
12361 for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
12362 /* refcnt is 0 when allocating the memory. */
12363 pool->actions[i].offset = i;
12364 LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
12370 * Allocate a ASO CT action from free list.
12373 * Pointer to the Ethernet device structure.
12374 * @param[out] error
12375 * Pointer to the error structure.
12378 * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
12381 flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
12383 struct mlx5_priv *priv = dev->data->dev_private;
12384 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12385 struct mlx5_aso_ct_action *ct = NULL;
12386 struct mlx5_aso_ct_pool *pool;
12391 if (!priv->config.devx) {
12392 rte_errno = ENOTSUP;
12395 /* Get a free CT action, if no, a new pool will be created. */
12396 rte_spinlock_lock(&mng->ct_sl);
12397 ct = LIST_FIRST(&mng->free_cts);
12399 LIST_REMOVE(ct, next);
12400 } else if (!flow_dv_ct_pool_create(dev, &ct)) {
12401 rte_spinlock_unlock(&mng->ct_sl);
12402 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
12403 NULL, "failed to create ASO CT pool");
12406 rte_spinlock_unlock(&mng->ct_sl);
12407 pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
12408 ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
12409 /* 0: inactive, 1: created, 2+: used by flows. */
12410 __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
12411 reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
12412 if (!ct->dr_action_orig) {
12413 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12414 ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
12415 (priv->sh->rx_domain, pool->devx_obj->obj,
12417 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
12420 RTE_SET_USED(reg_c);
12422 if (!ct->dr_action_orig) {
12423 flow_dv_aso_ct_dev_release(dev, ct_idx);
12424 rte_flow_error_set(error, rte_errno,
12425 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12426 "failed to create ASO CT action");
12430 if (!ct->dr_action_rply) {
12431 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12432 ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
12433 (priv->sh->rx_domain, pool->devx_obj->obj,
12435 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
12438 if (!ct->dr_action_rply) {
12439 flow_dv_aso_ct_dev_release(dev, ct_idx);
12440 rte_flow_error_set(error, rte_errno,
12441 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12442 "failed to create ASO CT action");
12450 * Create a conntrack object with context and actions by using ASO mechanism.
12453 * Pointer to rte_eth_dev structure.
12455 * Pointer to conntrack information profile.
12456 * @param[out] error
12457 * Pointer to the error structure.
12460 * Index to conntrack object on success, 0 otherwise.
12463 flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
12464 const struct rte_flow_action_conntrack *pro,
12465 struct rte_flow_error *error)
12467 struct mlx5_priv *priv = dev->data->dev_private;
12468 struct mlx5_dev_ctx_shared *sh = priv->sh;
12469 struct mlx5_aso_ct_action *ct;
12472 if (!sh->ct_aso_en)
12473 return rte_flow_error_set(error, ENOTSUP,
12474 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12475 "Connection is not supported");
12476 idx = flow_dv_aso_ct_alloc(dev, error);
12478 return rte_flow_error_set(error, rte_errno,
12479 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12480 "Failed to allocate CT object");
12481 ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12482 if (mlx5_aso_ct_update_by_wqe(sh, ct, pro))
12483 return rte_flow_error_set(error, EBUSY,
12484 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12485 "Failed to update CT");
12486 ct->is_original = !!pro->is_original_dir;
12487 ct->peer = pro->peer_port;
12492 * Fill the flow with DV spec, lock free
12493 * (mutex should be acquired by caller).
12496 * Pointer to rte_eth_dev structure.
12497 * @param[in, out] dev_flow
12498 * Pointer to the sub flow.
12500 * Pointer to the flow attributes.
12502 * Pointer to the list of items.
12503 * @param[in] actions
12504 * Pointer to the list of actions.
12505 * @param[out] error
12506 * Pointer to the error structure.
12509 * 0 on success, a negative errno value otherwise and rte_errno is set.
12512 flow_dv_translate(struct rte_eth_dev *dev,
12513 struct mlx5_flow *dev_flow,
12514 const struct rte_flow_attr *attr,
12515 const struct rte_flow_item items[],
12516 const struct rte_flow_action actions[],
12517 struct rte_flow_error *error)
12519 struct mlx5_priv *priv = dev->data->dev_private;
12520 struct mlx5_dev_config *dev_conf = &priv->config;
12521 struct rte_flow *flow = dev_flow->flow;
12522 struct mlx5_flow_handle *handle = dev_flow->handle;
12523 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12524 struct mlx5_flow_rss_desc *rss_desc;
12525 uint64_t item_flags = 0;
12526 uint64_t last_item = 0;
12527 uint64_t action_flags = 0;
12528 struct mlx5_flow_dv_matcher matcher = {
12530 .size = sizeof(matcher.mask.buf),
12534 bool actions_end = false;
12536 struct mlx5_flow_dv_modify_hdr_resource res;
12537 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
12538 sizeof(struct mlx5_modification_cmd) *
12539 (MLX5_MAX_MODIFY_NUM + 1)];
12541 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
12542 const struct rte_flow_action_count *count = NULL;
12543 const struct rte_flow_action_age *non_shared_age = NULL;
12544 union flow_dv_attr flow_attr = { .attr = 0 };
12546 union mlx5_flow_tbl_key tbl_key;
12547 uint32_t modify_action_position = UINT32_MAX;
12548 void *match_mask = matcher.mask.buf;
12549 void *match_value = dev_flow->dv.value.buf;
12550 uint8_t next_protocol = 0xff;
12551 struct rte_vlan_hdr vlan = { 0 };
12552 struct mlx5_flow_dv_dest_array_resource mdest_res;
12553 struct mlx5_flow_dv_sample_resource sample_res;
12554 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
12555 const struct rte_flow_action_sample *sample = NULL;
12556 struct mlx5_flow_sub_actions_list *sample_act;
12557 uint32_t sample_act_pos = UINT32_MAX;
12558 uint32_t age_act_pos = UINT32_MAX;
12559 uint32_t num_of_dest = 0;
12560 int tmp_actions_n = 0;
12563 const struct mlx5_flow_tunnel *tunnel = NULL;
12564 struct flow_grp_info grp_info = {
12565 .external = !!dev_flow->external,
12566 .transfer = !!attr->transfer,
12567 .fdb_def_rule = !!priv->fdb_def_rule,
12568 .skip_scale = dev_flow->skip_scale &
12569 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
12570 .std_tbl_fix = true,
12572 const struct rte_flow_item *head_item = items;
12575 return rte_flow_error_set(error, ENOMEM,
12576 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12578 "failed to push flow workspace");
12579 rss_desc = &wks->rss_desc;
12580 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
12581 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
12582 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12583 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12584 /* update normal path action resource into last index of array */
12585 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
12586 if (is_tunnel_offload_active(dev)) {
12587 if (dev_flow->tunnel) {
12588 RTE_VERIFY(dev_flow->tof_type ==
12589 MLX5_TUNNEL_OFFLOAD_MISS_RULE);
12590 tunnel = dev_flow->tunnel;
12592 tunnel = mlx5_get_tof(items, actions,
12593 &dev_flow->tof_type);
12594 dev_flow->tunnel = tunnel;
12596 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
12597 (dev, attr, tunnel, dev_flow->tof_type);
12599 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12600 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12601 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
12605 dev_flow->dv.group = table;
12606 if (attr->transfer)
12607 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12608 /* number of actions must be set to 0 in case of dirty stack. */
12609 mhdr_res->actions_num = 0;
12610 if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
12612 * do not add decap action if match rule drops packet
12613 * HW rejects rules with decap & drop
12615 * if tunnel match rule was inserted before matching tunnel set
12616 * rule flow table used in the match rule must be registered.
12617 * current implementation handles that in the
12618 * flow_dv_match_register() at the function end.
12620 bool add_decap = true;
12621 const struct rte_flow_action *ptr = actions;
12623 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
12624 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
12630 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12634 dev_flow->dv.actions[actions_n++] =
12635 dev_flow->dv.encap_decap->action;
12636 action_flags |= MLX5_FLOW_ACTION_DECAP;
12639 for (; !actions_end ; actions++) {
12640 const struct rte_flow_action_queue *queue;
12641 const struct rte_flow_action_rss *rss;
12642 const struct rte_flow_action *action = actions;
12643 const uint8_t *rss_key;
12644 struct mlx5_flow_tbl_resource *tbl;
12645 struct mlx5_aso_age_action *age_act;
12646 struct mlx5_flow_counter *cnt_act;
12647 uint32_t port_id = 0;
12648 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
12649 int action_type = actions->type;
12650 const struct rte_flow_action *found_action = NULL;
12651 uint32_t jump_group = 0;
12652 uint32_t owner_idx;
12653 struct mlx5_aso_ct_action *ct;
12655 if (!mlx5_flow_os_action_supported(action_type))
12656 return rte_flow_error_set(error, ENOTSUP,
12657 RTE_FLOW_ERROR_TYPE_ACTION,
12659 "action not supported");
12660 switch (action_type) {
12661 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
12662 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
12664 case RTE_FLOW_ACTION_TYPE_VOID:
12666 case RTE_FLOW_ACTION_TYPE_PORT_ID:
12667 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
12668 if (flow_dv_translate_action_port_id(dev, action,
12671 port_id_resource.port_id = port_id;
12672 MLX5_ASSERT(!handle->rix_port_id_action);
12673 if (flow_dv_port_id_action_resource_register
12674 (dev, &port_id_resource, dev_flow, error))
12676 dev_flow->dv.actions[actions_n++] =
12677 dev_flow->dv.port_id_action->action;
12678 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12679 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
12680 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12683 case RTE_FLOW_ACTION_TYPE_FLAG:
12684 action_flags |= MLX5_FLOW_ACTION_FLAG;
12685 dev_flow->handle->mark = 1;
12686 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12687 struct rte_flow_action_mark mark = {
12688 .id = MLX5_FLOW_MARK_DEFAULT,
12691 if (flow_dv_convert_action_mark(dev, &mark,
12695 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12698 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
12700 * Only one FLAG or MARK is supported per device flow
12701 * right now. So the pointer to the tag resource must be
12702 * zero before the register process.
12704 MLX5_ASSERT(!handle->dvh.rix_tag);
12705 if (flow_dv_tag_resource_register(dev, tag_be,
12708 MLX5_ASSERT(dev_flow->dv.tag_resource);
12709 dev_flow->dv.actions[actions_n++] =
12710 dev_flow->dv.tag_resource->action;
12712 case RTE_FLOW_ACTION_TYPE_MARK:
12713 action_flags |= MLX5_FLOW_ACTION_MARK;
12714 dev_flow->handle->mark = 1;
12715 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12716 const struct rte_flow_action_mark *mark =
12717 (const struct rte_flow_action_mark *)
12720 if (flow_dv_convert_action_mark(dev, mark,
12724 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12728 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
12729 /* Legacy (non-extensive) MARK action. */
12730 tag_be = mlx5_flow_mark_set
12731 (((const struct rte_flow_action_mark *)
12732 (actions->conf))->id);
12733 MLX5_ASSERT(!handle->dvh.rix_tag);
12734 if (flow_dv_tag_resource_register(dev, tag_be,
12737 MLX5_ASSERT(dev_flow->dv.tag_resource);
12738 dev_flow->dv.actions[actions_n++] =
12739 dev_flow->dv.tag_resource->action;
12741 case RTE_FLOW_ACTION_TYPE_SET_META:
12742 if (flow_dv_convert_action_set_meta
12743 (dev, mhdr_res, attr,
12744 (const struct rte_flow_action_set_meta *)
12745 actions->conf, error))
12747 action_flags |= MLX5_FLOW_ACTION_SET_META;
12749 case RTE_FLOW_ACTION_TYPE_SET_TAG:
12750 if (flow_dv_convert_action_set_tag
12752 (const struct rte_flow_action_set_tag *)
12753 actions->conf, error))
12755 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12757 case RTE_FLOW_ACTION_TYPE_DROP:
12758 action_flags |= MLX5_FLOW_ACTION_DROP;
12759 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
12761 case RTE_FLOW_ACTION_TYPE_QUEUE:
12762 queue = actions->conf;
12763 rss_desc->queue_num = 1;
12764 rss_desc->queue[0] = queue->index;
12765 action_flags |= MLX5_FLOW_ACTION_QUEUE;
12766 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
12767 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
12770 case RTE_FLOW_ACTION_TYPE_RSS:
12771 rss = actions->conf;
12772 memcpy(rss_desc->queue, rss->queue,
12773 rss->queue_num * sizeof(uint16_t));
12774 rss_desc->queue_num = rss->queue_num;
12775 /* NULL RSS key indicates default RSS key. */
12776 rss_key = !rss->key ? rss_hash_default_key : rss->key;
12777 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12779 * rss->level and rss.types should be set in advance
12780 * when expanding items for RSS.
12782 action_flags |= MLX5_FLOW_ACTION_RSS;
12783 dev_flow->handle->fate_action = rss_desc->shared_rss ?
12784 MLX5_FLOW_FATE_SHARED_RSS :
12785 MLX5_FLOW_FATE_QUEUE;
12787 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
12788 owner_idx = (uint32_t)(uintptr_t)action->conf;
12789 age_act = flow_aso_age_get_by_idx(dev, owner_idx);
12790 if (flow->age == 0) {
12791 flow->age = owner_idx;
12792 __atomic_fetch_add(&age_act->refcnt, 1,
12795 age_act_pos = actions_n++;
12796 action_flags |= MLX5_FLOW_ACTION_AGE;
12798 case RTE_FLOW_ACTION_TYPE_AGE:
12799 non_shared_age = action->conf;
12800 age_act_pos = actions_n++;
12801 action_flags |= MLX5_FLOW_ACTION_AGE;
12803 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
12804 owner_idx = (uint32_t)(uintptr_t)action->conf;
12805 cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
12807 MLX5_ASSERT(cnt_act != NULL);
12809 * When creating meter drop flow in drop table, the
12810 * counter should not overwrite the rte flow counter.
12812 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
12813 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
12814 dev_flow->dv.actions[actions_n++] =
12817 if (flow->counter == 0) {
12818 flow->counter = owner_idx;
12820 (&cnt_act->shared_info.refcnt,
12821 1, __ATOMIC_RELAXED);
12823 /* Save information first, will apply later. */
12824 action_flags |= MLX5_FLOW_ACTION_COUNT;
12827 case RTE_FLOW_ACTION_TYPE_COUNT:
12828 if (!dev_conf->devx) {
12829 return rte_flow_error_set
12831 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12833 "count action not supported");
12835 /* Save information first, will apply later. */
12836 count = action->conf;
12837 action_flags |= MLX5_FLOW_ACTION_COUNT;
12839 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
12840 dev_flow->dv.actions[actions_n++] =
12841 priv->sh->pop_vlan_action;
12842 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
12844 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
12845 if (!(action_flags &
12846 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
12847 flow_dev_get_vlan_info_from_items(items, &vlan);
12848 vlan.eth_proto = rte_be_to_cpu_16
12849 ((((const struct rte_flow_action_of_push_vlan *)
12850 actions->conf)->ethertype));
12851 found_action = mlx5_flow_find_action
12853 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
12855 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12856 found_action = mlx5_flow_find_action
12858 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
12860 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12861 if (flow_dv_create_action_push_vlan
12862 (dev, attr, &vlan, dev_flow, error))
12864 dev_flow->dv.actions[actions_n++] =
12865 dev_flow->dv.push_vlan_res->action;
12866 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
12868 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
12869 /* of_vlan_push action handled this action */
12870 MLX5_ASSERT(action_flags &
12871 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
12873 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
12874 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
12876 flow_dev_get_vlan_info_from_items(items, &vlan);
12877 mlx5_update_vlan_vid_pcp(actions, &vlan);
12878 /* If no VLAN push - this is a modify header action */
12879 if (flow_dv_convert_action_modify_vlan_vid
12880 (mhdr_res, actions, error))
12882 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
12884 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
12885 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
12886 if (flow_dv_create_action_l2_encap(dev, actions,
12891 dev_flow->dv.actions[actions_n++] =
12892 dev_flow->dv.encap_decap->action;
12893 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12894 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12895 sample_act->action_flags |=
12896 MLX5_FLOW_ACTION_ENCAP;
12898 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
12899 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
12900 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12904 dev_flow->dv.actions[actions_n++] =
12905 dev_flow->dv.encap_decap->action;
12906 action_flags |= MLX5_FLOW_ACTION_DECAP;
12908 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
12909 /* Handle encap with preceding decap. */
12910 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
12911 if (flow_dv_create_action_raw_encap
12912 (dev, actions, dev_flow, attr, error))
12914 dev_flow->dv.actions[actions_n++] =
12915 dev_flow->dv.encap_decap->action;
12917 /* Handle encap without preceding decap. */
12918 if (flow_dv_create_action_l2_encap
12919 (dev, actions, dev_flow, attr->transfer,
12922 dev_flow->dv.actions[actions_n++] =
12923 dev_flow->dv.encap_decap->action;
12925 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12926 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12927 sample_act->action_flags |=
12928 MLX5_FLOW_ACTION_ENCAP;
12930 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
12931 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
12933 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
12934 if (flow_dv_create_action_l2_decap
12935 (dev, dev_flow, attr->transfer, error))
12937 dev_flow->dv.actions[actions_n++] =
12938 dev_flow->dv.encap_decap->action;
12940 /* If decap is followed by encap, handle it at encap. */
12941 action_flags |= MLX5_FLOW_ACTION_DECAP;
12943 case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
12944 dev_flow->dv.actions[actions_n++] =
12945 (void *)(uintptr_t)action->conf;
12946 action_flags |= MLX5_FLOW_ACTION_JUMP;
12948 case RTE_FLOW_ACTION_TYPE_JUMP:
12949 jump_group = ((const struct rte_flow_action_jump *)
12950 action->conf)->group;
12951 grp_info.std_tbl_fix = 0;
12952 if (dev_flow->skip_scale &
12953 (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
12954 grp_info.skip_scale = 1;
12956 grp_info.skip_scale = 0;
12957 ret = mlx5_flow_group_to_table(dev, tunnel,
12963 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
12965 !!dev_flow->external,
12966 tunnel, jump_group, 0,
12969 return rte_flow_error_set
12971 RTE_FLOW_ERROR_TYPE_ACTION,
12973 "cannot create jump action.");
12974 if (flow_dv_jump_tbl_resource_register
12975 (dev, tbl, dev_flow, error)) {
12976 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12977 return rte_flow_error_set
12979 RTE_FLOW_ERROR_TYPE_ACTION,
12981 "cannot create jump action.");
12983 dev_flow->dv.actions[actions_n++] =
12984 dev_flow->dv.jump->action;
12985 action_flags |= MLX5_FLOW_ACTION_JUMP;
12986 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
12987 sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
12990 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
12991 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
12992 if (flow_dv_convert_action_modify_mac
12993 (mhdr_res, actions, error))
12995 action_flags |= actions->type ==
12996 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
12997 MLX5_FLOW_ACTION_SET_MAC_SRC :
12998 MLX5_FLOW_ACTION_SET_MAC_DST;
13000 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
13001 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
13002 if (flow_dv_convert_action_modify_ipv4
13003 (mhdr_res, actions, error))
13005 action_flags |= actions->type ==
13006 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
13007 MLX5_FLOW_ACTION_SET_IPV4_SRC :
13008 MLX5_FLOW_ACTION_SET_IPV4_DST;
13010 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
13011 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
13012 if (flow_dv_convert_action_modify_ipv6
13013 (mhdr_res, actions, error))
13015 action_flags |= actions->type ==
13016 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
13017 MLX5_FLOW_ACTION_SET_IPV6_SRC :
13018 MLX5_FLOW_ACTION_SET_IPV6_DST;
13020 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
13021 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
13022 if (flow_dv_convert_action_modify_tp
13023 (mhdr_res, actions, items,
13024 &flow_attr, dev_flow, !!(action_flags &
13025 MLX5_FLOW_ACTION_DECAP), error))
13027 action_flags |= actions->type ==
13028 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
13029 MLX5_FLOW_ACTION_SET_TP_SRC :
13030 MLX5_FLOW_ACTION_SET_TP_DST;
13032 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
13033 if (flow_dv_convert_action_modify_dec_ttl
13034 (mhdr_res, items, &flow_attr, dev_flow,
13036 MLX5_FLOW_ACTION_DECAP), error))
13038 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
13040 case RTE_FLOW_ACTION_TYPE_SET_TTL:
13041 if (flow_dv_convert_action_modify_ttl
13042 (mhdr_res, actions, items, &flow_attr,
13043 dev_flow, !!(action_flags &
13044 MLX5_FLOW_ACTION_DECAP), error))
13046 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
13048 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
13049 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
13050 if (flow_dv_convert_action_modify_tcp_seq
13051 (mhdr_res, actions, error))
13053 action_flags |= actions->type ==
13054 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
13055 MLX5_FLOW_ACTION_INC_TCP_SEQ :
13056 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
13059 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
13060 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
13061 if (flow_dv_convert_action_modify_tcp_ack
13062 (mhdr_res, actions, error))
13064 action_flags |= actions->type ==
13065 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
13066 MLX5_FLOW_ACTION_INC_TCP_ACK :
13067 MLX5_FLOW_ACTION_DEC_TCP_ACK;
13069 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
13070 if (flow_dv_convert_action_set_reg
13071 (mhdr_res, actions, error))
13073 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13075 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
13076 if (flow_dv_convert_action_copy_mreg
13077 (dev, mhdr_res, actions, error))
13079 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13081 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
13082 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
13083 dev_flow->handle->fate_action =
13084 MLX5_FLOW_FATE_DEFAULT_MISS;
13086 case RTE_FLOW_ACTION_TYPE_METER:
13088 return rte_flow_error_set(error, rte_errno,
13089 RTE_FLOW_ERROR_TYPE_ACTION,
13090 NULL, "Failed to get meter in flow.");
13091 /* Set the meter action. */
13092 dev_flow->dv.actions[actions_n++] =
13093 wks->fm->meter_action;
13094 action_flags |= MLX5_FLOW_ACTION_METER;
13096 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
13097 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
13100 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
13102 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
13103 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
13106 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
13108 case RTE_FLOW_ACTION_TYPE_SAMPLE:
13109 sample_act_pos = actions_n;
13110 sample = (const struct rte_flow_action_sample *)
13113 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
13114 /* put encap action into group if work with port id */
13115 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
13116 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
13117 sample_act->action_flags |=
13118 MLX5_FLOW_ACTION_ENCAP;
13120 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
13121 if (flow_dv_convert_action_modify_field
13122 (dev, mhdr_res, actions, attr, error))
13124 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
13126 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
13127 owner_idx = (uint32_t)(uintptr_t)action->conf;
13128 ct = flow_aso_ct_get_by_idx(dev, owner_idx);
13130 return rte_flow_error_set(error, EINVAL,
13131 RTE_FLOW_ERROR_TYPE_ACTION,
13133 "Failed to get CT object.");
13134 if (mlx5_aso_ct_available(priv->sh, ct))
13135 return rte_flow_error_set(error, rte_errno,
13136 RTE_FLOW_ERROR_TYPE_ACTION,
13138 "CT is unavailable.");
13139 if (ct->is_original)
13140 dev_flow->dv.actions[actions_n] =
13141 ct->dr_action_orig;
13143 dev_flow->dv.actions[actions_n] =
13144 ct->dr_action_rply;
13145 if (flow->ct == 0) {
13146 flow->indirect_type =
13147 MLX5_INDIRECT_ACTION_TYPE_CT;
13148 flow->ct = owner_idx;
13149 __atomic_fetch_add(&ct->refcnt, 1,
13153 action_flags |= MLX5_FLOW_ACTION_CT;
13155 case RTE_FLOW_ACTION_TYPE_END:
13156 actions_end = true;
13157 if (mhdr_res->actions_num) {
13158 /* create modify action if needed. */
13159 if (flow_dv_modify_hdr_resource_register
13160 (dev, mhdr_res, dev_flow, error))
13162 dev_flow->dv.actions[modify_action_position] =
13163 handle->dvh.modify_hdr->action;
13166 * Handle AGE and COUNT action by single HW counter
13167 * when they are not shared.
13169 if (action_flags & MLX5_FLOW_ACTION_AGE) {
13170 if ((non_shared_age && count) ||
13171 !(priv->sh->flow_hit_aso_en &&
13172 (attr->group || attr->transfer))) {
13173 /* Creates age by counters. */
13174 cnt_act = flow_dv_prepare_counter
13181 dev_flow->dv.actions[age_act_pos] =
13185 if (!flow->age && non_shared_age) {
13186 flow->age = flow_dv_aso_age_alloc
13190 flow_dv_aso_age_params_init
13192 non_shared_age->context ?
13193 non_shared_age->context :
13194 (void *)(uintptr_t)
13195 (dev_flow->flow_idx),
13196 non_shared_age->timeout);
13198 age_act = flow_aso_age_get_by_idx(dev,
13200 dev_flow->dv.actions[age_act_pos] =
13201 age_act->dr_action;
13203 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
13205 * Create one count action, to be used
13206 * by all sub-flows.
13208 cnt_act = flow_dv_prepare_counter(dev, dev_flow,
13213 dev_flow->dv.actions[actions_n++] =
13219 if (mhdr_res->actions_num &&
13220 modify_action_position == UINT32_MAX)
13221 modify_action_position = actions_n++;
13223 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
13224 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
13225 int item_type = items->type;
13227 if (!mlx5_flow_os_item_supported(item_type))
13228 return rte_flow_error_set(error, ENOTSUP,
13229 RTE_FLOW_ERROR_TYPE_ITEM,
13230 NULL, "item not supported");
13231 switch (item_type) {
13232 case RTE_FLOW_ITEM_TYPE_PORT_ID:
13233 flow_dv_translate_item_port_id
13234 (dev, match_mask, match_value, items, attr);
13235 last_item = MLX5_FLOW_ITEM_PORT_ID;
13237 case RTE_FLOW_ITEM_TYPE_ETH:
13238 flow_dv_translate_item_eth(match_mask, match_value,
13240 dev_flow->dv.group);
13241 matcher.priority = action_flags &
13242 MLX5_FLOW_ACTION_DEFAULT_MISS &&
13243 !dev_flow->external ?
13244 MLX5_PRIORITY_MAP_L3 :
13245 MLX5_PRIORITY_MAP_L2;
13246 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
13247 MLX5_FLOW_LAYER_OUTER_L2;
13249 case RTE_FLOW_ITEM_TYPE_VLAN:
13250 flow_dv_translate_item_vlan(dev_flow,
13251 match_mask, match_value,
13253 dev_flow->dv.group);
13254 matcher.priority = MLX5_PRIORITY_MAP_L2;
13255 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
13256 MLX5_FLOW_LAYER_INNER_VLAN) :
13257 (MLX5_FLOW_LAYER_OUTER_L2 |
13258 MLX5_FLOW_LAYER_OUTER_VLAN);
13260 case RTE_FLOW_ITEM_TYPE_IPV4:
13261 mlx5_flow_tunnel_ip_check(items, next_protocol,
13262 &item_flags, &tunnel);
13263 flow_dv_translate_item_ipv4(match_mask, match_value,
13265 dev_flow->dv.group);
13266 matcher.priority = MLX5_PRIORITY_MAP_L3;
13267 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
13268 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
13269 if (items->mask != NULL &&
13270 ((const struct rte_flow_item_ipv4 *)
13271 items->mask)->hdr.next_proto_id) {
13273 ((const struct rte_flow_item_ipv4 *)
13274 (items->spec))->hdr.next_proto_id;
13276 ((const struct rte_flow_item_ipv4 *)
13277 (items->mask))->hdr.next_proto_id;
13279 /* Reset for inner layer. */
13280 next_protocol = 0xff;
13283 case RTE_FLOW_ITEM_TYPE_IPV6:
13284 mlx5_flow_tunnel_ip_check(items, next_protocol,
13285 &item_flags, &tunnel);
13286 flow_dv_translate_item_ipv6(match_mask, match_value,
13288 dev_flow->dv.group);
13289 matcher.priority = MLX5_PRIORITY_MAP_L3;
13290 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
13291 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
13292 if (items->mask != NULL &&
13293 ((const struct rte_flow_item_ipv6 *)
13294 items->mask)->hdr.proto) {
13296 ((const struct rte_flow_item_ipv6 *)
13297 items->spec)->hdr.proto;
13299 ((const struct rte_flow_item_ipv6 *)
13300 items->mask)->hdr.proto;
13302 /* Reset for inner layer. */
13303 next_protocol = 0xff;
13306 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
13307 flow_dv_translate_item_ipv6_frag_ext(match_mask,
13310 last_item = tunnel ?
13311 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
13312 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
13313 if (items->mask != NULL &&
13314 ((const struct rte_flow_item_ipv6_frag_ext *)
13315 items->mask)->hdr.next_header) {
13317 ((const struct rte_flow_item_ipv6_frag_ext *)
13318 items->spec)->hdr.next_header;
13320 ((const struct rte_flow_item_ipv6_frag_ext *)
13321 items->mask)->hdr.next_header;
13323 /* Reset for inner layer. */
13324 next_protocol = 0xff;
13327 case RTE_FLOW_ITEM_TYPE_TCP:
13328 flow_dv_translate_item_tcp(match_mask, match_value,
13330 matcher.priority = MLX5_PRIORITY_MAP_L4;
13331 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
13332 MLX5_FLOW_LAYER_OUTER_L4_TCP;
13334 case RTE_FLOW_ITEM_TYPE_UDP:
13335 flow_dv_translate_item_udp(match_mask, match_value,
13337 matcher.priority = MLX5_PRIORITY_MAP_L4;
13338 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
13339 MLX5_FLOW_LAYER_OUTER_L4_UDP;
13341 case RTE_FLOW_ITEM_TYPE_GRE:
13342 flow_dv_translate_item_gre(match_mask, match_value,
13344 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13345 last_item = MLX5_FLOW_LAYER_GRE;
13347 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
13348 flow_dv_translate_item_gre_key(match_mask,
13349 match_value, items);
13350 last_item = MLX5_FLOW_LAYER_GRE_KEY;
13352 case RTE_FLOW_ITEM_TYPE_NVGRE:
13353 flow_dv_translate_item_nvgre(match_mask, match_value,
13355 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13356 last_item = MLX5_FLOW_LAYER_GRE;
13358 case RTE_FLOW_ITEM_TYPE_VXLAN:
13359 flow_dv_translate_item_vxlan(dev, attr,
13360 match_mask, match_value,
13362 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13363 last_item = MLX5_FLOW_LAYER_VXLAN;
13365 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
13366 flow_dv_translate_item_vxlan_gpe(match_mask,
13367 match_value, items,
13369 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13370 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
13372 case RTE_FLOW_ITEM_TYPE_GENEVE:
13373 flow_dv_translate_item_geneve(match_mask, match_value,
13375 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13376 last_item = MLX5_FLOW_LAYER_GENEVE;
13378 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
13379 ret = flow_dv_translate_item_geneve_opt(dev, match_mask,
13383 return rte_flow_error_set(error, -ret,
13384 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13385 "cannot create GENEVE TLV option");
13386 flow->geneve_tlv_option = 1;
13387 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
13389 case RTE_FLOW_ITEM_TYPE_MPLS:
13390 flow_dv_translate_item_mpls(match_mask, match_value,
13391 items, last_item, tunnel);
13392 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13393 last_item = MLX5_FLOW_LAYER_MPLS;
13395 case RTE_FLOW_ITEM_TYPE_MARK:
13396 flow_dv_translate_item_mark(dev, match_mask,
13397 match_value, items);
13398 last_item = MLX5_FLOW_ITEM_MARK;
13400 case RTE_FLOW_ITEM_TYPE_META:
13401 flow_dv_translate_item_meta(dev, match_mask,
13402 match_value, attr, items);
13403 last_item = MLX5_FLOW_ITEM_METADATA;
13405 case RTE_FLOW_ITEM_TYPE_ICMP:
13406 flow_dv_translate_item_icmp(match_mask, match_value,
13408 last_item = MLX5_FLOW_LAYER_ICMP;
13410 case RTE_FLOW_ITEM_TYPE_ICMP6:
13411 flow_dv_translate_item_icmp6(match_mask, match_value,
13413 last_item = MLX5_FLOW_LAYER_ICMP6;
13415 case RTE_FLOW_ITEM_TYPE_TAG:
13416 flow_dv_translate_item_tag(dev, match_mask,
13417 match_value, items);
13418 last_item = MLX5_FLOW_ITEM_TAG;
13420 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
13421 flow_dv_translate_mlx5_item_tag(dev, match_mask,
13422 match_value, items);
13423 last_item = MLX5_FLOW_ITEM_TAG;
13425 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
13426 flow_dv_translate_item_tx_queue(dev, match_mask,
13429 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
13431 case RTE_FLOW_ITEM_TYPE_GTP:
13432 flow_dv_translate_item_gtp(match_mask, match_value,
13434 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13435 last_item = MLX5_FLOW_LAYER_GTP;
13437 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
13438 ret = flow_dv_translate_item_gtp_psc(match_mask,
13442 return rte_flow_error_set(error, -ret,
13443 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13444 "cannot create GTP PSC item");
13445 last_item = MLX5_FLOW_LAYER_GTP_PSC;
13447 case RTE_FLOW_ITEM_TYPE_ECPRI:
13448 if (!mlx5_flex_parser_ecpri_exist(dev)) {
13449 /* Create it only the first time to be used. */
13450 ret = mlx5_flex_parser_ecpri_alloc(dev);
13452 return rte_flow_error_set
13454 RTE_FLOW_ERROR_TYPE_ITEM,
13456 "cannot create eCPRI parser");
13458 flow_dv_translate_item_ecpri(dev, match_mask,
13459 match_value, items,
13461 /* No other protocol should follow eCPRI layer. */
13462 last_item = MLX5_FLOW_LAYER_ECPRI;
13464 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
13465 flow_dv_translate_item_integrity(match_mask,
13469 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
13470 flow_dv_translate_item_aso_ct(dev, match_mask,
13471 match_value, items);
13476 item_flags |= last_item;
13479 * When E-Switch mode is enabled, we have two cases where we need to
13480 * set the source port manually.
13481 * The first one, is in case of Nic steering rule, and the second is
13482 * E-Switch rule where no port_id item was found. In both cases
13483 * the source port is set according the current port in use.
13485 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
13486 (priv->representor || priv->master)) {
13487 if (flow_dv_translate_item_port_id(dev, match_mask,
13488 match_value, NULL, attr))
13491 #ifdef RTE_LIBRTE_MLX5_DEBUG
13492 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
13493 dev_flow->dv.value.buf));
13496 * Layers may be already initialized from prefix flow if this dev_flow
13497 * is the suffix flow.
13499 handle->layers |= item_flags;
13500 if (action_flags & MLX5_FLOW_ACTION_RSS)
13501 flow_dv_hashfields_set(dev_flow, rss_desc);
13502 /* If has RSS action in the sample action, the Sample/Mirror resource
13503 * should be registered after the hash filed be update.
13505 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
13506 ret = flow_dv_translate_action_sample(dev,
13515 ret = flow_dv_create_action_sample(dev,
13524 return rte_flow_error_set
13526 RTE_FLOW_ERROR_TYPE_ACTION,
13528 "cannot create sample action");
13529 if (num_of_dest > 1) {
13530 dev_flow->dv.actions[sample_act_pos] =
13531 dev_flow->dv.dest_array_res->action;
13533 dev_flow->dv.actions[sample_act_pos] =
13534 dev_flow->dv.sample_res->verbs_action;
13538 * For multiple destination (sample action with ratio=1), the encap
13539 * action and port id action will be combined into group action.
13540 * So need remove the original these actions in the flow and only
13541 * use the sample action instead of.
13543 if (num_of_dest > 1 &&
13544 (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
13546 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
13548 for (i = 0; i < actions_n; i++) {
13549 if ((sample_act->dr_encap_action &&
13550 sample_act->dr_encap_action ==
13551 dev_flow->dv.actions[i]) ||
13552 (sample_act->dr_port_id_action &&
13553 sample_act->dr_port_id_action ==
13554 dev_flow->dv.actions[i]) ||
13555 (sample_act->dr_jump_action &&
13556 sample_act->dr_jump_action ==
13557 dev_flow->dv.actions[i]))
13559 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
13561 memcpy((void *)dev_flow->dv.actions,
13562 (void *)temp_actions,
13563 tmp_actions_n * sizeof(void *));
13564 actions_n = tmp_actions_n;
13566 dev_flow->dv.actions_n = actions_n;
13567 dev_flow->act_flags = action_flags;
13568 if (wks->skip_matcher_reg)
13570 /* Register matcher. */
13571 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
13572 matcher.mask.size);
13573 matcher.priority = mlx5_get_matcher_priority(dev, attr,
13576 * When creating meter drop flow in drop table, using original
13577 * 5-tuple match, the matcher priority should be lower than
13580 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
13581 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
13582 matcher.priority <= MLX5_REG_BITS)
13583 matcher.priority += MLX5_REG_BITS;
13584 /* reserved field no needs to be set to 0 here. */
13585 tbl_key.is_fdb = attr->transfer;
13586 tbl_key.is_egress = attr->egress;
13587 tbl_key.level = dev_flow->dv.group;
13588 tbl_key.id = dev_flow->dv.table_id;
13589 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
13590 tunnel, attr->group, error))
13596 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13599 * @param[in, out] action
13600 * Shred RSS action holding hash RX queue objects.
13601 * @param[in] hash_fields
13602 * Defines combination of packet fields to participate in RX hash.
13603 * @param[in] tunnel
13605 * @param[in] hrxq_idx
13606 * Hash RX queue index to set.
13609 * 0 on success, otherwise negative errno value.
13612 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
13613 const uint64_t hash_fields,
13616 uint32_t *hrxqs = action->hrxq;
13618 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13619 case MLX5_RSS_HASH_IPV4:
13620 /* fall-through. */
13621 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13622 /* fall-through. */
13623 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13624 hrxqs[0] = hrxq_idx;
13626 case MLX5_RSS_HASH_IPV4_TCP:
13627 /* fall-through. */
13628 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13629 /* fall-through. */
13630 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13631 hrxqs[1] = hrxq_idx;
13633 case MLX5_RSS_HASH_IPV4_UDP:
13634 /* fall-through. */
13635 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13636 /* fall-through. */
13637 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13638 hrxqs[2] = hrxq_idx;
13640 case MLX5_RSS_HASH_IPV6:
13641 /* fall-through. */
13642 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13643 /* fall-through. */
13644 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13645 hrxqs[3] = hrxq_idx;
13647 case MLX5_RSS_HASH_IPV6_TCP:
13648 /* fall-through. */
13649 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13650 /* fall-through. */
13651 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13652 hrxqs[4] = hrxq_idx;
13654 case MLX5_RSS_HASH_IPV6_UDP:
13655 /* fall-through. */
13656 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13657 /* fall-through. */
13658 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13659 hrxqs[5] = hrxq_idx;
13661 case MLX5_RSS_HASH_NONE:
13662 hrxqs[6] = hrxq_idx;
13670 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13674 * Pointer to the Ethernet device structure.
13676 * Shared RSS action ID holding hash RX queue objects.
13677 * @param[in] hash_fields
13678 * Defines combination of packet fields to participate in RX hash.
13679 * @param[in] tunnel
13683 * Valid hash RX queue index, otherwise 0.
13686 __flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
13687 const uint64_t hash_fields)
13689 struct mlx5_priv *priv = dev->data->dev_private;
13690 struct mlx5_shared_action_rss *shared_rss =
13691 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
13692 const uint32_t *hrxqs = shared_rss->hrxq;
13694 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13695 case MLX5_RSS_HASH_IPV4:
13696 /* fall-through. */
13697 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13698 /* fall-through. */
13699 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13701 case MLX5_RSS_HASH_IPV4_TCP:
13702 /* fall-through. */
13703 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13704 /* fall-through. */
13705 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13707 case MLX5_RSS_HASH_IPV4_UDP:
13708 /* fall-through. */
13709 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13710 /* fall-through. */
13711 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13713 case MLX5_RSS_HASH_IPV6:
13714 /* fall-through. */
13715 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13716 /* fall-through. */
13717 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13719 case MLX5_RSS_HASH_IPV6_TCP:
13720 /* fall-through. */
13721 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13722 /* fall-through. */
13723 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13725 case MLX5_RSS_HASH_IPV6_UDP:
13726 /* fall-through. */
13727 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13728 /* fall-through. */
13729 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13731 case MLX5_RSS_HASH_NONE:
13740 * Apply the flow to the NIC, lock free,
13741 * (mutex should be acquired by caller).
13744 * Pointer to the Ethernet device structure.
13745 * @param[in, out] flow
13746 * Pointer to flow structure.
13747 * @param[out] error
13748 * Pointer to error structure.
13751 * 0 on success, a negative errno value otherwise and rte_errno is set.
13754 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
13755 struct rte_flow_error *error)
13757 struct mlx5_flow_dv_workspace *dv;
13758 struct mlx5_flow_handle *dh;
13759 struct mlx5_flow_handle_dv *dv_h;
13760 struct mlx5_flow *dev_flow;
13761 struct mlx5_priv *priv = dev->data->dev_private;
13762 uint32_t handle_idx;
13766 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13767 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
13771 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
13772 dev_flow = &wks->flows[idx];
13773 dv = &dev_flow->dv;
13774 dh = dev_flow->handle;
13777 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
13778 if (dv->transfer) {
13779 MLX5_ASSERT(priv->sh->dr_drop_action);
13780 dv->actions[n++] = priv->sh->dr_drop_action;
13782 #ifdef HAVE_MLX5DV_DR
13783 /* DR supports drop action placeholder. */
13784 MLX5_ASSERT(priv->sh->dr_drop_action);
13785 dv->actions[n++] = dv->group ?
13786 priv->sh->dr_drop_action :
13787 priv->root_drop_action;
13789 /* For DV we use the explicit drop queue. */
13790 MLX5_ASSERT(priv->drop_queue.hrxq);
13792 priv->drop_queue.hrxq->action;
13795 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
13796 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
13797 struct mlx5_hrxq *hrxq;
13800 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
13805 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13806 "cannot get hash queue");
13809 dh->rix_hrxq = hrxq_idx;
13810 dv->actions[n++] = hrxq->action;
13811 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13812 struct mlx5_hrxq *hrxq = NULL;
13815 hrxq_idx = __flow_dv_action_rss_hrxq_lookup(dev,
13816 rss_desc->shared_rss,
13817 dev_flow->hash_fields);
13819 hrxq = mlx5_ipool_get
13820 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
13825 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13826 "cannot get hash queue");
13829 dh->rix_srss = rss_desc->shared_rss;
13830 dv->actions[n++] = hrxq->action;
13831 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
13832 if (!priv->sh->default_miss_action) {
13835 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13836 "default miss action not be created.");
13839 dv->actions[n++] = priv->sh->default_miss_action;
13841 misc_mask = flow_dv_matcher_enable(dv->value.buf);
13842 __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
13843 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
13844 (void *)&dv->value, n,
13845 dv->actions, &dh->drv_flow);
13849 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13851 (!priv->config.allow_duplicate_pattern &&
13853 "duplicating pattern is not allowed" :
13854 "hardware refuses to create flow");
13857 if (priv->vmwa_context &&
13858 dh->vf_vlan.tag && !dh->vf_vlan.created) {
13860 * The rule contains the VLAN pattern.
13861 * For VF we are going to create VLAN
13862 * interface to make hypervisor set correct
13863 * e-Switch vport context.
13865 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
13870 err = rte_errno; /* Save rte_errno before cleanup. */
13871 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
13872 handle_idx, dh, next) {
13873 /* hrxq is union, don't clear it if the flag is not set. */
13874 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
13875 mlx5_hrxq_release(dev, dh->rix_hrxq);
13877 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13880 if (dh->vf_vlan.tag && dh->vf_vlan.created)
13881 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
13883 rte_errno = err; /* Restore rte_errno. */
13888 flow_dv_matcher_remove_cb(void *tool_ctx __rte_unused,
13889 struct mlx5_list_entry *entry)
13891 struct mlx5_flow_dv_matcher *resource = container_of(entry,
13895 claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
13896 mlx5_free(resource);
13900 * Release the flow matcher.
13903 * Pointer to Ethernet device.
13905 * Index to port ID action resource.
13908 * 1 while a reference on it exists, 0 when freed.
13911 flow_dv_matcher_release(struct rte_eth_dev *dev,
13912 struct mlx5_flow_handle *handle)
13914 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
13915 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
13916 typeof(*tbl), tbl);
13919 MLX5_ASSERT(matcher->matcher_object);
13920 ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
13921 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
13926 flow_dv_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
13928 struct mlx5_dev_ctx_shared *sh = tool_ctx;
13929 struct mlx5_flow_dv_encap_decap_resource *res =
13930 container_of(entry, typeof(*res), entry);
13932 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13933 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
13937 * Release an encap/decap resource.
13940 * Pointer to Ethernet device.
13941 * @param encap_decap_idx
13942 * Index of encap decap resource.
13945 * 1 while a reference on it exists, 0 when freed.
13948 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
13949 uint32_t encap_decap_idx)
13951 struct mlx5_priv *priv = dev->data->dev_private;
13952 struct mlx5_flow_dv_encap_decap_resource *resource;
13954 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
13958 MLX5_ASSERT(resource->action);
13959 return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
13963 * Release an jump to table action resource.
13966 * Pointer to Ethernet device.
13968 * Index to the jump action resource.
13971 * 1 while a reference on it exists, 0 when freed.
13974 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
13977 struct mlx5_priv *priv = dev->data->dev_private;
13978 struct mlx5_flow_tbl_data_entry *tbl_data;
13980 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
13984 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
13988 flow_dv_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
13990 struct mlx5_flow_dv_modify_hdr_resource *res =
13991 container_of(entry, typeof(*res), entry);
13992 struct mlx5_dev_ctx_shared *sh = tool_ctx;
13994 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13995 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
13999 * Release a modify-header resource.
14002 * Pointer to Ethernet device.
14004 * Pointer to mlx5_flow_handle.
14007 * 1 while a reference on it exists, 0 when freed.
14010 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
14011 struct mlx5_flow_handle *handle)
14013 struct mlx5_priv *priv = dev->data->dev_private;
14014 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
14016 MLX5_ASSERT(entry->action);
14017 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
14021 flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14023 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14024 struct mlx5_flow_dv_port_id_action_resource *resource =
14025 container_of(entry, typeof(*resource), entry);
14027 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14028 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
14032 * Release port ID action resource.
14035 * Pointer to Ethernet device.
14037 * Pointer to mlx5_flow_handle.
14040 * 1 while a reference on it exists, 0 when freed.
14043 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
14046 struct mlx5_priv *priv = dev->data->dev_private;
14047 struct mlx5_flow_dv_port_id_action_resource *resource;
14049 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
14052 MLX5_ASSERT(resource->action);
14053 return mlx5_list_unregister(priv->sh->port_id_action_list,
14058 * Release shared RSS action resource.
14061 * Pointer to Ethernet device.
14063 * Shared RSS action index.
14066 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
14068 struct mlx5_priv *priv = dev->data->dev_private;
14069 struct mlx5_shared_action_rss *shared_rss;
14071 shared_rss = mlx5_ipool_get
14072 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
14073 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14077 flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14079 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14080 struct mlx5_flow_dv_push_vlan_action_resource *resource =
14081 container_of(entry, typeof(*resource), entry);
14083 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14084 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
14088 * Release push vlan action resource.
14091 * Pointer to Ethernet device.
14093 * Pointer to mlx5_flow_handle.
14096 * 1 while a reference on it exists, 0 when freed.
14099 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
14100 struct mlx5_flow_handle *handle)
14102 struct mlx5_priv *priv = dev->data->dev_private;
14103 struct mlx5_flow_dv_push_vlan_action_resource *resource;
14104 uint32_t idx = handle->dvh.rix_push_vlan;
14106 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
14109 MLX5_ASSERT(resource->action);
14110 return mlx5_list_unregister(priv->sh->push_vlan_action_list,
14115 * Release the fate resource.
14118 * Pointer to Ethernet device.
14120 * Pointer to mlx5_flow_handle.
14123 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
14124 struct mlx5_flow_handle *handle)
14126 if (!handle->rix_fate)
14128 switch (handle->fate_action) {
14129 case MLX5_FLOW_FATE_QUEUE:
14130 if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
14131 mlx5_hrxq_release(dev, handle->rix_hrxq);
14133 case MLX5_FLOW_FATE_JUMP:
14134 flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
14136 case MLX5_FLOW_FATE_PORT_ID:
14137 flow_dv_port_id_action_resource_release(dev,
14138 handle->rix_port_id_action);
14141 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
14144 handle->rix_fate = 0;
14148 flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
14149 struct mlx5_list_entry *entry)
14151 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
14154 struct rte_eth_dev *dev = resource->dev;
14155 struct mlx5_priv *priv = dev->data->dev_private;
14157 if (resource->verbs_action)
14158 claim_zero(mlx5_flow_os_destroy_flow_action
14159 (resource->verbs_action));
14160 if (resource->normal_path_tbl)
14161 flow_dv_tbl_resource_release(MLX5_SH(dev),
14162 resource->normal_path_tbl);
14163 flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
14164 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
14165 DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
14169 * Release an sample resource.
14172 * Pointer to Ethernet device.
14174 * Pointer to mlx5_flow_handle.
14177 * 1 while a reference on it exists, 0 when freed.
14180 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
14181 struct mlx5_flow_handle *handle)
14183 struct mlx5_priv *priv = dev->data->dev_private;
14184 struct mlx5_flow_dv_sample_resource *resource;
14186 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
14187 handle->dvh.rix_sample);
14190 MLX5_ASSERT(resource->verbs_action);
14191 return mlx5_list_unregister(priv->sh->sample_action_list,
14196 flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
14197 struct mlx5_list_entry *entry)
14199 struct mlx5_flow_dv_dest_array_resource *resource =
14200 container_of(entry, typeof(*resource), entry);
14201 struct rte_eth_dev *dev = resource->dev;
14202 struct mlx5_priv *priv = dev->data->dev_private;
14205 MLX5_ASSERT(resource->action);
14206 if (resource->action)
14207 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14208 for (; i < resource->num_of_dest; i++)
14209 flow_dv_sample_sub_actions_release(dev,
14210 &resource->sample_idx[i]);
14211 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
14212 DRV_LOG(DEBUG, "destination array resource %p: removed",
14217 * Release an destination array resource.
14220 * Pointer to Ethernet device.
14222 * Pointer to mlx5_flow_handle.
14225 * 1 while a reference on it exists, 0 when freed.
14228 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
14229 struct mlx5_flow_handle *handle)
14231 struct mlx5_priv *priv = dev->data->dev_private;
14232 struct mlx5_flow_dv_dest_array_resource *resource;
14234 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
14235 handle->dvh.rix_dest_array);
14238 MLX5_ASSERT(resource->action);
14239 return mlx5_list_unregister(priv->sh->dest_array_list,
14244 flow_dv_geneve_tlv_option_resource_release(struct rte_eth_dev *dev)
14246 struct mlx5_priv *priv = dev->data->dev_private;
14247 struct mlx5_dev_ctx_shared *sh = priv->sh;
14248 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
14249 sh->geneve_tlv_option_resource;
14250 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
14251 if (geneve_opt_resource) {
14252 if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
14253 __ATOMIC_RELAXED))) {
14254 claim_zero(mlx5_devx_cmd_destroy
14255 (geneve_opt_resource->obj));
14256 mlx5_free(sh->geneve_tlv_option_resource);
14257 sh->geneve_tlv_option_resource = NULL;
14260 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
14264 * Remove the flow from the NIC but keeps it in memory.
14265 * Lock free, (mutex should be acquired by caller).
14268 * Pointer to Ethernet device.
14269 * @param[in, out] flow
14270 * Pointer to flow structure.
14273 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
14275 struct mlx5_flow_handle *dh;
14276 uint32_t handle_idx;
14277 struct mlx5_priv *priv = dev->data->dev_private;
14281 handle_idx = flow->dev_handles;
14282 while (handle_idx) {
14283 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14287 if (dh->drv_flow) {
14288 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
14289 dh->drv_flow = NULL;
14291 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
14292 flow_dv_fate_resource_release(dev, dh);
14293 if (dh->vf_vlan.tag && dh->vf_vlan.created)
14294 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
14295 handle_idx = dh->next.next;
14300 * Remove the flow from the NIC and the memory.
14301 * Lock free, (mutex should be acquired by caller).
14304 * Pointer to the Ethernet device structure.
14305 * @param[in, out] flow
14306 * Pointer to flow structure.
14309 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
14311 struct mlx5_flow_handle *dev_handle;
14312 struct mlx5_priv *priv = dev->data->dev_private;
14313 struct mlx5_flow_meter_info *fm = NULL;
14318 flow_dv_remove(dev, flow);
14319 if (flow->counter) {
14320 flow_dv_counter_free(dev, flow->counter);
14324 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
14326 mlx5_flow_meter_detach(priv, fm);
14329 /* Keep the current age handling by default. */
14330 if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
14331 flow_dv_aso_ct_release(dev, flow->ct, NULL);
14332 else if (flow->age)
14333 flow_dv_aso_age_release(dev, flow->age);
14334 if (flow->geneve_tlv_option) {
14335 flow_dv_geneve_tlv_option_resource_release(dev);
14336 flow->geneve_tlv_option = 0;
14338 while (flow->dev_handles) {
14339 uint32_t tmp_idx = flow->dev_handles;
14341 dev_handle = mlx5_ipool_get(priv->sh->ipool
14342 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
14345 flow->dev_handles = dev_handle->next.next;
14346 if (dev_handle->dvh.matcher)
14347 flow_dv_matcher_release(dev, dev_handle);
14348 if (dev_handle->dvh.rix_sample)
14349 flow_dv_sample_resource_release(dev, dev_handle);
14350 if (dev_handle->dvh.rix_dest_array)
14351 flow_dv_dest_array_resource_release(dev, dev_handle);
14352 if (dev_handle->dvh.rix_encap_decap)
14353 flow_dv_encap_decap_resource_release(dev,
14354 dev_handle->dvh.rix_encap_decap);
14355 if (dev_handle->dvh.modify_hdr)
14356 flow_dv_modify_hdr_resource_release(dev, dev_handle);
14357 if (dev_handle->dvh.rix_push_vlan)
14358 flow_dv_push_vlan_action_resource_release(dev,
14360 if (dev_handle->dvh.rix_tag)
14361 flow_dv_tag_release(dev,
14362 dev_handle->dvh.rix_tag);
14363 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
14364 flow_dv_fate_resource_release(dev, dev_handle);
14366 srss = dev_handle->rix_srss;
14367 if (fm && dev_handle->is_meter_flow_id &&
14368 dev_handle->split_flow_id)
14369 mlx5_ipool_free(fm->flow_ipool,
14370 dev_handle->split_flow_id);
14371 else if (dev_handle->split_flow_id &&
14372 !dev_handle->is_meter_flow_id)
14373 mlx5_ipool_free(priv->sh->ipool
14374 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
14375 dev_handle->split_flow_id);
14376 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14380 flow_dv_shared_rss_action_release(dev, srss);
14384 * Release array of hash RX queue objects.
14388 * Pointer to the Ethernet device structure.
14389 * @param[in, out] hrxqs
14390 * Array of hash RX queue objects.
14393 * Total number of references to hash RX queue objects in *hrxqs* array
14394 * after this operation.
14397 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
14398 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
14403 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
14404 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
14414 * Release all hash RX queue objects representing shared RSS action.
14417 * Pointer to the Ethernet device structure.
14418 * @param[in, out] action
14419 * Shared RSS action to remove hash RX queue objects from.
14422 * Total number of references to hash RX queue objects stored in *action*
14423 * after this operation.
14424 * Expected to be 0 if no external references held.
14427 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
14428 struct mlx5_shared_action_rss *shared_rss)
14430 return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
14434 * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
14437 * Only one hash value is available for one L3+L4 combination:
14439 * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
14440 * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
14441 * same slot in mlx5_rss_hash_fields.
14444 * Pointer to the shared action RSS conf.
14445 * @param[in, out] hash_field
14446 * hash_field variable needed to be adjusted.
14452 __flow_dv_action_rss_l34_hash_adjust(struct mlx5_shared_action_rss *rss,
14453 uint64_t *hash_field)
14455 uint64_t rss_types = rss->origin.types;
14457 switch (*hash_field & ~IBV_RX_HASH_INNER) {
14458 case MLX5_RSS_HASH_IPV4:
14459 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
14460 *hash_field &= ~MLX5_RSS_HASH_IPV4;
14461 if (rss_types & ETH_RSS_L3_DST_ONLY)
14462 *hash_field |= IBV_RX_HASH_DST_IPV4;
14463 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
14464 *hash_field |= IBV_RX_HASH_SRC_IPV4;
14466 *hash_field |= MLX5_RSS_HASH_IPV4;
14469 case MLX5_RSS_HASH_IPV6:
14470 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
14471 *hash_field &= ~MLX5_RSS_HASH_IPV6;
14472 if (rss_types & ETH_RSS_L3_DST_ONLY)
14473 *hash_field |= IBV_RX_HASH_DST_IPV6;
14474 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
14475 *hash_field |= IBV_RX_HASH_SRC_IPV6;
14477 *hash_field |= MLX5_RSS_HASH_IPV6;
14480 case MLX5_RSS_HASH_IPV4_UDP:
14481 /* fall-through. */
14482 case MLX5_RSS_HASH_IPV6_UDP:
14483 if (rss_types & ETH_RSS_UDP) {
14484 *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
14485 if (rss_types & ETH_RSS_L4_DST_ONLY)
14486 *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
14487 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
14488 *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
14490 *hash_field |= MLX5_UDP_IBV_RX_HASH;
14493 case MLX5_RSS_HASH_IPV4_TCP:
14494 /* fall-through. */
14495 case MLX5_RSS_HASH_IPV6_TCP:
14496 if (rss_types & ETH_RSS_TCP) {
14497 *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
14498 if (rss_types & ETH_RSS_L4_DST_ONLY)
14499 *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
14500 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
14501 *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
14503 *hash_field |= MLX5_TCP_IBV_RX_HASH;
14512 * Setup shared RSS action.
14513 * Prepare set of hash RX queue objects sufficient to handle all valid
14514 * hash_fields combinations (see enum ibv_rx_hash_fields).
14517 * Pointer to the Ethernet device structure.
14518 * @param[in] action_idx
14519 * Shared RSS action ipool index.
14520 * @param[in, out] action
14521 * Partially initialized shared RSS action.
14522 * @param[out] error
14523 * Perform verbose error reporting if not NULL. Initialized in case of
14527 * 0 on success, otherwise negative errno value.
14530 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
14531 uint32_t action_idx,
14532 struct mlx5_shared_action_rss *shared_rss,
14533 struct rte_flow_error *error)
14535 struct mlx5_flow_rss_desc rss_desc = { 0 };
14539 if (mlx5_ind_table_obj_setup(dev, shared_rss->ind_tbl)) {
14540 return rte_flow_error_set(error, rte_errno,
14541 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14542 "cannot setup indirection table");
14544 memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
14545 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
14546 rss_desc.const_q = shared_rss->origin.queue;
14547 rss_desc.queue_num = shared_rss->origin.queue_num;
14548 /* Set non-zero value to indicate a shared RSS. */
14549 rss_desc.shared_rss = action_idx;
14550 rss_desc.ind_tbl = shared_rss->ind_tbl;
14551 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
14553 uint64_t hash_fields = mlx5_rss_hash_fields[i];
14556 __flow_dv_action_rss_l34_hash_adjust(shared_rss, &hash_fields);
14557 if (shared_rss->origin.level > 1) {
14558 hash_fields |= IBV_RX_HASH_INNER;
14561 rss_desc.tunnel = tunnel;
14562 rss_desc.hash_fields = hash_fields;
14563 hrxq_idx = mlx5_hrxq_get(dev, &rss_desc);
14567 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14568 "cannot get hash queue");
14569 goto error_hrxq_new;
14571 err = __flow_dv_action_rss_hrxq_set
14572 (shared_rss, hash_fields, hrxq_idx);
14578 __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14579 if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
14580 shared_rss->ind_tbl = NULL;
14586 * Create shared RSS action.
14589 * Pointer to the Ethernet device structure.
14591 * Shared action configuration.
14593 * RSS action specification used to create shared action.
14594 * @param[out] error
14595 * Perform verbose error reporting if not NULL. Initialized in case of
14599 * A valid shared action ID in case of success, 0 otherwise and
14600 * rte_errno is set.
14603 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
14604 const struct rte_flow_indir_action_conf *conf,
14605 const struct rte_flow_action_rss *rss,
14606 struct rte_flow_error *error)
14608 struct mlx5_priv *priv = dev->data->dev_private;
14609 struct mlx5_shared_action_rss *shared_rss = NULL;
14610 void *queue = NULL;
14611 struct rte_flow_action_rss *origin;
14612 const uint8_t *rss_key;
14613 uint32_t queue_size = rss->queue_num * sizeof(uint16_t);
14616 RTE_SET_USED(conf);
14617 queue = mlx5_malloc(0, RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14619 shared_rss = mlx5_ipool_zmalloc
14620 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
14621 if (!shared_rss || !queue) {
14622 rte_flow_error_set(error, ENOMEM,
14623 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14624 "cannot allocate resource memory");
14625 goto error_rss_init;
14627 if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
14628 rte_flow_error_set(error, E2BIG,
14629 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14630 "rss action number out of range");
14631 goto error_rss_init;
14633 shared_rss->ind_tbl = mlx5_malloc(MLX5_MEM_ZERO,
14634 sizeof(*shared_rss->ind_tbl),
14636 if (!shared_rss->ind_tbl) {
14637 rte_flow_error_set(error, ENOMEM,
14638 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14639 "cannot allocate resource memory");
14640 goto error_rss_init;
14642 memcpy(queue, rss->queue, queue_size);
14643 shared_rss->ind_tbl->queues = queue;
14644 shared_rss->ind_tbl->queues_n = rss->queue_num;
14645 origin = &shared_rss->origin;
14646 origin->func = rss->func;
14647 origin->level = rss->level;
14648 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
14649 origin->types = !rss->types ? ETH_RSS_IP : rss->types;
14650 /* NULL RSS key indicates default RSS key. */
14651 rss_key = !rss->key ? rss_hash_default_key : rss->key;
14652 memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
14653 origin->key = &shared_rss->key[0];
14654 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
14655 origin->queue = queue;
14656 origin->queue_num = rss->queue_num;
14657 if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
14658 goto error_rss_init;
14659 rte_spinlock_init(&shared_rss->action_rss_sl);
14660 __atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14661 rte_spinlock_lock(&priv->shared_act_sl);
14662 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14663 &priv->rss_shared_actions, idx, shared_rss, next);
14664 rte_spinlock_unlock(&priv->shared_act_sl);
14668 if (shared_rss->ind_tbl)
14669 mlx5_free(shared_rss->ind_tbl);
14670 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14679 * Destroy the shared RSS action.
14680 * Release related hash RX queue objects.
14683 * Pointer to the Ethernet device structure.
14685 * The shared RSS action object ID to be removed.
14686 * @param[out] error
14687 * Perform verbose error reporting if not NULL. Initialized in case of
14691 * 0 on success, otherwise negative errno value.
14694 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
14695 struct rte_flow_error *error)
14697 struct mlx5_priv *priv = dev->data->dev_private;
14698 struct mlx5_shared_action_rss *shared_rss =
14699 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14700 uint32_t old_refcnt = 1;
14702 uint16_t *queue = NULL;
14705 return rte_flow_error_set(error, EINVAL,
14706 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14707 "invalid shared action");
14708 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
14709 0, 0, __ATOMIC_ACQUIRE,
14711 return rte_flow_error_set(error, EBUSY,
14712 RTE_FLOW_ERROR_TYPE_ACTION,
14714 "shared rss has references");
14715 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14717 return rte_flow_error_set(error, EBUSY,
14718 RTE_FLOW_ERROR_TYPE_ACTION,
14720 "shared rss hrxq has references");
14721 queue = shared_rss->ind_tbl->queues;
14722 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true);
14724 return rte_flow_error_set(error, EBUSY,
14725 RTE_FLOW_ERROR_TYPE_ACTION,
14727 "shared rss indirection table has"
14730 rte_spinlock_lock(&priv->shared_act_sl);
14731 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14732 &priv->rss_shared_actions, idx, shared_rss, next);
14733 rte_spinlock_unlock(&priv->shared_act_sl);
14734 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14740 * Create indirect action, lock free,
14741 * (mutex should be acquired by caller).
14742 * Dispatcher for action type specific call.
14745 * Pointer to the Ethernet device structure.
14747 * Shared action configuration.
14748 * @param[in] action
14749 * Action specification used to create indirect action.
14750 * @param[out] error
14751 * Perform verbose error reporting if not NULL. Initialized in case of
14755 * A valid shared action handle in case of success, NULL otherwise and
14756 * rte_errno is set.
14758 static struct rte_flow_action_handle *
14759 flow_dv_action_create(struct rte_eth_dev *dev,
14760 const struct rte_flow_indir_action_conf *conf,
14761 const struct rte_flow_action *action,
14762 struct rte_flow_error *err)
14764 struct mlx5_priv *priv = dev->data->dev_private;
14765 uint32_t age_idx = 0;
14769 switch (action->type) {
14770 case RTE_FLOW_ACTION_TYPE_RSS:
14771 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
14772 idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
14773 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14775 case RTE_FLOW_ACTION_TYPE_AGE:
14776 age_idx = flow_dv_aso_age_alloc(dev, err);
14781 idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
14782 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
14783 flow_dv_aso_age_params_init(dev, age_idx,
14784 ((const struct rte_flow_action_age *)
14785 action->conf)->context ?
14786 ((const struct rte_flow_action_age *)
14787 action->conf)->context :
14788 (void *)(uintptr_t)idx,
14789 ((const struct rte_flow_action_age *)
14790 action->conf)->timeout);
14793 case RTE_FLOW_ACTION_TYPE_COUNT:
14794 ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
14795 idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
14796 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14798 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
14799 ret = flow_dv_translate_create_conntrack(dev, action->conf,
14801 idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
14804 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
14805 NULL, "action type not supported");
14808 return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
14812 * Destroy the indirect action.
14813 * Release action related resources on the NIC and the memory.
14814 * Lock free, (mutex should be acquired by caller).
14815 * Dispatcher for action type specific call.
14818 * Pointer to the Ethernet device structure.
14819 * @param[in] handle
14820 * The indirect action object handle to be removed.
14821 * @param[out] error
14822 * Perform verbose error reporting if not NULL. Initialized in case of
14826 * 0 on success, otherwise negative errno value.
14829 flow_dv_action_destroy(struct rte_eth_dev *dev,
14830 struct rte_flow_action_handle *handle,
14831 struct rte_flow_error *error)
14833 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14834 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14835 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
14836 struct mlx5_flow_counter *cnt;
14837 uint32_t no_flow_refcnt = 1;
14841 case MLX5_INDIRECT_ACTION_TYPE_RSS:
14842 return __flow_dv_action_rss_release(dev, idx, error);
14843 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
14844 cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
14845 if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
14846 &no_flow_refcnt, 1, false,
14849 return rte_flow_error_set(error, EBUSY,
14850 RTE_FLOW_ERROR_TYPE_ACTION,
14852 "Indirect count action has references");
14853 flow_dv_counter_free(dev, idx);
14855 case MLX5_INDIRECT_ACTION_TYPE_AGE:
14856 ret = flow_dv_aso_age_release(dev, idx);
14859 * In this case, the last flow has a reference will
14860 * actually release the age action.
14862 DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
14863 " released with references %d.", idx, ret);
14865 case MLX5_INDIRECT_ACTION_TYPE_CT:
14866 ret = flow_dv_aso_ct_release(dev, idx, error);
14870 DRV_LOG(DEBUG, "Connection tracking object %u still "
14871 "has references %d.", idx, ret);
14874 return rte_flow_error_set(error, ENOTSUP,
14875 RTE_FLOW_ERROR_TYPE_ACTION,
14877 "action type not supported");
14882 * Updates in place shared RSS action configuration.
14885 * Pointer to the Ethernet device structure.
14887 * The shared RSS action object ID to be updated.
14888 * @param[in] action_conf
14889 * RSS action specification used to modify *shared_rss*.
14890 * @param[out] error
14891 * Perform verbose error reporting if not NULL. Initialized in case of
14895 * 0 on success, otherwise negative errno value.
14896 * @note: currently only support update of RSS queues.
14899 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
14900 const struct rte_flow_action_rss *action_conf,
14901 struct rte_flow_error *error)
14903 struct mlx5_priv *priv = dev->data->dev_private;
14904 struct mlx5_shared_action_rss *shared_rss =
14905 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14907 void *queue = NULL;
14908 uint16_t *queue_old = NULL;
14909 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
14912 return rte_flow_error_set(error, EINVAL,
14913 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14914 "invalid shared action to update");
14915 if (priv->obj_ops.ind_table_modify == NULL)
14916 return rte_flow_error_set(error, ENOTSUP,
14917 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14918 "cannot modify indirection table");
14919 queue = mlx5_malloc(MLX5_MEM_ZERO,
14920 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14923 return rte_flow_error_set(error, ENOMEM,
14924 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14926 "cannot allocate resource memory");
14927 memcpy(queue, action_conf->queue, queue_size);
14928 MLX5_ASSERT(shared_rss->ind_tbl);
14929 rte_spinlock_lock(&shared_rss->action_rss_sl);
14930 queue_old = shared_rss->ind_tbl->queues;
14931 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
14932 queue, action_conf->queue_num, true);
14935 ret = rte_flow_error_set(error, rte_errno,
14936 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14937 "cannot update indirection table");
14939 mlx5_free(queue_old);
14940 shared_rss->origin.queue = queue;
14941 shared_rss->origin.queue_num = action_conf->queue_num;
14943 rte_spinlock_unlock(&shared_rss->action_rss_sl);
14948 * Updates in place conntrack context or direction.
14949 * Context update should be synchronized.
14952 * Pointer to the Ethernet device structure.
14954 * The conntrack object ID to be updated.
14955 * @param[in] update
14956 * Pointer to the structure of information to update.
14957 * @param[out] error
14958 * Perform verbose error reporting if not NULL. Initialized in case of
14962 * 0 on success, otherwise negative errno value.
14965 __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
14966 const struct rte_flow_modify_conntrack *update,
14967 struct rte_flow_error *error)
14969 struct mlx5_priv *priv = dev->data->dev_private;
14970 struct mlx5_aso_ct_action *ct;
14971 const struct rte_flow_action_conntrack *new_prf;
14973 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
14976 if (PORT_ID(priv) != owner)
14977 return rte_flow_error_set(error, EACCES,
14978 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14980 "CT object owned by another port");
14981 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
14982 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
14984 return rte_flow_error_set(error, ENOMEM,
14985 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14987 "CT object is inactive");
14988 new_prf = &update->new_ct;
14989 if (update->direction)
14990 ct->is_original = !!new_prf->is_original_dir;
14991 if (update->state) {
14992 /* Only validate the profile when it needs to be updated. */
14993 ret = mlx5_validate_action_ct(dev, new_prf, error);
14996 ret = mlx5_aso_ct_update_by_wqe(priv->sh, ct, new_prf);
14998 return rte_flow_error_set(error, EIO,
14999 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15001 "Failed to send CT context update WQE");
15002 /* Block until ready or a failure. */
15003 ret = mlx5_aso_ct_available(priv->sh, ct);
15005 rte_flow_error_set(error, rte_errno,
15006 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15008 "Timeout to get the CT update");
15014 * Updates in place shared action configuration, lock free,
15015 * (mutex should be acquired by caller).
15018 * Pointer to the Ethernet device structure.
15019 * @param[in] handle
15020 * The indirect action object handle to be updated.
15021 * @param[in] update
15022 * Action specification used to modify the action pointed by *handle*.
15023 * *update* could be of same type with the action pointed by the *handle*
15024 * handle argument, or some other structures like a wrapper, depending on
15025 * the indirect action type.
15026 * @param[out] error
15027 * Perform verbose error reporting if not NULL. Initialized in case of
15031 * 0 on success, otherwise negative errno value.
15034 flow_dv_action_update(struct rte_eth_dev *dev,
15035 struct rte_flow_action_handle *handle,
15036 const void *update,
15037 struct rte_flow_error *err)
15039 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15040 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15041 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15042 const void *action_conf;
15045 case MLX5_INDIRECT_ACTION_TYPE_RSS:
15046 action_conf = ((const struct rte_flow_action *)update)->conf;
15047 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
15048 case MLX5_INDIRECT_ACTION_TYPE_CT:
15049 return __flow_dv_action_ct_update(dev, idx, update, err);
15051 return rte_flow_error_set(err, ENOTSUP,
15052 RTE_FLOW_ERROR_TYPE_ACTION,
15054 "action type update not supported");
15059 * Destroy the meter sub policy table rules.
15060 * Lock free, (mutex should be acquired by caller).
15063 * Pointer to Ethernet device.
15064 * @param[in] sub_policy
15065 * Pointer to meter sub policy table.
15068 __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
15069 struct mlx5_flow_meter_sub_policy *sub_policy)
15071 struct mlx5_priv *priv = dev->data->dev_private;
15072 struct mlx5_flow_tbl_data_entry *tbl;
15073 struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
15074 struct mlx5_flow_meter_info *next_fm;
15075 struct mlx5_sub_policy_color_rule *color_rule;
15079 for (i = 0; i < RTE_COLORS; i++) {
15081 if (i == RTE_COLOR_GREEN && policy &&
15082 policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
15083 next_fm = mlx5_flow_meter_find(priv,
15084 policy->act_cnt[i].next_mtr_id, NULL);
15085 RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
15087 claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
15088 tbl = container_of(color_rule->matcher->tbl,
15089 typeof(*tbl), tbl);
15090 mlx5_list_unregister(tbl->matchers,
15091 &color_rule->matcher->entry);
15092 TAILQ_REMOVE(&sub_policy->color_rules[i],
15093 color_rule, next_port);
15094 mlx5_free(color_rule);
15096 mlx5_flow_meter_detach(priv, next_fm);
15099 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15100 if (sub_policy->rix_hrxq[i]) {
15101 if (policy && !policy->is_hierarchy)
15102 mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
15103 sub_policy->rix_hrxq[i] = 0;
15105 if (sub_policy->jump_tbl[i]) {
15106 flow_dv_tbl_resource_release(MLX5_SH(dev),
15107 sub_policy->jump_tbl[i]);
15108 sub_policy->jump_tbl[i] = NULL;
15111 if (sub_policy->tbl_rsc) {
15112 flow_dv_tbl_resource_release(MLX5_SH(dev),
15113 sub_policy->tbl_rsc);
15114 sub_policy->tbl_rsc = NULL;
15119 * Destroy policy rules, lock free,
15120 * (mutex should be acquired by caller).
15121 * Dispatcher for action type specific call.
15124 * Pointer to the Ethernet device structure.
15125 * @param[in] mtr_policy
15126 * Meter policy struct.
15129 flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
15130 struct mlx5_flow_meter_policy *mtr_policy)
15133 struct mlx5_flow_meter_sub_policy *sub_policy;
15134 uint16_t sub_policy_num;
15136 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15137 sub_policy_num = (mtr_policy->sub_policy_num >>
15138 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15139 MLX5_MTR_SUB_POLICY_NUM_MASK;
15140 for (j = 0; j < sub_policy_num; j++) {
15141 sub_policy = mtr_policy->sub_policys[i][j];
15143 __flow_dv_destroy_sub_policy_rules(dev,
15150 * Destroy policy action, lock free,
15151 * (mutex should be acquired by caller).
15152 * Dispatcher for action type specific call.
15155 * Pointer to the Ethernet device structure.
15156 * @param[in] mtr_policy
15157 * Meter policy struct.
15160 flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
15161 struct mlx5_flow_meter_policy *mtr_policy)
15163 struct rte_flow_action *rss_action;
15164 struct mlx5_flow_handle dev_handle;
15167 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15168 if (mtr_policy->act_cnt[i].rix_mark) {
15169 flow_dv_tag_release(dev,
15170 mtr_policy->act_cnt[i].rix_mark);
15171 mtr_policy->act_cnt[i].rix_mark = 0;
15173 if (mtr_policy->act_cnt[i].modify_hdr) {
15174 dev_handle.dvh.modify_hdr =
15175 mtr_policy->act_cnt[i].modify_hdr;
15176 flow_dv_modify_hdr_resource_release(dev, &dev_handle);
15178 switch (mtr_policy->act_cnt[i].fate_action) {
15179 case MLX5_FLOW_FATE_SHARED_RSS:
15180 rss_action = mtr_policy->act_cnt[i].rss;
15181 mlx5_free(rss_action);
15183 case MLX5_FLOW_FATE_PORT_ID:
15184 if (mtr_policy->act_cnt[i].rix_port_id_action) {
15185 flow_dv_port_id_action_resource_release(dev,
15186 mtr_policy->act_cnt[i].rix_port_id_action);
15187 mtr_policy->act_cnt[i].rix_port_id_action = 0;
15190 case MLX5_FLOW_FATE_DROP:
15191 case MLX5_FLOW_FATE_JUMP:
15192 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15193 mtr_policy->act_cnt[i].dr_jump_action[j] =
15197 /*Queue action do nothing*/
15201 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15202 mtr_policy->dr_drop_action[j] = NULL;
15206 * Create policy action per domain, lock free,
15207 * (mutex should be acquired by caller).
15208 * Dispatcher for action type specific call.
15211 * Pointer to the Ethernet device structure.
15212 * @param[in] mtr_policy
15213 * Meter policy struct.
15214 * @param[in] action
15215 * Action specification used to create meter actions.
15216 * @param[out] error
15217 * Perform verbose error reporting if not NULL. Initialized in case of
15221 * 0 on success, otherwise negative errno value.
15224 __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
15225 struct mlx5_flow_meter_policy *mtr_policy,
15226 const struct rte_flow_action *actions[RTE_COLORS],
15227 enum mlx5_meter_domain domain,
15228 struct rte_mtr_error *error)
15230 struct mlx5_priv *priv = dev->data->dev_private;
15231 struct rte_flow_error flow_err;
15232 const struct rte_flow_action *act;
15233 uint64_t action_flags;
15234 struct mlx5_flow_handle dh;
15235 struct mlx5_flow dev_flow;
15236 struct mlx5_flow_dv_port_id_action_resource port_id_action;
15238 uint8_t egress, transfer;
15239 struct mlx5_meter_policy_action_container *act_cnt = NULL;
15241 struct mlx5_flow_dv_modify_hdr_resource res;
15242 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
15243 sizeof(struct mlx5_modification_cmd) *
15244 (MLX5_MAX_MODIFY_NUM + 1)];
15246 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
15248 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15249 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15250 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
15251 memset(&dev_flow, 0, sizeof(struct mlx5_flow));
15252 memset(&port_id_action, 0,
15253 sizeof(struct mlx5_flow_dv_port_id_action_resource));
15254 memset(mhdr_res, 0, sizeof(*mhdr_res));
15255 mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
15256 (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15257 MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
15258 dev_flow.handle = &dh;
15259 dev_flow.dv.port_id_action = &port_id_action;
15260 dev_flow.external = true;
15261 for (i = 0; i < RTE_COLORS; i++) {
15262 if (i < MLX5_MTR_RTE_COLORS)
15263 act_cnt = &mtr_policy->act_cnt[i];
15264 /* Skip the color policy actions creation. */
15265 if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
15266 (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
15269 for (act = actions[i];
15270 act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
15271 switch (act->type) {
15272 case RTE_FLOW_ACTION_TYPE_MARK:
15274 uint32_t tag_be = mlx5_flow_mark_set
15275 (((const struct rte_flow_action_mark *)
15278 if (i >= MLX5_MTR_RTE_COLORS)
15279 return -rte_mtr_error_set(error,
15281 RTE_MTR_ERROR_TYPE_METER_POLICY,
15283 "cannot create policy "
15284 "mark action for this color");
15285 dev_flow.handle->mark = 1;
15286 if (flow_dv_tag_resource_register(dev, tag_be,
15287 &dev_flow, &flow_err))
15288 return -rte_mtr_error_set(error,
15290 RTE_MTR_ERROR_TYPE_METER_POLICY,
15292 "cannot setup policy mark action");
15293 MLX5_ASSERT(dev_flow.dv.tag_resource);
15294 act_cnt->rix_mark =
15295 dev_flow.handle->dvh.rix_tag;
15296 action_flags |= MLX5_FLOW_ACTION_MARK;
15299 case RTE_FLOW_ACTION_TYPE_SET_TAG:
15300 if (i >= MLX5_MTR_RTE_COLORS)
15301 return -rte_mtr_error_set(error,
15303 RTE_MTR_ERROR_TYPE_METER_POLICY,
15305 "cannot create policy "
15306 "set tag action for this color");
15307 if (flow_dv_convert_action_set_tag
15309 (const struct rte_flow_action_set_tag *)
15310 act->conf, &flow_err))
15311 return -rte_mtr_error_set(error,
15313 RTE_MTR_ERROR_TYPE_METER_POLICY,
15314 NULL, "cannot convert policy "
15316 if (!mhdr_res->actions_num)
15317 return -rte_mtr_error_set(error,
15319 RTE_MTR_ERROR_TYPE_METER_POLICY,
15320 NULL, "cannot find policy "
15322 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15324 case RTE_FLOW_ACTION_TYPE_DROP:
15326 struct mlx5_flow_mtr_mng *mtrmng =
15328 struct mlx5_flow_tbl_data_entry *tbl_data;
15331 * Create the drop table with
15332 * METER DROP level.
15334 if (!mtrmng->drop_tbl[domain]) {
15335 mtrmng->drop_tbl[domain] =
15336 flow_dv_tbl_resource_get(dev,
15337 MLX5_FLOW_TABLE_LEVEL_METER,
15338 egress, transfer, false, NULL, 0,
15339 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
15340 if (!mtrmng->drop_tbl[domain])
15341 return -rte_mtr_error_set
15343 RTE_MTR_ERROR_TYPE_METER_POLICY,
15345 "Failed to create meter drop table");
15347 tbl_data = container_of
15348 (mtrmng->drop_tbl[domain],
15349 struct mlx5_flow_tbl_data_entry, tbl);
15350 if (i < MLX5_MTR_RTE_COLORS) {
15351 act_cnt->dr_jump_action[domain] =
15352 tbl_data->jump.action;
15353 act_cnt->fate_action =
15354 MLX5_FLOW_FATE_DROP;
15356 if (i == RTE_COLOR_RED)
15357 mtr_policy->dr_drop_action[domain] =
15358 tbl_data->jump.action;
15359 action_flags |= MLX5_FLOW_ACTION_DROP;
15362 case RTE_FLOW_ACTION_TYPE_QUEUE:
15364 if (i >= MLX5_MTR_RTE_COLORS)
15365 return -rte_mtr_error_set(error,
15367 RTE_MTR_ERROR_TYPE_METER_POLICY,
15368 NULL, "cannot create policy "
15369 "fate queue for this color");
15371 ((const struct rte_flow_action_queue *)
15372 (act->conf))->index;
15373 act_cnt->fate_action =
15374 MLX5_FLOW_FATE_QUEUE;
15375 dev_flow.handle->fate_action =
15376 MLX5_FLOW_FATE_QUEUE;
15377 mtr_policy->is_queue = 1;
15378 action_flags |= MLX5_FLOW_ACTION_QUEUE;
15381 case RTE_FLOW_ACTION_TYPE_RSS:
15385 if (i >= MLX5_MTR_RTE_COLORS)
15386 return -rte_mtr_error_set(error,
15388 RTE_MTR_ERROR_TYPE_METER_POLICY,
15390 "cannot create policy "
15391 "rss action for this color");
15393 * Save RSS conf into policy struct
15394 * for translate stage.
15396 rss_size = (int)rte_flow_conv
15397 (RTE_FLOW_CONV_OP_ACTION,
15398 NULL, 0, act, &flow_err);
15400 return -rte_mtr_error_set(error,
15402 RTE_MTR_ERROR_TYPE_METER_POLICY,
15403 NULL, "Get the wrong "
15404 "rss action struct size");
15405 act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
15406 rss_size, 0, SOCKET_ID_ANY);
15408 return -rte_mtr_error_set(error,
15410 RTE_MTR_ERROR_TYPE_METER_POLICY,
15412 "Fail to malloc rss action memory");
15413 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
15414 act_cnt->rss, rss_size,
15417 return -rte_mtr_error_set(error,
15419 RTE_MTR_ERROR_TYPE_METER_POLICY,
15420 NULL, "Fail to save "
15421 "rss action into policy struct");
15422 act_cnt->fate_action =
15423 MLX5_FLOW_FATE_SHARED_RSS;
15424 action_flags |= MLX5_FLOW_ACTION_RSS;
15427 case RTE_FLOW_ACTION_TYPE_PORT_ID:
15428 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15430 struct mlx5_flow_dv_port_id_action_resource
15432 uint32_t port_id = 0;
15434 if (i >= MLX5_MTR_RTE_COLORS)
15435 return -rte_mtr_error_set(error,
15437 RTE_MTR_ERROR_TYPE_METER_POLICY,
15438 NULL, "cannot create policy "
15439 "port action for this color");
15440 memset(&port_id_resource, 0,
15441 sizeof(port_id_resource));
15442 if (flow_dv_translate_action_port_id(dev, act,
15443 &port_id, &flow_err))
15444 return -rte_mtr_error_set(error,
15446 RTE_MTR_ERROR_TYPE_METER_POLICY,
15447 NULL, "cannot translate "
15448 "policy port action");
15449 port_id_resource.port_id = port_id;
15450 if (flow_dv_port_id_action_resource_register
15451 (dev, &port_id_resource,
15452 &dev_flow, &flow_err))
15453 return -rte_mtr_error_set(error,
15455 RTE_MTR_ERROR_TYPE_METER_POLICY,
15456 NULL, "cannot setup "
15457 "policy port action");
15458 act_cnt->rix_port_id_action =
15459 dev_flow.handle->rix_port_id_action;
15460 act_cnt->fate_action =
15461 MLX5_FLOW_FATE_PORT_ID;
15462 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15465 case RTE_FLOW_ACTION_TYPE_JUMP:
15467 uint32_t jump_group = 0;
15468 uint32_t table = 0;
15469 struct mlx5_flow_tbl_data_entry *tbl_data;
15470 struct flow_grp_info grp_info = {
15471 .external = !!dev_flow.external,
15472 .transfer = !!transfer,
15473 .fdb_def_rule = !!priv->fdb_def_rule,
15475 .skip_scale = dev_flow.skip_scale &
15476 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
15478 struct mlx5_flow_meter_sub_policy *sub_policy =
15479 mtr_policy->sub_policys[domain][0];
15481 if (i >= MLX5_MTR_RTE_COLORS)
15482 return -rte_mtr_error_set(error,
15484 RTE_MTR_ERROR_TYPE_METER_POLICY,
15486 "cannot create policy "
15487 "jump action for this color");
15489 ((const struct rte_flow_action_jump *)
15491 if (mlx5_flow_group_to_table(dev, NULL,
15494 &grp_info, &flow_err))
15495 return -rte_mtr_error_set(error,
15497 RTE_MTR_ERROR_TYPE_METER_POLICY,
15498 NULL, "cannot setup "
15499 "policy jump action");
15500 sub_policy->jump_tbl[i] =
15501 flow_dv_tbl_resource_get(dev,
15504 !!dev_flow.external,
15505 NULL, jump_group, 0,
15508 (!sub_policy->jump_tbl[i])
15509 return -rte_mtr_error_set(error,
15511 RTE_MTR_ERROR_TYPE_METER_POLICY,
15512 NULL, "cannot create jump action.");
15513 tbl_data = container_of
15514 (sub_policy->jump_tbl[i],
15515 struct mlx5_flow_tbl_data_entry, tbl);
15516 act_cnt->dr_jump_action[domain] =
15517 tbl_data->jump.action;
15518 act_cnt->fate_action =
15519 MLX5_FLOW_FATE_JUMP;
15520 action_flags |= MLX5_FLOW_ACTION_JUMP;
15524 * No need to check meter hierarchy for Y or R colors
15525 * here since it is done in the validation stage.
15527 case RTE_FLOW_ACTION_TYPE_METER:
15529 const struct rte_flow_action_meter *mtr;
15530 struct mlx5_flow_meter_info *next_fm;
15531 struct mlx5_flow_meter_policy *next_policy;
15532 struct rte_flow_action tag_action;
15533 struct mlx5_rte_flow_action_set_tag set_tag;
15534 uint32_t next_mtr_idx = 0;
15537 next_fm = mlx5_flow_meter_find(priv,
15541 return -rte_mtr_error_set(error, EINVAL,
15542 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15543 "Fail to find next meter.");
15544 if (next_fm->def_policy)
15545 return -rte_mtr_error_set(error, EINVAL,
15546 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15547 "Hierarchy only supports termination meter.");
15548 next_policy = mlx5_flow_meter_policy_find(dev,
15549 next_fm->policy_id, NULL);
15550 MLX5_ASSERT(next_policy);
15551 if (next_fm->drop_cnt) {
15554 mlx5_flow_get_reg_id(dev,
15557 (struct rte_flow_error *)error);
15558 set_tag.offset = (priv->mtr_reg_share ?
15559 MLX5_MTR_COLOR_BITS : 0);
15560 set_tag.length = (priv->mtr_reg_share ?
15561 MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
15563 set_tag.data = next_mtr_idx;
15565 (enum rte_flow_action_type)
15566 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
15567 tag_action.conf = &set_tag;
15568 if (flow_dv_convert_action_set_reg
15569 (mhdr_res, &tag_action,
15570 (struct rte_flow_error *)error))
15573 MLX5_FLOW_ACTION_SET_TAG;
15575 act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
15576 act_cnt->next_mtr_id = next_fm->meter_id;
15577 act_cnt->next_sub_policy = NULL;
15578 mtr_policy->is_hierarchy = 1;
15579 mtr_policy->dev = next_policy->dev;
15581 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
15585 return -rte_mtr_error_set(error, ENOTSUP,
15586 RTE_MTR_ERROR_TYPE_METER_POLICY,
15587 NULL, "action type not supported");
15589 if (action_flags & MLX5_FLOW_ACTION_SET_TAG) {
15590 /* create modify action if needed. */
15591 dev_flow.dv.group = 1;
15592 if (flow_dv_modify_hdr_resource_register
15593 (dev, mhdr_res, &dev_flow, &flow_err))
15594 return -rte_mtr_error_set(error,
15596 RTE_MTR_ERROR_TYPE_METER_POLICY,
15597 NULL, "cannot register policy "
15599 act_cnt->modify_hdr =
15600 dev_flow.handle->dvh.modify_hdr;
15608 * Create policy action per domain, lock free,
15609 * (mutex should be acquired by caller).
15610 * Dispatcher for action type specific call.
15613 * Pointer to the Ethernet device structure.
15614 * @param[in] mtr_policy
15615 * Meter policy struct.
15616 * @param[in] action
15617 * Action specification used to create meter actions.
15618 * @param[out] error
15619 * Perform verbose error reporting if not NULL. Initialized in case of
15623 * 0 on success, otherwise negative errno value.
15626 flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
15627 struct mlx5_flow_meter_policy *mtr_policy,
15628 const struct rte_flow_action *actions[RTE_COLORS],
15629 struct rte_mtr_error *error)
15632 uint16_t sub_policy_num;
15634 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15635 sub_policy_num = (mtr_policy->sub_policy_num >>
15636 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15637 MLX5_MTR_SUB_POLICY_NUM_MASK;
15638 if (sub_policy_num) {
15639 ret = __flow_dv_create_domain_policy_acts(dev,
15640 mtr_policy, actions,
15641 (enum mlx5_meter_domain)i, error);
15642 /* Cleaning resource is done in the caller level. */
15651 * Query a DV flow rule for its statistics via DevX.
15654 * Pointer to Ethernet device.
15655 * @param[in] cnt_idx
15656 * Index to the flow counter.
15658 * Data retrieved by the query.
15659 * @param[out] error
15660 * Perform verbose error reporting if not NULL.
15663 * 0 on success, a negative errno value otherwise and rte_errno is set.
15666 flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
15667 struct rte_flow_error *error)
15669 struct mlx5_priv *priv = dev->data->dev_private;
15670 struct rte_flow_query_count *qc = data;
15672 if (!priv->config.devx)
15673 return rte_flow_error_set(error, ENOTSUP,
15674 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15676 "counters are not supported");
15678 uint64_t pkts, bytes;
15679 struct mlx5_flow_counter *cnt;
15680 int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
15683 return rte_flow_error_set(error, -err,
15684 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15685 NULL, "cannot read counters");
15686 cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
15689 qc->hits = pkts - cnt->hits;
15690 qc->bytes = bytes - cnt->bytes;
15693 cnt->bytes = bytes;
15697 return rte_flow_error_set(error, EINVAL,
15698 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15700 "counters are not available");
15704 flow_dv_action_query(struct rte_eth_dev *dev,
15705 const struct rte_flow_action_handle *handle, void *data,
15706 struct rte_flow_error *error)
15708 struct mlx5_age_param *age_param;
15709 struct rte_flow_query_age *resp;
15710 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15711 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15712 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15713 struct mlx5_priv *priv = dev->data->dev_private;
15714 struct mlx5_aso_ct_action *ct;
15719 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15720 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
15722 resp->aged = __atomic_load_n(&age_param->state,
15723 __ATOMIC_RELAXED) == AGE_TMOUT ?
15725 resp->sec_since_last_hit_valid = !resp->aged;
15726 if (resp->sec_since_last_hit_valid)
15727 resp->sec_since_last_hit = __atomic_load_n
15728 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15730 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15731 return flow_dv_query_count(dev, idx, data, error);
15732 case MLX5_INDIRECT_ACTION_TYPE_CT:
15733 owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
15734 if (owner != PORT_ID(priv))
15735 return rte_flow_error_set(error, EACCES,
15736 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15738 "CT object owned by another port");
15739 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
15740 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
15743 return rte_flow_error_set(error, EFAULT,
15744 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15746 "CT object is inactive");
15747 ((struct rte_flow_action_conntrack *)data)->peer_port =
15749 ((struct rte_flow_action_conntrack *)data)->is_original_dir =
15751 if (mlx5_aso_ct_query_by_wqe(priv->sh, ct, data))
15752 return rte_flow_error_set(error, EIO,
15753 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15755 "Failed to query CT context");
15758 return rte_flow_error_set(error, ENOTSUP,
15759 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15760 "action type query not supported");
15765 * Query a flow rule AGE action for aging information.
15768 * Pointer to Ethernet device.
15770 * Pointer to the sub flow.
15772 * data retrieved by the query.
15773 * @param[out] error
15774 * Perform verbose error reporting if not NULL.
15777 * 0 on success, a negative errno value otherwise and rte_errno is set.
15780 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
15781 void *data, struct rte_flow_error *error)
15783 struct rte_flow_query_age *resp = data;
15784 struct mlx5_age_param *age_param;
15787 struct mlx5_aso_age_action *act =
15788 flow_aso_age_get_by_idx(dev, flow->age);
15790 age_param = &act->age_params;
15791 } else if (flow->counter) {
15792 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
15794 if (!age_param || !age_param->timeout)
15795 return rte_flow_error_set
15797 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15798 NULL, "cannot read age data");
15800 return rte_flow_error_set(error, EINVAL,
15801 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15802 NULL, "age data not available");
15804 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
15806 resp->sec_since_last_hit_valid = !resp->aged;
15807 if (resp->sec_since_last_hit_valid)
15808 resp->sec_since_last_hit = __atomic_load_n
15809 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15816 * @see rte_flow_query()
15817 * @see rte_flow_ops
15820 flow_dv_query(struct rte_eth_dev *dev,
15821 struct rte_flow *flow __rte_unused,
15822 const struct rte_flow_action *actions __rte_unused,
15823 void *data __rte_unused,
15824 struct rte_flow_error *error __rte_unused)
15828 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
15829 switch (actions->type) {
15830 case RTE_FLOW_ACTION_TYPE_VOID:
15832 case RTE_FLOW_ACTION_TYPE_COUNT:
15833 ret = flow_dv_query_count(dev, flow->counter, data,
15836 case RTE_FLOW_ACTION_TYPE_AGE:
15837 ret = flow_dv_query_age(dev, flow, data, error);
15840 return rte_flow_error_set(error, ENOTSUP,
15841 RTE_FLOW_ERROR_TYPE_ACTION,
15843 "action not supported");
15850 * Destroy the meter table set.
15851 * Lock free, (mutex should be acquired by caller).
15854 * Pointer to Ethernet device.
15856 * Meter information table.
15859 flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
15860 struct mlx5_flow_meter_info *fm)
15862 struct mlx5_priv *priv = dev->data->dev_private;
15865 if (!fm || !priv->config.dv_flow_en)
15867 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15868 if (fm->drop_rule[i]) {
15869 claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
15870 fm->drop_rule[i] = NULL;
15876 flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
15878 struct mlx5_priv *priv = dev->data->dev_private;
15879 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15880 struct mlx5_flow_tbl_data_entry *tbl;
15883 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15884 if (mtrmng->def_rule[i]) {
15885 claim_zero(mlx5_flow_os_destroy_flow
15886 (mtrmng->def_rule[i]));
15887 mtrmng->def_rule[i] = NULL;
15889 if (mtrmng->def_matcher[i]) {
15890 tbl = container_of(mtrmng->def_matcher[i]->tbl,
15891 struct mlx5_flow_tbl_data_entry, tbl);
15892 mlx5_list_unregister(tbl->matchers,
15893 &mtrmng->def_matcher[i]->entry);
15894 mtrmng->def_matcher[i] = NULL;
15896 for (j = 0; j < MLX5_REG_BITS; j++) {
15897 if (mtrmng->drop_matcher[i][j]) {
15899 container_of(mtrmng->drop_matcher[i][j]->tbl,
15900 struct mlx5_flow_tbl_data_entry,
15902 mlx5_list_unregister(tbl->matchers,
15903 &mtrmng->drop_matcher[i][j]->entry);
15904 mtrmng->drop_matcher[i][j] = NULL;
15907 if (mtrmng->drop_tbl[i]) {
15908 flow_dv_tbl_resource_release(MLX5_SH(dev),
15909 mtrmng->drop_tbl[i]);
15910 mtrmng->drop_tbl[i] = NULL;
15915 /* Number of meter flow actions, count and jump or count and drop. */
15916 #define METER_ACTIONS 2
15919 __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
15920 enum mlx5_meter_domain domain)
15922 struct mlx5_priv *priv = dev->data->dev_private;
15923 struct mlx5_flow_meter_def_policy *def_policy =
15924 priv->sh->mtrmng->def_policy[domain];
15926 __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
15927 mlx5_free(def_policy);
15928 priv->sh->mtrmng->def_policy[domain] = NULL;
15932 * Destroy the default policy table set.
15935 * Pointer to Ethernet device.
15938 flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
15940 struct mlx5_priv *priv = dev->data->dev_private;
15943 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
15944 if (priv->sh->mtrmng->def_policy[i])
15945 __flow_dv_destroy_domain_def_policy(dev,
15946 (enum mlx5_meter_domain)i);
15947 priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
15951 __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
15952 uint32_t color_reg_c_idx,
15953 enum rte_color color, void *matcher_object,
15954 int actions_n, void *actions,
15955 bool match_src_port, const struct rte_flow_item *item,
15956 void **rule, const struct rte_flow_attr *attr)
15959 struct mlx5_flow_dv_match_params value = {
15960 .size = sizeof(value.buf),
15962 struct mlx5_flow_dv_match_params matcher = {
15963 .size = sizeof(matcher.buf),
15965 struct mlx5_priv *priv = dev->data->dev_private;
15968 if (match_src_port && (priv->representor || priv->master)) {
15969 if (flow_dv_translate_item_port_id(dev, matcher.buf,
15970 value.buf, item, attr)) {
15971 DRV_LOG(ERR, "Failed to create meter policy%d flow's"
15972 " value with port.", color);
15976 flow_dv_match_meta_reg(matcher.buf, value.buf,
15977 (enum modify_reg)color_reg_c_idx,
15978 rte_col_2_mlx5_col(color), UINT32_MAX);
15979 misc_mask = flow_dv_matcher_enable(value.buf);
15980 __flow_dv_adjust_buf_size(&value.size, misc_mask);
15981 ret = mlx5_flow_os_create_flow(matcher_object, (void *)&value,
15982 actions_n, actions, rule);
15984 DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
15991 __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
15992 uint32_t color_reg_c_idx,
15994 struct mlx5_flow_meter_sub_policy *sub_policy,
15995 const struct rte_flow_attr *attr,
15996 bool match_src_port,
15997 const struct rte_flow_item *item,
15998 struct mlx5_flow_dv_matcher **policy_matcher,
15999 struct rte_flow_error *error)
16001 struct mlx5_list_entry *entry;
16002 struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
16003 struct mlx5_flow_dv_matcher matcher = {
16005 .size = sizeof(matcher.mask.buf),
16009 struct mlx5_flow_dv_match_params value = {
16010 .size = sizeof(value.buf),
16012 struct mlx5_flow_cb_ctx ctx = {
16016 struct mlx5_flow_tbl_data_entry *tbl_data;
16017 struct mlx5_priv *priv = dev->data->dev_private;
16018 const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
16020 if (match_src_port && (priv->representor || priv->master)) {
16021 if (flow_dv_translate_item_port_id(dev, matcher.mask.buf,
16022 value.buf, item, attr)) {
16023 DRV_LOG(ERR, "Failed to register meter policy%d matcher"
16024 " with port.", priority);
16028 tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
16029 if (priority < RTE_COLOR_RED)
16030 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16031 (enum modify_reg)color_reg_c_idx, 0, color_mask);
16032 matcher.priority = priority;
16033 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
16034 matcher.mask.size);
16035 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16037 DRV_LOG(ERR, "Failed to register meter drop matcher.");
16041 container_of(entry, struct mlx5_flow_dv_matcher, entry);
16046 * Create the policy rules per domain.
16049 * Pointer to Ethernet device.
16050 * @param[in] sub_policy
16051 * Pointer to sub policy table..
16052 * @param[in] egress
16053 * Direction of the table.
16054 * @param[in] transfer
16055 * E-Switch or NIC flow.
16057 * Pointer to policy action list per color.
16060 * 0 on success, -1 otherwise.
16063 __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
16064 struct mlx5_flow_meter_sub_policy *sub_policy,
16065 uint8_t egress, uint8_t transfer, bool match_src_port,
16066 struct mlx5_meter_policy_acts acts[RTE_COLORS])
16068 struct mlx5_priv *priv = dev->data->dev_private;
16069 struct rte_flow_error flow_err;
16070 uint32_t color_reg_c_idx;
16071 struct rte_flow_attr attr = {
16072 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
16075 .egress = !!egress,
16076 .transfer = !!transfer,
16080 int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
16081 struct mlx5_sub_policy_color_rule *color_rule;
16083 struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
16087 /* Create policy table with POLICY level. */
16088 if (!sub_policy->tbl_rsc)
16089 sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
16090 MLX5_FLOW_TABLE_LEVEL_POLICY,
16091 egress, transfer, false, NULL, 0, 0,
16092 sub_policy->idx, &flow_err);
16093 if (!sub_policy->tbl_rsc) {
16095 "Failed to create meter sub policy table.");
16098 /* Prepare matchers. */
16099 color_reg_c_idx = ret;
16100 for (i = 0; i < RTE_COLORS; i++) {
16101 TAILQ_INIT(&sub_policy->color_rules[i]);
16102 if (!acts[i].actions_n)
16104 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
16105 sizeof(struct mlx5_sub_policy_color_rule),
16108 DRV_LOG(ERR, "No memory to create color rule.");
16111 tmp_rules[i] = color_rule;
16112 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
16113 color_rule, next_port);
16114 color_rule->src_port = priv->representor_id;
16117 /* Create matchers for colors. */
16118 svport_match = (i != RTE_COLOR_RED) ? match_src_port : false;
16119 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
16120 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
16121 &attr, svport_match, NULL,
16122 &color_rule->matcher, &flow_err)) {
16123 DRV_LOG(ERR, "Failed to create color%u matcher.", i);
16126 /* Create flow, matching color. */
16127 if (__flow_dv_create_policy_flow(dev,
16128 color_reg_c_idx, (enum rte_color)i,
16129 color_rule->matcher->matcher_object,
16130 acts[i].actions_n, acts[i].dv_actions,
16131 svport_match, NULL, &color_rule->rule,
16133 DRV_LOG(ERR, "Failed to create color%u rule.", i);
16139 /* All the policy rules will be cleared. */
16141 color_rule = tmp_rules[i];
16143 if (color_rule->rule)
16144 mlx5_flow_os_destroy_flow(color_rule->rule);
16145 if (color_rule->matcher) {
16146 struct mlx5_flow_tbl_data_entry *tbl =
16147 container_of(color_rule->matcher->tbl,
16148 typeof(*tbl), tbl);
16149 mlx5_list_unregister(tbl->matchers,
16150 &color_rule->matcher->entry);
16152 TAILQ_REMOVE(&sub_policy->color_rules[i],
16153 color_rule, next_port);
16154 mlx5_free(color_rule);
16161 __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
16162 struct mlx5_flow_meter_policy *mtr_policy,
16163 struct mlx5_flow_meter_sub_policy *sub_policy,
16166 struct mlx5_priv *priv = dev->data->dev_private;
16167 struct mlx5_meter_policy_acts acts[RTE_COLORS];
16168 struct mlx5_flow_dv_tag_resource *tag;
16169 struct mlx5_flow_dv_port_id_action_resource *port_action;
16170 struct mlx5_hrxq *hrxq;
16171 struct mlx5_flow_meter_info *next_fm = NULL;
16172 struct mlx5_flow_meter_policy *next_policy;
16173 struct mlx5_flow_meter_sub_policy *next_sub_policy;
16174 struct mlx5_flow_tbl_data_entry *tbl_data;
16175 struct rte_flow_error error;
16176 uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16177 uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16178 bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
16179 bool match_src_port = false;
16182 /* If RSS or Queue, no previous actions / rules is created. */
16183 for (i = 0; i < RTE_COLORS; i++) {
16184 acts[i].actions_n = 0;
16185 if (i == RTE_COLOR_RED) {
16186 /* Only support drop on red. */
16187 acts[i].dv_actions[0] =
16188 mtr_policy->dr_drop_action[domain];
16189 acts[i].actions_n = 1;
16192 if (i == RTE_COLOR_GREEN &&
16193 mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
16194 struct rte_flow_attr attr = {
16195 .transfer = transfer
16198 next_fm = mlx5_flow_meter_find(priv,
16199 mtr_policy->act_cnt[i].next_mtr_id,
16203 "Failed to get next hierarchy meter.");
16206 if (mlx5_flow_meter_attach(priv, next_fm,
16208 DRV_LOG(ERR, "%s", error.message);
16212 /* Meter action must be the first for TX. */
16214 acts[i].dv_actions[acts[i].actions_n] =
16215 next_fm->meter_action;
16216 acts[i].actions_n++;
16219 if (mtr_policy->act_cnt[i].rix_mark) {
16220 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
16221 mtr_policy->act_cnt[i].rix_mark);
16223 DRV_LOG(ERR, "Failed to find "
16224 "mark action for policy.");
16227 acts[i].dv_actions[acts[i].actions_n] = tag->action;
16228 acts[i].actions_n++;
16230 if (mtr_policy->act_cnt[i].modify_hdr) {
16231 acts[i].dv_actions[acts[i].actions_n] =
16232 mtr_policy->act_cnt[i].modify_hdr->action;
16233 acts[i].actions_n++;
16235 if (mtr_policy->act_cnt[i].fate_action) {
16236 switch (mtr_policy->act_cnt[i].fate_action) {
16237 case MLX5_FLOW_FATE_PORT_ID:
16238 port_action = mlx5_ipool_get
16239 (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
16240 mtr_policy->act_cnt[i].rix_port_id_action);
16241 if (!port_action) {
16242 DRV_LOG(ERR, "Failed to find "
16243 "port action for policy.");
16246 acts[i].dv_actions[acts[i].actions_n] =
16247 port_action->action;
16248 acts[i].actions_n++;
16249 mtr_policy->dev = dev;
16250 match_src_port = true;
16252 case MLX5_FLOW_FATE_DROP:
16253 case MLX5_FLOW_FATE_JUMP:
16254 acts[i].dv_actions[acts[i].actions_n] =
16255 mtr_policy->act_cnt[i].dr_jump_action[domain];
16256 acts[i].actions_n++;
16258 case MLX5_FLOW_FATE_SHARED_RSS:
16259 case MLX5_FLOW_FATE_QUEUE:
16260 hrxq = mlx5_ipool_get
16261 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16262 sub_policy->rix_hrxq[i]);
16264 DRV_LOG(ERR, "Failed to find "
16265 "queue action for policy.");
16268 acts[i].dv_actions[acts[i].actions_n] =
16270 acts[i].actions_n++;
16272 case MLX5_FLOW_FATE_MTR:
16275 "No next hierarchy meter.");
16279 acts[i].dv_actions[acts[i].actions_n] =
16280 next_fm->meter_action;
16281 acts[i].actions_n++;
16283 if (mtr_policy->act_cnt[i].next_sub_policy) {
16285 mtr_policy->act_cnt[i].next_sub_policy;
16288 mlx5_flow_meter_policy_find(dev,
16289 next_fm->policy_id, NULL);
16290 MLX5_ASSERT(next_policy);
16292 next_policy->sub_policys[domain][0];
16295 container_of(next_sub_policy->tbl_rsc,
16296 struct mlx5_flow_tbl_data_entry, tbl);
16297 acts[i].dv_actions[acts[i].actions_n++] =
16298 tbl_data->jump.action;
16299 if (mtr_policy->act_cnt[i].modify_hdr)
16300 match_src_port = !!transfer;
16303 /*Queue action do nothing*/
16308 if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
16309 egress, transfer, match_src_port, acts)) {
16311 "Failed to create policy rules per domain.");
16317 mlx5_flow_meter_detach(priv, next_fm);
16322 * Create the policy rules.
16325 * Pointer to Ethernet device.
16326 * @param[in,out] mtr_policy
16327 * Pointer to meter policy table.
16330 * 0 on success, -1 otherwise.
16333 flow_dv_create_policy_rules(struct rte_eth_dev *dev,
16334 struct mlx5_flow_meter_policy *mtr_policy)
16337 uint16_t sub_policy_num;
16339 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16340 sub_policy_num = (mtr_policy->sub_policy_num >>
16341 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
16342 MLX5_MTR_SUB_POLICY_NUM_MASK;
16343 if (!sub_policy_num)
16345 /* Prepare actions list and create policy rules. */
16346 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16347 mtr_policy->sub_policys[i][0], i)) {
16348 DRV_LOG(ERR, "Failed to create policy action "
16349 "list per domain.");
16357 __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
16359 struct mlx5_priv *priv = dev->data->dev_private;
16360 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16361 struct mlx5_flow_meter_def_policy *def_policy;
16362 struct mlx5_flow_tbl_resource *jump_tbl;
16363 struct mlx5_flow_tbl_data_entry *tbl_data;
16364 uint8_t egress, transfer;
16365 struct rte_flow_error error;
16366 struct mlx5_meter_policy_acts acts[RTE_COLORS];
16369 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16370 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16371 def_policy = mtrmng->def_policy[domain];
16373 def_policy = mlx5_malloc(MLX5_MEM_ZERO,
16374 sizeof(struct mlx5_flow_meter_def_policy),
16375 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
16377 DRV_LOG(ERR, "Failed to alloc default policy table.");
16378 goto def_policy_error;
16380 mtrmng->def_policy[domain] = def_policy;
16381 /* Create the meter suffix table with SUFFIX level. */
16382 jump_tbl = flow_dv_tbl_resource_get(dev,
16383 MLX5_FLOW_TABLE_LEVEL_METER,
16384 egress, transfer, false, NULL, 0,
16385 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
16388 "Failed to create meter suffix table.");
16389 goto def_policy_error;
16391 def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
16392 tbl_data = container_of(jump_tbl,
16393 struct mlx5_flow_tbl_data_entry, tbl);
16394 def_policy->dr_jump_action[RTE_COLOR_GREEN] =
16395 tbl_data->jump.action;
16396 acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
16397 acts[RTE_COLOR_GREEN].actions_n = 1;
16399 * YELLOW has the same default policy as GREEN does.
16400 * G & Y share the same table and action. The 2nd time of table
16401 * resource getting is just to update the reference count for
16402 * the releasing stage.
16404 jump_tbl = flow_dv_tbl_resource_get(dev,
16405 MLX5_FLOW_TABLE_LEVEL_METER,
16406 egress, transfer, false, NULL, 0,
16407 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
16410 "Failed to get meter suffix table.");
16411 goto def_policy_error;
16413 def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
16414 tbl_data = container_of(jump_tbl,
16415 struct mlx5_flow_tbl_data_entry, tbl);
16416 def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
16417 tbl_data->jump.action;
16418 acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
16419 acts[RTE_COLOR_YELLOW].actions_n = 1;
16420 /* Create jump action to the drop table. */
16421 if (!mtrmng->drop_tbl[domain]) {
16422 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
16423 (dev, MLX5_FLOW_TABLE_LEVEL_METER,
16424 egress, transfer, false, NULL, 0,
16425 0, MLX5_MTR_TABLE_ID_DROP, &error);
16426 if (!mtrmng->drop_tbl[domain]) {
16427 DRV_LOG(ERR, "Failed to create meter "
16428 "drop table for default policy.");
16429 goto def_policy_error;
16432 /* all RED: unique Drop table for jump action. */
16433 tbl_data = container_of(mtrmng->drop_tbl[domain],
16434 struct mlx5_flow_tbl_data_entry, tbl);
16435 def_policy->dr_jump_action[RTE_COLOR_RED] =
16436 tbl_data->jump.action;
16437 acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
16438 acts[RTE_COLOR_RED].actions_n = 1;
16439 /* Create default policy rules. */
16440 ret = __flow_dv_create_domain_policy_rules(dev,
16441 &def_policy->sub_policy,
16442 egress, transfer, false, acts);
16444 DRV_LOG(ERR, "Failed to create default policy rules.");
16445 goto def_policy_error;
16450 __flow_dv_destroy_domain_def_policy(dev,
16451 (enum mlx5_meter_domain)domain);
16456 * Create the default policy table set.
16459 * Pointer to Ethernet device.
16461 * 0 on success, -1 otherwise.
16464 flow_dv_create_def_policy(struct rte_eth_dev *dev)
16466 struct mlx5_priv *priv = dev->data->dev_private;
16469 /* Non-termination policy table. */
16470 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16471 if (!priv->config.dv_esw_en && i == MLX5_MTR_DOMAIN_TRANSFER)
16473 if (__flow_dv_create_domain_def_policy(dev, i)) {
16474 DRV_LOG(ERR, "Failed to create default policy");
16475 /* Rollback the created default policies for others. */
16476 flow_dv_destroy_def_policy(dev);
16484 * Create the needed meter tables.
16485 * Lock free, (mutex should be acquired by caller).
16488 * Pointer to Ethernet device.
16490 * Meter information table.
16491 * @param[in] mtr_idx
16493 * @param[in] domain_bitmap
16496 * 0 on success, -1 otherwise.
16499 flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
16500 struct mlx5_flow_meter_info *fm,
16502 uint8_t domain_bitmap)
16504 struct mlx5_priv *priv = dev->data->dev_private;
16505 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16506 struct rte_flow_error error;
16507 struct mlx5_flow_tbl_data_entry *tbl_data;
16508 uint8_t egress, transfer;
16509 void *actions[METER_ACTIONS];
16510 int domain, ret, i;
16511 struct mlx5_flow_counter *cnt;
16512 struct mlx5_flow_dv_match_params value = {
16513 .size = sizeof(value.buf),
16515 struct mlx5_flow_dv_match_params matcher_para = {
16516 .size = sizeof(matcher_para.buf),
16518 int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
16520 uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
16521 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
16522 struct mlx5_list_entry *entry;
16523 struct mlx5_flow_dv_matcher matcher = {
16525 .size = sizeof(matcher.mask.buf),
16528 struct mlx5_flow_dv_matcher *drop_matcher;
16529 struct mlx5_flow_cb_ctx ctx = {
16535 if (!priv->mtr_en || mtr_id_reg_c < 0) {
16536 rte_errno = ENOTSUP;
16539 for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
16540 if (!(domain_bitmap & (1 << domain)) ||
16541 (mtrmng->def_rule[domain] && !fm->drop_cnt))
16543 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16544 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16545 /* Create the drop table with METER DROP level. */
16546 if (!mtrmng->drop_tbl[domain]) {
16547 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
16548 MLX5_FLOW_TABLE_LEVEL_METER,
16549 egress, transfer, false, NULL, 0,
16550 0, MLX5_MTR_TABLE_ID_DROP, &error);
16551 if (!mtrmng->drop_tbl[domain]) {
16552 DRV_LOG(ERR, "Failed to create meter drop table.");
16556 /* Create default matcher in drop table. */
16557 matcher.tbl = mtrmng->drop_tbl[domain],
16558 tbl_data = container_of(mtrmng->drop_tbl[domain],
16559 struct mlx5_flow_tbl_data_entry, tbl);
16560 if (!mtrmng->def_matcher[domain]) {
16561 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16562 (enum modify_reg)mtr_id_reg_c,
16564 matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
16565 matcher.crc = rte_raw_cksum
16566 ((const void *)matcher.mask.buf,
16567 matcher.mask.size);
16568 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16570 DRV_LOG(ERR, "Failed to register meter "
16571 "drop default matcher.");
16574 mtrmng->def_matcher[domain] = container_of(entry,
16575 struct mlx5_flow_dv_matcher, entry);
16577 /* Create default rule in drop table. */
16578 if (!mtrmng->def_rule[domain]) {
16580 actions[i++] = priv->sh->dr_drop_action;
16581 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16582 (enum modify_reg)mtr_id_reg_c, 0, 0);
16583 misc_mask = flow_dv_matcher_enable(value.buf);
16584 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16585 ret = mlx5_flow_os_create_flow
16586 (mtrmng->def_matcher[domain]->matcher_object,
16587 (void *)&value, i, actions,
16588 &mtrmng->def_rule[domain]);
16590 DRV_LOG(ERR, "Failed to create meter "
16591 "default drop rule for drop table.");
16597 MLX5_ASSERT(mtrmng->max_mtr_bits);
16598 if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
16599 /* Create matchers for Drop. */
16600 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16601 (enum modify_reg)mtr_id_reg_c, 0,
16602 (mtr_id_mask << mtr_id_offset));
16603 matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
16604 matcher.crc = rte_raw_cksum
16605 ((const void *)matcher.mask.buf,
16606 matcher.mask.size);
16607 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16610 "Failed to register meter drop matcher.");
16613 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
16614 container_of(entry, struct mlx5_flow_dv_matcher,
16618 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
16619 /* Create drop rule, matching meter_id only. */
16620 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16621 (enum modify_reg)mtr_id_reg_c,
16622 (mtr_idx << mtr_id_offset), UINT32_MAX);
16624 cnt = flow_dv_counter_get_by_idx(dev,
16625 fm->drop_cnt, NULL);
16626 actions[i++] = cnt->action;
16627 actions[i++] = priv->sh->dr_drop_action;
16628 misc_mask = flow_dv_matcher_enable(value.buf);
16629 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16630 ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
16631 (void *)&value, i, actions,
16632 &fm->drop_rule[domain]);
16634 DRV_LOG(ERR, "Failed to create meter "
16635 "drop rule for drop table.");
16641 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16642 if (fm->drop_rule[i]) {
16643 claim_zero(mlx5_flow_os_destroy_flow
16644 (fm->drop_rule[i]));
16645 fm->drop_rule[i] = NULL;
16651 static struct mlx5_flow_meter_sub_policy *
16652 __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
16653 struct mlx5_flow_meter_policy *mtr_policy,
16654 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
16655 struct mlx5_flow_meter_sub_policy *next_sub_policy,
16658 struct mlx5_priv *priv = dev->data->dev_private;
16659 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16660 uint32_t sub_policy_idx = 0;
16661 uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
16663 struct mlx5_hrxq *hrxq;
16664 struct mlx5_flow_handle dh;
16665 struct mlx5_meter_policy_action_container *act_cnt;
16666 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16667 uint16_t sub_policy_num;
16669 rte_spinlock_lock(&mtr_policy->sl);
16670 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16673 hrxq_idx[i] = mlx5_hrxq_get(dev, rss_desc[i]);
16674 if (!hrxq_idx[i]) {
16675 rte_spinlock_unlock(&mtr_policy->sl);
16679 sub_policy_num = (mtr_policy->sub_policy_num >>
16680 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16681 MLX5_MTR_SUB_POLICY_NUM_MASK;
16682 for (j = 0; j < sub_policy_num; j++) {
16683 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16686 mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
16689 if (i >= MLX5_MTR_RTE_COLORS) {
16691 * Found the sub policy table with
16692 * the same queue per color.
16694 rte_spinlock_unlock(&mtr_policy->sl);
16695 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
16696 mlx5_hrxq_release(dev, hrxq_idx[i]);
16698 return mtr_policy->sub_policys[domain][j];
16701 /* Create sub policy. */
16702 if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[0]) {
16703 /* Reuse the first pre-allocated sub_policy. */
16704 sub_policy = mtr_policy->sub_policys[domain][0];
16705 sub_policy_idx = sub_policy->idx;
16707 sub_policy = mlx5_ipool_zmalloc
16708 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16711 sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
16712 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
16713 mlx5_hrxq_release(dev, hrxq_idx[i]);
16714 goto rss_sub_policy_error;
16716 sub_policy->idx = sub_policy_idx;
16717 sub_policy->main_policy = mtr_policy;
16719 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16722 sub_policy->rix_hrxq[i] = hrxq_idx[i];
16723 if (mtr_policy->is_hierarchy) {
16724 act_cnt = &mtr_policy->act_cnt[i];
16725 act_cnt->next_sub_policy = next_sub_policy;
16726 mlx5_hrxq_release(dev, hrxq_idx[i]);
16729 * Overwrite the last action from
16730 * RSS action to Queue action.
16732 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
16735 DRV_LOG(ERR, "Failed to get policy hrxq");
16736 goto rss_sub_policy_error;
16738 act_cnt = &mtr_policy->act_cnt[i];
16739 if (act_cnt->rix_mark || act_cnt->modify_hdr) {
16740 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
16741 if (act_cnt->rix_mark)
16743 dh.fate_action = MLX5_FLOW_FATE_QUEUE;
16744 dh.rix_hrxq = hrxq_idx[i];
16745 flow_drv_rxq_flags_set(dev, &dh);
16749 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16750 sub_policy, domain)) {
16751 DRV_LOG(ERR, "Failed to create policy "
16752 "rules for ingress domain.");
16753 goto rss_sub_policy_error;
16755 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16756 i = (mtr_policy->sub_policy_num >>
16757 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16758 MLX5_MTR_SUB_POLICY_NUM_MASK;
16759 if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
16760 DRV_LOG(ERR, "No free sub-policy slot.");
16761 goto rss_sub_policy_error;
16763 mtr_policy->sub_policys[domain][i] = sub_policy;
16765 mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16766 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
16767 mtr_policy->sub_policy_num |=
16768 (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16769 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
16771 rte_spinlock_unlock(&mtr_policy->sl);
16774 rss_sub_policy_error:
16776 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
16777 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16778 i = (mtr_policy->sub_policy_num >>
16779 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16780 MLX5_MTR_SUB_POLICY_NUM_MASK;
16781 mtr_policy->sub_policys[domain][i] = NULL;
16782 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16786 rte_spinlock_unlock(&mtr_policy->sl);
16791 * Find the policy table for prefix table with RSS.
16794 * Pointer to Ethernet device.
16795 * @param[in] mtr_policy
16796 * Pointer to meter policy table.
16797 * @param[in] rss_desc
16798 * Pointer to rss_desc
16800 * Pointer to table set on success, NULL otherwise and rte_errno is set.
16802 static struct mlx5_flow_meter_sub_policy *
16803 flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
16804 struct mlx5_flow_meter_policy *mtr_policy,
16805 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
16807 struct mlx5_priv *priv = dev->data->dev_private;
16808 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16809 struct mlx5_flow_meter_info *next_fm;
16810 struct mlx5_flow_meter_policy *next_policy;
16811 struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
16812 struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
16813 struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
16814 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16815 bool reuse_sub_policy;
16820 /* Iterate hierarchy to get all policies in this hierarchy. */
16821 policies[i++] = mtr_policy;
16822 if (!mtr_policy->is_hierarchy)
16824 if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
16825 DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
16828 next_fm = mlx5_flow_meter_find(priv,
16829 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
16831 DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
16835 mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
16837 MLX5_ASSERT(next_policy);
16838 mtr_policy = next_policy;
16842 * From last policy to the first one in hierarchy,
16843 * create / get the sub policy for each of them.
16845 sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
16849 &reuse_sub_policy);
16851 DRV_LOG(ERR, "Failed to get the sub policy.");
16854 if (!reuse_sub_policy)
16855 sub_policies[j++] = sub_policy;
16856 next_sub_policy = sub_policy;
16861 uint16_t sub_policy_num;
16863 sub_policy = sub_policies[--j];
16864 mtr_policy = sub_policy->main_policy;
16865 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
16866 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16867 sub_policy_num = (mtr_policy->sub_policy_num >>
16868 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16869 MLX5_MTR_SUB_POLICY_NUM_MASK;
16870 mtr_policy->sub_policys[domain][sub_policy_num - 1] =
16873 mtr_policy->sub_policy_num &=
16874 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16875 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
16876 mtr_policy->sub_policy_num |=
16877 (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16878 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
16879 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16887 * Create the sub policy tag rule for all meters in hierarchy.
16890 * Pointer to Ethernet device.
16892 * Meter information table.
16893 * @param[in] src_port
16894 * The src port this extra rule should use.
16896 * The src port match item.
16897 * @param[out] error
16898 * Perform verbose error reporting if not NULL.
16900 * 0 on success, a negative errno value otherwise and rte_errno is set.
16903 flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
16904 struct mlx5_flow_meter_info *fm,
16906 const struct rte_flow_item *item,
16907 struct rte_flow_error *error)
16909 struct mlx5_priv *priv = dev->data->dev_private;
16910 struct mlx5_flow_meter_policy *mtr_policy;
16911 struct mlx5_flow_meter_sub_policy *sub_policy;
16912 struct mlx5_flow_meter_info *next_fm = NULL;
16913 struct mlx5_flow_meter_policy *next_policy;
16914 struct mlx5_flow_meter_sub_policy *next_sub_policy;
16915 struct mlx5_flow_tbl_data_entry *tbl_data;
16916 struct mlx5_sub_policy_color_rule *color_rule;
16917 struct mlx5_meter_policy_acts acts;
16918 uint32_t color_reg_c_idx;
16919 bool mtr_first = (src_port != UINT16_MAX) ? true : false;
16920 struct rte_flow_attr attr = {
16921 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
16928 uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
16931 mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
16932 MLX5_ASSERT(mtr_policy);
16933 if (!mtr_policy->is_hierarchy)
16935 next_fm = mlx5_flow_meter_find(priv,
16936 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
16938 return rte_flow_error_set(error, EINVAL,
16939 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16940 "Failed to find next meter in hierarchy.");
16942 if (!next_fm->drop_cnt)
16944 color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
16945 sub_policy = mtr_policy->sub_policys[domain][0];
16946 for (i = 0; i < RTE_COLORS; i++) {
16947 bool rule_exist = false;
16948 struct mlx5_meter_policy_action_container *act_cnt;
16950 if (i >= RTE_COLOR_YELLOW)
16952 TAILQ_FOREACH(color_rule,
16953 &sub_policy->color_rules[i], next_port)
16954 if (color_rule->src_port == src_port) {
16960 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
16961 sizeof(struct mlx5_sub_policy_color_rule),
16964 return rte_flow_error_set(error, ENOMEM,
16965 RTE_FLOW_ERROR_TYPE_ACTION,
16966 NULL, "No memory to create tag color rule.");
16967 color_rule->src_port = src_port;
16969 next_policy = mlx5_flow_meter_policy_find(dev,
16970 next_fm->policy_id, NULL);
16971 MLX5_ASSERT(next_policy);
16972 next_sub_policy = next_policy->sub_policys[domain][0];
16973 tbl_data = container_of(next_sub_policy->tbl_rsc,
16974 struct mlx5_flow_tbl_data_entry, tbl);
16975 act_cnt = &mtr_policy->act_cnt[i];
16977 acts.dv_actions[0] = next_fm->meter_action;
16978 acts.dv_actions[1] = act_cnt->modify_hdr->action;
16980 acts.dv_actions[0] = act_cnt->modify_hdr->action;
16981 acts.dv_actions[1] = next_fm->meter_action;
16983 acts.dv_actions[2] = tbl_data->jump.action;
16984 acts.actions_n = 3;
16985 if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
16989 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
16990 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
16992 &color_rule->matcher, error)) {
16993 rte_flow_error_set(error, errno,
16994 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16995 "Failed to create hierarchy meter matcher.");
16998 if (__flow_dv_create_policy_flow(dev, color_reg_c_idx,
17000 color_rule->matcher->matcher_object,
17001 acts.actions_n, acts.dv_actions,
17003 &color_rule->rule, &attr)) {
17004 rte_flow_error_set(error, errno,
17005 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17006 "Failed to create hierarchy meter rule.");
17009 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
17010 color_rule, next_port);
17014 * Recursive call to iterate all meters in hierarchy and
17015 * create needed rules.
17017 return flow_dv_meter_hierarchy_rule_create(dev, next_fm,
17018 src_port, item, error);
17021 if (color_rule->rule)
17022 mlx5_flow_os_destroy_flow(color_rule->rule);
17023 if (color_rule->matcher) {
17024 struct mlx5_flow_tbl_data_entry *tbl =
17025 container_of(color_rule->matcher->tbl,
17026 typeof(*tbl), tbl);
17027 mlx5_list_unregister(tbl->matchers,
17028 &color_rule->matcher->entry);
17030 mlx5_free(color_rule);
17033 mlx5_flow_meter_detach(priv, next_fm);
17038 * Destroy the sub policy table with RX queue.
17041 * Pointer to Ethernet device.
17042 * @param[in] mtr_policy
17043 * Pointer to meter policy table.
17046 flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
17047 struct mlx5_flow_meter_policy *mtr_policy)
17049 struct mlx5_priv *priv = dev->data->dev_private;
17050 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
17051 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
17053 uint16_t sub_policy_num, new_policy_num;
17055 rte_spinlock_lock(&mtr_policy->sl);
17056 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17057 switch (mtr_policy->act_cnt[i].fate_action) {
17058 case MLX5_FLOW_FATE_SHARED_RSS:
17059 sub_policy_num = (mtr_policy->sub_policy_num >>
17060 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17061 MLX5_MTR_SUB_POLICY_NUM_MASK;
17062 new_policy_num = sub_policy_num;
17063 for (j = 0; j < sub_policy_num; j++) {
17065 mtr_policy->sub_policys[domain][j];
17067 __flow_dv_destroy_sub_policy_rules(dev,
17070 mtr_policy->sub_policys[domain][0]) {
17071 mtr_policy->sub_policys[domain][j] =
17074 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17080 if (new_policy_num != sub_policy_num) {
17081 mtr_policy->sub_policy_num &=
17082 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17083 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
17084 mtr_policy->sub_policy_num |=
17086 MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17087 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
17090 case MLX5_FLOW_FATE_QUEUE:
17091 sub_policy = mtr_policy->sub_policys[domain][0];
17092 __flow_dv_destroy_sub_policy_rules(dev,
17096 /*Other actions without queue and do nothing*/
17100 rte_spinlock_unlock(&mtr_policy->sl);
17103 * Check whether the DR drop action is supported on the root table or not.
17105 * Create a simple flow with DR drop action on root table to validate
17106 * if DR drop action on root table is supported or not.
17109 * Pointer to rte_eth_dev structure.
17112 * 0 on success, a negative errno value otherwise and rte_errno is set.
17115 mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
17117 struct mlx5_priv *priv = dev->data->dev_private;
17118 struct mlx5_dev_ctx_shared *sh = priv->sh;
17119 struct mlx5_flow_dv_match_params mask = {
17120 .size = sizeof(mask.buf),
17122 struct mlx5_flow_dv_match_params value = {
17123 .size = sizeof(value.buf),
17125 struct mlx5dv_flow_matcher_attr dv_attr = {
17126 .type = IBV_FLOW_ATTR_NORMAL,
17128 .match_criteria_enable = 0,
17129 .match_mask = (void *)&mask,
17131 struct mlx5_flow_tbl_resource *tbl = NULL;
17132 void *matcher = NULL;
17136 tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
17140 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
17141 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
17142 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
17146 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
17147 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
17148 &sh->dr_drop_action, &flow);
17151 * If DR drop action is not supported on root table, flow create will
17152 * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
17156 (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
17157 DRV_LOG(INFO, "DR drop action is not supported in root table.");
17159 DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
17162 claim_zero(mlx5_flow_os_destroy_flow(flow));
17165 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
17167 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
17172 * Validate the batch counter support in root table.
17174 * Create a simple flow with invalid counter and drop action on root table to
17175 * validate if batch counter with offset on root table is supported or not.
17178 * Pointer to rte_eth_dev structure.
17181 * 0 on success, a negative errno value otherwise and rte_errno is set.
17184 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
17186 struct mlx5_priv *priv = dev->data->dev_private;
17187 struct mlx5_dev_ctx_shared *sh = priv->sh;
17188 struct mlx5_flow_dv_match_params mask = {
17189 .size = sizeof(mask.buf),
17191 struct mlx5_flow_dv_match_params value = {
17192 .size = sizeof(value.buf),
17194 struct mlx5dv_flow_matcher_attr dv_attr = {
17195 .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
17197 .match_criteria_enable = 0,
17198 .match_mask = (void *)&mask,
17200 void *actions[2] = { 0 };
17201 struct mlx5_flow_tbl_resource *tbl = NULL;
17202 struct mlx5_devx_obj *dcs = NULL;
17203 void *matcher = NULL;
17207 tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
17211 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
17214 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
17218 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
17219 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
17220 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
17224 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
17225 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
17229 * If batch counter with offset is not supported, the driver will not
17230 * validate the invalid offset value, flow create should success.
17231 * In this case, it means batch counter is not supported in root table.
17233 * Otherwise, if flow create is failed, counter offset is supported.
17236 DRV_LOG(INFO, "Batch counter is not supported in root "
17237 "table. Switch to fallback mode.");
17238 rte_errno = ENOTSUP;
17240 claim_zero(mlx5_flow_os_destroy_flow(flow));
17242 /* Check matcher to make sure validate fail at flow create. */
17243 if (!matcher || (matcher && errno != EINVAL))
17244 DRV_LOG(ERR, "Unexpected error in counter offset "
17245 "support detection");
17249 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
17251 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
17253 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
17255 claim_zero(mlx5_devx_cmd_destroy(dcs));
17260 * Query a devx counter.
17263 * Pointer to the Ethernet device structure.
17265 * Index to the flow counter.
17267 * Set to clear the counter statistics.
17269 * The statistics value of packets.
17270 * @param[out] bytes
17271 * The statistics value of bytes.
17274 * 0 on success, otherwise return -1.
17277 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
17278 uint64_t *pkts, uint64_t *bytes)
17280 struct mlx5_priv *priv = dev->data->dev_private;
17281 struct mlx5_flow_counter *cnt;
17282 uint64_t inn_pkts, inn_bytes;
17285 if (!priv->config.devx)
17288 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
17291 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
17292 *pkts = inn_pkts - cnt->hits;
17293 *bytes = inn_bytes - cnt->bytes;
17295 cnt->hits = inn_pkts;
17296 cnt->bytes = inn_bytes;
17302 * Get aged-out flows.
17305 * Pointer to the Ethernet device structure.
17306 * @param[in] context
17307 * The address of an array of pointers to the aged-out flows contexts.
17308 * @param[in] nb_contexts
17309 * The length of context array pointers.
17310 * @param[out] error
17311 * Perform verbose error reporting if not NULL. Initialized in case of
17315 * how many contexts get in success, otherwise negative errno value.
17316 * if nb_contexts is 0, return the amount of all aged contexts.
17317 * if nb_contexts is not 0 , return the amount of aged flows reported
17318 * in the context array.
17319 * @note: only stub for now
17322 flow_dv_get_aged_flows(struct rte_eth_dev *dev,
17324 uint32_t nb_contexts,
17325 struct rte_flow_error *error)
17327 struct mlx5_priv *priv = dev->data->dev_private;
17328 struct mlx5_age_info *age_info;
17329 struct mlx5_age_param *age_param;
17330 struct mlx5_flow_counter *counter;
17331 struct mlx5_aso_age_action *act;
17334 if (nb_contexts && !context)
17335 return rte_flow_error_set(error, EINVAL,
17336 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17337 NULL, "empty context");
17338 age_info = GET_PORT_AGE_INFO(priv);
17339 rte_spinlock_lock(&age_info->aged_sl);
17340 LIST_FOREACH(act, &age_info->aged_aso, next) {
17343 context[nb_flows - 1] =
17344 act->age_params.context;
17345 if (!(--nb_contexts))
17349 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
17352 age_param = MLX5_CNT_TO_AGE(counter);
17353 context[nb_flows - 1] = age_param->context;
17354 if (!(--nb_contexts))
17358 rte_spinlock_unlock(&age_info->aged_sl);
17359 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
17364 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
17367 flow_dv_counter_allocate(struct rte_eth_dev *dev)
17369 return flow_dv_counter_alloc(dev, 0);
17373 * Validate indirect action.
17374 * Dispatcher for action type specific validation.
17377 * Pointer to the Ethernet device structure.
17379 * Indirect action configuration.
17380 * @param[in] action
17381 * The indirect action object to validate.
17382 * @param[out] error
17383 * Perform verbose error reporting if not NULL. Initialized in case of
17387 * 0 on success, otherwise negative errno value.
17390 flow_dv_action_validate(struct rte_eth_dev *dev,
17391 const struct rte_flow_indir_action_conf *conf,
17392 const struct rte_flow_action *action,
17393 struct rte_flow_error *err)
17395 struct mlx5_priv *priv = dev->data->dev_private;
17397 RTE_SET_USED(conf);
17398 switch (action->type) {
17399 case RTE_FLOW_ACTION_TYPE_RSS:
17401 * priv->obj_ops is set according to driver capabilities.
17402 * When DevX capabilities are
17403 * sufficient, it is set to devx_obj_ops.
17404 * Otherwise, it is set to ibv_obj_ops.
17405 * ibv_obj_ops doesn't support ind_table_modify operation.
17406 * In this case the indirect RSS action can't be used.
17408 if (priv->obj_ops.ind_table_modify == NULL)
17409 return rte_flow_error_set
17411 RTE_FLOW_ERROR_TYPE_ACTION,
17413 "Indirect RSS action not supported");
17414 return mlx5_validate_action_rss(dev, action, err);
17415 case RTE_FLOW_ACTION_TYPE_AGE:
17416 if (!priv->sh->aso_age_mng)
17417 return rte_flow_error_set(err, ENOTSUP,
17418 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17420 "Indirect age action not supported");
17421 return flow_dv_validate_action_age(0, action, dev, err);
17422 case RTE_FLOW_ACTION_TYPE_COUNT:
17423 return flow_dv_validate_action_count(dev, true, 0, err);
17424 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17425 if (!priv->sh->ct_aso_en)
17426 return rte_flow_error_set(err, ENOTSUP,
17427 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17428 "ASO CT is not supported");
17429 return mlx5_validate_action_ct(dev, action->conf, err);
17431 return rte_flow_error_set(err, ENOTSUP,
17432 RTE_FLOW_ERROR_TYPE_ACTION,
17434 "action type not supported");
17439 * Check if the RSS configurations for colors of a meter policy match
17440 * each other, except the queues.
17443 * Pointer to the first RSS flow action.
17445 * Pointer to the second RSS flow action.
17448 * 0 on match, 1 on conflict.
17451 flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
17452 const struct rte_flow_action_rss *r2)
17456 if (r1->func != r2->func || r1->level != r2->level ||
17457 r1->types != r2->types || r1->key_len != r2->key_len ||
17458 memcmp(r1->key, r2->key, r1->key_len))
17464 * Validate the meter hierarchy chain for meter policy.
17467 * Pointer to the Ethernet device structure.
17468 * @param[in] meter_id
17470 * @param[in] action_flags
17471 * Holds the actions detected until now.
17472 * @param[out] is_rss
17474 * @param[out] hierarchy_domain
17475 * The domain bitmap for hierarchy policy.
17476 * @param[out] error
17477 * Perform verbose error reporting if not NULL. Initialized in case of
17481 * 0 on success, otherwise negative errno value with error set.
17484 flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
17486 uint64_t action_flags,
17488 uint8_t *hierarchy_domain,
17489 struct rte_mtr_error *error)
17491 struct mlx5_priv *priv = dev->data->dev_private;
17492 struct mlx5_flow_meter_info *fm;
17493 struct mlx5_flow_meter_policy *policy;
17496 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
17497 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
17498 return -rte_mtr_error_set(error, EINVAL,
17499 RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
17501 "Multiple fate actions not supported.");
17502 *hierarchy_domain = 0;
17504 fm = mlx5_flow_meter_find(priv, meter_id, NULL);
17506 return -rte_mtr_error_set(error, EINVAL,
17507 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17508 "Meter not found in meter hierarchy.");
17509 if (fm->def_policy)
17510 return -rte_mtr_error_set(error, EINVAL,
17511 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17512 "Non termination meter not supported in hierarchy.");
17513 policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
17514 MLX5_ASSERT(policy);
17516 * Only inherit the supported domains of the first meter in
17518 * One meter supports at least one domain.
17520 if (!*hierarchy_domain) {
17521 if (policy->transfer)
17522 *hierarchy_domain |=
17523 MLX5_MTR_DOMAIN_TRANSFER_BIT;
17524 if (policy->ingress)
17525 *hierarchy_domain |=
17526 MLX5_MTR_DOMAIN_INGRESS_BIT;
17527 if (policy->egress)
17528 *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
17530 if (!policy->is_hierarchy) {
17531 *is_rss = policy->is_rss;
17534 meter_id = policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id;
17535 if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
17536 return -rte_mtr_error_set(error, EINVAL,
17537 RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
17538 "Exceed max hierarchy meter number.");
17544 * Validate meter policy actions.
17545 * Dispatcher for action type specific validation.
17548 * Pointer to the Ethernet device structure.
17549 * @param[in] action
17550 * The meter policy action object to validate.
17552 * Attributes of flow to determine steering domain.
17553 * @param[out] error
17554 * Perform verbose error reporting if not NULL. Initialized in case of
17558 * 0 on success, otherwise negative errno value.
17561 flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
17562 const struct rte_flow_action *actions[RTE_COLORS],
17563 struct rte_flow_attr *attr,
17565 uint8_t *domain_bitmap,
17566 uint8_t *policy_mode,
17567 struct rte_mtr_error *error)
17569 struct mlx5_priv *priv = dev->data->dev_private;
17570 struct mlx5_dev_config *dev_conf = &priv->config;
17571 const struct rte_flow_action *act;
17572 uint64_t action_flags[RTE_COLORS] = {0};
17575 struct rte_flow_error flow_err;
17576 uint8_t domain_color[RTE_COLORS] = {0};
17577 uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
17578 uint8_t hierarchy_domain = 0;
17579 const struct rte_flow_action_meter *mtr;
17580 bool def_green = false;
17581 bool def_yellow = false;
17582 const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
17584 if (!priv->config.dv_esw_en)
17585 def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
17586 *domain_bitmap = def_domain;
17587 /* Red color could only support DROP action. */
17588 if (!actions[RTE_COLOR_RED] ||
17589 actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
17590 return -rte_mtr_error_set(error, ENOTSUP,
17591 RTE_MTR_ERROR_TYPE_METER_POLICY,
17592 NULL, "Red color only supports drop action.");
17594 * Check default policy actions:
17595 * Green / Yellow: no action, Red: drop action
17596 * Either G or Y will trigger default policy actions to be created.
17598 if (!actions[RTE_COLOR_GREEN] ||
17599 actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
17601 if (!actions[RTE_COLOR_YELLOW] ||
17602 actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
17604 if (def_green && def_yellow) {
17605 *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
17607 } else if (!def_green && def_yellow) {
17608 *policy_mode = MLX5_MTR_POLICY_MODE_OG;
17609 } else if (def_green && !def_yellow) {
17610 *policy_mode = MLX5_MTR_POLICY_MODE_OY;
17612 /* Set to empty string in case of NULL pointer access by user. */
17613 flow_err.message = "";
17614 for (i = 0; i < RTE_COLORS; i++) {
17616 for (action_flags[i] = 0, actions_n = 0;
17617 act && act->type != RTE_FLOW_ACTION_TYPE_END;
17619 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
17620 return -rte_mtr_error_set(error, ENOTSUP,
17621 RTE_MTR_ERROR_TYPE_METER_POLICY,
17622 NULL, "too many actions");
17623 switch (act->type) {
17624 case RTE_FLOW_ACTION_TYPE_PORT_ID:
17625 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17626 if (!priv->config.dv_esw_en)
17627 return -rte_mtr_error_set(error,
17629 RTE_MTR_ERROR_TYPE_METER_POLICY,
17630 NULL, "PORT action validate check"
17631 " fail for ESW disable");
17632 ret = flow_dv_validate_action_port_id(dev,
17634 act, attr, &flow_err);
17636 return -rte_mtr_error_set(error,
17638 RTE_MTR_ERROR_TYPE_METER_POLICY,
17639 NULL, flow_err.message ?
17641 "PORT action validate check fail");
17643 action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
17645 case RTE_FLOW_ACTION_TYPE_MARK:
17646 ret = flow_dv_validate_action_mark(dev, act,
17650 return -rte_mtr_error_set(error,
17652 RTE_MTR_ERROR_TYPE_METER_POLICY,
17653 NULL, flow_err.message ?
17655 "Mark action validate check fail");
17656 if (dev_conf->dv_xmeta_en !=
17657 MLX5_XMETA_MODE_LEGACY)
17658 return -rte_mtr_error_set(error,
17660 RTE_MTR_ERROR_TYPE_METER_POLICY,
17661 NULL, "Extend MARK action is "
17662 "not supported. Please try use "
17663 "default policy for meter.");
17664 action_flags[i] |= MLX5_FLOW_ACTION_MARK;
17667 case RTE_FLOW_ACTION_TYPE_SET_TAG:
17668 ret = flow_dv_validate_action_set_tag(dev,
17669 act, action_flags[i],
17672 return -rte_mtr_error_set(error,
17674 RTE_MTR_ERROR_TYPE_METER_POLICY,
17675 NULL, flow_err.message ?
17677 "Set tag action validate check fail");
17678 action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
17681 case RTE_FLOW_ACTION_TYPE_DROP:
17682 ret = mlx5_flow_validate_action_drop
17683 (action_flags[i], attr, &flow_err);
17685 return -rte_mtr_error_set(error,
17687 RTE_MTR_ERROR_TYPE_METER_POLICY,
17688 NULL, flow_err.message ?
17690 "Drop action validate check fail");
17691 action_flags[i] |= MLX5_FLOW_ACTION_DROP;
17694 case RTE_FLOW_ACTION_TYPE_QUEUE:
17696 * Check whether extensive
17697 * metadata feature is engaged.
17699 if (dev_conf->dv_flow_en &&
17700 (dev_conf->dv_xmeta_en !=
17701 MLX5_XMETA_MODE_LEGACY) &&
17702 mlx5_flow_ext_mreg_supported(dev))
17703 return -rte_mtr_error_set(error,
17705 RTE_MTR_ERROR_TYPE_METER_POLICY,
17706 NULL, "Queue action with meta "
17707 "is not supported. Please try use "
17708 "default policy for meter.");
17709 ret = mlx5_flow_validate_action_queue(act,
17710 action_flags[i], dev,
17713 return -rte_mtr_error_set(error,
17715 RTE_MTR_ERROR_TYPE_METER_POLICY,
17716 NULL, flow_err.message ?
17718 "Queue action validate check fail");
17719 action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
17722 case RTE_FLOW_ACTION_TYPE_RSS:
17723 if (dev_conf->dv_flow_en &&
17724 (dev_conf->dv_xmeta_en !=
17725 MLX5_XMETA_MODE_LEGACY) &&
17726 mlx5_flow_ext_mreg_supported(dev))
17727 return -rte_mtr_error_set(error,
17729 RTE_MTR_ERROR_TYPE_METER_POLICY,
17730 NULL, "RSS action with meta "
17731 "is not supported. Please try use "
17732 "default policy for meter.");
17733 ret = mlx5_validate_action_rss(dev, act,
17736 return -rte_mtr_error_set(error,
17738 RTE_MTR_ERROR_TYPE_METER_POLICY,
17739 NULL, flow_err.message ?
17741 "RSS action validate check fail");
17742 action_flags[i] |= MLX5_FLOW_ACTION_RSS;
17744 /* Either G or Y will set the RSS. */
17745 rss_color[i] = act->conf;
17747 case RTE_FLOW_ACTION_TYPE_JUMP:
17748 ret = flow_dv_validate_action_jump(dev,
17749 NULL, act, action_flags[i],
17750 attr, true, &flow_err);
17752 return -rte_mtr_error_set(error,
17754 RTE_MTR_ERROR_TYPE_METER_POLICY,
17755 NULL, flow_err.message ?
17757 "Jump action validate check fail");
17759 action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
17762 * Only the last meter in the hierarchy will support
17763 * the YELLOW color steering. Then in the meter policy
17764 * actions list, there should be no other meter inside.
17766 case RTE_FLOW_ACTION_TYPE_METER:
17767 if (i != RTE_COLOR_GREEN)
17768 return -rte_mtr_error_set(error,
17770 RTE_MTR_ERROR_TYPE_METER_POLICY,
17772 "Meter hierarchy only supports GREEN color.");
17773 if (*policy_mode != MLX5_MTR_POLICY_MODE_OG)
17774 return -rte_mtr_error_set(error,
17776 RTE_MTR_ERROR_TYPE_METER_POLICY,
17778 "No yellow policy should be provided in meter hierarchy.");
17780 ret = flow_dv_validate_policy_mtr_hierarchy(dev,
17790 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
17793 return -rte_mtr_error_set(error, ENOTSUP,
17794 RTE_MTR_ERROR_TYPE_METER_POLICY,
17796 "Doesn't support optional action");
17799 if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID)
17800 domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
17801 else if ((action_flags[i] &
17802 (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
17803 (action_flags[i] & MLX5_FLOW_ACTION_MARK))
17805 * Only support MLX5_XMETA_MODE_LEGACY
17806 * so MARK action is only in ingress domain.
17808 domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
17810 domain_color[i] = def_domain;
17811 if (action_flags[i] &
17812 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
17813 domain_color[i] &= hierarchy_domain;
17815 * Non-termination actions only support NIC Tx domain.
17816 * The adjustion should be skipped when there is no
17817 * action or only END is provided. The default domains
17818 * bit-mask is set to find the MIN intersection.
17819 * The action flags checking should also be skipped.
17821 if ((def_green && i == RTE_COLOR_GREEN) ||
17822 (def_yellow && i == RTE_COLOR_YELLOW))
17825 * Validate the drop action mutual exclusion
17826 * with other actions. Drop action is mutually-exclusive
17827 * with any other action, except for Count action.
17829 if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
17830 (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
17831 return -rte_mtr_error_set(error, ENOTSUP,
17832 RTE_MTR_ERROR_TYPE_METER_POLICY,
17833 NULL, "Drop action is mutually-exclusive "
17834 "with any other action");
17836 /* Eswitch has few restrictions on using items and actions */
17837 if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
17838 if (!mlx5_flow_ext_mreg_supported(dev) &&
17839 action_flags[i] & MLX5_FLOW_ACTION_MARK)
17840 return -rte_mtr_error_set(error, ENOTSUP,
17841 RTE_MTR_ERROR_TYPE_METER_POLICY,
17842 NULL, "unsupported action MARK");
17843 if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
17844 return -rte_mtr_error_set(error, ENOTSUP,
17845 RTE_MTR_ERROR_TYPE_METER_POLICY,
17846 NULL, "unsupported action QUEUE");
17847 if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
17848 return -rte_mtr_error_set(error, ENOTSUP,
17849 RTE_MTR_ERROR_TYPE_METER_POLICY,
17850 NULL, "unsupported action RSS");
17851 if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
17852 return -rte_mtr_error_set(error, ENOTSUP,
17853 RTE_MTR_ERROR_TYPE_METER_POLICY,
17854 NULL, "no fate action is found");
17856 if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
17857 (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
17858 if ((domain_color[i] &
17859 MLX5_MTR_DOMAIN_EGRESS_BIT))
17861 MLX5_MTR_DOMAIN_EGRESS_BIT;
17863 return -rte_mtr_error_set(error,
17865 RTE_MTR_ERROR_TYPE_METER_POLICY,
17867 "no fate action is found");
17871 /* If both colors have RSS, the attributes should be the same. */
17872 if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
17873 rss_color[RTE_COLOR_YELLOW]))
17874 return -rte_mtr_error_set(error, EINVAL,
17875 RTE_MTR_ERROR_TYPE_METER_POLICY,
17876 NULL, "policy RSS attr conflict");
17877 if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
17879 /* "domain_color[C]" is non-zero for each color, default is ALL. */
17880 if (!def_green && !def_yellow &&
17881 domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
17882 !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
17883 !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
17884 return -rte_mtr_error_set(error, EINVAL,
17885 RTE_MTR_ERROR_TYPE_METER_POLICY,
17886 NULL, "policy domains conflict");
17888 * At least one color policy is listed in the actions, the domains
17889 * to be supported should be the intersection.
17891 *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
17892 domain_color[RTE_COLOR_YELLOW];
17897 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
17899 struct mlx5_priv *priv = dev->data->dev_private;
17902 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
17903 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
17908 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
17909 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
17913 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
17914 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
17921 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
17922 .validate = flow_dv_validate,
17923 .prepare = flow_dv_prepare,
17924 .translate = flow_dv_translate,
17925 .apply = flow_dv_apply,
17926 .remove = flow_dv_remove,
17927 .destroy = flow_dv_destroy,
17928 .query = flow_dv_query,
17929 .create_mtr_tbls = flow_dv_create_mtr_tbls,
17930 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
17931 .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
17932 .create_meter = flow_dv_mtr_alloc,
17933 .free_meter = flow_dv_aso_mtr_release_to_pool,
17934 .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
17935 .create_mtr_acts = flow_dv_create_mtr_policy_acts,
17936 .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
17937 .create_policy_rules = flow_dv_create_policy_rules,
17938 .destroy_policy_rules = flow_dv_destroy_policy_rules,
17939 .create_def_policy = flow_dv_create_def_policy,
17940 .destroy_def_policy = flow_dv_destroy_def_policy,
17941 .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
17942 .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
17943 .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
17944 .counter_alloc = flow_dv_counter_allocate,
17945 .counter_free = flow_dv_counter_free,
17946 .counter_query = flow_dv_counter_query,
17947 .get_aged_flows = flow_dv_get_aged_flows,
17948 .action_validate = flow_dv_action_validate,
17949 .action_create = flow_dv_action_create,
17950 .action_destroy = flow_dv_action_destroy,
17951 .action_update = flow_dv_action_update,
17952 .action_query = flow_dv_action_query,
17953 .sync_domain = flow_dv_sync_domain,
17956 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */