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