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>
27 #include <mlx5_glue.h>
28 #include <mlx5_devx_cmds.h>
30 #include <mlx5_malloc.h>
32 #include "mlx5_defs.h"
34 #include "mlx5_common_os.h"
35 #include "mlx5_flow.h"
36 #include "mlx5_flow_os.h"
39 #include "rte_pmd_mlx5.h"
41 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
43 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
44 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
47 #ifndef HAVE_MLX5DV_DR_ESWITCH
48 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
49 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
53 #ifndef HAVE_MLX5DV_DR
54 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
57 /* VLAN header definitions */
58 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
59 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
60 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
61 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
62 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
77 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
78 struct mlx5_flow_tbl_resource *tbl);
81 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
82 uint32_t encap_decap_idx);
85 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
88 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss);
91 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
95 * Initialize flow attributes structure according to flow items' types.
97 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
98 * mode. For tunnel mode, the items to be modified are the outermost ones.
101 * Pointer to item specification.
103 * Pointer to flow attributes structure.
104 * @param[in] dev_flow
105 * Pointer to the sub flow.
106 * @param[in] tunnel_decap
107 * Whether action is after tunnel decapsulation.
110 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
111 struct mlx5_flow *dev_flow, bool tunnel_decap)
113 uint64_t layers = dev_flow->handle->layers;
116 * If layers is already initialized, it means this dev_flow is the
117 * suffix flow, the layers flags is set by the prefix flow. Need to
118 * use the layer flags from prefix flow as the suffix flow may not
119 * have the user defined items as the flow is split.
122 if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
124 else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
126 if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
128 else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
133 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
134 uint8_t next_protocol = 0xff;
135 switch (item->type) {
136 case RTE_FLOW_ITEM_TYPE_GRE:
137 case RTE_FLOW_ITEM_TYPE_NVGRE:
138 case RTE_FLOW_ITEM_TYPE_VXLAN:
139 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
140 case RTE_FLOW_ITEM_TYPE_GENEVE:
141 case RTE_FLOW_ITEM_TYPE_MPLS:
145 case RTE_FLOW_ITEM_TYPE_IPV4:
148 if (item->mask != NULL &&
149 ((const struct rte_flow_item_ipv4 *)
150 item->mask)->hdr.next_proto_id)
152 ((const struct rte_flow_item_ipv4 *)
153 (item->spec))->hdr.next_proto_id &
154 ((const struct rte_flow_item_ipv4 *)
155 (item->mask))->hdr.next_proto_id;
156 if ((next_protocol == IPPROTO_IPIP ||
157 next_protocol == IPPROTO_IPV6) && tunnel_decap)
160 case RTE_FLOW_ITEM_TYPE_IPV6:
163 if (item->mask != NULL &&
164 ((const struct rte_flow_item_ipv6 *)
165 item->mask)->hdr.proto)
167 ((const struct rte_flow_item_ipv6 *)
168 (item->spec))->hdr.proto &
169 ((const struct rte_flow_item_ipv6 *)
170 (item->mask))->hdr.proto;
171 if ((next_protocol == IPPROTO_IPIP ||
172 next_protocol == IPPROTO_IPV6) && tunnel_decap)
175 case RTE_FLOW_ITEM_TYPE_UDP:
179 case RTE_FLOW_ITEM_TYPE_TCP:
191 * Convert rte_mtr_color to mlx5 color.
200 rte_col_2_mlx5_col(enum rte_color rcol)
203 case RTE_COLOR_GREEN:
204 return MLX5_FLOW_COLOR_GREEN;
205 case RTE_COLOR_YELLOW:
206 return MLX5_FLOW_COLOR_YELLOW;
208 return MLX5_FLOW_COLOR_RED;
212 return MLX5_FLOW_COLOR_UNDEFINED;
215 struct field_modify_info {
216 uint32_t size; /* Size of field in protocol header, in bytes. */
217 uint32_t offset; /* Offset of field in protocol header, in bytes. */
218 enum mlx5_modification_field id;
221 struct field_modify_info modify_eth[] = {
222 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
223 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
224 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
225 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
229 struct field_modify_info modify_vlan_out_first_vid[] = {
230 /* Size in bits !!! */
231 {12, 0, MLX5_MODI_OUT_FIRST_VID},
235 struct field_modify_info modify_ipv4[] = {
236 {1, 1, MLX5_MODI_OUT_IP_DSCP},
237 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
238 {4, 12, MLX5_MODI_OUT_SIPV4},
239 {4, 16, MLX5_MODI_OUT_DIPV4},
243 struct field_modify_info modify_ipv6[] = {
244 {1, 0, MLX5_MODI_OUT_IP_DSCP},
245 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
246 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
247 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
248 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
249 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
250 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
251 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
252 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
253 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
257 struct field_modify_info modify_udp[] = {
258 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
259 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
263 struct field_modify_info modify_tcp[] = {
264 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
265 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
266 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
267 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
271 static const struct rte_flow_item *
272 mlx5_flow_find_tunnel_item(const struct rte_flow_item *item)
274 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
275 switch (item->type) {
278 case RTE_FLOW_ITEM_TYPE_VXLAN:
279 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
280 case RTE_FLOW_ITEM_TYPE_GRE:
281 case RTE_FLOW_ITEM_TYPE_MPLS:
282 case RTE_FLOW_ITEM_TYPE_NVGRE:
283 case RTE_FLOW_ITEM_TYPE_GENEVE:
285 case RTE_FLOW_ITEM_TYPE_IPV4:
286 case RTE_FLOW_ITEM_TYPE_IPV6:
287 if (item[1].type == RTE_FLOW_ITEM_TYPE_IPV4 ||
288 item[1].type == RTE_FLOW_ITEM_TYPE_IPV6)
297 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
298 uint8_t next_protocol, uint64_t *item_flags,
301 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
302 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
303 if (next_protocol == IPPROTO_IPIP) {
304 *item_flags |= MLX5_FLOW_LAYER_IPIP;
307 if (next_protocol == IPPROTO_IPV6) {
308 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
313 /* Update VLAN's VID/PCP based on input rte_flow_action.
316 * Pointer to struct rte_flow_action.
318 * Pointer to struct rte_vlan_hdr.
321 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
322 struct rte_vlan_hdr *vlan)
325 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
327 ((const struct rte_flow_action_of_set_vlan_pcp *)
328 action->conf)->vlan_pcp;
329 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
330 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
331 vlan->vlan_tci |= vlan_tci;
332 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
333 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
334 vlan->vlan_tci |= rte_be_to_cpu_16
335 (((const struct rte_flow_action_of_set_vlan_vid *)
336 action->conf)->vlan_vid);
341 * Fetch 1, 2, 3 or 4 byte field from the byte array
342 * and return as unsigned integer in host-endian format.
345 * Pointer to data array.
347 * Size of field to extract.
350 * converted field in host endian format.
352 static inline uint32_t
353 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
362 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
365 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
366 ret = (ret << 8) | *(data + sizeof(uint16_t));
369 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
380 * Convert modify-header action to DV specification.
382 * Data length of each action is determined by provided field description
383 * and the item mask. Data bit offset and width of each action is determined
384 * by provided item mask.
387 * Pointer to item specification.
389 * Pointer to field modification information.
390 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
391 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
392 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
394 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
395 * Negative offset value sets the same offset as source offset.
396 * size field is ignored, value is taken from source field.
397 * @param[in,out] resource
398 * Pointer to the modify-header resource.
400 * Type of modification.
402 * Pointer to the error structure.
405 * 0 on success, a negative errno value otherwise and rte_errno is set.
408 flow_dv_convert_modify_action(struct rte_flow_item *item,
409 struct field_modify_info *field,
410 struct field_modify_info *dcopy,
411 struct mlx5_flow_dv_modify_hdr_resource *resource,
412 uint32_t type, struct rte_flow_error *error)
414 uint32_t i = resource->actions_num;
415 struct mlx5_modification_cmd *actions = resource->actions;
418 * The item and mask are provided in big-endian format.
419 * The fields should be presented as in big-endian format either.
420 * Mask must be always present, it defines the actual field width.
422 MLX5_ASSERT(item->mask);
423 MLX5_ASSERT(field->size);
430 if (i >= MLX5_MAX_MODIFY_NUM)
431 return rte_flow_error_set(error, EINVAL,
432 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
433 "too many items to modify");
434 /* Fetch variable byte size mask from the array. */
435 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
436 field->offset, field->size);
441 /* Deduce actual data width in bits from mask value. */
442 off_b = rte_bsf32(mask);
443 size_b = sizeof(uint32_t) * CHAR_BIT -
444 off_b - __builtin_clz(mask);
446 size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
447 actions[i] = (struct mlx5_modification_cmd) {
453 /* Convert entire record to expected big-endian format. */
454 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
455 if (type == MLX5_MODIFICATION_TYPE_COPY) {
457 actions[i].dst_field = dcopy->id;
458 actions[i].dst_offset =
459 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
460 /* Convert entire record to big-endian format. */
461 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
464 MLX5_ASSERT(item->spec);
465 data = flow_dv_fetch_field((const uint8_t *)item->spec +
466 field->offset, field->size);
467 /* Shift out the trailing masked bits from data. */
468 data = (data & mask) >> off_b;
469 actions[i].data1 = rte_cpu_to_be_32(data);
473 } while (field->size);
474 if (resource->actions_num == i)
475 return rte_flow_error_set(error, EINVAL,
476 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
477 "invalid modification flow item");
478 resource->actions_num = i;
483 * Convert modify-header set IPv4 address action to DV specification.
485 * @param[in,out] resource
486 * Pointer to the modify-header resource.
488 * Pointer to action specification.
490 * Pointer to the error structure.
493 * 0 on success, a negative errno value otherwise and rte_errno is set.
496 flow_dv_convert_action_modify_ipv4
497 (struct mlx5_flow_dv_modify_hdr_resource *resource,
498 const struct rte_flow_action *action,
499 struct rte_flow_error *error)
501 const struct rte_flow_action_set_ipv4 *conf =
502 (const struct rte_flow_action_set_ipv4 *)(action->conf);
503 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
504 struct rte_flow_item_ipv4 ipv4;
505 struct rte_flow_item_ipv4 ipv4_mask;
507 memset(&ipv4, 0, sizeof(ipv4));
508 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
509 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
510 ipv4.hdr.src_addr = conf->ipv4_addr;
511 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
513 ipv4.hdr.dst_addr = conf->ipv4_addr;
514 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
517 item.mask = &ipv4_mask;
518 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
519 MLX5_MODIFICATION_TYPE_SET, error);
523 * Convert modify-header set IPv6 address action to DV specification.
525 * @param[in,out] resource
526 * Pointer to the modify-header resource.
528 * Pointer to action specification.
530 * Pointer to the error structure.
533 * 0 on success, a negative errno value otherwise and rte_errno is set.
536 flow_dv_convert_action_modify_ipv6
537 (struct mlx5_flow_dv_modify_hdr_resource *resource,
538 const struct rte_flow_action *action,
539 struct rte_flow_error *error)
541 const struct rte_flow_action_set_ipv6 *conf =
542 (const struct rte_flow_action_set_ipv6 *)(action->conf);
543 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
544 struct rte_flow_item_ipv6 ipv6;
545 struct rte_flow_item_ipv6 ipv6_mask;
547 memset(&ipv6, 0, sizeof(ipv6));
548 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
549 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
550 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
551 sizeof(ipv6.hdr.src_addr));
552 memcpy(&ipv6_mask.hdr.src_addr,
553 &rte_flow_item_ipv6_mask.hdr.src_addr,
554 sizeof(ipv6.hdr.src_addr));
556 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
557 sizeof(ipv6.hdr.dst_addr));
558 memcpy(&ipv6_mask.hdr.dst_addr,
559 &rte_flow_item_ipv6_mask.hdr.dst_addr,
560 sizeof(ipv6.hdr.dst_addr));
563 item.mask = &ipv6_mask;
564 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
565 MLX5_MODIFICATION_TYPE_SET, error);
569 * Convert modify-header set MAC address action to DV specification.
571 * @param[in,out] resource
572 * Pointer to the modify-header resource.
574 * Pointer to action specification.
576 * Pointer to the error structure.
579 * 0 on success, a negative errno value otherwise and rte_errno is set.
582 flow_dv_convert_action_modify_mac
583 (struct mlx5_flow_dv_modify_hdr_resource *resource,
584 const struct rte_flow_action *action,
585 struct rte_flow_error *error)
587 const struct rte_flow_action_set_mac *conf =
588 (const struct rte_flow_action_set_mac *)(action->conf);
589 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
590 struct rte_flow_item_eth eth;
591 struct rte_flow_item_eth eth_mask;
593 memset(ð, 0, sizeof(eth));
594 memset(ð_mask, 0, sizeof(eth_mask));
595 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
596 memcpy(ð.src.addr_bytes, &conf->mac_addr,
597 sizeof(eth.src.addr_bytes));
598 memcpy(ð_mask.src.addr_bytes,
599 &rte_flow_item_eth_mask.src.addr_bytes,
600 sizeof(eth_mask.src.addr_bytes));
602 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
603 sizeof(eth.dst.addr_bytes));
604 memcpy(ð_mask.dst.addr_bytes,
605 &rte_flow_item_eth_mask.dst.addr_bytes,
606 sizeof(eth_mask.dst.addr_bytes));
609 item.mask = ð_mask;
610 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
611 MLX5_MODIFICATION_TYPE_SET, error);
615 * Convert modify-header set VLAN VID action to DV specification.
617 * @param[in,out] resource
618 * Pointer to the modify-header resource.
620 * Pointer to action specification.
622 * Pointer to the error structure.
625 * 0 on success, a negative errno value otherwise and rte_errno is set.
628 flow_dv_convert_action_modify_vlan_vid
629 (struct mlx5_flow_dv_modify_hdr_resource *resource,
630 const struct rte_flow_action *action,
631 struct rte_flow_error *error)
633 const struct rte_flow_action_of_set_vlan_vid *conf =
634 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
635 int i = resource->actions_num;
636 struct mlx5_modification_cmd *actions = resource->actions;
637 struct field_modify_info *field = modify_vlan_out_first_vid;
639 if (i >= MLX5_MAX_MODIFY_NUM)
640 return rte_flow_error_set(error, EINVAL,
641 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
642 "too many items to modify");
643 actions[i] = (struct mlx5_modification_cmd) {
644 .action_type = MLX5_MODIFICATION_TYPE_SET,
646 .length = field->size,
647 .offset = field->offset,
649 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
650 actions[i].data1 = conf->vlan_vid;
651 actions[i].data1 = actions[i].data1 << 16;
652 resource->actions_num = ++i;
657 * Convert modify-header set TP action to DV specification.
659 * @param[in,out] resource
660 * Pointer to the modify-header resource.
662 * Pointer to action specification.
664 * Pointer to rte_flow_item objects list.
666 * Pointer to flow attributes structure.
667 * @param[in] dev_flow
668 * Pointer to the sub flow.
669 * @param[in] tunnel_decap
670 * Whether action is after tunnel decapsulation.
672 * Pointer to the error structure.
675 * 0 on success, a negative errno value otherwise and rte_errno is set.
678 flow_dv_convert_action_modify_tp
679 (struct mlx5_flow_dv_modify_hdr_resource *resource,
680 const struct rte_flow_action *action,
681 const struct rte_flow_item *items,
682 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
683 bool tunnel_decap, struct rte_flow_error *error)
685 const struct rte_flow_action_set_tp *conf =
686 (const struct rte_flow_action_set_tp *)(action->conf);
687 struct rte_flow_item item;
688 struct rte_flow_item_udp udp;
689 struct rte_flow_item_udp udp_mask;
690 struct rte_flow_item_tcp tcp;
691 struct rte_flow_item_tcp tcp_mask;
692 struct field_modify_info *field;
695 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
697 memset(&udp, 0, sizeof(udp));
698 memset(&udp_mask, 0, sizeof(udp_mask));
699 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
700 udp.hdr.src_port = conf->port;
701 udp_mask.hdr.src_port =
702 rte_flow_item_udp_mask.hdr.src_port;
704 udp.hdr.dst_port = conf->port;
705 udp_mask.hdr.dst_port =
706 rte_flow_item_udp_mask.hdr.dst_port;
708 item.type = RTE_FLOW_ITEM_TYPE_UDP;
710 item.mask = &udp_mask;
713 MLX5_ASSERT(attr->tcp);
714 memset(&tcp, 0, sizeof(tcp));
715 memset(&tcp_mask, 0, sizeof(tcp_mask));
716 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
717 tcp.hdr.src_port = conf->port;
718 tcp_mask.hdr.src_port =
719 rte_flow_item_tcp_mask.hdr.src_port;
721 tcp.hdr.dst_port = conf->port;
722 tcp_mask.hdr.dst_port =
723 rte_flow_item_tcp_mask.hdr.dst_port;
725 item.type = RTE_FLOW_ITEM_TYPE_TCP;
727 item.mask = &tcp_mask;
730 return flow_dv_convert_modify_action(&item, field, NULL, resource,
731 MLX5_MODIFICATION_TYPE_SET, error);
735 * Convert modify-header set TTL action to DV specification.
737 * @param[in,out] resource
738 * Pointer to the modify-header resource.
740 * Pointer to action specification.
742 * Pointer to rte_flow_item objects list.
744 * Pointer to flow attributes structure.
745 * @param[in] dev_flow
746 * Pointer to the sub flow.
747 * @param[in] tunnel_decap
748 * Whether action is after tunnel decapsulation.
750 * Pointer to the error structure.
753 * 0 on success, a negative errno value otherwise and rte_errno is set.
756 flow_dv_convert_action_modify_ttl
757 (struct mlx5_flow_dv_modify_hdr_resource *resource,
758 const struct rte_flow_action *action,
759 const struct rte_flow_item *items,
760 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
761 bool tunnel_decap, struct rte_flow_error *error)
763 const struct rte_flow_action_set_ttl *conf =
764 (const struct rte_flow_action_set_ttl *)(action->conf);
765 struct rte_flow_item item;
766 struct rte_flow_item_ipv4 ipv4;
767 struct rte_flow_item_ipv4 ipv4_mask;
768 struct rte_flow_item_ipv6 ipv6;
769 struct rte_flow_item_ipv6 ipv6_mask;
770 struct field_modify_info *field;
773 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
775 memset(&ipv4, 0, sizeof(ipv4));
776 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
777 ipv4.hdr.time_to_live = conf->ttl_value;
778 ipv4_mask.hdr.time_to_live = 0xFF;
779 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
781 item.mask = &ipv4_mask;
784 MLX5_ASSERT(attr->ipv6);
785 memset(&ipv6, 0, sizeof(ipv6));
786 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
787 ipv6.hdr.hop_limits = conf->ttl_value;
788 ipv6_mask.hdr.hop_limits = 0xFF;
789 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
791 item.mask = &ipv6_mask;
794 return flow_dv_convert_modify_action(&item, field, NULL, resource,
795 MLX5_MODIFICATION_TYPE_SET, error);
799 * Convert modify-header decrement TTL action to DV specification.
801 * @param[in,out] resource
802 * Pointer to the modify-header resource.
804 * Pointer to action specification.
806 * Pointer to rte_flow_item objects list.
808 * Pointer to flow attributes structure.
809 * @param[in] dev_flow
810 * Pointer to the sub flow.
811 * @param[in] tunnel_decap
812 * Whether action is after tunnel decapsulation.
814 * Pointer to the error structure.
817 * 0 on success, a negative errno value otherwise and rte_errno is set.
820 flow_dv_convert_action_modify_dec_ttl
821 (struct mlx5_flow_dv_modify_hdr_resource *resource,
822 const struct rte_flow_item *items,
823 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
824 bool tunnel_decap, struct rte_flow_error *error)
826 struct rte_flow_item item;
827 struct rte_flow_item_ipv4 ipv4;
828 struct rte_flow_item_ipv4 ipv4_mask;
829 struct rte_flow_item_ipv6 ipv6;
830 struct rte_flow_item_ipv6 ipv6_mask;
831 struct field_modify_info *field;
834 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
836 memset(&ipv4, 0, sizeof(ipv4));
837 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
838 ipv4.hdr.time_to_live = 0xFF;
839 ipv4_mask.hdr.time_to_live = 0xFF;
840 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
842 item.mask = &ipv4_mask;
845 MLX5_ASSERT(attr->ipv6);
846 memset(&ipv6, 0, sizeof(ipv6));
847 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
848 ipv6.hdr.hop_limits = 0xFF;
849 ipv6_mask.hdr.hop_limits = 0xFF;
850 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
852 item.mask = &ipv6_mask;
855 return flow_dv_convert_modify_action(&item, field, NULL, resource,
856 MLX5_MODIFICATION_TYPE_ADD, error);
860 * Convert modify-header increment/decrement TCP Sequence number
861 * to DV specification.
863 * @param[in,out] resource
864 * Pointer to the modify-header resource.
866 * Pointer to action specification.
868 * Pointer to the error structure.
871 * 0 on success, a negative errno value otherwise and rte_errno is set.
874 flow_dv_convert_action_modify_tcp_seq
875 (struct mlx5_flow_dv_modify_hdr_resource *resource,
876 const struct rte_flow_action *action,
877 struct rte_flow_error *error)
879 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
880 uint64_t value = rte_be_to_cpu_32(*conf);
881 struct rte_flow_item item;
882 struct rte_flow_item_tcp tcp;
883 struct rte_flow_item_tcp tcp_mask;
885 memset(&tcp, 0, sizeof(tcp));
886 memset(&tcp_mask, 0, sizeof(tcp_mask));
887 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
889 * The HW has no decrement operation, only increment operation.
890 * To simulate decrement X from Y using increment operation
891 * we need to add UINT32_MAX X times to Y.
892 * Each adding of UINT32_MAX decrements Y by 1.
895 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
896 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
897 item.type = RTE_FLOW_ITEM_TYPE_TCP;
899 item.mask = &tcp_mask;
900 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
901 MLX5_MODIFICATION_TYPE_ADD, error);
905 * Convert modify-header increment/decrement TCP Acknowledgment number
906 * to DV specification.
908 * @param[in,out] resource
909 * Pointer to the modify-header resource.
911 * Pointer to action specification.
913 * Pointer to the error structure.
916 * 0 on success, a negative errno value otherwise and rte_errno is set.
919 flow_dv_convert_action_modify_tcp_ack
920 (struct mlx5_flow_dv_modify_hdr_resource *resource,
921 const struct rte_flow_action *action,
922 struct rte_flow_error *error)
924 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
925 uint64_t value = rte_be_to_cpu_32(*conf);
926 struct rte_flow_item item;
927 struct rte_flow_item_tcp tcp;
928 struct rte_flow_item_tcp tcp_mask;
930 memset(&tcp, 0, sizeof(tcp));
931 memset(&tcp_mask, 0, sizeof(tcp_mask));
932 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
934 * The HW has no decrement operation, only increment operation.
935 * To simulate decrement X from Y using increment operation
936 * we need to add UINT32_MAX X times to Y.
937 * Each adding of UINT32_MAX decrements Y by 1.
940 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
941 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
942 item.type = RTE_FLOW_ITEM_TYPE_TCP;
944 item.mask = &tcp_mask;
945 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
946 MLX5_MODIFICATION_TYPE_ADD, error);
949 static enum mlx5_modification_field reg_to_field[] = {
950 [REG_NON] = MLX5_MODI_OUT_NONE,
951 [REG_A] = MLX5_MODI_META_DATA_REG_A,
952 [REG_B] = MLX5_MODI_META_DATA_REG_B,
953 [REG_C_0] = MLX5_MODI_META_REG_C_0,
954 [REG_C_1] = MLX5_MODI_META_REG_C_1,
955 [REG_C_2] = MLX5_MODI_META_REG_C_2,
956 [REG_C_3] = MLX5_MODI_META_REG_C_3,
957 [REG_C_4] = MLX5_MODI_META_REG_C_4,
958 [REG_C_5] = MLX5_MODI_META_REG_C_5,
959 [REG_C_6] = MLX5_MODI_META_REG_C_6,
960 [REG_C_7] = MLX5_MODI_META_REG_C_7,
964 * Convert register set to DV specification.
966 * @param[in,out] resource
967 * Pointer to the modify-header resource.
969 * Pointer to action specification.
971 * Pointer to the error structure.
974 * 0 on success, a negative errno value otherwise and rte_errno is set.
977 flow_dv_convert_action_set_reg
978 (struct mlx5_flow_dv_modify_hdr_resource *resource,
979 const struct rte_flow_action *action,
980 struct rte_flow_error *error)
982 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
983 struct mlx5_modification_cmd *actions = resource->actions;
984 uint32_t i = resource->actions_num;
986 if (i >= MLX5_MAX_MODIFY_NUM)
987 return rte_flow_error_set(error, EINVAL,
988 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
989 "too many items to modify");
990 MLX5_ASSERT(conf->id != REG_NON);
991 MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
992 actions[i] = (struct mlx5_modification_cmd) {
993 .action_type = MLX5_MODIFICATION_TYPE_SET,
994 .field = reg_to_field[conf->id],
995 .offset = conf->offset,
996 .length = conf->length,
998 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
999 actions[i].data1 = rte_cpu_to_be_32(conf->data);
1001 resource->actions_num = i;
1006 * Convert SET_TAG action to DV specification.
1009 * Pointer to the rte_eth_dev structure.
1010 * @param[in,out] resource
1011 * Pointer to the modify-header resource.
1013 * Pointer to action specification.
1015 * Pointer to the error structure.
1018 * 0 on success, a negative errno value otherwise and rte_errno is set.
1021 flow_dv_convert_action_set_tag
1022 (struct rte_eth_dev *dev,
1023 struct mlx5_flow_dv_modify_hdr_resource *resource,
1024 const struct rte_flow_action_set_tag *conf,
1025 struct rte_flow_error *error)
1027 rte_be32_t data = rte_cpu_to_be_32(conf->data);
1028 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1029 struct rte_flow_item item = {
1033 struct field_modify_info reg_c_x[] = {
1036 enum mlx5_modification_field reg_type;
1039 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1042 MLX5_ASSERT(ret != REG_NON);
1043 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1044 reg_type = reg_to_field[ret];
1045 MLX5_ASSERT(reg_type > 0);
1046 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1047 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1048 MLX5_MODIFICATION_TYPE_SET, error);
1052 * Convert internal COPY_REG action to DV specification.
1055 * Pointer to the rte_eth_dev structure.
1056 * @param[in,out] res
1057 * Pointer to the modify-header resource.
1059 * Pointer to action specification.
1061 * Pointer to the error structure.
1064 * 0 on success, a negative errno value otherwise and rte_errno is set.
1067 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1068 struct mlx5_flow_dv_modify_hdr_resource *res,
1069 const struct rte_flow_action *action,
1070 struct rte_flow_error *error)
1072 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1073 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1074 struct rte_flow_item item = {
1078 struct field_modify_info reg_src[] = {
1079 {4, 0, reg_to_field[conf->src]},
1082 struct field_modify_info reg_dst = {
1084 .id = reg_to_field[conf->dst],
1086 /* Adjust reg_c[0] usage according to reported mask. */
1087 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1088 struct mlx5_priv *priv = dev->data->dev_private;
1089 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1091 MLX5_ASSERT(reg_c0);
1092 MLX5_ASSERT(priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1093 if (conf->dst == REG_C_0) {
1094 /* Copy to reg_c[0], within mask only. */
1095 reg_dst.offset = rte_bsf32(reg_c0);
1097 * Mask is ignoring the enianness, because
1098 * there is no conversion in datapath.
1100 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1101 /* Copy from destination lower bits to reg_c[0]. */
1102 mask = reg_c0 >> reg_dst.offset;
1104 /* Copy from destination upper bits to reg_c[0]. */
1105 mask = reg_c0 << (sizeof(reg_c0) * CHAR_BIT -
1106 rte_fls_u32(reg_c0));
1109 mask = rte_cpu_to_be_32(reg_c0);
1110 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1111 /* Copy from reg_c[0] to destination lower bits. */
1114 /* Copy from reg_c[0] to destination upper bits. */
1115 reg_dst.offset = sizeof(reg_c0) * CHAR_BIT -
1116 (rte_fls_u32(reg_c0) -
1121 return flow_dv_convert_modify_action(&item,
1122 reg_src, ®_dst, res,
1123 MLX5_MODIFICATION_TYPE_COPY,
1128 * Convert MARK action to DV specification. This routine is used
1129 * in extensive metadata only and requires metadata register to be
1130 * handled. In legacy mode hardware tag resource is engaged.
1133 * Pointer to the rte_eth_dev structure.
1135 * Pointer to MARK action specification.
1136 * @param[in,out] resource
1137 * Pointer to the modify-header resource.
1139 * Pointer to the error structure.
1142 * 0 on success, a negative errno value otherwise and rte_errno is set.
1145 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1146 const struct rte_flow_action_mark *conf,
1147 struct mlx5_flow_dv_modify_hdr_resource *resource,
1148 struct rte_flow_error *error)
1150 struct mlx5_priv *priv = dev->data->dev_private;
1151 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1152 priv->sh->dv_mark_mask);
1153 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1154 struct rte_flow_item item = {
1158 struct field_modify_info reg_c_x[] = {
1164 return rte_flow_error_set(error, EINVAL,
1165 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1166 NULL, "zero mark action mask");
1167 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1170 MLX5_ASSERT(reg > 0);
1171 if (reg == REG_C_0) {
1172 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1173 uint32_t shl_c0 = rte_bsf32(msk_c0);
1175 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1176 mask = rte_cpu_to_be_32(mask) & msk_c0;
1177 mask = rte_cpu_to_be_32(mask << shl_c0);
1179 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1180 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1181 MLX5_MODIFICATION_TYPE_SET, error);
1185 * Get metadata register index for specified steering domain.
1188 * Pointer to the rte_eth_dev structure.
1190 * Attributes of flow to determine steering domain.
1192 * Pointer to the error structure.
1195 * positive index on success, a negative errno value otherwise
1196 * and rte_errno is set.
1198 static enum modify_reg
1199 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1200 const struct rte_flow_attr *attr,
1201 struct rte_flow_error *error)
1204 mlx5_flow_get_reg_id(dev, attr->transfer ?
1208 MLX5_METADATA_RX, 0, error);
1210 return rte_flow_error_set(error,
1211 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1212 NULL, "unavailable "
1213 "metadata register");
1218 * Convert SET_META action to DV specification.
1221 * Pointer to the rte_eth_dev structure.
1222 * @param[in,out] resource
1223 * Pointer to the modify-header resource.
1225 * Attributes of flow that includes this item.
1227 * Pointer to action specification.
1229 * Pointer to the error structure.
1232 * 0 on success, a negative errno value otherwise and rte_errno is set.
1235 flow_dv_convert_action_set_meta
1236 (struct rte_eth_dev *dev,
1237 struct mlx5_flow_dv_modify_hdr_resource *resource,
1238 const struct rte_flow_attr *attr,
1239 const struct rte_flow_action_set_meta *conf,
1240 struct rte_flow_error *error)
1242 uint32_t data = conf->data;
1243 uint32_t mask = conf->mask;
1244 struct rte_flow_item item = {
1248 struct field_modify_info reg_c_x[] = {
1251 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1255 MLX5_ASSERT(reg != REG_NON);
1257 * In datapath code there is no endianness
1258 * coversions for perfromance reasons, all
1259 * pattern conversions are done in rte_flow.
1261 if (reg == REG_C_0) {
1262 struct mlx5_priv *priv = dev->data->dev_private;
1263 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1266 MLX5_ASSERT(msk_c0);
1267 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1268 shl_c0 = rte_bsf32(msk_c0);
1270 shl_c0 = sizeof(msk_c0) * CHAR_BIT - rte_fls_u32(msk_c0);
1274 MLX5_ASSERT(!(~msk_c0 & rte_cpu_to_be_32(mask)));
1276 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1277 /* The routine expects parameters in memory as big-endian ones. */
1278 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1279 MLX5_MODIFICATION_TYPE_SET, error);
1283 * Convert modify-header set IPv4 DSCP action to DV specification.
1285 * @param[in,out] resource
1286 * Pointer to the modify-header resource.
1288 * Pointer to action specification.
1290 * Pointer to the error structure.
1293 * 0 on success, a negative errno value otherwise and rte_errno is set.
1296 flow_dv_convert_action_modify_ipv4_dscp
1297 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1298 const struct rte_flow_action *action,
1299 struct rte_flow_error *error)
1301 const struct rte_flow_action_set_dscp *conf =
1302 (const struct rte_flow_action_set_dscp *)(action->conf);
1303 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1304 struct rte_flow_item_ipv4 ipv4;
1305 struct rte_flow_item_ipv4 ipv4_mask;
1307 memset(&ipv4, 0, sizeof(ipv4));
1308 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1309 ipv4.hdr.type_of_service = conf->dscp;
1310 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1312 item.mask = &ipv4_mask;
1313 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1314 MLX5_MODIFICATION_TYPE_SET, error);
1318 * Convert modify-header set IPv6 DSCP action to DV specification.
1320 * @param[in,out] resource
1321 * Pointer to the modify-header resource.
1323 * Pointer to action specification.
1325 * Pointer to the error structure.
1328 * 0 on success, a negative errno value otherwise and rte_errno is set.
1331 flow_dv_convert_action_modify_ipv6_dscp
1332 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1333 const struct rte_flow_action *action,
1334 struct rte_flow_error *error)
1336 const struct rte_flow_action_set_dscp *conf =
1337 (const struct rte_flow_action_set_dscp *)(action->conf);
1338 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1339 struct rte_flow_item_ipv6 ipv6;
1340 struct rte_flow_item_ipv6 ipv6_mask;
1342 memset(&ipv6, 0, sizeof(ipv6));
1343 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1345 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1346 * rdma-core only accept the DSCP bits byte aligned start from
1347 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1348 * bits in IPv6 case as rdma-core requires byte aligned value.
1350 ipv6.hdr.vtc_flow = conf->dscp;
1351 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1353 item.mask = &ipv6_mask;
1354 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1355 MLX5_MODIFICATION_TYPE_SET, error);
1359 mlx5_flow_item_field_width(enum rte_flow_field_id field)
1362 case RTE_FLOW_FIELD_START:
1364 case RTE_FLOW_FIELD_MAC_DST:
1365 case RTE_FLOW_FIELD_MAC_SRC:
1367 case RTE_FLOW_FIELD_VLAN_TYPE:
1369 case RTE_FLOW_FIELD_VLAN_ID:
1371 case RTE_FLOW_FIELD_MAC_TYPE:
1373 case RTE_FLOW_FIELD_IPV4_DSCP:
1375 case RTE_FLOW_FIELD_IPV4_TTL:
1377 case RTE_FLOW_FIELD_IPV4_SRC:
1378 case RTE_FLOW_FIELD_IPV4_DST:
1380 case RTE_FLOW_FIELD_IPV6_DSCP:
1382 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1384 case RTE_FLOW_FIELD_IPV6_SRC:
1385 case RTE_FLOW_FIELD_IPV6_DST:
1387 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1388 case RTE_FLOW_FIELD_TCP_PORT_DST:
1390 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1391 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1393 case RTE_FLOW_FIELD_TCP_FLAGS:
1395 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1396 case RTE_FLOW_FIELD_UDP_PORT_DST:
1398 case RTE_FLOW_FIELD_VXLAN_VNI:
1399 case RTE_FLOW_FIELD_GENEVE_VNI:
1401 case RTE_FLOW_FIELD_GTP_TEID:
1402 case RTE_FLOW_FIELD_TAG:
1404 case RTE_FLOW_FIELD_MARK:
1406 case RTE_FLOW_FIELD_META:
1408 case RTE_FLOW_FIELD_POINTER:
1409 case RTE_FLOW_FIELD_VALUE:
1418 mlx5_flow_field_id_to_modify_info
1419 (const struct rte_flow_action_modify_data *data,
1420 struct field_modify_info *info,
1421 uint32_t *mask, uint32_t *value,
1422 uint32_t width, uint32_t dst_width,
1423 struct rte_eth_dev *dev,
1424 const struct rte_flow_attr *attr,
1425 struct rte_flow_error *error)
1429 switch (data->field) {
1430 case RTE_FLOW_FIELD_START:
1431 /* not supported yet */
1434 case RTE_FLOW_FIELD_MAC_DST:
1436 if (data->offset < 32) {
1437 info[idx] = (struct field_modify_info){4, 0,
1438 MLX5_MODI_OUT_DMAC_47_16};
1441 rte_cpu_to_be_32(0xffffffff >>
1445 mask[idx] = RTE_BE32(0xffffffff);
1452 info[idx] = (struct field_modify_info){2, 4 * idx,
1453 MLX5_MODI_OUT_DMAC_15_0};
1454 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1456 if (data->offset < 32)
1457 info[idx++] = (struct field_modify_info){4, 0,
1458 MLX5_MODI_OUT_DMAC_47_16};
1459 info[idx] = (struct field_modify_info){2, 0,
1460 MLX5_MODI_OUT_DMAC_15_0};
1463 case RTE_FLOW_FIELD_MAC_SRC:
1465 if (data->offset < 32) {
1466 info[idx] = (struct field_modify_info){4, 0,
1467 MLX5_MODI_OUT_SMAC_47_16};
1470 rte_cpu_to_be_32(0xffffffff >>
1474 mask[idx] = RTE_BE32(0xffffffff);
1481 info[idx] = (struct field_modify_info){2, 4 * idx,
1482 MLX5_MODI_OUT_SMAC_15_0};
1483 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1485 if (data->offset < 32)
1486 info[idx++] = (struct field_modify_info){4, 0,
1487 MLX5_MODI_OUT_SMAC_47_16};
1488 info[idx] = (struct field_modify_info){2, 0,
1489 MLX5_MODI_OUT_SMAC_15_0};
1492 case RTE_FLOW_FIELD_VLAN_TYPE:
1493 /* not supported yet */
1495 case RTE_FLOW_FIELD_VLAN_ID:
1496 info[idx] = (struct field_modify_info){2, 0,
1497 MLX5_MODI_OUT_FIRST_VID};
1499 mask[idx] = rte_cpu_to_be_16(0x0fff >> (12 - width));
1501 case RTE_FLOW_FIELD_MAC_TYPE:
1502 info[idx] = (struct field_modify_info){2, 0,
1503 MLX5_MODI_OUT_ETHERTYPE};
1505 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1507 case RTE_FLOW_FIELD_IPV4_DSCP:
1508 info[idx] = (struct field_modify_info){1, 0,
1509 MLX5_MODI_OUT_IP_DSCP};
1511 mask[idx] = 0x3f >> (6 - width);
1513 case RTE_FLOW_FIELD_IPV4_TTL:
1514 info[idx] = (struct field_modify_info){1, 0,
1515 MLX5_MODI_OUT_IPV4_TTL};
1517 mask[idx] = 0xff >> (8 - width);
1519 case RTE_FLOW_FIELD_IPV4_SRC:
1520 info[idx] = (struct field_modify_info){4, 0,
1521 MLX5_MODI_OUT_SIPV4};
1523 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1526 case RTE_FLOW_FIELD_IPV4_DST:
1527 info[idx] = (struct field_modify_info){4, 0,
1528 MLX5_MODI_OUT_DIPV4};
1530 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1533 case RTE_FLOW_FIELD_IPV6_DSCP:
1534 info[idx] = (struct field_modify_info){1, 0,
1535 MLX5_MODI_OUT_IP_DSCP};
1537 mask[idx] = 0x3f >> (6 - width);
1539 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1540 info[idx] = (struct field_modify_info){1, 0,
1541 MLX5_MODI_OUT_IPV6_HOPLIMIT};
1543 mask[idx] = 0xff >> (8 - width);
1545 case RTE_FLOW_FIELD_IPV6_SRC:
1547 if (data->offset < 32) {
1548 info[idx] = (struct field_modify_info){4,
1550 MLX5_MODI_OUT_SIPV6_31_0};
1553 rte_cpu_to_be_32(0xffffffff >>
1557 mask[idx] = RTE_BE32(0xffffffff);
1564 if (data->offset < 64) {
1565 info[idx] = (struct field_modify_info){4,
1567 MLX5_MODI_OUT_SIPV6_63_32};
1570 rte_cpu_to_be_32(0xffffffff >>
1574 mask[idx] = RTE_BE32(0xffffffff);
1581 if (data->offset < 96) {
1582 info[idx] = (struct field_modify_info){4,
1584 MLX5_MODI_OUT_SIPV6_95_64};
1587 rte_cpu_to_be_32(0xffffffff >>
1591 mask[idx] = RTE_BE32(0xffffffff);
1598 info[idx] = (struct field_modify_info){4, 4 * idx,
1599 MLX5_MODI_OUT_SIPV6_127_96};
1600 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1603 if (data->offset < 32)
1604 info[idx++] = (struct field_modify_info){4, 0,
1605 MLX5_MODI_OUT_SIPV6_31_0};
1606 if (data->offset < 64)
1607 info[idx++] = (struct field_modify_info){4, 0,
1608 MLX5_MODI_OUT_SIPV6_63_32};
1609 if (data->offset < 96)
1610 info[idx++] = (struct field_modify_info){4, 0,
1611 MLX5_MODI_OUT_SIPV6_95_64};
1612 if (data->offset < 128)
1613 info[idx++] = (struct field_modify_info){4, 0,
1614 MLX5_MODI_OUT_SIPV6_127_96};
1617 case RTE_FLOW_FIELD_IPV6_DST:
1619 if (data->offset < 32) {
1620 info[idx] = (struct field_modify_info){4,
1622 MLX5_MODI_OUT_DIPV6_31_0};
1625 rte_cpu_to_be_32(0xffffffff >>
1629 mask[idx] = RTE_BE32(0xffffffff);
1636 if (data->offset < 64) {
1637 info[idx] = (struct field_modify_info){4,
1639 MLX5_MODI_OUT_DIPV6_63_32};
1642 rte_cpu_to_be_32(0xffffffff >>
1646 mask[idx] = RTE_BE32(0xffffffff);
1653 if (data->offset < 96) {
1654 info[idx] = (struct field_modify_info){4,
1656 MLX5_MODI_OUT_DIPV6_95_64};
1659 rte_cpu_to_be_32(0xffffffff >>
1663 mask[idx] = RTE_BE32(0xffffffff);
1670 info[idx] = (struct field_modify_info){4, 4 * idx,
1671 MLX5_MODI_OUT_DIPV6_127_96};
1672 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1675 if (data->offset < 32)
1676 info[idx++] = (struct field_modify_info){4, 0,
1677 MLX5_MODI_OUT_DIPV6_31_0};
1678 if (data->offset < 64)
1679 info[idx++] = (struct field_modify_info){4, 0,
1680 MLX5_MODI_OUT_DIPV6_63_32};
1681 if (data->offset < 96)
1682 info[idx++] = (struct field_modify_info){4, 0,
1683 MLX5_MODI_OUT_DIPV6_95_64};
1684 if (data->offset < 128)
1685 info[idx++] = (struct field_modify_info){4, 0,
1686 MLX5_MODI_OUT_DIPV6_127_96};
1689 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1690 info[idx] = (struct field_modify_info){2, 0,
1691 MLX5_MODI_OUT_TCP_SPORT};
1693 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1695 case RTE_FLOW_FIELD_TCP_PORT_DST:
1696 info[idx] = (struct field_modify_info){2, 0,
1697 MLX5_MODI_OUT_TCP_DPORT};
1699 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1701 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1702 info[idx] = (struct field_modify_info){4, 0,
1703 MLX5_MODI_OUT_TCP_SEQ_NUM};
1705 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1708 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1709 info[idx] = (struct field_modify_info){4, 0,
1710 MLX5_MODI_OUT_TCP_ACK_NUM};
1712 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1715 case RTE_FLOW_FIELD_TCP_FLAGS:
1716 info[idx] = (struct field_modify_info){2, 0,
1717 MLX5_MODI_OUT_TCP_FLAGS};
1719 mask[idx] = rte_cpu_to_be_16(0x1ff >> (9 - width));
1721 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1722 info[idx] = (struct field_modify_info){2, 0,
1723 MLX5_MODI_OUT_UDP_SPORT};
1725 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1727 case RTE_FLOW_FIELD_UDP_PORT_DST:
1728 info[idx] = (struct field_modify_info){2, 0,
1729 MLX5_MODI_OUT_UDP_DPORT};
1731 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1733 case RTE_FLOW_FIELD_VXLAN_VNI:
1734 /* not supported yet */
1736 case RTE_FLOW_FIELD_GENEVE_VNI:
1737 /* not supported yet*/
1739 case RTE_FLOW_FIELD_GTP_TEID:
1740 info[idx] = (struct field_modify_info){4, 0,
1741 MLX5_MODI_GTP_TEID};
1743 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1746 case RTE_FLOW_FIELD_TAG:
1748 int reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
1749 data->level, error);
1752 MLX5_ASSERT(reg != REG_NON);
1753 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1754 info[idx] = (struct field_modify_info){4, 0,
1758 rte_cpu_to_be_32(0xffffffff >>
1762 case RTE_FLOW_FIELD_MARK:
1764 int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
1768 MLX5_ASSERT(reg != REG_NON);
1769 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1770 info[idx] = (struct field_modify_info){4, 0,
1774 rte_cpu_to_be_32(0xffffffff >>
1778 case RTE_FLOW_FIELD_META:
1780 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1783 MLX5_ASSERT(reg != REG_NON);
1784 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1785 info[idx] = (struct field_modify_info){4, 0,
1789 rte_cpu_to_be_32(0xffffffff >>
1793 case RTE_FLOW_FIELD_POINTER:
1794 case RTE_FLOW_FIELD_VALUE:
1795 if (data->field == RTE_FLOW_FIELD_POINTER)
1796 memcpy(&val, (void *)(uintptr_t)data->value,
1800 for (idx = 0; idx < MLX5_ACT_MAX_MOD_FIELDS; idx++) {
1802 if (dst_width > 16) {
1803 value[idx] = rte_cpu_to_be_32(val);
1805 } else if (dst_width > 8) {
1806 value[idx] = rte_cpu_to_be_16(val);
1809 value[idx] = (uint8_t)val;
1824 * Convert modify_field action to DV specification.
1827 * Pointer to the rte_eth_dev structure.
1828 * @param[in,out] resource
1829 * Pointer to the modify-header resource.
1831 * Pointer to action specification.
1833 * Attributes of flow that includes this item.
1835 * Pointer to the error structure.
1838 * 0 on success, a negative errno value otherwise and rte_errno is set.
1841 flow_dv_convert_action_modify_field
1842 (struct rte_eth_dev *dev,
1843 struct mlx5_flow_dv_modify_hdr_resource *resource,
1844 const struct rte_flow_action *action,
1845 const struct rte_flow_attr *attr,
1846 struct rte_flow_error *error)
1848 const struct rte_flow_action_modify_field *conf =
1849 (const struct rte_flow_action_modify_field *)(action->conf);
1850 struct rte_flow_item item;
1851 struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1853 struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1855 uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1856 uint32_t value[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1858 uint32_t dst_width = mlx5_flow_item_field_width(conf->dst.field);
1860 if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1861 conf->src.field == RTE_FLOW_FIELD_VALUE) {
1862 type = MLX5_MODIFICATION_TYPE_SET;
1863 /** For SET fill the destination field (field) first. */
1864 mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1865 value, conf->width, dst_width, dev, attr, error);
1866 /** Then copy immediate value from source as per mask. */
1867 mlx5_flow_field_id_to_modify_info(&conf->src, dcopy, mask,
1868 value, conf->width, dst_width, dev, attr, error);
1871 type = MLX5_MODIFICATION_TYPE_COPY;
1872 /** For COPY fill the destination field (dcopy) without mask. */
1873 mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1874 value, conf->width, dst_width, dev, attr, error);
1875 /** Then construct the source field (field) with mask. */
1876 mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1877 value, conf->width, dst_width, dev, attr, error);
1880 return flow_dv_convert_modify_action(&item,
1881 field, dcopy, resource, type, error);
1885 * Validate MARK item.
1888 * Pointer to the rte_eth_dev structure.
1890 * Item specification.
1892 * Attributes of flow that includes this item.
1894 * Pointer to error structure.
1897 * 0 on success, a negative errno value otherwise and rte_errno is set.
1900 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1901 const struct rte_flow_item *item,
1902 const struct rte_flow_attr *attr __rte_unused,
1903 struct rte_flow_error *error)
1905 struct mlx5_priv *priv = dev->data->dev_private;
1906 struct mlx5_dev_config *config = &priv->config;
1907 const struct rte_flow_item_mark *spec = item->spec;
1908 const struct rte_flow_item_mark *mask = item->mask;
1909 const struct rte_flow_item_mark nic_mask = {
1910 .id = priv->sh->dv_mark_mask,
1914 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1915 return rte_flow_error_set(error, ENOTSUP,
1916 RTE_FLOW_ERROR_TYPE_ITEM, item,
1917 "extended metadata feature"
1919 if (!mlx5_flow_ext_mreg_supported(dev))
1920 return rte_flow_error_set(error, ENOTSUP,
1921 RTE_FLOW_ERROR_TYPE_ITEM, item,
1922 "extended metadata register"
1923 " isn't supported");
1925 return rte_flow_error_set(error, ENOTSUP,
1926 RTE_FLOW_ERROR_TYPE_ITEM, item,
1927 "extended metadata register"
1928 " isn't available");
1929 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1933 return rte_flow_error_set(error, EINVAL,
1934 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1936 "data cannot be empty");
1937 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1938 return rte_flow_error_set(error, EINVAL,
1939 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1941 "mark id exceeds the limit");
1945 return rte_flow_error_set(error, EINVAL,
1946 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1947 "mask cannot be zero");
1949 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1950 (const uint8_t *)&nic_mask,
1951 sizeof(struct rte_flow_item_mark),
1952 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1959 * Validate META item.
1962 * Pointer to the rte_eth_dev structure.
1964 * Item specification.
1966 * Attributes of flow that includes this item.
1968 * Pointer to error structure.
1971 * 0 on success, a negative errno value otherwise and rte_errno is set.
1974 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1975 const struct rte_flow_item *item,
1976 const struct rte_flow_attr *attr,
1977 struct rte_flow_error *error)
1979 struct mlx5_priv *priv = dev->data->dev_private;
1980 struct mlx5_dev_config *config = &priv->config;
1981 const struct rte_flow_item_meta *spec = item->spec;
1982 const struct rte_flow_item_meta *mask = item->mask;
1983 struct rte_flow_item_meta nic_mask = {
1990 return rte_flow_error_set(error, EINVAL,
1991 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1993 "data cannot be empty");
1994 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1995 if (!mlx5_flow_ext_mreg_supported(dev))
1996 return rte_flow_error_set(error, ENOTSUP,
1997 RTE_FLOW_ERROR_TYPE_ITEM, item,
1998 "extended metadata register"
1999 " isn't supported");
2000 reg = flow_dv_get_metadata_reg(dev, attr, error);
2004 return rte_flow_error_set(error, ENOTSUP,
2005 RTE_FLOW_ERROR_TYPE_ITEM, item,
2006 "unavalable extended metadata register");
2008 return rte_flow_error_set(error, ENOTSUP,
2009 RTE_FLOW_ERROR_TYPE_ITEM, item,
2013 nic_mask.data = priv->sh->dv_meta_mask;
2016 return rte_flow_error_set(error, ENOTSUP,
2017 RTE_FLOW_ERROR_TYPE_ITEM, item,
2018 "extended metadata feature "
2019 "should be enabled when "
2020 "meta item is requested "
2021 "with e-switch mode ");
2023 return rte_flow_error_set(error, ENOTSUP,
2024 RTE_FLOW_ERROR_TYPE_ITEM, item,
2025 "match on metadata for ingress "
2026 "is not supported in legacy "
2030 mask = &rte_flow_item_meta_mask;
2032 return rte_flow_error_set(error, EINVAL,
2033 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2034 "mask cannot be zero");
2036 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2037 (const uint8_t *)&nic_mask,
2038 sizeof(struct rte_flow_item_meta),
2039 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2044 * Validate TAG item.
2047 * Pointer to the rte_eth_dev structure.
2049 * Item specification.
2051 * Attributes of flow that includes this item.
2053 * Pointer to error structure.
2056 * 0 on success, a negative errno value otherwise and rte_errno is set.
2059 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2060 const struct rte_flow_item *item,
2061 const struct rte_flow_attr *attr __rte_unused,
2062 struct rte_flow_error *error)
2064 const struct rte_flow_item_tag *spec = item->spec;
2065 const struct rte_flow_item_tag *mask = item->mask;
2066 const struct rte_flow_item_tag nic_mask = {
2067 .data = RTE_BE32(UINT32_MAX),
2072 if (!mlx5_flow_ext_mreg_supported(dev))
2073 return rte_flow_error_set(error, ENOTSUP,
2074 RTE_FLOW_ERROR_TYPE_ITEM, item,
2075 "extensive metadata register"
2076 " isn't supported");
2078 return rte_flow_error_set(error, EINVAL,
2079 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2081 "data cannot be empty");
2083 mask = &rte_flow_item_tag_mask;
2085 return rte_flow_error_set(error, EINVAL,
2086 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2087 "mask cannot be zero");
2089 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2090 (const uint8_t *)&nic_mask,
2091 sizeof(struct rte_flow_item_tag),
2092 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2095 if (mask->index != 0xff)
2096 return rte_flow_error_set(error, EINVAL,
2097 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2098 "partial mask for tag index"
2099 " is not supported");
2100 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2103 MLX5_ASSERT(ret != REG_NON);
2108 * Validate vport item.
2111 * Pointer to the rte_eth_dev structure.
2113 * Item specification.
2115 * Attributes of flow that includes this item.
2116 * @param[in] item_flags
2117 * Bit-fields that holds the items detected until now.
2119 * Pointer to error structure.
2122 * 0 on success, a negative errno value otherwise and rte_errno is set.
2125 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2126 const struct rte_flow_item *item,
2127 const struct rte_flow_attr *attr,
2128 uint64_t item_flags,
2129 struct rte_flow_error *error)
2131 const struct rte_flow_item_port_id *spec = item->spec;
2132 const struct rte_flow_item_port_id *mask = item->mask;
2133 const struct rte_flow_item_port_id switch_mask = {
2136 struct mlx5_priv *esw_priv;
2137 struct mlx5_priv *dev_priv;
2140 if (!attr->transfer)
2141 return rte_flow_error_set(error, EINVAL,
2142 RTE_FLOW_ERROR_TYPE_ITEM,
2144 "match on port id is valid only"
2145 " when transfer flag is enabled");
2146 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2147 return rte_flow_error_set(error, ENOTSUP,
2148 RTE_FLOW_ERROR_TYPE_ITEM, item,
2149 "multiple source ports are not"
2152 mask = &switch_mask;
2153 if (mask->id != 0xffffffff)
2154 return rte_flow_error_set(error, ENOTSUP,
2155 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2157 "no support for partial mask on"
2159 ret = mlx5_flow_item_acceptable
2160 (item, (const uint8_t *)mask,
2161 (const uint8_t *)&rte_flow_item_port_id_mask,
2162 sizeof(struct rte_flow_item_port_id),
2163 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2168 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2170 return rte_flow_error_set(error, rte_errno,
2171 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2172 "failed to obtain E-Switch info for"
2174 dev_priv = mlx5_dev_to_eswitch_info(dev);
2176 return rte_flow_error_set(error, rte_errno,
2177 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2179 "failed to obtain E-Switch info");
2180 if (esw_priv->domain_id != dev_priv->domain_id)
2181 return rte_flow_error_set(error, EINVAL,
2182 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2183 "cannot match on a port from a"
2184 " different E-Switch");
2189 * Validate VLAN item.
2192 * Item specification.
2193 * @param[in] item_flags
2194 * Bit-fields that holds the items detected until now.
2196 * Ethernet device flow is being created on.
2198 * Pointer to error structure.
2201 * 0 on success, a negative errno value otherwise and rte_errno is set.
2204 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2205 uint64_t item_flags,
2206 struct rte_eth_dev *dev,
2207 struct rte_flow_error *error)
2209 const struct rte_flow_item_vlan *mask = item->mask;
2210 const struct rte_flow_item_vlan nic_mask = {
2211 .tci = RTE_BE16(UINT16_MAX),
2212 .inner_type = RTE_BE16(UINT16_MAX),
2215 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2217 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2218 MLX5_FLOW_LAYER_INNER_L4) :
2219 (MLX5_FLOW_LAYER_OUTER_L3 |
2220 MLX5_FLOW_LAYER_OUTER_L4);
2221 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2222 MLX5_FLOW_LAYER_OUTER_VLAN;
2224 if (item_flags & vlanm)
2225 return rte_flow_error_set(error, EINVAL,
2226 RTE_FLOW_ERROR_TYPE_ITEM, item,
2227 "multiple VLAN layers not supported");
2228 else if ((item_flags & l34m) != 0)
2229 return rte_flow_error_set(error, EINVAL,
2230 RTE_FLOW_ERROR_TYPE_ITEM, item,
2231 "VLAN cannot follow L3/L4 layer");
2233 mask = &rte_flow_item_vlan_mask;
2234 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2235 (const uint8_t *)&nic_mask,
2236 sizeof(struct rte_flow_item_vlan),
2237 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2240 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2241 struct mlx5_priv *priv = dev->data->dev_private;
2243 if (priv->vmwa_context) {
2245 * Non-NULL context means we have a virtual machine
2246 * and SR-IOV enabled, we have to create VLAN interface
2247 * to make hypervisor to setup E-Switch vport
2248 * context correctly. We avoid creating the multiple
2249 * VLAN interfaces, so we cannot support VLAN tag mask.
2251 return rte_flow_error_set(error, EINVAL,
2252 RTE_FLOW_ERROR_TYPE_ITEM,
2254 "VLAN tag mask is not"
2255 " supported in virtual"
2263 * GTP flags are contained in 1 byte of the format:
2264 * -------------------------------------------
2265 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2266 * |-----------------------------------------|
2267 * | value | Version | PT | Res | E | S | PN |
2268 * -------------------------------------------
2270 * Matching is supported only for GTP flags E, S, PN.
2272 #define MLX5_GTP_FLAGS_MASK 0x07
2275 * Validate GTP item.
2278 * Pointer to the rte_eth_dev structure.
2280 * Item specification.
2281 * @param[in] item_flags
2282 * Bit-fields that holds the items detected until now.
2284 * Pointer to error structure.
2287 * 0 on success, a negative errno value otherwise and rte_errno is set.
2290 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2291 const struct rte_flow_item *item,
2292 uint64_t item_flags,
2293 struct rte_flow_error *error)
2295 struct mlx5_priv *priv = dev->data->dev_private;
2296 const struct rte_flow_item_gtp *spec = item->spec;
2297 const struct rte_flow_item_gtp *mask = item->mask;
2298 const struct rte_flow_item_gtp nic_mask = {
2299 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
2301 .teid = RTE_BE32(0xffffffff),
2304 if (!priv->config.hca_attr.tunnel_stateless_gtp)
2305 return rte_flow_error_set(error, ENOTSUP,
2306 RTE_FLOW_ERROR_TYPE_ITEM, item,
2307 "GTP support is not enabled");
2308 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2309 return rte_flow_error_set(error, ENOTSUP,
2310 RTE_FLOW_ERROR_TYPE_ITEM, item,
2311 "multiple tunnel layers not"
2313 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2314 return rte_flow_error_set(error, EINVAL,
2315 RTE_FLOW_ERROR_TYPE_ITEM, item,
2316 "no outer UDP layer found");
2318 mask = &rte_flow_item_gtp_mask;
2319 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
2320 return rte_flow_error_set(error, ENOTSUP,
2321 RTE_FLOW_ERROR_TYPE_ITEM, item,
2322 "Match is supported for GTP"
2324 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2325 (const uint8_t *)&nic_mask,
2326 sizeof(struct rte_flow_item_gtp),
2327 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2331 * Validate GTP PSC item.
2334 * Item specification.
2335 * @param[in] last_item
2336 * Previous validated item in the pattern items.
2337 * @param[in] gtp_item
2338 * Previous GTP item specification.
2340 * Pointer to flow attributes.
2342 * Pointer to error structure.
2345 * 0 on success, a negative errno value otherwise and rte_errno is set.
2348 flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2350 const struct rte_flow_item *gtp_item,
2351 const struct rte_flow_attr *attr,
2352 struct rte_flow_error *error)
2354 const struct rte_flow_item_gtp *gtp_spec;
2355 const struct rte_flow_item_gtp *gtp_mask;
2356 const struct rte_flow_item_gtp_psc *spec;
2357 const struct rte_flow_item_gtp_psc *mask;
2358 const struct rte_flow_item_gtp_psc nic_mask = {
2363 if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2364 return rte_flow_error_set
2365 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2366 "GTP PSC item must be preceded with GTP item");
2367 gtp_spec = gtp_item->spec;
2368 gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2369 /* GTP spec and E flag is requested to match zero. */
2371 (gtp_mask->v_pt_rsv_flags &
2372 ~gtp_spec->v_pt_rsv_flags & MLX5_GTP_EXT_HEADER_FLAG))
2373 return rte_flow_error_set
2374 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2375 "GTP E flag must be 1 to match GTP PSC");
2376 /* Check the flow is not created in group zero. */
2377 if (!attr->transfer && !attr->group)
2378 return rte_flow_error_set
2379 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2380 "GTP PSC is not supported for group 0");
2381 /* GTP spec is here and E flag is requested to match zero. */
2385 mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2386 if (spec->pdu_type > MLX5_GTP_EXT_MAX_PDU_TYPE)
2387 return rte_flow_error_set
2388 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2389 "PDU type should be smaller than 16");
2390 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2391 (const uint8_t *)&nic_mask,
2392 sizeof(struct rte_flow_item_gtp_psc),
2393 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2397 * Validate IPV4 item.
2398 * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2399 * add specific validation of fragment_offset field,
2402 * Item specification.
2403 * @param[in] item_flags
2404 * Bit-fields that holds the items detected until now.
2406 * Pointer to error structure.
2409 * 0 on success, a negative errno value otherwise and rte_errno is set.
2412 flow_dv_validate_item_ipv4(const struct rte_flow_item *item,
2413 uint64_t item_flags,
2415 uint16_t ether_type,
2416 struct rte_flow_error *error)
2419 const struct rte_flow_item_ipv4 *spec = item->spec;
2420 const struct rte_flow_item_ipv4 *last = item->last;
2421 const struct rte_flow_item_ipv4 *mask = item->mask;
2422 rte_be16_t fragment_offset_spec = 0;
2423 rte_be16_t fragment_offset_last = 0;
2424 const struct rte_flow_item_ipv4 nic_ipv4_mask = {
2426 .src_addr = RTE_BE32(0xffffffff),
2427 .dst_addr = RTE_BE32(0xffffffff),
2428 .type_of_service = 0xff,
2429 .fragment_offset = RTE_BE16(0xffff),
2430 .next_proto_id = 0xff,
2431 .time_to_live = 0xff,
2435 ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2436 ether_type, &nic_ipv4_mask,
2437 MLX5_ITEM_RANGE_ACCEPTED, error);
2441 fragment_offset_spec = spec->hdr.fragment_offset &
2442 mask->hdr.fragment_offset;
2443 if (!fragment_offset_spec)
2446 * spec and mask are valid, enforce using full mask to make sure the
2447 * complete value is used correctly.
2449 if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2450 != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2451 return rte_flow_error_set(error, EINVAL,
2452 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2453 item, "must use full mask for"
2454 " fragment_offset");
2456 * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
2457 * indicating this is 1st fragment of fragmented packet.
2458 * This is not yet supported in MLX5, return appropriate error message.
2460 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
2461 return rte_flow_error_set(error, ENOTSUP,
2462 RTE_FLOW_ERROR_TYPE_ITEM, item,
2463 "match on first fragment not "
2465 if (fragment_offset_spec && !last)
2466 return rte_flow_error_set(error, ENOTSUP,
2467 RTE_FLOW_ERROR_TYPE_ITEM, item,
2468 "specified value not supported");
2469 /* spec and last are valid, validate the specified range. */
2470 fragment_offset_last = last->hdr.fragment_offset &
2471 mask->hdr.fragment_offset;
2473 * Match on fragment_offset spec 0x2001 and last 0x3fff
2474 * means MF is 1 and frag-offset is > 0.
2475 * This packet is fragment 2nd and onward, excluding last.
2476 * This is not yet supported in MLX5, return appropriate
2479 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
2480 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2481 return rte_flow_error_set(error, ENOTSUP,
2482 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2483 last, "match on following "
2484 "fragments not supported");
2486 * Match on fragment_offset spec 0x0001 and last 0x1fff
2487 * means MF is 0 and frag-offset is > 0.
2488 * This packet is last fragment of fragmented packet.
2489 * This is not yet supported in MLX5, return appropriate
2492 if (fragment_offset_spec == RTE_BE16(1) &&
2493 fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
2494 return rte_flow_error_set(error, ENOTSUP,
2495 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2496 last, "match on last "
2497 "fragment not supported");
2499 * Match on fragment_offset spec 0x0001 and last 0x3fff
2500 * means MF and/or frag-offset is not 0.
2501 * This is a fragmented packet.
2502 * Other range values are invalid and rejected.
2504 if (!(fragment_offset_spec == RTE_BE16(1) &&
2505 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
2506 return rte_flow_error_set(error, ENOTSUP,
2507 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2508 "specified range not supported");
2513 * Validate IPV6 fragment extension item.
2516 * Item specification.
2517 * @param[in] item_flags
2518 * Bit-fields that holds the items detected until now.
2520 * Pointer to error structure.
2523 * 0 on success, a negative errno value otherwise and rte_errno is set.
2526 flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
2527 uint64_t item_flags,
2528 struct rte_flow_error *error)
2530 const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
2531 const struct rte_flow_item_ipv6_frag_ext *last = item->last;
2532 const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
2533 rte_be16_t frag_data_spec = 0;
2534 rte_be16_t frag_data_last = 0;
2535 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2536 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2537 MLX5_FLOW_LAYER_OUTER_L4;
2539 struct rte_flow_item_ipv6_frag_ext nic_mask = {
2541 .next_header = 0xff,
2542 .frag_data = RTE_BE16(0xffff),
2546 if (item_flags & l4m)
2547 return rte_flow_error_set(error, EINVAL,
2548 RTE_FLOW_ERROR_TYPE_ITEM, item,
2549 "ipv6 fragment extension item cannot "
2551 if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
2552 (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
2553 return rte_flow_error_set(error, EINVAL,
2554 RTE_FLOW_ERROR_TYPE_ITEM, item,
2555 "ipv6 fragment extension item must "
2556 "follow ipv6 item");
2558 frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
2559 if (!frag_data_spec)
2562 * spec and mask are valid, enforce using full mask to make sure the
2563 * complete value is used correctly.
2565 if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
2566 RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2567 return rte_flow_error_set(error, EINVAL,
2568 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2569 item, "must use full mask for"
2572 * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2573 * This is 1st fragment of fragmented packet.
2575 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2576 return rte_flow_error_set(error, ENOTSUP,
2577 RTE_FLOW_ERROR_TYPE_ITEM, item,
2578 "match on first fragment not "
2580 if (frag_data_spec && !last)
2581 return rte_flow_error_set(error, EINVAL,
2582 RTE_FLOW_ERROR_TYPE_ITEM, item,
2583 "specified value not supported");
2584 ret = mlx5_flow_item_acceptable
2585 (item, (const uint8_t *)mask,
2586 (const uint8_t *)&nic_mask,
2587 sizeof(struct rte_flow_item_ipv6_frag_ext),
2588 MLX5_ITEM_RANGE_ACCEPTED, error);
2591 /* spec and last are valid, validate the specified range. */
2592 frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2594 * Match on frag_data spec 0x0009 and last 0xfff9
2595 * means M is 1 and frag-offset is > 0.
2596 * This packet is fragment 2nd and onward, excluding last.
2597 * This is not yet supported in MLX5, return appropriate
2600 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2601 RTE_IPV6_EHDR_MF_MASK) &&
2602 frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2603 return rte_flow_error_set(error, ENOTSUP,
2604 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2605 last, "match on following "
2606 "fragments not supported");
2608 * Match on frag_data spec 0x0008 and last 0xfff8
2609 * means M is 0 and frag-offset is > 0.
2610 * This packet is last fragment of fragmented packet.
2611 * This is not yet supported in MLX5, return appropriate
2614 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2615 frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2616 return rte_flow_error_set(error, ENOTSUP,
2617 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2618 last, "match on last "
2619 "fragment not supported");
2620 /* Other range values are invalid and rejected. */
2621 return rte_flow_error_set(error, EINVAL,
2622 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2623 "specified range not supported");
2627 * Validate ASO CT item.
2630 * Pointer to the rte_eth_dev structure.
2632 * Item specification.
2633 * @param[in] item_flags
2634 * Pointer to bit-fields that holds the items detected until now.
2636 * Pointer to error structure.
2639 * 0 on success, a negative errno value otherwise and rte_errno is set.
2642 flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
2643 const struct rte_flow_item *item,
2644 uint64_t *item_flags,
2645 struct rte_flow_error *error)
2647 const struct rte_flow_item_conntrack *spec = item->spec;
2648 const struct rte_flow_item_conntrack *mask = item->mask;
2652 if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
2653 return rte_flow_error_set(error, EINVAL,
2654 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2655 "Only one CT is supported");
2657 mask = &rte_flow_item_conntrack_mask;
2658 flags = spec->flags & mask->flags;
2659 if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
2660 ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
2661 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
2662 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
2663 return rte_flow_error_set(error, EINVAL,
2664 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2665 "Conflict status bits");
2666 /* State change also needs to be considered. */
2667 *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
2672 * Validate the pop VLAN action.
2675 * Pointer to the rte_eth_dev structure.
2676 * @param[in] action_flags
2677 * Holds the actions detected until now.
2679 * Pointer to the pop vlan action.
2680 * @param[in] item_flags
2681 * The items found in this flow rule.
2683 * Pointer to flow attributes.
2685 * Pointer to error structure.
2688 * 0 on success, a negative errno value otherwise and rte_errno is set.
2691 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
2692 uint64_t action_flags,
2693 const struct rte_flow_action *action,
2694 uint64_t item_flags,
2695 const struct rte_flow_attr *attr,
2696 struct rte_flow_error *error)
2698 const struct mlx5_priv *priv = dev->data->dev_private;
2702 if (!priv->sh->pop_vlan_action)
2703 return rte_flow_error_set(error, ENOTSUP,
2704 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2706 "pop vlan action is not supported");
2708 return rte_flow_error_set(error, ENOTSUP,
2709 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2711 "pop vlan action not supported for "
2713 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
2714 return rte_flow_error_set(error, ENOTSUP,
2715 RTE_FLOW_ERROR_TYPE_ACTION, action,
2716 "no support for multiple VLAN "
2718 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
2719 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
2720 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
2721 return rte_flow_error_set(error, ENOTSUP,
2722 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2724 "cannot pop vlan after decap without "
2725 "match on inner vlan in the flow");
2726 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
2727 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
2728 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2729 return rte_flow_error_set(error, ENOTSUP,
2730 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2732 "cannot pop vlan without a "
2733 "match on (outer) vlan in the flow");
2734 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2735 return rte_flow_error_set(error, EINVAL,
2736 RTE_FLOW_ERROR_TYPE_ACTION, action,
2737 "wrong action order, port_id should "
2738 "be after pop VLAN action");
2739 if (!attr->transfer && priv->representor)
2740 return rte_flow_error_set(error, ENOTSUP,
2741 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2742 "pop vlan action for VF representor "
2743 "not supported on NIC table");
2748 * Get VLAN default info from vlan match info.
2751 * the list of item specifications.
2753 * pointer VLAN info to fill to.
2756 * 0 on success, a negative errno value otherwise and rte_errno is set.
2759 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
2760 struct rte_vlan_hdr *vlan)
2762 const struct rte_flow_item_vlan nic_mask = {
2763 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
2764 MLX5DV_FLOW_VLAN_VID_MASK),
2765 .inner_type = RTE_BE16(0xffff),
2770 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2771 int type = items->type;
2773 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
2774 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
2777 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
2778 const struct rte_flow_item_vlan *vlan_m = items->mask;
2779 const struct rte_flow_item_vlan *vlan_v = items->spec;
2781 /* If VLAN item in pattern doesn't contain data, return here. */
2786 /* Only full match values are accepted */
2787 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
2788 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
2789 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
2791 rte_be_to_cpu_16(vlan_v->tci &
2792 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
2794 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
2795 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
2796 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
2798 rte_be_to_cpu_16(vlan_v->tci &
2799 MLX5DV_FLOW_VLAN_VID_MASK_BE);
2801 if (vlan_m->inner_type == nic_mask.inner_type)
2802 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
2803 vlan_m->inner_type);
2808 * Validate the push VLAN action.
2811 * Pointer to the rte_eth_dev structure.
2812 * @param[in] action_flags
2813 * Holds the actions detected until now.
2814 * @param[in] item_flags
2815 * The items found in this flow rule.
2817 * Pointer to the action structure.
2819 * Pointer to flow attributes
2821 * Pointer to error structure.
2824 * 0 on success, a negative errno value otherwise and rte_errno is set.
2827 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
2828 uint64_t action_flags,
2829 const struct rte_flow_item_vlan *vlan_m,
2830 const struct rte_flow_action *action,
2831 const struct rte_flow_attr *attr,
2832 struct rte_flow_error *error)
2834 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
2835 const struct mlx5_priv *priv = dev->data->dev_private;
2837 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
2838 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
2839 return rte_flow_error_set(error, EINVAL,
2840 RTE_FLOW_ERROR_TYPE_ACTION, action,
2841 "invalid vlan ethertype");
2842 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2843 return rte_flow_error_set(error, EINVAL,
2844 RTE_FLOW_ERROR_TYPE_ACTION, action,
2845 "wrong action order, port_id should "
2846 "be after push VLAN");
2847 if (!attr->transfer && priv->representor)
2848 return rte_flow_error_set(error, ENOTSUP,
2849 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2850 "push vlan action for VF representor "
2851 "not supported on NIC table");
2853 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
2854 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
2855 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
2856 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
2857 !(mlx5_flow_find_action
2858 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
2859 return rte_flow_error_set(error, EINVAL,
2860 RTE_FLOW_ERROR_TYPE_ACTION, action,
2861 "not full match mask on VLAN PCP and "
2862 "there is no of_set_vlan_pcp action, "
2863 "push VLAN action cannot figure out "
2866 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
2867 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
2868 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
2869 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
2870 !(mlx5_flow_find_action
2871 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
2872 return rte_flow_error_set(error, EINVAL,
2873 RTE_FLOW_ERROR_TYPE_ACTION, action,
2874 "not full match mask on VLAN VID and "
2875 "there is no of_set_vlan_vid action, "
2876 "push VLAN action cannot figure out "
2883 * Validate the set VLAN PCP.
2885 * @param[in] action_flags
2886 * Holds the actions detected until now.
2887 * @param[in] actions
2888 * Pointer to the list of actions remaining in the flow rule.
2890 * Pointer to error structure.
2893 * 0 on success, a negative errno value otherwise and rte_errno is set.
2896 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2897 const struct rte_flow_action actions[],
2898 struct rte_flow_error *error)
2900 const struct rte_flow_action *action = actions;
2901 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2903 if (conf->vlan_pcp > 7)
2904 return rte_flow_error_set(error, EINVAL,
2905 RTE_FLOW_ERROR_TYPE_ACTION, action,
2906 "VLAN PCP value is too big");
2907 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2908 return rte_flow_error_set(error, ENOTSUP,
2909 RTE_FLOW_ERROR_TYPE_ACTION, action,
2910 "set VLAN PCP action must follow "
2911 "the push VLAN action");
2912 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2913 return rte_flow_error_set(error, ENOTSUP,
2914 RTE_FLOW_ERROR_TYPE_ACTION, action,
2915 "Multiple VLAN PCP modification are "
2917 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2918 return rte_flow_error_set(error, EINVAL,
2919 RTE_FLOW_ERROR_TYPE_ACTION, action,
2920 "wrong action order, port_id should "
2921 "be after set VLAN PCP");
2926 * Validate the set VLAN VID.
2928 * @param[in] item_flags
2929 * Holds the items detected in this rule.
2930 * @param[in] action_flags
2931 * Holds the actions detected until now.
2932 * @param[in] actions
2933 * Pointer to the list of actions remaining in the flow rule.
2935 * Pointer to error structure.
2938 * 0 on success, a negative errno value otherwise and rte_errno is set.
2941 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2942 uint64_t action_flags,
2943 const struct rte_flow_action actions[],
2944 struct rte_flow_error *error)
2946 const struct rte_flow_action *action = actions;
2947 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
2949 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
2950 return rte_flow_error_set(error, EINVAL,
2951 RTE_FLOW_ERROR_TYPE_ACTION, action,
2952 "VLAN VID value is too big");
2953 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
2954 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2955 return rte_flow_error_set(error, ENOTSUP,
2956 RTE_FLOW_ERROR_TYPE_ACTION, action,
2957 "set VLAN VID action must follow push"
2958 " VLAN action or match on VLAN item");
2959 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
2960 return rte_flow_error_set(error, ENOTSUP,
2961 RTE_FLOW_ERROR_TYPE_ACTION, action,
2962 "Multiple VLAN VID modifications are "
2964 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2965 return rte_flow_error_set(error, EINVAL,
2966 RTE_FLOW_ERROR_TYPE_ACTION, action,
2967 "wrong action order, port_id should "
2968 "be after set VLAN VID");
2973 * Validate the FLAG action.
2976 * Pointer to the rte_eth_dev structure.
2977 * @param[in] action_flags
2978 * Holds the actions detected until now.
2980 * Pointer to flow attributes
2982 * Pointer to error structure.
2985 * 0 on success, a negative errno value otherwise and rte_errno is set.
2988 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
2989 uint64_t action_flags,
2990 const struct rte_flow_attr *attr,
2991 struct rte_flow_error *error)
2993 struct mlx5_priv *priv = dev->data->dev_private;
2994 struct mlx5_dev_config *config = &priv->config;
2997 /* Fall back if no extended metadata register support. */
2998 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2999 return mlx5_flow_validate_action_flag(action_flags, attr,
3001 /* Extensive metadata mode requires registers. */
3002 if (!mlx5_flow_ext_mreg_supported(dev))
3003 return rte_flow_error_set(error, ENOTSUP,
3004 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3005 "no metadata registers "
3006 "to support flag action");
3007 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3008 return rte_flow_error_set(error, ENOTSUP,
3009 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3010 "extended metadata register"
3011 " isn't available");
3012 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3015 MLX5_ASSERT(ret > 0);
3016 if (action_flags & MLX5_FLOW_ACTION_MARK)
3017 return rte_flow_error_set(error, EINVAL,
3018 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3019 "can't mark and flag in same flow");
3020 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3021 return rte_flow_error_set(error, EINVAL,
3022 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3024 " actions in same flow");
3029 * Validate MARK action.
3032 * Pointer to the rte_eth_dev structure.
3034 * Pointer to action.
3035 * @param[in] action_flags
3036 * Holds the actions detected until now.
3038 * Pointer to flow attributes
3040 * Pointer to error structure.
3043 * 0 on success, a negative errno value otherwise and rte_errno is set.
3046 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3047 const struct rte_flow_action *action,
3048 uint64_t action_flags,
3049 const struct rte_flow_attr *attr,
3050 struct rte_flow_error *error)
3052 struct mlx5_priv *priv = dev->data->dev_private;
3053 struct mlx5_dev_config *config = &priv->config;
3054 const struct rte_flow_action_mark *mark = action->conf;
3057 if (is_tunnel_offload_active(dev))
3058 return rte_flow_error_set(error, ENOTSUP,
3059 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3061 "if tunnel offload active");
3062 /* Fall back if no extended metadata register support. */
3063 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3064 return mlx5_flow_validate_action_mark(action, action_flags,
3066 /* Extensive metadata mode requires registers. */
3067 if (!mlx5_flow_ext_mreg_supported(dev))
3068 return rte_flow_error_set(error, ENOTSUP,
3069 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3070 "no metadata registers "
3071 "to support mark action");
3072 if (!priv->sh->dv_mark_mask)
3073 return rte_flow_error_set(error, ENOTSUP,
3074 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3075 "extended metadata register"
3076 " isn't available");
3077 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3080 MLX5_ASSERT(ret > 0);
3082 return rte_flow_error_set(error, EINVAL,
3083 RTE_FLOW_ERROR_TYPE_ACTION, action,
3084 "configuration cannot be null");
3085 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3086 return rte_flow_error_set(error, EINVAL,
3087 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3089 "mark id exceeds the limit");
3090 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3091 return rte_flow_error_set(error, EINVAL,
3092 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3093 "can't flag and mark in same flow");
3094 if (action_flags & MLX5_FLOW_ACTION_MARK)
3095 return rte_flow_error_set(error, EINVAL,
3096 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3097 "can't have 2 mark actions in same"
3103 * Validate SET_META action.
3106 * Pointer to the rte_eth_dev structure.
3108 * Pointer to the action structure.
3109 * @param[in] action_flags
3110 * Holds the actions detected until now.
3112 * Pointer to flow attributes
3114 * Pointer to error structure.
3117 * 0 on success, a negative errno value otherwise and rte_errno is set.
3120 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3121 const struct rte_flow_action *action,
3122 uint64_t action_flags __rte_unused,
3123 const struct rte_flow_attr *attr,
3124 struct rte_flow_error *error)
3126 const struct rte_flow_action_set_meta *conf;
3127 uint32_t nic_mask = UINT32_MAX;
3130 if (!mlx5_flow_ext_mreg_supported(dev))
3131 return rte_flow_error_set(error, ENOTSUP,
3132 RTE_FLOW_ERROR_TYPE_ACTION, action,
3133 "extended metadata register"
3134 " isn't supported");
3135 reg = flow_dv_get_metadata_reg(dev, attr, error);
3139 return rte_flow_error_set(error, ENOTSUP,
3140 RTE_FLOW_ERROR_TYPE_ACTION, action,
3141 "unavalable extended metadata register");
3142 if (reg != REG_A && reg != REG_B) {
3143 struct mlx5_priv *priv = dev->data->dev_private;
3145 nic_mask = priv->sh->dv_meta_mask;
3147 if (!(action->conf))
3148 return rte_flow_error_set(error, EINVAL,
3149 RTE_FLOW_ERROR_TYPE_ACTION, action,
3150 "configuration cannot be null");
3151 conf = (const struct rte_flow_action_set_meta *)action->conf;
3153 return rte_flow_error_set(error, EINVAL,
3154 RTE_FLOW_ERROR_TYPE_ACTION, action,
3155 "zero mask doesn't have any effect");
3156 if (conf->mask & ~nic_mask)
3157 return rte_flow_error_set(error, EINVAL,
3158 RTE_FLOW_ERROR_TYPE_ACTION, action,
3159 "meta data must be within reg C0");
3164 * Validate SET_TAG action.
3167 * Pointer to the rte_eth_dev structure.
3169 * Pointer to the action structure.
3170 * @param[in] action_flags
3171 * Holds the actions detected until now.
3173 * Pointer to flow attributes
3175 * Pointer to error structure.
3178 * 0 on success, a negative errno value otherwise and rte_errno is set.
3181 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3182 const struct rte_flow_action *action,
3183 uint64_t action_flags,
3184 const struct rte_flow_attr *attr,
3185 struct rte_flow_error *error)
3187 const struct rte_flow_action_set_tag *conf;
3188 const uint64_t terminal_action_flags =
3189 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3190 MLX5_FLOW_ACTION_RSS;
3193 if (!mlx5_flow_ext_mreg_supported(dev))
3194 return rte_flow_error_set(error, ENOTSUP,
3195 RTE_FLOW_ERROR_TYPE_ACTION, action,
3196 "extensive metadata register"
3197 " isn't supported");
3198 if (!(action->conf))
3199 return rte_flow_error_set(error, EINVAL,
3200 RTE_FLOW_ERROR_TYPE_ACTION, action,
3201 "configuration cannot be null");
3202 conf = (const struct rte_flow_action_set_tag *)action->conf;
3204 return rte_flow_error_set(error, EINVAL,
3205 RTE_FLOW_ERROR_TYPE_ACTION, action,
3206 "zero mask doesn't have any effect");
3207 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3210 if (!attr->transfer && attr->ingress &&
3211 (action_flags & terminal_action_flags))
3212 return rte_flow_error_set(error, EINVAL,
3213 RTE_FLOW_ERROR_TYPE_ACTION, action,
3214 "set_tag has no effect"
3215 " with terminal actions");
3220 * Check if action counter is shared by either old or new mechanism.
3223 * Pointer to the action structure.
3226 * True when counter is shared, false otherwise.
3229 is_shared_action_count(const struct rte_flow_action *action)
3231 const struct rte_flow_action_count *count =
3232 (const struct rte_flow_action_count *)action->conf;
3234 if ((int)action->type == MLX5_RTE_FLOW_ACTION_TYPE_COUNT)
3236 return !!(count && count->shared);
3240 * Validate count action.
3243 * Pointer to rte_eth_dev structure.
3245 * Indicator if action is shared.
3246 * @param[in] action_flags
3247 * Holds the actions detected until now.
3249 * Pointer to error structure.
3252 * 0 on success, a negative errno value otherwise and rte_errno is set.
3255 flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3256 uint64_t action_flags,
3257 struct rte_flow_error *error)
3259 struct mlx5_priv *priv = dev->data->dev_private;
3261 if (!priv->config.devx)
3263 if (action_flags & MLX5_FLOW_ACTION_COUNT)
3264 return rte_flow_error_set(error, EINVAL,
3265 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3266 "duplicate count actions set");
3267 if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
3268 !priv->sh->flow_hit_aso_en)
3269 return rte_flow_error_set(error, EINVAL,
3270 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3271 "old age and shared count combination is not supported");
3272 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3276 return rte_flow_error_set
3278 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3280 "count action not supported");
3284 * Validate the L2 encap action.
3287 * Pointer to the rte_eth_dev structure.
3288 * @param[in] action_flags
3289 * Holds the actions detected until now.
3291 * Pointer to the action structure.
3293 * Pointer to flow attributes.
3295 * Pointer to error structure.
3298 * 0 on success, a negative errno value otherwise and rte_errno is set.
3301 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3302 uint64_t action_flags,
3303 const struct rte_flow_action *action,
3304 const struct rte_flow_attr *attr,
3305 struct rte_flow_error *error)
3307 const struct mlx5_priv *priv = dev->data->dev_private;
3309 if (!(action->conf))
3310 return rte_flow_error_set(error, EINVAL,
3311 RTE_FLOW_ERROR_TYPE_ACTION, action,
3312 "configuration cannot be null");
3313 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3314 return rte_flow_error_set(error, EINVAL,
3315 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3316 "can only have a single encap action "
3318 if (!attr->transfer && priv->representor)
3319 return rte_flow_error_set(error, ENOTSUP,
3320 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3321 "encap action for VF representor "
3322 "not supported on NIC table");
3327 * Validate a decap action.
3330 * Pointer to the rte_eth_dev structure.
3331 * @param[in] action_flags
3332 * Holds the actions detected until now.
3334 * Pointer to the action structure.
3335 * @param[in] item_flags
3336 * Holds the items detected.
3338 * Pointer to flow attributes
3340 * Pointer to error structure.
3343 * 0 on success, a negative errno value otherwise and rte_errno is set.
3346 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3347 uint64_t action_flags,
3348 const struct rte_flow_action *action,
3349 const uint64_t item_flags,
3350 const struct rte_flow_attr *attr,
3351 struct rte_flow_error *error)
3353 const struct mlx5_priv *priv = dev->data->dev_private;
3355 if (priv->config.hca_attr.scatter_fcs_w_decap_disable &&
3356 !priv->config.decap_en)
3357 return rte_flow_error_set(error, ENOTSUP,
3358 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3359 "decap is not enabled");
3360 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3361 return rte_flow_error_set(error, ENOTSUP,
3362 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3364 MLX5_FLOW_ACTION_DECAP ? "can only "
3365 "have a single decap action" : "decap "
3366 "after encap is not supported");
3367 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3368 return rte_flow_error_set(error, EINVAL,
3369 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3370 "can't have decap action after"
3373 return rte_flow_error_set(error, ENOTSUP,
3374 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3376 "decap action not supported for "
3378 if (!attr->transfer && priv->representor)
3379 return rte_flow_error_set(error, ENOTSUP,
3380 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3381 "decap action for VF representor "
3382 "not supported on NIC table");
3383 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3384 !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3385 return rte_flow_error_set(error, ENOTSUP,
3386 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3387 "VXLAN item should be present for VXLAN decap");
3391 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3394 * Validate the raw encap and decap actions.
3397 * Pointer to the rte_eth_dev structure.
3399 * Pointer to the decap action.
3401 * Pointer to the encap action.
3403 * Pointer to flow attributes
3404 * @param[in/out] action_flags
3405 * Holds the actions detected until now.
3406 * @param[out] actions_n
3407 * pointer to the number of actions counter.
3409 * Pointer to the action structure.
3410 * @param[in] item_flags
3411 * Holds the items detected.
3413 * Pointer to error structure.
3416 * 0 on success, a negative errno value otherwise and rte_errno is set.
3419 flow_dv_validate_action_raw_encap_decap
3420 (struct rte_eth_dev *dev,
3421 const struct rte_flow_action_raw_decap *decap,
3422 const struct rte_flow_action_raw_encap *encap,
3423 const struct rte_flow_attr *attr, uint64_t *action_flags,
3424 int *actions_n, const struct rte_flow_action *action,
3425 uint64_t item_flags, struct rte_flow_error *error)
3427 const struct mlx5_priv *priv = dev->data->dev_private;
3430 if (encap && (!encap->size || !encap->data))
3431 return rte_flow_error_set(error, EINVAL,
3432 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3433 "raw encap data cannot be empty");
3434 if (decap && encap) {
3435 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3436 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3439 else if (encap->size <=
3440 MLX5_ENCAPSULATION_DECISION_SIZE &&
3442 MLX5_ENCAPSULATION_DECISION_SIZE)
3445 else if (encap->size >
3446 MLX5_ENCAPSULATION_DECISION_SIZE &&
3448 MLX5_ENCAPSULATION_DECISION_SIZE)
3449 /* 2 L2 actions: encap and decap. */
3452 return rte_flow_error_set(error,
3454 RTE_FLOW_ERROR_TYPE_ACTION,
3455 NULL, "unsupported too small "
3456 "raw decap and too small raw "
3457 "encap combination");
3460 ret = flow_dv_validate_action_decap(dev, *action_flags, action,
3461 item_flags, attr, error);
3464 *action_flags |= MLX5_FLOW_ACTION_DECAP;
3468 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
3469 return rte_flow_error_set(error, ENOTSUP,
3470 RTE_FLOW_ERROR_TYPE_ACTION,
3472 "small raw encap size");
3473 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
3474 return rte_flow_error_set(error, EINVAL,
3475 RTE_FLOW_ERROR_TYPE_ACTION,
3477 "more than one encap action");
3478 if (!attr->transfer && priv->representor)
3479 return rte_flow_error_set
3481 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3482 "encap action for VF representor "
3483 "not supported on NIC table");
3484 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
3491 * Validate the ASO CT action.
3494 * Pointer to the rte_eth_dev structure.
3495 * @param[in] action_flags
3496 * Holds the actions detected until now.
3497 * @param[in] item_flags
3498 * The items found in this flow rule.
3500 * Pointer to flow attributes.
3502 * Pointer to error structure.
3505 * 0 on success, a negative errno value otherwise and rte_errno is set.
3508 flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
3509 uint64_t action_flags,
3510 uint64_t item_flags,
3511 const struct rte_flow_attr *attr,
3512 struct rte_flow_error *error)
3516 if (attr->group == 0 && !attr->transfer)
3517 return rte_flow_error_set(error, ENOTSUP,
3518 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3520 "Only support non-root table");
3521 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
3522 return rte_flow_error_set(error, ENOTSUP,
3523 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3524 "CT cannot follow a fate action");
3525 if ((action_flags & MLX5_FLOW_ACTION_METER) ||
3526 (action_flags & MLX5_FLOW_ACTION_AGE))
3527 return rte_flow_error_set(error, EINVAL,
3528 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3529 "Only one ASO action is supported");
3530 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3531 return rte_flow_error_set(error, EINVAL,
3532 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3533 "Encap cannot exist before CT");
3534 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3535 return rte_flow_error_set(error, EINVAL,
3536 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3537 "Not a outer TCP packet");
3542 * Match encap_decap resource.
3545 * Pointer to the hash list.
3547 * Pointer to exist resource entry object.
3549 * Key of the new entry.
3551 * Pointer to new encap_decap resource.
3554 * 0 on matching, none-zero otherwise.
3557 flow_dv_encap_decap_match_cb(struct mlx5_hlist *list __rte_unused,
3558 struct mlx5_hlist_entry *entry,
3559 uint64_t key __rte_unused, void *cb_ctx)
3561 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3562 struct mlx5_flow_dv_encap_decap_resource *resource = ctx->data;
3563 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3565 cache_resource = container_of(entry,
3566 struct mlx5_flow_dv_encap_decap_resource,
3568 if (resource->reformat_type == cache_resource->reformat_type &&
3569 resource->ft_type == cache_resource->ft_type &&
3570 resource->flags == cache_resource->flags &&
3571 resource->size == cache_resource->size &&
3572 !memcmp((const void *)resource->buf,
3573 (const void *)cache_resource->buf,
3580 * Allocate encap_decap resource.
3583 * Pointer to the hash list.
3585 * Pointer to exist resource entry object.
3587 * Pointer to new encap_decap resource.
3590 * 0 on matching, none-zero otherwise.
3592 struct mlx5_hlist_entry *
3593 flow_dv_encap_decap_create_cb(struct mlx5_hlist *list,
3594 uint64_t key __rte_unused,
3597 struct mlx5_dev_ctx_shared *sh = list->ctx;
3598 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3599 struct mlx5dv_dr_domain *domain;
3600 struct mlx5_flow_dv_encap_decap_resource *resource = ctx->data;
3601 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3605 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3606 domain = sh->fdb_domain;
3607 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3608 domain = sh->rx_domain;
3610 domain = sh->tx_domain;
3611 /* Register new encap/decap resource. */
3612 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
3614 if (!cache_resource) {
3615 rte_flow_error_set(ctx->error, ENOMEM,
3616 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3617 "cannot allocate resource memory");
3620 *cache_resource = *resource;
3621 cache_resource->idx = idx;
3622 ret = mlx5_flow_os_create_flow_action_packet_reformat
3623 (sh->ctx, domain, cache_resource,
3624 &cache_resource->action);
3626 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
3627 rte_flow_error_set(ctx->error, ENOMEM,
3628 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3629 NULL, "cannot create action");
3633 return &cache_resource->entry;
3637 * Find existing encap/decap resource or create and register a new one.
3639 * @param[in, out] dev
3640 * Pointer to rte_eth_dev structure.
3641 * @param[in, out] resource
3642 * Pointer to encap/decap resource.
3643 * @parm[in, out] dev_flow
3644 * Pointer to the dev_flow.
3646 * pointer to error structure.
3649 * 0 on success otherwise -errno and errno is set.
3652 flow_dv_encap_decap_resource_register
3653 (struct rte_eth_dev *dev,
3654 struct mlx5_flow_dv_encap_decap_resource *resource,
3655 struct mlx5_flow *dev_flow,
3656 struct rte_flow_error *error)
3658 struct mlx5_priv *priv = dev->data->dev_private;
3659 struct mlx5_dev_ctx_shared *sh = priv->sh;
3660 struct mlx5_hlist_entry *entry;
3664 uint32_t refmt_type:8;
3666 * Header reformat actions can be shared between
3667 * non-root tables. One bit to indicate non-root
3671 uint32_t reserve:15;
3674 } encap_decap_key = {
3676 .ft_type = resource->ft_type,
3677 .refmt_type = resource->reformat_type,
3678 .is_root = !!dev_flow->dv.group,
3682 struct mlx5_flow_cb_ctx ctx = {
3688 resource->flags = dev_flow->dv.group ? 0 : 1;
3689 key64 = __rte_raw_cksum(&encap_decap_key.v32,
3690 sizeof(encap_decap_key.v32), 0);
3691 if (resource->reformat_type !=
3692 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
3694 key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
3695 entry = mlx5_hlist_register(sh->encaps_decaps, key64, &ctx);
3698 resource = container_of(entry, typeof(*resource), entry);
3699 dev_flow->dv.encap_decap = resource;
3700 dev_flow->handle->dvh.rix_encap_decap = resource->idx;
3705 * Find existing table jump resource or create and register a new one.
3707 * @param[in, out] dev
3708 * Pointer to rte_eth_dev structure.
3709 * @param[in, out] tbl
3710 * Pointer to flow table resource.
3711 * @parm[in, out] dev_flow
3712 * Pointer to the dev_flow.
3714 * pointer to error structure.
3717 * 0 on success otherwise -errno and errno is set.
3720 flow_dv_jump_tbl_resource_register
3721 (struct rte_eth_dev *dev __rte_unused,
3722 struct mlx5_flow_tbl_resource *tbl,
3723 struct mlx5_flow *dev_flow,
3724 struct rte_flow_error *error __rte_unused)
3726 struct mlx5_flow_tbl_data_entry *tbl_data =
3727 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
3730 MLX5_ASSERT(tbl_data->jump.action);
3731 dev_flow->handle->rix_jump = tbl_data->idx;
3732 dev_flow->dv.jump = &tbl_data->jump;
3737 flow_dv_port_id_match_cb(struct mlx5_cache_list *list __rte_unused,
3738 struct mlx5_cache_entry *entry, void *cb_ctx)
3740 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3741 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3742 struct mlx5_flow_dv_port_id_action_resource *res =
3743 container_of(entry, typeof(*res), entry);
3745 return ref->port_id != res->port_id;
3748 struct mlx5_cache_entry *
3749 flow_dv_port_id_create_cb(struct mlx5_cache_list *list,
3750 struct mlx5_cache_entry *entry __rte_unused,
3753 struct mlx5_dev_ctx_shared *sh = list->ctx;
3754 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3755 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3756 struct mlx5_flow_dv_port_id_action_resource *cache;
3760 /* Register new port id action resource. */
3761 cache = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3763 rte_flow_error_set(ctx->error, ENOMEM,
3764 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3765 "cannot allocate port_id action cache memory");
3769 ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
3773 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
3774 rte_flow_error_set(ctx->error, ENOMEM,
3775 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3776 "cannot create action");
3780 return &cache->entry;
3784 * Find existing table port ID resource or create and register a new one.
3786 * @param[in, out] dev
3787 * Pointer to rte_eth_dev structure.
3788 * @param[in, out] resource
3789 * Pointer to port ID action resource.
3790 * @parm[in, out] dev_flow
3791 * Pointer to the dev_flow.
3793 * pointer to error structure.
3796 * 0 on success otherwise -errno and errno is set.
3799 flow_dv_port_id_action_resource_register
3800 (struct rte_eth_dev *dev,
3801 struct mlx5_flow_dv_port_id_action_resource *resource,
3802 struct mlx5_flow *dev_flow,
3803 struct rte_flow_error *error)
3805 struct mlx5_priv *priv = dev->data->dev_private;
3806 struct mlx5_cache_entry *entry;
3807 struct mlx5_flow_dv_port_id_action_resource *cache;
3808 struct mlx5_flow_cb_ctx ctx = {
3813 entry = mlx5_cache_register(&priv->sh->port_id_action_list, &ctx);
3816 cache = container_of(entry, typeof(*cache), entry);
3817 dev_flow->dv.port_id_action = cache;
3818 dev_flow->handle->rix_port_id_action = cache->idx;
3823 flow_dv_push_vlan_match_cb(struct mlx5_cache_list *list __rte_unused,
3824 struct mlx5_cache_entry *entry, void *cb_ctx)
3826 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3827 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3828 struct mlx5_flow_dv_push_vlan_action_resource *res =
3829 container_of(entry, typeof(*res), entry);
3831 return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
3834 struct mlx5_cache_entry *
3835 flow_dv_push_vlan_create_cb(struct mlx5_cache_list *list,
3836 struct mlx5_cache_entry *entry __rte_unused,
3839 struct mlx5_dev_ctx_shared *sh = list->ctx;
3840 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3841 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3842 struct mlx5_flow_dv_push_vlan_action_resource *cache;
3843 struct mlx5dv_dr_domain *domain;
3847 /* Register new port id action resource. */
3848 cache = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3850 rte_flow_error_set(ctx->error, ENOMEM,
3851 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3852 "cannot allocate push_vlan action cache memory");
3856 if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3857 domain = sh->fdb_domain;
3858 else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3859 domain = sh->rx_domain;
3861 domain = sh->tx_domain;
3862 ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
3865 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
3866 rte_flow_error_set(ctx->error, ENOMEM,
3867 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3868 "cannot create push vlan action");
3872 return &cache->entry;
3876 * Find existing push vlan resource or create and register a new one.
3878 * @param [in, out] dev
3879 * Pointer to rte_eth_dev structure.
3880 * @param[in, out] resource
3881 * Pointer to port ID action resource.
3882 * @parm[in, out] dev_flow
3883 * Pointer to the dev_flow.
3885 * pointer to error structure.
3888 * 0 on success otherwise -errno and errno is set.
3891 flow_dv_push_vlan_action_resource_register
3892 (struct rte_eth_dev *dev,
3893 struct mlx5_flow_dv_push_vlan_action_resource *resource,
3894 struct mlx5_flow *dev_flow,
3895 struct rte_flow_error *error)
3897 struct mlx5_priv *priv = dev->data->dev_private;
3898 struct mlx5_flow_dv_push_vlan_action_resource *cache;
3899 struct mlx5_cache_entry *entry;
3900 struct mlx5_flow_cb_ctx ctx = {
3905 entry = mlx5_cache_register(&priv->sh->push_vlan_action_list, &ctx);
3908 cache = container_of(entry, typeof(*cache), entry);
3910 dev_flow->handle->dvh.rix_push_vlan = cache->idx;
3911 dev_flow->dv.push_vlan_res = cache;
3916 * Get the size of specific rte_flow_item_type hdr size
3918 * @param[in] item_type
3919 * Tested rte_flow_item_type.
3922 * sizeof struct item_type, 0 if void or irrelevant.
3925 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
3929 switch (item_type) {
3930 case RTE_FLOW_ITEM_TYPE_ETH:
3931 retval = sizeof(struct rte_ether_hdr);
3933 case RTE_FLOW_ITEM_TYPE_VLAN:
3934 retval = sizeof(struct rte_vlan_hdr);
3936 case RTE_FLOW_ITEM_TYPE_IPV4:
3937 retval = sizeof(struct rte_ipv4_hdr);
3939 case RTE_FLOW_ITEM_TYPE_IPV6:
3940 retval = sizeof(struct rte_ipv6_hdr);
3942 case RTE_FLOW_ITEM_TYPE_UDP:
3943 retval = sizeof(struct rte_udp_hdr);
3945 case RTE_FLOW_ITEM_TYPE_TCP:
3946 retval = sizeof(struct rte_tcp_hdr);
3948 case RTE_FLOW_ITEM_TYPE_VXLAN:
3949 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
3950 retval = sizeof(struct rte_vxlan_hdr);
3952 case RTE_FLOW_ITEM_TYPE_GRE:
3953 case RTE_FLOW_ITEM_TYPE_NVGRE:
3954 retval = sizeof(struct rte_gre_hdr);
3956 case RTE_FLOW_ITEM_TYPE_MPLS:
3957 retval = sizeof(struct rte_mpls_hdr);
3959 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
3967 #define MLX5_ENCAP_IPV4_VERSION 0x40
3968 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
3969 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
3970 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
3971 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
3972 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
3973 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
3976 * Convert the encap action data from list of rte_flow_item to raw buffer
3979 * Pointer to rte_flow_item objects list.
3981 * Pointer to the output buffer.
3983 * Pointer to the output buffer size.
3985 * Pointer to the error structure.
3988 * 0 on success, a negative errno value otherwise and rte_errno is set.
3991 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
3992 size_t *size, struct rte_flow_error *error)
3994 struct rte_ether_hdr *eth = NULL;
3995 struct rte_vlan_hdr *vlan = NULL;
3996 struct rte_ipv4_hdr *ipv4 = NULL;
3997 struct rte_ipv6_hdr *ipv6 = NULL;
3998 struct rte_udp_hdr *udp = NULL;
3999 struct rte_vxlan_hdr *vxlan = NULL;
4000 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4001 struct rte_gre_hdr *gre = NULL;
4003 size_t temp_size = 0;
4006 return rte_flow_error_set(error, EINVAL,
4007 RTE_FLOW_ERROR_TYPE_ACTION,
4008 NULL, "invalid empty data");
4009 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4010 len = flow_dv_get_item_hdr_len(items->type);
4011 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4012 return rte_flow_error_set(error, EINVAL,
4013 RTE_FLOW_ERROR_TYPE_ACTION,
4014 (void *)items->type,
4015 "items total size is too big"
4016 " for encap action");
4017 rte_memcpy((void *)&buf[temp_size], items->spec, len);
4018 switch (items->type) {
4019 case RTE_FLOW_ITEM_TYPE_ETH:
4020 eth = (struct rte_ether_hdr *)&buf[temp_size];
4022 case RTE_FLOW_ITEM_TYPE_VLAN:
4023 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4025 return rte_flow_error_set(error, EINVAL,
4026 RTE_FLOW_ERROR_TYPE_ACTION,
4027 (void *)items->type,
4028 "eth header not found");
4029 if (!eth->ether_type)
4030 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4032 case RTE_FLOW_ITEM_TYPE_IPV4:
4033 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4035 return rte_flow_error_set(error, EINVAL,
4036 RTE_FLOW_ERROR_TYPE_ACTION,
4037 (void *)items->type,
4038 "neither eth nor vlan"
4040 if (vlan && !vlan->eth_proto)
4041 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4042 else if (eth && !eth->ether_type)
4043 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4044 if (!ipv4->version_ihl)
4045 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4046 MLX5_ENCAP_IPV4_IHL_MIN;
4047 if (!ipv4->time_to_live)
4048 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4050 case RTE_FLOW_ITEM_TYPE_IPV6:
4051 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4053 return rte_flow_error_set(error, EINVAL,
4054 RTE_FLOW_ERROR_TYPE_ACTION,
4055 (void *)items->type,
4056 "neither eth nor vlan"
4058 if (vlan && !vlan->eth_proto)
4059 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4060 else if (eth && !eth->ether_type)
4061 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4062 if (!ipv6->vtc_flow)
4064 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4065 if (!ipv6->hop_limits)
4066 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4068 case RTE_FLOW_ITEM_TYPE_UDP:
4069 udp = (struct rte_udp_hdr *)&buf[temp_size];
4071 return rte_flow_error_set(error, EINVAL,
4072 RTE_FLOW_ERROR_TYPE_ACTION,
4073 (void *)items->type,
4074 "ip header not found");
4075 if (ipv4 && !ipv4->next_proto_id)
4076 ipv4->next_proto_id = IPPROTO_UDP;
4077 else if (ipv6 && !ipv6->proto)
4078 ipv6->proto = IPPROTO_UDP;
4080 case RTE_FLOW_ITEM_TYPE_VXLAN:
4081 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4083 return rte_flow_error_set(error, EINVAL,
4084 RTE_FLOW_ERROR_TYPE_ACTION,
4085 (void *)items->type,
4086 "udp header not found");
4088 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4089 if (!vxlan->vx_flags)
4091 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4093 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4094 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4096 return rte_flow_error_set(error, EINVAL,
4097 RTE_FLOW_ERROR_TYPE_ACTION,
4098 (void *)items->type,
4099 "udp header not found");
4100 if (!vxlan_gpe->proto)
4101 return rte_flow_error_set(error, EINVAL,
4102 RTE_FLOW_ERROR_TYPE_ACTION,
4103 (void *)items->type,
4104 "next protocol not found");
4107 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4108 if (!vxlan_gpe->vx_flags)
4109 vxlan_gpe->vx_flags =
4110 MLX5_ENCAP_VXLAN_GPE_FLAGS;
4112 case RTE_FLOW_ITEM_TYPE_GRE:
4113 case RTE_FLOW_ITEM_TYPE_NVGRE:
4114 gre = (struct rte_gre_hdr *)&buf[temp_size];
4116 return rte_flow_error_set(error, EINVAL,
4117 RTE_FLOW_ERROR_TYPE_ACTION,
4118 (void *)items->type,
4119 "next protocol not found");
4121 return rte_flow_error_set(error, EINVAL,
4122 RTE_FLOW_ERROR_TYPE_ACTION,
4123 (void *)items->type,
4124 "ip header not found");
4125 if (ipv4 && !ipv4->next_proto_id)
4126 ipv4->next_proto_id = IPPROTO_GRE;
4127 else if (ipv6 && !ipv6->proto)
4128 ipv6->proto = IPPROTO_GRE;
4130 case RTE_FLOW_ITEM_TYPE_VOID:
4133 return rte_flow_error_set(error, EINVAL,
4134 RTE_FLOW_ERROR_TYPE_ACTION,
4135 (void *)items->type,
4136 "unsupported item type");
4146 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4148 struct rte_ether_hdr *eth = NULL;
4149 struct rte_vlan_hdr *vlan = NULL;
4150 struct rte_ipv6_hdr *ipv6 = NULL;
4151 struct rte_udp_hdr *udp = NULL;
4155 eth = (struct rte_ether_hdr *)data;
4156 next_hdr = (char *)(eth + 1);
4157 proto = RTE_BE16(eth->ether_type);
4160 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4161 vlan = (struct rte_vlan_hdr *)next_hdr;
4162 proto = RTE_BE16(vlan->eth_proto);
4163 next_hdr += sizeof(struct rte_vlan_hdr);
4166 /* HW calculates IPv4 csum. no need to proceed */
4167 if (proto == RTE_ETHER_TYPE_IPV4)
4170 /* non IPv4/IPv6 header. not supported */
4171 if (proto != RTE_ETHER_TYPE_IPV6) {
4172 return rte_flow_error_set(error, ENOTSUP,
4173 RTE_FLOW_ERROR_TYPE_ACTION,
4174 NULL, "Cannot offload non IPv4/IPv6");
4177 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4179 /* ignore non UDP */
4180 if (ipv6->proto != IPPROTO_UDP)
4183 udp = (struct rte_udp_hdr *)(ipv6 + 1);
4184 udp->dgram_cksum = 0;
4190 * Convert L2 encap action to DV specification.
4193 * Pointer to rte_eth_dev structure.
4195 * Pointer to action structure.
4196 * @param[in, out] dev_flow
4197 * Pointer to the mlx5_flow.
4198 * @param[in] transfer
4199 * Mark if the flow is E-Switch flow.
4201 * Pointer to the error structure.
4204 * 0 on success, a negative errno value otherwise and rte_errno is set.
4207 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4208 const struct rte_flow_action *action,
4209 struct mlx5_flow *dev_flow,
4211 struct rte_flow_error *error)
4213 const struct rte_flow_item *encap_data;
4214 const struct rte_flow_action_raw_encap *raw_encap_data;
4215 struct mlx5_flow_dv_encap_decap_resource res = {
4217 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4218 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4219 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4222 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4224 (const struct rte_flow_action_raw_encap *)action->conf;
4225 res.size = raw_encap_data->size;
4226 memcpy(res.buf, raw_encap_data->data, res.size);
4228 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4230 ((const struct rte_flow_action_vxlan_encap *)
4231 action->conf)->definition;
4234 ((const struct rte_flow_action_nvgre_encap *)
4235 action->conf)->definition;
4236 if (flow_dv_convert_encap_data(encap_data, res.buf,
4240 if (flow_dv_zero_encap_udp_csum(res.buf, error))
4242 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4243 return rte_flow_error_set(error, EINVAL,
4244 RTE_FLOW_ERROR_TYPE_ACTION,
4245 NULL, "can't create L2 encap action");
4250 * Convert L2 decap action to DV specification.
4253 * Pointer to rte_eth_dev structure.
4254 * @param[in, out] dev_flow
4255 * Pointer to the mlx5_flow.
4256 * @param[in] transfer
4257 * Mark if the flow is E-Switch flow.
4259 * Pointer to the error structure.
4262 * 0 on success, a negative errno value otherwise and rte_errno is set.
4265 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
4266 struct mlx5_flow *dev_flow,
4268 struct rte_flow_error *error)
4270 struct mlx5_flow_dv_encap_decap_resource res = {
4273 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
4274 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4275 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
4278 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4279 return rte_flow_error_set(error, EINVAL,
4280 RTE_FLOW_ERROR_TYPE_ACTION,
4281 NULL, "can't create L2 decap action");
4286 * Convert raw decap/encap (L3 tunnel) action to DV specification.
4289 * Pointer to rte_eth_dev structure.
4291 * Pointer to action structure.
4292 * @param[in, out] dev_flow
4293 * Pointer to the mlx5_flow.
4295 * Pointer to the flow attributes.
4297 * Pointer to the error structure.
4300 * 0 on success, a negative errno value otherwise and rte_errno is set.
4303 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
4304 const struct rte_flow_action *action,
4305 struct mlx5_flow *dev_flow,
4306 const struct rte_flow_attr *attr,
4307 struct rte_flow_error *error)
4309 const struct rte_flow_action_raw_encap *encap_data;
4310 struct mlx5_flow_dv_encap_decap_resource res;
4312 memset(&res, 0, sizeof(res));
4313 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
4314 res.size = encap_data->size;
4315 memcpy(res.buf, encap_data->data, res.size);
4316 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
4317 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
4318 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
4320 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4322 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4323 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4324 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4325 return rte_flow_error_set(error, EINVAL,
4326 RTE_FLOW_ERROR_TYPE_ACTION,
4327 NULL, "can't create encap action");
4332 * Create action push VLAN.
4335 * Pointer to rte_eth_dev structure.
4337 * Pointer to the flow attributes.
4339 * Pointer to the vlan to push to the Ethernet header.
4340 * @param[in, out] dev_flow
4341 * Pointer to the mlx5_flow.
4343 * Pointer to the error structure.
4346 * 0 on success, a negative errno value otherwise and rte_errno is set.
4349 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
4350 const struct rte_flow_attr *attr,
4351 const struct rte_vlan_hdr *vlan,
4352 struct mlx5_flow *dev_flow,
4353 struct rte_flow_error *error)
4355 struct mlx5_flow_dv_push_vlan_action_resource res;
4357 memset(&res, 0, sizeof(res));
4359 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
4362 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4364 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4365 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4366 return flow_dv_push_vlan_action_resource_register
4367 (dev, &res, dev_flow, error);
4371 * Validate the modify-header actions.
4373 * @param[in] action_flags
4374 * Holds the actions detected until now.
4376 * Pointer to the modify action.
4378 * Pointer to error structure.
4381 * 0 on success, a negative errno value otherwise and rte_errno is set.
4384 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
4385 const struct rte_flow_action *action,
4386 struct rte_flow_error *error)
4388 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
4389 return rte_flow_error_set(error, EINVAL,
4390 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4391 NULL, "action configuration not set");
4392 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4393 return rte_flow_error_set(error, EINVAL,
4394 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4395 "can't have encap action before"
4401 * Validate the modify-header MAC address actions.
4403 * @param[in] action_flags
4404 * Holds the actions detected until now.
4406 * Pointer to the modify action.
4407 * @param[in] item_flags
4408 * Holds the items detected.
4410 * Pointer to error structure.
4413 * 0 on success, a negative errno value otherwise and rte_errno is set.
4416 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
4417 const struct rte_flow_action *action,
4418 const uint64_t item_flags,
4419 struct rte_flow_error *error)
4423 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4425 if (!(item_flags & MLX5_FLOW_LAYER_L2))
4426 return rte_flow_error_set(error, EINVAL,
4427 RTE_FLOW_ERROR_TYPE_ACTION,
4429 "no L2 item in pattern");
4435 * Validate the modify-header IPv4 address actions.
4437 * @param[in] action_flags
4438 * Holds the actions detected until now.
4440 * Pointer to the modify action.
4441 * @param[in] item_flags
4442 * Holds the items detected.
4444 * Pointer to error structure.
4447 * 0 on success, a negative errno value otherwise and rte_errno is set.
4450 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
4451 const struct rte_flow_action *action,
4452 const uint64_t item_flags,
4453 struct rte_flow_error *error)
4458 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4460 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4461 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4462 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4463 if (!(item_flags & layer))
4464 return rte_flow_error_set(error, EINVAL,
4465 RTE_FLOW_ERROR_TYPE_ACTION,
4467 "no ipv4 item in pattern");
4473 * Validate the modify-header IPv6 address actions.
4475 * @param[in] action_flags
4476 * Holds the actions detected until now.
4478 * Pointer to the modify action.
4479 * @param[in] item_flags
4480 * Holds the items detected.
4482 * Pointer to error structure.
4485 * 0 on success, a negative errno value otherwise and rte_errno is set.
4488 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
4489 const struct rte_flow_action *action,
4490 const uint64_t item_flags,
4491 struct rte_flow_error *error)
4496 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4498 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4499 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4500 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4501 if (!(item_flags & layer))
4502 return rte_flow_error_set(error, EINVAL,
4503 RTE_FLOW_ERROR_TYPE_ACTION,
4505 "no ipv6 item in pattern");
4511 * Validate the modify-header TP actions.
4513 * @param[in] action_flags
4514 * Holds the actions detected until now.
4516 * Pointer to the modify action.
4517 * @param[in] item_flags
4518 * Holds the items detected.
4520 * Pointer to error structure.
4523 * 0 on success, a negative errno value otherwise and rte_errno is set.
4526 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
4527 const struct rte_flow_action *action,
4528 const uint64_t item_flags,
4529 struct rte_flow_error *error)
4534 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4536 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4537 MLX5_FLOW_LAYER_INNER_L4 :
4538 MLX5_FLOW_LAYER_OUTER_L4;
4539 if (!(item_flags & layer))
4540 return rte_flow_error_set(error, EINVAL,
4541 RTE_FLOW_ERROR_TYPE_ACTION,
4542 NULL, "no transport layer "
4549 * Validate the modify-header actions of increment/decrement
4550 * TCP Sequence-number.
4552 * @param[in] action_flags
4553 * Holds the actions detected until now.
4555 * Pointer to the modify action.
4556 * @param[in] item_flags
4557 * Holds the items detected.
4559 * Pointer to error structure.
4562 * 0 on success, a negative errno value otherwise and rte_errno is set.
4565 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
4566 const struct rte_flow_action *action,
4567 const uint64_t item_flags,
4568 struct rte_flow_error *error)
4573 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4575 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4576 MLX5_FLOW_LAYER_INNER_L4_TCP :
4577 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4578 if (!(item_flags & layer))
4579 return rte_flow_error_set(error, EINVAL,
4580 RTE_FLOW_ERROR_TYPE_ACTION,
4581 NULL, "no TCP item in"
4583 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
4584 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
4585 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
4586 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
4587 return rte_flow_error_set(error, EINVAL,
4588 RTE_FLOW_ERROR_TYPE_ACTION,
4590 "cannot decrease and increase"
4591 " TCP sequence number"
4592 " at the same time");
4598 * Validate the modify-header actions of increment/decrement
4599 * TCP Acknowledgment number.
4601 * @param[in] action_flags
4602 * Holds the actions detected until now.
4604 * Pointer to the modify action.
4605 * @param[in] item_flags
4606 * Holds the items detected.
4608 * Pointer to error structure.
4611 * 0 on success, a negative errno value otherwise and rte_errno is set.
4614 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
4615 const struct rte_flow_action *action,
4616 const uint64_t item_flags,
4617 struct rte_flow_error *error)
4622 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4624 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4625 MLX5_FLOW_LAYER_INNER_L4_TCP :
4626 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4627 if (!(item_flags & layer))
4628 return rte_flow_error_set(error, EINVAL,
4629 RTE_FLOW_ERROR_TYPE_ACTION,
4630 NULL, "no TCP item in"
4632 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
4633 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
4634 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
4635 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
4636 return rte_flow_error_set(error, EINVAL,
4637 RTE_FLOW_ERROR_TYPE_ACTION,
4639 "cannot decrease and increase"
4640 " TCP acknowledgment number"
4641 " at the same time");
4647 * Validate the modify-header TTL actions.
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_ttl(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_L3 :
4674 MLX5_FLOW_LAYER_OUTER_L3;
4675 if (!(item_flags & layer))
4676 return rte_flow_error_set(error, EINVAL,
4677 RTE_FLOW_ERROR_TYPE_ACTION,
4679 "no IP protocol in pattern");
4685 * Validate the generic modify field actions.
4687 * Pointer to the rte_eth_dev structure.
4688 * @param[in] action_flags
4689 * Holds the actions detected until now.
4691 * Pointer to the modify action.
4693 * Pointer to the flow attributes.
4695 * Pointer to error structure.
4698 * Number of header fields to modify (0 or more) on success,
4699 * a negative errno value otherwise and rte_errno is set.
4702 flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
4703 const uint64_t action_flags,
4704 const struct rte_flow_action *action,
4705 const struct rte_flow_attr *attr,
4706 struct rte_flow_error *error)
4709 struct mlx5_priv *priv = dev->data->dev_private;
4710 struct mlx5_dev_config *config = &priv->config;
4711 const struct rte_flow_action_modify_field *action_modify_field =
4713 uint32_t dst_width =
4714 mlx5_flow_item_field_width(action_modify_field->dst.field);
4715 uint32_t src_width =
4716 mlx5_flow_item_field_width(action_modify_field->src.field);
4718 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4722 if (action_modify_field->width == 0)
4723 return rte_flow_error_set(error, EINVAL,
4724 RTE_FLOW_ERROR_TYPE_ACTION, action,
4725 "no bits are requested to be modified");
4726 else if (action_modify_field->width > dst_width ||
4727 action_modify_field->width > src_width)
4728 return rte_flow_error_set(error, EINVAL,
4729 RTE_FLOW_ERROR_TYPE_ACTION, action,
4730 "cannot modify more bits than"
4731 " the width of a field");
4732 if (action_modify_field->dst.field != RTE_FLOW_FIELD_VALUE &&
4733 action_modify_field->dst.field != RTE_FLOW_FIELD_POINTER) {
4734 if ((action_modify_field->dst.offset +
4735 action_modify_field->width > dst_width) ||
4736 (action_modify_field->dst.offset % 32))
4737 return rte_flow_error_set(error, EINVAL,
4738 RTE_FLOW_ERROR_TYPE_ACTION, action,
4739 "destination offset is too big"
4740 " or not aligned to 4 bytes");
4741 if (action_modify_field->dst.level &&
4742 action_modify_field->dst.field != RTE_FLOW_FIELD_TAG)
4743 return rte_flow_error_set(error, ENOTSUP,
4744 RTE_FLOW_ERROR_TYPE_ACTION, action,
4745 "inner header fields modification"
4746 " is not supported");
4748 if (action_modify_field->src.field != RTE_FLOW_FIELD_VALUE &&
4749 action_modify_field->src.field != RTE_FLOW_FIELD_POINTER) {
4750 if (!attr->transfer && !attr->group)
4751 return rte_flow_error_set(error, ENOTSUP,
4752 RTE_FLOW_ERROR_TYPE_ACTION, action,
4753 "modify field action is not"
4754 " supported for group 0");
4755 if ((action_modify_field->src.offset +
4756 action_modify_field->width > src_width) ||
4757 (action_modify_field->src.offset % 32))
4758 return rte_flow_error_set(error, EINVAL,
4759 RTE_FLOW_ERROR_TYPE_ACTION, action,
4760 "source offset is too big"
4761 " or not aligned to 4 bytes");
4762 if (action_modify_field->src.level &&
4763 action_modify_field->src.field != RTE_FLOW_FIELD_TAG)
4764 return rte_flow_error_set(error, ENOTSUP,
4765 RTE_FLOW_ERROR_TYPE_ACTION, action,
4766 "inner header fields modification"
4767 " is not supported");
4769 if (action_modify_field->dst.field ==
4770 action_modify_field->src.field)
4771 return rte_flow_error_set(error, EINVAL,
4772 RTE_FLOW_ERROR_TYPE_ACTION, action,
4773 "source and destination fields"
4774 " cannot be the same");
4775 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VALUE ||
4776 action_modify_field->dst.field == RTE_FLOW_FIELD_POINTER)
4777 return rte_flow_error_set(error, EINVAL,
4778 RTE_FLOW_ERROR_TYPE_ACTION, action,
4779 "immediate value or a pointer to it"
4780 " cannot be used as a destination");
4781 if (action_modify_field->dst.field == RTE_FLOW_FIELD_START ||
4782 action_modify_field->src.field == RTE_FLOW_FIELD_START)
4783 return rte_flow_error_set(error, ENOTSUP,
4784 RTE_FLOW_ERROR_TYPE_ACTION, action,
4785 "modifications of an arbitrary"
4786 " place in a packet is not supported");
4787 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VLAN_TYPE ||
4788 action_modify_field->src.field == RTE_FLOW_FIELD_VLAN_TYPE)
4789 return rte_flow_error_set(error, ENOTSUP,
4790 RTE_FLOW_ERROR_TYPE_ACTION, action,
4791 "modifications of the 802.1Q Tag"
4792 " Identifier is not supported");
4793 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VXLAN_VNI ||
4794 action_modify_field->src.field == RTE_FLOW_FIELD_VXLAN_VNI)
4795 return rte_flow_error_set(error, ENOTSUP,
4796 RTE_FLOW_ERROR_TYPE_ACTION, action,
4797 "modifications of the VXLAN Network"
4798 " Identifier is not supported");
4799 if (action_modify_field->dst.field == RTE_FLOW_FIELD_GENEVE_VNI ||
4800 action_modify_field->src.field == RTE_FLOW_FIELD_GENEVE_VNI)
4801 return rte_flow_error_set(error, ENOTSUP,
4802 RTE_FLOW_ERROR_TYPE_ACTION, action,
4803 "modifications of the GENEVE Network"
4804 " Identifier is not supported");
4805 if (action_modify_field->dst.field == RTE_FLOW_FIELD_MARK ||
4806 action_modify_field->src.field == RTE_FLOW_FIELD_MARK ||
4807 action_modify_field->dst.field == RTE_FLOW_FIELD_META ||
4808 action_modify_field->src.field == RTE_FLOW_FIELD_META) {
4809 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4810 !mlx5_flow_ext_mreg_supported(dev))
4811 return rte_flow_error_set(error, ENOTSUP,
4812 RTE_FLOW_ERROR_TYPE_ACTION, action,
4813 "cannot modify mark or metadata without"
4814 " extended metadata register support");
4816 if (action_modify_field->operation != RTE_FLOW_MODIFY_SET)
4817 return rte_flow_error_set(error, ENOTSUP,
4818 RTE_FLOW_ERROR_TYPE_ACTION, action,
4819 "add and sub operations"
4820 " are not supported");
4821 return (action_modify_field->width / 32) +
4822 !!(action_modify_field->width % 32);
4826 * Validate jump action.
4829 * Pointer to the jump action.
4830 * @param[in] action_flags
4831 * Holds the actions detected until now.
4832 * @param[in] attributes
4833 * Pointer to flow attributes
4834 * @param[in] external
4835 * Action belongs to flow rule created by request external to PMD.
4837 * Pointer to error structure.
4840 * 0 on success, a negative errno value otherwise and rte_errno is set.
4843 flow_dv_validate_action_jump(struct rte_eth_dev *dev,
4844 const struct mlx5_flow_tunnel *tunnel,
4845 const struct rte_flow_action *action,
4846 uint64_t action_flags,
4847 const struct rte_flow_attr *attributes,
4848 bool external, struct rte_flow_error *error)
4850 uint32_t target_group, table;
4852 struct flow_grp_info grp_info = {
4853 .external = !!external,
4854 .transfer = !!attributes->transfer,
4858 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4859 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4860 return rte_flow_error_set(error, EINVAL,
4861 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4862 "can't have 2 fate actions in"
4865 return rte_flow_error_set(error, EINVAL,
4866 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4867 NULL, "action configuration not set");
4869 ((const struct rte_flow_action_jump *)action->conf)->group;
4870 ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
4874 if (attributes->group == target_group &&
4875 !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
4876 MLX5_FLOW_ACTION_TUNNEL_MATCH)))
4877 return rte_flow_error_set(error, EINVAL,
4878 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4879 "target group must be other than"
4880 " the current flow group");
4885 * Validate the port_id action.
4888 * Pointer to rte_eth_dev structure.
4889 * @param[in] action_flags
4890 * Bit-fields that holds the actions detected until now.
4892 * Port_id RTE action structure.
4894 * Attributes of flow that includes this action.
4896 * Pointer to error structure.
4899 * 0 on success, a negative errno value otherwise and rte_errno is set.
4902 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
4903 uint64_t action_flags,
4904 const struct rte_flow_action *action,
4905 const struct rte_flow_attr *attr,
4906 struct rte_flow_error *error)
4908 const struct rte_flow_action_port_id *port_id;
4909 struct mlx5_priv *act_priv;
4910 struct mlx5_priv *dev_priv;
4913 if (!attr->transfer)
4914 return rte_flow_error_set(error, ENOTSUP,
4915 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4917 "port id action is valid in transfer"
4919 if (!action || !action->conf)
4920 return rte_flow_error_set(error, ENOTSUP,
4921 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4923 "port id action parameters must be"
4925 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4926 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4927 return rte_flow_error_set(error, EINVAL,
4928 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4929 "can have only one fate actions in"
4931 dev_priv = mlx5_dev_to_eswitch_info(dev);
4933 return rte_flow_error_set(error, rte_errno,
4934 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4936 "failed to obtain E-Switch info");
4937 port_id = action->conf;
4938 port = port_id->original ? dev->data->port_id : port_id->id;
4939 act_priv = mlx5_port_to_eswitch_info(port, false);
4941 return rte_flow_error_set
4943 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
4944 "failed to obtain E-Switch port id for port");
4945 if (act_priv->domain_id != dev_priv->domain_id)
4946 return rte_flow_error_set
4948 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4949 "port does not belong to"
4950 " E-Switch being configured");
4955 * Get the maximum number of modify header actions.
4958 * Pointer to rte_eth_dev structure.
4960 * Flags bits to check if root level.
4963 * Max number of modify header actions device can support.
4965 static inline unsigned int
4966 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
4970 * There's no way to directly query the max capacity from FW.
4971 * The maximal value on root table should be assumed to be supported.
4973 if (!(flags & MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL))
4974 return MLX5_MAX_MODIFY_NUM;
4976 return MLX5_ROOT_TBL_MODIFY_NUM;
4980 * Validate the meter action.
4983 * Pointer to rte_eth_dev structure.
4984 * @param[in] action_flags
4985 * Bit-fields that holds the actions detected until now.
4987 * Pointer to the meter action.
4989 * Attributes of flow that includes this action.
4991 * Pointer to error structure.
4994 * 0 on success, a negative errno value otherwise and rte_ernno is set.
4997 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
4998 uint64_t action_flags,
4999 const struct rte_flow_action *action,
5000 const struct rte_flow_attr *attr,
5002 struct rte_flow_error *error)
5004 struct mlx5_priv *priv = dev->data->dev_private;
5005 const struct rte_flow_action_meter *am = action->conf;
5006 struct mlx5_flow_meter_info *fm;
5007 struct mlx5_flow_meter_policy *mtr_policy;
5008 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5011 return rte_flow_error_set(error, EINVAL,
5012 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5013 "meter action conf is NULL");
5015 if (action_flags & MLX5_FLOW_ACTION_METER)
5016 return rte_flow_error_set(error, ENOTSUP,
5017 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5018 "meter chaining not support");
5019 if (action_flags & MLX5_FLOW_ACTION_JUMP)
5020 return rte_flow_error_set(error, ENOTSUP,
5021 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5022 "meter with jump not support");
5024 return rte_flow_error_set(error, ENOTSUP,
5025 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5027 "meter action not supported");
5028 fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5030 return rte_flow_error_set(error, EINVAL,
5031 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5033 /* aso meter can always be shared by different domains */
5034 if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5035 !(fm->transfer == attr->transfer ||
5036 (!fm->ingress && !attr->ingress && attr->egress) ||
5037 (!fm->egress && !attr->egress && attr->ingress)))
5038 return rte_flow_error_set(error, EINVAL,
5039 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5040 "Flow attributes domain are either invalid "
5041 "or have a domain conflict with current "
5042 "meter attributes");
5043 if (fm->def_policy) {
5044 if (!((attr->transfer &&
5045 mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
5047 mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
5049 mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
5050 return rte_flow_error_set(error, EINVAL,
5051 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5052 "Flow attributes domain "
5053 "have a conflict with current "
5054 "meter domain attributes");
5057 mtr_policy = mlx5_flow_meter_policy_find(dev,
5058 fm->policy_id, NULL);
5060 return rte_flow_error_set(error, EINVAL,
5061 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5062 "Invalid policy id for meter ");
5063 if (!((attr->transfer && mtr_policy->transfer) ||
5064 (attr->egress && mtr_policy->egress) ||
5065 (attr->ingress && mtr_policy->ingress)))
5066 return rte_flow_error_set(error, EINVAL,
5067 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5068 "Flow attributes domain "
5069 "have a conflict with current "
5070 "meter domain attributes");
5071 *def_policy = false;
5077 * Validate the age action.
5079 * @param[in] action_flags
5080 * Holds the actions detected until now.
5082 * Pointer to the age action.
5084 * Pointer to the Ethernet device structure.
5086 * Pointer to error structure.
5089 * 0 on success, a negative errno value otherwise and rte_errno is set.
5092 flow_dv_validate_action_age(uint64_t action_flags,
5093 const struct rte_flow_action *action,
5094 struct rte_eth_dev *dev,
5095 struct rte_flow_error *error)
5097 struct mlx5_priv *priv = dev->data->dev_private;
5098 const struct rte_flow_action_age *age = action->conf;
5100 if (!priv->config.devx || (priv->sh->cmng.counter_fallback &&
5101 !priv->sh->aso_age_mng))
5102 return rte_flow_error_set(error, ENOTSUP,
5103 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5105 "age action not supported");
5106 if (!(action->conf))
5107 return rte_flow_error_set(error, EINVAL,
5108 RTE_FLOW_ERROR_TYPE_ACTION, action,
5109 "configuration cannot be null");
5110 if (!(age->timeout))
5111 return rte_flow_error_set(error, EINVAL,
5112 RTE_FLOW_ERROR_TYPE_ACTION, action,
5113 "invalid timeout value 0");
5114 if (action_flags & MLX5_FLOW_ACTION_AGE)
5115 return rte_flow_error_set(error, EINVAL,
5116 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5117 "duplicate age actions set");
5122 * Validate the modify-header IPv4 DSCP actions.
5124 * @param[in] action_flags
5125 * Holds the actions detected until now.
5127 * Pointer to the modify action.
5128 * @param[in] item_flags
5129 * Holds the items detected.
5131 * Pointer to error structure.
5134 * 0 on success, a negative errno value otherwise and rte_errno is set.
5137 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
5138 const struct rte_flow_action *action,
5139 const uint64_t item_flags,
5140 struct rte_flow_error *error)
5144 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5146 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
5147 return rte_flow_error_set(error, EINVAL,
5148 RTE_FLOW_ERROR_TYPE_ACTION,
5150 "no ipv4 item in pattern");
5156 * Validate the modify-header IPv6 DSCP actions.
5158 * @param[in] action_flags
5159 * Holds the actions detected until now.
5161 * Pointer to the modify action.
5162 * @param[in] item_flags
5163 * Holds the items detected.
5165 * Pointer to error structure.
5168 * 0 on success, a negative errno value otherwise and rte_errno is set.
5171 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
5172 const struct rte_flow_action *action,
5173 const uint64_t item_flags,
5174 struct rte_flow_error *error)
5178 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5180 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
5181 return rte_flow_error_set(error, EINVAL,
5182 RTE_FLOW_ERROR_TYPE_ACTION,
5184 "no ipv6 item in pattern");
5190 * Match modify-header resource.
5193 * Pointer to the hash list.
5195 * Pointer to exist resource entry object.
5197 * Key of the new entry.
5199 * Pointer to new modify-header resource.
5202 * 0 on matching, non-zero otherwise.
5205 flow_dv_modify_match_cb(struct mlx5_hlist *list __rte_unused,
5206 struct mlx5_hlist_entry *entry,
5207 uint64_t key __rte_unused, void *cb_ctx)
5209 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5210 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5211 struct mlx5_flow_dv_modify_hdr_resource *resource =
5212 container_of(entry, typeof(*resource), entry);
5213 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5215 key_len += ref->actions_num * sizeof(ref->actions[0]);
5216 return ref->actions_num != resource->actions_num ||
5217 memcmp(&ref->ft_type, &resource->ft_type, key_len);
5220 struct mlx5_hlist_entry *
5221 flow_dv_modify_create_cb(struct mlx5_hlist *list, uint64_t key __rte_unused,
5224 struct mlx5_dev_ctx_shared *sh = list->ctx;
5225 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5226 struct mlx5dv_dr_domain *ns;
5227 struct mlx5_flow_dv_modify_hdr_resource *entry;
5228 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5230 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5231 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5233 entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry) + data_len, 0,
5236 rte_flow_error_set(ctx->error, ENOMEM,
5237 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5238 "cannot allocate resource memory");
5241 rte_memcpy(&entry->ft_type,
5242 RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
5243 key_len + data_len);
5244 if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
5245 ns = sh->fdb_domain;
5246 else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
5250 ret = mlx5_flow_os_create_flow_action_modify_header
5251 (sh->ctx, ns, entry,
5252 data_len, &entry->action);
5255 rte_flow_error_set(ctx->error, ENOMEM,
5256 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5257 NULL, "cannot create modification action");
5260 return &entry->entry;
5264 * Validate the sample action.
5266 * @param[in, out] action_flags
5267 * Holds the actions detected until now.
5269 * Pointer to the sample action.
5271 * Pointer to the Ethernet device structure.
5273 * Attributes of flow that includes this action.
5274 * @param[in] item_flags
5275 * Holds the items detected.
5277 * Pointer to the RSS action.
5278 * @param[out] sample_rss
5279 * Pointer to the RSS action in sample action list.
5281 * Pointer to the COUNT action in sample action list.
5282 * @param[out] fdb_mirror_limit
5283 * Pointer to the FDB mirror limitation flag.
5285 * Pointer to error structure.
5288 * 0 on success, a negative errno value otherwise and rte_errno is set.
5291 flow_dv_validate_action_sample(uint64_t *action_flags,
5292 const struct rte_flow_action *action,
5293 struct rte_eth_dev *dev,
5294 const struct rte_flow_attr *attr,
5295 uint64_t item_flags,
5296 const struct rte_flow_action_rss *rss,
5297 const struct rte_flow_action_rss **sample_rss,
5298 const struct rte_flow_action_count **count,
5299 int *fdb_mirror_limit,
5300 struct rte_flow_error *error)
5302 struct mlx5_priv *priv = dev->data->dev_private;
5303 struct mlx5_dev_config *dev_conf = &priv->config;
5304 const struct rte_flow_action_sample *sample = action->conf;
5305 const struct rte_flow_action *act;
5306 uint64_t sub_action_flags = 0;
5307 uint16_t queue_index = 0xFFFF;
5312 return rte_flow_error_set(error, EINVAL,
5313 RTE_FLOW_ERROR_TYPE_ACTION, action,
5314 "configuration cannot be NULL");
5315 if (sample->ratio == 0)
5316 return rte_flow_error_set(error, EINVAL,
5317 RTE_FLOW_ERROR_TYPE_ACTION, action,
5318 "ratio value starts from 1");
5319 if (!priv->config.devx || (sample->ratio > 0 && !priv->sampler_en))
5320 return rte_flow_error_set(error, ENOTSUP,
5321 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5323 "sample action not supported");
5324 if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
5325 return rte_flow_error_set(error, EINVAL,
5326 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5327 "Multiple sample actions not "
5329 if (*action_flags & MLX5_FLOW_ACTION_METER)
5330 return rte_flow_error_set(error, EINVAL,
5331 RTE_FLOW_ERROR_TYPE_ACTION, action,
5332 "wrong action order, meter should "
5333 "be after sample action");
5334 if (*action_flags & MLX5_FLOW_ACTION_JUMP)
5335 return rte_flow_error_set(error, EINVAL,
5336 RTE_FLOW_ERROR_TYPE_ACTION, action,
5337 "wrong action order, jump should "
5338 "be after sample action");
5339 act = sample->actions;
5340 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
5341 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5342 return rte_flow_error_set(error, ENOTSUP,
5343 RTE_FLOW_ERROR_TYPE_ACTION,
5344 act, "too many actions");
5345 switch (act->type) {
5346 case RTE_FLOW_ACTION_TYPE_QUEUE:
5347 ret = mlx5_flow_validate_action_queue(act,
5353 queue_index = ((const struct rte_flow_action_queue *)
5354 (act->conf))->index;
5355 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
5358 case RTE_FLOW_ACTION_TYPE_RSS:
5359 *sample_rss = act->conf;
5360 ret = mlx5_flow_validate_action_rss(act,
5367 if (rss && *sample_rss &&
5368 ((*sample_rss)->level != rss->level ||
5369 (*sample_rss)->types != rss->types))
5370 return rte_flow_error_set(error, ENOTSUP,
5371 RTE_FLOW_ERROR_TYPE_ACTION,
5373 "Can't use the different RSS types "
5374 "or level in the same flow");
5375 if (*sample_rss != NULL && (*sample_rss)->queue_num)
5376 queue_index = (*sample_rss)->queue[0];
5377 sub_action_flags |= MLX5_FLOW_ACTION_RSS;
5380 case RTE_FLOW_ACTION_TYPE_MARK:
5381 ret = flow_dv_validate_action_mark(dev, act,
5386 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
5387 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
5388 MLX5_FLOW_ACTION_MARK_EXT;
5390 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
5393 case RTE_FLOW_ACTION_TYPE_COUNT:
5394 ret = flow_dv_validate_action_count
5395 (dev, is_shared_action_count(act),
5396 *action_flags | sub_action_flags,
5401 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
5402 *action_flags |= MLX5_FLOW_ACTION_COUNT;
5405 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5406 ret = flow_dv_validate_action_port_id(dev,
5413 sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5416 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5417 ret = flow_dv_validate_action_raw_encap_decap
5418 (dev, NULL, act->conf, attr, &sub_action_flags,
5419 &actions_n, action, item_flags, error);
5424 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5425 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5426 ret = flow_dv_validate_action_l2_encap(dev,
5432 sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
5436 return rte_flow_error_set(error, ENOTSUP,
5437 RTE_FLOW_ERROR_TYPE_ACTION,
5439 "Doesn't support optional "
5443 if (attr->ingress && !attr->transfer) {
5444 if (!(sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
5445 MLX5_FLOW_ACTION_RSS)))
5446 return rte_flow_error_set(error, EINVAL,
5447 RTE_FLOW_ERROR_TYPE_ACTION,
5449 "Ingress must has a dest "
5450 "QUEUE for Sample");
5451 } else if (attr->egress && !attr->transfer) {
5452 return rte_flow_error_set(error, ENOTSUP,
5453 RTE_FLOW_ERROR_TYPE_ACTION,
5455 "Sample Only support Ingress "
5457 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
5458 MLX5_ASSERT(attr->transfer);
5459 if (sample->ratio > 1)
5460 return rte_flow_error_set(error, ENOTSUP,
5461 RTE_FLOW_ERROR_TYPE_ACTION,
5463 "E-Switch doesn't support "
5464 "any optional action "
5466 if (sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
5467 return rte_flow_error_set(error, ENOTSUP,
5468 RTE_FLOW_ERROR_TYPE_ACTION,
5470 "unsupported action QUEUE");
5471 if (sub_action_flags & MLX5_FLOW_ACTION_RSS)
5472 return rte_flow_error_set(error, ENOTSUP,
5473 RTE_FLOW_ERROR_TYPE_ACTION,
5475 "unsupported action QUEUE");
5476 if (!(sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
5477 return rte_flow_error_set(error, EINVAL,
5478 RTE_FLOW_ERROR_TYPE_ACTION,
5480 "E-Switch must has a dest "
5481 "port for mirroring");
5482 if (!priv->config.hca_attr.reg_c_preserve &&
5483 priv->representor_id != -1)
5484 *fdb_mirror_limit = 1;
5486 /* Continue validation for Xcap actions.*/
5487 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
5488 (queue_index == 0xFFFF ||
5489 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5490 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5491 MLX5_FLOW_XCAP_ACTIONS)
5492 return rte_flow_error_set(error, ENOTSUP,
5493 RTE_FLOW_ERROR_TYPE_ACTION,
5494 NULL, "encap and decap "
5495 "combination aren't "
5497 if (!attr->transfer && attr->ingress && (sub_action_flags &
5498 MLX5_FLOW_ACTION_ENCAP))
5499 return rte_flow_error_set(error, ENOTSUP,
5500 RTE_FLOW_ERROR_TYPE_ACTION,
5501 NULL, "encap is not supported"
5502 " for ingress traffic");
5508 * Find existing modify-header resource or create and register a new one.
5510 * @param dev[in, out]
5511 * Pointer to rte_eth_dev structure.
5512 * @param[in, out] resource
5513 * Pointer to modify-header resource.
5514 * @parm[in, out] dev_flow
5515 * Pointer to the dev_flow.
5517 * pointer to error structure.
5520 * 0 on success otherwise -errno and errno is set.
5523 flow_dv_modify_hdr_resource_register
5524 (struct rte_eth_dev *dev,
5525 struct mlx5_flow_dv_modify_hdr_resource *resource,
5526 struct mlx5_flow *dev_flow,
5527 struct rte_flow_error *error)
5529 struct mlx5_priv *priv = dev->data->dev_private;
5530 struct mlx5_dev_ctx_shared *sh = priv->sh;
5531 uint32_t key_len = sizeof(*resource) -
5532 offsetof(typeof(*resource), ft_type) +
5533 resource->actions_num * sizeof(resource->actions[0]);
5534 struct mlx5_hlist_entry *entry;
5535 struct mlx5_flow_cb_ctx ctx = {
5541 resource->flags = dev_flow->dv.group ? 0 :
5542 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
5543 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
5545 return rte_flow_error_set(error, EOVERFLOW,
5546 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5547 "too many modify header items");
5548 key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
5549 entry = mlx5_hlist_register(sh->modify_cmds, key64, &ctx);
5552 resource = container_of(entry, typeof(*resource), entry);
5553 dev_flow->handle->dvh.modify_hdr = resource;
5558 * Get DV flow counter by index.
5561 * Pointer to the Ethernet device structure.
5563 * mlx5 flow counter index in the container.
5565 * mlx5 flow counter pool in the container.
5568 * Pointer to the counter, NULL otherwise.
5570 static struct mlx5_flow_counter *
5571 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
5573 struct mlx5_flow_counter_pool **ppool)
5575 struct mlx5_priv *priv = dev->data->dev_private;
5576 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5577 struct mlx5_flow_counter_pool *pool;
5579 /* Decrease to original index and clear shared bit. */
5580 idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
5581 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cmng->n);
5582 pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
5586 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
5590 * Check the devx counter belongs to the pool.
5593 * Pointer to the counter pool.
5595 * The counter devx ID.
5598 * True if counter belongs to the pool, false otherwise.
5601 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
5603 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
5604 MLX5_COUNTERS_PER_POOL;
5606 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
5612 * Get a pool by devx counter ID.
5615 * Pointer to the counter management.
5617 * The counter devx ID.
5620 * The counter pool pointer if exists, NULL otherwise,
5622 static struct mlx5_flow_counter_pool *
5623 flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
5626 struct mlx5_flow_counter_pool *pool = NULL;
5628 rte_spinlock_lock(&cmng->pool_update_sl);
5629 /* Check last used pool. */
5630 if (cmng->last_pool_idx != POOL_IDX_INVALID &&
5631 flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
5632 pool = cmng->pools[cmng->last_pool_idx];
5635 /* ID out of range means no suitable pool in the container. */
5636 if (id > cmng->max_id || id < cmng->min_id)
5639 * Find the pool from the end of the container, since mostly counter
5640 * ID is sequence increasing, and the last pool should be the needed
5645 struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
5647 if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
5653 rte_spinlock_unlock(&cmng->pool_update_sl);
5658 * Resize a counter container.
5661 * Pointer to the Ethernet device structure.
5664 * 0 on success, otherwise negative errno value and rte_errno is set.
5667 flow_dv_container_resize(struct rte_eth_dev *dev)
5669 struct mlx5_priv *priv = dev->data->dev_private;
5670 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5671 void *old_pools = cmng->pools;
5672 uint32_t resize = cmng->n + MLX5_CNT_CONTAINER_RESIZE;
5673 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
5674 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
5681 memcpy(pools, old_pools, cmng->n *
5682 sizeof(struct mlx5_flow_counter_pool *));
5684 cmng->pools = pools;
5686 mlx5_free(old_pools);
5691 * Query a devx flow counter.
5694 * Pointer to the Ethernet device structure.
5695 * @param[in] counter
5696 * Index to the flow counter.
5698 * The statistics value of packets.
5700 * The statistics value of bytes.
5703 * 0 on success, otherwise a negative errno value and rte_errno is set.
5706 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
5709 struct mlx5_priv *priv = dev->data->dev_private;
5710 struct mlx5_flow_counter_pool *pool = NULL;
5711 struct mlx5_flow_counter *cnt;
5714 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
5716 if (priv->sh->cmng.counter_fallback)
5717 return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
5718 0, pkts, bytes, 0, NULL, NULL, 0);
5719 rte_spinlock_lock(&pool->sl);
5724 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
5725 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
5726 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
5728 rte_spinlock_unlock(&pool->sl);
5733 * Create and initialize a new counter pool.
5736 * Pointer to the Ethernet device structure.
5738 * The devX counter handle.
5740 * Whether the pool is for counter that was allocated for aging.
5741 * @param[in/out] cont_cur
5742 * Pointer to the container pointer, it will be update in pool resize.
5745 * The pool container pointer on success, NULL otherwise and rte_errno is set.
5747 static struct mlx5_flow_counter_pool *
5748 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
5751 struct mlx5_priv *priv = dev->data->dev_private;
5752 struct mlx5_flow_counter_pool *pool;
5753 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5754 bool fallback = priv->sh->cmng.counter_fallback;
5755 uint32_t size = sizeof(*pool);
5757 size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
5758 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
5759 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
5765 pool->is_aged = !!age;
5766 pool->query_gen = 0;
5767 pool->min_dcs = dcs;
5768 rte_spinlock_init(&pool->sl);
5769 rte_spinlock_init(&pool->csl);
5770 TAILQ_INIT(&pool->counters[0]);
5771 TAILQ_INIT(&pool->counters[1]);
5772 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
5773 rte_spinlock_lock(&cmng->pool_update_sl);
5774 pool->index = cmng->n_valid;
5775 if (pool->index == cmng->n && flow_dv_container_resize(dev)) {
5777 rte_spinlock_unlock(&cmng->pool_update_sl);
5780 cmng->pools[pool->index] = pool;
5782 if (unlikely(fallback)) {
5783 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
5785 if (base < cmng->min_id)
5786 cmng->min_id = base;
5787 if (base > cmng->max_id)
5788 cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
5789 cmng->last_pool_idx = pool->index;
5791 rte_spinlock_unlock(&cmng->pool_update_sl);
5796 * Prepare a new counter and/or a new counter pool.
5799 * Pointer to the Ethernet device structure.
5800 * @param[out] cnt_free
5801 * Where to put the pointer of a new counter.
5803 * Whether the pool is for counter that was allocated for aging.
5806 * The counter pool pointer and @p cnt_free is set on success,
5807 * NULL otherwise and rte_errno is set.
5809 static struct mlx5_flow_counter_pool *
5810 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
5811 struct mlx5_flow_counter **cnt_free,
5814 struct mlx5_priv *priv = dev->data->dev_private;
5815 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5816 struct mlx5_flow_counter_pool *pool;
5817 struct mlx5_counters tmp_tq;
5818 struct mlx5_devx_obj *dcs = NULL;
5819 struct mlx5_flow_counter *cnt;
5820 enum mlx5_counter_type cnt_type =
5821 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
5822 bool fallback = priv->sh->cmng.counter_fallback;
5826 /* bulk_bitmap must be 0 for single counter allocation. */
5827 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
5830 pool = flow_dv_find_pool_by_id(cmng, dcs->id);
5832 pool = flow_dv_pool_create(dev, dcs, age);
5834 mlx5_devx_cmd_destroy(dcs);
5838 i = dcs->id % MLX5_COUNTERS_PER_POOL;
5839 cnt = MLX5_POOL_GET_CNT(pool, i);
5841 cnt->dcs_when_free = dcs;
5845 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
5847 rte_errno = ENODATA;
5850 pool = flow_dv_pool_create(dev, dcs, age);
5852 mlx5_devx_cmd_destroy(dcs);
5855 TAILQ_INIT(&tmp_tq);
5856 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
5857 cnt = MLX5_POOL_GET_CNT(pool, i);
5859 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
5861 rte_spinlock_lock(&cmng->csl[cnt_type]);
5862 TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
5863 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5864 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
5865 (*cnt_free)->pool = pool;
5870 * Allocate a flow counter.
5873 * Pointer to the Ethernet device structure.
5875 * Whether the counter was allocated for aging.
5878 * Index to flow counter on success, 0 otherwise and rte_errno is set.
5881 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
5883 struct mlx5_priv *priv = dev->data->dev_private;
5884 struct mlx5_flow_counter_pool *pool = NULL;
5885 struct mlx5_flow_counter *cnt_free = NULL;
5886 bool fallback = priv->sh->cmng.counter_fallback;
5887 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5888 enum mlx5_counter_type cnt_type =
5889 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
5892 if (!priv->config.devx) {
5893 rte_errno = ENOTSUP;
5896 /* Get free counters from container. */
5897 rte_spinlock_lock(&cmng->csl[cnt_type]);
5898 cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
5900 TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
5901 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5902 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
5904 pool = cnt_free->pool;
5906 cnt_free->dcs_when_active = cnt_free->dcs_when_free;
5907 /* Create a DV counter action only in the first time usage. */
5908 if (!cnt_free->action) {
5910 struct mlx5_devx_obj *dcs;
5914 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
5915 dcs = pool->min_dcs;
5918 dcs = cnt_free->dcs_when_free;
5920 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
5927 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
5928 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
5929 /* Update the counter reset values. */
5930 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
5933 if (!fallback && !priv->sh->cmng.query_thread_on)
5934 /* Start the asynchronous batch query by the host thread. */
5935 mlx5_set_query_alarm(priv->sh);
5937 * When the count action isn't shared (by ID), shared_info field is
5938 * used for indirect action API's refcnt.
5939 * When the counter action is not shared neither by ID nor by indirect
5940 * action API, shared info must be 1.
5942 cnt_free->shared_info.refcnt = 1;
5946 cnt_free->pool = pool;
5948 cnt_free->dcs_when_free = cnt_free->dcs_when_active;
5949 rte_spinlock_lock(&cmng->csl[cnt_type]);
5950 TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
5951 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5957 * Allocate a shared flow counter.
5960 * Pointer to the shared counter configuration.
5962 * Pointer to save the allocated counter index.
5965 * Index to flow counter on success, 0 otherwise and rte_errno is set.
5969 flow_dv_counter_alloc_shared_cb(void *ctx, union mlx5_l3t_data *data)
5971 struct mlx5_shared_counter_conf *conf = ctx;
5972 struct rte_eth_dev *dev = conf->dev;
5973 struct mlx5_flow_counter *cnt;
5975 data->dword = flow_dv_counter_alloc(dev, 0);
5976 data->dword |= MLX5_CNT_SHARED_OFFSET;
5977 cnt = flow_dv_counter_get_by_idx(dev, data->dword, NULL);
5978 cnt->shared_info.id = conf->id;
5983 * Get a shared flow counter.
5986 * Pointer to the Ethernet device structure.
5988 * Counter identifier.
5991 * Index to flow counter on success, 0 otherwise and rte_errno is set.
5994 flow_dv_counter_get_shared(struct rte_eth_dev *dev, uint32_t id)
5996 struct mlx5_priv *priv = dev->data->dev_private;
5997 struct mlx5_shared_counter_conf conf = {
6001 union mlx5_l3t_data data = {
6005 mlx5_l3t_prepare_entry(priv->sh->cnt_id_tbl, id, &data,
6006 flow_dv_counter_alloc_shared_cb, &conf);
6011 * Get age param from counter index.
6014 * Pointer to the Ethernet device structure.
6015 * @param[in] counter
6016 * Index to the counter handler.
6019 * The aging parameter specified for the counter index.
6021 static struct mlx5_age_param*
6022 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
6025 struct mlx5_flow_counter *cnt;
6026 struct mlx5_flow_counter_pool *pool = NULL;
6028 flow_dv_counter_get_by_idx(dev, counter, &pool);
6029 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
6030 cnt = MLX5_POOL_GET_CNT(pool, counter);
6031 return MLX5_CNT_TO_AGE(cnt);
6035 * Remove a flow counter from aged counter list.
6038 * Pointer to the Ethernet device structure.
6039 * @param[in] counter
6040 * Index to the counter handler.
6042 * Pointer to the counter handler.
6045 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
6046 uint32_t counter, struct mlx5_flow_counter *cnt)
6048 struct mlx5_age_info *age_info;
6049 struct mlx5_age_param *age_param;
6050 struct mlx5_priv *priv = dev->data->dev_private;
6051 uint16_t expected = AGE_CANDIDATE;
6053 age_info = GET_PORT_AGE_INFO(priv);
6054 age_param = flow_dv_counter_idx_get_age(dev, counter);
6055 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
6056 AGE_FREE, false, __ATOMIC_RELAXED,
6057 __ATOMIC_RELAXED)) {
6059 * We need the lock even it is age timeout,
6060 * since counter may still in process.
6062 rte_spinlock_lock(&age_info->aged_sl);
6063 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
6064 rte_spinlock_unlock(&age_info->aged_sl);
6065 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
6070 * Release a flow counter.
6073 * Pointer to the Ethernet device structure.
6074 * @param[in] counter
6075 * Index to the counter handler.
6078 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
6080 struct mlx5_priv *priv = dev->data->dev_private;
6081 struct mlx5_flow_counter_pool *pool = NULL;
6082 struct mlx5_flow_counter *cnt;
6083 enum mlx5_counter_type cnt_type;
6087 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6090 * If the counter action is shared by ID, the l3t_clear_entry function
6091 * reduces its references counter. If after the reduction the action is
6092 * still referenced, the function returns here and does not release it.
6094 if (IS_LEGACY_SHARED_CNT(counter) &&
6095 mlx5_l3t_clear_entry(priv->sh->cnt_id_tbl, cnt->shared_info.id))
6098 * If the counter action is shared by indirect action API, the atomic
6099 * function reduces its references counter. If after the reduction the
6100 * action is still referenced, the function returns here and does not
6102 * When the counter action is not shared neither by ID nor by indirect
6103 * action API, shared info is 1 before the reduction, so this condition
6104 * is failed and function doesn't return here.
6106 if (!IS_LEGACY_SHARED_CNT(counter) &&
6107 __atomic_sub_fetch(&cnt->shared_info.refcnt, 1, __ATOMIC_RELAXED))
6110 flow_dv_counter_remove_from_age(dev, counter, cnt);
6113 * Put the counter back to list to be updated in none fallback mode.
6114 * Currently, we are using two list alternately, while one is in query,
6115 * add the freed counter to the other list based on the pool query_gen
6116 * value. After query finishes, add counter the list to the global
6117 * container counter list. The list changes while query starts. In
6118 * this case, lock will not be needed as query callback and release
6119 * function both operate with the different list.
6121 if (!priv->sh->cmng.counter_fallback) {
6122 rte_spinlock_lock(&pool->csl);
6123 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
6124 rte_spinlock_unlock(&pool->csl);
6126 cnt->dcs_when_free = cnt->dcs_when_active;
6127 cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6128 MLX5_COUNTER_TYPE_ORIGIN;
6129 rte_spinlock_lock(&priv->sh->cmng.csl[cnt_type]);
6130 TAILQ_INSERT_TAIL(&priv->sh->cmng.counters[cnt_type],
6132 rte_spinlock_unlock(&priv->sh->cmng.csl[cnt_type]);
6137 * Resize a meter id container.
6140 * Pointer to the Ethernet device structure.
6143 * 0 on success, otherwise negative errno value and rte_errno is set.
6146 flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
6148 struct mlx5_priv *priv = dev->data->dev_private;
6149 struct mlx5_aso_mtr_pools_mng *pools_mng =
6150 &priv->sh->mtrmng->pools_mng;
6151 void *old_pools = pools_mng->pools;
6152 uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
6153 uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
6154 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
6161 if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER)) {
6166 memcpy(pools, old_pools, pools_mng->n *
6167 sizeof(struct mlx5_aso_mtr_pool *));
6168 pools_mng->n = resize;
6169 pools_mng->pools = pools;
6171 mlx5_free(old_pools);
6176 * Prepare a new meter and/or a new meter pool.
6179 * Pointer to the Ethernet device structure.
6180 * @param[out] mtr_free
6181 * Where to put the pointer of a new meter.g.
6184 * The meter pool pointer and @mtr_free is set on success,
6185 * NULL otherwise and rte_errno is set.
6187 static struct mlx5_aso_mtr_pool *
6188 flow_dv_mtr_pool_create(struct rte_eth_dev *dev,
6189 struct mlx5_aso_mtr **mtr_free)
6191 struct mlx5_priv *priv = dev->data->dev_private;
6192 struct mlx5_aso_mtr_pools_mng *pools_mng =
6193 &priv->sh->mtrmng->pools_mng;
6194 struct mlx5_aso_mtr_pool *pool = NULL;
6195 struct mlx5_devx_obj *dcs = NULL;
6197 uint32_t log_obj_size;
6199 log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
6200 dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->ctx,
6201 priv->sh->pdn, log_obj_size);
6203 rte_errno = ENODATA;
6206 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
6209 claim_zero(mlx5_devx_cmd_destroy(dcs));
6212 pool->devx_obj = dcs;
6213 pool->index = pools_mng->n_valid;
6214 if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
6216 claim_zero(mlx5_devx_cmd_destroy(dcs));
6219 pools_mng->pools[pool->index] = pool;
6220 pools_mng->n_valid++;
6221 for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
6222 pool->mtrs[i].offset = i;
6223 LIST_INSERT_HEAD(&pools_mng->meters,
6224 &pool->mtrs[i], next);
6226 pool->mtrs[0].offset = 0;
6227 *mtr_free = &pool->mtrs[0];
6232 * Release a flow meter into pool.
6235 * Pointer to the Ethernet device structure.
6236 * @param[in] mtr_idx
6237 * Index to aso flow meter.
6240 flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
6242 struct mlx5_priv *priv = dev->data->dev_private;
6243 struct mlx5_aso_mtr_pools_mng *pools_mng =
6244 &priv->sh->mtrmng->pools_mng;
6245 struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
6247 MLX5_ASSERT(aso_mtr);
6248 rte_spinlock_lock(&pools_mng->mtrsl);
6249 memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
6250 aso_mtr->state = ASO_METER_FREE;
6251 LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
6252 rte_spinlock_unlock(&pools_mng->mtrsl);
6256 * Allocate a aso flow meter.
6259 * Pointer to the Ethernet device structure.
6262 * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
6265 flow_dv_mtr_alloc(struct rte_eth_dev *dev)
6267 struct mlx5_priv *priv = dev->data->dev_private;
6268 struct mlx5_aso_mtr *mtr_free = NULL;
6269 struct mlx5_aso_mtr_pools_mng *pools_mng =
6270 &priv->sh->mtrmng->pools_mng;
6271 struct mlx5_aso_mtr_pool *pool;
6272 uint32_t mtr_idx = 0;
6274 if (!priv->config.devx) {
6275 rte_errno = ENOTSUP;
6278 /* Allocate the flow meter memory. */
6279 /* Get free meters from management. */
6280 rte_spinlock_lock(&pools_mng->mtrsl);
6281 mtr_free = LIST_FIRST(&pools_mng->meters);
6283 LIST_REMOVE(mtr_free, next);
6284 if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
6285 rte_spinlock_unlock(&pools_mng->mtrsl);
6288 mtr_free->state = ASO_METER_WAIT;
6289 rte_spinlock_unlock(&pools_mng->mtrsl);
6290 pool = container_of(mtr_free,
6291 struct mlx5_aso_mtr_pool,
6292 mtrs[mtr_free->offset]);
6293 mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
6294 if (!mtr_free->fm.meter_action) {
6295 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
6296 struct rte_flow_error error;
6299 reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
6300 mtr_free->fm.meter_action =
6301 mlx5_glue->dv_create_flow_action_aso
6302 (priv->sh->rx_domain,
6303 pool->devx_obj->obj,
6305 (1 << MLX5_FLOW_COLOR_GREEN),
6307 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
6308 if (!mtr_free->fm.meter_action) {
6309 flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
6317 * Verify the @p attributes will be correctly understood by the NIC and store
6318 * them in the @p flow if everything is correct.
6321 * Pointer to dev struct.
6322 * @param[in] attributes
6323 * Pointer to flow attributes
6324 * @param[in] external
6325 * This flow rule is created by request external to PMD.
6327 * Pointer to error structure.
6330 * - 0 on success and non root table.
6331 * - 1 on success and root table.
6332 * - a negative errno value otherwise and rte_errno is set.
6335 flow_dv_validate_attributes(struct rte_eth_dev *dev,
6336 const struct mlx5_flow_tunnel *tunnel,
6337 const struct rte_flow_attr *attributes,
6338 const struct flow_grp_info *grp_info,
6339 struct rte_flow_error *error)
6341 struct mlx5_priv *priv = dev->data->dev_private;
6342 uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
6345 #ifndef HAVE_MLX5DV_DR
6346 RTE_SET_USED(tunnel);
6347 RTE_SET_USED(grp_info);
6348 if (attributes->group)
6349 return rte_flow_error_set(error, ENOTSUP,
6350 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6352 "groups are not supported");
6356 ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
6361 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
6363 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
6364 attributes->priority > lowest_priority)
6365 return rte_flow_error_set(error, ENOTSUP,
6366 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
6368 "priority out of range");
6369 if (attributes->transfer) {
6370 if (!priv->config.dv_esw_en)
6371 return rte_flow_error_set
6373 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6374 "E-Switch dr is not supported");
6375 if (!(priv->representor || priv->master))
6376 return rte_flow_error_set
6377 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6378 NULL, "E-Switch configuration can only be"
6379 " done by a master or a representor device");
6380 if (attributes->egress)
6381 return rte_flow_error_set
6383 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
6384 "egress is not supported");
6386 if (!(attributes->egress ^ attributes->ingress))
6387 return rte_flow_error_set(error, ENOTSUP,
6388 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6389 "must specify exactly one of "
6390 "ingress or egress");
6395 mlx5_flow_locate_proto_l3(const struct rte_flow_item **head,
6396 const struct rte_flow_item *end)
6398 const struct rte_flow_item *item = *head;
6399 uint16_t l3_protocol;
6401 for (; item != end; item++) {
6402 switch (item->type) {
6405 case RTE_FLOW_ITEM_TYPE_IPV4:
6406 l3_protocol = RTE_ETHER_TYPE_IPV4;
6408 case RTE_FLOW_ITEM_TYPE_IPV6:
6409 l3_protocol = RTE_ETHER_TYPE_IPV6;
6411 case RTE_FLOW_ITEM_TYPE_ETH:
6412 if (item->mask && item->spec) {
6413 MLX5_ETHER_TYPE_FROM_HEADER(rte_flow_item_eth,
6416 if (l3_protocol == RTE_ETHER_TYPE_IPV4 ||
6417 l3_protocol == RTE_ETHER_TYPE_IPV6)
6421 case RTE_FLOW_ITEM_TYPE_VLAN:
6422 if (item->mask && item->spec) {
6423 MLX5_ETHER_TYPE_FROM_HEADER(rte_flow_item_vlan,
6426 if (l3_protocol == RTE_ETHER_TYPE_IPV4 ||
6427 l3_protocol == RTE_ETHER_TYPE_IPV6)
6440 mlx5_flow_locate_proto_l4(const struct rte_flow_item **head,
6441 const struct rte_flow_item *end)
6443 const struct rte_flow_item *item = *head;
6444 uint8_t l4_protocol;
6446 for (; item != end; item++) {
6447 switch (item->type) {
6450 case RTE_FLOW_ITEM_TYPE_TCP:
6451 l4_protocol = IPPROTO_TCP;
6453 case RTE_FLOW_ITEM_TYPE_UDP:
6454 l4_protocol = IPPROTO_UDP;
6456 case RTE_FLOW_ITEM_TYPE_IPV4:
6457 if (item->mask && item->spec) {
6458 const struct rte_flow_item_ipv4 *mask, *spec;
6460 mask = (typeof(mask))item->mask;
6461 spec = (typeof(spec))item->spec;
6462 l4_protocol = mask->hdr.next_proto_id &
6463 spec->hdr.next_proto_id;
6464 if (l4_protocol == IPPROTO_TCP ||
6465 l4_protocol == IPPROTO_UDP)
6469 case RTE_FLOW_ITEM_TYPE_IPV6:
6470 if (item->mask && item->spec) {
6471 const struct rte_flow_item_ipv6 *mask, *spec;
6472 mask = (typeof(mask))item->mask;
6473 spec = (typeof(spec))item->spec;
6474 l4_protocol = mask->hdr.proto & spec->hdr.proto;
6475 if (l4_protocol == IPPROTO_TCP ||
6476 l4_protocol == IPPROTO_UDP)
6489 flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
6490 const struct rte_flow_item *rule_items,
6491 const struct rte_flow_item *integrity_item,
6492 struct rte_flow_error *error)
6494 struct mlx5_priv *priv = dev->data->dev_private;
6495 const struct rte_flow_item *tunnel_item, *end_item, *item = rule_items;
6496 const struct rte_flow_item_integrity *mask = (typeof(mask))
6497 integrity_item->mask;
6498 const struct rte_flow_item_integrity *spec = (typeof(spec))
6499 integrity_item->spec;
6502 if (!priv->config.hca_attr.pkt_integrity_match)
6503 return rte_flow_error_set(error, ENOTSUP,
6504 RTE_FLOW_ERROR_TYPE_ITEM,
6506 "packet integrity integrity_item not supported");
6508 mask = &rte_flow_item_integrity_mask;
6509 if (!mlx5_validate_integrity_item(mask))
6510 return rte_flow_error_set(error, ENOTSUP,
6511 RTE_FLOW_ERROR_TYPE_ITEM,
6513 "unsupported integrity filter");
6514 tunnel_item = mlx5_flow_find_tunnel_item(rule_items);
6515 if (spec->level > 1) {
6517 return rte_flow_error_set(error, ENOTSUP,
6518 RTE_FLOW_ERROR_TYPE_ITEM,
6520 "missing tunnel item");
6522 end_item = mlx5_find_end_item(tunnel_item);
6524 end_item = tunnel_item ? tunnel_item :
6525 mlx5_find_end_item(integrity_item);
6527 if (mask->l3_ok || mask->ipv4_csum_ok) {
6528 protocol = mlx5_flow_locate_proto_l3(&item, end_item);
6530 return rte_flow_error_set(error, EINVAL,
6531 RTE_FLOW_ERROR_TYPE_ITEM,
6533 "missing L3 protocol");
6535 if (mask->l4_ok || mask->l4_csum_ok) {
6536 protocol = mlx5_flow_locate_proto_l4(&item, end_item);
6538 return rte_flow_error_set(error, EINVAL,
6539 RTE_FLOW_ERROR_TYPE_ITEM,
6541 "missing L4 protocol");
6547 * Internal validation function. For validating both actions and items.
6550 * Pointer to the rte_eth_dev structure.
6552 * Pointer to the flow attributes.
6554 * Pointer to the list of items.
6555 * @param[in] actions
6556 * Pointer to the list of actions.
6557 * @param[in] external
6558 * This flow rule is created by request external to PMD.
6559 * @param[in] hairpin
6560 * Number of hairpin TX actions, 0 means classic flow.
6562 * Pointer to the error structure.
6565 * 0 on success, a negative errno value otherwise and rte_errno is set.
6568 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
6569 const struct rte_flow_item items[],
6570 const struct rte_flow_action actions[],
6571 bool external, int hairpin, struct rte_flow_error *error)
6574 uint64_t action_flags = 0;
6575 uint64_t item_flags = 0;
6576 uint64_t last_item = 0;
6577 uint8_t next_protocol = 0xff;
6578 uint16_t ether_type = 0;
6580 uint8_t item_ipv6_proto = 0;
6581 int fdb_mirror_limit = 0;
6582 int modify_after_mirror = 0;
6583 const struct rte_flow_item *geneve_item = NULL;
6584 const struct rte_flow_item *gre_item = NULL;
6585 const struct rte_flow_item *gtp_item = NULL;
6586 const struct rte_flow_action_raw_decap *decap;
6587 const struct rte_flow_action_raw_encap *encap;
6588 const struct rte_flow_action_rss *rss = NULL;
6589 const struct rte_flow_action_rss *sample_rss = NULL;
6590 const struct rte_flow_action_count *sample_count = NULL;
6591 const struct rte_flow_item_tcp nic_tcp_mask = {
6594 .src_port = RTE_BE16(UINT16_MAX),
6595 .dst_port = RTE_BE16(UINT16_MAX),
6598 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
6601 "\xff\xff\xff\xff\xff\xff\xff\xff"
6602 "\xff\xff\xff\xff\xff\xff\xff\xff",
6604 "\xff\xff\xff\xff\xff\xff\xff\xff"
6605 "\xff\xff\xff\xff\xff\xff\xff\xff",
6606 .vtc_flow = RTE_BE32(0xffffffff),
6612 const struct rte_flow_item_ecpri nic_ecpri_mask = {
6616 RTE_BE32(((const struct rte_ecpri_common_hdr) {
6620 .dummy[0] = 0xffffffff,
6623 struct mlx5_priv *priv = dev->data->dev_private;
6624 struct mlx5_dev_config *dev_conf = &priv->config;
6625 uint16_t queue_index = 0xFFFF;
6626 const struct rte_flow_item_vlan *vlan_m = NULL;
6627 uint32_t rw_act_num = 0;
6629 const struct mlx5_flow_tunnel *tunnel;
6630 struct flow_grp_info grp_info = {
6631 .external = !!external,
6632 .transfer = !!attr->transfer,
6633 .fdb_def_rule = !!priv->fdb_def_rule,
6635 const struct rte_eth_hairpin_conf *conf;
6636 const struct rte_flow_item *rule_items = items;
6637 bool def_policy = false;
6641 if (is_flow_tunnel_match_rule(dev, attr, items, actions)) {
6642 tunnel = flow_items_to_tunnel(items);
6643 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
6644 MLX5_FLOW_ACTION_DECAP;
6645 } else if (is_flow_tunnel_steer_rule(dev, attr, items, actions)) {
6646 tunnel = flow_actions_to_tunnel(actions);
6647 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6651 if (tunnel && priv->representor)
6652 return rte_flow_error_set(error, ENOTSUP,
6653 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6654 "decap not supported "
6655 "for VF representor");
6656 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
6657 (dev, tunnel, attr, items, actions);
6658 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
6661 is_root = (uint64_t)ret;
6662 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6663 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
6664 int type = items->type;
6666 if (!mlx5_flow_os_item_supported(type))
6667 return rte_flow_error_set(error, ENOTSUP,
6668 RTE_FLOW_ERROR_TYPE_ITEM,
6669 NULL, "item not supported");
6671 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
6672 if (items[0].type != (typeof(items[0].type))
6673 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL)
6674 return rte_flow_error_set
6676 RTE_FLOW_ERROR_TYPE_ITEM,
6677 NULL, "MLX5 private items "
6678 "must be the first");
6680 case RTE_FLOW_ITEM_TYPE_VOID:
6682 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6683 ret = flow_dv_validate_item_port_id
6684 (dev, items, attr, item_flags, error);
6687 last_item = MLX5_FLOW_ITEM_PORT_ID;
6689 case RTE_FLOW_ITEM_TYPE_ETH:
6690 ret = mlx5_flow_validate_item_eth(items, item_flags,
6694 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
6695 MLX5_FLOW_LAYER_OUTER_L2;
6696 if (items->mask != NULL && items->spec != NULL) {
6698 ((const struct rte_flow_item_eth *)
6701 ((const struct rte_flow_item_eth *)
6703 ether_type = rte_be_to_cpu_16(ether_type);
6708 case RTE_FLOW_ITEM_TYPE_VLAN:
6709 ret = flow_dv_validate_item_vlan(items, item_flags,
6713 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
6714 MLX5_FLOW_LAYER_OUTER_VLAN;
6715 if (items->mask != NULL && items->spec != NULL) {
6717 ((const struct rte_flow_item_vlan *)
6718 items->spec)->inner_type;
6720 ((const struct rte_flow_item_vlan *)
6721 items->mask)->inner_type;
6722 ether_type = rte_be_to_cpu_16(ether_type);
6726 /* Store outer VLAN mask for of_push_vlan action. */
6728 vlan_m = items->mask;
6730 case RTE_FLOW_ITEM_TYPE_IPV4:
6731 mlx5_flow_tunnel_ip_check(items, next_protocol,
6732 &item_flags, &tunnel);
6733 ret = flow_dv_validate_item_ipv4(items, item_flags,
6734 last_item, ether_type,
6738 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
6739 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
6740 if (items->mask != NULL &&
6741 ((const struct rte_flow_item_ipv4 *)
6742 items->mask)->hdr.next_proto_id) {
6744 ((const struct rte_flow_item_ipv4 *)
6745 (items->spec))->hdr.next_proto_id;
6747 ((const struct rte_flow_item_ipv4 *)
6748 (items->mask))->hdr.next_proto_id;
6750 /* Reset for inner layer. */
6751 next_protocol = 0xff;
6754 case RTE_FLOW_ITEM_TYPE_IPV6:
6755 mlx5_flow_tunnel_ip_check(items, next_protocol,
6756 &item_flags, &tunnel);
6757 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
6764 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
6765 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
6766 if (items->mask != NULL &&
6767 ((const struct rte_flow_item_ipv6 *)
6768 items->mask)->hdr.proto) {
6770 ((const struct rte_flow_item_ipv6 *)
6771 items->spec)->hdr.proto;
6773 ((const struct rte_flow_item_ipv6 *)
6774 items->spec)->hdr.proto;
6776 ((const struct rte_flow_item_ipv6 *)
6777 items->mask)->hdr.proto;
6779 /* Reset for inner layer. */
6780 next_protocol = 0xff;
6783 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
6784 ret = flow_dv_validate_item_ipv6_frag_ext(items,
6789 last_item = tunnel ?
6790 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
6791 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
6792 if (items->mask != NULL &&
6793 ((const struct rte_flow_item_ipv6_frag_ext *)
6794 items->mask)->hdr.next_header) {
6796 ((const struct rte_flow_item_ipv6_frag_ext *)
6797 items->spec)->hdr.next_header;
6799 ((const struct rte_flow_item_ipv6_frag_ext *)
6800 items->mask)->hdr.next_header;
6802 /* Reset for inner layer. */
6803 next_protocol = 0xff;
6806 case RTE_FLOW_ITEM_TYPE_TCP:
6807 ret = mlx5_flow_validate_item_tcp
6814 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
6815 MLX5_FLOW_LAYER_OUTER_L4_TCP;
6817 case RTE_FLOW_ITEM_TYPE_UDP:
6818 ret = mlx5_flow_validate_item_udp(items, item_flags,
6823 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
6824 MLX5_FLOW_LAYER_OUTER_L4_UDP;
6826 case RTE_FLOW_ITEM_TYPE_GRE:
6827 ret = mlx5_flow_validate_item_gre(items, item_flags,
6828 next_protocol, error);
6832 last_item = MLX5_FLOW_LAYER_GRE;
6834 case RTE_FLOW_ITEM_TYPE_NVGRE:
6835 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
6840 last_item = MLX5_FLOW_LAYER_NVGRE;
6842 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6843 ret = mlx5_flow_validate_item_gre_key
6844 (items, item_flags, gre_item, error);
6847 last_item = MLX5_FLOW_LAYER_GRE_KEY;
6849 case RTE_FLOW_ITEM_TYPE_VXLAN:
6850 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
6854 last_item = MLX5_FLOW_LAYER_VXLAN;
6856 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6857 ret = mlx5_flow_validate_item_vxlan_gpe(items,
6862 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
6864 case RTE_FLOW_ITEM_TYPE_GENEVE:
6865 ret = mlx5_flow_validate_item_geneve(items,
6870 geneve_item = items;
6871 last_item = MLX5_FLOW_LAYER_GENEVE;
6873 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
6874 ret = mlx5_flow_validate_item_geneve_opt(items,
6881 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
6883 case RTE_FLOW_ITEM_TYPE_MPLS:
6884 ret = mlx5_flow_validate_item_mpls(dev, items,
6889 last_item = MLX5_FLOW_LAYER_MPLS;
6892 case RTE_FLOW_ITEM_TYPE_MARK:
6893 ret = flow_dv_validate_item_mark(dev, items, attr,
6897 last_item = MLX5_FLOW_ITEM_MARK;
6899 case RTE_FLOW_ITEM_TYPE_META:
6900 ret = flow_dv_validate_item_meta(dev, items, attr,
6904 last_item = MLX5_FLOW_ITEM_METADATA;
6906 case RTE_FLOW_ITEM_TYPE_ICMP:
6907 ret = mlx5_flow_validate_item_icmp(items, item_flags,
6912 last_item = MLX5_FLOW_LAYER_ICMP;
6914 case RTE_FLOW_ITEM_TYPE_ICMP6:
6915 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
6920 item_ipv6_proto = IPPROTO_ICMPV6;
6921 last_item = MLX5_FLOW_LAYER_ICMP6;
6923 case RTE_FLOW_ITEM_TYPE_TAG:
6924 ret = flow_dv_validate_item_tag(dev, items,
6928 last_item = MLX5_FLOW_ITEM_TAG;
6930 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
6931 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
6933 case RTE_FLOW_ITEM_TYPE_GTP:
6934 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
6939 last_item = MLX5_FLOW_LAYER_GTP;
6941 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6942 ret = flow_dv_validate_item_gtp_psc(items, last_item,
6947 last_item = MLX5_FLOW_LAYER_GTP_PSC;
6949 case RTE_FLOW_ITEM_TYPE_ECPRI:
6950 /* Capacity will be checked in the translate stage. */
6951 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
6958 last_item = MLX5_FLOW_LAYER_ECPRI;
6960 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
6961 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY)
6962 return rte_flow_error_set
6964 RTE_FLOW_ERROR_TYPE_ITEM,
6965 NULL, "multiple integrity items not supported");
6966 ret = flow_dv_validate_item_integrity(dev, rule_items,
6970 last_item = MLX5_FLOW_ITEM_INTEGRITY;
6972 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
6973 ret = flow_dv_validate_item_aso_ct(dev, items,
6974 &item_flags, error);
6979 return rte_flow_error_set(error, ENOTSUP,
6980 RTE_FLOW_ERROR_TYPE_ITEM,
6981 NULL, "item not supported");
6983 item_flags |= last_item;
6985 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
6986 int type = actions->type;
6987 bool shared_count = false;
6989 if (!mlx5_flow_os_action_supported(type))
6990 return rte_flow_error_set(error, ENOTSUP,
6991 RTE_FLOW_ERROR_TYPE_ACTION,
6993 "action not supported");
6994 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6995 return rte_flow_error_set(error, ENOTSUP,
6996 RTE_FLOW_ERROR_TYPE_ACTION,
6997 actions, "too many actions");
6999 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
7000 return rte_flow_error_set(error, ENOTSUP,
7001 RTE_FLOW_ERROR_TYPE_ACTION,
7002 NULL, "meter action with policy "
7003 "must be the last action");
7005 case RTE_FLOW_ACTION_TYPE_VOID:
7007 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7008 ret = flow_dv_validate_action_port_id(dev,
7015 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7018 case RTE_FLOW_ACTION_TYPE_FLAG:
7019 ret = flow_dv_validate_action_flag(dev, action_flags,
7023 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7024 /* Count all modify-header actions as one. */
7025 if (!(action_flags &
7026 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7028 action_flags |= MLX5_FLOW_ACTION_FLAG |
7029 MLX5_FLOW_ACTION_MARK_EXT;
7030 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7031 modify_after_mirror = 1;
7034 action_flags |= MLX5_FLOW_ACTION_FLAG;
7037 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7039 case RTE_FLOW_ACTION_TYPE_MARK:
7040 ret = flow_dv_validate_action_mark(dev, actions,
7045 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7046 /* Count all modify-header actions as one. */
7047 if (!(action_flags &
7048 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7050 action_flags |= MLX5_FLOW_ACTION_MARK |
7051 MLX5_FLOW_ACTION_MARK_EXT;
7052 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7053 modify_after_mirror = 1;
7055 action_flags |= MLX5_FLOW_ACTION_MARK;
7058 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7060 case RTE_FLOW_ACTION_TYPE_SET_META:
7061 ret = flow_dv_validate_action_set_meta(dev, actions,
7066 /* Count all modify-header actions as one action. */
7067 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7069 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7070 modify_after_mirror = 1;
7071 action_flags |= MLX5_FLOW_ACTION_SET_META;
7072 rw_act_num += MLX5_ACT_NUM_SET_META;
7074 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7075 ret = flow_dv_validate_action_set_tag(dev, actions,
7080 /* Count all modify-header actions as one action. */
7081 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7083 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7084 modify_after_mirror = 1;
7085 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7086 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7088 case RTE_FLOW_ACTION_TYPE_DROP:
7089 ret = mlx5_flow_validate_action_drop(action_flags,
7093 action_flags |= MLX5_FLOW_ACTION_DROP;
7096 case RTE_FLOW_ACTION_TYPE_QUEUE:
7097 ret = mlx5_flow_validate_action_queue(actions,
7102 queue_index = ((const struct rte_flow_action_queue *)
7103 (actions->conf))->index;
7104 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7107 case RTE_FLOW_ACTION_TYPE_RSS:
7108 rss = actions->conf;
7109 ret = mlx5_flow_validate_action_rss(actions,
7115 if (rss && sample_rss &&
7116 (sample_rss->level != rss->level ||
7117 sample_rss->types != rss->types))
7118 return rte_flow_error_set(error, ENOTSUP,
7119 RTE_FLOW_ERROR_TYPE_ACTION,
7121 "Can't use the different RSS types "
7122 "or level in the same flow");
7123 if (rss != NULL && rss->queue_num)
7124 queue_index = rss->queue[0];
7125 action_flags |= MLX5_FLOW_ACTION_RSS;
7128 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7130 mlx5_flow_validate_action_default_miss(action_flags,
7134 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
7137 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
7138 case RTE_FLOW_ACTION_TYPE_COUNT:
7139 shared_count = is_shared_action_count(actions);
7140 ret = flow_dv_validate_action_count(dev, shared_count,
7145 action_flags |= MLX5_FLOW_ACTION_COUNT;
7148 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7149 if (flow_dv_validate_action_pop_vlan(dev,
7155 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7156 modify_after_mirror = 1;
7157 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7160 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7161 ret = flow_dv_validate_action_push_vlan(dev,
7168 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7169 modify_after_mirror = 1;
7170 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7173 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7174 ret = flow_dv_validate_action_set_vlan_pcp
7175 (action_flags, actions, error);
7178 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7179 modify_after_mirror = 1;
7180 /* Count PCP with push_vlan command. */
7181 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
7183 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7184 ret = flow_dv_validate_action_set_vlan_vid
7185 (item_flags, action_flags,
7189 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7190 modify_after_mirror = 1;
7191 /* Count VID with push_vlan command. */
7192 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7193 rw_act_num += MLX5_ACT_NUM_MDF_VID;
7195 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7196 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7197 ret = flow_dv_validate_action_l2_encap(dev,
7203 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7206 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7207 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7208 ret = flow_dv_validate_action_decap(dev, action_flags,
7209 actions, item_flags,
7213 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7214 modify_after_mirror = 1;
7215 action_flags |= MLX5_FLOW_ACTION_DECAP;
7218 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7219 ret = flow_dv_validate_action_raw_encap_decap
7220 (dev, NULL, actions->conf, attr, &action_flags,
7221 &actions_n, actions, item_flags, error);
7225 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7226 decap = actions->conf;
7227 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
7229 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7233 encap = actions->conf;
7235 ret = flow_dv_validate_action_raw_encap_decap
7237 decap ? decap : &empty_decap, encap,
7238 attr, &action_flags, &actions_n,
7239 actions, item_flags, error);
7242 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7243 (action_flags & MLX5_FLOW_ACTION_DECAP))
7244 modify_after_mirror = 1;
7246 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7247 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7248 ret = flow_dv_validate_action_modify_mac(action_flags,
7254 /* Count all modify-header actions as one action. */
7255 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7257 action_flags |= actions->type ==
7258 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7259 MLX5_FLOW_ACTION_SET_MAC_SRC :
7260 MLX5_FLOW_ACTION_SET_MAC_DST;
7261 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7262 modify_after_mirror = 1;
7264 * Even if the source and destination MAC addresses have
7265 * overlap in the header with 4B alignment, the convert
7266 * function will handle them separately and 4 SW actions
7267 * will be created. And 2 actions will be added each
7268 * time no matter how many bytes of address will be set.
7270 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
7272 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7273 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7274 ret = flow_dv_validate_action_modify_ipv4(action_flags,
7280 /* Count all modify-header actions as one action. */
7281 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7283 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7284 modify_after_mirror = 1;
7285 action_flags |= actions->type ==
7286 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7287 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7288 MLX5_FLOW_ACTION_SET_IPV4_DST;
7289 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
7291 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7292 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7293 ret = flow_dv_validate_action_modify_ipv6(action_flags,
7299 if (item_ipv6_proto == IPPROTO_ICMPV6)
7300 return rte_flow_error_set(error, ENOTSUP,
7301 RTE_FLOW_ERROR_TYPE_ACTION,
7303 "Can't change header "
7304 "with ICMPv6 proto");
7305 /* Count all modify-header actions as one action. */
7306 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7308 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7309 modify_after_mirror = 1;
7310 action_flags |= actions->type ==
7311 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7312 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7313 MLX5_FLOW_ACTION_SET_IPV6_DST;
7314 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
7316 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7317 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7318 ret = flow_dv_validate_action_modify_tp(action_flags,
7324 /* Count all modify-header actions as one action. */
7325 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7327 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7328 modify_after_mirror = 1;
7329 action_flags |= actions->type ==
7330 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7331 MLX5_FLOW_ACTION_SET_TP_SRC :
7332 MLX5_FLOW_ACTION_SET_TP_DST;
7333 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
7335 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7336 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7337 ret = flow_dv_validate_action_modify_ttl(action_flags,
7343 /* Count all modify-header actions as one action. */
7344 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7346 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7347 modify_after_mirror = 1;
7348 action_flags |= actions->type ==
7349 RTE_FLOW_ACTION_TYPE_SET_TTL ?
7350 MLX5_FLOW_ACTION_SET_TTL :
7351 MLX5_FLOW_ACTION_DEC_TTL;
7352 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
7354 case RTE_FLOW_ACTION_TYPE_JUMP:
7355 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
7361 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7363 return rte_flow_error_set(error, EINVAL,
7364 RTE_FLOW_ERROR_TYPE_ACTION,
7366 "sample and jump action combination is not supported");
7368 action_flags |= MLX5_FLOW_ACTION_JUMP;
7370 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7371 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7372 ret = flow_dv_validate_action_modify_tcp_seq
7379 /* Count all modify-header actions as one action. */
7380 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7382 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7383 modify_after_mirror = 1;
7384 action_flags |= actions->type ==
7385 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7386 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7387 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7388 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
7390 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7391 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7392 ret = flow_dv_validate_action_modify_tcp_ack
7399 /* Count all modify-header actions as one action. */
7400 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7402 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7403 modify_after_mirror = 1;
7404 action_flags |= actions->type ==
7405 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7406 MLX5_FLOW_ACTION_INC_TCP_ACK :
7407 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7408 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
7410 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7412 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7413 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7414 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7416 case RTE_FLOW_ACTION_TYPE_METER:
7417 ret = mlx5_flow_validate_action_meter(dev,
7424 action_flags |= MLX5_FLOW_ACTION_METER;
7427 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
7429 /* Meter action will add one more TAG action. */
7430 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7432 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
7433 if (!attr->transfer && !attr->group)
7434 return rte_flow_error_set(error, ENOTSUP,
7435 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7437 "Shared ASO age action is not supported for group 0");
7438 if (action_flags & MLX5_FLOW_ACTION_AGE)
7439 return rte_flow_error_set
7441 RTE_FLOW_ERROR_TYPE_ACTION,
7443 "duplicate age actions set");
7444 action_flags |= MLX5_FLOW_ACTION_AGE;
7447 case RTE_FLOW_ACTION_TYPE_AGE:
7448 ret = flow_dv_validate_action_age(action_flags,
7454 * Validate the regular AGE action (using counter)
7455 * mutual exclusion with share counter actions.
7457 if (!priv->sh->flow_hit_aso_en) {
7459 return rte_flow_error_set
7461 RTE_FLOW_ERROR_TYPE_ACTION,
7463 "old age and shared count combination is not supported");
7465 return rte_flow_error_set
7467 RTE_FLOW_ERROR_TYPE_ACTION,
7469 "old age action and count must be in the same sub flow");
7471 action_flags |= MLX5_FLOW_ACTION_AGE;
7474 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7475 ret = flow_dv_validate_action_modify_ipv4_dscp
7482 /* Count all modify-header actions as one action. */
7483 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7485 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7486 modify_after_mirror = 1;
7487 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7488 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7490 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7491 ret = flow_dv_validate_action_modify_ipv6_dscp
7498 /* Count all modify-header actions as one action. */
7499 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7501 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7502 modify_after_mirror = 1;
7503 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7504 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7506 case RTE_FLOW_ACTION_TYPE_SAMPLE:
7507 ret = flow_dv_validate_action_sample(&action_flags,
7516 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
7519 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
7520 if (actions[0].type != (typeof(actions[0].type))
7521 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET)
7522 return rte_flow_error_set
7524 RTE_FLOW_ERROR_TYPE_ACTION,
7525 NULL, "MLX5 private action "
7526 "must be the first");
7528 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
7530 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7531 ret = flow_dv_validate_action_modify_field(dev,
7538 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7539 modify_after_mirror = 1;
7540 /* Count all modify-header actions as one action. */
7541 if (!(action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD))
7543 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
7546 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7547 ret = flow_dv_validate_action_aso_ct(dev, action_flags,
7552 action_flags |= MLX5_FLOW_ACTION_CT;
7555 return rte_flow_error_set(error, ENOTSUP,
7556 RTE_FLOW_ERROR_TYPE_ACTION,
7558 "action not supported");
7562 * Validate actions in flow rules
7563 * - Explicit decap action is prohibited by the tunnel offload API.
7564 * - Drop action in tunnel steer rule is prohibited by the API.
7565 * - Application cannot use MARK action because it's value can mask
7566 * tunnel default miss nitification.
7567 * - JUMP in tunnel match rule has no support in current PMD
7569 * - TAG & META are reserved for future uses.
7571 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
7572 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
7573 MLX5_FLOW_ACTION_MARK |
7574 MLX5_FLOW_ACTION_SET_TAG |
7575 MLX5_FLOW_ACTION_SET_META |
7576 MLX5_FLOW_ACTION_DROP;
7578 if (action_flags & bad_actions_mask)
7579 return rte_flow_error_set
7581 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7582 "Invalid RTE action in tunnel "
7584 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
7585 return rte_flow_error_set
7587 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7588 "tunnel set decap rule must terminate "
7591 return rte_flow_error_set
7593 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7594 "tunnel flows for ingress traffic only");
7596 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
7597 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
7598 MLX5_FLOW_ACTION_MARK |
7599 MLX5_FLOW_ACTION_SET_TAG |
7600 MLX5_FLOW_ACTION_SET_META;
7602 if (action_flags & bad_actions_mask)
7603 return rte_flow_error_set
7605 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7606 "Invalid RTE action in tunnel "
7610 * Validate the drop action mutual exclusion with other actions.
7611 * Drop action is mutually-exclusive with any other action, except for
7613 * Drop action compatibility with tunnel offload was already validated.
7615 if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
7616 MLX5_FLOW_ACTION_TUNNEL_MATCH));
7617 else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
7618 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
7619 return rte_flow_error_set(error, EINVAL,
7620 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7621 "Drop action is mutually-exclusive "
7622 "with any other action, except for "
7624 /* Eswitch has few restrictions on using items and actions */
7625 if (attr->transfer) {
7626 if (!mlx5_flow_ext_mreg_supported(dev) &&
7627 action_flags & MLX5_FLOW_ACTION_FLAG)
7628 return rte_flow_error_set(error, ENOTSUP,
7629 RTE_FLOW_ERROR_TYPE_ACTION,
7631 "unsupported action FLAG");
7632 if (!mlx5_flow_ext_mreg_supported(dev) &&
7633 action_flags & MLX5_FLOW_ACTION_MARK)
7634 return rte_flow_error_set(error, ENOTSUP,
7635 RTE_FLOW_ERROR_TYPE_ACTION,
7637 "unsupported action MARK");
7638 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
7639 return rte_flow_error_set(error, ENOTSUP,
7640 RTE_FLOW_ERROR_TYPE_ACTION,
7642 "unsupported action QUEUE");
7643 if (action_flags & MLX5_FLOW_ACTION_RSS)
7644 return rte_flow_error_set(error, ENOTSUP,
7645 RTE_FLOW_ERROR_TYPE_ACTION,
7647 "unsupported action RSS");
7648 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
7649 return rte_flow_error_set(error, EINVAL,
7650 RTE_FLOW_ERROR_TYPE_ACTION,
7652 "no fate action is found");
7654 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
7655 return rte_flow_error_set(error, EINVAL,
7656 RTE_FLOW_ERROR_TYPE_ACTION,
7658 "no fate action is found");
7661 * Continue validation for Xcap and VLAN actions.
7662 * If hairpin is working in explicit TX rule mode, there is no actions
7663 * splitting and the validation of hairpin ingress flow should be the
7664 * same as other standard flows.
7666 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
7667 MLX5_FLOW_VLAN_ACTIONS)) &&
7668 (queue_index == 0xFFFF ||
7669 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN ||
7670 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
7671 conf->tx_explicit != 0))) {
7672 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
7673 MLX5_FLOW_XCAP_ACTIONS)
7674 return rte_flow_error_set(error, ENOTSUP,
7675 RTE_FLOW_ERROR_TYPE_ACTION,
7676 NULL, "encap and decap "
7677 "combination aren't supported");
7678 if (!attr->transfer && attr->ingress) {
7679 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7680 return rte_flow_error_set
7682 RTE_FLOW_ERROR_TYPE_ACTION,
7683 NULL, "encap is not supported"
7684 " for ingress traffic");
7685 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7686 return rte_flow_error_set
7688 RTE_FLOW_ERROR_TYPE_ACTION,
7689 NULL, "push VLAN action not "
7690 "supported for ingress");
7691 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
7692 MLX5_FLOW_VLAN_ACTIONS)
7693 return rte_flow_error_set
7695 RTE_FLOW_ERROR_TYPE_ACTION,
7696 NULL, "no support for "
7697 "multiple VLAN actions");
7700 if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
7701 if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
7702 ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
7704 return rte_flow_error_set
7706 RTE_FLOW_ERROR_TYPE_ACTION,
7707 NULL, "fate action not supported for "
7708 "meter with policy");
7710 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
7711 return rte_flow_error_set
7713 RTE_FLOW_ERROR_TYPE_ACTION,
7714 NULL, "modify header action in egress "
7715 "cannot be done before meter action");
7716 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7717 return rte_flow_error_set
7719 RTE_FLOW_ERROR_TYPE_ACTION,
7720 NULL, "encap action in egress "
7721 "cannot be done before meter action");
7722 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7723 return rte_flow_error_set
7725 RTE_FLOW_ERROR_TYPE_ACTION,
7726 NULL, "push vlan action in egress "
7727 "cannot be done before meter action");
7731 * Hairpin flow will add one more TAG action in TX implicit mode.
7732 * In TX explicit mode, there will be no hairpin flow ID.
7735 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7736 /* extra metadata enabled: one more TAG action will be add. */
7737 if (dev_conf->dv_flow_en &&
7738 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
7739 mlx5_flow_ext_mreg_supported(dev))
7740 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7742 flow_dv_modify_hdr_action_max(dev, is_root)) {
7743 return rte_flow_error_set(error, ENOTSUP,
7744 RTE_FLOW_ERROR_TYPE_ACTION,
7745 NULL, "too many header modify"
7746 " actions to support");
7748 /* Eswitch egress mirror and modify flow has limitation on CX5 */
7749 if (fdb_mirror_limit && modify_after_mirror)
7750 return rte_flow_error_set(error, EINVAL,
7751 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7752 "sample before modify action is not supported");
7757 * Internal preparation function. Allocates the DV flow size,
7758 * this size is constant.
7761 * Pointer to the rte_eth_dev structure.
7763 * Pointer to the flow attributes.
7765 * Pointer to the list of items.
7766 * @param[in] actions
7767 * Pointer to the list of actions.
7769 * Pointer to the error structure.
7772 * Pointer to mlx5_flow object on success,
7773 * otherwise NULL and rte_errno is set.
7775 static struct mlx5_flow *
7776 flow_dv_prepare(struct rte_eth_dev *dev,
7777 const struct rte_flow_attr *attr __rte_unused,
7778 const struct rte_flow_item items[] __rte_unused,
7779 const struct rte_flow_action actions[] __rte_unused,
7780 struct rte_flow_error *error)
7782 uint32_t handle_idx = 0;
7783 struct mlx5_flow *dev_flow;
7784 struct mlx5_flow_handle *dev_handle;
7785 struct mlx5_priv *priv = dev->data->dev_private;
7786 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
7789 wks->skip_matcher_reg = 0;
7790 /* In case of corrupting the memory. */
7791 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
7792 rte_flow_error_set(error, ENOSPC,
7793 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7794 "not free temporary device flow");
7797 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
7800 rte_flow_error_set(error, ENOMEM,
7801 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7802 "not enough memory to create flow handle");
7805 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
7806 dev_flow = &wks->flows[wks->flow_idx++];
7807 memset(dev_flow, 0, sizeof(*dev_flow));
7808 dev_flow->handle = dev_handle;
7809 dev_flow->handle_idx = handle_idx;
7811 * In some old rdma-core releases, before continuing, a check of the
7812 * length of matching parameter will be done at first. It needs to use
7813 * the length without misc4 param. If the flow has misc4 support, then
7814 * the length needs to be adjusted accordingly. Each param member is
7815 * aligned with a 64B boundary naturally.
7817 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param) -
7818 MLX5_ST_SZ_BYTES(fte_match_set_misc4);
7819 dev_flow->ingress = attr->ingress;
7820 dev_flow->dv.transfer = attr->transfer;
7824 #ifdef RTE_LIBRTE_MLX5_DEBUG
7826 * Sanity check for match mask and value. Similar to check_valid_spec() in
7827 * kernel driver. If unmasked bit is present in value, it returns failure.
7830 * pointer to match mask buffer.
7831 * @param match_value
7832 * pointer to match value buffer.
7835 * 0 if valid, -EINVAL otherwise.
7838 flow_dv_check_valid_spec(void *match_mask, void *match_value)
7840 uint8_t *m = match_mask;
7841 uint8_t *v = match_value;
7844 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
7847 "match_value differs from match_criteria"
7848 " %p[%u] != %p[%u]",
7849 match_value, i, match_mask, i);
7858 * Add match of ip_version.
7862 * @param[in] headers_v
7863 * Values header pointer.
7864 * @param[in] headers_m
7865 * Masks header pointer.
7866 * @param[in] ip_version
7867 * The IP version to set.
7870 flow_dv_set_match_ip_version(uint32_t group,
7876 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
7878 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
7880 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
7881 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
7882 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
7886 * Add Ethernet item to matcher and to the value.
7888 * @param[in, out] matcher
7890 * @param[in, out] key
7891 * Flow matcher value.
7893 * Flow pattern to translate.
7895 * Item is inner pattern.
7898 flow_dv_translate_item_eth(void *matcher, void *key,
7899 const struct rte_flow_item *item, int inner,
7902 const struct rte_flow_item_eth *eth_m = item->mask;
7903 const struct rte_flow_item_eth *eth_v = item->spec;
7904 const struct rte_flow_item_eth nic_mask = {
7905 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
7906 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
7907 .type = RTE_BE16(0xffff),
7920 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
7922 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7924 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
7926 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7928 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
7929 ð_m->dst, sizeof(eth_m->dst));
7930 /* The value must be in the range of the mask. */
7931 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
7932 for (i = 0; i < sizeof(eth_m->dst); ++i)
7933 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
7934 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
7935 ð_m->src, sizeof(eth_m->src));
7936 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
7937 /* The value must be in the range of the mask. */
7938 for (i = 0; i < sizeof(eth_m->dst); ++i)
7939 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
7941 * HW supports match on one Ethertype, the Ethertype following the last
7942 * VLAN tag of the packet (see PRM).
7943 * Set match on ethertype only if ETH header is not followed by VLAN.
7944 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
7945 * ethertype, and use ip_version field instead.
7946 * eCPRI over Ether layer will use type value 0xAEFE.
7948 if (eth_m->type == 0xFFFF) {
7949 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
7950 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
7951 switch (eth_v->type) {
7952 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
7953 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
7955 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
7956 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
7957 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
7959 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
7960 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
7962 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
7963 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
7969 if (eth_m->has_vlan) {
7970 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
7971 if (eth_v->has_vlan) {
7973 * Here, when also has_more_vlan field in VLAN item is
7974 * not set, only single-tagged packets will be matched.
7976 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
7980 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
7981 rte_be_to_cpu_16(eth_m->type));
7982 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
7983 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
7987 * Add VLAN item to matcher and to the value.
7989 * @param[in, out] dev_flow
7991 * @param[in, out] matcher
7993 * @param[in, out] key
7994 * Flow matcher value.
7996 * Flow pattern to translate.
7998 * Item is inner pattern.
8001 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
8002 void *matcher, void *key,
8003 const struct rte_flow_item *item,
8004 int inner, uint32_t group)
8006 const struct rte_flow_item_vlan *vlan_m = item->mask;
8007 const struct rte_flow_item_vlan *vlan_v = item->spec;
8014 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8016 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8018 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8020 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8022 * This is workaround, masks are not supported,
8023 * and pre-validated.
8026 dev_flow->handle->vf_vlan.tag =
8027 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
8030 * When VLAN item exists in flow, mark packet as tagged,
8031 * even if TCI is not specified.
8033 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
8034 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8035 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8040 vlan_m = &rte_flow_item_vlan_mask;
8041 tci_m = rte_be_to_cpu_16(vlan_m->tci);
8042 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
8043 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
8044 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
8045 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
8046 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
8047 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
8048 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
8050 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8051 * ethertype, and use ip_version field instead.
8053 if (vlan_m->inner_type == 0xFFFF) {
8054 switch (vlan_v->inner_type) {
8055 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8056 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8057 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8058 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8060 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8061 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8063 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8064 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8070 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
8071 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8072 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8073 /* Only one vlan_tag bit can be set. */
8074 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8077 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8078 rte_be_to_cpu_16(vlan_m->inner_type));
8079 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
8080 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
8084 * Add IPV4 item to matcher and to the value.
8086 * @param[in, out] matcher
8088 * @param[in, out] key
8089 * Flow matcher value.
8091 * Flow pattern to translate.
8093 * Item is inner pattern.
8095 * The group to insert the rule.
8098 flow_dv_translate_item_ipv4(void *matcher, void *key,
8099 const struct rte_flow_item *item,
8100 int inner, uint32_t group)
8102 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
8103 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
8104 const struct rte_flow_item_ipv4 nic_mask = {
8106 .src_addr = RTE_BE32(0xffffffff),
8107 .dst_addr = RTE_BE32(0xffffffff),
8108 .type_of_service = 0xff,
8109 .next_proto_id = 0xff,
8110 .time_to_live = 0xff,
8120 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8122 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8124 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8126 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8128 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
8133 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8134 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8135 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8136 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8137 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
8138 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
8139 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8140 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8141 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8142 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8143 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
8144 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
8145 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
8146 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
8147 ipv4_m->hdr.type_of_service);
8148 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
8149 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
8150 ipv4_m->hdr.type_of_service >> 2);
8151 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
8152 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8153 ipv4_m->hdr.next_proto_id);
8154 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8155 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
8156 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8157 ipv4_m->hdr.time_to_live);
8158 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8159 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
8160 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8161 !!(ipv4_m->hdr.fragment_offset));
8162 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8163 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
8167 * Add IPV6 item to matcher and to the value.
8169 * @param[in, out] matcher
8171 * @param[in, out] key
8172 * Flow matcher value.
8174 * Flow pattern to translate.
8176 * Item is inner pattern.
8178 * The group to insert the rule.
8181 flow_dv_translate_item_ipv6(void *matcher, void *key,
8182 const struct rte_flow_item *item,
8183 int inner, uint32_t group)
8185 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
8186 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
8187 const struct rte_flow_item_ipv6 nic_mask = {
8190 "\xff\xff\xff\xff\xff\xff\xff\xff"
8191 "\xff\xff\xff\xff\xff\xff\xff\xff",
8193 "\xff\xff\xff\xff\xff\xff\xff\xff"
8194 "\xff\xff\xff\xff\xff\xff\xff\xff",
8195 .vtc_flow = RTE_BE32(0xffffffff),
8202 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8203 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8212 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8214 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8216 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8218 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8220 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
8225 size = sizeof(ipv6_m->hdr.dst_addr);
8226 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8227 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8228 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8229 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8230 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
8231 for (i = 0; i < size; ++i)
8232 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
8233 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8234 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8235 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8236 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8237 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
8238 for (i = 0; i < size; ++i)
8239 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
8241 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
8242 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
8243 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
8244 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
8245 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
8246 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
8249 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
8251 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
8254 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
8256 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
8260 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8262 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8263 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
8265 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8266 ipv6_m->hdr.hop_limits);
8267 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8268 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
8269 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8270 !!(ipv6_m->has_frag_ext));
8271 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8272 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
8276 * Add IPV6 fragment extension item to matcher and to the value.
8278 * @param[in, out] matcher
8280 * @param[in, out] key
8281 * Flow matcher value.
8283 * Flow pattern to translate.
8285 * Item is inner pattern.
8288 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
8289 const struct rte_flow_item *item,
8292 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
8293 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
8294 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
8296 .next_header = 0xff,
8297 .frag_data = RTE_BE16(0xffff),
8304 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8306 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8308 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8310 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8312 /* IPv6 fragment extension item exists, so packet is IP fragment. */
8313 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
8314 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
8315 if (!ipv6_frag_ext_v)
8317 if (!ipv6_frag_ext_m)
8318 ipv6_frag_ext_m = &nic_mask;
8319 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8320 ipv6_frag_ext_m->hdr.next_header);
8321 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8322 ipv6_frag_ext_v->hdr.next_header &
8323 ipv6_frag_ext_m->hdr.next_header);
8327 * Add TCP item to matcher and to the value.
8329 * @param[in, out] matcher
8331 * @param[in, out] key
8332 * Flow matcher value.
8334 * Flow pattern to translate.
8336 * Item is inner pattern.
8339 flow_dv_translate_item_tcp(void *matcher, void *key,
8340 const struct rte_flow_item *item,
8343 const struct rte_flow_item_tcp *tcp_m = item->mask;
8344 const struct rte_flow_item_tcp *tcp_v = item->spec;
8349 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8351 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8353 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8355 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8357 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8358 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
8362 tcp_m = &rte_flow_item_tcp_mask;
8363 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
8364 rte_be_to_cpu_16(tcp_m->hdr.src_port));
8365 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
8366 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
8367 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
8368 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
8369 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
8370 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
8371 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
8372 tcp_m->hdr.tcp_flags);
8373 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
8374 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
8378 * Add UDP item to matcher and to the value.
8380 * @param[in, out] matcher
8382 * @param[in, out] key
8383 * Flow matcher value.
8385 * Flow pattern to translate.
8387 * Item is inner pattern.
8390 flow_dv_translate_item_udp(void *matcher, void *key,
8391 const struct rte_flow_item *item,
8394 const struct rte_flow_item_udp *udp_m = item->mask;
8395 const struct rte_flow_item_udp *udp_v = item->spec;
8400 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8402 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8404 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8406 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8408 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8409 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
8413 udp_m = &rte_flow_item_udp_mask;
8414 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
8415 rte_be_to_cpu_16(udp_m->hdr.src_port));
8416 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
8417 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
8418 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
8419 rte_be_to_cpu_16(udp_m->hdr.dst_port));
8420 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8421 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
8425 * Add GRE optional Key item to matcher and to the value.
8427 * @param[in, out] matcher
8429 * @param[in, out] key
8430 * Flow matcher value.
8432 * Flow pattern to translate.
8434 * Item is inner pattern.
8437 flow_dv_translate_item_gre_key(void *matcher, void *key,
8438 const struct rte_flow_item *item)
8440 const rte_be32_t *key_m = item->mask;
8441 const rte_be32_t *key_v = item->spec;
8442 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8443 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8444 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
8446 /* GRE K bit must be on and should already be validated */
8447 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
8448 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
8452 key_m = &gre_key_default_mask;
8453 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
8454 rte_be_to_cpu_32(*key_m) >> 8);
8455 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
8456 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
8457 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
8458 rte_be_to_cpu_32(*key_m) & 0xFF);
8459 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
8460 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
8464 * Add GRE item to matcher and to the value.
8466 * @param[in, out] matcher
8468 * @param[in, out] key
8469 * Flow matcher value.
8471 * Flow pattern to translate.
8473 * Item is inner pattern.
8476 flow_dv_translate_item_gre(void *matcher, void *key,
8477 const struct rte_flow_item *item,
8480 const struct rte_flow_item_gre *gre_m = item->mask;
8481 const struct rte_flow_item_gre *gre_v = item->spec;
8484 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8485 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8492 uint16_t s_present:1;
8493 uint16_t k_present:1;
8494 uint16_t rsvd_bit1:1;
8495 uint16_t c_present:1;
8499 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
8502 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8504 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8506 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8508 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8510 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8511 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
8515 gre_m = &rte_flow_item_gre_mask;
8516 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
8517 rte_be_to_cpu_16(gre_m->protocol));
8518 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8519 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
8520 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
8521 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
8522 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
8523 gre_crks_rsvd0_ver_m.c_present);
8524 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
8525 gre_crks_rsvd0_ver_v.c_present &
8526 gre_crks_rsvd0_ver_m.c_present);
8527 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
8528 gre_crks_rsvd0_ver_m.k_present);
8529 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
8530 gre_crks_rsvd0_ver_v.k_present &
8531 gre_crks_rsvd0_ver_m.k_present);
8532 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
8533 gre_crks_rsvd0_ver_m.s_present);
8534 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
8535 gre_crks_rsvd0_ver_v.s_present &
8536 gre_crks_rsvd0_ver_m.s_present);
8540 * Add NVGRE item to matcher and to the value.
8542 * @param[in, out] matcher
8544 * @param[in, out] key
8545 * Flow matcher value.
8547 * Flow pattern to translate.
8549 * Item is inner pattern.
8552 flow_dv_translate_item_nvgre(void *matcher, void *key,
8553 const struct rte_flow_item *item,
8556 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
8557 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
8558 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8559 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8560 const char *tni_flow_id_m;
8561 const char *tni_flow_id_v;
8567 /* For NVGRE, GRE header fields must be set with defined values. */
8568 const struct rte_flow_item_gre gre_spec = {
8569 .c_rsvd0_ver = RTE_BE16(0x2000),
8570 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
8572 const struct rte_flow_item_gre gre_mask = {
8573 .c_rsvd0_ver = RTE_BE16(0xB000),
8574 .protocol = RTE_BE16(UINT16_MAX),
8576 const struct rte_flow_item gre_item = {
8581 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
8585 nvgre_m = &rte_flow_item_nvgre_mask;
8586 tni_flow_id_m = (const char *)nvgre_m->tni;
8587 tni_flow_id_v = (const char *)nvgre_v->tni;
8588 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
8589 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
8590 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
8591 memcpy(gre_key_m, tni_flow_id_m, size);
8592 for (i = 0; i < size; ++i)
8593 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
8597 * Add VXLAN item to matcher and to the value.
8599 * @param[in, out] matcher
8601 * @param[in, out] key
8602 * Flow matcher value.
8604 * Flow pattern to translate.
8606 * Item is inner pattern.
8609 flow_dv_translate_item_vxlan(void *matcher, void *key,
8610 const struct rte_flow_item *item,
8613 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
8614 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
8617 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8618 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8626 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8628 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8630 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8632 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8634 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8635 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8636 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8637 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8638 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8643 vxlan_m = &rte_flow_item_vxlan_mask;
8644 size = sizeof(vxlan_m->vni);
8645 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
8646 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
8647 memcpy(vni_m, vxlan_m->vni, size);
8648 for (i = 0; i < size; ++i)
8649 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8653 * Add VXLAN-GPE item to matcher and to the value.
8655 * @param[in, out] matcher
8657 * @param[in, out] key
8658 * Flow matcher value.
8660 * Flow pattern to translate.
8662 * Item is inner pattern.
8666 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
8667 const struct rte_flow_item *item, int inner)
8669 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
8670 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
8674 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
8676 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8682 uint8_t flags_m = 0xff;
8683 uint8_t flags_v = 0xc;
8686 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8688 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8690 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8692 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8694 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8695 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8696 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8697 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8698 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8703 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
8704 size = sizeof(vxlan_m->vni);
8705 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
8706 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
8707 memcpy(vni_m, vxlan_m->vni, size);
8708 for (i = 0; i < size; ++i)
8709 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8710 if (vxlan_m->flags) {
8711 flags_m = vxlan_m->flags;
8712 flags_v = vxlan_v->flags;
8714 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
8715 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
8716 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
8718 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
8723 * Add Geneve item to matcher and to the value.
8725 * @param[in, out] matcher
8727 * @param[in, out] key
8728 * Flow matcher value.
8730 * Flow pattern to translate.
8732 * Item is inner pattern.
8736 flow_dv_translate_item_geneve(void *matcher, void *key,
8737 const struct rte_flow_item *item, int inner)
8739 const struct rte_flow_item_geneve *geneve_m = item->mask;
8740 const struct rte_flow_item_geneve *geneve_v = item->spec;
8743 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8744 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8753 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8755 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8757 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8759 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8761 dport = MLX5_UDP_PORT_GENEVE;
8762 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8763 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8764 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8769 geneve_m = &rte_flow_item_geneve_mask;
8770 size = sizeof(geneve_m->vni);
8771 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
8772 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
8773 memcpy(vni_m, geneve_m->vni, size);
8774 for (i = 0; i < size; ++i)
8775 vni_v[i] = vni_m[i] & geneve_v->vni[i];
8776 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
8777 rte_be_to_cpu_16(geneve_m->protocol));
8778 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
8779 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
8780 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
8781 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
8782 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
8783 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
8784 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
8785 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
8786 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
8787 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
8788 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
8789 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
8790 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
8794 * Create Geneve TLV option resource.
8796 * @param dev[in, out]
8797 * Pointer to rte_eth_dev structure.
8798 * @param[in, out] tag_be24
8799 * Tag value in big endian then R-shift 8.
8800 * @parm[in, out] dev_flow
8801 * Pointer to the dev_flow.
8803 * pointer to error structure.
8806 * 0 on success otherwise -errno and errno is set.
8810 flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
8811 const struct rte_flow_item *item,
8812 struct rte_flow_error *error)
8814 struct mlx5_priv *priv = dev->data->dev_private;
8815 struct mlx5_dev_ctx_shared *sh = priv->sh;
8816 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
8817 sh->geneve_tlv_option_resource;
8818 struct mlx5_devx_obj *obj;
8819 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
8824 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
8825 if (geneve_opt_resource != NULL) {
8826 if (geneve_opt_resource->option_class ==
8827 geneve_opt_v->option_class &&
8828 geneve_opt_resource->option_type ==
8829 geneve_opt_v->option_type &&
8830 geneve_opt_resource->length ==
8831 geneve_opt_v->option_len) {
8832 /* We already have GENVE TLV option obj allocated. */
8833 __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
8836 ret = rte_flow_error_set(error, ENOMEM,
8837 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8838 "Only one GENEVE TLV option supported");
8842 /* Create a GENEVE TLV object and resource. */
8843 obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->ctx,
8844 geneve_opt_v->option_class,
8845 geneve_opt_v->option_type,
8846 geneve_opt_v->option_len);
8848 ret = rte_flow_error_set(error, ENODATA,
8849 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8850 "Failed to create GENEVE TLV Devx object");
8853 sh->geneve_tlv_option_resource =
8854 mlx5_malloc(MLX5_MEM_ZERO,
8855 sizeof(*geneve_opt_resource),
8857 if (!sh->geneve_tlv_option_resource) {
8858 claim_zero(mlx5_devx_cmd_destroy(obj));
8859 ret = rte_flow_error_set(error, ENOMEM,
8860 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8861 "GENEVE TLV object memory allocation failed");
8864 geneve_opt_resource = sh->geneve_tlv_option_resource;
8865 geneve_opt_resource->obj = obj;
8866 geneve_opt_resource->option_class = geneve_opt_v->option_class;
8867 geneve_opt_resource->option_type = geneve_opt_v->option_type;
8868 geneve_opt_resource->length = geneve_opt_v->option_len;
8869 __atomic_store_n(&geneve_opt_resource->refcnt, 1,
8873 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
8878 * Add Geneve TLV option item to matcher.
8880 * @param[in, out] dev
8881 * Pointer to rte_eth_dev structure.
8882 * @param[in, out] matcher
8884 * @param[in, out] key
8885 * Flow matcher value.
8887 * Flow pattern to translate.
8889 * Pointer to error structure.
8892 flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *matcher,
8893 void *key, const struct rte_flow_item *item,
8894 struct rte_flow_error *error)
8896 const struct rte_flow_item_geneve_opt *geneve_opt_m = item->mask;
8897 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
8898 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8899 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8900 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
8902 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8903 rte_be32_t opt_data_key = 0, opt_data_mask = 0;
8909 geneve_opt_m = &rte_flow_item_geneve_opt_mask;
8910 ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
8913 DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
8917 * Set the option length in GENEVE header if not requested.
8918 * The GENEVE TLV option length is expressed by the option length field
8919 * in the GENEVE header.
8920 * If the option length was not requested but the GENEVE TLV option item
8921 * is present we set the option length field implicitly.
8923 if (!MLX5_GET16(fte_match_set_misc, misc_m, geneve_opt_len)) {
8924 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
8925 MLX5_GENEVE_OPTLEN_MASK);
8926 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
8927 geneve_opt_v->option_len + 1);
8930 if (geneve_opt_v->data) {
8931 memcpy(&opt_data_key, geneve_opt_v->data,
8932 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
8933 sizeof(opt_data_key)));
8934 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
8935 sizeof(opt_data_key));
8936 memcpy(&opt_data_mask, geneve_opt_m->data,
8937 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
8938 sizeof(opt_data_mask)));
8939 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
8940 sizeof(opt_data_mask));
8941 MLX5_SET(fte_match_set_misc3, misc3_m,
8942 geneve_tlv_option_0_data,
8943 rte_be_to_cpu_32(opt_data_mask));
8944 MLX5_SET(fte_match_set_misc3, misc3_v,
8945 geneve_tlv_option_0_data,
8946 rte_be_to_cpu_32(opt_data_key & opt_data_mask));
8952 * Add MPLS item to matcher and to the value.
8954 * @param[in, out] matcher
8956 * @param[in, out] key
8957 * Flow matcher value.
8959 * Flow pattern to translate.
8960 * @param[in] prev_layer
8961 * The protocol layer indicated in previous item.
8963 * Item is inner pattern.
8966 flow_dv_translate_item_mpls(void *matcher, void *key,
8967 const struct rte_flow_item *item,
8968 uint64_t prev_layer,
8971 const uint32_t *in_mpls_m = item->mask;
8972 const uint32_t *in_mpls_v = item->spec;
8973 uint32_t *out_mpls_m = 0;
8974 uint32_t *out_mpls_v = 0;
8975 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8976 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8977 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
8979 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
8980 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
8981 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8983 switch (prev_layer) {
8984 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
8985 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
8986 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8987 MLX5_UDP_PORT_MPLS);
8989 case MLX5_FLOW_LAYER_GRE:
8990 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
8991 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8992 RTE_ETHER_TYPE_MPLS);
8995 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8996 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9003 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
9004 switch (prev_layer) {
9005 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9007 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9008 outer_first_mpls_over_udp);
9010 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9011 outer_first_mpls_over_udp);
9013 case MLX5_FLOW_LAYER_GRE:
9015 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9016 outer_first_mpls_over_gre);
9018 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9019 outer_first_mpls_over_gre);
9022 /* Inner MPLS not over GRE is not supported. */
9025 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9029 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9035 if (out_mpls_m && out_mpls_v) {
9036 *out_mpls_m = *in_mpls_m;
9037 *out_mpls_v = *in_mpls_v & *in_mpls_m;
9042 * Add metadata register item to matcher
9044 * @param[in, out] matcher
9046 * @param[in, out] key
9047 * Flow matcher value.
9048 * @param[in] reg_type
9049 * Type of device metadata register
9056 flow_dv_match_meta_reg(void *matcher, void *key,
9057 enum modify_reg reg_type,
9058 uint32_t data, uint32_t mask)
9061 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
9063 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9069 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
9070 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
9073 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
9074 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
9078 * The metadata register C0 field might be divided into
9079 * source vport index and META item value, we should set
9080 * this field according to specified mask, not as whole one.
9082 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
9084 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
9085 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
9088 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
9091 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
9092 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
9095 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
9096 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
9099 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
9100 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
9103 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
9104 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
9107 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
9108 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
9111 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
9112 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
9115 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
9116 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
9125 * Add MARK item to matcher
9128 * The device to configure through.
9129 * @param[in, out] matcher
9131 * @param[in, out] key
9132 * Flow matcher value.
9134 * Flow pattern to translate.
9137 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
9138 void *matcher, void *key,
9139 const struct rte_flow_item *item)
9141 struct mlx5_priv *priv = dev->data->dev_private;
9142 const struct rte_flow_item_mark *mark;
9146 mark = item->mask ? (const void *)item->mask :
9147 &rte_flow_item_mark_mask;
9148 mask = mark->id & priv->sh->dv_mark_mask;
9149 mark = (const void *)item->spec;
9151 value = mark->id & priv->sh->dv_mark_mask & mask;
9153 enum modify_reg reg;
9155 /* Get the metadata register index for the mark. */
9156 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
9157 MLX5_ASSERT(reg > 0);
9158 if (reg == REG_C_0) {
9159 struct mlx5_priv *priv = dev->data->dev_private;
9160 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9161 uint32_t shl_c0 = rte_bsf32(msk_c0);
9167 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9172 * Add META item to matcher
9175 * The devich to configure through.
9176 * @param[in, out] matcher
9178 * @param[in, out] key
9179 * Flow matcher value.
9181 * Attributes of flow that includes this item.
9183 * Flow pattern to translate.
9186 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
9187 void *matcher, void *key,
9188 const struct rte_flow_attr *attr,
9189 const struct rte_flow_item *item)
9191 const struct rte_flow_item_meta *meta_m;
9192 const struct rte_flow_item_meta *meta_v;
9194 meta_m = (const void *)item->mask;
9196 meta_m = &rte_flow_item_meta_mask;
9197 meta_v = (const void *)item->spec;
9200 uint32_t value = meta_v->data;
9201 uint32_t mask = meta_m->data;
9203 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
9206 MLX5_ASSERT(reg != REG_NON);
9208 * In datapath code there is no endianness
9209 * coversions for perfromance reasons, all
9210 * pattern conversions are done in rte_flow.
9212 value = rte_cpu_to_be_32(value);
9213 mask = rte_cpu_to_be_32(mask);
9214 if (reg == REG_C_0) {
9215 struct mlx5_priv *priv = dev->data->dev_private;
9216 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9217 uint32_t shl_c0 = rte_bsf32(msk_c0);
9218 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
9219 uint32_t shr_c0 = __builtin_clz(priv->sh->dv_meta_mask);
9226 MLX5_ASSERT(msk_c0);
9227 MLX5_ASSERT(!(~msk_c0 & mask));
9229 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9234 * Add vport metadata Reg C0 item to matcher
9236 * @param[in, out] matcher
9238 * @param[in, out] key
9239 * Flow matcher value.
9241 * Flow pattern to translate.
9244 flow_dv_translate_item_meta_vport(void *matcher, void *key,
9245 uint32_t value, uint32_t mask)
9247 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
9251 * Add tag item to matcher
9254 * The devich to configure through.
9255 * @param[in, out] matcher
9257 * @param[in, out] key
9258 * Flow matcher value.
9260 * Flow pattern to translate.
9263 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
9264 void *matcher, void *key,
9265 const struct rte_flow_item *item)
9267 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
9268 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
9269 uint32_t mask, value;
9272 value = tag_v->data;
9273 mask = tag_m ? tag_m->data : UINT32_MAX;
9274 if (tag_v->id == REG_C_0) {
9275 struct mlx5_priv *priv = dev->data->dev_private;
9276 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9277 uint32_t shl_c0 = rte_bsf32(msk_c0);
9283 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
9287 * Add TAG item to matcher
9290 * The devich to configure through.
9291 * @param[in, out] matcher
9293 * @param[in, out] key
9294 * Flow matcher value.
9296 * Flow pattern to translate.
9299 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
9300 void *matcher, void *key,
9301 const struct rte_flow_item *item)
9303 const struct rte_flow_item_tag *tag_v = item->spec;
9304 const struct rte_flow_item_tag *tag_m = item->mask;
9305 enum modify_reg reg;
9308 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
9309 /* Get the metadata register index for the tag. */
9310 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
9311 MLX5_ASSERT(reg > 0);
9312 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
9316 * Add source vport match to the specified matcher.
9318 * @param[in, out] matcher
9320 * @param[in, out] key
9321 * Flow matcher value.
9323 * Source vport value to match
9328 flow_dv_translate_item_source_vport(void *matcher, void *key,
9329 int16_t port, uint16_t mask)
9331 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9332 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9334 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
9335 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
9339 * Translate port-id item to eswitch match on port-id.
9342 * The devich to configure through.
9343 * @param[in, out] matcher
9345 * @param[in, out] key
9346 * Flow matcher value.
9348 * Flow pattern to translate.
9353 * 0 on success, a negative errno value otherwise.
9356 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
9357 void *key, const struct rte_flow_item *item,
9358 const struct rte_flow_attr *attr)
9360 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
9361 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
9362 struct mlx5_priv *priv;
9365 mask = pid_m ? pid_m->id : 0xffff;
9366 id = pid_v ? pid_v->id : dev->data->port_id;
9367 priv = mlx5_port_to_eswitch_info(id, item == NULL);
9371 * Translate to vport field or to metadata, depending on mode.
9372 * Kernel can use either misc.source_port or half of C0 metadata
9375 if (priv->vport_meta_mask) {
9377 * Provide the hint for SW steering library
9378 * to insert the flow into ingress domain and
9379 * save the extra vport match.
9381 if (mask == 0xffff && priv->vport_id == 0xffff &&
9382 priv->pf_bond < 0 && attr->transfer)
9383 flow_dv_translate_item_source_vport
9384 (matcher, key, priv->vport_id, mask);
9386 * We should always set the vport metadata register,
9387 * otherwise the SW steering library can drop
9388 * the rule if wire vport metadata value is not zero,
9389 * it depends on kernel configuration.
9391 flow_dv_translate_item_meta_vport(matcher, key,
9392 priv->vport_meta_tag,
9393 priv->vport_meta_mask);
9395 flow_dv_translate_item_source_vport(matcher, key,
9396 priv->vport_id, mask);
9402 * Add ICMP6 item to matcher and to the value.
9404 * @param[in, out] matcher
9406 * @param[in, out] key
9407 * Flow matcher value.
9409 * Flow pattern to translate.
9411 * Item is inner pattern.
9414 flow_dv_translate_item_icmp6(void *matcher, void *key,
9415 const struct rte_flow_item *item,
9418 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
9419 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
9422 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9424 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9426 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9428 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9430 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9432 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9434 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9435 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
9439 icmp6_m = &rte_flow_item_icmp6_mask;
9440 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
9441 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
9442 icmp6_v->type & icmp6_m->type);
9443 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
9444 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
9445 icmp6_v->code & icmp6_m->code);
9449 * Add ICMP item to matcher and to the value.
9451 * @param[in, out] matcher
9453 * @param[in, out] key
9454 * Flow matcher value.
9456 * Flow pattern to translate.
9458 * Item is inner pattern.
9461 flow_dv_translate_item_icmp(void *matcher, void *key,
9462 const struct rte_flow_item *item,
9465 const struct rte_flow_item_icmp *icmp_m = item->mask;
9466 const struct rte_flow_item_icmp *icmp_v = item->spec;
9467 uint32_t icmp_header_data_m = 0;
9468 uint32_t icmp_header_data_v = 0;
9471 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9473 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9475 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9477 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9479 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9481 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9483 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9484 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
9488 icmp_m = &rte_flow_item_icmp_mask;
9489 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
9490 icmp_m->hdr.icmp_type);
9491 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
9492 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
9493 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
9494 icmp_m->hdr.icmp_code);
9495 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
9496 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
9497 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
9498 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
9499 if (icmp_header_data_m) {
9500 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
9501 icmp_header_data_v |=
9502 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
9503 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
9504 icmp_header_data_m);
9505 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
9506 icmp_header_data_v & icmp_header_data_m);
9511 * Add GTP item to matcher and to the value.
9513 * @param[in, out] matcher
9515 * @param[in, out] key
9516 * Flow matcher value.
9518 * Flow pattern to translate.
9520 * Item is inner pattern.
9523 flow_dv_translate_item_gtp(void *matcher, void *key,
9524 const struct rte_flow_item *item, int inner)
9526 const struct rte_flow_item_gtp *gtp_m = item->mask;
9527 const struct rte_flow_item_gtp *gtp_v = item->spec;
9530 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9532 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9533 uint16_t dport = RTE_GTPU_UDP_PORT;
9536 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9538 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9540 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9542 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9544 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9545 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9546 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
9551 gtp_m = &rte_flow_item_gtp_mask;
9552 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
9553 gtp_m->v_pt_rsv_flags);
9554 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
9555 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
9556 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
9557 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
9558 gtp_v->msg_type & gtp_m->msg_type);
9559 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
9560 rte_be_to_cpu_32(gtp_m->teid));
9561 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
9562 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
9566 * Add GTP PSC item to matcher.
9568 * @param[in, out] matcher
9570 * @param[in, out] key
9571 * Flow matcher value.
9573 * Flow pattern to translate.
9576 flow_dv_translate_item_gtp_psc(void *matcher, void *key,
9577 const struct rte_flow_item *item)
9579 const struct rte_flow_item_gtp_psc *gtp_psc_m = item->mask;
9580 const struct rte_flow_item_gtp_psc *gtp_psc_v = item->spec;
9581 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9583 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9589 uint8_t next_ext_header_type;
9594 /* Always set E-flag match on one, regardless of GTP item settings. */
9595 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_m, gtpu_msg_flags);
9596 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9597 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags, gtp_flags);
9598 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
9599 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9600 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
9601 /*Set next extension header type. */
9604 dw_2.next_ext_header_type = 0xff;
9605 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_dw_2,
9606 rte_cpu_to_be_32(dw_2.w32));
9609 dw_2.next_ext_header_type = 0x85;
9610 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
9611 rte_cpu_to_be_32(dw_2.w32));
9623 /*Set extension header PDU type and Qos. */
9625 gtp_psc_m = &rte_flow_item_gtp_psc_mask;
9627 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_m->pdu_type);
9628 dw_0.qfi = gtp_psc_m->qfi;
9629 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_first_ext_dw_0,
9630 rte_cpu_to_be_32(dw_0.w32));
9632 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->pdu_type &
9633 gtp_psc_m->pdu_type);
9634 dw_0.qfi = gtp_psc_v->qfi & gtp_psc_m->qfi;
9635 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
9636 rte_cpu_to_be_32(dw_0.w32));
9642 * Add eCPRI item to matcher and to the value.
9645 * The devich to configure through.
9646 * @param[in, out] matcher
9648 * @param[in, out] key
9649 * Flow matcher value.
9651 * Flow pattern to translate.
9652 * @param[in] samples
9653 * Sample IDs to be used in the matching.
9656 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
9657 void *key, const struct rte_flow_item *item)
9659 struct mlx5_priv *priv = dev->data->dev_private;
9660 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
9661 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
9662 struct rte_ecpri_common_hdr common;
9663 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
9665 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
9673 ecpri_m = &rte_flow_item_ecpri_mask;
9675 * Maximal four DW samples are supported in a single matching now.
9676 * Two are used now for a eCPRI matching:
9677 * 1. Type: one byte, mask should be 0x00ff0000 in network order
9678 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
9681 if (!ecpri_m->hdr.common.u32)
9683 samples = priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0].ids;
9684 /* Need to take the whole DW as the mask to fill the entry. */
9685 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9686 prog_sample_field_value_0);
9687 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9688 prog_sample_field_value_0);
9689 /* Already big endian (network order) in the header. */
9690 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
9691 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
9692 /* Sample#0, used for matching type, offset 0. */
9693 MLX5_SET(fte_match_set_misc4, misc4_m,
9694 prog_sample_field_id_0, samples[0]);
9695 /* It makes no sense to set the sample ID in the mask field. */
9696 MLX5_SET(fte_match_set_misc4, misc4_v,
9697 prog_sample_field_id_0, samples[0]);
9699 * Checking if message body part needs to be matched.
9700 * Some wildcard rules only matching type field should be supported.
9702 if (ecpri_m->hdr.dummy[0]) {
9703 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
9704 switch (common.type) {
9705 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
9706 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
9707 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
9708 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9709 prog_sample_field_value_1);
9710 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9711 prog_sample_field_value_1);
9712 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
9713 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
9714 ecpri_m->hdr.dummy[0];
9715 /* Sample#1, to match message body, offset 4. */
9716 MLX5_SET(fte_match_set_misc4, misc4_m,
9717 prog_sample_field_id_1, samples[1]);
9718 MLX5_SET(fte_match_set_misc4, misc4_v,
9719 prog_sample_field_id_1, samples[1]);
9722 /* Others, do not match any sample ID. */
9729 * Add connection tracking status item to matcher
9732 * The devich to configure through.
9733 * @param[in, out] matcher
9735 * @param[in, out] key
9736 * Flow matcher value.
9738 * Flow pattern to translate.
9741 flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
9742 void *matcher, void *key,
9743 const struct rte_flow_item *item)
9745 uint32_t reg_value = 0;
9747 /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
9748 uint32_t reg_mask = 0;
9749 const struct rte_flow_item_conntrack *spec = item->spec;
9750 const struct rte_flow_item_conntrack *mask = item->mask;
9752 struct rte_flow_error error;
9755 mask = &rte_flow_item_conntrack_mask;
9756 if (!spec || !mask->flags)
9758 flags = spec->flags & mask->flags;
9759 /* The conflict should be checked in the validation. */
9760 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
9761 reg_value |= MLX5_CT_SYNDROME_VALID;
9762 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
9763 reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
9764 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
9765 reg_value |= MLX5_CT_SYNDROME_INVALID;
9766 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
9767 reg_value |= MLX5_CT_SYNDROME_TRAP;
9768 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
9769 reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
9770 if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
9771 RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
9772 RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
9774 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
9775 reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
9776 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
9777 reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
9778 /* The REG_C_x value could be saved during startup. */
9779 reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
9780 if (reg_id == REG_NON)
9782 flow_dv_match_meta_reg(matcher, key, (enum modify_reg)reg_id,
9783 reg_value, reg_mask);
9786 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
9788 #define HEADER_IS_ZERO(match_criteria, headers) \
9789 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
9790 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
9793 * Calculate flow matcher enable bitmap.
9795 * @param match_criteria
9796 * Pointer to flow matcher criteria.
9799 * Bitmap of enabled fields.
9802 flow_dv_matcher_enable(uint32_t *match_criteria)
9804 uint8_t match_criteria_enable;
9806 match_criteria_enable =
9807 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
9808 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
9809 match_criteria_enable |=
9810 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
9811 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
9812 match_criteria_enable |=
9813 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
9814 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
9815 match_criteria_enable |=
9816 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
9817 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
9818 match_criteria_enable |=
9819 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
9820 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
9821 match_criteria_enable |=
9822 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
9823 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
9824 return match_criteria_enable;
9827 struct mlx5_hlist_entry *
9828 flow_dv_tbl_create_cb(struct mlx5_hlist *list, uint64_t key64, void *cb_ctx)
9830 struct mlx5_dev_ctx_shared *sh = list->ctx;
9831 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9832 struct rte_eth_dev *dev = ctx->dev;
9833 struct mlx5_flow_tbl_data_entry *tbl_data;
9834 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data;
9835 struct rte_flow_error *error = ctx->error;
9836 union mlx5_flow_tbl_key key = { .v64 = key64 };
9837 struct mlx5_flow_tbl_resource *tbl;
9842 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
9844 rte_flow_error_set(error, ENOMEM,
9845 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9847 "cannot allocate flow table data entry");
9850 tbl_data->idx = idx;
9851 tbl_data->tunnel = tt_prm->tunnel;
9852 tbl_data->group_id = tt_prm->group_id;
9853 tbl_data->external = !!tt_prm->external;
9854 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
9855 tbl_data->is_egress = !!key.is_egress;
9856 tbl_data->is_transfer = !!key.is_fdb;
9857 tbl_data->dummy = !!key.dummy;
9858 tbl_data->level = key.level;
9859 tbl_data->id = key.id;
9860 tbl = &tbl_data->tbl;
9862 return &tbl_data->entry;
9864 domain = sh->fdb_domain;
9865 else if (key.is_egress)
9866 domain = sh->tx_domain;
9868 domain = sh->rx_domain;
9869 ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
9871 rte_flow_error_set(error, ENOMEM,
9872 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9873 NULL, "cannot create flow table object");
9874 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
9877 if (key.level != 0) {
9878 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
9879 (tbl->obj, &tbl_data->jump.action);
9881 rte_flow_error_set(error, ENOMEM,
9882 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9884 "cannot create flow jump action");
9885 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
9886 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
9890 MKSTR(matcher_name, "%s_%s_%u_%u_matcher_cache",
9891 key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
9893 mlx5_cache_list_init(&tbl_data->matchers, matcher_name, 0, sh,
9894 flow_dv_matcher_create_cb,
9895 flow_dv_matcher_match_cb,
9896 flow_dv_matcher_remove_cb);
9897 return &tbl_data->entry;
9901 flow_dv_tbl_match_cb(struct mlx5_hlist *list __rte_unused,
9902 struct mlx5_hlist_entry *entry, uint64_t key64,
9903 void *cb_ctx __rte_unused)
9905 struct mlx5_flow_tbl_data_entry *tbl_data =
9906 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
9907 union mlx5_flow_tbl_key key = { .v64 = key64 };
9909 return tbl_data->level != key.level ||
9910 tbl_data->id != key.id ||
9911 tbl_data->dummy != key.dummy ||
9912 tbl_data->is_transfer != !!key.is_fdb ||
9913 tbl_data->is_egress != !!key.is_egress;
9919 * @param[in, out] dev
9920 * Pointer to rte_eth_dev structure.
9921 * @param[in] table_level
9922 * Table level to use.
9924 * Direction of the table.
9925 * @param[in] transfer
9926 * E-Switch or NIC flow.
9928 * Dummy entry for dv API.
9929 * @param[in] table_id
9932 * pointer to error structure.
9935 * Returns tables resource based on the index, NULL in case of failed.
9937 struct mlx5_flow_tbl_resource *
9938 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
9939 uint32_t table_level, uint8_t egress,
9942 const struct mlx5_flow_tunnel *tunnel,
9943 uint32_t group_id, uint8_t dummy,
9945 struct rte_flow_error *error)
9947 struct mlx5_priv *priv = dev->data->dev_private;
9948 union mlx5_flow_tbl_key table_key = {
9950 .level = table_level,
9954 .is_fdb = !!transfer,
9955 .is_egress = !!egress,
9958 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
9960 .group_id = group_id,
9961 .external = external,
9963 struct mlx5_flow_cb_ctx ctx = {
9968 struct mlx5_hlist_entry *entry;
9969 struct mlx5_flow_tbl_data_entry *tbl_data;
9971 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
9973 rte_flow_error_set(error, ENOMEM,
9974 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9975 "cannot get table");
9978 DRV_LOG(DEBUG, "table_level %u table_id %u "
9979 "tunnel %u group %u registered.",
9980 table_level, table_id,
9981 tunnel ? tunnel->tunnel_id : 0, group_id);
9982 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
9983 return &tbl_data->tbl;
9987 flow_dv_tbl_remove_cb(struct mlx5_hlist *list,
9988 struct mlx5_hlist_entry *entry)
9990 struct mlx5_dev_ctx_shared *sh = list->ctx;
9991 struct mlx5_flow_tbl_data_entry *tbl_data =
9992 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
9994 MLX5_ASSERT(entry && sh);
9995 if (tbl_data->jump.action)
9996 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
9997 if (tbl_data->tbl.obj)
9998 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
9999 if (tbl_data->tunnel_offload && tbl_data->external) {
10000 struct mlx5_hlist_entry *he;
10001 struct mlx5_hlist *tunnel_grp_hash;
10002 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
10003 union tunnel_tbl_key tunnel_key = {
10004 .tunnel_id = tbl_data->tunnel ?
10005 tbl_data->tunnel->tunnel_id : 0,
10006 .group = tbl_data->group_id
10008 uint32_t table_level = tbl_data->level;
10010 tunnel_grp_hash = tbl_data->tunnel ?
10011 tbl_data->tunnel->groups :
10013 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, NULL);
10015 mlx5_hlist_unregister(tunnel_grp_hash, he);
10017 "table_level %u id %u tunnel %u group %u released.",
10021 tbl_data->tunnel->tunnel_id : 0,
10022 tbl_data->group_id);
10024 mlx5_cache_list_destroy(&tbl_data->matchers);
10025 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10029 * Release a flow table.
10032 * Pointer to device shared structure.
10034 * Table resource to be released.
10037 * Returns 0 if table was released, else return 1;
10040 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
10041 struct mlx5_flow_tbl_resource *tbl)
10043 struct mlx5_flow_tbl_data_entry *tbl_data =
10044 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10048 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
10052 flow_dv_matcher_match_cb(struct mlx5_cache_list *list __rte_unused,
10053 struct mlx5_cache_entry *entry, void *cb_ctx)
10055 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10056 struct mlx5_flow_dv_matcher *ref = ctx->data;
10057 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
10060 return cur->crc != ref->crc ||
10061 cur->priority != ref->priority ||
10062 memcmp((const void *)cur->mask.buf,
10063 (const void *)ref->mask.buf, ref->mask.size);
10066 struct mlx5_cache_entry *
10067 flow_dv_matcher_create_cb(struct mlx5_cache_list *list,
10068 struct mlx5_cache_entry *entry __rte_unused,
10071 struct mlx5_dev_ctx_shared *sh = list->ctx;
10072 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10073 struct mlx5_flow_dv_matcher *ref = ctx->data;
10074 struct mlx5_flow_dv_matcher *cache;
10075 struct mlx5dv_flow_matcher_attr dv_attr = {
10076 .type = IBV_FLOW_ATTR_NORMAL,
10077 .match_mask = (void *)&ref->mask,
10079 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10080 typeof(*tbl), tbl);
10083 cache = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*cache), 0, SOCKET_ID_ANY);
10085 rte_flow_error_set(ctx->error, ENOMEM,
10086 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10087 "cannot create matcher");
10091 dv_attr.match_criteria_enable =
10092 flow_dv_matcher_enable(cache->mask.buf);
10093 dv_attr.priority = ref->priority;
10094 if (tbl->is_egress)
10095 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
10096 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->tbl.obj,
10097 &cache->matcher_object);
10100 rte_flow_error_set(ctx->error, ENOMEM,
10101 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10102 "cannot create matcher");
10105 return &cache->entry;
10109 * Register the flow matcher.
10111 * @param[in, out] dev
10112 * Pointer to rte_eth_dev structure.
10113 * @param[in, out] matcher
10114 * Pointer to flow matcher.
10115 * @param[in, out] key
10116 * Pointer to flow table key.
10117 * @parm[in, out] dev_flow
10118 * Pointer to the dev_flow.
10119 * @param[out] error
10120 * pointer to error structure.
10123 * 0 on success otherwise -errno and errno is set.
10126 flow_dv_matcher_register(struct rte_eth_dev *dev,
10127 struct mlx5_flow_dv_matcher *ref,
10128 union mlx5_flow_tbl_key *key,
10129 struct mlx5_flow *dev_flow,
10130 const struct mlx5_flow_tunnel *tunnel,
10132 struct rte_flow_error *error)
10134 struct mlx5_cache_entry *entry;
10135 struct mlx5_flow_dv_matcher *cache;
10136 struct mlx5_flow_tbl_resource *tbl;
10137 struct mlx5_flow_tbl_data_entry *tbl_data;
10138 struct mlx5_flow_cb_ctx ctx = {
10144 * tunnel offload API requires this registration for cases when
10145 * tunnel match rule was inserted before tunnel set rule.
10147 tbl = flow_dv_tbl_resource_get(dev, key->level,
10148 key->is_egress, key->is_fdb,
10149 dev_flow->external, tunnel,
10150 group_id, 0, key->id, error);
10152 return -rte_errno; /* No need to refill the error info */
10153 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10155 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
10157 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
10158 return rte_flow_error_set(error, ENOMEM,
10159 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10160 "cannot allocate ref memory");
10162 cache = container_of(entry, typeof(*cache), entry);
10163 dev_flow->handle->dvh.matcher = cache;
10167 struct mlx5_hlist_entry *
10168 flow_dv_tag_create_cb(struct mlx5_hlist *list, uint64_t key, void *ctx)
10170 struct mlx5_dev_ctx_shared *sh = list->ctx;
10171 struct rte_flow_error *error = ctx;
10172 struct mlx5_flow_dv_tag_resource *entry;
10176 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10178 rte_flow_error_set(error, ENOMEM,
10179 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10180 "cannot allocate resource memory");
10184 entry->tag_id = key;
10185 ret = mlx5_flow_os_create_flow_action_tag(key,
10188 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
10189 rte_flow_error_set(error, ENOMEM,
10190 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10191 NULL, "cannot create action");
10194 return &entry->entry;
10198 flow_dv_tag_match_cb(struct mlx5_hlist *list __rte_unused,
10199 struct mlx5_hlist_entry *entry, uint64_t key,
10200 void *cb_ctx __rte_unused)
10202 struct mlx5_flow_dv_tag_resource *tag =
10203 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10205 return key != tag->tag_id;
10209 * Find existing tag resource or create and register a new one.
10211 * @param dev[in, out]
10212 * Pointer to rte_eth_dev structure.
10213 * @param[in, out] tag_be24
10214 * Tag value in big endian then R-shift 8.
10215 * @parm[in, out] dev_flow
10216 * Pointer to the dev_flow.
10217 * @param[out] error
10218 * pointer to error structure.
10221 * 0 on success otherwise -errno and errno is set.
10224 flow_dv_tag_resource_register
10225 (struct rte_eth_dev *dev,
10227 struct mlx5_flow *dev_flow,
10228 struct rte_flow_error *error)
10230 struct mlx5_priv *priv = dev->data->dev_private;
10231 struct mlx5_flow_dv_tag_resource *cache_resource;
10232 struct mlx5_hlist_entry *entry;
10234 entry = mlx5_hlist_register(priv->sh->tag_table, tag_be24, error);
10236 cache_resource = container_of
10237 (entry, struct mlx5_flow_dv_tag_resource, entry);
10238 dev_flow->handle->dvh.rix_tag = cache_resource->idx;
10239 dev_flow->dv.tag_resource = cache_resource;
10246 flow_dv_tag_remove_cb(struct mlx5_hlist *list,
10247 struct mlx5_hlist_entry *entry)
10249 struct mlx5_dev_ctx_shared *sh = list->ctx;
10250 struct mlx5_flow_dv_tag_resource *tag =
10251 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10253 MLX5_ASSERT(tag && sh && tag->action);
10254 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
10255 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
10256 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10263 * Pointer to Ethernet device.
10268 * 1 while a reference on it exists, 0 when freed.
10271 flow_dv_tag_release(struct rte_eth_dev *dev,
10274 struct mlx5_priv *priv = dev->data->dev_private;
10275 struct mlx5_flow_dv_tag_resource *tag;
10277 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
10280 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
10281 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
10282 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
10286 * Translate port ID action to vport.
10289 * Pointer to rte_eth_dev structure.
10290 * @param[in] action
10291 * Pointer to the port ID action.
10292 * @param[out] dst_port_id
10293 * The target port ID.
10294 * @param[out] error
10295 * Pointer to the error structure.
10298 * 0 on success, a negative errno value otherwise and rte_errno is set.
10301 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
10302 const struct rte_flow_action *action,
10303 uint32_t *dst_port_id,
10304 struct rte_flow_error *error)
10307 struct mlx5_priv *priv;
10308 const struct rte_flow_action_port_id *conf =
10309 (const struct rte_flow_action_port_id *)action->conf;
10311 port = conf->original ? dev->data->port_id : conf->id;
10312 priv = mlx5_port_to_eswitch_info(port, false);
10314 return rte_flow_error_set(error, -rte_errno,
10315 RTE_FLOW_ERROR_TYPE_ACTION,
10317 "No eswitch info was found for port");
10318 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
10320 * This parameter is transferred to
10321 * mlx5dv_dr_action_create_dest_ib_port().
10323 *dst_port_id = priv->dev_port;
10326 * Legacy mode, no LAG configurations is supported.
10327 * This parameter is transferred to
10328 * mlx5dv_dr_action_create_dest_vport().
10330 *dst_port_id = priv->vport_id;
10336 * Create a counter with aging configuration.
10339 * Pointer to rte_eth_dev structure.
10340 * @param[in] dev_flow
10341 * Pointer to the mlx5_flow.
10342 * @param[out] count
10343 * Pointer to the counter action configuration.
10345 * Pointer to the aging action configuration.
10348 * Index to flow counter on success, 0 otherwise.
10351 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
10352 struct mlx5_flow *dev_flow,
10353 const struct rte_flow_action_count *count,
10354 const struct rte_flow_action_age *age)
10357 struct mlx5_age_param *age_param;
10359 if (count && count->shared)
10360 counter = flow_dv_counter_get_shared(dev, count->id);
10362 counter = flow_dv_counter_alloc(dev, !!age);
10363 if (!counter || age == NULL)
10365 age_param = flow_dv_counter_idx_get_age(dev, counter);
10366 age_param->context = age->context ? age->context :
10367 (void *)(uintptr_t)(dev_flow->flow_idx);
10368 age_param->timeout = age->timeout;
10369 age_param->port_id = dev->data->port_id;
10370 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
10371 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
10376 * Add Tx queue matcher
10379 * Pointer to the dev struct.
10380 * @param[in, out] matcher
10382 * @param[in, out] key
10383 * Flow matcher value.
10385 * Flow pattern to translate.
10387 * Item is inner pattern.
10390 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
10391 void *matcher, void *key,
10392 const struct rte_flow_item *item)
10394 const struct mlx5_rte_flow_item_tx_queue *queue_m;
10395 const struct mlx5_rte_flow_item_tx_queue *queue_v;
10397 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
10399 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10400 struct mlx5_txq_ctrl *txq;
10404 queue_m = (const void *)item->mask;
10407 queue_v = (const void *)item->spec;
10410 txq = mlx5_txq_get(dev, queue_v->queue);
10413 queue = txq->obj->sq->id;
10414 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
10415 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
10416 queue & queue_m->queue);
10417 mlx5_txq_release(dev, queue_v->queue);
10421 * Set the hash fields according to the @p flow information.
10423 * @param[in] dev_flow
10424 * Pointer to the mlx5_flow.
10425 * @param[in] rss_desc
10426 * Pointer to the mlx5_flow_rss_desc.
10429 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
10430 struct mlx5_flow_rss_desc *rss_desc)
10432 uint64_t items = dev_flow->handle->layers;
10434 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
10436 dev_flow->hash_fields = 0;
10437 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
10438 if (rss_desc->level >= 2) {
10439 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
10443 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
10444 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
10445 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
10446 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10447 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
10448 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10449 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
10451 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
10453 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
10454 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
10455 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
10456 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10457 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
10458 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10459 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
10461 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
10464 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
10465 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
10466 if (rss_types & ETH_RSS_UDP) {
10467 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10468 dev_flow->hash_fields |=
10469 IBV_RX_HASH_SRC_PORT_UDP;
10470 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10471 dev_flow->hash_fields |=
10472 IBV_RX_HASH_DST_PORT_UDP;
10474 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
10476 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
10477 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
10478 if (rss_types & ETH_RSS_TCP) {
10479 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10480 dev_flow->hash_fields |=
10481 IBV_RX_HASH_SRC_PORT_TCP;
10482 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10483 dev_flow->hash_fields |=
10484 IBV_RX_HASH_DST_PORT_TCP;
10486 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
10492 * Prepare an Rx Hash queue.
10495 * Pointer to Ethernet device.
10496 * @param[in] dev_flow
10497 * Pointer to the mlx5_flow.
10498 * @param[in] rss_desc
10499 * Pointer to the mlx5_flow_rss_desc.
10500 * @param[out] hrxq_idx
10501 * Hash Rx queue index.
10504 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
10506 static struct mlx5_hrxq *
10507 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
10508 struct mlx5_flow *dev_flow,
10509 struct mlx5_flow_rss_desc *rss_desc,
10510 uint32_t *hrxq_idx)
10512 struct mlx5_priv *priv = dev->data->dev_private;
10513 struct mlx5_flow_handle *dh = dev_flow->handle;
10514 struct mlx5_hrxq *hrxq;
10516 MLX5_ASSERT(rss_desc->queue_num);
10517 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
10518 rss_desc->hash_fields = dev_flow->hash_fields;
10519 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
10520 rss_desc->shared_rss = 0;
10521 *hrxq_idx = mlx5_hrxq_get(dev, rss_desc);
10524 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
10530 * Release sample sub action resource.
10532 * @param[in, out] dev
10533 * Pointer to rte_eth_dev structure.
10534 * @param[in] act_res
10535 * Pointer to sample sub action resource.
10538 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
10539 struct mlx5_flow_sub_actions_idx *act_res)
10541 if (act_res->rix_hrxq) {
10542 mlx5_hrxq_release(dev, act_res->rix_hrxq);
10543 act_res->rix_hrxq = 0;
10545 if (act_res->rix_encap_decap) {
10546 flow_dv_encap_decap_resource_release(dev,
10547 act_res->rix_encap_decap);
10548 act_res->rix_encap_decap = 0;
10550 if (act_res->rix_port_id_action) {
10551 flow_dv_port_id_action_resource_release(dev,
10552 act_res->rix_port_id_action);
10553 act_res->rix_port_id_action = 0;
10555 if (act_res->rix_tag) {
10556 flow_dv_tag_release(dev, act_res->rix_tag);
10557 act_res->rix_tag = 0;
10559 if (act_res->rix_jump) {
10560 flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
10561 act_res->rix_jump = 0;
10566 flow_dv_sample_match_cb(struct mlx5_cache_list *list __rte_unused,
10567 struct mlx5_cache_entry *entry, void *cb_ctx)
10569 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10570 struct rte_eth_dev *dev = ctx->dev;
10571 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
10572 struct mlx5_flow_dv_sample_resource *cache_resource =
10573 container_of(entry, typeof(*cache_resource), entry);
10575 if (resource->ratio == cache_resource->ratio &&
10576 resource->ft_type == cache_resource->ft_type &&
10577 resource->ft_id == cache_resource->ft_id &&
10578 resource->set_action == cache_resource->set_action &&
10579 !memcmp((void *)&resource->sample_act,
10580 (void *)&cache_resource->sample_act,
10581 sizeof(struct mlx5_flow_sub_actions_list))) {
10583 * Existing sample action should release the prepared
10584 * sub-actions reference counter.
10586 flow_dv_sample_sub_actions_release(dev,
10587 &resource->sample_idx);
10593 struct mlx5_cache_entry *
10594 flow_dv_sample_create_cb(struct mlx5_cache_list *list __rte_unused,
10595 struct mlx5_cache_entry *entry __rte_unused,
10598 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10599 struct rte_eth_dev *dev = ctx->dev;
10600 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
10601 void **sample_dv_actions = resource->sub_actions;
10602 struct mlx5_flow_dv_sample_resource *cache_resource;
10603 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
10604 struct mlx5_priv *priv = dev->data->dev_private;
10605 struct mlx5_dev_ctx_shared *sh = priv->sh;
10606 struct mlx5_flow_tbl_resource *tbl;
10608 const uint32_t next_ft_step = 1;
10609 uint32_t next_ft_id = resource->ft_id + next_ft_step;
10610 uint8_t is_egress = 0;
10611 uint8_t is_transfer = 0;
10612 struct rte_flow_error *error = ctx->error;
10614 /* Register new sample resource. */
10615 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
10616 if (!cache_resource) {
10617 rte_flow_error_set(error, ENOMEM,
10618 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10620 "cannot allocate resource memory");
10623 *cache_resource = *resource;
10624 /* Create normal path table level */
10625 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
10627 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
10629 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
10630 is_egress, is_transfer,
10631 true, NULL, 0, 0, 0, error);
10633 rte_flow_error_set(error, ENOMEM,
10634 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10636 "fail to create normal path table "
10640 cache_resource->normal_path_tbl = tbl;
10641 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
10642 if (!sh->default_miss_action) {
10643 rte_flow_error_set(error, ENOMEM,
10644 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10646 "default miss action was not "
10650 sample_dv_actions[resource->sample_act.actions_num++] =
10651 sh->default_miss_action;
10653 /* Create a DR sample action */
10654 sampler_attr.sample_ratio = cache_resource->ratio;
10655 sampler_attr.default_next_table = tbl->obj;
10656 sampler_attr.num_sample_actions = resource->sample_act.actions_num;
10657 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
10658 &sample_dv_actions[0];
10659 sampler_attr.action = cache_resource->set_action;
10660 if (mlx5_os_flow_dr_create_flow_action_sampler
10661 (&sampler_attr, &cache_resource->verbs_action)) {
10662 rte_flow_error_set(error, ENOMEM,
10663 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10664 NULL, "cannot create sample action");
10667 cache_resource->idx = idx;
10668 cache_resource->dev = dev;
10669 return &cache_resource->entry;
10671 if (cache_resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
10672 flow_dv_sample_sub_actions_release(dev,
10673 &cache_resource->sample_idx);
10674 if (cache_resource->normal_path_tbl)
10675 flow_dv_tbl_resource_release(MLX5_SH(dev),
10676 cache_resource->normal_path_tbl);
10677 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
10683 * Find existing sample resource or create and register a new one.
10685 * @param[in, out] dev
10686 * Pointer to rte_eth_dev structure.
10687 * @param[in] resource
10688 * Pointer to sample resource.
10689 * @parm[in, out] dev_flow
10690 * Pointer to the dev_flow.
10691 * @param[out] error
10692 * pointer to error structure.
10695 * 0 on success otherwise -errno and errno is set.
10698 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
10699 struct mlx5_flow_dv_sample_resource *resource,
10700 struct mlx5_flow *dev_flow,
10701 struct rte_flow_error *error)
10703 struct mlx5_flow_dv_sample_resource *cache_resource;
10704 struct mlx5_cache_entry *entry;
10705 struct mlx5_priv *priv = dev->data->dev_private;
10706 struct mlx5_flow_cb_ctx ctx = {
10712 entry = mlx5_cache_register(&priv->sh->sample_action_list, &ctx);
10715 cache_resource = container_of(entry, typeof(*cache_resource), entry);
10716 dev_flow->handle->dvh.rix_sample = cache_resource->idx;
10717 dev_flow->dv.sample_res = cache_resource;
10722 flow_dv_dest_array_match_cb(struct mlx5_cache_list *list __rte_unused,
10723 struct mlx5_cache_entry *entry, void *cb_ctx)
10725 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10726 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
10727 struct rte_eth_dev *dev = ctx->dev;
10728 struct mlx5_flow_dv_dest_array_resource *cache_resource =
10729 container_of(entry, typeof(*cache_resource), entry);
10732 if (resource->num_of_dest == cache_resource->num_of_dest &&
10733 resource->ft_type == cache_resource->ft_type &&
10734 !memcmp((void *)cache_resource->sample_act,
10735 (void *)resource->sample_act,
10736 (resource->num_of_dest *
10737 sizeof(struct mlx5_flow_sub_actions_list)))) {
10739 * Existing sample action should release the prepared
10740 * sub-actions reference counter.
10742 for (idx = 0; idx < resource->num_of_dest; idx++)
10743 flow_dv_sample_sub_actions_release(dev,
10744 &resource->sample_idx[idx]);
10750 struct mlx5_cache_entry *
10751 flow_dv_dest_array_create_cb(struct mlx5_cache_list *list __rte_unused,
10752 struct mlx5_cache_entry *entry __rte_unused,
10755 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10756 struct rte_eth_dev *dev = ctx->dev;
10757 struct mlx5_flow_dv_dest_array_resource *cache_resource;
10758 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
10759 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
10760 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
10761 struct mlx5_priv *priv = dev->data->dev_private;
10762 struct mlx5_dev_ctx_shared *sh = priv->sh;
10763 struct mlx5_flow_sub_actions_list *sample_act;
10764 struct mlx5dv_dr_domain *domain;
10765 uint32_t idx = 0, res_idx = 0;
10766 struct rte_flow_error *error = ctx->error;
10767 uint64_t action_flags;
10770 /* Register new destination array resource. */
10771 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
10773 if (!cache_resource) {
10774 rte_flow_error_set(error, ENOMEM,
10775 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10777 "cannot allocate resource memory");
10780 *cache_resource = *resource;
10781 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
10782 domain = sh->fdb_domain;
10783 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
10784 domain = sh->rx_domain;
10786 domain = sh->tx_domain;
10787 for (idx = 0; idx < resource->num_of_dest; idx++) {
10788 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
10789 mlx5_malloc(MLX5_MEM_ZERO,
10790 sizeof(struct mlx5dv_dr_action_dest_attr),
10792 if (!dest_attr[idx]) {
10793 rte_flow_error_set(error, ENOMEM,
10794 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10796 "cannot allocate resource memory");
10799 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
10800 sample_act = &resource->sample_act[idx];
10801 action_flags = sample_act->action_flags;
10802 switch (action_flags) {
10803 case MLX5_FLOW_ACTION_QUEUE:
10804 dest_attr[idx]->dest = sample_act->dr_queue_action;
10806 case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
10807 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
10808 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
10809 dest_attr[idx]->dest_reformat->reformat =
10810 sample_act->dr_encap_action;
10811 dest_attr[idx]->dest_reformat->dest =
10812 sample_act->dr_port_id_action;
10814 case MLX5_FLOW_ACTION_PORT_ID:
10815 dest_attr[idx]->dest = sample_act->dr_port_id_action;
10817 case MLX5_FLOW_ACTION_JUMP:
10818 dest_attr[idx]->dest = sample_act->dr_jump_action;
10821 rte_flow_error_set(error, EINVAL,
10822 RTE_FLOW_ERROR_TYPE_ACTION,
10824 "unsupported actions type");
10828 /* create a dest array actioin */
10829 ret = mlx5_os_flow_dr_create_flow_action_dest_array
10831 cache_resource->num_of_dest,
10833 &cache_resource->action);
10835 rte_flow_error_set(error, ENOMEM,
10836 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10838 "cannot create destination array action");
10841 cache_resource->idx = res_idx;
10842 cache_resource->dev = dev;
10843 for (idx = 0; idx < resource->num_of_dest; idx++)
10844 mlx5_free(dest_attr[idx]);
10845 return &cache_resource->entry;
10847 for (idx = 0; idx < resource->num_of_dest; idx++) {
10848 flow_dv_sample_sub_actions_release(dev,
10849 &cache_resource->sample_idx[idx]);
10850 if (dest_attr[idx])
10851 mlx5_free(dest_attr[idx]);
10854 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
10859 * Find existing destination array resource or create and register a new one.
10861 * @param[in, out] dev
10862 * Pointer to rte_eth_dev structure.
10863 * @param[in] resource
10864 * Pointer to destination array resource.
10865 * @parm[in, out] dev_flow
10866 * Pointer to the dev_flow.
10867 * @param[out] error
10868 * pointer to error structure.
10871 * 0 on success otherwise -errno and errno is set.
10874 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
10875 struct mlx5_flow_dv_dest_array_resource *resource,
10876 struct mlx5_flow *dev_flow,
10877 struct rte_flow_error *error)
10879 struct mlx5_flow_dv_dest_array_resource *cache_resource;
10880 struct mlx5_priv *priv = dev->data->dev_private;
10881 struct mlx5_cache_entry *entry;
10882 struct mlx5_flow_cb_ctx ctx = {
10888 entry = mlx5_cache_register(&priv->sh->dest_array_list, &ctx);
10891 cache_resource = container_of(entry, typeof(*cache_resource), entry);
10892 dev_flow->handle->dvh.rix_dest_array = cache_resource->idx;
10893 dev_flow->dv.dest_array_res = cache_resource;
10898 * Convert Sample action to DV specification.
10901 * Pointer to rte_eth_dev structure.
10902 * @param[in] action
10903 * Pointer to sample action structure.
10904 * @param[in, out] dev_flow
10905 * Pointer to the mlx5_flow.
10907 * Pointer to the flow attributes.
10908 * @param[in, out] num_of_dest
10909 * Pointer to the num of destination.
10910 * @param[in, out] sample_actions
10911 * Pointer to sample actions list.
10912 * @param[in, out] res
10913 * Pointer to sample resource.
10914 * @param[out] error
10915 * Pointer to the error structure.
10918 * 0 on success, a negative errno value otherwise and rte_errno is set.
10921 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
10922 const struct rte_flow_action_sample *action,
10923 struct mlx5_flow *dev_flow,
10924 const struct rte_flow_attr *attr,
10925 uint32_t *num_of_dest,
10926 void **sample_actions,
10927 struct mlx5_flow_dv_sample_resource *res,
10928 struct rte_flow_error *error)
10930 struct mlx5_priv *priv = dev->data->dev_private;
10931 const struct rte_flow_action *sub_actions;
10932 struct mlx5_flow_sub_actions_list *sample_act;
10933 struct mlx5_flow_sub_actions_idx *sample_idx;
10934 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10935 struct rte_flow *flow = dev_flow->flow;
10936 struct mlx5_flow_rss_desc *rss_desc;
10937 uint64_t action_flags = 0;
10940 rss_desc = &wks->rss_desc;
10941 sample_act = &res->sample_act;
10942 sample_idx = &res->sample_idx;
10943 res->ratio = action->ratio;
10944 sub_actions = action->actions;
10945 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
10946 int type = sub_actions->type;
10947 uint32_t pre_rix = 0;
10950 case RTE_FLOW_ACTION_TYPE_QUEUE:
10952 const struct rte_flow_action_queue *queue;
10953 struct mlx5_hrxq *hrxq;
10956 queue = sub_actions->conf;
10957 rss_desc->queue_num = 1;
10958 rss_desc->queue[0] = queue->index;
10959 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
10960 rss_desc, &hrxq_idx);
10962 return rte_flow_error_set
10964 RTE_FLOW_ERROR_TYPE_ACTION,
10966 "cannot create fate queue");
10967 sample_act->dr_queue_action = hrxq->action;
10968 sample_idx->rix_hrxq = hrxq_idx;
10969 sample_actions[sample_act->actions_num++] =
10972 action_flags |= MLX5_FLOW_ACTION_QUEUE;
10973 if (action_flags & MLX5_FLOW_ACTION_MARK)
10974 dev_flow->handle->rix_hrxq = hrxq_idx;
10975 dev_flow->handle->fate_action =
10976 MLX5_FLOW_FATE_QUEUE;
10979 case RTE_FLOW_ACTION_TYPE_RSS:
10981 struct mlx5_hrxq *hrxq;
10983 const struct rte_flow_action_rss *rss;
10984 const uint8_t *rss_key;
10986 rss = sub_actions->conf;
10987 memcpy(rss_desc->queue, rss->queue,
10988 rss->queue_num * sizeof(uint16_t));
10989 rss_desc->queue_num = rss->queue_num;
10990 /* NULL RSS key indicates default RSS key. */
10991 rss_key = !rss->key ? rss_hash_default_key : rss->key;
10992 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
10994 * rss->level and rss.types should be set in advance
10995 * when expanding items for RSS.
10997 flow_dv_hashfields_set(dev_flow, rss_desc);
10998 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
10999 rss_desc, &hrxq_idx);
11001 return rte_flow_error_set
11003 RTE_FLOW_ERROR_TYPE_ACTION,
11005 "cannot create fate queue");
11006 sample_act->dr_queue_action = hrxq->action;
11007 sample_idx->rix_hrxq = hrxq_idx;
11008 sample_actions[sample_act->actions_num++] =
11011 action_flags |= MLX5_FLOW_ACTION_RSS;
11012 if (action_flags & MLX5_FLOW_ACTION_MARK)
11013 dev_flow->handle->rix_hrxq = hrxq_idx;
11014 dev_flow->handle->fate_action =
11015 MLX5_FLOW_FATE_QUEUE;
11018 case RTE_FLOW_ACTION_TYPE_MARK:
11020 uint32_t tag_be = mlx5_flow_mark_set
11021 (((const struct rte_flow_action_mark *)
11022 (sub_actions->conf))->id);
11024 dev_flow->handle->mark = 1;
11025 pre_rix = dev_flow->handle->dvh.rix_tag;
11026 /* Save the mark resource before sample */
11027 pre_r = dev_flow->dv.tag_resource;
11028 if (flow_dv_tag_resource_register(dev, tag_be,
11031 MLX5_ASSERT(dev_flow->dv.tag_resource);
11032 sample_act->dr_tag_action =
11033 dev_flow->dv.tag_resource->action;
11034 sample_idx->rix_tag =
11035 dev_flow->handle->dvh.rix_tag;
11036 sample_actions[sample_act->actions_num++] =
11037 sample_act->dr_tag_action;
11038 /* Recover the mark resource after sample */
11039 dev_flow->dv.tag_resource = pre_r;
11040 dev_flow->handle->dvh.rix_tag = pre_rix;
11041 action_flags |= MLX5_FLOW_ACTION_MARK;
11044 case RTE_FLOW_ACTION_TYPE_COUNT:
11046 if (!flow->counter) {
11048 flow_dv_translate_create_counter(dev,
11049 dev_flow, sub_actions->conf,
11051 if (!flow->counter)
11052 return rte_flow_error_set
11054 RTE_FLOW_ERROR_TYPE_ACTION,
11056 "cannot create counter"
11059 sample_act->dr_cnt_action =
11060 (flow_dv_counter_get_by_idx(dev,
11061 flow->counter, NULL))->action;
11062 sample_actions[sample_act->actions_num++] =
11063 sample_act->dr_cnt_action;
11064 action_flags |= MLX5_FLOW_ACTION_COUNT;
11067 case RTE_FLOW_ACTION_TYPE_PORT_ID:
11069 struct mlx5_flow_dv_port_id_action_resource
11071 uint32_t port_id = 0;
11073 memset(&port_id_resource, 0, sizeof(port_id_resource));
11074 /* Save the port id resource before sample */
11075 pre_rix = dev_flow->handle->rix_port_id_action;
11076 pre_r = dev_flow->dv.port_id_action;
11077 if (flow_dv_translate_action_port_id(dev, sub_actions,
11080 port_id_resource.port_id = port_id;
11081 if (flow_dv_port_id_action_resource_register
11082 (dev, &port_id_resource, dev_flow, error))
11084 sample_act->dr_port_id_action =
11085 dev_flow->dv.port_id_action->action;
11086 sample_idx->rix_port_id_action =
11087 dev_flow->handle->rix_port_id_action;
11088 sample_actions[sample_act->actions_num++] =
11089 sample_act->dr_port_id_action;
11090 /* Recover the port id resource after sample */
11091 dev_flow->dv.port_id_action = pre_r;
11092 dev_flow->handle->rix_port_id_action = pre_rix;
11094 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
11097 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11098 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11099 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11100 /* Save the encap resource before sample */
11101 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
11102 pre_r = dev_flow->dv.encap_decap;
11103 if (flow_dv_create_action_l2_encap(dev, sub_actions,
11108 sample_act->dr_encap_action =
11109 dev_flow->dv.encap_decap->action;
11110 sample_idx->rix_encap_decap =
11111 dev_flow->handle->dvh.rix_encap_decap;
11112 sample_actions[sample_act->actions_num++] =
11113 sample_act->dr_encap_action;
11114 /* Recover the encap resource after sample */
11115 dev_flow->dv.encap_decap = pre_r;
11116 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
11117 action_flags |= MLX5_FLOW_ACTION_ENCAP;
11120 return rte_flow_error_set(error, EINVAL,
11121 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11123 "Not support for sampler action");
11126 sample_act->action_flags = action_flags;
11127 res->ft_id = dev_flow->dv.group;
11128 if (attr->transfer) {
11130 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
11131 uint64_t set_action;
11132 } action_ctx = { .set_action = 0 };
11134 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
11135 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
11136 MLX5_MODIFICATION_TYPE_SET);
11137 MLX5_SET(set_action_in, action_ctx.action_in, field,
11138 MLX5_MODI_META_REG_C_0);
11139 MLX5_SET(set_action_in, action_ctx.action_in, data,
11140 priv->vport_meta_tag);
11141 res->set_action = action_ctx.set_action;
11142 } else if (attr->ingress) {
11143 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
11145 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
11151 * Convert Sample action to DV specification.
11154 * Pointer to rte_eth_dev structure.
11155 * @param[in, out] dev_flow
11156 * Pointer to the mlx5_flow.
11157 * @param[in] num_of_dest
11158 * The num of destination.
11159 * @param[in, out] res
11160 * Pointer to sample resource.
11161 * @param[in, out] mdest_res
11162 * Pointer to destination array resource.
11163 * @param[in] sample_actions
11164 * Pointer to sample path actions list.
11165 * @param[in] action_flags
11166 * Holds the actions detected until now.
11167 * @param[out] error
11168 * Pointer to the error structure.
11171 * 0 on success, a negative errno value otherwise and rte_errno is set.
11174 flow_dv_create_action_sample(struct rte_eth_dev *dev,
11175 struct mlx5_flow *dev_flow,
11176 uint32_t num_of_dest,
11177 struct mlx5_flow_dv_sample_resource *res,
11178 struct mlx5_flow_dv_dest_array_resource *mdest_res,
11179 void **sample_actions,
11180 uint64_t action_flags,
11181 struct rte_flow_error *error)
11183 /* update normal path action resource into last index of array */
11184 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
11185 struct mlx5_flow_sub_actions_list *sample_act =
11186 &mdest_res->sample_act[dest_index];
11187 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11188 struct mlx5_flow_rss_desc *rss_desc;
11189 uint32_t normal_idx = 0;
11190 struct mlx5_hrxq *hrxq;
11194 rss_desc = &wks->rss_desc;
11195 if (num_of_dest > 1) {
11196 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
11197 /* Handle QP action for mirroring */
11198 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11199 rss_desc, &hrxq_idx);
11201 return rte_flow_error_set
11203 RTE_FLOW_ERROR_TYPE_ACTION,
11205 "cannot create rx queue");
11207 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
11208 sample_act->dr_queue_action = hrxq->action;
11209 if (action_flags & MLX5_FLOW_ACTION_MARK)
11210 dev_flow->handle->rix_hrxq = hrxq_idx;
11211 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
11213 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
11215 mdest_res->sample_idx[dest_index].rix_encap_decap =
11216 dev_flow->handle->dvh.rix_encap_decap;
11217 sample_act->dr_encap_action =
11218 dev_flow->dv.encap_decap->action;
11219 dev_flow->handle->dvh.rix_encap_decap = 0;
11221 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
11223 mdest_res->sample_idx[dest_index].rix_port_id_action =
11224 dev_flow->handle->rix_port_id_action;
11225 sample_act->dr_port_id_action =
11226 dev_flow->dv.port_id_action->action;
11227 dev_flow->handle->rix_port_id_action = 0;
11229 if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
11231 mdest_res->sample_idx[dest_index].rix_jump =
11232 dev_flow->handle->rix_jump;
11233 sample_act->dr_jump_action =
11234 dev_flow->dv.jump->action;
11235 dev_flow->handle->rix_jump = 0;
11237 sample_act->actions_num = normal_idx;
11238 /* update sample action resource into first index of array */
11239 mdest_res->ft_type = res->ft_type;
11240 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
11241 sizeof(struct mlx5_flow_sub_actions_idx));
11242 memcpy(&mdest_res->sample_act[0], &res->sample_act,
11243 sizeof(struct mlx5_flow_sub_actions_list));
11244 mdest_res->num_of_dest = num_of_dest;
11245 if (flow_dv_dest_array_resource_register(dev, mdest_res,
11247 return rte_flow_error_set(error, EINVAL,
11248 RTE_FLOW_ERROR_TYPE_ACTION,
11249 NULL, "can't create sample "
11252 res->sub_actions = sample_actions;
11253 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
11254 return rte_flow_error_set(error, EINVAL,
11255 RTE_FLOW_ERROR_TYPE_ACTION,
11257 "can't create sample action");
11263 * Remove an ASO age action from age actions list.
11266 * Pointer to the Ethernet device structure.
11268 * Pointer to the aso age action handler.
11271 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
11272 struct mlx5_aso_age_action *age)
11274 struct mlx5_age_info *age_info;
11275 struct mlx5_age_param *age_param = &age->age_params;
11276 struct mlx5_priv *priv = dev->data->dev_private;
11277 uint16_t expected = AGE_CANDIDATE;
11279 age_info = GET_PORT_AGE_INFO(priv);
11280 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
11281 AGE_FREE, false, __ATOMIC_RELAXED,
11282 __ATOMIC_RELAXED)) {
11284 * We need the lock even it is age timeout,
11285 * since age action may still in process.
11287 rte_spinlock_lock(&age_info->aged_sl);
11288 LIST_REMOVE(age, next);
11289 rte_spinlock_unlock(&age_info->aged_sl);
11290 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
11295 * Release an ASO age action.
11298 * Pointer to the Ethernet device structure.
11299 * @param[in] age_idx
11300 * Index of ASO age action to release.
11302 * True if the release operation is during flow destroy operation.
11303 * False if the release operation is during action destroy operation.
11306 * 0 when age action was removed, otherwise the number of references.
11309 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
11311 struct mlx5_priv *priv = dev->data->dev_private;
11312 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11313 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
11314 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
11317 flow_dv_aso_age_remove_from_age(dev, age);
11318 rte_spinlock_lock(&mng->free_sl);
11319 LIST_INSERT_HEAD(&mng->free, age, next);
11320 rte_spinlock_unlock(&mng->free_sl);
11326 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
11329 * Pointer to the Ethernet device structure.
11332 * 0 on success, otherwise negative errno value and rte_errno is set.
11335 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
11337 struct mlx5_priv *priv = dev->data->dev_private;
11338 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11339 void *old_pools = mng->pools;
11340 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
11341 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
11342 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11345 rte_errno = ENOMEM;
11349 memcpy(pools, old_pools,
11350 mng->n * sizeof(struct mlx5_flow_counter_pool *));
11351 mlx5_free(old_pools);
11353 /* First ASO flow hit allocation - starting ASO data-path. */
11354 int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
11362 mng->pools = pools;
11367 * Create and initialize a new ASO aging pool.
11370 * Pointer to the Ethernet device structure.
11371 * @param[out] age_free
11372 * Where to put the pointer of a new age action.
11375 * The age actions pool pointer and @p age_free is set on success,
11376 * NULL otherwise and rte_errno is set.
11378 static struct mlx5_aso_age_pool *
11379 flow_dv_age_pool_create(struct rte_eth_dev *dev,
11380 struct mlx5_aso_age_action **age_free)
11382 struct mlx5_priv *priv = dev->data->dev_private;
11383 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11384 struct mlx5_aso_age_pool *pool = NULL;
11385 struct mlx5_devx_obj *obj = NULL;
11388 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->ctx,
11391 rte_errno = ENODATA;
11392 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
11395 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
11397 claim_zero(mlx5_devx_cmd_destroy(obj));
11398 rte_errno = ENOMEM;
11401 pool->flow_hit_aso_obj = obj;
11402 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
11403 rte_spinlock_lock(&mng->resize_sl);
11404 pool->index = mng->next;
11405 /* Resize pools array if there is no room for the new pool in it. */
11406 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
11407 claim_zero(mlx5_devx_cmd_destroy(obj));
11409 rte_spinlock_unlock(&mng->resize_sl);
11412 mng->pools[pool->index] = pool;
11414 rte_spinlock_unlock(&mng->resize_sl);
11415 /* Assign the first action in the new pool, the rest go to free list. */
11416 *age_free = &pool->actions[0];
11417 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
11418 pool->actions[i].offset = i;
11419 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
11425 * Allocate a ASO aging bit.
11428 * Pointer to the Ethernet device structure.
11429 * @param[out] error
11430 * Pointer to the error structure.
11433 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
11436 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
11438 struct mlx5_priv *priv = dev->data->dev_private;
11439 const struct mlx5_aso_age_pool *pool;
11440 struct mlx5_aso_age_action *age_free = NULL;
11441 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11444 /* Try to get the next free age action bit. */
11445 rte_spinlock_lock(&mng->free_sl);
11446 age_free = LIST_FIRST(&mng->free);
11448 LIST_REMOVE(age_free, next);
11449 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
11450 rte_spinlock_unlock(&mng->free_sl);
11451 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
11452 NULL, "failed to create ASO age pool");
11453 return 0; /* 0 is an error. */
11455 rte_spinlock_unlock(&mng->free_sl);
11456 pool = container_of
11457 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
11458 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
11460 if (!age_free->dr_action) {
11461 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
11465 rte_flow_error_set(error, rte_errno,
11466 RTE_FLOW_ERROR_TYPE_ACTION,
11467 NULL, "failed to get reg_c "
11468 "for ASO flow hit");
11469 return 0; /* 0 is an error. */
11471 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
11472 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
11473 (priv->sh->rx_domain,
11474 pool->flow_hit_aso_obj->obj, age_free->offset,
11475 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
11476 (reg_c - REG_C_0));
11477 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
11478 if (!age_free->dr_action) {
11480 rte_spinlock_lock(&mng->free_sl);
11481 LIST_INSERT_HEAD(&mng->free, age_free, next);
11482 rte_spinlock_unlock(&mng->free_sl);
11483 rte_flow_error_set(error, rte_errno,
11484 RTE_FLOW_ERROR_TYPE_ACTION,
11485 NULL, "failed to create ASO "
11486 "flow hit action");
11487 return 0; /* 0 is an error. */
11490 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
11491 return pool->index | ((age_free->offset + 1) << 16);
11495 * Create a age action using ASO mechanism.
11498 * Pointer to rte_eth_dev structure.
11500 * Pointer to the aging action configuration.
11501 * @param[out] error
11502 * Pointer to the error structure.
11505 * Index to flow counter on success, 0 otherwise.
11508 flow_dv_translate_create_aso_age(struct rte_eth_dev *dev,
11509 const struct rte_flow_action_age *age,
11510 struct rte_flow_error *error)
11512 uint32_t age_idx = 0;
11513 struct mlx5_aso_age_action *aso_age;
11515 age_idx = flow_dv_aso_age_alloc(dev, error);
11518 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
11519 aso_age->age_params.context = age->context;
11520 aso_age->age_params.timeout = age->timeout;
11521 aso_age->age_params.port_id = dev->data->port_id;
11522 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
11524 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
11530 flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
11531 const struct rte_flow_item_integrity *value,
11532 void *headers_m, void *headers_v)
11535 /* application l4_ok filter aggregates all hardware l4 filters
11536 * therefore hw l4_checksum_ok must be implicitly added here.
11538 struct rte_flow_item_integrity local_item;
11540 local_item.l4_csum_ok = 1;
11541 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
11542 local_item.l4_csum_ok);
11543 if (value->l4_ok) {
11544 /* application l4_ok = 1 matches sets both hw flags
11545 * l4_ok and l4_checksum_ok flags to 1.
11547 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11548 l4_checksum_ok, local_item.l4_csum_ok);
11549 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_ok,
11551 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_ok,
11554 /* application l4_ok = 0 matches on hw flag
11555 * l4_checksum_ok = 0 only.
11557 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11558 l4_checksum_ok, 0);
11560 } else if (mask->l4_csum_ok) {
11561 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
11563 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
11564 value->l4_csum_ok);
11569 flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
11570 const struct rte_flow_item_integrity *value,
11571 void *headers_m, void *headers_v,
11575 /* application l3_ok filter aggregates all hardware l3 filters
11576 * therefore hw ipv4_checksum_ok must be implicitly added here.
11578 struct rte_flow_item_integrity local_item;
11580 local_item.ipv4_csum_ok = !!is_ipv4;
11581 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
11582 local_item.ipv4_csum_ok);
11583 if (value->l3_ok) {
11584 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11585 ipv4_checksum_ok, local_item.ipv4_csum_ok);
11586 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l3_ok,
11588 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l3_ok,
11591 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11592 ipv4_checksum_ok, 0);
11594 } else if (mask->ipv4_csum_ok) {
11595 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
11596 mask->ipv4_csum_ok);
11597 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
11598 value->ipv4_csum_ok);
11603 flow_dv_translate_item_integrity(void *matcher, void *key,
11604 const struct rte_flow_item *head_item,
11605 const struct rte_flow_item *integrity_item)
11607 const struct rte_flow_item_integrity *mask = integrity_item->mask;
11608 const struct rte_flow_item_integrity *value = integrity_item->spec;
11609 const struct rte_flow_item *tunnel_item, *end_item, *item;
11612 uint32_t l3_protocol;
11617 mask = &rte_flow_item_integrity_mask;
11618 if (value->level > 1) {
11619 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
11621 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
11623 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
11625 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11627 tunnel_item = mlx5_flow_find_tunnel_item(head_item);
11628 if (value->level > 1) {
11629 /* tunnel item was verified during the item validation */
11630 item = tunnel_item;
11631 end_item = mlx5_find_end_item(tunnel_item);
11634 end_item = tunnel_item ? tunnel_item :
11635 mlx5_find_end_item(integrity_item);
11637 l3_protocol = mask->l3_ok ?
11638 mlx5_flow_locate_proto_l3(&item, end_item) : 0;
11639 flow_dv_translate_integrity_l3(mask, value, headers_m, headers_v,
11640 l3_protocol == RTE_ETHER_TYPE_IPV4);
11641 flow_dv_translate_integrity_l4(mask, value, headers_m, headers_v);
11645 * Prepares DV flow counter with aging configuration.
11646 * Gets it by index when exists, creates a new one when doesn't.
11649 * Pointer to rte_eth_dev structure.
11650 * @param[in] dev_flow
11651 * Pointer to the mlx5_flow.
11652 * @param[in, out] flow
11653 * Pointer to the sub flow.
11655 * Pointer to the counter action configuration.
11657 * Pointer to the aging action configuration.
11658 * @param[out] error
11659 * Pointer to the error structure.
11662 * Pointer to the counter, NULL otherwise.
11664 static struct mlx5_flow_counter *
11665 flow_dv_prepare_counter(struct rte_eth_dev *dev,
11666 struct mlx5_flow *dev_flow,
11667 struct rte_flow *flow,
11668 const struct rte_flow_action_count *count,
11669 const struct rte_flow_action_age *age,
11670 struct rte_flow_error *error)
11672 if (!flow->counter) {
11673 flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
11675 if (!flow->counter) {
11676 rte_flow_error_set(error, rte_errno,
11677 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11678 "cannot create counter object.");
11682 return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
11686 * Release an ASO CT action.
11689 * Pointer to the Ethernet device structure.
11691 * Index of ASO CT action to release.
11694 * 0 when CT action was removed, otherwise the number of references.
11697 flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t idx)
11699 struct mlx5_priv *priv = dev->data->dev_private;
11700 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11702 struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_idx(dev, idx);
11703 enum mlx5_aso_ct_state state =
11704 __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
11706 /* Cannot release when CT is in the ASO SQ. */
11707 if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
11709 ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
11711 if (ct->dr_action_orig) {
11712 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11713 claim_zero(mlx5_glue->destroy_flow_action
11714 (ct->dr_action_orig));
11716 ct->dr_action_orig = NULL;
11718 if (ct->dr_action_rply) {
11719 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11720 claim_zero(mlx5_glue->destroy_flow_action
11721 (ct->dr_action_rply));
11723 ct->dr_action_rply = NULL;
11725 /* Clear the state to free, no need in 1st allocation. */
11726 MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
11727 rte_spinlock_lock(&mng->ct_sl);
11728 LIST_INSERT_HEAD(&mng->free_cts, ct, next);
11729 rte_spinlock_unlock(&mng->ct_sl);
11735 * Resize the ASO CT pools array by 64 pools.
11738 * Pointer to the Ethernet device structure.
11741 * 0 on success, otherwise negative errno value and rte_errno is set.
11744 flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
11746 struct mlx5_priv *priv = dev->data->dev_private;
11747 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11748 void *old_pools = mng->pools;
11749 /* Magic number now, need a macro. */
11750 uint32_t resize = mng->n + 64;
11751 uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
11752 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11755 rte_errno = ENOMEM;
11758 rte_rwlock_write_lock(&mng->resize_rwl);
11759 /* ASO SQ/QP was already initialized in the startup. */
11761 /* Realloc could be an alternative choice. */
11762 rte_memcpy(pools, old_pools,
11763 mng->n * sizeof(struct mlx5_aso_ct_pool *));
11764 mlx5_free(old_pools);
11767 mng->pools = pools;
11768 rte_rwlock_write_unlock(&mng->resize_rwl);
11773 * Create and initialize a new ASO CT pool.
11776 * Pointer to the Ethernet device structure.
11777 * @param[out] ct_free
11778 * Where to put the pointer of a new CT action.
11781 * The CT actions pool pointer and @p ct_free is set on success,
11782 * NULL otherwise and rte_errno is set.
11784 static struct mlx5_aso_ct_pool *
11785 flow_dv_ct_pool_create(struct rte_eth_dev *dev,
11786 struct mlx5_aso_ct_action **ct_free)
11788 struct mlx5_priv *priv = dev->data->dev_private;
11789 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11790 struct mlx5_aso_ct_pool *pool = NULL;
11791 struct mlx5_devx_obj *obj = NULL;
11793 uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
11795 obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->ctx,
11796 priv->sh->pdn, log_obj_size);
11798 rte_errno = ENODATA;
11799 DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
11802 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
11804 rte_errno = ENOMEM;
11805 claim_zero(mlx5_devx_cmd_destroy(obj));
11808 pool->devx_obj = obj;
11809 pool->index = mng->next;
11810 /* Resize pools array if there is no room for the new pool in it. */
11811 if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
11812 claim_zero(mlx5_devx_cmd_destroy(obj));
11816 mng->pools[pool->index] = pool;
11818 /* Assign the first action in the new pool, the rest go to free list. */
11819 *ct_free = &pool->actions[0];
11820 /* Lock outside, the list operation is safe here. */
11821 for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
11822 /* refcnt is 0 when allocating the memory. */
11823 pool->actions[i].offset = i;
11824 LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
11830 * Allocate a ASO CT action from free list.
11833 * Pointer to the Ethernet device structure.
11834 * @param[out] error
11835 * Pointer to the error structure.
11838 * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
11841 flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
11843 struct mlx5_priv *priv = dev->data->dev_private;
11844 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11845 struct mlx5_aso_ct_action *ct = NULL;
11846 struct mlx5_aso_ct_pool *pool;
11851 if (!priv->config.devx) {
11852 rte_errno = ENOTSUP;
11855 /* Get a free CT action, if no, a new pool will be created. */
11856 rte_spinlock_lock(&mng->ct_sl);
11857 ct = LIST_FIRST(&mng->free_cts);
11859 LIST_REMOVE(ct, next);
11860 } else if (!flow_dv_ct_pool_create(dev, &ct)) {
11861 rte_spinlock_unlock(&mng->ct_sl);
11862 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
11863 NULL, "failed to create ASO CT pool");
11866 rte_spinlock_unlock(&mng->ct_sl);
11867 pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
11868 ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
11869 /* 0: inactive, 1: created, 2+: used by flows. */
11870 __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
11871 reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
11872 if (!ct->dr_action_orig) {
11873 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11874 ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
11875 (priv->sh->rx_domain, pool->devx_obj->obj,
11877 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
11880 RTE_SET_USED(reg_c);
11882 if (!ct->dr_action_orig) {
11883 flow_dv_aso_ct_release(dev, ct_idx);
11884 rte_flow_error_set(error, rte_errno,
11885 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11886 "failed to create ASO CT action");
11890 if (!ct->dr_action_rply) {
11891 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11892 ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
11893 (priv->sh->rx_domain, pool->devx_obj->obj,
11895 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
11898 if (!ct->dr_action_rply) {
11899 flow_dv_aso_ct_release(dev, ct_idx);
11900 rte_flow_error_set(error, rte_errno,
11901 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11902 "failed to create ASO CT action");
11910 * Create a conntrack object with context and actions by using ASO mechanism.
11913 * Pointer to rte_eth_dev structure.
11915 * Pointer to conntrack information profile.
11916 * @param[out] error
11917 * Pointer to the error structure.
11920 * Index to conntrack object on success, 0 otherwise.
11923 flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
11924 const struct rte_flow_action_conntrack *pro,
11925 struct rte_flow_error *error)
11927 struct mlx5_priv *priv = dev->data->dev_private;
11928 struct mlx5_dev_ctx_shared *sh = priv->sh;
11929 struct mlx5_aso_ct_action *ct;
11932 if (!sh->ct_aso_en)
11933 return rte_flow_error_set(error, ENOTSUP,
11934 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11935 "Connection is not supported");
11936 idx = flow_dv_aso_ct_alloc(dev, error);
11938 return rte_flow_error_set(error, rte_errno,
11939 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11940 "Failed to allocate CT object");
11941 ct = flow_aso_ct_get_by_idx(dev, idx);
11942 if (mlx5_aso_ct_update_by_wqe(sh, ct, pro))
11943 return rte_flow_error_set(error, EBUSY,
11944 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11945 "Failed to update CT");
11946 ct->is_original = !!pro->is_original_dir;
11951 * Fill the flow with DV spec, lock free
11952 * (mutex should be acquired by caller).
11955 * Pointer to rte_eth_dev structure.
11956 * @param[in, out] dev_flow
11957 * Pointer to the sub flow.
11959 * Pointer to the flow attributes.
11961 * Pointer to the list of items.
11962 * @param[in] actions
11963 * Pointer to the list of actions.
11964 * @param[out] error
11965 * Pointer to the error structure.
11968 * 0 on success, a negative errno value otherwise and rte_errno is set.
11971 flow_dv_translate(struct rte_eth_dev *dev,
11972 struct mlx5_flow *dev_flow,
11973 const struct rte_flow_attr *attr,
11974 const struct rte_flow_item items[],
11975 const struct rte_flow_action actions[],
11976 struct rte_flow_error *error)
11978 struct mlx5_priv *priv = dev->data->dev_private;
11979 struct mlx5_dev_config *dev_conf = &priv->config;
11980 struct rte_flow *flow = dev_flow->flow;
11981 struct mlx5_flow_handle *handle = dev_flow->handle;
11982 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11983 struct mlx5_flow_rss_desc *rss_desc;
11984 uint64_t item_flags = 0;
11985 uint64_t last_item = 0;
11986 uint64_t action_flags = 0;
11987 struct mlx5_flow_dv_matcher matcher = {
11989 .size = sizeof(matcher.mask.buf) -
11990 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
11994 bool actions_end = false;
11996 struct mlx5_flow_dv_modify_hdr_resource res;
11997 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
11998 sizeof(struct mlx5_modification_cmd) *
11999 (MLX5_MAX_MODIFY_NUM + 1)];
12001 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
12002 const struct rte_flow_action_count *count = NULL;
12003 const struct rte_flow_action_age *non_shared_age = NULL;
12004 union flow_dv_attr flow_attr = { .attr = 0 };
12006 union mlx5_flow_tbl_key tbl_key;
12007 uint32_t modify_action_position = UINT32_MAX;
12008 void *match_mask = matcher.mask.buf;
12009 void *match_value = dev_flow->dv.value.buf;
12010 uint8_t next_protocol = 0xff;
12011 struct rte_vlan_hdr vlan = { 0 };
12012 struct mlx5_flow_dv_dest_array_resource mdest_res;
12013 struct mlx5_flow_dv_sample_resource sample_res;
12014 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
12015 const struct rte_flow_action_sample *sample = NULL;
12016 struct mlx5_flow_sub_actions_list *sample_act;
12017 uint32_t sample_act_pos = UINT32_MAX;
12018 uint32_t age_act_pos = UINT32_MAX;
12019 uint32_t num_of_dest = 0;
12020 int tmp_actions_n = 0;
12023 const struct mlx5_flow_tunnel *tunnel;
12024 struct flow_grp_info grp_info = {
12025 .external = !!dev_flow->external,
12026 .transfer = !!attr->transfer,
12027 .fdb_def_rule = !!priv->fdb_def_rule,
12028 .skip_scale = dev_flow->skip_scale &
12029 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
12031 const struct rte_flow_item *head_item = items;
12034 return rte_flow_error_set(error, ENOMEM,
12035 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12037 "failed to push flow workspace");
12038 rss_desc = &wks->rss_desc;
12039 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
12040 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
12041 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12042 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12043 /* update normal path action resource into last index of array */
12044 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
12045 tunnel = is_flow_tunnel_match_rule(dev, attr, items, actions) ?
12046 flow_items_to_tunnel(items) :
12047 is_flow_tunnel_steer_rule(dev, attr, items, actions) ?
12048 flow_actions_to_tunnel(actions) :
12049 dev_flow->tunnel ? dev_flow->tunnel : NULL;
12050 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12051 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12052 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
12053 (dev, tunnel, attr, items, actions);
12054 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
12058 dev_flow->dv.group = table;
12059 if (attr->transfer)
12060 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12061 /* number of actions must be set to 0 in case of dirty stack. */
12062 mhdr_res->actions_num = 0;
12063 if (is_flow_tunnel_match_rule(dev, attr, items, actions)) {
12065 * do not add decap action if match rule drops packet
12066 * HW rejects rules with decap & drop
12068 * if tunnel match rule was inserted before matching tunnel set
12069 * rule flow table used in the match rule must be registered.
12070 * current implementation handles that in the
12071 * flow_dv_match_register() at the function end.
12073 bool add_decap = true;
12074 const struct rte_flow_action *ptr = actions;
12076 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
12077 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
12083 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12087 dev_flow->dv.actions[actions_n++] =
12088 dev_flow->dv.encap_decap->action;
12089 action_flags |= MLX5_FLOW_ACTION_DECAP;
12092 for (; !actions_end ; actions++) {
12093 const struct rte_flow_action_queue *queue;
12094 const struct rte_flow_action_rss *rss;
12095 const struct rte_flow_action *action = actions;
12096 const uint8_t *rss_key;
12097 struct mlx5_flow_tbl_resource *tbl;
12098 struct mlx5_aso_age_action *age_act;
12099 struct mlx5_flow_counter *cnt_act;
12100 uint32_t port_id = 0;
12101 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
12102 int action_type = actions->type;
12103 const struct rte_flow_action *found_action = NULL;
12104 uint32_t jump_group = 0;
12106 struct mlx5_aso_ct_action *ct;
12108 if (!mlx5_flow_os_action_supported(action_type))
12109 return rte_flow_error_set(error, ENOTSUP,
12110 RTE_FLOW_ERROR_TYPE_ACTION,
12112 "action not supported");
12113 switch (action_type) {
12114 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
12115 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
12117 case RTE_FLOW_ACTION_TYPE_VOID:
12119 case RTE_FLOW_ACTION_TYPE_PORT_ID:
12120 if (flow_dv_translate_action_port_id(dev, action,
12123 port_id_resource.port_id = port_id;
12124 MLX5_ASSERT(!handle->rix_port_id_action);
12125 if (flow_dv_port_id_action_resource_register
12126 (dev, &port_id_resource, dev_flow, error))
12128 dev_flow->dv.actions[actions_n++] =
12129 dev_flow->dv.port_id_action->action;
12130 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12131 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
12132 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12135 case RTE_FLOW_ACTION_TYPE_FLAG:
12136 action_flags |= MLX5_FLOW_ACTION_FLAG;
12137 dev_flow->handle->mark = 1;
12138 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12139 struct rte_flow_action_mark mark = {
12140 .id = MLX5_FLOW_MARK_DEFAULT,
12143 if (flow_dv_convert_action_mark(dev, &mark,
12147 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12150 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
12152 * Only one FLAG or MARK is supported per device flow
12153 * right now. So the pointer to the tag resource must be
12154 * zero before the register process.
12156 MLX5_ASSERT(!handle->dvh.rix_tag);
12157 if (flow_dv_tag_resource_register(dev, tag_be,
12160 MLX5_ASSERT(dev_flow->dv.tag_resource);
12161 dev_flow->dv.actions[actions_n++] =
12162 dev_flow->dv.tag_resource->action;
12164 case RTE_FLOW_ACTION_TYPE_MARK:
12165 action_flags |= MLX5_FLOW_ACTION_MARK;
12166 dev_flow->handle->mark = 1;
12167 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12168 const struct rte_flow_action_mark *mark =
12169 (const struct rte_flow_action_mark *)
12172 if (flow_dv_convert_action_mark(dev, mark,
12176 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12180 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
12181 /* Legacy (non-extensive) MARK action. */
12182 tag_be = mlx5_flow_mark_set
12183 (((const struct rte_flow_action_mark *)
12184 (actions->conf))->id);
12185 MLX5_ASSERT(!handle->dvh.rix_tag);
12186 if (flow_dv_tag_resource_register(dev, tag_be,
12189 MLX5_ASSERT(dev_flow->dv.tag_resource);
12190 dev_flow->dv.actions[actions_n++] =
12191 dev_flow->dv.tag_resource->action;
12193 case RTE_FLOW_ACTION_TYPE_SET_META:
12194 if (flow_dv_convert_action_set_meta
12195 (dev, mhdr_res, attr,
12196 (const struct rte_flow_action_set_meta *)
12197 actions->conf, error))
12199 action_flags |= MLX5_FLOW_ACTION_SET_META;
12201 case RTE_FLOW_ACTION_TYPE_SET_TAG:
12202 if (flow_dv_convert_action_set_tag
12204 (const struct rte_flow_action_set_tag *)
12205 actions->conf, error))
12207 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12209 case RTE_FLOW_ACTION_TYPE_DROP:
12210 action_flags |= MLX5_FLOW_ACTION_DROP;
12211 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
12213 case RTE_FLOW_ACTION_TYPE_QUEUE:
12214 queue = actions->conf;
12215 rss_desc->queue_num = 1;
12216 rss_desc->queue[0] = queue->index;
12217 action_flags |= MLX5_FLOW_ACTION_QUEUE;
12218 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
12219 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
12222 case RTE_FLOW_ACTION_TYPE_RSS:
12223 rss = actions->conf;
12224 memcpy(rss_desc->queue, rss->queue,
12225 rss->queue_num * sizeof(uint16_t));
12226 rss_desc->queue_num = rss->queue_num;
12227 /* NULL RSS key indicates default RSS key. */
12228 rss_key = !rss->key ? rss_hash_default_key : rss->key;
12229 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12231 * rss->level and rss.types should be set in advance
12232 * when expanding items for RSS.
12234 action_flags |= MLX5_FLOW_ACTION_RSS;
12235 dev_flow->handle->fate_action = rss_desc->shared_rss ?
12236 MLX5_FLOW_FATE_SHARED_RSS :
12237 MLX5_FLOW_FATE_QUEUE;
12239 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
12240 flow->age = (uint32_t)(uintptr_t)(action->conf);
12241 age_act = flow_aso_age_get_by_idx(dev, flow->age);
12242 __atomic_fetch_add(&age_act->refcnt, 1,
12244 age_act_pos = actions_n++;
12245 action_flags |= MLX5_FLOW_ACTION_AGE;
12247 case RTE_FLOW_ACTION_TYPE_AGE:
12248 non_shared_age = action->conf;
12249 age_act_pos = actions_n++;
12250 action_flags |= MLX5_FLOW_ACTION_AGE;
12252 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
12253 flow->counter = (uint32_t)(uintptr_t)(action->conf);
12254 cnt_act = flow_dv_counter_get_by_idx(dev, flow->counter,
12256 __atomic_fetch_add(&cnt_act->shared_info.refcnt, 1,
12258 /* Save information first, will apply later. */
12259 action_flags |= MLX5_FLOW_ACTION_COUNT;
12261 case RTE_FLOW_ACTION_TYPE_COUNT:
12262 if (!dev_conf->devx) {
12263 return rte_flow_error_set
12265 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12267 "count action not supported");
12269 /* Save information first, will apply later. */
12270 count = action->conf;
12271 action_flags |= MLX5_FLOW_ACTION_COUNT;
12273 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
12274 dev_flow->dv.actions[actions_n++] =
12275 priv->sh->pop_vlan_action;
12276 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
12278 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
12279 if (!(action_flags &
12280 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
12281 flow_dev_get_vlan_info_from_items(items, &vlan);
12282 vlan.eth_proto = rte_be_to_cpu_16
12283 ((((const struct rte_flow_action_of_push_vlan *)
12284 actions->conf)->ethertype));
12285 found_action = mlx5_flow_find_action
12287 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
12289 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12290 found_action = mlx5_flow_find_action
12292 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
12294 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12295 if (flow_dv_create_action_push_vlan
12296 (dev, attr, &vlan, dev_flow, error))
12298 dev_flow->dv.actions[actions_n++] =
12299 dev_flow->dv.push_vlan_res->action;
12300 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
12302 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
12303 /* of_vlan_push action handled this action */
12304 MLX5_ASSERT(action_flags &
12305 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
12307 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
12308 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
12310 flow_dev_get_vlan_info_from_items(items, &vlan);
12311 mlx5_update_vlan_vid_pcp(actions, &vlan);
12312 /* If no VLAN push - this is a modify header action */
12313 if (flow_dv_convert_action_modify_vlan_vid
12314 (mhdr_res, actions, error))
12316 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
12318 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
12319 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
12320 if (flow_dv_create_action_l2_encap(dev, actions,
12325 dev_flow->dv.actions[actions_n++] =
12326 dev_flow->dv.encap_decap->action;
12327 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12328 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12329 sample_act->action_flags |=
12330 MLX5_FLOW_ACTION_ENCAP;
12332 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
12333 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
12334 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12338 dev_flow->dv.actions[actions_n++] =
12339 dev_flow->dv.encap_decap->action;
12340 action_flags |= MLX5_FLOW_ACTION_DECAP;
12342 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
12343 /* Handle encap with preceding decap. */
12344 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
12345 if (flow_dv_create_action_raw_encap
12346 (dev, actions, dev_flow, attr, error))
12348 dev_flow->dv.actions[actions_n++] =
12349 dev_flow->dv.encap_decap->action;
12351 /* Handle encap without preceding decap. */
12352 if (flow_dv_create_action_l2_encap
12353 (dev, actions, dev_flow, attr->transfer,
12356 dev_flow->dv.actions[actions_n++] =
12357 dev_flow->dv.encap_decap->action;
12359 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12360 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12361 sample_act->action_flags |=
12362 MLX5_FLOW_ACTION_ENCAP;
12364 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
12365 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
12367 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
12368 if (flow_dv_create_action_l2_decap
12369 (dev, dev_flow, attr->transfer, error))
12371 dev_flow->dv.actions[actions_n++] =
12372 dev_flow->dv.encap_decap->action;
12374 /* If decap is followed by encap, handle it at encap. */
12375 action_flags |= MLX5_FLOW_ACTION_DECAP;
12377 case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
12378 dev_flow->dv.actions[actions_n++] =
12379 (void *)(uintptr_t)action->conf;
12380 action_flags |= MLX5_FLOW_ACTION_JUMP;
12382 case RTE_FLOW_ACTION_TYPE_JUMP:
12383 jump_group = ((const struct rte_flow_action_jump *)
12384 action->conf)->group;
12385 grp_info.std_tbl_fix = 0;
12386 if (dev_flow->skip_scale &
12387 (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
12388 grp_info.skip_scale = 1;
12390 grp_info.skip_scale = 0;
12391 ret = mlx5_flow_group_to_table(dev, tunnel,
12397 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
12399 !!dev_flow->external,
12400 tunnel, jump_group, 0,
12403 return rte_flow_error_set
12405 RTE_FLOW_ERROR_TYPE_ACTION,
12407 "cannot create jump action.");
12408 if (flow_dv_jump_tbl_resource_register
12409 (dev, tbl, dev_flow, error)) {
12410 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12411 return rte_flow_error_set
12413 RTE_FLOW_ERROR_TYPE_ACTION,
12415 "cannot create jump action.");
12417 dev_flow->dv.actions[actions_n++] =
12418 dev_flow->dv.jump->action;
12419 action_flags |= MLX5_FLOW_ACTION_JUMP;
12420 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
12421 sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
12424 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
12425 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
12426 if (flow_dv_convert_action_modify_mac
12427 (mhdr_res, actions, error))
12429 action_flags |= actions->type ==
12430 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
12431 MLX5_FLOW_ACTION_SET_MAC_SRC :
12432 MLX5_FLOW_ACTION_SET_MAC_DST;
12434 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
12435 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
12436 if (flow_dv_convert_action_modify_ipv4
12437 (mhdr_res, actions, error))
12439 action_flags |= actions->type ==
12440 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
12441 MLX5_FLOW_ACTION_SET_IPV4_SRC :
12442 MLX5_FLOW_ACTION_SET_IPV4_DST;
12444 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
12445 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
12446 if (flow_dv_convert_action_modify_ipv6
12447 (mhdr_res, actions, error))
12449 action_flags |= actions->type ==
12450 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
12451 MLX5_FLOW_ACTION_SET_IPV6_SRC :
12452 MLX5_FLOW_ACTION_SET_IPV6_DST;
12454 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
12455 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
12456 if (flow_dv_convert_action_modify_tp
12457 (mhdr_res, actions, items,
12458 &flow_attr, dev_flow, !!(action_flags &
12459 MLX5_FLOW_ACTION_DECAP), error))
12461 action_flags |= actions->type ==
12462 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
12463 MLX5_FLOW_ACTION_SET_TP_SRC :
12464 MLX5_FLOW_ACTION_SET_TP_DST;
12466 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
12467 if (flow_dv_convert_action_modify_dec_ttl
12468 (mhdr_res, items, &flow_attr, dev_flow,
12470 MLX5_FLOW_ACTION_DECAP), error))
12472 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
12474 case RTE_FLOW_ACTION_TYPE_SET_TTL:
12475 if (flow_dv_convert_action_modify_ttl
12476 (mhdr_res, actions, items, &flow_attr,
12477 dev_flow, !!(action_flags &
12478 MLX5_FLOW_ACTION_DECAP), error))
12480 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
12482 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
12483 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
12484 if (flow_dv_convert_action_modify_tcp_seq
12485 (mhdr_res, actions, error))
12487 action_flags |= actions->type ==
12488 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
12489 MLX5_FLOW_ACTION_INC_TCP_SEQ :
12490 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
12493 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
12494 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
12495 if (flow_dv_convert_action_modify_tcp_ack
12496 (mhdr_res, actions, error))
12498 action_flags |= actions->type ==
12499 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
12500 MLX5_FLOW_ACTION_INC_TCP_ACK :
12501 MLX5_FLOW_ACTION_DEC_TCP_ACK;
12503 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
12504 if (flow_dv_convert_action_set_reg
12505 (mhdr_res, actions, error))
12507 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12509 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
12510 if (flow_dv_convert_action_copy_mreg
12511 (dev, mhdr_res, actions, error))
12513 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12515 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
12516 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
12517 dev_flow->handle->fate_action =
12518 MLX5_FLOW_FATE_DEFAULT_MISS;
12520 case RTE_FLOW_ACTION_TYPE_METER:
12522 return rte_flow_error_set(error, rte_errno,
12523 RTE_FLOW_ERROR_TYPE_ACTION,
12524 NULL, "Failed to get meter in flow.");
12525 /* Set the meter action. */
12526 dev_flow->dv.actions[actions_n++] =
12527 wks->fm->meter_action;
12528 action_flags |= MLX5_FLOW_ACTION_METER;
12530 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
12531 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
12534 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
12536 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
12537 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
12540 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
12542 case RTE_FLOW_ACTION_TYPE_SAMPLE:
12543 sample_act_pos = actions_n;
12544 sample = (const struct rte_flow_action_sample *)
12547 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
12548 /* put encap action into group if work with port id */
12549 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
12550 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
12551 sample_act->action_flags |=
12552 MLX5_FLOW_ACTION_ENCAP;
12554 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
12555 if (flow_dv_convert_action_modify_field
12556 (dev, mhdr_res, actions, attr, error))
12558 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
12560 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
12561 ct_idx = (uint32_t)(uintptr_t)action->conf;
12562 ct = flow_aso_ct_get_by_idx(dev, ct_idx);
12563 if (mlx5_aso_ct_available(priv->sh, ct))
12564 return rte_flow_error_set(error, rte_errno,
12565 RTE_FLOW_ERROR_TYPE_ACTION,
12567 "CT is unavailable.");
12568 if (ct->is_original)
12569 dev_flow->dv.actions[actions_n] =
12570 ct->dr_action_orig;
12572 dev_flow->dv.actions[actions_n] =
12573 ct->dr_action_rply;
12574 flow->indirect_type = MLX5_INDIRECT_ACTION_TYPE_CT;
12576 __atomic_fetch_add(&ct->refcnt, 1, __ATOMIC_RELAXED);
12578 action_flags |= MLX5_FLOW_ACTION_CT;
12580 case RTE_FLOW_ACTION_TYPE_END:
12581 actions_end = true;
12582 if (mhdr_res->actions_num) {
12583 /* create modify action if needed. */
12584 if (flow_dv_modify_hdr_resource_register
12585 (dev, mhdr_res, dev_flow, error))
12587 dev_flow->dv.actions[modify_action_position] =
12588 handle->dvh.modify_hdr->action;
12591 * Handle AGE and COUNT action by single HW counter
12592 * when they are not shared.
12594 if (action_flags & MLX5_FLOW_ACTION_AGE) {
12595 if ((non_shared_age &&
12596 count && !count->shared) ||
12597 !(priv->sh->flow_hit_aso_en &&
12599 /* Creates age by counters. */
12600 cnt_act = flow_dv_prepare_counter
12607 dev_flow->dv.actions[age_act_pos] =
12611 if (!flow->age && non_shared_age) {
12613 flow_dv_translate_create_aso_age
12618 return rte_flow_error_set
12620 RTE_FLOW_ERROR_TYPE_ACTION,
12622 "can't create ASO age action");
12624 age_act = flow_aso_age_get_by_idx(dev,
12626 dev_flow->dv.actions[age_act_pos] =
12627 age_act->dr_action;
12629 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
12631 * Create one count action, to be used
12632 * by all sub-flows.
12634 cnt_act = flow_dv_prepare_counter(dev, dev_flow,
12639 dev_flow->dv.actions[actions_n++] =
12645 if (mhdr_res->actions_num &&
12646 modify_action_position == UINT32_MAX)
12647 modify_action_position = actions_n++;
12649 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
12650 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
12651 int item_type = items->type;
12653 if (!mlx5_flow_os_item_supported(item_type))
12654 return rte_flow_error_set(error, ENOTSUP,
12655 RTE_FLOW_ERROR_TYPE_ITEM,
12656 NULL, "item not supported");
12657 switch (item_type) {
12658 case RTE_FLOW_ITEM_TYPE_PORT_ID:
12659 flow_dv_translate_item_port_id
12660 (dev, match_mask, match_value, items, attr);
12661 last_item = MLX5_FLOW_ITEM_PORT_ID;
12663 case RTE_FLOW_ITEM_TYPE_ETH:
12664 flow_dv_translate_item_eth(match_mask, match_value,
12666 dev_flow->dv.group);
12667 matcher.priority = action_flags &
12668 MLX5_FLOW_ACTION_DEFAULT_MISS &&
12669 !dev_flow->external ?
12670 MLX5_PRIORITY_MAP_L3 :
12671 MLX5_PRIORITY_MAP_L2;
12672 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
12673 MLX5_FLOW_LAYER_OUTER_L2;
12675 case RTE_FLOW_ITEM_TYPE_VLAN:
12676 flow_dv_translate_item_vlan(dev_flow,
12677 match_mask, match_value,
12679 dev_flow->dv.group);
12680 matcher.priority = MLX5_PRIORITY_MAP_L2;
12681 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
12682 MLX5_FLOW_LAYER_INNER_VLAN) :
12683 (MLX5_FLOW_LAYER_OUTER_L2 |
12684 MLX5_FLOW_LAYER_OUTER_VLAN);
12686 case RTE_FLOW_ITEM_TYPE_IPV4:
12687 mlx5_flow_tunnel_ip_check(items, next_protocol,
12688 &item_flags, &tunnel);
12689 flow_dv_translate_item_ipv4(match_mask, match_value,
12691 dev_flow->dv.group);
12692 matcher.priority = MLX5_PRIORITY_MAP_L3;
12693 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
12694 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
12695 if (items->mask != NULL &&
12696 ((const struct rte_flow_item_ipv4 *)
12697 items->mask)->hdr.next_proto_id) {
12699 ((const struct rte_flow_item_ipv4 *)
12700 (items->spec))->hdr.next_proto_id;
12702 ((const struct rte_flow_item_ipv4 *)
12703 (items->mask))->hdr.next_proto_id;
12705 /* Reset for inner layer. */
12706 next_protocol = 0xff;
12709 case RTE_FLOW_ITEM_TYPE_IPV6:
12710 mlx5_flow_tunnel_ip_check(items, next_protocol,
12711 &item_flags, &tunnel);
12712 flow_dv_translate_item_ipv6(match_mask, match_value,
12714 dev_flow->dv.group);
12715 matcher.priority = MLX5_PRIORITY_MAP_L3;
12716 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
12717 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
12718 if (items->mask != NULL &&
12719 ((const struct rte_flow_item_ipv6 *)
12720 items->mask)->hdr.proto) {
12722 ((const struct rte_flow_item_ipv6 *)
12723 items->spec)->hdr.proto;
12725 ((const struct rte_flow_item_ipv6 *)
12726 items->mask)->hdr.proto;
12728 /* Reset for inner layer. */
12729 next_protocol = 0xff;
12732 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
12733 flow_dv_translate_item_ipv6_frag_ext(match_mask,
12736 last_item = tunnel ?
12737 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
12738 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
12739 if (items->mask != NULL &&
12740 ((const struct rte_flow_item_ipv6_frag_ext *)
12741 items->mask)->hdr.next_header) {
12743 ((const struct rte_flow_item_ipv6_frag_ext *)
12744 items->spec)->hdr.next_header;
12746 ((const struct rte_flow_item_ipv6_frag_ext *)
12747 items->mask)->hdr.next_header;
12749 /* Reset for inner layer. */
12750 next_protocol = 0xff;
12753 case RTE_FLOW_ITEM_TYPE_TCP:
12754 flow_dv_translate_item_tcp(match_mask, match_value,
12756 matcher.priority = MLX5_PRIORITY_MAP_L4;
12757 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
12758 MLX5_FLOW_LAYER_OUTER_L4_TCP;
12760 case RTE_FLOW_ITEM_TYPE_UDP:
12761 flow_dv_translate_item_udp(match_mask, match_value,
12763 matcher.priority = MLX5_PRIORITY_MAP_L4;
12764 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
12765 MLX5_FLOW_LAYER_OUTER_L4_UDP;
12767 case RTE_FLOW_ITEM_TYPE_GRE:
12768 flow_dv_translate_item_gre(match_mask, match_value,
12770 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12771 last_item = MLX5_FLOW_LAYER_GRE;
12773 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
12774 flow_dv_translate_item_gre_key(match_mask,
12775 match_value, items);
12776 last_item = MLX5_FLOW_LAYER_GRE_KEY;
12778 case RTE_FLOW_ITEM_TYPE_NVGRE:
12779 flow_dv_translate_item_nvgre(match_mask, match_value,
12781 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12782 last_item = MLX5_FLOW_LAYER_GRE;
12784 case RTE_FLOW_ITEM_TYPE_VXLAN:
12785 flow_dv_translate_item_vxlan(match_mask, match_value,
12787 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12788 last_item = MLX5_FLOW_LAYER_VXLAN;
12790 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
12791 flow_dv_translate_item_vxlan_gpe(match_mask,
12792 match_value, items,
12794 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12795 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
12797 case RTE_FLOW_ITEM_TYPE_GENEVE:
12798 flow_dv_translate_item_geneve(match_mask, match_value,
12800 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12801 last_item = MLX5_FLOW_LAYER_GENEVE;
12803 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
12804 ret = flow_dv_translate_item_geneve_opt(dev, match_mask,
12808 return rte_flow_error_set(error, -ret,
12809 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
12810 "cannot create GENEVE TLV option");
12811 flow->geneve_tlv_option = 1;
12812 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
12814 case RTE_FLOW_ITEM_TYPE_MPLS:
12815 flow_dv_translate_item_mpls(match_mask, match_value,
12816 items, last_item, tunnel);
12817 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12818 last_item = MLX5_FLOW_LAYER_MPLS;
12820 case RTE_FLOW_ITEM_TYPE_MARK:
12821 flow_dv_translate_item_mark(dev, match_mask,
12822 match_value, items);
12823 last_item = MLX5_FLOW_ITEM_MARK;
12825 case RTE_FLOW_ITEM_TYPE_META:
12826 flow_dv_translate_item_meta(dev, match_mask,
12827 match_value, attr, items);
12828 last_item = MLX5_FLOW_ITEM_METADATA;
12830 case RTE_FLOW_ITEM_TYPE_ICMP:
12831 flow_dv_translate_item_icmp(match_mask, match_value,
12833 last_item = MLX5_FLOW_LAYER_ICMP;
12835 case RTE_FLOW_ITEM_TYPE_ICMP6:
12836 flow_dv_translate_item_icmp6(match_mask, match_value,
12838 last_item = MLX5_FLOW_LAYER_ICMP6;
12840 case RTE_FLOW_ITEM_TYPE_TAG:
12841 flow_dv_translate_item_tag(dev, match_mask,
12842 match_value, items);
12843 last_item = MLX5_FLOW_ITEM_TAG;
12845 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
12846 flow_dv_translate_mlx5_item_tag(dev, match_mask,
12847 match_value, items);
12848 last_item = MLX5_FLOW_ITEM_TAG;
12850 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
12851 flow_dv_translate_item_tx_queue(dev, match_mask,
12854 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
12856 case RTE_FLOW_ITEM_TYPE_GTP:
12857 flow_dv_translate_item_gtp(match_mask, match_value,
12859 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12860 last_item = MLX5_FLOW_LAYER_GTP;
12862 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
12863 ret = flow_dv_translate_item_gtp_psc(match_mask,
12867 return rte_flow_error_set(error, -ret,
12868 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
12869 "cannot create GTP PSC item");
12870 last_item = MLX5_FLOW_LAYER_GTP_PSC;
12872 case RTE_FLOW_ITEM_TYPE_ECPRI:
12873 if (!mlx5_flex_parser_ecpri_exist(dev)) {
12874 /* Create it only the first time to be used. */
12875 ret = mlx5_flex_parser_ecpri_alloc(dev);
12877 return rte_flow_error_set
12879 RTE_FLOW_ERROR_TYPE_ITEM,
12881 "cannot create eCPRI parser");
12883 /* Adjust the length matcher and device flow value. */
12884 matcher.mask.size = MLX5_ST_SZ_BYTES(fte_match_param);
12885 dev_flow->dv.value.size =
12886 MLX5_ST_SZ_BYTES(fte_match_param);
12887 flow_dv_translate_item_ecpri(dev, match_mask,
12888 match_value, items);
12889 /* No other protocol should follow eCPRI layer. */
12890 last_item = MLX5_FLOW_LAYER_ECPRI;
12892 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
12893 flow_dv_translate_item_integrity(match_mask,
12897 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
12898 flow_dv_translate_item_aso_ct(dev, match_mask,
12899 match_value, items);
12904 item_flags |= last_item;
12907 * When E-Switch mode is enabled, we have two cases where we need to
12908 * set the source port manually.
12909 * The first one, is in case of Nic steering rule, and the second is
12910 * E-Switch rule where no port_id item was found. In both cases
12911 * the source port is set according the current port in use.
12913 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
12914 (priv->representor || priv->master)) {
12915 if (flow_dv_translate_item_port_id(dev, match_mask,
12916 match_value, NULL, attr))
12919 #ifdef RTE_LIBRTE_MLX5_DEBUG
12920 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
12921 dev_flow->dv.value.buf));
12924 * Layers may be already initialized from prefix flow if this dev_flow
12925 * is the suffix flow.
12927 handle->layers |= item_flags;
12928 if (action_flags & MLX5_FLOW_ACTION_RSS)
12929 flow_dv_hashfields_set(dev_flow, rss_desc);
12930 /* If has RSS action in the sample action, the Sample/Mirror resource
12931 * should be registered after the hash filed be update.
12933 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
12934 ret = flow_dv_translate_action_sample(dev,
12943 ret = flow_dv_create_action_sample(dev,
12952 return rte_flow_error_set
12954 RTE_FLOW_ERROR_TYPE_ACTION,
12956 "cannot create sample action");
12957 if (num_of_dest > 1) {
12958 dev_flow->dv.actions[sample_act_pos] =
12959 dev_flow->dv.dest_array_res->action;
12961 dev_flow->dv.actions[sample_act_pos] =
12962 dev_flow->dv.sample_res->verbs_action;
12966 * For multiple destination (sample action with ratio=1), the encap
12967 * action and port id action will be combined into group action.
12968 * So need remove the original these actions in the flow and only
12969 * use the sample action instead of.
12971 if (num_of_dest > 1 &&
12972 (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
12974 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
12976 for (i = 0; i < actions_n; i++) {
12977 if ((sample_act->dr_encap_action &&
12978 sample_act->dr_encap_action ==
12979 dev_flow->dv.actions[i]) ||
12980 (sample_act->dr_port_id_action &&
12981 sample_act->dr_port_id_action ==
12982 dev_flow->dv.actions[i]) ||
12983 (sample_act->dr_jump_action &&
12984 sample_act->dr_jump_action ==
12985 dev_flow->dv.actions[i]))
12987 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
12989 memcpy((void *)dev_flow->dv.actions,
12990 (void *)temp_actions,
12991 tmp_actions_n * sizeof(void *));
12992 actions_n = tmp_actions_n;
12994 dev_flow->dv.actions_n = actions_n;
12995 dev_flow->act_flags = action_flags;
12996 if (wks->skip_matcher_reg)
12998 /* Register matcher. */
12999 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
13000 matcher.mask.size);
13001 matcher.priority = mlx5_get_matcher_priority(dev, attr,
13003 /* reserved field no needs to be set to 0 here. */
13004 tbl_key.is_fdb = attr->transfer;
13005 tbl_key.is_egress = attr->egress;
13006 tbl_key.level = dev_flow->dv.group;
13007 tbl_key.id = dev_flow->dv.table_id;
13008 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
13009 tunnel, attr->group, error))
13015 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13018 * @param[in, out] action
13019 * Shred RSS action holding hash RX queue objects.
13020 * @param[in] hash_fields
13021 * Defines combination of packet fields to participate in RX hash.
13022 * @param[in] tunnel
13024 * @param[in] hrxq_idx
13025 * Hash RX queue index to set.
13028 * 0 on success, otherwise negative errno value.
13031 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
13032 const uint64_t hash_fields,
13035 uint32_t *hrxqs = action->hrxq;
13037 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13038 case MLX5_RSS_HASH_IPV4:
13039 /* fall-through. */
13040 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13041 /* fall-through. */
13042 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13043 hrxqs[0] = hrxq_idx;
13045 case MLX5_RSS_HASH_IPV4_TCP:
13046 /* fall-through. */
13047 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13048 /* fall-through. */
13049 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13050 hrxqs[1] = hrxq_idx;
13052 case MLX5_RSS_HASH_IPV4_UDP:
13053 /* fall-through. */
13054 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13055 /* fall-through. */
13056 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13057 hrxqs[2] = hrxq_idx;
13059 case MLX5_RSS_HASH_IPV6:
13060 /* fall-through. */
13061 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13062 /* fall-through. */
13063 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13064 hrxqs[3] = hrxq_idx;
13066 case MLX5_RSS_HASH_IPV6_TCP:
13067 /* fall-through. */
13068 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13069 /* fall-through. */
13070 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13071 hrxqs[4] = hrxq_idx;
13073 case MLX5_RSS_HASH_IPV6_UDP:
13074 /* fall-through. */
13075 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13076 /* fall-through. */
13077 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13078 hrxqs[5] = hrxq_idx;
13080 case MLX5_RSS_HASH_NONE:
13081 hrxqs[6] = hrxq_idx;
13089 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13093 * Pointer to the Ethernet device structure.
13095 * Shared RSS action ID holding hash RX queue objects.
13096 * @param[in] hash_fields
13097 * Defines combination of packet fields to participate in RX hash.
13098 * @param[in] tunnel
13102 * Valid hash RX queue index, otherwise 0.
13105 __flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
13106 const uint64_t hash_fields)
13108 struct mlx5_priv *priv = dev->data->dev_private;
13109 struct mlx5_shared_action_rss *shared_rss =
13110 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
13111 const uint32_t *hrxqs = shared_rss->hrxq;
13113 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13114 case MLX5_RSS_HASH_IPV4:
13115 /* fall-through. */
13116 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13117 /* fall-through. */
13118 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13120 case MLX5_RSS_HASH_IPV4_TCP:
13121 /* fall-through. */
13122 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13123 /* fall-through. */
13124 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13126 case MLX5_RSS_HASH_IPV4_UDP:
13127 /* fall-through. */
13128 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13129 /* fall-through. */
13130 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13132 case MLX5_RSS_HASH_IPV6:
13133 /* fall-through. */
13134 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13135 /* fall-through. */
13136 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13138 case MLX5_RSS_HASH_IPV6_TCP:
13139 /* fall-through. */
13140 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13141 /* fall-through. */
13142 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13144 case MLX5_RSS_HASH_IPV6_UDP:
13145 /* fall-through. */
13146 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13147 /* fall-through. */
13148 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13150 case MLX5_RSS_HASH_NONE:
13159 * Apply the flow to the NIC, lock free,
13160 * (mutex should be acquired by caller).
13163 * Pointer to the Ethernet device structure.
13164 * @param[in, out] flow
13165 * Pointer to flow structure.
13166 * @param[out] error
13167 * Pointer to error structure.
13170 * 0 on success, a negative errno value otherwise and rte_errno is set.
13173 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
13174 struct rte_flow_error *error)
13176 struct mlx5_flow_dv_workspace *dv;
13177 struct mlx5_flow_handle *dh;
13178 struct mlx5_flow_handle_dv *dv_h;
13179 struct mlx5_flow *dev_flow;
13180 struct mlx5_priv *priv = dev->data->dev_private;
13181 uint32_t handle_idx;
13185 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13186 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
13189 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
13190 dev_flow = &wks->flows[idx];
13191 dv = &dev_flow->dv;
13192 dh = dev_flow->handle;
13195 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
13196 if (dv->transfer) {
13197 MLX5_ASSERT(priv->sh->dr_drop_action);
13198 dv->actions[n++] = priv->sh->dr_drop_action;
13200 #ifdef HAVE_MLX5DV_DR
13201 /* DR supports drop action placeholder. */
13202 MLX5_ASSERT(priv->sh->dr_drop_action);
13203 dv->actions[n++] = priv->sh->dr_drop_action;
13205 /* For DV we use the explicit drop queue. */
13206 MLX5_ASSERT(priv->drop_queue.hrxq);
13208 priv->drop_queue.hrxq->action;
13211 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
13212 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
13213 struct mlx5_hrxq *hrxq;
13216 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
13221 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13222 "cannot get hash queue");
13225 dh->rix_hrxq = hrxq_idx;
13226 dv->actions[n++] = hrxq->action;
13227 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13228 struct mlx5_hrxq *hrxq = NULL;
13231 hrxq_idx = __flow_dv_action_rss_hrxq_lookup(dev,
13232 rss_desc->shared_rss,
13233 dev_flow->hash_fields);
13235 hrxq = mlx5_ipool_get
13236 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
13241 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13242 "cannot get hash queue");
13245 dh->rix_srss = rss_desc->shared_rss;
13246 dv->actions[n++] = hrxq->action;
13247 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
13248 if (!priv->sh->default_miss_action) {
13251 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13252 "default miss action not be created.");
13255 dv->actions[n++] = priv->sh->default_miss_action;
13257 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
13258 (void *)&dv->value, n,
13259 dv->actions, &dh->drv_flow);
13261 rte_flow_error_set(error, errno,
13262 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13264 "hardware refuses to create flow");
13267 if (priv->vmwa_context &&
13268 dh->vf_vlan.tag && !dh->vf_vlan.created) {
13270 * The rule contains the VLAN pattern.
13271 * For VF we are going to create VLAN
13272 * interface to make hypervisor set correct
13273 * e-Switch vport context.
13275 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
13280 err = rte_errno; /* Save rte_errno before cleanup. */
13281 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
13282 handle_idx, dh, next) {
13283 /* hrxq is union, don't clear it if the flag is not set. */
13284 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
13285 mlx5_hrxq_release(dev, dh->rix_hrxq);
13287 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13290 if (dh->vf_vlan.tag && dh->vf_vlan.created)
13291 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
13293 rte_errno = err; /* Restore rte_errno. */
13298 flow_dv_matcher_remove_cb(struct mlx5_cache_list *list __rte_unused,
13299 struct mlx5_cache_entry *entry)
13301 struct mlx5_flow_dv_matcher *cache = container_of(entry, typeof(*cache),
13304 claim_zero(mlx5_flow_os_destroy_flow_matcher(cache->matcher_object));
13309 * Release the flow matcher.
13312 * Pointer to Ethernet device.
13314 * Index to port ID action resource.
13317 * 1 while a reference on it exists, 0 when freed.
13320 flow_dv_matcher_release(struct rte_eth_dev *dev,
13321 struct mlx5_flow_handle *handle)
13323 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
13324 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
13325 typeof(*tbl), tbl);
13328 MLX5_ASSERT(matcher->matcher_object);
13329 ret = mlx5_cache_unregister(&tbl->matchers, &matcher->entry);
13330 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
13335 * Release encap_decap resource.
13338 * Pointer to the hash list.
13340 * Pointer to exist resource entry object.
13343 flow_dv_encap_decap_remove_cb(struct mlx5_hlist *list,
13344 struct mlx5_hlist_entry *entry)
13346 struct mlx5_dev_ctx_shared *sh = list->ctx;
13347 struct mlx5_flow_dv_encap_decap_resource *res =
13348 container_of(entry, typeof(*res), entry);
13350 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13351 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
13355 * Release an encap/decap resource.
13358 * Pointer to Ethernet device.
13359 * @param encap_decap_idx
13360 * Index of encap decap resource.
13363 * 1 while a reference on it exists, 0 when freed.
13366 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
13367 uint32_t encap_decap_idx)
13369 struct mlx5_priv *priv = dev->data->dev_private;
13370 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
13372 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
13374 if (!cache_resource)
13376 MLX5_ASSERT(cache_resource->action);
13377 return mlx5_hlist_unregister(priv->sh->encaps_decaps,
13378 &cache_resource->entry);
13382 * Release an jump to table action resource.
13385 * Pointer to Ethernet device.
13387 * Index to the jump action resource.
13390 * 1 while a reference on it exists, 0 when freed.
13393 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
13396 struct mlx5_priv *priv = dev->data->dev_private;
13397 struct mlx5_flow_tbl_data_entry *tbl_data;
13399 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
13403 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
13407 flow_dv_modify_remove_cb(struct mlx5_hlist *list __rte_unused,
13408 struct mlx5_hlist_entry *entry)
13410 struct mlx5_flow_dv_modify_hdr_resource *res =
13411 container_of(entry, typeof(*res), entry);
13413 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13418 * Release a modify-header resource.
13421 * Pointer to Ethernet device.
13423 * Pointer to mlx5_flow_handle.
13426 * 1 while a reference on it exists, 0 when freed.
13429 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
13430 struct mlx5_flow_handle *handle)
13432 struct mlx5_priv *priv = dev->data->dev_private;
13433 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
13435 MLX5_ASSERT(entry->action);
13436 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
13440 flow_dv_port_id_remove_cb(struct mlx5_cache_list *list,
13441 struct mlx5_cache_entry *entry)
13443 struct mlx5_dev_ctx_shared *sh = list->ctx;
13444 struct mlx5_flow_dv_port_id_action_resource *cache =
13445 container_of(entry, typeof(*cache), entry);
13447 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
13448 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], cache->idx);
13452 * Release port ID action resource.
13455 * Pointer to Ethernet device.
13457 * Pointer to mlx5_flow_handle.
13460 * 1 while a reference on it exists, 0 when freed.
13463 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
13466 struct mlx5_priv *priv = dev->data->dev_private;
13467 struct mlx5_flow_dv_port_id_action_resource *cache;
13469 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
13472 MLX5_ASSERT(cache->action);
13473 return mlx5_cache_unregister(&priv->sh->port_id_action_list,
13478 * Release shared RSS action resource.
13481 * Pointer to Ethernet device.
13483 * Shared RSS action index.
13486 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
13488 struct mlx5_priv *priv = dev->data->dev_private;
13489 struct mlx5_shared_action_rss *shared_rss;
13491 shared_rss = mlx5_ipool_get
13492 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
13493 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
13497 flow_dv_push_vlan_remove_cb(struct mlx5_cache_list *list,
13498 struct mlx5_cache_entry *entry)
13500 struct mlx5_dev_ctx_shared *sh = list->ctx;
13501 struct mlx5_flow_dv_push_vlan_action_resource *cache =
13502 container_of(entry, typeof(*cache), entry);
13504 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
13505 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], cache->idx);
13509 * Release push vlan action resource.
13512 * Pointer to Ethernet device.
13514 * Pointer to mlx5_flow_handle.
13517 * 1 while a reference on it exists, 0 when freed.
13520 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
13521 struct mlx5_flow_handle *handle)
13523 struct mlx5_priv *priv = dev->data->dev_private;
13524 struct mlx5_flow_dv_push_vlan_action_resource *cache;
13525 uint32_t idx = handle->dvh.rix_push_vlan;
13527 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
13530 MLX5_ASSERT(cache->action);
13531 return mlx5_cache_unregister(&priv->sh->push_vlan_action_list,
13536 * Release the fate resource.
13539 * Pointer to Ethernet device.
13541 * Pointer to mlx5_flow_handle.
13544 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
13545 struct mlx5_flow_handle *handle)
13547 if (!handle->rix_fate)
13549 switch (handle->fate_action) {
13550 case MLX5_FLOW_FATE_QUEUE:
13551 if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
13552 mlx5_hrxq_release(dev, handle->rix_hrxq);
13554 case MLX5_FLOW_FATE_JUMP:
13555 flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
13557 case MLX5_FLOW_FATE_PORT_ID:
13558 flow_dv_port_id_action_resource_release(dev,
13559 handle->rix_port_id_action);
13562 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
13565 handle->rix_fate = 0;
13569 flow_dv_sample_remove_cb(struct mlx5_cache_list *list __rte_unused,
13570 struct mlx5_cache_entry *entry)
13572 struct mlx5_flow_dv_sample_resource *cache_resource =
13573 container_of(entry, typeof(*cache_resource), entry);
13574 struct rte_eth_dev *dev = cache_resource->dev;
13575 struct mlx5_priv *priv = dev->data->dev_private;
13577 if (cache_resource->verbs_action)
13578 claim_zero(mlx5_flow_os_destroy_flow_action
13579 (cache_resource->verbs_action));
13580 if (cache_resource->normal_path_tbl)
13581 flow_dv_tbl_resource_release(MLX5_SH(dev),
13582 cache_resource->normal_path_tbl);
13583 flow_dv_sample_sub_actions_release(dev,
13584 &cache_resource->sample_idx);
13585 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
13586 cache_resource->idx);
13587 DRV_LOG(DEBUG, "sample resource %p: removed",
13588 (void *)cache_resource);
13592 * Release an sample resource.
13595 * Pointer to Ethernet device.
13597 * Pointer to mlx5_flow_handle.
13600 * 1 while a reference on it exists, 0 when freed.
13603 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
13604 struct mlx5_flow_handle *handle)
13606 struct mlx5_priv *priv = dev->data->dev_private;
13607 struct mlx5_flow_dv_sample_resource *cache_resource;
13609 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
13610 handle->dvh.rix_sample);
13611 if (!cache_resource)
13613 MLX5_ASSERT(cache_resource->verbs_action);
13614 return mlx5_cache_unregister(&priv->sh->sample_action_list,
13615 &cache_resource->entry);
13619 flow_dv_dest_array_remove_cb(struct mlx5_cache_list *list __rte_unused,
13620 struct mlx5_cache_entry *entry)
13622 struct mlx5_flow_dv_dest_array_resource *cache_resource =
13623 container_of(entry, typeof(*cache_resource), entry);
13624 struct rte_eth_dev *dev = cache_resource->dev;
13625 struct mlx5_priv *priv = dev->data->dev_private;
13628 MLX5_ASSERT(cache_resource->action);
13629 if (cache_resource->action)
13630 claim_zero(mlx5_flow_os_destroy_flow_action
13631 (cache_resource->action));
13632 for (; i < cache_resource->num_of_dest; i++)
13633 flow_dv_sample_sub_actions_release(dev,
13634 &cache_resource->sample_idx[i]);
13635 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
13636 cache_resource->idx);
13637 DRV_LOG(DEBUG, "destination array resource %p: removed",
13638 (void *)cache_resource);
13642 * Release an destination array resource.
13645 * Pointer to Ethernet device.
13647 * Pointer to mlx5_flow_handle.
13650 * 1 while a reference on it exists, 0 when freed.
13653 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
13654 struct mlx5_flow_handle *handle)
13656 struct mlx5_priv *priv = dev->data->dev_private;
13657 struct mlx5_flow_dv_dest_array_resource *cache;
13659 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
13660 handle->dvh.rix_dest_array);
13663 MLX5_ASSERT(cache->action);
13664 return mlx5_cache_unregister(&priv->sh->dest_array_list,
13669 flow_dv_geneve_tlv_option_resource_release(struct rte_eth_dev *dev)
13671 struct mlx5_priv *priv = dev->data->dev_private;
13672 struct mlx5_dev_ctx_shared *sh = priv->sh;
13673 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
13674 sh->geneve_tlv_option_resource;
13675 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
13676 if (geneve_opt_resource) {
13677 if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
13678 __ATOMIC_RELAXED))) {
13679 claim_zero(mlx5_devx_cmd_destroy
13680 (geneve_opt_resource->obj));
13681 mlx5_free(sh->geneve_tlv_option_resource);
13682 sh->geneve_tlv_option_resource = NULL;
13685 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
13689 * Remove the flow from the NIC but keeps it in memory.
13690 * Lock free, (mutex should be acquired by caller).
13693 * Pointer to Ethernet device.
13694 * @param[in, out] flow
13695 * Pointer to flow structure.
13698 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
13700 struct mlx5_flow_handle *dh;
13701 uint32_t handle_idx;
13702 struct mlx5_priv *priv = dev->data->dev_private;
13706 handle_idx = flow->dev_handles;
13707 while (handle_idx) {
13708 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
13712 if (dh->drv_flow) {
13713 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
13714 dh->drv_flow = NULL;
13716 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
13717 flow_dv_fate_resource_release(dev, dh);
13718 if (dh->vf_vlan.tag && dh->vf_vlan.created)
13719 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
13720 handle_idx = dh->next.next;
13725 * Remove the flow from the NIC and the memory.
13726 * Lock free, (mutex should be acquired by caller).
13729 * Pointer to the Ethernet device structure.
13730 * @param[in, out] flow
13731 * Pointer to flow structure.
13734 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
13736 struct mlx5_flow_handle *dev_handle;
13737 struct mlx5_priv *priv = dev->data->dev_private;
13738 struct mlx5_flow_meter_info *fm = NULL;
13743 flow_dv_remove(dev, flow);
13744 if (flow->counter) {
13745 flow_dv_counter_free(dev, flow->counter);
13749 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
13751 mlx5_flow_meter_detach(priv, fm);
13754 /* Keep the current age handling by default. */
13755 if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
13756 flow_dv_aso_ct_release(dev, flow->ct);
13757 else if (flow->age)
13758 flow_dv_aso_age_release(dev, flow->age);
13759 if (flow->geneve_tlv_option) {
13760 flow_dv_geneve_tlv_option_resource_release(dev);
13761 flow->geneve_tlv_option = 0;
13763 while (flow->dev_handles) {
13764 uint32_t tmp_idx = flow->dev_handles;
13766 dev_handle = mlx5_ipool_get(priv->sh->ipool
13767 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
13770 flow->dev_handles = dev_handle->next.next;
13771 if (dev_handle->dvh.matcher)
13772 flow_dv_matcher_release(dev, dev_handle);
13773 if (dev_handle->dvh.rix_sample)
13774 flow_dv_sample_resource_release(dev, dev_handle);
13775 if (dev_handle->dvh.rix_dest_array)
13776 flow_dv_dest_array_resource_release(dev, dev_handle);
13777 if (dev_handle->dvh.rix_encap_decap)
13778 flow_dv_encap_decap_resource_release(dev,
13779 dev_handle->dvh.rix_encap_decap);
13780 if (dev_handle->dvh.modify_hdr)
13781 flow_dv_modify_hdr_resource_release(dev, dev_handle);
13782 if (dev_handle->dvh.rix_push_vlan)
13783 flow_dv_push_vlan_action_resource_release(dev,
13785 if (dev_handle->dvh.rix_tag)
13786 flow_dv_tag_release(dev,
13787 dev_handle->dvh.rix_tag);
13788 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
13789 flow_dv_fate_resource_release(dev, dev_handle);
13791 srss = dev_handle->rix_srss;
13792 if (fm && dev_handle->is_meter_flow_id &&
13793 dev_handle->split_flow_id)
13794 mlx5_ipool_free(fm->flow_ipool,
13795 dev_handle->split_flow_id);
13796 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
13800 flow_dv_shared_rss_action_release(dev, srss);
13804 * Release array of hash RX queue objects.
13808 * Pointer to the Ethernet device structure.
13809 * @param[in, out] hrxqs
13810 * Array of hash RX queue objects.
13813 * Total number of references to hash RX queue objects in *hrxqs* array
13814 * after this operation.
13817 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
13818 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
13823 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
13824 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
13834 * Release all hash RX queue objects representing shared RSS action.
13837 * Pointer to the Ethernet device structure.
13838 * @param[in, out] action
13839 * Shared RSS action to remove hash RX queue objects from.
13842 * Total number of references to hash RX queue objects stored in *action*
13843 * after this operation.
13844 * Expected to be 0 if no external references held.
13847 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
13848 struct mlx5_shared_action_rss *shared_rss)
13850 return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
13854 * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
13857 * Only one hash value is available for one L3+L4 combination:
13859 * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
13860 * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
13861 * same slot in mlx5_rss_hash_fields.
13864 * Pointer to the shared action RSS conf.
13865 * @param[in, out] hash_field
13866 * hash_field variable needed to be adjusted.
13872 __flow_dv_action_rss_l34_hash_adjust(struct mlx5_shared_action_rss *rss,
13873 uint64_t *hash_field)
13875 uint64_t rss_types = rss->origin.types;
13877 switch (*hash_field & ~IBV_RX_HASH_INNER) {
13878 case MLX5_RSS_HASH_IPV4:
13879 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
13880 *hash_field &= ~MLX5_RSS_HASH_IPV4;
13881 if (rss_types & ETH_RSS_L3_DST_ONLY)
13882 *hash_field |= IBV_RX_HASH_DST_IPV4;
13883 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
13884 *hash_field |= IBV_RX_HASH_SRC_IPV4;
13886 *hash_field |= MLX5_RSS_HASH_IPV4;
13889 case MLX5_RSS_HASH_IPV6:
13890 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
13891 *hash_field &= ~MLX5_RSS_HASH_IPV6;
13892 if (rss_types & ETH_RSS_L3_DST_ONLY)
13893 *hash_field |= IBV_RX_HASH_DST_IPV6;
13894 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
13895 *hash_field |= IBV_RX_HASH_SRC_IPV6;
13897 *hash_field |= MLX5_RSS_HASH_IPV6;
13900 case MLX5_RSS_HASH_IPV4_UDP:
13901 /* fall-through. */
13902 case MLX5_RSS_HASH_IPV6_UDP:
13903 if (rss_types & ETH_RSS_UDP) {
13904 *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
13905 if (rss_types & ETH_RSS_L4_DST_ONLY)
13906 *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
13907 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
13908 *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
13910 *hash_field |= MLX5_UDP_IBV_RX_HASH;
13913 case MLX5_RSS_HASH_IPV4_TCP:
13914 /* fall-through. */
13915 case MLX5_RSS_HASH_IPV6_TCP:
13916 if (rss_types & ETH_RSS_TCP) {
13917 *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
13918 if (rss_types & ETH_RSS_L4_DST_ONLY)
13919 *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
13920 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
13921 *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
13923 *hash_field |= MLX5_TCP_IBV_RX_HASH;
13932 * Setup shared RSS action.
13933 * Prepare set of hash RX queue objects sufficient to handle all valid
13934 * hash_fields combinations (see enum ibv_rx_hash_fields).
13937 * Pointer to the Ethernet device structure.
13938 * @param[in] action_idx
13939 * Shared RSS action ipool index.
13940 * @param[in, out] action
13941 * Partially initialized shared RSS action.
13942 * @param[out] error
13943 * Perform verbose error reporting if not NULL. Initialized in case of
13947 * 0 on success, otherwise negative errno value.
13950 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
13951 uint32_t action_idx,
13952 struct mlx5_shared_action_rss *shared_rss,
13953 struct rte_flow_error *error)
13955 struct mlx5_flow_rss_desc rss_desc = { 0 };
13959 if (mlx5_ind_table_obj_setup(dev, shared_rss->ind_tbl)) {
13960 return rte_flow_error_set(error, rte_errno,
13961 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13962 "cannot setup indirection table");
13964 memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
13965 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
13966 rss_desc.const_q = shared_rss->origin.queue;
13967 rss_desc.queue_num = shared_rss->origin.queue_num;
13968 /* Set non-zero value to indicate a shared RSS. */
13969 rss_desc.shared_rss = action_idx;
13970 rss_desc.ind_tbl = shared_rss->ind_tbl;
13971 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
13973 uint64_t hash_fields = mlx5_rss_hash_fields[i];
13976 __flow_dv_action_rss_l34_hash_adjust(shared_rss, &hash_fields);
13977 if (shared_rss->origin.level > 1) {
13978 hash_fields |= IBV_RX_HASH_INNER;
13981 rss_desc.tunnel = tunnel;
13982 rss_desc.hash_fields = hash_fields;
13983 hrxq_idx = mlx5_hrxq_get(dev, &rss_desc);
13987 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13988 "cannot get hash queue");
13989 goto error_hrxq_new;
13991 err = __flow_dv_action_rss_hrxq_set
13992 (shared_rss, hash_fields, hrxq_idx);
13998 __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
13999 if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
14000 shared_rss->ind_tbl = NULL;
14006 * Create shared RSS action.
14009 * Pointer to the Ethernet device structure.
14011 * Shared action configuration.
14013 * RSS action specification used to create shared action.
14014 * @param[out] error
14015 * Perform verbose error reporting if not NULL. Initialized in case of
14019 * A valid shared action ID in case of success, 0 otherwise and
14020 * rte_errno is set.
14023 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
14024 const struct rte_flow_indir_action_conf *conf,
14025 const struct rte_flow_action_rss *rss,
14026 struct rte_flow_error *error)
14028 struct mlx5_priv *priv = dev->data->dev_private;
14029 struct mlx5_shared_action_rss *shared_rss = NULL;
14030 void *queue = NULL;
14031 struct rte_flow_action_rss *origin;
14032 const uint8_t *rss_key;
14033 uint32_t queue_size = rss->queue_num * sizeof(uint16_t);
14036 RTE_SET_USED(conf);
14037 queue = mlx5_malloc(0, RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14039 shared_rss = mlx5_ipool_zmalloc
14040 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
14041 if (!shared_rss || !queue) {
14042 rte_flow_error_set(error, ENOMEM,
14043 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14044 "cannot allocate resource memory");
14045 goto error_rss_init;
14047 if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
14048 rte_flow_error_set(error, E2BIG,
14049 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14050 "rss action number out of range");
14051 goto error_rss_init;
14053 shared_rss->ind_tbl = mlx5_malloc(MLX5_MEM_ZERO,
14054 sizeof(*shared_rss->ind_tbl),
14056 if (!shared_rss->ind_tbl) {
14057 rte_flow_error_set(error, ENOMEM,
14058 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14059 "cannot allocate resource memory");
14060 goto error_rss_init;
14062 memcpy(queue, rss->queue, queue_size);
14063 shared_rss->ind_tbl->queues = queue;
14064 shared_rss->ind_tbl->queues_n = rss->queue_num;
14065 origin = &shared_rss->origin;
14066 origin->func = rss->func;
14067 origin->level = rss->level;
14068 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
14069 origin->types = !rss->types ? ETH_RSS_IP : rss->types;
14070 /* NULL RSS key indicates default RSS key. */
14071 rss_key = !rss->key ? rss_hash_default_key : rss->key;
14072 memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
14073 origin->key = &shared_rss->key[0];
14074 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
14075 origin->queue = queue;
14076 origin->queue_num = rss->queue_num;
14077 if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
14078 goto error_rss_init;
14079 rte_spinlock_init(&shared_rss->action_rss_sl);
14080 __atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14081 rte_spinlock_lock(&priv->shared_act_sl);
14082 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14083 &priv->rss_shared_actions, idx, shared_rss, next);
14084 rte_spinlock_unlock(&priv->shared_act_sl);
14088 if (shared_rss->ind_tbl)
14089 mlx5_free(shared_rss->ind_tbl);
14090 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14099 * Destroy the shared RSS action.
14100 * Release related hash RX queue objects.
14103 * Pointer to the Ethernet device structure.
14105 * The shared RSS action object ID to be removed.
14106 * @param[out] error
14107 * Perform verbose error reporting if not NULL. Initialized in case of
14111 * 0 on success, otherwise negative errno value.
14114 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
14115 struct rte_flow_error *error)
14117 struct mlx5_priv *priv = dev->data->dev_private;
14118 struct mlx5_shared_action_rss *shared_rss =
14119 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14120 uint32_t old_refcnt = 1;
14122 uint16_t *queue = NULL;
14125 return rte_flow_error_set(error, EINVAL,
14126 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14127 "invalid shared action");
14128 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14130 return rte_flow_error_set(error, EBUSY,
14131 RTE_FLOW_ERROR_TYPE_ACTION,
14133 "shared rss hrxq has references");
14134 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
14135 0, 0, __ATOMIC_ACQUIRE,
14137 return rte_flow_error_set(error, EBUSY,
14138 RTE_FLOW_ERROR_TYPE_ACTION,
14140 "shared rss has references");
14141 queue = shared_rss->ind_tbl->queues;
14142 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true);
14144 return rte_flow_error_set(error, EBUSY,
14145 RTE_FLOW_ERROR_TYPE_ACTION,
14147 "shared rss indirection table has"
14150 rte_spinlock_lock(&priv->shared_act_sl);
14151 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14152 &priv->rss_shared_actions, idx, shared_rss, next);
14153 rte_spinlock_unlock(&priv->shared_act_sl);
14154 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14160 * Create indirect action, lock free,
14161 * (mutex should be acquired by caller).
14162 * Dispatcher for action type specific call.
14165 * Pointer to the Ethernet device structure.
14167 * Shared action configuration.
14168 * @param[in] action
14169 * Action specification used to create indirect action.
14170 * @param[out] error
14171 * Perform verbose error reporting if not NULL. Initialized in case of
14175 * A valid shared action handle in case of success, NULL otherwise and
14176 * rte_errno is set.
14178 static struct rte_flow_action_handle *
14179 flow_dv_action_create(struct rte_eth_dev *dev,
14180 const struct rte_flow_indir_action_conf *conf,
14181 const struct rte_flow_action *action,
14182 struct rte_flow_error *err)
14187 switch (action->type) {
14188 case RTE_FLOW_ACTION_TYPE_RSS:
14189 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
14190 idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
14191 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14193 case RTE_FLOW_ACTION_TYPE_AGE:
14194 ret = flow_dv_translate_create_aso_age(dev, action->conf, err);
14195 idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
14196 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14198 struct mlx5_aso_age_action *aso_age =
14199 flow_aso_age_get_by_idx(dev, ret);
14201 if (!aso_age->age_params.context)
14202 aso_age->age_params.context =
14203 (void *)(uintptr_t)idx;
14206 case RTE_FLOW_ACTION_TYPE_COUNT:
14207 ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
14208 idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
14209 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14211 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
14212 ret = flow_dv_translate_create_conntrack(dev, action->conf,
14214 idx = (MLX5_INDIRECT_ACTION_TYPE_CT <<
14215 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14218 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
14219 NULL, "action type not supported");
14222 return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
14226 * Destroy the indirect action.
14227 * Release action related resources on the NIC and the memory.
14228 * Lock free, (mutex should be acquired by caller).
14229 * Dispatcher for action type specific call.
14232 * Pointer to the Ethernet device structure.
14233 * @param[in] handle
14234 * The indirect action object handle to be removed.
14235 * @param[out] error
14236 * Perform verbose error reporting if not NULL. Initialized in case of
14240 * 0 on success, otherwise negative errno value.
14243 flow_dv_action_destroy(struct rte_eth_dev *dev,
14244 struct rte_flow_action_handle *handle,
14245 struct rte_flow_error *error)
14247 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14248 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14249 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
14250 struct mlx5_flow_counter *cnt;
14251 uint32_t no_flow_refcnt = 1;
14255 case MLX5_INDIRECT_ACTION_TYPE_RSS:
14256 return __flow_dv_action_rss_release(dev, idx, error);
14257 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
14258 cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
14259 if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
14260 &no_flow_refcnt, 1, false,
14263 return rte_flow_error_set(error, EBUSY,
14264 RTE_FLOW_ERROR_TYPE_ACTION,
14266 "Indirect count action has references");
14267 flow_dv_counter_free(dev, idx);
14269 case MLX5_INDIRECT_ACTION_TYPE_AGE:
14270 ret = flow_dv_aso_age_release(dev, idx);
14273 * In this case, the last flow has a reference will
14274 * actually release the age action.
14276 DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
14277 " released with references %d.", idx, ret);
14279 case MLX5_INDIRECT_ACTION_TYPE_CT:
14280 ret = flow_dv_aso_ct_release(dev, idx);
14282 DRV_LOG(DEBUG, "Connection tracking object %u still "
14283 "has references %d.", idx, ret);
14286 return rte_flow_error_set(error, ENOTSUP,
14287 RTE_FLOW_ERROR_TYPE_ACTION,
14289 "action type not supported");
14294 * Updates in place shared RSS action configuration.
14297 * Pointer to the Ethernet device structure.
14299 * The shared RSS action object ID to be updated.
14300 * @param[in] action_conf
14301 * RSS action specification used to modify *shared_rss*.
14302 * @param[out] error
14303 * Perform verbose error reporting if not NULL. Initialized in case of
14307 * 0 on success, otherwise negative errno value.
14308 * @note: currently only support update of RSS queues.
14311 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
14312 const struct rte_flow_action_rss *action_conf,
14313 struct rte_flow_error *error)
14315 struct mlx5_priv *priv = dev->data->dev_private;
14316 struct mlx5_shared_action_rss *shared_rss =
14317 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14319 void *queue = NULL;
14320 uint16_t *queue_old = NULL;
14321 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
14324 return rte_flow_error_set(error, EINVAL,
14325 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14326 "invalid shared action to update");
14327 if (priv->obj_ops.ind_table_modify == NULL)
14328 return rte_flow_error_set(error, ENOTSUP,
14329 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14330 "cannot modify indirection table");
14331 queue = mlx5_malloc(MLX5_MEM_ZERO,
14332 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14335 return rte_flow_error_set(error, ENOMEM,
14336 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14338 "cannot allocate resource memory");
14339 memcpy(queue, action_conf->queue, queue_size);
14340 MLX5_ASSERT(shared_rss->ind_tbl);
14341 rte_spinlock_lock(&shared_rss->action_rss_sl);
14342 queue_old = shared_rss->ind_tbl->queues;
14343 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
14344 queue, action_conf->queue_num, true);
14347 ret = rte_flow_error_set(error, rte_errno,
14348 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14349 "cannot update indirection table");
14351 mlx5_free(queue_old);
14352 shared_rss->origin.queue = queue;
14353 shared_rss->origin.queue_num = action_conf->queue_num;
14355 rte_spinlock_unlock(&shared_rss->action_rss_sl);
14360 * Updates in place conntrack context or direction.
14361 * Context update should be synchronized.
14364 * Pointer to the Ethernet device structure.
14366 * The conntrack object ID to be updated.
14367 * @param[in] update
14368 * Pointer to the structure of information to update.
14369 * @param[out] error
14370 * Perform verbose error reporting if not NULL. Initialized in case of
14374 * 0 on success, otherwise negative errno value.
14377 __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
14378 const struct rte_flow_modify_conntrack *update,
14379 struct rte_flow_error *error)
14381 struct mlx5_priv *priv = dev->data->dev_private;
14382 struct mlx5_aso_ct_action *ct;
14383 const struct rte_flow_action_conntrack *new_prf;
14386 ct = flow_aso_ct_get_by_idx(dev, idx);
14388 return rte_flow_error_set(error, ENOMEM,
14389 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14391 "CT object is inactive");
14392 new_prf = &update->new_ct;
14393 if (update->direction)
14394 ct->is_original = !!new_prf->is_original_dir;
14395 if (update->state) {
14396 /* Only validate the profile when it needs to be updated. */
14397 ret = mlx5_validate_action_ct(dev, new_prf, error);
14400 ret = mlx5_aso_ct_update_by_wqe(priv->sh, ct, new_prf);
14402 return rte_flow_error_set(error, EIO,
14403 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14405 "Failed to send CT context update WQE");
14406 /* Block until ready or a failure. */
14407 ret = mlx5_aso_ct_available(priv->sh, ct);
14409 rte_flow_error_set(error, rte_errno,
14410 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14412 "Timeout to get the CT update");
14418 * Updates in place shared action configuration, lock free,
14419 * (mutex should be acquired by caller).
14422 * Pointer to the Ethernet device structure.
14423 * @param[in] handle
14424 * The indirect action object handle to be updated.
14425 * @param[in] update
14426 * Action specification used to modify the action pointed by *handle*.
14427 * *update* could be of same type with the action pointed by the *handle*
14428 * handle argument, or some other structures like a wrapper, depending on
14429 * the indirect action type.
14430 * @param[out] error
14431 * Perform verbose error reporting if not NULL. Initialized in case of
14435 * 0 on success, otherwise negative errno value.
14438 flow_dv_action_update(struct rte_eth_dev *dev,
14439 struct rte_flow_action_handle *handle,
14440 const void *update,
14441 struct rte_flow_error *err)
14443 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14444 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14445 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
14446 const void *action_conf;
14449 case MLX5_INDIRECT_ACTION_TYPE_RSS:
14450 action_conf = ((const struct rte_flow_action *)update)->conf;
14451 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
14452 case MLX5_INDIRECT_ACTION_TYPE_CT:
14453 return __flow_dv_action_ct_update(dev, idx, update, err);
14455 return rte_flow_error_set(err, ENOTSUP,
14456 RTE_FLOW_ERROR_TYPE_ACTION,
14458 "action type update not supported");
14463 * Destroy the meter sub policy table rules.
14464 * Lock free, (mutex should be acquired by caller).
14467 * Pointer to Ethernet device.
14468 * @param[in] sub_policy
14469 * Pointer to meter sub policy table.
14472 __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
14473 struct mlx5_flow_meter_sub_policy *sub_policy)
14475 struct mlx5_flow_tbl_data_entry *tbl;
14478 for (i = 0; i < RTE_COLORS; i++) {
14479 if (sub_policy->color_rule[i]) {
14480 claim_zero(mlx5_flow_os_destroy_flow
14481 (sub_policy->color_rule[i]));
14482 sub_policy->color_rule[i] = NULL;
14484 if (sub_policy->color_matcher[i]) {
14485 tbl = container_of(sub_policy->color_matcher[i]->tbl,
14486 typeof(*tbl), tbl);
14487 mlx5_cache_unregister(&tbl->matchers,
14488 &sub_policy->color_matcher[i]->entry);
14489 sub_policy->color_matcher[i] = NULL;
14492 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
14493 if (sub_policy->rix_hrxq[i]) {
14494 mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
14495 sub_policy->rix_hrxq[i] = 0;
14497 if (sub_policy->jump_tbl[i]) {
14498 flow_dv_tbl_resource_release(MLX5_SH(dev),
14499 sub_policy->jump_tbl[i]);
14500 sub_policy->jump_tbl[i] = NULL;
14503 if (sub_policy->tbl_rsc) {
14504 flow_dv_tbl_resource_release(MLX5_SH(dev),
14505 sub_policy->tbl_rsc);
14506 sub_policy->tbl_rsc = NULL;
14511 * Destroy policy rules, lock free,
14512 * (mutex should be acquired by caller).
14513 * Dispatcher for action type specific call.
14516 * Pointer to the Ethernet device structure.
14517 * @param[in] mtr_policy
14518 * Meter policy struct.
14521 flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
14522 struct mlx5_flow_meter_policy *mtr_policy)
14525 struct mlx5_flow_meter_sub_policy *sub_policy;
14526 uint16_t sub_policy_num;
14528 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
14529 sub_policy_num = (mtr_policy->sub_policy_num >>
14530 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
14531 MLX5_MTR_SUB_POLICY_NUM_MASK;
14532 for (j = 0; j < sub_policy_num; j++) {
14533 sub_policy = mtr_policy->sub_policys[i][j];
14535 __flow_dv_destroy_sub_policy_rules
14542 * Destroy policy action, lock free,
14543 * (mutex should be acquired by caller).
14544 * Dispatcher for action type specific call.
14547 * Pointer to the Ethernet device structure.
14548 * @param[in] mtr_policy
14549 * Meter policy struct.
14552 flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
14553 struct mlx5_flow_meter_policy *mtr_policy)
14555 struct rte_flow_action *rss_action;
14556 struct mlx5_flow_handle dev_handle;
14559 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
14560 if (mtr_policy->act_cnt[i].rix_mark) {
14561 flow_dv_tag_release(dev,
14562 mtr_policy->act_cnt[i].rix_mark);
14563 mtr_policy->act_cnt[i].rix_mark = 0;
14565 if (mtr_policy->act_cnt[i].modify_hdr) {
14566 dev_handle.dvh.modify_hdr =
14567 mtr_policy->act_cnt[i].modify_hdr;
14568 flow_dv_modify_hdr_resource_release(dev, &dev_handle);
14570 switch (mtr_policy->act_cnt[i].fate_action) {
14571 case MLX5_FLOW_FATE_SHARED_RSS:
14572 rss_action = mtr_policy->act_cnt[i].rss;
14573 mlx5_free(rss_action);
14575 case MLX5_FLOW_FATE_PORT_ID:
14576 if (mtr_policy->act_cnt[i].rix_port_id_action) {
14577 flow_dv_port_id_action_resource_release(dev,
14578 mtr_policy->act_cnt[i].rix_port_id_action);
14579 mtr_policy->act_cnt[i].rix_port_id_action = 0;
14582 case MLX5_FLOW_FATE_DROP:
14583 case MLX5_FLOW_FATE_JUMP:
14584 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
14585 mtr_policy->act_cnt[i].dr_jump_action[j] =
14589 /*Queue action do nothing*/
14593 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
14594 mtr_policy->dr_drop_action[j] = NULL;
14598 * Create policy action per domain, lock free,
14599 * (mutex should be acquired by caller).
14600 * Dispatcher for action type specific call.
14603 * Pointer to the Ethernet device structure.
14604 * @param[in] mtr_policy
14605 * Meter policy struct.
14606 * @param[in] action
14607 * Action specification used to create meter actions.
14608 * @param[out] error
14609 * Perform verbose error reporting if not NULL. Initialized in case of
14613 * 0 on success, otherwise negative errno value.
14616 __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
14617 struct mlx5_flow_meter_policy *mtr_policy,
14618 const struct rte_flow_action *actions[RTE_COLORS],
14619 enum mlx5_meter_domain domain,
14620 struct rte_mtr_error *error)
14622 struct mlx5_priv *priv = dev->data->dev_private;
14623 struct rte_flow_error flow_err;
14624 const struct rte_flow_action *act;
14625 uint64_t action_flags = 0;
14626 struct mlx5_flow_handle dh;
14627 struct mlx5_flow dev_flow;
14628 struct mlx5_flow_dv_port_id_action_resource port_id_action;
14630 uint8_t egress, transfer;
14631 struct mlx5_meter_policy_action_container *act_cnt = NULL;
14633 struct mlx5_flow_dv_modify_hdr_resource res;
14634 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
14635 sizeof(struct mlx5_modification_cmd) *
14636 (MLX5_MAX_MODIFY_NUM + 1)];
14639 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
14640 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
14641 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
14642 memset(&dev_flow, 0, sizeof(struct mlx5_flow));
14643 memset(&port_id_action, 0,
14644 sizeof(struct mlx5_flow_dv_port_id_action_resource));
14645 dev_flow.handle = &dh;
14646 dev_flow.dv.port_id_action = &port_id_action;
14647 dev_flow.external = true;
14648 for (i = 0; i < RTE_COLORS; i++) {
14649 if (i < MLX5_MTR_RTE_COLORS)
14650 act_cnt = &mtr_policy->act_cnt[i];
14651 for (act = actions[i];
14652 act && act->type != RTE_FLOW_ACTION_TYPE_END;
14654 switch (act->type) {
14655 case RTE_FLOW_ACTION_TYPE_MARK:
14657 uint32_t tag_be = mlx5_flow_mark_set
14658 (((const struct rte_flow_action_mark *)
14661 if (i >= MLX5_MTR_RTE_COLORS)
14662 return -rte_mtr_error_set(error,
14664 RTE_MTR_ERROR_TYPE_METER_POLICY,
14666 "cannot create policy "
14667 "mark action for this color");
14668 dev_flow.handle->mark = 1;
14669 if (flow_dv_tag_resource_register(dev, tag_be,
14670 &dev_flow, &flow_err))
14671 return -rte_mtr_error_set(error,
14673 RTE_MTR_ERROR_TYPE_METER_POLICY,
14675 "cannot setup policy mark action");
14676 MLX5_ASSERT(dev_flow.dv.tag_resource);
14677 act_cnt->rix_mark =
14678 dev_flow.handle->dvh.rix_tag;
14679 if (action_flags & MLX5_FLOW_ACTION_QUEUE) {
14680 dev_flow.handle->rix_hrxq =
14681 mtr_policy->sub_policys[domain][0]->rix_hrxq[i];
14682 flow_drv_rxq_flags_set(dev,
14685 action_flags |= MLX5_FLOW_ACTION_MARK;
14688 case RTE_FLOW_ACTION_TYPE_SET_TAG:
14690 struct mlx5_flow_dv_modify_hdr_resource
14691 *mhdr_res = &mhdr_dummy.res;
14693 if (i >= MLX5_MTR_RTE_COLORS)
14694 return -rte_mtr_error_set(error,
14696 RTE_MTR_ERROR_TYPE_METER_POLICY,
14698 "cannot create policy "
14699 "set tag action for this color");
14700 memset(mhdr_res, 0, sizeof(*mhdr_res));
14701 mhdr_res->ft_type = transfer ?
14702 MLX5DV_FLOW_TABLE_TYPE_FDB :
14704 MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
14705 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
14706 if (flow_dv_convert_action_set_tag
14708 (const struct rte_flow_action_set_tag *)
14709 act->conf, &flow_err))
14710 return -rte_mtr_error_set(error,
14712 RTE_MTR_ERROR_TYPE_METER_POLICY,
14713 NULL, "cannot convert policy "
14715 if (!mhdr_res->actions_num)
14716 return -rte_mtr_error_set(error,
14718 RTE_MTR_ERROR_TYPE_METER_POLICY,
14719 NULL, "cannot find policy "
14721 /* create modify action if needed. */
14722 dev_flow.dv.group = 1;
14723 if (flow_dv_modify_hdr_resource_register
14724 (dev, mhdr_res, &dev_flow, &flow_err))
14725 return -rte_mtr_error_set(error,
14727 RTE_MTR_ERROR_TYPE_METER_POLICY,
14728 NULL, "cannot register policy "
14730 act_cnt->modify_hdr =
14731 dev_flow.handle->dvh.modify_hdr;
14732 if (action_flags & MLX5_FLOW_ACTION_QUEUE) {
14733 dev_flow.handle->rix_hrxq =
14734 mtr_policy->sub_policys[domain][0]->rix_hrxq[i];
14735 flow_drv_rxq_flags_set(dev,
14738 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
14741 case RTE_FLOW_ACTION_TYPE_DROP:
14743 struct mlx5_flow_mtr_mng *mtrmng =
14745 struct mlx5_flow_tbl_data_entry *tbl_data;
14748 * Create the drop table with
14749 * METER DROP level.
14751 if (!mtrmng->drop_tbl[domain]) {
14752 mtrmng->drop_tbl[domain] =
14753 flow_dv_tbl_resource_get(dev,
14754 MLX5_FLOW_TABLE_LEVEL_METER,
14755 egress, transfer, false, NULL, 0,
14756 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
14757 if (!mtrmng->drop_tbl[domain])
14758 return -rte_mtr_error_set
14760 RTE_MTR_ERROR_TYPE_METER_POLICY,
14762 "Failed to create meter drop table");
14764 tbl_data = container_of
14765 (mtrmng->drop_tbl[domain],
14766 struct mlx5_flow_tbl_data_entry, tbl);
14767 if (i < MLX5_MTR_RTE_COLORS) {
14768 act_cnt->dr_jump_action[domain] =
14769 tbl_data->jump.action;
14770 act_cnt->fate_action =
14771 MLX5_FLOW_FATE_DROP;
14773 if (i == RTE_COLOR_RED)
14774 mtr_policy->dr_drop_action[domain] =
14775 tbl_data->jump.action;
14776 action_flags |= MLX5_FLOW_ACTION_DROP;
14779 case RTE_FLOW_ACTION_TYPE_QUEUE:
14781 struct mlx5_hrxq *hrxq;
14783 struct mlx5_flow_rss_desc rss_desc;
14784 struct mlx5_flow_meter_sub_policy *sub_policy =
14785 mtr_policy->sub_policys[domain][0];
14787 if (i >= MLX5_MTR_RTE_COLORS)
14788 return -rte_mtr_error_set(error,
14790 RTE_MTR_ERROR_TYPE_METER_POLICY,
14791 NULL, "cannot create policy "
14792 "fate queue for this color");
14793 memset(&rss_desc, 0,
14794 sizeof(struct mlx5_flow_rss_desc));
14795 rss_desc.queue_num = 1;
14796 rss_desc.const_q = act->conf;
14797 hrxq = flow_dv_hrxq_prepare(dev, &dev_flow,
14798 &rss_desc, &hrxq_idx);
14800 return -rte_mtr_error_set(error,
14802 RTE_MTR_ERROR_TYPE_METER_POLICY,
14804 "cannot create policy fate queue");
14805 sub_policy->rix_hrxq[i] = hrxq_idx;
14806 act_cnt->fate_action =
14807 MLX5_FLOW_FATE_QUEUE;
14808 dev_flow.handle->fate_action =
14809 MLX5_FLOW_FATE_QUEUE;
14810 if (action_flags & MLX5_FLOW_ACTION_MARK ||
14811 action_flags & MLX5_FLOW_ACTION_SET_TAG) {
14812 dev_flow.handle->rix_hrxq = hrxq_idx;
14813 flow_drv_rxq_flags_set(dev,
14816 action_flags |= MLX5_FLOW_ACTION_QUEUE;
14819 case RTE_FLOW_ACTION_TYPE_RSS:
14823 if (i >= MLX5_MTR_RTE_COLORS)
14824 return -rte_mtr_error_set(error,
14826 RTE_MTR_ERROR_TYPE_METER_POLICY,
14828 "cannot create policy "
14829 "rss action for this color");
14831 * Save RSS conf into policy struct
14832 * for translate stage.
14834 rss_size = (int)rte_flow_conv
14835 (RTE_FLOW_CONV_OP_ACTION,
14836 NULL, 0, act, &flow_err);
14838 return -rte_mtr_error_set(error,
14840 RTE_MTR_ERROR_TYPE_METER_POLICY,
14841 NULL, "Get the wrong "
14842 "rss action struct size");
14843 act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
14844 rss_size, 0, SOCKET_ID_ANY);
14846 return -rte_mtr_error_set(error,
14848 RTE_MTR_ERROR_TYPE_METER_POLICY,
14850 "Fail to malloc rss action memory");
14851 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
14852 act_cnt->rss, rss_size,
14855 return -rte_mtr_error_set(error,
14857 RTE_MTR_ERROR_TYPE_METER_POLICY,
14858 NULL, "Fail to save "
14859 "rss action into policy struct");
14860 act_cnt->fate_action =
14861 MLX5_FLOW_FATE_SHARED_RSS;
14862 action_flags |= MLX5_FLOW_ACTION_RSS;
14865 case RTE_FLOW_ACTION_TYPE_PORT_ID:
14867 struct mlx5_flow_dv_port_id_action_resource
14869 uint32_t port_id = 0;
14871 if (i >= MLX5_MTR_RTE_COLORS)
14872 return -rte_mtr_error_set(error,
14874 RTE_MTR_ERROR_TYPE_METER_POLICY,
14875 NULL, "cannot create policy "
14876 "port action for this color");
14877 memset(&port_id_resource, 0,
14878 sizeof(port_id_resource));
14879 if (flow_dv_translate_action_port_id(dev, act,
14880 &port_id, &flow_err))
14881 return -rte_mtr_error_set(error,
14883 RTE_MTR_ERROR_TYPE_METER_POLICY,
14884 NULL, "cannot translate "
14885 "policy port action");
14886 port_id_resource.port_id = port_id;
14887 if (flow_dv_port_id_action_resource_register
14888 (dev, &port_id_resource,
14889 &dev_flow, &flow_err))
14890 return -rte_mtr_error_set(error,
14892 RTE_MTR_ERROR_TYPE_METER_POLICY,
14893 NULL, "cannot setup "
14894 "policy port action");
14895 act_cnt->rix_port_id_action =
14896 dev_flow.handle->rix_port_id_action;
14897 act_cnt->fate_action =
14898 MLX5_FLOW_FATE_PORT_ID;
14899 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
14902 case RTE_FLOW_ACTION_TYPE_JUMP:
14904 uint32_t jump_group = 0;
14905 uint32_t table = 0;
14906 struct mlx5_flow_tbl_data_entry *tbl_data;
14907 struct flow_grp_info grp_info = {
14908 .external = !!dev_flow.external,
14909 .transfer = !!transfer,
14910 .fdb_def_rule = !!priv->fdb_def_rule,
14912 .skip_scale = dev_flow.skip_scale &
14913 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
14915 struct mlx5_flow_meter_sub_policy *sub_policy =
14916 mtr_policy->sub_policys[domain][0];
14918 if (i >= MLX5_MTR_RTE_COLORS)
14919 return -rte_mtr_error_set(error,
14921 RTE_MTR_ERROR_TYPE_METER_POLICY,
14923 "cannot create policy "
14924 "jump action for this color");
14926 ((const struct rte_flow_action_jump *)
14928 if (mlx5_flow_group_to_table(dev, NULL,
14931 &grp_info, &flow_err))
14932 return -rte_mtr_error_set(error,
14934 RTE_MTR_ERROR_TYPE_METER_POLICY,
14935 NULL, "cannot setup "
14936 "policy jump action");
14937 sub_policy->jump_tbl[i] =
14938 flow_dv_tbl_resource_get(dev,
14941 !!dev_flow.external,
14942 NULL, jump_group, 0,
14945 (!sub_policy->jump_tbl[i])
14946 return -rte_mtr_error_set(error,
14948 RTE_MTR_ERROR_TYPE_METER_POLICY,
14949 NULL, "cannot create jump action.");
14950 tbl_data = container_of
14951 (sub_policy->jump_tbl[i],
14952 struct mlx5_flow_tbl_data_entry, tbl);
14953 act_cnt->dr_jump_action[domain] =
14954 tbl_data->jump.action;
14955 act_cnt->fate_action =
14956 MLX5_FLOW_FATE_JUMP;
14957 action_flags |= MLX5_FLOW_ACTION_JUMP;
14961 return -rte_mtr_error_set(error, ENOTSUP,
14962 RTE_MTR_ERROR_TYPE_METER_POLICY,
14963 NULL, "action type not supported");
14971 * Create policy action per domain, lock free,
14972 * (mutex should be acquired by caller).
14973 * Dispatcher for action type specific call.
14976 * Pointer to the Ethernet device structure.
14977 * @param[in] mtr_policy
14978 * Meter policy struct.
14979 * @param[in] action
14980 * Action specification used to create meter actions.
14981 * @param[out] error
14982 * Perform verbose error reporting if not NULL. Initialized in case of
14986 * 0 on success, otherwise negative errno value.
14989 flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
14990 struct mlx5_flow_meter_policy *mtr_policy,
14991 const struct rte_flow_action *actions[RTE_COLORS],
14992 struct rte_mtr_error *error)
14995 uint16_t sub_policy_num;
14997 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
14998 sub_policy_num = (mtr_policy->sub_policy_num >>
14999 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15000 MLX5_MTR_SUB_POLICY_NUM_MASK;
15001 if (sub_policy_num) {
15002 ret = __flow_dv_create_domain_policy_acts(dev,
15003 mtr_policy, actions,
15004 (enum mlx5_meter_domain)i, error);
15013 * Query a DV flow rule for its statistics via DevX.
15016 * Pointer to Ethernet device.
15017 * @param[in] cnt_idx
15018 * Index to the flow counter.
15020 * Data retrieved by the query.
15021 * @param[out] error
15022 * Perform verbose error reporting if not NULL.
15025 * 0 on success, a negative errno value otherwise and rte_errno is set.
15028 flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
15029 struct rte_flow_error *error)
15031 struct mlx5_priv *priv = dev->data->dev_private;
15032 struct rte_flow_query_count *qc = data;
15034 if (!priv->config.devx)
15035 return rte_flow_error_set(error, ENOTSUP,
15036 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15038 "counters are not supported");
15040 uint64_t pkts, bytes;
15041 struct mlx5_flow_counter *cnt;
15042 int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
15045 return rte_flow_error_set(error, -err,
15046 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15047 NULL, "cannot read counters");
15048 cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
15051 qc->hits = pkts - cnt->hits;
15052 qc->bytes = bytes - cnt->bytes;
15055 cnt->bytes = bytes;
15059 return rte_flow_error_set(error, EINVAL,
15060 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15062 "counters are not available");
15066 flow_dv_action_query(struct rte_eth_dev *dev,
15067 const struct rte_flow_action_handle *handle, void *data,
15068 struct rte_flow_error *error)
15070 struct mlx5_age_param *age_param;
15071 struct rte_flow_query_age *resp;
15072 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15073 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15074 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15075 struct mlx5_priv *priv = dev->data->dev_private;
15076 struct mlx5_aso_ct_action *ct;
15079 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15080 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
15082 resp->aged = __atomic_load_n(&age_param->state,
15083 __ATOMIC_RELAXED) == AGE_TMOUT ?
15085 resp->sec_since_last_hit_valid = !resp->aged;
15086 if (resp->sec_since_last_hit_valid)
15087 resp->sec_since_last_hit = __atomic_load_n
15088 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15090 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15091 return flow_dv_query_count(dev, idx, data, error);
15092 case MLX5_INDIRECT_ACTION_TYPE_CT:
15093 ct = flow_aso_ct_get_by_idx(dev, idx);
15095 return rte_flow_error_set(error, EFAULT,
15096 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15098 "CT object is inactive");
15099 ((struct rte_flow_action_conntrack *)data)->peer_port =
15101 ((struct rte_flow_action_conntrack *)data)->is_original_dir =
15103 if (mlx5_aso_ct_query_by_wqe(priv->sh, ct, data))
15104 return rte_flow_error_set(error, EIO,
15105 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15107 "Failed to query CT context");
15110 return rte_flow_error_set(error, ENOTSUP,
15111 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15112 "action type query not supported");
15117 * Query a flow rule AGE action for aging information.
15120 * Pointer to Ethernet device.
15122 * Pointer to the sub flow.
15124 * data retrieved by the query.
15125 * @param[out] error
15126 * Perform verbose error reporting if not NULL.
15129 * 0 on success, a negative errno value otherwise and rte_errno is set.
15132 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
15133 void *data, struct rte_flow_error *error)
15135 struct rte_flow_query_age *resp = data;
15136 struct mlx5_age_param *age_param;
15139 struct mlx5_aso_age_action *act =
15140 flow_aso_age_get_by_idx(dev, flow->age);
15142 age_param = &act->age_params;
15143 } else if (flow->counter) {
15144 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
15146 if (!age_param || !age_param->timeout)
15147 return rte_flow_error_set
15149 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15150 NULL, "cannot read age data");
15152 return rte_flow_error_set(error, EINVAL,
15153 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15154 NULL, "age data not available");
15156 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
15158 resp->sec_since_last_hit_valid = !resp->aged;
15159 if (resp->sec_since_last_hit_valid)
15160 resp->sec_since_last_hit = __atomic_load_n
15161 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15168 * @see rte_flow_query()
15169 * @see rte_flow_ops
15172 flow_dv_query(struct rte_eth_dev *dev,
15173 struct rte_flow *flow __rte_unused,
15174 const struct rte_flow_action *actions __rte_unused,
15175 void *data __rte_unused,
15176 struct rte_flow_error *error __rte_unused)
15180 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
15181 switch (actions->type) {
15182 case RTE_FLOW_ACTION_TYPE_VOID:
15184 case RTE_FLOW_ACTION_TYPE_COUNT:
15185 ret = flow_dv_query_count(dev, flow->counter, data,
15188 case RTE_FLOW_ACTION_TYPE_AGE:
15189 ret = flow_dv_query_age(dev, flow, data, error);
15192 return rte_flow_error_set(error, ENOTSUP,
15193 RTE_FLOW_ERROR_TYPE_ACTION,
15195 "action not supported");
15202 * Destroy the meter table set.
15203 * Lock free, (mutex should be acquired by caller).
15206 * Pointer to Ethernet device.
15208 * Meter information table.
15211 flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
15212 struct mlx5_flow_meter_info *fm)
15214 struct mlx5_priv *priv = dev->data->dev_private;
15217 if (!fm || !priv->config.dv_flow_en)
15219 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15220 if (fm->drop_rule[i]) {
15221 claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
15222 fm->drop_rule[i] = NULL;
15228 flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
15230 struct mlx5_priv *priv = dev->data->dev_private;
15231 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15232 struct mlx5_flow_tbl_data_entry *tbl;
15235 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15236 if (mtrmng->def_rule[i]) {
15237 claim_zero(mlx5_flow_os_destroy_flow
15238 (mtrmng->def_rule[i]));
15239 mtrmng->def_rule[i] = NULL;
15241 if (mtrmng->def_matcher[i]) {
15242 tbl = container_of(mtrmng->def_matcher[i]->tbl,
15243 struct mlx5_flow_tbl_data_entry, tbl);
15244 mlx5_cache_unregister(&tbl->matchers,
15245 &mtrmng->def_matcher[i]->entry);
15246 mtrmng->def_matcher[i] = NULL;
15248 for (j = 0; j < MLX5_REG_BITS; j++) {
15249 if (mtrmng->drop_matcher[i][j]) {
15251 container_of(mtrmng->drop_matcher[i][j]->tbl,
15252 struct mlx5_flow_tbl_data_entry,
15254 mlx5_cache_unregister(&tbl->matchers,
15255 &mtrmng->drop_matcher[i][j]->entry);
15256 mtrmng->drop_matcher[i][j] = NULL;
15259 if (mtrmng->drop_tbl[i]) {
15260 flow_dv_tbl_resource_release(MLX5_SH(dev),
15261 mtrmng->drop_tbl[i]);
15262 mtrmng->drop_tbl[i] = NULL;
15267 /* Number of meter flow actions, count and jump or count and drop. */
15268 #define METER_ACTIONS 2
15271 __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
15272 enum mlx5_meter_domain domain)
15274 struct mlx5_priv *priv = dev->data->dev_private;
15275 struct mlx5_flow_meter_def_policy *def_policy =
15276 priv->sh->mtrmng->def_policy[domain];
15278 __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
15279 mlx5_free(def_policy);
15280 priv->sh->mtrmng->def_policy[domain] = NULL;
15284 * Destroy the default policy table set.
15287 * Pointer to Ethernet device.
15290 flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
15292 struct mlx5_priv *priv = dev->data->dev_private;
15295 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
15296 if (priv->sh->mtrmng->def_policy[i])
15297 __flow_dv_destroy_domain_def_policy(dev,
15298 (enum mlx5_meter_domain)i);
15299 priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
15303 __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
15304 uint32_t color_reg_c_idx,
15305 enum rte_color color, void *matcher_object,
15306 int actions_n, void *actions,
15307 bool is_default_policy, void **rule,
15308 const struct rte_flow_attr *attr)
15311 struct mlx5_flow_dv_match_params value = {
15312 .size = sizeof(value.buf) -
15313 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15315 struct mlx5_flow_dv_match_params matcher = {
15316 .size = sizeof(matcher.buf) -
15317 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15319 struct mlx5_priv *priv = dev->data->dev_private;
15321 if (!is_default_policy && (priv->representor || priv->master)) {
15322 if (flow_dv_translate_item_port_id(dev, matcher.buf,
15323 value.buf, NULL, attr)) {
15325 "Failed to create meter policy flow with port.");
15329 flow_dv_match_meta_reg(matcher.buf, value.buf,
15330 (enum modify_reg)color_reg_c_idx,
15331 rte_col_2_mlx5_col(color),
15333 ret = mlx5_flow_os_create_flow(matcher_object,
15334 (void *)&value, actions_n, actions, rule);
15336 DRV_LOG(ERR, "Failed to create meter policy flow.");
15343 __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
15344 uint32_t color_reg_c_idx,
15346 struct mlx5_flow_meter_sub_policy *sub_policy,
15347 const struct rte_flow_attr *attr,
15348 bool is_default_policy,
15349 struct rte_flow_error *error)
15351 struct mlx5_cache_entry *entry;
15352 struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
15353 struct mlx5_flow_dv_matcher matcher = {
15355 .size = sizeof(matcher.mask.buf) -
15356 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15360 struct mlx5_flow_dv_match_params value = {
15361 .size = sizeof(value.buf) -
15362 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15364 struct mlx5_flow_cb_ctx ctx = {
15368 struct mlx5_flow_tbl_data_entry *tbl_data;
15369 struct mlx5_priv *priv = dev->data->dev_private;
15370 uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
15372 if (!is_default_policy && (priv->representor || priv->master)) {
15373 if (flow_dv_translate_item_port_id(dev, matcher.mask.buf,
15374 value.buf, NULL, attr)) {
15376 "Failed to register meter drop matcher with port.");
15380 tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
15381 if (priority < RTE_COLOR_RED)
15382 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
15383 (enum modify_reg)color_reg_c_idx, 0, color_mask);
15384 matcher.priority = priority;
15385 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15386 matcher.mask.size);
15387 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
15389 DRV_LOG(ERR, "Failed to register meter drop matcher.");
15392 sub_policy->color_matcher[priority] =
15393 container_of(entry, struct mlx5_flow_dv_matcher, entry);
15398 * Create the policy rules per domain.
15401 * Pointer to Ethernet device.
15402 * @param[in] sub_policy
15403 * Pointer to sub policy table..
15404 * @param[in] egress
15405 * Direction of the table.
15406 * @param[in] transfer
15407 * E-Switch or NIC flow.
15409 * Pointer to policy action list per color.
15412 * 0 on success, -1 otherwise.
15415 __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
15416 struct mlx5_flow_meter_sub_policy *sub_policy,
15417 uint8_t egress, uint8_t transfer, bool is_default_policy,
15418 struct mlx5_meter_policy_acts acts[RTE_COLORS])
15420 struct rte_flow_error flow_err;
15421 uint32_t color_reg_c_idx;
15422 struct rte_flow_attr attr = {
15423 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
15426 .egress = !!egress,
15427 .transfer = !!transfer,
15431 int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
15435 /* Create policy table with POLICY level. */
15436 if (!sub_policy->tbl_rsc)
15437 sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
15438 MLX5_FLOW_TABLE_LEVEL_POLICY,
15439 egress, transfer, false, NULL, 0, 0,
15440 sub_policy->idx, &flow_err);
15441 if (!sub_policy->tbl_rsc) {
15443 "Failed to create meter sub policy table.");
15446 /* Prepare matchers. */
15447 color_reg_c_idx = ret;
15448 for (i = 0; i < RTE_COLORS; i++) {
15449 if (i == RTE_COLOR_YELLOW || !acts[i].actions_n)
15452 if (!sub_policy->color_matcher[i]) {
15453 /* Create matchers for Color. */
15454 if (__flow_dv_create_policy_matcher(dev,
15455 color_reg_c_idx, i, sub_policy,
15456 &attr, is_default_policy, &flow_err))
15459 /* Create flow, matching color. */
15460 if (acts[i].actions_n)
15461 if (__flow_dv_create_policy_flow(dev,
15462 color_reg_c_idx, (enum rte_color)i,
15463 sub_policy->color_matcher[i]->matcher_object,
15465 acts[i].dv_actions,
15467 &sub_policy->color_rule[i],
15475 __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
15476 struct mlx5_flow_meter_policy *mtr_policy,
15477 struct mlx5_flow_meter_sub_policy *sub_policy,
15480 struct mlx5_priv *priv = dev->data->dev_private;
15481 struct mlx5_meter_policy_acts acts[RTE_COLORS];
15482 struct mlx5_flow_dv_tag_resource *tag;
15483 struct mlx5_flow_dv_port_id_action_resource *port_action;
15484 struct mlx5_hrxq *hrxq;
15485 uint8_t egress, transfer;
15488 for (i = 0; i < RTE_COLORS; i++) {
15489 acts[i].actions_n = 0;
15490 if (i == RTE_COLOR_YELLOW)
15492 if (i == RTE_COLOR_RED) {
15493 /* Only support drop on red. */
15494 acts[i].dv_actions[0] =
15495 mtr_policy->dr_drop_action[domain];
15496 acts[i].actions_n = 1;
15499 if (mtr_policy->act_cnt[i].rix_mark) {
15500 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
15501 mtr_policy->act_cnt[i].rix_mark);
15503 DRV_LOG(ERR, "Failed to find "
15504 "mark action for policy.");
15507 acts[i].dv_actions[acts[i].actions_n] =
15509 acts[i].actions_n++;
15511 if (mtr_policy->act_cnt[i].modify_hdr) {
15512 acts[i].dv_actions[acts[i].actions_n] =
15513 mtr_policy->act_cnt[i].modify_hdr->action;
15514 acts[i].actions_n++;
15516 if (mtr_policy->act_cnt[i].fate_action) {
15517 switch (mtr_policy->act_cnt[i].fate_action) {
15518 case MLX5_FLOW_FATE_PORT_ID:
15519 port_action = mlx5_ipool_get
15520 (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
15521 mtr_policy->act_cnt[i].rix_port_id_action);
15522 if (!port_action) {
15523 DRV_LOG(ERR, "Failed to find "
15524 "port action for policy.");
15527 acts[i].dv_actions[acts[i].actions_n] =
15528 port_action->action;
15529 acts[i].actions_n++;
15531 case MLX5_FLOW_FATE_DROP:
15532 case MLX5_FLOW_FATE_JUMP:
15533 acts[i].dv_actions[acts[i].actions_n] =
15534 mtr_policy->act_cnt[i].dr_jump_action[domain];
15535 acts[i].actions_n++;
15537 case MLX5_FLOW_FATE_SHARED_RSS:
15538 case MLX5_FLOW_FATE_QUEUE:
15539 hrxq = mlx5_ipool_get
15540 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
15541 sub_policy->rix_hrxq[i]);
15543 DRV_LOG(ERR, "Failed to find "
15544 "queue action for policy.");
15547 acts[i].dv_actions[acts[i].actions_n] =
15549 acts[i].actions_n++;
15552 /*Queue action do nothing*/
15557 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15558 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15559 if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
15560 egress, transfer, false, acts)) {
15562 "Failed to create policy rules per domain.");
15569 * Create the policy rules.
15572 * Pointer to Ethernet device.
15573 * @param[in,out] mtr_policy
15574 * Pointer to meter policy table.
15577 * 0 on success, -1 otherwise.
15580 flow_dv_create_policy_rules(struct rte_eth_dev *dev,
15581 struct mlx5_flow_meter_policy *mtr_policy)
15584 uint16_t sub_policy_num;
15586 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15587 sub_policy_num = (mtr_policy->sub_policy_num >>
15588 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15589 MLX5_MTR_SUB_POLICY_NUM_MASK;
15590 if (!sub_policy_num)
15592 /* Prepare actions list and create policy rules. */
15593 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
15594 mtr_policy->sub_policys[i][0], i)) {
15596 "Failed to create policy action list per domain.");
15604 __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
15606 struct mlx5_priv *priv = dev->data->dev_private;
15607 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15608 struct mlx5_flow_meter_def_policy *def_policy;
15609 struct mlx5_flow_tbl_resource *jump_tbl;
15610 struct mlx5_flow_tbl_data_entry *tbl_data;
15611 uint8_t egress, transfer;
15612 struct rte_flow_error error;
15613 struct mlx5_meter_policy_acts acts[RTE_COLORS];
15616 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15617 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15618 def_policy = mtrmng->def_policy[domain];
15620 def_policy = mlx5_malloc(MLX5_MEM_ZERO,
15621 sizeof(struct mlx5_flow_meter_def_policy),
15622 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
15624 DRV_LOG(ERR, "Failed to alloc "
15625 "default policy table.");
15626 goto def_policy_error;
15628 mtrmng->def_policy[domain] = def_policy;
15629 /* Create the meter suffix table with SUFFIX level. */
15630 jump_tbl = flow_dv_tbl_resource_get(dev,
15631 MLX5_FLOW_TABLE_LEVEL_METER,
15632 egress, transfer, false, NULL, 0,
15633 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
15636 "Failed to create meter suffix table.");
15637 goto def_policy_error;
15639 def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
15640 tbl_data = container_of(jump_tbl,
15641 struct mlx5_flow_tbl_data_entry, tbl);
15642 def_policy->dr_jump_action[RTE_COLOR_GREEN] =
15643 tbl_data->jump.action;
15644 acts[RTE_COLOR_GREEN].dv_actions[0] =
15645 tbl_data->jump.action;
15646 acts[RTE_COLOR_GREEN].actions_n = 1;
15647 /* Create jump action to the drop table. */
15648 if (!mtrmng->drop_tbl[domain]) {
15649 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
15650 (dev, MLX5_FLOW_TABLE_LEVEL_METER,
15651 egress, transfer, false, NULL, 0,
15652 0, MLX5_MTR_TABLE_ID_DROP, &error);
15653 if (!mtrmng->drop_tbl[domain]) {
15654 DRV_LOG(ERR, "Failed to create "
15655 "meter drop table for default policy.");
15656 goto def_policy_error;
15659 tbl_data = container_of(mtrmng->drop_tbl[domain],
15660 struct mlx5_flow_tbl_data_entry, tbl);
15661 def_policy->dr_jump_action[RTE_COLOR_RED] =
15662 tbl_data->jump.action;
15663 acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
15664 acts[RTE_COLOR_RED].actions_n = 1;
15665 /* Create default policy rules. */
15666 ret = __flow_dv_create_domain_policy_rules(dev,
15667 &def_policy->sub_policy,
15668 egress, transfer, true, acts);
15670 DRV_LOG(ERR, "Failed to create "
15671 "default policy rules.");
15672 goto def_policy_error;
15677 __flow_dv_destroy_domain_def_policy(dev,
15678 (enum mlx5_meter_domain)domain);
15683 * Create the default policy table set.
15686 * Pointer to Ethernet device.
15688 * 0 on success, -1 otherwise.
15691 flow_dv_create_def_policy(struct rte_eth_dev *dev)
15693 struct mlx5_priv *priv = dev->data->dev_private;
15696 /* Non-termination policy table. */
15697 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15698 if (!priv->config.dv_esw_en && i == MLX5_MTR_DOMAIN_TRANSFER)
15700 if (__flow_dv_create_domain_def_policy(dev, i)) {
15702 "Failed to create default policy");
15710 * Create the needed meter tables.
15711 * Lock free, (mutex should be acquired by caller).
15714 * Pointer to Ethernet device.
15716 * Meter information table.
15717 * @param[in] mtr_idx
15719 * @param[in] domain_bitmap
15722 * 0 on success, -1 otherwise.
15725 flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
15726 struct mlx5_flow_meter_info *fm,
15728 uint8_t domain_bitmap)
15730 struct mlx5_priv *priv = dev->data->dev_private;
15731 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15732 struct rte_flow_error error;
15733 struct mlx5_flow_tbl_data_entry *tbl_data;
15734 uint8_t egress, transfer;
15735 void *actions[METER_ACTIONS];
15736 int domain, ret, i;
15737 struct mlx5_flow_counter *cnt;
15738 struct mlx5_flow_dv_match_params value = {
15739 .size = sizeof(value.buf) -
15740 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15742 struct mlx5_flow_dv_match_params matcher_para = {
15743 .size = sizeof(matcher_para.buf) -
15744 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15746 int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
15748 uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
15749 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
15750 struct mlx5_cache_entry *entry;
15751 struct mlx5_flow_dv_matcher matcher = {
15753 .size = sizeof(matcher.mask.buf) -
15754 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15757 struct mlx5_flow_dv_matcher *drop_matcher;
15758 struct mlx5_flow_cb_ctx ctx = {
15763 if (!priv->mtr_en || mtr_id_reg_c < 0) {
15764 rte_errno = ENOTSUP;
15767 for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
15768 if (!(domain_bitmap & (1 << domain)) ||
15769 (mtrmng->def_rule[domain] && !fm->drop_cnt))
15771 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15772 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15773 /* Create the drop table with METER DROP level. */
15774 if (!mtrmng->drop_tbl[domain]) {
15775 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
15776 MLX5_FLOW_TABLE_LEVEL_METER,
15777 egress, transfer, false, NULL, 0,
15778 0, MLX5_MTR_TABLE_ID_DROP, &error);
15779 if (!mtrmng->drop_tbl[domain]) {
15780 DRV_LOG(ERR, "Failed to create meter drop table.");
15784 /* Create default matcher in drop table. */
15785 matcher.tbl = mtrmng->drop_tbl[domain],
15786 tbl_data = container_of(mtrmng->drop_tbl[domain],
15787 struct mlx5_flow_tbl_data_entry, tbl);
15788 if (!mtrmng->def_matcher[domain]) {
15789 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
15790 (enum modify_reg)mtr_id_reg_c,
15792 matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
15793 matcher.crc = rte_raw_cksum
15794 ((const void *)matcher.mask.buf,
15795 matcher.mask.size);
15796 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
15798 DRV_LOG(ERR, "Failed to register meter "
15799 "drop default matcher.");
15802 mtrmng->def_matcher[domain] = container_of(entry,
15803 struct mlx5_flow_dv_matcher, entry);
15805 /* Create default rule in drop table. */
15806 if (!mtrmng->def_rule[domain]) {
15808 actions[i++] = priv->sh->dr_drop_action;
15809 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
15810 (enum modify_reg)mtr_id_reg_c, 0, 0);
15811 ret = mlx5_flow_os_create_flow
15812 (mtrmng->def_matcher[domain]->matcher_object,
15813 (void *)&value, i, actions,
15814 &mtrmng->def_rule[domain]);
15816 DRV_LOG(ERR, "Failed to create meter "
15817 "default drop rule for drop table.");
15823 MLX5_ASSERT(mtrmng->max_mtr_bits);
15824 if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
15825 /* Create matchers for Drop. */
15826 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
15827 (enum modify_reg)mtr_id_reg_c, 0,
15828 (mtr_id_mask << mtr_id_offset));
15829 matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
15830 matcher.crc = rte_raw_cksum
15831 ((const void *)matcher.mask.buf,
15832 matcher.mask.size);
15833 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
15836 "Failed to register meter drop matcher.");
15839 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
15840 container_of(entry, struct mlx5_flow_dv_matcher,
15844 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
15845 /* Create drop rule, matching meter_id only. */
15846 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
15847 (enum modify_reg)mtr_id_reg_c,
15848 (mtr_idx << mtr_id_offset), UINT32_MAX);
15850 cnt = flow_dv_counter_get_by_idx(dev,
15851 fm->drop_cnt, NULL);
15852 actions[i++] = cnt->action;
15853 actions[i++] = priv->sh->dr_drop_action;
15854 ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
15855 (void *)&value, i, actions,
15856 &fm->drop_rule[domain]);
15858 DRV_LOG(ERR, "Failed to create meter "
15859 "drop rule for drop table.");
15865 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15866 if (fm->drop_rule[i]) {
15867 claim_zero(mlx5_flow_os_destroy_flow
15868 (fm->drop_rule[i]));
15869 fm->drop_rule[i] = NULL;
15876 * Find the policy table for prefix table with RSS.
15879 * Pointer to Ethernet device.
15880 * @param[in] mtr_policy
15881 * Pointer to meter policy table.
15882 * @param[in] rss_desc
15883 * Pointer to rss_desc
15885 * Pointer to table set on success, NULL otherwise and rte_errno is set.
15887 static struct mlx5_flow_meter_sub_policy *
15888 flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
15889 struct mlx5_flow_meter_policy *mtr_policy,
15890 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
15892 struct mlx5_priv *priv = dev->data->dev_private;
15893 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
15894 uint32_t sub_policy_idx = 0;
15895 uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
15897 struct mlx5_hrxq *hrxq;
15898 struct mlx5_flow_handle dh;
15899 struct mlx5_meter_policy_action_container *act_cnt;
15900 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
15901 uint16_t sub_policy_num;
15903 rte_spinlock_lock(&mtr_policy->sl);
15904 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15907 hrxq_idx[i] = mlx5_hrxq_get(dev, rss_desc[i]);
15908 if (!hrxq_idx[i]) {
15909 rte_spinlock_unlock(&mtr_policy->sl);
15913 sub_policy_num = (mtr_policy->sub_policy_num >>
15914 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
15915 MLX5_MTR_SUB_POLICY_NUM_MASK;
15916 for (i = 0; i < sub_policy_num;
15918 for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) {
15921 mtr_policy->sub_policys[domain][i]->rix_hrxq[j])
15924 if (j >= MLX5_MTR_RTE_COLORS) {
15926 * Found the sub policy table with
15927 * the same queue per color
15929 rte_spinlock_unlock(&mtr_policy->sl);
15930 for (j = 0; j < MLX5_MTR_RTE_COLORS; j++)
15931 mlx5_hrxq_release(dev, hrxq_idx[j]);
15932 return mtr_policy->sub_policys[domain][i];
15935 /* Create sub policy. */
15936 if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[0]) {
15937 /* Reuse the first dummy sub_policy*/
15938 sub_policy = mtr_policy->sub_policys[domain][0];
15939 sub_policy_idx = sub_policy->idx;
15941 sub_policy = mlx5_ipool_zmalloc
15942 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
15945 sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
15946 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
15947 mlx5_hrxq_release(dev, hrxq_idx[i]);
15948 goto rss_sub_policy_error;
15950 sub_policy->idx = sub_policy_idx;
15951 sub_policy->main_policy = mtr_policy;
15953 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15956 sub_policy->rix_hrxq[i] = hrxq_idx[i];
15958 * Overwrite the last action from
15959 * RSS action to Queue action.
15961 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
15964 DRV_LOG(ERR, "Failed to create policy hrxq");
15965 goto rss_sub_policy_error;
15967 act_cnt = &mtr_policy->act_cnt[i];
15968 if (act_cnt->rix_mark || act_cnt->modify_hdr) {
15969 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
15970 if (act_cnt->rix_mark)
15972 dh.fate_action = MLX5_FLOW_FATE_QUEUE;
15973 dh.rix_hrxq = hrxq_idx[i];
15974 flow_drv_rxq_flags_set(dev, &dh);
15977 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
15978 sub_policy, domain)) {
15979 DRV_LOG(ERR, "Failed to create policy "
15980 "rules per domain.");
15981 goto rss_sub_policy_error;
15983 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
15984 i = (mtr_policy->sub_policy_num >>
15985 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
15986 MLX5_MTR_SUB_POLICY_NUM_MASK;
15987 mtr_policy->sub_policys[domain][i] = sub_policy;
15989 if (i > MLX5_MTR_RSS_MAX_SUB_POLICY)
15990 goto rss_sub_policy_error;
15991 mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
15992 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
15993 mtr_policy->sub_policy_num |=
15994 (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
15995 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
15997 rte_spinlock_unlock(&mtr_policy->sl);
15999 rss_sub_policy_error:
16001 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
16002 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16003 i = (mtr_policy->sub_policy_num >>
16004 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16005 MLX5_MTR_SUB_POLICY_NUM_MASK;
16006 mtr_policy->sub_policys[domain][i] = NULL;
16008 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16012 if (sub_policy_idx)
16013 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16015 rte_spinlock_unlock(&mtr_policy->sl);
16020 * Validate the batch counter support in root table.
16022 * Create a simple flow with invalid counter and drop action on root table to
16023 * validate if batch counter with offset on root table is supported or not.
16026 * Pointer to rte_eth_dev structure.
16029 * 0 on success, a negative errno value otherwise and rte_errno is set.
16032 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
16034 struct mlx5_priv *priv = dev->data->dev_private;
16035 struct mlx5_dev_ctx_shared *sh = priv->sh;
16036 struct mlx5_flow_dv_match_params mask = {
16037 .size = sizeof(mask.buf),
16039 struct mlx5_flow_dv_match_params value = {
16040 .size = sizeof(value.buf),
16042 struct mlx5dv_flow_matcher_attr dv_attr = {
16043 .type = IBV_FLOW_ATTR_NORMAL,
16045 .match_criteria_enable = 0,
16046 .match_mask = (void *)&mask,
16048 void *actions[2] = { 0 };
16049 struct mlx5_flow_tbl_resource *tbl = NULL;
16050 struct mlx5_devx_obj *dcs = NULL;
16051 void *matcher = NULL;
16055 tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
16059 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
16062 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
16066 actions[1] = sh->dr_drop_action ? sh->dr_drop_action :
16067 priv->drop_queue.hrxq->action;
16068 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
16069 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
16073 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 2,
16077 * If batch counter with offset is not supported, the driver will not
16078 * validate the invalid offset value, flow create should success.
16079 * In this case, it means batch counter is not supported in root table.
16081 * Otherwise, if flow create is failed, counter offset is supported.
16084 DRV_LOG(INFO, "Batch counter is not supported in root "
16085 "table. Switch to fallback mode.");
16086 rte_errno = ENOTSUP;
16088 claim_zero(mlx5_flow_os_destroy_flow(flow));
16090 /* Check matcher to make sure validate fail at flow create. */
16091 if (!matcher || (matcher && errno != EINVAL))
16092 DRV_LOG(ERR, "Unexpected error in counter offset "
16093 "support detection");
16097 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
16099 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
16101 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
16103 claim_zero(mlx5_devx_cmd_destroy(dcs));
16108 * Query a devx counter.
16111 * Pointer to the Ethernet device structure.
16113 * Index to the flow counter.
16115 * Set to clear the counter statistics.
16117 * The statistics value of packets.
16118 * @param[out] bytes
16119 * The statistics value of bytes.
16122 * 0 on success, otherwise return -1.
16125 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
16126 uint64_t *pkts, uint64_t *bytes)
16128 struct mlx5_priv *priv = dev->data->dev_private;
16129 struct mlx5_flow_counter *cnt;
16130 uint64_t inn_pkts, inn_bytes;
16133 if (!priv->config.devx)
16136 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
16139 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
16140 *pkts = inn_pkts - cnt->hits;
16141 *bytes = inn_bytes - cnt->bytes;
16143 cnt->hits = inn_pkts;
16144 cnt->bytes = inn_bytes;
16150 * Get aged-out flows.
16153 * Pointer to the Ethernet device structure.
16154 * @param[in] context
16155 * The address of an array of pointers to the aged-out flows contexts.
16156 * @param[in] nb_contexts
16157 * The length of context array pointers.
16158 * @param[out] error
16159 * Perform verbose error reporting if not NULL. Initialized in case of
16163 * how many contexts get in success, otherwise negative errno value.
16164 * if nb_contexts is 0, return the amount of all aged contexts.
16165 * if nb_contexts is not 0 , return the amount of aged flows reported
16166 * in the context array.
16167 * @note: only stub for now
16170 flow_get_aged_flows(struct rte_eth_dev *dev,
16172 uint32_t nb_contexts,
16173 struct rte_flow_error *error)
16175 struct mlx5_priv *priv = dev->data->dev_private;
16176 struct mlx5_age_info *age_info;
16177 struct mlx5_age_param *age_param;
16178 struct mlx5_flow_counter *counter;
16179 struct mlx5_aso_age_action *act;
16182 if (nb_contexts && !context)
16183 return rte_flow_error_set(error, EINVAL,
16184 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16185 NULL, "empty context");
16186 age_info = GET_PORT_AGE_INFO(priv);
16187 rte_spinlock_lock(&age_info->aged_sl);
16188 LIST_FOREACH(act, &age_info->aged_aso, next) {
16191 context[nb_flows - 1] =
16192 act->age_params.context;
16193 if (!(--nb_contexts))
16197 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
16200 age_param = MLX5_CNT_TO_AGE(counter);
16201 context[nb_flows - 1] = age_param->context;
16202 if (!(--nb_contexts))
16206 rte_spinlock_unlock(&age_info->aged_sl);
16207 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
16212 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
16215 flow_dv_counter_allocate(struct rte_eth_dev *dev)
16217 return flow_dv_counter_alloc(dev, 0);
16221 * Validate indirect action.
16222 * Dispatcher for action type specific validation.
16225 * Pointer to the Ethernet device structure.
16227 * Indirect action configuration.
16228 * @param[in] action
16229 * The indirect action object to validate.
16230 * @param[out] error
16231 * Perform verbose error reporting if not NULL. Initialized in case of
16235 * 0 on success, otherwise negative errno value.
16238 flow_dv_action_validate(struct rte_eth_dev *dev,
16239 const struct rte_flow_indir_action_conf *conf,
16240 const struct rte_flow_action *action,
16241 struct rte_flow_error *err)
16243 struct mlx5_priv *priv = dev->data->dev_private;
16245 RTE_SET_USED(conf);
16246 switch (action->type) {
16247 case RTE_FLOW_ACTION_TYPE_RSS:
16249 * priv->obj_ops is set according to driver capabilities.
16250 * When DevX capabilities are
16251 * sufficient, it is set to devx_obj_ops.
16252 * Otherwise, it is set to ibv_obj_ops.
16253 * ibv_obj_ops doesn't support ind_table_modify operation.
16254 * In this case the indirect RSS action can't be used.
16256 if (priv->obj_ops.ind_table_modify == NULL)
16257 return rte_flow_error_set
16259 RTE_FLOW_ERROR_TYPE_ACTION,
16261 "Indirect RSS action not supported");
16262 return mlx5_validate_action_rss(dev, action, err);
16263 case RTE_FLOW_ACTION_TYPE_AGE:
16264 if (!priv->sh->aso_age_mng)
16265 return rte_flow_error_set(err, ENOTSUP,
16266 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16268 "Indirect age action not supported");
16269 return flow_dv_validate_action_age(0, action, dev, err);
16270 case RTE_FLOW_ACTION_TYPE_COUNT:
16272 * There are two mechanisms to share the action count.
16273 * The old mechanism uses the shared field to share, while the
16274 * new mechanism uses the indirect action API.
16275 * This validation comes to make sure that the two mechanisms
16276 * are not combined.
16278 if (is_shared_action_count(action))
16279 return rte_flow_error_set(err, ENOTSUP,
16280 RTE_FLOW_ERROR_TYPE_ACTION,
16282 "Mix shared and indirect counter is not supported");
16283 return flow_dv_validate_action_count(dev, true, 0, err);
16284 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
16285 if (!priv->sh->ct_aso_en)
16286 return rte_flow_error_set(err, ENOTSUP,
16287 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16288 "ASO CT is not supported");
16289 return mlx5_validate_action_ct(dev, action->conf, err);
16291 return rte_flow_error_set(err, ENOTSUP,
16292 RTE_FLOW_ERROR_TYPE_ACTION,
16294 "action type not supported");
16299 * Validate meter policy actions.
16300 * Dispatcher for action type specific validation.
16303 * Pointer to the Ethernet device structure.
16304 * @param[in] action
16305 * The meter policy action object to validate.
16307 * Attributes of flow to determine steering domain.
16308 * @param[out] error
16309 * Perform verbose error reporting if not NULL. Initialized in case of
16313 * 0 on success, otherwise negative errno value.
16316 flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
16317 const struct rte_flow_action *actions[RTE_COLORS],
16318 struct rte_flow_attr *attr,
16320 uint8_t *domain_bitmap,
16321 bool *is_def_policy,
16322 struct rte_mtr_error *error)
16324 struct mlx5_priv *priv = dev->data->dev_private;
16325 struct mlx5_dev_config *dev_conf = &priv->config;
16326 const struct rte_flow_action *act;
16327 uint64_t action_flags = 0;
16330 struct rte_flow_error flow_err;
16331 uint8_t domain_color[RTE_COLORS] = {0};
16332 uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
16334 if (!priv->config.dv_esw_en)
16335 def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
16336 *domain_bitmap = def_domain;
16337 if (actions[RTE_COLOR_YELLOW] &&
16338 actions[RTE_COLOR_YELLOW]->type != RTE_FLOW_ACTION_TYPE_END)
16339 return -rte_mtr_error_set(error, ENOTSUP,
16340 RTE_MTR_ERROR_TYPE_METER_POLICY,
16342 "Yellow color does not support any action.");
16343 if (actions[RTE_COLOR_YELLOW] &&
16344 actions[RTE_COLOR_YELLOW]->type != RTE_FLOW_ACTION_TYPE_DROP)
16345 return -rte_mtr_error_set(error, ENOTSUP,
16346 RTE_MTR_ERROR_TYPE_METER_POLICY,
16347 NULL, "Red color only supports drop action.");
16349 * Check default policy actions:
16350 * Green/Yellow: no action, Red: drop action
16352 if ((!actions[RTE_COLOR_GREEN] ||
16353 actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)) {
16354 *is_def_policy = true;
16357 flow_err.message = NULL;
16358 for (i = 0; i < RTE_COLORS; i++) {
16360 for (action_flags = 0, actions_n = 0;
16361 act && act->type != RTE_FLOW_ACTION_TYPE_END;
16363 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
16364 return -rte_mtr_error_set(error, ENOTSUP,
16365 RTE_MTR_ERROR_TYPE_METER_POLICY,
16366 NULL, "too many actions");
16367 switch (act->type) {
16368 case RTE_FLOW_ACTION_TYPE_PORT_ID:
16369 if (!priv->config.dv_esw_en)
16370 return -rte_mtr_error_set(error,
16372 RTE_MTR_ERROR_TYPE_METER_POLICY,
16373 NULL, "PORT action validate check"
16374 " fail for ESW disable");
16375 ret = flow_dv_validate_action_port_id(dev,
16377 act, attr, &flow_err);
16379 return -rte_mtr_error_set(error,
16381 RTE_MTR_ERROR_TYPE_METER_POLICY,
16382 NULL, flow_err.message ?
16384 "PORT action validate check fail");
16386 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
16388 case RTE_FLOW_ACTION_TYPE_MARK:
16389 ret = flow_dv_validate_action_mark(dev, act,
16393 return -rte_mtr_error_set(error,
16395 RTE_MTR_ERROR_TYPE_METER_POLICY,
16396 NULL, flow_err.message ?
16398 "Mark action validate check fail");
16399 if (dev_conf->dv_xmeta_en !=
16400 MLX5_XMETA_MODE_LEGACY)
16401 return -rte_mtr_error_set(error,
16403 RTE_MTR_ERROR_TYPE_METER_POLICY,
16404 NULL, "Extend MARK action is "
16405 "not supported. Please try use "
16406 "default policy for meter.");
16407 action_flags |= MLX5_FLOW_ACTION_MARK;
16410 case RTE_FLOW_ACTION_TYPE_SET_TAG:
16411 ret = flow_dv_validate_action_set_tag(dev,
16415 return -rte_mtr_error_set(error,
16417 RTE_MTR_ERROR_TYPE_METER_POLICY,
16418 NULL, flow_err.message ?
16420 "Set tag action validate check fail");
16422 * Count all modify-header actions
16425 if (!(action_flags &
16426 MLX5_FLOW_MODIFY_HDR_ACTIONS))
16428 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
16430 case RTE_FLOW_ACTION_TYPE_DROP:
16431 ret = mlx5_flow_validate_action_drop
16435 return -rte_mtr_error_set(error,
16437 RTE_MTR_ERROR_TYPE_METER_POLICY,
16438 NULL, flow_err.message ?
16440 "Drop action validate check fail");
16441 action_flags |= MLX5_FLOW_ACTION_DROP;
16444 case RTE_FLOW_ACTION_TYPE_QUEUE:
16446 * Check whether extensive
16447 * metadata feature is engaged.
16449 if (dev_conf->dv_flow_en &&
16450 (dev_conf->dv_xmeta_en !=
16451 MLX5_XMETA_MODE_LEGACY) &&
16452 mlx5_flow_ext_mreg_supported(dev))
16453 return -rte_mtr_error_set(error,
16455 RTE_MTR_ERROR_TYPE_METER_POLICY,
16456 NULL, "Queue action with meta "
16457 "is not supported. Please try use "
16458 "default policy for meter.");
16459 ret = mlx5_flow_validate_action_queue(act,
16463 return -rte_mtr_error_set(error,
16465 RTE_MTR_ERROR_TYPE_METER_POLICY,
16466 NULL, flow_err.message ?
16468 "Queue action validate check fail");
16469 action_flags |= MLX5_FLOW_ACTION_QUEUE;
16472 case RTE_FLOW_ACTION_TYPE_RSS:
16473 if (dev_conf->dv_flow_en &&
16474 (dev_conf->dv_xmeta_en !=
16475 MLX5_XMETA_MODE_LEGACY) &&
16476 mlx5_flow_ext_mreg_supported(dev))
16477 return -rte_mtr_error_set(error,
16479 RTE_MTR_ERROR_TYPE_METER_POLICY,
16480 NULL, "RSS action with meta "
16481 "is not supported. Please try use "
16482 "default policy for meter.");
16483 ret = mlx5_validate_action_rss(dev, act,
16486 return -rte_mtr_error_set(error,
16488 RTE_MTR_ERROR_TYPE_METER_POLICY,
16489 NULL, flow_err.message ?
16491 "RSS action validate check fail");
16492 action_flags |= MLX5_FLOW_ACTION_RSS;
16496 case RTE_FLOW_ACTION_TYPE_JUMP:
16497 ret = flow_dv_validate_action_jump(dev,
16498 NULL, act, action_flags,
16499 attr, true, &flow_err);
16501 return -rte_mtr_error_set(error,
16503 RTE_MTR_ERROR_TYPE_METER_POLICY,
16504 NULL, flow_err.message ?
16506 "Jump action validate check fail");
16508 action_flags |= MLX5_FLOW_ACTION_JUMP;
16511 return -rte_mtr_error_set(error, ENOTSUP,
16512 RTE_MTR_ERROR_TYPE_METER_POLICY,
16514 "Doesn't support optional action");
16517 /* Yellow is not supported, just skip. */
16518 if (i == RTE_COLOR_YELLOW)
16520 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
16521 domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
16522 else if ((action_flags &
16523 (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
16524 (action_flags & MLX5_FLOW_ACTION_MARK))
16526 * Only support MLX5_XMETA_MODE_LEGACY
16527 * so MARK action only in ingress domain.
16529 domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
16531 domain_color[i] = def_domain;
16533 * Validate the drop action mutual exclusion
16534 * with other actions. Drop action is mutually-exclusive
16535 * with any other action, except for Count action.
16537 if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
16538 (action_flags & ~MLX5_FLOW_ACTION_DROP)) {
16539 return -rte_mtr_error_set(error, ENOTSUP,
16540 RTE_MTR_ERROR_TYPE_METER_POLICY,
16541 NULL, "Drop action is mutually-exclusive "
16542 "with any other action");
16544 /* Eswitch has few restrictions on using items and actions */
16545 if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
16546 if (!mlx5_flow_ext_mreg_supported(dev) &&
16547 action_flags & MLX5_FLOW_ACTION_MARK)
16548 return -rte_mtr_error_set(error, ENOTSUP,
16549 RTE_MTR_ERROR_TYPE_METER_POLICY,
16550 NULL, "unsupported action MARK");
16551 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
16552 return -rte_mtr_error_set(error, ENOTSUP,
16553 RTE_MTR_ERROR_TYPE_METER_POLICY,
16554 NULL, "unsupported action QUEUE");
16555 if (action_flags & MLX5_FLOW_ACTION_RSS)
16556 return -rte_mtr_error_set(error, ENOTSUP,
16557 RTE_MTR_ERROR_TYPE_METER_POLICY,
16558 NULL, "unsupported action RSS");
16559 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
16560 return -rte_mtr_error_set(error, ENOTSUP,
16561 RTE_MTR_ERROR_TYPE_METER_POLICY,
16562 NULL, "no fate action is found");
16564 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) &&
16566 MLX5_MTR_DOMAIN_INGRESS_BIT)) {
16567 if ((domain_color[i] &
16568 MLX5_MTR_DOMAIN_EGRESS_BIT))
16570 MLX5_MTR_DOMAIN_EGRESS_BIT;
16572 return -rte_mtr_error_set(error,
16574 RTE_MTR_ERROR_TYPE_METER_POLICY,
16575 NULL, "no fate action is found");
16578 if (domain_color[i] != def_domain)
16579 *domain_bitmap = domain_color[i];
16585 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
16587 struct mlx5_priv *priv = dev->data->dev_private;
16590 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
16591 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
16596 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
16597 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
16601 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
16602 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
16609 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
16610 .validate = flow_dv_validate,
16611 .prepare = flow_dv_prepare,
16612 .translate = flow_dv_translate,
16613 .apply = flow_dv_apply,
16614 .remove = flow_dv_remove,
16615 .destroy = flow_dv_destroy,
16616 .query = flow_dv_query,
16617 .create_mtr_tbls = flow_dv_create_mtr_tbls,
16618 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
16619 .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
16620 .create_meter = flow_dv_mtr_alloc,
16621 .free_meter = flow_dv_aso_mtr_release_to_pool,
16622 .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
16623 .create_mtr_acts = flow_dv_create_mtr_policy_acts,
16624 .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
16625 .create_policy_rules = flow_dv_create_policy_rules,
16626 .destroy_policy_rules = flow_dv_destroy_policy_rules,
16627 .create_def_policy = flow_dv_create_def_policy,
16628 .destroy_def_policy = flow_dv_destroy_def_policy,
16629 .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
16630 .counter_alloc = flow_dv_counter_allocate,
16631 .counter_free = flow_dv_counter_free,
16632 .counter_query = flow_dv_counter_query,
16633 .get_aged_flows = flow_get_aged_flows,
16634 .action_validate = flow_dv_action_validate,
16635 .action_create = flow_dv_action_create,
16636 .action_destroy = flow_dv_action_destroy,
16637 .action_update = flow_dv_action_update,
16638 .action_query = flow_dv_action_query,
16639 .sync_domain = flow_dv_sync_domain,
16642 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */