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 /* Update VLAN's VID/PCP based on input rte_flow_action.
317 * Pointer to struct rte_flow_action.
319 * Pointer to struct rte_vlan_hdr.
322 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
323 struct rte_vlan_hdr *vlan)
326 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
328 ((const struct rte_flow_action_of_set_vlan_pcp *)
329 action->conf)->vlan_pcp;
330 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
331 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
332 vlan->vlan_tci |= vlan_tci;
333 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
334 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
335 vlan->vlan_tci |= rte_be_to_cpu_16
336 (((const struct rte_flow_action_of_set_vlan_vid *)
337 action->conf)->vlan_vid);
342 * Fetch 1, 2, 3 or 4 byte field from the byte array
343 * and return as unsigned integer in host-endian format.
346 * Pointer to data array.
348 * Size of field to extract.
351 * converted field in host endian format.
353 static inline uint32_t
354 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
363 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
366 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
367 ret = (ret << 8) | *(data + sizeof(uint16_t));
370 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
381 * Convert modify-header action to DV specification.
383 * Data length of each action is determined by provided field description
384 * and the item mask. Data bit offset and width of each action is determined
385 * by provided item mask.
388 * Pointer to item specification.
390 * Pointer to field modification information.
391 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
392 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
393 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
395 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
396 * Negative offset value sets the same offset as source offset.
397 * size field is ignored, value is taken from source field.
398 * @param[in,out] resource
399 * Pointer to the modify-header resource.
401 * Type of modification.
403 * Pointer to the error structure.
406 * 0 on success, a negative errno value otherwise and rte_errno is set.
409 flow_dv_convert_modify_action(struct rte_flow_item *item,
410 struct field_modify_info *field,
411 struct field_modify_info *dcopy,
412 struct mlx5_flow_dv_modify_hdr_resource *resource,
413 uint32_t type, struct rte_flow_error *error)
415 uint32_t i = resource->actions_num;
416 struct mlx5_modification_cmd *actions = resource->actions;
417 uint32_t carry_b = 0;
420 * The item and mask are provided in big-endian format.
421 * The fields should be presented as in big-endian format either.
422 * Mask must be always present, it defines the actual field width.
424 MLX5_ASSERT(item->mask);
425 MLX5_ASSERT(field->size);
431 bool next_field = true;
432 bool next_dcopy = true;
434 if (i >= MLX5_MAX_MODIFY_NUM)
435 return rte_flow_error_set(error, EINVAL,
436 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
437 "too many items to modify");
438 /* Fetch variable byte size mask from the array. */
439 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
440 field->offset, field->size);
445 /* Deduce actual data width in bits from mask value. */
446 off_b = rte_bsf32(mask) + carry_b;
447 size_b = sizeof(uint32_t) * CHAR_BIT -
448 off_b - __builtin_clz(mask);
450 actions[i] = (struct mlx5_modification_cmd) {
454 .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
457 if (type == MLX5_MODIFICATION_TYPE_COPY) {
459 actions[i].dst_field = dcopy->id;
460 actions[i].dst_offset =
461 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
462 /* Convert entire record to big-endian format. */
463 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
465 * Destination field overflow. Copy leftovers of
466 * a source field to the next destination field.
469 if ((size_b > dcopy->size * CHAR_BIT - dcopy->offset) &&
472 dcopy->size * CHAR_BIT - dcopy->offset;
473 carry_b = actions[i].length;
477 * Not enough bits in a source filed to fill a
478 * destination field. Switch to the next source.
480 if ((size_b < dcopy->size * CHAR_BIT - dcopy->offset) &&
481 (size_b == field->size * CHAR_BIT - off_b)) {
483 field->size * CHAR_BIT - off_b;
484 dcopy->offset += actions[i].length;
490 MLX5_ASSERT(item->spec);
491 data = flow_dv_fetch_field((const uint8_t *)item->spec +
492 field->offset, field->size);
493 /* Shift out the trailing masked bits from data. */
494 data = (data & mask) >> off_b;
495 actions[i].data1 = rte_cpu_to_be_32(data);
497 /* Convert entire record to expected big-endian format. */
498 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
502 } while (field->size);
503 if (resource->actions_num == i)
504 return rte_flow_error_set(error, EINVAL,
505 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
506 "invalid modification flow item");
507 resource->actions_num = i;
512 * Convert modify-header set IPv4 address action to DV specification.
514 * @param[in,out] resource
515 * Pointer to the modify-header resource.
517 * Pointer to action specification.
519 * Pointer to the error structure.
522 * 0 on success, a negative errno value otherwise and rte_errno is set.
525 flow_dv_convert_action_modify_ipv4
526 (struct mlx5_flow_dv_modify_hdr_resource *resource,
527 const struct rte_flow_action *action,
528 struct rte_flow_error *error)
530 const struct rte_flow_action_set_ipv4 *conf =
531 (const struct rte_flow_action_set_ipv4 *)(action->conf);
532 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
533 struct rte_flow_item_ipv4 ipv4;
534 struct rte_flow_item_ipv4 ipv4_mask;
536 memset(&ipv4, 0, sizeof(ipv4));
537 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
538 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
539 ipv4.hdr.src_addr = conf->ipv4_addr;
540 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
542 ipv4.hdr.dst_addr = conf->ipv4_addr;
543 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
546 item.mask = &ipv4_mask;
547 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
548 MLX5_MODIFICATION_TYPE_SET, error);
552 * Convert modify-header set IPv6 address action to DV specification.
554 * @param[in,out] resource
555 * Pointer to the modify-header resource.
557 * Pointer to action specification.
559 * Pointer to the error structure.
562 * 0 on success, a negative errno value otherwise and rte_errno is set.
565 flow_dv_convert_action_modify_ipv6
566 (struct mlx5_flow_dv_modify_hdr_resource *resource,
567 const struct rte_flow_action *action,
568 struct rte_flow_error *error)
570 const struct rte_flow_action_set_ipv6 *conf =
571 (const struct rte_flow_action_set_ipv6 *)(action->conf);
572 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
573 struct rte_flow_item_ipv6 ipv6;
574 struct rte_flow_item_ipv6 ipv6_mask;
576 memset(&ipv6, 0, sizeof(ipv6));
577 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
578 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
579 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
580 sizeof(ipv6.hdr.src_addr));
581 memcpy(&ipv6_mask.hdr.src_addr,
582 &rte_flow_item_ipv6_mask.hdr.src_addr,
583 sizeof(ipv6.hdr.src_addr));
585 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
586 sizeof(ipv6.hdr.dst_addr));
587 memcpy(&ipv6_mask.hdr.dst_addr,
588 &rte_flow_item_ipv6_mask.hdr.dst_addr,
589 sizeof(ipv6.hdr.dst_addr));
592 item.mask = &ipv6_mask;
593 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
594 MLX5_MODIFICATION_TYPE_SET, error);
598 * Convert modify-header set MAC address action to DV specification.
600 * @param[in,out] resource
601 * Pointer to the modify-header resource.
603 * Pointer to action specification.
605 * Pointer to the error structure.
608 * 0 on success, a negative errno value otherwise and rte_errno is set.
611 flow_dv_convert_action_modify_mac
612 (struct mlx5_flow_dv_modify_hdr_resource *resource,
613 const struct rte_flow_action *action,
614 struct rte_flow_error *error)
616 const struct rte_flow_action_set_mac *conf =
617 (const struct rte_flow_action_set_mac *)(action->conf);
618 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
619 struct rte_flow_item_eth eth;
620 struct rte_flow_item_eth eth_mask;
622 memset(ð, 0, sizeof(eth));
623 memset(ð_mask, 0, sizeof(eth_mask));
624 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
625 memcpy(ð.src.addr_bytes, &conf->mac_addr,
626 sizeof(eth.src.addr_bytes));
627 memcpy(ð_mask.src.addr_bytes,
628 &rte_flow_item_eth_mask.src.addr_bytes,
629 sizeof(eth_mask.src.addr_bytes));
631 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
632 sizeof(eth.dst.addr_bytes));
633 memcpy(ð_mask.dst.addr_bytes,
634 &rte_flow_item_eth_mask.dst.addr_bytes,
635 sizeof(eth_mask.dst.addr_bytes));
638 item.mask = ð_mask;
639 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
640 MLX5_MODIFICATION_TYPE_SET, error);
644 * Convert modify-header set VLAN VID action to DV specification.
646 * @param[in,out] resource
647 * Pointer to the modify-header resource.
649 * Pointer to action specification.
651 * Pointer to the error structure.
654 * 0 on success, a negative errno value otherwise and rte_errno is set.
657 flow_dv_convert_action_modify_vlan_vid
658 (struct mlx5_flow_dv_modify_hdr_resource *resource,
659 const struct rte_flow_action *action,
660 struct rte_flow_error *error)
662 const struct rte_flow_action_of_set_vlan_vid *conf =
663 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
664 int i = resource->actions_num;
665 struct mlx5_modification_cmd *actions = resource->actions;
666 struct field_modify_info *field = modify_vlan_out_first_vid;
668 if (i >= MLX5_MAX_MODIFY_NUM)
669 return rte_flow_error_set(error, EINVAL,
670 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
671 "too many items to modify");
672 actions[i] = (struct mlx5_modification_cmd) {
673 .action_type = MLX5_MODIFICATION_TYPE_SET,
675 .length = field->size,
676 .offset = field->offset,
678 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
679 actions[i].data1 = conf->vlan_vid;
680 actions[i].data1 = actions[i].data1 << 16;
681 resource->actions_num = ++i;
686 * Convert modify-header set TP action to DV specification.
688 * @param[in,out] resource
689 * Pointer to the modify-header resource.
691 * Pointer to action specification.
693 * Pointer to rte_flow_item objects list.
695 * Pointer to flow attributes structure.
696 * @param[in] dev_flow
697 * Pointer to the sub flow.
698 * @param[in] tunnel_decap
699 * Whether action is after tunnel decapsulation.
701 * Pointer to the error structure.
704 * 0 on success, a negative errno value otherwise and rte_errno is set.
707 flow_dv_convert_action_modify_tp
708 (struct mlx5_flow_dv_modify_hdr_resource *resource,
709 const struct rte_flow_action *action,
710 const struct rte_flow_item *items,
711 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
712 bool tunnel_decap, struct rte_flow_error *error)
714 const struct rte_flow_action_set_tp *conf =
715 (const struct rte_flow_action_set_tp *)(action->conf);
716 struct rte_flow_item item;
717 struct rte_flow_item_udp udp;
718 struct rte_flow_item_udp udp_mask;
719 struct rte_flow_item_tcp tcp;
720 struct rte_flow_item_tcp tcp_mask;
721 struct field_modify_info *field;
724 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
726 memset(&udp, 0, sizeof(udp));
727 memset(&udp_mask, 0, sizeof(udp_mask));
728 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
729 udp.hdr.src_port = conf->port;
730 udp_mask.hdr.src_port =
731 rte_flow_item_udp_mask.hdr.src_port;
733 udp.hdr.dst_port = conf->port;
734 udp_mask.hdr.dst_port =
735 rte_flow_item_udp_mask.hdr.dst_port;
737 item.type = RTE_FLOW_ITEM_TYPE_UDP;
739 item.mask = &udp_mask;
742 MLX5_ASSERT(attr->tcp);
743 memset(&tcp, 0, sizeof(tcp));
744 memset(&tcp_mask, 0, sizeof(tcp_mask));
745 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
746 tcp.hdr.src_port = conf->port;
747 tcp_mask.hdr.src_port =
748 rte_flow_item_tcp_mask.hdr.src_port;
750 tcp.hdr.dst_port = conf->port;
751 tcp_mask.hdr.dst_port =
752 rte_flow_item_tcp_mask.hdr.dst_port;
754 item.type = RTE_FLOW_ITEM_TYPE_TCP;
756 item.mask = &tcp_mask;
759 return flow_dv_convert_modify_action(&item, field, NULL, resource,
760 MLX5_MODIFICATION_TYPE_SET, error);
764 * Convert modify-header set TTL action to DV specification.
766 * @param[in,out] resource
767 * Pointer to the modify-header resource.
769 * Pointer to action specification.
771 * Pointer to rte_flow_item objects list.
773 * Pointer to flow attributes structure.
774 * @param[in] dev_flow
775 * Pointer to the sub flow.
776 * @param[in] tunnel_decap
777 * Whether action is after tunnel decapsulation.
779 * Pointer to the error structure.
782 * 0 on success, a negative errno value otherwise and rte_errno is set.
785 flow_dv_convert_action_modify_ttl
786 (struct mlx5_flow_dv_modify_hdr_resource *resource,
787 const struct rte_flow_action *action,
788 const struct rte_flow_item *items,
789 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
790 bool tunnel_decap, struct rte_flow_error *error)
792 const struct rte_flow_action_set_ttl *conf =
793 (const struct rte_flow_action_set_ttl *)(action->conf);
794 struct rte_flow_item item;
795 struct rte_flow_item_ipv4 ipv4;
796 struct rte_flow_item_ipv4 ipv4_mask;
797 struct rte_flow_item_ipv6 ipv6;
798 struct rte_flow_item_ipv6 ipv6_mask;
799 struct field_modify_info *field;
802 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
804 memset(&ipv4, 0, sizeof(ipv4));
805 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
806 ipv4.hdr.time_to_live = conf->ttl_value;
807 ipv4_mask.hdr.time_to_live = 0xFF;
808 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
810 item.mask = &ipv4_mask;
813 MLX5_ASSERT(attr->ipv6);
814 memset(&ipv6, 0, sizeof(ipv6));
815 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
816 ipv6.hdr.hop_limits = conf->ttl_value;
817 ipv6_mask.hdr.hop_limits = 0xFF;
818 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
820 item.mask = &ipv6_mask;
823 return flow_dv_convert_modify_action(&item, field, NULL, resource,
824 MLX5_MODIFICATION_TYPE_SET, error);
828 * Convert modify-header decrement TTL action to DV specification.
830 * @param[in,out] resource
831 * Pointer to the modify-header resource.
833 * Pointer to action specification.
835 * Pointer to rte_flow_item objects list.
837 * Pointer to flow attributes structure.
838 * @param[in] dev_flow
839 * Pointer to the sub flow.
840 * @param[in] tunnel_decap
841 * Whether action is after tunnel decapsulation.
843 * Pointer to the error structure.
846 * 0 on success, a negative errno value otherwise and rte_errno is set.
849 flow_dv_convert_action_modify_dec_ttl
850 (struct mlx5_flow_dv_modify_hdr_resource *resource,
851 const struct rte_flow_item *items,
852 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
853 bool tunnel_decap, struct rte_flow_error *error)
855 struct rte_flow_item item;
856 struct rte_flow_item_ipv4 ipv4;
857 struct rte_flow_item_ipv4 ipv4_mask;
858 struct rte_flow_item_ipv6 ipv6;
859 struct rte_flow_item_ipv6 ipv6_mask;
860 struct field_modify_info *field;
863 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
865 memset(&ipv4, 0, sizeof(ipv4));
866 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
867 ipv4.hdr.time_to_live = 0xFF;
868 ipv4_mask.hdr.time_to_live = 0xFF;
869 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
871 item.mask = &ipv4_mask;
874 MLX5_ASSERT(attr->ipv6);
875 memset(&ipv6, 0, sizeof(ipv6));
876 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
877 ipv6.hdr.hop_limits = 0xFF;
878 ipv6_mask.hdr.hop_limits = 0xFF;
879 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
881 item.mask = &ipv6_mask;
884 return flow_dv_convert_modify_action(&item, field, NULL, resource,
885 MLX5_MODIFICATION_TYPE_ADD, error);
889 * Convert modify-header increment/decrement TCP Sequence number
890 * to DV specification.
892 * @param[in,out] resource
893 * Pointer to the modify-header resource.
895 * Pointer to action specification.
897 * Pointer to the error structure.
900 * 0 on success, a negative errno value otherwise and rte_errno is set.
903 flow_dv_convert_action_modify_tcp_seq
904 (struct mlx5_flow_dv_modify_hdr_resource *resource,
905 const struct rte_flow_action *action,
906 struct rte_flow_error *error)
908 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
909 uint64_t value = rte_be_to_cpu_32(*conf);
910 struct rte_flow_item item;
911 struct rte_flow_item_tcp tcp;
912 struct rte_flow_item_tcp tcp_mask;
914 memset(&tcp, 0, sizeof(tcp));
915 memset(&tcp_mask, 0, sizeof(tcp_mask));
916 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
918 * The HW has no decrement operation, only increment operation.
919 * To simulate decrement X from Y using increment operation
920 * we need to add UINT32_MAX X times to Y.
921 * Each adding of UINT32_MAX decrements Y by 1.
924 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
925 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
926 item.type = RTE_FLOW_ITEM_TYPE_TCP;
928 item.mask = &tcp_mask;
929 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
930 MLX5_MODIFICATION_TYPE_ADD, error);
934 * Convert modify-header increment/decrement TCP Acknowledgment number
935 * to DV specification.
937 * @param[in,out] resource
938 * Pointer to the modify-header resource.
940 * Pointer to action specification.
942 * Pointer to the error structure.
945 * 0 on success, a negative errno value otherwise and rte_errno is set.
948 flow_dv_convert_action_modify_tcp_ack
949 (struct mlx5_flow_dv_modify_hdr_resource *resource,
950 const struct rte_flow_action *action,
951 struct rte_flow_error *error)
953 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
954 uint64_t value = rte_be_to_cpu_32(*conf);
955 struct rte_flow_item item;
956 struct rte_flow_item_tcp tcp;
957 struct rte_flow_item_tcp tcp_mask;
959 memset(&tcp, 0, sizeof(tcp));
960 memset(&tcp_mask, 0, sizeof(tcp_mask));
961 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
963 * The HW has no decrement operation, only increment operation.
964 * To simulate decrement X from Y using increment operation
965 * we need to add UINT32_MAX X times to Y.
966 * Each adding of UINT32_MAX decrements Y by 1.
969 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
970 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
971 item.type = RTE_FLOW_ITEM_TYPE_TCP;
973 item.mask = &tcp_mask;
974 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
975 MLX5_MODIFICATION_TYPE_ADD, error);
978 static enum mlx5_modification_field reg_to_field[] = {
979 [REG_NON] = MLX5_MODI_OUT_NONE,
980 [REG_A] = MLX5_MODI_META_DATA_REG_A,
981 [REG_B] = MLX5_MODI_META_DATA_REG_B,
982 [REG_C_0] = MLX5_MODI_META_REG_C_0,
983 [REG_C_1] = MLX5_MODI_META_REG_C_1,
984 [REG_C_2] = MLX5_MODI_META_REG_C_2,
985 [REG_C_3] = MLX5_MODI_META_REG_C_3,
986 [REG_C_4] = MLX5_MODI_META_REG_C_4,
987 [REG_C_5] = MLX5_MODI_META_REG_C_5,
988 [REG_C_6] = MLX5_MODI_META_REG_C_6,
989 [REG_C_7] = MLX5_MODI_META_REG_C_7,
993 * Convert register set to DV specification.
995 * @param[in,out] resource
996 * Pointer to the modify-header resource.
998 * Pointer to action specification.
1000 * Pointer to the error structure.
1003 * 0 on success, a negative errno value otherwise and rte_errno is set.
1006 flow_dv_convert_action_set_reg
1007 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1008 const struct rte_flow_action *action,
1009 struct rte_flow_error *error)
1011 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
1012 struct mlx5_modification_cmd *actions = resource->actions;
1013 uint32_t i = resource->actions_num;
1015 if (i >= MLX5_MAX_MODIFY_NUM)
1016 return rte_flow_error_set(error, EINVAL,
1017 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1018 "too many items to modify");
1019 MLX5_ASSERT(conf->id != REG_NON);
1020 MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
1021 actions[i] = (struct mlx5_modification_cmd) {
1022 .action_type = MLX5_MODIFICATION_TYPE_SET,
1023 .field = reg_to_field[conf->id],
1024 .offset = conf->offset,
1025 .length = conf->length,
1027 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
1028 actions[i].data1 = rte_cpu_to_be_32(conf->data);
1030 resource->actions_num = i;
1035 * Convert SET_TAG action to DV specification.
1038 * Pointer to the rte_eth_dev structure.
1039 * @param[in,out] resource
1040 * Pointer to the modify-header resource.
1042 * Pointer to action specification.
1044 * Pointer to the error structure.
1047 * 0 on success, a negative errno value otherwise and rte_errno is set.
1050 flow_dv_convert_action_set_tag
1051 (struct rte_eth_dev *dev,
1052 struct mlx5_flow_dv_modify_hdr_resource *resource,
1053 const struct rte_flow_action_set_tag *conf,
1054 struct rte_flow_error *error)
1056 rte_be32_t data = rte_cpu_to_be_32(conf->data);
1057 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1058 struct rte_flow_item item = {
1062 struct field_modify_info reg_c_x[] = {
1065 enum mlx5_modification_field reg_type;
1068 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1071 MLX5_ASSERT(ret != REG_NON);
1072 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1073 reg_type = reg_to_field[ret];
1074 MLX5_ASSERT(reg_type > 0);
1075 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1076 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1077 MLX5_MODIFICATION_TYPE_SET, error);
1081 * Convert internal COPY_REG action to DV specification.
1084 * Pointer to the rte_eth_dev structure.
1085 * @param[in,out] res
1086 * Pointer to the modify-header resource.
1088 * Pointer to action specification.
1090 * Pointer to the error structure.
1093 * 0 on success, a negative errno value otherwise and rte_errno is set.
1096 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1097 struct mlx5_flow_dv_modify_hdr_resource *res,
1098 const struct rte_flow_action *action,
1099 struct rte_flow_error *error)
1101 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1102 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1103 struct rte_flow_item item = {
1107 struct field_modify_info reg_src[] = {
1108 {4, 0, reg_to_field[conf->src]},
1111 struct field_modify_info reg_dst = {
1113 .id = reg_to_field[conf->dst],
1115 /* Adjust reg_c[0] usage according to reported mask. */
1116 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1117 struct mlx5_priv *priv = dev->data->dev_private;
1118 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1120 MLX5_ASSERT(reg_c0);
1121 MLX5_ASSERT(priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1122 if (conf->dst == REG_C_0) {
1123 /* Copy to reg_c[0], within mask only. */
1124 reg_dst.offset = rte_bsf32(reg_c0);
1126 * Mask is ignoring the enianness, because
1127 * there is no conversion in datapath.
1129 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1130 /* Copy from destination lower bits to reg_c[0]. */
1131 mask = reg_c0 >> reg_dst.offset;
1133 /* Copy from destination upper bits to reg_c[0]. */
1134 mask = reg_c0 << (sizeof(reg_c0) * CHAR_BIT -
1135 rte_fls_u32(reg_c0));
1138 mask = rte_cpu_to_be_32(reg_c0);
1139 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1140 /* Copy from reg_c[0] to destination lower bits. */
1143 /* Copy from reg_c[0] to destination upper bits. */
1144 reg_dst.offset = sizeof(reg_c0) * CHAR_BIT -
1145 (rte_fls_u32(reg_c0) -
1150 return flow_dv_convert_modify_action(&item,
1151 reg_src, ®_dst, res,
1152 MLX5_MODIFICATION_TYPE_COPY,
1157 * Convert MARK action to DV specification. This routine is used
1158 * in extensive metadata only and requires metadata register to be
1159 * handled. In legacy mode hardware tag resource is engaged.
1162 * Pointer to the rte_eth_dev structure.
1164 * Pointer to MARK action specification.
1165 * @param[in,out] resource
1166 * Pointer to the modify-header resource.
1168 * Pointer to the error structure.
1171 * 0 on success, a negative errno value otherwise and rte_errno is set.
1174 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1175 const struct rte_flow_action_mark *conf,
1176 struct mlx5_flow_dv_modify_hdr_resource *resource,
1177 struct rte_flow_error *error)
1179 struct mlx5_priv *priv = dev->data->dev_private;
1180 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1181 priv->sh->dv_mark_mask);
1182 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1183 struct rte_flow_item item = {
1187 struct field_modify_info reg_c_x[] = {
1193 return rte_flow_error_set(error, EINVAL,
1194 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1195 NULL, "zero mark action mask");
1196 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1199 MLX5_ASSERT(reg > 0);
1200 if (reg == REG_C_0) {
1201 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1202 uint32_t shl_c0 = rte_bsf32(msk_c0);
1204 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1205 mask = rte_cpu_to_be_32(mask) & msk_c0;
1206 mask = rte_cpu_to_be_32(mask << shl_c0);
1208 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1209 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1210 MLX5_MODIFICATION_TYPE_SET, error);
1214 * Get metadata register index for specified steering domain.
1217 * Pointer to the rte_eth_dev structure.
1219 * Attributes of flow to determine steering domain.
1221 * Pointer to the error structure.
1224 * positive index on success, a negative errno value otherwise
1225 * and rte_errno is set.
1227 static enum modify_reg
1228 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1229 const struct rte_flow_attr *attr,
1230 struct rte_flow_error *error)
1233 mlx5_flow_get_reg_id(dev, attr->transfer ?
1237 MLX5_METADATA_RX, 0, error);
1239 return rte_flow_error_set(error,
1240 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1241 NULL, "unavailable "
1242 "metadata register");
1247 * Convert SET_META action to DV specification.
1250 * Pointer to the rte_eth_dev structure.
1251 * @param[in,out] resource
1252 * Pointer to the modify-header resource.
1254 * Attributes of flow that includes this item.
1256 * Pointer to action specification.
1258 * Pointer to the error structure.
1261 * 0 on success, a negative errno value otherwise and rte_errno is set.
1264 flow_dv_convert_action_set_meta
1265 (struct rte_eth_dev *dev,
1266 struct mlx5_flow_dv_modify_hdr_resource *resource,
1267 const struct rte_flow_attr *attr,
1268 const struct rte_flow_action_set_meta *conf,
1269 struct rte_flow_error *error)
1271 uint32_t mask = rte_cpu_to_be_32(conf->mask);
1272 uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1273 struct rte_flow_item item = {
1277 struct field_modify_info reg_c_x[] = {
1280 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1284 MLX5_ASSERT(reg != REG_NON);
1285 if (reg == REG_C_0) {
1286 struct mlx5_priv *priv = dev->data->dev_private;
1287 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1288 uint32_t shl_c0 = rte_bsf32(msk_c0);
1290 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1291 mask = rte_cpu_to_be_32(mask) & msk_c0;
1292 mask = rte_cpu_to_be_32(mask << shl_c0);
1294 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1295 /* The routine expects parameters in memory as big-endian ones. */
1296 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1297 MLX5_MODIFICATION_TYPE_SET, error);
1301 * Convert modify-header set IPv4 DSCP action to DV specification.
1303 * @param[in,out] resource
1304 * Pointer to the modify-header resource.
1306 * Pointer to action specification.
1308 * Pointer to the error structure.
1311 * 0 on success, a negative errno value otherwise and rte_errno is set.
1314 flow_dv_convert_action_modify_ipv4_dscp
1315 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1316 const struct rte_flow_action *action,
1317 struct rte_flow_error *error)
1319 const struct rte_flow_action_set_dscp *conf =
1320 (const struct rte_flow_action_set_dscp *)(action->conf);
1321 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1322 struct rte_flow_item_ipv4 ipv4;
1323 struct rte_flow_item_ipv4 ipv4_mask;
1325 memset(&ipv4, 0, sizeof(ipv4));
1326 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1327 ipv4.hdr.type_of_service = conf->dscp;
1328 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1330 item.mask = &ipv4_mask;
1331 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1332 MLX5_MODIFICATION_TYPE_SET, error);
1336 * Convert modify-header set IPv6 DSCP action to DV specification.
1338 * @param[in,out] resource
1339 * Pointer to the modify-header resource.
1341 * Pointer to action specification.
1343 * Pointer to the error structure.
1346 * 0 on success, a negative errno value otherwise and rte_errno is set.
1349 flow_dv_convert_action_modify_ipv6_dscp
1350 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1351 const struct rte_flow_action *action,
1352 struct rte_flow_error *error)
1354 const struct rte_flow_action_set_dscp *conf =
1355 (const struct rte_flow_action_set_dscp *)(action->conf);
1356 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1357 struct rte_flow_item_ipv6 ipv6;
1358 struct rte_flow_item_ipv6 ipv6_mask;
1360 memset(&ipv6, 0, sizeof(ipv6));
1361 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1363 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1364 * rdma-core only accept the DSCP bits byte aligned start from
1365 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1366 * bits in IPv6 case as rdma-core requires byte aligned value.
1368 ipv6.hdr.vtc_flow = conf->dscp;
1369 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1371 item.mask = &ipv6_mask;
1372 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1373 MLX5_MODIFICATION_TYPE_SET, error);
1377 mlx5_flow_item_field_width(struct mlx5_dev_config *config,
1378 enum rte_flow_field_id field)
1381 case RTE_FLOW_FIELD_START:
1383 case RTE_FLOW_FIELD_MAC_DST:
1384 case RTE_FLOW_FIELD_MAC_SRC:
1386 case RTE_FLOW_FIELD_VLAN_TYPE:
1388 case RTE_FLOW_FIELD_VLAN_ID:
1390 case RTE_FLOW_FIELD_MAC_TYPE:
1392 case RTE_FLOW_FIELD_IPV4_DSCP:
1394 case RTE_FLOW_FIELD_IPV4_TTL:
1396 case RTE_FLOW_FIELD_IPV4_SRC:
1397 case RTE_FLOW_FIELD_IPV4_DST:
1399 case RTE_FLOW_FIELD_IPV6_DSCP:
1401 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1403 case RTE_FLOW_FIELD_IPV6_SRC:
1404 case RTE_FLOW_FIELD_IPV6_DST:
1406 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1407 case RTE_FLOW_FIELD_TCP_PORT_DST:
1409 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1410 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1412 case RTE_FLOW_FIELD_TCP_FLAGS:
1414 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1415 case RTE_FLOW_FIELD_UDP_PORT_DST:
1417 case RTE_FLOW_FIELD_VXLAN_VNI:
1418 case RTE_FLOW_FIELD_GENEVE_VNI:
1420 case RTE_FLOW_FIELD_GTP_TEID:
1421 case RTE_FLOW_FIELD_TAG:
1423 case RTE_FLOW_FIELD_MARK:
1425 case RTE_FLOW_FIELD_META:
1426 if (config->dv_xmeta_en == MLX5_XMETA_MODE_META16)
1428 else if (config->dv_xmeta_en == MLX5_XMETA_MODE_META32)
1432 case RTE_FLOW_FIELD_POINTER:
1433 case RTE_FLOW_FIELD_VALUE:
1442 mlx5_flow_field_id_to_modify_info
1443 (const struct rte_flow_action_modify_data *data,
1444 struct field_modify_info *info,
1445 uint32_t *mask, uint32_t *value,
1446 uint32_t width, uint32_t dst_width,
1447 struct rte_eth_dev *dev,
1448 const struct rte_flow_attr *attr,
1449 struct rte_flow_error *error)
1451 struct mlx5_priv *priv = dev->data->dev_private;
1452 struct mlx5_dev_config *config = &priv->config;
1456 switch (data->field) {
1457 case RTE_FLOW_FIELD_START:
1458 /* not supported yet */
1461 case RTE_FLOW_FIELD_MAC_DST:
1462 off = data->offset > 16 ? data->offset - 16 : 0;
1464 if (data->offset < 16) {
1465 info[idx] = (struct field_modify_info){2, 0,
1466 MLX5_MODI_OUT_DMAC_15_0};
1468 mask[idx] = rte_cpu_to_be_16(0xffff >>
1472 mask[idx] = RTE_BE16(0xffff);
1479 info[idx] = (struct field_modify_info){4, 4 * idx,
1480 MLX5_MODI_OUT_DMAC_47_16};
1481 mask[idx] = rte_cpu_to_be_32((0xffffffff >>
1482 (32 - width)) << off);
1484 if (data->offset < 16)
1485 info[idx++] = (struct field_modify_info){2, 0,
1486 MLX5_MODI_OUT_DMAC_15_0};
1487 info[idx] = (struct field_modify_info){4, off,
1488 MLX5_MODI_OUT_DMAC_47_16};
1491 case RTE_FLOW_FIELD_MAC_SRC:
1492 off = data->offset > 16 ? data->offset - 16 : 0;
1494 if (data->offset < 16) {
1495 info[idx] = (struct field_modify_info){2, 0,
1496 MLX5_MODI_OUT_SMAC_15_0};
1498 mask[idx] = rte_cpu_to_be_16(0xffff >>
1502 mask[idx] = RTE_BE16(0xffff);
1509 info[idx] = (struct field_modify_info){4, 4 * idx,
1510 MLX5_MODI_OUT_SMAC_47_16};
1511 mask[idx] = rte_cpu_to_be_32((0xffffffff >>
1512 (32 - width)) << off);
1514 if (data->offset < 16)
1515 info[idx++] = (struct field_modify_info){2, 0,
1516 MLX5_MODI_OUT_SMAC_15_0};
1517 info[idx] = (struct field_modify_info){4, off,
1518 MLX5_MODI_OUT_SMAC_47_16};
1521 case RTE_FLOW_FIELD_VLAN_TYPE:
1522 /* not supported yet */
1524 case RTE_FLOW_FIELD_VLAN_ID:
1525 info[idx] = (struct field_modify_info){2, 0,
1526 MLX5_MODI_OUT_FIRST_VID};
1528 mask[idx] = rte_cpu_to_be_16(0x0fff >> (12 - width));
1530 case RTE_FLOW_FIELD_MAC_TYPE:
1531 info[idx] = (struct field_modify_info){2, 0,
1532 MLX5_MODI_OUT_ETHERTYPE};
1534 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1536 case RTE_FLOW_FIELD_IPV4_DSCP:
1537 info[idx] = (struct field_modify_info){1, 0,
1538 MLX5_MODI_OUT_IP_DSCP};
1540 mask[idx] = 0x3f >> (6 - width);
1542 case RTE_FLOW_FIELD_IPV4_TTL:
1543 info[idx] = (struct field_modify_info){1, 0,
1544 MLX5_MODI_OUT_IPV4_TTL};
1546 mask[idx] = 0xff >> (8 - width);
1548 case RTE_FLOW_FIELD_IPV4_SRC:
1549 info[idx] = (struct field_modify_info){4, 0,
1550 MLX5_MODI_OUT_SIPV4};
1552 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1555 case RTE_FLOW_FIELD_IPV4_DST:
1556 info[idx] = (struct field_modify_info){4, 0,
1557 MLX5_MODI_OUT_DIPV4};
1559 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1562 case RTE_FLOW_FIELD_IPV6_DSCP:
1563 info[idx] = (struct field_modify_info){1, 0,
1564 MLX5_MODI_OUT_IP_DSCP};
1566 mask[idx] = 0x3f >> (6 - width);
1568 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1569 info[idx] = (struct field_modify_info){1, 0,
1570 MLX5_MODI_OUT_IPV6_HOPLIMIT};
1572 mask[idx] = 0xff >> (8 - width);
1574 case RTE_FLOW_FIELD_IPV6_SRC:
1576 if (data->offset < 32) {
1577 info[idx] = (struct field_modify_info){4,
1579 MLX5_MODI_OUT_SIPV6_31_0};
1582 rte_cpu_to_be_32(0xffffffff >>
1586 mask[idx] = RTE_BE32(0xffffffff);
1593 if (data->offset < 64) {
1594 info[idx] = (struct field_modify_info){4,
1596 MLX5_MODI_OUT_SIPV6_63_32};
1599 rte_cpu_to_be_32(0xffffffff >>
1603 mask[idx] = RTE_BE32(0xffffffff);
1610 if (data->offset < 96) {
1611 info[idx] = (struct field_modify_info){4,
1613 MLX5_MODI_OUT_SIPV6_95_64};
1616 rte_cpu_to_be_32(0xffffffff >>
1620 mask[idx] = RTE_BE32(0xffffffff);
1627 info[idx] = (struct field_modify_info){4, 4 * idx,
1628 MLX5_MODI_OUT_SIPV6_127_96};
1629 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1632 if (data->offset < 32)
1633 info[idx++] = (struct field_modify_info){4, 0,
1634 MLX5_MODI_OUT_SIPV6_31_0};
1635 if (data->offset < 64)
1636 info[idx++] = (struct field_modify_info){4, 0,
1637 MLX5_MODI_OUT_SIPV6_63_32};
1638 if (data->offset < 96)
1639 info[idx++] = (struct field_modify_info){4, 0,
1640 MLX5_MODI_OUT_SIPV6_95_64};
1641 if (data->offset < 128)
1642 info[idx++] = (struct field_modify_info){4, 0,
1643 MLX5_MODI_OUT_SIPV6_127_96};
1646 case RTE_FLOW_FIELD_IPV6_DST:
1648 if (data->offset < 32) {
1649 info[idx] = (struct field_modify_info){4,
1651 MLX5_MODI_OUT_DIPV6_31_0};
1654 rte_cpu_to_be_32(0xffffffff >>
1658 mask[idx] = RTE_BE32(0xffffffff);
1665 if (data->offset < 64) {
1666 info[idx] = (struct field_modify_info){4,
1668 MLX5_MODI_OUT_DIPV6_63_32};
1671 rte_cpu_to_be_32(0xffffffff >>
1675 mask[idx] = RTE_BE32(0xffffffff);
1682 if (data->offset < 96) {
1683 info[idx] = (struct field_modify_info){4,
1685 MLX5_MODI_OUT_DIPV6_95_64};
1688 rte_cpu_to_be_32(0xffffffff >>
1692 mask[idx] = RTE_BE32(0xffffffff);
1699 info[idx] = (struct field_modify_info){4, 4 * idx,
1700 MLX5_MODI_OUT_DIPV6_127_96};
1701 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1704 if (data->offset < 32)
1705 info[idx++] = (struct field_modify_info){4, 0,
1706 MLX5_MODI_OUT_DIPV6_31_0};
1707 if (data->offset < 64)
1708 info[idx++] = (struct field_modify_info){4, 0,
1709 MLX5_MODI_OUT_DIPV6_63_32};
1710 if (data->offset < 96)
1711 info[idx++] = (struct field_modify_info){4, 0,
1712 MLX5_MODI_OUT_DIPV6_95_64};
1713 if (data->offset < 128)
1714 info[idx++] = (struct field_modify_info){4, 0,
1715 MLX5_MODI_OUT_DIPV6_127_96};
1718 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1719 info[idx] = (struct field_modify_info){2, 0,
1720 MLX5_MODI_OUT_TCP_SPORT};
1722 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1724 case RTE_FLOW_FIELD_TCP_PORT_DST:
1725 info[idx] = (struct field_modify_info){2, 0,
1726 MLX5_MODI_OUT_TCP_DPORT};
1728 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1730 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1731 info[idx] = (struct field_modify_info){4, 0,
1732 MLX5_MODI_OUT_TCP_SEQ_NUM};
1734 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1737 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1738 info[idx] = (struct field_modify_info){4, 0,
1739 MLX5_MODI_OUT_TCP_ACK_NUM};
1741 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1744 case RTE_FLOW_FIELD_TCP_FLAGS:
1745 info[idx] = (struct field_modify_info){2, 0,
1746 MLX5_MODI_OUT_TCP_FLAGS};
1748 mask[idx] = rte_cpu_to_be_16(0x1ff >> (9 - width));
1750 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1751 info[idx] = (struct field_modify_info){2, 0,
1752 MLX5_MODI_OUT_UDP_SPORT};
1754 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1756 case RTE_FLOW_FIELD_UDP_PORT_DST:
1757 info[idx] = (struct field_modify_info){2, 0,
1758 MLX5_MODI_OUT_UDP_DPORT};
1760 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1762 case RTE_FLOW_FIELD_VXLAN_VNI:
1763 /* not supported yet */
1765 case RTE_FLOW_FIELD_GENEVE_VNI:
1766 /* not supported yet*/
1768 case RTE_FLOW_FIELD_GTP_TEID:
1769 info[idx] = (struct field_modify_info){4, 0,
1770 MLX5_MODI_GTP_TEID};
1772 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1775 case RTE_FLOW_FIELD_TAG:
1777 int reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
1778 data->level, error);
1781 MLX5_ASSERT(reg != REG_NON);
1782 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1783 info[idx] = (struct field_modify_info){4, 0,
1787 rte_cpu_to_be_32(0xffffffff >>
1791 case RTE_FLOW_FIELD_MARK:
1793 int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
1797 MLX5_ASSERT(reg != REG_NON);
1798 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1799 info[idx] = (struct field_modify_info){4, 0,
1803 rte_cpu_to_be_32(0xffffffff >>
1807 case RTE_FLOW_FIELD_META:
1809 unsigned int xmeta = config->dv_xmeta_en;
1810 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1813 MLX5_ASSERT(reg != REG_NON);
1814 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1815 if (xmeta == MLX5_XMETA_MODE_META16) {
1816 info[idx] = (struct field_modify_info){2, 0,
1819 mask[idx] = rte_cpu_to_be_16(0xffff >>
1821 } else if (xmeta == MLX5_XMETA_MODE_META32) {
1822 info[idx] = (struct field_modify_info){4, 0,
1826 rte_cpu_to_be_32(0xffffffff >>
1833 case RTE_FLOW_FIELD_POINTER:
1834 case RTE_FLOW_FIELD_VALUE:
1835 if (data->field == RTE_FLOW_FIELD_POINTER)
1836 memcpy(&val, (void *)(uintptr_t)data->value,
1840 for (idx = 0; idx < MLX5_ACT_MAX_MOD_FIELDS; idx++) {
1842 if (dst_width == 48) {
1843 /*special case for MAC addresses */
1844 value[idx] = rte_cpu_to_be_16(val);
1847 } else if (dst_width > 16) {
1848 value[idx] = rte_cpu_to_be_32(val);
1850 } else if (dst_width > 8) {
1851 value[idx] = rte_cpu_to_be_16(val);
1854 value[idx] = (uint8_t)val;
1869 * Convert modify_field action to DV specification.
1872 * Pointer to the rte_eth_dev structure.
1873 * @param[in,out] resource
1874 * Pointer to the modify-header resource.
1876 * Pointer to action specification.
1878 * Attributes of flow that includes this item.
1880 * Pointer to the error structure.
1883 * 0 on success, a negative errno value otherwise and rte_errno is set.
1886 flow_dv_convert_action_modify_field
1887 (struct rte_eth_dev *dev,
1888 struct mlx5_flow_dv_modify_hdr_resource *resource,
1889 const struct rte_flow_action *action,
1890 const struct rte_flow_attr *attr,
1891 struct rte_flow_error *error)
1893 struct mlx5_priv *priv = dev->data->dev_private;
1894 struct mlx5_dev_config *config = &priv->config;
1895 const struct rte_flow_action_modify_field *conf =
1896 (const struct rte_flow_action_modify_field *)(action->conf);
1897 struct rte_flow_item item;
1898 struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1900 struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1902 uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1903 uint32_t value[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1905 uint32_t dst_width = mlx5_flow_item_field_width(config,
1908 if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1909 conf->src.field == RTE_FLOW_FIELD_VALUE) {
1910 type = MLX5_MODIFICATION_TYPE_SET;
1911 /** For SET fill the destination field (field) first. */
1912 mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1913 value, conf->width, dst_width, dev, attr, error);
1914 /** Then copy immediate value from source as per mask. */
1915 mlx5_flow_field_id_to_modify_info(&conf->src, dcopy, mask,
1916 value, conf->width, dst_width, dev, attr, error);
1919 type = MLX5_MODIFICATION_TYPE_COPY;
1920 /** For COPY fill the destination field (dcopy) without mask. */
1921 mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1922 value, conf->width, dst_width, dev, attr, error);
1923 /** Then construct the source field (field) with mask. */
1924 mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1925 value, conf->width, dst_width, dev, attr, error);
1928 return flow_dv_convert_modify_action(&item,
1929 field, dcopy, resource, type, error);
1933 * Validate MARK item.
1936 * Pointer to the rte_eth_dev structure.
1938 * Item specification.
1940 * Attributes of flow that includes this item.
1942 * Pointer to error structure.
1945 * 0 on success, a negative errno value otherwise and rte_errno is set.
1948 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1949 const struct rte_flow_item *item,
1950 const struct rte_flow_attr *attr __rte_unused,
1951 struct rte_flow_error *error)
1953 struct mlx5_priv *priv = dev->data->dev_private;
1954 struct mlx5_dev_config *config = &priv->config;
1955 const struct rte_flow_item_mark *spec = item->spec;
1956 const struct rte_flow_item_mark *mask = item->mask;
1957 const struct rte_flow_item_mark nic_mask = {
1958 .id = priv->sh->dv_mark_mask,
1962 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1963 return rte_flow_error_set(error, ENOTSUP,
1964 RTE_FLOW_ERROR_TYPE_ITEM, item,
1965 "extended metadata feature"
1967 if (!mlx5_flow_ext_mreg_supported(dev))
1968 return rte_flow_error_set(error, ENOTSUP,
1969 RTE_FLOW_ERROR_TYPE_ITEM, item,
1970 "extended metadata register"
1971 " isn't supported");
1973 return rte_flow_error_set(error, ENOTSUP,
1974 RTE_FLOW_ERROR_TYPE_ITEM, item,
1975 "extended metadata register"
1976 " isn't available");
1977 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1981 return rte_flow_error_set(error, EINVAL,
1982 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1984 "data cannot be empty");
1985 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1986 return rte_flow_error_set(error, EINVAL,
1987 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1989 "mark id exceeds the limit");
1993 return rte_flow_error_set(error, EINVAL,
1994 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1995 "mask cannot be zero");
1997 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1998 (const uint8_t *)&nic_mask,
1999 sizeof(struct rte_flow_item_mark),
2000 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2007 * Validate META item.
2010 * Pointer to the rte_eth_dev structure.
2012 * Item specification.
2014 * Attributes of flow that includes this item.
2016 * Pointer to error structure.
2019 * 0 on success, a negative errno value otherwise and rte_errno is set.
2022 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
2023 const struct rte_flow_item *item,
2024 const struct rte_flow_attr *attr,
2025 struct rte_flow_error *error)
2027 struct mlx5_priv *priv = dev->data->dev_private;
2028 struct mlx5_dev_config *config = &priv->config;
2029 const struct rte_flow_item_meta *spec = item->spec;
2030 const struct rte_flow_item_meta *mask = item->mask;
2031 struct rte_flow_item_meta nic_mask = {
2038 return rte_flow_error_set(error, EINVAL,
2039 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2041 "data cannot be empty");
2042 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2043 if (!mlx5_flow_ext_mreg_supported(dev))
2044 return rte_flow_error_set(error, ENOTSUP,
2045 RTE_FLOW_ERROR_TYPE_ITEM, item,
2046 "extended metadata register"
2047 " isn't supported");
2048 reg = flow_dv_get_metadata_reg(dev, attr, error);
2052 return rte_flow_error_set(error, ENOTSUP,
2053 RTE_FLOW_ERROR_TYPE_ITEM, item,
2054 "unavalable extended metadata register");
2056 return rte_flow_error_set(error, ENOTSUP,
2057 RTE_FLOW_ERROR_TYPE_ITEM, item,
2061 nic_mask.data = priv->sh->dv_meta_mask;
2064 return rte_flow_error_set(error, ENOTSUP,
2065 RTE_FLOW_ERROR_TYPE_ITEM, item,
2066 "extended metadata feature "
2067 "should be enabled when "
2068 "meta item is requested "
2069 "with e-switch mode ");
2071 return rte_flow_error_set(error, ENOTSUP,
2072 RTE_FLOW_ERROR_TYPE_ITEM, item,
2073 "match on metadata for ingress "
2074 "is not supported in legacy "
2078 mask = &rte_flow_item_meta_mask;
2080 return rte_flow_error_set(error, EINVAL,
2081 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2082 "mask cannot be zero");
2084 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2085 (const uint8_t *)&nic_mask,
2086 sizeof(struct rte_flow_item_meta),
2087 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2092 * Validate TAG item.
2095 * Pointer to the rte_eth_dev structure.
2097 * Item specification.
2099 * Attributes of flow that includes this item.
2101 * Pointer to error structure.
2104 * 0 on success, a negative errno value otherwise and rte_errno is set.
2107 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2108 const struct rte_flow_item *item,
2109 const struct rte_flow_attr *attr __rte_unused,
2110 struct rte_flow_error *error)
2112 const struct rte_flow_item_tag *spec = item->spec;
2113 const struct rte_flow_item_tag *mask = item->mask;
2114 const struct rte_flow_item_tag nic_mask = {
2115 .data = RTE_BE32(UINT32_MAX),
2120 if (!mlx5_flow_ext_mreg_supported(dev))
2121 return rte_flow_error_set(error, ENOTSUP,
2122 RTE_FLOW_ERROR_TYPE_ITEM, item,
2123 "extensive metadata register"
2124 " isn't supported");
2126 return rte_flow_error_set(error, EINVAL,
2127 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2129 "data cannot be empty");
2131 mask = &rte_flow_item_tag_mask;
2133 return rte_flow_error_set(error, EINVAL,
2134 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2135 "mask cannot be zero");
2137 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2138 (const uint8_t *)&nic_mask,
2139 sizeof(struct rte_flow_item_tag),
2140 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2143 if (mask->index != 0xff)
2144 return rte_flow_error_set(error, EINVAL,
2145 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2146 "partial mask for tag index"
2147 " is not supported");
2148 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2151 MLX5_ASSERT(ret != REG_NON);
2156 * Validate vport item.
2159 * Pointer to the rte_eth_dev structure.
2161 * Item specification.
2163 * Attributes of flow that includes this item.
2164 * @param[in] item_flags
2165 * Bit-fields that holds the items detected until now.
2167 * Pointer to error structure.
2170 * 0 on success, a negative errno value otherwise and rte_errno is set.
2173 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2174 const struct rte_flow_item *item,
2175 const struct rte_flow_attr *attr,
2176 uint64_t item_flags,
2177 struct rte_flow_error *error)
2179 const struct rte_flow_item_port_id *spec = item->spec;
2180 const struct rte_flow_item_port_id *mask = item->mask;
2181 const struct rte_flow_item_port_id switch_mask = {
2184 struct mlx5_priv *esw_priv;
2185 struct mlx5_priv *dev_priv;
2188 if (!attr->transfer)
2189 return rte_flow_error_set(error, EINVAL,
2190 RTE_FLOW_ERROR_TYPE_ITEM,
2192 "match on port id is valid only"
2193 " when transfer flag is enabled");
2194 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2195 return rte_flow_error_set(error, ENOTSUP,
2196 RTE_FLOW_ERROR_TYPE_ITEM, item,
2197 "multiple source ports are not"
2200 mask = &switch_mask;
2201 if (mask->id != 0xffffffff)
2202 return rte_flow_error_set(error, ENOTSUP,
2203 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2205 "no support for partial mask on"
2207 ret = mlx5_flow_item_acceptable
2208 (item, (const uint8_t *)mask,
2209 (const uint8_t *)&rte_flow_item_port_id_mask,
2210 sizeof(struct rte_flow_item_port_id),
2211 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2216 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2218 return rte_flow_error_set(error, rte_errno,
2219 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2220 "failed to obtain E-Switch info for"
2222 dev_priv = mlx5_dev_to_eswitch_info(dev);
2224 return rte_flow_error_set(error, rte_errno,
2225 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2227 "failed to obtain E-Switch info");
2228 if (esw_priv->domain_id != dev_priv->domain_id)
2229 return rte_flow_error_set(error, EINVAL,
2230 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2231 "cannot match on a port from a"
2232 " different E-Switch");
2237 * Validate VLAN item.
2240 * Item specification.
2241 * @param[in] item_flags
2242 * Bit-fields that holds the items detected until now.
2244 * Ethernet device flow is being created on.
2246 * Pointer to error structure.
2249 * 0 on success, a negative errno value otherwise and rte_errno is set.
2252 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2253 uint64_t item_flags,
2254 struct rte_eth_dev *dev,
2255 struct rte_flow_error *error)
2257 const struct rte_flow_item_vlan *mask = item->mask;
2258 const struct rte_flow_item_vlan nic_mask = {
2259 .tci = RTE_BE16(UINT16_MAX),
2260 .inner_type = RTE_BE16(UINT16_MAX),
2263 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2265 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2266 MLX5_FLOW_LAYER_INNER_L4) :
2267 (MLX5_FLOW_LAYER_OUTER_L3 |
2268 MLX5_FLOW_LAYER_OUTER_L4);
2269 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2270 MLX5_FLOW_LAYER_OUTER_VLAN;
2272 if (item_flags & vlanm)
2273 return rte_flow_error_set(error, EINVAL,
2274 RTE_FLOW_ERROR_TYPE_ITEM, item,
2275 "multiple VLAN layers not supported");
2276 else if ((item_flags & l34m) != 0)
2277 return rte_flow_error_set(error, EINVAL,
2278 RTE_FLOW_ERROR_TYPE_ITEM, item,
2279 "VLAN cannot follow L3/L4 layer");
2281 mask = &rte_flow_item_vlan_mask;
2282 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2283 (const uint8_t *)&nic_mask,
2284 sizeof(struct rte_flow_item_vlan),
2285 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2288 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2289 struct mlx5_priv *priv = dev->data->dev_private;
2291 if (priv->vmwa_context) {
2293 * Non-NULL context means we have a virtual machine
2294 * and SR-IOV enabled, we have to create VLAN interface
2295 * to make hypervisor to setup E-Switch vport
2296 * context correctly. We avoid creating the multiple
2297 * VLAN interfaces, so we cannot support VLAN tag mask.
2299 return rte_flow_error_set(error, EINVAL,
2300 RTE_FLOW_ERROR_TYPE_ITEM,
2302 "VLAN tag mask is not"
2303 " supported in virtual"
2311 * GTP flags are contained in 1 byte of the format:
2312 * -------------------------------------------
2313 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2314 * |-----------------------------------------|
2315 * | value | Version | PT | Res | E | S | PN |
2316 * -------------------------------------------
2318 * Matching is supported only for GTP flags E, S, PN.
2320 #define MLX5_GTP_FLAGS_MASK 0x07
2323 * Validate GTP item.
2326 * Pointer to the rte_eth_dev structure.
2328 * Item specification.
2329 * @param[in] item_flags
2330 * Bit-fields that holds the items detected until now.
2332 * Pointer to error structure.
2335 * 0 on success, a negative errno value otherwise and rte_errno is set.
2338 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2339 const struct rte_flow_item *item,
2340 uint64_t item_flags,
2341 struct rte_flow_error *error)
2343 struct mlx5_priv *priv = dev->data->dev_private;
2344 const struct rte_flow_item_gtp *spec = item->spec;
2345 const struct rte_flow_item_gtp *mask = item->mask;
2346 const struct rte_flow_item_gtp nic_mask = {
2347 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
2349 .teid = RTE_BE32(0xffffffff),
2352 if (!priv->config.hca_attr.tunnel_stateless_gtp)
2353 return rte_flow_error_set(error, ENOTSUP,
2354 RTE_FLOW_ERROR_TYPE_ITEM, item,
2355 "GTP support is not enabled");
2356 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2357 return rte_flow_error_set(error, ENOTSUP,
2358 RTE_FLOW_ERROR_TYPE_ITEM, item,
2359 "multiple tunnel layers not"
2361 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2362 return rte_flow_error_set(error, EINVAL,
2363 RTE_FLOW_ERROR_TYPE_ITEM, item,
2364 "no outer UDP layer found");
2366 mask = &rte_flow_item_gtp_mask;
2367 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
2368 return rte_flow_error_set(error, ENOTSUP,
2369 RTE_FLOW_ERROR_TYPE_ITEM, item,
2370 "Match is supported for GTP"
2372 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2373 (const uint8_t *)&nic_mask,
2374 sizeof(struct rte_flow_item_gtp),
2375 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2379 * Validate GTP PSC item.
2382 * Item specification.
2383 * @param[in] last_item
2384 * Previous validated item in the pattern items.
2385 * @param[in] gtp_item
2386 * Previous GTP item specification.
2388 * Pointer to flow attributes.
2390 * Pointer to error structure.
2393 * 0 on success, a negative errno value otherwise and rte_errno is set.
2396 flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2398 const struct rte_flow_item *gtp_item,
2399 const struct rte_flow_attr *attr,
2400 struct rte_flow_error *error)
2402 const struct rte_flow_item_gtp *gtp_spec;
2403 const struct rte_flow_item_gtp *gtp_mask;
2404 const struct rte_flow_item_gtp_psc *spec;
2405 const struct rte_flow_item_gtp_psc *mask;
2406 const struct rte_flow_item_gtp_psc nic_mask = {
2411 if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2412 return rte_flow_error_set
2413 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2414 "GTP PSC item must be preceded with GTP item");
2415 gtp_spec = gtp_item->spec;
2416 gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2417 /* GTP spec and E flag is requested to match zero. */
2419 (gtp_mask->v_pt_rsv_flags &
2420 ~gtp_spec->v_pt_rsv_flags & MLX5_GTP_EXT_HEADER_FLAG))
2421 return rte_flow_error_set
2422 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2423 "GTP E flag must be 1 to match GTP PSC");
2424 /* Check the flow is not created in group zero. */
2425 if (!attr->transfer && !attr->group)
2426 return rte_flow_error_set
2427 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2428 "GTP PSC is not supported for group 0");
2429 /* GTP spec is here and E flag is requested to match zero. */
2433 mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2434 if (spec->pdu_type > MLX5_GTP_EXT_MAX_PDU_TYPE)
2435 return rte_flow_error_set
2436 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2437 "PDU type should be smaller than 16");
2438 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2439 (const uint8_t *)&nic_mask,
2440 sizeof(struct rte_flow_item_gtp_psc),
2441 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2445 * Validate IPV4 item.
2446 * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2447 * add specific validation of fragment_offset field,
2450 * Item specification.
2451 * @param[in] item_flags
2452 * Bit-fields that holds the items detected until now.
2454 * Pointer to error structure.
2457 * 0 on success, a negative errno value otherwise and rte_errno is set.
2460 flow_dv_validate_item_ipv4(const struct rte_flow_item *item,
2461 uint64_t item_flags,
2463 uint16_t ether_type,
2464 struct rte_flow_error *error)
2467 const struct rte_flow_item_ipv4 *spec = item->spec;
2468 const struct rte_flow_item_ipv4 *last = item->last;
2469 const struct rte_flow_item_ipv4 *mask = item->mask;
2470 rte_be16_t fragment_offset_spec = 0;
2471 rte_be16_t fragment_offset_last = 0;
2472 const struct rte_flow_item_ipv4 nic_ipv4_mask = {
2474 .src_addr = RTE_BE32(0xffffffff),
2475 .dst_addr = RTE_BE32(0xffffffff),
2476 .type_of_service = 0xff,
2477 .fragment_offset = RTE_BE16(0xffff),
2478 .next_proto_id = 0xff,
2479 .time_to_live = 0xff,
2483 ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2484 ether_type, &nic_ipv4_mask,
2485 MLX5_ITEM_RANGE_ACCEPTED, error);
2489 fragment_offset_spec = spec->hdr.fragment_offset &
2490 mask->hdr.fragment_offset;
2491 if (!fragment_offset_spec)
2494 * spec and mask are valid, enforce using full mask to make sure the
2495 * complete value is used correctly.
2497 if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2498 != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2499 return rte_flow_error_set(error, EINVAL,
2500 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2501 item, "must use full mask for"
2502 " fragment_offset");
2504 * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
2505 * indicating this is 1st fragment of fragmented packet.
2506 * This is not yet supported in MLX5, return appropriate error message.
2508 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
2509 return rte_flow_error_set(error, ENOTSUP,
2510 RTE_FLOW_ERROR_TYPE_ITEM, item,
2511 "match on first fragment not "
2513 if (fragment_offset_spec && !last)
2514 return rte_flow_error_set(error, ENOTSUP,
2515 RTE_FLOW_ERROR_TYPE_ITEM, item,
2516 "specified value not supported");
2517 /* spec and last are valid, validate the specified range. */
2518 fragment_offset_last = last->hdr.fragment_offset &
2519 mask->hdr.fragment_offset;
2521 * Match on fragment_offset spec 0x2001 and last 0x3fff
2522 * means MF is 1 and frag-offset is > 0.
2523 * This packet is fragment 2nd and onward, excluding last.
2524 * This is not yet supported in MLX5, return appropriate
2527 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
2528 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2529 return rte_flow_error_set(error, ENOTSUP,
2530 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2531 last, "match on following "
2532 "fragments not supported");
2534 * Match on fragment_offset spec 0x0001 and last 0x1fff
2535 * means MF is 0 and frag-offset is > 0.
2536 * This packet is last fragment of fragmented packet.
2537 * This is not yet supported in MLX5, return appropriate
2540 if (fragment_offset_spec == RTE_BE16(1) &&
2541 fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
2542 return rte_flow_error_set(error, ENOTSUP,
2543 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2544 last, "match on last "
2545 "fragment not supported");
2547 * Match on fragment_offset spec 0x0001 and last 0x3fff
2548 * means MF and/or frag-offset is not 0.
2549 * This is a fragmented packet.
2550 * Other range values are invalid and rejected.
2552 if (!(fragment_offset_spec == RTE_BE16(1) &&
2553 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
2554 return rte_flow_error_set(error, ENOTSUP,
2555 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2556 "specified range not supported");
2561 * Validate IPV6 fragment extension item.
2564 * Item specification.
2565 * @param[in] item_flags
2566 * Bit-fields that holds the items detected until now.
2568 * Pointer to error structure.
2571 * 0 on success, a negative errno value otherwise and rte_errno is set.
2574 flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
2575 uint64_t item_flags,
2576 struct rte_flow_error *error)
2578 const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
2579 const struct rte_flow_item_ipv6_frag_ext *last = item->last;
2580 const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
2581 rte_be16_t frag_data_spec = 0;
2582 rte_be16_t frag_data_last = 0;
2583 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2584 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2585 MLX5_FLOW_LAYER_OUTER_L4;
2587 struct rte_flow_item_ipv6_frag_ext nic_mask = {
2589 .next_header = 0xff,
2590 .frag_data = RTE_BE16(0xffff),
2594 if (item_flags & l4m)
2595 return rte_flow_error_set(error, EINVAL,
2596 RTE_FLOW_ERROR_TYPE_ITEM, item,
2597 "ipv6 fragment extension item cannot "
2599 if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
2600 (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
2601 return rte_flow_error_set(error, EINVAL,
2602 RTE_FLOW_ERROR_TYPE_ITEM, item,
2603 "ipv6 fragment extension item must "
2604 "follow ipv6 item");
2606 frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
2607 if (!frag_data_spec)
2610 * spec and mask are valid, enforce using full mask to make sure the
2611 * complete value is used correctly.
2613 if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
2614 RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2615 return rte_flow_error_set(error, EINVAL,
2616 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2617 item, "must use full mask for"
2620 * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2621 * This is 1st fragment of fragmented packet.
2623 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2624 return rte_flow_error_set(error, ENOTSUP,
2625 RTE_FLOW_ERROR_TYPE_ITEM, item,
2626 "match on first fragment not "
2628 if (frag_data_spec && !last)
2629 return rte_flow_error_set(error, EINVAL,
2630 RTE_FLOW_ERROR_TYPE_ITEM, item,
2631 "specified value not supported");
2632 ret = mlx5_flow_item_acceptable
2633 (item, (const uint8_t *)mask,
2634 (const uint8_t *)&nic_mask,
2635 sizeof(struct rte_flow_item_ipv6_frag_ext),
2636 MLX5_ITEM_RANGE_ACCEPTED, error);
2639 /* spec and last are valid, validate the specified range. */
2640 frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2642 * Match on frag_data spec 0x0009 and last 0xfff9
2643 * means M is 1 and frag-offset is > 0.
2644 * This packet is fragment 2nd and onward, excluding last.
2645 * This is not yet supported in MLX5, return appropriate
2648 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2649 RTE_IPV6_EHDR_MF_MASK) &&
2650 frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2651 return rte_flow_error_set(error, ENOTSUP,
2652 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2653 last, "match on following "
2654 "fragments not supported");
2656 * Match on frag_data spec 0x0008 and last 0xfff8
2657 * means M is 0 and frag-offset is > 0.
2658 * This packet is last fragment of fragmented packet.
2659 * This is not yet supported in MLX5, return appropriate
2662 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2663 frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2664 return rte_flow_error_set(error, ENOTSUP,
2665 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2666 last, "match on last "
2667 "fragment not supported");
2668 /* Other range values are invalid and rejected. */
2669 return rte_flow_error_set(error, EINVAL,
2670 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2671 "specified range not supported");
2675 * Validate ASO CT item.
2678 * Pointer to the rte_eth_dev structure.
2680 * Item specification.
2681 * @param[in] item_flags
2682 * Pointer to bit-fields that holds the items detected until now.
2684 * Pointer to error structure.
2687 * 0 on success, a negative errno value otherwise and rte_errno is set.
2690 flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
2691 const struct rte_flow_item *item,
2692 uint64_t *item_flags,
2693 struct rte_flow_error *error)
2695 const struct rte_flow_item_conntrack *spec = item->spec;
2696 const struct rte_flow_item_conntrack *mask = item->mask;
2700 if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
2701 return rte_flow_error_set(error, EINVAL,
2702 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2703 "Only one CT is supported");
2705 mask = &rte_flow_item_conntrack_mask;
2706 flags = spec->flags & mask->flags;
2707 if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
2708 ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
2709 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
2710 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
2711 return rte_flow_error_set(error, EINVAL,
2712 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2713 "Conflict status bits");
2714 /* State change also needs to be considered. */
2715 *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
2720 * Validate the pop VLAN action.
2723 * Pointer to the rte_eth_dev structure.
2724 * @param[in] action_flags
2725 * Holds the actions detected until now.
2727 * Pointer to the pop vlan action.
2728 * @param[in] item_flags
2729 * The items found in this flow rule.
2731 * Pointer to flow attributes.
2733 * Pointer to error structure.
2736 * 0 on success, a negative errno value otherwise and rte_errno is set.
2739 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
2740 uint64_t action_flags,
2741 const struct rte_flow_action *action,
2742 uint64_t item_flags,
2743 const struct rte_flow_attr *attr,
2744 struct rte_flow_error *error)
2746 const struct mlx5_priv *priv = dev->data->dev_private;
2750 if (!priv->sh->pop_vlan_action)
2751 return rte_flow_error_set(error, ENOTSUP,
2752 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2754 "pop vlan action is not supported");
2756 return rte_flow_error_set(error, ENOTSUP,
2757 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2759 "pop vlan action not supported for "
2761 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
2762 return rte_flow_error_set(error, ENOTSUP,
2763 RTE_FLOW_ERROR_TYPE_ACTION, action,
2764 "no support for multiple VLAN "
2766 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
2767 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
2768 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
2769 return rte_flow_error_set(error, ENOTSUP,
2770 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2772 "cannot pop vlan after decap without "
2773 "match on inner vlan in the flow");
2774 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
2775 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
2776 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2777 return rte_flow_error_set(error, ENOTSUP,
2778 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2780 "cannot pop vlan without a "
2781 "match on (outer) vlan in the flow");
2782 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2783 return rte_flow_error_set(error, EINVAL,
2784 RTE_FLOW_ERROR_TYPE_ACTION, action,
2785 "wrong action order, port_id should "
2786 "be after pop VLAN action");
2787 if (!attr->transfer && priv->representor)
2788 return rte_flow_error_set(error, ENOTSUP,
2789 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2790 "pop vlan action for VF representor "
2791 "not supported on NIC table");
2796 * Get VLAN default info from vlan match info.
2799 * the list of item specifications.
2801 * pointer VLAN info to fill to.
2804 * 0 on success, a negative errno value otherwise and rte_errno is set.
2807 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
2808 struct rte_vlan_hdr *vlan)
2810 const struct rte_flow_item_vlan nic_mask = {
2811 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
2812 MLX5DV_FLOW_VLAN_VID_MASK),
2813 .inner_type = RTE_BE16(0xffff),
2818 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2819 int type = items->type;
2821 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
2822 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
2825 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
2826 const struct rte_flow_item_vlan *vlan_m = items->mask;
2827 const struct rte_flow_item_vlan *vlan_v = items->spec;
2829 /* If VLAN item in pattern doesn't contain data, return here. */
2834 /* Only full match values are accepted */
2835 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
2836 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
2837 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
2839 rte_be_to_cpu_16(vlan_v->tci &
2840 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
2842 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
2843 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
2844 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
2846 rte_be_to_cpu_16(vlan_v->tci &
2847 MLX5DV_FLOW_VLAN_VID_MASK_BE);
2849 if (vlan_m->inner_type == nic_mask.inner_type)
2850 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
2851 vlan_m->inner_type);
2856 * Validate the push VLAN action.
2859 * Pointer to the rte_eth_dev structure.
2860 * @param[in] action_flags
2861 * Holds the actions detected until now.
2862 * @param[in] item_flags
2863 * The items found in this flow rule.
2865 * Pointer to the action structure.
2867 * Pointer to flow attributes
2869 * Pointer to error structure.
2872 * 0 on success, a negative errno value otherwise and rte_errno is set.
2875 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
2876 uint64_t action_flags,
2877 const struct rte_flow_item_vlan *vlan_m,
2878 const struct rte_flow_action *action,
2879 const struct rte_flow_attr *attr,
2880 struct rte_flow_error *error)
2882 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
2883 const struct mlx5_priv *priv = dev->data->dev_private;
2885 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
2886 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
2887 return rte_flow_error_set(error, EINVAL,
2888 RTE_FLOW_ERROR_TYPE_ACTION, action,
2889 "invalid vlan ethertype");
2890 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2891 return rte_flow_error_set(error, EINVAL,
2892 RTE_FLOW_ERROR_TYPE_ACTION, action,
2893 "wrong action order, port_id should "
2894 "be after push VLAN");
2895 if (!attr->transfer && priv->representor)
2896 return rte_flow_error_set(error, ENOTSUP,
2897 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2898 "push vlan action for VF representor "
2899 "not supported on NIC table");
2901 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
2902 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
2903 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
2904 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
2905 !(mlx5_flow_find_action
2906 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
2907 return rte_flow_error_set(error, EINVAL,
2908 RTE_FLOW_ERROR_TYPE_ACTION, action,
2909 "not full match mask on VLAN PCP and "
2910 "there is no of_set_vlan_pcp action, "
2911 "push VLAN action cannot figure out "
2914 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
2915 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
2916 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
2917 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
2918 !(mlx5_flow_find_action
2919 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
2920 return rte_flow_error_set(error, EINVAL,
2921 RTE_FLOW_ERROR_TYPE_ACTION, action,
2922 "not full match mask on VLAN VID and "
2923 "there is no of_set_vlan_vid action, "
2924 "push VLAN action cannot figure out "
2931 * Validate the set VLAN PCP.
2933 * @param[in] action_flags
2934 * Holds the actions detected until now.
2935 * @param[in] actions
2936 * Pointer to the list of actions remaining in the flow rule.
2938 * Pointer to error structure.
2941 * 0 on success, a negative errno value otherwise and rte_errno is set.
2944 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2945 const struct rte_flow_action actions[],
2946 struct rte_flow_error *error)
2948 const struct rte_flow_action *action = actions;
2949 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2951 if (conf->vlan_pcp > 7)
2952 return rte_flow_error_set(error, EINVAL,
2953 RTE_FLOW_ERROR_TYPE_ACTION, action,
2954 "VLAN PCP value is too big");
2955 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2956 return rte_flow_error_set(error, ENOTSUP,
2957 RTE_FLOW_ERROR_TYPE_ACTION, action,
2958 "set VLAN PCP action must follow "
2959 "the push VLAN action");
2960 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2961 return rte_flow_error_set(error, ENOTSUP,
2962 RTE_FLOW_ERROR_TYPE_ACTION, action,
2963 "Multiple VLAN PCP modification are "
2965 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2966 return rte_flow_error_set(error, EINVAL,
2967 RTE_FLOW_ERROR_TYPE_ACTION, action,
2968 "wrong action order, port_id should "
2969 "be after set VLAN PCP");
2974 * Validate the set VLAN VID.
2976 * @param[in] item_flags
2977 * Holds the items detected in this rule.
2978 * @param[in] action_flags
2979 * Holds the actions detected until now.
2980 * @param[in] actions
2981 * Pointer to the list of actions remaining in the flow rule.
2983 * Pointer to error structure.
2986 * 0 on success, a negative errno value otherwise and rte_errno is set.
2989 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2990 uint64_t action_flags,
2991 const struct rte_flow_action actions[],
2992 struct rte_flow_error *error)
2994 const struct rte_flow_action *action = actions;
2995 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
2997 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
2998 return rte_flow_error_set(error, EINVAL,
2999 RTE_FLOW_ERROR_TYPE_ACTION, action,
3000 "VLAN VID value is too big");
3001 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3002 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3003 return rte_flow_error_set(error, ENOTSUP,
3004 RTE_FLOW_ERROR_TYPE_ACTION, action,
3005 "set VLAN VID action must follow push"
3006 " VLAN action or match on VLAN item");
3007 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3008 return rte_flow_error_set(error, ENOTSUP,
3009 RTE_FLOW_ERROR_TYPE_ACTION, action,
3010 "Multiple VLAN VID modifications are "
3012 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3013 return rte_flow_error_set(error, EINVAL,
3014 RTE_FLOW_ERROR_TYPE_ACTION, action,
3015 "wrong action order, port_id should "
3016 "be after set VLAN VID");
3021 * Validate the FLAG action.
3024 * Pointer to the rte_eth_dev structure.
3025 * @param[in] action_flags
3026 * Holds the actions detected until now.
3028 * Pointer to flow attributes
3030 * Pointer to error structure.
3033 * 0 on success, a negative errno value otherwise and rte_errno is set.
3036 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3037 uint64_t action_flags,
3038 const struct rte_flow_attr *attr,
3039 struct rte_flow_error *error)
3041 struct mlx5_priv *priv = dev->data->dev_private;
3042 struct mlx5_dev_config *config = &priv->config;
3045 /* Fall back if no extended metadata register support. */
3046 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3047 return mlx5_flow_validate_action_flag(action_flags, attr,
3049 /* Extensive metadata mode requires registers. */
3050 if (!mlx5_flow_ext_mreg_supported(dev))
3051 return rte_flow_error_set(error, ENOTSUP,
3052 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3053 "no metadata registers "
3054 "to support flag action");
3055 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3056 return rte_flow_error_set(error, ENOTSUP,
3057 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3058 "extended metadata register"
3059 " isn't available");
3060 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3063 MLX5_ASSERT(ret > 0);
3064 if (action_flags & MLX5_FLOW_ACTION_MARK)
3065 return rte_flow_error_set(error, EINVAL,
3066 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3067 "can't mark and flag in same flow");
3068 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3069 return rte_flow_error_set(error, EINVAL,
3070 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3072 " actions in same flow");
3077 * Validate MARK action.
3080 * Pointer to the rte_eth_dev structure.
3082 * Pointer to action.
3083 * @param[in] action_flags
3084 * Holds the actions detected until now.
3086 * Pointer to flow attributes
3088 * Pointer to error structure.
3091 * 0 on success, a negative errno value otherwise and rte_errno is set.
3094 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3095 const struct rte_flow_action *action,
3096 uint64_t action_flags,
3097 const struct rte_flow_attr *attr,
3098 struct rte_flow_error *error)
3100 struct mlx5_priv *priv = dev->data->dev_private;
3101 struct mlx5_dev_config *config = &priv->config;
3102 const struct rte_flow_action_mark *mark = action->conf;
3105 if (is_tunnel_offload_active(dev))
3106 return rte_flow_error_set(error, ENOTSUP,
3107 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3109 "if tunnel offload active");
3110 /* Fall back if no extended metadata register support. */
3111 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3112 return mlx5_flow_validate_action_mark(action, action_flags,
3114 /* Extensive metadata mode requires registers. */
3115 if (!mlx5_flow_ext_mreg_supported(dev))
3116 return rte_flow_error_set(error, ENOTSUP,
3117 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3118 "no metadata registers "
3119 "to support mark action");
3120 if (!priv->sh->dv_mark_mask)
3121 return rte_flow_error_set(error, ENOTSUP,
3122 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3123 "extended metadata register"
3124 " isn't available");
3125 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3128 MLX5_ASSERT(ret > 0);
3130 return rte_flow_error_set(error, EINVAL,
3131 RTE_FLOW_ERROR_TYPE_ACTION, action,
3132 "configuration cannot be null");
3133 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3134 return rte_flow_error_set(error, EINVAL,
3135 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3137 "mark id exceeds the limit");
3138 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3139 return rte_flow_error_set(error, EINVAL,
3140 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3141 "can't flag and mark in same flow");
3142 if (action_flags & MLX5_FLOW_ACTION_MARK)
3143 return rte_flow_error_set(error, EINVAL,
3144 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3145 "can't have 2 mark actions in same"
3151 * Validate SET_META action.
3154 * Pointer to the rte_eth_dev structure.
3156 * Pointer to the action structure.
3157 * @param[in] action_flags
3158 * Holds the actions detected until now.
3160 * Pointer to flow attributes
3162 * Pointer to error structure.
3165 * 0 on success, a negative errno value otherwise and rte_errno is set.
3168 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3169 const struct rte_flow_action *action,
3170 uint64_t action_flags __rte_unused,
3171 const struct rte_flow_attr *attr,
3172 struct rte_flow_error *error)
3174 const struct rte_flow_action_set_meta *conf;
3175 uint32_t nic_mask = UINT32_MAX;
3178 if (!mlx5_flow_ext_mreg_supported(dev))
3179 return rte_flow_error_set(error, ENOTSUP,
3180 RTE_FLOW_ERROR_TYPE_ACTION, action,
3181 "extended metadata register"
3182 " isn't supported");
3183 reg = flow_dv_get_metadata_reg(dev, attr, error);
3187 return rte_flow_error_set(error, ENOTSUP,
3188 RTE_FLOW_ERROR_TYPE_ACTION, action,
3189 "unavalable extended metadata register");
3190 if (reg != REG_A && reg != REG_B) {
3191 struct mlx5_priv *priv = dev->data->dev_private;
3193 nic_mask = priv->sh->dv_meta_mask;
3195 if (!(action->conf))
3196 return rte_flow_error_set(error, EINVAL,
3197 RTE_FLOW_ERROR_TYPE_ACTION, action,
3198 "configuration cannot be null");
3199 conf = (const struct rte_flow_action_set_meta *)action->conf;
3201 return rte_flow_error_set(error, EINVAL,
3202 RTE_FLOW_ERROR_TYPE_ACTION, action,
3203 "zero mask doesn't have any effect");
3204 if (conf->mask & ~nic_mask)
3205 return rte_flow_error_set(error, EINVAL,
3206 RTE_FLOW_ERROR_TYPE_ACTION, action,
3207 "meta data must be within reg C0");
3212 * Validate SET_TAG action.
3215 * Pointer to the rte_eth_dev structure.
3217 * Pointer to the action structure.
3218 * @param[in] action_flags
3219 * Holds the actions detected until now.
3221 * Pointer to flow attributes
3223 * Pointer to error structure.
3226 * 0 on success, a negative errno value otherwise and rte_errno is set.
3229 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3230 const struct rte_flow_action *action,
3231 uint64_t action_flags,
3232 const struct rte_flow_attr *attr,
3233 struct rte_flow_error *error)
3235 const struct rte_flow_action_set_tag *conf;
3236 const uint64_t terminal_action_flags =
3237 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3238 MLX5_FLOW_ACTION_RSS;
3241 if (!mlx5_flow_ext_mreg_supported(dev))
3242 return rte_flow_error_set(error, ENOTSUP,
3243 RTE_FLOW_ERROR_TYPE_ACTION, action,
3244 "extensive metadata register"
3245 " isn't supported");
3246 if (!(action->conf))
3247 return rte_flow_error_set(error, EINVAL,
3248 RTE_FLOW_ERROR_TYPE_ACTION, action,
3249 "configuration cannot be null");
3250 conf = (const struct rte_flow_action_set_tag *)action->conf;
3252 return rte_flow_error_set(error, EINVAL,
3253 RTE_FLOW_ERROR_TYPE_ACTION, action,
3254 "zero mask doesn't have any effect");
3255 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3258 if (!attr->transfer && attr->ingress &&
3259 (action_flags & terminal_action_flags))
3260 return rte_flow_error_set(error, EINVAL,
3261 RTE_FLOW_ERROR_TYPE_ACTION, action,
3262 "set_tag has no effect"
3263 " with terminal actions");
3268 * Check if action counter is shared by either old or new mechanism.
3271 * Pointer to the action structure.
3274 * True when counter is shared, false otherwise.
3277 is_shared_action_count(const struct rte_flow_action *action)
3279 const struct rte_flow_action_count *count =
3280 (const struct rte_flow_action_count *)action->conf;
3282 if ((int)action->type == MLX5_RTE_FLOW_ACTION_TYPE_COUNT)
3284 return !!(count && count->shared);
3288 * Validate count action.
3291 * Pointer to rte_eth_dev structure.
3293 * Indicator if action is shared.
3294 * @param[in] action_flags
3295 * Holds the actions detected until now.
3297 * Pointer to error structure.
3300 * 0 on success, a negative errno value otherwise and rte_errno is set.
3303 flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3304 uint64_t action_flags,
3305 struct rte_flow_error *error)
3307 struct mlx5_priv *priv = dev->data->dev_private;
3309 if (!priv->config.devx)
3311 if (action_flags & MLX5_FLOW_ACTION_COUNT)
3312 return rte_flow_error_set(error, EINVAL,
3313 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3314 "duplicate count actions set");
3315 if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
3316 !priv->sh->flow_hit_aso_en)
3317 return rte_flow_error_set(error, EINVAL,
3318 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3319 "old age and shared count combination is not supported");
3320 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3324 return rte_flow_error_set
3326 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3328 "count action not supported");
3332 * Validate the L2 encap action.
3335 * Pointer to the rte_eth_dev structure.
3336 * @param[in] action_flags
3337 * Holds the actions detected until now.
3339 * Pointer to the action structure.
3341 * Pointer to flow attributes.
3343 * Pointer to error structure.
3346 * 0 on success, a negative errno value otherwise and rte_errno is set.
3349 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3350 uint64_t action_flags,
3351 const struct rte_flow_action *action,
3352 const struct rte_flow_attr *attr,
3353 struct rte_flow_error *error)
3355 const struct mlx5_priv *priv = dev->data->dev_private;
3357 if (!(action->conf))
3358 return rte_flow_error_set(error, EINVAL,
3359 RTE_FLOW_ERROR_TYPE_ACTION, action,
3360 "configuration cannot be null");
3361 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3362 return rte_flow_error_set(error, EINVAL,
3363 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3364 "can only have a single encap action "
3366 if (!attr->transfer && priv->representor)
3367 return rte_flow_error_set(error, ENOTSUP,
3368 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3369 "encap action for VF representor "
3370 "not supported on NIC table");
3375 * Validate a decap action.
3378 * Pointer to the rte_eth_dev structure.
3379 * @param[in] action_flags
3380 * Holds the actions detected until now.
3382 * Pointer to the action structure.
3383 * @param[in] item_flags
3384 * Holds the items detected.
3386 * Pointer to flow attributes
3388 * Pointer to error structure.
3391 * 0 on success, a negative errno value otherwise and rte_errno is set.
3394 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3395 uint64_t action_flags,
3396 const struct rte_flow_action *action,
3397 const uint64_t item_flags,
3398 const struct rte_flow_attr *attr,
3399 struct rte_flow_error *error)
3401 const struct mlx5_priv *priv = dev->data->dev_private;
3403 if (priv->config.hca_attr.scatter_fcs_w_decap_disable &&
3404 !priv->config.decap_en)
3405 return rte_flow_error_set(error, ENOTSUP,
3406 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3407 "decap is not enabled");
3408 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3409 return rte_flow_error_set(error, ENOTSUP,
3410 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3412 MLX5_FLOW_ACTION_DECAP ? "can only "
3413 "have a single decap action" : "decap "
3414 "after encap is not supported");
3415 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3416 return rte_flow_error_set(error, EINVAL,
3417 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3418 "can't have decap action after"
3421 return rte_flow_error_set(error, ENOTSUP,
3422 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3424 "decap action not supported for "
3426 if (!attr->transfer && priv->representor)
3427 return rte_flow_error_set(error, ENOTSUP,
3428 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3429 "decap action for VF representor "
3430 "not supported on NIC table");
3431 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3432 !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3433 return rte_flow_error_set(error, ENOTSUP,
3434 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3435 "VXLAN item should be present for VXLAN decap");
3439 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3442 * Validate the raw encap and decap actions.
3445 * Pointer to the rte_eth_dev structure.
3447 * Pointer to the decap action.
3449 * Pointer to the encap action.
3451 * Pointer to flow attributes
3452 * @param[in/out] action_flags
3453 * Holds the actions detected until now.
3454 * @param[out] actions_n
3455 * pointer to the number of actions counter.
3457 * Pointer to the action structure.
3458 * @param[in] item_flags
3459 * Holds the items detected.
3461 * Pointer to error structure.
3464 * 0 on success, a negative errno value otherwise and rte_errno is set.
3467 flow_dv_validate_action_raw_encap_decap
3468 (struct rte_eth_dev *dev,
3469 const struct rte_flow_action_raw_decap *decap,
3470 const struct rte_flow_action_raw_encap *encap,
3471 const struct rte_flow_attr *attr, uint64_t *action_flags,
3472 int *actions_n, const struct rte_flow_action *action,
3473 uint64_t item_flags, struct rte_flow_error *error)
3475 const struct mlx5_priv *priv = dev->data->dev_private;
3478 if (encap && (!encap->size || !encap->data))
3479 return rte_flow_error_set(error, EINVAL,
3480 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3481 "raw encap data cannot be empty");
3482 if (decap && encap) {
3483 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3484 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3487 else if (encap->size <=
3488 MLX5_ENCAPSULATION_DECISION_SIZE &&
3490 MLX5_ENCAPSULATION_DECISION_SIZE)
3493 else if (encap->size >
3494 MLX5_ENCAPSULATION_DECISION_SIZE &&
3496 MLX5_ENCAPSULATION_DECISION_SIZE)
3497 /* 2 L2 actions: encap and decap. */
3500 return rte_flow_error_set(error,
3502 RTE_FLOW_ERROR_TYPE_ACTION,
3503 NULL, "unsupported too small "
3504 "raw decap and too small raw "
3505 "encap combination");
3508 ret = flow_dv_validate_action_decap(dev, *action_flags, action,
3509 item_flags, attr, error);
3512 *action_flags |= MLX5_FLOW_ACTION_DECAP;
3516 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
3517 return rte_flow_error_set(error, ENOTSUP,
3518 RTE_FLOW_ERROR_TYPE_ACTION,
3520 "small raw encap size");
3521 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
3522 return rte_flow_error_set(error, EINVAL,
3523 RTE_FLOW_ERROR_TYPE_ACTION,
3525 "more than one encap action");
3526 if (!attr->transfer && priv->representor)
3527 return rte_flow_error_set
3529 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3530 "encap action for VF representor "
3531 "not supported on NIC table");
3532 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
3539 * Validate the ASO CT action.
3542 * Pointer to the rte_eth_dev structure.
3543 * @param[in] action_flags
3544 * Holds the actions detected until now.
3545 * @param[in] item_flags
3546 * The items found in this flow rule.
3548 * Pointer to flow attributes.
3550 * Pointer to error structure.
3553 * 0 on success, a negative errno value otherwise and rte_errno is set.
3556 flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
3557 uint64_t action_flags,
3558 uint64_t item_flags,
3559 const struct rte_flow_attr *attr,
3560 struct rte_flow_error *error)
3564 if (attr->group == 0 && !attr->transfer)
3565 return rte_flow_error_set(error, ENOTSUP,
3566 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3568 "Only support non-root table");
3569 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
3570 return rte_flow_error_set(error, ENOTSUP,
3571 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3572 "CT cannot follow a fate action");
3573 if ((action_flags & MLX5_FLOW_ACTION_METER) ||
3574 (action_flags & MLX5_FLOW_ACTION_AGE))
3575 return rte_flow_error_set(error, EINVAL,
3576 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3577 "Only one ASO action is supported");
3578 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3579 return rte_flow_error_set(error, EINVAL,
3580 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3581 "Encap cannot exist before CT");
3582 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3583 return rte_flow_error_set(error, EINVAL,
3584 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3585 "Not a outer TCP packet");
3590 * Match encap_decap resource.
3593 * Pointer to the hash list.
3595 * Pointer to exist resource entry object.
3597 * Key of the new entry.
3599 * Pointer to new encap_decap resource.
3602 * 0 on matching, none-zero otherwise.
3605 flow_dv_encap_decap_match_cb(struct mlx5_hlist *list __rte_unused,
3606 struct mlx5_hlist_entry *entry,
3607 uint64_t key __rte_unused, void *cb_ctx)
3609 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3610 struct mlx5_flow_dv_encap_decap_resource *resource = ctx->data;
3611 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3613 cache_resource = container_of(entry,
3614 struct mlx5_flow_dv_encap_decap_resource,
3616 if (resource->reformat_type == cache_resource->reformat_type &&
3617 resource->ft_type == cache_resource->ft_type &&
3618 resource->flags == cache_resource->flags &&
3619 resource->size == cache_resource->size &&
3620 !memcmp((const void *)resource->buf,
3621 (const void *)cache_resource->buf,
3628 * Allocate encap_decap resource.
3631 * Pointer to the hash list.
3633 * Pointer to exist resource entry object.
3635 * Pointer to new encap_decap resource.
3638 * 0 on matching, none-zero otherwise.
3640 struct mlx5_hlist_entry *
3641 flow_dv_encap_decap_create_cb(struct mlx5_hlist *list,
3642 uint64_t key __rte_unused,
3645 struct mlx5_dev_ctx_shared *sh = list->ctx;
3646 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3647 struct mlx5dv_dr_domain *domain;
3648 struct mlx5_flow_dv_encap_decap_resource *resource = ctx->data;
3649 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3653 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3654 domain = sh->fdb_domain;
3655 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3656 domain = sh->rx_domain;
3658 domain = sh->tx_domain;
3659 /* Register new encap/decap resource. */
3660 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
3662 if (!cache_resource) {
3663 rte_flow_error_set(ctx->error, ENOMEM,
3664 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3665 "cannot allocate resource memory");
3668 *cache_resource = *resource;
3669 cache_resource->idx = idx;
3670 ret = mlx5_flow_os_create_flow_action_packet_reformat
3671 (sh->ctx, domain, cache_resource,
3672 &cache_resource->action);
3674 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
3675 rte_flow_error_set(ctx->error, ENOMEM,
3676 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3677 NULL, "cannot create action");
3681 return &cache_resource->entry;
3685 * Find existing encap/decap resource or create and register a new one.
3687 * @param[in, out] dev
3688 * Pointer to rte_eth_dev structure.
3689 * @param[in, out] resource
3690 * Pointer to encap/decap resource.
3691 * @parm[in, out] dev_flow
3692 * Pointer to the dev_flow.
3694 * pointer to error structure.
3697 * 0 on success otherwise -errno and errno is set.
3700 flow_dv_encap_decap_resource_register
3701 (struct rte_eth_dev *dev,
3702 struct mlx5_flow_dv_encap_decap_resource *resource,
3703 struct mlx5_flow *dev_flow,
3704 struct rte_flow_error *error)
3706 struct mlx5_priv *priv = dev->data->dev_private;
3707 struct mlx5_dev_ctx_shared *sh = priv->sh;
3708 struct mlx5_hlist_entry *entry;
3712 uint32_t refmt_type:8;
3714 * Header reformat actions can be shared between
3715 * non-root tables. One bit to indicate non-root
3719 uint32_t reserve:15;
3722 } encap_decap_key = {
3724 .ft_type = resource->ft_type,
3725 .refmt_type = resource->reformat_type,
3726 .is_root = !!dev_flow->dv.group,
3730 struct mlx5_flow_cb_ctx ctx = {
3736 resource->flags = dev_flow->dv.group ? 0 : 1;
3737 key64 = __rte_raw_cksum(&encap_decap_key.v32,
3738 sizeof(encap_decap_key.v32), 0);
3739 if (resource->reformat_type !=
3740 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
3742 key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
3743 entry = mlx5_hlist_register(sh->encaps_decaps, key64, &ctx);
3746 resource = container_of(entry, typeof(*resource), entry);
3747 dev_flow->dv.encap_decap = resource;
3748 dev_flow->handle->dvh.rix_encap_decap = resource->idx;
3753 * Find existing table jump resource or create and register a new one.
3755 * @param[in, out] dev
3756 * Pointer to rte_eth_dev structure.
3757 * @param[in, out] tbl
3758 * Pointer to flow table resource.
3759 * @parm[in, out] dev_flow
3760 * Pointer to the dev_flow.
3762 * pointer to error structure.
3765 * 0 on success otherwise -errno and errno is set.
3768 flow_dv_jump_tbl_resource_register
3769 (struct rte_eth_dev *dev __rte_unused,
3770 struct mlx5_flow_tbl_resource *tbl,
3771 struct mlx5_flow *dev_flow,
3772 struct rte_flow_error *error __rte_unused)
3774 struct mlx5_flow_tbl_data_entry *tbl_data =
3775 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
3778 MLX5_ASSERT(tbl_data->jump.action);
3779 dev_flow->handle->rix_jump = tbl_data->idx;
3780 dev_flow->dv.jump = &tbl_data->jump;
3785 flow_dv_port_id_match_cb(struct mlx5_cache_list *list __rte_unused,
3786 struct mlx5_cache_entry *entry, void *cb_ctx)
3788 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3789 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3790 struct mlx5_flow_dv_port_id_action_resource *res =
3791 container_of(entry, typeof(*res), entry);
3793 return ref->port_id != res->port_id;
3796 struct mlx5_cache_entry *
3797 flow_dv_port_id_create_cb(struct mlx5_cache_list *list,
3798 struct mlx5_cache_entry *entry __rte_unused,
3801 struct mlx5_dev_ctx_shared *sh = list->ctx;
3802 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3803 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3804 struct mlx5_flow_dv_port_id_action_resource *cache;
3808 /* Register new port id action resource. */
3809 cache = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3811 rte_flow_error_set(ctx->error, ENOMEM,
3812 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3813 "cannot allocate port_id action cache memory");
3817 ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
3821 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
3822 rte_flow_error_set(ctx->error, ENOMEM,
3823 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3824 "cannot create action");
3828 return &cache->entry;
3832 * Find existing table port ID resource or create and register a new one.
3834 * @param[in, out] dev
3835 * Pointer to rte_eth_dev structure.
3836 * @param[in, out] resource
3837 * Pointer to port ID action resource.
3838 * @parm[in, out] dev_flow
3839 * Pointer to the dev_flow.
3841 * pointer to error structure.
3844 * 0 on success otherwise -errno and errno is set.
3847 flow_dv_port_id_action_resource_register
3848 (struct rte_eth_dev *dev,
3849 struct mlx5_flow_dv_port_id_action_resource *resource,
3850 struct mlx5_flow *dev_flow,
3851 struct rte_flow_error *error)
3853 struct mlx5_priv *priv = dev->data->dev_private;
3854 struct mlx5_cache_entry *entry;
3855 struct mlx5_flow_dv_port_id_action_resource *cache;
3856 struct mlx5_flow_cb_ctx ctx = {
3861 entry = mlx5_cache_register(&priv->sh->port_id_action_list, &ctx);
3864 cache = container_of(entry, typeof(*cache), entry);
3865 dev_flow->dv.port_id_action = cache;
3866 dev_flow->handle->rix_port_id_action = cache->idx;
3871 flow_dv_push_vlan_match_cb(struct mlx5_cache_list *list __rte_unused,
3872 struct mlx5_cache_entry *entry, void *cb_ctx)
3874 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3875 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3876 struct mlx5_flow_dv_push_vlan_action_resource *res =
3877 container_of(entry, typeof(*res), entry);
3879 return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
3882 struct mlx5_cache_entry *
3883 flow_dv_push_vlan_create_cb(struct mlx5_cache_list *list,
3884 struct mlx5_cache_entry *entry __rte_unused,
3887 struct mlx5_dev_ctx_shared *sh = list->ctx;
3888 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3889 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3890 struct mlx5_flow_dv_push_vlan_action_resource *cache;
3891 struct mlx5dv_dr_domain *domain;
3895 /* Register new port id action resource. */
3896 cache = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3898 rte_flow_error_set(ctx->error, ENOMEM,
3899 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3900 "cannot allocate push_vlan action cache memory");
3904 if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3905 domain = sh->fdb_domain;
3906 else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3907 domain = sh->rx_domain;
3909 domain = sh->tx_domain;
3910 ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
3913 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
3914 rte_flow_error_set(ctx->error, ENOMEM,
3915 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3916 "cannot create push vlan action");
3920 return &cache->entry;
3924 * Find existing push vlan resource or create and register a new one.
3926 * @param [in, out] dev
3927 * Pointer to rte_eth_dev structure.
3928 * @param[in, out] resource
3929 * Pointer to port ID action resource.
3930 * @parm[in, out] dev_flow
3931 * Pointer to the dev_flow.
3933 * pointer to error structure.
3936 * 0 on success otherwise -errno and errno is set.
3939 flow_dv_push_vlan_action_resource_register
3940 (struct rte_eth_dev *dev,
3941 struct mlx5_flow_dv_push_vlan_action_resource *resource,
3942 struct mlx5_flow *dev_flow,
3943 struct rte_flow_error *error)
3945 struct mlx5_priv *priv = dev->data->dev_private;
3946 struct mlx5_flow_dv_push_vlan_action_resource *cache;
3947 struct mlx5_cache_entry *entry;
3948 struct mlx5_flow_cb_ctx ctx = {
3953 entry = mlx5_cache_register(&priv->sh->push_vlan_action_list, &ctx);
3956 cache = container_of(entry, typeof(*cache), entry);
3958 dev_flow->handle->dvh.rix_push_vlan = cache->idx;
3959 dev_flow->dv.push_vlan_res = cache;
3964 * Get the size of specific rte_flow_item_type hdr size
3966 * @param[in] item_type
3967 * Tested rte_flow_item_type.
3970 * sizeof struct item_type, 0 if void or irrelevant.
3973 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
3977 switch (item_type) {
3978 case RTE_FLOW_ITEM_TYPE_ETH:
3979 retval = sizeof(struct rte_ether_hdr);
3981 case RTE_FLOW_ITEM_TYPE_VLAN:
3982 retval = sizeof(struct rte_vlan_hdr);
3984 case RTE_FLOW_ITEM_TYPE_IPV4:
3985 retval = sizeof(struct rte_ipv4_hdr);
3987 case RTE_FLOW_ITEM_TYPE_IPV6:
3988 retval = sizeof(struct rte_ipv6_hdr);
3990 case RTE_FLOW_ITEM_TYPE_UDP:
3991 retval = sizeof(struct rte_udp_hdr);
3993 case RTE_FLOW_ITEM_TYPE_TCP:
3994 retval = sizeof(struct rte_tcp_hdr);
3996 case RTE_FLOW_ITEM_TYPE_VXLAN:
3997 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
3998 retval = sizeof(struct rte_vxlan_hdr);
4000 case RTE_FLOW_ITEM_TYPE_GRE:
4001 case RTE_FLOW_ITEM_TYPE_NVGRE:
4002 retval = sizeof(struct rte_gre_hdr);
4004 case RTE_FLOW_ITEM_TYPE_MPLS:
4005 retval = sizeof(struct rte_mpls_hdr);
4007 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4015 #define MLX5_ENCAP_IPV4_VERSION 0x40
4016 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4017 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4018 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4019 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4020 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4021 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4024 * Convert the encap action data from list of rte_flow_item to raw buffer
4027 * Pointer to rte_flow_item objects list.
4029 * Pointer to the output buffer.
4031 * Pointer to the output buffer size.
4033 * Pointer to the error structure.
4036 * 0 on success, a negative errno value otherwise and rte_errno is set.
4039 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4040 size_t *size, struct rte_flow_error *error)
4042 struct rte_ether_hdr *eth = NULL;
4043 struct rte_vlan_hdr *vlan = NULL;
4044 struct rte_ipv4_hdr *ipv4 = NULL;
4045 struct rte_ipv6_hdr *ipv6 = NULL;
4046 struct rte_udp_hdr *udp = NULL;
4047 struct rte_vxlan_hdr *vxlan = NULL;
4048 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4049 struct rte_gre_hdr *gre = NULL;
4051 size_t temp_size = 0;
4054 return rte_flow_error_set(error, EINVAL,
4055 RTE_FLOW_ERROR_TYPE_ACTION,
4056 NULL, "invalid empty data");
4057 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4058 len = flow_dv_get_item_hdr_len(items->type);
4059 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4060 return rte_flow_error_set(error, EINVAL,
4061 RTE_FLOW_ERROR_TYPE_ACTION,
4062 (void *)items->type,
4063 "items total size is too big"
4064 " for encap action");
4065 rte_memcpy((void *)&buf[temp_size], items->spec, len);
4066 switch (items->type) {
4067 case RTE_FLOW_ITEM_TYPE_ETH:
4068 eth = (struct rte_ether_hdr *)&buf[temp_size];
4070 case RTE_FLOW_ITEM_TYPE_VLAN:
4071 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4073 return rte_flow_error_set(error, EINVAL,
4074 RTE_FLOW_ERROR_TYPE_ACTION,
4075 (void *)items->type,
4076 "eth header not found");
4077 if (!eth->ether_type)
4078 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4080 case RTE_FLOW_ITEM_TYPE_IPV4:
4081 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4083 return rte_flow_error_set(error, EINVAL,
4084 RTE_FLOW_ERROR_TYPE_ACTION,
4085 (void *)items->type,
4086 "neither eth nor vlan"
4088 if (vlan && !vlan->eth_proto)
4089 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4090 else if (eth && !eth->ether_type)
4091 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4092 if (!ipv4->version_ihl)
4093 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4094 MLX5_ENCAP_IPV4_IHL_MIN;
4095 if (!ipv4->time_to_live)
4096 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4098 case RTE_FLOW_ITEM_TYPE_IPV6:
4099 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4101 return rte_flow_error_set(error, EINVAL,
4102 RTE_FLOW_ERROR_TYPE_ACTION,
4103 (void *)items->type,
4104 "neither eth nor vlan"
4106 if (vlan && !vlan->eth_proto)
4107 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4108 else if (eth && !eth->ether_type)
4109 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4110 if (!ipv6->vtc_flow)
4112 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4113 if (!ipv6->hop_limits)
4114 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4116 case RTE_FLOW_ITEM_TYPE_UDP:
4117 udp = (struct rte_udp_hdr *)&buf[temp_size];
4119 return rte_flow_error_set(error, EINVAL,
4120 RTE_FLOW_ERROR_TYPE_ACTION,
4121 (void *)items->type,
4122 "ip header not found");
4123 if (ipv4 && !ipv4->next_proto_id)
4124 ipv4->next_proto_id = IPPROTO_UDP;
4125 else if (ipv6 && !ipv6->proto)
4126 ipv6->proto = IPPROTO_UDP;
4128 case RTE_FLOW_ITEM_TYPE_VXLAN:
4129 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4131 return rte_flow_error_set(error, EINVAL,
4132 RTE_FLOW_ERROR_TYPE_ACTION,
4133 (void *)items->type,
4134 "udp header not found");
4136 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4137 if (!vxlan->vx_flags)
4139 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4141 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4142 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4144 return rte_flow_error_set(error, EINVAL,
4145 RTE_FLOW_ERROR_TYPE_ACTION,
4146 (void *)items->type,
4147 "udp header not found");
4148 if (!vxlan_gpe->proto)
4149 return rte_flow_error_set(error, EINVAL,
4150 RTE_FLOW_ERROR_TYPE_ACTION,
4151 (void *)items->type,
4152 "next protocol not found");
4155 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4156 if (!vxlan_gpe->vx_flags)
4157 vxlan_gpe->vx_flags =
4158 MLX5_ENCAP_VXLAN_GPE_FLAGS;
4160 case RTE_FLOW_ITEM_TYPE_GRE:
4161 case RTE_FLOW_ITEM_TYPE_NVGRE:
4162 gre = (struct rte_gre_hdr *)&buf[temp_size];
4164 return rte_flow_error_set(error, EINVAL,
4165 RTE_FLOW_ERROR_TYPE_ACTION,
4166 (void *)items->type,
4167 "next protocol not found");
4169 return rte_flow_error_set(error, EINVAL,
4170 RTE_FLOW_ERROR_TYPE_ACTION,
4171 (void *)items->type,
4172 "ip header not found");
4173 if (ipv4 && !ipv4->next_proto_id)
4174 ipv4->next_proto_id = IPPROTO_GRE;
4175 else if (ipv6 && !ipv6->proto)
4176 ipv6->proto = IPPROTO_GRE;
4178 case RTE_FLOW_ITEM_TYPE_VOID:
4181 return rte_flow_error_set(error, EINVAL,
4182 RTE_FLOW_ERROR_TYPE_ACTION,
4183 (void *)items->type,
4184 "unsupported item type");
4194 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4196 struct rte_ether_hdr *eth = NULL;
4197 struct rte_vlan_hdr *vlan = NULL;
4198 struct rte_ipv6_hdr *ipv6 = NULL;
4199 struct rte_udp_hdr *udp = NULL;
4203 eth = (struct rte_ether_hdr *)data;
4204 next_hdr = (char *)(eth + 1);
4205 proto = RTE_BE16(eth->ether_type);
4208 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4209 vlan = (struct rte_vlan_hdr *)next_hdr;
4210 proto = RTE_BE16(vlan->eth_proto);
4211 next_hdr += sizeof(struct rte_vlan_hdr);
4214 /* HW calculates IPv4 csum. no need to proceed */
4215 if (proto == RTE_ETHER_TYPE_IPV4)
4218 /* non IPv4/IPv6 header. not supported */
4219 if (proto != RTE_ETHER_TYPE_IPV6) {
4220 return rte_flow_error_set(error, ENOTSUP,
4221 RTE_FLOW_ERROR_TYPE_ACTION,
4222 NULL, "Cannot offload non IPv4/IPv6");
4225 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4227 /* ignore non UDP */
4228 if (ipv6->proto != IPPROTO_UDP)
4231 udp = (struct rte_udp_hdr *)(ipv6 + 1);
4232 udp->dgram_cksum = 0;
4238 * Convert L2 encap action to DV specification.
4241 * Pointer to rte_eth_dev structure.
4243 * Pointer to action structure.
4244 * @param[in, out] dev_flow
4245 * Pointer to the mlx5_flow.
4246 * @param[in] transfer
4247 * Mark if the flow is E-Switch flow.
4249 * Pointer to the error structure.
4252 * 0 on success, a negative errno value otherwise and rte_errno is set.
4255 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4256 const struct rte_flow_action *action,
4257 struct mlx5_flow *dev_flow,
4259 struct rte_flow_error *error)
4261 const struct rte_flow_item *encap_data;
4262 const struct rte_flow_action_raw_encap *raw_encap_data;
4263 struct mlx5_flow_dv_encap_decap_resource res = {
4265 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4266 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4267 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4270 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4272 (const struct rte_flow_action_raw_encap *)action->conf;
4273 res.size = raw_encap_data->size;
4274 memcpy(res.buf, raw_encap_data->data, res.size);
4276 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4278 ((const struct rte_flow_action_vxlan_encap *)
4279 action->conf)->definition;
4282 ((const struct rte_flow_action_nvgre_encap *)
4283 action->conf)->definition;
4284 if (flow_dv_convert_encap_data(encap_data, res.buf,
4288 if (flow_dv_zero_encap_udp_csum(res.buf, error))
4290 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4291 return rte_flow_error_set(error, EINVAL,
4292 RTE_FLOW_ERROR_TYPE_ACTION,
4293 NULL, "can't create L2 encap action");
4298 * Convert L2 decap action to DV specification.
4301 * Pointer to rte_eth_dev structure.
4302 * @param[in, out] dev_flow
4303 * Pointer to the mlx5_flow.
4304 * @param[in] transfer
4305 * Mark if the flow is E-Switch flow.
4307 * Pointer to the error structure.
4310 * 0 on success, a negative errno value otherwise and rte_errno is set.
4313 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
4314 struct mlx5_flow *dev_flow,
4316 struct rte_flow_error *error)
4318 struct mlx5_flow_dv_encap_decap_resource res = {
4321 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
4322 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4323 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
4326 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4327 return rte_flow_error_set(error, EINVAL,
4328 RTE_FLOW_ERROR_TYPE_ACTION,
4329 NULL, "can't create L2 decap action");
4334 * Convert raw decap/encap (L3 tunnel) action to DV specification.
4337 * Pointer to rte_eth_dev structure.
4339 * Pointer to action structure.
4340 * @param[in, out] dev_flow
4341 * Pointer to the mlx5_flow.
4343 * Pointer to the flow attributes.
4345 * Pointer to the error structure.
4348 * 0 on success, a negative errno value otherwise and rte_errno is set.
4351 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
4352 const struct rte_flow_action *action,
4353 struct mlx5_flow *dev_flow,
4354 const struct rte_flow_attr *attr,
4355 struct rte_flow_error *error)
4357 const struct rte_flow_action_raw_encap *encap_data;
4358 struct mlx5_flow_dv_encap_decap_resource res;
4360 memset(&res, 0, sizeof(res));
4361 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
4362 res.size = encap_data->size;
4363 memcpy(res.buf, encap_data->data, res.size);
4364 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
4365 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
4366 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
4368 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4370 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4371 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4372 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4373 return rte_flow_error_set(error, EINVAL,
4374 RTE_FLOW_ERROR_TYPE_ACTION,
4375 NULL, "can't create encap action");
4380 * Create action push VLAN.
4383 * Pointer to rte_eth_dev structure.
4385 * Pointer to the flow attributes.
4387 * Pointer to the vlan to push to the Ethernet header.
4388 * @param[in, out] dev_flow
4389 * Pointer to the mlx5_flow.
4391 * Pointer to the error structure.
4394 * 0 on success, a negative errno value otherwise and rte_errno is set.
4397 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
4398 const struct rte_flow_attr *attr,
4399 const struct rte_vlan_hdr *vlan,
4400 struct mlx5_flow *dev_flow,
4401 struct rte_flow_error *error)
4403 struct mlx5_flow_dv_push_vlan_action_resource res;
4405 memset(&res, 0, sizeof(res));
4407 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
4410 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4412 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4413 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4414 return flow_dv_push_vlan_action_resource_register
4415 (dev, &res, dev_flow, error);
4419 * Validate the modify-header actions.
4421 * @param[in] action_flags
4422 * Holds the actions detected until now.
4424 * Pointer to the modify action.
4426 * Pointer to error structure.
4429 * 0 on success, a negative errno value otherwise and rte_errno is set.
4432 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
4433 const struct rte_flow_action *action,
4434 struct rte_flow_error *error)
4436 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
4437 return rte_flow_error_set(error, EINVAL,
4438 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4439 NULL, "action configuration not set");
4440 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4441 return rte_flow_error_set(error, EINVAL,
4442 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4443 "can't have encap action before"
4449 * Validate the modify-header MAC address actions.
4451 * @param[in] action_flags
4452 * Holds the actions detected until now.
4454 * Pointer to the modify action.
4455 * @param[in] item_flags
4456 * Holds the items detected.
4458 * Pointer to error structure.
4461 * 0 on success, a negative errno value otherwise and rte_errno is set.
4464 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
4465 const struct rte_flow_action *action,
4466 const uint64_t item_flags,
4467 struct rte_flow_error *error)
4471 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4473 if (!(item_flags & MLX5_FLOW_LAYER_L2))
4474 return rte_flow_error_set(error, EINVAL,
4475 RTE_FLOW_ERROR_TYPE_ACTION,
4477 "no L2 item in pattern");
4483 * Validate the modify-header IPv4 address actions.
4485 * @param[in] action_flags
4486 * Holds the actions detected until now.
4488 * Pointer to the modify action.
4489 * @param[in] item_flags
4490 * Holds the items detected.
4492 * Pointer to error structure.
4495 * 0 on success, a negative errno value otherwise and rte_errno is set.
4498 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
4499 const struct rte_flow_action *action,
4500 const uint64_t item_flags,
4501 struct rte_flow_error *error)
4506 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4508 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4509 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4510 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4511 if (!(item_flags & layer))
4512 return rte_flow_error_set(error, EINVAL,
4513 RTE_FLOW_ERROR_TYPE_ACTION,
4515 "no ipv4 item in pattern");
4521 * Validate the modify-header IPv6 address actions.
4523 * @param[in] action_flags
4524 * Holds the actions detected until now.
4526 * Pointer to the modify action.
4527 * @param[in] item_flags
4528 * Holds the items detected.
4530 * Pointer to error structure.
4533 * 0 on success, a negative errno value otherwise and rte_errno is set.
4536 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
4537 const struct rte_flow_action *action,
4538 const uint64_t item_flags,
4539 struct rte_flow_error *error)
4544 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4546 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4547 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4548 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4549 if (!(item_flags & layer))
4550 return rte_flow_error_set(error, EINVAL,
4551 RTE_FLOW_ERROR_TYPE_ACTION,
4553 "no ipv6 item in pattern");
4559 * Validate the modify-header TP actions.
4561 * @param[in] action_flags
4562 * Holds the actions detected until now.
4564 * Pointer to the modify action.
4565 * @param[in] item_flags
4566 * Holds the items detected.
4568 * Pointer to error structure.
4571 * 0 on success, a negative errno value otherwise and rte_errno is set.
4574 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
4575 const struct rte_flow_action *action,
4576 const uint64_t item_flags,
4577 struct rte_flow_error *error)
4582 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4584 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4585 MLX5_FLOW_LAYER_INNER_L4 :
4586 MLX5_FLOW_LAYER_OUTER_L4;
4587 if (!(item_flags & layer))
4588 return rte_flow_error_set(error, EINVAL,
4589 RTE_FLOW_ERROR_TYPE_ACTION,
4590 NULL, "no transport layer "
4597 * Validate the modify-header actions of increment/decrement
4598 * TCP Sequence-number.
4600 * @param[in] action_flags
4601 * Holds the actions detected until now.
4603 * Pointer to the modify action.
4604 * @param[in] item_flags
4605 * Holds the items detected.
4607 * Pointer to error structure.
4610 * 0 on success, a negative errno value otherwise and rte_errno is set.
4613 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
4614 const struct rte_flow_action *action,
4615 const uint64_t item_flags,
4616 struct rte_flow_error *error)
4621 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4623 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4624 MLX5_FLOW_LAYER_INNER_L4_TCP :
4625 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4626 if (!(item_flags & layer))
4627 return rte_flow_error_set(error, EINVAL,
4628 RTE_FLOW_ERROR_TYPE_ACTION,
4629 NULL, "no TCP item in"
4631 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
4632 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
4633 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
4634 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
4635 return rte_flow_error_set(error, EINVAL,
4636 RTE_FLOW_ERROR_TYPE_ACTION,
4638 "cannot decrease and increase"
4639 " TCP sequence number"
4640 " at the same time");
4646 * Validate the modify-header actions of increment/decrement
4647 * TCP Acknowledgment number.
4649 * @param[in] action_flags
4650 * Holds the actions detected until now.
4652 * Pointer to the modify action.
4653 * @param[in] item_flags
4654 * Holds the items detected.
4656 * Pointer to error structure.
4659 * 0 on success, a negative errno value otherwise and rte_errno is set.
4662 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
4663 const struct rte_flow_action *action,
4664 const uint64_t item_flags,
4665 struct rte_flow_error *error)
4670 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4672 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4673 MLX5_FLOW_LAYER_INNER_L4_TCP :
4674 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4675 if (!(item_flags & layer))
4676 return rte_flow_error_set(error, EINVAL,
4677 RTE_FLOW_ERROR_TYPE_ACTION,
4678 NULL, "no TCP item in"
4680 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
4681 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
4682 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
4683 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
4684 return rte_flow_error_set(error, EINVAL,
4685 RTE_FLOW_ERROR_TYPE_ACTION,
4687 "cannot decrease and increase"
4688 " TCP acknowledgment number"
4689 " at the same time");
4695 * Validate the modify-header TTL actions.
4697 * @param[in] action_flags
4698 * Holds the actions detected until now.
4700 * Pointer to the modify action.
4701 * @param[in] item_flags
4702 * Holds the items detected.
4704 * Pointer to error structure.
4707 * 0 on success, a negative errno value otherwise and rte_errno is set.
4710 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
4711 const struct rte_flow_action *action,
4712 const uint64_t item_flags,
4713 struct rte_flow_error *error)
4718 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4720 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4721 MLX5_FLOW_LAYER_INNER_L3 :
4722 MLX5_FLOW_LAYER_OUTER_L3;
4723 if (!(item_flags & layer))
4724 return rte_flow_error_set(error, EINVAL,
4725 RTE_FLOW_ERROR_TYPE_ACTION,
4727 "no IP protocol in pattern");
4733 * Validate the generic modify field actions.
4735 * Pointer to the rte_eth_dev structure.
4736 * @param[in] action_flags
4737 * Holds the actions detected until now.
4739 * Pointer to the modify action.
4741 * Pointer to the flow attributes.
4743 * Pointer to error structure.
4746 * Number of header fields to modify (0 or more) on success,
4747 * a negative errno value otherwise and rte_errno is set.
4750 flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
4751 const uint64_t action_flags,
4752 const struct rte_flow_action *action,
4753 const struct rte_flow_attr *attr,
4754 struct rte_flow_error *error)
4757 struct mlx5_priv *priv = dev->data->dev_private;
4758 struct mlx5_dev_config *config = &priv->config;
4759 const struct rte_flow_action_modify_field *action_modify_field =
4761 uint32_t dst_width = mlx5_flow_item_field_width(config,
4762 action_modify_field->dst.field);
4763 uint32_t src_width = mlx5_flow_item_field_width(config,
4764 action_modify_field->src.field);
4766 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4770 if (action_modify_field->width == 0)
4771 return rte_flow_error_set(error, EINVAL,
4772 RTE_FLOW_ERROR_TYPE_ACTION, action,
4773 "no bits are requested to be modified");
4774 else if (action_modify_field->width > dst_width ||
4775 action_modify_field->width > src_width)
4776 return rte_flow_error_set(error, EINVAL,
4777 RTE_FLOW_ERROR_TYPE_ACTION, action,
4778 "cannot modify more bits than"
4779 " the width of a field");
4780 if (action_modify_field->dst.field != RTE_FLOW_FIELD_VALUE &&
4781 action_modify_field->dst.field != RTE_FLOW_FIELD_POINTER) {
4782 if ((action_modify_field->dst.offset +
4783 action_modify_field->width > dst_width) ||
4784 (action_modify_field->dst.offset % 32))
4785 return rte_flow_error_set(error, EINVAL,
4786 RTE_FLOW_ERROR_TYPE_ACTION, action,
4787 "destination offset is too big"
4788 " or not aligned to 4 bytes");
4789 if (action_modify_field->dst.level &&
4790 action_modify_field->dst.field != RTE_FLOW_FIELD_TAG)
4791 return rte_flow_error_set(error, ENOTSUP,
4792 RTE_FLOW_ERROR_TYPE_ACTION, action,
4793 "inner header fields modification"
4794 " is not supported");
4796 if (action_modify_field->src.field != RTE_FLOW_FIELD_VALUE &&
4797 action_modify_field->src.field != RTE_FLOW_FIELD_POINTER) {
4798 if (!attr->transfer && !attr->group)
4799 return rte_flow_error_set(error, ENOTSUP,
4800 RTE_FLOW_ERROR_TYPE_ACTION, action,
4801 "modify field action is not"
4802 " supported for group 0");
4803 if ((action_modify_field->src.offset +
4804 action_modify_field->width > src_width) ||
4805 (action_modify_field->src.offset % 32))
4806 return rte_flow_error_set(error, EINVAL,
4807 RTE_FLOW_ERROR_TYPE_ACTION, action,
4808 "source offset is too big"
4809 " or not aligned to 4 bytes");
4810 if (action_modify_field->src.level &&
4811 action_modify_field->src.field != RTE_FLOW_FIELD_TAG)
4812 return rte_flow_error_set(error, ENOTSUP,
4813 RTE_FLOW_ERROR_TYPE_ACTION, action,
4814 "inner header fields modification"
4815 " is not supported");
4817 if ((action_modify_field->dst.field ==
4818 action_modify_field->src.field) &&
4819 (action_modify_field->dst.level ==
4820 action_modify_field->src.level))
4821 return rte_flow_error_set(error, EINVAL,
4822 RTE_FLOW_ERROR_TYPE_ACTION, action,
4823 "source and destination fields"
4824 " cannot be the same");
4825 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VALUE ||
4826 action_modify_field->dst.field == RTE_FLOW_FIELD_POINTER)
4827 return rte_flow_error_set(error, EINVAL,
4828 RTE_FLOW_ERROR_TYPE_ACTION, action,
4829 "immediate value or a pointer to it"
4830 " cannot be used as a destination");
4831 if (action_modify_field->dst.field == RTE_FLOW_FIELD_START ||
4832 action_modify_field->src.field == RTE_FLOW_FIELD_START)
4833 return rte_flow_error_set(error, ENOTSUP,
4834 RTE_FLOW_ERROR_TYPE_ACTION, action,
4835 "modifications of an arbitrary"
4836 " place in a packet is not supported");
4837 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VLAN_TYPE ||
4838 action_modify_field->src.field == RTE_FLOW_FIELD_VLAN_TYPE)
4839 return rte_flow_error_set(error, ENOTSUP,
4840 RTE_FLOW_ERROR_TYPE_ACTION, action,
4841 "modifications of the 802.1Q Tag"
4842 " Identifier is not supported");
4843 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VXLAN_VNI ||
4844 action_modify_field->src.field == RTE_FLOW_FIELD_VXLAN_VNI)
4845 return rte_flow_error_set(error, ENOTSUP,
4846 RTE_FLOW_ERROR_TYPE_ACTION, action,
4847 "modifications of the VXLAN Network"
4848 " Identifier is not supported");
4849 if (action_modify_field->dst.field == RTE_FLOW_FIELD_GENEVE_VNI ||
4850 action_modify_field->src.field == RTE_FLOW_FIELD_GENEVE_VNI)
4851 return rte_flow_error_set(error, ENOTSUP,
4852 RTE_FLOW_ERROR_TYPE_ACTION, action,
4853 "modifications of the GENEVE Network"
4854 " Identifier is not supported");
4855 if (action_modify_field->dst.field == RTE_FLOW_FIELD_MARK ||
4856 action_modify_field->src.field == RTE_FLOW_FIELD_MARK ||
4857 action_modify_field->dst.field == RTE_FLOW_FIELD_META ||
4858 action_modify_field->src.field == RTE_FLOW_FIELD_META) {
4859 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4860 !mlx5_flow_ext_mreg_supported(dev))
4861 return rte_flow_error_set(error, ENOTSUP,
4862 RTE_FLOW_ERROR_TYPE_ACTION, action,
4863 "cannot modify mark or metadata without"
4864 " extended metadata register support");
4866 if (action_modify_field->operation != RTE_FLOW_MODIFY_SET)
4867 return rte_flow_error_set(error, ENOTSUP,
4868 RTE_FLOW_ERROR_TYPE_ACTION, action,
4869 "add and sub operations"
4870 " are not supported");
4871 return (action_modify_field->width / 32) +
4872 !!(action_modify_field->width % 32);
4876 * Validate jump action.
4879 * Pointer to the jump action.
4880 * @param[in] action_flags
4881 * Holds the actions detected until now.
4882 * @param[in] attributes
4883 * Pointer to flow attributes
4884 * @param[in] external
4885 * Action belongs to flow rule created by request external to PMD.
4887 * Pointer to error structure.
4890 * 0 on success, a negative errno value otherwise and rte_errno is set.
4893 flow_dv_validate_action_jump(struct rte_eth_dev *dev,
4894 const struct mlx5_flow_tunnel *tunnel,
4895 const struct rte_flow_action *action,
4896 uint64_t action_flags,
4897 const struct rte_flow_attr *attributes,
4898 bool external, struct rte_flow_error *error)
4900 uint32_t target_group, table;
4902 struct flow_grp_info grp_info = {
4903 .external = !!external,
4904 .transfer = !!attributes->transfer,
4908 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4909 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4910 return rte_flow_error_set(error, EINVAL,
4911 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4912 "can't have 2 fate actions in"
4915 return rte_flow_error_set(error, EINVAL,
4916 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4917 NULL, "action configuration not set");
4919 ((const struct rte_flow_action_jump *)action->conf)->group;
4920 ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
4924 if (attributes->group == target_group &&
4925 !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
4926 MLX5_FLOW_ACTION_TUNNEL_MATCH)))
4927 return rte_flow_error_set(error, EINVAL,
4928 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4929 "target group must be other than"
4930 " the current flow group");
4935 * Validate the port_id action.
4938 * Pointer to rte_eth_dev structure.
4939 * @param[in] action_flags
4940 * Bit-fields that holds the actions detected until now.
4942 * Port_id RTE action structure.
4944 * Attributes of flow that includes this action.
4946 * Pointer to error structure.
4949 * 0 on success, a negative errno value otherwise and rte_errno is set.
4952 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
4953 uint64_t action_flags,
4954 const struct rte_flow_action *action,
4955 const struct rte_flow_attr *attr,
4956 struct rte_flow_error *error)
4958 const struct rte_flow_action_port_id *port_id;
4959 struct mlx5_priv *act_priv;
4960 struct mlx5_priv *dev_priv;
4963 if (!attr->transfer)
4964 return rte_flow_error_set(error, ENOTSUP,
4965 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4967 "port id action is valid in transfer"
4969 if (!action || !action->conf)
4970 return rte_flow_error_set(error, ENOTSUP,
4971 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4973 "port id action parameters must be"
4975 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4976 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4977 return rte_flow_error_set(error, EINVAL,
4978 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4979 "can have only one fate actions in"
4981 dev_priv = mlx5_dev_to_eswitch_info(dev);
4983 return rte_flow_error_set(error, rte_errno,
4984 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4986 "failed to obtain E-Switch info");
4987 port_id = action->conf;
4988 port = port_id->original ? dev->data->port_id : port_id->id;
4989 act_priv = mlx5_port_to_eswitch_info(port, false);
4991 return rte_flow_error_set
4993 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
4994 "failed to obtain E-Switch port id for port");
4995 if (act_priv->domain_id != dev_priv->domain_id)
4996 return rte_flow_error_set
4998 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4999 "port does not belong to"
5000 " E-Switch being configured");
5005 * Get the maximum number of modify header actions.
5008 * Pointer to rte_eth_dev structure.
5010 * Flags bits to check if root level.
5013 * Max number of modify header actions device can support.
5015 static inline unsigned int
5016 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5020 * There's no way to directly query the max capacity from FW.
5021 * The maximal value on root table should be assumed to be supported.
5023 if (!(flags & MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL))
5024 return MLX5_MAX_MODIFY_NUM;
5026 return MLX5_ROOT_TBL_MODIFY_NUM;
5030 * Validate the meter action.
5033 * Pointer to rte_eth_dev structure.
5034 * @param[in] action_flags
5035 * Bit-fields that holds the actions detected until now.
5037 * Pointer to the meter action.
5039 * Attributes of flow that includes this action.
5040 * @param[in] port_id_item
5041 * Pointer to item indicating port id.
5043 * Pointer to error structure.
5046 * 0 on success, a negative errno value otherwise and rte_ernno is set.
5049 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5050 uint64_t action_flags,
5051 const struct rte_flow_action *action,
5052 const struct rte_flow_attr *attr,
5053 const struct rte_flow_item *port_id_item,
5055 struct rte_flow_error *error)
5057 struct mlx5_priv *priv = dev->data->dev_private;
5058 const struct rte_flow_action_meter *am = action->conf;
5059 struct mlx5_flow_meter_info *fm;
5060 struct mlx5_flow_meter_policy *mtr_policy;
5061 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5064 return rte_flow_error_set(error, EINVAL,
5065 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5066 "meter action conf is NULL");
5068 if (action_flags & MLX5_FLOW_ACTION_METER)
5069 return rte_flow_error_set(error, ENOTSUP,
5070 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5071 "meter chaining not support");
5072 if (action_flags & MLX5_FLOW_ACTION_JUMP)
5073 return rte_flow_error_set(error, ENOTSUP,
5074 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5075 "meter with jump not support");
5077 return rte_flow_error_set(error, ENOTSUP,
5078 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5080 "meter action not supported");
5081 fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5083 return rte_flow_error_set(error, EINVAL,
5084 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5086 /* aso meter can always be shared by different domains */
5087 if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5088 !(fm->transfer == attr->transfer ||
5089 (!fm->ingress && !attr->ingress && attr->egress) ||
5090 (!fm->egress && !attr->egress && attr->ingress)))
5091 return rte_flow_error_set(error, EINVAL,
5092 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5093 "Flow attributes domain are either invalid "
5094 "or have a domain conflict with current "
5095 "meter attributes");
5096 if (fm->def_policy) {
5097 if (!((attr->transfer &&
5098 mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
5100 mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
5102 mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
5103 return rte_flow_error_set(error, EINVAL,
5104 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5105 "Flow attributes domain "
5106 "have a conflict with current "
5107 "meter domain attributes");
5110 mtr_policy = mlx5_flow_meter_policy_find(dev,
5111 fm->policy_id, NULL);
5113 return rte_flow_error_set(error, EINVAL,
5114 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5115 "Invalid policy id for meter ");
5116 if (!((attr->transfer && mtr_policy->transfer) ||
5117 (attr->egress && mtr_policy->egress) ||
5118 (attr->ingress && mtr_policy->ingress)))
5119 return rte_flow_error_set(error, EINVAL,
5120 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5121 "Flow attributes domain "
5122 "have a conflict with current "
5123 "meter domain attributes");
5124 if (attr->transfer && mtr_policy->dev) {
5126 * When policy has fate action of port_id,
5127 * the flow should have the same src port as policy.
5129 struct mlx5_priv *policy_port_priv =
5130 mtr_policy->dev->data->dev_private;
5131 int32_t flow_src_port = priv->representor_id;
5134 const struct rte_flow_item_port_id *spec =
5136 struct mlx5_priv *port_priv =
5137 mlx5_port_to_eswitch_info(spec->id,
5140 return rte_flow_error_set(error,
5142 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5144 "Failed to get port info.");
5145 flow_src_port = port_priv->representor_id;
5147 if (flow_src_port != policy_port_priv->representor_id)
5148 return rte_flow_error_set(error,
5150 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
5152 "Flow and meter policy "
5153 "have different src port.");
5155 *def_policy = false;
5161 * Validate the age action.
5163 * @param[in] action_flags
5164 * Holds the actions detected until now.
5166 * Pointer to the age action.
5168 * Pointer to the Ethernet device structure.
5170 * Pointer to error structure.
5173 * 0 on success, a negative errno value otherwise and rte_errno is set.
5176 flow_dv_validate_action_age(uint64_t action_flags,
5177 const struct rte_flow_action *action,
5178 struct rte_eth_dev *dev,
5179 struct rte_flow_error *error)
5181 struct mlx5_priv *priv = dev->data->dev_private;
5182 const struct rte_flow_action_age *age = action->conf;
5184 if (!priv->config.devx || (priv->sh->cmng.counter_fallback &&
5185 !priv->sh->aso_age_mng))
5186 return rte_flow_error_set(error, ENOTSUP,
5187 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5189 "age action not supported");
5190 if (!(action->conf))
5191 return rte_flow_error_set(error, EINVAL,
5192 RTE_FLOW_ERROR_TYPE_ACTION, action,
5193 "configuration cannot be null");
5194 if (!(age->timeout))
5195 return rte_flow_error_set(error, EINVAL,
5196 RTE_FLOW_ERROR_TYPE_ACTION, action,
5197 "invalid timeout value 0");
5198 if (action_flags & MLX5_FLOW_ACTION_AGE)
5199 return rte_flow_error_set(error, EINVAL,
5200 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5201 "duplicate age actions set");
5206 * Validate the modify-header IPv4 DSCP actions.
5208 * @param[in] action_flags
5209 * Holds the actions detected until now.
5211 * Pointer to the modify action.
5212 * @param[in] item_flags
5213 * Holds the items detected.
5215 * Pointer to error structure.
5218 * 0 on success, a negative errno value otherwise and rte_errno is set.
5221 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
5222 const struct rte_flow_action *action,
5223 const uint64_t item_flags,
5224 struct rte_flow_error *error)
5228 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5230 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
5231 return rte_flow_error_set(error, EINVAL,
5232 RTE_FLOW_ERROR_TYPE_ACTION,
5234 "no ipv4 item in pattern");
5240 * Validate the modify-header IPv6 DSCP actions.
5242 * @param[in] action_flags
5243 * Holds the actions detected until now.
5245 * Pointer to the modify action.
5246 * @param[in] item_flags
5247 * Holds the items detected.
5249 * Pointer to error structure.
5252 * 0 on success, a negative errno value otherwise and rte_errno is set.
5255 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
5256 const struct rte_flow_action *action,
5257 const uint64_t item_flags,
5258 struct rte_flow_error *error)
5262 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5264 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
5265 return rte_flow_error_set(error, EINVAL,
5266 RTE_FLOW_ERROR_TYPE_ACTION,
5268 "no ipv6 item in pattern");
5274 * Match modify-header resource.
5277 * Pointer to the hash list.
5279 * Pointer to exist resource entry object.
5281 * Key of the new entry.
5283 * Pointer to new modify-header resource.
5286 * 0 on matching, non-zero otherwise.
5289 flow_dv_modify_match_cb(struct mlx5_hlist *list __rte_unused,
5290 struct mlx5_hlist_entry *entry,
5291 uint64_t key __rte_unused, void *cb_ctx)
5293 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5294 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5295 struct mlx5_flow_dv_modify_hdr_resource *resource =
5296 container_of(entry, typeof(*resource), entry);
5297 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5299 key_len += ref->actions_num * sizeof(ref->actions[0]);
5300 return ref->actions_num != resource->actions_num ||
5301 memcmp(&ref->ft_type, &resource->ft_type, key_len);
5304 struct mlx5_hlist_entry *
5305 flow_dv_modify_create_cb(struct mlx5_hlist *list, uint64_t key __rte_unused,
5308 struct mlx5_dev_ctx_shared *sh = list->ctx;
5309 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5310 struct mlx5dv_dr_domain *ns;
5311 struct mlx5_flow_dv_modify_hdr_resource *entry;
5312 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5314 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5315 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5317 entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry) + data_len, 0,
5320 rte_flow_error_set(ctx->error, ENOMEM,
5321 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5322 "cannot allocate resource memory");
5325 rte_memcpy(&entry->ft_type,
5326 RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
5327 key_len + data_len);
5328 if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
5329 ns = sh->fdb_domain;
5330 else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
5334 ret = mlx5_flow_os_create_flow_action_modify_header
5335 (sh->ctx, ns, entry,
5336 data_len, &entry->action);
5339 rte_flow_error_set(ctx->error, ENOMEM,
5340 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5341 NULL, "cannot create modification action");
5344 return &entry->entry;
5348 * Validate the sample action.
5350 * @param[in, out] action_flags
5351 * Holds the actions detected until now.
5353 * Pointer to the sample action.
5355 * Pointer to the Ethernet device structure.
5357 * Attributes of flow that includes this action.
5358 * @param[in] item_flags
5359 * Holds the items detected.
5361 * Pointer to the RSS action.
5362 * @param[out] sample_rss
5363 * Pointer to the RSS action in sample action list.
5365 * Pointer to the COUNT action in sample action list.
5366 * @param[out] fdb_mirror_limit
5367 * Pointer to the FDB mirror limitation flag.
5369 * Pointer to error structure.
5372 * 0 on success, a negative errno value otherwise and rte_errno is set.
5375 flow_dv_validate_action_sample(uint64_t *action_flags,
5376 const struct rte_flow_action *action,
5377 struct rte_eth_dev *dev,
5378 const struct rte_flow_attr *attr,
5379 uint64_t item_flags,
5380 const struct rte_flow_action_rss *rss,
5381 const struct rte_flow_action_rss **sample_rss,
5382 const struct rte_flow_action_count **count,
5383 int *fdb_mirror_limit,
5384 struct rte_flow_error *error)
5386 struct mlx5_priv *priv = dev->data->dev_private;
5387 struct mlx5_dev_config *dev_conf = &priv->config;
5388 const struct rte_flow_action_sample *sample = action->conf;
5389 const struct rte_flow_action *act;
5390 uint64_t sub_action_flags = 0;
5391 uint16_t queue_index = 0xFFFF;
5396 return rte_flow_error_set(error, EINVAL,
5397 RTE_FLOW_ERROR_TYPE_ACTION, action,
5398 "configuration cannot be NULL");
5399 if (sample->ratio == 0)
5400 return rte_flow_error_set(error, EINVAL,
5401 RTE_FLOW_ERROR_TYPE_ACTION, action,
5402 "ratio value starts from 1");
5403 if (!priv->config.devx || (sample->ratio > 0 && !priv->sampler_en))
5404 return rte_flow_error_set(error, ENOTSUP,
5405 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5407 "sample action not supported");
5408 if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
5409 return rte_flow_error_set(error, EINVAL,
5410 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5411 "Multiple sample actions not "
5413 if (*action_flags & MLX5_FLOW_ACTION_METER)
5414 return rte_flow_error_set(error, EINVAL,
5415 RTE_FLOW_ERROR_TYPE_ACTION, action,
5416 "wrong action order, meter should "
5417 "be after sample action");
5418 if (*action_flags & MLX5_FLOW_ACTION_JUMP)
5419 return rte_flow_error_set(error, EINVAL,
5420 RTE_FLOW_ERROR_TYPE_ACTION, action,
5421 "wrong action order, jump should "
5422 "be after sample action");
5423 act = sample->actions;
5424 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
5425 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5426 return rte_flow_error_set(error, ENOTSUP,
5427 RTE_FLOW_ERROR_TYPE_ACTION,
5428 act, "too many actions");
5429 switch (act->type) {
5430 case RTE_FLOW_ACTION_TYPE_QUEUE:
5431 ret = mlx5_flow_validate_action_queue(act,
5437 queue_index = ((const struct rte_flow_action_queue *)
5438 (act->conf))->index;
5439 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
5442 case RTE_FLOW_ACTION_TYPE_RSS:
5443 *sample_rss = act->conf;
5444 ret = mlx5_flow_validate_action_rss(act,
5451 if (rss && *sample_rss &&
5452 ((*sample_rss)->level != rss->level ||
5453 (*sample_rss)->types != rss->types))
5454 return rte_flow_error_set(error, ENOTSUP,
5455 RTE_FLOW_ERROR_TYPE_ACTION,
5457 "Can't use the different RSS types "
5458 "or level in the same flow");
5459 if (*sample_rss != NULL && (*sample_rss)->queue_num)
5460 queue_index = (*sample_rss)->queue[0];
5461 sub_action_flags |= MLX5_FLOW_ACTION_RSS;
5464 case RTE_FLOW_ACTION_TYPE_MARK:
5465 ret = flow_dv_validate_action_mark(dev, act,
5470 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
5471 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
5472 MLX5_FLOW_ACTION_MARK_EXT;
5474 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
5477 case RTE_FLOW_ACTION_TYPE_COUNT:
5478 ret = flow_dv_validate_action_count
5479 (dev, is_shared_action_count(act),
5480 *action_flags | sub_action_flags,
5485 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
5486 *action_flags |= MLX5_FLOW_ACTION_COUNT;
5489 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5490 ret = flow_dv_validate_action_port_id(dev,
5497 sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5500 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5501 ret = flow_dv_validate_action_raw_encap_decap
5502 (dev, NULL, act->conf, attr, &sub_action_flags,
5503 &actions_n, action, item_flags, error);
5508 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5509 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5510 ret = flow_dv_validate_action_l2_encap(dev,
5516 sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
5520 return rte_flow_error_set(error, ENOTSUP,
5521 RTE_FLOW_ERROR_TYPE_ACTION,
5523 "Doesn't support optional "
5527 if (attr->ingress && !attr->transfer) {
5528 if (!(sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
5529 MLX5_FLOW_ACTION_RSS)))
5530 return rte_flow_error_set(error, EINVAL,
5531 RTE_FLOW_ERROR_TYPE_ACTION,
5533 "Ingress must has a dest "
5534 "QUEUE for Sample");
5535 } else if (attr->egress && !attr->transfer) {
5536 return rte_flow_error_set(error, ENOTSUP,
5537 RTE_FLOW_ERROR_TYPE_ACTION,
5539 "Sample Only support Ingress "
5541 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
5542 MLX5_ASSERT(attr->transfer);
5543 if (sample->ratio > 1)
5544 return rte_flow_error_set(error, ENOTSUP,
5545 RTE_FLOW_ERROR_TYPE_ACTION,
5547 "E-Switch doesn't support "
5548 "any optional action "
5550 if (sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
5551 return rte_flow_error_set(error, ENOTSUP,
5552 RTE_FLOW_ERROR_TYPE_ACTION,
5554 "unsupported action QUEUE");
5555 if (sub_action_flags & MLX5_FLOW_ACTION_RSS)
5556 return rte_flow_error_set(error, ENOTSUP,
5557 RTE_FLOW_ERROR_TYPE_ACTION,
5559 "unsupported action QUEUE");
5560 if (!(sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
5561 return rte_flow_error_set(error, EINVAL,
5562 RTE_FLOW_ERROR_TYPE_ACTION,
5564 "E-Switch must has a dest "
5565 "port for mirroring");
5566 if (!priv->config.hca_attr.reg_c_preserve &&
5567 priv->representor_id != UINT16_MAX)
5568 *fdb_mirror_limit = 1;
5570 /* Continue validation for Xcap actions.*/
5571 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
5572 (queue_index == 0xFFFF ||
5573 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5574 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5575 MLX5_FLOW_XCAP_ACTIONS)
5576 return rte_flow_error_set(error, ENOTSUP,
5577 RTE_FLOW_ERROR_TYPE_ACTION,
5578 NULL, "encap and decap "
5579 "combination aren't "
5581 if (!attr->transfer && attr->ingress && (sub_action_flags &
5582 MLX5_FLOW_ACTION_ENCAP))
5583 return rte_flow_error_set(error, ENOTSUP,
5584 RTE_FLOW_ERROR_TYPE_ACTION,
5585 NULL, "encap is not supported"
5586 " for ingress traffic");
5592 * Find existing modify-header resource or create and register a new one.
5594 * @param dev[in, out]
5595 * Pointer to rte_eth_dev structure.
5596 * @param[in, out] resource
5597 * Pointer to modify-header resource.
5598 * @parm[in, out] dev_flow
5599 * Pointer to the dev_flow.
5601 * pointer to error structure.
5604 * 0 on success otherwise -errno and errno is set.
5607 flow_dv_modify_hdr_resource_register
5608 (struct rte_eth_dev *dev,
5609 struct mlx5_flow_dv_modify_hdr_resource *resource,
5610 struct mlx5_flow *dev_flow,
5611 struct rte_flow_error *error)
5613 struct mlx5_priv *priv = dev->data->dev_private;
5614 struct mlx5_dev_ctx_shared *sh = priv->sh;
5615 uint32_t key_len = sizeof(*resource) -
5616 offsetof(typeof(*resource), ft_type) +
5617 resource->actions_num * sizeof(resource->actions[0]);
5618 struct mlx5_hlist_entry *entry;
5619 struct mlx5_flow_cb_ctx ctx = {
5625 resource->flags = dev_flow->dv.group ? 0 :
5626 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
5627 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
5629 return rte_flow_error_set(error, EOVERFLOW,
5630 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5631 "too many modify header items");
5632 key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
5633 entry = mlx5_hlist_register(sh->modify_cmds, key64, &ctx);
5636 resource = container_of(entry, typeof(*resource), entry);
5637 dev_flow->handle->dvh.modify_hdr = resource;
5642 * Get DV flow counter by index.
5645 * Pointer to the Ethernet device structure.
5647 * mlx5 flow counter index in the container.
5649 * mlx5 flow counter pool in the container.
5652 * Pointer to the counter, NULL otherwise.
5654 static struct mlx5_flow_counter *
5655 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
5657 struct mlx5_flow_counter_pool **ppool)
5659 struct mlx5_priv *priv = dev->data->dev_private;
5660 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5661 struct mlx5_flow_counter_pool *pool;
5663 /* Decrease to original index and clear shared bit. */
5664 idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
5665 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cmng->n);
5666 pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
5670 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
5674 * Check the devx counter belongs to the pool.
5677 * Pointer to the counter pool.
5679 * The counter devx ID.
5682 * True if counter belongs to the pool, false otherwise.
5685 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
5687 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
5688 MLX5_COUNTERS_PER_POOL;
5690 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
5696 * Get a pool by devx counter ID.
5699 * Pointer to the counter management.
5701 * The counter devx ID.
5704 * The counter pool pointer if exists, NULL otherwise,
5706 static struct mlx5_flow_counter_pool *
5707 flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
5710 struct mlx5_flow_counter_pool *pool = NULL;
5712 rte_spinlock_lock(&cmng->pool_update_sl);
5713 /* Check last used pool. */
5714 if (cmng->last_pool_idx != POOL_IDX_INVALID &&
5715 flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
5716 pool = cmng->pools[cmng->last_pool_idx];
5719 /* ID out of range means no suitable pool in the container. */
5720 if (id > cmng->max_id || id < cmng->min_id)
5723 * Find the pool from the end of the container, since mostly counter
5724 * ID is sequence increasing, and the last pool should be the needed
5729 struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
5731 if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
5737 rte_spinlock_unlock(&cmng->pool_update_sl);
5742 * Resize a counter container.
5745 * Pointer to the Ethernet device structure.
5748 * 0 on success, otherwise negative errno value and rte_errno is set.
5751 flow_dv_container_resize(struct rte_eth_dev *dev)
5753 struct mlx5_priv *priv = dev->data->dev_private;
5754 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5755 void *old_pools = cmng->pools;
5756 uint32_t resize = cmng->n + MLX5_CNT_CONTAINER_RESIZE;
5757 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
5758 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
5765 memcpy(pools, old_pools, cmng->n *
5766 sizeof(struct mlx5_flow_counter_pool *));
5768 cmng->pools = pools;
5770 mlx5_free(old_pools);
5775 * Query a devx flow counter.
5778 * Pointer to the Ethernet device structure.
5779 * @param[in] counter
5780 * Index to the flow counter.
5782 * The statistics value of packets.
5784 * The statistics value of bytes.
5787 * 0 on success, otherwise a negative errno value and rte_errno is set.
5790 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
5793 struct mlx5_priv *priv = dev->data->dev_private;
5794 struct mlx5_flow_counter_pool *pool = NULL;
5795 struct mlx5_flow_counter *cnt;
5798 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
5800 if (priv->sh->cmng.counter_fallback)
5801 return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
5802 0, pkts, bytes, 0, NULL, NULL, 0);
5803 rte_spinlock_lock(&pool->sl);
5808 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
5809 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
5810 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
5812 rte_spinlock_unlock(&pool->sl);
5817 * Create and initialize a new counter pool.
5820 * Pointer to the Ethernet device structure.
5822 * The devX counter handle.
5824 * Whether the pool is for counter that was allocated for aging.
5825 * @param[in/out] cont_cur
5826 * Pointer to the container pointer, it will be update in pool resize.
5829 * The pool container pointer on success, NULL otherwise and rte_errno is set.
5831 static struct mlx5_flow_counter_pool *
5832 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
5835 struct mlx5_priv *priv = dev->data->dev_private;
5836 struct mlx5_flow_counter_pool *pool;
5837 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5838 bool fallback = priv->sh->cmng.counter_fallback;
5839 uint32_t size = sizeof(*pool);
5841 size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
5842 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
5843 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
5849 pool->is_aged = !!age;
5850 pool->query_gen = 0;
5851 pool->min_dcs = dcs;
5852 rte_spinlock_init(&pool->sl);
5853 rte_spinlock_init(&pool->csl);
5854 TAILQ_INIT(&pool->counters[0]);
5855 TAILQ_INIT(&pool->counters[1]);
5856 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
5857 rte_spinlock_lock(&cmng->pool_update_sl);
5858 pool->index = cmng->n_valid;
5859 if (pool->index == cmng->n && flow_dv_container_resize(dev)) {
5861 rte_spinlock_unlock(&cmng->pool_update_sl);
5864 cmng->pools[pool->index] = pool;
5866 if (unlikely(fallback)) {
5867 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
5869 if (base < cmng->min_id)
5870 cmng->min_id = base;
5871 if (base > cmng->max_id)
5872 cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
5873 cmng->last_pool_idx = pool->index;
5875 rte_spinlock_unlock(&cmng->pool_update_sl);
5880 * Prepare a new counter and/or a new counter pool.
5883 * Pointer to the Ethernet device structure.
5884 * @param[out] cnt_free
5885 * Where to put the pointer of a new counter.
5887 * Whether the pool is for counter that was allocated for aging.
5890 * The counter pool pointer and @p cnt_free is set on success,
5891 * NULL otherwise and rte_errno is set.
5893 static struct mlx5_flow_counter_pool *
5894 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
5895 struct mlx5_flow_counter **cnt_free,
5898 struct mlx5_priv *priv = dev->data->dev_private;
5899 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5900 struct mlx5_flow_counter_pool *pool;
5901 struct mlx5_counters tmp_tq;
5902 struct mlx5_devx_obj *dcs = NULL;
5903 struct mlx5_flow_counter *cnt;
5904 enum mlx5_counter_type cnt_type =
5905 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
5906 bool fallback = priv->sh->cmng.counter_fallback;
5910 /* bulk_bitmap must be 0 for single counter allocation. */
5911 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
5914 pool = flow_dv_find_pool_by_id(cmng, dcs->id);
5916 pool = flow_dv_pool_create(dev, dcs, age);
5918 mlx5_devx_cmd_destroy(dcs);
5922 i = dcs->id % MLX5_COUNTERS_PER_POOL;
5923 cnt = MLX5_POOL_GET_CNT(pool, i);
5925 cnt->dcs_when_free = dcs;
5929 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
5931 rte_errno = ENODATA;
5934 pool = flow_dv_pool_create(dev, dcs, age);
5936 mlx5_devx_cmd_destroy(dcs);
5939 TAILQ_INIT(&tmp_tq);
5940 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
5941 cnt = MLX5_POOL_GET_CNT(pool, i);
5943 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
5945 rte_spinlock_lock(&cmng->csl[cnt_type]);
5946 TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
5947 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5948 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
5949 (*cnt_free)->pool = pool;
5954 * Allocate a flow counter.
5957 * Pointer to the Ethernet device structure.
5959 * Whether the counter was allocated for aging.
5962 * Index to flow counter on success, 0 otherwise and rte_errno is set.
5965 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
5967 struct mlx5_priv *priv = dev->data->dev_private;
5968 struct mlx5_flow_counter_pool *pool = NULL;
5969 struct mlx5_flow_counter *cnt_free = NULL;
5970 bool fallback = priv->sh->cmng.counter_fallback;
5971 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5972 enum mlx5_counter_type cnt_type =
5973 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
5976 if (!priv->config.devx) {
5977 rte_errno = ENOTSUP;
5980 /* Get free counters from container. */
5981 rte_spinlock_lock(&cmng->csl[cnt_type]);
5982 cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
5984 TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
5985 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5986 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
5988 pool = cnt_free->pool;
5990 cnt_free->dcs_when_active = cnt_free->dcs_when_free;
5991 /* Create a DV counter action only in the first time usage. */
5992 if (!cnt_free->action) {
5994 struct mlx5_devx_obj *dcs;
5998 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
5999 dcs = pool->min_dcs;
6002 dcs = cnt_free->dcs_when_free;
6004 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
6011 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
6012 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
6013 /* Update the counter reset values. */
6014 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
6017 if (!fallback && !priv->sh->cmng.query_thread_on)
6018 /* Start the asynchronous batch query by the host thread. */
6019 mlx5_set_query_alarm(priv->sh);
6021 * When the count action isn't shared (by ID), shared_info field is
6022 * used for indirect action API's refcnt.
6023 * When the counter action is not shared neither by ID nor by indirect
6024 * action API, shared info must be 1.
6026 cnt_free->shared_info.refcnt = 1;
6030 cnt_free->pool = pool;
6032 cnt_free->dcs_when_free = cnt_free->dcs_when_active;
6033 rte_spinlock_lock(&cmng->csl[cnt_type]);
6034 TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
6035 rte_spinlock_unlock(&cmng->csl[cnt_type]);
6041 * Allocate a shared flow counter.
6044 * Pointer to the shared counter configuration.
6046 * Pointer to save the allocated counter index.
6049 * Index to flow counter on success, 0 otherwise and rte_errno is set.
6053 flow_dv_counter_alloc_shared_cb(void *ctx, union mlx5_l3t_data *data)
6055 struct mlx5_shared_counter_conf *conf = ctx;
6056 struct rte_eth_dev *dev = conf->dev;
6057 struct mlx5_flow_counter *cnt;
6059 data->dword = flow_dv_counter_alloc(dev, 0);
6060 data->dword |= MLX5_CNT_SHARED_OFFSET;
6061 cnt = flow_dv_counter_get_by_idx(dev, data->dword, NULL);
6062 cnt->shared_info.id = conf->id;
6067 * Get a shared flow counter.
6070 * Pointer to the Ethernet device structure.
6072 * Counter identifier.
6075 * Index to flow counter on success, 0 otherwise and rte_errno is set.
6078 flow_dv_counter_get_shared(struct rte_eth_dev *dev, uint32_t id)
6080 struct mlx5_priv *priv = dev->data->dev_private;
6081 struct mlx5_shared_counter_conf conf = {
6085 union mlx5_l3t_data data = {
6089 mlx5_l3t_prepare_entry(priv->sh->cnt_id_tbl, id, &data,
6090 flow_dv_counter_alloc_shared_cb, &conf);
6095 * Get age param from counter index.
6098 * Pointer to the Ethernet device structure.
6099 * @param[in] counter
6100 * Index to the counter handler.
6103 * The aging parameter specified for the counter index.
6105 static struct mlx5_age_param*
6106 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
6109 struct mlx5_flow_counter *cnt;
6110 struct mlx5_flow_counter_pool *pool = NULL;
6112 flow_dv_counter_get_by_idx(dev, counter, &pool);
6113 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
6114 cnt = MLX5_POOL_GET_CNT(pool, counter);
6115 return MLX5_CNT_TO_AGE(cnt);
6119 * Remove a flow counter from aged counter list.
6122 * Pointer to the Ethernet device structure.
6123 * @param[in] counter
6124 * Index to the counter handler.
6126 * Pointer to the counter handler.
6129 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
6130 uint32_t counter, struct mlx5_flow_counter *cnt)
6132 struct mlx5_age_info *age_info;
6133 struct mlx5_age_param *age_param;
6134 struct mlx5_priv *priv = dev->data->dev_private;
6135 uint16_t expected = AGE_CANDIDATE;
6137 age_info = GET_PORT_AGE_INFO(priv);
6138 age_param = flow_dv_counter_idx_get_age(dev, counter);
6139 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
6140 AGE_FREE, false, __ATOMIC_RELAXED,
6141 __ATOMIC_RELAXED)) {
6143 * We need the lock even it is age timeout,
6144 * since counter may still in process.
6146 rte_spinlock_lock(&age_info->aged_sl);
6147 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
6148 rte_spinlock_unlock(&age_info->aged_sl);
6149 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
6154 * Release a flow counter.
6157 * Pointer to the Ethernet device structure.
6158 * @param[in] counter
6159 * Index to the counter handler.
6162 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
6164 struct mlx5_priv *priv = dev->data->dev_private;
6165 struct mlx5_flow_counter_pool *pool = NULL;
6166 struct mlx5_flow_counter *cnt;
6167 enum mlx5_counter_type cnt_type;
6171 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6173 if (pool->is_aged) {
6174 flow_dv_counter_remove_from_age(dev, counter, cnt);
6177 * If the counter action is shared by ID, the l3t_clear_entry
6178 * function reduces its references counter. If after the
6179 * reduction the action is still referenced, the function
6180 * returns here and does not release it.
6182 if (IS_LEGACY_SHARED_CNT(counter) &&
6183 mlx5_l3t_clear_entry(priv->sh->cnt_id_tbl,
6184 cnt->shared_info.id))
6187 * If the counter action is shared by indirect action API,
6188 * the atomic function reduces its references counter.
6189 * If after the reduction the action is still referenced, the
6190 * function returns here and does not release it.
6191 * When the counter action is not shared neither by ID nor by
6192 * indirect action API, shared info is 1 before the reduction,
6193 * so this condition is failed and function doesn't return here.
6195 if (!IS_LEGACY_SHARED_CNT(counter) &&
6196 __atomic_sub_fetch(&cnt->shared_info.refcnt, 1,
6202 * Put the counter back to list to be updated in none fallback mode.
6203 * Currently, we are using two list alternately, while one is in query,
6204 * add the freed counter to the other list based on the pool query_gen
6205 * value. After query finishes, add counter the list to the global
6206 * container counter list. The list changes while query starts. In
6207 * this case, lock will not be needed as query callback and release
6208 * function both operate with the different list.
6210 if (!priv->sh->cmng.counter_fallback) {
6211 rte_spinlock_lock(&pool->csl);
6212 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
6213 rte_spinlock_unlock(&pool->csl);
6215 cnt->dcs_when_free = cnt->dcs_when_active;
6216 cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6217 MLX5_COUNTER_TYPE_ORIGIN;
6218 rte_spinlock_lock(&priv->sh->cmng.csl[cnt_type]);
6219 TAILQ_INSERT_TAIL(&priv->sh->cmng.counters[cnt_type],
6221 rte_spinlock_unlock(&priv->sh->cmng.csl[cnt_type]);
6226 * Resize a meter id container.
6229 * Pointer to the Ethernet device structure.
6232 * 0 on success, otherwise negative errno value and rte_errno is set.
6235 flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
6237 struct mlx5_priv *priv = dev->data->dev_private;
6238 struct mlx5_aso_mtr_pools_mng *pools_mng =
6239 &priv->sh->mtrmng->pools_mng;
6240 void *old_pools = pools_mng->pools;
6241 uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
6242 uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
6243 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
6250 if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER)) {
6255 memcpy(pools, old_pools, pools_mng->n *
6256 sizeof(struct mlx5_aso_mtr_pool *));
6257 pools_mng->n = resize;
6258 pools_mng->pools = pools;
6260 mlx5_free(old_pools);
6265 * Prepare a new meter and/or a new meter pool.
6268 * Pointer to the Ethernet device structure.
6269 * @param[out] mtr_free
6270 * Where to put the pointer of a new meter.g.
6273 * The meter pool pointer and @mtr_free is set on success,
6274 * NULL otherwise and rte_errno is set.
6276 static struct mlx5_aso_mtr_pool *
6277 flow_dv_mtr_pool_create(struct rte_eth_dev *dev,
6278 struct mlx5_aso_mtr **mtr_free)
6280 struct mlx5_priv *priv = dev->data->dev_private;
6281 struct mlx5_aso_mtr_pools_mng *pools_mng =
6282 &priv->sh->mtrmng->pools_mng;
6283 struct mlx5_aso_mtr_pool *pool = NULL;
6284 struct mlx5_devx_obj *dcs = NULL;
6286 uint32_t log_obj_size;
6288 log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
6289 dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->ctx,
6290 priv->sh->pdn, log_obj_size);
6292 rte_errno = ENODATA;
6295 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
6298 claim_zero(mlx5_devx_cmd_destroy(dcs));
6301 pool->devx_obj = dcs;
6302 pool->index = pools_mng->n_valid;
6303 if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
6305 claim_zero(mlx5_devx_cmd_destroy(dcs));
6308 pools_mng->pools[pool->index] = pool;
6309 pools_mng->n_valid++;
6310 for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
6311 pool->mtrs[i].offset = i;
6312 LIST_INSERT_HEAD(&pools_mng->meters,
6313 &pool->mtrs[i], next);
6315 pool->mtrs[0].offset = 0;
6316 *mtr_free = &pool->mtrs[0];
6321 * Release a flow meter into pool.
6324 * Pointer to the Ethernet device structure.
6325 * @param[in] mtr_idx
6326 * Index to aso flow meter.
6329 flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
6331 struct mlx5_priv *priv = dev->data->dev_private;
6332 struct mlx5_aso_mtr_pools_mng *pools_mng =
6333 &priv->sh->mtrmng->pools_mng;
6334 struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
6336 MLX5_ASSERT(aso_mtr);
6337 rte_spinlock_lock(&pools_mng->mtrsl);
6338 memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
6339 aso_mtr->state = ASO_METER_FREE;
6340 LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
6341 rte_spinlock_unlock(&pools_mng->mtrsl);
6345 * Allocate a aso flow meter.
6348 * Pointer to the Ethernet device structure.
6351 * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
6354 flow_dv_mtr_alloc(struct rte_eth_dev *dev)
6356 struct mlx5_priv *priv = dev->data->dev_private;
6357 struct mlx5_aso_mtr *mtr_free = NULL;
6358 struct mlx5_aso_mtr_pools_mng *pools_mng =
6359 &priv->sh->mtrmng->pools_mng;
6360 struct mlx5_aso_mtr_pool *pool;
6361 uint32_t mtr_idx = 0;
6363 if (!priv->config.devx) {
6364 rte_errno = ENOTSUP;
6367 /* Allocate the flow meter memory. */
6368 /* Get free meters from management. */
6369 rte_spinlock_lock(&pools_mng->mtrsl);
6370 mtr_free = LIST_FIRST(&pools_mng->meters);
6372 LIST_REMOVE(mtr_free, next);
6373 if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
6374 rte_spinlock_unlock(&pools_mng->mtrsl);
6377 mtr_free->state = ASO_METER_WAIT;
6378 rte_spinlock_unlock(&pools_mng->mtrsl);
6379 pool = container_of(mtr_free,
6380 struct mlx5_aso_mtr_pool,
6381 mtrs[mtr_free->offset]);
6382 mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
6383 if (!mtr_free->fm.meter_action) {
6384 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
6385 struct rte_flow_error error;
6388 reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
6389 mtr_free->fm.meter_action =
6390 mlx5_glue->dv_create_flow_action_aso
6391 (priv->sh->rx_domain,
6392 pool->devx_obj->obj,
6394 (1 << MLX5_FLOW_COLOR_GREEN),
6396 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
6397 if (!mtr_free->fm.meter_action) {
6398 flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
6406 * Verify the @p attributes will be correctly understood by the NIC and store
6407 * them in the @p flow if everything is correct.
6410 * Pointer to dev struct.
6411 * @param[in] attributes
6412 * Pointer to flow attributes
6413 * @param[in] external
6414 * This flow rule is created by request external to PMD.
6416 * Pointer to error structure.
6419 * - 0 on success and non root table.
6420 * - 1 on success and root table.
6421 * - a negative errno value otherwise and rte_errno is set.
6424 flow_dv_validate_attributes(struct rte_eth_dev *dev,
6425 const struct mlx5_flow_tunnel *tunnel,
6426 const struct rte_flow_attr *attributes,
6427 const struct flow_grp_info *grp_info,
6428 struct rte_flow_error *error)
6430 struct mlx5_priv *priv = dev->data->dev_private;
6431 uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
6434 #ifndef HAVE_MLX5DV_DR
6435 RTE_SET_USED(tunnel);
6436 RTE_SET_USED(grp_info);
6437 if (attributes->group)
6438 return rte_flow_error_set(error, ENOTSUP,
6439 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6441 "groups are not supported");
6445 ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
6450 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
6452 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
6453 attributes->priority > lowest_priority)
6454 return rte_flow_error_set(error, ENOTSUP,
6455 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
6457 "priority out of range");
6458 if (attributes->transfer) {
6459 if (!priv->config.dv_esw_en)
6460 return rte_flow_error_set
6462 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6463 "E-Switch dr is not supported");
6464 if (!(priv->representor || priv->master))
6465 return rte_flow_error_set
6466 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6467 NULL, "E-Switch configuration can only be"
6468 " done by a master or a representor device");
6469 if (attributes->egress)
6470 return rte_flow_error_set
6472 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
6473 "egress is not supported");
6475 if (!(attributes->egress ^ attributes->ingress))
6476 return rte_flow_error_set(error, ENOTSUP,
6477 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6478 "must specify exactly one of "
6479 "ingress or egress");
6484 mlx5_flow_locate_proto_l3(const struct rte_flow_item **head,
6485 const struct rte_flow_item *end)
6487 const struct rte_flow_item *item = *head;
6488 uint16_t l3_protocol;
6490 for (; item != end; item++) {
6491 switch (item->type) {
6494 case RTE_FLOW_ITEM_TYPE_IPV4:
6495 l3_protocol = RTE_ETHER_TYPE_IPV4;
6497 case RTE_FLOW_ITEM_TYPE_IPV6:
6498 l3_protocol = RTE_ETHER_TYPE_IPV6;
6500 case RTE_FLOW_ITEM_TYPE_ETH:
6501 if (item->mask && item->spec) {
6502 MLX5_ETHER_TYPE_FROM_HEADER(rte_flow_item_eth,
6505 if (l3_protocol == RTE_ETHER_TYPE_IPV4 ||
6506 l3_protocol == RTE_ETHER_TYPE_IPV6)
6510 case RTE_FLOW_ITEM_TYPE_VLAN:
6511 if (item->mask && item->spec) {
6512 MLX5_ETHER_TYPE_FROM_HEADER(rte_flow_item_vlan,
6515 if (l3_protocol == RTE_ETHER_TYPE_IPV4 ||
6516 l3_protocol == RTE_ETHER_TYPE_IPV6)
6529 mlx5_flow_locate_proto_l4(const struct rte_flow_item **head,
6530 const struct rte_flow_item *end)
6532 const struct rte_flow_item *item = *head;
6533 uint8_t l4_protocol;
6535 for (; item != end; item++) {
6536 switch (item->type) {
6539 case RTE_FLOW_ITEM_TYPE_TCP:
6540 l4_protocol = IPPROTO_TCP;
6542 case RTE_FLOW_ITEM_TYPE_UDP:
6543 l4_protocol = IPPROTO_UDP;
6545 case RTE_FLOW_ITEM_TYPE_IPV4:
6546 if (item->mask && item->spec) {
6547 const struct rte_flow_item_ipv4 *mask, *spec;
6549 mask = (typeof(mask))item->mask;
6550 spec = (typeof(spec))item->spec;
6551 l4_protocol = mask->hdr.next_proto_id &
6552 spec->hdr.next_proto_id;
6553 if (l4_protocol == IPPROTO_TCP ||
6554 l4_protocol == IPPROTO_UDP)
6558 case RTE_FLOW_ITEM_TYPE_IPV6:
6559 if (item->mask && item->spec) {
6560 const struct rte_flow_item_ipv6 *mask, *spec;
6561 mask = (typeof(mask))item->mask;
6562 spec = (typeof(spec))item->spec;
6563 l4_protocol = mask->hdr.proto & spec->hdr.proto;
6564 if (l4_protocol == IPPROTO_TCP ||
6565 l4_protocol == IPPROTO_UDP)
6578 flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
6579 const struct rte_flow_item *rule_items,
6580 const struct rte_flow_item *integrity_item,
6581 struct rte_flow_error *error)
6583 struct mlx5_priv *priv = dev->data->dev_private;
6584 const struct rte_flow_item *tunnel_item, *end_item, *item = rule_items;
6585 const struct rte_flow_item_integrity *mask = (typeof(mask))
6586 integrity_item->mask;
6587 const struct rte_flow_item_integrity *spec = (typeof(spec))
6588 integrity_item->spec;
6591 if (!priv->config.hca_attr.pkt_integrity_match)
6592 return rte_flow_error_set(error, ENOTSUP,
6593 RTE_FLOW_ERROR_TYPE_ITEM,
6595 "packet integrity integrity_item not supported");
6597 mask = &rte_flow_item_integrity_mask;
6598 if (!mlx5_validate_integrity_item(mask))
6599 return rte_flow_error_set(error, ENOTSUP,
6600 RTE_FLOW_ERROR_TYPE_ITEM,
6602 "unsupported integrity filter");
6603 tunnel_item = mlx5_flow_find_tunnel_item(rule_items);
6604 if (spec->level > 1) {
6606 return rte_flow_error_set(error, ENOTSUP,
6607 RTE_FLOW_ERROR_TYPE_ITEM,
6609 "missing tunnel item");
6611 end_item = mlx5_find_end_item(tunnel_item);
6613 end_item = tunnel_item ? tunnel_item :
6614 mlx5_find_end_item(integrity_item);
6616 if (mask->l3_ok || mask->ipv4_csum_ok) {
6617 protocol = mlx5_flow_locate_proto_l3(&item, end_item);
6619 return rte_flow_error_set(error, EINVAL,
6620 RTE_FLOW_ERROR_TYPE_ITEM,
6622 "missing L3 protocol");
6624 if (mask->l4_ok || mask->l4_csum_ok) {
6625 protocol = mlx5_flow_locate_proto_l4(&item, end_item);
6627 return rte_flow_error_set(error, EINVAL,
6628 RTE_FLOW_ERROR_TYPE_ITEM,
6630 "missing L4 protocol");
6636 * Internal validation function. For validating both actions and items.
6639 * Pointer to the rte_eth_dev structure.
6641 * Pointer to the flow attributes.
6643 * Pointer to the list of items.
6644 * @param[in] actions
6645 * Pointer to the list of actions.
6646 * @param[in] external
6647 * This flow rule is created by request external to PMD.
6648 * @param[in] hairpin
6649 * Number of hairpin TX actions, 0 means classic flow.
6651 * Pointer to the error structure.
6654 * 0 on success, a negative errno value otherwise and rte_errno is set.
6657 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
6658 const struct rte_flow_item items[],
6659 const struct rte_flow_action actions[],
6660 bool external, int hairpin, struct rte_flow_error *error)
6663 uint64_t action_flags = 0;
6664 uint64_t item_flags = 0;
6665 uint64_t last_item = 0;
6666 uint8_t next_protocol = 0xff;
6667 uint16_t ether_type = 0;
6669 uint8_t item_ipv6_proto = 0;
6670 int fdb_mirror_limit = 0;
6671 int modify_after_mirror = 0;
6672 const struct rte_flow_item *geneve_item = NULL;
6673 const struct rte_flow_item *gre_item = NULL;
6674 const struct rte_flow_item *gtp_item = NULL;
6675 const struct rte_flow_action_raw_decap *decap;
6676 const struct rte_flow_action_raw_encap *encap;
6677 const struct rte_flow_action_rss *rss = NULL;
6678 const struct rte_flow_action_rss *sample_rss = NULL;
6679 const struct rte_flow_action_count *sample_count = NULL;
6680 const struct rte_flow_item_tcp nic_tcp_mask = {
6683 .src_port = RTE_BE16(UINT16_MAX),
6684 .dst_port = RTE_BE16(UINT16_MAX),
6687 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
6690 "\xff\xff\xff\xff\xff\xff\xff\xff"
6691 "\xff\xff\xff\xff\xff\xff\xff\xff",
6693 "\xff\xff\xff\xff\xff\xff\xff\xff"
6694 "\xff\xff\xff\xff\xff\xff\xff\xff",
6695 .vtc_flow = RTE_BE32(0xffffffff),
6701 const struct rte_flow_item_ecpri nic_ecpri_mask = {
6705 RTE_BE32(((const struct rte_ecpri_common_hdr) {
6709 .dummy[0] = 0xffffffff,
6712 struct mlx5_priv *priv = dev->data->dev_private;
6713 struct mlx5_dev_config *dev_conf = &priv->config;
6714 uint16_t queue_index = 0xFFFF;
6715 const struct rte_flow_item_vlan *vlan_m = NULL;
6716 uint32_t rw_act_num = 0;
6718 const struct mlx5_flow_tunnel *tunnel;
6719 enum mlx5_tof_rule_type tof_rule_type;
6720 struct flow_grp_info grp_info = {
6721 .external = !!external,
6722 .transfer = !!attr->transfer,
6723 .fdb_def_rule = !!priv->fdb_def_rule,
6724 .std_tbl_fix = true,
6726 const struct rte_eth_hairpin_conf *conf;
6727 const struct rte_flow_item *rule_items = items;
6728 const struct rte_flow_item *port_id_item = NULL;
6729 bool def_policy = false;
6733 tunnel = is_tunnel_offload_active(dev) ?
6734 mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
6736 if (priv->representor)
6737 return rte_flow_error_set
6739 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6740 NULL, "decap not supported for VF representor");
6741 if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
6742 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6743 else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
6744 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
6745 MLX5_FLOW_ACTION_DECAP;
6746 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
6747 (dev, attr, tunnel, tof_rule_type);
6749 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
6752 is_root = (uint64_t)ret;
6753 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6754 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
6755 int type = items->type;
6757 if (!mlx5_flow_os_item_supported(type))
6758 return rte_flow_error_set(error, ENOTSUP,
6759 RTE_FLOW_ERROR_TYPE_ITEM,
6760 NULL, "item not supported");
6762 case RTE_FLOW_ITEM_TYPE_VOID:
6764 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6765 ret = flow_dv_validate_item_port_id
6766 (dev, items, attr, item_flags, error);
6769 last_item = MLX5_FLOW_ITEM_PORT_ID;
6770 port_id_item = items;
6772 case RTE_FLOW_ITEM_TYPE_ETH:
6773 ret = mlx5_flow_validate_item_eth(items, item_flags,
6777 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
6778 MLX5_FLOW_LAYER_OUTER_L2;
6779 if (items->mask != NULL && items->spec != NULL) {
6781 ((const struct rte_flow_item_eth *)
6784 ((const struct rte_flow_item_eth *)
6786 ether_type = rte_be_to_cpu_16(ether_type);
6791 case RTE_FLOW_ITEM_TYPE_VLAN:
6792 ret = flow_dv_validate_item_vlan(items, item_flags,
6796 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
6797 MLX5_FLOW_LAYER_OUTER_VLAN;
6798 if (items->mask != NULL && items->spec != NULL) {
6800 ((const struct rte_flow_item_vlan *)
6801 items->spec)->inner_type;
6803 ((const struct rte_flow_item_vlan *)
6804 items->mask)->inner_type;
6805 ether_type = rte_be_to_cpu_16(ether_type);
6809 /* Store outer VLAN mask for of_push_vlan action. */
6811 vlan_m = items->mask;
6813 case RTE_FLOW_ITEM_TYPE_IPV4:
6814 mlx5_flow_tunnel_ip_check(items, next_protocol,
6815 &item_flags, &tunnel);
6816 ret = flow_dv_validate_item_ipv4(items, item_flags,
6817 last_item, ether_type,
6821 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
6822 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
6823 if (items->mask != NULL &&
6824 ((const struct rte_flow_item_ipv4 *)
6825 items->mask)->hdr.next_proto_id) {
6827 ((const struct rte_flow_item_ipv4 *)
6828 (items->spec))->hdr.next_proto_id;
6830 ((const struct rte_flow_item_ipv4 *)
6831 (items->mask))->hdr.next_proto_id;
6833 /* Reset for inner layer. */
6834 next_protocol = 0xff;
6837 case RTE_FLOW_ITEM_TYPE_IPV6:
6838 mlx5_flow_tunnel_ip_check(items, next_protocol,
6839 &item_flags, &tunnel);
6840 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
6847 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
6848 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
6849 if (items->mask != NULL &&
6850 ((const struct rte_flow_item_ipv6 *)
6851 items->mask)->hdr.proto) {
6853 ((const struct rte_flow_item_ipv6 *)
6854 items->spec)->hdr.proto;
6856 ((const struct rte_flow_item_ipv6 *)
6857 items->spec)->hdr.proto;
6859 ((const struct rte_flow_item_ipv6 *)
6860 items->mask)->hdr.proto;
6862 /* Reset for inner layer. */
6863 next_protocol = 0xff;
6866 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
6867 ret = flow_dv_validate_item_ipv6_frag_ext(items,
6872 last_item = tunnel ?
6873 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
6874 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
6875 if (items->mask != NULL &&
6876 ((const struct rte_flow_item_ipv6_frag_ext *)
6877 items->mask)->hdr.next_header) {
6879 ((const struct rte_flow_item_ipv6_frag_ext *)
6880 items->spec)->hdr.next_header;
6882 ((const struct rte_flow_item_ipv6_frag_ext *)
6883 items->mask)->hdr.next_header;
6885 /* Reset for inner layer. */
6886 next_protocol = 0xff;
6889 case RTE_FLOW_ITEM_TYPE_TCP:
6890 ret = mlx5_flow_validate_item_tcp
6897 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
6898 MLX5_FLOW_LAYER_OUTER_L4_TCP;
6900 case RTE_FLOW_ITEM_TYPE_UDP:
6901 ret = mlx5_flow_validate_item_udp(items, item_flags,
6906 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
6907 MLX5_FLOW_LAYER_OUTER_L4_UDP;
6909 case RTE_FLOW_ITEM_TYPE_GRE:
6910 ret = mlx5_flow_validate_item_gre(items, item_flags,
6911 next_protocol, error);
6915 last_item = MLX5_FLOW_LAYER_GRE;
6917 case RTE_FLOW_ITEM_TYPE_NVGRE:
6918 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
6923 last_item = MLX5_FLOW_LAYER_NVGRE;
6925 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6926 ret = mlx5_flow_validate_item_gre_key
6927 (items, item_flags, gre_item, error);
6930 last_item = MLX5_FLOW_LAYER_GRE_KEY;
6932 case RTE_FLOW_ITEM_TYPE_VXLAN:
6933 ret = mlx5_flow_validate_item_vxlan(dev, items,
6938 last_item = MLX5_FLOW_LAYER_VXLAN;
6940 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6941 ret = mlx5_flow_validate_item_vxlan_gpe(items,
6946 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
6948 case RTE_FLOW_ITEM_TYPE_GENEVE:
6949 ret = mlx5_flow_validate_item_geneve(items,
6954 geneve_item = items;
6955 last_item = MLX5_FLOW_LAYER_GENEVE;
6957 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
6958 ret = mlx5_flow_validate_item_geneve_opt(items,
6965 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
6967 case RTE_FLOW_ITEM_TYPE_MPLS:
6968 ret = mlx5_flow_validate_item_mpls(dev, items,
6973 last_item = MLX5_FLOW_LAYER_MPLS;
6976 case RTE_FLOW_ITEM_TYPE_MARK:
6977 ret = flow_dv_validate_item_mark(dev, items, attr,
6981 last_item = MLX5_FLOW_ITEM_MARK;
6983 case RTE_FLOW_ITEM_TYPE_META:
6984 ret = flow_dv_validate_item_meta(dev, items, attr,
6988 last_item = MLX5_FLOW_ITEM_METADATA;
6990 case RTE_FLOW_ITEM_TYPE_ICMP:
6991 ret = mlx5_flow_validate_item_icmp(items, item_flags,
6996 last_item = MLX5_FLOW_LAYER_ICMP;
6998 case RTE_FLOW_ITEM_TYPE_ICMP6:
6999 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
7004 item_ipv6_proto = IPPROTO_ICMPV6;
7005 last_item = MLX5_FLOW_LAYER_ICMP6;
7007 case RTE_FLOW_ITEM_TYPE_TAG:
7008 ret = flow_dv_validate_item_tag(dev, items,
7012 last_item = MLX5_FLOW_ITEM_TAG;
7014 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
7015 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
7017 case RTE_FLOW_ITEM_TYPE_GTP:
7018 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
7023 last_item = MLX5_FLOW_LAYER_GTP;
7025 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
7026 ret = flow_dv_validate_item_gtp_psc(items, last_item,
7031 last_item = MLX5_FLOW_LAYER_GTP_PSC;
7033 case RTE_FLOW_ITEM_TYPE_ECPRI:
7034 /* Capacity will be checked in the translate stage. */
7035 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
7042 last_item = MLX5_FLOW_LAYER_ECPRI;
7044 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
7045 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY)
7046 return rte_flow_error_set
7048 RTE_FLOW_ERROR_TYPE_ITEM,
7049 NULL, "multiple integrity items not supported");
7050 ret = flow_dv_validate_item_integrity(dev, rule_items,
7054 last_item = MLX5_FLOW_ITEM_INTEGRITY;
7056 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
7057 ret = flow_dv_validate_item_aso_ct(dev, items,
7058 &item_flags, error);
7062 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
7063 /* tunnel offload item was processed before
7064 * list it here as a supported type
7068 return rte_flow_error_set(error, ENOTSUP,
7069 RTE_FLOW_ERROR_TYPE_ITEM,
7070 NULL, "item not supported");
7072 item_flags |= last_item;
7074 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
7075 int type = actions->type;
7076 bool shared_count = false;
7078 if (!mlx5_flow_os_action_supported(type))
7079 return rte_flow_error_set(error, ENOTSUP,
7080 RTE_FLOW_ERROR_TYPE_ACTION,
7082 "action not supported");
7083 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
7084 return rte_flow_error_set(error, ENOTSUP,
7085 RTE_FLOW_ERROR_TYPE_ACTION,
7086 actions, "too many actions");
7088 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
7089 return rte_flow_error_set(error, ENOTSUP,
7090 RTE_FLOW_ERROR_TYPE_ACTION,
7091 NULL, "meter action with policy "
7092 "must be the last action");
7094 case RTE_FLOW_ACTION_TYPE_VOID:
7096 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7097 ret = flow_dv_validate_action_port_id(dev,
7104 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7107 case RTE_FLOW_ACTION_TYPE_FLAG:
7108 ret = flow_dv_validate_action_flag(dev, action_flags,
7112 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7113 /* Count all modify-header actions as one. */
7114 if (!(action_flags &
7115 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7117 action_flags |= MLX5_FLOW_ACTION_FLAG |
7118 MLX5_FLOW_ACTION_MARK_EXT;
7119 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7120 modify_after_mirror = 1;
7123 action_flags |= MLX5_FLOW_ACTION_FLAG;
7126 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7128 case RTE_FLOW_ACTION_TYPE_MARK:
7129 ret = flow_dv_validate_action_mark(dev, actions,
7134 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7135 /* Count all modify-header actions as one. */
7136 if (!(action_flags &
7137 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7139 action_flags |= MLX5_FLOW_ACTION_MARK |
7140 MLX5_FLOW_ACTION_MARK_EXT;
7141 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7142 modify_after_mirror = 1;
7144 action_flags |= MLX5_FLOW_ACTION_MARK;
7147 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7149 case RTE_FLOW_ACTION_TYPE_SET_META:
7150 ret = flow_dv_validate_action_set_meta(dev, actions,
7155 /* Count all modify-header actions as one action. */
7156 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7158 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7159 modify_after_mirror = 1;
7160 action_flags |= MLX5_FLOW_ACTION_SET_META;
7161 rw_act_num += MLX5_ACT_NUM_SET_META;
7163 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7164 ret = flow_dv_validate_action_set_tag(dev, actions,
7169 /* Count all modify-header actions as one action. */
7170 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7172 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7173 modify_after_mirror = 1;
7174 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7175 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7177 case RTE_FLOW_ACTION_TYPE_DROP:
7178 ret = mlx5_flow_validate_action_drop(action_flags,
7182 action_flags |= MLX5_FLOW_ACTION_DROP;
7185 case RTE_FLOW_ACTION_TYPE_QUEUE:
7186 ret = mlx5_flow_validate_action_queue(actions,
7191 queue_index = ((const struct rte_flow_action_queue *)
7192 (actions->conf))->index;
7193 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7196 case RTE_FLOW_ACTION_TYPE_RSS:
7197 rss = actions->conf;
7198 ret = mlx5_flow_validate_action_rss(actions,
7204 if (rss && sample_rss &&
7205 (sample_rss->level != rss->level ||
7206 sample_rss->types != rss->types))
7207 return rte_flow_error_set(error, ENOTSUP,
7208 RTE_FLOW_ERROR_TYPE_ACTION,
7210 "Can't use the different RSS types "
7211 "or level in the same flow");
7212 if (rss != NULL && rss->queue_num)
7213 queue_index = rss->queue[0];
7214 action_flags |= MLX5_FLOW_ACTION_RSS;
7217 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7219 mlx5_flow_validate_action_default_miss(action_flags,
7223 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
7226 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
7227 case RTE_FLOW_ACTION_TYPE_COUNT:
7228 shared_count = is_shared_action_count(actions);
7229 ret = flow_dv_validate_action_count(dev, shared_count,
7234 action_flags |= MLX5_FLOW_ACTION_COUNT;
7237 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7238 if (flow_dv_validate_action_pop_vlan(dev,
7244 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7245 modify_after_mirror = 1;
7246 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7249 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7250 ret = flow_dv_validate_action_push_vlan(dev,
7257 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7258 modify_after_mirror = 1;
7259 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7262 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7263 ret = flow_dv_validate_action_set_vlan_pcp
7264 (action_flags, actions, error);
7267 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7268 modify_after_mirror = 1;
7269 /* Count PCP with push_vlan command. */
7270 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
7272 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7273 ret = flow_dv_validate_action_set_vlan_vid
7274 (item_flags, action_flags,
7278 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7279 modify_after_mirror = 1;
7280 /* Count VID with push_vlan command. */
7281 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7282 rw_act_num += MLX5_ACT_NUM_MDF_VID;
7284 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7285 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7286 ret = flow_dv_validate_action_l2_encap(dev,
7292 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7295 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7296 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7297 ret = flow_dv_validate_action_decap(dev, action_flags,
7298 actions, item_flags,
7302 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7303 modify_after_mirror = 1;
7304 action_flags |= MLX5_FLOW_ACTION_DECAP;
7307 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7308 ret = flow_dv_validate_action_raw_encap_decap
7309 (dev, NULL, actions->conf, attr, &action_flags,
7310 &actions_n, actions, item_flags, error);
7314 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7315 decap = actions->conf;
7316 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
7318 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7322 encap = actions->conf;
7324 ret = flow_dv_validate_action_raw_encap_decap
7326 decap ? decap : &empty_decap, encap,
7327 attr, &action_flags, &actions_n,
7328 actions, item_flags, error);
7331 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7332 (action_flags & MLX5_FLOW_ACTION_DECAP))
7333 modify_after_mirror = 1;
7335 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7336 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7337 ret = flow_dv_validate_action_modify_mac(action_flags,
7343 /* Count all modify-header actions as one action. */
7344 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7346 action_flags |= actions->type ==
7347 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7348 MLX5_FLOW_ACTION_SET_MAC_SRC :
7349 MLX5_FLOW_ACTION_SET_MAC_DST;
7350 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7351 modify_after_mirror = 1;
7353 * Even if the source and destination MAC addresses have
7354 * overlap in the header with 4B alignment, the convert
7355 * function will handle them separately and 4 SW actions
7356 * will be created. And 2 actions will be added each
7357 * time no matter how many bytes of address will be set.
7359 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
7361 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7362 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7363 ret = flow_dv_validate_action_modify_ipv4(action_flags,
7369 /* Count all modify-header actions as one action. */
7370 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7372 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7373 modify_after_mirror = 1;
7374 action_flags |= actions->type ==
7375 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7376 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7377 MLX5_FLOW_ACTION_SET_IPV4_DST;
7378 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
7380 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7381 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7382 ret = flow_dv_validate_action_modify_ipv6(action_flags,
7388 if (item_ipv6_proto == IPPROTO_ICMPV6)
7389 return rte_flow_error_set(error, ENOTSUP,
7390 RTE_FLOW_ERROR_TYPE_ACTION,
7392 "Can't change header "
7393 "with ICMPv6 proto");
7394 /* Count all modify-header actions as one action. */
7395 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7397 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7398 modify_after_mirror = 1;
7399 action_flags |= actions->type ==
7400 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7401 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7402 MLX5_FLOW_ACTION_SET_IPV6_DST;
7403 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
7405 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7406 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7407 ret = flow_dv_validate_action_modify_tp(action_flags,
7413 /* Count all modify-header actions as one action. */
7414 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7416 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7417 modify_after_mirror = 1;
7418 action_flags |= actions->type ==
7419 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7420 MLX5_FLOW_ACTION_SET_TP_SRC :
7421 MLX5_FLOW_ACTION_SET_TP_DST;
7422 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
7424 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7425 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7426 ret = flow_dv_validate_action_modify_ttl(action_flags,
7432 /* Count all modify-header actions as one action. */
7433 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7435 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7436 modify_after_mirror = 1;
7437 action_flags |= actions->type ==
7438 RTE_FLOW_ACTION_TYPE_SET_TTL ?
7439 MLX5_FLOW_ACTION_SET_TTL :
7440 MLX5_FLOW_ACTION_DEC_TTL;
7441 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
7443 case RTE_FLOW_ACTION_TYPE_JUMP:
7444 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
7450 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7452 return rte_flow_error_set(error, EINVAL,
7453 RTE_FLOW_ERROR_TYPE_ACTION,
7455 "sample and jump action combination is not supported");
7457 action_flags |= MLX5_FLOW_ACTION_JUMP;
7459 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7460 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7461 ret = flow_dv_validate_action_modify_tcp_seq
7468 /* Count all modify-header actions as one action. */
7469 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7471 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7472 modify_after_mirror = 1;
7473 action_flags |= actions->type ==
7474 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7475 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7476 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7477 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
7479 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7480 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7481 ret = flow_dv_validate_action_modify_tcp_ack
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_INC_TCP_ACK ?
7495 MLX5_FLOW_ACTION_INC_TCP_ACK :
7496 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7497 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
7499 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7501 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7502 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7503 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7505 case RTE_FLOW_ACTION_TYPE_METER:
7506 ret = mlx5_flow_validate_action_meter(dev,
7514 action_flags |= MLX5_FLOW_ACTION_METER;
7517 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
7519 /* Meter action will add one more TAG action. */
7520 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7522 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
7523 if (!attr->transfer && !attr->group)
7524 return rte_flow_error_set(error, ENOTSUP,
7525 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7527 "Shared ASO age action is not supported for group 0");
7528 if (action_flags & MLX5_FLOW_ACTION_AGE)
7529 return rte_flow_error_set
7531 RTE_FLOW_ERROR_TYPE_ACTION,
7533 "duplicate age actions set");
7534 action_flags |= MLX5_FLOW_ACTION_AGE;
7537 case RTE_FLOW_ACTION_TYPE_AGE:
7538 ret = flow_dv_validate_action_age(action_flags,
7544 * Validate the regular AGE action (using counter)
7545 * mutual exclusion with share counter actions.
7547 if (!priv->sh->flow_hit_aso_en) {
7549 return rte_flow_error_set
7551 RTE_FLOW_ERROR_TYPE_ACTION,
7553 "old age and shared count combination is not supported");
7555 return rte_flow_error_set
7557 RTE_FLOW_ERROR_TYPE_ACTION,
7559 "old age action and count must be in the same sub flow");
7561 action_flags |= MLX5_FLOW_ACTION_AGE;
7564 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7565 ret = flow_dv_validate_action_modify_ipv4_dscp
7572 /* Count all modify-header actions as one action. */
7573 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7575 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7576 modify_after_mirror = 1;
7577 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7578 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7580 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7581 ret = flow_dv_validate_action_modify_ipv6_dscp
7588 /* Count all modify-header actions as one action. */
7589 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7591 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7592 modify_after_mirror = 1;
7593 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7594 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7596 case RTE_FLOW_ACTION_TYPE_SAMPLE:
7597 ret = flow_dv_validate_action_sample(&action_flags,
7606 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
7609 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7610 ret = flow_dv_validate_action_modify_field(dev,
7617 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7618 modify_after_mirror = 1;
7619 /* Count all modify-header actions as one action. */
7620 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7622 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
7625 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7626 ret = flow_dv_validate_action_aso_ct(dev, action_flags,
7631 action_flags |= MLX5_FLOW_ACTION_CT;
7633 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
7634 /* tunnel offload action was processed before
7635 * list it here as a supported type
7639 return rte_flow_error_set(error, ENOTSUP,
7640 RTE_FLOW_ERROR_TYPE_ACTION,
7642 "action not supported");
7646 * Validate actions in flow rules
7647 * - Explicit decap action is prohibited by the tunnel offload API.
7648 * - Drop action in tunnel steer rule is prohibited by the API.
7649 * - Application cannot use MARK action because it's value can mask
7650 * tunnel default miss nitification.
7651 * - JUMP in tunnel match rule has no support in current PMD
7653 * - TAG & META are reserved for future uses.
7655 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
7656 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
7657 MLX5_FLOW_ACTION_MARK |
7658 MLX5_FLOW_ACTION_SET_TAG |
7659 MLX5_FLOW_ACTION_SET_META |
7660 MLX5_FLOW_ACTION_DROP;
7662 if (action_flags & bad_actions_mask)
7663 return rte_flow_error_set
7665 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7666 "Invalid RTE action in tunnel "
7668 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
7669 return rte_flow_error_set
7671 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7672 "tunnel set decap rule must terminate "
7675 return rte_flow_error_set
7677 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7678 "tunnel flows for ingress traffic only");
7680 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
7681 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
7682 MLX5_FLOW_ACTION_MARK |
7683 MLX5_FLOW_ACTION_SET_TAG |
7684 MLX5_FLOW_ACTION_SET_META;
7686 if (action_flags & bad_actions_mask)
7687 return rte_flow_error_set
7689 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7690 "Invalid RTE action in tunnel "
7694 * Validate the drop action mutual exclusion with other actions.
7695 * Drop action is mutually-exclusive with any other action, except for
7697 * Drop action compatibility with tunnel offload was already validated.
7699 if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
7700 MLX5_FLOW_ACTION_TUNNEL_MATCH));
7701 else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
7702 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
7703 return rte_flow_error_set(error, EINVAL,
7704 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7705 "Drop action is mutually-exclusive "
7706 "with any other action, except for "
7708 /* Eswitch has few restrictions on using items and actions */
7709 if (attr->transfer) {
7710 if (!mlx5_flow_ext_mreg_supported(dev) &&
7711 action_flags & MLX5_FLOW_ACTION_FLAG)
7712 return rte_flow_error_set(error, ENOTSUP,
7713 RTE_FLOW_ERROR_TYPE_ACTION,
7715 "unsupported action FLAG");
7716 if (!mlx5_flow_ext_mreg_supported(dev) &&
7717 action_flags & MLX5_FLOW_ACTION_MARK)
7718 return rte_flow_error_set(error, ENOTSUP,
7719 RTE_FLOW_ERROR_TYPE_ACTION,
7721 "unsupported action MARK");
7722 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
7723 return rte_flow_error_set(error, ENOTSUP,
7724 RTE_FLOW_ERROR_TYPE_ACTION,
7726 "unsupported action QUEUE");
7727 if (action_flags & MLX5_FLOW_ACTION_RSS)
7728 return rte_flow_error_set(error, ENOTSUP,
7729 RTE_FLOW_ERROR_TYPE_ACTION,
7731 "unsupported action RSS");
7732 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
7733 return rte_flow_error_set(error, EINVAL,
7734 RTE_FLOW_ERROR_TYPE_ACTION,
7736 "no fate action is found");
7738 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
7739 return rte_flow_error_set(error, EINVAL,
7740 RTE_FLOW_ERROR_TYPE_ACTION,
7742 "no fate action is found");
7745 * Continue validation for Xcap and VLAN actions.
7746 * If hairpin is working in explicit TX rule mode, there is no actions
7747 * splitting and the validation of hairpin ingress flow should be the
7748 * same as other standard flows.
7750 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
7751 MLX5_FLOW_VLAN_ACTIONS)) &&
7752 (queue_index == 0xFFFF ||
7753 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN ||
7754 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
7755 conf->tx_explicit != 0))) {
7756 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
7757 MLX5_FLOW_XCAP_ACTIONS)
7758 return rte_flow_error_set(error, ENOTSUP,
7759 RTE_FLOW_ERROR_TYPE_ACTION,
7760 NULL, "encap and decap "
7761 "combination aren't supported");
7762 if (!attr->transfer && attr->ingress) {
7763 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7764 return rte_flow_error_set
7766 RTE_FLOW_ERROR_TYPE_ACTION,
7767 NULL, "encap is not supported"
7768 " for ingress traffic");
7769 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7770 return rte_flow_error_set
7772 RTE_FLOW_ERROR_TYPE_ACTION,
7773 NULL, "push VLAN action not "
7774 "supported for ingress");
7775 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
7776 MLX5_FLOW_VLAN_ACTIONS)
7777 return rte_flow_error_set
7779 RTE_FLOW_ERROR_TYPE_ACTION,
7780 NULL, "no support for "
7781 "multiple VLAN actions");
7784 if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
7785 if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
7786 ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
7788 return rte_flow_error_set
7790 RTE_FLOW_ERROR_TYPE_ACTION,
7791 NULL, "fate action not supported for "
7792 "meter with policy");
7794 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
7795 return rte_flow_error_set
7797 RTE_FLOW_ERROR_TYPE_ACTION,
7798 NULL, "modify header action in egress "
7799 "cannot be done before meter action");
7800 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7801 return rte_flow_error_set
7803 RTE_FLOW_ERROR_TYPE_ACTION,
7804 NULL, "encap action in egress "
7805 "cannot be done before meter action");
7806 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7807 return rte_flow_error_set
7809 RTE_FLOW_ERROR_TYPE_ACTION,
7810 NULL, "push vlan action in egress "
7811 "cannot be done before meter action");
7815 * Hairpin flow will add one more TAG action in TX implicit mode.
7816 * In TX explicit mode, there will be no hairpin flow ID.
7819 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7820 /* extra metadata enabled: one more TAG action will be add. */
7821 if (dev_conf->dv_flow_en &&
7822 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
7823 mlx5_flow_ext_mreg_supported(dev))
7824 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7826 flow_dv_modify_hdr_action_max(dev, is_root)) {
7827 return rte_flow_error_set(error, ENOTSUP,
7828 RTE_FLOW_ERROR_TYPE_ACTION,
7829 NULL, "too many header modify"
7830 " actions to support");
7832 /* Eswitch egress mirror and modify flow has limitation on CX5 */
7833 if (fdb_mirror_limit && modify_after_mirror)
7834 return rte_flow_error_set(error, EINVAL,
7835 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7836 "sample before modify action is not supported");
7841 * Internal preparation function. Allocates the DV flow size,
7842 * this size is constant.
7845 * Pointer to the rte_eth_dev structure.
7847 * Pointer to the flow attributes.
7849 * Pointer to the list of items.
7850 * @param[in] actions
7851 * Pointer to the list of actions.
7853 * Pointer to the error structure.
7856 * Pointer to mlx5_flow object on success,
7857 * otherwise NULL and rte_errno is set.
7859 static struct mlx5_flow *
7860 flow_dv_prepare(struct rte_eth_dev *dev,
7861 const struct rte_flow_attr *attr __rte_unused,
7862 const struct rte_flow_item items[] __rte_unused,
7863 const struct rte_flow_action actions[] __rte_unused,
7864 struct rte_flow_error *error)
7866 uint32_t handle_idx = 0;
7867 struct mlx5_flow *dev_flow;
7868 struct mlx5_flow_handle *dev_handle;
7869 struct mlx5_priv *priv = dev->data->dev_private;
7870 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
7873 wks->skip_matcher_reg = 0;
7875 wks->final_policy = NULL;
7876 /* In case of corrupting the memory. */
7877 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
7878 rte_flow_error_set(error, ENOSPC,
7879 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7880 "not free temporary device flow");
7883 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
7886 rte_flow_error_set(error, ENOMEM,
7887 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7888 "not enough memory to create flow handle");
7891 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
7892 dev_flow = &wks->flows[wks->flow_idx++];
7893 memset(dev_flow, 0, sizeof(*dev_flow));
7894 dev_flow->handle = dev_handle;
7895 dev_flow->handle_idx = handle_idx;
7896 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
7897 dev_flow->ingress = attr->ingress;
7898 dev_flow->dv.transfer = attr->transfer;
7902 #ifdef RTE_LIBRTE_MLX5_DEBUG
7904 * Sanity check for match mask and value. Similar to check_valid_spec() in
7905 * kernel driver. If unmasked bit is present in value, it returns failure.
7908 * pointer to match mask buffer.
7909 * @param match_value
7910 * pointer to match value buffer.
7913 * 0 if valid, -EINVAL otherwise.
7916 flow_dv_check_valid_spec(void *match_mask, void *match_value)
7918 uint8_t *m = match_mask;
7919 uint8_t *v = match_value;
7922 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
7925 "match_value differs from match_criteria"
7926 " %p[%u] != %p[%u]",
7927 match_value, i, match_mask, i);
7936 * Add match of ip_version.
7940 * @param[in] headers_v
7941 * Values header pointer.
7942 * @param[in] headers_m
7943 * Masks header pointer.
7944 * @param[in] ip_version
7945 * The IP version to set.
7948 flow_dv_set_match_ip_version(uint32_t group,
7954 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
7956 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
7958 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
7959 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
7960 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
7964 * Add Ethernet item to matcher and to the value.
7966 * @param[in, out] matcher
7968 * @param[in, out] key
7969 * Flow matcher value.
7971 * Flow pattern to translate.
7973 * Item is inner pattern.
7976 flow_dv_translate_item_eth(void *matcher, void *key,
7977 const struct rte_flow_item *item, int inner,
7980 const struct rte_flow_item_eth *eth_m = item->mask;
7981 const struct rte_flow_item_eth *eth_v = item->spec;
7982 const struct rte_flow_item_eth nic_mask = {
7983 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
7984 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
7985 .type = RTE_BE16(0xffff),
7998 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8000 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8002 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8004 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8006 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
8007 ð_m->dst, sizeof(eth_m->dst));
8008 /* The value must be in the range of the mask. */
8009 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
8010 for (i = 0; i < sizeof(eth_m->dst); ++i)
8011 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
8012 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
8013 ð_m->src, sizeof(eth_m->src));
8014 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
8015 /* The value must be in the range of the mask. */
8016 for (i = 0; i < sizeof(eth_m->dst); ++i)
8017 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
8019 * HW supports match on one Ethertype, the Ethertype following the last
8020 * VLAN tag of the packet (see PRM).
8021 * Set match on ethertype only if ETH header is not followed by VLAN.
8022 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8023 * ethertype, and use ip_version field instead.
8024 * eCPRI over Ether layer will use type value 0xAEFE.
8026 if (eth_m->type == 0xFFFF) {
8027 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
8028 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8029 switch (eth_v->type) {
8030 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8031 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8033 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
8034 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8035 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8037 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8038 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8040 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8041 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8047 if (eth_m->has_vlan) {
8048 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8049 if (eth_v->has_vlan) {
8051 * Here, when also has_more_vlan field in VLAN item is
8052 * not set, only single-tagged packets will be matched.
8054 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8058 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8059 rte_be_to_cpu_16(eth_m->type));
8060 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
8061 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
8065 * Add VLAN item to matcher and to the value.
8067 * @param[in, out] dev_flow
8069 * @param[in, out] matcher
8071 * @param[in, out] key
8072 * Flow matcher value.
8074 * Flow pattern to translate.
8076 * Item is inner pattern.
8079 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
8080 void *matcher, void *key,
8081 const struct rte_flow_item *item,
8082 int inner, uint32_t group)
8084 const struct rte_flow_item_vlan *vlan_m = item->mask;
8085 const struct rte_flow_item_vlan *vlan_v = item->spec;
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 * This is workaround, masks are not supported,
8101 * and pre-validated.
8104 dev_flow->handle->vf_vlan.tag =
8105 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
8108 * When VLAN item exists in flow, mark packet as tagged,
8109 * even if TCI is not specified.
8111 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
8112 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8113 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8118 vlan_m = &rte_flow_item_vlan_mask;
8119 tci_m = rte_be_to_cpu_16(vlan_m->tci);
8120 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
8121 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
8122 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
8123 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
8124 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
8125 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
8126 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
8128 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8129 * ethertype, and use ip_version field instead.
8131 if (vlan_m->inner_type == 0xFFFF) {
8132 switch (vlan_v->inner_type) {
8133 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8134 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8135 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8136 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8138 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8139 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8141 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8142 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8148 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
8149 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8150 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8151 /* Only one vlan_tag bit can be set. */
8152 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8155 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8156 rte_be_to_cpu_16(vlan_m->inner_type));
8157 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
8158 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
8162 * Add IPV4 item to matcher and to the value.
8164 * @param[in, out] matcher
8166 * @param[in, out] key
8167 * Flow matcher value.
8169 * Flow pattern to translate.
8171 * Item is inner pattern.
8173 * The group to insert the rule.
8176 flow_dv_translate_item_ipv4(void *matcher, void *key,
8177 const struct rte_flow_item *item,
8178 int inner, uint32_t group)
8180 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
8181 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
8182 const struct rte_flow_item_ipv4 nic_mask = {
8184 .src_addr = RTE_BE32(0xffffffff),
8185 .dst_addr = RTE_BE32(0xffffffff),
8186 .type_of_service = 0xff,
8187 .next_proto_id = 0xff,
8188 .time_to_live = 0xff,
8198 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8200 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8202 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8204 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8206 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
8211 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8212 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8213 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8214 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8215 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
8216 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
8217 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8218 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8219 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8220 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8221 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
8222 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
8223 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
8224 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
8225 ipv4_m->hdr.type_of_service);
8226 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
8227 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
8228 ipv4_m->hdr.type_of_service >> 2);
8229 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
8230 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8231 ipv4_m->hdr.next_proto_id);
8232 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8233 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
8234 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8235 ipv4_m->hdr.time_to_live);
8236 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8237 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
8238 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8239 !!(ipv4_m->hdr.fragment_offset));
8240 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8241 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
8245 * Add IPV6 item to matcher and to the value.
8247 * @param[in, out] matcher
8249 * @param[in, out] key
8250 * Flow matcher value.
8252 * Flow pattern to translate.
8254 * Item is inner pattern.
8256 * The group to insert the rule.
8259 flow_dv_translate_item_ipv6(void *matcher, void *key,
8260 const struct rte_flow_item *item,
8261 int inner, uint32_t group)
8263 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
8264 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
8265 const struct rte_flow_item_ipv6 nic_mask = {
8268 "\xff\xff\xff\xff\xff\xff\xff\xff"
8269 "\xff\xff\xff\xff\xff\xff\xff\xff",
8271 "\xff\xff\xff\xff\xff\xff\xff\xff"
8272 "\xff\xff\xff\xff\xff\xff\xff\xff",
8273 .vtc_flow = RTE_BE32(0xffffffff),
8280 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8281 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8290 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8292 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8294 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8296 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8298 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
8303 size = sizeof(ipv6_m->hdr.dst_addr);
8304 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8305 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8306 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8307 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8308 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
8309 for (i = 0; i < size; ++i)
8310 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
8311 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8312 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8313 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8314 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8315 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
8316 for (i = 0; i < size; ++i)
8317 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
8319 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
8320 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
8321 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
8322 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
8323 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
8324 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
8327 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
8329 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
8332 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
8334 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
8338 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8340 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8341 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
8343 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8344 ipv6_m->hdr.hop_limits);
8345 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8346 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
8347 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8348 !!(ipv6_m->has_frag_ext));
8349 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8350 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
8354 * Add IPV6 fragment extension item to matcher and to the value.
8356 * @param[in, out] matcher
8358 * @param[in, out] key
8359 * Flow matcher value.
8361 * Flow pattern to translate.
8363 * Item is inner pattern.
8366 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
8367 const struct rte_flow_item *item,
8370 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
8371 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
8372 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
8374 .next_header = 0xff,
8375 .frag_data = RTE_BE16(0xffff),
8382 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8384 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8386 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8388 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8390 /* IPv6 fragment extension item exists, so packet is IP fragment. */
8391 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
8392 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
8393 if (!ipv6_frag_ext_v)
8395 if (!ipv6_frag_ext_m)
8396 ipv6_frag_ext_m = &nic_mask;
8397 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8398 ipv6_frag_ext_m->hdr.next_header);
8399 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8400 ipv6_frag_ext_v->hdr.next_header &
8401 ipv6_frag_ext_m->hdr.next_header);
8405 * Add TCP item to matcher and to the value.
8407 * @param[in, out] matcher
8409 * @param[in, out] key
8410 * Flow matcher value.
8412 * Flow pattern to translate.
8414 * Item is inner pattern.
8417 flow_dv_translate_item_tcp(void *matcher, void *key,
8418 const struct rte_flow_item *item,
8421 const struct rte_flow_item_tcp *tcp_m = item->mask;
8422 const struct rte_flow_item_tcp *tcp_v = item->spec;
8427 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8429 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8431 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8433 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8435 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8436 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
8440 tcp_m = &rte_flow_item_tcp_mask;
8441 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
8442 rte_be_to_cpu_16(tcp_m->hdr.src_port));
8443 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
8444 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
8445 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
8446 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
8447 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
8448 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
8449 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
8450 tcp_m->hdr.tcp_flags);
8451 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
8452 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
8456 * Add UDP item to matcher and to the value.
8458 * @param[in, out] matcher
8460 * @param[in, out] key
8461 * Flow matcher value.
8463 * Flow pattern to translate.
8465 * Item is inner pattern.
8468 flow_dv_translate_item_udp(void *matcher, void *key,
8469 const struct rte_flow_item *item,
8472 const struct rte_flow_item_udp *udp_m = item->mask;
8473 const struct rte_flow_item_udp *udp_v = item->spec;
8478 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8480 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8482 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8484 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8486 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8487 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
8491 udp_m = &rte_flow_item_udp_mask;
8492 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
8493 rte_be_to_cpu_16(udp_m->hdr.src_port));
8494 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
8495 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
8496 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
8497 rte_be_to_cpu_16(udp_m->hdr.dst_port));
8498 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8499 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
8503 * Add GRE optional Key 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_gre_key(void *matcher, void *key,
8516 const struct rte_flow_item *item)
8518 const rte_be32_t *key_m = item->mask;
8519 const rte_be32_t *key_v = item->spec;
8520 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8521 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8522 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
8524 /* GRE K bit must be on and should already be validated */
8525 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
8526 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
8530 key_m = &gre_key_default_mask;
8531 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
8532 rte_be_to_cpu_32(*key_m) >> 8);
8533 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
8534 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
8535 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
8536 rte_be_to_cpu_32(*key_m) & 0xFF);
8537 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
8538 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
8542 * Add GRE item to matcher and to the value.
8544 * @param[in, out] matcher
8546 * @param[in, out] key
8547 * Flow matcher value.
8549 * Flow pattern to translate.
8551 * Item is inner pattern.
8554 flow_dv_translate_item_gre(void *matcher, void *key,
8555 const struct rte_flow_item *item,
8558 const struct rte_flow_item_gre *gre_m = item->mask;
8559 const struct rte_flow_item_gre *gre_v = item->spec;
8562 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8563 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8570 uint16_t s_present:1;
8571 uint16_t k_present:1;
8572 uint16_t rsvd_bit1:1;
8573 uint16_t c_present:1;
8577 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
8580 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8582 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8584 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8586 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8588 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8589 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
8593 gre_m = &rte_flow_item_gre_mask;
8594 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
8595 rte_be_to_cpu_16(gre_m->protocol));
8596 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8597 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
8598 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
8599 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
8600 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
8601 gre_crks_rsvd0_ver_m.c_present);
8602 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
8603 gre_crks_rsvd0_ver_v.c_present &
8604 gre_crks_rsvd0_ver_m.c_present);
8605 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
8606 gre_crks_rsvd0_ver_m.k_present);
8607 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
8608 gre_crks_rsvd0_ver_v.k_present &
8609 gre_crks_rsvd0_ver_m.k_present);
8610 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
8611 gre_crks_rsvd0_ver_m.s_present);
8612 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
8613 gre_crks_rsvd0_ver_v.s_present &
8614 gre_crks_rsvd0_ver_m.s_present);
8618 * Add NVGRE item to matcher and to the value.
8620 * @param[in, out] matcher
8622 * @param[in, out] key
8623 * Flow matcher value.
8625 * Flow pattern to translate.
8627 * Item is inner pattern.
8630 flow_dv_translate_item_nvgre(void *matcher, void *key,
8631 const struct rte_flow_item *item,
8634 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
8635 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
8636 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8637 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8638 const char *tni_flow_id_m;
8639 const char *tni_flow_id_v;
8645 /* For NVGRE, GRE header fields must be set with defined values. */
8646 const struct rte_flow_item_gre gre_spec = {
8647 .c_rsvd0_ver = RTE_BE16(0x2000),
8648 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
8650 const struct rte_flow_item_gre gre_mask = {
8651 .c_rsvd0_ver = RTE_BE16(0xB000),
8652 .protocol = RTE_BE16(UINT16_MAX),
8654 const struct rte_flow_item gre_item = {
8659 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
8663 nvgre_m = &rte_flow_item_nvgre_mask;
8664 tni_flow_id_m = (const char *)nvgre_m->tni;
8665 tni_flow_id_v = (const char *)nvgre_v->tni;
8666 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
8667 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
8668 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
8669 memcpy(gre_key_m, tni_flow_id_m, size);
8670 for (i = 0; i < size; ++i)
8671 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
8675 * Add VXLAN item to matcher and to the value.
8678 * Pointer to the Ethernet device structure.
8680 * Flow rule attributes.
8681 * @param[in, out] matcher
8683 * @param[in, out] key
8684 * Flow matcher value.
8686 * Flow pattern to translate.
8688 * Item is inner pattern.
8691 flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
8692 const struct rte_flow_attr *attr,
8693 void *matcher, void *key,
8694 const struct rte_flow_item *item,
8697 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
8698 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
8703 uint32_t *tunnel_header_v;
8704 uint32_t *tunnel_header_m;
8706 struct mlx5_priv *priv = dev->data->dev_private;
8707 const struct rte_flow_item_vxlan nic_mask = {
8708 .vni = "\xff\xff\xff",
8713 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8715 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8717 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8719 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8721 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8722 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8723 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8724 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8725 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8730 if ((!attr->group && !priv->sh->tunnel_header_0_1) ||
8731 (attr->group && !priv->sh->misc5_cap))
8732 vxlan_m = &rte_flow_item_vxlan_mask;
8734 vxlan_m = &nic_mask;
8736 if ((!attr->group && !attr->transfer && !priv->sh->tunnel_header_0_1) ||
8737 ((attr->group || attr->transfer) && !priv->sh->misc5_cap)) {
8744 misc_m = MLX5_ADDR_OF(fte_match_param,
8745 matcher, misc_parameters);
8746 misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8747 size = sizeof(vxlan_m->vni);
8748 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
8749 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
8750 memcpy(vni_m, vxlan_m->vni, size);
8751 for (i = 0; i < size; ++i)
8752 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8755 misc5_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_5);
8756 misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
8757 tunnel_header_v = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
8760 tunnel_header_m = (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc5,
8763 *tunnel_header_v = (vxlan_v->vni[0] & vxlan_m->vni[0]) |
8764 (vxlan_v->vni[1] & vxlan_m->vni[1]) << 8 |
8765 (vxlan_v->vni[2] & vxlan_m->vni[2]) << 16;
8766 if (*tunnel_header_v)
8767 *tunnel_header_m = vxlan_m->vni[0] |
8768 vxlan_m->vni[1] << 8 |
8769 vxlan_m->vni[2] << 16;
8771 *tunnel_header_m = 0x0;
8772 *tunnel_header_v |= (vxlan_v->rsvd1 & vxlan_m->rsvd1) << 24;
8773 if (vxlan_v->rsvd1 & vxlan_m->rsvd1)
8774 *tunnel_header_m |= vxlan_m->rsvd1 << 24;
8778 * Add VXLAN-GPE item to matcher and to the value.
8780 * @param[in, out] matcher
8782 * @param[in, out] key
8783 * Flow matcher value.
8785 * Flow pattern to translate.
8787 * Item is inner pattern.
8791 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
8792 const struct rte_flow_item *item, int inner)
8794 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
8795 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
8799 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
8801 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8807 uint8_t flags_m = 0xff;
8808 uint8_t flags_v = 0xc;
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);
8828 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
8829 size = sizeof(vxlan_m->vni);
8830 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
8831 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
8832 memcpy(vni_m, vxlan_m->vni, size);
8833 for (i = 0; i < size; ++i)
8834 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8835 if (vxlan_m->flags) {
8836 flags_m = vxlan_m->flags;
8837 flags_v = vxlan_v->flags;
8839 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
8840 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
8841 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
8843 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
8848 * Add Geneve item to matcher and to the value.
8850 * @param[in, out] matcher
8852 * @param[in, out] key
8853 * Flow matcher value.
8855 * Flow pattern to translate.
8857 * Item is inner pattern.
8861 flow_dv_translate_item_geneve(void *matcher, void *key,
8862 const struct rte_flow_item *item, int inner)
8864 const struct rte_flow_item_geneve *geneve_m = item->mask;
8865 const struct rte_flow_item_geneve *geneve_v = item->spec;
8868 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8869 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8878 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8880 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8882 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8884 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8886 dport = MLX5_UDP_PORT_GENEVE;
8887 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8888 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8889 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8894 geneve_m = &rte_flow_item_geneve_mask;
8895 size = sizeof(geneve_m->vni);
8896 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
8897 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
8898 memcpy(vni_m, geneve_m->vni, size);
8899 for (i = 0; i < size; ++i)
8900 vni_v[i] = vni_m[i] & geneve_v->vni[i];
8901 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
8902 rte_be_to_cpu_16(geneve_m->protocol));
8903 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
8904 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
8905 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
8906 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
8907 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
8908 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
8909 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
8910 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
8911 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
8912 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
8913 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
8914 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
8915 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
8919 * Create Geneve TLV option resource.
8921 * @param dev[in, out]
8922 * Pointer to rte_eth_dev structure.
8923 * @param[in, out] tag_be24
8924 * Tag value in big endian then R-shift 8.
8925 * @parm[in, out] dev_flow
8926 * Pointer to the dev_flow.
8928 * pointer to error structure.
8931 * 0 on success otherwise -errno and errno is set.
8935 flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
8936 const struct rte_flow_item *item,
8937 struct rte_flow_error *error)
8939 struct mlx5_priv *priv = dev->data->dev_private;
8940 struct mlx5_dev_ctx_shared *sh = priv->sh;
8941 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
8942 sh->geneve_tlv_option_resource;
8943 struct mlx5_devx_obj *obj;
8944 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
8949 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
8950 if (geneve_opt_resource != NULL) {
8951 if (geneve_opt_resource->option_class ==
8952 geneve_opt_v->option_class &&
8953 geneve_opt_resource->option_type ==
8954 geneve_opt_v->option_type &&
8955 geneve_opt_resource->length ==
8956 geneve_opt_v->option_len) {
8957 /* We already have GENVE TLV option obj allocated. */
8958 __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
8961 ret = rte_flow_error_set(error, ENOMEM,
8962 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8963 "Only one GENEVE TLV option supported");
8967 /* Create a GENEVE TLV object and resource. */
8968 obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->ctx,
8969 geneve_opt_v->option_class,
8970 geneve_opt_v->option_type,
8971 geneve_opt_v->option_len);
8973 ret = rte_flow_error_set(error, ENODATA,
8974 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8975 "Failed to create GENEVE TLV Devx object");
8978 sh->geneve_tlv_option_resource =
8979 mlx5_malloc(MLX5_MEM_ZERO,
8980 sizeof(*geneve_opt_resource),
8982 if (!sh->geneve_tlv_option_resource) {
8983 claim_zero(mlx5_devx_cmd_destroy(obj));
8984 ret = rte_flow_error_set(error, ENOMEM,
8985 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8986 "GENEVE TLV object memory allocation failed");
8989 geneve_opt_resource = sh->geneve_tlv_option_resource;
8990 geneve_opt_resource->obj = obj;
8991 geneve_opt_resource->option_class = geneve_opt_v->option_class;
8992 geneve_opt_resource->option_type = geneve_opt_v->option_type;
8993 geneve_opt_resource->length = geneve_opt_v->option_len;
8994 __atomic_store_n(&geneve_opt_resource->refcnt, 1,
8998 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
9003 * Add Geneve TLV option item to matcher.
9005 * @param[in, out] dev
9006 * Pointer to rte_eth_dev structure.
9007 * @param[in, out] matcher
9009 * @param[in, out] key
9010 * Flow matcher value.
9012 * Flow pattern to translate.
9014 * Pointer to error structure.
9017 flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *matcher,
9018 void *key, const struct rte_flow_item *item,
9019 struct rte_flow_error *error)
9021 const struct rte_flow_item_geneve_opt *geneve_opt_m = item->mask;
9022 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
9023 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9024 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9025 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9027 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9028 rte_be32_t opt_data_key = 0, opt_data_mask = 0;
9034 geneve_opt_m = &rte_flow_item_geneve_opt_mask;
9035 ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
9038 DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
9042 * Set the option length in GENEVE header if not requested.
9043 * The GENEVE TLV option length is expressed by the option length field
9044 * in the GENEVE header.
9045 * If the option length was not requested but the GENEVE TLV option item
9046 * is present we set the option length field implicitly.
9048 if (!MLX5_GET16(fte_match_set_misc, misc_m, geneve_opt_len)) {
9049 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
9050 MLX5_GENEVE_OPTLEN_MASK);
9051 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
9052 geneve_opt_v->option_len + 1);
9055 if (geneve_opt_v->data) {
9056 memcpy(&opt_data_key, geneve_opt_v->data,
9057 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9058 sizeof(opt_data_key)));
9059 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9060 sizeof(opt_data_key));
9061 memcpy(&opt_data_mask, geneve_opt_m->data,
9062 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
9063 sizeof(opt_data_mask)));
9064 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
9065 sizeof(opt_data_mask));
9066 MLX5_SET(fte_match_set_misc3, misc3_m,
9067 geneve_tlv_option_0_data,
9068 rte_be_to_cpu_32(opt_data_mask));
9069 MLX5_SET(fte_match_set_misc3, misc3_v,
9070 geneve_tlv_option_0_data,
9071 rte_be_to_cpu_32(opt_data_key & opt_data_mask));
9077 * Add MPLS item to matcher and to the value.
9079 * @param[in, out] matcher
9081 * @param[in, out] key
9082 * Flow matcher value.
9084 * Flow pattern to translate.
9085 * @param[in] prev_layer
9086 * The protocol layer indicated in previous item.
9088 * Item is inner pattern.
9091 flow_dv_translate_item_mpls(void *matcher, void *key,
9092 const struct rte_flow_item *item,
9093 uint64_t prev_layer,
9096 const uint32_t *in_mpls_m = item->mask;
9097 const uint32_t *in_mpls_v = item->spec;
9098 uint32_t *out_mpls_m = 0;
9099 uint32_t *out_mpls_v = 0;
9100 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9101 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9102 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
9104 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9105 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9106 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9108 switch (prev_layer) {
9109 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9110 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
9111 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9112 MLX5_UDP_PORT_MPLS);
9114 case MLX5_FLOW_LAYER_GRE:
9116 case MLX5_FLOW_LAYER_GRE_KEY:
9117 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
9118 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9119 RTE_ETHER_TYPE_MPLS);
9127 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
9128 switch (prev_layer) {
9129 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9131 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9132 outer_first_mpls_over_udp);
9134 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9135 outer_first_mpls_over_udp);
9137 case MLX5_FLOW_LAYER_GRE:
9139 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9140 outer_first_mpls_over_gre);
9142 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9143 outer_first_mpls_over_gre);
9146 /* Inner MPLS not over GRE is not supported. */
9149 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9153 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9159 if (out_mpls_m && out_mpls_v) {
9160 *out_mpls_m = *in_mpls_m;
9161 *out_mpls_v = *in_mpls_v & *in_mpls_m;
9166 * Add metadata register item to matcher
9168 * @param[in, out] matcher
9170 * @param[in, out] key
9171 * Flow matcher value.
9172 * @param[in] reg_type
9173 * Type of device metadata register
9180 flow_dv_match_meta_reg(void *matcher, void *key,
9181 enum modify_reg reg_type,
9182 uint32_t data, uint32_t mask)
9185 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
9187 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9193 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
9194 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
9197 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
9198 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
9202 * The metadata register C0 field might be divided into
9203 * source vport index and META item value, we should set
9204 * this field according to specified mask, not as whole one.
9206 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
9208 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
9209 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
9212 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
9215 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
9216 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
9219 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
9220 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
9223 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
9224 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
9227 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
9228 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
9231 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
9232 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
9235 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
9236 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
9239 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
9240 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
9249 * Add MARK item to matcher
9252 * The device to configure through.
9253 * @param[in, out] matcher
9255 * @param[in, out] key
9256 * Flow matcher value.
9258 * Flow pattern to translate.
9261 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
9262 void *matcher, void *key,
9263 const struct rte_flow_item *item)
9265 struct mlx5_priv *priv = dev->data->dev_private;
9266 const struct rte_flow_item_mark *mark;
9270 mark = item->mask ? (const void *)item->mask :
9271 &rte_flow_item_mark_mask;
9272 mask = mark->id & priv->sh->dv_mark_mask;
9273 mark = (const void *)item->spec;
9275 value = mark->id & priv->sh->dv_mark_mask & mask;
9277 enum modify_reg reg;
9279 /* Get the metadata register index for the mark. */
9280 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
9281 MLX5_ASSERT(reg > 0);
9282 if (reg == REG_C_0) {
9283 struct mlx5_priv *priv = dev->data->dev_private;
9284 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9285 uint32_t shl_c0 = rte_bsf32(msk_c0);
9291 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9296 * Add META item to matcher
9299 * The devich to configure through.
9300 * @param[in, out] matcher
9302 * @param[in, out] key
9303 * Flow matcher value.
9305 * Attributes of flow that includes this item.
9307 * Flow pattern to translate.
9310 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
9311 void *matcher, void *key,
9312 const struct rte_flow_attr *attr,
9313 const struct rte_flow_item *item)
9315 const struct rte_flow_item_meta *meta_m;
9316 const struct rte_flow_item_meta *meta_v;
9318 meta_m = (const void *)item->mask;
9320 meta_m = &rte_flow_item_meta_mask;
9321 meta_v = (const void *)item->spec;
9324 uint32_t value = meta_v->data;
9325 uint32_t mask = meta_m->data;
9327 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
9330 MLX5_ASSERT(reg != REG_NON);
9331 if (reg == REG_C_0) {
9332 struct mlx5_priv *priv = dev->data->dev_private;
9333 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9334 uint32_t shl_c0 = rte_bsf32(msk_c0);
9340 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9345 * Add vport metadata Reg C0 item to matcher
9347 * @param[in, out] matcher
9349 * @param[in, out] key
9350 * Flow matcher value.
9352 * Flow pattern to translate.
9355 flow_dv_translate_item_meta_vport(void *matcher, void *key,
9356 uint32_t value, uint32_t mask)
9358 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
9362 * Add tag item to matcher
9365 * The devich to configure through.
9366 * @param[in, out] matcher
9368 * @param[in, out] key
9369 * Flow matcher value.
9371 * Flow pattern to translate.
9374 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
9375 void *matcher, void *key,
9376 const struct rte_flow_item *item)
9378 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
9379 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
9380 uint32_t mask, value;
9383 value = tag_v->data;
9384 mask = tag_m ? tag_m->data : UINT32_MAX;
9385 if (tag_v->id == REG_C_0) {
9386 struct mlx5_priv *priv = dev->data->dev_private;
9387 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9388 uint32_t shl_c0 = rte_bsf32(msk_c0);
9394 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
9398 * Add TAG item to matcher
9401 * The devich to configure through.
9402 * @param[in, out] matcher
9404 * @param[in, out] key
9405 * Flow matcher value.
9407 * Flow pattern to translate.
9410 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
9411 void *matcher, void *key,
9412 const struct rte_flow_item *item)
9414 const struct rte_flow_item_tag *tag_v = item->spec;
9415 const struct rte_flow_item_tag *tag_m = item->mask;
9416 enum modify_reg reg;
9419 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
9420 /* Get the metadata register index for the tag. */
9421 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
9422 MLX5_ASSERT(reg > 0);
9423 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
9427 * Add source vport match to the specified matcher.
9429 * @param[in, out] matcher
9431 * @param[in, out] key
9432 * Flow matcher value.
9434 * Source vport value to match
9439 flow_dv_translate_item_source_vport(void *matcher, void *key,
9440 int16_t port, uint16_t mask)
9442 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9443 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9445 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
9446 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
9450 * Translate port-id item to eswitch match on port-id.
9453 * The devich to configure through.
9454 * @param[in, out] matcher
9456 * @param[in, out] key
9457 * Flow matcher value.
9459 * Flow pattern to translate.
9464 * 0 on success, a negative errno value otherwise.
9467 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
9468 void *key, const struct rte_flow_item *item,
9469 const struct rte_flow_attr *attr)
9471 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
9472 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
9473 struct mlx5_priv *priv;
9476 mask = pid_m ? pid_m->id : 0xffff;
9477 id = pid_v ? pid_v->id : dev->data->port_id;
9478 priv = mlx5_port_to_eswitch_info(id, item == NULL);
9482 * Translate to vport field or to metadata, depending on mode.
9483 * Kernel can use either misc.source_port or half of C0 metadata
9486 if (priv->vport_meta_mask) {
9488 * Provide the hint for SW steering library
9489 * to insert the flow into ingress domain and
9490 * save the extra vport match.
9492 if (mask == 0xffff && priv->vport_id == 0xffff &&
9493 priv->pf_bond < 0 && attr->transfer)
9494 flow_dv_translate_item_source_vport
9495 (matcher, key, priv->vport_id, mask);
9497 * We should always set the vport metadata register,
9498 * otherwise the SW steering library can drop
9499 * the rule if wire vport metadata value is not zero,
9500 * it depends on kernel configuration.
9502 flow_dv_translate_item_meta_vport(matcher, key,
9503 priv->vport_meta_tag,
9504 priv->vport_meta_mask);
9506 flow_dv_translate_item_source_vport(matcher, key,
9507 priv->vport_id, mask);
9513 * Add ICMP6 item to matcher and to the value.
9515 * @param[in, out] matcher
9517 * @param[in, out] key
9518 * Flow matcher value.
9520 * Flow pattern to translate.
9522 * Item is inner pattern.
9525 flow_dv_translate_item_icmp6(void *matcher, void *key,
9526 const struct rte_flow_item *item,
9529 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
9530 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
9533 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9535 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9537 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9539 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9541 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9543 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9545 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9546 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
9550 icmp6_m = &rte_flow_item_icmp6_mask;
9551 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
9552 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
9553 icmp6_v->type & icmp6_m->type);
9554 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
9555 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
9556 icmp6_v->code & icmp6_m->code);
9560 * Add ICMP item to matcher and to the value.
9562 * @param[in, out] matcher
9564 * @param[in, out] key
9565 * Flow matcher value.
9567 * Flow pattern to translate.
9569 * Item is inner pattern.
9572 flow_dv_translate_item_icmp(void *matcher, void *key,
9573 const struct rte_flow_item *item,
9576 const struct rte_flow_item_icmp *icmp_m = item->mask;
9577 const struct rte_flow_item_icmp *icmp_v = item->spec;
9578 uint32_t icmp_header_data_m = 0;
9579 uint32_t icmp_header_data_v = 0;
9582 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9584 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9586 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9588 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9590 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9592 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9594 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9595 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
9599 icmp_m = &rte_flow_item_icmp_mask;
9600 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
9601 icmp_m->hdr.icmp_type);
9602 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
9603 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
9604 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
9605 icmp_m->hdr.icmp_code);
9606 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
9607 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
9608 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
9609 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
9610 if (icmp_header_data_m) {
9611 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
9612 icmp_header_data_v |=
9613 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
9614 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
9615 icmp_header_data_m);
9616 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
9617 icmp_header_data_v & icmp_header_data_m);
9622 * Add GTP item to matcher and to the value.
9624 * @param[in, out] matcher
9626 * @param[in, out] key
9627 * Flow matcher value.
9629 * Flow pattern to translate.
9631 * Item is inner pattern.
9634 flow_dv_translate_item_gtp(void *matcher, void *key,
9635 const struct rte_flow_item *item, int inner)
9637 const struct rte_flow_item_gtp *gtp_m = item->mask;
9638 const struct rte_flow_item_gtp *gtp_v = item->spec;
9641 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9643 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9644 uint16_t dport = RTE_GTPU_UDP_PORT;
9647 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9649 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9651 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9653 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9655 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9656 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9657 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
9662 gtp_m = &rte_flow_item_gtp_mask;
9663 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
9664 gtp_m->v_pt_rsv_flags);
9665 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
9666 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
9667 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
9668 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
9669 gtp_v->msg_type & gtp_m->msg_type);
9670 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
9671 rte_be_to_cpu_32(gtp_m->teid));
9672 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
9673 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
9677 * Add GTP PSC item to matcher.
9679 * @param[in, out] matcher
9681 * @param[in, out] key
9682 * Flow matcher value.
9684 * Flow pattern to translate.
9687 flow_dv_translate_item_gtp_psc(void *matcher, void *key,
9688 const struct rte_flow_item *item)
9690 const struct rte_flow_item_gtp_psc *gtp_psc_m = item->mask;
9691 const struct rte_flow_item_gtp_psc *gtp_psc_v = item->spec;
9692 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9694 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9700 uint8_t next_ext_header_type;
9705 /* Always set E-flag match on one, regardless of GTP item settings. */
9706 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_m, gtpu_msg_flags);
9707 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9708 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags, gtp_flags);
9709 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
9710 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9711 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
9712 /*Set next extension header type. */
9715 dw_2.next_ext_header_type = 0xff;
9716 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_dw_2,
9717 rte_cpu_to_be_32(dw_2.w32));
9720 dw_2.next_ext_header_type = 0x85;
9721 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
9722 rte_cpu_to_be_32(dw_2.w32));
9734 /*Set extension header PDU type and Qos. */
9736 gtp_psc_m = &rte_flow_item_gtp_psc_mask;
9738 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_m->pdu_type);
9739 dw_0.qfi = gtp_psc_m->qfi;
9740 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_first_ext_dw_0,
9741 rte_cpu_to_be_32(dw_0.w32));
9743 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->pdu_type &
9744 gtp_psc_m->pdu_type);
9745 dw_0.qfi = gtp_psc_v->qfi & gtp_psc_m->qfi;
9746 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
9747 rte_cpu_to_be_32(dw_0.w32));
9753 * Add eCPRI item to matcher and to the value.
9756 * The devich to configure through.
9757 * @param[in, out] matcher
9759 * @param[in, out] key
9760 * Flow matcher value.
9762 * Flow pattern to translate.
9763 * @param[in] samples
9764 * Sample IDs to be used in the matching.
9767 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
9768 void *key, const struct rte_flow_item *item)
9770 struct mlx5_priv *priv = dev->data->dev_private;
9771 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
9772 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
9773 struct rte_ecpri_common_hdr common;
9774 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
9776 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
9784 ecpri_m = &rte_flow_item_ecpri_mask;
9786 * Maximal four DW samples are supported in a single matching now.
9787 * Two are used now for a eCPRI matching:
9788 * 1. Type: one byte, mask should be 0x00ff0000 in network order
9789 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
9792 if (!ecpri_m->hdr.common.u32)
9794 samples = priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0].ids;
9795 /* Need to take the whole DW as the mask to fill the entry. */
9796 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9797 prog_sample_field_value_0);
9798 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9799 prog_sample_field_value_0);
9800 /* Already big endian (network order) in the header. */
9801 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
9802 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
9803 /* Sample#0, used for matching type, offset 0. */
9804 MLX5_SET(fte_match_set_misc4, misc4_m,
9805 prog_sample_field_id_0, samples[0]);
9806 /* It makes no sense to set the sample ID in the mask field. */
9807 MLX5_SET(fte_match_set_misc4, misc4_v,
9808 prog_sample_field_id_0, samples[0]);
9810 * Checking if message body part needs to be matched.
9811 * Some wildcard rules only matching type field should be supported.
9813 if (ecpri_m->hdr.dummy[0]) {
9814 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
9815 switch (common.type) {
9816 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
9817 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
9818 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
9819 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9820 prog_sample_field_value_1);
9821 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9822 prog_sample_field_value_1);
9823 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
9824 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
9825 ecpri_m->hdr.dummy[0];
9826 /* Sample#1, to match message body, offset 4. */
9827 MLX5_SET(fte_match_set_misc4, misc4_m,
9828 prog_sample_field_id_1, samples[1]);
9829 MLX5_SET(fte_match_set_misc4, misc4_v,
9830 prog_sample_field_id_1, samples[1]);
9833 /* Others, do not match any sample ID. */
9840 * Add connection tracking status item to matcher
9843 * The devich to configure through.
9844 * @param[in, out] matcher
9846 * @param[in, out] key
9847 * Flow matcher value.
9849 * Flow pattern to translate.
9852 flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
9853 void *matcher, void *key,
9854 const struct rte_flow_item *item)
9856 uint32_t reg_value = 0;
9858 /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
9859 uint32_t reg_mask = 0;
9860 const struct rte_flow_item_conntrack *spec = item->spec;
9861 const struct rte_flow_item_conntrack *mask = item->mask;
9863 struct rte_flow_error error;
9866 mask = &rte_flow_item_conntrack_mask;
9867 if (!spec || !mask->flags)
9869 flags = spec->flags & mask->flags;
9870 /* The conflict should be checked in the validation. */
9871 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
9872 reg_value |= MLX5_CT_SYNDROME_VALID;
9873 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
9874 reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
9875 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
9876 reg_value |= MLX5_CT_SYNDROME_INVALID;
9877 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
9878 reg_value |= MLX5_CT_SYNDROME_TRAP;
9879 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
9880 reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
9881 if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
9882 RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
9883 RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
9885 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
9886 reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
9887 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
9888 reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
9889 /* The REG_C_x value could be saved during startup. */
9890 reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
9891 if (reg_id == REG_NON)
9893 flow_dv_match_meta_reg(matcher, key, (enum modify_reg)reg_id,
9894 reg_value, reg_mask);
9897 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
9899 #define HEADER_IS_ZERO(match_criteria, headers) \
9900 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
9901 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
9904 * Calculate flow matcher enable bitmap.
9906 * @param match_criteria
9907 * Pointer to flow matcher criteria.
9910 * Bitmap of enabled fields.
9913 flow_dv_matcher_enable(uint32_t *match_criteria)
9915 uint8_t match_criteria_enable;
9917 match_criteria_enable =
9918 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
9919 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
9920 match_criteria_enable |=
9921 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
9922 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
9923 match_criteria_enable |=
9924 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
9925 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
9926 match_criteria_enable |=
9927 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
9928 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
9929 match_criteria_enable |=
9930 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
9931 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
9932 match_criteria_enable |=
9933 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
9934 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
9935 match_criteria_enable |=
9936 (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
9937 MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
9938 return match_criteria_enable;
9942 __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
9945 * Check flow matching criteria first, subtract misc5/4 length if flow
9946 * doesn't own misc5/4 parameters. In some old rdma-core releases,
9947 * misc5/4 are not supported, and matcher creation failure is expected
9948 * w/o subtration. If misc5 is provided, misc4 must be counted in since
9949 * misc5 is right after misc4.
9951 if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
9952 *size = MLX5_ST_SZ_BYTES(fte_match_param) -
9953 MLX5_ST_SZ_BYTES(fte_match_set_misc5);
9954 if (!(match_criteria & (1 <<
9955 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
9956 *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
9961 struct mlx5_hlist_entry *
9962 flow_dv_tbl_create_cb(struct mlx5_hlist *list, uint64_t key64, void *cb_ctx)
9964 struct mlx5_dev_ctx_shared *sh = list->ctx;
9965 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9966 struct rte_eth_dev *dev = ctx->dev;
9967 struct mlx5_flow_tbl_data_entry *tbl_data;
9968 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data;
9969 struct rte_flow_error *error = ctx->error;
9970 union mlx5_flow_tbl_key key = { .v64 = key64 };
9971 struct mlx5_flow_tbl_resource *tbl;
9976 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
9978 rte_flow_error_set(error, ENOMEM,
9979 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9981 "cannot allocate flow table data entry");
9984 tbl_data->idx = idx;
9985 tbl_data->tunnel = tt_prm->tunnel;
9986 tbl_data->group_id = tt_prm->group_id;
9987 tbl_data->external = !!tt_prm->external;
9988 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
9989 tbl_data->is_egress = !!key.is_egress;
9990 tbl_data->is_transfer = !!key.is_fdb;
9991 tbl_data->dummy = !!key.dummy;
9992 tbl_data->level = key.level;
9993 tbl_data->id = key.id;
9994 tbl = &tbl_data->tbl;
9996 return &tbl_data->entry;
9998 domain = sh->fdb_domain;
9999 else if (key.is_egress)
10000 domain = sh->tx_domain;
10002 domain = sh->rx_domain;
10003 ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
10005 rte_flow_error_set(error, ENOMEM,
10006 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10007 NULL, "cannot create flow table object");
10008 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10011 if (key.level != 0) {
10012 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
10013 (tbl->obj, &tbl_data->jump.action);
10015 rte_flow_error_set(error, ENOMEM,
10016 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10018 "cannot create flow jump action");
10019 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
10020 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
10024 MKSTR(matcher_name, "%s_%s_%u_%u_matcher_cache",
10025 key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
10026 key.level, key.id);
10027 mlx5_cache_list_init(&tbl_data->matchers, matcher_name, 0, sh,
10028 flow_dv_matcher_create_cb,
10029 flow_dv_matcher_match_cb,
10030 flow_dv_matcher_remove_cb);
10031 return &tbl_data->entry;
10035 flow_dv_tbl_match_cb(struct mlx5_hlist *list __rte_unused,
10036 struct mlx5_hlist_entry *entry, uint64_t key64,
10037 void *cb_ctx __rte_unused)
10039 struct mlx5_flow_tbl_data_entry *tbl_data =
10040 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10041 union mlx5_flow_tbl_key key = { .v64 = key64 };
10043 return tbl_data->level != key.level ||
10044 tbl_data->id != key.id ||
10045 tbl_data->dummy != key.dummy ||
10046 tbl_data->is_transfer != !!key.is_fdb ||
10047 tbl_data->is_egress != !!key.is_egress;
10051 * Get a flow table.
10053 * @param[in, out] dev
10054 * Pointer to rte_eth_dev structure.
10055 * @param[in] table_level
10056 * Table level to use.
10057 * @param[in] egress
10058 * Direction of the table.
10059 * @param[in] transfer
10060 * E-Switch or NIC flow.
10062 * Dummy entry for dv API.
10063 * @param[in] table_id
10065 * @param[out] error
10066 * pointer to error structure.
10069 * Returns tables resource based on the index, NULL in case of failed.
10071 struct mlx5_flow_tbl_resource *
10072 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
10073 uint32_t table_level, uint8_t egress,
10076 const struct mlx5_flow_tunnel *tunnel,
10077 uint32_t group_id, uint8_t dummy,
10079 struct rte_flow_error *error)
10081 struct mlx5_priv *priv = dev->data->dev_private;
10082 union mlx5_flow_tbl_key table_key = {
10084 .level = table_level,
10088 .is_fdb = !!transfer,
10089 .is_egress = !!egress,
10092 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
10094 .group_id = group_id,
10095 .external = external,
10097 struct mlx5_flow_cb_ctx ctx = {
10102 struct mlx5_hlist_entry *entry;
10103 struct mlx5_flow_tbl_data_entry *tbl_data;
10105 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
10107 rte_flow_error_set(error, ENOMEM,
10108 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10109 "cannot get table");
10112 DRV_LOG(DEBUG, "table_level %u table_id %u "
10113 "tunnel %u group %u registered.",
10114 table_level, table_id,
10115 tunnel ? tunnel->tunnel_id : 0, group_id);
10116 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10117 return &tbl_data->tbl;
10121 flow_dv_tbl_remove_cb(struct mlx5_hlist *list,
10122 struct mlx5_hlist_entry *entry)
10124 struct mlx5_dev_ctx_shared *sh = list->ctx;
10125 struct mlx5_flow_tbl_data_entry *tbl_data =
10126 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10128 MLX5_ASSERT(entry && sh);
10129 if (tbl_data->jump.action)
10130 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10131 if (tbl_data->tbl.obj)
10132 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
10133 if (tbl_data->tunnel_offload && tbl_data->external) {
10134 struct mlx5_hlist_entry *he;
10135 struct mlx5_hlist *tunnel_grp_hash;
10136 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
10137 union tunnel_tbl_key tunnel_key = {
10138 .tunnel_id = tbl_data->tunnel ?
10139 tbl_data->tunnel->tunnel_id : 0,
10140 .group = tbl_data->group_id
10142 uint32_t table_level = tbl_data->level;
10144 tunnel_grp_hash = tbl_data->tunnel ?
10145 tbl_data->tunnel->groups :
10147 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, NULL);
10149 mlx5_hlist_unregister(tunnel_grp_hash, he);
10151 "table_level %u id %u tunnel %u group %u released.",
10155 tbl_data->tunnel->tunnel_id : 0,
10156 tbl_data->group_id);
10158 mlx5_cache_list_destroy(&tbl_data->matchers);
10159 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10163 * Release a flow table.
10166 * Pointer to device shared structure.
10168 * Table resource to be released.
10171 * Returns 0 if table was released, else return 1;
10174 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
10175 struct mlx5_flow_tbl_resource *tbl)
10177 struct mlx5_flow_tbl_data_entry *tbl_data =
10178 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10182 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
10186 flow_dv_matcher_match_cb(struct mlx5_cache_list *list __rte_unused,
10187 struct mlx5_cache_entry *entry, void *cb_ctx)
10189 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10190 struct mlx5_flow_dv_matcher *ref = ctx->data;
10191 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
10194 return cur->crc != ref->crc ||
10195 cur->priority != ref->priority ||
10196 memcmp((const void *)cur->mask.buf,
10197 (const void *)ref->mask.buf, ref->mask.size);
10200 struct mlx5_cache_entry *
10201 flow_dv_matcher_create_cb(struct mlx5_cache_list *list,
10202 struct mlx5_cache_entry *entry __rte_unused,
10205 struct mlx5_dev_ctx_shared *sh = list->ctx;
10206 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10207 struct mlx5_flow_dv_matcher *ref = ctx->data;
10208 struct mlx5_flow_dv_matcher *cache;
10209 struct mlx5dv_flow_matcher_attr dv_attr = {
10210 .type = IBV_FLOW_ATTR_NORMAL,
10211 .match_mask = (void *)&ref->mask,
10213 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10214 typeof(*tbl), tbl);
10217 cache = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*cache), 0, SOCKET_ID_ANY);
10219 rte_flow_error_set(ctx->error, ENOMEM,
10220 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10221 "cannot create matcher");
10225 dv_attr.match_criteria_enable =
10226 flow_dv_matcher_enable(cache->mask.buf);
10227 __flow_dv_adjust_buf_size(&ref->mask.size,
10228 dv_attr.match_criteria_enable);
10229 dv_attr.priority = ref->priority;
10230 if (tbl->is_egress)
10231 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
10232 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->tbl.obj,
10233 &cache->matcher_object);
10236 rte_flow_error_set(ctx->error, ENOMEM,
10237 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10238 "cannot create matcher");
10241 return &cache->entry;
10245 * Register the flow matcher.
10247 * @param[in, out] dev
10248 * Pointer to rte_eth_dev structure.
10249 * @param[in, out] matcher
10250 * Pointer to flow matcher.
10251 * @param[in, out] key
10252 * Pointer to flow table key.
10253 * @parm[in, out] dev_flow
10254 * Pointer to the dev_flow.
10255 * @param[out] error
10256 * pointer to error structure.
10259 * 0 on success otherwise -errno and errno is set.
10262 flow_dv_matcher_register(struct rte_eth_dev *dev,
10263 struct mlx5_flow_dv_matcher *ref,
10264 union mlx5_flow_tbl_key *key,
10265 struct mlx5_flow *dev_flow,
10266 const struct mlx5_flow_tunnel *tunnel,
10268 struct rte_flow_error *error)
10270 struct mlx5_cache_entry *entry;
10271 struct mlx5_flow_dv_matcher *cache;
10272 struct mlx5_flow_tbl_resource *tbl;
10273 struct mlx5_flow_tbl_data_entry *tbl_data;
10274 struct mlx5_flow_cb_ctx ctx = {
10279 * tunnel offload API requires this registration for cases when
10280 * tunnel match rule was inserted before tunnel set rule.
10282 tbl = flow_dv_tbl_resource_get(dev, key->level,
10283 key->is_egress, key->is_fdb,
10284 dev_flow->external, tunnel,
10285 group_id, 0, key->id, error);
10287 return -rte_errno; /* No need to refill the error info */
10288 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10290 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
10292 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
10293 return rte_flow_error_set(error, ENOMEM,
10294 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10295 "cannot allocate ref memory");
10297 cache = container_of(entry, typeof(*cache), entry);
10298 dev_flow->handle->dvh.matcher = cache;
10302 struct mlx5_hlist_entry *
10303 flow_dv_tag_create_cb(struct mlx5_hlist *list, uint64_t key, void *ctx)
10305 struct mlx5_dev_ctx_shared *sh = list->ctx;
10306 struct rte_flow_error *error = ctx;
10307 struct mlx5_flow_dv_tag_resource *entry;
10311 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10313 rte_flow_error_set(error, ENOMEM,
10314 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10315 "cannot allocate resource memory");
10319 entry->tag_id = key;
10320 ret = mlx5_flow_os_create_flow_action_tag(key,
10323 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
10324 rte_flow_error_set(error, ENOMEM,
10325 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10326 NULL, "cannot create action");
10329 return &entry->entry;
10333 flow_dv_tag_match_cb(struct mlx5_hlist *list __rte_unused,
10334 struct mlx5_hlist_entry *entry, uint64_t key,
10335 void *cb_ctx __rte_unused)
10337 struct mlx5_flow_dv_tag_resource *tag =
10338 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10340 return key != tag->tag_id;
10344 * Find existing tag resource or create and register a new one.
10346 * @param dev[in, out]
10347 * Pointer to rte_eth_dev structure.
10348 * @param[in, out] tag_be24
10349 * Tag value in big endian then R-shift 8.
10350 * @parm[in, out] dev_flow
10351 * Pointer to the dev_flow.
10352 * @param[out] error
10353 * pointer to error structure.
10356 * 0 on success otherwise -errno and errno is set.
10359 flow_dv_tag_resource_register
10360 (struct rte_eth_dev *dev,
10362 struct mlx5_flow *dev_flow,
10363 struct rte_flow_error *error)
10365 struct mlx5_priv *priv = dev->data->dev_private;
10366 struct mlx5_flow_dv_tag_resource *cache_resource;
10367 struct mlx5_hlist_entry *entry;
10369 entry = mlx5_hlist_register(priv->sh->tag_table, tag_be24, error);
10371 cache_resource = container_of
10372 (entry, struct mlx5_flow_dv_tag_resource, entry);
10373 dev_flow->handle->dvh.rix_tag = cache_resource->idx;
10374 dev_flow->dv.tag_resource = cache_resource;
10381 flow_dv_tag_remove_cb(struct mlx5_hlist *list,
10382 struct mlx5_hlist_entry *entry)
10384 struct mlx5_dev_ctx_shared *sh = list->ctx;
10385 struct mlx5_flow_dv_tag_resource *tag =
10386 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10388 MLX5_ASSERT(tag && sh && tag->action);
10389 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
10390 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
10391 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10398 * Pointer to Ethernet device.
10403 * 1 while a reference on it exists, 0 when freed.
10406 flow_dv_tag_release(struct rte_eth_dev *dev,
10409 struct mlx5_priv *priv = dev->data->dev_private;
10410 struct mlx5_flow_dv_tag_resource *tag;
10412 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
10415 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
10416 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
10417 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
10421 * Translate port ID action to vport.
10424 * Pointer to rte_eth_dev structure.
10425 * @param[in] action
10426 * Pointer to the port ID action.
10427 * @param[out] dst_port_id
10428 * The target port ID.
10429 * @param[out] error
10430 * Pointer to the error structure.
10433 * 0 on success, a negative errno value otherwise and rte_errno is set.
10436 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
10437 const struct rte_flow_action *action,
10438 uint32_t *dst_port_id,
10439 struct rte_flow_error *error)
10442 struct mlx5_priv *priv;
10443 const struct rte_flow_action_port_id *conf =
10444 (const struct rte_flow_action_port_id *)action->conf;
10446 port = conf->original ? dev->data->port_id : conf->id;
10447 priv = mlx5_port_to_eswitch_info(port, false);
10449 return rte_flow_error_set(error, -rte_errno,
10450 RTE_FLOW_ERROR_TYPE_ACTION,
10452 "No eswitch info was found for port");
10453 #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
10455 * This parameter is transferred to
10456 * mlx5dv_dr_action_create_dest_ib_port().
10458 *dst_port_id = priv->dev_port;
10461 * Legacy mode, no LAG configurations is supported.
10462 * This parameter is transferred to
10463 * mlx5dv_dr_action_create_dest_vport().
10465 *dst_port_id = priv->vport_id;
10471 * Create a counter with aging configuration.
10474 * Pointer to rte_eth_dev structure.
10475 * @param[in] dev_flow
10476 * Pointer to the mlx5_flow.
10477 * @param[out] count
10478 * Pointer to the counter action configuration.
10480 * Pointer to the aging action configuration.
10483 * Index to flow counter on success, 0 otherwise.
10486 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
10487 struct mlx5_flow *dev_flow,
10488 const struct rte_flow_action_count *count,
10489 const struct rte_flow_action_age *age)
10492 struct mlx5_age_param *age_param;
10494 if (count && count->shared)
10495 counter = flow_dv_counter_get_shared(dev, count->id);
10497 counter = flow_dv_counter_alloc(dev, !!age);
10498 if (!counter || age == NULL)
10500 age_param = flow_dv_counter_idx_get_age(dev, counter);
10501 age_param->context = age->context ? age->context :
10502 (void *)(uintptr_t)(dev_flow->flow_idx);
10503 age_param->timeout = age->timeout;
10504 age_param->port_id = dev->data->port_id;
10505 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
10506 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
10511 * Add Tx queue matcher
10514 * Pointer to the dev struct.
10515 * @param[in, out] matcher
10517 * @param[in, out] key
10518 * Flow matcher value.
10520 * Flow pattern to translate.
10522 * Item is inner pattern.
10525 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
10526 void *matcher, void *key,
10527 const struct rte_flow_item *item)
10529 const struct mlx5_rte_flow_item_tx_queue *queue_m;
10530 const struct mlx5_rte_flow_item_tx_queue *queue_v;
10532 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
10534 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10535 struct mlx5_txq_ctrl *txq;
10539 queue_m = (const void *)item->mask;
10542 queue_v = (const void *)item->spec;
10545 txq = mlx5_txq_get(dev, queue_v->queue);
10548 queue = txq->obj->sq->id;
10549 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
10550 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
10551 queue & queue_m->queue);
10552 mlx5_txq_release(dev, queue_v->queue);
10556 * Set the hash fields according to the @p flow information.
10558 * @param[in] dev_flow
10559 * Pointer to the mlx5_flow.
10560 * @param[in] rss_desc
10561 * Pointer to the mlx5_flow_rss_desc.
10564 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
10565 struct mlx5_flow_rss_desc *rss_desc)
10567 uint64_t items = dev_flow->handle->layers;
10569 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
10571 dev_flow->hash_fields = 0;
10572 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
10573 if (rss_desc->level >= 2) {
10574 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
10578 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
10579 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
10580 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
10581 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10582 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
10583 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10584 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
10586 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
10588 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
10589 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
10590 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
10591 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10592 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
10593 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10594 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
10596 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
10599 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
10600 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
10601 if (rss_types & ETH_RSS_UDP) {
10602 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10603 dev_flow->hash_fields |=
10604 IBV_RX_HASH_SRC_PORT_UDP;
10605 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10606 dev_flow->hash_fields |=
10607 IBV_RX_HASH_DST_PORT_UDP;
10609 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
10611 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
10612 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
10613 if (rss_types & ETH_RSS_TCP) {
10614 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10615 dev_flow->hash_fields |=
10616 IBV_RX_HASH_SRC_PORT_TCP;
10617 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10618 dev_flow->hash_fields |=
10619 IBV_RX_HASH_DST_PORT_TCP;
10621 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
10627 * Prepare an Rx Hash queue.
10630 * Pointer to Ethernet device.
10631 * @param[in] dev_flow
10632 * Pointer to the mlx5_flow.
10633 * @param[in] rss_desc
10634 * Pointer to the mlx5_flow_rss_desc.
10635 * @param[out] hrxq_idx
10636 * Hash Rx queue index.
10639 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
10641 static struct mlx5_hrxq *
10642 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
10643 struct mlx5_flow *dev_flow,
10644 struct mlx5_flow_rss_desc *rss_desc,
10645 uint32_t *hrxq_idx)
10647 struct mlx5_priv *priv = dev->data->dev_private;
10648 struct mlx5_flow_handle *dh = dev_flow->handle;
10649 struct mlx5_hrxq *hrxq;
10651 MLX5_ASSERT(rss_desc->queue_num);
10652 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
10653 rss_desc->hash_fields = dev_flow->hash_fields;
10654 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
10655 rss_desc->shared_rss = 0;
10656 *hrxq_idx = mlx5_hrxq_get(dev, rss_desc);
10659 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
10665 * Release sample sub action resource.
10667 * @param[in, out] dev
10668 * Pointer to rte_eth_dev structure.
10669 * @param[in] act_res
10670 * Pointer to sample sub action resource.
10673 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
10674 struct mlx5_flow_sub_actions_idx *act_res)
10676 if (act_res->rix_hrxq) {
10677 mlx5_hrxq_release(dev, act_res->rix_hrxq);
10678 act_res->rix_hrxq = 0;
10680 if (act_res->rix_encap_decap) {
10681 flow_dv_encap_decap_resource_release(dev,
10682 act_res->rix_encap_decap);
10683 act_res->rix_encap_decap = 0;
10685 if (act_res->rix_port_id_action) {
10686 flow_dv_port_id_action_resource_release(dev,
10687 act_res->rix_port_id_action);
10688 act_res->rix_port_id_action = 0;
10690 if (act_res->rix_tag) {
10691 flow_dv_tag_release(dev, act_res->rix_tag);
10692 act_res->rix_tag = 0;
10694 if (act_res->rix_jump) {
10695 flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
10696 act_res->rix_jump = 0;
10701 flow_dv_sample_match_cb(struct mlx5_cache_list *list __rte_unused,
10702 struct mlx5_cache_entry *entry, void *cb_ctx)
10704 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10705 struct rte_eth_dev *dev = ctx->dev;
10706 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
10707 struct mlx5_flow_dv_sample_resource *cache_resource =
10708 container_of(entry, typeof(*cache_resource), entry);
10710 if (resource->ratio == cache_resource->ratio &&
10711 resource->ft_type == cache_resource->ft_type &&
10712 resource->ft_id == cache_resource->ft_id &&
10713 resource->set_action == cache_resource->set_action &&
10714 !memcmp((void *)&resource->sample_act,
10715 (void *)&cache_resource->sample_act,
10716 sizeof(struct mlx5_flow_sub_actions_list))) {
10718 * Existing sample action should release the prepared
10719 * sub-actions reference counter.
10721 flow_dv_sample_sub_actions_release(dev,
10722 &resource->sample_idx);
10728 struct mlx5_cache_entry *
10729 flow_dv_sample_create_cb(struct mlx5_cache_list *list __rte_unused,
10730 struct mlx5_cache_entry *entry __rte_unused,
10733 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10734 struct rte_eth_dev *dev = ctx->dev;
10735 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
10736 void **sample_dv_actions = resource->sub_actions;
10737 struct mlx5_flow_dv_sample_resource *cache_resource;
10738 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
10739 struct mlx5_priv *priv = dev->data->dev_private;
10740 struct mlx5_dev_ctx_shared *sh = priv->sh;
10741 struct mlx5_flow_tbl_resource *tbl;
10743 const uint32_t next_ft_step = 1;
10744 uint32_t next_ft_id = resource->ft_id + next_ft_step;
10745 uint8_t is_egress = 0;
10746 uint8_t is_transfer = 0;
10747 struct rte_flow_error *error = ctx->error;
10749 /* Register new sample resource. */
10750 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
10751 if (!cache_resource) {
10752 rte_flow_error_set(error, ENOMEM,
10753 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10755 "cannot allocate resource memory");
10758 *cache_resource = *resource;
10759 /* Create normal path table level */
10760 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
10762 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
10764 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
10765 is_egress, is_transfer,
10766 true, NULL, 0, 0, 0, error);
10768 rte_flow_error_set(error, ENOMEM,
10769 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10771 "fail to create normal path table "
10775 cache_resource->normal_path_tbl = tbl;
10776 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
10777 if (!sh->default_miss_action) {
10778 rte_flow_error_set(error, ENOMEM,
10779 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10781 "default miss action was not "
10785 sample_dv_actions[resource->sample_act.actions_num++] =
10786 sh->default_miss_action;
10788 /* Create a DR sample action */
10789 sampler_attr.sample_ratio = cache_resource->ratio;
10790 sampler_attr.default_next_table = tbl->obj;
10791 sampler_attr.num_sample_actions = resource->sample_act.actions_num;
10792 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
10793 &sample_dv_actions[0];
10794 sampler_attr.action = cache_resource->set_action;
10795 if (mlx5_os_flow_dr_create_flow_action_sampler
10796 (&sampler_attr, &cache_resource->verbs_action)) {
10797 rte_flow_error_set(error, ENOMEM,
10798 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10799 NULL, "cannot create sample action");
10802 cache_resource->idx = idx;
10803 cache_resource->dev = dev;
10804 return &cache_resource->entry;
10806 if (cache_resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
10807 flow_dv_sample_sub_actions_release(dev,
10808 &cache_resource->sample_idx);
10809 if (cache_resource->normal_path_tbl)
10810 flow_dv_tbl_resource_release(MLX5_SH(dev),
10811 cache_resource->normal_path_tbl);
10812 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
10818 * Find existing sample resource or create and register a new one.
10820 * @param[in, out] dev
10821 * Pointer to rte_eth_dev structure.
10822 * @param[in] resource
10823 * Pointer to sample resource.
10824 * @parm[in, out] dev_flow
10825 * Pointer to the dev_flow.
10826 * @param[out] error
10827 * pointer to error structure.
10830 * 0 on success otherwise -errno and errno is set.
10833 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
10834 struct mlx5_flow_dv_sample_resource *resource,
10835 struct mlx5_flow *dev_flow,
10836 struct rte_flow_error *error)
10838 struct mlx5_flow_dv_sample_resource *cache_resource;
10839 struct mlx5_cache_entry *entry;
10840 struct mlx5_priv *priv = dev->data->dev_private;
10841 struct mlx5_flow_cb_ctx ctx = {
10847 entry = mlx5_cache_register(&priv->sh->sample_action_list, &ctx);
10850 cache_resource = container_of(entry, typeof(*cache_resource), entry);
10851 dev_flow->handle->dvh.rix_sample = cache_resource->idx;
10852 dev_flow->dv.sample_res = cache_resource;
10857 flow_dv_dest_array_match_cb(struct mlx5_cache_list *list __rte_unused,
10858 struct mlx5_cache_entry *entry, void *cb_ctx)
10860 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10861 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
10862 struct rte_eth_dev *dev = ctx->dev;
10863 struct mlx5_flow_dv_dest_array_resource *cache_resource =
10864 container_of(entry, typeof(*cache_resource), entry);
10867 if (resource->num_of_dest == cache_resource->num_of_dest &&
10868 resource->ft_type == cache_resource->ft_type &&
10869 !memcmp((void *)cache_resource->sample_act,
10870 (void *)resource->sample_act,
10871 (resource->num_of_dest *
10872 sizeof(struct mlx5_flow_sub_actions_list)))) {
10874 * Existing sample action should release the prepared
10875 * sub-actions reference counter.
10877 for (idx = 0; idx < resource->num_of_dest; idx++)
10878 flow_dv_sample_sub_actions_release(dev,
10879 &resource->sample_idx[idx]);
10885 struct mlx5_cache_entry *
10886 flow_dv_dest_array_create_cb(struct mlx5_cache_list *list __rte_unused,
10887 struct mlx5_cache_entry *entry __rte_unused,
10890 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10891 struct rte_eth_dev *dev = ctx->dev;
10892 struct mlx5_flow_dv_dest_array_resource *cache_resource;
10893 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
10894 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
10895 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
10896 struct mlx5_priv *priv = dev->data->dev_private;
10897 struct mlx5_dev_ctx_shared *sh = priv->sh;
10898 struct mlx5_flow_sub_actions_list *sample_act;
10899 struct mlx5dv_dr_domain *domain;
10900 uint32_t idx = 0, res_idx = 0;
10901 struct rte_flow_error *error = ctx->error;
10902 uint64_t action_flags;
10905 /* Register new destination array resource. */
10906 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
10908 if (!cache_resource) {
10909 rte_flow_error_set(error, ENOMEM,
10910 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10912 "cannot allocate resource memory");
10915 *cache_resource = *resource;
10916 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
10917 domain = sh->fdb_domain;
10918 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
10919 domain = sh->rx_domain;
10921 domain = sh->tx_domain;
10922 for (idx = 0; idx < resource->num_of_dest; idx++) {
10923 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
10924 mlx5_malloc(MLX5_MEM_ZERO,
10925 sizeof(struct mlx5dv_dr_action_dest_attr),
10927 if (!dest_attr[idx]) {
10928 rte_flow_error_set(error, ENOMEM,
10929 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10931 "cannot allocate resource memory");
10934 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
10935 sample_act = &resource->sample_act[idx];
10936 action_flags = sample_act->action_flags;
10937 switch (action_flags) {
10938 case MLX5_FLOW_ACTION_QUEUE:
10939 dest_attr[idx]->dest = sample_act->dr_queue_action;
10941 case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
10942 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
10943 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
10944 dest_attr[idx]->dest_reformat->reformat =
10945 sample_act->dr_encap_action;
10946 dest_attr[idx]->dest_reformat->dest =
10947 sample_act->dr_port_id_action;
10949 case MLX5_FLOW_ACTION_PORT_ID:
10950 dest_attr[idx]->dest = sample_act->dr_port_id_action;
10952 case MLX5_FLOW_ACTION_JUMP:
10953 dest_attr[idx]->dest = sample_act->dr_jump_action;
10956 rte_flow_error_set(error, EINVAL,
10957 RTE_FLOW_ERROR_TYPE_ACTION,
10959 "unsupported actions type");
10963 /* create a dest array actioin */
10964 ret = mlx5_os_flow_dr_create_flow_action_dest_array
10966 cache_resource->num_of_dest,
10968 &cache_resource->action);
10970 rte_flow_error_set(error, ENOMEM,
10971 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10973 "cannot create destination array action");
10976 cache_resource->idx = res_idx;
10977 cache_resource->dev = dev;
10978 for (idx = 0; idx < resource->num_of_dest; idx++)
10979 mlx5_free(dest_attr[idx]);
10980 return &cache_resource->entry;
10982 for (idx = 0; idx < resource->num_of_dest; idx++) {
10983 flow_dv_sample_sub_actions_release(dev,
10984 &cache_resource->sample_idx[idx]);
10985 if (dest_attr[idx])
10986 mlx5_free(dest_attr[idx]);
10989 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
10994 * Find existing destination array resource or create and register a new one.
10996 * @param[in, out] dev
10997 * Pointer to rte_eth_dev structure.
10998 * @param[in] resource
10999 * Pointer to destination array resource.
11000 * @parm[in, out] dev_flow
11001 * Pointer to the dev_flow.
11002 * @param[out] error
11003 * pointer to error structure.
11006 * 0 on success otherwise -errno and errno is set.
11009 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
11010 struct mlx5_flow_dv_dest_array_resource *resource,
11011 struct mlx5_flow *dev_flow,
11012 struct rte_flow_error *error)
11014 struct mlx5_flow_dv_dest_array_resource *cache_resource;
11015 struct mlx5_priv *priv = dev->data->dev_private;
11016 struct mlx5_cache_entry *entry;
11017 struct mlx5_flow_cb_ctx ctx = {
11023 entry = mlx5_cache_register(&priv->sh->dest_array_list, &ctx);
11026 cache_resource = container_of(entry, typeof(*cache_resource), entry);
11027 dev_flow->handle->dvh.rix_dest_array = cache_resource->idx;
11028 dev_flow->dv.dest_array_res = cache_resource;
11033 * Convert Sample action to DV specification.
11036 * Pointer to rte_eth_dev structure.
11037 * @param[in] action
11038 * Pointer to sample action structure.
11039 * @param[in, out] dev_flow
11040 * Pointer to the mlx5_flow.
11042 * Pointer to the flow attributes.
11043 * @param[in, out] num_of_dest
11044 * Pointer to the num of destination.
11045 * @param[in, out] sample_actions
11046 * Pointer to sample actions list.
11047 * @param[in, out] res
11048 * Pointer to sample resource.
11049 * @param[out] error
11050 * Pointer to the error structure.
11053 * 0 on success, a negative errno value otherwise and rte_errno is set.
11056 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
11057 const struct rte_flow_action_sample *action,
11058 struct mlx5_flow *dev_flow,
11059 const struct rte_flow_attr *attr,
11060 uint32_t *num_of_dest,
11061 void **sample_actions,
11062 struct mlx5_flow_dv_sample_resource *res,
11063 struct rte_flow_error *error)
11065 struct mlx5_priv *priv = dev->data->dev_private;
11066 const struct rte_flow_action *sub_actions;
11067 struct mlx5_flow_sub_actions_list *sample_act;
11068 struct mlx5_flow_sub_actions_idx *sample_idx;
11069 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11070 struct rte_flow *flow = dev_flow->flow;
11071 struct mlx5_flow_rss_desc *rss_desc;
11072 uint64_t action_flags = 0;
11075 rss_desc = &wks->rss_desc;
11076 sample_act = &res->sample_act;
11077 sample_idx = &res->sample_idx;
11078 res->ratio = action->ratio;
11079 sub_actions = action->actions;
11080 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
11081 int type = sub_actions->type;
11082 uint32_t pre_rix = 0;
11085 case RTE_FLOW_ACTION_TYPE_QUEUE:
11087 const struct rte_flow_action_queue *queue;
11088 struct mlx5_hrxq *hrxq;
11091 queue = sub_actions->conf;
11092 rss_desc->queue_num = 1;
11093 rss_desc->queue[0] = queue->index;
11094 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11095 rss_desc, &hrxq_idx);
11097 return rte_flow_error_set
11099 RTE_FLOW_ERROR_TYPE_ACTION,
11101 "cannot create fate queue");
11102 sample_act->dr_queue_action = hrxq->action;
11103 sample_idx->rix_hrxq = hrxq_idx;
11104 sample_actions[sample_act->actions_num++] =
11107 action_flags |= MLX5_FLOW_ACTION_QUEUE;
11108 if (action_flags & MLX5_FLOW_ACTION_MARK)
11109 dev_flow->handle->rix_hrxq = hrxq_idx;
11110 dev_flow->handle->fate_action =
11111 MLX5_FLOW_FATE_QUEUE;
11114 case RTE_FLOW_ACTION_TYPE_RSS:
11116 struct mlx5_hrxq *hrxq;
11118 const struct rte_flow_action_rss *rss;
11119 const uint8_t *rss_key;
11121 rss = sub_actions->conf;
11122 memcpy(rss_desc->queue, rss->queue,
11123 rss->queue_num * sizeof(uint16_t));
11124 rss_desc->queue_num = rss->queue_num;
11125 /* NULL RSS key indicates default RSS key. */
11126 rss_key = !rss->key ? rss_hash_default_key : rss->key;
11127 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
11129 * rss->level and rss.types should be set in advance
11130 * when expanding items for RSS.
11132 flow_dv_hashfields_set(dev_flow, rss_desc);
11133 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11134 rss_desc, &hrxq_idx);
11136 return rte_flow_error_set
11138 RTE_FLOW_ERROR_TYPE_ACTION,
11140 "cannot create fate queue");
11141 sample_act->dr_queue_action = hrxq->action;
11142 sample_idx->rix_hrxq = hrxq_idx;
11143 sample_actions[sample_act->actions_num++] =
11146 action_flags |= MLX5_FLOW_ACTION_RSS;
11147 if (action_flags & MLX5_FLOW_ACTION_MARK)
11148 dev_flow->handle->rix_hrxq = hrxq_idx;
11149 dev_flow->handle->fate_action =
11150 MLX5_FLOW_FATE_QUEUE;
11153 case RTE_FLOW_ACTION_TYPE_MARK:
11155 uint32_t tag_be = mlx5_flow_mark_set
11156 (((const struct rte_flow_action_mark *)
11157 (sub_actions->conf))->id);
11159 dev_flow->handle->mark = 1;
11160 pre_rix = dev_flow->handle->dvh.rix_tag;
11161 /* Save the mark resource before sample */
11162 pre_r = dev_flow->dv.tag_resource;
11163 if (flow_dv_tag_resource_register(dev, tag_be,
11166 MLX5_ASSERT(dev_flow->dv.tag_resource);
11167 sample_act->dr_tag_action =
11168 dev_flow->dv.tag_resource->action;
11169 sample_idx->rix_tag =
11170 dev_flow->handle->dvh.rix_tag;
11171 sample_actions[sample_act->actions_num++] =
11172 sample_act->dr_tag_action;
11173 /* Recover the mark resource after sample */
11174 dev_flow->dv.tag_resource = pre_r;
11175 dev_flow->handle->dvh.rix_tag = pre_rix;
11176 action_flags |= MLX5_FLOW_ACTION_MARK;
11179 case RTE_FLOW_ACTION_TYPE_COUNT:
11181 if (!flow->counter) {
11183 flow_dv_translate_create_counter(dev,
11184 dev_flow, sub_actions->conf,
11186 if (!flow->counter)
11187 return rte_flow_error_set
11189 RTE_FLOW_ERROR_TYPE_ACTION,
11191 "cannot create counter"
11194 sample_act->dr_cnt_action =
11195 (flow_dv_counter_get_by_idx(dev,
11196 flow->counter, NULL))->action;
11197 sample_actions[sample_act->actions_num++] =
11198 sample_act->dr_cnt_action;
11199 action_flags |= MLX5_FLOW_ACTION_COUNT;
11202 case RTE_FLOW_ACTION_TYPE_PORT_ID:
11204 struct mlx5_flow_dv_port_id_action_resource
11206 uint32_t port_id = 0;
11208 memset(&port_id_resource, 0, sizeof(port_id_resource));
11209 /* Save the port id resource before sample */
11210 pre_rix = dev_flow->handle->rix_port_id_action;
11211 pre_r = dev_flow->dv.port_id_action;
11212 if (flow_dv_translate_action_port_id(dev, sub_actions,
11215 port_id_resource.port_id = port_id;
11216 if (flow_dv_port_id_action_resource_register
11217 (dev, &port_id_resource, dev_flow, error))
11219 sample_act->dr_port_id_action =
11220 dev_flow->dv.port_id_action->action;
11221 sample_idx->rix_port_id_action =
11222 dev_flow->handle->rix_port_id_action;
11223 sample_actions[sample_act->actions_num++] =
11224 sample_act->dr_port_id_action;
11225 /* Recover the port id resource after sample */
11226 dev_flow->dv.port_id_action = pre_r;
11227 dev_flow->handle->rix_port_id_action = pre_rix;
11229 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
11232 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11233 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11234 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11235 /* Save the encap resource before sample */
11236 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
11237 pre_r = dev_flow->dv.encap_decap;
11238 if (flow_dv_create_action_l2_encap(dev, sub_actions,
11243 sample_act->dr_encap_action =
11244 dev_flow->dv.encap_decap->action;
11245 sample_idx->rix_encap_decap =
11246 dev_flow->handle->dvh.rix_encap_decap;
11247 sample_actions[sample_act->actions_num++] =
11248 sample_act->dr_encap_action;
11249 /* Recover the encap resource after sample */
11250 dev_flow->dv.encap_decap = pre_r;
11251 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
11252 action_flags |= MLX5_FLOW_ACTION_ENCAP;
11255 return rte_flow_error_set(error, EINVAL,
11256 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11258 "Not support for sampler action");
11261 sample_act->action_flags = action_flags;
11262 res->ft_id = dev_flow->dv.group;
11263 if (attr->transfer) {
11265 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
11266 uint64_t set_action;
11267 } action_ctx = { .set_action = 0 };
11269 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
11270 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
11271 MLX5_MODIFICATION_TYPE_SET);
11272 MLX5_SET(set_action_in, action_ctx.action_in, field,
11273 MLX5_MODI_META_REG_C_0);
11274 MLX5_SET(set_action_in, action_ctx.action_in, data,
11275 priv->vport_meta_tag);
11276 res->set_action = action_ctx.set_action;
11277 } else if (attr->ingress) {
11278 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
11280 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
11286 * Convert Sample action to DV specification.
11289 * Pointer to rte_eth_dev structure.
11290 * @param[in, out] dev_flow
11291 * Pointer to the mlx5_flow.
11292 * @param[in] num_of_dest
11293 * The num of destination.
11294 * @param[in, out] res
11295 * Pointer to sample resource.
11296 * @param[in, out] mdest_res
11297 * Pointer to destination array resource.
11298 * @param[in] sample_actions
11299 * Pointer to sample path actions list.
11300 * @param[in] action_flags
11301 * Holds the actions detected until now.
11302 * @param[out] error
11303 * Pointer to the error structure.
11306 * 0 on success, a negative errno value otherwise and rte_errno is set.
11309 flow_dv_create_action_sample(struct rte_eth_dev *dev,
11310 struct mlx5_flow *dev_flow,
11311 uint32_t num_of_dest,
11312 struct mlx5_flow_dv_sample_resource *res,
11313 struct mlx5_flow_dv_dest_array_resource *mdest_res,
11314 void **sample_actions,
11315 uint64_t action_flags,
11316 struct rte_flow_error *error)
11318 /* update normal path action resource into last index of array */
11319 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
11320 struct mlx5_flow_sub_actions_list *sample_act =
11321 &mdest_res->sample_act[dest_index];
11322 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11323 struct mlx5_flow_rss_desc *rss_desc;
11324 uint32_t normal_idx = 0;
11325 struct mlx5_hrxq *hrxq;
11329 rss_desc = &wks->rss_desc;
11330 if (num_of_dest > 1) {
11331 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
11332 /* Handle QP action for mirroring */
11333 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11334 rss_desc, &hrxq_idx);
11336 return rte_flow_error_set
11338 RTE_FLOW_ERROR_TYPE_ACTION,
11340 "cannot create rx queue");
11342 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
11343 sample_act->dr_queue_action = hrxq->action;
11344 if (action_flags & MLX5_FLOW_ACTION_MARK)
11345 dev_flow->handle->rix_hrxq = hrxq_idx;
11346 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
11348 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
11350 mdest_res->sample_idx[dest_index].rix_encap_decap =
11351 dev_flow->handle->dvh.rix_encap_decap;
11352 sample_act->dr_encap_action =
11353 dev_flow->dv.encap_decap->action;
11354 dev_flow->handle->dvh.rix_encap_decap = 0;
11356 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
11358 mdest_res->sample_idx[dest_index].rix_port_id_action =
11359 dev_flow->handle->rix_port_id_action;
11360 sample_act->dr_port_id_action =
11361 dev_flow->dv.port_id_action->action;
11362 dev_flow->handle->rix_port_id_action = 0;
11364 if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
11366 mdest_res->sample_idx[dest_index].rix_jump =
11367 dev_flow->handle->rix_jump;
11368 sample_act->dr_jump_action =
11369 dev_flow->dv.jump->action;
11370 dev_flow->handle->rix_jump = 0;
11372 sample_act->actions_num = normal_idx;
11373 /* update sample action resource into first index of array */
11374 mdest_res->ft_type = res->ft_type;
11375 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
11376 sizeof(struct mlx5_flow_sub_actions_idx));
11377 memcpy(&mdest_res->sample_act[0], &res->sample_act,
11378 sizeof(struct mlx5_flow_sub_actions_list));
11379 mdest_res->num_of_dest = num_of_dest;
11380 if (flow_dv_dest_array_resource_register(dev, mdest_res,
11382 return rte_flow_error_set(error, EINVAL,
11383 RTE_FLOW_ERROR_TYPE_ACTION,
11384 NULL, "can't create sample "
11387 res->sub_actions = sample_actions;
11388 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
11389 return rte_flow_error_set(error, EINVAL,
11390 RTE_FLOW_ERROR_TYPE_ACTION,
11392 "can't create sample action");
11398 * Remove an ASO age action from age actions list.
11401 * Pointer to the Ethernet device structure.
11403 * Pointer to the aso age action handler.
11406 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
11407 struct mlx5_aso_age_action *age)
11409 struct mlx5_age_info *age_info;
11410 struct mlx5_age_param *age_param = &age->age_params;
11411 struct mlx5_priv *priv = dev->data->dev_private;
11412 uint16_t expected = AGE_CANDIDATE;
11414 age_info = GET_PORT_AGE_INFO(priv);
11415 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
11416 AGE_FREE, false, __ATOMIC_RELAXED,
11417 __ATOMIC_RELAXED)) {
11419 * We need the lock even it is age timeout,
11420 * since age action may still in process.
11422 rte_spinlock_lock(&age_info->aged_sl);
11423 LIST_REMOVE(age, next);
11424 rte_spinlock_unlock(&age_info->aged_sl);
11425 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
11430 * Release an ASO age action.
11433 * Pointer to the Ethernet device structure.
11434 * @param[in] age_idx
11435 * Index of ASO age action to release.
11437 * True if the release operation is during flow destroy operation.
11438 * False if the release operation is during action destroy operation.
11441 * 0 when age action was removed, otherwise the number of references.
11444 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
11446 struct mlx5_priv *priv = dev->data->dev_private;
11447 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11448 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
11449 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
11452 flow_dv_aso_age_remove_from_age(dev, age);
11453 rte_spinlock_lock(&mng->free_sl);
11454 LIST_INSERT_HEAD(&mng->free, age, next);
11455 rte_spinlock_unlock(&mng->free_sl);
11461 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
11464 * Pointer to the Ethernet device structure.
11467 * 0 on success, otherwise negative errno value and rte_errno is set.
11470 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
11472 struct mlx5_priv *priv = dev->data->dev_private;
11473 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11474 void *old_pools = mng->pools;
11475 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
11476 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
11477 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11480 rte_errno = ENOMEM;
11484 memcpy(pools, old_pools,
11485 mng->n * sizeof(struct mlx5_flow_counter_pool *));
11486 mlx5_free(old_pools);
11488 /* First ASO flow hit allocation - starting ASO data-path. */
11489 int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
11497 mng->pools = pools;
11502 * Create and initialize a new ASO aging pool.
11505 * Pointer to the Ethernet device structure.
11506 * @param[out] age_free
11507 * Where to put the pointer of a new age action.
11510 * The age actions pool pointer and @p age_free is set on success,
11511 * NULL otherwise and rte_errno is set.
11513 static struct mlx5_aso_age_pool *
11514 flow_dv_age_pool_create(struct rte_eth_dev *dev,
11515 struct mlx5_aso_age_action **age_free)
11517 struct mlx5_priv *priv = dev->data->dev_private;
11518 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11519 struct mlx5_aso_age_pool *pool = NULL;
11520 struct mlx5_devx_obj *obj = NULL;
11523 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->ctx,
11526 rte_errno = ENODATA;
11527 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
11530 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
11532 claim_zero(mlx5_devx_cmd_destroy(obj));
11533 rte_errno = ENOMEM;
11536 pool->flow_hit_aso_obj = obj;
11537 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
11538 rte_spinlock_lock(&mng->resize_sl);
11539 pool->index = mng->next;
11540 /* Resize pools array if there is no room for the new pool in it. */
11541 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
11542 claim_zero(mlx5_devx_cmd_destroy(obj));
11544 rte_spinlock_unlock(&mng->resize_sl);
11547 mng->pools[pool->index] = pool;
11549 rte_spinlock_unlock(&mng->resize_sl);
11550 /* Assign the first action in the new pool, the rest go to free list. */
11551 *age_free = &pool->actions[0];
11552 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
11553 pool->actions[i].offset = i;
11554 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
11560 * Allocate a ASO aging bit.
11563 * Pointer to the Ethernet device structure.
11564 * @param[out] error
11565 * Pointer to the error structure.
11568 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
11571 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
11573 struct mlx5_priv *priv = dev->data->dev_private;
11574 const struct mlx5_aso_age_pool *pool;
11575 struct mlx5_aso_age_action *age_free = NULL;
11576 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11579 /* Try to get the next free age action bit. */
11580 rte_spinlock_lock(&mng->free_sl);
11581 age_free = LIST_FIRST(&mng->free);
11583 LIST_REMOVE(age_free, next);
11584 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
11585 rte_spinlock_unlock(&mng->free_sl);
11586 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
11587 NULL, "failed to create ASO age pool");
11588 return 0; /* 0 is an error. */
11590 rte_spinlock_unlock(&mng->free_sl);
11591 pool = container_of
11592 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
11593 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
11595 if (!age_free->dr_action) {
11596 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
11600 rte_flow_error_set(error, rte_errno,
11601 RTE_FLOW_ERROR_TYPE_ACTION,
11602 NULL, "failed to get reg_c "
11603 "for ASO flow hit");
11604 return 0; /* 0 is an error. */
11606 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
11607 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
11608 (priv->sh->rx_domain,
11609 pool->flow_hit_aso_obj->obj, age_free->offset,
11610 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
11611 (reg_c - REG_C_0));
11612 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
11613 if (!age_free->dr_action) {
11615 rte_spinlock_lock(&mng->free_sl);
11616 LIST_INSERT_HEAD(&mng->free, age_free, next);
11617 rte_spinlock_unlock(&mng->free_sl);
11618 rte_flow_error_set(error, rte_errno,
11619 RTE_FLOW_ERROR_TYPE_ACTION,
11620 NULL, "failed to create ASO "
11621 "flow hit action");
11622 return 0; /* 0 is an error. */
11625 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
11626 return pool->index | ((age_free->offset + 1) << 16);
11630 * Initialize flow ASO age parameters.
11633 * Pointer to rte_eth_dev structure.
11634 * @param[in] age_idx
11635 * Index of ASO age action.
11636 * @param[in] context
11637 * Pointer to flow counter age context.
11638 * @param[in] timeout
11639 * Aging timeout in seconds.
11643 flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
11648 struct mlx5_aso_age_action *aso_age;
11650 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
11651 MLX5_ASSERT(aso_age);
11652 aso_age->age_params.context = context;
11653 aso_age->age_params.timeout = timeout;
11654 aso_age->age_params.port_id = dev->data->port_id;
11655 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
11657 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
11662 flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
11663 const struct rte_flow_item_integrity *value,
11664 void *headers_m, void *headers_v)
11667 /* application l4_ok filter aggregates all hardware l4 filters
11668 * therefore hw l4_checksum_ok must be implicitly added here.
11670 struct rte_flow_item_integrity local_item;
11672 local_item.l4_csum_ok = 1;
11673 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
11674 local_item.l4_csum_ok);
11675 if (value->l4_ok) {
11676 /* application l4_ok = 1 matches sets both hw flags
11677 * l4_ok and l4_checksum_ok flags to 1.
11679 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11680 l4_checksum_ok, local_item.l4_csum_ok);
11681 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_ok,
11683 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_ok,
11686 /* application l4_ok = 0 matches on hw flag
11687 * l4_checksum_ok = 0 only.
11689 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11690 l4_checksum_ok, 0);
11692 } else if (mask->l4_csum_ok) {
11693 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
11695 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_checksum_ok,
11696 value->l4_csum_ok);
11701 flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
11702 const struct rte_flow_item_integrity *value,
11703 void *headers_m, void *headers_v,
11707 /* application l3_ok filter aggregates all hardware l3 filters
11708 * therefore hw ipv4_checksum_ok must be implicitly added here.
11710 struct rte_flow_item_integrity local_item;
11712 local_item.ipv4_csum_ok = !!is_ipv4;
11713 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
11714 local_item.ipv4_csum_ok);
11715 if (value->l3_ok) {
11716 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11717 ipv4_checksum_ok, local_item.ipv4_csum_ok);
11718 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l3_ok,
11720 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l3_ok,
11723 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11724 ipv4_checksum_ok, 0);
11726 } else if (mask->ipv4_csum_ok) {
11727 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
11728 mask->ipv4_csum_ok);
11729 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
11730 value->ipv4_csum_ok);
11735 flow_dv_translate_item_integrity(void *matcher, void *key,
11736 const struct rte_flow_item *head_item,
11737 const struct rte_flow_item *integrity_item)
11739 const struct rte_flow_item_integrity *mask = integrity_item->mask;
11740 const struct rte_flow_item_integrity *value = integrity_item->spec;
11741 const struct rte_flow_item *tunnel_item, *end_item, *item;
11744 uint32_t l3_protocol;
11749 mask = &rte_flow_item_integrity_mask;
11750 if (value->level > 1) {
11751 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
11753 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
11755 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
11757 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11759 tunnel_item = mlx5_flow_find_tunnel_item(head_item);
11760 if (value->level > 1) {
11761 /* tunnel item was verified during the item validation */
11762 item = tunnel_item;
11763 end_item = mlx5_find_end_item(tunnel_item);
11766 end_item = tunnel_item ? tunnel_item :
11767 mlx5_find_end_item(integrity_item);
11769 l3_protocol = mask->l3_ok ?
11770 mlx5_flow_locate_proto_l3(&item, end_item) : 0;
11771 flow_dv_translate_integrity_l3(mask, value, headers_m, headers_v,
11772 l3_protocol == RTE_ETHER_TYPE_IPV4);
11773 flow_dv_translate_integrity_l4(mask, value, headers_m, headers_v);
11777 * Prepares DV flow counter with aging configuration.
11778 * Gets it by index when exists, creates a new one when doesn't.
11781 * Pointer to rte_eth_dev structure.
11782 * @param[in] dev_flow
11783 * Pointer to the mlx5_flow.
11784 * @param[in, out] flow
11785 * Pointer to the sub flow.
11787 * Pointer to the counter action configuration.
11789 * Pointer to the aging action configuration.
11790 * @param[out] error
11791 * Pointer to the error structure.
11794 * Pointer to the counter, NULL otherwise.
11796 static struct mlx5_flow_counter *
11797 flow_dv_prepare_counter(struct rte_eth_dev *dev,
11798 struct mlx5_flow *dev_flow,
11799 struct rte_flow *flow,
11800 const struct rte_flow_action_count *count,
11801 const struct rte_flow_action_age *age,
11802 struct rte_flow_error *error)
11804 if (!flow->counter) {
11805 flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
11807 if (!flow->counter) {
11808 rte_flow_error_set(error, rte_errno,
11809 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11810 "cannot create counter object.");
11814 return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
11818 * Release an ASO CT action by its own device.
11821 * Pointer to the Ethernet device structure.
11823 * Index of ASO CT action to release.
11826 * 0 when CT action was removed, otherwise the number of references.
11829 flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
11831 struct mlx5_priv *priv = dev->data->dev_private;
11832 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11834 struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
11835 enum mlx5_aso_ct_state state =
11836 __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
11838 /* Cannot release when CT is in the ASO SQ. */
11839 if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
11841 ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
11843 if (ct->dr_action_orig) {
11844 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11845 claim_zero(mlx5_glue->destroy_flow_action
11846 (ct->dr_action_orig));
11848 ct->dr_action_orig = NULL;
11850 if (ct->dr_action_rply) {
11851 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11852 claim_zero(mlx5_glue->destroy_flow_action
11853 (ct->dr_action_rply));
11855 ct->dr_action_rply = NULL;
11857 /* Clear the state to free, no need in 1st allocation. */
11858 MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
11859 rte_spinlock_lock(&mng->ct_sl);
11860 LIST_INSERT_HEAD(&mng->free_cts, ct, next);
11861 rte_spinlock_unlock(&mng->ct_sl);
11867 flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx)
11869 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
11870 uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
11871 struct rte_eth_dev *owndev = &rte_eth_devices[owner];
11874 MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
11875 if (dev->data->dev_started != 1)
11877 return flow_dv_aso_ct_dev_release(owndev, idx);
11881 * Resize the ASO CT pools array by 64 pools.
11884 * Pointer to the Ethernet device structure.
11887 * 0 on success, otherwise negative errno value and rte_errno is set.
11890 flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
11892 struct mlx5_priv *priv = dev->data->dev_private;
11893 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11894 void *old_pools = mng->pools;
11895 /* Magic number now, need a macro. */
11896 uint32_t resize = mng->n + 64;
11897 uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
11898 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11901 rte_errno = ENOMEM;
11904 rte_rwlock_write_lock(&mng->resize_rwl);
11905 /* ASO SQ/QP was already initialized in the startup. */
11907 /* Realloc could be an alternative choice. */
11908 rte_memcpy(pools, old_pools,
11909 mng->n * sizeof(struct mlx5_aso_ct_pool *));
11910 mlx5_free(old_pools);
11913 mng->pools = pools;
11914 rte_rwlock_write_unlock(&mng->resize_rwl);
11919 * Create and initialize a new ASO CT pool.
11922 * Pointer to the Ethernet device structure.
11923 * @param[out] ct_free
11924 * Where to put the pointer of a new CT action.
11927 * The CT actions pool pointer and @p ct_free is set on success,
11928 * NULL otherwise and rte_errno is set.
11930 static struct mlx5_aso_ct_pool *
11931 flow_dv_ct_pool_create(struct rte_eth_dev *dev,
11932 struct mlx5_aso_ct_action **ct_free)
11934 struct mlx5_priv *priv = dev->data->dev_private;
11935 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11936 struct mlx5_aso_ct_pool *pool = NULL;
11937 struct mlx5_devx_obj *obj = NULL;
11939 uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
11941 obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->ctx,
11942 priv->sh->pdn, log_obj_size);
11944 rte_errno = ENODATA;
11945 DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
11948 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
11950 rte_errno = ENOMEM;
11951 claim_zero(mlx5_devx_cmd_destroy(obj));
11954 pool->devx_obj = obj;
11955 pool->index = mng->next;
11956 /* Resize pools array if there is no room for the new pool in it. */
11957 if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
11958 claim_zero(mlx5_devx_cmd_destroy(obj));
11962 mng->pools[pool->index] = pool;
11964 /* Assign the first action in the new pool, the rest go to free list. */
11965 *ct_free = &pool->actions[0];
11966 /* Lock outside, the list operation is safe here. */
11967 for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
11968 /* refcnt is 0 when allocating the memory. */
11969 pool->actions[i].offset = i;
11970 LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
11976 * Allocate a ASO CT action from free list.
11979 * Pointer to the Ethernet device structure.
11980 * @param[out] error
11981 * Pointer to the error structure.
11984 * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
11987 flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
11989 struct mlx5_priv *priv = dev->data->dev_private;
11990 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11991 struct mlx5_aso_ct_action *ct = NULL;
11992 struct mlx5_aso_ct_pool *pool;
11997 if (!priv->config.devx) {
11998 rte_errno = ENOTSUP;
12001 /* Get a free CT action, if no, a new pool will be created. */
12002 rte_spinlock_lock(&mng->ct_sl);
12003 ct = LIST_FIRST(&mng->free_cts);
12005 LIST_REMOVE(ct, next);
12006 } else if (!flow_dv_ct_pool_create(dev, &ct)) {
12007 rte_spinlock_unlock(&mng->ct_sl);
12008 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
12009 NULL, "failed to create ASO CT pool");
12012 rte_spinlock_unlock(&mng->ct_sl);
12013 pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
12014 ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
12015 /* 0: inactive, 1: created, 2+: used by flows. */
12016 __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
12017 reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
12018 if (!ct->dr_action_orig) {
12019 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12020 ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
12021 (priv->sh->rx_domain, pool->devx_obj->obj,
12023 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
12026 RTE_SET_USED(reg_c);
12028 if (!ct->dr_action_orig) {
12029 flow_dv_aso_ct_dev_release(dev, ct_idx);
12030 rte_flow_error_set(error, rte_errno,
12031 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12032 "failed to create ASO CT action");
12036 if (!ct->dr_action_rply) {
12037 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
12038 ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
12039 (priv->sh->rx_domain, pool->devx_obj->obj,
12041 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
12044 if (!ct->dr_action_rply) {
12045 flow_dv_aso_ct_dev_release(dev, ct_idx);
12046 rte_flow_error_set(error, rte_errno,
12047 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12048 "failed to create ASO CT action");
12056 * Create a conntrack object with context and actions by using ASO mechanism.
12059 * Pointer to rte_eth_dev structure.
12061 * Pointer to conntrack information profile.
12062 * @param[out] error
12063 * Pointer to the error structure.
12066 * Index to conntrack object on success, 0 otherwise.
12069 flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
12070 const struct rte_flow_action_conntrack *pro,
12071 struct rte_flow_error *error)
12073 struct mlx5_priv *priv = dev->data->dev_private;
12074 struct mlx5_dev_ctx_shared *sh = priv->sh;
12075 struct mlx5_aso_ct_action *ct;
12078 if (!sh->ct_aso_en)
12079 return rte_flow_error_set(error, ENOTSUP,
12080 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12081 "Connection is not supported");
12082 idx = flow_dv_aso_ct_alloc(dev, error);
12084 return rte_flow_error_set(error, rte_errno,
12085 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12086 "Failed to allocate CT object");
12087 ct = flow_aso_ct_get_by_dev_idx(dev, idx);
12088 if (mlx5_aso_ct_update_by_wqe(sh, ct, pro))
12089 return rte_flow_error_set(error, EBUSY,
12090 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
12091 "Failed to update CT");
12092 ct->is_original = !!pro->is_original_dir;
12093 ct->peer = pro->peer_port;
12098 * Fill the flow with DV spec, lock free
12099 * (mutex should be acquired by caller).
12102 * Pointer to rte_eth_dev structure.
12103 * @param[in, out] dev_flow
12104 * Pointer to the sub flow.
12106 * Pointer to the flow attributes.
12108 * Pointer to the list of items.
12109 * @param[in] actions
12110 * Pointer to the list of actions.
12111 * @param[out] error
12112 * Pointer to the error structure.
12115 * 0 on success, a negative errno value otherwise and rte_errno is set.
12118 flow_dv_translate(struct rte_eth_dev *dev,
12119 struct mlx5_flow *dev_flow,
12120 const struct rte_flow_attr *attr,
12121 const struct rte_flow_item items[],
12122 const struct rte_flow_action actions[],
12123 struct rte_flow_error *error)
12125 struct mlx5_priv *priv = dev->data->dev_private;
12126 struct mlx5_dev_config *dev_conf = &priv->config;
12127 struct rte_flow *flow = dev_flow->flow;
12128 struct mlx5_flow_handle *handle = dev_flow->handle;
12129 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12130 struct mlx5_flow_rss_desc *rss_desc;
12131 uint64_t item_flags = 0;
12132 uint64_t last_item = 0;
12133 uint64_t action_flags = 0;
12134 struct mlx5_flow_dv_matcher matcher = {
12136 .size = sizeof(matcher.mask.buf),
12140 bool actions_end = false;
12142 struct mlx5_flow_dv_modify_hdr_resource res;
12143 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
12144 sizeof(struct mlx5_modification_cmd) *
12145 (MLX5_MAX_MODIFY_NUM + 1)];
12147 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
12148 const struct rte_flow_action_count *count = NULL;
12149 const struct rte_flow_action_age *non_shared_age = NULL;
12150 union flow_dv_attr flow_attr = { .attr = 0 };
12152 union mlx5_flow_tbl_key tbl_key;
12153 uint32_t modify_action_position = UINT32_MAX;
12154 void *match_mask = matcher.mask.buf;
12155 void *match_value = dev_flow->dv.value.buf;
12156 uint8_t next_protocol = 0xff;
12157 struct rte_vlan_hdr vlan = { 0 };
12158 struct mlx5_flow_dv_dest_array_resource mdest_res;
12159 struct mlx5_flow_dv_sample_resource sample_res;
12160 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
12161 const struct rte_flow_action_sample *sample = NULL;
12162 struct mlx5_flow_sub_actions_list *sample_act;
12163 uint32_t sample_act_pos = UINT32_MAX;
12164 uint32_t age_act_pos = UINT32_MAX;
12165 uint32_t num_of_dest = 0;
12166 int tmp_actions_n = 0;
12169 const struct mlx5_flow_tunnel *tunnel = NULL;
12170 struct flow_grp_info grp_info = {
12171 .external = !!dev_flow->external,
12172 .transfer = !!attr->transfer,
12173 .fdb_def_rule = !!priv->fdb_def_rule,
12174 .skip_scale = dev_flow->skip_scale &
12175 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
12176 .std_tbl_fix = true,
12178 const struct rte_flow_item *head_item = items;
12181 return rte_flow_error_set(error, ENOMEM,
12182 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12184 "failed to push flow workspace");
12185 rss_desc = &wks->rss_desc;
12186 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
12187 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
12188 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12189 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12190 /* update normal path action resource into last index of array */
12191 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
12192 if (is_tunnel_offload_active(dev)) {
12193 if (dev_flow->tunnel) {
12194 RTE_VERIFY(dev_flow->tof_type ==
12195 MLX5_TUNNEL_OFFLOAD_MISS_RULE);
12196 tunnel = dev_flow->tunnel;
12198 tunnel = mlx5_get_tof(items, actions,
12199 &dev_flow->tof_type);
12200 dev_flow->tunnel = tunnel;
12202 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
12203 (dev, attr, tunnel, dev_flow->tof_type);
12205 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12206 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12207 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
12211 dev_flow->dv.group = table;
12212 if (attr->transfer)
12213 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12214 /* number of actions must be set to 0 in case of dirty stack. */
12215 mhdr_res->actions_num = 0;
12216 if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
12218 * do not add decap action if match rule drops packet
12219 * HW rejects rules with decap & drop
12221 * if tunnel match rule was inserted before matching tunnel set
12222 * rule flow table used in the match rule must be registered.
12223 * current implementation handles that in the
12224 * flow_dv_match_register() at the function end.
12226 bool add_decap = true;
12227 const struct rte_flow_action *ptr = actions;
12229 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
12230 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
12236 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12240 dev_flow->dv.actions[actions_n++] =
12241 dev_flow->dv.encap_decap->action;
12242 action_flags |= MLX5_FLOW_ACTION_DECAP;
12245 for (; !actions_end ; actions++) {
12246 const struct rte_flow_action_queue *queue;
12247 const struct rte_flow_action_rss *rss;
12248 const struct rte_flow_action *action = actions;
12249 const uint8_t *rss_key;
12250 struct mlx5_flow_tbl_resource *tbl;
12251 struct mlx5_aso_age_action *age_act;
12252 struct mlx5_flow_counter *cnt_act;
12253 uint32_t port_id = 0;
12254 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
12255 int action_type = actions->type;
12256 const struct rte_flow_action *found_action = NULL;
12257 uint32_t jump_group = 0;
12258 uint32_t owner_idx;
12259 struct mlx5_aso_ct_action *ct;
12261 if (!mlx5_flow_os_action_supported(action_type))
12262 return rte_flow_error_set(error, ENOTSUP,
12263 RTE_FLOW_ERROR_TYPE_ACTION,
12265 "action not supported");
12266 switch (action_type) {
12267 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
12268 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
12270 case RTE_FLOW_ACTION_TYPE_VOID:
12272 case RTE_FLOW_ACTION_TYPE_PORT_ID:
12273 if (flow_dv_translate_action_port_id(dev, action,
12276 port_id_resource.port_id = port_id;
12277 MLX5_ASSERT(!handle->rix_port_id_action);
12278 if (flow_dv_port_id_action_resource_register
12279 (dev, &port_id_resource, dev_flow, error))
12281 dev_flow->dv.actions[actions_n++] =
12282 dev_flow->dv.port_id_action->action;
12283 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12284 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
12285 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12288 case RTE_FLOW_ACTION_TYPE_FLAG:
12289 action_flags |= MLX5_FLOW_ACTION_FLAG;
12290 dev_flow->handle->mark = 1;
12291 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12292 struct rte_flow_action_mark mark = {
12293 .id = MLX5_FLOW_MARK_DEFAULT,
12296 if (flow_dv_convert_action_mark(dev, &mark,
12300 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12303 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
12305 * Only one FLAG or MARK is supported per device flow
12306 * right now. So the pointer to the tag resource must be
12307 * zero before the register process.
12309 MLX5_ASSERT(!handle->dvh.rix_tag);
12310 if (flow_dv_tag_resource_register(dev, tag_be,
12313 MLX5_ASSERT(dev_flow->dv.tag_resource);
12314 dev_flow->dv.actions[actions_n++] =
12315 dev_flow->dv.tag_resource->action;
12317 case RTE_FLOW_ACTION_TYPE_MARK:
12318 action_flags |= MLX5_FLOW_ACTION_MARK;
12319 dev_flow->handle->mark = 1;
12320 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12321 const struct rte_flow_action_mark *mark =
12322 (const struct rte_flow_action_mark *)
12325 if (flow_dv_convert_action_mark(dev, mark,
12329 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12333 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
12334 /* Legacy (non-extensive) MARK action. */
12335 tag_be = mlx5_flow_mark_set
12336 (((const struct rte_flow_action_mark *)
12337 (actions->conf))->id);
12338 MLX5_ASSERT(!handle->dvh.rix_tag);
12339 if (flow_dv_tag_resource_register(dev, tag_be,
12342 MLX5_ASSERT(dev_flow->dv.tag_resource);
12343 dev_flow->dv.actions[actions_n++] =
12344 dev_flow->dv.tag_resource->action;
12346 case RTE_FLOW_ACTION_TYPE_SET_META:
12347 if (flow_dv_convert_action_set_meta
12348 (dev, mhdr_res, attr,
12349 (const struct rte_flow_action_set_meta *)
12350 actions->conf, error))
12352 action_flags |= MLX5_FLOW_ACTION_SET_META;
12354 case RTE_FLOW_ACTION_TYPE_SET_TAG:
12355 if (flow_dv_convert_action_set_tag
12357 (const struct rte_flow_action_set_tag *)
12358 actions->conf, error))
12360 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12362 case RTE_FLOW_ACTION_TYPE_DROP:
12363 action_flags |= MLX5_FLOW_ACTION_DROP;
12364 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
12366 case RTE_FLOW_ACTION_TYPE_QUEUE:
12367 queue = actions->conf;
12368 rss_desc->queue_num = 1;
12369 rss_desc->queue[0] = queue->index;
12370 action_flags |= MLX5_FLOW_ACTION_QUEUE;
12371 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
12372 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
12375 case RTE_FLOW_ACTION_TYPE_RSS:
12376 rss = actions->conf;
12377 memcpy(rss_desc->queue, rss->queue,
12378 rss->queue_num * sizeof(uint16_t));
12379 rss_desc->queue_num = rss->queue_num;
12380 /* NULL RSS key indicates default RSS key. */
12381 rss_key = !rss->key ? rss_hash_default_key : rss->key;
12382 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12384 * rss->level and rss.types should be set in advance
12385 * when expanding items for RSS.
12387 action_flags |= MLX5_FLOW_ACTION_RSS;
12388 dev_flow->handle->fate_action = rss_desc->shared_rss ?
12389 MLX5_FLOW_FATE_SHARED_RSS :
12390 MLX5_FLOW_FATE_QUEUE;
12392 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
12393 flow->age = (uint32_t)(uintptr_t)(action->conf);
12394 age_act = flow_aso_age_get_by_idx(dev, flow->age);
12395 __atomic_fetch_add(&age_act->refcnt, 1,
12397 age_act_pos = actions_n++;
12398 action_flags |= MLX5_FLOW_ACTION_AGE;
12400 case RTE_FLOW_ACTION_TYPE_AGE:
12401 non_shared_age = action->conf;
12402 age_act_pos = actions_n++;
12403 action_flags |= MLX5_FLOW_ACTION_AGE;
12405 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
12406 flow->counter = (uint32_t)(uintptr_t)(action->conf);
12407 cnt_act = flow_dv_counter_get_by_idx(dev, flow->counter,
12409 __atomic_fetch_add(&cnt_act->shared_info.refcnt, 1,
12411 /* Save information first, will apply later. */
12412 action_flags |= MLX5_FLOW_ACTION_COUNT;
12414 case RTE_FLOW_ACTION_TYPE_COUNT:
12415 if (!dev_conf->devx) {
12416 return rte_flow_error_set
12418 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12420 "count action not supported");
12422 /* Save information first, will apply later. */
12423 count = action->conf;
12424 action_flags |= MLX5_FLOW_ACTION_COUNT;
12426 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
12427 dev_flow->dv.actions[actions_n++] =
12428 priv->sh->pop_vlan_action;
12429 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
12431 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
12432 if (!(action_flags &
12433 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
12434 flow_dev_get_vlan_info_from_items(items, &vlan);
12435 vlan.eth_proto = rte_be_to_cpu_16
12436 ((((const struct rte_flow_action_of_push_vlan *)
12437 actions->conf)->ethertype));
12438 found_action = mlx5_flow_find_action
12440 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
12442 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12443 found_action = mlx5_flow_find_action
12445 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
12447 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12448 if (flow_dv_create_action_push_vlan
12449 (dev, attr, &vlan, dev_flow, error))
12451 dev_flow->dv.actions[actions_n++] =
12452 dev_flow->dv.push_vlan_res->action;
12453 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
12455 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
12456 /* of_vlan_push action handled this action */
12457 MLX5_ASSERT(action_flags &
12458 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
12460 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
12461 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
12463 flow_dev_get_vlan_info_from_items(items, &vlan);
12464 mlx5_update_vlan_vid_pcp(actions, &vlan);
12465 /* If no VLAN push - this is a modify header action */
12466 if (flow_dv_convert_action_modify_vlan_vid
12467 (mhdr_res, actions, error))
12469 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
12471 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
12472 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
12473 if (flow_dv_create_action_l2_encap(dev, actions,
12478 dev_flow->dv.actions[actions_n++] =
12479 dev_flow->dv.encap_decap->action;
12480 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12481 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12482 sample_act->action_flags |=
12483 MLX5_FLOW_ACTION_ENCAP;
12485 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
12486 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
12487 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12491 dev_flow->dv.actions[actions_n++] =
12492 dev_flow->dv.encap_decap->action;
12493 action_flags |= MLX5_FLOW_ACTION_DECAP;
12495 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
12496 /* Handle encap with preceding decap. */
12497 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
12498 if (flow_dv_create_action_raw_encap
12499 (dev, actions, dev_flow, attr, error))
12501 dev_flow->dv.actions[actions_n++] =
12502 dev_flow->dv.encap_decap->action;
12504 /* Handle encap without preceding decap. */
12505 if (flow_dv_create_action_l2_encap
12506 (dev, actions, dev_flow, attr->transfer,
12509 dev_flow->dv.actions[actions_n++] =
12510 dev_flow->dv.encap_decap->action;
12512 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12513 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12514 sample_act->action_flags |=
12515 MLX5_FLOW_ACTION_ENCAP;
12517 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
12518 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
12520 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
12521 if (flow_dv_create_action_l2_decap
12522 (dev, dev_flow, attr->transfer, error))
12524 dev_flow->dv.actions[actions_n++] =
12525 dev_flow->dv.encap_decap->action;
12527 /* If decap is followed by encap, handle it at encap. */
12528 action_flags |= MLX5_FLOW_ACTION_DECAP;
12530 case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
12531 dev_flow->dv.actions[actions_n++] =
12532 (void *)(uintptr_t)action->conf;
12533 action_flags |= MLX5_FLOW_ACTION_JUMP;
12535 case RTE_FLOW_ACTION_TYPE_JUMP:
12536 jump_group = ((const struct rte_flow_action_jump *)
12537 action->conf)->group;
12538 grp_info.std_tbl_fix = 0;
12539 if (dev_flow->skip_scale &
12540 (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
12541 grp_info.skip_scale = 1;
12543 grp_info.skip_scale = 0;
12544 ret = mlx5_flow_group_to_table(dev, tunnel,
12550 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
12552 !!dev_flow->external,
12553 tunnel, jump_group, 0,
12556 return rte_flow_error_set
12558 RTE_FLOW_ERROR_TYPE_ACTION,
12560 "cannot create jump action.");
12561 if (flow_dv_jump_tbl_resource_register
12562 (dev, tbl, dev_flow, error)) {
12563 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12564 return rte_flow_error_set
12566 RTE_FLOW_ERROR_TYPE_ACTION,
12568 "cannot create jump action.");
12570 dev_flow->dv.actions[actions_n++] =
12571 dev_flow->dv.jump->action;
12572 action_flags |= MLX5_FLOW_ACTION_JUMP;
12573 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
12574 sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
12577 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
12578 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
12579 if (flow_dv_convert_action_modify_mac
12580 (mhdr_res, actions, error))
12582 action_flags |= actions->type ==
12583 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
12584 MLX5_FLOW_ACTION_SET_MAC_SRC :
12585 MLX5_FLOW_ACTION_SET_MAC_DST;
12587 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
12588 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
12589 if (flow_dv_convert_action_modify_ipv4
12590 (mhdr_res, actions, error))
12592 action_flags |= actions->type ==
12593 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
12594 MLX5_FLOW_ACTION_SET_IPV4_SRC :
12595 MLX5_FLOW_ACTION_SET_IPV4_DST;
12597 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
12598 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
12599 if (flow_dv_convert_action_modify_ipv6
12600 (mhdr_res, actions, error))
12602 action_flags |= actions->type ==
12603 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
12604 MLX5_FLOW_ACTION_SET_IPV6_SRC :
12605 MLX5_FLOW_ACTION_SET_IPV6_DST;
12607 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
12608 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
12609 if (flow_dv_convert_action_modify_tp
12610 (mhdr_res, actions, items,
12611 &flow_attr, dev_flow, !!(action_flags &
12612 MLX5_FLOW_ACTION_DECAP), error))
12614 action_flags |= actions->type ==
12615 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
12616 MLX5_FLOW_ACTION_SET_TP_SRC :
12617 MLX5_FLOW_ACTION_SET_TP_DST;
12619 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
12620 if (flow_dv_convert_action_modify_dec_ttl
12621 (mhdr_res, items, &flow_attr, dev_flow,
12623 MLX5_FLOW_ACTION_DECAP), error))
12625 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
12627 case RTE_FLOW_ACTION_TYPE_SET_TTL:
12628 if (flow_dv_convert_action_modify_ttl
12629 (mhdr_res, actions, items, &flow_attr,
12630 dev_flow, !!(action_flags &
12631 MLX5_FLOW_ACTION_DECAP), error))
12633 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
12635 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
12636 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
12637 if (flow_dv_convert_action_modify_tcp_seq
12638 (mhdr_res, actions, error))
12640 action_flags |= actions->type ==
12641 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
12642 MLX5_FLOW_ACTION_INC_TCP_SEQ :
12643 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
12646 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
12647 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
12648 if (flow_dv_convert_action_modify_tcp_ack
12649 (mhdr_res, actions, error))
12651 action_flags |= actions->type ==
12652 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
12653 MLX5_FLOW_ACTION_INC_TCP_ACK :
12654 MLX5_FLOW_ACTION_DEC_TCP_ACK;
12656 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
12657 if (flow_dv_convert_action_set_reg
12658 (mhdr_res, actions, error))
12660 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12662 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
12663 if (flow_dv_convert_action_copy_mreg
12664 (dev, mhdr_res, actions, error))
12666 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12668 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
12669 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
12670 dev_flow->handle->fate_action =
12671 MLX5_FLOW_FATE_DEFAULT_MISS;
12673 case RTE_FLOW_ACTION_TYPE_METER:
12675 return rte_flow_error_set(error, rte_errno,
12676 RTE_FLOW_ERROR_TYPE_ACTION,
12677 NULL, "Failed to get meter in flow.");
12678 /* Set the meter action. */
12679 dev_flow->dv.actions[actions_n++] =
12680 wks->fm->meter_action;
12681 action_flags |= MLX5_FLOW_ACTION_METER;
12683 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
12684 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
12687 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
12689 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
12690 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
12693 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
12695 case RTE_FLOW_ACTION_TYPE_SAMPLE:
12696 sample_act_pos = actions_n;
12697 sample = (const struct rte_flow_action_sample *)
12700 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
12701 /* put encap action into group if work with port id */
12702 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
12703 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
12704 sample_act->action_flags |=
12705 MLX5_FLOW_ACTION_ENCAP;
12707 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
12708 if (flow_dv_convert_action_modify_field
12709 (dev, mhdr_res, actions, attr, error))
12711 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
12713 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
12714 owner_idx = (uint32_t)(uintptr_t)action->conf;
12715 ct = flow_aso_ct_get_by_idx(dev, owner_idx);
12717 return rte_flow_error_set(error, EINVAL,
12718 RTE_FLOW_ERROR_TYPE_ACTION,
12720 "Failed to get CT object.");
12721 if (mlx5_aso_ct_available(priv->sh, ct))
12722 return rte_flow_error_set(error, rte_errno,
12723 RTE_FLOW_ERROR_TYPE_ACTION,
12725 "CT is unavailable.");
12726 if (ct->is_original)
12727 dev_flow->dv.actions[actions_n] =
12728 ct->dr_action_orig;
12730 dev_flow->dv.actions[actions_n] =
12731 ct->dr_action_rply;
12732 flow->indirect_type = MLX5_INDIRECT_ACTION_TYPE_CT;
12733 flow->ct = owner_idx;
12734 __atomic_fetch_add(&ct->refcnt, 1, __ATOMIC_RELAXED);
12736 action_flags |= MLX5_FLOW_ACTION_CT;
12738 case RTE_FLOW_ACTION_TYPE_END:
12739 actions_end = true;
12740 if (mhdr_res->actions_num) {
12741 /* create modify action if needed. */
12742 if (flow_dv_modify_hdr_resource_register
12743 (dev, mhdr_res, dev_flow, error))
12745 dev_flow->dv.actions[modify_action_position] =
12746 handle->dvh.modify_hdr->action;
12749 * Handle AGE and COUNT action by single HW counter
12750 * when they are not shared.
12752 if (action_flags & MLX5_FLOW_ACTION_AGE) {
12753 if ((non_shared_age &&
12754 count && !count->shared) ||
12755 !(priv->sh->flow_hit_aso_en &&
12756 (attr->group || attr->transfer))) {
12757 /* Creates age by counters. */
12758 cnt_act = flow_dv_prepare_counter
12765 dev_flow->dv.actions[age_act_pos] =
12769 if (!flow->age && non_shared_age) {
12770 flow->age = flow_dv_aso_age_alloc
12774 flow_dv_aso_age_params_init
12776 non_shared_age->context ?
12777 non_shared_age->context :
12778 (void *)(uintptr_t)
12779 (dev_flow->flow_idx),
12780 non_shared_age->timeout);
12782 age_act = flow_aso_age_get_by_idx(dev,
12784 dev_flow->dv.actions[age_act_pos] =
12785 age_act->dr_action;
12787 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
12789 * Create one count action, to be used
12790 * by all sub-flows.
12792 cnt_act = flow_dv_prepare_counter(dev, dev_flow,
12797 dev_flow->dv.actions[actions_n++] =
12803 if (mhdr_res->actions_num &&
12804 modify_action_position == UINT32_MAX)
12805 modify_action_position = actions_n++;
12807 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
12808 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
12809 int item_type = items->type;
12811 if (!mlx5_flow_os_item_supported(item_type))
12812 return rte_flow_error_set(error, ENOTSUP,
12813 RTE_FLOW_ERROR_TYPE_ITEM,
12814 NULL, "item not supported");
12815 switch (item_type) {
12816 case RTE_FLOW_ITEM_TYPE_PORT_ID:
12817 flow_dv_translate_item_port_id
12818 (dev, match_mask, match_value, items, attr);
12819 last_item = MLX5_FLOW_ITEM_PORT_ID;
12821 case RTE_FLOW_ITEM_TYPE_ETH:
12822 flow_dv_translate_item_eth(match_mask, match_value,
12824 dev_flow->dv.group);
12825 matcher.priority = action_flags &
12826 MLX5_FLOW_ACTION_DEFAULT_MISS &&
12827 !dev_flow->external ?
12828 MLX5_PRIORITY_MAP_L3 :
12829 MLX5_PRIORITY_MAP_L2;
12830 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
12831 MLX5_FLOW_LAYER_OUTER_L2;
12833 case RTE_FLOW_ITEM_TYPE_VLAN:
12834 flow_dv_translate_item_vlan(dev_flow,
12835 match_mask, match_value,
12837 dev_flow->dv.group);
12838 matcher.priority = MLX5_PRIORITY_MAP_L2;
12839 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
12840 MLX5_FLOW_LAYER_INNER_VLAN) :
12841 (MLX5_FLOW_LAYER_OUTER_L2 |
12842 MLX5_FLOW_LAYER_OUTER_VLAN);
12844 case RTE_FLOW_ITEM_TYPE_IPV4:
12845 mlx5_flow_tunnel_ip_check(items, next_protocol,
12846 &item_flags, &tunnel);
12847 flow_dv_translate_item_ipv4(match_mask, match_value,
12849 dev_flow->dv.group);
12850 matcher.priority = MLX5_PRIORITY_MAP_L3;
12851 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
12852 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
12853 if (items->mask != NULL &&
12854 ((const struct rte_flow_item_ipv4 *)
12855 items->mask)->hdr.next_proto_id) {
12857 ((const struct rte_flow_item_ipv4 *)
12858 (items->spec))->hdr.next_proto_id;
12860 ((const struct rte_flow_item_ipv4 *)
12861 (items->mask))->hdr.next_proto_id;
12863 /* Reset for inner layer. */
12864 next_protocol = 0xff;
12867 case RTE_FLOW_ITEM_TYPE_IPV6:
12868 mlx5_flow_tunnel_ip_check(items, next_protocol,
12869 &item_flags, &tunnel);
12870 flow_dv_translate_item_ipv6(match_mask, match_value,
12872 dev_flow->dv.group);
12873 matcher.priority = MLX5_PRIORITY_MAP_L3;
12874 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
12875 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
12876 if (items->mask != NULL &&
12877 ((const struct rte_flow_item_ipv6 *)
12878 items->mask)->hdr.proto) {
12880 ((const struct rte_flow_item_ipv6 *)
12881 items->spec)->hdr.proto;
12883 ((const struct rte_flow_item_ipv6 *)
12884 items->mask)->hdr.proto;
12886 /* Reset for inner layer. */
12887 next_protocol = 0xff;
12890 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
12891 flow_dv_translate_item_ipv6_frag_ext(match_mask,
12894 last_item = tunnel ?
12895 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
12896 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
12897 if (items->mask != NULL &&
12898 ((const struct rte_flow_item_ipv6_frag_ext *)
12899 items->mask)->hdr.next_header) {
12901 ((const struct rte_flow_item_ipv6_frag_ext *)
12902 items->spec)->hdr.next_header;
12904 ((const struct rte_flow_item_ipv6_frag_ext *)
12905 items->mask)->hdr.next_header;
12907 /* Reset for inner layer. */
12908 next_protocol = 0xff;
12911 case RTE_FLOW_ITEM_TYPE_TCP:
12912 flow_dv_translate_item_tcp(match_mask, match_value,
12914 matcher.priority = MLX5_PRIORITY_MAP_L4;
12915 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
12916 MLX5_FLOW_LAYER_OUTER_L4_TCP;
12918 case RTE_FLOW_ITEM_TYPE_UDP:
12919 flow_dv_translate_item_udp(match_mask, match_value,
12921 matcher.priority = MLX5_PRIORITY_MAP_L4;
12922 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
12923 MLX5_FLOW_LAYER_OUTER_L4_UDP;
12925 case RTE_FLOW_ITEM_TYPE_GRE:
12926 flow_dv_translate_item_gre(match_mask, match_value,
12928 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12929 last_item = MLX5_FLOW_LAYER_GRE;
12931 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
12932 flow_dv_translate_item_gre_key(match_mask,
12933 match_value, items);
12934 last_item = MLX5_FLOW_LAYER_GRE_KEY;
12936 case RTE_FLOW_ITEM_TYPE_NVGRE:
12937 flow_dv_translate_item_nvgre(match_mask, match_value,
12939 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12940 last_item = MLX5_FLOW_LAYER_GRE;
12942 case RTE_FLOW_ITEM_TYPE_VXLAN:
12943 flow_dv_translate_item_vxlan(dev, attr,
12944 match_mask, match_value,
12946 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12947 last_item = MLX5_FLOW_LAYER_VXLAN;
12949 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
12950 flow_dv_translate_item_vxlan_gpe(match_mask,
12951 match_value, items,
12953 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12954 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
12956 case RTE_FLOW_ITEM_TYPE_GENEVE:
12957 flow_dv_translate_item_geneve(match_mask, match_value,
12959 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12960 last_item = MLX5_FLOW_LAYER_GENEVE;
12962 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
12963 ret = flow_dv_translate_item_geneve_opt(dev, match_mask,
12967 return rte_flow_error_set(error, -ret,
12968 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
12969 "cannot create GENEVE TLV option");
12970 flow->geneve_tlv_option = 1;
12971 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
12973 case RTE_FLOW_ITEM_TYPE_MPLS:
12974 flow_dv_translate_item_mpls(match_mask, match_value,
12975 items, last_item, tunnel);
12976 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12977 last_item = MLX5_FLOW_LAYER_MPLS;
12979 case RTE_FLOW_ITEM_TYPE_MARK:
12980 flow_dv_translate_item_mark(dev, match_mask,
12981 match_value, items);
12982 last_item = MLX5_FLOW_ITEM_MARK;
12984 case RTE_FLOW_ITEM_TYPE_META:
12985 flow_dv_translate_item_meta(dev, match_mask,
12986 match_value, attr, items);
12987 last_item = MLX5_FLOW_ITEM_METADATA;
12989 case RTE_FLOW_ITEM_TYPE_ICMP:
12990 flow_dv_translate_item_icmp(match_mask, match_value,
12992 last_item = MLX5_FLOW_LAYER_ICMP;
12994 case RTE_FLOW_ITEM_TYPE_ICMP6:
12995 flow_dv_translate_item_icmp6(match_mask, match_value,
12997 last_item = MLX5_FLOW_LAYER_ICMP6;
12999 case RTE_FLOW_ITEM_TYPE_TAG:
13000 flow_dv_translate_item_tag(dev, match_mask,
13001 match_value, items);
13002 last_item = MLX5_FLOW_ITEM_TAG;
13004 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
13005 flow_dv_translate_mlx5_item_tag(dev, match_mask,
13006 match_value, items);
13007 last_item = MLX5_FLOW_ITEM_TAG;
13009 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
13010 flow_dv_translate_item_tx_queue(dev, match_mask,
13013 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
13015 case RTE_FLOW_ITEM_TYPE_GTP:
13016 flow_dv_translate_item_gtp(match_mask, match_value,
13018 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
13019 last_item = MLX5_FLOW_LAYER_GTP;
13021 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
13022 ret = flow_dv_translate_item_gtp_psc(match_mask,
13026 return rte_flow_error_set(error, -ret,
13027 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
13028 "cannot create GTP PSC item");
13029 last_item = MLX5_FLOW_LAYER_GTP_PSC;
13031 case RTE_FLOW_ITEM_TYPE_ECPRI:
13032 if (!mlx5_flex_parser_ecpri_exist(dev)) {
13033 /* Create it only the first time to be used. */
13034 ret = mlx5_flex_parser_ecpri_alloc(dev);
13036 return rte_flow_error_set
13038 RTE_FLOW_ERROR_TYPE_ITEM,
13040 "cannot create eCPRI parser");
13042 flow_dv_translate_item_ecpri(dev, match_mask,
13043 match_value, items);
13044 /* No other protocol should follow eCPRI layer. */
13045 last_item = MLX5_FLOW_LAYER_ECPRI;
13047 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
13048 flow_dv_translate_item_integrity(match_mask,
13052 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
13053 flow_dv_translate_item_aso_ct(dev, match_mask,
13054 match_value, items);
13059 item_flags |= last_item;
13062 * When E-Switch mode is enabled, we have two cases where we need to
13063 * set the source port manually.
13064 * The first one, is in case of Nic steering rule, and the second is
13065 * E-Switch rule where no port_id item was found. In both cases
13066 * the source port is set according the current port in use.
13068 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
13069 (priv->representor || priv->master)) {
13070 if (flow_dv_translate_item_port_id(dev, match_mask,
13071 match_value, NULL, attr))
13074 #ifdef RTE_LIBRTE_MLX5_DEBUG
13075 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
13076 dev_flow->dv.value.buf));
13079 * Layers may be already initialized from prefix flow if this dev_flow
13080 * is the suffix flow.
13082 handle->layers |= item_flags;
13083 if (action_flags & MLX5_FLOW_ACTION_RSS)
13084 flow_dv_hashfields_set(dev_flow, rss_desc);
13085 /* If has RSS action in the sample action, the Sample/Mirror resource
13086 * should be registered after the hash filed be update.
13088 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
13089 ret = flow_dv_translate_action_sample(dev,
13098 ret = flow_dv_create_action_sample(dev,
13107 return rte_flow_error_set
13109 RTE_FLOW_ERROR_TYPE_ACTION,
13111 "cannot create sample action");
13112 if (num_of_dest > 1) {
13113 dev_flow->dv.actions[sample_act_pos] =
13114 dev_flow->dv.dest_array_res->action;
13116 dev_flow->dv.actions[sample_act_pos] =
13117 dev_flow->dv.sample_res->verbs_action;
13121 * For multiple destination (sample action with ratio=1), the encap
13122 * action and port id action will be combined into group action.
13123 * So need remove the original these actions in the flow and only
13124 * use the sample action instead of.
13126 if (num_of_dest > 1 &&
13127 (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
13129 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
13131 for (i = 0; i < actions_n; i++) {
13132 if ((sample_act->dr_encap_action &&
13133 sample_act->dr_encap_action ==
13134 dev_flow->dv.actions[i]) ||
13135 (sample_act->dr_port_id_action &&
13136 sample_act->dr_port_id_action ==
13137 dev_flow->dv.actions[i]) ||
13138 (sample_act->dr_jump_action &&
13139 sample_act->dr_jump_action ==
13140 dev_flow->dv.actions[i]))
13142 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
13144 memcpy((void *)dev_flow->dv.actions,
13145 (void *)temp_actions,
13146 tmp_actions_n * sizeof(void *));
13147 actions_n = tmp_actions_n;
13149 dev_flow->dv.actions_n = actions_n;
13150 dev_flow->act_flags = action_flags;
13151 if (wks->skip_matcher_reg)
13153 /* Register matcher. */
13154 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
13155 matcher.mask.size);
13156 matcher.priority = mlx5_get_matcher_priority(dev, attr,
13159 * When creating meter drop flow in drop table, using original
13160 * 5-tuple match, the matcher priority should be lower than
13163 if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
13164 dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
13165 matcher.priority <= MLX5_REG_BITS)
13166 matcher.priority += MLX5_REG_BITS;
13167 /* reserved field no needs to be set to 0 here. */
13168 tbl_key.is_fdb = attr->transfer;
13169 tbl_key.is_egress = attr->egress;
13170 tbl_key.level = dev_flow->dv.group;
13171 tbl_key.id = dev_flow->dv.table_id;
13172 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
13173 tunnel, attr->group, error))
13179 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13182 * @param[in, out] action
13183 * Shred RSS action holding hash RX queue objects.
13184 * @param[in] hash_fields
13185 * Defines combination of packet fields to participate in RX hash.
13186 * @param[in] tunnel
13188 * @param[in] hrxq_idx
13189 * Hash RX queue index to set.
13192 * 0 on success, otherwise negative errno value.
13195 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
13196 const uint64_t hash_fields,
13199 uint32_t *hrxqs = action->hrxq;
13201 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13202 case MLX5_RSS_HASH_IPV4:
13203 /* fall-through. */
13204 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13205 /* fall-through. */
13206 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13207 hrxqs[0] = hrxq_idx;
13209 case MLX5_RSS_HASH_IPV4_TCP:
13210 /* fall-through. */
13211 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13212 /* fall-through. */
13213 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13214 hrxqs[1] = hrxq_idx;
13216 case MLX5_RSS_HASH_IPV4_UDP:
13217 /* fall-through. */
13218 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13219 /* fall-through. */
13220 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13221 hrxqs[2] = hrxq_idx;
13223 case MLX5_RSS_HASH_IPV6:
13224 /* fall-through. */
13225 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13226 /* fall-through. */
13227 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13228 hrxqs[3] = hrxq_idx;
13230 case MLX5_RSS_HASH_IPV6_TCP:
13231 /* fall-through. */
13232 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13233 /* fall-through. */
13234 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13235 hrxqs[4] = hrxq_idx;
13237 case MLX5_RSS_HASH_IPV6_UDP:
13238 /* fall-through. */
13239 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13240 /* fall-through. */
13241 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13242 hrxqs[5] = hrxq_idx;
13244 case MLX5_RSS_HASH_NONE:
13245 hrxqs[6] = hrxq_idx;
13253 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13257 * Pointer to the Ethernet device structure.
13259 * Shared RSS action ID holding hash RX queue objects.
13260 * @param[in] hash_fields
13261 * Defines combination of packet fields to participate in RX hash.
13262 * @param[in] tunnel
13266 * Valid hash RX queue index, otherwise 0.
13269 __flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
13270 const uint64_t hash_fields)
13272 struct mlx5_priv *priv = dev->data->dev_private;
13273 struct mlx5_shared_action_rss *shared_rss =
13274 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
13275 const uint32_t *hrxqs = shared_rss->hrxq;
13277 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13278 case MLX5_RSS_HASH_IPV4:
13279 /* fall-through. */
13280 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13281 /* fall-through. */
13282 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13284 case MLX5_RSS_HASH_IPV4_TCP:
13285 /* fall-through. */
13286 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13287 /* fall-through. */
13288 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13290 case MLX5_RSS_HASH_IPV4_UDP:
13291 /* fall-through. */
13292 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13293 /* fall-through. */
13294 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13296 case MLX5_RSS_HASH_IPV6:
13297 /* fall-through. */
13298 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13299 /* fall-through. */
13300 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13302 case MLX5_RSS_HASH_IPV6_TCP:
13303 /* fall-through. */
13304 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13305 /* fall-through. */
13306 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13308 case MLX5_RSS_HASH_IPV6_UDP:
13309 /* fall-through. */
13310 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13311 /* fall-through. */
13312 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13314 case MLX5_RSS_HASH_NONE:
13323 * Apply the flow to the NIC, lock free,
13324 * (mutex should be acquired by caller).
13327 * Pointer to the Ethernet device structure.
13328 * @param[in, out] flow
13329 * Pointer to flow structure.
13330 * @param[out] error
13331 * Pointer to error structure.
13334 * 0 on success, a negative errno value otherwise and rte_errno is set.
13337 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
13338 struct rte_flow_error *error)
13340 struct mlx5_flow_dv_workspace *dv;
13341 struct mlx5_flow_handle *dh;
13342 struct mlx5_flow_handle_dv *dv_h;
13343 struct mlx5_flow *dev_flow;
13344 struct mlx5_priv *priv = dev->data->dev_private;
13345 uint32_t handle_idx;
13349 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13350 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
13354 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
13355 dev_flow = &wks->flows[idx];
13356 dv = &dev_flow->dv;
13357 dh = dev_flow->handle;
13360 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
13361 if (dv->transfer) {
13362 MLX5_ASSERT(priv->sh->dr_drop_action);
13363 dv->actions[n++] = priv->sh->dr_drop_action;
13365 #ifdef HAVE_MLX5DV_DR
13366 /* DR supports drop action placeholder. */
13367 MLX5_ASSERT(priv->sh->dr_drop_action);
13368 dv->actions[n++] = priv->sh->dr_drop_action;
13370 /* For DV we use the explicit drop queue. */
13371 MLX5_ASSERT(priv->drop_queue.hrxq);
13373 priv->drop_queue.hrxq->action;
13376 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
13377 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
13378 struct mlx5_hrxq *hrxq;
13381 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
13386 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13387 "cannot get hash queue");
13390 dh->rix_hrxq = hrxq_idx;
13391 dv->actions[n++] = hrxq->action;
13392 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13393 struct mlx5_hrxq *hrxq = NULL;
13396 hrxq_idx = __flow_dv_action_rss_hrxq_lookup(dev,
13397 rss_desc->shared_rss,
13398 dev_flow->hash_fields);
13400 hrxq = mlx5_ipool_get
13401 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
13406 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13407 "cannot get hash queue");
13410 dh->rix_srss = rss_desc->shared_rss;
13411 dv->actions[n++] = hrxq->action;
13412 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
13413 if (!priv->sh->default_miss_action) {
13416 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13417 "default miss action not be created.");
13420 dv->actions[n++] = priv->sh->default_miss_action;
13422 misc_mask = flow_dv_matcher_enable(dv->value.buf);
13423 __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
13424 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
13425 (void *)&dv->value, n,
13426 dv->actions, &dh->drv_flow);
13430 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13432 (!priv->config.allow_duplicate_pattern &&
13434 "duplicating pattern is not allowed" :
13435 "hardware refuses to create flow");
13438 if (priv->vmwa_context &&
13439 dh->vf_vlan.tag && !dh->vf_vlan.created) {
13441 * The rule contains the VLAN pattern.
13442 * For VF we are going to create VLAN
13443 * interface to make hypervisor set correct
13444 * e-Switch vport context.
13446 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
13451 err = rte_errno; /* Save rte_errno before cleanup. */
13452 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
13453 handle_idx, dh, next) {
13454 /* hrxq is union, don't clear it if the flag is not set. */
13455 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
13456 mlx5_hrxq_release(dev, dh->rix_hrxq);
13458 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13461 if (dh->vf_vlan.tag && dh->vf_vlan.created)
13462 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
13464 rte_errno = err; /* Restore rte_errno. */
13469 flow_dv_matcher_remove_cb(struct mlx5_cache_list *list __rte_unused,
13470 struct mlx5_cache_entry *entry)
13472 struct mlx5_flow_dv_matcher *cache = container_of(entry, typeof(*cache),
13475 claim_zero(mlx5_flow_os_destroy_flow_matcher(cache->matcher_object));
13480 * Release the flow matcher.
13483 * Pointer to Ethernet device.
13485 * Index to port ID action resource.
13488 * 1 while a reference on it exists, 0 when freed.
13491 flow_dv_matcher_release(struct rte_eth_dev *dev,
13492 struct mlx5_flow_handle *handle)
13494 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
13495 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
13496 typeof(*tbl), tbl);
13499 MLX5_ASSERT(matcher->matcher_object);
13500 ret = mlx5_cache_unregister(&tbl->matchers, &matcher->entry);
13501 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
13506 * Release encap_decap resource.
13509 * Pointer to the hash list.
13511 * Pointer to exist resource entry object.
13514 flow_dv_encap_decap_remove_cb(struct mlx5_hlist *list,
13515 struct mlx5_hlist_entry *entry)
13517 struct mlx5_dev_ctx_shared *sh = list->ctx;
13518 struct mlx5_flow_dv_encap_decap_resource *res =
13519 container_of(entry, typeof(*res), entry);
13521 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13522 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
13526 * Release an encap/decap resource.
13529 * Pointer to Ethernet device.
13530 * @param encap_decap_idx
13531 * Index of encap decap resource.
13534 * 1 while a reference on it exists, 0 when freed.
13537 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
13538 uint32_t encap_decap_idx)
13540 struct mlx5_priv *priv = dev->data->dev_private;
13541 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
13543 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
13545 if (!cache_resource)
13547 MLX5_ASSERT(cache_resource->action);
13548 return mlx5_hlist_unregister(priv->sh->encaps_decaps,
13549 &cache_resource->entry);
13553 * Release an jump to table action resource.
13556 * Pointer to Ethernet device.
13558 * Index to the jump action resource.
13561 * 1 while a reference on it exists, 0 when freed.
13564 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
13567 struct mlx5_priv *priv = dev->data->dev_private;
13568 struct mlx5_flow_tbl_data_entry *tbl_data;
13570 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
13574 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
13578 flow_dv_modify_remove_cb(struct mlx5_hlist *list __rte_unused,
13579 struct mlx5_hlist_entry *entry)
13581 struct mlx5_flow_dv_modify_hdr_resource *res =
13582 container_of(entry, typeof(*res), entry);
13584 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13589 * Release a modify-header resource.
13592 * Pointer to Ethernet device.
13594 * Pointer to mlx5_flow_handle.
13597 * 1 while a reference on it exists, 0 when freed.
13600 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
13601 struct mlx5_flow_handle *handle)
13603 struct mlx5_priv *priv = dev->data->dev_private;
13604 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
13606 MLX5_ASSERT(entry->action);
13607 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
13611 flow_dv_port_id_remove_cb(struct mlx5_cache_list *list,
13612 struct mlx5_cache_entry *entry)
13614 struct mlx5_dev_ctx_shared *sh = list->ctx;
13615 struct mlx5_flow_dv_port_id_action_resource *cache =
13616 container_of(entry, typeof(*cache), entry);
13618 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
13619 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], cache->idx);
13623 * Release port ID action resource.
13626 * Pointer to Ethernet device.
13628 * Pointer to mlx5_flow_handle.
13631 * 1 while a reference on it exists, 0 when freed.
13634 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
13637 struct mlx5_priv *priv = dev->data->dev_private;
13638 struct mlx5_flow_dv_port_id_action_resource *cache;
13640 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
13643 MLX5_ASSERT(cache->action);
13644 return mlx5_cache_unregister(&priv->sh->port_id_action_list,
13649 * Release shared RSS action resource.
13652 * Pointer to Ethernet device.
13654 * Shared RSS action index.
13657 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
13659 struct mlx5_priv *priv = dev->data->dev_private;
13660 struct mlx5_shared_action_rss *shared_rss;
13662 shared_rss = mlx5_ipool_get
13663 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
13664 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
13668 flow_dv_push_vlan_remove_cb(struct mlx5_cache_list *list,
13669 struct mlx5_cache_entry *entry)
13671 struct mlx5_dev_ctx_shared *sh = list->ctx;
13672 struct mlx5_flow_dv_push_vlan_action_resource *cache =
13673 container_of(entry, typeof(*cache), entry);
13675 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
13676 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], cache->idx);
13680 * Release push vlan action resource.
13683 * Pointer to Ethernet device.
13685 * Pointer to mlx5_flow_handle.
13688 * 1 while a reference on it exists, 0 when freed.
13691 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
13692 struct mlx5_flow_handle *handle)
13694 struct mlx5_priv *priv = dev->data->dev_private;
13695 struct mlx5_flow_dv_push_vlan_action_resource *cache;
13696 uint32_t idx = handle->dvh.rix_push_vlan;
13698 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
13701 MLX5_ASSERT(cache->action);
13702 return mlx5_cache_unregister(&priv->sh->push_vlan_action_list,
13707 * Release the fate resource.
13710 * Pointer to Ethernet device.
13712 * Pointer to mlx5_flow_handle.
13715 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
13716 struct mlx5_flow_handle *handle)
13718 if (!handle->rix_fate)
13720 switch (handle->fate_action) {
13721 case MLX5_FLOW_FATE_QUEUE:
13722 if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
13723 mlx5_hrxq_release(dev, handle->rix_hrxq);
13725 case MLX5_FLOW_FATE_JUMP:
13726 flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
13728 case MLX5_FLOW_FATE_PORT_ID:
13729 flow_dv_port_id_action_resource_release(dev,
13730 handle->rix_port_id_action);
13733 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
13736 handle->rix_fate = 0;
13740 flow_dv_sample_remove_cb(struct mlx5_cache_list *list __rte_unused,
13741 struct mlx5_cache_entry *entry)
13743 struct mlx5_flow_dv_sample_resource *cache_resource =
13744 container_of(entry, typeof(*cache_resource), entry);
13745 struct rte_eth_dev *dev = cache_resource->dev;
13746 struct mlx5_priv *priv = dev->data->dev_private;
13748 if (cache_resource->verbs_action)
13749 claim_zero(mlx5_flow_os_destroy_flow_action
13750 (cache_resource->verbs_action));
13751 if (cache_resource->normal_path_tbl)
13752 flow_dv_tbl_resource_release(MLX5_SH(dev),
13753 cache_resource->normal_path_tbl);
13754 flow_dv_sample_sub_actions_release(dev,
13755 &cache_resource->sample_idx);
13756 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
13757 cache_resource->idx);
13758 DRV_LOG(DEBUG, "sample resource %p: removed",
13759 (void *)cache_resource);
13763 * Release an sample resource.
13766 * Pointer to Ethernet device.
13768 * Pointer to mlx5_flow_handle.
13771 * 1 while a reference on it exists, 0 when freed.
13774 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
13775 struct mlx5_flow_handle *handle)
13777 struct mlx5_priv *priv = dev->data->dev_private;
13778 struct mlx5_flow_dv_sample_resource *cache_resource;
13780 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
13781 handle->dvh.rix_sample);
13782 if (!cache_resource)
13784 MLX5_ASSERT(cache_resource->verbs_action);
13785 return mlx5_cache_unregister(&priv->sh->sample_action_list,
13786 &cache_resource->entry);
13790 flow_dv_dest_array_remove_cb(struct mlx5_cache_list *list __rte_unused,
13791 struct mlx5_cache_entry *entry)
13793 struct mlx5_flow_dv_dest_array_resource *cache_resource =
13794 container_of(entry, typeof(*cache_resource), entry);
13795 struct rte_eth_dev *dev = cache_resource->dev;
13796 struct mlx5_priv *priv = dev->data->dev_private;
13799 MLX5_ASSERT(cache_resource->action);
13800 if (cache_resource->action)
13801 claim_zero(mlx5_flow_os_destroy_flow_action
13802 (cache_resource->action));
13803 for (; i < cache_resource->num_of_dest; i++)
13804 flow_dv_sample_sub_actions_release(dev,
13805 &cache_resource->sample_idx[i]);
13806 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
13807 cache_resource->idx);
13808 DRV_LOG(DEBUG, "destination array resource %p: removed",
13809 (void *)cache_resource);
13813 * Release an destination array resource.
13816 * Pointer to Ethernet device.
13818 * Pointer to mlx5_flow_handle.
13821 * 1 while a reference on it exists, 0 when freed.
13824 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
13825 struct mlx5_flow_handle *handle)
13827 struct mlx5_priv *priv = dev->data->dev_private;
13828 struct mlx5_flow_dv_dest_array_resource *cache;
13830 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
13831 handle->dvh.rix_dest_array);
13834 MLX5_ASSERT(cache->action);
13835 return mlx5_cache_unregister(&priv->sh->dest_array_list,
13840 flow_dv_geneve_tlv_option_resource_release(struct rte_eth_dev *dev)
13842 struct mlx5_priv *priv = dev->data->dev_private;
13843 struct mlx5_dev_ctx_shared *sh = priv->sh;
13844 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
13845 sh->geneve_tlv_option_resource;
13846 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
13847 if (geneve_opt_resource) {
13848 if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
13849 __ATOMIC_RELAXED))) {
13850 claim_zero(mlx5_devx_cmd_destroy
13851 (geneve_opt_resource->obj));
13852 mlx5_free(sh->geneve_tlv_option_resource);
13853 sh->geneve_tlv_option_resource = NULL;
13856 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
13860 * Remove the flow from the NIC but keeps it in memory.
13861 * Lock free, (mutex should be acquired by caller).
13864 * Pointer to Ethernet device.
13865 * @param[in, out] flow
13866 * Pointer to flow structure.
13869 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
13871 struct mlx5_flow_handle *dh;
13872 uint32_t handle_idx;
13873 struct mlx5_priv *priv = dev->data->dev_private;
13877 handle_idx = flow->dev_handles;
13878 while (handle_idx) {
13879 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
13883 if (dh->drv_flow) {
13884 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
13885 dh->drv_flow = NULL;
13887 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
13888 flow_dv_fate_resource_release(dev, dh);
13889 if (dh->vf_vlan.tag && dh->vf_vlan.created)
13890 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
13891 handle_idx = dh->next.next;
13896 * Remove the flow from the NIC and the memory.
13897 * Lock free, (mutex should be acquired by caller).
13900 * Pointer to the Ethernet device structure.
13901 * @param[in, out] flow
13902 * Pointer to flow structure.
13905 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
13907 struct mlx5_flow_handle *dev_handle;
13908 struct mlx5_priv *priv = dev->data->dev_private;
13909 struct mlx5_flow_meter_info *fm = NULL;
13914 flow_dv_remove(dev, flow);
13915 if (flow->counter) {
13916 flow_dv_counter_free(dev, flow->counter);
13920 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
13922 mlx5_flow_meter_detach(priv, fm);
13925 /* Keep the current age handling by default. */
13926 if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
13927 flow_dv_aso_ct_release(dev, flow->ct);
13928 else if (flow->age)
13929 flow_dv_aso_age_release(dev, flow->age);
13930 if (flow->geneve_tlv_option) {
13931 flow_dv_geneve_tlv_option_resource_release(dev);
13932 flow->geneve_tlv_option = 0;
13934 while (flow->dev_handles) {
13935 uint32_t tmp_idx = flow->dev_handles;
13937 dev_handle = mlx5_ipool_get(priv->sh->ipool
13938 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
13941 flow->dev_handles = dev_handle->next.next;
13942 if (dev_handle->dvh.matcher)
13943 flow_dv_matcher_release(dev, dev_handle);
13944 if (dev_handle->dvh.rix_sample)
13945 flow_dv_sample_resource_release(dev, dev_handle);
13946 if (dev_handle->dvh.rix_dest_array)
13947 flow_dv_dest_array_resource_release(dev, dev_handle);
13948 if (dev_handle->dvh.rix_encap_decap)
13949 flow_dv_encap_decap_resource_release(dev,
13950 dev_handle->dvh.rix_encap_decap);
13951 if (dev_handle->dvh.modify_hdr)
13952 flow_dv_modify_hdr_resource_release(dev, dev_handle);
13953 if (dev_handle->dvh.rix_push_vlan)
13954 flow_dv_push_vlan_action_resource_release(dev,
13956 if (dev_handle->dvh.rix_tag)
13957 flow_dv_tag_release(dev,
13958 dev_handle->dvh.rix_tag);
13959 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
13960 flow_dv_fate_resource_release(dev, dev_handle);
13962 srss = dev_handle->rix_srss;
13963 if (fm && dev_handle->is_meter_flow_id &&
13964 dev_handle->split_flow_id)
13965 mlx5_ipool_free(fm->flow_ipool,
13966 dev_handle->split_flow_id);
13967 else if (dev_handle->split_flow_id &&
13968 !dev_handle->is_meter_flow_id)
13969 mlx5_ipool_free(priv->sh->ipool
13970 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
13971 dev_handle->split_flow_id);
13972 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
13976 flow_dv_shared_rss_action_release(dev, srss);
13980 * Release array of hash RX queue objects.
13984 * Pointer to the Ethernet device structure.
13985 * @param[in, out] hrxqs
13986 * Array of hash RX queue objects.
13989 * Total number of references to hash RX queue objects in *hrxqs* array
13990 * after this operation.
13993 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
13994 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
13999 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
14000 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
14010 * Release all hash RX queue objects representing shared RSS action.
14013 * Pointer to the Ethernet device structure.
14014 * @param[in, out] action
14015 * Shared RSS action to remove hash RX queue objects from.
14018 * Total number of references to hash RX queue objects stored in *action*
14019 * after this operation.
14020 * Expected to be 0 if no external references held.
14023 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
14024 struct mlx5_shared_action_rss *shared_rss)
14026 return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
14030 * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
14033 * Only one hash value is available for one L3+L4 combination:
14035 * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
14036 * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
14037 * same slot in mlx5_rss_hash_fields.
14040 * Pointer to the shared action RSS conf.
14041 * @param[in, out] hash_field
14042 * hash_field variable needed to be adjusted.
14048 __flow_dv_action_rss_l34_hash_adjust(struct mlx5_shared_action_rss *rss,
14049 uint64_t *hash_field)
14051 uint64_t rss_types = rss->origin.types;
14053 switch (*hash_field & ~IBV_RX_HASH_INNER) {
14054 case MLX5_RSS_HASH_IPV4:
14055 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
14056 *hash_field &= ~MLX5_RSS_HASH_IPV4;
14057 if (rss_types & ETH_RSS_L3_DST_ONLY)
14058 *hash_field |= IBV_RX_HASH_DST_IPV4;
14059 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
14060 *hash_field |= IBV_RX_HASH_SRC_IPV4;
14062 *hash_field |= MLX5_RSS_HASH_IPV4;
14065 case MLX5_RSS_HASH_IPV6:
14066 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
14067 *hash_field &= ~MLX5_RSS_HASH_IPV6;
14068 if (rss_types & ETH_RSS_L3_DST_ONLY)
14069 *hash_field |= IBV_RX_HASH_DST_IPV6;
14070 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
14071 *hash_field |= IBV_RX_HASH_SRC_IPV6;
14073 *hash_field |= MLX5_RSS_HASH_IPV6;
14076 case MLX5_RSS_HASH_IPV4_UDP:
14077 /* fall-through. */
14078 case MLX5_RSS_HASH_IPV6_UDP:
14079 if (rss_types & ETH_RSS_UDP) {
14080 *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
14081 if (rss_types & ETH_RSS_L4_DST_ONLY)
14082 *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
14083 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
14084 *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
14086 *hash_field |= MLX5_UDP_IBV_RX_HASH;
14089 case MLX5_RSS_HASH_IPV4_TCP:
14090 /* fall-through. */
14091 case MLX5_RSS_HASH_IPV6_TCP:
14092 if (rss_types & ETH_RSS_TCP) {
14093 *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
14094 if (rss_types & ETH_RSS_L4_DST_ONLY)
14095 *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
14096 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
14097 *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
14099 *hash_field |= MLX5_TCP_IBV_RX_HASH;
14108 * Setup shared RSS action.
14109 * Prepare set of hash RX queue objects sufficient to handle all valid
14110 * hash_fields combinations (see enum ibv_rx_hash_fields).
14113 * Pointer to the Ethernet device structure.
14114 * @param[in] action_idx
14115 * Shared RSS action ipool index.
14116 * @param[in, out] action
14117 * Partially initialized shared RSS action.
14118 * @param[out] error
14119 * Perform verbose error reporting if not NULL. Initialized in case of
14123 * 0 on success, otherwise negative errno value.
14126 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
14127 uint32_t action_idx,
14128 struct mlx5_shared_action_rss *shared_rss,
14129 struct rte_flow_error *error)
14131 struct mlx5_flow_rss_desc rss_desc = { 0 };
14135 if (mlx5_ind_table_obj_setup(dev, shared_rss->ind_tbl)) {
14136 return rte_flow_error_set(error, rte_errno,
14137 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14138 "cannot setup indirection table");
14140 memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
14141 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
14142 rss_desc.const_q = shared_rss->origin.queue;
14143 rss_desc.queue_num = shared_rss->origin.queue_num;
14144 /* Set non-zero value to indicate a shared RSS. */
14145 rss_desc.shared_rss = action_idx;
14146 rss_desc.ind_tbl = shared_rss->ind_tbl;
14147 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
14149 uint64_t hash_fields = mlx5_rss_hash_fields[i];
14152 __flow_dv_action_rss_l34_hash_adjust(shared_rss, &hash_fields);
14153 if (shared_rss->origin.level > 1) {
14154 hash_fields |= IBV_RX_HASH_INNER;
14157 rss_desc.tunnel = tunnel;
14158 rss_desc.hash_fields = hash_fields;
14159 hrxq_idx = mlx5_hrxq_get(dev, &rss_desc);
14163 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14164 "cannot get hash queue");
14165 goto error_hrxq_new;
14167 err = __flow_dv_action_rss_hrxq_set
14168 (shared_rss, hash_fields, hrxq_idx);
14174 __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14175 if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
14176 shared_rss->ind_tbl = NULL;
14182 * Create shared RSS action.
14185 * Pointer to the Ethernet device structure.
14187 * Shared action configuration.
14189 * RSS action specification used to create shared action.
14190 * @param[out] error
14191 * Perform verbose error reporting if not NULL. Initialized in case of
14195 * A valid shared action ID in case of success, 0 otherwise and
14196 * rte_errno is set.
14199 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
14200 const struct rte_flow_indir_action_conf *conf,
14201 const struct rte_flow_action_rss *rss,
14202 struct rte_flow_error *error)
14204 struct mlx5_priv *priv = dev->data->dev_private;
14205 struct mlx5_shared_action_rss *shared_rss = NULL;
14206 void *queue = NULL;
14207 struct rte_flow_action_rss *origin;
14208 const uint8_t *rss_key;
14209 uint32_t queue_size = rss->queue_num * sizeof(uint16_t);
14212 RTE_SET_USED(conf);
14213 queue = mlx5_malloc(0, RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14215 shared_rss = mlx5_ipool_zmalloc
14216 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
14217 if (!shared_rss || !queue) {
14218 rte_flow_error_set(error, ENOMEM,
14219 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14220 "cannot allocate resource memory");
14221 goto error_rss_init;
14223 if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
14224 rte_flow_error_set(error, E2BIG,
14225 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14226 "rss action number out of range");
14227 goto error_rss_init;
14229 shared_rss->ind_tbl = mlx5_malloc(MLX5_MEM_ZERO,
14230 sizeof(*shared_rss->ind_tbl),
14232 if (!shared_rss->ind_tbl) {
14233 rte_flow_error_set(error, ENOMEM,
14234 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14235 "cannot allocate resource memory");
14236 goto error_rss_init;
14238 memcpy(queue, rss->queue, queue_size);
14239 shared_rss->ind_tbl->queues = queue;
14240 shared_rss->ind_tbl->queues_n = rss->queue_num;
14241 origin = &shared_rss->origin;
14242 origin->func = rss->func;
14243 origin->level = rss->level;
14244 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
14245 origin->types = !rss->types ? ETH_RSS_IP : rss->types;
14246 /* NULL RSS key indicates default RSS key. */
14247 rss_key = !rss->key ? rss_hash_default_key : rss->key;
14248 memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
14249 origin->key = &shared_rss->key[0];
14250 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
14251 origin->queue = queue;
14252 origin->queue_num = rss->queue_num;
14253 if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
14254 goto error_rss_init;
14255 rte_spinlock_init(&shared_rss->action_rss_sl);
14256 __atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14257 rte_spinlock_lock(&priv->shared_act_sl);
14258 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14259 &priv->rss_shared_actions, idx, shared_rss, next);
14260 rte_spinlock_unlock(&priv->shared_act_sl);
14264 if (shared_rss->ind_tbl)
14265 mlx5_free(shared_rss->ind_tbl);
14266 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14275 * Destroy the shared RSS action.
14276 * Release related hash RX queue objects.
14279 * Pointer to the Ethernet device structure.
14281 * The shared RSS action object ID to be removed.
14282 * @param[out] error
14283 * Perform verbose error reporting if not NULL. Initialized in case of
14287 * 0 on success, otherwise negative errno value.
14290 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
14291 struct rte_flow_error *error)
14293 struct mlx5_priv *priv = dev->data->dev_private;
14294 struct mlx5_shared_action_rss *shared_rss =
14295 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14296 uint32_t old_refcnt = 1;
14298 uint16_t *queue = NULL;
14301 return rte_flow_error_set(error, EINVAL,
14302 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14303 "invalid shared action");
14304 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14306 return rte_flow_error_set(error, EBUSY,
14307 RTE_FLOW_ERROR_TYPE_ACTION,
14309 "shared rss hrxq has references");
14310 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
14311 0, 0, __ATOMIC_ACQUIRE,
14313 return rte_flow_error_set(error, EBUSY,
14314 RTE_FLOW_ERROR_TYPE_ACTION,
14316 "shared rss has references");
14317 queue = shared_rss->ind_tbl->queues;
14318 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true);
14320 return rte_flow_error_set(error, EBUSY,
14321 RTE_FLOW_ERROR_TYPE_ACTION,
14323 "shared rss indirection table has"
14326 rte_spinlock_lock(&priv->shared_act_sl);
14327 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14328 &priv->rss_shared_actions, idx, shared_rss, next);
14329 rte_spinlock_unlock(&priv->shared_act_sl);
14330 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14336 * Create indirect action, lock free,
14337 * (mutex should be acquired by caller).
14338 * Dispatcher for action type specific call.
14341 * Pointer to the Ethernet device structure.
14343 * Shared action configuration.
14344 * @param[in] action
14345 * Action specification used to create indirect action.
14346 * @param[out] error
14347 * Perform verbose error reporting if not NULL. Initialized in case of
14351 * A valid shared action handle in case of success, NULL otherwise and
14352 * rte_errno is set.
14354 static struct rte_flow_action_handle *
14355 flow_dv_action_create(struct rte_eth_dev *dev,
14356 const struct rte_flow_indir_action_conf *conf,
14357 const struct rte_flow_action *action,
14358 struct rte_flow_error *err)
14360 struct mlx5_priv *priv = dev->data->dev_private;
14361 uint32_t age_idx = 0;
14365 switch (action->type) {
14366 case RTE_FLOW_ACTION_TYPE_RSS:
14367 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
14368 idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
14369 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14371 case RTE_FLOW_ACTION_TYPE_AGE:
14372 age_idx = flow_dv_aso_age_alloc(dev, err);
14377 idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
14378 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
14379 flow_dv_aso_age_params_init(dev, age_idx,
14380 ((const struct rte_flow_action_age *)
14381 action->conf)->context ?
14382 ((const struct rte_flow_action_age *)
14383 action->conf)->context :
14384 (void *)(uintptr_t)idx,
14385 ((const struct rte_flow_action_age *)
14386 action->conf)->timeout);
14389 case RTE_FLOW_ACTION_TYPE_COUNT:
14390 ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
14391 idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
14392 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14394 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
14395 ret = flow_dv_translate_create_conntrack(dev, action->conf,
14397 idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
14400 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
14401 NULL, "action type not supported");
14404 return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
14408 * Destroy the indirect action.
14409 * Release action related resources on the NIC and the memory.
14410 * Lock free, (mutex should be acquired by caller).
14411 * Dispatcher for action type specific call.
14414 * Pointer to the Ethernet device structure.
14415 * @param[in] handle
14416 * The indirect action object handle to be removed.
14417 * @param[out] error
14418 * Perform verbose error reporting if not NULL. Initialized in case of
14422 * 0 on success, otherwise negative errno value.
14425 flow_dv_action_destroy(struct rte_eth_dev *dev,
14426 struct rte_flow_action_handle *handle,
14427 struct rte_flow_error *error)
14429 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14430 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14431 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
14432 struct mlx5_flow_counter *cnt;
14433 uint32_t no_flow_refcnt = 1;
14437 case MLX5_INDIRECT_ACTION_TYPE_RSS:
14438 return __flow_dv_action_rss_release(dev, idx, error);
14439 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
14440 cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
14441 if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
14442 &no_flow_refcnt, 1, false,
14445 return rte_flow_error_set(error, EBUSY,
14446 RTE_FLOW_ERROR_TYPE_ACTION,
14448 "Indirect count action has references");
14449 flow_dv_counter_free(dev, idx);
14451 case MLX5_INDIRECT_ACTION_TYPE_AGE:
14452 ret = flow_dv_aso_age_release(dev, idx);
14455 * In this case, the last flow has a reference will
14456 * actually release the age action.
14458 DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
14459 " released with references %d.", idx, ret);
14461 case MLX5_INDIRECT_ACTION_TYPE_CT:
14462 ret = flow_dv_aso_ct_release(dev, idx);
14466 DRV_LOG(DEBUG, "Connection tracking object %u still "
14467 "has references %d.", idx, ret);
14470 return rte_flow_error_set(error, ENOTSUP,
14471 RTE_FLOW_ERROR_TYPE_ACTION,
14473 "action type not supported");
14478 * Updates in place shared RSS action configuration.
14481 * Pointer to the Ethernet device structure.
14483 * The shared RSS action object ID to be updated.
14484 * @param[in] action_conf
14485 * RSS action specification used to modify *shared_rss*.
14486 * @param[out] error
14487 * Perform verbose error reporting if not NULL. Initialized in case of
14491 * 0 on success, otherwise negative errno value.
14492 * @note: currently only support update of RSS queues.
14495 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
14496 const struct rte_flow_action_rss *action_conf,
14497 struct rte_flow_error *error)
14499 struct mlx5_priv *priv = dev->data->dev_private;
14500 struct mlx5_shared_action_rss *shared_rss =
14501 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14503 void *queue = NULL;
14504 uint16_t *queue_old = NULL;
14505 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
14508 return rte_flow_error_set(error, EINVAL,
14509 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14510 "invalid shared action to update");
14511 if (priv->obj_ops.ind_table_modify == NULL)
14512 return rte_flow_error_set(error, ENOTSUP,
14513 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14514 "cannot modify indirection table");
14515 queue = mlx5_malloc(MLX5_MEM_ZERO,
14516 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14519 return rte_flow_error_set(error, ENOMEM,
14520 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14522 "cannot allocate resource memory");
14523 memcpy(queue, action_conf->queue, queue_size);
14524 MLX5_ASSERT(shared_rss->ind_tbl);
14525 rte_spinlock_lock(&shared_rss->action_rss_sl);
14526 queue_old = shared_rss->ind_tbl->queues;
14527 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
14528 queue, action_conf->queue_num, true);
14531 ret = rte_flow_error_set(error, rte_errno,
14532 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14533 "cannot update indirection table");
14535 mlx5_free(queue_old);
14536 shared_rss->origin.queue = queue;
14537 shared_rss->origin.queue_num = action_conf->queue_num;
14539 rte_spinlock_unlock(&shared_rss->action_rss_sl);
14544 * Updates in place conntrack context or direction.
14545 * Context update should be synchronized.
14548 * Pointer to the Ethernet device structure.
14550 * The conntrack object ID to be updated.
14551 * @param[in] update
14552 * Pointer to the structure of information to update.
14553 * @param[out] error
14554 * Perform verbose error reporting if not NULL. Initialized in case of
14558 * 0 on success, otherwise negative errno value.
14561 __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
14562 const struct rte_flow_modify_conntrack *update,
14563 struct rte_flow_error *error)
14565 struct mlx5_priv *priv = dev->data->dev_private;
14566 struct mlx5_aso_ct_action *ct;
14567 const struct rte_flow_action_conntrack *new_prf;
14569 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
14572 if (PORT_ID(priv) != owner)
14573 return rte_flow_error_set(error, EACCES,
14574 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14576 "CT object owned by another port");
14577 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
14578 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
14580 return rte_flow_error_set(error, ENOMEM,
14581 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14583 "CT object is inactive");
14584 new_prf = &update->new_ct;
14585 if (update->direction)
14586 ct->is_original = !!new_prf->is_original_dir;
14587 if (update->state) {
14588 /* Only validate the profile when it needs to be updated. */
14589 ret = mlx5_validate_action_ct(dev, new_prf, error);
14592 ret = mlx5_aso_ct_update_by_wqe(priv->sh, ct, new_prf);
14594 return rte_flow_error_set(error, EIO,
14595 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14597 "Failed to send CT context update WQE");
14598 /* Block until ready or a failure. */
14599 ret = mlx5_aso_ct_available(priv->sh, ct);
14601 rte_flow_error_set(error, rte_errno,
14602 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14604 "Timeout to get the CT update");
14610 * Updates in place shared action configuration, lock free,
14611 * (mutex should be acquired by caller).
14614 * Pointer to the Ethernet device structure.
14615 * @param[in] handle
14616 * The indirect action object handle to be updated.
14617 * @param[in] update
14618 * Action specification used to modify the action pointed by *handle*.
14619 * *update* could be of same type with the action pointed by the *handle*
14620 * handle argument, or some other structures like a wrapper, depending on
14621 * the indirect action type.
14622 * @param[out] error
14623 * Perform verbose error reporting if not NULL. Initialized in case of
14627 * 0 on success, otherwise negative errno value.
14630 flow_dv_action_update(struct rte_eth_dev *dev,
14631 struct rte_flow_action_handle *handle,
14632 const void *update,
14633 struct rte_flow_error *err)
14635 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14636 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14637 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
14638 const void *action_conf;
14641 case MLX5_INDIRECT_ACTION_TYPE_RSS:
14642 action_conf = ((const struct rte_flow_action *)update)->conf;
14643 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
14644 case MLX5_INDIRECT_ACTION_TYPE_CT:
14645 return __flow_dv_action_ct_update(dev, idx, update, err);
14647 return rte_flow_error_set(err, ENOTSUP,
14648 RTE_FLOW_ERROR_TYPE_ACTION,
14650 "action type update not supported");
14655 * Destroy the meter sub policy table rules.
14656 * Lock free, (mutex should be acquired by caller).
14659 * Pointer to Ethernet device.
14660 * @param[in] sub_policy
14661 * Pointer to meter sub policy table.
14664 __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
14665 struct mlx5_flow_meter_sub_policy *sub_policy)
14667 struct mlx5_priv *priv = dev->data->dev_private;
14668 struct mlx5_flow_tbl_data_entry *tbl;
14669 struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
14670 struct mlx5_flow_meter_info *next_fm;
14671 struct mlx5_sub_policy_color_rule *color_rule;
14675 for (i = 0; i < RTE_COLORS; i++) {
14677 if (i == RTE_COLOR_GREEN && policy &&
14678 policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
14679 next_fm = mlx5_flow_meter_find(priv,
14680 policy->act_cnt[i].next_mtr_id, NULL);
14681 TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
14683 claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
14684 tbl = container_of(color_rule->matcher->tbl,
14685 typeof(*tbl), tbl);
14686 mlx5_cache_unregister(&tbl->matchers,
14687 &color_rule->matcher->entry);
14688 TAILQ_REMOVE(&sub_policy->color_rules[i],
14689 color_rule, next_port);
14690 mlx5_free(color_rule);
14692 mlx5_flow_meter_detach(priv, next_fm);
14695 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
14696 if (sub_policy->rix_hrxq[i]) {
14697 if (policy && !policy->is_hierarchy)
14698 mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
14699 sub_policy->rix_hrxq[i] = 0;
14701 if (sub_policy->jump_tbl[i]) {
14702 flow_dv_tbl_resource_release(MLX5_SH(dev),
14703 sub_policy->jump_tbl[i]);
14704 sub_policy->jump_tbl[i] = NULL;
14707 if (sub_policy->tbl_rsc) {
14708 flow_dv_tbl_resource_release(MLX5_SH(dev),
14709 sub_policy->tbl_rsc);
14710 sub_policy->tbl_rsc = NULL;
14715 * Destroy policy rules, lock free,
14716 * (mutex should be acquired by caller).
14717 * Dispatcher for action type specific call.
14720 * Pointer to the Ethernet device structure.
14721 * @param[in] mtr_policy
14722 * Meter policy struct.
14725 flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
14726 struct mlx5_flow_meter_policy *mtr_policy)
14729 struct mlx5_flow_meter_sub_policy *sub_policy;
14730 uint16_t sub_policy_num;
14732 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
14733 sub_policy_num = (mtr_policy->sub_policy_num >>
14734 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
14735 MLX5_MTR_SUB_POLICY_NUM_MASK;
14736 for (j = 0; j < sub_policy_num; j++) {
14737 sub_policy = mtr_policy->sub_policys[i][j];
14739 __flow_dv_destroy_sub_policy_rules
14746 * Destroy policy action, lock free,
14747 * (mutex should be acquired by caller).
14748 * Dispatcher for action type specific call.
14751 * Pointer to the Ethernet device structure.
14752 * @param[in] mtr_policy
14753 * Meter policy struct.
14756 flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
14757 struct mlx5_flow_meter_policy *mtr_policy)
14759 struct rte_flow_action *rss_action;
14760 struct mlx5_flow_handle dev_handle;
14763 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
14764 if (mtr_policy->act_cnt[i].rix_mark) {
14765 flow_dv_tag_release(dev,
14766 mtr_policy->act_cnt[i].rix_mark);
14767 mtr_policy->act_cnt[i].rix_mark = 0;
14769 if (mtr_policy->act_cnt[i].modify_hdr) {
14770 dev_handle.dvh.modify_hdr =
14771 mtr_policy->act_cnt[i].modify_hdr;
14772 flow_dv_modify_hdr_resource_release(dev, &dev_handle);
14774 switch (mtr_policy->act_cnt[i].fate_action) {
14775 case MLX5_FLOW_FATE_SHARED_RSS:
14776 rss_action = mtr_policy->act_cnt[i].rss;
14777 mlx5_free(rss_action);
14779 case MLX5_FLOW_FATE_PORT_ID:
14780 if (mtr_policy->act_cnt[i].rix_port_id_action) {
14781 flow_dv_port_id_action_resource_release(dev,
14782 mtr_policy->act_cnt[i].rix_port_id_action);
14783 mtr_policy->act_cnt[i].rix_port_id_action = 0;
14786 case MLX5_FLOW_FATE_DROP:
14787 case MLX5_FLOW_FATE_JUMP:
14788 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
14789 mtr_policy->act_cnt[i].dr_jump_action[j] =
14793 /*Queue action do nothing*/
14797 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
14798 mtr_policy->dr_drop_action[j] = NULL;
14802 * Create policy action per domain, lock free,
14803 * (mutex should be acquired by caller).
14804 * Dispatcher for action type specific call.
14807 * Pointer to the Ethernet device structure.
14808 * @param[in] mtr_policy
14809 * Meter policy struct.
14810 * @param[in] action
14811 * Action specification used to create meter actions.
14812 * @param[out] error
14813 * Perform verbose error reporting if not NULL. Initialized in case of
14817 * 0 on success, otherwise negative errno value.
14820 __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
14821 struct mlx5_flow_meter_policy *mtr_policy,
14822 const struct rte_flow_action *actions[RTE_COLORS],
14823 enum mlx5_meter_domain domain,
14824 struct rte_mtr_error *error)
14826 struct mlx5_priv *priv = dev->data->dev_private;
14827 struct rte_flow_error flow_err;
14828 const struct rte_flow_action *act;
14829 uint64_t action_flags = 0;
14830 struct mlx5_flow_handle dh;
14831 struct mlx5_flow dev_flow;
14832 struct mlx5_flow_dv_port_id_action_resource port_id_action;
14834 uint8_t egress, transfer;
14835 struct mlx5_meter_policy_action_container *act_cnt = NULL;
14837 struct mlx5_flow_dv_modify_hdr_resource res;
14838 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
14839 sizeof(struct mlx5_modification_cmd) *
14840 (MLX5_MAX_MODIFY_NUM + 1)];
14842 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
14844 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
14845 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
14846 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
14847 memset(&dev_flow, 0, sizeof(struct mlx5_flow));
14848 memset(&port_id_action, 0,
14849 sizeof(struct mlx5_flow_dv_port_id_action_resource));
14850 memset(mhdr_res, 0, sizeof(*mhdr_res));
14851 mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
14853 MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
14854 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
14855 dev_flow.handle = &dh;
14856 dev_flow.dv.port_id_action = &port_id_action;
14857 dev_flow.external = true;
14858 for (i = 0; i < RTE_COLORS; i++) {
14859 if (i < MLX5_MTR_RTE_COLORS)
14860 act_cnt = &mtr_policy->act_cnt[i];
14861 for (act = actions[i];
14862 act && act->type != RTE_FLOW_ACTION_TYPE_END;
14864 switch (act->type) {
14865 case RTE_FLOW_ACTION_TYPE_MARK:
14867 uint32_t tag_be = mlx5_flow_mark_set
14868 (((const struct rte_flow_action_mark *)
14871 if (i >= MLX5_MTR_RTE_COLORS)
14872 return -rte_mtr_error_set(error,
14874 RTE_MTR_ERROR_TYPE_METER_POLICY,
14876 "cannot create policy "
14877 "mark action for this color");
14878 dev_flow.handle->mark = 1;
14879 if (flow_dv_tag_resource_register(dev, tag_be,
14880 &dev_flow, &flow_err))
14881 return -rte_mtr_error_set(error,
14883 RTE_MTR_ERROR_TYPE_METER_POLICY,
14885 "cannot setup policy mark action");
14886 MLX5_ASSERT(dev_flow.dv.tag_resource);
14887 act_cnt->rix_mark =
14888 dev_flow.handle->dvh.rix_tag;
14889 action_flags |= MLX5_FLOW_ACTION_MARK;
14892 case RTE_FLOW_ACTION_TYPE_SET_TAG:
14893 if (i >= MLX5_MTR_RTE_COLORS)
14894 return -rte_mtr_error_set(error,
14896 RTE_MTR_ERROR_TYPE_METER_POLICY,
14898 "cannot create policy "
14899 "set tag action for this color");
14900 if (flow_dv_convert_action_set_tag
14902 (const struct rte_flow_action_set_tag *)
14903 act->conf, &flow_err))
14904 return -rte_mtr_error_set(error,
14906 RTE_MTR_ERROR_TYPE_METER_POLICY,
14907 NULL, "cannot convert policy "
14909 if (!mhdr_res->actions_num)
14910 return -rte_mtr_error_set(error,
14912 RTE_MTR_ERROR_TYPE_METER_POLICY,
14913 NULL, "cannot find policy "
14915 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
14917 case RTE_FLOW_ACTION_TYPE_DROP:
14919 struct mlx5_flow_mtr_mng *mtrmng =
14921 struct mlx5_flow_tbl_data_entry *tbl_data;
14924 * Create the drop table with
14925 * METER DROP level.
14927 if (!mtrmng->drop_tbl[domain]) {
14928 mtrmng->drop_tbl[domain] =
14929 flow_dv_tbl_resource_get(dev,
14930 MLX5_FLOW_TABLE_LEVEL_METER,
14931 egress, transfer, false, NULL, 0,
14932 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
14933 if (!mtrmng->drop_tbl[domain])
14934 return -rte_mtr_error_set
14936 RTE_MTR_ERROR_TYPE_METER_POLICY,
14938 "Failed to create meter drop table");
14940 tbl_data = container_of
14941 (mtrmng->drop_tbl[domain],
14942 struct mlx5_flow_tbl_data_entry, tbl);
14943 if (i < MLX5_MTR_RTE_COLORS) {
14944 act_cnt->dr_jump_action[domain] =
14945 tbl_data->jump.action;
14946 act_cnt->fate_action =
14947 MLX5_FLOW_FATE_DROP;
14949 if (i == RTE_COLOR_RED)
14950 mtr_policy->dr_drop_action[domain] =
14951 tbl_data->jump.action;
14952 action_flags |= MLX5_FLOW_ACTION_DROP;
14955 case RTE_FLOW_ACTION_TYPE_QUEUE:
14957 if (i >= MLX5_MTR_RTE_COLORS)
14958 return -rte_mtr_error_set(error,
14960 RTE_MTR_ERROR_TYPE_METER_POLICY,
14961 NULL, "cannot create policy "
14962 "fate queue for this color");
14964 ((const struct rte_flow_action_queue *)
14965 (act->conf))->index;
14966 act_cnt->fate_action =
14967 MLX5_FLOW_FATE_QUEUE;
14968 dev_flow.handle->fate_action =
14969 MLX5_FLOW_FATE_QUEUE;
14970 mtr_policy->is_queue = 1;
14971 action_flags |= MLX5_FLOW_ACTION_QUEUE;
14974 case RTE_FLOW_ACTION_TYPE_RSS:
14978 if (i >= MLX5_MTR_RTE_COLORS)
14979 return -rte_mtr_error_set(error,
14981 RTE_MTR_ERROR_TYPE_METER_POLICY,
14983 "cannot create policy "
14984 "rss action for this color");
14986 * Save RSS conf into policy struct
14987 * for translate stage.
14989 rss_size = (int)rte_flow_conv
14990 (RTE_FLOW_CONV_OP_ACTION,
14991 NULL, 0, act, &flow_err);
14993 return -rte_mtr_error_set(error,
14995 RTE_MTR_ERROR_TYPE_METER_POLICY,
14996 NULL, "Get the wrong "
14997 "rss action struct size");
14998 act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
14999 rss_size, 0, SOCKET_ID_ANY);
15001 return -rte_mtr_error_set(error,
15003 RTE_MTR_ERROR_TYPE_METER_POLICY,
15005 "Fail to malloc rss action memory");
15006 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
15007 act_cnt->rss, rss_size,
15010 return -rte_mtr_error_set(error,
15012 RTE_MTR_ERROR_TYPE_METER_POLICY,
15013 NULL, "Fail to save "
15014 "rss action into policy struct");
15015 act_cnt->fate_action =
15016 MLX5_FLOW_FATE_SHARED_RSS;
15017 action_flags |= MLX5_FLOW_ACTION_RSS;
15020 case RTE_FLOW_ACTION_TYPE_PORT_ID:
15022 struct mlx5_flow_dv_port_id_action_resource
15024 uint32_t port_id = 0;
15026 if (i >= MLX5_MTR_RTE_COLORS)
15027 return -rte_mtr_error_set(error,
15029 RTE_MTR_ERROR_TYPE_METER_POLICY,
15030 NULL, "cannot create policy "
15031 "port action for this color");
15032 memset(&port_id_resource, 0,
15033 sizeof(port_id_resource));
15034 if (flow_dv_translate_action_port_id(dev, act,
15035 &port_id, &flow_err))
15036 return -rte_mtr_error_set(error,
15038 RTE_MTR_ERROR_TYPE_METER_POLICY,
15039 NULL, "cannot translate "
15040 "policy port action");
15041 port_id_resource.port_id = port_id;
15042 if (flow_dv_port_id_action_resource_register
15043 (dev, &port_id_resource,
15044 &dev_flow, &flow_err))
15045 return -rte_mtr_error_set(error,
15047 RTE_MTR_ERROR_TYPE_METER_POLICY,
15048 NULL, "cannot setup "
15049 "policy port action");
15050 act_cnt->rix_port_id_action =
15051 dev_flow.handle->rix_port_id_action;
15052 act_cnt->fate_action =
15053 MLX5_FLOW_FATE_PORT_ID;
15054 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15057 case RTE_FLOW_ACTION_TYPE_JUMP:
15059 uint32_t jump_group = 0;
15060 uint32_t table = 0;
15061 struct mlx5_flow_tbl_data_entry *tbl_data;
15062 struct flow_grp_info grp_info = {
15063 .external = !!dev_flow.external,
15064 .transfer = !!transfer,
15065 .fdb_def_rule = !!priv->fdb_def_rule,
15067 .skip_scale = dev_flow.skip_scale &
15068 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
15070 struct mlx5_flow_meter_sub_policy *sub_policy =
15071 mtr_policy->sub_policys[domain][0];
15073 if (i >= MLX5_MTR_RTE_COLORS)
15074 return -rte_mtr_error_set(error,
15076 RTE_MTR_ERROR_TYPE_METER_POLICY,
15078 "cannot create policy "
15079 "jump action for this color");
15081 ((const struct rte_flow_action_jump *)
15083 if (mlx5_flow_group_to_table(dev, NULL,
15086 &grp_info, &flow_err))
15087 return -rte_mtr_error_set(error,
15089 RTE_MTR_ERROR_TYPE_METER_POLICY,
15090 NULL, "cannot setup "
15091 "policy jump action");
15092 sub_policy->jump_tbl[i] =
15093 flow_dv_tbl_resource_get(dev,
15096 !!dev_flow.external,
15097 NULL, jump_group, 0,
15100 (!sub_policy->jump_tbl[i])
15101 return -rte_mtr_error_set(error,
15103 RTE_MTR_ERROR_TYPE_METER_POLICY,
15104 NULL, "cannot create jump action.");
15105 tbl_data = container_of
15106 (sub_policy->jump_tbl[i],
15107 struct mlx5_flow_tbl_data_entry, tbl);
15108 act_cnt->dr_jump_action[domain] =
15109 tbl_data->jump.action;
15110 act_cnt->fate_action =
15111 MLX5_FLOW_FATE_JUMP;
15112 action_flags |= MLX5_FLOW_ACTION_JUMP;
15115 case RTE_FLOW_ACTION_TYPE_METER:
15117 const struct rte_flow_action_meter *mtr;
15118 struct mlx5_flow_meter_info *next_fm;
15119 struct mlx5_flow_meter_policy *next_policy;
15120 struct rte_flow_action tag_action;
15121 struct mlx5_rte_flow_action_set_tag set_tag;
15122 uint32_t next_mtr_idx = 0;
15125 next_fm = mlx5_flow_meter_find(priv,
15129 return -rte_mtr_error_set(error, EINVAL,
15130 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15131 "Fail to find next meter.");
15132 if (next_fm->def_policy)
15133 return -rte_mtr_error_set(error, EINVAL,
15134 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
15135 "Hierarchy only supports termination meter.");
15136 next_policy = mlx5_flow_meter_policy_find(dev,
15137 next_fm->policy_id, NULL);
15138 MLX5_ASSERT(next_policy);
15139 if (next_fm->drop_cnt) {
15142 mlx5_flow_get_reg_id(dev,
15145 (struct rte_flow_error *)error);
15146 set_tag.offset = (priv->mtr_reg_share ?
15147 MLX5_MTR_COLOR_BITS : 0);
15148 set_tag.length = (priv->mtr_reg_share ?
15149 MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
15151 set_tag.data = next_mtr_idx;
15153 (enum rte_flow_action_type)
15154 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
15155 tag_action.conf = &set_tag;
15156 if (flow_dv_convert_action_set_reg
15157 (mhdr_res, &tag_action,
15158 (struct rte_flow_error *)error))
15161 MLX5_FLOW_ACTION_SET_TAG;
15163 act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
15164 act_cnt->next_mtr_id = next_fm->meter_id;
15165 act_cnt->next_sub_policy = NULL;
15166 mtr_policy->is_hierarchy = 1;
15167 mtr_policy->dev = next_policy->dev;
15169 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
15173 return -rte_mtr_error_set(error, ENOTSUP,
15174 RTE_MTR_ERROR_TYPE_METER_POLICY,
15175 NULL, "action type not supported");
15177 if (action_flags & MLX5_FLOW_ACTION_SET_TAG) {
15178 /* create modify action if needed. */
15179 dev_flow.dv.group = 1;
15180 if (flow_dv_modify_hdr_resource_register
15181 (dev, mhdr_res, &dev_flow, &flow_err))
15182 return -rte_mtr_error_set(error,
15184 RTE_MTR_ERROR_TYPE_METER_POLICY,
15185 NULL, "cannot register policy "
15187 act_cnt->modify_hdr =
15188 dev_flow.handle->dvh.modify_hdr;
15196 * Create policy action per domain, lock free,
15197 * (mutex should be acquired by caller).
15198 * Dispatcher for action type specific call.
15201 * Pointer to the Ethernet device structure.
15202 * @param[in] mtr_policy
15203 * Meter policy struct.
15204 * @param[in] action
15205 * Action specification used to create meter actions.
15206 * @param[out] error
15207 * Perform verbose error reporting if not NULL. Initialized in case of
15211 * 0 on success, otherwise negative errno value.
15214 flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
15215 struct mlx5_flow_meter_policy *mtr_policy,
15216 const struct rte_flow_action *actions[RTE_COLORS],
15217 struct rte_mtr_error *error)
15220 uint16_t sub_policy_num;
15222 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15223 sub_policy_num = (mtr_policy->sub_policy_num >>
15224 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15225 MLX5_MTR_SUB_POLICY_NUM_MASK;
15226 if (sub_policy_num) {
15227 ret = __flow_dv_create_domain_policy_acts(dev,
15228 mtr_policy, actions,
15229 (enum mlx5_meter_domain)i, error);
15238 * Query a DV flow rule for its statistics via DevX.
15241 * Pointer to Ethernet device.
15242 * @param[in] cnt_idx
15243 * Index to the flow counter.
15245 * Data retrieved by the query.
15246 * @param[out] error
15247 * Perform verbose error reporting if not NULL.
15250 * 0 on success, a negative errno value otherwise and rte_errno is set.
15253 flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
15254 struct rte_flow_error *error)
15256 struct mlx5_priv *priv = dev->data->dev_private;
15257 struct rte_flow_query_count *qc = data;
15259 if (!priv->config.devx)
15260 return rte_flow_error_set(error, ENOTSUP,
15261 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15263 "counters are not supported");
15265 uint64_t pkts, bytes;
15266 struct mlx5_flow_counter *cnt;
15267 int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
15270 return rte_flow_error_set(error, -err,
15271 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15272 NULL, "cannot read counters");
15273 cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
15276 qc->hits = pkts - cnt->hits;
15277 qc->bytes = bytes - cnt->bytes;
15280 cnt->bytes = bytes;
15284 return rte_flow_error_set(error, EINVAL,
15285 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15287 "counters are not available");
15291 flow_dv_action_query(struct rte_eth_dev *dev,
15292 const struct rte_flow_action_handle *handle, void *data,
15293 struct rte_flow_error *error)
15295 struct mlx5_age_param *age_param;
15296 struct rte_flow_query_age *resp;
15297 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15298 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15299 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15300 struct mlx5_priv *priv = dev->data->dev_private;
15301 struct mlx5_aso_ct_action *ct;
15306 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15307 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
15309 resp->aged = __atomic_load_n(&age_param->state,
15310 __ATOMIC_RELAXED) == AGE_TMOUT ?
15312 resp->sec_since_last_hit_valid = !resp->aged;
15313 if (resp->sec_since_last_hit_valid)
15314 resp->sec_since_last_hit = __atomic_load_n
15315 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15317 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15318 return flow_dv_query_count(dev, idx, data, error);
15319 case MLX5_INDIRECT_ACTION_TYPE_CT:
15320 owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
15321 if (owner != PORT_ID(priv))
15322 return rte_flow_error_set(error, EACCES,
15323 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15325 "CT object owned by another port");
15326 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
15327 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
15330 return rte_flow_error_set(error, EFAULT,
15331 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15333 "CT object is inactive");
15334 ((struct rte_flow_action_conntrack *)data)->peer_port =
15336 ((struct rte_flow_action_conntrack *)data)->is_original_dir =
15338 if (mlx5_aso_ct_query_by_wqe(priv->sh, ct, data))
15339 return rte_flow_error_set(error, EIO,
15340 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15342 "Failed to query CT context");
15345 return rte_flow_error_set(error, ENOTSUP,
15346 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15347 "action type query not supported");
15352 * Query a flow rule AGE action for aging information.
15355 * Pointer to Ethernet device.
15357 * Pointer to the sub flow.
15359 * data retrieved by the query.
15360 * @param[out] error
15361 * Perform verbose error reporting if not NULL.
15364 * 0 on success, a negative errno value otherwise and rte_errno is set.
15367 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
15368 void *data, struct rte_flow_error *error)
15370 struct rte_flow_query_age *resp = data;
15371 struct mlx5_age_param *age_param;
15374 struct mlx5_aso_age_action *act =
15375 flow_aso_age_get_by_idx(dev, flow->age);
15377 age_param = &act->age_params;
15378 } else if (flow->counter) {
15379 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
15381 if (!age_param || !age_param->timeout)
15382 return rte_flow_error_set
15384 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15385 NULL, "cannot read age data");
15387 return rte_flow_error_set(error, EINVAL,
15388 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15389 NULL, "age data not available");
15391 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
15393 resp->sec_since_last_hit_valid = !resp->aged;
15394 if (resp->sec_since_last_hit_valid)
15395 resp->sec_since_last_hit = __atomic_load_n
15396 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15403 * @see rte_flow_query()
15404 * @see rte_flow_ops
15407 flow_dv_query(struct rte_eth_dev *dev,
15408 struct rte_flow *flow __rte_unused,
15409 const struct rte_flow_action *actions __rte_unused,
15410 void *data __rte_unused,
15411 struct rte_flow_error *error __rte_unused)
15415 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
15416 switch (actions->type) {
15417 case RTE_FLOW_ACTION_TYPE_VOID:
15419 case RTE_FLOW_ACTION_TYPE_COUNT:
15420 ret = flow_dv_query_count(dev, flow->counter, data,
15423 case RTE_FLOW_ACTION_TYPE_AGE:
15424 ret = flow_dv_query_age(dev, flow, data, error);
15427 return rte_flow_error_set(error, ENOTSUP,
15428 RTE_FLOW_ERROR_TYPE_ACTION,
15430 "action not supported");
15437 * Destroy the meter table set.
15438 * Lock free, (mutex should be acquired by caller).
15441 * Pointer to Ethernet device.
15443 * Meter information table.
15446 flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
15447 struct mlx5_flow_meter_info *fm)
15449 struct mlx5_priv *priv = dev->data->dev_private;
15452 if (!fm || !priv->config.dv_flow_en)
15454 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15455 if (fm->drop_rule[i]) {
15456 claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
15457 fm->drop_rule[i] = NULL;
15463 flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
15465 struct mlx5_priv *priv = dev->data->dev_private;
15466 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15467 struct mlx5_flow_tbl_data_entry *tbl;
15470 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15471 if (mtrmng->def_rule[i]) {
15472 claim_zero(mlx5_flow_os_destroy_flow
15473 (mtrmng->def_rule[i]));
15474 mtrmng->def_rule[i] = NULL;
15476 if (mtrmng->def_matcher[i]) {
15477 tbl = container_of(mtrmng->def_matcher[i]->tbl,
15478 struct mlx5_flow_tbl_data_entry, tbl);
15479 mlx5_cache_unregister(&tbl->matchers,
15480 &mtrmng->def_matcher[i]->entry);
15481 mtrmng->def_matcher[i] = NULL;
15483 for (j = 0; j < MLX5_REG_BITS; j++) {
15484 if (mtrmng->drop_matcher[i][j]) {
15486 container_of(mtrmng->drop_matcher[i][j]->tbl,
15487 struct mlx5_flow_tbl_data_entry,
15489 mlx5_cache_unregister(&tbl->matchers,
15490 &mtrmng->drop_matcher[i][j]->entry);
15491 mtrmng->drop_matcher[i][j] = NULL;
15494 if (mtrmng->drop_tbl[i]) {
15495 flow_dv_tbl_resource_release(MLX5_SH(dev),
15496 mtrmng->drop_tbl[i]);
15497 mtrmng->drop_tbl[i] = NULL;
15502 /* Number of meter flow actions, count and jump or count and drop. */
15503 #define METER_ACTIONS 2
15506 __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
15507 enum mlx5_meter_domain domain)
15509 struct mlx5_priv *priv = dev->data->dev_private;
15510 struct mlx5_flow_meter_def_policy *def_policy =
15511 priv->sh->mtrmng->def_policy[domain];
15513 __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
15514 mlx5_free(def_policy);
15515 priv->sh->mtrmng->def_policy[domain] = NULL;
15519 * Destroy the default policy table set.
15522 * Pointer to Ethernet device.
15525 flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
15527 struct mlx5_priv *priv = dev->data->dev_private;
15530 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
15531 if (priv->sh->mtrmng->def_policy[i])
15532 __flow_dv_destroy_domain_def_policy(dev,
15533 (enum mlx5_meter_domain)i);
15534 priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
15538 __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
15539 uint32_t color_reg_c_idx,
15540 enum rte_color color, void *matcher_object,
15541 int actions_n, void *actions,
15542 bool match_src_port, const struct rte_flow_item *item,
15543 void **rule, const struct rte_flow_attr *attr)
15546 struct mlx5_flow_dv_match_params value = {
15547 .size = sizeof(value.buf),
15549 struct mlx5_flow_dv_match_params matcher = {
15550 .size = sizeof(matcher.buf),
15552 struct mlx5_priv *priv = dev->data->dev_private;
15555 if (match_src_port && (priv->representor || priv->master)) {
15556 if (flow_dv_translate_item_port_id(dev, matcher.buf,
15557 value.buf, item, attr)) {
15559 "Failed to create meter policy flow with port.");
15563 flow_dv_match_meta_reg(matcher.buf, value.buf,
15564 (enum modify_reg)color_reg_c_idx,
15565 rte_col_2_mlx5_col(color),
15567 misc_mask = flow_dv_matcher_enable(value.buf);
15568 __flow_dv_adjust_buf_size(&value.size, misc_mask);
15569 ret = mlx5_flow_os_create_flow(matcher_object,
15570 (void *)&value, actions_n, actions, rule);
15572 DRV_LOG(ERR, "Failed to create meter policy flow.");
15579 __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
15580 uint32_t color_reg_c_idx,
15582 struct mlx5_flow_meter_sub_policy *sub_policy,
15583 const struct rte_flow_attr *attr,
15584 bool match_src_port,
15585 const struct rte_flow_item *item,
15586 struct mlx5_flow_dv_matcher **policy_matcher,
15587 struct rte_flow_error *error)
15589 struct mlx5_cache_entry *entry;
15590 struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
15591 struct mlx5_flow_dv_matcher matcher = {
15593 .size = sizeof(matcher.mask.buf),
15597 struct mlx5_flow_dv_match_params value = {
15598 .size = sizeof(value.buf),
15600 struct mlx5_flow_cb_ctx ctx = {
15604 struct mlx5_flow_tbl_data_entry *tbl_data;
15605 struct mlx5_priv *priv = dev->data->dev_private;
15606 uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
15608 if (match_src_port && (priv->representor || priv->master)) {
15609 if (flow_dv_translate_item_port_id(dev, matcher.mask.buf,
15610 value.buf, item, attr)) {
15612 "Failed to register meter drop matcher with port.");
15616 tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
15617 if (priority < RTE_COLOR_RED)
15618 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
15619 (enum modify_reg)color_reg_c_idx, 0, color_mask);
15620 matcher.priority = priority;
15621 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15622 matcher.mask.size);
15623 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
15625 DRV_LOG(ERR, "Failed to register meter drop matcher.");
15629 container_of(entry, struct mlx5_flow_dv_matcher, entry);
15634 * Create the policy rules per domain.
15637 * Pointer to Ethernet device.
15638 * @param[in] sub_policy
15639 * Pointer to sub policy table..
15640 * @param[in] egress
15641 * Direction of the table.
15642 * @param[in] transfer
15643 * E-Switch or NIC flow.
15645 * Pointer to policy action list per color.
15648 * 0 on success, -1 otherwise.
15651 __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
15652 struct mlx5_flow_meter_sub_policy *sub_policy,
15653 uint8_t egress, uint8_t transfer, bool match_src_port,
15654 struct mlx5_meter_policy_acts acts[RTE_COLORS])
15656 struct mlx5_priv *priv = dev->data->dev_private;
15657 struct rte_flow_error flow_err;
15658 uint32_t color_reg_c_idx;
15659 struct rte_flow_attr attr = {
15660 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
15663 .egress = !!egress,
15664 .transfer = !!transfer,
15668 int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
15669 struct mlx5_sub_policy_color_rule *color_rule;
15673 /* Create policy table with POLICY level. */
15674 if (!sub_policy->tbl_rsc)
15675 sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
15676 MLX5_FLOW_TABLE_LEVEL_POLICY,
15677 egress, transfer, false, NULL, 0, 0,
15678 sub_policy->idx, &flow_err);
15679 if (!sub_policy->tbl_rsc) {
15681 "Failed to create meter sub policy table.");
15684 /* Prepare matchers. */
15685 color_reg_c_idx = ret;
15686 for (i = 0; i < RTE_COLORS; i++) {
15687 TAILQ_INIT(&sub_policy->color_rules[i]);
15688 if (i == RTE_COLOR_YELLOW || !acts[i].actions_n)
15690 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
15691 sizeof(struct mlx5_sub_policy_color_rule),
15694 DRV_LOG(ERR, "No memory to create color rule.");
15697 color_rule->src_port = priv->representor_id;
15699 /* Create matchers for Color. */
15700 if (__flow_dv_create_policy_matcher(dev,
15701 color_reg_c_idx, i, sub_policy, &attr,
15702 (i != RTE_COLOR_RED ? match_src_port : false),
15703 NULL, &color_rule->matcher, &flow_err)) {
15704 DRV_LOG(ERR, "Failed to create color matcher.");
15707 /* Create flow, matching color. */
15708 if (__flow_dv_create_policy_flow(dev,
15709 color_reg_c_idx, (enum rte_color)i,
15710 color_rule->matcher->matcher_object,
15712 acts[i].dv_actions,
15713 (i != RTE_COLOR_RED ? match_src_port : false),
15714 NULL, &color_rule->rule,
15716 DRV_LOG(ERR, "Failed to create color rule.");
15719 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
15720 color_rule, next_port);
15725 if (color_rule->rule)
15726 mlx5_flow_os_destroy_flow(color_rule->rule);
15727 if (color_rule->matcher) {
15728 struct mlx5_flow_tbl_data_entry *tbl =
15729 container_of(color_rule->matcher->tbl,
15730 typeof(*tbl), tbl);
15731 mlx5_cache_unregister(&tbl->matchers,
15732 &color_rule->matcher->entry);
15734 mlx5_free(color_rule);
15740 __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
15741 struct mlx5_flow_meter_policy *mtr_policy,
15742 struct mlx5_flow_meter_sub_policy *sub_policy,
15745 struct mlx5_priv *priv = dev->data->dev_private;
15746 struct mlx5_meter_policy_acts acts[RTE_COLORS];
15747 struct mlx5_flow_dv_tag_resource *tag;
15748 struct mlx5_flow_dv_port_id_action_resource *port_action;
15749 struct mlx5_hrxq *hrxq;
15750 struct mlx5_flow_meter_info *next_fm = NULL;
15751 struct mlx5_flow_meter_policy *next_policy;
15752 struct mlx5_flow_meter_sub_policy *next_sub_policy;
15753 struct mlx5_flow_tbl_data_entry *tbl_data;
15754 struct rte_flow_error error;
15755 uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15756 uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15757 bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
15758 bool match_src_port = false;
15761 for (i = 0; i < RTE_COLORS; i++) {
15762 acts[i].actions_n = 0;
15763 if (i == RTE_COLOR_YELLOW)
15765 if (i == RTE_COLOR_RED) {
15766 /* Only support drop on red. */
15767 acts[i].dv_actions[0] =
15768 mtr_policy->dr_drop_action[domain];
15769 acts[i].actions_n = 1;
15772 if (mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
15773 struct rte_flow_attr attr = {
15774 .transfer = transfer
15777 next_fm = mlx5_flow_meter_find(priv,
15778 mtr_policy->act_cnt[i].next_mtr_id,
15782 "Failed to get next hierarchy meter.");
15785 if (mlx5_flow_meter_attach(priv, next_fm,
15787 DRV_LOG(ERR, "%s", error.message);
15791 /* Meter action must be the first for TX. */
15793 acts[i].dv_actions[acts[i].actions_n] =
15794 next_fm->meter_action;
15795 acts[i].actions_n++;
15798 if (mtr_policy->act_cnt[i].rix_mark) {
15799 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
15800 mtr_policy->act_cnt[i].rix_mark);
15802 DRV_LOG(ERR, "Failed to find "
15803 "mark action for policy.");
15806 acts[i].dv_actions[acts[i].actions_n] =
15808 acts[i].actions_n++;
15810 if (mtr_policy->act_cnt[i].modify_hdr) {
15811 acts[i].dv_actions[acts[i].actions_n] =
15812 mtr_policy->act_cnt[i].modify_hdr->action;
15813 acts[i].actions_n++;
15815 if (mtr_policy->act_cnt[i].fate_action) {
15816 switch (mtr_policy->act_cnt[i].fate_action) {
15817 case MLX5_FLOW_FATE_PORT_ID:
15818 port_action = mlx5_ipool_get
15819 (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
15820 mtr_policy->act_cnt[i].rix_port_id_action);
15821 if (!port_action) {
15822 DRV_LOG(ERR, "Failed to find "
15823 "port action for policy.");
15826 acts[i].dv_actions[acts[i].actions_n] =
15827 port_action->action;
15828 acts[i].actions_n++;
15829 mtr_policy->dev = dev;
15830 match_src_port = true;
15832 case MLX5_FLOW_FATE_DROP:
15833 case MLX5_FLOW_FATE_JUMP:
15834 acts[i].dv_actions[acts[i].actions_n] =
15835 mtr_policy->act_cnt[i].dr_jump_action[domain];
15836 acts[i].actions_n++;
15838 case MLX5_FLOW_FATE_SHARED_RSS:
15839 case MLX5_FLOW_FATE_QUEUE:
15840 hrxq = mlx5_ipool_get
15841 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
15842 sub_policy->rix_hrxq[i]);
15844 DRV_LOG(ERR, "Failed to find "
15845 "queue action for policy.");
15848 acts[i].dv_actions[acts[i].actions_n] =
15850 acts[i].actions_n++;
15852 case MLX5_FLOW_FATE_MTR:
15855 "No next hierarchy meter.");
15859 acts[i].dv_actions[acts[i].actions_n] =
15860 next_fm->meter_action;
15861 acts[i].actions_n++;
15863 if (mtr_policy->act_cnt[i].next_sub_policy) {
15865 mtr_policy->act_cnt[i].next_sub_policy;
15868 mlx5_flow_meter_policy_find(dev,
15869 next_fm->policy_id, NULL);
15870 MLX5_ASSERT(next_policy);
15872 next_policy->sub_policys[domain][0];
15875 container_of(next_sub_policy->tbl_rsc,
15876 struct mlx5_flow_tbl_data_entry, tbl);
15877 acts[i].dv_actions[acts[i].actions_n++] =
15878 tbl_data->jump.action;
15879 if (mtr_policy->act_cnt[i].modify_hdr)
15880 match_src_port = !!transfer;
15883 /*Queue action do nothing*/
15888 if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
15889 egress, transfer, match_src_port, acts)) {
15891 "Failed to create policy rules per domain.");
15897 mlx5_flow_meter_detach(priv, next_fm);
15902 * Create the policy rules.
15905 * Pointer to Ethernet device.
15906 * @param[in,out] mtr_policy
15907 * Pointer to meter policy table.
15910 * 0 on success, -1 otherwise.
15913 flow_dv_create_policy_rules(struct rte_eth_dev *dev,
15914 struct mlx5_flow_meter_policy *mtr_policy)
15917 uint16_t sub_policy_num;
15919 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15920 sub_policy_num = (mtr_policy->sub_policy_num >>
15921 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15922 MLX5_MTR_SUB_POLICY_NUM_MASK;
15923 if (!sub_policy_num)
15925 /* Prepare actions list and create policy rules. */
15926 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
15927 mtr_policy->sub_policys[i][0], i)) {
15929 "Failed to create policy action list per domain.");
15937 __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
15939 struct mlx5_priv *priv = dev->data->dev_private;
15940 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15941 struct mlx5_flow_meter_def_policy *def_policy;
15942 struct mlx5_flow_tbl_resource *jump_tbl;
15943 struct mlx5_flow_tbl_data_entry *tbl_data;
15944 uint8_t egress, transfer;
15945 struct rte_flow_error error;
15946 struct mlx5_meter_policy_acts acts[RTE_COLORS];
15949 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15950 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15951 def_policy = mtrmng->def_policy[domain];
15953 def_policy = mlx5_malloc(MLX5_MEM_ZERO,
15954 sizeof(struct mlx5_flow_meter_def_policy),
15955 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
15957 DRV_LOG(ERR, "Failed to alloc "
15958 "default policy table.");
15959 goto def_policy_error;
15961 mtrmng->def_policy[domain] = def_policy;
15962 /* Create the meter suffix table with SUFFIX level. */
15963 jump_tbl = flow_dv_tbl_resource_get(dev,
15964 MLX5_FLOW_TABLE_LEVEL_METER,
15965 egress, transfer, false, NULL, 0,
15966 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
15969 "Failed to create meter suffix table.");
15970 goto def_policy_error;
15972 def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
15973 tbl_data = container_of(jump_tbl,
15974 struct mlx5_flow_tbl_data_entry, tbl);
15975 def_policy->dr_jump_action[RTE_COLOR_GREEN] =
15976 tbl_data->jump.action;
15977 acts[RTE_COLOR_GREEN].dv_actions[0] =
15978 tbl_data->jump.action;
15979 acts[RTE_COLOR_GREEN].actions_n = 1;
15980 /* Create jump action to the drop table. */
15981 if (!mtrmng->drop_tbl[domain]) {
15982 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
15983 (dev, MLX5_FLOW_TABLE_LEVEL_METER,
15984 egress, transfer, false, NULL, 0,
15985 0, MLX5_MTR_TABLE_ID_DROP, &error);
15986 if (!mtrmng->drop_tbl[domain]) {
15987 DRV_LOG(ERR, "Failed to create "
15988 "meter drop table for default policy.");
15989 goto def_policy_error;
15992 tbl_data = container_of(mtrmng->drop_tbl[domain],
15993 struct mlx5_flow_tbl_data_entry, tbl);
15994 def_policy->dr_jump_action[RTE_COLOR_RED] =
15995 tbl_data->jump.action;
15996 acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
15997 acts[RTE_COLOR_RED].actions_n = 1;
15998 /* Create default policy rules. */
15999 ret = __flow_dv_create_domain_policy_rules(dev,
16000 &def_policy->sub_policy,
16001 egress, transfer, false, acts);
16003 DRV_LOG(ERR, "Failed to create "
16004 "default policy rules.");
16005 goto def_policy_error;
16010 __flow_dv_destroy_domain_def_policy(dev,
16011 (enum mlx5_meter_domain)domain);
16016 * Create the default policy table set.
16019 * Pointer to Ethernet device.
16021 * 0 on success, -1 otherwise.
16024 flow_dv_create_def_policy(struct rte_eth_dev *dev)
16026 struct mlx5_priv *priv = dev->data->dev_private;
16029 /* Non-termination policy table. */
16030 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16031 if (!priv->config.dv_esw_en && i == MLX5_MTR_DOMAIN_TRANSFER)
16033 if (__flow_dv_create_domain_def_policy(dev, i)) {
16035 "Failed to create default policy");
16043 * Create the needed meter tables.
16044 * Lock free, (mutex should be acquired by caller).
16047 * Pointer to Ethernet device.
16049 * Meter information table.
16050 * @param[in] mtr_idx
16052 * @param[in] domain_bitmap
16055 * 0 on success, -1 otherwise.
16058 flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
16059 struct mlx5_flow_meter_info *fm,
16061 uint8_t domain_bitmap)
16063 struct mlx5_priv *priv = dev->data->dev_private;
16064 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
16065 struct rte_flow_error error;
16066 struct mlx5_flow_tbl_data_entry *tbl_data;
16067 uint8_t egress, transfer;
16068 void *actions[METER_ACTIONS];
16069 int domain, ret, i;
16070 struct mlx5_flow_counter *cnt;
16071 struct mlx5_flow_dv_match_params value = {
16072 .size = sizeof(value.buf),
16074 struct mlx5_flow_dv_match_params matcher_para = {
16075 .size = sizeof(matcher_para.buf),
16077 int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
16079 uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
16080 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
16081 struct mlx5_cache_entry *entry;
16082 struct mlx5_flow_dv_matcher matcher = {
16084 .size = sizeof(matcher.mask.buf),
16087 struct mlx5_flow_dv_matcher *drop_matcher;
16088 struct mlx5_flow_cb_ctx ctx = {
16094 if (!priv->mtr_en || mtr_id_reg_c < 0) {
16095 rte_errno = ENOTSUP;
16098 for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
16099 if (!(domain_bitmap & (1 << domain)) ||
16100 (mtrmng->def_rule[domain] && !fm->drop_cnt))
16102 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
16103 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
16104 /* Create the drop table with METER DROP level. */
16105 if (!mtrmng->drop_tbl[domain]) {
16106 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
16107 MLX5_FLOW_TABLE_LEVEL_METER,
16108 egress, transfer, false, NULL, 0,
16109 0, MLX5_MTR_TABLE_ID_DROP, &error);
16110 if (!mtrmng->drop_tbl[domain]) {
16111 DRV_LOG(ERR, "Failed to create meter drop table.");
16115 /* Create default matcher in drop table. */
16116 matcher.tbl = mtrmng->drop_tbl[domain],
16117 tbl_data = container_of(mtrmng->drop_tbl[domain],
16118 struct mlx5_flow_tbl_data_entry, tbl);
16119 if (!mtrmng->def_matcher[domain]) {
16120 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16121 (enum modify_reg)mtr_id_reg_c,
16123 matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
16124 matcher.crc = rte_raw_cksum
16125 ((const void *)matcher.mask.buf,
16126 matcher.mask.size);
16127 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
16129 DRV_LOG(ERR, "Failed to register meter "
16130 "drop default matcher.");
16133 mtrmng->def_matcher[domain] = container_of(entry,
16134 struct mlx5_flow_dv_matcher, entry);
16136 /* Create default rule in drop table. */
16137 if (!mtrmng->def_rule[domain]) {
16139 actions[i++] = priv->sh->dr_drop_action;
16140 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16141 (enum modify_reg)mtr_id_reg_c, 0, 0);
16142 misc_mask = flow_dv_matcher_enable(value.buf);
16143 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16144 ret = mlx5_flow_os_create_flow
16145 (mtrmng->def_matcher[domain]->matcher_object,
16146 (void *)&value, i, actions,
16147 &mtrmng->def_rule[domain]);
16149 DRV_LOG(ERR, "Failed to create meter "
16150 "default drop rule for drop table.");
16156 MLX5_ASSERT(mtrmng->max_mtr_bits);
16157 if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
16158 /* Create matchers for Drop. */
16159 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
16160 (enum modify_reg)mtr_id_reg_c, 0,
16161 (mtr_id_mask << mtr_id_offset));
16162 matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
16163 matcher.crc = rte_raw_cksum
16164 ((const void *)matcher.mask.buf,
16165 matcher.mask.size);
16166 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
16169 "Failed to register meter drop matcher.");
16172 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
16173 container_of(entry, struct mlx5_flow_dv_matcher,
16177 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
16178 /* Create drop rule, matching meter_id only. */
16179 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
16180 (enum modify_reg)mtr_id_reg_c,
16181 (mtr_idx << mtr_id_offset), UINT32_MAX);
16183 cnt = flow_dv_counter_get_by_idx(dev,
16184 fm->drop_cnt, NULL);
16185 actions[i++] = cnt->action;
16186 actions[i++] = priv->sh->dr_drop_action;
16187 misc_mask = flow_dv_matcher_enable(value.buf);
16188 __flow_dv_adjust_buf_size(&value.size, misc_mask);
16189 ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
16190 (void *)&value, i, actions,
16191 &fm->drop_rule[domain]);
16193 DRV_LOG(ERR, "Failed to create meter "
16194 "drop rule for drop table.");
16200 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
16201 if (fm->drop_rule[i]) {
16202 claim_zero(mlx5_flow_os_destroy_flow
16203 (fm->drop_rule[i]));
16204 fm->drop_rule[i] = NULL;
16210 static struct mlx5_flow_meter_sub_policy *
16211 __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
16212 struct mlx5_flow_meter_policy *mtr_policy,
16213 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
16214 struct mlx5_flow_meter_sub_policy *next_sub_policy,
16217 struct mlx5_priv *priv = dev->data->dev_private;
16218 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16219 uint32_t sub_policy_idx = 0;
16220 uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
16222 struct mlx5_hrxq *hrxq;
16223 struct mlx5_flow_handle dh;
16224 struct mlx5_meter_policy_action_container *act_cnt;
16225 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16226 uint16_t sub_policy_num;
16228 rte_spinlock_lock(&mtr_policy->sl);
16229 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16232 hrxq_idx[i] = mlx5_hrxq_get(dev, rss_desc[i]);
16233 if (!hrxq_idx[i]) {
16234 rte_spinlock_unlock(&mtr_policy->sl);
16238 sub_policy_num = (mtr_policy->sub_policy_num >>
16239 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16240 MLX5_MTR_SUB_POLICY_NUM_MASK;
16241 for (i = 0; i < sub_policy_num;
16243 for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) {
16246 mtr_policy->sub_policys[domain][i]->rix_hrxq[j])
16249 if (j >= MLX5_MTR_RTE_COLORS) {
16251 * Found the sub policy table with
16252 * the same queue per color
16254 rte_spinlock_unlock(&mtr_policy->sl);
16255 for (j = 0; j < MLX5_MTR_RTE_COLORS; j++)
16256 mlx5_hrxq_release(dev, hrxq_idx[j]);
16258 return mtr_policy->sub_policys[domain][i];
16261 /* Create sub policy. */
16262 if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[0]) {
16263 /* Reuse the first dummy sub_policy*/
16264 sub_policy = mtr_policy->sub_policys[domain][0];
16265 sub_policy_idx = sub_policy->idx;
16267 sub_policy = mlx5_ipool_zmalloc
16268 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16271 sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
16272 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
16273 mlx5_hrxq_release(dev, hrxq_idx[i]);
16274 goto rss_sub_policy_error;
16276 sub_policy->idx = sub_policy_idx;
16277 sub_policy->main_policy = mtr_policy;
16279 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16282 sub_policy->rix_hrxq[i] = hrxq_idx[i];
16283 if (mtr_policy->is_hierarchy) {
16284 act_cnt = &mtr_policy->act_cnt[i];
16285 act_cnt->next_sub_policy = next_sub_policy;
16286 mlx5_hrxq_release(dev, hrxq_idx[i]);
16289 * Overwrite the last action from
16290 * RSS action to Queue action.
16292 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
16295 DRV_LOG(ERR, "Failed to create policy hrxq");
16296 goto rss_sub_policy_error;
16298 act_cnt = &mtr_policy->act_cnt[i];
16299 if (act_cnt->rix_mark || act_cnt->modify_hdr) {
16300 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
16301 if (act_cnt->rix_mark)
16303 dh.fate_action = MLX5_FLOW_FATE_QUEUE;
16304 dh.rix_hrxq = hrxq_idx[i];
16305 flow_drv_rxq_flags_set(dev, &dh);
16309 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16310 sub_policy, domain)) {
16311 DRV_LOG(ERR, "Failed to create policy "
16312 "rules per domain.");
16313 goto rss_sub_policy_error;
16315 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16316 i = (mtr_policy->sub_policy_num >>
16317 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16318 MLX5_MTR_SUB_POLICY_NUM_MASK;
16319 mtr_policy->sub_policys[domain][i] = sub_policy;
16321 if (i > MLX5_MTR_RSS_MAX_SUB_POLICY)
16322 goto rss_sub_policy_error;
16323 mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16324 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
16325 mtr_policy->sub_policy_num |=
16326 (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16327 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
16329 rte_spinlock_unlock(&mtr_policy->sl);
16332 rss_sub_policy_error:
16334 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
16335 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16336 i = (mtr_policy->sub_policy_num >>
16337 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16338 MLX5_MTR_SUB_POLICY_NUM_MASK;
16339 mtr_policy->sub_policys[domain][i] = NULL;
16341 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16345 rte_spinlock_unlock(&mtr_policy->sl);
16350 * Find the policy table for prefix table with RSS.
16353 * Pointer to Ethernet device.
16354 * @param[in] mtr_policy
16355 * Pointer to meter policy table.
16356 * @param[in] rss_desc
16357 * Pointer to rss_desc
16359 * Pointer to table set on success, NULL otherwise and rte_errno is set.
16361 static struct mlx5_flow_meter_sub_policy *
16362 flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
16363 struct mlx5_flow_meter_policy *mtr_policy,
16364 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
16366 struct mlx5_priv *priv = dev->data->dev_private;
16367 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16368 struct mlx5_flow_meter_info *next_fm;
16369 struct mlx5_flow_meter_policy *next_policy;
16370 struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
16371 struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
16372 struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
16373 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16374 bool reuse_sub_policy;
16379 /* Iterate hierarchy to get all policies in this hierarchy. */
16380 policies[i++] = mtr_policy;
16381 if (!mtr_policy->is_hierarchy)
16383 if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
16384 DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
16387 next_fm = mlx5_flow_meter_find(priv,
16388 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
16390 DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
16394 mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
16396 MLX5_ASSERT(next_policy);
16397 mtr_policy = next_policy;
16401 * From last policy to the first one in hierarchy,
16402 * create/get the sub policy for each of them.
16404 sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
16408 &reuse_sub_policy);
16410 DRV_LOG(ERR, "Failed to get the sub policy.");
16413 if (!reuse_sub_policy)
16414 sub_policies[j++] = sub_policy;
16415 next_sub_policy = sub_policy;
16420 uint16_t sub_policy_num;
16422 sub_policy = sub_policies[--j];
16423 mtr_policy = sub_policy->main_policy;
16424 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
16425 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16426 sub_policy_num = (mtr_policy->sub_policy_num >>
16427 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16428 MLX5_MTR_SUB_POLICY_NUM_MASK;
16429 mtr_policy->sub_policys[domain][sub_policy_num - 1] =
16432 mtr_policy->sub_policy_num &=
16433 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16434 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
16435 mtr_policy->sub_policy_num |=
16436 (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16437 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
16438 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16446 * Create the sub policy tag rule for all meters in hierarchy.
16449 * Pointer to Ethernet device.
16451 * Meter information table.
16452 * @param[in] src_port
16453 * The src port this extra rule should use.
16455 * The src port match item.
16456 * @param[out] error
16457 * Perform verbose error reporting if not NULL.
16459 * 0 on success, a negative errno value otherwise and rte_errno is set.
16462 flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
16463 struct mlx5_flow_meter_info *fm,
16465 const struct rte_flow_item *item,
16466 struct rte_flow_error *error)
16468 struct mlx5_priv *priv = dev->data->dev_private;
16469 struct mlx5_flow_meter_policy *mtr_policy;
16470 struct mlx5_flow_meter_sub_policy *sub_policy;
16471 struct mlx5_flow_meter_info *next_fm = NULL;
16472 struct mlx5_flow_meter_policy *next_policy;
16473 struct mlx5_flow_meter_sub_policy *next_sub_policy;
16474 struct mlx5_flow_tbl_data_entry *tbl_data;
16475 struct mlx5_sub_policy_color_rule *color_rule;
16476 struct mlx5_meter_policy_acts acts;
16477 uint32_t color_reg_c_idx;
16478 bool mtr_first = (src_port != UINT16_MAX) ? true : false;
16479 struct rte_flow_attr attr = {
16480 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
16487 uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
16490 mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
16491 MLX5_ASSERT(mtr_policy);
16492 if (!mtr_policy->is_hierarchy)
16494 next_fm = mlx5_flow_meter_find(priv,
16495 mtr_policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id, NULL);
16497 return rte_flow_error_set(error, EINVAL,
16498 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16499 "Failed to find next meter in hierarchy.");
16501 if (!next_fm->drop_cnt)
16503 color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
16504 sub_policy = mtr_policy->sub_policys[domain][0];
16505 for (i = 0; i < RTE_COLORS; i++) {
16506 bool rule_exist = false;
16507 struct mlx5_meter_policy_action_container *act_cnt;
16509 if (i >= RTE_COLOR_YELLOW)
16511 TAILQ_FOREACH(color_rule,
16512 &sub_policy->color_rules[i], next_port)
16513 if (color_rule->src_port == src_port) {
16519 color_rule = mlx5_malloc(MLX5_MEM_ZERO,
16520 sizeof(struct mlx5_sub_policy_color_rule),
16523 return rte_flow_error_set(error, ENOMEM,
16524 RTE_FLOW_ERROR_TYPE_ACTION,
16525 NULL, "No memory to create tag color rule.");
16526 color_rule->src_port = src_port;
16528 next_policy = mlx5_flow_meter_policy_find(dev,
16529 next_fm->policy_id, NULL);
16530 MLX5_ASSERT(next_policy);
16531 next_sub_policy = next_policy->sub_policys[domain][0];
16532 tbl_data = container_of(next_sub_policy->tbl_rsc,
16533 struct mlx5_flow_tbl_data_entry, tbl);
16534 act_cnt = &mtr_policy->act_cnt[i];
16536 acts.dv_actions[0] = next_fm->meter_action;
16537 acts.dv_actions[1] = act_cnt->modify_hdr->action;
16539 acts.dv_actions[0] = act_cnt->modify_hdr->action;
16540 acts.dv_actions[1] = next_fm->meter_action;
16542 acts.dv_actions[2] = tbl_data->jump.action;
16543 acts.actions_n = 3;
16544 if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
16548 if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
16549 i, sub_policy, &attr, true, item,
16550 &color_rule->matcher, error)) {
16551 rte_flow_error_set(error, errno,
16552 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16553 "Failed to create hierarchy meter matcher.");
16556 if (__flow_dv_create_policy_flow(dev, color_reg_c_idx,
16558 color_rule->matcher->matcher_object,
16559 acts.actions_n, acts.dv_actions,
16561 &color_rule->rule, &attr)) {
16562 rte_flow_error_set(error, errno,
16563 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16564 "Failed to create hierarchy meter rule.");
16567 TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
16568 color_rule, next_port);
16572 * Recursive call to iterate all meters in hierarchy and
16573 * create needed rules.
16575 return flow_dv_meter_hierarchy_rule_create(dev, next_fm,
16576 src_port, item, error);
16579 if (color_rule->rule)
16580 mlx5_flow_os_destroy_flow(color_rule->rule);
16581 if (color_rule->matcher) {
16582 struct mlx5_flow_tbl_data_entry *tbl =
16583 container_of(color_rule->matcher->tbl,
16584 typeof(*tbl), tbl);
16585 mlx5_cache_unregister(&tbl->matchers,
16586 &color_rule->matcher->entry);
16588 mlx5_free(color_rule);
16591 mlx5_flow_meter_detach(priv, next_fm);
16596 * Destroy the sub policy table with RX queue.
16599 * Pointer to Ethernet device.
16600 * @param[in] mtr_policy
16601 * Pointer to meter policy table.
16604 flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
16605 struct mlx5_flow_meter_policy *mtr_policy)
16607 struct mlx5_priv *priv = dev->data->dev_private;
16608 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16609 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16611 uint16_t sub_policy_num, new_policy_num;
16613 rte_spinlock_lock(&mtr_policy->sl);
16614 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16615 switch (mtr_policy->act_cnt[i].fate_action) {
16616 case MLX5_FLOW_FATE_SHARED_RSS:
16617 sub_policy_num = (mtr_policy->sub_policy_num >>
16618 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16619 MLX5_MTR_SUB_POLICY_NUM_MASK;
16620 new_policy_num = sub_policy_num;
16621 for (j = 0; j < sub_policy_num; j++) {
16623 mtr_policy->sub_policys[domain][j];
16625 __flow_dv_destroy_sub_policy_rules(dev,
16628 mtr_policy->sub_policys[domain][0]) {
16629 mtr_policy->sub_policys[domain][j] =
16632 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16638 if (new_policy_num != sub_policy_num) {
16639 mtr_policy->sub_policy_num &=
16640 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16641 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
16642 mtr_policy->sub_policy_num |=
16644 MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16645 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
16648 case MLX5_FLOW_FATE_QUEUE:
16649 sub_policy = mtr_policy->sub_policys[domain][0];
16650 __flow_dv_destroy_sub_policy_rules(dev,
16654 /*Other actions without queue and do nothing*/
16658 rte_spinlock_unlock(&mtr_policy->sl);
16662 * Validate the batch counter support in root table.
16664 * Create a simple flow with invalid counter and drop action on root table to
16665 * validate if batch counter with offset on root table is supported or not.
16668 * Pointer to rte_eth_dev structure.
16671 * 0 on success, a negative errno value otherwise and rte_errno is set.
16674 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
16676 struct mlx5_priv *priv = dev->data->dev_private;
16677 struct mlx5_dev_ctx_shared *sh = priv->sh;
16678 struct mlx5_flow_dv_match_params mask = {
16679 .size = sizeof(mask.buf),
16681 struct mlx5_flow_dv_match_params value = {
16682 .size = sizeof(value.buf),
16684 struct mlx5dv_flow_matcher_attr dv_attr = {
16685 .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
16687 .match_criteria_enable = 0,
16688 .match_mask = (void *)&mask,
16690 void *actions[2] = { 0 };
16691 struct mlx5_flow_tbl_resource *tbl = NULL;
16692 struct mlx5_devx_obj *dcs = NULL;
16693 void *matcher = NULL;
16697 tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
16701 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
16704 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
16708 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
16709 __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
16710 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
16714 __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
16715 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
16719 * If batch counter with offset is not supported, the driver will not
16720 * validate the invalid offset value, flow create should success.
16721 * In this case, it means batch counter is not supported in root table.
16723 * Otherwise, if flow create is failed, counter offset is supported.
16726 DRV_LOG(INFO, "Batch counter is not supported in root "
16727 "table. Switch to fallback mode.");
16728 rte_errno = ENOTSUP;
16730 claim_zero(mlx5_flow_os_destroy_flow(flow));
16732 /* Check matcher to make sure validate fail at flow create. */
16733 if (!matcher || (matcher && errno != EINVAL))
16734 DRV_LOG(ERR, "Unexpected error in counter offset "
16735 "support detection");
16739 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
16741 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
16743 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
16745 claim_zero(mlx5_devx_cmd_destroy(dcs));
16750 * Query a devx counter.
16753 * Pointer to the Ethernet device structure.
16755 * Index to the flow counter.
16757 * Set to clear the counter statistics.
16759 * The statistics value of packets.
16760 * @param[out] bytes
16761 * The statistics value of bytes.
16764 * 0 on success, otherwise return -1.
16767 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
16768 uint64_t *pkts, uint64_t *bytes)
16770 struct mlx5_priv *priv = dev->data->dev_private;
16771 struct mlx5_flow_counter *cnt;
16772 uint64_t inn_pkts, inn_bytes;
16775 if (!priv->config.devx)
16778 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
16781 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
16782 *pkts = inn_pkts - cnt->hits;
16783 *bytes = inn_bytes - cnt->bytes;
16785 cnt->hits = inn_pkts;
16786 cnt->bytes = inn_bytes;
16792 * Get aged-out flows.
16795 * Pointer to the Ethernet device structure.
16796 * @param[in] context
16797 * The address of an array of pointers to the aged-out flows contexts.
16798 * @param[in] nb_contexts
16799 * The length of context array pointers.
16800 * @param[out] error
16801 * Perform verbose error reporting if not NULL. Initialized in case of
16805 * how many contexts get in success, otherwise negative errno value.
16806 * if nb_contexts is 0, return the amount of all aged contexts.
16807 * if nb_contexts is not 0 , return the amount of aged flows reported
16808 * in the context array.
16809 * @note: only stub for now
16812 flow_get_aged_flows(struct rte_eth_dev *dev,
16814 uint32_t nb_contexts,
16815 struct rte_flow_error *error)
16817 struct mlx5_priv *priv = dev->data->dev_private;
16818 struct mlx5_age_info *age_info;
16819 struct mlx5_age_param *age_param;
16820 struct mlx5_flow_counter *counter;
16821 struct mlx5_aso_age_action *act;
16824 if (nb_contexts && !context)
16825 return rte_flow_error_set(error, EINVAL,
16826 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16827 NULL, "empty context");
16828 age_info = GET_PORT_AGE_INFO(priv);
16829 rte_spinlock_lock(&age_info->aged_sl);
16830 LIST_FOREACH(act, &age_info->aged_aso, next) {
16833 context[nb_flows - 1] =
16834 act->age_params.context;
16835 if (!(--nb_contexts))
16839 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
16842 age_param = MLX5_CNT_TO_AGE(counter);
16843 context[nb_flows - 1] = age_param->context;
16844 if (!(--nb_contexts))
16848 rte_spinlock_unlock(&age_info->aged_sl);
16849 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
16854 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
16857 flow_dv_counter_allocate(struct rte_eth_dev *dev)
16859 return flow_dv_counter_alloc(dev, 0);
16863 * Validate indirect action.
16864 * Dispatcher for action type specific validation.
16867 * Pointer to the Ethernet device structure.
16869 * Indirect action configuration.
16870 * @param[in] action
16871 * The indirect action object to validate.
16872 * @param[out] error
16873 * Perform verbose error reporting if not NULL. Initialized in case of
16877 * 0 on success, otherwise negative errno value.
16880 flow_dv_action_validate(struct rte_eth_dev *dev,
16881 const struct rte_flow_indir_action_conf *conf,
16882 const struct rte_flow_action *action,
16883 struct rte_flow_error *err)
16885 struct mlx5_priv *priv = dev->data->dev_private;
16887 RTE_SET_USED(conf);
16888 switch (action->type) {
16889 case RTE_FLOW_ACTION_TYPE_RSS:
16891 * priv->obj_ops is set according to driver capabilities.
16892 * When DevX capabilities are
16893 * sufficient, it is set to devx_obj_ops.
16894 * Otherwise, it is set to ibv_obj_ops.
16895 * ibv_obj_ops doesn't support ind_table_modify operation.
16896 * In this case the indirect RSS action can't be used.
16898 if (priv->obj_ops.ind_table_modify == NULL)
16899 return rte_flow_error_set
16901 RTE_FLOW_ERROR_TYPE_ACTION,
16903 "Indirect RSS action not supported");
16904 return mlx5_validate_action_rss(dev, action, err);
16905 case RTE_FLOW_ACTION_TYPE_AGE:
16906 if (!priv->sh->aso_age_mng)
16907 return rte_flow_error_set(err, ENOTSUP,
16908 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16910 "Indirect age action not supported");
16911 return flow_dv_validate_action_age(0, action, dev, err);
16912 case RTE_FLOW_ACTION_TYPE_COUNT:
16914 * There are two mechanisms to share the action count.
16915 * The old mechanism uses the shared field to share, while the
16916 * new mechanism uses the indirect action API.
16917 * This validation comes to make sure that the two mechanisms
16918 * are not combined.
16920 if (is_shared_action_count(action))
16921 return rte_flow_error_set(err, ENOTSUP,
16922 RTE_FLOW_ERROR_TYPE_ACTION,
16924 "Mix shared and indirect counter is not supported");
16925 return flow_dv_validate_action_count(dev, true, 0, err);
16926 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
16927 if (!priv->sh->ct_aso_en)
16928 return rte_flow_error_set(err, ENOTSUP,
16929 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16930 "ASO CT is not supported");
16931 return mlx5_validate_action_ct(dev, action->conf, err);
16933 return rte_flow_error_set(err, ENOTSUP,
16934 RTE_FLOW_ERROR_TYPE_ACTION,
16936 "action type not supported");
16941 * Validate the meter hierarchy chain for meter policy.
16944 * Pointer to the Ethernet device structure.
16945 * @param[in] meter_id
16947 * @param[in] action_flags
16948 * Holds the actions detected until now.
16949 * @param[out] is_rss
16951 * @param[out] hierarchy_domain
16952 * The domain bitmap for hierarchy policy.
16953 * @param[out] error
16954 * Perform verbose error reporting if not NULL. Initialized in case of
16958 * 0 on success, otherwise negative errno value with error set.
16961 flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
16963 uint64_t action_flags,
16965 uint8_t *hierarchy_domain,
16966 struct rte_mtr_error *error)
16968 struct mlx5_priv *priv = dev->data->dev_private;
16969 struct mlx5_flow_meter_info *fm;
16970 struct mlx5_flow_meter_policy *policy;
16973 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
16974 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
16975 return -rte_mtr_error_set(error, EINVAL,
16976 RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
16978 "Multiple fate actions not supported.");
16980 fm = mlx5_flow_meter_find(priv, meter_id, NULL);
16982 return -rte_mtr_error_set(error, EINVAL,
16983 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
16984 "Meter not found in meter hierarchy.");
16985 if (fm->def_policy)
16986 return -rte_mtr_error_set(error, EINVAL,
16987 RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
16988 "Non termination meter not supported in hierarchy.");
16989 policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
16990 MLX5_ASSERT(policy);
16991 if (!policy->is_hierarchy) {
16992 if (policy->transfer)
16993 *hierarchy_domain |=
16994 MLX5_MTR_DOMAIN_TRANSFER_BIT;
16995 if (policy->ingress)
16996 *hierarchy_domain |=
16997 MLX5_MTR_DOMAIN_INGRESS_BIT;
16998 if (policy->egress)
16999 *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
17000 *is_rss = policy->is_rss;
17003 meter_id = policy->act_cnt[RTE_COLOR_GREEN].next_mtr_id;
17004 if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
17005 return -rte_mtr_error_set(error, EINVAL,
17006 RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
17007 "Exceed max hierarchy meter number.");
17013 * Validate meter policy actions.
17014 * Dispatcher for action type specific validation.
17017 * Pointer to the Ethernet device structure.
17018 * @param[in] action
17019 * The meter policy action object to validate.
17021 * Attributes of flow to determine steering domain.
17022 * @param[out] error
17023 * Perform verbose error reporting if not NULL. Initialized in case of
17027 * 0 on success, otherwise negative errno value.
17030 flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
17031 const struct rte_flow_action *actions[RTE_COLORS],
17032 struct rte_flow_attr *attr,
17034 uint8_t *domain_bitmap,
17035 bool *is_def_policy,
17036 struct rte_mtr_error *error)
17038 struct mlx5_priv *priv = dev->data->dev_private;
17039 struct mlx5_dev_config *dev_conf = &priv->config;
17040 const struct rte_flow_action *act;
17041 uint64_t action_flags = 0;
17044 struct rte_flow_error flow_err;
17045 uint8_t domain_color[RTE_COLORS] = {0};
17046 uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
17047 uint8_t hierarchy_domain = 0;
17048 const struct rte_flow_action_meter *mtr;
17050 if (!priv->config.dv_esw_en)
17051 def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
17052 *domain_bitmap = def_domain;
17053 if (actions[RTE_COLOR_YELLOW] &&
17054 actions[RTE_COLOR_YELLOW]->type != RTE_FLOW_ACTION_TYPE_END)
17055 return -rte_mtr_error_set(error, ENOTSUP,
17056 RTE_MTR_ERROR_TYPE_METER_POLICY,
17058 "Yellow color does not support any action.");
17059 if (actions[RTE_COLOR_YELLOW] &&
17060 actions[RTE_COLOR_YELLOW]->type != RTE_FLOW_ACTION_TYPE_DROP)
17061 return -rte_mtr_error_set(error, ENOTSUP,
17062 RTE_MTR_ERROR_TYPE_METER_POLICY,
17063 NULL, "Red color only supports drop action.");
17065 * Check default policy actions:
17066 * Green/Yellow: no action, Red: drop action
17068 if ((!actions[RTE_COLOR_GREEN] ||
17069 actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)) {
17070 *is_def_policy = true;
17073 flow_err.message = NULL;
17074 for (i = 0; i < RTE_COLORS; i++) {
17076 for (action_flags = 0, actions_n = 0;
17077 act && act->type != RTE_FLOW_ACTION_TYPE_END;
17079 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
17080 return -rte_mtr_error_set(error, ENOTSUP,
17081 RTE_MTR_ERROR_TYPE_METER_POLICY,
17082 NULL, "too many actions");
17083 switch (act->type) {
17084 case RTE_FLOW_ACTION_TYPE_PORT_ID:
17085 if (!priv->config.dv_esw_en)
17086 return -rte_mtr_error_set(error,
17088 RTE_MTR_ERROR_TYPE_METER_POLICY,
17089 NULL, "PORT action validate check"
17090 " fail for ESW disable");
17091 ret = flow_dv_validate_action_port_id(dev,
17093 act, attr, &flow_err);
17095 return -rte_mtr_error_set(error,
17097 RTE_MTR_ERROR_TYPE_METER_POLICY,
17098 NULL, flow_err.message ?
17100 "PORT action validate check fail");
17102 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
17104 case RTE_FLOW_ACTION_TYPE_MARK:
17105 ret = flow_dv_validate_action_mark(dev, act,
17109 return -rte_mtr_error_set(error,
17111 RTE_MTR_ERROR_TYPE_METER_POLICY,
17112 NULL, flow_err.message ?
17114 "Mark action validate check fail");
17115 if (dev_conf->dv_xmeta_en !=
17116 MLX5_XMETA_MODE_LEGACY)
17117 return -rte_mtr_error_set(error,
17119 RTE_MTR_ERROR_TYPE_METER_POLICY,
17120 NULL, "Extend MARK action is "
17121 "not supported. Please try use "
17122 "default policy for meter.");
17123 action_flags |= MLX5_FLOW_ACTION_MARK;
17126 case RTE_FLOW_ACTION_TYPE_SET_TAG:
17127 ret = flow_dv_validate_action_set_tag(dev,
17131 return -rte_mtr_error_set(error,
17133 RTE_MTR_ERROR_TYPE_METER_POLICY,
17134 NULL, flow_err.message ?
17136 "Set tag action validate check fail");
17138 * Count all modify-header actions
17141 if (!(action_flags &
17142 MLX5_FLOW_MODIFY_HDR_ACTIONS))
17144 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
17146 case RTE_FLOW_ACTION_TYPE_DROP:
17147 ret = mlx5_flow_validate_action_drop
17151 return -rte_mtr_error_set(error,
17153 RTE_MTR_ERROR_TYPE_METER_POLICY,
17154 NULL, flow_err.message ?
17156 "Drop action validate check fail");
17157 action_flags |= MLX5_FLOW_ACTION_DROP;
17160 case RTE_FLOW_ACTION_TYPE_QUEUE:
17162 * Check whether extensive
17163 * metadata feature is engaged.
17165 if (dev_conf->dv_flow_en &&
17166 (dev_conf->dv_xmeta_en !=
17167 MLX5_XMETA_MODE_LEGACY) &&
17168 mlx5_flow_ext_mreg_supported(dev))
17169 return -rte_mtr_error_set(error,
17171 RTE_MTR_ERROR_TYPE_METER_POLICY,
17172 NULL, "Queue action with meta "
17173 "is not supported. Please try use "
17174 "default policy for meter.");
17175 ret = mlx5_flow_validate_action_queue(act,
17179 return -rte_mtr_error_set(error,
17181 RTE_MTR_ERROR_TYPE_METER_POLICY,
17182 NULL, flow_err.message ?
17184 "Queue action validate check fail");
17185 action_flags |= MLX5_FLOW_ACTION_QUEUE;
17188 case RTE_FLOW_ACTION_TYPE_RSS:
17189 if (dev_conf->dv_flow_en &&
17190 (dev_conf->dv_xmeta_en !=
17191 MLX5_XMETA_MODE_LEGACY) &&
17192 mlx5_flow_ext_mreg_supported(dev))
17193 return -rte_mtr_error_set(error,
17195 RTE_MTR_ERROR_TYPE_METER_POLICY,
17196 NULL, "RSS action with meta "
17197 "is not supported. Please try use "
17198 "default policy for meter.");
17199 ret = mlx5_validate_action_rss(dev, act,
17202 return -rte_mtr_error_set(error,
17204 RTE_MTR_ERROR_TYPE_METER_POLICY,
17205 NULL, flow_err.message ?
17207 "RSS action validate check fail");
17208 action_flags |= MLX5_FLOW_ACTION_RSS;
17212 case RTE_FLOW_ACTION_TYPE_JUMP:
17213 ret = flow_dv_validate_action_jump(dev,
17214 NULL, act, action_flags,
17215 attr, true, &flow_err);
17217 return -rte_mtr_error_set(error,
17219 RTE_MTR_ERROR_TYPE_METER_POLICY,
17220 NULL, flow_err.message ?
17222 "Jump action validate check fail");
17224 action_flags |= MLX5_FLOW_ACTION_JUMP;
17226 case RTE_FLOW_ACTION_TYPE_METER:
17227 if (i != RTE_COLOR_GREEN)
17228 return -rte_mtr_error_set(error,
17230 RTE_MTR_ERROR_TYPE_METER_POLICY,
17231 NULL, flow_err.message ?
17233 "Meter hierarchy only supports GREEN color.");
17235 ret = flow_dv_validate_policy_mtr_hierarchy(dev,
17245 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
17248 return -rte_mtr_error_set(error, ENOTSUP,
17249 RTE_MTR_ERROR_TYPE_METER_POLICY,
17251 "Doesn't support optional action");
17254 /* Yellow is not supported, just skip. */
17255 if (i == RTE_COLOR_YELLOW)
17257 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
17258 domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
17259 else if ((action_flags &
17260 (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
17261 (action_flags & MLX5_FLOW_ACTION_MARK))
17263 * Only support MLX5_XMETA_MODE_LEGACY
17264 * so MARK action only in ingress domain.
17266 domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
17267 else if (action_flags &
17268 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
17269 domain_color[i] = hierarchy_domain;
17271 domain_color[i] = def_domain;
17273 * Validate the drop action mutual exclusion
17274 * with other actions. Drop action is mutually-exclusive
17275 * with any other action, except for Count action.
17277 if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
17278 (action_flags & ~MLX5_FLOW_ACTION_DROP)) {
17279 return -rte_mtr_error_set(error, ENOTSUP,
17280 RTE_MTR_ERROR_TYPE_METER_POLICY,
17281 NULL, "Drop action is mutually-exclusive "
17282 "with any other action");
17284 /* Eswitch has few restrictions on using items and actions */
17285 if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
17286 if (!mlx5_flow_ext_mreg_supported(dev) &&
17287 action_flags & MLX5_FLOW_ACTION_MARK)
17288 return -rte_mtr_error_set(error, ENOTSUP,
17289 RTE_MTR_ERROR_TYPE_METER_POLICY,
17290 NULL, "unsupported action MARK");
17291 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
17292 return -rte_mtr_error_set(error, ENOTSUP,
17293 RTE_MTR_ERROR_TYPE_METER_POLICY,
17294 NULL, "unsupported action QUEUE");
17295 if (action_flags & MLX5_FLOW_ACTION_RSS)
17296 return -rte_mtr_error_set(error, ENOTSUP,
17297 RTE_MTR_ERROR_TYPE_METER_POLICY,
17298 NULL, "unsupported action RSS");
17299 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
17300 return -rte_mtr_error_set(error, ENOTSUP,
17301 RTE_MTR_ERROR_TYPE_METER_POLICY,
17302 NULL, "no fate action is found");
17304 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) &&
17306 MLX5_MTR_DOMAIN_INGRESS_BIT)) {
17307 if ((domain_color[i] &
17308 MLX5_MTR_DOMAIN_EGRESS_BIT))
17310 MLX5_MTR_DOMAIN_EGRESS_BIT;
17312 return -rte_mtr_error_set(error,
17314 RTE_MTR_ERROR_TYPE_METER_POLICY,
17315 NULL, "no fate action is found");
17318 if (domain_color[i] != def_domain)
17319 *domain_bitmap = domain_color[i];
17325 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
17327 struct mlx5_priv *priv = dev->data->dev_private;
17330 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
17331 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
17336 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
17337 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
17341 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
17342 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
17349 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
17350 .validate = flow_dv_validate,
17351 .prepare = flow_dv_prepare,
17352 .translate = flow_dv_translate,
17353 .apply = flow_dv_apply,
17354 .remove = flow_dv_remove,
17355 .destroy = flow_dv_destroy,
17356 .query = flow_dv_query,
17357 .create_mtr_tbls = flow_dv_create_mtr_tbls,
17358 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
17359 .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
17360 .create_meter = flow_dv_mtr_alloc,
17361 .free_meter = flow_dv_aso_mtr_release_to_pool,
17362 .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
17363 .create_mtr_acts = flow_dv_create_mtr_policy_acts,
17364 .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
17365 .create_policy_rules = flow_dv_create_policy_rules,
17366 .destroy_policy_rules = flow_dv_destroy_policy_rules,
17367 .create_def_policy = flow_dv_create_def_policy,
17368 .destroy_def_policy = flow_dv_destroy_def_policy,
17369 .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
17370 .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
17371 .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
17372 .counter_alloc = flow_dv_counter_allocate,
17373 .counter_free = flow_dv_counter_free,
17374 .counter_query = flow_dv_counter_query,
17375 .get_aged_flows = flow_get_aged_flows,
17376 .action_validate = flow_dv_action_validate,
17377 .action_create = flow_dv_action_create,
17378 .action_destroy = flow_dv_action_destroy,
17379 .action_update = flow_dv_action_update,
17380 .action_query = flow_dv_action_query,
17381 .sync_domain = flow_dv_sync_domain,
17384 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */