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(struct mlx5_dev_config *config,
1360 enum rte_flow_field_id field)
1363 case RTE_FLOW_FIELD_START:
1365 case RTE_FLOW_FIELD_MAC_DST:
1366 case RTE_FLOW_FIELD_MAC_SRC:
1368 case RTE_FLOW_FIELD_VLAN_TYPE:
1370 case RTE_FLOW_FIELD_VLAN_ID:
1372 case RTE_FLOW_FIELD_MAC_TYPE:
1374 case RTE_FLOW_FIELD_IPV4_DSCP:
1376 case RTE_FLOW_FIELD_IPV4_TTL:
1378 case RTE_FLOW_FIELD_IPV4_SRC:
1379 case RTE_FLOW_FIELD_IPV4_DST:
1381 case RTE_FLOW_FIELD_IPV6_DSCP:
1383 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1385 case RTE_FLOW_FIELD_IPV6_SRC:
1386 case RTE_FLOW_FIELD_IPV6_DST:
1388 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1389 case RTE_FLOW_FIELD_TCP_PORT_DST:
1391 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1392 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1394 case RTE_FLOW_FIELD_TCP_FLAGS:
1396 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1397 case RTE_FLOW_FIELD_UDP_PORT_DST:
1399 case RTE_FLOW_FIELD_VXLAN_VNI:
1400 case RTE_FLOW_FIELD_GENEVE_VNI:
1402 case RTE_FLOW_FIELD_GTP_TEID:
1403 case RTE_FLOW_FIELD_TAG:
1405 case RTE_FLOW_FIELD_MARK:
1407 case RTE_FLOW_FIELD_META:
1408 if (config->dv_xmeta_en == MLX5_XMETA_MODE_META16)
1410 else if (config->dv_xmeta_en == MLX5_XMETA_MODE_META32)
1414 case RTE_FLOW_FIELD_POINTER:
1415 case RTE_FLOW_FIELD_VALUE:
1424 mlx5_flow_field_id_to_modify_info
1425 (const struct rte_flow_action_modify_data *data,
1426 struct field_modify_info *info,
1427 uint32_t *mask, uint32_t *value,
1428 uint32_t width, uint32_t dst_width,
1429 struct rte_eth_dev *dev,
1430 const struct rte_flow_attr *attr,
1431 struct rte_flow_error *error)
1433 struct mlx5_priv *priv = dev->data->dev_private;
1434 struct mlx5_dev_config *config = &priv->config;
1437 switch (data->field) {
1438 case RTE_FLOW_FIELD_START:
1439 /* not supported yet */
1442 case RTE_FLOW_FIELD_MAC_DST:
1444 if (data->offset < 32) {
1445 info[idx] = (struct field_modify_info){4, 0,
1446 MLX5_MODI_OUT_DMAC_47_16};
1449 rte_cpu_to_be_32(0xffffffff >>
1453 mask[idx] = RTE_BE32(0xffffffff);
1460 info[idx] = (struct field_modify_info){2, 4 * idx,
1461 MLX5_MODI_OUT_DMAC_15_0};
1462 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1464 if (data->offset < 32)
1465 info[idx++] = (struct field_modify_info){4, 0,
1466 MLX5_MODI_OUT_DMAC_47_16};
1467 info[idx] = (struct field_modify_info){2, 0,
1468 MLX5_MODI_OUT_DMAC_15_0};
1471 case RTE_FLOW_FIELD_MAC_SRC:
1473 if (data->offset < 32) {
1474 info[idx] = (struct field_modify_info){4, 0,
1475 MLX5_MODI_OUT_SMAC_47_16};
1478 rte_cpu_to_be_32(0xffffffff >>
1482 mask[idx] = RTE_BE32(0xffffffff);
1489 info[idx] = (struct field_modify_info){2, 4 * idx,
1490 MLX5_MODI_OUT_SMAC_15_0};
1491 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1493 if (data->offset < 32)
1494 info[idx++] = (struct field_modify_info){4, 0,
1495 MLX5_MODI_OUT_SMAC_47_16};
1496 info[idx] = (struct field_modify_info){2, 0,
1497 MLX5_MODI_OUT_SMAC_15_0};
1500 case RTE_FLOW_FIELD_VLAN_TYPE:
1501 /* not supported yet */
1503 case RTE_FLOW_FIELD_VLAN_ID:
1504 info[idx] = (struct field_modify_info){2, 0,
1505 MLX5_MODI_OUT_FIRST_VID};
1507 mask[idx] = rte_cpu_to_be_16(0x0fff >> (12 - width));
1509 case RTE_FLOW_FIELD_MAC_TYPE:
1510 info[idx] = (struct field_modify_info){2, 0,
1511 MLX5_MODI_OUT_ETHERTYPE};
1513 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1515 case RTE_FLOW_FIELD_IPV4_DSCP:
1516 info[idx] = (struct field_modify_info){1, 0,
1517 MLX5_MODI_OUT_IP_DSCP};
1519 mask[idx] = 0x3f >> (6 - width);
1521 case RTE_FLOW_FIELD_IPV4_TTL:
1522 info[idx] = (struct field_modify_info){1, 0,
1523 MLX5_MODI_OUT_IPV4_TTL};
1525 mask[idx] = 0xff >> (8 - width);
1527 case RTE_FLOW_FIELD_IPV4_SRC:
1528 info[idx] = (struct field_modify_info){4, 0,
1529 MLX5_MODI_OUT_SIPV4};
1531 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1534 case RTE_FLOW_FIELD_IPV4_DST:
1535 info[idx] = (struct field_modify_info){4, 0,
1536 MLX5_MODI_OUT_DIPV4};
1538 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1541 case RTE_FLOW_FIELD_IPV6_DSCP:
1542 info[idx] = (struct field_modify_info){1, 0,
1543 MLX5_MODI_OUT_IP_DSCP};
1545 mask[idx] = 0x3f >> (6 - width);
1547 case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1548 info[idx] = (struct field_modify_info){1, 0,
1549 MLX5_MODI_OUT_IPV6_HOPLIMIT};
1551 mask[idx] = 0xff >> (8 - width);
1553 case RTE_FLOW_FIELD_IPV6_SRC:
1555 if (data->offset < 32) {
1556 info[idx] = (struct field_modify_info){4,
1558 MLX5_MODI_OUT_SIPV6_31_0};
1561 rte_cpu_to_be_32(0xffffffff >>
1565 mask[idx] = RTE_BE32(0xffffffff);
1572 if (data->offset < 64) {
1573 info[idx] = (struct field_modify_info){4,
1575 MLX5_MODI_OUT_SIPV6_63_32};
1578 rte_cpu_to_be_32(0xffffffff >>
1582 mask[idx] = RTE_BE32(0xffffffff);
1589 if (data->offset < 96) {
1590 info[idx] = (struct field_modify_info){4,
1592 MLX5_MODI_OUT_SIPV6_95_64};
1595 rte_cpu_to_be_32(0xffffffff >>
1599 mask[idx] = RTE_BE32(0xffffffff);
1606 info[idx] = (struct field_modify_info){4, 4 * idx,
1607 MLX5_MODI_OUT_SIPV6_127_96};
1608 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1611 if (data->offset < 32)
1612 info[idx++] = (struct field_modify_info){4, 0,
1613 MLX5_MODI_OUT_SIPV6_31_0};
1614 if (data->offset < 64)
1615 info[idx++] = (struct field_modify_info){4, 0,
1616 MLX5_MODI_OUT_SIPV6_63_32};
1617 if (data->offset < 96)
1618 info[idx++] = (struct field_modify_info){4, 0,
1619 MLX5_MODI_OUT_SIPV6_95_64};
1620 if (data->offset < 128)
1621 info[idx++] = (struct field_modify_info){4, 0,
1622 MLX5_MODI_OUT_SIPV6_127_96};
1625 case RTE_FLOW_FIELD_IPV6_DST:
1627 if (data->offset < 32) {
1628 info[idx] = (struct field_modify_info){4,
1630 MLX5_MODI_OUT_DIPV6_31_0};
1633 rte_cpu_to_be_32(0xffffffff >>
1637 mask[idx] = RTE_BE32(0xffffffff);
1644 if (data->offset < 64) {
1645 info[idx] = (struct field_modify_info){4,
1647 MLX5_MODI_OUT_DIPV6_63_32};
1650 rte_cpu_to_be_32(0xffffffff >>
1654 mask[idx] = RTE_BE32(0xffffffff);
1661 if (data->offset < 96) {
1662 info[idx] = (struct field_modify_info){4,
1664 MLX5_MODI_OUT_DIPV6_95_64};
1667 rte_cpu_to_be_32(0xffffffff >>
1671 mask[idx] = RTE_BE32(0xffffffff);
1678 info[idx] = (struct field_modify_info){4, 4 * idx,
1679 MLX5_MODI_OUT_DIPV6_127_96};
1680 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1683 if (data->offset < 32)
1684 info[idx++] = (struct field_modify_info){4, 0,
1685 MLX5_MODI_OUT_DIPV6_31_0};
1686 if (data->offset < 64)
1687 info[idx++] = (struct field_modify_info){4, 0,
1688 MLX5_MODI_OUT_DIPV6_63_32};
1689 if (data->offset < 96)
1690 info[idx++] = (struct field_modify_info){4, 0,
1691 MLX5_MODI_OUT_DIPV6_95_64};
1692 if (data->offset < 128)
1693 info[idx++] = (struct field_modify_info){4, 0,
1694 MLX5_MODI_OUT_DIPV6_127_96};
1697 case RTE_FLOW_FIELD_TCP_PORT_SRC:
1698 info[idx] = (struct field_modify_info){2, 0,
1699 MLX5_MODI_OUT_TCP_SPORT};
1701 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1703 case RTE_FLOW_FIELD_TCP_PORT_DST:
1704 info[idx] = (struct field_modify_info){2, 0,
1705 MLX5_MODI_OUT_TCP_DPORT};
1707 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1709 case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1710 info[idx] = (struct field_modify_info){4, 0,
1711 MLX5_MODI_OUT_TCP_SEQ_NUM};
1713 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1716 case RTE_FLOW_FIELD_TCP_ACK_NUM:
1717 info[idx] = (struct field_modify_info){4, 0,
1718 MLX5_MODI_OUT_TCP_ACK_NUM};
1720 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1723 case RTE_FLOW_FIELD_TCP_FLAGS:
1724 info[idx] = (struct field_modify_info){2, 0,
1725 MLX5_MODI_OUT_TCP_FLAGS};
1727 mask[idx] = rte_cpu_to_be_16(0x1ff >> (9 - width));
1729 case RTE_FLOW_FIELD_UDP_PORT_SRC:
1730 info[idx] = (struct field_modify_info){2, 0,
1731 MLX5_MODI_OUT_UDP_SPORT};
1733 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1735 case RTE_FLOW_FIELD_UDP_PORT_DST:
1736 info[idx] = (struct field_modify_info){2, 0,
1737 MLX5_MODI_OUT_UDP_DPORT};
1739 mask[idx] = rte_cpu_to_be_16(0xffff >> (16 - width));
1741 case RTE_FLOW_FIELD_VXLAN_VNI:
1742 /* not supported yet */
1744 case RTE_FLOW_FIELD_GENEVE_VNI:
1745 /* not supported yet*/
1747 case RTE_FLOW_FIELD_GTP_TEID:
1748 info[idx] = (struct field_modify_info){4, 0,
1749 MLX5_MODI_GTP_TEID};
1751 mask[idx] = rte_cpu_to_be_32(0xffffffff >>
1754 case RTE_FLOW_FIELD_TAG:
1756 int reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
1757 data->level, error);
1760 MLX5_ASSERT(reg != REG_NON);
1761 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1762 info[idx] = (struct field_modify_info){4, 0,
1766 rte_cpu_to_be_32(0xffffffff >>
1770 case RTE_FLOW_FIELD_MARK:
1772 int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
1776 MLX5_ASSERT(reg != REG_NON);
1777 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1778 info[idx] = (struct field_modify_info){4, 0,
1782 rte_cpu_to_be_32(0xffffffff >>
1786 case RTE_FLOW_FIELD_META:
1788 unsigned int xmeta = config->dv_xmeta_en;
1789 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1792 MLX5_ASSERT(reg != REG_NON);
1793 MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
1794 if (xmeta == MLX5_XMETA_MODE_META16) {
1795 info[idx] = (struct field_modify_info){2, 0,
1798 mask[idx] = rte_cpu_to_be_16(0xffff >>
1800 } else if (xmeta == MLX5_XMETA_MODE_META32) {
1801 info[idx] = (struct field_modify_info){4, 0,
1805 rte_cpu_to_be_32(0xffffffff >>
1812 case RTE_FLOW_FIELD_POINTER:
1813 case RTE_FLOW_FIELD_VALUE:
1814 if (data->field == RTE_FLOW_FIELD_POINTER)
1815 memcpy(&val, (void *)(uintptr_t)data->value,
1819 for (idx = 0; idx < MLX5_ACT_MAX_MOD_FIELDS; idx++) {
1821 if (dst_width > 16) {
1822 value[idx] = rte_cpu_to_be_32(val);
1824 } else if (dst_width > 8) {
1825 value[idx] = rte_cpu_to_be_16(val);
1828 value[idx] = (uint8_t)val;
1843 * Convert modify_field action to DV specification.
1846 * Pointer to the rte_eth_dev structure.
1847 * @param[in,out] resource
1848 * Pointer to the modify-header resource.
1850 * Pointer to action specification.
1852 * Attributes of flow that includes this item.
1854 * Pointer to the error structure.
1857 * 0 on success, a negative errno value otherwise and rte_errno is set.
1860 flow_dv_convert_action_modify_field
1861 (struct rte_eth_dev *dev,
1862 struct mlx5_flow_dv_modify_hdr_resource *resource,
1863 const struct rte_flow_action *action,
1864 const struct rte_flow_attr *attr,
1865 struct rte_flow_error *error)
1867 struct mlx5_priv *priv = dev->data->dev_private;
1868 struct mlx5_dev_config *config = &priv->config;
1869 const struct rte_flow_action_modify_field *conf =
1870 (const struct rte_flow_action_modify_field *)(action->conf);
1871 struct rte_flow_item item;
1872 struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
1874 struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
1876 uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1877 uint32_t value[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
1879 uint32_t dst_width = mlx5_flow_item_field_width(config,
1882 if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
1883 conf->src.field == RTE_FLOW_FIELD_VALUE) {
1884 type = MLX5_MODIFICATION_TYPE_SET;
1885 /** For SET fill the destination field (field) first. */
1886 mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
1887 value, conf->width, dst_width, dev, attr, error);
1888 /** Then copy immediate value from source as per mask. */
1889 mlx5_flow_field_id_to_modify_info(&conf->src, dcopy, mask,
1890 value, conf->width, dst_width, dev, attr, error);
1893 type = MLX5_MODIFICATION_TYPE_COPY;
1894 /** For COPY fill the destination field (dcopy) without mask. */
1895 mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
1896 value, conf->width, dst_width, dev, attr, error);
1897 /** Then construct the source field (field) with mask. */
1898 mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
1899 value, conf->width, dst_width, dev, attr, error);
1902 return flow_dv_convert_modify_action(&item,
1903 field, dcopy, resource, type, error);
1907 * Validate MARK item.
1910 * Pointer to the rte_eth_dev structure.
1912 * Item specification.
1914 * Attributes of flow that includes this item.
1916 * Pointer to error structure.
1919 * 0 on success, a negative errno value otherwise and rte_errno is set.
1922 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1923 const struct rte_flow_item *item,
1924 const struct rte_flow_attr *attr __rte_unused,
1925 struct rte_flow_error *error)
1927 struct mlx5_priv *priv = dev->data->dev_private;
1928 struct mlx5_dev_config *config = &priv->config;
1929 const struct rte_flow_item_mark *spec = item->spec;
1930 const struct rte_flow_item_mark *mask = item->mask;
1931 const struct rte_flow_item_mark nic_mask = {
1932 .id = priv->sh->dv_mark_mask,
1936 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1937 return rte_flow_error_set(error, ENOTSUP,
1938 RTE_FLOW_ERROR_TYPE_ITEM, item,
1939 "extended metadata feature"
1941 if (!mlx5_flow_ext_mreg_supported(dev))
1942 return rte_flow_error_set(error, ENOTSUP,
1943 RTE_FLOW_ERROR_TYPE_ITEM, item,
1944 "extended metadata register"
1945 " isn't supported");
1947 return rte_flow_error_set(error, ENOTSUP,
1948 RTE_FLOW_ERROR_TYPE_ITEM, item,
1949 "extended metadata register"
1950 " isn't available");
1951 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1955 return rte_flow_error_set(error, EINVAL,
1956 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1958 "data cannot be empty");
1959 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1960 return rte_flow_error_set(error, EINVAL,
1961 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1963 "mark id exceeds the limit");
1967 return rte_flow_error_set(error, EINVAL,
1968 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1969 "mask cannot be zero");
1971 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1972 (const uint8_t *)&nic_mask,
1973 sizeof(struct rte_flow_item_mark),
1974 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1981 * Validate META item.
1984 * Pointer to the rte_eth_dev structure.
1986 * Item specification.
1988 * Attributes of flow that includes this item.
1990 * Pointer to error structure.
1993 * 0 on success, a negative errno value otherwise and rte_errno is set.
1996 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1997 const struct rte_flow_item *item,
1998 const struct rte_flow_attr *attr,
1999 struct rte_flow_error *error)
2001 struct mlx5_priv *priv = dev->data->dev_private;
2002 struct mlx5_dev_config *config = &priv->config;
2003 const struct rte_flow_item_meta *spec = item->spec;
2004 const struct rte_flow_item_meta *mask = item->mask;
2005 struct rte_flow_item_meta nic_mask = {
2012 return rte_flow_error_set(error, EINVAL,
2013 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2015 "data cannot be empty");
2016 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2017 if (!mlx5_flow_ext_mreg_supported(dev))
2018 return rte_flow_error_set(error, ENOTSUP,
2019 RTE_FLOW_ERROR_TYPE_ITEM, item,
2020 "extended metadata register"
2021 " isn't supported");
2022 reg = flow_dv_get_metadata_reg(dev, attr, error);
2026 return rte_flow_error_set(error, ENOTSUP,
2027 RTE_FLOW_ERROR_TYPE_ITEM, item,
2028 "unavalable extended metadata register");
2030 return rte_flow_error_set(error, ENOTSUP,
2031 RTE_FLOW_ERROR_TYPE_ITEM, item,
2035 nic_mask.data = priv->sh->dv_meta_mask;
2038 return rte_flow_error_set(error, ENOTSUP,
2039 RTE_FLOW_ERROR_TYPE_ITEM, item,
2040 "extended metadata feature "
2041 "should be enabled when "
2042 "meta item is requested "
2043 "with e-switch mode ");
2045 return rte_flow_error_set(error, ENOTSUP,
2046 RTE_FLOW_ERROR_TYPE_ITEM, item,
2047 "match on metadata for ingress "
2048 "is not supported in legacy "
2052 mask = &rte_flow_item_meta_mask;
2054 return rte_flow_error_set(error, EINVAL,
2055 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2056 "mask cannot be zero");
2058 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2059 (const uint8_t *)&nic_mask,
2060 sizeof(struct rte_flow_item_meta),
2061 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2066 * Validate TAG item.
2069 * Pointer to the rte_eth_dev structure.
2071 * Item specification.
2073 * Attributes of flow that includes this item.
2075 * Pointer to error structure.
2078 * 0 on success, a negative errno value otherwise and rte_errno is set.
2081 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2082 const struct rte_flow_item *item,
2083 const struct rte_flow_attr *attr __rte_unused,
2084 struct rte_flow_error *error)
2086 const struct rte_flow_item_tag *spec = item->spec;
2087 const struct rte_flow_item_tag *mask = item->mask;
2088 const struct rte_flow_item_tag nic_mask = {
2089 .data = RTE_BE32(UINT32_MAX),
2094 if (!mlx5_flow_ext_mreg_supported(dev))
2095 return rte_flow_error_set(error, ENOTSUP,
2096 RTE_FLOW_ERROR_TYPE_ITEM, item,
2097 "extensive metadata register"
2098 " isn't supported");
2100 return rte_flow_error_set(error, EINVAL,
2101 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2103 "data cannot be empty");
2105 mask = &rte_flow_item_tag_mask;
2107 return rte_flow_error_set(error, EINVAL,
2108 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2109 "mask cannot be zero");
2111 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2112 (const uint8_t *)&nic_mask,
2113 sizeof(struct rte_flow_item_tag),
2114 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2117 if (mask->index != 0xff)
2118 return rte_flow_error_set(error, EINVAL,
2119 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2120 "partial mask for tag index"
2121 " is not supported");
2122 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2125 MLX5_ASSERT(ret != REG_NON);
2130 * Validate vport item.
2133 * Pointer to the rte_eth_dev structure.
2135 * Item specification.
2137 * Attributes of flow that includes this item.
2138 * @param[in] item_flags
2139 * Bit-fields that holds the items detected until now.
2141 * Pointer to error structure.
2144 * 0 on success, a negative errno value otherwise and rte_errno is set.
2147 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2148 const struct rte_flow_item *item,
2149 const struct rte_flow_attr *attr,
2150 uint64_t item_flags,
2151 struct rte_flow_error *error)
2153 const struct rte_flow_item_port_id *spec = item->spec;
2154 const struct rte_flow_item_port_id *mask = item->mask;
2155 const struct rte_flow_item_port_id switch_mask = {
2158 struct mlx5_priv *esw_priv;
2159 struct mlx5_priv *dev_priv;
2162 if (!attr->transfer)
2163 return rte_flow_error_set(error, EINVAL,
2164 RTE_FLOW_ERROR_TYPE_ITEM,
2166 "match on port id is valid only"
2167 " when transfer flag is enabled");
2168 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2169 return rte_flow_error_set(error, ENOTSUP,
2170 RTE_FLOW_ERROR_TYPE_ITEM, item,
2171 "multiple source ports are not"
2174 mask = &switch_mask;
2175 if (mask->id != 0xffffffff)
2176 return rte_flow_error_set(error, ENOTSUP,
2177 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2179 "no support for partial mask on"
2181 ret = mlx5_flow_item_acceptable
2182 (item, (const uint8_t *)mask,
2183 (const uint8_t *)&rte_flow_item_port_id_mask,
2184 sizeof(struct rte_flow_item_port_id),
2185 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2190 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2192 return rte_flow_error_set(error, rte_errno,
2193 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2194 "failed to obtain E-Switch info for"
2196 dev_priv = mlx5_dev_to_eswitch_info(dev);
2198 return rte_flow_error_set(error, rte_errno,
2199 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2201 "failed to obtain E-Switch info");
2202 if (esw_priv->domain_id != dev_priv->domain_id)
2203 return rte_flow_error_set(error, EINVAL,
2204 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2205 "cannot match on a port from a"
2206 " different E-Switch");
2211 * Validate VLAN item.
2214 * Item specification.
2215 * @param[in] item_flags
2216 * Bit-fields that holds the items detected until now.
2218 * Ethernet device flow is being created on.
2220 * Pointer to error structure.
2223 * 0 on success, a negative errno value otherwise and rte_errno is set.
2226 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2227 uint64_t item_flags,
2228 struct rte_eth_dev *dev,
2229 struct rte_flow_error *error)
2231 const struct rte_flow_item_vlan *mask = item->mask;
2232 const struct rte_flow_item_vlan nic_mask = {
2233 .tci = RTE_BE16(UINT16_MAX),
2234 .inner_type = RTE_BE16(UINT16_MAX),
2237 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2239 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2240 MLX5_FLOW_LAYER_INNER_L4) :
2241 (MLX5_FLOW_LAYER_OUTER_L3 |
2242 MLX5_FLOW_LAYER_OUTER_L4);
2243 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2244 MLX5_FLOW_LAYER_OUTER_VLAN;
2246 if (item_flags & vlanm)
2247 return rte_flow_error_set(error, EINVAL,
2248 RTE_FLOW_ERROR_TYPE_ITEM, item,
2249 "multiple VLAN layers not supported");
2250 else if ((item_flags & l34m) != 0)
2251 return rte_flow_error_set(error, EINVAL,
2252 RTE_FLOW_ERROR_TYPE_ITEM, item,
2253 "VLAN cannot follow L3/L4 layer");
2255 mask = &rte_flow_item_vlan_mask;
2256 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2257 (const uint8_t *)&nic_mask,
2258 sizeof(struct rte_flow_item_vlan),
2259 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2262 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
2263 struct mlx5_priv *priv = dev->data->dev_private;
2265 if (priv->vmwa_context) {
2267 * Non-NULL context means we have a virtual machine
2268 * and SR-IOV enabled, we have to create VLAN interface
2269 * to make hypervisor to setup E-Switch vport
2270 * context correctly. We avoid creating the multiple
2271 * VLAN interfaces, so we cannot support VLAN tag mask.
2273 return rte_flow_error_set(error, EINVAL,
2274 RTE_FLOW_ERROR_TYPE_ITEM,
2276 "VLAN tag mask is not"
2277 " supported in virtual"
2285 * GTP flags are contained in 1 byte of the format:
2286 * -------------------------------------------
2287 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2288 * |-----------------------------------------|
2289 * | value | Version | PT | Res | E | S | PN |
2290 * -------------------------------------------
2292 * Matching is supported only for GTP flags E, S, PN.
2294 #define MLX5_GTP_FLAGS_MASK 0x07
2297 * Validate GTP item.
2300 * Pointer to the rte_eth_dev structure.
2302 * Item specification.
2303 * @param[in] item_flags
2304 * Bit-fields that holds the items detected until now.
2306 * Pointer to error structure.
2309 * 0 on success, a negative errno value otherwise and rte_errno is set.
2312 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2313 const struct rte_flow_item *item,
2314 uint64_t item_flags,
2315 struct rte_flow_error *error)
2317 struct mlx5_priv *priv = dev->data->dev_private;
2318 const struct rte_flow_item_gtp *spec = item->spec;
2319 const struct rte_flow_item_gtp *mask = item->mask;
2320 const struct rte_flow_item_gtp nic_mask = {
2321 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
2323 .teid = RTE_BE32(0xffffffff),
2326 if (!priv->config.hca_attr.tunnel_stateless_gtp)
2327 return rte_flow_error_set(error, ENOTSUP,
2328 RTE_FLOW_ERROR_TYPE_ITEM, item,
2329 "GTP support is not enabled");
2330 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2331 return rte_flow_error_set(error, ENOTSUP,
2332 RTE_FLOW_ERROR_TYPE_ITEM, item,
2333 "multiple tunnel layers not"
2335 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2336 return rte_flow_error_set(error, EINVAL,
2337 RTE_FLOW_ERROR_TYPE_ITEM, item,
2338 "no outer UDP layer found");
2340 mask = &rte_flow_item_gtp_mask;
2341 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
2342 return rte_flow_error_set(error, ENOTSUP,
2343 RTE_FLOW_ERROR_TYPE_ITEM, item,
2344 "Match is supported for GTP"
2346 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2347 (const uint8_t *)&nic_mask,
2348 sizeof(struct rte_flow_item_gtp),
2349 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2353 * Validate GTP PSC item.
2356 * Item specification.
2357 * @param[in] last_item
2358 * Previous validated item in the pattern items.
2359 * @param[in] gtp_item
2360 * Previous GTP item specification.
2362 * Pointer to flow attributes.
2364 * Pointer to error structure.
2367 * 0 on success, a negative errno value otherwise and rte_errno is set.
2370 flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
2372 const struct rte_flow_item *gtp_item,
2373 const struct rte_flow_attr *attr,
2374 struct rte_flow_error *error)
2376 const struct rte_flow_item_gtp *gtp_spec;
2377 const struct rte_flow_item_gtp *gtp_mask;
2378 const struct rte_flow_item_gtp_psc *spec;
2379 const struct rte_flow_item_gtp_psc *mask;
2380 const struct rte_flow_item_gtp_psc nic_mask = {
2385 if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2386 return rte_flow_error_set
2387 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2388 "GTP PSC item must be preceded with GTP item");
2389 gtp_spec = gtp_item->spec;
2390 gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2391 /* GTP spec and E flag is requested to match zero. */
2393 (gtp_mask->v_pt_rsv_flags &
2394 ~gtp_spec->v_pt_rsv_flags & MLX5_GTP_EXT_HEADER_FLAG))
2395 return rte_flow_error_set
2396 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2397 "GTP E flag must be 1 to match GTP PSC");
2398 /* Check the flow is not created in group zero. */
2399 if (!attr->transfer && !attr->group)
2400 return rte_flow_error_set
2401 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2402 "GTP PSC is not supported for group 0");
2403 /* GTP spec is here and E flag is requested to match zero. */
2407 mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2408 if (spec->pdu_type > MLX5_GTP_EXT_MAX_PDU_TYPE)
2409 return rte_flow_error_set
2410 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2411 "PDU type should be smaller than 16");
2412 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
2413 (const uint8_t *)&nic_mask,
2414 sizeof(struct rte_flow_item_gtp_psc),
2415 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2419 * Validate IPV4 item.
2420 * Use existing validation function mlx5_flow_validate_item_ipv4(), and
2421 * add specific validation of fragment_offset field,
2424 * Item specification.
2425 * @param[in] item_flags
2426 * Bit-fields that holds the items detected until now.
2428 * Pointer to error structure.
2431 * 0 on success, a negative errno value otherwise and rte_errno is set.
2434 flow_dv_validate_item_ipv4(const struct rte_flow_item *item,
2435 uint64_t item_flags,
2437 uint16_t ether_type,
2438 struct rte_flow_error *error)
2441 const struct rte_flow_item_ipv4 *spec = item->spec;
2442 const struct rte_flow_item_ipv4 *last = item->last;
2443 const struct rte_flow_item_ipv4 *mask = item->mask;
2444 rte_be16_t fragment_offset_spec = 0;
2445 rte_be16_t fragment_offset_last = 0;
2446 const struct rte_flow_item_ipv4 nic_ipv4_mask = {
2448 .src_addr = RTE_BE32(0xffffffff),
2449 .dst_addr = RTE_BE32(0xffffffff),
2450 .type_of_service = 0xff,
2451 .fragment_offset = RTE_BE16(0xffff),
2452 .next_proto_id = 0xff,
2453 .time_to_live = 0xff,
2457 ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
2458 ether_type, &nic_ipv4_mask,
2459 MLX5_ITEM_RANGE_ACCEPTED, error);
2463 fragment_offset_spec = spec->hdr.fragment_offset &
2464 mask->hdr.fragment_offset;
2465 if (!fragment_offset_spec)
2468 * spec and mask are valid, enforce using full mask to make sure the
2469 * complete value is used correctly.
2471 if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2472 != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2473 return rte_flow_error_set(error, EINVAL,
2474 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2475 item, "must use full mask for"
2476 " fragment_offset");
2478 * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
2479 * indicating this is 1st fragment of fragmented packet.
2480 * This is not yet supported in MLX5, return appropriate error message.
2482 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
2483 return rte_flow_error_set(error, ENOTSUP,
2484 RTE_FLOW_ERROR_TYPE_ITEM, item,
2485 "match on first fragment not "
2487 if (fragment_offset_spec && !last)
2488 return rte_flow_error_set(error, ENOTSUP,
2489 RTE_FLOW_ERROR_TYPE_ITEM, item,
2490 "specified value not supported");
2491 /* spec and last are valid, validate the specified range. */
2492 fragment_offset_last = last->hdr.fragment_offset &
2493 mask->hdr.fragment_offset;
2495 * Match on fragment_offset spec 0x2001 and last 0x3fff
2496 * means MF is 1 and frag-offset is > 0.
2497 * This packet is fragment 2nd and onward, excluding last.
2498 * This is not yet supported in MLX5, return appropriate
2501 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
2502 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
2503 return rte_flow_error_set(error, ENOTSUP,
2504 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2505 last, "match on following "
2506 "fragments not supported");
2508 * Match on fragment_offset spec 0x0001 and last 0x1fff
2509 * means MF is 0 and frag-offset is > 0.
2510 * This packet is last fragment of fragmented packet.
2511 * This is not yet supported in MLX5, return appropriate
2514 if (fragment_offset_spec == RTE_BE16(1) &&
2515 fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
2516 return rte_flow_error_set(error, ENOTSUP,
2517 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2518 last, "match on last "
2519 "fragment not supported");
2521 * Match on fragment_offset spec 0x0001 and last 0x3fff
2522 * means MF and/or frag-offset is not 0.
2523 * This is a fragmented packet.
2524 * Other range values are invalid and rejected.
2526 if (!(fragment_offset_spec == RTE_BE16(1) &&
2527 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
2528 return rte_flow_error_set(error, ENOTSUP,
2529 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2530 "specified range not supported");
2535 * Validate IPV6 fragment extension item.
2538 * Item specification.
2539 * @param[in] item_flags
2540 * Bit-fields that holds the items detected until now.
2542 * Pointer to error structure.
2545 * 0 on success, a negative errno value otherwise and rte_errno is set.
2548 flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
2549 uint64_t item_flags,
2550 struct rte_flow_error *error)
2552 const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
2553 const struct rte_flow_item_ipv6_frag_ext *last = item->last;
2554 const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
2555 rte_be16_t frag_data_spec = 0;
2556 rte_be16_t frag_data_last = 0;
2557 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2558 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2559 MLX5_FLOW_LAYER_OUTER_L4;
2561 struct rte_flow_item_ipv6_frag_ext nic_mask = {
2563 .next_header = 0xff,
2564 .frag_data = RTE_BE16(0xffff),
2568 if (item_flags & l4m)
2569 return rte_flow_error_set(error, EINVAL,
2570 RTE_FLOW_ERROR_TYPE_ITEM, item,
2571 "ipv6 fragment extension item cannot "
2573 if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
2574 (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
2575 return rte_flow_error_set(error, EINVAL,
2576 RTE_FLOW_ERROR_TYPE_ITEM, item,
2577 "ipv6 fragment extension item must "
2578 "follow ipv6 item");
2580 frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
2581 if (!frag_data_spec)
2584 * spec and mask are valid, enforce using full mask to make sure the
2585 * complete value is used correctly.
2587 if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
2588 RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2589 return rte_flow_error_set(error, EINVAL,
2590 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2591 item, "must use full mask for"
2594 * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2595 * This is 1st fragment of fragmented packet.
2597 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2598 return rte_flow_error_set(error, ENOTSUP,
2599 RTE_FLOW_ERROR_TYPE_ITEM, item,
2600 "match on first fragment not "
2602 if (frag_data_spec && !last)
2603 return rte_flow_error_set(error, EINVAL,
2604 RTE_FLOW_ERROR_TYPE_ITEM, item,
2605 "specified value not supported");
2606 ret = mlx5_flow_item_acceptable
2607 (item, (const uint8_t *)mask,
2608 (const uint8_t *)&nic_mask,
2609 sizeof(struct rte_flow_item_ipv6_frag_ext),
2610 MLX5_ITEM_RANGE_ACCEPTED, error);
2613 /* spec and last are valid, validate the specified range. */
2614 frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2616 * Match on frag_data spec 0x0009 and last 0xfff9
2617 * means M is 1 and frag-offset is > 0.
2618 * This packet is fragment 2nd and onward, excluding last.
2619 * This is not yet supported in MLX5, return appropriate
2622 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2623 RTE_IPV6_EHDR_MF_MASK) &&
2624 frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2625 return rte_flow_error_set(error, ENOTSUP,
2626 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2627 last, "match on following "
2628 "fragments not supported");
2630 * Match on frag_data spec 0x0008 and last 0xfff8
2631 * means M is 0 and frag-offset is > 0.
2632 * This packet is last fragment of fragmented packet.
2633 * This is not yet supported in MLX5, return appropriate
2636 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2637 frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2638 return rte_flow_error_set(error, ENOTSUP,
2639 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2640 last, "match on last "
2641 "fragment not supported");
2642 /* Other range values are invalid and rejected. */
2643 return rte_flow_error_set(error, EINVAL,
2644 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2645 "specified range not supported");
2649 * Validate ASO CT item.
2652 * Pointer to the rte_eth_dev structure.
2654 * Item specification.
2655 * @param[in] item_flags
2656 * Pointer to bit-fields that holds the items detected until now.
2658 * Pointer to error structure.
2661 * 0 on success, a negative errno value otherwise and rte_errno is set.
2664 flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
2665 const struct rte_flow_item *item,
2666 uint64_t *item_flags,
2667 struct rte_flow_error *error)
2669 const struct rte_flow_item_conntrack *spec = item->spec;
2670 const struct rte_flow_item_conntrack *mask = item->mask;
2674 if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
2675 return rte_flow_error_set(error, EINVAL,
2676 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2677 "Only one CT is supported");
2679 mask = &rte_flow_item_conntrack_mask;
2680 flags = spec->flags & mask->flags;
2681 if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
2682 ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
2683 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
2684 (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
2685 return rte_flow_error_set(error, EINVAL,
2686 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2687 "Conflict status bits");
2688 /* State change also needs to be considered. */
2689 *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
2694 * Validate the pop VLAN action.
2697 * Pointer to the rte_eth_dev structure.
2698 * @param[in] action_flags
2699 * Holds the actions detected until now.
2701 * Pointer to the pop vlan action.
2702 * @param[in] item_flags
2703 * The items found in this flow rule.
2705 * Pointer to flow attributes.
2707 * Pointer to error structure.
2710 * 0 on success, a negative errno value otherwise and rte_errno is set.
2713 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
2714 uint64_t action_flags,
2715 const struct rte_flow_action *action,
2716 uint64_t item_flags,
2717 const struct rte_flow_attr *attr,
2718 struct rte_flow_error *error)
2720 const struct mlx5_priv *priv = dev->data->dev_private;
2724 if (!priv->sh->pop_vlan_action)
2725 return rte_flow_error_set(error, ENOTSUP,
2726 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2728 "pop vlan action is not supported");
2730 return rte_flow_error_set(error, ENOTSUP,
2731 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2733 "pop vlan action not supported for "
2735 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
2736 return rte_flow_error_set(error, ENOTSUP,
2737 RTE_FLOW_ERROR_TYPE_ACTION, action,
2738 "no support for multiple VLAN "
2740 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
2741 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
2742 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
2743 return rte_flow_error_set(error, ENOTSUP,
2744 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2746 "cannot pop vlan after decap without "
2747 "match on inner vlan in the flow");
2748 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
2749 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
2750 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2751 return rte_flow_error_set(error, ENOTSUP,
2752 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2754 "cannot pop vlan without a "
2755 "match on (outer) vlan in the flow");
2756 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2757 return rte_flow_error_set(error, EINVAL,
2758 RTE_FLOW_ERROR_TYPE_ACTION, action,
2759 "wrong action order, port_id should "
2760 "be after pop VLAN action");
2761 if (!attr->transfer && priv->representor)
2762 return rte_flow_error_set(error, ENOTSUP,
2763 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2764 "pop vlan action for VF representor "
2765 "not supported on NIC table");
2770 * Get VLAN default info from vlan match info.
2773 * the list of item specifications.
2775 * pointer VLAN info to fill to.
2778 * 0 on success, a negative errno value otherwise and rte_errno is set.
2781 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
2782 struct rte_vlan_hdr *vlan)
2784 const struct rte_flow_item_vlan nic_mask = {
2785 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
2786 MLX5DV_FLOW_VLAN_VID_MASK),
2787 .inner_type = RTE_BE16(0xffff),
2792 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2793 int type = items->type;
2795 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
2796 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
2799 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
2800 const struct rte_flow_item_vlan *vlan_m = items->mask;
2801 const struct rte_flow_item_vlan *vlan_v = items->spec;
2803 /* If VLAN item in pattern doesn't contain data, return here. */
2808 /* Only full match values are accepted */
2809 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
2810 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
2811 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
2813 rte_be_to_cpu_16(vlan_v->tci &
2814 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
2816 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
2817 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
2818 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
2820 rte_be_to_cpu_16(vlan_v->tci &
2821 MLX5DV_FLOW_VLAN_VID_MASK_BE);
2823 if (vlan_m->inner_type == nic_mask.inner_type)
2824 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
2825 vlan_m->inner_type);
2830 * Validate the push VLAN action.
2833 * Pointer to the rte_eth_dev structure.
2834 * @param[in] action_flags
2835 * Holds the actions detected until now.
2836 * @param[in] item_flags
2837 * The items found in this flow rule.
2839 * Pointer to the action structure.
2841 * Pointer to flow attributes
2843 * Pointer to error structure.
2846 * 0 on success, a negative errno value otherwise and rte_errno is set.
2849 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
2850 uint64_t action_flags,
2851 const struct rte_flow_item_vlan *vlan_m,
2852 const struct rte_flow_action *action,
2853 const struct rte_flow_attr *attr,
2854 struct rte_flow_error *error)
2856 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
2857 const struct mlx5_priv *priv = dev->data->dev_private;
2859 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
2860 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
2861 return rte_flow_error_set(error, EINVAL,
2862 RTE_FLOW_ERROR_TYPE_ACTION, action,
2863 "invalid vlan ethertype");
2864 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2865 return rte_flow_error_set(error, EINVAL,
2866 RTE_FLOW_ERROR_TYPE_ACTION, action,
2867 "wrong action order, port_id should "
2868 "be after push VLAN");
2869 if (!attr->transfer && priv->representor)
2870 return rte_flow_error_set(error, ENOTSUP,
2871 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2872 "push vlan action for VF representor "
2873 "not supported on NIC table");
2875 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
2876 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
2877 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
2878 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
2879 !(mlx5_flow_find_action
2880 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
2881 return rte_flow_error_set(error, EINVAL,
2882 RTE_FLOW_ERROR_TYPE_ACTION, action,
2883 "not full match mask on VLAN PCP and "
2884 "there is no of_set_vlan_pcp action, "
2885 "push VLAN action cannot figure out "
2888 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
2889 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
2890 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
2891 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
2892 !(mlx5_flow_find_action
2893 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
2894 return rte_flow_error_set(error, EINVAL,
2895 RTE_FLOW_ERROR_TYPE_ACTION, action,
2896 "not full match mask on VLAN VID and "
2897 "there is no of_set_vlan_vid action, "
2898 "push VLAN action cannot figure out "
2905 * Validate the set VLAN PCP.
2907 * @param[in] action_flags
2908 * Holds the actions detected until now.
2909 * @param[in] actions
2910 * Pointer to the list of actions remaining in the flow rule.
2912 * Pointer to error structure.
2915 * 0 on success, a negative errno value otherwise and rte_errno is set.
2918 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2919 const struct rte_flow_action actions[],
2920 struct rte_flow_error *error)
2922 const struct rte_flow_action *action = actions;
2923 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2925 if (conf->vlan_pcp > 7)
2926 return rte_flow_error_set(error, EINVAL,
2927 RTE_FLOW_ERROR_TYPE_ACTION, action,
2928 "VLAN PCP value is too big");
2929 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2930 return rte_flow_error_set(error, ENOTSUP,
2931 RTE_FLOW_ERROR_TYPE_ACTION, action,
2932 "set VLAN PCP action must follow "
2933 "the push VLAN action");
2934 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2935 return rte_flow_error_set(error, ENOTSUP,
2936 RTE_FLOW_ERROR_TYPE_ACTION, action,
2937 "Multiple VLAN PCP modification are "
2939 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2940 return rte_flow_error_set(error, EINVAL,
2941 RTE_FLOW_ERROR_TYPE_ACTION, action,
2942 "wrong action order, port_id should "
2943 "be after set VLAN PCP");
2948 * Validate the set VLAN VID.
2950 * @param[in] item_flags
2951 * Holds the items detected in this rule.
2952 * @param[in] action_flags
2953 * Holds the actions detected until now.
2954 * @param[in] actions
2955 * Pointer to the list of actions remaining in the flow rule.
2957 * Pointer to error structure.
2960 * 0 on success, a negative errno value otherwise and rte_errno is set.
2963 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2964 uint64_t action_flags,
2965 const struct rte_flow_action actions[],
2966 struct rte_flow_error *error)
2968 const struct rte_flow_action *action = actions;
2969 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
2971 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
2972 return rte_flow_error_set(error, EINVAL,
2973 RTE_FLOW_ERROR_TYPE_ACTION, action,
2974 "VLAN VID value is too big");
2975 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
2976 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2977 return rte_flow_error_set(error, ENOTSUP,
2978 RTE_FLOW_ERROR_TYPE_ACTION, action,
2979 "set VLAN VID action must follow push"
2980 " VLAN action or match on VLAN item");
2981 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
2982 return rte_flow_error_set(error, ENOTSUP,
2983 RTE_FLOW_ERROR_TYPE_ACTION, action,
2984 "Multiple VLAN VID modifications are "
2986 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2987 return rte_flow_error_set(error, EINVAL,
2988 RTE_FLOW_ERROR_TYPE_ACTION, action,
2989 "wrong action order, port_id should "
2990 "be after set VLAN VID");
2995 * Validate the FLAG action.
2998 * Pointer to the rte_eth_dev structure.
2999 * @param[in] action_flags
3000 * Holds the actions detected until now.
3002 * Pointer to flow attributes
3004 * Pointer to error structure.
3007 * 0 on success, a negative errno value otherwise and rte_errno is set.
3010 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3011 uint64_t action_flags,
3012 const struct rte_flow_attr *attr,
3013 struct rte_flow_error *error)
3015 struct mlx5_priv *priv = dev->data->dev_private;
3016 struct mlx5_dev_config *config = &priv->config;
3019 /* Fall back if no extended metadata register support. */
3020 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3021 return mlx5_flow_validate_action_flag(action_flags, attr,
3023 /* Extensive metadata mode requires registers. */
3024 if (!mlx5_flow_ext_mreg_supported(dev))
3025 return rte_flow_error_set(error, ENOTSUP,
3026 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3027 "no metadata registers "
3028 "to support flag action");
3029 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3030 return rte_flow_error_set(error, ENOTSUP,
3031 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3032 "extended metadata register"
3033 " isn't available");
3034 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3037 MLX5_ASSERT(ret > 0);
3038 if (action_flags & MLX5_FLOW_ACTION_MARK)
3039 return rte_flow_error_set(error, EINVAL,
3040 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3041 "can't mark and flag in same flow");
3042 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3043 return rte_flow_error_set(error, EINVAL,
3044 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3046 " actions in same flow");
3051 * Validate MARK action.
3054 * Pointer to the rte_eth_dev structure.
3056 * Pointer to action.
3057 * @param[in] action_flags
3058 * Holds the actions detected until now.
3060 * Pointer to flow attributes
3062 * Pointer to error structure.
3065 * 0 on success, a negative errno value otherwise and rte_errno is set.
3068 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3069 const struct rte_flow_action *action,
3070 uint64_t action_flags,
3071 const struct rte_flow_attr *attr,
3072 struct rte_flow_error *error)
3074 struct mlx5_priv *priv = dev->data->dev_private;
3075 struct mlx5_dev_config *config = &priv->config;
3076 const struct rte_flow_action_mark *mark = action->conf;
3079 if (is_tunnel_offload_active(dev))
3080 return rte_flow_error_set(error, ENOTSUP,
3081 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3083 "if tunnel offload active");
3084 /* Fall back if no extended metadata register support. */
3085 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3086 return mlx5_flow_validate_action_mark(action, action_flags,
3088 /* Extensive metadata mode requires registers. */
3089 if (!mlx5_flow_ext_mreg_supported(dev))
3090 return rte_flow_error_set(error, ENOTSUP,
3091 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3092 "no metadata registers "
3093 "to support mark action");
3094 if (!priv->sh->dv_mark_mask)
3095 return rte_flow_error_set(error, ENOTSUP,
3096 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3097 "extended metadata register"
3098 " isn't available");
3099 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3102 MLX5_ASSERT(ret > 0);
3104 return rte_flow_error_set(error, EINVAL,
3105 RTE_FLOW_ERROR_TYPE_ACTION, action,
3106 "configuration cannot be null");
3107 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3108 return rte_flow_error_set(error, EINVAL,
3109 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3111 "mark id exceeds the limit");
3112 if (action_flags & MLX5_FLOW_ACTION_FLAG)
3113 return rte_flow_error_set(error, EINVAL,
3114 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3115 "can't flag and mark in same flow");
3116 if (action_flags & MLX5_FLOW_ACTION_MARK)
3117 return rte_flow_error_set(error, EINVAL,
3118 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3119 "can't have 2 mark actions in same"
3125 * Validate SET_META action.
3128 * Pointer to the rte_eth_dev structure.
3130 * Pointer to the action structure.
3131 * @param[in] action_flags
3132 * Holds the actions detected until now.
3134 * Pointer to flow attributes
3136 * Pointer to error structure.
3139 * 0 on success, a negative errno value otherwise and rte_errno is set.
3142 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3143 const struct rte_flow_action *action,
3144 uint64_t action_flags __rte_unused,
3145 const struct rte_flow_attr *attr,
3146 struct rte_flow_error *error)
3148 const struct rte_flow_action_set_meta *conf;
3149 uint32_t nic_mask = UINT32_MAX;
3152 if (!mlx5_flow_ext_mreg_supported(dev))
3153 return rte_flow_error_set(error, ENOTSUP,
3154 RTE_FLOW_ERROR_TYPE_ACTION, action,
3155 "extended metadata register"
3156 " isn't supported");
3157 reg = flow_dv_get_metadata_reg(dev, attr, error);
3161 return rte_flow_error_set(error, ENOTSUP,
3162 RTE_FLOW_ERROR_TYPE_ACTION, action,
3163 "unavalable extended metadata register");
3164 if (reg != REG_A && reg != REG_B) {
3165 struct mlx5_priv *priv = dev->data->dev_private;
3167 nic_mask = priv->sh->dv_meta_mask;
3169 if (!(action->conf))
3170 return rte_flow_error_set(error, EINVAL,
3171 RTE_FLOW_ERROR_TYPE_ACTION, action,
3172 "configuration cannot be null");
3173 conf = (const struct rte_flow_action_set_meta *)action->conf;
3175 return rte_flow_error_set(error, EINVAL,
3176 RTE_FLOW_ERROR_TYPE_ACTION, action,
3177 "zero mask doesn't have any effect");
3178 if (conf->mask & ~nic_mask)
3179 return rte_flow_error_set(error, EINVAL,
3180 RTE_FLOW_ERROR_TYPE_ACTION, action,
3181 "meta data must be within reg C0");
3186 * Validate SET_TAG action.
3189 * Pointer to the rte_eth_dev structure.
3191 * Pointer to the action structure.
3192 * @param[in] action_flags
3193 * Holds the actions detected until now.
3195 * Pointer to flow attributes
3197 * Pointer to error structure.
3200 * 0 on success, a negative errno value otherwise and rte_errno is set.
3203 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3204 const struct rte_flow_action *action,
3205 uint64_t action_flags,
3206 const struct rte_flow_attr *attr,
3207 struct rte_flow_error *error)
3209 const struct rte_flow_action_set_tag *conf;
3210 const uint64_t terminal_action_flags =
3211 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3212 MLX5_FLOW_ACTION_RSS;
3215 if (!mlx5_flow_ext_mreg_supported(dev))
3216 return rte_flow_error_set(error, ENOTSUP,
3217 RTE_FLOW_ERROR_TYPE_ACTION, action,
3218 "extensive metadata register"
3219 " isn't supported");
3220 if (!(action->conf))
3221 return rte_flow_error_set(error, EINVAL,
3222 RTE_FLOW_ERROR_TYPE_ACTION, action,
3223 "configuration cannot be null");
3224 conf = (const struct rte_flow_action_set_tag *)action->conf;
3226 return rte_flow_error_set(error, EINVAL,
3227 RTE_FLOW_ERROR_TYPE_ACTION, action,
3228 "zero mask doesn't have any effect");
3229 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3232 if (!attr->transfer && attr->ingress &&
3233 (action_flags & terminal_action_flags))
3234 return rte_flow_error_set(error, EINVAL,
3235 RTE_FLOW_ERROR_TYPE_ACTION, action,
3236 "set_tag has no effect"
3237 " with terminal actions");
3242 * Check if action counter is shared by either old or new mechanism.
3245 * Pointer to the action structure.
3248 * True when counter is shared, false otherwise.
3251 is_shared_action_count(const struct rte_flow_action *action)
3253 const struct rte_flow_action_count *count =
3254 (const struct rte_flow_action_count *)action->conf;
3256 if ((int)action->type == MLX5_RTE_FLOW_ACTION_TYPE_COUNT)
3258 return !!(count && count->shared);
3262 * Validate count action.
3265 * Pointer to rte_eth_dev structure.
3267 * Indicator if action is shared.
3268 * @param[in] action_flags
3269 * Holds the actions detected until now.
3271 * Pointer to error structure.
3274 * 0 on success, a negative errno value otherwise and rte_errno is set.
3277 flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3278 uint64_t action_flags,
3279 struct rte_flow_error *error)
3281 struct mlx5_priv *priv = dev->data->dev_private;
3283 if (!priv->config.devx)
3285 if (action_flags & MLX5_FLOW_ACTION_COUNT)
3286 return rte_flow_error_set(error, EINVAL,
3287 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3288 "duplicate count actions set");
3289 if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
3290 !priv->sh->flow_hit_aso_en)
3291 return rte_flow_error_set(error, EINVAL,
3292 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3293 "old age and shared count combination is not supported");
3294 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3298 return rte_flow_error_set
3300 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3302 "count action not supported");
3306 * Validate the L2 encap action.
3309 * Pointer to the rte_eth_dev structure.
3310 * @param[in] action_flags
3311 * Holds the actions detected until now.
3313 * Pointer to the action structure.
3315 * Pointer to flow attributes.
3317 * Pointer to error structure.
3320 * 0 on success, a negative errno value otherwise and rte_errno is set.
3323 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3324 uint64_t action_flags,
3325 const struct rte_flow_action *action,
3326 const struct rte_flow_attr *attr,
3327 struct rte_flow_error *error)
3329 const struct mlx5_priv *priv = dev->data->dev_private;
3331 if (!(action->conf))
3332 return rte_flow_error_set(error, EINVAL,
3333 RTE_FLOW_ERROR_TYPE_ACTION, action,
3334 "configuration cannot be null");
3335 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3336 return rte_flow_error_set(error, EINVAL,
3337 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3338 "can only have a single encap action "
3340 if (!attr->transfer && priv->representor)
3341 return rte_flow_error_set(error, ENOTSUP,
3342 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3343 "encap action for VF representor "
3344 "not supported on NIC table");
3349 * Validate a decap action.
3352 * Pointer to the rte_eth_dev structure.
3353 * @param[in] action_flags
3354 * Holds the actions detected until now.
3356 * Pointer to the action structure.
3357 * @param[in] item_flags
3358 * Holds the items detected.
3360 * Pointer to flow attributes
3362 * Pointer to error structure.
3365 * 0 on success, a negative errno value otherwise and rte_errno is set.
3368 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3369 uint64_t action_flags,
3370 const struct rte_flow_action *action,
3371 const uint64_t item_flags,
3372 const struct rte_flow_attr *attr,
3373 struct rte_flow_error *error)
3375 const struct mlx5_priv *priv = dev->data->dev_private;
3377 if (priv->config.hca_attr.scatter_fcs_w_decap_disable &&
3378 !priv->config.decap_en)
3379 return rte_flow_error_set(error, ENOTSUP,
3380 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3381 "decap is not enabled");
3382 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3383 return rte_flow_error_set(error, ENOTSUP,
3384 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3386 MLX5_FLOW_ACTION_DECAP ? "can only "
3387 "have a single decap action" : "decap "
3388 "after encap is not supported");
3389 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3390 return rte_flow_error_set(error, EINVAL,
3391 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3392 "can't have decap action after"
3395 return rte_flow_error_set(error, ENOTSUP,
3396 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3398 "decap action not supported for "
3400 if (!attr->transfer && priv->representor)
3401 return rte_flow_error_set(error, ENOTSUP,
3402 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3403 "decap action for VF representor "
3404 "not supported on NIC table");
3405 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
3406 !(item_flags & MLX5_FLOW_LAYER_VXLAN))
3407 return rte_flow_error_set(error, ENOTSUP,
3408 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3409 "VXLAN item should be present for VXLAN decap");
3413 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
3416 * Validate the raw encap and decap actions.
3419 * Pointer to the rte_eth_dev structure.
3421 * Pointer to the decap action.
3423 * Pointer to the encap action.
3425 * Pointer to flow attributes
3426 * @param[in/out] action_flags
3427 * Holds the actions detected until now.
3428 * @param[out] actions_n
3429 * pointer to the number of actions counter.
3431 * Pointer to the action structure.
3432 * @param[in] item_flags
3433 * Holds the items detected.
3435 * Pointer to error structure.
3438 * 0 on success, a negative errno value otherwise and rte_errno is set.
3441 flow_dv_validate_action_raw_encap_decap
3442 (struct rte_eth_dev *dev,
3443 const struct rte_flow_action_raw_decap *decap,
3444 const struct rte_flow_action_raw_encap *encap,
3445 const struct rte_flow_attr *attr, uint64_t *action_flags,
3446 int *actions_n, const struct rte_flow_action *action,
3447 uint64_t item_flags, struct rte_flow_error *error)
3449 const struct mlx5_priv *priv = dev->data->dev_private;
3452 if (encap && (!encap->size || !encap->data))
3453 return rte_flow_error_set(error, EINVAL,
3454 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3455 "raw encap data cannot be empty");
3456 if (decap && encap) {
3457 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
3458 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
3461 else if (encap->size <=
3462 MLX5_ENCAPSULATION_DECISION_SIZE &&
3464 MLX5_ENCAPSULATION_DECISION_SIZE)
3467 else if (encap->size >
3468 MLX5_ENCAPSULATION_DECISION_SIZE &&
3470 MLX5_ENCAPSULATION_DECISION_SIZE)
3471 /* 2 L2 actions: encap and decap. */
3474 return rte_flow_error_set(error,
3476 RTE_FLOW_ERROR_TYPE_ACTION,
3477 NULL, "unsupported too small "
3478 "raw decap and too small raw "
3479 "encap combination");
3482 ret = flow_dv_validate_action_decap(dev, *action_flags, action,
3483 item_flags, attr, error);
3486 *action_flags |= MLX5_FLOW_ACTION_DECAP;
3490 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
3491 return rte_flow_error_set(error, ENOTSUP,
3492 RTE_FLOW_ERROR_TYPE_ACTION,
3494 "small raw encap size");
3495 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
3496 return rte_flow_error_set(error, EINVAL,
3497 RTE_FLOW_ERROR_TYPE_ACTION,
3499 "more than one encap action");
3500 if (!attr->transfer && priv->representor)
3501 return rte_flow_error_set
3503 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3504 "encap action for VF representor "
3505 "not supported on NIC table");
3506 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
3513 * Validate the ASO CT action.
3516 * Pointer to the rte_eth_dev structure.
3517 * @param[in] action_flags
3518 * Holds the actions detected until now.
3519 * @param[in] item_flags
3520 * The items found in this flow rule.
3522 * Pointer to flow attributes.
3524 * Pointer to error structure.
3527 * 0 on success, a negative errno value otherwise and rte_errno is set.
3530 flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
3531 uint64_t action_flags,
3532 uint64_t item_flags,
3533 const struct rte_flow_attr *attr,
3534 struct rte_flow_error *error)
3538 if (attr->group == 0 && !attr->transfer)
3539 return rte_flow_error_set(error, ENOTSUP,
3540 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3542 "Only support non-root table");
3543 if (action_flags & MLX5_FLOW_FATE_ACTIONS)
3544 return rte_flow_error_set(error, ENOTSUP,
3545 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3546 "CT cannot follow a fate action");
3547 if ((action_flags & MLX5_FLOW_ACTION_METER) ||
3548 (action_flags & MLX5_FLOW_ACTION_AGE))
3549 return rte_flow_error_set(error, EINVAL,
3550 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3551 "Only one ASO action is supported");
3552 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3553 return rte_flow_error_set(error, EINVAL,
3554 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3555 "Encap cannot exist before CT");
3556 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
3557 return rte_flow_error_set(error, EINVAL,
3558 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3559 "Not a outer TCP packet");
3564 * Match encap_decap resource.
3567 * Pointer to the hash list.
3569 * Pointer to exist resource entry object.
3571 * Key of the new entry.
3573 * Pointer to new encap_decap resource.
3576 * 0 on matching, none-zero otherwise.
3579 flow_dv_encap_decap_match_cb(struct mlx5_hlist *list __rte_unused,
3580 struct mlx5_hlist_entry *entry,
3581 uint64_t key __rte_unused, void *cb_ctx)
3583 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3584 struct mlx5_flow_dv_encap_decap_resource *resource = ctx->data;
3585 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3587 cache_resource = container_of(entry,
3588 struct mlx5_flow_dv_encap_decap_resource,
3590 if (resource->reformat_type == cache_resource->reformat_type &&
3591 resource->ft_type == cache_resource->ft_type &&
3592 resource->flags == cache_resource->flags &&
3593 resource->size == cache_resource->size &&
3594 !memcmp((const void *)resource->buf,
3595 (const void *)cache_resource->buf,
3602 * Allocate encap_decap resource.
3605 * Pointer to the hash list.
3607 * Pointer to exist resource entry object.
3609 * Pointer to new encap_decap resource.
3612 * 0 on matching, none-zero otherwise.
3614 struct mlx5_hlist_entry *
3615 flow_dv_encap_decap_create_cb(struct mlx5_hlist *list,
3616 uint64_t key __rte_unused,
3619 struct mlx5_dev_ctx_shared *sh = list->ctx;
3620 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3621 struct mlx5dv_dr_domain *domain;
3622 struct mlx5_flow_dv_encap_decap_resource *resource = ctx->data;
3623 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
3627 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3628 domain = sh->fdb_domain;
3629 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3630 domain = sh->rx_domain;
3632 domain = sh->tx_domain;
3633 /* Register new encap/decap resource. */
3634 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
3636 if (!cache_resource) {
3637 rte_flow_error_set(ctx->error, ENOMEM,
3638 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3639 "cannot allocate resource memory");
3642 *cache_resource = *resource;
3643 cache_resource->idx = idx;
3644 ret = mlx5_flow_os_create_flow_action_packet_reformat
3645 (sh->ctx, domain, cache_resource,
3646 &cache_resource->action);
3648 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
3649 rte_flow_error_set(ctx->error, ENOMEM,
3650 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3651 NULL, "cannot create action");
3655 return &cache_resource->entry;
3659 * Find existing encap/decap resource or create and register a new one.
3661 * @param[in, out] dev
3662 * Pointer to rte_eth_dev structure.
3663 * @param[in, out] resource
3664 * Pointer to encap/decap resource.
3665 * @parm[in, out] dev_flow
3666 * Pointer to the dev_flow.
3668 * pointer to error structure.
3671 * 0 on success otherwise -errno and errno is set.
3674 flow_dv_encap_decap_resource_register
3675 (struct rte_eth_dev *dev,
3676 struct mlx5_flow_dv_encap_decap_resource *resource,
3677 struct mlx5_flow *dev_flow,
3678 struct rte_flow_error *error)
3680 struct mlx5_priv *priv = dev->data->dev_private;
3681 struct mlx5_dev_ctx_shared *sh = priv->sh;
3682 struct mlx5_hlist_entry *entry;
3686 uint32_t refmt_type:8;
3688 * Header reformat actions can be shared between
3689 * non-root tables. One bit to indicate non-root
3693 uint32_t reserve:15;
3696 } encap_decap_key = {
3698 .ft_type = resource->ft_type,
3699 .refmt_type = resource->reformat_type,
3700 .is_root = !!dev_flow->dv.group,
3704 struct mlx5_flow_cb_ctx ctx = {
3710 resource->flags = dev_flow->dv.group ? 0 : 1;
3711 key64 = __rte_raw_cksum(&encap_decap_key.v32,
3712 sizeof(encap_decap_key.v32), 0);
3713 if (resource->reformat_type !=
3714 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
3716 key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
3717 entry = mlx5_hlist_register(sh->encaps_decaps, key64, &ctx);
3720 resource = container_of(entry, typeof(*resource), entry);
3721 dev_flow->dv.encap_decap = resource;
3722 dev_flow->handle->dvh.rix_encap_decap = resource->idx;
3727 * Find existing table jump resource or create and register a new one.
3729 * @param[in, out] dev
3730 * Pointer to rte_eth_dev structure.
3731 * @param[in, out] tbl
3732 * Pointer to flow table resource.
3733 * @parm[in, out] dev_flow
3734 * Pointer to the dev_flow.
3736 * pointer to error structure.
3739 * 0 on success otherwise -errno and errno is set.
3742 flow_dv_jump_tbl_resource_register
3743 (struct rte_eth_dev *dev __rte_unused,
3744 struct mlx5_flow_tbl_resource *tbl,
3745 struct mlx5_flow *dev_flow,
3746 struct rte_flow_error *error __rte_unused)
3748 struct mlx5_flow_tbl_data_entry *tbl_data =
3749 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
3752 MLX5_ASSERT(tbl_data->jump.action);
3753 dev_flow->handle->rix_jump = tbl_data->idx;
3754 dev_flow->dv.jump = &tbl_data->jump;
3759 flow_dv_port_id_match_cb(struct mlx5_cache_list *list __rte_unused,
3760 struct mlx5_cache_entry *entry, void *cb_ctx)
3762 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3763 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3764 struct mlx5_flow_dv_port_id_action_resource *res =
3765 container_of(entry, typeof(*res), entry);
3767 return ref->port_id != res->port_id;
3770 struct mlx5_cache_entry *
3771 flow_dv_port_id_create_cb(struct mlx5_cache_list *list,
3772 struct mlx5_cache_entry *entry __rte_unused,
3775 struct mlx5_dev_ctx_shared *sh = list->ctx;
3776 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3777 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3778 struct mlx5_flow_dv_port_id_action_resource *cache;
3782 /* Register new port id action resource. */
3783 cache = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3785 rte_flow_error_set(ctx->error, ENOMEM,
3786 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3787 "cannot allocate port_id action cache memory");
3791 ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
3795 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
3796 rte_flow_error_set(ctx->error, ENOMEM,
3797 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3798 "cannot create action");
3802 return &cache->entry;
3806 * Find existing table port ID resource or create and register a new one.
3808 * @param[in, out] dev
3809 * Pointer to rte_eth_dev structure.
3810 * @param[in, out] resource
3811 * Pointer to port ID action resource.
3812 * @parm[in, out] dev_flow
3813 * Pointer to the dev_flow.
3815 * pointer to error structure.
3818 * 0 on success otherwise -errno and errno is set.
3821 flow_dv_port_id_action_resource_register
3822 (struct rte_eth_dev *dev,
3823 struct mlx5_flow_dv_port_id_action_resource *resource,
3824 struct mlx5_flow *dev_flow,
3825 struct rte_flow_error *error)
3827 struct mlx5_priv *priv = dev->data->dev_private;
3828 struct mlx5_cache_entry *entry;
3829 struct mlx5_flow_dv_port_id_action_resource *cache;
3830 struct mlx5_flow_cb_ctx ctx = {
3835 entry = mlx5_cache_register(&priv->sh->port_id_action_list, &ctx);
3838 cache = container_of(entry, typeof(*cache), entry);
3839 dev_flow->dv.port_id_action = cache;
3840 dev_flow->handle->rix_port_id_action = cache->idx;
3845 flow_dv_push_vlan_match_cb(struct mlx5_cache_list *list __rte_unused,
3846 struct mlx5_cache_entry *entry, void *cb_ctx)
3848 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3849 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3850 struct mlx5_flow_dv_push_vlan_action_resource *res =
3851 container_of(entry, typeof(*res), entry);
3853 return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
3856 struct mlx5_cache_entry *
3857 flow_dv_push_vlan_create_cb(struct mlx5_cache_list *list,
3858 struct mlx5_cache_entry *entry __rte_unused,
3861 struct mlx5_dev_ctx_shared *sh = list->ctx;
3862 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3863 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3864 struct mlx5_flow_dv_push_vlan_action_resource *cache;
3865 struct mlx5dv_dr_domain *domain;
3869 /* Register new port id action resource. */
3870 cache = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3872 rte_flow_error_set(ctx->error, ENOMEM,
3873 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3874 "cannot allocate push_vlan action cache memory");
3878 if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3879 domain = sh->fdb_domain;
3880 else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3881 domain = sh->rx_domain;
3883 domain = sh->tx_domain;
3884 ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
3887 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
3888 rte_flow_error_set(ctx->error, ENOMEM,
3889 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3890 "cannot create push vlan action");
3894 return &cache->entry;
3898 * Find existing push vlan resource or create and register a new one.
3900 * @param [in, out] dev
3901 * Pointer to rte_eth_dev structure.
3902 * @param[in, out] resource
3903 * Pointer to port ID action resource.
3904 * @parm[in, out] dev_flow
3905 * Pointer to the dev_flow.
3907 * pointer to error structure.
3910 * 0 on success otherwise -errno and errno is set.
3913 flow_dv_push_vlan_action_resource_register
3914 (struct rte_eth_dev *dev,
3915 struct mlx5_flow_dv_push_vlan_action_resource *resource,
3916 struct mlx5_flow *dev_flow,
3917 struct rte_flow_error *error)
3919 struct mlx5_priv *priv = dev->data->dev_private;
3920 struct mlx5_flow_dv_push_vlan_action_resource *cache;
3921 struct mlx5_cache_entry *entry;
3922 struct mlx5_flow_cb_ctx ctx = {
3927 entry = mlx5_cache_register(&priv->sh->push_vlan_action_list, &ctx);
3930 cache = container_of(entry, typeof(*cache), entry);
3932 dev_flow->handle->dvh.rix_push_vlan = cache->idx;
3933 dev_flow->dv.push_vlan_res = cache;
3938 * Get the size of specific rte_flow_item_type hdr size
3940 * @param[in] item_type
3941 * Tested rte_flow_item_type.
3944 * sizeof struct item_type, 0 if void or irrelevant.
3947 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
3951 switch (item_type) {
3952 case RTE_FLOW_ITEM_TYPE_ETH:
3953 retval = sizeof(struct rte_ether_hdr);
3955 case RTE_FLOW_ITEM_TYPE_VLAN:
3956 retval = sizeof(struct rte_vlan_hdr);
3958 case RTE_FLOW_ITEM_TYPE_IPV4:
3959 retval = sizeof(struct rte_ipv4_hdr);
3961 case RTE_FLOW_ITEM_TYPE_IPV6:
3962 retval = sizeof(struct rte_ipv6_hdr);
3964 case RTE_FLOW_ITEM_TYPE_UDP:
3965 retval = sizeof(struct rte_udp_hdr);
3967 case RTE_FLOW_ITEM_TYPE_TCP:
3968 retval = sizeof(struct rte_tcp_hdr);
3970 case RTE_FLOW_ITEM_TYPE_VXLAN:
3971 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
3972 retval = sizeof(struct rte_vxlan_hdr);
3974 case RTE_FLOW_ITEM_TYPE_GRE:
3975 case RTE_FLOW_ITEM_TYPE_NVGRE:
3976 retval = sizeof(struct rte_gre_hdr);
3978 case RTE_FLOW_ITEM_TYPE_MPLS:
3979 retval = sizeof(struct rte_mpls_hdr);
3981 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
3989 #define MLX5_ENCAP_IPV4_VERSION 0x40
3990 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
3991 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
3992 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
3993 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
3994 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
3995 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
3998 * Convert the encap action data from list of rte_flow_item to raw buffer
4001 * Pointer to rte_flow_item objects list.
4003 * Pointer to the output buffer.
4005 * Pointer to the output buffer size.
4007 * Pointer to the error structure.
4010 * 0 on success, a negative errno value otherwise and rte_errno is set.
4013 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4014 size_t *size, struct rte_flow_error *error)
4016 struct rte_ether_hdr *eth = NULL;
4017 struct rte_vlan_hdr *vlan = NULL;
4018 struct rte_ipv4_hdr *ipv4 = NULL;
4019 struct rte_ipv6_hdr *ipv6 = NULL;
4020 struct rte_udp_hdr *udp = NULL;
4021 struct rte_vxlan_hdr *vxlan = NULL;
4022 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4023 struct rte_gre_hdr *gre = NULL;
4025 size_t temp_size = 0;
4028 return rte_flow_error_set(error, EINVAL,
4029 RTE_FLOW_ERROR_TYPE_ACTION,
4030 NULL, "invalid empty data");
4031 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4032 len = flow_dv_get_item_hdr_len(items->type);
4033 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4034 return rte_flow_error_set(error, EINVAL,
4035 RTE_FLOW_ERROR_TYPE_ACTION,
4036 (void *)items->type,
4037 "items total size is too big"
4038 " for encap action");
4039 rte_memcpy((void *)&buf[temp_size], items->spec, len);
4040 switch (items->type) {
4041 case RTE_FLOW_ITEM_TYPE_ETH:
4042 eth = (struct rte_ether_hdr *)&buf[temp_size];
4044 case RTE_FLOW_ITEM_TYPE_VLAN:
4045 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4047 return rte_flow_error_set(error, EINVAL,
4048 RTE_FLOW_ERROR_TYPE_ACTION,
4049 (void *)items->type,
4050 "eth header not found");
4051 if (!eth->ether_type)
4052 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4054 case RTE_FLOW_ITEM_TYPE_IPV4:
4055 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4057 return rte_flow_error_set(error, EINVAL,
4058 RTE_FLOW_ERROR_TYPE_ACTION,
4059 (void *)items->type,
4060 "neither eth nor vlan"
4062 if (vlan && !vlan->eth_proto)
4063 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4064 else if (eth && !eth->ether_type)
4065 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4066 if (!ipv4->version_ihl)
4067 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4068 MLX5_ENCAP_IPV4_IHL_MIN;
4069 if (!ipv4->time_to_live)
4070 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4072 case RTE_FLOW_ITEM_TYPE_IPV6:
4073 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4075 return rte_flow_error_set(error, EINVAL,
4076 RTE_FLOW_ERROR_TYPE_ACTION,
4077 (void *)items->type,
4078 "neither eth nor vlan"
4080 if (vlan && !vlan->eth_proto)
4081 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4082 else if (eth && !eth->ether_type)
4083 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4084 if (!ipv6->vtc_flow)
4086 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4087 if (!ipv6->hop_limits)
4088 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4090 case RTE_FLOW_ITEM_TYPE_UDP:
4091 udp = (struct rte_udp_hdr *)&buf[temp_size];
4093 return rte_flow_error_set(error, EINVAL,
4094 RTE_FLOW_ERROR_TYPE_ACTION,
4095 (void *)items->type,
4096 "ip header not found");
4097 if (ipv4 && !ipv4->next_proto_id)
4098 ipv4->next_proto_id = IPPROTO_UDP;
4099 else if (ipv6 && !ipv6->proto)
4100 ipv6->proto = IPPROTO_UDP;
4102 case RTE_FLOW_ITEM_TYPE_VXLAN:
4103 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4105 return rte_flow_error_set(error, EINVAL,
4106 RTE_FLOW_ERROR_TYPE_ACTION,
4107 (void *)items->type,
4108 "udp header not found");
4110 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4111 if (!vxlan->vx_flags)
4113 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4115 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4116 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4118 return rte_flow_error_set(error, EINVAL,
4119 RTE_FLOW_ERROR_TYPE_ACTION,
4120 (void *)items->type,
4121 "udp header not found");
4122 if (!vxlan_gpe->proto)
4123 return rte_flow_error_set(error, EINVAL,
4124 RTE_FLOW_ERROR_TYPE_ACTION,
4125 (void *)items->type,
4126 "next protocol not found");
4129 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4130 if (!vxlan_gpe->vx_flags)
4131 vxlan_gpe->vx_flags =
4132 MLX5_ENCAP_VXLAN_GPE_FLAGS;
4134 case RTE_FLOW_ITEM_TYPE_GRE:
4135 case RTE_FLOW_ITEM_TYPE_NVGRE:
4136 gre = (struct rte_gre_hdr *)&buf[temp_size];
4138 return rte_flow_error_set(error, EINVAL,
4139 RTE_FLOW_ERROR_TYPE_ACTION,
4140 (void *)items->type,
4141 "next protocol not found");
4143 return rte_flow_error_set(error, EINVAL,
4144 RTE_FLOW_ERROR_TYPE_ACTION,
4145 (void *)items->type,
4146 "ip header not found");
4147 if (ipv4 && !ipv4->next_proto_id)
4148 ipv4->next_proto_id = IPPROTO_GRE;
4149 else if (ipv6 && !ipv6->proto)
4150 ipv6->proto = IPPROTO_GRE;
4152 case RTE_FLOW_ITEM_TYPE_VOID:
4155 return rte_flow_error_set(error, EINVAL,
4156 RTE_FLOW_ERROR_TYPE_ACTION,
4157 (void *)items->type,
4158 "unsupported item type");
4168 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
4170 struct rte_ether_hdr *eth = NULL;
4171 struct rte_vlan_hdr *vlan = NULL;
4172 struct rte_ipv6_hdr *ipv6 = NULL;
4173 struct rte_udp_hdr *udp = NULL;
4177 eth = (struct rte_ether_hdr *)data;
4178 next_hdr = (char *)(eth + 1);
4179 proto = RTE_BE16(eth->ether_type);
4182 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
4183 vlan = (struct rte_vlan_hdr *)next_hdr;
4184 proto = RTE_BE16(vlan->eth_proto);
4185 next_hdr += sizeof(struct rte_vlan_hdr);
4188 /* HW calculates IPv4 csum. no need to proceed */
4189 if (proto == RTE_ETHER_TYPE_IPV4)
4192 /* non IPv4/IPv6 header. not supported */
4193 if (proto != RTE_ETHER_TYPE_IPV6) {
4194 return rte_flow_error_set(error, ENOTSUP,
4195 RTE_FLOW_ERROR_TYPE_ACTION,
4196 NULL, "Cannot offload non IPv4/IPv6");
4199 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
4201 /* ignore non UDP */
4202 if (ipv6->proto != IPPROTO_UDP)
4205 udp = (struct rte_udp_hdr *)(ipv6 + 1);
4206 udp->dgram_cksum = 0;
4212 * Convert L2 encap action to DV specification.
4215 * Pointer to rte_eth_dev structure.
4217 * Pointer to action structure.
4218 * @param[in, out] dev_flow
4219 * Pointer to the mlx5_flow.
4220 * @param[in] transfer
4221 * Mark if the flow is E-Switch flow.
4223 * Pointer to the error structure.
4226 * 0 on success, a negative errno value otherwise and rte_errno is set.
4229 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
4230 const struct rte_flow_action *action,
4231 struct mlx5_flow *dev_flow,
4233 struct rte_flow_error *error)
4235 const struct rte_flow_item *encap_data;
4236 const struct rte_flow_action_raw_encap *raw_encap_data;
4237 struct mlx5_flow_dv_encap_decap_resource res = {
4239 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
4240 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4241 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
4244 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
4246 (const struct rte_flow_action_raw_encap *)action->conf;
4247 res.size = raw_encap_data->size;
4248 memcpy(res.buf, raw_encap_data->data, res.size);
4250 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
4252 ((const struct rte_flow_action_vxlan_encap *)
4253 action->conf)->definition;
4256 ((const struct rte_flow_action_nvgre_encap *)
4257 action->conf)->definition;
4258 if (flow_dv_convert_encap_data(encap_data, res.buf,
4262 if (flow_dv_zero_encap_udp_csum(res.buf, error))
4264 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4265 return rte_flow_error_set(error, EINVAL,
4266 RTE_FLOW_ERROR_TYPE_ACTION,
4267 NULL, "can't create L2 encap action");
4272 * Convert L2 decap action to DV specification.
4275 * Pointer to rte_eth_dev structure.
4276 * @param[in, out] dev_flow
4277 * Pointer to the mlx5_flow.
4278 * @param[in] transfer
4279 * Mark if the flow is E-Switch flow.
4281 * Pointer to the error structure.
4284 * 0 on success, a negative errno value otherwise and rte_errno is set.
4287 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
4288 struct mlx5_flow *dev_flow,
4290 struct rte_flow_error *error)
4292 struct mlx5_flow_dv_encap_decap_resource res = {
4295 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
4296 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
4297 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
4300 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4301 return rte_flow_error_set(error, EINVAL,
4302 RTE_FLOW_ERROR_TYPE_ACTION,
4303 NULL, "can't create L2 decap action");
4308 * Convert raw decap/encap (L3 tunnel) action to DV specification.
4311 * Pointer to rte_eth_dev structure.
4313 * Pointer to action structure.
4314 * @param[in, out] dev_flow
4315 * Pointer to the mlx5_flow.
4317 * Pointer to the flow attributes.
4319 * Pointer to the error structure.
4322 * 0 on success, a negative errno value otherwise and rte_errno is set.
4325 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
4326 const struct rte_flow_action *action,
4327 struct mlx5_flow *dev_flow,
4328 const struct rte_flow_attr *attr,
4329 struct rte_flow_error *error)
4331 const struct rte_flow_action_raw_encap *encap_data;
4332 struct mlx5_flow_dv_encap_decap_resource res;
4334 memset(&res, 0, sizeof(res));
4335 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
4336 res.size = encap_data->size;
4337 memcpy(res.buf, encap_data->data, res.size);
4338 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
4339 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
4340 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
4342 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4344 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4345 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4346 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
4347 return rte_flow_error_set(error, EINVAL,
4348 RTE_FLOW_ERROR_TYPE_ACTION,
4349 NULL, "can't create encap action");
4354 * Create action push VLAN.
4357 * Pointer to rte_eth_dev structure.
4359 * Pointer to the flow attributes.
4361 * Pointer to the vlan to push to the Ethernet header.
4362 * @param[in, out] dev_flow
4363 * Pointer to the mlx5_flow.
4365 * Pointer to the error structure.
4368 * 0 on success, a negative errno value otherwise and rte_errno is set.
4371 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
4372 const struct rte_flow_attr *attr,
4373 const struct rte_vlan_hdr *vlan,
4374 struct mlx5_flow *dev_flow,
4375 struct rte_flow_error *error)
4377 struct mlx5_flow_dv_push_vlan_action_resource res;
4379 memset(&res, 0, sizeof(res));
4381 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
4384 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
4386 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
4387 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
4388 return flow_dv_push_vlan_action_resource_register
4389 (dev, &res, dev_flow, error);
4393 * Validate the modify-header actions.
4395 * @param[in] action_flags
4396 * Holds the actions detected until now.
4398 * Pointer to the modify action.
4400 * Pointer to error structure.
4403 * 0 on success, a negative errno value otherwise and rte_errno is set.
4406 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
4407 const struct rte_flow_action *action,
4408 struct rte_flow_error *error)
4410 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
4411 return rte_flow_error_set(error, EINVAL,
4412 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4413 NULL, "action configuration not set");
4414 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4415 return rte_flow_error_set(error, EINVAL,
4416 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4417 "can't have encap action before"
4423 * Validate the modify-header MAC address actions.
4425 * @param[in] action_flags
4426 * Holds the actions detected until now.
4428 * Pointer to the modify action.
4429 * @param[in] item_flags
4430 * Holds the items detected.
4432 * Pointer to error structure.
4435 * 0 on success, a negative errno value otherwise and rte_errno is set.
4438 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
4439 const struct rte_flow_action *action,
4440 const uint64_t item_flags,
4441 struct rte_flow_error *error)
4445 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4447 if (!(item_flags & MLX5_FLOW_LAYER_L2))
4448 return rte_flow_error_set(error, EINVAL,
4449 RTE_FLOW_ERROR_TYPE_ACTION,
4451 "no L2 item in pattern");
4457 * Validate the modify-header IPv4 address actions.
4459 * @param[in] action_flags
4460 * Holds the actions detected until now.
4462 * Pointer to the modify action.
4463 * @param[in] item_flags
4464 * Holds the items detected.
4466 * Pointer to error structure.
4469 * 0 on success, a negative errno value otherwise and rte_errno is set.
4472 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
4473 const struct rte_flow_action *action,
4474 const uint64_t item_flags,
4475 struct rte_flow_error *error)
4480 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4482 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4483 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
4484 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4485 if (!(item_flags & layer))
4486 return rte_flow_error_set(error, EINVAL,
4487 RTE_FLOW_ERROR_TYPE_ACTION,
4489 "no ipv4 item in pattern");
4495 * Validate the modify-header IPv6 address actions.
4497 * @param[in] action_flags
4498 * Holds the actions detected until now.
4500 * Pointer to the modify action.
4501 * @param[in] item_flags
4502 * Holds the items detected.
4504 * Pointer to error structure.
4507 * 0 on success, a negative errno value otherwise and rte_errno is set.
4510 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
4511 const struct rte_flow_action *action,
4512 const uint64_t item_flags,
4513 struct rte_flow_error *error)
4518 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4520 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4521 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
4522 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4523 if (!(item_flags & layer))
4524 return rte_flow_error_set(error, EINVAL,
4525 RTE_FLOW_ERROR_TYPE_ACTION,
4527 "no ipv6 item in pattern");
4533 * Validate the modify-header TP actions.
4535 * @param[in] action_flags
4536 * Holds the actions detected until now.
4538 * Pointer to the modify action.
4539 * @param[in] item_flags
4540 * Holds the items detected.
4542 * Pointer to error structure.
4545 * 0 on success, a negative errno value otherwise and rte_errno is set.
4548 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
4549 const struct rte_flow_action *action,
4550 const uint64_t item_flags,
4551 struct rte_flow_error *error)
4556 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4558 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4559 MLX5_FLOW_LAYER_INNER_L4 :
4560 MLX5_FLOW_LAYER_OUTER_L4;
4561 if (!(item_flags & layer))
4562 return rte_flow_error_set(error, EINVAL,
4563 RTE_FLOW_ERROR_TYPE_ACTION,
4564 NULL, "no transport layer "
4571 * Validate the modify-header actions of increment/decrement
4572 * TCP Sequence-number.
4574 * @param[in] action_flags
4575 * Holds the actions detected until now.
4577 * Pointer to the modify action.
4578 * @param[in] item_flags
4579 * Holds the items detected.
4581 * Pointer to error structure.
4584 * 0 on success, a negative errno value otherwise and rte_errno is set.
4587 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
4588 const struct rte_flow_action *action,
4589 const uint64_t item_flags,
4590 struct rte_flow_error *error)
4595 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4597 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4598 MLX5_FLOW_LAYER_INNER_L4_TCP :
4599 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4600 if (!(item_flags & layer))
4601 return rte_flow_error_set(error, EINVAL,
4602 RTE_FLOW_ERROR_TYPE_ACTION,
4603 NULL, "no TCP item in"
4605 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
4606 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
4607 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
4608 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
4609 return rte_flow_error_set(error, EINVAL,
4610 RTE_FLOW_ERROR_TYPE_ACTION,
4612 "cannot decrease and increase"
4613 " TCP sequence number"
4614 " at the same time");
4620 * Validate the modify-header actions of increment/decrement
4621 * TCP Acknowledgment number.
4623 * @param[in] action_flags
4624 * Holds the actions detected until now.
4626 * Pointer to the modify action.
4627 * @param[in] item_flags
4628 * Holds the items detected.
4630 * Pointer to error structure.
4633 * 0 on success, a negative errno value otherwise and rte_errno is set.
4636 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
4637 const struct rte_flow_action *action,
4638 const uint64_t item_flags,
4639 struct rte_flow_error *error)
4644 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4646 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4647 MLX5_FLOW_LAYER_INNER_L4_TCP :
4648 MLX5_FLOW_LAYER_OUTER_L4_TCP;
4649 if (!(item_flags & layer))
4650 return rte_flow_error_set(error, EINVAL,
4651 RTE_FLOW_ERROR_TYPE_ACTION,
4652 NULL, "no TCP item in"
4654 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
4655 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
4656 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
4657 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
4658 return rte_flow_error_set(error, EINVAL,
4659 RTE_FLOW_ERROR_TYPE_ACTION,
4661 "cannot decrease and increase"
4662 " TCP acknowledgment number"
4663 " at the same time");
4669 * Validate the modify-header TTL actions.
4671 * @param[in] action_flags
4672 * Holds the actions detected until now.
4674 * Pointer to the modify action.
4675 * @param[in] item_flags
4676 * Holds the items detected.
4678 * Pointer to error structure.
4681 * 0 on success, a negative errno value otherwise and rte_errno is set.
4684 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
4685 const struct rte_flow_action *action,
4686 const uint64_t item_flags,
4687 struct rte_flow_error *error)
4692 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4694 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
4695 MLX5_FLOW_LAYER_INNER_L3 :
4696 MLX5_FLOW_LAYER_OUTER_L3;
4697 if (!(item_flags & layer))
4698 return rte_flow_error_set(error, EINVAL,
4699 RTE_FLOW_ERROR_TYPE_ACTION,
4701 "no IP protocol in pattern");
4707 * Validate the generic modify field actions.
4709 * Pointer to the rte_eth_dev structure.
4710 * @param[in] action_flags
4711 * Holds the actions detected until now.
4713 * Pointer to the modify action.
4715 * Pointer to the flow attributes.
4717 * Pointer to error structure.
4720 * Number of header fields to modify (0 or more) on success,
4721 * a negative errno value otherwise and rte_errno is set.
4724 flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
4725 const uint64_t action_flags,
4726 const struct rte_flow_action *action,
4727 const struct rte_flow_attr *attr,
4728 struct rte_flow_error *error)
4731 struct mlx5_priv *priv = dev->data->dev_private;
4732 struct mlx5_dev_config *config = &priv->config;
4733 const struct rte_flow_action_modify_field *action_modify_field =
4735 uint32_t dst_width = mlx5_flow_item_field_width(config,
4736 action_modify_field->dst.field);
4737 uint32_t src_width = mlx5_flow_item_field_width(config,
4738 action_modify_field->src.field);
4740 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4744 if (action_modify_field->width == 0)
4745 return rte_flow_error_set(error, EINVAL,
4746 RTE_FLOW_ERROR_TYPE_ACTION, action,
4747 "no bits are requested to be modified");
4748 else if (action_modify_field->width > dst_width ||
4749 action_modify_field->width > src_width)
4750 return rte_flow_error_set(error, EINVAL,
4751 RTE_FLOW_ERROR_TYPE_ACTION, action,
4752 "cannot modify more bits than"
4753 " the width of a field");
4754 if (action_modify_field->dst.field != RTE_FLOW_FIELD_VALUE &&
4755 action_modify_field->dst.field != RTE_FLOW_FIELD_POINTER) {
4756 if ((action_modify_field->dst.offset +
4757 action_modify_field->width > dst_width) ||
4758 (action_modify_field->dst.offset % 32))
4759 return rte_flow_error_set(error, EINVAL,
4760 RTE_FLOW_ERROR_TYPE_ACTION, action,
4761 "destination offset is too big"
4762 " or not aligned to 4 bytes");
4763 if (action_modify_field->dst.level &&
4764 action_modify_field->dst.field != RTE_FLOW_FIELD_TAG)
4765 return rte_flow_error_set(error, ENOTSUP,
4766 RTE_FLOW_ERROR_TYPE_ACTION, action,
4767 "inner header fields modification"
4768 " is not supported");
4770 if (action_modify_field->src.field != RTE_FLOW_FIELD_VALUE &&
4771 action_modify_field->src.field != RTE_FLOW_FIELD_POINTER) {
4772 if (!attr->transfer && !attr->group)
4773 return rte_flow_error_set(error, ENOTSUP,
4774 RTE_FLOW_ERROR_TYPE_ACTION, action,
4775 "modify field action is not"
4776 " supported for group 0");
4777 if ((action_modify_field->src.offset +
4778 action_modify_field->width > src_width) ||
4779 (action_modify_field->src.offset % 32))
4780 return rte_flow_error_set(error, EINVAL,
4781 RTE_FLOW_ERROR_TYPE_ACTION, action,
4782 "source offset is too big"
4783 " or not aligned to 4 bytes");
4784 if (action_modify_field->src.level &&
4785 action_modify_field->src.field != RTE_FLOW_FIELD_TAG)
4786 return rte_flow_error_set(error, ENOTSUP,
4787 RTE_FLOW_ERROR_TYPE_ACTION, action,
4788 "inner header fields modification"
4789 " is not supported");
4791 if ((action_modify_field->dst.field ==
4792 action_modify_field->src.field) &&
4793 (action_modify_field->dst.level ==
4794 action_modify_field->src.level))
4795 return rte_flow_error_set(error, EINVAL,
4796 RTE_FLOW_ERROR_TYPE_ACTION, action,
4797 "source and destination fields"
4798 " cannot be the same");
4799 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VALUE ||
4800 action_modify_field->dst.field == RTE_FLOW_FIELD_POINTER)
4801 return rte_flow_error_set(error, EINVAL,
4802 RTE_FLOW_ERROR_TYPE_ACTION, action,
4803 "immediate value or a pointer to it"
4804 " cannot be used as a destination");
4805 if (action_modify_field->dst.field == RTE_FLOW_FIELD_START ||
4806 action_modify_field->src.field == RTE_FLOW_FIELD_START)
4807 return rte_flow_error_set(error, ENOTSUP,
4808 RTE_FLOW_ERROR_TYPE_ACTION, action,
4809 "modifications of an arbitrary"
4810 " place in a packet is not supported");
4811 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VLAN_TYPE ||
4812 action_modify_field->src.field == RTE_FLOW_FIELD_VLAN_TYPE)
4813 return rte_flow_error_set(error, ENOTSUP,
4814 RTE_FLOW_ERROR_TYPE_ACTION, action,
4815 "modifications of the 802.1Q Tag"
4816 " Identifier is not supported");
4817 if (action_modify_field->dst.field == RTE_FLOW_FIELD_VXLAN_VNI ||
4818 action_modify_field->src.field == RTE_FLOW_FIELD_VXLAN_VNI)
4819 return rte_flow_error_set(error, ENOTSUP,
4820 RTE_FLOW_ERROR_TYPE_ACTION, action,
4821 "modifications of the VXLAN Network"
4822 " Identifier is not supported");
4823 if (action_modify_field->dst.field == RTE_FLOW_FIELD_GENEVE_VNI ||
4824 action_modify_field->src.field == RTE_FLOW_FIELD_GENEVE_VNI)
4825 return rte_flow_error_set(error, ENOTSUP,
4826 RTE_FLOW_ERROR_TYPE_ACTION, action,
4827 "modifications of the GENEVE Network"
4828 " Identifier is not supported");
4829 if (action_modify_field->dst.field == RTE_FLOW_FIELD_MARK ||
4830 action_modify_field->src.field == RTE_FLOW_FIELD_MARK ||
4831 action_modify_field->dst.field == RTE_FLOW_FIELD_META ||
4832 action_modify_field->src.field == RTE_FLOW_FIELD_META) {
4833 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
4834 !mlx5_flow_ext_mreg_supported(dev))
4835 return rte_flow_error_set(error, ENOTSUP,
4836 RTE_FLOW_ERROR_TYPE_ACTION, action,
4837 "cannot modify mark or metadata without"
4838 " extended metadata register support");
4840 if (action_modify_field->operation != RTE_FLOW_MODIFY_SET)
4841 return rte_flow_error_set(error, ENOTSUP,
4842 RTE_FLOW_ERROR_TYPE_ACTION, action,
4843 "add and sub operations"
4844 " are not supported");
4845 return (action_modify_field->width / 32) +
4846 !!(action_modify_field->width % 32);
4850 * Validate jump action.
4853 * Pointer to the jump action.
4854 * @param[in] action_flags
4855 * Holds the actions detected until now.
4856 * @param[in] attributes
4857 * Pointer to flow attributes
4858 * @param[in] external
4859 * Action belongs to flow rule created by request external to PMD.
4861 * Pointer to error structure.
4864 * 0 on success, a negative errno value otherwise and rte_errno is set.
4867 flow_dv_validate_action_jump(struct rte_eth_dev *dev,
4868 const struct mlx5_flow_tunnel *tunnel,
4869 const struct rte_flow_action *action,
4870 uint64_t action_flags,
4871 const struct rte_flow_attr *attributes,
4872 bool external, struct rte_flow_error *error)
4874 uint32_t target_group, table;
4876 struct flow_grp_info grp_info = {
4877 .external = !!external,
4878 .transfer = !!attributes->transfer,
4882 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4883 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4884 return rte_flow_error_set(error, EINVAL,
4885 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4886 "can't have 2 fate actions in"
4889 return rte_flow_error_set(error, EINVAL,
4890 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4891 NULL, "action configuration not set");
4893 ((const struct rte_flow_action_jump *)action->conf)->group;
4894 ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
4898 if (attributes->group == target_group &&
4899 !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
4900 MLX5_FLOW_ACTION_TUNNEL_MATCH)))
4901 return rte_flow_error_set(error, EINVAL,
4902 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4903 "target group must be other than"
4904 " the current flow group");
4909 * Validate the port_id action.
4912 * Pointer to rte_eth_dev structure.
4913 * @param[in] action_flags
4914 * Bit-fields that holds the actions detected until now.
4916 * Port_id RTE action structure.
4918 * Attributes of flow that includes this action.
4920 * Pointer to error structure.
4923 * 0 on success, a negative errno value otherwise and rte_errno is set.
4926 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
4927 uint64_t action_flags,
4928 const struct rte_flow_action *action,
4929 const struct rte_flow_attr *attr,
4930 struct rte_flow_error *error)
4932 const struct rte_flow_action_port_id *port_id;
4933 struct mlx5_priv *act_priv;
4934 struct mlx5_priv *dev_priv;
4937 if (!attr->transfer)
4938 return rte_flow_error_set(error, ENOTSUP,
4939 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4941 "port id action is valid in transfer"
4943 if (!action || !action->conf)
4944 return rte_flow_error_set(error, ENOTSUP,
4945 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4947 "port id action parameters must be"
4949 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4950 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4951 return rte_flow_error_set(error, EINVAL,
4952 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4953 "can have only one fate actions in"
4955 dev_priv = mlx5_dev_to_eswitch_info(dev);
4957 return rte_flow_error_set(error, rte_errno,
4958 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4960 "failed to obtain E-Switch info");
4961 port_id = action->conf;
4962 port = port_id->original ? dev->data->port_id : port_id->id;
4963 act_priv = mlx5_port_to_eswitch_info(port, false);
4965 return rte_flow_error_set
4967 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
4968 "failed to obtain E-Switch port id for port");
4969 if (act_priv->domain_id != dev_priv->domain_id)
4970 return rte_flow_error_set
4972 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4973 "port does not belong to"
4974 " E-Switch being configured");
4979 * Get the maximum number of modify header actions.
4982 * Pointer to rte_eth_dev structure.
4984 * Flags bits to check if root level.
4987 * Max number of modify header actions device can support.
4989 static inline unsigned int
4990 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
4994 * There's no way to directly query the max capacity from FW.
4995 * The maximal value on root table should be assumed to be supported.
4997 if (!(flags & MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL))
4998 return MLX5_MAX_MODIFY_NUM;
5000 return MLX5_ROOT_TBL_MODIFY_NUM;
5004 * Validate the meter action.
5007 * Pointer to rte_eth_dev structure.
5008 * @param[in] action_flags
5009 * Bit-fields that holds the actions detected until now.
5011 * Pointer to the meter action.
5013 * Attributes of flow that includes this action.
5015 * Pointer to error structure.
5018 * 0 on success, a negative errno value otherwise and rte_ernno is set.
5021 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5022 uint64_t action_flags,
5023 const struct rte_flow_action *action,
5024 const struct rte_flow_attr *attr,
5026 struct rte_flow_error *error)
5028 struct mlx5_priv *priv = dev->data->dev_private;
5029 const struct rte_flow_action_meter *am = action->conf;
5030 struct mlx5_flow_meter_info *fm;
5031 struct mlx5_flow_meter_policy *mtr_policy;
5032 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5035 return rte_flow_error_set(error, EINVAL,
5036 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5037 "meter action conf is NULL");
5039 if (action_flags & MLX5_FLOW_ACTION_METER)
5040 return rte_flow_error_set(error, ENOTSUP,
5041 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5042 "meter chaining not support");
5043 if (action_flags & MLX5_FLOW_ACTION_JUMP)
5044 return rte_flow_error_set(error, ENOTSUP,
5045 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5046 "meter with jump not support");
5048 return rte_flow_error_set(error, ENOTSUP,
5049 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5051 "meter action not supported");
5052 fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5054 return rte_flow_error_set(error, EINVAL,
5055 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5057 /* aso meter can always be shared by different domains */
5058 if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5059 !(fm->transfer == attr->transfer ||
5060 (!fm->ingress && !attr->ingress && attr->egress) ||
5061 (!fm->egress && !attr->egress && attr->ingress)))
5062 return rte_flow_error_set(error, EINVAL,
5063 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5064 "Flow attributes domain are either invalid "
5065 "or have a domain conflict with current "
5066 "meter attributes");
5067 if (fm->def_policy) {
5068 if (!((attr->transfer &&
5069 mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
5071 mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
5073 mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
5074 return rte_flow_error_set(error, EINVAL,
5075 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5076 "Flow attributes domain "
5077 "have a conflict with current "
5078 "meter domain attributes");
5081 mtr_policy = mlx5_flow_meter_policy_find(dev,
5082 fm->policy_id, NULL);
5084 return rte_flow_error_set(error, EINVAL,
5085 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5086 "Invalid policy id for meter ");
5087 if (!((attr->transfer && mtr_policy->transfer) ||
5088 (attr->egress && mtr_policy->egress) ||
5089 (attr->ingress && mtr_policy->ingress)))
5090 return rte_flow_error_set(error, EINVAL,
5091 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5092 "Flow attributes domain "
5093 "have a conflict with current "
5094 "meter domain attributes");
5095 *def_policy = false;
5101 * Validate the age action.
5103 * @param[in] action_flags
5104 * Holds the actions detected until now.
5106 * Pointer to the age action.
5108 * Pointer to the Ethernet device structure.
5110 * Pointer to error structure.
5113 * 0 on success, a negative errno value otherwise and rte_errno is set.
5116 flow_dv_validate_action_age(uint64_t action_flags,
5117 const struct rte_flow_action *action,
5118 struct rte_eth_dev *dev,
5119 struct rte_flow_error *error)
5121 struct mlx5_priv *priv = dev->data->dev_private;
5122 const struct rte_flow_action_age *age = action->conf;
5124 if (!priv->config.devx || (priv->sh->cmng.counter_fallback &&
5125 !priv->sh->aso_age_mng))
5126 return rte_flow_error_set(error, ENOTSUP,
5127 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5129 "age action not supported");
5130 if (!(action->conf))
5131 return rte_flow_error_set(error, EINVAL,
5132 RTE_FLOW_ERROR_TYPE_ACTION, action,
5133 "configuration cannot be null");
5134 if (!(age->timeout))
5135 return rte_flow_error_set(error, EINVAL,
5136 RTE_FLOW_ERROR_TYPE_ACTION, action,
5137 "invalid timeout value 0");
5138 if (action_flags & MLX5_FLOW_ACTION_AGE)
5139 return rte_flow_error_set(error, EINVAL,
5140 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5141 "duplicate age actions set");
5146 * Validate the modify-header IPv4 DSCP actions.
5148 * @param[in] action_flags
5149 * Holds the actions detected until now.
5151 * Pointer to the modify action.
5152 * @param[in] item_flags
5153 * Holds the items detected.
5155 * Pointer to error structure.
5158 * 0 on success, a negative errno value otherwise and rte_errno is set.
5161 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
5162 const struct rte_flow_action *action,
5163 const uint64_t item_flags,
5164 struct rte_flow_error *error)
5168 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5170 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
5171 return rte_flow_error_set(error, EINVAL,
5172 RTE_FLOW_ERROR_TYPE_ACTION,
5174 "no ipv4 item in pattern");
5180 * Validate the modify-header IPv6 DSCP actions.
5182 * @param[in] action_flags
5183 * Holds the actions detected until now.
5185 * Pointer to the modify action.
5186 * @param[in] item_flags
5187 * Holds the items detected.
5189 * Pointer to error structure.
5192 * 0 on success, a negative errno value otherwise and rte_errno is set.
5195 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
5196 const struct rte_flow_action *action,
5197 const uint64_t item_flags,
5198 struct rte_flow_error *error)
5202 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5204 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
5205 return rte_flow_error_set(error, EINVAL,
5206 RTE_FLOW_ERROR_TYPE_ACTION,
5208 "no ipv6 item in pattern");
5214 * Match modify-header resource.
5217 * Pointer to the hash list.
5219 * Pointer to exist resource entry object.
5221 * Key of the new entry.
5223 * Pointer to new modify-header resource.
5226 * 0 on matching, non-zero otherwise.
5229 flow_dv_modify_match_cb(struct mlx5_hlist *list __rte_unused,
5230 struct mlx5_hlist_entry *entry,
5231 uint64_t key __rte_unused, void *cb_ctx)
5233 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5234 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5235 struct mlx5_flow_dv_modify_hdr_resource *resource =
5236 container_of(entry, typeof(*resource), entry);
5237 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5239 key_len += ref->actions_num * sizeof(ref->actions[0]);
5240 return ref->actions_num != resource->actions_num ||
5241 memcmp(&ref->ft_type, &resource->ft_type, key_len);
5244 struct mlx5_hlist_entry *
5245 flow_dv_modify_create_cb(struct mlx5_hlist *list, uint64_t key __rte_unused,
5248 struct mlx5_dev_ctx_shared *sh = list->ctx;
5249 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5250 struct mlx5dv_dr_domain *ns;
5251 struct mlx5_flow_dv_modify_hdr_resource *entry;
5252 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
5254 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
5255 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
5257 entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry) + data_len, 0,
5260 rte_flow_error_set(ctx->error, ENOMEM,
5261 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5262 "cannot allocate resource memory");
5265 rte_memcpy(&entry->ft_type,
5266 RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
5267 key_len + data_len);
5268 if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
5269 ns = sh->fdb_domain;
5270 else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
5274 ret = mlx5_flow_os_create_flow_action_modify_header
5275 (sh->ctx, ns, entry,
5276 data_len, &entry->action);
5279 rte_flow_error_set(ctx->error, ENOMEM,
5280 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5281 NULL, "cannot create modification action");
5284 return &entry->entry;
5288 * Validate the sample action.
5290 * @param[in, out] action_flags
5291 * Holds the actions detected until now.
5293 * Pointer to the sample action.
5295 * Pointer to the Ethernet device structure.
5297 * Attributes of flow that includes this action.
5298 * @param[in] item_flags
5299 * Holds the items detected.
5301 * Pointer to the RSS action.
5302 * @param[out] sample_rss
5303 * Pointer to the RSS action in sample action list.
5305 * Pointer to the COUNT action in sample action list.
5306 * @param[out] fdb_mirror_limit
5307 * Pointer to the FDB mirror limitation flag.
5309 * Pointer to error structure.
5312 * 0 on success, a negative errno value otherwise and rte_errno is set.
5315 flow_dv_validate_action_sample(uint64_t *action_flags,
5316 const struct rte_flow_action *action,
5317 struct rte_eth_dev *dev,
5318 const struct rte_flow_attr *attr,
5319 uint64_t item_flags,
5320 const struct rte_flow_action_rss *rss,
5321 const struct rte_flow_action_rss **sample_rss,
5322 const struct rte_flow_action_count **count,
5323 int *fdb_mirror_limit,
5324 struct rte_flow_error *error)
5326 struct mlx5_priv *priv = dev->data->dev_private;
5327 struct mlx5_dev_config *dev_conf = &priv->config;
5328 const struct rte_flow_action_sample *sample = action->conf;
5329 const struct rte_flow_action *act;
5330 uint64_t sub_action_flags = 0;
5331 uint16_t queue_index = 0xFFFF;
5336 return rte_flow_error_set(error, EINVAL,
5337 RTE_FLOW_ERROR_TYPE_ACTION, action,
5338 "configuration cannot be NULL");
5339 if (sample->ratio == 0)
5340 return rte_flow_error_set(error, EINVAL,
5341 RTE_FLOW_ERROR_TYPE_ACTION, action,
5342 "ratio value starts from 1");
5343 if (!priv->config.devx || (sample->ratio > 0 && !priv->sampler_en))
5344 return rte_flow_error_set(error, ENOTSUP,
5345 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5347 "sample action not supported");
5348 if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
5349 return rte_flow_error_set(error, EINVAL,
5350 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5351 "Multiple sample actions not "
5353 if (*action_flags & MLX5_FLOW_ACTION_METER)
5354 return rte_flow_error_set(error, EINVAL,
5355 RTE_FLOW_ERROR_TYPE_ACTION, action,
5356 "wrong action order, meter should "
5357 "be after sample action");
5358 if (*action_flags & MLX5_FLOW_ACTION_JUMP)
5359 return rte_flow_error_set(error, EINVAL,
5360 RTE_FLOW_ERROR_TYPE_ACTION, action,
5361 "wrong action order, jump should "
5362 "be after sample action");
5363 act = sample->actions;
5364 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
5365 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5366 return rte_flow_error_set(error, ENOTSUP,
5367 RTE_FLOW_ERROR_TYPE_ACTION,
5368 act, "too many actions");
5369 switch (act->type) {
5370 case RTE_FLOW_ACTION_TYPE_QUEUE:
5371 ret = mlx5_flow_validate_action_queue(act,
5377 queue_index = ((const struct rte_flow_action_queue *)
5378 (act->conf))->index;
5379 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
5382 case RTE_FLOW_ACTION_TYPE_RSS:
5383 *sample_rss = act->conf;
5384 ret = mlx5_flow_validate_action_rss(act,
5391 if (rss && *sample_rss &&
5392 ((*sample_rss)->level != rss->level ||
5393 (*sample_rss)->types != rss->types))
5394 return rte_flow_error_set(error, ENOTSUP,
5395 RTE_FLOW_ERROR_TYPE_ACTION,
5397 "Can't use the different RSS types "
5398 "or level in the same flow");
5399 if (*sample_rss != NULL && (*sample_rss)->queue_num)
5400 queue_index = (*sample_rss)->queue[0];
5401 sub_action_flags |= MLX5_FLOW_ACTION_RSS;
5404 case RTE_FLOW_ACTION_TYPE_MARK:
5405 ret = flow_dv_validate_action_mark(dev, act,
5410 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
5411 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
5412 MLX5_FLOW_ACTION_MARK_EXT;
5414 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
5417 case RTE_FLOW_ACTION_TYPE_COUNT:
5418 ret = flow_dv_validate_action_count
5419 (dev, is_shared_action_count(act),
5420 *action_flags | sub_action_flags,
5425 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
5426 *action_flags |= MLX5_FLOW_ACTION_COUNT;
5429 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5430 ret = flow_dv_validate_action_port_id(dev,
5437 sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5440 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5441 ret = flow_dv_validate_action_raw_encap_decap
5442 (dev, NULL, act->conf, attr, &sub_action_flags,
5443 &actions_n, action, item_flags, error);
5448 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5449 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5450 ret = flow_dv_validate_action_l2_encap(dev,
5456 sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
5460 return rte_flow_error_set(error, ENOTSUP,
5461 RTE_FLOW_ERROR_TYPE_ACTION,
5463 "Doesn't support optional "
5467 if (attr->ingress && !attr->transfer) {
5468 if (!(sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
5469 MLX5_FLOW_ACTION_RSS)))
5470 return rte_flow_error_set(error, EINVAL,
5471 RTE_FLOW_ERROR_TYPE_ACTION,
5473 "Ingress must has a dest "
5474 "QUEUE for Sample");
5475 } else if (attr->egress && !attr->transfer) {
5476 return rte_flow_error_set(error, ENOTSUP,
5477 RTE_FLOW_ERROR_TYPE_ACTION,
5479 "Sample Only support Ingress "
5481 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
5482 MLX5_ASSERT(attr->transfer);
5483 if (sample->ratio > 1)
5484 return rte_flow_error_set(error, ENOTSUP,
5485 RTE_FLOW_ERROR_TYPE_ACTION,
5487 "E-Switch doesn't support "
5488 "any optional action "
5490 if (sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
5491 return rte_flow_error_set(error, ENOTSUP,
5492 RTE_FLOW_ERROR_TYPE_ACTION,
5494 "unsupported action QUEUE");
5495 if (sub_action_flags & MLX5_FLOW_ACTION_RSS)
5496 return rte_flow_error_set(error, ENOTSUP,
5497 RTE_FLOW_ERROR_TYPE_ACTION,
5499 "unsupported action QUEUE");
5500 if (!(sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
5501 return rte_flow_error_set(error, EINVAL,
5502 RTE_FLOW_ERROR_TYPE_ACTION,
5504 "E-Switch must has a dest "
5505 "port for mirroring");
5506 if (!priv->config.hca_attr.reg_c_preserve &&
5507 priv->representor_id != -1)
5508 *fdb_mirror_limit = 1;
5510 /* Continue validation for Xcap actions.*/
5511 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
5512 (queue_index == 0xFFFF ||
5513 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
5514 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
5515 MLX5_FLOW_XCAP_ACTIONS)
5516 return rte_flow_error_set(error, ENOTSUP,
5517 RTE_FLOW_ERROR_TYPE_ACTION,
5518 NULL, "encap and decap "
5519 "combination aren't "
5521 if (!attr->transfer && attr->ingress && (sub_action_flags &
5522 MLX5_FLOW_ACTION_ENCAP))
5523 return rte_flow_error_set(error, ENOTSUP,
5524 RTE_FLOW_ERROR_TYPE_ACTION,
5525 NULL, "encap is not supported"
5526 " for ingress traffic");
5532 * Find existing modify-header resource or create and register a new one.
5534 * @param dev[in, out]
5535 * Pointer to rte_eth_dev structure.
5536 * @param[in, out] resource
5537 * Pointer to modify-header resource.
5538 * @parm[in, out] dev_flow
5539 * Pointer to the dev_flow.
5541 * pointer to error structure.
5544 * 0 on success otherwise -errno and errno is set.
5547 flow_dv_modify_hdr_resource_register
5548 (struct rte_eth_dev *dev,
5549 struct mlx5_flow_dv_modify_hdr_resource *resource,
5550 struct mlx5_flow *dev_flow,
5551 struct rte_flow_error *error)
5553 struct mlx5_priv *priv = dev->data->dev_private;
5554 struct mlx5_dev_ctx_shared *sh = priv->sh;
5555 uint32_t key_len = sizeof(*resource) -
5556 offsetof(typeof(*resource), ft_type) +
5557 resource->actions_num * sizeof(resource->actions[0]);
5558 struct mlx5_hlist_entry *entry;
5559 struct mlx5_flow_cb_ctx ctx = {
5565 resource->flags = dev_flow->dv.group ? 0 :
5566 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
5567 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
5569 return rte_flow_error_set(error, EOVERFLOW,
5570 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5571 "too many modify header items");
5572 key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
5573 entry = mlx5_hlist_register(sh->modify_cmds, key64, &ctx);
5576 resource = container_of(entry, typeof(*resource), entry);
5577 dev_flow->handle->dvh.modify_hdr = resource;
5582 * Get DV flow counter by index.
5585 * Pointer to the Ethernet device structure.
5587 * mlx5 flow counter index in the container.
5589 * mlx5 flow counter pool in the container.
5592 * Pointer to the counter, NULL otherwise.
5594 static struct mlx5_flow_counter *
5595 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
5597 struct mlx5_flow_counter_pool **ppool)
5599 struct mlx5_priv *priv = dev->data->dev_private;
5600 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5601 struct mlx5_flow_counter_pool *pool;
5603 /* Decrease to original index and clear shared bit. */
5604 idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
5605 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cmng->n);
5606 pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
5610 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
5614 * Check the devx counter belongs to the pool.
5617 * Pointer to the counter pool.
5619 * The counter devx ID.
5622 * True if counter belongs to the pool, false otherwise.
5625 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
5627 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
5628 MLX5_COUNTERS_PER_POOL;
5630 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
5636 * Get a pool by devx counter ID.
5639 * Pointer to the counter management.
5641 * The counter devx ID.
5644 * The counter pool pointer if exists, NULL otherwise,
5646 static struct mlx5_flow_counter_pool *
5647 flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
5650 struct mlx5_flow_counter_pool *pool = NULL;
5652 rte_spinlock_lock(&cmng->pool_update_sl);
5653 /* Check last used pool. */
5654 if (cmng->last_pool_idx != POOL_IDX_INVALID &&
5655 flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
5656 pool = cmng->pools[cmng->last_pool_idx];
5659 /* ID out of range means no suitable pool in the container. */
5660 if (id > cmng->max_id || id < cmng->min_id)
5663 * Find the pool from the end of the container, since mostly counter
5664 * ID is sequence increasing, and the last pool should be the needed
5669 struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
5671 if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
5677 rte_spinlock_unlock(&cmng->pool_update_sl);
5682 * Resize a counter container.
5685 * Pointer to the Ethernet device structure.
5688 * 0 on success, otherwise negative errno value and rte_errno is set.
5691 flow_dv_container_resize(struct rte_eth_dev *dev)
5693 struct mlx5_priv *priv = dev->data->dev_private;
5694 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5695 void *old_pools = cmng->pools;
5696 uint32_t resize = cmng->n + MLX5_CNT_CONTAINER_RESIZE;
5697 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
5698 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
5705 memcpy(pools, old_pools, cmng->n *
5706 sizeof(struct mlx5_flow_counter_pool *));
5708 cmng->pools = pools;
5710 mlx5_free(old_pools);
5715 * Query a devx flow counter.
5718 * Pointer to the Ethernet device structure.
5719 * @param[in] counter
5720 * Index to the flow counter.
5722 * The statistics value of packets.
5724 * The statistics value of bytes.
5727 * 0 on success, otherwise a negative errno value and rte_errno is set.
5730 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
5733 struct mlx5_priv *priv = dev->data->dev_private;
5734 struct mlx5_flow_counter_pool *pool = NULL;
5735 struct mlx5_flow_counter *cnt;
5738 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
5740 if (priv->sh->cmng.counter_fallback)
5741 return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
5742 0, pkts, bytes, 0, NULL, NULL, 0);
5743 rte_spinlock_lock(&pool->sl);
5748 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
5749 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
5750 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
5752 rte_spinlock_unlock(&pool->sl);
5757 * Create and initialize a new counter pool.
5760 * Pointer to the Ethernet device structure.
5762 * The devX counter handle.
5764 * Whether the pool is for counter that was allocated for aging.
5765 * @param[in/out] cont_cur
5766 * Pointer to the container pointer, it will be update in pool resize.
5769 * The pool container pointer on success, NULL otherwise and rte_errno is set.
5771 static struct mlx5_flow_counter_pool *
5772 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
5775 struct mlx5_priv *priv = dev->data->dev_private;
5776 struct mlx5_flow_counter_pool *pool;
5777 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5778 bool fallback = priv->sh->cmng.counter_fallback;
5779 uint32_t size = sizeof(*pool);
5781 size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
5782 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
5783 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
5789 pool->is_aged = !!age;
5790 pool->query_gen = 0;
5791 pool->min_dcs = dcs;
5792 rte_spinlock_init(&pool->sl);
5793 rte_spinlock_init(&pool->csl);
5794 TAILQ_INIT(&pool->counters[0]);
5795 TAILQ_INIT(&pool->counters[1]);
5796 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
5797 rte_spinlock_lock(&cmng->pool_update_sl);
5798 pool->index = cmng->n_valid;
5799 if (pool->index == cmng->n && flow_dv_container_resize(dev)) {
5801 rte_spinlock_unlock(&cmng->pool_update_sl);
5804 cmng->pools[pool->index] = pool;
5806 if (unlikely(fallback)) {
5807 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
5809 if (base < cmng->min_id)
5810 cmng->min_id = base;
5811 if (base > cmng->max_id)
5812 cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
5813 cmng->last_pool_idx = pool->index;
5815 rte_spinlock_unlock(&cmng->pool_update_sl);
5820 * Prepare a new counter and/or a new counter pool.
5823 * Pointer to the Ethernet device structure.
5824 * @param[out] cnt_free
5825 * Where to put the pointer of a new counter.
5827 * Whether the pool is for counter that was allocated for aging.
5830 * The counter pool pointer and @p cnt_free is set on success,
5831 * NULL otherwise and rte_errno is set.
5833 static struct mlx5_flow_counter_pool *
5834 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
5835 struct mlx5_flow_counter **cnt_free,
5838 struct mlx5_priv *priv = dev->data->dev_private;
5839 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5840 struct mlx5_flow_counter_pool *pool;
5841 struct mlx5_counters tmp_tq;
5842 struct mlx5_devx_obj *dcs = NULL;
5843 struct mlx5_flow_counter *cnt;
5844 enum mlx5_counter_type cnt_type =
5845 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
5846 bool fallback = priv->sh->cmng.counter_fallback;
5850 /* bulk_bitmap must be 0 for single counter allocation. */
5851 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
5854 pool = flow_dv_find_pool_by_id(cmng, dcs->id);
5856 pool = flow_dv_pool_create(dev, dcs, age);
5858 mlx5_devx_cmd_destroy(dcs);
5862 i = dcs->id % MLX5_COUNTERS_PER_POOL;
5863 cnt = MLX5_POOL_GET_CNT(pool, i);
5865 cnt->dcs_when_free = dcs;
5869 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
5871 rte_errno = ENODATA;
5874 pool = flow_dv_pool_create(dev, dcs, age);
5876 mlx5_devx_cmd_destroy(dcs);
5879 TAILQ_INIT(&tmp_tq);
5880 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
5881 cnt = MLX5_POOL_GET_CNT(pool, i);
5883 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
5885 rte_spinlock_lock(&cmng->csl[cnt_type]);
5886 TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
5887 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5888 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
5889 (*cnt_free)->pool = pool;
5894 * Allocate a flow counter.
5897 * Pointer to the Ethernet device structure.
5899 * Whether the counter was allocated for aging.
5902 * Index to flow counter on success, 0 otherwise and rte_errno is set.
5905 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
5907 struct mlx5_priv *priv = dev->data->dev_private;
5908 struct mlx5_flow_counter_pool *pool = NULL;
5909 struct mlx5_flow_counter *cnt_free = NULL;
5910 bool fallback = priv->sh->cmng.counter_fallback;
5911 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
5912 enum mlx5_counter_type cnt_type =
5913 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
5916 if (!priv->config.devx) {
5917 rte_errno = ENOTSUP;
5920 /* Get free counters from container. */
5921 rte_spinlock_lock(&cmng->csl[cnt_type]);
5922 cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
5924 TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
5925 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5926 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
5928 pool = cnt_free->pool;
5930 cnt_free->dcs_when_active = cnt_free->dcs_when_free;
5931 /* Create a DV counter action only in the first time usage. */
5932 if (!cnt_free->action) {
5934 struct mlx5_devx_obj *dcs;
5938 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
5939 dcs = pool->min_dcs;
5942 dcs = cnt_free->dcs_when_free;
5944 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
5951 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
5952 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
5953 /* Update the counter reset values. */
5954 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
5957 if (!fallback && !priv->sh->cmng.query_thread_on)
5958 /* Start the asynchronous batch query by the host thread. */
5959 mlx5_set_query_alarm(priv->sh);
5961 * When the count action isn't shared (by ID), shared_info field is
5962 * used for indirect action API's refcnt.
5963 * When the counter action is not shared neither by ID nor by indirect
5964 * action API, shared info must be 1.
5966 cnt_free->shared_info.refcnt = 1;
5970 cnt_free->pool = pool;
5972 cnt_free->dcs_when_free = cnt_free->dcs_when_active;
5973 rte_spinlock_lock(&cmng->csl[cnt_type]);
5974 TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
5975 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5981 * Allocate a shared flow counter.
5984 * Pointer to the shared counter configuration.
5986 * Pointer to save the allocated counter index.
5989 * Index to flow counter on success, 0 otherwise and rte_errno is set.
5993 flow_dv_counter_alloc_shared_cb(void *ctx, union mlx5_l3t_data *data)
5995 struct mlx5_shared_counter_conf *conf = ctx;
5996 struct rte_eth_dev *dev = conf->dev;
5997 struct mlx5_flow_counter *cnt;
5999 data->dword = flow_dv_counter_alloc(dev, 0);
6000 data->dword |= MLX5_CNT_SHARED_OFFSET;
6001 cnt = flow_dv_counter_get_by_idx(dev, data->dword, NULL);
6002 cnt->shared_info.id = conf->id;
6007 * Get a shared flow counter.
6010 * Pointer to the Ethernet device structure.
6012 * Counter identifier.
6015 * Index to flow counter on success, 0 otherwise and rte_errno is set.
6018 flow_dv_counter_get_shared(struct rte_eth_dev *dev, uint32_t id)
6020 struct mlx5_priv *priv = dev->data->dev_private;
6021 struct mlx5_shared_counter_conf conf = {
6025 union mlx5_l3t_data data = {
6029 mlx5_l3t_prepare_entry(priv->sh->cnt_id_tbl, id, &data,
6030 flow_dv_counter_alloc_shared_cb, &conf);
6035 * Get age param from counter index.
6038 * Pointer to the Ethernet device structure.
6039 * @param[in] counter
6040 * Index to the counter handler.
6043 * The aging parameter specified for the counter index.
6045 static struct mlx5_age_param*
6046 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
6049 struct mlx5_flow_counter *cnt;
6050 struct mlx5_flow_counter_pool *pool = NULL;
6052 flow_dv_counter_get_by_idx(dev, counter, &pool);
6053 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
6054 cnt = MLX5_POOL_GET_CNT(pool, counter);
6055 return MLX5_CNT_TO_AGE(cnt);
6059 * Remove a flow counter from aged counter list.
6062 * Pointer to the Ethernet device structure.
6063 * @param[in] counter
6064 * Index to the counter handler.
6066 * Pointer to the counter handler.
6069 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
6070 uint32_t counter, struct mlx5_flow_counter *cnt)
6072 struct mlx5_age_info *age_info;
6073 struct mlx5_age_param *age_param;
6074 struct mlx5_priv *priv = dev->data->dev_private;
6075 uint16_t expected = AGE_CANDIDATE;
6077 age_info = GET_PORT_AGE_INFO(priv);
6078 age_param = flow_dv_counter_idx_get_age(dev, counter);
6079 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
6080 AGE_FREE, false, __ATOMIC_RELAXED,
6081 __ATOMIC_RELAXED)) {
6083 * We need the lock even it is age timeout,
6084 * since counter may still in process.
6086 rte_spinlock_lock(&age_info->aged_sl);
6087 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
6088 rte_spinlock_unlock(&age_info->aged_sl);
6089 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
6094 * Release a flow counter.
6097 * Pointer to the Ethernet device structure.
6098 * @param[in] counter
6099 * Index to the counter handler.
6102 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
6104 struct mlx5_priv *priv = dev->data->dev_private;
6105 struct mlx5_flow_counter_pool *pool = NULL;
6106 struct mlx5_flow_counter *cnt;
6107 enum mlx5_counter_type cnt_type;
6111 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6113 if (pool->is_aged) {
6114 flow_dv_counter_remove_from_age(dev, counter, cnt);
6117 * If the counter action is shared by ID, the l3t_clear_entry
6118 * function reduces its references counter. If after the
6119 * reduction the action is still referenced, the function
6120 * returns here and does not release it.
6122 if (IS_LEGACY_SHARED_CNT(counter) &&
6123 mlx5_l3t_clear_entry(priv->sh->cnt_id_tbl,
6124 cnt->shared_info.id))
6127 * If the counter action is shared by indirect action API,
6128 * the atomic function reduces its references counter.
6129 * If after the reduction the action is still referenced, the
6130 * function returns here and does not release it.
6131 * When the counter action is not shared neither by ID nor by
6132 * indirect action API, shared info is 1 before the reduction,
6133 * so this condition is failed and function doesn't return here.
6135 if (!IS_LEGACY_SHARED_CNT(counter) &&
6136 __atomic_sub_fetch(&cnt->shared_info.refcnt, 1,
6142 * Put the counter back to list to be updated in none fallback mode.
6143 * Currently, we are using two list alternately, while one is in query,
6144 * add the freed counter to the other list based on the pool query_gen
6145 * value. After query finishes, add counter the list to the global
6146 * container counter list. The list changes while query starts. In
6147 * this case, lock will not be needed as query callback and release
6148 * function both operate with the different list.
6150 if (!priv->sh->cmng.counter_fallback) {
6151 rte_spinlock_lock(&pool->csl);
6152 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
6153 rte_spinlock_unlock(&pool->csl);
6155 cnt->dcs_when_free = cnt->dcs_when_active;
6156 cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
6157 MLX5_COUNTER_TYPE_ORIGIN;
6158 rte_spinlock_lock(&priv->sh->cmng.csl[cnt_type]);
6159 TAILQ_INSERT_TAIL(&priv->sh->cmng.counters[cnt_type],
6161 rte_spinlock_unlock(&priv->sh->cmng.csl[cnt_type]);
6166 * Resize a meter id container.
6169 * Pointer to the Ethernet device structure.
6172 * 0 on success, otherwise negative errno value and rte_errno is set.
6175 flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
6177 struct mlx5_priv *priv = dev->data->dev_private;
6178 struct mlx5_aso_mtr_pools_mng *pools_mng =
6179 &priv->sh->mtrmng->pools_mng;
6180 void *old_pools = pools_mng->pools;
6181 uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
6182 uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
6183 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
6190 if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER)) {
6195 memcpy(pools, old_pools, pools_mng->n *
6196 sizeof(struct mlx5_aso_mtr_pool *));
6197 pools_mng->n = resize;
6198 pools_mng->pools = pools;
6200 mlx5_free(old_pools);
6205 * Prepare a new meter and/or a new meter pool.
6208 * Pointer to the Ethernet device structure.
6209 * @param[out] mtr_free
6210 * Where to put the pointer of a new meter.g.
6213 * The meter pool pointer and @mtr_free is set on success,
6214 * NULL otherwise and rte_errno is set.
6216 static struct mlx5_aso_mtr_pool *
6217 flow_dv_mtr_pool_create(struct rte_eth_dev *dev,
6218 struct mlx5_aso_mtr **mtr_free)
6220 struct mlx5_priv *priv = dev->data->dev_private;
6221 struct mlx5_aso_mtr_pools_mng *pools_mng =
6222 &priv->sh->mtrmng->pools_mng;
6223 struct mlx5_aso_mtr_pool *pool = NULL;
6224 struct mlx5_devx_obj *dcs = NULL;
6226 uint32_t log_obj_size;
6228 log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
6229 dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->ctx,
6230 priv->sh->pdn, log_obj_size);
6232 rte_errno = ENODATA;
6235 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
6238 claim_zero(mlx5_devx_cmd_destroy(dcs));
6241 pool->devx_obj = dcs;
6242 pool->index = pools_mng->n_valid;
6243 if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
6245 claim_zero(mlx5_devx_cmd_destroy(dcs));
6248 pools_mng->pools[pool->index] = pool;
6249 pools_mng->n_valid++;
6250 for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
6251 pool->mtrs[i].offset = i;
6252 LIST_INSERT_HEAD(&pools_mng->meters,
6253 &pool->mtrs[i], next);
6255 pool->mtrs[0].offset = 0;
6256 *mtr_free = &pool->mtrs[0];
6261 * Release a flow meter into pool.
6264 * Pointer to the Ethernet device structure.
6265 * @param[in] mtr_idx
6266 * Index to aso flow meter.
6269 flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
6271 struct mlx5_priv *priv = dev->data->dev_private;
6272 struct mlx5_aso_mtr_pools_mng *pools_mng =
6273 &priv->sh->mtrmng->pools_mng;
6274 struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
6276 MLX5_ASSERT(aso_mtr);
6277 rte_spinlock_lock(&pools_mng->mtrsl);
6278 memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
6279 aso_mtr->state = ASO_METER_FREE;
6280 LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
6281 rte_spinlock_unlock(&pools_mng->mtrsl);
6285 * Allocate a aso flow meter.
6288 * Pointer to the Ethernet device structure.
6291 * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
6294 flow_dv_mtr_alloc(struct rte_eth_dev *dev)
6296 struct mlx5_priv *priv = dev->data->dev_private;
6297 struct mlx5_aso_mtr *mtr_free = NULL;
6298 struct mlx5_aso_mtr_pools_mng *pools_mng =
6299 &priv->sh->mtrmng->pools_mng;
6300 struct mlx5_aso_mtr_pool *pool;
6301 uint32_t mtr_idx = 0;
6303 if (!priv->config.devx) {
6304 rte_errno = ENOTSUP;
6307 /* Allocate the flow meter memory. */
6308 /* Get free meters from management. */
6309 rte_spinlock_lock(&pools_mng->mtrsl);
6310 mtr_free = LIST_FIRST(&pools_mng->meters);
6312 LIST_REMOVE(mtr_free, next);
6313 if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
6314 rte_spinlock_unlock(&pools_mng->mtrsl);
6317 mtr_free->state = ASO_METER_WAIT;
6318 rte_spinlock_unlock(&pools_mng->mtrsl);
6319 pool = container_of(mtr_free,
6320 struct mlx5_aso_mtr_pool,
6321 mtrs[mtr_free->offset]);
6322 mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
6323 if (!mtr_free->fm.meter_action) {
6324 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
6325 struct rte_flow_error error;
6328 reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
6329 mtr_free->fm.meter_action =
6330 mlx5_glue->dv_create_flow_action_aso
6331 (priv->sh->rx_domain,
6332 pool->devx_obj->obj,
6334 (1 << MLX5_FLOW_COLOR_GREEN),
6336 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
6337 if (!mtr_free->fm.meter_action) {
6338 flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
6346 * Verify the @p attributes will be correctly understood by the NIC and store
6347 * them in the @p flow if everything is correct.
6350 * Pointer to dev struct.
6351 * @param[in] attributes
6352 * Pointer to flow attributes
6353 * @param[in] external
6354 * This flow rule is created by request external to PMD.
6356 * Pointer to error structure.
6359 * - 0 on success and non root table.
6360 * - 1 on success and root table.
6361 * - a negative errno value otherwise and rte_errno is set.
6364 flow_dv_validate_attributes(struct rte_eth_dev *dev,
6365 const struct mlx5_flow_tunnel *tunnel,
6366 const struct rte_flow_attr *attributes,
6367 const struct flow_grp_info *grp_info,
6368 struct rte_flow_error *error)
6370 struct mlx5_priv *priv = dev->data->dev_private;
6371 uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
6374 #ifndef HAVE_MLX5DV_DR
6375 RTE_SET_USED(tunnel);
6376 RTE_SET_USED(grp_info);
6377 if (attributes->group)
6378 return rte_flow_error_set(error, ENOTSUP,
6379 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
6381 "groups are not supported");
6385 ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
6390 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
6392 if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
6393 attributes->priority > lowest_priority)
6394 return rte_flow_error_set(error, ENOTSUP,
6395 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
6397 "priority out of range");
6398 if (attributes->transfer) {
6399 if (!priv->config.dv_esw_en)
6400 return rte_flow_error_set
6402 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6403 "E-Switch dr is not supported");
6404 if (!(priv->representor || priv->master))
6405 return rte_flow_error_set
6406 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6407 NULL, "E-Switch configuration can only be"
6408 " done by a master or a representor device");
6409 if (attributes->egress)
6410 return rte_flow_error_set
6412 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
6413 "egress is not supported");
6415 if (!(attributes->egress ^ attributes->ingress))
6416 return rte_flow_error_set(error, ENOTSUP,
6417 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
6418 "must specify exactly one of "
6419 "ingress or egress");
6424 mlx5_flow_locate_proto_l3(const struct rte_flow_item **head,
6425 const struct rte_flow_item *end)
6427 const struct rte_flow_item *item = *head;
6428 uint16_t l3_protocol;
6430 for (; item != end; item++) {
6431 switch (item->type) {
6434 case RTE_FLOW_ITEM_TYPE_IPV4:
6435 l3_protocol = RTE_ETHER_TYPE_IPV4;
6437 case RTE_FLOW_ITEM_TYPE_IPV6:
6438 l3_protocol = RTE_ETHER_TYPE_IPV6;
6440 case RTE_FLOW_ITEM_TYPE_ETH:
6441 if (item->mask && item->spec) {
6442 MLX5_ETHER_TYPE_FROM_HEADER(rte_flow_item_eth,
6445 if (l3_protocol == RTE_ETHER_TYPE_IPV4 ||
6446 l3_protocol == RTE_ETHER_TYPE_IPV6)
6450 case RTE_FLOW_ITEM_TYPE_VLAN:
6451 if (item->mask && item->spec) {
6452 MLX5_ETHER_TYPE_FROM_HEADER(rte_flow_item_vlan,
6455 if (l3_protocol == RTE_ETHER_TYPE_IPV4 ||
6456 l3_protocol == RTE_ETHER_TYPE_IPV6)
6469 mlx5_flow_locate_proto_l4(const struct rte_flow_item **head,
6470 const struct rte_flow_item *end)
6472 const struct rte_flow_item *item = *head;
6473 uint8_t l4_protocol;
6475 for (; item != end; item++) {
6476 switch (item->type) {
6479 case RTE_FLOW_ITEM_TYPE_TCP:
6480 l4_protocol = IPPROTO_TCP;
6482 case RTE_FLOW_ITEM_TYPE_UDP:
6483 l4_protocol = IPPROTO_UDP;
6485 case RTE_FLOW_ITEM_TYPE_IPV4:
6486 if (item->mask && item->spec) {
6487 const struct rte_flow_item_ipv4 *mask, *spec;
6489 mask = (typeof(mask))item->mask;
6490 spec = (typeof(spec))item->spec;
6491 l4_protocol = mask->hdr.next_proto_id &
6492 spec->hdr.next_proto_id;
6493 if (l4_protocol == IPPROTO_TCP ||
6494 l4_protocol == IPPROTO_UDP)
6498 case RTE_FLOW_ITEM_TYPE_IPV6:
6499 if (item->mask && item->spec) {
6500 const struct rte_flow_item_ipv6 *mask, *spec;
6501 mask = (typeof(mask))item->mask;
6502 spec = (typeof(spec))item->spec;
6503 l4_protocol = mask->hdr.proto & spec->hdr.proto;
6504 if (l4_protocol == IPPROTO_TCP ||
6505 l4_protocol == IPPROTO_UDP)
6518 flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
6519 const struct rte_flow_item *rule_items,
6520 const struct rte_flow_item *integrity_item,
6521 struct rte_flow_error *error)
6523 struct mlx5_priv *priv = dev->data->dev_private;
6524 const struct rte_flow_item *tunnel_item, *end_item, *item = rule_items;
6525 const struct rte_flow_item_integrity *mask = (typeof(mask))
6526 integrity_item->mask;
6527 const struct rte_flow_item_integrity *spec = (typeof(spec))
6528 integrity_item->spec;
6531 if (!priv->config.hca_attr.pkt_integrity_match)
6532 return rte_flow_error_set(error, ENOTSUP,
6533 RTE_FLOW_ERROR_TYPE_ITEM,
6535 "packet integrity integrity_item not supported");
6537 mask = &rte_flow_item_integrity_mask;
6538 if (!mlx5_validate_integrity_item(mask))
6539 return rte_flow_error_set(error, ENOTSUP,
6540 RTE_FLOW_ERROR_TYPE_ITEM,
6542 "unsupported integrity filter");
6543 tunnel_item = mlx5_flow_find_tunnel_item(rule_items);
6544 if (spec->level > 1) {
6546 return rte_flow_error_set(error, ENOTSUP,
6547 RTE_FLOW_ERROR_TYPE_ITEM,
6549 "missing tunnel item");
6551 end_item = mlx5_find_end_item(tunnel_item);
6553 end_item = tunnel_item ? tunnel_item :
6554 mlx5_find_end_item(integrity_item);
6556 if (mask->l3_ok || mask->ipv4_csum_ok) {
6557 protocol = mlx5_flow_locate_proto_l3(&item, end_item);
6559 return rte_flow_error_set(error, EINVAL,
6560 RTE_FLOW_ERROR_TYPE_ITEM,
6562 "missing L3 protocol");
6564 if (mask->l4_ok || mask->l4_csum_ok) {
6565 protocol = mlx5_flow_locate_proto_l4(&item, end_item);
6567 return rte_flow_error_set(error, EINVAL,
6568 RTE_FLOW_ERROR_TYPE_ITEM,
6570 "missing L4 protocol");
6576 * Internal validation function. For validating both actions and items.
6579 * Pointer to the rte_eth_dev structure.
6581 * Pointer to the flow attributes.
6583 * Pointer to the list of items.
6584 * @param[in] actions
6585 * Pointer to the list of actions.
6586 * @param[in] external
6587 * This flow rule is created by request external to PMD.
6588 * @param[in] hairpin
6589 * Number of hairpin TX actions, 0 means classic flow.
6591 * Pointer to the error structure.
6594 * 0 on success, a negative errno value otherwise and rte_errno is set.
6597 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
6598 const struct rte_flow_item items[],
6599 const struct rte_flow_action actions[],
6600 bool external, int hairpin, struct rte_flow_error *error)
6603 uint64_t action_flags = 0;
6604 uint64_t item_flags = 0;
6605 uint64_t last_item = 0;
6606 uint8_t next_protocol = 0xff;
6607 uint16_t ether_type = 0;
6609 uint8_t item_ipv6_proto = 0;
6610 int fdb_mirror_limit = 0;
6611 int modify_after_mirror = 0;
6612 const struct rte_flow_item *geneve_item = NULL;
6613 const struct rte_flow_item *gre_item = NULL;
6614 const struct rte_flow_item *gtp_item = NULL;
6615 const struct rte_flow_action_raw_decap *decap;
6616 const struct rte_flow_action_raw_encap *encap;
6617 const struct rte_flow_action_rss *rss = NULL;
6618 const struct rte_flow_action_rss *sample_rss = NULL;
6619 const struct rte_flow_action_count *sample_count = NULL;
6620 const struct rte_flow_item_tcp nic_tcp_mask = {
6623 .src_port = RTE_BE16(UINT16_MAX),
6624 .dst_port = RTE_BE16(UINT16_MAX),
6627 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
6630 "\xff\xff\xff\xff\xff\xff\xff\xff"
6631 "\xff\xff\xff\xff\xff\xff\xff\xff",
6633 "\xff\xff\xff\xff\xff\xff\xff\xff"
6634 "\xff\xff\xff\xff\xff\xff\xff\xff",
6635 .vtc_flow = RTE_BE32(0xffffffff),
6641 const struct rte_flow_item_ecpri nic_ecpri_mask = {
6645 RTE_BE32(((const struct rte_ecpri_common_hdr) {
6649 .dummy[0] = 0xffffffff,
6652 struct mlx5_priv *priv = dev->data->dev_private;
6653 struct mlx5_dev_config *dev_conf = &priv->config;
6654 uint16_t queue_index = 0xFFFF;
6655 const struct rte_flow_item_vlan *vlan_m = NULL;
6656 uint32_t rw_act_num = 0;
6658 const struct mlx5_flow_tunnel *tunnel;
6659 enum mlx5_tof_rule_type tof_rule_type;
6660 struct flow_grp_info grp_info = {
6661 .external = !!external,
6662 .transfer = !!attr->transfer,
6663 .fdb_def_rule = !!priv->fdb_def_rule,
6664 .std_tbl_fix = true,
6666 const struct rte_eth_hairpin_conf *conf;
6667 const struct rte_flow_item *rule_items = items;
6668 bool def_policy = false;
6672 tunnel = is_tunnel_offload_active(dev) ?
6673 mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
6675 if (priv->representor)
6676 return rte_flow_error_set
6678 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6679 NULL, "decap not supported for VF representor");
6680 if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
6681 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6682 else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
6683 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
6684 MLX5_FLOW_ACTION_DECAP;
6685 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
6686 (dev, attr, tunnel, tof_rule_type);
6688 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
6691 is_root = (uint64_t)ret;
6692 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6693 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
6694 int type = items->type;
6696 if (!mlx5_flow_os_item_supported(type))
6697 return rte_flow_error_set(error, ENOTSUP,
6698 RTE_FLOW_ERROR_TYPE_ITEM,
6699 NULL, "item not supported");
6701 case RTE_FLOW_ITEM_TYPE_VOID:
6703 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6704 ret = flow_dv_validate_item_port_id
6705 (dev, items, attr, item_flags, error);
6708 last_item = MLX5_FLOW_ITEM_PORT_ID;
6710 case RTE_FLOW_ITEM_TYPE_ETH:
6711 ret = mlx5_flow_validate_item_eth(items, item_flags,
6715 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
6716 MLX5_FLOW_LAYER_OUTER_L2;
6717 if (items->mask != NULL && items->spec != NULL) {
6719 ((const struct rte_flow_item_eth *)
6722 ((const struct rte_flow_item_eth *)
6724 ether_type = rte_be_to_cpu_16(ether_type);
6729 case RTE_FLOW_ITEM_TYPE_VLAN:
6730 ret = flow_dv_validate_item_vlan(items, item_flags,
6734 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
6735 MLX5_FLOW_LAYER_OUTER_VLAN;
6736 if (items->mask != NULL && items->spec != NULL) {
6738 ((const struct rte_flow_item_vlan *)
6739 items->spec)->inner_type;
6741 ((const struct rte_flow_item_vlan *)
6742 items->mask)->inner_type;
6743 ether_type = rte_be_to_cpu_16(ether_type);
6747 /* Store outer VLAN mask for of_push_vlan action. */
6749 vlan_m = items->mask;
6751 case RTE_FLOW_ITEM_TYPE_IPV4:
6752 mlx5_flow_tunnel_ip_check(items, next_protocol,
6753 &item_flags, &tunnel);
6754 ret = flow_dv_validate_item_ipv4(items, item_flags,
6755 last_item, ether_type,
6759 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
6760 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
6761 if (items->mask != NULL &&
6762 ((const struct rte_flow_item_ipv4 *)
6763 items->mask)->hdr.next_proto_id) {
6765 ((const struct rte_flow_item_ipv4 *)
6766 (items->spec))->hdr.next_proto_id;
6768 ((const struct rte_flow_item_ipv4 *)
6769 (items->mask))->hdr.next_proto_id;
6771 /* Reset for inner layer. */
6772 next_protocol = 0xff;
6775 case RTE_FLOW_ITEM_TYPE_IPV6:
6776 mlx5_flow_tunnel_ip_check(items, next_protocol,
6777 &item_flags, &tunnel);
6778 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
6785 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
6786 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
6787 if (items->mask != NULL &&
6788 ((const struct rte_flow_item_ipv6 *)
6789 items->mask)->hdr.proto) {
6791 ((const struct rte_flow_item_ipv6 *)
6792 items->spec)->hdr.proto;
6794 ((const struct rte_flow_item_ipv6 *)
6795 items->spec)->hdr.proto;
6797 ((const struct rte_flow_item_ipv6 *)
6798 items->mask)->hdr.proto;
6800 /* Reset for inner layer. */
6801 next_protocol = 0xff;
6804 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
6805 ret = flow_dv_validate_item_ipv6_frag_ext(items,
6810 last_item = tunnel ?
6811 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
6812 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
6813 if (items->mask != NULL &&
6814 ((const struct rte_flow_item_ipv6_frag_ext *)
6815 items->mask)->hdr.next_header) {
6817 ((const struct rte_flow_item_ipv6_frag_ext *)
6818 items->spec)->hdr.next_header;
6820 ((const struct rte_flow_item_ipv6_frag_ext *)
6821 items->mask)->hdr.next_header;
6823 /* Reset for inner layer. */
6824 next_protocol = 0xff;
6827 case RTE_FLOW_ITEM_TYPE_TCP:
6828 ret = mlx5_flow_validate_item_tcp
6835 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
6836 MLX5_FLOW_LAYER_OUTER_L4_TCP;
6838 case RTE_FLOW_ITEM_TYPE_UDP:
6839 ret = mlx5_flow_validate_item_udp(items, item_flags,
6844 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
6845 MLX5_FLOW_LAYER_OUTER_L4_UDP;
6847 case RTE_FLOW_ITEM_TYPE_GRE:
6848 ret = mlx5_flow_validate_item_gre(items, item_flags,
6849 next_protocol, error);
6853 last_item = MLX5_FLOW_LAYER_GRE;
6855 case RTE_FLOW_ITEM_TYPE_NVGRE:
6856 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
6861 last_item = MLX5_FLOW_LAYER_NVGRE;
6863 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6864 ret = mlx5_flow_validate_item_gre_key
6865 (items, item_flags, gre_item, error);
6868 last_item = MLX5_FLOW_LAYER_GRE_KEY;
6870 case RTE_FLOW_ITEM_TYPE_VXLAN:
6871 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
6875 last_item = MLX5_FLOW_LAYER_VXLAN;
6877 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6878 ret = mlx5_flow_validate_item_vxlan_gpe(items,
6883 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
6885 case RTE_FLOW_ITEM_TYPE_GENEVE:
6886 ret = mlx5_flow_validate_item_geneve(items,
6891 geneve_item = items;
6892 last_item = MLX5_FLOW_LAYER_GENEVE;
6894 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
6895 ret = mlx5_flow_validate_item_geneve_opt(items,
6902 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
6904 case RTE_FLOW_ITEM_TYPE_MPLS:
6905 ret = mlx5_flow_validate_item_mpls(dev, items,
6910 last_item = MLX5_FLOW_LAYER_MPLS;
6913 case RTE_FLOW_ITEM_TYPE_MARK:
6914 ret = flow_dv_validate_item_mark(dev, items, attr,
6918 last_item = MLX5_FLOW_ITEM_MARK;
6920 case RTE_FLOW_ITEM_TYPE_META:
6921 ret = flow_dv_validate_item_meta(dev, items, attr,
6925 last_item = MLX5_FLOW_ITEM_METADATA;
6927 case RTE_FLOW_ITEM_TYPE_ICMP:
6928 ret = mlx5_flow_validate_item_icmp(items, item_flags,
6933 last_item = MLX5_FLOW_LAYER_ICMP;
6935 case RTE_FLOW_ITEM_TYPE_ICMP6:
6936 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
6941 item_ipv6_proto = IPPROTO_ICMPV6;
6942 last_item = MLX5_FLOW_LAYER_ICMP6;
6944 case RTE_FLOW_ITEM_TYPE_TAG:
6945 ret = flow_dv_validate_item_tag(dev, items,
6949 last_item = MLX5_FLOW_ITEM_TAG;
6951 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
6952 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
6954 case RTE_FLOW_ITEM_TYPE_GTP:
6955 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
6960 last_item = MLX5_FLOW_LAYER_GTP;
6962 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6963 ret = flow_dv_validate_item_gtp_psc(items, last_item,
6968 last_item = MLX5_FLOW_LAYER_GTP_PSC;
6970 case RTE_FLOW_ITEM_TYPE_ECPRI:
6971 /* Capacity will be checked in the translate stage. */
6972 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
6979 last_item = MLX5_FLOW_LAYER_ECPRI;
6981 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
6982 if (item_flags & MLX5_FLOW_ITEM_INTEGRITY)
6983 return rte_flow_error_set
6985 RTE_FLOW_ERROR_TYPE_ITEM,
6986 NULL, "multiple integrity items not supported");
6987 ret = flow_dv_validate_item_integrity(dev, rule_items,
6991 last_item = MLX5_FLOW_ITEM_INTEGRITY;
6993 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
6994 ret = flow_dv_validate_item_aso_ct(dev, items,
6995 &item_flags, error);
6999 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
7000 /* tunnel offload item was processed before
7001 * list it here as a supported type
7005 return rte_flow_error_set(error, ENOTSUP,
7006 RTE_FLOW_ERROR_TYPE_ITEM,
7007 NULL, "item not supported");
7009 item_flags |= last_item;
7011 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
7012 int type = actions->type;
7013 bool shared_count = false;
7015 if (!mlx5_flow_os_action_supported(type))
7016 return rte_flow_error_set(error, ENOTSUP,
7017 RTE_FLOW_ERROR_TYPE_ACTION,
7019 "action not supported");
7020 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
7021 return rte_flow_error_set(error, ENOTSUP,
7022 RTE_FLOW_ERROR_TYPE_ACTION,
7023 actions, "too many actions");
7025 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
7026 return rte_flow_error_set(error, ENOTSUP,
7027 RTE_FLOW_ERROR_TYPE_ACTION,
7028 NULL, "meter action with policy "
7029 "must be the last action");
7031 case RTE_FLOW_ACTION_TYPE_VOID:
7033 case RTE_FLOW_ACTION_TYPE_PORT_ID:
7034 ret = flow_dv_validate_action_port_id(dev,
7041 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
7044 case RTE_FLOW_ACTION_TYPE_FLAG:
7045 ret = flow_dv_validate_action_flag(dev, action_flags,
7049 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7050 /* Count all modify-header actions as one. */
7051 if (!(action_flags &
7052 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7054 action_flags |= MLX5_FLOW_ACTION_FLAG |
7055 MLX5_FLOW_ACTION_MARK_EXT;
7056 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7057 modify_after_mirror = 1;
7060 action_flags |= MLX5_FLOW_ACTION_FLAG;
7063 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7065 case RTE_FLOW_ACTION_TYPE_MARK:
7066 ret = flow_dv_validate_action_mark(dev, actions,
7071 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
7072 /* Count all modify-header actions as one. */
7073 if (!(action_flags &
7074 MLX5_FLOW_MODIFY_HDR_ACTIONS))
7076 action_flags |= MLX5_FLOW_ACTION_MARK |
7077 MLX5_FLOW_ACTION_MARK_EXT;
7078 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7079 modify_after_mirror = 1;
7081 action_flags |= MLX5_FLOW_ACTION_MARK;
7084 rw_act_num += MLX5_ACT_NUM_SET_MARK;
7086 case RTE_FLOW_ACTION_TYPE_SET_META:
7087 ret = flow_dv_validate_action_set_meta(dev, actions,
7092 /* Count all modify-header actions as one action. */
7093 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7095 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7096 modify_after_mirror = 1;
7097 action_flags |= MLX5_FLOW_ACTION_SET_META;
7098 rw_act_num += MLX5_ACT_NUM_SET_META;
7100 case RTE_FLOW_ACTION_TYPE_SET_TAG:
7101 ret = flow_dv_validate_action_set_tag(dev, actions,
7106 /* Count all modify-header actions as one action. */
7107 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7109 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7110 modify_after_mirror = 1;
7111 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
7112 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7114 case RTE_FLOW_ACTION_TYPE_DROP:
7115 ret = mlx5_flow_validate_action_drop(action_flags,
7119 action_flags |= MLX5_FLOW_ACTION_DROP;
7122 case RTE_FLOW_ACTION_TYPE_QUEUE:
7123 ret = mlx5_flow_validate_action_queue(actions,
7128 queue_index = ((const struct rte_flow_action_queue *)
7129 (actions->conf))->index;
7130 action_flags |= MLX5_FLOW_ACTION_QUEUE;
7133 case RTE_FLOW_ACTION_TYPE_RSS:
7134 rss = actions->conf;
7135 ret = mlx5_flow_validate_action_rss(actions,
7141 if (rss && sample_rss &&
7142 (sample_rss->level != rss->level ||
7143 sample_rss->types != rss->types))
7144 return rte_flow_error_set(error, ENOTSUP,
7145 RTE_FLOW_ERROR_TYPE_ACTION,
7147 "Can't use the different RSS types "
7148 "or level in the same flow");
7149 if (rss != NULL && rss->queue_num)
7150 queue_index = rss->queue[0];
7151 action_flags |= MLX5_FLOW_ACTION_RSS;
7154 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
7156 mlx5_flow_validate_action_default_miss(action_flags,
7160 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
7163 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
7164 case RTE_FLOW_ACTION_TYPE_COUNT:
7165 shared_count = is_shared_action_count(actions);
7166 ret = flow_dv_validate_action_count(dev, shared_count,
7171 action_flags |= MLX5_FLOW_ACTION_COUNT;
7174 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
7175 if (flow_dv_validate_action_pop_vlan(dev,
7181 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7182 modify_after_mirror = 1;
7183 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
7186 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
7187 ret = flow_dv_validate_action_push_vlan(dev,
7194 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7195 modify_after_mirror = 1;
7196 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
7199 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
7200 ret = flow_dv_validate_action_set_vlan_pcp
7201 (action_flags, actions, error);
7204 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7205 modify_after_mirror = 1;
7206 /* Count PCP with push_vlan command. */
7207 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
7209 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
7210 ret = flow_dv_validate_action_set_vlan_vid
7211 (item_flags, action_flags,
7215 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7216 modify_after_mirror = 1;
7217 /* Count VID with push_vlan command. */
7218 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
7219 rw_act_num += MLX5_ACT_NUM_MDF_VID;
7221 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
7222 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
7223 ret = flow_dv_validate_action_l2_encap(dev,
7229 action_flags |= MLX5_FLOW_ACTION_ENCAP;
7232 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
7233 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
7234 ret = flow_dv_validate_action_decap(dev, action_flags,
7235 actions, item_flags,
7239 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7240 modify_after_mirror = 1;
7241 action_flags |= MLX5_FLOW_ACTION_DECAP;
7244 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
7245 ret = flow_dv_validate_action_raw_encap_decap
7246 (dev, NULL, actions->conf, attr, &action_flags,
7247 &actions_n, actions, item_flags, error);
7251 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
7252 decap = actions->conf;
7253 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
7255 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
7259 encap = actions->conf;
7261 ret = flow_dv_validate_action_raw_encap_decap
7263 decap ? decap : &empty_decap, encap,
7264 attr, &action_flags, &actions_n,
7265 actions, item_flags, error);
7268 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7269 (action_flags & MLX5_FLOW_ACTION_DECAP))
7270 modify_after_mirror = 1;
7272 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
7273 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
7274 ret = flow_dv_validate_action_modify_mac(action_flags,
7280 /* Count all modify-header actions as one action. */
7281 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7283 action_flags |= actions->type ==
7284 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
7285 MLX5_FLOW_ACTION_SET_MAC_SRC :
7286 MLX5_FLOW_ACTION_SET_MAC_DST;
7287 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7288 modify_after_mirror = 1;
7290 * Even if the source and destination MAC addresses have
7291 * overlap in the header with 4B alignment, the convert
7292 * function will handle them separately and 4 SW actions
7293 * will be created. And 2 actions will be added each
7294 * time no matter how many bytes of address will be set.
7296 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
7298 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
7299 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
7300 ret = flow_dv_validate_action_modify_ipv4(action_flags,
7306 /* Count all modify-header actions as one action. */
7307 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7309 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7310 modify_after_mirror = 1;
7311 action_flags |= actions->type ==
7312 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
7313 MLX5_FLOW_ACTION_SET_IPV4_SRC :
7314 MLX5_FLOW_ACTION_SET_IPV4_DST;
7315 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
7317 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
7318 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
7319 ret = flow_dv_validate_action_modify_ipv6(action_flags,
7325 if (item_ipv6_proto == IPPROTO_ICMPV6)
7326 return rte_flow_error_set(error, ENOTSUP,
7327 RTE_FLOW_ERROR_TYPE_ACTION,
7329 "Can't change header "
7330 "with ICMPv6 proto");
7331 /* Count all modify-header actions as one action. */
7332 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7334 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7335 modify_after_mirror = 1;
7336 action_flags |= actions->type ==
7337 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
7338 MLX5_FLOW_ACTION_SET_IPV6_SRC :
7339 MLX5_FLOW_ACTION_SET_IPV6_DST;
7340 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
7342 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
7343 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
7344 ret = flow_dv_validate_action_modify_tp(action_flags,
7350 /* Count all modify-header actions as one action. */
7351 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7353 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7354 modify_after_mirror = 1;
7355 action_flags |= actions->type ==
7356 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
7357 MLX5_FLOW_ACTION_SET_TP_SRC :
7358 MLX5_FLOW_ACTION_SET_TP_DST;
7359 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
7361 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
7362 case RTE_FLOW_ACTION_TYPE_SET_TTL:
7363 ret = flow_dv_validate_action_modify_ttl(action_flags,
7369 /* Count all modify-header actions as one action. */
7370 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7372 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7373 modify_after_mirror = 1;
7374 action_flags |= actions->type ==
7375 RTE_FLOW_ACTION_TYPE_SET_TTL ?
7376 MLX5_FLOW_ACTION_SET_TTL :
7377 MLX5_FLOW_ACTION_DEC_TTL;
7378 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
7380 case RTE_FLOW_ACTION_TYPE_JUMP:
7381 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
7387 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
7389 return rte_flow_error_set(error, EINVAL,
7390 RTE_FLOW_ERROR_TYPE_ACTION,
7392 "sample and jump action combination is not supported");
7394 action_flags |= MLX5_FLOW_ACTION_JUMP;
7396 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
7397 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
7398 ret = flow_dv_validate_action_modify_tcp_seq
7405 /* Count all modify-header actions as one action. */
7406 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7408 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7409 modify_after_mirror = 1;
7410 action_flags |= actions->type ==
7411 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
7412 MLX5_FLOW_ACTION_INC_TCP_SEQ :
7413 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
7414 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
7416 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
7417 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
7418 ret = flow_dv_validate_action_modify_tcp_ack
7425 /* Count all modify-header actions as one action. */
7426 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7428 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7429 modify_after_mirror = 1;
7430 action_flags |= actions->type ==
7431 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
7432 MLX5_FLOW_ACTION_INC_TCP_ACK :
7433 MLX5_FLOW_ACTION_DEC_TCP_ACK;
7434 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
7436 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
7438 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
7439 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
7440 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7442 case RTE_FLOW_ACTION_TYPE_METER:
7443 ret = mlx5_flow_validate_action_meter(dev,
7450 action_flags |= MLX5_FLOW_ACTION_METER;
7453 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
7455 /* Meter action will add one more TAG action. */
7456 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7458 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
7459 if (!attr->transfer && !attr->group)
7460 return rte_flow_error_set(error, ENOTSUP,
7461 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7463 "Shared ASO age action is not supported for group 0");
7464 if (action_flags & MLX5_FLOW_ACTION_AGE)
7465 return rte_flow_error_set
7467 RTE_FLOW_ERROR_TYPE_ACTION,
7469 "duplicate age actions set");
7470 action_flags |= MLX5_FLOW_ACTION_AGE;
7473 case RTE_FLOW_ACTION_TYPE_AGE:
7474 ret = flow_dv_validate_action_age(action_flags,
7480 * Validate the regular AGE action (using counter)
7481 * mutual exclusion with share counter actions.
7483 if (!priv->sh->flow_hit_aso_en) {
7485 return rte_flow_error_set
7487 RTE_FLOW_ERROR_TYPE_ACTION,
7489 "old age and shared count combination is not supported");
7491 return rte_flow_error_set
7493 RTE_FLOW_ERROR_TYPE_ACTION,
7495 "old age action and count must be in the same sub flow");
7497 action_flags |= MLX5_FLOW_ACTION_AGE;
7500 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
7501 ret = flow_dv_validate_action_modify_ipv4_dscp
7508 /* Count all modify-header actions as one action. */
7509 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7511 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7512 modify_after_mirror = 1;
7513 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
7514 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7516 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
7517 ret = flow_dv_validate_action_modify_ipv6_dscp
7524 /* Count all modify-header actions as one action. */
7525 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
7527 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7528 modify_after_mirror = 1;
7529 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
7530 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
7532 case RTE_FLOW_ACTION_TYPE_SAMPLE:
7533 ret = flow_dv_validate_action_sample(&action_flags,
7542 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
7545 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
7546 ret = flow_dv_validate_action_modify_field(dev,
7553 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
7554 modify_after_mirror = 1;
7555 /* Count all modify-header actions as one action. */
7556 if (!(action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD))
7558 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
7561 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
7562 ret = flow_dv_validate_action_aso_ct(dev, action_flags,
7567 action_flags |= MLX5_FLOW_ACTION_CT;
7569 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
7570 /* tunnel offload action was processed before
7571 * list it here as a supported type
7575 return rte_flow_error_set(error, ENOTSUP,
7576 RTE_FLOW_ERROR_TYPE_ACTION,
7578 "action not supported");
7582 * Validate actions in flow rules
7583 * - Explicit decap action is prohibited by the tunnel offload API.
7584 * - Drop action in tunnel steer rule is prohibited by the API.
7585 * - Application cannot use MARK action because it's value can mask
7586 * tunnel default miss nitification.
7587 * - JUMP in tunnel match rule has no support in current PMD
7589 * - TAG & META are reserved for future uses.
7591 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
7592 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
7593 MLX5_FLOW_ACTION_MARK |
7594 MLX5_FLOW_ACTION_SET_TAG |
7595 MLX5_FLOW_ACTION_SET_META |
7596 MLX5_FLOW_ACTION_DROP;
7598 if (action_flags & bad_actions_mask)
7599 return rte_flow_error_set
7601 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7602 "Invalid RTE action in tunnel "
7604 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
7605 return rte_flow_error_set
7607 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7608 "tunnel set decap rule must terminate "
7611 return rte_flow_error_set
7613 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7614 "tunnel flows for ingress traffic only");
7616 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
7617 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
7618 MLX5_FLOW_ACTION_MARK |
7619 MLX5_FLOW_ACTION_SET_TAG |
7620 MLX5_FLOW_ACTION_SET_META;
7622 if (action_flags & bad_actions_mask)
7623 return rte_flow_error_set
7625 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7626 "Invalid RTE action in tunnel "
7630 * Validate the drop action mutual exclusion with other actions.
7631 * Drop action is mutually-exclusive with any other action, except for
7633 * Drop action compatibility with tunnel offload was already validated.
7635 if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
7636 MLX5_FLOW_ACTION_TUNNEL_MATCH));
7637 else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
7638 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
7639 return rte_flow_error_set(error, EINVAL,
7640 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7641 "Drop action is mutually-exclusive "
7642 "with any other action, except for "
7644 /* Eswitch has few restrictions on using items and actions */
7645 if (attr->transfer) {
7646 if (!mlx5_flow_ext_mreg_supported(dev) &&
7647 action_flags & MLX5_FLOW_ACTION_FLAG)
7648 return rte_flow_error_set(error, ENOTSUP,
7649 RTE_FLOW_ERROR_TYPE_ACTION,
7651 "unsupported action FLAG");
7652 if (!mlx5_flow_ext_mreg_supported(dev) &&
7653 action_flags & MLX5_FLOW_ACTION_MARK)
7654 return rte_flow_error_set(error, ENOTSUP,
7655 RTE_FLOW_ERROR_TYPE_ACTION,
7657 "unsupported action MARK");
7658 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
7659 return rte_flow_error_set(error, ENOTSUP,
7660 RTE_FLOW_ERROR_TYPE_ACTION,
7662 "unsupported action QUEUE");
7663 if (action_flags & MLX5_FLOW_ACTION_RSS)
7664 return rte_flow_error_set(error, ENOTSUP,
7665 RTE_FLOW_ERROR_TYPE_ACTION,
7667 "unsupported action RSS");
7668 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
7669 return rte_flow_error_set(error, EINVAL,
7670 RTE_FLOW_ERROR_TYPE_ACTION,
7672 "no fate action is found");
7674 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
7675 return rte_flow_error_set(error, EINVAL,
7676 RTE_FLOW_ERROR_TYPE_ACTION,
7678 "no fate action is found");
7681 * Continue validation for Xcap and VLAN actions.
7682 * If hairpin is working in explicit TX rule mode, there is no actions
7683 * splitting and the validation of hairpin ingress flow should be the
7684 * same as other standard flows.
7686 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
7687 MLX5_FLOW_VLAN_ACTIONS)) &&
7688 (queue_index == 0xFFFF ||
7689 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN ||
7690 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
7691 conf->tx_explicit != 0))) {
7692 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
7693 MLX5_FLOW_XCAP_ACTIONS)
7694 return rte_flow_error_set(error, ENOTSUP,
7695 RTE_FLOW_ERROR_TYPE_ACTION,
7696 NULL, "encap and decap "
7697 "combination aren't supported");
7698 if (!attr->transfer && attr->ingress) {
7699 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7700 return rte_flow_error_set
7702 RTE_FLOW_ERROR_TYPE_ACTION,
7703 NULL, "encap is not supported"
7704 " for ingress traffic");
7705 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7706 return rte_flow_error_set
7708 RTE_FLOW_ERROR_TYPE_ACTION,
7709 NULL, "push VLAN action not "
7710 "supported for ingress");
7711 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
7712 MLX5_FLOW_VLAN_ACTIONS)
7713 return rte_flow_error_set
7715 RTE_FLOW_ERROR_TYPE_ACTION,
7716 NULL, "no support for "
7717 "multiple VLAN actions");
7720 if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
7721 if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
7722 ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
7724 return rte_flow_error_set
7726 RTE_FLOW_ERROR_TYPE_ACTION,
7727 NULL, "fate action not supported for "
7728 "meter with policy");
7730 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
7731 return rte_flow_error_set
7733 RTE_FLOW_ERROR_TYPE_ACTION,
7734 NULL, "modify header action in egress "
7735 "cannot be done before meter action");
7736 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
7737 return rte_flow_error_set
7739 RTE_FLOW_ERROR_TYPE_ACTION,
7740 NULL, "encap action in egress "
7741 "cannot be done before meter action");
7742 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
7743 return rte_flow_error_set
7745 RTE_FLOW_ERROR_TYPE_ACTION,
7746 NULL, "push vlan action in egress "
7747 "cannot be done before meter action");
7751 * Hairpin flow will add one more TAG action in TX implicit mode.
7752 * In TX explicit mode, there will be no hairpin flow ID.
7755 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7756 /* extra metadata enabled: one more TAG action will be add. */
7757 if (dev_conf->dv_flow_en &&
7758 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
7759 mlx5_flow_ext_mreg_supported(dev))
7760 rw_act_num += MLX5_ACT_NUM_SET_TAG;
7762 flow_dv_modify_hdr_action_max(dev, is_root)) {
7763 return rte_flow_error_set(error, ENOTSUP,
7764 RTE_FLOW_ERROR_TYPE_ACTION,
7765 NULL, "too many header modify"
7766 " actions to support");
7768 /* Eswitch egress mirror and modify flow has limitation on CX5 */
7769 if (fdb_mirror_limit && modify_after_mirror)
7770 return rte_flow_error_set(error, EINVAL,
7771 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
7772 "sample before modify action is not supported");
7777 * Internal preparation function. Allocates the DV flow size,
7778 * this size is constant.
7781 * Pointer to the rte_eth_dev structure.
7783 * Pointer to the flow attributes.
7785 * Pointer to the list of items.
7786 * @param[in] actions
7787 * Pointer to the list of actions.
7789 * Pointer to the error structure.
7792 * Pointer to mlx5_flow object on success,
7793 * otherwise NULL and rte_errno is set.
7795 static struct mlx5_flow *
7796 flow_dv_prepare(struct rte_eth_dev *dev,
7797 const struct rte_flow_attr *attr __rte_unused,
7798 const struct rte_flow_item items[] __rte_unused,
7799 const struct rte_flow_action actions[] __rte_unused,
7800 struct rte_flow_error *error)
7802 uint32_t handle_idx = 0;
7803 struct mlx5_flow *dev_flow;
7804 struct mlx5_flow_handle *dev_handle;
7805 struct mlx5_priv *priv = dev->data->dev_private;
7806 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
7809 wks->skip_matcher_reg = 0;
7810 /* In case of corrupting the memory. */
7811 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
7812 rte_flow_error_set(error, ENOSPC,
7813 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7814 "not free temporary device flow");
7817 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
7820 rte_flow_error_set(error, ENOMEM,
7821 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7822 "not enough memory to create flow handle");
7825 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
7826 dev_flow = &wks->flows[wks->flow_idx++];
7827 memset(dev_flow, 0, sizeof(*dev_flow));
7828 dev_flow->handle = dev_handle;
7829 dev_flow->handle_idx = handle_idx;
7831 * In some old rdma-core releases, before continuing, a check of the
7832 * length of matching parameter will be done at first. It needs to use
7833 * the length without misc4 param. If the flow has misc4 support, then
7834 * the length needs to be adjusted accordingly. Each param member is
7835 * aligned with a 64B boundary naturally.
7837 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param) -
7838 MLX5_ST_SZ_BYTES(fte_match_set_misc4);
7839 dev_flow->ingress = attr->ingress;
7840 dev_flow->dv.transfer = attr->transfer;
7844 #ifdef RTE_LIBRTE_MLX5_DEBUG
7846 * Sanity check for match mask and value. Similar to check_valid_spec() in
7847 * kernel driver. If unmasked bit is present in value, it returns failure.
7850 * pointer to match mask buffer.
7851 * @param match_value
7852 * pointer to match value buffer.
7855 * 0 if valid, -EINVAL otherwise.
7858 flow_dv_check_valid_spec(void *match_mask, void *match_value)
7860 uint8_t *m = match_mask;
7861 uint8_t *v = match_value;
7864 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
7867 "match_value differs from match_criteria"
7868 " %p[%u] != %p[%u]",
7869 match_value, i, match_mask, i);
7878 * Add match of ip_version.
7882 * @param[in] headers_v
7883 * Values header pointer.
7884 * @param[in] headers_m
7885 * Masks header pointer.
7886 * @param[in] ip_version
7887 * The IP version to set.
7890 flow_dv_set_match_ip_version(uint32_t group,
7896 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
7898 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
7900 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
7901 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
7902 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
7906 * Add Ethernet item to matcher and to the value.
7908 * @param[in, out] matcher
7910 * @param[in, out] key
7911 * Flow matcher value.
7913 * Flow pattern to translate.
7915 * Item is inner pattern.
7918 flow_dv_translate_item_eth(void *matcher, void *key,
7919 const struct rte_flow_item *item, int inner,
7922 const struct rte_flow_item_eth *eth_m = item->mask;
7923 const struct rte_flow_item_eth *eth_v = item->spec;
7924 const struct rte_flow_item_eth nic_mask = {
7925 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
7926 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
7927 .type = RTE_BE16(0xffff),
7940 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
7942 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7944 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
7946 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7948 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
7949 ð_m->dst, sizeof(eth_m->dst));
7950 /* The value must be in the range of the mask. */
7951 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
7952 for (i = 0; i < sizeof(eth_m->dst); ++i)
7953 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
7954 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
7955 ð_m->src, sizeof(eth_m->src));
7956 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
7957 /* The value must be in the range of the mask. */
7958 for (i = 0; i < sizeof(eth_m->dst); ++i)
7959 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
7961 * HW supports match on one Ethertype, the Ethertype following the last
7962 * VLAN tag of the packet (see PRM).
7963 * Set match on ethertype only if ETH header is not followed by VLAN.
7964 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
7965 * ethertype, and use ip_version field instead.
7966 * eCPRI over Ether layer will use type value 0xAEFE.
7968 if (eth_m->type == 0xFFFF) {
7969 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
7970 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
7971 switch (eth_v->type) {
7972 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
7973 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
7975 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
7976 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
7977 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
7979 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
7980 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
7982 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
7983 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
7989 if (eth_m->has_vlan) {
7990 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
7991 if (eth_v->has_vlan) {
7993 * Here, when also has_more_vlan field in VLAN item is
7994 * not set, only single-tagged packets will be matched.
7996 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8000 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8001 rte_be_to_cpu_16(eth_m->type));
8002 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
8003 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
8007 * Add VLAN item to matcher and to the value.
8009 * @param[in, out] dev_flow
8011 * @param[in, out] matcher
8013 * @param[in, out] key
8014 * Flow matcher value.
8016 * Flow pattern to translate.
8018 * Item is inner pattern.
8021 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
8022 void *matcher, void *key,
8023 const struct rte_flow_item *item,
8024 int inner, uint32_t group)
8026 const struct rte_flow_item_vlan *vlan_m = item->mask;
8027 const struct rte_flow_item_vlan *vlan_v = item->spec;
8034 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8036 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8038 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
8040 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8042 * This is workaround, masks are not supported,
8043 * and pre-validated.
8046 dev_flow->handle->vf_vlan.tag =
8047 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
8050 * When VLAN item exists in flow, mark packet as tagged,
8051 * even if TCI is not specified.
8053 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
8054 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
8055 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
8060 vlan_m = &rte_flow_item_vlan_mask;
8061 tci_m = rte_be_to_cpu_16(vlan_m->tci);
8062 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
8063 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
8064 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
8065 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
8066 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
8067 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
8068 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
8070 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
8071 * ethertype, and use ip_version field instead.
8073 if (vlan_m->inner_type == 0xFFFF) {
8074 switch (vlan_v->inner_type) {
8075 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
8076 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8077 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8078 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8080 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
8081 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
8083 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
8084 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
8090 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
8091 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
8092 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
8093 /* Only one vlan_tag bit can be set. */
8094 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
8097 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
8098 rte_be_to_cpu_16(vlan_m->inner_type));
8099 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
8100 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
8104 * Add IPV4 item to matcher and to the value.
8106 * @param[in, out] matcher
8108 * @param[in, out] key
8109 * Flow matcher value.
8111 * Flow pattern to translate.
8113 * Item is inner pattern.
8115 * The group to insert the rule.
8118 flow_dv_translate_item_ipv4(void *matcher, void *key,
8119 const struct rte_flow_item *item,
8120 int inner, uint32_t group)
8122 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
8123 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
8124 const struct rte_flow_item_ipv4 nic_mask = {
8126 .src_addr = RTE_BE32(0xffffffff),
8127 .dst_addr = RTE_BE32(0xffffffff),
8128 .type_of_service = 0xff,
8129 .next_proto_id = 0xff,
8130 .time_to_live = 0xff,
8140 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8142 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8144 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8146 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8148 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
8153 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8154 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8155 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8156 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
8157 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
8158 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
8159 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8160 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8161 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8162 src_ipv4_src_ipv6.ipv4_layout.ipv4);
8163 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
8164 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
8165 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
8166 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
8167 ipv4_m->hdr.type_of_service);
8168 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
8169 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
8170 ipv4_m->hdr.type_of_service >> 2);
8171 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
8172 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8173 ipv4_m->hdr.next_proto_id);
8174 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8175 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
8176 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8177 ipv4_m->hdr.time_to_live);
8178 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8179 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
8180 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8181 !!(ipv4_m->hdr.fragment_offset));
8182 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8183 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
8187 * Add IPV6 item to matcher and to the value.
8189 * @param[in, out] matcher
8191 * @param[in, out] key
8192 * Flow matcher value.
8194 * Flow pattern to translate.
8196 * Item is inner pattern.
8198 * The group to insert the rule.
8201 flow_dv_translate_item_ipv6(void *matcher, void *key,
8202 const struct rte_flow_item *item,
8203 int inner, uint32_t group)
8205 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
8206 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
8207 const struct rte_flow_item_ipv6 nic_mask = {
8210 "\xff\xff\xff\xff\xff\xff\xff\xff"
8211 "\xff\xff\xff\xff\xff\xff\xff\xff",
8213 "\xff\xff\xff\xff\xff\xff\xff\xff"
8214 "\xff\xff\xff\xff\xff\xff\xff\xff",
8215 .vtc_flow = RTE_BE32(0xffffffff),
8222 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8223 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8232 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8234 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8236 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8238 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8240 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
8245 size = sizeof(ipv6_m->hdr.dst_addr);
8246 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8247 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8248 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8249 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
8250 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
8251 for (i = 0; i < size; ++i)
8252 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
8253 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
8254 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8255 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
8256 src_ipv4_src_ipv6.ipv6_layout.ipv6);
8257 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
8258 for (i = 0; i < size; ++i)
8259 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
8261 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
8262 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
8263 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
8264 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
8265 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
8266 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
8269 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
8271 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
8274 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
8276 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
8280 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8282 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8283 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
8285 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
8286 ipv6_m->hdr.hop_limits);
8287 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
8288 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
8289 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
8290 !!(ipv6_m->has_frag_ext));
8291 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
8292 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
8296 * Add IPV6 fragment extension item to matcher and to the value.
8298 * @param[in, out] matcher
8300 * @param[in, out] key
8301 * Flow matcher value.
8303 * Flow pattern to translate.
8305 * Item is inner pattern.
8308 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
8309 const struct rte_flow_item *item,
8312 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
8313 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
8314 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
8316 .next_header = 0xff,
8317 .frag_data = RTE_BE16(0xffff),
8324 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8326 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8328 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8330 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8332 /* IPv6 fragment extension item exists, so packet is IP fragment. */
8333 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
8334 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
8335 if (!ipv6_frag_ext_v)
8337 if (!ipv6_frag_ext_m)
8338 ipv6_frag_ext_m = &nic_mask;
8339 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
8340 ipv6_frag_ext_m->hdr.next_header);
8341 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
8342 ipv6_frag_ext_v->hdr.next_header &
8343 ipv6_frag_ext_m->hdr.next_header);
8347 * Add TCP item to matcher and to the value.
8349 * @param[in, out] matcher
8351 * @param[in, out] key
8352 * Flow matcher value.
8354 * Flow pattern to translate.
8356 * Item is inner pattern.
8359 flow_dv_translate_item_tcp(void *matcher, void *key,
8360 const struct rte_flow_item *item,
8363 const struct rte_flow_item_tcp *tcp_m = item->mask;
8364 const struct rte_flow_item_tcp *tcp_v = item->spec;
8369 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8371 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8373 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8375 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8377 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8378 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
8382 tcp_m = &rte_flow_item_tcp_mask;
8383 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
8384 rte_be_to_cpu_16(tcp_m->hdr.src_port));
8385 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
8386 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
8387 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
8388 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
8389 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
8390 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
8391 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
8392 tcp_m->hdr.tcp_flags);
8393 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
8394 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
8398 * Add UDP item to matcher and to the value.
8400 * @param[in, out] matcher
8402 * @param[in, out] key
8403 * Flow matcher value.
8405 * Flow pattern to translate.
8407 * Item is inner pattern.
8410 flow_dv_translate_item_udp(void *matcher, void *key,
8411 const struct rte_flow_item *item,
8414 const struct rte_flow_item_udp *udp_m = item->mask;
8415 const struct rte_flow_item_udp *udp_v = item->spec;
8420 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8422 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8424 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8426 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8428 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8429 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
8433 udp_m = &rte_flow_item_udp_mask;
8434 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
8435 rte_be_to_cpu_16(udp_m->hdr.src_port));
8436 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
8437 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
8438 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
8439 rte_be_to_cpu_16(udp_m->hdr.dst_port));
8440 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
8441 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
8445 * Add GRE optional Key item to matcher and to the value.
8447 * @param[in, out] matcher
8449 * @param[in, out] key
8450 * Flow matcher value.
8452 * Flow pattern to translate.
8454 * Item is inner pattern.
8457 flow_dv_translate_item_gre_key(void *matcher, void *key,
8458 const struct rte_flow_item *item)
8460 const rte_be32_t *key_m = item->mask;
8461 const rte_be32_t *key_v = item->spec;
8462 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8463 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8464 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
8466 /* GRE K bit must be on and should already be validated */
8467 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
8468 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
8472 key_m = &gre_key_default_mask;
8473 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
8474 rte_be_to_cpu_32(*key_m) >> 8);
8475 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
8476 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
8477 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
8478 rte_be_to_cpu_32(*key_m) & 0xFF);
8479 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
8480 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
8484 * Add GRE item to matcher and to the value.
8486 * @param[in, out] matcher
8488 * @param[in, out] key
8489 * Flow matcher value.
8491 * Flow pattern to translate.
8493 * Item is inner pattern.
8496 flow_dv_translate_item_gre(void *matcher, void *key,
8497 const struct rte_flow_item *item,
8500 const struct rte_flow_item_gre *gre_m = item->mask;
8501 const struct rte_flow_item_gre *gre_v = item->spec;
8504 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8505 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8512 uint16_t s_present:1;
8513 uint16_t k_present:1;
8514 uint16_t rsvd_bit1:1;
8515 uint16_t c_present:1;
8519 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
8522 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8524 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8526 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8528 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8530 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
8531 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
8535 gre_m = &rte_flow_item_gre_mask;
8536 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
8537 rte_be_to_cpu_16(gre_m->protocol));
8538 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
8539 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
8540 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
8541 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
8542 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
8543 gre_crks_rsvd0_ver_m.c_present);
8544 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
8545 gre_crks_rsvd0_ver_v.c_present &
8546 gre_crks_rsvd0_ver_m.c_present);
8547 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
8548 gre_crks_rsvd0_ver_m.k_present);
8549 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
8550 gre_crks_rsvd0_ver_v.k_present &
8551 gre_crks_rsvd0_ver_m.k_present);
8552 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
8553 gre_crks_rsvd0_ver_m.s_present);
8554 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
8555 gre_crks_rsvd0_ver_v.s_present &
8556 gre_crks_rsvd0_ver_m.s_present);
8560 * Add NVGRE item to matcher and to the value.
8562 * @param[in, out] matcher
8564 * @param[in, out] key
8565 * Flow matcher value.
8567 * Flow pattern to translate.
8569 * Item is inner pattern.
8572 flow_dv_translate_item_nvgre(void *matcher, void *key,
8573 const struct rte_flow_item *item,
8576 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
8577 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
8578 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8579 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8580 const char *tni_flow_id_m;
8581 const char *tni_flow_id_v;
8587 /* For NVGRE, GRE header fields must be set with defined values. */
8588 const struct rte_flow_item_gre gre_spec = {
8589 .c_rsvd0_ver = RTE_BE16(0x2000),
8590 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
8592 const struct rte_flow_item_gre gre_mask = {
8593 .c_rsvd0_ver = RTE_BE16(0xB000),
8594 .protocol = RTE_BE16(UINT16_MAX),
8596 const struct rte_flow_item gre_item = {
8601 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
8605 nvgre_m = &rte_flow_item_nvgre_mask;
8606 tni_flow_id_m = (const char *)nvgre_m->tni;
8607 tni_flow_id_v = (const char *)nvgre_v->tni;
8608 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
8609 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
8610 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
8611 memcpy(gre_key_m, tni_flow_id_m, size);
8612 for (i = 0; i < size; ++i)
8613 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
8617 * Add VXLAN item to matcher and to the value.
8619 * @param[in, out] matcher
8621 * @param[in, out] key
8622 * Flow matcher value.
8624 * Flow pattern to translate.
8626 * Item is inner pattern.
8629 flow_dv_translate_item_vxlan(void *matcher, void *key,
8630 const struct rte_flow_item *item,
8633 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
8634 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
8637 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8638 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8646 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8648 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8650 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8652 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8654 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8655 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8656 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8657 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8658 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8663 vxlan_m = &rte_flow_item_vxlan_mask;
8664 size = sizeof(vxlan_m->vni);
8665 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
8666 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
8667 memcpy(vni_m, vxlan_m->vni, size);
8668 for (i = 0; i < size; ++i)
8669 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8673 * Add VXLAN-GPE item to matcher and to the value.
8675 * @param[in, out] matcher
8677 * @param[in, out] key
8678 * Flow matcher value.
8680 * Flow pattern to translate.
8682 * Item is inner pattern.
8686 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
8687 const struct rte_flow_item *item, int inner)
8689 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
8690 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
8694 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
8696 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8702 uint8_t flags_m = 0xff;
8703 uint8_t flags_v = 0xc;
8706 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8708 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8710 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8712 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8714 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
8715 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
8716 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8717 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8718 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8723 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
8724 size = sizeof(vxlan_m->vni);
8725 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
8726 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
8727 memcpy(vni_m, vxlan_m->vni, size);
8728 for (i = 0; i < size; ++i)
8729 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
8730 if (vxlan_m->flags) {
8731 flags_m = vxlan_m->flags;
8732 flags_v = vxlan_v->flags;
8734 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
8735 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
8736 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
8738 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
8743 * Add Geneve item to matcher and to the value.
8745 * @param[in, out] matcher
8747 * @param[in, out] key
8748 * Flow matcher value.
8750 * Flow pattern to translate.
8752 * Item is inner pattern.
8756 flow_dv_translate_item_geneve(void *matcher, void *key,
8757 const struct rte_flow_item *item, int inner)
8759 const struct rte_flow_item_geneve *geneve_m = item->mask;
8760 const struct rte_flow_item_geneve *geneve_v = item->spec;
8763 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8764 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8773 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8775 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
8777 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
8779 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
8781 dport = MLX5_UDP_PORT_GENEVE;
8782 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
8783 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
8784 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
8789 geneve_m = &rte_flow_item_geneve_mask;
8790 size = sizeof(geneve_m->vni);
8791 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
8792 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
8793 memcpy(vni_m, geneve_m->vni, size);
8794 for (i = 0; i < size; ++i)
8795 vni_v[i] = vni_m[i] & geneve_v->vni[i];
8796 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
8797 rte_be_to_cpu_16(geneve_m->protocol));
8798 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
8799 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
8800 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
8801 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
8802 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
8803 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
8804 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
8805 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
8806 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
8807 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
8808 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
8809 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
8810 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
8814 * Create Geneve TLV option resource.
8816 * @param dev[in, out]
8817 * Pointer to rte_eth_dev structure.
8818 * @param[in, out] tag_be24
8819 * Tag value in big endian then R-shift 8.
8820 * @parm[in, out] dev_flow
8821 * Pointer to the dev_flow.
8823 * pointer to error structure.
8826 * 0 on success otherwise -errno and errno is set.
8830 flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
8831 const struct rte_flow_item *item,
8832 struct rte_flow_error *error)
8834 struct mlx5_priv *priv = dev->data->dev_private;
8835 struct mlx5_dev_ctx_shared *sh = priv->sh;
8836 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
8837 sh->geneve_tlv_option_resource;
8838 struct mlx5_devx_obj *obj;
8839 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
8844 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
8845 if (geneve_opt_resource != NULL) {
8846 if (geneve_opt_resource->option_class ==
8847 geneve_opt_v->option_class &&
8848 geneve_opt_resource->option_type ==
8849 geneve_opt_v->option_type &&
8850 geneve_opt_resource->length ==
8851 geneve_opt_v->option_len) {
8852 /* We already have GENVE TLV option obj allocated. */
8853 __atomic_fetch_add(&geneve_opt_resource->refcnt, 1,
8856 ret = rte_flow_error_set(error, ENOMEM,
8857 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8858 "Only one GENEVE TLV option supported");
8862 /* Create a GENEVE TLV object and resource. */
8863 obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->ctx,
8864 geneve_opt_v->option_class,
8865 geneve_opt_v->option_type,
8866 geneve_opt_v->option_len);
8868 ret = rte_flow_error_set(error, ENODATA,
8869 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8870 "Failed to create GENEVE TLV Devx object");
8873 sh->geneve_tlv_option_resource =
8874 mlx5_malloc(MLX5_MEM_ZERO,
8875 sizeof(*geneve_opt_resource),
8877 if (!sh->geneve_tlv_option_resource) {
8878 claim_zero(mlx5_devx_cmd_destroy(obj));
8879 ret = rte_flow_error_set(error, ENOMEM,
8880 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8881 "GENEVE TLV object memory allocation failed");
8884 geneve_opt_resource = sh->geneve_tlv_option_resource;
8885 geneve_opt_resource->obj = obj;
8886 geneve_opt_resource->option_class = geneve_opt_v->option_class;
8887 geneve_opt_resource->option_type = geneve_opt_v->option_type;
8888 geneve_opt_resource->length = geneve_opt_v->option_len;
8889 __atomic_store_n(&geneve_opt_resource->refcnt, 1,
8893 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
8898 * Add Geneve TLV option item to matcher.
8900 * @param[in, out] dev
8901 * Pointer to rte_eth_dev structure.
8902 * @param[in, out] matcher
8904 * @param[in, out] key
8905 * Flow matcher value.
8907 * Flow pattern to translate.
8909 * Pointer to error structure.
8912 flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *matcher,
8913 void *key, const struct rte_flow_item *item,
8914 struct rte_flow_error *error)
8916 const struct rte_flow_item_geneve_opt *geneve_opt_m = item->mask;
8917 const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
8918 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8919 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8920 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
8922 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
8923 rte_be32_t opt_data_key = 0, opt_data_mask = 0;
8929 geneve_opt_m = &rte_flow_item_geneve_opt_mask;
8930 ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
8933 DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
8937 * Set the option length in GENEVE header if not requested.
8938 * The GENEVE TLV option length is expressed by the option length field
8939 * in the GENEVE header.
8940 * If the option length was not requested but the GENEVE TLV option item
8941 * is present we set the option length field implicitly.
8943 if (!MLX5_GET16(fte_match_set_misc, misc_m, geneve_opt_len)) {
8944 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
8945 MLX5_GENEVE_OPTLEN_MASK);
8946 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
8947 geneve_opt_v->option_len + 1);
8950 if (geneve_opt_v->data) {
8951 memcpy(&opt_data_key, geneve_opt_v->data,
8952 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
8953 sizeof(opt_data_key)));
8954 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
8955 sizeof(opt_data_key));
8956 memcpy(&opt_data_mask, geneve_opt_m->data,
8957 RTE_MIN((uint32_t)(geneve_opt_v->option_len * 4),
8958 sizeof(opt_data_mask)));
8959 MLX5_ASSERT((uint32_t)(geneve_opt_v->option_len * 4) <=
8960 sizeof(opt_data_mask));
8961 MLX5_SET(fte_match_set_misc3, misc3_m,
8962 geneve_tlv_option_0_data,
8963 rte_be_to_cpu_32(opt_data_mask));
8964 MLX5_SET(fte_match_set_misc3, misc3_v,
8965 geneve_tlv_option_0_data,
8966 rte_be_to_cpu_32(opt_data_key & opt_data_mask));
8972 * Add MPLS item to matcher and to the value.
8974 * @param[in, out] matcher
8976 * @param[in, out] key
8977 * Flow matcher value.
8979 * Flow pattern to translate.
8980 * @param[in] prev_layer
8981 * The protocol layer indicated in previous item.
8983 * Item is inner pattern.
8986 flow_dv_translate_item_mpls(void *matcher, void *key,
8987 const struct rte_flow_item *item,
8988 uint64_t prev_layer,
8991 const uint32_t *in_mpls_m = item->mask;
8992 const uint32_t *in_mpls_v = item->spec;
8993 uint32_t *out_mpls_m = 0;
8994 uint32_t *out_mpls_v = 0;
8995 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8996 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8997 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
8999 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9000 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
9001 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9003 switch (prev_layer) {
9004 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9005 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
9006 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9007 MLX5_UDP_PORT_MPLS);
9009 case MLX5_FLOW_LAYER_GRE:
9010 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
9011 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9012 RTE_ETHER_TYPE_MPLS);
9015 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
9016 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9023 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
9024 switch (prev_layer) {
9025 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
9027 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9028 outer_first_mpls_over_udp);
9030 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9031 outer_first_mpls_over_udp);
9033 case MLX5_FLOW_LAYER_GRE:
9035 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
9036 outer_first_mpls_over_gre);
9038 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
9039 outer_first_mpls_over_gre);
9042 /* Inner MPLS not over GRE is not supported. */
9045 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9049 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
9055 if (out_mpls_m && out_mpls_v) {
9056 *out_mpls_m = *in_mpls_m;
9057 *out_mpls_v = *in_mpls_v & *in_mpls_m;
9062 * Add metadata register item to matcher
9064 * @param[in, out] matcher
9066 * @param[in, out] key
9067 * Flow matcher value.
9068 * @param[in] reg_type
9069 * Type of device metadata register
9076 flow_dv_match_meta_reg(void *matcher, void *key,
9077 enum modify_reg reg_type,
9078 uint32_t data, uint32_t mask)
9081 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
9083 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
9089 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
9090 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
9093 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
9094 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
9098 * The metadata register C0 field might be divided into
9099 * source vport index and META item value, we should set
9100 * this field according to specified mask, not as whole one.
9102 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
9104 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
9105 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
9108 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
9111 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
9112 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
9115 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
9116 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
9119 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
9120 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
9123 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
9124 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
9127 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
9128 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
9131 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
9132 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
9135 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
9136 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
9145 * Add MARK item to matcher
9148 * The device to configure through.
9149 * @param[in, out] matcher
9151 * @param[in, out] key
9152 * Flow matcher value.
9154 * Flow pattern to translate.
9157 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
9158 void *matcher, void *key,
9159 const struct rte_flow_item *item)
9161 struct mlx5_priv *priv = dev->data->dev_private;
9162 const struct rte_flow_item_mark *mark;
9166 mark = item->mask ? (const void *)item->mask :
9167 &rte_flow_item_mark_mask;
9168 mask = mark->id & priv->sh->dv_mark_mask;
9169 mark = (const void *)item->spec;
9171 value = mark->id & priv->sh->dv_mark_mask & mask;
9173 enum modify_reg reg;
9175 /* Get the metadata register index for the mark. */
9176 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
9177 MLX5_ASSERT(reg > 0);
9178 if (reg == REG_C_0) {
9179 struct mlx5_priv *priv = dev->data->dev_private;
9180 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9181 uint32_t shl_c0 = rte_bsf32(msk_c0);
9187 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9192 * Add META item to matcher
9195 * The devich to configure through.
9196 * @param[in, out] matcher
9198 * @param[in, out] key
9199 * Flow matcher value.
9201 * Attributes of flow that includes this item.
9203 * Flow pattern to translate.
9206 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
9207 void *matcher, void *key,
9208 const struct rte_flow_attr *attr,
9209 const struct rte_flow_item *item)
9211 const struct rte_flow_item_meta *meta_m;
9212 const struct rte_flow_item_meta *meta_v;
9214 meta_m = (const void *)item->mask;
9216 meta_m = &rte_flow_item_meta_mask;
9217 meta_v = (const void *)item->spec;
9220 uint32_t value = meta_v->data;
9221 uint32_t mask = meta_m->data;
9223 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
9226 MLX5_ASSERT(reg != REG_NON);
9228 * In datapath code there is no endianness
9229 * coversions for perfromance reasons, all
9230 * pattern conversions are done in rte_flow.
9232 value = rte_cpu_to_be_32(value);
9233 mask = rte_cpu_to_be_32(mask);
9234 if (reg == REG_C_0) {
9235 struct mlx5_priv *priv = dev->data->dev_private;
9236 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9237 uint32_t shl_c0 = rte_bsf32(msk_c0);
9238 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
9239 uint32_t shr_c0 = __builtin_clz(priv->sh->dv_meta_mask);
9246 MLX5_ASSERT(msk_c0);
9247 MLX5_ASSERT(!(~msk_c0 & mask));
9249 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
9254 * Add vport metadata Reg C0 item to matcher
9256 * @param[in, out] matcher
9258 * @param[in, out] key
9259 * Flow matcher value.
9261 * Flow pattern to translate.
9264 flow_dv_translate_item_meta_vport(void *matcher, void *key,
9265 uint32_t value, uint32_t mask)
9267 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
9271 * Add tag item to matcher
9274 * The devich to configure through.
9275 * @param[in, out] matcher
9277 * @param[in, out] key
9278 * Flow matcher value.
9280 * Flow pattern to translate.
9283 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
9284 void *matcher, void *key,
9285 const struct rte_flow_item *item)
9287 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
9288 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
9289 uint32_t mask, value;
9292 value = tag_v->data;
9293 mask = tag_m ? tag_m->data : UINT32_MAX;
9294 if (tag_v->id == REG_C_0) {
9295 struct mlx5_priv *priv = dev->data->dev_private;
9296 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
9297 uint32_t shl_c0 = rte_bsf32(msk_c0);
9303 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
9307 * Add TAG item to matcher
9310 * The devich to configure through.
9311 * @param[in, out] matcher
9313 * @param[in, out] key
9314 * Flow matcher value.
9316 * Flow pattern to translate.
9319 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
9320 void *matcher, void *key,
9321 const struct rte_flow_item *item)
9323 const struct rte_flow_item_tag *tag_v = item->spec;
9324 const struct rte_flow_item_tag *tag_m = item->mask;
9325 enum modify_reg reg;
9328 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
9329 /* Get the metadata register index for the tag. */
9330 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
9331 MLX5_ASSERT(reg > 0);
9332 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
9336 * Add source vport match to the specified matcher.
9338 * @param[in, out] matcher
9340 * @param[in, out] key
9341 * Flow matcher value.
9343 * Source vport value to match
9348 flow_dv_translate_item_source_vport(void *matcher, void *key,
9349 int16_t port, uint16_t mask)
9351 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
9352 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9354 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
9355 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
9359 * Translate port-id item to eswitch match on port-id.
9362 * The devich to configure through.
9363 * @param[in, out] matcher
9365 * @param[in, out] key
9366 * Flow matcher value.
9368 * Flow pattern to translate.
9373 * 0 on success, a negative errno value otherwise.
9376 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
9377 void *key, const struct rte_flow_item *item,
9378 const struct rte_flow_attr *attr)
9380 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
9381 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
9382 struct mlx5_priv *priv;
9385 mask = pid_m ? pid_m->id : 0xffff;
9386 id = pid_v ? pid_v->id : dev->data->port_id;
9387 priv = mlx5_port_to_eswitch_info(id, item == NULL);
9391 * Translate to vport field or to metadata, depending on mode.
9392 * Kernel can use either misc.source_port or half of C0 metadata
9395 if (priv->vport_meta_mask) {
9397 * Provide the hint for SW steering library
9398 * to insert the flow into ingress domain and
9399 * save the extra vport match.
9401 if (mask == 0xffff && priv->vport_id == 0xffff &&
9402 priv->pf_bond < 0 && attr->transfer)
9403 flow_dv_translate_item_source_vport
9404 (matcher, key, priv->vport_id, mask);
9406 * We should always set the vport metadata register,
9407 * otherwise the SW steering library can drop
9408 * the rule if wire vport metadata value is not zero,
9409 * it depends on kernel configuration.
9411 flow_dv_translate_item_meta_vport(matcher, key,
9412 priv->vport_meta_tag,
9413 priv->vport_meta_mask);
9415 flow_dv_translate_item_source_vport(matcher, key,
9416 priv->vport_id, mask);
9422 * Add ICMP6 item to matcher and to the value.
9424 * @param[in, out] matcher
9426 * @param[in, out] key
9427 * Flow matcher value.
9429 * Flow pattern to translate.
9431 * Item is inner pattern.
9434 flow_dv_translate_item_icmp6(void *matcher, void *key,
9435 const struct rte_flow_item *item,
9438 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
9439 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
9442 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9444 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9446 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9448 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9450 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9452 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9454 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9455 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
9459 icmp6_m = &rte_flow_item_icmp6_mask;
9460 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
9461 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
9462 icmp6_v->type & icmp6_m->type);
9463 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
9464 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
9465 icmp6_v->code & icmp6_m->code);
9469 * Add ICMP item to matcher and to the value.
9471 * @param[in, out] matcher
9473 * @param[in, out] key
9474 * Flow matcher value.
9476 * Flow pattern to translate.
9478 * Item is inner pattern.
9481 flow_dv_translate_item_icmp(void *matcher, void *key,
9482 const struct rte_flow_item *item,
9485 const struct rte_flow_item_icmp *icmp_m = item->mask;
9486 const struct rte_flow_item_icmp *icmp_v = item->spec;
9487 uint32_t icmp_header_data_m = 0;
9488 uint32_t icmp_header_data_v = 0;
9491 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9493 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9495 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9497 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9499 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9501 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9503 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
9504 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
9508 icmp_m = &rte_flow_item_icmp_mask;
9509 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
9510 icmp_m->hdr.icmp_type);
9511 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
9512 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
9513 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
9514 icmp_m->hdr.icmp_code);
9515 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
9516 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
9517 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
9518 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
9519 if (icmp_header_data_m) {
9520 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
9521 icmp_header_data_v |=
9522 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
9523 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
9524 icmp_header_data_m);
9525 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
9526 icmp_header_data_v & icmp_header_data_m);
9531 * Add GTP item to matcher and to the value.
9533 * @param[in, out] matcher
9535 * @param[in, out] key
9536 * Flow matcher value.
9538 * Flow pattern to translate.
9540 * Item is inner pattern.
9543 flow_dv_translate_item_gtp(void *matcher, void *key,
9544 const struct rte_flow_item *item, int inner)
9546 const struct rte_flow_item_gtp *gtp_m = item->mask;
9547 const struct rte_flow_item_gtp *gtp_v = item->spec;
9550 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9552 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9553 uint16_t dport = RTE_GTPU_UDP_PORT;
9556 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9558 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9560 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
9562 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9564 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
9565 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
9566 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
9571 gtp_m = &rte_flow_item_gtp_mask;
9572 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
9573 gtp_m->v_pt_rsv_flags);
9574 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
9575 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
9576 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
9577 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
9578 gtp_v->msg_type & gtp_m->msg_type);
9579 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
9580 rte_be_to_cpu_32(gtp_m->teid));
9581 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
9582 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
9586 * Add GTP PSC item to matcher.
9588 * @param[in, out] matcher
9590 * @param[in, out] key
9591 * Flow matcher value.
9593 * Flow pattern to translate.
9596 flow_dv_translate_item_gtp_psc(void *matcher, void *key,
9597 const struct rte_flow_item *item)
9599 const struct rte_flow_item_gtp_psc *gtp_psc_m = item->mask;
9600 const struct rte_flow_item_gtp_psc *gtp_psc_v = item->spec;
9601 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
9603 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
9609 uint8_t next_ext_header_type;
9614 /* Always set E-flag match on one, regardless of GTP item settings. */
9615 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_m, gtpu_msg_flags);
9616 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9617 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags, gtp_flags);
9618 gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
9619 gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
9620 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
9621 /*Set next extension header type. */
9624 dw_2.next_ext_header_type = 0xff;
9625 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_dw_2,
9626 rte_cpu_to_be_32(dw_2.w32));
9629 dw_2.next_ext_header_type = 0x85;
9630 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
9631 rte_cpu_to_be_32(dw_2.w32));
9643 /*Set extension header PDU type and Qos. */
9645 gtp_psc_m = &rte_flow_item_gtp_psc_mask;
9647 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_m->pdu_type);
9648 dw_0.qfi = gtp_psc_m->qfi;
9649 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_first_ext_dw_0,
9650 rte_cpu_to_be_32(dw_0.w32));
9652 dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->pdu_type &
9653 gtp_psc_m->pdu_type);
9654 dw_0.qfi = gtp_psc_v->qfi & gtp_psc_m->qfi;
9655 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
9656 rte_cpu_to_be_32(dw_0.w32));
9662 * Add eCPRI item to matcher and to the value.
9665 * The devich to configure through.
9666 * @param[in, out] matcher
9668 * @param[in, out] key
9669 * Flow matcher value.
9671 * Flow pattern to translate.
9672 * @param[in] samples
9673 * Sample IDs to be used in the matching.
9676 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
9677 void *key, const struct rte_flow_item *item)
9679 struct mlx5_priv *priv = dev->data->dev_private;
9680 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
9681 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
9682 struct rte_ecpri_common_hdr common;
9683 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
9685 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
9693 ecpri_m = &rte_flow_item_ecpri_mask;
9695 * Maximal four DW samples are supported in a single matching now.
9696 * Two are used now for a eCPRI matching:
9697 * 1. Type: one byte, mask should be 0x00ff0000 in network order
9698 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
9701 if (!ecpri_m->hdr.common.u32)
9703 samples = priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0].ids;
9704 /* Need to take the whole DW as the mask to fill the entry. */
9705 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9706 prog_sample_field_value_0);
9707 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9708 prog_sample_field_value_0);
9709 /* Already big endian (network order) in the header. */
9710 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
9711 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
9712 /* Sample#0, used for matching type, offset 0. */
9713 MLX5_SET(fte_match_set_misc4, misc4_m,
9714 prog_sample_field_id_0, samples[0]);
9715 /* It makes no sense to set the sample ID in the mask field. */
9716 MLX5_SET(fte_match_set_misc4, misc4_v,
9717 prog_sample_field_id_0, samples[0]);
9719 * Checking if message body part needs to be matched.
9720 * Some wildcard rules only matching type field should be supported.
9722 if (ecpri_m->hdr.dummy[0]) {
9723 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
9724 switch (common.type) {
9725 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
9726 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
9727 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
9728 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
9729 prog_sample_field_value_1);
9730 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
9731 prog_sample_field_value_1);
9732 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
9733 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
9734 ecpri_m->hdr.dummy[0];
9735 /* Sample#1, to match message body, offset 4. */
9736 MLX5_SET(fte_match_set_misc4, misc4_m,
9737 prog_sample_field_id_1, samples[1]);
9738 MLX5_SET(fte_match_set_misc4, misc4_v,
9739 prog_sample_field_id_1, samples[1]);
9742 /* Others, do not match any sample ID. */
9749 * Add connection tracking status item to matcher
9752 * The devich to configure through.
9753 * @param[in, out] matcher
9755 * @param[in, out] key
9756 * Flow matcher value.
9758 * Flow pattern to translate.
9761 flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
9762 void *matcher, void *key,
9763 const struct rte_flow_item *item)
9765 uint32_t reg_value = 0;
9767 /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
9768 uint32_t reg_mask = 0;
9769 const struct rte_flow_item_conntrack *spec = item->spec;
9770 const struct rte_flow_item_conntrack *mask = item->mask;
9772 struct rte_flow_error error;
9775 mask = &rte_flow_item_conntrack_mask;
9776 if (!spec || !mask->flags)
9778 flags = spec->flags & mask->flags;
9779 /* The conflict should be checked in the validation. */
9780 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
9781 reg_value |= MLX5_CT_SYNDROME_VALID;
9782 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
9783 reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
9784 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
9785 reg_value |= MLX5_CT_SYNDROME_INVALID;
9786 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
9787 reg_value |= MLX5_CT_SYNDROME_TRAP;
9788 if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
9789 reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
9790 if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
9791 RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
9792 RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
9794 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
9795 reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
9796 if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
9797 reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
9798 /* The REG_C_x value could be saved during startup. */
9799 reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
9800 if (reg_id == REG_NON)
9802 flow_dv_match_meta_reg(matcher, key, (enum modify_reg)reg_id,
9803 reg_value, reg_mask);
9806 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
9808 #define HEADER_IS_ZERO(match_criteria, headers) \
9809 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
9810 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
9813 * Calculate flow matcher enable bitmap.
9815 * @param match_criteria
9816 * Pointer to flow matcher criteria.
9819 * Bitmap of enabled fields.
9822 flow_dv_matcher_enable(uint32_t *match_criteria)
9824 uint8_t match_criteria_enable;
9826 match_criteria_enable =
9827 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
9828 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
9829 match_criteria_enable |=
9830 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
9831 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
9832 match_criteria_enable |=
9833 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
9834 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
9835 match_criteria_enable |=
9836 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
9837 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
9838 match_criteria_enable |=
9839 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
9840 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
9841 match_criteria_enable |=
9842 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
9843 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
9844 return match_criteria_enable;
9847 struct mlx5_hlist_entry *
9848 flow_dv_tbl_create_cb(struct mlx5_hlist *list, uint64_t key64, void *cb_ctx)
9850 struct mlx5_dev_ctx_shared *sh = list->ctx;
9851 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
9852 struct rte_eth_dev *dev = ctx->dev;
9853 struct mlx5_flow_tbl_data_entry *tbl_data;
9854 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data;
9855 struct rte_flow_error *error = ctx->error;
9856 union mlx5_flow_tbl_key key = { .v64 = key64 };
9857 struct mlx5_flow_tbl_resource *tbl;
9862 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
9864 rte_flow_error_set(error, ENOMEM,
9865 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9867 "cannot allocate flow table data entry");
9870 tbl_data->idx = idx;
9871 tbl_data->tunnel = tt_prm->tunnel;
9872 tbl_data->group_id = tt_prm->group_id;
9873 tbl_data->external = !!tt_prm->external;
9874 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
9875 tbl_data->is_egress = !!key.is_egress;
9876 tbl_data->is_transfer = !!key.is_fdb;
9877 tbl_data->dummy = !!key.dummy;
9878 tbl_data->level = key.level;
9879 tbl_data->id = key.id;
9880 tbl = &tbl_data->tbl;
9882 return &tbl_data->entry;
9884 domain = sh->fdb_domain;
9885 else if (key.is_egress)
9886 domain = sh->tx_domain;
9888 domain = sh->rx_domain;
9889 ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
9891 rte_flow_error_set(error, ENOMEM,
9892 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9893 NULL, "cannot create flow table object");
9894 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
9897 if (key.level != 0) {
9898 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
9899 (tbl->obj, &tbl_data->jump.action);
9901 rte_flow_error_set(error, ENOMEM,
9902 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9904 "cannot create flow jump action");
9905 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
9906 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
9910 MKSTR(matcher_name, "%s_%s_%u_%u_matcher_cache",
9911 key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
9913 mlx5_cache_list_init(&tbl_data->matchers, matcher_name, 0, sh,
9914 flow_dv_matcher_create_cb,
9915 flow_dv_matcher_match_cb,
9916 flow_dv_matcher_remove_cb);
9917 return &tbl_data->entry;
9921 flow_dv_tbl_match_cb(struct mlx5_hlist *list __rte_unused,
9922 struct mlx5_hlist_entry *entry, uint64_t key64,
9923 void *cb_ctx __rte_unused)
9925 struct mlx5_flow_tbl_data_entry *tbl_data =
9926 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
9927 union mlx5_flow_tbl_key key = { .v64 = key64 };
9929 return tbl_data->level != key.level ||
9930 tbl_data->id != key.id ||
9931 tbl_data->dummy != key.dummy ||
9932 tbl_data->is_transfer != !!key.is_fdb ||
9933 tbl_data->is_egress != !!key.is_egress;
9939 * @param[in, out] dev
9940 * Pointer to rte_eth_dev structure.
9941 * @param[in] table_level
9942 * Table level to use.
9944 * Direction of the table.
9945 * @param[in] transfer
9946 * E-Switch or NIC flow.
9948 * Dummy entry for dv API.
9949 * @param[in] table_id
9952 * pointer to error structure.
9955 * Returns tables resource based on the index, NULL in case of failed.
9957 struct mlx5_flow_tbl_resource *
9958 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
9959 uint32_t table_level, uint8_t egress,
9962 const struct mlx5_flow_tunnel *tunnel,
9963 uint32_t group_id, uint8_t dummy,
9965 struct rte_flow_error *error)
9967 struct mlx5_priv *priv = dev->data->dev_private;
9968 union mlx5_flow_tbl_key table_key = {
9970 .level = table_level,
9974 .is_fdb = !!transfer,
9975 .is_egress = !!egress,
9978 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
9980 .group_id = group_id,
9981 .external = external,
9983 struct mlx5_flow_cb_ctx ctx = {
9988 struct mlx5_hlist_entry *entry;
9989 struct mlx5_flow_tbl_data_entry *tbl_data;
9991 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
9993 rte_flow_error_set(error, ENOMEM,
9994 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9995 "cannot get table");
9998 DRV_LOG(DEBUG, "table_level %u table_id %u "
9999 "tunnel %u group %u registered.",
10000 table_level, table_id,
10001 tunnel ? tunnel->tunnel_id : 0, group_id);
10002 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10003 return &tbl_data->tbl;
10007 flow_dv_tbl_remove_cb(struct mlx5_hlist *list,
10008 struct mlx5_hlist_entry *entry)
10010 struct mlx5_dev_ctx_shared *sh = list->ctx;
10011 struct mlx5_flow_tbl_data_entry *tbl_data =
10012 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
10014 MLX5_ASSERT(entry && sh);
10015 if (tbl_data->jump.action)
10016 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
10017 if (tbl_data->tbl.obj)
10018 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
10019 if (tbl_data->tunnel_offload && tbl_data->external) {
10020 struct mlx5_hlist_entry *he;
10021 struct mlx5_hlist *tunnel_grp_hash;
10022 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
10023 union tunnel_tbl_key tunnel_key = {
10024 .tunnel_id = tbl_data->tunnel ?
10025 tbl_data->tunnel->tunnel_id : 0,
10026 .group = tbl_data->group_id
10028 uint32_t table_level = tbl_data->level;
10030 tunnel_grp_hash = tbl_data->tunnel ?
10031 tbl_data->tunnel->groups :
10033 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, NULL);
10035 mlx5_hlist_unregister(tunnel_grp_hash, he);
10037 "table_level %u id %u tunnel %u group %u released.",
10041 tbl_data->tunnel->tunnel_id : 0,
10042 tbl_data->group_id);
10044 mlx5_cache_list_destroy(&tbl_data->matchers);
10045 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
10049 * Release a flow table.
10052 * Pointer to device shared structure.
10054 * Table resource to be released.
10057 * Returns 0 if table was released, else return 1;
10060 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
10061 struct mlx5_flow_tbl_resource *tbl)
10063 struct mlx5_flow_tbl_data_entry *tbl_data =
10064 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10068 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
10072 flow_dv_matcher_match_cb(struct mlx5_cache_list *list __rte_unused,
10073 struct mlx5_cache_entry *entry, void *cb_ctx)
10075 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10076 struct mlx5_flow_dv_matcher *ref = ctx->data;
10077 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
10080 return cur->crc != ref->crc ||
10081 cur->priority != ref->priority ||
10082 memcmp((const void *)cur->mask.buf,
10083 (const void *)ref->mask.buf, ref->mask.size);
10086 struct mlx5_cache_entry *
10087 flow_dv_matcher_create_cb(struct mlx5_cache_list *list,
10088 struct mlx5_cache_entry *entry __rte_unused,
10091 struct mlx5_dev_ctx_shared *sh = list->ctx;
10092 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10093 struct mlx5_flow_dv_matcher *ref = ctx->data;
10094 struct mlx5_flow_dv_matcher *cache;
10095 struct mlx5dv_flow_matcher_attr dv_attr = {
10096 .type = IBV_FLOW_ATTR_NORMAL,
10097 .match_mask = (void *)&ref->mask,
10099 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
10100 typeof(*tbl), tbl);
10103 cache = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*cache), 0, SOCKET_ID_ANY);
10105 rte_flow_error_set(ctx->error, ENOMEM,
10106 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10107 "cannot create matcher");
10111 dv_attr.match_criteria_enable =
10112 flow_dv_matcher_enable(cache->mask.buf);
10113 dv_attr.priority = ref->priority;
10114 if (tbl->is_egress)
10115 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
10116 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->tbl.obj,
10117 &cache->matcher_object);
10120 rte_flow_error_set(ctx->error, ENOMEM,
10121 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10122 "cannot create matcher");
10125 return &cache->entry;
10129 * Register the flow matcher.
10131 * @param[in, out] dev
10132 * Pointer to rte_eth_dev structure.
10133 * @param[in, out] matcher
10134 * Pointer to flow matcher.
10135 * @param[in, out] key
10136 * Pointer to flow table key.
10137 * @parm[in, out] dev_flow
10138 * Pointer to the dev_flow.
10139 * @param[out] error
10140 * pointer to error structure.
10143 * 0 on success otherwise -errno and errno is set.
10146 flow_dv_matcher_register(struct rte_eth_dev *dev,
10147 struct mlx5_flow_dv_matcher *ref,
10148 union mlx5_flow_tbl_key *key,
10149 struct mlx5_flow *dev_flow,
10150 const struct mlx5_flow_tunnel *tunnel,
10152 struct rte_flow_error *error)
10154 struct mlx5_cache_entry *entry;
10155 struct mlx5_flow_dv_matcher *cache;
10156 struct mlx5_flow_tbl_resource *tbl;
10157 struct mlx5_flow_tbl_data_entry *tbl_data;
10158 struct mlx5_flow_cb_ctx ctx = {
10164 * tunnel offload API requires this registration for cases when
10165 * tunnel match rule was inserted before tunnel set rule.
10167 tbl = flow_dv_tbl_resource_get(dev, key->level,
10168 key->is_egress, key->is_fdb,
10169 dev_flow->external, tunnel,
10170 group_id, 0, key->id, error);
10172 return -rte_errno; /* No need to refill the error info */
10173 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
10175 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
10177 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
10178 return rte_flow_error_set(error, ENOMEM,
10179 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10180 "cannot allocate ref memory");
10182 cache = container_of(entry, typeof(*cache), entry);
10183 dev_flow->handle->dvh.matcher = cache;
10187 struct mlx5_hlist_entry *
10188 flow_dv_tag_create_cb(struct mlx5_hlist *list, uint64_t key, void *ctx)
10190 struct mlx5_dev_ctx_shared *sh = list->ctx;
10191 struct rte_flow_error *error = ctx;
10192 struct mlx5_flow_dv_tag_resource *entry;
10196 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
10198 rte_flow_error_set(error, ENOMEM,
10199 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10200 "cannot allocate resource memory");
10204 entry->tag_id = key;
10205 ret = mlx5_flow_os_create_flow_action_tag(key,
10208 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
10209 rte_flow_error_set(error, ENOMEM,
10210 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10211 NULL, "cannot create action");
10214 return &entry->entry;
10218 flow_dv_tag_match_cb(struct mlx5_hlist *list __rte_unused,
10219 struct mlx5_hlist_entry *entry, uint64_t key,
10220 void *cb_ctx __rte_unused)
10222 struct mlx5_flow_dv_tag_resource *tag =
10223 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10225 return key != tag->tag_id;
10229 * Find existing tag resource or create and register a new one.
10231 * @param dev[in, out]
10232 * Pointer to rte_eth_dev structure.
10233 * @param[in, out] tag_be24
10234 * Tag value in big endian then R-shift 8.
10235 * @parm[in, out] dev_flow
10236 * Pointer to the dev_flow.
10237 * @param[out] error
10238 * pointer to error structure.
10241 * 0 on success otherwise -errno and errno is set.
10244 flow_dv_tag_resource_register
10245 (struct rte_eth_dev *dev,
10247 struct mlx5_flow *dev_flow,
10248 struct rte_flow_error *error)
10250 struct mlx5_priv *priv = dev->data->dev_private;
10251 struct mlx5_flow_dv_tag_resource *cache_resource;
10252 struct mlx5_hlist_entry *entry;
10254 entry = mlx5_hlist_register(priv->sh->tag_table, tag_be24, error);
10256 cache_resource = container_of
10257 (entry, struct mlx5_flow_dv_tag_resource, entry);
10258 dev_flow->handle->dvh.rix_tag = cache_resource->idx;
10259 dev_flow->dv.tag_resource = cache_resource;
10266 flow_dv_tag_remove_cb(struct mlx5_hlist *list,
10267 struct mlx5_hlist_entry *entry)
10269 struct mlx5_dev_ctx_shared *sh = list->ctx;
10270 struct mlx5_flow_dv_tag_resource *tag =
10271 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
10273 MLX5_ASSERT(tag && sh && tag->action);
10274 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
10275 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
10276 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
10283 * Pointer to Ethernet device.
10288 * 1 while a reference on it exists, 0 when freed.
10291 flow_dv_tag_release(struct rte_eth_dev *dev,
10294 struct mlx5_priv *priv = dev->data->dev_private;
10295 struct mlx5_flow_dv_tag_resource *tag;
10297 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
10300 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
10301 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
10302 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
10306 * Translate port ID action to vport.
10309 * Pointer to rte_eth_dev structure.
10310 * @param[in] action
10311 * Pointer to the port ID action.
10312 * @param[out] dst_port_id
10313 * The target port ID.
10314 * @param[out] error
10315 * Pointer to the error structure.
10318 * 0 on success, a negative errno value otherwise and rte_errno is set.
10321 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
10322 const struct rte_flow_action *action,
10323 uint32_t *dst_port_id,
10324 struct rte_flow_error *error)
10327 struct mlx5_priv *priv;
10328 const struct rte_flow_action_port_id *conf =
10329 (const struct rte_flow_action_port_id *)action->conf;
10331 port = conf->original ? dev->data->port_id : conf->id;
10332 priv = mlx5_port_to_eswitch_info(port, false);
10334 return rte_flow_error_set(error, -rte_errno,
10335 RTE_FLOW_ERROR_TYPE_ACTION,
10337 "No eswitch info was found for port");
10338 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
10340 * This parameter is transferred to
10341 * mlx5dv_dr_action_create_dest_ib_port().
10343 *dst_port_id = priv->dev_port;
10346 * Legacy mode, no LAG configurations is supported.
10347 * This parameter is transferred to
10348 * mlx5dv_dr_action_create_dest_vport().
10350 *dst_port_id = priv->vport_id;
10356 * Create a counter with aging configuration.
10359 * Pointer to rte_eth_dev structure.
10360 * @param[in] dev_flow
10361 * Pointer to the mlx5_flow.
10362 * @param[out] count
10363 * Pointer to the counter action configuration.
10365 * Pointer to the aging action configuration.
10368 * Index to flow counter on success, 0 otherwise.
10371 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
10372 struct mlx5_flow *dev_flow,
10373 const struct rte_flow_action_count *count,
10374 const struct rte_flow_action_age *age)
10377 struct mlx5_age_param *age_param;
10379 if (count && count->shared)
10380 counter = flow_dv_counter_get_shared(dev, count->id);
10382 counter = flow_dv_counter_alloc(dev, !!age);
10383 if (!counter || age == NULL)
10385 age_param = flow_dv_counter_idx_get_age(dev, counter);
10386 age_param->context = age->context ? age->context :
10387 (void *)(uintptr_t)(dev_flow->flow_idx);
10388 age_param->timeout = age->timeout;
10389 age_param->port_id = dev->data->port_id;
10390 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
10391 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
10396 * Add Tx queue matcher
10399 * Pointer to the dev struct.
10400 * @param[in, out] matcher
10402 * @param[in, out] key
10403 * Flow matcher value.
10405 * Flow pattern to translate.
10407 * Item is inner pattern.
10410 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
10411 void *matcher, void *key,
10412 const struct rte_flow_item *item)
10414 const struct mlx5_rte_flow_item_tx_queue *queue_m;
10415 const struct mlx5_rte_flow_item_tx_queue *queue_v;
10417 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
10419 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10420 struct mlx5_txq_ctrl *txq;
10424 queue_m = (const void *)item->mask;
10427 queue_v = (const void *)item->spec;
10430 txq = mlx5_txq_get(dev, queue_v->queue);
10433 queue = txq->obj->sq->id;
10434 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
10435 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
10436 queue & queue_m->queue);
10437 mlx5_txq_release(dev, queue_v->queue);
10441 * Set the hash fields according to the @p flow information.
10443 * @param[in] dev_flow
10444 * Pointer to the mlx5_flow.
10445 * @param[in] rss_desc
10446 * Pointer to the mlx5_flow_rss_desc.
10449 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
10450 struct mlx5_flow_rss_desc *rss_desc)
10452 uint64_t items = dev_flow->handle->layers;
10454 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
10456 dev_flow->hash_fields = 0;
10457 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
10458 if (rss_desc->level >= 2) {
10459 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
10463 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
10464 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
10465 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
10466 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10467 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
10468 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10469 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
10471 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
10473 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
10474 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
10475 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
10476 if (rss_types & ETH_RSS_L3_SRC_ONLY)
10477 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
10478 else if (rss_types & ETH_RSS_L3_DST_ONLY)
10479 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
10481 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
10484 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
10485 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
10486 if (rss_types & ETH_RSS_UDP) {
10487 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10488 dev_flow->hash_fields |=
10489 IBV_RX_HASH_SRC_PORT_UDP;
10490 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10491 dev_flow->hash_fields |=
10492 IBV_RX_HASH_DST_PORT_UDP;
10494 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
10496 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
10497 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
10498 if (rss_types & ETH_RSS_TCP) {
10499 if (rss_types & ETH_RSS_L4_SRC_ONLY)
10500 dev_flow->hash_fields |=
10501 IBV_RX_HASH_SRC_PORT_TCP;
10502 else if (rss_types & ETH_RSS_L4_DST_ONLY)
10503 dev_flow->hash_fields |=
10504 IBV_RX_HASH_DST_PORT_TCP;
10506 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
10512 * Prepare an Rx Hash queue.
10515 * Pointer to Ethernet device.
10516 * @param[in] dev_flow
10517 * Pointer to the mlx5_flow.
10518 * @param[in] rss_desc
10519 * Pointer to the mlx5_flow_rss_desc.
10520 * @param[out] hrxq_idx
10521 * Hash Rx queue index.
10524 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
10526 static struct mlx5_hrxq *
10527 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
10528 struct mlx5_flow *dev_flow,
10529 struct mlx5_flow_rss_desc *rss_desc,
10530 uint32_t *hrxq_idx)
10532 struct mlx5_priv *priv = dev->data->dev_private;
10533 struct mlx5_flow_handle *dh = dev_flow->handle;
10534 struct mlx5_hrxq *hrxq;
10536 MLX5_ASSERT(rss_desc->queue_num);
10537 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
10538 rss_desc->hash_fields = dev_flow->hash_fields;
10539 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
10540 rss_desc->shared_rss = 0;
10541 *hrxq_idx = mlx5_hrxq_get(dev, rss_desc);
10544 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
10550 * Release sample sub action resource.
10552 * @param[in, out] dev
10553 * Pointer to rte_eth_dev structure.
10554 * @param[in] act_res
10555 * Pointer to sample sub action resource.
10558 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
10559 struct mlx5_flow_sub_actions_idx *act_res)
10561 if (act_res->rix_hrxq) {
10562 mlx5_hrxq_release(dev, act_res->rix_hrxq);
10563 act_res->rix_hrxq = 0;
10565 if (act_res->rix_encap_decap) {
10566 flow_dv_encap_decap_resource_release(dev,
10567 act_res->rix_encap_decap);
10568 act_res->rix_encap_decap = 0;
10570 if (act_res->rix_port_id_action) {
10571 flow_dv_port_id_action_resource_release(dev,
10572 act_res->rix_port_id_action);
10573 act_res->rix_port_id_action = 0;
10575 if (act_res->rix_tag) {
10576 flow_dv_tag_release(dev, act_res->rix_tag);
10577 act_res->rix_tag = 0;
10579 if (act_res->rix_jump) {
10580 flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
10581 act_res->rix_jump = 0;
10586 flow_dv_sample_match_cb(struct mlx5_cache_list *list __rte_unused,
10587 struct mlx5_cache_entry *entry, void *cb_ctx)
10589 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10590 struct rte_eth_dev *dev = ctx->dev;
10591 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
10592 struct mlx5_flow_dv_sample_resource *cache_resource =
10593 container_of(entry, typeof(*cache_resource), entry);
10595 if (resource->ratio == cache_resource->ratio &&
10596 resource->ft_type == cache_resource->ft_type &&
10597 resource->ft_id == cache_resource->ft_id &&
10598 resource->set_action == cache_resource->set_action &&
10599 !memcmp((void *)&resource->sample_act,
10600 (void *)&cache_resource->sample_act,
10601 sizeof(struct mlx5_flow_sub_actions_list))) {
10603 * Existing sample action should release the prepared
10604 * sub-actions reference counter.
10606 flow_dv_sample_sub_actions_release(dev,
10607 &resource->sample_idx);
10613 struct mlx5_cache_entry *
10614 flow_dv_sample_create_cb(struct mlx5_cache_list *list __rte_unused,
10615 struct mlx5_cache_entry *entry __rte_unused,
10618 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10619 struct rte_eth_dev *dev = ctx->dev;
10620 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
10621 void **sample_dv_actions = resource->sub_actions;
10622 struct mlx5_flow_dv_sample_resource *cache_resource;
10623 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
10624 struct mlx5_priv *priv = dev->data->dev_private;
10625 struct mlx5_dev_ctx_shared *sh = priv->sh;
10626 struct mlx5_flow_tbl_resource *tbl;
10628 const uint32_t next_ft_step = 1;
10629 uint32_t next_ft_id = resource->ft_id + next_ft_step;
10630 uint8_t is_egress = 0;
10631 uint8_t is_transfer = 0;
10632 struct rte_flow_error *error = ctx->error;
10634 /* Register new sample resource. */
10635 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
10636 if (!cache_resource) {
10637 rte_flow_error_set(error, ENOMEM,
10638 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10640 "cannot allocate resource memory");
10643 *cache_resource = *resource;
10644 /* Create normal path table level */
10645 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
10647 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
10649 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
10650 is_egress, is_transfer,
10651 true, NULL, 0, 0, 0, error);
10653 rte_flow_error_set(error, ENOMEM,
10654 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10656 "fail to create normal path table "
10660 cache_resource->normal_path_tbl = tbl;
10661 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
10662 if (!sh->default_miss_action) {
10663 rte_flow_error_set(error, ENOMEM,
10664 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10666 "default miss action was not "
10670 sample_dv_actions[resource->sample_act.actions_num++] =
10671 sh->default_miss_action;
10673 /* Create a DR sample action */
10674 sampler_attr.sample_ratio = cache_resource->ratio;
10675 sampler_attr.default_next_table = tbl->obj;
10676 sampler_attr.num_sample_actions = resource->sample_act.actions_num;
10677 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
10678 &sample_dv_actions[0];
10679 sampler_attr.action = cache_resource->set_action;
10680 if (mlx5_os_flow_dr_create_flow_action_sampler
10681 (&sampler_attr, &cache_resource->verbs_action)) {
10682 rte_flow_error_set(error, ENOMEM,
10683 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10684 NULL, "cannot create sample action");
10687 cache_resource->idx = idx;
10688 cache_resource->dev = dev;
10689 return &cache_resource->entry;
10691 if (cache_resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
10692 flow_dv_sample_sub_actions_release(dev,
10693 &cache_resource->sample_idx);
10694 if (cache_resource->normal_path_tbl)
10695 flow_dv_tbl_resource_release(MLX5_SH(dev),
10696 cache_resource->normal_path_tbl);
10697 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
10703 * Find existing sample resource or create and register a new one.
10705 * @param[in, out] dev
10706 * Pointer to rte_eth_dev structure.
10707 * @param[in] resource
10708 * Pointer to sample resource.
10709 * @parm[in, out] dev_flow
10710 * Pointer to the dev_flow.
10711 * @param[out] error
10712 * pointer to error structure.
10715 * 0 on success otherwise -errno and errno is set.
10718 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
10719 struct mlx5_flow_dv_sample_resource *resource,
10720 struct mlx5_flow *dev_flow,
10721 struct rte_flow_error *error)
10723 struct mlx5_flow_dv_sample_resource *cache_resource;
10724 struct mlx5_cache_entry *entry;
10725 struct mlx5_priv *priv = dev->data->dev_private;
10726 struct mlx5_flow_cb_ctx ctx = {
10732 entry = mlx5_cache_register(&priv->sh->sample_action_list, &ctx);
10735 cache_resource = container_of(entry, typeof(*cache_resource), entry);
10736 dev_flow->handle->dvh.rix_sample = cache_resource->idx;
10737 dev_flow->dv.sample_res = cache_resource;
10742 flow_dv_dest_array_match_cb(struct mlx5_cache_list *list __rte_unused,
10743 struct mlx5_cache_entry *entry, void *cb_ctx)
10745 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10746 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
10747 struct rte_eth_dev *dev = ctx->dev;
10748 struct mlx5_flow_dv_dest_array_resource *cache_resource =
10749 container_of(entry, typeof(*cache_resource), entry);
10752 if (resource->num_of_dest == cache_resource->num_of_dest &&
10753 resource->ft_type == cache_resource->ft_type &&
10754 !memcmp((void *)cache_resource->sample_act,
10755 (void *)resource->sample_act,
10756 (resource->num_of_dest *
10757 sizeof(struct mlx5_flow_sub_actions_list)))) {
10759 * Existing sample action should release the prepared
10760 * sub-actions reference counter.
10762 for (idx = 0; idx < resource->num_of_dest; idx++)
10763 flow_dv_sample_sub_actions_release(dev,
10764 &resource->sample_idx[idx]);
10770 struct mlx5_cache_entry *
10771 flow_dv_dest_array_create_cb(struct mlx5_cache_list *list __rte_unused,
10772 struct mlx5_cache_entry *entry __rte_unused,
10775 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
10776 struct rte_eth_dev *dev = ctx->dev;
10777 struct mlx5_flow_dv_dest_array_resource *cache_resource;
10778 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
10779 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
10780 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
10781 struct mlx5_priv *priv = dev->data->dev_private;
10782 struct mlx5_dev_ctx_shared *sh = priv->sh;
10783 struct mlx5_flow_sub_actions_list *sample_act;
10784 struct mlx5dv_dr_domain *domain;
10785 uint32_t idx = 0, res_idx = 0;
10786 struct rte_flow_error *error = ctx->error;
10787 uint64_t action_flags;
10790 /* Register new destination array resource. */
10791 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
10793 if (!cache_resource) {
10794 rte_flow_error_set(error, ENOMEM,
10795 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10797 "cannot allocate resource memory");
10800 *cache_resource = *resource;
10801 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
10802 domain = sh->fdb_domain;
10803 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
10804 domain = sh->rx_domain;
10806 domain = sh->tx_domain;
10807 for (idx = 0; idx < resource->num_of_dest; idx++) {
10808 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
10809 mlx5_malloc(MLX5_MEM_ZERO,
10810 sizeof(struct mlx5dv_dr_action_dest_attr),
10812 if (!dest_attr[idx]) {
10813 rte_flow_error_set(error, ENOMEM,
10814 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10816 "cannot allocate resource memory");
10819 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
10820 sample_act = &resource->sample_act[idx];
10821 action_flags = sample_act->action_flags;
10822 switch (action_flags) {
10823 case MLX5_FLOW_ACTION_QUEUE:
10824 dest_attr[idx]->dest = sample_act->dr_queue_action;
10826 case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
10827 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
10828 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
10829 dest_attr[idx]->dest_reformat->reformat =
10830 sample_act->dr_encap_action;
10831 dest_attr[idx]->dest_reformat->dest =
10832 sample_act->dr_port_id_action;
10834 case MLX5_FLOW_ACTION_PORT_ID:
10835 dest_attr[idx]->dest = sample_act->dr_port_id_action;
10837 case MLX5_FLOW_ACTION_JUMP:
10838 dest_attr[idx]->dest = sample_act->dr_jump_action;
10841 rte_flow_error_set(error, EINVAL,
10842 RTE_FLOW_ERROR_TYPE_ACTION,
10844 "unsupported actions type");
10848 /* create a dest array actioin */
10849 ret = mlx5_os_flow_dr_create_flow_action_dest_array
10851 cache_resource->num_of_dest,
10853 &cache_resource->action);
10855 rte_flow_error_set(error, ENOMEM,
10856 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10858 "cannot create destination array action");
10861 cache_resource->idx = res_idx;
10862 cache_resource->dev = dev;
10863 for (idx = 0; idx < resource->num_of_dest; idx++)
10864 mlx5_free(dest_attr[idx]);
10865 return &cache_resource->entry;
10867 for (idx = 0; idx < resource->num_of_dest; idx++) {
10868 flow_dv_sample_sub_actions_release(dev,
10869 &cache_resource->sample_idx[idx]);
10870 if (dest_attr[idx])
10871 mlx5_free(dest_attr[idx]);
10874 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
10879 * Find existing destination array resource or create and register a new one.
10881 * @param[in, out] dev
10882 * Pointer to rte_eth_dev structure.
10883 * @param[in] resource
10884 * Pointer to destination array resource.
10885 * @parm[in, out] dev_flow
10886 * Pointer to the dev_flow.
10887 * @param[out] error
10888 * pointer to error structure.
10891 * 0 on success otherwise -errno and errno is set.
10894 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
10895 struct mlx5_flow_dv_dest_array_resource *resource,
10896 struct mlx5_flow *dev_flow,
10897 struct rte_flow_error *error)
10899 struct mlx5_flow_dv_dest_array_resource *cache_resource;
10900 struct mlx5_priv *priv = dev->data->dev_private;
10901 struct mlx5_cache_entry *entry;
10902 struct mlx5_flow_cb_ctx ctx = {
10908 entry = mlx5_cache_register(&priv->sh->dest_array_list, &ctx);
10911 cache_resource = container_of(entry, typeof(*cache_resource), entry);
10912 dev_flow->handle->dvh.rix_dest_array = cache_resource->idx;
10913 dev_flow->dv.dest_array_res = cache_resource;
10918 * Convert Sample action to DV specification.
10921 * Pointer to rte_eth_dev structure.
10922 * @param[in] action
10923 * Pointer to sample action structure.
10924 * @param[in, out] dev_flow
10925 * Pointer to the mlx5_flow.
10927 * Pointer to the flow attributes.
10928 * @param[in, out] num_of_dest
10929 * Pointer to the num of destination.
10930 * @param[in, out] sample_actions
10931 * Pointer to sample actions list.
10932 * @param[in, out] res
10933 * Pointer to sample resource.
10934 * @param[out] error
10935 * Pointer to the error structure.
10938 * 0 on success, a negative errno value otherwise and rte_errno is set.
10941 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
10942 const struct rte_flow_action_sample *action,
10943 struct mlx5_flow *dev_flow,
10944 const struct rte_flow_attr *attr,
10945 uint32_t *num_of_dest,
10946 void **sample_actions,
10947 struct mlx5_flow_dv_sample_resource *res,
10948 struct rte_flow_error *error)
10950 struct mlx5_priv *priv = dev->data->dev_private;
10951 const struct rte_flow_action *sub_actions;
10952 struct mlx5_flow_sub_actions_list *sample_act;
10953 struct mlx5_flow_sub_actions_idx *sample_idx;
10954 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10955 struct rte_flow *flow = dev_flow->flow;
10956 struct mlx5_flow_rss_desc *rss_desc;
10957 uint64_t action_flags = 0;
10960 rss_desc = &wks->rss_desc;
10961 sample_act = &res->sample_act;
10962 sample_idx = &res->sample_idx;
10963 res->ratio = action->ratio;
10964 sub_actions = action->actions;
10965 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
10966 int type = sub_actions->type;
10967 uint32_t pre_rix = 0;
10970 case RTE_FLOW_ACTION_TYPE_QUEUE:
10972 const struct rte_flow_action_queue *queue;
10973 struct mlx5_hrxq *hrxq;
10976 queue = sub_actions->conf;
10977 rss_desc->queue_num = 1;
10978 rss_desc->queue[0] = queue->index;
10979 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
10980 rss_desc, &hrxq_idx);
10982 return rte_flow_error_set
10984 RTE_FLOW_ERROR_TYPE_ACTION,
10986 "cannot create fate queue");
10987 sample_act->dr_queue_action = hrxq->action;
10988 sample_idx->rix_hrxq = hrxq_idx;
10989 sample_actions[sample_act->actions_num++] =
10992 action_flags |= MLX5_FLOW_ACTION_QUEUE;
10993 if (action_flags & MLX5_FLOW_ACTION_MARK)
10994 dev_flow->handle->rix_hrxq = hrxq_idx;
10995 dev_flow->handle->fate_action =
10996 MLX5_FLOW_FATE_QUEUE;
10999 case RTE_FLOW_ACTION_TYPE_RSS:
11001 struct mlx5_hrxq *hrxq;
11003 const struct rte_flow_action_rss *rss;
11004 const uint8_t *rss_key;
11006 rss = sub_actions->conf;
11007 memcpy(rss_desc->queue, rss->queue,
11008 rss->queue_num * sizeof(uint16_t));
11009 rss_desc->queue_num = rss->queue_num;
11010 /* NULL RSS key indicates default RSS key. */
11011 rss_key = !rss->key ? rss_hash_default_key : rss->key;
11012 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
11014 * rss->level and rss.types should be set in advance
11015 * when expanding items for RSS.
11017 flow_dv_hashfields_set(dev_flow, rss_desc);
11018 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11019 rss_desc, &hrxq_idx);
11021 return rte_flow_error_set
11023 RTE_FLOW_ERROR_TYPE_ACTION,
11025 "cannot create fate queue");
11026 sample_act->dr_queue_action = hrxq->action;
11027 sample_idx->rix_hrxq = hrxq_idx;
11028 sample_actions[sample_act->actions_num++] =
11031 action_flags |= MLX5_FLOW_ACTION_RSS;
11032 if (action_flags & MLX5_FLOW_ACTION_MARK)
11033 dev_flow->handle->rix_hrxq = hrxq_idx;
11034 dev_flow->handle->fate_action =
11035 MLX5_FLOW_FATE_QUEUE;
11038 case RTE_FLOW_ACTION_TYPE_MARK:
11040 uint32_t tag_be = mlx5_flow_mark_set
11041 (((const struct rte_flow_action_mark *)
11042 (sub_actions->conf))->id);
11044 dev_flow->handle->mark = 1;
11045 pre_rix = dev_flow->handle->dvh.rix_tag;
11046 /* Save the mark resource before sample */
11047 pre_r = dev_flow->dv.tag_resource;
11048 if (flow_dv_tag_resource_register(dev, tag_be,
11051 MLX5_ASSERT(dev_flow->dv.tag_resource);
11052 sample_act->dr_tag_action =
11053 dev_flow->dv.tag_resource->action;
11054 sample_idx->rix_tag =
11055 dev_flow->handle->dvh.rix_tag;
11056 sample_actions[sample_act->actions_num++] =
11057 sample_act->dr_tag_action;
11058 /* Recover the mark resource after sample */
11059 dev_flow->dv.tag_resource = pre_r;
11060 dev_flow->handle->dvh.rix_tag = pre_rix;
11061 action_flags |= MLX5_FLOW_ACTION_MARK;
11064 case RTE_FLOW_ACTION_TYPE_COUNT:
11066 if (!flow->counter) {
11068 flow_dv_translate_create_counter(dev,
11069 dev_flow, sub_actions->conf,
11071 if (!flow->counter)
11072 return rte_flow_error_set
11074 RTE_FLOW_ERROR_TYPE_ACTION,
11076 "cannot create counter"
11079 sample_act->dr_cnt_action =
11080 (flow_dv_counter_get_by_idx(dev,
11081 flow->counter, NULL))->action;
11082 sample_actions[sample_act->actions_num++] =
11083 sample_act->dr_cnt_action;
11084 action_flags |= MLX5_FLOW_ACTION_COUNT;
11087 case RTE_FLOW_ACTION_TYPE_PORT_ID:
11089 struct mlx5_flow_dv_port_id_action_resource
11091 uint32_t port_id = 0;
11093 memset(&port_id_resource, 0, sizeof(port_id_resource));
11094 /* Save the port id resource before sample */
11095 pre_rix = dev_flow->handle->rix_port_id_action;
11096 pre_r = dev_flow->dv.port_id_action;
11097 if (flow_dv_translate_action_port_id(dev, sub_actions,
11100 port_id_resource.port_id = port_id;
11101 if (flow_dv_port_id_action_resource_register
11102 (dev, &port_id_resource, dev_flow, error))
11104 sample_act->dr_port_id_action =
11105 dev_flow->dv.port_id_action->action;
11106 sample_idx->rix_port_id_action =
11107 dev_flow->handle->rix_port_id_action;
11108 sample_actions[sample_act->actions_num++] =
11109 sample_act->dr_port_id_action;
11110 /* Recover the port id resource after sample */
11111 dev_flow->dv.port_id_action = pre_r;
11112 dev_flow->handle->rix_port_id_action = pre_rix;
11114 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
11117 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
11118 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
11119 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
11120 /* Save the encap resource before sample */
11121 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
11122 pre_r = dev_flow->dv.encap_decap;
11123 if (flow_dv_create_action_l2_encap(dev, sub_actions,
11128 sample_act->dr_encap_action =
11129 dev_flow->dv.encap_decap->action;
11130 sample_idx->rix_encap_decap =
11131 dev_flow->handle->dvh.rix_encap_decap;
11132 sample_actions[sample_act->actions_num++] =
11133 sample_act->dr_encap_action;
11134 /* Recover the encap resource after sample */
11135 dev_flow->dv.encap_decap = pre_r;
11136 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
11137 action_flags |= MLX5_FLOW_ACTION_ENCAP;
11140 return rte_flow_error_set(error, EINVAL,
11141 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11143 "Not support for sampler action");
11146 sample_act->action_flags = action_flags;
11147 res->ft_id = dev_flow->dv.group;
11148 if (attr->transfer) {
11150 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
11151 uint64_t set_action;
11152 } action_ctx = { .set_action = 0 };
11154 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
11155 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
11156 MLX5_MODIFICATION_TYPE_SET);
11157 MLX5_SET(set_action_in, action_ctx.action_in, field,
11158 MLX5_MODI_META_REG_C_0);
11159 MLX5_SET(set_action_in, action_ctx.action_in, data,
11160 priv->vport_meta_tag);
11161 res->set_action = action_ctx.set_action;
11162 } else if (attr->ingress) {
11163 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
11165 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
11171 * Convert Sample action to DV specification.
11174 * Pointer to rte_eth_dev structure.
11175 * @param[in, out] dev_flow
11176 * Pointer to the mlx5_flow.
11177 * @param[in] num_of_dest
11178 * The num of destination.
11179 * @param[in, out] res
11180 * Pointer to sample resource.
11181 * @param[in, out] mdest_res
11182 * Pointer to destination array resource.
11183 * @param[in] sample_actions
11184 * Pointer to sample path actions list.
11185 * @param[in] action_flags
11186 * Holds the actions detected until now.
11187 * @param[out] error
11188 * Pointer to the error structure.
11191 * 0 on success, a negative errno value otherwise and rte_errno is set.
11194 flow_dv_create_action_sample(struct rte_eth_dev *dev,
11195 struct mlx5_flow *dev_flow,
11196 uint32_t num_of_dest,
11197 struct mlx5_flow_dv_sample_resource *res,
11198 struct mlx5_flow_dv_dest_array_resource *mdest_res,
11199 void **sample_actions,
11200 uint64_t action_flags,
11201 struct rte_flow_error *error)
11203 /* update normal path action resource into last index of array */
11204 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
11205 struct mlx5_flow_sub_actions_list *sample_act =
11206 &mdest_res->sample_act[dest_index];
11207 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11208 struct mlx5_flow_rss_desc *rss_desc;
11209 uint32_t normal_idx = 0;
11210 struct mlx5_hrxq *hrxq;
11214 rss_desc = &wks->rss_desc;
11215 if (num_of_dest > 1) {
11216 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
11217 /* Handle QP action for mirroring */
11218 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
11219 rss_desc, &hrxq_idx);
11221 return rte_flow_error_set
11223 RTE_FLOW_ERROR_TYPE_ACTION,
11225 "cannot create rx queue");
11227 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
11228 sample_act->dr_queue_action = hrxq->action;
11229 if (action_flags & MLX5_FLOW_ACTION_MARK)
11230 dev_flow->handle->rix_hrxq = hrxq_idx;
11231 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
11233 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
11235 mdest_res->sample_idx[dest_index].rix_encap_decap =
11236 dev_flow->handle->dvh.rix_encap_decap;
11237 sample_act->dr_encap_action =
11238 dev_flow->dv.encap_decap->action;
11239 dev_flow->handle->dvh.rix_encap_decap = 0;
11241 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
11243 mdest_res->sample_idx[dest_index].rix_port_id_action =
11244 dev_flow->handle->rix_port_id_action;
11245 sample_act->dr_port_id_action =
11246 dev_flow->dv.port_id_action->action;
11247 dev_flow->handle->rix_port_id_action = 0;
11249 if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
11251 mdest_res->sample_idx[dest_index].rix_jump =
11252 dev_flow->handle->rix_jump;
11253 sample_act->dr_jump_action =
11254 dev_flow->dv.jump->action;
11255 dev_flow->handle->rix_jump = 0;
11257 sample_act->actions_num = normal_idx;
11258 /* update sample action resource into first index of array */
11259 mdest_res->ft_type = res->ft_type;
11260 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
11261 sizeof(struct mlx5_flow_sub_actions_idx));
11262 memcpy(&mdest_res->sample_act[0], &res->sample_act,
11263 sizeof(struct mlx5_flow_sub_actions_list));
11264 mdest_res->num_of_dest = num_of_dest;
11265 if (flow_dv_dest_array_resource_register(dev, mdest_res,
11267 return rte_flow_error_set(error, EINVAL,
11268 RTE_FLOW_ERROR_TYPE_ACTION,
11269 NULL, "can't create sample "
11272 res->sub_actions = sample_actions;
11273 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
11274 return rte_flow_error_set(error, EINVAL,
11275 RTE_FLOW_ERROR_TYPE_ACTION,
11277 "can't create sample action");
11283 * Remove an ASO age action from age actions list.
11286 * Pointer to the Ethernet device structure.
11288 * Pointer to the aso age action handler.
11291 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
11292 struct mlx5_aso_age_action *age)
11294 struct mlx5_age_info *age_info;
11295 struct mlx5_age_param *age_param = &age->age_params;
11296 struct mlx5_priv *priv = dev->data->dev_private;
11297 uint16_t expected = AGE_CANDIDATE;
11299 age_info = GET_PORT_AGE_INFO(priv);
11300 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
11301 AGE_FREE, false, __ATOMIC_RELAXED,
11302 __ATOMIC_RELAXED)) {
11304 * We need the lock even it is age timeout,
11305 * since age action may still in process.
11307 rte_spinlock_lock(&age_info->aged_sl);
11308 LIST_REMOVE(age, next);
11309 rte_spinlock_unlock(&age_info->aged_sl);
11310 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
11315 * Release an ASO age action.
11318 * Pointer to the Ethernet device structure.
11319 * @param[in] age_idx
11320 * Index of ASO age action to release.
11322 * True if the release operation is during flow destroy operation.
11323 * False if the release operation is during action destroy operation.
11326 * 0 when age action was removed, otherwise the number of references.
11329 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
11331 struct mlx5_priv *priv = dev->data->dev_private;
11332 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11333 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
11334 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
11337 flow_dv_aso_age_remove_from_age(dev, age);
11338 rte_spinlock_lock(&mng->free_sl);
11339 LIST_INSERT_HEAD(&mng->free, age, next);
11340 rte_spinlock_unlock(&mng->free_sl);
11346 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
11349 * Pointer to the Ethernet device structure.
11352 * 0 on success, otherwise negative errno value and rte_errno is set.
11355 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
11357 struct mlx5_priv *priv = dev->data->dev_private;
11358 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11359 void *old_pools = mng->pools;
11360 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
11361 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
11362 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11365 rte_errno = ENOMEM;
11369 memcpy(pools, old_pools,
11370 mng->n * sizeof(struct mlx5_flow_counter_pool *));
11371 mlx5_free(old_pools);
11373 /* First ASO flow hit allocation - starting ASO data-path. */
11374 int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
11382 mng->pools = pools;
11387 * Create and initialize a new ASO aging pool.
11390 * Pointer to the Ethernet device structure.
11391 * @param[out] age_free
11392 * Where to put the pointer of a new age action.
11395 * The age actions pool pointer and @p age_free is set on success,
11396 * NULL otherwise and rte_errno is set.
11398 static struct mlx5_aso_age_pool *
11399 flow_dv_age_pool_create(struct rte_eth_dev *dev,
11400 struct mlx5_aso_age_action **age_free)
11402 struct mlx5_priv *priv = dev->data->dev_private;
11403 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11404 struct mlx5_aso_age_pool *pool = NULL;
11405 struct mlx5_devx_obj *obj = NULL;
11408 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->ctx,
11411 rte_errno = ENODATA;
11412 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
11415 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
11417 claim_zero(mlx5_devx_cmd_destroy(obj));
11418 rte_errno = ENOMEM;
11421 pool->flow_hit_aso_obj = obj;
11422 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
11423 rte_spinlock_lock(&mng->resize_sl);
11424 pool->index = mng->next;
11425 /* Resize pools array if there is no room for the new pool in it. */
11426 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
11427 claim_zero(mlx5_devx_cmd_destroy(obj));
11429 rte_spinlock_unlock(&mng->resize_sl);
11432 mng->pools[pool->index] = pool;
11434 rte_spinlock_unlock(&mng->resize_sl);
11435 /* Assign the first action in the new pool, the rest go to free list. */
11436 *age_free = &pool->actions[0];
11437 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
11438 pool->actions[i].offset = i;
11439 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
11445 * Allocate a ASO aging bit.
11448 * Pointer to the Ethernet device structure.
11449 * @param[out] error
11450 * Pointer to the error structure.
11453 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
11456 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
11458 struct mlx5_priv *priv = dev->data->dev_private;
11459 const struct mlx5_aso_age_pool *pool;
11460 struct mlx5_aso_age_action *age_free = NULL;
11461 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
11464 /* Try to get the next free age action bit. */
11465 rte_spinlock_lock(&mng->free_sl);
11466 age_free = LIST_FIRST(&mng->free);
11468 LIST_REMOVE(age_free, next);
11469 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
11470 rte_spinlock_unlock(&mng->free_sl);
11471 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
11472 NULL, "failed to create ASO age pool");
11473 return 0; /* 0 is an error. */
11475 rte_spinlock_unlock(&mng->free_sl);
11476 pool = container_of
11477 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
11478 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
11480 if (!age_free->dr_action) {
11481 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
11485 rte_flow_error_set(error, rte_errno,
11486 RTE_FLOW_ERROR_TYPE_ACTION,
11487 NULL, "failed to get reg_c "
11488 "for ASO flow hit");
11489 return 0; /* 0 is an error. */
11491 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
11492 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
11493 (priv->sh->rx_domain,
11494 pool->flow_hit_aso_obj->obj, age_free->offset,
11495 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
11496 (reg_c - REG_C_0));
11497 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
11498 if (!age_free->dr_action) {
11500 rte_spinlock_lock(&mng->free_sl);
11501 LIST_INSERT_HEAD(&mng->free, age_free, next);
11502 rte_spinlock_unlock(&mng->free_sl);
11503 rte_flow_error_set(error, rte_errno,
11504 RTE_FLOW_ERROR_TYPE_ACTION,
11505 NULL, "failed to create ASO "
11506 "flow hit action");
11507 return 0; /* 0 is an error. */
11510 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
11511 return pool->index | ((age_free->offset + 1) << 16);
11515 * Initialize flow ASO age parameters.
11518 * Pointer to rte_eth_dev structure.
11519 * @param[in] age_idx
11520 * Index of ASO age action.
11521 * @param[in] context
11522 * Pointer to flow counter age context.
11523 * @param[in] timeout
11524 * Aging timeout in seconds.
11528 flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
11533 struct mlx5_aso_age_action *aso_age;
11535 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
11536 MLX5_ASSERT(aso_age);
11537 aso_age->age_params.context = context;
11538 aso_age->age_params.timeout = timeout;
11539 aso_age->age_params.port_id = dev->data->port_id;
11540 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
11542 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
11547 flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
11548 const struct rte_flow_item_integrity *value,
11549 void *headers_m, void *headers_v)
11552 /* application l4_ok filter aggregates all hardware l4 filters
11553 * therefore hw l4_checksum_ok must be implicitly added here.
11555 struct rte_flow_item_integrity local_item;
11557 local_item.l4_csum_ok = 1;
11558 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
11559 local_item.l4_csum_ok);
11560 if (value->l4_ok) {
11561 /* application l4_ok = 1 matches sets both hw flags
11562 * l4_ok and l4_checksum_ok flags to 1.
11564 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11565 l4_checksum_ok, local_item.l4_csum_ok);
11566 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_ok,
11568 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l4_ok,
11571 /* application l4_ok = 0 matches on hw flag
11572 * l4_checksum_ok = 0 only.
11574 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11575 l4_checksum_ok, 0);
11577 } else if (mask->l4_csum_ok) {
11578 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l4_checksum_ok,
11580 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
11581 value->l4_csum_ok);
11586 flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
11587 const struct rte_flow_item_integrity *value,
11588 void *headers_m, void *headers_v,
11592 /* application l3_ok filter aggregates all hardware l3 filters
11593 * therefore hw ipv4_checksum_ok must be implicitly added here.
11595 struct rte_flow_item_integrity local_item;
11597 local_item.ipv4_csum_ok = !!is_ipv4;
11598 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
11599 local_item.ipv4_csum_ok);
11600 if (value->l3_ok) {
11601 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11602 ipv4_checksum_ok, local_item.ipv4_csum_ok);
11603 MLX5_SET(fte_match_set_lyr_2_4, headers_m, l3_ok,
11605 MLX5_SET(fte_match_set_lyr_2_4, headers_v, l3_ok,
11608 MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11609 ipv4_checksum_ok, 0);
11611 } else if (mask->ipv4_csum_ok) {
11612 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ipv4_checksum_ok,
11613 mask->ipv4_csum_ok);
11614 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_checksum_ok,
11615 value->ipv4_csum_ok);
11620 flow_dv_translate_item_integrity(void *matcher, void *key,
11621 const struct rte_flow_item *head_item,
11622 const struct rte_flow_item *integrity_item)
11624 const struct rte_flow_item_integrity *mask = integrity_item->mask;
11625 const struct rte_flow_item_integrity *value = integrity_item->spec;
11626 const struct rte_flow_item *tunnel_item, *end_item, *item;
11629 uint32_t l3_protocol;
11634 mask = &rte_flow_item_integrity_mask;
11635 if (value->level > 1) {
11636 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
11638 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
11640 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
11642 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11644 tunnel_item = mlx5_flow_find_tunnel_item(head_item);
11645 if (value->level > 1) {
11646 /* tunnel item was verified during the item validation */
11647 item = tunnel_item;
11648 end_item = mlx5_find_end_item(tunnel_item);
11651 end_item = tunnel_item ? tunnel_item :
11652 mlx5_find_end_item(integrity_item);
11654 l3_protocol = mask->l3_ok ?
11655 mlx5_flow_locate_proto_l3(&item, end_item) : 0;
11656 flow_dv_translate_integrity_l3(mask, value, headers_m, headers_v,
11657 l3_protocol == RTE_ETHER_TYPE_IPV4);
11658 flow_dv_translate_integrity_l4(mask, value, headers_m, headers_v);
11662 * Prepares DV flow counter with aging configuration.
11663 * Gets it by index when exists, creates a new one when doesn't.
11666 * Pointer to rte_eth_dev structure.
11667 * @param[in] dev_flow
11668 * Pointer to the mlx5_flow.
11669 * @param[in, out] flow
11670 * Pointer to the sub flow.
11672 * Pointer to the counter action configuration.
11674 * Pointer to the aging action configuration.
11675 * @param[out] error
11676 * Pointer to the error structure.
11679 * Pointer to the counter, NULL otherwise.
11681 static struct mlx5_flow_counter *
11682 flow_dv_prepare_counter(struct rte_eth_dev *dev,
11683 struct mlx5_flow *dev_flow,
11684 struct rte_flow *flow,
11685 const struct rte_flow_action_count *count,
11686 const struct rte_flow_action_age *age,
11687 struct rte_flow_error *error)
11689 if (!flow->counter) {
11690 flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
11692 if (!flow->counter) {
11693 rte_flow_error_set(error, rte_errno,
11694 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11695 "cannot create counter object.");
11699 return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
11703 * Release an ASO CT action by its own device.
11706 * Pointer to the Ethernet device structure.
11708 * Index of ASO CT action to release.
11711 * 0 when CT action was removed, otherwise the number of references.
11714 flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
11716 struct mlx5_priv *priv = dev->data->dev_private;
11717 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11719 struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
11720 enum mlx5_aso_ct_state state =
11721 __atomic_load_n(&ct->state, __ATOMIC_RELAXED);
11723 /* Cannot release when CT is in the ASO SQ. */
11724 if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
11726 ret = __atomic_sub_fetch(&ct->refcnt, 1, __ATOMIC_RELAXED);
11728 if (ct->dr_action_orig) {
11729 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11730 claim_zero(mlx5_glue->destroy_flow_action
11731 (ct->dr_action_orig));
11733 ct->dr_action_orig = NULL;
11735 if (ct->dr_action_rply) {
11736 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11737 claim_zero(mlx5_glue->destroy_flow_action
11738 (ct->dr_action_rply));
11740 ct->dr_action_rply = NULL;
11742 /* Clear the state to free, no need in 1st allocation. */
11743 MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
11744 rte_spinlock_lock(&mng->ct_sl);
11745 LIST_INSERT_HEAD(&mng->free_cts, ct, next);
11746 rte_spinlock_unlock(&mng->ct_sl);
11752 flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx)
11754 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
11755 uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
11756 struct rte_eth_dev *owndev = &rte_eth_devices[owner];
11759 MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
11760 if (dev->data->dev_started != 1)
11762 return flow_dv_aso_ct_dev_release(owndev, idx);
11766 * Resize the ASO CT pools array by 64 pools.
11769 * Pointer to the Ethernet device structure.
11772 * 0 on success, otherwise negative errno value and rte_errno is set.
11775 flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
11777 struct mlx5_priv *priv = dev->data->dev_private;
11778 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11779 void *old_pools = mng->pools;
11780 /* Magic number now, need a macro. */
11781 uint32_t resize = mng->n + 64;
11782 uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
11783 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
11786 rte_errno = ENOMEM;
11789 rte_rwlock_write_lock(&mng->resize_rwl);
11790 /* ASO SQ/QP was already initialized in the startup. */
11792 /* Realloc could be an alternative choice. */
11793 rte_memcpy(pools, old_pools,
11794 mng->n * sizeof(struct mlx5_aso_ct_pool *));
11795 mlx5_free(old_pools);
11798 mng->pools = pools;
11799 rte_rwlock_write_unlock(&mng->resize_rwl);
11804 * Create and initialize a new ASO CT pool.
11807 * Pointer to the Ethernet device structure.
11808 * @param[out] ct_free
11809 * Where to put the pointer of a new CT action.
11812 * The CT actions pool pointer and @p ct_free is set on success,
11813 * NULL otherwise and rte_errno is set.
11815 static struct mlx5_aso_ct_pool *
11816 flow_dv_ct_pool_create(struct rte_eth_dev *dev,
11817 struct mlx5_aso_ct_action **ct_free)
11819 struct mlx5_priv *priv = dev->data->dev_private;
11820 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11821 struct mlx5_aso_ct_pool *pool = NULL;
11822 struct mlx5_devx_obj *obj = NULL;
11824 uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
11826 obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->ctx,
11827 priv->sh->pdn, log_obj_size);
11829 rte_errno = ENODATA;
11830 DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
11833 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
11835 rte_errno = ENOMEM;
11836 claim_zero(mlx5_devx_cmd_destroy(obj));
11839 pool->devx_obj = obj;
11840 pool->index = mng->next;
11841 /* Resize pools array if there is no room for the new pool in it. */
11842 if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
11843 claim_zero(mlx5_devx_cmd_destroy(obj));
11847 mng->pools[pool->index] = pool;
11849 /* Assign the first action in the new pool, the rest go to free list. */
11850 *ct_free = &pool->actions[0];
11851 /* Lock outside, the list operation is safe here. */
11852 for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
11853 /* refcnt is 0 when allocating the memory. */
11854 pool->actions[i].offset = i;
11855 LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
11861 * Allocate a ASO CT action from free list.
11864 * Pointer to the Ethernet device structure.
11865 * @param[out] error
11866 * Pointer to the error structure.
11869 * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
11872 flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
11874 struct mlx5_priv *priv = dev->data->dev_private;
11875 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
11876 struct mlx5_aso_ct_action *ct = NULL;
11877 struct mlx5_aso_ct_pool *pool;
11882 if (!priv->config.devx) {
11883 rte_errno = ENOTSUP;
11886 /* Get a free CT action, if no, a new pool will be created. */
11887 rte_spinlock_lock(&mng->ct_sl);
11888 ct = LIST_FIRST(&mng->free_cts);
11890 LIST_REMOVE(ct, next);
11891 } else if (!flow_dv_ct_pool_create(dev, &ct)) {
11892 rte_spinlock_unlock(&mng->ct_sl);
11893 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
11894 NULL, "failed to create ASO CT pool");
11897 rte_spinlock_unlock(&mng->ct_sl);
11898 pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
11899 ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
11900 /* 0: inactive, 1: created, 2+: used by flows. */
11901 __atomic_store_n(&ct->refcnt, 1, __ATOMIC_RELAXED);
11902 reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
11903 if (!ct->dr_action_orig) {
11904 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11905 ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
11906 (priv->sh->rx_domain, pool->devx_obj->obj,
11908 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
11911 RTE_SET_USED(reg_c);
11913 if (!ct->dr_action_orig) {
11914 flow_dv_aso_ct_dev_release(dev, ct_idx);
11915 rte_flow_error_set(error, rte_errno,
11916 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11917 "failed to create ASO CT action");
11921 if (!ct->dr_action_rply) {
11922 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
11923 ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
11924 (priv->sh->rx_domain, pool->devx_obj->obj,
11926 MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
11929 if (!ct->dr_action_rply) {
11930 flow_dv_aso_ct_dev_release(dev, ct_idx);
11931 rte_flow_error_set(error, rte_errno,
11932 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11933 "failed to create ASO CT action");
11941 * Create a conntrack object with context and actions by using ASO mechanism.
11944 * Pointer to rte_eth_dev structure.
11946 * Pointer to conntrack information profile.
11947 * @param[out] error
11948 * Pointer to the error structure.
11951 * Index to conntrack object on success, 0 otherwise.
11954 flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
11955 const struct rte_flow_action_conntrack *pro,
11956 struct rte_flow_error *error)
11958 struct mlx5_priv *priv = dev->data->dev_private;
11959 struct mlx5_dev_ctx_shared *sh = priv->sh;
11960 struct mlx5_aso_ct_action *ct;
11963 if (!sh->ct_aso_en)
11964 return rte_flow_error_set(error, ENOTSUP,
11965 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11966 "Connection is not supported");
11967 idx = flow_dv_aso_ct_alloc(dev, error);
11969 return rte_flow_error_set(error, rte_errno,
11970 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11971 "Failed to allocate CT object");
11972 ct = flow_aso_ct_get_by_dev_idx(dev, idx);
11973 if (mlx5_aso_ct_update_by_wqe(sh, ct, pro))
11974 return rte_flow_error_set(error, EBUSY,
11975 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11976 "Failed to update CT");
11977 ct->is_original = !!pro->is_original_dir;
11978 ct->peer = pro->peer_port;
11983 * Fill the flow with DV spec, lock free
11984 * (mutex should be acquired by caller).
11987 * Pointer to rte_eth_dev structure.
11988 * @param[in, out] dev_flow
11989 * Pointer to the sub flow.
11991 * Pointer to the flow attributes.
11993 * Pointer to the list of items.
11994 * @param[in] actions
11995 * Pointer to the list of actions.
11996 * @param[out] error
11997 * Pointer to the error structure.
12000 * 0 on success, a negative errno value otherwise and rte_errno is set.
12003 flow_dv_translate(struct rte_eth_dev *dev,
12004 struct mlx5_flow *dev_flow,
12005 const struct rte_flow_attr *attr,
12006 const struct rte_flow_item items[],
12007 const struct rte_flow_action actions[],
12008 struct rte_flow_error *error)
12010 struct mlx5_priv *priv = dev->data->dev_private;
12011 struct mlx5_dev_config *dev_conf = &priv->config;
12012 struct rte_flow *flow = dev_flow->flow;
12013 struct mlx5_flow_handle *handle = dev_flow->handle;
12014 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
12015 struct mlx5_flow_rss_desc *rss_desc;
12016 uint64_t item_flags = 0;
12017 uint64_t last_item = 0;
12018 uint64_t action_flags = 0;
12019 struct mlx5_flow_dv_matcher matcher = {
12021 .size = sizeof(matcher.mask.buf) -
12022 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
12026 bool actions_end = false;
12028 struct mlx5_flow_dv_modify_hdr_resource res;
12029 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
12030 sizeof(struct mlx5_modification_cmd) *
12031 (MLX5_MAX_MODIFY_NUM + 1)];
12033 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
12034 const struct rte_flow_action_count *count = NULL;
12035 const struct rte_flow_action_age *non_shared_age = NULL;
12036 union flow_dv_attr flow_attr = { .attr = 0 };
12038 union mlx5_flow_tbl_key tbl_key;
12039 uint32_t modify_action_position = UINT32_MAX;
12040 void *match_mask = matcher.mask.buf;
12041 void *match_value = dev_flow->dv.value.buf;
12042 uint8_t next_protocol = 0xff;
12043 struct rte_vlan_hdr vlan = { 0 };
12044 struct mlx5_flow_dv_dest_array_resource mdest_res;
12045 struct mlx5_flow_dv_sample_resource sample_res;
12046 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
12047 const struct rte_flow_action_sample *sample = NULL;
12048 struct mlx5_flow_sub_actions_list *sample_act;
12049 uint32_t sample_act_pos = UINT32_MAX;
12050 uint32_t age_act_pos = UINT32_MAX;
12051 uint32_t num_of_dest = 0;
12052 int tmp_actions_n = 0;
12055 const struct mlx5_flow_tunnel *tunnel = NULL;
12056 struct flow_grp_info grp_info = {
12057 .external = !!dev_flow->external,
12058 .transfer = !!attr->transfer,
12059 .fdb_def_rule = !!priv->fdb_def_rule,
12060 .skip_scale = dev_flow->skip_scale &
12061 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
12062 .std_tbl_fix = true,
12064 const struct rte_flow_item *head_item = items;
12067 return rte_flow_error_set(error, ENOMEM,
12068 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12070 "failed to push flow workspace");
12071 rss_desc = &wks->rss_desc;
12072 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
12073 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
12074 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12075 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12076 /* update normal path action resource into last index of array */
12077 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
12078 if (is_tunnel_offload_active(dev)) {
12079 if (dev_flow->tunnel) {
12080 RTE_VERIFY(dev_flow->tof_type ==
12081 MLX5_TUNNEL_OFFLOAD_MISS_RULE);
12082 tunnel = dev_flow->tunnel;
12084 tunnel = mlx5_get_tof(items, actions,
12085 &dev_flow->tof_type);
12086 dev_flow->tunnel = tunnel;
12088 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
12089 (dev, attr, tunnel, dev_flow->tof_type);
12091 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
12092 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
12093 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
12097 dev_flow->dv.group = table;
12098 if (attr->transfer)
12099 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
12100 /* number of actions must be set to 0 in case of dirty stack. */
12101 mhdr_res->actions_num = 0;
12102 if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
12104 * do not add decap action if match rule drops packet
12105 * HW rejects rules with decap & drop
12107 * if tunnel match rule was inserted before matching tunnel set
12108 * rule flow table used in the match rule must be registered.
12109 * current implementation handles that in the
12110 * flow_dv_match_register() at the function end.
12112 bool add_decap = true;
12113 const struct rte_flow_action *ptr = actions;
12115 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
12116 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
12122 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12126 dev_flow->dv.actions[actions_n++] =
12127 dev_flow->dv.encap_decap->action;
12128 action_flags |= MLX5_FLOW_ACTION_DECAP;
12131 for (; !actions_end ; actions++) {
12132 const struct rte_flow_action_queue *queue;
12133 const struct rte_flow_action_rss *rss;
12134 const struct rte_flow_action *action = actions;
12135 const uint8_t *rss_key;
12136 struct mlx5_flow_tbl_resource *tbl;
12137 struct mlx5_aso_age_action *age_act;
12138 struct mlx5_flow_counter *cnt_act;
12139 uint32_t port_id = 0;
12140 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
12141 int action_type = actions->type;
12142 const struct rte_flow_action *found_action = NULL;
12143 uint32_t jump_group = 0;
12144 uint32_t owner_idx;
12145 struct mlx5_aso_ct_action *ct;
12147 if (!mlx5_flow_os_action_supported(action_type))
12148 return rte_flow_error_set(error, ENOTSUP,
12149 RTE_FLOW_ERROR_TYPE_ACTION,
12151 "action not supported");
12152 switch (action_type) {
12153 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
12154 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
12156 case RTE_FLOW_ACTION_TYPE_VOID:
12158 case RTE_FLOW_ACTION_TYPE_PORT_ID:
12159 if (flow_dv_translate_action_port_id(dev, action,
12162 port_id_resource.port_id = port_id;
12163 MLX5_ASSERT(!handle->rix_port_id_action);
12164 if (flow_dv_port_id_action_resource_register
12165 (dev, &port_id_resource, dev_flow, error))
12167 dev_flow->dv.actions[actions_n++] =
12168 dev_flow->dv.port_id_action->action;
12169 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12170 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
12171 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
12174 case RTE_FLOW_ACTION_TYPE_FLAG:
12175 action_flags |= MLX5_FLOW_ACTION_FLAG;
12176 dev_flow->handle->mark = 1;
12177 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12178 struct rte_flow_action_mark mark = {
12179 .id = MLX5_FLOW_MARK_DEFAULT,
12182 if (flow_dv_convert_action_mark(dev, &mark,
12186 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12189 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
12191 * Only one FLAG or MARK is supported per device flow
12192 * right now. So the pointer to the tag resource must be
12193 * zero before the register process.
12195 MLX5_ASSERT(!handle->dvh.rix_tag);
12196 if (flow_dv_tag_resource_register(dev, tag_be,
12199 MLX5_ASSERT(dev_flow->dv.tag_resource);
12200 dev_flow->dv.actions[actions_n++] =
12201 dev_flow->dv.tag_resource->action;
12203 case RTE_FLOW_ACTION_TYPE_MARK:
12204 action_flags |= MLX5_FLOW_ACTION_MARK;
12205 dev_flow->handle->mark = 1;
12206 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
12207 const struct rte_flow_action_mark *mark =
12208 (const struct rte_flow_action_mark *)
12211 if (flow_dv_convert_action_mark(dev, mark,
12215 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
12219 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
12220 /* Legacy (non-extensive) MARK action. */
12221 tag_be = mlx5_flow_mark_set
12222 (((const struct rte_flow_action_mark *)
12223 (actions->conf))->id);
12224 MLX5_ASSERT(!handle->dvh.rix_tag);
12225 if (flow_dv_tag_resource_register(dev, tag_be,
12228 MLX5_ASSERT(dev_flow->dv.tag_resource);
12229 dev_flow->dv.actions[actions_n++] =
12230 dev_flow->dv.tag_resource->action;
12232 case RTE_FLOW_ACTION_TYPE_SET_META:
12233 if (flow_dv_convert_action_set_meta
12234 (dev, mhdr_res, attr,
12235 (const struct rte_flow_action_set_meta *)
12236 actions->conf, error))
12238 action_flags |= MLX5_FLOW_ACTION_SET_META;
12240 case RTE_FLOW_ACTION_TYPE_SET_TAG:
12241 if (flow_dv_convert_action_set_tag
12243 (const struct rte_flow_action_set_tag *)
12244 actions->conf, error))
12246 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12248 case RTE_FLOW_ACTION_TYPE_DROP:
12249 action_flags |= MLX5_FLOW_ACTION_DROP;
12250 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
12252 case RTE_FLOW_ACTION_TYPE_QUEUE:
12253 queue = actions->conf;
12254 rss_desc->queue_num = 1;
12255 rss_desc->queue[0] = queue->index;
12256 action_flags |= MLX5_FLOW_ACTION_QUEUE;
12257 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
12258 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
12261 case RTE_FLOW_ACTION_TYPE_RSS:
12262 rss = actions->conf;
12263 memcpy(rss_desc->queue, rss->queue,
12264 rss->queue_num * sizeof(uint16_t));
12265 rss_desc->queue_num = rss->queue_num;
12266 /* NULL RSS key indicates default RSS key. */
12267 rss_key = !rss->key ? rss_hash_default_key : rss->key;
12268 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
12270 * rss->level and rss.types should be set in advance
12271 * when expanding items for RSS.
12273 action_flags |= MLX5_FLOW_ACTION_RSS;
12274 dev_flow->handle->fate_action = rss_desc->shared_rss ?
12275 MLX5_FLOW_FATE_SHARED_RSS :
12276 MLX5_FLOW_FATE_QUEUE;
12278 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
12279 flow->age = (uint32_t)(uintptr_t)(action->conf);
12280 age_act = flow_aso_age_get_by_idx(dev, flow->age);
12281 __atomic_fetch_add(&age_act->refcnt, 1,
12283 age_act_pos = actions_n++;
12284 action_flags |= MLX5_FLOW_ACTION_AGE;
12286 case RTE_FLOW_ACTION_TYPE_AGE:
12287 non_shared_age = action->conf;
12288 age_act_pos = actions_n++;
12289 action_flags |= MLX5_FLOW_ACTION_AGE;
12291 case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
12292 flow->counter = (uint32_t)(uintptr_t)(action->conf);
12293 cnt_act = flow_dv_counter_get_by_idx(dev, flow->counter,
12295 __atomic_fetch_add(&cnt_act->shared_info.refcnt, 1,
12297 /* Save information first, will apply later. */
12298 action_flags |= MLX5_FLOW_ACTION_COUNT;
12300 case RTE_FLOW_ACTION_TYPE_COUNT:
12301 if (!dev_conf->devx) {
12302 return rte_flow_error_set
12304 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12306 "count action not supported");
12308 /* Save information first, will apply later. */
12309 count = action->conf;
12310 action_flags |= MLX5_FLOW_ACTION_COUNT;
12312 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
12313 dev_flow->dv.actions[actions_n++] =
12314 priv->sh->pop_vlan_action;
12315 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
12317 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
12318 if (!(action_flags &
12319 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
12320 flow_dev_get_vlan_info_from_items(items, &vlan);
12321 vlan.eth_proto = rte_be_to_cpu_16
12322 ((((const struct rte_flow_action_of_push_vlan *)
12323 actions->conf)->ethertype));
12324 found_action = mlx5_flow_find_action
12326 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
12328 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12329 found_action = mlx5_flow_find_action
12331 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
12333 mlx5_update_vlan_vid_pcp(found_action, &vlan);
12334 if (flow_dv_create_action_push_vlan
12335 (dev, attr, &vlan, dev_flow, error))
12337 dev_flow->dv.actions[actions_n++] =
12338 dev_flow->dv.push_vlan_res->action;
12339 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
12341 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
12342 /* of_vlan_push action handled this action */
12343 MLX5_ASSERT(action_flags &
12344 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
12346 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
12347 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
12349 flow_dev_get_vlan_info_from_items(items, &vlan);
12350 mlx5_update_vlan_vid_pcp(actions, &vlan);
12351 /* If no VLAN push - this is a modify header action */
12352 if (flow_dv_convert_action_modify_vlan_vid
12353 (mhdr_res, actions, error))
12355 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
12357 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
12358 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
12359 if (flow_dv_create_action_l2_encap(dev, actions,
12364 dev_flow->dv.actions[actions_n++] =
12365 dev_flow->dv.encap_decap->action;
12366 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12367 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12368 sample_act->action_flags |=
12369 MLX5_FLOW_ACTION_ENCAP;
12371 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
12372 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
12373 if (flow_dv_create_action_l2_decap(dev, dev_flow,
12377 dev_flow->dv.actions[actions_n++] =
12378 dev_flow->dv.encap_decap->action;
12379 action_flags |= MLX5_FLOW_ACTION_DECAP;
12381 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
12382 /* Handle encap with preceding decap. */
12383 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
12384 if (flow_dv_create_action_raw_encap
12385 (dev, actions, dev_flow, attr, error))
12387 dev_flow->dv.actions[actions_n++] =
12388 dev_flow->dv.encap_decap->action;
12390 /* Handle encap without preceding decap. */
12391 if (flow_dv_create_action_l2_encap
12392 (dev, actions, dev_flow, attr->transfer,
12395 dev_flow->dv.actions[actions_n++] =
12396 dev_flow->dv.encap_decap->action;
12398 action_flags |= MLX5_FLOW_ACTION_ENCAP;
12399 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
12400 sample_act->action_flags |=
12401 MLX5_FLOW_ACTION_ENCAP;
12403 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
12404 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
12406 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
12407 if (flow_dv_create_action_l2_decap
12408 (dev, dev_flow, attr->transfer, error))
12410 dev_flow->dv.actions[actions_n++] =
12411 dev_flow->dv.encap_decap->action;
12413 /* If decap is followed by encap, handle it at encap. */
12414 action_flags |= MLX5_FLOW_ACTION_DECAP;
12416 case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
12417 dev_flow->dv.actions[actions_n++] =
12418 (void *)(uintptr_t)action->conf;
12419 action_flags |= MLX5_FLOW_ACTION_JUMP;
12421 case RTE_FLOW_ACTION_TYPE_JUMP:
12422 jump_group = ((const struct rte_flow_action_jump *)
12423 action->conf)->group;
12424 grp_info.std_tbl_fix = 0;
12425 if (dev_flow->skip_scale &
12426 (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
12427 grp_info.skip_scale = 1;
12429 grp_info.skip_scale = 0;
12430 ret = mlx5_flow_group_to_table(dev, tunnel,
12436 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
12438 !!dev_flow->external,
12439 tunnel, jump_group, 0,
12442 return rte_flow_error_set
12444 RTE_FLOW_ERROR_TYPE_ACTION,
12446 "cannot create jump action.");
12447 if (flow_dv_jump_tbl_resource_register
12448 (dev, tbl, dev_flow, error)) {
12449 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12450 return rte_flow_error_set
12452 RTE_FLOW_ERROR_TYPE_ACTION,
12454 "cannot create jump action.");
12456 dev_flow->dv.actions[actions_n++] =
12457 dev_flow->dv.jump->action;
12458 action_flags |= MLX5_FLOW_ACTION_JUMP;
12459 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
12460 sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
12463 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
12464 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
12465 if (flow_dv_convert_action_modify_mac
12466 (mhdr_res, actions, error))
12468 action_flags |= actions->type ==
12469 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
12470 MLX5_FLOW_ACTION_SET_MAC_SRC :
12471 MLX5_FLOW_ACTION_SET_MAC_DST;
12473 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
12474 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
12475 if (flow_dv_convert_action_modify_ipv4
12476 (mhdr_res, actions, error))
12478 action_flags |= actions->type ==
12479 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
12480 MLX5_FLOW_ACTION_SET_IPV4_SRC :
12481 MLX5_FLOW_ACTION_SET_IPV4_DST;
12483 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
12484 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
12485 if (flow_dv_convert_action_modify_ipv6
12486 (mhdr_res, actions, error))
12488 action_flags |= actions->type ==
12489 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
12490 MLX5_FLOW_ACTION_SET_IPV6_SRC :
12491 MLX5_FLOW_ACTION_SET_IPV6_DST;
12493 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
12494 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
12495 if (flow_dv_convert_action_modify_tp
12496 (mhdr_res, actions, items,
12497 &flow_attr, dev_flow, !!(action_flags &
12498 MLX5_FLOW_ACTION_DECAP), error))
12500 action_flags |= actions->type ==
12501 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
12502 MLX5_FLOW_ACTION_SET_TP_SRC :
12503 MLX5_FLOW_ACTION_SET_TP_DST;
12505 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
12506 if (flow_dv_convert_action_modify_dec_ttl
12507 (mhdr_res, items, &flow_attr, dev_flow,
12509 MLX5_FLOW_ACTION_DECAP), error))
12511 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
12513 case RTE_FLOW_ACTION_TYPE_SET_TTL:
12514 if (flow_dv_convert_action_modify_ttl
12515 (mhdr_res, actions, items, &flow_attr,
12516 dev_flow, !!(action_flags &
12517 MLX5_FLOW_ACTION_DECAP), error))
12519 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
12521 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
12522 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
12523 if (flow_dv_convert_action_modify_tcp_seq
12524 (mhdr_res, actions, error))
12526 action_flags |= actions->type ==
12527 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
12528 MLX5_FLOW_ACTION_INC_TCP_SEQ :
12529 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
12532 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
12533 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
12534 if (flow_dv_convert_action_modify_tcp_ack
12535 (mhdr_res, actions, error))
12537 action_flags |= actions->type ==
12538 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
12539 MLX5_FLOW_ACTION_INC_TCP_ACK :
12540 MLX5_FLOW_ACTION_DEC_TCP_ACK;
12542 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
12543 if (flow_dv_convert_action_set_reg
12544 (mhdr_res, actions, error))
12546 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12548 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
12549 if (flow_dv_convert_action_copy_mreg
12550 (dev, mhdr_res, actions, error))
12552 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
12554 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
12555 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
12556 dev_flow->handle->fate_action =
12557 MLX5_FLOW_FATE_DEFAULT_MISS;
12559 case RTE_FLOW_ACTION_TYPE_METER:
12561 return rte_flow_error_set(error, rte_errno,
12562 RTE_FLOW_ERROR_TYPE_ACTION,
12563 NULL, "Failed to get meter in flow.");
12564 /* Set the meter action. */
12565 dev_flow->dv.actions[actions_n++] =
12566 wks->fm->meter_action;
12567 action_flags |= MLX5_FLOW_ACTION_METER;
12569 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
12570 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
12573 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
12575 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
12576 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
12579 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
12581 case RTE_FLOW_ACTION_TYPE_SAMPLE:
12582 sample_act_pos = actions_n;
12583 sample = (const struct rte_flow_action_sample *)
12586 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
12587 /* put encap action into group if work with port id */
12588 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
12589 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
12590 sample_act->action_flags |=
12591 MLX5_FLOW_ACTION_ENCAP;
12593 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
12594 if (flow_dv_convert_action_modify_field
12595 (dev, mhdr_res, actions, attr, error))
12597 action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
12599 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
12600 owner_idx = (uint32_t)(uintptr_t)action->conf;
12601 ct = flow_aso_ct_get_by_idx(dev, owner_idx);
12603 return rte_flow_error_set(error, EINVAL,
12604 RTE_FLOW_ERROR_TYPE_ACTION,
12606 "Failed to get CT object.");
12607 if (mlx5_aso_ct_available(priv->sh, ct))
12608 return rte_flow_error_set(error, rte_errno,
12609 RTE_FLOW_ERROR_TYPE_ACTION,
12611 "CT is unavailable.");
12612 if (ct->is_original)
12613 dev_flow->dv.actions[actions_n] =
12614 ct->dr_action_orig;
12616 dev_flow->dv.actions[actions_n] =
12617 ct->dr_action_rply;
12618 flow->indirect_type = MLX5_INDIRECT_ACTION_TYPE_CT;
12619 flow->ct = owner_idx;
12620 __atomic_fetch_add(&ct->refcnt, 1, __ATOMIC_RELAXED);
12622 action_flags |= MLX5_FLOW_ACTION_CT;
12624 case RTE_FLOW_ACTION_TYPE_END:
12625 actions_end = true;
12626 if (mhdr_res->actions_num) {
12627 /* create modify action if needed. */
12628 if (flow_dv_modify_hdr_resource_register
12629 (dev, mhdr_res, dev_flow, error))
12631 dev_flow->dv.actions[modify_action_position] =
12632 handle->dvh.modify_hdr->action;
12635 * Handle AGE and COUNT action by single HW counter
12636 * when they are not shared.
12638 if (action_flags & MLX5_FLOW_ACTION_AGE) {
12639 if ((non_shared_age &&
12640 count && !count->shared) ||
12641 !(priv->sh->flow_hit_aso_en &&
12642 (attr->group || attr->transfer))) {
12643 /* Creates age by counters. */
12644 cnt_act = flow_dv_prepare_counter
12651 dev_flow->dv.actions[age_act_pos] =
12655 if (!flow->age && non_shared_age) {
12656 flow->age = flow_dv_aso_age_alloc
12660 flow_dv_aso_age_params_init
12662 non_shared_age->context ?
12663 non_shared_age->context :
12664 (void *)(uintptr_t)
12665 (dev_flow->flow_idx),
12666 non_shared_age->timeout);
12668 age_act = flow_aso_age_get_by_idx(dev,
12670 dev_flow->dv.actions[age_act_pos] =
12671 age_act->dr_action;
12673 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
12675 * Create one count action, to be used
12676 * by all sub-flows.
12678 cnt_act = flow_dv_prepare_counter(dev, dev_flow,
12683 dev_flow->dv.actions[actions_n++] =
12689 if (mhdr_res->actions_num &&
12690 modify_action_position == UINT32_MAX)
12691 modify_action_position = actions_n++;
12693 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
12694 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
12695 int item_type = items->type;
12697 if (!mlx5_flow_os_item_supported(item_type))
12698 return rte_flow_error_set(error, ENOTSUP,
12699 RTE_FLOW_ERROR_TYPE_ITEM,
12700 NULL, "item not supported");
12701 switch (item_type) {
12702 case RTE_FLOW_ITEM_TYPE_PORT_ID:
12703 flow_dv_translate_item_port_id
12704 (dev, match_mask, match_value, items, attr);
12705 last_item = MLX5_FLOW_ITEM_PORT_ID;
12707 case RTE_FLOW_ITEM_TYPE_ETH:
12708 flow_dv_translate_item_eth(match_mask, match_value,
12710 dev_flow->dv.group);
12711 matcher.priority = action_flags &
12712 MLX5_FLOW_ACTION_DEFAULT_MISS &&
12713 !dev_flow->external ?
12714 MLX5_PRIORITY_MAP_L3 :
12715 MLX5_PRIORITY_MAP_L2;
12716 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
12717 MLX5_FLOW_LAYER_OUTER_L2;
12719 case RTE_FLOW_ITEM_TYPE_VLAN:
12720 flow_dv_translate_item_vlan(dev_flow,
12721 match_mask, match_value,
12723 dev_flow->dv.group);
12724 matcher.priority = MLX5_PRIORITY_MAP_L2;
12725 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
12726 MLX5_FLOW_LAYER_INNER_VLAN) :
12727 (MLX5_FLOW_LAYER_OUTER_L2 |
12728 MLX5_FLOW_LAYER_OUTER_VLAN);
12730 case RTE_FLOW_ITEM_TYPE_IPV4:
12731 mlx5_flow_tunnel_ip_check(items, next_protocol,
12732 &item_flags, &tunnel);
12733 flow_dv_translate_item_ipv4(match_mask, match_value,
12735 dev_flow->dv.group);
12736 matcher.priority = MLX5_PRIORITY_MAP_L3;
12737 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
12738 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
12739 if (items->mask != NULL &&
12740 ((const struct rte_flow_item_ipv4 *)
12741 items->mask)->hdr.next_proto_id) {
12743 ((const struct rte_flow_item_ipv4 *)
12744 (items->spec))->hdr.next_proto_id;
12746 ((const struct rte_flow_item_ipv4 *)
12747 (items->mask))->hdr.next_proto_id;
12749 /* Reset for inner layer. */
12750 next_protocol = 0xff;
12753 case RTE_FLOW_ITEM_TYPE_IPV6:
12754 mlx5_flow_tunnel_ip_check(items, next_protocol,
12755 &item_flags, &tunnel);
12756 flow_dv_translate_item_ipv6(match_mask, match_value,
12758 dev_flow->dv.group);
12759 matcher.priority = MLX5_PRIORITY_MAP_L3;
12760 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
12761 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
12762 if (items->mask != NULL &&
12763 ((const struct rte_flow_item_ipv6 *)
12764 items->mask)->hdr.proto) {
12766 ((const struct rte_flow_item_ipv6 *)
12767 items->spec)->hdr.proto;
12769 ((const struct rte_flow_item_ipv6 *)
12770 items->mask)->hdr.proto;
12772 /* Reset for inner layer. */
12773 next_protocol = 0xff;
12776 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
12777 flow_dv_translate_item_ipv6_frag_ext(match_mask,
12780 last_item = tunnel ?
12781 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
12782 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
12783 if (items->mask != NULL &&
12784 ((const struct rte_flow_item_ipv6_frag_ext *)
12785 items->mask)->hdr.next_header) {
12787 ((const struct rte_flow_item_ipv6_frag_ext *)
12788 items->spec)->hdr.next_header;
12790 ((const struct rte_flow_item_ipv6_frag_ext *)
12791 items->mask)->hdr.next_header;
12793 /* Reset for inner layer. */
12794 next_protocol = 0xff;
12797 case RTE_FLOW_ITEM_TYPE_TCP:
12798 flow_dv_translate_item_tcp(match_mask, match_value,
12800 matcher.priority = MLX5_PRIORITY_MAP_L4;
12801 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
12802 MLX5_FLOW_LAYER_OUTER_L4_TCP;
12804 case RTE_FLOW_ITEM_TYPE_UDP:
12805 flow_dv_translate_item_udp(match_mask, match_value,
12807 matcher.priority = MLX5_PRIORITY_MAP_L4;
12808 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
12809 MLX5_FLOW_LAYER_OUTER_L4_UDP;
12811 case RTE_FLOW_ITEM_TYPE_GRE:
12812 flow_dv_translate_item_gre(match_mask, match_value,
12814 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12815 last_item = MLX5_FLOW_LAYER_GRE;
12817 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
12818 flow_dv_translate_item_gre_key(match_mask,
12819 match_value, items);
12820 last_item = MLX5_FLOW_LAYER_GRE_KEY;
12822 case RTE_FLOW_ITEM_TYPE_NVGRE:
12823 flow_dv_translate_item_nvgre(match_mask, match_value,
12825 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12826 last_item = MLX5_FLOW_LAYER_GRE;
12828 case RTE_FLOW_ITEM_TYPE_VXLAN:
12829 flow_dv_translate_item_vxlan(match_mask, match_value,
12831 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12832 last_item = MLX5_FLOW_LAYER_VXLAN;
12834 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
12835 flow_dv_translate_item_vxlan_gpe(match_mask,
12836 match_value, items,
12838 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12839 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
12841 case RTE_FLOW_ITEM_TYPE_GENEVE:
12842 flow_dv_translate_item_geneve(match_mask, match_value,
12844 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12845 last_item = MLX5_FLOW_LAYER_GENEVE;
12847 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
12848 ret = flow_dv_translate_item_geneve_opt(dev, match_mask,
12852 return rte_flow_error_set(error, -ret,
12853 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
12854 "cannot create GENEVE TLV option");
12855 flow->geneve_tlv_option = 1;
12856 last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
12858 case RTE_FLOW_ITEM_TYPE_MPLS:
12859 flow_dv_translate_item_mpls(match_mask, match_value,
12860 items, last_item, tunnel);
12861 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12862 last_item = MLX5_FLOW_LAYER_MPLS;
12864 case RTE_FLOW_ITEM_TYPE_MARK:
12865 flow_dv_translate_item_mark(dev, match_mask,
12866 match_value, items);
12867 last_item = MLX5_FLOW_ITEM_MARK;
12869 case RTE_FLOW_ITEM_TYPE_META:
12870 flow_dv_translate_item_meta(dev, match_mask,
12871 match_value, attr, items);
12872 last_item = MLX5_FLOW_ITEM_METADATA;
12874 case RTE_FLOW_ITEM_TYPE_ICMP:
12875 flow_dv_translate_item_icmp(match_mask, match_value,
12877 last_item = MLX5_FLOW_LAYER_ICMP;
12879 case RTE_FLOW_ITEM_TYPE_ICMP6:
12880 flow_dv_translate_item_icmp6(match_mask, match_value,
12882 last_item = MLX5_FLOW_LAYER_ICMP6;
12884 case RTE_FLOW_ITEM_TYPE_TAG:
12885 flow_dv_translate_item_tag(dev, match_mask,
12886 match_value, items);
12887 last_item = MLX5_FLOW_ITEM_TAG;
12889 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
12890 flow_dv_translate_mlx5_item_tag(dev, match_mask,
12891 match_value, items);
12892 last_item = MLX5_FLOW_ITEM_TAG;
12894 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
12895 flow_dv_translate_item_tx_queue(dev, match_mask,
12898 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
12900 case RTE_FLOW_ITEM_TYPE_GTP:
12901 flow_dv_translate_item_gtp(match_mask, match_value,
12903 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
12904 last_item = MLX5_FLOW_LAYER_GTP;
12906 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
12907 ret = flow_dv_translate_item_gtp_psc(match_mask,
12911 return rte_flow_error_set(error, -ret,
12912 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
12913 "cannot create GTP PSC item");
12914 last_item = MLX5_FLOW_LAYER_GTP_PSC;
12916 case RTE_FLOW_ITEM_TYPE_ECPRI:
12917 if (!mlx5_flex_parser_ecpri_exist(dev)) {
12918 /* Create it only the first time to be used. */
12919 ret = mlx5_flex_parser_ecpri_alloc(dev);
12921 return rte_flow_error_set
12923 RTE_FLOW_ERROR_TYPE_ITEM,
12925 "cannot create eCPRI parser");
12927 /* Adjust the length matcher and device flow value. */
12928 matcher.mask.size = MLX5_ST_SZ_BYTES(fte_match_param);
12929 dev_flow->dv.value.size =
12930 MLX5_ST_SZ_BYTES(fte_match_param);
12931 flow_dv_translate_item_ecpri(dev, match_mask,
12932 match_value, items);
12933 /* No other protocol should follow eCPRI layer. */
12934 last_item = MLX5_FLOW_LAYER_ECPRI;
12936 case RTE_FLOW_ITEM_TYPE_INTEGRITY:
12937 flow_dv_translate_item_integrity(match_mask,
12941 case RTE_FLOW_ITEM_TYPE_CONNTRACK:
12942 flow_dv_translate_item_aso_ct(dev, match_mask,
12943 match_value, items);
12948 item_flags |= last_item;
12951 * When E-Switch mode is enabled, we have two cases where we need to
12952 * set the source port manually.
12953 * The first one, is in case of Nic steering rule, and the second is
12954 * E-Switch rule where no port_id item was found. In both cases
12955 * the source port is set according the current port in use.
12957 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
12958 (priv->representor || priv->master)) {
12959 if (flow_dv_translate_item_port_id(dev, match_mask,
12960 match_value, NULL, attr))
12963 #ifdef RTE_LIBRTE_MLX5_DEBUG
12964 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
12965 dev_flow->dv.value.buf));
12968 * Layers may be already initialized from prefix flow if this dev_flow
12969 * is the suffix flow.
12971 handle->layers |= item_flags;
12972 if (action_flags & MLX5_FLOW_ACTION_RSS)
12973 flow_dv_hashfields_set(dev_flow, rss_desc);
12974 /* If has RSS action in the sample action, the Sample/Mirror resource
12975 * should be registered after the hash filed be update.
12977 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
12978 ret = flow_dv_translate_action_sample(dev,
12987 ret = flow_dv_create_action_sample(dev,
12996 return rte_flow_error_set
12998 RTE_FLOW_ERROR_TYPE_ACTION,
13000 "cannot create sample action");
13001 if (num_of_dest > 1) {
13002 dev_flow->dv.actions[sample_act_pos] =
13003 dev_flow->dv.dest_array_res->action;
13005 dev_flow->dv.actions[sample_act_pos] =
13006 dev_flow->dv.sample_res->verbs_action;
13010 * For multiple destination (sample action with ratio=1), the encap
13011 * action and port id action will be combined into group action.
13012 * So need remove the original these actions in the flow and only
13013 * use the sample action instead of.
13015 if (num_of_dest > 1 &&
13016 (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
13018 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
13020 for (i = 0; i < actions_n; i++) {
13021 if ((sample_act->dr_encap_action &&
13022 sample_act->dr_encap_action ==
13023 dev_flow->dv.actions[i]) ||
13024 (sample_act->dr_port_id_action &&
13025 sample_act->dr_port_id_action ==
13026 dev_flow->dv.actions[i]) ||
13027 (sample_act->dr_jump_action &&
13028 sample_act->dr_jump_action ==
13029 dev_flow->dv.actions[i]))
13031 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
13033 memcpy((void *)dev_flow->dv.actions,
13034 (void *)temp_actions,
13035 tmp_actions_n * sizeof(void *));
13036 actions_n = tmp_actions_n;
13038 dev_flow->dv.actions_n = actions_n;
13039 dev_flow->act_flags = action_flags;
13040 if (wks->skip_matcher_reg)
13042 /* Register matcher. */
13043 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
13044 matcher.mask.size);
13045 matcher.priority = mlx5_get_matcher_priority(dev, attr,
13047 /* reserved field no needs to be set to 0 here. */
13048 tbl_key.is_fdb = attr->transfer;
13049 tbl_key.is_egress = attr->egress;
13050 tbl_key.level = dev_flow->dv.group;
13051 tbl_key.id = dev_flow->dv.table_id;
13052 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
13053 tunnel, attr->group, error))
13059 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13062 * @param[in, out] action
13063 * Shred RSS action holding hash RX queue objects.
13064 * @param[in] hash_fields
13065 * Defines combination of packet fields to participate in RX hash.
13066 * @param[in] tunnel
13068 * @param[in] hrxq_idx
13069 * Hash RX queue index to set.
13072 * 0 on success, otherwise negative errno value.
13075 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
13076 const uint64_t hash_fields,
13079 uint32_t *hrxqs = action->hrxq;
13081 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13082 case MLX5_RSS_HASH_IPV4:
13083 /* fall-through. */
13084 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13085 /* fall-through. */
13086 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13087 hrxqs[0] = hrxq_idx;
13089 case MLX5_RSS_HASH_IPV4_TCP:
13090 /* fall-through. */
13091 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13092 /* fall-through. */
13093 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13094 hrxqs[1] = hrxq_idx;
13096 case MLX5_RSS_HASH_IPV4_UDP:
13097 /* fall-through. */
13098 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13099 /* fall-through. */
13100 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13101 hrxqs[2] = hrxq_idx;
13103 case MLX5_RSS_HASH_IPV6:
13104 /* fall-through. */
13105 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13106 /* fall-through. */
13107 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13108 hrxqs[3] = hrxq_idx;
13110 case MLX5_RSS_HASH_IPV6_TCP:
13111 /* fall-through. */
13112 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13113 /* fall-through. */
13114 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13115 hrxqs[4] = hrxq_idx;
13117 case MLX5_RSS_HASH_IPV6_UDP:
13118 /* fall-through. */
13119 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13120 /* fall-through. */
13121 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13122 hrxqs[5] = hrxq_idx;
13124 case MLX5_RSS_HASH_NONE:
13125 hrxqs[6] = hrxq_idx;
13133 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
13137 * Pointer to the Ethernet device structure.
13139 * Shared RSS action ID holding hash RX queue objects.
13140 * @param[in] hash_fields
13141 * Defines combination of packet fields to participate in RX hash.
13142 * @param[in] tunnel
13146 * Valid hash RX queue index, otherwise 0.
13149 __flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
13150 const uint64_t hash_fields)
13152 struct mlx5_priv *priv = dev->data->dev_private;
13153 struct mlx5_shared_action_rss *shared_rss =
13154 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
13155 const uint32_t *hrxqs = shared_rss->hrxq;
13157 switch (hash_fields & ~IBV_RX_HASH_INNER) {
13158 case MLX5_RSS_HASH_IPV4:
13159 /* fall-through. */
13160 case MLX5_RSS_HASH_IPV4_DST_ONLY:
13161 /* fall-through. */
13162 case MLX5_RSS_HASH_IPV4_SRC_ONLY:
13164 case MLX5_RSS_HASH_IPV4_TCP:
13165 /* fall-through. */
13166 case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
13167 /* fall-through. */
13168 case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
13170 case MLX5_RSS_HASH_IPV4_UDP:
13171 /* fall-through. */
13172 case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
13173 /* fall-through. */
13174 case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
13176 case MLX5_RSS_HASH_IPV6:
13177 /* fall-through. */
13178 case MLX5_RSS_HASH_IPV6_DST_ONLY:
13179 /* fall-through. */
13180 case MLX5_RSS_HASH_IPV6_SRC_ONLY:
13182 case MLX5_RSS_HASH_IPV6_TCP:
13183 /* fall-through. */
13184 case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
13185 /* fall-through. */
13186 case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
13188 case MLX5_RSS_HASH_IPV6_UDP:
13189 /* fall-through. */
13190 case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
13191 /* fall-through. */
13192 case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
13194 case MLX5_RSS_HASH_NONE:
13203 * Apply the flow to the NIC, lock free,
13204 * (mutex should be acquired by caller).
13207 * Pointer to the Ethernet device structure.
13208 * @param[in, out] flow
13209 * Pointer to flow structure.
13210 * @param[out] error
13211 * Pointer to error structure.
13214 * 0 on success, a negative errno value otherwise and rte_errno is set.
13217 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
13218 struct rte_flow_error *error)
13220 struct mlx5_flow_dv_workspace *dv;
13221 struct mlx5_flow_handle *dh;
13222 struct mlx5_flow_handle_dv *dv_h;
13223 struct mlx5_flow *dev_flow;
13224 struct mlx5_priv *priv = dev->data->dev_private;
13225 uint32_t handle_idx;
13229 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13230 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
13233 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
13234 dev_flow = &wks->flows[idx];
13235 dv = &dev_flow->dv;
13236 dh = dev_flow->handle;
13239 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
13240 if (dv->transfer) {
13241 MLX5_ASSERT(priv->sh->dr_drop_action);
13242 dv->actions[n++] = priv->sh->dr_drop_action;
13244 #ifdef HAVE_MLX5DV_DR
13245 /* DR supports drop action placeholder. */
13246 MLX5_ASSERT(priv->sh->dr_drop_action);
13247 dv->actions[n++] = priv->sh->dr_drop_action;
13249 /* For DV we use the explicit drop queue. */
13250 MLX5_ASSERT(priv->drop_queue.hrxq);
13252 priv->drop_queue.hrxq->action;
13255 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
13256 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
13257 struct mlx5_hrxq *hrxq;
13260 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
13265 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13266 "cannot get hash queue");
13269 dh->rix_hrxq = hrxq_idx;
13270 dv->actions[n++] = hrxq->action;
13271 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13272 struct mlx5_hrxq *hrxq = NULL;
13275 hrxq_idx = __flow_dv_action_rss_hrxq_lookup(dev,
13276 rss_desc->shared_rss,
13277 dev_flow->hash_fields);
13279 hrxq = mlx5_ipool_get
13280 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
13285 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13286 "cannot get hash queue");
13289 dh->rix_srss = rss_desc->shared_rss;
13290 dv->actions[n++] = hrxq->action;
13291 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
13292 if (!priv->sh->default_miss_action) {
13295 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13296 "default miss action not be created.");
13299 dv->actions[n++] = priv->sh->default_miss_action;
13301 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
13302 (void *)&dv->value, n,
13303 dv->actions, &dh->drv_flow);
13305 rte_flow_error_set(error, errno,
13306 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13308 "hardware refuses to create flow");
13311 if (priv->vmwa_context &&
13312 dh->vf_vlan.tag && !dh->vf_vlan.created) {
13314 * The rule contains the VLAN pattern.
13315 * For VF we are going to create VLAN
13316 * interface to make hypervisor set correct
13317 * e-Switch vport context.
13319 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
13324 err = rte_errno; /* Save rte_errno before cleanup. */
13325 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
13326 handle_idx, dh, next) {
13327 /* hrxq is union, don't clear it if the flag is not set. */
13328 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
13329 mlx5_hrxq_release(dev, dh->rix_hrxq);
13331 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
13334 if (dh->vf_vlan.tag && dh->vf_vlan.created)
13335 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
13337 rte_errno = err; /* Restore rte_errno. */
13342 flow_dv_matcher_remove_cb(struct mlx5_cache_list *list __rte_unused,
13343 struct mlx5_cache_entry *entry)
13345 struct mlx5_flow_dv_matcher *cache = container_of(entry, typeof(*cache),
13348 claim_zero(mlx5_flow_os_destroy_flow_matcher(cache->matcher_object));
13353 * Release the flow matcher.
13356 * Pointer to Ethernet device.
13358 * Index to port ID action resource.
13361 * 1 while a reference on it exists, 0 when freed.
13364 flow_dv_matcher_release(struct rte_eth_dev *dev,
13365 struct mlx5_flow_handle *handle)
13367 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
13368 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
13369 typeof(*tbl), tbl);
13372 MLX5_ASSERT(matcher->matcher_object);
13373 ret = mlx5_cache_unregister(&tbl->matchers, &matcher->entry);
13374 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
13379 * Release encap_decap resource.
13382 * Pointer to the hash list.
13384 * Pointer to exist resource entry object.
13387 flow_dv_encap_decap_remove_cb(struct mlx5_hlist *list,
13388 struct mlx5_hlist_entry *entry)
13390 struct mlx5_dev_ctx_shared *sh = list->ctx;
13391 struct mlx5_flow_dv_encap_decap_resource *res =
13392 container_of(entry, typeof(*res), entry);
13394 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13395 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
13399 * Release an encap/decap resource.
13402 * Pointer to Ethernet device.
13403 * @param encap_decap_idx
13404 * Index of encap decap resource.
13407 * 1 while a reference on it exists, 0 when freed.
13410 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
13411 uint32_t encap_decap_idx)
13413 struct mlx5_priv *priv = dev->data->dev_private;
13414 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
13416 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
13418 if (!cache_resource)
13420 MLX5_ASSERT(cache_resource->action);
13421 return mlx5_hlist_unregister(priv->sh->encaps_decaps,
13422 &cache_resource->entry);
13426 * Release an jump to table action resource.
13429 * Pointer to Ethernet device.
13431 * Index to the jump action resource.
13434 * 1 while a reference on it exists, 0 when freed.
13437 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
13440 struct mlx5_priv *priv = dev->data->dev_private;
13441 struct mlx5_flow_tbl_data_entry *tbl_data;
13443 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
13447 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
13451 flow_dv_modify_remove_cb(struct mlx5_hlist *list __rte_unused,
13452 struct mlx5_hlist_entry *entry)
13454 struct mlx5_flow_dv_modify_hdr_resource *res =
13455 container_of(entry, typeof(*res), entry);
13457 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
13462 * Release a modify-header resource.
13465 * Pointer to Ethernet device.
13467 * Pointer to mlx5_flow_handle.
13470 * 1 while a reference on it exists, 0 when freed.
13473 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
13474 struct mlx5_flow_handle *handle)
13476 struct mlx5_priv *priv = dev->data->dev_private;
13477 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
13479 MLX5_ASSERT(entry->action);
13480 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
13484 flow_dv_port_id_remove_cb(struct mlx5_cache_list *list,
13485 struct mlx5_cache_entry *entry)
13487 struct mlx5_dev_ctx_shared *sh = list->ctx;
13488 struct mlx5_flow_dv_port_id_action_resource *cache =
13489 container_of(entry, typeof(*cache), entry);
13491 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
13492 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], cache->idx);
13496 * Release port ID action resource.
13499 * Pointer to Ethernet device.
13501 * Pointer to mlx5_flow_handle.
13504 * 1 while a reference on it exists, 0 when freed.
13507 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
13510 struct mlx5_priv *priv = dev->data->dev_private;
13511 struct mlx5_flow_dv_port_id_action_resource *cache;
13513 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
13516 MLX5_ASSERT(cache->action);
13517 return mlx5_cache_unregister(&priv->sh->port_id_action_list,
13522 * Release shared RSS action resource.
13525 * Pointer to Ethernet device.
13527 * Shared RSS action index.
13530 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
13532 struct mlx5_priv *priv = dev->data->dev_private;
13533 struct mlx5_shared_action_rss *shared_rss;
13535 shared_rss = mlx5_ipool_get
13536 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
13537 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
13541 flow_dv_push_vlan_remove_cb(struct mlx5_cache_list *list,
13542 struct mlx5_cache_entry *entry)
13544 struct mlx5_dev_ctx_shared *sh = list->ctx;
13545 struct mlx5_flow_dv_push_vlan_action_resource *cache =
13546 container_of(entry, typeof(*cache), entry);
13548 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
13549 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], cache->idx);
13553 * Release push vlan action resource.
13556 * Pointer to Ethernet device.
13558 * Pointer to mlx5_flow_handle.
13561 * 1 while a reference on it exists, 0 when freed.
13564 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
13565 struct mlx5_flow_handle *handle)
13567 struct mlx5_priv *priv = dev->data->dev_private;
13568 struct mlx5_flow_dv_push_vlan_action_resource *cache;
13569 uint32_t idx = handle->dvh.rix_push_vlan;
13571 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
13574 MLX5_ASSERT(cache->action);
13575 return mlx5_cache_unregister(&priv->sh->push_vlan_action_list,
13580 * Release the fate resource.
13583 * Pointer to Ethernet device.
13585 * Pointer to mlx5_flow_handle.
13588 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
13589 struct mlx5_flow_handle *handle)
13591 if (!handle->rix_fate)
13593 switch (handle->fate_action) {
13594 case MLX5_FLOW_FATE_QUEUE:
13595 if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
13596 mlx5_hrxq_release(dev, handle->rix_hrxq);
13598 case MLX5_FLOW_FATE_JUMP:
13599 flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
13601 case MLX5_FLOW_FATE_PORT_ID:
13602 flow_dv_port_id_action_resource_release(dev,
13603 handle->rix_port_id_action);
13606 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
13609 handle->rix_fate = 0;
13613 flow_dv_sample_remove_cb(struct mlx5_cache_list *list __rte_unused,
13614 struct mlx5_cache_entry *entry)
13616 struct mlx5_flow_dv_sample_resource *cache_resource =
13617 container_of(entry, typeof(*cache_resource), entry);
13618 struct rte_eth_dev *dev = cache_resource->dev;
13619 struct mlx5_priv *priv = dev->data->dev_private;
13621 if (cache_resource->verbs_action)
13622 claim_zero(mlx5_flow_os_destroy_flow_action
13623 (cache_resource->verbs_action));
13624 if (cache_resource->normal_path_tbl)
13625 flow_dv_tbl_resource_release(MLX5_SH(dev),
13626 cache_resource->normal_path_tbl);
13627 flow_dv_sample_sub_actions_release(dev,
13628 &cache_resource->sample_idx);
13629 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
13630 cache_resource->idx);
13631 DRV_LOG(DEBUG, "sample resource %p: removed",
13632 (void *)cache_resource);
13636 * Release an sample resource.
13639 * Pointer to Ethernet device.
13641 * Pointer to mlx5_flow_handle.
13644 * 1 while a reference on it exists, 0 when freed.
13647 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
13648 struct mlx5_flow_handle *handle)
13650 struct mlx5_priv *priv = dev->data->dev_private;
13651 struct mlx5_flow_dv_sample_resource *cache_resource;
13653 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
13654 handle->dvh.rix_sample);
13655 if (!cache_resource)
13657 MLX5_ASSERT(cache_resource->verbs_action);
13658 return mlx5_cache_unregister(&priv->sh->sample_action_list,
13659 &cache_resource->entry);
13663 flow_dv_dest_array_remove_cb(struct mlx5_cache_list *list __rte_unused,
13664 struct mlx5_cache_entry *entry)
13666 struct mlx5_flow_dv_dest_array_resource *cache_resource =
13667 container_of(entry, typeof(*cache_resource), entry);
13668 struct rte_eth_dev *dev = cache_resource->dev;
13669 struct mlx5_priv *priv = dev->data->dev_private;
13672 MLX5_ASSERT(cache_resource->action);
13673 if (cache_resource->action)
13674 claim_zero(mlx5_flow_os_destroy_flow_action
13675 (cache_resource->action));
13676 for (; i < cache_resource->num_of_dest; i++)
13677 flow_dv_sample_sub_actions_release(dev,
13678 &cache_resource->sample_idx[i]);
13679 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
13680 cache_resource->idx);
13681 DRV_LOG(DEBUG, "destination array resource %p: removed",
13682 (void *)cache_resource);
13686 * Release an destination array resource.
13689 * Pointer to Ethernet device.
13691 * Pointer to mlx5_flow_handle.
13694 * 1 while a reference on it exists, 0 when freed.
13697 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
13698 struct mlx5_flow_handle *handle)
13700 struct mlx5_priv *priv = dev->data->dev_private;
13701 struct mlx5_flow_dv_dest_array_resource *cache;
13703 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
13704 handle->dvh.rix_dest_array);
13707 MLX5_ASSERT(cache->action);
13708 return mlx5_cache_unregister(&priv->sh->dest_array_list,
13713 flow_dv_geneve_tlv_option_resource_release(struct rte_eth_dev *dev)
13715 struct mlx5_priv *priv = dev->data->dev_private;
13716 struct mlx5_dev_ctx_shared *sh = priv->sh;
13717 struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
13718 sh->geneve_tlv_option_resource;
13719 rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
13720 if (geneve_opt_resource) {
13721 if (!(__atomic_sub_fetch(&geneve_opt_resource->refcnt, 1,
13722 __ATOMIC_RELAXED))) {
13723 claim_zero(mlx5_devx_cmd_destroy
13724 (geneve_opt_resource->obj));
13725 mlx5_free(sh->geneve_tlv_option_resource);
13726 sh->geneve_tlv_option_resource = NULL;
13729 rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
13733 * Remove the flow from the NIC but keeps it in memory.
13734 * Lock free, (mutex should be acquired by caller).
13737 * Pointer to Ethernet device.
13738 * @param[in, out] flow
13739 * Pointer to flow structure.
13742 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
13744 struct mlx5_flow_handle *dh;
13745 uint32_t handle_idx;
13746 struct mlx5_priv *priv = dev->data->dev_private;
13750 handle_idx = flow->dev_handles;
13751 while (handle_idx) {
13752 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
13756 if (dh->drv_flow) {
13757 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
13758 dh->drv_flow = NULL;
13760 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
13761 flow_dv_fate_resource_release(dev, dh);
13762 if (dh->vf_vlan.tag && dh->vf_vlan.created)
13763 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
13764 handle_idx = dh->next.next;
13769 * Remove the flow from the NIC and the memory.
13770 * Lock free, (mutex should be acquired by caller).
13773 * Pointer to the Ethernet device structure.
13774 * @param[in, out] flow
13775 * Pointer to flow structure.
13778 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
13780 struct mlx5_flow_handle *dev_handle;
13781 struct mlx5_priv *priv = dev->data->dev_private;
13782 struct mlx5_flow_meter_info *fm = NULL;
13787 flow_dv_remove(dev, flow);
13788 if (flow->counter) {
13789 flow_dv_counter_free(dev, flow->counter);
13793 fm = flow_dv_meter_find_by_idx(priv, flow->meter);
13795 mlx5_flow_meter_detach(priv, fm);
13798 /* Keep the current age handling by default. */
13799 if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
13800 flow_dv_aso_ct_release(dev, flow->ct);
13801 else if (flow->age)
13802 flow_dv_aso_age_release(dev, flow->age);
13803 if (flow->geneve_tlv_option) {
13804 flow_dv_geneve_tlv_option_resource_release(dev);
13805 flow->geneve_tlv_option = 0;
13807 while (flow->dev_handles) {
13808 uint32_t tmp_idx = flow->dev_handles;
13810 dev_handle = mlx5_ipool_get(priv->sh->ipool
13811 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
13814 flow->dev_handles = dev_handle->next.next;
13815 if (dev_handle->dvh.matcher)
13816 flow_dv_matcher_release(dev, dev_handle);
13817 if (dev_handle->dvh.rix_sample)
13818 flow_dv_sample_resource_release(dev, dev_handle);
13819 if (dev_handle->dvh.rix_dest_array)
13820 flow_dv_dest_array_resource_release(dev, dev_handle);
13821 if (dev_handle->dvh.rix_encap_decap)
13822 flow_dv_encap_decap_resource_release(dev,
13823 dev_handle->dvh.rix_encap_decap);
13824 if (dev_handle->dvh.modify_hdr)
13825 flow_dv_modify_hdr_resource_release(dev, dev_handle);
13826 if (dev_handle->dvh.rix_push_vlan)
13827 flow_dv_push_vlan_action_resource_release(dev,
13829 if (dev_handle->dvh.rix_tag)
13830 flow_dv_tag_release(dev,
13831 dev_handle->dvh.rix_tag);
13832 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
13833 flow_dv_fate_resource_release(dev, dev_handle);
13835 srss = dev_handle->rix_srss;
13836 if (fm && dev_handle->is_meter_flow_id &&
13837 dev_handle->split_flow_id)
13838 mlx5_ipool_free(fm->flow_ipool,
13839 dev_handle->split_flow_id);
13840 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
13844 flow_dv_shared_rss_action_release(dev, srss);
13848 * Release array of hash RX queue objects.
13852 * Pointer to the Ethernet device structure.
13853 * @param[in, out] hrxqs
13854 * Array of hash RX queue objects.
13857 * Total number of references to hash RX queue objects in *hrxqs* array
13858 * after this operation.
13861 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
13862 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
13867 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
13868 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
13878 * Release all hash RX queue objects representing shared RSS action.
13881 * Pointer to the Ethernet device structure.
13882 * @param[in, out] action
13883 * Shared RSS action to remove hash RX queue objects from.
13886 * Total number of references to hash RX queue objects stored in *action*
13887 * after this operation.
13888 * Expected to be 0 if no external references held.
13891 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
13892 struct mlx5_shared_action_rss *shared_rss)
13894 return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
13898 * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
13901 * Only one hash value is available for one L3+L4 combination:
13903 * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
13904 * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
13905 * same slot in mlx5_rss_hash_fields.
13908 * Pointer to the shared action RSS conf.
13909 * @param[in, out] hash_field
13910 * hash_field variable needed to be adjusted.
13916 __flow_dv_action_rss_l34_hash_adjust(struct mlx5_shared_action_rss *rss,
13917 uint64_t *hash_field)
13919 uint64_t rss_types = rss->origin.types;
13921 switch (*hash_field & ~IBV_RX_HASH_INNER) {
13922 case MLX5_RSS_HASH_IPV4:
13923 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
13924 *hash_field &= ~MLX5_RSS_HASH_IPV4;
13925 if (rss_types & ETH_RSS_L3_DST_ONLY)
13926 *hash_field |= IBV_RX_HASH_DST_IPV4;
13927 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
13928 *hash_field |= IBV_RX_HASH_SRC_IPV4;
13930 *hash_field |= MLX5_RSS_HASH_IPV4;
13933 case MLX5_RSS_HASH_IPV6:
13934 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
13935 *hash_field &= ~MLX5_RSS_HASH_IPV6;
13936 if (rss_types & ETH_RSS_L3_DST_ONLY)
13937 *hash_field |= IBV_RX_HASH_DST_IPV6;
13938 else if (rss_types & ETH_RSS_L3_SRC_ONLY)
13939 *hash_field |= IBV_RX_HASH_SRC_IPV6;
13941 *hash_field |= MLX5_RSS_HASH_IPV6;
13944 case MLX5_RSS_HASH_IPV4_UDP:
13945 /* fall-through. */
13946 case MLX5_RSS_HASH_IPV6_UDP:
13947 if (rss_types & ETH_RSS_UDP) {
13948 *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
13949 if (rss_types & ETH_RSS_L4_DST_ONLY)
13950 *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
13951 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
13952 *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
13954 *hash_field |= MLX5_UDP_IBV_RX_HASH;
13957 case MLX5_RSS_HASH_IPV4_TCP:
13958 /* fall-through. */
13959 case MLX5_RSS_HASH_IPV6_TCP:
13960 if (rss_types & ETH_RSS_TCP) {
13961 *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
13962 if (rss_types & ETH_RSS_L4_DST_ONLY)
13963 *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
13964 else if (rss_types & ETH_RSS_L4_SRC_ONLY)
13965 *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
13967 *hash_field |= MLX5_TCP_IBV_RX_HASH;
13976 * Setup shared RSS action.
13977 * Prepare set of hash RX queue objects sufficient to handle all valid
13978 * hash_fields combinations (see enum ibv_rx_hash_fields).
13981 * Pointer to the Ethernet device structure.
13982 * @param[in] action_idx
13983 * Shared RSS action ipool index.
13984 * @param[in, out] action
13985 * Partially initialized shared RSS action.
13986 * @param[out] error
13987 * Perform verbose error reporting if not NULL. Initialized in case of
13991 * 0 on success, otherwise negative errno value.
13994 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
13995 uint32_t action_idx,
13996 struct mlx5_shared_action_rss *shared_rss,
13997 struct rte_flow_error *error)
13999 struct mlx5_flow_rss_desc rss_desc = { 0 };
14003 if (mlx5_ind_table_obj_setup(dev, shared_rss->ind_tbl)) {
14004 return rte_flow_error_set(error, rte_errno,
14005 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14006 "cannot setup indirection table");
14008 memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
14009 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
14010 rss_desc.const_q = shared_rss->origin.queue;
14011 rss_desc.queue_num = shared_rss->origin.queue_num;
14012 /* Set non-zero value to indicate a shared RSS. */
14013 rss_desc.shared_rss = action_idx;
14014 rss_desc.ind_tbl = shared_rss->ind_tbl;
14015 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
14017 uint64_t hash_fields = mlx5_rss_hash_fields[i];
14020 __flow_dv_action_rss_l34_hash_adjust(shared_rss, &hash_fields);
14021 if (shared_rss->origin.level > 1) {
14022 hash_fields |= IBV_RX_HASH_INNER;
14025 rss_desc.tunnel = tunnel;
14026 rss_desc.hash_fields = hash_fields;
14027 hrxq_idx = mlx5_hrxq_get(dev, &rss_desc);
14031 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14032 "cannot get hash queue");
14033 goto error_hrxq_new;
14035 err = __flow_dv_action_rss_hrxq_set
14036 (shared_rss, hash_fields, hrxq_idx);
14042 __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14043 if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
14044 shared_rss->ind_tbl = NULL;
14050 * Create shared RSS action.
14053 * Pointer to the Ethernet device structure.
14055 * Shared action configuration.
14057 * RSS action specification used to create shared action.
14058 * @param[out] error
14059 * Perform verbose error reporting if not NULL. Initialized in case of
14063 * A valid shared action ID in case of success, 0 otherwise and
14064 * rte_errno is set.
14067 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
14068 const struct rte_flow_indir_action_conf *conf,
14069 const struct rte_flow_action_rss *rss,
14070 struct rte_flow_error *error)
14072 struct mlx5_priv *priv = dev->data->dev_private;
14073 struct mlx5_shared_action_rss *shared_rss = NULL;
14074 void *queue = NULL;
14075 struct rte_flow_action_rss *origin;
14076 const uint8_t *rss_key;
14077 uint32_t queue_size = rss->queue_num * sizeof(uint16_t);
14080 RTE_SET_USED(conf);
14081 queue = mlx5_malloc(0, RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14083 shared_rss = mlx5_ipool_zmalloc
14084 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
14085 if (!shared_rss || !queue) {
14086 rte_flow_error_set(error, ENOMEM,
14087 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14088 "cannot allocate resource memory");
14089 goto error_rss_init;
14091 if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
14092 rte_flow_error_set(error, E2BIG,
14093 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14094 "rss action number out of range");
14095 goto error_rss_init;
14097 shared_rss->ind_tbl = mlx5_malloc(MLX5_MEM_ZERO,
14098 sizeof(*shared_rss->ind_tbl),
14100 if (!shared_rss->ind_tbl) {
14101 rte_flow_error_set(error, ENOMEM,
14102 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14103 "cannot allocate resource memory");
14104 goto error_rss_init;
14106 memcpy(queue, rss->queue, queue_size);
14107 shared_rss->ind_tbl->queues = queue;
14108 shared_rss->ind_tbl->queues_n = rss->queue_num;
14109 origin = &shared_rss->origin;
14110 origin->func = rss->func;
14111 origin->level = rss->level;
14112 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
14113 origin->types = !rss->types ? ETH_RSS_IP : rss->types;
14114 /* NULL RSS key indicates default RSS key. */
14115 rss_key = !rss->key ? rss_hash_default_key : rss->key;
14116 memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
14117 origin->key = &shared_rss->key[0];
14118 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
14119 origin->queue = queue;
14120 origin->queue_num = rss->queue_num;
14121 if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
14122 goto error_rss_init;
14123 rte_spinlock_init(&shared_rss->action_rss_sl);
14124 __atomic_add_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
14125 rte_spinlock_lock(&priv->shared_act_sl);
14126 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14127 &priv->rss_shared_actions, idx, shared_rss, next);
14128 rte_spinlock_unlock(&priv->shared_act_sl);
14132 if (shared_rss->ind_tbl)
14133 mlx5_free(shared_rss->ind_tbl);
14134 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14143 * Destroy the shared RSS action.
14144 * Release related hash RX queue objects.
14147 * Pointer to the Ethernet device structure.
14149 * The shared RSS action object ID to be removed.
14150 * @param[out] error
14151 * Perform verbose error reporting if not NULL. Initialized in case of
14155 * 0 on success, otherwise negative errno value.
14158 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
14159 struct rte_flow_error *error)
14161 struct mlx5_priv *priv = dev->data->dev_private;
14162 struct mlx5_shared_action_rss *shared_rss =
14163 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14164 uint32_t old_refcnt = 1;
14166 uint16_t *queue = NULL;
14169 return rte_flow_error_set(error, EINVAL,
14170 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14171 "invalid shared action");
14172 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
14174 return rte_flow_error_set(error, EBUSY,
14175 RTE_FLOW_ERROR_TYPE_ACTION,
14177 "shared rss hrxq has references");
14178 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
14179 0, 0, __ATOMIC_ACQUIRE,
14181 return rte_flow_error_set(error, EBUSY,
14182 RTE_FLOW_ERROR_TYPE_ACTION,
14184 "shared rss has references");
14185 queue = shared_rss->ind_tbl->queues;
14186 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true);
14188 return rte_flow_error_set(error, EBUSY,
14189 RTE_FLOW_ERROR_TYPE_ACTION,
14191 "shared rss indirection table has"
14194 rte_spinlock_lock(&priv->shared_act_sl);
14195 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14196 &priv->rss_shared_actions, idx, shared_rss, next);
14197 rte_spinlock_unlock(&priv->shared_act_sl);
14198 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
14204 * Create indirect action, lock free,
14205 * (mutex should be acquired by caller).
14206 * Dispatcher for action type specific call.
14209 * Pointer to the Ethernet device structure.
14211 * Shared action configuration.
14212 * @param[in] action
14213 * Action specification used to create indirect action.
14214 * @param[out] error
14215 * Perform verbose error reporting if not NULL. Initialized in case of
14219 * A valid shared action handle in case of success, NULL otherwise and
14220 * rte_errno is set.
14222 static struct rte_flow_action_handle *
14223 flow_dv_action_create(struct rte_eth_dev *dev,
14224 const struct rte_flow_indir_action_conf *conf,
14225 const struct rte_flow_action *action,
14226 struct rte_flow_error *err)
14228 struct mlx5_priv *priv = dev->data->dev_private;
14229 uint32_t age_idx = 0;
14233 switch (action->type) {
14234 case RTE_FLOW_ACTION_TYPE_RSS:
14235 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
14236 idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
14237 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14239 case RTE_FLOW_ACTION_TYPE_AGE:
14240 age_idx = flow_dv_aso_age_alloc(dev, err);
14245 idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
14246 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
14247 flow_dv_aso_age_params_init(dev, age_idx,
14248 ((const struct rte_flow_action_age *)
14249 action->conf)->context ?
14250 ((const struct rte_flow_action_age *)
14251 action->conf)->context :
14252 (void *)(uintptr_t)idx,
14253 ((const struct rte_flow_action_age *)
14254 action->conf)->timeout);
14257 case RTE_FLOW_ACTION_TYPE_COUNT:
14258 ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
14259 idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
14260 MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
14262 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
14263 ret = flow_dv_translate_create_conntrack(dev, action->conf,
14265 idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
14268 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
14269 NULL, "action type not supported");
14272 return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
14276 * Destroy the indirect action.
14277 * Release action related resources on the NIC and the memory.
14278 * Lock free, (mutex should be acquired by caller).
14279 * Dispatcher for action type specific call.
14282 * Pointer to the Ethernet device structure.
14283 * @param[in] handle
14284 * The indirect action object handle to be removed.
14285 * @param[out] error
14286 * Perform verbose error reporting if not NULL. Initialized in case of
14290 * 0 on success, otherwise negative errno value.
14293 flow_dv_action_destroy(struct rte_eth_dev *dev,
14294 struct rte_flow_action_handle *handle,
14295 struct rte_flow_error *error)
14297 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14298 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14299 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
14300 struct mlx5_flow_counter *cnt;
14301 uint32_t no_flow_refcnt = 1;
14305 case MLX5_INDIRECT_ACTION_TYPE_RSS:
14306 return __flow_dv_action_rss_release(dev, idx, error);
14307 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
14308 cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
14309 if (!__atomic_compare_exchange_n(&cnt->shared_info.refcnt,
14310 &no_flow_refcnt, 1, false,
14313 return rte_flow_error_set(error, EBUSY,
14314 RTE_FLOW_ERROR_TYPE_ACTION,
14316 "Indirect count action has references");
14317 flow_dv_counter_free(dev, idx);
14319 case MLX5_INDIRECT_ACTION_TYPE_AGE:
14320 ret = flow_dv_aso_age_release(dev, idx);
14323 * In this case, the last flow has a reference will
14324 * actually release the age action.
14326 DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
14327 " released with references %d.", idx, ret);
14329 case MLX5_INDIRECT_ACTION_TYPE_CT:
14330 ret = flow_dv_aso_ct_release(dev, idx);
14334 DRV_LOG(DEBUG, "Connection tracking object %u still "
14335 "has references %d.", idx, ret);
14338 return rte_flow_error_set(error, ENOTSUP,
14339 RTE_FLOW_ERROR_TYPE_ACTION,
14341 "action type not supported");
14346 * Updates in place shared RSS action configuration.
14349 * Pointer to the Ethernet device structure.
14351 * The shared RSS action object ID to be updated.
14352 * @param[in] action_conf
14353 * RSS action specification used to modify *shared_rss*.
14354 * @param[out] error
14355 * Perform verbose error reporting if not NULL. Initialized in case of
14359 * 0 on success, otherwise negative errno value.
14360 * @note: currently only support update of RSS queues.
14363 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
14364 const struct rte_flow_action_rss *action_conf,
14365 struct rte_flow_error *error)
14367 struct mlx5_priv *priv = dev->data->dev_private;
14368 struct mlx5_shared_action_rss *shared_rss =
14369 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
14371 void *queue = NULL;
14372 uint16_t *queue_old = NULL;
14373 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
14376 return rte_flow_error_set(error, EINVAL,
14377 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14378 "invalid shared action to update");
14379 if (priv->obj_ops.ind_table_modify == NULL)
14380 return rte_flow_error_set(error, ENOTSUP,
14381 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14382 "cannot modify indirection table");
14383 queue = mlx5_malloc(MLX5_MEM_ZERO,
14384 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
14387 return rte_flow_error_set(error, ENOMEM,
14388 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14390 "cannot allocate resource memory");
14391 memcpy(queue, action_conf->queue, queue_size);
14392 MLX5_ASSERT(shared_rss->ind_tbl);
14393 rte_spinlock_lock(&shared_rss->action_rss_sl);
14394 queue_old = shared_rss->ind_tbl->queues;
14395 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
14396 queue, action_conf->queue_num, true);
14399 ret = rte_flow_error_set(error, rte_errno,
14400 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14401 "cannot update indirection table");
14403 mlx5_free(queue_old);
14404 shared_rss->origin.queue = queue;
14405 shared_rss->origin.queue_num = action_conf->queue_num;
14407 rte_spinlock_unlock(&shared_rss->action_rss_sl);
14412 * Updates in place conntrack context or direction.
14413 * Context update should be synchronized.
14416 * Pointer to the Ethernet device structure.
14418 * The conntrack object ID to be updated.
14419 * @param[in] update
14420 * Pointer to the structure of information to update.
14421 * @param[out] error
14422 * Perform verbose error reporting if not NULL. Initialized in case of
14426 * 0 on success, otherwise negative errno value.
14429 __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
14430 const struct rte_flow_modify_conntrack *update,
14431 struct rte_flow_error *error)
14433 struct mlx5_priv *priv = dev->data->dev_private;
14434 struct mlx5_aso_ct_action *ct;
14435 const struct rte_flow_action_conntrack *new_prf;
14437 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
14440 if (PORT_ID(priv) != owner)
14441 return rte_flow_error_set(error, EACCES,
14442 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14444 "CT object owned by another port");
14445 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
14446 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
14448 return rte_flow_error_set(error, ENOMEM,
14449 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14451 "CT object is inactive");
14452 new_prf = &update->new_ct;
14453 if (update->direction)
14454 ct->is_original = !!new_prf->is_original_dir;
14455 if (update->state) {
14456 /* Only validate the profile when it needs to be updated. */
14457 ret = mlx5_validate_action_ct(dev, new_prf, error);
14460 ret = mlx5_aso_ct_update_by_wqe(priv->sh, ct, new_prf);
14462 return rte_flow_error_set(error, EIO,
14463 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14465 "Failed to send CT context update WQE");
14466 /* Block until ready or a failure. */
14467 ret = mlx5_aso_ct_available(priv->sh, ct);
14469 rte_flow_error_set(error, rte_errno,
14470 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14472 "Timeout to get the CT update");
14478 * Updates in place shared action configuration, lock free,
14479 * (mutex should be acquired by caller).
14482 * Pointer to the Ethernet device structure.
14483 * @param[in] handle
14484 * The indirect action object handle to be updated.
14485 * @param[in] update
14486 * Action specification used to modify the action pointed by *handle*.
14487 * *update* could be of same type with the action pointed by the *handle*
14488 * handle argument, or some other structures like a wrapper, depending on
14489 * the indirect action type.
14490 * @param[out] error
14491 * Perform verbose error reporting if not NULL. Initialized in case of
14495 * 0 on success, otherwise negative errno value.
14498 flow_dv_action_update(struct rte_eth_dev *dev,
14499 struct rte_flow_action_handle *handle,
14500 const void *update,
14501 struct rte_flow_error *err)
14503 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
14504 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
14505 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
14506 const void *action_conf;
14509 case MLX5_INDIRECT_ACTION_TYPE_RSS:
14510 action_conf = ((const struct rte_flow_action *)update)->conf;
14511 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
14512 case MLX5_INDIRECT_ACTION_TYPE_CT:
14513 return __flow_dv_action_ct_update(dev, idx, update, err);
14515 return rte_flow_error_set(err, ENOTSUP,
14516 RTE_FLOW_ERROR_TYPE_ACTION,
14518 "action type update not supported");
14523 * Destroy the meter sub policy table rules.
14524 * Lock free, (mutex should be acquired by caller).
14527 * Pointer to Ethernet device.
14528 * @param[in] sub_policy
14529 * Pointer to meter sub policy table.
14532 __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
14533 struct mlx5_flow_meter_sub_policy *sub_policy)
14535 struct mlx5_flow_tbl_data_entry *tbl;
14538 for (i = 0; i < RTE_COLORS; i++) {
14539 if (sub_policy->color_rule[i]) {
14540 claim_zero(mlx5_flow_os_destroy_flow
14541 (sub_policy->color_rule[i]));
14542 sub_policy->color_rule[i] = NULL;
14544 if (sub_policy->color_matcher[i]) {
14545 tbl = container_of(sub_policy->color_matcher[i]->tbl,
14546 typeof(*tbl), tbl);
14547 mlx5_cache_unregister(&tbl->matchers,
14548 &sub_policy->color_matcher[i]->entry);
14549 sub_policy->color_matcher[i] = NULL;
14552 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
14553 if (sub_policy->rix_hrxq[i]) {
14554 mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
14555 sub_policy->rix_hrxq[i] = 0;
14557 if (sub_policy->jump_tbl[i]) {
14558 flow_dv_tbl_resource_release(MLX5_SH(dev),
14559 sub_policy->jump_tbl[i]);
14560 sub_policy->jump_tbl[i] = NULL;
14563 if (sub_policy->tbl_rsc) {
14564 flow_dv_tbl_resource_release(MLX5_SH(dev),
14565 sub_policy->tbl_rsc);
14566 sub_policy->tbl_rsc = NULL;
14571 * Destroy policy rules, lock free,
14572 * (mutex should be acquired by caller).
14573 * Dispatcher for action type specific call.
14576 * Pointer to the Ethernet device structure.
14577 * @param[in] mtr_policy
14578 * Meter policy struct.
14581 flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
14582 struct mlx5_flow_meter_policy *mtr_policy)
14585 struct mlx5_flow_meter_sub_policy *sub_policy;
14586 uint16_t sub_policy_num;
14588 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
14589 sub_policy_num = (mtr_policy->sub_policy_num >>
14590 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
14591 MLX5_MTR_SUB_POLICY_NUM_MASK;
14592 for (j = 0; j < sub_policy_num; j++) {
14593 sub_policy = mtr_policy->sub_policys[i][j];
14595 __flow_dv_destroy_sub_policy_rules
14602 * Destroy policy action, lock free,
14603 * (mutex should be acquired by caller).
14604 * Dispatcher for action type specific call.
14607 * Pointer to the Ethernet device structure.
14608 * @param[in] mtr_policy
14609 * Meter policy struct.
14612 flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
14613 struct mlx5_flow_meter_policy *mtr_policy)
14615 struct rte_flow_action *rss_action;
14616 struct mlx5_flow_handle dev_handle;
14619 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
14620 if (mtr_policy->act_cnt[i].rix_mark) {
14621 flow_dv_tag_release(dev,
14622 mtr_policy->act_cnt[i].rix_mark);
14623 mtr_policy->act_cnt[i].rix_mark = 0;
14625 if (mtr_policy->act_cnt[i].modify_hdr) {
14626 dev_handle.dvh.modify_hdr =
14627 mtr_policy->act_cnt[i].modify_hdr;
14628 flow_dv_modify_hdr_resource_release(dev, &dev_handle);
14630 switch (mtr_policy->act_cnt[i].fate_action) {
14631 case MLX5_FLOW_FATE_SHARED_RSS:
14632 rss_action = mtr_policy->act_cnt[i].rss;
14633 mlx5_free(rss_action);
14635 case MLX5_FLOW_FATE_PORT_ID:
14636 if (mtr_policy->act_cnt[i].rix_port_id_action) {
14637 flow_dv_port_id_action_resource_release(dev,
14638 mtr_policy->act_cnt[i].rix_port_id_action);
14639 mtr_policy->act_cnt[i].rix_port_id_action = 0;
14642 case MLX5_FLOW_FATE_DROP:
14643 case MLX5_FLOW_FATE_JUMP:
14644 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
14645 mtr_policy->act_cnt[i].dr_jump_action[j] =
14649 /*Queue action do nothing*/
14653 for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
14654 mtr_policy->dr_drop_action[j] = NULL;
14658 * Create policy action per domain, lock free,
14659 * (mutex should be acquired by caller).
14660 * Dispatcher for action type specific call.
14663 * Pointer to the Ethernet device structure.
14664 * @param[in] mtr_policy
14665 * Meter policy struct.
14666 * @param[in] action
14667 * Action specification used to create meter actions.
14668 * @param[out] error
14669 * Perform verbose error reporting if not NULL. Initialized in case of
14673 * 0 on success, otherwise negative errno value.
14676 __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
14677 struct mlx5_flow_meter_policy *mtr_policy,
14678 const struct rte_flow_action *actions[RTE_COLORS],
14679 enum mlx5_meter_domain domain,
14680 struct rte_mtr_error *error)
14682 struct mlx5_priv *priv = dev->data->dev_private;
14683 struct rte_flow_error flow_err;
14684 const struct rte_flow_action *act;
14685 uint64_t action_flags = 0;
14686 struct mlx5_flow_handle dh;
14687 struct mlx5_flow dev_flow;
14688 struct mlx5_flow_dv_port_id_action_resource port_id_action;
14690 uint8_t egress, transfer;
14691 struct mlx5_meter_policy_action_container *act_cnt = NULL;
14693 struct mlx5_flow_dv_modify_hdr_resource res;
14694 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
14695 sizeof(struct mlx5_modification_cmd) *
14696 (MLX5_MAX_MODIFY_NUM + 1)];
14699 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
14700 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
14701 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
14702 memset(&dev_flow, 0, sizeof(struct mlx5_flow));
14703 memset(&port_id_action, 0,
14704 sizeof(struct mlx5_flow_dv_port_id_action_resource));
14705 dev_flow.handle = &dh;
14706 dev_flow.dv.port_id_action = &port_id_action;
14707 dev_flow.external = true;
14708 for (i = 0; i < RTE_COLORS; i++) {
14709 if (i < MLX5_MTR_RTE_COLORS)
14710 act_cnt = &mtr_policy->act_cnt[i];
14711 for (act = actions[i];
14712 act && act->type != RTE_FLOW_ACTION_TYPE_END;
14714 switch (act->type) {
14715 case RTE_FLOW_ACTION_TYPE_MARK:
14717 uint32_t tag_be = mlx5_flow_mark_set
14718 (((const struct rte_flow_action_mark *)
14721 if (i >= MLX5_MTR_RTE_COLORS)
14722 return -rte_mtr_error_set(error,
14724 RTE_MTR_ERROR_TYPE_METER_POLICY,
14726 "cannot create policy "
14727 "mark action for this color");
14728 dev_flow.handle->mark = 1;
14729 if (flow_dv_tag_resource_register(dev, tag_be,
14730 &dev_flow, &flow_err))
14731 return -rte_mtr_error_set(error,
14733 RTE_MTR_ERROR_TYPE_METER_POLICY,
14735 "cannot setup policy mark action");
14736 MLX5_ASSERT(dev_flow.dv.tag_resource);
14737 act_cnt->rix_mark =
14738 dev_flow.handle->dvh.rix_tag;
14739 action_flags |= MLX5_FLOW_ACTION_MARK;
14742 case RTE_FLOW_ACTION_TYPE_SET_TAG:
14744 struct mlx5_flow_dv_modify_hdr_resource
14745 *mhdr_res = &mhdr_dummy.res;
14747 if (i >= MLX5_MTR_RTE_COLORS)
14748 return -rte_mtr_error_set(error,
14750 RTE_MTR_ERROR_TYPE_METER_POLICY,
14752 "cannot create policy "
14753 "set tag action for this color");
14754 memset(mhdr_res, 0, sizeof(*mhdr_res));
14755 mhdr_res->ft_type = transfer ?
14756 MLX5DV_FLOW_TABLE_TYPE_FDB :
14758 MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
14759 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
14760 if (flow_dv_convert_action_set_tag
14762 (const struct rte_flow_action_set_tag *)
14763 act->conf, &flow_err))
14764 return -rte_mtr_error_set(error,
14766 RTE_MTR_ERROR_TYPE_METER_POLICY,
14767 NULL, "cannot convert policy "
14769 if (!mhdr_res->actions_num)
14770 return -rte_mtr_error_set(error,
14772 RTE_MTR_ERROR_TYPE_METER_POLICY,
14773 NULL, "cannot find policy "
14775 /* create modify action if needed. */
14776 dev_flow.dv.group = 1;
14777 if (flow_dv_modify_hdr_resource_register
14778 (dev, mhdr_res, &dev_flow, &flow_err))
14779 return -rte_mtr_error_set(error,
14781 RTE_MTR_ERROR_TYPE_METER_POLICY,
14782 NULL, "cannot register policy "
14784 act_cnt->modify_hdr =
14785 dev_flow.handle->dvh.modify_hdr;
14786 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
14789 case RTE_FLOW_ACTION_TYPE_DROP:
14791 struct mlx5_flow_mtr_mng *mtrmng =
14793 struct mlx5_flow_tbl_data_entry *tbl_data;
14796 * Create the drop table with
14797 * METER DROP level.
14799 if (!mtrmng->drop_tbl[domain]) {
14800 mtrmng->drop_tbl[domain] =
14801 flow_dv_tbl_resource_get(dev,
14802 MLX5_FLOW_TABLE_LEVEL_METER,
14803 egress, transfer, false, NULL, 0,
14804 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
14805 if (!mtrmng->drop_tbl[domain])
14806 return -rte_mtr_error_set
14808 RTE_MTR_ERROR_TYPE_METER_POLICY,
14810 "Failed to create meter drop table");
14812 tbl_data = container_of
14813 (mtrmng->drop_tbl[domain],
14814 struct mlx5_flow_tbl_data_entry, tbl);
14815 if (i < MLX5_MTR_RTE_COLORS) {
14816 act_cnt->dr_jump_action[domain] =
14817 tbl_data->jump.action;
14818 act_cnt->fate_action =
14819 MLX5_FLOW_FATE_DROP;
14821 if (i == RTE_COLOR_RED)
14822 mtr_policy->dr_drop_action[domain] =
14823 tbl_data->jump.action;
14824 action_flags |= MLX5_FLOW_ACTION_DROP;
14827 case RTE_FLOW_ACTION_TYPE_QUEUE:
14829 if (i >= MLX5_MTR_RTE_COLORS)
14830 return -rte_mtr_error_set(error,
14832 RTE_MTR_ERROR_TYPE_METER_POLICY,
14833 NULL, "cannot create policy "
14834 "fate queue for this color");
14836 ((const struct rte_flow_action_queue *)
14837 (act->conf))->index;
14838 act_cnt->fate_action =
14839 MLX5_FLOW_FATE_QUEUE;
14840 dev_flow.handle->fate_action =
14841 MLX5_FLOW_FATE_QUEUE;
14842 mtr_policy->is_queue = 1;
14843 action_flags |= MLX5_FLOW_ACTION_QUEUE;
14846 case RTE_FLOW_ACTION_TYPE_RSS:
14850 if (i >= MLX5_MTR_RTE_COLORS)
14851 return -rte_mtr_error_set(error,
14853 RTE_MTR_ERROR_TYPE_METER_POLICY,
14855 "cannot create policy "
14856 "rss action for this color");
14858 * Save RSS conf into policy struct
14859 * for translate stage.
14861 rss_size = (int)rte_flow_conv
14862 (RTE_FLOW_CONV_OP_ACTION,
14863 NULL, 0, act, &flow_err);
14865 return -rte_mtr_error_set(error,
14867 RTE_MTR_ERROR_TYPE_METER_POLICY,
14868 NULL, "Get the wrong "
14869 "rss action struct size");
14870 act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
14871 rss_size, 0, SOCKET_ID_ANY);
14873 return -rte_mtr_error_set(error,
14875 RTE_MTR_ERROR_TYPE_METER_POLICY,
14877 "Fail to malloc rss action memory");
14878 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
14879 act_cnt->rss, rss_size,
14882 return -rte_mtr_error_set(error,
14884 RTE_MTR_ERROR_TYPE_METER_POLICY,
14885 NULL, "Fail to save "
14886 "rss action into policy struct");
14887 act_cnt->fate_action =
14888 MLX5_FLOW_FATE_SHARED_RSS;
14889 action_flags |= MLX5_FLOW_ACTION_RSS;
14892 case RTE_FLOW_ACTION_TYPE_PORT_ID:
14894 struct mlx5_flow_dv_port_id_action_resource
14896 uint32_t port_id = 0;
14898 if (i >= MLX5_MTR_RTE_COLORS)
14899 return -rte_mtr_error_set(error,
14901 RTE_MTR_ERROR_TYPE_METER_POLICY,
14902 NULL, "cannot create policy "
14903 "port action for this color");
14904 memset(&port_id_resource, 0,
14905 sizeof(port_id_resource));
14906 if (flow_dv_translate_action_port_id(dev, act,
14907 &port_id, &flow_err))
14908 return -rte_mtr_error_set(error,
14910 RTE_MTR_ERROR_TYPE_METER_POLICY,
14911 NULL, "cannot translate "
14912 "policy port action");
14913 port_id_resource.port_id = port_id;
14914 if (flow_dv_port_id_action_resource_register
14915 (dev, &port_id_resource,
14916 &dev_flow, &flow_err))
14917 return -rte_mtr_error_set(error,
14919 RTE_MTR_ERROR_TYPE_METER_POLICY,
14920 NULL, "cannot setup "
14921 "policy port action");
14922 act_cnt->rix_port_id_action =
14923 dev_flow.handle->rix_port_id_action;
14924 act_cnt->fate_action =
14925 MLX5_FLOW_FATE_PORT_ID;
14926 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
14929 case RTE_FLOW_ACTION_TYPE_JUMP:
14931 uint32_t jump_group = 0;
14932 uint32_t table = 0;
14933 struct mlx5_flow_tbl_data_entry *tbl_data;
14934 struct flow_grp_info grp_info = {
14935 .external = !!dev_flow.external,
14936 .transfer = !!transfer,
14937 .fdb_def_rule = !!priv->fdb_def_rule,
14939 .skip_scale = dev_flow.skip_scale &
14940 (1 << MLX5_SCALE_FLOW_GROUP_BIT),
14942 struct mlx5_flow_meter_sub_policy *sub_policy =
14943 mtr_policy->sub_policys[domain][0];
14945 if (i >= MLX5_MTR_RTE_COLORS)
14946 return -rte_mtr_error_set(error,
14948 RTE_MTR_ERROR_TYPE_METER_POLICY,
14950 "cannot create policy "
14951 "jump action for this color");
14953 ((const struct rte_flow_action_jump *)
14955 if (mlx5_flow_group_to_table(dev, NULL,
14958 &grp_info, &flow_err))
14959 return -rte_mtr_error_set(error,
14961 RTE_MTR_ERROR_TYPE_METER_POLICY,
14962 NULL, "cannot setup "
14963 "policy jump action");
14964 sub_policy->jump_tbl[i] =
14965 flow_dv_tbl_resource_get(dev,
14968 !!dev_flow.external,
14969 NULL, jump_group, 0,
14972 (!sub_policy->jump_tbl[i])
14973 return -rte_mtr_error_set(error,
14975 RTE_MTR_ERROR_TYPE_METER_POLICY,
14976 NULL, "cannot create jump action.");
14977 tbl_data = container_of
14978 (sub_policy->jump_tbl[i],
14979 struct mlx5_flow_tbl_data_entry, tbl);
14980 act_cnt->dr_jump_action[domain] =
14981 tbl_data->jump.action;
14982 act_cnt->fate_action =
14983 MLX5_FLOW_FATE_JUMP;
14984 action_flags |= MLX5_FLOW_ACTION_JUMP;
14988 return -rte_mtr_error_set(error, ENOTSUP,
14989 RTE_MTR_ERROR_TYPE_METER_POLICY,
14990 NULL, "action type not supported");
14998 * Create policy action per domain, lock free,
14999 * (mutex should be acquired by caller).
15000 * Dispatcher for action type specific call.
15003 * Pointer to the Ethernet device structure.
15004 * @param[in] mtr_policy
15005 * Meter policy struct.
15006 * @param[in] action
15007 * Action specification used to create meter actions.
15008 * @param[out] error
15009 * Perform verbose error reporting if not NULL. Initialized in case of
15013 * 0 on success, otherwise negative errno value.
15016 flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
15017 struct mlx5_flow_meter_policy *mtr_policy,
15018 const struct rte_flow_action *actions[RTE_COLORS],
15019 struct rte_mtr_error *error)
15022 uint16_t sub_policy_num;
15024 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15025 sub_policy_num = (mtr_policy->sub_policy_num >>
15026 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15027 MLX5_MTR_SUB_POLICY_NUM_MASK;
15028 if (sub_policy_num) {
15029 ret = __flow_dv_create_domain_policy_acts(dev,
15030 mtr_policy, actions,
15031 (enum mlx5_meter_domain)i, error);
15040 * Query a DV flow rule for its statistics via DevX.
15043 * Pointer to Ethernet device.
15044 * @param[in] cnt_idx
15045 * Index to the flow counter.
15047 * Data retrieved by the query.
15048 * @param[out] error
15049 * Perform verbose error reporting if not NULL.
15052 * 0 on success, a negative errno value otherwise and rte_errno is set.
15055 flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
15056 struct rte_flow_error *error)
15058 struct mlx5_priv *priv = dev->data->dev_private;
15059 struct rte_flow_query_count *qc = data;
15061 if (!priv->config.devx)
15062 return rte_flow_error_set(error, ENOTSUP,
15063 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15065 "counters are not supported");
15067 uint64_t pkts, bytes;
15068 struct mlx5_flow_counter *cnt;
15069 int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
15072 return rte_flow_error_set(error, -err,
15073 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15074 NULL, "cannot read counters");
15075 cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
15078 qc->hits = pkts - cnt->hits;
15079 qc->bytes = bytes - cnt->bytes;
15082 cnt->bytes = bytes;
15086 return rte_flow_error_set(error, EINVAL,
15087 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15089 "counters are not available");
15093 flow_dv_action_query(struct rte_eth_dev *dev,
15094 const struct rte_flow_action_handle *handle, void *data,
15095 struct rte_flow_error *error)
15097 struct mlx5_age_param *age_param;
15098 struct rte_flow_query_age *resp;
15099 uint32_t act_idx = (uint32_t)(uintptr_t)handle;
15100 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
15101 uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
15102 struct mlx5_priv *priv = dev->data->dev_private;
15103 struct mlx5_aso_ct_action *ct;
15108 case MLX5_INDIRECT_ACTION_TYPE_AGE:
15109 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
15111 resp->aged = __atomic_load_n(&age_param->state,
15112 __ATOMIC_RELAXED) == AGE_TMOUT ?
15114 resp->sec_since_last_hit_valid = !resp->aged;
15115 if (resp->sec_since_last_hit_valid)
15116 resp->sec_since_last_hit = __atomic_load_n
15117 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15119 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
15120 return flow_dv_query_count(dev, idx, data, error);
15121 case MLX5_INDIRECT_ACTION_TYPE_CT:
15122 owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
15123 if (owner != PORT_ID(priv))
15124 return rte_flow_error_set(error, EACCES,
15125 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15127 "CT object owned by another port");
15128 dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
15129 ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
15132 return rte_flow_error_set(error, EFAULT,
15133 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15135 "CT object is inactive");
15136 ((struct rte_flow_action_conntrack *)data)->peer_port =
15138 ((struct rte_flow_action_conntrack *)data)->is_original_dir =
15140 if (mlx5_aso_ct_query_by_wqe(priv->sh, ct, data))
15141 return rte_flow_error_set(error, EIO,
15142 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15144 "Failed to query CT context");
15147 return rte_flow_error_set(error, ENOTSUP,
15148 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
15149 "action type query not supported");
15154 * Query a flow rule AGE action for aging information.
15157 * Pointer to Ethernet device.
15159 * Pointer to the sub flow.
15161 * data retrieved by the query.
15162 * @param[out] error
15163 * Perform verbose error reporting if not NULL.
15166 * 0 on success, a negative errno value otherwise and rte_errno is set.
15169 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
15170 void *data, struct rte_flow_error *error)
15172 struct rte_flow_query_age *resp = data;
15173 struct mlx5_age_param *age_param;
15176 struct mlx5_aso_age_action *act =
15177 flow_aso_age_get_by_idx(dev, flow->age);
15179 age_param = &act->age_params;
15180 } else if (flow->counter) {
15181 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
15183 if (!age_param || !age_param->timeout)
15184 return rte_flow_error_set
15186 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15187 NULL, "cannot read age data");
15189 return rte_flow_error_set(error, EINVAL,
15190 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15191 NULL, "age data not available");
15193 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
15195 resp->sec_since_last_hit_valid = !resp->aged;
15196 if (resp->sec_since_last_hit_valid)
15197 resp->sec_since_last_hit = __atomic_load_n
15198 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
15205 * @see rte_flow_query()
15206 * @see rte_flow_ops
15209 flow_dv_query(struct rte_eth_dev *dev,
15210 struct rte_flow *flow __rte_unused,
15211 const struct rte_flow_action *actions __rte_unused,
15212 void *data __rte_unused,
15213 struct rte_flow_error *error __rte_unused)
15217 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
15218 switch (actions->type) {
15219 case RTE_FLOW_ACTION_TYPE_VOID:
15221 case RTE_FLOW_ACTION_TYPE_COUNT:
15222 ret = flow_dv_query_count(dev, flow->counter, data,
15225 case RTE_FLOW_ACTION_TYPE_AGE:
15226 ret = flow_dv_query_age(dev, flow, data, error);
15229 return rte_flow_error_set(error, ENOTSUP,
15230 RTE_FLOW_ERROR_TYPE_ACTION,
15232 "action not supported");
15239 * Destroy the meter table set.
15240 * Lock free, (mutex should be acquired by caller).
15243 * Pointer to Ethernet device.
15245 * Meter information table.
15248 flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
15249 struct mlx5_flow_meter_info *fm)
15251 struct mlx5_priv *priv = dev->data->dev_private;
15254 if (!fm || !priv->config.dv_flow_en)
15256 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15257 if (fm->drop_rule[i]) {
15258 claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
15259 fm->drop_rule[i] = NULL;
15265 flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
15267 struct mlx5_priv *priv = dev->data->dev_private;
15268 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15269 struct mlx5_flow_tbl_data_entry *tbl;
15272 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15273 if (mtrmng->def_rule[i]) {
15274 claim_zero(mlx5_flow_os_destroy_flow
15275 (mtrmng->def_rule[i]));
15276 mtrmng->def_rule[i] = NULL;
15278 if (mtrmng->def_matcher[i]) {
15279 tbl = container_of(mtrmng->def_matcher[i]->tbl,
15280 struct mlx5_flow_tbl_data_entry, tbl);
15281 mlx5_cache_unregister(&tbl->matchers,
15282 &mtrmng->def_matcher[i]->entry);
15283 mtrmng->def_matcher[i] = NULL;
15285 for (j = 0; j < MLX5_REG_BITS; j++) {
15286 if (mtrmng->drop_matcher[i][j]) {
15288 container_of(mtrmng->drop_matcher[i][j]->tbl,
15289 struct mlx5_flow_tbl_data_entry,
15291 mlx5_cache_unregister(&tbl->matchers,
15292 &mtrmng->drop_matcher[i][j]->entry);
15293 mtrmng->drop_matcher[i][j] = NULL;
15296 if (mtrmng->drop_tbl[i]) {
15297 flow_dv_tbl_resource_release(MLX5_SH(dev),
15298 mtrmng->drop_tbl[i]);
15299 mtrmng->drop_tbl[i] = NULL;
15304 /* Number of meter flow actions, count and jump or count and drop. */
15305 #define METER_ACTIONS 2
15308 __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
15309 enum mlx5_meter_domain domain)
15311 struct mlx5_priv *priv = dev->data->dev_private;
15312 struct mlx5_flow_meter_def_policy *def_policy =
15313 priv->sh->mtrmng->def_policy[domain];
15315 __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
15316 mlx5_free(def_policy);
15317 priv->sh->mtrmng->def_policy[domain] = NULL;
15321 * Destroy the default policy table set.
15324 * Pointer to Ethernet device.
15327 flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
15329 struct mlx5_priv *priv = dev->data->dev_private;
15332 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
15333 if (priv->sh->mtrmng->def_policy[i])
15334 __flow_dv_destroy_domain_def_policy(dev,
15335 (enum mlx5_meter_domain)i);
15336 priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
15340 __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
15341 uint32_t color_reg_c_idx,
15342 enum rte_color color, void *matcher_object,
15343 int actions_n, void *actions,
15344 bool is_default_policy, void **rule,
15345 const struct rte_flow_attr *attr)
15348 struct mlx5_flow_dv_match_params value = {
15349 .size = sizeof(value.buf) -
15350 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15352 struct mlx5_flow_dv_match_params matcher = {
15353 .size = sizeof(matcher.buf) -
15354 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15356 struct mlx5_priv *priv = dev->data->dev_private;
15358 if (!is_default_policy && (priv->representor || priv->master)) {
15359 if (flow_dv_translate_item_port_id(dev, matcher.buf,
15360 value.buf, NULL, attr)) {
15362 "Failed to create meter policy flow with port.");
15366 flow_dv_match_meta_reg(matcher.buf, value.buf,
15367 (enum modify_reg)color_reg_c_idx,
15368 rte_col_2_mlx5_col(color),
15370 ret = mlx5_flow_os_create_flow(matcher_object,
15371 (void *)&value, actions_n, actions, rule);
15373 DRV_LOG(ERR, "Failed to create meter policy flow.");
15380 __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
15381 uint32_t color_reg_c_idx,
15383 struct mlx5_flow_meter_sub_policy *sub_policy,
15384 const struct rte_flow_attr *attr,
15385 bool is_default_policy,
15386 struct rte_flow_error *error)
15388 struct mlx5_cache_entry *entry;
15389 struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
15390 struct mlx5_flow_dv_matcher matcher = {
15392 .size = sizeof(matcher.mask.buf) -
15393 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15397 struct mlx5_flow_dv_match_params value = {
15398 .size = sizeof(value.buf) -
15399 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15401 struct mlx5_flow_cb_ctx ctx = {
15405 struct mlx5_flow_tbl_data_entry *tbl_data;
15406 struct mlx5_priv *priv = dev->data->dev_private;
15407 uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
15409 if (!is_default_policy && (priv->representor || priv->master)) {
15410 if (flow_dv_translate_item_port_id(dev, matcher.mask.buf,
15411 value.buf, NULL, attr)) {
15413 "Failed to register meter drop matcher with port.");
15417 tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
15418 if (priority < RTE_COLOR_RED)
15419 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
15420 (enum modify_reg)color_reg_c_idx, 0, color_mask);
15421 matcher.priority = priority;
15422 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15423 matcher.mask.size);
15424 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
15426 DRV_LOG(ERR, "Failed to register meter drop matcher.");
15429 sub_policy->color_matcher[priority] =
15430 container_of(entry, struct mlx5_flow_dv_matcher, entry);
15435 * Create the policy rules per domain.
15438 * Pointer to Ethernet device.
15439 * @param[in] sub_policy
15440 * Pointer to sub policy table..
15441 * @param[in] egress
15442 * Direction of the table.
15443 * @param[in] transfer
15444 * E-Switch or NIC flow.
15446 * Pointer to policy action list per color.
15449 * 0 on success, -1 otherwise.
15452 __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
15453 struct mlx5_flow_meter_sub_policy *sub_policy,
15454 uint8_t egress, uint8_t transfer, bool is_default_policy,
15455 struct mlx5_meter_policy_acts acts[RTE_COLORS])
15457 struct rte_flow_error flow_err;
15458 uint32_t color_reg_c_idx;
15459 struct rte_flow_attr attr = {
15460 .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
15463 .egress = !!egress,
15464 .transfer = !!transfer,
15468 int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
15472 /* Create policy table with POLICY level. */
15473 if (!sub_policy->tbl_rsc)
15474 sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
15475 MLX5_FLOW_TABLE_LEVEL_POLICY,
15476 egress, transfer, false, NULL, 0, 0,
15477 sub_policy->idx, &flow_err);
15478 if (!sub_policy->tbl_rsc) {
15480 "Failed to create meter sub policy table.");
15483 /* Prepare matchers. */
15484 color_reg_c_idx = ret;
15485 for (i = 0; i < RTE_COLORS; i++) {
15486 if (i == RTE_COLOR_YELLOW || !acts[i].actions_n)
15489 if (!sub_policy->color_matcher[i]) {
15490 /* Create matchers for Color. */
15491 if (__flow_dv_create_policy_matcher(dev,
15492 color_reg_c_idx, i, sub_policy,
15493 &attr, is_default_policy, &flow_err))
15496 /* Create flow, matching color. */
15497 if (acts[i].actions_n)
15498 if (__flow_dv_create_policy_flow(dev,
15499 color_reg_c_idx, (enum rte_color)i,
15500 sub_policy->color_matcher[i]->matcher_object,
15502 acts[i].dv_actions,
15504 &sub_policy->color_rule[i],
15512 __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
15513 struct mlx5_flow_meter_policy *mtr_policy,
15514 struct mlx5_flow_meter_sub_policy *sub_policy,
15517 struct mlx5_priv *priv = dev->data->dev_private;
15518 struct mlx5_meter_policy_acts acts[RTE_COLORS];
15519 struct mlx5_flow_dv_tag_resource *tag;
15520 struct mlx5_flow_dv_port_id_action_resource *port_action;
15521 struct mlx5_hrxq *hrxq;
15522 uint8_t egress, transfer;
15525 for (i = 0; i < RTE_COLORS; i++) {
15526 acts[i].actions_n = 0;
15527 if (i == RTE_COLOR_YELLOW)
15529 if (i == RTE_COLOR_RED) {
15530 /* Only support drop on red. */
15531 acts[i].dv_actions[0] =
15532 mtr_policy->dr_drop_action[domain];
15533 acts[i].actions_n = 1;
15536 if (mtr_policy->act_cnt[i].rix_mark) {
15537 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
15538 mtr_policy->act_cnt[i].rix_mark);
15540 DRV_LOG(ERR, "Failed to find "
15541 "mark action for policy.");
15544 acts[i].dv_actions[acts[i].actions_n] =
15546 acts[i].actions_n++;
15548 if (mtr_policy->act_cnt[i].modify_hdr) {
15549 acts[i].dv_actions[acts[i].actions_n] =
15550 mtr_policy->act_cnt[i].modify_hdr->action;
15551 acts[i].actions_n++;
15553 if (mtr_policy->act_cnt[i].fate_action) {
15554 switch (mtr_policy->act_cnt[i].fate_action) {
15555 case MLX5_FLOW_FATE_PORT_ID:
15556 port_action = mlx5_ipool_get
15557 (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
15558 mtr_policy->act_cnt[i].rix_port_id_action);
15559 if (!port_action) {
15560 DRV_LOG(ERR, "Failed to find "
15561 "port action for policy.");
15564 acts[i].dv_actions[acts[i].actions_n] =
15565 port_action->action;
15566 acts[i].actions_n++;
15568 case MLX5_FLOW_FATE_DROP:
15569 case MLX5_FLOW_FATE_JUMP:
15570 acts[i].dv_actions[acts[i].actions_n] =
15571 mtr_policy->act_cnt[i].dr_jump_action[domain];
15572 acts[i].actions_n++;
15574 case MLX5_FLOW_FATE_SHARED_RSS:
15575 case MLX5_FLOW_FATE_QUEUE:
15576 hrxq = mlx5_ipool_get
15577 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
15578 sub_policy->rix_hrxq[i]);
15580 DRV_LOG(ERR, "Failed to find "
15581 "queue action for policy.");
15584 acts[i].dv_actions[acts[i].actions_n] =
15586 acts[i].actions_n++;
15589 /*Queue action do nothing*/
15594 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15595 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15596 if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
15597 egress, transfer, false, acts)) {
15599 "Failed to create policy rules per domain.");
15606 * Create the policy rules.
15609 * Pointer to Ethernet device.
15610 * @param[in,out] mtr_policy
15611 * Pointer to meter policy table.
15614 * 0 on success, -1 otherwise.
15617 flow_dv_create_policy_rules(struct rte_eth_dev *dev,
15618 struct mlx5_flow_meter_policy *mtr_policy)
15621 uint16_t sub_policy_num;
15623 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15624 sub_policy_num = (mtr_policy->sub_policy_num >>
15625 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
15626 MLX5_MTR_SUB_POLICY_NUM_MASK;
15627 if (!sub_policy_num)
15629 /* Prepare actions list and create policy rules. */
15630 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
15631 mtr_policy->sub_policys[i][0], i)) {
15633 "Failed to create policy action list per domain.");
15641 __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
15643 struct mlx5_priv *priv = dev->data->dev_private;
15644 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15645 struct mlx5_flow_meter_def_policy *def_policy;
15646 struct mlx5_flow_tbl_resource *jump_tbl;
15647 struct mlx5_flow_tbl_data_entry *tbl_data;
15648 uint8_t egress, transfer;
15649 struct rte_flow_error error;
15650 struct mlx5_meter_policy_acts acts[RTE_COLORS];
15653 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15654 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15655 def_policy = mtrmng->def_policy[domain];
15657 def_policy = mlx5_malloc(MLX5_MEM_ZERO,
15658 sizeof(struct mlx5_flow_meter_def_policy),
15659 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
15661 DRV_LOG(ERR, "Failed to alloc "
15662 "default policy table.");
15663 goto def_policy_error;
15665 mtrmng->def_policy[domain] = def_policy;
15666 /* Create the meter suffix table with SUFFIX level. */
15667 jump_tbl = flow_dv_tbl_resource_get(dev,
15668 MLX5_FLOW_TABLE_LEVEL_METER,
15669 egress, transfer, false, NULL, 0,
15670 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
15673 "Failed to create meter suffix table.");
15674 goto def_policy_error;
15676 def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
15677 tbl_data = container_of(jump_tbl,
15678 struct mlx5_flow_tbl_data_entry, tbl);
15679 def_policy->dr_jump_action[RTE_COLOR_GREEN] =
15680 tbl_data->jump.action;
15681 acts[RTE_COLOR_GREEN].dv_actions[0] =
15682 tbl_data->jump.action;
15683 acts[RTE_COLOR_GREEN].actions_n = 1;
15684 /* Create jump action to the drop table. */
15685 if (!mtrmng->drop_tbl[domain]) {
15686 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
15687 (dev, MLX5_FLOW_TABLE_LEVEL_METER,
15688 egress, transfer, false, NULL, 0,
15689 0, MLX5_MTR_TABLE_ID_DROP, &error);
15690 if (!mtrmng->drop_tbl[domain]) {
15691 DRV_LOG(ERR, "Failed to create "
15692 "meter drop table for default policy.");
15693 goto def_policy_error;
15696 tbl_data = container_of(mtrmng->drop_tbl[domain],
15697 struct mlx5_flow_tbl_data_entry, tbl);
15698 def_policy->dr_jump_action[RTE_COLOR_RED] =
15699 tbl_data->jump.action;
15700 acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
15701 acts[RTE_COLOR_RED].actions_n = 1;
15702 /* Create default policy rules. */
15703 ret = __flow_dv_create_domain_policy_rules(dev,
15704 &def_policy->sub_policy,
15705 egress, transfer, true, acts);
15707 DRV_LOG(ERR, "Failed to create "
15708 "default policy rules.");
15709 goto def_policy_error;
15714 __flow_dv_destroy_domain_def_policy(dev,
15715 (enum mlx5_meter_domain)domain);
15720 * Create the default policy table set.
15723 * Pointer to Ethernet device.
15725 * 0 on success, -1 otherwise.
15728 flow_dv_create_def_policy(struct rte_eth_dev *dev)
15730 struct mlx5_priv *priv = dev->data->dev_private;
15733 /* Non-termination policy table. */
15734 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15735 if (!priv->config.dv_esw_en && i == MLX5_MTR_DOMAIN_TRANSFER)
15737 if (__flow_dv_create_domain_def_policy(dev, i)) {
15739 "Failed to create default policy");
15747 * Create the needed meter tables.
15748 * Lock free, (mutex should be acquired by caller).
15751 * Pointer to Ethernet device.
15753 * Meter information table.
15754 * @param[in] mtr_idx
15756 * @param[in] domain_bitmap
15759 * 0 on success, -1 otherwise.
15762 flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
15763 struct mlx5_flow_meter_info *fm,
15765 uint8_t domain_bitmap)
15767 struct mlx5_priv *priv = dev->data->dev_private;
15768 struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
15769 struct rte_flow_error error;
15770 struct mlx5_flow_tbl_data_entry *tbl_data;
15771 uint8_t egress, transfer;
15772 void *actions[METER_ACTIONS];
15773 int domain, ret, i;
15774 struct mlx5_flow_counter *cnt;
15775 struct mlx5_flow_dv_match_params value = {
15776 .size = sizeof(value.buf) -
15777 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15779 struct mlx5_flow_dv_match_params matcher_para = {
15780 .size = sizeof(matcher_para.buf) -
15781 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15783 int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
15785 uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
15786 uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
15787 struct mlx5_cache_entry *entry;
15788 struct mlx5_flow_dv_matcher matcher = {
15790 .size = sizeof(matcher.mask.buf) -
15791 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
15794 struct mlx5_flow_dv_matcher *drop_matcher;
15795 struct mlx5_flow_cb_ctx ctx = {
15800 if (!priv->mtr_en || mtr_id_reg_c < 0) {
15801 rte_errno = ENOTSUP;
15804 for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
15805 if (!(domain_bitmap & (1 << domain)) ||
15806 (mtrmng->def_rule[domain] && !fm->drop_cnt))
15808 egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
15809 transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
15810 /* Create the drop table with METER DROP level. */
15811 if (!mtrmng->drop_tbl[domain]) {
15812 mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
15813 MLX5_FLOW_TABLE_LEVEL_METER,
15814 egress, transfer, false, NULL, 0,
15815 0, MLX5_MTR_TABLE_ID_DROP, &error);
15816 if (!mtrmng->drop_tbl[domain]) {
15817 DRV_LOG(ERR, "Failed to create meter drop table.");
15821 /* Create default matcher in drop table. */
15822 matcher.tbl = mtrmng->drop_tbl[domain],
15823 tbl_data = container_of(mtrmng->drop_tbl[domain],
15824 struct mlx5_flow_tbl_data_entry, tbl);
15825 if (!mtrmng->def_matcher[domain]) {
15826 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
15827 (enum modify_reg)mtr_id_reg_c,
15829 matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
15830 matcher.crc = rte_raw_cksum
15831 ((const void *)matcher.mask.buf,
15832 matcher.mask.size);
15833 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
15835 DRV_LOG(ERR, "Failed to register meter "
15836 "drop default matcher.");
15839 mtrmng->def_matcher[domain] = container_of(entry,
15840 struct mlx5_flow_dv_matcher, entry);
15842 /* Create default rule in drop table. */
15843 if (!mtrmng->def_rule[domain]) {
15845 actions[i++] = priv->sh->dr_drop_action;
15846 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
15847 (enum modify_reg)mtr_id_reg_c, 0, 0);
15848 ret = mlx5_flow_os_create_flow
15849 (mtrmng->def_matcher[domain]->matcher_object,
15850 (void *)&value, i, actions,
15851 &mtrmng->def_rule[domain]);
15853 DRV_LOG(ERR, "Failed to create meter "
15854 "default drop rule for drop table.");
15860 MLX5_ASSERT(mtrmng->max_mtr_bits);
15861 if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
15862 /* Create matchers for Drop. */
15863 flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
15864 (enum modify_reg)mtr_id_reg_c, 0,
15865 (mtr_id_mask << mtr_id_offset));
15866 matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
15867 matcher.crc = rte_raw_cksum
15868 ((const void *)matcher.mask.buf,
15869 matcher.mask.size);
15870 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
15873 "Failed to register meter drop matcher.");
15876 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
15877 container_of(entry, struct mlx5_flow_dv_matcher,
15881 mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
15882 /* Create drop rule, matching meter_id only. */
15883 flow_dv_match_meta_reg(matcher_para.buf, value.buf,
15884 (enum modify_reg)mtr_id_reg_c,
15885 (mtr_idx << mtr_id_offset), UINT32_MAX);
15887 cnt = flow_dv_counter_get_by_idx(dev,
15888 fm->drop_cnt, NULL);
15889 actions[i++] = cnt->action;
15890 actions[i++] = priv->sh->dr_drop_action;
15891 ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
15892 (void *)&value, i, actions,
15893 &fm->drop_rule[domain]);
15895 DRV_LOG(ERR, "Failed to create meter "
15896 "drop rule for drop table.");
15902 for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
15903 if (fm->drop_rule[i]) {
15904 claim_zero(mlx5_flow_os_destroy_flow
15905 (fm->drop_rule[i]));
15906 fm->drop_rule[i] = NULL;
15913 * Find the policy table for prefix table with RSS.
15916 * Pointer to Ethernet device.
15917 * @param[in] mtr_policy
15918 * Pointer to meter policy table.
15919 * @param[in] rss_desc
15920 * Pointer to rss_desc
15922 * Pointer to table set on success, NULL otherwise and rte_errno is set.
15924 static struct mlx5_flow_meter_sub_policy *
15925 flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
15926 struct mlx5_flow_meter_policy *mtr_policy,
15927 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
15929 struct mlx5_priv *priv = dev->data->dev_private;
15930 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
15931 uint32_t sub_policy_idx = 0;
15932 uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
15934 struct mlx5_hrxq *hrxq;
15935 struct mlx5_flow_handle dh;
15936 struct mlx5_meter_policy_action_container *act_cnt;
15937 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
15938 uint16_t sub_policy_num;
15940 rte_spinlock_lock(&mtr_policy->sl);
15941 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15944 hrxq_idx[i] = mlx5_hrxq_get(dev, rss_desc[i]);
15945 if (!hrxq_idx[i]) {
15946 rte_spinlock_unlock(&mtr_policy->sl);
15950 sub_policy_num = (mtr_policy->sub_policy_num >>
15951 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
15952 MLX5_MTR_SUB_POLICY_NUM_MASK;
15953 for (i = 0; i < sub_policy_num;
15955 for (j = 0; j < MLX5_MTR_RTE_COLORS; j++) {
15958 mtr_policy->sub_policys[domain][i]->rix_hrxq[j])
15961 if (j >= MLX5_MTR_RTE_COLORS) {
15963 * Found the sub policy table with
15964 * the same queue per color
15966 rte_spinlock_unlock(&mtr_policy->sl);
15967 for (j = 0; j < MLX5_MTR_RTE_COLORS; j++)
15968 mlx5_hrxq_release(dev, hrxq_idx[j]);
15969 return mtr_policy->sub_policys[domain][i];
15972 /* Create sub policy. */
15973 if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[0]) {
15974 /* Reuse the first dummy sub_policy*/
15975 sub_policy = mtr_policy->sub_policys[domain][0];
15976 sub_policy_idx = sub_policy->idx;
15978 sub_policy = mlx5_ipool_zmalloc
15979 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
15982 sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
15983 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
15984 mlx5_hrxq_release(dev, hrxq_idx[i]);
15985 goto rss_sub_policy_error;
15987 sub_policy->idx = sub_policy_idx;
15988 sub_policy->main_policy = mtr_policy;
15990 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
15993 sub_policy->rix_hrxq[i] = hrxq_idx[i];
15995 * Overwrite the last action from
15996 * RSS action to Queue action.
15998 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
16001 DRV_LOG(ERR, "Failed to create policy hrxq");
16002 goto rss_sub_policy_error;
16004 act_cnt = &mtr_policy->act_cnt[i];
16005 if (act_cnt->rix_mark || act_cnt->modify_hdr) {
16006 memset(&dh, 0, sizeof(struct mlx5_flow_handle));
16007 if (act_cnt->rix_mark)
16009 dh.fate_action = MLX5_FLOW_FATE_QUEUE;
16010 dh.rix_hrxq = hrxq_idx[i];
16011 flow_drv_rxq_flags_set(dev, &dh);
16014 if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
16015 sub_policy, domain)) {
16016 DRV_LOG(ERR, "Failed to create policy "
16017 "rules per domain.");
16018 goto rss_sub_policy_error;
16020 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16021 i = (mtr_policy->sub_policy_num >>
16022 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16023 MLX5_MTR_SUB_POLICY_NUM_MASK;
16024 mtr_policy->sub_policys[domain][i] = sub_policy;
16026 if (i > MLX5_MTR_RSS_MAX_SUB_POLICY)
16027 goto rss_sub_policy_error;
16028 mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16029 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
16030 mtr_policy->sub_policy_num |=
16031 (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16032 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
16034 rte_spinlock_unlock(&mtr_policy->sl);
16036 rss_sub_policy_error:
16038 __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
16039 if (sub_policy != mtr_policy->sub_policys[domain][0]) {
16040 i = (mtr_policy->sub_policy_num >>
16041 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16042 MLX5_MTR_SUB_POLICY_NUM_MASK;
16043 mtr_policy->sub_policys[domain][i] = NULL;
16045 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16049 if (sub_policy_idx)
16050 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16052 rte_spinlock_unlock(&mtr_policy->sl);
16058 * Destroy the sub policy table with RX queue.
16061 * Pointer to Ethernet device.
16062 * @param[in] mtr_policy
16063 * Pointer to meter policy table.
16066 flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
16067 struct mlx5_flow_meter_policy *mtr_policy)
16069 struct mlx5_priv *priv = dev->data->dev_private;
16070 struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
16071 uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
16073 uint16_t sub_policy_num, new_policy_num;
16075 rte_spinlock_lock(&mtr_policy->sl);
16076 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
16077 switch (mtr_policy->act_cnt[i].fate_action) {
16078 case MLX5_FLOW_FATE_SHARED_RSS:
16079 sub_policy_num = (mtr_policy->sub_policy_num >>
16080 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
16081 MLX5_MTR_SUB_POLICY_NUM_MASK;
16082 new_policy_num = sub_policy_num;
16083 for (j = 0; j < sub_policy_num; j++) {
16085 mtr_policy->sub_policys[domain][j];
16087 __flow_dv_destroy_sub_policy_rules(dev,
16090 mtr_policy->sub_policys[domain][0]) {
16091 mtr_policy->sub_policys[domain][j] =
16094 (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
16100 if (new_policy_num != sub_policy_num) {
16101 mtr_policy->sub_policy_num &=
16102 ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
16103 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
16104 mtr_policy->sub_policy_num |=
16106 MLX5_MTR_SUB_POLICY_NUM_MASK) <<
16107 (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
16110 case MLX5_FLOW_FATE_QUEUE:
16111 sub_policy = mtr_policy->sub_policys[domain][0];
16112 __flow_dv_destroy_sub_policy_rules(dev,
16116 /*Other actions without queue and do nothing*/
16120 rte_spinlock_unlock(&mtr_policy->sl);
16124 * Validate the batch counter support in root table.
16126 * Create a simple flow with invalid counter and drop action on root table to
16127 * validate if batch counter with offset on root table is supported or not.
16130 * Pointer to rte_eth_dev structure.
16133 * 0 on success, a negative errno value otherwise and rte_errno is set.
16136 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
16138 struct mlx5_priv *priv = dev->data->dev_private;
16139 struct mlx5_dev_ctx_shared *sh = priv->sh;
16140 struct mlx5_flow_dv_match_params mask = {
16141 .size = sizeof(mask.buf),
16143 struct mlx5_flow_dv_match_params value = {
16144 .size = sizeof(value.buf),
16146 struct mlx5dv_flow_matcher_attr dv_attr = {
16147 .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
16149 .match_criteria_enable = 0,
16150 .match_mask = (void *)&mask,
16152 void *actions[2] = { 0 };
16153 struct mlx5_flow_tbl_resource *tbl = NULL;
16154 struct mlx5_devx_obj *dcs = NULL;
16155 void *matcher = NULL;
16159 tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
16163 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
16166 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
16170 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
16171 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
16175 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
16179 * If batch counter with offset is not supported, the driver will not
16180 * validate the invalid offset value, flow create should success.
16181 * In this case, it means batch counter is not supported in root table.
16183 * Otherwise, if flow create is failed, counter offset is supported.
16186 DRV_LOG(INFO, "Batch counter is not supported in root "
16187 "table. Switch to fallback mode.");
16188 rte_errno = ENOTSUP;
16190 claim_zero(mlx5_flow_os_destroy_flow(flow));
16192 /* Check matcher to make sure validate fail at flow create. */
16193 if (!matcher || (matcher && errno != EINVAL))
16194 DRV_LOG(ERR, "Unexpected error in counter offset "
16195 "support detection");
16199 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
16201 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
16203 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
16205 claim_zero(mlx5_devx_cmd_destroy(dcs));
16210 * Query a devx counter.
16213 * Pointer to the Ethernet device structure.
16215 * Index to the flow counter.
16217 * Set to clear the counter statistics.
16219 * The statistics value of packets.
16220 * @param[out] bytes
16221 * The statistics value of bytes.
16224 * 0 on success, otherwise return -1.
16227 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
16228 uint64_t *pkts, uint64_t *bytes)
16230 struct mlx5_priv *priv = dev->data->dev_private;
16231 struct mlx5_flow_counter *cnt;
16232 uint64_t inn_pkts, inn_bytes;
16235 if (!priv->config.devx)
16238 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
16241 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
16242 *pkts = inn_pkts - cnt->hits;
16243 *bytes = inn_bytes - cnt->bytes;
16245 cnt->hits = inn_pkts;
16246 cnt->bytes = inn_bytes;
16252 * Get aged-out flows.
16255 * Pointer to the Ethernet device structure.
16256 * @param[in] context
16257 * The address of an array of pointers to the aged-out flows contexts.
16258 * @param[in] nb_contexts
16259 * The length of context array pointers.
16260 * @param[out] error
16261 * Perform verbose error reporting if not NULL. Initialized in case of
16265 * how many contexts get in success, otherwise negative errno value.
16266 * if nb_contexts is 0, return the amount of all aged contexts.
16267 * if nb_contexts is not 0 , return the amount of aged flows reported
16268 * in the context array.
16269 * @note: only stub for now
16272 flow_get_aged_flows(struct rte_eth_dev *dev,
16274 uint32_t nb_contexts,
16275 struct rte_flow_error *error)
16277 struct mlx5_priv *priv = dev->data->dev_private;
16278 struct mlx5_age_info *age_info;
16279 struct mlx5_age_param *age_param;
16280 struct mlx5_flow_counter *counter;
16281 struct mlx5_aso_age_action *act;
16284 if (nb_contexts && !context)
16285 return rte_flow_error_set(error, EINVAL,
16286 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16287 NULL, "empty context");
16288 age_info = GET_PORT_AGE_INFO(priv);
16289 rte_spinlock_lock(&age_info->aged_sl);
16290 LIST_FOREACH(act, &age_info->aged_aso, next) {
16293 context[nb_flows - 1] =
16294 act->age_params.context;
16295 if (!(--nb_contexts))
16299 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
16302 age_param = MLX5_CNT_TO_AGE(counter);
16303 context[nb_flows - 1] = age_param->context;
16304 if (!(--nb_contexts))
16308 rte_spinlock_unlock(&age_info->aged_sl);
16309 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
16314 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
16317 flow_dv_counter_allocate(struct rte_eth_dev *dev)
16319 return flow_dv_counter_alloc(dev, 0);
16323 * Validate indirect action.
16324 * Dispatcher for action type specific validation.
16327 * Pointer to the Ethernet device structure.
16329 * Indirect action configuration.
16330 * @param[in] action
16331 * The indirect action object to validate.
16332 * @param[out] error
16333 * Perform verbose error reporting if not NULL. Initialized in case of
16337 * 0 on success, otherwise negative errno value.
16340 flow_dv_action_validate(struct rte_eth_dev *dev,
16341 const struct rte_flow_indir_action_conf *conf,
16342 const struct rte_flow_action *action,
16343 struct rte_flow_error *err)
16345 struct mlx5_priv *priv = dev->data->dev_private;
16347 RTE_SET_USED(conf);
16348 switch (action->type) {
16349 case RTE_FLOW_ACTION_TYPE_RSS:
16351 * priv->obj_ops is set according to driver capabilities.
16352 * When DevX capabilities are
16353 * sufficient, it is set to devx_obj_ops.
16354 * Otherwise, it is set to ibv_obj_ops.
16355 * ibv_obj_ops doesn't support ind_table_modify operation.
16356 * In this case the indirect RSS action can't be used.
16358 if (priv->obj_ops.ind_table_modify == NULL)
16359 return rte_flow_error_set
16361 RTE_FLOW_ERROR_TYPE_ACTION,
16363 "Indirect RSS action not supported");
16364 return mlx5_validate_action_rss(dev, action, err);
16365 case RTE_FLOW_ACTION_TYPE_AGE:
16366 if (!priv->sh->aso_age_mng)
16367 return rte_flow_error_set(err, ENOTSUP,
16368 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16370 "Indirect age action not supported");
16371 return flow_dv_validate_action_age(0, action, dev, err);
16372 case RTE_FLOW_ACTION_TYPE_COUNT:
16374 * There are two mechanisms to share the action count.
16375 * The old mechanism uses the shared field to share, while the
16376 * new mechanism uses the indirect action API.
16377 * This validation comes to make sure that the two mechanisms
16378 * are not combined.
16380 if (is_shared_action_count(action))
16381 return rte_flow_error_set(err, ENOTSUP,
16382 RTE_FLOW_ERROR_TYPE_ACTION,
16384 "Mix shared and indirect counter is not supported");
16385 return flow_dv_validate_action_count(dev, true, 0, err);
16386 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
16387 if (!priv->sh->ct_aso_en)
16388 return rte_flow_error_set(err, ENOTSUP,
16389 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16390 "ASO CT is not supported");
16391 return mlx5_validate_action_ct(dev, action->conf, err);
16393 return rte_flow_error_set(err, ENOTSUP,
16394 RTE_FLOW_ERROR_TYPE_ACTION,
16396 "action type not supported");
16401 * Validate meter policy actions.
16402 * Dispatcher for action type specific validation.
16405 * Pointer to the Ethernet device structure.
16406 * @param[in] action
16407 * The meter policy action object to validate.
16409 * Attributes of flow to determine steering domain.
16410 * @param[out] error
16411 * Perform verbose error reporting if not NULL. Initialized in case of
16415 * 0 on success, otherwise negative errno value.
16418 flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
16419 const struct rte_flow_action *actions[RTE_COLORS],
16420 struct rte_flow_attr *attr,
16422 uint8_t *domain_bitmap,
16423 bool *is_def_policy,
16424 struct rte_mtr_error *error)
16426 struct mlx5_priv *priv = dev->data->dev_private;
16427 struct mlx5_dev_config *dev_conf = &priv->config;
16428 const struct rte_flow_action *act;
16429 uint64_t action_flags = 0;
16432 struct rte_flow_error flow_err;
16433 uint8_t domain_color[RTE_COLORS] = {0};
16434 uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
16436 if (!priv->config.dv_esw_en)
16437 def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
16438 *domain_bitmap = def_domain;
16439 if (actions[RTE_COLOR_YELLOW] &&
16440 actions[RTE_COLOR_YELLOW]->type != RTE_FLOW_ACTION_TYPE_END)
16441 return -rte_mtr_error_set(error, ENOTSUP,
16442 RTE_MTR_ERROR_TYPE_METER_POLICY,
16444 "Yellow color does not support any action.");
16445 if (actions[RTE_COLOR_YELLOW] &&
16446 actions[RTE_COLOR_YELLOW]->type != RTE_FLOW_ACTION_TYPE_DROP)
16447 return -rte_mtr_error_set(error, ENOTSUP,
16448 RTE_MTR_ERROR_TYPE_METER_POLICY,
16449 NULL, "Red color only supports drop action.");
16451 * Check default policy actions:
16452 * Green/Yellow: no action, Red: drop action
16454 if ((!actions[RTE_COLOR_GREEN] ||
16455 actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)) {
16456 *is_def_policy = true;
16459 flow_err.message = NULL;
16460 for (i = 0; i < RTE_COLORS; i++) {
16462 for (action_flags = 0, actions_n = 0;
16463 act && act->type != RTE_FLOW_ACTION_TYPE_END;
16465 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
16466 return -rte_mtr_error_set(error, ENOTSUP,
16467 RTE_MTR_ERROR_TYPE_METER_POLICY,
16468 NULL, "too many actions");
16469 switch (act->type) {
16470 case RTE_FLOW_ACTION_TYPE_PORT_ID:
16471 if (!priv->config.dv_esw_en)
16472 return -rte_mtr_error_set(error,
16474 RTE_MTR_ERROR_TYPE_METER_POLICY,
16475 NULL, "PORT action validate check"
16476 " fail for ESW disable");
16477 ret = flow_dv_validate_action_port_id(dev,
16479 act, attr, &flow_err);
16481 return -rte_mtr_error_set(error,
16483 RTE_MTR_ERROR_TYPE_METER_POLICY,
16484 NULL, flow_err.message ?
16486 "PORT action validate check fail");
16488 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
16490 case RTE_FLOW_ACTION_TYPE_MARK:
16491 ret = flow_dv_validate_action_mark(dev, act,
16495 return -rte_mtr_error_set(error,
16497 RTE_MTR_ERROR_TYPE_METER_POLICY,
16498 NULL, flow_err.message ?
16500 "Mark action validate check fail");
16501 if (dev_conf->dv_xmeta_en !=
16502 MLX5_XMETA_MODE_LEGACY)
16503 return -rte_mtr_error_set(error,
16505 RTE_MTR_ERROR_TYPE_METER_POLICY,
16506 NULL, "Extend MARK action is "
16507 "not supported. Please try use "
16508 "default policy for meter.");
16509 action_flags |= MLX5_FLOW_ACTION_MARK;
16512 case RTE_FLOW_ACTION_TYPE_SET_TAG:
16513 ret = flow_dv_validate_action_set_tag(dev,
16517 return -rte_mtr_error_set(error,
16519 RTE_MTR_ERROR_TYPE_METER_POLICY,
16520 NULL, flow_err.message ?
16522 "Set tag action validate check fail");
16524 * Count all modify-header actions
16527 if (!(action_flags &
16528 MLX5_FLOW_MODIFY_HDR_ACTIONS))
16530 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
16532 case RTE_FLOW_ACTION_TYPE_DROP:
16533 ret = mlx5_flow_validate_action_drop
16537 return -rte_mtr_error_set(error,
16539 RTE_MTR_ERROR_TYPE_METER_POLICY,
16540 NULL, flow_err.message ?
16542 "Drop action validate check fail");
16543 action_flags |= MLX5_FLOW_ACTION_DROP;
16546 case RTE_FLOW_ACTION_TYPE_QUEUE:
16548 * Check whether extensive
16549 * metadata feature is engaged.
16551 if (dev_conf->dv_flow_en &&
16552 (dev_conf->dv_xmeta_en !=
16553 MLX5_XMETA_MODE_LEGACY) &&
16554 mlx5_flow_ext_mreg_supported(dev))
16555 return -rte_mtr_error_set(error,
16557 RTE_MTR_ERROR_TYPE_METER_POLICY,
16558 NULL, "Queue action with meta "
16559 "is not supported. Please try use "
16560 "default policy for meter.");
16561 ret = mlx5_flow_validate_action_queue(act,
16565 return -rte_mtr_error_set(error,
16567 RTE_MTR_ERROR_TYPE_METER_POLICY,
16568 NULL, flow_err.message ?
16570 "Queue action validate check fail");
16571 action_flags |= MLX5_FLOW_ACTION_QUEUE;
16574 case RTE_FLOW_ACTION_TYPE_RSS:
16575 if (dev_conf->dv_flow_en &&
16576 (dev_conf->dv_xmeta_en !=
16577 MLX5_XMETA_MODE_LEGACY) &&
16578 mlx5_flow_ext_mreg_supported(dev))
16579 return -rte_mtr_error_set(error,
16581 RTE_MTR_ERROR_TYPE_METER_POLICY,
16582 NULL, "RSS action with meta "
16583 "is not supported. Please try use "
16584 "default policy for meter.");
16585 ret = mlx5_validate_action_rss(dev, act,
16588 return -rte_mtr_error_set(error,
16590 RTE_MTR_ERROR_TYPE_METER_POLICY,
16591 NULL, flow_err.message ?
16593 "RSS action validate check fail");
16594 action_flags |= MLX5_FLOW_ACTION_RSS;
16598 case RTE_FLOW_ACTION_TYPE_JUMP:
16599 ret = flow_dv_validate_action_jump(dev,
16600 NULL, act, action_flags,
16601 attr, true, &flow_err);
16603 return -rte_mtr_error_set(error,
16605 RTE_MTR_ERROR_TYPE_METER_POLICY,
16606 NULL, flow_err.message ?
16608 "Jump action validate check fail");
16610 action_flags |= MLX5_FLOW_ACTION_JUMP;
16613 return -rte_mtr_error_set(error, ENOTSUP,
16614 RTE_MTR_ERROR_TYPE_METER_POLICY,
16616 "Doesn't support optional action");
16619 /* Yellow is not supported, just skip. */
16620 if (i == RTE_COLOR_YELLOW)
16622 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
16623 domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
16624 else if ((action_flags &
16625 (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
16626 (action_flags & MLX5_FLOW_ACTION_MARK))
16628 * Only support MLX5_XMETA_MODE_LEGACY
16629 * so MARK action only in ingress domain.
16631 domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
16633 domain_color[i] = def_domain;
16635 * Validate the drop action mutual exclusion
16636 * with other actions. Drop action is mutually-exclusive
16637 * with any other action, except for Count action.
16639 if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
16640 (action_flags & ~MLX5_FLOW_ACTION_DROP)) {
16641 return -rte_mtr_error_set(error, ENOTSUP,
16642 RTE_MTR_ERROR_TYPE_METER_POLICY,
16643 NULL, "Drop action is mutually-exclusive "
16644 "with any other action");
16646 /* Eswitch has few restrictions on using items and actions */
16647 if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
16648 if (!mlx5_flow_ext_mreg_supported(dev) &&
16649 action_flags & MLX5_FLOW_ACTION_MARK)
16650 return -rte_mtr_error_set(error, ENOTSUP,
16651 RTE_MTR_ERROR_TYPE_METER_POLICY,
16652 NULL, "unsupported action MARK");
16653 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
16654 return -rte_mtr_error_set(error, ENOTSUP,
16655 RTE_MTR_ERROR_TYPE_METER_POLICY,
16656 NULL, "unsupported action QUEUE");
16657 if (action_flags & MLX5_FLOW_ACTION_RSS)
16658 return -rte_mtr_error_set(error, ENOTSUP,
16659 RTE_MTR_ERROR_TYPE_METER_POLICY,
16660 NULL, "unsupported action RSS");
16661 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
16662 return -rte_mtr_error_set(error, ENOTSUP,
16663 RTE_MTR_ERROR_TYPE_METER_POLICY,
16664 NULL, "no fate action is found");
16666 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) &&
16668 MLX5_MTR_DOMAIN_INGRESS_BIT)) {
16669 if ((domain_color[i] &
16670 MLX5_MTR_DOMAIN_EGRESS_BIT))
16672 MLX5_MTR_DOMAIN_EGRESS_BIT;
16674 return -rte_mtr_error_set(error,
16676 RTE_MTR_ERROR_TYPE_METER_POLICY,
16677 NULL, "no fate action is found");
16680 if (domain_color[i] != def_domain)
16681 *domain_bitmap = domain_color[i];
16687 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
16689 struct mlx5_priv *priv = dev->data->dev_private;
16692 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
16693 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
16698 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
16699 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
16703 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
16704 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
16711 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
16712 .validate = flow_dv_validate,
16713 .prepare = flow_dv_prepare,
16714 .translate = flow_dv_translate,
16715 .apply = flow_dv_apply,
16716 .remove = flow_dv_remove,
16717 .destroy = flow_dv_destroy,
16718 .query = flow_dv_query,
16719 .create_mtr_tbls = flow_dv_create_mtr_tbls,
16720 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
16721 .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
16722 .create_meter = flow_dv_mtr_alloc,
16723 .free_meter = flow_dv_aso_mtr_release_to_pool,
16724 .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
16725 .create_mtr_acts = flow_dv_create_mtr_policy_acts,
16726 .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
16727 .create_policy_rules = flow_dv_create_policy_rules,
16728 .destroy_policy_rules = flow_dv_destroy_policy_rules,
16729 .create_def_policy = flow_dv_create_def_policy,
16730 .destroy_def_policy = flow_dv_destroy_def_policy,
16731 .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
16732 .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
16733 .counter_alloc = flow_dv_counter_allocate,
16734 .counter_free = flow_dv_counter_free,
16735 .counter_query = flow_dv_counter_query,
16736 .get_aged_flows = flow_get_aged_flows,
16737 .action_validate = flow_dv_action_validate,
16738 .action_create = flow_dv_action_create,
16739 .action_destroy = flow_dv_action_destroy,
16740 .action_update = flow_dv_action_update,
16741 .action_query = flow_dv_action_query,
16742 .sync_domain = flow_dv_sync_domain,
16745 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */