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 enum mlx5_tof_rule_type tof_rule_type;
6631 struct flow_grp_info grp_info = {
6632 .external = !!external,
6633 .transfer = !!attr->transfer,
6634 .fdb_def_rule = !!priv->fdb_def_rule,
6635 .std_tbl_fix = true,
6637 const struct rte_eth_hairpin_conf *conf;
6638 const struct rte_flow_item *rule_items = items;
6639 bool def_policy = false;
6643 tunnel = is_tunnel_offload_active(dev) ?
6644 mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
6646 if (priv->representor)
6647 return rte_flow_error_set
6649 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6650 NULL, "decap not supported for VF representor");
6651 if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
6652 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6653 else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
6654 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
6655 MLX5_FLOW_ACTION_DECAP;
6656 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
6657 (dev, attr, tunnel, tof_rule_type);
6659 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
6662 is_root = (uint64_t)ret;
6663 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6664 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
6665 int type = items->type;
6667 if (!mlx5_flow_os_item_supported(type))
6668 return rte_flow_error_set(error, ENOTSUP,
6669 RTE_FLOW_ERROR_TYPE_ITEM,
6670 NULL, "item not supported");
6672 case RTE_FLOW_ITEM_TYPE_VOID:
6674 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6675 ret = flow_dv_validate_item_port_id
6676 (dev, items, attr, item_flags, error);
6679 last_item = MLX5_FLOW_ITEM_PORT_ID;
6681 case RTE_FLOW_ITEM_TYPE_ETH:
6682 ret = mlx5_flow_validate_item_eth(items, item_flags,
6686 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
6687 MLX5_FLOW_LAYER_OUTER_L2;
6688 if (items->mask != NULL && items->spec != NULL) {
6690 ((const struct rte_flow_item_eth *)
6693 ((const struct rte_flow_item_eth *)
6695 ether_type = rte_be_to_cpu_16(ether_type);
6700 case RTE_FLOW_ITEM_TYPE_VLAN:
6701 ret = flow_dv_validate_item_vlan(items, item_flags,
6705 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
6706 MLX5_FLOW_LAYER_OUTER_VLAN;
6707 if (items->mask != NULL && items->spec != NULL) {
6709 ((const struct rte_flow_item_vlan *)
6710 items->spec)->inner_type;
6712 ((const struct rte_flow_item_vlan *)
6713 items->mask)->inner_type;
6714 ether_type = rte_be_to_cpu_16(ether_type);
6718 /* Store outer VLAN mask for of_push_vlan action. */
6720 vlan_m = items->mask;
6722 case RTE_FLOW_ITEM_TYPE_IPV4:
6723 mlx5_flow_tunnel_ip_check(items, next_protocol,
6724 &item_flags, &tunnel);
6725 ret = flow_dv_validate_item_ipv4(items, item_flags,
6726 last_item, ether_type,
6730 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
6731 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
6732 if (items->mask != NULL &&
6733 ((const struct rte_flow_item_ipv4 *)
6734 items->mask)->hdr.next_proto_id) {
6736 ((const struct rte_flow_item_ipv4 *)
6737 (items->spec))->hdr.next_proto_id;
6739 ((const struct rte_flow_item_ipv4 *)
6740 (items->mask))->hdr.next_proto_id;
6742 /* Reset for inner layer. */
6743 next_protocol = 0xff;
6746 case RTE_FLOW_ITEM_TYPE_IPV6:
6747 mlx5_flow_tunnel_ip_check(items, next_protocol,
6748 &item_flags, &tunnel);
6749 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
6756 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
6757 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
6758 if (items->mask != NULL &&
6759 ((const struct rte_flow_item_ipv6 *)
6760 items->mask)->hdr.proto) {
6762 ((const struct rte_flow_item_ipv6 *)
6763 items->spec)->hdr.proto;
6765 ((const struct rte_flow_item_ipv6 *)
6766 items->spec)->hdr.proto;
6768 ((const struct rte_flow_item_ipv6 *)
6769 items->mask)->hdr.proto;
6771 /* Reset for inner layer. */
6772 next_protocol = 0xff;
6775 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
6776 ret = flow_dv_validate_item_ipv6_frag_ext(items,
6781 last_item = tunnel ?
6782 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
6783 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
6784 if (items->mask != NULL &&
6785 ((const struct rte_flow_item_ipv6_frag_ext *)
6786 items->mask)->hdr.next_header) {
6788 ((const struct rte_flow_item_ipv6_frag_ext *)
6789 items->spec)->hdr.next_header;
6791 ((const struct rte_flow_item_ipv6_frag_ext *)
6792 items->mask)->hdr.next_header;
6794 /* Reset for inner layer. */
6795 next_protocol = 0xff;
6798 case RTE_FLOW_ITEM_TYPE_TCP:
6799 ret = mlx5_flow_validate_item_tcp
6806 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
6807 MLX5_FLOW_LAYER_OUTER_L4_TCP;
6809 case RTE_FLOW_ITEM_TYPE_UDP:
6810 ret = mlx5_flow_validate_item_udp(items, item_flags,
6815 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
6816 MLX5_FLOW_LAYER_OUTER_L4_UDP;
6818 case RTE_FLOW_ITEM_TYPE_GRE:
6819 ret = mlx5_flow_validate_item_gre(items, item_flags,
6820 next_protocol, error);
6824 last_item = MLX5_FLOW_LAYER_GRE;
6826 case RTE_FLOW_ITEM_TYPE_NVGRE:
6827 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
6832 last_item = MLX5_FLOW_LAYER_NVGRE;
6834 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6835 ret = mlx5_flow_validate_item_gre_key
6836 (items, item_flags, gre_item, error);
6839 last_item = MLX5_FLOW_LAYER_GRE_KEY;
6841 case RTE_FLOW_ITEM_TYPE_VXLAN:
6842 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
6846 last_item = MLX5_FLOW_LAYER_VXLAN;
6848 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6849 ret = mlx5_flow_validate_item_vxlan_gpe(items,
6854 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
6856 case RTE_FLOW_ITEM_TYPE_GENEVE:
6857 ret = mlx5_flow_validate_item_geneve(items,
6862 geneve_item = items;
6863 last_item = MLX5_FLOW_LAYER_GENEVE;
6865 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
6866 ret = mlx5_flow_validate_item_geneve_opt(items,
6873 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
6875 case RTE_FLOW_ITEM_TYPE_MPLS:
6876 ret = mlx5_flow_validate_item_mpls(dev, items,
6881 last_item = MLX5_FLOW_LAYER_MPLS;
6884 case RTE_FLOW_ITEM_TYPE_MARK:
6885 ret = flow_dv_validate_item_mark(dev, items, attr,
6889 last_item = MLX5_FLOW_ITEM_MARK;
6891 case RTE_FLOW_ITEM_TYPE_META:
6892 ret = flow_dv_validate_item_meta(dev, items, attr,
6896 last_item = MLX5_FLOW_ITEM_METADATA;
6898 case RTE_FLOW_ITEM_TYPE_ICMP:
6899 ret = mlx5_flow_validate_item_icmp(items, item_flags,
6904 last_item = MLX5_FLOW_LAYER_ICMP;
6906 case RTE_FLOW_ITEM_TYPE_ICMP6:
6907 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
6912 item_ipv6_proto = IPPROTO_ICMPV6;
6913 last_item = MLX5_FLOW_LAYER_ICMP6;
6915 case RTE_FLOW_ITEM_TYPE_TAG:
6916 ret = flow_dv_validate_item_tag(dev, items,
6920 last_item = MLX5_FLOW_ITEM_TAG;
6922 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
6923 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
6925 case RTE_FLOW_ITEM_TYPE_GTP:
6926 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
6931 last_item = MLX5_FLOW_LAYER_GTP;
6933 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6934 ret = flow_dv_validate_item_gtp_psc(items, last_item,
6939 last_item = MLX5_FLOW_LAYER_GTP_PSC;
6941 case RTE_FLOW_ITEM_TYPE_ECPRI:
6942 /* Capacity will be checked in the translate stage. */
6943 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
6950 last_item = MLX5_FLOW_LAYER_ECPRI;
6952 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
6953 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY)
6954 return rte_flow_error_set
6956 RTE_FLOW_ERROR_TYPE_ITEM,
6957 NULL, "multiple integrity items not supported");
6958 ret = flow_dv_validate_item_integrity(dev, rule_items,
6962 last_item = MLX5_FLOW_ITEM_INTEGRITY;
6964 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
6965 ret = flow_dv_validate_item_aso_ct(dev, items,
6966 &item_flags, error);
6970 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
6971 /* tunnel offload item was processed before
6972 * list it here as a supported type
6976 return rte_flow_error_set(error, ENOTSUP,
6977 RTE_FLOW_ERROR_TYPE_ITEM,
6978 NULL, "item not supported");
6980 item_flags |= last_item;
6982 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
6983 int type = actions->type;
6984 bool shared_count = false;
6986 if (!mlx5_flow_os_action_supported(type))
6987 return rte_flow_error_set(error, ENOTSUP,
6988 RTE_FLOW_ERROR_TYPE_ACTION,
6990 "action not supported");
6991 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6992 return rte_flow_error_set(error, ENOTSUP,
6993 RTE_FLOW_ERROR_TYPE_ACTION,
6994 actions, "too many actions");
6996 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
6997 return rte_flow_error_set(error, ENOTSUP,
6998 RTE_FLOW_ERROR_TYPE_ACTION,
6999 NULL, "meter action with policy "
7000 "must be the last action");
7002 case RTE_FLOW_ACTION_TYPE_VOID:
7004 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7005 ret = flow_dv_validate_action_port_id(dev,
7012 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7015 case RTE_FLOW_ACTION_TYPE_FLAG:
7016 ret = flow_dv_validate_action_flag(dev, action_flags,
7020 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7021 /* Count all modify-header actions as one. */
7022 if (!(action_flags &
7023 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7025 action_flags |= MLX5_FLOW_ACTION_FLAG |
7026 MLX5_FLOW_ACTION_MARK_EXT;
7027 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7028 modify_after_mirror = 1;
7031 action_flags |= MLX5_FLOW_ACTION_FLAG;
7034 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7036 case RTE_FLOW_ACTION_TYPE_MARK:
7037 ret = flow_dv_validate_action_mark(dev, actions,
7042 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7043 /* Count all modify-header actions as one. */
7044 if (!(action_flags &
7045 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7047 action_flags |= MLX5_FLOW_ACTION_MARK |
7048 MLX5_FLOW_ACTION_MARK_EXT;
7049 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7050 modify_after_mirror = 1;
7052 action_flags |= MLX5_FLOW_ACTION_MARK;
7055 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7057 case RTE_FLOW_ACTION_TYPE_SET_META:
7058 ret = flow_dv_validate_action_set_meta(dev, actions,
7063 /* Count all modify-header actions as one action. */
7064 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7066 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7067 modify_after_mirror = 1;
7068 action_flags |= MLX5_FLOW_ACTION_SET_META;
7069 rw_act_num += MLX5_ACT_NUM_SET_META;
7071 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7072 ret = flow_dv_validate_action_set_tag(dev, actions,
7077 /* Count all modify-header actions as one action. */
7078 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7080 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7081 modify_after_mirror = 1;
7082 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7083 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7085 case RTE_FLOW_ACTION_TYPE_DROP:
7086 ret = mlx5_flow_validate_action_drop(action_flags,
7090 action_flags |= MLX5_FLOW_ACTION_DROP;
7093 case RTE_FLOW_ACTION_TYPE_QUEUE:
7094 ret = mlx5_flow_validate_action_queue(actions,
7099 queue_index = ((const struct rte_flow_action_queue *)
7100 (actions->conf))->index;
7101 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7104 case RTE_FLOW_ACTION_TYPE_RSS:
7105 rss = actions->conf;
7106 ret = mlx5_flow_validate_action_rss(actions,
7112 if (rss && sample_rss &&
7113 (sample_rss->level != rss->level ||
7114 sample_rss->types != rss->types))
7115 return rte_flow_error_set(error, ENOTSUP,
7116 RTE_FLOW_ERROR_TYPE_ACTION,
7118 "Can't use the different RSS types "
7119 "or level in the same flow");
7120 if (rss != NULL && rss->queue_num)
7121 queue_index = rss->queue[0];
7122 action_flags |= MLX5_FLOW_ACTION_RSS;
7125 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7127 mlx5_flow_validate_action_default_miss(action_flags,
7131 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
7134 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
7135 case RTE_FLOW_ACTION_TYPE_COUNT:
7136 shared_count = is_shared_action_count(actions);
7137 ret = flow_dv_validate_action_count(dev, shared_count,
7142 action_flags |= MLX5_FLOW_ACTION_COUNT;
7145 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7146 if (flow_dv_validate_action_pop_vlan(dev,
7152 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7153 modify_after_mirror = 1;
7154 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7157 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7158 ret = flow_dv_validate_action_push_vlan(dev,
7165 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7166 modify_after_mirror = 1;
7167 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7170 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7171 ret = flow_dv_validate_action_set_vlan_pcp
7172 (action_flags, actions, error);
7175 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7176 modify_after_mirror = 1;
7177 /* Count PCP with push_vlan command. */
7178 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
7180 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7181 ret = flow_dv_validate_action_set_vlan_vid
7182 (item_flags, action_flags,
7186 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7187 modify_after_mirror = 1;
7188 /* Count VID with push_vlan command. */
7189 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7190 rw_act_num += MLX5_ACT_NUM_MDF_VID;
7192 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7193 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7194 ret = flow_dv_validate_action_l2_encap(dev,
7200 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7203 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7204 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7205 ret = flow_dv_validate_action_decap(dev, action_flags,
7206 actions, item_flags,
7210 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7211 modify_after_mirror = 1;
7212 action_flags |= MLX5_FLOW_ACTION_DECAP;
7215 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7216 ret = flow_dv_validate_action_raw_encap_decap
7217 (dev, NULL, actions->conf, attr, &action_flags,
7218 &actions_n, actions, item_flags, error);
7222 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7223 decap = actions->conf;
7224 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
7226 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7230 encap = actions->conf;
7232 ret = flow_dv_validate_action_raw_encap_decap
7234 decap ? decap : &empty_decap, encap,
7235 attr, &action_flags, &actions_n,
7236 actions, item_flags, error);
7239 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7240 (action_flags & MLX5_FLOW_ACTION_DECAP))
7241 modify_after_mirror = 1;
7243 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7244 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7245 ret = flow_dv_validate_action_modify_mac(action_flags,
7251 /* Count all modify-header actions as one action. */
7252 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7254 action_flags |= actions->type ==
7255 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7256 MLX5_FLOW_ACTION_SET_MAC_SRC :
7257 MLX5_FLOW_ACTION_SET_MAC_DST;
7258 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7259 modify_after_mirror = 1;
7261 * Even if the source and destination MAC addresses have
7262 * overlap in the header with 4B alignment, the convert
7263 * function will handle them separately and 4 SW actions
7264 * will be created. And 2 actions will be added each
7265 * time no matter how many bytes of address will be set.
7267 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
7269 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7270 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7271 ret = flow_dv_validate_action_modify_ipv4(action_flags,
7277 /* Count all modify-header actions as one action. */
7278 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7280 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7281 modify_after_mirror = 1;
7282 action_flags |= actions->type ==
7283 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7284 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7285 MLX5_FLOW_ACTION_SET_IPV4_DST;
7286 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
7288 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7289 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7290 ret = flow_dv_validate_action_modify_ipv6(action_flags,
7296 if (item_ipv6_proto == IPPROTO_ICMPV6)
7297 return rte_flow_error_set(error, ENOTSUP,
7298 RTE_FLOW_ERROR_TYPE_ACTION,
7300 "Can't change header "
7301 "with ICMPv6 proto");
7302 /* Count all modify-header actions as one action. */
7303 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7305 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7306 modify_after_mirror = 1;
7307 action_flags |= actions->type ==
7308 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7309 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7310 MLX5_FLOW_ACTION_SET_IPV6_DST;
7311 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
7313 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7314 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7315 ret = flow_dv_validate_action_modify_tp(action_flags,
7321 /* Count all modify-header actions as one action. */
7322 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7324 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7325 modify_after_mirror = 1;
7326 action_flags |= actions->type ==
7327 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7328 MLX5_FLOW_ACTION_SET_TP_SRC :
7329 MLX5_FLOW_ACTION_SET_TP_DST;
7330 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
7332 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7333 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7334 ret = flow_dv_validate_action_modify_ttl(action_flags,
7340 /* Count all modify-header actions as one action. */
7341 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7343 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7344 modify_after_mirror = 1;
7345 action_flags |= actions->type ==
7346 RTE_FLOW_ACTION_TYPE_SET_TTL ?
7347 MLX5_FLOW_ACTION_SET_TTL :
7348 MLX5_FLOW_ACTION_DEC_TTL;
7349 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
7351 case RTE_FLOW_ACTION_TYPE_JUMP:
7352 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
7358 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7360 return rte_flow_error_set(error, EINVAL,
7361 RTE_FLOW_ERROR_TYPE_ACTION,
7363 "sample and jump action combination is not supported");
7365 action_flags |= MLX5_FLOW_ACTION_JUMP;
7367 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7368 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7369 ret = flow_dv_validate_action_modify_tcp_seq
7376 /* Count all modify-header actions as one action. */
7377 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7379 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7380 modify_after_mirror = 1;
7381 action_flags |= actions->type ==
7382 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7383 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7384 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7385 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
7387 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7388 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7389 ret = flow_dv_validate_action_modify_tcp_ack
7396 /* Count all modify-header actions as one action. */
7397 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7399 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7400 modify_after_mirror = 1;
7401 action_flags |= actions->type ==
7402 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7403 MLX5_FLOW_ACTION_INC_TCP_ACK :
7404 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7405 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
7407 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7409 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7410 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7411 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7413 case RTE_FLOW_ACTION_TYPE_METER:
7414 ret = mlx5_flow_validate_action_meter(dev,
7421 action_flags |= MLX5_FLOW_ACTION_METER;
7424 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
7426 /* Meter action will add one more TAG action. */
7427 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7429 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
7430 if (!attr->transfer && !attr->group)
7431 return rte_flow_error_set(error, ENOTSUP,
7432 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7434 "Shared ASO age action is not supported for group 0");
7435 if (action_flags & MLX5_FLOW_ACTION_AGE)
7436 return rte_flow_error_set
7438 RTE_FLOW_ERROR_TYPE_ACTION,
7440 "duplicate age actions set");
7441 action_flags |= MLX5_FLOW_ACTION_AGE;
7444 case RTE_FLOW_ACTION_TYPE_AGE:
7445 ret = flow_dv_validate_action_age(action_flags,
7451 * Validate the regular AGE action (using counter)
7452 * mutual exclusion with share counter actions.
7454 if (!priv->sh->flow_hit_aso_en) {
7456 return rte_flow_error_set
7458 RTE_FLOW_ERROR_TYPE_ACTION,
7460 "old age and shared count combination is not supported");
7462 return rte_flow_error_set
7464 RTE_FLOW_ERROR_TYPE_ACTION,
7466 "old age action and count must be in the same sub flow");
7468 action_flags |= MLX5_FLOW_ACTION_AGE;
7471 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7472 ret = flow_dv_validate_action_modify_ipv4_dscp
7479 /* Count all modify-header actions as one action. */
7480 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7482 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7483 modify_after_mirror = 1;
7484 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7485 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7487 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7488 ret = flow_dv_validate_action_modify_ipv6_dscp
7495 /* Count all modify-header actions as one action. */
7496 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7498 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7499 modify_after_mirror = 1;
7500 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7501 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7503 case RTE_FLOW_ACTION_TYPE_SAMPLE:
7504 ret = flow_dv_validate_action_sample(&action_flags,
7513 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
7516 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7517 ret = flow_dv_validate_action_modify_field(dev,
7524 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7525 modify_after_mirror = 1;
7526 /* Count all modify-header actions as one action. */
7527 if (!(action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD))
7529 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
7532 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7533 ret = flow_dv_validate_action_aso_ct(dev, action_flags,
7538 action_flags |= MLX5_FLOW_ACTION_CT;
7540 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
7541 /* tunnel offload action was processed before
7542 * list it here as a supported type
7546 return rte_flow_error_set(error, ENOTSUP,
7547 RTE_FLOW_ERROR_TYPE_ACTION,
7549 "action not supported");
7553 * Validate actions in flow rules
7554 * - Explicit decap action is prohibited by the tunnel offload API.
7555 * - Drop action in tunnel steer rule is prohibited by the API.
7556 * - Application cannot use MARK action because it's value can mask
7557 * tunnel default miss nitification.
7558 * - JUMP in tunnel match rule has no support in current PMD
7560 * - TAG & META are reserved for future uses.
7562 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
7563 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
7564 MLX5_FLOW_ACTION_MARK |
7565 MLX5_FLOW_ACTION_SET_TAG |
7566 MLX5_FLOW_ACTION_SET_META |
7567 MLX5_FLOW_ACTION_DROP;
7569 if (action_flags & bad_actions_mask)
7570 return rte_flow_error_set
7572 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7573 "Invalid RTE action in tunnel "
7575 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
7576 return rte_flow_error_set
7578 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7579 "tunnel set decap rule must terminate "
7582 return rte_flow_error_set
7584 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7585 "tunnel flows for ingress traffic only");
7587 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
7588 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
7589 MLX5_FLOW_ACTION_MARK |
7590 MLX5_FLOW_ACTION_SET_TAG |
7591 MLX5_FLOW_ACTION_SET_META;
7593 if (action_flags & bad_actions_mask)
7594 return rte_flow_error_set
7596 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7597 "Invalid RTE action in tunnel "
7601 * Validate the drop action mutual exclusion with other actions.
7602 * Drop action is mutually-exclusive with any other action, except for
7604 * Drop action compatibility with tunnel offload was already validated.
7606 if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
7607 MLX5_FLOW_ACTION_TUNNEL_MATCH));
7608 else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
7609 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
7610 return rte_flow_error_set(error, EINVAL,
7611 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7612 "Drop action is mutually-exclusive "
7613 "with any other action, except for "
7615 /* Eswitch has few restrictions on using items and actions */
7616 if (attr->transfer) {
7617 if (!mlx5_flow_ext_mreg_supported(dev) &&
7618 action_flags & MLX5_FLOW_ACTION_FLAG)
7619 return rte_flow_error_set(error, ENOTSUP,
7620 RTE_FLOW_ERROR_TYPE_ACTION,
7622 "unsupported action FLAG");
7623 if (!mlx5_flow_ext_mreg_supported(dev) &&
7624 action_flags & MLX5_FLOW_ACTION_MARK)
7625 return rte_flow_error_set(error, ENOTSUP,
7626 RTE_FLOW_ERROR_TYPE_ACTION,
7628 "unsupported action MARK");
7629 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
7630 return rte_flow_error_set(error, ENOTSUP,
7631 RTE_FLOW_ERROR_TYPE_ACTION,
7633 "unsupported action QUEUE");
7634 if (action_flags & MLX5_FLOW_ACTION_RSS)
7635 return rte_flow_error_set(error, ENOTSUP,
7636 RTE_FLOW_ERROR_TYPE_ACTION,
7638 "unsupported action RSS");
7639 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
7640 return rte_flow_error_set(error, EINVAL,
7641 RTE_FLOW_ERROR_TYPE_ACTION,
7643 "no fate action is found");
7645 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
7646 return rte_flow_error_set(error, EINVAL,
7647 RTE_FLOW_ERROR_TYPE_ACTION,
7649 "no fate action is found");
7652 * Continue validation for Xcap and VLAN actions.
7653 * If hairpin is working in explicit TX rule mode, there is no actions
7654 * splitting and the validation of hairpin ingress flow should be the
7655 * same as other standard flows.
7657 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
7658 MLX5_FLOW_VLAN_ACTIONS)) &&
7659 (queue_index == 0xFFFF ||
7660 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN ||
7661 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
7662 conf->tx_explicit != 0))) {
7663 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
7664 MLX5_FLOW_XCAP_ACTIONS)
7665 return rte_flow_error_set(error, ENOTSUP,
7666 RTE_FLOW_ERROR_TYPE_ACTION,
7667 NULL, "encap and decap "
7668 "combination aren't supported");
7669 if (!attr->transfer && attr->ingress) {
7670 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7671 return rte_flow_error_set
7673 RTE_FLOW_ERROR_TYPE_ACTION,
7674 NULL, "encap is not supported"
7675 " for ingress traffic");
7676 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7677 return rte_flow_error_set
7679 RTE_FLOW_ERROR_TYPE_ACTION,
7680 NULL, "push VLAN action not "
7681 "supported for ingress");
7682 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
7683 MLX5_FLOW_VLAN_ACTIONS)
7684 return rte_flow_error_set
7686 RTE_FLOW_ERROR_TYPE_ACTION,
7687 NULL, "no support for "
7688 "multiple VLAN actions");
7691 if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
7692 if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
7693 ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
7695 return rte_flow_error_set
7697 RTE_FLOW_ERROR_TYPE_ACTION,
7698 NULL, "fate action not supported for "
7699 "meter with policy");
7701 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
7702 return rte_flow_error_set
7704 RTE_FLOW_ERROR_TYPE_ACTION,
7705 NULL, "modify header action in egress "
7706 "cannot be done before meter action");
7707 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7708 return rte_flow_error_set
7710 RTE_FLOW_ERROR_TYPE_ACTION,
7711 NULL, "encap action in egress "
7712 "cannot be done before meter action");
7713 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7714 return rte_flow_error_set
7716 RTE_FLOW_ERROR_TYPE_ACTION,
7717 NULL, "push vlan action in egress "
7718 "cannot be done before meter action");
7722 * Hairpin flow will add one more TAG action in TX implicit mode.
7723 * In TX explicit mode, there will be no hairpin flow ID.
7726 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7727 /* extra metadata enabled: one more TAG action will be add. */
7728 if (dev_conf->dv_flow_en &&
7729 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
7730 mlx5_flow_ext_mreg_supported(dev))
7731 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7733 flow_dv_modify_hdr_action_max(dev, is_root)) {
7734 return rte_flow_error_set(error, ENOTSUP,
7735 RTE_FLOW_ERROR_TYPE_ACTION,
7736 NULL, "too many header modify"
7737 " actions to support");
7739 /* Eswitch egress mirror and modify flow has limitation on CX5 */
7740 if (fdb_mirror_limit && modify_after_mirror)
7741 return rte_flow_error_set(error, EINVAL,
7742 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7743 "sample before modify action is not supported");
7748 * Internal preparation function. Allocates the DV flow size,
7749 * this size is constant.
7752 * Pointer to the rte_eth_dev structure.
7754 * Pointer to the flow attributes.
7756 * Pointer to the list of items.
7757 * @param[in] actions
7758 * Pointer to the list of actions.
7760 * Pointer to the error structure.
7763 * Pointer to mlx5_flow object on success,
7764 * otherwise NULL and rte_errno is set.
7766 static struct mlx5_flow *
7767 flow_dv_prepare(struct rte_eth_dev *dev,
7768 const struct rte_flow_attr *attr __rte_unused,
7769 const struct rte_flow_item items[] __rte_unused,
7770 const struct rte_flow_action actions[] __rte_unused,
7771 struct rte_flow_error *error)
7773 uint32_t handle_idx = 0;
7774 struct mlx5_flow *dev_flow;
7775 struct mlx5_flow_handle *dev_handle;
7776 struct mlx5_priv *priv = dev->data->dev_private;
7777 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
7780 wks->skip_matcher_reg = 0;
7781 /* In case of corrupting the memory. */
7782 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
7783 rte_flow_error_set(error, ENOSPC,
7784 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7785 "not free temporary device flow");
7788 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
7791 rte_flow_error_set(error, ENOMEM,
7792 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7793 "not enough memory to create flow handle");
7796 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
7797 dev_flow = &wks->flows[wks->flow_idx++];
7798 memset(dev_flow, 0, sizeof(*dev_flow));
7799 dev_flow->handle = dev_handle;
7800 dev_flow->handle_idx = handle_idx;
7802 * In some old rdma-core releases, before continuing, a check of the
7803 * length of matching parameter will be done at first. It needs to use
7804 * the length without misc4 param. If the flow has misc4 support, then
7805 * the length needs to be adjusted accordingly. Each param member is
7806 * aligned with a 64B boundary naturally.
7808 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param) -
7809 MLX5_ST_SZ_BYTES(fte_match_set_misc4);
7810 dev_flow->ingress = attr->ingress;
7811 dev_flow->dv.transfer = attr->transfer;
7815 #ifdef RTE_LIBRTE_MLX5_DEBUG
7817 * Sanity check for match mask and value. Similar to check_valid_spec() in
7818 * kernel driver. If unmasked bit is present in value, it returns failure.
7821 * pointer to match mask buffer.
7822 * @param match_value
7823 * pointer to match value buffer.
7826 * 0 if valid, -EINVAL otherwise.
7829 flow_dv_check_valid_spec(void *match_mask, void *match_value)
7831 uint8_t *m = match_mask;
7832 uint8_t *v = match_value;
7835 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
7838 "match_value differs from match_criteria"
7839 " %p[%u] != %p[%u]",
7840 match_value, i, match_mask, i);
7849 * Add match of ip_version.
7853 * @param[in] headers_v
7854 * Values header pointer.
7855 * @param[in] headers_m
7856 * Masks header pointer.
7857 * @param[in] ip_version
7858 * The IP version to set.
7861 flow_dv_set_match_ip_version(uint32_t group,
7867 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
7869 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
7871 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
7872 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
7873 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
7877 * Add Ethernet item to matcher and to the value.
7879 * @param[in, out] matcher
7881 * @param[in, out] key
7882 * Flow matcher value.
7884 * Flow pattern to translate.
7886 * Item is inner pattern.
7889 flow_dv_translate_item_eth(void *matcher, void *key,
7890 const struct rte_flow_item *item, int inner,
7893 const struct rte_flow_item_eth *eth_m = item->mask;
7894 const struct rte_flow_item_eth *eth_v = item->spec;
7895 const struct rte_flow_item_eth nic_mask = {
7896 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
7897 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
7898 .type = RTE_BE16(0xffff),
7911 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
7913 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7915 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
7917 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7919 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
7920 ð_m->dst, sizeof(eth_m->dst));
7921 /* The value must be in the range of the mask. */
7922 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
7923 for (i = 0; i < sizeof(eth_m->dst); ++i)
7924 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
7925 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
7926 ð_m->src, sizeof(eth_m->src));
7927 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
7928 /* The value must be in the range of the mask. */
7929 for (i = 0; i < sizeof(eth_m->dst); ++i)
7930 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
7932 * HW supports match on one Ethertype, the Ethertype following the last
7933 * VLAN tag of the packet (see PRM).
7934 * Set match on ethertype only if ETH header is not followed by VLAN.
7935 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
7936 * ethertype, and use ip_version field instead.
7937 * eCPRI over Ether layer will use type value 0xAEFE.
7939 if (eth_m->type == 0xFFFF) {
7940 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
7941 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
7942 switch (eth_v->type) {
7943 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
7944 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
7946 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
7947 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
7948 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
7950 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
7951 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
7953 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
7954 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
7960 if (eth_m->has_vlan) {
7961 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
7962 if (eth_v->has_vlan) {
7964 * Here, when also has_more_vlan field in VLAN item is
7965 * not set, only single-tagged packets will be matched.
7967 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
7971 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
7972 rte_be_to_cpu_16(eth_m->type));
7973 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
7974 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
7978 * Add VLAN item to matcher and to the value.
7980 * @param[in, out] dev_flow
7982 * @param[in, out] matcher
7984 * @param[in, out] key
7985 * Flow matcher value.
7987 * Flow pattern to translate.
7989 * Item is inner pattern.
7992 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
7993 void *matcher, void *key,
7994 const struct rte_flow_item *item,
7995 int inner, uint32_t group)
7997 const struct rte_flow_item_vlan *vlan_m = item->mask;
7998 const struct rte_flow_item_vlan *vlan_v = item->spec;
8005 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8007 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8009 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8011 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8013 * This is workaround, masks are not supported,
8014 * and pre-validated.
8017 dev_flow->handle->vf_vlan.tag =
8018 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
8021 * When VLAN item exists in flow, mark packet as tagged,
8022 * even if TCI is not specified.
8024 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
8025 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8026 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8031 vlan_m = &rte_flow_item_vlan_mask;
8032 tci_m = rte_be_to_cpu_16(vlan_m->tci);
8033 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
8034 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
8035 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
8036 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
8037 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
8038 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
8039 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
8041 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8042 * ethertype, and use ip_version field instead.
8044 if (vlan_m->inner_type == 0xFFFF) {
8045 switch (vlan_v->inner_type) {
8046 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8047 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8048 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8049 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8051 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8052 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8054 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8055 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8061 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
8062 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8063 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8064 /* Only one vlan_tag bit can be set. */
8065 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8068 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8069 rte_be_to_cpu_16(vlan_m->inner_type));
8070 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
8071 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
8075 * Add IPV4 item to matcher and to the value.
8077 * @param[in, out] matcher
8079 * @param[in, out] key
8080 * Flow matcher value.
8082 * Flow pattern to translate.
8084 * Item is inner pattern.
8086 * The group to insert the rule.
8089 flow_dv_translate_item_ipv4(void *matcher, void *key,
8090 const struct rte_flow_item *item,
8091 int inner, uint32_t group)
8093 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
8094 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
8095 const struct rte_flow_item_ipv4 nic_mask = {
8097 .src_addr = RTE_BE32(0xffffffff),
8098 .dst_addr = RTE_BE32(0xffffffff),
8099 .type_of_service = 0xff,
8100 .next_proto_id = 0xff,
8101 .time_to_live = 0xff,
8111 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8113 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8115 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8117 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8119 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
8124 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8125 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8126 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8127 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8128 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
8129 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
8130 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8131 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8132 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8133 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8134 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
8135 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
8136 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
8137 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
8138 ipv4_m->hdr.type_of_service);
8139 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
8140 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
8141 ipv4_m->hdr.type_of_service >> 2);
8142 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
8143 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8144 ipv4_m->hdr.next_proto_id);
8145 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8146 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
8147 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8148 ipv4_m->hdr.time_to_live);
8149 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8150 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
8151 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8152 !!(ipv4_m->hdr.fragment_offset));
8153 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8154 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
8158 * Add IPV6 item to matcher and to the value.
8160 * @param[in, out] matcher
8162 * @param[in, out] key
8163 * Flow matcher value.
8165 * Flow pattern to translate.
8167 * Item is inner pattern.
8169 * The group to insert the rule.
8172 flow_dv_translate_item_ipv6(void *matcher, void *key,
8173 const struct rte_flow_item *item,
8174 int inner, uint32_t group)
8176 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
8177 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
8178 const struct rte_flow_item_ipv6 nic_mask = {
8181 "\xff\xff\xff\xff\xff\xff\xff\xff"
8182 "\xff\xff\xff\xff\xff\xff\xff\xff",
8184 "\xff\xff\xff\xff\xff\xff\xff\xff"
8185 "\xff\xff\xff\xff\xff\xff\xff\xff",
8186 .vtc_flow = RTE_BE32(0xffffffff),
8193 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8194 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8203 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8205 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8207 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8209 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8211 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
8216 size = sizeof(ipv6_m->hdr.dst_addr);
8217 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8218 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8219 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8220 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8221 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
8222 for (i = 0; i < size; ++i)
8223 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
8224 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8225 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8226 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8227 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8228 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
8229 for (i = 0; i < size; ++i)
8230 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
8232 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
8233 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
8234 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
8235 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
8236 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
8237 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
8240 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
8242 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
8245 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
8247 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
8251 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8253 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8254 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
8256 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8257 ipv6_m->hdr.hop_limits);
8258 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8259 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
8260 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8261 !!(ipv6_m->has_frag_ext));
8262 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8263 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
8267 * Add IPV6 fragment extension item to matcher and to the value.
8269 * @param[in, out] matcher
8271 * @param[in, out] key
8272 * Flow matcher value.
8274 * Flow pattern to translate.
8276 * Item is inner pattern.
8279 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
8280 const struct rte_flow_item *item,
8283 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
8284 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
8285 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
8287 .next_header = 0xff,
8288 .frag_data = RTE_BE16(0xffff),
8295 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8297 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8299 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8301 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8303 /* IPv6 fragment extension item exists, so packet is IP fragment. */
8304 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
8305 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
8306 if (!ipv6_frag_ext_v)
8308 if (!ipv6_frag_ext_m)
8309 ipv6_frag_ext_m = &nic_mask;
8310 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8311 ipv6_frag_ext_m->hdr.next_header);
8312 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8313 ipv6_frag_ext_v->hdr.next_header &
8314 ipv6_frag_ext_m->hdr.next_header);
8318 * Add TCP item to matcher and to the value.
8320 * @param[in, out] matcher
8322 * @param[in, out] key
8323 * Flow matcher value.
8325 * Flow pattern to translate.
8327 * Item is inner pattern.
8330 flow_dv_translate_item_tcp(void *matcher, void *key,
8331 const struct rte_flow_item *item,
8334 const struct rte_flow_item_tcp *tcp_m = item->mask;
8335 const struct rte_flow_item_tcp *tcp_v = item->spec;
8340 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8342 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8344 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8346 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8348 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8349 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
8353 tcp_m = &rte_flow_item_tcp_mask;
8354 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
8355 rte_be_to_cpu_16(tcp_m->hdr.src_port));
8356 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
8357 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
8358 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
8359 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
8360 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
8361 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
8362 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
8363 tcp_m->hdr.tcp_flags);
8364 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
8365 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
8369 * Add UDP item to matcher and to the value.
8371 * @param[in, out] matcher
8373 * @param[in, out] key
8374 * Flow matcher value.
8376 * Flow pattern to translate.
8378 * Item is inner pattern.
8381 flow_dv_translate_item_udp(void *matcher, void *key,
8382 const struct rte_flow_item *item,
8385 const struct rte_flow_item_udp *udp_m = item->mask;
8386 const struct rte_flow_item_udp *udp_v = item->spec;
8391 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8393 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8395 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8397 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8399 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8400 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
8404 udp_m = &rte_flow_item_udp_mask;
8405 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
8406 rte_be_to_cpu_16(udp_m->hdr.src_port));
8407 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
8408 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
8409 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
8410 rte_be_to_cpu_16(udp_m->hdr.dst_port));
8411 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8412 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
8416 * Add GRE optional Key item to matcher and to the value.
8418 * @param[in, out] matcher
8420 * @param[in, out] key
8421 * Flow matcher value.
8423 * Flow pattern to translate.
8425 * Item is inner pattern.
8428 flow_dv_translate_item_gre_key(void *matcher, void *key,
8429 const struct rte_flow_item *item)
8431 const rte_be32_t *key_m = item->mask;
8432 const rte_be32_t *key_v = item->spec;
8433 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8434 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8435 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
8437 /* GRE K bit must be on and should already be validated */
8438 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
8439 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
8443 key_m = &gre_key_default_mask;
8444 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
8445 rte_be_to_cpu_32(*key_m) >> 8);
8446 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
8447 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
8448 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
8449 rte_be_to_cpu_32(*key_m) & 0xFF);
8450 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
8451 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
8455 * Add GRE item to matcher and to the value.
8457 * @param[in, out] matcher
8459 * @param[in, out] key
8460 * Flow matcher value.
8462 * Flow pattern to translate.
8464 * Item is inner pattern.
8467 flow_dv_translate_item_gre(void *matcher, void *key,
8468 const struct rte_flow_item *item,
8471 const struct rte_flow_item_gre *gre_m = item->mask;
8472 const struct rte_flow_item_gre *gre_v = item->spec;
8475 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8476 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8483 uint16_t s_present:1;
8484 uint16_t k_present:1;
8485 uint16_t rsvd_bit1:1;
8486 uint16_t c_present:1;
8490 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
8493 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8495 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8497 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8499 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8501 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8502 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
8506 gre_m = &rte_flow_item_gre_mask;
8507 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
8508 rte_be_to_cpu_16(gre_m->protocol));
8509 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8510 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
8511 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
8512 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
8513 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
8514 gre_crks_rsvd0_ver_m.c_present);
8515 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
8516 gre_crks_rsvd0_ver_v.c_present &
8517 gre_crks_rsvd0_ver_m.c_present);
8518 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
8519 gre_crks_rsvd0_ver_m.k_present);
8520 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
8521 gre_crks_rsvd0_ver_v.k_present &
8522 gre_crks_rsvd0_ver_m.k_present);
8523 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
8524 gre_crks_rsvd0_ver_m.s_present);
8525 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
8526 gre_crks_rsvd0_ver_v.s_present &
8527 gre_crks_rsvd0_ver_m.s_present);
8531 * Add NVGRE item to matcher and to the value.
8533 * @param[in, out] matcher
8535 * @param[in, out] key
8536 * Flow matcher value.
8538 * Flow pattern to translate.
8540 * Item is inner pattern.
8543 flow_dv_translate_item_nvgre(void *matcher, void *key,
8544 const struct rte_flow_item *item,
8547 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
8548 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
8549 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8550 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8551 const char *tni_flow_id_m;
8552 const char *tni_flow_id_v;
8558 /* For NVGRE, GRE header fields must be set with defined values. */
8559 const struct rte_flow_item_gre gre_spec = {
8560 .c_rsvd0_ver = RTE_BE16(0x2000),
8561 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
8563 const struct rte_flow_item_gre gre_mask = {
8564 .c_rsvd0_ver = RTE_BE16(0xB000),
8565 .protocol = RTE_BE16(UINT16_MAX),
8567 const struct rte_flow_item gre_item = {
8572 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
8576 nvgre_m = &rte_flow_item_nvgre_mask;
8577 tni_flow_id_m = (const char *)nvgre_m->tni;
8578 tni_flow_id_v = (const char *)nvgre_v->tni;
8579 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
8580 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
8581 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
8582 memcpy(gre_key_m, tni_flow_id_m, size);
8583 for (i = 0; i < size; ++i)
8584 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
8588 * Add VXLAN item to matcher and to the value.
8590 * @param[in, out] matcher
8592 * @param[in, out] key
8593 * Flow matcher value.
8595 * Flow pattern to translate.
8597 * Item is inner pattern.
8600 flow_dv_translate_item_vxlan(void *matcher, void *key,
8601 const struct rte_flow_item *item,
8604 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
8605 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
8608 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8609 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8617 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8619 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8621 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8623 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8625 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8626 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8627 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8628 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8629 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8634 vxlan_m = &rte_flow_item_vxlan_mask;
8635 size = sizeof(vxlan_m->vni);
8636 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
8637 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
8638 memcpy(vni_m, vxlan_m->vni, size);
8639 for (i = 0; i < size; ++i)
8640 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8644 * Add VXLAN-GPE item to matcher and to the value.
8646 * @param[in, out] matcher
8648 * @param[in, out] key
8649 * Flow matcher value.
8651 * Flow pattern to translate.
8653 * Item is inner pattern.
8657 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
8658 const struct rte_flow_item *item, int inner)
8660 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
8661 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
8665 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
8667 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8673 uint8_t flags_m = 0xff;
8674 uint8_t flags_v = 0xc;
8677 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8679 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8681 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8683 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8685 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8686 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8687 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8688 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8689 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8694 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
8695 size = sizeof(vxlan_m->vni);
8696 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
8697 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
8698 memcpy(vni_m, vxlan_m->vni, size);
8699 for (i = 0; i < size; ++i)
8700 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8701 if (vxlan_m->flags) {
8702 flags_m = vxlan_m->flags;
8703 flags_v = vxlan_v->flags;
8705 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
8706 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
8707 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
8709 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
8714 * Add Geneve item to matcher and to the value.
8716 * @param[in, out] matcher
8718 * @param[in, out] key
8719 * Flow matcher value.
8721 * Flow pattern to translate.
8723 * Item is inner pattern.
8727 flow_dv_translate_item_geneve(void *matcher, void *key,
8728 const struct rte_flow_item *item, int inner)
8730 const struct rte_flow_item_geneve *geneve_m = item->mask;
8731 const struct rte_flow_item_geneve *geneve_v = item->spec;
8734 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8735 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8744 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8746 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8748 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8750 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8752 dport = MLX5_UDP_PORT_GENEVE;
8753 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8754 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8755 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8760 geneve_m = &rte_flow_item_geneve_mask;
8761 size = sizeof(geneve_m->vni);
8762 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
8763 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
8764 memcpy(vni_m, geneve_m->vni, size);
8765 for (i = 0; i < size; ++i)
8766 vni_v[i] = vni_m[i] & geneve_v->vni[i];
8767 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
8768 rte_be_to_cpu_16(geneve_m->protocol));
8769 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
8770 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
8771 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
8772 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
8773 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
8774 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
8775 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
8776 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
8777 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
8778 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
8779 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
8780 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
8781 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
8785 * Create Geneve TLV option resource.
8787 * @param dev[in, out]
8788 * Pointer to rte_eth_dev structure.
8789 * @param[in, out] tag_be24
8790 * Tag value in big endian then R-shift 8.
8791 * @parm[in, out] dev_flow
8792 * Pointer to the dev_flow.
8794 * pointer to error structure.
8797 * 0 on success otherwise -errno and errno is set.
8801 flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
8802 const struct rte_flow_item *item,
8803 struct rte_flow_error *error)
8805 struct mlx5_priv *priv = dev->data->dev_private;
8806 struct mlx5_dev_ctx_shared *sh = priv->sh;
8807 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
8808 sh->geneve_tlv_option_resource;
8809 struct mlx5_devx_obj *obj;
8810 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
8815 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
8816 if (geneve_opt_resource != NULL) {
8817 if (geneve_opt_resource->option_class ==
8818 geneve_opt_v->option_class &&
8819 geneve_opt_resource->option_type ==
8820 geneve_opt_v->option_type &&
8821 geneve_opt_resource->length ==
8822 geneve_opt_v->option_len) {
8823 /* We already have GENVE TLV option obj allocated. */
8824 __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
8827 ret = rte_flow_error_set(error, ENOMEM,
8828 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8829 "Only one GENEVE TLV option supported");
8833 /* Create a GENEVE TLV object and resource. */
8834 obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->ctx,
8835 geneve_opt_v->option_class,
8836 geneve_opt_v->option_type,
8837 geneve_opt_v->option_len);
8839 ret = rte_flow_error_set(error, ENODATA,
8840 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8841 "Failed to create GENEVE TLV Devx object");
8844 sh->geneve_tlv_option_resource =
8845 mlx5_malloc(MLX5_MEM_ZERO,
8846 sizeof(*geneve_opt_resource),
8848 if (!sh->geneve_tlv_option_resource) {
8849 claim_zero(mlx5_devx_cmd_destroy(obj));
8850 ret = rte_flow_error_set(error, ENOMEM,
8851 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8852 "GENEVE TLV object memory allocation failed");
8855 geneve_opt_resource = sh->geneve_tlv_option_resource;
8856 geneve_opt_resource->obj = obj;
8857 geneve_opt_resource->option_class = geneve_opt_v->option_class;
8858 geneve_opt_resource->option_type = geneve_opt_v->option_type;
8859 geneve_opt_resource->length = geneve_opt_v->option_len;
8860 __atomic_store_n(&geneve_opt_resource->refcnt, 1,
8864 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
8869 * Add Geneve TLV option item to matcher.
8871 * @param[in, out] dev
8872 * Pointer to rte_eth_dev structure.
8873 * @param[in, out] matcher
8875 * @param[in, out] key
8876 * Flow matcher value.
8878 * Flow pattern to translate.
8880 * Pointer to error structure.
8883 flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *matcher,
8884 void *key, const struct rte_flow_item *item,
8885 struct rte_flow_error *error)
8887 const struct rte_flow_item_geneve_opt *geneve_opt_m = item->mask;
8888 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
8889 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8890 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8891 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
8893 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8894 rte_be32_t opt_data_key = 0, opt_data_mask = 0;
8900 geneve_opt_m = &rte_flow_item_geneve_opt_mask;
8901 ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
8904 DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
8908 * Set the option length in GENEVE header if not requested.
8909 * The GENEVE TLV option length is expressed by the option length field
8910 * in the GENEVE header.
8911 * If the option length was not requested but the GENEVE TLV option item
8912 * is present we set the option length field implicitly.
8914 if (!MLX5_GET16(fte_match_set_misc, misc_m, geneve_opt_len)) {
8915 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
8916 MLX5_GENEVE_OPTLEN_MASK);
8917 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
8918 geneve_opt_v->option_len + 1);
8921 if (geneve_opt_v->data) {
8922 memcpy(&opt_data_key, geneve_opt_v->data,
8923 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
8924 sizeof(opt_data_key)));
8925 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
8926 sizeof(opt_data_key));
8927 memcpy(&opt_data_mask, geneve_opt_m->data,
8928 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
8929 sizeof(opt_data_mask)));
8930 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
8931 sizeof(opt_data_mask));
8932 MLX5_SET(fte_match_set_misc3, misc3_m,
8933 geneve_tlv_option_0_data,
8934 rte_be_to_cpu_32(opt_data_mask));
8935 MLX5_SET(fte_match_set_misc3, misc3_v,
8936 geneve_tlv_option_0_data,
8937 rte_be_to_cpu_32(opt_data_key & opt_data_mask));
8943 * Add MPLS item to matcher and to the value.
8945 * @param[in, out] matcher
8947 * @param[in, out] key
8948 * Flow matcher value.
8950 * Flow pattern to translate.
8951 * @param[in] prev_layer
8952 * The protocol layer indicated in previous item.
8954 * Item is inner pattern.
8957 flow_dv_translate_item_mpls(void *matcher, void *key,
8958 const struct rte_flow_item *item,
8959 uint64_t prev_layer,
8962 const uint32_t *in_mpls_m = item->mask;
8963 const uint32_t *in_mpls_v = item->spec;
8964 uint32_t *out_mpls_m = 0;
8965 uint32_t *out_mpls_v = 0;
8966 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8967 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8968 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
8970 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
8971 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
8972 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8974 switch (prev_layer) {
8975 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
8976 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
8977 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8978 MLX5_UDP_PORT_MPLS);
8980 case MLX5_FLOW_LAYER_GRE:
8981 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
8982 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8983 RTE_ETHER_TYPE_MPLS);
8986 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8987 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8994 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
8995 switch (prev_layer) {
8996 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
8998 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
8999 outer_first_mpls_over_udp);
9001 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9002 outer_first_mpls_over_udp);
9004 case MLX5_FLOW_LAYER_GRE:
9006 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9007 outer_first_mpls_over_gre);
9009 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9010 outer_first_mpls_over_gre);
9013 /* Inner MPLS not over GRE is not supported. */
9016 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9020 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9026 if (out_mpls_m && out_mpls_v) {
9027 *out_mpls_m = *in_mpls_m;
9028 *out_mpls_v = *in_mpls_v & *in_mpls_m;
9033 * Add metadata register item to matcher
9035 * @param[in, out] matcher
9037 * @param[in, out] key
9038 * Flow matcher value.
9039 * @param[in] reg_type
9040 * Type of device metadata register
9047 flow_dv_match_meta_reg(void *matcher, void *key,
9048 enum modify_reg reg_type,
9049 uint32_t data, uint32_t mask)
9052 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
9054 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9060 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
9061 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
9064 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
9065 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
9069 * The metadata register C0 field might be divided into
9070 * source vport index and META item value, we should set
9071 * this field according to specified mask, not as whole one.
9073 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
9075 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
9076 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
9079 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
9082 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
9083 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
9086 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
9087 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
9090 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
9091 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
9094 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
9095 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
9098 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
9099 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
9102 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
9103 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
9106 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
9107 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
9116 * Add MARK item to matcher
9119 * The device to configure through.
9120 * @param[in, out] matcher
9122 * @param[in, out] key
9123 * Flow matcher value.
9125 * Flow pattern to translate.
9128 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
9129 void *matcher, void *key,
9130 const struct rte_flow_item *item)
9132 struct mlx5_priv *priv = dev->data->dev_private;
9133 const struct rte_flow_item_mark *mark;
9137 mark = item->mask ? (const void *)item->mask :
9138 &rte_flow_item_mark_mask;
9139 mask = mark->id & priv->sh->dv_mark_mask;
9140 mark = (const void *)item->spec;
9142 value = mark->id & priv->sh->dv_mark_mask & mask;
9144 enum modify_reg reg;
9146 /* Get the metadata register index for the mark. */
9147 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
9148 MLX5_ASSERT(reg > 0);
9149 if (reg == REG_C_0) {
9150 struct mlx5_priv *priv = dev->data->dev_private;
9151 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9152 uint32_t shl_c0 = rte_bsf32(msk_c0);
9158 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9163 * Add META item to matcher
9166 * The devich to configure through.
9167 * @param[in, out] matcher
9169 * @param[in, out] key
9170 * Flow matcher value.
9172 * Attributes of flow that includes this item.
9174 * Flow pattern to translate.
9177 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
9178 void *matcher, void *key,
9179 const struct rte_flow_attr *attr,
9180 const struct rte_flow_item *item)
9182 const struct rte_flow_item_meta *meta_m;
9183 const struct rte_flow_item_meta *meta_v;
9185 meta_m = (const void *)item->mask;
9187 meta_m = &rte_flow_item_meta_mask;
9188 meta_v = (const void *)item->spec;
9191 uint32_t value = meta_v->data;
9192 uint32_t mask = meta_m->data;
9194 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
9197 MLX5_ASSERT(reg != REG_NON);
9199 * In datapath code there is no endianness
9200 * coversions for perfromance reasons, all
9201 * pattern conversions are done in rte_flow.
9203 value = rte_cpu_to_be_32(value);
9204 mask = rte_cpu_to_be_32(mask);
9205 if (reg == REG_C_0) {
9206 struct mlx5_priv *priv = dev->data->dev_private;
9207 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9208 uint32_t shl_c0 = rte_bsf32(msk_c0);
9209 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
9210 uint32_t shr_c0 = __builtin_clz(priv->sh->dv_meta_mask);
9217 MLX5_ASSERT(msk_c0);
9218 MLX5_ASSERT(!(~msk_c0 & mask));
9220 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9225 * Add vport metadata Reg C0 item to matcher
9227 * @param[in, out] matcher
9229 * @param[in, out] key
9230 * Flow matcher value.
9232 * Flow pattern to translate.
9235 flow_dv_translate_item_meta_vport(void *matcher, void *key,
9236 uint32_t value, uint32_t mask)
9238 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
9242 * Add tag item to matcher
9245 * The devich to configure through.
9246 * @param[in, out] matcher
9248 * @param[in, out] key
9249 * Flow matcher value.
9251 * Flow pattern to translate.
9254 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
9255 void *matcher, void *key,
9256 const struct rte_flow_item *item)
9258 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
9259 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
9260 uint32_t mask, value;
9263 value = tag_v->data;
9264 mask = tag_m ? tag_m->data : UINT32_MAX;
9265 if (tag_v->id == REG_C_0) {
9266 struct mlx5_priv *priv = dev->data->dev_private;
9267 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9268 uint32_t shl_c0 = rte_bsf32(msk_c0);
9274 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
9278 * Add TAG item to matcher
9281 * The devich to configure through.
9282 * @param[in, out] matcher
9284 * @param[in, out] key
9285 * Flow matcher value.
9287 * Flow pattern to translate.
9290 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
9291 void *matcher, void *key,
9292 const struct rte_flow_item *item)
9294 const struct rte_flow_item_tag *tag_v = item->spec;
9295 const struct rte_flow_item_tag *tag_m = item->mask;
9296 enum modify_reg reg;
9299 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
9300 /* Get the metadata register index for the tag. */
9301 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
9302 MLX5_ASSERT(reg > 0);
9303 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
9307 * Add source vport match to the specified matcher.
9309 * @param[in, out] matcher
9311 * @param[in, out] key
9312 * Flow matcher value.
9314 * Source vport value to match
9319 flow_dv_translate_item_source_vport(void *matcher, void *key,
9320 int16_t port, uint16_t mask)
9322 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9323 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9325 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
9326 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
9330 * Translate port-id item to eswitch match on port-id.
9333 * The devich to configure through.
9334 * @param[in, out] matcher
9336 * @param[in, out] key
9337 * Flow matcher value.
9339 * Flow pattern to translate.
9344 * 0 on success, a negative errno value otherwise.
9347 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
9348 void *key, const struct rte_flow_item *item,
9349 const struct rte_flow_attr *attr)
9351 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
9352 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
9353 struct mlx5_priv *priv;
9356 mask = pid_m ? pid_m->id : 0xffff;
9357 id = pid_v ? pid_v->id : dev->data->port_id;
9358 priv = mlx5_port_to_eswitch_info(id, item == NULL);
9362 * Translate to vport field or to metadata, depending on mode.
9363 * Kernel can use either misc.source_port or half of C0 metadata
9366 if (priv->vport_meta_mask) {
9368 * Provide the hint for SW steering library
9369 * to insert the flow into ingress domain and
9370 * save the extra vport match.
9372 if (mask == 0xffff && priv->vport_id == 0xffff &&
9373 priv->pf_bond < 0 && attr->transfer)
9374 flow_dv_translate_item_source_vport
9375 (matcher, key, priv->vport_id, mask);
9377 * We should always set the vport metadata register,
9378 * otherwise the SW steering library can drop
9379 * the rule if wire vport metadata value is not zero,
9380 * it depends on kernel configuration.
9382 flow_dv_translate_item_meta_vport(matcher, key,
9383 priv->vport_meta_tag,
9384 priv->vport_meta_mask);
9386 flow_dv_translate_item_source_vport(matcher, key,
9387 priv->vport_id, mask);
9393 * Add ICMP6 item to matcher and to the value.
9395 * @param[in, out] matcher
9397 * @param[in, out] key
9398 * Flow matcher value.
9400 * Flow pattern to translate.
9402 * Item is inner pattern.
9405 flow_dv_translate_item_icmp6(void *matcher, void *key,
9406 const struct rte_flow_item *item,
9409 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
9410 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
9413 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9415 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9417 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9419 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9421 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9423 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9425 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9426 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
9430 icmp6_m = &rte_flow_item_icmp6_mask;
9431 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
9432 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
9433 icmp6_v->type & icmp6_m->type);
9434 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
9435 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
9436 icmp6_v->code & icmp6_m->code);
9440 * Add ICMP item to matcher and to the value.
9442 * @param[in, out] matcher
9444 * @param[in, out] key
9445 * Flow matcher value.
9447 * Flow pattern to translate.
9449 * Item is inner pattern.
9452 flow_dv_translate_item_icmp(void *matcher, void *key,
9453 const struct rte_flow_item *item,
9456 const struct rte_flow_item_icmp *icmp_m = item->mask;
9457 const struct rte_flow_item_icmp *icmp_v = item->spec;
9458 uint32_t icmp_header_data_m = 0;
9459 uint32_t icmp_header_data_v = 0;
9462 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9464 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9466 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9468 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9470 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9472 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9474 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9475 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
9479 icmp_m = &rte_flow_item_icmp_mask;
9480 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
9481 icmp_m->hdr.icmp_type);
9482 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
9483 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
9484 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
9485 icmp_m->hdr.icmp_code);
9486 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
9487 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
9488 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
9489 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
9490 if (icmp_header_data_m) {
9491 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
9492 icmp_header_data_v |=
9493 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
9494 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
9495 icmp_header_data_m);
9496 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
9497 icmp_header_data_v & icmp_header_data_m);
9502 * Add GTP item to matcher and to the value.
9504 * @param[in, out] matcher
9506 * @param[in, out] key
9507 * Flow matcher value.
9509 * Flow pattern to translate.
9511 * Item is inner pattern.
9514 flow_dv_translate_item_gtp(void *matcher, void *key,
9515 const struct rte_flow_item *item, int inner)
9517 const struct rte_flow_item_gtp *gtp_m = item->mask;
9518 const struct rte_flow_item_gtp *gtp_v = item->spec;
9521 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9523 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9524 uint16_t dport = RTE_GTPU_UDP_PORT;
9527 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9529 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9531 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9533 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9535 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9536 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9537 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
9542 gtp_m = &rte_flow_item_gtp_mask;
9543 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
9544 gtp_m->v_pt_rsv_flags);
9545 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
9546 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
9547 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
9548 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
9549 gtp_v->msg_type & gtp_m->msg_type);
9550 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
9551 rte_be_to_cpu_32(gtp_m->teid));
9552 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
9553 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
9557 * Add GTP PSC item to matcher.
9559 * @param[in, out] matcher
9561 * @param[in, out] key
9562 * Flow matcher value.
9564 * Flow pattern to translate.
9567 flow_dv_translate_item_gtp_psc(void *matcher, void *key,
9568 const struct rte_flow_item *item)
9570 const struct rte_flow_item_gtp_psc *gtp_psc_m = item->mask;
9571 const struct rte_flow_item_gtp_psc *gtp_psc_v = item->spec;
9572 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9574 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9580 uint8_t next_ext_header_type;
9585 /* Always set E-flag match on one, regardless of GTP item settings. */
9586 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_m, gtpu_msg_flags);
9587 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9588 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags, gtp_flags);
9589 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
9590 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9591 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
9592 /*Set next extension header type. */
9595 dw_2.next_ext_header_type = 0xff;
9596 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_dw_2,
9597 rte_cpu_to_be_32(dw_2.w32));
9600 dw_2.next_ext_header_type = 0x85;
9601 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
9602 rte_cpu_to_be_32(dw_2.w32));
9614 /*Set extension header PDU type and Qos. */
9616 gtp_psc_m = &rte_flow_item_gtp_psc_mask;
9618 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_m->pdu_type);
9619 dw_0.qfi = gtp_psc_m->qfi;
9620 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_first_ext_dw_0,
9621 rte_cpu_to_be_32(dw_0.w32));
9623 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->pdu_type &
9624 gtp_psc_m->pdu_type);
9625 dw_0.qfi = gtp_psc_v->qfi & gtp_psc_m->qfi;
9626 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
9627 rte_cpu_to_be_32(dw_0.w32));
9633 * Add eCPRI item to matcher and to the value.
9636 * The devich to configure through.
9637 * @param[in, out] matcher
9639 * @param[in, out] key
9640 * Flow matcher value.
9642 * Flow pattern to translate.
9643 * @param[in] samples
9644 * Sample IDs to be used in the matching.
9647 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
9648 void *key, const struct rte_flow_item *item)
9650 struct mlx5_priv *priv = dev->data->dev_private;
9651 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
9652 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
9653 struct rte_ecpri_common_hdr common;
9654 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
9656 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
9664 ecpri_m = &rte_flow_item_ecpri_mask;
9666 * Maximal four DW samples are supported in a single matching now.
9667 * Two are used now for a eCPRI matching:
9668 * 1. Type: one byte, mask should be 0x00ff0000 in network order
9669 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
9672 if (!ecpri_m->hdr.common.u32)
9674 samples = priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0].ids;
9675 /* Need to take the whole DW as the mask to fill the entry. */
9676 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9677 prog_sample_field_value_0);
9678 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9679 prog_sample_field_value_0);
9680 /* Already big endian (network order) in the header. */
9681 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
9682 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
9683 /* Sample#0, used for matching type, offset 0. */
9684 MLX5_SET(fte_match_set_misc4, misc4_m,
9685 prog_sample_field_id_0, samples[0]);
9686 /* It makes no sense to set the sample ID in the mask field. */
9687 MLX5_SET(fte_match_set_misc4, misc4_v,
9688 prog_sample_field_id_0, samples[0]);
9690 * Checking if message body part needs to be matched.
9691 * Some wildcard rules only matching type field should be supported.
9693 if (ecpri_m->hdr.dummy[0]) {
9694 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
9695 switch (common.type) {
9696 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
9697 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
9698 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
9699 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9700 prog_sample_field_value_1);
9701 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9702 prog_sample_field_value_1);
9703 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
9704 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
9705 ecpri_m->hdr.dummy[0];
9706 /* Sample#1, to match message body, offset 4. */
9707 MLX5_SET(fte_match_set_misc4, misc4_m,
9708 prog_sample_field_id_1, samples[1]);
9709 MLX5_SET(fte_match_set_misc4, misc4_v,
9710 prog_sample_field_id_1, samples[1]);
9713 /* Others, do not match any sample ID. */
9720 * Add connection tracking status item to matcher
9723 * The devich to configure through.
9724 * @param[in, out] matcher
9726 * @param[in, out] key
9727 * Flow matcher value.
9729 * Flow pattern to translate.
9732 flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
9733 void *matcher, void *key,
9734 const struct rte_flow_item *item)
9736 uint32_t reg_value = 0;
9738 /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
9739 uint32_t reg_mask = 0;
9740 const struct rte_flow_item_conntrack *spec = item->spec;
9741 const struct rte_flow_item_conntrack *mask = item->mask;
9743 struct rte_flow_error error;
9746 mask = &rte_flow_item_conntrack_mask;
9747 if (!spec || !mask->flags)
9749 flags = spec->flags & mask->flags;
9750 /* The conflict should be checked in the validation. */
9751 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
9752 reg_value |= MLX5_CT_SYNDROME_VALID;
9753 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
9754 reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
9755 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
9756 reg_value |= MLX5_CT_SYNDROME_INVALID;
9757 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
9758 reg_value |= MLX5_CT_SYNDROME_TRAP;
9759 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
9760 reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
9761 if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
9762 RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
9763 RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
9765 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
9766 reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
9767 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
9768 reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
9769 /* The REG_C_x value could be saved during startup. */
9770 reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
9771 if (reg_id == REG_NON)
9773 flow_dv_match_meta_reg(matcher, key, (enum modify_reg)reg_id,
9774 reg_value, reg_mask);
9777 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
9779 #define HEADER_IS_ZERO(match_criteria, headers) \
9780 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
9781 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
9784 * Calculate flow matcher enable bitmap.
9786 * @param match_criteria
9787 * Pointer to flow matcher criteria.
9790 * Bitmap of enabled fields.
9793 flow_dv_matcher_enable(uint32_t *match_criteria)
9795 uint8_t match_criteria_enable;
9797 match_criteria_enable =
9798 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
9799 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
9800 match_criteria_enable |=
9801 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
9802 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
9803 match_criteria_enable |=
9804 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
9805 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
9806 match_criteria_enable |=
9807 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
9808 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
9809 match_criteria_enable |=
9810 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
9811 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
9812 match_criteria_enable |=
9813 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
9814 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
9815 return match_criteria_enable;
9818 struct mlx5_hlist_entry *
9819 flow_dv_tbl_create_cb(struct mlx5_hlist *list, uint64_t key64, void *cb_ctx)
9821 struct mlx5_dev_ctx_shared *sh = list->ctx;
9822 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9823 struct rte_eth_dev *dev = ctx->dev;
9824 struct mlx5_flow_tbl_data_entry *tbl_data;
9825 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data;
9826 struct rte_flow_error *error = ctx->error;
9827 union mlx5_flow_tbl_key key = { .v64 = key64 };
9828 struct mlx5_flow_tbl_resource *tbl;
9833 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
9835 rte_flow_error_set(error, ENOMEM,
9836 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9838 "cannot allocate flow table data entry");
9841 tbl_data->idx = idx;
9842 tbl_data->tunnel = tt_prm->tunnel;
9843 tbl_data->group_id = tt_prm->group_id;
9844 tbl_data->external = !!tt_prm->external;
9845 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
9846 tbl_data->is_egress = !!key.is_egress;
9847 tbl_data->is_transfer = !!key.is_fdb;
9848 tbl_data->dummy = !!key.dummy;
9849 tbl_data->level = key.level;
9850 tbl_data->id = key.id;
9851 tbl = &tbl_data->tbl;
9853 return &tbl_data->entry;
9855 domain = sh->fdb_domain;
9856 else if (key.is_egress)
9857 domain = sh->tx_domain;
9859 domain = sh->rx_domain;
9860 ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
9862 rte_flow_error_set(error, ENOMEM,
9863 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9864 NULL, "cannot create flow table object");
9865 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
9868 if (key.level != 0) {
9869 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
9870 (tbl->obj, &tbl_data->jump.action);
9872 rte_flow_error_set(error, ENOMEM,
9873 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9875 "cannot create flow jump action");
9876 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
9877 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
9881 MKSTR(matcher_name, "%s_%s_%u_%u_matcher_cache",
9882 key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
9884 mlx5_cache_list_init(&tbl_data->matchers, matcher_name, 0, sh,
9885 flow_dv_matcher_create_cb,
9886 flow_dv_matcher_match_cb,
9887 flow_dv_matcher_remove_cb);
9888 return &tbl_data->entry;
9892 flow_dv_tbl_match_cb(struct mlx5_hlist *list __rte_unused,
9893 struct mlx5_hlist_entry *entry, uint64_t key64,
9894 void *cb_ctx __rte_unused)
9896 struct mlx5_flow_tbl_data_entry *tbl_data =
9897 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
9898 union mlx5_flow_tbl_key key = { .v64 = key64 };
9900 return tbl_data->level != key.level ||
9901 tbl_data->id != key.id ||
9902 tbl_data->dummy != key.dummy ||
9903 tbl_data->is_transfer != !!key.is_fdb ||
9904 tbl_data->is_egress != !!key.is_egress;
9910 * @param[in, out] dev
9911 * Pointer to rte_eth_dev structure.
9912 * @param[in] table_level
9913 * Table level to use.
9915 * Direction of the table.
9916 * @param[in] transfer
9917 * E-Switch or NIC flow.
9919 * Dummy entry for dv API.
9920 * @param[in] table_id
9923 * pointer to error structure.
9926 * Returns tables resource based on the index, NULL in case of failed.
9928 struct mlx5_flow_tbl_resource *
9929 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
9930 uint32_t table_level, uint8_t egress,
9933 const struct mlx5_flow_tunnel *tunnel,
9934 uint32_t group_id, uint8_t dummy,
9936 struct rte_flow_error *error)
9938 struct mlx5_priv *priv = dev->data->dev_private;
9939 union mlx5_flow_tbl_key table_key = {
9941 .level = table_level,
9945 .is_fdb = !!transfer,
9946 .is_egress = !!egress,
9949 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
9951 .group_id = group_id,
9952 .external = external,
9954 struct mlx5_flow_cb_ctx ctx = {
9959 struct mlx5_hlist_entry *entry;
9960 struct mlx5_flow_tbl_data_entry *tbl_data;
9962 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
9964 rte_flow_error_set(error, ENOMEM,
9965 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9966 "cannot get table");
9969 DRV_LOG(DEBUG, "table_level %u table_id %u "
9970 "tunnel %u group %u registered.",
9971 table_level, table_id,
9972 tunnel ? tunnel->tunnel_id : 0, group_id);
9973 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
9974 return &tbl_data->tbl;
9978 flow_dv_tbl_remove_cb(struct mlx5_hlist *list,
9979 struct mlx5_hlist_entry *entry)
9981 struct mlx5_dev_ctx_shared *sh = list->ctx;
9982 struct mlx5_flow_tbl_data_entry *tbl_data =
9983 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
9985 MLX5_ASSERT(entry && sh);
9986 if (tbl_data->jump.action)
9987 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
9988 if (tbl_data->tbl.obj)
9989 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
9990 if (tbl_data->tunnel_offload && tbl_data->external) {
9991 struct mlx5_hlist_entry *he;
9992 struct mlx5_hlist *tunnel_grp_hash;
9993 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
9994 union tunnel_tbl_key tunnel_key = {
9995 .tunnel_id = tbl_data->tunnel ?
9996 tbl_data->tunnel->tunnel_id : 0,
9997 .group = tbl_data->group_id
9999 uint32_t table_level = tbl_data->level;
10001 tunnel_grp_hash = tbl_data->tunnel ?
10002 tbl_data->tunnel->groups :
10004 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, NULL);
10006 mlx5_hlist_unregister(tunnel_grp_hash, he);
10008 "table_level %u id %u tunnel %u group %u released.",
10012 tbl_data->tunnel->tunnel_id : 0,
10013 tbl_data->group_id);
10015 mlx5_cache_list_destroy(&tbl_data->matchers);
10016 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10020 * Release a flow table.
10023 * Pointer to device shared structure.
10025 * Table resource to be released.
10028 * Returns 0 if table was released, else return 1;
10031 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
10032 struct mlx5_flow_tbl_resource *tbl)
10034 struct mlx5_flow_tbl_data_entry *tbl_data =
10035 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10039 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
10043 flow_dv_matcher_match_cb(struct mlx5_cache_list *list __rte_unused,
10044 struct mlx5_cache_entry *entry, void *cb_ctx)
10046 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10047 struct mlx5_flow_dv_matcher *ref = ctx->data;
10048 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
10051 return cur->crc != ref->crc ||
10052 cur->priority != ref->priority ||
10053 memcmp((const void *)cur->mask.buf,
10054 (const void *)ref->mask.buf, ref->mask.size);
10057 struct mlx5_cache_entry *
10058 flow_dv_matcher_create_cb(struct mlx5_cache_list *list,
10059 struct mlx5_cache_entry *entry __rte_unused,
10062 struct mlx5_dev_ctx_shared *sh = list->ctx;
10063 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10064 struct mlx5_flow_dv_matcher *ref = ctx->data;
10065 struct mlx5_flow_dv_matcher *cache;
10066 struct mlx5dv_flow_matcher_attr dv_attr = {
10067 .type = IBV_FLOW_ATTR_NORMAL,
10068 .match_mask = (void *)&ref->mask,
10070 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10071 typeof(*tbl), tbl);
10074 cache = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*cache), 0, SOCKET_ID_ANY);
10076 rte_flow_error_set(ctx->error, ENOMEM,
10077 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10078 "cannot create matcher");
10082 dv_attr.match_criteria_enable =
10083 flow_dv_matcher_enable(cache->mask.buf);
10084 dv_attr.priority = ref->priority;
10085 if (tbl->is_egress)
10086 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
10087 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->tbl.obj,
10088 &cache->matcher_object);
10091 rte_flow_error_set(ctx->error, ENOMEM,
10092 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10093 "cannot create matcher");
10096 return &cache->entry;
10100 * Register the flow matcher.
10102 * @param[in, out] dev
10103 * Pointer to rte_eth_dev structure.
10104 * @param[in, out] matcher
10105 * Pointer to flow matcher.
10106 * @param[in, out] key
10107 * Pointer to flow table key.
10108 * @parm[in, out] dev_flow
10109 * Pointer to the dev_flow.
10110 * @param[out] error
10111 * pointer to error structure.
10114 * 0 on success otherwise -errno and errno is set.
10117 flow_dv_matcher_register(struct rte_eth_dev *dev,
10118 struct mlx5_flow_dv_matcher *ref,
10119 union mlx5_flow_tbl_key *key,
10120 struct mlx5_flow *dev_flow,
10121 const struct mlx5_flow_tunnel *tunnel,
10123 struct rte_flow_error *error)
10125 struct mlx5_cache_entry *entry;
10126 struct mlx5_flow_dv_matcher *cache;
10127 struct mlx5_flow_tbl_resource *tbl;
10128 struct mlx5_flow_tbl_data_entry *tbl_data;
10129 struct mlx5_flow_cb_ctx ctx = {
10135 * tunnel offload API requires this registration for cases when
10136 * tunnel match rule was inserted before tunnel set rule.
10138 tbl = flow_dv_tbl_resource_get(dev, key->level,
10139 key->is_egress, key->is_fdb,
10140 dev_flow->external, tunnel,
10141 group_id, 0, key->id, error);
10143 return -rte_errno; /* No need to refill the error info */
10144 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10146 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
10148 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
10149 return rte_flow_error_set(error, ENOMEM,
10150 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10151 "cannot allocate ref memory");
10153 cache = container_of(entry, typeof(*cache), entry);
10154 dev_flow->handle->dvh.matcher = cache;
10158 struct mlx5_hlist_entry *
10159 flow_dv_tag_create_cb(struct mlx5_hlist *list, uint64_t key, void *ctx)
10161 struct mlx5_dev_ctx_shared *sh = list->ctx;
10162 struct rte_flow_error *error = ctx;
10163 struct mlx5_flow_dv_tag_resource *entry;
10167 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10169 rte_flow_error_set(error, ENOMEM,
10170 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10171 "cannot allocate resource memory");
10175 entry->tag_id = key;
10176 ret = mlx5_flow_os_create_flow_action_tag(key,
10179 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
10180 rte_flow_error_set(error, ENOMEM,
10181 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10182 NULL, "cannot create action");
10185 return &entry->entry;
10189 flow_dv_tag_match_cb(struct mlx5_hlist *list __rte_unused,
10190 struct mlx5_hlist_entry *entry, uint64_t key,
10191 void *cb_ctx __rte_unused)
10193 struct mlx5_flow_dv_tag_resource *tag =
10194 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10196 return key != tag->tag_id;
10200 * Find existing tag resource or create and register a new one.
10202 * @param dev[in, out]
10203 * Pointer to rte_eth_dev structure.
10204 * @param[in, out] tag_be24
10205 * Tag value in big endian then R-shift 8.
10206 * @parm[in, out] dev_flow
10207 * Pointer to the dev_flow.
10208 * @param[out] error
10209 * pointer to error structure.
10212 * 0 on success otherwise -errno and errno is set.
10215 flow_dv_tag_resource_register
10216 (struct rte_eth_dev *dev,
10218 struct mlx5_flow *dev_flow,
10219 struct rte_flow_error *error)
10221 struct mlx5_priv *priv = dev->data->dev_private;
10222 struct mlx5_flow_dv_tag_resource *cache_resource;
10223 struct mlx5_hlist_entry *entry;
10225 entry = mlx5_hlist_register(priv->sh->tag_table, tag_be24, error);
10227 cache_resource = container_of
10228 (entry, struct mlx5_flow_dv_tag_resource, entry);
10229 dev_flow->handle->dvh.rix_tag = cache_resource->idx;
10230 dev_flow->dv.tag_resource = cache_resource;
10237 flow_dv_tag_remove_cb(struct mlx5_hlist *list,
10238 struct mlx5_hlist_entry *entry)
10240 struct mlx5_dev_ctx_shared *sh = list->ctx;
10241 struct mlx5_flow_dv_tag_resource *tag =
10242 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10244 MLX5_ASSERT(tag && sh && tag->action);
10245 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
10246 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
10247 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10254 * Pointer to Ethernet device.
10259 * 1 while a reference on it exists, 0 when freed.
10262 flow_dv_tag_release(struct rte_eth_dev *dev,
10265 struct mlx5_priv *priv = dev->data->dev_private;
10266 struct mlx5_flow_dv_tag_resource *tag;
10268 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
10271 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
10272 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
10273 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
10277 * Translate port ID action to vport.
10280 * Pointer to rte_eth_dev structure.
10281 * @param[in] action
10282 * Pointer to the port ID action.
10283 * @param[out] dst_port_id
10284 * The target port ID.
10285 * @param[out] error
10286 * Pointer to the error structure.
10289 * 0 on success, a negative errno value otherwise and rte_errno is set.
10292 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
10293 const struct rte_flow_action *action,
10294 uint32_t *dst_port_id,
10295 struct rte_flow_error *error)
10298 struct mlx5_priv *priv;
10299 const struct rte_flow_action_port_id *conf =
10300 (const struct rte_flow_action_port_id *)action->conf;
10302 port = conf->original ? dev->data->port_id : conf->id;
10303 priv = mlx5_port_to_eswitch_info(port, false);
10305 return rte_flow_error_set(error, -rte_errno,
10306 RTE_FLOW_ERROR_TYPE_ACTION,
10308 "No eswitch info was found for port");
10309 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
10311 * This parameter is transferred to
10312 * mlx5dv_dr_action_create_dest_ib_port().
10314 *dst_port_id = priv->dev_port;
10317 * Legacy mode, no LAG configurations is supported.
10318 * This parameter is transferred to
10319 * mlx5dv_dr_action_create_dest_vport().
10321 *dst_port_id = priv->vport_id;
10327 * Create a counter with aging configuration.
10330 * Pointer to rte_eth_dev structure.
10331 * @param[in] dev_flow
10332 * Pointer to the mlx5_flow.
10333 * @param[out] count
10334 * Pointer to the counter action configuration.
10336 * Pointer to the aging action configuration.
10339 * Index to flow counter on success, 0 otherwise.
10342 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
10343 struct mlx5_flow *dev_flow,
10344 const struct rte_flow_action_count *count,
10345 const struct rte_flow_action_age *age)
10348 struct mlx5_age_param *age_param;
10350 if (count && count->shared)
10351 counter = flow_dv_counter_get_shared(dev, count->id);
10353 counter = flow_dv_counter_alloc(dev, !!age);
10354 if (!counter || age == NULL)
10356 age_param = flow_dv_counter_idx_get_age(dev, counter);
10357 age_param->context = age->context ? age->context :
10358 (void *)(uintptr_t)(dev_flow->flow_idx);
10359 age_param->timeout = age->timeout;
10360 age_param->port_id = dev->data->port_id;
10361 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
10362 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
10367 * Add Tx queue matcher
10370 * Pointer to the dev struct.
10371 * @param[in, out] matcher
10373 * @param[in, out] key
10374 * Flow matcher value.
10376 * Flow pattern to translate.
10378 * Item is inner pattern.
10381 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
10382 void *matcher, void *key,
10383 const struct rte_flow_item *item)
10385 const struct mlx5_rte_flow_item_tx_queue *queue_m;
10386 const struct mlx5_rte_flow_item_tx_queue *queue_v;
10388 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
10390 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10391 struct mlx5_txq_ctrl *txq;
10395 queue_m = (const void *)item->mask;
10398 queue_v = (const void *)item->spec;
10401 txq = mlx5_txq_get(dev, queue_v->queue);
10404 queue = txq->obj->sq->id;
10405 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
10406 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
10407 queue & queue_m->queue);
10408 mlx5_txq_release(dev, queue_v->queue);
10412 * Set the hash fields according to the @p flow information.
10414 * @param[in] dev_flow
10415 * Pointer to the mlx5_flow.
10416 * @param[in] rss_desc
10417 * Pointer to the mlx5_flow_rss_desc.
10420 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
10421 struct mlx5_flow_rss_desc *rss_desc)
10423 uint64_t items = dev_flow->handle->layers;
10425 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
10427 dev_flow->hash_fields = 0;
10428 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
10429 if (rss_desc->level >= 2) {
10430 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
10434 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
10435 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
10436 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
10437 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10438 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
10439 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10440 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
10442 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
10444 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
10445 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
10446 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
10447 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10448 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
10449 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10450 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
10452 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
10455 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
10456 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
10457 if (rss_types & ETH_RSS_UDP) {
10458 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10459 dev_flow->hash_fields |=
10460 IBV_RX_HASH_SRC_PORT_UDP;
10461 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10462 dev_flow->hash_fields |=
10463 IBV_RX_HASH_DST_PORT_UDP;
10465 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
10467 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
10468 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
10469 if (rss_types & ETH_RSS_TCP) {
10470 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10471 dev_flow->hash_fields |=
10472 IBV_RX_HASH_SRC_PORT_TCP;
10473 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10474 dev_flow->hash_fields |=
10475 IBV_RX_HASH_DST_PORT_TCP;
10477 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
10483 * Prepare an Rx Hash queue.
10486 * Pointer to Ethernet device.
10487 * @param[in] dev_flow
10488 * Pointer to the mlx5_flow.
10489 * @param[in] rss_desc
10490 * Pointer to the mlx5_flow_rss_desc.
10491 * @param[out] hrxq_idx
10492 * Hash Rx queue index.
10495 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
10497 static struct mlx5_hrxq *
10498 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
10499 struct mlx5_flow *dev_flow,
10500 struct mlx5_flow_rss_desc *rss_desc,
10501 uint32_t *hrxq_idx)
10503 struct mlx5_priv *priv = dev->data->dev_private;
10504 struct mlx5_flow_handle *dh = dev_flow->handle;
10505 struct mlx5_hrxq *hrxq;
10507 MLX5_ASSERT(rss_desc->queue_num);
10508 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
10509 rss_desc->hash_fields = dev_flow->hash_fields;
10510 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
10511 rss_desc->shared_rss = 0;
10512 *hrxq_idx = mlx5_hrxq_get(dev, rss_desc);
10515 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
10521 * Release sample sub action resource.
10523 * @param[in, out] dev
10524 * Pointer to rte_eth_dev structure.
10525 * @param[in] act_res
10526 * Pointer to sample sub action resource.
10529 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
10530 struct mlx5_flow_sub_actions_idx *act_res)
10532 if (act_res->rix_hrxq) {
10533 mlx5_hrxq_release(dev, act_res->rix_hrxq);
10534 act_res->rix_hrxq = 0;
10536 if (act_res->rix_encap_decap) {
10537 flow_dv_encap_decap_resource_release(dev,
10538 act_res->rix_encap_decap);
10539 act_res->rix_encap_decap = 0;
10541 if (act_res->rix_port_id_action) {
10542 flow_dv_port_id_action_resource_release(dev,
10543 act_res->rix_port_id_action);
10544 act_res->rix_port_id_action = 0;
10546 if (act_res->rix_tag) {
10547 flow_dv_tag_release(dev, act_res->rix_tag);
10548 act_res->rix_tag = 0;
10550 if (act_res->rix_jump) {
10551 flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
10552 act_res->rix_jump = 0;
10557 flow_dv_sample_match_cb(struct mlx5_cache_list *list __rte_unused,
10558 struct mlx5_cache_entry *entry, void *cb_ctx)
10560 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10561 struct rte_eth_dev *dev = ctx->dev;
10562 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
10563 struct mlx5_flow_dv_sample_resource *cache_resource =
10564 container_of(entry, typeof(*cache_resource), entry);
10566 if (resource->ratio == cache_resource->ratio &&
10567 resource->ft_type == cache_resource->ft_type &&
10568 resource->ft_id == cache_resource->ft_id &&
10569 resource->set_action == cache_resource->set_action &&
10570 !memcmp((void *)&resource->sample_act,
10571 (void *)&cache_resource->sample_act,
10572 sizeof(struct mlx5_flow_sub_actions_list))) {
10574 * Existing sample action should release the prepared
10575 * sub-actions reference counter.
10577 flow_dv_sample_sub_actions_release(dev,
10578 &resource->sample_idx);
10584 struct mlx5_cache_entry *
10585 flow_dv_sample_create_cb(struct mlx5_cache_list *list __rte_unused,
10586 struct mlx5_cache_entry *entry __rte_unused,
10589 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10590 struct rte_eth_dev *dev = ctx->dev;
10591 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
10592 void **sample_dv_actions = resource->sub_actions;
10593 struct mlx5_flow_dv_sample_resource *cache_resource;
10594 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
10595 struct mlx5_priv *priv = dev->data->dev_private;
10596 struct mlx5_dev_ctx_shared *sh = priv->sh;
10597 struct mlx5_flow_tbl_resource *tbl;
10599 const uint32_t next_ft_step = 1;
10600 uint32_t next_ft_id = resource->ft_id + next_ft_step;
10601 uint8_t is_egress = 0;
10602 uint8_t is_transfer = 0;
10603 struct rte_flow_error *error = ctx->error;
10605 /* Register new sample resource. */
10606 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
10607 if (!cache_resource) {
10608 rte_flow_error_set(error, ENOMEM,
10609 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10611 "cannot allocate resource memory");
10614 *cache_resource = *resource;
10615 /* Create normal path table level */
10616 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
10618 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
10620 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
10621 is_egress, is_transfer,
10622 true, NULL, 0, 0, 0, error);
10624 rte_flow_error_set(error, ENOMEM,
10625 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10627 "fail to create normal path table "
10631 cache_resource->normal_path_tbl = tbl;
10632 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
10633 if (!sh->default_miss_action) {
10634 rte_flow_error_set(error, ENOMEM,
10635 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10637 "default miss action was not "
10641 sample_dv_actions[resource->sample_act.actions_num++] =
10642 sh->default_miss_action;
10644 /* Create a DR sample action */
10645 sampler_attr.sample_ratio = cache_resource->ratio;
10646 sampler_attr.default_next_table = tbl->obj;
10647 sampler_attr.num_sample_actions = resource->sample_act.actions_num;
10648 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
10649 &sample_dv_actions[0];
10650 sampler_attr.action = cache_resource->set_action;
10651 if (mlx5_os_flow_dr_create_flow_action_sampler
10652 (&sampler_attr, &cache_resource->verbs_action)) {
10653 rte_flow_error_set(error, ENOMEM,
10654 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10655 NULL, "cannot create sample action");
10658 cache_resource->idx = idx;
10659 cache_resource->dev = dev;
10660 return &cache_resource->entry;
10662 if (cache_resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
10663 flow_dv_sample_sub_actions_release(dev,
10664 &cache_resource->sample_idx);
10665 if (cache_resource->normal_path_tbl)
10666 flow_dv_tbl_resource_release(MLX5_SH(dev),
10667 cache_resource->normal_path_tbl);
10668 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
10674 * Find existing sample resource or create and register a new one.
10676 * @param[in, out] dev
10677 * Pointer to rte_eth_dev structure.
10678 * @param[in] resource
10679 * Pointer to sample resource.
10680 * @parm[in, out] dev_flow
10681 * Pointer to the dev_flow.
10682 * @param[out] error
10683 * pointer to error structure.
10686 * 0 on success otherwise -errno and errno is set.
10689 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
10690 struct mlx5_flow_dv_sample_resource *resource,
10691 struct mlx5_flow *dev_flow,
10692 struct rte_flow_error *error)
10694 struct mlx5_flow_dv_sample_resource *cache_resource;
10695 struct mlx5_cache_entry *entry;
10696 struct mlx5_priv *priv = dev->data->dev_private;
10697 struct mlx5_flow_cb_ctx ctx = {
10703 entry = mlx5_cache_register(&priv->sh->sample_action_list, &ctx);
10706 cache_resource = container_of(entry, typeof(*cache_resource), entry);
10707 dev_flow->handle->dvh.rix_sample = cache_resource->idx;
10708 dev_flow->dv.sample_res = cache_resource;
10713 flow_dv_dest_array_match_cb(struct mlx5_cache_list *list __rte_unused,
10714 struct mlx5_cache_entry *entry, void *cb_ctx)
10716 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10717 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
10718 struct rte_eth_dev *dev = ctx->dev;
10719 struct mlx5_flow_dv_dest_array_resource *cache_resource =
10720 container_of(entry, typeof(*cache_resource), entry);
10723 if (resource->num_of_dest == cache_resource->num_of_dest &&
10724 resource->ft_type == cache_resource->ft_type &&
10725 !memcmp((void *)cache_resource->sample_act,
10726 (void *)resource->sample_act,
10727 (resource->num_of_dest *
10728 sizeof(struct mlx5_flow_sub_actions_list)))) {
10730 * Existing sample action should release the prepared
10731 * sub-actions reference counter.
10733 for (idx = 0; idx < resource->num_of_dest; idx++)
10734 flow_dv_sample_sub_actions_release(dev,
10735 &resource->sample_idx[idx]);
10741 struct mlx5_cache_entry *
10742 flow_dv_dest_array_create_cb(struct mlx5_cache_list *list __rte_unused,
10743 struct mlx5_cache_entry *entry __rte_unused,
10746 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10747 struct rte_eth_dev *dev = ctx->dev;
10748 struct mlx5_flow_dv_dest_array_resource *cache_resource;
10749 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
10750 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
10751 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
10752 struct mlx5_priv *priv = dev->data->dev_private;
10753 struct mlx5_dev_ctx_shared *sh = priv->sh;
10754 struct mlx5_flow_sub_actions_list *sample_act;
10755 struct mlx5dv_dr_domain *domain;
10756 uint32_t idx = 0, res_idx = 0;
10757 struct rte_flow_error *error = ctx->error;
10758 uint64_t action_flags;
10761 /* Register new destination array resource. */
10762 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
10764 if (!cache_resource) {
10765 rte_flow_error_set(error, ENOMEM,
10766 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10768 "cannot allocate resource memory");
10771 *cache_resource = *resource;
10772 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
10773 domain = sh->fdb_domain;
10774 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
10775 domain = sh->rx_domain;
10777 domain = sh->tx_domain;
10778 for (idx = 0; idx < resource->num_of_dest; idx++) {
10779 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
10780 mlx5_malloc(MLX5_MEM_ZERO,
10781 sizeof(struct mlx5dv_dr_action_dest_attr),
10783 if (!dest_attr[idx]) {
10784 rte_flow_error_set(error, ENOMEM,
10785 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10787 "cannot allocate resource memory");
10790 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
10791 sample_act = &resource->sample_act[idx];
10792 action_flags = sample_act->action_flags;
10793 switch (action_flags) {
10794 case MLX5_FLOW_ACTION_QUEUE:
10795 dest_attr[idx]->dest = sample_act->dr_queue_action;
10797 case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
10798 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
10799 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
10800 dest_attr[idx]->dest_reformat->reformat =
10801 sample_act->dr_encap_action;
10802 dest_attr[idx]->dest_reformat->dest =
10803 sample_act->dr_port_id_action;
10805 case MLX5_FLOW_ACTION_PORT_ID:
10806 dest_attr[idx]->dest = sample_act->dr_port_id_action;
10808 case MLX5_FLOW_ACTION_JUMP:
10809 dest_attr[idx]->dest = sample_act->dr_jump_action;
10812 rte_flow_error_set(error, EINVAL,
10813 RTE_FLOW_ERROR_TYPE_ACTION,
10815 "unsupported actions type");
10819 /* create a dest array actioin */
10820 ret = mlx5_os_flow_dr_create_flow_action_dest_array
10822 cache_resource->num_of_dest,
10824 &cache_resource->action);
10826 rte_flow_error_set(error, ENOMEM,
10827 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10829 "cannot create destination array action");
10832 cache_resource->idx = res_idx;
10833 cache_resource->dev = dev;
10834 for (idx = 0; idx < resource->num_of_dest; idx++)
10835 mlx5_free(dest_attr[idx]);
10836 return &cache_resource->entry;
10838 for (idx = 0; idx < resource->num_of_dest; idx++) {
10839 flow_dv_sample_sub_actions_release(dev,
10840 &cache_resource->sample_idx[idx]);
10841 if (dest_attr[idx])
10842 mlx5_free(dest_attr[idx]);
10845 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
10850 * Find existing destination array resource or create and register a new one.
10852 * @param[in, out] dev
10853 * Pointer to rte_eth_dev structure.
10854 * @param[in] resource
10855 * Pointer to destination array resource.
10856 * @parm[in, out] dev_flow
10857 * Pointer to the dev_flow.
10858 * @param[out] error
10859 * pointer to error structure.
10862 * 0 on success otherwise -errno and errno is set.
10865 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
10866 struct mlx5_flow_dv_dest_array_resource *resource,
10867 struct mlx5_flow *dev_flow,
10868 struct rte_flow_error *error)
10870 struct mlx5_flow_dv_dest_array_resource *cache_resource;
10871 struct mlx5_priv *priv = dev->data->dev_private;
10872 struct mlx5_cache_entry *entry;
10873 struct mlx5_flow_cb_ctx ctx = {
10879 entry = mlx5_cache_register(&priv->sh->dest_array_list, &ctx);
10882 cache_resource = container_of(entry, typeof(*cache_resource), entry);
10883 dev_flow->handle->dvh.rix_dest_array = cache_resource->idx;
10884 dev_flow->dv.dest_array_res = cache_resource;
10889 * Convert Sample action to DV specification.
10892 * Pointer to rte_eth_dev structure.
10893 * @param[in] action
10894 * Pointer to sample action structure.
10895 * @param[in, out] dev_flow
10896 * Pointer to the mlx5_flow.
10898 * Pointer to the flow attributes.
10899 * @param[in, out] num_of_dest
10900 * Pointer to the num of destination.
10901 * @param[in, out] sample_actions
10902 * Pointer to sample actions list.
10903 * @param[in, out] res
10904 * Pointer to sample resource.
10905 * @param[out] error
10906 * Pointer to the error structure.
10909 * 0 on success, a negative errno value otherwise and rte_errno is set.
10912 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
10913 const struct rte_flow_action_sample *action,
10914 struct mlx5_flow *dev_flow,
10915 const struct rte_flow_attr *attr,
10916 uint32_t *num_of_dest,
10917 void **sample_actions,
10918 struct mlx5_flow_dv_sample_resource *res,
10919 struct rte_flow_error *error)
10921 struct mlx5_priv *priv = dev->data->dev_private;
10922 const struct rte_flow_action *sub_actions;
10923 struct mlx5_flow_sub_actions_list *sample_act;
10924 struct mlx5_flow_sub_actions_idx *sample_idx;
10925 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10926 struct rte_flow *flow = dev_flow->flow;
10927 struct mlx5_flow_rss_desc *rss_desc;
10928 uint64_t action_flags = 0;
10931 rss_desc = &wks->rss_desc;
10932 sample_act = &res->sample_act;
10933 sample_idx = &res->sample_idx;
10934 res->ratio = action->ratio;
10935 sub_actions = action->actions;
10936 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
10937 int type = sub_actions->type;
10938 uint32_t pre_rix = 0;
10941 case RTE_FLOW_ACTION_TYPE_QUEUE:
10943 const struct rte_flow_action_queue *queue;
10944 struct mlx5_hrxq *hrxq;
10947 queue = sub_actions->conf;
10948 rss_desc->queue_num = 1;
10949 rss_desc->queue[0] = queue->index;
10950 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
10951 rss_desc, &hrxq_idx);
10953 return rte_flow_error_set
10955 RTE_FLOW_ERROR_TYPE_ACTION,
10957 "cannot create fate queue");
10958 sample_act->dr_queue_action = hrxq->action;
10959 sample_idx->rix_hrxq = hrxq_idx;
10960 sample_actions[sample_act->actions_num++] =
10963 action_flags |= MLX5_FLOW_ACTION_QUEUE;
10964 if (action_flags & MLX5_FLOW_ACTION_MARK)
10965 dev_flow->handle->rix_hrxq = hrxq_idx;
10966 dev_flow->handle->fate_action =
10967 MLX5_FLOW_FATE_QUEUE;
10970 case RTE_FLOW_ACTION_TYPE_RSS:
10972 struct mlx5_hrxq *hrxq;
10974 const struct rte_flow_action_rss *rss;
10975 const uint8_t *rss_key;
10977 rss = sub_actions->conf;
10978 memcpy(rss_desc->queue, rss->queue,
10979 rss->queue_num * sizeof(uint16_t));
10980 rss_desc->queue_num = rss->queue_num;
10981 /* NULL RSS key indicates default RSS key. */
10982 rss_key = !rss->key ? rss_hash_default_key : rss->key;
10983 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
10985 * rss->level and rss.types should be set in advance
10986 * when expanding items for RSS.
10988 flow_dv_hashfields_set(dev_flow, rss_desc);
10989 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
10990 rss_desc, &hrxq_idx);
10992 return rte_flow_error_set
10994 RTE_FLOW_ERROR_TYPE_ACTION,
10996 "cannot create fate queue");
10997 sample_act->dr_queue_action = hrxq->action;
10998 sample_idx->rix_hrxq = hrxq_idx;
10999 sample_actions[sample_act->actions_num++] =
11002 action_flags |= MLX5_FLOW_ACTION_RSS;
11003 if (action_flags & MLX5_FLOW_ACTION_MARK)
11004 dev_flow->handle->rix_hrxq = hrxq_idx;
11005 dev_flow->handle->fate_action =
11006 MLX5_FLOW_FATE_QUEUE;
11009 case RTE_FLOW_ACTION_TYPE_MARK:
11011 uint32_t tag_be = mlx5_flow_mark_set
11012 (((const struct rte_flow_action_mark *)
11013 (sub_actions->conf))->id);
11015 dev_flow->handle->mark = 1;
11016 pre_rix = dev_flow->handle->dvh.rix_tag;
11017 /* Save the mark resource before sample */
11018 pre_r = dev_flow->dv.tag_resource;
11019 if (flow_dv_tag_resource_register(dev, tag_be,
11022 MLX5_ASSERT(dev_flow->dv.tag_resource);
11023 sample_act->dr_tag_action =
11024 dev_flow->dv.tag_resource->action;
11025 sample_idx->rix_tag =
11026 dev_flow->handle->dvh.rix_tag;
11027 sample_actions[sample_act->actions_num++] =
11028 sample_act->dr_tag_action;
11029 /* Recover the mark resource after sample */
11030 dev_flow->dv.tag_resource = pre_r;
11031 dev_flow->handle->dvh.rix_tag = pre_rix;
11032 action_flags |= MLX5_FLOW_ACTION_MARK;
11035 case RTE_FLOW_ACTION_TYPE_COUNT:
11037 if (!flow->counter) {
11039 flow_dv_translate_create_counter(dev,
11040 dev_flow, sub_actions->conf,
11042 if (!flow->counter)
11043 return rte_flow_error_set
11045 RTE_FLOW_ERROR_TYPE_ACTION,
11047 "cannot create counter"
11050 sample_act->dr_cnt_action =
11051 (flow_dv_counter_get_by_idx(dev,
11052 flow->counter, NULL))->action;
11053 sample_actions[sample_act->actions_num++] =
11054 sample_act->dr_cnt_action;
11055 action_flags |= MLX5_FLOW_ACTION_COUNT;
11058 case RTE_FLOW_ACTION_TYPE_PORT_ID:
11060 struct mlx5_flow_dv_port_id_action_resource
11062 uint32_t port_id = 0;
11064 memset(&port_id_resource, 0, sizeof(port_id_resource));
11065 /* Save the port id resource before sample */
11066 pre_rix = dev_flow->handle->rix_port_id_action;
11067 pre_r = dev_flow->dv.port_id_action;
11068 if (flow_dv_translate_action_port_id(dev, sub_actions,
11071 port_id_resource.port_id = port_id;
11072 if (flow_dv_port_id_action_resource_register
11073 (dev, &port_id_resource, dev_flow, error))
11075 sample_act->dr_port_id_action =
11076 dev_flow->dv.port_id_action->action;
11077 sample_idx->rix_port_id_action =
11078 dev_flow->handle->rix_port_id_action;
11079 sample_actions[sample_act->actions_num++] =
11080 sample_act->dr_port_id_action;
11081 /* Recover the port id resource after sample */
11082 dev_flow->dv.port_id_action = pre_r;
11083 dev_flow->handle->rix_port_id_action = pre_rix;
11085 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
11088 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11089 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11090 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11091 /* Save the encap resource before sample */
11092 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
11093 pre_r = dev_flow->dv.encap_decap;
11094 if (flow_dv_create_action_l2_encap(dev, sub_actions,
11099 sample_act->dr_encap_action =
11100 dev_flow->dv.encap_decap->action;
11101 sample_idx->rix_encap_decap =
11102 dev_flow->handle->dvh.rix_encap_decap;
11103 sample_actions[sample_act->actions_num++] =
11104 sample_act->dr_encap_action;
11105 /* Recover the encap resource after sample */
11106 dev_flow->dv.encap_decap = pre_r;
11107 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
11108 action_flags |= MLX5_FLOW_ACTION_ENCAP;
11111 return rte_flow_error_set(error, EINVAL,
11112 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11114 "Not support for sampler action");
11117 sample_act->action_flags = action_flags;
11118 res->ft_id = dev_flow->dv.group;
11119 if (attr->transfer) {
11121 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
11122 uint64_t set_action;
11123 } action_ctx = { .set_action = 0 };
11125 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
11126 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
11127 MLX5_MODIFICATION_TYPE_SET);
11128 MLX5_SET(set_action_in, action_ctx.action_in, field,
11129 MLX5_MODI_META_REG_C_0);
11130 MLX5_SET(set_action_in, action_ctx.action_in, data,
11131 priv->vport_meta_tag);
11132 res->set_action = action_ctx.set_action;
11133 } else if (attr->ingress) {
11134 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
11136 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
11142 * Convert Sample action to DV specification.
11145 * Pointer to rte_eth_dev structure.
11146 * @param[in, out] dev_flow
11147 * Pointer to the mlx5_flow.
11148 * @param[in] num_of_dest
11149 * The num of destination.
11150 * @param[in, out] res
11151 * Pointer to sample resource.
11152 * @param[in, out] mdest_res
11153 * Pointer to destination array resource.
11154 * @param[in] sample_actions
11155 * Pointer to sample path actions list.
11156 * @param[in] action_flags
11157 * Holds the actions detected until now.
11158 * @param[out] error
11159 * Pointer to the error structure.
11162 * 0 on success, a negative errno value otherwise and rte_errno is set.
11165 flow_dv_create_action_sample(struct rte_eth_dev *dev,
11166 struct mlx5_flow *dev_flow,
11167 uint32_t num_of_dest,
11168 struct mlx5_flow_dv_sample_resource *res,
11169 struct mlx5_flow_dv_dest_array_resource *mdest_res,
11170 void **sample_actions,
11171 uint64_t action_flags,
11172 struct rte_flow_error *error)
11174 /* update normal path action resource into last index of array */
11175 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
11176 struct mlx5_flow_sub_actions_list *sample_act =
11177 &mdest_res->sample_act[dest_index];
11178 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11179 struct mlx5_flow_rss_desc *rss_desc;
11180 uint32_t normal_idx = 0;
11181 struct mlx5_hrxq *hrxq;
11185 rss_desc = &wks->rss_desc;
11186 if (num_of_dest > 1) {
11187 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
11188 /* Handle QP action for mirroring */
11189 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11190 rss_desc, &hrxq_idx);
11192 return rte_flow_error_set
11194 RTE_FLOW_ERROR_TYPE_ACTION,
11196 "cannot create rx queue");
11198 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
11199 sample_act->dr_queue_action = hrxq->action;
11200 if (action_flags & MLX5_FLOW_ACTION_MARK)
11201 dev_flow->handle->rix_hrxq = hrxq_idx;
11202 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
11204 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
11206 mdest_res->sample_idx[dest_index].rix_encap_decap =
11207 dev_flow->handle->dvh.rix_encap_decap;
11208 sample_act->dr_encap_action =
11209 dev_flow->dv.encap_decap->action;
11210 dev_flow->handle->dvh.rix_encap_decap = 0;
11212 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
11214 mdest_res->sample_idx[dest_index].rix_port_id_action =
11215 dev_flow->handle->rix_port_id_action;
11216 sample_act->dr_port_id_action =
11217 dev_flow->dv.port_id_action->action;
11218 dev_flow->handle->rix_port_id_action = 0;
11220 if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
11222 mdest_res->sample_idx[dest_index].rix_jump =
11223 dev_flow->handle->rix_jump;
11224 sample_act->dr_jump_action =
11225 dev_flow->dv.jump->action;
11226 dev_flow->handle->rix_jump = 0;
11228 sample_act->actions_num = normal_idx;
11229 /* update sample action resource into first index of array */
11230 mdest_res->ft_type = res->ft_type;
11231 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
11232 sizeof(struct mlx5_flow_sub_actions_idx));
11233 memcpy(&mdest_res->sample_act[0], &res->sample_act,
11234 sizeof(struct mlx5_flow_sub_actions_list));
11235 mdest_res->num_of_dest = num_of_dest;
11236 if (flow_dv_dest_array_resource_register(dev, mdest_res,
11238 return rte_flow_error_set(error, EINVAL,
11239 RTE_FLOW_ERROR_TYPE_ACTION,
11240 NULL, "can't create sample "
11243 res->sub_actions = sample_actions;
11244 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
11245 return rte_flow_error_set(error, EINVAL,
11246 RTE_FLOW_ERROR_TYPE_ACTION,
11248 "can't create sample action");
11254 * Remove an ASO age action from age actions list.
11257 * Pointer to the Ethernet device structure.
11259 * Pointer to the aso age action handler.
11262 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
11263 struct mlx5_aso_age_action *age)
11265 struct mlx5_age_info *age_info;
11266 struct mlx5_age_param *age_param = &age->age_params;
11267 struct mlx5_priv *priv = dev->data->dev_private;
11268 uint16_t expected = AGE_CANDIDATE;
11270 age_info = GET_PORT_AGE_INFO(priv);
11271 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
11272 AGE_FREE, false, __ATOMIC_RELAXED,
11273 __ATOMIC_RELAXED)) {
11275 * We need the lock even it is age timeout,
11276 * since age action may still in process.
11278 rte_spinlock_lock(&age_info->aged_sl);
11279 LIST_REMOVE(age, next);
11280 rte_spinlock_unlock(&age_info->aged_sl);
11281 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
11286 * Release an ASO age action.
11289 * Pointer to the Ethernet device structure.
11290 * @param[in] age_idx
11291 * Index of ASO age action to release.
11293 * True if the release operation is during flow destroy operation.
11294 * False if the release operation is during action destroy operation.
11297 * 0 when age action was removed, otherwise the number of references.
11300 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
11302 struct mlx5_priv *priv = dev->data->dev_private;
11303 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11304 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
11305 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
11308 flow_dv_aso_age_remove_from_age(dev, age);
11309 rte_spinlock_lock(&mng->free_sl);
11310 LIST_INSERT_HEAD(&mng->free, age, next);
11311 rte_spinlock_unlock(&mng->free_sl);
11317 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
11320 * Pointer to the Ethernet device structure.
11323 * 0 on success, otherwise negative errno value and rte_errno is set.
11326 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
11328 struct mlx5_priv *priv = dev->data->dev_private;
11329 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11330 void *old_pools = mng->pools;
11331 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
11332 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
11333 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11336 rte_errno = ENOMEM;
11340 memcpy(pools, old_pools,
11341 mng->n * sizeof(struct mlx5_flow_counter_pool *));
11342 mlx5_free(old_pools);
11344 /* First ASO flow hit allocation - starting ASO data-path. */
11345 int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
11353 mng->pools = pools;
11358 * Create and initialize a new ASO aging pool.
11361 * Pointer to the Ethernet device structure.
11362 * @param[out] age_free
11363 * Where to put the pointer of a new age action.
11366 * The age actions pool pointer and @p age_free is set on success,
11367 * NULL otherwise and rte_errno is set.
11369 static struct mlx5_aso_age_pool *
11370 flow_dv_age_pool_create(struct rte_eth_dev *dev,
11371 struct mlx5_aso_age_action **age_free)
11373 struct mlx5_priv *priv = dev->data->dev_private;
11374 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11375 struct mlx5_aso_age_pool *pool = NULL;
11376 struct mlx5_devx_obj *obj = NULL;
11379 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->ctx,
11382 rte_errno = ENODATA;
11383 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
11386 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
11388 claim_zero(mlx5_devx_cmd_destroy(obj));
11389 rte_errno = ENOMEM;
11392 pool->flow_hit_aso_obj = obj;
11393 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
11394 rte_spinlock_lock(&mng->resize_sl);
11395 pool->index = mng->next;
11396 /* Resize pools array if there is no room for the new pool in it. */
11397 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
11398 claim_zero(mlx5_devx_cmd_destroy(obj));
11400 rte_spinlock_unlock(&mng->resize_sl);
11403 mng->pools[pool->index] = pool;
11405 rte_spinlock_unlock(&mng->resize_sl);
11406 /* Assign the first action in the new pool, the rest go to free list. */
11407 *age_free = &pool->actions[0];
11408 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
11409 pool->actions[i].offset = i;
11410 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
11416 * Allocate a ASO aging bit.
11419 * Pointer to the Ethernet device structure.
11420 * @param[out] error
11421 * Pointer to the error structure.
11424 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
11427 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
11429 struct mlx5_priv *priv = dev->data->dev_private;
11430 const struct mlx5_aso_age_pool *pool;
11431 struct mlx5_aso_age_action *age_free = NULL;
11432 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11435 /* Try to get the next free age action bit. */
11436 rte_spinlock_lock(&mng->free_sl);
11437 age_free = LIST_FIRST(&mng->free);
11439 LIST_REMOVE(age_free, next);
11440 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
11441 rte_spinlock_unlock(&mng->free_sl);
11442 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
11443 NULL, "failed to create ASO age pool");
11444 return 0; /* 0 is an error. */
11446 rte_spinlock_unlock(&mng->free_sl);
11447 pool = container_of
11448 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
11449 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
11451 if (!age_free->dr_action) {
11452 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
11456 rte_flow_error_set(error, rte_errno,
11457 RTE_FLOW_ERROR_TYPE_ACTION,
11458 NULL, "failed to get reg_c "
11459 "for ASO flow hit");
11460 return 0; /* 0 is an error. */
11462 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
11463 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
11464 (priv->sh->rx_domain,
11465 pool->flow_hit_aso_obj->obj, age_free->offset,
11466 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
11467 (reg_c - REG_C_0));
11468 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
11469 if (!age_free->dr_action) {
11471 rte_spinlock_lock(&mng->free_sl);
11472 LIST_INSERT_HEAD(&mng->free, age_free, next);
11473 rte_spinlock_unlock(&mng->free_sl);
11474 rte_flow_error_set(error, rte_errno,
11475 RTE_FLOW_ERROR_TYPE_ACTION,
11476 NULL, "failed to create ASO "
11477 "flow hit action");
11478 return 0; /* 0 is an error. */
11481 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
11482 return pool->index | ((age_free->offset + 1) << 16);
11486 * Create a age action using ASO mechanism.
11489 * Pointer to rte_eth_dev structure.
11491 * Pointer to the aging action configuration.
11492 * @param[out] error
11493 * Pointer to the error structure.
11496 * Index to flow counter on success, 0 otherwise.
11499 flow_dv_translate_create_aso_age(struct rte_eth_dev *dev,
11500 const struct rte_flow_action_age *age,
11501 struct rte_flow_error *error)
11503 uint32_t age_idx = 0;
11504 struct mlx5_aso_age_action *aso_age;
11506 age_idx = flow_dv_aso_age_alloc(dev, error);
11509 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
11510 aso_age->age_params.context = age->context;
11511 aso_age->age_params.timeout = age->timeout;
11512 aso_age->age_params.port_id = dev->data->port_id;
11513 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
11515 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
11521 flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
11522 const struct rte_flow_item_integrity *value,
11523 void *headers_m, void *headers_v)
11526 /* application l4_ok filter aggregates all hardware l4 filters
11527 * therefore hw l4_checksum_ok must be implicitly added here.
11529 struct rte_flow_item_integrity local_item;
11531 local_item.l4_csum_ok = 1;
11532 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
11533 local_item.l4_csum_ok);
11534 if (value->l4_ok) {
11535 /* application l4_ok = 1 matches sets both hw flags
11536 * l4_ok and l4_checksum_ok flags to 1.
11538 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11539 l4_checksum_ok, local_item.l4_csum_ok);
11540 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_ok,
11542 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_ok,
11545 /* application l4_ok = 0 matches on hw flag
11546 * l4_checksum_ok = 0 only.
11548 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11549 l4_checksum_ok, 0);
11551 } else if (mask->l4_csum_ok) {
11552 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
11554 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
11555 value->l4_csum_ok);
11560 flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
11561 const struct rte_flow_item_integrity *value,
11562 void *headers_m, void *headers_v,
11566 /* application l3_ok filter aggregates all hardware l3 filters
11567 * therefore hw ipv4_checksum_ok must be implicitly added here.
11569 struct rte_flow_item_integrity local_item;
11571 local_item.ipv4_csum_ok = !!is_ipv4;
11572 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
11573 local_item.ipv4_csum_ok);
11574 if (value->l3_ok) {
11575 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11576 ipv4_checksum_ok, local_item.ipv4_csum_ok);
11577 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l3_ok,
11579 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l3_ok,
11582 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11583 ipv4_checksum_ok, 0);
11585 } else if (mask->ipv4_csum_ok) {
11586 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
11587 mask->ipv4_csum_ok);
11588 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
11589 value->ipv4_csum_ok);
11594 flow_dv_translate_item_integrity(void *matcher, void *key,
11595 const struct rte_flow_item *head_item,
11596 const struct rte_flow_item *integrity_item)
11598 const struct rte_flow_item_integrity *mask = integrity_item->mask;
11599 const struct rte_flow_item_integrity *value = integrity_item->spec;
11600 const struct rte_flow_item *tunnel_item, *end_item, *item;
11603 uint32_t l3_protocol;
11608 mask = &rte_flow_item_integrity_mask;
11609 if (value->level > 1) {
11610 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
11612 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
11614 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
11616 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11618 tunnel_item = mlx5_flow_find_tunnel_item(head_item);
11619 if (value->level > 1) {
11620 /* tunnel item was verified during the item validation */
11621 item = tunnel_item;
11622 end_item = mlx5_find_end_item(tunnel_item);
11625 end_item = tunnel_item ? tunnel_item :
11626 mlx5_find_end_item(integrity_item);
11628 l3_protocol = mask->l3_ok ?
11629 mlx5_flow_locate_proto_l3(&item, end_item) : 0;
11630 flow_dv_translate_integrity_l3(mask, value, headers_m, headers_v,
11631 l3_protocol == RTE_ETHER_TYPE_IPV4);
11632 flow_dv_translate_integrity_l4(mask, value, headers_m, headers_v);
11636 * Prepares DV flow counter with aging configuration.
11637 * Gets it by index when exists, creates a new one when doesn't.
11640 * Pointer to rte_eth_dev structure.
11641 * @param[in] dev_flow
11642 * Pointer to the mlx5_flow.
11643 * @param[in, out] flow
11644 * Pointer to the sub flow.
11646 * Pointer to the counter action configuration.
11648 * Pointer to the aging action configuration.
11649 * @param[out] error
11650 * Pointer to the error structure.
11653 * Pointer to the counter, NULL otherwise.
11655 static struct mlx5_flow_counter *
11656 flow_dv_prepare_counter(struct rte_eth_dev *dev,
11657 struct mlx5_flow *dev_flow,
11658 struct rte_flow *flow,
11659 const struct rte_flow_action_count *count,
11660 const struct rte_flow_action_age *age,
11661 struct rte_flow_error *error)
11663 if (!flow->counter) {
11664 flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
11666 if (!flow->counter) {
11667 rte_flow_error_set(error, rte_errno,
11668 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11669 "cannot create counter object.");
11673 return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
11677 * Release an ASO CT action by its own device.
11680 * Pointer to the Ethernet device structure.
11682 * Index of ASO CT action to release.
11685 * 0 when CT action was removed, otherwise the number of references.
11688 flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
11690 struct mlx5_priv *priv = dev->data->dev_private;
11691 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11693 struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
11694 enum mlx5_aso_ct_state state =
11695 __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
11697 /* Cannot release when CT is in the ASO SQ. */
11698 if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
11700 ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
11702 if (ct->dr_action_orig) {
11703 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11704 claim_zero(mlx5_glue->destroy_flow_action
11705 (ct->dr_action_orig));
11707 ct->dr_action_orig = NULL;
11709 if (ct->dr_action_rply) {
11710 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11711 claim_zero(mlx5_glue->destroy_flow_action
11712 (ct->dr_action_rply));
11714 ct->dr_action_rply = NULL;
11716 /* Clear the state to free, no need in 1st allocation. */
11717 MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
11718 rte_spinlock_lock(&mng->ct_sl);
11719 LIST_INSERT_HEAD(&mng->free_cts, ct, next);
11720 rte_spinlock_unlock(&mng->ct_sl);
11726 flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx)
11728 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
11729 uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
11730 struct rte_eth_dev *owndev = &rte_eth_devices[owner];
11733 MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
11734 if (dev->data->dev_started != 1)
11736 return flow_dv_aso_ct_dev_release(owndev, idx);
11740 * Resize the ASO CT pools array by 64 pools.
11743 * Pointer to the Ethernet device structure.
11746 * 0 on success, otherwise negative errno value and rte_errno is set.
11749 flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
11751 struct mlx5_priv *priv = dev->data->dev_private;
11752 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11753 void *old_pools = mng->pools;
11754 /* Magic number now, need a macro. */
11755 uint32_t resize = mng->n + 64;
11756 uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
11757 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11760 rte_errno = ENOMEM;
11763 rte_rwlock_write_lock(&mng->resize_rwl);
11764 /* ASO SQ/QP was already initialized in the startup. */
11766 /* Realloc could be an alternative choice. */
11767 rte_memcpy(pools, old_pools,
11768 mng->n * sizeof(struct mlx5_aso_ct_pool *));
11769 mlx5_free(old_pools);
11772 mng->pools = pools;
11773 rte_rwlock_write_unlock(&mng->resize_rwl);
11778 * Create and initialize a new ASO CT pool.
11781 * Pointer to the Ethernet device structure.
11782 * @param[out] ct_free
11783 * Where to put the pointer of a new CT action.
11786 * The CT actions pool pointer and @p ct_free is set on success,
11787 * NULL otherwise and rte_errno is set.
11789 static struct mlx5_aso_ct_pool *
11790 flow_dv_ct_pool_create(struct rte_eth_dev *dev,
11791 struct mlx5_aso_ct_action **ct_free)
11793 struct mlx5_priv *priv = dev->data->dev_private;
11794 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11795 struct mlx5_aso_ct_pool *pool = NULL;
11796 struct mlx5_devx_obj *obj = NULL;
11798 uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
11800 obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->ctx,
11801 priv->sh->pdn, log_obj_size);
11803 rte_errno = ENODATA;
11804 DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
11807 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
11809 rte_errno = ENOMEM;
11810 claim_zero(mlx5_devx_cmd_destroy(obj));
11813 pool->devx_obj = obj;
11814 pool->index = mng->next;
11815 /* Resize pools array if there is no room for the new pool in it. */
11816 if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
11817 claim_zero(mlx5_devx_cmd_destroy(obj));
11821 mng->pools[pool->index] = pool;
11823 /* Assign the first action in the new pool, the rest go to free list. */
11824 *ct_free = &pool->actions[0];
11825 /* Lock outside, the list operation is safe here. */
11826 for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
11827 /* refcnt is 0 when allocating the memory. */
11828 pool->actions[i].offset = i;
11829 LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
11835 * Allocate a ASO CT action from free list.
11838 * Pointer to the Ethernet device structure.
11839 * @param[out] error
11840 * Pointer to the error structure.
11843 * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
11846 flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
11848 struct mlx5_priv *priv = dev->data->dev_private;
11849 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11850 struct mlx5_aso_ct_action *ct = NULL;
11851 struct mlx5_aso_ct_pool *pool;
11856 if (!priv->config.devx) {
11857 rte_errno = ENOTSUP;
11860 /* Get a free CT action, if no, a new pool will be created. */
11861 rte_spinlock_lock(&mng->ct_sl);
11862 ct = LIST_FIRST(&mng->free_cts);
11864 LIST_REMOVE(ct, next);
11865 } else if (!flow_dv_ct_pool_create(dev, &ct)) {
11866 rte_spinlock_unlock(&mng->ct_sl);
11867 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
11868 NULL, "failed to create ASO CT pool");
11871 rte_spinlock_unlock(&mng->ct_sl);
11872 pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
11873 ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
11874 /* 0: inactive, 1: created, 2+: used by flows. */
11875 __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
11876 reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
11877 if (!ct->dr_action_orig) {
11878 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11879 ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
11880 (priv->sh->rx_domain, pool->devx_obj->obj,
11882 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
11885 RTE_SET_USED(reg_c);
11887 if (!ct->dr_action_orig) {
11888 flow_dv_aso_ct_dev_release(dev, ct_idx);
11889 rte_flow_error_set(error, rte_errno,
11890 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11891 "failed to create ASO CT action");
11895 if (!ct->dr_action_rply) {
11896 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11897 ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
11898 (priv->sh->rx_domain, pool->devx_obj->obj,
11900 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
11903 if (!ct->dr_action_rply) {
11904 flow_dv_aso_ct_dev_release(dev, ct_idx);
11905 rte_flow_error_set(error, rte_errno,
11906 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11907 "failed to create ASO CT action");
11915 * Create a conntrack object with context and actions by using ASO mechanism.
11918 * Pointer to rte_eth_dev structure.
11920 * Pointer to conntrack information profile.
11921 * @param[out] error
11922 * Pointer to the error structure.
11925 * Index to conntrack object on success, 0 otherwise.
11928 flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
11929 const struct rte_flow_action_conntrack *pro,
11930 struct rte_flow_error *error)
11932 struct mlx5_priv *priv = dev->data->dev_private;
11933 struct mlx5_dev_ctx_shared *sh = priv->sh;
11934 struct mlx5_aso_ct_action *ct;
11937 if (!sh->ct_aso_en)
11938 return rte_flow_error_set(error, ENOTSUP,
11939 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11940 "Connection is not supported");
11941 idx = flow_dv_aso_ct_alloc(dev, error);
11943 return rte_flow_error_set(error, rte_errno,
11944 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11945 "Failed to allocate CT object");
11946 ct = flow_aso_ct_get_by_dev_idx(dev, idx);
11947 if (mlx5_aso_ct_update_by_wqe(sh, ct, pro))
11948 return rte_flow_error_set(error, EBUSY,
11949 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11950 "Failed to update CT");
11951 ct->is_original = !!pro->is_original_dir;
11952 ct->peer = pro->peer_port;
11957 * Fill the flow with DV spec, lock free
11958 * (mutex should be acquired by caller).
11961 * Pointer to rte_eth_dev structure.
11962 * @param[in, out] dev_flow
11963 * Pointer to the sub flow.
11965 * Pointer to the flow attributes.
11967 * Pointer to the list of items.
11968 * @param[in] actions
11969 * Pointer to the list of actions.
11970 * @param[out] error
11971 * Pointer to the error structure.
11974 * 0 on success, a negative errno value otherwise and rte_errno is set.
11977 flow_dv_translate(struct rte_eth_dev *dev,
11978 struct mlx5_flow *dev_flow,
11979 const struct rte_flow_attr *attr,
11980 const struct rte_flow_item items[],
11981 const struct rte_flow_action actions[],
11982 struct rte_flow_error *error)
11984 struct mlx5_priv *priv = dev->data->dev_private;
11985 struct mlx5_dev_config *dev_conf = &priv->config;
11986 struct rte_flow *flow = dev_flow->flow;
11987 struct mlx5_flow_handle *handle = dev_flow->handle;
11988 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11989 struct mlx5_flow_rss_desc *rss_desc;
11990 uint64_t item_flags = 0;
11991 uint64_t last_item = 0;
11992 uint64_t action_flags = 0;
11993 struct mlx5_flow_dv_matcher matcher = {
11995 .size = sizeof(matcher.mask.buf) -
11996 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
12000 bool actions_end = false;
12002 struct mlx5_flow_dv_modify_hdr_resource res;
12003 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
12004 sizeof(struct mlx5_modification_cmd) *
12005 (MLX5_MAX_MODIFY_NUM + 1)];
12007 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
12008 const struct rte_flow_action_count *count = NULL;
12009 const struct rte_flow_action_age *non_shared_age = NULL;
12010 union flow_dv_attr flow_attr = { .attr = 0 };
12012 union mlx5_flow_tbl_key tbl_key;
12013 uint32_t modify_action_position = UINT32_MAX;
12014 void *match_mask = matcher.mask.buf;
12015 void *match_value = dev_flow->dv.value.buf;
12016 uint8_t next_protocol = 0xff;
12017 struct rte_vlan_hdr vlan = { 0 };
12018 struct mlx5_flow_dv_dest_array_resource mdest_res;
12019 struct mlx5_flow_dv_sample_resource sample_res;
12020 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
12021 const struct rte_flow_action_sample *sample = NULL;
12022 struct mlx5_flow_sub_actions_list *sample_act;
12023 uint32_t sample_act_pos = UINT32_MAX;
12024 uint32_t age_act_pos = UINT32_MAX;
12025 uint32_t num_of_dest = 0;
12026 int tmp_actions_n = 0;
12029 const struct mlx5_flow_tunnel *tunnel = NULL;
12030 struct flow_grp_info grp_info = {
12031 .external = !!dev_flow->external,
12032 .transfer = !!attr->transfer,
12033 .fdb_def_rule = !!priv->fdb_def_rule,
12034 .skip_scale = dev_flow->skip_scale &
12035 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
12036 .std_tbl_fix = true,
12038 const struct rte_flow_item *head_item = items;
12041 return rte_flow_error_set(error, ENOMEM,
12042 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12044 "failed to push flow workspace");
12045 rss_desc = &wks->rss_desc;
12046 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
12047 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
12048 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12049 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12050 /* update normal path action resource into last index of array */
12051 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
12052 if (is_tunnel_offload_active(dev)) {
12053 if (dev_flow->tunnel) {
12054 RTE_VERIFY(dev_flow->tof_type ==
12055 MLX5_TUNNEL_OFFLOAD_MISS_RULE);
12056 tunnel = dev_flow->tunnel;
12058 tunnel = mlx5_get_tof(items, actions,
12059 &dev_flow->tof_type);
12060 dev_flow->tunnel = tunnel;
12062 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
12063 (dev, attr, tunnel, dev_flow->tof_type);
12065 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12066 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12067 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
12071 dev_flow->dv.group = table;
12072 if (attr->transfer)
12073 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12074 /* number of actions must be set to 0 in case of dirty stack. */
12075 mhdr_res->actions_num = 0;
12076 if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
12078 * do not add decap action if match rule drops packet
12079 * HW rejects rules with decap & drop
12081 * if tunnel match rule was inserted before matching tunnel set
12082 * rule flow table used in the match rule must be registered.
12083 * current implementation handles that in the
12084 * flow_dv_match_register() at the function end.
12086 bool add_decap = true;
12087 const struct rte_flow_action *ptr = actions;
12089 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
12090 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
12096 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12100 dev_flow->dv.actions[actions_n++] =
12101 dev_flow->dv.encap_decap->action;
12102 action_flags |= MLX5_FLOW_ACTION_DECAP;
12105 for (; !actions_end ; actions++) {
12106 const struct rte_flow_action_queue *queue;
12107 const struct rte_flow_action_rss *rss;
12108 const struct rte_flow_action *action = actions;
12109 const uint8_t *rss_key;
12110 struct mlx5_flow_tbl_resource *tbl;
12111 struct mlx5_aso_age_action *age_act;
12112 struct mlx5_flow_counter *cnt_act;
12113 uint32_t port_id = 0;
12114 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
12115 int action_type = actions->type;
12116 const struct rte_flow_action *found_action = NULL;
12117 uint32_t jump_group = 0;
12118 uint32_t owner_idx;
12119 struct mlx5_aso_ct_action *ct;
12121 if (!mlx5_flow_os_action_supported(action_type))
12122 return rte_flow_error_set(error, ENOTSUP,
12123 RTE_FLOW_ERROR_TYPE_ACTION,
12125 "action not supported");
12126 switch (action_type) {
12127 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
12128 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
12130 case RTE_FLOW_ACTION_TYPE_VOID:
12132 case RTE_FLOW_ACTION_TYPE_PORT_ID:
12133 if (flow_dv_translate_action_port_id(dev, action,
12136 port_id_resource.port_id = port_id;
12137 MLX5_ASSERT(!handle->rix_port_id_action);
12138 if (flow_dv_port_id_action_resource_register
12139 (dev, &port_id_resource, dev_flow, error))
12141 dev_flow->dv.actions[actions_n++] =
12142 dev_flow->dv.port_id_action->action;
12143 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12144 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
12145 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12148 case RTE_FLOW_ACTION_TYPE_FLAG:
12149 action_flags |= MLX5_FLOW_ACTION_FLAG;
12150 dev_flow->handle->mark = 1;
12151 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12152 struct rte_flow_action_mark mark = {
12153 .id = MLX5_FLOW_MARK_DEFAULT,
12156 if (flow_dv_convert_action_mark(dev, &mark,
12160 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12163 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
12165 * Only one FLAG or MARK is supported per device flow
12166 * right now. So the pointer to the tag resource must be
12167 * zero before the register process.
12169 MLX5_ASSERT(!handle->dvh.rix_tag);
12170 if (flow_dv_tag_resource_register(dev, tag_be,
12173 MLX5_ASSERT(dev_flow->dv.tag_resource);
12174 dev_flow->dv.actions[actions_n++] =
12175 dev_flow->dv.tag_resource->action;
12177 case RTE_FLOW_ACTION_TYPE_MARK:
12178 action_flags |= MLX5_FLOW_ACTION_MARK;
12179 dev_flow->handle->mark = 1;
12180 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12181 const struct rte_flow_action_mark *mark =
12182 (const struct rte_flow_action_mark *)
12185 if (flow_dv_convert_action_mark(dev, mark,
12189 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12193 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
12194 /* Legacy (non-extensive) MARK action. */
12195 tag_be = mlx5_flow_mark_set
12196 (((const struct rte_flow_action_mark *)
12197 (actions->conf))->id);
12198 MLX5_ASSERT(!handle->dvh.rix_tag);
12199 if (flow_dv_tag_resource_register(dev, tag_be,
12202 MLX5_ASSERT(dev_flow->dv.tag_resource);
12203 dev_flow->dv.actions[actions_n++] =
12204 dev_flow->dv.tag_resource->action;
12206 case RTE_FLOW_ACTION_TYPE_SET_META:
12207 if (flow_dv_convert_action_set_meta
12208 (dev, mhdr_res, attr,
12209 (const struct rte_flow_action_set_meta *)
12210 actions->conf, error))
12212 action_flags |= MLX5_FLOW_ACTION_SET_META;
12214 case RTE_FLOW_ACTION_TYPE_SET_TAG:
12215 if (flow_dv_convert_action_set_tag
12217 (const struct rte_flow_action_set_tag *)
12218 actions->conf, error))
12220 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12222 case RTE_FLOW_ACTION_TYPE_DROP:
12223 action_flags |= MLX5_FLOW_ACTION_DROP;
12224 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
12226 case RTE_FLOW_ACTION_TYPE_QUEUE:
12227 queue = actions->conf;
12228 rss_desc->queue_num = 1;
12229 rss_desc->queue[0] = queue->index;
12230 action_flags |= MLX5_FLOW_ACTION_QUEUE;
12231 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
12232 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
12235 case RTE_FLOW_ACTION_TYPE_RSS:
12236 rss = actions->conf;
12237 memcpy(rss_desc->queue, rss->queue,
12238 rss->queue_num * sizeof(uint16_t));
12239 rss_desc->queue_num = rss->queue_num;
12240 /* NULL RSS key indicates default RSS key. */
12241 rss_key = !rss->key ? rss_hash_default_key : rss->key;
12242 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12244 * rss->level and rss.types should be set in advance
12245 * when expanding items for RSS.
12247 action_flags |= MLX5_FLOW_ACTION_RSS;
12248 dev_flow->handle->fate_action = rss_desc->shared_rss ?
12249 MLX5_FLOW_FATE_SHARED_RSS :
12250 MLX5_FLOW_FATE_QUEUE;
12252 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
12253 flow->age = (uint32_t)(uintptr_t)(action->conf);
12254 age_act = flow_aso_age_get_by_idx(dev, flow->age);
12255 __atomic_fetch_add(&age_act->refcnt, 1,
12257 age_act_pos = actions_n++;
12258 action_flags |= MLX5_FLOW_ACTION_AGE;
12260 case RTE_FLOW_ACTION_TYPE_AGE:
12261 non_shared_age = action->conf;
12262 age_act_pos = actions_n++;
12263 action_flags |= MLX5_FLOW_ACTION_AGE;
12265 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
12266 flow->counter = (uint32_t)(uintptr_t)(action->conf);
12267 cnt_act = flow_dv_counter_get_by_idx(dev, flow->counter,
12269 __atomic_fetch_add(&cnt_act->shared_info.refcnt, 1,
12271 /* Save information first, will apply later. */
12272 action_flags |= MLX5_FLOW_ACTION_COUNT;
12274 case RTE_FLOW_ACTION_TYPE_COUNT:
12275 if (!dev_conf->devx) {
12276 return rte_flow_error_set
12278 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12280 "count action not supported");
12282 /* Save information first, will apply later. */
12283 count = action->conf;
12284 action_flags |= MLX5_FLOW_ACTION_COUNT;
12286 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
12287 dev_flow->dv.actions[actions_n++] =
12288 priv->sh->pop_vlan_action;
12289 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
12291 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
12292 if (!(action_flags &
12293 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
12294 flow_dev_get_vlan_info_from_items(items, &vlan);
12295 vlan.eth_proto = rte_be_to_cpu_16
12296 ((((const struct rte_flow_action_of_push_vlan *)
12297 actions->conf)->ethertype));
12298 found_action = mlx5_flow_find_action
12300 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
12302 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12303 found_action = mlx5_flow_find_action
12305 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
12307 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12308 if (flow_dv_create_action_push_vlan
12309 (dev, attr, &vlan, dev_flow, error))
12311 dev_flow->dv.actions[actions_n++] =
12312 dev_flow->dv.push_vlan_res->action;
12313 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
12315 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
12316 /* of_vlan_push action handled this action */
12317 MLX5_ASSERT(action_flags &
12318 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
12320 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
12321 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
12323 flow_dev_get_vlan_info_from_items(items, &vlan);
12324 mlx5_update_vlan_vid_pcp(actions, &vlan);
12325 /* If no VLAN push - this is a modify header action */
12326 if (flow_dv_convert_action_modify_vlan_vid
12327 (mhdr_res, actions, error))
12329 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
12331 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
12332 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
12333 if (flow_dv_create_action_l2_encap(dev, actions,
12338 dev_flow->dv.actions[actions_n++] =
12339 dev_flow->dv.encap_decap->action;
12340 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12341 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12342 sample_act->action_flags |=
12343 MLX5_FLOW_ACTION_ENCAP;
12345 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
12346 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
12347 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12351 dev_flow->dv.actions[actions_n++] =
12352 dev_flow->dv.encap_decap->action;
12353 action_flags |= MLX5_FLOW_ACTION_DECAP;
12355 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
12356 /* Handle encap with preceding decap. */
12357 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
12358 if (flow_dv_create_action_raw_encap
12359 (dev, actions, dev_flow, attr, error))
12361 dev_flow->dv.actions[actions_n++] =
12362 dev_flow->dv.encap_decap->action;
12364 /* Handle encap without preceding decap. */
12365 if (flow_dv_create_action_l2_encap
12366 (dev, actions, dev_flow, attr->transfer,
12369 dev_flow->dv.actions[actions_n++] =
12370 dev_flow->dv.encap_decap->action;
12372 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12373 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12374 sample_act->action_flags |=
12375 MLX5_FLOW_ACTION_ENCAP;
12377 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
12378 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
12380 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
12381 if (flow_dv_create_action_l2_decap
12382 (dev, dev_flow, attr->transfer, error))
12384 dev_flow->dv.actions[actions_n++] =
12385 dev_flow->dv.encap_decap->action;
12387 /* If decap is followed by encap, handle it at encap. */
12388 action_flags |= MLX5_FLOW_ACTION_DECAP;
12390 case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
12391 dev_flow->dv.actions[actions_n++] =
12392 (void *)(uintptr_t)action->conf;
12393 action_flags |= MLX5_FLOW_ACTION_JUMP;
12395 case RTE_FLOW_ACTION_TYPE_JUMP:
12396 jump_group = ((const struct rte_flow_action_jump *)
12397 action->conf)->group;
12398 grp_info.std_tbl_fix = 0;
12399 if (dev_flow->skip_scale &
12400 (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
12401 grp_info.skip_scale = 1;
12403 grp_info.skip_scale = 0;
12404 ret = mlx5_flow_group_to_table(dev, tunnel,
12410 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
12412 !!dev_flow->external,
12413 tunnel, jump_group, 0,
12416 return rte_flow_error_set
12418 RTE_FLOW_ERROR_TYPE_ACTION,
12420 "cannot create jump action.");
12421 if (flow_dv_jump_tbl_resource_register
12422 (dev, tbl, dev_flow, error)) {
12423 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12424 return rte_flow_error_set
12426 RTE_FLOW_ERROR_TYPE_ACTION,
12428 "cannot create jump action.");
12430 dev_flow->dv.actions[actions_n++] =
12431 dev_flow->dv.jump->action;
12432 action_flags |= MLX5_FLOW_ACTION_JUMP;
12433 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
12434 sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
12437 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
12438 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
12439 if (flow_dv_convert_action_modify_mac
12440 (mhdr_res, actions, error))
12442 action_flags |= actions->type ==
12443 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
12444 MLX5_FLOW_ACTION_SET_MAC_SRC :
12445 MLX5_FLOW_ACTION_SET_MAC_DST;
12447 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
12448 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
12449 if (flow_dv_convert_action_modify_ipv4
12450 (mhdr_res, actions, error))
12452 action_flags |= actions->type ==
12453 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
12454 MLX5_FLOW_ACTION_SET_IPV4_SRC :
12455 MLX5_FLOW_ACTION_SET_IPV4_DST;
12457 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
12458 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
12459 if (flow_dv_convert_action_modify_ipv6
12460 (mhdr_res, actions, error))
12462 action_flags |= actions->type ==
12463 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
12464 MLX5_FLOW_ACTION_SET_IPV6_SRC :
12465 MLX5_FLOW_ACTION_SET_IPV6_DST;
12467 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
12468 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
12469 if (flow_dv_convert_action_modify_tp
12470 (mhdr_res, actions, items,
12471 &flow_attr, dev_flow, !!(action_flags &
12472 MLX5_FLOW_ACTION_DECAP), error))
12474 action_flags |= actions->type ==
12475 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
12476 MLX5_FLOW_ACTION_SET_TP_SRC :
12477 MLX5_FLOW_ACTION_SET_TP_DST;
12479 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
12480 if (flow_dv_convert_action_modify_dec_ttl
12481 (mhdr_res, items, &flow_attr, dev_flow,
12483 MLX5_FLOW_ACTION_DECAP), error))
12485 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
12487 case RTE_FLOW_ACTION_TYPE_SET_TTL:
12488 if (flow_dv_convert_action_modify_ttl
12489 (mhdr_res, actions, items, &flow_attr,
12490 dev_flow, !!(action_flags &
12491 MLX5_FLOW_ACTION_DECAP), error))
12493 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
12495 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
12496 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
12497 if (flow_dv_convert_action_modify_tcp_seq
12498 (mhdr_res, actions, error))
12500 action_flags |= actions->type ==
12501 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
12502 MLX5_FLOW_ACTION_INC_TCP_SEQ :
12503 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
12506 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
12507 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
12508 if (flow_dv_convert_action_modify_tcp_ack
12509 (mhdr_res, actions, error))
12511 action_flags |= actions->type ==
12512 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
12513 MLX5_FLOW_ACTION_INC_TCP_ACK :
12514 MLX5_FLOW_ACTION_DEC_TCP_ACK;
12516 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
12517 if (flow_dv_convert_action_set_reg
12518 (mhdr_res, actions, error))
12520 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12522 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
12523 if (flow_dv_convert_action_copy_mreg
12524 (dev, mhdr_res, actions, error))
12526 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12528 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
12529 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
12530 dev_flow->handle->fate_action =
12531 MLX5_FLOW_FATE_DEFAULT_MISS;
12533 case RTE_FLOW_ACTION_TYPE_METER:
12535 return rte_flow_error_set(error, rte_errno,
12536 RTE_FLOW_ERROR_TYPE_ACTION,
12537 NULL, "Failed to get meter in flow.");
12538 /* Set the meter action. */
12539 dev_flow->dv.actions[actions_n++] =
12540 wks->fm->meter_action;
12541 action_flags |= MLX5_FLOW_ACTION_METER;
12543 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
12544 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
12547 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
12549 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
12550 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
12553 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
12555 case RTE_FLOW_ACTION_TYPE_SAMPLE:
12556 sample_act_pos = actions_n;
12557 sample = (const struct rte_flow_action_sample *)
12560 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
12561 /* put encap action into group if work with port id */
12562 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
12563 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
12564 sample_act->action_flags |=
12565 MLX5_FLOW_ACTION_ENCAP;
12567 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
12568 if (flow_dv_convert_action_modify_field
12569 (dev, mhdr_res, actions, attr, error))
12571 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
12573 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
12574 owner_idx = (uint32_t)(uintptr_t)action->conf;
12575 ct = flow_aso_ct_get_by_idx(dev, owner_idx);
12577 return rte_flow_error_set(error, EINVAL,
12578 RTE_FLOW_ERROR_TYPE_ACTION,
12580 "Failed to get CT object.");
12581 if (mlx5_aso_ct_available(priv->sh, ct))
12582 return rte_flow_error_set(error, rte_errno,
12583 RTE_FLOW_ERROR_TYPE_ACTION,
12585 "CT is unavailable.");
12586 if (ct->is_original)
12587 dev_flow->dv.actions[actions_n] =
12588 ct->dr_action_orig;
12590 dev_flow->dv.actions[actions_n] =
12591 ct->dr_action_rply;
12592 flow->indirect_type = MLX5_INDIRECT_ACTION_TYPE_CT;
12593 flow->ct = owner_idx;
12594 __atomic_fetch_add(&ct->refcnt, 1, __ATOMIC_RELAXED);
12596 action_flags |= MLX5_FLOW_ACTION_CT;
12598 case RTE_FLOW_ACTION_TYPE_END:
12599 actions_end = true;
12600 if (mhdr_res->actions_num) {
12601 /* create modify action if needed. */
12602 if (flow_dv_modify_hdr_resource_register
12603 (dev, mhdr_res, dev_flow, error))
12605 dev_flow->dv.actions[modify_action_position] =
12606 handle->dvh.modify_hdr->action;
12609 * Handle AGE and COUNT action by single HW counter
12610 * when they are not shared.
12612 if (action_flags & MLX5_FLOW_ACTION_AGE) {
12613 if ((non_shared_age &&
12614 count && !count->shared) ||
12615 !(priv->sh->flow_hit_aso_en &&
12617 /* Creates age by counters. */
12618 cnt_act = flow_dv_prepare_counter
12625 dev_flow->dv.actions[age_act_pos] =
12629 if (!flow->age && non_shared_age) {
12631 flow_dv_translate_create_aso_age
12636 return rte_flow_error_set
12638 RTE_FLOW_ERROR_TYPE_ACTION,
12640 "can't create ASO age action");
12642 age_act = flow_aso_age_get_by_idx(dev,
12644 dev_flow->dv.actions[age_act_pos] =
12645 age_act->dr_action;
12647 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
12649 * Create one count action, to be used
12650 * by all sub-flows.
12652 cnt_act = flow_dv_prepare_counter(dev, dev_flow,
12657 dev_flow->dv.actions[actions_n++] =
12663 if (mhdr_res->actions_num &&
12664 modify_action_position == UINT32_MAX)
12665 modify_action_position = actions_n++;
12667 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
12668 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
12669 int item_type = items->type;
12671 if (!mlx5_flow_os_item_supported(item_type))
12672 return rte_flow_error_set(error, ENOTSUP,
12673 RTE_FLOW_ERROR_TYPE_ITEM,
12674 NULL, "item not supported");
12675 switch (item_type) {
12676 case RTE_FLOW_ITEM_TYPE_PORT_ID:
12677 flow_dv_translate_item_port_id
12678 (dev, match_mask, match_value, items, attr);
12679 last_item = MLX5_FLOW_ITEM_PORT_ID;
12681 case RTE_FLOW_ITEM_TYPE_ETH:
12682 flow_dv_translate_item_eth(match_mask, match_value,
12684 dev_flow->dv.group);
12685 matcher.priority = action_flags &
12686 MLX5_FLOW_ACTION_DEFAULT_MISS &&
12687 !dev_flow->external ?
12688 MLX5_PRIORITY_MAP_L3 :
12689 MLX5_PRIORITY_MAP_L2;
12690 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
12691 MLX5_FLOW_LAYER_OUTER_L2;
12693 case RTE_FLOW_ITEM_TYPE_VLAN:
12694 flow_dv_translate_item_vlan(dev_flow,
12695 match_mask, match_value,
12697 dev_flow->dv.group);
12698 matcher.priority = MLX5_PRIORITY_MAP_L2;
12699 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
12700 MLX5_FLOW_LAYER_INNER_VLAN) :
12701 (MLX5_FLOW_LAYER_OUTER_L2 |
12702 MLX5_FLOW_LAYER_OUTER_VLAN);
12704 case RTE_FLOW_ITEM_TYPE_IPV4:
12705 mlx5_flow_tunnel_ip_check(items, next_protocol,
12706 &item_flags, &tunnel);
12707 flow_dv_translate_item_ipv4(match_mask, match_value,
12709 dev_flow->dv.group);
12710 matcher.priority = MLX5_PRIORITY_MAP_L3;
12711 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
12712 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
12713 if (items->mask != NULL &&
12714 ((const struct rte_flow_item_ipv4 *)
12715 items->mask)->hdr.next_proto_id) {
12717 ((const struct rte_flow_item_ipv4 *)
12718 (items->spec))->hdr.next_proto_id;
12720 ((const struct rte_flow_item_ipv4 *)
12721 (items->mask))->hdr.next_proto_id;
12723 /* Reset for inner layer. */
12724 next_protocol = 0xff;
12727 case RTE_FLOW_ITEM_TYPE_IPV6:
12728 mlx5_flow_tunnel_ip_check(items, next_protocol,
12729 &item_flags, &tunnel);
12730 flow_dv_translate_item_ipv6(match_mask, match_value,
12732 dev_flow->dv.group);
12733 matcher.priority = MLX5_PRIORITY_MAP_L3;
12734 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
12735 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
12736 if (items->mask != NULL &&
12737 ((const struct rte_flow_item_ipv6 *)
12738 items->mask)->hdr.proto) {
12740 ((const struct rte_flow_item_ipv6 *)
12741 items->spec)->hdr.proto;
12743 ((const struct rte_flow_item_ipv6 *)
12744 items->mask)->hdr.proto;
12746 /* Reset for inner layer. */
12747 next_protocol = 0xff;
12750 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
12751 flow_dv_translate_item_ipv6_frag_ext(match_mask,
12754 last_item = tunnel ?
12755 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
12756 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
12757 if (items->mask != NULL &&
12758 ((const struct rte_flow_item_ipv6_frag_ext *)
12759 items->mask)->hdr.next_header) {
12761 ((const struct rte_flow_item_ipv6_frag_ext *)
12762 items->spec)->hdr.next_header;
12764 ((const struct rte_flow_item_ipv6_frag_ext *)
12765 items->mask)->hdr.next_header;
12767 /* Reset for inner layer. */
12768 next_protocol = 0xff;
12771 case RTE_FLOW_ITEM_TYPE_TCP:
12772 flow_dv_translate_item_tcp(match_mask, match_value,
12774 matcher.priority = MLX5_PRIORITY_MAP_L4;
12775 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
12776 MLX5_FLOW_LAYER_OUTER_L4_TCP;
12778 case RTE_FLOW_ITEM_TYPE_UDP:
12779 flow_dv_translate_item_udp(match_mask, match_value,
12781 matcher.priority = MLX5_PRIORITY_MAP_L4;
12782 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
12783 MLX5_FLOW_LAYER_OUTER_L4_UDP;
12785 case RTE_FLOW_ITEM_TYPE_GRE:
12786 flow_dv_translate_item_gre(match_mask, match_value,
12788 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12789 last_item = MLX5_FLOW_LAYER_GRE;
12791 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
12792 flow_dv_translate_item_gre_key(match_mask,
12793 match_value, items);
12794 last_item = MLX5_FLOW_LAYER_GRE_KEY;
12796 case RTE_FLOW_ITEM_TYPE_NVGRE:
12797 flow_dv_translate_item_nvgre(match_mask, match_value,
12799 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12800 last_item = MLX5_FLOW_LAYER_GRE;
12802 case RTE_FLOW_ITEM_TYPE_VXLAN:
12803 flow_dv_translate_item_vxlan(match_mask, match_value,
12805 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12806 last_item = MLX5_FLOW_LAYER_VXLAN;
12808 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
12809 flow_dv_translate_item_vxlan_gpe(match_mask,
12810 match_value, items,
12812 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12813 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
12815 case RTE_FLOW_ITEM_TYPE_GENEVE:
12816 flow_dv_translate_item_geneve(match_mask, match_value,
12818 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12819 last_item = MLX5_FLOW_LAYER_GENEVE;
12821 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
12822 ret = flow_dv_translate_item_geneve_opt(dev, match_mask,
12826 return rte_flow_error_set(error, -ret,
12827 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
12828 "cannot create GENEVE TLV option");
12829 flow->geneve_tlv_option = 1;
12830 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
12832 case RTE_FLOW_ITEM_TYPE_MPLS:
12833 flow_dv_translate_item_mpls(match_mask, match_value,
12834 items, last_item, tunnel);
12835 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12836 last_item = MLX5_FLOW_LAYER_MPLS;
12838 case RTE_FLOW_ITEM_TYPE_MARK:
12839 flow_dv_translate_item_mark(dev, match_mask,
12840 match_value, items);
12841 last_item = MLX5_FLOW_ITEM_MARK;
12843 case RTE_FLOW_ITEM_TYPE_META:
12844 flow_dv_translate_item_meta(dev, match_mask,
12845 match_value, attr, items);
12846 last_item = MLX5_FLOW_ITEM_METADATA;
12848 case RTE_FLOW_ITEM_TYPE_ICMP:
12849 flow_dv_translate_item_icmp(match_mask, match_value,
12851 last_item = MLX5_FLOW_LAYER_ICMP;
12853 case RTE_FLOW_ITEM_TYPE_ICMP6:
12854 flow_dv_translate_item_icmp6(match_mask, match_value,
12856 last_item = MLX5_FLOW_LAYER_ICMP6;
12858 case RTE_FLOW_ITEM_TYPE_TAG:
12859 flow_dv_translate_item_tag(dev, match_mask,
12860 match_value, items);
12861 last_item = MLX5_FLOW_ITEM_TAG;
12863 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
12864 flow_dv_translate_mlx5_item_tag(dev, match_mask,
12865 match_value, items);
12866 last_item = MLX5_FLOW_ITEM_TAG;
12868 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
12869 flow_dv_translate_item_tx_queue(dev, match_mask,
12872 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
12874 case RTE_FLOW_ITEM_TYPE_GTP:
12875 flow_dv_translate_item_gtp(match_mask, match_value,
12877 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12878 last_item = MLX5_FLOW_LAYER_GTP;
12880 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
12881 ret = flow_dv_translate_item_gtp_psc(match_mask,
12885 return rte_flow_error_set(error, -ret,
12886 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
12887 "cannot create GTP PSC item");
12888 last_item = MLX5_FLOW_LAYER_GTP_PSC;
12890 case RTE_FLOW_ITEM_TYPE_ECPRI:
12891 if (!mlx5_flex_parser_ecpri_exist(dev)) {
12892 /* Create it only the first time to be used. */
12893 ret = mlx5_flex_parser_ecpri_alloc(dev);
12895 return rte_flow_error_set
12897 RTE_FLOW_ERROR_TYPE_ITEM,
12899 "cannot create eCPRI parser");
12901 /* Adjust the length matcher and device flow value. */
12902 matcher.mask.size = MLX5_ST_SZ_BYTES(fte_match_param);
12903 dev_flow->dv.value.size =
12904 MLX5_ST_SZ_BYTES(fte_match_param);
12905 flow_dv_translate_item_ecpri(dev, match_mask,
12906 match_value, items);
12907 /* No other protocol should follow eCPRI layer. */
12908 last_item = MLX5_FLOW_LAYER_ECPRI;
12910 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
12911 flow_dv_translate_item_integrity(match_mask,
12915 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
12916 flow_dv_translate_item_aso_ct(dev, match_mask,
12917 match_value, items);
12922 item_flags |= last_item;
12925 * When E-Switch mode is enabled, we have two cases where we need to
12926 * set the source port manually.
12927 * The first one, is in case of Nic steering rule, and the second is
12928 * E-Switch rule where no port_id item was found. In both cases
12929 * the source port is set according the current port in use.
12931 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
12932 (priv->representor || priv->master)) {
12933 if (flow_dv_translate_item_port_id(dev, match_mask,
12934 match_value, NULL, attr))
12937 #ifdef RTE_LIBRTE_MLX5_DEBUG
12938 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
12939 dev_flow->dv.value.buf));
12942 * Layers may be already initialized from prefix flow if this dev_flow
12943 * is the suffix flow.
12945 handle->layers |= item_flags;
12946 if (action_flags & MLX5_FLOW_ACTION_RSS)
12947 flow_dv_hashfields_set(dev_flow, rss_desc);
12948 /* If has RSS action in the sample action, the Sample/Mirror resource
12949 * should be registered after the hash filed be update.
12951 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
12952 ret = flow_dv_translate_action_sample(dev,
12961 ret = flow_dv_create_action_sample(dev,
12970 return rte_flow_error_set
12972 RTE_FLOW_ERROR_TYPE_ACTION,
12974 "cannot create sample action");
12975 if (num_of_dest > 1) {
12976 dev_flow->dv.actions[sample_act_pos] =
12977 dev_flow->dv.dest_array_res->action;
12979 dev_flow->dv.actions[sample_act_pos] =
12980 dev_flow->dv.sample_res->verbs_action;
12984 * For multiple destination (sample action with ratio=1), the encap
12985 * action and port id action will be combined into group action.
12986 * So need remove the original these actions in the flow and only
12987 * use the sample action instead of.
12989 if (num_of_dest > 1 &&
12990 (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
12992 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
12994 for (i = 0; i < actions_n; i++) {
12995 if ((sample_act->dr_encap_action &&
12996 sample_act->dr_encap_action ==
12997 dev_flow->dv.actions[i]) ||
12998 (sample_act->dr_port_id_action &&
12999 sample_act->dr_port_id_action ==
13000 dev_flow->dv.actions[i]) ||
13001 (sample_act->dr_jump_action &&
13002 sample_act->dr_jump_action ==
13003 dev_flow->dv.actions[i]))
13005 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
13007 memcpy((void *)dev_flow->dv.actions,
13008 (void *)temp_actions,
13009 tmp_actions_n * sizeof(void *));
13010 actions_n = tmp_actions_n;
13012 dev_flow->dv.actions_n = actions_n;
13013 dev_flow->act_flags = action_flags;
13014 if (wks->skip_matcher_reg)
13016 /* Register matcher. */
13017 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
13018 matcher.mask.size);
13019 matcher.priority = mlx5_get_matcher_priority(dev, attr,
13021 /* reserved field no needs to be set to 0 here. */
13022 tbl_key.is_fdb = attr->transfer;
13023 tbl_key.is_egress = attr->egress;
13024 tbl_key.level = dev_flow->dv.group;
13025 tbl_key.id = dev_flow->dv.table_id;
13026 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
13027 tunnel, attr->group, error))
13033 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13036 * @param[in, out] action
13037 * Shred RSS action holding hash RX queue objects.
13038 * @param[in] hash_fields
13039 * Defines combination of packet fields to participate in RX hash.
13040 * @param[in] tunnel
13042 * @param[in] hrxq_idx
13043 * Hash RX queue index to set.
13046 * 0 on success, otherwise negative errno value.
13049 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
13050 const uint64_t hash_fields,
13053 uint32_t *hrxqs = action->hrxq;
13055 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13056 case MLX5_RSS_HASH_IPV4:
13057 /* fall-through. */
13058 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13059 /* fall-through. */
13060 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13061 hrxqs[0] = hrxq_idx;
13063 case MLX5_RSS_HASH_IPV4_TCP:
13064 /* fall-through. */
13065 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13066 /* fall-through. */
13067 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13068 hrxqs[1] = hrxq_idx;
13070 case MLX5_RSS_HASH_IPV4_UDP:
13071 /* fall-through. */
13072 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13073 /* fall-through. */
13074 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13075 hrxqs[2] = hrxq_idx;
13077 case MLX5_RSS_HASH_IPV6:
13078 /* fall-through. */
13079 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13080 /* fall-through. */
13081 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13082 hrxqs[3] = hrxq_idx;
13084 case MLX5_RSS_HASH_IPV6_TCP:
13085 /* fall-through. */
13086 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13087 /* fall-through. */
13088 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13089 hrxqs[4] = hrxq_idx;
13091 case MLX5_RSS_HASH_IPV6_UDP:
13092 /* fall-through. */
13093 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13094 /* fall-through. */
13095 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13096 hrxqs[5] = hrxq_idx;
13098 case MLX5_RSS_HASH_NONE:
13099 hrxqs[6] = hrxq_idx;
13107 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13111 * Pointer to the Ethernet device structure.
13113 * Shared RSS action ID holding hash RX queue objects.
13114 * @param[in] hash_fields
13115 * Defines combination of packet fields to participate in RX hash.
13116 * @param[in] tunnel
13120 * Valid hash RX queue index, otherwise 0.
13123 __flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
13124 const uint64_t hash_fields)
13126 struct mlx5_priv *priv = dev->data->dev_private;
13127 struct mlx5_shared_action_rss *shared_rss =
13128 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
13129 const uint32_t *hrxqs = shared_rss->hrxq;
13131 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13132 case MLX5_RSS_HASH_IPV4:
13133 /* fall-through. */
13134 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13135 /* fall-through. */
13136 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13138 case MLX5_RSS_HASH_IPV4_TCP:
13139 /* fall-through. */
13140 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13141 /* fall-through. */
13142 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13144 case MLX5_RSS_HASH_IPV4_UDP:
13145 /* fall-through. */
13146 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13147 /* fall-through. */
13148 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13150 case MLX5_RSS_HASH_IPV6:
13151 /* fall-through. */
13152 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13153 /* fall-through. */
13154 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13156 case MLX5_RSS_HASH_IPV6_TCP:
13157 /* fall-through. */
13158 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13159 /* fall-through. */
13160 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13162 case MLX5_RSS_HASH_IPV6_UDP:
13163 /* fall-through. */
13164 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13165 /* fall-through. */
13166 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13168 case MLX5_RSS_HASH_NONE:
13177 * Apply the flow to the NIC, lock free,
13178 * (mutex should be acquired by caller).
13181 * Pointer to the Ethernet device structure.
13182 * @param[in, out] flow
13183 * Pointer to flow structure.
13184 * @param[out] error
13185 * Pointer to error structure.
13188 * 0 on success, a negative errno value otherwise and rte_errno is set.
13191 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
13192 struct rte_flow_error *error)
13194 struct mlx5_flow_dv_workspace *dv;
13195 struct mlx5_flow_handle *dh;
13196 struct mlx5_flow_handle_dv *dv_h;
13197 struct mlx5_flow *dev_flow;
13198 struct mlx5_priv *priv = dev->data->dev_private;
13199 uint32_t handle_idx;
13203 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13204 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
13207 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
13208 dev_flow = &wks->flows[idx];
13209 dv = &dev_flow->dv;
13210 dh = dev_flow->handle;
13213 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
13214 if (dv->transfer) {
13215 MLX5_ASSERT(priv->sh->dr_drop_action);
13216 dv->actions[n++] = priv->sh->dr_drop_action;
13218 #ifdef HAVE_MLX5DV_DR
13219 /* DR supports drop action placeholder. */
13220 MLX5_ASSERT(priv->sh->dr_drop_action);
13221 dv->actions[n++] = priv->sh->dr_drop_action;
13223 /* For DV we use the explicit drop queue. */
13224 MLX5_ASSERT(priv->drop_queue.hrxq);
13226 priv->drop_queue.hrxq->action;
13229 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
13230 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
13231 struct mlx5_hrxq *hrxq;
13234 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
13239 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13240 "cannot get hash queue");
13243 dh->rix_hrxq = hrxq_idx;
13244 dv->actions[n++] = hrxq->action;
13245 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13246 struct mlx5_hrxq *hrxq = NULL;
13249 hrxq_idx = __flow_dv_action_rss_hrxq_lookup(dev,
13250 rss_desc->shared_rss,
13251 dev_flow->hash_fields);
13253 hrxq = mlx5_ipool_get
13254 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
13259 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13260 "cannot get hash queue");
13263 dh->rix_srss = rss_desc->shared_rss;
13264 dv->actions[n++] = hrxq->action;
13265 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
13266 if (!priv->sh->default_miss_action) {
13269 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13270 "default miss action not be created.");
13273 dv->actions[n++] = priv->sh->default_miss_action;
13275 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
13276 (void *)&dv->value, n,
13277 dv->actions, &dh->drv_flow);
13279 rte_flow_error_set(error, errno,
13280 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13282 "hardware refuses to create flow");
13285 if (priv->vmwa_context &&
13286 dh->vf_vlan.tag && !dh->vf_vlan.created) {
13288 * The rule contains the VLAN pattern.
13289 * For VF we are going to create VLAN
13290 * interface to make hypervisor set correct
13291 * e-Switch vport context.
13293 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
13298 err = rte_errno; /* Save rte_errno before cleanup. */
13299 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
13300 handle_idx, dh, next) {
13301 /* hrxq is union, don't clear it if the flag is not set. */
13302 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
13303 mlx5_hrxq_release(dev, dh->rix_hrxq);
13305 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13308 if (dh->vf_vlan.tag && dh->vf_vlan.created)
13309 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
13311 rte_errno = err; /* Restore rte_errno. */
13316 flow_dv_matcher_remove_cb(struct mlx5_cache_list *list __rte_unused,
13317 struct mlx5_cache_entry *entry)
13319 struct mlx5_flow_dv_matcher *cache = container_of(entry, typeof(*cache),
13322 claim_zero(mlx5_flow_os_destroy_flow_matcher(cache->matcher_object));
13327 * Release the flow matcher.
13330 * Pointer to Ethernet device.
13332 * Index to port ID action resource.
13335 * 1 while a reference on it exists, 0 when freed.
13338 flow_dv_matcher_release(struct rte_eth_dev *dev,
13339 struct mlx5_flow_handle *handle)
13341 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
13342 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
13343 typeof(*tbl), tbl);
13346 MLX5_ASSERT(matcher->matcher_object);
13347 ret = mlx5_cache_unregister(&tbl->matchers, &matcher->entry);
13348 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
13353 * Release encap_decap resource.
13356 * Pointer to the hash list.
13358 * Pointer to exist resource entry object.
13361 flow_dv_encap_decap_remove_cb(struct mlx5_hlist *list,
13362 struct mlx5_hlist_entry *entry)
13364 struct mlx5_dev_ctx_shared *sh = list->ctx;
13365 struct mlx5_flow_dv_encap_decap_resource *res =
13366 container_of(entry, typeof(*res), entry);
13368 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13369 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
13373 * Release an encap/decap resource.
13376 * Pointer to Ethernet device.
13377 * @param encap_decap_idx
13378 * Index of encap decap resource.
13381 * 1 while a reference on it exists, 0 when freed.
13384 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
13385 uint32_t encap_decap_idx)
13387 struct mlx5_priv *priv = dev->data->dev_private;
13388 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
13390 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
13392 if (!cache_resource)
13394 MLX5_ASSERT(cache_resource->action);
13395 return mlx5_hlist_unregister(priv->sh->encaps_decaps,
13396 &cache_resource->entry);
13400 * Release an jump to table action resource.
13403 * Pointer to Ethernet device.
13405 * Index to the jump action resource.
13408 * 1 while a reference on it exists, 0 when freed.
13411 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
13414 struct mlx5_priv *priv = dev->data->dev_private;
13415 struct mlx5_flow_tbl_data_entry *tbl_data;
13417 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
13421 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
13425 flow_dv_modify_remove_cb(struct mlx5_hlist *list __rte_unused,
13426 struct mlx5_hlist_entry *entry)
13428 struct mlx5_flow_dv_modify_hdr_resource *res =
13429 container_of(entry, typeof(*res), entry);
13431 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13436 * Release a modify-header resource.
13439 * Pointer to Ethernet device.
13441 * Pointer to mlx5_flow_handle.
13444 * 1 while a reference on it exists, 0 when freed.
13447 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
13448 struct mlx5_flow_handle *handle)
13450 struct mlx5_priv *priv = dev->data->dev_private;
13451 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
13453 MLX5_ASSERT(entry->action);
13454 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
13458 flow_dv_port_id_remove_cb(struct mlx5_cache_list *list,
13459 struct mlx5_cache_entry *entry)
13461 struct mlx5_dev_ctx_shared *sh = list->ctx;
13462 struct mlx5_flow_dv_port_id_action_resource *cache =
13463 container_of(entry, typeof(*cache), entry);
13465 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
13466 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], cache->idx);
13470 * Release port ID action resource.
13473 * Pointer to Ethernet device.
13475 * Pointer to mlx5_flow_handle.
13478 * 1 while a reference on it exists, 0 when freed.
13481 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
13484 struct mlx5_priv *priv = dev->data->dev_private;
13485 struct mlx5_flow_dv_port_id_action_resource *cache;
13487 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
13490 MLX5_ASSERT(cache->action);
13491 return mlx5_cache_unregister(&priv->sh->port_id_action_list,
13496 * Release shared RSS action resource.
13499 * Pointer to Ethernet device.
13501 * Shared RSS action index.
13504 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
13506 struct mlx5_priv *priv = dev->data->dev_private;
13507 struct mlx5_shared_action_rss *shared_rss;
13509 shared_rss = mlx5_ipool_get
13510 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
13511 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
13515 flow_dv_push_vlan_remove_cb(struct mlx5_cache_list *list,
13516 struct mlx5_cache_entry *entry)
13518 struct mlx5_dev_ctx_shared *sh = list->ctx;
13519 struct mlx5_flow_dv_push_vlan_action_resource *cache =
13520 container_of(entry, typeof(*cache), entry);
13522 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
13523 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], cache->idx);
13527 * Release push vlan action resource.
13530 * Pointer to Ethernet device.
13532 * Pointer to mlx5_flow_handle.
13535 * 1 while a reference on it exists, 0 when freed.
13538 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
13539 struct mlx5_flow_handle *handle)
13541 struct mlx5_priv *priv = dev->data->dev_private;
13542 struct mlx5_flow_dv_push_vlan_action_resource *cache;
13543 uint32_t idx = handle->dvh.rix_push_vlan;
13545 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
13548 MLX5_ASSERT(cache->action);
13549 return mlx5_cache_unregister(&priv->sh->push_vlan_action_list,
13554 * Release the fate resource.
13557 * Pointer to Ethernet device.
13559 * Pointer to mlx5_flow_handle.
13562 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
13563 struct mlx5_flow_handle *handle)
13565 if (!handle->rix_fate)
13567 switch (handle->fate_action) {
13568 case MLX5_FLOW_FATE_QUEUE:
13569 if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
13570 mlx5_hrxq_release(dev, handle->rix_hrxq);
13572 case MLX5_FLOW_FATE_JUMP:
13573 flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
13575 case MLX5_FLOW_FATE_PORT_ID:
13576 flow_dv_port_id_action_resource_release(dev,
13577 handle->rix_port_id_action);
13580 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
13583 handle->rix_fate = 0;
13587 flow_dv_sample_remove_cb(struct mlx5_cache_list *list __rte_unused,
13588 struct mlx5_cache_entry *entry)
13590 struct mlx5_flow_dv_sample_resource *cache_resource =
13591 container_of(entry, typeof(*cache_resource), entry);
13592 struct rte_eth_dev *dev = cache_resource->dev;
13593 struct mlx5_priv *priv = dev->data->dev_private;
13595 if (cache_resource->verbs_action)
13596 claim_zero(mlx5_flow_os_destroy_flow_action
13597 (cache_resource->verbs_action));
13598 if (cache_resource->normal_path_tbl)
13599 flow_dv_tbl_resource_release(MLX5_SH(dev),
13600 cache_resource->normal_path_tbl);
13601 flow_dv_sample_sub_actions_release(dev,
13602 &cache_resource->sample_idx);
13603 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
13604 cache_resource->idx);
13605 DRV_LOG(DEBUG, "sample resource %p: removed",
13606 (void *)cache_resource);
13610 * Release an sample resource.
13613 * Pointer to Ethernet device.
13615 * Pointer to mlx5_flow_handle.
13618 * 1 while a reference on it exists, 0 when freed.
13621 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
13622 struct mlx5_flow_handle *handle)
13624 struct mlx5_priv *priv = dev->data->dev_private;
13625 struct mlx5_flow_dv_sample_resource *cache_resource;
13627 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
13628 handle->dvh.rix_sample);
13629 if (!cache_resource)
13631 MLX5_ASSERT(cache_resource->verbs_action);
13632 return mlx5_cache_unregister(&priv->sh->sample_action_list,
13633 &cache_resource->entry);
13637 flow_dv_dest_array_remove_cb(struct mlx5_cache_list *list __rte_unused,
13638 struct mlx5_cache_entry *entry)
13640 struct mlx5_flow_dv_dest_array_resource *cache_resource =
13641 container_of(entry, typeof(*cache_resource), entry);
13642 struct rte_eth_dev *dev = cache_resource->dev;
13643 struct mlx5_priv *priv = dev->data->dev_private;
13646 MLX5_ASSERT(cache_resource->action);
13647 if (cache_resource->action)
13648 claim_zero(mlx5_flow_os_destroy_flow_action
13649 (cache_resource->action));
13650 for (; i < cache_resource->num_of_dest; i++)
13651 flow_dv_sample_sub_actions_release(dev,
13652 &cache_resource->sample_idx[i]);
13653 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
13654 cache_resource->idx);
13655 DRV_LOG(DEBUG, "destination array resource %p: removed",
13656 (void *)cache_resource);
13660 * Release an destination array resource.
13663 * Pointer to Ethernet device.
13665 * Pointer to mlx5_flow_handle.
13668 * 1 while a reference on it exists, 0 when freed.
13671 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
13672 struct mlx5_flow_handle *handle)
13674 struct mlx5_priv *priv = dev->data->dev_private;
13675 struct mlx5_flow_dv_dest_array_resource *cache;
13677 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
13678 handle->dvh.rix_dest_array);
13681 MLX5_ASSERT(cache->action);
13682 return mlx5_cache_unregister(&priv->sh->dest_array_list,
13687 flow_dv_geneve_tlv_option_resource_release(struct rte_eth_dev *dev)
13689 struct mlx5_priv *priv = dev->data->dev_private;
13690 struct mlx5_dev_ctx_shared *sh = priv->sh;
13691 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
13692 sh->geneve_tlv_option_resource;
13693 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
13694 if (geneve_opt_resource) {
13695 if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
13696 __ATOMIC_RELAXED))) {
13697 claim_zero(mlx5_devx_cmd_destroy
13698 (geneve_opt_resource->obj));
13699 mlx5_free(sh->geneve_tlv_option_resource);
13700 sh->geneve_tlv_option_resource = NULL;
13703 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
13707 * Remove the flow from the NIC but keeps it in memory.
13708 * Lock free, (mutex should be acquired by caller).
13711 * Pointer to Ethernet device.
13712 * @param[in, out] flow
13713 * Pointer to flow structure.
13716 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
13718 struct mlx5_flow_handle *dh;
13719 uint32_t handle_idx;
13720 struct mlx5_priv *priv = dev->data->dev_private;
13724 handle_idx = flow->dev_handles;
13725 while (handle_idx) {
13726 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
13730 if (dh->drv_flow) {
13731 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
13732 dh->drv_flow = NULL;
13734 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
13735 flow_dv_fate_resource_release(dev, dh);
13736 if (dh->vf_vlan.tag && dh->vf_vlan.created)
13737 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
13738 handle_idx = dh->next.next;
13743 * Remove the flow from the NIC and the memory.
13744 * Lock free, (mutex should be acquired by caller).
13747 * Pointer to the Ethernet device structure.
13748 * @param[in, out] flow
13749 * Pointer to flow structure.
13752 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
13754 struct mlx5_flow_handle *dev_handle;
13755 struct mlx5_priv *priv = dev->data->dev_private;
13756 struct mlx5_flow_meter_info *fm = NULL;
13761 flow_dv_remove(dev, flow);
13762 if (flow->counter) {
13763 flow_dv_counter_free(dev, flow->counter);
13767 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
13769 mlx5_flow_meter_detach(priv, fm);
13772 /* Keep the current age handling by default. */
13773 if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
13774 flow_dv_aso_ct_release(dev, flow->ct);
13775 else if (flow->age)
13776 flow_dv_aso_age_release(dev, flow->age);
13777 if (flow->geneve_tlv_option) {
13778 flow_dv_geneve_tlv_option_resource_release(dev);
13779 flow->geneve_tlv_option = 0;
13781 while (flow->dev_handles) {
13782 uint32_t tmp_idx = flow->dev_handles;
13784 dev_handle = mlx5_ipool_get(priv->sh->ipool
13785 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
13788 flow->dev_handles = dev_handle->next.next;
13789 if (dev_handle->dvh.matcher)
13790 flow_dv_matcher_release(dev, dev_handle);
13791 if (dev_handle->dvh.rix_sample)
13792 flow_dv_sample_resource_release(dev, dev_handle);
13793 if (dev_handle->dvh.rix_dest_array)
13794 flow_dv_dest_array_resource_release(dev, dev_handle);
13795 if (dev_handle->dvh.rix_encap_decap)
13796 flow_dv_encap_decap_resource_release(dev,
13797 dev_handle->dvh.rix_encap_decap);
13798 if (dev_handle->dvh.modify_hdr)
13799 flow_dv_modify_hdr_resource_release(dev, dev_handle);
13800 if (dev_handle->dvh.rix_push_vlan)
13801 flow_dv_push_vlan_action_resource_release(dev,
13803 if (dev_handle->dvh.rix_tag)
13804 flow_dv_tag_release(dev,
13805 dev_handle->dvh.rix_tag);
13806 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
13807 flow_dv_fate_resource_release(dev, dev_handle);
13809 srss = dev_handle->rix_srss;
13810 if (fm && dev_handle->is_meter_flow_id &&
13811 dev_handle->split_flow_id)
13812 mlx5_ipool_free(fm->flow_ipool,
13813 dev_handle->split_flow_id);
13814 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
13818 flow_dv_shared_rss_action_release(dev, srss);
13822 * Release array of hash RX queue objects.
13826 * Pointer to the Ethernet device structure.
13827 * @param[in, out] hrxqs
13828 * Array of hash RX queue objects.
13831 * Total number of references to hash RX queue objects in *hrxqs* array
13832 * after this operation.
13835 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
13836 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
13841 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
13842 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
13852 * Release all hash RX queue objects representing shared RSS action.
13855 * Pointer to the Ethernet device structure.
13856 * @param[in, out] action
13857 * Shared RSS action to remove hash RX queue objects from.
13860 * Total number of references to hash RX queue objects stored in *action*
13861 * after this operation.
13862 * Expected to be 0 if no external references held.
13865 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
13866 struct mlx5_shared_action_rss *shared_rss)
13868 return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
13872 * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
13875 * Only one hash value is available for one L3+L4 combination:
13877 * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
13878 * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
13879 * same slot in mlx5_rss_hash_fields.
13882 * Pointer to the shared action RSS conf.
13883 * @param[in, out] hash_field
13884 * hash_field variable needed to be adjusted.
13890 __flow_dv_action_rss_l34_hash_adjust(struct mlx5_shared_action_rss *rss,
13891 uint64_t *hash_field)
13893 uint64_t rss_types = rss->origin.types;
13895 switch (*hash_field & ~IBV_RX_HASH_INNER) {
13896 case MLX5_RSS_HASH_IPV4:
13897 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
13898 *hash_field &= ~MLX5_RSS_HASH_IPV4;
13899 if (rss_types & ETH_RSS_L3_DST_ONLY)
13900 *hash_field |= IBV_RX_HASH_DST_IPV4;
13901 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
13902 *hash_field |= IBV_RX_HASH_SRC_IPV4;
13904 *hash_field |= MLX5_RSS_HASH_IPV4;
13907 case MLX5_RSS_HASH_IPV6:
13908 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
13909 *hash_field &= ~MLX5_RSS_HASH_IPV6;
13910 if (rss_types & ETH_RSS_L3_DST_ONLY)
13911 *hash_field |= IBV_RX_HASH_DST_IPV6;
13912 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
13913 *hash_field |= IBV_RX_HASH_SRC_IPV6;
13915 *hash_field |= MLX5_RSS_HASH_IPV6;
13918 case MLX5_RSS_HASH_IPV4_UDP:
13919 /* fall-through. */
13920 case MLX5_RSS_HASH_IPV6_UDP:
13921 if (rss_types & ETH_RSS_UDP) {
13922 *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
13923 if (rss_types & ETH_RSS_L4_DST_ONLY)
13924 *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
13925 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
13926 *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
13928 *hash_field |= MLX5_UDP_IBV_RX_HASH;
13931 case MLX5_RSS_HASH_IPV4_TCP:
13932 /* fall-through. */
13933 case MLX5_RSS_HASH_IPV6_TCP:
13934 if (rss_types & ETH_RSS_TCP) {
13935 *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
13936 if (rss_types & ETH_RSS_L4_DST_ONLY)
13937 *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
13938 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
13939 *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
13941 *hash_field |= MLX5_TCP_IBV_RX_HASH;
13950 * Setup shared RSS action.
13951 * Prepare set of hash RX queue objects sufficient to handle all valid
13952 * hash_fields combinations (see enum ibv_rx_hash_fields).
13955 * Pointer to the Ethernet device structure.
13956 * @param[in] action_idx
13957 * Shared RSS action ipool index.
13958 * @param[in, out] action
13959 * Partially initialized shared RSS action.
13960 * @param[out] error
13961 * Perform verbose error reporting if not NULL. Initialized in case of
13965 * 0 on success, otherwise negative errno value.
13968 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
13969 uint32_t action_idx,
13970 struct mlx5_shared_action_rss *shared_rss,
13971 struct rte_flow_error *error)
13973 struct mlx5_flow_rss_desc rss_desc = { 0 };
13977 if (mlx5_ind_table_obj_setup(dev, shared_rss->ind_tbl)) {
13978 return rte_flow_error_set(error, rte_errno,
13979 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13980 "cannot setup indirection table");
13982 memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
13983 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
13984 rss_desc.const_q = shared_rss->origin.queue;
13985 rss_desc.queue_num = shared_rss->origin.queue_num;
13986 /* Set non-zero value to indicate a shared RSS. */
13987 rss_desc.shared_rss = action_idx;
13988 rss_desc.ind_tbl = shared_rss->ind_tbl;
13989 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
13991 uint64_t hash_fields = mlx5_rss_hash_fields[i];
13994 __flow_dv_action_rss_l34_hash_adjust(shared_rss, &hash_fields);
13995 if (shared_rss->origin.level > 1) {
13996 hash_fields |= IBV_RX_HASH_INNER;
13999 rss_desc.tunnel = tunnel;
14000 rss_desc.hash_fields = hash_fields;
14001 hrxq_idx = mlx5_hrxq_get(dev, &rss_desc);
14005 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14006 "cannot get hash queue");
14007 goto error_hrxq_new;
14009 err = __flow_dv_action_rss_hrxq_set
14010 (shared_rss, hash_fields, hrxq_idx);
14016 __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14017 if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
14018 shared_rss->ind_tbl = NULL;
14024 * Create shared RSS action.
14027 * Pointer to the Ethernet device structure.
14029 * Shared action configuration.
14031 * RSS action specification used to create shared action.
14032 * @param[out] error
14033 * Perform verbose error reporting if not NULL. Initialized in case of
14037 * A valid shared action ID in case of success, 0 otherwise and
14038 * rte_errno is set.
14041 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
14042 const struct rte_flow_indir_action_conf *conf,
14043 const struct rte_flow_action_rss *rss,
14044 struct rte_flow_error *error)
14046 struct mlx5_priv *priv = dev->data->dev_private;
14047 struct mlx5_shared_action_rss *shared_rss = NULL;
14048 void *queue = NULL;
14049 struct rte_flow_action_rss *origin;
14050 const uint8_t *rss_key;
14051 uint32_t queue_size = rss->queue_num * sizeof(uint16_t);
14054 RTE_SET_USED(conf);
14055 queue = mlx5_malloc(0, RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14057 shared_rss = mlx5_ipool_zmalloc
14058 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
14059 if (!shared_rss || !queue) {
14060 rte_flow_error_set(error, ENOMEM,
14061 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14062 "cannot allocate resource memory");
14063 goto error_rss_init;
14065 if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
14066 rte_flow_error_set(error, E2BIG,
14067 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14068 "rss action number out of range");
14069 goto error_rss_init;
14071 shared_rss->ind_tbl = mlx5_malloc(MLX5_MEM_ZERO,
14072 sizeof(*shared_rss->ind_tbl),
14074 if (!shared_rss->ind_tbl) {
14075 rte_flow_error_set(error, ENOMEM,
14076 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14077 "cannot allocate resource memory");
14078 goto error_rss_init;
14080 memcpy(queue, rss->queue, queue_size);
14081 shared_rss->ind_tbl->queues = queue;
14082 shared_rss->ind_tbl->queues_n = rss->queue_num;
14083 origin = &shared_rss->origin;
14084 origin->func = rss->func;
14085 origin->level = rss->level;
14086 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
14087 origin->types = !rss->types ? ETH_RSS_IP : rss->types;
14088 /* NULL RSS key indicates default RSS key. */
14089 rss_key = !rss->key ? rss_hash_default_key : rss->key;
14090 memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
14091 origin->key = &shared_rss->key[0];
14092 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
14093 origin->queue = queue;
14094 origin->queue_num = rss->queue_num;
14095 if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
14096 goto error_rss_init;
14097 rte_spinlock_init(&shared_rss->action_rss_sl);
14098 __atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14099 rte_spinlock_lock(&priv->shared_act_sl);
14100 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14101 &priv->rss_shared_actions, idx, shared_rss, next);
14102 rte_spinlock_unlock(&priv->shared_act_sl);
14106 if (shared_rss->ind_tbl)
14107 mlx5_free(shared_rss->ind_tbl);
14108 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14117 * Destroy the shared RSS action.
14118 * Release related hash RX queue objects.
14121 * Pointer to the Ethernet device structure.
14123 * The shared RSS action object ID to be removed.
14124 * @param[out] error
14125 * Perform verbose error reporting if not NULL. Initialized in case of
14129 * 0 on success, otherwise negative errno value.
14132 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
14133 struct rte_flow_error *error)
14135 struct mlx5_priv *priv = dev->data->dev_private;
14136 struct mlx5_shared_action_rss *shared_rss =
14137 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14138 uint32_t old_refcnt = 1;
14140 uint16_t *queue = NULL;
14143 return rte_flow_error_set(error, EINVAL,
14144 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14145 "invalid shared action");
14146 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14148 return rte_flow_error_set(error, EBUSY,
14149 RTE_FLOW_ERROR_TYPE_ACTION,
14151 "shared rss hrxq has references");
14152 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
14153 0, 0, __ATOMIC_ACQUIRE,
14155 return rte_flow_error_set(error, EBUSY,
14156 RTE_FLOW_ERROR_TYPE_ACTION,
14158 "shared rss has references");
14159 queue = shared_rss->ind_tbl->queues;
14160 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true);
14162 return rte_flow_error_set(error, EBUSY,
14163 RTE_FLOW_ERROR_TYPE_ACTION,
14165 "shared rss indirection table has"
14168 rte_spinlock_lock(&priv->shared_act_sl);
14169 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14170 &priv->rss_shared_actions, idx, shared_rss, next);
14171 rte_spinlock_unlock(&priv->shared_act_sl);
14172 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14178 * Create indirect action, lock free,
14179 * (mutex should be acquired by caller).
14180 * Dispatcher for action type specific call.
14183 * Pointer to the Ethernet device structure.
14185 * Shared action configuration.
14186 * @param[in] action
14187 * Action specification used to create indirect action.
14188 * @param[out] error
14189 * Perform verbose error reporting if not NULL. Initialized in case of
14193 * A valid shared action handle in case of success, NULL otherwise and
14194 * rte_errno is set.
14196 static struct rte_flow_action_handle *
14197 flow_dv_action_create(struct rte_eth_dev *dev,
14198 const struct rte_flow_indir_action_conf *conf,
14199 const struct rte_flow_action *action,
14200 struct rte_flow_error *err)
14204 struct mlx5_priv *priv = dev->data->dev_private;
14206 switch (action->type) {
14207 case RTE_FLOW_ACTION_TYPE_RSS:
14208 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
14209 idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
14210 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14212 case RTE_FLOW_ACTION_TYPE_AGE:
14213 ret = flow_dv_translate_create_aso_age(dev, action->conf, err);
14214 idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
14215 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14217 struct mlx5_aso_age_action *aso_age =
14218 flow_aso_age_get_by_idx(dev, ret);
14220 if (!aso_age->age_params.context)
14221 aso_age->age_params.context =
14222 (void *)(uintptr_t)idx;
14225 case RTE_FLOW_ACTION_TYPE_COUNT:
14226 ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
14227 idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
14228 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14230 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
14231 ret = flow_dv_translate_create_conntrack(dev, action->conf,
14233 idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
14236 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
14237 NULL, "action type not supported");
14240 return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
14244 * Destroy the indirect action.
14245 * Release action related resources on the NIC and the memory.
14246 * Lock free, (mutex should be acquired by caller).
14247 * Dispatcher for action type specific call.
14250 * Pointer to the Ethernet device structure.
14251 * @param[in] handle
14252 * The indirect action object handle to be removed.
14253 * @param[out] error
14254 * Perform verbose error reporting if not NULL. Initialized in case of
14258 * 0 on success, otherwise negative errno value.
14261 flow_dv_action_destroy(struct rte_eth_dev *dev,
14262 struct rte_flow_action_handle *handle,
14263 struct rte_flow_error *error)
14265 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14266 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14267 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
14268 struct mlx5_flow_counter *cnt;
14269 uint32_t no_flow_refcnt = 1;
14273 case MLX5_INDIRECT_ACTION_TYPE_RSS:
14274 return __flow_dv_action_rss_release(dev, idx, error);
14275 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
14276 cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
14277 if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
14278 &no_flow_refcnt, 1, false,
14281 return rte_flow_error_set(error, EBUSY,
14282 RTE_FLOW_ERROR_TYPE_ACTION,
14284 "Indirect count action has references");
14285 flow_dv_counter_free(dev, idx);
14287 case MLX5_INDIRECT_ACTION_TYPE_AGE:
14288 ret = flow_dv_aso_age_release(dev, idx);
14291 * In this case, the last flow has a reference will
14292 * actually release the age action.
14294 DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
14295 " released with references %d.", idx, ret);
14297 case MLX5_INDIRECT_ACTION_TYPE_CT:
14298 ret = flow_dv_aso_ct_release(dev, idx);
14302 DRV_LOG(DEBUG, "Connection tracking object %u still "
14303 "has references %d.", idx, ret);
14306 return rte_flow_error_set(error, ENOTSUP,
14307 RTE_FLOW_ERROR_TYPE_ACTION,
14309 "action type not supported");
14314 * Updates in place shared RSS action configuration.
14317 * Pointer to the Ethernet device structure.
14319 * The shared RSS action object ID to be updated.
14320 * @param[in] action_conf
14321 * RSS action specification used to modify *shared_rss*.
14322 * @param[out] error
14323 * Perform verbose error reporting if not NULL. Initialized in case of
14327 * 0 on success, otherwise negative errno value.
14328 * @note: currently only support update of RSS queues.
14331 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
14332 const struct rte_flow_action_rss *action_conf,
14333 struct rte_flow_error *error)
14335 struct mlx5_priv *priv = dev->data->dev_private;
14336 struct mlx5_shared_action_rss *shared_rss =
14337 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14339 void *queue = NULL;
14340 uint16_t *queue_old = NULL;
14341 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
14344 return rte_flow_error_set(error, EINVAL,
14345 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14346 "invalid shared action to update");
14347 if (priv->obj_ops.ind_table_modify == NULL)
14348 return rte_flow_error_set(error, ENOTSUP,
14349 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14350 "cannot modify indirection table");
14351 queue = mlx5_malloc(MLX5_MEM_ZERO,
14352 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14355 return rte_flow_error_set(error, ENOMEM,
14356 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14358 "cannot allocate resource memory");
14359 memcpy(queue, action_conf->queue, queue_size);
14360 MLX5_ASSERT(shared_rss->ind_tbl);
14361 rte_spinlock_lock(&shared_rss->action_rss_sl);
14362 queue_old = shared_rss->ind_tbl->queues;
14363 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
14364 queue, action_conf->queue_num, true);
14367 ret = rte_flow_error_set(error, rte_errno,
14368 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14369 "cannot update indirection table");
14371 mlx5_free(queue_old);
14372 shared_rss->origin.queue = queue;
14373 shared_rss->origin.queue_num = action_conf->queue_num;
14375 rte_spinlock_unlock(&shared_rss->action_rss_sl);
14380 * Updates in place conntrack context or direction.
14381 * Context update should be synchronized.
14384 * Pointer to the Ethernet device structure.
14386 * The conntrack object ID to be updated.
14387 * @param[in] update
14388 * Pointer to the structure of information to update.
14389 * @param[out] error
14390 * Perform verbose error reporting if not NULL. Initialized in case of
14394 * 0 on success, otherwise negative errno value.
14397 __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
14398 const struct rte_flow_modify_conntrack *update,
14399 struct rte_flow_error *error)
14401 struct mlx5_priv *priv = dev->data->dev_private;
14402 struct mlx5_aso_ct_action *ct;
14403 const struct rte_flow_action_conntrack *new_prf;
14405 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
14408 if (PORT_ID(priv) != owner)
14409 return rte_flow_error_set(error, EACCES,
14410 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14412 "CT object owned by another port");
14413 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
14414 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
14416 return rte_flow_error_set(error, ENOMEM,
14417 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14419 "CT object is inactive");
14420 new_prf = &update->new_ct;
14421 if (update->direction)
14422 ct->is_original = !!new_prf->is_original_dir;
14423 if (update->state) {
14424 /* Only validate the profile when it needs to be updated. */
14425 ret = mlx5_validate_action_ct(dev, new_prf, error);
14428 ret = mlx5_aso_ct_update_by_wqe(priv->sh, ct, new_prf);
14430 return rte_flow_error_set(error, EIO,
14431 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14433 "Failed to send CT context update WQE");
14434 /* Block until ready or a failure. */
14435 ret = mlx5_aso_ct_available(priv->sh, ct);
14437 rte_flow_error_set(error, rte_errno,
14438 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14440 "Timeout to get the CT update");
14446 * Updates in place shared action configuration, lock free,
14447 * (mutex should be acquired by caller).
14450 * Pointer to the Ethernet device structure.
14451 * @param[in] handle
14452 * The indirect action object handle to be updated.
14453 * @param[in] update
14454 * Action specification used to modify the action pointed by *handle*.
14455 * *update* could be of same type with the action pointed by the *handle*
14456 * handle argument, or some other structures like a wrapper, depending on
14457 * the indirect action type.
14458 * @param[out] error
14459 * Perform verbose error reporting if not NULL. Initialized in case of
14463 * 0 on success, otherwise negative errno value.
14466 flow_dv_action_update(struct rte_eth_dev *dev,
14467 struct rte_flow_action_handle *handle,
14468 const void *update,
14469 struct rte_flow_error *err)
14471 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14472 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14473 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
14474 const void *action_conf;
14477 case MLX5_INDIRECT_ACTION_TYPE_RSS:
14478 action_conf = ((const struct rte_flow_action *)update)->conf;
14479 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
14480 case MLX5_INDIRECT_ACTION_TYPE_CT:
14481 return __flow_dv_action_ct_update(dev, idx, update, err);
14483 return rte_flow_error_set(err, ENOTSUP,
14484 RTE_FLOW_ERROR_TYPE_ACTION,
14486 "action type update not supported");
14491 * Destroy the meter sub policy table rules.
14492 * Lock free, (mutex should be acquired by caller).
14495 * Pointer to Ethernet device.
14496 * @param[in] sub_policy
14497 * Pointer to meter sub policy table.
14500 __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
14501 struct mlx5_flow_meter_sub_policy *sub_policy)
14503 struct mlx5_flow_tbl_data_entry *tbl;
14506 for (i = 0; i < RTE_COLORS; i++) {
14507 if (sub_policy->color_rule[i]) {
14508 claim_zero(mlx5_flow_os_destroy_flow
14509 (sub_policy->color_rule[i]));
14510 sub_policy->color_rule[i] = NULL;
14512 if (sub_policy->color_matcher[i]) {
14513 tbl = container_of(sub_policy->color_matcher[i]->tbl,
14514 typeof(*tbl), tbl);
14515 mlx5_cache_unregister(&tbl->matchers,
14516 &sub_policy->color_matcher[i]->entry);
14517 sub_policy->color_matcher[i] = NULL;
14520 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
14521 if (sub_policy->rix_hrxq[i]) {
14522 mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
14523 sub_policy->rix_hrxq[i] = 0;
14525 if (sub_policy->jump_tbl[i]) {
14526 flow_dv_tbl_resource_release(MLX5_SH(dev),
14527 sub_policy->jump_tbl[i]);
14528 sub_policy->jump_tbl[i] = NULL;
14531 if (sub_policy->tbl_rsc) {
14532 flow_dv_tbl_resource_release(MLX5_SH(dev),
14533 sub_policy->tbl_rsc);
14534 sub_policy->tbl_rsc = NULL;
14539 * Destroy policy rules, lock free,
14540 * (mutex should be acquired by caller).
14541 * Dispatcher for action type specific call.
14544 * Pointer to the Ethernet device structure.
14545 * @param[in] mtr_policy
14546 * Meter policy struct.
14549 flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
14550 struct mlx5_flow_meter_policy *mtr_policy)
14553 struct mlx5_flow_meter_sub_policy *sub_policy;
14554 uint16_t sub_policy_num;
14556 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
14557 sub_policy_num = (mtr_policy->sub_policy_num >>
14558 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
14559 MLX5_MTR_SUB_POLICY_NUM_MASK;
14560 for (j = 0; j < sub_policy_num; j++) {
14561 sub_policy = mtr_policy->sub_policys[i][j];
14563 __flow_dv_destroy_sub_policy_rules
14570 * Destroy policy action, lock free,
14571 * (mutex should be acquired by caller).
14572 * Dispatcher for action type specific call.
14575 * Pointer to the Ethernet device structure.
14576 * @param[in] mtr_policy
14577 * Meter policy struct.
14580 flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
14581 struct mlx5_flow_meter_policy *mtr_policy)
14583 struct rte_flow_action *rss_action;
14584 struct mlx5_flow_handle dev_handle;
14587 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
14588 if (mtr_policy->act_cnt[i].rix_mark) {
14589 flow_dv_tag_release(dev,
14590 mtr_policy->act_cnt[i].rix_mark);
14591 mtr_policy->act_cnt[i].rix_mark = 0;
14593 if (mtr_policy->act_cnt[i].modify_hdr) {
14594 dev_handle.dvh.modify_hdr =
14595 mtr_policy->act_cnt[i].modify_hdr;
14596 flow_dv_modify_hdr_resource_release(dev, &dev_handle);
14598 switch (mtr_policy->act_cnt[i].fate_action) {
14599 case MLX5_FLOW_FATE_SHARED_RSS:
14600 rss_action = mtr_policy->act_cnt[i].rss;
14601 mlx5_free(rss_action);
14603 case MLX5_FLOW_FATE_PORT_ID:
14604 if (mtr_policy->act_cnt[i].rix_port_id_action) {
14605 flow_dv_port_id_action_resource_release(dev,
14606 mtr_policy->act_cnt[i].rix_port_id_action);
14607 mtr_policy->act_cnt[i].rix_port_id_action = 0;
14610 case MLX5_FLOW_FATE_DROP:
14611 case MLX5_FLOW_FATE_JUMP:
14612 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
14613 mtr_policy->act_cnt[i].dr_jump_action[j] =
14617 /*Queue action do nothing*/
14621 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
14622 mtr_policy->dr_drop_action[j] = NULL;
14626 * Create policy action per domain, lock free,
14627 * (mutex should be acquired by caller).
14628 * Dispatcher for action type specific call.
14631 * Pointer to the Ethernet device structure.
14632 * @param[in] mtr_policy
14633 * Meter policy struct.
14634 * @param[in] action
14635 * Action specification used to create meter actions.
14636 * @param[out] error
14637 * Perform verbose error reporting if not NULL. Initialized in case of
14641 * 0 on success, otherwise negative errno value.
14644 __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
14645 struct mlx5_flow_meter_policy *mtr_policy,
14646 const struct rte_flow_action *actions[RTE_COLORS],
14647 enum mlx5_meter_domain domain,
14648 struct rte_mtr_error *error)
14650 struct mlx5_priv *priv = dev->data->dev_private;
14651 struct rte_flow_error flow_err;
14652 const struct rte_flow_action *act;
14653 uint64_t action_flags = 0;
14654 struct mlx5_flow_handle dh;
14655 struct mlx5_flow dev_flow;
14656 struct mlx5_flow_dv_port_id_action_resource port_id_action;
14658 uint8_t egress, transfer;
14659 struct mlx5_meter_policy_action_container *act_cnt = NULL;
14661 struct mlx5_flow_dv_modify_hdr_resource res;
14662 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
14663 sizeof(struct mlx5_modification_cmd) *
14664 (MLX5_MAX_MODIFY_NUM + 1)];
14667 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
14668 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
14669 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
14670 memset(&dev_flow, 0, sizeof(struct mlx5_flow));
14671 memset(&port_id_action, 0,
14672 sizeof(struct mlx5_flow_dv_port_id_action_resource));
14673 dev_flow.handle = &dh;
14674 dev_flow.dv.port_id_action = &port_id_action;
14675 dev_flow.external = true;
14676 for (i = 0; i < RTE_COLORS; i++) {
14677 if (i < MLX5_MTR_RTE_COLORS)
14678 act_cnt = &mtr_policy->act_cnt[i];
14679 for (act = actions[i];
14680 act && act->type != RTE_FLOW_ACTION_TYPE_END;
14682 switch (act->type) {
14683 case RTE_FLOW_ACTION_TYPE_MARK:
14685 uint32_t tag_be = mlx5_flow_mark_set
14686 (((const struct rte_flow_action_mark *)
14689 if (i >= MLX5_MTR_RTE_COLORS)
14690 return -rte_mtr_error_set(error,
14692 RTE_MTR_ERROR_TYPE_METER_POLICY,
14694 "cannot create policy "
14695 "mark action for this color");
14696 dev_flow.handle->mark = 1;
14697 if (flow_dv_tag_resource_register(dev, tag_be,
14698 &dev_flow, &flow_err))
14699 return -rte_mtr_error_set(error,
14701 RTE_MTR_ERROR_TYPE_METER_POLICY,
14703 "cannot setup policy mark action");
14704 MLX5_ASSERT(dev_flow.dv.tag_resource);
14705 act_cnt->rix_mark =
14706 dev_flow.handle->dvh.rix_tag;
14707 if (action_flags & MLX5_FLOW_ACTION_QUEUE) {
14708 dev_flow.handle->rix_hrxq =
14709 mtr_policy->sub_policys[domain][0]->rix_hrxq[i];
14710 flow_drv_rxq_flags_set(dev,
14713 action_flags |= MLX5_FLOW_ACTION_MARK;
14716 case RTE_FLOW_ACTION_TYPE_SET_TAG:
14718 struct mlx5_flow_dv_modify_hdr_resource
14719 *mhdr_res = &mhdr_dummy.res;
14721 if (i >= MLX5_MTR_RTE_COLORS)
14722 return -rte_mtr_error_set(error,
14724 RTE_MTR_ERROR_TYPE_METER_POLICY,
14726 "cannot create policy "
14727 "set tag action for this color");
14728 memset(mhdr_res, 0, sizeof(*mhdr_res));
14729 mhdr_res->ft_type = transfer ?
14730 MLX5DV_FLOW_TABLE_TYPE_FDB :
14732 MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
14733 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
14734 if (flow_dv_convert_action_set_tag
14736 (const struct rte_flow_action_set_tag *)
14737 act->conf, &flow_err))
14738 return -rte_mtr_error_set(error,
14740 RTE_MTR_ERROR_TYPE_METER_POLICY,
14741 NULL, "cannot convert policy "
14743 if (!mhdr_res->actions_num)
14744 return -rte_mtr_error_set(error,
14746 RTE_MTR_ERROR_TYPE_METER_POLICY,
14747 NULL, "cannot find policy "
14749 /* create modify action if needed. */
14750 dev_flow.dv.group = 1;
14751 if (flow_dv_modify_hdr_resource_register
14752 (dev, mhdr_res, &dev_flow, &flow_err))
14753 return -rte_mtr_error_set(error,
14755 RTE_MTR_ERROR_TYPE_METER_POLICY,
14756 NULL, "cannot register policy "
14758 act_cnt->modify_hdr =
14759 dev_flow.handle->dvh.modify_hdr;
14760 if (action_flags & MLX5_FLOW_ACTION_QUEUE) {
14761 dev_flow.handle->rix_hrxq =
14762 mtr_policy->sub_policys[domain][0]->rix_hrxq[i];
14763 flow_drv_rxq_flags_set(dev,
14766 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
14769 case RTE_FLOW_ACTION_TYPE_DROP:
14771 struct mlx5_flow_mtr_mng *mtrmng =
14773 struct mlx5_flow_tbl_data_entry *tbl_data;
14776 * Create the drop table with
14777 * METER DROP level.
14779 if (!mtrmng->drop_tbl[domain]) {
14780 mtrmng->drop_tbl[domain] =
14781 flow_dv_tbl_resource_get(dev,
14782 MLX5_FLOW_TABLE_LEVEL_METER,
14783 egress, transfer, false, NULL, 0,
14784 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
14785 if (!mtrmng->drop_tbl[domain])
14786 return -rte_mtr_error_set
14788 RTE_MTR_ERROR_TYPE_METER_POLICY,
14790 "Failed to create meter drop table");
14792 tbl_data = container_of
14793 (mtrmng->drop_tbl[domain],
14794 struct mlx5_flow_tbl_data_entry, tbl);
14795 if (i < MLX5_MTR_RTE_COLORS) {
14796 act_cnt->dr_jump_action[domain] =
14797 tbl_data->jump.action;
14798 act_cnt->fate_action =
14799 MLX5_FLOW_FATE_DROP;
14801 if (i == RTE_COLOR_RED)
14802 mtr_policy->dr_drop_action[domain] =
14803 tbl_data->jump.action;
14804 action_flags |= MLX5_FLOW_ACTION_DROP;
14807 case RTE_FLOW_ACTION_TYPE_QUEUE:
14809 struct mlx5_hrxq *hrxq;
14811 struct mlx5_flow_rss_desc rss_desc;
14812 struct mlx5_flow_meter_sub_policy *sub_policy =
14813 mtr_policy->sub_policys[domain][0];
14815 if (i >= MLX5_MTR_RTE_COLORS)
14816 return -rte_mtr_error_set(error,
14818 RTE_MTR_ERROR_TYPE_METER_POLICY,
14819 NULL, "cannot create policy "
14820 "fate queue for this color");
14821 memset(&rss_desc, 0,
14822 sizeof(struct mlx5_flow_rss_desc));
14823 rss_desc.queue_num = 1;
14824 rss_desc.const_q = act->conf;
14825 hrxq = flow_dv_hrxq_prepare(dev, &dev_flow,
14826 &rss_desc, &hrxq_idx);
14828 return -rte_mtr_error_set(error,
14830 RTE_MTR_ERROR_TYPE_METER_POLICY,
14832 "cannot create policy fate queue");
14833 sub_policy->rix_hrxq[i] = hrxq_idx;
14834 act_cnt->fate_action =
14835 MLX5_FLOW_FATE_QUEUE;
14836 dev_flow.handle->fate_action =
14837 MLX5_FLOW_FATE_QUEUE;
14838 if (action_flags & MLX5_FLOW_ACTION_MARK ||
14839 action_flags & MLX5_FLOW_ACTION_SET_TAG) {
14840 dev_flow.handle->rix_hrxq = hrxq_idx;
14841 flow_drv_rxq_flags_set(dev,
14844 action_flags |= MLX5_FLOW_ACTION_QUEUE;
14847 case RTE_FLOW_ACTION_TYPE_RSS:
14851 if (i >= MLX5_MTR_RTE_COLORS)
14852 return -rte_mtr_error_set(error,
14854 RTE_MTR_ERROR_TYPE_METER_POLICY,
14856 "cannot create policy "
14857 "rss action for this color");
14859 * Save RSS conf into policy struct
14860 * for translate stage.
14862 rss_size = (int)rte_flow_conv
14863 (RTE_FLOW_CONV_OP_ACTION,
14864 NULL, 0, act, &flow_err);
14866 return -rte_mtr_error_set(error,
14868 RTE_MTR_ERROR_TYPE_METER_POLICY,
14869 NULL, "Get the wrong "
14870 "rss action struct size");
14871 act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
14872 rss_size, 0, SOCKET_ID_ANY);
14874 return -rte_mtr_error_set(error,
14876 RTE_MTR_ERROR_TYPE_METER_POLICY,
14878 "Fail to malloc rss action memory");
14879 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
14880 act_cnt->rss, rss_size,
14883 return -rte_mtr_error_set(error,
14885 RTE_MTR_ERROR_TYPE_METER_POLICY,
14886 NULL, "Fail to save "
14887 "rss action into policy struct");
14888 act_cnt->fate_action =
14889 MLX5_FLOW_FATE_SHARED_RSS;
14890 action_flags |= MLX5_FLOW_ACTION_RSS;
14893 case RTE_FLOW_ACTION_TYPE_PORT_ID:
14895 struct mlx5_flow_dv_port_id_action_resource
14897 uint32_t port_id = 0;
14899 if (i >= MLX5_MTR_RTE_COLORS)
14900 return -rte_mtr_error_set(error,
14902 RTE_MTR_ERROR_TYPE_METER_POLICY,
14903 NULL, "cannot create policy "
14904 "port action for this color");
14905 memset(&port_id_resource, 0,
14906 sizeof(port_id_resource));
14907 if (flow_dv_translate_action_port_id(dev, act,
14908 &port_id, &flow_err))
14909 return -rte_mtr_error_set(error,
14911 RTE_MTR_ERROR_TYPE_METER_POLICY,
14912 NULL, "cannot translate "
14913 "policy port action");
14914 port_id_resource.port_id = port_id;
14915 if (flow_dv_port_id_action_resource_register
14916 (dev, &port_id_resource,
14917 &dev_flow, &flow_err))
14918 return -rte_mtr_error_set(error,
14920 RTE_MTR_ERROR_TYPE_METER_POLICY,
14921 NULL, "cannot setup "
14922 "policy port action");
14923 act_cnt->rix_port_id_action =
14924 dev_flow.handle->rix_port_id_action;
14925 act_cnt->fate_action =
14926 MLX5_FLOW_FATE_PORT_ID;
14927 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
14930 case RTE_FLOW_ACTION_TYPE_JUMP:
14932 uint32_t jump_group = 0;
14933 uint32_t table = 0;
14934 struct mlx5_flow_tbl_data_entry *tbl_data;
14935 struct flow_grp_info grp_info = {
14936 .external = !!dev_flow.external,
14937 .transfer = !!transfer,
14938 .fdb_def_rule = !!priv->fdb_def_rule,
14940 .skip_scale = dev_flow.skip_scale &
14941 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
14943 struct mlx5_flow_meter_sub_policy *sub_policy =
14944 mtr_policy->sub_policys[domain][0];
14946 if (i >= MLX5_MTR_RTE_COLORS)
14947 return -rte_mtr_error_set(error,
14949 RTE_MTR_ERROR_TYPE_METER_POLICY,
14951 "cannot create policy "
14952 "jump action for this color");
14954 ((const struct rte_flow_action_jump *)
14956 if (mlx5_flow_group_to_table(dev, NULL,
14959 &grp_info, &flow_err))
14960 return -rte_mtr_error_set(error,
14962 RTE_MTR_ERROR_TYPE_METER_POLICY,
14963 NULL, "cannot setup "
14964 "policy jump action");
14965 sub_policy->jump_tbl[i] =
14966 flow_dv_tbl_resource_get(dev,
14969 !!dev_flow.external,
14970 NULL, jump_group, 0,
14973 (!sub_policy->jump_tbl[i])
14974 return -rte_mtr_error_set(error,
14976 RTE_MTR_ERROR_TYPE_METER_POLICY,
14977 NULL, "cannot create jump action.");
14978 tbl_data = container_of
14979 (sub_policy->jump_tbl[i],
14980 struct mlx5_flow_tbl_data_entry, tbl);
14981 act_cnt->dr_jump_action[domain] =
14982 tbl_data->jump.action;
14983 act_cnt->fate_action =
14984 MLX5_FLOW_FATE_JUMP;
14985 action_flags |= MLX5_FLOW_ACTION_JUMP;
14989 return -rte_mtr_error_set(error, ENOTSUP,
14990 RTE_MTR_ERROR_TYPE_METER_POLICY,
14991 NULL, "action type not supported");
14999 * Create policy action per domain, lock free,
15000 * (mutex should be acquired by caller).
15001 * Dispatcher for action type specific call.
15004 * Pointer to the Ethernet device structure.
15005 * @param[in] mtr_policy
15006 * Meter policy struct.
15007 * @param[in] action
15008 * Action specification used to create meter actions.
15009 * @param[out] error
15010 * Perform verbose error reporting if not NULL. Initialized in case of
15014 * 0 on success, otherwise negative errno value.
15017 flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
15018 struct mlx5_flow_meter_policy *mtr_policy,
15019 const struct rte_flow_action *actions[RTE_COLORS],
15020 struct rte_mtr_error *error)
15023 uint16_t sub_policy_num;
15025 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15026 sub_policy_num = (mtr_policy->sub_policy_num >>
15027 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15028 MLX5_MTR_SUB_POLICY_NUM_MASK;
15029 if (sub_policy_num) {
15030 ret = __flow_dv_create_domain_policy_acts(dev,
15031 mtr_policy, actions,
15032 (enum mlx5_meter_domain)i, error);
15041 * Query a DV flow rule for its statistics via DevX.
15044 * Pointer to Ethernet device.
15045 * @param[in] cnt_idx
15046 * Index to the flow counter.
15048 * Data retrieved by the query.
15049 * @param[out] error
15050 * Perform verbose error reporting if not NULL.
15053 * 0 on success, a negative errno value otherwise and rte_errno is set.
15056 flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
15057 struct rte_flow_error *error)
15059 struct mlx5_priv *priv = dev->data->dev_private;
15060 struct rte_flow_query_count *qc = data;
15062 if (!priv->config.devx)
15063 return rte_flow_error_set(error, ENOTSUP,
15064 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15066 "counters are not supported");
15068 uint64_t pkts, bytes;
15069 struct mlx5_flow_counter *cnt;
15070 int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
15073 return rte_flow_error_set(error, -err,
15074 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15075 NULL, "cannot read counters");
15076 cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
15079 qc->hits = pkts - cnt->hits;
15080 qc->bytes = bytes - cnt->bytes;
15083 cnt->bytes = bytes;
15087 return rte_flow_error_set(error, EINVAL,
15088 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15090 "counters are not available");
15094 flow_dv_action_query(struct rte_eth_dev *dev,
15095 const struct rte_flow_action_handle *handle, void *data,
15096 struct rte_flow_error *error)
15098 struct mlx5_age_param *age_param;
15099 struct rte_flow_query_age *resp;
15100 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15101 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15102 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15103 struct mlx5_priv *priv = dev->data->dev_private;
15104 struct mlx5_aso_ct_action *ct;
15109 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15110 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
15112 resp->aged = __atomic_load_n(&age_param->state,
15113 __ATOMIC_RELAXED) == AGE_TMOUT ?
15115 resp->sec_since_last_hit_valid = !resp->aged;
15116 if (resp->sec_since_last_hit_valid)
15117 resp->sec_since_last_hit = __atomic_load_n
15118 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15120 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15121 return flow_dv_query_count(dev, idx, data, error);
15122 case MLX5_INDIRECT_ACTION_TYPE_CT:
15123 owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
15124 if (owner != PORT_ID(priv))
15125 return rte_flow_error_set(error, EACCES,
15126 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15128 "CT object owned by another port");
15129 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
15130 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
15133 return rte_flow_error_set(error, EFAULT,
15134 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15136 "CT object is inactive");
15137 ((struct rte_flow_action_conntrack *)data)->peer_port =
15139 ((struct rte_flow_action_conntrack *)data)->is_original_dir =
15141 if (mlx5_aso_ct_query_by_wqe(priv->sh, ct, data))
15142 return rte_flow_error_set(error, EIO,
15143 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15145 "Failed to query CT context");
15148 return rte_flow_error_set(error, ENOTSUP,
15149 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15150 "action type query not supported");
15155 * Query a flow rule AGE action for aging information.
15158 * Pointer to Ethernet device.
15160 * Pointer to the sub flow.
15162 * data retrieved by the query.
15163 * @param[out] error
15164 * Perform verbose error reporting if not NULL.
15167 * 0 on success, a negative errno value otherwise and rte_errno is set.
15170 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
15171 void *data, struct rte_flow_error *error)
15173 struct rte_flow_query_age *resp = data;
15174 struct mlx5_age_param *age_param;
15177 struct mlx5_aso_age_action *act =
15178 flow_aso_age_get_by_idx(dev, flow->age);
15180 age_param = &act->age_params;
15181 } else if (flow->counter) {
15182 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
15184 if (!age_param || !age_param->timeout)
15185 return rte_flow_error_set
15187 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15188 NULL, "cannot read age data");
15190 return rte_flow_error_set(error, EINVAL,
15191 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15192 NULL, "age data not available");
15194 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
15196 resp->sec_since_last_hit_valid = !resp->aged;
15197 if (resp->sec_since_last_hit_valid)
15198 resp->sec_since_last_hit = __atomic_load_n
15199 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15206 * @see rte_flow_query()
15207 * @see rte_flow_ops
15210 flow_dv_query(struct rte_eth_dev *dev,
15211 struct rte_flow *flow __rte_unused,
15212 const struct rte_flow_action *actions __rte_unused,
15213 void *data __rte_unused,
15214 struct rte_flow_error *error __rte_unused)
15218 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
15219 switch (actions->type) {
15220 case RTE_FLOW_ACTION_TYPE_VOID:
15222 case RTE_FLOW_ACTION_TYPE_COUNT:
15223 ret = flow_dv_query_count(dev, flow->counter, data,
15226 case RTE_FLOW_ACTION_TYPE_AGE:
15227 ret = flow_dv_query_age(dev, flow, data, error);
15230 return rte_flow_error_set(error, ENOTSUP,
15231 RTE_FLOW_ERROR_TYPE_ACTION,
15233 "action not supported");
15240 * Destroy the meter table set.
15241 * Lock free, (mutex should be acquired by caller).
15244 * Pointer to Ethernet device.
15246 * Meter information table.
15249 flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
15250 struct mlx5_flow_meter_info *fm)
15252 struct mlx5_priv *priv = dev->data->dev_private;
15255 if (!fm || !priv->config.dv_flow_en)
15257 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15258 if (fm->drop_rule[i]) {
15259 claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
15260 fm->drop_rule[i] = NULL;
15266 flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
15268 struct mlx5_priv *priv = dev->data->dev_private;
15269 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15270 struct mlx5_flow_tbl_data_entry *tbl;
15273 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15274 if (mtrmng->def_rule[i]) {
15275 claim_zero(mlx5_flow_os_destroy_flow
15276 (mtrmng->def_rule[i]));
15277 mtrmng->def_rule[i] = NULL;
15279 if (mtrmng->def_matcher[i]) {
15280 tbl = container_of(mtrmng->def_matcher[i]->tbl,
15281 struct mlx5_flow_tbl_data_entry, tbl);
15282 mlx5_cache_unregister(&tbl->matchers,
15283 &mtrmng->def_matcher[i]->entry);
15284 mtrmng->def_matcher[i] = NULL;
15286 for (j = 0; j < MLX5_REG_BITS; j++) {
15287 if (mtrmng->drop_matcher[i][j]) {
15289 container_of(mtrmng->drop_matcher[i][j]->tbl,
15290 struct mlx5_flow_tbl_data_entry,
15292 mlx5_cache_unregister(&tbl->matchers,
15293 &mtrmng->drop_matcher[i][j]->entry);
15294 mtrmng->drop_matcher[i][j] = NULL;
15297 if (mtrmng->drop_tbl[i]) {
15298 flow_dv_tbl_resource_release(MLX5_SH(dev),
15299 mtrmng->drop_tbl[i]);
15300 mtrmng->drop_tbl[i] = NULL;
15305 /* Number of meter flow actions, count and jump or count and drop. */
15306 #define METER_ACTIONS 2
15309 __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
15310 enum mlx5_meter_domain domain)
15312 struct mlx5_priv *priv = dev->data->dev_private;
15313 struct mlx5_flow_meter_def_policy *def_policy =
15314 priv->sh->mtrmng->def_policy[domain];
15316 __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
15317 mlx5_free(def_policy);
15318 priv->sh->mtrmng->def_policy[domain] = NULL;
15322 * Destroy the default policy table set.
15325 * Pointer to Ethernet device.
15328 flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
15330 struct mlx5_priv *priv = dev->data->dev_private;
15333 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
15334 if (priv->sh->mtrmng->def_policy[i])
15335 __flow_dv_destroy_domain_def_policy(dev,
15336 (enum mlx5_meter_domain)i);
15337 priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
15341 __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
15342 uint32_t color_reg_c_idx,
15343 enum rte_color color, void *matcher_object,
15344 int actions_n, void *actions,
15345 bool is_default_policy, void **rule,
15346 const struct rte_flow_attr *attr)
15349 struct mlx5_flow_dv_match_params value = {
15350 .size = sizeof(value.buf) -
15351 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15353 struct mlx5_flow_dv_match_params matcher = {
15354 .size = sizeof(matcher.buf) -
15355 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15357 struct mlx5_priv *priv = dev->data->dev_private;
15359 if (!is_default_policy && (priv->representor || priv->master)) {
15360 if (flow_dv_translate_item_port_id(dev, matcher.buf,
15361 value.buf, NULL, attr)) {
15363 "Failed to create meter policy flow with port.");
15367 flow_dv_match_meta_reg(matcher.buf, value.buf,
15368 (enum modify_reg)color_reg_c_idx,
15369 rte_col_2_mlx5_col(color),
15371 ret = mlx5_flow_os_create_flow(matcher_object,
15372 (void *)&value, actions_n, actions, rule);
15374 DRV_LOG(ERR, "Failed to create meter policy flow.");
15381 __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
15382 uint32_t color_reg_c_idx,
15384 struct mlx5_flow_meter_sub_policy *sub_policy,
15385 const struct rte_flow_attr *attr,
15386 bool is_default_policy,
15387 struct rte_flow_error *error)
15389 struct mlx5_cache_entry *entry;
15390 struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
15391 struct mlx5_flow_dv_matcher matcher = {
15393 .size = sizeof(matcher.mask.buf) -
15394 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15398 struct mlx5_flow_dv_match_params value = {
15399 .size = sizeof(value.buf) -
15400 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15402 struct mlx5_flow_cb_ctx ctx = {
15406 struct mlx5_flow_tbl_data_entry *tbl_data;
15407 struct mlx5_priv *priv = dev->data->dev_private;
15408 uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
15410 if (!is_default_policy && (priv->representor || priv->master)) {
15411 if (flow_dv_translate_item_port_id(dev, matcher.mask.buf,
15412 value.buf, NULL, attr)) {
15414 "Failed to register meter drop matcher with port.");
15418 tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
15419 if (priority < RTE_COLOR_RED)
15420 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
15421 (enum modify_reg)color_reg_c_idx, 0, color_mask);
15422 matcher.priority = priority;
15423 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15424 matcher.mask.size);
15425 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
15427 DRV_LOG(ERR, "Failed to register meter drop matcher.");
15430 sub_policy->color_matcher[priority] =
15431 container_of(entry, struct mlx5_flow_dv_matcher, entry);
15436 * Create the policy rules per domain.
15439 * Pointer to Ethernet device.
15440 * @param[in] sub_policy
15441 * Pointer to sub policy table..
15442 * @param[in] egress
15443 * Direction of the table.
15444 * @param[in] transfer
15445 * E-Switch or NIC flow.
15447 * Pointer to policy action list per color.
15450 * 0 on success, -1 otherwise.
15453 __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
15454 struct mlx5_flow_meter_sub_policy *sub_policy,
15455 uint8_t egress, uint8_t transfer, bool is_default_policy,
15456 struct mlx5_meter_policy_acts acts[RTE_COLORS])
15458 struct rte_flow_error flow_err;
15459 uint32_t color_reg_c_idx;
15460 struct rte_flow_attr attr = {
15461 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
15464 .egress = !!egress,
15465 .transfer = !!transfer,
15469 int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
15473 /* Create policy table with POLICY level. */
15474 if (!sub_policy->tbl_rsc)
15475 sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
15476 MLX5_FLOW_TABLE_LEVEL_POLICY,
15477 egress, transfer, false, NULL, 0, 0,
15478 sub_policy->idx, &flow_err);
15479 if (!sub_policy->tbl_rsc) {
15481 "Failed to create meter sub policy table.");
15484 /* Prepare matchers. */
15485 color_reg_c_idx = ret;
15486 for (i = 0; i < RTE_COLORS; i++) {
15487 if (i == RTE_COLOR_YELLOW || !acts[i].actions_n)
15490 if (!sub_policy->color_matcher[i]) {
15491 /* Create matchers for Color. */
15492 if (__flow_dv_create_policy_matcher(dev,
15493 color_reg_c_idx, i, sub_policy,
15494 &attr, is_default_policy, &flow_err))
15497 /* Create flow, matching color. */
15498 if (acts[i].actions_n)
15499 if (__flow_dv_create_policy_flow(dev,
15500 color_reg_c_idx, (enum rte_color)i,
15501 sub_policy->color_matcher[i]->matcher_object,
15503 acts[i].dv_actions,
15505 &sub_policy->color_rule[i],
15513 __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
15514 struct mlx5_flow_meter_policy *mtr_policy,
15515 struct mlx5_flow_meter_sub_policy *sub_policy,
15518 struct mlx5_priv *priv = dev->data->dev_private;
15519 struct mlx5_meter_policy_acts acts[RTE_COLORS];
15520 struct mlx5_flow_dv_tag_resource *tag;
15521 struct mlx5_flow_dv_port_id_action_resource *port_action;
15522 struct mlx5_hrxq *hrxq;
15523 uint8_t egress, transfer;
15526 for (i = 0; i < RTE_COLORS; i++) {
15527 acts[i].actions_n = 0;
15528 if (i == RTE_COLOR_YELLOW)
15530 if (i == RTE_COLOR_RED) {
15531 /* Only support drop on red. */
15532 acts[i].dv_actions[0] =
15533 mtr_policy->dr_drop_action[domain];
15534 acts[i].actions_n = 1;
15537 if (mtr_policy->act_cnt[i].rix_mark) {
15538 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
15539 mtr_policy->act_cnt[i].rix_mark);
15541 DRV_LOG(ERR, "Failed to find "
15542 "mark action for policy.");
15545 acts[i].dv_actions[acts[i].actions_n] =
15547 acts[i].actions_n++;
15549 if (mtr_policy->act_cnt[i].modify_hdr) {
15550 acts[i].dv_actions[acts[i].actions_n] =
15551 mtr_policy->act_cnt[i].modify_hdr->action;
15552 acts[i].actions_n++;
15554 if (mtr_policy->act_cnt[i].fate_action) {
15555 switch (mtr_policy->act_cnt[i].fate_action) {
15556 case MLX5_FLOW_FATE_PORT_ID:
15557 port_action = mlx5_ipool_get
15558 (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
15559 mtr_policy->act_cnt[i].rix_port_id_action);
15560 if (!port_action) {
15561 DRV_LOG(ERR, "Failed to find "
15562 "port action for policy.");
15565 acts[i].dv_actions[acts[i].actions_n] =
15566 port_action->action;
15567 acts[i].actions_n++;
15569 case MLX5_FLOW_FATE_DROP:
15570 case MLX5_FLOW_FATE_JUMP:
15571 acts[i].dv_actions[acts[i].actions_n] =
15572 mtr_policy->act_cnt[i].dr_jump_action[domain];
15573 acts[i].actions_n++;
15575 case MLX5_FLOW_FATE_SHARED_RSS:
15576 case MLX5_FLOW_FATE_QUEUE:
15577 hrxq = mlx5_ipool_get
15578 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
15579 sub_policy->rix_hrxq[i]);
15581 DRV_LOG(ERR, "Failed to find "
15582 "queue action for policy.");
15585 acts[i].dv_actions[acts[i].actions_n] =
15587 acts[i].actions_n++;
15590 /*Queue action do nothing*/
15595 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15596 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15597 if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
15598 egress, transfer, false, acts)) {
15600 "Failed to create policy rules per domain.");
15607 * Create the policy rules.
15610 * Pointer to Ethernet device.
15611 * @param[in,out] mtr_policy
15612 * Pointer to meter policy table.
15615 * 0 on success, -1 otherwise.
15618 flow_dv_create_policy_rules(struct rte_eth_dev *dev,
15619 struct mlx5_flow_meter_policy *mtr_policy)
15622 uint16_t sub_policy_num;
15624 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15625 sub_policy_num = (mtr_policy->sub_policy_num >>
15626 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15627 MLX5_MTR_SUB_POLICY_NUM_MASK;
15628 if (!sub_policy_num)
15630 /* Prepare actions list and create policy rules. */
15631 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
15632 mtr_policy->sub_policys[i][0], i)) {
15634 "Failed to create policy action list per domain.");
15642 __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
15644 struct mlx5_priv *priv = dev->data->dev_private;
15645 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15646 struct mlx5_flow_meter_def_policy *def_policy;
15647 struct mlx5_flow_tbl_resource *jump_tbl;
15648 struct mlx5_flow_tbl_data_entry *tbl_data;
15649 uint8_t egress, transfer;
15650 struct rte_flow_error error;
15651 struct mlx5_meter_policy_acts acts[RTE_COLORS];
15654 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15655 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15656 def_policy = mtrmng->def_policy[domain];
15658 def_policy = mlx5_malloc(MLX5_MEM_ZERO,
15659 sizeof(struct mlx5_flow_meter_def_policy),
15660 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
15662 DRV_LOG(ERR, "Failed to alloc "
15663 "default policy table.");
15664 goto def_policy_error;
15666 mtrmng->def_policy[domain] = def_policy;
15667 /* Create the meter suffix table with SUFFIX level. */
15668 jump_tbl = flow_dv_tbl_resource_get(dev,
15669 MLX5_FLOW_TABLE_LEVEL_METER,
15670 egress, transfer, false, NULL, 0,
15671 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
15674 "Failed to create meter suffix table.");
15675 goto def_policy_error;
15677 def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
15678 tbl_data = container_of(jump_tbl,
15679 struct mlx5_flow_tbl_data_entry, tbl);
15680 def_policy->dr_jump_action[RTE_COLOR_GREEN] =
15681 tbl_data->jump.action;
15682 acts[RTE_COLOR_GREEN].dv_actions[0] =
15683 tbl_data->jump.action;
15684 acts[RTE_COLOR_GREEN].actions_n = 1;
15685 /* Create jump action to the drop table. */
15686 if (!mtrmng->drop_tbl[domain]) {
15687 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
15688 (dev, MLX5_FLOW_TABLE_LEVEL_METER,
15689 egress, transfer, false, NULL, 0,
15690 0, MLX5_MTR_TABLE_ID_DROP, &error);
15691 if (!mtrmng->drop_tbl[domain]) {
15692 DRV_LOG(ERR, "Failed to create "
15693 "meter drop table for default policy.");
15694 goto def_policy_error;
15697 tbl_data = container_of(mtrmng->drop_tbl[domain],
15698 struct mlx5_flow_tbl_data_entry, tbl);
15699 def_policy->dr_jump_action[RTE_COLOR_RED] =
15700 tbl_data->jump.action;
15701 acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
15702 acts[RTE_COLOR_RED].actions_n = 1;
15703 /* Create default policy rules. */
15704 ret = __flow_dv_create_domain_policy_rules(dev,
15705 &def_policy->sub_policy,
15706 egress, transfer, true, acts);
15708 DRV_LOG(ERR, "Failed to create "
15709 "default policy rules.");
15710 goto def_policy_error;
15715 __flow_dv_destroy_domain_def_policy(dev,
15716 (enum mlx5_meter_domain)domain);
15721 * Create the default policy table set.
15724 * Pointer to Ethernet device.
15726 * 0 on success, -1 otherwise.
15729 flow_dv_create_def_policy(struct rte_eth_dev *dev)
15731 struct mlx5_priv *priv = dev->data->dev_private;
15734 /* Non-termination policy table. */
15735 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15736 if (!priv->config.dv_esw_en && i == MLX5_MTR_DOMAIN_TRANSFER)
15738 if (__flow_dv_create_domain_def_policy(dev, i)) {
15740 "Failed to create default policy");
15748 * Create the needed meter tables.
15749 * Lock free, (mutex should be acquired by caller).
15752 * Pointer to Ethernet device.
15754 * Meter information table.
15755 * @param[in] mtr_idx
15757 * @param[in] domain_bitmap
15760 * 0 on success, -1 otherwise.
15763 flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
15764 struct mlx5_flow_meter_info *fm,
15766 uint8_t domain_bitmap)
15768 struct mlx5_priv *priv = dev->data->dev_private;
15769 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15770 struct rte_flow_error error;
15771 struct mlx5_flow_tbl_data_entry *tbl_data;
15772 uint8_t egress, transfer;
15773 void *actions[METER_ACTIONS];
15774 int domain, ret, i;
15775 struct mlx5_flow_counter *cnt;
15776 struct mlx5_flow_dv_match_params value = {
15777 .size = sizeof(value.buf) -
15778 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15780 struct mlx5_flow_dv_match_params matcher_para = {
15781 .size = sizeof(matcher_para.buf) -
15782 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15784 int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
15786 uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
15787 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
15788 struct mlx5_cache_entry *entry;
15789 struct mlx5_flow_dv_matcher matcher = {
15791 .size = sizeof(matcher.mask.buf) -
15792 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15795 struct mlx5_flow_dv_matcher *drop_matcher;
15796 struct mlx5_flow_cb_ctx ctx = {
15801 if (!priv->mtr_en || mtr_id_reg_c < 0) {
15802 rte_errno = ENOTSUP;
15805 for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
15806 if (!(domain_bitmap & (1 << domain)) ||
15807 (mtrmng->def_rule[domain] && !fm->drop_cnt))
15809 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15810 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15811 /* Create the drop table with METER DROP level. */
15812 if (!mtrmng->drop_tbl[domain]) {
15813 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
15814 MLX5_FLOW_TABLE_LEVEL_METER,
15815 egress, transfer, false, NULL, 0,
15816 0, MLX5_MTR_TABLE_ID_DROP, &error);
15817 if (!mtrmng->drop_tbl[domain]) {
15818 DRV_LOG(ERR, "Failed to create meter drop table.");
15822 /* Create default matcher in drop table. */
15823 matcher.tbl = mtrmng->drop_tbl[domain],
15824 tbl_data = container_of(mtrmng->drop_tbl[domain],
15825 struct mlx5_flow_tbl_data_entry, tbl);
15826 if (!mtrmng->def_matcher[domain]) {
15827 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
15828 (enum modify_reg)mtr_id_reg_c,
15830 matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
15831 matcher.crc = rte_raw_cksum
15832 ((const void *)matcher.mask.buf,
15833 matcher.mask.size);
15834 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
15836 DRV_LOG(ERR, "Failed to register meter "
15837 "drop default matcher.");
15840 mtrmng->def_matcher[domain] = container_of(entry,
15841 struct mlx5_flow_dv_matcher, entry);
15843 /* Create default rule in drop table. */
15844 if (!mtrmng->def_rule[domain]) {
15846 actions[i++] = priv->sh->dr_drop_action;
15847 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
15848 (enum modify_reg)mtr_id_reg_c, 0, 0);
15849 ret = mlx5_flow_os_create_flow
15850 (mtrmng->def_matcher[domain]->matcher_object,
15851 (void *)&value, i, actions,
15852 &mtrmng->def_rule[domain]);
15854 DRV_LOG(ERR, "Failed to create meter "
15855 "default drop rule for drop table.");
15861 MLX5_ASSERT(mtrmng->max_mtr_bits);
15862 if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
15863 /* Create matchers for Drop. */
15864 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
15865 (enum modify_reg)mtr_id_reg_c, 0,
15866 (mtr_id_mask << mtr_id_offset));
15867 matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
15868 matcher.crc = rte_raw_cksum
15869 ((const void *)matcher.mask.buf,
15870 matcher.mask.size);
15871 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
15874 "Failed to register meter drop matcher.");
15877 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
15878 container_of(entry, struct mlx5_flow_dv_matcher,
15882 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
15883 /* Create drop rule, matching meter_id only. */
15884 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
15885 (enum modify_reg)mtr_id_reg_c,
15886 (mtr_idx << mtr_id_offset), UINT32_MAX);
15888 cnt = flow_dv_counter_get_by_idx(dev,
15889 fm->drop_cnt, NULL);
15890 actions[i++] = cnt->action;
15891 actions[i++] = priv->sh->dr_drop_action;
15892 ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
15893 (void *)&value, i, actions,
15894 &fm->drop_rule[domain]);
15896 DRV_LOG(ERR, "Failed to create meter "
15897 "drop rule for drop table.");
15903 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15904 if (fm->drop_rule[i]) {
15905 claim_zero(mlx5_flow_os_destroy_flow
15906 (fm->drop_rule[i]));
15907 fm->drop_rule[i] = NULL;
15914 * Find the policy table for prefix table with RSS.
15917 * Pointer to Ethernet device.
15918 * @param[in] mtr_policy
15919 * Pointer to meter policy table.
15920 * @param[in] rss_desc
15921 * Pointer to rss_desc
15923 * Pointer to table set on success, NULL otherwise and rte_errno is set.
15925 static struct mlx5_flow_meter_sub_policy *
15926 flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
15927 struct mlx5_flow_meter_policy *mtr_policy,
15928 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
15930 struct mlx5_priv *priv = dev->data->dev_private;
15931 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
15932 uint32_t sub_policy_idx = 0;
15933 uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
15935 struct mlx5_hrxq *hrxq;
15936 struct mlx5_flow_handle dh;
15937 struct mlx5_meter_policy_action_container *act_cnt;
15938 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
15939 uint16_t sub_policy_num;
15941 rte_spinlock_lock(&mtr_policy->sl);
15942 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15945 hrxq_idx[i] = mlx5_hrxq_get(dev, rss_desc[i]);
15946 if (!hrxq_idx[i]) {
15947 rte_spinlock_unlock(&mtr_policy->sl);
15951 sub_policy_num = (mtr_policy->sub_policy_num >>
15952 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
15953 MLX5_MTR_SUB_POLICY_NUM_MASK;
15954 for (i = 0; i < sub_policy_num;
15956 for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) {
15959 mtr_policy->sub_policys[domain][i]->rix_hrxq[j])
15962 if (j >= MLX5_MTR_RTE_COLORS) {
15964 * Found the sub policy table with
15965 * the same queue per color
15967 rte_spinlock_unlock(&mtr_policy->sl);
15968 for (j = 0; j < MLX5_MTR_RTE_COLORS; j++)
15969 mlx5_hrxq_release(dev, hrxq_idx[j]);
15970 return mtr_policy->sub_policys[domain][i];
15973 /* Create sub policy. */
15974 if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[0]) {
15975 /* Reuse the first dummy sub_policy*/
15976 sub_policy = mtr_policy->sub_policys[domain][0];
15977 sub_policy_idx = sub_policy->idx;
15979 sub_policy = mlx5_ipool_zmalloc
15980 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
15983 sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
15984 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
15985 mlx5_hrxq_release(dev, hrxq_idx[i]);
15986 goto rss_sub_policy_error;
15988 sub_policy->idx = sub_policy_idx;
15989 sub_policy->main_policy = mtr_policy;
15991 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15994 sub_policy->rix_hrxq[i] = hrxq_idx[i];
15996 * Overwrite the last action from
15997 * RSS action to Queue action.
15999 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
16002 DRV_LOG(ERR, "Failed to create policy hrxq");
16003 goto rss_sub_policy_error;
16005 act_cnt = &mtr_policy->act_cnt[i];
16006 if (act_cnt->rix_mark || act_cnt->modify_hdr) {
16007 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
16008 if (act_cnt->rix_mark)
16010 dh.fate_action = MLX5_FLOW_FATE_QUEUE;
16011 dh.rix_hrxq = hrxq_idx[i];
16012 flow_drv_rxq_flags_set(dev, &dh);
16015 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16016 sub_policy, domain)) {
16017 DRV_LOG(ERR, "Failed to create policy "
16018 "rules per domain.");
16019 goto rss_sub_policy_error;
16021 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16022 i = (mtr_policy->sub_policy_num >>
16023 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16024 MLX5_MTR_SUB_POLICY_NUM_MASK;
16025 mtr_policy->sub_policys[domain][i] = sub_policy;
16027 if (i > MLX5_MTR_RSS_MAX_SUB_POLICY)
16028 goto rss_sub_policy_error;
16029 mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16030 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
16031 mtr_policy->sub_policy_num |=
16032 (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16033 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
16035 rte_spinlock_unlock(&mtr_policy->sl);
16037 rss_sub_policy_error:
16039 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
16040 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16041 i = (mtr_policy->sub_policy_num >>
16042 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16043 MLX5_MTR_SUB_POLICY_NUM_MASK;
16044 mtr_policy->sub_policys[domain][i] = NULL;
16046 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16050 if (sub_policy_idx)
16051 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16053 rte_spinlock_unlock(&mtr_policy->sl);
16058 * Validate the batch counter support in root table.
16060 * Create a simple flow with invalid counter and drop action on root table to
16061 * validate if batch counter with offset on root table is supported or not.
16064 * Pointer to rte_eth_dev structure.
16067 * 0 on success, a negative errno value otherwise and rte_errno is set.
16070 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
16072 struct mlx5_priv *priv = dev->data->dev_private;
16073 struct mlx5_dev_ctx_shared *sh = priv->sh;
16074 struct mlx5_flow_dv_match_params mask = {
16075 .size = sizeof(mask.buf),
16077 struct mlx5_flow_dv_match_params value = {
16078 .size = sizeof(value.buf),
16080 struct mlx5dv_flow_matcher_attr dv_attr = {
16081 .type = IBV_FLOW_ATTR_NORMAL,
16083 .match_criteria_enable = 0,
16084 .match_mask = (void *)&mask,
16086 void *actions[2] = { 0 };
16087 struct mlx5_flow_tbl_resource *tbl = NULL;
16088 struct mlx5_devx_obj *dcs = NULL;
16089 void *matcher = NULL;
16093 tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
16097 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
16100 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
16104 actions[1] = sh->dr_drop_action ? sh->dr_drop_action :
16105 priv->drop_queue.hrxq->action;
16106 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
16107 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
16111 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 2,
16115 * If batch counter with offset is not supported, the driver will not
16116 * validate the invalid offset value, flow create should success.
16117 * In this case, it means batch counter is not supported in root table.
16119 * Otherwise, if flow create is failed, counter offset is supported.
16122 DRV_LOG(INFO, "Batch counter is not supported in root "
16123 "table. Switch to fallback mode.");
16124 rte_errno = ENOTSUP;
16126 claim_zero(mlx5_flow_os_destroy_flow(flow));
16128 /* Check matcher to make sure validate fail at flow create. */
16129 if (!matcher || (matcher && errno != EINVAL))
16130 DRV_LOG(ERR, "Unexpected error in counter offset "
16131 "support detection");
16135 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
16137 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
16139 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
16141 claim_zero(mlx5_devx_cmd_destroy(dcs));
16146 * Query a devx counter.
16149 * Pointer to the Ethernet device structure.
16151 * Index to the flow counter.
16153 * Set to clear the counter statistics.
16155 * The statistics value of packets.
16156 * @param[out] bytes
16157 * The statistics value of bytes.
16160 * 0 on success, otherwise return -1.
16163 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
16164 uint64_t *pkts, uint64_t *bytes)
16166 struct mlx5_priv *priv = dev->data->dev_private;
16167 struct mlx5_flow_counter *cnt;
16168 uint64_t inn_pkts, inn_bytes;
16171 if (!priv->config.devx)
16174 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
16177 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
16178 *pkts = inn_pkts - cnt->hits;
16179 *bytes = inn_bytes - cnt->bytes;
16181 cnt->hits = inn_pkts;
16182 cnt->bytes = inn_bytes;
16188 * Get aged-out flows.
16191 * Pointer to the Ethernet device structure.
16192 * @param[in] context
16193 * The address of an array of pointers to the aged-out flows contexts.
16194 * @param[in] nb_contexts
16195 * The length of context array pointers.
16196 * @param[out] error
16197 * Perform verbose error reporting if not NULL. Initialized in case of
16201 * how many contexts get in success, otherwise negative errno value.
16202 * if nb_contexts is 0, return the amount of all aged contexts.
16203 * if nb_contexts is not 0 , return the amount of aged flows reported
16204 * in the context array.
16205 * @note: only stub for now
16208 flow_get_aged_flows(struct rte_eth_dev *dev,
16210 uint32_t nb_contexts,
16211 struct rte_flow_error *error)
16213 struct mlx5_priv *priv = dev->data->dev_private;
16214 struct mlx5_age_info *age_info;
16215 struct mlx5_age_param *age_param;
16216 struct mlx5_flow_counter *counter;
16217 struct mlx5_aso_age_action *act;
16220 if (nb_contexts && !context)
16221 return rte_flow_error_set(error, EINVAL,
16222 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16223 NULL, "empty context");
16224 age_info = GET_PORT_AGE_INFO(priv);
16225 rte_spinlock_lock(&age_info->aged_sl);
16226 LIST_FOREACH(act, &age_info->aged_aso, next) {
16229 context[nb_flows - 1] =
16230 act->age_params.context;
16231 if (!(--nb_contexts))
16235 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
16238 age_param = MLX5_CNT_TO_AGE(counter);
16239 context[nb_flows - 1] = age_param->context;
16240 if (!(--nb_contexts))
16244 rte_spinlock_unlock(&age_info->aged_sl);
16245 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
16250 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
16253 flow_dv_counter_allocate(struct rte_eth_dev *dev)
16255 return flow_dv_counter_alloc(dev, 0);
16259 * Validate indirect action.
16260 * Dispatcher for action type specific validation.
16263 * Pointer to the Ethernet device structure.
16265 * Indirect action configuration.
16266 * @param[in] action
16267 * The indirect action object to validate.
16268 * @param[out] error
16269 * Perform verbose error reporting if not NULL. Initialized in case of
16273 * 0 on success, otherwise negative errno value.
16276 flow_dv_action_validate(struct rte_eth_dev *dev,
16277 const struct rte_flow_indir_action_conf *conf,
16278 const struct rte_flow_action *action,
16279 struct rte_flow_error *err)
16281 struct mlx5_priv *priv = dev->data->dev_private;
16283 RTE_SET_USED(conf);
16284 switch (action->type) {
16285 case RTE_FLOW_ACTION_TYPE_RSS:
16287 * priv->obj_ops is set according to driver capabilities.
16288 * When DevX capabilities are
16289 * sufficient, it is set to devx_obj_ops.
16290 * Otherwise, it is set to ibv_obj_ops.
16291 * ibv_obj_ops doesn't support ind_table_modify operation.
16292 * In this case the indirect RSS action can't be used.
16294 if (priv->obj_ops.ind_table_modify == NULL)
16295 return rte_flow_error_set
16297 RTE_FLOW_ERROR_TYPE_ACTION,
16299 "Indirect RSS action not supported");
16300 return mlx5_validate_action_rss(dev, action, err);
16301 case RTE_FLOW_ACTION_TYPE_AGE:
16302 if (!priv->sh->aso_age_mng)
16303 return rte_flow_error_set(err, ENOTSUP,
16304 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16306 "Indirect age action not supported");
16307 return flow_dv_validate_action_age(0, action, dev, err);
16308 case RTE_FLOW_ACTION_TYPE_COUNT:
16310 * There are two mechanisms to share the action count.
16311 * The old mechanism uses the shared field to share, while the
16312 * new mechanism uses the indirect action API.
16313 * This validation comes to make sure that the two mechanisms
16314 * are not combined.
16316 if (is_shared_action_count(action))
16317 return rte_flow_error_set(err, ENOTSUP,
16318 RTE_FLOW_ERROR_TYPE_ACTION,
16320 "Mix shared and indirect counter is not supported");
16321 return flow_dv_validate_action_count(dev, true, 0, err);
16322 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
16323 if (!priv->sh->ct_aso_en)
16324 return rte_flow_error_set(err, ENOTSUP,
16325 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16326 "ASO CT is not supported");
16327 return mlx5_validate_action_ct(dev, action->conf, err);
16329 return rte_flow_error_set(err, ENOTSUP,
16330 RTE_FLOW_ERROR_TYPE_ACTION,
16332 "action type not supported");
16337 * Validate meter policy actions.
16338 * Dispatcher for action type specific validation.
16341 * Pointer to the Ethernet device structure.
16342 * @param[in] action
16343 * The meter policy action object to validate.
16345 * Attributes of flow to determine steering domain.
16346 * @param[out] error
16347 * Perform verbose error reporting if not NULL. Initialized in case of
16351 * 0 on success, otherwise negative errno value.
16354 flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
16355 const struct rte_flow_action *actions[RTE_COLORS],
16356 struct rte_flow_attr *attr,
16358 uint8_t *domain_bitmap,
16359 bool *is_def_policy,
16360 struct rte_mtr_error *error)
16362 struct mlx5_priv *priv = dev->data->dev_private;
16363 struct mlx5_dev_config *dev_conf = &priv->config;
16364 const struct rte_flow_action *act;
16365 uint64_t action_flags = 0;
16368 struct rte_flow_error flow_err;
16369 uint8_t domain_color[RTE_COLORS] = {0};
16370 uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
16372 if (!priv->config.dv_esw_en)
16373 def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
16374 *domain_bitmap = def_domain;
16375 if (actions[RTE_COLOR_YELLOW] &&
16376 actions[RTE_COLOR_YELLOW]->type != RTE_FLOW_ACTION_TYPE_END)
16377 return -rte_mtr_error_set(error, ENOTSUP,
16378 RTE_MTR_ERROR_TYPE_METER_POLICY,
16380 "Yellow color does not support any action.");
16381 if (actions[RTE_COLOR_YELLOW] &&
16382 actions[RTE_COLOR_YELLOW]->type != RTE_FLOW_ACTION_TYPE_DROP)
16383 return -rte_mtr_error_set(error, ENOTSUP,
16384 RTE_MTR_ERROR_TYPE_METER_POLICY,
16385 NULL, "Red color only supports drop action.");
16387 * Check default policy actions:
16388 * Green/Yellow: no action, Red: drop action
16390 if ((!actions[RTE_COLOR_GREEN] ||
16391 actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)) {
16392 *is_def_policy = true;
16395 flow_err.message = NULL;
16396 for (i = 0; i < RTE_COLORS; i++) {
16398 for (action_flags = 0, actions_n = 0;
16399 act && act->type != RTE_FLOW_ACTION_TYPE_END;
16401 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
16402 return -rte_mtr_error_set(error, ENOTSUP,
16403 RTE_MTR_ERROR_TYPE_METER_POLICY,
16404 NULL, "too many actions");
16405 switch (act->type) {
16406 case RTE_FLOW_ACTION_TYPE_PORT_ID:
16407 if (!priv->config.dv_esw_en)
16408 return -rte_mtr_error_set(error,
16410 RTE_MTR_ERROR_TYPE_METER_POLICY,
16411 NULL, "PORT action validate check"
16412 " fail for ESW disable");
16413 ret = flow_dv_validate_action_port_id(dev,
16415 act, attr, &flow_err);
16417 return -rte_mtr_error_set(error,
16419 RTE_MTR_ERROR_TYPE_METER_POLICY,
16420 NULL, flow_err.message ?
16422 "PORT action validate check fail");
16424 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
16426 case RTE_FLOW_ACTION_TYPE_MARK:
16427 ret = flow_dv_validate_action_mark(dev, act,
16431 return -rte_mtr_error_set(error,
16433 RTE_MTR_ERROR_TYPE_METER_POLICY,
16434 NULL, flow_err.message ?
16436 "Mark action validate check fail");
16437 if (dev_conf->dv_xmeta_en !=
16438 MLX5_XMETA_MODE_LEGACY)
16439 return -rte_mtr_error_set(error,
16441 RTE_MTR_ERROR_TYPE_METER_POLICY,
16442 NULL, "Extend MARK action is "
16443 "not supported. Please try use "
16444 "default policy for meter.");
16445 action_flags |= MLX5_FLOW_ACTION_MARK;
16448 case RTE_FLOW_ACTION_TYPE_SET_TAG:
16449 ret = flow_dv_validate_action_set_tag(dev,
16453 return -rte_mtr_error_set(error,
16455 RTE_MTR_ERROR_TYPE_METER_POLICY,
16456 NULL, flow_err.message ?
16458 "Set tag action validate check fail");
16460 * Count all modify-header actions
16463 if (!(action_flags &
16464 MLX5_FLOW_MODIFY_HDR_ACTIONS))
16466 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
16468 case RTE_FLOW_ACTION_TYPE_DROP:
16469 ret = mlx5_flow_validate_action_drop
16473 return -rte_mtr_error_set(error,
16475 RTE_MTR_ERROR_TYPE_METER_POLICY,
16476 NULL, flow_err.message ?
16478 "Drop action validate check fail");
16479 action_flags |= MLX5_FLOW_ACTION_DROP;
16482 case RTE_FLOW_ACTION_TYPE_QUEUE:
16484 * Check whether extensive
16485 * metadata feature is engaged.
16487 if (dev_conf->dv_flow_en &&
16488 (dev_conf->dv_xmeta_en !=
16489 MLX5_XMETA_MODE_LEGACY) &&
16490 mlx5_flow_ext_mreg_supported(dev))
16491 return -rte_mtr_error_set(error,
16493 RTE_MTR_ERROR_TYPE_METER_POLICY,
16494 NULL, "Queue action with meta "
16495 "is not supported. Please try use "
16496 "default policy for meter.");
16497 ret = mlx5_flow_validate_action_queue(act,
16501 return -rte_mtr_error_set(error,
16503 RTE_MTR_ERROR_TYPE_METER_POLICY,
16504 NULL, flow_err.message ?
16506 "Queue action validate check fail");
16507 action_flags |= MLX5_FLOW_ACTION_QUEUE;
16510 case RTE_FLOW_ACTION_TYPE_RSS:
16511 if (dev_conf->dv_flow_en &&
16512 (dev_conf->dv_xmeta_en !=
16513 MLX5_XMETA_MODE_LEGACY) &&
16514 mlx5_flow_ext_mreg_supported(dev))
16515 return -rte_mtr_error_set(error,
16517 RTE_MTR_ERROR_TYPE_METER_POLICY,
16518 NULL, "RSS action with meta "
16519 "is not supported. Please try use "
16520 "default policy for meter.");
16521 ret = mlx5_validate_action_rss(dev, act,
16524 return -rte_mtr_error_set(error,
16526 RTE_MTR_ERROR_TYPE_METER_POLICY,
16527 NULL, flow_err.message ?
16529 "RSS action validate check fail");
16530 action_flags |= MLX5_FLOW_ACTION_RSS;
16534 case RTE_FLOW_ACTION_TYPE_JUMP:
16535 ret = flow_dv_validate_action_jump(dev,
16536 NULL, act, action_flags,
16537 attr, true, &flow_err);
16539 return -rte_mtr_error_set(error,
16541 RTE_MTR_ERROR_TYPE_METER_POLICY,
16542 NULL, flow_err.message ?
16544 "Jump action validate check fail");
16546 action_flags |= MLX5_FLOW_ACTION_JUMP;
16549 return -rte_mtr_error_set(error, ENOTSUP,
16550 RTE_MTR_ERROR_TYPE_METER_POLICY,
16552 "Doesn't support optional action");
16555 /* Yellow is not supported, just skip. */
16556 if (i == RTE_COLOR_YELLOW)
16558 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
16559 domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
16560 else if ((action_flags &
16561 (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
16562 (action_flags & MLX5_FLOW_ACTION_MARK))
16564 * Only support MLX5_XMETA_MODE_LEGACY
16565 * so MARK action only in ingress domain.
16567 domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
16569 domain_color[i] = def_domain;
16571 * Validate the drop action mutual exclusion
16572 * with other actions. Drop action is mutually-exclusive
16573 * with any other action, except for Count action.
16575 if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
16576 (action_flags & ~MLX5_FLOW_ACTION_DROP)) {
16577 return -rte_mtr_error_set(error, ENOTSUP,
16578 RTE_MTR_ERROR_TYPE_METER_POLICY,
16579 NULL, "Drop action is mutually-exclusive "
16580 "with any other action");
16582 /* Eswitch has few restrictions on using items and actions */
16583 if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
16584 if (!mlx5_flow_ext_mreg_supported(dev) &&
16585 action_flags & MLX5_FLOW_ACTION_MARK)
16586 return -rte_mtr_error_set(error, ENOTSUP,
16587 RTE_MTR_ERROR_TYPE_METER_POLICY,
16588 NULL, "unsupported action MARK");
16589 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
16590 return -rte_mtr_error_set(error, ENOTSUP,
16591 RTE_MTR_ERROR_TYPE_METER_POLICY,
16592 NULL, "unsupported action QUEUE");
16593 if (action_flags & MLX5_FLOW_ACTION_RSS)
16594 return -rte_mtr_error_set(error, ENOTSUP,
16595 RTE_MTR_ERROR_TYPE_METER_POLICY,
16596 NULL, "unsupported action RSS");
16597 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
16598 return -rte_mtr_error_set(error, ENOTSUP,
16599 RTE_MTR_ERROR_TYPE_METER_POLICY,
16600 NULL, "no fate action is found");
16602 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) &&
16604 MLX5_MTR_DOMAIN_INGRESS_BIT)) {
16605 if ((domain_color[i] &
16606 MLX5_MTR_DOMAIN_EGRESS_BIT))
16608 MLX5_MTR_DOMAIN_EGRESS_BIT;
16610 return -rte_mtr_error_set(error,
16612 RTE_MTR_ERROR_TYPE_METER_POLICY,
16613 NULL, "no fate action is found");
16616 if (domain_color[i] != def_domain)
16617 *domain_bitmap = domain_color[i];
16623 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
16625 struct mlx5_priv *priv = dev->data->dev_private;
16628 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
16629 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
16634 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
16635 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
16639 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
16640 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
16647 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
16648 .validate = flow_dv_validate,
16649 .prepare = flow_dv_prepare,
16650 .translate = flow_dv_translate,
16651 .apply = flow_dv_apply,
16652 .remove = flow_dv_remove,
16653 .destroy = flow_dv_destroy,
16654 .query = flow_dv_query,
16655 .create_mtr_tbls = flow_dv_create_mtr_tbls,
16656 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
16657 .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
16658 .create_meter = flow_dv_mtr_alloc,
16659 .free_meter = flow_dv_aso_mtr_release_to_pool,
16660 .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
16661 .create_mtr_acts = flow_dv_create_mtr_policy_acts,
16662 .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
16663 .create_policy_rules = flow_dv_create_policy_rules,
16664 .destroy_policy_rules = flow_dv_destroy_policy_rules,
16665 .create_def_policy = flow_dv_create_def_policy,
16666 .destroy_def_policy = flow_dv_destroy_def_policy,
16667 .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
16668 .counter_alloc = flow_dv_counter_allocate,
16669 .counter_free = flow_dv_counter_free,
16670 .counter_query = flow_dv_counter_query,
16671 .get_aged_flows = flow_get_aged_flows,
16672 .action_validate = flow_dv_action_validate,
16673 .action_create = flow_dv_action_create,
16674 .action_destroy = flow_dv_action_destroy,
16675 .action_update = flow_dv_action_update,
16676 .action_query = flow_dv_action_query,
16677 .sync_domain = flow_dv_sync_domain,
16680 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */