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, int inherit)
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:
1445 return inherit < 0 ? 0 : inherit;
1453 mlx5_flow_field_id_to_modify_info
1454 (const struct rte_flow_action_modify_data *data,
1455 struct field_modify_info *info, uint32_t *mask,
1456 uint32_t width, uint32_t *shift, struct rte_eth_dev *dev,
1457 const struct rte_flow_attr *attr, struct rte_flow_error *error)
1459 struct mlx5_priv *priv = dev->data->dev_private;
1463 switch (data->field) {
1464 case RTE_FLOW_FIELD_START:
1465 /* not supported yet */
1468 case RTE_FLOW_FIELD_MAC_DST:
1469 off = data->offset > 16 ? data->offset - 16 : 0;
1471 if (data->offset < 16) {
1472 info[idx] = (struct field_modify_info){2, 4,
1473 MLX5_MODI_OUT_DMAC_15_0};
1475 mask[idx] = rte_cpu_to_be_16(0xffff >>
1479 mask[idx] = RTE_BE16(0xffff);
1486 info[idx] = (struct field_modify_info){4, 0,
1487 MLX5_MODI_OUT_DMAC_47_16};
1488 mask[idx] = rte_cpu_to_be_32((0xffffffff >>
1489 (32 - width)) << off);
1491 if (data->offset < 16)
1492 info[idx++] = (struct field_modify_info){2, 4,
1493 MLX5_MODI_OUT_DMAC_15_0};
1494 info[idx] = (struct field_modify_info){4, 0,
1495 MLX5_MODI_OUT_DMAC_47_16};
1498 case RTE_FLOW_FIELD_MAC_SRC:
1499 off = data->offset > 16 ? data->offset - 16 : 0;
1501 if (data->offset < 16) {
1502 info[idx] = (struct field_modify_info){2, 4,
1503 MLX5_MODI_OUT_SMAC_15_0};
1505 mask[idx] = rte_cpu_to_be_16(0xffff >>
1509 mask[idx] = RTE_BE16(0xffff);
1516 info[idx] = (struct field_modify_info){4, 0,
1517 MLX5_MODI_OUT_SMAC_47_16};
1518 mask[idx] = rte_cpu_to_be_32((0xffffffff >>
1519 (32 - width)) << off);
1521 if (data->offset < 16)
1522 info[idx++] = (struct field_modify_info){2, 4,
1523 MLX5_MODI_OUT_SMAC_15_0};
1524 info[idx] = (struct field_modify_info){4, 0,
1525 MLX5_MODI_OUT_SMAC_47_16};
1528 case RTE_FLOW_FIELD_VLAN_TYPE:
1529 /* not supported yet */
1531 case RTE_FLOW_FIELD_VLAN_ID:
1532 info[idx] = (struct field_modify_info){2, 0,
1533 MLX5_MODI_OUT_FIRST_VID};
1535 mask[idx] = rte_cpu_to_be_16(0x0fff >> (12 - width));
1537 case RTE_FLOW_FIELD_MAC_TYPE:
1538 info[idx] = (struct field_modify_info){2, 0,
1539 MLX5_MODI_OUT_ETHERTYPE};
1541 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1543 case RTE_FLOW_FIELD_IPV4_DSCP:
1544 info[idx] = (struct field_modify_info){1, 0,
1545 MLX5_MODI_OUT_IP_DSCP};
1547 mask[idx] = 0x3f >> (6 - width);
1549 case RTE_FLOW_FIELD_IPV4_TTL:
1550 info[idx] = (struct field_modify_info){1, 0,
1551 MLX5_MODI_OUT_IPV4_TTL};
1553 mask[idx] = 0xff >> (8 - width);
1555 case RTE_FLOW_FIELD_IPV4_SRC:
1556 info[idx] = (struct field_modify_info){4, 0,
1557 MLX5_MODI_OUT_SIPV4};
1559 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1562 case RTE_FLOW_FIELD_IPV4_DST:
1563 info[idx] = (struct field_modify_info){4, 0,
1564 MLX5_MODI_OUT_DIPV4};
1566 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1569 case RTE_FLOW_FIELD_IPV6_DSCP:
1570 info[idx] = (struct field_modify_info){1, 0,
1571 MLX5_MODI_OUT_IP_DSCP};
1573 mask[idx] = 0x3f >> (6 - width);
1575 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1576 info[idx] = (struct field_modify_info){1, 0,
1577 MLX5_MODI_OUT_IPV6_HOPLIMIT};
1579 mask[idx] = 0xff >> (8 - width);
1581 case RTE_FLOW_FIELD_IPV6_SRC:
1583 if (data->offset < 32) {
1584 info[idx] = (struct field_modify_info){4, 12,
1585 MLX5_MODI_OUT_SIPV6_31_0};
1588 rte_cpu_to_be_32(0xffffffff >>
1592 mask[idx] = RTE_BE32(0xffffffff);
1599 if (data->offset < 64) {
1600 info[idx] = (struct field_modify_info){4, 8,
1601 MLX5_MODI_OUT_SIPV6_63_32};
1604 rte_cpu_to_be_32(0xffffffff >>
1608 mask[idx] = RTE_BE32(0xffffffff);
1615 if (data->offset < 96) {
1616 info[idx] = (struct field_modify_info){4, 4,
1617 MLX5_MODI_OUT_SIPV6_95_64};
1620 rte_cpu_to_be_32(0xffffffff >>
1624 mask[idx] = RTE_BE32(0xffffffff);
1631 info[idx] = (struct field_modify_info){4, 0,
1632 MLX5_MODI_OUT_SIPV6_127_96};
1633 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1636 if (data->offset < 32)
1637 info[idx++] = (struct field_modify_info){4, 12,
1638 MLX5_MODI_OUT_SIPV6_31_0};
1639 if (data->offset < 64)
1640 info[idx++] = (struct field_modify_info){4, 8,
1641 MLX5_MODI_OUT_SIPV6_63_32};
1642 if (data->offset < 96)
1643 info[idx++] = (struct field_modify_info){4, 4,
1644 MLX5_MODI_OUT_SIPV6_95_64};
1645 if (data->offset < 128)
1646 info[idx++] = (struct field_modify_info){4, 0,
1647 MLX5_MODI_OUT_SIPV6_127_96};
1650 case RTE_FLOW_FIELD_IPV6_DST:
1652 if (data->offset < 32) {
1653 info[idx] = (struct field_modify_info){4, 12,
1654 MLX5_MODI_OUT_DIPV6_31_0};
1657 rte_cpu_to_be_32(0xffffffff >>
1661 mask[idx] = RTE_BE32(0xffffffff);
1668 if (data->offset < 64) {
1669 info[idx] = (struct field_modify_info){4, 8,
1670 MLX5_MODI_OUT_DIPV6_63_32};
1673 rte_cpu_to_be_32(0xffffffff >>
1677 mask[idx] = RTE_BE32(0xffffffff);
1684 if (data->offset < 96) {
1685 info[idx] = (struct field_modify_info){4, 4,
1686 MLX5_MODI_OUT_DIPV6_95_64};
1689 rte_cpu_to_be_32(0xffffffff >>
1693 mask[idx] = RTE_BE32(0xffffffff);
1700 info[idx] = (struct field_modify_info){4, 0,
1701 MLX5_MODI_OUT_DIPV6_127_96};
1702 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1705 if (data->offset < 32)
1706 info[idx++] = (struct field_modify_info){4, 12,
1707 MLX5_MODI_OUT_DIPV6_31_0};
1708 if (data->offset < 64)
1709 info[idx++] = (struct field_modify_info){4, 8,
1710 MLX5_MODI_OUT_DIPV6_63_32};
1711 if (data->offset < 96)
1712 info[idx++] = (struct field_modify_info){4, 4,
1713 MLX5_MODI_OUT_DIPV6_95_64};
1714 if (data->offset < 128)
1715 info[idx++] = (struct field_modify_info){4, 0,
1716 MLX5_MODI_OUT_DIPV6_127_96};
1719 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1720 info[idx] = (struct field_modify_info){2, 0,
1721 MLX5_MODI_OUT_TCP_SPORT};
1723 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1725 case RTE_FLOW_FIELD_TCP_PORT_DST:
1726 info[idx] = (struct field_modify_info){2, 0,
1727 MLX5_MODI_OUT_TCP_DPORT};
1729 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1731 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1732 info[idx] = (struct field_modify_info){4, 0,
1733 MLX5_MODI_OUT_TCP_SEQ_NUM};
1735 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1738 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1739 info[idx] = (struct field_modify_info){4, 0,
1740 MLX5_MODI_OUT_TCP_ACK_NUM};
1742 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1745 case RTE_FLOW_FIELD_TCP_FLAGS:
1746 info[idx] = (struct field_modify_info){2, 0,
1747 MLX5_MODI_OUT_TCP_FLAGS};
1749 mask[idx] = rte_cpu_to_be_16(0x1ff >> (9 - width));
1751 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1752 info[idx] = (struct field_modify_info){2, 0,
1753 MLX5_MODI_OUT_UDP_SPORT};
1755 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1757 case RTE_FLOW_FIELD_UDP_PORT_DST:
1758 info[idx] = (struct field_modify_info){2, 0,
1759 MLX5_MODI_OUT_UDP_DPORT};
1761 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1763 case RTE_FLOW_FIELD_VXLAN_VNI:
1764 /* not supported yet */
1766 case RTE_FLOW_FIELD_GENEVE_VNI:
1767 /* not supported yet*/
1769 case RTE_FLOW_FIELD_GTP_TEID:
1770 info[idx] = (struct field_modify_info){4, 0,
1771 MLX5_MODI_GTP_TEID};
1773 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1776 case RTE_FLOW_FIELD_TAG:
1778 int reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
1779 data->level, error);
1782 MLX5_ASSERT(reg != REG_NON);
1783 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1784 info[idx] = (struct field_modify_info){4, 0,
1788 rte_cpu_to_be_32(0xffffffff >>
1792 case RTE_FLOW_FIELD_MARK:
1794 uint32_t mark_mask = priv->sh->dv_mark_mask;
1795 uint32_t mark_count = __builtin_popcount(mark_mask);
1796 int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
1800 MLX5_ASSERT(reg != REG_NON);
1801 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1802 info[idx] = (struct field_modify_info){4, 0,
1805 mask[idx] = rte_cpu_to_be_32((mark_mask >>
1806 (mark_count - width)) & mark_mask);
1809 case RTE_FLOW_FIELD_META:
1811 uint32_t meta_mask = priv->sh->dv_meta_mask;
1812 uint32_t meta_count = __builtin_popcount(meta_mask);
1814 rte_cpu_to_be_32(priv->sh->dv_regc0_mask);
1815 uint32_t shl_c0 = rte_bsf32(msk_c0);
1816 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1819 MLX5_ASSERT(reg != REG_NON);
1820 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1823 info[idx] = (struct field_modify_info){4, 0,
1826 mask[idx] = rte_cpu_to_be_32((meta_mask >>
1827 (meta_count - width)) & meta_mask);
1830 case RTE_FLOW_FIELD_POINTER:
1831 case RTE_FLOW_FIELD_VALUE:
1839 * Convert modify_field action to DV specification.
1842 * Pointer to the rte_eth_dev structure.
1843 * @param[in,out] resource
1844 * Pointer to the modify-header resource.
1846 * Pointer to action specification.
1848 * Attributes of flow that includes this item.
1850 * Pointer to the error structure.
1853 * 0 on success, a negative errno value otherwise and rte_errno is set.
1856 flow_dv_convert_action_modify_field
1857 (struct rte_eth_dev *dev,
1858 struct mlx5_flow_dv_modify_hdr_resource *resource,
1859 const struct rte_flow_action *action,
1860 const struct rte_flow_attr *attr,
1861 struct rte_flow_error *error)
1863 const struct rte_flow_action_modify_field *conf =
1864 (const struct rte_flow_action_modify_field *)(action->conf);
1865 struct rte_flow_item item = {
1869 struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1871 struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1873 uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1877 if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1878 conf->src.field == RTE_FLOW_FIELD_VALUE) {
1879 type = MLX5_MODIFICATION_TYPE_SET;
1880 /** For SET fill the destination field (field) first. */
1881 mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1882 conf->width, &shift, dev,
1884 item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
1885 (void *)(uintptr_t)conf->src.pvalue :
1886 (void *)(uintptr_t)&conf->src.value;
1888 type = MLX5_MODIFICATION_TYPE_COPY;
1889 /** For COPY fill the destination field (dcopy) without mask. */
1890 mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1891 conf->width, &shift, dev,
1893 /** Then construct the source field (field) with mask. */
1894 mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1895 conf->width, &shift,
1899 return flow_dv_convert_modify_action(&item,
1900 field, dcopy, resource, type, error);
1904 * Validate MARK item.
1907 * Pointer to the rte_eth_dev structure.
1909 * Item specification.
1911 * Attributes of flow that includes this item.
1913 * Pointer to error structure.
1916 * 0 on success, a negative errno value otherwise and rte_errno is set.
1919 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1920 const struct rte_flow_item *item,
1921 const struct rte_flow_attr *attr __rte_unused,
1922 struct rte_flow_error *error)
1924 struct mlx5_priv *priv = dev->data->dev_private;
1925 struct mlx5_dev_config *config = &priv->config;
1926 const struct rte_flow_item_mark *spec = item->spec;
1927 const struct rte_flow_item_mark *mask = item->mask;
1928 const struct rte_flow_item_mark nic_mask = {
1929 .id = priv->sh->dv_mark_mask,
1933 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1934 return rte_flow_error_set(error, ENOTSUP,
1935 RTE_FLOW_ERROR_TYPE_ITEM, item,
1936 "extended metadata feature"
1938 if (!mlx5_flow_ext_mreg_supported(dev))
1939 return rte_flow_error_set(error, ENOTSUP,
1940 RTE_FLOW_ERROR_TYPE_ITEM, item,
1941 "extended metadata register"
1942 " isn't supported");
1944 return rte_flow_error_set(error, ENOTSUP,
1945 RTE_FLOW_ERROR_TYPE_ITEM, item,
1946 "extended metadata register"
1947 " isn't available");
1948 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1952 return rte_flow_error_set(error, EINVAL,
1953 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1955 "data cannot be empty");
1956 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1957 return rte_flow_error_set(error, EINVAL,
1958 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1960 "mark id exceeds the limit");
1964 return rte_flow_error_set(error, EINVAL,
1965 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1966 "mask cannot be zero");
1968 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1969 (const uint8_t *)&nic_mask,
1970 sizeof(struct rte_flow_item_mark),
1971 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1978 * Validate META item.
1981 * Pointer to the rte_eth_dev structure.
1983 * Item specification.
1985 * Attributes of flow that includes this item.
1987 * Pointer to error structure.
1990 * 0 on success, a negative errno value otherwise and rte_errno is set.
1993 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1994 const struct rte_flow_item *item,
1995 const struct rte_flow_attr *attr,
1996 struct rte_flow_error *error)
1998 struct mlx5_priv *priv = dev->data->dev_private;
1999 struct mlx5_dev_config *config = &priv->config;
2000 const struct rte_flow_item_meta *spec = item->spec;
2001 const struct rte_flow_item_meta *mask = item->mask;
2002 struct rte_flow_item_meta nic_mask = {
2009 return rte_flow_error_set(error, EINVAL,
2010 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2012 "data cannot be empty");
2013 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2014 if (!mlx5_flow_ext_mreg_supported(dev))
2015 return rte_flow_error_set(error, ENOTSUP,
2016 RTE_FLOW_ERROR_TYPE_ITEM, item,
2017 "extended metadata register"
2018 " isn't supported");
2019 reg = flow_dv_get_metadata_reg(dev, attr, error);
2023 return rte_flow_error_set(error, ENOTSUP,
2024 RTE_FLOW_ERROR_TYPE_ITEM, item,
2025 "unavalable extended metadata register");
2027 return rte_flow_error_set(error, ENOTSUP,
2028 RTE_FLOW_ERROR_TYPE_ITEM, item,
2032 nic_mask.data = priv->sh->dv_meta_mask;
2035 return rte_flow_error_set(error, ENOTSUP,
2036 RTE_FLOW_ERROR_TYPE_ITEM, item,
2037 "extended metadata feature "
2038 "should be enabled when "
2039 "meta item is requested "
2040 "with e-switch mode ");
2042 return rte_flow_error_set(error, ENOTSUP,
2043 RTE_FLOW_ERROR_TYPE_ITEM, item,
2044 "match on metadata for ingress "
2045 "is not supported in legacy "
2049 mask = &rte_flow_item_meta_mask;
2051 return rte_flow_error_set(error, EINVAL,
2052 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2053 "mask cannot be zero");
2055 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2056 (const uint8_t *)&nic_mask,
2057 sizeof(struct rte_flow_item_meta),
2058 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2063 * Validate TAG item.
2066 * Pointer to the rte_eth_dev structure.
2068 * Item specification.
2070 * Attributes of flow that includes this item.
2072 * Pointer to error structure.
2075 * 0 on success, a negative errno value otherwise and rte_errno is set.
2078 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2079 const struct rte_flow_item *item,
2080 const struct rte_flow_attr *attr __rte_unused,
2081 struct rte_flow_error *error)
2083 const struct rte_flow_item_tag *spec = item->spec;
2084 const struct rte_flow_item_tag *mask = item->mask;
2085 const struct rte_flow_item_tag nic_mask = {
2086 .data = RTE_BE32(UINT32_MAX),
2091 if (!mlx5_flow_ext_mreg_supported(dev))
2092 return rte_flow_error_set(error, ENOTSUP,
2093 RTE_FLOW_ERROR_TYPE_ITEM, item,
2094 "extensive metadata register"
2095 " isn't supported");
2097 return rte_flow_error_set(error, EINVAL,
2098 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2100 "data cannot be empty");
2102 mask = &rte_flow_item_tag_mask;
2104 return rte_flow_error_set(error, EINVAL,
2105 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2106 "mask cannot be zero");
2108 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2109 (const uint8_t *)&nic_mask,
2110 sizeof(struct rte_flow_item_tag),
2111 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2114 if (mask->index != 0xff)
2115 return rte_flow_error_set(error, EINVAL,
2116 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2117 "partial mask for tag index"
2118 " is not supported");
2119 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2122 MLX5_ASSERT(ret != REG_NON);
2127 * Validate vport item.
2130 * Pointer to the rte_eth_dev structure.
2132 * Item specification.
2134 * Attributes of flow that includes this item.
2135 * @param[in] item_flags
2136 * Bit-fields that holds the items detected until now.
2138 * Pointer to error structure.
2141 * 0 on success, a negative errno value otherwise and rte_errno is set.
2144 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2145 const struct rte_flow_item *item,
2146 const struct rte_flow_attr *attr,
2147 uint64_t item_flags,
2148 struct rte_flow_error *error)
2150 const struct rte_flow_item_port_id *spec = item->spec;
2151 const struct rte_flow_item_port_id *mask = item->mask;
2152 const struct rte_flow_item_port_id switch_mask = {
2155 struct mlx5_priv *esw_priv;
2156 struct mlx5_priv *dev_priv;
2159 if (!attr->transfer)
2160 return rte_flow_error_set(error, EINVAL,
2161 RTE_FLOW_ERROR_TYPE_ITEM,
2163 "match on port id is valid only"
2164 " when transfer flag is enabled");
2165 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2166 return rte_flow_error_set(error, ENOTSUP,
2167 RTE_FLOW_ERROR_TYPE_ITEM, item,
2168 "multiple source ports are not"
2171 mask = &switch_mask;
2172 if (mask->id != 0xffffffff)
2173 return rte_flow_error_set(error, ENOTSUP,
2174 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2176 "no support for partial mask on"
2178 ret = mlx5_flow_item_acceptable
2179 (item, (const uint8_t *)mask,
2180 (const uint8_t *)&rte_flow_item_port_id_mask,
2181 sizeof(struct rte_flow_item_port_id),
2182 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2187 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2189 return rte_flow_error_set(error, rte_errno,
2190 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2191 "failed to obtain E-Switch info for"
2193 dev_priv = mlx5_dev_to_eswitch_info(dev);
2195 return rte_flow_error_set(error, rte_errno,
2196 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2198 "failed to obtain E-Switch info");
2199 if (esw_priv->domain_id != dev_priv->domain_id)
2200 return rte_flow_error_set(error, EINVAL,
2201 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2202 "cannot match on a port from a"
2203 " different E-Switch");
2208 * Validate VLAN item.
2211 * Item specification.
2212 * @param[in] item_flags
2213 * Bit-fields that holds the items detected until now.
2215 * Ethernet device flow is being created on.
2217 * Pointer to error structure.
2220 * 0 on success, a negative errno value otherwise and rte_errno is set.
2223 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2224 uint64_t item_flags,
2225 struct rte_eth_dev *dev,
2226 struct rte_flow_error *error)
2228 const struct rte_flow_item_vlan *mask = item->mask;
2229 const struct rte_flow_item_vlan nic_mask = {
2230 .tci = RTE_BE16(UINT16_MAX),
2231 .inner_type = RTE_BE16(UINT16_MAX),
2234 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2236 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2237 MLX5_FLOW_LAYER_INNER_L4) :
2238 (MLX5_FLOW_LAYER_OUTER_L3 |
2239 MLX5_FLOW_LAYER_OUTER_L4);
2240 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2241 MLX5_FLOW_LAYER_OUTER_VLAN;
2243 if (item_flags & vlanm)
2244 return rte_flow_error_set(error, EINVAL,
2245 RTE_FLOW_ERROR_TYPE_ITEM, item,
2246 "multiple VLAN layers not supported");
2247 else if ((item_flags & l34m) != 0)
2248 return rte_flow_error_set(error, EINVAL,
2249 RTE_FLOW_ERROR_TYPE_ITEM, item,
2250 "VLAN cannot follow L3/L4 layer");
2252 mask = &rte_flow_item_vlan_mask;
2253 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2254 (const uint8_t *)&nic_mask,
2255 sizeof(struct rte_flow_item_vlan),
2256 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2259 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2260 struct mlx5_priv *priv = dev->data->dev_private;
2262 if (priv->vmwa_context) {
2264 * Non-NULL context means we have a virtual machine
2265 * and SR-IOV enabled, we have to create VLAN interface
2266 * to make hypervisor to setup E-Switch vport
2267 * context correctly. We avoid creating the multiple
2268 * VLAN interfaces, so we cannot support VLAN tag mask.
2270 return rte_flow_error_set(error, EINVAL,
2271 RTE_FLOW_ERROR_TYPE_ITEM,
2273 "VLAN tag mask is not"
2274 " supported in virtual"
2282 * GTP flags are contained in 1 byte of the format:
2283 * -------------------------------------------
2284 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2285 * |-----------------------------------------|
2286 * | value | Version | PT | Res | E | S | PN |
2287 * -------------------------------------------
2289 * Matching is supported only for GTP flags E, S, PN.
2291 #define MLX5_GTP_FLAGS_MASK 0x07
2294 * Validate GTP item.
2297 * Pointer to the rte_eth_dev structure.
2299 * Item specification.
2300 * @param[in] item_flags
2301 * Bit-fields that holds the items detected until now.
2303 * Pointer to error structure.
2306 * 0 on success, a negative errno value otherwise and rte_errno is set.
2309 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2310 const struct rte_flow_item *item,
2311 uint64_t item_flags,
2312 struct rte_flow_error *error)
2314 struct mlx5_priv *priv = dev->data->dev_private;
2315 const struct rte_flow_item_gtp *spec = item->spec;
2316 const struct rte_flow_item_gtp *mask = item->mask;
2317 const struct rte_flow_item_gtp nic_mask = {
2318 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
2320 .teid = RTE_BE32(0xffffffff),
2323 if (!priv->config.hca_attr.tunnel_stateless_gtp)
2324 return rte_flow_error_set(error, ENOTSUP,
2325 RTE_FLOW_ERROR_TYPE_ITEM, item,
2326 "GTP support is not enabled");
2327 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2328 return rte_flow_error_set(error, ENOTSUP,
2329 RTE_FLOW_ERROR_TYPE_ITEM, item,
2330 "multiple tunnel layers not"
2332 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2333 return rte_flow_error_set(error, EINVAL,
2334 RTE_FLOW_ERROR_TYPE_ITEM, item,
2335 "no outer UDP layer found");
2337 mask = &rte_flow_item_gtp_mask;
2338 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
2339 return rte_flow_error_set(error, ENOTSUP,
2340 RTE_FLOW_ERROR_TYPE_ITEM, item,
2341 "Match is supported for GTP"
2343 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2344 (const uint8_t *)&nic_mask,
2345 sizeof(struct rte_flow_item_gtp),
2346 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2350 * Validate GTP PSC item.
2353 * Item specification.
2354 * @param[in] last_item
2355 * Previous validated item in the pattern items.
2356 * @param[in] gtp_item
2357 * Previous GTP item specification.
2359 * Pointer to flow attributes.
2361 * Pointer to error structure.
2364 * 0 on success, a negative errno value otherwise and rte_errno is set.
2367 flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2369 const struct rte_flow_item *gtp_item,
2370 const struct rte_flow_attr *attr,
2371 struct rte_flow_error *error)
2373 const struct rte_flow_item_gtp *gtp_spec;
2374 const struct rte_flow_item_gtp *gtp_mask;
2375 const struct rte_flow_item_gtp_psc *mask;
2376 const struct rte_flow_item_gtp_psc nic_mask = {
2381 if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2382 return rte_flow_error_set
2383 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2384 "GTP PSC item must be preceded with GTP item");
2385 gtp_spec = gtp_item->spec;
2386 gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2387 /* GTP spec and E flag is requested to match zero. */
2389 (gtp_mask->v_pt_rsv_flags &
2390 ~gtp_spec->v_pt_rsv_flags & MLX5_GTP_EXT_HEADER_FLAG))
2391 return rte_flow_error_set
2392 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2393 "GTP E flag must be 1 to match GTP PSC");
2394 /* Check the flow is not created in group zero. */
2395 if (!attr->transfer && !attr->group)
2396 return rte_flow_error_set
2397 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2398 "GTP PSC is not supported for group 0");
2399 /* GTP spec is here and E flag is requested to match zero. */
2402 mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2403 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2404 (const uint8_t *)&nic_mask,
2405 sizeof(struct rte_flow_item_gtp_psc),
2406 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2410 * Validate IPV4 item.
2411 * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2412 * add specific validation of fragment_offset field,
2415 * Item specification.
2416 * @param[in] item_flags
2417 * Bit-fields that holds the items detected until now.
2419 * Pointer to error structure.
2422 * 0 on success, a negative errno value otherwise and rte_errno is set.
2425 flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
2426 const struct rte_flow_item *item,
2427 uint64_t item_flags, uint64_t last_item,
2428 uint16_t ether_type, struct rte_flow_error *error)
2431 struct mlx5_priv *priv = dev->data->dev_private;
2432 const struct rte_flow_item_ipv4 *spec = item->spec;
2433 const struct rte_flow_item_ipv4 *last = item->last;
2434 const struct rte_flow_item_ipv4 *mask = item->mask;
2435 rte_be16_t fragment_offset_spec = 0;
2436 rte_be16_t fragment_offset_last = 0;
2437 struct rte_flow_item_ipv4 nic_ipv4_mask = {
2439 .src_addr = RTE_BE32(0xffffffff),
2440 .dst_addr = RTE_BE32(0xffffffff),
2441 .type_of_service = 0xff,
2442 .fragment_offset = RTE_BE16(0xffff),
2443 .next_proto_id = 0xff,
2444 .time_to_live = 0xff,
2448 if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
2449 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2450 bool ihl_cap = !tunnel ? priv->config.hca_attr.outer_ipv4_ihl :
2451 priv->config.hca_attr.inner_ipv4_ihl;
2453 return rte_flow_error_set(error, ENOTSUP,
2454 RTE_FLOW_ERROR_TYPE_ITEM,
2456 "IPV4 ihl offload not supported");
2457 nic_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
2459 ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2460 ether_type, &nic_ipv4_mask,
2461 MLX5_ITEM_RANGE_ACCEPTED, error);
2465 fragment_offset_spec = spec->hdr.fragment_offset &
2466 mask->hdr.fragment_offset;
2467 if (!fragment_offset_spec)
2470 * spec and mask are valid, enforce using full mask to make sure the
2471 * complete value is used correctly.
2473 if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2474 != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2475 return rte_flow_error_set(error, EINVAL,
2476 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2477 item, "must use full mask for"
2478 " fragment_offset");
2480 * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
2481 * indicating this is 1st fragment of fragmented packet.
2482 * This is not yet supported in MLX5, return appropriate error message.
2484 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
2485 return rte_flow_error_set(error, ENOTSUP,
2486 RTE_FLOW_ERROR_TYPE_ITEM, item,
2487 "match on first fragment not "
2489 if (fragment_offset_spec && !last)
2490 return rte_flow_error_set(error, ENOTSUP,
2491 RTE_FLOW_ERROR_TYPE_ITEM, item,
2492 "specified value not supported");
2493 /* spec and last are valid, validate the specified range. */
2494 fragment_offset_last = last->hdr.fragment_offset &
2495 mask->hdr.fragment_offset;
2497 * Match on fragment_offset spec 0x2001 and last 0x3fff
2498 * means MF is 1 and frag-offset is > 0.
2499 * This packet is fragment 2nd and onward, excluding last.
2500 * This is not yet supported in MLX5, return appropriate
2503 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
2504 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2505 return rte_flow_error_set(error, ENOTSUP,
2506 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2507 last, "match on following "
2508 "fragments not supported");
2510 * Match on fragment_offset spec 0x0001 and last 0x1fff
2511 * means MF is 0 and frag-offset is > 0.
2512 * This packet is last fragment of fragmented packet.
2513 * This is not yet supported in MLX5, return appropriate
2516 if (fragment_offset_spec == RTE_BE16(1) &&
2517 fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
2518 return rte_flow_error_set(error, ENOTSUP,
2519 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2520 last, "match on last "
2521 "fragment not supported");
2523 * Match on fragment_offset spec 0x0001 and last 0x3fff
2524 * means MF and/or frag-offset is not 0.
2525 * This is a fragmented packet.
2526 * Other range values are invalid and rejected.
2528 if (!(fragment_offset_spec == RTE_BE16(1) &&
2529 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
2530 return rte_flow_error_set(error, ENOTSUP,
2531 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2532 "specified range not supported");
2537 * Validate IPV6 fragment extension item.
2540 * Item specification.
2541 * @param[in] item_flags
2542 * Bit-fields that holds the items detected until now.
2544 * Pointer to error structure.
2547 * 0 on success, a negative errno value otherwise and rte_errno is set.
2550 flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
2551 uint64_t item_flags,
2552 struct rte_flow_error *error)
2554 const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
2555 const struct rte_flow_item_ipv6_frag_ext *last = item->last;
2556 const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
2557 rte_be16_t frag_data_spec = 0;
2558 rte_be16_t frag_data_last = 0;
2559 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2560 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2561 MLX5_FLOW_LAYER_OUTER_L4;
2563 struct rte_flow_item_ipv6_frag_ext nic_mask = {
2565 .next_header = 0xff,
2566 .frag_data = RTE_BE16(0xffff),
2570 if (item_flags & l4m)
2571 return rte_flow_error_set(error, EINVAL,
2572 RTE_FLOW_ERROR_TYPE_ITEM, item,
2573 "ipv6 fragment extension item cannot "
2575 if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
2576 (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
2577 return rte_flow_error_set(error, EINVAL,
2578 RTE_FLOW_ERROR_TYPE_ITEM, item,
2579 "ipv6 fragment extension item must "
2580 "follow ipv6 item");
2582 frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
2583 if (!frag_data_spec)
2586 * spec and mask are valid, enforce using full mask to make sure the
2587 * complete value is used correctly.
2589 if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
2590 RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2591 return rte_flow_error_set(error, EINVAL,
2592 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2593 item, "must use full mask for"
2596 * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2597 * This is 1st fragment of fragmented packet.
2599 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2600 return rte_flow_error_set(error, ENOTSUP,
2601 RTE_FLOW_ERROR_TYPE_ITEM, item,
2602 "match on first fragment not "
2604 if (frag_data_spec && !last)
2605 return rte_flow_error_set(error, EINVAL,
2606 RTE_FLOW_ERROR_TYPE_ITEM, item,
2607 "specified value not supported");
2608 ret = mlx5_flow_item_acceptable
2609 (item, (const uint8_t *)mask,
2610 (const uint8_t *)&nic_mask,
2611 sizeof(struct rte_flow_item_ipv6_frag_ext),
2612 MLX5_ITEM_RANGE_ACCEPTED, error);
2615 /* spec and last are valid, validate the specified range. */
2616 frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2618 * Match on frag_data spec 0x0009 and last 0xfff9
2619 * means M is 1 and frag-offset is > 0.
2620 * This packet is fragment 2nd and onward, excluding last.
2621 * This is not yet supported in MLX5, return appropriate
2624 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2625 RTE_IPV6_EHDR_MF_MASK) &&
2626 frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2627 return rte_flow_error_set(error, ENOTSUP,
2628 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2629 last, "match on following "
2630 "fragments not supported");
2632 * Match on frag_data spec 0x0008 and last 0xfff8
2633 * means M is 0 and frag-offset is > 0.
2634 * This packet is last fragment of fragmented packet.
2635 * This is not yet supported in MLX5, return appropriate
2638 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2639 frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2640 return rte_flow_error_set(error, ENOTSUP,
2641 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2642 last, "match on last "
2643 "fragment not supported");
2644 /* Other range values are invalid and rejected. */
2645 return rte_flow_error_set(error, EINVAL,
2646 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2647 "specified range not supported");
2651 * Validate ASO CT item.
2654 * Pointer to the rte_eth_dev structure.
2656 * Item specification.
2657 * @param[in] item_flags
2658 * Pointer to bit-fields that holds the items detected until now.
2660 * Pointer to error structure.
2663 * 0 on success, a negative errno value otherwise and rte_errno is set.
2666 flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
2667 const struct rte_flow_item *item,
2668 uint64_t *item_flags,
2669 struct rte_flow_error *error)
2671 const struct rte_flow_item_conntrack *spec = item->spec;
2672 const struct rte_flow_item_conntrack *mask = item->mask;
2676 if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
2677 return rte_flow_error_set(error, EINVAL,
2678 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2679 "Only one CT is supported");
2681 mask = &rte_flow_item_conntrack_mask;
2682 flags = spec->flags & mask->flags;
2683 if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
2684 ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
2685 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
2686 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
2687 return rte_flow_error_set(error, EINVAL,
2688 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2689 "Conflict status bits");
2690 /* State change also needs to be considered. */
2691 *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
2696 * Validate the pop VLAN action.
2699 * Pointer to the rte_eth_dev structure.
2700 * @param[in] action_flags
2701 * Holds the actions detected until now.
2703 * Pointer to the pop vlan action.
2704 * @param[in] item_flags
2705 * The items found in this flow rule.
2707 * Pointer to flow attributes.
2709 * Pointer to error structure.
2712 * 0 on success, a negative errno value otherwise and rte_errno is set.
2715 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
2716 uint64_t action_flags,
2717 const struct rte_flow_action *action,
2718 uint64_t item_flags,
2719 const struct rte_flow_attr *attr,
2720 struct rte_flow_error *error)
2722 const struct mlx5_priv *priv = dev->data->dev_private;
2723 struct mlx5_dev_ctx_shared *sh = priv->sh;
2724 bool direction_error = false;
2726 if (!priv->sh->pop_vlan_action)
2727 return rte_flow_error_set(error, ENOTSUP,
2728 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2730 "pop vlan action is not supported");
2731 /* Pop VLAN is not supported in egress except for CX6 FDB mode. */
2732 if (attr->transfer) {
2733 bool fdb_tx = priv->representor_id != UINT16_MAX;
2734 bool is_cx5 = sh->steering_format_version ==
2735 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
2737 if (fdb_tx && is_cx5)
2738 direction_error = true;
2739 } else if (attr->egress) {
2740 direction_error = true;
2742 if (direction_error)
2743 return rte_flow_error_set(error, ENOTSUP,
2744 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2746 "pop vlan action not supported for egress");
2747 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
2748 return rte_flow_error_set(error, ENOTSUP,
2749 RTE_FLOW_ERROR_TYPE_ACTION, action,
2750 "no support for multiple VLAN "
2752 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
2753 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
2754 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
2755 return rte_flow_error_set(error, ENOTSUP,
2756 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2758 "cannot pop vlan after decap without "
2759 "match on inner vlan in the flow");
2760 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
2761 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
2762 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2763 return rte_flow_error_set(error, ENOTSUP,
2764 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2766 "cannot pop vlan without a "
2767 "match on (outer) vlan in the flow");
2768 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2769 return rte_flow_error_set(error, EINVAL,
2770 RTE_FLOW_ERROR_TYPE_ACTION, action,
2771 "wrong action order, port_id should "
2772 "be after pop VLAN action");
2773 if (!attr->transfer && priv->representor)
2774 return rte_flow_error_set(error, ENOTSUP,
2775 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2776 "pop vlan action for VF representor "
2777 "not supported on NIC table");
2782 * Get VLAN default info from vlan match info.
2785 * the list of item specifications.
2787 * pointer VLAN info to fill to.
2790 * 0 on success, a negative errno value otherwise and rte_errno is set.
2793 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
2794 struct rte_vlan_hdr *vlan)
2796 const struct rte_flow_item_vlan nic_mask = {
2797 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
2798 MLX5DV_FLOW_VLAN_VID_MASK),
2799 .inner_type = RTE_BE16(0xffff),
2804 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2805 int type = items->type;
2807 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
2808 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
2811 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
2812 const struct rte_flow_item_vlan *vlan_m = items->mask;
2813 const struct rte_flow_item_vlan *vlan_v = items->spec;
2815 /* If VLAN item in pattern doesn't contain data, return here. */
2820 /* Only full match values are accepted */
2821 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
2822 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
2823 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
2825 rte_be_to_cpu_16(vlan_v->tci &
2826 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
2828 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
2829 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
2830 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
2832 rte_be_to_cpu_16(vlan_v->tci &
2833 MLX5DV_FLOW_VLAN_VID_MASK_BE);
2835 if (vlan_m->inner_type == nic_mask.inner_type)
2836 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
2837 vlan_m->inner_type);
2842 * Validate the push VLAN action.
2845 * Pointer to the rte_eth_dev structure.
2846 * @param[in] action_flags
2847 * Holds the actions detected until now.
2848 * @param[in] item_flags
2849 * The items found in this flow rule.
2851 * Pointer to the action structure.
2853 * Pointer to flow attributes
2855 * Pointer to error structure.
2858 * 0 on success, a negative errno value otherwise and rte_errno is set.
2861 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
2862 uint64_t action_flags,
2863 const struct rte_flow_item_vlan *vlan_m,
2864 const struct rte_flow_action *action,
2865 const struct rte_flow_attr *attr,
2866 struct rte_flow_error *error)
2868 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
2869 const struct mlx5_priv *priv = dev->data->dev_private;
2870 struct mlx5_dev_ctx_shared *sh = priv->sh;
2871 bool direction_error = false;
2873 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
2874 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
2875 return rte_flow_error_set(error, EINVAL,
2876 RTE_FLOW_ERROR_TYPE_ACTION, action,
2877 "invalid vlan ethertype");
2878 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2879 return rte_flow_error_set(error, EINVAL,
2880 RTE_FLOW_ERROR_TYPE_ACTION, action,
2881 "wrong action order, port_id should "
2882 "be after push VLAN");
2883 /* Push VLAN is not supported in ingress except for CX6 FDB mode. */
2884 if (attr->transfer) {
2885 bool fdb_tx = priv->representor_id != UINT16_MAX;
2886 bool is_cx5 = sh->steering_format_version ==
2887 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
2889 if (!fdb_tx && is_cx5)
2890 direction_error = true;
2891 } else if (attr->ingress) {
2892 direction_error = true;
2894 if (direction_error)
2895 return rte_flow_error_set(error, ENOTSUP,
2896 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2898 "push vlan action not supported for ingress");
2899 if (!attr->transfer && priv->representor)
2900 return rte_flow_error_set(error, ENOTSUP,
2901 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2902 "push vlan action for VF representor "
2903 "not supported on NIC table");
2905 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
2906 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
2907 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
2908 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
2909 !(mlx5_flow_find_action
2910 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
2911 return rte_flow_error_set(error, EINVAL,
2912 RTE_FLOW_ERROR_TYPE_ACTION, action,
2913 "not full match mask on VLAN PCP and "
2914 "there is no of_set_vlan_pcp action, "
2915 "push VLAN action cannot figure out "
2918 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
2919 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
2920 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
2921 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
2922 !(mlx5_flow_find_action
2923 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
2924 return rte_flow_error_set(error, EINVAL,
2925 RTE_FLOW_ERROR_TYPE_ACTION, action,
2926 "not full match mask on VLAN VID and "
2927 "there is no of_set_vlan_vid action, "
2928 "push VLAN action cannot figure out "
2935 * Validate the set VLAN PCP.
2937 * @param[in] action_flags
2938 * Holds the actions detected until now.
2939 * @param[in] actions
2940 * Pointer to the list of actions remaining in the flow rule.
2942 * Pointer to error structure.
2945 * 0 on success, a negative errno value otherwise and rte_errno is set.
2948 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2949 const struct rte_flow_action actions[],
2950 struct rte_flow_error *error)
2952 const struct rte_flow_action *action = actions;
2953 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2955 if (conf->vlan_pcp > 7)
2956 return rte_flow_error_set(error, EINVAL,
2957 RTE_FLOW_ERROR_TYPE_ACTION, action,
2958 "VLAN PCP value is too big");
2959 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2960 return rte_flow_error_set(error, ENOTSUP,
2961 RTE_FLOW_ERROR_TYPE_ACTION, action,
2962 "set VLAN PCP action must follow "
2963 "the push VLAN action");
2964 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2965 return rte_flow_error_set(error, ENOTSUP,
2966 RTE_FLOW_ERROR_TYPE_ACTION, action,
2967 "Multiple VLAN PCP modification are "
2969 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2970 return rte_flow_error_set(error, EINVAL,
2971 RTE_FLOW_ERROR_TYPE_ACTION, action,
2972 "wrong action order, port_id should "
2973 "be after set VLAN PCP");
2978 * Validate the set VLAN VID.
2980 * @param[in] item_flags
2981 * Holds the items detected in this rule.
2982 * @param[in] action_flags
2983 * Holds the actions detected until now.
2984 * @param[in] actions
2985 * Pointer to the list of actions remaining in the flow rule.
2987 * Pointer to error structure.
2990 * 0 on success, a negative errno value otherwise and rte_errno is set.
2993 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2994 uint64_t action_flags,
2995 const struct rte_flow_action actions[],
2996 struct rte_flow_error *error)
2998 const struct rte_flow_action *action = actions;
2999 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3001 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3002 return rte_flow_error_set(error, EINVAL,
3003 RTE_FLOW_ERROR_TYPE_ACTION, action,
3004 "VLAN VID value is too big");
3005 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3006 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3007 return rte_flow_error_set(error, ENOTSUP,
3008 RTE_FLOW_ERROR_TYPE_ACTION, action,
3009 "set VLAN VID action must follow push"
3010 " VLAN action or match on VLAN item");
3011 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3012 return rte_flow_error_set(error, ENOTSUP,
3013 RTE_FLOW_ERROR_TYPE_ACTION, action,
3014 "Multiple VLAN VID modifications are "
3016 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3017 return rte_flow_error_set(error, EINVAL,
3018 RTE_FLOW_ERROR_TYPE_ACTION, action,
3019 "wrong action order, port_id should "
3020 "be after set VLAN VID");
3025 * Validate the FLAG action.
3028 * Pointer to the rte_eth_dev structure.
3029 * @param[in] action_flags
3030 * Holds the actions detected until now.
3032 * Pointer to flow attributes
3034 * Pointer to error structure.
3037 * 0 on success, a negative errno value otherwise and rte_errno is set.
3040 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3041 uint64_t action_flags,
3042 const struct rte_flow_attr *attr,
3043 struct rte_flow_error *error)
3045 struct mlx5_priv *priv = dev->data->dev_private;
3046 struct mlx5_dev_config *config = &priv->config;
3049 /* Fall back if no extended metadata register support. */
3050 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3051 return mlx5_flow_validate_action_flag(action_flags, attr,
3053 /* Extensive metadata mode requires registers. */
3054 if (!mlx5_flow_ext_mreg_supported(dev))
3055 return rte_flow_error_set(error, ENOTSUP,
3056 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3057 "no metadata registers "
3058 "to support flag action");
3059 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3060 return rte_flow_error_set(error, ENOTSUP,
3061 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3062 "extended metadata register"
3063 " isn't available");
3064 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3067 MLX5_ASSERT(ret > 0);
3068 if (action_flags & MLX5_FLOW_ACTION_MARK)
3069 return rte_flow_error_set(error, EINVAL,
3070 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3071 "can't mark and flag in same flow");
3072 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3073 return rte_flow_error_set(error, EINVAL,
3074 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3076 " actions in same flow");
3081 * Validate MARK action.
3084 * Pointer to the rte_eth_dev structure.
3086 * Pointer to action.
3087 * @param[in] action_flags
3088 * Holds the actions detected until now.
3090 * Pointer to flow attributes
3092 * Pointer to error structure.
3095 * 0 on success, a negative errno value otherwise and rte_errno is set.
3098 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3099 const struct rte_flow_action *action,
3100 uint64_t action_flags,
3101 const struct rte_flow_attr *attr,
3102 struct rte_flow_error *error)
3104 struct mlx5_priv *priv = dev->data->dev_private;
3105 struct mlx5_dev_config *config = &priv->config;
3106 const struct rte_flow_action_mark *mark = action->conf;
3109 if (is_tunnel_offload_active(dev))
3110 return rte_flow_error_set(error, ENOTSUP,
3111 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3113 "if tunnel offload active");
3114 /* Fall back if no extended metadata register support. */
3115 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3116 return mlx5_flow_validate_action_mark(action, action_flags,
3118 /* Extensive metadata mode requires registers. */
3119 if (!mlx5_flow_ext_mreg_supported(dev))
3120 return rte_flow_error_set(error, ENOTSUP,
3121 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3122 "no metadata registers "
3123 "to support mark action");
3124 if (!priv->sh->dv_mark_mask)
3125 return rte_flow_error_set(error, ENOTSUP,
3126 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3127 "extended metadata register"
3128 " isn't available");
3129 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3132 MLX5_ASSERT(ret > 0);
3134 return rte_flow_error_set(error, EINVAL,
3135 RTE_FLOW_ERROR_TYPE_ACTION, action,
3136 "configuration cannot be null");
3137 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3138 return rte_flow_error_set(error, EINVAL,
3139 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3141 "mark id exceeds the limit");
3142 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3143 return rte_flow_error_set(error, EINVAL,
3144 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3145 "can't flag and mark in same flow");
3146 if (action_flags & MLX5_FLOW_ACTION_MARK)
3147 return rte_flow_error_set(error, EINVAL,
3148 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3149 "can't have 2 mark actions in same"
3155 * Validate SET_META action.
3158 * Pointer to the rte_eth_dev structure.
3160 * Pointer to the action structure.
3161 * @param[in] action_flags
3162 * Holds the actions detected until now.
3164 * Pointer to flow attributes
3166 * Pointer to error structure.
3169 * 0 on success, a negative errno value otherwise and rte_errno is set.
3172 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3173 const struct rte_flow_action *action,
3174 uint64_t action_flags __rte_unused,
3175 const struct rte_flow_attr *attr,
3176 struct rte_flow_error *error)
3178 const struct rte_flow_action_set_meta *conf;
3179 uint32_t nic_mask = UINT32_MAX;
3182 if (!mlx5_flow_ext_mreg_supported(dev))
3183 return rte_flow_error_set(error, ENOTSUP,
3184 RTE_FLOW_ERROR_TYPE_ACTION, action,
3185 "extended metadata register"
3186 " isn't supported");
3187 reg = flow_dv_get_metadata_reg(dev, attr, error);
3191 return rte_flow_error_set(error, ENOTSUP,
3192 RTE_FLOW_ERROR_TYPE_ACTION, action,
3193 "unavalable extended metadata register");
3194 if (reg != REG_A && reg != REG_B) {
3195 struct mlx5_priv *priv = dev->data->dev_private;
3197 nic_mask = priv->sh->dv_meta_mask;
3199 if (!(action->conf))
3200 return rte_flow_error_set(error, EINVAL,
3201 RTE_FLOW_ERROR_TYPE_ACTION, action,
3202 "configuration cannot be null");
3203 conf = (const struct rte_flow_action_set_meta *)action->conf;
3205 return rte_flow_error_set(error, EINVAL,
3206 RTE_FLOW_ERROR_TYPE_ACTION, action,
3207 "zero mask doesn't have any effect");
3208 if (conf->mask & ~nic_mask)
3209 return rte_flow_error_set(error, EINVAL,
3210 RTE_FLOW_ERROR_TYPE_ACTION, action,
3211 "meta data must be within reg C0");
3216 * Validate SET_TAG action.
3219 * Pointer to the rte_eth_dev structure.
3221 * Pointer to the action structure.
3222 * @param[in] action_flags
3223 * Holds the actions detected until now.
3225 * Pointer to flow attributes
3227 * Pointer to error structure.
3230 * 0 on success, a negative errno value otherwise and rte_errno is set.
3233 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3234 const struct rte_flow_action *action,
3235 uint64_t action_flags,
3236 const struct rte_flow_attr *attr,
3237 struct rte_flow_error *error)
3239 const struct rte_flow_action_set_tag *conf;
3240 const uint64_t terminal_action_flags =
3241 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3242 MLX5_FLOW_ACTION_RSS;
3245 if (!mlx5_flow_ext_mreg_supported(dev))
3246 return rte_flow_error_set(error, ENOTSUP,
3247 RTE_FLOW_ERROR_TYPE_ACTION, action,
3248 "extensive metadata register"
3249 " isn't supported");
3250 if (!(action->conf))
3251 return rte_flow_error_set(error, EINVAL,
3252 RTE_FLOW_ERROR_TYPE_ACTION, action,
3253 "configuration cannot be null");
3254 conf = (const struct rte_flow_action_set_tag *)action->conf;
3256 return rte_flow_error_set(error, EINVAL,
3257 RTE_FLOW_ERROR_TYPE_ACTION, action,
3258 "zero mask doesn't have any effect");
3259 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3262 if (!attr->transfer && attr->ingress &&
3263 (action_flags & terminal_action_flags))
3264 return rte_flow_error_set(error, EINVAL,
3265 RTE_FLOW_ERROR_TYPE_ACTION, action,
3266 "set_tag has no effect"
3267 " with terminal actions");
3272 * Validate count action.
3275 * Pointer to rte_eth_dev structure.
3277 * Indicator if action is shared.
3278 * @param[in] action_flags
3279 * Holds the actions detected until now.
3281 * Pointer to error structure.
3284 * 0 on success, a negative errno value otherwise and rte_errno is set.
3287 flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3288 uint64_t action_flags,
3289 struct rte_flow_error *error)
3291 struct mlx5_priv *priv = dev->data->dev_private;
3293 if (!priv->sh->devx)
3295 if (action_flags & MLX5_FLOW_ACTION_COUNT)
3296 return rte_flow_error_set(error, EINVAL,
3297 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3298 "duplicate count actions set");
3299 if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
3300 !priv->sh->flow_hit_aso_en)
3301 return rte_flow_error_set(error, EINVAL,
3302 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3303 "old age and shared count combination is not supported");
3304 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3308 return rte_flow_error_set
3310 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3312 "count action not supported");
3316 * Validate the L2 encap action.
3319 * Pointer to the rte_eth_dev structure.
3320 * @param[in] action_flags
3321 * Holds the actions detected until now.
3323 * Pointer to the action structure.
3325 * Pointer to flow attributes.
3327 * Pointer to error structure.
3330 * 0 on success, a negative errno value otherwise and rte_errno is set.
3333 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3334 uint64_t action_flags,
3335 const struct rte_flow_action *action,
3336 const struct rte_flow_attr *attr,
3337 struct rte_flow_error *error)
3339 const struct mlx5_priv *priv = dev->data->dev_private;
3341 if (!(action->conf))
3342 return rte_flow_error_set(error, EINVAL,
3343 RTE_FLOW_ERROR_TYPE_ACTION, action,
3344 "configuration cannot be null");
3345 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3346 return rte_flow_error_set(error, EINVAL,
3347 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3348 "can only have a single encap action "
3350 if (!attr->transfer && priv->representor)
3351 return rte_flow_error_set(error, ENOTSUP,
3352 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3353 "encap action for VF representor "
3354 "not supported on NIC table");
3359 * Validate a decap action.
3362 * Pointer to the rte_eth_dev structure.
3363 * @param[in] action_flags
3364 * Holds the actions detected until now.
3366 * Pointer to the action structure.
3367 * @param[in] item_flags
3368 * Holds the items detected.
3370 * Pointer to flow attributes
3372 * Pointer to error structure.
3375 * 0 on success, a negative errno value otherwise and rte_errno is set.
3378 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3379 uint64_t action_flags,
3380 const struct rte_flow_action *action,
3381 const uint64_t item_flags,
3382 const struct rte_flow_attr *attr,
3383 struct rte_flow_error *error)
3385 const struct mlx5_priv *priv = dev->data->dev_private;
3387 if (priv->config.hca_attr.scatter_fcs_w_decap_disable &&
3388 !priv->config.decap_en)
3389 return rte_flow_error_set(error, ENOTSUP,
3390 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3391 "decap is not enabled");
3392 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3393 return rte_flow_error_set(error, ENOTSUP,
3394 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3396 MLX5_FLOW_ACTION_DECAP ? "can only "
3397 "have a single decap action" : "decap "
3398 "after encap is not supported");
3399 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3400 return rte_flow_error_set(error, EINVAL,
3401 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3402 "can't have decap action after"
3405 return rte_flow_error_set(error, ENOTSUP,
3406 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3408 "decap action not supported for "
3410 if (!attr->transfer && priv->representor)
3411 return rte_flow_error_set(error, ENOTSUP,
3412 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3413 "decap action for VF representor "
3414 "not supported on NIC table");
3415 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3416 !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3417 return rte_flow_error_set(error, ENOTSUP,
3418 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3419 "VXLAN item should be present for VXLAN decap");
3423 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3426 * Validate the raw encap and decap actions.
3429 * Pointer to the rte_eth_dev structure.
3431 * Pointer to the decap action.
3433 * Pointer to the encap action.
3435 * Pointer to flow attributes
3436 * @param[in/out] action_flags
3437 * Holds the actions detected until now.
3438 * @param[out] actions_n
3439 * pointer to the number of actions counter.
3441 * Pointer to the action structure.
3442 * @param[in] item_flags
3443 * Holds the items detected.
3445 * Pointer to error structure.
3448 * 0 on success, a negative errno value otherwise and rte_errno is set.
3451 flow_dv_validate_action_raw_encap_decap
3452 (struct rte_eth_dev *dev,
3453 const struct rte_flow_action_raw_decap *decap,
3454 const struct rte_flow_action_raw_encap *encap,
3455 const struct rte_flow_attr *attr, uint64_t *action_flags,
3456 int *actions_n, const struct rte_flow_action *action,
3457 uint64_t item_flags, struct rte_flow_error *error)
3459 const struct mlx5_priv *priv = dev->data->dev_private;
3462 if (encap && (!encap->size || !encap->data))
3463 return rte_flow_error_set(error, EINVAL,
3464 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3465 "raw encap data cannot be empty");
3466 if (decap && encap) {
3467 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3468 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3471 else if (encap->size <=
3472 MLX5_ENCAPSULATION_DECISION_SIZE &&
3474 MLX5_ENCAPSULATION_DECISION_SIZE)
3477 else if (encap->size >
3478 MLX5_ENCAPSULATION_DECISION_SIZE &&
3480 MLX5_ENCAPSULATION_DECISION_SIZE)
3481 /* 2 L2 actions: encap and decap. */
3484 return rte_flow_error_set(error,
3486 RTE_FLOW_ERROR_TYPE_ACTION,
3487 NULL, "unsupported too small "
3488 "raw decap and too small raw "
3489 "encap combination");
3492 ret = flow_dv_validate_action_decap(dev, *action_flags, action,
3493 item_flags, attr, error);
3496 *action_flags |= MLX5_FLOW_ACTION_DECAP;
3500 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
3501 return rte_flow_error_set(error, ENOTSUP,
3502 RTE_FLOW_ERROR_TYPE_ACTION,
3504 "small raw encap size");
3505 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
3506 return rte_flow_error_set(error, EINVAL,
3507 RTE_FLOW_ERROR_TYPE_ACTION,
3509 "more than one encap action");
3510 if (!attr->transfer && priv->representor)
3511 return rte_flow_error_set
3513 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3514 "encap action for VF representor "
3515 "not supported on NIC table");
3516 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
3523 * Validate the ASO CT action.
3526 * Pointer to the rte_eth_dev structure.
3527 * @param[in] action_flags
3528 * Holds the actions detected until now.
3529 * @param[in] item_flags
3530 * The items found in this flow rule.
3532 * Pointer to flow attributes.
3534 * Pointer to error structure.
3537 * 0 on success, a negative errno value otherwise and rte_errno is set.
3540 flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
3541 uint64_t action_flags,
3542 uint64_t item_flags,
3543 const struct rte_flow_attr *attr,
3544 struct rte_flow_error *error)
3548 if (attr->group == 0 && !attr->transfer)
3549 return rte_flow_error_set(error, ENOTSUP,
3550 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3552 "Only support non-root table");
3553 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
3554 return rte_flow_error_set(error, ENOTSUP,
3555 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3556 "CT cannot follow a fate action");
3557 if ((action_flags & MLX5_FLOW_ACTION_METER) ||
3558 (action_flags & MLX5_FLOW_ACTION_AGE))
3559 return rte_flow_error_set(error, EINVAL,
3560 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3561 "Only one ASO action is supported");
3562 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3563 return rte_flow_error_set(error, EINVAL,
3564 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3565 "Encap cannot exist before CT");
3566 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3567 return rte_flow_error_set(error, EINVAL,
3568 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3569 "Not a outer TCP packet");
3574 flow_dv_encap_decap_match_cb(void *tool_ctx __rte_unused,
3575 struct mlx5_list_entry *entry, void *cb_ctx)
3577 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3578 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3579 struct mlx5_flow_dv_encap_decap_resource *resource;
3581 resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
3583 if (resource->reformat_type == ctx_resource->reformat_type &&
3584 resource->ft_type == ctx_resource->ft_type &&
3585 resource->flags == ctx_resource->flags &&
3586 resource->size == ctx_resource->size &&
3587 !memcmp((const void *)resource->buf,
3588 (const void *)ctx_resource->buf,
3594 struct mlx5_list_entry *
3595 flow_dv_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
3597 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3598 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3599 struct mlx5dv_dr_domain *domain;
3600 struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
3601 struct mlx5_flow_dv_encap_decap_resource *resource;
3605 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3606 domain = sh->fdb_domain;
3607 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3608 domain = sh->rx_domain;
3610 domain = sh->tx_domain;
3611 /* Register new encap/decap resource. */
3612 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
3614 rte_flow_error_set(ctx->error, ENOMEM,
3615 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3616 "cannot allocate resource memory");
3619 *resource = *ctx_resource;
3620 resource->idx = idx;
3621 ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
3625 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
3626 rte_flow_error_set(ctx->error, ENOMEM,
3627 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3628 NULL, "cannot create action");
3632 return &resource->entry;
3635 struct mlx5_list_entry *
3636 flow_dv_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
3639 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3640 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3641 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3644 cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
3646 if (!cache_resource) {
3647 rte_flow_error_set(ctx->error, ENOMEM,
3648 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3649 "cannot allocate resource memory");
3652 memcpy(cache_resource, oentry, sizeof(*cache_resource));
3653 cache_resource->idx = idx;
3654 return &cache_resource->entry;
3658 flow_dv_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3660 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3661 struct mlx5_flow_dv_encap_decap_resource *res =
3662 container_of(entry, typeof(*res), entry);
3664 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
3668 * Find existing encap/decap resource or create and register a new one.
3670 * @param[in, out] dev
3671 * Pointer to rte_eth_dev structure.
3672 * @param[in, out] resource
3673 * Pointer to encap/decap resource.
3674 * @parm[in, out] dev_flow
3675 * Pointer to the dev_flow.
3677 * pointer to error structure.
3680 * 0 on success otherwise -errno and errno is set.
3683 flow_dv_encap_decap_resource_register
3684 (struct rte_eth_dev *dev,
3685 struct mlx5_flow_dv_encap_decap_resource *resource,
3686 struct mlx5_flow *dev_flow,
3687 struct rte_flow_error *error)
3689 struct mlx5_priv *priv = dev->data->dev_private;
3690 struct mlx5_dev_ctx_shared *sh = priv->sh;
3691 struct mlx5_list_entry *entry;
3695 uint32_t refmt_type:8;
3697 * Header reformat actions can be shared between
3698 * non-root tables. One bit to indicate non-root
3702 uint32_t reserve:15;
3705 } encap_decap_key = {
3707 .ft_type = resource->ft_type,
3708 .refmt_type = resource->reformat_type,
3709 .is_root = !!dev_flow->dv.group,
3713 struct mlx5_flow_cb_ctx ctx = {
3717 struct mlx5_hlist *encaps_decaps;
3720 encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
3722 MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
3724 flow_dv_encap_decap_create_cb,
3725 flow_dv_encap_decap_match_cb,
3726 flow_dv_encap_decap_remove_cb,
3727 flow_dv_encap_decap_clone_cb,
3728 flow_dv_encap_decap_clone_free_cb);
3729 if (unlikely(!encaps_decaps))
3731 resource->flags = dev_flow->dv.group ? 0 : 1;
3732 key64 = __rte_raw_cksum(&encap_decap_key.v32,
3733 sizeof(encap_decap_key.v32), 0);
3734 if (resource->reformat_type !=
3735 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
3737 key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
3738 entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
3741 resource = container_of(entry, typeof(*resource), entry);
3742 dev_flow->dv.encap_decap = resource;
3743 dev_flow->handle->dvh.rix_encap_decap = resource->idx;
3748 * Find existing table jump resource or create and register a new one.
3750 * @param[in, out] dev
3751 * Pointer to rte_eth_dev structure.
3752 * @param[in, out] tbl
3753 * Pointer to flow table resource.
3754 * @parm[in, out] dev_flow
3755 * Pointer to the dev_flow.
3757 * pointer to error structure.
3760 * 0 on success otherwise -errno and errno is set.
3763 flow_dv_jump_tbl_resource_register
3764 (struct rte_eth_dev *dev __rte_unused,
3765 struct mlx5_flow_tbl_resource *tbl,
3766 struct mlx5_flow *dev_flow,
3767 struct rte_flow_error *error __rte_unused)
3769 struct mlx5_flow_tbl_data_entry *tbl_data =
3770 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
3773 MLX5_ASSERT(tbl_data->jump.action);
3774 dev_flow->handle->rix_jump = tbl_data->idx;
3775 dev_flow->dv.jump = &tbl_data->jump;
3780 flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
3781 struct mlx5_list_entry *entry, void *cb_ctx)
3783 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3784 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3785 struct mlx5_flow_dv_port_id_action_resource *res =
3786 container_of(entry, typeof(*res), entry);
3788 return ref->port_id != res->port_id;
3791 struct mlx5_list_entry *
3792 flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
3794 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3795 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3796 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3797 struct mlx5_flow_dv_port_id_action_resource *resource;
3801 /* Register new port id action resource. */
3802 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3804 rte_flow_error_set(ctx->error, ENOMEM,
3805 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3806 "cannot allocate port_id action memory");
3810 ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
3814 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
3815 rte_flow_error_set(ctx->error, ENOMEM,
3816 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3817 "cannot create action");
3820 resource->idx = idx;
3821 return &resource->entry;
3824 struct mlx5_list_entry *
3825 flow_dv_port_id_clone_cb(void *tool_ctx,
3826 struct mlx5_list_entry *entry __rte_unused,
3829 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3830 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3831 struct mlx5_flow_dv_port_id_action_resource *resource;
3834 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3836 rte_flow_error_set(ctx->error, ENOMEM,
3837 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3838 "cannot allocate port_id action memory");
3841 memcpy(resource, entry, sizeof(*resource));
3842 resource->idx = idx;
3843 return &resource->entry;
3847 flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3849 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3850 struct mlx5_flow_dv_port_id_action_resource *resource =
3851 container_of(entry, typeof(*resource), entry);
3853 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
3857 * Find existing table port ID resource or create and register a new one.
3859 * @param[in, out] dev
3860 * Pointer to rte_eth_dev structure.
3861 * @param[in, out] ref
3862 * Pointer to port ID action resource reference.
3863 * @parm[in, out] dev_flow
3864 * Pointer to the dev_flow.
3866 * pointer to error structure.
3869 * 0 on success otherwise -errno and errno is set.
3872 flow_dv_port_id_action_resource_register
3873 (struct rte_eth_dev *dev,
3874 struct mlx5_flow_dv_port_id_action_resource *ref,
3875 struct mlx5_flow *dev_flow,
3876 struct rte_flow_error *error)
3878 struct mlx5_priv *priv = dev->data->dev_private;
3879 struct mlx5_list_entry *entry;
3880 struct mlx5_flow_dv_port_id_action_resource *resource;
3881 struct mlx5_flow_cb_ctx ctx = {
3886 entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
3889 resource = container_of(entry, typeof(*resource), entry);
3890 dev_flow->dv.port_id_action = resource;
3891 dev_flow->handle->rix_port_id_action = resource->idx;
3896 flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
3897 struct mlx5_list_entry *entry, void *cb_ctx)
3899 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3900 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3901 struct mlx5_flow_dv_push_vlan_action_resource *res =
3902 container_of(entry, typeof(*res), entry);
3904 return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
3907 struct mlx5_list_entry *
3908 flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
3910 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3911 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3912 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3913 struct mlx5_flow_dv_push_vlan_action_resource *resource;
3914 struct mlx5dv_dr_domain *domain;
3918 /* Register new port id action resource. */
3919 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3921 rte_flow_error_set(ctx->error, ENOMEM,
3922 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3923 "cannot allocate push_vlan action memory");
3927 if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3928 domain = sh->fdb_domain;
3929 else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3930 domain = sh->rx_domain;
3932 domain = sh->tx_domain;
3933 ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
3936 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
3937 rte_flow_error_set(ctx->error, ENOMEM,
3938 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3939 "cannot create push vlan action");
3942 resource->idx = idx;
3943 return &resource->entry;
3946 struct mlx5_list_entry *
3947 flow_dv_push_vlan_clone_cb(void *tool_ctx,
3948 struct mlx5_list_entry *entry __rte_unused,
3951 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3952 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3953 struct mlx5_flow_dv_push_vlan_action_resource *resource;
3956 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3958 rte_flow_error_set(ctx->error, ENOMEM,
3959 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3960 "cannot allocate push_vlan action memory");
3963 memcpy(resource, entry, sizeof(*resource));
3964 resource->idx = idx;
3965 return &resource->entry;
3969 flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
3971 struct mlx5_dev_ctx_shared *sh = tool_ctx;
3972 struct mlx5_flow_dv_push_vlan_action_resource *resource =
3973 container_of(entry, typeof(*resource), entry);
3975 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
3979 * Find existing push vlan resource or create and register a new one.
3981 * @param [in, out] dev
3982 * Pointer to rte_eth_dev structure.
3983 * @param[in, out] ref
3984 * Pointer to port ID action resource reference.
3985 * @parm[in, out] dev_flow
3986 * Pointer to the dev_flow.
3988 * pointer to error structure.
3991 * 0 on success otherwise -errno and errno is set.
3994 flow_dv_push_vlan_action_resource_register
3995 (struct rte_eth_dev *dev,
3996 struct mlx5_flow_dv_push_vlan_action_resource *ref,
3997 struct mlx5_flow *dev_flow,
3998 struct rte_flow_error *error)
4000 struct mlx5_priv *priv = dev->data->dev_private;
4001 struct mlx5_flow_dv_push_vlan_action_resource *resource;
4002 struct mlx5_list_entry *entry;
4003 struct mlx5_flow_cb_ctx ctx = {
4008 entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4011 resource = container_of(entry, typeof(*resource), entry);
4013 dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4014 dev_flow->dv.push_vlan_res = resource;
4019 * Get the size of specific rte_flow_item_type hdr size
4021 * @param[in] item_type
4022 * Tested rte_flow_item_type.
4025 * sizeof struct item_type, 0 if void or irrelevant.
4028 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4032 switch (item_type) {
4033 case RTE_FLOW_ITEM_TYPE_ETH:
4034 retval = sizeof(struct rte_ether_hdr);
4036 case RTE_FLOW_ITEM_TYPE_VLAN:
4037 retval = sizeof(struct rte_vlan_hdr);
4039 case RTE_FLOW_ITEM_TYPE_IPV4:
4040 retval = sizeof(struct rte_ipv4_hdr);
4042 case RTE_FLOW_ITEM_TYPE_IPV6:
4043 retval = sizeof(struct rte_ipv6_hdr);
4045 case RTE_FLOW_ITEM_TYPE_UDP:
4046 retval = sizeof(struct rte_udp_hdr);
4048 case RTE_FLOW_ITEM_TYPE_TCP:
4049 retval = sizeof(struct rte_tcp_hdr);
4051 case RTE_FLOW_ITEM_TYPE_VXLAN:
4052 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4053 retval = sizeof(struct rte_vxlan_hdr);
4055 case RTE_FLOW_ITEM_TYPE_GRE:
4056 case RTE_FLOW_ITEM_TYPE_NVGRE:
4057 retval = sizeof(struct rte_gre_hdr);
4059 case RTE_FLOW_ITEM_TYPE_MPLS:
4060 retval = sizeof(struct rte_mpls_hdr);
4062 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4070 #define MLX5_ENCAP_IPV4_VERSION 0x40
4071 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4072 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4073 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4074 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4075 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4076 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4079 * Convert the encap action data from list of rte_flow_item to raw buffer
4082 * Pointer to rte_flow_item objects list.
4084 * Pointer to the output buffer.
4086 * Pointer to the output buffer size.
4088 * Pointer to the error structure.
4091 * 0 on success, a negative errno value otherwise and rte_errno is set.
4094 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4095 size_t *size, struct rte_flow_error *error)
4097 struct rte_ether_hdr *eth = NULL;
4098 struct rte_vlan_hdr *vlan = NULL;
4099 struct rte_ipv4_hdr *ipv4 = NULL;
4100 struct rte_ipv6_hdr *ipv6 = NULL;
4101 struct rte_udp_hdr *udp = NULL;
4102 struct rte_vxlan_hdr *vxlan = NULL;
4103 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4104 struct rte_gre_hdr *gre = NULL;
4106 size_t temp_size = 0;
4109 return rte_flow_error_set(error, EINVAL,
4110 RTE_FLOW_ERROR_TYPE_ACTION,
4111 NULL, "invalid empty data");
4112 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4113 len = flow_dv_get_item_hdr_len(items->type);
4114 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4115 return rte_flow_error_set(error, EINVAL,
4116 RTE_FLOW_ERROR_TYPE_ACTION,
4117 (void *)items->type,
4118 "items total size is too big"
4119 " for encap action");
4120 rte_memcpy((void *)&buf[temp_size], items->spec, len);
4121 switch (items->type) {
4122 case RTE_FLOW_ITEM_TYPE_ETH:
4123 eth = (struct rte_ether_hdr *)&buf[temp_size];
4125 case RTE_FLOW_ITEM_TYPE_VLAN:
4126 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4128 return rte_flow_error_set(error, EINVAL,
4129 RTE_FLOW_ERROR_TYPE_ACTION,
4130 (void *)items->type,
4131 "eth header not found");
4132 if (!eth->ether_type)
4133 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4135 case RTE_FLOW_ITEM_TYPE_IPV4:
4136 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4138 return rte_flow_error_set(error, EINVAL,
4139 RTE_FLOW_ERROR_TYPE_ACTION,
4140 (void *)items->type,
4141 "neither eth nor vlan"
4143 if (vlan && !vlan->eth_proto)
4144 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4145 else if (eth && !eth->ether_type)
4146 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4147 if (!ipv4->version_ihl)
4148 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4149 MLX5_ENCAP_IPV4_IHL_MIN;
4150 if (!ipv4->time_to_live)
4151 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4153 case RTE_FLOW_ITEM_TYPE_IPV6:
4154 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4156 return rte_flow_error_set(error, EINVAL,
4157 RTE_FLOW_ERROR_TYPE_ACTION,
4158 (void *)items->type,
4159 "neither eth nor vlan"
4161 if (vlan && !vlan->eth_proto)
4162 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4163 else if (eth && !eth->ether_type)
4164 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4165 if (!ipv6->vtc_flow)
4167 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4168 if (!ipv6->hop_limits)
4169 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4171 case RTE_FLOW_ITEM_TYPE_UDP:
4172 udp = (struct rte_udp_hdr *)&buf[temp_size];
4174 return rte_flow_error_set(error, EINVAL,
4175 RTE_FLOW_ERROR_TYPE_ACTION,
4176 (void *)items->type,
4177 "ip header not found");
4178 if (ipv4 && !ipv4->next_proto_id)
4179 ipv4->next_proto_id = IPPROTO_UDP;
4180 else if (ipv6 && !ipv6->proto)
4181 ipv6->proto = IPPROTO_UDP;
4183 case RTE_FLOW_ITEM_TYPE_VXLAN:
4184 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4186 return rte_flow_error_set(error, EINVAL,
4187 RTE_FLOW_ERROR_TYPE_ACTION,
4188 (void *)items->type,
4189 "udp header not found");
4191 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4192 if (!vxlan->vx_flags)
4194 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4196 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4197 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4199 return rte_flow_error_set(error, EINVAL,
4200 RTE_FLOW_ERROR_TYPE_ACTION,
4201 (void *)items->type,
4202 "udp header not found");
4203 if (!vxlan_gpe->proto)
4204 return rte_flow_error_set(error, EINVAL,
4205 RTE_FLOW_ERROR_TYPE_ACTION,
4206 (void *)items->type,
4207 "next protocol not found");
4210 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4211 if (!vxlan_gpe->vx_flags)
4212 vxlan_gpe->vx_flags =
4213 MLX5_ENCAP_VXLAN_GPE_FLAGS;
4215 case RTE_FLOW_ITEM_TYPE_GRE:
4216 case RTE_FLOW_ITEM_TYPE_NVGRE:
4217 gre = (struct rte_gre_hdr *)&buf[temp_size];
4219 return rte_flow_error_set(error, EINVAL,
4220 RTE_FLOW_ERROR_TYPE_ACTION,
4221 (void *)items->type,
4222 "next protocol not found");
4224 return rte_flow_error_set(error, EINVAL,
4225 RTE_FLOW_ERROR_TYPE_ACTION,
4226 (void *)items->type,
4227 "ip header not found");
4228 if (ipv4 && !ipv4->next_proto_id)
4229 ipv4->next_proto_id = IPPROTO_GRE;
4230 else if (ipv6 && !ipv6->proto)
4231 ipv6->proto = IPPROTO_GRE;
4233 case RTE_FLOW_ITEM_TYPE_VOID:
4236 return rte_flow_error_set(error, EINVAL,
4237 RTE_FLOW_ERROR_TYPE_ACTION,
4238 (void *)items->type,
4239 "unsupported item type");
4249 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4251 struct rte_ether_hdr *eth = NULL;
4252 struct rte_vlan_hdr *vlan = NULL;
4253 struct rte_ipv6_hdr *ipv6 = NULL;
4254 struct rte_udp_hdr *udp = NULL;
4258 eth = (struct rte_ether_hdr *)data;
4259 next_hdr = (char *)(eth + 1);
4260 proto = RTE_BE16(eth->ether_type);
4263 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4264 vlan = (struct rte_vlan_hdr *)next_hdr;
4265 proto = RTE_BE16(vlan->eth_proto);
4266 next_hdr += sizeof(struct rte_vlan_hdr);
4269 /* HW calculates IPv4 csum. no need to proceed */
4270 if (proto == RTE_ETHER_TYPE_IPV4)
4273 /* non IPv4/IPv6 header. not supported */
4274 if (proto != RTE_ETHER_TYPE_IPV6) {
4275 return rte_flow_error_set(error, ENOTSUP,
4276 RTE_FLOW_ERROR_TYPE_ACTION,
4277 NULL, "Cannot offload non IPv4/IPv6");
4280 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4282 /* ignore non UDP */
4283 if (ipv6->proto != IPPROTO_UDP)
4286 udp = (struct rte_udp_hdr *)(ipv6 + 1);
4287 udp->dgram_cksum = 0;
4293 * Convert L2 encap action to DV specification.
4296 * Pointer to rte_eth_dev structure.
4298 * Pointer to action structure.
4299 * @param[in, out] dev_flow
4300 * Pointer to the mlx5_flow.
4301 * @param[in] transfer
4302 * Mark if the flow is E-Switch flow.
4304 * Pointer to the error structure.
4307 * 0 on success, a negative errno value otherwise and rte_errno is set.
4310 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4311 const struct rte_flow_action *action,
4312 struct mlx5_flow *dev_flow,
4314 struct rte_flow_error *error)
4316 const struct rte_flow_item *encap_data;
4317 const struct rte_flow_action_raw_encap *raw_encap_data;
4318 struct mlx5_flow_dv_encap_decap_resource res = {
4320 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4321 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4322 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4325 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4327 (const struct rte_flow_action_raw_encap *)action->conf;
4328 res.size = raw_encap_data->size;
4329 memcpy(res.buf, raw_encap_data->data, res.size);
4331 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4333 ((const struct rte_flow_action_vxlan_encap *)
4334 action->conf)->definition;
4337 ((const struct rte_flow_action_nvgre_encap *)
4338 action->conf)->definition;
4339 if (flow_dv_convert_encap_data(encap_data, res.buf,
4343 if (flow_dv_zero_encap_udp_csum(res.buf, error))
4345 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4346 return rte_flow_error_set(error, EINVAL,
4347 RTE_FLOW_ERROR_TYPE_ACTION,
4348 NULL, "can't create L2 encap action");
4353 * Convert L2 decap action to DV specification.
4356 * Pointer to rte_eth_dev structure.
4357 * @param[in, out] dev_flow
4358 * Pointer to the mlx5_flow.
4359 * @param[in] transfer
4360 * Mark if the flow is E-Switch flow.
4362 * Pointer to the error structure.
4365 * 0 on success, a negative errno value otherwise and rte_errno is set.
4368 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
4369 struct mlx5_flow *dev_flow,
4371 struct rte_flow_error *error)
4373 struct mlx5_flow_dv_encap_decap_resource res = {
4376 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
4377 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4378 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
4381 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4382 return rte_flow_error_set(error, EINVAL,
4383 RTE_FLOW_ERROR_TYPE_ACTION,
4384 NULL, "can't create L2 decap action");
4389 * Convert raw decap/encap (L3 tunnel) action to DV specification.
4392 * Pointer to rte_eth_dev structure.
4394 * Pointer to action structure.
4395 * @param[in, out] dev_flow
4396 * Pointer to the mlx5_flow.
4398 * Pointer to the flow attributes.
4400 * Pointer to the error structure.
4403 * 0 on success, a negative errno value otherwise and rte_errno is set.
4406 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
4407 const struct rte_flow_action *action,
4408 struct mlx5_flow *dev_flow,
4409 const struct rte_flow_attr *attr,
4410 struct rte_flow_error *error)
4412 const struct rte_flow_action_raw_encap *encap_data;
4413 struct mlx5_flow_dv_encap_decap_resource res;
4415 memset(&res, 0, sizeof(res));
4416 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
4417 res.size = encap_data->size;
4418 memcpy(res.buf, encap_data->data, res.size);
4419 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
4420 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
4421 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
4423 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4425 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4426 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4427 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4428 return rte_flow_error_set(error, EINVAL,
4429 RTE_FLOW_ERROR_TYPE_ACTION,
4430 NULL, "can't create encap action");
4435 * Create action push VLAN.
4438 * Pointer to rte_eth_dev structure.
4440 * Pointer to the flow attributes.
4442 * Pointer to the vlan to push to the Ethernet header.
4443 * @param[in, out] dev_flow
4444 * Pointer to the mlx5_flow.
4446 * Pointer to the error structure.
4449 * 0 on success, a negative errno value otherwise and rte_errno is set.
4452 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
4453 const struct rte_flow_attr *attr,
4454 const struct rte_vlan_hdr *vlan,
4455 struct mlx5_flow *dev_flow,
4456 struct rte_flow_error *error)
4458 struct mlx5_flow_dv_push_vlan_action_resource res;
4460 memset(&res, 0, sizeof(res));
4462 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
4465 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4467 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4468 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4469 return flow_dv_push_vlan_action_resource_register
4470 (dev, &res, dev_flow, error);
4474 * Validate the modify-header actions.
4476 * @param[in] action_flags
4477 * Holds the actions detected until now.
4479 * Pointer to the modify action.
4481 * Pointer to error structure.
4484 * 0 on success, a negative errno value otherwise and rte_errno is set.
4487 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
4488 const struct rte_flow_action *action,
4489 struct rte_flow_error *error)
4491 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
4492 return rte_flow_error_set(error, EINVAL,
4493 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4494 NULL, "action configuration not set");
4495 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4496 return rte_flow_error_set(error, EINVAL,
4497 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4498 "can't have encap action before"
4504 * Validate the modify-header MAC address actions.
4506 * @param[in] action_flags
4507 * Holds the actions detected until now.
4509 * Pointer to the modify action.
4510 * @param[in] item_flags
4511 * Holds the items detected.
4513 * Pointer to error structure.
4516 * 0 on success, a negative errno value otherwise and rte_errno is set.
4519 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
4520 const struct rte_flow_action *action,
4521 const uint64_t item_flags,
4522 struct rte_flow_error *error)
4526 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4528 if (!(item_flags & MLX5_FLOW_LAYER_L2))
4529 return rte_flow_error_set(error, EINVAL,
4530 RTE_FLOW_ERROR_TYPE_ACTION,
4532 "no L2 item in pattern");
4538 * Validate the modify-header IPv4 address actions.
4540 * @param[in] action_flags
4541 * Holds the actions detected until now.
4543 * Pointer to the modify action.
4544 * @param[in] item_flags
4545 * Holds the items detected.
4547 * Pointer to error structure.
4550 * 0 on success, a negative errno value otherwise and rte_errno is set.
4553 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
4554 const struct rte_flow_action *action,
4555 const uint64_t item_flags,
4556 struct rte_flow_error *error)
4561 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4563 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4564 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4565 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4566 if (!(item_flags & layer))
4567 return rte_flow_error_set(error, EINVAL,
4568 RTE_FLOW_ERROR_TYPE_ACTION,
4570 "no ipv4 item in pattern");
4576 * Validate the modify-header IPv6 address actions.
4578 * @param[in] action_flags
4579 * Holds the actions detected until now.
4581 * Pointer to the modify action.
4582 * @param[in] item_flags
4583 * Holds the items detected.
4585 * Pointer to error structure.
4588 * 0 on success, a negative errno value otherwise and rte_errno is set.
4591 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
4592 const struct rte_flow_action *action,
4593 const uint64_t item_flags,
4594 struct rte_flow_error *error)
4599 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4601 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4602 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4603 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4604 if (!(item_flags & layer))
4605 return rte_flow_error_set(error, EINVAL,
4606 RTE_FLOW_ERROR_TYPE_ACTION,
4608 "no ipv6 item in pattern");
4614 * Validate the modify-header TP actions.
4616 * @param[in] action_flags
4617 * Holds the actions detected until now.
4619 * Pointer to the modify action.
4620 * @param[in] item_flags
4621 * Holds the items detected.
4623 * Pointer to error structure.
4626 * 0 on success, a negative errno value otherwise and rte_errno is set.
4629 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
4630 const struct rte_flow_action *action,
4631 const uint64_t item_flags,
4632 struct rte_flow_error *error)
4637 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4639 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4640 MLX5_FLOW_LAYER_INNER_L4 :
4641 MLX5_FLOW_LAYER_OUTER_L4;
4642 if (!(item_flags & layer))
4643 return rte_flow_error_set(error, EINVAL,
4644 RTE_FLOW_ERROR_TYPE_ACTION,
4645 NULL, "no transport layer "
4652 * Validate the modify-header actions of increment/decrement
4653 * TCP Sequence-number.
4655 * @param[in] action_flags
4656 * Holds the actions detected until now.
4658 * Pointer to the modify action.
4659 * @param[in] item_flags
4660 * Holds the items detected.
4662 * Pointer to error structure.
4665 * 0 on success, a negative errno value otherwise and rte_errno is set.
4668 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
4669 const struct rte_flow_action *action,
4670 const uint64_t item_flags,
4671 struct rte_flow_error *error)
4676 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4678 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4679 MLX5_FLOW_LAYER_INNER_L4_TCP :
4680 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4681 if (!(item_flags & layer))
4682 return rte_flow_error_set(error, EINVAL,
4683 RTE_FLOW_ERROR_TYPE_ACTION,
4684 NULL, "no TCP item in"
4686 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
4687 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
4688 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
4689 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
4690 return rte_flow_error_set(error, EINVAL,
4691 RTE_FLOW_ERROR_TYPE_ACTION,
4693 "cannot decrease and increase"
4694 " TCP sequence number"
4695 " at the same time");
4701 * Validate the modify-header actions of increment/decrement
4702 * TCP Acknowledgment number.
4704 * @param[in] action_flags
4705 * Holds the actions detected until now.
4707 * Pointer to the modify action.
4708 * @param[in] item_flags
4709 * Holds the items detected.
4711 * Pointer to error structure.
4714 * 0 on success, a negative errno value otherwise and rte_errno is set.
4717 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
4718 const struct rte_flow_action *action,
4719 const uint64_t item_flags,
4720 struct rte_flow_error *error)
4725 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4727 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4728 MLX5_FLOW_LAYER_INNER_L4_TCP :
4729 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4730 if (!(item_flags & layer))
4731 return rte_flow_error_set(error, EINVAL,
4732 RTE_FLOW_ERROR_TYPE_ACTION,
4733 NULL, "no TCP item in"
4735 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
4736 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
4737 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
4738 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
4739 return rte_flow_error_set(error, EINVAL,
4740 RTE_FLOW_ERROR_TYPE_ACTION,
4742 "cannot decrease and increase"
4743 " TCP acknowledgment number"
4744 " at the same time");
4750 * Validate the modify-header TTL actions.
4752 * @param[in] action_flags
4753 * Holds the actions detected until now.
4755 * Pointer to the modify action.
4756 * @param[in] item_flags
4757 * Holds the items detected.
4759 * Pointer to error structure.
4762 * 0 on success, a negative errno value otherwise and rte_errno is set.
4765 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
4766 const struct rte_flow_action *action,
4767 const uint64_t item_flags,
4768 struct rte_flow_error *error)
4773 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4775 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4776 MLX5_FLOW_LAYER_INNER_L3 :
4777 MLX5_FLOW_LAYER_OUTER_L3;
4778 if (!(item_flags & layer))
4779 return rte_flow_error_set(error, EINVAL,
4780 RTE_FLOW_ERROR_TYPE_ACTION,
4782 "no IP protocol in pattern");
4788 * Validate the generic modify field actions.
4790 * Pointer to the rte_eth_dev structure.
4791 * @param[in] action_flags
4792 * Holds the actions detected until now.
4794 * Pointer to the modify action.
4796 * Pointer to the flow attributes.
4798 * Pointer to error structure.
4801 * Number of header fields to modify (0 or more) on success,
4802 * a negative errno value otherwise and rte_errno is set.
4805 flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
4806 const uint64_t action_flags,
4807 const struct rte_flow_action *action,
4808 const struct rte_flow_attr *attr,
4809 struct rte_flow_error *error)
4812 struct mlx5_priv *priv = dev->data->dev_private;
4813 struct mlx5_dev_config *config = &priv->config;
4814 const struct rte_flow_action_modify_field *action_modify_field =
4816 uint32_t dst_width = mlx5_flow_item_field_width(priv,
4817 action_modify_field->dst.field, -1);
4818 uint32_t src_width = mlx5_flow_item_field_width(priv,
4819 action_modify_field->src.field, dst_width);
4821 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4825 if (action_modify_field->width == 0)
4826 return rte_flow_error_set(error, EINVAL,
4827 RTE_FLOW_ERROR_TYPE_ACTION, action,
4828 "no bits are requested to be modified");
4829 else if (action_modify_field->width > dst_width ||
4830 action_modify_field->width > src_width)
4831 return rte_flow_error_set(error, EINVAL,
4832 RTE_FLOW_ERROR_TYPE_ACTION, action,
4833 "cannot modify more bits than"
4834 " the width of a field");
4835 if (action_modify_field->dst.field != RTE_FLOW_FIELD_VALUE &&
4836 action_modify_field->dst.field != RTE_FLOW_FIELD_POINTER) {
4837 if ((action_modify_field->dst.offset +
4838 action_modify_field->width > dst_width) ||
4839 (action_modify_field->dst.offset % 32))
4840 return rte_flow_error_set(error, EINVAL,
4841 RTE_FLOW_ERROR_TYPE_ACTION, action,
4842 "destination offset is too big"
4843 " or not aligned to 4 bytes");
4844 if (action_modify_field->dst.level &&
4845 action_modify_field->dst.field != RTE_FLOW_FIELD_TAG)
4846 return rte_flow_error_set(error, ENOTSUP,
4847 RTE_FLOW_ERROR_TYPE_ACTION, action,
4848 "inner header fields modification"
4849 " is not supported");
4851 if (action_modify_field->src.field != RTE_FLOW_FIELD_VALUE &&
4852 action_modify_field->src.field != RTE_FLOW_FIELD_POINTER) {
4853 if (!attr->transfer && !attr->group)
4854 return rte_flow_error_set(error, ENOTSUP,
4855 RTE_FLOW_ERROR_TYPE_ACTION, action,
4856 "modify field action is not"
4857 " supported for group 0");
4858 if ((action_modify_field->src.offset +
4859 action_modify_field->width > src_width) ||
4860 (action_modify_field->src.offset % 32))
4861 return rte_flow_error_set(error, EINVAL,
4862 RTE_FLOW_ERROR_TYPE_ACTION, action,
4863 "source offset is too big"
4864 " or not aligned to 4 bytes");
4865 if (action_modify_field->src.level &&
4866 action_modify_field->src.field != RTE_FLOW_FIELD_TAG)
4867 return rte_flow_error_set(error, ENOTSUP,
4868 RTE_FLOW_ERROR_TYPE_ACTION, action,
4869 "inner header fields modification"
4870 " is not supported");
4872 if ((action_modify_field->dst.field ==
4873 action_modify_field->src.field) &&
4874 (action_modify_field->dst.level ==
4875 action_modify_field->src.level))
4876 return rte_flow_error_set(error, EINVAL,
4877 RTE_FLOW_ERROR_TYPE_ACTION, action,
4878 "source and destination fields"
4879 " cannot be the same");
4880 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VALUE ||
4881 action_modify_field->dst.field == RTE_FLOW_FIELD_POINTER ||
4882 action_modify_field->dst.field == RTE_FLOW_FIELD_MARK)
4883 return rte_flow_error_set(error, EINVAL,
4884 RTE_FLOW_ERROR_TYPE_ACTION, action,
4885 "mark, immediate value or a pointer to it"
4886 " cannot be used as a destination");
4887 if (action_modify_field->dst.field == RTE_FLOW_FIELD_START ||
4888 action_modify_field->src.field == RTE_FLOW_FIELD_START)
4889 return rte_flow_error_set(error, ENOTSUP,
4890 RTE_FLOW_ERROR_TYPE_ACTION, action,
4891 "modifications of an arbitrary"
4892 " place in a packet is not supported");
4893 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VLAN_TYPE ||
4894 action_modify_field->src.field == RTE_FLOW_FIELD_VLAN_TYPE)
4895 return rte_flow_error_set(error, ENOTSUP,
4896 RTE_FLOW_ERROR_TYPE_ACTION, action,
4897 "modifications of the 802.1Q Tag"
4898 " Identifier is not supported");
4899 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VXLAN_VNI ||
4900 action_modify_field->src.field == RTE_FLOW_FIELD_VXLAN_VNI)
4901 return rte_flow_error_set(error, ENOTSUP,
4902 RTE_FLOW_ERROR_TYPE_ACTION, action,
4903 "modifications of the VXLAN Network"
4904 " Identifier is not supported");
4905 if (action_modify_field->dst.field == RTE_FLOW_FIELD_GENEVE_VNI ||
4906 action_modify_field->src.field == RTE_FLOW_FIELD_GENEVE_VNI)
4907 return rte_flow_error_set(error, ENOTSUP,
4908 RTE_FLOW_ERROR_TYPE_ACTION, action,
4909 "modifications of the GENEVE Network"
4910 " Identifier is not supported");
4911 if (action_modify_field->dst.field == RTE_FLOW_FIELD_MARK ||
4912 action_modify_field->src.field == RTE_FLOW_FIELD_MARK ||
4913 action_modify_field->dst.field == RTE_FLOW_FIELD_META ||
4914 action_modify_field->src.field == RTE_FLOW_FIELD_META) {
4915 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4916 !mlx5_flow_ext_mreg_supported(dev))
4917 return rte_flow_error_set(error, ENOTSUP,
4918 RTE_FLOW_ERROR_TYPE_ACTION, action,
4919 "cannot modify mark or metadata without"
4920 " extended metadata register support");
4922 if (action_modify_field->operation != RTE_FLOW_MODIFY_SET)
4923 return rte_flow_error_set(error, ENOTSUP,
4924 RTE_FLOW_ERROR_TYPE_ACTION, action,
4925 "add and sub operations"
4926 " are not supported");
4927 return (action_modify_field->width / 32) +
4928 !!(action_modify_field->width % 32);
4932 * Validate jump action.
4935 * Pointer to the jump action.
4936 * @param[in] action_flags
4937 * Holds the actions detected until now.
4938 * @param[in] attributes
4939 * Pointer to flow attributes
4940 * @param[in] external
4941 * Action belongs to flow rule created by request external to PMD.
4943 * Pointer to error structure.
4946 * 0 on success, a negative errno value otherwise and rte_errno is set.
4949 flow_dv_validate_action_jump(struct rte_eth_dev *dev,
4950 const struct mlx5_flow_tunnel *tunnel,
4951 const struct rte_flow_action *action,
4952 uint64_t action_flags,
4953 const struct rte_flow_attr *attributes,
4954 bool external, struct rte_flow_error *error)
4956 uint32_t target_group, table;
4958 struct flow_grp_info grp_info = {
4959 .external = !!external,
4960 .transfer = !!attributes->transfer,
4964 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4965 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4966 return rte_flow_error_set(error, EINVAL,
4967 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4968 "can't have 2 fate actions in"
4971 return rte_flow_error_set(error, EINVAL,
4972 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4973 NULL, "action configuration not set");
4975 ((const struct rte_flow_action_jump *)action->conf)->group;
4976 ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
4980 if (attributes->group == target_group &&
4981 !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
4982 MLX5_FLOW_ACTION_TUNNEL_MATCH)))
4983 return rte_flow_error_set(error, EINVAL,
4984 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4985 "target group must be other than"
4986 " the current flow group");
4991 * Validate action PORT_ID / REPRESENTED_PORT.
4994 * Pointer to rte_eth_dev structure.
4995 * @param[in] action_flags
4996 * Bit-fields that holds the actions detected until now.
4998 * PORT_ID / REPRESENTED_PORT action structure.
5000 * Attributes of flow that includes this action.
5002 * Pointer to error structure.
5005 * 0 on success, a negative errno value otherwise and rte_errno is set.
5008 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5009 uint64_t action_flags,
5010 const struct rte_flow_action *action,
5011 const struct rte_flow_attr *attr,
5012 struct rte_flow_error *error)
5014 const struct rte_flow_action_port_id *port_id;
5015 const struct rte_flow_action_ethdev *ethdev;
5016 struct mlx5_priv *act_priv;
5017 struct mlx5_priv *dev_priv;
5020 if (!attr->transfer)
5021 return rte_flow_error_set(error, ENOTSUP,
5022 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5024 "port action is valid in transfer"
5026 if (!action || !action->conf)
5027 return rte_flow_error_set(error, ENOTSUP,
5028 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5030 "port action parameters must be"
5032 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5033 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5034 return rte_flow_error_set(error, EINVAL,
5035 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5036 "can have only one fate actions in"
5038 dev_priv = mlx5_dev_to_eswitch_info(dev);
5040 return rte_flow_error_set(error, rte_errno,
5041 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5043 "failed to obtain E-Switch info");
5044 switch (action->type) {
5045 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5046 port_id = action->conf;
5047 port = port_id->original ? dev->data->port_id : port_id->id;
5049 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5050 ethdev = action->conf;
5051 port = ethdev->port_id;
5055 return rte_flow_error_set
5057 RTE_FLOW_ERROR_TYPE_ACTION, action,
5058 "unknown E-Switch action");
5060 act_priv = mlx5_port_to_eswitch_info(port, false);
5062 return rte_flow_error_set
5064 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5065 "failed to obtain E-Switch port id for port");
5066 if (act_priv->domain_id != dev_priv->domain_id)
5067 return rte_flow_error_set
5069 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5070 "port does not belong to"
5071 " E-Switch being configured");
5076 * Get the maximum number of modify header actions.
5079 * Pointer to rte_eth_dev structure.
5081 * Whether action is on root table.
5084 * Max number of modify header actions device can support.
5086 static inline unsigned int
5087 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5091 * There's no way to directly query the max capacity from FW.
5092 * The maximal value on root table should be assumed to be supported.
5095 return MLX5_MAX_MODIFY_NUM;
5097 return MLX5_ROOT_TBL_MODIFY_NUM;
5101 * Validate the meter action.
5104 * Pointer to rte_eth_dev structure.
5105 * @param[in] action_flags
5106 * Bit-fields that holds the actions detected until now.
5108 * Pointer to the meter action.
5110 * Attributes of flow that includes this action.
5111 * @param[in] port_id_item
5112 * Pointer to item indicating port id.
5114 * Pointer to error structure.
5117 * 0 on success, a negative errno value otherwise and rte_ernno is set.
5120 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5121 uint64_t action_flags,
5122 const struct rte_flow_action *action,
5123 const struct rte_flow_attr *attr,
5124 const struct rte_flow_item *port_id_item,
5126 struct rte_flow_error *error)
5128 struct mlx5_priv *priv = dev->data->dev_private;
5129 const struct rte_flow_action_meter *am = action->conf;
5130 struct mlx5_flow_meter_info *fm;
5131 struct mlx5_flow_meter_policy *mtr_policy;
5132 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5135 return rte_flow_error_set(error, EINVAL,
5136 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5137 "meter action conf is NULL");
5139 if (action_flags & MLX5_FLOW_ACTION_METER)
5140 return rte_flow_error_set(error, ENOTSUP,
5141 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5142 "meter chaining not support");
5143 if (action_flags & MLX5_FLOW_ACTION_JUMP)
5144 return rte_flow_error_set(error, ENOTSUP,
5145 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5146 "meter with jump not support");
5148 return rte_flow_error_set(error, ENOTSUP,
5149 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5151 "meter action not supported");
5152 fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5154 return rte_flow_error_set(error, EINVAL,
5155 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5157 /* aso meter can always be shared by different domains */
5158 if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5159 !(fm->transfer == attr->transfer ||
5160 (!fm->ingress && !attr->ingress && attr->egress) ||
5161 (!fm->egress && !attr->egress && attr->ingress)))
5162 return rte_flow_error_set(error, EINVAL,
5163 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5164 "Flow attributes domain are either invalid "
5165 "or have a domain conflict with current "
5166 "meter attributes");
5167 if (fm->def_policy) {
5168 if (!((attr->transfer &&
5169 mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
5171 mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
5173 mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
5174 return rte_flow_error_set(error, EINVAL,
5175 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5176 "Flow attributes domain "
5177 "have a conflict with current "
5178 "meter domain attributes");
5181 mtr_policy = mlx5_flow_meter_policy_find(dev,
5182 fm->policy_id, NULL);
5184 return rte_flow_error_set(error, EINVAL,
5185 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5186 "Invalid policy id for meter ");
5187 if (!((attr->transfer && mtr_policy->transfer) ||
5188 (attr->egress && mtr_policy->egress) ||
5189 (attr->ingress && mtr_policy->ingress)))
5190 return rte_flow_error_set(error, EINVAL,
5191 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5192 "Flow attributes domain "
5193 "have a conflict with current "
5194 "meter domain attributes");
5195 if (attr->transfer && mtr_policy->dev) {
5197 * When policy has fate action of port_id,
5198 * the flow should have the same src port as policy.
5200 struct mlx5_priv *policy_port_priv =
5201 mtr_policy->dev->data->dev_private;
5202 int32_t flow_src_port = priv->representor_id;
5205 const struct rte_flow_item_port_id *spec =
5207 struct mlx5_priv *port_priv =
5208 mlx5_port_to_eswitch_info(spec->id,
5211 return rte_flow_error_set(error,
5213 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5215 "Failed to get port info.");
5216 flow_src_port = port_priv->representor_id;
5218 if (flow_src_port != policy_port_priv->representor_id)
5219 return rte_flow_error_set(error,
5221 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5223 "Flow and meter policy "
5224 "have different src port.");
5226 *def_policy = false;
5232 * Validate the age action.
5234 * @param[in] action_flags
5235 * Holds the actions detected until now.
5237 * Pointer to the age action.
5239 * Pointer to the Ethernet device structure.
5241 * Pointer to error structure.
5244 * 0 on success, a negative errno value otherwise and rte_errno is set.
5247 flow_dv_validate_action_age(uint64_t action_flags,
5248 const struct rte_flow_action *action,
5249 struct rte_eth_dev *dev,
5250 struct rte_flow_error *error)
5252 struct mlx5_priv *priv = dev->data->dev_private;
5253 const struct rte_flow_action_age *age = action->conf;
5255 if (!priv->sh->devx || (priv->sh->cmng.counter_fallback &&
5256 !priv->sh->aso_age_mng))
5257 return rte_flow_error_set(error, ENOTSUP,
5258 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5260 "age action not supported");
5261 if (!(action->conf))
5262 return rte_flow_error_set(error, EINVAL,
5263 RTE_FLOW_ERROR_TYPE_ACTION, action,
5264 "configuration cannot be null");
5265 if (!(age->timeout))
5266 return rte_flow_error_set(error, EINVAL,
5267 RTE_FLOW_ERROR_TYPE_ACTION, action,
5268 "invalid timeout value 0");
5269 if (action_flags & MLX5_FLOW_ACTION_AGE)
5270 return rte_flow_error_set(error, EINVAL,
5271 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5272 "duplicate age actions set");
5277 * Validate the modify-header IPv4 DSCP actions.
5279 * @param[in] action_flags
5280 * Holds the actions detected until now.
5282 * Pointer to the modify action.
5283 * @param[in] item_flags
5284 * Holds the items detected.
5286 * Pointer to error structure.
5289 * 0 on success, a negative errno value otherwise and rte_errno is set.
5292 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
5293 const struct rte_flow_action *action,
5294 const uint64_t item_flags,
5295 struct rte_flow_error *error)
5299 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5301 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
5302 return rte_flow_error_set(error, EINVAL,
5303 RTE_FLOW_ERROR_TYPE_ACTION,
5305 "no ipv4 item in pattern");
5311 * Validate the modify-header IPv6 DSCP actions.
5313 * @param[in] action_flags
5314 * Holds the actions detected until now.
5316 * Pointer to the modify action.
5317 * @param[in] item_flags
5318 * Holds the items detected.
5320 * Pointer to error structure.
5323 * 0 on success, a negative errno value otherwise and rte_errno is set.
5326 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
5327 const struct rte_flow_action *action,
5328 const uint64_t item_flags,
5329 struct rte_flow_error *error)
5333 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5335 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
5336 return rte_flow_error_set(error, EINVAL,
5337 RTE_FLOW_ERROR_TYPE_ACTION,
5339 "no ipv6 item in pattern");
5345 flow_dv_modify_match_cb(void *tool_ctx __rte_unused,
5346 struct mlx5_list_entry *entry, void *cb_ctx)
5348 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5349 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5350 struct mlx5_flow_dv_modify_hdr_resource *resource =
5351 container_of(entry, typeof(*resource), entry);
5352 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5354 key_len += ref->actions_num * sizeof(ref->actions[0]);
5355 return ref->actions_num != resource->actions_num ||
5356 memcmp(&ref->ft_type, &resource->ft_type, key_len);
5359 static struct mlx5_indexed_pool *
5360 flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
5362 struct mlx5_indexed_pool *ipool = __atomic_load_n
5363 (&sh->mdh_ipools[index], __ATOMIC_SEQ_CST);
5366 struct mlx5_indexed_pool *expected = NULL;
5367 struct mlx5_indexed_pool_config cfg =
5368 (struct mlx5_indexed_pool_config) {
5369 .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
5371 sizeof(struct mlx5_modification_cmd),
5376 .release_mem_en = !!sh->reclaim_mode,
5377 .per_core_cache = sh->reclaim_mode ? 0 : (1 << 16),
5378 .malloc = mlx5_malloc,
5380 .type = "mlx5_modify_action_resource",
5383 cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
5384 ipool = mlx5_ipool_create(&cfg);
5387 if (!__atomic_compare_exchange_n(&sh->mdh_ipools[index],
5388 &expected, ipool, false,
5390 __ATOMIC_SEQ_CST)) {
5391 mlx5_ipool_destroy(ipool);
5392 ipool = __atomic_load_n(&sh->mdh_ipools[index],
5399 struct mlx5_list_entry *
5400 flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
5402 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5403 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5404 struct mlx5dv_dr_domain *ns;
5405 struct mlx5_flow_dv_modify_hdr_resource *entry;
5406 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5407 struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
5408 ref->actions_num - 1);
5410 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5411 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5414 if (unlikely(!ipool)) {
5415 rte_flow_error_set(ctx->error, ENOMEM,
5416 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5417 NULL, "cannot allocate modify ipool");
5420 entry = mlx5_ipool_zmalloc(ipool, &idx);
5422 rte_flow_error_set(ctx->error, ENOMEM,
5423 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5424 "cannot allocate resource memory");
5427 rte_memcpy(&entry->ft_type,
5428 RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
5429 key_len + data_len);
5430 if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
5431 ns = sh->fdb_domain;
5432 else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
5436 ret = mlx5_flow_os_create_flow_action_modify_header
5437 (sh->cdev->ctx, ns, entry,
5438 data_len, &entry->action);
5440 mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
5441 rte_flow_error_set(ctx->error, ENOMEM,
5442 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5443 NULL, "cannot create modification action");
5447 return &entry->entry;
5450 struct mlx5_list_entry *
5451 flow_dv_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5454 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5455 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5456 struct mlx5_flow_dv_modify_hdr_resource *entry;
5457 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5458 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5461 entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
5464 rte_flow_error_set(ctx->error, ENOMEM,
5465 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5466 "cannot allocate resource memory");
5469 memcpy(entry, oentry, sizeof(*entry) + data_len);
5471 return &entry->entry;
5475 flow_dv_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5477 struct mlx5_dev_ctx_shared *sh = tool_ctx;
5478 struct mlx5_flow_dv_modify_hdr_resource *res =
5479 container_of(entry, typeof(*res), entry);
5481 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
5485 * Validate the sample action.
5487 * @param[in, out] action_flags
5488 * Holds the actions detected until now.
5490 * Pointer to the sample action.
5492 * Pointer to the Ethernet device structure.
5494 * Attributes of flow that includes this action.
5495 * @param[in] item_flags
5496 * Holds the items detected.
5498 * Pointer to the RSS action.
5499 * @param[out] sample_rss
5500 * Pointer to the RSS action in sample action list.
5502 * Pointer to the COUNT action in sample action list.
5503 * @param[out] fdb_mirror_limit
5504 * Pointer to the FDB mirror limitation flag.
5506 * Pointer to error structure.
5509 * 0 on success, a negative errno value otherwise and rte_errno is set.
5512 flow_dv_validate_action_sample(uint64_t *action_flags,
5513 const struct rte_flow_action *action,
5514 struct rte_eth_dev *dev,
5515 const struct rte_flow_attr *attr,
5516 uint64_t item_flags,
5517 const struct rte_flow_action_rss *rss,
5518 const struct rte_flow_action_rss **sample_rss,
5519 const struct rte_flow_action_count **count,
5520 int *fdb_mirror_limit,
5521 struct rte_flow_error *error)
5523 struct mlx5_priv *priv = dev->data->dev_private;
5524 struct mlx5_dev_config *dev_conf = &priv->config;
5525 const struct rte_flow_action_sample *sample = action->conf;
5526 const struct rte_flow_action *act;
5527 uint64_t sub_action_flags = 0;
5528 uint16_t queue_index = 0xFFFF;
5533 return rte_flow_error_set(error, EINVAL,
5534 RTE_FLOW_ERROR_TYPE_ACTION, action,
5535 "configuration cannot be NULL");
5536 if (sample->ratio == 0)
5537 return rte_flow_error_set(error, EINVAL,
5538 RTE_FLOW_ERROR_TYPE_ACTION, action,
5539 "ratio value starts from 1");
5540 if (!priv->sh->devx || (sample->ratio > 0 && !priv->sampler_en))
5541 return rte_flow_error_set(error, ENOTSUP,
5542 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5544 "sample action not supported");
5545 if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
5546 return rte_flow_error_set(error, EINVAL,
5547 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5548 "Multiple sample actions not "
5550 if (*action_flags & MLX5_FLOW_ACTION_METER)
5551 return rte_flow_error_set(error, EINVAL,
5552 RTE_FLOW_ERROR_TYPE_ACTION, action,
5553 "wrong action order, meter should "
5554 "be after sample action");
5555 if (*action_flags & MLX5_FLOW_ACTION_JUMP)
5556 return rte_flow_error_set(error, EINVAL,
5557 RTE_FLOW_ERROR_TYPE_ACTION, action,
5558 "wrong action order, jump should "
5559 "be after sample action");
5560 act = sample->actions;
5561 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
5562 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5563 return rte_flow_error_set(error, ENOTSUP,
5564 RTE_FLOW_ERROR_TYPE_ACTION,
5565 act, "too many actions");
5566 switch (act->type) {
5567 case RTE_FLOW_ACTION_TYPE_QUEUE:
5568 ret = mlx5_flow_validate_action_queue(act,
5574 queue_index = ((const struct rte_flow_action_queue *)
5575 (act->conf))->index;
5576 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
5579 case RTE_FLOW_ACTION_TYPE_RSS:
5580 *sample_rss = act->conf;
5581 ret = mlx5_flow_validate_action_rss(act,
5588 if (rss && *sample_rss &&
5589 ((*sample_rss)->level != rss->level ||
5590 (*sample_rss)->types != rss->types))
5591 return rte_flow_error_set(error, ENOTSUP,
5592 RTE_FLOW_ERROR_TYPE_ACTION,
5594 "Can't use the different RSS types "
5595 "or level in the same flow");
5596 if (*sample_rss != NULL && (*sample_rss)->queue_num)
5597 queue_index = (*sample_rss)->queue[0];
5598 sub_action_flags |= MLX5_FLOW_ACTION_RSS;
5601 case RTE_FLOW_ACTION_TYPE_MARK:
5602 ret = flow_dv_validate_action_mark(dev, act,
5607 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
5608 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
5609 MLX5_FLOW_ACTION_MARK_EXT;
5611 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
5614 case RTE_FLOW_ACTION_TYPE_COUNT:
5615 ret = flow_dv_validate_action_count
5616 (dev, false, *action_flags | sub_action_flags,
5621 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
5622 *action_flags |= MLX5_FLOW_ACTION_COUNT;
5625 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5626 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5627 ret = flow_dv_validate_action_port_id(dev,
5634 sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5637 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5638 ret = flow_dv_validate_action_raw_encap_decap
5639 (dev, NULL, act->conf, attr, &sub_action_flags,
5640 &actions_n, action, item_flags, error);
5645 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5646 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5647 ret = flow_dv_validate_action_l2_encap(dev,
5653 sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
5657 return rte_flow_error_set(error, ENOTSUP,
5658 RTE_FLOW_ERROR_TYPE_ACTION,
5660 "Doesn't support optional "
5664 if (attr->ingress && !attr->transfer) {
5665 if (!(sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
5666 MLX5_FLOW_ACTION_RSS)))
5667 return rte_flow_error_set(error, EINVAL,
5668 RTE_FLOW_ERROR_TYPE_ACTION,
5670 "Ingress must has a dest "
5671 "QUEUE for Sample");
5672 } else if (attr->egress && !attr->transfer) {
5673 return rte_flow_error_set(error, ENOTSUP,
5674 RTE_FLOW_ERROR_TYPE_ACTION,
5676 "Sample Only support Ingress "
5678 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
5679 MLX5_ASSERT(attr->transfer);
5680 if (sample->ratio > 1)
5681 return rte_flow_error_set(error, ENOTSUP,
5682 RTE_FLOW_ERROR_TYPE_ACTION,
5684 "E-Switch doesn't support "
5685 "any optional action "
5687 if (sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
5688 return rte_flow_error_set(error, ENOTSUP,
5689 RTE_FLOW_ERROR_TYPE_ACTION,
5691 "unsupported action QUEUE");
5692 if (sub_action_flags & MLX5_FLOW_ACTION_RSS)
5693 return rte_flow_error_set(error, ENOTSUP,
5694 RTE_FLOW_ERROR_TYPE_ACTION,
5696 "unsupported action QUEUE");
5697 if (!(sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
5698 return rte_flow_error_set(error, EINVAL,
5699 RTE_FLOW_ERROR_TYPE_ACTION,
5701 "E-Switch must has a dest "
5702 "port for mirroring");
5703 if (!priv->config.hca_attr.reg_c_preserve &&
5704 priv->representor_id != UINT16_MAX)
5705 *fdb_mirror_limit = 1;
5707 /* Continue validation for Xcap actions.*/
5708 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
5709 (queue_index == 0xFFFF ||
5710 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5711 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5712 MLX5_FLOW_XCAP_ACTIONS)
5713 return rte_flow_error_set(error, ENOTSUP,
5714 RTE_FLOW_ERROR_TYPE_ACTION,
5715 NULL, "encap and decap "
5716 "combination aren't "
5718 if (!attr->transfer && attr->ingress && (sub_action_flags &
5719 MLX5_FLOW_ACTION_ENCAP))
5720 return rte_flow_error_set(error, ENOTSUP,
5721 RTE_FLOW_ERROR_TYPE_ACTION,
5722 NULL, "encap is not supported"
5723 " for ingress traffic");
5729 * Find existing modify-header resource or create and register a new one.
5731 * @param dev[in, out]
5732 * Pointer to rte_eth_dev structure.
5733 * @param[in, out] resource
5734 * Pointer to modify-header resource.
5735 * @parm[in, out] dev_flow
5736 * Pointer to the dev_flow.
5738 * pointer to error structure.
5741 * 0 on success otherwise -errno and errno is set.
5744 flow_dv_modify_hdr_resource_register
5745 (struct rte_eth_dev *dev,
5746 struct mlx5_flow_dv_modify_hdr_resource *resource,
5747 struct mlx5_flow *dev_flow,
5748 struct rte_flow_error *error)
5750 struct mlx5_priv *priv = dev->data->dev_private;
5751 struct mlx5_dev_ctx_shared *sh = priv->sh;
5752 uint32_t key_len = sizeof(*resource) -
5753 offsetof(typeof(*resource), ft_type) +
5754 resource->actions_num * sizeof(resource->actions[0]);
5755 struct mlx5_list_entry *entry;
5756 struct mlx5_flow_cb_ctx ctx = {
5760 struct mlx5_hlist *modify_cmds;
5763 modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
5765 MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
5767 flow_dv_modify_create_cb,
5768 flow_dv_modify_match_cb,
5769 flow_dv_modify_remove_cb,
5770 flow_dv_modify_clone_cb,
5771 flow_dv_modify_clone_free_cb);
5772 if (unlikely(!modify_cmds))
5774 resource->root = !dev_flow->dv.group;
5775 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
5777 return rte_flow_error_set(error, EOVERFLOW,
5778 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5779 "too many modify header items");
5780 key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
5781 entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
5784 resource = container_of(entry, typeof(*resource), entry);
5785 dev_flow->handle->dvh.modify_hdr = resource;
5790 * Get DV flow counter by index.
5793 * Pointer to the Ethernet device structure.
5795 * mlx5 flow counter index in the container.
5797 * mlx5 flow counter pool in the container.
5800 * Pointer to the counter, NULL otherwise.
5802 static struct mlx5_flow_counter *
5803 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
5805 struct mlx5_flow_counter_pool **ppool)
5807 struct mlx5_priv *priv = dev->data->dev_private;
5808 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5809 struct mlx5_flow_counter_pool *pool;
5811 /* Decrease to original index and clear shared bit. */
5812 idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
5813 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cmng->n);
5814 pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
5818 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
5822 * Check the devx counter belongs to the pool.
5825 * Pointer to the counter pool.
5827 * The counter devx ID.
5830 * True if counter belongs to the pool, false otherwise.
5833 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
5835 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
5836 MLX5_COUNTERS_PER_POOL;
5838 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
5844 * Get a pool by devx counter ID.
5847 * Pointer to the counter management.
5849 * The counter devx ID.
5852 * The counter pool pointer if exists, NULL otherwise,
5854 static struct mlx5_flow_counter_pool *
5855 flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
5858 struct mlx5_flow_counter_pool *pool = NULL;
5860 rte_spinlock_lock(&cmng->pool_update_sl);
5861 /* Check last used pool. */
5862 if (cmng->last_pool_idx != POOL_IDX_INVALID &&
5863 flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
5864 pool = cmng->pools[cmng->last_pool_idx];
5867 /* ID out of range means no suitable pool in the container. */
5868 if (id > cmng->max_id || id < cmng->min_id)
5871 * Find the pool from the end of the container, since mostly counter
5872 * ID is sequence increasing, and the last pool should be the needed
5877 struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
5879 if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
5885 rte_spinlock_unlock(&cmng->pool_update_sl);
5890 * Resize a counter container.
5893 * Pointer to the Ethernet device structure.
5896 * 0 on success, otherwise negative errno value and rte_errno is set.
5899 flow_dv_container_resize(struct rte_eth_dev *dev)
5901 struct mlx5_priv *priv = dev->data->dev_private;
5902 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5903 void *old_pools = cmng->pools;
5904 uint32_t resize = cmng->n + MLX5_CNT_CONTAINER_RESIZE;
5905 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
5906 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
5913 memcpy(pools, old_pools, cmng->n *
5914 sizeof(struct mlx5_flow_counter_pool *));
5916 cmng->pools = pools;
5918 mlx5_free(old_pools);
5923 * Query a devx flow counter.
5926 * Pointer to the Ethernet device structure.
5927 * @param[in] counter
5928 * Index to the flow counter.
5930 * The statistics value of packets.
5932 * The statistics value of bytes.
5935 * 0 on success, otherwise a negative errno value and rte_errno is set.
5938 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
5941 struct mlx5_priv *priv = dev->data->dev_private;
5942 struct mlx5_flow_counter_pool *pool = NULL;
5943 struct mlx5_flow_counter *cnt;
5946 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
5948 if (priv->sh->cmng.counter_fallback)
5949 return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
5950 0, pkts, bytes, 0, NULL, NULL, 0);
5951 rte_spinlock_lock(&pool->sl);
5956 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
5957 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
5958 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
5960 rte_spinlock_unlock(&pool->sl);
5965 * Create and initialize a new counter pool.
5968 * Pointer to the Ethernet device structure.
5970 * The devX counter handle.
5972 * Whether the pool is for counter that was allocated for aging.
5973 * @param[in/out] cont_cur
5974 * Pointer to the container pointer, it will be update in pool resize.
5977 * The pool container pointer on success, NULL otherwise and rte_errno is set.
5979 static struct mlx5_flow_counter_pool *
5980 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
5983 struct mlx5_priv *priv = dev->data->dev_private;
5984 struct mlx5_flow_counter_pool *pool;
5985 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5986 bool fallback = priv->sh->cmng.counter_fallback;
5987 uint32_t size = sizeof(*pool);
5989 size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
5990 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
5991 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
5997 pool->is_aged = !!age;
5998 pool->query_gen = 0;
5999 pool->min_dcs = dcs;
6000 rte_spinlock_init(&pool->sl);
6001 rte_spinlock_init(&pool->csl);
6002 TAILQ_INIT(&pool->counters[0]);
6003 TAILQ_INIT(&pool->counters[1]);
6004 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6005 rte_spinlock_lock(&cmng->pool_update_sl);
6006 pool->index = cmng->n_valid;
6007 if (pool->index == cmng->n && flow_dv_container_resize(dev)) {
6009 rte_spinlock_unlock(&cmng->pool_update_sl);
6012 cmng->pools[pool->index] = pool;
6014 if (unlikely(fallback)) {
6015 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6017 if (base < cmng->min_id)
6018 cmng->min_id = base;
6019 if (base > cmng->max_id)
6020 cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6021 cmng->last_pool_idx = pool->index;
6023 rte_spinlock_unlock(&cmng->pool_update_sl);
6028 * Prepare a new counter and/or a new counter pool.
6031 * Pointer to the Ethernet device structure.
6032 * @param[out] cnt_free
6033 * Where to put the pointer of a new counter.
6035 * Whether the pool is for counter that was allocated for aging.
6038 * The counter pool pointer and @p cnt_free is set on success,
6039 * NULL otherwise and rte_errno is set.
6041 static struct mlx5_flow_counter_pool *
6042 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6043 struct mlx5_flow_counter **cnt_free,
6046 struct mlx5_priv *priv = dev->data->dev_private;
6047 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6048 struct mlx5_flow_counter_pool *pool;
6049 struct mlx5_counters tmp_tq;
6050 struct mlx5_devx_obj *dcs = NULL;
6051 struct mlx5_flow_counter *cnt;
6052 enum mlx5_counter_type cnt_type =
6053 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6054 bool fallback = priv->sh->cmng.counter_fallback;
6058 /* bulk_bitmap must be 0 for single counter allocation. */
6059 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6062 pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6064 pool = flow_dv_pool_create(dev, dcs, age);
6066 mlx5_devx_cmd_destroy(dcs);
6070 i = dcs->id % MLX5_COUNTERS_PER_POOL;
6071 cnt = MLX5_POOL_GET_CNT(pool, i);
6073 cnt->dcs_when_free = dcs;
6077 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6079 rte_errno = ENODATA;
6082 pool = flow_dv_pool_create(dev, dcs, age);
6084 mlx5_devx_cmd_destroy(dcs);
6087 TAILQ_INIT(&tmp_tq);
6088 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6089 cnt = MLX5_POOL_GET_CNT(pool, i);
6091 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6093 rte_spinlock_lock(&cmng->csl[cnt_type]);
6094 TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6095 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6096 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6097 (*cnt_free)->pool = pool;
6102 * Allocate a flow counter.
6105 * Pointer to the Ethernet device structure.
6107 * Whether the counter was allocated for aging.
6110 * Index to flow counter on success, 0 otherwise and rte_errno is set.
6113 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6115 struct mlx5_priv *priv = dev->data->dev_private;
6116 struct mlx5_flow_counter_pool *pool = NULL;
6117 struct mlx5_flow_counter *cnt_free = NULL;
6118 bool fallback = priv->sh->cmng.counter_fallback;
6119 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
6120 enum mlx5_counter_type cnt_type =
6121 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6124 if (!priv->sh->devx) {
6125 rte_errno = ENOTSUP;
6128 /* Get free counters from container. */
6129 rte_spinlock_lock(&cmng->csl[cnt_type]);
6130 cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6132 TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6133 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6134 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6136 pool = cnt_free->pool;
6138 cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6139 /* Create a DV counter action only in the first time usage. */
6140 if (!cnt_free->action) {
6142 struct mlx5_devx_obj *dcs;
6146 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
6147 dcs = pool->min_dcs;
6150 dcs = cnt_free->dcs_when_free;
6152 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
6159 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
6160 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
6161 /* Update the counter reset values. */
6162 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
6165 if (!fallback && !priv->sh->cmng.query_thread_on)
6166 /* Start the asynchronous batch query by the host thread. */
6167 mlx5_set_query_alarm(priv->sh);
6169 * When the count action isn't shared (by ID), shared_info field is
6170 * used for indirect action API's refcnt.
6171 * When the counter action is not shared neither by ID nor by indirect
6172 * action API, shared info must be 1.
6174 cnt_free->shared_info.refcnt = 1;
6178 cnt_free->pool = pool;
6180 cnt_free->dcs_when_free = cnt_free->dcs_when_active;
6181 rte_spinlock_lock(&cmng->csl[cnt_type]);
6182 TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
6183 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6189 * Get age param from counter index.
6192 * Pointer to the Ethernet device structure.
6193 * @param[in] counter
6194 * Index to the counter handler.
6197 * The aging parameter specified for the counter index.
6199 static struct mlx5_age_param*
6200 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
6203 struct mlx5_flow_counter *cnt;
6204 struct mlx5_flow_counter_pool *pool = NULL;
6206 flow_dv_counter_get_by_idx(dev, counter, &pool);
6207 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
6208 cnt = MLX5_POOL_GET_CNT(pool, counter);
6209 return MLX5_CNT_TO_AGE(cnt);
6213 * Remove a flow counter from aged counter list.
6216 * Pointer to the Ethernet device structure.
6217 * @param[in] counter
6218 * Index to the counter handler.
6220 * Pointer to the counter handler.
6223 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
6224 uint32_t counter, struct mlx5_flow_counter *cnt)
6226 struct mlx5_age_info *age_info;
6227 struct mlx5_age_param *age_param;
6228 struct mlx5_priv *priv = dev->data->dev_private;
6229 uint16_t expected = AGE_CANDIDATE;
6231 age_info = GET_PORT_AGE_INFO(priv);
6232 age_param = flow_dv_counter_idx_get_age(dev, counter);
6233 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
6234 AGE_FREE, false, __ATOMIC_RELAXED,
6235 __ATOMIC_RELAXED)) {
6237 * We need the lock even it is age timeout,
6238 * since counter may still in process.
6240 rte_spinlock_lock(&age_info->aged_sl);
6241 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
6242 rte_spinlock_unlock(&age_info->aged_sl);
6243 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
6248 * Release a flow counter.
6251 * Pointer to the Ethernet device structure.
6252 * @param[in] counter
6253 * Index to the counter handler.
6256 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
6258 struct mlx5_priv *priv = dev->data->dev_private;
6259 struct mlx5_flow_counter_pool *pool = NULL;
6260 struct mlx5_flow_counter *cnt;
6261 enum mlx5_counter_type cnt_type;
6265 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6267 if (pool->is_aged) {
6268 flow_dv_counter_remove_from_age(dev, counter, cnt);
6271 * If the counter action is shared by indirect action API,
6272 * the atomic function reduces its references counter.
6273 * If after the reduction the action is still referenced, the
6274 * function returns here and does not release it.
6275 * When the counter action is not shared by
6276 * indirect action API, shared info is 1 before the reduction,
6277 * so this condition is failed and function doesn't return here.
6279 if (__atomic_sub_fetch(&cnt->shared_info.refcnt, 1,
6285 * Put the counter back to list to be updated in none fallback mode.
6286 * Currently, we are using two list alternately, while one is in query,
6287 * add the freed counter to the other list based on the pool query_gen
6288 * value. After query finishes, add counter the list to the global
6289 * container counter list. The list changes while query starts. In
6290 * this case, lock will not be needed as query callback and release
6291 * function both operate with the different list.
6293 if (!priv->sh->cmng.counter_fallback) {
6294 rte_spinlock_lock(&pool->csl);
6295 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
6296 rte_spinlock_unlock(&pool->csl);
6298 cnt->dcs_when_free = cnt->dcs_when_active;
6299 cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6300 MLX5_COUNTER_TYPE_ORIGIN;
6301 rte_spinlock_lock(&priv->sh->cmng.csl[cnt_type]);
6302 TAILQ_INSERT_TAIL(&priv->sh->cmng.counters[cnt_type],
6304 rte_spinlock_unlock(&priv->sh->cmng.csl[cnt_type]);
6309 * Resize a meter id container.
6312 * Pointer to the Ethernet device structure.
6315 * 0 on success, otherwise negative errno value and rte_errno is set.
6318 flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
6320 struct mlx5_priv *priv = dev->data->dev_private;
6321 struct mlx5_aso_mtr_pools_mng *pools_mng =
6322 &priv->sh->mtrmng->pools_mng;
6323 void *old_pools = pools_mng->pools;
6324 uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
6325 uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
6326 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
6333 if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER)) {
6338 memcpy(pools, old_pools, pools_mng->n *
6339 sizeof(struct mlx5_aso_mtr_pool *));
6340 pools_mng->n = resize;
6341 pools_mng->pools = pools;
6343 mlx5_free(old_pools);
6348 * Prepare a new meter and/or a new meter pool.
6351 * Pointer to the Ethernet device structure.
6352 * @param[out] mtr_free
6353 * Where to put the pointer of a new meter.g.
6356 * The meter pool pointer and @mtr_free is set on success,
6357 * NULL otherwise and rte_errno is set.
6359 static struct mlx5_aso_mtr_pool *
6360 flow_dv_mtr_pool_create(struct rte_eth_dev *dev,
6361 struct mlx5_aso_mtr **mtr_free)
6363 struct mlx5_priv *priv = dev->data->dev_private;
6364 struct mlx5_aso_mtr_pools_mng *pools_mng =
6365 &priv->sh->mtrmng->pools_mng;
6366 struct mlx5_aso_mtr_pool *pool = NULL;
6367 struct mlx5_devx_obj *dcs = NULL;
6369 uint32_t log_obj_size;
6371 log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
6372 dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
6373 priv->sh->pdn, log_obj_size);
6375 rte_errno = ENODATA;
6378 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
6381 claim_zero(mlx5_devx_cmd_destroy(dcs));
6384 pool->devx_obj = dcs;
6385 pool->index = pools_mng->n_valid;
6386 if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
6388 claim_zero(mlx5_devx_cmd_destroy(dcs));
6391 pools_mng->pools[pool->index] = pool;
6392 pools_mng->n_valid++;
6393 for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
6394 pool->mtrs[i].offset = i;
6395 LIST_INSERT_HEAD(&pools_mng->meters,
6396 &pool->mtrs[i], next);
6398 pool->mtrs[0].offset = 0;
6399 *mtr_free = &pool->mtrs[0];
6404 * Release a flow meter into pool.
6407 * Pointer to the Ethernet device structure.
6408 * @param[in] mtr_idx
6409 * Index to aso flow meter.
6412 flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
6414 struct mlx5_priv *priv = dev->data->dev_private;
6415 struct mlx5_aso_mtr_pools_mng *pools_mng =
6416 &priv->sh->mtrmng->pools_mng;
6417 struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
6419 MLX5_ASSERT(aso_mtr);
6420 rte_spinlock_lock(&pools_mng->mtrsl);
6421 memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
6422 aso_mtr->state = ASO_METER_FREE;
6423 LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
6424 rte_spinlock_unlock(&pools_mng->mtrsl);
6428 * Allocate a aso flow meter.
6431 * Pointer to the Ethernet device structure.
6434 * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
6437 flow_dv_mtr_alloc(struct rte_eth_dev *dev)
6439 struct mlx5_priv *priv = dev->data->dev_private;
6440 struct mlx5_aso_mtr *mtr_free = NULL;
6441 struct mlx5_aso_mtr_pools_mng *pools_mng =
6442 &priv->sh->mtrmng->pools_mng;
6443 struct mlx5_aso_mtr_pool *pool;
6444 uint32_t mtr_idx = 0;
6446 if (!priv->sh->devx) {
6447 rte_errno = ENOTSUP;
6450 /* Allocate the flow meter memory. */
6451 /* Get free meters from management. */
6452 rte_spinlock_lock(&pools_mng->mtrsl);
6453 mtr_free = LIST_FIRST(&pools_mng->meters);
6455 LIST_REMOVE(mtr_free, next);
6456 if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
6457 rte_spinlock_unlock(&pools_mng->mtrsl);
6460 mtr_free->state = ASO_METER_WAIT;
6461 rte_spinlock_unlock(&pools_mng->mtrsl);
6462 pool = container_of(mtr_free,
6463 struct mlx5_aso_mtr_pool,
6464 mtrs[mtr_free->offset]);
6465 mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
6466 if (!mtr_free->fm.meter_action) {
6467 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
6468 struct rte_flow_error error;
6471 reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
6472 mtr_free->fm.meter_action =
6473 mlx5_glue->dv_create_flow_action_aso
6474 (priv->sh->rx_domain,
6475 pool->devx_obj->obj,
6477 (1 << MLX5_FLOW_COLOR_GREEN),
6479 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
6480 if (!mtr_free->fm.meter_action) {
6481 flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
6489 * Verify the @p attributes will be correctly understood by the NIC and store
6490 * them in the @p flow if everything is correct.
6493 * Pointer to dev struct.
6494 * @param[in] attributes
6495 * Pointer to flow attributes
6496 * @param[in] external
6497 * This flow rule is created by request external to PMD.
6499 * Pointer to error structure.
6502 * - 0 on success and non root table.
6503 * - 1 on success and root table.
6504 * - a negative errno value otherwise and rte_errno is set.
6507 flow_dv_validate_attributes(struct rte_eth_dev *dev,
6508 const struct mlx5_flow_tunnel *tunnel,
6509 const struct rte_flow_attr *attributes,
6510 const struct flow_grp_info *grp_info,
6511 struct rte_flow_error *error)
6513 struct mlx5_priv *priv = dev->data->dev_private;
6514 uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
6517 #ifndef HAVE_MLX5DV_DR
6518 RTE_SET_USED(tunnel);
6519 RTE_SET_USED(grp_info);
6520 if (attributes->group)
6521 return rte_flow_error_set(error, ENOTSUP,
6522 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6524 "groups are not supported");
6528 ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
6533 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
6535 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
6536 attributes->priority > lowest_priority)
6537 return rte_flow_error_set(error, ENOTSUP,
6538 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
6540 "priority out of range");
6541 if (attributes->transfer) {
6542 if (!priv->config.dv_esw_en)
6543 return rte_flow_error_set
6545 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6546 "E-Switch dr is not supported");
6547 if (!(priv->representor || priv->master))
6548 return rte_flow_error_set
6549 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6550 NULL, "E-Switch configuration can only be"
6551 " done by a master or a representor device");
6552 if (attributes->egress)
6553 return rte_flow_error_set
6555 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
6556 "egress is not supported");
6558 if (!(attributes->egress ^ attributes->ingress))
6559 return rte_flow_error_set(error, ENOTSUP,
6560 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6561 "must specify exactly one of "
6562 "ingress or egress");
6567 mlx5_flow_locate_proto_l3(const struct rte_flow_item **head,
6568 const struct rte_flow_item *end)
6570 const struct rte_flow_item *item = *head;
6571 uint16_t l3_protocol;
6573 for (; item != end; item++) {
6574 switch (item->type) {
6577 case RTE_FLOW_ITEM_TYPE_IPV4:
6578 l3_protocol = RTE_ETHER_TYPE_IPV4;
6580 case RTE_FLOW_ITEM_TYPE_IPV6:
6581 l3_protocol = RTE_ETHER_TYPE_IPV6;
6583 case RTE_FLOW_ITEM_TYPE_ETH:
6584 if (item->mask && item->spec) {
6585 MLX5_ETHER_TYPE_FROM_HEADER(rte_flow_item_eth,
6588 if (l3_protocol == RTE_ETHER_TYPE_IPV4 ||
6589 l3_protocol == RTE_ETHER_TYPE_IPV6)
6593 case RTE_FLOW_ITEM_TYPE_VLAN:
6594 if (item->mask && item->spec) {
6595 MLX5_ETHER_TYPE_FROM_HEADER(rte_flow_item_vlan,
6598 if (l3_protocol == RTE_ETHER_TYPE_IPV4 ||
6599 l3_protocol == RTE_ETHER_TYPE_IPV6)
6612 mlx5_flow_locate_proto_l4(const struct rte_flow_item **head,
6613 const struct rte_flow_item *end)
6615 const struct rte_flow_item *item = *head;
6616 uint8_t l4_protocol;
6618 for (; item != end; item++) {
6619 switch (item->type) {
6622 case RTE_FLOW_ITEM_TYPE_TCP:
6623 l4_protocol = IPPROTO_TCP;
6625 case RTE_FLOW_ITEM_TYPE_UDP:
6626 l4_protocol = IPPROTO_UDP;
6628 case RTE_FLOW_ITEM_TYPE_IPV4:
6629 if (item->mask && item->spec) {
6630 const struct rte_flow_item_ipv4 *mask, *spec;
6632 mask = (typeof(mask))item->mask;
6633 spec = (typeof(spec))item->spec;
6634 l4_protocol = mask->hdr.next_proto_id &
6635 spec->hdr.next_proto_id;
6636 if (l4_protocol == IPPROTO_TCP ||
6637 l4_protocol == IPPROTO_UDP)
6641 case RTE_FLOW_ITEM_TYPE_IPV6:
6642 if (item->mask && item->spec) {
6643 const struct rte_flow_item_ipv6 *mask, *spec;
6644 mask = (typeof(mask))item->mask;
6645 spec = (typeof(spec))item->spec;
6646 l4_protocol = mask->hdr.proto & spec->hdr.proto;
6647 if (l4_protocol == IPPROTO_TCP ||
6648 l4_protocol == IPPROTO_UDP)
6661 flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
6662 const struct rte_flow_item *rule_items,
6663 const struct rte_flow_item *integrity_item,
6664 struct rte_flow_error *error)
6666 struct mlx5_priv *priv = dev->data->dev_private;
6667 const struct rte_flow_item *tunnel_item, *end_item, *item = rule_items;
6668 const struct rte_flow_item_integrity *mask = (typeof(mask))
6669 integrity_item->mask;
6670 const struct rte_flow_item_integrity *spec = (typeof(spec))
6671 integrity_item->spec;
6674 if (!priv->config.hca_attr.pkt_integrity_match)
6675 return rte_flow_error_set(error, ENOTSUP,
6676 RTE_FLOW_ERROR_TYPE_ITEM,
6678 "packet integrity integrity_item not supported");
6680 mask = &rte_flow_item_integrity_mask;
6681 if (!mlx5_validate_integrity_item(mask))
6682 return rte_flow_error_set(error, ENOTSUP,
6683 RTE_FLOW_ERROR_TYPE_ITEM,
6685 "unsupported integrity filter");
6686 tunnel_item = mlx5_flow_find_tunnel_item(rule_items);
6687 if (spec->level > 1) {
6689 return rte_flow_error_set(error, ENOTSUP,
6690 RTE_FLOW_ERROR_TYPE_ITEM,
6692 "missing tunnel item");
6694 end_item = mlx5_find_end_item(tunnel_item);
6696 end_item = tunnel_item ? tunnel_item :
6697 mlx5_find_end_item(integrity_item);
6699 if (mask->l3_ok || mask->ipv4_csum_ok) {
6700 protocol = mlx5_flow_locate_proto_l3(&item, end_item);
6702 return rte_flow_error_set(error, EINVAL,
6703 RTE_FLOW_ERROR_TYPE_ITEM,
6705 "missing L3 protocol");
6707 if (mask->l4_ok || mask->l4_csum_ok) {
6708 protocol = mlx5_flow_locate_proto_l4(&item, end_item);
6710 return rte_flow_error_set(error, EINVAL,
6711 RTE_FLOW_ERROR_TYPE_ITEM,
6713 "missing L4 protocol");
6719 * Internal validation function. For validating both actions and items.
6722 * Pointer to the rte_eth_dev structure.
6724 * Pointer to the flow attributes.
6726 * Pointer to the list of items.
6727 * @param[in] actions
6728 * Pointer to the list of actions.
6729 * @param[in] external
6730 * This flow rule is created by request external to PMD.
6731 * @param[in] hairpin
6732 * Number of hairpin TX actions, 0 means classic flow.
6734 * Pointer to the error structure.
6737 * 0 on success, a negative errno value otherwise and rte_errno is set.
6740 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
6741 const struct rte_flow_item items[],
6742 const struct rte_flow_action actions[],
6743 bool external, int hairpin, struct rte_flow_error *error)
6746 uint64_t action_flags = 0;
6747 uint64_t item_flags = 0;
6748 uint64_t last_item = 0;
6749 uint8_t next_protocol = 0xff;
6750 uint16_t ether_type = 0;
6752 uint8_t item_ipv6_proto = 0;
6753 int fdb_mirror_limit = 0;
6754 int modify_after_mirror = 0;
6755 const struct rte_flow_item *geneve_item = NULL;
6756 const struct rte_flow_item *gre_item = NULL;
6757 const struct rte_flow_item *gtp_item = NULL;
6758 const struct rte_flow_action_raw_decap *decap;
6759 const struct rte_flow_action_raw_encap *encap;
6760 const struct rte_flow_action_rss *rss = NULL;
6761 const struct rte_flow_action_rss *sample_rss = NULL;
6762 const struct rte_flow_action_count *sample_count = NULL;
6763 const struct rte_flow_item_tcp nic_tcp_mask = {
6766 .src_port = RTE_BE16(UINT16_MAX),
6767 .dst_port = RTE_BE16(UINT16_MAX),
6770 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
6773 "\xff\xff\xff\xff\xff\xff\xff\xff"
6774 "\xff\xff\xff\xff\xff\xff\xff\xff",
6776 "\xff\xff\xff\xff\xff\xff\xff\xff"
6777 "\xff\xff\xff\xff\xff\xff\xff\xff",
6778 .vtc_flow = RTE_BE32(0xffffffff),
6784 const struct rte_flow_item_ecpri nic_ecpri_mask = {
6788 RTE_BE32(((const struct rte_ecpri_common_hdr) {
6792 .dummy[0] = 0xffffffff,
6795 struct mlx5_priv *priv = dev->data->dev_private;
6796 struct mlx5_dev_config *dev_conf = &priv->config;
6797 uint16_t queue_index = 0xFFFF;
6798 const struct rte_flow_item_vlan *vlan_m = NULL;
6799 uint32_t rw_act_num = 0;
6801 const struct mlx5_flow_tunnel *tunnel;
6802 enum mlx5_tof_rule_type tof_rule_type;
6803 struct flow_grp_info grp_info = {
6804 .external = !!external,
6805 .transfer = !!attr->transfer,
6806 .fdb_def_rule = !!priv->fdb_def_rule,
6807 .std_tbl_fix = true,
6809 const struct rte_eth_hairpin_conf *conf;
6810 const struct rte_flow_item *rule_items = items;
6811 const struct rte_flow_item *port_id_item = NULL;
6812 bool def_policy = false;
6813 uint16_t udp_dport = 0;
6817 tunnel = is_tunnel_offload_active(dev) ?
6818 mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
6820 if (priv->representor)
6821 return rte_flow_error_set
6823 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6824 NULL, "decap not supported for VF representor");
6825 if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
6826 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6827 else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
6828 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
6829 MLX5_FLOW_ACTION_DECAP;
6830 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
6831 (dev, attr, tunnel, tof_rule_type);
6833 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
6836 is_root = (uint64_t)ret;
6837 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6838 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
6839 int type = items->type;
6841 if (!mlx5_flow_os_item_supported(type))
6842 return rte_flow_error_set(error, ENOTSUP,
6843 RTE_FLOW_ERROR_TYPE_ITEM,
6844 NULL, "item not supported");
6846 case RTE_FLOW_ITEM_TYPE_VOID:
6848 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6849 ret = flow_dv_validate_item_port_id
6850 (dev, items, attr, item_flags, error);
6853 last_item = MLX5_FLOW_ITEM_PORT_ID;
6854 port_id_item = items;
6856 case RTE_FLOW_ITEM_TYPE_ETH:
6857 ret = mlx5_flow_validate_item_eth(items, item_flags,
6861 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
6862 MLX5_FLOW_LAYER_OUTER_L2;
6863 if (items->mask != NULL && items->spec != NULL) {
6865 ((const struct rte_flow_item_eth *)
6868 ((const struct rte_flow_item_eth *)
6870 ether_type = rte_be_to_cpu_16(ether_type);
6875 case RTE_FLOW_ITEM_TYPE_VLAN:
6876 ret = flow_dv_validate_item_vlan(items, item_flags,
6880 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
6881 MLX5_FLOW_LAYER_OUTER_VLAN;
6882 if (items->mask != NULL && items->spec != NULL) {
6884 ((const struct rte_flow_item_vlan *)
6885 items->spec)->inner_type;
6887 ((const struct rte_flow_item_vlan *)
6888 items->mask)->inner_type;
6889 ether_type = rte_be_to_cpu_16(ether_type);
6893 /* Store outer VLAN mask for of_push_vlan action. */
6895 vlan_m = items->mask;
6897 case RTE_FLOW_ITEM_TYPE_IPV4:
6898 mlx5_flow_tunnel_ip_check(items, next_protocol,
6899 &item_flags, &tunnel);
6900 ret = flow_dv_validate_item_ipv4(dev, items, item_flags,
6901 last_item, ether_type,
6905 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
6906 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
6907 if (items->mask != NULL &&
6908 ((const struct rte_flow_item_ipv4 *)
6909 items->mask)->hdr.next_proto_id) {
6911 ((const struct rte_flow_item_ipv4 *)
6912 (items->spec))->hdr.next_proto_id;
6914 ((const struct rte_flow_item_ipv4 *)
6915 (items->mask))->hdr.next_proto_id;
6917 /* Reset for inner layer. */
6918 next_protocol = 0xff;
6921 case RTE_FLOW_ITEM_TYPE_IPV6:
6922 mlx5_flow_tunnel_ip_check(items, next_protocol,
6923 &item_flags, &tunnel);
6924 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
6931 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
6932 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
6933 if (items->mask != NULL &&
6934 ((const struct rte_flow_item_ipv6 *)
6935 items->mask)->hdr.proto) {
6937 ((const struct rte_flow_item_ipv6 *)
6938 items->spec)->hdr.proto;
6940 ((const struct rte_flow_item_ipv6 *)
6941 items->spec)->hdr.proto;
6943 ((const struct rte_flow_item_ipv6 *)
6944 items->mask)->hdr.proto;
6946 /* Reset for inner layer. */
6947 next_protocol = 0xff;
6950 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
6951 ret = flow_dv_validate_item_ipv6_frag_ext(items,
6956 last_item = tunnel ?
6957 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
6958 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
6959 if (items->mask != NULL &&
6960 ((const struct rte_flow_item_ipv6_frag_ext *)
6961 items->mask)->hdr.next_header) {
6963 ((const struct rte_flow_item_ipv6_frag_ext *)
6964 items->spec)->hdr.next_header;
6966 ((const struct rte_flow_item_ipv6_frag_ext *)
6967 items->mask)->hdr.next_header;
6969 /* Reset for inner layer. */
6970 next_protocol = 0xff;
6973 case RTE_FLOW_ITEM_TYPE_TCP:
6974 ret = mlx5_flow_validate_item_tcp
6981 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
6982 MLX5_FLOW_LAYER_OUTER_L4_TCP;
6984 case RTE_FLOW_ITEM_TYPE_UDP:
6985 ret = mlx5_flow_validate_item_udp(items, item_flags,
6988 const struct rte_flow_item_udp *spec = items->spec;
6989 const struct rte_flow_item_udp *mask = items->mask;
6991 mask = &rte_flow_item_udp_mask;
6993 udp_dport = rte_be_to_cpu_16
6994 (spec->hdr.dst_port &
6995 mask->hdr.dst_port);
6998 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
6999 MLX5_FLOW_LAYER_OUTER_L4_UDP;
7001 case RTE_FLOW_ITEM_TYPE_GRE:
7002 ret = mlx5_flow_validate_item_gre(items, item_flags,
7003 next_protocol, error);
7007 last_item = MLX5_FLOW_LAYER_GRE;
7009 case RTE_FLOW_ITEM_TYPE_NVGRE:
7010 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
7015 last_item = MLX5_FLOW_LAYER_NVGRE;
7017 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7018 ret = mlx5_flow_validate_item_gre_key
7019 (items, item_flags, gre_item, error);
7022 last_item = MLX5_FLOW_LAYER_GRE_KEY;
7024 case RTE_FLOW_ITEM_TYPE_VXLAN:
7025 ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
7030 last_item = MLX5_FLOW_LAYER_VXLAN;
7032 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7033 ret = mlx5_flow_validate_item_vxlan_gpe(items,
7038 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
7040 case RTE_FLOW_ITEM_TYPE_GENEVE:
7041 ret = mlx5_flow_validate_item_geneve(items,
7046 geneve_item = items;
7047 last_item = MLX5_FLOW_LAYER_GENEVE;
7049 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
7050 ret = mlx5_flow_validate_item_geneve_opt(items,
7057 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
7059 case RTE_FLOW_ITEM_TYPE_MPLS:
7060 ret = mlx5_flow_validate_item_mpls(dev, items,
7065 last_item = MLX5_FLOW_LAYER_MPLS;
7068 case RTE_FLOW_ITEM_TYPE_MARK:
7069 ret = flow_dv_validate_item_mark(dev, items, attr,
7073 last_item = MLX5_FLOW_ITEM_MARK;
7075 case RTE_FLOW_ITEM_TYPE_META:
7076 ret = flow_dv_validate_item_meta(dev, items, attr,
7080 last_item = MLX5_FLOW_ITEM_METADATA;
7082 case RTE_FLOW_ITEM_TYPE_ICMP:
7083 ret = mlx5_flow_validate_item_icmp(items, item_flags,
7088 last_item = MLX5_FLOW_LAYER_ICMP;
7090 case RTE_FLOW_ITEM_TYPE_ICMP6:
7091 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
7096 item_ipv6_proto = IPPROTO_ICMPV6;
7097 last_item = MLX5_FLOW_LAYER_ICMP6;
7099 case RTE_FLOW_ITEM_TYPE_TAG:
7100 ret = flow_dv_validate_item_tag(dev, items,
7104 last_item = MLX5_FLOW_ITEM_TAG;
7106 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7107 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
7109 case RTE_FLOW_ITEM_TYPE_GTP:
7110 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
7115 last_item = MLX5_FLOW_LAYER_GTP;
7117 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
7118 ret = flow_dv_validate_item_gtp_psc(items, last_item,
7123 last_item = MLX5_FLOW_LAYER_GTP_PSC;
7125 case RTE_FLOW_ITEM_TYPE_ECPRI:
7126 /* Capacity will be checked in the translate stage. */
7127 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
7134 last_item = MLX5_FLOW_LAYER_ECPRI;
7136 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
7137 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY)
7138 return rte_flow_error_set
7140 RTE_FLOW_ERROR_TYPE_ITEM,
7141 NULL, "multiple integrity items not supported");
7142 ret = flow_dv_validate_item_integrity(dev, rule_items,
7146 last_item = MLX5_FLOW_ITEM_INTEGRITY;
7148 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
7149 ret = flow_dv_validate_item_aso_ct(dev, items,
7150 &item_flags, error);
7154 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
7155 /* tunnel offload item was processed before
7156 * list it here as a supported type
7160 return rte_flow_error_set(error, ENOTSUP,
7161 RTE_FLOW_ERROR_TYPE_ITEM,
7162 NULL, "item not supported");
7164 item_flags |= last_item;
7166 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
7167 int type = actions->type;
7168 bool shared_count = false;
7170 if (!mlx5_flow_os_action_supported(type))
7171 return rte_flow_error_set(error, ENOTSUP,
7172 RTE_FLOW_ERROR_TYPE_ACTION,
7174 "action not supported");
7175 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
7176 return rte_flow_error_set(error, ENOTSUP,
7177 RTE_FLOW_ERROR_TYPE_ACTION,
7178 actions, "too many actions");
7180 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
7181 return rte_flow_error_set(error, ENOTSUP,
7182 RTE_FLOW_ERROR_TYPE_ACTION,
7183 NULL, "meter action with policy "
7184 "must be the last action");
7186 case RTE_FLOW_ACTION_TYPE_VOID:
7188 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7189 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
7190 ret = flow_dv_validate_action_port_id(dev,
7197 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7200 case RTE_FLOW_ACTION_TYPE_FLAG:
7201 ret = flow_dv_validate_action_flag(dev, action_flags,
7205 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7206 /* Count all modify-header actions as one. */
7207 if (!(action_flags &
7208 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7210 action_flags |= MLX5_FLOW_ACTION_FLAG |
7211 MLX5_FLOW_ACTION_MARK_EXT;
7212 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7213 modify_after_mirror = 1;
7216 action_flags |= MLX5_FLOW_ACTION_FLAG;
7219 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7221 case RTE_FLOW_ACTION_TYPE_MARK:
7222 ret = flow_dv_validate_action_mark(dev, actions,
7227 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7228 /* Count all modify-header actions as one. */
7229 if (!(action_flags &
7230 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7232 action_flags |= MLX5_FLOW_ACTION_MARK |
7233 MLX5_FLOW_ACTION_MARK_EXT;
7234 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7235 modify_after_mirror = 1;
7237 action_flags |= MLX5_FLOW_ACTION_MARK;
7240 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7242 case RTE_FLOW_ACTION_TYPE_SET_META:
7243 ret = flow_dv_validate_action_set_meta(dev, actions,
7248 /* Count all modify-header actions as one action. */
7249 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7251 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7252 modify_after_mirror = 1;
7253 action_flags |= MLX5_FLOW_ACTION_SET_META;
7254 rw_act_num += MLX5_ACT_NUM_SET_META;
7256 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7257 ret = flow_dv_validate_action_set_tag(dev, actions,
7262 /* Count all modify-header actions as one action. */
7263 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7265 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7266 modify_after_mirror = 1;
7267 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7268 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7270 case RTE_FLOW_ACTION_TYPE_DROP:
7271 ret = mlx5_flow_validate_action_drop(action_flags,
7275 action_flags |= MLX5_FLOW_ACTION_DROP;
7278 case RTE_FLOW_ACTION_TYPE_QUEUE:
7279 ret = mlx5_flow_validate_action_queue(actions,
7284 queue_index = ((const struct rte_flow_action_queue *)
7285 (actions->conf))->index;
7286 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7289 case RTE_FLOW_ACTION_TYPE_RSS:
7290 rss = actions->conf;
7291 ret = mlx5_flow_validate_action_rss(actions,
7297 if (rss && sample_rss &&
7298 (sample_rss->level != rss->level ||
7299 sample_rss->types != rss->types))
7300 return rte_flow_error_set(error, ENOTSUP,
7301 RTE_FLOW_ERROR_TYPE_ACTION,
7303 "Can't use the different RSS types "
7304 "or level in the same flow");
7305 if (rss != NULL && rss->queue_num)
7306 queue_index = rss->queue[0];
7307 action_flags |= MLX5_FLOW_ACTION_RSS;
7310 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7312 mlx5_flow_validate_action_default_miss(action_flags,
7316 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
7319 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
7320 shared_count = true;
7322 case RTE_FLOW_ACTION_TYPE_COUNT:
7323 ret = flow_dv_validate_action_count(dev, shared_count,
7328 action_flags |= MLX5_FLOW_ACTION_COUNT;
7331 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7332 if (flow_dv_validate_action_pop_vlan(dev,
7338 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7339 modify_after_mirror = 1;
7340 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7343 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7344 ret = flow_dv_validate_action_push_vlan(dev,
7351 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7352 modify_after_mirror = 1;
7353 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7356 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7357 ret = flow_dv_validate_action_set_vlan_pcp
7358 (action_flags, actions, error);
7361 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7362 modify_after_mirror = 1;
7363 /* Count PCP with push_vlan command. */
7364 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
7366 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7367 ret = flow_dv_validate_action_set_vlan_vid
7368 (item_flags, action_flags,
7372 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7373 modify_after_mirror = 1;
7374 /* Count VID with push_vlan command. */
7375 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7376 rw_act_num += MLX5_ACT_NUM_MDF_VID;
7378 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7379 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7380 ret = flow_dv_validate_action_l2_encap(dev,
7386 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7389 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7390 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7391 ret = flow_dv_validate_action_decap(dev, action_flags,
7392 actions, item_flags,
7396 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7397 modify_after_mirror = 1;
7398 action_flags |= MLX5_FLOW_ACTION_DECAP;
7401 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7402 ret = flow_dv_validate_action_raw_encap_decap
7403 (dev, NULL, actions->conf, attr, &action_flags,
7404 &actions_n, actions, item_flags, error);
7408 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7409 decap = actions->conf;
7410 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
7412 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7416 encap = actions->conf;
7418 ret = flow_dv_validate_action_raw_encap_decap
7420 decap ? decap : &empty_decap, encap,
7421 attr, &action_flags, &actions_n,
7422 actions, item_flags, error);
7425 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7426 (action_flags & MLX5_FLOW_ACTION_DECAP))
7427 modify_after_mirror = 1;
7429 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7430 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7431 ret = flow_dv_validate_action_modify_mac(action_flags,
7437 /* Count all modify-header actions as one action. */
7438 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7440 action_flags |= actions->type ==
7441 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7442 MLX5_FLOW_ACTION_SET_MAC_SRC :
7443 MLX5_FLOW_ACTION_SET_MAC_DST;
7444 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7445 modify_after_mirror = 1;
7447 * Even if the source and destination MAC addresses have
7448 * overlap in the header with 4B alignment, the convert
7449 * function will handle them separately and 4 SW actions
7450 * will be created. And 2 actions will be added each
7451 * time no matter how many bytes of address will be set.
7453 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
7455 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7456 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7457 ret = flow_dv_validate_action_modify_ipv4(action_flags,
7463 /* Count all modify-header actions as one action. */
7464 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7466 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7467 modify_after_mirror = 1;
7468 action_flags |= actions->type ==
7469 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7470 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7471 MLX5_FLOW_ACTION_SET_IPV4_DST;
7472 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
7474 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7475 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7476 ret = flow_dv_validate_action_modify_ipv6(action_flags,
7482 if (item_ipv6_proto == IPPROTO_ICMPV6)
7483 return rte_flow_error_set(error, ENOTSUP,
7484 RTE_FLOW_ERROR_TYPE_ACTION,
7486 "Can't change header "
7487 "with ICMPv6 proto");
7488 /* Count all modify-header actions as one action. */
7489 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7491 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7492 modify_after_mirror = 1;
7493 action_flags |= actions->type ==
7494 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7495 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7496 MLX5_FLOW_ACTION_SET_IPV6_DST;
7497 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
7499 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7500 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7501 ret = flow_dv_validate_action_modify_tp(action_flags,
7507 /* Count all modify-header actions as one action. */
7508 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7510 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7511 modify_after_mirror = 1;
7512 action_flags |= actions->type ==
7513 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7514 MLX5_FLOW_ACTION_SET_TP_SRC :
7515 MLX5_FLOW_ACTION_SET_TP_DST;
7516 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
7518 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7519 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7520 ret = flow_dv_validate_action_modify_ttl(action_flags,
7526 /* Count all modify-header actions as one action. */
7527 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7529 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7530 modify_after_mirror = 1;
7531 action_flags |= actions->type ==
7532 RTE_FLOW_ACTION_TYPE_SET_TTL ?
7533 MLX5_FLOW_ACTION_SET_TTL :
7534 MLX5_FLOW_ACTION_DEC_TTL;
7535 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
7537 case RTE_FLOW_ACTION_TYPE_JUMP:
7538 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
7544 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7546 return rte_flow_error_set(error, EINVAL,
7547 RTE_FLOW_ERROR_TYPE_ACTION,
7549 "sample and jump action combination is not supported");
7551 action_flags |= MLX5_FLOW_ACTION_JUMP;
7553 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7554 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7555 ret = flow_dv_validate_action_modify_tcp_seq
7562 /* Count all modify-header actions as one action. */
7563 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7565 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7566 modify_after_mirror = 1;
7567 action_flags |= actions->type ==
7568 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7569 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7570 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7571 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
7573 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7574 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7575 ret = flow_dv_validate_action_modify_tcp_ack
7582 /* Count all modify-header actions as one action. */
7583 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7585 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7586 modify_after_mirror = 1;
7587 action_flags |= actions->type ==
7588 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7589 MLX5_FLOW_ACTION_INC_TCP_ACK :
7590 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7591 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
7593 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7595 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7596 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7597 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7599 case RTE_FLOW_ACTION_TYPE_METER:
7600 ret = mlx5_flow_validate_action_meter(dev,
7608 action_flags |= MLX5_FLOW_ACTION_METER;
7611 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
7613 /* Meter action will add one more TAG action. */
7614 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7616 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
7617 if (!attr->transfer && !attr->group)
7618 return rte_flow_error_set(error, ENOTSUP,
7619 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7621 "Shared ASO age action is not supported for group 0");
7622 if (action_flags & MLX5_FLOW_ACTION_AGE)
7623 return rte_flow_error_set
7625 RTE_FLOW_ERROR_TYPE_ACTION,
7627 "duplicate age actions set");
7628 action_flags |= MLX5_FLOW_ACTION_AGE;
7631 case RTE_FLOW_ACTION_TYPE_AGE:
7632 ret = flow_dv_validate_action_age(action_flags,
7638 * Validate the regular AGE action (using counter)
7639 * mutual exclusion with share counter actions.
7641 if (!priv->sh->flow_hit_aso_en) {
7643 return rte_flow_error_set
7645 RTE_FLOW_ERROR_TYPE_ACTION,
7647 "old age and shared count combination is not supported");
7649 return rte_flow_error_set
7651 RTE_FLOW_ERROR_TYPE_ACTION,
7653 "old age action and count must be in the same sub flow");
7655 action_flags |= MLX5_FLOW_ACTION_AGE;
7658 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7659 ret = flow_dv_validate_action_modify_ipv4_dscp
7666 /* Count all modify-header actions as one action. */
7667 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7669 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7670 modify_after_mirror = 1;
7671 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7672 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7674 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7675 ret = flow_dv_validate_action_modify_ipv6_dscp
7682 /* Count all modify-header actions as one action. */
7683 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7685 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7686 modify_after_mirror = 1;
7687 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7688 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7690 case RTE_FLOW_ACTION_TYPE_SAMPLE:
7691 ret = flow_dv_validate_action_sample(&action_flags,
7700 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
7703 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7704 ret = flow_dv_validate_action_modify_field(dev,
7711 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7712 modify_after_mirror = 1;
7713 /* Count all modify-header actions as one action. */
7714 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7716 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
7719 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7720 ret = flow_dv_validate_action_aso_ct(dev, action_flags,
7725 action_flags |= MLX5_FLOW_ACTION_CT;
7727 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
7728 /* tunnel offload action was processed before
7729 * list it here as a supported type
7733 return rte_flow_error_set(error, ENOTSUP,
7734 RTE_FLOW_ERROR_TYPE_ACTION,
7736 "action not supported");
7740 * Validate actions in flow rules
7741 * - Explicit decap action is prohibited by the tunnel offload API.
7742 * - Drop action in tunnel steer rule is prohibited by the API.
7743 * - Application cannot use MARK action because it's value can mask
7744 * tunnel default miss nitification.
7745 * - JUMP in tunnel match rule has no support in current PMD
7747 * - TAG & META are reserved for future uses.
7749 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
7750 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
7751 MLX5_FLOW_ACTION_MARK |
7752 MLX5_FLOW_ACTION_SET_TAG |
7753 MLX5_FLOW_ACTION_SET_META |
7754 MLX5_FLOW_ACTION_DROP;
7756 if (action_flags & bad_actions_mask)
7757 return rte_flow_error_set
7759 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7760 "Invalid RTE action in tunnel "
7762 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
7763 return rte_flow_error_set
7765 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7766 "tunnel set decap rule must terminate "
7769 return rte_flow_error_set
7771 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7772 "tunnel flows for ingress traffic only");
7774 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
7775 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
7776 MLX5_FLOW_ACTION_MARK |
7777 MLX5_FLOW_ACTION_SET_TAG |
7778 MLX5_FLOW_ACTION_SET_META;
7780 if (action_flags & bad_actions_mask)
7781 return rte_flow_error_set
7783 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7784 "Invalid RTE action in tunnel "
7788 * Validate the drop action mutual exclusion with other actions.
7789 * Drop action is mutually-exclusive with any other action, except for
7791 * Drop action compatibility with tunnel offload was already validated.
7793 if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
7794 MLX5_FLOW_ACTION_TUNNEL_MATCH));
7795 else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
7796 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
7797 return rte_flow_error_set(error, EINVAL,
7798 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7799 "Drop action is mutually-exclusive "
7800 "with any other action, except for "
7802 /* Eswitch has few restrictions on using items and actions */
7803 if (attr->transfer) {
7804 if (!mlx5_flow_ext_mreg_supported(dev) &&
7805 action_flags & MLX5_FLOW_ACTION_FLAG)
7806 return rte_flow_error_set(error, ENOTSUP,
7807 RTE_FLOW_ERROR_TYPE_ACTION,
7809 "unsupported action FLAG");
7810 if (!mlx5_flow_ext_mreg_supported(dev) &&
7811 action_flags & MLX5_FLOW_ACTION_MARK)
7812 return rte_flow_error_set(error, ENOTSUP,
7813 RTE_FLOW_ERROR_TYPE_ACTION,
7815 "unsupported action MARK");
7816 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
7817 return rte_flow_error_set(error, ENOTSUP,
7818 RTE_FLOW_ERROR_TYPE_ACTION,
7820 "unsupported action QUEUE");
7821 if (action_flags & MLX5_FLOW_ACTION_RSS)
7822 return rte_flow_error_set(error, ENOTSUP,
7823 RTE_FLOW_ERROR_TYPE_ACTION,
7825 "unsupported action RSS");
7826 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
7827 return rte_flow_error_set(error, EINVAL,
7828 RTE_FLOW_ERROR_TYPE_ACTION,
7830 "no fate action is found");
7832 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
7833 return rte_flow_error_set(error, EINVAL,
7834 RTE_FLOW_ERROR_TYPE_ACTION,
7836 "no fate action is found");
7839 * Continue validation for Xcap and VLAN actions.
7840 * If hairpin is working in explicit TX rule mode, there is no actions
7841 * splitting and the validation of hairpin ingress flow should be the
7842 * same as other standard flows.
7844 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
7845 MLX5_FLOW_VLAN_ACTIONS)) &&
7846 (queue_index == 0xFFFF ||
7847 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN ||
7848 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
7849 conf->tx_explicit != 0))) {
7850 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
7851 MLX5_FLOW_XCAP_ACTIONS)
7852 return rte_flow_error_set(error, ENOTSUP,
7853 RTE_FLOW_ERROR_TYPE_ACTION,
7854 NULL, "encap and decap "
7855 "combination aren't supported");
7856 if (!attr->transfer && attr->ingress) {
7857 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7858 return rte_flow_error_set
7860 RTE_FLOW_ERROR_TYPE_ACTION,
7861 NULL, "encap is not supported"
7862 " for ingress traffic");
7863 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7864 return rte_flow_error_set
7866 RTE_FLOW_ERROR_TYPE_ACTION,
7867 NULL, "push VLAN action not "
7868 "supported for ingress");
7869 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
7870 MLX5_FLOW_VLAN_ACTIONS)
7871 return rte_flow_error_set
7873 RTE_FLOW_ERROR_TYPE_ACTION,
7874 NULL, "no support for "
7875 "multiple VLAN actions");
7878 if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
7879 if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
7880 ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
7882 return rte_flow_error_set
7884 RTE_FLOW_ERROR_TYPE_ACTION,
7885 NULL, "fate action not supported for "
7886 "meter with policy");
7888 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
7889 return rte_flow_error_set
7891 RTE_FLOW_ERROR_TYPE_ACTION,
7892 NULL, "modify header action in egress "
7893 "cannot be done before meter action");
7894 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7895 return rte_flow_error_set
7897 RTE_FLOW_ERROR_TYPE_ACTION,
7898 NULL, "encap action in egress "
7899 "cannot be done before meter action");
7900 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7901 return rte_flow_error_set
7903 RTE_FLOW_ERROR_TYPE_ACTION,
7904 NULL, "push vlan action in egress "
7905 "cannot be done before meter action");
7909 * Hairpin flow will add one more TAG action in TX implicit mode.
7910 * In TX explicit mode, there will be no hairpin flow ID.
7913 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7914 /* extra metadata enabled: one more TAG action will be add. */
7915 if (dev_conf->dv_flow_en &&
7916 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
7917 mlx5_flow_ext_mreg_supported(dev))
7918 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7920 flow_dv_modify_hdr_action_max(dev, is_root)) {
7921 return rte_flow_error_set(error, ENOTSUP,
7922 RTE_FLOW_ERROR_TYPE_ACTION,
7923 NULL, "too many header modify"
7924 " actions to support");
7926 /* Eswitch egress mirror and modify flow has limitation on CX5 */
7927 if (fdb_mirror_limit && modify_after_mirror)
7928 return rte_flow_error_set(error, EINVAL,
7929 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7930 "sample before modify action is not supported");
7935 * Internal preparation function. Allocates the DV flow size,
7936 * this size is constant.
7939 * Pointer to the rte_eth_dev structure.
7941 * Pointer to the flow attributes.
7943 * Pointer to the list of items.
7944 * @param[in] actions
7945 * Pointer to the list of actions.
7947 * Pointer to the error structure.
7950 * Pointer to mlx5_flow object on success,
7951 * otherwise NULL and rte_errno is set.
7953 static struct mlx5_flow *
7954 flow_dv_prepare(struct rte_eth_dev *dev,
7955 const struct rte_flow_attr *attr __rte_unused,
7956 const struct rte_flow_item items[] __rte_unused,
7957 const struct rte_flow_action actions[] __rte_unused,
7958 struct rte_flow_error *error)
7960 uint32_t handle_idx = 0;
7961 struct mlx5_flow *dev_flow;
7962 struct mlx5_flow_handle *dev_handle;
7963 struct mlx5_priv *priv = dev->data->dev_private;
7964 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
7967 wks->skip_matcher_reg = 0;
7969 wks->final_policy = NULL;
7970 /* In case of corrupting the memory. */
7971 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
7972 rte_flow_error_set(error, ENOSPC,
7973 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7974 "not free temporary device flow");
7977 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
7980 rte_flow_error_set(error, ENOMEM,
7981 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7982 "not enough memory to create flow handle");
7985 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
7986 dev_flow = &wks->flows[wks->flow_idx++];
7987 memset(dev_flow, 0, sizeof(*dev_flow));
7988 dev_flow->handle = dev_handle;
7989 dev_flow->handle_idx = handle_idx;
7990 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
7991 dev_flow->ingress = attr->ingress;
7992 dev_flow->dv.transfer = attr->transfer;
7996 #ifdef RTE_LIBRTE_MLX5_DEBUG
7998 * Sanity check for match mask and value. Similar to check_valid_spec() in
7999 * kernel driver. If unmasked bit is present in value, it returns failure.
8002 * pointer to match mask buffer.
8003 * @param match_value
8004 * pointer to match value buffer.
8007 * 0 if valid, -EINVAL otherwise.
8010 flow_dv_check_valid_spec(void *match_mask, void *match_value)
8012 uint8_t *m = match_mask;
8013 uint8_t *v = match_value;
8016 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
8019 "match_value differs from match_criteria"
8020 " %p[%u] != %p[%u]",
8021 match_value, i, match_mask, i);
8030 * Add match of ip_version.
8034 * @param[in] headers_v
8035 * Values header pointer.
8036 * @param[in] headers_m
8037 * Masks header pointer.
8038 * @param[in] ip_version
8039 * The IP version to set.
8042 flow_dv_set_match_ip_version(uint32_t group,
8048 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
8050 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
8052 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
8053 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
8054 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
8058 * Add Ethernet item to matcher and to the value.
8060 * @param[in, out] matcher
8062 * @param[in, out] key
8063 * Flow matcher value.
8065 * Flow pattern to translate.
8067 * Item is inner pattern.
8070 flow_dv_translate_item_eth(void *matcher, void *key,
8071 const struct rte_flow_item *item, int inner,
8074 const struct rte_flow_item_eth *eth_m = item->mask;
8075 const struct rte_flow_item_eth *eth_v = item->spec;
8076 const struct rte_flow_item_eth nic_mask = {
8077 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8078 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
8079 .type = RTE_BE16(0xffff),
8092 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8094 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8096 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8098 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8100 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
8101 ð_m->dst, sizeof(eth_m->dst));
8102 /* The value must be in the range of the mask. */
8103 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
8104 for (i = 0; i < sizeof(eth_m->dst); ++i)
8105 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
8106 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
8107 ð_m->src, sizeof(eth_m->src));
8108 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
8109 /* The value must be in the range of the mask. */
8110 for (i = 0; i < sizeof(eth_m->dst); ++i)
8111 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
8113 * HW supports match on one Ethertype, the Ethertype following the last
8114 * VLAN tag of the packet (see PRM).
8115 * Set match on ethertype only if ETH header is not followed by VLAN.
8116 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8117 * ethertype, and use ip_version field instead.
8118 * eCPRI over Ether layer will use type value 0xAEFE.
8120 if (eth_m->type == 0xFFFF) {
8121 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
8122 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8123 switch (eth_v->type) {
8124 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8125 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8127 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
8128 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8129 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8131 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8132 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8134 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8135 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8141 if (eth_m->has_vlan) {
8142 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8143 if (eth_v->has_vlan) {
8145 * Here, when also has_more_vlan field in VLAN item is
8146 * not set, only single-tagged packets will be matched.
8148 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8152 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8153 rte_be_to_cpu_16(eth_m->type));
8154 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
8155 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
8159 * Add VLAN item to matcher and to the value.
8161 * @param[in, out] dev_flow
8163 * @param[in, out] matcher
8165 * @param[in, out] key
8166 * Flow matcher value.
8168 * Flow pattern to translate.
8170 * Item is inner pattern.
8173 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
8174 void *matcher, void *key,
8175 const struct rte_flow_item *item,
8176 int inner, uint32_t group)
8178 const struct rte_flow_item_vlan *vlan_m = item->mask;
8179 const struct rte_flow_item_vlan *vlan_v = item->spec;
8186 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8188 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8190 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8192 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8194 * This is workaround, masks are not supported,
8195 * and pre-validated.
8198 dev_flow->handle->vf_vlan.tag =
8199 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
8202 * When VLAN item exists in flow, mark packet as tagged,
8203 * even if TCI is not specified.
8205 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
8206 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8207 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8212 vlan_m = &rte_flow_item_vlan_mask;
8213 tci_m = rte_be_to_cpu_16(vlan_m->tci);
8214 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
8215 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
8216 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
8217 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
8218 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
8219 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
8220 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
8222 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8223 * ethertype, and use ip_version field instead.
8225 if (vlan_m->inner_type == 0xFFFF) {
8226 switch (vlan_v->inner_type) {
8227 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8228 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8229 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8230 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8232 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8233 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8235 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8236 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8242 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
8243 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8244 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8245 /* Only one vlan_tag bit can be set. */
8246 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8249 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8250 rte_be_to_cpu_16(vlan_m->inner_type));
8251 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
8252 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
8256 * Add IPV4 item to matcher and to the value.
8258 * @param[in, out] matcher
8260 * @param[in, out] key
8261 * Flow matcher value.
8263 * Flow pattern to translate.
8265 * Item is inner pattern.
8267 * The group to insert the rule.
8270 flow_dv_translate_item_ipv4(void *matcher, void *key,
8271 const struct rte_flow_item *item,
8272 int inner, uint32_t group)
8274 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
8275 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
8276 const struct rte_flow_item_ipv4 nic_mask = {
8278 .src_addr = RTE_BE32(0xffffffff),
8279 .dst_addr = RTE_BE32(0xffffffff),
8280 .type_of_service = 0xff,
8281 .next_proto_id = 0xff,
8282 .time_to_live = 0xff,
8289 uint8_t tos, ihl_m, ihl_v;
8292 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8294 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8296 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8298 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8300 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
8305 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8306 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8307 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8308 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8309 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
8310 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
8311 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8312 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8313 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8314 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8315 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
8316 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
8317 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
8318 ihl_m = ipv4_m->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8319 ihl_v = ipv4_v->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK;
8320 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_ihl, ihl_m);
8321 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl, ihl_m & ihl_v);
8322 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
8323 ipv4_m->hdr.type_of_service);
8324 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
8325 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
8326 ipv4_m->hdr.type_of_service >> 2);
8327 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
8328 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8329 ipv4_m->hdr.next_proto_id);
8330 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8331 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
8332 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8333 ipv4_m->hdr.time_to_live);
8334 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8335 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
8336 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8337 !!(ipv4_m->hdr.fragment_offset));
8338 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8339 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
8343 * Add IPV6 item to matcher and to the value.
8345 * @param[in, out] matcher
8347 * @param[in, out] key
8348 * Flow matcher value.
8350 * Flow pattern to translate.
8352 * Item is inner pattern.
8354 * The group to insert the rule.
8357 flow_dv_translate_item_ipv6(void *matcher, void *key,
8358 const struct rte_flow_item *item,
8359 int inner, uint32_t group)
8361 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
8362 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
8363 const struct rte_flow_item_ipv6 nic_mask = {
8366 "\xff\xff\xff\xff\xff\xff\xff\xff"
8367 "\xff\xff\xff\xff\xff\xff\xff\xff",
8369 "\xff\xff\xff\xff\xff\xff\xff\xff"
8370 "\xff\xff\xff\xff\xff\xff\xff\xff",
8371 .vtc_flow = RTE_BE32(0xffffffff),
8378 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8379 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8388 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8390 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8392 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8394 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8396 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
8401 size = sizeof(ipv6_m->hdr.dst_addr);
8402 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8403 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8404 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8405 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8406 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
8407 for (i = 0; i < size; ++i)
8408 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
8409 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8410 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8411 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8412 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8413 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
8414 for (i = 0; i < size; ++i)
8415 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
8417 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
8418 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
8419 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
8420 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
8421 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
8422 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
8425 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
8427 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
8430 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
8432 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
8436 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8438 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8439 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
8441 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8442 ipv6_m->hdr.hop_limits);
8443 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8444 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
8445 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8446 !!(ipv6_m->has_frag_ext));
8447 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8448 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
8452 * Add IPV6 fragment extension item to matcher and to the value.
8454 * @param[in, out] matcher
8456 * @param[in, out] key
8457 * Flow matcher value.
8459 * Flow pattern to translate.
8461 * Item is inner pattern.
8464 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
8465 const struct rte_flow_item *item,
8468 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
8469 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
8470 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
8472 .next_header = 0xff,
8473 .frag_data = RTE_BE16(0xffff),
8480 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8482 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8484 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8486 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8488 /* IPv6 fragment extension item exists, so packet is IP fragment. */
8489 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
8490 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
8491 if (!ipv6_frag_ext_v)
8493 if (!ipv6_frag_ext_m)
8494 ipv6_frag_ext_m = &nic_mask;
8495 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8496 ipv6_frag_ext_m->hdr.next_header);
8497 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8498 ipv6_frag_ext_v->hdr.next_header &
8499 ipv6_frag_ext_m->hdr.next_header);
8503 * Add TCP item to matcher and to the value.
8505 * @param[in, out] matcher
8507 * @param[in, out] key
8508 * Flow matcher value.
8510 * Flow pattern to translate.
8512 * Item is inner pattern.
8515 flow_dv_translate_item_tcp(void *matcher, void *key,
8516 const struct rte_flow_item *item,
8519 const struct rte_flow_item_tcp *tcp_m = item->mask;
8520 const struct rte_flow_item_tcp *tcp_v = item->spec;
8525 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8527 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8529 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8531 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8533 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8534 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
8538 tcp_m = &rte_flow_item_tcp_mask;
8539 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
8540 rte_be_to_cpu_16(tcp_m->hdr.src_port));
8541 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
8542 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
8543 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
8544 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
8545 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
8546 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
8547 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
8548 tcp_m->hdr.tcp_flags);
8549 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
8550 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
8554 * Add UDP item to matcher and to the value.
8556 * @param[in, out] matcher
8558 * @param[in, out] key
8559 * Flow matcher value.
8561 * Flow pattern to translate.
8563 * Item is inner pattern.
8566 flow_dv_translate_item_udp(void *matcher, void *key,
8567 const struct rte_flow_item *item,
8570 const struct rte_flow_item_udp *udp_m = item->mask;
8571 const struct rte_flow_item_udp *udp_v = item->spec;
8576 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8578 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8580 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8582 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8584 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8585 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
8589 udp_m = &rte_flow_item_udp_mask;
8590 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
8591 rte_be_to_cpu_16(udp_m->hdr.src_port));
8592 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
8593 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
8594 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
8595 rte_be_to_cpu_16(udp_m->hdr.dst_port));
8596 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8597 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
8601 * Add GRE optional Key item to matcher and to the value.
8603 * @param[in, out] matcher
8605 * @param[in, out] key
8606 * Flow matcher value.
8608 * Flow pattern to translate.
8610 * Item is inner pattern.
8613 flow_dv_translate_item_gre_key(void *matcher, void *key,
8614 const struct rte_flow_item *item)
8616 const rte_be32_t *key_m = item->mask;
8617 const rte_be32_t *key_v = item->spec;
8618 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8619 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8620 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
8622 /* GRE K bit must be on and should already be validated */
8623 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
8624 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
8628 key_m = &gre_key_default_mask;
8629 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
8630 rte_be_to_cpu_32(*key_m) >> 8);
8631 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
8632 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
8633 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
8634 rte_be_to_cpu_32(*key_m) & 0xFF);
8635 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
8636 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
8640 * Add GRE item to matcher and to the value.
8642 * @param[in, out] matcher
8644 * @param[in, out] key
8645 * Flow matcher value.
8647 * Flow pattern to translate.
8649 * Item is inner pattern.
8652 flow_dv_translate_item_gre(void *matcher, void *key,
8653 const struct rte_flow_item *item,
8656 const struct rte_flow_item_gre *gre_m = item->mask;
8657 const struct rte_flow_item_gre *gre_v = item->spec;
8660 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8661 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8668 uint16_t s_present:1;
8669 uint16_t k_present:1;
8670 uint16_t rsvd_bit1:1;
8671 uint16_t c_present:1;
8675 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
8678 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8680 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8682 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8684 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8686 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8687 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
8691 gre_m = &rte_flow_item_gre_mask;
8692 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
8693 rte_be_to_cpu_16(gre_m->protocol));
8694 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8695 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
8696 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
8697 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
8698 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
8699 gre_crks_rsvd0_ver_m.c_present);
8700 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
8701 gre_crks_rsvd0_ver_v.c_present &
8702 gre_crks_rsvd0_ver_m.c_present);
8703 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
8704 gre_crks_rsvd0_ver_m.k_present);
8705 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
8706 gre_crks_rsvd0_ver_v.k_present &
8707 gre_crks_rsvd0_ver_m.k_present);
8708 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
8709 gre_crks_rsvd0_ver_m.s_present);
8710 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
8711 gre_crks_rsvd0_ver_v.s_present &
8712 gre_crks_rsvd0_ver_m.s_present);
8716 * Add NVGRE item to matcher and to the value.
8718 * @param[in, out] matcher
8720 * @param[in, out] key
8721 * Flow matcher value.
8723 * Flow pattern to translate.
8725 * Item is inner pattern.
8728 flow_dv_translate_item_nvgre(void *matcher, void *key,
8729 const struct rte_flow_item *item,
8732 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
8733 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
8734 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8735 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8736 const char *tni_flow_id_m;
8737 const char *tni_flow_id_v;
8743 /* For NVGRE, GRE header fields must be set with defined values. */
8744 const struct rte_flow_item_gre gre_spec = {
8745 .c_rsvd0_ver = RTE_BE16(0x2000),
8746 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
8748 const struct rte_flow_item_gre gre_mask = {
8749 .c_rsvd0_ver = RTE_BE16(0xB000),
8750 .protocol = RTE_BE16(UINT16_MAX),
8752 const struct rte_flow_item gre_item = {
8757 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
8761 nvgre_m = &rte_flow_item_nvgre_mask;
8762 tni_flow_id_m = (const char *)nvgre_m->tni;
8763 tni_flow_id_v = (const char *)nvgre_v->tni;
8764 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
8765 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
8766 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
8767 memcpy(gre_key_m, tni_flow_id_m, size);
8768 for (i = 0; i < size; ++i)
8769 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
8773 * Add VXLAN item to matcher and to the value.
8776 * Pointer to the Ethernet device structure.
8778 * Flow rule attributes.
8779 * @param[in, out] matcher
8781 * @param[in, out] key
8782 * Flow matcher value.
8784 * Flow pattern to translate.
8786 * Item is inner pattern.
8789 flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
8790 const struct rte_flow_attr *attr,
8791 void *matcher, void *key,
8792 const struct rte_flow_item *item,
8795 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
8796 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
8801 uint32_t *tunnel_header_v;
8802 uint32_t *tunnel_header_m;
8804 struct mlx5_priv *priv = dev->data->dev_private;
8805 const struct rte_flow_item_vxlan nic_mask = {
8806 .vni = "\xff\xff\xff",
8811 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8813 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8815 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8817 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8819 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8820 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8821 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8822 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8823 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8825 dport = MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport);
8829 if ((!attr->group && !priv->sh->tunnel_header_0_1) ||
8830 (attr->group && !priv->sh->misc5_cap))
8831 vxlan_m = &rte_flow_item_vxlan_mask;
8833 vxlan_m = &nic_mask;
8835 if ((priv->sh->steering_format_version ==
8836 MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
8837 dport != MLX5_UDP_PORT_VXLAN) ||
8838 (!attr->group && !attr->transfer && !priv->sh->tunnel_header_0_1) ||
8839 ((attr->group || attr->transfer) && !priv->sh->misc5_cap)) {
8846 misc_m = MLX5_ADDR_OF(fte_match_param,
8847 matcher, misc_parameters);
8848 misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8849 size = sizeof(vxlan_m->vni);
8850 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
8851 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
8852 memcpy(vni_m, vxlan_m->vni, size);
8853 for (i = 0; i < size; ++i)
8854 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8857 misc5_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_5);
8858 misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
8859 tunnel_header_v = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
8862 tunnel_header_m = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
8865 *tunnel_header_v = (vxlan_v->vni[0] & vxlan_m->vni[0]) |
8866 (vxlan_v->vni[1] & vxlan_m->vni[1]) << 8 |
8867 (vxlan_v->vni[2] & vxlan_m->vni[2]) << 16;
8868 if (*tunnel_header_v)
8869 *tunnel_header_m = vxlan_m->vni[0] |
8870 vxlan_m->vni[1] << 8 |
8871 vxlan_m->vni[2] << 16;
8873 *tunnel_header_m = 0x0;
8874 *tunnel_header_v |= (vxlan_v->rsvd1 & vxlan_m->rsvd1) << 24;
8875 if (vxlan_v->rsvd1 & vxlan_m->rsvd1)
8876 *tunnel_header_m |= vxlan_m->rsvd1 << 24;
8880 * Add VXLAN-GPE item to matcher and to the value.
8882 * @param[in, out] matcher
8884 * @param[in, out] key
8885 * Flow matcher value.
8887 * Flow pattern to translate.
8889 * Item is inner pattern.
8893 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
8894 const struct rte_flow_item *item, int inner)
8896 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
8897 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
8901 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
8903 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8909 uint8_t flags_m = 0xff;
8910 uint8_t flags_v = 0xc;
8913 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8915 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8917 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8919 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8921 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8922 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8923 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8924 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8925 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8930 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
8931 size = sizeof(vxlan_m->vni);
8932 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
8933 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
8934 memcpy(vni_m, vxlan_m->vni, size);
8935 for (i = 0; i < size; ++i)
8936 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8937 if (vxlan_m->flags) {
8938 flags_m = vxlan_m->flags;
8939 flags_v = vxlan_v->flags;
8941 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
8942 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
8943 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
8945 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
8950 * Add Geneve item to matcher and to the value.
8952 * @param[in, out] matcher
8954 * @param[in, out] key
8955 * Flow matcher value.
8957 * Flow pattern to translate.
8959 * Item is inner pattern.
8963 flow_dv_translate_item_geneve(void *matcher, void *key,
8964 const struct rte_flow_item *item, int inner)
8966 const struct rte_flow_item_geneve *geneve_m = item->mask;
8967 const struct rte_flow_item_geneve *geneve_v = item->spec;
8970 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8971 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8980 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8982 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8984 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8986 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8988 dport = MLX5_UDP_PORT_GENEVE;
8989 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8990 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8991 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8996 geneve_m = &rte_flow_item_geneve_mask;
8997 size = sizeof(geneve_m->vni);
8998 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
8999 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
9000 memcpy(vni_m, geneve_m->vni, size);
9001 for (i = 0; i < size; ++i)
9002 vni_v[i] = vni_m[i] & geneve_v->vni[i];
9003 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
9004 rte_be_to_cpu_16(geneve_m->protocol));
9005 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
9006 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
9007 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
9008 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
9009 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
9010 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9011 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
9012 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
9013 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9014 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9015 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9016 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
9017 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
9021 * Create Geneve TLV option resource.
9023 * @param dev[in, out]
9024 * Pointer to rte_eth_dev structure.
9025 * @param[in, out] tag_be24
9026 * Tag value in big endian then R-shift 8.
9027 * @parm[in, out] dev_flow
9028 * Pointer to the dev_flow.
9030 * pointer to error structure.
9033 * 0 on success otherwise -errno and errno is set.
9037 flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
9038 const struct rte_flow_item *item,
9039 struct rte_flow_error *error)
9041 struct mlx5_priv *priv = dev->data->dev_private;
9042 struct mlx5_dev_ctx_shared *sh = priv->sh;
9043 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
9044 sh->geneve_tlv_option_resource;
9045 struct mlx5_devx_obj *obj;
9046 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9051 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
9052 if (geneve_opt_resource != NULL) {
9053 if (geneve_opt_resource->option_class ==
9054 geneve_opt_v->option_class &&
9055 geneve_opt_resource->option_type ==
9056 geneve_opt_v->option_type &&
9057 geneve_opt_resource->length ==
9058 geneve_opt_v->option_len) {
9059 /* We already have GENVE TLV option obj allocated. */
9060 __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
9063 ret = rte_flow_error_set(error, ENOMEM,
9064 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9065 "Only one GENEVE TLV option supported");
9069 /* Create a GENEVE TLV object and resource. */
9070 obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
9071 geneve_opt_v->option_class,
9072 geneve_opt_v->option_type,
9073 geneve_opt_v->option_len);
9075 ret = rte_flow_error_set(error, ENODATA,
9076 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9077 "Failed to create GENEVE TLV Devx object");
9080 sh->geneve_tlv_option_resource =
9081 mlx5_malloc(MLX5_MEM_ZERO,
9082 sizeof(*geneve_opt_resource),
9084 if (!sh->geneve_tlv_option_resource) {
9085 claim_zero(mlx5_devx_cmd_destroy(obj));
9086 ret = rte_flow_error_set(error, ENOMEM,
9087 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9088 "GENEVE TLV object memory allocation failed");
9091 geneve_opt_resource = sh->geneve_tlv_option_resource;
9092 geneve_opt_resource->obj = obj;
9093 geneve_opt_resource->option_class = geneve_opt_v->option_class;
9094 geneve_opt_resource->option_type = geneve_opt_v->option_type;
9095 geneve_opt_resource->length = geneve_opt_v->option_len;
9096 __atomic_store_n(&geneve_opt_resource->refcnt, 1,
9100 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
9105 * Add Geneve TLV option item to matcher.
9107 * @param[in, out] dev
9108 * Pointer to rte_eth_dev structure.
9109 * @param[in, out] matcher
9111 * @param[in, out] key
9112 * Flow matcher value.
9114 * Flow pattern to translate.
9116 * Pointer to error structure.
9119 flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *matcher,
9120 void *key, const struct rte_flow_item *item,
9121 struct rte_flow_error *error)
9123 const struct rte_flow_item_geneve_opt *geneve_opt_m = item->mask;
9124 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9125 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9126 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9127 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9129 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9130 rte_be32_t opt_data_key = 0, opt_data_mask = 0;
9136 geneve_opt_m = &rte_flow_item_geneve_opt_mask;
9137 ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
9140 DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
9144 * Set the option length in GENEVE header if not requested.
9145 * The GENEVE TLV option length is expressed by the option length field
9146 * in the GENEVE header.
9147 * If the option length was not requested but the GENEVE TLV option item
9148 * is present we set the option length field implicitly.
9150 if (!MLX5_GET16(fte_match_set_misc, misc_m, geneve_opt_len)) {
9151 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9152 MLX5_GENEVE_OPTLEN_MASK);
9153 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9154 geneve_opt_v->option_len + 1);
9156 MLX5_SET(fte_match_set_misc, misc_m, geneve_tlv_option_0_exist, 1);
9157 MLX5_SET(fte_match_set_misc, misc_v, geneve_tlv_option_0_exist, 1);
9159 if (geneve_opt_v->data) {
9160 memcpy(&opt_data_key, geneve_opt_v->data,
9161 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9162 sizeof(opt_data_key)));
9163 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9164 sizeof(opt_data_key));
9165 memcpy(&opt_data_mask, geneve_opt_m->data,
9166 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9167 sizeof(opt_data_mask)));
9168 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9169 sizeof(opt_data_mask));
9170 MLX5_SET(fte_match_set_misc3, misc3_m,
9171 geneve_tlv_option_0_data,
9172 rte_be_to_cpu_32(opt_data_mask));
9173 MLX5_SET(fte_match_set_misc3, misc3_v,
9174 geneve_tlv_option_0_data,
9175 rte_be_to_cpu_32(opt_data_key & opt_data_mask));
9181 * Add MPLS item to matcher and to the value.
9183 * @param[in, out] matcher
9185 * @param[in, out] key
9186 * Flow matcher value.
9188 * Flow pattern to translate.
9189 * @param[in] prev_layer
9190 * The protocol layer indicated in previous item.
9192 * Item is inner pattern.
9195 flow_dv_translate_item_mpls(void *matcher, void *key,
9196 const struct rte_flow_item *item,
9197 uint64_t prev_layer,
9200 const uint32_t *in_mpls_m = item->mask;
9201 const uint32_t *in_mpls_v = item->spec;
9202 uint32_t *out_mpls_m = 0;
9203 uint32_t *out_mpls_v = 0;
9204 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9205 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9206 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
9208 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9209 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9210 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9212 switch (prev_layer) {
9213 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9214 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
9215 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9216 MLX5_UDP_PORT_MPLS);
9218 case MLX5_FLOW_LAYER_GRE:
9220 case MLX5_FLOW_LAYER_GRE_KEY:
9221 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
9222 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9223 RTE_ETHER_TYPE_MPLS);
9231 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
9232 switch (prev_layer) {
9233 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9235 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9236 outer_first_mpls_over_udp);
9238 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9239 outer_first_mpls_over_udp);
9241 case MLX5_FLOW_LAYER_GRE:
9243 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9244 outer_first_mpls_over_gre);
9246 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9247 outer_first_mpls_over_gre);
9250 /* Inner MPLS not over GRE is not supported. */
9253 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9257 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9263 if (out_mpls_m && out_mpls_v) {
9264 *out_mpls_m = *in_mpls_m;
9265 *out_mpls_v = *in_mpls_v & *in_mpls_m;
9270 * Add metadata register item to matcher
9272 * @param[in, out] matcher
9274 * @param[in, out] key
9275 * Flow matcher value.
9276 * @param[in] reg_type
9277 * Type of device metadata register
9284 flow_dv_match_meta_reg(void *matcher, void *key,
9285 enum modify_reg reg_type,
9286 uint32_t data, uint32_t mask)
9289 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
9291 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9297 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
9298 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
9301 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
9302 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
9306 * The metadata register C0 field might be divided into
9307 * source vport index and META item value, we should set
9308 * this field according to specified mask, not as whole one.
9310 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
9312 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
9313 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
9316 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
9319 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
9320 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
9323 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
9324 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
9327 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
9328 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
9331 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
9332 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
9335 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
9336 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
9339 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
9340 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
9343 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
9344 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
9353 * Add MARK item to matcher
9356 * The device to configure through.
9357 * @param[in, out] matcher
9359 * @param[in, out] key
9360 * Flow matcher value.
9362 * Flow pattern to translate.
9365 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
9366 void *matcher, void *key,
9367 const struct rte_flow_item *item)
9369 struct mlx5_priv *priv = dev->data->dev_private;
9370 const struct rte_flow_item_mark *mark;
9374 mark = item->mask ? (const void *)item->mask :
9375 &rte_flow_item_mark_mask;
9376 mask = mark->id & priv->sh->dv_mark_mask;
9377 mark = (const void *)item->spec;
9379 value = mark->id & priv->sh->dv_mark_mask & mask;
9381 enum modify_reg reg;
9383 /* Get the metadata register index for the mark. */
9384 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
9385 MLX5_ASSERT(reg > 0);
9386 if (reg == REG_C_0) {
9387 struct mlx5_priv *priv = dev->data->dev_private;
9388 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9389 uint32_t shl_c0 = rte_bsf32(msk_c0);
9395 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9400 * Add META item to matcher
9403 * The devich to configure through.
9404 * @param[in, out] matcher
9406 * @param[in, out] key
9407 * Flow matcher value.
9409 * Attributes of flow that includes this item.
9411 * Flow pattern to translate.
9414 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
9415 void *matcher, void *key,
9416 const struct rte_flow_attr *attr,
9417 const struct rte_flow_item *item)
9419 const struct rte_flow_item_meta *meta_m;
9420 const struct rte_flow_item_meta *meta_v;
9422 meta_m = (const void *)item->mask;
9424 meta_m = &rte_flow_item_meta_mask;
9425 meta_v = (const void *)item->spec;
9428 uint32_t value = meta_v->data;
9429 uint32_t mask = meta_m->data;
9431 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
9434 MLX5_ASSERT(reg != REG_NON);
9435 if (reg == REG_C_0) {
9436 struct mlx5_priv *priv = dev->data->dev_private;
9437 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9438 uint32_t shl_c0 = rte_bsf32(msk_c0);
9444 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9449 * Add vport metadata Reg C0 item to matcher
9451 * @param[in, out] matcher
9453 * @param[in, out] key
9454 * Flow matcher value.
9456 * Flow pattern to translate.
9459 flow_dv_translate_item_meta_vport(void *matcher, void *key,
9460 uint32_t value, uint32_t mask)
9462 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
9466 * Add tag item to matcher
9469 * The devich to configure through.
9470 * @param[in, out] matcher
9472 * @param[in, out] key
9473 * Flow matcher value.
9475 * Flow pattern to translate.
9478 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
9479 void *matcher, void *key,
9480 const struct rte_flow_item *item)
9482 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
9483 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
9484 uint32_t mask, value;
9487 value = tag_v->data;
9488 mask = tag_m ? tag_m->data : UINT32_MAX;
9489 if (tag_v->id == REG_C_0) {
9490 struct mlx5_priv *priv = dev->data->dev_private;
9491 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9492 uint32_t shl_c0 = rte_bsf32(msk_c0);
9498 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
9502 * Add TAG item to matcher
9505 * The devich to configure through.
9506 * @param[in, out] matcher
9508 * @param[in, out] key
9509 * Flow matcher value.
9511 * Flow pattern to translate.
9514 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
9515 void *matcher, void *key,
9516 const struct rte_flow_item *item)
9518 const struct rte_flow_item_tag *tag_v = item->spec;
9519 const struct rte_flow_item_tag *tag_m = item->mask;
9520 enum modify_reg reg;
9523 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
9524 /* Get the metadata register index for the tag. */
9525 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
9526 MLX5_ASSERT(reg > 0);
9527 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
9531 * Add source vport match to the specified matcher.
9533 * @param[in, out] matcher
9535 * @param[in, out] key
9536 * Flow matcher value.
9538 * Source vport value to match
9543 flow_dv_translate_item_source_vport(void *matcher, void *key,
9544 int16_t port, uint16_t mask)
9546 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9547 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9549 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
9550 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
9554 * Translate port-id item to eswitch match on port-id.
9557 * The devich to configure through.
9558 * @param[in, out] matcher
9560 * @param[in, out] key
9561 * Flow matcher value.
9563 * Flow pattern to translate.
9568 * 0 on success, a negative errno value otherwise.
9571 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
9572 void *key, const struct rte_flow_item *item,
9573 const struct rte_flow_attr *attr)
9575 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
9576 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
9577 struct mlx5_priv *priv;
9580 mask = pid_m ? pid_m->id : 0xffff;
9581 id = pid_v ? pid_v->id : dev->data->port_id;
9582 priv = mlx5_port_to_eswitch_info(id, item == NULL);
9586 * Translate to vport field or to metadata, depending on mode.
9587 * Kernel can use either misc.source_port or half of C0 metadata
9590 if (priv->vport_meta_mask) {
9592 * Provide the hint for SW steering library
9593 * to insert the flow into ingress domain and
9594 * save the extra vport match.
9596 if (mask == 0xffff && priv->vport_id == 0xffff &&
9597 priv->pf_bond < 0 && attr->transfer)
9598 flow_dv_translate_item_source_vport
9599 (matcher, key, priv->vport_id, mask);
9601 * We should always set the vport metadata register,
9602 * otherwise the SW steering library can drop
9603 * the rule if wire vport metadata value is not zero,
9604 * it depends on kernel configuration.
9606 flow_dv_translate_item_meta_vport(matcher, key,
9607 priv->vport_meta_tag,
9608 priv->vport_meta_mask);
9610 flow_dv_translate_item_source_vport(matcher, key,
9611 priv->vport_id, mask);
9617 * Add ICMP6 item to matcher and to the value.
9619 * @param[in, out] matcher
9621 * @param[in, out] key
9622 * Flow matcher value.
9624 * Flow pattern to translate.
9626 * Item is inner pattern.
9629 flow_dv_translate_item_icmp6(void *matcher, void *key,
9630 const struct rte_flow_item *item,
9633 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
9634 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
9637 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9639 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9641 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9643 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9645 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9647 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9649 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9650 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
9654 icmp6_m = &rte_flow_item_icmp6_mask;
9655 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
9656 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
9657 icmp6_v->type & icmp6_m->type);
9658 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
9659 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
9660 icmp6_v->code & icmp6_m->code);
9664 * Add ICMP item to matcher and to the value.
9666 * @param[in, out] matcher
9668 * @param[in, out] key
9669 * Flow matcher value.
9671 * Flow pattern to translate.
9673 * Item is inner pattern.
9676 flow_dv_translate_item_icmp(void *matcher, void *key,
9677 const struct rte_flow_item *item,
9680 const struct rte_flow_item_icmp *icmp_m = item->mask;
9681 const struct rte_flow_item_icmp *icmp_v = item->spec;
9682 uint32_t icmp_header_data_m = 0;
9683 uint32_t icmp_header_data_v = 0;
9686 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9688 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9690 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9692 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9694 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9696 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9698 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9699 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
9703 icmp_m = &rte_flow_item_icmp_mask;
9704 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
9705 icmp_m->hdr.icmp_type);
9706 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
9707 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
9708 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
9709 icmp_m->hdr.icmp_code);
9710 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
9711 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
9712 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
9713 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
9714 if (icmp_header_data_m) {
9715 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
9716 icmp_header_data_v |=
9717 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
9718 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
9719 icmp_header_data_m);
9720 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
9721 icmp_header_data_v & icmp_header_data_m);
9726 * Add GTP item to matcher and to the value.
9728 * @param[in, out] matcher
9730 * @param[in, out] key
9731 * Flow matcher value.
9733 * Flow pattern to translate.
9735 * Item is inner pattern.
9738 flow_dv_translate_item_gtp(void *matcher, void *key,
9739 const struct rte_flow_item *item, int inner)
9741 const struct rte_flow_item_gtp *gtp_m = item->mask;
9742 const struct rte_flow_item_gtp *gtp_v = item->spec;
9745 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9747 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9748 uint16_t dport = RTE_GTPU_UDP_PORT;
9751 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9753 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9755 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9757 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9759 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9760 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9761 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
9766 gtp_m = &rte_flow_item_gtp_mask;
9767 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
9768 gtp_m->v_pt_rsv_flags);
9769 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
9770 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
9771 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
9772 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
9773 gtp_v->msg_type & gtp_m->msg_type);
9774 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
9775 rte_be_to_cpu_32(gtp_m->teid));
9776 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
9777 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
9781 * Add GTP PSC item to matcher.
9783 * @param[in, out] matcher
9785 * @param[in, out] key
9786 * Flow matcher value.
9788 * Flow pattern to translate.
9791 flow_dv_translate_item_gtp_psc(void *matcher, void *key,
9792 const struct rte_flow_item *item)
9794 const struct rte_flow_item_gtp_psc *gtp_psc_m = item->mask;
9795 const struct rte_flow_item_gtp_psc *gtp_psc_v = item->spec;
9796 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9798 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9804 uint8_t next_ext_header_type;
9809 /* Always set E-flag match on one, regardless of GTP item settings. */
9810 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_m, gtpu_msg_flags);
9811 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9812 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags, gtp_flags);
9813 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
9814 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9815 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
9816 /*Set next extension header type. */
9819 dw_2.next_ext_header_type = 0xff;
9820 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_dw_2,
9821 rte_cpu_to_be_32(dw_2.w32));
9824 dw_2.next_ext_header_type = 0x85;
9825 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
9826 rte_cpu_to_be_32(dw_2.w32));
9838 /*Set extension header PDU type and Qos. */
9840 gtp_psc_m = &rte_flow_item_gtp_psc_mask;
9842 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_m->hdr.type);
9843 dw_0.qfi = gtp_psc_m->hdr.qfi;
9844 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_first_ext_dw_0,
9845 rte_cpu_to_be_32(dw_0.w32));
9847 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
9848 gtp_psc_m->hdr.type);
9849 dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
9850 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
9851 rte_cpu_to_be_32(dw_0.w32));
9857 * Add eCPRI item to matcher and to the value.
9860 * The devich to configure through.
9861 * @param[in, out] matcher
9863 * @param[in, out] key
9864 * Flow matcher value.
9866 * Flow pattern to translate.
9867 * @param[in] last_item
9871 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
9872 void *key, const struct rte_flow_item *item,
9875 struct mlx5_priv *priv = dev->data->dev_private;
9876 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
9877 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
9878 struct rte_ecpri_common_hdr common;
9879 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
9881 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
9887 * In case of eCPRI over Ethernet, if EtherType is not specified,
9888 * match on eCPRI EtherType implicitly.
9890 if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
9891 void *hdrs_m, *hdrs_v, *l2m, *l2v;
9893 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9894 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9895 l2m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, ethertype);
9896 l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
9897 if (*(uint16_t *)l2m == 0 && *(uint16_t *)l2v == 0) {
9898 *(uint16_t *)l2m = UINT16_MAX;
9899 *(uint16_t *)l2v = RTE_BE16(RTE_ETHER_TYPE_ECPRI);
9905 ecpri_m = &rte_flow_item_ecpri_mask;
9907 * Maximal four DW samples are supported in a single matching now.
9908 * Two are used now for a eCPRI matching:
9909 * 1. Type: one byte, mask should be 0x00ff0000 in network order
9910 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
9913 if (!ecpri_m->hdr.common.u32)
9915 samples = priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0].ids;
9916 /* Need to take the whole DW as the mask to fill the entry. */
9917 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9918 prog_sample_field_value_0);
9919 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9920 prog_sample_field_value_0);
9921 /* Already big endian (network order) in the header. */
9922 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
9923 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
9924 /* Sample#0, used for matching type, offset 0. */
9925 MLX5_SET(fte_match_set_misc4, misc4_m,
9926 prog_sample_field_id_0, samples[0]);
9927 /* It makes no sense to set the sample ID in the mask field. */
9928 MLX5_SET(fte_match_set_misc4, misc4_v,
9929 prog_sample_field_id_0, samples[0]);
9931 * Checking if message body part needs to be matched.
9932 * Some wildcard rules only matching type field should be supported.
9934 if (ecpri_m->hdr.dummy[0]) {
9935 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
9936 switch (common.type) {
9937 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
9938 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
9939 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
9940 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9941 prog_sample_field_value_1);
9942 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9943 prog_sample_field_value_1);
9944 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
9945 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
9946 ecpri_m->hdr.dummy[0];
9947 /* Sample#1, to match message body, offset 4. */
9948 MLX5_SET(fte_match_set_misc4, misc4_m,
9949 prog_sample_field_id_1, samples[1]);
9950 MLX5_SET(fte_match_set_misc4, misc4_v,
9951 prog_sample_field_id_1, samples[1]);
9954 /* Others, do not match any sample ID. */
9961 * Add connection tracking status item to matcher
9964 * The devich to configure through.
9965 * @param[in, out] matcher
9967 * @param[in, out] key
9968 * Flow matcher value.
9970 * Flow pattern to translate.
9973 flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
9974 void *matcher, void *key,
9975 const struct rte_flow_item *item)
9977 uint32_t reg_value = 0;
9979 /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
9980 uint32_t reg_mask = 0;
9981 const struct rte_flow_item_conntrack *spec = item->spec;
9982 const struct rte_flow_item_conntrack *mask = item->mask;
9984 struct rte_flow_error error;
9987 mask = &rte_flow_item_conntrack_mask;
9988 if (!spec || !mask->flags)
9990 flags = spec->flags & mask->flags;
9991 /* The conflict should be checked in the validation. */
9992 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
9993 reg_value |= MLX5_CT_SYNDROME_VALID;
9994 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
9995 reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
9996 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
9997 reg_value |= MLX5_CT_SYNDROME_INVALID;
9998 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
9999 reg_value |= MLX5_CT_SYNDROME_TRAP;
10000 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10001 reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
10002 if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
10003 RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
10004 RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
10006 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
10007 reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
10008 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
10009 reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
10010 /* The REG_C_x value could be saved during startup. */
10011 reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
10012 if (reg_id == REG_NON)
10014 flow_dv_match_meta_reg(matcher, key, (enum modify_reg)reg_id,
10015 reg_value, reg_mask);
10018 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
10020 #define HEADER_IS_ZERO(match_criteria, headers) \
10021 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
10022 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
10025 * Calculate flow matcher enable bitmap.
10027 * @param match_criteria
10028 * Pointer to flow matcher criteria.
10031 * Bitmap of enabled fields.
10034 flow_dv_matcher_enable(uint32_t *match_criteria)
10036 uint8_t match_criteria_enable;
10038 match_criteria_enable =
10039 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
10040 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
10041 match_criteria_enable |=
10042 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
10043 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
10044 match_criteria_enable |=
10045 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
10046 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
10047 match_criteria_enable |=
10048 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
10049 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
10050 match_criteria_enable |=
10051 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
10052 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
10053 match_criteria_enable |=
10054 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
10055 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
10056 match_criteria_enable |=
10057 (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
10058 MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
10059 return match_criteria_enable;
10063 __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
10066 * Check flow matching criteria first, subtract misc5/4 length if flow
10067 * doesn't own misc5/4 parameters. In some old rdma-core releases,
10068 * misc5/4 are not supported, and matcher creation failure is expected
10069 * w/o subtration. If misc5 is provided, misc4 must be counted in since
10070 * misc5 is right after misc4.
10072 if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
10073 *size = MLX5_ST_SZ_BYTES(fte_match_param) -
10074 MLX5_ST_SZ_BYTES(fte_match_set_misc5);
10075 if (!(match_criteria & (1 <<
10076 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
10077 *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
10082 static struct mlx5_list_entry *
10083 flow_dv_matcher_clone_cb(void *tool_ctx __rte_unused,
10084 struct mlx5_list_entry *entry, void *cb_ctx)
10086 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10087 struct mlx5_flow_dv_matcher *ref = ctx->data;
10088 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10089 typeof(*tbl), tbl);
10090 struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
10095 rte_flow_error_set(ctx->error, ENOMEM,
10096 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10097 "cannot create matcher");
10100 memcpy(resource, entry, sizeof(*resource));
10101 resource->tbl = &tbl->tbl;
10102 return &resource->entry;
10106 flow_dv_matcher_clone_free_cb(void *tool_ctx __rte_unused,
10107 struct mlx5_list_entry *entry)
10112 struct mlx5_list_entry *
10113 flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
10115 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10116 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10117 struct rte_eth_dev *dev = ctx->dev;
10118 struct mlx5_flow_tbl_data_entry *tbl_data;
10119 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
10120 struct rte_flow_error *error = ctx->error;
10121 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10122 struct mlx5_flow_tbl_resource *tbl;
10127 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10129 rte_flow_error_set(error, ENOMEM,
10130 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10132 "cannot allocate flow table data entry");
10135 tbl_data->idx = idx;
10136 tbl_data->tunnel = tt_prm->tunnel;
10137 tbl_data->group_id = tt_prm->group_id;
10138 tbl_data->external = !!tt_prm->external;
10139 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
10140 tbl_data->is_egress = !!key.is_egress;
10141 tbl_data->is_transfer = !!key.is_fdb;
10142 tbl_data->dummy = !!key.dummy;
10143 tbl_data->level = key.level;
10144 tbl_data->id = key.id;
10145 tbl = &tbl_data->tbl;
10147 return &tbl_data->entry;
10149 domain = sh->fdb_domain;
10150 else if (key.is_egress)
10151 domain = sh->tx_domain;
10153 domain = sh->rx_domain;
10154 ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
10156 rte_flow_error_set(error, ENOMEM,
10157 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10158 NULL, "cannot create flow table object");
10159 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10162 if (key.level != 0) {
10163 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
10164 (tbl->obj, &tbl_data->jump.action);
10166 rte_flow_error_set(error, ENOMEM,
10167 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10169 "cannot create flow jump action");
10170 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10171 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10175 MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
10176 key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
10177 key.level, key.id);
10178 tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
10179 flow_dv_matcher_create_cb,
10180 flow_dv_matcher_match_cb,
10181 flow_dv_matcher_remove_cb,
10182 flow_dv_matcher_clone_cb,
10183 flow_dv_matcher_clone_free_cb);
10184 if (!tbl_data->matchers) {
10185 rte_flow_error_set(error, ENOMEM,
10186 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10188 "cannot create tbl matcher list");
10189 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10190 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10191 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10194 return &tbl_data->entry;
10198 flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
10201 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10202 struct mlx5_flow_tbl_data_entry *tbl_data =
10203 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10204 union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
10206 return tbl_data->level != key.level ||
10207 tbl_data->id != key.id ||
10208 tbl_data->dummy != key.dummy ||
10209 tbl_data->is_transfer != !!key.is_fdb ||
10210 tbl_data->is_egress != !!key.is_egress;
10213 struct mlx5_list_entry *
10214 flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
10217 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10218 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10219 struct mlx5_flow_tbl_data_entry *tbl_data;
10220 struct rte_flow_error *error = ctx->error;
10223 tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
10225 rte_flow_error_set(error, ENOMEM,
10226 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10228 "cannot allocate flow table data entry");
10231 memcpy(tbl_data, oentry, sizeof(*tbl_data));
10232 tbl_data->idx = idx;
10233 return &tbl_data->entry;
10237 flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10239 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10240 struct mlx5_flow_tbl_data_entry *tbl_data =
10241 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10243 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10247 * Get a flow table.
10249 * @param[in, out] dev
10250 * Pointer to rte_eth_dev structure.
10251 * @param[in] table_level
10252 * Table level to use.
10253 * @param[in] egress
10254 * Direction of the table.
10255 * @param[in] transfer
10256 * E-Switch or NIC flow.
10258 * Dummy entry for dv API.
10259 * @param[in] table_id
10261 * @param[out] error
10262 * pointer to error structure.
10265 * Returns tables resource based on the index, NULL in case of failed.
10267 struct mlx5_flow_tbl_resource *
10268 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
10269 uint32_t table_level, uint8_t egress,
10272 const struct mlx5_flow_tunnel *tunnel,
10273 uint32_t group_id, uint8_t dummy,
10275 struct rte_flow_error *error)
10277 struct mlx5_priv *priv = dev->data->dev_private;
10278 union mlx5_flow_tbl_key table_key = {
10280 .level = table_level,
10284 .is_fdb = !!transfer,
10285 .is_egress = !!egress,
10288 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
10290 .group_id = group_id,
10291 .external = external,
10293 struct mlx5_flow_cb_ctx ctx = {
10296 .data = &table_key.v64,
10299 struct mlx5_list_entry *entry;
10300 struct mlx5_flow_tbl_data_entry *tbl_data;
10302 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
10304 rte_flow_error_set(error, ENOMEM,
10305 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10306 "cannot get table");
10309 DRV_LOG(DEBUG, "table_level %u table_id %u "
10310 "tunnel %u group %u registered.",
10311 table_level, table_id,
10312 tunnel ? tunnel->tunnel_id : 0, group_id);
10313 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10314 return &tbl_data->tbl;
10318 flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10320 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10321 struct mlx5_flow_tbl_data_entry *tbl_data =
10322 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10324 MLX5_ASSERT(entry && sh);
10325 if (tbl_data->jump.action)
10326 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10327 if (tbl_data->tbl.obj)
10328 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
10329 if (tbl_data->tunnel_offload && tbl_data->external) {
10330 struct mlx5_list_entry *he;
10331 struct mlx5_hlist *tunnel_grp_hash;
10332 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
10333 union tunnel_tbl_key tunnel_key = {
10334 .tunnel_id = tbl_data->tunnel ?
10335 tbl_data->tunnel->tunnel_id : 0,
10336 .group = tbl_data->group_id
10338 uint32_t table_level = tbl_data->level;
10339 struct mlx5_flow_cb_ctx ctx = {
10340 .data = (void *)&tunnel_key.val,
10343 tunnel_grp_hash = tbl_data->tunnel ?
10344 tbl_data->tunnel->groups :
10346 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
10348 mlx5_hlist_unregister(tunnel_grp_hash, he);
10350 "table_level %u id %u tunnel %u group %u released.",
10354 tbl_data->tunnel->tunnel_id : 0,
10355 tbl_data->group_id);
10357 mlx5_list_destroy(tbl_data->matchers);
10358 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10362 * Release a flow table.
10365 * Pointer to device shared structure.
10367 * Table resource to be released.
10370 * Returns 0 if table was released, else return 1;
10373 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
10374 struct mlx5_flow_tbl_resource *tbl)
10376 struct mlx5_flow_tbl_data_entry *tbl_data =
10377 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10381 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
10385 flow_dv_matcher_match_cb(void *tool_ctx __rte_unused,
10386 struct mlx5_list_entry *entry, void *cb_ctx)
10388 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10389 struct mlx5_flow_dv_matcher *ref = ctx->data;
10390 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
10393 return cur->crc != ref->crc ||
10394 cur->priority != ref->priority ||
10395 memcmp((const void *)cur->mask.buf,
10396 (const void *)ref->mask.buf, ref->mask.size);
10399 struct mlx5_list_entry *
10400 flow_dv_matcher_create_cb(void *tool_ctx, void *cb_ctx)
10402 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10403 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10404 struct mlx5_flow_dv_matcher *ref = ctx->data;
10405 struct mlx5_flow_dv_matcher *resource;
10406 struct mlx5dv_flow_matcher_attr dv_attr = {
10407 .type = IBV_FLOW_ATTR_NORMAL,
10408 .match_mask = (void *)&ref->mask,
10410 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10411 typeof(*tbl), tbl);
10414 resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
10417 rte_flow_error_set(ctx->error, ENOMEM,
10418 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10419 "cannot create matcher");
10423 dv_attr.match_criteria_enable =
10424 flow_dv_matcher_enable(resource->mask.buf);
10425 __flow_dv_adjust_buf_size(&ref->mask.size,
10426 dv_attr.match_criteria_enable);
10427 dv_attr.priority = ref->priority;
10428 if (tbl->is_egress)
10429 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
10430 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
10432 &resource->matcher_object);
10434 mlx5_free(resource);
10435 rte_flow_error_set(ctx->error, ENOMEM,
10436 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10437 "cannot create matcher");
10440 return &resource->entry;
10444 * Register the flow matcher.
10446 * @param[in, out] dev
10447 * Pointer to rte_eth_dev structure.
10448 * @param[in, out] matcher
10449 * Pointer to flow matcher.
10450 * @param[in, out] key
10451 * Pointer to flow table key.
10452 * @parm[in, out] dev_flow
10453 * Pointer to the dev_flow.
10454 * @param[out] error
10455 * pointer to error structure.
10458 * 0 on success otherwise -errno and errno is set.
10461 flow_dv_matcher_register(struct rte_eth_dev *dev,
10462 struct mlx5_flow_dv_matcher *ref,
10463 union mlx5_flow_tbl_key *key,
10464 struct mlx5_flow *dev_flow,
10465 const struct mlx5_flow_tunnel *tunnel,
10467 struct rte_flow_error *error)
10469 struct mlx5_list_entry *entry;
10470 struct mlx5_flow_dv_matcher *resource;
10471 struct mlx5_flow_tbl_resource *tbl;
10472 struct mlx5_flow_tbl_data_entry *tbl_data;
10473 struct mlx5_flow_cb_ctx ctx = {
10478 * tunnel offload API requires this registration for cases when
10479 * tunnel match rule was inserted before tunnel set rule.
10481 tbl = flow_dv_tbl_resource_get(dev, key->level,
10482 key->is_egress, key->is_fdb,
10483 dev_flow->external, tunnel,
10484 group_id, 0, key->id, error);
10486 return -rte_errno; /* No need to refill the error info */
10487 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10489 entry = mlx5_list_register(tbl_data->matchers, &ctx);
10491 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
10492 return rte_flow_error_set(error, ENOMEM,
10493 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10494 "cannot allocate ref memory");
10496 resource = container_of(entry, typeof(*resource), entry);
10497 dev_flow->handle->dvh.matcher = resource;
10501 struct mlx5_list_entry *
10502 flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
10504 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10505 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10506 struct mlx5_flow_dv_tag_resource *entry;
10510 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10512 rte_flow_error_set(ctx->error, ENOMEM,
10513 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10514 "cannot allocate resource memory");
10518 entry->tag_id = *(uint32_t *)(ctx->data);
10519 ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
10522 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
10523 rte_flow_error_set(ctx->error, ENOMEM,
10524 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10525 NULL, "cannot create action");
10528 return &entry->entry;
10532 flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
10535 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10536 struct mlx5_flow_dv_tag_resource *tag =
10537 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10539 return *(uint32_t *)(ctx->data) != tag->tag_id;
10542 struct mlx5_list_entry *
10543 flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
10546 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10547 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10548 struct mlx5_flow_dv_tag_resource *entry;
10551 entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10553 rte_flow_error_set(ctx->error, ENOMEM,
10554 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10555 "cannot allocate tag resource memory");
10558 memcpy(entry, oentry, sizeof(*entry));
10560 return &entry->entry;
10564 flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10566 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10567 struct mlx5_flow_dv_tag_resource *tag =
10568 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10570 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10574 * Find existing tag resource or create and register a new one.
10576 * @param dev[in, out]
10577 * Pointer to rte_eth_dev structure.
10578 * @param[in, out] tag_be24
10579 * Tag value in big endian then R-shift 8.
10580 * @parm[in, out] dev_flow
10581 * Pointer to the dev_flow.
10582 * @param[out] error
10583 * pointer to error structure.
10586 * 0 on success otherwise -errno and errno is set.
10589 flow_dv_tag_resource_register
10590 (struct rte_eth_dev *dev,
10592 struct mlx5_flow *dev_flow,
10593 struct rte_flow_error *error)
10595 struct mlx5_priv *priv = dev->data->dev_private;
10596 struct mlx5_flow_dv_tag_resource *resource;
10597 struct mlx5_list_entry *entry;
10598 struct mlx5_flow_cb_ctx ctx = {
10602 struct mlx5_hlist *tag_table;
10604 tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
10606 MLX5_TAGS_HLIST_ARRAY_SIZE,
10607 false, false, priv->sh,
10608 flow_dv_tag_create_cb,
10609 flow_dv_tag_match_cb,
10610 flow_dv_tag_remove_cb,
10611 flow_dv_tag_clone_cb,
10612 flow_dv_tag_clone_free_cb);
10613 if (unlikely(!tag_table))
10615 entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
10617 resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
10619 dev_flow->handle->dvh.rix_tag = resource->idx;
10620 dev_flow->dv.tag_resource = resource;
10627 flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
10629 struct mlx5_dev_ctx_shared *sh = tool_ctx;
10630 struct mlx5_flow_dv_tag_resource *tag =
10631 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10633 MLX5_ASSERT(tag && sh && tag->action);
10634 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
10635 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
10636 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10643 * Pointer to Ethernet device.
10648 * 1 while a reference on it exists, 0 when freed.
10651 flow_dv_tag_release(struct rte_eth_dev *dev,
10654 struct mlx5_priv *priv = dev->data->dev_private;
10655 struct mlx5_flow_dv_tag_resource *tag;
10657 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
10660 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
10661 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
10662 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
10666 * Translate action PORT_ID / REPRESENTED_PORT to vport.
10669 * Pointer to rte_eth_dev structure.
10670 * @param[in] action
10671 * Pointer to action PORT_ID / REPRESENTED_PORT.
10672 * @param[out] dst_port_id
10673 * The target port ID.
10674 * @param[out] error
10675 * Pointer to the error structure.
10678 * 0 on success, a negative errno value otherwise and rte_errno is set.
10681 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
10682 const struct rte_flow_action *action,
10683 uint32_t *dst_port_id,
10684 struct rte_flow_error *error)
10687 struct mlx5_priv *priv;
10689 switch (action->type) {
10690 case RTE_FLOW_ACTION_TYPE_PORT_ID: {
10691 const struct rte_flow_action_port_id *conf;
10693 conf = (const struct rte_flow_action_port_id *)action->conf;
10694 port = conf->original ? dev->data->port_id : conf->id;
10697 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
10698 const struct rte_flow_action_ethdev *ethdev;
10700 ethdev = (const struct rte_flow_action_ethdev *)action->conf;
10701 port = ethdev->port_id;
10705 MLX5_ASSERT(false);
10706 return rte_flow_error_set(error, EINVAL,
10707 RTE_FLOW_ERROR_TYPE_ACTION, action,
10708 "unknown E-Switch action");
10711 priv = mlx5_port_to_eswitch_info(port, false);
10713 return rte_flow_error_set(error, -rte_errno,
10714 RTE_FLOW_ERROR_TYPE_ACTION,
10716 "No eswitch info was found for port");
10717 #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
10719 * This parameter is transferred to
10720 * mlx5dv_dr_action_create_dest_ib_port().
10722 *dst_port_id = priv->dev_port;
10725 * Legacy mode, no LAG configurations is supported.
10726 * This parameter is transferred to
10727 * mlx5dv_dr_action_create_dest_vport().
10729 *dst_port_id = priv->vport_id;
10735 * Create a counter with aging configuration.
10738 * Pointer to rte_eth_dev structure.
10739 * @param[in] dev_flow
10740 * Pointer to the mlx5_flow.
10741 * @param[out] count
10742 * Pointer to the counter action configuration.
10744 * Pointer to the aging action configuration.
10747 * Index to flow counter on success, 0 otherwise.
10750 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
10751 struct mlx5_flow *dev_flow,
10752 const struct rte_flow_action_count *count
10754 const struct rte_flow_action_age *age)
10757 struct mlx5_age_param *age_param;
10759 counter = flow_dv_counter_alloc(dev, !!age);
10760 if (!counter || age == NULL)
10762 age_param = flow_dv_counter_idx_get_age(dev, counter);
10763 age_param->context = age->context ? age->context :
10764 (void *)(uintptr_t)(dev_flow->flow_idx);
10765 age_param->timeout = age->timeout;
10766 age_param->port_id = dev->data->port_id;
10767 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
10768 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
10773 * Add Tx queue matcher
10776 * Pointer to the dev struct.
10777 * @param[in, out] matcher
10779 * @param[in, out] key
10780 * Flow matcher value.
10782 * Flow pattern to translate.
10784 * Item is inner pattern.
10787 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
10788 void *matcher, void *key,
10789 const struct rte_flow_item *item)
10791 const struct mlx5_rte_flow_item_tx_queue *queue_m;
10792 const struct mlx5_rte_flow_item_tx_queue *queue_v;
10794 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
10796 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10797 struct mlx5_txq_ctrl *txq;
10801 queue_m = (const void *)item->mask;
10804 queue_v = (const void *)item->spec;
10807 txq = mlx5_txq_get(dev, queue_v->queue);
10810 queue = txq->obj->sq->id;
10811 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
10812 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
10813 queue & queue_m->queue);
10814 mlx5_txq_release(dev, queue_v->queue);
10818 * Set the hash fields according to the @p flow information.
10820 * @param[in] dev_flow
10821 * Pointer to the mlx5_flow.
10822 * @param[in] rss_desc
10823 * Pointer to the mlx5_flow_rss_desc.
10826 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
10827 struct mlx5_flow_rss_desc *rss_desc)
10829 uint64_t items = dev_flow->handle->layers;
10831 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
10833 dev_flow->hash_fields = 0;
10834 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
10835 if (rss_desc->level >= 2)
10838 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
10839 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
10840 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
10841 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10842 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
10843 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10844 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
10846 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
10848 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
10849 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
10850 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
10851 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10852 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
10853 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10854 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
10856 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
10859 if (dev_flow->hash_fields == 0)
10861 * There is no match between the RSS types and the
10862 * L3 protocol (IPv4/IPv6) defined in the flow rule.
10865 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
10866 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
10867 if (rss_types & ETH_RSS_UDP) {
10868 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10869 dev_flow->hash_fields |=
10870 IBV_RX_HASH_SRC_PORT_UDP;
10871 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10872 dev_flow->hash_fields |=
10873 IBV_RX_HASH_DST_PORT_UDP;
10875 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
10877 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
10878 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
10879 if (rss_types & ETH_RSS_TCP) {
10880 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10881 dev_flow->hash_fields |=
10882 IBV_RX_HASH_SRC_PORT_TCP;
10883 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10884 dev_flow->hash_fields |=
10885 IBV_RX_HASH_DST_PORT_TCP;
10887 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
10891 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
10895 * Prepare an Rx Hash queue.
10898 * Pointer to Ethernet device.
10899 * @param[in] dev_flow
10900 * Pointer to the mlx5_flow.
10901 * @param[in] rss_desc
10902 * Pointer to the mlx5_flow_rss_desc.
10903 * @param[out] hrxq_idx
10904 * Hash Rx queue index.
10907 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
10909 static struct mlx5_hrxq *
10910 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
10911 struct mlx5_flow *dev_flow,
10912 struct mlx5_flow_rss_desc *rss_desc,
10913 uint32_t *hrxq_idx)
10915 struct mlx5_priv *priv = dev->data->dev_private;
10916 struct mlx5_flow_handle *dh = dev_flow->handle;
10917 struct mlx5_hrxq *hrxq;
10919 MLX5_ASSERT(rss_desc->queue_num);
10920 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
10921 rss_desc->hash_fields = dev_flow->hash_fields;
10922 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
10923 rss_desc->shared_rss = 0;
10924 if (rss_desc->hash_fields == 0)
10925 rss_desc->queue_num = 1;
10926 *hrxq_idx = mlx5_hrxq_get(dev, rss_desc);
10929 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
10935 * Release sample sub action resource.
10937 * @param[in, out] dev
10938 * Pointer to rte_eth_dev structure.
10939 * @param[in] act_res
10940 * Pointer to sample sub action resource.
10943 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
10944 struct mlx5_flow_sub_actions_idx *act_res)
10946 if (act_res->rix_hrxq) {
10947 mlx5_hrxq_release(dev, act_res->rix_hrxq);
10948 act_res->rix_hrxq = 0;
10950 if (act_res->rix_encap_decap) {
10951 flow_dv_encap_decap_resource_release(dev,
10952 act_res->rix_encap_decap);
10953 act_res->rix_encap_decap = 0;
10955 if (act_res->rix_port_id_action) {
10956 flow_dv_port_id_action_resource_release(dev,
10957 act_res->rix_port_id_action);
10958 act_res->rix_port_id_action = 0;
10960 if (act_res->rix_tag) {
10961 flow_dv_tag_release(dev, act_res->rix_tag);
10962 act_res->rix_tag = 0;
10964 if (act_res->rix_jump) {
10965 flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
10966 act_res->rix_jump = 0;
10971 flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
10972 struct mlx5_list_entry *entry, void *cb_ctx)
10974 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10975 struct rte_eth_dev *dev = ctx->dev;
10976 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
10977 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
10981 if (ctx_resource->ratio == resource->ratio &&
10982 ctx_resource->ft_type == resource->ft_type &&
10983 ctx_resource->ft_id == resource->ft_id &&
10984 ctx_resource->set_action == resource->set_action &&
10985 !memcmp((void *)&ctx_resource->sample_act,
10986 (void *)&resource->sample_act,
10987 sizeof(struct mlx5_flow_sub_actions_list))) {
10989 * Existing sample action should release the prepared
10990 * sub-actions reference counter.
10992 flow_dv_sample_sub_actions_release(dev,
10993 &ctx_resource->sample_idx);
10999 struct mlx5_list_entry *
11000 flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11002 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11003 struct rte_eth_dev *dev = ctx->dev;
11004 struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
11005 void **sample_dv_actions = ctx_resource->sub_actions;
11006 struct mlx5_flow_dv_sample_resource *resource;
11007 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
11008 struct mlx5_priv *priv = dev->data->dev_private;
11009 struct mlx5_dev_ctx_shared *sh = priv->sh;
11010 struct mlx5_flow_tbl_resource *tbl;
11012 const uint32_t next_ft_step = 1;
11013 uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
11014 uint8_t is_egress = 0;
11015 uint8_t is_transfer = 0;
11016 struct rte_flow_error *error = ctx->error;
11018 /* Register new sample resource. */
11019 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11021 rte_flow_error_set(error, ENOMEM,
11022 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11024 "cannot allocate resource memory");
11027 *resource = *ctx_resource;
11028 /* Create normal path table level */
11029 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11031 else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
11033 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
11034 is_egress, is_transfer,
11035 true, NULL, 0, 0, 0, error);
11037 rte_flow_error_set(error, ENOMEM,
11038 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11040 "fail to create normal path table "
11044 resource->normal_path_tbl = tbl;
11045 if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
11046 if (!sh->default_miss_action) {
11047 rte_flow_error_set(error, ENOMEM,
11048 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11050 "default miss action was not "
11054 sample_dv_actions[ctx_resource->sample_act.actions_num++] =
11055 sh->default_miss_action;
11057 /* Create a DR sample action */
11058 sampler_attr.sample_ratio = resource->ratio;
11059 sampler_attr.default_next_table = tbl->obj;
11060 sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
11061 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
11062 &sample_dv_actions[0];
11063 sampler_attr.action = resource->set_action;
11064 if (mlx5_os_flow_dr_create_flow_action_sampler
11065 (&sampler_attr, &resource->verbs_action)) {
11066 rte_flow_error_set(error, ENOMEM,
11067 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11068 NULL, "cannot create sample action");
11071 resource->idx = idx;
11072 resource->dev = dev;
11073 return &resource->entry;
11075 if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
11076 flow_dv_sample_sub_actions_release(dev,
11077 &resource->sample_idx);
11078 if (resource->normal_path_tbl)
11079 flow_dv_tbl_resource_release(MLX5_SH(dev),
11080 resource->normal_path_tbl);
11081 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
11086 struct mlx5_list_entry *
11087 flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
11088 struct mlx5_list_entry *entry __rte_unused,
11091 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11092 struct rte_eth_dev *dev = ctx->dev;
11093 struct mlx5_flow_dv_sample_resource *resource;
11094 struct mlx5_priv *priv = dev->data->dev_private;
11095 struct mlx5_dev_ctx_shared *sh = priv->sh;
11098 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
11100 rte_flow_error_set(ctx->error, ENOMEM,
11101 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11103 "cannot allocate resource memory");
11106 memcpy(resource, entry, sizeof(*resource));
11107 resource->idx = idx;
11108 resource->dev = dev;
11109 return &resource->entry;
11113 flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
11114 struct mlx5_list_entry *entry)
11116 struct mlx5_flow_dv_sample_resource *resource =
11117 container_of(entry, typeof(*resource), entry);
11118 struct rte_eth_dev *dev = resource->dev;
11119 struct mlx5_priv *priv = dev->data->dev_private;
11121 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
11125 * Find existing sample resource or create and register a new one.
11127 * @param[in, out] dev
11128 * Pointer to rte_eth_dev structure.
11130 * Pointer to sample resource reference.
11131 * @parm[in, out] dev_flow
11132 * Pointer to the dev_flow.
11133 * @param[out] error
11134 * pointer to error structure.
11137 * 0 on success otherwise -errno and errno is set.
11140 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
11141 struct mlx5_flow_dv_sample_resource *ref,
11142 struct mlx5_flow *dev_flow,
11143 struct rte_flow_error *error)
11145 struct mlx5_flow_dv_sample_resource *resource;
11146 struct mlx5_list_entry *entry;
11147 struct mlx5_priv *priv = dev->data->dev_private;
11148 struct mlx5_flow_cb_ctx ctx = {
11154 entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
11157 resource = container_of(entry, typeof(*resource), entry);
11158 dev_flow->handle->dvh.rix_sample = resource->idx;
11159 dev_flow->dv.sample_res = resource;
11164 flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
11165 struct mlx5_list_entry *entry, void *cb_ctx)
11167 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11168 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11169 struct rte_eth_dev *dev = ctx->dev;
11170 struct mlx5_flow_dv_dest_array_resource *resource =
11171 container_of(entry, typeof(*resource), entry);
11174 if (ctx_resource->num_of_dest == resource->num_of_dest &&
11175 ctx_resource->ft_type == resource->ft_type &&
11176 !memcmp((void *)resource->sample_act,
11177 (void *)ctx_resource->sample_act,
11178 (ctx_resource->num_of_dest *
11179 sizeof(struct mlx5_flow_sub_actions_list)))) {
11181 * Existing sample action should release the prepared
11182 * sub-actions reference counter.
11184 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11185 flow_dv_sample_sub_actions_release(dev,
11186 &ctx_resource->sample_idx[idx]);
11192 struct mlx5_list_entry *
11193 flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
11195 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11196 struct rte_eth_dev *dev = ctx->dev;
11197 struct mlx5_flow_dv_dest_array_resource *resource;
11198 struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
11199 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
11200 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
11201 struct mlx5_priv *priv = dev->data->dev_private;
11202 struct mlx5_dev_ctx_shared *sh = priv->sh;
11203 struct mlx5_flow_sub_actions_list *sample_act;
11204 struct mlx5dv_dr_domain *domain;
11205 uint32_t idx = 0, res_idx = 0;
11206 struct rte_flow_error *error = ctx->error;
11207 uint64_t action_flags;
11210 /* Register new destination array resource. */
11211 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11214 rte_flow_error_set(error, ENOMEM,
11215 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11217 "cannot allocate resource memory");
11220 *resource = *ctx_resource;
11221 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
11222 domain = sh->fdb_domain;
11223 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
11224 domain = sh->rx_domain;
11226 domain = sh->tx_domain;
11227 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11228 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
11229 mlx5_malloc(MLX5_MEM_ZERO,
11230 sizeof(struct mlx5dv_dr_action_dest_attr),
11232 if (!dest_attr[idx]) {
11233 rte_flow_error_set(error, ENOMEM,
11234 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11236 "cannot allocate resource memory");
11239 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
11240 sample_act = &ctx_resource->sample_act[idx];
11241 action_flags = sample_act->action_flags;
11242 switch (action_flags) {
11243 case MLX5_FLOW_ACTION_QUEUE:
11244 dest_attr[idx]->dest = sample_act->dr_queue_action;
11246 case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
11247 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
11248 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
11249 dest_attr[idx]->dest_reformat->reformat =
11250 sample_act->dr_encap_action;
11251 dest_attr[idx]->dest_reformat->dest =
11252 sample_act->dr_port_id_action;
11254 case MLX5_FLOW_ACTION_PORT_ID:
11255 dest_attr[idx]->dest = sample_act->dr_port_id_action;
11257 case MLX5_FLOW_ACTION_JUMP:
11258 dest_attr[idx]->dest = sample_act->dr_jump_action;
11261 rte_flow_error_set(error, EINVAL,
11262 RTE_FLOW_ERROR_TYPE_ACTION,
11264 "unsupported actions type");
11268 /* create a dest array actioin */
11269 ret = mlx5_os_flow_dr_create_flow_action_dest_array
11271 resource->num_of_dest,
11273 &resource->action);
11275 rte_flow_error_set(error, ENOMEM,
11276 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11278 "cannot create destination array action");
11281 resource->idx = res_idx;
11282 resource->dev = dev;
11283 for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
11284 mlx5_free(dest_attr[idx]);
11285 return &resource->entry;
11287 for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
11288 flow_dv_sample_sub_actions_release(dev,
11289 &resource->sample_idx[idx]);
11290 if (dest_attr[idx])
11291 mlx5_free(dest_attr[idx]);
11293 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
11297 struct mlx5_list_entry *
11298 flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
11299 struct mlx5_list_entry *entry __rte_unused,
11302 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11303 struct rte_eth_dev *dev = ctx->dev;
11304 struct mlx5_flow_dv_dest_array_resource *resource;
11305 struct mlx5_priv *priv = dev->data->dev_private;
11306 struct mlx5_dev_ctx_shared *sh = priv->sh;
11307 uint32_t res_idx = 0;
11308 struct rte_flow_error *error = ctx->error;
11310 resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11313 rte_flow_error_set(error, ENOMEM,
11314 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11316 "cannot allocate dest-array memory");
11319 memcpy(resource, entry, sizeof(*resource));
11320 resource->idx = res_idx;
11321 resource->dev = dev;
11322 return &resource->entry;
11326 flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
11327 struct mlx5_list_entry *entry)
11329 struct mlx5_flow_dv_dest_array_resource *resource =
11330 container_of(entry, typeof(*resource), entry);
11331 struct rte_eth_dev *dev = resource->dev;
11332 struct mlx5_priv *priv = dev->data->dev_private;
11334 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
11338 * Find existing destination array resource or create and register a new one.
11340 * @param[in, out] dev
11341 * Pointer to rte_eth_dev structure.
11343 * Pointer to destination array resource reference.
11344 * @parm[in, out] dev_flow
11345 * Pointer to the dev_flow.
11346 * @param[out] error
11347 * pointer to error structure.
11350 * 0 on success otherwise -errno and errno is set.
11353 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
11354 struct mlx5_flow_dv_dest_array_resource *ref,
11355 struct mlx5_flow *dev_flow,
11356 struct rte_flow_error *error)
11358 struct mlx5_flow_dv_dest_array_resource *resource;
11359 struct mlx5_priv *priv = dev->data->dev_private;
11360 struct mlx5_list_entry *entry;
11361 struct mlx5_flow_cb_ctx ctx = {
11367 entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
11370 resource = container_of(entry, typeof(*resource), entry);
11371 dev_flow->handle->dvh.rix_dest_array = resource->idx;
11372 dev_flow->dv.dest_array_res = resource;
11377 * Convert Sample action to DV specification.
11380 * Pointer to rte_eth_dev structure.
11381 * @param[in] action
11382 * Pointer to sample action structure.
11383 * @param[in, out] dev_flow
11384 * Pointer to the mlx5_flow.
11386 * Pointer to the flow attributes.
11387 * @param[in, out] num_of_dest
11388 * Pointer to the num of destination.
11389 * @param[in, out] sample_actions
11390 * Pointer to sample actions list.
11391 * @param[in, out] res
11392 * Pointer to sample resource.
11393 * @param[out] error
11394 * Pointer to the error structure.
11397 * 0 on success, a negative errno value otherwise and rte_errno is set.
11400 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
11401 const struct rte_flow_action_sample *action,
11402 struct mlx5_flow *dev_flow,
11403 const struct rte_flow_attr *attr,
11404 uint32_t *num_of_dest,
11405 void **sample_actions,
11406 struct mlx5_flow_dv_sample_resource *res,
11407 struct rte_flow_error *error)
11409 struct mlx5_priv *priv = dev->data->dev_private;
11410 const struct rte_flow_action *sub_actions;
11411 struct mlx5_flow_sub_actions_list *sample_act;
11412 struct mlx5_flow_sub_actions_idx *sample_idx;
11413 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11414 struct rte_flow *flow = dev_flow->flow;
11415 struct mlx5_flow_rss_desc *rss_desc;
11416 uint64_t action_flags = 0;
11419 rss_desc = &wks->rss_desc;
11420 sample_act = &res->sample_act;
11421 sample_idx = &res->sample_idx;
11422 res->ratio = action->ratio;
11423 sub_actions = action->actions;
11424 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
11425 int type = sub_actions->type;
11426 uint32_t pre_rix = 0;
11429 case RTE_FLOW_ACTION_TYPE_QUEUE:
11431 const struct rte_flow_action_queue *queue;
11432 struct mlx5_hrxq *hrxq;
11435 queue = sub_actions->conf;
11436 rss_desc->queue_num = 1;
11437 rss_desc->queue[0] = queue->index;
11438 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11439 rss_desc, &hrxq_idx);
11441 return rte_flow_error_set
11443 RTE_FLOW_ERROR_TYPE_ACTION,
11445 "cannot create fate queue");
11446 sample_act->dr_queue_action = hrxq->action;
11447 sample_idx->rix_hrxq = hrxq_idx;
11448 sample_actions[sample_act->actions_num++] =
11451 action_flags |= MLX5_FLOW_ACTION_QUEUE;
11452 if (action_flags & MLX5_FLOW_ACTION_MARK)
11453 dev_flow->handle->rix_hrxq = hrxq_idx;
11454 dev_flow->handle->fate_action =
11455 MLX5_FLOW_FATE_QUEUE;
11458 case RTE_FLOW_ACTION_TYPE_RSS:
11460 struct mlx5_hrxq *hrxq;
11462 const struct rte_flow_action_rss *rss;
11463 const uint8_t *rss_key;
11465 rss = sub_actions->conf;
11466 memcpy(rss_desc->queue, rss->queue,
11467 rss->queue_num * sizeof(uint16_t));
11468 rss_desc->queue_num = rss->queue_num;
11469 /* NULL RSS key indicates default RSS key. */
11470 rss_key = !rss->key ? rss_hash_default_key : rss->key;
11471 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
11473 * rss->level and rss.types should be set in advance
11474 * when expanding items for RSS.
11476 flow_dv_hashfields_set(dev_flow, rss_desc);
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_RSS;
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_MARK:
11499 uint32_t tag_be = mlx5_flow_mark_set
11500 (((const struct rte_flow_action_mark *)
11501 (sub_actions->conf))->id);
11503 dev_flow->handle->mark = 1;
11504 pre_rix = dev_flow->handle->dvh.rix_tag;
11505 /* Save the mark resource before sample */
11506 pre_r = dev_flow->dv.tag_resource;
11507 if (flow_dv_tag_resource_register(dev, tag_be,
11510 MLX5_ASSERT(dev_flow->dv.tag_resource);
11511 sample_act->dr_tag_action =
11512 dev_flow->dv.tag_resource->action;
11513 sample_idx->rix_tag =
11514 dev_flow->handle->dvh.rix_tag;
11515 sample_actions[sample_act->actions_num++] =
11516 sample_act->dr_tag_action;
11517 /* Recover the mark resource after sample */
11518 dev_flow->dv.tag_resource = pre_r;
11519 dev_flow->handle->dvh.rix_tag = pre_rix;
11520 action_flags |= MLX5_FLOW_ACTION_MARK;
11523 case RTE_FLOW_ACTION_TYPE_COUNT:
11525 if (!flow->counter) {
11527 flow_dv_translate_create_counter(dev,
11528 dev_flow, sub_actions->conf,
11530 if (!flow->counter)
11531 return rte_flow_error_set
11533 RTE_FLOW_ERROR_TYPE_ACTION,
11535 "cannot create counter"
11538 sample_act->dr_cnt_action =
11539 (flow_dv_counter_get_by_idx(dev,
11540 flow->counter, NULL))->action;
11541 sample_actions[sample_act->actions_num++] =
11542 sample_act->dr_cnt_action;
11543 action_flags |= MLX5_FLOW_ACTION_COUNT;
11546 case RTE_FLOW_ACTION_TYPE_PORT_ID:
11547 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
11549 struct mlx5_flow_dv_port_id_action_resource
11551 uint32_t port_id = 0;
11553 memset(&port_id_resource, 0, sizeof(port_id_resource));
11554 /* Save the port id resource before sample */
11555 pre_rix = dev_flow->handle->rix_port_id_action;
11556 pre_r = dev_flow->dv.port_id_action;
11557 if (flow_dv_translate_action_port_id(dev, sub_actions,
11560 port_id_resource.port_id = port_id;
11561 if (flow_dv_port_id_action_resource_register
11562 (dev, &port_id_resource, dev_flow, error))
11564 sample_act->dr_port_id_action =
11565 dev_flow->dv.port_id_action->action;
11566 sample_idx->rix_port_id_action =
11567 dev_flow->handle->rix_port_id_action;
11568 sample_actions[sample_act->actions_num++] =
11569 sample_act->dr_port_id_action;
11570 /* Recover the port id resource after sample */
11571 dev_flow->dv.port_id_action = pre_r;
11572 dev_flow->handle->rix_port_id_action = pre_rix;
11574 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
11577 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11578 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11579 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11580 /* Save the encap resource before sample */
11581 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
11582 pre_r = dev_flow->dv.encap_decap;
11583 if (flow_dv_create_action_l2_encap(dev, sub_actions,
11588 sample_act->dr_encap_action =
11589 dev_flow->dv.encap_decap->action;
11590 sample_idx->rix_encap_decap =
11591 dev_flow->handle->dvh.rix_encap_decap;
11592 sample_actions[sample_act->actions_num++] =
11593 sample_act->dr_encap_action;
11594 /* Recover the encap resource after sample */
11595 dev_flow->dv.encap_decap = pre_r;
11596 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
11597 action_flags |= MLX5_FLOW_ACTION_ENCAP;
11600 return rte_flow_error_set(error, EINVAL,
11601 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11603 "Not support for sampler action");
11606 sample_act->action_flags = action_flags;
11607 res->ft_id = dev_flow->dv.group;
11608 if (attr->transfer) {
11610 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
11611 uint64_t set_action;
11612 } action_ctx = { .set_action = 0 };
11614 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
11615 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
11616 MLX5_MODIFICATION_TYPE_SET);
11617 MLX5_SET(set_action_in, action_ctx.action_in, field,
11618 MLX5_MODI_META_REG_C_0);
11619 MLX5_SET(set_action_in, action_ctx.action_in, data,
11620 priv->vport_meta_tag);
11621 res->set_action = action_ctx.set_action;
11622 } else if (attr->ingress) {
11623 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
11625 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
11631 * Convert Sample action to DV specification.
11634 * Pointer to rte_eth_dev structure.
11635 * @param[in, out] dev_flow
11636 * Pointer to the mlx5_flow.
11637 * @param[in] num_of_dest
11638 * The num of destination.
11639 * @param[in, out] res
11640 * Pointer to sample resource.
11641 * @param[in, out] mdest_res
11642 * Pointer to destination array resource.
11643 * @param[in] sample_actions
11644 * Pointer to sample path actions list.
11645 * @param[in] action_flags
11646 * Holds the actions detected until now.
11647 * @param[out] error
11648 * Pointer to the error structure.
11651 * 0 on success, a negative errno value otherwise and rte_errno is set.
11654 flow_dv_create_action_sample(struct rte_eth_dev *dev,
11655 struct mlx5_flow *dev_flow,
11656 uint32_t num_of_dest,
11657 struct mlx5_flow_dv_sample_resource *res,
11658 struct mlx5_flow_dv_dest_array_resource *mdest_res,
11659 void **sample_actions,
11660 uint64_t action_flags,
11661 struct rte_flow_error *error)
11663 /* update normal path action resource into last index of array */
11664 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
11665 struct mlx5_flow_sub_actions_list *sample_act =
11666 &mdest_res->sample_act[dest_index];
11667 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11668 struct mlx5_flow_rss_desc *rss_desc;
11669 uint32_t normal_idx = 0;
11670 struct mlx5_hrxq *hrxq;
11674 rss_desc = &wks->rss_desc;
11675 if (num_of_dest > 1) {
11676 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
11677 /* Handle QP action for mirroring */
11678 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11679 rss_desc, &hrxq_idx);
11681 return rte_flow_error_set
11683 RTE_FLOW_ERROR_TYPE_ACTION,
11685 "cannot create rx queue");
11687 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
11688 sample_act->dr_queue_action = hrxq->action;
11689 if (action_flags & MLX5_FLOW_ACTION_MARK)
11690 dev_flow->handle->rix_hrxq = hrxq_idx;
11691 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
11693 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
11695 mdest_res->sample_idx[dest_index].rix_encap_decap =
11696 dev_flow->handle->dvh.rix_encap_decap;
11697 sample_act->dr_encap_action =
11698 dev_flow->dv.encap_decap->action;
11699 dev_flow->handle->dvh.rix_encap_decap = 0;
11701 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
11703 mdest_res->sample_idx[dest_index].rix_port_id_action =
11704 dev_flow->handle->rix_port_id_action;
11705 sample_act->dr_port_id_action =
11706 dev_flow->dv.port_id_action->action;
11707 dev_flow->handle->rix_port_id_action = 0;
11709 if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
11711 mdest_res->sample_idx[dest_index].rix_jump =
11712 dev_flow->handle->rix_jump;
11713 sample_act->dr_jump_action =
11714 dev_flow->dv.jump->action;
11715 dev_flow->handle->rix_jump = 0;
11717 sample_act->actions_num = normal_idx;
11718 /* update sample action resource into first index of array */
11719 mdest_res->ft_type = res->ft_type;
11720 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
11721 sizeof(struct mlx5_flow_sub_actions_idx));
11722 memcpy(&mdest_res->sample_act[0], &res->sample_act,
11723 sizeof(struct mlx5_flow_sub_actions_list));
11724 mdest_res->num_of_dest = num_of_dest;
11725 if (flow_dv_dest_array_resource_register(dev, mdest_res,
11727 return rte_flow_error_set(error, EINVAL,
11728 RTE_FLOW_ERROR_TYPE_ACTION,
11729 NULL, "can't create sample "
11732 res->sub_actions = sample_actions;
11733 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
11734 return rte_flow_error_set(error, EINVAL,
11735 RTE_FLOW_ERROR_TYPE_ACTION,
11737 "can't create sample action");
11743 * Remove an ASO age action from age actions list.
11746 * Pointer to the Ethernet device structure.
11748 * Pointer to the aso age action handler.
11751 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
11752 struct mlx5_aso_age_action *age)
11754 struct mlx5_age_info *age_info;
11755 struct mlx5_age_param *age_param = &age->age_params;
11756 struct mlx5_priv *priv = dev->data->dev_private;
11757 uint16_t expected = AGE_CANDIDATE;
11759 age_info = GET_PORT_AGE_INFO(priv);
11760 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
11761 AGE_FREE, false, __ATOMIC_RELAXED,
11762 __ATOMIC_RELAXED)) {
11764 * We need the lock even it is age timeout,
11765 * since age action may still in process.
11767 rte_spinlock_lock(&age_info->aged_sl);
11768 LIST_REMOVE(age, next);
11769 rte_spinlock_unlock(&age_info->aged_sl);
11770 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
11775 * Release an ASO age action.
11778 * Pointer to the Ethernet device structure.
11779 * @param[in] age_idx
11780 * Index of ASO age action to release.
11782 * True if the release operation is during flow destroy operation.
11783 * False if the release operation is during action destroy operation.
11786 * 0 when age action was removed, otherwise the number of references.
11789 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
11791 struct mlx5_priv *priv = dev->data->dev_private;
11792 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11793 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
11794 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
11797 flow_dv_aso_age_remove_from_age(dev, age);
11798 rte_spinlock_lock(&mng->free_sl);
11799 LIST_INSERT_HEAD(&mng->free, age, next);
11800 rte_spinlock_unlock(&mng->free_sl);
11806 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
11809 * Pointer to the Ethernet device structure.
11812 * 0 on success, otherwise negative errno value and rte_errno is set.
11815 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
11817 struct mlx5_priv *priv = dev->data->dev_private;
11818 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11819 void *old_pools = mng->pools;
11820 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
11821 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
11822 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11825 rte_errno = ENOMEM;
11829 memcpy(pools, old_pools,
11830 mng->n * sizeof(struct mlx5_flow_counter_pool *));
11831 mlx5_free(old_pools);
11833 /* First ASO flow hit allocation - starting ASO data-path. */
11834 int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
11842 mng->pools = pools;
11847 * Create and initialize a new ASO aging pool.
11850 * Pointer to the Ethernet device structure.
11851 * @param[out] age_free
11852 * Where to put the pointer of a new age action.
11855 * The age actions pool pointer and @p age_free is set on success,
11856 * NULL otherwise and rte_errno is set.
11858 static struct mlx5_aso_age_pool *
11859 flow_dv_age_pool_create(struct rte_eth_dev *dev,
11860 struct mlx5_aso_age_action **age_free)
11862 struct mlx5_priv *priv = dev->data->dev_private;
11863 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11864 struct mlx5_aso_age_pool *pool = NULL;
11865 struct mlx5_devx_obj *obj = NULL;
11868 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
11871 rte_errno = ENODATA;
11872 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
11875 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
11877 claim_zero(mlx5_devx_cmd_destroy(obj));
11878 rte_errno = ENOMEM;
11881 pool->flow_hit_aso_obj = obj;
11882 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
11883 rte_spinlock_lock(&mng->resize_sl);
11884 pool->index = mng->next;
11885 /* Resize pools array if there is no room for the new pool in it. */
11886 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
11887 claim_zero(mlx5_devx_cmd_destroy(obj));
11889 rte_spinlock_unlock(&mng->resize_sl);
11892 mng->pools[pool->index] = pool;
11894 rte_spinlock_unlock(&mng->resize_sl);
11895 /* Assign the first action in the new pool, the rest go to free list. */
11896 *age_free = &pool->actions[0];
11897 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
11898 pool->actions[i].offset = i;
11899 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
11905 * Allocate a ASO aging bit.
11908 * Pointer to the Ethernet device structure.
11909 * @param[out] error
11910 * Pointer to the error structure.
11913 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
11916 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
11918 struct mlx5_priv *priv = dev->data->dev_private;
11919 const struct mlx5_aso_age_pool *pool;
11920 struct mlx5_aso_age_action *age_free = NULL;
11921 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11924 /* Try to get the next free age action bit. */
11925 rte_spinlock_lock(&mng->free_sl);
11926 age_free = LIST_FIRST(&mng->free);
11928 LIST_REMOVE(age_free, next);
11929 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
11930 rte_spinlock_unlock(&mng->free_sl);
11931 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
11932 NULL, "failed to create ASO age pool");
11933 return 0; /* 0 is an error. */
11935 rte_spinlock_unlock(&mng->free_sl);
11936 pool = container_of
11937 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
11938 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
11940 if (!age_free->dr_action) {
11941 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
11945 rte_flow_error_set(error, rte_errno,
11946 RTE_FLOW_ERROR_TYPE_ACTION,
11947 NULL, "failed to get reg_c "
11948 "for ASO flow hit");
11949 return 0; /* 0 is an error. */
11951 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
11952 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
11953 (priv->sh->rx_domain,
11954 pool->flow_hit_aso_obj->obj, age_free->offset,
11955 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
11956 (reg_c - REG_C_0));
11957 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
11958 if (!age_free->dr_action) {
11960 rte_spinlock_lock(&mng->free_sl);
11961 LIST_INSERT_HEAD(&mng->free, age_free, next);
11962 rte_spinlock_unlock(&mng->free_sl);
11963 rte_flow_error_set(error, rte_errno,
11964 RTE_FLOW_ERROR_TYPE_ACTION,
11965 NULL, "failed to create ASO "
11966 "flow hit action");
11967 return 0; /* 0 is an error. */
11970 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
11971 return pool->index | ((age_free->offset + 1) << 16);
11975 * Initialize flow ASO age parameters.
11978 * Pointer to rte_eth_dev structure.
11979 * @param[in] age_idx
11980 * Index of ASO age action.
11981 * @param[in] context
11982 * Pointer to flow counter age context.
11983 * @param[in] timeout
11984 * Aging timeout in seconds.
11988 flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
11993 struct mlx5_aso_age_action *aso_age;
11995 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
11996 MLX5_ASSERT(aso_age);
11997 aso_age->age_params.context = context;
11998 aso_age->age_params.timeout = timeout;
11999 aso_age->age_params.port_id = dev->data->port_id;
12000 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
12002 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
12007 flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
12008 const struct rte_flow_item_integrity *value,
12009 void *headers_m, void *headers_v)
12012 /* application l4_ok filter aggregates all hardware l4 filters
12013 * therefore hw l4_checksum_ok must be implicitly added here.
12015 struct rte_flow_item_integrity local_item;
12017 local_item.l4_csum_ok = 1;
12018 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
12019 local_item.l4_csum_ok);
12020 if (value->l4_ok) {
12021 /* application l4_ok = 1 matches sets both hw flags
12022 * l4_ok and l4_checksum_ok flags to 1.
12024 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12025 l4_checksum_ok, local_item.l4_csum_ok);
12026 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_ok,
12028 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_ok,
12031 /* application l4_ok = 0 matches on hw flag
12032 * l4_checksum_ok = 0 only.
12034 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12035 l4_checksum_ok, 0);
12037 } else if (mask->l4_csum_ok) {
12038 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
12040 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_checksum_ok,
12041 value->l4_csum_ok);
12046 flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
12047 const struct rte_flow_item_integrity *value,
12048 void *headers_m, void *headers_v,
12052 /* application l3_ok filter aggregates all hardware l3 filters
12053 * therefore hw ipv4_checksum_ok must be implicitly added here.
12055 struct rte_flow_item_integrity local_item;
12057 local_item.ipv4_csum_ok = !!is_ipv4;
12058 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
12059 local_item.ipv4_csum_ok);
12060 if (value->l3_ok) {
12061 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12062 ipv4_checksum_ok, local_item.ipv4_csum_ok);
12063 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l3_ok,
12065 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l3_ok,
12068 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
12069 ipv4_checksum_ok, 0);
12071 } else if (mask->ipv4_csum_ok) {
12072 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
12073 mask->ipv4_csum_ok);
12074 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
12075 value->ipv4_csum_ok);
12080 flow_dv_translate_item_integrity(void *matcher, void *key,
12081 const struct rte_flow_item *head_item,
12082 const struct rte_flow_item *integrity_item)
12084 const struct rte_flow_item_integrity *mask = integrity_item->mask;
12085 const struct rte_flow_item_integrity *value = integrity_item->spec;
12086 const struct rte_flow_item *tunnel_item, *end_item, *item;
12089 uint32_t l3_protocol;
12094 mask = &rte_flow_item_integrity_mask;
12095 if (value->level > 1) {
12096 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12098 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
12100 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
12102 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
12104 tunnel_item = mlx5_flow_find_tunnel_item(head_item);
12105 if (value->level > 1) {
12106 /* tunnel item was verified during the item validation */
12107 item = tunnel_item;
12108 end_item = mlx5_find_end_item(tunnel_item);
12111 end_item = tunnel_item ? tunnel_item :
12112 mlx5_find_end_item(integrity_item);
12114 l3_protocol = mask->l3_ok ?
12115 mlx5_flow_locate_proto_l3(&item, end_item) : 0;
12116 flow_dv_translate_integrity_l3(mask, value, headers_m, headers_v,
12117 l3_protocol == RTE_ETHER_TYPE_IPV4);
12118 flow_dv_translate_integrity_l4(mask, value, headers_m, headers_v);
12122 * Prepares DV flow counter with aging configuration.
12123 * Gets it by index when exists, creates a new one when doesn't.
12126 * Pointer to rte_eth_dev structure.
12127 * @param[in] dev_flow
12128 * Pointer to the mlx5_flow.
12129 * @param[in, out] flow
12130 * Pointer to the sub flow.
12132 * Pointer to the counter action configuration.
12134 * Pointer to the aging action configuration.
12135 * @param[out] error
12136 * Pointer to the error structure.
12139 * Pointer to the counter, NULL otherwise.
12141 static struct mlx5_flow_counter *
12142 flow_dv_prepare_counter(struct rte_eth_dev *dev,
12143 struct mlx5_flow *dev_flow,
12144 struct rte_flow *flow,
12145 const struct rte_flow_action_count *count,
12146 const struct rte_flow_action_age *age,
12147 struct rte_flow_error *error)
12149 if (!flow->counter) {
12150 flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
12152 if (!flow->counter) {
12153 rte_flow_error_set(error, rte_errno,
12154 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12155 "cannot create counter object.");
12159 return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
12163 * Release an ASO CT action by its own device.
12166 * Pointer to the Ethernet device structure.
12168 * Index of ASO CT action to release.
12171 * 0 when CT action was removed, otherwise the number of references.
12174 flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
12176 struct mlx5_priv *priv = dev->data->dev_private;
12177 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12179 struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12180 enum mlx5_aso_ct_state state =
12181 __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
12183 /* Cannot release when CT is in the ASO SQ. */
12184 if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
12186 ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
12188 if (ct->dr_action_orig) {
12189 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12190 claim_zero(mlx5_glue->destroy_flow_action
12191 (ct->dr_action_orig));
12193 ct->dr_action_orig = NULL;
12195 if (ct->dr_action_rply) {
12196 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12197 claim_zero(mlx5_glue->destroy_flow_action
12198 (ct->dr_action_rply));
12200 ct->dr_action_rply = NULL;
12202 /* Clear the state to free, no need in 1st allocation. */
12203 MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
12204 rte_spinlock_lock(&mng->ct_sl);
12205 LIST_INSERT_HEAD(&mng->free_cts, ct, next);
12206 rte_spinlock_unlock(&mng->ct_sl);
12212 flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
12213 struct rte_flow_error *error)
12215 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
12216 uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
12217 struct rte_eth_dev *owndev = &rte_eth_devices[owner];
12220 MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
12221 if (dev->data->dev_started != 1)
12222 return rte_flow_error_set(error, EAGAIN,
12223 RTE_FLOW_ERROR_TYPE_ACTION,
12225 "Indirect CT action cannot be destroyed when the port is stopped");
12226 ret = flow_dv_aso_ct_dev_release(owndev, idx);
12228 return rte_flow_error_set(error, EAGAIN,
12229 RTE_FLOW_ERROR_TYPE_ACTION,
12231 "Current state prevents indirect CT action from being destroyed");
12236 * Resize the ASO CT pools array by 64 pools.
12239 * Pointer to the Ethernet device structure.
12242 * 0 on success, otherwise negative errno value and rte_errno is set.
12245 flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
12247 struct mlx5_priv *priv = dev->data->dev_private;
12248 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12249 void *old_pools = mng->pools;
12250 /* Magic number now, need a macro. */
12251 uint32_t resize = mng->n + 64;
12252 uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
12253 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
12256 rte_errno = ENOMEM;
12259 rte_rwlock_write_lock(&mng->resize_rwl);
12260 /* ASO SQ/QP was already initialized in the startup. */
12262 /* Realloc could be an alternative choice. */
12263 rte_memcpy(pools, old_pools,
12264 mng->n * sizeof(struct mlx5_aso_ct_pool *));
12265 mlx5_free(old_pools);
12268 mng->pools = pools;
12269 rte_rwlock_write_unlock(&mng->resize_rwl);
12274 * Create and initialize a new ASO CT pool.
12277 * Pointer to the Ethernet device structure.
12278 * @param[out] ct_free
12279 * Where to put the pointer of a new CT action.
12282 * The CT actions pool pointer and @p ct_free is set on success,
12283 * NULL otherwise and rte_errno is set.
12285 static struct mlx5_aso_ct_pool *
12286 flow_dv_ct_pool_create(struct rte_eth_dev *dev,
12287 struct mlx5_aso_ct_action **ct_free)
12289 struct mlx5_priv *priv = dev->data->dev_private;
12290 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12291 struct mlx5_aso_ct_pool *pool = NULL;
12292 struct mlx5_devx_obj *obj = NULL;
12294 uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
12296 obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
12297 priv->sh->pdn, log_obj_size);
12299 rte_errno = ENODATA;
12300 DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
12303 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
12305 rte_errno = ENOMEM;
12306 claim_zero(mlx5_devx_cmd_destroy(obj));
12309 pool->devx_obj = obj;
12310 pool->index = mng->next;
12311 /* Resize pools array if there is no room for the new pool in it. */
12312 if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
12313 claim_zero(mlx5_devx_cmd_destroy(obj));
12317 mng->pools[pool->index] = pool;
12319 /* Assign the first action in the new pool, the rest go to free list. */
12320 *ct_free = &pool->actions[0];
12321 /* Lock outside, the list operation is safe here. */
12322 for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
12323 /* refcnt is 0 when allocating the memory. */
12324 pool->actions[i].offset = i;
12325 LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
12331 * Allocate a ASO CT action from free list.
12334 * Pointer to the Ethernet device structure.
12335 * @param[out] error
12336 * Pointer to the error structure.
12339 * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
12342 flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
12344 struct mlx5_priv *priv = dev->data->dev_private;
12345 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
12346 struct mlx5_aso_ct_action *ct = NULL;
12347 struct mlx5_aso_ct_pool *pool;
12352 if (!priv->sh->devx) {
12353 rte_errno = ENOTSUP;
12356 /* Get a free CT action, if no, a new pool will be created. */
12357 rte_spinlock_lock(&mng->ct_sl);
12358 ct = LIST_FIRST(&mng->free_cts);
12360 LIST_REMOVE(ct, next);
12361 } else if (!flow_dv_ct_pool_create(dev, &ct)) {
12362 rte_spinlock_unlock(&mng->ct_sl);
12363 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
12364 NULL, "failed to create ASO CT pool");
12367 rte_spinlock_unlock(&mng->ct_sl);
12368 pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
12369 ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
12370 /* 0: inactive, 1: created, 2+: used by flows. */
12371 __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
12372 reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
12373 if (!ct->dr_action_orig) {
12374 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12375 ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
12376 (priv->sh->rx_domain, pool->devx_obj->obj,
12378 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
12381 RTE_SET_USED(reg_c);
12383 if (!ct->dr_action_orig) {
12384 flow_dv_aso_ct_dev_release(dev, ct_idx);
12385 rte_flow_error_set(error, rte_errno,
12386 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12387 "failed to create ASO CT action");
12391 if (!ct->dr_action_rply) {
12392 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12393 ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
12394 (priv->sh->rx_domain, pool->devx_obj->obj,
12396 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
12399 if (!ct->dr_action_rply) {
12400 flow_dv_aso_ct_dev_release(dev, ct_idx);
12401 rte_flow_error_set(error, rte_errno,
12402 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12403 "failed to create ASO CT action");
12411 * Create a conntrack object with context and actions by using ASO mechanism.
12414 * Pointer to rte_eth_dev structure.
12416 * Pointer to conntrack information profile.
12417 * @param[out] error
12418 * Pointer to the error structure.
12421 * Index to conntrack object on success, 0 otherwise.
12424 flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
12425 const struct rte_flow_action_conntrack *pro,
12426 struct rte_flow_error *error)
12428 struct mlx5_priv *priv = dev->data->dev_private;
12429 struct mlx5_dev_ctx_shared *sh = priv->sh;
12430 struct mlx5_aso_ct_action *ct;
12433 if (!sh->ct_aso_en)
12434 return rte_flow_error_set(error, ENOTSUP,
12435 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12436 "Connection is not supported");
12437 idx = flow_dv_aso_ct_alloc(dev, error);
12439 return rte_flow_error_set(error, rte_errno,
12440 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12441 "Failed to allocate CT object");
12442 ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12443 if (mlx5_aso_ct_update_by_wqe(sh, ct, pro))
12444 return rte_flow_error_set(error, EBUSY,
12445 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12446 "Failed to update CT");
12447 ct->is_original = !!pro->is_original_dir;
12448 ct->peer = pro->peer_port;
12453 * Fill the flow with DV spec, lock free
12454 * (mutex should be acquired by caller).
12457 * Pointer to rte_eth_dev structure.
12458 * @param[in, out] dev_flow
12459 * Pointer to the sub flow.
12461 * Pointer to the flow attributes.
12463 * Pointer to the list of items.
12464 * @param[in] actions
12465 * Pointer to the list of actions.
12466 * @param[out] error
12467 * Pointer to the error structure.
12470 * 0 on success, a negative errno value otherwise and rte_errno is set.
12473 flow_dv_translate(struct rte_eth_dev *dev,
12474 struct mlx5_flow *dev_flow,
12475 const struct rte_flow_attr *attr,
12476 const struct rte_flow_item items[],
12477 const struct rte_flow_action actions[],
12478 struct rte_flow_error *error)
12480 struct mlx5_priv *priv = dev->data->dev_private;
12481 struct mlx5_dev_config *dev_conf = &priv->config;
12482 struct rte_flow *flow = dev_flow->flow;
12483 struct mlx5_flow_handle *handle = dev_flow->handle;
12484 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12485 struct mlx5_flow_rss_desc *rss_desc;
12486 uint64_t item_flags = 0;
12487 uint64_t last_item = 0;
12488 uint64_t action_flags = 0;
12489 struct mlx5_flow_dv_matcher matcher = {
12491 .size = sizeof(matcher.mask.buf),
12495 bool actions_end = false;
12497 struct mlx5_flow_dv_modify_hdr_resource res;
12498 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
12499 sizeof(struct mlx5_modification_cmd) *
12500 (MLX5_MAX_MODIFY_NUM + 1)];
12502 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
12503 const struct rte_flow_action_count *count = NULL;
12504 const struct rte_flow_action_age *non_shared_age = NULL;
12505 union flow_dv_attr flow_attr = { .attr = 0 };
12507 union mlx5_flow_tbl_key tbl_key;
12508 uint32_t modify_action_position = UINT32_MAX;
12509 void *match_mask = matcher.mask.buf;
12510 void *match_value = dev_flow->dv.value.buf;
12511 uint8_t next_protocol = 0xff;
12512 struct rte_vlan_hdr vlan = { 0 };
12513 struct mlx5_flow_dv_dest_array_resource mdest_res;
12514 struct mlx5_flow_dv_sample_resource sample_res;
12515 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
12516 const struct rte_flow_action_sample *sample = NULL;
12517 struct mlx5_flow_sub_actions_list *sample_act;
12518 uint32_t sample_act_pos = UINT32_MAX;
12519 uint32_t age_act_pos = UINT32_MAX;
12520 uint32_t num_of_dest = 0;
12521 int tmp_actions_n = 0;
12524 const struct mlx5_flow_tunnel *tunnel = NULL;
12525 struct flow_grp_info grp_info = {
12526 .external = !!dev_flow->external,
12527 .transfer = !!attr->transfer,
12528 .fdb_def_rule = !!priv->fdb_def_rule,
12529 .skip_scale = dev_flow->skip_scale &
12530 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
12531 .std_tbl_fix = true,
12533 const struct rte_flow_item *head_item = items;
12536 return rte_flow_error_set(error, ENOMEM,
12537 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12539 "failed to push flow workspace");
12540 rss_desc = &wks->rss_desc;
12541 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
12542 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
12543 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12544 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12545 /* update normal path action resource into last index of array */
12546 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
12547 if (is_tunnel_offload_active(dev)) {
12548 if (dev_flow->tunnel) {
12549 RTE_VERIFY(dev_flow->tof_type ==
12550 MLX5_TUNNEL_OFFLOAD_MISS_RULE);
12551 tunnel = dev_flow->tunnel;
12553 tunnel = mlx5_get_tof(items, actions,
12554 &dev_flow->tof_type);
12555 dev_flow->tunnel = tunnel;
12557 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
12558 (dev, attr, tunnel, dev_flow->tof_type);
12560 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12561 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12562 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
12566 dev_flow->dv.group = table;
12567 if (attr->transfer)
12568 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12569 /* number of actions must be set to 0 in case of dirty stack. */
12570 mhdr_res->actions_num = 0;
12571 if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
12573 * do not add decap action if match rule drops packet
12574 * HW rejects rules with decap & drop
12576 * if tunnel match rule was inserted before matching tunnel set
12577 * rule flow table used in the match rule must be registered.
12578 * current implementation handles that in the
12579 * flow_dv_match_register() at the function end.
12581 bool add_decap = true;
12582 const struct rte_flow_action *ptr = actions;
12584 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
12585 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
12591 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12595 dev_flow->dv.actions[actions_n++] =
12596 dev_flow->dv.encap_decap->action;
12597 action_flags |= MLX5_FLOW_ACTION_DECAP;
12600 for (; !actions_end ; actions++) {
12601 const struct rte_flow_action_queue *queue;
12602 const struct rte_flow_action_rss *rss;
12603 const struct rte_flow_action *action = actions;
12604 const uint8_t *rss_key;
12605 struct mlx5_flow_tbl_resource *tbl;
12606 struct mlx5_aso_age_action *age_act;
12607 struct mlx5_flow_counter *cnt_act;
12608 uint32_t port_id = 0;
12609 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
12610 int action_type = actions->type;
12611 const struct rte_flow_action *found_action = NULL;
12612 uint32_t jump_group = 0;
12613 uint32_t owner_idx;
12614 struct mlx5_aso_ct_action *ct;
12616 if (!mlx5_flow_os_action_supported(action_type))
12617 return rte_flow_error_set(error, ENOTSUP,
12618 RTE_FLOW_ERROR_TYPE_ACTION,
12620 "action not supported");
12621 switch (action_type) {
12622 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
12623 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
12625 case RTE_FLOW_ACTION_TYPE_VOID:
12627 case RTE_FLOW_ACTION_TYPE_PORT_ID:
12628 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
12629 if (flow_dv_translate_action_port_id(dev, action,
12632 port_id_resource.port_id = port_id;
12633 MLX5_ASSERT(!handle->rix_port_id_action);
12634 if (flow_dv_port_id_action_resource_register
12635 (dev, &port_id_resource, dev_flow, error))
12637 dev_flow->dv.actions[actions_n++] =
12638 dev_flow->dv.port_id_action->action;
12639 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12640 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
12641 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12644 case RTE_FLOW_ACTION_TYPE_FLAG:
12645 action_flags |= MLX5_FLOW_ACTION_FLAG;
12646 dev_flow->handle->mark = 1;
12647 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12648 struct rte_flow_action_mark mark = {
12649 .id = MLX5_FLOW_MARK_DEFAULT,
12652 if (flow_dv_convert_action_mark(dev, &mark,
12656 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12659 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
12661 * Only one FLAG or MARK is supported per device flow
12662 * right now. So the pointer to the tag resource must be
12663 * zero before the register process.
12665 MLX5_ASSERT(!handle->dvh.rix_tag);
12666 if (flow_dv_tag_resource_register(dev, tag_be,
12669 MLX5_ASSERT(dev_flow->dv.tag_resource);
12670 dev_flow->dv.actions[actions_n++] =
12671 dev_flow->dv.tag_resource->action;
12673 case RTE_FLOW_ACTION_TYPE_MARK:
12674 action_flags |= MLX5_FLOW_ACTION_MARK;
12675 dev_flow->handle->mark = 1;
12676 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12677 const struct rte_flow_action_mark *mark =
12678 (const struct rte_flow_action_mark *)
12681 if (flow_dv_convert_action_mark(dev, mark,
12685 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12689 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
12690 /* Legacy (non-extensive) MARK action. */
12691 tag_be = mlx5_flow_mark_set
12692 (((const struct rte_flow_action_mark *)
12693 (actions->conf))->id);
12694 MLX5_ASSERT(!handle->dvh.rix_tag);
12695 if (flow_dv_tag_resource_register(dev, tag_be,
12698 MLX5_ASSERT(dev_flow->dv.tag_resource);
12699 dev_flow->dv.actions[actions_n++] =
12700 dev_flow->dv.tag_resource->action;
12702 case RTE_FLOW_ACTION_TYPE_SET_META:
12703 if (flow_dv_convert_action_set_meta
12704 (dev, mhdr_res, attr,
12705 (const struct rte_flow_action_set_meta *)
12706 actions->conf, error))
12708 action_flags |= MLX5_FLOW_ACTION_SET_META;
12710 case RTE_FLOW_ACTION_TYPE_SET_TAG:
12711 if (flow_dv_convert_action_set_tag
12713 (const struct rte_flow_action_set_tag *)
12714 actions->conf, error))
12716 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12718 case RTE_FLOW_ACTION_TYPE_DROP:
12719 action_flags |= MLX5_FLOW_ACTION_DROP;
12720 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
12722 case RTE_FLOW_ACTION_TYPE_QUEUE:
12723 queue = actions->conf;
12724 rss_desc->queue_num = 1;
12725 rss_desc->queue[0] = queue->index;
12726 action_flags |= MLX5_FLOW_ACTION_QUEUE;
12727 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
12728 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
12731 case RTE_FLOW_ACTION_TYPE_RSS:
12732 rss = actions->conf;
12733 memcpy(rss_desc->queue, rss->queue,
12734 rss->queue_num * sizeof(uint16_t));
12735 rss_desc->queue_num = rss->queue_num;
12736 /* NULL RSS key indicates default RSS key. */
12737 rss_key = !rss->key ? rss_hash_default_key : rss->key;
12738 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12740 * rss->level and rss.types should be set in advance
12741 * when expanding items for RSS.
12743 action_flags |= MLX5_FLOW_ACTION_RSS;
12744 dev_flow->handle->fate_action = rss_desc->shared_rss ?
12745 MLX5_FLOW_FATE_SHARED_RSS :
12746 MLX5_FLOW_FATE_QUEUE;
12748 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
12749 owner_idx = (uint32_t)(uintptr_t)action->conf;
12750 age_act = flow_aso_age_get_by_idx(dev, owner_idx);
12751 if (flow->age == 0) {
12752 flow->age = owner_idx;
12753 __atomic_fetch_add(&age_act->refcnt, 1,
12756 age_act_pos = actions_n++;
12757 action_flags |= MLX5_FLOW_ACTION_AGE;
12759 case RTE_FLOW_ACTION_TYPE_AGE:
12760 non_shared_age = action->conf;
12761 age_act_pos = actions_n++;
12762 action_flags |= MLX5_FLOW_ACTION_AGE;
12764 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
12765 owner_idx = (uint32_t)(uintptr_t)action->conf;
12766 cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
12768 MLX5_ASSERT(cnt_act != NULL);
12770 * When creating meter drop flow in drop table, the
12771 * counter should not overwrite the rte flow counter.
12773 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
12774 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
12775 dev_flow->dv.actions[actions_n++] =
12778 if (flow->counter == 0) {
12779 flow->counter = owner_idx;
12781 (&cnt_act->shared_info.refcnt,
12782 1, __ATOMIC_RELAXED);
12784 /* Save information first, will apply later. */
12785 action_flags |= MLX5_FLOW_ACTION_COUNT;
12788 case RTE_FLOW_ACTION_TYPE_COUNT:
12789 if (!priv->sh->devx) {
12790 return rte_flow_error_set
12792 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12794 "count action not supported");
12796 /* Save information first, will apply later. */
12797 count = action->conf;
12798 action_flags |= MLX5_FLOW_ACTION_COUNT;
12800 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
12801 dev_flow->dv.actions[actions_n++] =
12802 priv->sh->pop_vlan_action;
12803 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
12805 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
12806 if (!(action_flags &
12807 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
12808 flow_dev_get_vlan_info_from_items(items, &vlan);
12809 vlan.eth_proto = rte_be_to_cpu_16
12810 ((((const struct rte_flow_action_of_push_vlan *)
12811 actions->conf)->ethertype));
12812 found_action = mlx5_flow_find_action
12814 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
12816 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12817 found_action = mlx5_flow_find_action
12819 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
12821 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12822 if (flow_dv_create_action_push_vlan
12823 (dev, attr, &vlan, dev_flow, error))
12825 dev_flow->dv.actions[actions_n++] =
12826 dev_flow->dv.push_vlan_res->action;
12827 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
12829 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
12830 /* of_vlan_push action handled this action */
12831 MLX5_ASSERT(action_flags &
12832 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
12834 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
12835 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
12837 flow_dev_get_vlan_info_from_items(items, &vlan);
12838 mlx5_update_vlan_vid_pcp(actions, &vlan);
12839 /* If no VLAN push - this is a modify header action */
12840 if (flow_dv_convert_action_modify_vlan_vid
12841 (mhdr_res, actions, error))
12843 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
12845 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
12846 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
12847 if (flow_dv_create_action_l2_encap(dev, actions,
12852 dev_flow->dv.actions[actions_n++] =
12853 dev_flow->dv.encap_decap->action;
12854 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12855 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12856 sample_act->action_flags |=
12857 MLX5_FLOW_ACTION_ENCAP;
12859 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
12860 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
12861 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12865 dev_flow->dv.actions[actions_n++] =
12866 dev_flow->dv.encap_decap->action;
12867 action_flags |= MLX5_FLOW_ACTION_DECAP;
12869 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
12870 /* Handle encap with preceding decap. */
12871 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
12872 if (flow_dv_create_action_raw_encap
12873 (dev, actions, dev_flow, attr, error))
12875 dev_flow->dv.actions[actions_n++] =
12876 dev_flow->dv.encap_decap->action;
12878 /* Handle encap without preceding decap. */
12879 if (flow_dv_create_action_l2_encap
12880 (dev, actions, dev_flow, attr->transfer,
12883 dev_flow->dv.actions[actions_n++] =
12884 dev_flow->dv.encap_decap->action;
12886 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12887 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12888 sample_act->action_flags |=
12889 MLX5_FLOW_ACTION_ENCAP;
12891 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
12892 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
12894 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
12895 if (flow_dv_create_action_l2_decap
12896 (dev, dev_flow, attr->transfer, error))
12898 dev_flow->dv.actions[actions_n++] =
12899 dev_flow->dv.encap_decap->action;
12901 /* If decap is followed by encap, handle it at encap. */
12902 action_flags |= MLX5_FLOW_ACTION_DECAP;
12904 case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
12905 dev_flow->dv.actions[actions_n++] =
12906 (void *)(uintptr_t)action->conf;
12907 action_flags |= MLX5_FLOW_ACTION_JUMP;
12909 case RTE_FLOW_ACTION_TYPE_JUMP:
12910 jump_group = ((const struct rte_flow_action_jump *)
12911 action->conf)->group;
12912 grp_info.std_tbl_fix = 0;
12913 if (dev_flow->skip_scale &
12914 (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
12915 grp_info.skip_scale = 1;
12917 grp_info.skip_scale = 0;
12918 ret = mlx5_flow_group_to_table(dev, tunnel,
12924 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
12926 !!dev_flow->external,
12927 tunnel, jump_group, 0,
12930 return rte_flow_error_set
12932 RTE_FLOW_ERROR_TYPE_ACTION,
12934 "cannot create jump action.");
12935 if (flow_dv_jump_tbl_resource_register
12936 (dev, tbl, dev_flow, error)) {
12937 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12938 return rte_flow_error_set
12940 RTE_FLOW_ERROR_TYPE_ACTION,
12942 "cannot create jump action.");
12944 dev_flow->dv.actions[actions_n++] =
12945 dev_flow->dv.jump->action;
12946 action_flags |= MLX5_FLOW_ACTION_JUMP;
12947 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
12948 sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
12951 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
12952 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
12953 if (flow_dv_convert_action_modify_mac
12954 (mhdr_res, actions, error))
12956 action_flags |= actions->type ==
12957 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
12958 MLX5_FLOW_ACTION_SET_MAC_SRC :
12959 MLX5_FLOW_ACTION_SET_MAC_DST;
12961 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
12962 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
12963 if (flow_dv_convert_action_modify_ipv4
12964 (mhdr_res, actions, error))
12966 action_flags |= actions->type ==
12967 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
12968 MLX5_FLOW_ACTION_SET_IPV4_SRC :
12969 MLX5_FLOW_ACTION_SET_IPV4_DST;
12971 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
12972 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
12973 if (flow_dv_convert_action_modify_ipv6
12974 (mhdr_res, actions, error))
12976 action_flags |= actions->type ==
12977 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
12978 MLX5_FLOW_ACTION_SET_IPV6_SRC :
12979 MLX5_FLOW_ACTION_SET_IPV6_DST;
12981 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
12982 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
12983 if (flow_dv_convert_action_modify_tp
12984 (mhdr_res, actions, items,
12985 &flow_attr, dev_flow, !!(action_flags &
12986 MLX5_FLOW_ACTION_DECAP), error))
12988 action_flags |= actions->type ==
12989 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
12990 MLX5_FLOW_ACTION_SET_TP_SRC :
12991 MLX5_FLOW_ACTION_SET_TP_DST;
12993 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
12994 if (flow_dv_convert_action_modify_dec_ttl
12995 (mhdr_res, items, &flow_attr, dev_flow,
12997 MLX5_FLOW_ACTION_DECAP), error))
12999 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
13001 case RTE_FLOW_ACTION_TYPE_SET_TTL:
13002 if (flow_dv_convert_action_modify_ttl
13003 (mhdr_res, actions, items, &flow_attr,
13004 dev_flow, !!(action_flags &
13005 MLX5_FLOW_ACTION_DECAP), error))
13007 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
13009 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
13010 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
13011 if (flow_dv_convert_action_modify_tcp_seq
13012 (mhdr_res, actions, error))
13014 action_flags |= actions->type ==
13015 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
13016 MLX5_FLOW_ACTION_INC_TCP_SEQ :
13017 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
13020 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
13021 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
13022 if (flow_dv_convert_action_modify_tcp_ack
13023 (mhdr_res, actions, error))
13025 action_flags |= actions->type ==
13026 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
13027 MLX5_FLOW_ACTION_INC_TCP_ACK :
13028 MLX5_FLOW_ACTION_DEC_TCP_ACK;
13030 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
13031 if (flow_dv_convert_action_set_reg
13032 (mhdr_res, actions, error))
13034 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13036 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
13037 if (flow_dv_convert_action_copy_mreg
13038 (dev, mhdr_res, actions, error))
13040 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
13042 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
13043 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
13044 dev_flow->handle->fate_action =
13045 MLX5_FLOW_FATE_DEFAULT_MISS;
13047 case RTE_FLOW_ACTION_TYPE_METER:
13049 return rte_flow_error_set(error, rte_errno,
13050 RTE_FLOW_ERROR_TYPE_ACTION,
13051 NULL, "Failed to get meter in flow.");
13052 /* Set the meter action. */
13053 dev_flow->dv.actions[actions_n++] =
13054 wks->fm->meter_action;
13055 action_flags |= MLX5_FLOW_ACTION_METER;
13057 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
13058 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
13061 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
13063 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
13064 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
13067 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
13069 case RTE_FLOW_ACTION_TYPE_SAMPLE:
13070 sample_act_pos = actions_n;
13071 sample = (const struct rte_flow_action_sample *)
13074 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
13075 /* put encap action into group if work with port id */
13076 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
13077 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
13078 sample_act->action_flags |=
13079 MLX5_FLOW_ACTION_ENCAP;
13081 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
13082 if (flow_dv_convert_action_modify_field
13083 (dev, mhdr_res, actions, attr, error))
13085 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
13087 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
13088 owner_idx = (uint32_t)(uintptr_t)action->conf;
13089 ct = flow_aso_ct_get_by_idx(dev, owner_idx);
13091 return rte_flow_error_set(error, EINVAL,
13092 RTE_FLOW_ERROR_TYPE_ACTION,
13094 "Failed to get CT object.");
13095 if (mlx5_aso_ct_available(priv->sh, ct))
13096 return rte_flow_error_set(error, rte_errno,
13097 RTE_FLOW_ERROR_TYPE_ACTION,
13099 "CT is unavailable.");
13100 if (ct->is_original)
13101 dev_flow->dv.actions[actions_n] =
13102 ct->dr_action_orig;
13104 dev_flow->dv.actions[actions_n] =
13105 ct->dr_action_rply;
13106 if (flow->ct == 0) {
13107 flow->indirect_type =
13108 MLX5_INDIRECT_ACTION_TYPE_CT;
13109 flow->ct = owner_idx;
13110 __atomic_fetch_add(&ct->refcnt, 1,
13114 action_flags |= MLX5_FLOW_ACTION_CT;
13116 case RTE_FLOW_ACTION_TYPE_END:
13117 actions_end = true;
13118 if (mhdr_res->actions_num) {
13119 /* create modify action if needed. */
13120 if (flow_dv_modify_hdr_resource_register
13121 (dev, mhdr_res, dev_flow, error))
13123 dev_flow->dv.actions[modify_action_position] =
13124 handle->dvh.modify_hdr->action;
13127 * Handle AGE and COUNT action by single HW counter
13128 * when they are not shared.
13130 if (action_flags & MLX5_FLOW_ACTION_AGE) {
13131 if ((non_shared_age && count) ||
13132 !(priv->sh->flow_hit_aso_en &&
13133 (attr->group || attr->transfer))) {
13134 /* Creates age by counters. */
13135 cnt_act = flow_dv_prepare_counter
13142 dev_flow->dv.actions[age_act_pos] =
13146 if (!flow->age && non_shared_age) {
13147 flow->age = flow_dv_aso_age_alloc
13151 flow_dv_aso_age_params_init
13153 non_shared_age->context ?
13154 non_shared_age->context :
13155 (void *)(uintptr_t)
13156 (dev_flow->flow_idx),
13157 non_shared_age->timeout);
13159 age_act = flow_aso_age_get_by_idx(dev,
13161 dev_flow->dv.actions[age_act_pos] =
13162 age_act->dr_action;
13164 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
13166 * Create one count action, to be used
13167 * by all sub-flows.
13169 cnt_act = flow_dv_prepare_counter(dev, dev_flow,
13174 dev_flow->dv.actions[actions_n++] =
13180 if (mhdr_res->actions_num &&
13181 modify_action_position == UINT32_MAX)
13182 modify_action_position = actions_n++;
13184 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
13185 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
13186 int item_type = items->type;
13188 if (!mlx5_flow_os_item_supported(item_type))
13189 return rte_flow_error_set(error, ENOTSUP,
13190 RTE_FLOW_ERROR_TYPE_ITEM,
13191 NULL, "item not supported");
13192 switch (item_type) {
13193 case RTE_FLOW_ITEM_TYPE_PORT_ID:
13194 flow_dv_translate_item_port_id
13195 (dev, match_mask, match_value, items, attr);
13196 last_item = MLX5_FLOW_ITEM_PORT_ID;
13198 case RTE_FLOW_ITEM_TYPE_ETH:
13199 flow_dv_translate_item_eth(match_mask, match_value,
13201 dev_flow->dv.group);
13202 matcher.priority = action_flags &
13203 MLX5_FLOW_ACTION_DEFAULT_MISS &&
13204 !dev_flow->external ?
13205 MLX5_PRIORITY_MAP_L3 :
13206 MLX5_PRIORITY_MAP_L2;
13207 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
13208 MLX5_FLOW_LAYER_OUTER_L2;
13210 case RTE_FLOW_ITEM_TYPE_VLAN:
13211 flow_dv_translate_item_vlan(dev_flow,
13212 match_mask, match_value,
13214 dev_flow->dv.group);
13215 matcher.priority = MLX5_PRIORITY_MAP_L2;
13216 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
13217 MLX5_FLOW_LAYER_INNER_VLAN) :
13218 (MLX5_FLOW_LAYER_OUTER_L2 |
13219 MLX5_FLOW_LAYER_OUTER_VLAN);
13221 case RTE_FLOW_ITEM_TYPE_IPV4:
13222 mlx5_flow_tunnel_ip_check(items, next_protocol,
13223 &item_flags, &tunnel);
13224 flow_dv_translate_item_ipv4(match_mask, match_value,
13226 dev_flow->dv.group);
13227 matcher.priority = MLX5_PRIORITY_MAP_L3;
13228 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
13229 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
13230 if (items->mask != NULL &&
13231 ((const struct rte_flow_item_ipv4 *)
13232 items->mask)->hdr.next_proto_id) {
13234 ((const struct rte_flow_item_ipv4 *)
13235 (items->spec))->hdr.next_proto_id;
13237 ((const struct rte_flow_item_ipv4 *)
13238 (items->mask))->hdr.next_proto_id;
13240 /* Reset for inner layer. */
13241 next_protocol = 0xff;
13244 case RTE_FLOW_ITEM_TYPE_IPV6:
13245 mlx5_flow_tunnel_ip_check(items, next_protocol,
13246 &item_flags, &tunnel);
13247 flow_dv_translate_item_ipv6(match_mask, match_value,
13249 dev_flow->dv.group);
13250 matcher.priority = MLX5_PRIORITY_MAP_L3;
13251 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
13252 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
13253 if (items->mask != NULL &&
13254 ((const struct rte_flow_item_ipv6 *)
13255 items->mask)->hdr.proto) {
13257 ((const struct rte_flow_item_ipv6 *)
13258 items->spec)->hdr.proto;
13260 ((const struct rte_flow_item_ipv6 *)
13261 items->mask)->hdr.proto;
13263 /* Reset for inner layer. */
13264 next_protocol = 0xff;
13267 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
13268 flow_dv_translate_item_ipv6_frag_ext(match_mask,
13271 last_item = tunnel ?
13272 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
13273 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
13274 if (items->mask != NULL &&
13275 ((const struct rte_flow_item_ipv6_frag_ext *)
13276 items->mask)->hdr.next_header) {
13278 ((const struct rte_flow_item_ipv6_frag_ext *)
13279 items->spec)->hdr.next_header;
13281 ((const struct rte_flow_item_ipv6_frag_ext *)
13282 items->mask)->hdr.next_header;
13284 /* Reset for inner layer. */
13285 next_protocol = 0xff;
13288 case RTE_FLOW_ITEM_TYPE_TCP:
13289 flow_dv_translate_item_tcp(match_mask, match_value,
13291 matcher.priority = MLX5_PRIORITY_MAP_L4;
13292 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
13293 MLX5_FLOW_LAYER_OUTER_L4_TCP;
13295 case RTE_FLOW_ITEM_TYPE_UDP:
13296 flow_dv_translate_item_udp(match_mask, match_value,
13298 matcher.priority = MLX5_PRIORITY_MAP_L4;
13299 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
13300 MLX5_FLOW_LAYER_OUTER_L4_UDP;
13302 case RTE_FLOW_ITEM_TYPE_GRE:
13303 flow_dv_translate_item_gre(match_mask, match_value,
13305 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13306 last_item = MLX5_FLOW_LAYER_GRE;
13308 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
13309 flow_dv_translate_item_gre_key(match_mask,
13310 match_value, items);
13311 last_item = MLX5_FLOW_LAYER_GRE_KEY;
13313 case RTE_FLOW_ITEM_TYPE_NVGRE:
13314 flow_dv_translate_item_nvgre(match_mask, match_value,
13316 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13317 last_item = MLX5_FLOW_LAYER_GRE;
13319 case RTE_FLOW_ITEM_TYPE_VXLAN:
13320 flow_dv_translate_item_vxlan(dev, attr,
13321 match_mask, match_value,
13323 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13324 last_item = MLX5_FLOW_LAYER_VXLAN;
13326 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
13327 flow_dv_translate_item_vxlan_gpe(match_mask,
13328 match_value, items,
13330 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13331 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
13333 case RTE_FLOW_ITEM_TYPE_GENEVE:
13334 flow_dv_translate_item_geneve(match_mask, match_value,
13336 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13337 last_item = MLX5_FLOW_LAYER_GENEVE;
13339 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
13340 ret = flow_dv_translate_item_geneve_opt(dev, match_mask,
13344 return rte_flow_error_set(error, -ret,
13345 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13346 "cannot create GENEVE TLV option");
13347 flow->geneve_tlv_option = 1;
13348 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
13350 case RTE_FLOW_ITEM_TYPE_MPLS:
13351 flow_dv_translate_item_mpls(match_mask, match_value,
13352 items, last_item, tunnel);
13353 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13354 last_item = MLX5_FLOW_LAYER_MPLS;
13356 case RTE_FLOW_ITEM_TYPE_MARK:
13357 flow_dv_translate_item_mark(dev, match_mask,
13358 match_value, items);
13359 last_item = MLX5_FLOW_ITEM_MARK;
13361 case RTE_FLOW_ITEM_TYPE_META:
13362 flow_dv_translate_item_meta(dev, match_mask,
13363 match_value, attr, items);
13364 last_item = MLX5_FLOW_ITEM_METADATA;
13366 case RTE_FLOW_ITEM_TYPE_ICMP:
13367 flow_dv_translate_item_icmp(match_mask, match_value,
13369 last_item = MLX5_FLOW_LAYER_ICMP;
13371 case RTE_FLOW_ITEM_TYPE_ICMP6:
13372 flow_dv_translate_item_icmp6(match_mask, match_value,
13374 last_item = MLX5_FLOW_LAYER_ICMP6;
13376 case RTE_FLOW_ITEM_TYPE_TAG:
13377 flow_dv_translate_item_tag(dev, match_mask,
13378 match_value, items);
13379 last_item = MLX5_FLOW_ITEM_TAG;
13381 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
13382 flow_dv_translate_mlx5_item_tag(dev, match_mask,
13383 match_value, items);
13384 last_item = MLX5_FLOW_ITEM_TAG;
13386 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
13387 flow_dv_translate_item_tx_queue(dev, match_mask,
13390 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
13392 case RTE_FLOW_ITEM_TYPE_GTP:
13393 flow_dv_translate_item_gtp(match_mask, match_value,
13395 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13396 last_item = MLX5_FLOW_LAYER_GTP;
13398 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
13399 ret = flow_dv_translate_item_gtp_psc(match_mask,
13403 return rte_flow_error_set(error, -ret,
13404 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13405 "cannot create GTP PSC item");
13406 last_item = MLX5_FLOW_LAYER_GTP_PSC;
13408 case RTE_FLOW_ITEM_TYPE_ECPRI:
13409 if (!mlx5_flex_parser_ecpri_exist(dev)) {
13410 /* Create it only the first time to be used. */
13411 ret = mlx5_flex_parser_ecpri_alloc(dev);
13413 return rte_flow_error_set
13415 RTE_FLOW_ERROR_TYPE_ITEM,
13417 "cannot create eCPRI parser");
13419 flow_dv_translate_item_ecpri(dev, match_mask,
13420 match_value, items,
13422 /* No other protocol should follow eCPRI layer. */
13423 last_item = MLX5_FLOW_LAYER_ECPRI;
13425 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
13426 flow_dv_translate_item_integrity(match_mask,
13430 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
13431 flow_dv_translate_item_aso_ct(dev, match_mask,
13432 match_value, items);
13437 item_flags |= last_item;
13440 * When E-Switch mode is enabled, we have two cases where we need to
13441 * set the source port manually.
13442 * The first one, is in case of Nic steering rule, and the second is
13443 * E-Switch rule where no port_id item was found. In both cases
13444 * the source port is set according the current port in use.
13446 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
13447 (priv->representor || priv->master)) {
13448 if (flow_dv_translate_item_port_id(dev, match_mask,
13449 match_value, NULL, attr))
13452 #ifdef RTE_LIBRTE_MLX5_DEBUG
13453 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
13454 dev_flow->dv.value.buf));
13457 * Layers may be already initialized from prefix flow if this dev_flow
13458 * is the suffix flow.
13460 handle->layers |= item_flags;
13461 if (action_flags & MLX5_FLOW_ACTION_RSS)
13462 flow_dv_hashfields_set(dev_flow, rss_desc);
13463 /* If has RSS action in the sample action, the Sample/Mirror resource
13464 * should be registered after the hash filed be update.
13466 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
13467 ret = flow_dv_translate_action_sample(dev,
13476 ret = flow_dv_create_action_sample(dev,
13485 return rte_flow_error_set
13487 RTE_FLOW_ERROR_TYPE_ACTION,
13489 "cannot create sample action");
13490 if (num_of_dest > 1) {
13491 dev_flow->dv.actions[sample_act_pos] =
13492 dev_flow->dv.dest_array_res->action;
13494 dev_flow->dv.actions[sample_act_pos] =
13495 dev_flow->dv.sample_res->verbs_action;
13499 * For multiple destination (sample action with ratio=1), the encap
13500 * action and port id action will be combined into group action.
13501 * So need remove the original these actions in the flow and only
13502 * use the sample action instead of.
13504 if (num_of_dest > 1 &&
13505 (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
13507 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
13509 for (i = 0; i < actions_n; i++) {
13510 if ((sample_act->dr_encap_action &&
13511 sample_act->dr_encap_action ==
13512 dev_flow->dv.actions[i]) ||
13513 (sample_act->dr_port_id_action &&
13514 sample_act->dr_port_id_action ==
13515 dev_flow->dv.actions[i]) ||
13516 (sample_act->dr_jump_action &&
13517 sample_act->dr_jump_action ==
13518 dev_flow->dv.actions[i]))
13520 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
13522 memcpy((void *)dev_flow->dv.actions,
13523 (void *)temp_actions,
13524 tmp_actions_n * sizeof(void *));
13525 actions_n = tmp_actions_n;
13527 dev_flow->dv.actions_n = actions_n;
13528 dev_flow->act_flags = action_flags;
13529 if (wks->skip_matcher_reg)
13531 /* Register matcher. */
13532 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
13533 matcher.mask.size);
13534 matcher.priority = mlx5_get_matcher_priority(dev, attr,
13537 * When creating meter drop flow in drop table, using original
13538 * 5-tuple match, the matcher priority should be lower than
13541 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
13542 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
13543 matcher.priority <= MLX5_REG_BITS)
13544 matcher.priority += MLX5_REG_BITS;
13545 /* reserved field no needs to be set to 0 here. */
13546 tbl_key.is_fdb = attr->transfer;
13547 tbl_key.is_egress = attr->egress;
13548 tbl_key.level = dev_flow->dv.group;
13549 tbl_key.id = dev_flow->dv.table_id;
13550 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
13551 tunnel, attr->group, error))
13557 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13560 * @param[in, out] action
13561 * Shred RSS action holding hash RX queue objects.
13562 * @param[in] hash_fields
13563 * Defines combination of packet fields to participate in RX hash.
13564 * @param[in] tunnel
13566 * @param[in] hrxq_idx
13567 * Hash RX queue index to set.
13570 * 0 on success, otherwise negative errno value.
13573 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
13574 const uint64_t hash_fields,
13577 uint32_t *hrxqs = action->hrxq;
13579 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13580 case MLX5_RSS_HASH_IPV4:
13581 /* fall-through. */
13582 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13583 /* fall-through. */
13584 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13585 hrxqs[0] = hrxq_idx;
13587 case MLX5_RSS_HASH_IPV4_TCP:
13588 /* fall-through. */
13589 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13590 /* fall-through. */
13591 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13592 hrxqs[1] = hrxq_idx;
13594 case MLX5_RSS_HASH_IPV4_UDP:
13595 /* fall-through. */
13596 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13597 /* fall-through. */
13598 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13599 hrxqs[2] = hrxq_idx;
13601 case MLX5_RSS_HASH_IPV6:
13602 /* fall-through. */
13603 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13604 /* fall-through. */
13605 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13606 hrxqs[3] = hrxq_idx;
13608 case MLX5_RSS_HASH_IPV6_TCP:
13609 /* fall-through. */
13610 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13611 /* fall-through. */
13612 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13613 hrxqs[4] = hrxq_idx;
13615 case MLX5_RSS_HASH_IPV6_UDP:
13616 /* fall-through. */
13617 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13618 /* fall-through. */
13619 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13620 hrxqs[5] = hrxq_idx;
13622 case MLX5_RSS_HASH_NONE:
13623 hrxqs[6] = hrxq_idx;
13631 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13635 * Pointer to the Ethernet device structure.
13637 * Shared RSS action ID holding hash RX queue objects.
13638 * @param[in] hash_fields
13639 * Defines combination of packet fields to participate in RX hash.
13640 * @param[in] tunnel
13644 * Valid hash RX queue index, otherwise 0.
13647 __flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
13648 const uint64_t hash_fields)
13650 struct mlx5_priv *priv = dev->data->dev_private;
13651 struct mlx5_shared_action_rss *shared_rss =
13652 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
13653 const uint32_t *hrxqs = shared_rss->hrxq;
13655 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13656 case MLX5_RSS_HASH_IPV4:
13657 /* fall-through. */
13658 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13659 /* fall-through. */
13660 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13662 case MLX5_RSS_HASH_IPV4_TCP:
13663 /* fall-through. */
13664 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13665 /* fall-through. */
13666 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13668 case MLX5_RSS_HASH_IPV4_UDP:
13669 /* fall-through. */
13670 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13671 /* fall-through. */
13672 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13674 case MLX5_RSS_HASH_IPV6:
13675 /* fall-through. */
13676 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13677 /* fall-through. */
13678 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13680 case MLX5_RSS_HASH_IPV6_TCP:
13681 /* fall-through. */
13682 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13683 /* fall-through. */
13684 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13686 case MLX5_RSS_HASH_IPV6_UDP:
13687 /* fall-through. */
13688 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13689 /* fall-through. */
13690 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13692 case MLX5_RSS_HASH_NONE:
13701 * Apply the flow to the NIC, lock free,
13702 * (mutex should be acquired by caller).
13705 * Pointer to the Ethernet device structure.
13706 * @param[in, out] flow
13707 * Pointer to flow structure.
13708 * @param[out] error
13709 * Pointer to error structure.
13712 * 0 on success, a negative errno value otherwise and rte_errno is set.
13715 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
13716 struct rte_flow_error *error)
13718 struct mlx5_flow_dv_workspace *dv;
13719 struct mlx5_flow_handle *dh;
13720 struct mlx5_flow_handle_dv *dv_h;
13721 struct mlx5_flow *dev_flow;
13722 struct mlx5_priv *priv = dev->data->dev_private;
13723 uint32_t handle_idx;
13727 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13728 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
13732 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
13733 dev_flow = &wks->flows[idx];
13734 dv = &dev_flow->dv;
13735 dh = dev_flow->handle;
13738 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
13739 if (dv->transfer) {
13740 MLX5_ASSERT(priv->sh->dr_drop_action);
13741 dv->actions[n++] = priv->sh->dr_drop_action;
13743 #ifdef HAVE_MLX5DV_DR
13744 /* DR supports drop action placeholder. */
13745 MLX5_ASSERT(priv->sh->dr_drop_action);
13746 dv->actions[n++] = dv->group ?
13747 priv->sh->dr_drop_action :
13748 priv->root_drop_action;
13750 /* For DV we use the explicit drop queue. */
13751 MLX5_ASSERT(priv->drop_queue.hrxq);
13753 priv->drop_queue.hrxq->action;
13756 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
13757 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
13758 struct mlx5_hrxq *hrxq;
13761 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
13766 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13767 "cannot get hash queue");
13770 dh->rix_hrxq = hrxq_idx;
13771 dv->actions[n++] = hrxq->action;
13772 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13773 struct mlx5_hrxq *hrxq = NULL;
13776 hrxq_idx = __flow_dv_action_rss_hrxq_lookup(dev,
13777 rss_desc->shared_rss,
13778 dev_flow->hash_fields);
13780 hrxq = mlx5_ipool_get
13781 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
13786 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13787 "cannot get hash queue");
13790 dh->rix_srss = rss_desc->shared_rss;
13791 dv->actions[n++] = hrxq->action;
13792 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
13793 if (!priv->sh->default_miss_action) {
13796 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13797 "default miss action not be created.");
13800 dv->actions[n++] = priv->sh->default_miss_action;
13802 misc_mask = flow_dv_matcher_enable(dv->value.buf);
13803 __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
13804 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
13805 (void *)&dv->value, n,
13806 dv->actions, &dh->drv_flow);
13810 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13812 (!priv->config.allow_duplicate_pattern &&
13814 "duplicating pattern is not allowed" :
13815 "hardware refuses to create flow");
13818 if (priv->vmwa_context &&
13819 dh->vf_vlan.tag && !dh->vf_vlan.created) {
13821 * The rule contains the VLAN pattern.
13822 * For VF we are going to create VLAN
13823 * interface to make hypervisor set correct
13824 * e-Switch vport context.
13826 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
13831 err = rte_errno; /* Save rte_errno before cleanup. */
13832 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
13833 handle_idx, dh, next) {
13834 /* hrxq is union, don't clear it if the flag is not set. */
13835 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
13836 mlx5_hrxq_release(dev, dh->rix_hrxq);
13838 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13841 if (dh->vf_vlan.tag && dh->vf_vlan.created)
13842 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
13844 rte_errno = err; /* Restore rte_errno. */
13849 flow_dv_matcher_remove_cb(void *tool_ctx __rte_unused,
13850 struct mlx5_list_entry *entry)
13852 struct mlx5_flow_dv_matcher *resource = container_of(entry,
13856 claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
13857 mlx5_free(resource);
13861 * Release the flow matcher.
13864 * Pointer to Ethernet device.
13866 * Index to port ID action resource.
13869 * 1 while a reference on it exists, 0 when freed.
13872 flow_dv_matcher_release(struct rte_eth_dev *dev,
13873 struct mlx5_flow_handle *handle)
13875 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
13876 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
13877 typeof(*tbl), tbl);
13880 MLX5_ASSERT(matcher->matcher_object);
13881 ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
13882 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
13887 flow_dv_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
13889 struct mlx5_dev_ctx_shared *sh = tool_ctx;
13890 struct mlx5_flow_dv_encap_decap_resource *res =
13891 container_of(entry, typeof(*res), entry);
13893 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13894 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
13898 * Release an encap/decap resource.
13901 * Pointer to Ethernet device.
13902 * @param encap_decap_idx
13903 * Index of encap decap resource.
13906 * 1 while a reference on it exists, 0 when freed.
13909 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
13910 uint32_t encap_decap_idx)
13912 struct mlx5_priv *priv = dev->data->dev_private;
13913 struct mlx5_flow_dv_encap_decap_resource *resource;
13915 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
13919 MLX5_ASSERT(resource->action);
13920 return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
13924 * Release an jump to table action resource.
13927 * Pointer to Ethernet device.
13929 * Index to the jump action resource.
13932 * 1 while a reference on it exists, 0 when freed.
13935 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
13938 struct mlx5_priv *priv = dev->data->dev_private;
13939 struct mlx5_flow_tbl_data_entry *tbl_data;
13941 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
13945 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
13949 flow_dv_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
13951 struct mlx5_flow_dv_modify_hdr_resource *res =
13952 container_of(entry, typeof(*res), entry);
13953 struct mlx5_dev_ctx_shared *sh = tool_ctx;
13955 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13956 mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
13960 * Release a modify-header resource.
13963 * Pointer to Ethernet device.
13965 * Pointer to mlx5_flow_handle.
13968 * 1 while a reference on it exists, 0 when freed.
13971 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
13972 struct mlx5_flow_handle *handle)
13974 struct mlx5_priv *priv = dev->data->dev_private;
13975 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
13977 MLX5_ASSERT(entry->action);
13978 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
13982 flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
13984 struct mlx5_dev_ctx_shared *sh = tool_ctx;
13985 struct mlx5_flow_dv_port_id_action_resource *resource =
13986 container_of(entry, typeof(*resource), entry);
13988 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
13989 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
13993 * Release port ID action resource.
13996 * Pointer to Ethernet device.
13998 * Pointer to mlx5_flow_handle.
14001 * 1 while a reference on it exists, 0 when freed.
14004 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
14007 struct mlx5_priv *priv = dev->data->dev_private;
14008 struct mlx5_flow_dv_port_id_action_resource *resource;
14010 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
14013 MLX5_ASSERT(resource->action);
14014 return mlx5_list_unregister(priv->sh->port_id_action_list,
14019 * Release shared RSS action resource.
14022 * Pointer to Ethernet device.
14024 * Shared RSS action index.
14027 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
14029 struct mlx5_priv *priv = dev->data->dev_private;
14030 struct mlx5_shared_action_rss *shared_rss;
14032 shared_rss = mlx5_ipool_get
14033 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
14034 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14038 flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
14040 struct mlx5_dev_ctx_shared *sh = tool_ctx;
14041 struct mlx5_flow_dv_push_vlan_action_resource *resource =
14042 container_of(entry, typeof(*resource), entry);
14044 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14045 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
14049 * Release push vlan action resource.
14052 * Pointer to Ethernet device.
14054 * Pointer to mlx5_flow_handle.
14057 * 1 while a reference on it exists, 0 when freed.
14060 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
14061 struct mlx5_flow_handle *handle)
14063 struct mlx5_priv *priv = dev->data->dev_private;
14064 struct mlx5_flow_dv_push_vlan_action_resource *resource;
14065 uint32_t idx = handle->dvh.rix_push_vlan;
14067 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
14070 MLX5_ASSERT(resource->action);
14071 return mlx5_list_unregister(priv->sh->push_vlan_action_list,
14076 * Release the fate resource.
14079 * Pointer to Ethernet device.
14081 * Pointer to mlx5_flow_handle.
14084 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
14085 struct mlx5_flow_handle *handle)
14087 if (!handle->rix_fate)
14089 switch (handle->fate_action) {
14090 case MLX5_FLOW_FATE_QUEUE:
14091 if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
14092 mlx5_hrxq_release(dev, handle->rix_hrxq);
14094 case MLX5_FLOW_FATE_JUMP:
14095 flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
14097 case MLX5_FLOW_FATE_PORT_ID:
14098 flow_dv_port_id_action_resource_release(dev,
14099 handle->rix_port_id_action);
14102 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
14105 handle->rix_fate = 0;
14109 flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
14110 struct mlx5_list_entry *entry)
14112 struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
14115 struct rte_eth_dev *dev = resource->dev;
14116 struct mlx5_priv *priv = dev->data->dev_private;
14118 if (resource->verbs_action)
14119 claim_zero(mlx5_flow_os_destroy_flow_action
14120 (resource->verbs_action));
14121 if (resource->normal_path_tbl)
14122 flow_dv_tbl_resource_release(MLX5_SH(dev),
14123 resource->normal_path_tbl);
14124 flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
14125 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
14126 DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
14130 * Release an sample resource.
14133 * Pointer to Ethernet device.
14135 * Pointer to mlx5_flow_handle.
14138 * 1 while a reference on it exists, 0 when freed.
14141 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
14142 struct mlx5_flow_handle *handle)
14144 struct mlx5_priv *priv = dev->data->dev_private;
14145 struct mlx5_flow_dv_sample_resource *resource;
14147 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
14148 handle->dvh.rix_sample);
14151 MLX5_ASSERT(resource->verbs_action);
14152 return mlx5_list_unregister(priv->sh->sample_action_list,
14157 flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
14158 struct mlx5_list_entry *entry)
14160 struct mlx5_flow_dv_dest_array_resource *resource =
14161 container_of(entry, typeof(*resource), entry);
14162 struct rte_eth_dev *dev = resource->dev;
14163 struct mlx5_priv *priv = dev->data->dev_private;
14166 MLX5_ASSERT(resource->action);
14167 if (resource->action)
14168 claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
14169 for (; i < resource->num_of_dest; i++)
14170 flow_dv_sample_sub_actions_release(dev,
14171 &resource->sample_idx[i]);
14172 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
14173 DRV_LOG(DEBUG, "destination array resource %p: removed",
14178 * Release an destination array resource.
14181 * Pointer to Ethernet device.
14183 * Pointer to mlx5_flow_handle.
14186 * 1 while a reference on it exists, 0 when freed.
14189 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
14190 struct mlx5_flow_handle *handle)
14192 struct mlx5_priv *priv = dev->data->dev_private;
14193 struct mlx5_flow_dv_dest_array_resource *resource;
14195 resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
14196 handle->dvh.rix_dest_array);
14199 MLX5_ASSERT(resource->action);
14200 return mlx5_list_unregister(priv->sh->dest_array_list,
14205 flow_dv_geneve_tlv_option_resource_release(struct rte_eth_dev *dev)
14207 struct mlx5_priv *priv = dev->data->dev_private;
14208 struct mlx5_dev_ctx_shared *sh = priv->sh;
14209 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
14210 sh->geneve_tlv_option_resource;
14211 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
14212 if (geneve_opt_resource) {
14213 if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
14214 __ATOMIC_RELAXED))) {
14215 claim_zero(mlx5_devx_cmd_destroy
14216 (geneve_opt_resource->obj));
14217 mlx5_free(sh->geneve_tlv_option_resource);
14218 sh->geneve_tlv_option_resource = NULL;
14221 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
14225 * Remove the flow from the NIC but keeps it in memory.
14226 * Lock free, (mutex should be acquired by caller).
14229 * Pointer to Ethernet device.
14230 * @param[in, out] flow
14231 * Pointer to flow structure.
14234 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
14236 struct mlx5_flow_handle *dh;
14237 uint32_t handle_idx;
14238 struct mlx5_priv *priv = dev->data->dev_private;
14242 handle_idx = flow->dev_handles;
14243 while (handle_idx) {
14244 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14248 if (dh->drv_flow) {
14249 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
14250 dh->drv_flow = NULL;
14252 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
14253 flow_dv_fate_resource_release(dev, dh);
14254 if (dh->vf_vlan.tag && dh->vf_vlan.created)
14255 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
14256 handle_idx = dh->next.next;
14261 * Remove the flow from the NIC and the memory.
14262 * Lock free, (mutex should be acquired by caller).
14265 * Pointer to the Ethernet device structure.
14266 * @param[in, out] flow
14267 * Pointer to flow structure.
14270 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
14272 struct mlx5_flow_handle *dev_handle;
14273 struct mlx5_priv *priv = dev->data->dev_private;
14274 struct mlx5_flow_meter_info *fm = NULL;
14279 flow_dv_remove(dev, flow);
14280 if (flow->counter) {
14281 flow_dv_counter_free(dev, flow->counter);
14285 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
14287 mlx5_flow_meter_detach(priv, fm);
14290 /* Keep the current age handling by default. */
14291 if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
14292 flow_dv_aso_ct_release(dev, flow->ct, NULL);
14293 else if (flow->age)
14294 flow_dv_aso_age_release(dev, flow->age);
14295 if (flow->geneve_tlv_option) {
14296 flow_dv_geneve_tlv_option_resource_release(dev);
14297 flow->geneve_tlv_option = 0;
14299 while (flow->dev_handles) {
14300 uint32_t tmp_idx = flow->dev_handles;
14302 dev_handle = mlx5_ipool_get(priv->sh->ipool
14303 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
14306 flow->dev_handles = dev_handle->next.next;
14307 if (dev_handle->dvh.matcher)
14308 flow_dv_matcher_release(dev, dev_handle);
14309 if (dev_handle->dvh.rix_sample)
14310 flow_dv_sample_resource_release(dev, dev_handle);
14311 if (dev_handle->dvh.rix_dest_array)
14312 flow_dv_dest_array_resource_release(dev, dev_handle);
14313 if (dev_handle->dvh.rix_encap_decap)
14314 flow_dv_encap_decap_resource_release(dev,
14315 dev_handle->dvh.rix_encap_decap);
14316 if (dev_handle->dvh.modify_hdr)
14317 flow_dv_modify_hdr_resource_release(dev, dev_handle);
14318 if (dev_handle->dvh.rix_push_vlan)
14319 flow_dv_push_vlan_action_resource_release(dev,
14321 if (dev_handle->dvh.rix_tag)
14322 flow_dv_tag_release(dev,
14323 dev_handle->dvh.rix_tag);
14324 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
14325 flow_dv_fate_resource_release(dev, dev_handle);
14327 srss = dev_handle->rix_srss;
14328 if (fm && dev_handle->is_meter_flow_id &&
14329 dev_handle->split_flow_id)
14330 mlx5_ipool_free(fm->flow_ipool,
14331 dev_handle->split_flow_id);
14332 else if (dev_handle->split_flow_id &&
14333 !dev_handle->is_meter_flow_id)
14334 mlx5_ipool_free(priv->sh->ipool
14335 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
14336 dev_handle->split_flow_id);
14337 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
14341 flow_dv_shared_rss_action_release(dev, srss);
14345 * Release array of hash RX queue objects.
14349 * Pointer to the Ethernet device structure.
14350 * @param[in, out] hrxqs
14351 * Array of hash RX queue objects.
14354 * Total number of references to hash RX queue objects in *hrxqs* array
14355 * after this operation.
14358 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
14359 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
14364 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
14365 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
14375 * Release all hash RX queue objects representing shared RSS action.
14378 * Pointer to the Ethernet device structure.
14379 * @param[in, out] action
14380 * Shared RSS action to remove hash RX queue objects from.
14383 * Total number of references to hash RX queue objects stored in *action*
14384 * after this operation.
14385 * Expected to be 0 if no external references held.
14388 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
14389 struct mlx5_shared_action_rss *shared_rss)
14391 return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
14395 * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
14398 * Only one hash value is available for one L3+L4 combination:
14400 * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
14401 * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
14402 * same slot in mlx5_rss_hash_fields.
14405 * Pointer to the shared action RSS conf.
14406 * @param[in, out] hash_field
14407 * hash_field variable needed to be adjusted.
14413 __flow_dv_action_rss_l34_hash_adjust(struct mlx5_shared_action_rss *rss,
14414 uint64_t *hash_field)
14416 uint64_t rss_types = rss->origin.types;
14418 switch (*hash_field & ~IBV_RX_HASH_INNER) {
14419 case MLX5_RSS_HASH_IPV4:
14420 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
14421 *hash_field &= ~MLX5_RSS_HASH_IPV4;
14422 if (rss_types & ETH_RSS_L3_DST_ONLY)
14423 *hash_field |= IBV_RX_HASH_DST_IPV4;
14424 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
14425 *hash_field |= IBV_RX_HASH_SRC_IPV4;
14427 *hash_field |= MLX5_RSS_HASH_IPV4;
14430 case MLX5_RSS_HASH_IPV6:
14431 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
14432 *hash_field &= ~MLX5_RSS_HASH_IPV6;
14433 if (rss_types & ETH_RSS_L3_DST_ONLY)
14434 *hash_field |= IBV_RX_HASH_DST_IPV6;
14435 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
14436 *hash_field |= IBV_RX_HASH_SRC_IPV6;
14438 *hash_field |= MLX5_RSS_HASH_IPV6;
14441 case MLX5_RSS_HASH_IPV4_UDP:
14442 /* fall-through. */
14443 case MLX5_RSS_HASH_IPV6_UDP:
14444 if (rss_types & ETH_RSS_UDP) {
14445 *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
14446 if (rss_types & ETH_RSS_L4_DST_ONLY)
14447 *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
14448 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
14449 *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
14451 *hash_field |= MLX5_UDP_IBV_RX_HASH;
14454 case MLX5_RSS_HASH_IPV4_TCP:
14455 /* fall-through. */
14456 case MLX5_RSS_HASH_IPV6_TCP:
14457 if (rss_types & ETH_RSS_TCP) {
14458 *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
14459 if (rss_types & ETH_RSS_L4_DST_ONLY)
14460 *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
14461 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
14462 *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
14464 *hash_field |= MLX5_TCP_IBV_RX_HASH;
14473 * Setup shared RSS action.
14474 * Prepare set of hash RX queue objects sufficient to handle all valid
14475 * hash_fields combinations (see enum ibv_rx_hash_fields).
14478 * Pointer to the Ethernet device structure.
14479 * @param[in] action_idx
14480 * Shared RSS action ipool index.
14481 * @param[in, out] action
14482 * Partially initialized shared RSS action.
14483 * @param[out] error
14484 * Perform verbose error reporting if not NULL. Initialized in case of
14488 * 0 on success, otherwise negative errno value.
14491 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
14492 uint32_t action_idx,
14493 struct mlx5_shared_action_rss *shared_rss,
14494 struct rte_flow_error *error)
14496 struct mlx5_flow_rss_desc rss_desc = { 0 };
14500 if (mlx5_ind_table_obj_setup(dev, shared_rss->ind_tbl)) {
14501 return rte_flow_error_set(error, rte_errno,
14502 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14503 "cannot setup indirection table");
14505 memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
14506 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
14507 rss_desc.const_q = shared_rss->origin.queue;
14508 rss_desc.queue_num = shared_rss->origin.queue_num;
14509 /* Set non-zero value to indicate a shared RSS. */
14510 rss_desc.shared_rss = action_idx;
14511 rss_desc.ind_tbl = shared_rss->ind_tbl;
14512 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
14514 uint64_t hash_fields = mlx5_rss_hash_fields[i];
14517 __flow_dv_action_rss_l34_hash_adjust(shared_rss, &hash_fields);
14518 if (shared_rss->origin.level > 1) {
14519 hash_fields |= IBV_RX_HASH_INNER;
14522 rss_desc.tunnel = tunnel;
14523 rss_desc.hash_fields = hash_fields;
14524 hrxq_idx = mlx5_hrxq_get(dev, &rss_desc);
14528 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14529 "cannot get hash queue");
14530 goto error_hrxq_new;
14532 err = __flow_dv_action_rss_hrxq_set
14533 (shared_rss, hash_fields, hrxq_idx);
14539 __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14540 if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
14541 shared_rss->ind_tbl = NULL;
14547 * Create shared RSS action.
14550 * Pointer to the Ethernet device structure.
14552 * Shared action configuration.
14554 * RSS action specification used to create shared action.
14555 * @param[out] error
14556 * Perform verbose error reporting if not NULL. Initialized in case of
14560 * A valid shared action ID in case of success, 0 otherwise and
14561 * rte_errno is set.
14564 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
14565 const struct rte_flow_indir_action_conf *conf,
14566 const struct rte_flow_action_rss *rss,
14567 struct rte_flow_error *error)
14569 struct mlx5_priv *priv = dev->data->dev_private;
14570 struct mlx5_shared_action_rss *shared_rss = NULL;
14571 void *queue = NULL;
14572 struct rte_flow_action_rss *origin;
14573 const uint8_t *rss_key;
14574 uint32_t queue_size = rss->queue_num * sizeof(uint16_t);
14577 RTE_SET_USED(conf);
14578 queue = mlx5_malloc(0, RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14580 shared_rss = mlx5_ipool_zmalloc
14581 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
14582 if (!shared_rss || !queue) {
14583 rte_flow_error_set(error, ENOMEM,
14584 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14585 "cannot allocate resource memory");
14586 goto error_rss_init;
14588 if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
14589 rte_flow_error_set(error, E2BIG,
14590 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14591 "rss action number out of range");
14592 goto error_rss_init;
14594 shared_rss->ind_tbl = mlx5_malloc(MLX5_MEM_ZERO,
14595 sizeof(*shared_rss->ind_tbl),
14597 if (!shared_rss->ind_tbl) {
14598 rte_flow_error_set(error, ENOMEM,
14599 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14600 "cannot allocate resource memory");
14601 goto error_rss_init;
14603 memcpy(queue, rss->queue, queue_size);
14604 shared_rss->ind_tbl->queues = queue;
14605 shared_rss->ind_tbl->queues_n = rss->queue_num;
14606 origin = &shared_rss->origin;
14607 origin->func = rss->func;
14608 origin->level = rss->level;
14609 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
14610 origin->types = !rss->types ? ETH_RSS_IP : rss->types;
14611 /* NULL RSS key indicates default RSS key. */
14612 rss_key = !rss->key ? rss_hash_default_key : rss->key;
14613 memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
14614 origin->key = &shared_rss->key[0];
14615 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
14616 origin->queue = queue;
14617 origin->queue_num = rss->queue_num;
14618 if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
14619 goto error_rss_init;
14620 rte_spinlock_init(&shared_rss->action_rss_sl);
14621 __atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14622 rte_spinlock_lock(&priv->shared_act_sl);
14623 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14624 &priv->rss_shared_actions, idx, shared_rss, next);
14625 rte_spinlock_unlock(&priv->shared_act_sl);
14629 if (shared_rss->ind_tbl)
14630 mlx5_free(shared_rss->ind_tbl);
14631 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14640 * Destroy the shared RSS action.
14641 * Release related hash RX queue objects.
14644 * Pointer to the Ethernet device structure.
14646 * The shared RSS action object ID to be removed.
14647 * @param[out] error
14648 * Perform verbose error reporting if not NULL. Initialized in case of
14652 * 0 on success, otherwise negative errno value.
14655 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
14656 struct rte_flow_error *error)
14658 struct mlx5_priv *priv = dev->data->dev_private;
14659 struct mlx5_shared_action_rss *shared_rss =
14660 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14661 uint32_t old_refcnt = 1;
14663 uint16_t *queue = NULL;
14666 return rte_flow_error_set(error, EINVAL,
14667 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14668 "invalid shared action");
14669 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
14670 0, 0, __ATOMIC_ACQUIRE,
14672 return rte_flow_error_set(error, EBUSY,
14673 RTE_FLOW_ERROR_TYPE_ACTION,
14675 "shared rss has references");
14676 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14678 return rte_flow_error_set(error, EBUSY,
14679 RTE_FLOW_ERROR_TYPE_ACTION,
14681 "shared rss hrxq has references");
14682 queue = shared_rss->ind_tbl->queues;
14683 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true);
14685 return rte_flow_error_set(error, EBUSY,
14686 RTE_FLOW_ERROR_TYPE_ACTION,
14688 "shared rss indirection table has"
14691 rte_spinlock_lock(&priv->shared_act_sl);
14692 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14693 &priv->rss_shared_actions, idx, shared_rss, next);
14694 rte_spinlock_unlock(&priv->shared_act_sl);
14695 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14701 * Create indirect action, lock free,
14702 * (mutex should be acquired by caller).
14703 * Dispatcher for action type specific call.
14706 * Pointer to the Ethernet device structure.
14708 * Shared action configuration.
14709 * @param[in] action
14710 * Action specification used to create indirect action.
14711 * @param[out] error
14712 * Perform verbose error reporting if not NULL. Initialized in case of
14716 * A valid shared action handle in case of success, NULL otherwise and
14717 * rte_errno is set.
14719 static struct rte_flow_action_handle *
14720 flow_dv_action_create(struct rte_eth_dev *dev,
14721 const struct rte_flow_indir_action_conf *conf,
14722 const struct rte_flow_action *action,
14723 struct rte_flow_error *err)
14725 struct mlx5_priv *priv = dev->data->dev_private;
14726 uint32_t age_idx = 0;
14730 switch (action->type) {
14731 case RTE_FLOW_ACTION_TYPE_RSS:
14732 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
14733 idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
14734 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14736 case RTE_FLOW_ACTION_TYPE_AGE:
14737 age_idx = flow_dv_aso_age_alloc(dev, err);
14742 idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
14743 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
14744 flow_dv_aso_age_params_init(dev, age_idx,
14745 ((const struct rte_flow_action_age *)
14746 action->conf)->context ?
14747 ((const struct rte_flow_action_age *)
14748 action->conf)->context :
14749 (void *)(uintptr_t)idx,
14750 ((const struct rte_flow_action_age *)
14751 action->conf)->timeout);
14754 case RTE_FLOW_ACTION_TYPE_COUNT:
14755 ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
14756 idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
14757 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14759 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
14760 ret = flow_dv_translate_create_conntrack(dev, action->conf,
14762 idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
14765 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
14766 NULL, "action type not supported");
14769 return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
14773 * Destroy the indirect action.
14774 * Release action related resources on the NIC and the memory.
14775 * Lock free, (mutex should be acquired by caller).
14776 * Dispatcher for action type specific call.
14779 * Pointer to the Ethernet device structure.
14780 * @param[in] handle
14781 * The indirect action object handle to be removed.
14782 * @param[out] error
14783 * Perform verbose error reporting if not NULL. Initialized in case of
14787 * 0 on success, otherwise negative errno value.
14790 flow_dv_action_destroy(struct rte_eth_dev *dev,
14791 struct rte_flow_action_handle *handle,
14792 struct rte_flow_error *error)
14794 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14795 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14796 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
14797 struct mlx5_flow_counter *cnt;
14798 uint32_t no_flow_refcnt = 1;
14802 case MLX5_INDIRECT_ACTION_TYPE_RSS:
14803 return __flow_dv_action_rss_release(dev, idx, error);
14804 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
14805 cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
14806 if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
14807 &no_flow_refcnt, 1, false,
14810 return rte_flow_error_set(error, EBUSY,
14811 RTE_FLOW_ERROR_TYPE_ACTION,
14813 "Indirect count action has references");
14814 flow_dv_counter_free(dev, idx);
14816 case MLX5_INDIRECT_ACTION_TYPE_AGE:
14817 ret = flow_dv_aso_age_release(dev, idx);
14820 * In this case, the last flow has a reference will
14821 * actually release the age action.
14823 DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
14824 " released with references %d.", idx, ret);
14826 case MLX5_INDIRECT_ACTION_TYPE_CT:
14827 ret = flow_dv_aso_ct_release(dev, idx, error);
14831 DRV_LOG(DEBUG, "Connection tracking object %u still "
14832 "has references %d.", idx, ret);
14835 return rte_flow_error_set(error, ENOTSUP,
14836 RTE_FLOW_ERROR_TYPE_ACTION,
14838 "action type not supported");
14843 * Updates in place shared RSS action configuration.
14846 * Pointer to the Ethernet device structure.
14848 * The shared RSS action object ID to be updated.
14849 * @param[in] action_conf
14850 * RSS action specification used to modify *shared_rss*.
14851 * @param[out] error
14852 * Perform verbose error reporting if not NULL. Initialized in case of
14856 * 0 on success, otherwise negative errno value.
14857 * @note: currently only support update of RSS queues.
14860 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
14861 const struct rte_flow_action_rss *action_conf,
14862 struct rte_flow_error *error)
14864 struct mlx5_priv *priv = dev->data->dev_private;
14865 struct mlx5_shared_action_rss *shared_rss =
14866 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14868 void *queue = NULL;
14869 uint16_t *queue_old = NULL;
14870 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
14873 return rte_flow_error_set(error, EINVAL,
14874 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14875 "invalid shared action to update");
14876 if (priv->obj_ops.ind_table_modify == NULL)
14877 return rte_flow_error_set(error, ENOTSUP,
14878 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14879 "cannot modify indirection table");
14880 queue = mlx5_malloc(MLX5_MEM_ZERO,
14881 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14884 return rte_flow_error_set(error, ENOMEM,
14885 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14887 "cannot allocate resource memory");
14888 memcpy(queue, action_conf->queue, queue_size);
14889 MLX5_ASSERT(shared_rss->ind_tbl);
14890 rte_spinlock_lock(&shared_rss->action_rss_sl);
14891 queue_old = shared_rss->ind_tbl->queues;
14892 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
14893 queue, action_conf->queue_num, true);
14896 ret = rte_flow_error_set(error, rte_errno,
14897 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14898 "cannot update indirection table");
14900 mlx5_free(queue_old);
14901 shared_rss->origin.queue = queue;
14902 shared_rss->origin.queue_num = action_conf->queue_num;
14904 rte_spinlock_unlock(&shared_rss->action_rss_sl);
14909 * Updates in place conntrack context or direction.
14910 * Context update should be synchronized.
14913 * Pointer to the Ethernet device structure.
14915 * The conntrack object ID to be updated.
14916 * @param[in] update
14917 * Pointer to the structure of information to update.
14918 * @param[out] error
14919 * Perform verbose error reporting if not NULL. Initialized in case of
14923 * 0 on success, otherwise negative errno value.
14926 __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
14927 const struct rte_flow_modify_conntrack *update,
14928 struct rte_flow_error *error)
14930 struct mlx5_priv *priv = dev->data->dev_private;
14931 struct mlx5_aso_ct_action *ct;
14932 const struct rte_flow_action_conntrack *new_prf;
14934 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
14937 if (PORT_ID(priv) != owner)
14938 return rte_flow_error_set(error, EACCES,
14939 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14941 "CT object owned by another port");
14942 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
14943 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
14945 return rte_flow_error_set(error, ENOMEM,
14946 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14948 "CT object is inactive");
14949 new_prf = &update->new_ct;
14950 if (update->direction)
14951 ct->is_original = !!new_prf->is_original_dir;
14952 if (update->state) {
14953 /* Only validate the profile when it needs to be updated. */
14954 ret = mlx5_validate_action_ct(dev, new_prf, error);
14957 ret = mlx5_aso_ct_update_by_wqe(priv->sh, ct, new_prf);
14959 return rte_flow_error_set(error, EIO,
14960 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14962 "Failed to send CT context update WQE");
14963 /* Block until ready or a failure. */
14964 ret = mlx5_aso_ct_available(priv->sh, ct);
14966 rte_flow_error_set(error, rte_errno,
14967 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14969 "Timeout to get the CT update");
14975 * Updates in place shared action configuration, lock free,
14976 * (mutex should be acquired by caller).
14979 * Pointer to the Ethernet device structure.
14980 * @param[in] handle
14981 * The indirect action object handle to be updated.
14982 * @param[in] update
14983 * Action specification used to modify the action pointed by *handle*.
14984 * *update* could be of same type with the action pointed by the *handle*
14985 * handle argument, or some other structures like a wrapper, depending on
14986 * the indirect action type.
14987 * @param[out] error
14988 * Perform verbose error reporting if not NULL. Initialized in case of
14992 * 0 on success, otherwise negative errno value.
14995 flow_dv_action_update(struct rte_eth_dev *dev,
14996 struct rte_flow_action_handle *handle,
14997 const void *update,
14998 struct rte_flow_error *err)
15000 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15001 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15002 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15003 const void *action_conf;
15006 case MLX5_INDIRECT_ACTION_TYPE_RSS:
15007 action_conf = ((const struct rte_flow_action *)update)->conf;
15008 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
15009 case MLX5_INDIRECT_ACTION_TYPE_CT:
15010 return __flow_dv_action_ct_update(dev, idx, update, err);
15012 return rte_flow_error_set(err, ENOTSUP,
15013 RTE_FLOW_ERROR_TYPE_ACTION,
15015 "action type update not supported");
15020 * Destroy the meter sub policy table rules.
15021 * Lock free, (mutex should be acquired by caller).
15024 * Pointer to Ethernet device.
15025 * @param[in] sub_policy
15026 * Pointer to meter sub policy table.
15029 __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
15030 struct mlx5_flow_meter_sub_policy *sub_policy)
15032 struct mlx5_priv *priv = dev->data->dev_private;
15033 struct mlx5_flow_tbl_data_entry *tbl;
15034 struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
15035 struct mlx5_flow_meter_info *next_fm;
15036 struct mlx5_sub_policy_color_rule *color_rule;
15040 for (i = 0; i < RTE_COLORS; i++) {
15042 if (i == RTE_COLOR_GREEN && policy &&
15043 policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
15044 next_fm = mlx5_flow_meter_find(priv,
15045 policy->act_cnt[i].next_mtr_id, NULL);
15046 RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
15048 claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
15049 tbl = container_of(color_rule->matcher->tbl,
15050 typeof(*tbl), tbl);
15051 mlx5_list_unregister(tbl->matchers,
15052 &color_rule->matcher->entry);
15053 TAILQ_REMOVE(&sub_policy->color_rules[i],
15054 color_rule, next_port);
15055 mlx5_free(color_rule);
15057 mlx5_flow_meter_detach(priv, next_fm);
15060 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15061 if (sub_policy->rix_hrxq[i]) {
15062 if (policy && !policy->is_hierarchy)
15063 mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
15064 sub_policy->rix_hrxq[i] = 0;
15066 if (sub_policy->jump_tbl[i]) {
15067 flow_dv_tbl_resource_release(MLX5_SH(dev),
15068 sub_policy->jump_tbl[i]);
15069 sub_policy->jump_tbl[i] = NULL;
15072 if (sub_policy->tbl_rsc) {
15073 flow_dv_tbl_resource_release(MLX5_SH(dev),
15074 sub_policy->tbl_rsc);
15075 sub_policy->tbl_rsc = NULL;
15080 * Destroy policy rules, lock free,
15081 * (mutex should be acquired by caller).
15082 * Dispatcher for action type specific call.
15085 * Pointer to the Ethernet device structure.
15086 * @param[in] mtr_policy
15087 * Meter policy struct.
15090 flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
15091 struct mlx5_flow_meter_policy *mtr_policy)
15094 struct mlx5_flow_meter_sub_policy *sub_policy;
15095 uint16_t sub_policy_num;
15097 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15098 sub_policy_num = (mtr_policy->sub_policy_num >>
15099 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15100 MLX5_MTR_SUB_POLICY_NUM_MASK;
15101 for (j = 0; j < sub_policy_num; j++) {
15102 sub_policy = mtr_policy->sub_policys[i][j];
15104 __flow_dv_destroy_sub_policy_rules(dev,
15111 * Destroy policy action, lock free,
15112 * (mutex should be acquired by caller).
15113 * Dispatcher for action type specific call.
15116 * Pointer to the Ethernet device structure.
15117 * @param[in] mtr_policy
15118 * Meter policy struct.
15121 flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
15122 struct mlx5_flow_meter_policy *mtr_policy)
15124 struct rte_flow_action *rss_action;
15125 struct mlx5_flow_handle dev_handle;
15128 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15129 if (mtr_policy->act_cnt[i].rix_mark) {
15130 flow_dv_tag_release(dev,
15131 mtr_policy->act_cnt[i].rix_mark);
15132 mtr_policy->act_cnt[i].rix_mark = 0;
15134 if (mtr_policy->act_cnt[i].modify_hdr) {
15135 dev_handle.dvh.modify_hdr =
15136 mtr_policy->act_cnt[i].modify_hdr;
15137 flow_dv_modify_hdr_resource_release(dev, &dev_handle);
15139 switch (mtr_policy->act_cnt[i].fate_action) {
15140 case MLX5_FLOW_FATE_SHARED_RSS:
15141 rss_action = mtr_policy->act_cnt[i].rss;
15142 mlx5_free(rss_action);
15144 case MLX5_FLOW_FATE_PORT_ID:
15145 if (mtr_policy->act_cnt[i].rix_port_id_action) {
15146 flow_dv_port_id_action_resource_release(dev,
15147 mtr_policy->act_cnt[i].rix_port_id_action);
15148 mtr_policy->act_cnt[i].rix_port_id_action = 0;
15151 case MLX5_FLOW_FATE_DROP:
15152 case MLX5_FLOW_FATE_JUMP:
15153 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15154 mtr_policy->act_cnt[i].dr_jump_action[j] =
15158 /*Queue action do nothing*/
15162 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
15163 mtr_policy->dr_drop_action[j] = NULL;
15167 * Create policy action per domain, lock free,
15168 * (mutex should be acquired by caller).
15169 * Dispatcher for action type specific call.
15172 * Pointer to the Ethernet device structure.
15173 * @param[in] mtr_policy
15174 * Meter policy struct.
15175 * @param[in] action
15176 * Action specification used to create meter actions.
15177 * @param[out] error
15178 * Perform verbose error reporting if not NULL. Initialized in case of
15182 * 0 on success, otherwise negative errno value.
15185 __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
15186 struct mlx5_flow_meter_policy *mtr_policy,
15187 const struct rte_flow_action *actions[RTE_COLORS],
15188 enum mlx5_meter_domain domain,
15189 struct rte_mtr_error *error)
15191 struct mlx5_priv *priv = dev->data->dev_private;
15192 struct rte_flow_error flow_err;
15193 const struct rte_flow_action *act;
15194 uint64_t action_flags;
15195 struct mlx5_flow_handle dh;
15196 struct mlx5_flow dev_flow;
15197 struct mlx5_flow_dv_port_id_action_resource port_id_action;
15199 uint8_t egress, transfer;
15200 struct mlx5_meter_policy_action_container *act_cnt = NULL;
15202 struct mlx5_flow_dv_modify_hdr_resource res;
15203 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
15204 sizeof(struct mlx5_modification_cmd) *
15205 (MLX5_MAX_MODIFY_NUM + 1)];
15207 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
15209 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15210 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15211 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
15212 memset(&dev_flow, 0, sizeof(struct mlx5_flow));
15213 memset(&port_id_action, 0,
15214 sizeof(struct mlx5_flow_dv_port_id_action_resource));
15215 memset(mhdr_res, 0, sizeof(*mhdr_res));
15216 mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
15217 (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15218 MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
15219 dev_flow.handle = &dh;
15220 dev_flow.dv.port_id_action = &port_id_action;
15221 dev_flow.external = true;
15222 for (i = 0; i < RTE_COLORS; i++) {
15223 if (i < MLX5_MTR_RTE_COLORS)
15224 act_cnt = &mtr_policy->act_cnt[i];
15225 /* Skip the color policy actions creation. */
15226 if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
15227 (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
15230 for (act = actions[i];
15231 act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
15232 switch (act->type) {
15233 case RTE_FLOW_ACTION_TYPE_MARK:
15235 uint32_t tag_be = mlx5_flow_mark_set
15236 (((const struct rte_flow_action_mark *)
15239 if (i >= MLX5_MTR_RTE_COLORS)
15240 return -rte_mtr_error_set(error,
15242 RTE_MTR_ERROR_TYPE_METER_POLICY,
15244 "cannot create policy "
15245 "mark action for this color");
15246 dev_flow.handle->mark = 1;
15247 if (flow_dv_tag_resource_register(dev, tag_be,
15248 &dev_flow, &flow_err))
15249 return -rte_mtr_error_set(error,
15251 RTE_MTR_ERROR_TYPE_METER_POLICY,
15253 "cannot setup policy mark action");
15254 MLX5_ASSERT(dev_flow.dv.tag_resource);
15255 act_cnt->rix_mark =
15256 dev_flow.handle->dvh.rix_tag;
15257 action_flags |= MLX5_FLOW_ACTION_MARK;
15260 case RTE_FLOW_ACTION_TYPE_SET_TAG:
15261 if (i >= MLX5_MTR_RTE_COLORS)
15262 return -rte_mtr_error_set(error,
15264 RTE_MTR_ERROR_TYPE_METER_POLICY,
15266 "cannot create policy "
15267 "set tag action for this color");
15268 if (flow_dv_convert_action_set_tag
15270 (const struct rte_flow_action_set_tag *)
15271 act->conf, &flow_err))
15272 return -rte_mtr_error_set(error,
15274 RTE_MTR_ERROR_TYPE_METER_POLICY,
15275 NULL, "cannot convert policy "
15277 if (!mhdr_res->actions_num)
15278 return -rte_mtr_error_set(error,
15280 RTE_MTR_ERROR_TYPE_METER_POLICY,
15281 NULL, "cannot find policy "
15283 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15285 case RTE_FLOW_ACTION_TYPE_DROP:
15287 struct mlx5_flow_mtr_mng *mtrmng =
15289 struct mlx5_flow_tbl_data_entry *tbl_data;
15292 * Create the drop table with
15293 * METER DROP level.
15295 if (!mtrmng->drop_tbl[domain]) {
15296 mtrmng->drop_tbl[domain] =
15297 flow_dv_tbl_resource_get(dev,
15298 MLX5_FLOW_TABLE_LEVEL_METER,
15299 egress, transfer, false, NULL, 0,
15300 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
15301 if (!mtrmng->drop_tbl[domain])
15302 return -rte_mtr_error_set
15304 RTE_MTR_ERROR_TYPE_METER_POLICY,
15306 "Failed to create meter drop table");
15308 tbl_data = container_of
15309 (mtrmng->drop_tbl[domain],
15310 struct mlx5_flow_tbl_data_entry, tbl);
15311 if (i < MLX5_MTR_RTE_COLORS) {
15312 act_cnt->dr_jump_action[domain] =
15313 tbl_data->jump.action;
15314 act_cnt->fate_action =
15315 MLX5_FLOW_FATE_DROP;
15317 if (i == RTE_COLOR_RED)
15318 mtr_policy->dr_drop_action[domain] =
15319 tbl_data->jump.action;
15320 action_flags |= MLX5_FLOW_ACTION_DROP;
15323 case RTE_FLOW_ACTION_TYPE_QUEUE:
15325 if (i >= MLX5_MTR_RTE_COLORS)
15326 return -rte_mtr_error_set(error,
15328 RTE_MTR_ERROR_TYPE_METER_POLICY,
15329 NULL, "cannot create policy "
15330 "fate queue for this color");
15332 ((const struct rte_flow_action_queue *)
15333 (act->conf))->index;
15334 act_cnt->fate_action =
15335 MLX5_FLOW_FATE_QUEUE;
15336 dev_flow.handle->fate_action =
15337 MLX5_FLOW_FATE_QUEUE;
15338 mtr_policy->is_queue = 1;
15339 action_flags |= MLX5_FLOW_ACTION_QUEUE;
15342 case RTE_FLOW_ACTION_TYPE_RSS:
15346 if (i >= MLX5_MTR_RTE_COLORS)
15347 return -rte_mtr_error_set(error,
15349 RTE_MTR_ERROR_TYPE_METER_POLICY,
15351 "cannot create policy "
15352 "rss action for this color");
15354 * Save RSS conf into policy struct
15355 * for translate stage.
15357 rss_size = (int)rte_flow_conv
15358 (RTE_FLOW_CONV_OP_ACTION,
15359 NULL, 0, act, &flow_err);
15361 return -rte_mtr_error_set(error,
15363 RTE_MTR_ERROR_TYPE_METER_POLICY,
15364 NULL, "Get the wrong "
15365 "rss action struct size");
15366 act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
15367 rss_size, 0, SOCKET_ID_ANY);
15369 return -rte_mtr_error_set(error,
15371 RTE_MTR_ERROR_TYPE_METER_POLICY,
15373 "Fail to malloc rss action memory");
15374 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
15375 act_cnt->rss, rss_size,
15378 return -rte_mtr_error_set(error,
15380 RTE_MTR_ERROR_TYPE_METER_POLICY,
15381 NULL, "Fail to save "
15382 "rss action into policy struct");
15383 act_cnt->fate_action =
15384 MLX5_FLOW_FATE_SHARED_RSS;
15385 action_flags |= MLX5_FLOW_ACTION_RSS;
15388 case RTE_FLOW_ACTION_TYPE_PORT_ID:
15389 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15391 struct mlx5_flow_dv_port_id_action_resource
15393 uint32_t port_id = 0;
15395 if (i >= MLX5_MTR_RTE_COLORS)
15396 return -rte_mtr_error_set(error,
15398 RTE_MTR_ERROR_TYPE_METER_POLICY,
15399 NULL, "cannot create policy "
15400 "port action for this color");
15401 memset(&port_id_resource, 0,
15402 sizeof(port_id_resource));
15403 if (flow_dv_translate_action_port_id(dev, act,
15404 &port_id, &flow_err))
15405 return -rte_mtr_error_set(error,
15407 RTE_MTR_ERROR_TYPE_METER_POLICY,
15408 NULL, "cannot translate "
15409 "policy port action");
15410 port_id_resource.port_id = port_id;
15411 if (flow_dv_port_id_action_resource_register
15412 (dev, &port_id_resource,
15413 &dev_flow, &flow_err))
15414 return -rte_mtr_error_set(error,
15416 RTE_MTR_ERROR_TYPE_METER_POLICY,
15417 NULL, "cannot setup "
15418 "policy port action");
15419 act_cnt->rix_port_id_action =
15420 dev_flow.handle->rix_port_id_action;
15421 act_cnt->fate_action =
15422 MLX5_FLOW_FATE_PORT_ID;
15423 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15426 case RTE_FLOW_ACTION_TYPE_JUMP:
15428 uint32_t jump_group = 0;
15429 uint32_t table = 0;
15430 struct mlx5_flow_tbl_data_entry *tbl_data;
15431 struct flow_grp_info grp_info = {
15432 .external = !!dev_flow.external,
15433 .transfer = !!transfer,
15434 .fdb_def_rule = !!priv->fdb_def_rule,
15436 .skip_scale = dev_flow.skip_scale &
15437 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
15439 struct mlx5_flow_meter_sub_policy *sub_policy =
15440 mtr_policy->sub_policys[domain][0];
15442 if (i >= MLX5_MTR_RTE_COLORS)
15443 return -rte_mtr_error_set(error,
15445 RTE_MTR_ERROR_TYPE_METER_POLICY,
15447 "cannot create policy "
15448 "jump action for this color");
15450 ((const struct rte_flow_action_jump *)
15452 if (mlx5_flow_group_to_table(dev, NULL,
15455 &grp_info, &flow_err))
15456 return -rte_mtr_error_set(error,
15458 RTE_MTR_ERROR_TYPE_METER_POLICY,
15459 NULL, "cannot setup "
15460 "policy jump action");
15461 sub_policy->jump_tbl[i] =
15462 flow_dv_tbl_resource_get(dev,
15465 !!dev_flow.external,
15466 NULL, jump_group, 0,
15469 (!sub_policy->jump_tbl[i])
15470 return -rte_mtr_error_set(error,
15472 RTE_MTR_ERROR_TYPE_METER_POLICY,
15473 NULL, "cannot create jump action.");
15474 tbl_data = container_of
15475 (sub_policy->jump_tbl[i],
15476 struct mlx5_flow_tbl_data_entry, tbl);
15477 act_cnt->dr_jump_action[domain] =
15478 tbl_data->jump.action;
15479 act_cnt->fate_action =
15480 MLX5_FLOW_FATE_JUMP;
15481 action_flags |= MLX5_FLOW_ACTION_JUMP;
15485 * No need to check meter hierarchy for Y or R colors
15486 * here since it is done in the validation stage.
15488 case RTE_FLOW_ACTION_TYPE_METER:
15490 const struct rte_flow_action_meter *mtr;
15491 struct mlx5_flow_meter_info *next_fm;
15492 struct mlx5_flow_meter_policy *next_policy;
15493 struct rte_flow_action tag_action;
15494 struct mlx5_rte_flow_action_set_tag set_tag;
15495 uint32_t next_mtr_idx = 0;
15498 next_fm = mlx5_flow_meter_find(priv,
15502 return -rte_mtr_error_set(error, EINVAL,
15503 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15504 "Fail to find next meter.");
15505 if (next_fm->def_policy)
15506 return -rte_mtr_error_set(error, EINVAL,
15507 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15508 "Hierarchy only supports termination meter.");
15509 next_policy = mlx5_flow_meter_policy_find(dev,
15510 next_fm->policy_id, NULL);
15511 MLX5_ASSERT(next_policy);
15512 if (next_fm->drop_cnt) {
15515 mlx5_flow_get_reg_id(dev,
15518 (struct rte_flow_error *)error);
15519 set_tag.offset = (priv->mtr_reg_share ?
15520 MLX5_MTR_COLOR_BITS : 0);
15521 set_tag.length = (priv->mtr_reg_share ?
15522 MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
15524 set_tag.data = next_mtr_idx;
15526 (enum rte_flow_action_type)
15527 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
15528 tag_action.conf = &set_tag;
15529 if (flow_dv_convert_action_set_reg
15530 (mhdr_res, &tag_action,
15531 (struct rte_flow_error *)error))
15534 MLX5_FLOW_ACTION_SET_TAG;
15536 act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
15537 act_cnt->next_mtr_id = next_fm->meter_id;
15538 act_cnt->next_sub_policy = NULL;
15539 mtr_policy->is_hierarchy = 1;
15540 mtr_policy->dev = next_policy->dev;
15542 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
15546 return -rte_mtr_error_set(error, ENOTSUP,
15547 RTE_MTR_ERROR_TYPE_METER_POLICY,
15548 NULL, "action type not supported");
15550 if (action_flags & MLX5_FLOW_ACTION_SET_TAG) {
15551 /* create modify action if needed. */
15552 dev_flow.dv.group = 1;
15553 if (flow_dv_modify_hdr_resource_register
15554 (dev, mhdr_res, &dev_flow, &flow_err))
15555 return -rte_mtr_error_set(error,
15557 RTE_MTR_ERROR_TYPE_METER_POLICY,
15558 NULL, "cannot register policy "
15560 act_cnt->modify_hdr =
15561 dev_flow.handle->dvh.modify_hdr;
15569 * Create policy action per domain, lock free,
15570 * (mutex should be acquired by caller).
15571 * Dispatcher for action type specific call.
15574 * Pointer to the Ethernet device structure.
15575 * @param[in] mtr_policy
15576 * Meter policy struct.
15577 * @param[in] action
15578 * Action specification used to create meter actions.
15579 * @param[out] error
15580 * Perform verbose error reporting if not NULL. Initialized in case of
15584 * 0 on success, otherwise negative errno value.
15587 flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
15588 struct mlx5_flow_meter_policy *mtr_policy,
15589 const struct rte_flow_action *actions[RTE_COLORS],
15590 struct rte_mtr_error *error)
15593 uint16_t sub_policy_num;
15595 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15596 sub_policy_num = (mtr_policy->sub_policy_num >>
15597 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15598 MLX5_MTR_SUB_POLICY_NUM_MASK;
15599 if (sub_policy_num) {
15600 ret = __flow_dv_create_domain_policy_acts(dev,
15601 mtr_policy, actions,
15602 (enum mlx5_meter_domain)i, error);
15603 /* Cleaning resource is done in the caller level. */
15612 * Query a DV flow rule for its statistics via DevX.
15615 * Pointer to Ethernet device.
15616 * @param[in] cnt_idx
15617 * Index to the flow counter.
15619 * Data retrieved by the query.
15620 * @param[out] error
15621 * Perform verbose error reporting if not NULL.
15624 * 0 on success, a negative errno value otherwise and rte_errno is set.
15627 flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
15628 struct rte_flow_error *error)
15630 struct mlx5_priv *priv = dev->data->dev_private;
15631 struct rte_flow_query_count *qc = data;
15633 if (!priv->sh->devx)
15634 return rte_flow_error_set(error, ENOTSUP,
15635 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15637 "counters are not supported");
15639 uint64_t pkts, bytes;
15640 struct mlx5_flow_counter *cnt;
15641 int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
15644 return rte_flow_error_set(error, -err,
15645 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15646 NULL, "cannot read counters");
15647 cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
15650 qc->hits = pkts - cnt->hits;
15651 qc->bytes = bytes - cnt->bytes;
15654 cnt->bytes = bytes;
15658 return rte_flow_error_set(error, EINVAL,
15659 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15661 "counters are not available");
15665 flow_dv_action_query(struct rte_eth_dev *dev,
15666 const struct rte_flow_action_handle *handle, void *data,
15667 struct rte_flow_error *error)
15669 struct mlx5_age_param *age_param;
15670 struct rte_flow_query_age *resp;
15671 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15672 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15673 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15674 struct mlx5_priv *priv = dev->data->dev_private;
15675 struct mlx5_aso_ct_action *ct;
15680 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15681 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
15683 resp->aged = __atomic_load_n(&age_param->state,
15684 __ATOMIC_RELAXED) == AGE_TMOUT ?
15686 resp->sec_since_last_hit_valid = !resp->aged;
15687 if (resp->sec_since_last_hit_valid)
15688 resp->sec_since_last_hit = __atomic_load_n
15689 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15691 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15692 return flow_dv_query_count(dev, idx, data, error);
15693 case MLX5_INDIRECT_ACTION_TYPE_CT:
15694 owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
15695 if (owner != PORT_ID(priv))
15696 return rte_flow_error_set(error, EACCES,
15697 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15699 "CT object owned by another port");
15700 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
15701 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
15704 return rte_flow_error_set(error, EFAULT,
15705 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15707 "CT object is inactive");
15708 ((struct rte_flow_action_conntrack *)data)->peer_port =
15710 ((struct rte_flow_action_conntrack *)data)->is_original_dir =
15712 if (mlx5_aso_ct_query_by_wqe(priv->sh, ct, data))
15713 return rte_flow_error_set(error, EIO,
15714 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15716 "Failed to query CT context");
15719 return rte_flow_error_set(error, ENOTSUP,
15720 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15721 "action type query not supported");
15726 * Query a flow rule AGE action for aging information.
15729 * Pointer to Ethernet device.
15731 * Pointer to the sub flow.
15733 * data retrieved by the query.
15734 * @param[out] error
15735 * Perform verbose error reporting if not NULL.
15738 * 0 on success, a negative errno value otherwise and rte_errno is set.
15741 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
15742 void *data, struct rte_flow_error *error)
15744 struct rte_flow_query_age *resp = data;
15745 struct mlx5_age_param *age_param;
15748 struct mlx5_aso_age_action *act =
15749 flow_aso_age_get_by_idx(dev, flow->age);
15751 age_param = &act->age_params;
15752 } else if (flow->counter) {
15753 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
15755 if (!age_param || !age_param->timeout)
15756 return rte_flow_error_set
15758 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15759 NULL, "cannot read age data");
15761 return rte_flow_error_set(error, EINVAL,
15762 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15763 NULL, "age data not available");
15765 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
15767 resp->sec_since_last_hit_valid = !resp->aged;
15768 if (resp->sec_since_last_hit_valid)
15769 resp->sec_since_last_hit = __atomic_load_n
15770 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15777 * @see rte_flow_query()
15778 * @see rte_flow_ops
15781 flow_dv_query(struct rte_eth_dev *dev,
15782 struct rte_flow *flow __rte_unused,
15783 const struct rte_flow_action *actions __rte_unused,
15784 void *data __rte_unused,
15785 struct rte_flow_error *error __rte_unused)
15789 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
15790 switch (actions->type) {
15791 case RTE_FLOW_ACTION_TYPE_VOID:
15793 case RTE_FLOW_ACTION_TYPE_COUNT:
15794 ret = flow_dv_query_count(dev, flow->counter, data,
15797 case RTE_FLOW_ACTION_TYPE_AGE:
15798 ret = flow_dv_query_age(dev, flow, data, error);
15801 return rte_flow_error_set(error, ENOTSUP,
15802 RTE_FLOW_ERROR_TYPE_ACTION,
15804 "action not supported");
15811 * Destroy the meter table set.
15812 * Lock free, (mutex should be acquired by caller).
15815 * Pointer to Ethernet device.
15817 * Meter information table.
15820 flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
15821 struct mlx5_flow_meter_info *fm)
15823 struct mlx5_priv *priv = dev->data->dev_private;
15826 if (!fm || !priv->config.dv_flow_en)
15828 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15829 if (fm->drop_rule[i]) {
15830 claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
15831 fm->drop_rule[i] = NULL;
15837 flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
15839 struct mlx5_priv *priv = dev->data->dev_private;
15840 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15841 struct mlx5_flow_tbl_data_entry *tbl;
15844 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15845 if (mtrmng->def_rule[i]) {
15846 claim_zero(mlx5_flow_os_destroy_flow
15847 (mtrmng->def_rule[i]));
15848 mtrmng->def_rule[i] = NULL;
15850 if (mtrmng->def_matcher[i]) {
15851 tbl = container_of(mtrmng->def_matcher[i]->tbl,
15852 struct mlx5_flow_tbl_data_entry, tbl);
15853 mlx5_list_unregister(tbl->matchers,
15854 &mtrmng->def_matcher[i]->entry);
15855 mtrmng->def_matcher[i] = NULL;
15857 for (j = 0; j < MLX5_REG_BITS; j++) {
15858 if (mtrmng->drop_matcher[i][j]) {
15860 container_of(mtrmng->drop_matcher[i][j]->tbl,
15861 struct mlx5_flow_tbl_data_entry,
15863 mlx5_list_unregister(tbl->matchers,
15864 &mtrmng->drop_matcher[i][j]->entry);
15865 mtrmng->drop_matcher[i][j] = NULL;
15868 if (mtrmng->drop_tbl[i]) {
15869 flow_dv_tbl_resource_release(MLX5_SH(dev),
15870 mtrmng->drop_tbl[i]);
15871 mtrmng->drop_tbl[i] = NULL;
15876 /* Number of meter flow actions, count and jump or count and drop. */
15877 #define METER_ACTIONS 2
15880 __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
15881 enum mlx5_meter_domain domain)
15883 struct mlx5_priv *priv = dev->data->dev_private;
15884 struct mlx5_flow_meter_def_policy *def_policy =
15885 priv->sh->mtrmng->def_policy[domain];
15887 __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
15888 mlx5_free(def_policy);
15889 priv->sh->mtrmng->def_policy[domain] = NULL;
15893 * Destroy the default policy table set.
15896 * Pointer to Ethernet device.
15899 flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
15901 struct mlx5_priv *priv = dev->data->dev_private;
15904 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
15905 if (priv->sh->mtrmng->def_policy[i])
15906 __flow_dv_destroy_domain_def_policy(dev,
15907 (enum mlx5_meter_domain)i);
15908 priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
15912 __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
15913 uint32_t color_reg_c_idx,
15914 enum rte_color color, void *matcher_object,
15915 int actions_n, void *actions,
15916 bool match_src_port, const struct rte_flow_item *item,
15917 void **rule, const struct rte_flow_attr *attr)
15920 struct mlx5_flow_dv_match_params value = {
15921 .size = sizeof(value.buf),
15923 struct mlx5_flow_dv_match_params matcher = {
15924 .size = sizeof(matcher.buf),
15926 struct mlx5_priv *priv = dev->data->dev_private;
15929 if (match_src_port && (priv->representor || priv->master)) {
15930 if (flow_dv_translate_item_port_id(dev, matcher.buf,
15931 value.buf, item, attr)) {
15932 DRV_LOG(ERR, "Failed to create meter policy%d flow's"
15933 " value with port.", color);
15937 flow_dv_match_meta_reg(matcher.buf, value.buf,
15938 (enum modify_reg)color_reg_c_idx,
15939 rte_col_2_mlx5_col(color), UINT32_MAX);
15940 misc_mask = flow_dv_matcher_enable(value.buf);
15941 __flow_dv_adjust_buf_size(&value.size, misc_mask);
15942 ret = mlx5_flow_os_create_flow(matcher_object, (void *)&value,
15943 actions_n, actions, rule);
15945 DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
15952 __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
15953 uint32_t color_reg_c_idx,
15955 struct mlx5_flow_meter_sub_policy *sub_policy,
15956 const struct rte_flow_attr *attr,
15957 bool match_src_port,
15958 const struct rte_flow_item *item,
15959 struct mlx5_flow_dv_matcher **policy_matcher,
15960 struct rte_flow_error *error)
15962 struct mlx5_list_entry *entry;
15963 struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
15964 struct mlx5_flow_dv_matcher matcher = {
15966 .size = sizeof(matcher.mask.buf),
15970 struct mlx5_flow_dv_match_params value = {
15971 .size = sizeof(value.buf),
15973 struct mlx5_flow_cb_ctx ctx = {
15977 struct mlx5_flow_tbl_data_entry *tbl_data;
15978 struct mlx5_priv *priv = dev->data->dev_private;
15979 const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
15981 if (match_src_port && (priv->representor || priv->master)) {
15982 if (flow_dv_translate_item_port_id(dev, matcher.mask.buf,
15983 value.buf, item, attr)) {
15984 DRV_LOG(ERR, "Failed to register meter policy%d matcher"
15985 " with port.", priority);
15989 tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
15990 if (priority < RTE_COLOR_RED)
15991 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
15992 (enum modify_reg)color_reg_c_idx, 0, color_mask);
15993 matcher.priority = priority;
15994 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15995 matcher.mask.size);
15996 entry = mlx5_list_register(tbl_data->matchers, &ctx);
15998 DRV_LOG(ERR, "Failed to register meter drop matcher.");
16002 container_of(entry, struct mlx5_flow_dv_matcher, entry);
16007 * Create the policy rules per domain.
16010 * Pointer to Ethernet device.
16011 * @param[in] sub_policy
16012 * Pointer to sub policy table..
16013 * @param[in] egress
16014 * Direction of the table.
16015 * @param[in] transfer
16016 * E-Switch or NIC flow.
16018 * Pointer to policy action list per color.
16021 * 0 on success, -1 otherwise.
16024 __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
16025 struct mlx5_flow_meter_sub_policy *sub_policy,
16026 uint8_t egress, uint8_t transfer, bool match_src_port,
16027 struct mlx5_meter_policy_acts acts[RTE_COLORS])
16029 struct mlx5_priv *priv = dev->data->dev_private;
16030 struct rte_flow_error flow_err;
16031 uint32_t color_reg_c_idx;
16032 struct rte_flow_attr attr = {
16033 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
16036 .egress = !!egress,
16037 .transfer = !!transfer,
16041 int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
16042 struct mlx5_sub_policy_color_rule *color_rule;
16044 struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
16048 /* Create policy table with POLICY level. */
16049 if (!sub_policy->tbl_rsc)
16050 sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
16051 MLX5_FLOW_TABLE_LEVEL_POLICY,
16052 egress, transfer, false, NULL, 0, 0,
16053 sub_policy->idx, &flow_err);
16054 if (!sub_policy->tbl_rsc) {
16056 "Failed to create meter sub policy table.");
16059 /* Prepare matchers. */
16060 color_reg_c_idx = ret;
16061 for (i = 0; i < RTE_COLORS; i++) {
16062 TAILQ_INIT(&sub_policy->color_rules[i]);
16063 if (!acts[i].actions_n)
16065 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
16066 sizeof(struct mlx5_sub_policy_color_rule),
16069 DRV_LOG(ERR, "No memory to create color rule.");
16072 tmp_rules[i] = color_rule;
16073 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
16074 color_rule, next_port);
16075 color_rule->src_port = priv->representor_id;
16078 /* Create matchers for colors. */
16079 svport_match = (i != RTE_COLOR_RED) ? match_src_port : false;
16080 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
16081 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
16082 &attr, svport_match, NULL,
16083 &color_rule->matcher, &flow_err)) {
16084 DRV_LOG(ERR, "Failed to create color%u matcher.", i);
16087 /* Create flow, matching color. */
16088 if (__flow_dv_create_policy_flow(dev,
16089 color_reg_c_idx, (enum rte_color)i,
16090 color_rule->matcher->matcher_object,
16091 acts[i].actions_n, acts[i].dv_actions,
16092 svport_match, NULL, &color_rule->rule,
16094 DRV_LOG(ERR, "Failed to create color%u rule.", i);
16100 /* All the policy rules will be cleared. */
16102 color_rule = tmp_rules[i];
16104 if (color_rule->rule)
16105 mlx5_flow_os_destroy_flow(color_rule->rule);
16106 if (color_rule->matcher) {
16107 struct mlx5_flow_tbl_data_entry *tbl =
16108 container_of(color_rule->matcher->tbl,
16109 typeof(*tbl), tbl);
16110 mlx5_list_unregister(tbl->matchers,
16111 &color_rule->matcher->entry);
16113 TAILQ_REMOVE(&sub_policy->color_rules[i],
16114 color_rule, next_port);
16115 mlx5_free(color_rule);
16122 __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
16123 struct mlx5_flow_meter_policy *mtr_policy,
16124 struct mlx5_flow_meter_sub_policy *sub_policy,
16127 struct mlx5_priv *priv = dev->data->dev_private;
16128 struct mlx5_meter_policy_acts acts[RTE_COLORS];
16129 struct mlx5_flow_dv_tag_resource *tag;
16130 struct mlx5_flow_dv_port_id_action_resource *port_action;
16131 struct mlx5_hrxq *hrxq;
16132 struct mlx5_flow_meter_info *next_fm = NULL;
16133 struct mlx5_flow_meter_policy *next_policy;
16134 struct mlx5_flow_meter_sub_policy *next_sub_policy;
16135 struct mlx5_flow_tbl_data_entry *tbl_data;
16136 struct rte_flow_error error;
16137 uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16138 uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16139 bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
16140 bool match_src_port = false;
16143 /* If RSS or Queue, no previous actions / rules is created. */
16144 for (i = 0; i < RTE_COLORS; i++) {
16145 acts[i].actions_n = 0;
16146 if (i == RTE_COLOR_RED) {
16147 /* Only support drop on red. */
16148 acts[i].dv_actions[0] =
16149 mtr_policy->dr_drop_action[domain];
16150 acts[i].actions_n = 1;
16153 if (i == RTE_COLOR_GREEN &&
16154 mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
16155 struct rte_flow_attr attr = {
16156 .transfer = transfer
16159 next_fm = mlx5_flow_meter_find(priv,
16160 mtr_policy->act_cnt[i].next_mtr_id,
16164 "Failed to get next hierarchy meter.");
16167 if (mlx5_flow_meter_attach(priv, next_fm,
16169 DRV_LOG(ERR, "%s", error.message);
16173 /* Meter action must be the first for TX. */
16175 acts[i].dv_actions[acts[i].actions_n] =
16176 next_fm->meter_action;
16177 acts[i].actions_n++;
16180 if (mtr_policy->act_cnt[i].rix_mark) {
16181 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
16182 mtr_policy->act_cnt[i].rix_mark);
16184 DRV_LOG(ERR, "Failed to find "
16185 "mark action for policy.");
16188 acts[i].dv_actions[acts[i].actions_n] = tag->action;
16189 acts[i].actions_n++;
16191 if (mtr_policy->act_cnt[i].modify_hdr) {
16192 acts[i].dv_actions[acts[i].actions_n] =
16193 mtr_policy->act_cnt[i].modify_hdr->action;
16194 acts[i].actions_n++;
16196 if (mtr_policy->act_cnt[i].fate_action) {
16197 switch (mtr_policy->act_cnt[i].fate_action) {
16198 case MLX5_FLOW_FATE_PORT_ID:
16199 port_action = mlx5_ipool_get
16200 (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
16201 mtr_policy->act_cnt[i].rix_port_id_action);
16202 if (!port_action) {
16203 DRV_LOG(ERR, "Failed to find "
16204 "port action for policy.");
16207 acts[i].dv_actions[acts[i].actions_n] =
16208 port_action->action;
16209 acts[i].actions_n++;
16210 mtr_policy->dev = dev;
16211 match_src_port = true;
16213 case MLX5_FLOW_FATE_DROP:
16214 case MLX5_FLOW_FATE_JUMP:
16215 acts[i].dv_actions[acts[i].actions_n] =
16216 mtr_policy->act_cnt[i].dr_jump_action[domain];
16217 acts[i].actions_n++;
16219 case MLX5_FLOW_FATE_SHARED_RSS:
16220 case MLX5_FLOW_FATE_QUEUE:
16221 hrxq = mlx5_ipool_get
16222 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16223 sub_policy->rix_hrxq[i]);
16225 DRV_LOG(ERR, "Failed to find "
16226 "queue action for policy.");
16229 acts[i].dv_actions[acts[i].actions_n] =
16231 acts[i].actions_n++;
16233 case MLX5_FLOW_FATE_MTR:
16236 "No next hierarchy meter.");
16240 acts[i].dv_actions[acts[i].actions_n] =
16241 next_fm->meter_action;
16242 acts[i].actions_n++;
16244 if (mtr_policy->act_cnt[i].next_sub_policy) {
16246 mtr_policy->act_cnt[i].next_sub_policy;
16249 mlx5_flow_meter_policy_find(dev,
16250 next_fm->policy_id, NULL);
16251 MLX5_ASSERT(next_policy);
16253 next_policy->sub_policys[domain][0];
16256 container_of(next_sub_policy->tbl_rsc,
16257 struct mlx5_flow_tbl_data_entry, tbl);
16258 acts[i].dv_actions[acts[i].actions_n++] =
16259 tbl_data->jump.action;
16260 if (mtr_policy->act_cnt[i].modify_hdr)
16261 match_src_port = !!transfer;
16264 /*Queue action do nothing*/
16269 if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
16270 egress, transfer, match_src_port, acts)) {
16272 "Failed to create policy rules per domain.");
16278 mlx5_flow_meter_detach(priv, next_fm);
16283 * Create the policy rules.
16286 * Pointer to Ethernet device.
16287 * @param[in,out] mtr_policy
16288 * Pointer to meter policy table.
16291 * 0 on success, -1 otherwise.
16294 flow_dv_create_policy_rules(struct rte_eth_dev *dev,
16295 struct mlx5_flow_meter_policy *mtr_policy)
16298 uint16_t sub_policy_num;
16300 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16301 sub_policy_num = (mtr_policy->sub_policy_num >>
16302 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
16303 MLX5_MTR_SUB_POLICY_NUM_MASK;
16304 if (!sub_policy_num)
16306 /* Prepare actions list and create policy rules. */
16307 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16308 mtr_policy->sub_policys[i][0], i)) {
16309 DRV_LOG(ERR, "Failed to create policy action "
16310 "list per domain.");
16318 __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
16320 struct mlx5_priv *priv = dev->data->dev_private;
16321 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16322 struct mlx5_flow_meter_def_policy *def_policy;
16323 struct mlx5_flow_tbl_resource *jump_tbl;
16324 struct mlx5_flow_tbl_data_entry *tbl_data;
16325 uint8_t egress, transfer;
16326 struct rte_flow_error error;
16327 struct mlx5_meter_policy_acts acts[RTE_COLORS];
16330 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16331 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16332 def_policy = mtrmng->def_policy[domain];
16334 def_policy = mlx5_malloc(MLX5_MEM_ZERO,
16335 sizeof(struct mlx5_flow_meter_def_policy),
16336 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
16338 DRV_LOG(ERR, "Failed to alloc default policy table.");
16339 goto def_policy_error;
16341 mtrmng->def_policy[domain] = def_policy;
16342 /* Create the meter suffix table with SUFFIX level. */
16343 jump_tbl = flow_dv_tbl_resource_get(dev,
16344 MLX5_FLOW_TABLE_LEVEL_METER,
16345 egress, transfer, false, NULL, 0,
16346 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
16349 "Failed to create meter suffix table.");
16350 goto def_policy_error;
16352 def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
16353 tbl_data = container_of(jump_tbl,
16354 struct mlx5_flow_tbl_data_entry, tbl);
16355 def_policy->dr_jump_action[RTE_COLOR_GREEN] =
16356 tbl_data->jump.action;
16357 acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
16358 acts[RTE_COLOR_GREEN].actions_n = 1;
16360 * YELLOW has the same default policy as GREEN does.
16361 * G & Y share the same table and action. The 2nd time of table
16362 * resource getting is just to update the reference count for
16363 * the releasing stage.
16365 jump_tbl = flow_dv_tbl_resource_get(dev,
16366 MLX5_FLOW_TABLE_LEVEL_METER,
16367 egress, transfer, false, NULL, 0,
16368 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
16371 "Failed to get meter suffix table.");
16372 goto def_policy_error;
16374 def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
16375 tbl_data = container_of(jump_tbl,
16376 struct mlx5_flow_tbl_data_entry, tbl);
16377 def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
16378 tbl_data->jump.action;
16379 acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
16380 acts[RTE_COLOR_YELLOW].actions_n = 1;
16381 /* Create jump action to the drop table. */
16382 if (!mtrmng->drop_tbl[domain]) {
16383 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
16384 (dev, MLX5_FLOW_TABLE_LEVEL_METER,
16385 egress, transfer, false, NULL, 0,
16386 0, MLX5_MTR_TABLE_ID_DROP, &error);
16387 if (!mtrmng->drop_tbl[domain]) {
16388 DRV_LOG(ERR, "Failed to create meter "
16389 "drop table for default policy.");
16390 goto def_policy_error;
16393 /* all RED: unique Drop table for jump action. */
16394 tbl_data = container_of(mtrmng->drop_tbl[domain],
16395 struct mlx5_flow_tbl_data_entry, tbl);
16396 def_policy->dr_jump_action[RTE_COLOR_RED] =
16397 tbl_data->jump.action;
16398 acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
16399 acts[RTE_COLOR_RED].actions_n = 1;
16400 /* Create default policy rules. */
16401 ret = __flow_dv_create_domain_policy_rules(dev,
16402 &def_policy->sub_policy,
16403 egress, transfer, false, acts);
16405 DRV_LOG(ERR, "Failed to create default policy rules.");
16406 goto def_policy_error;
16411 __flow_dv_destroy_domain_def_policy(dev,
16412 (enum mlx5_meter_domain)domain);
16417 * Create the default policy table set.
16420 * Pointer to Ethernet device.
16422 * 0 on success, -1 otherwise.
16425 flow_dv_create_def_policy(struct rte_eth_dev *dev)
16427 struct mlx5_priv *priv = dev->data->dev_private;
16430 /* Non-termination policy table. */
16431 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16432 if (!priv->config.dv_esw_en && i == MLX5_MTR_DOMAIN_TRANSFER)
16434 if (__flow_dv_create_domain_def_policy(dev, i)) {
16435 DRV_LOG(ERR, "Failed to create default policy");
16436 /* Rollback the created default policies for others. */
16437 flow_dv_destroy_def_policy(dev);
16445 * Create the needed meter tables.
16446 * Lock free, (mutex should be acquired by caller).
16449 * Pointer to Ethernet device.
16451 * Meter information table.
16452 * @param[in] mtr_idx
16454 * @param[in] domain_bitmap
16457 * 0 on success, -1 otherwise.
16460 flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
16461 struct mlx5_flow_meter_info *fm,
16463 uint8_t domain_bitmap)
16465 struct mlx5_priv *priv = dev->data->dev_private;
16466 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16467 struct rte_flow_error error;
16468 struct mlx5_flow_tbl_data_entry *tbl_data;
16469 uint8_t egress, transfer;
16470 void *actions[METER_ACTIONS];
16471 int domain, ret, i;
16472 struct mlx5_flow_counter *cnt;
16473 struct mlx5_flow_dv_match_params value = {
16474 .size = sizeof(value.buf),
16476 struct mlx5_flow_dv_match_params matcher_para = {
16477 .size = sizeof(matcher_para.buf),
16479 int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
16481 uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
16482 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
16483 struct mlx5_list_entry *entry;
16484 struct mlx5_flow_dv_matcher matcher = {
16486 .size = sizeof(matcher.mask.buf),
16489 struct mlx5_flow_dv_matcher *drop_matcher;
16490 struct mlx5_flow_cb_ctx ctx = {
16496 if (!priv->mtr_en || mtr_id_reg_c < 0) {
16497 rte_errno = ENOTSUP;
16500 for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
16501 if (!(domain_bitmap & (1 << domain)) ||
16502 (mtrmng->def_rule[domain] && !fm->drop_cnt))
16504 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16505 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16506 /* Create the drop table with METER DROP level. */
16507 if (!mtrmng->drop_tbl[domain]) {
16508 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
16509 MLX5_FLOW_TABLE_LEVEL_METER,
16510 egress, transfer, false, NULL, 0,
16511 0, MLX5_MTR_TABLE_ID_DROP, &error);
16512 if (!mtrmng->drop_tbl[domain]) {
16513 DRV_LOG(ERR, "Failed to create meter drop table.");
16517 /* Create default matcher in drop table. */
16518 matcher.tbl = mtrmng->drop_tbl[domain],
16519 tbl_data = container_of(mtrmng->drop_tbl[domain],
16520 struct mlx5_flow_tbl_data_entry, tbl);
16521 if (!mtrmng->def_matcher[domain]) {
16522 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16523 (enum modify_reg)mtr_id_reg_c,
16525 matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
16526 matcher.crc = rte_raw_cksum
16527 ((const void *)matcher.mask.buf,
16528 matcher.mask.size);
16529 entry = mlx5_list_register(tbl_data->matchers, &ctx);
16531 DRV_LOG(ERR, "Failed to register meter "
16532 "drop default matcher.");
16535 mtrmng->def_matcher[domain] = container_of(entry,
16536 struct mlx5_flow_dv_matcher, entry);
16538 /* Create default rule in drop table. */
16539 if (!mtrmng->def_rule[domain]) {
16541 actions[i++] = priv->sh->dr_drop_action;
16542 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16543 (enum modify_reg)mtr_id_reg_c, 0, 0);
16544 misc_mask = flow_dv_matcher_enable(value.buf);
16545 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16546 ret = mlx5_flow_os_create_flow
16547 (mtrmng->def_matcher[domain]->matcher_object,
16548 (void *)&value, i, actions,
16549 &mtrmng->def_rule[domain]);
16551 DRV_LOG(ERR, "Failed to create meter "
16552 "default drop rule for drop table.");
16558 MLX5_ASSERT(mtrmng->max_mtr_bits);
16559 if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
16560 /* Create matchers for Drop. */
16561 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16562 (enum modify_reg)mtr_id_reg_c, 0,
16563 (mtr_id_mask << mtr_id_offset));
16564 matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
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);
16571 "Failed to register meter drop matcher.");
16574 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
16575 container_of(entry, struct mlx5_flow_dv_matcher,
16579 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
16580 /* Create drop rule, matching meter_id only. */
16581 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16582 (enum modify_reg)mtr_id_reg_c,
16583 (mtr_idx << mtr_id_offset), UINT32_MAX);
16585 cnt = flow_dv_counter_get_by_idx(dev,
16586 fm->drop_cnt, NULL);
16587 actions[i++] = cnt->action;
16588 actions[i++] = priv->sh->dr_drop_action;
16589 misc_mask = flow_dv_matcher_enable(value.buf);
16590 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16591 ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
16592 (void *)&value, i, actions,
16593 &fm->drop_rule[domain]);
16595 DRV_LOG(ERR, "Failed to create meter "
16596 "drop rule for drop table.");
16602 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16603 if (fm->drop_rule[i]) {
16604 claim_zero(mlx5_flow_os_destroy_flow
16605 (fm->drop_rule[i]));
16606 fm->drop_rule[i] = NULL;
16612 static struct mlx5_flow_meter_sub_policy *
16613 __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
16614 struct mlx5_flow_meter_policy *mtr_policy,
16615 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
16616 struct mlx5_flow_meter_sub_policy *next_sub_policy,
16619 struct mlx5_priv *priv = dev->data->dev_private;
16620 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16621 uint32_t sub_policy_idx = 0;
16622 uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
16624 struct mlx5_hrxq *hrxq;
16625 struct mlx5_flow_handle dh;
16626 struct mlx5_meter_policy_action_container *act_cnt;
16627 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16628 uint16_t sub_policy_num;
16630 rte_spinlock_lock(&mtr_policy->sl);
16631 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16634 hrxq_idx[i] = mlx5_hrxq_get(dev, rss_desc[i]);
16635 if (!hrxq_idx[i]) {
16636 rte_spinlock_unlock(&mtr_policy->sl);
16640 sub_policy_num = (mtr_policy->sub_policy_num >>
16641 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16642 MLX5_MTR_SUB_POLICY_NUM_MASK;
16643 for (j = 0; j < sub_policy_num; j++) {
16644 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16647 mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
16650 if (i >= MLX5_MTR_RTE_COLORS) {
16652 * Found the sub policy table with
16653 * the same queue per color.
16655 rte_spinlock_unlock(&mtr_policy->sl);
16656 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
16657 mlx5_hrxq_release(dev, hrxq_idx[i]);
16659 return mtr_policy->sub_policys[domain][j];
16662 /* Create sub policy. */
16663 if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[0]) {
16664 /* Reuse the first pre-allocated sub_policy. */
16665 sub_policy = mtr_policy->sub_policys[domain][0];
16666 sub_policy_idx = sub_policy->idx;
16668 sub_policy = mlx5_ipool_zmalloc
16669 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16672 sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
16673 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
16674 mlx5_hrxq_release(dev, hrxq_idx[i]);
16675 goto rss_sub_policy_error;
16677 sub_policy->idx = sub_policy_idx;
16678 sub_policy->main_policy = mtr_policy;
16680 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16683 sub_policy->rix_hrxq[i] = hrxq_idx[i];
16684 if (mtr_policy->is_hierarchy) {
16685 act_cnt = &mtr_policy->act_cnt[i];
16686 act_cnt->next_sub_policy = next_sub_policy;
16687 mlx5_hrxq_release(dev, hrxq_idx[i]);
16690 * Overwrite the last action from
16691 * RSS action to Queue action.
16693 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
16696 DRV_LOG(ERR, "Failed to get policy hrxq");
16697 goto rss_sub_policy_error;
16699 act_cnt = &mtr_policy->act_cnt[i];
16700 if (act_cnt->rix_mark || act_cnt->modify_hdr) {
16701 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
16702 if (act_cnt->rix_mark)
16704 dh.fate_action = MLX5_FLOW_FATE_QUEUE;
16705 dh.rix_hrxq = hrxq_idx[i];
16706 flow_drv_rxq_flags_set(dev, &dh);
16710 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16711 sub_policy, domain)) {
16712 DRV_LOG(ERR, "Failed to create policy "
16713 "rules for ingress domain.");
16714 goto rss_sub_policy_error;
16716 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16717 i = (mtr_policy->sub_policy_num >>
16718 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16719 MLX5_MTR_SUB_POLICY_NUM_MASK;
16720 if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
16721 DRV_LOG(ERR, "No free sub-policy slot.");
16722 goto rss_sub_policy_error;
16724 mtr_policy->sub_policys[domain][i] = sub_policy;
16726 mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16727 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
16728 mtr_policy->sub_policy_num |=
16729 (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16730 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
16732 rte_spinlock_unlock(&mtr_policy->sl);
16735 rss_sub_policy_error:
16737 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
16738 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16739 i = (mtr_policy->sub_policy_num >>
16740 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16741 MLX5_MTR_SUB_POLICY_NUM_MASK;
16742 mtr_policy->sub_policys[domain][i] = NULL;
16743 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16747 rte_spinlock_unlock(&mtr_policy->sl);
16752 * Find the policy table for prefix table with RSS.
16755 * Pointer to Ethernet device.
16756 * @param[in] mtr_policy
16757 * Pointer to meter policy table.
16758 * @param[in] rss_desc
16759 * Pointer to rss_desc
16761 * Pointer to table set on success, NULL otherwise and rte_errno is set.
16763 static struct mlx5_flow_meter_sub_policy *
16764 flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
16765 struct mlx5_flow_meter_policy *mtr_policy,
16766 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
16768 struct mlx5_priv *priv = dev->data->dev_private;
16769 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16770 struct mlx5_flow_meter_info *next_fm;
16771 struct mlx5_flow_meter_policy *next_policy;
16772 struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
16773 struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
16774 struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
16775 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16776 bool reuse_sub_policy;
16781 /* Iterate hierarchy to get all policies in this hierarchy. */
16782 policies[i++] = mtr_policy;
16783 if (!mtr_policy->is_hierarchy)
16785 if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
16786 DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
16789 next_fm = mlx5_flow_meter_find(priv,
16790 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
16792 DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
16796 mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
16798 MLX5_ASSERT(next_policy);
16799 mtr_policy = next_policy;
16803 * From last policy to the first one in hierarchy,
16804 * create / get the sub policy for each of them.
16806 sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
16810 &reuse_sub_policy);
16812 DRV_LOG(ERR, "Failed to get the sub policy.");
16815 if (!reuse_sub_policy)
16816 sub_policies[j++] = sub_policy;
16817 next_sub_policy = sub_policy;
16822 uint16_t sub_policy_num;
16824 sub_policy = sub_policies[--j];
16825 mtr_policy = sub_policy->main_policy;
16826 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
16827 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16828 sub_policy_num = (mtr_policy->sub_policy_num >>
16829 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16830 MLX5_MTR_SUB_POLICY_NUM_MASK;
16831 mtr_policy->sub_policys[domain][sub_policy_num - 1] =
16834 mtr_policy->sub_policy_num &=
16835 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16836 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
16837 mtr_policy->sub_policy_num |=
16838 (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16839 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
16840 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16848 * Create the sub policy tag rule for all meters in hierarchy.
16851 * Pointer to Ethernet device.
16853 * Meter information table.
16854 * @param[in] src_port
16855 * The src port this extra rule should use.
16857 * The src port match item.
16858 * @param[out] error
16859 * Perform verbose error reporting if not NULL.
16861 * 0 on success, a negative errno value otherwise and rte_errno is set.
16864 flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
16865 struct mlx5_flow_meter_info *fm,
16867 const struct rte_flow_item *item,
16868 struct rte_flow_error *error)
16870 struct mlx5_priv *priv = dev->data->dev_private;
16871 struct mlx5_flow_meter_policy *mtr_policy;
16872 struct mlx5_flow_meter_sub_policy *sub_policy;
16873 struct mlx5_flow_meter_info *next_fm = NULL;
16874 struct mlx5_flow_meter_policy *next_policy;
16875 struct mlx5_flow_meter_sub_policy *next_sub_policy;
16876 struct mlx5_flow_tbl_data_entry *tbl_data;
16877 struct mlx5_sub_policy_color_rule *color_rule;
16878 struct mlx5_meter_policy_acts acts;
16879 uint32_t color_reg_c_idx;
16880 bool mtr_first = (src_port != UINT16_MAX) ? true : false;
16881 struct rte_flow_attr attr = {
16882 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
16889 uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
16892 mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
16893 MLX5_ASSERT(mtr_policy);
16894 if (!mtr_policy->is_hierarchy)
16896 next_fm = mlx5_flow_meter_find(priv,
16897 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
16899 return rte_flow_error_set(error, EINVAL,
16900 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16901 "Failed to find next meter in hierarchy.");
16903 if (!next_fm->drop_cnt)
16905 color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
16906 sub_policy = mtr_policy->sub_policys[domain][0];
16907 for (i = 0; i < RTE_COLORS; i++) {
16908 bool rule_exist = false;
16909 struct mlx5_meter_policy_action_container *act_cnt;
16911 if (i >= RTE_COLOR_YELLOW)
16913 TAILQ_FOREACH(color_rule,
16914 &sub_policy->color_rules[i], next_port)
16915 if (color_rule->src_port == src_port) {
16921 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
16922 sizeof(struct mlx5_sub_policy_color_rule),
16925 return rte_flow_error_set(error, ENOMEM,
16926 RTE_FLOW_ERROR_TYPE_ACTION,
16927 NULL, "No memory to create tag color rule.");
16928 color_rule->src_port = src_port;
16930 next_policy = mlx5_flow_meter_policy_find(dev,
16931 next_fm->policy_id, NULL);
16932 MLX5_ASSERT(next_policy);
16933 next_sub_policy = next_policy->sub_policys[domain][0];
16934 tbl_data = container_of(next_sub_policy->tbl_rsc,
16935 struct mlx5_flow_tbl_data_entry, tbl);
16936 act_cnt = &mtr_policy->act_cnt[i];
16938 acts.dv_actions[0] = next_fm->meter_action;
16939 acts.dv_actions[1] = act_cnt->modify_hdr->action;
16941 acts.dv_actions[0] = act_cnt->modify_hdr->action;
16942 acts.dv_actions[1] = next_fm->meter_action;
16944 acts.dv_actions[2] = tbl_data->jump.action;
16945 acts.actions_n = 3;
16946 if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
16950 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
16951 MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
16953 &color_rule->matcher, error)) {
16954 rte_flow_error_set(error, errno,
16955 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16956 "Failed to create hierarchy meter matcher.");
16959 if (__flow_dv_create_policy_flow(dev, color_reg_c_idx,
16961 color_rule->matcher->matcher_object,
16962 acts.actions_n, acts.dv_actions,
16964 &color_rule->rule, &attr)) {
16965 rte_flow_error_set(error, errno,
16966 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16967 "Failed to create hierarchy meter rule.");
16970 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
16971 color_rule, next_port);
16975 * Recursive call to iterate all meters in hierarchy and
16976 * create needed rules.
16978 return flow_dv_meter_hierarchy_rule_create(dev, next_fm,
16979 src_port, item, error);
16982 if (color_rule->rule)
16983 mlx5_flow_os_destroy_flow(color_rule->rule);
16984 if (color_rule->matcher) {
16985 struct mlx5_flow_tbl_data_entry *tbl =
16986 container_of(color_rule->matcher->tbl,
16987 typeof(*tbl), tbl);
16988 mlx5_list_unregister(tbl->matchers,
16989 &color_rule->matcher->entry);
16991 mlx5_free(color_rule);
16994 mlx5_flow_meter_detach(priv, next_fm);
16999 * Destroy the sub policy table with RX queue.
17002 * Pointer to Ethernet device.
17003 * @param[in] mtr_policy
17004 * Pointer to meter policy table.
17007 flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
17008 struct mlx5_flow_meter_policy *mtr_policy)
17010 struct mlx5_priv *priv = dev->data->dev_private;
17011 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
17012 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
17014 uint16_t sub_policy_num, new_policy_num;
17016 rte_spinlock_lock(&mtr_policy->sl);
17017 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17018 switch (mtr_policy->act_cnt[i].fate_action) {
17019 case MLX5_FLOW_FATE_SHARED_RSS:
17020 sub_policy_num = (mtr_policy->sub_policy_num >>
17021 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
17022 MLX5_MTR_SUB_POLICY_NUM_MASK;
17023 new_policy_num = sub_policy_num;
17024 for (j = 0; j < sub_policy_num; j++) {
17026 mtr_policy->sub_policys[domain][j];
17028 __flow_dv_destroy_sub_policy_rules(dev,
17031 mtr_policy->sub_policys[domain][0]) {
17032 mtr_policy->sub_policys[domain][j] =
17035 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
17041 if (new_policy_num != sub_policy_num) {
17042 mtr_policy->sub_policy_num &=
17043 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
17044 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
17045 mtr_policy->sub_policy_num |=
17047 MLX5_MTR_SUB_POLICY_NUM_MASK) <<
17048 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
17051 case MLX5_FLOW_FATE_QUEUE:
17052 sub_policy = mtr_policy->sub_policys[domain][0];
17053 __flow_dv_destroy_sub_policy_rules(dev,
17057 /*Other actions without queue and do nothing*/
17061 rte_spinlock_unlock(&mtr_policy->sl);
17064 * Check whether the DR drop action is supported on the root table or not.
17066 * Create a simple flow with DR drop action on root table to validate
17067 * if DR drop action on root table is supported or not.
17070 * Pointer to rte_eth_dev structure.
17073 * 0 on success, a negative errno value otherwise and rte_errno is set.
17076 mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
17078 struct mlx5_priv *priv = dev->data->dev_private;
17079 struct mlx5_dev_ctx_shared *sh = priv->sh;
17080 struct mlx5_flow_dv_match_params mask = {
17081 .size = sizeof(mask.buf),
17083 struct mlx5_flow_dv_match_params value = {
17084 .size = sizeof(value.buf),
17086 struct mlx5dv_flow_matcher_attr dv_attr = {
17087 .type = IBV_FLOW_ATTR_NORMAL,
17089 .match_criteria_enable = 0,
17090 .match_mask = (void *)&mask,
17092 struct mlx5_flow_tbl_resource *tbl = NULL;
17093 void *matcher = NULL;
17097 tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
17101 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
17102 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
17103 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
17104 tbl->obj, &matcher);
17107 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
17108 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
17109 &sh->dr_drop_action, &flow);
17112 * If DR drop action is not supported on root table, flow create will
17113 * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
17117 (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
17118 DRV_LOG(INFO, "DR drop action is not supported in root table.");
17120 DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
17123 claim_zero(mlx5_flow_os_destroy_flow(flow));
17126 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
17128 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
17133 * Validate the batch counter support in root table.
17135 * Create a simple flow with invalid counter and drop action on root table to
17136 * validate if batch counter with offset on root table is supported or not.
17139 * Pointer to rte_eth_dev structure.
17142 * 0 on success, a negative errno value otherwise and rte_errno is set.
17145 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
17147 struct mlx5_priv *priv = dev->data->dev_private;
17148 struct mlx5_dev_ctx_shared *sh = priv->sh;
17149 struct mlx5_flow_dv_match_params mask = {
17150 .size = sizeof(mask.buf),
17152 struct mlx5_flow_dv_match_params value = {
17153 .size = sizeof(value.buf),
17155 struct mlx5dv_flow_matcher_attr dv_attr = {
17156 .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
17158 .match_criteria_enable = 0,
17159 .match_mask = (void *)&mask,
17161 void *actions[2] = { 0 };
17162 struct mlx5_flow_tbl_resource *tbl = NULL;
17163 struct mlx5_devx_obj *dcs = NULL;
17164 void *matcher = NULL;
17168 tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
17172 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
17175 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
17179 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
17180 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
17181 ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
17182 tbl->obj, &matcher);
17185 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
17186 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
17190 * If batch counter with offset is not supported, the driver will not
17191 * validate the invalid offset value, flow create should success.
17192 * In this case, it means batch counter is not supported in root table.
17194 * Otherwise, if flow create is failed, counter offset is supported.
17197 DRV_LOG(INFO, "Batch counter is not supported in root "
17198 "table. Switch to fallback mode.");
17199 rte_errno = ENOTSUP;
17201 claim_zero(mlx5_flow_os_destroy_flow(flow));
17203 /* Check matcher to make sure validate fail at flow create. */
17204 if (!matcher || (matcher && errno != EINVAL))
17205 DRV_LOG(ERR, "Unexpected error in counter offset "
17206 "support detection");
17210 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
17212 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
17214 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
17216 claim_zero(mlx5_devx_cmd_destroy(dcs));
17221 * Query a devx counter.
17224 * Pointer to the Ethernet device structure.
17226 * Index to the flow counter.
17228 * Set to clear the counter statistics.
17230 * The statistics value of packets.
17231 * @param[out] bytes
17232 * The statistics value of bytes.
17235 * 0 on success, otherwise return -1.
17238 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
17239 uint64_t *pkts, uint64_t *bytes)
17241 struct mlx5_priv *priv = dev->data->dev_private;
17242 struct mlx5_flow_counter *cnt;
17243 uint64_t inn_pkts, inn_bytes;
17246 if (!priv->sh->devx)
17249 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
17252 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
17253 *pkts = inn_pkts - cnt->hits;
17254 *bytes = inn_bytes - cnt->bytes;
17256 cnt->hits = inn_pkts;
17257 cnt->bytes = inn_bytes;
17263 * Get aged-out flows.
17266 * Pointer to the Ethernet device structure.
17267 * @param[in] context
17268 * The address of an array of pointers to the aged-out flows contexts.
17269 * @param[in] nb_contexts
17270 * The length of context array pointers.
17271 * @param[out] error
17272 * Perform verbose error reporting if not NULL. Initialized in case of
17276 * how many contexts get in success, otherwise negative errno value.
17277 * if nb_contexts is 0, return the amount of all aged contexts.
17278 * if nb_contexts is not 0 , return the amount of aged flows reported
17279 * in the context array.
17280 * @note: only stub for now
17283 flow_dv_get_aged_flows(struct rte_eth_dev *dev,
17285 uint32_t nb_contexts,
17286 struct rte_flow_error *error)
17288 struct mlx5_priv *priv = dev->data->dev_private;
17289 struct mlx5_age_info *age_info;
17290 struct mlx5_age_param *age_param;
17291 struct mlx5_flow_counter *counter;
17292 struct mlx5_aso_age_action *act;
17295 if (nb_contexts && !context)
17296 return rte_flow_error_set(error, EINVAL,
17297 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17298 NULL, "empty context");
17299 age_info = GET_PORT_AGE_INFO(priv);
17300 rte_spinlock_lock(&age_info->aged_sl);
17301 LIST_FOREACH(act, &age_info->aged_aso, next) {
17304 context[nb_flows - 1] =
17305 act->age_params.context;
17306 if (!(--nb_contexts))
17310 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
17313 age_param = MLX5_CNT_TO_AGE(counter);
17314 context[nb_flows - 1] = age_param->context;
17315 if (!(--nb_contexts))
17319 rte_spinlock_unlock(&age_info->aged_sl);
17320 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
17325 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
17328 flow_dv_counter_allocate(struct rte_eth_dev *dev)
17330 return flow_dv_counter_alloc(dev, 0);
17334 * Validate indirect action.
17335 * Dispatcher for action type specific validation.
17338 * Pointer to the Ethernet device structure.
17340 * Indirect action configuration.
17341 * @param[in] action
17342 * The indirect action object to validate.
17343 * @param[out] error
17344 * Perform verbose error reporting if not NULL. Initialized in case of
17348 * 0 on success, otherwise negative errno value.
17351 flow_dv_action_validate(struct rte_eth_dev *dev,
17352 const struct rte_flow_indir_action_conf *conf,
17353 const struct rte_flow_action *action,
17354 struct rte_flow_error *err)
17356 struct mlx5_priv *priv = dev->data->dev_private;
17358 RTE_SET_USED(conf);
17359 switch (action->type) {
17360 case RTE_FLOW_ACTION_TYPE_RSS:
17362 * priv->obj_ops is set according to driver capabilities.
17363 * When DevX capabilities are
17364 * sufficient, it is set to devx_obj_ops.
17365 * Otherwise, it is set to ibv_obj_ops.
17366 * ibv_obj_ops doesn't support ind_table_modify operation.
17367 * In this case the indirect RSS action can't be used.
17369 if (priv->obj_ops.ind_table_modify == NULL)
17370 return rte_flow_error_set
17372 RTE_FLOW_ERROR_TYPE_ACTION,
17374 "Indirect RSS action not supported");
17375 return mlx5_validate_action_rss(dev, action, err);
17376 case RTE_FLOW_ACTION_TYPE_AGE:
17377 if (!priv->sh->aso_age_mng)
17378 return rte_flow_error_set(err, ENOTSUP,
17379 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17381 "Indirect age action not supported");
17382 return flow_dv_validate_action_age(0, action, dev, err);
17383 case RTE_FLOW_ACTION_TYPE_COUNT:
17384 return flow_dv_validate_action_count(dev, true, 0, err);
17385 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17386 if (!priv->sh->ct_aso_en)
17387 return rte_flow_error_set(err, ENOTSUP,
17388 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17389 "ASO CT is not supported");
17390 return mlx5_validate_action_ct(dev, action->conf, err);
17392 return rte_flow_error_set(err, ENOTSUP,
17393 RTE_FLOW_ERROR_TYPE_ACTION,
17395 "action type not supported");
17400 * Check if the RSS configurations for colors of a meter policy match
17401 * each other, except the queues.
17404 * Pointer to the first RSS flow action.
17406 * Pointer to the second RSS flow action.
17409 * 0 on match, 1 on conflict.
17412 flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
17413 const struct rte_flow_action_rss *r2)
17417 if (r1->func != r2->func || r1->level != r2->level ||
17418 r1->types != r2->types || r1->key_len != r2->key_len ||
17419 memcmp(r1->key, r2->key, r1->key_len))
17425 * Validate the meter hierarchy chain for meter policy.
17428 * Pointer to the Ethernet device structure.
17429 * @param[in] meter_id
17431 * @param[in] action_flags
17432 * Holds the actions detected until now.
17433 * @param[out] is_rss
17435 * @param[out] hierarchy_domain
17436 * The domain bitmap for hierarchy policy.
17437 * @param[out] error
17438 * Perform verbose error reporting if not NULL. Initialized in case of
17442 * 0 on success, otherwise negative errno value with error set.
17445 flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
17447 uint64_t action_flags,
17449 uint8_t *hierarchy_domain,
17450 struct rte_mtr_error *error)
17452 struct mlx5_priv *priv = dev->data->dev_private;
17453 struct mlx5_flow_meter_info *fm;
17454 struct mlx5_flow_meter_policy *policy;
17457 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
17458 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
17459 return -rte_mtr_error_set(error, EINVAL,
17460 RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
17462 "Multiple fate actions not supported.");
17463 *hierarchy_domain = 0;
17465 fm = mlx5_flow_meter_find(priv, meter_id, NULL);
17467 return -rte_mtr_error_set(error, EINVAL,
17468 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17469 "Meter not found in meter hierarchy.");
17470 if (fm->def_policy)
17471 return -rte_mtr_error_set(error, EINVAL,
17472 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17473 "Non termination meter not supported in hierarchy.");
17474 policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
17475 MLX5_ASSERT(policy);
17477 * Only inherit the supported domains of the first meter in
17479 * One meter supports at least one domain.
17481 if (!*hierarchy_domain) {
17482 if (policy->transfer)
17483 *hierarchy_domain |=
17484 MLX5_MTR_DOMAIN_TRANSFER_BIT;
17485 if (policy->ingress)
17486 *hierarchy_domain |=
17487 MLX5_MTR_DOMAIN_INGRESS_BIT;
17488 if (policy->egress)
17489 *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
17491 if (!policy->is_hierarchy) {
17492 *is_rss = policy->is_rss;
17495 meter_id = policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id;
17496 if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
17497 return -rte_mtr_error_set(error, EINVAL,
17498 RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
17499 "Exceed max hierarchy meter number.");
17505 * Validate meter policy actions.
17506 * Dispatcher for action type specific validation.
17509 * Pointer to the Ethernet device structure.
17510 * @param[in] action
17511 * The meter policy action object to validate.
17513 * Attributes of flow to determine steering domain.
17514 * @param[out] error
17515 * Perform verbose error reporting if not NULL. Initialized in case of
17519 * 0 on success, otherwise negative errno value.
17522 flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
17523 const struct rte_flow_action *actions[RTE_COLORS],
17524 struct rte_flow_attr *attr,
17526 uint8_t *domain_bitmap,
17527 uint8_t *policy_mode,
17528 struct rte_mtr_error *error)
17530 struct mlx5_priv *priv = dev->data->dev_private;
17531 struct mlx5_dev_config *dev_conf = &priv->config;
17532 const struct rte_flow_action *act;
17533 uint64_t action_flags[RTE_COLORS] = {0};
17536 struct rte_flow_error flow_err;
17537 uint8_t domain_color[RTE_COLORS] = {0};
17538 uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
17539 uint8_t hierarchy_domain = 0;
17540 const struct rte_flow_action_meter *mtr;
17541 bool def_green = false;
17542 bool def_yellow = false;
17543 const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
17545 if (!priv->config.dv_esw_en)
17546 def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
17547 *domain_bitmap = def_domain;
17548 /* Red color could only support DROP action. */
17549 if (!actions[RTE_COLOR_RED] ||
17550 actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
17551 return -rte_mtr_error_set(error, ENOTSUP,
17552 RTE_MTR_ERROR_TYPE_METER_POLICY,
17553 NULL, "Red color only supports drop action.");
17555 * Check default policy actions:
17556 * Green / Yellow: no action, Red: drop action
17557 * Either G or Y will trigger default policy actions to be created.
17559 if (!actions[RTE_COLOR_GREEN] ||
17560 actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
17562 if (!actions[RTE_COLOR_YELLOW] ||
17563 actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
17565 if (def_green && def_yellow) {
17566 *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
17568 } else if (!def_green && def_yellow) {
17569 *policy_mode = MLX5_MTR_POLICY_MODE_OG;
17570 } else if (def_green && !def_yellow) {
17571 *policy_mode = MLX5_MTR_POLICY_MODE_OY;
17573 /* Set to empty string in case of NULL pointer access by user. */
17574 flow_err.message = "";
17575 for (i = 0; i < RTE_COLORS; i++) {
17577 for (action_flags[i] = 0, actions_n = 0;
17578 act && act->type != RTE_FLOW_ACTION_TYPE_END;
17580 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
17581 return -rte_mtr_error_set(error, ENOTSUP,
17582 RTE_MTR_ERROR_TYPE_METER_POLICY,
17583 NULL, "too many actions");
17584 switch (act->type) {
17585 case RTE_FLOW_ACTION_TYPE_PORT_ID:
17586 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17587 if (!priv->config.dv_esw_en)
17588 return -rte_mtr_error_set(error,
17590 RTE_MTR_ERROR_TYPE_METER_POLICY,
17591 NULL, "PORT action validate check"
17592 " fail for ESW disable");
17593 ret = flow_dv_validate_action_port_id(dev,
17595 act, attr, &flow_err);
17597 return -rte_mtr_error_set(error,
17599 RTE_MTR_ERROR_TYPE_METER_POLICY,
17600 NULL, flow_err.message ?
17602 "PORT action validate check fail");
17604 action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
17606 case RTE_FLOW_ACTION_TYPE_MARK:
17607 ret = flow_dv_validate_action_mark(dev, act,
17611 return -rte_mtr_error_set(error,
17613 RTE_MTR_ERROR_TYPE_METER_POLICY,
17614 NULL, flow_err.message ?
17616 "Mark action validate check fail");
17617 if (dev_conf->dv_xmeta_en !=
17618 MLX5_XMETA_MODE_LEGACY)
17619 return -rte_mtr_error_set(error,
17621 RTE_MTR_ERROR_TYPE_METER_POLICY,
17622 NULL, "Extend MARK action is "
17623 "not supported. Please try use "
17624 "default policy for meter.");
17625 action_flags[i] |= MLX5_FLOW_ACTION_MARK;
17628 case RTE_FLOW_ACTION_TYPE_SET_TAG:
17629 ret = flow_dv_validate_action_set_tag(dev,
17630 act, action_flags[i],
17633 return -rte_mtr_error_set(error,
17635 RTE_MTR_ERROR_TYPE_METER_POLICY,
17636 NULL, flow_err.message ?
17638 "Set tag action validate check fail");
17639 action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
17642 case RTE_FLOW_ACTION_TYPE_DROP:
17643 ret = mlx5_flow_validate_action_drop
17644 (action_flags[i], attr, &flow_err);
17646 return -rte_mtr_error_set(error,
17648 RTE_MTR_ERROR_TYPE_METER_POLICY,
17649 NULL, flow_err.message ?
17651 "Drop action validate check fail");
17652 action_flags[i] |= MLX5_FLOW_ACTION_DROP;
17655 case RTE_FLOW_ACTION_TYPE_QUEUE:
17657 * Check whether extensive
17658 * metadata feature is engaged.
17660 if (dev_conf->dv_flow_en &&
17661 (dev_conf->dv_xmeta_en !=
17662 MLX5_XMETA_MODE_LEGACY) &&
17663 mlx5_flow_ext_mreg_supported(dev))
17664 return -rte_mtr_error_set(error,
17666 RTE_MTR_ERROR_TYPE_METER_POLICY,
17667 NULL, "Queue action with meta "
17668 "is not supported. Please try use "
17669 "default policy for meter.");
17670 ret = mlx5_flow_validate_action_queue(act,
17671 action_flags[i], dev,
17674 return -rte_mtr_error_set(error,
17676 RTE_MTR_ERROR_TYPE_METER_POLICY,
17677 NULL, flow_err.message ?
17679 "Queue action validate check fail");
17680 action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
17683 case RTE_FLOW_ACTION_TYPE_RSS:
17684 if (dev_conf->dv_flow_en &&
17685 (dev_conf->dv_xmeta_en !=
17686 MLX5_XMETA_MODE_LEGACY) &&
17687 mlx5_flow_ext_mreg_supported(dev))
17688 return -rte_mtr_error_set(error,
17690 RTE_MTR_ERROR_TYPE_METER_POLICY,
17691 NULL, "RSS action with meta "
17692 "is not supported. Please try use "
17693 "default policy for meter.");
17694 ret = mlx5_validate_action_rss(dev, act,
17697 return -rte_mtr_error_set(error,
17699 RTE_MTR_ERROR_TYPE_METER_POLICY,
17700 NULL, flow_err.message ?
17702 "RSS action validate check fail");
17703 action_flags[i] |= MLX5_FLOW_ACTION_RSS;
17705 /* Either G or Y will set the RSS. */
17706 rss_color[i] = act->conf;
17708 case RTE_FLOW_ACTION_TYPE_JUMP:
17709 ret = flow_dv_validate_action_jump(dev,
17710 NULL, act, action_flags[i],
17711 attr, true, &flow_err);
17713 return -rte_mtr_error_set(error,
17715 RTE_MTR_ERROR_TYPE_METER_POLICY,
17716 NULL, flow_err.message ?
17718 "Jump action validate check fail");
17720 action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
17723 * Only the last meter in the hierarchy will support
17724 * the YELLOW color steering. Then in the meter policy
17725 * actions list, there should be no other meter inside.
17727 case RTE_FLOW_ACTION_TYPE_METER:
17728 if (i != RTE_COLOR_GREEN)
17729 return -rte_mtr_error_set(error,
17731 RTE_MTR_ERROR_TYPE_METER_POLICY,
17733 "Meter hierarchy only supports GREEN color.");
17734 if (*policy_mode != MLX5_MTR_POLICY_MODE_OG)
17735 return -rte_mtr_error_set(error,
17737 RTE_MTR_ERROR_TYPE_METER_POLICY,
17739 "No yellow policy should be provided in meter hierarchy.");
17741 ret = flow_dv_validate_policy_mtr_hierarchy(dev,
17751 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
17754 return -rte_mtr_error_set(error, ENOTSUP,
17755 RTE_MTR_ERROR_TYPE_METER_POLICY,
17757 "Doesn't support optional action");
17760 if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
17761 domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
17762 } else if ((action_flags[i] &
17763 (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
17764 (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
17766 * Only support MLX5_XMETA_MODE_LEGACY
17767 * so MARK action is only in ingress domain.
17769 domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
17771 domain_color[i] = def_domain;
17772 if (action_flags[i] &&
17773 !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
17775 ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
17777 if (action_flags[i] &
17778 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
17779 domain_color[i] &= hierarchy_domain;
17781 * Non-termination actions only support NIC Tx domain.
17782 * The adjustion should be skipped when there is no
17783 * action or only END is provided. The default domains
17784 * bit-mask is set to find the MIN intersection.
17785 * The action flags checking should also be skipped.
17787 if ((def_green && i == RTE_COLOR_GREEN) ||
17788 (def_yellow && i == RTE_COLOR_YELLOW))
17791 * Validate the drop action mutual exclusion
17792 * with other actions. Drop action is mutually-exclusive
17793 * with any other action, except for Count action.
17795 if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
17796 (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
17797 return -rte_mtr_error_set(error, ENOTSUP,
17798 RTE_MTR_ERROR_TYPE_METER_POLICY,
17799 NULL, "Drop action is mutually-exclusive "
17800 "with any other action");
17802 /* Eswitch has few restrictions on using items and actions */
17803 if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
17804 if (!mlx5_flow_ext_mreg_supported(dev) &&
17805 action_flags[i] & MLX5_FLOW_ACTION_MARK)
17806 return -rte_mtr_error_set(error, ENOTSUP,
17807 RTE_MTR_ERROR_TYPE_METER_POLICY,
17808 NULL, "unsupported action MARK");
17809 if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
17810 return -rte_mtr_error_set(error, ENOTSUP,
17811 RTE_MTR_ERROR_TYPE_METER_POLICY,
17812 NULL, "unsupported action QUEUE");
17813 if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
17814 return -rte_mtr_error_set(error, ENOTSUP,
17815 RTE_MTR_ERROR_TYPE_METER_POLICY,
17816 NULL, "unsupported action RSS");
17817 if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
17818 return -rte_mtr_error_set(error, ENOTSUP,
17819 RTE_MTR_ERROR_TYPE_METER_POLICY,
17820 NULL, "no fate action is found");
17822 if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
17823 (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
17824 if ((domain_color[i] &
17825 MLX5_MTR_DOMAIN_EGRESS_BIT))
17827 MLX5_MTR_DOMAIN_EGRESS_BIT;
17829 return -rte_mtr_error_set(error,
17831 RTE_MTR_ERROR_TYPE_METER_POLICY,
17833 "no fate action is found");
17837 /* If both colors have RSS, the attributes should be the same. */
17838 if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
17839 rss_color[RTE_COLOR_YELLOW]))
17840 return -rte_mtr_error_set(error, EINVAL,
17841 RTE_MTR_ERROR_TYPE_METER_POLICY,
17842 NULL, "policy RSS attr conflict");
17843 if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
17845 /* "domain_color[C]" is non-zero for each color, default is ALL. */
17846 if (!def_green && !def_yellow &&
17847 domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
17848 !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
17849 !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
17850 return -rte_mtr_error_set(error, EINVAL,
17851 RTE_MTR_ERROR_TYPE_METER_POLICY,
17852 NULL, "policy domains conflict");
17854 * At least one color policy is listed in the actions, the domains
17855 * to be supported should be the intersection.
17857 *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
17858 domain_color[RTE_COLOR_YELLOW];
17863 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
17865 struct mlx5_priv *priv = dev->data->dev_private;
17868 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
17869 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
17874 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
17875 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
17879 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
17880 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
17887 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
17888 .validate = flow_dv_validate,
17889 .prepare = flow_dv_prepare,
17890 .translate = flow_dv_translate,
17891 .apply = flow_dv_apply,
17892 .remove = flow_dv_remove,
17893 .destroy = flow_dv_destroy,
17894 .query = flow_dv_query,
17895 .create_mtr_tbls = flow_dv_create_mtr_tbls,
17896 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
17897 .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
17898 .create_meter = flow_dv_mtr_alloc,
17899 .free_meter = flow_dv_aso_mtr_release_to_pool,
17900 .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
17901 .create_mtr_acts = flow_dv_create_mtr_policy_acts,
17902 .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
17903 .create_policy_rules = flow_dv_create_policy_rules,
17904 .destroy_policy_rules = flow_dv_destroy_policy_rules,
17905 .create_def_policy = flow_dv_create_def_policy,
17906 .destroy_def_policy = flow_dv_destroy_def_policy,
17907 .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
17908 .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
17909 .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
17910 .counter_alloc = flow_dv_counter_allocate,
17911 .counter_free = flow_dv_counter_free,
17912 .counter_query = flow_dv_counter_query,
17913 .get_aged_flows = flow_dv_get_aged_flows,
17914 .action_validate = flow_dv_action_validate,
17915 .action_create = flow_dv_action_create,
17916 .action_destroy = flow_dv_action_destroy,
17917 .action_update = flow_dv_action_update,
17918 .action_query = flow_dv_action_query,
17919 .sync_domain = flow_dv_sync_domain,
17922 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */