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 <rte_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 <mlx5_glue.h>
26 #include <mlx5_devx_cmds.h>
28 #include <mlx5_malloc.h>
30 #include "mlx5_defs.h"
32 #include "mlx5_common_os.h"
33 #include "mlx5_flow.h"
34 #include "mlx5_flow_os.h"
35 #include "mlx5_rxtx.h"
36 #include "rte_pmd_mlx5.h"
38 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
40 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
41 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
44 #ifndef HAVE_MLX5DV_DR_ESWITCH
45 #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
46 #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
50 #ifndef HAVE_MLX5DV_DR
51 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
54 /* VLAN header definitions */
55 #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
56 #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
57 #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
58 #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
59 #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
74 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
75 struct mlx5_flow_tbl_resource *tbl);
78 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
79 uint32_t encap_decap_idx);
82 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
85 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss);
88 * Initialize flow attributes structure according to flow items' types.
90 * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
91 * mode. For tunnel mode, the items to be modified are the outermost ones.
94 * Pointer to item specification.
96 * Pointer to flow attributes structure.
98 * Pointer to the sub flow.
99 * @param[in] tunnel_decap
100 * Whether action is after tunnel decapsulation.
103 flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
104 struct mlx5_flow *dev_flow, bool tunnel_decap)
106 uint64_t layers = dev_flow->handle->layers;
109 * If layers is already initialized, it means this dev_flow is the
110 * suffix flow, the layers flags is set by the prefix flow. Need to
111 * use the layer flags from prefix flow as the suffix flow may not
112 * have the user defined items as the flow is split.
115 if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
117 else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
119 if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
121 else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
126 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
127 uint8_t next_protocol = 0xff;
128 switch (item->type) {
129 case RTE_FLOW_ITEM_TYPE_GRE:
130 case RTE_FLOW_ITEM_TYPE_NVGRE:
131 case RTE_FLOW_ITEM_TYPE_VXLAN:
132 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
133 case RTE_FLOW_ITEM_TYPE_GENEVE:
134 case RTE_FLOW_ITEM_TYPE_MPLS:
138 case RTE_FLOW_ITEM_TYPE_IPV4:
141 if (item->mask != NULL &&
142 ((const struct rte_flow_item_ipv4 *)
143 item->mask)->hdr.next_proto_id)
145 ((const struct rte_flow_item_ipv4 *)
146 (item->spec))->hdr.next_proto_id &
147 ((const struct rte_flow_item_ipv4 *)
148 (item->mask))->hdr.next_proto_id;
149 if ((next_protocol == IPPROTO_IPIP ||
150 next_protocol == IPPROTO_IPV6) && tunnel_decap)
153 case RTE_FLOW_ITEM_TYPE_IPV6:
156 if (item->mask != NULL &&
157 ((const struct rte_flow_item_ipv6 *)
158 item->mask)->hdr.proto)
160 ((const struct rte_flow_item_ipv6 *)
161 (item->spec))->hdr.proto &
162 ((const struct rte_flow_item_ipv6 *)
163 (item->mask))->hdr.proto;
164 if ((next_protocol == IPPROTO_IPIP ||
165 next_protocol == IPPROTO_IPV6) && tunnel_decap)
168 case RTE_FLOW_ITEM_TYPE_UDP:
172 case RTE_FLOW_ITEM_TYPE_TCP:
184 * Convert rte_mtr_color to mlx5 color.
193 rte_col_2_mlx5_col(enum rte_color rcol)
196 case RTE_COLOR_GREEN:
197 return MLX5_FLOW_COLOR_GREEN;
198 case RTE_COLOR_YELLOW:
199 return MLX5_FLOW_COLOR_YELLOW;
201 return MLX5_FLOW_COLOR_RED;
205 return MLX5_FLOW_COLOR_UNDEFINED;
208 struct field_modify_info {
209 uint32_t size; /* Size of field in protocol header, in bytes. */
210 uint32_t offset; /* Offset of field in protocol header, in bytes. */
211 enum mlx5_modification_field id;
214 struct field_modify_info modify_eth[] = {
215 {4, 0, MLX5_MODI_OUT_DMAC_47_16},
216 {2, 4, MLX5_MODI_OUT_DMAC_15_0},
217 {4, 6, MLX5_MODI_OUT_SMAC_47_16},
218 {2, 10, MLX5_MODI_OUT_SMAC_15_0},
222 struct field_modify_info modify_vlan_out_first_vid[] = {
223 /* Size in bits !!! */
224 {12, 0, MLX5_MODI_OUT_FIRST_VID},
228 struct field_modify_info modify_ipv4[] = {
229 {1, 1, MLX5_MODI_OUT_IP_DSCP},
230 {1, 8, MLX5_MODI_OUT_IPV4_TTL},
231 {4, 12, MLX5_MODI_OUT_SIPV4},
232 {4, 16, MLX5_MODI_OUT_DIPV4},
236 struct field_modify_info modify_ipv6[] = {
237 {1, 0, MLX5_MODI_OUT_IP_DSCP},
238 {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
239 {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
240 {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
241 {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
242 {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
243 {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
244 {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
245 {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
246 {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
250 struct field_modify_info modify_udp[] = {
251 {2, 0, MLX5_MODI_OUT_UDP_SPORT},
252 {2, 2, MLX5_MODI_OUT_UDP_DPORT},
256 struct field_modify_info modify_tcp[] = {
257 {2, 0, MLX5_MODI_OUT_TCP_SPORT},
258 {2, 2, MLX5_MODI_OUT_TCP_DPORT},
259 {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
260 {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
265 mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
266 uint8_t next_protocol, uint64_t *item_flags,
269 MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
270 item->type == RTE_FLOW_ITEM_TYPE_IPV6);
271 if (next_protocol == IPPROTO_IPIP) {
272 *item_flags |= MLX5_FLOW_LAYER_IPIP;
275 if (next_protocol == IPPROTO_IPV6) {
276 *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
281 /* Update VLAN's VID/PCP based on input rte_flow_action.
284 * Pointer to struct rte_flow_action.
286 * Pointer to struct rte_vlan_hdr.
289 mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
290 struct rte_vlan_hdr *vlan)
293 if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
295 ((const struct rte_flow_action_of_set_vlan_pcp *)
296 action->conf)->vlan_pcp;
297 vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
298 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
299 vlan->vlan_tci |= vlan_tci;
300 } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
301 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
302 vlan->vlan_tci |= rte_be_to_cpu_16
303 (((const struct rte_flow_action_of_set_vlan_vid *)
304 action->conf)->vlan_vid);
309 * Fetch 1, 2, 3 or 4 byte field from the byte array
310 * and return as unsigned integer in host-endian format.
313 * Pointer to data array.
315 * Size of field to extract.
318 * converted field in host endian format.
320 static inline uint32_t
321 flow_dv_fetch_field(const uint8_t *data, uint32_t size)
330 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
333 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data);
334 ret = (ret << 8) | *(data + sizeof(uint16_t));
337 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data);
348 * Convert modify-header action to DV specification.
350 * Data length of each action is determined by provided field description
351 * and the item mask. Data bit offset and width of each action is determined
352 * by provided item mask.
355 * Pointer to item specification.
357 * Pointer to field modification information.
358 * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
359 * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
360 * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
362 * Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
363 * Negative offset value sets the same offset as source offset.
364 * size field is ignored, value is taken from source field.
365 * @param[in,out] resource
366 * Pointer to the modify-header resource.
368 * Type of modification.
370 * Pointer to the error structure.
373 * 0 on success, a negative errno value otherwise and rte_errno is set.
376 flow_dv_convert_modify_action(struct rte_flow_item *item,
377 struct field_modify_info *field,
378 struct field_modify_info *dcopy,
379 struct mlx5_flow_dv_modify_hdr_resource *resource,
380 uint32_t type, struct rte_flow_error *error)
382 uint32_t i = resource->actions_num;
383 struct mlx5_modification_cmd *actions = resource->actions;
386 * The item and mask are provided in big-endian format.
387 * The fields should be presented as in big-endian format either.
388 * Mask must be always present, it defines the actual field width.
390 MLX5_ASSERT(item->mask);
391 MLX5_ASSERT(field->size);
398 if (i >= MLX5_MAX_MODIFY_NUM)
399 return rte_flow_error_set(error, EINVAL,
400 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
401 "too many items to modify");
402 /* Fetch variable byte size mask from the array. */
403 mask = flow_dv_fetch_field((const uint8_t *)item->mask +
404 field->offset, field->size);
409 /* Deduce actual data width in bits from mask value. */
410 off_b = rte_bsf32(mask);
411 size_b = sizeof(uint32_t) * CHAR_BIT -
412 off_b - __builtin_clz(mask);
414 size_b = size_b == sizeof(uint32_t) * CHAR_BIT ? 0 : size_b;
415 actions[i] = (struct mlx5_modification_cmd) {
421 /* Convert entire record to expected big-endian format. */
422 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
423 if (type == MLX5_MODIFICATION_TYPE_COPY) {
425 actions[i].dst_field = dcopy->id;
426 actions[i].dst_offset =
427 (int)dcopy->offset < 0 ? off_b : dcopy->offset;
428 /* Convert entire record to big-endian format. */
429 actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
431 MLX5_ASSERT(item->spec);
432 data = flow_dv_fetch_field((const uint8_t *)item->spec +
433 field->offset, field->size);
434 /* Shift out the trailing masked bits from data. */
435 data = (data & mask) >> off_b;
436 actions[i].data1 = rte_cpu_to_be_32(data);
440 } while (field->size);
441 if (resource->actions_num == i)
442 return rte_flow_error_set(error, EINVAL,
443 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
444 "invalid modification flow item");
445 resource->actions_num = i;
450 * Convert modify-header set IPv4 address action to DV specification.
452 * @param[in,out] resource
453 * Pointer to the modify-header resource.
455 * Pointer to action specification.
457 * Pointer to the error structure.
460 * 0 on success, a negative errno value otherwise and rte_errno is set.
463 flow_dv_convert_action_modify_ipv4
464 (struct mlx5_flow_dv_modify_hdr_resource *resource,
465 const struct rte_flow_action *action,
466 struct rte_flow_error *error)
468 const struct rte_flow_action_set_ipv4 *conf =
469 (const struct rte_flow_action_set_ipv4 *)(action->conf);
470 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
471 struct rte_flow_item_ipv4 ipv4;
472 struct rte_flow_item_ipv4 ipv4_mask;
474 memset(&ipv4, 0, sizeof(ipv4));
475 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
476 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
477 ipv4.hdr.src_addr = conf->ipv4_addr;
478 ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
480 ipv4.hdr.dst_addr = conf->ipv4_addr;
481 ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
484 item.mask = &ipv4_mask;
485 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
486 MLX5_MODIFICATION_TYPE_SET, error);
490 * Convert modify-header set IPv6 address action to DV specification.
492 * @param[in,out] resource
493 * Pointer to the modify-header resource.
495 * Pointer to action specification.
497 * Pointer to the error structure.
500 * 0 on success, a negative errno value otherwise and rte_errno is set.
503 flow_dv_convert_action_modify_ipv6
504 (struct mlx5_flow_dv_modify_hdr_resource *resource,
505 const struct rte_flow_action *action,
506 struct rte_flow_error *error)
508 const struct rte_flow_action_set_ipv6 *conf =
509 (const struct rte_flow_action_set_ipv6 *)(action->conf);
510 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
511 struct rte_flow_item_ipv6 ipv6;
512 struct rte_flow_item_ipv6 ipv6_mask;
514 memset(&ipv6, 0, sizeof(ipv6));
515 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
516 if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
517 memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
518 sizeof(ipv6.hdr.src_addr));
519 memcpy(&ipv6_mask.hdr.src_addr,
520 &rte_flow_item_ipv6_mask.hdr.src_addr,
521 sizeof(ipv6.hdr.src_addr));
523 memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
524 sizeof(ipv6.hdr.dst_addr));
525 memcpy(&ipv6_mask.hdr.dst_addr,
526 &rte_flow_item_ipv6_mask.hdr.dst_addr,
527 sizeof(ipv6.hdr.dst_addr));
530 item.mask = &ipv6_mask;
531 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
532 MLX5_MODIFICATION_TYPE_SET, error);
536 * Convert modify-header set MAC address action to DV specification.
538 * @param[in,out] resource
539 * Pointer to the modify-header resource.
541 * Pointer to action specification.
543 * Pointer to the error structure.
546 * 0 on success, a negative errno value otherwise and rte_errno is set.
549 flow_dv_convert_action_modify_mac
550 (struct mlx5_flow_dv_modify_hdr_resource *resource,
551 const struct rte_flow_action *action,
552 struct rte_flow_error *error)
554 const struct rte_flow_action_set_mac *conf =
555 (const struct rte_flow_action_set_mac *)(action->conf);
556 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
557 struct rte_flow_item_eth eth;
558 struct rte_flow_item_eth eth_mask;
560 memset(ð, 0, sizeof(eth));
561 memset(ð_mask, 0, sizeof(eth_mask));
562 if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
563 memcpy(ð.src.addr_bytes, &conf->mac_addr,
564 sizeof(eth.src.addr_bytes));
565 memcpy(ð_mask.src.addr_bytes,
566 &rte_flow_item_eth_mask.src.addr_bytes,
567 sizeof(eth_mask.src.addr_bytes));
569 memcpy(ð.dst.addr_bytes, &conf->mac_addr,
570 sizeof(eth.dst.addr_bytes));
571 memcpy(ð_mask.dst.addr_bytes,
572 &rte_flow_item_eth_mask.dst.addr_bytes,
573 sizeof(eth_mask.dst.addr_bytes));
576 item.mask = ð_mask;
577 return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
578 MLX5_MODIFICATION_TYPE_SET, error);
582 * Convert modify-header set VLAN VID action to DV specification.
584 * @param[in,out] resource
585 * Pointer to the modify-header resource.
587 * Pointer to action specification.
589 * Pointer to the error structure.
592 * 0 on success, a negative errno value otherwise and rte_errno is set.
595 flow_dv_convert_action_modify_vlan_vid
596 (struct mlx5_flow_dv_modify_hdr_resource *resource,
597 const struct rte_flow_action *action,
598 struct rte_flow_error *error)
600 const struct rte_flow_action_of_set_vlan_vid *conf =
601 (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
602 int i = resource->actions_num;
603 struct mlx5_modification_cmd *actions = resource->actions;
604 struct field_modify_info *field = modify_vlan_out_first_vid;
606 if (i >= MLX5_MAX_MODIFY_NUM)
607 return rte_flow_error_set(error, EINVAL,
608 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
609 "too many items to modify");
610 actions[i] = (struct mlx5_modification_cmd) {
611 .action_type = MLX5_MODIFICATION_TYPE_SET,
613 .length = field->size,
614 .offset = field->offset,
616 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
617 actions[i].data1 = conf->vlan_vid;
618 actions[i].data1 = actions[i].data1 << 16;
619 resource->actions_num = ++i;
624 * Convert modify-header set TP action to DV specification.
626 * @param[in,out] resource
627 * Pointer to the modify-header resource.
629 * Pointer to action specification.
631 * Pointer to rte_flow_item objects list.
633 * Pointer to flow attributes structure.
634 * @param[in] dev_flow
635 * Pointer to the sub flow.
636 * @param[in] tunnel_decap
637 * Whether action is after tunnel decapsulation.
639 * Pointer to the error structure.
642 * 0 on success, a negative errno value otherwise and rte_errno is set.
645 flow_dv_convert_action_modify_tp
646 (struct mlx5_flow_dv_modify_hdr_resource *resource,
647 const struct rte_flow_action *action,
648 const struct rte_flow_item *items,
649 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
650 bool tunnel_decap, struct rte_flow_error *error)
652 const struct rte_flow_action_set_tp *conf =
653 (const struct rte_flow_action_set_tp *)(action->conf);
654 struct rte_flow_item item;
655 struct rte_flow_item_udp udp;
656 struct rte_flow_item_udp udp_mask;
657 struct rte_flow_item_tcp tcp;
658 struct rte_flow_item_tcp tcp_mask;
659 struct field_modify_info *field;
662 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
664 memset(&udp, 0, sizeof(udp));
665 memset(&udp_mask, 0, sizeof(udp_mask));
666 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
667 udp.hdr.src_port = conf->port;
668 udp_mask.hdr.src_port =
669 rte_flow_item_udp_mask.hdr.src_port;
671 udp.hdr.dst_port = conf->port;
672 udp_mask.hdr.dst_port =
673 rte_flow_item_udp_mask.hdr.dst_port;
675 item.type = RTE_FLOW_ITEM_TYPE_UDP;
677 item.mask = &udp_mask;
680 MLX5_ASSERT(attr->tcp);
681 memset(&tcp, 0, sizeof(tcp));
682 memset(&tcp_mask, 0, sizeof(tcp_mask));
683 if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
684 tcp.hdr.src_port = conf->port;
685 tcp_mask.hdr.src_port =
686 rte_flow_item_tcp_mask.hdr.src_port;
688 tcp.hdr.dst_port = conf->port;
689 tcp_mask.hdr.dst_port =
690 rte_flow_item_tcp_mask.hdr.dst_port;
692 item.type = RTE_FLOW_ITEM_TYPE_TCP;
694 item.mask = &tcp_mask;
697 return flow_dv_convert_modify_action(&item, field, NULL, resource,
698 MLX5_MODIFICATION_TYPE_SET, error);
702 * Convert modify-header set TTL action to DV specification.
704 * @param[in,out] resource
705 * Pointer to the modify-header resource.
707 * Pointer to action specification.
709 * Pointer to rte_flow_item objects list.
711 * Pointer to flow attributes structure.
712 * @param[in] dev_flow
713 * Pointer to the sub flow.
714 * @param[in] tunnel_decap
715 * Whether action is after tunnel decapsulation.
717 * Pointer to the error structure.
720 * 0 on success, a negative errno value otherwise and rte_errno is set.
723 flow_dv_convert_action_modify_ttl
724 (struct mlx5_flow_dv_modify_hdr_resource *resource,
725 const struct rte_flow_action *action,
726 const struct rte_flow_item *items,
727 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
728 bool tunnel_decap, struct rte_flow_error *error)
730 const struct rte_flow_action_set_ttl *conf =
731 (const struct rte_flow_action_set_ttl *)(action->conf);
732 struct rte_flow_item item;
733 struct rte_flow_item_ipv4 ipv4;
734 struct rte_flow_item_ipv4 ipv4_mask;
735 struct rte_flow_item_ipv6 ipv6;
736 struct rte_flow_item_ipv6 ipv6_mask;
737 struct field_modify_info *field;
740 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
742 memset(&ipv4, 0, sizeof(ipv4));
743 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
744 ipv4.hdr.time_to_live = conf->ttl_value;
745 ipv4_mask.hdr.time_to_live = 0xFF;
746 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
748 item.mask = &ipv4_mask;
751 MLX5_ASSERT(attr->ipv6);
752 memset(&ipv6, 0, sizeof(ipv6));
753 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
754 ipv6.hdr.hop_limits = conf->ttl_value;
755 ipv6_mask.hdr.hop_limits = 0xFF;
756 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
758 item.mask = &ipv6_mask;
761 return flow_dv_convert_modify_action(&item, field, NULL, resource,
762 MLX5_MODIFICATION_TYPE_SET, error);
766 * Convert modify-header decrement TTL action to DV specification.
768 * @param[in,out] resource
769 * Pointer to the modify-header resource.
771 * Pointer to action specification.
773 * Pointer to rte_flow_item objects list.
775 * Pointer to flow attributes structure.
776 * @param[in] dev_flow
777 * Pointer to the sub flow.
778 * @param[in] tunnel_decap
779 * Whether action is after tunnel decapsulation.
781 * Pointer to the error structure.
784 * 0 on success, a negative errno value otherwise and rte_errno is set.
787 flow_dv_convert_action_modify_dec_ttl
788 (struct mlx5_flow_dv_modify_hdr_resource *resource,
789 const struct rte_flow_item *items,
790 union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
791 bool tunnel_decap, struct rte_flow_error *error)
793 struct rte_flow_item item;
794 struct rte_flow_item_ipv4 ipv4;
795 struct rte_flow_item_ipv4 ipv4_mask;
796 struct rte_flow_item_ipv6 ipv6;
797 struct rte_flow_item_ipv6 ipv6_mask;
798 struct field_modify_info *field;
801 flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
803 memset(&ipv4, 0, sizeof(ipv4));
804 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
805 ipv4.hdr.time_to_live = 0xFF;
806 ipv4_mask.hdr.time_to_live = 0xFF;
807 item.type = RTE_FLOW_ITEM_TYPE_IPV4;
809 item.mask = &ipv4_mask;
812 MLX5_ASSERT(attr->ipv6);
813 memset(&ipv6, 0, sizeof(ipv6));
814 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
815 ipv6.hdr.hop_limits = 0xFF;
816 ipv6_mask.hdr.hop_limits = 0xFF;
817 item.type = RTE_FLOW_ITEM_TYPE_IPV6;
819 item.mask = &ipv6_mask;
822 return flow_dv_convert_modify_action(&item, field, NULL, resource,
823 MLX5_MODIFICATION_TYPE_ADD, error);
827 * Convert modify-header increment/decrement TCP Sequence number
828 * to DV specification.
830 * @param[in,out] resource
831 * Pointer to the modify-header resource.
833 * Pointer to action specification.
835 * Pointer to the error structure.
838 * 0 on success, a negative errno value otherwise and rte_errno is set.
841 flow_dv_convert_action_modify_tcp_seq
842 (struct mlx5_flow_dv_modify_hdr_resource *resource,
843 const struct rte_flow_action *action,
844 struct rte_flow_error *error)
846 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
847 uint64_t value = rte_be_to_cpu_32(*conf);
848 struct rte_flow_item item;
849 struct rte_flow_item_tcp tcp;
850 struct rte_flow_item_tcp tcp_mask;
852 memset(&tcp, 0, sizeof(tcp));
853 memset(&tcp_mask, 0, sizeof(tcp_mask));
854 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
856 * The HW has no decrement operation, only increment operation.
857 * To simulate decrement X from Y using increment operation
858 * we need to add UINT32_MAX X times to Y.
859 * Each adding of UINT32_MAX decrements Y by 1.
862 tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
863 tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
864 item.type = RTE_FLOW_ITEM_TYPE_TCP;
866 item.mask = &tcp_mask;
867 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
868 MLX5_MODIFICATION_TYPE_ADD, error);
872 * Convert modify-header increment/decrement TCP Acknowledgment number
873 * to DV specification.
875 * @param[in,out] resource
876 * Pointer to the modify-header resource.
878 * Pointer to action specification.
880 * Pointer to the error structure.
883 * 0 on success, a negative errno value otherwise and rte_errno is set.
886 flow_dv_convert_action_modify_tcp_ack
887 (struct mlx5_flow_dv_modify_hdr_resource *resource,
888 const struct rte_flow_action *action,
889 struct rte_flow_error *error)
891 const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
892 uint64_t value = rte_be_to_cpu_32(*conf);
893 struct rte_flow_item item;
894 struct rte_flow_item_tcp tcp;
895 struct rte_flow_item_tcp tcp_mask;
897 memset(&tcp, 0, sizeof(tcp));
898 memset(&tcp_mask, 0, sizeof(tcp_mask));
899 if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
901 * The HW has no decrement operation, only increment operation.
902 * To simulate decrement X from Y using increment operation
903 * we need to add UINT32_MAX X times to Y.
904 * Each adding of UINT32_MAX decrements Y by 1.
907 tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
908 tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
909 item.type = RTE_FLOW_ITEM_TYPE_TCP;
911 item.mask = &tcp_mask;
912 return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
913 MLX5_MODIFICATION_TYPE_ADD, error);
916 static enum mlx5_modification_field reg_to_field[] = {
917 [REG_NON] = MLX5_MODI_OUT_NONE,
918 [REG_A] = MLX5_MODI_META_DATA_REG_A,
919 [REG_B] = MLX5_MODI_META_DATA_REG_B,
920 [REG_C_0] = MLX5_MODI_META_REG_C_0,
921 [REG_C_1] = MLX5_MODI_META_REG_C_1,
922 [REG_C_2] = MLX5_MODI_META_REG_C_2,
923 [REG_C_3] = MLX5_MODI_META_REG_C_3,
924 [REG_C_4] = MLX5_MODI_META_REG_C_4,
925 [REG_C_5] = MLX5_MODI_META_REG_C_5,
926 [REG_C_6] = MLX5_MODI_META_REG_C_6,
927 [REG_C_7] = MLX5_MODI_META_REG_C_7,
931 * Convert register set to DV specification.
933 * @param[in,out] resource
934 * Pointer to the modify-header resource.
936 * Pointer to action specification.
938 * Pointer to the error structure.
941 * 0 on success, a negative errno value otherwise and rte_errno is set.
944 flow_dv_convert_action_set_reg
945 (struct mlx5_flow_dv_modify_hdr_resource *resource,
946 const struct rte_flow_action *action,
947 struct rte_flow_error *error)
949 const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
950 struct mlx5_modification_cmd *actions = resource->actions;
951 uint32_t i = resource->actions_num;
953 if (i >= MLX5_MAX_MODIFY_NUM)
954 return rte_flow_error_set(error, EINVAL,
955 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
956 "too many items to modify");
957 MLX5_ASSERT(conf->id != REG_NON);
958 MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
959 actions[i] = (struct mlx5_modification_cmd) {
960 .action_type = MLX5_MODIFICATION_TYPE_SET,
961 .field = reg_to_field[conf->id],
963 actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
964 actions[i].data1 = rte_cpu_to_be_32(conf->data);
966 resource->actions_num = i;
971 * Convert SET_TAG action to DV specification.
974 * Pointer to the rte_eth_dev structure.
975 * @param[in,out] resource
976 * Pointer to the modify-header resource.
978 * Pointer to action specification.
980 * Pointer to the error structure.
983 * 0 on success, a negative errno value otherwise and rte_errno is set.
986 flow_dv_convert_action_set_tag
987 (struct rte_eth_dev *dev,
988 struct mlx5_flow_dv_modify_hdr_resource *resource,
989 const struct rte_flow_action_set_tag *conf,
990 struct rte_flow_error *error)
992 rte_be32_t data = rte_cpu_to_be_32(conf->data);
993 rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
994 struct rte_flow_item item = {
998 struct field_modify_info reg_c_x[] = {
1001 enum mlx5_modification_field reg_type;
1004 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1007 MLX5_ASSERT(ret != REG_NON);
1008 MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1009 reg_type = reg_to_field[ret];
1010 MLX5_ASSERT(reg_type > 0);
1011 reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1012 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1013 MLX5_MODIFICATION_TYPE_SET, error);
1017 * Convert internal COPY_REG action to DV specification.
1020 * Pointer to the rte_eth_dev structure.
1021 * @param[in,out] res
1022 * Pointer to the modify-header resource.
1024 * Pointer to action specification.
1026 * Pointer to the error structure.
1029 * 0 on success, a negative errno value otherwise and rte_errno is set.
1032 flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1033 struct mlx5_flow_dv_modify_hdr_resource *res,
1034 const struct rte_flow_action *action,
1035 struct rte_flow_error *error)
1037 const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1038 rte_be32_t mask = RTE_BE32(UINT32_MAX);
1039 struct rte_flow_item item = {
1043 struct field_modify_info reg_src[] = {
1044 {4, 0, reg_to_field[conf->src]},
1047 struct field_modify_info reg_dst = {
1049 .id = reg_to_field[conf->dst],
1051 /* Adjust reg_c[0] usage according to reported mask. */
1052 if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1053 struct mlx5_priv *priv = dev->data->dev_private;
1054 uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1056 MLX5_ASSERT(reg_c0);
1057 MLX5_ASSERT(priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY);
1058 if (conf->dst == REG_C_0) {
1059 /* Copy to reg_c[0], within mask only. */
1060 reg_dst.offset = rte_bsf32(reg_c0);
1062 * Mask is ignoring the enianness, because
1063 * there is no conversion in datapath.
1065 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1066 /* Copy from destination lower bits to reg_c[0]. */
1067 mask = reg_c0 >> reg_dst.offset;
1069 /* Copy from destination upper bits to reg_c[0]. */
1070 mask = reg_c0 << (sizeof(reg_c0) * CHAR_BIT -
1071 rte_fls_u32(reg_c0));
1074 mask = rte_cpu_to_be_32(reg_c0);
1075 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1076 /* Copy from reg_c[0] to destination lower bits. */
1079 /* Copy from reg_c[0] to destination upper bits. */
1080 reg_dst.offset = sizeof(reg_c0) * CHAR_BIT -
1081 (rte_fls_u32(reg_c0) -
1086 return flow_dv_convert_modify_action(&item,
1087 reg_src, ®_dst, res,
1088 MLX5_MODIFICATION_TYPE_COPY,
1093 * Convert MARK action to DV specification. This routine is used
1094 * in extensive metadata only and requires metadata register to be
1095 * handled. In legacy mode hardware tag resource is engaged.
1098 * Pointer to the rte_eth_dev structure.
1100 * Pointer to MARK action specification.
1101 * @param[in,out] resource
1102 * Pointer to the modify-header resource.
1104 * Pointer to the error structure.
1107 * 0 on success, a negative errno value otherwise and rte_errno is set.
1110 flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1111 const struct rte_flow_action_mark *conf,
1112 struct mlx5_flow_dv_modify_hdr_resource *resource,
1113 struct rte_flow_error *error)
1115 struct mlx5_priv *priv = dev->data->dev_private;
1116 rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1117 priv->sh->dv_mark_mask);
1118 rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1119 struct rte_flow_item item = {
1123 struct field_modify_info reg_c_x[] = {
1129 return rte_flow_error_set(error, EINVAL,
1130 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1131 NULL, "zero mark action mask");
1132 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1135 MLX5_ASSERT(reg > 0);
1136 if (reg == REG_C_0) {
1137 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1138 uint32_t shl_c0 = rte_bsf32(msk_c0);
1140 data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1141 mask = rte_cpu_to_be_32(mask) & msk_c0;
1142 mask = rte_cpu_to_be_32(mask << shl_c0);
1144 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1145 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1146 MLX5_MODIFICATION_TYPE_SET, error);
1150 * Get metadata register index for specified steering domain.
1153 * Pointer to the rte_eth_dev structure.
1155 * Attributes of flow to determine steering domain.
1157 * Pointer to the error structure.
1160 * positive index on success, a negative errno value otherwise
1161 * and rte_errno is set.
1163 static enum modify_reg
1164 flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1165 const struct rte_flow_attr *attr,
1166 struct rte_flow_error *error)
1169 mlx5_flow_get_reg_id(dev, attr->transfer ?
1173 MLX5_METADATA_RX, 0, error);
1175 return rte_flow_error_set(error,
1176 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1177 NULL, "unavailable "
1178 "metadata register");
1183 * Convert SET_META action to DV specification.
1186 * Pointer to the rte_eth_dev structure.
1187 * @param[in,out] resource
1188 * Pointer to the modify-header resource.
1190 * Attributes of flow that includes this item.
1192 * Pointer to action specification.
1194 * Pointer to the error structure.
1197 * 0 on success, a negative errno value otherwise and rte_errno is set.
1200 flow_dv_convert_action_set_meta
1201 (struct rte_eth_dev *dev,
1202 struct mlx5_flow_dv_modify_hdr_resource *resource,
1203 const struct rte_flow_attr *attr,
1204 const struct rte_flow_action_set_meta *conf,
1205 struct rte_flow_error *error)
1207 uint32_t data = conf->data;
1208 uint32_t mask = conf->mask;
1209 struct rte_flow_item item = {
1213 struct field_modify_info reg_c_x[] = {
1216 int reg = flow_dv_get_metadata_reg(dev, attr, error);
1220 MLX5_ASSERT(reg != REG_NON);
1222 * In datapath code there is no endianness
1223 * coversions for perfromance reasons, all
1224 * pattern conversions are done in rte_flow.
1226 if (reg == REG_C_0) {
1227 struct mlx5_priv *priv = dev->data->dev_private;
1228 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1231 MLX5_ASSERT(msk_c0);
1232 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1233 shl_c0 = rte_bsf32(msk_c0);
1235 shl_c0 = sizeof(msk_c0) * CHAR_BIT - rte_fls_u32(msk_c0);
1239 MLX5_ASSERT(!(~msk_c0 & rte_cpu_to_be_32(mask)));
1241 reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1242 /* The routine expects parameters in memory as big-endian ones. */
1243 return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1244 MLX5_MODIFICATION_TYPE_SET, error);
1248 * Convert modify-header set IPv4 DSCP action to DV specification.
1250 * @param[in,out] resource
1251 * Pointer to the modify-header resource.
1253 * Pointer to action specification.
1255 * Pointer to the error structure.
1258 * 0 on success, a negative errno value otherwise and rte_errno is set.
1261 flow_dv_convert_action_modify_ipv4_dscp
1262 (struct mlx5_flow_dv_modify_hdr_resource *resource,
1263 const struct rte_flow_action *action,
1264 struct rte_flow_error *error)
1266 const struct rte_flow_action_set_dscp *conf =
1267 (const struct rte_flow_action_set_dscp *)(action->conf);
1268 struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1269 struct rte_flow_item_ipv4 ipv4;
1270 struct rte_flow_item_ipv4 ipv4_mask;
1272 memset(&ipv4, 0, sizeof(ipv4));
1273 memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1274 ipv4.hdr.type_of_service = conf->dscp;
1275 ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1277 item.mask = &ipv4_mask;
1278 return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1279 MLX5_MODIFICATION_TYPE_SET, error);
1283 * Convert modify-header set IPv6 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_ipv6_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_IPV6 };
1304 struct rte_flow_item_ipv6 ipv6;
1305 struct rte_flow_item_ipv6 ipv6_mask;
1307 memset(&ipv6, 0, sizeof(ipv6));
1308 memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1310 * Even though the DSCP bits offset of IPv6 is not byte aligned,
1311 * rdma-core only accept the DSCP bits byte aligned start from
1312 * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1313 * bits in IPv6 case as rdma-core requires byte aligned value.
1315 ipv6.hdr.vtc_flow = conf->dscp;
1316 ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> 22;
1318 item.mask = &ipv6_mask;
1319 return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
1320 MLX5_MODIFICATION_TYPE_SET, error);
1324 * Validate MARK item.
1327 * Pointer to the rte_eth_dev structure.
1329 * Item specification.
1331 * Attributes of flow that includes this item.
1333 * Pointer to error structure.
1336 * 0 on success, a negative errno value otherwise and rte_errno is set.
1339 flow_dv_validate_item_mark(struct rte_eth_dev *dev,
1340 const struct rte_flow_item *item,
1341 const struct rte_flow_attr *attr __rte_unused,
1342 struct rte_flow_error *error)
1344 struct mlx5_priv *priv = dev->data->dev_private;
1345 struct mlx5_dev_config *config = &priv->config;
1346 const struct rte_flow_item_mark *spec = item->spec;
1347 const struct rte_flow_item_mark *mask = item->mask;
1348 const struct rte_flow_item_mark nic_mask = {
1349 .id = priv->sh->dv_mark_mask,
1353 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
1354 return rte_flow_error_set(error, ENOTSUP,
1355 RTE_FLOW_ERROR_TYPE_ITEM, item,
1356 "extended metadata feature"
1358 if (!mlx5_flow_ext_mreg_supported(dev))
1359 return rte_flow_error_set(error, ENOTSUP,
1360 RTE_FLOW_ERROR_TYPE_ITEM, item,
1361 "extended metadata register"
1362 " isn't supported");
1364 return rte_flow_error_set(error, ENOTSUP,
1365 RTE_FLOW_ERROR_TYPE_ITEM, item,
1366 "extended metadata register"
1367 " isn't available");
1368 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1372 return rte_flow_error_set(error, EINVAL,
1373 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1375 "data cannot be empty");
1376 if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
1377 return rte_flow_error_set(error, EINVAL,
1378 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1380 "mark id exceeds the limit");
1384 return rte_flow_error_set(error, EINVAL,
1385 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1386 "mask cannot be zero");
1388 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1389 (const uint8_t *)&nic_mask,
1390 sizeof(struct rte_flow_item_mark),
1391 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1398 * Validate META item.
1401 * Pointer to the rte_eth_dev structure.
1403 * Item specification.
1405 * Attributes of flow that includes this item.
1407 * Pointer to error structure.
1410 * 0 on success, a negative errno value otherwise and rte_errno is set.
1413 flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
1414 const struct rte_flow_item *item,
1415 const struct rte_flow_attr *attr,
1416 struct rte_flow_error *error)
1418 struct mlx5_priv *priv = dev->data->dev_private;
1419 struct mlx5_dev_config *config = &priv->config;
1420 const struct rte_flow_item_meta *spec = item->spec;
1421 const struct rte_flow_item_meta *mask = item->mask;
1422 struct rte_flow_item_meta nic_mask = {
1429 return rte_flow_error_set(error, EINVAL,
1430 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1432 "data cannot be empty");
1433 if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1434 if (!mlx5_flow_ext_mreg_supported(dev))
1435 return rte_flow_error_set(error, ENOTSUP,
1436 RTE_FLOW_ERROR_TYPE_ITEM, item,
1437 "extended metadata register"
1438 " isn't supported");
1439 reg = flow_dv_get_metadata_reg(dev, attr, error);
1443 return rte_flow_error_set(error, ENOTSUP,
1444 RTE_FLOW_ERROR_TYPE_ITEM, item,
1445 "unavalable extended metadata register");
1447 return rte_flow_error_set(error, ENOTSUP,
1448 RTE_FLOW_ERROR_TYPE_ITEM, item,
1452 nic_mask.data = priv->sh->dv_meta_mask;
1453 } else if (attr->transfer) {
1454 return rte_flow_error_set(error, ENOTSUP,
1455 RTE_FLOW_ERROR_TYPE_ITEM, item,
1456 "extended metadata feature "
1457 "should be enabled when "
1458 "meta item is requested "
1459 "with e-switch mode ");
1462 mask = &rte_flow_item_meta_mask;
1464 return rte_flow_error_set(error, EINVAL,
1465 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1466 "mask cannot be zero");
1468 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1469 (const uint8_t *)&nic_mask,
1470 sizeof(struct rte_flow_item_meta),
1471 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1476 * Validate TAG item.
1479 * Pointer to the rte_eth_dev structure.
1481 * Item specification.
1483 * Attributes of flow that includes this item.
1485 * Pointer to error structure.
1488 * 0 on success, a negative errno value otherwise and rte_errno is set.
1491 flow_dv_validate_item_tag(struct rte_eth_dev *dev,
1492 const struct rte_flow_item *item,
1493 const struct rte_flow_attr *attr __rte_unused,
1494 struct rte_flow_error *error)
1496 const struct rte_flow_item_tag *spec = item->spec;
1497 const struct rte_flow_item_tag *mask = item->mask;
1498 const struct rte_flow_item_tag nic_mask = {
1499 .data = RTE_BE32(UINT32_MAX),
1504 if (!mlx5_flow_ext_mreg_supported(dev))
1505 return rte_flow_error_set(error, ENOTSUP,
1506 RTE_FLOW_ERROR_TYPE_ITEM, item,
1507 "extensive metadata register"
1508 " isn't supported");
1510 return rte_flow_error_set(error, EINVAL,
1511 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1513 "data cannot be empty");
1515 mask = &rte_flow_item_tag_mask;
1517 return rte_flow_error_set(error, EINVAL,
1518 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1519 "mask cannot be zero");
1521 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1522 (const uint8_t *)&nic_mask,
1523 sizeof(struct rte_flow_item_tag),
1524 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1527 if (mask->index != 0xff)
1528 return rte_flow_error_set(error, EINVAL,
1529 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
1530 "partial mask for tag index"
1531 " is not supported");
1532 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
1535 MLX5_ASSERT(ret != REG_NON);
1540 * Validate vport item.
1543 * Pointer to the rte_eth_dev structure.
1545 * Item specification.
1547 * Attributes of flow that includes this item.
1548 * @param[in] item_flags
1549 * Bit-fields that holds the items detected until now.
1551 * Pointer to error structure.
1554 * 0 on success, a negative errno value otherwise and rte_errno is set.
1557 flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
1558 const struct rte_flow_item *item,
1559 const struct rte_flow_attr *attr,
1560 uint64_t item_flags,
1561 struct rte_flow_error *error)
1563 const struct rte_flow_item_port_id *spec = item->spec;
1564 const struct rte_flow_item_port_id *mask = item->mask;
1565 const struct rte_flow_item_port_id switch_mask = {
1568 struct mlx5_priv *esw_priv;
1569 struct mlx5_priv *dev_priv;
1572 if (!attr->transfer)
1573 return rte_flow_error_set(error, EINVAL,
1574 RTE_FLOW_ERROR_TYPE_ITEM,
1576 "match on port id is valid only"
1577 " when transfer flag is enabled");
1578 if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
1579 return rte_flow_error_set(error, ENOTSUP,
1580 RTE_FLOW_ERROR_TYPE_ITEM, item,
1581 "multiple source ports are not"
1584 mask = &switch_mask;
1585 if (mask->id != 0xffffffff)
1586 return rte_flow_error_set(error, ENOTSUP,
1587 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
1589 "no support for partial mask on"
1591 ret = mlx5_flow_item_acceptable
1592 (item, (const uint8_t *)mask,
1593 (const uint8_t *)&rte_flow_item_port_id_mask,
1594 sizeof(struct rte_flow_item_port_id),
1595 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1600 esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
1602 return rte_flow_error_set(error, rte_errno,
1603 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1604 "failed to obtain E-Switch info for"
1606 dev_priv = mlx5_dev_to_eswitch_info(dev);
1608 return rte_flow_error_set(error, rte_errno,
1609 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1611 "failed to obtain E-Switch info");
1612 if (esw_priv->domain_id != dev_priv->domain_id)
1613 return rte_flow_error_set(error, EINVAL,
1614 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
1615 "cannot match on a port from a"
1616 " different E-Switch");
1621 * Validate VLAN item.
1624 * Item specification.
1625 * @param[in] item_flags
1626 * Bit-fields that holds the items detected until now.
1628 * Ethernet device flow is being created on.
1630 * Pointer to error structure.
1633 * 0 on success, a negative errno value otherwise and rte_errno is set.
1636 flow_dv_validate_item_vlan(const struct rte_flow_item *item,
1637 uint64_t item_flags,
1638 struct rte_eth_dev *dev,
1639 struct rte_flow_error *error)
1641 const struct rte_flow_item_vlan *mask = item->mask;
1642 const struct rte_flow_item_vlan nic_mask = {
1643 .tci = RTE_BE16(UINT16_MAX),
1644 .inner_type = RTE_BE16(UINT16_MAX),
1647 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1649 const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
1650 MLX5_FLOW_LAYER_INNER_L4) :
1651 (MLX5_FLOW_LAYER_OUTER_L3 |
1652 MLX5_FLOW_LAYER_OUTER_L4);
1653 const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
1654 MLX5_FLOW_LAYER_OUTER_VLAN;
1656 if (item_flags & vlanm)
1657 return rte_flow_error_set(error, EINVAL,
1658 RTE_FLOW_ERROR_TYPE_ITEM, item,
1659 "multiple VLAN layers not supported");
1660 else if ((item_flags & l34m) != 0)
1661 return rte_flow_error_set(error, EINVAL,
1662 RTE_FLOW_ERROR_TYPE_ITEM, item,
1663 "VLAN cannot follow L3/L4 layer");
1665 mask = &rte_flow_item_vlan_mask;
1666 ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1667 (const uint8_t *)&nic_mask,
1668 sizeof(struct rte_flow_item_vlan),
1669 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1672 if (!tunnel && mask->tci != RTE_BE16(0x0fff)) {
1673 struct mlx5_priv *priv = dev->data->dev_private;
1675 if (priv->vmwa_context) {
1677 * Non-NULL context means we have a virtual machine
1678 * and SR-IOV enabled, we have to create VLAN interface
1679 * to make hypervisor to setup E-Switch vport
1680 * context correctly. We avoid creating the multiple
1681 * VLAN interfaces, so we cannot support VLAN tag mask.
1683 return rte_flow_error_set(error, EINVAL,
1684 RTE_FLOW_ERROR_TYPE_ITEM,
1686 "VLAN tag mask is not"
1687 " supported in virtual"
1695 * GTP flags are contained in 1 byte of the format:
1696 * -------------------------------------------
1697 * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
1698 * |-----------------------------------------|
1699 * | value | Version | PT | Res | E | S | PN |
1700 * -------------------------------------------
1702 * Matching is supported only for GTP flags E, S, PN.
1704 #define MLX5_GTP_FLAGS_MASK 0x07
1707 * Validate GTP item.
1710 * Pointer to the rte_eth_dev structure.
1712 * Item specification.
1713 * @param[in] item_flags
1714 * Bit-fields that holds the items detected until now.
1716 * Pointer to error structure.
1719 * 0 on success, a negative errno value otherwise and rte_errno is set.
1722 flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
1723 const struct rte_flow_item *item,
1724 uint64_t item_flags,
1725 struct rte_flow_error *error)
1727 struct mlx5_priv *priv = dev->data->dev_private;
1728 const struct rte_flow_item_gtp *spec = item->spec;
1729 const struct rte_flow_item_gtp *mask = item->mask;
1730 const struct rte_flow_item_gtp nic_mask = {
1731 .v_pt_rsv_flags = MLX5_GTP_FLAGS_MASK,
1733 .teid = RTE_BE32(0xffffffff),
1736 if (!priv->config.hca_attr.tunnel_stateless_gtp)
1737 return rte_flow_error_set(error, ENOTSUP,
1738 RTE_FLOW_ERROR_TYPE_ITEM, item,
1739 "GTP support is not enabled");
1740 if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
1741 return rte_flow_error_set(error, ENOTSUP,
1742 RTE_FLOW_ERROR_TYPE_ITEM, item,
1743 "multiple tunnel layers not"
1745 if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
1746 return rte_flow_error_set(error, EINVAL,
1747 RTE_FLOW_ERROR_TYPE_ITEM, item,
1748 "no outer UDP layer found");
1750 mask = &rte_flow_item_gtp_mask;
1751 if (spec && spec->v_pt_rsv_flags & ~MLX5_GTP_FLAGS_MASK)
1752 return rte_flow_error_set(error, ENOTSUP,
1753 RTE_FLOW_ERROR_TYPE_ITEM, item,
1754 "Match is supported for GTP"
1756 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1757 (const uint8_t *)&nic_mask,
1758 sizeof(struct rte_flow_item_gtp),
1759 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1763 * Validate GTP PSC item.
1766 * Item specification.
1767 * @param[in] last_item
1768 * Previous validated item in the pattern items.
1769 * @param[in] gtp_item
1770 * Previous GTP item specification.
1772 * Pointer to flow attributes.
1774 * Pointer to error structure.
1777 * 0 on success, a negative errno value otherwise and rte_errno is set.
1780 flow_dv_validate_item_gtp_psc(const struct rte_flow_item *item,
1782 const struct rte_flow_item *gtp_item,
1783 const struct rte_flow_attr *attr,
1784 struct rte_flow_error *error)
1786 const struct rte_flow_item_gtp *gtp_spec;
1787 const struct rte_flow_item_gtp *gtp_mask;
1788 const struct rte_flow_item_gtp_psc *spec;
1789 const struct rte_flow_item_gtp_psc *mask;
1790 const struct rte_flow_item_gtp_psc nic_mask = {
1795 if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
1796 return rte_flow_error_set
1797 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
1798 "GTP PSC item must be preceded with GTP item");
1799 gtp_spec = gtp_item->spec;
1800 gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
1801 /* GTP spec and E flag is requested to match zero. */
1803 (gtp_mask->v_pt_rsv_flags &
1804 ~gtp_spec->v_pt_rsv_flags & MLX5_GTP_EXT_HEADER_FLAG))
1805 return rte_flow_error_set
1806 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
1807 "GTP E flag must be 1 to match GTP PSC");
1808 /* Check the flow is not created in group zero. */
1809 if (!attr->transfer && !attr->group)
1810 return rte_flow_error_set
1811 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1812 "GTP PSC is not supported for group 0");
1813 /* GTP spec is here and E flag is requested to match zero. */
1817 mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
1818 if (spec->pdu_type > MLX5_GTP_EXT_MAX_PDU_TYPE)
1819 return rte_flow_error_set
1820 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
1821 "PDU type should be smaller than 16");
1822 return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
1823 (const uint8_t *)&nic_mask,
1824 sizeof(struct rte_flow_item_gtp_psc),
1825 MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
1829 * Validate IPV4 item.
1830 * Use existing validation function mlx5_flow_validate_item_ipv4(), and
1831 * add specific validation of fragment_offset field,
1834 * Item specification.
1835 * @param[in] item_flags
1836 * Bit-fields that holds the items detected until now.
1838 * Pointer to error structure.
1841 * 0 on success, a negative errno value otherwise and rte_errno is set.
1844 flow_dv_validate_item_ipv4(const struct rte_flow_item *item,
1845 uint64_t item_flags,
1847 uint16_t ether_type,
1848 struct rte_flow_error *error)
1851 const struct rte_flow_item_ipv4 *spec = item->spec;
1852 const struct rte_flow_item_ipv4 *last = item->last;
1853 const struct rte_flow_item_ipv4 *mask = item->mask;
1854 rte_be16_t fragment_offset_spec = 0;
1855 rte_be16_t fragment_offset_last = 0;
1856 const struct rte_flow_item_ipv4 nic_ipv4_mask = {
1858 .src_addr = RTE_BE32(0xffffffff),
1859 .dst_addr = RTE_BE32(0xffffffff),
1860 .type_of_service = 0xff,
1861 .fragment_offset = RTE_BE16(0xffff),
1862 .next_proto_id = 0xff,
1863 .time_to_live = 0xff,
1867 ret = mlx5_flow_validate_item_ipv4(item, item_flags, last_item,
1868 ether_type, &nic_ipv4_mask,
1869 MLX5_ITEM_RANGE_ACCEPTED, error);
1873 fragment_offset_spec = spec->hdr.fragment_offset &
1874 mask->hdr.fragment_offset;
1875 if (!fragment_offset_spec)
1878 * spec and mask are valid, enforce using full mask to make sure the
1879 * complete value is used correctly.
1881 if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
1882 != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
1883 return rte_flow_error_set(error, EINVAL,
1884 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
1885 item, "must use full mask for"
1886 " fragment_offset");
1888 * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
1889 * indicating this is 1st fragment of fragmented packet.
1890 * This is not yet supported in MLX5, return appropriate error message.
1892 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
1893 return rte_flow_error_set(error, ENOTSUP,
1894 RTE_FLOW_ERROR_TYPE_ITEM, item,
1895 "match on first fragment not "
1897 if (fragment_offset_spec && !last)
1898 return rte_flow_error_set(error, ENOTSUP,
1899 RTE_FLOW_ERROR_TYPE_ITEM, item,
1900 "specified value not supported");
1901 /* spec and last are valid, validate the specified range. */
1902 fragment_offset_last = last->hdr.fragment_offset &
1903 mask->hdr.fragment_offset;
1905 * Match on fragment_offset spec 0x2001 and last 0x3fff
1906 * means MF is 1 and frag-offset is > 0.
1907 * This packet is fragment 2nd and onward, excluding last.
1908 * This is not yet supported in MLX5, return appropriate
1911 if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
1912 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
1913 return rte_flow_error_set(error, ENOTSUP,
1914 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
1915 last, "match on following "
1916 "fragments not supported");
1918 * Match on fragment_offset spec 0x0001 and last 0x1fff
1919 * means MF is 0 and frag-offset is > 0.
1920 * This packet is last fragment of fragmented packet.
1921 * This is not yet supported in MLX5, return appropriate
1924 if (fragment_offset_spec == RTE_BE16(1) &&
1925 fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
1926 return rte_flow_error_set(error, ENOTSUP,
1927 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
1928 last, "match on last "
1929 "fragment not supported");
1931 * Match on fragment_offset spec 0x0001 and last 0x3fff
1932 * means MF and/or frag-offset is not 0.
1933 * This is a fragmented packet.
1934 * Other range values are invalid and rejected.
1936 if (!(fragment_offset_spec == RTE_BE16(1) &&
1937 fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
1938 return rte_flow_error_set(error, ENOTSUP,
1939 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
1940 "specified range not supported");
1945 * Validate IPV6 fragment extension item.
1948 * Item specification.
1949 * @param[in] item_flags
1950 * Bit-fields that holds the items detected until now.
1952 * Pointer to error structure.
1955 * 0 on success, a negative errno value otherwise and rte_errno is set.
1958 flow_dv_validate_item_ipv6_frag_ext(const struct rte_flow_item *item,
1959 uint64_t item_flags,
1960 struct rte_flow_error *error)
1962 const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
1963 const struct rte_flow_item_ipv6_frag_ext *last = item->last;
1964 const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
1965 rte_be16_t frag_data_spec = 0;
1966 rte_be16_t frag_data_last = 0;
1967 const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
1968 const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
1969 MLX5_FLOW_LAYER_OUTER_L4;
1971 struct rte_flow_item_ipv6_frag_ext nic_mask = {
1973 .next_header = 0xff,
1974 .frag_data = RTE_BE16(0xffff),
1978 if (item_flags & l4m)
1979 return rte_flow_error_set(error, EINVAL,
1980 RTE_FLOW_ERROR_TYPE_ITEM, item,
1981 "ipv6 fragment extension item cannot "
1983 if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
1984 (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
1985 return rte_flow_error_set(error, EINVAL,
1986 RTE_FLOW_ERROR_TYPE_ITEM, item,
1987 "ipv6 fragment extension item must "
1988 "follow ipv6 item");
1990 frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
1991 if (!frag_data_spec)
1994 * spec and mask are valid, enforce using full mask to make sure the
1995 * complete value is used correctly.
1997 if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
1998 RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
1999 return rte_flow_error_set(error, EINVAL,
2000 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2001 item, "must use full mask for"
2004 * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
2005 * This is 1st fragment of fragmented packet.
2007 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
2008 return rte_flow_error_set(error, ENOTSUP,
2009 RTE_FLOW_ERROR_TYPE_ITEM, item,
2010 "match on first fragment not "
2012 if (frag_data_spec && !last)
2013 return rte_flow_error_set(error, EINVAL,
2014 RTE_FLOW_ERROR_TYPE_ITEM, item,
2015 "specified value not supported");
2016 ret = mlx5_flow_item_acceptable
2017 (item, (const uint8_t *)mask,
2018 (const uint8_t *)&nic_mask,
2019 sizeof(struct rte_flow_item_ipv6_frag_ext),
2020 MLX5_ITEM_RANGE_ACCEPTED, error);
2023 /* spec and last are valid, validate the specified range. */
2024 frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
2026 * Match on frag_data spec 0x0009 and last 0xfff9
2027 * means M is 1 and frag-offset is > 0.
2028 * This packet is fragment 2nd and onward, excluding last.
2029 * This is not yet supported in MLX5, return appropriate
2032 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
2033 RTE_IPV6_EHDR_MF_MASK) &&
2034 frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
2035 return rte_flow_error_set(error, ENOTSUP,
2036 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2037 last, "match on following "
2038 "fragments not supported");
2040 * Match on frag_data spec 0x0008 and last 0xfff8
2041 * means M is 0 and frag-offset is > 0.
2042 * This packet is last fragment of fragmented packet.
2043 * This is not yet supported in MLX5, return appropriate
2046 if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
2047 frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
2048 return rte_flow_error_set(error, ENOTSUP,
2049 RTE_FLOW_ERROR_TYPE_ITEM_LAST,
2050 last, "match on last "
2051 "fragment not supported");
2052 /* Other range values are invalid and rejected. */
2053 return rte_flow_error_set(error, EINVAL,
2054 RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
2055 "specified range not supported");
2059 * Validate the pop VLAN action.
2062 * Pointer to the rte_eth_dev structure.
2063 * @param[in] action_flags
2064 * Holds the actions detected until now.
2066 * Pointer to the pop vlan action.
2067 * @param[in] item_flags
2068 * The items found in this flow rule.
2070 * Pointer to flow attributes.
2072 * Pointer to error structure.
2075 * 0 on success, a negative errno value otherwise and rte_errno is set.
2078 flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
2079 uint64_t action_flags,
2080 const struct rte_flow_action *action,
2081 uint64_t item_flags,
2082 const struct rte_flow_attr *attr,
2083 struct rte_flow_error *error)
2085 const struct mlx5_priv *priv = dev->data->dev_private;
2089 if (!priv->sh->pop_vlan_action)
2090 return rte_flow_error_set(error, ENOTSUP,
2091 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2093 "pop vlan action is not supported");
2095 return rte_flow_error_set(error, ENOTSUP,
2096 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2098 "pop vlan action not supported for "
2100 if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
2101 return rte_flow_error_set(error, ENOTSUP,
2102 RTE_FLOW_ERROR_TYPE_ACTION, action,
2103 "no support for multiple VLAN "
2105 /* Pop VLAN with preceding Decap requires inner header with VLAN. */
2106 if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
2107 !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
2108 return rte_flow_error_set(error, ENOTSUP,
2109 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2111 "cannot pop vlan after decap without "
2112 "match on inner vlan in the flow");
2113 /* Pop VLAN without preceding Decap requires outer header with VLAN. */
2114 if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
2115 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2116 return rte_flow_error_set(error, ENOTSUP,
2117 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2119 "cannot pop vlan without a "
2120 "match on (outer) vlan in the flow");
2121 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2122 return rte_flow_error_set(error, EINVAL,
2123 RTE_FLOW_ERROR_TYPE_ACTION, action,
2124 "wrong action order, port_id should "
2125 "be after pop VLAN action");
2126 if (!attr->transfer && priv->representor)
2127 return rte_flow_error_set(error, ENOTSUP,
2128 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2129 "pop vlan action for VF representor "
2130 "not supported on NIC table");
2135 * Get VLAN default info from vlan match info.
2138 * the list of item specifications.
2140 * pointer VLAN info to fill to.
2143 * 0 on success, a negative errno value otherwise and rte_errno is set.
2146 flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
2147 struct rte_vlan_hdr *vlan)
2149 const struct rte_flow_item_vlan nic_mask = {
2150 .tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
2151 MLX5DV_FLOW_VLAN_VID_MASK),
2152 .inner_type = RTE_BE16(0xffff),
2157 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
2158 int type = items->type;
2160 if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
2161 type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
2164 if (items->type != RTE_FLOW_ITEM_TYPE_END) {
2165 const struct rte_flow_item_vlan *vlan_m = items->mask;
2166 const struct rte_flow_item_vlan *vlan_v = items->spec;
2168 /* If VLAN item in pattern doesn't contain data, return here. */
2173 /* Only full match values are accepted */
2174 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
2175 MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
2176 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
2178 rte_be_to_cpu_16(vlan_v->tci &
2179 MLX5DV_FLOW_VLAN_PCP_MASK_BE);
2181 if ((vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
2182 MLX5DV_FLOW_VLAN_VID_MASK_BE) {
2183 vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
2185 rte_be_to_cpu_16(vlan_v->tci &
2186 MLX5DV_FLOW_VLAN_VID_MASK_BE);
2188 if (vlan_m->inner_type == nic_mask.inner_type)
2189 vlan->eth_proto = rte_be_to_cpu_16(vlan_v->inner_type &
2190 vlan_m->inner_type);
2195 * Validate the push VLAN action.
2198 * Pointer to the rte_eth_dev structure.
2199 * @param[in] action_flags
2200 * Holds the actions detected until now.
2201 * @param[in] item_flags
2202 * The items found in this flow rule.
2204 * Pointer to the action structure.
2206 * Pointer to flow attributes
2208 * Pointer to error structure.
2211 * 0 on success, a negative errno value otherwise and rte_errno is set.
2214 flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
2215 uint64_t action_flags,
2216 const struct rte_flow_item_vlan *vlan_m,
2217 const struct rte_flow_action *action,
2218 const struct rte_flow_attr *attr,
2219 struct rte_flow_error *error)
2221 const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
2222 const struct mlx5_priv *priv = dev->data->dev_private;
2224 if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
2225 push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
2226 return rte_flow_error_set(error, EINVAL,
2227 RTE_FLOW_ERROR_TYPE_ACTION, action,
2228 "invalid vlan ethertype");
2229 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2230 return rte_flow_error_set(error, EINVAL,
2231 RTE_FLOW_ERROR_TYPE_ACTION, action,
2232 "wrong action order, port_id should "
2233 "be after push VLAN");
2234 if (!attr->transfer && priv->representor)
2235 return rte_flow_error_set(error, ENOTSUP,
2236 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2237 "push vlan action for VF representor "
2238 "not supported on NIC table");
2240 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
2241 (vlan_m->tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
2242 MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
2243 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
2244 !(mlx5_flow_find_action
2245 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
2246 return rte_flow_error_set(error, EINVAL,
2247 RTE_FLOW_ERROR_TYPE_ACTION, action,
2248 "not full match mask on VLAN PCP and "
2249 "there is no of_set_vlan_pcp action, "
2250 "push VLAN action cannot figure out "
2253 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
2254 (vlan_m->tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
2255 MLX5DV_FLOW_VLAN_VID_MASK_BE &&
2256 !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
2257 !(mlx5_flow_find_action
2258 (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
2259 return rte_flow_error_set(error, EINVAL,
2260 RTE_FLOW_ERROR_TYPE_ACTION, action,
2261 "not full match mask on VLAN VID and "
2262 "there is no of_set_vlan_vid action, "
2263 "push VLAN action cannot figure out "
2270 * Validate the set VLAN PCP.
2272 * @param[in] action_flags
2273 * Holds the actions detected until now.
2274 * @param[in] actions
2275 * Pointer to the list of actions remaining in the flow rule.
2277 * Pointer to error structure.
2280 * 0 on success, a negative errno value otherwise and rte_errno is set.
2283 flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
2284 const struct rte_flow_action actions[],
2285 struct rte_flow_error *error)
2287 const struct rte_flow_action *action = actions;
2288 const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
2290 if (conf->vlan_pcp > 7)
2291 return rte_flow_error_set(error, EINVAL,
2292 RTE_FLOW_ERROR_TYPE_ACTION, action,
2293 "VLAN PCP value is too big");
2294 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
2295 return rte_flow_error_set(error, ENOTSUP,
2296 RTE_FLOW_ERROR_TYPE_ACTION, action,
2297 "set VLAN PCP action must follow "
2298 "the push VLAN action");
2299 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
2300 return rte_flow_error_set(error, ENOTSUP,
2301 RTE_FLOW_ERROR_TYPE_ACTION, action,
2302 "Multiple VLAN PCP modification are "
2304 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2305 return rte_flow_error_set(error, EINVAL,
2306 RTE_FLOW_ERROR_TYPE_ACTION, action,
2307 "wrong action order, port_id should "
2308 "be after set VLAN PCP");
2313 * Validate the set VLAN VID.
2315 * @param[in] item_flags
2316 * Holds the items detected in this rule.
2317 * @param[in] action_flags
2318 * Holds the actions detected until now.
2319 * @param[in] actions
2320 * Pointer to the list of actions remaining in the flow rule.
2322 * Pointer to error structure.
2325 * 0 on success, a negative errno value otherwise and rte_errno is set.
2328 flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
2329 uint64_t action_flags,
2330 const struct rte_flow_action actions[],
2331 struct rte_flow_error *error)
2333 const struct rte_flow_action *action = actions;
2334 const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
2336 if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
2337 return rte_flow_error_set(error, EINVAL,
2338 RTE_FLOW_ERROR_TYPE_ACTION, action,
2339 "VLAN VID value is too big");
2340 if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
2341 !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
2342 return rte_flow_error_set(error, ENOTSUP,
2343 RTE_FLOW_ERROR_TYPE_ACTION, action,
2344 "set VLAN VID action must follow push"
2345 " VLAN action or match on VLAN item");
2346 if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
2347 return rte_flow_error_set(error, ENOTSUP,
2348 RTE_FLOW_ERROR_TYPE_ACTION, action,
2349 "Multiple VLAN VID modifications are "
2351 if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
2352 return rte_flow_error_set(error, EINVAL,
2353 RTE_FLOW_ERROR_TYPE_ACTION, action,
2354 "wrong action order, port_id should "
2355 "be after set VLAN VID");
2360 * Validate the FLAG action.
2363 * Pointer to the rte_eth_dev structure.
2364 * @param[in] action_flags
2365 * Holds the actions detected until now.
2367 * Pointer to flow attributes
2369 * Pointer to error structure.
2372 * 0 on success, a negative errno value otherwise and rte_errno is set.
2375 flow_dv_validate_action_flag(struct rte_eth_dev *dev,
2376 uint64_t action_flags,
2377 const struct rte_flow_attr *attr,
2378 struct rte_flow_error *error)
2380 struct mlx5_priv *priv = dev->data->dev_private;
2381 struct mlx5_dev_config *config = &priv->config;
2384 /* Fall back if no extended metadata register support. */
2385 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2386 return mlx5_flow_validate_action_flag(action_flags, attr,
2388 /* Extensive metadata mode requires registers. */
2389 if (!mlx5_flow_ext_mreg_supported(dev))
2390 return rte_flow_error_set(error, ENOTSUP,
2391 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2392 "no metadata registers "
2393 "to support flag action");
2394 if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
2395 return rte_flow_error_set(error, ENOTSUP,
2396 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2397 "extended metadata register"
2398 " isn't available");
2399 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2402 MLX5_ASSERT(ret > 0);
2403 if (action_flags & MLX5_FLOW_ACTION_MARK)
2404 return rte_flow_error_set(error, EINVAL,
2405 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2406 "can't mark and flag in same flow");
2407 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2408 return rte_flow_error_set(error, EINVAL,
2409 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2411 " actions in same flow");
2416 * Validate MARK action.
2419 * Pointer to the rte_eth_dev structure.
2421 * Pointer to action.
2422 * @param[in] action_flags
2423 * Holds the actions detected until now.
2425 * Pointer to flow attributes
2427 * Pointer to error structure.
2430 * 0 on success, a negative errno value otherwise and rte_errno is set.
2433 flow_dv_validate_action_mark(struct rte_eth_dev *dev,
2434 const struct rte_flow_action *action,
2435 uint64_t action_flags,
2436 const struct rte_flow_attr *attr,
2437 struct rte_flow_error *error)
2439 struct mlx5_priv *priv = dev->data->dev_private;
2440 struct mlx5_dev_config *config = &priv->config;
2441 const struct rte_flow_action_mark *mark = action->conf;
2444 /* Fall back if no extended metadata register support. */
2445 if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2446 return mlx5_flow_validate_action_mark(action, action_flags,
2448 /* Extensive metadata mode requires registers. */
2449 if (!mlx5_flow_ext_mreg_supported(dev))
2450 return rte_flow_error_set(error, ENOTSUP,
2451 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2452 "no metadata registers "
2453 "to support mark action");
2454 if (!priv->sh->dv_mark_mask)
2455 return rte_flow_error_set(error, ENOTSUP,
2456 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2457 "extended metadata register"
2458 " isn't available");
2459 ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2462 MLX5_ASSERT(ret > 0);
2464 return rte_flow_error_set(error, EINVAL,
2465 RTE_FLOW_ERROR_TYPE_ACTION, action,
2466 "configuration cannot be null");
2467 if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
2468 return rte_flow_error_set(error, EINVAL,
2469 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2471 "mark id exceeds the limit");
2472 if (action_flags & MLX5_FLOW_ACTION_FLAG)
2473 return rte_flow_error_set(error, EINVAL,
2474 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2475 "can't flag and mark in same flow");
2476 if (action_flags & MLX5_FLOW_ACTION_MARK)
2477 return rte_flow_error_set(error, EINVAL,
2478 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2479 "can't have 2 mark actions in same"
2485 * Validate SET_META action.
2488 * Pointer to the rte_eth_dev structure.
2490 * Pointer to the action structure.
2491 * @param[in] action_flags
2492 * Holds the actions detected until now.
2494 * Pointer to flow attributes
2496 * Pointer to error structure.
2499 * 0 on success, a negative errno value otherwise and rte_errno is set.
2502 flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
2503 const struct rte_flow_action *action,
2504 uint64_t action_flags __rte_unused,
2505 const struct rte_flow_attr *attr,
2506 struct rte_flow_error *error)
2508 const struct rte_flow_action_set_meta *conf;
2509 uint32_t nic_mask = UINT32_MAX;
2512 if (!mlx5_flow_ext_mreg_supported(dev))
2513 return rte_flow_error_set(error, ENOTSUP,
2514 RTE_FLOW_ERROR_TYPE_ACTION, action,
2515 "extended metadata register"
2516 " isn't supported");
2517 reg = flow_dv_get_metadata_reg(dev, attr, error);
2521 return rte_flow_error_set(error, ENOTSUP,
2522 RTE_FLOW_ERROR_TYPE_ACTION, action,
2523 "unavalable extended metadata register");
2524 if (reg != REG_A && reg != REG_B) {
2525 struct mlx5_priv *priv = dev->data->dev_private;
2527 nic_mask = priv->sh->dv_meta_mask;
2529 if (!(action->conf))
2530 return rte_flow_error_set(error, EINVAL,
2531 RTE_FLOW_ERROR_TYPE_ACTION, action,
2532 "configuration cannot be null");
2533 conf = (const struct rte_flow_action_set_meta *)action->conf;
2535 return rte_flow_error_set(error, EINVAL,
2536 RTE_FLOW_ERROR_TYPE_ACTION, action,
2537 "zero mask doesn't have any effect");
2538 if (conf->mask & ~nic_mask)
2539 return rte_flow_error_set(error, EINVAL,
2540 RTE_FLOW_ERROR_TYPE_ACTION, action,
2541 "meta data must be within reg C0");
2546 * Validate SET_TAG action.
2549 * Pointer to the rte_eth_dev structure.
2551 * Pointer to the action structure.
2552 * @param[in] action_flags
2553 * Holds the actions detected until now.
2555 * Pointer to flow attributes
2557 * Pointer to error structure.
2560 * 0 on success, a negative errno value otherwise and rte_errno is set.
2563 flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
2564 const struct rte_flow_action *action,
2565 uint64_t action_flags,
2566 const struct rte_flow_attr *attr,
2567 struct rte_flow_error *error)
2569 const struct rte_flow_action_set_tag *conf;
2570 const uint64_t terminal_action_flags =
2571 MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
2572 MLX5_FLOW_ACTION_RSS;
2575 if (!mlx5_flow_ext_mreg_supported(dev))
2576 return rte_flow_error_set(error, ENOTSUP,
2577 RTE_FLOW_ERROR_TYPE_ACTION, action,
2578 "extensive metadata register"
2579 " isn't supported");
2580 if (!(action->conf))
2581 return rte_flow_error_set(error, EINVAL,
2582 RTE_FLOW_ERROR_TYPE_ACTION, action,
2583 "configuration cannot be null");
2584 conf = (const struct rte_flow_action_set_tag *)action->conf;
2586 return rte_flow_error_set(error, EINVAL,
2587 RTE_FLOW_ERROR_TYPE_ACTION, action,
2588 "zero mask doesn't have any effect");
2589 ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
2592 if (!attr->transfer && attr->ingress &&
2593 (action_flags & terminal_action_flags))
2594 return rte_flow_error_set(error, EINVAL,
2595 RTE_FLOW_ERROR_TYPE_ACTION, action,
2596 "set_tag has no effect"
2597 " with terminal actions");
2602 * Validate count action.
2605 * Pointer to rte_eth_dev structure.
2607 * Pointer to error structure.
2610 * 0 on success, a negative errno value otherwise and rte_errno is set.
2613 flow_dv_validate_action_count(struct rte_eth_dev *dev,
2614 struct rte_flow_error *error)
2616 struct mlx5_priv *priv = dev->data->dev_private;
2618 if (!priv->config.devx)
2620 #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
2624 return rte_flow_error_set
2626 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2628 "count action not supported");
2632 * Validate the L2 encap action.
2635 * Pointer to the rte_eth_dev structure.
2636 * @param[in] action_flags
2637 * Holds the actions detected until now.
2639 * Pointer to the action structure.
2641 * Pointer to flow attributes.
2643 * Pointer to error structure.
2646 * 0 on success, a negative errno value otherwise and rte_errno is set.
2649 flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
2650 uint64_t action_flags,
2651 const struct rte_flow_action *action,
2652 const struct rte_flow_attr *attr,
2653 struct rte_flow_error *error)
2655 const struct mlx5_priv *priv = dev->data->dev_private;
2657 if (!(action->conf))
2658 return rte_flow_error_set(error, EINVAL,
2659 RTE_FLOW_ERROR_TYPE_ACTION, action,
2660 "configuration cannot be null");
2661 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
2662 return rte_flow_error_set(error, EINVAL,
2663 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2664 "can only have a single encap action "
2666 if (!attr->transfer && priv->representor)
2667 return rte_flow_error_set(error, ENOTSUP,
2668 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2669 "encap action for VF representor "
2670 "not supported on NIC table");
2675 * Validate a decap action.
2678 * Pointer to the rte_eth_dev structure.
2679 * @param[in] action_flags
2680 * Holds the actions detected until now.
2682 * Pointer to the action structure.
2683 * @param[in] item_flags
2684 * Holds the items detected.
2686 * Pointer to flow attributes
2688 * Pointer to error structure.
2691 * 0 on success, a negative errno value otherwise and rte_errno is set.
2694 flow_dv_validate_action_decap(struct rte_eth_dev *dev,
2695 uint64_t action_flags,
2696 const struct rte_flow_action *action,
2697 const uint64_t item_flags,
2698 const struct rte_flow_attr *attr,
2699 struct rte_flow_error *error)
2701 const struct mlx5_priv *priv = dev->data->dev_private;
2703 if (priv->config.hca_attr.scatter_fcs_w_decap_disable &&
2704 !priv->config.decap_en)
2705 return rte_flow_error_set(error, ENOTSUP,
2706 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2707 "decap is not enabled");
2708 if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
2709 return rte_flow_error_set(error, ENOTSUP,
2710 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2712 MLX5_FLOW_ACTION_DECAP ? "can only "
2713 "have a single decap action" : "decap "
2714 "after encap is not supported");
2715 if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
2716 return rte_flow_error_set(error, EINVAL,
2717 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2718 "can't have decap action after"
2721 return rte_flow_error_set(error, ENOTSUP,
2722 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2724 "decap action not supported for "
2726 if (!attr->transfer && priv->representor)
2727 return rte_flow_error_set(error, ENOTSUP,
2728 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2729 "decap action for VF representor "
2730 "not supported on NIC table");
2731 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
2732 !(item_flags & MLX5_FLOW_LAYER_VXLAN))
2733 return rte_flow_error_set(error, ENOTSUP,
2734 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2735 "VXLAN item should be present for VXLAN decap");
2739 const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
2742 * Validate the raw encap and decap actions.
2745 * Pointer to the rte_eth_dev structure.
2747 * Pointer to the decap action.
2749 * Pointer to the encap action.
2751 * Pointer to flow attributes
2752 * @param[in/out] action_flags
2753 * Holds the actions detected until now.
2754 * @param[out] actions_n
2755 * pointer to the number of actions counter.
2757 * Pointer to the action structure.
2758 * @param[in] item_flags
2759 * Holds the items detected.
2761 * Pointer to error structure.
2764 * 0 on success, a negative errno value otherwise and rte_errno is set.
2767 flow_dv_validate_action_raw_encap_decap
2768 (struct rte_eth_dev *dev,
2769 const struct rte_flow_action_raw_decap *decap,
2770 const struct rte_flow_action_raw_encap *encap,
2771 const struct rte_flow_attr *attr, uint64_t *action_flags,
2772 int *actions_n, const struct rte_flow_action *action,
2773 uint64_t item_flags, struct rte_flow_error *error)
2775 const struct mlx5_priv *priv = dev->data->dev_private;
2778 if (encap && (!encap->size || !encap->data))
2779 return rte_flow_error_set(error, EINVAL,
2780 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2781 "raw encap data cannot be empty");
2782 if (decap && encap) {
2783 if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
2784 encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
2787 else if (encap->size <=
2788 MLX5_ENCAPSULATION_DECISION_SIZE &&
2790 MLX5_ENCAPSULATION_DECISION_SIZE)
2793 else if (encap->size >
2794 MLX5_ENCAPSULATION_DECISION_SIZE &&
2796 MLX5_ENCAPSULATION_DECISION_SIZE)
2797 /* 2 L2 actions: encap and decap. */
2800 return rte_flow_error_set(error,
2802 RTE_FLOW_ERROR_TYPE_ACTION,
2803 NULL, "unsupported too small "
2804 "raw decap and too small raw "
2805 "encap combination");
2808 ret = flow_dv_validate_action_decap(dev, *action_flags, action,
2809 item_flags, attr, error);
2812 *action_flags |= MLX5_FLOW_ACTION_DECAP;
2816 if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
2817 return rte_flow_error_set(error, ENOTSUP,
2818 RTE_FLOW_ERROR_TYPE_ACTION,
2820 "small raw encap size");
2821 if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
2822 return rte_flow_error_set(error, EINVAL,
2823 RTE_FLOW_ERROR_TYPE_ACTION,
2825 "more than one encap action");
2826 if (!attr->transfer && priv->representor)
2827 return rte_flow_error_set
2829 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2830 "encap action for VF representor "
2831 "not supported on NIC table");
2832 *action_flags |= MLX5_FLOW_ACTION_ENCAP;
2839 * Match encap_decap resource.
2842 * Pointer to the hash list.
2844 * Pointer to exist resource entry object.
2846 * Key of the new entry.
2848 * Pointer to new encap_decap resource.
2851 * 0 on matching, none-zero otherwise.
2854 flow_dv_encap_decap_match_cb(struct mlx5_hlist *list __rte_unused,
2855 struct mlx5_hlist_entry *entry,
2856 uint64_t key __rte_unused, void *cb_ctx)
2858 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
2859 struct mlx5_flow_dv_encap_decap_resource *resource = ctx->data;
2860 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
2862 cache_resource = container_of(entry,
2863 struct mlx5_flow_dv_encap_decap_resource,
2865 if (resource->reformat_type == cache_resource->reformat_type &&
2866 resource->ft_type == cache_resource->ft_type &&
2867 resource->flags == cache_resource->flags &&
2868 resource->size == cache_resource->size &&
2869 !memcmp((const void *)resource->buf,
2870 (const void *)cache_resource->buf,
2877 * Allocate encap_decap resource.
2880 * Pointer to the hash list.
2882 * Pointer to exist resource entry object.
2884 * Pointer to new encap_decap resource.
2887 * 0 on matching, none-zero otherwise.
2889 struct mlx5_hlist_entry *
2890 flow_dv_encap_decap_create_cb(struct mlx5_hlist *list,
2891 uint64_t key __rte_unused,
2894 struct mlx5_dev_ctx_shared *sh = list->ctx;
2895 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
2896 struct mlx5dv_dr_domain *domain;
2897 struct mlx5_flow_dv_encap_decap_resource *resource = ctx->data;
2898 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
2902 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
2903 domain = sh->fdb_domain;
2904 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
2905 domain = sh->rx_domain;
2907 domain = sh->tx_domain;
2908 /* Register new encap/decap resource. */
2909 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
2911 if (!cache_resource) {
2912 rte_flow_error_set(ctx->error, ENOMEM,
2913 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2914 "cannot allocate resource memory");
2917 *cache_resource = *resource;
2918 cache_resource->idx = idx;
2919 ret = mlx5_flow_os_create_flow_action_packet_reformat
2920 (sh->ctx, domain, cache_resource,
2921 &cache_resource->action);
2923 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
2924 rte_flow_error_set(ctx->error, ENOMEM,
2925 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2926 NULL, "cannot create action");
2930 return &cache_resource->entry;
2934 * Find existing encap/decap resource or create and register a new one.
2936 * @param[in, out] dev
2937 * Pointer to rte_eth_dev structure.
2938 * @param[in, out] resource
2939 * Pointer to encap/decap resource.
2940 * @parm[in, out] dev_flow
2941 * Pointer to the dev_flow.
2943 * pointer to error structure.
2946 * 0 on success otherwise -errno and errno is set.
2949 flow_dv_encap_decap_resource_register
2950 (struct rte_eth_dev *dev,
2951 struct mlx5_flow_dv_encap_decap_resource *resource,
2952 struct mlx5_flow *dev_flow,
2953 struct rte_flow_error *error)
2955 struct mlx5_priv *priv = dev->data->dev_private;
2956 struct mlx5_dev_ctx_shared *sh = priv->sh;
2957 struct mlx5_hlist_entry *entry;
2961 uint32_t refmt_type:8;
2963 * Header reformat actions can be shared between
2964 * non-root tables. One bit to indicate non-root
2968 uint32_t reserve:15;
2971 } encap_decap_key = {
2973 .ft_type = resource->ft_type,
2974 .refmt_type = resource->reformat_type,
2975 .is_root = !!dev_flow->dv.group,
2979 struct mlx5_flow_cb_ctx ctx = {
2985 resource->flags = dev_flow->dv.group ? 0 : 1;
2986 key64 = __rte_raw_cksum(&encap_decap_key.v32,
2987 sizeof(encap_decap_key.v32), 0);
2988 if (resource->reformat_type !=
2989 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
2991 key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
2992 entry = mlx5_hlist_register(sh->encaps_decaps, key64, &ctx);
2995 resource = container_of(entry, typeof(*resource), entry);
2996 dev_flow->dv.encap_decap = resource;
2997 dev_flow->handle->dvh.rix_encap_decap = resource->idx;
3002 * Find existing table jump resource or create and register a new one.
3004 * @param[in, out] dev
3005 * Pointer to rte_eth_dev structure.
3006 * @param[in, out] tbl
3007 * Pointer to flow table resource.
3008 * @parm[in, out] dev_flow
3009 * Pointer to the dev_flow.
3011 * pointer to error structure.
3014 * 0 on success otherwise -errno and errno is set.
3017 flow_dv_jump_tbl_resource_register
3018 (struct rte_eth_dev *dev __rte_unused,
3019 struct mlx5_flow_tbl_resource *tbl,
3020 struct mlx5_flow *dev_flow,
3021 struct rte_flow_error *error __rte_unused)
3023 struct mlx5_flow_tbl_data_entry *tbl_data =
3024 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
3027 MLX5_ASSERT(tbl_data->jump.action);
3028 dev_flow->handle->rix_jump = tbl_data->idx;
3029 dev_flow->dv.jump = &tbl_data->jump;
3034 flow_dv_port_id_match_cb(struct mlx5_cache_list *list __rte_unused,
3035 struct mlx5_cache_entry *entry, void *cb_ctx)
3037 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3038 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3039 struct mlx5_flow_dv_port_id_action_resource *res =
3040 container_of(entry, typeof(*res), entry);
3042 return ref->port_id != res->port_id;
3045 struct mlx5_cache_entry *
3046 flow_dv_port_id_create_cb(struct mlx5_cache_list *list,
3047 struct mlx5_cache_entry *entry __rte_unused,
3050 struct mlx5_dev_ctx_shared *sh = list->ctx;
3051 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3052 struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
3053 struct mlx5_flow_dv_port_id_action_resource *cache;
3057 /* Register new port id action resource. */
3058 cache = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
3060 rte_flow_error_set(ctx->error, ENOMEM,
3061 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3062 "cannot allocate port_id action cache memory");
3066 ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
3070 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
3071 rte_flow_error_set(ctx->error, ENOMEM,
3072 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3073 "cannot create action");
3076 return &cache->entry;
3080 * Find existing table port ID resource or create and register a new one.
3082 * @param[in, out] dev
3083 * Pointer to rte_eth_dev structure.
3084 * @param[in, out] resource
3085 * Pointer to port ID action resource.
3086 * @parm[in, out] dev_flow
3087 * Pointer to the dev_flow.
3089 * pointer to error structure.
3092 * 0 on success otherwise -errno and errno is set.
3095 flow_dv_port_id_action_resource_register
3096 (struct rte_eth_dev *dev,
3097 struct mlx5_flow_dv_port_id_action_resource *resource,
3098 struct mlx5_flow *dev_flow,
3099 struct rte_flow_error *error)
3101 struct mlx5_priv *priv = dev->data->dev_private;
3102 struct mlx5_cache_entry *entry;
3103 struct mlx5_flow_dv_port_id_action_resource *cache;
3104 struct mlx5_flow_cb_ctx ctx = {
3109 entry = mlx5_cache_register(&priv->sh->port_id_action_list, &ctx);
3112 cache = container_of(entry, typeof(*cache), entry);
3113 dev_flow->dv.port_id_action = cache;
3114 dev_flow->handle->rix_port_id_action = cache->idx;
3119 flow_dv_push_vlan_match_cb(struct mlx5_cache_list *list __rte_unused,
3120 struct mlx5_cache_entry *entry, void *cb_ctx)
3122 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3123 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3124 struct mlx5_flow_dv_push_vlan_action_resource *res =
3125 container_of(entry, typeof(*res), entry);
3127 return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
3130 struct mlx5_cache_entry *
3131 flow_dv_push_vlan_create_cb(struct mlx5_cache_list *list,
3132 struct mlx5_cache_entry *entry __rte_unused,
3135 struct mlx5_dev_ctx_shared *sh = list->ctx;
3136 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
3137 struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
3138 struct mlx5_flow_dv_push_vlan_action_resource *cache;
3139 struct mlx5dv_dr_domain *domain;
3143 /* Register new port id action resource. */
3144 cache = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
3146 rte_flow_error_set(ctx->error, ENOMEM,
3147 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3148 "cannot allocate push_vlan action cache memory");
3152 if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
3153 domain = sh->fdb_domain;
3154 else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
3155 domain = sh->rx_domain;
3157 domain = sh->tx_domain;
3158 ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
3161 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
3162 rte_flow_error_set(ctx->error, ENOMEM,
3163 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3164 "cannot create push vlan action");
3167 return &cache->entry;
3171 * Find existing push vlan resource or create and register a new one.
3173 * @param [in, out] dev
3174 * Pointer to rte_eth_dev structure.
3175 * @param[in, out] resource
3176 * Pointer to port ID action resource.
3177 * @parm[in, out] dev_flow
3178 * Pointer to the dev_flow.
3180 * pointer to error structure.
3183 * 0 on success otherwise -errno and errno is set.
3186 flow_dv_push_vlan_action_resource_register
3187 (struct rte_eth_dev *dev,
3188 struct mlx5_flow_dv_push_vlan_action_resource *resource,
3189 struct mlx5_flow *dev_flow,
3190 struct rte_flow_error *error)
3192 struct mlx5_priv *priv = dev->data->dev_private;
3193 struct mlx5_flow_dv_push_vlan_action_resource *cache;
3194 struct mlx5_cache_entry *entry;
3195 struct mlx5_flow_cb_ctx ctx = {
3200 entry = mlx5_cache_register(&priv->sh->push_vlan_action_list, &ctx);
3203 cache = container_of(entry, typeof(*cache), entry);
3205 dev_flow->handle->dvh.rix_push_vlan = cache->idx;
3206 dev_flow->dv.push_vlan_res = cache;
3211 * Get the size of specific rte_flow_item_type hdr size
3213 * @param[in] item_type
3214 * Tested rte_flow_item_type.
3217 * sizeof struct item_type, 0 if void or irrelevant.
3220 flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
3224 switch (item_type) {
3225 case RTE_FLOW_ITEM_TYPE_ETH:
3226 retval = sizeof(struct rte_ether_hdr);
3228 case RTE_FLOW_ITEM_TYPE_VLAN:
3229 retval = sizeof(struct rte_vlan_hdr);
3231 case RTE_FLOW_ITEM_TYPE_IPV4:
3232 retval = sizeof(struct rte_ipv4_hdr);
3234 case RTE_FLOW_ITEM_TYPE_IPV6:
3235 retval = sizeof(struct rte_ipv6_hdr);
3237 case RTE_FLOW_ITEM_TYPE_UDP:
3238 retval = sizeof(struct rte_udp_hdr);
3240 case RTE_FLOW_ITEM_TYPE_TCP:
3241 retval = sizeof(struct rte_tcp_hdr);
3243 case RTE_FLOW_ITEM_TYPE_VXLAN:
3244 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
3245 retval = sizeof(struct rte_vxlan_hdr);
3247 case RTE_FLOW_ITEM_TYPE_GRE:
3248 case RTE_FLOW_ITEM_TYPE_NVGRE:
3249 retval = sizeof(struct rte_gre_hdr);
3251 case RTE_FLOW_ITEM_TYPE_MPLS:
3252 retval = sizeof(struct rte_mpls_hdr);
3254 case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
3262 #define MLX5_ENCAP_IPV4_VERSION 0x40
3263 #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
3264 #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
3265 #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
3266 #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
3267 #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
3268 #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
3271 * Convert the encap action data from list of rte_flow_item to raw buffer
3274 * Pointer to rte_flow_item objects list.
3276 * Pointer to the output buffer.
3278 * Pointer to the output buffer size.
3280 * Pointer to the error structure.
3283 * 0 on success, a negative errno value otherwise and rte_errno is set.
3286 flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
3287 size_t *size, struct rte_flow_error *error)
3289 struct rte_ether_hdr *eth = NULL;
3290 struct rte_vlan_hdr *vlan = NULL;
3291 struct rte_ipv4_hdr *ipv4 = NULL;
3292 struct rte_ipv6_hdr *ipv6 = NULL;
3293 struct rte_udp_hdr *udp = NULL;
3294 struct rte_vxlan_hdr *vxlan = NULL;
3295 struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
3296 struct rte_gre_hdr *gre = NULL;
3298 size_t temp_size = 0;
3301 return rte_flow_error_set(error, EINVAL,
3302 RTE_FLOW_ERROR_TYPE_ACTION,
3303 NULL, "invalid empty data");
3304 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3305 len = flow_dv_get_item_hdr_len(items->type);
3306 if (len + temp_size > MLX5_ENCAP_MAX_LEN)
3307 return rte_flow_error_set(error, EINVAL,
3308 RTE_FLOW_ERROR_TYPE_ACTION,
3309 (void *)items->type,
3310 "items total size is too big"
3311 " for encap action");
3312 rte_memcpy((void *)&buf[temp_size], items->spec, len);
3313 switch (items->type) {
3314 case RTE_FLOW_ITEM_TYPE_ETH:
3315 eth = (struct rte_ether_hdr *)&buf[temp_size];
3317 case RTE_FLOW_ITEM_TYPE_VLAN:
3318 vlan = (struct rte_vlan_hdr *)&buf[temp_size];
3320 return rte_flow_error_set(error, EINVAL,
3321 RTE_FLOW_ERROR_TYPE_ACTION,
3322 (void *)items->type,
3323 "eth header not found");
3324 if (!eth->ether_type)
3325 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
3327 case RTE_FLOW_ITEM_TYPE_IPV4:
3328 ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
3330 return rte_flow_error_set(error, EINVAL,
3331 RTE_FLOW_ERROR_TYPE_ACTION,
3332 (void *)items->type,
3333 "neither eth nor vlan"
3335 if (vlan && !vlan->eth_proto)
3336 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3337 else if (eth && !eth->ether_type)
3338 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3339 if (!ipv4->version_ihl)
3340 ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
3341 MLX5_ENCAP_IPV4_IHL_MIN;
3342 if (!ipv4->time_to_live)
3343 ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
3345 case RTE_FLOW_ITEM_TYPE_IPV6:
3346 ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
3348 return rte_flow_error_set(error, EINVAL,
3349 RTE_FLOW_ERROR_TYPE_ACTION,
3350 (void *)items->type,
3351 "neither eth nor vlan"
3353 if (vlan && !vlan->eth_proto)
3354 vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3355 else if (eth && !eth->ether_type)
3356 eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3357 if (!ipv6->vtc_flow)
3359 RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
3360 if (!ipv6->hop_limits)
3361 ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
3363 case RTE_FLOW_ITEM_TYPE_UDP:
3364 udp = (struct rte_udp_hdr *)&buf[temp_size];
3366 return rte_flow_error_set(error, EINVAL,
3367 RTE_FLOW_ERROR_TYPE_ACTION,
3368 (void *)items->type,
3369 "ip header not found");
3370 if (ipv4 && !ipv4->next_proto_id)
3371 ipv4->next_proto_id = IPPROTO_UDP;
3372 else if (ipv6 && !ipv6->proto)
3373 ipv6->proto = IPPROTO_UDP;
3375 case RTE_FLOW_ITEM_TYPE_VXLAN:
3376 vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
3378 return rte_flow_error_set(error, EINVAL,
3379 RTE_FLOW_ERROR_TYPE_ACTION,
3380 (void *)items->type,
3381 "udp header not found");
3383 udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
3384 if (!vxlan->vx_flags)
3386 RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
3388 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
3389 vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
3391 return rte_flow_error_set(error, EINVAL,
3392 RTE_FLOW_ERROR_TYPE_ACTION,
3393 (void *)items->type,
3394 "udp header not found");
3395 if (!vxlan_gpe->proto)
3396 return rte_flow_error_set(error, EINVAL,
3397 RTE_FLOW_ERROR_TYPE_ACTION,
3398 (void *)items->type,
3399 "next protocol not found");
3402 RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
3403 if (!vxlan_gpe->vx_flags)
3404 vxlan_gpe->vx_flags =
3405 MLX5_ENCAP_VXLAN_GPE_FLAGS;
3407 case RTE_FLOW_ITEM_TYPE_GRE:
3408 case RTE_FLOW_ITEM_TYPE_NVGRE:
3409 gre = (struct rte_gre_hdr *)&buf[temp_size];
3411 return rte_flow_error_set(error, EINVAL,
3412 RTE_FLOW_ERROR_TYPE_ACTION,
3413 (void *)items->type,
3414 "next protocol not found");
3416 return rte_flow_error_set(error, EINVAL,
3417 RTE_FLOW_ERROR_TYPE_ACTION,
3418 (void *)items->type,
3419 "ip header not found");
3420 if (ipv4 && !ipv4->next_proto_id)
3421 ipv4->next_proto_id = IPPROTO_GRE;
3422 else if (ipv6 && !ipv6->proto)
3423 ipv6->proto = IPPROTO_GRE;
3425 case RTE_FLOW_ITEM_TYPE_VOID:
3428 return rte_flow_error_set(error, EINVAL,
3429 RTE_FLOW_ERROR_TYPE_ACTION,
3430 (void *)items->type,
3431 "unsupported item type");
3441 flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
3443 struct rte_ether_hdr *eth = NULL;
3444 struct rte_vlan_hdr *vlan = NULL;
3445 struct rte_ipv6_hdr *ipv6 = NULL;
3446 struct rte_udp_hdr *udp = NULL;
3450 eth = (struct rte_ether_hdr *)data;
3451 next_hdr = (char *)(eth + 1);
3452 proto = RTE_BE16(eth->ether_type);
3455 while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
3456 vlan = (struct rte_vlan_hdr *)next_hdr;
3457 proto = RTE_BE16(vlan->eth_proto);
3458 next_hdr += sizeof(struct rte_vlan_hdr);
3461 /* HW calculates IPv4 csum. no need to proceed */
3462 if (proto == RTE_ETHER_TYPE_IPV4)
3465 /* non IPv4/IPv6 header. not supported */
3466 if (proto != RTE_ETHER_TYPE_IPV6) {
3467 return rte_flow_error_set(error, ENOTSUP,
3468 RTE_FLOW_ERROR_TYPE_ACTION,
3469 NULL, "Cannot offload non IPv4/IPv6");
3472 ipv6 = (struct rte_ipv6_hdr *)next_hdr;
3474 /* ignore non UDP */
3475 if (ipv6->proto != IPPROTO_UDP)
3478 udp = (struct rte_udp_hdr *)(ipv6 + 1);
3479 udp->dgram_cksum = 0;
3485 * Convert L2 encap action to DV specification.
3488 * Pointer to rte_eth_dev structure.
3490 * Pointer to action structure.
3491 * @param[in, out] dev_flow
3492 * Pointer to the mlx5_flow.
3493 * @param[in] transfer
3494 * Mark if the flow is E-Switch flow.
3496 * Pointer to the error structure.
3499 * 0 on success, a negative errno value otherwise and rte_errno is set.
3502 flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
3503 const struct rte_flow_action *action,
3504 struct mlx5_flow *dev_flow,
3506 struct rte_flow_error *error)
3508 const struct rte_flow_item *encap_data;
3509 const struct rte_flow_action_raw_encap *raw_encap_data;
3510 struct mlx5_flow_dv_encap_decap_resource res = {
3512 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
3513 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
3514 MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
3517 if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
3519 (const struct rte_flow_action_raw_encap *)action->conf;
3520 res.size = raw_encap_data->size;
3521 memcpy(res.buf, raw_encap_data->data, res.size);
3523 if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
3525 ((const struct rte_flow_action_vxlan_encap *)
3526 action->conf)->definition;
3529 ((const struct rte_flow_action_nvgre_encap *)
3530 action->conf)->definition;
3531 if (flow_dv_convert_encap_data(encap_data, res.buf,
3535 if (flow_dv_zero_encap_udp_csum(res.buf, error))
3537 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3538 return rte_flow_error_set(error, EINVAL,
3539 RTE_FLOW_ERROR_TYPE_ACTION,
3540 NULL, "can't create L2 encap action");
3545 * Convert L2 decap action to DV specification.
3548 * Pointer to rte_eth_dev structure.
3549 * @param[in, out] dev_flow
3550 * Pointer to the mlx5_flow.
3551 * @param[in] transfer
3552 * Mark if the flow is E-Switch flow.
3554 * Pointer to the error structure.
3557 * 0 on success, a negative errno value otherwise and rte_errno is set.
3560 flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
3561 struct mlx5_flow *dev_flow,
3563 struct rte_flow_error *error)
3565 struct mlx5_flow_dv_encap_decap_resource res = {
3568 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
3569 .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
3570 MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
3573 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3574 return rte_flow_error_set(error, EINVAL,
3575 RTE_FLOW_ERROR_TYPE_ACTION,
3576 NULL, "can't create L2 decap action");
3581 * Convert raw decap/encap (L3 tunnel) action to DV specification.
3584 * Pointer to rte_eth_dev structure.
3586 * Pointer to action structure.
3587 * @param[in, out] dev_flow
3588 * Pointer to the mlx5_flow.
3590 * Pointer to the flow attributes.
3592 * Pointer to the error structure.
3595 * 0 on success, a negative errno value otherwise and rte_errno is set.
3598 flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
3599 const struct rte_flow_action *action,
3600 struct mlx5_flow *dev_flow,
3601 const struct rte_flow_attr *attr,
3602 struct rte_flow_error *error)
3604 const struct rte_flow_action_raw_encap *encap_data;
3605 struct mlx5_flow_dv_encap_decap_resource res;
3607 memset(&res, 0, sizeof(res));
3608 encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
3609 res.size = encap_data->size;
3610 memcpy(res.buf, encap_data->data, res.size);
3611 res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
3612 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
3613 MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
3615 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3617 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3618 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3619 if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
3620 return rte_flow_error_set(error, EINVAL,
3621 RTE_FLOW_ERROR_TYPE_ACTION,
3622 NULL, "can't create encap action");
3627 * Create action push VLAN.
3630 * Pointer to rte_eth_dev structure.
3632 * Pointer to the flow attributes.
3634 * Pointer to the vlan to push to the Ethernet header.
3635 * @param[in, out] dev_flow
3636 * Pointer to the mlx5_flow.
3638 * Pointer to the error structure.
3641 * 0 on success, a negative errno value otherwise and rte_errno is set.
3644 flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
3645 const struct rte_flow_attr *attr,
3646 const struct rte_vlan_hdr *vlan,
3647 struct mlx5_flow *dev_flow,
3648 struct rte_flow_error *error)
3650 struct mlx5_flow_dv_push_vlan_action_resource res;
3652 memset(&res, 0, sizeof(res));
3654 rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
3657 res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
3659 res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
3660 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
3661 return flow_dv_push_vlan_action_resource_register
3662 (dev, &res, dev_flow, error);
3665 static int fdb_mirror;
3668 * Validate the modify-header actions.
3670 * @param[in] action_flags
3671 * Holds the actions detected until now.
3673 * Pointer to the modify action.
3675 * Pointer to error structure.
3678 * 0 on success, a negative errno value otherwise and rte_errno is set.
3681 flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
3682 const struct rte_flow_action *action,
3683 struct rte_flow_error *error)
3685 if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
3686 return rte_flow_error_set(error, EINVAL,
3687 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3688 NULL, "action configuration not set");
3689 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3690 return rte_flow_error_set(error, EINVAL,
3691 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3692 "can't have encap action before"
3694 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) && fdb_mirror)
3695 return rte_flow_error_set(error, EINVAL,
3696 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3697 "can't support sample action before"
3698 " modify action for E-Switch"
3704 * Validate the modify-header MAC address actions.
3706 * @param[in] action_flags
3707 * Holds the actions detected until now.
3709 * Pointer to the modify action.
3710 * @param[in] item_flags
3711 * Holds the items detected.
3713 * Pointer to error structure.
3716 * 0 on success, a negative errno value otherwise and rte_errno is set.
3719 flow_dv_validate_action_modify_mac(const uint64_t action_flags,
3720 const struct rte_flow_action *action,
3721 const uint64_t item_flags,
3722 struct rte_flow_error *error)
3726 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3728 if (!(item_flags & MLX5_FLOW_LAYER_L2))
3729 return rte_flow_error_set(error, EINVAL,
3730 RTE_FLOW_ERROR_TYPE_ACTION,
3732 "no L2 item in pattern");
3738 * Validate the modify-header IPv4 address actions.
3740 * @param[in] action_flags
3741 * Holds the actions detected until now.
3743 * Pointer to the modify action.
3744 * @param[in] item_flags
3745 * Holds the items detected.
3747 * Pointer to error structure.
3750 * 0 on success, a negative errno value otherwise and rte_errno is set.
3753 flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
3754 const struct rte_flow_action *action,
3755 const uint64_t item_flags,
3756 struct rte_flow_error *error)
3761 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3763 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3764 MLX5_FLOW_LAYER_INNER_L3_IPV4 :
3765 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
3766 if (!(item_flags & layer))
3767 return rte_flow_error_set(error, EINVAL,
3768 RTE_FLOW_ERROR_TYPE_ACTION,
3770 "no ipv4 item in pattern");
3776 * Validate the modify-header IPv6 address actions.
3778 * @param[in] action_flags
3779 * Holds the actions detected until now.
3781 * Pointer to the modify action.
3782 * @param[in] item_flags
3783 * Holds the items detected.
3785 * Pointer to error structure.
3788 * 0 on success, a negative errno value otherwise and rte_errno is set.
3791 flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
3792 const struct rte_flow_action *action,
3793 const uint64_t item_flags,
3794 struct rte_flow_error *error)
3799 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3801 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3802 MLX5_FLOW_LAYER_INNER_L3_IPV6 :
3803 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
3804 if (!(item_flags & layer))
3805 return rte_flow_error_set(error, EINVAL,
3806 RTE_FLOW_ERROR_TYPE_ACTION,
3808 "no ipv6 item in pattern");
3814 * Validate the modify-header TP actions.
3816 * @param[in] action_flags
3817 * Holds the actions detected until now.
3819 * Pointer to the modify action.
3820 * @param[in] item_flags
3821 * Holds the items detected.
3823 * Pointer to error structure.
3826 * 0 on success, a negative errno value otherwise and rte_errno is set.
3829 flow_dv_validate_action_modify_tp(const uint64_t action_flags,
3830 const struct rte_flow_action *action,
3831 const uint64_t item_flags,
3832 struct rte_flow_error *error)
3837 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3839 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3840 MLX5_FLOW_LAYER_INNER_L4 :
3841 MLX5_FLOW_LAYER_OUTER_L4;
3842 if (!(item_flags & layer))
3843 return rte_flow_error_set(error, EINVAL,
3844 RTE_FLOW_ERROR_TYPE_ACTION,
3845 NULL, "no transport layer "
3852 * Validate the modify-header actions of increment/decrement
3853 * TCP Sequence-number.
3855 * @param[in] action_flags
3856 * Holds the actions detected until now.
3858 * Pointer to the modify action.
3859 * @param[in] item_flags
3860 * Holds the items detected.
3862 * Pointer to error structure.
3865 * 0 on success, a negative errno value otherwise and rte_errno is set.
3868 flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
3869 const struct rte_flow_action *action,
3870 const uint64_t item_flags,
3871 struct rte_flow_error *error)
3876 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3878 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3879 MLX5_FLOW_LAYER_INNER_L4_TCP :
3880 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3881 if (!(item_flags & layer))
3882 return rte_flow_error_set(error, EINVAL,
3883 RTE_FLOW_ERROR_TYPE_ACTION,
3884 NULL, "no TCP item in"
3886 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
3887 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
3888 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
3889 (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
3890 return rte_flow_error_set(error, EINVAL,
3891 RTE_FLOW_ERROR_TYPE_ACTION,
3893 "cannot decrease and increase"
3894 " TCP sequence number"
3895 " at the same time");
3901 * Validate the modify-header actions of increment/decrement
3902 * TCP Acknowledgment number.
3904 * @param[in] action_flags
3905 * Holds the actions detected until now.
3907 * Pointer to the modify action.
3908 * @param[in] item_flags
3909 * Holds the items detected.
3911 * Pointer to error structure.
3914 * 0 on success, a negative errno value otherwise and rte_errno is set.
3917 flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
3918 const struct rte_flow_action *action,
3919 const uint64_t item_flags,
3920 struct rte_flow_error *error)
3925 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3927 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3928 MLX5_FLOW_LAYER_INNER_L4_TCP :
3929 MLX5_FLOW_LAYER_OUTER_L4_TCP;
3930 if (!(item_flags & layer))
3931 return rte_flow_error_set(error, EINVAL,
3932 RTE_FLOW_ERROR_TYPE_ACTION,
3933 NULL, "no TCP item in"
3935 if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
3936 (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
3937 (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
3938 (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
3939 return rte_flow_error_set(error, EINVAL,
3940 RTE_FLOW_ERROR_TYPE_ACTION,
3942 "cannot decrease and increase"
3943 " TCP acknowledgment number"
3944 " at the same time");
3950 * Validate the modify-header TTL actions.
3952 * @param[in] action_flags
3953 * Holds the actions detected until now.
3955 * Pointer to the modify action.
3956 * @param[in] item_flags
3957 * Holds the items detected.
3959 * Pointer to error structure.
3962 * 0 on success, a negative errno value otherwise and rte_errno is set.
3965 flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
3966 const struct rte_flow_action *action,
3967 const uint64_t item_flags,
3968 struct rte_flow_error *error)
3973 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
3975 layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
3976 MLX5_FLOW_LAYER_INNER_L3 :
3977 MLX5_FLOW_LAYER_OUTER_L3;
3978 if (!(item_flags & layer))
3979 return rte_flow_error_set(error, EINVAL,
3980 RTE_FLOW_ERROR_TYPE_ACTION,
3982 "no IP protocol in pattern");
3988 * Validate jump action.
3991 * Pointer to the jump action.
3992 * @param[in] action_flags
3993 * Holds the actions detected until now.
3994 * @param[in] attributes
3995 * Pointer to flow attributes
3996 * @param[in] external
3997 * Action belongs to flow rule created by request external to PMD.
3999 * Pointer to error structure.
4002 * 0 on success, a negative errno value otherwise and rte_errno is set.
4005 flow_dv_validate_action_jump(struct rte_eth_dev *dev,
4006 const struct mlx5_flow_tunnel *tunnel,
4007 const struct rte_flow_action *action,
4008 uint64_t action_flags,
4009 const struct rte_flow_attr *attributes,
4010 bool external, struct rte_flow_error *error)
4012 uint32_t target_group, table;
4014 struct flow_grp_info grp_info = {
4015 .external = !!external,
4016 .transfer = !!attributes->transfer,
4020 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4021 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4022 return rte_flow_error_set(error, EINVAL,
4023 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4024 "can't have 2 fate actions in"
4026 if (action_flags & MLX5_FLOW_ACTION_METER)
4027 return rte_flow_error_set(error, ENOTSUP,
4028 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4029 "jump with meter not support");
4030 if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) && fdb_mirror)
4031 return rte_flow_error_set(error, EINVAL,
4032 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4033 "E-Switch mirroring can't support"
4034 " Sample action and jump action in"
4037 return rte_flow_error_set(error, EINVAL,
4038 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4039 NULL, "action configuration not set");
4041 ((const struct rte_flow_action_jump *)action->conf)->group;
4042 ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
4046 if (attributes->group == target_group &&
4047 !(action_flags & (MLX5_FLOW_ACTION_TUNNEL_SET |
4048 MLX5_FLOW_ACTION_TUNNEL_MATCH)))
4049 return rte_flow_error_set(error, EINVAL,
4050 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4051 "target group must be other than"
4052 " the current flow group");
4057 * Validate the port_id action.
4060 * Pointer to rte_eth_dev structure.
4061 * @param[in] action_flags
4062 * Bit-fields that holds the actions detected until now.
4064 * Port_id RTE action structure.
4066 * Attributes of flow that includes this action.
4068 * Pointer to error structure.
4071 * 0 on success, a negative errno value otherwise and rte_errno is set.
4074 flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
4075 uint64_t action_flags,
4076 const struct rte_flow_action *action,
4077 const struct rte_flow_attr *attr,
4078 struct rte_flow_error *error)
4080 const struct rte_flow_action_port_id *port_id;
4081 struct mlx5_priv *act_priv;
4082 struct mlx5_priv *dev_priv;
4085 if (!attr->transfer)
4086 return rte_flow_error_set(error, ENOTSUP,
4087 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4089 "port id action is valid in transfer"
4091 if (!action || !action->conf)
4092 return rte_flow_error_set(error, ENOTSUP,
4093 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4095 "port id action parameters must be"
4097 if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
4098 MLX5_FLOW_FATE_ESWITCH_ACTIONS))
4099 return rte_flow_error_set(error, EINVAL,
4100 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4101 "can have only one fate actions in"
4103 dev_priv = mlx5_dev_to_eswitch_info(dev);
4105 return rte_flow_error_set(error, rte_errno,
4106 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4108 "failed to obtain E-Switch info");
4109 port_id = action->conf;
4110 port = port_id->original ? dev->data->port_id : port_id->id;
4111 act_priv = mlx5_port_to_eswitch_info(port, false);
4113 return rte_flow_error_set
4115 RTE_FLOW_ERROR_TYPE_ACTION_CONF, port_id,
4116 "failed to obtain E-Switch port id for port");
4117 if (act_priv->domain_id != dev_priv->domain_id)
4118 return rte_flow_error_set
4120 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4121 "port does not belong to"
4122 " E-Switch being configured");
4127 * Get the maximum number of modify header actions.
4130 * Pointer to rte_eth_dev structure.
4132 * Flags bits to check if root level.
4135 * Max number of modify header actions device can support.
4137 static inline unsigned int
4138 flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
4142 * There's no way to directly query the max capacity from FW.
4143 * The maximal value on root table should be assumed to be supported.
4145 if (!(flags & MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL))
4146 return MLX5_MAX_MODIFY_NUM;
4148 return MLX5_ROOT_TBL_MODIFY_NUM;
4152 * Validate the meter action.
4155 * Pointer to rte_eth_dev structure.
4156 * @param[in] action_flags
4157 * Bit-fields that holds the actions detected until now.
4159 * Pointer to the meter action.
4161 * Attributes of flow that includes this action.
4163 * Pointer to error structure.
4166 * 0 on success, a negative errno value otherwise and rte_ernno is set.
4169 mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
4170 uint64_t action_flags,
4171 const struct rte_flow_action *action,
4172 const struct rte_flow_attr *attr,
4173 struct rte_flow_error *error)
4175 struct mlx5_priv *priv = dev->data->dev_private;
4176 const struct rte_flow_action_meter *am = action->conf;
4177 struct mlx5_flow_meter *fm;
4180 return rte_flow_error_set(error, EINVAL,
4181 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4182 "meter action conf is NULL");
4184 if (action_flags & MLX5_FLOW_ACTION_METER)
4185 return rte_flow_error_set(error, ENOTSUP,
4186 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4187 "meter chaining not support");
4188 if (action_flags & MLX5_FLOW_ACTION_JUMP)
4189 return rte_flow_error_set(error, ENOTSUP,
4190 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4191 "meter with jump not support");
4193 return rte_flow_error_set(error, ENOTSUP,
4194 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4196 "meter action not supported");
4197 fm = mlx5_flow_meter_find(priv, am->mtr_id);
4199 return rte_flow_error_set(error, EINVAL,
4200 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4202 if (fm->ref_cnt && (!(fm->transfer == attr->transfer ||
4203 (!fm->ingress && !attr->ingress && attr->egress) ||
4204 (!fm->egress && !attr->egress && attr->ingress))))
4205 return rte_flow_error_set(error, EINVAL,
4206 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4207 "Flow attributes are either invalid "
4208 "or have a conflict with current "
4209 "meter attributes");
4214 * Validate the age action.
4216 * @param[in] action_flags
4217 * Holds the actions detected until now.
4219 * Pointer to the age action.
4221 * Pointer to the Ethernet device structure.
4223 * Pointer to error structure.
4226 * 0 on success, a negative errno value otherwise and rte_errno is set.
4229 flow_dv_validate_action_age(uint64_t action_flags,
4230 const struct rte_flow_action *action,
4231 struct rte_eth_dev *dev,
4232 struct rte_flow_error *error)
4234 struct mlx5_priv *priv = dev->data->dev_private;
4235 const struct rte_flow_action_age *age = action->conf;
4237 if (!priv->config.devx || (priv->sh->cmng.counter_fallback &&
4238 !priv->sh->aso_age_mng))
4239 return rte_flow_error_set(error, ENOTSUP,
4240 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4242 "age action not supported");
4243 if (!(action->conf))
4244 return rte_flow_error_set(error, EINVAL,
4245 RTE_FLOW_ERROR_TYPE_ACTION, action,
4246 "configuration cannot be null");
4247 if (!(age->timeout))
4248 return rte_flow_error_set(error, EINVAL,
4249 RTE_FLOW_ERROR_TYPE_ACTION, action,
4250 "invalid timeout value 0");
4251 if (action_flags & MLX5_FLOW_ACTION_AGE)
4252 return rte_flow_error_set(error, EINVAL,
4253 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4254 "duplicate age actions set");
4259 * Validate the modify-header IPv4 DSCP actions.
4261 * @param[in] action_flags
4262 * Holds the actions detected until now.
4264 * Pointer to the modify action.
4265 * @param[in] item_flags
4266 * Holds the items detected.
4268 * Pointer to error structure.
4271 * 0 on success, a negative errno value otherwise and rte_errno is set.
4274 flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
4275 const struct rte_flow_action *action,
4276 const uint64_t item_flags,
4277 struct rte_flow_error *error)
4281 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4283 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
4284 return rte_flow_error_set(error, EINVAL,
4285 RTE_FLOW_ERROR_TYPE_ACTION,
4287 "no ipv4 item in pattern");
4293 * Validate the modify-header IPv6 DSCP actions.
4295 * @param[in] action_flags
4296 * Holds the actions detected until now.
4298 * Pointer to the modify action.
4299 * @param[in] item_flags
4300 * Holds the items detected.
4302 * Pointer to error structure.
4305 * 0 on success, a negative errno value otherwise and rte_errno is set.
4308 flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
4309 const struct rte_flow_action *action,
4310 const uint64_t item_flags,
4311 struct rte_flow_error *error)
4315 ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
4317 if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
4318 return rte_flow_error_set(error, EINVAL,
4319 RTE_FLOW_ERROR_TYPE_ACTION,
4321 "no ipv6 item in pattern");
4327 * Match modify-header resource.
4330 * Pointer to the hash list.
4332 * Pointer to exist resource entry object.
4334 * Key of the new entry.
4336 * Pointer to new modify-header resource.
4339 * 0 on matching, non-zero otherwise.
4342 flow_dv_modify_match_cb(struct mlx5_hlist *list __rte_unused,
4343 struct mlx5_hlist_entry *entry,
4344 uint64_t key __rte_unused, void *cb_ctx)
4346 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4347 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
4348 struct mlx5_flow_dv_modify_hdr_resource *resource =
4349 container_of(entry, typeof(*resource), entry);
4350 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
4352 key_len += ref->actions_num * sizeof(ref->actions[0]);
4353 return ref->actions_num != resource->actions_num ||
4354 memcmp(&ref->ft_type, &resource->ft_type, key_len);
4357 struct mlx5_hlist_entry *
4358 flow_dv_modify_create_cb(struct mlx5_hlist *list, uint64_t key __rte_unused,
4361 struct mlx5_dev_ctx_shared *sh = list->ctx;
4362 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4363 struct mlx5dv_dr_domain *ns;
4364 struct mlx5_flow_dv_modify_hdr_resource *entry;
4365 struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
4367 uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
4368 uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
4370 entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry) + data_len, 0,
4373 rte_flow_error_set(ctx->error, ENOMEM,
4374 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4375 "cannot allocate resource memory");
4378 rte_memcpy(&entry->ft_type,
4379 RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
4380 key_len + data_len);
4381 if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4382 ns = sh->fdb_domain;
4383 else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
4387 ret = mlx5_flow_os_create_flow_action_modify_header
4388 (sh->ctx, ns, entry,
4389 data_len, &entry->action);
4392 rte_flow_error_set(ctx->error, ENOMEM,
4393 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4394 NULL, "cannot create modification action");
4397 return &entry->entry;
4401 * Validate the sample action.
4403 * @param[in] action_flags
4404 * Holds the actions detected until now.
4406 * Pointer to the sample action.
4408 * Pointer to the Ethernet device structure.
4410 * Attributes of flow that includes this action.
4411 * @param[in] item_flags
4412 * Holds the items detected.
4414 * Pointer to error structure.
4417 * 0 on success, a negative errno value otherwise and rte_errno is set.
4420 flow_dv_validate_action_sample(uint64_t action_flags,
4421 const struct rte_flow_action *action,
4422 struct rte_eth_dev *dev,
4423 const struct rte_flow_attr *attr,
4424 const uint64_t item_flags,
4425 struct rte_flow_error *error)
4427 struct mlx5_priv *priv = dev->data->dev_private;
4428 struct mlx5_dev_config *dev_conf = &priv->config;
4429 const struct rte_flow_action_sample *sample = action->conf;
4430 const struct rte_flow_action *act;
4431 uint64_t sub_action_flags = 0;
4432 uint16_t queue_index = 0xFFFF;
4438 return rte_flow_error_set(error, EINVAL,
4439 RTE_FLOW_ERROR_TYPE_ACTION, action,
4440 "configuration cannot be NULL");
4441 if (sample->ratio == 0)
4442 return rte_flow_error_set(error, EINVAL,
4443 RTE_FLOW_ERROR_TYPE_ACTION, action,
4444 "ratio value starts from 1");
4445 if (!priv->config.devx || (sample->ratio > 0 && !priv->sampler_en))
4446 return rte_flow_error_set(error, ENOTSUP,
4447 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4449 "sample action not supported");
4450 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
4451 return rte_flow_error_set(error, EINVAL,
4452 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4453 "Multiple sample actions not "
4455 if (action_flags & MLX5_FLOW_ACTION_METER)
4456 return rte_flow_error_set(error, EINVAL,
4457 RTE_FLOW_ERROR_TYPE_ACTION, action,
4458 "wrong action order, meter should "
4459 "be after sample action");
4460 if (action_flags & MLX5_FLOW_ACTION_JUMP)
4461 return rte_flow_error_set(error, EINVAL,
4462 RTE_FLOW_ERROR_TYPE_ACTION, action,
4463 "wrong action order, jump should "
4464 "be after sample action");
4465 act = sample->actions;
4466 for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
4467 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
4468 return rte_flow_error_set(error, ENOTSUP,
4469 RTE_FLOW_ERROR_TYPE_ACTION,
4470 act, "too many actions");
4471 switch (act->type) {
4472 case RTE_FLOW_ACTION_TYPE_QUEUE:
4473 ret = mlx5_flow_validate_action_queue(act,
4479 queue_index = ((const struct rte_flow_action_queue *)
4480 (act->conf))->index;
4481 sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
4484 case RTE_FLOW_ACTION_TYPE_MARK:
4485 ret = flow_dv_validate_action_mark(dev, act,
4490 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
4491 sub_action_flags |= MLX5_FLOW_ACTION_MARK |
4492 MLX5_FLOW_ACTION_MARK_EXT;
4494 sub_action_flags |= MLX5_FLOW_ACTION_MARK;
4497 case RTE_FLOW_ACTION_TYPE_COUNT:
4498 ret = flow_dv_validate_action_count(dev, error);
4501 sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
4504 case RTE_FLOW_ACTION_TYPE_PORT_ID:
4505 ret = flow_dv_validate_action_port_id(dev,
4512 sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
4515 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4516 ret = flow_dv_validate_action_raw_encap_decap
4517 (dev, NULL, act->conf, attr, &sub_action_flags,
4518 &actions_n, action, item_flags, error);
4524 return rte_flow_error_set(error, ENOTSUP,
4525 RTE_FLOW_ERROR_TYPE_ACTION,
4527 "Doesn't support optional "
4531 if (attr->ingress && !attr->transfer) {
4532 if (!(sub_action_flags & MLX5_FLOW_ACTION_QUEUE))
4533 return rte_flow_error_set(error, EINVAL,
4534 RTE_FLOW_ERROR_TYPE_ACTION,
4536 "Ingress must has a dest "
4537 "QUEUE for Sample");
4538 } else if (attr->egress && !attr->transfer) {
4539 return rte_flow_error_set(error, ENOTSUP,
4540 RTE_FLOW_ERROR_TYPE_ACTION,
4542 "Sample Only support Ingress "
4544 } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
4545 MLX5_ASSERT(attr->transfer);
4546 if (sample->ratio > 1)
4547 return rte_flow_error_set(error, ENOTSUP,
4548 RTE_FLOW_ERROR_TYPE_ACTION,
4550 "E-Switch doesn't support "
4551 "any optional action "
4554 if (sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
4555 return rte_flow_error_set(error, ENOTSUP,
4556 RTE_FLOW_ERROR_TYPE_ACTION,
4558 "unsupported action QUEUE");
4559 if (!(sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
4560 return rte_flow_error_set(error, EINVAL,
4561 RTE_FLOW_ERROR_TYPE_ACTION,
4563 "E-Switch must has a dest "
4564 "port for mirroring");
4566 /* Continue validation for Xcap actions.*/
4567 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
4568 (queue_index == 0xFFFF ||
4569 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN)) {
4570 if ((sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
4571 MLX5_FLOW_XCAP_ACTIONS)
4572 return rte_flow_error_set(error, ENOTSUP,
4573 RTE_FLOW_ERROR_TYPE_ACTION,
4574 NULL, "encap and decap "
4575 "combination aren't "
4577 if (!attr->transfer && attr->ingress && (sub_action_flags &
4578 MLX5_FLOW_ACTION_ENCAP))
4579 return rte_flow_error_set(error, ENOTSUP,
4580 RTE_FLOW_ERROR_TYPE_ACTION,
4581 NULL, "encap is not supported"
4582 " for ingress traffic");
4588 * Find existing modify-header resource or create and register a new one.
4590 * @param dev[in, out]
4591 * Pointer to rte_eth_dev structure.
4592 * @param[in, out] resource
4593 * Pointer to modify-header resource.
4594 * @parm[in, out] dev_flow
4595 * Pointer to the dev_flow.
4597 * pointer to error structure.
4600 * 0 on success otherwise -errno and errno is set.
4603 flow_dv_modify_hdr_resource_register
4604 (struct rte_eth_dev *dev,
4605 struct mlx5_flow_dv_modify_hdr_resource *resource,
4606 struct mlx5_flow *dev_flow,
4607 struct rte_flow_error *error)
4609 struct mlx5_priv *priv = dev->data->dev_private;
4610 struct mlx5_dev_ctx_shared *sh = priv->sh;
4611 uint32_t key_len = sizeof(*resource) -
4612 offsetof(typeof(*resource), ft_type) +
4613 resource->actions_num * sizeof(resource->actions[0]);
4614 struct mlx5_hlist_entry *entry;
4615 struct mlx5_flow_cb_ctx ctx = {
4621 resource->flags = dev_flow->dv.group ? 0 :
4622 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
4623 if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
4625 return rte_flow_error_set(error, EOVERFLOW,
4626 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4627 "too many modify header items");
4628 key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
4629 entry = mlx5_hlist_register(sh->modify_cmds, key64, &ctx);
4632 resource = container_of(entry, typeof(*resource), entry);
4633 dev_flow->handle->dvh.modify_hdr = resource;
4638 * Get DV flow counter by index.
4641 * Pointer to the Ethernet device structure.
4643 * mlx5 flow counter index in the container.
4645 * mlx5 flow counter pool in the container,
4648 * Pointer to the counter, NULL otherwise.
4650 static struct mlx5_flow_counter *
4651 flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
4653 struct mlx5_flow_counter_pool **ppool)
4655 struct mlx5_priv *priv = dev->data->dev_private;
4656 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
4657 struct mlx5_flow_counter_pool *pool;
4659 /* Decrease to original index and clear shared bit. */
4660 idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
4661 MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cmng->n);
4662 pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
4666 return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
4670 * Check the devx counter belongs to the pool.
4673 * Pointer to the counter pool.
4675 * The counter devx ID.
4678 * True if counter belongs to the pool, false otherwise.
4681 flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
4683 int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
4684 MLX5_COUNTERS_PER_POOL;
4686 if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
4692 * Get a pool by devx counter ID.
4695 * Pointer to the counter management.
4697 * The counter devx ID.
4700 * The counter pool pointer if exists, NULL otherwise,
4702 static struct mlx5_flow_counter_pool *
4703 flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
4706 struct mlx5_flow_counter_pool *pool = NULL;
4708 rte_spinlock_lock(&cmng->pool_update_sl);
4709 /* Check last used pool. */
4710 if (cmng->last_pool_idx != POOL_IDX_INVALID &&
4711 flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
4712 pool = cmng->pools[cmng->last_pool_idx];
4715 /* ID out of range means no suitable pool in the container. */
4716 if (id > cmng->max_id || id < cmng->min_id)
4719 * Find the pool from the end of the container, since mostly counter
4720 * ID is sequence increasing, and the last pool should be the needed
4725 struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
4727 if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
4733 rte_spinlock_unlock(&cmng->pool_update_sl);
4738 * Resize a counter container.
4741 * Pointer to the Ethernet device structure.
4744 * 0 on success, otherwise negative errno value and rte_errno is set.
4747 flow_dv_container_resize(struct rte_eth_dev *dev)
4749 struct mlx5_priv *priv = dev->data->dev_private;
4750 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
4751 void *old_pools = cmng->pools;
4752 uint32_t resize = cmng->n + MLX5_CNT_CONTAINER_RESIZE;
4753 uint32_t mem_size = sizeof(struct mlx5_flow_counter_pool *) * resize;
4754 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
4761 memcpy(pools, old_pools, cmng->n *
4762 sizeof(struct mlx5_flow_counter_pool *));
4764 cmng->pools = pools;
4766 mlx5_free(old_pools);
4771 * Query a devx flow counter.
4774 * Pointer to the Ethernet device structure.
4776 * Index to the flow counter.
4778 * The statistics value of packets.
4780 * The statistics value of bytes.
4783 * 0 on success, otherwise a negative errno value and rte_errno is set.
4786 _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
4789 struct mlx5_priv *priv = dev->data->dev_private;
4790 struct mlx5_flow_counter_pool *pool = NULL;
4791 struct mlx5_flow_counter *cnt;
4794 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
4796 if (priv->sh->cmng.counter_fallback)
4797 return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
4798 0, pkts, bytes, 0, NULL, NULL, 0);
4799 rte_spinlock_lock(&pool->sl);
4804 offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
4805 *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
4806 *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
4808 rte_spinlock_unlock(&pool->sl);
4813 * Create and initialize a new counter pool.
4816 * Pointer to the Ethernet device structure.
4818 * The devX counter handle.
4820 * Whether the pool is for counter that was allocated for aging.
4821 * @param[in/out] cont_cur
4822 * Pointer to the container pointer, it will be update in pool resize.
4825 * The pool container pointer on success, NULL otherwise and rte_errno is set.
4827 static struct mlx5_flow_counter_pool *
4828 flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
4831 struct mlx5_priv *priv = dev->data->dev_private;
4832 struct mlx5_flow_counter_pool *pool;
4833 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
4834 bool fallback = priv->sh->cmng.counter_fallback;
4835 uint32_t size = sizeof(*pool);
4837 size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
4838 size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
4839 pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
4845 pool->is_aged = !!age;
4846 pool->query_gen = 0;
4847 pool->min_dcs = dcs;
4848 rte_spinlock_init(&pool->sl);
4849 rte_spinlock_init(&pool->csl);
4850 TAILQ_INIT(&pool->counters[0]);
4851 TAILQ_INIT(&pool->counters[1]);
4852 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
4853 rte_spinlock_lock(&cmng->pool_update_sl);
4854 pool->index = cmng->n_valid;
4855 if (pool->index == cmng->n && flow_dv_container_resize(dev)) {
4857 rte_spinlock_unlock(&cmng->pool_update_sl);
4860 cmng->pools[pool->index] = pool;
4862 if (unlikely(fallback)) {
4863 int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
4865 if (base < cmng->min_id)
4866 cmng->min_id = base;
4867 if (base > cmng->max_id)
4868 cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
4869 cmng->last_pool_idx = pool->index;
4871 rte_spinlock_unlock(&cmng->pool_update_sl);
4876 * Prepare a new counter and/or a new counter pool.
4879 * Pointer to the Ethernet device structure.
4880 * @param[out] cnt_free
4881 * Where to put the pointer of a new counter.
4883 * Whether the pool is for counter that was allocated for aging.
4886 * The counter pool pointer and @p cnt_free is set on success,
4887 * NULL otherwise and rte_errno is set.
4889 static struct mlx5_flow_counter_pool *
4890 flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
4891 struct mlx5_flow_counter **cnt_free,
4894 struct mlx5_priv *priv = dev->data->dev_private;
4895 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
4896 struct mlx5_flow_counter_pool *pool;
4897 struct mlx5_counters tmp_tq;
4898 struct mlx5_devx_obj *dcs = NULL;
4899 struct mlx5_flow_counter *cnt;
4900 enum mlx5_counter_type cnt_type =
4901 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
4902 bool fallback = priv->sh->cmng.counter_fallback;
4906 /* bulk_bitmap must be 0 for single counter allocation. */
4907 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0);
4910 pool = flow_dv_find_pool_by_id(cmng, dcs->id);
4912 pool = flow_dv_pool_create(dev, dcs, age);
4914 mlx5_devx_cmd_destroy(dcs);
4918 i = dcs->id % MLX5_COUNTERS_PER_POOL;
4919 cnt = MLX5_POOL_GET_CNT(pool, i);
4921 cnt->dcs_when_free = dcs;
4925 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
4927 rte_errno = ENODATA;
4930 pool = flow_dv_pool_create(dev, dcs, age);
4932 mlx5_devx_cmd_destroy(dcs);
4935 TAILQ_INIT(&tmp_tq);
4936 for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
4937 cnt = MLX5_POOL_GET_CNT(pool, i);
4939 TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
4941 rte_spinlock_lock(&cmng->csl[cnt_type]);
4942 TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
4943 rte_spinlock_unlock(&cmng->csl[cnt_type]);
4944 *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
4945 (*cnt_free)->pool = pool;
4950 * Allocate a flow counter.
4953 * Pointer to the Ethernet device structure.
4955 * Whether the counter was allocated for aging.
4958 * Index to flow counter on success, 0 otherwise and rte_errno is set.
4961 flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
4963 struct mlx5_priv *priv = dev->data->dev_private;
4964 struct mlx5_flow_counter_pool *pool = NULL;
4965 struct mlx5_flow_counter *cnt_free = NULL;
4966 bool fallback = priv->sh->cmng.counter_fallback;
4967 struct mlx5_flow_counter_mng *cmng = &priv->sh->cmng;
4968 enum mlx5_counter_type cnt_type =
4969 age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
4972 if (!priv->config.devx) {
4973 rte_errno = ENOTSUP;
4976 /* Get free counters from container. */
4977 rte_spinlock_lock(&cmng->csl[cnt_type]);
4978 cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
4980 TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
4981 rte_spinlock_unlock(&cmng->csl[cnt_type]);
4982 if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
4984 pool = cnt_free->pool;
4986 cnt_free->dcs_when_active = cnt_free->dcs_when_free;
4987 /* Create a DV counter action only in the first time usage. */
4988 if (!cnt_free->action) {
4990 struct mlx5_devx_obj *dcs;
4994 offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
4995 dcs = pool->min_dcs;
4998 dcs = cnt_free->dcs_when_free;
5000 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
5007 cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
5008 MLX5_CNT_ARRAY_IDX(pool, cnt_free));
5009 /* Update the counter reset values. */
5010 if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
5013 if (!fallback && !priv->sh->cmng.query_thread_on)
5014 /* Start the asynchronous batch query by the host thread. */
5015 mlx5_set_query_alarm(priv->sh);
5019 cnt_free->pool = pool;
5021 cnt_free->dcs_when_free = cnt_free->dcs_when_active;
5022 rte_spinlock_lock(&cmng->csl[cnt_type]);
5023 TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
5024 rte_spinlock_unlock(&cmng->csl[cnt_type]);
5030 * Allocate a shared flow counter.
5033 * Pointer to the shared counter configuration.
5035 * Pointer to save the allocated counter index.
5038 * Index to flow counter on success, 0 otherwise and rte_errno is set.
5042 flow_dv_counter_alloc_shared_cb(void *ctx, union mlx5_l3t_data *data)
5044 struct mlx5_shared_counter_conf *conf = ctx;
5045 struct rte_eth_dev *dev = conf->dev;
5046 struct mlx5_flow_counter *cnt;
5048 data->dword = flow_dv_counter_alloc(dev, 0);
5049 data->dword |= MLX5_CNT_SHARED_OFFSET;
5050 cnt = flow_dv_counter_get_by_idx(dev, data->dword, NULL);
5051 cnt->shared_info.id = conf->id;
5056 * Get a shared flow counter.
5059 * Pointer to the Ethernet device structure.
5061 * Counter identifier.
5064 * Index to flow counter on success, 0 otherwise and rte_errno is set.
5067 flow_dv_counter_get_shared(struct rte_eth_dev *dev, uint32_t id)
5069 struct mlx5_priv *priv = dev->data->dev_private;
5070 struct mlx5_shared_counter_conf conf = {
5074 union mlx5_l3t_data data = {
5078 mlx5_l3t_prepare_entry(priv->sh->cnt_id_tbl, id, &data,
5079 flow_dv_counter_alloc_shared_cb, &conf);
5084 * Get age param from counter index.
5087 * Pointer to the Ethernet device structure.
5088 * @param[in] counter
5089 * Index to the counter handler.
5092 * The aging parameter specified for the counter index.
5094 static struct mlx5_age_param*
5095 flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
5098 struct mlx5_flow_counter *cnt;
5099 struct mlx5_flow_counter_pool *pool = NULL;
5101 flow_dv_counter_get_by_idx(dev, counter, &pool);
5102 counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
5103 cnt = MLX5_POOL_GET_CNT(pool, counter);
5104 return MLX5_CNT_TO_AGE(cnt);
5108 * Remove a flow counter from aged counter list.
5111 * Pointer to the Ethernet device structure.
5112 * @param[in] counter
5113 * Index to the counter handler.
5115 * Pointer to the counter handler.
5118 flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
5119 uint32_t counter, struct mlx5_flow_counter *cnt)
5121 struct mlx5_age_info *age_info;
5122 struct mlx5_age_param *age_param;
5123 struct mlx5_priv *priv = dev->data->dev_private;
5124 uint16_t expected = AGE_CANDIDATE;
5126 age_info = GET_PORT_AGE_INFO(priv);
5127 age_param = flow_dv_counter_idx_get_age(dev, counter);
5128 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
5129 AGE_FREE, false, __ATOMIC_RELAXED,
5130 __ATOMIC_RELAXED)) {
5132 * We need the lock even it is age timeout,
5133 * since counter may still in process.
5135 rte_spinlock_lock(&age_info->aged_sl);
5136 TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
5137 rte_spinlock_unlock(&age_info->aged_sl);
5138 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
5143 * Release a flow counter.
5146 * Pointer to the Ethernet device structure.
5147 * @param[in] counter
5148 * Index to the counter handler.
5151 flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
5153 struct mlx5_priv *priv = dev->data->dev_private;
5154 struct mlx5_flow_counter_pool *pool = NULL;
5155 struct mlx5_flow_counter *cnt;
5156 enum mlx5_counter_type cnt_type;
5160 cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
5162 if (IS_SHARED_CNT(counter) &&
5163 mlx5_l3t_clear_entry(priv->sh->cnt_id_tbl, cnt->shared_info.id))
5166 flow_dv_counter_remove_from_age(dev, counter, cnt);
5169 * Put the counter back to list to be updated in none fallback mode.
5170 * Currently, we are using two list alternately, while one is in query,
5171 * add the freed counter to the other list based on the pool query_gen
5172 * value. After query finishes, add counter the list to the global
5173 * container counter list. The list changes while query starts. In
5174 * this case, lock will not be needed as query callback and release
5175 * function both operate with the different list.
5178 if (!priv->sh->cmng.counter_fallback) {
5179 rte_spinlock_lock(&pool->csl);
5180 TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
5181 rte_spinlock_unlock(&pool->csl);
5183 cnt->dcs_when_free = cnt->dcs_when_active;
5184 cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
5185 MLX5_COUNTER_TYPE_ORIGIN;
5186 rte_spinlock_lock(&priv->sh->cmng.csl[cnt_type]);
5187 TAILQ_INSERT_TAIL(&priv->sh->cmng.counters[cnt_type],
5189 rte_spinlock_unlock(&priv->sh->cmng.csl[cnt_type]);
5194 * Verify the @p attributes will be correctly understood by the NIC and store
5195 * them in the @p flow if everything is correct.
5198 * Pointer to dev struct.
5199 * @param[in] attributes
5200 * Pointer to flow attributes
5201 * @param[in] external
5202 * This flow rule is created by request external to PMD.
5204 * Pointer to error structure.
5207 * - 0 on success and non root table.
5208 * - 1 on success and root table.
5209 * - a negative errno value otherwise and rte_errno is set.
5212 flow_dv_validate_attributes(struct rte_eth_dev *dev,
5213 const struct mlx5_flow_tunnel *tunnel,
5214 const struct rte_flow_attr *attributes,
5215 const struct flow_grp_info *grp_info,
5216 struct rte_flow_error *error)
5218 struct mlx5_priv *priv = dev->data->dev_private;
5219 uint32_t priority_max = priv->config.flow_prio - 1;
5222 #ifndef HAVE_MLX5DV_DR
5223 RTE_SET_USED(tunnel);
5224 RTE_SET_USED(grp_info);
5225 if (attributes->group)
5226 return rte_flow_error_set(error, ENOTSUP,
5227 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
5229 "groups are not supported");
5233 ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
5238 ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
5240 if (attributes->priority != MLX5_FLOW_PRIO_RSVD &&
5241 attributes->priority >= priority_max)
5242 return rte_flow_error_set(error, ENOTSUP,
5243 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
5245 "priority out of range");
5246 if (attributes->transfer) {
5247 if (!priv->config.dv_esw_en)
5248 return rte_flow_error_set
5250 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5251 "E-Switch dr is not supported");
5252 if (!(priv->representor || priv->master))
5253 return rte_flow_error_set
5254 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5255 NULL, "E-Switch configuration can only be"
5256 " done by a master or a representor device");
5257 if (attributes->egress)
5258 return rte_flow_error_set
5260 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attributes,
5261 "egress is not supported");
5263 if (!(attributes->egress ^ attributes->ingress))
5264 return rte_flow_error_set(error, ENOTSUP,
5265 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
5266 "must specify exactly one of "
5267 "ingress or egress");
5272 * Internal validation function. For validating both actions and items.
5275 * Pointer to the rte_eth_dev structure.
5277 * Pointer to the flow attributes.
5279 * Pointer to the list of items.
5280 * @param[in] actions
5281 * Pointer to the list of actions.
5282 * @param[in] external
5283 * This flow rule is created by request external to PMD.
5284 * @param[in] hairpin
5285 * Number of hairpin TX actions, 0 means classic flow.
5287 * Pointer to the error structure.
5290 * 0 on success, a negative errno value otherwise and rte_errno is set.
5293 flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
5294 const struct rte_flow_item items[],
5295 const struct rte_flow_action actions[],
5296 bool external, int hairpin, struct rte_flow_error *error)
5299 uint64_t action_flags = 0;
5300 uint64_t item_flags = 0;
5301 uint64_t last_item = 0;
5302 uint8_t next_protocol = 0xff;
5303 uint16_t ether_type = 0;
5305 uint8_t item_ipv6_proto = 0;
5306 const struct rte_flow_item *gre_item = NULL;
5307 const struct rte_flow_item *gtp_item = NULL;
5308 const struct rte_flow_action_raw_decap *decap;
5309 const struct rte_flow_action_raw_encap *encap;
5310 const struct rte_flow_action_rss *rss;
5311 const struct rte_flow_item_tcp nic_tcp_mask = {
5314 .src_port = RTE_BE16(UINT16_MAX),
5315 .dst_port = RTE_BE16(UINT16_MAX),
5318 const struct rte_flow_item_ipv6 nic_ipv6_mask = {
5321 "\xff\xff\xff\xff\xff\xff\xff\xff"
5322 "\xff\xff\xff\xff\xff\xff\xff\xff",
5324 "\xff\xff\xff\xff\xff\xff\xff\xff"
5325 "\xff\xff\xff\xff\xff\xff\xff\xff",
5326 .vtc_flow = RTE_BE32(0xffffffff),
5332 const struct rte_flow_item_ecpri nic_ecpri_mask = {
5336 RTE_BE32(((const struct rte_ecpri_common_hdr) {
5340 .dummy[0] = 0xffffffff,
5343 struct mlx5_priv *priv = dev->data->dev_private;
5344 struct mlx5_dev_config *dev_conf = &priv->config;
5345 uint16_t queue_index = 0xFFFF;
5346 const struct rte_flow_item_vlan *vlan_m = NULL;
5347 int16_t rw_act_num = 0;
5349 const struct mlx5_flow_tunnel *tunnel;
5350 struct flow_grp_info grp_info = {
5351 .external = !!external,
5352 .transfer = !!attr->transfer,
5353 .fdb_def_rule = !!priv->fdb_def_rule,
5355 const struct rte_eth_hairpin_conf *conf;
5359 if (is_flow_tunnel_match_rule(dev, attr, items, actions)) {
5360 tunnel = flow_items_to_tunnel(items);
5361 action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
5362 MLX5_FLOW_ACTION_DECAP;
5363 } else if (is_flow_tunnel_steer_rule(dev, attr, items, actions)) {
5364 tunnel = flow_actions_to_tunnel(actions);
5365 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
5369 if (tunnel && priv->representor)
5370 return rte_flow_error_set(error, ENOTSUP,
5371 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5372 "decap not supported "
5373 "for VF representor");
5374 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
5375 (dev, tunnel, attr, items, actions);
5376 ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
5379 is_root = (uint64_t)ret;
5380 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5381 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
5382 int type = items->type;
5384 if (!mlx5_flow_os_item_supported(type))
5385 return rte_flow_error_set(error, ENOTSUP,
5386 RTE_FLOW_ERROR_TYPE_ITEM,
5387 NULL, "item not supported");
5389 case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
5390 if (items[0].type != (typeof(items[0].type))
5391 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL)
5392 return rte_flow_error_set
5394 RTE_FLOW_ERROR_TYPE_ITEM,
5395 NULL, "MLX5 private items "
5396 "must be the first");
5398 case RTE_FLOW_ITEM_TYPE_VOID:
5400 case RTE_FLOW_ITEM_TYPE_PORT_ID:
5401 ret = flow_dv_validate_item_port_id
5402 (dev, items, attr, item_flags, error);
5405 last_item = MLX5_FLOW_ITEM_PORT_ID;
5407 case RTE_FLOW_ITEM_TYPE_ETH:
5408 ret = mlx5_flow_validate_item_eth(items, item_flags,
5412 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
5413 MLX5_FLOW_LAYER_OUTER_L2;
5414 if (items->mask != NULL && items->spec != NULL) {
5416 ((const struct rte_flow_item_eth *)
5419 ((const struct rte_flow_item_eth *)
5421 ether_type = rte_be_to_cpu_16(ether_type);
5426 case RTE_FLOW_ITEM_TYPE_VLAN:
5427 ret = flow_dv_validate_item_vlan(items, item_flags,
5431 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
5432 MLX5_FLOW_LAYER_OUTER_VLAN;
5433 if (items->mask != NULL && items->spec != NULL) {
5435 ((const struct rte_flow_item_vlan *)
5436 items->spec)->inner_type;
5438 ((const struct rte_flow_item_vlan *)
5439 items->mask)->inner_type;
5440 ether_type = rte_be_to_cpu_16(ether_type);
5444 /* Store outer VLAN mask for of_push_vlan action. */
5446 vlan_m = items->mask;
5448 case RTE_FLOW_ITEM_TYPE_IPV4:
5449 mlx5_flow_tunnel_ip_check(items, next_protocol,
5450 &item_flags, &tunnel);
5451 ret = flow_dv_validate_item_ipv4(items, item_flags,
5452 last_item, ether_type,
5456 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5457 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5458 if (items->mask != NULL &&
5459 ((const struct rte_flow_item_ipv4 *)
5460 items->mask)->hdr.next_proto_id) {
5462 ((const struct rte_flow_item_ipv4 *)
5463 (items->spec))->hdr.next_proto_id;
5465 ((const struct rte_flow_item_ipv4 *)
5466 (items->mask))->hdr.next_proto_id;
5468 /* Reset for inner layer. */
5469 next_protocol = 0xff;
5472 case RTE_FLOW_ITEM_TYPE_IPV6:
5473 mlx5_flow_tunnel_ip_check(items, next_protocol,
5474 &item_flags, &tunnel);
5475 ret = mlx5_flow_validate_item_ipv6(items, item_flags,
5482 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5483 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5484 if (items->mask != NULL &&
5485 ((const struct rte_flow_item_ipv6 *)
5486 items->mask)->hdr.proto) {
5488 ((const struct rte_flow_item_ipv6 *)
5489 items->spec)->hdr.proto;
5491 ((const struct rte_flow_item_ipv6 *)
5492 items->spec)->hdr.proto;
5494 ((const struct rte_flow_item_ipv6 *)
5495 items->mask)->hdr.proto;
5497 /* Reset for inner layer. */
5498 next_protocol = 0xff;
5501 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
5502 ret = flow_dv_validate_item_ipv6_frag_ext(items,
5507 last_item = tunnel ?
5508 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
5509 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
5510 if (items->mask != NULL &&
5511 ((const struct rte_flow_item_ipv6_frag_ext *)
5512 items->mask)->hdr.next_header) {
5514 ((const struct rte_flow_item_ipv6_frag_ext *)
5515 items->spec)->hdr.next_header;
5517 ((const struct rte_flow_item_ipv6_frag_ext *)
5518 items->mask)->hdr.next_header;
5520 /* Reset for inner layer. */
5521 next_protocol = 0xff;
5524 case RTE_FLOW_ITEM_TYPE_TCP:
5525 ret = mlx5_flow_validate_item_tcp
5532 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
5533 MLX5_FLOW_LAYER_OUTER_L4_TCP;
5535 case RTE_FLOW_ITEM_TYPE_UDP:
5536 ret = mlx5_flow_validate_item_udp(items, item_flags,
5541 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
5542 MLX5_FLOW_LAYER_OUTER_L4_UDP;
5544 case RTE_FLOW_ITEM_TYPE_GRE:
5545 ret = mlx5_flow_validate_item_gre(items, item_flags,
5546 next_protocol, error);
5550 last_item = MLX5_FLOW_LAYER_GRE;
5552 case RTE_FLOW_ITEM_TYPE_NVGRE:
5553 ret = mlx5_flow_validate_item_nvgre(items, item_flags,
5558 last_item = MLX5_FLOW_LAYER_NVGRE;
5560 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
5561 ret = mlx5_flow_validate_item_gre_key
5562 (items, item_flags, gre_item, error);
5565 last_item = MLX5_FLOW_LAYER_GRE_KEY;
5567 case RTE_FLOW_ITEM_TYPE_VXLAN:
5568 ret = mlx5_flow_validate_item_vxlan(items, item_flags,
5572 last_item = MLX5_FLOW_LAYER_VXLAN;
5574 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
5575 ret = mlx5_flow_validate_item_vxlan_gpe(items,
5580 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
5582 case RTE_FLOW_ITEM_TYPE_GENEVE:
5583 ret = mlx5_flow_validate_item_geneve(items,
5588 last_item = MLX5_FLOW_LAYER_GENEVE;
5590 case RTE_FLOW_ITEM_TYPE_MPLS:
5591 ret = mlx5_flow_validate_item_mpls(dev, items,
5596 last_item = MLX5_FLOW_LAYER_MPLS;
5599 case RTE_FLOW_ITEM_TYPE_MARK:
5600 ret = flow_dv_validate_item_mark(dev, items, attr,
5604 last_item = MLX5_FLOW_ITEM_MARK;
5606 case RTE_FLOW_ITEM_TYPE_META:
5607 ret = flow_dv_validate_item_meta(dev, items, attr,
5611 last_item = MLX5_FLOW_ITEM_METADATA;
5613 case RTE_FLOW_ITEM_TYPE_ICMP:
5614 ret = mlx5_flow_validate_item_icmp(items, item_flags,
5619 last_item = MLX5_FLOW_LAYER_ICMP;
5621 case RTE_FLOW_ITEM_TYPE_ICMP6:
5622 ret = mlx5_flow_validate_item_icmp6(items, item_flags,
5627 item_ipv6_proto = IPPROTO_ICMPV6;
5628 last_item = MLX5_FLOW_LAYER_ICMP6;
5630 case RTE_FLOW_ITEM_TYPE_TAG:
5631 ret = flow_dv_validate_item_tag(dev, items,
5635 last_item = MLX5_FLOW_ITEM_TAG;
5637 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
5638 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
5640 case RTE_FLOW_ITEM_TYPE_GTP:
5641 ret = flow_dv_validate_item_gtp(dev, items, item_flags,
5646 last_item = MLX5_FLOW_LAYER_GTP;
5648 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
5649 ret = flow_dv_validate_item_gtp_psc(items, last_item,
5654 last_item = MLX5_FLOW_LAYER_GTP_PSC;
5656 case RTE_FLOW_ITEM_TYPE_ECPRI:
5657 /* Capacity will be checked in the translate stage. */
5658 ret = mlx5_flow_validate_item_ecpri(items, item_flags,
5665 last_item = MLX5_FLOW_LAYER_ECPRI;
5668 return rte_flow_error_set(error, ENOTSUP,
5669 RTE_FLOW_ERROR_TYPE_ITEM,
5670 NULL, "item not supported");
5672 item_flags |= last_item;
5674 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5675 int type = actions->type;
5677 if (!mlx5_flow_os_action_supported(type))
5678 return rte_flow_error_set(error, ENOTSUP,
5679 RTE_FLOW_ERROR_TYPE_ACTION,
5681 "action not supported");
5682 if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
5683 return rte_flow_error_set(error, ENOTSUP,
5684 RTE_FLOW_ERROR_TYPE_ACTION,
5685 actions, "too many actions");
5687 case RTE_FLOW_ACTION_TYPE_VOID:
5689 case RTE_FLOW_ACTION_TYPE_PORT_ID:
5690 ret = flow_dv_validate_action_port_id(dev,
5697 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
5700 case RTE_FLOW_ACTION_TYPE_FLAG:
5701 ret = flow_dv_validate_action_flag(dev, action_flags,
5705 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
5706 /* Count all modify-header actions as one. */
5707 if (!(action_flags &
5708 MLX5_FLOW_MODIFY_HDR_ACTIONS))
5710 action_flags |= MLX5_FLOW_ACTION_FLAG |
5711 MLX5_FLOW_ACTION_MARK_EXT;
5713 action_flags |= MLX5_FLOW_ACTION_FLAG;
5716 rw_act_num += MLX5_ACT_NUM_SET_MARK;
5718 case RTE_FLOW_ACTION_TYPE_MARK:
5719 ret = flow_dv_validate_action_mark(dev, actions,
5724 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
5725 /* Count all modify-header actions as one. */
5726 if (!(action_flags &
5727 MLX5_FLOW_MODIFY_HDR_ACTIONS))
5729 action_flags |= MLX5_FLOW_ACTION_MARK |
5730 MLX5_FLOW_ACTION_MARK_EXT;
5732 action_flags |= MLX5_FLOW_ACTION_MARK;
5735 rw_act_num += MLX5_ACT_NUM_SET_MARK;
5737 case RTE_FLOW_ACTION_TYPE_SET_META:
5738 ret = flow_dv_validate_action_set_meta(dev, actions,
5743 /* Count all modify-header actions as one action. */
5744 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5746 action_flags |= MLX5_FLOW_ACTION_SET_META;
5747 rw_act_num += MLX5_ACT_NUM_SET_META;
5749 case RTE_FLOW_ACTION_TYPE_SET_TAG:
5750 ret = flow_dv_validate_action_set_tag(dev, actions,
5755 /* Count all modify-header actions as one action. */
5756 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5758 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
5759 rw_act_num += MLX5_ACT_NUM_SET_TAG;
5761 case RTE_FLOW_ACTION_TYPE_DROP:
5762 ret = mlx5_flow_validate_action_drop(action_flags,
5766 action_flags |= MLX5_FLOW_ACTION_DROP;
5769 case RTE_FLOW_ACTION_TYPE_QUEUE:
5770 ret = mlx5_flow_validate_action_queue(actions,
5775 queue_index = ((const struct rte_flow_action_queue *)
5776 (actions->conf))->index;
5777 action_flags |= MLX5_FLOW_ACTION_QUEUE;
5780 case RTE_FLOW_ACTION_TYPE_RSS:
5781 rss = actions->conf;
5782 ret = mlx5_flow_validate_action_rss(actions,
5788 if (rss != NULL && rss->queue_num)
5789 queue_index = rss->queue[0];
5790 action_flags |= MLX5_FLOW_ACTION_RSS;
5793 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
5795 mlx5_flow_validate_action_default_miss(action_flags,
5799 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
5802 case RTE_FLOW_ACTION_TYPE_COUNT:
5803 ret = flow_dv_validate_action_count(dev, error);
5806 action_flags |= MLX5_FLOW_ACTION_COUNT;
5809 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
5810 if (flow_dv_validate_action_pop_vlan(dev,
5816 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
5819 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5820 ret = flow_dv_validate_action_push_vlan(dev,
5827 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
5830 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5831 ret = flow_dv_validate_action_set_vlan_pcp
5832 (action_flags, actions, error);
5835 /* Count PCP with push_vlan command. */
5836 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
5838 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5839 ret = flow_dv_validate_action_set_vlan_vid
5840 (item_flags, action_flags,
5844 /* Count VID with push_vlan command. */
5845 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
5846 rw_act_num += MLX5_ACT_NUM_MDF_VID;
5848 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5849 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5850 ret = flow_dv_validate_action_l2_encap(dev,
5856 action_flags |= MLX5_FLOW_ACTION_ENCAP;
5859 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5860 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5861 ret = flow_dv_validate_action_decap(dev, action_flags,
5862 actions, item_flags,
5866 action_flags |= MLX5_FLOW_ACTION_DECAP;
5869 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5870 ret = flow_dv_validate_action_raw_encap_decap
5871 (dev, NULL, actions->conf, attr, &action_flags,
5872 &actions_n, actions, item_flags, error);
5876 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5877 decap = actions->conf;
5878 while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
5880 if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5884 encap = actions->conf;
5886 ret = flow_dv_validate_action_raw_encap_decap
5888 decap ? decap : &empty_decap, encap,
5889 attr, &action_flags, &actions_n,
5890 actions, item_flags, error);
5894 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
5895 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
5896 ret = flow_dv_validate_action_modify_mac(action_flags,
5902 /* Count all modify-header actions as one action. */
5903 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5905 action_flags |= actions->type ==
5906 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
5907 MLX5_FLOW_ACTION_SET_MAC_SRC :
5908 MLX5_FLOW_ACTION_SET_MAC_DST;
5910 * Even if the source and destination MAC addresses have
5911 * overlap in the header with 4B alignment, the convert
5912 * function will handle them separately and 4 SW actions
5913 * will be created. And 2 actions will be added each
5914 * time no matter how many bytes of address will be set.
5916 rw_act_num += MLX5_ACT_NUM_MDF_MAC;
5918 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
5919 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
5920 ret = flow_dv_validate_action_modify_ipv4(action_flags,
5926 /* Count all modify-header actions as one action. */
5927 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5929 action_flags |= actions->type ==
5930 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
5931 MLX5_FLOW_ACTION_SET_IPV4_SRC :
5932 MLX5_FLOW_ACTION_SET_IPV4_DST;
5933 rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
5935 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
5936 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
5937 ret = flow_dv_validate_action_modify_ipv6(action_flags,
5943 if (item_ipv6_proto == IPPROTO_ICMPV6)
5944 return rte_flow_error_set(error, ENOTSUP,
5945 RTE_FLOW_ERROR_TYPE_ACTION,
5947 "Can't change header "
5948 "with ICMPv6 proto");
5949 /* Count all modify-header actions as one action. */
5950 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5952 action_flags |= actions->type ==
5953 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
5954 MLX5_FLOW_ACTION_SET_IPV6_SRC :
5955 MLX5_FLOW_ACTION_SET_IPV6_DST;
5956 rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
5958 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
5959 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
5960 ret = flow_dv_validate_action_modify_tp(action_flags,
5966 /* Count all modify-header actions as one action. */
5967 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5969 action_flags |= actions->type ==
5970 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
5971 MLX5_FLOW_ACTION_SET_TP_SRC :
5972 MLX5_FLOW_ACTION_SET_TP_DST;
5973 rw_act_num += MLX5_ACT_NUM_MDF_PORT;
5975 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
5976 case RTE_FLOW_ACTION_TYPE_SET_TTL:
5977 ret = flow_dv_validate_action_modify_ttl(action_flags,
5983 /* Count all modify-header actions as one action. */
5984 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
5986 action_flags |= actions->type ==
5987 RTE_FLOW_ACTION_TYPE_SET_TTL ?
5988 MLX5_FLOW_ACTION_SET_TTL :
5989 MLX5_FLOW_ACTION_DEC_TTL;
5990 rw_act_num += MLX5_ACT_NUM_MDF_TTL;
5992 case RTE_FLOW_ACTION_TYPE_JUMP:
5993 ret = flow_dv_validate_action_jump(dev, tunnel, actions,
6000 action_flags |= MLX5_FLOW_ACTION_JUMP;
6002 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
6003 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
6004 ret = flow_dv_validate_action_modify_tcp_seq
6011 /* Count all modify-header actions as one action. */
6012 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6014 action_flags |= actions->type ==
6015 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
6016 MLX5_FLOW_ACTION_INC_TCP_SEQ :
6017 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
6018 rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
6020 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
6021 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
6022 ret = flow_dv_validate_action_modify_tcp_ack
6029 /* Count all modify-header actions as one action. */
6030 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6032 action_flags |= actions->type ==
6033 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
6034 MLX5_FLOW_ACTION_INC_TCP_ACK :
6035 MLX5_FLOW_ACTION_DEC_TCP_ACK;
6036 rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
6038 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
6040 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
6041 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
6042 rw_act_num += MLX5_ACT_NUM_SET_TAG;
6044 case RTE_FLOW_ACTION_TYPE_METER:
6045 ret = mlx5_flow_validate_action_meter(dev,
6051 action_flags |= MLX5_FLOW_ACTION_METER;
6053 /* Meter action will add one more TAG action. */
6054 rw_act_num += MLX5_ACT_NUM_SET_TAG;
6056 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
6057 if (!attr->transfer && !attr->group)
6058 return rte_flow_error_set(error, ENOTSUP,
6059 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6061 "Shared ASO age action is not supported for group 0");
6062 action_flags |= MLX5_FLOW_ACTION_AGE;
6065 case RTE_FLOW_ACTION_TYPE_AGE:
6066 ret = flow_dv_validate_action_age(action_flags,
6071 action_flags |= MLX5_FLOW_ACTION_AGE;
6074 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
6075 ret = flow_dv_validate_action_modify_ipv4_dscp
6082 /* Count all modify-header actions as one action. */
6083 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6085 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
6086 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
6088 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
6089 ret = flow_dv_validate_action_modify_ipv6_dscp
6096 /* Count all modify-header actions as one action. */
6097 if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
6099 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
6100 rw_act_num += MLX5_ACT_NUM_SET_DSCP;
6102 case RTE_FLOW_ACTION_TYPE_SAMPLE:
6103 ret = flow_dv_validate_action_sample(action_flags,
6109 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
6112 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
6113 if (actions[0].type != (typeof(actions[0].type))
6114 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET)
6115 return rte_flow_error_set
6117 RTE_FLOW_ERROR_TYPE_ACTION,
6118 NULL, "MLX5 private action "
6119 "must be the first");
6121 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
6124 return rte_flow_error_set(error, ENOTSUP,
6125 RTE_FLOW_ERROR_TYPE_ACTION,
6127 "action not supported");
6131 * Validate actions in flow rules
6132 * - Explicit decap action is prohibited by the tunnel offload API.
6133 * - Drop action in tunnel steer rule is prohibited by the API.
6134 * - Application cannot use MARK action because it's value can mask
6135 * tunnel default miss nitification.
6136 * - JUMP in tunnel match rule has no support in current PMD
6138 * - TAG & META are reserved for future uses.
6140 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
6141 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
6142 MLX5_FLOW_ACTION_MARK |
6143 MLX5_FLOW_ACTION_SET_TAG |
6144 MLX5_FLOW_ACTION_SET_META |
6145 MLX5_FLOW_ACTION_DROP;
6147 if (action_flags & bad_actions_mask)
6148 return rte_flow_error_set
6150 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6151 "Invalid RTE action in tunnel "
6153 if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
6154 return rte_flow_error_set
6156 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6157 "tunnel set decap rule must terminate "
6160 return rte_flow_error_set
6162 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6163 "tunnel flows for ingress traffic only");
6165 if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
6166 uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
6167 MLX5_FLOW_ACTION_MARK |
6168 MLX5_FLOW_ACTION_SET_TAG |
6169 MLX5_FLOW_ACTION_SET_META;
6171 if (action_flags & bad_actions_mask)
6172 return rte_flow_error_set
6174 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6175 "Invalid RTE action in tunnel "
6179 * Validate the drop action mutual exclusion with other actions.
6180 * Drop action is mutually-exclusive with any other action, except for
6183 if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
6184 (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
6185 return rte_flow_error_set(error, EINVAL,
6186 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6187 "Drop action is mutually-exclusive "
6188 "with any other action, except for "
6190 /* Eswitch has few restrictions on using items and actions */
6191 if (attr->transfer) {
6192 if (!mlx5_flow_ext_mreg_supported(dev) &&
6193 action_flags & MLX5_FLOW_ACTION_FLAG)
6194 return rte_flow_error_set(error, ENOTSUP,
6195 RTE_FLOW_ERROR_TYPE_ACTION,
6197 "unsupported action FLAG");
6198 if (!mlx5_flow_ext_mreg_supported(dev) &&
6199 action_flags & MLX5_FLOW_ACTION_MARK)
6200 return rte_flow_error_set(error, ENOTSUP,
6201 RTE_FLOW_ERROR_TYPE_ACTION,
6203 "unsupported action MARK");
6204 if (action_flags & MLX5_FLOW_ACTION_QUEUE)
6205 return rte_flow_error_set(error, ENOTSUP,
6206 RTE_FLOW_ERROR_TYPE_ACTION,
6208 "unsupported action QUEUE");
6209 if (action_flags & MLX5_FLOW_ACTION_RSS)
6210 return rte_flow_error_set(error, ENOTSUP,
6211 RTE_FLOW_ERROR_TYPE_ACTION,
6213 "unsupported action RSS");
6214 if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
6215 return rte_flow_error_set(error, EINVAL,
6216 RTE_FLOW_ERROR_TYPE_ACTION,
6218 "no fate action is found");
6220 if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
6221 return rte_flow_error_set(error, EINVAL,
6222 RTE_FLOW_ERROR_TYPE_ACTION,
6224 "no fate action is found");
6227 * Continue validation for Xcap and VLAN actions.
6228 * If hairpin is working in explicit TX rule mode, there is no actions
6229 * splitting and the validation of hairpin ingress flow should be the
6230 * same as other standard flows.
6232 if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
6233 MLX5_FLOW_VLAN_ACTIONS)) &&
6234 (queue_index == 0xFFFF ||
6235 mlx5_rxq_get_type(dev, queue_index) != MLX5_RXQ_TYPE_HAIRPIN ||
6236 ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
6237 conf->tx_explicit != 0))) {
6238 if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
6239 MLX5_FLOW_XCAP_ACTIONS)
6240 return rte_flow_error_set(error, ENOTSUP,
6241 RTE_FLOW_ERROR_TYPE_ACTION,
6242 NULL, "encap and decap "
6243 "combination aren't supported");
6244 if (!attr->transfer && attr->ingress) {
6245 if (action_flags & MLX5_FLOW_ACTION_ENCAP)
6246 return rte_flow_error_set
6248 RTE_FLOW_ERROR_TYPE_ACTION,
6249 NULL, "encap is not supported"
6250 " for ingress traffic");
6251 else if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
6252 return rte_flow_error_set
6254 RTE_FLOW_ERROR_TYPE_ACTION,
6255 NULL, "push VLAN action not "
6256 "supported for ingress");
6257 else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
6258 MLX5_FLOW_VLAN_ACTIONS)
6259 return rte_flow_error_set
6261 RTE_FLOW_ERROR_TYPE_ACTION,
6262 NULL, "no support for "
6263 "multiple VLAN actions");
6267 * Hairpin flow will add one more TAG action in TX implicit mode.
6268 * In TX explicit mode, there will be no hairpin flow ID.
6271 rw_act_num += MLX5_ACT_NUM_SET_TAG;
6272 /* extra metadata enabled: one more TAG action will be add. */
6273 if (dev_conf->dv_flow_en &&
6274 dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
6275 mlx5_flow_ext_mreg_supported(dev))
6276 rw_act_num += MLX5_ACT_NUM_SET_TAG;
6277 if ((uint32_t)rw_act_num >
6278 flow_dv_modify_hdr_action_max(dev, is_root)) {
6279 return rte_flow_error_set(error, ENOTSUP,
6280 RTE_FLOW_ERROR_TYPE_ACTION,
6281 NULL, "too many header modify"
6282 " actions to support");
6288 * Internal preparation function. Allocates the DV flow size,
6289 * this size is constant.
6292 * Pointer to the rte_eth_dev structure.
6294 * Pointer to the flow attributes.
6296 * Pointer to the list of items.
6297 * @param[in] actions
6298 * Pointer to the list of actions.
6300 * Pointer to the error structure.
6303 * Pointer to mlx5_flow object on success,
6304 * otherwise NULL and rte_errno is set.
6306 static struct mlx5_flow *
6307 flow_dv_prepare(struct rte_eth_dev *dev,
6308 const struct rte_flow_attr *attr __rte_unused,
6309 const struct rte_flow_item items[] __rte_unused,
6310 const struct rte_flow_action actions[] __rte_unused,
6311 struct rte_flow_error *error)
6313 uint32_t handle_idx = 0;
6314 struct mlx5_flow *dev_flow;
6315 struct mlx5_flow_handle *dev_handle;
6316 struct mlx5_priv *priv = dev->data->dev_private;
6317 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6320 /* In case of corrupting the memory. */
6321 if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
6322 rte_flow_error_set(error, ENOSPC,
6323 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6324 "not free temporary device flow");
6327 dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
6330 rte_flow_error_set(error, ENOMEM,
6331 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6332 "not enough memory to create flow handle");
6335 MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
6336 dev_flow = &wks->flows[wks->flow_idx++];
6337 memset(dev_flow, 0, sizeof(*dev_flow));
6338 dev_flow->handle = dev_handle;
6339 dev_flow->handle_idx = handle_idx;
6341 * In some old rdma-core releases, before continuing, a check of the
6342 * length of matching parameter will be done at first. It needs to use
6343 * the length without misc4 param. If the flow has misc4 support, then
6344 * the length needs to be adjusted accordingly. Each param member is
6345 * aligned with a 64B boundary naturally.
6347 dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param) -
6348 MLX5_ST_SZ_BYTES(fte_match_set_misc4);
6349 dev_flow->ingress = attr->ingress;
6350 dev_flow->dv.transfer = attr->transfer;
6354 #ifdef RTE_LIBRTE_MLX5_DEBUG
6356 * Sanity check for match mask and value. Similar to check_valid_spec() in
6357 * kernel driver. If unmasked bit is present in value, it returns failure.
6360 * pointer to match mask buffer.
6361 * @param match_value
6362 * pointer to match value buffer.
6365 * 0 if valid, -EINVAL otherwise.
6368 flow_dv_check_valid_spec(void *match_mask, void *match_value)
6370 uint8_t *m = match_mask;
6371 uint8_t *v = match_value;
6374 for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
6377 "match_value differs from match_criteria"
6378 " %p[%u] != %p[%u]",
6379 match_value, i, match_mask, i);
6388 * Add match of ip_version.
6392 * @param[in] headers_v
6393 * Values header pointer.
6394 * @param[in] headers_m
6395 * Masks header pointer.
6396 * @param[in] ip_version
6397 * The IP version to set.
6400 flow_dv_set_match_ip_version(uint32_t group,
6406 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf);
6408 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version,
6410 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, ip_version);
6411 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
6412 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype, 0);
6416 * Add Ethernet item to matcher and to the value.
6418 * @param[in, out] matcher
6420 * @param[in, out] key
6421 * Flow matcher value.
6423 * Flow pattern to translate.
6425 * Item is inner pattern.
6428 flow_dv_translate_item_eth(void *matcher, void *key,
6429 const struct rte_flow_item *item, int inner,
6432 const struct rte_flow_item_eth *eth_m = item->mask;
6433 const struct rte_flow_item_eth *eth_v = item->spec;
6434 const struct rte_flow_item_eth nic_mask = {
6435 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
6436 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
6437 .type = RTE_BE16(0xffff),
6450 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
6452 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6454 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
6456 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6458 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, dmac_47_16),
6459 ð_m->dst, sizeof(eth_m->dst));
6460 /* The value must be in the range of the mask. */
6461 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
6462 for (i = 0; i < sizeof(eth_m->dst); ++i)
6463 l24_v[i] = eth_m->dst.addr_bytes[i] & eth_v->dst.addr_bytes[i];
6464 memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_m, smac_47_16),
6465 ð_m->src, sizeof(eth_m->src));
6466 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
6467 /* The value must be in the range of the mask. */
6468 for (i = 0; i < sizeof(eth_m->dst); ++i)
6469 l24_v[i] = eth_m->src.addr_bytes[i] & eth_v->src.addr_bytes[i];
6471 * HW supports match on one Ethertype, the Ethertype following the last
6472 * VLAN tag of the packet (see PRM).
6473 * Set match on ethertype only if ETH header is not followed by VLAN.
6474 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
6475 * ethertype, and use ip_version field instead.
6476 * eCPRI over Ether layer will use type value 0xAEFE.
6478 if (eth_m->type == 0xFFFF) {
6479 /* Set cvlan_tag mask for any single\multi\un-tagged case. */
6480 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
6481 switch (eth_v->type) {
6482 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
6483 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
6485 case RTE_BE16(RTE_ETHER_TYPE_QINQ):
6486 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
6487 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
6489 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
6490 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
6492 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
6493 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
6499 if (eth_m->has_vlan) {
6500 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
6501 if (eth_v->has_vlan) {
6503 * Here, when also has_more_vlan field in VLAN item is
6504 * not set, only single-tagged packets will be matched.
6506 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
6510 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
6511 rte_be_to_cpu_16(eth_m->type));
6512 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
6513 *(uint16_t *)(l24_v) = eth_m->type & eth_v->type;
6517 * Add VLAN item to matcher and to the value.
6519 * @param[in, out] dev_flow
6521 * @param[in, out] matcher
6523 * @param[in, out] key
6524 * Flow matcher value.
6526 * Flow pattern to translate.
6528 * Item is inner pattern.
6531 flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
6532 void *matcher, void *key,
6533 const struct rte_flow_item *item,
6534 int inner, uint32_t group)
6536 const struct rte_flow_item_vlan *vlan_m = item->mask;
6537 const struct rte_flow_item_vlan *vlan_v = item->spec;
6544 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
6546 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6548 hdrs_m = MLX5_ADDR_OF(fte_match_param, matcher,
6550 hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6552 * This is workaround, masks are not supported,
6553 * and pre-validated.
6556 dev_flow->handle->vf_vlan.tag =
6557 rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
6560 * When VLAN item exists in flow, mark packet as tagged,
6561 * even if TCI is not specified.
6563 if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag)) {
6564 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, cvlan_tag, 1);
6565 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
6570 vlan_m = &rte_flow_item_vlan_mask;
6571 tci_m = rte_be_to_cpu_16(vlan_m->tci);
6572 tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
6573 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_vid, tci_m);
6574 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
6575 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_cfi, tci_m >> 12);
6576 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
6577 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, first_prio, tci_m >> 13);
6578 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
6580 * HW is optimized for IPv4/IPv6. In such cases, avoid setting
6581 * ethertype, and use ip_version field instead.
6583 if (vlan_m->inner_type == 0xFFFF) {
6584 switch (vlan_v->inner_type) {
6585 case RTE_BE16(RTE_ETHER_TYPE_VLAN):
6586 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
6587 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
6588 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
6590 case RTE_BE16(RTE_ETHER_TYPE_IPV4):
6591 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 4);
6593 case RTE_BE16(RTE_ETHER_TYPE_IPV6):
6594 flow_dv_set_match_ip_version(group, hdrs_v, hdrs_m, 6);
6600 if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
6601 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, svlan_tag, 1);
6602 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
6603 /* Only one vlan_tag bit can be set. */
6604 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
6607 MLX5_SET(fte_match_set_lyr_2_4, hdrs_m, ethertype,
6608 rte_be_to_cpu_16(vlan_m->inner_type));
6609 MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
6610 rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
6614 * Add IPV4 item to matcher and to the value.
6616 * @param[in, out] matcher
6618 * @param[in, out] key
6619 * Flow matcher value.
6621 * Flow pattern to translate.
6623 * Item is inner pattern.
6625 * The group to insert the rule.
6628 flow_dv_translate_item_ipv4(void *matcher, void *key,
6629 const struct rte_flow_item *item,
6630 int inner, uint32_t group)
6632 const struct rte_flow_item_ipv4 *ipv4_m = item->mask;
6633 const struct rte_flow_item_ipv4 *ipv4_v = item->spec;
6634 const struct rte_flow_item_ipv4 nic_mask = {
6636 .src_addr = RTE_BE32(0xffffffff),
6637 .dst_addr = RTE_BE32(0xffffffff),
6638 .type_of_service = 0xff,
6639 .next_proto_id = 0xff,
6640 .time_to_live = 0xff,
6650 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6652 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6654 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6656 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6658 flow_dv_set_match_ip_version(group, headers_v, headers_m, 4);
6663 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6664 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
6665 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6666 dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
6667 *(uint32_t *)l24_m = ipv4_m->hdr.dst_addr;
6668 *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
6669 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6670 src_ipv4_src_ipv6.ipv4_layout.ipv4);
6671 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6672 src_ipv4_src_ipv6.ipv4_layout.ipv4);
6673 *(uint32_t *)l24_m = ipv4_m->hdr.src_addr;
6674 *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
6675 tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
6676 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn,
6677 ipv4_m->hdr.type_of_service);
6678 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
6679 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp,
6680 ipv4_m->hdr.type_of_service >> 2);
6681 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
6682 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
6683 ipv4_m->hdr.next_proto_id);
6684 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6685 ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
6686 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
6687 ipv4_m->hdr.time_to_live);
6688 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
6689 ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
6690 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
6691 !!(ipv4_m->hdr.fragment_offset));
6692 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
6693 !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
6697 * Add IPV6 item to matcher and to the value.
6699 * @param[in, out] matcher
6701 * @param[in, out] key
6702 * Flow matcher value.
6704 * Flow pattern to translate.
6706 * Item is inner pattern.
6708 * The group to insert the rule.
6711 flow_dv_translate_item_ipv6(void *matcher, void *key,
6712 const struct rte_flow_item *item,
6713 int inner, uint32_t group)
6715 const struct rte_flow_item_ipv6 *ipv6_m = item->mask;
6716 const struct rte_flow_item_ipv6 *ipv6_v = item->spec;
6717 const struct rte_flow_item_ipv6 nic_mask = {
6720 "\xff\xff\xff\xff\xff\xff\xff\xff"
6721 "\xff\xff\xff\xff\xff\xff\xff\xff",
6723 "\xff\xff\xff\xff\xff\xff\xff\xff"
6724 "\xff\xff\xff\xff\xff\xff\xff\xff",
6725 .vtc_flow = RTE_BE32(0xffffffff),
6732 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6733 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6742 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6744 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6746 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6748 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6750 flow_dv_set_match_ip_version(group, headers_v, headers_m, 6);
6755 size = sizeof(ipv6_m->hdr.dst_addr);
6756 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6757 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
6758 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6759 dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
6760 memcpy(l24_m, ipv6_m->hdr.dst_addr, size);
6761 for (i = 0; i < size; ++i)
6762 l24_v[i] = l24_m[i] & ipv6_v->hdr.dst_addr[i];
6763 l24_m = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_m,
6764 src_ipv4_src_ipv6.ipv6_layout.ipv6);
6765 l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
6766 src_ipv4_src_ipv6.ipv6_layout.ipv6);
6767 memcpy(l24_m, ipv6_m->hdr.src_addr, size);
6768 for (i = 0; i < size; ++i)
6769 l24_v[i] = l24_m[i] & ipv6_v->hdr.src_addr[i];
6771 vtc_m = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow);
6772 vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
6773 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ecn, vtc_m >> 20);
6774 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
6775 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_dscp, vtc_m >> 22);
6776 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
6779 MLX5_SET(fte_match_set_misc, misc_m, inner_ipv6_flow_label,
6781 MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
6784 MLX5_SET(fte_match_set_misc, misc_m, outer_ipv6_flow_label,
6786 MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
6790 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
6792 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6793 ipv6_v->hdr.proto & ipv6_m->hdr.proto);
6795 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_ttl_hoplimit,
6796 ipv6_m->hdr.hop_limits);
6797 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
6798 ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
6799 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag,
6800 !!(ipv6_m->has_frag_ext));
6801 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
6802 !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
6806 * Add IPV6 fragment extension item to matcher and to the value.
6808 * @param[in, out] matcher
6810 * @param[in, out] key
6811 * Flow matcher value.
6813 * Flow pattern to translate.
6815 * Item is inner pattern.
6818 flow_dv_translate_item_ipv6_frag_ext(void *matcher, void *key,
6819 const struct rte_flow_item *item,
6822 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m = item->mask;
6823 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v = item->spec;
6824 const struct rte_flow_item_ipv6_frag_ext nic_mask = {
6826 .next_header = 0xff,
6827 .frag_data = RTE_BE16(0xffff),
6834 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6836 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6838 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6840 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6842 /* IPv6 fragment extension item exists, so packet is IP fragment. */
6843 MLX5_SET(fte_match_set_lyr_2_4, headers_m, frag, 1);
6844 MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
6845 if (!ipv6_frag_ext_v)
6847 if (!ipv6_frag_ext_m)
6848 ipv6_frag_ext_m = &nic_mask;
6849 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol,
6850 ipv6_frag_ext_m->hdr.next_header);
6851 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
6852 ipv6_frag_ext_v->hdr.next_header &
6853 ipv6_frag_ext_m->hdr.next_header);
6857 * Add TCP item to matcher and to the value.
6859 * @param[in, out] matcher
6861 * @param[in, out] key
6862 * Flow matcher value.
6864 * Flow pattern to translate.
6866 * Item is inner pattern.
6869 flow_dv_translate_item_tcp(void *matcher, void *key,
6870 const struct rte_flow_item *item,
6873 const struct rte_flow_item_tcp *tcp_m = item->mask;
6874 const struct rte_flow_item_tcp *tcp_v = item->spec;
6879 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6881 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6883 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6885 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6887 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6888 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_TCP);
6892 tcp_m = &rte_flow_item_tcp_mask;
6893 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_sport,
6894 rte_be_to_cpu_16(tcp_m->hdr.src_port));
6895 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
6896 rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
6897 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_dport,
6898 rte_be_to_cpu_16(tcp_m->hdr.dst_port));
6899 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
6900 rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
6901 MLX5_SET(fte_match_set_lyr_2_4, headers_m, tcp_flags,
6902 tcp_m->hdr.tcp_flags);
6903 MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
6904 (tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags));
6908 * Add UDP item to matcher and to the value.
6910 * @param[in, out] matcher
6912 * @param[in, out] key
6913 * Flow matcher value.
6915 * Flow pattern to translate.
6917 * Item is inner pattern.
6920 flow_dv_translate_item_udp(void *matcher, void *key,
6921 const struct rte_flow_item *item,
6924 const struct rte_flow_item_udp *udp_m = item->mask;
6925 const struct rte_flow_item_udp *udp_v = item->spec;
6930 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6932 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
6934 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
6936 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
6938 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
6939 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_UDP);
6943 udp_m = &rte_flow_item_udp_mask;
6944 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_sport,
6945 rte_be_to_cpu_16(udp_m->hdr.src_port));
6946 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
6947 rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
6948 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport,
6949 rte_be_to_cpu_16(udp_m->hdr.dst_port));
6950 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
6951 rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
6955 * Add GRE optional Key item to matcher and to the value.
6957 * @param[in, out] matcher
6959 * @param[in, out] key
6960 * Flow matcher value.
6962 * Flow pattern to translate.
6964 * Item is inner pattern.
6967 flow_dv_translate_item_gre_key(void *matcher, void *key,
6968 const struct rte_flow_item *item)
6970 const rte_be32_t *key_m = item->mask;
6971 const rte_be32_t *key_v = item->spec;
6972 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
6973 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
6974 rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6976 /* GRE K bit must be on and should already be validated */
6977 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present, 1);
6978 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
6982 key_m = &gre_key_default_mask;
6983 MLX5_SET(fte_match_set_misc, misc_m, gre_key_h,
6984 rte_be_to_cpu_32(*key_m) >> 8);
6985 MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
6986 rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
6987 MLX5_SET(fte_match_set_misc, misc_m, gre_key_l,
6988 rte_be_to_cpu_32(*key_m) & 0xFF);
6989 MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
6990 rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
6994 * Add GRE item to matcher and to the value.
6996 * @param[in, out] matcher
6998 * @param[in, out] key
6999 * Flow matcher value.
7001 * Flow pattern to translate.
7003 * Item is inner pattern.
7006 flow_dv_translate_item_gre(void *matcher, void *key,
7007 const struct rte_flow_item *item,
7010 const struct rte_flow_item_gre *gre_m = item->mask;
7011 const struct rte_flow_item_gre *gre_v = item->spec;
7014 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7015 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7022 uint16_t s_present:1;
7023 uint16_t k_present:1;
7024 uint16_t rsvd_bit1:1;
7025 uint16_t c_present:1;
7029 } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
7032 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7034 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7036 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7038 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7040 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
7041 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_GRE);
7045 gre_m = &rte_flow_item_gre_mask;
7046 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol,
7047 rte_be_to_cpu_16(gre_m->protocol));
7048 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
7049 rte_be_to_cpu_16(gre_v->protocol & gre_m->protocol));
7050 gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
7051 gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
7052 MLX5_SET(fte_match_set_misc, misc_m, gre_c_present,
7053 gre_crks_rsvd0_ver_m.c_present);
7054 MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
7055 gre_crks_rsvd0_ver_v.c_present &
7056 gre_crks_rsvd0_ver_m.c_present);
7057 MLX5_SET(fte_match_set_misc, misc_m, gre_k_present,
7058 gre_crks_rsvd0_ver_m.k_present);
7059 MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
7060 gre_crks_rsvd0_ver_v.k_present &
7061 gre_crks_rsvd0_ver_m.k_present);
7062 MLX5_SET(fte_match_set_misc, misc_m, gre_s_present,
7063 gre_crks_rsvd0_ver_m.s_present);
7064 MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
7065 gre_crks_rsvd0_ver_v.s_present &
7066 gre_crks_rsvd0_ver_m.s_present);
7070 * Add NVGRE item to matcher and to the value.
7072 * @param[in, out] matcher
7074 * @param[in, out] key
7075 * Flow matcher value.
7077 * Flow pattern to translate.
7079 * Item is inner pattern.
7082 flow_dv_translate_item_nvgre(void *matcher, void *key,
7083 const struct rte_flow_item *item,
7086 const struct rte_flow_item_nvgre *nvgre_m = item->mask;
7087 const struct rte_flow_item_nvgre *nvgre_v = item->spec;
7088 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7089 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7090 const char *tni_flow_id_m;
7091 const char *tni_flow_id_v;
7097 /* For NVGRE, GRE header fields must be set with defined values. */
7098 const struct rte_flow_item_gre gre_spec = {
7099 .c_rsvd0_ver = RTE_BE16(0x2000),
7100 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
7102 const struct rte_flow_item_gre gre_mask = {
7103 .c_rsvd0_ver = RTE_BE16(0xB000),
7104 .protocol = RTE_BE16(UINT16_MAX),
7106 const struct rte_flow_item gre_item = {
7111 flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
7115 nvgre_m = &rte_flow_item_nvgre_mask;
7116 tni_flow_id_m = (const char *)nvgre_m->tni;
7117 tni_flow_id_v = (const char *)nvgre_v->tni;
7118 size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
7119 gre_key_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, gre_key_h);
7120 gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
7121 memcpy(gre_key_m, tni_flow_id_m, size);
7122 for (i = 0; i < size; ++i)
7123 gre_key_v[i] = gre_key_m[i] & tni_flow_id_v[i];
7127 * Add VXLAN item to matcher and to the value.
7129 * @param[in, out] matcher
7131 * @param[in, out] key
7132 * Flow matcher value.
7134 * Flow pattern to translate.
7136 * Item is inner pattern.
7139 flow_dv_translate_item_vxlan(void *matcher, void *key,
7140 const struct rte_flow_item *item,
7143 const struct rte_flow_item_vxlan *vxlan_m = item->mask;
7144 const struct rte_flow_item_vxlan *vxlan_v = item->spec;
7147 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7148 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7156 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7158 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7160 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7162 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7164 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
7165 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
7166 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
7167 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
7168 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
7173 vxlan_m = &rte_flow_item_vxlan_mask;
7174 size = sizeof(vxlan_m->vni);
7175 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, vxlan_vni);
7176 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
7177 memcpy(vni_m, vxlan_m->vni, size);
7178 for (i = 0; i < size; ++i)
7179 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
7183 * Add VXLAN-GPE item to matcher and to the value.
7185 * @param[in, out] matcher
7187 * @param[in, out] key
7188 * Flow matcher value.
7190 * Flow pattern to translate.
7192 * Item is inner pattern.
7196 flow_dv_translate_item_vxlan_gpe(void *matcher, void *key,
7197 const struct rte_flow_item *item, int inner)
7199 const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
7200 const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
7204 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_3);
7206 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7212 uint8_t flags_m = 0xff;
7213 uint8_t flags_v = 0xc;
7216 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7218 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7220 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7222 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7224 dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
7225 MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
7226 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
7227 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
7228 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
7233 vxlan_m = &rte_flow_item_vxlan_gpe_mask;
7234 size = sizeof(vxlan_m->vni);
7235 vni_m = MLX5_ADDR_OF(fte_match_set_misc3, misc_m, outer_vxlan_gpe_vni);
7236 vni_v = MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
7237 memcpy(vni_m, vxlan_m->vni, size);
7238 for (i = 0; i < size; ++i)
7239 vni_v[i] = vni_m[i] & vxlan_v->vni[i];
7240 if (vxlan_m->flags) {
7241 flags_m = vxlan_m->flags;
7242 flags_v = vxlan_v->flags;
7244 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_flags, flags_m);
7245 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags, flags_v);
7246 MLX5_SET(fte_match_set_misc3, misc_m, outer_vxlan_gpe_next_protocol,
7248 MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_next_protocol,
7253 * Add Geneve item to matcher and to the value.
7255 * @param[in, out] matcher
7257 * @param[in, out] key
7258 * Flow matcher value.
7260 * Flow pattern to translate.
7262 * Item is inner pattern.
7266 flow_dv_translate_item_geneve(void *matcher, void *key,
7267 const struct rte_flow_item *item, int inner)
7269 const struct rte_flow_item_geneve *geneve_m = item->mask;
7270 const struct rte_flow_item_geneve *geneve_v = item->spec;
7273 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7274 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7283 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7285 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7287 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7289 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7291 dport = MLX5_UDP_PORT_GENEVE;
7292 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
7293 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
7294 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
7299 geneve_m = &rte_flow_item_geneve_mask;
7300 size = sizeof(geneve_m->vni);
7301 vni_m = MLX5_ADDR_OF(fte_match_set_misc, misc_m, geneve_vni);
7302 vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
7303 memcpy(vni_m, geneve_m->vni, size);
7304 for (i = 0; i < size; ++i)
7305 vni_v[i] = vni_m[i] & geneve_v->vni[i];
7306 MLX5_SET(fte_match_set_misc, misc_m, geneve_protocol_type,
7307 rte_be_to_cpu_16(geneve_m->protocol));
7308 MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
7309 rte_be_to_cpu_16(geneve_v->protocol & geneve_m->protocol));
7310 gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
7311 gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
7312 MLX5_SET(fte_match_set_misc, misc_m, geneve_oam,
7313 MLX5_GENEVE_OAMF_VAL(gbhdr_m));
7314 MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
7315 MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
7316 MLX5_SET(fte_match_set_misc, misc_m, geneve_opt_len,
7317 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
7318 MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
7319 MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
7320 MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
7324 * Add MPLS item to matcher and to the value.
7326 * @param[in, out] matcher
7328 * @param[in, out] key
7329 * Flow matcher value.
7331 * Flow pattern to translate.
7332 * @param[in] prev_layer
7333 * The protocol layer indicated in previous item.
7335 * Item is inner pattern.
7338 flow_dv_translate_item_mpls(void *matcher, void *key,
7339 const struct rte_flow_item *item,
7340 uint64_t prev_layer,
7343 const uint32_t *in_mpls_m = item->mask;
7344 const uint32_t *in_mpls_v = item->spec;
7345 uint32_t *out_mpls_m = 0;
7346 uint32_t *out_mpls_v = 0;
7347 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7348 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7349 void *misc2_m = MLX5_ADDR_OF(fte_match_param, matcher,
7351 void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
7352 void *headers_m = MLX5_ADDR_OF(fte_match_param, matcher, outer_headers);
7353 void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7355 switch (prev_layer) {
7356 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
7357 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
7358 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
7359 MLX5_UDP_PORT_MPLS);
7361 case MLX5_FLOW_LAYER_GRE:
7362 MLX5_SET(fte_match_set_misc, misc_m, gre_protocol, 0xffff);
7363 MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
7364 RTE_ETHER_TYPE_MPLS);
7367 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
7368 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
7375 in_mpls_m = (const uint32_t *)&rte_flow_item_mpls_mask;
7376 switch (prev_layer) {
7377 case MLX5_FLOW_LAYER_OUTER_L4_UDP:
7379 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
7380 outer_first_mpls_over_udp);
7382 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
7383 outer_first_mpls_over_udp);
7385 case MLX5_FLOW_LAYER_GRE:
7387 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_m,
7388 outer_first_mpls_over_gre);
7390 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
7391 outer_first_mpls_over_gre);
7394 /* Inner MPLS not over GRE is not supported. */
7397 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
7401 (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
7407 if (out_mpls_m && out_mpls_v) {
7408 *out_mpls_m = *in_mpls_m;
7409 *out_mpls_v = *in_mpls_v & *in_mpls_m;
7414 * Add metadata register item to matcher
7416 * @param[in, out] matcher
7418 * @param[in, out] key
7419 * Flow matcher value.
7420 * @param[in] reg_type
7421 * Type of device metadata register
7428 flow_dv_match_meta_reg(void *matcher, void *key,
7429 enum modify_reg reg_type,
7430 uint32_t data, uint32_t mask)
7433 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters_2);
7435 MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
7441 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_a, mask);
7442 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
7445 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_b, mask);
7446 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
7450 * The metadata register C0 field might be divided into
7451 * source vport index and META item value, we should set
7452 * this field according to specified mask, not as whole one.
7454 temp = MLX5_GET(fte_match_set_misc2, misc2_m, metadata_reg_c_0);
7456 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_0, temp);
7457 temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
7460 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
7463 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_1, mask);
7464 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
7467 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_2, mask);
7468 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
7471 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_3, mask);
7472 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
7475 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_4, mask);
7476 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
7479 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_5, mask);
7480 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
7483 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_6, mask);
7484 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
7487 MLX5_SET(fte_match_set_misc2, misc2_m, metadata_reg_c_7, mask);
7488 MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
7497 * Add MARK item to matcher
7500 * The device to configure through.
7501 * @param[in, out] matcher
7503 * @param[in, out] key
7504 * Flow matcher value.
7506 * Flow pattern to translate.
7509 flow_dv_translate_item_mark(struct rte_eth_dev *dev,
7510 void *matcher, void *key,
7511 const struct rte_flow_item *item)
7513 struct mlx5_priv *priv = dev->data->dev_private;
7514 const struct rte_flow_item_mark *mark;
7518 mark = item->mask ? (const void *)item->mask :
7519 &rte_flow_item_mark_mask;
7520 mask = mark->id & priv->sh->dv_mark_mask;
7521 mark = (const void *)item->spec;
7523 value = mark->id & priv->sh->dv_mark_mask & mask;
7525 enum modify_reg reg;
7527 /* Get the metadata register index for the mark. */
7528 reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
7529 MLX5_ASSERT(reg > 0);
7530 if (reg == REG_C_0) {
7531 struct mlx5_priv *priv = dev->data->dev_private;
7532 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
7533 uint32_t shl_c0 = rte_bsf32(msk_c0);
7539 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
7544 * Add META item to matcher
7547 * The devich to configure through.
7548 * @param[in, out] matcher
7550 * @param[in, out] key
7551 * Flow matcher value.
7553 * Attributes of flow that includes this item.
7555 * Flow pattern to translate.
7558 flow_dv_translate_item_meta(struct rte_eth_dev *dev,
7559 void *matcher, void *key,
7560 const struct rte_flow_attr *attr,
7561 const struct rte_flow_item *item)
7563 const struct rte_flow_item_meta *meta_m;
7564 const struct rte_flow_item_meta *meta_v;
7566 meta_m = (const void *)item->mask;
7568 meta_m = &rte_flow_item_meta_mask;
7569 meta_v = (const void *)item->spec;
7572 uint32_t value = meta_v->data;
7573 uint32_t mask = meta_m->data;
7575 reg = flow_dv_get_metadata_reg(dev, attr, NULL);
7578 MLX5_ASSERT(reg != REG_NON);
7580 * In datapath code there is no endianness
7581 * coversions for perfromance reasons, all
7582 * pattern conversions are done in rte_flow.
7584 value = rte_cpu_to_be_32(value);
7585 mask = rte_cpu_to_be_32(mask);
7586 if (reg == REG_C_0) {
7587 struct mlx5_priv *priv = dev->data->dev_private;
7588 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
7589 uint32_t shl_c0 = rte_bsf32(msk_c0);
7590 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
7591 uint32_t shr_c0 = __builtin_clz(priv->sh->dv_meta_mask);
7598 MLX5_ASSERT(msk_c0);
7599 MLX5_ASSERT(!(~msk_c0 & mask));
7601 flow_dv_match_meta_reg(matcher, key, reg, value, mask);
7606 * Add vport metadata Reg C0 item to matcher
7608 * @param[in, out] matcher
7610 * @param[in, out] key
7611 * Flow matcher value.
7613 * Flow pattern to translate.
7616 flow_dv_translate_item_meta_vport(void *matcher, void *key,
7617 uint32_t value, uint32_t mask)
7619 flow_dv_match_meta_reg(matcher, key, REG_C_0, value, mask);
7623 * Add tag item to matcher
7626 * The devich to configure through.
7627 * @param[in, out] matcher
7629 * @param[in, out] key
7630 * Flow matcher value.
7632 * Flow pattern to translate.
7635 flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev,
7636 void *matcher, void *key,
7637 const struct rte_flow_item *item)
7639 const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
7640 const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
7641 uint32_t mask, value;
7644 value = tag_v->data;
7645 mask = tag_m ? tag_m->data : UINT32_MAX;
7646 if (tag_v->id == REG_C_0) {
7647 struct mlx5_priv *priv = dev->data->dev_private;
7648 uint32_t msk_c0 = priv->sh->dv_regc0_mask;
7649 uint32_t shl_c0 = rte_bsf32(msk_c0);
7655 flow_dv_match_meta_reg(matcher, key, tag_v->id, value, mask);
7659 * Add TAG item to matcher
7662 * The devich to configure through.
7663 * @param[in, out] matcher
7665 * @param[in, out] key
7666 * Flow matcher value.
7668 * Flow pattern to translate.
7671 flow_dv_translate_item_tag(struct rte_eth_dev *dev,
7672 void *matcher, void *key,
7673 const struct rte_flow_item *item)
7675 const struct rte_flow_item_tag *tag_v = item->spec;
7676 const struct rte_flow_item_tag *tag_m = item->mask;
7677 enum modify_reg reg;
7680 tag_m = tag_m ? tag_m : &rte_flow_item_tag_mask;
7681 /* Get the metadata register index for the tag. */
7682 reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, tag_v->index, NULL);
7683 MLX5_ASSERT(reg > 0);
7684 flow_dv_match_meta_reg(matcher, key, reg, tag_v->data, tag_m->data);
7688 * Add source vport match to the specified matcher.
7690 * @param[in, out] matcher
7692 * @param[in, out] key
7693 * Flow matcher value.
7695 * Source vport value to match
7700 flow_dv_translate_item_source_vport(void *matcher, void *key,
7701 int16_t port, uint16_t mask)
7703 void *misc_m = MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
7704 void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
7706 MLX5_SET(fte_match_set_misc, misc_m, source_port, mask);
7707 MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
7711 * Translate port-id item to eswitch match on port-id.
7714 * The devich to configure through.
7715 * @param[in, out] matcher
7717 * @param[in, out] key
7718 * Flow matcher value.
7720 * Flow pattern to translate.
7725 * 0 on success, a negative errno value otherwise.
7728 flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *matcher,
7729 void *key, const struct rte_flow_item *item,
7730 const struct rte_flow_attr *attr)
7732 const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
7733 const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
7734 struct mlx5_priv *priv;
7737 mask = pid_m ? pid_m->id : 0xffff;
7738 id = pid_v ? pid_v->id : dev->data->port_id;
7739 priv = mlx5_port_to_eswitch_info(id, item == NULL);
7743 * Translate to vport field or to metadata, depending on mode.
7744 * Kernel can use either misc.source_port or half of C0 metadata
7747 if (priv->vport_meta_mask) {
7749 * Provide the hint for SW steering library
7750 * to insert the flow into ingress domain and
7751 * save the extra vport match.
7753 if (mask == 0xffff && priv->vport_id == 0xffff &&
7754 priv->pf_bond < 0 && attr->transfer)
7755 flow_dv_translate_item_source_vport
7756 (matcher, key, priv->vport_id, mask);
7758 flow_dv_translate_item_meta_vport
7760 priv->vport_meta_tag,
7761 priv->vport_meta_mask);
7763 flow_dv_translate_item_source_vport(matcher, key,
7764 priv->vport_id, mask);
7770 * Add ICMP6 item to matcher and to the value.
7772 * @param[in, out] matcher
7774 * @param[in, out] key
7775 * Flow matcher value.
7777 * Flow pattern to translate.
7779 * Item is inner pattern.
7782 flow_dv_translate_item_icmp6(void *matcher, void *key,
7783 const struct rte_flow_item *item,
7786 const struct rte_flow_item_icmp6 *icmp6_m = item->mask;
7787 const struct rte_flow_item_icmp6 *icmp6_v = item->spec;
7790 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7792 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7794 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7796 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7798 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7800 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7802 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
7803 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMPV6);
7807 icmp6_m = &rte_flow_item_icmp6_mask;
7808 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_type, icmp6_m->type);
7809 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
7810 icmp6_v->type & icmp6_m->type);
7811 MLX5_SET(fte_match_set_misc3, misc3_m, icmpv6_code, icmp6_m->code);
7812 MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
7813 icmp6_v->code & icmp6_m->code);
7817 * Add ICMP item to matcher and to the value.
7819 * @param[in, out] matcher
7821 * @param[in, out] key
7822 * Flow matcher value.
7824 * Flow pattern to translate.
7826 * Item is inner pattern.
7829 flow_dv_translate_item_icmp(void *matcher, void *key,
7830 const struct rte_flow_item *item,
7833 const struct rte_flow_item_icmp *icmp_m = item->mask;
7834 const struct rte_flow_item_icmp *icmp_v = item->spec;
7835 uint32_t icmp_header_data_m = 0;
7836 uint32_t icmp_header_data_v = 0;
7839 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7841 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7843 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7845 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7847 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7849 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7851 MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xFF);
7852 MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ICMP);
7856 icmp_m = &rte_flow_item_icmp_mask;
7857 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_type,
7858 icmp_m->hdr.icmp_type);
7859 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
7860 icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
7861 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_code,
7862 icmp_m->hdr.icmp_code);
7863 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
7864 icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
7865 icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
7866 icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
7867 if (icmp_header_data_m) {
7868 icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
7869 icmp_header_data_v |=
7870 rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
7871 MLX5_SET(fte_match_set_misc3, misc3_m, icmp_header_data,
7872 icmp_header_data_m);
7873 MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
7874 icmp_header_data_v & icmp_header_data_m);
7879 * Add GTP item to matcher and to the value.
7881 * @param[in, out] matcher
7883 * @param[in, out] key
7884 * Flow matcher value.
7886 * Flow pattern to translate.
7888 * Item is inner pattern.
7891 flow_dv_translate_item_gtp(void *matcher, void *key,
7892 const struct rte_flow_item *item, int inner)
7894 const struct rte_flow_item_gtp *gtp_m = item->mask;
7895 const struct rte_flow_item_gtp *gtp_v = item->spec;
7898 void *misc3_m = MLX5_ADDR_OF(fte_match_param, matcher,
7900 void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
7901 uint16_t dport = RTE_GTPU_UDP_PORT;
7904 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7906 headers_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
7908 headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
7910 headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
7912 if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
7913 MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xFFFF);
7914 MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, dport);
7919 gtp_m = &rte_flow_item_gtp_mask;
7920 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_flags,
7921 gtp_m->v_pt_rsv_flags);
7922 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
7923 gtp_v->v_pt_rsv_flags & gtp_m->v_pt_rsv_flags);
7924 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_msg_type, gtp_m->msg_type);
7925 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
7926 gtp_v->msg_type & gtp_m->msg_type);
7927 MLX5_SET(fte_match_set_misc3, misc3_m, gtpu_teid,
7928 rte_be_to_cpu_32(gtp_m->teid));
7929 MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
7930 rte_be_to_cpu_32(gtp_v->teid & gtp_m->teid));
7934 * Add eCPRI item to matcher and to the value.
7937 * The devich to configure through.
7938 * @param[in, out] matcher
7940 * @param[in, out] key
7941 * Flow matcher value.
7943 * Flow pattern to translate.
7944 * @param[in] samples
7945 * Sample IDs to be used in the matching.
7948 flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *matcher,
7949 void *key, const struct rte_flow_item *item)
7951 struct mlx5_priv *priv = dev->data->dev_private;
7952 const struct rte_flow_item_ecpri *ecpri_m = item->mask;
7953 const struct rte_flow_item_ecpri *ecpri_v = item->spec;
7954 struct rte_ecpri_common_hdr common;
7955 void *misc4_m = MLX5_ADDR_OF(fte_match_param, matcher,
7957 void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
7965 ecpri_m = &rte_flow_item_ecpri_mask;
7967 * Maximal four DW samples are supported in a single matching now.
7968 * Two are used now for a eCPRI matching:
7969 * 1. Type: one byte, mask should be 0x00ff0000 in network order
7970 * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
7973 if (!ecpri_m->hdr.common.u32)
7975 samples = priv->sh->fp[MLX5_FLEX_PARSER_ECPRI_0].ids;
7976 /* Need to take the whole DW as the mask to fill the entry. */
7977 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
7978 prog_sample_field_value_0);
7979 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
7980 prog_sample_field_value_0);
7981 /* Already big endian (network order) in the header. */
7982 *(uint32_t *)dw_m = ecpri_m->hdr.common.u32;
7983 *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
7984 /* Sample#0, used for matching type, offset 0. */
7985 MLX5_SET(fte_match_set_misc4, misc4_m,
7986 prog_sample_field_id_0, samples[0]);
7987 /* It makes no sense to set the sample ID in the mask field. */
7988 MLX5_SET(fte_match_set_misc4, misc4_v,
7989 prog_sample_field_id_0, samples[0]);
7991 * Checking if message body part needs to be matched.
7992 * Some wildcard rules only matching type field should be supported.
7994 if (ecpri_m->hdr.dummy[0]) {
7995 common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
7996 switch (common.type) {
7997 case RTE_ECPRI_MSG_TYPE_IQ_DATA:
7998 case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
7999 case RTE_ECPRI_MSG_TYPE_DLY_MSR:
8000 dw_m = MLX5_ADDR_OF(fte_match_set_misc4, misc4_m,
8001 prog_sample_field_value_1);
8002 dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
8003 prog_sample_field_value_1);
8004 *(uint32_t *)dw_m = ecpri_m->hdr.dummy[0];
8005 *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
8006 ecpri_m->hdr.dummy[0];
8007 /* Sample#1, to match message body, offset 4. */
8008 MLX5_SET(fte_match_set_misc4, misc4_m,
8009 prog_sample_field_id_1, samples[1]);
8010 MLX5_SET(fte_match_set_misc4, misc4_v,
8011 prog_sample_field_id_1, samples[1]);
8014 /* Others, do not match any sample ID. */
8020 static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
8022 #define HEADER_IS_ZERO(match_criteria, headers) \
8023 !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
8024 matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
8027 * Calculate flow matcher enable bitmap.
8029 * @param match_criteria
8030 * Pointer to flow matcher criteria.
8033 * Bitmap of enabled fields.
8036 flow_dv_matcher_enable(uint32_t *match_criteria)
8038 uint8_t match_criteria_enable;
8040 match_criteria_enable =
8041 (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
8042 MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
8043 match_criteria_enable |=
8044 (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
8045 MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
8046 match_criteria_enable |=
8047 (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
8048 MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
8049 match_criteria_enable |=
8050 (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
8051 MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
8052 match_criteria_enable |=
8053 (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
8054 MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
8055 match_criteria_enable |=
8056 (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
8057 MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
8058 return match_criteria_enable;
8061 struct mlx5_hlist_entry *
8062 flow_dv_tbl_create_cb(struct mlx5_hlist *list, uint64_t key64, void *cb_ctx)
8064 struct mlx5_dev_ctx_shared *sh = list->ctx;
8065 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8066 struct rte_eth_dev *dev = ctx->dev;
8067 struct mlx5_flow_tbl_data_entry *tbl_data;
8068 struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data;
8069 struct rte_flow_error *error = ctx->error;
8070 union mlx5_flow_tbl_key key = { .v64 = key64 };
8071 struct mlx5_flow_tbl_resource *tbl;
8076 tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
8078 rte_flow_error_set(error, ENOMEM,
8079 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8081 "cannot allocate flow table data entry");
8084 tbl_data->idx = idx;
8085 tbl_data->tunnel = tt_prm->tunnel;
8086 tbl_data->group_id = tt_prm->group_id;
8087 tbl_data->external = !!tt_prm->external;
8088 tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
8089 tbl_data->is_egress = !!key.direction;
8090 tbl_data->is_transfer = !!key.domain;
8091 tbl_data->dummy = !!key.dummy;
8092 tbl_data->table_id = key.table_id;
8093 tbl = &tbl_data->tbl;
8095 return &tbl_data->entry;
8097 domain = sh->fdb_domain;
8098 else if (key.direction)
8099 domain = sh->tx_domain;
8101 domain = sh->rx_domain;
8102 ret = mlx5_flow_os_create_flow_tbl(domain, key.table_id, &tbl->obj);
8104 rte_flow_error_set(error, ENOMEM,
8105 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8106 NULL, "cannot create flow table object");
8107 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
8111 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
8112 (tbl->obj, &tbl_data->jump.action);
8114 rte_flow_error_set(error, ENOMEM,
8115 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8117 "cannot create flow jump action");
8118 mlx5_flow_os_destroy_flow_tbl(tbl->obj);
8119 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
8123 MKSTR(matcher_name, "%s_%s_%u_matcher_cache",
8124 key.domain ? "FDB" : "NIC", key.direction ? "egress" : "ingress",
8126 mlx5_cache_list_init(&tbl_data->matchers, matcher_name, 0, sh,
8127 flow_dv_matcher_create_cb,
8128 flow_dv_matcher_match_cb,
8129 flow_dv_matcher_remove_cb);
8130 return &tbl_data->entry;
8134 flow_dv_tbl_match_cb(struct mlx5_hlist *list __rte_unused,
8135 struct mlx5_hlist_entry *entry, uint64_t key64,
8136 void *cb_ctx __rte_unused)
8138 struct mlx5_flow_tbl_data_entry *tbl_data =
8139 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
8140 union mlx5_flow_tbl_key key = { .v64 = key64 };
8142 return tbl_data->table_id != key.table_id ||
8143 tbl_data->dummy != key.dummy ||
8144 tbl_data->is_transfer != key.domain ||
8145 tbl_data->is_egress != key.direction;
8151 * @param[in, out] dev
8152 * Pointer to rte_eth_dev structure.
8153 * @param[in] table_id
8156 * Direction of the table.
8157 * @param[in] transfer
8158 * E-Switch or NIC flow.
8160 * Dummy entry for dv API.
8162 * pointer to error structure.
8165 * Returns tables resource based on the index, NULL in case of failed.
8167 struct mlx5_flow_tbl_resource *
8168 flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
8169 uint32_t table_id, uint8_t egress,
8172 const struct mlx5_flow_tunnel *tunnel,
8173 uint32_t group_id, uint8_t dummy,
8174 struct rte_flow_error *error)
8176 struct mlx5_priv *priv = dev->data->dev_private;
8177 union mlx5_flow_tbl_key table_key = {
8179 .table_id = table_id,
8181 .domain = !!transfer,
8182 .direction = !!egress,
8185 struct mlx5_flow_tbl_tunnel_prm tt_prm = {
8187 .group_id = group_id,
8188 .external = external,
8190 struct mlx5_flow_cb_ctx ctx = {
8195 struct mlx5_hlist_entry *entry;
8196 struct mlx5_flow_tbl_data_entry *tbl_data;
8198 entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
8200 rte_flow_error_set(error, ENOMEM,
8201 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8202 "cannot get table");
8205 DRV_LOG(DEBUG, "Table_id %u tunnel %u group %u registered.",
8206 table_id, tunnel ? tunnel->tunnel_id : 0, group_id);
8207 tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
8208 return &tbl_data->tbl;
8212 flow_dv_tbl_remove_cb(struct mlx5_hlist *list,
8213 struct mlx5_hlist_entry *entry)
8215 struct mlx5_dev_ctx_shared *sh = list->ctx;
8216 struct mlx5_flow_tbl_data_entry *tbl_data =
8217 container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
8219 MLX5_ASSERT(entry && sh);
8220 if (tbl_data->jump.action)
8221 mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
8222 if (tbl_data->tbl.obj)
8223 mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
8224 if (tbl_data->tunnel_offload && tbl_data->external) {
8225 struct mlx5_hlist_entry *he;
8226 struct mlx5_hlist *tunnel_grp_hash;
8227 struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
8228 union tunnel_tbl_key tunnel_key = {
8229 .tunnel_id = tbl_data->tunnel ?
8230 tbl_data->tunnel->tunnel_id : 0,
8231 .group = tbl_data->group_id
8233 uint32_t table_id = tbl_data->table_id;
8235 tunnel_grp_hash = tbl_data->tunnel ?
8236 tbl_data->tunnel->groups :
8238 he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, NULL);
8240 mlx5_hlist_unregister(tunnel_grp_hash, he);
8242 "Table_id %u tunnel %u group %u released.",
8245 tbl_data->tunnel->tunnel_id : 0,
8246 tbl_data->group_id);
8248 mlx5_cache_list_destroy(&tbl_data->matchers);
8249 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
8253 * Release a flow table.
8256 * Pointer to device shared structure.
8258 * Table resource to be released.
8261 * Returns 0 if table was released, else return 1;
8264 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
8265 struct mlx5_flow_tbl_resource *tbl)
8267 struct mlx5_flow_tbl_data_entry *tbl_data =
8268 container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
8272 return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
8276 flow_dv_matcher_match_cb(struct mlx5_cache_list *list __rte_unused,
8277 struct mlx5_cache_entry *entry, void *cb_ctx)
8279 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8280 struct mlx5_flow_dv_matcher *ref = ctx->data;
8281 struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
8284 return cur->crc != ref->crc ||
8285 cur->priority != ref->priority ||
8286 memcmp((const void *)cur->mask.buf,
8287 (const void *)ref->mask.buf, ref->mask.size);
8290 struct mlx5_cache_entry *
8291 flow_dv_matcher_create_cb(struct mlx5_cache_list *list,
8292 struct mlx5_cache_entry *entry __rte_unused,
8295 struct mlx5_dev_ctx_shared *sh = list->ctx;
8296 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8297 struct mlx5_flow_dv_matcher *ref = ctx->data;
8298 struct mlx5_flow_dv_matcher *cache;
8299 struct mlx5dv_flow_matcher_attr dv_attr = {
8300 .type = IBV_FLOW_ATTR_NORMAL,
8301 .match_mask = (void *)&ref->mask,
8303 struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
8307 cache = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*cache), 0, SOCKET_ID_ANY);
8309 rte_flow_error_set(ctx->error, ENOMEM,
8310 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8311 "cannot create matcher");
8315 dv_attr.match_criteria_enable =
8316 flow_dv_matcher_enable(cache->mask.buf);
8317 dv_attr.priority = ref->priority;
8319 dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
8320 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->tbl.obj,
8321 &cache->matcher_object);
8324 rte_flow_error_set(ctx->error, ENOMEM,
8325 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8326 "cannot create matcher");
8329 return &cache->entry;
8333 * Register the flow matcher.
8335 * @param[in, out] dev
8336 * Pointer to rte_eth_dev structure.
8337 * @param[in, out] matcher
8338 * Pointer to flow matcher.
8339 * @param[in, out] key
8340 * Pointer to flow table key.
8341 * @parm[in, out] dev_flow
8342 * Pointer to the dev_flow.
8344 * pointer to error structure.
8347 * 0 on success otherwise -errno and errno is set.
8350 flow_dv_matcher_register(struct rte_eth_dev *dev,
8351 struct mlx5_flow_dv_matcher *ref,
8352 union mlx5_flow_tbl_key *key,
8353 struct mlx5_flow *dev_flow,
8354 const struct mlx5_flow_tunnel *tunnel,
8356 struct rte_flow_error *error)
8358 struct mlx5_cache_entry *entry;
8359 struct mlx5_flow_dv_matcher *cache;
8360 struct mlx5_flow_tbl_resource *tbl;
8361 struct mlx5_flow_tbl_data_entry *tbl_data;
8362 struct mlx5_flow_cb_ctx ctx = {
8368 * tunnel offload API requires this registration for cases when
8369 * tunnel match rule was inserted before tunnel set rule.
8371 tbl = flow_dv_tbl_resource_get(dev, key->table_id,
8372 key->direction, key->domain,
8373 dev_flow->external, tunnel,
8374 group_id, 0, error);
8376 return -rte_errno; /* No need to refill the error info */
8377 tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
8379 entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
8381 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
8382 return rte_flow_error_set(error, ENOMEM,
8383 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8384 "cannot allocate ref memory");
8386 cache = container_of(entry, typeof(*cache), entry);
8387 dev_flow->handle->dvh.matcher = cache;
8391 struct mlx5_hlist_entry *
8392 flow_dv_tag_create_cb(struct mlx5_hlist *list, uint64_t key, void *ctx)
8394 struct mlx5_dev_ctx_shared *sh = list->ctx;
8395 struct rte_flow_error *error = ctx;
8396 struct mlx5_flow_dv_tag_resource *entry;
8400 entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
8402 rte_flow_error_set(error, ENOMEM,
8403 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8404 "cannot allocate resource memory");
8408 entry->tag_id = key;
8409 ret = mlx5_flow_os_create_flow_action_tag(key,
8412 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
8413 rte_flow_error_set(error, ENOMEM,
8414 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8415 NULL, "cannot create action");
8418 return &entry->entry;
8422 flow_dv_tag_match_cb(struct mlx5_hlist *list __rte_unused,
8423 struct mlx5_hlist_entry *entry, uint64_t key,
8424 void *cb_ctx __rte_unused)
8426 struct mlx5_flow_dv_tag_resource *tag =
8427 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
8429 return key != tag->tag_id;
8433 * Find existing tag resource or create and register a new one.
8435 * @param dev[in, out]
8436 * Pointer to rte_eth_dev structure.
8437 * @param[in, out] tag_be24
8438 * Tag value in big endian then R-shift 8.
8439 * @parm[in, out] dev_flow
8440 * Pointer to the dev_flow.
8442 * pointer to error structure.
8445 * 0 on success otherwise -errno and errno is set.
8448 flow_dv_tag_resource_register
8449 (struct rte_eth_dev *dev,
8451 struct mlx5_flow *dev_flow,
8452 struct rte_flow_error *error)
8454 struct mlx5_priv *priv = dev->data->dev_private;
8455 struct mlx5_flow_dv_tag_resource *cache_resource;
8456 struct mlx5_hlist_entry *entry;
8458 entry = mlx5_hlist_register(priv->sh->tag_table, tag_be24, error);
8460 cache_resource = container_of
8461 (entry, struct mlx5_flow_dv_tag_resource, entry);
8462 dev_flow->handle->dvh.rix_tag = cache_resource->idx;
8463 dev_flow->dv.tag_resource = cache_resource;
8470 flow_dv_tag_remove_cb(struct mlx5_hlist *list,
8471 struct mlx5_hlist_entry *entry)
8473 struct mlx5_dev_ctx_shared *sh = list->ctx;
8474 struct mlx5_flow_dv_tag_resource *tag =
8475 container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
8477 MLX5_ASSERT(tag && sh && tag->action);
8478 claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
8479 DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
8480 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
8487 * Pointer to Ethernet device.
8492 * 1 while a reference on it exists, 0 when freed.
8495 flow_dv_tag_release(struct rte_eth_dev *dev,
8498 struct mlx5_priv *priv = dev->data->dev_private;
8499 struct mlx5_flow_dv_tag_resource *tag;
8501 tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
8504 DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
8505 dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
8506 return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
8510 * Translate port ID action to vport.
8513 * Pointer to rte_eth_dev structure.
8515 * Pointer to the port ID action.
8516 * @param[out] dst_port_id
8517 * The target port ID.
8519 * Pointer to the error structure.
8522 * 0 on success, a negative errno value otherwise and rte_errno is set.
8525 flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
8526 const struct rte_flow_action *action,
8527 uint32_t *dst_port_id,
8528 struct rte_flow_error *error)
8531 struct mlx5_priv *priv;
8532 const struct rte_flow_action_port_id *conf =
8533 (const struct rte_flow_action_port_id *)action->conf;
8535 port = conf->original ? dev->data->port_id : conf->id;
8536 priv = mlx5_port_to_eswitch_info(port, false);
8538 return rte_flow_error_set(error, -rte_errno,
8539 RTE_FLOW_ERROR_TYPE_ACTION,
8541 "No eswitch info was found for port");
8542 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
8544 * This parameter is transferred to
8545 * mlx5dv_dr_action_create_dest_ib_port().
8547 *dst_port_id = priv->dev_port;
8550 * Legacy mode, no LAG configurations is supported.
8551 * This parameter is transferred to
8552 * mlx5dv_dr_action_create_dest_vport().
8554 *dst_port_id = priv->vport_id;
8560 * Create a counter with aging configuration.
8563 * Pointer to rte_eth_dev structure.
8565 * Pointer to the counter action configuration.
8567 * Pointer to the aging action configuration.
8570 * Index to flow counter on success, 0 otherwise.
8573 flow_dv_translate_create_counter(struct rte_eth_dev *dev,
8574 struct mlx5_flow *dev_flow,
8575 const struct rte_flow_action_count *count,
8576 const struct rte_flow_action_age *age)
8579 struct mlx5_age_param *age_param;
8581 if (count && count->shared)
8582 counter = flow_dv_counter_get_shared(dev, count->id);
8584 counter = flow_dv_counter_alloc(dev, !!age);
8585 if (!counter || age == NULL)
8587 age_param = flow_dv_counter_idx_get_age(dev, counter);
8588 age_param->context = age->context ? age->context :
8589 (void *)(uintptr_t)(dev_flow->flow_idx);
8590 age_param->timeout = age->timeout;
8591 age_param->port_id = dev->data->port_id;
8592 __atomic_store_n(&age_param->sec_since_last_hit, 0, __ATOMIC_RELAXED);
8593 __atomic_store_n(&age_param->state, AGE_CANDIDATE, __ATOMIC_RELAXED);
8598 * Add Tx queue matcher
8601 * Pointer to the dev struct.
8602 * @param[in, out] matcher
8604 * @param[in, out] key
8605 * Flow matcher value.
8607 * Flow pattern to translate.
8609 * Item is inner pattern.
8612 flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev,
8613 void *matcher, void *key,
8614 const struct rte_flow_item *item)
8616 const struct mlx5_rte_flow_item_tx_queue *queue_m;
8617 const struct mlx5_rte_flow_item_tx_queue *queue_v;
8619 MLX5_ADDR_OF(fte_match_param, matcher, misc_parameters);
8621 MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
8622 struct mlx5_txq_ctrl *txq;
8626 queue_m = (const void *)item->mask;
8629 queue_v = (const void *)item->spec;
8632 txq = mlx5_txq_get(dev, queue_v->queue);
8635 queue = txq->obj->sq->id;
8636 MLX5_SET(fte_match_set_misc, misc_m, source_sqn, queue_m->queue);
8637 MLX5_SET(fte_match_set_misc, misc_v, source_sqn,
8638 queue & queue_m->queue);
8639 mlx5_txq_release(dev, queue_v->queue);
8643 * Set the hash fields according to the @p flow information.
8645 * @param[in] dev_flow
8646 * Pointer to the mlx5_flow.
8647 * @param[in] rss_desc
8648 * Pointer to the mlx5_flow_rss_desc.
8651 flow_dv_hashfields_set(struct mlx5_flow *dev_flow,
8652 struct mlx5_flow_rss_desc *rss_desc)
8654 uint64_t items = dev_flow->handle->layers;
8656 uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
8658 dev_flow->hash_fields = 0;
8659 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
8660 if (rss_desc->level >= 2) {
8661 dev_flow->hash_fields |= IBV_RX_HASH_INNER;
8665 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
8666 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
8667 if (rss_types & MLX5_IPV4_LAYER_TYPES) {
8668 if (rss_types & ETH_RSS_L3_SRC_ONLY)
8669 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV4;
8670 else if (rss_types & ETH_RSS_L3_DST_ONLY)
8671 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV4;
8673 dev_flow->hash_fields |= MLX5_IPV4_IBV_RX_HASH;
8675 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
8676 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
8677 if (rss_types & MLX5_IPV6_LAYER_TYPES) {
8678 if (rss_types & ETH_RSS_L3_SRC_ONLY)
8679 dev_flow->hash_fields |= IBV_RX_HASH_SRC_IPV6;
8680 else if (rss_types & ETH_RSS_L3_DST_ONLY)
8681 dev_flow->hash_fields |= IBV_RX_HASH_DST_IPV6;
8683 dev_flow->hash_fields |= MLX5_IPV6_IBV_RX_HASH;
8686 if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
8687 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
8688 if (rss_types & ETH_RSS_UDP) {
8689 if (rss_types & ETH_RSS_L4_SRC_ONLY)
8690 dev_flow->hash_fields |=
8691 IBV_RX_HASH_SRC_PORT_UDP;
8692 else if (rss_types & ETH_RSS_L4_DST_ONLY)
8693 dev_flow->hash_fields |=
8694 IBV_RX_HASH_DST_PORT_UDP;
8696 dev_flow->hash_fields |= MLX5_UDP_IBV_RX_HASH;
8698 } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
8699 (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
8700 if (rss_types & ETH_RSS_TCP) {
8701 if (rss_types & ETH_RSS_L4_SRC_ONLY)
8702 dev_flow->hash_fields |=
8703 IBV_RX_HASH_SRC_PORT_TCP;
8704 else if (rss_types & ETH_RSS_L4_DST_ONLY)
8705 dev_flow->hash_fields |=
8706 IBV_RX_HASH_DST_PORT_TCP;
8708 dev_flow->hash_fields |= MLX5_TCP_IBV_RX_HASH;
8714 * Prepare an Rx Hash queue.
8717 * Pointer to Ethernet device.
8718 * @param[in] dev_flow
8719 * Pointer to the mlx5_flow.
8720 * @param[in] rss_desc
8721 * Pointer to the mlx5_flow_rss_desc.
8722 * @param[out] hrxq_idx
8723 * Hash Rx queue index.
8726 * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
8728 static struct mlx5_hrxq *
8729 flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
8730 struct mlx5_flow *dev_flow,
8731 struct mlx5_flow_rss_desc *rss_desc,
8734 struct mlx5_priv *priv = dev->data->dev_private;
8735 struct mlx5_flow_handle *dh = dev_flow->handle;
8736 struct mlx5_hrxq *hrxq;
8738 MLX5_ASSERT(rss_desc->queue_num);
8739 rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
8740 rss_desc->hash_fields = dev_flow->hash_fields;
8741 rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
8742 rss_desc->shared_rss = 0;
8743 *hrxq_idx = mlx5_hrxq_get(dev, rss_desc);
8746 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
8752 * Release sample sub action resource.
8754 * @param[in, out] dev
8755 * Pointer to rte_eth_dev structure.
8756 * @param[in] act_res
8757 * Pointer to sample sub action resource.
8760 flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
8761 struct mlx5_flow_sub_actions_idx *act_res)
8763 if (act_res->rix_hrxq) {
8764 mlx5_hrxq_release(dev, act_res->rix_hrxq);
8765 act_res->rix_hrxq = 0;
8767 if (act_res->rix_encap_decap) {
8768 flow_dv_encap_decap_resource_release(dev,
8769 act_res->rix_encap_decap);
8770 act_res->rix_encap_decap = 0;
8772 if (act_res->rix_port_id_action) {
8773 flow_dv_port_id_action_resource_release(dev,
8774 act_res->rix_port_id_action);
8775 act_res->rix_port_id_action = 0;
8777 if (act_res->rix_tag) {
8778 flow_dv_tag_release(dev, act_res->rix_tag);
8779 act_res->rix_tag = 0;
8782 flow_dv_counter_free(dev, act_res->cnt);
8788 flow_dv_sample_match_cb(struct mlx5_cache_list *list __rte_unused,
8789 struct mlx5_cache_entry *entry, void *cb_ctx)
8791 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8792 struct rte_eth_dev *dev = ctx->dev;
8793 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
8794 struct mlx5_flow_dv_sample_resource *cache_resource =
8795 container_of(entry, typeof(*cache_resource), entry);
8797 if (resource->ratio == cache_resource->ratio &&
8798 resource->ft_type == cache_resource->ft_type &&
8799 resource->ft_id == cache_resource->ft_id &&
8800 resource->set_action == cache_resource->set_action &&
8801 !memcmp((void *)&resource->sample_act,
8802 (void *)&cache_resource->sample_act,
8803 sizeof(struct mlx5_flow_sub_actions_list))) {
8805 * Existing sample action should release the prepared
8806 * sub-actions reference counter.
8808 flow_dv_sample_sub_actions_release(dev,
8809 &resource->sample_idx);
8815 struct mlx5_cache_entry *
8816 flow_dv_sample_create_cb(struct mlx5_cache_list *list __rte_unused,
8817 struct mlx5_cache_entry *entry __rte_unused,
8820 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8821 struct rte_eth_dev *dev = ctx->dev;
8822 struct mlx5_flow_dv_sample_resource *resource = ctx->data;
8823 void **sample_dv_actions = resource->sub_actions;
8824 struct mlx5_flow_dv_sample_resource *cache_resource;
8825 struct mlx5dv_dr_flow_sampler_attr sampler_attr;
8826 struct mlx5_priv *priv = dev->data->dev_private;
8827 struct mlx5_dev_ctx_shared *sh = priv->sh;
8828 struct mlx5_flow_tbl_resource *tbl;
8830 const uint32_t next_ft_step = 1;
8831 uint32_t next_ft_id = resource->ft_id + next_ft_step;
8832 uint8_t is_egress = 0;
8833 uint8_t is_transfer = 0;
8834 struct rte_flow_error *error = ctx->error;
8836 /* Register new sample resource. */
8837 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
8838 if (!cache_resource) {
8839 rte_flow_error_set(error, ENOMEM,
8840 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8842 "cannot allocate resource memory");
8845 *cache_resource = *resource;
8846 /* Create normal path table level */
8847 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
8849 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
8851 tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
8852 is_egress, is_transfer,
8853 true, NULL, 0, 0, error);
8855 rte_flow_error_set(error, ENOMEM,
8856 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8858 "fail to create normal path table "
8864 cache_resource->normal_path_tbl = tbl;
8865 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
8866 ret = mlx5_flow_os_create_flow_action_default_miss
8867 (&cache_resource->default_miss);
8869 rte_flow_error_set(error, ENOMEM,
8870 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8872 "cannot create default miss "
8876 sample_dv_actions[resource->sample_act.actions_num++] =
8877 cache_resource->default_miss;
8879 /* Create a DR sample action */
8880 sampler_attr.sample_ratio = cache_resource->ratio;
8881 sampler_attr.default_next_table = tbl->obj;
8882 sampler_attr.num_sample_actions = resource->sample_act.actions_num;
8883 sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
8884 &sample_dv_actions[0];
8885 sampler_attr.action = cache_resource->set_action;
8886 if (mlx5_os_flow_dr_create_flow_action_sampler
8887 (&sampler_attr, &cache_resource->verbs_action)) {
8888 rte_flow_error_set(error, ENOMEM,
8889 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8890 NULL, "cannot create sample action");
8893 cache_resource->idx = idx;
8894 cache_resource->dev = dev;
8895 return &cache_resource->entry;
8897 if (cache_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB &&
8898 cache_resource->default_miss)
8899 claim_zero(mlx5_flow_os_destroy_flow_action
8900 (cache_resource->default_miss));
8902 flow_dv_sample_sub_actions_release(dev,
8903 &cache_resource->sample_idx);
8904 if (cache_resource->normal_path_tbl)
8905 flow_dv_tbl_resource_release(MLX5_SH(dev),
8906 cache_resource->normal_path_tbl);
8907 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
8913 * Find existing sample resource or create and register a new one.
8915 * @param[in, out] dev
8916 * Pointer to rte_eth_dev structure.
8917 * @param[in] resource
8918 * Pointer to sample resource.
8919 * @parm[in, out] dev_flow
8920 * Pointer to the dev_flow.
8922 * pointer to error structure.
8925 * 0 on success otherwise -errno and errno is set.
8928 flow_dv_sample_resource_register(struct rte_eth_dev *dev,
8929 struct mlx5_flow_dv_sample_resource *resource,
8930 struct mlx5_flow *dev_flow,
8931 struct rte_flow_error *error)
8933 struct mlx5_flow_dv_sample_resource *cache_resource;
8934 struct mlx5_cache_entry *entry;
8935 struct mlx5_priv *priv = dev->data->dev_private;
8936 struct mlx5_flow_cb_ctx ctx = {
8942 entry = mlx5_cache_register(&priv->sh->sample_action_list, &ctx);
8945 cache_resource = container_of(entry, typeof(*cache_resource), entry);
8946 dev_flow->handle->dvh.rix_sample = cache_resource->idx;
8947 dev_flow->dv.sample_res = cache_resource;
8952 flow_dv_dest_array_match_cb(struct mlx5_cache_list *list __rte_unused,
8953 struct mlx5_cache_entry *entry, void *cb_ctx)
8955 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8956 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
8957 struct rte_eth_dev *dev = ctx->dev;
8958 struct mlx5_flow_dv_dest_array_resource *cache_resource =
8959 container_of(entry, typeof(*cache_resource), entry);
8962 if (resource->num_of_dest == cache_resource->num_of_dest &&
8963 resource->ft_type == cache_resource->ft_type &&
8964 !memcmp((void *)cache_resource->sample_act,
8965 (void *)resource->sample_act,
8966 (resource->num_of_dest *
8967 sizeof(struct mlx5_flow_sub_actions_list)))) {
8969 * Existing sample action should release the prepared
8970 * sub-actions reference counter.
8972 for (idx = 0; idx < resource->num_of_dest; idx++)
8973 flow_dv_sample_sub_actions_release(dev,
8974 &resource->sample_idx[idx]);
8980 struct mlx5_cache_entry *
8981 flow_dv_dest_array_create_cb(struct mlx5_cache_list *list __rte_unused,
8982 struct mlx5_cache_entry *entry __rte_unused,
8985 struct mlx5_flow_cb_ctx *ctx = cb_ctx;
8986 struct rte_eth_dev *dev = ctx->dev;
8987 struct mlx5_flow_dv_dest_array_resource *cache_resource;
8988 struct mlx5_flow_dv_dest_array_resource *resource = ctx->data;
8989 struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
8990 struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
8991 struct mlx5_priv *priv = dev->data->dev_private;
8992 struct mlx5_dev_ctx_shared *sh = priv->sh;
8993 struct mlx5_flow_sub_actions_list *sample_act;
8994 struct mlx5dv_dr_domain *domain;
8995 uint32_t idx = 0, res_idx = 0;
8996 struct rte_flow_error *error = ctx->error;
8999 /* Register new destination array resource. */
9000 cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
9002 if (!cache_resource) {
9003 rte_flow_error_set(error, ENOMEM,
9004 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9006 "cannot allocate resource memory");
9009 *cache_resource = *resource;
9010 if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
9011 domain = sh->fdb_domain;
9012 else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
9013 domain = sh->rx_domain;
9015 domain = sh->tx_domain;
9016 for (idx = 0; idx < resource->num_of_dest; idx++) {
9017 dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
9018 mlx5_malloc(MLX5_MEM_ZERO,
9019 sizeof(struct mlx5dv_dr_action_dest_attr),
9021 if (!dest_attr[idx]) {
9022 rte_flow_error_set(error, ENOMEM,
9023 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9025 "cannot allocate resource memory");
9028 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
9029 sample_act = &resource->sample_act[idx];
9030 if (sample_act->action_flags == MLX5_FLOW_ACTION_QUEUE) {
9031 dest_attr[idx]->dest = sample_act->dr_queue_action;
9032 } else if (sample_act->action_flags ==
9033 (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP)) {
9034 dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
9035 dest_attr[idx]->dest_reformat = &dest_reformat[idx];
9036 dest_attr[idx]->dest_reformat->reformat =
9037 sample_act->dr_encap_action;
9038 dest_attr[idx]->dest_reformat->dest =
9039 sample_act->dr_port_id_action;
9040 } else if (sample_act->action_flags ==
9041 MLX5_FLOW_ACTION_PORT_ID) {
9042 dest_attr[idx]->dest = sample_act->dr_port_id_action;
9045 /* create a dest array actioin */
9046 ret = mlx5_os_flow_dr_create_flow_action_dest_array
9048 cache_resource->num_of_dest,
9050 &cache_resource->action);
9052 rte_flow_error_set(error, ENOMEM,
9053 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9055 "cannot create destination array action");
9058 cache_resource->idx = res_idx;
9059 cache_resource->dev = dev;
9060 for (idx = 0; idx < resource->num_of_dest; idx++)
9061 mlx5_free(dest_attr[idx]);
9062 return &cache_resource->entry;
9064 for (idx = 0; idx < resource->num_of_dest; idx++) {
9065 struct mlx5_flow_sub_actions_idx *act_res =
9066 &cache_resource->sample_idx[idx];
9067 if (act_res->rix_hrxq &&
9068 !mlx5_hrxq_release(dev,
9070 act_res->rix_hrxq = 0;
9071 if (act_res->rix_encap_decap &&
9072 !flow_dv_encap_decap_resource_release(dev,
9073 act_res->rix_encap_decap))
9074 act_res->rix_encap_decap = 0;
9075 if (act_res->rix_port_id_action &&
9076 !flow_dv_port_id_action_resource_release(dev,
9077 act_res->rix_port_id_action))
9078 act_res->rix_port_id_action = 0;
9080 mlx5_free(dest_attr[idx]);
9083 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
9088 * Find existing destination array resource or create and register a new one.
9090 * @param[in, out] dev
9091 * Pointer to rte_eth_dev structure.
9092 * @param[in] resource
9093 * Pointer to destination array resource.
9094 * @parm[in, out] dev_flow
9095 * Pointer to the dev_flow.
9097 * pointer to error structure.
9100 * 0 on success otherwise -errno and errno is set.
9103 flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
9104 struct mlx5_flow_dv_dest_array_resource *resource,
9105 struct mlx5_flow *dev_flow,
9106 struct rte_flow_error *error)
9108 struct mlx5_flow_dv_dest_array_resource *cache_resource;
9109 struct mlx5_priv *priv = dev->data->dev_private;
9110 struct mlx5_cache_entry *entry;
9111 struct mlx5_flow_cb_ctx ctx = {
9117 entry = mlx5_cache_register(&priv->sh->dest_array_list, &ctx);
9120 cache_resource = container_of(entry, typeof(*cache_resource), entry);
9121 dev_flow->handle->dvh.rix_dest_array = cache_resource->idx;
9122 dev_flow->dv.dest_array_res = cache_resource;
9127 * Convert Sample action to DV specification.
9130 * Pointer to rte_eth_dev structure.
9132 * Pointer to action structure.
9133 * @param[in, out] dev_flow
9134 * Pointer to the mlx5_flow.
9136 * Pointer to the flow attributes.
9137 * @param[in, out] num_of_dest
9138 * Pointer to the num of destination.
9139 * @param[in, out] sample_actions
9140 * Pointer to sample actions list.
9141 * @param[in, out] res
9142 * Pointer to sample resource.
9144 * Pointer to the error structure.
9147 * 0 on success, a negative errno value otherwise and rte_errno is set.
9150 flow_dv_translate_action_sample(struct rte_eth_dev *dev,
9151 const struct rte_flow_action *action,
9152 struct mlx5_flow *dev_flow,
9153 const struct rte_flow_attr *attr,
9154 uint32_t *num_of_dest,
9155 void **sample_actions,
9156 struct mlx5_flow_dv_sample_resource *res,
9157 struct rte_flow_error *error)
9159 struct mlx5_priv *priv = dev->data->dev_private;
9160 const struct rte_flow_action_sample *sample_action;
9161 const struct rte_flow_action *sub_actions;
9162 const struct rte_flow_action_queue *queue;
9163 struct mlx5_flow_sub_actions_list *sample_act;
9164 struct mlx5_flow_sub_actions_idx *sample_idx;
9165 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
9166 struct mlx5_flow_rss_desc *rss_desc;
9167 uint64_t action_flags = 0;
9170 rss_desc = &wks->rss_desc;
9171 sample_act = &res->sample_act;
9172 sample_idx = &res->sample_idx;
9173 sample_action = (const struct rte_flow_action_sample *)action->conf;
9174 res->ratio = sample_action->ratio;
9175 sub_actions = sample_action->actions;
9176 for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
9177 int type = sub_actions->type;
9178 uint32_t pre_rix = 0;
9181 case RTE_FLOW_ACTION_TYPE_QUEUE:
9183 struct mlx5_hrxq *hrxq;
9186 queue = sub_actions->conf;
9187 rss_desc->queue_num = 1;
9188 rss_desc->queue[0] = queue->index;
9189 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
9190 rss_desc, &hrxq_idx);
9192 return rte_flow_error_set
9194 RTE_FLOW_ERROR_TYPE_ACTION,
9196 "cannot create fate queue");
9197 sample_act->dr_queue_action = hrxq->action;
9198 sample_idx->rix_hrxq = hrxq_idx;
9199 sample_actions[sample_act->actions_num++] =
9202 action_flags |= MLX5_FLOW_ACTION_QUEUE;
9203 if (action_flags & MLX5_FLOW_ACTION_MARK)
9204 dev_flow->handle->rix_hrxq = hrxq_idx;
9205 dev_flow->handle->fate_action =
9206 MLX5_FLOW_FATE_QUEUE;
9209 case RTE_FLOW_ACTION_TYPE_MARK:
9211 uint32_t tag_be = mlx5_flow_mark_set
9212 (((const struct rte_flow_action_mark *)
9213 (sub_actions->conf))->id);
9215 dev_flow->handle->mark = 1;
9216 pre_rix = dev_flow->handle->dvh.rix_tag;
9217 /* Save the mark resource before sample */
9218 pre_r = dev_flow->dv.tag_resource;
9219 if (flow_dv_tag_resource_register(dev, tag_be,
9222 MLX5_ASSERT(dev_flow->dv.tag_resource);
9223 sample_act->dr_tag_action =
9224 dev_flow->dv.tag_resource->action;
9225 sample_idx->rix_tag =
9226 dev_flow->handle->dvh.rix_tag;
9227 sample_actions[sample_act->actions_num++] =
9228 sample_act->dr_tag_action;
9229 /* Recover the mark resource after sample */
9230 dev_flow->dv.tag_resource = pre_r;
9231 dev_flow->handle->dvh.rix_tag = pre_rix;
9232 action_flags |= MLX5_FLOW_ACTION_MARK;
9235 case RTE_FLOW_ACTION_TYPE_COUNT:
9239 counter = flow_dv_translate_create_counter(dev,
9240 dev_flow, sub_actions->conf, 0);
9242 return rte_flow_error_set
9244 RTE_FLOW_ERROR_TYPE_ACTION,
9246 "cannot create counter"
9248 sample_idx->cnt = counter;
9249 sample_act->dr_cnt_action =
9250 (flow_dv_counter_get_by_idx(dev,
9251 counter, NULL))->action;
9252 sample_actions[sample_act->actions_num++] =
9253 sample_act->dr_cnt_action;
9254 action_flags |= MLX5_FLOW_ACTION_COUNT;
9257 case RTE_FLOW_ACTION_TYPE_PORT_ID:
9259 struct mlx5_flow_dv_port_id_action_resource
9261 uint32_t port_id = 0;
9263 memset(&port_id_resource, 0, sizeof(port_id_resource));
9264 /* Save the port id resource before sample */
9265 pre_rix = dev_flow->handle->rix_port_id_action;
9266 pre_r = dev_flow->dv.port_id_action;
9267 if (flow_dv_translate_action_port_id(dev, sub_actions,
9270 port_id_resource.port_id = port_id;
9271 if (flow_dv_port_id_action_resource_register
9272 (dev, &port_id_resource, dev_flow, error))
9274 sample_act->dr_port_id_action =
9275 dev_flow->dv.port_id_action->action;
9276 sample_idx->rix_port_id_action =
9277 dev_flow->handle->rix_port_id_action;
9278 sample_actions[sample_act->actions_num++] =
9279 sample_act->dr_port_id_action;
9280 /* Recover the port id resource after sample */
9281 dev_flow->dv.port_id_action = pre_r;
9282 dev_flow->handle->rix_port_id_action = pre_rix;
9284 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
9287 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
9288 /* Save the encap resource before sample */
9289 pre_rix = dev_flow->handle->dvh.rix_encap_decap;
9290 pre_r = dev_flow->dv.encap_decap;
9291 if (flow_dv_create_action_l2_encap(dev, sub_actions,
9296 sample_act->dr_encap_action =
9297 dev_flow->dv.encap_decap->action;
9298 sample_idx->rix_encap_decap =
9299 dev_flow->handle->dvh.rix_encap_decap;
9300 sample_actions[sample_act->actions_num++] =
9301 sample_act->dr_encap_action;
9302 /* Recover the encap resource after sample */
9303 dev_flow->dv.encap_decap = pre_r;
9304 dev_flow->handle->dvh.rix_encap_decap = pre_rix;
9305 action_flags |= MLX5_FLOW_ACTION_ENCAP;
9308 return rte_flow_error_set(error, EINVAL,
9309 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9311 "Not support for sampler action");
9314 sample_act->action_flags = action_flags;
9315 res->ft_id = dev_flow->dv.group;
9316 if (attr->transfer) {
9318 uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
9319 uint64_t set_action;
9320 } action_ctx = { .set_action = 0 };
9322 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
9323 MLX5_SET(set_action_in, action_ctx.action_in, action_type,
9324 MLX5_MODIFICATION_TYPE_SET);
9325 MLX5_SET(set_action_in, action_ctx.action_in, field,
9326 MLX5_MODI_META_REG_C_0);
9327 MLX5_SET(set_action_in, action_ctx.action_in, data,
9328 priv->vport_meta_tag);
9329 res->set_action = action_ctx.set_action;
9330 } else if (attr->ingress) {
9331 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
9333 res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
9339 * Convert Sample action to DV specification.
9342 * Pointer to rte_eth_dev structure.
9343 * @param[in, out] dev_flow
9344 * Pointer to the mlx5_flow.
9345 * @param[in] num_of_dest
9346 * The num of destination.
9347 * @param[in, out] res
9348 * Pointer to sample resource.
9349 * @param[in, out] mdest_res
9350 * Pointer to destination array resource.
9351 * @param[in] sample_actions
9352 * Pointer to sample path actions list.
9353 * @param[in] action_flags
9354 * Holds the actions detected until now.
9356 * Pointer to the error structure.
9359 * 0 on success, a negative errno value otherwise and rte_errno is set.
9362 flow_dv_create_action_sample(struct rte_eth_dev *dev,
9363 struct mlx5_flow *dev_flow,
9364 uint32_t num_of_dest,
9365 struct mlx5_flow_dv_sample_resource *res,
9366 struct mlx5_flow_dv_dest_array_resource *mdest_res,
9367 void **sample_actions,
9368 uint64_t action_flags,
9369 struct rte_flow_error *error)
9371 /* update normal path action resource into last index of array */
9372 uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
9373 struct mlx5_flow_sub_actions_list *sample_act =
9374 &mdest_res->sample_act[dest_index];
9375 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
9376 struct mlx5_flow_rss_desc *rss_desc;
9377 uint32_t normal_idx = 0;
9378 struct mlx5_hrxq *hrxq;
9382 rss_desc = &wks->rss_desc;
9383 if (num_of_dest > 1) {
9384 if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
9385 /* Handle QP action for mirroring */
9386 hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
9387 rss_desc, &hrxq_idx);
9389 return rte_flow_error_set
9391 RTE_FLOW_ERROR_TYPE_ACTION,
9393 "cannot create rx queue");
9395 mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
9396 sample_act->dr_queue_action = hrxq->action;
9397 if (action_flags & MLX5_FLOW_ACTION_MARK)
9398 dev_flow->handle->rix_hrxq = hrxq_idx;
9399 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
9401 if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
9403 mdest_res->sample_idx[dest_index].rix_encap_decap =
9404 dev_flow->handle->dvh.rix_encap_decap;
9405 sample_act->dr_encap_action =
9406 dev_flow->dv.encap_decap->action;
9408 if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
9410 mdest_res->sample_idx[dest_index].rix_port_id_action =
9411 dev_flow->handle->rix_port_id_action;
9412 sample_act->dr_port_id_action =
9413 dev_flow->dv.port_id_action->action;
9415 sample_act->actions_num = normal_idx;
9416 /* update sample action resource into first index of array */
9417 mdest_res->ft_type = res->ft_type;
9418 memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
9419 sizeof(struct mlx5_flow_sub_actions_idx));
9420 memcpy(&mdest_res->sample_act[0], &res->sample_act,
9421 sizeof(struct mlx5_flow_sub_actions_list));
9422 mdest_res->num_of_dest = num_of_dest;
9423 if (flow_dv_dest_array_resource_register(dev, mdest_res,
9425 return rte_flow_error_set(error, EINVAL,
9426 RTE_FLOW_ERROR_TYPE_ACTION,
9427 NULL, "can't create sample "
9430 res->sub_actions = sample_actions;
9431 if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
9432 return rte_flow_error_set(error, EINVAL,
9433 RTE_FLOW_ERROR_TYPE_ACTION,
9435 "can't create sample action");
9441 * Remove an ASO age action from age actions list.
9444 * Pointer to the Ethernet device structure.
9446 * Pointer to the aso age action handler.
9449 flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
9450 struct mlx5_aso_age_action *age)
9452 struct mlx5_age_info *age_info;
9453 struct mlx5_age_param *age_param = &age->age_params;
9454 struct mlx5_priv *priv = dev->data->dev_private;
9455 uint16_t expected = AGE_CANDIDATE;
9457 age_info = GET_PORT_AGE_INFO(priv);
9458 if (!__atomic_compare_exchange_n(&age_param->state, &expected,
9459 AGE_FREE, false, __ATOMIC_RELAXED,
9460 __ATOMIC_RELAXED)) {
9462 * We need the lock even it is age timeout,
9463 * since age action may still in process.
9465 rte_spinlock_lock(&age_info->aged_sl);
9466 LIST_REMOVE(age, next);
9467 rte_spinlock_unlock(&age_info->aged_sl);
9468 __atomic_store_n(&age_param->state, AGE_FREE, __ATOMIC_RELAXED);
9473 * Release an ASO age action.
9476 * Pointer to the Ethernet device structure.
9477 * @param[in] age_idx
9478 * Index of ASO age action to release.
9480 * True if the release operation is during flow destroy operation.
9481 * False if the release operation is during action destroy operation.
9484 * 0 when age action was removed, otherwise the number of references.
9487 flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
9489 struct mlx5_priv *priv = dev->data->dev_private;
9490 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
9491 struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
9492 uint32_t ret = __atomic_sub_fetch(&age->refcnt, 1, __ATOMIC_RELAXED);
9495 flow_dv_aso_age_remove_from_age(dev, age);
9496 rte_spinlock_lock(&mng->free_sl);
9497 LIST_INSERT_HEAD(&mng->free, age, next);
9498 rte_spinlock_unlock(&mng->free_sl);
9504 * Resize the ASO age pools array by MLX5_CNT_CONTAINER_RESIZE pools.
9507 * Pointer to the Ethernet device structure.
9510 * 0 on success, otherwise negative errno value and rte_errno is set.
9513 flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
9515 struct mlx5_priv *priv = dev->data->dev_private;
9516 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
9517 void *old_pools = mng->pools;
9518 uint32_t resize = mng->n + MLX5_CNT_CONTAINER_RESIZE;
9519 uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
9520 void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
9527 memcpy(pools, old_pools,
9528 mng->n * sizeof(struct mlx5_flow_counter_pool *));
9529 mlx5_free(old_pools);
9531 /* First ASO flow hit allocation - starting ASO data-path. */
9532 int ret = mlx5_aso_queue_start(priv->sh);
9545 * Create and initialize a new ASO aging pool.
9548 * Pointer to the Ethernet device structure.
9549 * @param[out] age_free
9550 * Where to put the pointer of a new age action.
9553 * The age actions pool pointer and @p age_free is set on success,
9554 * NULL otherwise and rte_errno is set.
9556 static struct mlx5_aso_age_pool *
9557 flow_dv_age_pool_create(struct rte_eth_dev *dev,
9558 struct mlx5_aso_age_action **age_free)
9560 struct mlx5_priv *priv = dev->data->dev_private;
9561 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
9562 struct mlx5_aso_age_pool *pool = NULL;
9563 struct mlx5_devx_obj *obj = NULL;
9566 obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->ctx,
9569 rte_errno = ENODATA;
9570 DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
9573 pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
9575 claim_zero(mlx5_devx_cmd_destroy(obj));
9579 pool->flow_hit_aso_obj = obj;
9580 pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
9581 rte_spinlock_lock(&mng->resize_sl);
9582 pool->index = mng->next;
9583 /* Resize pools array if there is no room for the new pool in it. */
9584 if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
9585 claim_zero(mlx5_devx_cmd_destroy(obj));
9587 rte_spinlock_unlock(&mng->resize_sl);
9590 mng->pools[pool->index] = pool;
9592 rte_spinlock_unlock(&mng->resize_sl);
9593 /* Assign the first action in the new pool, the rest go to free list. */
9594 *age_free = &pool->actions[0];
9595 for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
9596 pool->actions[i].offset = i;
9597 LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
9603 * Allocate a ASO aging bit.
9606 * Pointer to the Ethernet device structure.
9608 * Pointer to the error structure.
9611 * Index to ASO age action on success, 0 otherwise and rte_errno is set.
9614 flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
9616 struct mlx5_priv *priv = dev->data->dev_private;
9617 const struct mlx5_aso_age_pool *pool;
9618 struct mlx5_aso_age_action *age_free = NULL;
9619 struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
9622 /* Try to get the next free age action bit. */
9623 rte_spinlock_lock(&mng->free_sl);
9624 age_free = LIST_FIRST(&mng->free);
9626 LIST_REMOVE(age_free, next);
9627 } else if (!flow_dv_age_pool_create(dev, &age_free)) {
9628 rte_spinlock_unlock(&mng->free_sl);
9629 rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
9630 NULL, "failed to create ASO age pool");
9631 return 0; /* 0 is an error. */
9633 rte_spinlock_unlock(&mng->free_sl);
9635 ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
9636 (age_free - age_free->offset), const struct mlx5_aso_age_pool,
9638 if (!age_free->dr_action) {
9639 int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
9643 rte_flow_error_set(error, rte_errno,
9644 RTE_FLOW_ERROR_TYPE_ACTION,
9645 NULL, "failed to get reg_c "
9646 "for ASO flow hit");
9647 return 0; /* 0 is an error. */
9649 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
9650 age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
9651 (priv->sh->rx_domain,
9652 pool->flow_hit_aso_obj->obj, age_free->offset,
9653 MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
9655 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
9656 if (!age_free->dr_action) {
9658 rte_spinlock_lock(&mng->free_sl);
9659 LIST_INSERT_HEAD(&mng->free, age_free, next);
9660 rte_spinlock_unlock(&mng->free_sl);
9661 rte_flow_error_set(error, rte_errno,
9662 RTE_FLOW_ERROR_TYPE_ACTION,
9663 NULL, "failed to create ASO "
9665 return 0; /* 0 is an error. */
9668 __atomic_store_n(&age_free->refcnt, 1, __ATOMIC_RELAXED);
9669 return pool->index | ((age_free->offset + 1) << 16);
9673 * Create a age action using ASO mechanism.
9676 * Pointer to rte_eth_dev structure.
9678 * Pointer to the aging action configuration.
9680 * Pointer to the error structure.
9683 * Index to flow counter on success, 0 otherwise.
9686 flow_dv_translate_create_aso_age(struct rte_eth_dev *dev,
9687 const struct rte_flow_action_age *age,
9688 struct rte_flow_error *error)
9690 uint32_t age_idx = 0;
9691 struct mlx5_aso_age_action *aso_age;
9693 age_idx = flow_dv_aso_age_alloc(dev, error);
9696 aso_age = flow_aso_age_get_by_idx(dev, age_idx);
9697 aso_age->age_params.context = age->context;
9698 aso_age->age_params.timeout = age->timeout;
9699 aso_age->age_params.port_id = dev->data->port_id;
9700 __atomic_store_n(&aso_age->age_params.sec_since_last_hit, 0,
9702 __atomic_store_n(&aso_age->age_params.state, AGE_CANDIDATE,
9708 * Fill the flow with DV spec, lock free
9709 * (mutex should be acquired by caller).
9712 * Pointer to rte_eth_dev structure.
9713 * @param[in, out] dev_flow
9714 * Pointer to the sub flow.
9716 * Pointer to the flow attributes.
9718 * Pointer to the list of items.
9719 * @param[in] actions
9720 * Pointer to the list of actions.
9722 * Pointer to the error structure.
9725 * 0 on success, a negative errno value otherwise and rte_errno is set.
9728 flow_dv_translate(struct rte_eth_dev *dev,
9729 struct mlx5_flow *dev_flow,
9730 const struct rte_flow_attr *attr,
9731 const struct rte_flow_item items[],
9732 const struct rte_flow_action actions[],
9733 struct rte_flow_error *error)
9735 struct mlx5_priv *priv = dev->data->dev_private;
9736 struct mlx5_dev_config *dev_conf = &priv->config;
9737 struct rte_flow *flow = dev_flow->flow;
9738 struct mlx5_flow_handle *handle = dev_flow->handle;
9739 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
9740 struct mlx5_flow_rss_desc *rss_desc;
9741 uint64_t item_flags = 0;
9742 uint64_t last_item = 0;
9743 uint64_t action_flags = 0;
9744 uint64_t priority = attr->priority;
9745 struct mlx5_flow_dv_matcher matcher = {
9747 .size = sizeof(matcher.mask.buf) -
9748 MLX5_ST_SZ_BYTES(fte_match_set_misc4),
9752 bool actions_end = false;
9754 struct mlx5_flow_dv_modify_hdr_resource res;
9755 uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
9756 sizeof(struct mlx5_modification_cmd) *
9757 (MLX5_MAX_MODIFY_NUM + 1)];
9759 struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
9760 const struct rte_flow_action_count *count = NULL;
9761 const struct rte_flow_action_age *age = NULL;
9762 union flow_dv_attr flow_attr = { .attr = 0 };
9764 union mlx5_flow_tbl_key tbl_key;
9765 uint32_t modify_action_position = UINT32_MAX;
9766 void *match_mask = matcher.mask.buf;
9767 void *match_value = dev_flow->dv.value.buf;
9768 uint8_t next_protocol = 0xff;
9769 struct rte_vlan_hdr vlan = { 0 };
9770 struct mlx5_flow_dv_dest_array_resource mdest_res;
9771 struct mlx5_flow_dv_sample_resource sample_res;
9772 void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
9773 struct mlx5_flow_sub_actions_list *sample_act;
9774 uint32_t sample_act_pos = UINT32_MAX;
9775 uint32_t num_of_dest = 0;
9776 int tmp_actions_n = 0;
9779 const struct mlx5_flow_tunnel *tunnel;
9780 struct flow_grp_info grp_info = {
9781 .external = !!dev_flow->external,
9782 .transfer = !!attr->transfer,
9783 .fdb_def_rule = !!priv->fdb_def_rule,
9784 .skip_scale = !!dev_flow->skip_scale,
9788 return rte_flow_error_set(error, ENOMEM,
9789 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9791 "failed to push flow workspace");
9792 rss_desc = &wks->rss_desc;
9793 memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
9794 memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
9795 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
9796 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
9797 /* update normal path action resource into last index of array */
9798 sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
9799 tunnel = is_flow_tunnel_match_rule(dev, attr, items, actions) ?
9800 flow_items_to_tunnel(items) :
9801 is_flow_tunnel_steer_rule(dev, attr, items, actions) ?
9802 flow_actions_to_tunnel(actions) :
9803 dev_flow->tunnel ? dev_flow->tunnel : NULL;
9804 mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
9805 MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
9806 grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
9807 (dev, tunnel, attr, items, actions);
9808 ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
9812 dev_flow->dv.group = table;
9814 mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
9815 if (priority == MLX5_FLOW_PRIO_RSVD)
9816 priority = dev_conf->flow_prio - 1;
9817 /* number of actions must be set to 0 in case of dirty stack. */
9818 mhdr_res->actions_num = 0;
9819 if (is_flow_tunnel_match_rule(dev, attr, items, actions)) {
9821 * do not add decap action if match rule drops packet
9822 * HW rejects rules with decap & drop
9824 * if tunnel match rule was inserted before matching tunnel set
9825 * rule flow table used in the match rule must be registered.
9826 * current implementation handles that in the
9827 * flow_dv_match_register() at the function end.
9829 bool add_decap = true;
9830 const struct rte_flow_action *ptr = actions;
9832 for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
9833 if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
9839 if (flow_dv_create_action_l2_decap(dev, dev_flow,
9843 dev_flow->dv.actions[actions_n++] =
9844 dev_flow->dv.encap_decap->action;
9845 action_flags |= MLX5_FLOW_ACTION_DECAP;
9848 for (; !actions_end ; actions++) {
9849 const struct rte_flow_action_queue *queue;
9850 const struct rte_flow_action_rss *rss;
9851 const struct rte_flow_action *action = actions;
9852 const uint8_t *rss_key;
9853 const struct rte_flow_action_meter *mtr;
9854 struct mlx5_flow_tbl_resource *tbl;
9855 struct mlx5_aso_age_action *age_act;
9856 uint32_t port_id = 0;
9857 struct mlx5_flow_dv_port_id_action_resource port_id_resource;
9858 int action_type = actions->type;
9859 const struct rte_flow_action *found_action = NULL;
9860 struct mlx5_flow_meter *fm = NULL;
9861 uint32_t jump_group = 0;
9863 if (!mlx5_flow_os_action_supported(action_type))
9864 return rte_flow_error_set(error, ENOTSUP,
9865 RTE_FLOW_ERROR_TYPE_ACTION,
9867 "action not supported");
9868 switch (action_type) {
9869 case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
9870 action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
9872 case RTE_FLOW_ACTION_TYPE_VOID:
9874 case RTE_FLOW_ACTION_TYPE_PORT_ID:
9875 if (flow_dv_translate_action_port_id(dev, action,
9878 port_id_resource.port_id = port_id;
9879 MLX5_ASSERT(!handle->rix_port_id_action);
9880 if (flow_dv_port_id_action_resource_register
9881 (dev, &port_id_resource, dev_flow, error))
9883 dev_flow->dv.actions[actions_n++] =
9884 dev_flow->dv.port_id_action->action;
9885 action_flags |= MLX5_FLOW_ACTION_PORT_ID;
9886 dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
9887 sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
9890 case RTE_FLOW_ACTION_TYPE_FLAG:
9891 action_flags |= MLX5_FLOW_ACTION_FLAG;
9892 dev_flow->handle->mark = 1;
9893 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
9894 struct rte_flow_action_mark mark = {
9895 .id = MLX5_FLOW_MARK_DEFAULT,
9898 if (flow_dv_convert_action_mark(dev, &mark,
9902 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
9905 tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
9907 * Only one FLAG or MARK is supported per device flow
9908 * right now. So the pointer to the tag resource must be
9909 * zero before the register process.
9911 MLX5_ASSERT(!handle->dvh.rix_tag);
9912 if (flow_dv_tag_resource_register(dev, tag_be,
9915 MLX5_ASSERT(dev_flow->dv.tag_resource);
9916 dev_flow->dv.actions[actions_n++] =
9917 dev_flow->dv.tag_resource->action;
9919 case RTE_FLOW_ACTION_TYPE_MARK:
9920 action_flags |= MLX5_FLOW_ACTION_MARK;
9921 dev_flow->handle->mark = 1;
9922 if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
9923 const struct rte_flow_action_mark *mark =
9924 (const struct rte_flow_action_mark *)
9927 if (flow_dv_convert_action_mark(dev, mark,
9931 action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
9935 case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
9936 /* Legacy (non-extensive) MARK action. */
9937 tag_be = mlx5_flow_mark_set
9938 (((const struct rte_flow_action_mark *)
9939 (actions->conf))->id);
9940 MLX5_ASSERT(!handle->dvh.rix_tag);
9941 if (flow_dv_tag_resource_register(dev, tag_be,
9944 MLX5_ASSERT(dev_flow->dv.tag_resource);
9945 dev_flow->dv.actions[actions_n++] =
9946 dev_flow->dv.tag_resource->action;
9948 case RTE_FLOW_ACTION_TYPE_SET_META:
9949 if (flow_dv_convert_action_set_meta
9950 (dev, mhdr_res, attr,
9951 (const struct rte_flow_action_set_meta *)
9952 actions->conf, error))
9954 action_flags |= MLX5_FLOW_ACTION_SET_META;
9956 case RTE_FLOW_ACTION_TYPE_SET_TAG:
9957 if (flow_dv_convert_action_set_tag
9959 (const struct rte_flow_action_set_tag *)
9960 actions->conf, error))
9962 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
9964 case RTE_FLOW_ACTION_TYPE_DROP:
9965 action_flags |= MLX5_FLOW_ACTION_DROP;
9966 dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
9968 case RTE_FLOW_ACTION_TYPE_QUEUE:
9969 queue = actions->conf;
9970 rss_desc->queue_num = 1;
9971 rss_desc->queue[0] = queue->index;
9972 action_flags |= MLX5_FLOW_ACTION_QUEUE;
9973 dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
9974 sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
9977 case RTE_FLOW_ACTION_TYPE_RSS:
9978 rss = actions->conf;
9979 memcpy(rss_desc->queue, rss->queue,
9980 rss->queue_num * sizeof(uint16_t));
9981 rss_desc->queue_num = rss->queue_num;
9982 /* NULL RSS key indicates default RSS key. */
9983 rss_key = !rss->key ? rss_hash_default_key : rss->key;
9984 memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
9986 * rss->level and rss.types should be set in advance
9987 * when expanding items for RSS.
9989 action_flags |= MLX5_FLOW_ACTION_RSS;
9990 dev_flow->handle->fate_action = rss_desc->shared_rss ?
9991 MLX5_FLOW_FATE_SHARED_RSS :
9992 MLX5_FLOW_FATE_QUEUE;
9994 case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
9995 flow->age = (uint32_t)(uintptr_t)(action->conf);
9996 age_act = flow_aso_age_get_by_idx(dev, flow->age);
9997 __atomic_fetch_add(&age_act->refcnt, 1,
9999 dev_flow->dv.actions[actions_n++] = age_act->dr_action;
10000 action_flags |= MLX5_FLOW_ACTION_AGE;
10002 case RTE_FLOW_ACTION_TYPE_AGE:
10003 if (priv->sh->flow_hit_aso_en && attr->group) {
10004 flow->age = flow_dv_translate_create_aso_age
10005 (dev, action->conf, error);
10007 return rte_flow_error_set
10009 RTE_FLOW_ERROR_TYPE_ACTION,
10011 "can't create ASO age action");
10012 dev_flow->dv.actions[actions_n++] =
10013 (flow_aso_age_get_by_idx
10014 (dev, flow->age))->dr_action;
10015 action_flags |= MLX5_FLOW_ACTION_AGE;
10019 case RTE_FLOW_ACTION_TYPE_COUNT:
10020 if (!dev_conf->devx) {
10021 return rte_flow_error_set
10023 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10025 "count action not supported");
10027 /* Save information first, will apply later. */
10028 if (actions->type == RTE_FLOW_ACTION_TYPE_COUNT)
10029 count = action->conf;
10031 age = action->conf;
10032 action_flags |= MLX5_FLOW_ACTION_COUNT;
10034 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
10035 dev_flow->dv.actions[actions_n++] =
10036 priv->sh->pop_vlan_action;
10037 action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
10039 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
10040 if (!(action_flags &
10041 MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
10042 flow_dev_get_vlan_info_from_items(items, &vlan);
10043 vlan.eth_proto = rte_be_to_cpu_16
10044 ((((const struct rte_flow_action_of_push_vlan *)
10045 actions->conf)->ethertype));
10046 found_action = mlx5_flow_find_action
10048 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
10050 mlx5_update_vlan_vid_pcp(found_action, &vlan);
10051 found_action = mlx5_flow_find_action
10053 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
10055 mlx5_update_vlan_vid_pcp(found_action, &vlan);
10056 if (flow_dv_create_action_push_vlan
10057 (dev, attr, &vlan, dev_flow, error))
10059 dev_flow->dv.actions[actions_n++] =
10060 dev_flow->dv.push_vlan_res->action;
10061 action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
10063 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
10064 /* of_vlan_push action handled this action */
10065 MLX5_ASSERT(action_flags &
10066 MLX5_FLOW_ACTION_OF_PUSH_VLAN);
10068 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
10069 if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
10071 flow_dev_get_vlan_info_from_items(items, &vlan);
10072 mlx5_update_vlan_vid_pcp(actions, &vlan);
10073 /* If no VLAN push - this is a modify header action */
10074 if (flow_dv_convert_action_modify_vlan_vid
10075 (mhdr_res, actions, error))
10077 action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
10079 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
10080 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
10081 if (flow_dv_create_action_l2_encap(dev, actions,
10086 dev_flow->dv.actions[actions_n++] =
10087 dev_flow->dv.encap_decap->action;
10088 action_flags |= MLX5_FLOW_ACTION_ENCAP;
10089 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
10090 sample_act->action_flags |=
10091 MLX5_FLOW_ACTION_ENCAP;
10093 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
10094 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
10095 if (flow_dv_create_action_l2_decap(dev, dev_flow,
10099 dev_flow->dv.actions[actions_n++] =
10100 dev_flow->dv.encap_decap->action;
10101 action_flags |= MLX5_FLOW_ACTION_DECAP;
10103 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
10104 /* Handle encap with preceding decap. */
10105 if (action_flags & MLX5_FLOW_ACTION_DECAP) {
10106 if (flow_dv_create_action_raw_encap
10107 (dev, actions, dev_flow, attr, error))
10109 dev_flow->dv.actions[actions_n++] =
10110 dev_flow->dv.encap_decap->action;
10112 /* Handle encap without preceding decap. */
10113 if (flow_dv_create_action_l2_encap
10114 (dev, actions, dev_flow, attr->transfer,
10117 dev_flow->dv.actions[actions_n++] =
10118 dev_flow->dv.encap_decap->action;
10120 action_flags |= MLX5_FLOW_ACTION_ENCAP;
10121 if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
10122 sample_act->action_flags |=
10123 MLX5_FLOW_ACTION_ENCAP;
10125 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
10126 while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
10128 if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
10129 if (flow_dv_create_action_l2_decap
10130 (dev, dev_flow, attr->transfer, error))
10132 dev_flow->dv.actions[actions_n++] =
10133 dev_flow->dv.encap_decap->action;
10135 /* If decap is followed by encap, handle it at encap. */
10136 action_flags |= MLX5_FLOW_ACTION_DECAP;
10138 case RTE_FLOW_ACTION_TYPE_JUMP:
10139 jump_group = ((const struct rte_flow_action_jump *)
10140 action->conf)->group;
10141 grp_info.std_tbl_fix = 0;
10142 grp_info.skip_scale = 0;
10143 ret = mlx5_flow_group_to_table(dev, tunnel,
10149 tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
10151 !!dev_flow->external,
10152 tunnel, jump_group, 0,
10155 return rte_flow_error_set
10157 RTE_FLOW_ERROR_TYPE_ACTION,
10159 "cannot create jump action.");
10160 if (flow_dv_jump_tbl_resource_register
10161 (dev, tbl, dev_flow, error)) {
10162 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
10163 return rte_flow_error_set
10165 RTE_FLOW_ERROR_TYPE_ACTION,
10167 "cannot create jump action.");
10169 dev_flow->dv.actions[actions_n++] =
10170 dev_flow->dv.jump->action;
10171 action_flags |= MLX5_FLOW_ACTION_JUMP;
10172 dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
10174 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
10175 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
10176 if (flow_dv_convert_action_modify_mac
10177 (mhdr_res, actions, error))
10179 action_flags |= actions->type ==
10180 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
10181 MLX5_FLOW_ACTION_SET_MAC_SRC :
10182 MLX5_FLOW_ACTION_SET_MAC_DST;
10184 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
10185 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
10186 if (flow_dv_convert_action_modify_ipv4
10187 (mhdr_res, actions, error))
10189 action_flags |= actions->type ==
10190 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
10191 MLX5_FLOW_ACTION_SET_IPV4_SRC :
10192 MLX5_FLOW_ACTION_SET_IPV4_DST;
10194 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
10195 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
10196 if (flow_dv_convert_action_modify_ipv6
10197 (mhdr_res, actions, error))
10199 action_flags |= actions->type ==
10200 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
10201 MLX5_FLOW_ACTION_SET_IPV6_SRC :
10202 MLX5_FLOW_ACTION_SET_IPV6_DST;
10204 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
10205 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
10206 if (flow_dv_convert_action_modify_tp
10207 (mhdr_res, actions, items,
10208 &flow_attr, dev_flow, !!(action_flags &
10209 MLX5_FLOW_ACTION_DECAP), error))
10211 action_flags |= actions->type ==
10212 RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
10213 MLX5_FLOW_ACTION_SET_TP_SRC :
10214 MLX5_FLOW_ACTION_SET_TP_DST;
10216 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
10217 if (flow_dv_convert_action_modify_dec_ttl
10218 (mhdr_res, items, &flow_attr, dev_flow,
10220 MLX5_FLOW_ACTION_DECAP), error))
10222 action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
10224 case RTE_FLOW_ACTION_TYPE_SET_TTL:
10225 if (flow_dv_convert_action_modify_ttl
10226 (mhdr_res, actions, items, &flow_attr,
10227 dev_flow, !!(action_flags &
10228 MLX5_FLOW_ACTION_DECAP), error))
10230 action_flags |= MLX5_FLOW_ACTION_SET_TTL;
10232 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
10233 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
10234 if (flow_dv_convert_action_modify_tcp_seq
10235 (mhdr_res, actions, error))
10237 action_flags |= actions->type ==
10238 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
10239 MLX5_FLOW_ACTION_INC_TCP_SEQ :
10240 MLX5_FLOW_ACTION_DEC_TCP_SEQ;
10243 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
10244 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
10245 if (flow_dv_convert_action_modify_tcp_ack
10246 (mhdr_res, actions, error))
10248 action_flags |= actions->type ==
10249 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
10250 MLX5_FLOW_ACTION_INC_TCP_ACK :
10251 MLX5_FLOW_ACTION_DEC_TCP_ACK;
10253 case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
10254 if (flow_dv_convert_action_set_reg
10255 (mhdr_res, actions, error))
10257 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
10259 case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
10260 if (flow_dv_convert_action_copy_mreg
10261 (dev, mhdr_res, actions, error))
10263 action_flags |= MLX5_FLOW_ACTION_SET_TAG;
10265 case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
10266 action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
10267 dev_flow->handle->fate_action =
10268 MLX5_FLOW_FATE_DEFAULT_MISS;
10270 case RTE_FLOW_ACTION_TYPE_METER:
10271 mtr = actions->conf;
10272 if (!flow->meter) {
10273 fm = mlx5_flow_meter_attach(priv, mtr->mtr_id,
10276 return rte_flow_error_set(error,
10278 RTE_FLOW_ERROR_TYPE_ACTION,
10281 "or invalid parameters");
10282 flow->meter = fm->idx;
10284 /* Set the meter action. */
10286 fm = mlx5_ipool_get(priv->sh->ipool
10287 [MLX5_IPOOL_MTR], flow->meter);
10289 return rte_flow_error_set(error,
10291 RTE_FLOW_ERROR_TYPE_ACTION,
10294 "or invalid parameters");
10296 dev_flow->dv.actions[actions_n++] =
10297 fm->mfts->meter_action;
10298 action_flags |= MLX5_FLOW_ACTION_METER;
10300 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
10301 if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
10304 action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
10306 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
10307 if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
10310 action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
10312 case RTE_FLOW_ACTION_TYPE_SAMPLE:
10313 sample_act_pos = actions_n;
10314 ret = flow_dv_translate_action_sample(dev,
10324 action_flags |= MLX5_FLOW_ACTION_SAMPLE;
10325 /* put encap action into group if work with port id */
10326 if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
10327 (action_flags & MLX5_FLOW_ACTION_PORT_ID))
10328 sample_act->action_flags |=
10329 MLX5_FLOW_ACTION_ENCAP;
10331 case RTE_FLOW_ACTION_TYPE_END:
10332 actions_end = true;
10333 if (mhdr_res->actions_num) {
10334 /* create modify action if needed. */
10335 if (flow_dv_modify_hdr_resource_register
10336 (dev, mhdr_res, dev_flow, error))
10338 dev_flow->dv.actions[modify_action_position] =
10339 handle->dvh.modify_hdr->action;
10341 if (action_flags & MLX5_FLOW_ACTION_COUNT) {
10343 flow_dv_translate_create_counter(dev,
10344 dev_flow, count, age);
10346 if (!flow->counter)
10347 return rte_flow_error_set
10349 RTE_FLOW_ERROR_TYPE_ACTION,
10351 "cannot create counter"
10353 dev_flow->dv.actions[actions_n] =
10354 (flow_dv_counter_get_by_idx(dev,
10355 flow->counter, NULL))->action;
10358 if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
10359 ret = flow_dv_create_action_sample(dev,
10368 return rte_flow_error_set
10370 RTE_FLOW_ERROR_TYPE_ACTION,
10372 "cannot create sample action");
10373 if (num_of_dest > 1) {
10374 dev_flow->dv.actions[sample_act_pos] =
10375 dev_flow->dv.dest_array_res->action;
10377 dev_flow->dv.actions[sample_act_pos] =
10378 dev_flow->dv.sample_res->verbs_action;
10385 if (mhdr_res->actions_num &&
10386 modify_action_position == UINT32_MAX)
10387 modify_action_position = actions_n++;
10390 * For multiple destination (sample action with ratio=1), the encap
10391 * action and port id action will be combined into group action.
10392 * So need remove the original these actions in the flow and only
10393 * use the sample action instead of.
10395 if (num_of_dest > 1 && sample_act->dr_port_id_action) {
10397 void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
10399 for (i = 0; i < actions_n; i++) {
10400 if ((sample_act->dr_encap_action &&
10401 sample_act->dr_encap_action ==
10402 dev_flow->dv.actions[i]) ||
10403 (sample_act->dr_port_id_action &&
10404 sample_act->dr_port_id_action ==
10405 dev_flow->dv.actions[i]))
10407 temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
10409 memcpy((void *)dev_flow->dv.actions,
10410 (void *)temp_actions,
10411 tmp_actions_n * sizeof(void *));
10412 actions_n = tmp_actions_n;
10414 dev_flow->dv.actions_n = actions_n;
10415 dev_flow->act_flags = action_flags;
10416 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
10417 int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
10418 int item_type = items->type;
10420 if (!mlx5_flow_os_item_supported(item_type))
10421 return rte_flow_error_set(error, ENOTSUP,
10422 RTE_FLOW_ERROR_TYPE_ITEM,
10423 NULL, "item not supported");
10424 switch (item_type) {
10425 case RTE_FLOW_ITEM_TYPE_PORT_ID:
10426 flow_dv_translate_item_port_id
10427 (dev, match_mask, match_value, items, attr);
10428 last_item = MLX5_FLOW_ITEM_PORT_ID;
10430 case RTE_FLOW_ITEM_TYPE_ETH:
10431 flow_dv_translate_item_eth(match_mask, match_value,
10433 dev_flow->dv.group);
10434 matcher.priority = action_flags &
10435 MLX5_FLOW_ACTION_DEFAULT_MISS &&
10436 !dev_flow->external ?
10437 MLX5_PRIORITY_MAP_L3 :
10438 MLX5_PRIORITY_MAP_L2;
10439 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
10440 MLX5_FLOW_LAYER_OUTER_L2;
10442 case RTE_FLOW_ITEM_TYPE_VLAN:
10443 flow_dv_translate_item_vlan(dev_flow,
10444 match_mask, match_value,
10446 dev_flow->dv.group);
10447 matcher.priority = MLX5_PRIORITY_MAP_L2;
10448 last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
10449 MLX5_FLOW_LAYER_INNER_VLAN) :
10450 (MLX5_FLOW_LAYER_OUTER_L2 |
10451 MLX5_FLOW_LAYER_OUTER_VLAN);
10453 case RTE_FLOW_ITEM_TYPE_IPV4:
10454 mlx5_flow_tunnel_ip_check(items, next_protocol,
10455 &item_flags, &tunnel);
10456 flow_dv_translate_item_ipv4(match_mask, match_value,
10458 dev_flow->dv.group);
10459 matcher.priority = MLX5_PRIORITY_MAP_L3;
10460 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
10461 MLX5_FLOW_LAYER_OUTER_L3_IPV4;
10462 if (items->mask != NULL &&
10463 ((const struct rte_flow_item_ipv4 *)
10464 items->mask)->hdr.next_proto_id) {
10466 ((const struct rte_flow_item_ipv4 *)
10467 (items->spec))->hdr.next_proto_id;
10469 ((const struct rte_flow_item_ipv4 *)
10470 (items->mask))->hdr.next_proto_id;
10472 /* Reset for inner layer. */
10473 next_protocol = 0xff;
10476 case RTE_FLOW_ITEM_TYPE_IPV6:
10477 mlx5_flow_tunnel_ip_check(items, next_protocol,
10478 &item_flags, &tunnel);
10479 flow_dv_translate_item_ipv6(match_mask, match_value,
10481 dev_flow->dv.group);
10482 matcher.priority = MLX5_PRIORITY_MAP_L3;
10483 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
10484 MLX5_FLOW_LAYER_OUTER_L3_IPV6;
10485 if (items->mask != NULL &&
10486 ((const struct rte_flow_item_ipv6 *)
10487 items->mask)->hdr.proto) {
10489 ((const struct rte_flow_item_ipv6 *)
10490 items->spec)->hdr.proto;
10492 ((const struct rte_flow_item_ipv6 *)
10493 items->mask)->hdr.proto;
10495 /* Reset for inner layer. */
10496 next_protocol = 0xff;
10499 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
10500 flow_dv_translate_item_ipv6_frag_ext(match_mask,
10503 last_item = tunnel ?
10504 MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
10505 MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
10506 if (items->mask != NULL &&
10507 ((const struct rte_flow_item_ipv6_frag_ext *)
10508 items->mask)->hdr.next_header) {
10510 ((const struct rte_flow_item_ipv6_frag_ext *)
10511 items->spec)->hdr.next_header;
10513 ((const struct rte_flow_item_ipv6_frag_ext *)
10514 items->mask)->hdr.next_header;
10516 /* Reset for inner layer. */
10517 next_protocol = 0xff;
10520 case RTE_FLOW_ITEM_TYPE_TCP:
10521 flow_dv_translate_item_tcp(match_mask, match_value,
10523 matcher.priority = MLX5_PRIORITY_MAP_L4;
10524 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
10525 MLX5_FLOW_LAYER_OUTER_L4_TCP;
10527 case RTE_FLOW_ITEM_TYPE_UDP:
10528 flow_dv_translate_item_udp(match_mask, match_value,
10530 matcher.priority = MLX5_PRIORITY_MAP_L4;
10531 last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
10532 MLX5_FLOW_LAYER_OUTER_L4_UDP;
10534 case RTE_FLOW_ITEM_TYPE_GRE:
10535 flow_dv_translate_item_gre(match_mask, match_value,
10537 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
10538 last_item = MLX5_FLOW_LAYER_GRE;
10540 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
10541 flow_dv_translate_item_gre_key(match_mask,
10542 match_value, items);
10543 last_item = MLX5_FLOW_LAYER_GRE_KEY;
10545 case RTE_FLOW_ITEM_TYPE_NVGRE:
10546 flow_dv_translate_item_nvgre(match_mask, match_value,
10548 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
10549 last_item = MLX5_FLOW_LAYER_GRE;
10551 case RTE_FLOW_ITEM_TYPE_VXLAN:
10552 flow_dv_translate_item_vxlan(match_mask, match_value,
10554 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
10555 last_item = MLX5_FLOW_LAYER_VXLAN;
10557 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
10558 flow_dv_translate_item_vxlan_gpe(match_mask,
10559 match_value, items,
10561 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
10562 last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
10564 case RTE_FLOW_ITEM_TYPE_GENEVE:
10565 flow_dv_translate_item_geneve(match_mask, match_value,
10567 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
10568 last_item = MLX5_FLOW_LAYER_GENEVE;
10570 case RTE_FLOW_ITEM_TYPE_MPLS:
10571 flow_dv_translate_item_mpls(match_mask, match_value,
10572 items, last_item, tunnel);
10573 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
10574 last_item = MLX5_FLOW_LAYER_MPLS;
10576 case RTE_FLOW_ITEM_TYPE_MARK:
10577 flow_dv_translate_item_mark(dev, match_mask,
10578 match_value, items);
10579 last_item = MLX5_FLOW_ITEM_MARK;
10581 case RTE_FLOW_ITEM_TYPE_META:
10582 flow_dv_translate_item_meta(dev, match_mask,
10583 match_value, attr, items);
10584 last_item = MLX5_FLOW_ITEM_METADATA;
10586 case RTE_FLOW_ITEM_TYPE_ICMP:
10587 flow_dv_translate_item_icmp(match_mask, match_value,
10589 last_item = MLX5_FLOW_LAYER_ICMP;
10591 case RTE_FLOW_ITEM_TYPE_ICMP6:
10592 flow_dv_translate_item_icmp6(match_mask, match_value,
10594 last_item = MLX5_FLOW_LAYER_ICMP6;
10596 case RTE_FLOW_ITEM_TYPE_TAG:
10597 flow_dv_translate_item_tag(dev, match_mask,
10598 match_value, items);
10599 last_item = MLX5_FLOW_ITEM_TAG;
10601 case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
10602 flow_dv_translate_mlx5_item_tag(dev, match_mask,
10603 match_value, items);
10604 last_item = MLX5_FLOW_ITEM_TAG;
10606 case MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE:
10607 flow_dv_translate_item_tx_queue(dev, match_mask,
10610 last_item = MLX5_FLOW_ITEM_TX_QUEUE;
10612 case RTE_FLOW_ITEM_TYPE_GTP:
10613 flow_dv_translate_item_gtp(match_mask, match_value,
10615 matcher.priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
10616 last_item = MLX5_FLOW_LAYER_GTP;
10618 case RTE_FLOW_ITEM_TYPE_ECPRI:
10619 if (!mlx5_flex_parser_ecpri_exist(dev)) {
10620 /* Create it only the first time to be used. */
10621 ret = mlx5_flex_parser_ecpri_alloc(dev);
10623 return rte_flow_error_set
10625 RTE_FLOW_ERROR_TYPE_ITEM,
10627 "cannot create eCPRI parser");
10629 /* Adjust the length matcher and device flow value. */
10630 matcher.mask.size = MLX5_ST_SZ_BYTES(fte_match_param);
10631 dev_flow->dv.value.size =
10632 MLX5_ST_SZ_BYTES(fte_match_param);
10633 flow_dv_translate_item_ecpri(dev, match_mask,
10634 match_value, items);
10635 /* No other protocol should follow eCPRI layer. */
10636 last_item = MLX5_FLOW_LAYER_ECPRI;
10641 item_flags |= last_item;
10644 * When E-Switch mode is enabled, we have two cases where we need to
10645 * set the source port manually.
10646 * The first one, is in case of Nic steering rule, and the second is
10647 * E-Switch rule where no port_id item was found. In both cases
10648 * the source port is set according the current port in use.
10650 if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
10651 (priv->representor || priv->master)) {
10652 if (flow_dv_translate_item_port_id(dev, match_mask,
10653 match_value, NULL, attr))
10656 #ifdef RTE_LIBRTE_MLX5_DEBUG
10657 MLX5_ASSERT(!flow_dv_check_valid_spec(matcher.mask.buf,
10658 dev_flow->dv.value.buf));
10661 * Layers may be already initialized from prefix flow if this dev_flow
10662 * is the suffix flow.
10664 handle->layers |= item_flags;
10665 if (action_flags & MLX5_FLOW_ACTION_RSS)
10666 flow_dv_hashfields_set(dev_flow, rss_desc);
10667 /* Register matcher. */
10668 matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
10669 matcher.mask.size);
10670 matcher.priority = mlx5_os_flow_adjust_priority(dev,
10673 /* reserved field no needs to be set to 0 here. */
10674 tbl_key.domain = attr->transfer;
10675 tbl_key.direction = attr->egress;
10676 tbl_key.table_id = dev_flow->dv.group;
10677 if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
10678 tunnel, attr->group, error))
10684 * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
10687 * @param[in, out] action
10688 * Shred RSS action holding hash RX queue objects.
10689 * @param[in] hash_fields
10690 * Defines combination of packet fields to participate in RX hash.
10691 * @param[in] tunnel
10693 * @param[in] hrxq_idx
10694 * Hash RX queue index to set.
10697 * 0 on success, otherwise negative errno value.
10700 __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
10701 const uint64_t hash_fields,
10705 uint32_t *hrxqs = tunnel ? action->hrxq : action->hrxq_tunnel;
10707 switch (hash_fields & ~IBV_RX_HASH_INNER) {
10708 case MLX5_RSS_HASH_IPV4:
10709 hrxqs[0] = hrxq_idx;
10711 case MLX5_RSS_HASH_IPV4_TCP:
10712 hrxqs[1] = hrxq_idx;
10714 case MLX5_RSS_HASH_IPV4_UDP:
10715 hrxqs[2] = hrxq_idx;
10717 case MLX5_RSS_HASH_IPV6:
10718 hrxqs[3] = hrxq_idx;
10720 case MLX5_RSS_HASH_IPV6_TCP:
10721 hrxqs[4] = hrxq_idx;
10723 case MLX5_RSS_HASH_IPV6_UDP:
10724 hrxqs[5] = hrxq_idx;
10726 case MLX5_RSS_HASH_NONE:
10727 hrxqs[6] = hrxq_idx;
10735 * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
10739 * Pointer to the Ethernet device structure.
10741 * Shared RSS action ID holding hash RX queue objects.
10742 * @param[in] hash_fields
10743 * Defines combination of packet fields to participate in RX hash.
10744 * @param[in] tunnel
10748 * Valid hash RX queue index, otherwise 0.
10751 __flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
10752 const uint64_t hash_fields,
10755 struct mlx5_priv *priv = dev->data->dev_private;
10756 struct mlx5_shared_action_rss *shared_rss =
10757 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
10758 const uint32_t *hrxqs = tunnel ? shared_rss->hrxq :
10759 shared_rss->hrxq_tunnel;
10761 switch (hash_fields & ~IBV_RX_HASH_INNER) {
10762 case MLX5_RSS_HASH_IPV4:
10764 case MLX5_RSS_HASH_IPV4_TCP:
10766 case MLX5_RSS_HASH_IPV4_UDP:
10768 case MLX5_RSS_HASH_IPV6:
10770 case MLX5_RSS_HASH_IPV6_TCP:
10772 case MLX5_RSS_HASH_IPV6_UDP:
10774 case MLX5_RSS_HASH_NONE:
10782 * Apply the flow to the NIC, lock free,
10783 * (mutex should be acquired by caller).
10786 * Pointer to the Ethernet device structure.
10787 * @param[in, out] flow
10788 * Pointer to flow structure.
10789 * @param[out] error
10790 * Pointer to error structure.
10793 * 0 on success, a negative errno value otherwise and rte_errno is set.
10796 flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
10797 struct rte_flow_error *error)
10799 struct mlx5_flow_dv_workspace *dv;
10800 struct mlx5_flow_handle *dh;
10801 struct mlx5_flow_handle_dv *dv_h;
10802 struct mlx5_flow *dev_flow;
10803 struct mlx5_priv *priv = dev->data->dev_private;
10804 uint32_t handle_idx;
10808 struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10809 struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
10812 for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
10813 dev_flow = &wks->flows[idx];
10814 dv = &dev_flow->dv;
10815 dh = dev_flow->handle;
10818 if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
10819 if (dv->transfer) {
10820 dv->actions[n++] = priv->sh->esw_drop_action;
10822 MLX5_ASSERT(priv->drop_queue.hrxq);
10824 priv->drop_queue.hrxq->action;
10826 } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
10827 !dv_h->rix_sample && !dv_h->rix_dest_array)) {
10828 struct mlx5_hrxq *hrxq;
10831 hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
10836 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10837 "cannot get hash queue");
10840 dh->rix_hrxq = hrxq_idx;
10841 dv->actions[n++] = hrxq->action;
10842 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
10843 struct mlx5_hrxq *hrxq = NULL;
10846 hrxq_idx = __flow_dv_action_rss_hrxq_lookup(dev,
10847 rss_desc->shared_rss,
10848 dev_flow->hash_fields,
10850 MLX5_FLOW_LAYER_TUNNEL));
10852 hrxq = mlx5_ipool_get
10853 (priv->sh->ipool[MLX5_IPOOL_HRXQ],
10858 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10859 "cannot get hash queue");
10862 dh->rix_srss = rss_desc->shared_rss;
10863 dv->actions[n++] = hrxq->action;
10864 } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
10865 if (!priv->sh->default_miss_action) {
10868 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10869 "default miss action not be created.");
10872 dv->actions[n++] = priv->sh->default_miss_action;
10874 err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
10875 (void *)&dv->value, n,
10876 dv->actions, &dh->drv_flow);
10878 rte_flow_error_set(error, errno,
10879 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10881 "hardware refuses to create flow");
10884 if (priv->vmwa_context &&
10885 dh->vf_vlan.tag && !dh->vf_vlan.created) {
10887 * The rule contains the VLAN pattern.
10888 * For VF we are going to create VLAN
10889 * interface to make hypervisor set correct
10890 * e-Switch vport context.
10892 mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
10897 err = rte_errno; /* Save rte_errno before cleanup. */
10898 SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
10899 handle_idx, dh, next) {
10900 /* hrxq is union, don't clear it if the flag is not set. */
10901 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
10902 mlx5_hrxq_release(dev, dh->rix_hrxq);
10904 } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
10907 if (dh->vf_vlan.tag && dh->vf_vlan.created)
10908 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
10910 rte_errno = err; /* Restore rte_errno. */
10915 flow_dv_matcher_remove_cb(struct mlx5_cache_list *list __rte_unused,
10916 struct mlx5_cache_entry *entry)
10918 struct mlx5_flow_dv_matcher *cache = container_of(entry, typeof(*cache),
10921 claim_zero(mlx5_flow_os_destroy_flow_matcher(cache->matcher_object));
10926 * Release the flow matcher.
10929 * Pointer to Ethernet device.
10931 * Pointer to mlx5_flow_handle.
10934 * 1 while a reference on it exists, 0 when freed.
10937 flow_dv_matcher_release(struct rte_eth_dev *dev,
10938 struct mlx5_flow_handle *handle)
10940 struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
10941 struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
10942 typeof(*tbl), tbl);
10945 MLX5_ASSERT(matcher->matcher_object);
10946 ret = mlx5_cache_unregister(&tbl->matchers, &matcher->entry);
10947 flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
10952 * Release encap_decap resource.
10955 * Pointer to the hash list.
10957 * Pointer to exist resource entry object.
10960 flow_dv_encap_decap_remove_cb(struct mlx5_hlist *list,
10961 struct mlx5_hlist_entry *entry)
10963 struct mlx5_dev_ctx_shared *sh = list->ctx;
10964 struct mlx5_flow_dv_encap_decap_resource *res =
10965 container_of(entry, typeof(*res), entry);
10967 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
10968 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
10972 * Release an encap/decap resource.
10975 * Pointer to Ethernet device.
10976 * @param encap_decap_idx
10977 * Index of encap decap resource.
10980 * 1 while a reference on it exists, 0 when freed.
10983 flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,
10984 uint32_t encap_decap_idx)
10986 struct mlx5_priv *priv = dev->data->dev_private;
10987 struct mlx5_flow_dv_encap_decap_resource *cache_resource;
10989 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
10991 if (!cache_resource)
10993 MLX5_ASSERT(cache_resource->action);
10994 return mlx5_hlist_unregister(priv->sh->encaps_decaps,
10995 &cache_resource->entry);
10999 * Release an jump to table action resource.
11002 * Pointer to Ethernet device.
11004 * Pointer to mlx5_flow_handle.
11007 * 1 while a reference on it exists, 0 when freed.
11010 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
11011 struct mlx5_flow_handle *handle)
11013 struct mlx5_priv *priv = dev->data->dev_private;
11014 struct mlx5_flow_tbl_data_entry *tbl_data;
11016 tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
11020 return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
11024 flow_dv_modify_remove_cb(struct mlx5_hlist *list __rte_unused,
11025 struct mlx5_hlist_entry *entry)
11027 struct mlx5_flow_dv_modify_hdr_resource *res =
11028 container_of(entry, typeof(*res), entry);
11030 claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
11035 * Release a modify-header resource.
11038 * Pointer to Ethernet device.
11040 * Pointer to mlx5_flow_handle.
11043 * 1 while a reference on it exists, 0 when freed.
11046 flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
11047 struct mlx5_flow_handle *handle)
11049 struct mlx5_priv *priv = dev->data->dev_private;
11050 struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
11052 MLX5_ASSERT(entry->action);
11053 return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
11057 flow_dv_port_id_remove_cb(struct mlx5_cache_list *list,
11058 struct mlx5_cache_entry *entry)
11060 struct mlx5_dev_ctx_shared *sh = list->ctx;
11061 struct mlx5_flow_dv_port_id_action_resource *cache =
11062 container_of(entry, typeof(*cache), entry);
11064 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
11065 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], cache->idx);
11069 * Release port ID action resource.
11072 * Pointer to Ethernet device.
11074 * Pointer to mlx5_flow_handle.
11077 * 1 while a reference on it exists, 0 when freed.
11080 flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
11083 struct mlx5_priv *priv = dev->data->dev_private;
11084 struct mlx5_flow_dv_port_id_action_resource *cache;
11086 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
11089 MLX5_ASSERT(cache->action);
11090 return mlx5_cache_unregister(&priv->sh->port_id_action_list,
11095 * Release shared RSS action resource.
11098 * Pointer to Ethernet device.
11100 * Shared RSS action index.
11103 flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
11105 struct mlx5_priv *priv = dev->data->dev_private;
11106 struct mlx5_shared_action_rss *shared_rss;
11108 shared_rss = mlx5_ipool_get
11109 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
11110 __atomic_sub_fetch(&shared_rss->refcnt, 1, __ATOMIC_RELAXED);
11114 flow_dv_push_vlan_remove_cb(struct mlx5_cache_list *list,
11115 struct mlx5_cache_entry *entry)
11117 struct mlx5_dev_ctx_shared *sh = list->ctx;
11118 struct mlx5_flow_dv_push_vlan_action_resource *cache =
11119 container_of(entry, typeof(*cache), entry);
11121 claim_zero(mlx5_flow_os_destroy_flow_action(cache->action));
11122 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], cache->idx);
11126 * Release push vlan action resource.
11129 * Pointer to Ethernet device.
11131 * Pointer to mlx5_flow_handle.
11134 * 1 while a reference on it exists, 0 when freed.
11137 flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
11138 struct mlx5_flow_handle *handle)
11140 struct mlx5_priv *priv = dev->data->dev_private;
11141 struct mlx5_flow_dv_push_vlan_action_resource *cache;
11142 uint32_t idx = handle->dvh.rix_push_vlan;
11144 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
11147 MLX5_ASSERT(cache->action);
11148 return mlx5_cache_unregister(&priv->sh->push_vlan_action_list,
11153 * Release the fate resource.
11156 * Pointer to Ethernet device.
11158 * Pointer to mlx5_flow_handle.
11161 flow_dv_fate_resource_release(struct rte_eth_dev *dev,
11162 struct mlx5_flow_handle *handle)
11164 if (!handle->rix_fate)
11166 switch (handle->fate_action) {
11167 case MLX5_FLOW_FATE_QUEUE:
11168 mlx5_hrxq_release(dev, handle->rix_hrxq);
11170 case MLX5_FLOW_FATE_JUMP:
11171 flow_dv_jump_tbl_resource_release(dev, handle);
11173 case MLX5_FLOW_FATE_PORT_ID:
11174 flow_dv_port_id_action_resource_release(dev,
11175 handle->rix_port_id_action);
11178 DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
11181 handle->rix_fate = 0;
11185 flow_dv_sample_remove_cb(struct mlx5_cache_list *list __rte_unused,
11186 struct mlx5_cache_entry *entry)
11188 struct mlx5_flow_dv_sample_resource *cache_resource =
11189 container_of(entry, typeof(*cache_resource), entry);
11190 struct rte_eth_dev *dev = cache_resource->dev;
11191 struct mlx5_priv *priv = dev->data->dev_private;
11193 if (cache_resource->verbs_action)
11194 claim_zero(mlx5_flow_os_destroy_flow_action
11195 (cache_resource->verbs_action));
11196 if (cache_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
11197 if (cache_resource->default_miss)
11198 claim_zero(mlx5_flow_os_destroy_flow_action
11199 (cache_resource->default_miss));
11201 if (cache_resource->normal_path_tbl)
11202 flow_dv_tbl_resource_release(MLX5_SH(dev),
11203 cache_resource->normal_path_tbl);
11204 flow_dv_sample_sub_actions_release(dev,
11205 &cache_resource->sample_idx);
11206 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
11207 cache_resource->idx);
11208 DRV_LOG(DEBUG, "sample resource %p: removed",
11209 (void *)cache_resource);
11213 * Release an sample resource.
11216 * Pointer to Ethernet device.
11218 * Pointer to mlx5_flow_handle.
11221 * 1 while a reference on it exists, 0 when freed.
11224 flow_dv_sample_resource_release(struct rte_eth_dev *dev,
11225 struct mlx5_flow_handle *handle)
11227 struct mlx5_priv *priv = dev->data->dev_private;
11228 struct mlx5_flow_dv_sample_resource *cache_resource;
11230 cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
11231 handle->dvh.rix_sample);
11232 if (!cache_resource)
11234 MLX5_ASSERT(cache_resource->verbs_action);
11235 return mlx5_cache_unregister(&priv->sh->sample_action_list,
11236 &cache_resource->entry);
11240 flow_dv_dest_array_remove_cb(struct mlx5_cache_list *list __rte_unused,
11241 struct mlx5_cache_entry *entry)
11243 struct mlx5_flow_dv_dest_array_resource *cache_resource =
11244 container_of(entry, typeof(*cache_resource), entry);
11245 struct rte_eth_dev *dev = cache_resource->dev;
11246 struct mlx5_priv *priv = dev->data->dev_private;
11249 MLX5_ASSERT(cache_resource->action);
11250 if (cache_resource->action)
11251 claim_zero(mlx5_flow_os_destroy_flow_action
11252 (cache_resource->action));
11253 for (; i < cache_resource->num_of_dest; i++)
11254 flow_dv_sample_sub_actions_release(dev,
11255 &cache_resource->sample_idx[i]);
11256 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11257 cache_resource->idx);
11258 DRV_LOG(DEBUG, "destination array resource %p: removed",
11259 (void *)cache_resource);
11263 * Release an destination array resource.
11266 * Pointer to Ethernet device.
11268 * Pointer to mlx5_flow_handle.
11271 * 1 while a reference on it exists, 0 when freed.
11274 flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
11275 struct mlx5_flow_handle *handle)
11277 struct mlx5_priv *priv = dev->data->dev_private;
11278 struct mlx5_flow_dv_dest_array_resource *cache;
11280 cache = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
11281 handle->dvh.rix_dest_array);
11284 MLX5_ASSERT(cache->action);
11285 return mlx5_cache_unregister(&priv->sh->dest_array_list,
11290 * Remove the flow from the NIC but keeps it in memory.
11291 * Lock free, (mutex should be acquired by caller).
11294 * Pointer to Ethernet device.
11295 * @param[in, out] flow
11296 * Pointer to flow structure.
11299 flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
11301 struct mlx5_flow_handle *dh;
11302 uint32_t handle_idx;
11303 struct mlx5_priv *priv = dev->data->dev_private;
11307 handle_idx = flow->dev_handles;
11308 while (handle_idx) {
11309 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
11313 if (dh->drv_flow) {
11314 claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
11315 dh->drv_flow = NULL;
11317 if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
11318 flow_dv_fate_resource_release(dev, dh);
11319 if (dh->vf_vlan.tag && dh->vf_vlan.created)
11320 mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
11321 handle_idx = dh->next.next;
11326 * Remove the flow from the NIC and the memory.
11327 * Lock free, (mutex should be acquired by caller).
11330 * Pointer to the Ethernet device structure.
11331 * @param[in, out] flow
11332 * Pointer to flow structure.
11335 flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
11337 struct mlx5_flow_handle *dev_handle;
11338 struct mlx5_priv *priv = dev->data->dev_private;
11343 flow_dv_remove(dev, flow);
11344 if (flow->counter) {
11345 flow_dv_counter_free(dev, flow->counter);
11349 struct mlx5_flow_meter *fm;
11351 fm = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MTR],
11354 mlx5_flow_meter_detach(fm);
11358 flow_dv_aso_age_release(dev, flow->age);
11359 while (flow->dev_handles) {
11360 uint32_t tmp_idx = flow->dev_handles;
11362 dev_handle = mlx5_ipool_get(priv->sh->ipool
11363 [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
11366 flow->dev_handles = dev_handle->next.next;
11367 if (dev_handle->dvh.matcher)
11368 flow_dv_matcher_release(dev, dev_handle);
11369 if (dev_handle->dvh.rix_sample)
11370 flow_dv_sample_resource_release(dev, dev_handle);
11371 if (dev_handle->dvh.rix_dest_array)
11372 flow_dv_dest_array_resource_release(dev, dev_handle);
11373 if (dev_handle->dvh.rix_encap_decap)
11374 flow_dv_encap_decap_resource_release(dev,
11375 dev_handle->dvh.rix_encap_decap);
11376 if (dev_handle->dvh.modify_hdr)
11377 flow_dv_modify_hdr_resource_release(dev, dev_handle);
11378 if (dev_handle->dvh.rix_push_vlan)
11379 flow_dv_push_vlan_action_resource_release(dev,
11381 if (dev_handle->dvh.rix_tag)
11382 flow_dv_tag_release(dev,
11383 dev_handle->dvh.rix_tag);
11384 if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
11385 flow_dv_fate_resource_release(dev, dev_handle);
11387 srss = dev_handle->rix_srss;
11388 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
11392 flow_dv_shared_rss_action_release(dev, srss);
11396 * Release array of hash RX queue objects.
11400 * Pointer to the Ethernet device structure.
11401 * @param[in, out] hrxqs
11402 * Array of hash RX queue objects.
11405 * Total number of references to hash RX queue objects in *hrxqs* array
11406 * after this operation.
11409 __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
11410 uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
11415 for (i = 0; i < RTE_DIM(*hrxqs); i++) {
11416 int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
11426 * Release all hash RX queue objects representing shared RSS action.
11429 * Pointer to the Ethernet device structure.
11430 * @param[in, out] action
11431 * Shared RSS action to remove hash RX queue objects from.
11434 * Total number of references to hash RX queue objects stored in *action*
11435 * after this operation.
11436 * Expected to be 0 if no external references held.
11439 __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
11440 struct mlx5_shared_action_rss *action)
11442 return __flow_dv_hrxqs_release(dev, &action->hrxq) +
11443 __flow_dv_hrxqs_release(dev, &action->hrxq_tunnel);
11447 * Setup shared RSS action.
11448 * Prepare set of hash RX queue objects sufficient to handle all valid
11449 * hash_fields combinations (see enum ibv_rx_hash_fields).
11452 * Pointer to the Ethernet device structure.
11453 * @param[in] action_idx
11454 * Shared RSS action ipool index.
11455 * @param[in, out] action
11456 * Partially initialized shared RSS action.
11457 * @param[out] error
11458 * Perform verbose error reporting if not NULL. Initialized in case of
11462 * 0 on success, otherwise negative errno value.
11465 __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
11466 uint32_t action_idx,
11467 struct mlx5_shared_action_rss *action,
11468 struct rte_flow_error *error)
11470 struct mlx5_flow_rss_desc rss_desc = { 0 };
11474 if (mlx5_ind_table_obj_setup(dev, action->ind_tbl)) {
11475 return rte_flow_error_set(error, rte_errno,
11476 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11477 "cannot setup indirection table");
11479 memcpy(rss_desc.key, action->origin.key, MLX5_RSS_HASH_KEY_LEN);
11480 rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
11481 rss_desc.const_q = action->origin.queue;
11482 rss_desc.queue_num = action->origin.queue_num;
11483 /* Set non-zero value to indicate a shared RSS. */
11484 rss_desc.shared_rss = action_idx;
11485 rss_desc.ind_tbl = action->ind_tbl;
11486 for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
11488 uint64_t hash_fields = mlx5_rss_hash_fields[i];
11491 for (tunnel = 0; tunnel < 2; tunnel++) {
11492 rss_desc.tunnel = tunnel;
11493 rss_desc.hash_fields = hash_fields;
11494 hrxq_idx = mlx5_hrxq_get(dev, &rss_desc);
11498 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11499 "cannot get hash queue");
11500 goto error_hrxq_new;
11502 err = __flow_dv_action_rss_hrxq_set
11503 (action, hash_fields, tunnel, hrxq_idx);
11510 __flow_dv_action_rss_hrxqs_release(dev, action);
11511 if (!mlx5_ind_table_obj_release(dev, action->ind_tbl, true))
11512 action->ind_tbl = NULL;
11518 * Create shared RSS action.
11521 * Pointer to the Ethernet device structure.
11523 * Shared action configuration.
11525 * RSS action specification used to create shared action.
11526 * @param[out] error
11527 * Perform verbose error reporting if not NULL. Initialized in case of
11531 * A valid shared action ID in case of success, 0 otherwise and
11532 * rte_errno is set.
11535 __flow_dv_action_rss_create(struct rte_eth_dev *dev,
11536 const struct rte_flow_shared_action_conf *conf,
11537 const struct rte_flow_action_rss *rss,
11538 struct rte_flow_error *error)
11540 struct mlx5_priv *priv = dev->data->dev_private;
11541 struct mlx5_shared_action_rss *shared_action = NULL;
11542 void *queue = NULL;
11543 struct rte_flow_action_rss *origin;
11544 const uint8_t *rss_key;
11545 uint32_t queue_size = rss->queue_num * sizeof(uint16_t);
11548 RTE_SET_USED(conf);
11549 queue = mlx5_malloc(0, RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
11551 shared_action = mlx5_ipool_zmalloc
11552 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
11553 if (!shared_action || !queue) {
11554 rte_flow_error_set(error, ENOMEM,
11555 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11556 "cannot allocate resource memory");
11557 goto error_rss_init;
11559 if (idx > (1u << MLX5_SHARED_ACTION_TYPE_OFFSET)) {
11560 rte_flow_error_set(error, E2BIG,
11561 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11562 "rss action number out of range");
11563 goto error_rss_init;
11565 shared_action->ind_tbl = mlx5_malloc(MLX5_MEM_ZERO,
11566 sizeof(*shared_action->ind_tbl),
11568 if (!shared_action->ind_tbl) {
11569 rte_flow_error_set(error, ENOMEM,
11570 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11571 "cannot allocate resource memory");
11572 goto error_rss_init;
11574 memcpy(queue, rss->queue, queue_size);
11575 shared_action->ind_tbl->queues = queue;
11576 shared_action->ind_tbl->queues_n = rss->queue_num;
11577 origin = &shared_action->origin;
11578 origin->func = rss->func;
11579 origin->level = rss->level;
11580 /* RSS type 0 indicates default RSS type (ETH_RSS_IP). */
11581 origin->types = !rss->types ? ETH_RSS_IP : rss->types;
11582 /* NULL RSS key indicates default RSS key. */
11583 rss_key = !rss->key ? rss_hash_default_key : rss->key;
11584 memcpy(shared_action->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
11585 origin->key = &shared_action->key[0];
11586 origin->key_len = MLX5_RSS_HASH_KEY_LEN;
11587 origin->queue = queue;
11588 origin->queue_num = rss->queue_num;
11589 if (__flow_dv_action_rss_setup(dev, idx, shared_action, error))
11590 goto error_rss_init;
11591 rte_spinlock_init(&shared_action->action_rss_sl);
11592 __atomic_add_fetch(&shared_action->refcnt, 1, __ATOMIC_RELAXED);
11593 rte_spinlock_lock(&priv->shared_act_sl);
11594 ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
11595 &priv->rss_shared_actions, idx, shared_action, next);
11596 rte_spinlock_unlock(&priv->shared_act_sl);
11599 if (shared_action) {
11600 if (shared_action->ind_tbl)
11601 mlx5_free(shared_action->ind_tbl);
11602 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
11611 * Destroy the shared RSS action.
11612 * Release related hash RX queue objects.
11615 * Pointer to the Ethernet device structure.
11617 * The shared RSS action object ID to be removed.
11618 * @param[out] error
11619 * Perform verbose error reporting if not NULL. Initialized in case of
11623 * 0 on success, otherwise negative errno value.
11626 __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
11627 struct rte_flow_error *error)
11629 struct mlx5_priv *priv = dev->data->dev_private;
11630 struct mlx5_shared_action_rss *shared_rss =
11631 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
11632 uint32_t old_refcnt = 1;
11634 uint16_t *queue = NULL;
11637 return rte_flow_error_set(error, EINVAL,
11638 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11639 "invalid shared action");
11640 remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
11642 return rte_flow_error_set(error, EBUSY,
11643 RTE_FLOW_ERROR_TYPE_ACTION,
11645 "shared rss hrxq has references");
11646 queue = shared_rss->ind_tbl->queues;
11647 remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true);
11649 return rte_flow_error_set(error, EBUSY,
11650 RTE_FLOW_ERROR_TYPE_ACTION,
11652 "shared rss indirection table has"
11654 if (!__atomic_compare_exchange_n(&shared_rss->refcnt, &old_refcnt,
11655 0, 0, __ATOMIC_ACQUIRE,
11657 return rte_flow_error_set(error, EBUSY,
11658 RTE_FLOW_ERROR_TYPE_ACTION,
11660 "shared rss has references");
11662 rte_spinlock_lock(&priv->shared_act_sl);
11663 ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
11664 &priv->rss_shared_actions, idx, shared_rss, next);
11665 rte_spinlock_unlock(&priv->shared_act_sl);
11666 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
11672 * Create shared action, lock free,
11673 * (mutex should be acquired by caller).
11674 * Dispatcher for action type specific call.
11677 * Pointer to the Ethernet device structure.
11679 * Shared action configuration.
11680 * @param[in] action
11681 * Action specification used to create shared action.
11682 * @param[out] error
11683 * Perform verbose error reporting if not NULL. Initialized in case of
11687 * A valid shared action handle in case of success, NULL otherwise and
11688 * rte_errno is set.
11690 static struct rte_flow_shared_action *
11691 flow_dv_action_create(struct rte_eth_dev *dev,
11692 const struct rte_flow_shared_action_conf *conf,
11693 const struct rte_flow_action *action,
11694 struct rte_flow_error *err)
11699 switch (action->type) {
11700 case RTE_FLOW_ACTION_TYPE_RSS:
11701 ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
11702 idx = (MLX5_SHARED_ACTION_TYPE_RSS <<
11703 MLX5_SHARED_ACTION_TYPE_OFFSET) | ret;
11705 case RTE_FLOW_ACTION_TYPE_AGE:
11706 ret = flow_dv_translate_create_aso_age(dev, action->conf, err);
11707 idx = (MLX5_SHARED_ACTION_TYPE_AGE <<
11708 MLX5_SHARED_ACTION_TYPE_OFFSET) | ret;
11710 struct mlx5_aso_age_action *aso_age =
11711 flow_aso_age_get_by_idx(dev, ret);
11713 if (!aso_age->age_params.context)
11714 aso_age->age_params.context =
11715 (void *)(uintptr_t)idx;
11719 rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
11720 NULL, "action type not supported");
11723 return ret ? (struct rte_flow_shared_action *)(uintptr_t)idx : NULL;
11727 * Destroy the shared action.
11728 * Release action related resources on the NIC and the memory.
11729 * Lock free, (mutex should be acquired by caller).
11730 * Dispatcher for action type specific call.
11733 * Pointer to the Ethernet device structure.
11734 * @param[in] action
11735 * The shared action object to be removed.
11736 * @param[out] error
11737 * Perform verbose error reporting if not NULL. Initialized in case of
11741 * 0 on success, otherwise negative errno value.
11744 flow_dv_action_destroy(struct rte_eth_dev *dev,
11745 struct rte_flow_shared_action *action,
11746 struct rte_flow_error *error)
11748 uint32_t act_idx = (uint32_t)(uintptr_t)action;
11749 uint32_t type = act_idx >> MLX5_SHARED_ACTION_TYPE_OFFSET;
11750 uint32_t idx = act_idx & ((1u << MLX5_SHARED_ACTION_TYPE_OFFSET) - 1);
11754 case MLX5_SHARED_ACTION_TYPE_RSS:
11755 return __flow_dv_action_rss_release(dev, idx, error);
11756 case MLX5_SHARED_ACTION_TYPE_AGE:
11757 ret = flow_dv_aso_age_release(dev, idx);
11760 * In this case, the last flow has a reference will
11761 * actually release the age action.
11763 DRV_LOG(DEBUG, "Shared age action %" PRIu32 " was"
11764 " released with references %d.", idx, ret);
11767 return rte_flow_error_set(error, ENOTSUP,
11768 RTE_FLOW_ERROR_TYPE_ACTION,
11770 "action type not supported");
11775 * Updates in place shared RSS action configuration.
11778 * Pointer to the Ethernet device structure.
11780 * The shared RSS action object ID to be updated.
11781 * @param[in] action_conf
11782 * RSS action specification used to modify *shared_rss*.
11783 * @param[out] error
11784 * Perform verbose error reporting if not NULL. Initialized in case of
11788 * 0 on success, otherwise negative errno value.
11789 * @note: currently only support update of RSS queues.
11792 __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
11793 const struct rte_flow_action_rss *action_conf,
11794 struct rte_flow_error *error)
11796 struct mlx5_priv *priv = dev->data->dev_private;
11797 struct mlx5_shared_action_rss *shared_rss =
11798 mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
11800 void *queue = NULL;
11801 uint16_t *queue_old = NULL;
11802 uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
11805 return rte_flow_error_set(error, EINVAL,
11806 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11807 "invalid shared action to update");
11808 queue = mlx5_malloc(MLX5_MEM_ZERO,
11809 RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
11812 return rte_flow_error_set(error, ENOMEM,
11813 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11815 "cannot allocate resource memory");
11816 memcpy(queue, action_conf->queue, queue_size);
11817 MLX5_ASSERT(shared_rss->ind_tbl);
11818 rte_spinlock_lock(&shared_rss->action_rss_sl);
11819 queue_old = shared_rss->ind_tbl->queues;
11820 ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
11821 queue, action_conf->queue_num, true);
11824 ret = rte_flow_error_set(error, rte_errno,
11825 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
11826 "cannot update indirection table");
11828 mlx5_free(queue_old);
11829 shared_rss->origin.queue = queue;
11830 shared_rss->origin.queue_num = action_conf->queue_num;
11832 rte_spinlock_unlock(&shared_rss->action_rss_sl);
11837 * Updates in place shared action configuration, lock free,
11838 * (mutex should be acquired by caller).
11841 * Pointer to the Ethernet device structure.
11842 * @param[in] action
11843 * The shared action object to be updated.
11844 * @param[in] action_conf
11845 * Action specification used to modify *action*.
11846 * *action_conf* should be of type correlating with type of the *action*,
11847 * otherwise considered as invalid.
11848 * @param[out] error
11849 * Perform verbose error reporting if not NULL. Initialized in case of
11853 * 0 on success, otherwise negative errno value.
11856 flow_dv_action_update(struct rte_eth_dev *dev,
11857 struct rte_flow_shared_action *action,
11858 const void *action_conf,
11859 struct rte_flow_error *err)
11861 uint32_t act_idx = (uint32_t)(uintptr_t)action;
11862 uint32_t type = act_idx >> MLX5_SHARED_ACTION_TYPE_OFFSET;
11863 uint32_t idx = act_idx & ((1u << MLX5_SHARED_ACTION_TYPE_OFFSET) - 1);
11866 case MLX5_SHARED_ACTION_TYPE_RSS:
11867 return __flow_dv_action_rss_update(dev, idx, action_conf, err);
11869 return rte_flow_error_set(err, ENOTSUP,
11870 RTE_FLOW_ERROR_TYPE_ACTION,
11872 "action type update not supported");
11877 flow_dv_action_query(struct rte_eth_dev *dev,
11878 const struct rte_flow_shared_action *action, void *data,
11879 struct rte_flow_error *error)
11881 struct mlx5_age_param *age_param;
11882 struct rte_flow_query_age *resp;
11883 uint32_t act_idx = (uint32_t)(uintptr_t)action;
11884 uint32_t type = act_idx >> MLX5_SHARED_ACTION_TYPE_OFFSET;
11885 uint32_t idx = act_idx & ((1u << MLX5_SHARED_ACTION_TYPE_OFFSET) - 1);
11888 case MLX5_SHARED_ACTION_TYPE_AGE:
11889 age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
11891 resp->aged = __atomic_load_n(&age_param->state,
11892 __ATOMIC_RELAXED) == AGE_TMOUT ?
11894 resp->sec_since_last_hit_valid = !resp->aged;
11895 if (resp->sec_since_last_hit_valid)
11896 resp->sec_since_last_hit = __atomic_load_n
11897 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
11900 return rte_flow_error_set(error, ENOTSUP,
11901 RTE_FLOW_ERROR_TYPE_ACTION,
11903 "action type query not supported");
11908 * Query a dv flow rule for its statistics via devx.
11911 * Pointer to Ethernet device.
11913 * Pointer to the sub flow.
11915 * data retrieved by the query.
11916 * @param[out] error
11917 * Perform verbose error reporting if not NULL.
11920 * 0 on success, a negative errno value otherwise and rte_errno is set.
11923 flow_dv_query_count(struct rte_eth_dev *dev, struct rte_flow *flow,
11924 void *data, struct rte_flow_error *error)
11926 struct mlx5_priv *priv = dev->data->dev_private;
11927 struct rte_flow_query_count *qc = data;
11929 if (!priv->config.devx)
11930 return rte_flow_error_set(error, ENOTSUP,
11931 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11933 "counters are not supported");
11934 if (flow->counter) {
11935 uint64_t pkts, bytes;
11936 struct mlx5_flow_counter *cnt;
11938 cnt = flow_dv_counter_get_by_idx(dev, flow->counter,
11940 int err = _flow_dv_query_count(dev, flow->counter, &pkts,
11944 return rte_flow_error_set(error, -err,
11945 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11946 NULL, "cannot read counters");
11949 qc->hits = pkts - cnt->hits;
11950 qc->bytes = bytes - cnt->bytes;
11953 cnt->bytes = bytes;
11957 return rte_flow_error_set(error, EINVAL,
11958 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11960 "counters are not available");
11964 * Query a flow rule AGE action for aging information.
11967 * Pointer to Ethernet device.
11969 * Pointer to the sub flow.
11971 * data retrieved by the query.
11972 * @param[out] error
11973 * Perform verbose error reporting if not NULL.
11976 * 0 on success, a negative errno value otherwise and rte_errno is set.
11979 flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
11980 void *data, struct rte_flow_error *error)
11982 struct rte_flow_query_age *resp = data;
11983 struct mlx5_age_param *age_param;
11986 struct mlx5_aso_age_action *act =
11987 flow_aso_age_get_by_idx(dev, flow->age);
11989 age_param = &act->age_params;
11990 } else if (flow->counter) {
11991 age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
11993 if (!age_param || !age_param->timeout)
11994 return rte_flow_error_set
11996 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11997 NULL, "cannot read age data");
11999 return rte_flow_error_set(error, EINVAL,
12000 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12001 NULL, "age data not available");
12003 resp->aged = __atomic_load_n(&age_param->state, __ATOMIC_RELAXED) ==
12005 resp->sec_since_last_hit_valid = !resp->aged;
12006 if (resp->sec_since_last_hit_valid)
12007 resp->sec_since_last_hit = __atomic_load_n
12008 (&age_param->sec_since_last_hit, __ATOMIC_RELAXED);
12015 * @see rte_flow_query()
12016 * @see rte_flow_ops
12019 flow_dv_query(struct rte_eth_dev *dev,
12020 struct rte_flow *flow __rte_unused,
12021 const struct rte_flow_action *actions __rte_unused,
12022 void *data __rte_unused,
12023 struct rte_flow_error *error __rte_unused)
12027 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
12028 switch (actions->type) {
12029 case RTE_FLOW_ACTION_TYPE_VOID:
12031 case RTE_FLOW_ACTION_TYPE_COUNT:
12032 ret = flow_dv_query_count(dev, flow, data, error);
12034 case RTE_FLOW_ACTION_TYPE_AGE:
12035 ret = flow_dv_query_age(dev, flow, data, error);
12038 return rte_flow_error_set(error, ENOTSUP,
12039 RTE_FLOW_ERROR_TYPE_ACTION,
12041 "action not supported");
12048 * Destroy the meter table set.
12049 * Lock free, (mutex should be acquired by caller).
12052 * Pointer to Ethernet device.
12054 * Pointer to the meter table set.
12060 flow_dv_destroy_mtr_tbl(struct rte_eth_dev *dev,
12061 struct mlx5_meter_domains_infos *tbl)
12063 struct mlx5_priv *priv = dev->data->dev_private;
12064 struct mlx5_meter_domains_infos *mtd =
12065 (struct mlx5_meter_domains_infos *)tbl;
12067 if (!mtd || !priv->config.dv_flow_en)
12069 if (mtd->ingress.policer_rules[RTE_MTR_DROPPED])
12070 claim_zero(mlx5_flow_os_destroy_flow
12071 (mtd->ingress.policer_rules[RTE_MTR_DROPPED]));
12072 if (mtd->egress.policer_rules[RTE_MTR_DROPPED])
12073 claim_zero(mlx5_flow_os_destroy_flow
12074 (mtd->egress.policer_rules[RTE_MTR_DROPPED]));
12075 if (mtd->transfer.policer_rules[RTE_MTR_DROPPED])
12076 claim_zero(mlx5_flow_os_destroy_flow
12077 (mtd->transfer.policer_rules[RTE_MTR_DROPPED]));
12078 if (mtd->egress.color_matcher)
12079 claim_zero(mlx5_flow_os_destroy_flow_matcher
12080 (mtd->egress.color_matcher));
12081 if (mtd->egress.any_matcher)
12082 claim_zero(mlx5_flow_os_destroy_flow_matcher
12083 (mtd->egress.any_matcher));
12084 if (mtd->egress.tbl)
12085 flow_dv_tbl_resource_release(MLX5_SH(dev), mtd->egress.tbl);
12086 if (mtd->egress.sfx_tbl)
12087 flow_dv_tbl_resource_release(MLX5_SH(dev), mtd->egress.sfx_tbl);
12088 if (mtd->ingress.color_matcher)
12089 claim_zero(mlx5_flow_os_destroy_flow_matcher
12090 (mtd->ingress.color_matcher));
12091 if (mtd->ingress.any_matcher)
12092 claim_zero(mlx5_flow_os_destroy_flow_matcher
12093 (mtd->ingress.any_matcher));
12094 if (mtd->ingress.tbl)
12095 flow_dv_tbl_resource_release(MLX5_SH(dev), mtd->ingress.tbl);
12096 if (mtd->ingress.sfx_tbl)
12097 flow_dv_tbl_resource_release(MLX5_SH(dev),
12098 mtd->ingress.sfx_tbl);
12099 if (mtd->transfer.color_matcher)
12100 claim_zero(mlx5_flow_os_destroy_flow_matcher
12101 (mtd->transfer.color_matcher));
12102 if (mtd->transfer.any_matcher)
12103 claim_zero(mlx5_flow_os_destroy_flow_matcher
12104 (mtd->transfer.any_matcher));
12105 if (mtd->transfer.tbl)
12106 flow_dv_tbl_resource_release(MLX5_SH(dev), mtd->transfer.tbl);
12107 if (mtd->transfer.sfx_tbl)
12108 flow_dv_tbl_resource_release(MLX5_SH(dev),
12109 mtd->transfer.sfx_tbl);
12110 if (mtd->drop_actn)
12111 claim_zero(mlx5_flow_os_destroy_flow_action(mtd->drop_actn));
12116 /* Number of meter flow actions, count and jump or count and drop. */
12117 #define METER_ACTIONS 2
12120 * Create specify domain meter table and suffix table.
12123 * Pointer to Ethernet device.
12124 * @param[in,out] mtb
12125 * Pointer to DV meter table set.
12126 * @param[in] egress
12128 * @param[in] transfer
12130 * @param[in] color_reg_c_idx
12131 * Reg C index for color match.
12134 * 0 on success, -1 otherwise and rte_errno is set.
12137 flow_dv_prepare_mtr_tables(struct rte_eth_dev *dev,
12138 struct mlx5_meter_domains_infos *mtb,
12139 uint8_t egress, uint8_t transfer,
12140 uint32_t color_reg_c_idx)
12142 struct mlx5_priv *priv = dev->data->dev_private;
12143 struct mlx5_dev_ctx_shared *sh = priv->sh;
12144 struct mlx5_flow_dv_match_params mask = {
12145 .size = sizeof(mask.buf),
12147 struct mlx5_flow_dv_match_params value = {
12148 .size = sizeof(value.buf),
12150 struct mlx5dv_flow_matcher_attr dv_attr = {
12151 .type = IBV_FLOW_ATTR_NORMAL,
12153 .match_criteria_enable = 0,
12154 .match_mask = (void *)&mask,
12156 void *actions[METER_ACTIONS];
12157 struct mlx5_meter_domain_info *dtb;
12158 struct rte_flow_error error;
12163 dtb = &mtb->transfer;
12165 dtb = &mtb->egress;
12167 dtb = &mtb->ingress;
12168 /* Create the meter table with METER level. */
12169 dtb->tbl = flow_dv_tbl_resource_get(dev, MLX5_FLOW_TABLE_LEVEL_METER,
12170 egress, transfer, false, NULL, 0,
12173 DRV_LOG(ERR, "Failed to create meter policer table.");
12176 /* Create the meter suffix table with SUFFIX level. */
12177 dtb->sfx_tbl = flow_dv_tbl_resource_get(dev,
12178 MLX5_FLOW_TABLE_LEVEL_SUFFIX,
12179 egress, transfer, false, NULL, 0,
12181 if (!dtb->sfx_tbl) {
12182 DRV_LOG(ERR, "Failed to create meter suffix table.");
12185 /* Create matchers, Any and Color. */
12186 dv_attr.priority = 3;
12187 dv_attr.match_criteria_enable = 0;
12188 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, dtb->tbl->obj,
12189 &dtb->any_matcher);
12191 DRV_LOG(ERR, "Failed to create meter"
12192 " policer default matcher.");
12195 dv_attr.priority = 0;
12196 dv_attr.match_criteria_enable =
12197 1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
12198 flow_dv_match_meta_reg(mask.buf, value.buf, color_reg_c_idx,
12199 rte_col_2_mlx5_col(RTE_COLORS), UINT8_MAX);
12200 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, dtb->tbl->obj,
12201 &dtb->color_matcher);
12203 DRV_LOG(ERR, "Failed to create meter policer color matcher.");
12206 if (mtb->count_actns[RTE_MTR_DROPPED])
12207 actions[i++] = mtb->count_actns[RTE_MTR_DROPPED];
12208 actions[i++] = mtb->drop_actn;
12209 /* Default rule: lowest priority, match any, actions: drop. */
12210 ret = mlx5_flow_os_create_flow(dtb->any_matcher, (void *)&value, i,
12212 &dtb->policer_rules[RTE_MTR_DROPPED]);
12214 DRV_LOG(ERR, "Failed to create meter policer drop rule.");
12223 * Create the needed meter and suffix tables.
12224 * Lock free, (mutex should be acquired by caller).
12227 * Pointer to Ethernet device.
12229 * Pointer to the flow meter.
12232 * Pointer to table set on success, NULL otherwise and rte_errno is set.
12234 static struct mlx5_meter_domains_infos *
12235 flow_dv_create_mtr_tbl(struct rte_eth_dev *dev,
12236 const struct mlx5_flow_meter *fm)
12238 struct mlx5_priv *priv = dev->data->dev_private;
12239 struct mlx5_meter_domains_infos *mtb;
12243 if (!priv->mtr_en) {
12244 rte_errno = ENOTSUP;
12247 mtb = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*mtb), 0, SOCKET_ID_ANY);
12249 DRV_LOG(ERR, "Failed to allocate memory for meter.");
12252 /* Create meter count actions */
12253 for (i = 0; i <= RTE_MTR_DROPPED; i++) {
12254 struct mlx5_flow_counter *cnt;
12255 if (!fm->policer_stats.cnt[i])
12257 cnt = flow_dv_counter_get_by_idx(dev,
12258 fm->policer_stats.cnt[i], NULL);
12259 mtb->count_actns[i] = cnt->action;
12261 /* Create drop action. */
12262 ret = mlx5_flow_os_create_flow_action_drop(&mtb->drop_actn);
12264 DRV_LOG(ERR, "Failed to create drop action.");
12267 /* Egress meter table. */
12268 ret = flow_dv_prepare_mtr_tables(dev, mtb, 1, 0, priv->mtr_color_reg);
12270 DRV_LOG(ERR, "Failed to prepare egress meter table.");
12273 /* Ingress meter table. */
12274 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 0, priv->mtr_color_reg);
12276 DRV_LOG(ERR, "Failed to prepare ingress meter table.");
12279 /* FDB meter table. */
12280 if (priv->config.dv_esw_en) {
12281 ret = flow_dv_prepare_mtr_tables(dev, mtb, 0, 1,
12282 priv->mtr_color_reg);
12284 DRV_LOG(ERR, "Failed to prepare fdb meter table.");
12290 flow_dv_destroy_mtr_tbl(dev, mtb);
12295 * Destroy domain policer rule.
12298 * Pointer to domain table.
12301 flow_dv_destroy_domain_policer_rule(struct mlx5_meter_domain_info *dt)
12305 for (i = 0; i < RTE_MTR_DROPPED; i++) {
12306 if (dt->policer_rules[i]) {
12307 claim_zero(mlx5_flow_os_destroy_flow
12308 (dt->policer_rules[i]));
12309 dt->policer_rules[i] = NULL;
12312 if (dt->jump_actn) {
12313 claim_zero(mlx5_flow_os_destroy_flow_action(dt->jump_actn));
12314 dt->jump_actn = NULL;
12319 * Destroy policer rules.
12322 * Pointer to Ethernet device.
12324 * Pointer to flow meter structure.
12326 * Pointer to flow attributes.
12332 flow_dv_destroy_policer_rules(struct rte_eth_dev *dev __rte_unused,
12333 const struct mlx5_flow_meter *fm,
12334 const struct rte_flow_attr *attr)
12336 struct mlx5_meter_domains_infos *mtb = fm ? fm->mfts : NULL;
12341 flow_dv_destroy_domain_policer_rule(&mtb->egress);
12343 flow_dv_destroy_domain_policer_rule(&mtb->ingress);
12344 if (attr->transfer)
12345 flow_dv_destroy_domain_policer_rule(&mtb->transfer);
12350 * Create specify domain meter policer rule.
12353 * Pointer to flow meter structure.
12355 * Pointer to DV meter table set.
12356 * @param[in] mtr_reg_c
12357 * Color match REG_C.
12360 * 0 on success, -1 otherwise.
12363 flow_dv_create_policer_forward_rule(struct mlx5_flow_meter *fm,
12364 struct mlx5_meter_domain_info *dtb,
12367 struct mlx5_flow_dv_match_params matcher = {
12368 .size = sizeof(matcher.buf),
12370 struct mlx5_flow_dv_match_params value = {
12371 .size = sizeof(value.buf),
12373 struct mlx5_meter_domains_infos *mtb = fm->mfts;
12374 void *actions[METER_ACTIONS];
12378 /* Create jump action. */
12379 if (!dtb->jump_actn)
12380 ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
12381 (dtb->sfx_tbl->obj, &dtb->jump_actn);
12383 DRV_LOG(ERR, "Failed to create policer jump action.");
12386 for (i = 0; i < RTE_MTR_DROPPED; i++) {
12389 flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
12390 rte_col_2_mlx5_col(i), UINT8_MAX);
12391 if (mtb->count_actns[i])
12392 actions[j++] = mtb->count_actns[i];
12393 if (fm->action[i] == MTR_POLICER_ACTION_DROP)
12394 actions[j++] = mtb->drop_actn;
12396 actions[j++] = dtb->jump_actn;
12397 ret = mlx5_flow_os_create_flow(dtb->color_matcher,
12398 (void *)&value, j, actions,
12399 &dtb->policer_rules[i]);
12401 DRV_LOG(ERR, "Failed to create policer rule.");
12412 * Create policer rules.
12415 * Pointer to Ethernet device.
12417 * Pointer to flow meter structure.
12419 * Pointer to flow attributes.
12422 * 0 on success, -1 otherwise.
12425 flow_dv_create_policer_rules(struct rte_eth_dev *dev,
12426 struct mlx5_flow_meter *fm,
12427 const struct rte_flow_attr *attr)
12429 struct mlx5_priv *priv = dev->data->dev_private;
12430 struct mlx5_meter_domains_infos *mtb = fm->mfts;
12433 if (attr->egress) {
12434 ret = flow_dv_create_policer_forward_rule(fm, &mtb->egress,
12435 priv->mtr_color_reg);
12437 DRV_LOG(ERR, "Failed to create egress policer.");
12441 if (attr->ingress) {
12442 ret = flow_dv_create_policer_forward_rule(fm, &mtb->ingress,
12443 priv->mtr_color_reg);
12445 DRV_LOG(ERR, "Failed to create ingress policer.");
12449 if (attr->transfer) {
12450 ret = flow_dv_create_policer_forward_rule(fm, &mtb->transfer,
12451 priv->mtr_color_reg);
12453 DRV_LOG(ERR, "Failed to create transfer policer.");
12459 flow_dv_destroy_policer_rules(dev, fm, attr);
12464 * Validate the batch counter support in root table.
12466 * Create a simple flow with invalid counter and drop action on root table to
12467 * validate if batch counter with offset on root table is supported or not.
12470 * Pointer to rte_eth_dev structure.
12473 * 0 on success, a negative errno value otherwise and rte_errno is set.
12476 mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
12478 struct mlx5_priv *priv = dev->data->dev_private;
12479 struct mlx5_dev_ctx_shared *sh = priv->sh;
12480 struct mlx5_flow_dv_match_params mask = {
12481 .size = sizeof(mask.buf),
12483 struct mlx5_flow_dv_match_params value = {
12484 .size = sizeof(value.buf),
12486 struct mlx5dv_flow_matcher_attr dv_attr = {
12487 .type = IBV_FLOW_ATTR_NORMAL,
12489 .match_criteria_enable = 0,
12490 .match_mask = (void *)&mask,
12492 void *actions[2] = { 0 };
12493 struct mlx5_flow_tbl_resource *tbl = NULL;
12494 struct mlx5_devx_obj *dcs = NULL;
12495 void *matcher = NULL;
12499 tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL, 0, 0, NULL);
12502 dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->ctx, 0x4);
12505 ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
12509 actions[1] = priv->drop_queue.hrxq->action;
12510 dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
12511 ret = mlx5_flow_os_create_flow_matcher(sh->ctx, &dv_attr, tbl->obj,
12515 ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 2,
12519 * If batch counter with offset is not supported, the driver will not
12520 * validate the invalid offset value, flow create should success.
12521 * In this case, it means batch counter is not supported in root table.
12523 * Otherwise, if flow create is failed, counter offset is supported.
12526 DRV_LOG(INFO, "Batch counter is not supported in root "
12527 "table. Switch to fallback mode.");
12528 rte_errno = ENOTSUP;
12530 claim_zero(mlx5_flow_os_destroy_flow(flow));
12532 /* Check matcher to make sure validate fail at flow create. */
12533 if (!matcher || (matcher && errno != EINVAL))
12534 DRV_LOG(ERR, "Unexpected error in counter offset "
12535 "support detection");
12539 claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
12541 claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
12543 flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12545 claim_zero(mlx5_devx_cmd_destroy(dcs));
12550 * Query a devx counter.
12553 * Pointer to the Ethernet device structure.
12555 * Index to the flow counter.
12557 * Set to clear the counter statistics.
12559 * The statistics value of packets.
12560 * @param[out] bytes
12561 * The statistics value of bytes.
12564 * 0 on success, otherwise return -1.
12567 flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
12568 uint64_t *pkts, uint64_t *bytes)
12570 struct mlx5_priv *priv = dev->data->dev_private;
12571 struct mlx5_flow_counter *cnt;
12572 uint64_t inn_pkts, inn_bytes;
12575 if (!priv->config.devx)
12578 ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
12581 cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
12582 *pkts = inn_pkts - cnt->hits;
12583 *bytes = inn_bytes - cnt->bytes;
12585 cnt->hits = inn_pkts;
12586 cnt->bytes = inn_bytes;
12592 * Get aged-out flows.
12595 * Pointer to the Ethernet device structure.
12596 * @param[in] context
12597 * The address of an array of pointers to the aged-out flows contexts.
12598 * @param[in] nb_contexts
12599 * The length of context array pointers.
12600 * @param[out] error
12601 * Perform verbose error reporting if not NULL. Initialized in case of
12605 * how many contexts get in success, otherwise negative errno value.
12606 * if nb_contexts is 0, return the amount of all aged contexts.
12607 * if nb_contexts is not 0 , return the amount of aged flows reported
12608 * in the context array.
12609 * @note: only stub for now
12612 flow_get_aged_flows(struct rte_eth_dev *dev,
12614 uint32_t nb_contexts,
12615 struct rte_flow_error *error)
12617 struct mlx5_priv *priv = dev->data->dev_private;
12618 struct mlx5_age_info *age_info;
12619 struct mlx5_age_param *age_param;
12620 struct mlx5_flow_counter *counter;
12621 struct mlx5_aso_age_action *act;
12624 if (nb_contexts && !context)
12625 return rte_flow_error_set(error, EINVAL,
12626 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12627 NULL, "empty context");
12628 age_info = GET_PORT_AGE_INFO(priv);
12629 rte_spinlock_lock(&age_info->aged_sl);
12630 LIST_FOREACH(act, &age_info->aged_aso, next) {
12633 context[nb_flows - 1] =
12634 act->age_params.context;
12635 if (!(--nb_contexts))
12639 TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
12642 age_param = MLX5_CNT_TO_AGE(counter);
12643 context[nb_flows - 1] = age_param->context;
12644 if (!(--nb_contexts))
12648 rte_spinlock_unlock(&age_info->aged_sl);
12649 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
12654 * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
12657 flow_dv_counter_allocate(struct rte_eth_dev *dev)
12659 return flow_dv_counter_alloc(dev, 0);
12663 * Validate shared action.
12664 * Dispatcher for action type specific validation.
12667 * Pointer to the Ethernet device structure.
12669 * Shared action configuration.
12670 * @param[in] action
12671 * The shared action object to validate.
12672 * @param[out] error
12673 * Perform verbose error reporting if not NULL. Initialized in case of
12677 * 0 on success, otherwise negative errno value.
12680 flow_dv_action_validate(struct rte_eth_dev *dev,
12681 const struct rte_flow_shared_action_conf *conf,
12682 const struct rte_flow_action *action,
12683 struct rte_flow_error *err)
12685 struct mlx5_priv *priv = dev->data->dev_private;
12687 RTE_SET_USED(conf);
12688 switch (action->type) {
12689 case RTE_FLOW_ACTION_TYPE_RSS:
12690 return mlx5_validate_action_rss(dev, action, err);
12691 case RTE_FLOW_ACTION_TYPE_AGE:
12692 if (!priv->sh->aso_age_mng)
12693 return rte_flow_error_set(err, ENOTSUP,
12694 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12696 "shared age action not supported");
12697 return flow_dv_validate_action_age(0, action, dev, err);
12699 return rte_flow_error_set(err, ENOTSUP,
12700 RTE_FLOW_ERROR_TYPE_ACTION,
12702 "action type not supported");
12707 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
12709 struct mlx5_priv *priv = dev->data->dev_private;
12712 if ((domains & MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
12713 ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
12718 if ((domains & MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
12719 ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
12723 if ((domains & MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
12724 ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
12731 const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
12732 .validate = flow_dv_validate,
12733 .prepare = flow_dv_prepare,
12734 .translate = flow_dv_translate,
12735 .apply = flow_dv_apply,
12736 .remove = flow_dv_remove,
12737 .destroy = flow_dv_destroy,
12738 .query = flow_dv_query,
12739 .create_mtr_tbls = flow_dv_create_mtr_tbl,
12740 .destroy_mtr_tbls = flow_dv_destroy_mtr_tbl,
12741 .create_policer_rules = flow_dv_create_policer_rules,
12742 .destroy_policer_rules = flow_dv_destroy_policer_rules,
12743 .counter_alloc = flow_dv_counter_allocate,
12744 .counter_free = flow_dv_counter_free,
12745 .counter_query = flow_dv_counter_query,
12746 .get_aged_flows = flow_get_aged_flows,
12747 .action_validate = flow_dv_action_validate,
12748 .action_create = flow_dv_action_create,
12749 .action_destroy = flow_dv_action_destroy,
12750 .action_update = flow_dv_action_update,
12751 .action_query = flow_dv_action_query,
12752 .sync_domain = flow_dv_sync_domain,
12755 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */